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 (! isWORDCHAR(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_ char **s, UV *uv, const char** error_msg,
89 const bool output_warning, const bool strict,
90 const bool silence_non_portable,
94 /* Documentation to be supplied when interface nailed down finally
95 * This returns FALSE if there is an error which the caller need not recover
96 * from; , otherwise TRUE. In either case the caller should look at *len
98 * s is the address of a pointer to a NULL terminated string that begins
99 * with 'o', and the previous character was a backslash. At exit, *s
100 * will be advanced to the byte just after those absorbed by this
101 * function. Hence the caller can continue parsing from there. In
102 * the case of an error, this routine has generally positioned *s to
103 * point just to the right of the first bad spot, so that a message
104 * that has a "<--" to mark the spot will be correctly positioned.
105 * uv points to a UV that will hold the output value, valid only if the
106 * return from the function is TRUE
107 * error_msg is a pointer that will be set to an internal buffer giving an
108 * error message upon failure (the return is FALSE). Untouched if
110 * output_warning says whether to output any warning messages, or suppress
112 * strict is true if this should fail instead of warn if there are
113 * non-octal digits within the braces
114 * silence_non_portable is true if to suppress warnings about the code
115 * point returned being too large to fit on all platforms.
116 * UTF is true iff the string *s is encoded in UTF-8.
120 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES
121 | PERL_SCAN_DISALLOW_PREFIX
122 /* XXX Until the message is improved in grok_oct, handle errors
124 | PERL_SCAN_SILENT_ILLDIGIT;
126 PERL_ARGS_ASSERT_GROK_BSLASH_O;
133 *error_msg = "Missing braces on \\o{}";
139 (*s)++; /* Move past the '{' */
140 while (isOCTAL(**s)) { /* Position beyond the legal digits */
143 *error_msg = "Missing right brace on \\o{";
147 (*s)++; /* Point to expected first digit (could be first byte of utf8
148 sequence if not a digit) */
149 numbers_len = e - *s;
150 if (numbers_len == 0) {
151 (*s)++; /* Move past the } */
152 *error_msg = "Number with no digits";
156 if (silence_non_portable) {
157 flags |= PERL_SCAN_SILENT_NON_PORTABLE;
160 *uv = grok_oct(*s, &numbers_len, &flags, NULL);
161 /* Note that if has non-octal, will ignore everything starting with that up
164 if (numbers_len != (STRLEN) (e - *s)) {
167 *s += (UTF) ? UTF8SKIP(*s) : (STRLEN) 1;
168 *error_msg = "Non-octal character";
171 else if (output_warning) {
172 Perl_ck_warner(aTHX_ packWARN(WARN_DIGIT),
173 /* diag_listed_as: Non-octal character '%c'. Resolved as "%s" */
174 "Non-octal character '%c'. Resolved as \"\\o{%.*s}\"",
181 /* Return past the '}' */
187 PERL_STATIC_INLINE bool
188 S_grok_bslash_x(pTHX_ char **s, UV *uv, const char** error_msg,
189 const bool output_warning, const bool strict,
190 const bool silence_non_portable,
194 /* Documentation to be supplied when interface nailed down finally
195 * This returns FALSE if there is an error which the caller need not recover
196 * from; , otherwise TRUE. In either case the caller should look at *len
198 * s is the address of a pointer to a NULL terminated string that begins
199 * with 'x', and the previous character was a backslash. At exit, *s
200 * will be advanced to the byte just after those absorbed by this
201 * function. Hence the caller can continue parsing from there. In
202 * the case of an error, this routine has generally positioned *s to
203 * point just to the right of the first bad spot, so that a message
204 * that has a "<--" to mark the spot will be correctly positioned.
205 * uv points to a UV that will hold the output value, valid only if the
206 * return from the function is TRUE
207 * error_msg is a pointer that will be set to an internal buffer giving an
208 * error message upon failure (the return is FALSE). Untouched if
210 * output_warning says whether to output any warning messages, or suppress
212 * strict is true if anything out of the ordinary should cause this to
213 * fail instead of warn or be silent. For example, it requires
214 * exactly 2 digits following the \x (when there are no braces).
215 * 3 digits could be a mistake, so is forbidden in this mode.
216 * silence_non_portable is true if to suppress warnings about the code
217 * point returned being too large to fit on all platforms.
218 * UTF is true iff the string *s is encoded in UTF-8.
222 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
224 PERL_ARGS_ASSERT_GROK_BSLASH_X;
226 PERL_UNUSED_ARG(output_warning);
232 flags |= PERL_SCAN_SILENT_ILLDIGIT;
236 STRLEN len = (strict) ? 3 : 2;
238 *uv = grok_hex(*s, &len, &flags, NULL);
240 if (strict && len != 2) {
242 *s += (UTF) ? UTF8SKIP(*s) : 1;
243 *error_msg = "Non-hex character";
246 *error_msg = "Use \\x{...} for more than two hex characters";
255 (*s)++; /* Move past the '{' */
256 while (isXDIGIT(**s)) { /* Position beyond the legal digits */
259 /* XXX The corresponding message above for \o is just '\\o{'; other
260 * messages for other constructs include the '}', so are inconsistent.
262 *error_msg = "Missing right brace on \\x{}";
266 (*s)++; /* Point to expected first digit (could be first byte of utf8
267 sequence if not a digit) */
268 numbers_len = e - *s;
269 if (numbers_len == 0) {
271 (*s)++; /* Move past the } */
272 *error_msg = "Number with no digits";
278 flags |= PERL_SCAN_ALLOW_UNDERSCORES;
279 if (silence_non_portable) {
280 flags |= PERL_SCAN_SILENT_NON_PORTABLE;
283 *uv = grok_hex(*s, &numbers_len, &flags, NULL);
284 /* Note that if has non-hex, will ignore everything starting with that up
287 if (strict && numbers_len != (STRLEN) (e - *s)) {
289 *s += (UTF) ? UTF8SKIP(*s) : 1;
290 *error_msg = "Non-hex character";
294 /* Return past the '}' */
301 S_form_short_octal_warning(pTHX_
302 const char * const s, /* Points to first non-octal */
303 const STRLEN len /* Length of octals string, so
304 (s-len) points to first
307 /* Return a character string consisting of a warning message for when a
308 * string constant in octal is weird, like "\078". */
310 const char * sans_leading_zeros = s - len;
312 PERL_ARGS_ASSERT_FORM_SHORT_OCTAL_WARNING;
314 assert(*s == '8' || *s == '9');
316 /* Remove the leading zeros, retaining one zero so won't be zero length */
317 while (*sans_leading_zeros == '0') sans_leading_zeros++;
318 if (sans_leading_zeros == s) {
319 sans_leading_zeros--;
322 return Perl_form(aTHX_
323 "'%.*s' resolved to '\\o{%.*s}%c'",
324 (int) (len + 2), s - len - 1,
325 (int) (s - sans_leading_zeros), sans_leading_zeros,
331 * c-indentation-style: bsd
333 * indent-tabs-mode: nil
336 * ex: set ts=8 sts=4 sw=4 et: