3 * This file contains static functions that are related to
4 * parsing double-quotish expressions, but are used in more than
7 * It is currently #included by regcomp.c and toke.c.
10 #define PERL_IN_DQUOTE_STATIC_C
14 - regcurly - a little FSA that accepts {\d+,?\d*}
15 Pulled from regcomp.c.
17 PERL_STATIC_INLINE I32
18 S_regcurly(pTHX_ const char *s)
20 PERL_ARGS_ASSERT_REGCURLY;
38 /* XXX Add documentation after final interface and behavior is decided */
39 /* May want to show context for error, so would pass Perl_bslash_c(pTHX_ const char* current, const char* start, const bool output_warning)
44 S_grok_bslash_c(pTHX_ const char source, const bool utf8, const bool output_warning)
50 /* Trying to deprecate non-ASCII usages. This construct has never
51 * worked for a utf8 variant. So, even though are accepting non-ASCII
52 * Latin1 in 5.14, no need to make them work under utf8 */
53 if (! isASCII(source)) {
54 Perl_croak(aTHX_ "Character following \"\\c\" must be ASCII");
58 result = toCTRL(source);
59 if (! isASCII(source)) {
60 Perl_ck_warner_d(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
61 "Character following \"\\c\" must be ASCII");
63 else if (! isCNTRL(result) && output_warning) {
65 Perl_ck_warner_d(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
66 "\"\\c{\" is deprecated and is more clearly written as \";\"");
71 if (! isALNUM(result)) {
74 clearer[i++] = result;
77 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
78 "\"\\c%c\" is more clearly written simply as \"%s\"",
88 S_grok_bslash_o(pTHX_ const char *s,
91 const char** error_msg,
92 const bool output_warning)
95 /* Documentation to be supplied when interface nailed down finally
96 * This returns FALSE if there is an error which the caller need not recover
97 * from; , otherwise TRUE. In either case the caller should look at *len
99 * s points to a string that begins with 'o', and the previous character
101 * uv points to a UV that will hold the output value, valid only if the
102 * return from the function is TRUE
103 * len on success will point to the next character in the string past the
104 * end of this construct.
105 * on failure, it will point to the failure
106 * error_msg is a pointer that will be set to an internal buffer giving an
107 * error message upon failure (the return is FALSE). Untouched if
109 * output_warning says whether to output any warning messages, or suppress
114 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES
115 | PERL_SCAN_DISALLOW_PREFIX
116 /* XXX Until the message is improved in grok_oct, handle errors
118 | PERL_SCAN_SILENT_ILLDIGIT;
120 PERL_ARGS_ASSERT_GROK_BSLASH_O;
127 *len = 1; /* Move past the o */
128 *error_msg = "Missing braces on \\o{}";
134 *len = 2; /* Move past the o{ */
135 *error_msg = "Missing right brace on \\o{";
139 /* Return past the '}' no matter what is inside the braces */
140 *len = e - s + 2; /* 2 = 1 for the 'o' + 1 for the '}' */
142 s++; /* Point to first digit */
145 if (numbers_len == 0) {
146 *error_msg = "Number with no digits";
150 *uv = grok_oct(s, &numbers_len, &flags, NULL);
151 /* Note that if has non-octal, will ignore everything starting with that up
154 if (output_warning && numbers_len != (STRLEN) (e - s)) {
155 Perl_ck_warner(aTHX_ packWARN(WARN_DIGIT),
156 /* diag_listed_as: Non-octal character '%c'. Resolved as "%s" */
157 "Non-octal character '%c'. Resolved as \"\\o{%.*s}\"",
166 PERL_STATIC_INLINE bool
167 S_grok_bslash_x(pTHX_ const char *s,
170 const char** error_msg,
171 const bool output_warning)
174 /* Documentation to be supplied when interface nailed down finally
175 * This returns FALSE if there is an error which the caller need not recover
176 * from; , otherwise TRUE. In either case the caller should look at *len
178 * s points to a string that begins with 'x', and the previous character
180 * uv points to a UV that will hold the output value, valid only if the
181 * return from the function is TRUE
182 * len on success will point to the next character in the string past the
183 * end of this construct.
184 * on failure, it will point to the failure
185 * error_msg is a pointer that will be set to an internal buffer giving an
186 * error message upon failure (the return is FALSE). Untouched if
188 * output_warning says whether to output any warning messages, or suppress
193 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES
194 | PERL_SCAN_DISALLOW_PREFIX;
196 PERL_ARGS_ASSERT_GROK_BSLASH_X;
198 PERL_UNUSED_ARG(output_warning);
204 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
206 *uv = grok_hex(s, len, &flags, NULL);
213 *len = 2; /* Move past the 'x{' */
214 /* XXX The corresponding message above for \o is just '\\o{'; other
215 * messages for other constructs include the '}', so are inconsistent.
217 *error_msg = "Missing right brace on \\x{}";
221 /* Return past the '}' no matter what is inside the braces */
222 *len = e - s + 2; /* 2 = 1 for the 'x' + 1 for the '}' */
224 s++; /* Point to first digit */
227 *uv = grok_hex(s, &numbers_len, &flags, NULL);
228 /* Note that if has non-hex, will ignore everything starting with that up
236 * c-indentation-style: bsd
238 * indent-tabs-mode: nil
241 * ex: set ts=8 sts=4 sw=4 et: