Commit | Line | Data |
---|---|---|
a0d0e21e | 1 | /* toke.c |
a687059c | 2 | * |
bc89e66f | 3 | * Copyright (c) 1991-2001, Larry Wall |
a687059c | 4 | * |
d48672a2 LW |
5 | * You may distribute under the terms of either the GNU General Public |
6 | * License or the Artistic License, as specified in the README file. | |
378cc40b | 7 | * |
a0d0e21e LW |
8 | */ |
9 | ||
10 | /* | |
11 | * "It all comes from here, the stench and the peril." --Frodo | |
378cc40b LW |
12 | */ |
13 | ||
9cbb5ea2 GS |
14 | /* |
15 | * This file is the lexer for Perl. It's closely linked to the | |
4e553d73 | 16 | * parser, perly.y. |
ffb4593c NT |
17 | * |
18 | * The main routine is yylex(), which returns the next token. | |
19 | */ | |
20 | ||
378cc40b | 21 | #include "EXTERN.h" |
864dbfa3 | 22 | #define PERL_IN_TOKE_C |
378cc40b | 23 | #include "perl.h" |
378cc40b | 24 | |
d3b6f988 GS |
25 | #define yychar PL_yychar |
26 | #define yylval PL_yylval | |
27 | ||
fc36a67e | 28 | static char ident_too_long[] = "Identifier too long"; |
8903cb82 | 29 | |
acfe0abc | 30 | static void restore_rsfp(pTHX_ void *f); |
6e3aabd6 | 31 | #ifndef PERL_NO_UTF16_FILTER |
acfe0abc GS |
32 | static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen); |
33 | static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen); | |
6e3aabd6 | 34 | #endif |
51371543 | 35 | |
9059aa12 LW |
36 | #define XFAKEBRACK 128 |
37 | #define XENUMMASK 127 | |
38 | ||
39e02b42 JH |
39 | #ifdef USE_UTF8_SCRIPTS |
40 | # define UTF (!IN_BYTES) | |
2b9d42f0 | 41 | #else |
39e02b42 JH |
42 | # ifdef EBCDIC /* For now 'use utf8' does not affect tokenizer on EBCDIC */ |
43 | # define UTF (PL_linestr && DO_UTF8(PL_linestr)) | |
44 | # else | |
45 | # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8)) | |
46 | # endif | |
2b9d42f0 | 47 | #endif |
a0ed51b3 | 48 | |
61f0cdd9 | 49 | /* In variables named $^X, these are the legal values for X. |
2b92dfce GS |
50 | * 1999-02-27 mjd-perl-patch@plover.com */ |
51 | #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x))) | |
52 | ||
bf4acbe4 GS |
53 | /* On MacOS, respect nonbreaking spaces */ |
54 | #ifdef MACOS_TRADITIONAL | |
55 | #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t') | |
56 | #else | |
57 | #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t') | |
58 | #endif | |
59 | ||
ffb4593c NT |
60 | /* LEX_* are values for PL_lex_state, the state of the lexer. |
61 | * They are arranged oddly so that the guard on the switch statement | |
79072805 LW |
62 | * can get by with a single comparison (if the compiler is smart enough). |
63 | */ | |
64 | ||
fb73857a | 65 | /* #define LEX_NOTPARSING 11 is done in perl.h. */ |
66 | ||
55497cff | 67 | #define LEX_NORMAL 10 |
68 | #define LEX_INTERPNORMAL 9 | |
69 | #define LEX_INTERPCASEMOD 8 | |
70 | #define LEX_INTERPPUSH 7 | |
71 | #define LEX_INTERPSTART 6 | |
72 | #define LEX_INTERPEND 5 | |
73 | #define LEX_INTERPENDMAYBE 4 | |
74 | #define LEX_INTERPCONCAT 3 | |
75 | #define LEX_INTERPCONST 2 | |
76 | #define LEX_FORMLINE 1 | |
77 | #define LEX_KNOWNEXT 0 | |
79072805 | 78 | |
79072805 LW |
79 | #ifdef ff_next |
80 | #undef ff_next | |
d48672a2 LW |
81 | #endif |
82 | ||
a1a0e61e | 83 | #ifdef USE_PURE_BISON |
dba4d153 JH |
84 | # ifndef YYMAXLEVEL |
85 | # define YYMAXLEVEL 100 | |
86 | # endif | |
20141f0e IRC |
87 | YYSTYPE* yylval_pointer[YYMAXLEVEL]; |
88 | int* yychar_pointer[YYMAXLEVEL]; | |
6f202aea | 89 | int yyactlevel = -1; |
22c35a8c GS |
90 | # undef yylval |
91 | # undef yychar | |
20141f0e IRC |
92 | # define yylval (*yylval_pointer[yyactlevel]) |
93 | # define yychar (*yychar_pointer[yyactlevel]) | |
94 | # define PERL_YYLEX_PARAM yylval_pointer[yyactlevel],yychar_pointer[yyactlevel] | |
4e553d73 | 95 | # undef yylex |
dba4d153 | 96 | # define yylex() Perl_yylex_r(aTHX_ yylval_pointer[yyactlevel],yychar_pointer[yyactlevel]) |
a1a0e61e TD |
97 | #endif |
98 | ||
79072805 | 99 | #include "keywords.h" |
fe14fcc3 | 100 | |
ffb4593c NT |
101 | /* CLINE is a macro that ensures PL_copline has a sane value */ |
102 | ||
ae986130 LW |
103 | #ifdef CLINE |
104 | #undef CLINE | |
105 | #endif | |
57843af0 | 106 | #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline)) |
3280af22 | 107 | |
ffb4593c NT |
108 | /* |
109 | * Convenience functions to return different tokens and prime the | |
9cbb5ea2 | 110 | * lexer for the next token. They all take an argument. |
ffb4593c NT |
111 | * |
112 | * TOKEN : generic token (used for '(', DOLSHARP, etc) | |
113 | * OPERATOR : generic operator | |
114 | * AOPERATOR : assignment operator | |
115 | * PREBLOCK : beginning the block after an if, while, foreach, ... | |
116 | * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref) | |
117 | * PREREF : *EXPR where EXPR is not a simple identifier | |
118 | * TERM : expression term | |
119 | * LOOPX : loop exiting command (goto, last, dump, etc) | |
120 | * FTST : file test operator | |
121 | * FUN0 : zero-argument function | |
2d2e263d | 122 | * FUN1 : not used, except for not, which isn't a UNIOP |
ffb4593c NT |
123 | * BOop : bitwise or or xor |
124 | * BAop : bitwise and | |
125 | * SHop : shift operator | |
126 | * PWop : power operator | |
9cbb5ea2 | 127 | * PMop : pattern-matching operator |
ffb4593c NT |
128 | * Aop : addition-level operator |
129 | * Mop : multiplication-level operator | |
130 | * Eop : equality-testing operator | |
e5edeb50 | 131 | * Rop : relational operator <= != gt |
ffb4593c NT |
132 | * |
133 | * Also see LOP and lop() below. | |
134 | */ | |
135 | ||
075953c3 JH |
136 | /* Note that REPORT() and REPORT2() will be expressions that supply |
137 | * their own trailing comma, not suitable for statements as such. */ | |
998054bd | 138 | #ifdef DEBUGGING /* Serve -DT. */ |
075953c3 JH |
139 | # define REPORT(x,retval) tokereport(x,s,(int)retval), |
140 | # define REPORT2(x,retval) tokereport(x,s, yylval.ival), | |
998054bd | 141 | #else |
075953c3 JH |
142 | # define REPORT(x,retval) |
143 | # define REPORT2(x,retval) | |
998054bd SC |
144 | #endif |
145 | ||
075953c3 JH |
146 | #define TOKEN(retval) return (REPORT2("token",retval) PL_bufptr = s,(int)retval) |
147 | #define OPERATOR(retval) return (REPORT2("operator",retval) PL_expect = XTERM, PL_bufptr = s,(int)retval) | |
148 | #define AOPERATOR(retval) return ao((REPORT2("aop",retval) PL_expect = XTERM, PL_bufptr = s,(int)retval)) | |
149 | #define PREBLOCK(retval) return (REPORT2("preblock",retval) PL_expect = XBLOCK,PL_bufptr = s,(int)retval) | |
150 | #define PRETERMBLOCK(retval) return (REPORT2("pretermblock",retval) PL_expect = XTERMBLOCK,PL_bufptr = s,(int)retval) | |
151 | #define PREREF(retval) return (REPORT2("preref",retval) PL_expect = XREF,PL_bufptr = s,(int)retval) | |
152 | #define TERM(retval) return (CLINE, REPORT2("term",retval) PL_expect = XOPERATOR, PL_bufptr = s,(int)retval) | |
153 | #define LOOPX(f) return(yylval.ival=f, REPORT("loopx",f) PL_expect = XTERM,PL_bufptr = s,(int)LOOPEX) | |
154 | #define FTST(f) return(yylval.ival=f, REPORT("ftst",f) PL_expect = XTERM,PL_bufptr = s,(int)UNIOP) | |
155 | #define FUN0(f) return(yylval.ival = f, REPORT("fun0",f) PL_expect = XOPERATOR,PL_bufptr = s,(int)FUNC0) | |
156 | #define FUN1(f) return(yylval.ival = f, REPORT("fun1",f) PL_expect = XOPERATOR,PL_bufptr = s,(int)FUNC1) | |
157 | #define BOop(f) return ao((yylval.ival=f, REPORT("bitorop",f) PL_expect = XTERM,PL_bufptr = s,(int)BITOROP)) | |
158 | #define BAop(f) return ao((yylval.ival=f, REPORT("bitandop",f) PL_expect = XTERM,PL_bufptr = s,(int)BITANDOP)) | |
159 | #define SHop(f) return ao((yylval.ival=f, REPORT("shiftop",f) PL_expect = XTERM,PL_bufptr = s,(int)SHIFTOP)) | |
160 | #define PWop(f) return ao((yylval.ival=f, REPORT("powop",f) PL_expect = XTERM,PL_bufptr = s,(int)POWOP)) | |
161 | #define PMop(f) return(yylval.ival=f, REPORT("matchop",f) PL_expect = XTERM,PL_bufptr = s,(int)MATCHOP) | |
162 | #define Aop(f) return ao((yylval.ival=f, REPORT("add",f) PL_expect = XTERM,PL_bufptr = s,(int)ADDOP)) | |
163 | #define Mop(f) return ao((yylval.ival=f, REPORT("mul",f) PL_expect = XTERM,PL_bufptr = s,(int)MULOP)) | |
164 | #define Eop(f) return(yylval.ival=f, REPORT("eq",f) PL_expect = XTERM,PL_bufptr = s,(int)EQOP) | |
165 | #define Rop(f) return(yylval.ival=f, REPORT("rel",f) PL_expect = XTERM,PL_bufptr = s,(int)RELOP) | |
2f3197b3 | 166 | |
a687059c LW |
167 | /* This bit of chicanery makes a unary function followed by |
168 | * a parenthesis into a function with one argument, highest precedence. | |
169 | */ | |
2f3197b3 | 170 | #define UNI(f) return(yylval.ival = f, \ |
075953c3 | 171 | REPORT("uni",f) \ |
3280af22 NIS |
172 | PL_expect = XTERM, \ |
173 | PL_bufptr = s, \ | |
174 | PL_last_uni = PL_oldbufptr, \ | |
175 | PL_last_lop_op = f, \ | |
a687059c LW |
176 | (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) ) |
177 | ||
79072805 | 178 | #define UNIBRACK(f) return(yylval.ival = f, \ |
075953c3 | 179 | REPORT("uni",f) \ |
3280af22 NIS |
180 | PL_bufptr = s, \ |
181 | PL_last_uni = PL_oldbufptr, \ | |
79072805 LW |
182 | (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) ) |
183 | ||
9f68db38 | 184 | /* grandfather return to old style */ |
3280af22 | 185 | #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP) |
79072805 | 186 | |
8fa7f367 JH |
187 | #ifdef DEBUGGING |
188 | ||
2d00ba3b | 189 | STATIC void |
61b2116b | 190 | S_tokereport(pTHX_ char *thing, char* s, I32 rv) |
9041c2e3 | 191 | { |
998054bd | 192 | DEBUG_T({ |
9c5ffd7c | 193 | SV* report = newSVpv(thing, 0); |
29b291f7 RB |
194 | Perl_sv_catpvf(aTHX_ report, ":line %d:%"IVdf":", CopLINE(PL_curcop), |
195 | (IV)rv); | |
998054bd SC |
196 | |
197 | if (s - PL_bufptr > 0) | |
198 | sv_catpvn(report, PL_bufptr, s - PL_bufptr); | |
199 | else { | |
200 | if (PL_oldbufptr && *PL_oldbufptr) | |
201 | sv_catpv(report, PL_tokenbuf); | |
202 | } | |
203 | PerlIO_printf(Perl_debug_log, "### %s\n", SvPV_nolen(report)); | |
5f80b19c | 204 | }); |
998054bd SC |
205 | } |
206 | ||
8fa7f367 JH |
207 | #endif |
208 | ||
ffb4593c NT |
209 | /* |
210 | * S_ao | |
211 | * | |
212 | * This subroutine detects &&= and ||= and turns an ANDAND or OROR | |
213 | * into an OP_ANDASSIGN or OP_ORASSIGN | |
214 | */ | |
215 | ||
76e3520e | 216 | STATIC int |
cea2e8a9 | 217 | S_ao(pTHX_ int toketype) |
a0d0e21e | 218 | { |
3280af22 NIS |
219 | if (*PL_bufptr == '=') { |
220 | PL_bufptr++; | |
a0d0e21e LW |
221 | if (toketype == ANDAND) |
222 | yylval.ival = OP_ANDASSIGN; | |
223 | else if (toketype == OROR) | |
224 | yylval.ival = OP_ORASSIGN; | |
225 | toketype = ASSIGNOP; | |
226 | } | |
227 | return toketype; | |
228 | } | |
229 | ||
ffb4593c NT |
230 | /* |
231 | * S_no_op | |
232 | * When Perl expects an operator and finds something else, no_op | |
233 | * prints the warning. It always prints "<something> found where | |
234 | * operator expected. It prints "Missing semicolon on previous line?" | |
235 | * if the surprise occurs at the start of the line. "do you need to | |
236 | * predeclare ..." is printed out for code like "sub bar; foo bar $x" | |
237 | * where the compiler doesn't know if foo is a method call or a function. | |
238 | * It prints "Missing operator before end of line" if there's nothing | |
239 | * after the missing operator, or "... before <...>" if there is something | |
240 | * after the missing operator. | |
241 | */ | |
242 | ||
76e3520e | 243 | STATIC void |
cea2e8a9 | 244 | S_no_op(pTHX_ char *what, char *s) |
463ee0b2 | 245 | { |
3280af22 NIS |
246 | char *oldbp = PL_bufptr; |
247 | bool is_first = (PL_oldbufptr == PL_linestart); | |
68dc0745 | 248 | |
1189a94a GS |
249 | if (!s) |
250 | s = oldbp; | |
07c798fb | 251 | else |
1189a94a | 252 | PL_bufptr = s; |
cea2e8a9 | 253 | yywarn(Perl_form(aTHX_ "%s found where operator expected", what)); |
748a9306 | 254 | if (is_first) |
cea2e8a9 | 255 | Perl_warn(aTHX_ "\t(Missing semicolon on previous line?)\n"); |
7e2040f0 | 256 | else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) { |
748a9306 | 257 | char *t; |
7e2040f0 | 258 | for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ; |
3280af22 | 259 | if (t < PL_bufptr && isSPACE(*t)) |
cea2e8a9 | 260 | Perl_warn(aTHX_ "\t(Do you need to predeclare %.*s?)\n", |
3280af22 | 261 | t - PL_oldoldbufptr, PL_oldoldbufptr); |
748a9306 | 262 | } |
07c798fb HS |
263 | else { |
264 | assert(s >= oldbp); | |
cea2e8a9 | 265 | Perl_warn(aTHX_ "\t(Missing operator before %.*s?)\n", s - oldbp, oldbp); |
07c798fb | 266 | } |
3280af22 | 267 | PL_bufptr = oldbp; |
8990e307 LW |
268 | } |
269 | ||
ffb4593c NT |
270 | /* |
271 | * S_missingterm | |
272 | * Complain about missing quote/regexp/heredoc terminator. | |
273 | * If it's called with (char *)NULL then it cauterizes the line buffer. | |
274 | * If we're in a delimited string and the delimiter is a control | |
275 | * character, it's reformatted into a two-char sequence like ^C. | |
276 | * This is fatal. | |
277 | */ | |
278 | ||
76e3520e | 279 | STATIC void |
cea2e8a9 | 280 | S_missingterm(pTHX_ char *s) |
8990e307 LW |
281 | { |
282 | char tmpbuf[3]; | |
283 | char q; | |
284 | if (s) { | |
285 | char *nl = strrchr(s,'\n'); | |
d2719217 | 286 | if (nl) |
8990e307 LW |
287 | *nl = '\0'; |
288 | } | |
9d116dd7 JH |
289 | else if ( |
290 | #ifdef EBCDIC | |
291 | iscntrl(PL_multi_close) | |
292 | #else | |
293 | PL_multi_close < 32 || PL_multi_close == 127 | |
294 | #endif | |
295 | ) { | |
8990e307 | 296 | *tmpbuf = '^'; |
3280af22 | 297 | tmpbuf[1] = toCTRL(PL_multi_close); |
8990e307 LW |
298 | s = "\\n"; |
299 | tmpbuf[2] = '\0'; | |
300 | s = tmpbuf; | |
301 | } | |
302 | else { | |
3280af22 | 303 | *tmpbuf = PL_multi_close; |
8990e307 LW |
304 | tmpbuf[1] = '\0'; |
305 | s = tmpbuf; | |
306 | } | |
307 | q = strchr(s,'"') ? '\'' : '"'; | |
cea2e8a9 | 308 | Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q); |
463ee0b2 | 309 | } |
79072805 | 310 | |
ffb4593c NT |
311 | /* |
312 | * Perl_deprecate | |
ffb4593c NT |
313 | */ |
314 | ||
79072805 | 315 | void |
864dbfa3 | 316 | Perl_deprecate(pTHX_ char *s) |
a0d0e21e | 317 | { |
599cee73 | 318 | if (ckWARN(WARN_DEPRECATED)) |
cea2e8a9 | 319 | Perl_warner(aTHX_ WARN_DEPRECATED, "Use of %s is deprecated", s); |
a0d0e21e LW |
320 | } |
321 | ||
ffb4593c NT |
322 | /* |
323 | * depcom | |
9cbb5ea2 | 324 | * Deprecate a comma-less variable list. |
ffb4593c NT |
325 | */ |
326 | ||
76e3520e | 327 | STATIC void |
cea2e8a9 | 328 | S_depcom(pTHX) |
a0d0e21e LW |
329 | { |
330 | deprecate("comma-less variable list"); | |
331 | } | |
332 | ||
ffb4593c | 333 | /* |
9cbb5ea2 GS |
334 | * experimental text filters for win32 carriage-returns, utf16-to-utf8 and |
335 | * utf16-to-utf8-reversed. | |
ffb4593c NT |
336 | */ |
337 | ||
c39cd008 GS |
338 | #ifdef PERL_CR_FILTER |
339 | static void | |
340 | strip_return(SV *sv) | |
341 | { | |
342 | register char *s = SvPVX(sv); | |
343 | register char *e = s + SvCUR(sv); | |
344 | /* outer loop optimized to do nothing if there are no CR-LFs */ | |
345 | while (s < e) { | |
346 | if (*s++ == '\r' && *s == '\n') { | |
347 | /* hit a CR-LF, need to copy the rest */ | |
348 | register char *d = s - 1; | |
349 | *d++ = *s++; | |
350 | while (s < e) { | |
351 | if (*s == '\r' && s[1] == '\n') | |
352 | s++; | |
353 | *d++ = *s++; | |
354 | } | |
355 | SvCUR(sv) -= s - d; | |
356 | return; | |
357 | } | |
358 | } | |
359 | } | |
a868473f | 360 | |
76e3520e | 361 | STATIC I32 |
c39cd008 | 362 | S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
a868473f | 363 | { |
c39cd008 GS |
364 | I32 count = FILTER_READ(idx+1, sv, maxlen); |
365 | if (count > 0 && !maxlen) | |
366 | strip_return(sv); | |
367 | return count; | |
a868473f NIS |
368 | } |
369 | #endif | |
370 | ||
ffb4593c NT |
371 | /* |
372 | * Perl_lex_start | |
9cbb5ea2 GS |
373 | * Initialize variables. Uses the Perl save_stack to save its state (for |
374 | * recursive calls to the parser). | |
ffb4593c NT |
375 | */ |
376 | ||
a0d0e21e | 377 | void |
864dbfa3 | 378 | Perl_lex_start(pTHX_ SV *line) |
79072805 | 379 | { |
8990e307 LW |
380 | char *s; |
381 | STRLEN len; | |
382 | ||
3280af22 NIS |
383 | SAVEI32(PL_lex_dojoin); |
384 | SAVEI32(PL_lex_brackets); | |
3280af22 NIS |
385 | SAVEI32(PL_lex_casemods); |
386 | SAVEI32(PL_lex_starts); | |
387 | SAVEI32(PL_lex_state); | |
7766f137 | 388 | SAVEVPTR(PL_lex_inpat); |
3280af22 | 389 | SAVEI32(PL_lex_inwhat); |
18b09519 GS |
390 | if (PL_lex_state == LEX_KNOWNEXT) { |
391 | I32 toke = PL_nexttoke; | |
392 | while (--toke >= 0) { | |
393 | SAVEI32(PL_nexttype[toke]); | |
394 | SAVEVPTR(PL_nextval[toke]); | |
395 | } | |
396 | SAVEI32(PL_nexttoke); | |
18b09519 | 397 | } |
57843af0 | 398 | SAVECOPLINE(PL_curcop); |
3280af22 NIS |
399 | SAVEPPTR(PL_bufptr); |
400 | SAVEPPTR(PL_bufend); | |
401 | SAVEPPTR(PL_oldbufptr); | |
402 | SAVEPPTR(PL_oldoldbufptr); | |
207e3d1a JH |
403 | SAVEPPTR(PL_last_lop); |
404 | SAVEPPTR(PL_last_uni); | |
3280af22 NIS |
405 | SAVEPPTR(PL_linestart); |
406 | SAVESPTR(PL_linestr); | |
407 | SAVEPPTR(PL_lex_brackstack); | |
408 | SAVEPPTR(PL_lex_casestack); | |
c76ac1ee | 409 | SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp); |
3280af22 NIS |
410 | SAVESPTR(PL_lex_stuff); |
411 | SAVEI32(PL_lex_defer); | |
09bef843 | 412 | SAVEI32(PL_sublex_info.sub_inwhat); |
3280af22 | 413 | SAVESPTR(PL_lex_repl); |
bebdddfc GS |
414 | SAVEINT(PL_expect); |
415 | SAVEINT(PL_lex_expect); | |
3280af22 NIS |
416 | |
417 | PL_lex_state = LEX_NORMAL; | |
418 | PL_lex_defer = 0; | |
419 | PL_expect = XSTATE; | |
420 | PL_lex_brackets = 0; | |
3280af22 NIS |
421 | New(899, PL_lex_brackstack, 120, char); |
422 | New(899, PL_lex_casestack, 12, char); | |
423 | SAVEFREEPV(PL_lex_brackstack); | |
424 | SAVEFREEPV(PL_lex_casestack); | |
425 | PL_lex_casemods = 0; | |
426 | *PL_lex_casestack = '\0'; | |
427 | PL_lex_dojoin = 0; | |
428 | PL_lex_starts = 0; | |
429 | PL_lex_stuff = Nullsv; | |
430 | PL_lex_repl = Nullsv; | |
431 | PL_lex_inpat = 0; | |
76be56bc | 432 | PL_nexttoke = 0; |
3280af22 | 433 | PL_lex_inwhat = 0; |
09bef843 | 434 | PL_sublex_info.sub_inwhat = 0; |
3280af22 NIS |
435 | PL_linestr = line; |
436 | if (SvREADONLY(PL_linestr)) | |
437 | PL_linestr = sv_2mortal(newSVsv(PL_linestr)); | |
438 | s = SvPV(PL_linestr, len); | |
8990e307 | 439 | if (len && s[len-1] != ';') { |
3280af22 NIS |
440 | if (!(SvFLAGS(PL_linestr) & SVs_TEMP)) |
441 | PL_linestr = sv_2mortal(newSVsv(PL_linestr)); | |
442 | sv_catpvn(PL_linestr, "\n;", 2); | |
8990e307 | 443 | } |
3280af22 NIS |
444 | SvTEMP_off(PL_linestr); |
445 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr); | |
446 | PL_bufend = PL_bufptr + SvCUR(PL_linestr); | |
207e3d1a | 447 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 448 | PL_rsfp = 0; |
79072805 | 449 | } |
a687059c | 450 | |
ffb4593c NT |
451 | /* |
452 | * Perl_lex_end | |
9cbb5ea2 GS |
453 | * Finalizer for lexing operations. Must be called when the parser is |
454 | * done with the lexer. | |
ffb4593c NT |
455 | */ |
456 | ||
463ee0b2 | 457 | void |
864dbfa3 | 458 | Perl_lex_end(pTHX) |
463ee0b2 | 459 | { |
3280af22 | 460 | PL_doextract = FALSE; |
463ee0b2 LW |
461 | } |
462 | ||
ffb4593c NT |
463 | /* |
464 | * S_incline | |
465 | * This subroutine has nothing to do with tilting, whether at windmills | |
466 | * or pinball tables. Its name is short for "increment line". It | |
57843af0 | 467 | * increments the current line number in CopLINE(PL_curcop) and checks |
ffb4593c | 468 | * to see whether the line starts with a comment of the form |
9cbb5ea2 GS |
469 | * # line 500 "foo.pm" |
470 | * If so, it sets the current line number and file to the values in the comment. | |
ffb4593c NT |
471 | */ |
472 | ||
76e3520e | 473 | STATIC void |
cea2e8a9 | 474 | S_incline(pTHX_ char *s) |
463ee0b2 LW |
475 | { |
476 | char *t; | |
477 | char *n; | |
73659bf1 | 478 | char *e; |
463ee0b2 | 479 | char ch; |
463ee0b2 | 480 | |
57843af0 | 481 | CopLINE_inc(PL_curcop); |
463ee0b2 LW |
482 | if (*s++ != '#') |
483 | return; | |
bf4acbe4 | 484 | while (SPACE_OR_TAB(*s)) s++; |
73659bf1 GS |
485 | if (strnEQ(s, "line", 4)) |
486 | s += 4; | |
487 | else | |
488 | return; | |
084592ab | 489 | if (SPACE_OR_TAB(*s)) |
73659bf1 | 490 | s++; |
4e553d73 | 491 | else |
73659bf1 | 492 | return; |
bf4acbe4 | 493 | while (SPACE_OR_TAB(*s)) s++; |
463ee0b2 LW |
494 | if (!isDIGIT(*s)) |
495 | return; | |
496 | n = s; | |
497 | while (isDIGIT(*s)) | |
498 | s++; | |
bf4acbe4 | 499 | while (SPACE_OR_TAB(*s)) |
463ee0b2 | 500 | s++; |
73659bf1 | 501 | if (*s == '"' && (t = strchr(s+1, '"'))) { |
463ee0b2 | 502 | s++; |
73659bf1 GS |
503 | e = t + 1; |
504 | } | |
463ee0b2 | 505 | else { |
463ee0b2 | 506 | for (t = s; !isSPACE(*t); t++) ; |
73659bf1 | 507 | e = t; |
463ee0b2 | 508 | } |
bf4acbe4 | 509 | while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f') |
73659bf1 GS |
510 | e++; |
511 | if (*e != '\n' && *e != '\0') | |
512 | return; /* false alarm */ | |
513 | ||
463ee0b2 LW |
514 | ch = *t; |
515 | *t = '\0'; | |
f4dd75d9 GS |
516 | if (t - s > 0) { |
517 | #ifdef USE_ITHREADS | |
518 | Safefree(CopFILE(PL_curcop)); | |
519 | #else | |
520 | SvREFCNT_dec(CopFILEGV(PL_curcop)); | |
521 | #endif | |
57843af0 | 522 | CopFILE_set(PL_curcop, s); |
f4dd75d9 | 523 | } |
463ee0b2 | 524 | *t = ch; |
57843af0 | 525 | CopLINE_set(PL_curcop, atoi(n)-1); |
463ee0b2 LW |
526 | } |
527 | ||
ffb4593c NT |
528 | /* |
529 | * S_skipspace | |
530 | * Called to gobble the appropriate amount and type of whitespace. | |
531 | * Skips comments as well. | |
532 | */ | |
533 | ||
76e3520e | 534 | STATIC char * |
cea2e8a9 | 535 | S_skipspace(pTHX_ register char *s) |
a687059c | 536 | { |
3280af22 | 537 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
bf4acbe4 | 538 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
463ee0b2 LW |
539 | s++; |
540 | return s; | |
541 | } | |
542 | for (;;) { | |
fd049845 | 543 | STRLEN prevlen; |
09bef843 | 544 | SSize_t oldprevlen, oldoldprevlen; |
9c5ffd7c | 545 | SSize_t oldloplen = 0, oldunilen = 0; |
60e6418e GS |
546 | while (s < PL_bufend && isSPACE(*s)) { |
547 | if (*s++ == '\n' && PL_in_eval && !PL_rsfp) | |
548 | incline(s); | |
549 | } | |
ffb4593c NT |
550 | |
551 | /* comment */ | |
3280af22 NIS |
552 | if (s < PL_bufend && *s == '#') { |
553 | while (s < PL_bufend && *s != '\n') | |
463ee0b2 | 554 | s++; |
60e6418e | 555 | if (s < PL_bufend) { |
463ee0b2 | 556 | s++; |
60e6418e GS |
557 | if (PL_in_eval && !PL_rsfp) { |
558 | incline(s); | |
559 | continue; | |
560 | } | |
561 | } | |
463ee0b2 | 562 | } |
ffb4593c NT |
563 | |
564 | /* only continue to recharge the buffer if we're at the end | |
565 | * of the buffer, we're not reading from a source filter, and | |
566 | * we're in normal lexing mode | |
567 | */ | |
09bef843 SB |
568 | if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat || |
569 | PL_lex_state == LEX_FORMLINE) | |
463ee0b2 | 570 | return s; |
ffb4593c NT |
571 | |
572 | /* try to recharge the buffer */ | |
9cbb5ea2 GS |
573 | if ((s = filter_gets(PL_linestr, PL_rsfp, |
574 | (prevlen = SvCUR(PL_linestr)))) == Nullch) | |
575 | { | |
576 | /* end of file. Add on the -p or -n magic */ | |
3280af22 NIS |
577 | if (PL_minus_n || PL_minus_p) { |
578 | sv_setpv(PL_linestr,PL_minus_p ? | |
08e9d68e DD |
579 | ";}continue{print or die qq(-p destination: $!\\n)" : |
580 | ""); | |
3280af22 NIS |
581 | sv_catpv(PL_linestr,";}"); |
582 | PL_minus_n = PL_minus_p = 0; | |
a0d0e21e LW |
583 | } |
584 | else | |
3280af22 | 585 | sv_setpv(PL_linestr,";"); |
ffb4593c NT |
586 | |
587 | /* reset variables for next time we lex */ | |
9cbb5ea2 GS |
588 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart |
589 | = SvPVX(PL_linestr); | |
3280af22 | 590 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 591 | PL_last_lop = PL_last_uni = Nullch; |
ffb4593c NT |
592 | |
593 | /* Close the filehandle. Could be from -P preprocessor, | |
594 | * STDIN, or a regular file. If we were reading code from | |
595 | * STDIN (because the commandline held no -e or filename) | |
596 | * then we don't close it, we reset it so the code can | |
597 | * read from STDIN too. | |
598 | */ | |
599 | ||
3280af22 NIS |
600 | if (PL_preprocess && !PL_in_eval) |
601 | (void)PerlProc_pclose(PL_rsfp); | |
602 | else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) | |
603 | PerlIO_clearerr(PL_rsfp); | |
8990e307 | 604 | else |
3280af22 NIS |
605 | (void)PerlIO_close(PL_rsfp); |
606 | PL_rsfp = Nullfp; | |
463ee0b2 LW |
607 | return s; |
608 | } | |
ffb4593c NT |
609 | |
610 | /* not at end of file, so we only read another line */ | |
09bef843 SB |
611 | /* make corresponding updates to old pointers, for yyerror() */ |
612 | oldprevlen = PL_oldbufptr - PL_bufend; | |
613 | oldoldprevlen = PL_oldoldbufptr - PL_bufend; | |
614 | if (PL_last_uni) | |
615 | oldunilen = PL_last_uni - PL_bufend; | |
616 | if (PL_last_lop) | |
617 | oldloplen = PL_last_lop - PL_bufend; | |
3280af22 NIS |
618 | PL_linestart = PL_bufptr = s + prevlen; |
619 | PL_bufend = s + SvCUR(PL_linestr); | |
620 | s = PL_bufptr; | |
09bef843 SB |
621 | PL_oldbufptr = s + oldprevlen; |
622 | PL_oldoldbufptr = s + oldoldprevlen; | |
623 | if (PL_last_uni) | |
624 | PL_last_uni = s + oldunilen; | |
625 | if (PL_last_lop) | |
626 | PL_last_lop = s + oldloplen; | |
a0d0e21e | 627 | incline(s); |
ffb4593c NT |
628 | |
629 | /* debugger active and we're not compiling the debugger code, | |
630 | * so store the line into the debugger's array of lines | |
631 | */ | |
3280af22 | 632 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
8990e307 LW |
633 | SV *sv = NEWSV(85,0); |
634 | ||
635 | sv_upgrade(sv, SVt_PVMG); | |
3280af22 | 636 | sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr); |
57843af0 | 637 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
8990e307 | 638 | } |
463ee0b2 | 639 | } |
a687059c | 640 | } |
378cc40b | 641 | |
ffb4593c NT |
642 | /* |
643 | * S_check_uni | |
644 | * Check the unary operators to ensure there's no ambiguity in how they're | |
645 | * used. An ambiguous piece of code would be: | |
646 | * rand + 5 | |
647 | * This doesn't mean rand() + 5. Because rand() is a unary operator, | |
648 | * the +5 is its argument. | |
649 | */ | |
650 | ||
76e3520e | 651 | STATIC void |
cea2e8a9 | 652 | S_check_uni(pTHX) |
ba106d47 | 653 | { |
2f3197b3 | 654 | char *s; |
a0d0e21e | 655 | char *t; |
2f3197b3 | 656 | |
3280af22 | 657 | if (PL_oldoldbufptr != PL_last_uni) |
2f3197b3 | 658 | return; |
3280af22 NIS |
659 | while (isSPACE(*PL_last_uni)) |
660 | PL_last_uni++; | |
7e2040f0 | 661 | for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ; |
3280af22 | 662 | if ((t = strchr(s, '(')) && t < PL_bufptr) |
a0d0e21e | 663 | return; |
0453d815 | 664 | if (ckWARN_d(WARN_AMBIGUOUS)){ |
f248d071 | 665 | char ch = *s; |
0453d815 | 666 | *s = '\0'; |
4e553d73 NIS |
667 | Perl_warner(aTHX_ WARN_AMBIGUOUS, |
668 | "Warning: Use of \"%s\" without parens is ambiguous", | |
0453d815 PM |
669 | PL_last_uni); |
670 | *s = ch; | |
671 | } | |
2f3197b3 LW |
672 | } |
673 | ||
ffb4593c NT |
674 | /* workaround to replace the UNI() macro with a function. Only the |
675 | * hints/uts.sh file mentions this. Other comments elsewhere in the | |
676 | * source indicate Microport Unix might need it too. | |
677 | */ | |
678 | ||
ffed7fef LW |
679 | #ifdef CRIPPLED_CC |
680 | ||
681 | #undef UNI | |
ffed7fef | 682 | #define UNI(f) return uni(f,s) |
ffed7fef | 683 | |
76e3520e | 684 | STATIC int |
cea2e8a9 | 685 | S_uni(pTHX_ I32 f, char *s) |
ffed7fef LW |
686 | { |
687 | yylval.ival = f; | |
3280af22 NIS |
688 | PL_expect = XTERM; |
689 | PL_bufptr = s; | |
8f872242 NIS |
690 | PL_last_uni = PL_oldbufptr; |
691 | PL_last_lop_op = f; | |
ffed7fef LW |
692 | if (*s == '(') |
693 | return FUNC1; | |
694 | s = skipspace(s); | |
695 | if (*s == '(') | |
696 | return FUNC1; | |
697 | else | |
698 | return UNIOP; | |
699 | } | |
700 | ||
a0d0e21e LW |
701 | #endif /* CRIPPLED_CC */ |
702 | ||
ffb4593c NT |
703 | /* |
704 | * LOP : macro to build a list operator. Its behaviour has been replaced | |
705 | * with a subroutine, S_lop() for which LOP is just another name. | |
706 | */ | |
707 | ||
a0d0e21e LW |
708 | #define LOP(f,x) return lop(f,x,s) |
709 | ||
ffb4593c NT |
710 | /* |
711 | * S_lop | |
712 | * Build a list operator (or something that might be one). The rules: | |
713 | * - if we have a next token, then it's a list operator [why?] | |
714 | * - if the next thing is an opening paren, then it's a function | |
715 | * - else it's a list operator | |
716 | */ | |
717 | ||
76e3520e | 718 | STATIC I32 |
a0be28da | 719 | S_lop(pTHX_ I32 f, int x, char *s) |
ffed7fef | 720 | { |
79072805 | 721 | yylval.ival = f; |
35c8bce7 | 722 | CLINE; |
075953c3 | 723 | REPORT("lop", f) |
3280af22 NIS |
724 | PL_expect = x; |
725 | PL_bufptr = s; | |
726 | PL_last_lop = PL_oldbufptr; | |
727 | PL_last_lop_op = f; | |
728 | if (PL_nexttoke) | |
a0d0e21e | 729 | return LSTOP; |
79072805 LW |
730 | if (*s == '(') |
731 | return FUNC; | |
732 | s = skipspace(s); | |
733 | if (*s == '(') | |
734 | return FUNC; | |
735 | else | |
736 | return LSTOP; | |
737 | } | |
738 | ||
ffb4593c NT |
739 | /* |
740 | * S_force_next | |
9cbb5ea2 | 741 | * When the lexer realizes it knows the next token (for instance, |
ffb4593c | 742 | * it is reordering tokens for the parser) then it can call S_force_next |
9cbb5ea2 GS |
743 | * to know what token to return the next time the lexer is called. Caller |
744 | * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer | |
745 | * handles the token correctly. | |
ffb4593c NT |
746 | */ |
747 | ||
4e553d73 | 748 | STATIC void |
cea2e8a9 | 749 | S_force_next(pTHX_ I32 type) |
79072805 | 750 | { |
3280af22 NIS |
751 | PL_nexttype[PL_nexttoke] = type; |
752 | PL_nexttoke++; | |
753 | if (PL_lex_state != LEX_KNOWNEXT) { | |
754 | PL_lex_defer = PL_lex_state; | |
755 | PL_lex_expect = PL_expect; | |
756 | PL_lex_state = LEX_KNOWNEXT; | |
79072805 LW |
757 | } |
758 | } | |
759 | ||
ffb4593c NT |
760 | /* |
761 | * S_force_word | |
762 | * When the lexer knows the next thing is a word (for instance, it has | |
763 | * just seen -> and it knows that the next char is a word char, then | |
764 | * it calls S_force_word to stick the next word into the PL_next lookahead. | |
765 | * | |
766 | * Arguments: | |
b1b65b59 | 767 | * char *start : buffer position (must be within PL_linestr) |
ffb4593c NT |
768 | * int token : PL_next will be this type of bare word (e.g., METHOD,WORD) |
769 | * int check_keyword : if true, Perl checks to make sure the word isn't | |
770 | * a keyword (do this if the word is a label, e.g. goto FOO) | |
771 | * int allow_pack : if true, : characters will also be allowed (require, | |
772 | * use, etc. do this) | |
9cbb5ea2 | 773 | * int allow_initial_tick : used by the "sub" lexer only. |
ffb4593c NT |
774 | */ |
775 | ||
76e3520e | 776 | STATIC char * |
cea2e8a9 | 777 | S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick) |
79072805 | 778 | { |
463ee0b2 LW |
779 | register char *s; |
780 | STRLEN len; | |
4e553d73 | 781 | |
463ee0b2 LW |
782 | start = skipspace(start); |
783 | s = start; | |
7e2040f0 | 784 | if (isIDFIRST_lazy_if(s,UTF) || |
a0d0e21e | 785 | (allow_pack && *s == ':') || |
15f0808c | 786 | (allow_initial_tick && *s == '\'') ) |
a0d0e21e | 787 | { |
3280af22 NIS |
788 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len); |
789 | if (check_keyword && keyword(PL_tokenbuf, len)) | |
463ee0b2 LW |
790 | return start; |
791 | if (token == METHOD) { | |
792 | s = skipspace(s); | |
793 | if (*s == '(') | |
3280af22 | 794 | PL_expect = XTERM; |
463ee0b2 | 795 | else { |
3280af22 | 796 | PL_expect = XOPERATOR; |
463ee0b2 | 797 | } |
79072805 | 798 | } |
3280af22 NIS |
799 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(PL_tokenbuf,0)); |
800 | PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE; | |
79072805 LW |
801 | force_next(token); |
802 | } | |
803 | return s; | |
804 | } | |
805 | ||
ffb4593c NT |
806 | /* |
807 | * S_force_ident | |
9cbb5ea2 | 808 | * Called when the lexer wants $foo *foo &foo etc, but the program |
ffb4593c NT |
809 | * text only contains the "foo" portion. The first argument is a pointer |
810 | * to the "foo", and the second argument is the type symbol to prefix. | |
811 | * Forces the next token to be a "WORD". | |
9cbb5ea2 | 812 | * Creates the symbol if it didn't already exist (via gv_fetchpv()). |
ffb4593c NT |
813 | */ |
814 | ||
76e3520e | 815 | STATIC void |
cea2e8a9 | 816 | S_force_ident(pTHX_ register char *s, int kind) |
79072805 LW |
817 | { |
818 | if (s && *s) { | |
11343788 | 819 | OP* o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0)); |
3280af22 | 820 | PL_nextval[PL_nexttoke].opval = o; |
79072805 | 821 | force_next(WORD); |
748a9306 | 822 | if (kind) { |
11343788 | 823 | o->op_private = OPpCONST_ENTERED; |
55497cff | 824 | /* XXX see note in pp_entereval() for why we forgo typo |
825 | warnings if the symbol must be introduced in an eval. | |
826 | GSAR 96-10-12 */ | |
3280af22 | 827 | gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE, |
a0d0e21e LW |
828 | kind == '$' ? SVt_PV : |
829 | kind == '@' ? SVt_PVAV : | |
830 | kind == '%' ? SVt_PVHV : | |
831 | SVt_PVGV | |
832 | ); | |
748a9306 | 833 | } |
79072805 LW |
834 | } |
835 | } | |
836 | ||
1571675a GS |
837 | NV |
838 | Perl_str_to_version(pTHX_ SV *sv) | |
839 | { | |
840 | NV retval = 0.0; | |
841 | NV nshift = 1.0; | |
842 | STRLEN len; | |
843 | char *start = SvPVx(sv,len); | |
3aa33fe5 | 844 | bool utf = SvUTF8(sv) ? TRUE : FALSE; |
1571675a GS |
845 | char *end = start + len; |
846 | while (start < end) { | |
ba210ebe | 847 | STRLEN skip; |
1571675a GS |
848 | UV n; |
849 | if (utf) | |
9041c2e3 | 850 | n = utf8n_to_uvchr((U8*)start, len, &skip, 0); |
1571675a GS |
851 | else { |
852 | n = *(U8*)start; | |
853 | skip = 1; | |
854 | } | |
855 | retval += ((NV)n)/nshift; | |
856 | start += skip; | |
857 | nshift *= 1000; | |
858 | } | |
859 | return retval; | |
860 | } | |
861 | ||
4e553d73 | 862 | /* |
ffb4593c NT |
863 | * S_force_version |
864 | * Forces the next token to be a version number. | |
e759cc13 RGS |
865 | * If the next token appears to be an invalid version number, (e.g. "v2b"), |
866 | * and if "guessing" is TRUE, then no new token is created (and the caller | |
867 | * must use an alternative parsing method). | |
ffb4593c NT |
868 | */ |
869 | ||
76e3520e | 870 | STATIC char * |
e759cc13 | 871 | S_force_version(pTHX_ char *s, int guessing) |
89bfa8cd | 872 | { |
873 | OP *version = Nullop; | |
44dcb63b | 874 | char *d; |
89bfa8cd | 875 | |
876 | s = skipspace(s); | |
877 | ||
44dcb63b | 878 | d = s; |
dd629d5b | 879 | if (*d == 'v') |
44dcb63b | 880 | d++; |
44dcb63b | 881 | if (isDIGIT(*d)) { |
e759cc13 RGS |
882 | while (isDIGIT(*d) || *d == '_' || *d == '.') |
883 | d++; | |
9f3d182e | 884 | if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) { |
dd629d5b | 885 | SV *ver; |
b73d6f50 | 886 | s = scan_num(s, &yylval); |
89bfa8cd | 887 | version = yylval.opval; |
dd629d5b GS |
888 | ver = cSVOPx(version)->op_sv; |
889 | if (SvPOK(ver) && !SvNIOK(ver)) { | |
155aba94 | 890 | (void)SvUPGRADE(ver, SVt_PVNV); |
1571675a GS |
891 | SvNVX(ver) = str_to_version(ver); |
892 | SvNOK_on(ver); /* hint that it is a version */ | |
44dcb63b | 893 | } |
89bfa8cd | 894 | } |
e759cc13 RGS |
895 | else if (guessing) |
896 | return s; | |
89bfa8cd | 897 | } |
898 | ||
899 | /* NOTE: The parser sees the package name and the VERSION swapped */ | |
3280af22 | 900 | PL_nextval[PL_nexttoke].opval = version; |
4e553d73 | 901 | force_next(WORD); |
89bfa8cd | 902 | |
e759cc13 | 903 | return s; |
89bfa8cd | 904 | } |
905 | ||
ffb4593c NT |
906 | /* |
907 | * S_tokeq | |
908 | * Tokenize a quoted string passed in as an SV. It finds the next | |
909 | * chunk, up to end of string or a backslash. It may make a new | |
910 | * SV containing that chunk (if HINT_NEW_STRING is on). It also | |
911 | * turns \\ into \. | |
912 | */ | |
913 | ||
76e3520e | 914 | STATIC SV * |
cea2e8a9 | 915 | S_tokeq(pTHX_ SV *sv) |
79072805 LW |
916 | { |
917 | register char *s; | |
918 | register char *send; | |
919 | register char *d; | |
b3ac6de7 IZ |
920 | STRLEN len = 0; |
921 | SV *pv = sv; | |
79072805 LW |
922 | |
923 | if (!SvLEN(sv)) | |
b3ac6de7 | 924 | goto finish; |
79072805 | 925 | |
a0d0e21e | 926 | s = SvPV_force(sv, len); |
21a311ee | 927 | if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1) |
b3ac6de7 | 928 | goto finish; |
463ee0b2 | 929 | send = s + len; |
79072805 LW |
930 | while (s < send && *s != '\\') |
931 | s++; | |
932 | if (s == send) | |
b3ac6de7 | 933 | goto finish; |
79072805 | 934 | d = s; |
be4731d2 | 935 | if ( PL_hints & HINT_NEW_STRING ) { |
79cb57f6 | 936 | pv = sv_2mortal(newSVpvn(SvPVX(pv), len)); |
be4731d2 NIS |
937 | if (SvUTF8(sv)) |
938 | SvUTF8_on(pv); | |
939 | } | |
79072805 LW |
940 | while (s < send) { |
941 | if (*s == '\\') { | |
a0d0e21e | 942 | if (s + 1 < send && (s[1] == '\\')) |
79072805 LW |
943 | s++; /* all that, just for this */ |
944 | } | |
945 | *d++ = *s++; | |
946 | } | |
947 | *d = '\0'; | |
463ee0b2 | 948 | SvCUR_set(sv, d - SvPVX(sv)); |
b3ac6de7 | 949 | finish: |
3280af22 | 950 | if ( PL_hints & HINT_NEW_STRING ) |
b3ac6de7 | 951 | return new_constant(NULL, 0, "q", sv, pv, "q"); |
79072805 LW |
952 | return sv; |
953 | } | |
954 | ||
ffb4593c NT |
955 | /* |
956 | * Now come three functions related to double-quote context, | |
957 | * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when | |
958 | * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They | |
959 | * interact with PL_lex_state, and create fake ( ... ) argument lists | |
960 | * to handle functions and concatenation. | |
961 | * They assume that whoever calls them will be setting up a fake | |
962 | * join call, because each subthing puts a ',' after it. This lets | |
963 | * "lower \luPpEr" | |
964 | * become | |
965 | * join($, , 'lower ', lcfirst( 'uPpEr', ) ,) | |
966 | * | |
967 | * (I'm not sure whether the spurious commas at the end of lcfirst's | |
968 | * arguments and join's arguments are created or not). | |
969 | */ | |
970 | ||
971 | /* | |
972 | * S_sublex_start | |
973 | * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST). | |
974 | * | |
975 | * Pattern matching will set PL_lex_op to the pattern-matching op to | |
976 | * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise). | |
977 | * | |
978 | * OP_CONST and OP_READLINE are easy--just make the new op and return. | |
979 | * | |
980 | * Everything else becomes a FUNC. | |
981 | * | |
982 | * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we | |
983 | * had an OP_CONST or OP_READLINE). This just sets us up for a | |
984 | * call to S_sublex_push(). | |
985 | */ | |
986 | ||
76e3520e | 987 | STATIC I32 |
cea2e8a9 | 988 | S_sublex_start(pTHX) |
79072805 LW |
989 | { |
990 | register I32 op_type = yylval.ival; | |
79072805 LW |
991 | |
992 | if (op_type == OP_NULL) { | |
3280af22 NIS |
993 | yylval.opval = PL_lex_op; |
994 | PL_lex_op = Nullop; | |
79072805 LW |
995 | return THING; |
996 | } | |
997 | if (op_type == OP_CONST || op_type == OP_READLINE) { | |
3280af22 | 998 | SV *sv = tokeq(PL_lex_stuff); |
b3ac6de7 IZ |
999 | |
1000 | if (SvTYPE(sv) == SVt_PVIV) { | |
1001 | /* Overloaded constants, nothing fancy: Convert to SVt_PV: */ | |
1002 | STRLEN len; | |
1003 | char *p; | |
1004 | SV *nsv; | |
1005 | ||
1006 | p = SvPV(sv, len); | |
79cb57f6 | 1007 | nsv = newSVpvn(p, len); |
01ec43d0 GS |
1008 | if (SvUTF8(sv)) |
1009 | SvUTF8_on(nsv); | |
b3ac6de7 IZ |
1010 | SvREFCNT_dec(sv); |
1011 | sv = nsv; | |
4e553d73 | 1012 | } |
b3ac6de7 | 1013 | yylval.opval = (OP*)newSVOP(op_type, 0, sv); |
3280af22 | 1014 | PL_lex_stuff = Nullsv; |
79072805 LW |
1015 | return THING; |
1016 | } | |
1017 | ||
3280af22 NIS |
1018 | PL_sublex_info.super_state = PL_lex_state; |
1019 | PL_sublex_info.sub_inwhat = op_type; | |
1020 | PL_sublex_info.sub_op = PL_lex_op; | |
1021 | PL_lex_state = LEX_INTERPPUSH; | |
55497cff | 1022 | |
3280af22 NIS |
1023 | PL_expect = XTERM; |
1024 | if (PL_lex_op) { | |
1025 | yylval.opval = PL_lex_op; | |
1026 | PL_lex_op = Nullop; | |
55497cff | 1027 | return PMFUNC; |
1028 | } | |
1029 | else | |
1030 | return FUNC; | |
1031 | } | |
1032 | ||
ffb4593c NT |
1033 | /* |
1034 | * S_sublex_push | |
1035 | * Create a new scope to save the lexing state. The scope will be | |
1036 | * ended in S_sublex_done. Returns a '(', starting the function arguments | |
1037 | * to the uc, lc, etc. found before. | |
1038 | * Sets PL_lex_state to LEX_INTERPCONCAT. | |
1039 | */ | |
1040 | ||
76e3520e | 1041 | STATIC I32 |
cea2e8a9 | 1042 | S_sublex_push(pTHX) |
55497cff | 1043 | { |
f46d017c | 1044 | ENTER; |
55497cff | 1045 | |
3280af22 NIS |
1046 | PL_lex_state = PL_sublex_info.super_state; |
1047 | SAVEI32(PL_lex_dojoin); | |
1048 | SAVEI32(PL_lex_brackets); | |
3280af22 NIS |
1049 | SAVEI32(PL_lex_casemods); |
1050 | SAVEI32(PL_lex_starts); | |
1051 | SAVEI32(PL_lex_state); | |
7766f137 | 1052 | SAVEVPTR(PL_lex_inpat); |
3280af22 | 1053 | SAVEI32(PL_lex_inwhat); |
57843af0 | 1054 | SAVECOPLINE(PL_curcop); |
3280af22 | 1055 | SAVEPPTR(PL_bufptr); |
8452ff4b | 1056 | SAVEPPTR(PL_bufend); |
3280af22 NIS |
1057 | SAVEPPTR(PL_oldbufptr); |
1058 | SAVEPPTR(PL_oldoldbufptr); | |
207e3d1a JH |
1059 | SAVEPPTR(PL_last_lop); |
1060 | SAVEPPTR(PL_last_uni); | |
3280af22 NIS |
1061 | SAVEPPTR(PL_linestart); |
1062 | SAVESPTR(PL_linestr); | |
1063 | SAVEPPTR(PL_lex_brackstack); | |
1064 | SAVEPPTR(PL_lex_casestack); | |
1065 | ||
1066 | PL_linestr = PL_lex_stuff; | |
1067 | PL_lex_stuff = Nullsv; | |
1068 | ||
9cbb5ea2 GS |
1069 | PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart |
1070 | = SvPVX(PL_linestr); | |
3280af22 | 1071 | PL_bufend += SvCUR(PL_linestr); |
207e3d1a | 1072 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 NIS |
1073 | SAVEFREESV(PL_linestr); |
1074 | ||
1075 | PL_lex_dojoin = FALSE; | |
1076 | PL_lex_brackets = 0; | |
3280af22 NIS |
1077 | New(899, PL_lex_brackstack, 120, char); |
1078 | New(899, PL_lex_casestack, 12, char); | |
1079 | SAVEFREEPV(PL_lex_brackstack); | |
1080 | SAVEFREEPV(PL_lex_casestack); | |
1081 | PL_lex_casemods = 0; | |
1082 | *PL_lex_casestack = '\0'; | |
1083 | PL_lex_starts = 0; | |
1084 | PL_lex_state = LEX_INTERPCONCAT; | |
57843af0 | 1085 | CopLINE_set(PL_curcop, PL_multi_start); |
3280af22 NIS |
1086 | |
1087 | PL_lex_inwhat = PL_sublex_info.sub_inwhat; | |
1088 | if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST) | |
1089 | PL_lex_inpat = PL_sublex_info.sub_op; | |
79072805 | 1090 | else |
3280af22 | 1091 | PL_lex_inpat = Nullop; |
79072805 | 1092 | |
55497cff | 1093 | return '('; |
79072805 LW |
1094 | } |
1095 | ||
ffb4593c NT |
1096 | /* |
1097 | * S_sublex_done | |
1098 | * Restores lexer state after a S_sublex_push. | |
1099 | */ | |
1100 | ||
76e3520e | 1101 | STATIC I32 |
cea2e8a9 | 1102 | S_sublex_done(pTHX) |
79072805 | 1103 | { |
3280af22 | 1104 | if (!PL_lex_starts++) { |
9aa983d2 JH |
1105 | SV *sv = newSVpvn("",0); |
1106 | if (SvUTF8(PL_linestr)) | |
1107 | SvUTF8_on(sv); | |
3280af22 | 1108 | PL_expect = XOPERATOR; |
9aa983d2 | 1109 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
79072805 LW |
1110 | return THING; |
1111 | } | |
1112 | ||
3280af22 NIS |
1113 | if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */ |
1114 | PL_lex_state = LEX_INTERPCASEMOD; | |
cea2e8a9 | 1115 | return yylex(); |
79072805 LW |
1116 | } |
1117 | ||
ffb4593c | 1118 | /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */ |
3280af22 NIS |
1119 | if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) { |
1120 | PL_linestr = PL_lex_repl; | |
1121 | PL_lex_inpat = 0; | |
1122 | PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr); | |
1123 | PL_bufend += SvCUR(PL_linestr); | |
207e3d1a | 1124 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 NIS |
1125 | SAVEFREESV(PL_linestr); |
1126 | PL_lex_dojoin = FALSE; | |
1127 | PL_lex_brackets = 0; | |
3280af22 NIS |
1128 | PL_lex_casemods = 0; |
1129 | *PL_lex_casestack = '\0'; | |
1130 | PL_lex_starts = 0; | |
25da4f38 | 1131 | if (SvEVALED(PL_lex_repl)) { |
3280af22 NIS |
1132 | PL_lex_state = LEX_INTERPNORMAL; |
1133 | PL_lex_starts++; | |
e9fa98b2 HS |
1134 | /* we don't clear PL_lex_repl here, so that we can check later |
1135 | whether this is an evalled subst; that means we rely on the | |
1136 | logic to ensure sublex_done() is called again only via the | |
1137 | branch (in yylex()) that clears PL_lex_repl, else we'll loop */ | |
79072805 | 1138 | } |
e9fa98b2 | 1139 | else { |
3280af22 | 1140 | PL_lex_state = LEX_INTERPCONCAT; |
e9fa98b2 HS |
1141 | PL_lex_repl = Nullsv; |
1142 | } | |
79072805 | 1143 | return ','; |
ffed7fef LW |
1144 | } |
1145 | else { | |
f46d017c | 1146 | LEAVE; |
3280af22 NIS |
1147 | PL_bufend = SvPVX(PL_linestr); |
1148 | PL_bufend += SvCUR(PL_linestr); | |
1149 | PL_expect = XOPERATOR; | |
09bef843 | 1150 | PL_sublex_info.sub_inwhat = 0; |
79072805 | 1151 | return ')'; |
ffed7fef LW |
1152 | } |
1153 | } | |
1154 | ||
02aa26ce NT |
1155 | /* |
1156 | scan_const | |
1157 | ||
1158 | Extracts a pattern, double-quoted string, or transliteration. This | |
1159 | is terrifying code. | |
1160 | ||
3280af22 NIS |
1161 | It looks at lex_inwhat and PL_lex_inpat to find out whether it's |
1162 | processing a pattern (PL_lex_inpat is true), a transliteration | |
02aa26ce NT |
1163 | (lex_inwhat & OP_TRANS is true), or a double-quoted string. |
1164 | ||
9b599b2a GS |
1165 | Returns a pointer to the character scanned up to. Iff this is |
1166 | advanced from the start pointer supplied (ie if anything was | |
1167 | successfully parsed), will leave an OP for the substring scanned | |
1168 | in yylval. Caller must intuit reason for not parsing further | |
1169 | by looking at the next characters herself. | |
1170 | ||
02aa26ce NT |
1171 | In patterns: |
1172 | backslashes: | |
1173 | double-quoted style: \r and \n | |
1174 | regexp special ones: \D \s | |
1175 | constants: \x3 | |
1176 | backrefs: \1 (deprecated in substitution replacements) | |
1177 | case and quoting: \U \Q \E | |
1178 | stops on @ and $, but not for $ as tail anchor | |
1179 | ||
1180 | In transliterations: | |
1181 | characters are VERY literal, except for - not at the start or end | |
1182 | of the string, which indicates a range. scan_const expands the | |
1183 | range to the full set of intermediate characters. | |
1184 | ||
1185 | In double-quoted strings: | |
1186 | backslashes: | |
1187 | double-quoted style: \r and \n | |
1188 | constants: \x3 | |
1189 | backrefs: \1 (deprecated) | |
1190 | case and quoting: \U \Q \E | |
1191 | stops on @ and $ | |
1192 | ||
1193 | scan_const does *not* construct ops to handle interpolated strings. | |
1194 | It stops processing as soon as it finds an embedded $ or @ variable | |
1195 | and leaves it to the caller to work out what's going on. | |
1196 | ||
1197 | @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @:foo. | |
1198 | ||
1199 | $ in pattern could be $foo or could be tail anchor. Assumption: | |
1200 | it's a tail anchor if $ is the last thing in the string, or if it's | |
1201 | followed by one of ")| \n\t" | |
1202 | ||
1203 | \1 (backreferences) are turned into $1 | |
1204 | ||
1205 | The structure of the code is | |
1206 | while (there's a character to process) { | |
1207 | handle transliteration ranges | |
1208 | skip regexp comments | |
1209 | skip # initiated comments in //x patterns | |
1210 | check for embedded @foo | |
1211 | check for embedded scalars | |
1212 | if (backslash) { | |
1213 | leave intact backslashes from leave (below) | |
1214 | deprecate \1 in strings and sub replacements | |
1215 | handle string-changing backslashes \l \U \Q \E, etc. | |
1216 | switch (what was escaped) { | |
1217 | handle - in a transliteration (becomes a literal -) | |
1218 | handle \132 octal characters | |
1219 | handle 0x15 hex characters | |
1220 | handle \cV (control V) | |
1221 | handle printf backslashes (\f, \r, \n, etc) | |
1222 | } (end switch) | |
1223 | } (end if backslash) | |
1224 | } (end while character to read) | |
4e553d73 | 1225 | |
02aa26ce NT |
1226 | */ |
1227 | ||
76e3520e | 1228 | STATIC char * |
cea2e8a9 | 1229 | S_scan_const(pTHX_ char *start) |
79072805 | 1230 | { |
3280af22 | 1231 | register char *send = PL_bufend; /* end of the constant */ |
02aa26ce NT |
1232 | SV *sv = NEWSV(93, send - start); /* sv for the constant */ |
1233 | register char *s = start; /* start of the constant */ | |
1234 | register char *d = SvPVX(sv); /* destination for copies */ | |
1235 | bool dorange = FALSE; /* are we in a translit range? */ | |
c2e66d9e | 1236 | bool didrange = FALSE; /* did we just finish a range? */ |
2b9d42f0 NIS |
1237 | I32 has_utf8 = FALSE; /* Output constant is UTF8 */ |
1238 | I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */ | |
012bcf8d GS |
1239 | UV uv; |
1240 | ||
dff6d3cd | 1241 | const char *leaveit = /* set of acceptably-backslashed characters */ |
3280af22 | 1242 | PL_lex_inpat |
4a2d328f | 1243 | ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxcz0123456789[{]} \t\n\r\f\v#" |
9b599b2a | 1244 | : ""; |
79072805 | 1245 | |
2b9d42f0 NIS |
1246 | if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) { |
1247 | /* If we are doing a trans and we know we want UTF8 set expectation */ | |
1248 | has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF); | |
1249 | this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); | |
1250 | } | |
1251 | ||
1252 | ||
79072805 | 1253 | while (s < send || dorange) { |
02aa26ce | 1254 | /* get transliterations out of the way (they're most literal) */ |
3280af22 | 1255 | if (PL_lex_inwhat == OP_TRANS) { |
02aa26ce | 1256 | /* expand a range A-Z to the full set of characters. AIE! */ |
79072805 | 1257 | if (dorange) { |
1ba5c669 JH |
1258 | I32 i; /* current expanded character */ |
1259 | I32 min; /* first character in range */ | |
1260 | I32 max; /* last character in range */ | |
02aa26ce | 1261 | |
2b9d42f0 | 1262 | if (has_utf8) { |
8973db79 JH |
1263 | char *c = (char*)utf8_hop((U8*)d, -1); |
1264 | char *e = d++; | |
1265 | while (e-- > c) | |
1266 | *(e + 1) = *e; | |
25716404 | 1267 | *c = (char)UTF_TO_NATIVE(0xff); |
8973db79 JH |
1268 | /* mark the range as done, and continue */ |
1269 | dorange = FALSE; | |
1270 | didrange = TRUE; | |
1271 | continue; | |
1272 | } | |
2b9d42f0 | 1273 | |
02aa26ce | 1274 | i = d - SvPVX(sv); /* remember current offset */ |
9cbb5ea2 GS |
1275 | SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */ |
1276 | d = SvPVX(sv) + i; /* refresh d after realloc */ | |
02aa26ce NT |
1277 | d -= 2; /* eat the first char and the - */ |
1278 | ||
8ada0baa JH |
1279 | min = (U8)*d; /* first char in range */ |
1280 | max = (U8)d[1]; /* last char in range */ | |
1281 | ||
c2e66d9e | 1282 | if (min > max) { |
01ec43d0 | 1283 | Perl_croak(aTHX_ |
1ba5c669 JH |
1284 | "Invalid [] range \"%c-%c\" in transliteration operator", |
1285 | (char)min, (char)max); | |
c2e66d9e GS |
1286 | } |
1287 | ||
c7f1f016 | 1288 | #ifdef EBCDIC |
8ada0baa JH |
1289 | if ((isLOWER(min) && isLOWER(max)) || |
1290 | (isUPPER(min) && isUPPER(max))) { | |
1291 | if (isLOWER(min)) { | |
1292 | for (i = min; i <= max; i++) | |
1293 | if (isLOWER(i)) | |
db42d148 | 1294 | *d++ = NATIVE_TO_NEED(has_utf8,i); |
8ada0baa JH |
1295 | } else { |
1296 | for (i = min; i <= max; i++) | |
1297 | if (isUPPER(i)) | |
db42d148 | 1298 | *d++ = NATIVE_TO_NEED(has_utf8,i); |
8ada0baa JH |
1299 | } |
1300 | } | |
1301 | else | |
1302 | #endif | |
1303 | for (i = min; i <= max; i++) | |
1304 | *d++ = i; | |
02aa26ce NT |
1305 | |
1306 | /* mark the range as done, and continue */ | |
79072805 | 1307 | dorange = FALSE; |
01ec43d0 | 1308 | didrange = TRUE; |
79072805 | 1309 | continue; |
4e553d73 | 1310 | } |
02aa26ce NT |
1311 | |
1312 | /* range begins (ignore - as first or last char) */ | |
79072805 | 1313 | else if (*s == '-' && s+1 < send && s != start) { |
4e553d73 | 1314 | if (didrange) { |
1fafa243 | 1315 | Perl_croak(aTHX_ "Ambiguous range in transliteration operator"); |
01ec43d0 | 1316 | } |
2b9d42f0 | 1317 | if (has_utf8) { |
25716404 | 1318 | *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */ |
a0ed51b3 LW |
1319 | s++; |
1320 | continue; | |
1321 | } | |
79072805 LW |
1322 | dorange = TRUE; |
1323 | s++; | |
01ec43d0 GS |
1324 | } |
1325 | else { | |
1326 | didrange = FALSE; | |
1327 | } | |
79072805 | 1328 | } |
02aa26ce NT |
1329 | |
1330 | /* if we get here, we're not doing a transliteration */ | |
1331 | ||
0f5d15d6 IZ |
1332 | /* skip for regexp comments /(?#comment)/ and code /(?{code})/, |
1333 | except for the last char, which will be done separately. */ | |
3280af22 | 1334 | else if (*s == '(' && PL_lex_inpat && s[1] == '?') { |
cc6b7395 IZ |
1335 | if (s[2] == '#') { |
1336 | while (s < send && *s != ')') | |
db42d148 | 1337 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
155aba94 GS |
1338 | } |
1339 | else if (s[2] == '{' /* This should match regcomp.c */ | |
1340 | || ((s[2] == 'p' || s[2] == '?') && s[3] == '{')) | |
1341 | { | |
cc6b7395 | 1342 | I32 count = 1; |
0f5d15d6 | 1343 | char *regparse = s + (s[2] == '{' ? 3 : 4); |
cc6b7395 IZ |
1344 | char c; |
1345 | ||
d9f97599 GS |
1346 | while (count && (c = *regparse)) { |
1347 | if (c == '\\' && regparse[1]) | |
1348 | regparse++; | |
4e553d73 | 1349 | else if (c == '{') |
cc6b7395 | 1350 | count++; |
4e553d73 | 1351 | else if (c == '}') |
cc6b7395 | 1352 | count--; |
d9f97599 | 1353 | regparse++; |
cc6b7395 | 1354 | } |
5bdf89e7 IZ |
1355 | if (*regparse != ')') { |
1356 | regparse--; /* Leave one char for continuation. */ | |
cc6b7395 | 1357 | yyerror("Sequence (?{...}) not terminated or not {}-balanced"); |
5bdf89e7 | 1358 | } |
0f5d15d6 | 1359 | while (s < regparse) |
db42d148 | 1360 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
cc6b7395 | 1361 | } |
748a9306 | 1362 | } |
02aa26ce NT |
1363 | |
1364 | /* likewise skip #-initiated comments in //x patterns */ | |
3280af22 NIS |
1365 | else if (*s == '#' && PL_lex_inpat && |
1366 | ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) { | |
748a9306 | 1367 | while (s+1 < send && *s != '\n') |
db42d148 | 1368 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
748a9306 | 1369 | } |
02aa26ce | 1370 | |
5d1d4326 JH |
1371 | /* check for embedded arrays |
1372 | (@foo, @:foo, @'foo, @{foo}, @$foo, @+, @-) | |
1373 | */ | |
7e2040f0 | 1374 | else if (*s == '@' && s[1] |
5d1d4326 | 1375 | && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1]))) |
79072805 | 1376 | break; |
02aa26ce NT |
1377 | |
1378 | /* check for embedded scalars. only stop if we're sure it's a | |
1379 | variable. | |
1380 | */ | |
79072805 | 1381 | else if (*s == '$') { |
3280af22 | 1382 | if (!PL_lex_inpat) /* not a regexp, so $ must be var */ |
79072805 | 1383 | break; |
6002328a | 1384 | if (s + 1 < send && !strchr("()| \r\n\t", s[1])) |
79072805 LW |
1385 | break; /* in regexp, $ might be tail anchor */ |
1386 | } | |
02aa26ce | 1387 | |
2b9d42f0 NIS |
1388 | /* End of else if chain - OP_TRANS rejoin rest */ |
1389 | ||
02aa26ce | 1390 | /* backslashes */ |
79072805 LW |
1391 | if (*s == '\\' && s+1 < send) { |
1392 | s++; | |
02aa26ce NT |
1393 | |
1394 | /* some backslashes we leave behind */ | |
c9f97d15 | 1395 | if (*leaveit && *s && strchr(leaveit, *s)) { |
db42d148 NIS |
1396 | *d++ = NATIVE_TO_NEED(has_utf8,'\\'); |
1397 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); | |
79072805 LW |
1398 | continue; |
1399 | } | |
02aa26ce NT |
1400 | |
1401 | /* deprecate \1 in strings and substitution replacements */ | |
3280af22 | 1402 | if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat && |
a0d0e21e | 1403 | isDIGIT(*s) && *s != '0' && !isDIGIT(s[1])) |
79072805 | 1404 | { |
599cee73 | 1405 | if (ckWARN(WARN_SYNTAX)) |
cea2e8a9 | 1406 | Perl_warner(aTHX_ WARN_SYNTAX, "\\%c better written as $%c", *s, *s); |
79072805 LW |
1407 | *--s = '$'; |
1408 | break; | |
1409 | } | |
02aa26ce NT |
1410 | |
1411 | /* string-change backslash escapes */ | |
3280af22 | 1412 | if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) { |
79072805 LW |
1413 | --s; |
1414 | break; | |
1415 | } | |
02aa26ce NT |
1416 | |
1417 | /* if we get here, it's either a quoted -, or a digit */ | |
79072805 | 1418 | switch (*s) { |
02aa26ce NT |
1419 | |
1420 | /* quoted - in transliterations */ | |
79072805 | 1421 | case '-': |
3280af22 | 1422 | if (PL_lex_inwhat == OP_TRANS) { |
79072805 LW |
1423 | *d++ = *s++; |
1424 | continue; | |
1425 | } | |
1426 | /* FALL THROUGH */ | |
1427 | default: | |
11b8faa4 | 1428 | { |
7e84c16c | 1429 | if (ckWARN(WARN_MISC) && isALNUM(*s)) |
4e553d73 | 1430 | Perl_warner(aTHX_ WARN_MISC, |
11b8faa4 JH |
1431 | "Unrecognized escape \\%c passed through", |
1432 | *s); | |
1433 | /* default action is to copy the quoted character */ | |
f9a63242 | 1434 | goto default_action; |
11b8faa4 | 1435 | } |
02aa26ce NT |
1436 | |
1437 | /* \132 indicates an octal constant */ | |
79072805 LW |
1438 | case '0': case '1': case '2': case '3': |
1439 | case '4': case '5': case '6': case '7': | |
ba210ebe | 1440 | { |
53305cf1 NC |
1441 | I32 flags = 0; |
1442 | STRLEN len = 3; | |
1443 | uv = grok_oct(s, &len, &flags, NULL); | |
ba210ebe JH |
1444 | s += len; |
1445 | } | |
012bcf8d | 1446 | goto NUM_ESCAPE_INSERT; |
02aa26ce NT |
1447 | |
1448 | /* \x24 indicates a hex constant */ | |
79072805 | 1449 | case 'x': |
a0ed51b3 LW |
1450 | ++s; |
1451 | if (*s == '{') { | |
1452 | char* e = strchr(s, '}'); | |
a4c04bdc NC |
1453 | I32 flags = PERL_SCAN_ALLOW_UNDERSCORES | |
1454 | PERL_SCAN_DISALLOW_PREFIX; | |
53305cf1 | 1455 | STRLEN len; |
355860ce | 1456 | |
53305cf1 | 1457 | ++s; |
adaeee49 | 1458 | if (!e) { |
a0ed51b3 | 1459 | yyerror("Missing right brace on \\x{}"); |
355860ce | 1460 | continue; |
ba210ebe | 1461 | } |
53305cf1 NC |
1462 | len = e - s; |
1463 | uv = grok_hex(s, &len, &flags, NULL); | |
ba210ebe | 1464 | s = e + 1; |
a0ed51b3 LW |
1465 | } |
1466 | else { | |
ba210ebe | 1467 | { |
53305cf1 | 1468 | STRLEN len = 2; |
a4c04bdc | 1469 | I32 flags = PERL_SCAN_DISALLOW_PREFIX; |
53305cf1 | 1470 | uv = grok_hex(s, &len, &flags, NULL); |
ba210ebe JH |
1471 | s += len; |
1472 | } | |
012bcf8d GS |
1473 | } |
1474 | ||
1475 | NUM_ESCAPE_INSERT: | |
1476 | /* Insert oct or hex escaped character. | |
301d3d20 | 1477 | * There will always enough room in sv since such |
db42d148 | 1478 | * escapes will be longer than any UTF-8 sequence |
301d3d20 | 1479 | * they can end up as. */ |
ba7cea30 | 1480 | |
c7f1f016 NIS |
1481 | /* We need to map to chars to ASCII before doing the tests |
1482 | to cover EBCDIC | |
1483 | */ | |
c4d5f83a | 1484 | if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) { |
9aa983d2 | 1485 | if (!has_utf8 && uv > 255) { |
301d3d20 JH |
1486 | /* Might need to recode whatever we have |
1487 | * accumulated so far if it contains any | |
1488 | * hibit chars. | |
1489 | * | |
1490 | * (Can't we keep track of that and avoid | |
1491 | * this rescan? --jhi) | |
012bcf8d | 1492 | */ |
c7f1f016 | 1493 | int hicount = 0; |
63cd0674 NIS |
1494 | U8 *c; |
1495 | for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) { | |
c4d5f83a | 1496 | if (!NATIVE_IS_INVARIANT(*c)) { |
012bcf8d | 1497 | hicount++; |
db42d148 | 1498 | } |
012bcf8d | 1499 | } |
63cd0674 | 1500 | if (hicount) { |
db42d148 NIS |
1501 | STRLEN offset = d - SvPVX(sv); |
1502 | U8 *src, *dst; | |
1503 | d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset; | |
1504 | src = (U8 *)d - 1; | |
1505 | dst = src+hicount; | |
1506 | d += hicount; | |
1507 | while (src >= (U8 *)SvPVX(sv)) { | |
c4d5f83a | 1508 | if (!NATIVE_IS_INVARIANT(*src)) { |
63cd0674 | 1509 | U8 ch = NATIVE_TO_ASCII(*src); |
db42d148 NIS |
1510 | *dst-- = UTF8_EIGHT_BIT_LO(ch); |
1511 | *dst-- = UTF8_EIGHT_BIT_HI(ch); | |
012bcf8d GS |
1512 | } |
1513 | else { | |
63cd0674 | 1514 | *dst-- = *src; |
012bcf8d | 1515 | } |
c7f1f016 | 1516 | src--; |
012bcf8d GS |
1517 | } |
1518 | } | |
1519 | } | |
1520 | ||
9aa983d2 | 1521 | if (has_utf8 || uv > 255) { |
9041c2e3 | 1522 | d = (char*)uvchr_to_utf8((U8*)d, uv); |
4e553d73 | 1523 | has_utf8 = TRUE; |
f9a63242 JH |
1524 | if (PL_lex_inwhat == OP_TRANS && |
1525 | PL_sublex_info.sub_op) { | |
1526 | PL_sublex_info.sub_op->op_private |= | |
1527 | (PL_lex_repl ? OPpTRANS_FROM_UTF | |
1528 | : OPpTRANS_TO_UTF); | |
f9a63242 | 1529 | } |
012bcf8d | 1530 | } |
a0ed51b3 | 1531 | else { |
012bcf8d | 1532 | *d++ = (char)uv; |
a0ed51b3 | 1533 | } |
012bcf8d GS |
1534 | } |
1535 | else { | |
c4d5f83a | 1536 | *d++ = (char) uv; |
a0ed51b3 | 1537 | } |
79072805 | 1538 | continue; |
02aa26ce | 1539 | |
4a2d328f IZ |
1540 | /* \N{latin small letter a} is a named character */ |
1541 | case 'N': | |
55eda711 | 1542 | ++s; |
423cee85 JH |
1543 | if (*s == '{') { |
1544 | char* e = strchr(s, '}'); | |
155aba94 | 1545 | SV *res; |
423cee85 JH |
1546 | STRLEN len; |
1547 | char *str; | |
4e553d73 | 1548 | |
423cee85 | 1549 | if (!e) { |
5777a3f7 | 1550 | yyerror("Missing right brace on \\N{}"); |
423cee85 JH |
1551 | e = s - 1; |
1552 | goto cont_scan; | |
1553 | } | |
55eda711 JH |
1554 | res = newSVpvn(s + 1, e - s - 1); |
1555 | res = new_constant( Nullch, 0, "charnames", | |
1556 | res, Nullsv, "\\N{...}" ); | |
f9a63242 JH |
1557 | if (has_utf8) |
1558 | sv_utf8_upgrade(res); | |
423cee85 | 1559 | str = SvPV(res,len); |
89491803 | 1560 | if (!has_utf8 && SvUTF8(res)) { |
f08d6ad9 GS |
1561 | char *ostart = SvPVX(sv); |
1562 | SvCUR_set(sv, d - ostart); | |
1563 | SvPOK_on(sv); | |
e4f3eed8 | 1564 | *d = '\0'; |
f08d6ad9 | 1565 | sv_utf8_upgrade(sv); |
d2f449dd SB |
1566 | /* this just broke our allocation above... */ |
1567 | SvGROW(sv, send - start); | |
f08d6ad9 | 1568 | d = SvPVX(sv) + SvCUR(sv); |
89491803 | 1569 | has_utf8 = TRUE; |
f08d6ad9 | 1570 | } |
423cee85 JH |
1571 | if (len > e - s + 4) { |
1572 | char *odest = SvPVX(sv); | |
1573 | ||
8973db79 | 1574 | SvGROW(sv, (SvLEN(sv) + len - (e - s + 4))); |
423cee85 JH |
1575 | d = SvPVX(sv) + (d - odest); |
1576 | } | |
1577 | Copy(str, d, len, char); | |
1578 | d += len; | |
1579 | SvREFCNT_dec(res); | |
1580 | cont_scan: | |
1581 | s = e + 1; | |
1582 | } | |
1583 | else | |
5777a3f7 | 1584 | yyerror("Missing braces on \\N{}"); |
423cee85 JH |
1585 | continue; |
1586 | ||
02aa26ce | 1587 | /* \c is a control character */ |
79072805 LW |
1588 | case 'c': |
1589 | s++; | |
ba210ebe JH |
1590 | { |
1591 | U8 c = *s++; | |
c7f1f016 NIS |
1592 | #ifdef EBCDIC |
1593 | if (isLOWER(c)) | |
1594 | c = toUPPER(c); | |
1595 | #endif | |
db42d148 | 1596 | *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c)); |
ba210ebe | 1597 | } |
79072805 | 1598 | continue; |
02aa26ce NT |
1599 | |
1600 | /* printf-style backslashes, formfeeds, newlines, etc */ | |
79072805 | 1601 | case 'b': |
db42d148 | 1602 | *d++ = NATIVE_TO_NEED(has_utf8,'\b'); |
79072805 LW |
1603 | break; |
1604 | case 'n': | |
db42d148 | 1605 | *d++ = NATIVE_TO_NEED(has_utf8,'\n'); |
79072805 LW |
1606 | break; |
1607 | case 'r': | |
db42d148 | 1608 | *d++ = NATIVE_TO_NEED(has_utf8,'\r'); |
79072805 LW |
1609 | break; |
1610 | case 'f': | |
db42d148 | 1611 | *d++ = NATIVE_TO_NEED(has_utf8,'\f'); |
79072805 LW |
1612 | break; |
1613 | case 't': | |
db42d148 | 1614 | *d++ = NATIVE_TO_NEED(has_utf8,'\t'); |
79072805 | 1615 | break; |
34a3fe2a | 1616 | case 'e': |
db42d148 | 1617 | *d++ = ASCII_TO_NEED(has_utf8,'\033'); |
34a3fe2a PP |
1618 | break; |
1619 | case 'a': | |
db42d148 | 1620 | *d++ = ASCII_TO_NEED(has_utf8,'\007'); |
79072805 | 1621 | break; |
02aa26ce NT |
1622 | } /* end switch */ |
1623 | ||
79072805 LW |
1624 | s++; |
1625 | continue; | |
02aa26ce NT |
1626 | } /* end if (backslash) */ |
1627 | ||
f9a63242 | 1628 | default_action: |
2b9d42f0 NIS |
1629 | /* If we started with encoded form, or already know we want it |
1630 | and then encode the next character */ | |
1631 | if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) { | |
1632 | STRLEN len = 1; | |
1633 | UV uv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s); | |
1634 | STRLEN need = UNISKIP(NATIVE_TO_UNI(uv)); | |
1635 | s += len; | |
1636 | if (need > len) { | |
1637 | /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */ | |
1638 | STRLEN off = d - SvPVX(sv); | |
1639 | d = SvGROW(sv, SvLEN(sv) + (need-len)) + off; | |
1640 | } | |
1641 | d = (char*)uvchr_to_utf8((U8*)d, uv); | |
1642 | has_utf8 = TRUE; | |
1643 | } | |
1644 | else { | |
1645 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); | |
1646 | } | |
02aa26ce NT |
1647 | } /* while loop to process each character */ |
1648 | ||
1649 | /* terminate the string and set up the sv */ | |
79072805 | 1650 | *d = '\0'; |
463ee0b2 | 1651 | SvCUR_set(sv, d - SvPVX(sv)); |
2b9d42f0 | 1652 | if (SvCUR(sv) >= SvLEN(sv)) |
585602fa | 1653 | Perl_croak(aTHX_ "panic: constant overflowed allocated space"); |
2b9d42f0 | 1654 | |
79072805 | 1655 | SvPOK_on(sv); |
2b9d42f0 | 1656 | if (has_utf8) { |
7e2040f0 | 1657 | SvUTF8_on(sv); |
2b9d42f0 NIS |
1658 | if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) { |
1659 | PL_sublex_info.sub_op->op_private |= | |
1660 | (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); | |
1661 | } | |
1662 | } | |
79072805 | 1663 | |
02aa26ce | 1664 | /* shrink the sv if we allocated more than we used */ |
79072805 LW |
1665 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
1666 | SvLEN_set(sv, SvCUR(sv) + 1); | |
463ee0b2 | 1667 | Renew(SvPVX(sv), SvLEN(sv), char); |
79072805 | 1668 | } |
02aa26ce | 1669 | |
9b599b2a | 1670 | /* return the substring (via yylval) only if we parsed anything */ |
3280af22 NIS |
1671 | if (s > PL_bufptr) { |
1672 | if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) | |
4e553d73 | 1673 | sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"), |
b3ac6de7 | 1674 | sv, Nullsv, |
4e553d73 | 1675 | ( PL_lex_inwhat == OP_TRANS |
b3ac6de7 | 1676 | ? "tr" |
3280af22 | 1677 | : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) |
b3ac6de7 IZ |
1678 | ? "s" |
1679 | : "qq"))); | |
79072805 | 1680 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
b3ac6de7 | 1681 | } else |
8990e307 | 1682 | SvREFCNT_dec(sv); |
79072805 LW |
1683 | return s; |
1684 | } | |
1685 | ||
ffb4593c NT |
1686 | /* S_intuit_more |
1687 | * Returns TRUE if there's more to the expression (e.g., a subscript), | |
1688 | * FALSE otherwise. | |
ffb4593c NT |
1689 | * |
1690 | * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/ | |
1691 | * | |
1692 | * ->[ and ->{ return TRUE | |
1693 | * { and [ outside a pattern are always subscripts, so return TRUE | |
1694 | * if we're outside a pattern and it's not { or [, then return FALSE | |
1695 | * if we're in a pattern and the first char is a { | |
1696 | * {4,5} (any digits around the comma) returns FALSE | |
1697 | * if we're in a pattern and the first char is a [ | |
1698 | * [] returns FALSE | |
1699 | * [SOMETHING] has a funky algorithm to decide whether it's a | |
1700 | * character class or not. It has to deal with things like | |
1701 | * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/ | |
1702 | * anything else returns TRUE | |
1703 | */ | |
1704 | ||
9cbb5ea2 GS |
1705 | /* This is the one truly awful dwimmer necessary to conflate C and sed. */ |
1706 | ||
76e3520e | 1707 | STATIC int |
cea2e8a9 | 1708 | S_intuit_more(pTHX_ register char *s) |
79072805 | 1709 | { |
3280af22 | 1710 | if (PL_lex_brackets) |
79072805 LW |
1711 | return TRUE; |
1712 | if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{')) | |
1713 | return TRUE; | |
1714 | if (*s != '{' && *s != '[') | |
1715 | return FALSE; | |
3280af22 | 1716 | if (!PL_lex_inpat) |
79072805 LW |
1717 | return TRUE; |
1718 | ||
1719 | /* In a pattern, so maybe we have {n,m}. */ | |
1720 | if (*s == '{') { | |
1721 | s++; | |
1722 | if (!isDIGIT(*s)) | |
1723 | return TRUE; | |
1724 | while (isDIGIT(*s)) | |
1725 | s++; | |
1726 | if (*s == ',') | |
1727 | s++; | |
1728 | while (isDIGIT(*s)) | |
1729 | s++; | |
1730 | if (*s == '}') | |
1731 | return FALSE; | |
1732 | return TRUE; | |
1733 | ||
1734 | } | |
1735 | ||
1736 | /* On the other hand, maybe we have a character class */ | |
1737 | ||
1738 | s++; | |
1739 | if (*s == ']' || *s == '^') | |
1740 | return FALSE; | |
1741 | else { | |
ffb4593c | 1742 | /* this is terrifying, and it works */ |
79072805 LW |
1743 | int weight = 2; /* let's weigh the evidence */ |
1744 | char seen[256]; | |
f27ffc4a | 1745 | unsigned char un_char = 255, last_un_char; |
93a17b20 | 1746 | char *send = strchr(s,']'); |
3280af22 | 1747 | char tmpbuf[sizeof PL_tokenbuf * 4]; |
79072805 LW |
1748 | |
1749 | if (!send) /* has to be an expression */ | |
1750 | return TRUE; | |
1751 | ||
1752 | Zero(seen,256,char); | |
1753 | if (*s == '$') | |
1754 | weight -= 3; | |
1755 | else if (isDIGIT(*s)) { | |
1756 | if (s[1] != ']') { | |
1757 | if (isDIGIT(s[1]) && s[2] == ']') | |
1758 | weight -= 10; | |
1759 | } | |
1760 | else | |
1761 | weight -= 100; | |
1762 | } | |
1763 | for (; s < send; s++) { | |
1764 | last_un_char = un_char; | |
1765 | un_char = (unsigned char)*s; | |
1766 | switch (*s) { | |
1767 | case '@': | |
1768 | case '&': | |
1769 | case '$': | |
1770 | weight -= seen[un_char] * 10; | |
7e2040f0 | 1771 | if (isALNUM_lazy_if(s+1,UTF)) { |
8903cb82 | 1772 | scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE); |
a0d0e21e | 1773 | if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV)) |
79072805 LW |
1774 | weight -= 100; |
1775 | else | |
1776 | weight -= 10; | |
1777 | } | |
1778 | else if (*s == '$' && s[1] && | |
93a17b20 LW |
1779 | strchr("[#!%*<>()-=",s[1])) { |
1780 | if (/*{*/ strchr("])} =",s[2])) | |
79072805 LW |
1781 | weight -= 10; |
1782 | else | |
1783 | weight -= 1; | |
1784 | } | |
1785 | break; | |
1786 | case '\\': | |
1787 | un_char = 254; | |
1788 | if (s[1]) { | |
93a17b20 | 1789 | if (strchr("wds]",s[1])) |
79072805 LW |
1790 | weight += 100; |
1791 | else if (seen['\''] || seen['"']) | |
1792 | weight += 1; | |
93a17b20 | 1793 | else if (strchr("rnftbxcav",s[1])) |
79072805 LW |
1794 | weight += 40; |
1795 | else if (isDIGIT(s[1])) { | |
1796 | weight += 40; | |
1797 | while (s[1] && isDIGIT(s[1])) | |
1798 | s++; | |
1799 | } | |
1800 | } | |
1801 | else | |
1802 | weight += 100; | |
1803 | break; | |
1804 | case '-': | |
1805 | if (s[1] == '\\') | |
1806 | weight += 50; | |
93a17b20 | 1807 | if (strchr("aA01! ",last_un_char)) |
79072805 | 1808 | weight += 30; |
93a17b20 | 1809 | if (strchr("zZ79~",s[1])) |
79072805 | 1810 | weight += 30; |
f27ffc4a GS |
1811 | if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$')) |
1812 | weight -= 5; /* cope with negative subscript */ | |
79072805 LW |
1813 | break; |
1814 | default: | |
93a17b20 | 1815 | if (!isALNUM(last_un_char) && !strchr("$@&",last_un_char) && |
79072805 LW |
1816 | isALPHA(*s) && s[1] && isALPHA(s[1])) { |
1817 | char *d = tmpbuf; | |
1818 | while (isALPHA(*s)) | |
1819 | *d++ = *s++; | |
1820 | *d = '\0'; | |
1821 | if (keyword(tmpbuf, d - tmpbuf)) | |
1822 | weight -= 150; | |
1823 | } | |
1824 | if (un_char == last_un_char + 1) | |
1825 | weight += 5; | |
1826 | weight -= seen[un_char]; | |
1827 | break; | |
1828 | } | |
1829 | seen[un_char]++; | |
1830 | } | |
1831 | if (weight >= 0) /* probably a character class */ | |
1832 | return FALSE; | |
1833 | } | |
1834 | ||
1835 | return TRUE; | |
1836 | } | |
ffed7fef | 1837 | |
ffb4593c NT |
1838 | /* |
1839 | * S_intuit_method | |
1840 | * | |
1841 | * Does all the checking to disambiguate | |
1842 | * foo bar | |
1843 | * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise | |
1844 | * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args). | |
1845 | * | |
1846 | * First argument is the stuff after the first token, e.g. "bar". | |
1847 | * | |
1848 | * Not a method if bar is a filehandle. | |
1849 | * Not a method if foo is a subroutine prototyped to take a filehandle. | |
1850 | * Not a method if it's really "Foo $bar" | |
1851 | * Method if it's "foo $bar" | |
1852 | * Not a method if it's really "print foo $bar" | |
1853 | * Method if it's really "foo package::" (interpreted as package->foo) | |
1854 | * Not a method if bar is known to be a subroutne ("sub bar; foo bar") | |
3cb0bbe5 | 1855 | * Not a method if bar is a filehandle or package, but is quoted with |
ffb4593c NT |
1856 | * => |
1857 | */ | |
1858 | ||
76e3520e | 1859 | STATIC int |
cea2e8a9 | 1860 | S_intuit_method(pTHX_ char *start, GV *gv) |
a0d0e21e LW |
1861 | { |
1862 | char *s = start + (*start == '$'); | |
3280af22 | 1863 | char tmpbuf[sizeof PL_tokenbuf]; |
a0d0e21e LW |
1864 | STRLEN len; |
1865 | GV* indirgv; | |
1866 | ||
1867 | if (gv) { | |
b6c543e3 | 1868 | CV *cv; |
a0d0e21e LW |
1869 | if (GvIO(gv)) |
1870 | return 0; | |
b6c543e3 IZ |
1871 | if ((cv = GvCVu(gv))) { |
1872 | char *proto = SvPVX(cv); | |
1873 | if (proto) { | |
1874 | if (*proto == ';') | |
1875 | proto++; | |
1876 | if (*proto == '*') | |
1877 | return 0; | |
1878 | } | |
1879 | } else | |
a0d0e21e LW |
1880 | gv = 0; |
1881 | } | |
8903cb82 | 1882 | s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
ffb4593c NT |
1883 | /* start is the beginning of the possible filehandle/object, |
1884 | * and s is the end of it | |
1885 | * tmpbuf is a copy of it | |
1886 | */ | |
1887 | ||
a0d0e21e | 1888 | if (*start == '$') { |
3280af22 | 1889 | if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf)) |
a0d0e21e LW |
1890 | return 0; |
1891 | s = skipspace(s); | |
3280af22 NIS |
1892 | PL_bufptr = start; |
1893 | PL_expect = XREF; | |
a0d0e21e LW |
1894 | return *s == '(' ? FUNCMETH : METHOD; |
1895 | } | |
1896 | if (!keyword(tmpbuf, len)) { | |
c3e0f903 GS |
1897 | if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') { |
1898 | len -= 2; | |
1899 | tmpbuf[len] = '\0'; | |
1900 | goto bare_package; | |
1901 | } | |
1902 | indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV); | |
8ebc5c01 | 1903 | if (indirgv && GvCVu(indirgv)) |
a0d0e21e LW |
1904 | return 0; |
1905 | /* filehandle or package name makes it a method */ | |
89bfa8cd | 1906 | if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) { |
a0d0e21e | 1907 | s = skipspace(s); |
3280af22 | 1908 | if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>') |
55497cff | 1909 | return 0; /* no assumptions -- "=>" quotes bearword */ |
c3e0f903 | 1910 | bare_package: |
3280af22 | 1911 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, |
79cb57f6 | 1912 | newSVpvn(tmpbuf,len)); |
3280af22 NIS |
1913 | PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE; |
1914 | PL_expect = XTERM; | |
a0d0e21e | 1915 | force_next(WORD); |
3280af22 | 1916 | PL_bufptr = s; |
a0d0e21e LW |
1917 | return *s == '(' ? FUNCMETH : METHOD; |
1918 | } | |
1919 | } | |
1920 | return 0; | |
1921 | } | |
1922 | ||
ffb4593c NT |
1923 | /* |
1924 | * S_incl_perldb | |
1925 | * Return a string of Perl code to load the debugger. If PERL5DB | |
1926 | * is set, it will return the contents of that, otherwise a | |
1927 | * compile-time require of perl5db.pl. | |
1928 | */ | |
1929 | ||
76e3520e | 1930 | STATIC char* |
cea2e8a9 | 1931 | S_incl_perldb(pTHX) |
a0d0e21e | 1932 | { |
3280af22 | 1933 | if (PL_perldb) { |
76e3520e | 1934 | char *pdb = PerlEnv_getenv("PERL5DB"); |
a0d0e21e LW |
1935 | |
1936 | if (pdb) | |
1937 | return pdb; | |
61bb5906 | 1938 | SETERRNO(0,SS$_NORMAL); |
a0d0e21e LW |
1939 | return "BEGIN { require 'perl5db.pl' }"; |
1940 | } | |
1941 | return ""; | |
1942 | } | |
1943 | ||
1944 | ||
16d20bd9 | 1945 | /* Encoded script support. filter_add() effectively inserts a |
4e553d73 | 1946 | * 'pre-processing' function into the current source input stream. |
16d20bd9 AD |
1947 | * Note that the filter function only applies to the current source file |
1948 | * (e.g., it will not affect files 'require'd or 'use'd by this one). | |
1949 | * | |
1950 | * The datasv parameter (which may be NULL) can be used to pass | |
1951 | * private data to this instance of the filter. The filter function | |
1952 | * can recover the SV using the FILTER_DATA macro and use it to | |
1953 | * store private buffers and state information. | |
1954 | * | |
1955 | * The supplied datasv parameter is upgraded to a PVIO type | |
4755096e | 1956 | * and the IoDIRP/IoANY field is used to store the function pointer, |
e0c19803 | 1957 | * and IOf_FAKE_DIRP is enabled on datasv to mark this as such. |
16d20bd9 AD |
1958 | * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for |
1959 | * private use must be set using malloc'd pointers. | |
1960 | */ | |
16d20bd9 AD |
1961 | |
1962 | SV * | |
864dbfa3 | 1963 | Perl_filter_add(pTHX_ filter_t funcp, SV *datasv) |
16d20bd9 | 1964 | { |
f4c556ac GS |
1965 | if (!funcp) |
1966 | return Nullsv; | |
1967 | ||
3280af22 NIS |
1968 | if (!PL_rsfp_filters) |
1969 | PL_rsfp_filters = newAV(); | |
16d20bd9 | 1970 | if (!datasv) |
8c52afec | 1971 | datasv = NEWSV(255,0); |
16d20bd9 | 1972 | if (!SvUPGRADE(datasv, SVt_PVIO)) |
cea2e8a9 | 1973 | Perl_die(aTHX_ "Can't upgrade filter_add data to SVt_PVIO"); |
4755096e | 1974 | IoANY(datasv) = (void *)funcp; /* stash funcp into spare field */ |
e0c19803 | 1975 | IoFLAGS(datasv) |= IOf_FAKE_DIRP; |
f4c556ac GS |
1976 | DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n", |
1977 | funcp, SvPV_nolen(datasv))); | |
3280af22 NIS |
1978 | av_unshift(PL_rsfp_filters, 1); |
1979 | av_store(PL_rsfp_filters, 0, datasv) ; | |
16d20bd9 AD |
1980 | return(datasv); |
1981 | } | |
4e553d73 | 1982 | |
16d20bd9 AD |
1983 | |
1984 | /* Delete most recently added instance of this filter function. */ | |
a0d0e21e | 1985 | void |
864dbfa3 | 1986 | Perl_filter_del(pTHX_ filter_t funcp) |
16d20bd9 | 1987 | { |
e0c19803 | 1988 | SV *datasv; |
f4c556ac | 1989 | DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", funcp)); |
3280af22 | 1990 | if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0) |
16d20bd9 AD |
1991 | return; |
1992 | /* if filter is on top of stack (usual case) just pop it off */ | |
e0c19803 | 1993 | datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters)); |
4755096e | 1994 | if (IoANY(datasv) == (void *)funcp) { |
e0c19803 | 1995 | IoFLAGS(datasv) &= ~IOf_FAKE_DIRP; |
4755096e | 1996 | IoANY(datasv) = (void *)NULL; |
3280af22 | 1997 | sv_free(av_pop(PL_rsfp_filters)); |
e50aee73 | 1998 | |
16d20bd9 AD |
1999 | return; |
2000 | } | |
2001 | /* we need to search for the correct entry and clear it */ | |
cea2e8a9 | 2002 | Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)"); |
16d20bd9 AD |
2003 | } |
2004 | ||
2005 | ||
2006 | /* Invoke the n'th filter function for the current rsfp. */ | |
2007 | I32 | |
864dbfa3 | 2008 | Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen) |
4e553d73 NIS |
2009 | |
2010 | ||
8ac85365 | 2011 | /* 0 = read one text line */ |
a0d0e21e | 2012 | { |
16d20bd9 AD |
2013 | filter_t funcp; |
2014 | SV *datasv = NULL; | |
e50aee73 | 2015 | |
3280af22 | 2016 | if (!PL_rsfp_filters) |
16d20bd9 | 2017 | return -1; |
3280af22 | 2018 | if (idx > AvFILLp(PL_rsfp_filters)){ /* Any more filters? */ |
16d20bd9 AD |
2019 | /* Provide a default input filter to make life easy. */ |
2020 | /* Note that we append to the line. This is handy. */ | |
f4c556ac GS |
2021 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2022 | "filter_read %d: from rsfp\n", idx)); | |
4e553d73 | 2023 | if (maxlen) { |
16d20bd9 AD |
2024 | /* Want a block */ |
2025 | int len ; | |
2026 | int old_len = SvCUR(buf_sv) ; | |
2027 | ||
2028 | /* ensure buf_sv is large enough */ | |
2029 | SvGROW(buf_sv, old_len + maxlen) ; | |
3280af22 NIS |
2030 | if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){ |
2031 | if (PerlIO_error(PL_rsfp)) | |
37120919 AD |
2032 | return -1; /* error */ |
2033 | else | |
2034 | return 0 ; /* end of file */ | |
2035 | } | |
16d20bd9 AD |
2036 | SvCUR_set(buf_sv, old_len + len) ; |
2037 | } else { | |
2038 | /* Want a line */ | |
3280af22 NIS |
2039 | if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) { |
2040 | if (PerlIO_error(PL_rsfp)) | |
37120919 AD |
2041 | return -1; /* error */ |
2042 | else | |
2043 | return 0 ; /* end of file */ | |
2044 | } | |
16d20bd9 AD |
2045 | } |
2046 | return SvCUR(buf_sv); | |
2047 | } | |
2048 | /* Skip this filter slot if filter has been deleted */ | |
3280af22 | 2049 | if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef){ |
f4c556ac GS |
2050 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2051 | "filter_read %d: skipped (filter deleted)\n", | |
2052 | idx)); | |
16d20bd9 AD |
2053 | return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */ |
2054 | } | |
2055 | /* Get function pointer hidden within datasv */ | |
4755096e | 2056 | funcp = (filter_t)IoANY(datasv); |
f4c556ac GS |
2057 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2058 | "filter_read %d: via function %p (%s)\n", | |
2059 | idx, funcp, SvPV_nolen(datasv))); | |
16d20bd9 AD |
2060 | /* Call function. The function is expected to */ |
2061 | /* call "FILTER_READ(idx+1, buf_sv)" first. */ | |
37120919 | 2062 | /* Return: <0:error, =0:eof, >0:not eof */ |
acfe0abc | 2063 | return (*funcp)(aTHX_ idx, buf_sv, maxlen); |
16d20bd9 AD |
2064 | } |
2065 | ||
76e3520e | 2066 | STATIC char * |
cea2e8a9 | 2067 | S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append) |
16d20bd9 | 2068 | { |
c39cd008 | 2069 | #ifdef PERL_CR_FILTER |
3280af22 | 2070 | if (!PL_rsfp_filters) { |
c39cd008 | 2071 | filter_add(S_cr_textfilter,NULL); |
a868473f NIS |
2072 | } |
2073 | #endif | |
3280af22 | 2074 | if (PL_rsfp_filters) { |
16d20bd9 | 2075 | |
55497cff | 2076 | if (!append) |
2077 | SvCUR_set(sv, 0); /* start with empty line */ | |
16d20bd9 AD |
2078 | if (FILTER_READ(0, sv, 0) > 0) |
2079 | return ( SvPVX(sv) ) ; | |
2080 | else | |
2081 | return Nullch ; | |
2082 | } | |
9d116dd7 | 2083 | else |
fd049845 | 2084 | return (sv_gets(sv, fp, append)); |
a0d0e21e LW |
2085 | } |
2086 | ||
01ec43d0 GS |
2087 | STATIC HV * |
2088 | S_find_in_my_stash(pTHX_ char *pkgname, I32 len) | |
def3634b GS |
2089 | { |
2090 | GV *gv; | |
2091 | ||
01ec43d0 | 2092 | if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__")) |
def3634b GS |
2093 | return PL_curstash; |
2094 | ||
2095 | if (len > 2 && | |
2096 | (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') && | |
01ec43d0 GS |
2097 | (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV))) |
2098 | { | |
2099 | return GvHV(gv); /* Foo:: */ | |
def3634b GS |
2100 | } |
2101 | ||
2102 | /* use constant CLASS => 'MyClass' */ | |
2103 | if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) { | |
2104 | SV *sv; | |
2105 | if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) { | |
2106 | pkgname = SvPV_nolen(sv); | |
2107 | } | |
2108 | } | |
2109 | ||
2110 | return gv_stashpv(pkgname, FALSE); | |
2111 | } | |
a0d0e21e | 2112 | |
748a9306 LW |
2113 | #ifdef DEBUGGING |
2114 | static char* exp_name[] = | |
09bef843 SB |
2115 | { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK", |
2116 | "ATTRTERM", "TERMBLOCK" | |
2117 | }; | |
748a9306 | 2118 | #endif |
463ee0b2 | 2119 | |
02aa26ce NT |
2120 | /* |
2121 | yylex | |
2122 | ||
2123 | Works out what to call the token just pulled out of the input | |
2124 | stream. The yacc parser takes care of taking the ops we return and | |
2125 | stitching them into a tree. | |
2126 | ||
2127 | Returns: | |
2128 | PRIVATEREF | |
2129 | ||
2130 | Structure: | |
2131 | if read an identifier | |
2132 | if we're in a my declaration | |
2133 | croak if they tried to say my($foo::bar) | |
2134 | build the ops for a my() declaration | |
2135 | if it's an access to a my() variable | |
2136 | are we in a sort block? | |
2137 | croak if my($a); $a <=> $b | |
2138 | build ops for access to a my() variable | |
2139 | if in a dq string, and they've said @foo and we can't find @foo | |
2140 | croak | |
2141 | build ops for a bareword | |
2142 | if we already built the token before, use it. | |
2143 | */ | |
2144 | ||
dba4d153 | 2145 | #ifdef USE_PURE_BISON |
864dbfa3 | 2146 | int |
dba4d153 | 2147 | Perl_yylex_r(pTHX_ YYSTYPE *lvalp, int *lcharp) |
378cc40b | 2148 | { |
20141f0e IRC |
2149 | int r; |
2150 | ||
6f202aea | 2151 | yyactlevel++; |
20141f0e IRC |
2152 | yylval_pointer[yyactlevel] = lvalp; |
2153 | yychar_pointer[yyactlevel] = lcharp; | |
b73d6f50 IRC |
2154 | if (yyactlevel >= YYMAXLEVEL) |
2155 | Perl_croak(aTHX_ "panic: YYMAXLEVEL"); | |
20141f0e | 2156 | |
dba4d153 | 2157 | r = Perl_yylex(aTHX); |
20141f0e | 2158 | |
d8ae6756 IRC |
2159 | if (yyactlevel > 0) |
2160 | yyactlevel--; | |
20141f0e IRC |
2161 | |
2162 | return r; | |
2163 | } | |
dba4d153 | 2164 | #endif |
20141f0e | 2165 | |
dba4d153 JH |
2166 | #ifdef __SC__ |
2167 | #pragma segment Perl_yylex | |
2168 | #endif | |
dba4d153 | 2169 | int |
dba4d153 | 2170 | Perl_yylex(pTHX) |
20141f0e | 2171 | { |
79072805 | 2172 | register char *s; |
378cc40b | 2173 | register char *d; |
79072805 | 2174 | register I32 tmp; |
463ee0b2 | 2175 | STRLEN len; |
161b471a NIS |
2176 | GV *gv = Nullgv; |
2177 | GV **gvp = 0; | |
aa7440fb | 2178 | bool bof = FALSE; |
a687059c | 2179 | |
02aa26ce | 2180 | /* check if there's an identifier for us to look at */ |
8eceec63 | 2181 | if (PL_pending_ident) |
e930465f | 2182 | return S_pending_ident(aTHX); |
bbce6d69 | 2183 | |
02aa26ce NT |
2184 | /* no identifier pending identification */ |
2185 | ||
3280af22 | 2186 | switch (PL_lex_state) { |
79072805 LW |
2187 | #ifdef COMMENTARY |
2188 | case LEX_NORMAL: /* Some compilers will produce faster */ | |
2189 | case LEX_INTERPNORMAL: /* code if we comment these out. */ | |
2190 | break; | |
2191 | #endif | |
2192 | ||
09bef843 | 2193 | /* when we've already built the next token, just pull it out of the queue */ |
79072805 | 2194 | case LEX_KNOWNEXT: |
3280af22 NIS |
2195 | PL_nexttoke--; |
2196 | yylval = PL_nextval[PL_nexttoke]; | |
2197 | if (!PL_nexttoke) { | |
2198 | PL_lex_state = PL_lex_defer; | |
2199 | PL_expect = PL_lex_expect; | |
2200 | PL_lex_defer = LEX_NORMAL; | |
463ee0b2 | 2201 | } |
607df283 | 2202 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
4659c93f | 2203 | "### Next token after '%s' was known, type %"IVdf"\n", PL_bufptr, |
5f80b19c | 2204 | (IV)PL_nexttype[PL_nexttoke]); }); |
607df283 | 2205 | |
3280af22 | 2206 | return(PL_nexttype[PL_nexttoke]); |
79072805 | 2207 | |
02aa26ce | 2208 | /* interpolated case modifiers like \L \U, including \Q and \E. |
3280af22 | 2209 | when we get here, PL_bufptr is at the \ |
02aa26ce | 2210 | */ |
79072805 LW |
2211 | case LEX_INTERPCASEMOD: |
2212 | #ifdef DEBUGGING | |
3280af22 | 2213 | if (PL_bufptr != PL_bufend && *PL_bufptr != '\\') |
cea2e8a9 | 2214 | Perl_croak(aTHX_ "panic: INTERPCASEMOD"); |
79072805 | 2215 | #endif |
02aa26ce | 2216 | /* handle \E or end of string */ |
3280af22 | 2217 | if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') { |
a0d0e21e | 2218 | char oldmod; |
02aa26ce NT |
2219 | |
2220 | /* if at a \E */ | |
3280af22 NIS |
2221 | if (PL_lex_casemods) { |
2222 | oldmod = PL_lex_casestack[--PL_lex_casemods]; | |
2223 | PL_lex_casestack[PL_lex_casemods] = '\0'; | |
02aa26ce | 2224 | |
3280af22 NIS |
2225 | if (PL_bufptr != PL_bufend && strchr("LUQ", oldmod)) { |
2226 | PL_bufptr += 2; | |
2227 | PL_lex_state = LEX_INTERPCONCAT; | |
a0d0e21e | 2228 | } |
79072805 LW |
2229 | return ')'; |
2230 | } | |
3280af22 NIS |
2231 | if (PL_bufptr != PL_bufend) |
2232 | PL_bufptr += 2; | |
2233 | PL_lex_state = LEX_INTERPCONCAT; | |
cea2e8a9 | 2234 | return yylex(); |
79072805 LW |
2235 | } |
2236 | else { | |
607df283 | 2237 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
5f80b19c | 2238 | "### Saw case modifier at '%s'\n", PL_bufptr); }); |
3280af22 | 2239 | s = PL_bufptr + 1; |
79072805 LW |
2240 | if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3)) |
2241 | tmp = *s, *s = s[2], s[2] = tmp; /* misordered... */ | |
a0d0e21e | 2242 | if (strchr("LU", *s) && |
3280af22 | 2243 | (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) |
a0d0e21e | 2244 | { |
3280af22 | 2245 | PL_lex_casestack[--PL_lex_casemods] = '\0'; |
a0d0e21e LW |
2246 | return ')'; |
2247 | } | |
3280af22 NIS |
2248 | if (PL_lex_casemods > 10) { |
2249 | char* newlb = Renew(PL_lex_casestack, PL_lex_casemods + 2, char); | |
2250 | if (newlb != PL_lex_casestack) { | |
a0d0e21e | 2251 | SAVEFREEPV(newlb); |
3280af22 | 2252 | PL_lex_casestack = newlb; |
a0d0e21e LW |
2253 | } |
2254 | } | |
3280af22 NIS |
2255 | PL_lex_casestack[PL_lex_casemods++] = *s; |
2256 | PL_lex_casestack[PL_lex_casemods] = '\0'; | |
2257 | PL_lex_state = LEX_INTERPCONCAT; | |
2258 | PL_nextval[PL_nexttoke].ival = 0; | |
79072805 LW |
2259 | force_next('('); |
2260 | if (*s == 'l') | |
3280af22 | 2261 | PL_nextval[PL_nexttoke].ival = OP_LCFIRST; |
79072805 | 2262 | else if (*s == 'u') |
3280af22 | 2263 | PL_nextval[PL_nexttoke].ival = OP_UCFIRST; |
79072805 | 2264 | else if (*s == 'L') |
3280af22 | 2265 | PL_nextval[PL_nexttoke].ival = OP_LC; |
79072805 | 2266 | else if (*s == 'U') |
3280af22 | 2267 | PL_nextval[PL_nexttoke].ival = OP_UC; |
a0d0e21e | 2268 | else if (*s == 'Q') |
3280af22 | 2269 | PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA; |
79072805 | 2270 | else |
cea2e8a9 | 2271 | Perl_croak(aTHX_ "panic: yylex"); |
3280af22 | 2272 | PL_bufptr = s + 1; |
79072805 | 2273 | force_next(FUNC); |
3280af22 NIS |
2274 | if (PL_lex_starts) { |
2275 | s = PL_bufptr; | |
2276 | PL_lex_starts = 0; | |
79072805 LW |
2277 | Aop(OP_CONCAT); |
2278 | } | |
2279 | else | |
cea2e8a9 | 2280 | return yylex(); |
79072805 LW |
2281 | } |
2282 | ||
55497cff | 2283 | case LEX_INTERPPUSH: |
2284 | return sublex_push(); | |
2285 | ||
79072805 | 2286 | case LEX_INTERPSTART: |
3280af22 | 2287 | if (PL_bufptr == PL_bufend) |
79072805 | 2288 | return sublex_done(); |
607df283 | 2289 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
5f80b19c | 2290 | "### Interpolated variable at '%s'\n", PL_bufptr); }); |
3280af22 NIS |
2291 | PL_expect = XTERM; |
2292 | PL_lex_dojoin = (*PL_bufptr == '@'); | |
2293 | PL_lex_state = LEX_INTERPNORMAL; | |
2294 | if (PL_lex_dojoin) { | |
2295 | PL_nextval[PL_nexttoke].ival = 0; | |
79072805 | 2296 | force_next(','); |
4d1ff10f | 2297 | #ifdef USE_5005THREADS |
533c011a NIS |
2298 | PL_nextval[PL_nexttoke].opval = newOP(OP_THREADSV, 0); |
2299 | PL_nextval[PL_nexttoke].opval->op_targ = find_threadsv("\""); | |
554b3eca MB |
2300 | force_next(PRIVATEREF); |
2301 | #else | |
a0d0e21e | 2302 | force_ident("\"", '$'); |
4d1ff10f | 2303 | #endif /* USE_5005THREADS */ |
3280af22 | 2304 | PL_nextval[PL_nexttoke].ival = 0; |
79072805 | 2305 | force_next('$'); |
3280af22 | 2306 | PL_nextval[PL_nexttoke].ival = 0; |
79072805 | 2307 | force_next('('); |
3280af22 | 2308 | PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */ |
79072805 LW |
2309 | force_next(FUNC); |
2310 | } | |
3280af22 NIS |
2311 | if (PL_lex_starts++) { |
2312 | s = PL_bufptr; | |
79072805 LW |
2313 | Aop(OP_CONCAT); |
2314 | } | |
cea2e8a9 | 2315 | return yylex(); |
79072805 LW |
2316 | |
2317 | case LEX_INTERPENDMAYBE: | |
3280af22 NIS |
2318 | if (intuit_more(PL_bufptr)) { |
2319 | PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */ | |
79072805 LW |
2320 | break; |
2321 | } | |
2322 | /* FALL THROUGH */ | |
2323 | ||
2324 | case LEX_INTERPEND: | |
3280af22 NIS |
2325 | if (PL_lex_dojoin) { |
2326 | PL_lex_dojoin = FALSE; | |
2327 | PL_lex_state = LEX_INTERPCONCAT; | |
79072805 LW |
2328 | return ')'; |
2329 | } | |
43a16006 | 2330 | if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl |
25da4f38 | 2331 | && SvEVALED(PL_lex_repl)) |
43a16006 | 2332 | { |
e9fa98b2 | 2333 | if (PL_bufptr != PL_bufend) |
cea2e8a9 | 2334 | Perl_croak(aTHX_ "Bad evalled substitution pattern"); |
e9fa98b2 HS |
2335 | PL_lex_repl = Nullsv; |
2336 | } | |
79072805 LW |
2337 | /* FALLTHROUGH */ |
2338 | case LEX_INTERPCONCAT: | |
2339 | #ifdef DEBUGGING | |
3280af22 | 2340 | if (PL_lex_brackets) |
cea2e8a9 | 2341 | Perl_croak(aTHX_ "panic: INTERPCONCAT"); |
79072805 | 2342 | #endif |
3280af22 | 2343 | if (PL_bufptr == PL_bufend) |
79072805 LW |
2344 | return sublex_done(); |
2345 | ||
3280af22 NIS |
2346 | if (SvIVX(PL_linestr) == '\'') { |
2347 | SV *sv = newSVsv(PL_linestr); | |
2348 | if (!PL_lex_inpat) | |
76e3520e | 2349 | sv = tokeq(sv); |
3280af22 | 2350 | else if ( PL_hints & HINT_NEW_RE ) |
b3ac6de7 | 2351 | sv = new_constant(NULL, 0, "qr", sv, sv, "q"); |
79072805 | 2352 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
3280af22 | 2353 | s = PL_bufend; |
79072805 LW |
2354 | } |
2355 | else { | |
3280af22 | 2356 | s = scan_const(PL_bufptr); |
79072805 | 2357 | if (*s == '\\') |
3280af22 | 2358 | PL_lex_state = LEX_INTERPCASEMOD; |
79072805 | 2359 | else |
3280af22 | 2360 | PL_lex_state = LEX_INTERPSTART; |
79072805 LW |
2361 | } |
2362 | ||
3280af22 NIS |
2363 | if (s != PL_bufptr) { |
2364 | PL_nextval[PL_nexttoke] = yylval; | |
2365 | PL_expect = XTERM; | |
79072805 | 2366 | force_next(THING); |
3280af22 | 2367 | if (PL_lex_starts++) |
79072805 LW |
2368 | Aop(OP_CONCAT); |
2369 | else { | |
3280af22 | 2370 | PL_bufptr = s; |
cea2e8a9 | 2371 | return yylex(); |
79072805 LW |
2372 | } |
2373 | } | |
2374 | ||
cea2e8a9 | 2375 | return yylex(); |
a0d0e21e | 2376 | case LEX_FORMLINE: |
3280af22 NIS |
2377 | PL_lex_state = LEX_NORMAL; |
2378 | s = scan_formline(PL_bufptr); | |
2379 | if (!PL_lex_formbrack) | |
a0d0e21e LW |
2380 | goto rightbracket; |
2381 | OPERATOR(';'); | |
79072805 LW |
2382 | } |
2383 | ||
3280af22 NIS |
2384 | s = PL_bufptr; |
2385 | PL_oldoldbufptr = PL_oldbufptr; | |
2386 | PL_oldbufptr = s; | |
607df283 | 2387 | DEBUG_T( { |
bf49b057 GS |
2388 | PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at %s\n", |
2389 | exp_name[PL_expect], s); | |
5f80b19c | 2390 | } ); |
463ee0b2 LW |
2391 | |
2392 | retry: | |
378cc40b LW |
2393 | switch (*s) { |
2394 | default: | |
7e2040f0 | 2395 | if (isIDFIRST_lazy_if(s,UTF)) |
834a4ddd | 2396 | goto keylookup; |
cea2e8a9 | 2397 | Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255); |
e929a76b LW |
2398 | case 4: |
2399 | case 26: | |
2400 | goto fake_eof; /* emulate EOF on ^D or ^Z */ | |
378cc40b | 2401 | case 0: |
3280af22 NIS |
2402 | if (!PL_rsfp) { |
2403 | PL_last_uni = 0; | |
2404 | PL_last_lop = 0; | |
2405 | if (PL_lex_brackets) | |
d98d5fff | 2406 | yyerror("Missing right curly or square bracket"); |
4e553d73 | 2407 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
607df283 | 2408 | "### Tokener got EOF\n"); |
5f80b19c | 2409 | } ); |
79072805 | 2410 | TOKEN(0); |
463ee0b2 | 2411 | } |
3280af22 | 2412 | if (s++ < PL_bufend) |
a687059c | 2413 | goto retry; /* ignore stray nulls */ |
3280af22 NIS |
2414 | PL_last_uni = 0; |
2415 | PL_last_lop = 0; | |
2416 | if (!PL_in_eval && !PL_preambled) { | |
2417 | PL_preambled = TRUE; | |
2418 | sv_setpv(PL_linestr,incl_perldb()); | |
2419 | if (SvCUR(PL_linestr)) | |
2420 | sv_catpv(PL_linestr,";"); | |
2421 | if (PL_preambleav){ | |
2422 | while(AvFILLp(PL_preambleav) >= 0) { | |
2423 | SV *tmpsv = av_shift(PL_preambleav); | |
2424 | sv_catsv(PL_linestr, tmpsv); | |
2425 | sv_catpv(PL_linestr, ";"); | |
91b7def8 | 2426 | sv_free(tmpsv); |
2427 | } | |
3280af22 NIS |
2428 | sv_free((SV*)PL_preambleav); |
2429 | PL_preambleav = NULL; | |
91b7def8 | 2430 | } |
3280af22 NIS |
2431 | if (PL_minus_n || PL_minus_p) { |
2432 | sv_catpv(PL_linestr, "LINE: while (<>) {"); | |
2433 | if (PL_minus_l) | |
2434 | sv_catpv(PL_linestr,"chomp;"); | |
2435 | if (PL_minus_a) { | |
3280af22 NIS |
2436 | if (PL_minus_F) { |
2437 | if (strchr("/'\"", *PL_splitstr) | |
2438 | && strchr(PL_splitstr + 1, *PL_splitstr)) | |
cea2e8a9 | 2439 | Perl_sv_catpvf(aTHX_ PL_linestr, "@F=split(%s);", PL_splitstr); |
54310121 | 2440 | else { |
2441 | char delim; | |
2442 | s = "'~#\200\1'"; /* surely one char is unused...*/ | |
3280af22 | 2443 | while (s[1] && strchr(PL_splitstr, *s)) s++; |
54310121 | 2444 | delim = *s; |
75c72d73 | 2445 | Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s%c", |
46fc3d4c | 2446 | "q" + (delim == '\''), delim); |
3280af22 | 2447 | for (s = PL_splitstr; *s; s++) { |
54310121 | 2448 | if (*s == '\\') |
3280af22 NIS |
2449 | sv_catpvn(PL_linestr, "\\", 1); |
2450 | sv_catpvn(PL_linestr, s, 1); | |
54310121 | 2451 | } |
cea2e8a9 | 2452 | Perl_sv_catpvf(aTHX_ PL_linestr, "%c);", delim); |
54310121 | 2453 | } |
2304df62 AD |
2454 | } |
2455 | else | |
75c72d73 | 2456 | sv_catpv(PL_linestr,"our @F=split(' ');"); |
2304df62 | 2457 | } |
79072805 | 2458 | } |
3280af22 NIS |
2459 | sv_catpv(PL_linestr, "\n"); |
2460 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); | |
2461 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2462 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 2463 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
a0d0e21e LW |
2464 | SV *sv = NEWSV(85,0); |
2465 | ||
2466 | sv_upgrade(sv, SVt_PVMG); | |
3280af22 | 2467 | sv_setsv(sv,PL_linestr); |
57843af0 | 2468 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
a0d0e21e | 2469 | } |
79072805 | 2470 | goto retry; |
a687059c | 2471 | } |
e929a76b | 2472 | do { |
aa7440fb | 2473 | bof = PL_rsfp ? TRUE : FALSE; |
7e28d3af JH |
2474 | if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) { |
2475 | fake_eof: | |
2476 | if (PL_rsfp) { | |
2477 | if (PL_preprocess && !PL_in_eval) | |
2478 | (void)PerlProc_pclose(PL_rsfp); | |
2479 | else if ((PerlIO *)PL_rsfp == PerlIO_stdin()) | |
2480 | PerlIO_clearerr(PL_rsfp); | |
2481 | else | |
2482 | (void)PerlIO_close(PL_rsfp); | |
2483 | PL_rsfp = Nullfp; | |
2484 | PL_doextract = FALSE; | |
2485 | } | |
2486 | if (!PL_in_eval && (PL_minus_n || PL_minus_p)) { | |
2487 | sv_setpv(PL_linestr,PL_minus_p ? ";}continue{print" : ""); | |
2488 | sv_catpv(PL_linestr,";}"); | |
2489 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); | |
2490 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2491 | PL_last_lop = PL_last_uni = Nullch; |
7e28d3af JH |
2492 | PL_minus_n = PL_minus_p = 0; |
2493 | goto retry; | |
2494 | } | |
2495 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); | |
207e3d1a | 2496 | PL_last_lop = PL_last_uni = Nullch; |
7e28d3af JH |
2497 | sv_setpv(PL_linestr,""); |
2498 | TOKEN(';'); /* not infinite loop because rsfp is NULL now */ | |
2499 | } | |
2500 | /* if it looks like the start of a BOM, check if it in fact is */ | |
2501 | else if (bof && (!*s || *(U8*)s == 0xEF || *(U8*)s >= 0xFE)) { | |
226017aa | 2502 | #ifdef PERLIO_IS_STDIO |
e3f494f1 JH |
2503 | # ifdef __GNU_LIBRARY__ |
2504 | # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */ | |
226017aa DD |
2505 | # define FTELL_FOR_PIPE_IS_BROKEN |
2506 | # endif | |
e3f494f1 JH |
2507 | # else |
2508 | # ifdef __GLIBC__ | |
2509 | # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */ | |
2510 | # define FTELL_FOR_PIPE_IS_BROKEN | |
2511 | # endif | |
2512 | # endif | |
226017aa DD |
2513 | # endif |
2514 | #endif | |
2515 | #ifdef FTELL_FOR_PIPE_IS_BROKEN | |
2516 | /* This loses the possibility to detect the bof | |
2517 | * situation on perl -P when the libc5 is being used. | |
2518 | * Workaround? Maybe attach some extra state to PL_rsfp? | |
2519 | */ | |
2520 | if (!PL_preprocess) | |
7e28d3af | 2521 | bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr); |
226017aa | 2522 | #else |
7e28d3af | 2523 | bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr); |
226017aa | 2524 | #endif |
7e28d3af | 2525 | if (bof) { |
3280af22 | 2526 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
7e28d3af | 2527 | s = swallow_bom((U8*)s); |
e929a76b | 2528 | } |
378cc40b | 2529 | } |
3280af22 | 2530 | if (PL_doextract) { |
a0d0e21e | 2531 | if (*s == '#' && s[1] == '!' && instr(s,"perl")) |
3280af22 | 2532 | PL_doextract = FALSE; |
a0d0e21e LW |
2533 | |
2534 | /* Incest with pod. */ | |
2535 | if (*s == '=' && strnEQ(s, "=cut", 4)) { | |
3280af22 NIS |
2536 | sv_setpv(PL_linestr, ""); |
2537 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); | |
2538 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2539 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 2540 | PL_doextract = FALSE; |
a0d0e21e | 2541 | } |
4e553d73 | 2542 | } |
463ee0b2 | 2543 | incline(s); |
3280af22 NIS |
2544 | } while (PL_doextract); |
2545 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s; | |
2546 | if (PERLDB_LINE && PL_curstash != PL_debstash) { | |
79072805 | 2547 | SV *sv = NEWSV(85,0); |
a687059c | 2548 | |
93a17b20 | 2549 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 2550 | sv_setsv(sv,PL_linestr); |
57843af0 | 2551 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
a687059c | 2552 | } |
3280af22 | 2553 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 2554 | PL_last_lop = PL_last_uni = Nullch; |
57843af0 | 2555 | if (CopLINE(PL_curcop) == 1) { |
3280af22 | 2556 | while (s < PL_bufend && isSPACE(*s)) |
79072805 | 2557 | s++; |
a0d0e21e | 2558 | if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */ |
79072805 | 2559 | s++; |
44a8e56a | 2560 | d = Nullch; |
3280af22 | 2561 | if (!PL_in_eval) { |
44a8e56a | 2562 | if (*s == '#' && *(s+1) == '!') |
2563 | d = s + 2; | |
2564 | #ifdef ALTERNATE_SHEBANG | |
2565 | else { | |
2566 | static char as[] = ALTERNATE_SHEBANG; | |
2567 | if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1)) | |
2568 | d = s + (sizeof(as) - 1); | |
2569 | } | |
2570 | #endif /* ALTERNATE_SHEBANG */ | |
2571 | } | |
2572 | if (d) { | |
b8378b72 | 2573 | char *ipath; |
774d564b | 2574 | char *ipathend; |
b8378b72 | 2575 | |
774d564b | 2576 | while (isSPACE(*d)) |
b8378b72 CS |
2577 | d++; |
2578 | ipath = d; | |
774d564b | 2579 | while (*d && !isSPACE(*d)) |
2580 | d++; | |
2581 | ipathend = d; | |
2582 | ||
2583 | #ifdef ARG_ZERO_IS_SCRIPT | |
2584 | if (ipathend > ipath) { | |
2585 | /* | |
2586 | * HP-UX (at least) sets argv[0] to the script name, | |
2587 | * which makes $^X incorrect. And Digital UNIX and Linux, | |
2588 | * at least, set argv[0] to the basename of the Perl | |
2589 | * interpreter. So, having found "#!", we'll set it right. | |
2590 | */ | |
2591 | SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV)); | |
2592 | assert(SvPOK(x) || SvGMAGICAL(x)); | |
cc49e20b | 2593 | if (sv_eq(x, CopFILESV(PL_curcop))) { |
774d564b | 2594 | sv_setpvn(x, ipath, ipathend - ipath); |
9607fc9c | 2595 | SvSETMAGIC(x); |
2596 | } | |
774d564b | 2597 | TAINT_NOT; /* $^X is always tainted, but that's OK */ |
8ebc5c01 | 2598 | } |
774d564b | 2599 | #endif /* ARG_ZERO_IS_SCRIPT */ |
b8378b72 CS |
2600 | |
2601 | /* | |
2602 | * Look for options. | |
2603 | */ | |
748a9306 | 2604 | d = instr(s,"perl -"); |
84e30d1a | 2605 | if (!d) { |
748a9306 | 2606 | d = instr(s,"perl"); |
84e30d1a GS |
2607 | #if defined(DOSISH) |
2608 | /* avoid getting into infinite loops when shebang | |
2609 | * line contains "Perl" rather than "perl" */ | |
2610 | if (!d) { | |
2611 | for (d = ipathend-4; d >= ipath; --d) { | |
2612 | if ((*d == 'p' || *d == 'P') | |
2613 | && !ibcmp(d, "perl", 4)) | |
2614 | { | |
2615 | break; | |
2616 | } | |
2617 | } | |
2618 | if (d < ipath) | |
2619 | d = Nullch; | |
2620 | } | |
2621 | #endif | |
2622 | } | |
44a8e56a | 2623 | #ifdef ALTERNATE_SHEBANG |
2624 | /* | |
2625 | * If the ALTERNATE_SHEBANG on this system starts with a | |
2626 | * character that can be part of a Perl expression, then if | |
2627 | * we see it but not "perl", we're probably looking at the | |
2628 | * start of Perl code, not a request to hand off to some | |
2629 | * other interpreter. Similarly, if "perl" is there, but | |
2630 | * not in the first 'word' of the line, we assume the line | |
2631 | * contains the start of the Perl program. | |
44a8e56a | 2632 | */ |
2633 | if (d && *s != '#') { | |
774d564b | 2634 | char *c = ipath; |
44a8e56a | 2635 | while (*c && !strchr("; \t\r\n\f\v#", *c)) |
2636 | c++; | |
2637 | if (c < d) | |
2638 | d = Nullch; /* "perl" not in first word; ignore */ | |
2639 | else | |
2640 | *s = '#'; /* Don't try to parse shebang line */ | |
2641 | } | |
774d564b | 2642 | #endif /* ALTERNATE_SHEBANG */ |
bf4acbe4 | 2643 | #ifndef MACOS_TRADITIONAL |
748a9306 | 2644 | if (!d && |
44a8e56a | 2645 | *s == '#' && |
774d564b | 2646 | ipathend > ipath && |
3280af22 | 2647 | !PL_minus_c && |
748a9306 | 2648 | !instr(s,"indir") && |
3280af22 | 2649 | instr(PL_origargv[0],"perl")) |
748a9306 | 2650 | { |
9f68db38 | 2651 | char **newargv; |
9f68db38 | 2652 | |
774d564b | 2653 | *ipathend = '\0'; |
2654 | s = ipathend + 1; | |
3280af22 | 2655 | while (s < PL_bufend && isSPACE(*s)) |
9f68db38 | 2656 | s++; |
3280af22 NIS |
2657 | if (s < PL_bufend) { |
2658 | Newz(899,newargv,PL_origargc+3,char*); | |
9f68db38 | 2659 | newargv[1] = s; |
3280af22 | 2660 | while (s < PL_bufend && !isSPACE(*s)) |
9f68db38 LW |
2661 | s++; |
2662 | *s = '\0'; | |
3280af22 | 2663 | Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*); |
9f68db38 LW |
2664 | } |
2665 | else | |
3280af22 | 2666 | newargv = PL_origargv; |
774d564b | 2667 | newargv[0] = ipath; |
b4748376 | 2668 | PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv)); |
cea2e8a9 | 2669 | Perl_croak(aTHX_ "Can't exec %s", ipath); |
9f68db38 | 2670 | } |
bf4acbe4 | 2671 | #endif |
748a9306 | 2672 | if (d) { |
3280af22 NIS |
2673 | U32 oldpdb = PL_perldb; |
2674 | bool oldn = PL_minus_n; | |
2675 | bool oldp = PL_minus_p; | |
748a9306 LW |
2676 | |
2677 | while (*d && !isSPACE(*d)) d++; | |
bf4acbe4 | 2678 | while (SPACE_OR_TAB(*d)) d++; |
748a9306 LW |
2679 | |
2680 | if (*d++ == '-') { | |
8cc95fdb | 2681 | do { |
2682 | if (*d == 'M' || *d == 'm') { | |
2683 | char *m = d; | |
2684 | while (*d && !isSPACE(*d)) d++; | |
cea2e8a9 | 2685 | Perl_croak(aTHX_ "Too late for \"-%.*s\" option", |
8cc95fdb | 2686 | (int)(d - m), m); |
2687 | } | |
2688 | d = moreswitches(d); | |
2689 | } while (d); | |
155aba94 GS |
2690 | if ((PERLDB_LINE && !oldpdb) || |
2691 | ((PL_minus_n || PL_minus_p) && !(oldn || oldp))) | |
b084f20b | 2692 | /* if we have already added "LINE: while (<>) {", |
2693 | we must not do it again */ | |
748a9306 | 2694 | { |
3280af22 NIS |
2695 | sv_setpv(PL_linestr, ""); |
2696 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); | |
2697 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2698 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 2699 | PL_preambled = FALSE; |
84902520 | 2700 | if (PERLDB_LINE) |
3280af22 | 2701 | (void)gv_fetchfile(PL_origfilename); |
748a9306 LW |
2702 | goto retry; |
2703 | } | |
a0d0e21e | 2704 | } |
79072805 | 2705 | } |
9f68db38 | 2706 | } |
79072805 | 2707 | } |
3280af22 NIS |
2708 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
2709 | PL_bufptr = s; | |
2710 | PL_lex_state = LEX_FORMLINE; | |
cea2e8a9 | 2711 | return yylex(); |
ae986130 | 2712 | } |
378cc40b | 2713 | goto retry; |
4fdae800 | 2714 | case '\r': |
6a27c188 | 2715 | #ifdef PERL_STRICT_CR |
cea2e8a9 | 2716 | Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r'); |
4e553d73 | 2717 | Perl_croak(aTHX_ |
cc507455 | 2718 | "\t(Maybe you didn't strip carriage returns after a network transfer?)\n"); |
a868473f | 2719 | #endif |
4fdae800 | 2720 | case ' ': case '\t': case '\f': case 013: |
bf4acbe4 GS |
2721 | #ifdef MACOS_TRADITIONAL |
2722 | case '\312': | |
2723 | #endif | |
378cc40b LW |
2724 | s++; |
2725 | goto retry; | |
378cc40b | 2726 | case '#': |
e929a76b | 2727 | case '\n': |
3280af22 | 2728 | if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) { |
df0deb90 GS |
2729 | if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) { |
2730 | /* handle eval qq[#line 1 "foo"\n ...] */ | |
2731 | CopLINE_dec(PL_curcop); | |
2732 | incline(s); | |
2733 | } | |
3280af22 | 2734 | d = PL_bufend; |
a687059c | 2735 | while (s < d && *s != '\n') |
378cc40b | 2736 | s++; |
0f85fab0 | 2737 | if (s < d) |
378cc40b | 2738 | s++; |
78c267c1 | 2739 | else if (s > d) /* Found by Ilya: feed random input to Perl. */ |
a8406387 | 2740 | Perl_croak(aTHX_ "panic: input overflow"); |
463ee0b2 | 2741 | incline(s); |
3280af22 NIS |
2742 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
2743 | PL_bufptr = s; | |
2744 | PL_lex_state = LEX_FORMLINE; | |
cea2e8a9 | 2745 | return yylex(); |
a687059c | 2746 | } |
378cc40b | 2747 | } |
a687059c | 2748 | else { |
378cc40b | 2749 | *s = '\0'; |
3280af22 | 2750 | PL_bufend = s; |
a687059c | 2751 | } |
378cc40b LW |
2752 | goto retry; |
2753 | case '-': | |
79072805 | 2754 | if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) { |
e5edeb50 JH |
2755 | I32 ftst = 0; |
2756 | ||
378cc40b | 2757 | s++; |
3280af22 | 2758 | PL_bufptr = s; |
748a9306 LW |
2759 | tmp = *s++; |
2760 | ||
bf4acbe4 | 2761 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
748a9306 LW |
2762 | s++; |
2763 | ||
2764 | if (strnEQ(s,"=>",2)) { | |
3280af22 | 2765 | s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE); |
4e553d73 | 2766 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
607df283 | 2767 | "### Saw unary minus before =>, forcing word '%s'\n", s); |
5f80b19c | 2768 | } ); |
748a9306 LW |
2769 | OPERATOR('-'); /* unary minus */ |
2770 | } | |
3280af22 | 2771 | PL_last_uni = PL_oldbufptr; |
748a9306 | 2772 | switch (tmp) { |
e5edeb50 JH |
2773 | case 'r': ftst = OP_FTEREAD; break; |
2774 | case 'w': ftst = OP_FTEWRITE; break; | |
2775 | case 'x': ftst = OP_FTEEXEC; break; | |
2776 | case 'o': ftst = OP_FTEOWNED; break; | |
2777 | case 'R': ftst = OP_FTRREAD; break; | |
2778 | case 'W': ftst = OP_FTRWRITE; break; | |
2779 | case 'X': ftst = OP_FTREXEC; break; | |
2780 | case 'O': ftst = OP_FTROWNED; break; | |
2781 | case 'e': ftst = OP_FTIS; break; | |
2782 | case 'z': ftst = OP_FTZERO; break; | |
2783 | case 's': ftst = OP_FTSIZE; break; | |
2784 | case 'f': ftst = OP_FTFILE; break; | |
2785 | case 'd': ftst = OP_FTDIR; break; | |
2786 | case 'l': ftst = OP_FTLINK; break; | |
2787 | case 'p': ftst = OP_FTPIPE; break; | |
2788 | case 'S': ftst = OP_FTSOCK; break; | |
2789 | case 'u': ftst = OP_FTSUID; break; | |
2790 | case 'g': ftst = OP_FTSGID; break; | |
2791 | case 'k': ftst = OP_FTSVTX; break; | |
2792 | case 'b': ftst = OP_FTBLK; break; | |
2793 | case 'c': ftst = OP_FTCHR; break; | |
2794 | case 't': ftst = OP_FTTTY; break; | |
2795 | case 'T': ftst = OP_FTTEXT; break; | |
2796 | case 'B': ftst = OP_FTBINARY; break; | |
2797 | case 'M': case 'A': case 'C': | |
2798 | gv_fetchpv("\024",TRUE, SVt_PV); | |
2799 | switch (tmp) { | |
2800 | case 'M': ftst = OP_FTMTIME; break; | |
2801 | case 'A': ftst = OP_FTATIME; break; | |
2802 | case 'C': ftst = OP_FTCTIME; break; | |
2803 | default: break; | |
2804 | } | |
2805 | break; | |
378cc40b | 2806 | default: |
378cc40b LW |
2807 | break; |
2808 | } | |
e5edeb50 JH |
2809 | if (ftst) { |
2810 | PL_last_lop_op = ftst; | |
4e553d73 | 2811 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
0844c848 | 2812 | "### Saw file test %c\n", (int)ftst); |
5f80b19c | 2813 | } ); |
e5edeb50 JH |
2814 | FTST(ftst); |
2815 | } | |
2816 | else { | |
2817 | /* Assume it was a minus followed by a one-letter named | |
2818 | * subroutine call (or a -bareword), then. */ | |
95c31fe3 | 2819 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
0844c848 RB |
2820 | "### %c looked like a file test but was not\n", |
2821 | (int)ftst); | |
5f80b19c | 2822 | } ); |
e5edeb50 JH |
2823 | s -= 2; |
2824 | } | |
378cc40b | 2825 | } |
a687059c LW |
2826 | tmp = *s++; |
2827 | if (*s == tmp) { | |
2828 | s++; | |
3280af22 | 2829 | if (PL_expect == XOPERATOR) |
79072805 LW |
2830 | TERM(POSTDEC); |
2831 | else | |
2832 | OPERATOR(PREDEC); | |
2833 | } | |
2834 | else if (*s == '>') { | |
2835 | s++; | |
2836 | s = skipspace(s); | |
7e2040f0 | 2837 | if (isIDFIRST_lazy_if(s,UTF)) { |
a0d0e21e | 2838 | s = force_word(s,METHOD,FALSE,TRUE,FALSE); |
463ee0b2 | 2839 | TOKEN(ARROW); |
79072805 | 2840 | } |
748a9306 LW |
2841 | else if (*s == '$') |
2842 | OPERATOR(ARROW); | |
463ee0b2 | 2843 | else |
748a9306 | 2844 | TERM(ARROW); |
a687059c | 2845 | } |
3280af22 | 2846 | if (PL_expect == XOPERATOR) |
79072805 LW |
2847 | Aop(OP_SUBTRACT); |
2848 | else { | |
3280af22 | 2849 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) |
2f3197b3 | 2850 | check_uni(); |
79072805 | 2851 | OPERATOR('-'); /* unary minus */ |
2f3197b3 | 2852 | } |
79072805 | 2853 | |
378cc40b | 2854 | case '+': |
a687059c LW |
2855 | tmp = *s++; |
2856 | if (*s == tmp) { | |
378cc40b | 2857 | s++; |
3280af22 | 2858 | if (PL_expect == XOPERATOR) |
79072805 LW |
2859 | TERM(POSTINC); |
2860 | else | |
2861 | OPERATOR(PREINC); | |
378cc40b | 2862 | } |
3280af22 | 2863 | if (PL_expect == XOPERATOR) |
79072805 LW |
2864 | Aop(OP_ADD); |
2865 | else { | |
3280af22 | 2866 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) |
2f3197b3 | 2867 | check_uni(); |
a687059c | 2868 | OPERATOR('+'); |
2f3197b3 | 2869 | } |
a687059c | 2870 | |
378cc40b | 2871 | case '*': |
3280af22 NIS |
2872 | if (PL_expect != XOPERATOR) { |
2873 | s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); | |
2874 | PL_expect = XOPERATOR; | |
2875 | force_ident(PL_tokenbuf, '*'); | |
2876 | if (!*PL_tokenbuf) | |
a0d0e21e | 2877 | PREREF('*'); |
79072805 | 2878 | TERM('*'); |
a687059c | 2879 | } |
79072805 LW |
2880 | s++; |
2881 | if (*s == '*') { | |
a687059c | 2882 | s++; |
79072805 | 2883 | PWop(OP_POW); |
a687059c | 2884 | } |
79072805 LW |
2885 | Mop(OP_MULTIPLY); |
2886 | ||
378cc40b | 2887 | case '%': |
3280af22 | 2888 | if (PL_expect == XOPERATOR) { |
bbce6d69 | 2889 | ++s; |
2890 | Mop(OP_MODULO); | |
a687059c | 2891 | } |
3280af22 NIS |
2892 | PL_tokenbuf[0] = '%'; |
2893 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE); | |
2894 | if (!PL_tokenbuf[1]) { | |
2895 | if (s == PL_bufend) | |
bbce6d69 | 2896 | yyerror("Final % should be \\% or %name"); |
2897 | PREREF('%'); | |
a687059c | 2898 | } |
3280af22 | 2899 | PL_pending_ident = '%'; |
bbce6d69 | 2900 | TERM('%'); |
a687059c | 2901 | |
378cc40b | 2902 | case '^': |
79072805 | 2903 | s++; |
a0d0e21e | 2904 | BOop(OP_BIT_XOR); |
79072805 | 2905 | case '[': |
3280af22 | 2906 | PL_lex_brackets++; |
79072805 | 2907 | /* FALL THROUGH */ |
378cc40b | 2908 | case '~': |
378cc40b | 2909 | case ',': |
378cc40b LW |
2910 | tmp = *s++; |
2911 | OPERATOR(tmp); | |
a0d0e21e LW |
2912 | case ':': |
2913 | if (s[1] == ':') { | |
2914 | len = 0; | |
2915 | goto just_a_word; | |
2916 | } | |
2917 | s++; | |
09bef843 SB |
2918 | switch (PL_expect) { |
2919 | OP *attrs; | |
2920 | case XOPERATOR: | |
2921 | if (!PL_in_my || PL_lex_state != LEX_NORMAL) | |
2922 | break; | |
2923 | PL_bufptr = s; /* update in case we back off */ | |
2924 | goto grabattrs; | |
2925 | case XATTRBLOCK: | |
2926 | PL_expect = XBLOCK; | |
2927 | goto grabattrs; | |
2928 | case XATTRTERM: | |
2929 | PL_expect = XTERMBLOCK; | |
2930 | grabattrs: | |
2931 | s = skipspace(s); | |
2932 | attrs = Nullop; | |
7e2040f0 | 2933 | while (isIDFIRST_lazy_if(s,UTF)) { |
09bef843 | 2934 | d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
f9829d6b GS |
2935 | if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) { |
2936 | if (tmp < 0) tmp = -tmp; | |
2937 | switch (tmp) { | |
2938 | case KEY_or: | |
2939 | case KEY_and: | |
2940 | case KEY_for: | |
2941 | case KEY_unless: | |
2942 | case KEY_if: | |
2943 | case KEY_while: | |
2944 | case KEY_until: | |
2945 | goto got_attrs; | |
2946 | default: | |
2947 | break; | |
2948 | } | |
2949 | } | |
09bef843 SB |
2950 | if (*d == '(') { |
2951 | d = scan_str(d,TRUE,TRUE); | |
2952 | if (!d) { | |
09bef843 SB |
2953 | /* MUST advance bufptr here to avoid bogus |
2954 | "at end of line" context messages from yyerror(). | |
2955 | */ | |
2956 | PL_bufptr = s + len; | |
2957 | yyerror("Unterminated attribute parameter in attribute list"); | |
2958 | if (attrs) | |
2959 | op_free(attrs); | |
2960 | return 0; /* EOF indicator */ | |
2961 | } | |
2962 | } | |
2963 | if (PL_lex_stuff) { | |
2964 | SV *sv = newSVpvn(s, len); | |
2965 | sv_catsv(sv, PL_lex_stuff); | |
2966 | attrs = append_elem(OP_LIST, attrs, | |
2967 | newSVOP(OP_CONST, 0, sv)); | |
2968 | SvREFCNT_dec(PL_lex_stuff); | |
2969 | PL_lex_stuff = Nullsv; | |
2970 | } | |
2971 | else { | |
78f9721b SM |
2972 | if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len)) |
2973 | CvLVALUE_on(PL_compcv); | |
2974 | else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len)) | |
2975 | CvLOCKED_on(PL_compcv); | |
2976 | else if (!PL_in_my && len == 6 && strnEQ(s, "method", len)) | |
2977 | CvMETHOD_on(PL_compcv); | |
87ecf892 | 2978 | #ifdef USE_ITHREADS |
c8a3bf85 | 2979 | else if (PL_in_my == KEY_our && len == 6 && strnEQ(s, "unique", len)) |
7fb37951 | 2980 | GvUNIQUE_on(cGVOPx_gv(yylval.opval)); |
87ecf892 | 2981 | #endif |
78f9721b SM |
2982 | /* After we've set the flags, it could be argued that |
2983 | we don't need to do the attributes.pm-based setting | |
2984 | process, and shouldn't bother appending recognized | |
2985 | flags. To experiment with that, uncomment the | |
2986 | following "else": */ | |
0256094b | 2987 | else |
78f9721b SM |
2988 | attrs = append_elem(OP_LIST, attrs, |
2989 | newSVOP(OP_CONST, 0, | |
2990 | newSVpvn(s, len))); | |
09bef843 SB |
2991 | } |
2992 | s = skipspace(d); | |
0120eecf | 2993 | if (*s == ':' && s[1] != ':') |
09bef843 | 2994 | s = skipspace(s+1); |
0120eecf GS |
2995 | else if (s == d) |
2996 | break; /* require real whitespace or :'s */ | |
09bef843 | 2997 | } |
f9829d6b GS |
2998 | tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */ |
2999 | if (*s != ';' && *s != tmp && (tmp != '=' || *s != ')')) { | |
09bef843 SB |
3000 | char q = ((*s == '\'') ? '"' : '\''); |
3001 | /* If here for an expression, and parsed no attrs, back off. */ | |
3002 | if (tmp == '=' && !attrs) { | |
3003 | s = PL_bufptr; | |
3004 | break; | |
3005 | } | |
3006 | /* MUST advance bufptr here to avoid bogus "at end of line" | |
3007 | context messages from yyerror(). | |
3008 | */ | |
3009 | PL_bufptr = s; | |
3010 | if (!*s) | |
3011 | yyerror("Unterminated attribute list"); | |
3012 | else | |
3013 | yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list", | |
3014 | q, *s, q)); | |
3015 | if (attrs) | |
3016 | op_free(attrs); | |
3017 | OPERATOR(':'); | |
3018 | } | |
f9829d6b | 3019 | got_attrs: |
09bef843 SB |
3020 | if (attrs) { |
3021 | PL_nextval[PL_nexttoke].opval = attrs; | |
3022 | force_next(THING); | |
3023 | } | |
3024 | TOKEN(COLONATTR); | |
3025 | } | |
a0d0e21e | 3026 | OPERATOR(':'); |
8990e307 LW |
3027 | case '(': |
3028 | s++; | |
3280af22 NIS |
3029 | if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr) |
3030 | PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */ | |
a0d0e21e | 3031 | else |
3280af22 | 3032 | PL_expect = XTERM; |
a0d0e21e | 3033 | TOKEN('('); |
378cc40b | 3034 | case ';': |
f4dd75d9 | 3035 | CLINE; |
378cc40b LW |
3036 | tmp = *s++; |
3037 | OPERATOR(tmp); | |
3038 | case ')': | |
378cc40b | 3039 | tmp = *s++; |
16d20bd9 AD |
3040 | s = skipspace(s); |
3041 | if (*s == '{') | |
3042 | PREBLOCK(tmp); | |
378cc40b | 3043 | TERM(tmp); |
79072805 LW |
3044 | case ']': |
3045 | s++; | |
3280af22 | 3046 | if (PL_lex_brackets <= 0) |
d98d5fff | 3047 | yyerror("Unmatched right square bracket"); |
463ee0b2 | 3048 | else |
3280af22 NIS |
3049 | --PL_lex_brackets; |
3050 | if (PL_lex_state == LEX_INTERPNORMAL) { | |
3051 | if (PL_lex_brackets == 0) { | |
a0d0e21e | 3052 | if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>')) |
3280af22 | 3053 | PL_lex_state = LEX_INTERPEND; |
79072805 LW |
3054 | } |
3055 | } | |
4633a7c4 | 3056 | TERM(']'); |
79072805 LW |
3057 | case '{': |
3058 | leftbracket: | |
79072805 | 3059 | s++; |
3280af22 NIS |
3060 | if (PL_lex_brackets > 100) { |
3061 | char* newlb = Renew(PL_lex_brackstack, PL_lex_brackets + 1, char); | |
3062 | if (newlb != PL_lex_brackstack) { | |
8990e307 | 3063 | SAVEFREEPV(newlb); |
3280af22 | 3064 | PL_lex_brackstack = newlb; |
8990e307 LW |
3065 | } |
3066 | } | |
3280af22 | 3067 | switch (PL_expect) { |
a0d0e21e | 3068 | case XTERM: |
3280af22 | 3069 | if (PL_lex_formbrack) { |
a0d0e21e LW |
3070 | s--; |
3071 | PRETERMBLOCK(DO); | |
3072 | } | |
3280af22 NIS |
3073 | if (PL_oldoldbufptr == PL_last_lop) |
3074 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; | |
a0d0e21e | 3075 | else |
3280af22 | 3076 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
79072805 | 3077 | OPERATOR(HASHBRACK); |
a0d0e21e | 3078 | case XOPERATOR: |
bf4acbe4 | 3079 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
748a9306 | 3080 | s++; |
44a8e56a | 3081 | d = s; |
3280af22 NIS |
3082 | PL_tokenbuf[0] = '\0'; |
3083 | if (d < PL_bufend && *d == '-') { | |
3084 | PL_tokenbuf[0] = '-'; | |
44a8e56a | 3085 | d++; |
bf4acbe4 | 3086 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
44a8e56a | 3087 | d++; |
3088 | } | |
7e2040f0 | 3089 | if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) { |
3280af22 | 3090 | d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, |
8903cb82 | 3091 | FALSE, &len); |
bf4acbe4 | 3092 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
748a9306 LW |
3093 | d++; |
3094 | if (*d == '}') { | |
3280af22 | 3095 | char minus = (PL_tokenbuf[0] == '-'); |
44a8e56a | 3096 | s = force_word(s + minus, WORD, FALSE, TRUE, FALSE); |
3097 | if (minus) | |
3098 | force_next('-'); | |
748a9306 LW |
3099 | } |
3100 | } | |
3101 | /* FALL THROUGH */ | |
09bef843 | 3102 | case XATTRBLOCK: |
748a9306 | 3103 | case XBLOCK: |
3280af22 NIS |
3104 | PL_lex_brackstack[PL_lex_brackets++] = XSTATE; |
3105 | PL_expect = XSTATE; | |
a0d0e21e | 3106 | break; |
09bef843 | 3107 | case XATTRTERM: |
a0d0e21e | 3108 | case XTERMBLOCK: |
3280af22 NIS |
3109 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
3110 | PL_expect = XSTATE; | |
a0d0e21e LW |
3111 | break; |
3112 | default: { | |
3113 | char *t; | |
3280af22 NIS |
3114 | if (PL_oldoldbufptr == PL_last_lop) |
3115 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; | |
a0d0e21e | 3116 | else |
3280af22 | 3117 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
a0d0e21e | 3118 | s = skipspace(s); |
8452ff4b SB |
3119 | if (*s == '}') { |
3120 | if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) { | |
3121 | PL_expect = XTERM; | |
3122 | /* This hack is to get the ${} in the message. */ | |
3123 | PL_bufptr = s+1; | |
3124 | yyerror("syntax error"); | |
3125 | break; | |
3126 | } | |
a0d0e21e | 3127 | OPERATOR(HASHBRACK); |
8452ff4b | 3128 | } |
b8a4b1be GS |
3129 | /* This hack serves to disambiguate a pair of curlies |
3130 | * as being a block or an anon hash. Normally, expectation | |
3131 | * determines that, but in cases where we're not in a | |
3132 | * position to expect anything in particular (like inside | |
3133 | * eval"") we have to resolve the ambiguity. This code | |
3134 | * covers the case where the first term in the curlies is a | |
3135 | * quoted string. Most other cases need to be explicitly | |
3136 | * disambiguated by prepending a `+' before the opening | |
3137 | * curly in order to force resolution as an anon hash. | |
3138 | * | |
3139 | * XXX should probably propagate the outer expectation | |
3140 | * into eval"" to rely less on this hack, but that could | |
3141 | * potentially break current behavior of eval"". | |
3142 | * GSAR 97-07-21 | |
3143 | */ | |
3144 | t = s; | |
3145 | if (*s == '\'' || *s == '"' || *s == '`') { | |
3146 | /* common case: get past first string, handling escapes */ | |
3280af22 | 3147 | for (t++; t < PL_bufend && *t != *s;) |
b8a4b1be GS |
3148 | if (*t++ == '\\' && (*t == '\\' || *t == *s)) |
3149 | t++; | |
3150 | t++; | |
a0d0e21e | 3151 | } |
b8a4b1be | 3152 | else if (*s == 'q') { |
3280af22 | 3153 | if (++t < PL_bufend |
b8a4b1be | 3154 | && (!isALNUM(*t) |
3280af22 | 3155 | || ((*t == 'q' || *t == 'x') && ++t < PL_bufend |
0505442f GS |
3156 | && !isALNUM(*t)))) |
3157 | { | |
b8a4b1be GS |
3158 | char *tmps; |
3159 | char open, close, term; | |
3160 | I32 brackets = 1; | |
3161 | ||
3280af22 | 3162 | while (t < PL_bufend && isSPACE(*t)) |
b8a4b1be GS |
3163 | t++; |
3164 | term = *t; | |
3165 | open = term; | |
3166 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) | |
3167 | term = tmps[5]; | |
3168 | close = term; | |
3169 | if (open == close) | |
3280af22 NIS |
3170 | for (t++; t < PL_bufend; t++) { |
3171 | if (*t == '\\' && t+1 < PL_bufend && open != '\\') | |
b8a4b1be | 3172 | t++; |
6d07e5e9 | 3173 | else if (*t == open) |
b8a4b1be GS |
3174 | break; |
3175 | } | |
3176 | else | |
3280af22 NIS |
3177 | for (t++; t < PL_bufend; t++) { |
3178 | if (*t == '\\' && t+1 < PL_bufend) | |
b8a4b1be | 3179 | t++; |
6d07e5e9 | 3180 | else if (*t == close && --brackets <= 0) |
b8a4b1be GS |
3181 | break; |
3182 | else if (*t == open) | |
3183 | brackets++; | |
3184 | } | |
3185 | } | |
3186 | t++; | |
a0d0e21e | 3187 | } |
7e2040f0 | 3188 | else if (isALNUM_lazy_if(t,UTF)) { |
0505442f | 3189 | t += UTF8SKIP(t); |
7e2040f0 | 3190 | while (t < PL_bufend && isALNUM_lazy_if(t,UTF)) |
0505442f | 3191 | t += UTF8SKIP(t); |
a0d0e21e | 3192 | } |
3280af22 | 3193 | while (t < PL_bufend && isSPACE(*t)) |
a0d0e21e | 3194 | t++; |
b8a4b1be GS |
3195 | /* if comma follows first term, call it an anon hash */ |
3196 | /* XXX it could be a comma expression with loop modifiers */ | |
3280af22 | 3197 | if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s))) |
b8a4b1be | 3198 | || (*t == '=' && t[1] == '>'))) |
a0d0e21e | 3199 | OPERATOR(HASHBRACK); |
3280af22 | 3200 | if (PL_expect == XREF) |
4e4e412b | 3201 | PL_expect = XTERM; |
a0d0e21e | 3202 | else { |
3280af22 NIS |
3203 | PL_lex_brackstack[PL_lex_brackets-1] = XSTATE; |
3204 | PL_expect = XSTATE; | |
a0d0e21e | 3205 | } |
8990e307 | 3206 | } |
a0d0e21e | 3207 | break; |
463ee0b2 | 3208 | } |
57843af0 | 3209 | yylval.ival = CopLINE(PL_curcop); |
79072805 | 3210 | if (isSPACE(*s) || *s == '#') |
3280af22 | 3211 | PL_copline = NOLINE; /* invalidate current command line number */ |
79072805 | 3212 | TOKEN('{'); |
378cc40b | 3213 | case '}': |
79072805 LW |
3214 | rightbracket: |
3215 | s++; | |
3280af22 | 3216 | if (PL_lex_brackets <= 0) |
d98d5fff | 3217 | yyerror("Unmatched right curly bracket"); |
463ee0b2 | 3218 | else |
3280af22 | 3219 | PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets]; |
c2e66d9e | 3220 | if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL) |
3280af22 NIS |
3221 | PL_lex_formbrack = 0; |
3222 | if (PL_lex_state == LEX_INTERPNORMAL) { | |
3223 | if (PL_lex_brackets == 0) { | |
9059aa12 LW |
3224 | if (PL_expect & XFAKEBRACK) { |
3225 | PL_expect &= XENUMMASK; | |
3280af22 NIS |
3226 | PL_lex_state = LEX_INTERPEND; |
3227 | PL_bufptr = s; | |
cea2e8a9 | 3228 | return yylex(); /* ignore fake brackets */ |
79072805 | 3229 | } |
fa83b5b6 | 3230 | if (*s == '-' && s[1] == '>') |
3280af22 | 3231 | PL_lex_state = LEX_INTERPENDMAYBE; |
fa83b5b6 | 3232 | else if (*s != '[' && *s != '{') |
3280af22 | 3233 | PL_lex_state = LEX_INTERPEND; |
79072805 LW |
3234 | } |
3235 | } | |
9059aa12 LW |
3236 | if (PL_expect & XFAKEBRACK) { |
3237 | PL_expect &= XENUMMASK; | |
3280af22 | 3238 | PL_bufptr = s; |
cea2e8a9 | 3239 | return yylex(); /* ignore fake brackets */ |
748a9306 | 3240 | } |
79072805 LW |
3241 | force_next('}'); |
3242 | TOKEN(';'); | |
378cc40b LW |
3243 | case '&': |
3244 | s++; | |
3245 | tmp = *s++; | |
3246 | if (tmp == '&') | |
a0d0e21e | 3247 | AOPERATOR(ANDAND); |
378cc40b | 3248 | s--; |
3280af22 | 3249 | if (PL_expect == XOPERATOR) { |
7e2040f0 GS |
3250 | if (ckWARN(WARN_SEMICOLON) |
3251 | && isIDFIRST_lazy_if(s,UTF) && PL_bufptr == PL_linestart) | |
3252 | { | |
57843af0 | 3253 | CopLINE_dec(PL_curcop); |
cea2e8a9 | 3254 | Perl_warner(aTHX_ WARN_SEMICOLON, PL_warn_nosemi); |
57843af0 | 3255 | CopLINE_inc(PL_curcop); |
463ee0b2 | 3256 | } |
79072805 | 3257 | BAop(OP_BIT_AND); |
463ee0b2 | 3258 | } |
79072805 | 3259 | |
3280af22 NIS |
3260 | s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); |
3261 | if (*PL_tokenbuf) { | |
3262 | PL_expect = XOPERATOR; | |
3263 | force_ident(PL_tokenbuf, '&'); | |
463ee0b2 | 3264 | } |
79072805 LW |
3265 | else |
3266 | PREREF('&'); | |
c07a80fd | 3267 | yylval.ival = (OPpENTERSUB_AMPER<<8); |
79072805 LW |
3268 | TERM('&'); |
3269 | ||
378cc40b LW |
3270 | case '|': |
3271 | s++; | |
3272 | tmp = *s++; | |
3273 | if (tmp == '|') | |
a0d0e21e | 3274 | AOPERATOR(OROR); |
378cc40b | 3275 | s--; |
79072805 | 3276 | BOop(OP_BIT_OR); |
378cc40b LW |
3277 | case '=': |
3278 | s++; | |
3279 | tmp = *s++; | |
3280 | if (tmp == '=') | |
79072805 LW |
3281 | Eop(OP_EQ); |
3282 | if (tmp == '>') | |
3283 | OPERATOR(','); | |
378cc40b | 3284 | if (tmp == '~') |
79072805 | 3285 | PMop(OP_MATCH); |
599cee73 | 3286 | if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp)) |
cea2e8a9 | 3287 | Perl_warner(aTHX_ WARN_SYNTAX, "Reversed %c= operator",(int)tmp); |
378cc40b | 3288 | s--; |
3280af22 NIS |
3289 | if (PL_expect == XSTATE && isALPHA(tmp) && |
3290 | (s == PL_linestart+1 || s[-2] == '\n') ) | |
748a9306 | 3291 | { |
3280af22 NIS |
3292 | if (PL_in_eval && !PL_rsfp) { |
3293 | d = PL_bufend; | |
a5f75d66 AD |
3294 | while (s < d) { |
3295 | if (*s++ == '\n') { | |
3296 | incline(s); | |
3297 | if (strnEQ(s,"=cut",4)) { | |
3298 | s = strchr(s,'\n'); | |
3299 | if (s) | |
3300 | s++; | |
3301 | else | |
3302 | s = d; | |
3303 | incline(s); | |
3304 | goto retry; | |
3305 | } | |
3306 | } | |
3307 | } | |
3308 | goto retry; | |
3309 | } | |
3280af22 NIS |
3310 | s = PL_bufend; |
3311 | PL_doextract = TRUE; | |
a0d0e21e LW |
3312 | goto retry; |
3313 | } | |
3280af22 | 3314 | if (PL_lex_brackets < PL_lex_formbrack) { |
a0d0e21e | 3315 | char *t; |
51882d45 | 3316 | #ifdef PERL_STRICT_CR |
bf4acbe4 | 3317 | for (t = s; SPACE_OR_TAB(*t); t++) ; |
51882d45 | 3318 | #else |
bf4acbe4 | 3319 | for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ; |
51882d45 | 3320 | #endif |
a0d0e21e LW |
3321 | if (*t == '\n' || *t == '#') { |
3322 | s--; | |
3280af22 | 3323 | PL_expect = XBLOCK; |
a0d0e21e LW |
3324 | goto leftbracket; |
3325 | } | |
79072805 | 3326 | } |
a0d0e21e LW |
3327 | yylval.ival = 0; |
3328 | OPERATOR(ASSIGNOP); | |
378cc40b LW |
3329 | case '!': |
3330 | s++; | |
3331 | tmp = *s++; | |
3332 | if (tmp == '=') | |
79072805 | 3333 | Eop(OP_NE); |
378cc40b | 3334 | if (tmp == '~') |
79072805 | 3335 | PMop(OP_NOT); |
378cc40b LW |
3336 | s--; |
3337 | OPERATOR('!'); | |
3338 | case '<': | |
3280af22 | 3339 | if (PL_expect != XOPERATOR) { |
93a17b20 | 3340 | if (s[1] != '<' && !strchr(s,'>')) |
2f3197b3 | 3341 | check_uni(); |
79072805 LW |
3342 | if (s[1] == '<') |
3343 | s = scan_heredoc(s); | |
3344 | else | |
3345 | s = scan_inputsymbol(s); | |
3346 | TERM(sublex_start()); | |
378cc40b LW |
3347 | } |
3348 | s++; | |
3349 | tmp = *s++; | |
3350 | if (tmp == '<') | |
79072805 | 3351 | SHop(OP_LEFT_SHIFT); |
395c3793 LW |
3352 | if (tmp == '=') { |
3353 | tmp = *s++; | |
3354 | if (tmp == '>') | |
79072805 | 3355 | Eop(OP_NCMP); |
395c3793 | 3356 | s--; |
79072805 | 3357 | Rop(OP_LE); |
395c3793 | 3358 | } |
378cc40b | 3359 | s--; |
79072805 | 3360 | Rop(OP_LT); |
378cc40b LW |
3361 | case '>': |
3362 | s++; | |
3363 | tmp = *s++; | |
3364 | if (tmp == '>') | |
79072805 | 3365 | SHop(OP_RIGHT_SHIFT); |
378cc40b | 3366 | if (tmp == '=') |
79072805 | 3367 | Rop(OP_GE); |
378cc40b | 3368 | s--; |
79072805 | 3369 | Rop(OP_GT); |
378cc40b LW |
3370 | |
3371 | case '$': | |
bbce6d69 | 3372 | CLINE; |
3373 | ||
3280af22 NIS |
3374 | if (PL_expect == XOPERATOR) { |
3375 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3376 | PL_expect = XTERM; | |
a0d0e21e | 3377 | depcom(); |
bbce6d69 | 3378 | return ','; /* grandfather non-comma-format format */ |
a0d0e21e | 3379 | } |
8990e307 | 3380 | } |
a0d0e21e | 3381 | |
7e2040f0 | 3382 | if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) { |
3280af22 | 3383 | PL_tokenbuf[0] = '@'; |
376b8730 SM |
3384 | s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1, |
3385 | sizeof PL_tokenbuf - 1, FALSE); | |
3386 | if (PL_expect == XOPERATOR) | |
3387 | no_op("Array length", s); | |
3280af22 | 3388 | if (!PL_tokenbuf[1]) |
a0d0e21e | 3389 | PREREF(DOLSHARP); |
3280af22 NIS |
3390 | PL_expect = XOPERATOR; |
3391 | PL_pending_ident = '#'; | |
463ee0b2 | 3392 | TOKEN(DOLSHARP); |
79072805 | 3393 | } |
bbce6d69 | 3394 | |
3280af22 | 3395 | PL_tokenbuf[0] = '$'; |
376b8730 SM |
3396 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, |
3397 | sizeof PL_tokenbuf - 1, FALSE); | |
3398 | if (PL_expect == XOPERATOR) | |
3399 | no_op("Scalar", s); | |
3280af22 NIS |
3400 | if (!PL_tokenbuf[1]) { |
3401 | if (s == PL_bufend) | |
bbce6d69 | 3402 | yyerror("Final $ should be \\$ or $name"); |
3403 | PREREF('$'); | |
8990e307 | 3404 | } |
a0d0e21e | 3405 | |
bbce6d69 | 3406 | /* This kludge not intended to be bulletproof. */ |
3280af22 | 3407 | if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) { |
bbce6d69 | 3408 | yylval.opval = newSVOP(OP_CONST, 0, |
b448e4fe | 3409 | newSViv(PL_compiling.cop_arybase)); |
bbce6d69 | 3410 | yylval.opval->op_private = OPpCONST_ARYBASE; |
3411 | TERM(THING); | |
3412 | } | |
3413 | ||
ff68c719 | 3414 | d = s; |
69d2bceb | 3415 | tmp = (I32)*s; |
3280af22 | 3416 | if (PL_lex_state == LEX_NORMAL) |
ff68c719 | 3417 | s = skipspace(s); |
3418 | ||
3280af22 | 3419 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) { |
bbce6d69 | 3420 | char *t; |
3421 | if (*s == '[') { | |
3280af22 | 3422 | PL_tokenbuf[0] = '@'; |
599cee73 | 3423 | if (ckWARN(WARN_SYNTAX)) { |
bbce6d69 | 3424 | for(t = s + 1; |
7e2040f0 | 3425 | isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$'; |
bbce6d69 | 3426 | t++) ; |
a0d0e21e | 3427 | if (*t++ == ',') { |
3280af22 NIS |
3428 | PL_bufptr = skipspace(PL_bufptr); |
3429 | while (t < PL_bufend && *t != ']') | |
bbce6d69 | 3430 | t++; |
cea2e8a9 | 3431 | Perl_warner(aTHX_ WARN_SYNTAX, |
599cee73 PM |
3432 | "Multidimensional syntax %.*s not supported", |
3433 | (t - PL_bufptr) + 1, PL_bufptr); | |
a0d0e21e LW |
3434 | } |
3435 | } | |
bbce6d69 | 3436 | } |
3437 | else if (*s == '{') { | |
3280af22 | 3438 | PL_tokenbuf[0] = '%'; |
599cee73 | 3439 | if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") && |
bbce6d69 | 3440 | (t = strchr(s, '}')) && (t = strchr(t, '='))) |
3441 | { | |
3280af22 | 3442 | char tmpbuf[sizeof PL_tokenbuf]; |
a0d0e21e LW |
3443 | STRLEN len; |
3444 | for (t++; isSPACE(*t); t++) ; | |
7e2040f0 | 3445 | if (isIDFIRST_lazy_if(t,UTF)) { |
8903cb82 | 3446 | t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len); |
59a6d928 | 3447 | for (; isSPACE(*t); t++) ; |
864dbfa3 | 3448 | if (*t == ';' && get_cv(tmpbuf, FALSE)) |
cea2e8a9 | 3449 | Perl_warner(aTHX_ WARN_SYNTAX, |
599cee73 | 3450 | "You need to quote \"%s\"", tmpbuf); |
748a9306 | 3451 | } |
93a17b20 LW |
3452 | } |
3453 | } | |
2f3197b3 | 3454 | } |
bbce6d69 | 3455 | |
3280af22 | 3456 | PL_expect = XOPERATOR; |
69d2bceb | 3457 | if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) { |
3280af22 NIS |
3458 | bool islop = (PL_last_lop == PL_oldoldbufptr); |
3459 | if (!islop || PL_last_lop_op == OP_GREPSTART) | |
3460 | PL_expect = XOPERATOR; | |
bbce6d69 | 3461 | else if (strchr("$@\"'`q", *s)) |
3280af22 | 3462 | PL_expect = XTERM; /* e.g. print $fh "foo" */ |
7e2040f0 | 3463 | else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF)) |
3280af22 | 3464 | PL_expect = XTERM; /* e.g. print $fh &sub */ |
7e2040f0 | 3465 | else if (isIDFIRST_lazy_if(s,UTF)) { |
3280af22 | 3466 | char tmpbuf[sizeof PL_tokenbuf]; |
8903cb82 | 3467 | scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
155aba94 | 3468 | if ((tmp = keyword(tmpbuf, len))) { |
84902520 TB |
3469 | /* binary operators exclude handle interpretations */ |
3470 | switch (tmp) { | |
3471 | case -KEY_x: | |
3472 | case -KEY_eq: | |
3473 | case -KEY_ne: | |
3474 | case -KEY_gt: | |
3475 | case -KEY_lt: | |
3476 | case -KEY_ge: | |
3477 | case -KEY_le: | |
3478 | case -KEY_cmp: | |
3479 | break; | |
3480 | default: | |
3280af22 | 3481 | PL_expect = XTERM; /* e.g. print $fh length() */ |
84902520 TB |
3482 | break; |
3483 | } | |
3484 | } | |
68dc0745 | 3485 | else { |
3486 | GV *gv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV); | |
3487 | if (gv && GvCVu(gv)) | |
3280af22 | 3488 | PL_expect = XTERM; /* e.g. print $fh subr() */ |
93a17b20 | 3489 | } |
93a17b20 | 3490 | } |
bbce6d69 | 3491 | else if (isDIGIT(*s)) |
3280af22 | 3492 | PL_expect = XTERM; /* e.g. print $fh 3 */ |
bbce6d69 | 3493 | else if (*s == '.' && isDIGIT(s[1])) |
3280af22 | 3494 | PL_expect = XTERM; /* e.g. print $fh .3 */ |
e0587a03 | 3495 | else if (strchr("/?-+", *s) && !isSPACE(s[1]) && s[1] != '=') |
3280af22 | 3496 | PL_expect = XTERM; /* e.g. print $fh -1 */ |
e0587a03 | 3497 | else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=') |
3280af22 | 3498 | PL_expect = XTERM; /* print $fh <<"EOF" */ |
bbce6d69 | 3499 | } |
3280af22 | 3500 | PL_pending_ident = '$'; |
79072805 | 3501 | TOKEN('$'); |
378cc40b LW |
3502 | |
3503 | case '@': | |
3280af22 | 3504 | if (PL_expect == XOPERATOR) |
bbce6d69 | 3505 | no_op("Array", s); |
3280af22 NIS |
3506 | PL_tokenbuf[0] = '@'; |
3507 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE); | |
3508 | if (!PL_tokenbuf[1]) { | |
3509 | if (s == PL_bufend) | |
bbce6d69 | 3510 | yyerror("Final @ should be \\@ or @name"); |
3511 | PREREF('@'); | |
3512 | } | |
3280af22 | 3513 | if (PL_lex_state == LEX_NORMAL) |
ff68c719 | 3514 | s = skipspace(s); |
3280af22 | 3515 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) { |
bbce6d69 | 3516 | if (*s == '{') |
3280af22 | 3517 | PL_tokenbuf[0] = '%'; |
a0d0e21e LW |
3518 | |
3519 | /* Warn about @ where they meant $. */ | |
599cee73 | 3520 | if (ckWARN(WARN_SYNTAX)) { |
a0d0e21e LW |
3521 | if (*s == '[' || *s == '{') { |
3522 | char *t = s + 1; | |
7e2040f0 | 3523 | while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t))) |
a0d0e21e LW |
3524 | t++; |
3525 | if (*t == '}' || *t == ']') { | |
3526 | t++; | |
3280af22 | 3527 | PL_bufptr = skipspace(PL_bufptr); |
cea2e8a9 | 3528 | Perl_warner(aTHX_ WARN_SYNTAX, |
599cee73 | 3529 | "Scalar value %.*s better written as $%.*s", |
3280af22 | 3530 | t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1); |
a0d0e21e | 3531 | } |
93a17b20 LW |
3532 | } |
3533 | } | |
463ee0b2 | 3534 | } |
3280af22 | 3535 | PL_pending_ident = '@'; |
79072805 | 3536 | TERM('@'); |
378cc40b LW |
3537 | |
3538 | case '/': /* may either be division or pattern */ | |
3539 | case '?': /* may either be conditional or pattern */ | |
3280af22 | 3540 | if (PL_expect != XOPERATOR) { |
c277df42 | 3541 | /* Disable warning on "study /blah/" */ |
4e553d73 NIS |
3542 | if (PL_oldoldbufptr == PL_last_uni |
3543 | && (*PL_last_uni != 's' || s - PL_last_uni < 5 | |
7e2040f0 GS |
3544 | || memNE(PL_last_uni, "study", 5) |
3545 | || isALNUM_lazy_if(PL_last_uni+5,UTF))) | |
c277df42 | 3546 | check_uni(); |
8782bef2 | 3547 | s = scan_pat(s,OP_MATCH); |
79072805 | 3548 | TERM(sublex_start()); |
378cc40b LW |
3549 | } |
3550 | tmp = *s++; | |
a687059c | 3551 | if (tmp == '/') |
79072805 | 3552 | Mop(OP_DIVIDE); |
378cc40b LW |
3553 | OPERATOR(tmp); |
3554 | ||
3555 | case '.': | |
51882d45 GS |
3556 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack |
3557 | #ifdef PERL_STRICT_CR | |
3558 | && s[1] == '\n' | |
3559 | #else | |
3560 | && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n')) | |
3561 | #endif | |
3562 | && (s == PL_linestart || s[-1] == '\n') ) | |
3563 | { | |
3280af22 NIS |
3564 | PL_lex_formbrack = 0; |
3565 | PL_expect = XSTATE; | |
79072805 LW |
3566 | goto rightbracket; |
3567 | } | |
3280af22 | 3568 | if (PL_expect == XOPERATOR || !isDIGIT(s[1])) { |
378cc40b | 3569 | tmp = *s++; |
a687059c LW |
3570 | if (*s == tmp) { |
3571 | s++; | |
2f3197b3 LW |
3572 | if (*s == tmp) { |
3573 | s++; | |
79072805 | 3574 | yylval.ival = OPf_SPECIAL; |
2f3197b3 LW |
3575 | } |
3576 | else | |
79072805 | 3577 | yylval.ival = 0; |
378cc40b | 3578 | OPERATOR(DOTDOT); |
a687059c | 3579 | } |
3280af22 | 3580 | if (PL_expect != XOPERATOR) |
2f3197b3 | 3581 | check_uni(); |
79072805 | 3582 | Aop(OP_CONCAT); |
378cc40b LW |
3583 | } |
3584 | /* FALL THROUGH */ | |
3585 | case '0': case '1': case '2': case '3': case '4': | |
3586 | case '5': case '6': case '7': case '8': case '9': | |
b73d6f50 | 3587 | s = scan_num(s, &yylval); |
4e553d73 | 3588 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
607df283 | 3589 | "### Saw number in '%s'\n", s); |
5f80b19c | 3590 | } ); |
3280af22 | 3591 | if (PL_expect == XOPERATOR) |
8990e307 | 3592 | no_op("Number",s); |
79072805 LW |
3593 | TERM(THING); |
3594 | ||
3595 | case '\'': | |
09bef843 | 3596 | s = scan_str(s,FALSE,FALSE); |
4e553d73 | 3597 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
207e3d1a | 3598 | "### Saw string before '%s'\n", s); |
5f80b19c | 3599 | } ); |
3280af22 NIS |
3600 | if (PL_expect == XOPERATOR) { |
3601 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3602 | PL_expect = XTERM; | |
a0d0e21e LW |
3603 | depcom(); |
3604 | return ','; /* grandfather non-comma-format format */ | |
3605 | } | |
463ee0b2 | 3606 | else |
8990e307 | 3607 | no_op("String",s); |
463ee0b2 | 3608 | } |
79072805 | 3609 | if (!s) |
85e6fe83 | 3610 | missingterm((char*)0); |
79072805 LW |
3611 | yylval.ival = OP_CONST; |
3612 | TERM(sublex_start()); | |
3613 | ||
3614 | case '"': | |
09bef843 | 3615 | s = scan_str(s,FALSE,FALSE); |
4e553d73 | 3616 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
207e3d1a | 3617 | "### Saw string before '%s'\n", s); |
5f80b19c | 3618 | } ); |
3280af22 NIS |
3619 | if (PL_expect == XOPERATOR) { |
3620 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3621 | PL_expect = XTERM; | |
a0d0e21e LW |
3622 | depcom(); |
3623 | return ','; /* grandfather non-comma-format format */ | |
3624 | } | |
463ee0b2 | 3625 | else |
8990e307 | 3626 | no_op("String",s); |
463ee0b2 | 3627 | } |
79072805 | 3628 | if (!s) |
85e6fe83 | 3629 | missingterm((char*)0); |
4633a7c4 | 3630 | yylval.ival = OP_CONST; |
3280af22 | 3631 | for (d = SvPV(PL_lex_stuff, len); len; len--, d++) { |
63cd0674 | 3632 | if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) { |
4633a7c4 LW |
3633 | yylval.ival = OP_STRINGIFY; |
3634 | break; | |
3635 | } | |
3636 | } | |
79072805 LW |
3637 | TERM(sublex_start()); |
3638 | ||
3639 | case '`': | |
09bef843 | 3640 | s = scan_str(s,FALSE,FALSE); |
4e553d73 | 3641 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
207e3d1a | 3642 | "### Saw backtick string before '%s'\n", s); |
5f80b19c | 3643 | } ); |
3280af22 | 3644 | if (PL_expect == XOPERATOR) |
8990e307 | 3645 | no_op("Backticks",s); |
79072805 | 3646 | if (!s) |
85e6fe83 | 3647 | missingterm((char*)0); |
79072805 LW |
3648 | yylval.ival = OP_BACKTICK; |
3649 | set_csh(); | |
3650 | TERM(sublex_start()); | |
3651 | ||
3652 | case '\\': | |
3653 | s++; | |
599cee73 | 3654 | if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s)) |
cea2e8a9 | 3655 | Perl_warner(aTHX_ WARN_SYNTAX,"Can't use \\%c to mean $%c in expression", |
599cee73 | 3656 | *s, *s); |
3280af22 | 3657 | if (PL_expect == XOPERATOR) |
8990e307 | 3658 | no_op("Backslash",s); |
79072805 LW |
3659 | OPERATOR(REFGEN); |
3660 | ||
a7cb1f99 | 3661 | case 'v': |
e526c9e6 | 3662 | if (isDIGIT(s[1]) && PL_expect != XOPERATOR) { |
a7cb1f99 GS |
3663 | char *start = s; |
3664 | start++; | |
3665 | start++; | |
dd629d5b | 3666 | while (isDIGIT(*start) || *start == '_') |
a7cb1f99 GS |
3667 | start++; |
3668 | if (*start == '.' && isDIGIT(start[1])) { | |
b73d6f50 | 3669 | s = scan_num(s, &yylval); |
a7cb1f99 GS |
3670 | TERM(THING); |
3671 | } | |
e526c9e6 | 3672 | /* avoid v123abc() or $h{v1}, allow C<print v10;> */ |
62ec34bd | 3673 | else if (!isALPHA(*start) && (PL_expect == XTERM || PL_expect == XREF || PL_expect == XSTATE)) { |
e526c9e6 GS |
3674 | char c = *start; |
3675 | GV *gv; | |
3676 | *start = '\0'; | |
3677 | gv = gv_fetchpv(s, FALSE, SVt_PVCV); | |
3678 | *start = c; | |
3679 | if (!gv) { | |
b73d6f50 | 3680 | s = scan_num(s, &yylval); |
e526c9e6 GS |
3681 | TERM(THING); |
3682 | } | |
3683 | } | |
a7cb1f99 GS |
3684 | } |
3685 | goto keylookup; | |
79072805 | 3686 | case 'x': |
3280af22 | 3687 | if (isDIGIT(s[1]) && PL_expect == XOPERATOR) { |
79072805 LW |
3688 | s++; |
3689 | Mop(OP_REPEAT); | |
2f3197b3 | 3690 | } |
79072805 LW |
3691 | goto keylookup; |
3692 | ||
378cc40b | 3693 | case '_': |
79072805 LW |
3694 | case 'a': case 'A': |
3695 | case 'b': case 'B': | |
3696 | case 'c': case 'C': | |
3697 | case 'd': case 'D': | |
3698 | case 'e': case 'E': | |
3699 | case 'f': case 'F': | |
3700 | case 'g': case 'G': | |
3701 | case 'h': case 'H': | |
3702 | case 'i': case 'I': | |
3703 | case 'j': case 'J': | |
3704 | case 'k': case 'K': | |
3705 | case 'l': case 'L': | |
3706 | case 'm': case 'M': | |
3707 | case 'n': case 'N': | |
3708 | case 'o': case 'O': | |
3709 | case 'p': case 'P': | |
3710 | case 'q': case 'Q': | |
3711 | case 'r': case 'R': | |
3712 | case 's': case 'S': | |
3713 | case 't': case 'T': | |
3714 | case 'u': case 'U': | |
a7cb1f99 | 3715 | case 'V': |
79072805 LW |
3716 | case 'w': case 'W': |
3717 | case 'X': | |
3718 | case 'y': case 'Y': | |
3719 | case 'z': case 'Z': | |
3720 | ||
49dc05e3 | 3721 | keylookup: { |
161b471a NIS |
3722 | gv = Nullgv; |
3723 | gvp = 0; | |
49dc05e3 | 3724 | |
3280af22 NIS |
3725 | PL_bufptr = s; |
3726 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); | |
8ebc5c01 | 3727 | |
3728 | /* Some keywords can be followed by any delimiter, including ':' */ | |
155aba94 GS |
3729 | tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) || |
3730 | (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') || | |
3731 | (PL_tokenbuf[0] == 'q' && | |
3732 | strchr("qwxr", PL_tokenbuf[1]))))); | |
8ebc5c01 | 3733 | |
3734 | /* x::* is just a word, unless x is "CORE" */ | |
3280af22 | 3735 | if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE")) |
4633a7c4 LW |
3736 | goto just_a_word; |
3737 | ||
3643fb5f | 3738 | d = s; |
3280af22 | 3739 | while (d < PL_bufend && isSPACE(*d)) |
3643fb5f CS |
3740 | d++; /* no comments skipped here, or s### is misparsed */ |
3741 | ||
3742 | /* Is this a label? */ | |
3280af22 NIS |
3743 | if (!tmp && PL_expect == XSTATE |
3744 | && d < PL_bufend && *d == ':' && *(d + 1) != ':') { | |
8ebc5c01 | 3745 | s = d + 1; |
3280af22 | 3746 | yylval.pval = savepv(PL_tokenbuf); |
8ebc5c01 | 3747 | CLINE; |
3748 | TOKEN(LABEL); | |
3643fb5f CS |
3749 | } |
3750 | ||
3751 | /* Check for keywords */ | |
3280af22 | 3752 | tmp = keyword(PL_tokenbuf, len); |
748a9306 LW |
3753 | |
3754 | /* Is this a word before a => operator? */ | |
1c3923b3 | 3755 | if (*d == '=' && d[1] == '>') { |
748a9306 | 3756 | CLINE; |
3280af22 | 3757 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf,0)); |
748a9306 | 3758 | yylval.opval->op_private = OPpCONST_BARE; |
0064a8a9 | 3759 | if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len)) |
7948272d | 3760 | SvUTF8_on(((SVOP*)yylval.opval)->op_sv); |
748a9306 LW |
3761 | TERM(WORD); |
3762 | } | |
3763 | ||
a0d0e21e | 3764 | if (tmp < 0) { /* second-class keyword? */ |
56f7f34b CS |
3765 | GV *ogv = Nullgv; /* override (winner) */ |
3766 | GV *hgv = Nullgv; /* hidden (loser) */ | |
3280af22 | 3767 | if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) { |
56f7f34b | 3768 | CV *cv; |
3280af22 | 3769 | if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) && |
56f7f34b CS |
3770 | (cv = GvCVu(gv))) |
3771 | { | |
3772 | if (GvIMPORTED_CV(gv)) | |
3773 | ogv = gv; | |
3774 | else if (! CvMETHOD(cv)) | |
3775 | hgv = gv; | |
3776 | } | |
3777 | if (!ogv && | |
3280af22 NIS |
3778 | (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) && |
3779 | (gv = *gvp) != (GV*)&PL_sv_undef && | |
56f7f34b CS |
3780 | GvCVu(gv) && GvIMPORTED_CV(gv)) |
3781 | { | |
3782 | ogv = gv; | |
3783 | } | |
3784 | } | |
3785 | if (ogv) { | |
3786 | tmp = 0; /* overridden by import or by GLOBAL */ | |
6e7b2336 GS |
3787 | } |
3788 | else if (gv && !gvp | |
3789 | && -tmp==KEY_lock /* XXX generalizable kludge */ | |
d0456cad | 3790 | && GvCVu(gv) |
3280af22 | 3791 | && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE)) |
6e7b2336 GS |
3792 | { |
3793 | tmp = 0; /* any sub overrides "weak" keyword */ | |
a0d0e21e | 3794 | } |
56f7f34b CS |
3795 | else { /* no override */ |
3796 | tmp = -tmp; | |
3797 | gv = Nullgv; | |
3798 | gvp = 0; | |
4944e2f7 GS |
3799 | if (ckWARN(WARN_AMBIGUOUS) && hgv |
3800 | && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */ | |
cea2e8a9 | 3801 | Perl_warner(aTHX_ WARN_AMBIGUOUS, |
599cee73 | 3802 | "Ambiguous call resolved as CORE::%s(), %s", |
2f3ca594 | 3803 | GvENAME(hgv), "qualify as such or use &"); |
49dc05e3 | 3804 | } |
a0d0e21e LW |
3805 | } |
3806 | ||
3807 | reserved_word: | |
3808 | switch (tmp) { | |
79072805 LW |
3809 | |
3810 | default: /* not a keyword */ | |
93a17b20 | 3811 | just_a_word: { |
96e4d5b1 | 3812 | SV *sv; |
ce29ac45 | 3813 | int pkgname = 0; |
3280af22 | 3814 | char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]); |
8990e307 LW |
3815 | |
3816 | /* Get the rest if it looks like a package qualifier */ | |
3817 | ||
155aba94 | 3818 | if (*s == '\'' || (*s == ':' && s[1] == ':')) { |
c3e0f903 | 3819 | STRLEN morelen; |
3280af22 | 3820 | s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len, |
c3e0f903 GS |
3821 | TRUE, &morelen); |
3822 | if (!morelen) | |
cea2e8a9 | 3823 | Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf, |
ec2ab091 | 3824 | *s == '\'' ? "'" : "::"); |
c3e0f903 | 3825 | len += morelen; |
ce29ac45 | 3826 | pkgname = 1; |
a0d0e21e | 3827 | } |
8990e307 | 3828 | |
3280af22 NIS |
3829 | if (PL_expect == XOPERATOR) { |
3830 | if (PL_bufptr == PL_linestart) { | |
57843af0 | 3831 | CopLINE_dec(PL_curcop); |
cea2e8a9 | 3832 | Perl_warner(aTHX_ WARN_SEMICOLON, PL_warn_nosemi); |
57843af0 | 3833 | CopLINE_inc(PL_curcop); |
463ee0b2 LW |
3834 | } |
3835 | else | |
54310121 | 3836 | no_op("Bareword",s); |
463ee0b2 | 3837 | } |
8990e307 | 3838 | |
c3e0f903 GS |
3839 | /* Look for a subroutine with this name in current package, |
3840 | unless name is "Foo::", in which case Foo is a bearword | |
3841 | (and a package name). */ | |
3842 | ||
3843 | if (len > 2 && | |
3280af22 | 3844 | PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':') |
c3e0f903 | 3845 | { |
e476b1b5 | 3846 | if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV)) |
4e553d73 | 3847 | Perl_warner(aTHX_ WARN_BAREWORD, |
599cee73 | 3848 | "Bareword \"%s\" refers to nonexistent package", |
3280af22 | 3849 | PL_tokenbuf); |
c3e0f903 | 3850 | len -= 2; |
3280af22 | 3851 | PL_tokenbuf[len] = '\0'; |
c3e0f903 GS |
3852 | gv = Nullgv; |
3853 | gvp = 0; | |
3854 | } | |
3855 | else { | |
3856 | len = 0; | |
3857 | if (!gv) | |
3280af22 | 3858 | gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV); |
c3e0f903 GS |
3859 | } |
3860 | ||
3861 | /* if we saw a global override before, get the right name */ | |
8990e307 | 3862 | |
49dc05e3 | 3863 | if (gvp) { |
79cb57f6 | 3864 | sv = newSVpvn("CORE::GLOBAL::",14); |
3280af22 | 3865 | sv_catpv(sv,PL_tokenbuf); |
49dc05e3 GS |
3866 | } |
3867 | else | |
3280af22 | 3868 | sv = newSVpv(PL_tokenbuf,0); |
8990e307 | 3869 | |
a0d0e21e LW |
3870 | /* Presume this is going to be a bareword of some sort. */ |
3871 | ||
3872 | CLINE; | |
49dc05e3 | 3873 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
a0d0e21e LW |
3874 | yylval.opval->op_private = OPpCONST_BARE; |
3875 | ||
c3e0f903 GS |
3876 | /* And if "Foo::", then that's what it certainly is. */ |
3877 | ||
3878 | if (len) | |
3879 | goto safe_bareword; | |
3880 | ||
8990e307 LW |
3881 | /* See if it's the indirect object for a list operator. */ |
3882 | ||
3280af22 NIS |
3883 | if (PL_oldoldbufptr && |
3884 | PL_oldoldbufptr < PL_bufptr && | |
65cec589 GS |
3885 | (PL_oldoldbufptr == PL_last_lop |
3886 | || PL_oldoldbufptr == PL_last_uni) && | |
a0d0e21e | 3887 | /* NO SKIPSPACE BEFORE HERE! */ |
a9ef352a GS |
3888 | (PL_expect == XREF || |
3889 | ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF)) | |
a0d0e21e | 3890 | { |
748a9306 LW |
3891 | bool immediate_paren = *s == '('; |
3892 | ||
a0d0e21e LW |
3893 | /* (Now we can afford to cross potential line boundary.) */ |
3894 | s = skipspace(s); | |
3895 | ||
3896 | /* Two barewords in a row may indicate method call. */ | |
3897 | ||
7e2040f0 | 3898 | if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv))) |
a0d0e21e LW |
3899 | return tmp; |
3900 | ||
3901 | /* If not a declared subroutine, it's an indirect object. */ | |
3902 | /* (But it's an indir obj regardless for sort.) */ | |
3903 | ||
7948272d | 3904 | if ( !immediate_paren && (PL_last_lop_op == OP_SORT || |
f0670693 | 3905 | ((!gv || !GvCVu(gv)) && |
a9ef352a | 3906 | (PL_last_lop_op != OP_MAPSTART && |
f0670693 | 3907 | PL_last_lop_op != OP_GREPSTART)))) |
a9ef352a | 3908 | { |
3280af22 | 3909 | PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR; |
748a9306 | 3910 | goto bareword; |
93a17b20 LW |
3911 | } |
3912 | } | |
8990e307 | 3913 | |
3280af22 | 3914 | PL_expect = XOPERATOR; |
8990e307 | 3915 | s = skipspace(s); |
1c3923b3 GS |
3916 | |
3917 | /* Is this a word before a => operator? */ | |
ce29ac45 | 3918 | if (*s == '=' && s[1] == '>' && !pkgname) { |
1c3923b3 GS |
3919 | CLINE; |
3920 | sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf); | |
0064a8a9 | 3921 | if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len)) |
7948272d | 3922 | SvUTF8_on(((SVOP*)yylval.opval)->op_sv); |
1c3923b3 GS |
3923 | TERM(WORD); |
3924 | } | |
3925 | ||
3926 | /* If followed by a paren, it's certainly a subroutine. */ | |
93a17b20 | 3927 | if (*s == '(') { |
79072805 | 3928 | CLINE; |
96e4d5b1 | 3929 | if (gv && GvCVu(gv)) { |
bf4acbe4 | 3930 | for (d = s + 1; SPACE_OR_TAB(*d); d++) ; |
7a52d87a | 3931 | if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) { |
96e4d5b1 | 3932 | s = d + 1; |
3933 | goto its_constant; | |
3934 | } | |
3935 | } | |
3280af22 NIS |
3936 | PL_nextval[PL_nexttoke].opval = yylval.opval; |
3937 | PL_expect = XOPERATOR; | |
93a17b20 | 3938 | force_next(WORD); |
c07a80fd | 3939 | yylval.ival = 0; |
463ee0b2 | 3940 | TOKEN('&'); |
79072805 | 3941 | } |
93a17b20 | 3942 | |
a0d0e21e | 3943 | /* If followed by var or block, call it a method (unless sub) */ |
8990e307 | 3944 | |
8ebc5c01 | 3945 | if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) { |
3280af22 NIS |
3946 | PL_last_lop = PL_oldbufptr; |
3947 | PL_last_lop_op = OP_METHOD; | |
93a17b20 | 3948 | PREBLOCK(METHOD); |
463ee0b2 LW |
3949 | } |
3950 | ||
8990e307 LW |
3951 | /* If followed by a bareword, see if it looks like indir obj. */ |
3952 | ||
7e2040f0 | 3953 | if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp = intuit_method(s,gv))) |
a0d0e21e | 3954 | return tmp; |
93a17b20 | 3955 | |
8990e307 LW |
3956 | /* Not a method, so call it a subroutine (if defined) */ |
3957 | ||
8ebc5c01 | 3958 | if (gv && GvCVu(gv)) { |
46fc3d4c | 3959 | CV* cv; |
0453d815 PM |
3960 | if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS)) |
3961 | Perl_warner(aTHX_ WARN_AMBIGUOUS, | |
3962 | "Ambiguous use of -%s resolved as -&%s()", | |
3280af22 | 3963 | PL_tokenbuf, PL_tokenbuf); |
89bfa8cd | 3964 | /* Check for a constant sub */ |
46fc3d4c | 3965 | cv = GvCV(gv); |
96e4d5b1 | 3966 | if ((sv = cv_const_sv(cv))) { |
3967 | its_constant: | |
3968 | SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv); | |
3969 | ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv); | |
3970 | yylval.opval->op_private = 0; | |
3971 | TOKEN(WORD); | |
89bfa8cd | 3972 | } |
3973 | ||
a5f75d66 AD |
3974 | /* Resolve to GV now. */ |
3975 | op_free(yylval.opval); | |
3976 | yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv)); | |
9675f7ac | 3977 | yylval.opval->op_private |= OPpENTERSUB_NOPAREN; |
7a52d87a | 3978 | PL_last_lop = PL_oldbufptr; |
bf848113 | 3979 | PL_last_lop_op = OP_ENTERSUB; |
4633a7c4 LW |
3980 | /* Is there a prototype? */ |
3981 | if (SvPOK(cv)) { | |
3982 | STRLEN len; | |
7a52d87a | 3983 | char *proto = SvPV((SV*)cv, len); |
4633a7c4 LW |
3984 | if (!len) |
3985 | TERM(FUNC0SUB); | |
7a52d87a | 3986 | if (strEQ(proto, "$")) |
4633a7c4 | 3987 | OPERATOR(UNIOPSUB); |
7a52d87a | 3988 | if (*proto == '&' && *s == '{') { |
3280af22 | 3989 | sv_setpv(PL_subname,"__ANON__"); |
4633a7c4 LW |
3990 | PREBLOCK(LSTOPSUB); |
3991 | } | |
a9ef352a | 3992 | } |
3280af22 NIS |
3993 | PL_nextval[PL_nexttoke].opval = yylval.opval; |
3994 | PL_expect = XTERM; | |
8990e307 LW |
3995 | force_next(WORD); |
3996 | TOKEN(NOAMP); | |
3997 | } | |
748a9306 | 3998 | |
8990e307 LW |
3999 | /* Call it a bare word */ |
4000 | ||
5603f27d GS |
4001 | if (PL_hints & HINT_STRICT_SUBS) |
4002 | yylval.opval->op_private |= OPpCONST_STRICT; | |
4003 | else { | |
4004 | bareword: | |
4005 | if (ckWARN(WARN_RESERVED)) { | |
4006 | if (lastchar != '-') { | |
4007 | for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ; | |
9bbb1ada | 4008 | if (!*d && strNE(PL_tokenbuf,"main")) |
cea2e8a9 | 4009 | Perl_warner(aTHX_ WARN_RESERVED, PL_warn_reserved, |
5603f27d GS |
4010 | PL_tokenbuf); |
4011 | } | |
748a9306 LW |
4012 | } |
4013 | } | |
c3e0f903 GS |
4014 | |
4015 | safe_bareword: | |
f248d071 | 4016 | if (lastchar && strchr("*%&", lastchar) && ckWARN_d(WARN_AMBIGUOUS)) { |
0453d815 PM |
4017 | Perl_warner(aTHX_ WARN_AMBIGUOUS, |
4018 | "Operator or semicolon missing before %c%s", | |
3280af22 | 4019 | lastchar, PL_tokenbuf); |
0453d815 PM |
4020 | Perl_warner(aTHX_ WARN_AMBIGUOUS, |
4021 | "Ambiguous use of %c resolved as operator %c", | |
748a9306 LW |
4022 | lastchar, lastchar); |
4023 | } | |
93a17b20 | 4024 | TOKEN(WORD); |
79072805 | 4025 | } |
79072805 | 4026 | |
68dc0745 | 4027 | case KEY___FILE__: |
46fc3d4c | 4028 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
ed094faf | 4029 | newSVpv(CopFILE(PL_curcop),0)); |
46fc3d4c | 4030 | TERM(THING); |
4031 | ||
79072805 | 4032 | case KEY___LINE__: |
cf2093f6 | 4033 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
57843af0 | 4034 | Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop))); |
79072805 | 4035 | TERM(THING); |
68dc0745 | 4036 | |
4037 | case KEY___PACKAGE__: | |
4038 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, | |
3280af22 NIS |
4039 | (PL_curstash |
4040 | ? newSVsv(PL_curstname) | |
4041 | : &PL_sv_undef)); | |
79072805 | 4042 | TERM(THING); |
79072805 | 4043 | |
e50aee73 | 4044 | case KEY___DATA__: |
79072805 LW |
4045 | case KEY___END__: { |
4046 | GV *gv; | |
79072805 LW |
4047 | |
4048 | /*SUPPRESS 560*/ | |
3280af22 | 4049 | if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) { |
e50aee73 | 4050 | char *pname = "main"; |
3280af22 NIS |
4051 | if (PL_tokenbuf[2] == 'D') |
4052 | pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash); | |
cea2e8a9 | 4053 | gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO); |
a5f75d66 | 4054 | GvMULTI_on(gv); |
79072805 | 4055 | if (!GvIO(gv)) |
a0d0e21e | 4056 | GvIOp(gv) = newIO(); |
3280af22 | 4057 | IoIFP(GvIOp(gv)) = PL_rsfp; |
a0d0e21e LW |
4058 | #if defined(HAS_FCNTL) && defined(F_SETFD) |
4059 | { | |
3280af22 | 4060 | int fd = PerlIO_fileno(PL_rsfp); |
a0d0e21e LW |
4061 | fcntl(fd,F_SETFD,fd >= 3); |
4062 | } | |
79072805 | 4063 | #endif |
fd049845 | 4064 | /* Mark this internal pseudo-handle as clean */ |
4065 | IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT; | |
3280af22 | 4066 | if (PL_preprocess) |
50952442 | 4067 | IoTYPE(GvIOp(gv)) = IoTYPE_PIPE; |
3280af22 | 4068 | else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) |
50952442 | 4069 | IoTYPE(GvIOp(gv)) = IoTYPE_STD; |
79072805 | 4070 | else |
50952442 | 4071 | IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY; |
c39cd008 GS |
4072 | #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS) |
4073 | /* if the script was opened in binmode, we need to revert | |
53129d29 | 4074 | * it to text mode for compatibility; but only iff it has CRs |
c39cd008 | 4075 | * XXX this is a questionable hack at best. */ |
53129d29 GS |
4076 | if (PL_bufend-PL_bufptr > 2 |
4077 | && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r') | |
c39cd008 GS |
4078 | { |
4079 | Off_t loc = 0; | |
50952442 | 4080 | if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) { |
c39cd008 GS |
4081 | loc = PerlIO_tell(PL_rsfp); |
4082 | (void)PerlIO_seek(PL_rsfp, 0L, 0); | |
4083 | } | |
2986a63f JH |
4084 | #ifdef NETWARE |
4085 | if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) { | |
4086 | #else | |
c39cd008 | 4087 | if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) { |
2986a63f | 4088 | #endif /* NETWARE */ |
1143fce0 JH |
4089 | #ifdef PERLIO_IS_STDIO /* really? */ |
4090 | # if defined(__BORLANDC__) | |
cb359b41 JH |
4091 | /* XXX see note in do_binmode() */ |
4092 | ((FILE*)PL_rsfp)->flags &= ~_F_BIN; | |
1143fce0 JH |
4093 | # endif |
4094 | #endif | |
c39cd008 GS |
4095 | if (loc > 0) |
4096 | PerlIO_seek(PL_rsfp, loc, 0); | |
4097 | } | |
4098 | } | |
4099 | #endif | |
7948272d | 4100 | #ifdef PERLIO_LAYERS |
0064a8a9 | 4101 | if (UTF && !IN_BYTES) |
7948272d NIS |
4102 | PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8"); |
4103 | #endif | |
3280af22 | 4104 | PL_rsfp = Nullfp; |
79072805 LW |
4105 | } |
4106 | goto fake_eof; | |
e929a76b | 4107 | } |
de3bb511 | 4108 | |
8990e307 | 4109 | case KEY_AUTOLOAD: |
ed6116ce | 4110 | case KEY_DESTROY: |
79072805 | 4111 | case KEY_BEGIN: |
7d30b5c4 | 4112 | case KEY_CHECK: |
7d07dbc2 | 4113 | case KEY_INIT: |
7d30b5c4 | 4114 | case KEY_END: |
3280af22 NIS |
4115 | if (PL_expect == XSTATE) { |
4116 | s = PL_bufptr; | |
93a17b20 | 4117 | goto really_sub; |
79072805 LW |
4118 | } |
4119 | goto just_a_word; | |
4120 | ||
a0d0e21e LW |
4121 | case KEY_CORE: |
4122 | if (*s == ':' && s[1] == ':') { | |
4123 | s += 2; | |
748a9306 | 4124 | d = s; |
3280af22 | 4125 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
6798c92b GS |
4126 | if (!(tmp = keyword(PL_tokenbuf, len))) |
4127 | Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf); | |
a0d0e21e LW |
4128 | if (tmp < 0) |
4129 | tmp = -tmp; | |
4130 | goto reserved_word; | |
4131 | } | |
4132 | goto just_a_word; | |
4133 | ||
463ee0b2 LW |
4134 | case KEY_abs: |
4135 | UNI(OP_ABS); | |
4136 | ||
79072805 LW |
4137 | case KEY_alarm: |
4138 | UNI(OP_ALARM); | |
4139 | ||
4140 | case KEY_accept: | |
a0d0e21e | 4141 | LOP(OP_ACCEPT,XTERM); |
79072805 | 4142 | |
463ee0b2 LW |
4143 | case KEY_and: |
4144 | OPERATOR(ANDOP); | |
4145 | ||
79072805 | 4146 | case KEY_atan2: |
a0d0e21e | 4147 | LOP(OP_ATAN2,XTERM); |
85e6fe83 | 4148 | |
79072805 | 4149 | case KEY_bind: |
a0d0e21e | 4150 | LOP(OP_BIND,XTERM); |
79072805 LW |
4151 | |
4152 | case KEY_binmode: | |
1c1fc3ea | 4153 | LOP(OP_BINMODE,XTERM); |
79072805 LW |
4154 | |
4155 | case KEY_bless: | |
a0d0e21e | 4156 | LOP(OP_BLESS,XTERM); |
79072805 LW |
4157 | |
4158 | case KEY_chop: | |
4159 | UNI(OP_CHOP); | |
4160 | ||
4161 | case KEY_continue: | |
4162 | PREBLOCK(CONTINUE); | |
4163 | ||
4164 | case KEY_chdir: | |
85e6fe83 | 4165 | (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */ |
79072805 LW |
4166 | UNI(OP_CHDIR); |
4167 | ||
4168 | case KEY_close: | |
4169 | UNI(OP_CLOSE); | |
4170 | ||
4171 | case KEY_closedir: | |
4172 | UNI(OP_CLOSEDIR); | |
4173 | ||
4174 | case KEY_cmp: | |
4175 | Eop(OP_SCMP); | |
4176 | ||
4177 | case KEY_caller: | |
4178 | UNI(OP_CALLER); | |
4179 | ||
4180 | case KEY_crypt: | |
4181 | #ifdef FCRYPT | |
f4c556ac GS |
4182 | if (!PL_cryptseen) { |
4183 | PL_cryptseen = TRUE; | |
de3bb511 | 4184 | init_des(); |
f4c556ac | 4185 | } |
a687059c | 4186 | #endif |
a0d0e21e | 4187 | LOP(OP_CRYPT,XTERM); |
79072805 LW |
4188 | |
4189 | case KEY_chmod: | |
a0d0e21e | 4190 | LOP(OP_CHMOD,XTERM); |
79072805 LW |
4191 | |
4192 | case KEY_chown: | |
a0d0e21e | 4193 | LOP(OP_CHOWN,XTERM); |
79072805 LW |
4194 | |
4195 | case KEY_connect: | |
a0d0e21e | 4196 | LOP(OP_CONNECT,XTERM); |
79072805 | 4197 | |
463ee0b2 LW |
4198 | case KEY_chr: |
4199 | UNI(OP_CHR); | |
4200 | ||
79072805 LW |
4201 | case KEY_cos: |
4202 | UNI(OP_COS); | |
4203 | ||
4204 | case KEY_chroot: | |
4205 | UNI(OP_CHROOT); | |
4206 | ||
4207 | case KEY_do: | |
4208 | s = skipspace(s); | |
4209 | if (*s == '{') | |
a0d0e21e | 4210 | PRETERMBLOCK(DO); |
79072805 | 4211 | if (*s != '\'') |
89c5585f | 4212 | s = force_word(s,WORD,TRUE,TRUE,FALSE); |
378cc40b | 4213 | OPERATOR(DO); |
79072805 LW |
4214 | |
4215 | case KEY_die: | |
3280af22 | 4216 | PL_hints |= HINT_BLOCK_SCOPE; |
a0d0e21e | 4217 | LOP(OP_DIE,XTERM); |
79072805 LW |
4218 | |
4219 | case KEY_defined: | |
4220 | UNI(OP_DEFINED); | |
4221 | ||
4222 | case KEY_delete: | |
a0d0e21e | 4223 | UNI(OP_DELETE); |
79072805 LW |
4224 | |
4225 | case KEY_dbmopen: | |
a0d0e21e LW |
4226 | gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV); |
4227 | LOP(OP_DBMOPEN,XTERM); | |
79072805 LW |
4228 | |
4229 | case KEY_dbmclose: | |
4230 | UNI(OP_DBMCLOSE); | |
4231 | ||
4232 | case KEY_dump: | |
a0d0e21e | 4233 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4234 | LOOPX(OP_DUMP); |
4235 | ||
4236 | case KEY_else: | |
4237 | PREBLOCK(ELSE); | |
4238 | ||
4239 | case KEY_elsif: | |
57843af0 | 4240 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
4241 | OPERATOR(ELSIF); |
4242 | ||
4243 | case KEY_eq: | |
4244 | Eop(OP_SEQ); | |
4245 | ||
a0d0e21e LW |
4246 | case KEY_exists: |
4247 | UNI(OP_EXISTS); | |
4e553d73 | 4248 | |
79072805 LW |
4249 | case KEY_exit: |
4250 | UNI(OP_EXIT); | |
4251 | ||
4252 | case KEY_eval: | |
79072805 | 4253 | s = skipspace(s); |
3280af22 | 4254 | PL_expect = (*s == '{') ? XTERMBLOCK : XTERM; |
463ee0b2 | 4255 | UNIBRACK(OP_ENTEREVAL); |
79072805 LW |
4256 | |
4257 | case KEY_eof: | |
4258 | UNI(OP_EOF); | |
4259 | ||
4260 | case KEY_exp: | |
4261 | UNI(OP_EXP); | |
4262 | ||
4263 | case KEY_each: | |
4264 | UNI(OP_EACH); | |
4265 | ||
4266 | case KEY_exec: | |
4267 | set_csh(); | |
a0d0e21e | 4268 | LOP(OP_EXEC,XREF); |
79072805 LW |
4269 | |
4270 | case KEY_endhostent: | |
4271 | FUN0(OP_EHOSTENT); | |
4272 | ||
4273 | case KEY_endnetent: | |
4274 | FUN0(OP_ENETENT); | |
4275 | ||
4276 | case KEY_endservent: | |
4277 | FUN0(OP_ESERVENT); | |
4278 | ||
4279 | case KEY_endprotoent: | |
4280 | FUN0(OP_EPROTOENT); | |
4281 | ||
4282 | case KEY_endpwent: | |
4283 | FUN0(OP_EPWENT); | |
4284 | ||
4285 | case KEY_endgrent: | |
4286 | FUN0(OP_EGRENT); | |
4287 | ||
4288 | case KEY_for: | |
4289 | case KEY_foreach: | |
57843af0 | 4290 | yylval.ival = CopLINE(PL_curcop); |
55497cff | 4291 | s = skipspace(s); |
7e2040f0 | 4292 | if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) { |
55497cff | 4293 | char *p = s; |
3280af22 | 4294 | if ((PL_bufend - p) >= 3 && |
55497cff | 4295 | strnEQ(p, "my", 2) && isSPACE(*(p + 2))) |
4296 | p += 2; | |
77ca0c92 LW |
4297 | else if ((PL_bufend - p) >= 4 && |
4298 | strnEQ(p, "our", 3) && isSPACE(*(p + 3))) | |
4299 | p += 3; | |
55497cff | 4300 | p = skipspace(p); |
7e2040f0 | 4301 | if (isIDFIRST_lazy_if(p,UTF)) { |
77ca0c92 LW |
4302 | p = scan_ident(p, PL_bufend, |
4303 | PL_tokenbuf, sizeof PL_tokenbuf, TRUE); | |
4304 | p = skipspace(p); | |
4305 | } | |
4306 | if (*p != '$') | |
cea2e8a9 | 4307 | Perl_croak(aTHX_ "Missing $ on loop variable"); |
55497cff | 4308 | } |
79072805 LW |
4309 | OPERATOR(FOR); |
4310 | ||
4311 | case KEY_formline: | |
a0d0e21e | 4312 | LOP(OP_FORMLINE,XTERM); |
79072805 LW |
4313 | |
4314 | case KEY_fork: | |
4315 | FUN0(OP_FORK); | |
4316 | ||
4317 | case KEY_fcntl: | |
a0d0e21e | 4318 | LOP(OP_FCNTL,XTERM); |
79072805 LW |
4319 | |
4320 | case KEY_fileno: | |
4321 | UNI(OP_FILENO); | |
4322 | ||
4323 | case KEY_flock: | |
a0d0e21e | 4324 | LOP(OP_FLOCK,XTERM); |
79072805 LW |
4325 | |
4326 | case KEY_gt: | |
4327 | Rop(OP_SGT); | |
4328 | ||
4329 | case KEY_ge: | |
4330 | Rop(OP_SGE); | |
4331 | ||
4332 | case KEY_grep: | |
2c38e13d | 4333 | LOP(OP_GREPSTART, XREF); |
79072805 LW |
4334 | |
4335 | case KEY_goto: | |
a0d0e21e | 4336 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4337 | LOOPX(OP_GOTO); |
4338 | ||
4339 | case KEY_gmtime: | |
4340 | UNI(OP_GMTIME); | |
4341 | ||
4342 | case KEY_getc: | |
4343 | UNI(OP_GETC); | |
4344 | ||
4345 | case KEY_getppid: | |
4346 | FUN0(OP_GETPPID); | |
4347 | ||
4348 | case KEY_getpgrp: | |
4349 | UNI(OP_GETPGRP); | |
4350 | ||
4351 | case KEY_getpriority: | |
a0d0e21e | 4352 | LOP(OP_GETPRIORITY,XTERM); |
79072805 LW |
4353 | |
4354 | case KEY_getprotobyname: | |
4355 | UNI(OP_GPBYNAME); | |
4356 | ||
4357 | case KEY_getprotobynumber: | |
a0d0e21e | 4358 | LOP(OP_GPBYNUMBER,XTERM); |
79072805 LW |
4359 | |
4360 | case KEY_getprotoent: | |
4361 | FUN0(OP_GPROTOENT); | |
4362 | ||
4363 | case KEY_getpwent: | |
4364 | FUN0(OP_GPWENT); | |
4365 | ||
4366 | case KEY_getpwnam: | |
ff68c719 | 4367 | UNI(OP_GPWNAM); |
79072805 LW |
4368 | |
4369 | case KEY_getpwuid: | |
ff68c719 | 4370 | UNI(OP_GPWUID); |
79072805 LW |
4371 | |
4372 | case KEY_getpeername: | |
4373 | UNI(OP_GETPEERNAME); | |
4374 | ||
4375 | case KEY_gethostbyname: | |
4376 | UNI(OP_GHBYNAME); | |
4377 | ||
4378 | case KEY_gethostbyaddr: | |
a0d0e21e | 4379 | LOP(OP_GHBYADDR,XTERM); |
79072805 LW |
4380 | |
4381 | case KEY_gethostent: | |
4382 | FUN0(OP_GHOSTENT); | |
4383 | ||
4384 | case KEY_getnetbyname: | |
4385 | UNI(OP_GNBYNAME); | |
4386 | ||
4387 | case KEY_getnetbyaddr: | |
a0d0e21e | 4388 | LOP(OP_GNBYADDR,XTERM); |
79072805 LW |
4389 | |
4390 | case KEY_getnetent: | |
4391 | FUN0(OP_GNETENT); | |
4392 | ||
4393 | case KEY_getservbyname: | |
a0d0e21e | 4394 | LOP(OP_GSBYNAME,XTERM); |
79072805 LW |
4395 | |
4396 | case KEY_getservbyport: | |
a0d0e21e | 4397 | LOP(OP_GSBYPORT,XTERM); |
79072805 LW |
4398 | |
4399 | case KEY_getservent: | |
4400 | FUN0(OP_GSERVENT); | |
4401 | ||
4402 | case KEY_getsockname: | |
4403 | UNI(OP_GETSOCKNAME); | |
4404 | ||
4405 | case KEY_getsockopt: | |
a0d0e21e | 4406 | LOP(OP_GSOCKOPT,XTERM); |
79072805 LW |
4407 | |
4408 | case KEY_getgrent: | |
4409 | FUN0(OP_GGRENT); | |
4410 | ||
4411 | case KEY_getgrnam: | |
ff68c719 | 4412 | UNI(OP_GGRNAM); |
79072805 LW |
4413 | |
4414 | case KEY_getgrgid: | |
ff68c719 | 4415 | UNI(OP_GGRGID); |
79072805 LW |
4416 | |
4417 | case KEY_getlogin: | |
4418 | FUN0(OP_GETLOGIN); | |
4419 | ||
93a17b20 | 4420 | case KEY_glob: |
a0d0e21e LW |
4421 | set_csh(); |
4422 | LOP(OP_GLOB,XTERM); | |
93a17b20 | 4423 | |
79072805 LW |
4424 | case KEY_hex: |
4425 | UNI(OP_HEX); | |
4426 | ||
4427 | case KEY_if: | |
57843af0 | 4428 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
4429 | OPERATOR(IF); |
4430 | ||
4431 | case KEY_index: | |
a0d0e21e | 4432 | LOP(OP_INDEX,XTERM); |
79072805 LW |
4433 | |
4434 | case KEY_int: | |
4435 | UNI(OP_INT); | |
4436 | ||
4437 | case KEY_ioctl: | |
a0d0e21e | 4438 | LOP(OP_IOCTL,XTERM); |
79072805 LW |
4439 | |
4440 | case KEY_join: | |
a0d0e21e | 4441 | LOP(OP_JOIN,XTERM); |
79072805 LW |
4442 | |
4443 | case KEY_keys: | |
4444 | UNI(OP_KEYS); | |
4445 | ||
4446 | case KEY_kill: | |
a0d0e21e | 4447 | LOP(OP_KILL,XTERM); |
79072805 LW |
4448 | |
4449 | case KEY_last: | |
a0d0e21e | 4450 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 | 4451 | LOOPX(OP_LAST); |
4e553d73 | 4452 | |
79072805 LW |
4453 | case KEY_lc: |
4454 | UNI(OP_LC); | |
4455 | ||
4456 | case KEY_lcfirst: | |
4457 | UNI(OP_LCFIRST); | |
4458 | ||
4459 | case KEY_local: | |
09bef843 | 4460 | yylval.ival = 0; |
79072805 LW |
4461 | OPERATOR(LOCAL); |
4462 | ||
4463 | case KEY_length: | |
4464 | UNI(OP_LENGTH); | |
4465 | ||
4466 | case KEY_lt: | |
4467 | Rop(OP_SLT); | |
4468 | ||
4469 | case KEY_le: | |
4470 | Rop(OP_SLE); | |
4471 | ||
4472 | case KEY_localtime: | |
4473 | UNI(OP_LOCALTIME); | |
4474 | ||
4475 | case KEY_log: | |
4476 | UNI(OP_LOG); | |
4477 | ||
4478 | case KEY_link: | |
a0d0e21e | 4479 | LOP(OP_LINK,XTERM); |
79072805 LW |
4480 | |
4481 | case KEY_listen: | |
a0d0e21e | 4482 | LOP(OP_LISTEN,XTERM); |
79072805 | 4483 | |
c0329465 MB |
4484 | case KEY_lock: |
4485 | UNI(OP_LOCK); | |
4486 | ||
79072805 LW |
4487 | case KEY_lstat: |
4488 | UNI(OP_LSTAT); | |
4489 | ||
4490 | case KEY_m: | |
8782bef2 | 4491 | s = scan_pat(s,OP_MATCH); |
79072805 LW |
4492 | TERM(sublex_start()); |
4493 | ||
a0d0e21e | 4494 | case KEY_map: |
2c38e13d | 4495 | LOP(OP_MAPSTART, XREF); |
4e4e412b | 4496 | |
79072805 | 4497 | case KEY_mkdir: |
a0d0e21e | 4498 | LOP(OP_MKDIR,XTERM); |
79072805 LW |
4499 | |
4500 | case KEY_msgctl: | |
a0d0e21e | 4501 | LOP(OP_MSGCTL,XTERM); |
79072805 LW |
4502 | |
4503 | case KEY_msgget: | |
a0d0e21e | 4504 | LOP(OP_MSGGET,XTERM); |
79072805 LW |
4505 | |
4506 | case KEY_msgrcv: | |
a0d0e21e | 4507 | LOP(OP_MSGRCV,XTERM); |
79072805 LW |
4508 | |
4509 | case KEY_msgsnd: | |
a0d0e21e | 4510 | LOP(OP_MSGSND,XTERM); |
79072805 | 4511 | |
77ca0c92 | 4512 | case KEY_our: |
93a17b20 | 4513 | case KEY_my: |
77ca0c92 | 4514 | PL_in_my = tmp; |
c750a3ec | 4515 | s = skipspace(s); |
7e2040f0 | 4516 | if (isIDFIRST_lazy_if(s,UTF)) { |
3280af22 | 4517 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len); |
09bef843 SB |
4518 | if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3)) |
4519 | goto really_sub; | |
def3634b | 4520 | PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len); |
3280af22 | 4521 | if (!PL_in_my_stash) { |
c750a3ec | 4522 | char tmpbuf[1024]; |
3280af22 NIS |
4523 | PL_bufptr = s; |
4524 | sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf); | |
c750a3ec MB |
4525 | yyerror(tmpbuf); |
4526 | } | |
4527 | } | |
09bef843 | 4528 | yylval.ival = 1; |
55497cff | 4529 | OPERATOR(MY); |
93a17b20 | 4530 | |
79072805 | 4531 | case KEY_next: |
a0d0e21e | 4532 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4533 | LOOPX(OP_NEXT); |
4534 | ||
4535 | case KEY_ne: | |
4536 | Eop(OP_SNE); | |
4537 | ||
a0d0e21e | 4538 | case KEY_no: |
3280af22 | 4539 | if (PL_expect != XSTATE) |
a0d0e21e LW |
4540 | yyerror("\"no\" not allowed in expression"); |
4541 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
e759cc13 | 4542 | s = force_version(s, FALSE); |
a0d0e21e LW |
4543 | yylval.ival = 0; |
4544 | OPERATOR(USE); | |
4545 | ||
4546 | case KEY_not: | |
2d2e263d LW |
4547 | if (*s == '(' || (s = skipspace(s), *s == '(')) |
4548 | FUN1(OP_NOT); | |
4549 | else | |
4550 | OPERATOR(NOTOP); | |
a0d0e21e | 4551 | |
79072805 | 4552 | case KEY_open: |
93a17b20 | 4553 | s = skipspace(s); |
7e2040f0 | 4554 | if (isIDFIRST_lazy_if(s,UTF)) { |
93a17b20 | 4555 | char *t; |
7e2040f0 | 4556 | for (d = s; isALNUM_lazy_if(d,UTF); d++) ; |
93a17b20 | 4557 | t = skipspace(d); |
e476b1b5 GS |
4558 | if (strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)) |
4559 | Perl_warner(aTHX_ WARN_PRECEDENCE, | |
0453d815 PM |
4560 | "Precedence problem: open %.*s should be open(%.*s)", |
4561 | d-s,s, d-s,s); | |
93a17b20 | 4562 | } |
a0d0e21e | 4563 | LOP(OP_OPEN,XTERM); |
79072805 | 4564 | |
463ee0b2 | 4565 | case KEY_or: |
a0d0e21e | 4566 | yylval.ival = OP_OR; |
463ee0b2 LW |
4567 | OPERATOR(OROP); |
4568 | ||
79072805 LW |
4569 | case KEY_ord: |
4570 | UNI(OP_ORD); | |
4571 | ||
4572 | case KEY_oct: | |
4573 | UNI(OP_OCT); | |
4574 | ||
4575 | case KEY_opendir: | |
a0d0e21e | 4576 | LOP(OP_OPEN_DIR,XTERM); |
79072805 LW |
4577 | |
4578 | case KEY_print: | |
3280af22 | 4579 | checkcomma(s,PL_tokenbuf,"filehandle"); |
a0d0e21e | 4580 | LOP(OP_PRINT,XREF); |
79072805 LW |
4581 | |
4582 | case KEY_printf: | |
3280af22 | 4583 | checkcomma(s,PL_tokenbuf,"filehandle"); |
a0d0e21e | 4584 | LOP(OP_PRTF,XREF); |
79072805 | 4585 | |
c07a80fd | 4586 | case KEY_prototype: |
4587 | UNI(OP_PROTOTYPE); | |
4588 | ||
79072805 | 4589 | case KEY_push: |
a0d0e21e | 4590 | LOP(OP_PUSH,XTERM); |
79072805 LW |
4591 | |
4592 | case KEY_pop: | |
4593 | UNI(OP_POP); | |
4594 | ||
a0d0e21e LW |
4595 | case KEY_pos: |
4596 | UNI(OP_POS); | |
4e553d73 | 4597 | |
79072805 | 4598 | case KEY_pack: |
a0d0e21e | 4599 | LOP(OP_PACK,XTERM); |
79072805 LW |
4600 | |
4601 | case KEY_package: | |
a0d0e21e | 4602 | s = force_word(s,WORD,FALSE,TRUE,FALSE); |
79072805 LW |
4603 | OPERATOR(PACKAGE); |
4604 | ||
4605 | case KEY_pipe: | |
a0d0e21e | 4606 | LOP(OP_PIPE_OP,XTERM); |
79072805 LW |
4607 | |
4608 | case KEY_q: | |
09bef843 | 4609 | s = scan_str(s,FALSE,FALSE); |
79072805 | 4610 | if (!s) |
85e6fe83 | 4611 | missingterm((char*)0); |
79072805 LW |
4612 | yylval.ival = OP_CONST; |
4613 | TERM(sublex_start()); | |
4614 | ||
a0d0e21e LW |
4615 | case KEY_quotemeta: |
4616 | UNI(OP_QUOTEMETA); | |
4617 | ||
8990e307 | 4618 | case KEY_qw: |
09bef843 | 4619 | s = scan_str(s,FALSE,FALSE); |
8990e307 | 4620 | if (!s) |
85e6fe83 | 4621 | missingterm((char*)0); |
8127e0e3 GS |
4622 | force_next(')'); |
4623 | if (SvCUR(PL_lex_stuff)) { | |
4624 | OP *words = Nullop; | |
4625 | int warned = 0; | |
3280af22 | 4626 | d = SvPV_force(PL_lex_stuff, len); |
8127e0e3 | 4627 | while (len) { |
7948272d | 4628 | SV *sv; |
8127e0e3 GS |
4629 | for (; isSPACE(*d) && len; --len, ++d) ; |
4630 | if (len) { | |
4631 | char *b = d; | |
e476b1b5 | 4632 | if (!warned && ckWARN(WARN_QW)) { |
8127e0e3 GS |
4633 | for (; !isSPACE(*d) && len; --len, ++d) { |
4634 | if (*d == ',') { | |
e476b1b5 | 4635 | Perl_warner(aTHX_ WARN_QW, |
8127e0e3 GS |
4636 | "Possible attempt to separate words with commas"); |
4637 | ++warned; | |
4638 | } | |
4639 | else if (*d == '#') { | |
e476b1b5 | 4640 | Perl_warner(aTHX_ WARN_QW, |
8127e0e3 GS |
4641 | "Possible attempt to put comments in qw() list"); |
4642 | ++warned; | |
4643 | } | |
4644 | } | |
4645 | } | |
4646 | else { | |
4647 | for (; !isSPACE(*d) && len; --len, ++d) ; | |
4648 | } | |
7948272d NIS |
4649 | sv = newSVpvn(b, d-b); |
4650 | if (DO_UTF8(PL_lex_stuff)) | |
4651 | SvUTF8_on(sv); | |
8127e0e3 | 4652 | words = append_elem(OP_LIST, words, |
7948272d | 4653 | newSVOP(OP_CONST, 0, tokeq(sv))); |
55497cff | 4654 | } |
4655 | } | |
8127e0e3 GS |
4656 | if (words) { |
4657 | PL_nextval[PL_nexttoke].opval = words; | |
4658 | force_next(THING); | |
4659 | } | |
55497cff | 4660 | } |
37fd879b | 4661 | if (PL_lex_stuff) { |
8127e0e3 | 4662 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
4663 | PL_lex_stuff = Nullsv; |
4664 | } | |
3280af22 | 4665 | PL_expect = XTERM; |
8127e0e3 | 4666 | TOKEN('('); |
8990e307 | 4667 | |
79072805 | 4668 | case KEY_qq: |
09bef843 | 4669 | s = scan_str(s,FALSE,FALSE); |
79072805 | 4670 | if (!s) |
85e6fe83 | 4671 | missingterm((char*)0); |
a0d0e21e | 4672 | yylval.ival = OP_STRINGIFY; |
3280af22 NIS |
4673 | if (SvIVX(PL_lex_stuff) == '\'') |
4674 | SvIVX(PL_lex_stuff) = 0; /* qq'$foo' should intepolate */ | |
79072805 LW |
4675 | TERM(sublex_start()); |
4676 | ||
8782bef2 GB |
4677 | case KEY_qr: |
4678 | s = scan_pat(s,OP_QR); | |
4679 | TERM(sublex_start()); | |
4680 | ||
79072805 | 4681 | case KEY_qx: |
09bef843 | 4682 | s = scan_str(s,FALSE,FALSE); |
79072805 | 4683 | if (!s) |
85e6fe83 | 4684 | missingterm((char*)0); |
79072805 LW |
4685 | yylval.ival = OP_BACKTICK; |
4686 | set_csh(); | |
4687 | TERM(sublex_start()); | |
4688 | ||
4689 | case KEY_return: | |
4690 | OLDLOP(OP_RETURN); | |
4691 | ||
4692 | case KEY_require: | |
a7cb1f99 | 4693 | s = skipspace(s); |
e759cc13 RGS |
4694 | if (isDIGIT(*s)) { |
4695 | s = force_version(s, FALSE); | |
a7cb1f99 | 4696 | } |
e759cc13 RGS |
4697 | else if (*s != 'v' || !isDIGIT(s[1]) |
4698 | || (s = force_version(s, TRUE), *s == 'v')) | |
4699 | { | |
a7cb1f99 GS |
4700 | *PL_tokenbuf = '\0'; |
4701 | s = force_word(s,WORD,TRUE,TRUE,FALSE); | |
7e2040f0 | 4702 | if (isIDFIRST_lazy_if(PL_tokenbuf,UTF)) |
a7cb1f99 GS |
4703 | gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE); |
4704 | else if (*s == '<') | |
4705 | yyerror("<> should be quotes"); | |
4706 | } | |
463ee0b2 | 4707 | UNI(OP_REQUIRE); |
79072805 LW |
4708 | |
4709 | case KEY_reset: | |
4710 | UNI(OP_RESET); | |
4711 | ||
4712 | case KEY_redo: | |
a0d0e21e | 4713 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4714 | LOOPX(OP_REDO); |
4715 | ||
4716 | case KEY_rename: | |
a0d0e21e | 4717 | LOP(OP_RENAME,XTERM); |
79072805 LW |
4718 | |
4719 | case KEY_rand: | |
4720 | UNI(OP_RAND); | |
4721 | ||
4722 | case KEY_rmdir: | |
4723 | UNI(OP_RMDIR); | |
4724 | ||
4725 | case KEY_rindex: | |
a0d0e21e | 4726 | LOP(OP_RINDEX,XTERM); |
79072805 LW |
4727 | |
4728 | case KEY_read: | |
a0d0e21e | 4729 | LOP(OP_READ,XTERM); |
79072805 LW |
4730 | |
4731 | case KEY_readdir: | |
4732 | UNI(OP_READDIR); | |
4733 | ||
93a17b20 LW |
4734 | case KEY_readline: |
4735 | set_csh(); | |
4736 | UNI(OP_READLINE); | |
4737 | ||
4738 | case KEY_readpipe: | |
4739 | set_csh(); | |
4740 | UNI(OP_BACKTICK); | |
4741 | ||
79072805 LW |
4742 | case KEY_rewinddir: |
4743 | UNI(OP_REWINDDIR); | |
4744 | ||
4745 | case KEY_recv: | |
a0d0e21e | 4746 | LOP(OP_RECV,XTERM); |
79072805 LW |
4747 | |
4748 | case KEY_reverse: | |
a0d0e21e | 4749 | LOP(OP_REVERSE,XTERM); |
79072805 LW |
4750 | |
4751 | case KEY_readlink: | |
4752 | UNI(OP_READLINK); | |
4753 | ||
4754 | case KEY_ref: | |
4755 | UNI(OP_REF); | |
4756 | ||
4757 | case KEY_s: | |
4758 | s = scan_subst(s); | |
4759 | if (yylval.opval) | |
4760 | TERM(sublex_start()); | |
4761 | else | |
4762 | TOKEN(1); /* force error */ | |
4763 | ||
a0d0e21e LW |
4764 | case KEY_chomp: |
4765 | UNI(OP_CHOMP); | |
4e553d73 | 4766 | |
79072805 LW |
4767 | case KEY_scalar: |
4768 | UNI(OP_SCALAR); | |
4769 | ||
4770 | case KEY_select: | |
a0d0e21e | 4771 | LOP(OP_SELECT,XTERM); |
79072805 LW |
4772 | |
4773 | case KEY_seek: | |
a0d0e21e | 4774 | LOP(OP_SEEK,XTERM); |
79072805 LW |
4775 | |
4776 | case KEY_semctl: | |
a0d0e21e | 4777 | LOP(OP_SEMCTL,XTERM); |
79072805 LW |
4778 | |
4779 | case KEY_semget: | |
a0d0e21e | 4780 | LOP(OP_SEMGET,XTERM); |
79072805 LW |
4781 | |
4782 | case KEY_semop: | |
a0d0e21e | 4783 | LOP(OP_SEMOP,XTERM); |
79072805 LW |
4784 | |
4785 | case KEY_send: | |
a0d0e21e | 4786 | LOP(OP_SEND,XTERM); |
79072805 LW |
4787 | |
4788 | case KEY_setpgrp: | |
a0d0e21e | 4789 | LOP(OP_SETPGRP,XTERM); |
79072805 LW |
4790 | |
4791 | case KEY_setpriority: | |
a0d0e21e | 4792 | LOP(OP_SETPRIORITY,XTERM); |
79072805 LW |
4793 | |
4794 | case KEY_sethostent: | |
ff68c719 | 4795 | UNI(OP_SHOSTENT); |
79072805 LW |
4796 | |
4797 | case KEY_setnetent: | |
ff68c719 | 4798 | UNI(OP_SNETENT); |
79072805 LW |
4799 | |
4800 | case KEY_setservent: | |
ff68c719 | 4801 | UNI(OP_SSERVENT); |
79072805 LW |
4802 | |
4803 | case KEY_setprotoent: | |
ff68c719 | 4804 | UNI(OP_SPROTOENT); |
79072805 LW |
4805 | |
4806 | case KEY_setpwent: | |
4807 | FUN0(OP_SPWENT); | |
4808 | ||
4809 | case KEY_setgrent: | |
4810 | FUN0(OP_SGRENT); | |
4811 | ||
4812 | case KEY_seekdir: | |
a0d0e21e | 4813 | LOP(OP_SEEKDIR,XTERM); |
79072805 LW |
4814 | |
4815 | case KEY_setsockopt: | |
a0d0e21e | 4816 | LOP(OP_SSOCKOPT,XTERM); |
79072805 LW |
4817 | |
4818 | case KEY_shift: | |
4819 | UNI(OP_SHIFT); | |
4820 | ||
4821 | case KEY_shmctl: | |
a0d0e21e | 4822 | LOP(OP_SHMCTL,XTERM); |
79072805 LW |
4823 | |
4824 | case KEY_shmget: | |
a0d0e21e | 4825 | LOP(OP_SHMGET,XTERM); |
79072805 LW |
4826 | |
4827 | case KEY_shmread: | |
a0d0e21e | 4828 | LOP(OP_SHMREAD,XTERM); |
79072805 LW |
4829 | |
4830 | case KEY_shmwrite: | |
a0d0e21e | 4831 | LOP(OP_SHMWRITE,XTERM); |
79072805 LW |
4832 | |
4833 | case KEY_shutdown: | |
a0d0e21e | 4834 | LOP(OP_SHUTDOWN,XTERM); |
79072805 LW |
4835 | |
4836 | case KEY_sin: | |
4837 | UNI(OP_SIN); | |
4838 | ||
4839 | case KEY_sleep: | |
4840 | UNI(OP_SLEEP); | |
4841 | ||
4842 | case KEY_socket: | |
a0d0e21e | 4843 | LOP(OP_SOCKET,XTERM); |
79072805 LW |
4844 | |
4845 | case KEY_socketpair: | |
a0d0e21e | 4846 | LOP(OP_SOCKPAIR,XTERM); |
79072805 LW |
4847 | |
4848 | case KEY_sort: | |
3280af22 | 4849 | checkcomma(s,PL_tokenbuf,"subroutine name"); |
79072805 LW |
4850 | s = skipspace(s); |
4851 | if (*s == ';' || *s == ')') /* probably a close */ | |
cea2e8a9 | 4852 | Perl_croak(aTHX_ "sort is now a reserved word"); |
3280af22 | 4853 | PL_expect = XTERM; |
15f0808c | 4854 | s = force_word(s,WORD,TRUE,TRUE,FALSE); |
a0d0e21e | 4855 | LOP(OP_SORT,XREF); |
79072805 LW |
4856 | |
4857 | case KEY_split: | |
a0d0e21e | 4858 | LOP(OP_SPLIT,XTERM); |
79072805 LW |
4859 | |
4860 | case KEY_sprintf: | |
a0d0e21e | 4861 | LOP(OP_SPRINTF,XTERM); |
79072805 LW |
4862 | |
4863 | case KEY_splice: | |
a0d0e21e | 4864 | LOP(OP_SPLICE,XTERM); |
79072805 LW |
4865 | |
4866 | case KEY_sqrt: | |
4867 | UNI(OP_SQRT); | |
4868 | ||
4869 | case KEY_srand: | |
4870 | UNI(OP_SRAND); | |
4871 | ||
4872 | case KEY_stat: | |
4873 | UNI(OP_STAT); | |
4874 | ||
4875 | case KEY_study: | |
79072805 LW |
4876 | UNI(OP_STUDY); |
4877 | ||
4878 | case KEY_substr: | |
a0d0e21e | 4879 | LOP(OP_SUBSTR,XTERM); |
79072805 LW |
4880 | |
4881 | case KEY_format: | |
4882 | case KEY_sub: | |
93a17b20 | 4883 | really_sub: |
09bef843 | 4884 | { |
3280af22 | 4885 | char tmpbuf[sizeof PL_tokenbuf]; |
9c5ffd7c | 4886 | SSize_t tboffset = 0; |
09bef843 SB |
4887 | expectation attrful; |
4888 | bool have_name, have_proto; | |
4889 | int key = tmp; | |
4890 | ||
4891 | s = skipspace(s); | |
4892 | ||
7e2040f0 | 4893 | if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' || |
09bef843 SB |
4894 | (*s == ':' && s[1] == ':')) |
4895 | { | |
4896 | PL_expect = XBLOCK; | |
4897 | attrful = XATTRBLOCK; | |
b1b65b59 JH |
4898 | /* remember buffer pos'n for later force_word */ |
4899 | tboffset = s - PL_oldbufptr; | |
09bef843 SB |
4900 | d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
4901 | if (strchr(tmpbuf, ':')) | |
4902 | sv_setpv(PL_subname, tmpbuf); | |
4903 | else { | |
4904 | sv_setsv(PL_subname,PL_curstname); | |
4905 | sv_catpvn(PL_subname,"::",2); | |
4906 | sv_catpvn(PL_subname,tmpbuf,len); | |
4907 | } | |
4908 | s = skipspace(d); | |
4909 | have_name = TRUE; | |
4910 | } | |
463ee0b2 | 4911 | else { |
09bef843 SB |
4912 | if (key == KEY_my) |
4913 | Perl_croak(aTHX_ "Missing name in \"my sub\""); | |
4914 | PL_expect = XTERMBLOCK; | |
4915 | attrful = XATTRTERM; | |
4916 | sv_setpv(PL_subname,"?"); | |
4917 | have_name = FALSE; | |
463ee0b2 | 4918 | } |
4633a7c4 | 4919 | |
09bef843 SB |
4920 | if (key == KEY_format) { |
4921 | if (*s == '=') | |
4922 | PL_lex_formbrack = PL_lex_brackets + 1; | |
4923 | if (have_name) | |
b1b65b59 JH |
4924 | (void) force_word(PL_oldbufptr + tboffset, WORD, |
4925 | FALSE, TRUE, TRUE); | |
09bef843 SB |
4926 | OPERATOR(FORMAT); |
4927 | } | |
79072805 | 4928 | |
09bef843 SB |
4929 | /* Look for a prototype */ |
4930 | if (*s == '(') { | |
4931 | char *p; | |
4932 | ||
4933 | s = scan_str(s,FALSE,FALSE); | |
37fd879b | 4934 | if (!s) |
09bef843 | 4935 | Perl_croak(aTHX_ "Prototype not terminated"); |
09bef843 SB |
4936 | /* strip spaces */ |
4937 | d = SvPVX(PL_lex_stuff); | |
4938 | tmp = 0; | |
4939 | for (p = d; *p; ++p) { | |
4940 | if (!isSPACE(*p)) | |
4941 | d[tmp++] = *p; | |
4942 | } | |
4943 | d[tmp] = '\0'; | |
4944 | SvCUR(PL_lex_stuff) = tmp; | |
4945 | have_proto = TRUE; | |
68dc0745 | 4946 | |
09bef843 | 4947 | s = skipspace(s); |
4633a7c4 | 4948 | } |
09bef843 SB |
4949 | else |
4950 | have_proto = FALSE; | |
4951 | ||
4952 | if (*s == ':' && s[1] != ':') | |
4953 | PL_expect = attrful; | |
4954 | ||
4955 | if (have_proto) { | |
b1b65b59 JH |
4956 | PL_nextval[PL_nexttoke].opval = |
4957 | (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff); | |
09bef843 SB |
4958 | PL_lex_stuff = Nullsv; |
4959 | force_next(THING); | |
68dc0745 | 4960 | } |
09bef843 SB |
4961 | if (!have_name) { |
4962 | sv_setpv(PL_subname,"__ANON__"); | |
4963 | TOKEN(ANONSUB); | |
4633a7c4 | 4964 | } |
b1b65b59 JH |
4965 | (void) force_word(PL_oldbufptr + tboffset, WORD, |
4966 | FALSE, TRUE, TRUE); | |
09bef843 SB |
4967 | if (key == KEY_my) |
4968 | TOKEN(MYSUB); | |
4969 | TOKEN(SUB); | |
4633a7c4 | 4970 | } |
79072805 LW |
4971 | |
4972 | case KEY_system: | |
4973 | set_csh(); | |
a0d0e21e | 4974 | LOP(OP_SYSTEM,XREF); |
79072805 LW |
4975 | |
4976 | case KEY_symlink: | |
a0d0e21e | 4977 | LOP(OP_SYMLINK,XTERM); |
79072805 LW |
4978 | |
4979 | case KEY_syscall: | |
a0d0e21e | 4980 | LOP(OP_SYSCALL,XTERM); |
79072805 | 4981 | |
c07a80fd | 4982 | case KEY_sysopen: |
4983 | LOP(OP_SYSOPEN,XTERM); | |
4984 | ||
137443ea | 4985 | case KEY_sysseek: |
4986 | LOP(OP_SYSSEEK,XTERM); | |
4987 | ||
79072805 | 4988 | case KEY_sysread: |
a0d0e21e | 4989 | LOP(OP_SYSREAD,XTERM); |
79072805 LW |
4990 | |
4991 | case KEY_syswrite: | |
a0d0e21e | 4992 | LOP(OP_SYSWRITE,XTERM); |
79072805 LW |
4993 | |
4994 | case KEY_tr: | |
4995 | s = scan_trans(s); | |
4996 | TERM(sublex_start()); | |
4997 | ||
4998 | case KEY_tell: | |
4999 | UNI(OP_TELL); | |
5000 | ||
5001 | case KEY_telldir: | |
5002 | UNI(OP_TELLDIR); | |
5003 | ||
463ee0b2 | 5004 | case KEY_tie: |
a0d0e21e | 5005 | LOP(OP_TIE,XTERM); |
463ee0b2 | 5006 | |
c07a80fd | 5007 | case KEY_tied: |
5008 | UNI(OP_TIED); | |
5009 | ||
79072805 LW |
5010 | case KEY_time: |
5011 | FUN0(OP_TIME); | |
5012 | ||
5013 | case KEY_times: | |
5014 | FUN0(OP_TMS); | |
5015 | ||
5016 | case KEY_truncate: | |
a0d0e21e | 5017 | LOP(OP_TRUNCATE,XTERM); |
79072805 LW |
5018 | |
5019 | case KEY_uc: | |
5020 | UNI(OP_UC); | |
5021 | ||
5022 | case KEY_ucfirst: | |
5023 | UNI(OP_UCFIRST); | |
5024 | ||
463ee0b2 LW |
5025 | case KEY_untie: |
5026 | UNI(OP_UNTIE); | |
5027 | ||
79072805 | 5028 | case KEY_until: |
57843af0 | 5029 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5030 | OPERATOR(UNTIL); |
5031 | ||
5032 | case KEY_unless: | |
57843af0 | 5033 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5034 | OPERATOR(UNLESS); |
5035 | ||
5036 | case KEY_unlink: | |
a0d0e21e | 5037 | LOP(OP_UNLINK,XTERM); |
79072805 LW |
5038 | |
5039 | case KEY_undef: | |
5040 | UNI(OP_UNDEF); | |
5041 | ||
5042 | case KEY_unpack: | |
a0d0e21e | 5043 | LOP(OP_UNPACK,XTERM); |
79072805 LW |
5044 | |
5045 | case KEY_utime: | |
a0d0e21e | 5046 | LOP(OP_UTIME,XTERM); |
79072805 LW |
5047 | |
5048 | case KEY_umask: | |
5049 | UNI(OP_UMASK); | |
5050 | ||
5051 | case KEY_unshift: | |
a0d0e21e LW |
5052 | LOP(OP_UNSHIFT,XTERM); |
5053 | ||
5054 | case KEY_use: | |
3280af22 | 5055 | if (PL_expect != XSTATE) |
a0d0e21e | 5056 | yyerror("\"use\" not allowed in expression"); |
89bfa8cd | 5057 | s = skipspace(s); |
a7cb1f99 | 5058 | if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) { |
e759cc13 | 5059 | s = force_version(s, TRUE); |
a7cb1f99 | 5060 | if (*s == ';' || (s = skipspace(s), *s == ';')) { |
3280af22 | 5061 | PL_nextval[PL_nexttoke].opval = Nullop; |
89bfa8cd | 5062 | force_next(WORD); |
5063 | } | |
e759cc13 RGS |
5064 | else if (*s == 'v') { |
5065 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
5066 | s = force_version(s, FALSE); | |
5067 | } | |
89bfa8cd | 5068 | } |
5069 | else { | |
5070 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
e759cc13 | 5071 | s = force_version(s, FALSE); |
89bfa8cd | 5072 | } |
a0d0e21e LW |
5073 | yylval.ival = 1; |
5074 | OPERATOR(USE); | |
79072805 LW |
5075 | |
5076 | case KEY_values: | |
5077 | UNI(OP_VALUES); | |
5078 | ||
5079 | case KEY_vec: | |
a0d0e21e | 5080 | LOP(OP_VEC,XTERM); |
79072805 LW |
5081 | |
5082 | case KEY_while: | |
57843af0 | 5083 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5084 | OPERATOR(WHILE); |
5085 | ||
5086 | case KEY_warn: | |
3280af22 | 5087 | PL_hints |= HINT_BLOCK_SCOPE; |
a0d0e21e | 5088 | LOP(OP_WARN,XTERM); |
79072805 LW |
5089 | |
5090 | case KEY_wait: | |
5091 | FUN0(OP_WAIT); | |
5092 | ||
5093 | case KEY_waitpid: | |
a0d0e21e | 5094 | LOP(OP_WAITPID,XTERM); |
79072805 LW |
5095 | |
5096 | case KEY_wantarray: | |
5097 | FUN0(OP_WANTARRAY); | |
5098 | ||
5099 | case KEY_write: | |
9d116dd7 JH |
5100 | #ifdef EBCDIC |
5101 | { | |
5102 | static char ctl_l[2]; | |
5103 | ||
4e553d73 | 5104 | if (ctl_l[0] == '\0') |
9d116dd7 JH |
5105 | ctl_l[0] = toCTRL('L'); |
5106 | gv_fetchpv(ctl_l,TRUE, SVt_PV); | |
5107 | } | |
5108 | #else | |
5109 | gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */ | |
5110 | #endif | |
79072805 LW |
5111 | UNI(OP_ENTERWRITE); |
5112 | ||
5113 | case KEY_x: | |
3280af22 | 5114 | if (PL_expect == XOPERATOR) |
79072805 LW |
5115 | Mop(OP_REPEAT); |
5116 | check_uni(); | |
5117 | goto just_a_word; | |
5118 | ||
a0d0e21e LW |
5119 | case KEY_xor: |
5120 | yylval.ival = OP_XOR; | |
5121 | OPERATOR(OROP); | |
5122 | ||
79072805 LW |
5123 | case KEY_y: |
5124 | s = scan_trans(s); | |
5125 | TERM(sublex_start()); | |
5126 | } | |
49dc05e3 | 5127 | }} |
79072805 | 5128 | } |
bf4acbe4 GS |
5129 | #ifdef __SC__ |
5130 | #pragma segment Main | |
5131 | #endif | |
79072805 | 5132 | |
e930465f JH |
5133 | static int |
5134 | S_pending_ident(pTHX) | |
8eceec63 SC |
5135 | { |
5136 | register char *d; | |
5137 | register I32 tmp; | |
5138 | /* pit holds the identifier we read and pending_ident is reset */ | |
5139 | char pit = PL_pending_ident; | |
5140 | PL_pending_ident = 0; | |
5141 | ||
5142 | DEBUG_T({ PerlIO_printf(Perl_debug_log, | |
5143 | "### Tokener saw identifier '%s'\n", PL_tokenbuf); }); | |
5144 | ||
5145 | /* if we're in a my(), we can't allow dynamics here. | |
5146 | $foo'bar has already been turned into $foo::bar, so | |
5147 | just check for colons. | |
5148 | ||
5149 | if it's a legal name, the OP is a PADANY. | |
5150 | */ | |
5151 | if (PL_in_my) { | |
5152 | if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */ | |
5153 | if (strchr(PL_tokenbuf,':')) | |
5154 | yyerror(Perl_form(aTHX_ "No package name allowed for " | |
5155 | "variable %s in \"our\"", | |
5156 | PL_tokenbuf)); | |
5157 | tmp = pad_allocmy(PL_tokenbuf); | |
5158 | } | |
5159 | else { | |
5160 | if (strchr(PL_tokenbuf,':')) | |
5161 | yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf)); | |
5162 | ||
5163 | yylval.opval = newOP(OP_PADANY, 0); | |
5164 | yylval.opval->op_targ = pad_allocmy(PL_tokenbuf); | |
5165 | return PRIVATEREF; | |
5166 | } | |
5167 | } | |
5168 | ||
5169 | /* | |
5170 | build the ops for accesses to a my() variable. | |
5171 | ||
5172 | Deny my($a) or my($b) in a sort block, *if* $a or $b is | |
5173 | then used in a comparison. This catches most, but not | |
5174 | all cases. For instance, it catches | |
5175 | sort { my($a); $a <=> $b } | |
5176 | but not | |
5177 | sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; } | |
5178 | (although why you'd do that is anyone's guess). | |
5179 | */ | |
5180 | ||
5181 | if (!strchr(PL_tokenbuf,':')) { | |
4d1ff10f | 5182 | #ifdef USE_5005THREADS |
8eceec63 SC |
5183 | /* Check for single character per-thread SVs */ |
5184 | if (PL_tokenbuf[0] == '$' && PL_tokenbuf[2] == '\0' | |
5185 | && !isALPHA(PL_tokenbuf[1]) /* Rule out obvious non-threadsvs */ | |
5186 | && (tmp = find_threadsv(&PL_tokenbuf[1])) != NOT_IN_PAD) | |
5187 | { | |
5188 | yylval.opval = newOP(OP_THREADSV, 0); | |
5189 | yylval.opval->op_targ = tmp; | |
5190 | return PRIVATEREF; | |
5191 | } | |
4d1ff10f | 5192 | #endif /* USE_5005THREADS */ |
8eceec63 SC |
5193 | if ((tmp = pad_findmy(PL_tokenbuf)) != NOT_IN_PAD) { |
5194 | SV *namesv = AvARRAY(PL_comppad_name)[tmp]; | |
5195 | /* might be an "our" variable" */ | |
5196 | if (SvFLAGS(namesv) & SVpad_OUR) { | |
5197 | /* build ops for a bareword */ | |
5198 | SV *sym = newSVpv(HvNAME(GvSTASH(namesv)),0); | |
5199 | sv_catpvn(sym, "::", 2); | |
5200 | sv_catpv(sym, PL_tokenbuf+1); | |
5201 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym); | |
5202 | yylval.opval->op_private = OPpCONST_ENTERED; | |
5203 | gv_fetchpv(SvPVX(sym), | |
5204 | (PL_in_eval | |
5205 | ? (GV_ADDMULTI | GV_ADDINEVAL) | |
5206 | : TRUE | |
5207 | ), | |
5208 | ((PL_tokenbuf[0] == '$') ? SVt_PV | |
5209 | : (PL_tokenbuf[0] == '@') ? SVt_PVAV | |
5210 | : SVt_PVHV)); | |
5211 | return WORD; | |
5212 | } | |
5213 | ||
5214 | /* if it's a sort block and they're naming $a or $b */ | |
5215 | if (PL_last_lop_op == OP_SORT && | |
5216 | PL_tokenbuf[0] == '$' && | |
5217 | (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b') | |
5218 | && !PL_tokenbuf[2]) | |
5219 | { | |
5220 | for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart; | |
5221 | d < PL_bufend && *d != '\n'; | |
5222 | d++) | |
5223 | { | |
5224 | if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) { | |
5225 | Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison", | |
5226 | PL_tokenbuf); | |
5227 | } | |
5228 | } | |
5229 | } | |
5230 | ||
5231 | yylval.opval = newOP(OP_PADANY, 0); | |
5232 | yylval.opval->op_targ = tmp; | |
5233 | return PRIVATEREF; | |
5234 | } | |
5235 | } | |
5236 | ||
5237 | /* | |
5238 | Whine if they've said @foo in a doublequoted string, | |
5239 | and @foo isn't a variable we can find in the symbol | |
5240 | table. | |
5241 | */ | |
5242 | if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) { | |
5243 | GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV); | |
5244 | if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv))) | |
5245 | && ckWARN(WARN_AMBIGUOUS)) | |
5246 | { | |
5247 | /* Downgraded from fatal to warning 20000522 mjd */ | |
5248 | Perl_warner(aTHX_ WARN_AMBIGUOUS, | |
5249 | "Possible unintended interpolation of %s in string", | |
5250 | PL_tokenbuf); | |
5251 | } | |
5252 | } | |
5253 | ||
5254 | /* build ops for a bareword */ | |
5255 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0)); | |
5256 | yylval.opval->op_private = OPpCONST_ENTERED; | |
5257 | gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE, | |
5258 | ((PL_tokenbuf[0] == '$') ? SVt_PV | |
5259 | : (PL_tokenbuf[0] == '@') ? SVt_PVAV | |
5260 | : SVt_PVHV)); | |
5261 | return WORD; | |
5262 | } | |
5263 | ||
79072805 | 5264 | I32 |
864dbfa3 | 5265 | Perl_keyword(pTHX_ register char *d, I32 len) |
79072805 LW |
5266 | { |
5267 | switch (*d) { | |
5268 | case '_': | |
5269 | if (d[1] == '_') { | |
a0d0e21e | 5270 | if (strEQ(d,"__FILE__")) return -KEY___FILE__; |
68dc0745 | 5271 | if (strEQ(d,"__LINE__")) return -KEY___LINE__; |
5272 | if (strEQ(d,"__PACKAGE__")) return -KEY___PACKAGE__; | |
e50aee73 | 5273 | if (strEQ(d,"__DATA__")) return KEY___DATA__; |
79072805 LW |
5274 | if (strEQ(d,"__END__")) return KEY___END__; |
5275 | } | |
5276 | break; | |
8990e307 LW |
5277 | case 'A': |
5278 | if (strEQ(d,"AUTOLOAD")) return KEY_AUTOLOAD; | |
5279 | break; | |
79072805 | 5280 | case 'a': |
463ee0b2 LW |
5281 | switch (len) { |
5282 | case 3: | |
a0d0e21e LW |
5283 | if (strEQ(d,"and")) return -KEY_and; |
5284 | if (strEQ(d,"abs")) return -KEY_abs; | |
85e6fe83 | 5285 | break; |
463ee0b2 | 5286 | case 5: |
a0d0e21e LW |
5287 | if (strEQ(d,"alarm")) return -KEY_alarm; |
5288 | if (strEQ(d,"atan2")) return -KEY_atan2; | |
463ee0b2 LW |
5289 | break; |
5290 | case 6: | |
a0d0e21e | 5291 | if (strEQ(d,"accept")) return -KEY_accept; |
463ee0b2 LW |
5292 | break; |
5293 | } | |
79072805 LW |
5294 | break; |
5295 | case 'B': | |
5296 | if (strEQ(d,"BEGIN")) return KEY_BEGIN; | |
93a17b20 | 5297 | break; |
79072805 | 5298 | case 'b': |
a0d0e21e LW |
5299 | if (strEQ(d,"bless")) return -KEY_bless; |
5300 | if (strEQ(d,"bind")) return -KEY_bind; | |
5301 | if (strEQ(d,"binmode")) return -KEY_binmode; | |
5302 | break; | |
5303 | case 'C': | |
5304 | if (strEQ(d,"CORE")) return -KEY_CORE; | |
7d30b5c4 | 5305 | if (strEQ(d,"CHECK")) return KEY_CHECK; |
79072805 LW |
5306 | break; |
5307 | case 'c': | |
5308 | switch (len) { | |
5309 | case 3: | |
a0d0e21e LW |
5310 | if (strEQ(d,"cmp")) return -KEY_cmp; |
5311 | if (strEQ(d,"chr")) return -KEY_chr; | |
5312 | if (strEQ(d,"cos")) return -KEY_cos; | |
79072805 LW |
5313 | break; |
5314 | case 4: | |
79e5458b | 5315 | if (strEQ(d,"chop")) return -KEY_chop; |
79072805 LW |
5316 | break; |
5317 | case 5: | |
a0d0e21e LW |
5318 | if (strEQ(d,"close")) return -KEY_close; |
5319 | if (strEQ(d,"chdir")) return -KEY_chdir; | |
79e5458b | 5320 | if (strEQ(d,"chomp")) return -KEY_chomp; |
a0d0e21e LW |
5321 | if (strEQ(d,"chmod")) return -KEY_chmod; |
5322 | if (strEQ(d,"chown")) return -KEY_chown; | |
5323 | if (strEQ(d,"crypt")) return -KEY_crypt; | |
79072805 LW |
5324 | break; |
5325 | case 6: | |
a0d0e21e LW |
5326 | if (strEQ(d,"chroot")) return -KEY_chroot; |
5327 | if (strEQ(d,"caller")) return -KEY_caller; | |
79072805 LW |
5328 | break; |
5329 | case 7: | |
a0d0e21e | 5330 | if (strEQ(d,"connect")) return -KEY_connect; |
79072805 LW |
5331 | break; |
5332 | case 8: | |
a0d0e21e LW |
5333 | if (strEQ(d,"closedir")) return -KEY_closedir; |
5334 | if (strEQ(d,"continue")) return -KEY_continue; | |
79072805 LW |
5335 | break; |
5336 | } | |
5337 | break; | |
ed6116ce LW |
5338 | case 'D': |
5339 | if (strEQ(d,"DESTROY")) return KEY_DESTROY; | |
5340 | break; | |
79072805 LW |
5341 | case 'd': |
5342 | switch (len) { | |
5343 | case 2: | |
5344 | if (strEQ(d,"do")) return KEY_do; | |
5345 | break; | |
5346 | case 3: | |
a0d0e21e | 5347 | if (strEQ(d,"die")) return -KEY_die; |
79072805 LW |
5348 | break; |
5349 | case 4: | |
a0d0e21e | 5350 | if (strEQ(d,"dump")) return -KEY_dump; |
79072805 LW |
5351 | break; |
5352 | case 6: | |
5353 | if (strEQ(d,"delete")) return KEY_delete; | |
5354 | break; | |
5355 | case 7: | |
5356 | if (strEQ(d,"defined")) return KEY_defined; | |
a0d0e21e | 5357 | if (strEQ(d,"dbmopen")) return -KEY_dbmopen; |
79072805 LW |
5358 | break; |
5359 | case 8: | |
a0d0e21e | 5360 | if (strEQ(d,"dbmclose")) return -KEY_dbmclose; |
79072805 LW |
5361 | break; |
5362 | } | |
5363 | break; | |
5364 | case 'E': | |
79072805 LW |
5365 | if (strEQ(d,"END")) return KEY_END; |
5366 | break; | |
5367 | case 'e': | |
5368 | switch (len) { | |
5369 | case 2: | |
a0d0e21e | 5370 | if (strEQ(d,"eq")) return -KEY_eq; |
79072805 LW |
5371 | break; |
5372 | case 3: | |
a0d0e21e LW |
5373 | if (strEQ(d,"eof")) return -KEY_eof; |
5374 | if (strEQ(d,"exp")) return -KEY_exp; | |
79072805 LW |
5375 | break; |
5376 | case 4: | |
5377 | if (strEQ(d,"else")) return KEY_else; | |
a0d0e21e | 5378 | if (strEQ(d,"exit")) return -KEY_exit; |
79072805 | 5379 | if (strEQ(d,"eval")) return KEY_eval; |
a0d0e21e | 5380 | if (strEQ(d,"exec")) return -KEY_exec; |
3a6a8333 | 5381 | if (strEQ(d,"each")) return -KEY_each; |
79072805 LW |
5382 | break; |
5383 | case 5: | |
5384 | if (strEQ(d,"elsif")) return KEY_elsif; | |
5385 | break; | |
a0d0e21e LW |
5386 | case 6: |
5387 | if (strEQ(d,"exists")) return KEY_exists; | |
cea2e8a9 | 5388 | if (strEQ(d,"elseif")) Perl_warn(aTHX_ "elseif should be elsif"); |
a0d0e21e | 5389 | break; |
79072805 | 5390 | case 8: |
a0d0e21e LW |
5391 | if (strEQ(d,"endgrent")) return -KEY_endgrent; |
5392 | if (strEQ(d,"endpwent")) return -KEY_endpwent; | |
79072805 LW |
5393 | break; |
5394 | case 9: | |
a0d0e21e | 5395 | if (strEQ(d,"endnetent")) return -KEY_endnetent; |
79072805 LW |
5396 | break; |
5397 | case 10: | |
a0d0e21e LW |
5398 | if (strEQ(d,"endhostent")) return -KEY_endhostent; |
5399 | if (strEQ(d,"endservent")) return -KEY_endservent; | |
79072805 LW |
5400 | break; |
5401 | case 11: | |
a0d0e21e | 5402 | if (strEQ(d,"endprotoent")) return -KEY_endprotoent; |
79072805 | 5403 | break; |
a687059c | 5404 | } |
a687059c | 5405 | break; |
79072805 LW |
5406 | case 'f': |
5407 | switch (len) { | |
5408 | case 3: | |
5409 | if (strEQ(d,"for")) return KEY_for; | |
5410 | break; | |
5411 | case 4: | |
a0d0e21e | 5412 | if (strEQ(d,"fork")) return -KEY_fork; |
79072805 LW |
5413 | break; |
5414 | case 5: | |
a0d0e21e LW |
5415 | if (strEQ(d,"fcntl")) return -KEY_fcntl; |
5416 | if (strEQ(d,"flock")) return -KEY_flock; | |
79072805 LW |
5417 | break; |
5418 | case 6: | |
5419 | if (strEQ(d,"format")) return KEY_format; | |
a0d0e21e | 5420 | if (strEQ(d,"fileno")) return -KEY_fileno; |
79072805 LW |
5421 | break; |
5422 | case 7: | |
5423 | if (strEQ(d,"foreach")) return KEY_foreach; | |
5424 | break; | |
5425 | case 8: | |
a0d0e21e | 5426 | if (strEQ(d,"formline")) return -KEY_formline; |
79072805 | 5427 | break; |
378cc40b | 5428 | } |
a687059c | 5429 | break; |
79072805 | 5430 | case 'g': |
a687059c LW |
5431 | if (strnEQ(d,"get",3)) { |
5432 | d += 3; | |
5433 | if (*d == 'p') { | |
79072805 LW |
5434 | switch (len) { |
5435 | case 7: | |
a0d0e21e LW |
5436 | if (strEQ(d,"ppid")) return -KEY_getppid; |
5437 | if (strEQ(d,"pgrp")) return -KEY_getpgrp; | |
79072805 LW |
5438 | break; |
5439 | case 8: | |
a0d0e21e LW |
5440 | if (strEQ(d,"pwent")) return -KEY_getpwent; |
5441 | if (strEQ(d,"pwnam")) return -KEY_getpwnam; | |
5442 | if (strEQ(d,"pwuid")) return -KEY_getpwuid; | |
79072805 LW |
5443 | break; |
5444 | case 11: | |
a0d0e21e LW |
5445 | if (strEQ(d,"peername")) return -KEY_getpeername; |
5446 | if (strEQ(d,"protoent")) return -KEY_getprotoent; | |
5447 | if (strEQ(d,"priority")) return -KEY_getpriority; | |
79072805 LW |
5448 | break; |
5449 | case 14: | |
a0d0e21e | 5450 | if (strEQ(d,"protobyname")) return -KEY_getprotobyname; |
79072805 LW |
5451 | break; |
5452 | case 16: | |
a0d0e21e | 5453 | if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber; |
79072805 LW |
5454 | break; |
5455 | } | |
a687059c LW |
5456 | } |
5457 | else if (*d == 'h') { | |
a0d0e21e LW |
5458 | if (strEQ(d,"hostbyname")) return -KEY_gethostbyname; |
5459 | if (strEQ(d,"hostbyaddr")) return -KEY_gethostbyaddr; | |
5460 | if (strEQ(d,"hostent")) return -KEY_gethostent; | |
a687059c LW |
5461 | } |
5462 | else if (*d == 'n') { | |
a0d0e21e LW |
5463 | if (strEQ(d,"netbyname")) return -KEY_getnetbyname; |
5464 | if (strEQ(d,"netbyaddr")) return -KEY_getnetbyaddr; | |
5465 | if (strEQ(d,"netent")) return -KEY_getnetent; | |
a687059c LW |
5466 | } |
5467 | else if (*d == 's') { | |
a0d0e21e LW |
5468 | if (strEQ(d,"servbyname")) return -KEY_getservbyname; |
5469 | if (strEQ(d,"servbyport")) return -KEY_getservbyport; | |
5470 | if (strEQ(d,"servent")) return -KEY_getservent; | |
5471 | if (strEQ(d,"sockname")) return -KEY_getsockname; | |
5472 | if (strEQ(d,"sockopt")) return -KEY_getsockopt; | |
a687059c LW |
5473 | } |
5474 | else if (*d == 'g') { | |
a0d0e21e LW |
5475 | if (strEQ(d,"grent")) return -KEY_getgrent; |
5476 | if (strEQ(d,"grnam")) return -KEY_getgrnam; | |
5477 | if (strEQ(d,"grgid")) return -KEY_getgrgid; | |
a687059c LW |
5478 | } |
5479 | else if (*d == 'l') { | |
a0d0e21e | 5480 | if (strEQ(d,"login")) return -KEY_getlogin; |
a687059c | 5481 | } |
a0d0e21e | 5482 | else if (strEQ(d,"c")) return -KEY_getc; |
79072805 | 5483 | break; |
a687059c | 5484 | } |
79072805 LW |
5485 | switch (len) { |
5486 | case 2: | |
a0d0e21e LW |
5487 | if (strEQ(d,"gt")) return -KEY_gt; |
5488 | if (strEQ(d,"ge")) return -KEY_ge; | |
79072805 LW |
5489 | break; |
5490 | case 4: | |
5491 | if (strEQ(d,"grep")) return KEY_grep; | |
5492 | if (strEQ(d,"goto")) return KEY_goto; | |
fb73857a | 5493 | if (strEQ(d,"glob")) return KEY_glob; |
79072805 LW |
5494 | break; |
5495 | case 6: | |
a0d0e21e | 5496 | if (strEQ(d,"gmtime")) return -KEY_gmtime; |
79072805 | 5497 | break; |
378cc40b | 5498 | } |
a687059c | 5499 | break; |
79072805 | 5500 | case 'h': |
a0d0e21e | 5501 | if (strEQ(d,"hex")) return -KEY_hex; |
a687059c | 5502 | break; |
7d07dbc2 MB |
5503 | case 'I': |
5504 | if (strEQ(d,"INIT")) return KEY_INIT; | |
5505 | break; | |
79072805 LW |
5506 | case 'i': |
5507 | switch (len) { | |
5508 | case 2: | |
5509 | if (strEQ(d,"if")) return KEY_if; | |
5510 | break; | |
5511 | case 3: | |
a0d0e21e | 5512 | if (strEQ(d,"int")) return -KEY_int; |
79072805 LW |
5513 | break; |
5514 | case 5: | |
a0d0e21e LW |
5515 | if (strEQ(d,"index")) return -KEY_index; |
5516 | if (strEQ(d,"ioctl")) return -KEY_ioctl; | |
79072805 LW |
5517 | break; |
5518 | } | |
a687059c | 5519 | break; |
79072805 | 5520 | case 'j': |
a0d0e21e | 5521 | if (strEQ(d,"join")) return -KEY_join; |
a687059c | 5522 | break; |
79072805 LW |
5523 | case 'k': |
5524 | if (len == 4) { | |
3a6a8333 | 5525 | if (strEQ(d,"keys")) return -KEY_keys; |
a0d0e21e | 5526 | if (strEQ(d,"kill")) return -KEY_kill; |
663a0e37 | 5527 | } |
79072805 | 5528 | break; |
79072805 LW |
5529 | case 'l': |
5530 | switch (len) { | |
5531 | case 2: | |
a0d0e21e LW |
5532 | if (strEQ(d,"lt")) return -KEY_lt; |
5533 | if (strEQ(d,"le")) return -KEY_le; | |
5534 | if (strEQ(d,"lc")) return -KEY_lc; | |
79072805 LW |
5535 | break; |
5536 | case 3: | |
a0d0e21e | 5537 | if (strEQ(d,"log")) return -KEY_log; |
79072805 LW |
5538 | break; |
5539 | case 4: | |
5540 | if (strEQ(d,"last")) return KEY_last; | |
a0d0e21e | 5541 | if (strEQ(d,"link")) return -KEY_link; |
c0329465 | 5542 | if (strEQ(d,"lock")) return -KEY_lock; |
395c3793 | 5543 | break; |
79072805 LW |
5544 | case 5: |
5545 | if (strEQ(d,"local")) return KEY_local; | |
a0d0e21e | 5546 | if (strEQ(d,"lstat")) return -KEY_lstat; |
79072805 LW |
5547 | break; |
5548 | case 6: | |
a0d0e21e LW |
5549 | if (strEQ(d,"length")) return -KEY_length; |
5550 | if (strEQ(d,"listen")) return -KEY_listen; | |
79072805 LW |
5551 | break; |
5552 | case 7: | |
a0d0e21e | 5553 | if (strEQ(d,"lcfirst")) return -KEY_lcfirst; |
79072805 LW |
5554 | break; |
5555 | case 9: | |
a0d0e21e | 5556 | if (strEQ(d,"localtime")) return -KEY_localtime; |
395c3793 LW |
5557 | break; |
5558 | } | |
a687059c | 5559 | break; |
79072805 LW |
5560 | case 'm': |
5561 | switch (len) { | |
5562 | case 1: return KEY_m; | |
93a17b20 LW |
5563 | case 2: |
5564 | if (strEQ(d,"my")) return KEY_my; | |
5565 | break; | |
a0d0e21e LW |
5566 | case 3: |
5567 | if (strEQ(d,"map")) return KEY_map; | |
5568 | break; | |
79072805 | 5569 | case 5: |
a0d0e21e | 5570 | if (strEQ(d,"mkdir")) return -KEY_mkdir; |
79072805 LW |
5571 | break; |
5572 | case 6: | |
a0d0e21e LW |
5573 | if (strEQ(d,"msgctl")) return -KEY_msgctl; |
5574 | if (strEQ(d,"msgget")) return -KEY_msgget; | |
5575 | if (strEQ(d,"msgrcv")) return -KEY_msgrcv; | |
5576 | if (strEQ(d,"msgsnd")) return -KEY_msgsnd; | |
79072805 LW |
5577 | break; |
5578 | } | |
a687059c | 5579 | break; |
79072805 LW |
5580 | case 'n': |
5581 | if (strEQ(d,"next")) return KEY_next; | |
a0d0e21e LW |
5582 | if (strEQ(d,"ne")) return -KEY_ne; |
5583 | if (strEQ(d,"not")) return -KEY_not; | |
5584 | if (strEQ(d,"no")) return KEY_no; | |
a687059c | 5585 | break; |
79072805 LW |
5586 | case 'o': |
5587 | switch (len) { | |
463ee0b2 | 5588 | case 2: |
a0d0e21e | 5589 | if (strEQ(d,"or")) return -KEY_or; |
463ee0b2 | 5590 | break; |
79072805 | 5591 | case 3: |
a0d0e21e LW |
5592 | if (strEQ(d,"ord")) return -KEY_ord; |
5593 | if (strEQ(d,"oct")) return -KEY_oct; | |
77ca0c92 | 5594 | if (strEQ(d,"our")) return KEY_our; |
79072805 LW |
5595 | break; |
5596 | case 4: | |
a0d0e21e | 5597 | if (strEQ(d,"open")) return -KEY_open; |
79072805 LW |
5598 | break; |
5599 | case 7: | |
a0d0e21e | 5600 | if (strEQ(d,"opendir")) return -KEY_opendir; |
79072805 | 5601 | break; |
fe14fcc3 | 5602 | } |
a687059c | 5603 | break; |
79072805 LW |
5604 | case 'p': |
5605 | switch (len) { | |
5606 | case 3: | |
4e553d73 | 5607 | if (strEQ(d,"pop")) return -KEY_pop; |
a0d0e21e | 5608 | if (strEQ(d,"pos")) return KEY_pos; |
79072805 LW |
5609 | break; |
5610 | case 4: | |
3a6a8333 | 5611 | if (strEQ(d,"push")) return -KEY_push; |
a0d0e21e LW |
5612 | if (strEQ(d,"pack")) return -KEY_pack; |
5613 | if (strEQ(d,"pipe")) return -KEY_pipe; | |
79072805 LW |
5614 | break; |
5615 | case 5: | |
5616 | if (strEQ(d,"print")) return KEY_print; | |
5617 | break; | |
5618 | case 6: | |
5619 | if (strEQ(d,"printf")) return KEY_printf; | |
5620 | break; | |
5621 | case 7: | |
5622 | if (strEQ(d,"package")) return KEY_package; | |
5623 | break; | |
c07a80fd | 5624 | case 9: |
5625 | if (strEQ(d,"prototype")) return KEY_prototype; | |
663a0e37 | 5626 | } |
79072805 LW |
5627 | break; |
5628 | case 'q': | |
5629 | if (len <= 2) { | |
5630 | if (strEQ(d,"q")) return KEY_q; | |
8782bef2 | 5631 | if (strEQ(d,"qr")) return KEY_qr; |
79072805 | 5632 | if (strEQ(d,"qq")) return KEY_qq; |
8990e307 | 5633 | if (strEQ(d,"qw")) return KEY_qw; |
79072805 | 5634 | if (strEQ(d,"qx")) return KEY_qx; |
663a0e37 | 5635 | } |
a0d0e21e | 5636 | else if (strEQ(d,"quotemeta")) return -KEY_quotemeta; |
79072805 LW |
5637 | break; |
5638 | case 'r': | |
5639 | switch (len) { | |
5640 | case 3: | |
a0d0e21e | 5641 | if (strEQ(d,"ref")) return -KEY_ref; |
79072805 LW |
5642 | break; |
5643 | case 4: | |
a0d0e21e LW |
5644 | if (strEQ(d,"read")) return -KEY_read; |
5645 | if (strEQ(d,"rand")) return -KEY_rand; | |
5646 | if (strEQ(d,"recv")) return -KEY_recv; | |
79072805 LW |
5647 | if (strEQ(d,"redo")) return KEY_redo; |
5648 | break; | |
5649 | case 5: | |
a0d0e21e LW |
5650 | if (strEQ(d,"rmdir")) return -KEY_rmdir; |
5651 | if (strEQ(d,"reset")) return -KEY_reset; | |
79072805 LW |
5652 | break; |
5653 | case 6: | |
5654 | if (strEQ(d,"return")) return KEY_return; | |
a0d0e21e LW |
5655 | if (strEQ(d,"rename")) return -KEY_rename; |
5656 | if (strEQ(d,"rindex")) return -KEY_rindex; | |
79072805 LW |
5657 | break; |
5658 | case 7: | |
ec4ab249 | 5659 | if (strEQ(d,"require")) return KEY_require; |
a0d0e21e LW |
5660 | if (strEQ(d,"reverse")) return -KEY_reverse; |
5661 | if (strEQ(d,"readdir")) return -KEY_readdir; | |
79072805 LW |
5662 | break; |
5663 | case 8: | |
a0d0e21e LW |
5664 | if (strEQ(d,"readlink")) return -KEY_readlink; |
5665 | if (strEQ(d,"readline")) return -KEY_readline; | |
5666 | if (strEQ(d,"readpipe")) return -KEY_readpipe; | |
79072805 LW |
5667 | break; |
5668 | case 9: | |
a0d0e21e | 5669 | if (strEQ(d,"rewinddir")) return -KEY_rewinddir; |
79072805 | 5670 | break; |
a687059c | 5671 | } |
79072805 LW |
5672 | break; |
5673 | case 's': | |
a687059c | 5674 | switch (d[1]) { |
79072805 | 5675 | case 0: return KEY_s; |
a687059c | 5676 | case 'c': |
79072805 | 5677 | if (strEQ(d,"scalar")) return KEY_scalar; |
a687059c LW |
5678 | break; |
5679 | case 'e': | |
79072805 LW |
5680 | switch (len) { |
5681 | case 4: | |
a0d0e21e LW |
5682 | if (strEQ(d,"seek")) return -KEY_seek; |
5683 | if (strEQ(d,"send")) return -KEY_send; | |
79072805 LW |
5684 | break; |
5685 | case 5: | |
a0d0e21e | 5686 | if (strEQ(d,"semop")) return -KEY_semop; |
79072805 LW |
5687 | break; |
5688 | case 6: | |
a0d0e21e LW |
5689 | if (strEQ(d,"select")) return -KEY_select; |
5690 | if (strEQ(d,"semctl")) return -KEY_semctl; | |
5691 | if (strEQ(d,"semget")) return -KEY_semget; | |
79072805 LW |
5692 | break; |
5693 | case 7: | |
a0d0e21e LW |
5694 | if (strEQ(d,"setpgrp")) return -KEY_setpgrp; |
5695 | if (strEQ(d,"seekdir")) return -KEY_seekdir; | |
79072805 LW |
5696 | break; |
5697 | case 8: | |
a0d0e21e LW |
5698 | if (strEQ(d,"setpwent")) return -KEY_setpwent; |
5699 | if (strEQ(d,"setgrent")) return -KEY_setgrent; | |
79072805 LW |
5700 | break; |
5701 | case 9: | |
a0d0e21e | 5702 | if (strEQ(d,"setnetent")) return -KEY_setnetent; |
79072805 LW |
5703 | break; |
5704 | case 10: | |
a0d0e21e LW |
5705 | if (strEQ(d,"setsockopt")) return -KEY_setsockopt; |
5706 | if (strEQ(d,"sethostent")) return -KEY_sethostent; | |
5707 | if (strEQ(d,"setservent")) return -KEY_setservent; | |
79072805 LW |
5708 | break; |
5709 | case 11: | |
a0d0e21e LW |
5710 | if (strEQ(d,"setpriority")) return -KEY_setpriority; |
5711 | if (strEQ(d,"setprotoent")) return -KEY_setprotoent; | |
79072805 LW |
5712 | break; |
5713 | } | |
a687059c LW |
5714 | break; |
5715 | case 'h': | |
79072805 LW |
5716 | switch (len) { |
5717 | case 5: | |
3a6a8333 | 5718 | if (strEQ(d,"shift")) return -KEY_shift; |
79072805 LW |
5719 | break; |
5720 | case 6: | |
a0d0e21e LW |
5721 | if (strEQ(d,"shmctl")) return -KEY_shmctl; |
5722 | if (strEQ(d,"shmget")) return -KEY_shmget; | |
79072805 LW |
5723 | break; |
5724 | case 7: | |
a0d0e21e | 5725 | if (strEQ(d,"shmread")) return -KEY_shmread; |
79072805 LW |
5726 | break; |
5727 | case 8: | |
a0d0e21e LW |
5728 | if (strEQ(d,"shmwrite")) return -KEY_shmwrite; |
5729 | if (strEQ(d,"shutdown")) return -KEY_shutdown; | |
79072805 LW |
5730 | break; |
5731 | } | |
a687059c LW |
5732 | break; |
5733 | case 'i': | |
a0d0e21e | 5734 | if (strEQ(d,"sin")) return -KEY_sin; |
a687059c LW |
5735 | break; |
5736 | case 'l': | |
a0d0e21e | 5737 | if (strEQ(d,"sleep")) return -KEY_sleep; |
a687059c LW |
5738 | break; |
5739 | case 'o': | |
79072805 | 5740 | if (strEQ(d,"sort")) return KEY_sort; |
a0d0e21e LW |
5741 | if (strEQ(d,"socket")) return -KEY_socket; |
5742 | if (strEQ(d,"socketpair")) return -KEY_socketpair; | |
a687059c LW |
5743 | break; |
5744 | case 'p': | |
79072805 | 5745 | if (strEQ(d,"split")) return KEY_split; |
a0d0e21e | 5746 | if (strEQ(d,"sprintf")) return -KEY_sprintf; |
3a6a8333 | 5747 | if (strEQ(d,"splice")) return -KEY_splice; |
a687059c LW |
5748 | break; |
5749 | case 'q': | |
a0d0e21e | 5750 | if (strEQ(d,"sqrt")) return -KEY_sqrt; |
a687059c LW |
5751 | break; |
5752 | case 'r': | |
a0d0e21e | 5753 | if (strEQ(d,"srand")) return -KEY_srand; |
a687059c LW |
5754 | break; |
5755 | case 't': | |
a0d0e21e | 5756 | if (strEQ(d,"stat")) return -KEY_stat; |
79072805 | 5757 | if (strEQ(d,"study")) return KEY_study; |
a687059c LW |
5758 | break; |
5759 | case 'u': | |
a0d0e21e | 5760 | if (strEQ(d,"substr")) return -KEY_substr; |
79072805 | 5761 | if (strEQ(d,"sub")) return KEY_sub; |
a687059c LW |
5762 | break; |
5763 | case 'y': | |
79072805 LW |
5764 | switch (len) { |
5765 | case 6: | |
a0d0e21e | 5766 | if (strEQ(d,"system")) return -KEY_system; |
79072805 LW |
5767 | break; |
5768 | case 7: | |
a0d0e21e LW |
5769 | if (strEQ(d,"symlink")) return -KEY_symlink; |
5770 | if (strEQ(d,"syscall")) return -KEY_syscall; | |
137443ea | 5771 | if (strEQ(d,"sysopen")) return -KEY_sysopen; |
5772 | if (strEQ(d,"sysread")) return -KEY_sysread; | |
5773 | if (strEQ(d,"sysseek")) return -KEY_sysseek; | |
79072805 LW |
5774 | break; |
5775 | case 8: | |
a0d0e21e | 5776 | if (strEQ(d,"syswrite")) return -KEY_syswrite; |
79072805 | 5777 | break; |
a687059c | 5778 | } |
a687059c LW |
5779 | break; |
5780 | } | |
5781 | break; | |
79072805 LW |
5782 | case 't': |
5783 | switch (len) { | |
5784 | case 2: | |
5785 | if (strEQ(d,"tr")) return KEY_tr; | |
5786 | break; | |
463ee0b2 LW |
5787 | case 3: |
5788 | if (strEQ(d,"tie")) return KEY_tie; | |
5789 | break; | |
79072805 | 5790 | case 4: |
a0d0e21e | 5791 | if (strEQ(d,"tell")) return -KEY_tell; |
c07a80fd | 5792 | if (strEQ(d,"tied")) return KEY_tied; |
a0d0e21e | 5793 | if (strEQ(d,"time")) return -KEY_time; |
79072805 LW |
5794 | break; |
5795 | case 5: | |
a0d0e21e | 5796 | if (strEQ(d,"times")) return -KEY_times; |
79072805 LW |
5797 | break; |
5798 | case 7: | |
a0d0e21e | 5799 | if (strEQ(d,"telldir")) return -KEY_telldir; |
79072805 LW |
5800 | break; |
5801 | case 8: | |
a0d0e21e | 5802 | if (strEQ(d,"truncate")) return -KEY_truncate; |
79072805 | 5803 | break; |
378cc40b | 5804 | } |
a687059c | 5805 | break; |
79072805 LW |
5806 | case 'u': |
5807 | switch (len) { | |
5808 | case 2: | |
a0d0e21e LW |
5809 | if (strEQ(d,"uc")) return -KEY_uc; |
5810 | break; | |
5811 | case 3: | |
5812 | if (strEQ(d,"use")) return KEY_use; | |
79072805 LW |
5813 | break; |
5814 | case 5: | |
5815 | if (strEQ(d,"undef")) return KEY_undef; | |
5816 | if (strEQ(d,"until")) return KEY_until; | |
463ee0b2 | 5817 | if (strEQ(d,"untie")) return KEY_untie; |
a0d0e21e LW |
5818 | if (strEQ(d,"utime")) return -KEY_utime; |
5819 | if (strEQ(d,"umask")) return -KEY_umask; | |
79072805 LW |
5820 | break; |
5821 | case 6: | |
5822 | if (strEQ(d,"unless")) return KEY_unless; | |
a0d0e21e LW |
5823 | if (strEQ(d,"unpack")) return -KEY_unpack; |
5824 | if (strEQ(d,"unlink")) return -KEY_unlink; | |
79072805 LW |
5825 | break; |
5826 | case 7: | |
3a6a8333 | 5827 | if (strEQ(d,"unshift")) return -KEY_unshift; |
a0d0e21e | 5828 | if (strEQ(d,"ucfirst")) return -KEY_ucfirst; |
79072805 | 5829 | break; |
a687059c LW |
5830 | } |
5831 | break; | |
79072805 | 5832 | case 'v': |
a0d0e21e LW |
5833 | if (strEQ(d,"values")) return -KEY_values; |
5834 | if (strEQ(d,"vec")) return -KEY_vec; | |
a687059c | 5835 | break; |
79072805 LW |
5836 | case 'w': |
5837 | switch (len) { | |
5838 | case 4: | |
a0d0e21e LW |
5839 | if (strEQ(d,"warn")) return -KEY_warn; |
5840 | if (strEQ(d,"wait")) return -KEY_wait; | |
79072805 LW |
5841 | break; |
5842 | case 5: | |
5843 | if (strEQ(d,"while")) return KEY_while; | |
a0d0e21e | 5844 | if (strEQ(d,"write")) return -KEY_write; |
79072805 LW |
5845 | break; |
5846 | case 7: | |
a0d0e21e | 5847 | if (strEQ(d,"waitpid")) return -KEY_waitpid; |
79072805 LW |
5848 | break; |
5849 | case 9: | |
a0d0e21e | 5850 | if (strEQ(d,"wantarray")) return -KEY_wantarray; |
79072805 | 5851 | break; |
2f3197b3 | 5852 | } |
a687059c | 5853 | break; |
79072805 | 5854 | case 'x': |
a0d0e21e LW |
5855 | if (len == 1) return -KEY_x; |
5856 | if (strEQ(d,"xor")) return -KEY_xor; | |
a687059c | 5857 | break; |
79072805 LW |
5858 | case 'y': |
5859 | if (len == 1) return KEY_y; | |
5860 | break; | |
5861 | case 'z': | |
a687059c LW |
5862 | break; |
5863 | } | |
79072805 | 5864 | return 0; |
a687059c LW |
5865 | } |
5866 | ||
76e3520e | 5867 | STATIC void |
cea2e8a9 | 5868 | S_checkcomma(pTHX_ register char *s, char *name, char *what) |
a687059c | 5869 | { |
2f3197b3 LW |
5870 | char *w; |
5871 | ||
d008e5eb | 5872 | if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */ |
d008e5eb GS |
5873 | if (ckWARN(WARN_SYNTAX)) { |
5874 | int level = 1; | |
5875 | for (w = s+2; *w && level; w++) { | |
5876 | if (*w == '(') | |
5877 | ++level; | |
5878 | else if (*w == ')') | |
5879 | --level; | |
5880 | } | |
5881 | if (*w) | |
5882 | for (; *w && isSPACE(*w); w++) ; | |
5883 | if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */ | |
65cec589 GS |
5884 | Perl_warner(aTHX_ WARN_SYNTAX, |
5885 | "%s (...) interpreted as function",name); | |
d008e5eb | 5886 | } |
2f3197b3 | 5887 | } |
3280af22 | 5888 | while (s < PL_bufend && isSPACE(*s)) |
2f3197b3 | 5889 | s++; |
a687059c LW |
5890 | if (*s == '(') |
5891 | s++; | |
3280af22 | 5892 | while (s < PL_bufend && isSPACE(*s)) |
a687059c | 5893 | s++; |
7e2040f0 | 5894 | if (isIDFIRST_lazy_if(s,UTF)) { |
2f3197b3 | 5895 | w = s++; |
7e2040f0 | 5896 | while (isALNUM_lazy_if(s,UTF)) |
a687059c | 5897 | s++; |
3280af22 | 5898 | while (s < PL_bufend && isSPACE(*s)) |
a687059c | 5899 | s++; |
e929a76b | 5900 | if (*s == ',') { |
463ee0b2 | 5901 | int kw; |
e929a76b | 5902 | *s = '\0'; |
864dbfa3 | 5903 | kw = keyword(w, s - w) || get_cv(w, FALSE) != 0; |
e929a76b | 5904 | *s = ','; |
463ee0b2 | 5905 | if (kw) |
e929a76b | 5906 | return; |
cea2e8a9 | 5907 | Perl_croak(aTHX_ "No comma allowed after %s", what); |
463ee0b2 LW |
5908 | } |
5909 | } | |
5910 | } | |
5911 | ||
423cee85 JH |
5912 | /* Either returns sv, or mortalizes sv and returns a new SV*. |
5913 | Best used as sv=new_constant(..., sv, ...). | |
5914 | If s, pv are NULL, calls subroutine with one argument, | |
5915 | and type is used with error messages only. */ | |
5916 | ||
b3ac6de7 | 5917 | STATIC SV * |
dff6d3cd | 5918 | S_new_constant(pTHX_ char *s, STRLEN len, const char *key, SV *sv, SV *pv, |
9b0e499b | 5919 | const char *type) |
b3ac6de7 | 5920 | { |
b3ac6de7 | 5921 | dSP; |
3280af22 | 5922 | HV *table = GvHV(PL_hintgv); /* ^H */ |
b3ac6de7 | 5923 | SV *res; |
b3ac6de7 IZ |
5924 | SV **cvp; |
5925 | SV *cv, *typesv; | |
f0af216f | 5926 | const char *why1, *why2, *why3; |
4e553d73 | 5927 | |
f0af216f | 5928 | if (!table || !(PL_hints & HINT_LOCALIZE_HH)) { |
423cee85 JH |
5929 | SV *msg; |
5930 | ||
f0af216f | 5931 | why2 = strEQ(key,"charnames") |
41ab332f | 5932 | ? "(possibly a missing \"use charnames ...\")" |
f0af216f | 5933 | : ""; |
4e553d73 | 5934 | msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s", |
41ab332f JH |
5935 | (type ? type: "undef"), why2); |
5936 | ||
5937 | /* This is convoluted and evil ("goto considered harmful") | |
5938 | * but I do not understand the intricacies of all the different | |
5939 | * failure modes of %^H in here. The goal here is to make | |
5940 | * the most probable error message user-friendly. --jhi */ | |
5941 | ||
5942 | goto msgdone; | |
5943 | ||
423cee85 | 5944 | report: |
4e553d73 | 5945 | msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s", |
f0af216f | 5946 | (type ? type: "undef"), why1, why2, why3); |
41ab332f | 5947 | msgdone: |
423cee85 JH |
5948 | yyerror(SvPVX(msg)); |
5949 | SvREFCNT_dec(msg); | |
5950 | return sv; | |
5951 | } | |
b3ac6de7 IZ |
5952 | cvp = hv_fetch(table, key, strlen(key), FALSE); |
5953 | if (!cvp || !SvOK(*cvp)) { | |
423cee85 JH |
5954 | why1 = "$^H{"; |
5955 | why2 = key; | |
f0af216f | 5956 | why3 = "} is not defined"; |
423cee85 | 5957 | goto report; |
b3ac6de7 IZ |
5958 | } |
5959 | sv_2mortal(sv); /* Parent created it permanently */ | |
5960 | cv = *cvp; | |
423cee85 JH |
5961 | if (!pv && s) |
5962 | pv = sv_2mortal(newSVpvn(s, len)); | |
5963 | if (type && pv) | |
5964 | typesv = sv_2mortal(newSVpv(type, 0)); | |
b3ac6de7 | 5965 | else |
423cee85 | 5966 | typesv = &PL_sv_undef; |
4e553d73 | 5967 | |
e788e7d3 | 5968 | PUSHSTACKi(PERLSI_OVERLOAD); |
423cee85 JH |
5969 | ENTER ; |
5970 | SAVETMPS; | |
4e553d73 | 5971 | |
423cee85 | 5972 | PUSHMARK(SP) ; |
a5845cb7 | 5973 | EXTEND(sp, 3); |
423cee85 JH |
5974 | if (pv) |
5975 | PUSHs(pv); | |
b3ac6de7 | 5976 | PUSHs(sv); |
423cee85 JH |
5977 | if (pv) |
5978 | PUSHs(typesv); | |
b3ac6de7 | 5979 | PUTBACK; |
423cee85 | 5980 | call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL)); |
4e553d73 | 5981 | |
423cee85 | 5982 | SPAGAIN ; |
4e553d73 | 5983 | |
423cee85 | 5984 | /* Check the eval first */ |
9b0e499b | 5985 | if (!PL_in_eval && SvTRUE(ERRSV)) { |
423cee85 JH |
5986 | STRLEN n_a; |
5987 | sv_catpv(ERRSV, "Propagated"); | |
5988 | yyerror(SvPV(ERRSV, n_a)); /* Duplicates the message inside eval */ | |
e1f15930 | 5989 | (void)POPs; |
423cee85 JH |
5990 | res = SvREFCNT_inc(sv); |
5991 | } | |
5992 | else { | |
5993 | res = POPs; | |
e1f15930 | 5994 | (void)SvREFCNT_inc(res); |
423cee85 | 5995 | } |
4e553d73 | 5996 | |
423cee85 JH |
5997 | PUTBACK ; |
5998 | FREETMPS ; | |
5999 | LEAVE ; | |
b3ac6de7 | 6000 | POPSTACK; |
4e553d73 | 6001 | |
b3ac6de7 | 6002 | if (!SvOK(res)) { |
423cee85 JH |
6003 | why1 = "Call to &{$^H{"; |
6004 | why2 = key; | |
f0af216f | 6005 | why3 = "}} did not return a defined value"; |
423cee85 JH |
6006 | sv = res; |
6007 | goto report; | |
9b0e499b | 6008 | } |
423cee85 | 6009 | |
9b0e499b | 6010 | return res; |
b3ac6de7 | 6011 | } |
4e553d73 | 6012 | |
76e3520e | 6013 | STATIC char * |
cea2e8a9 | 6014 | S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp) |
463ee0b2 LW |
6015 | { |
6016 | register char *d = dest; | |
8903cb82 | 6017 | register char *e = d + destlen - 3; /* two-character token, ending NUL */ |
463ee0b2 | 6018 | for (;;) { |
8903cb82 | 6019 | if (d >= e) |
cea2e8a9 | 6020 | Perl_croak(aTHX_ ident_too_long); |
834a4ddd | 6021 | if (isALNUM(*s)) /* UTF handled below */ |
463ee0b2 | 6022 | *d++ = *s++; |
7e2040f0 | 6023 | else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) { |
463ee0b2 LW |
6024 | *d++ = ':'; |
6025 | *d++ = ':'; | |
6026 | s++; | |
6027 | } | |
c3e0f903 | 6028 | else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') { |
463ee0b2 LW |
6029 | *d++ = *s++; |
6030 | *d++ = *s++; | |
6031 | } | |
fd400ab9 | 6032 | else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
a0ed51b3 | 6033 | char *t = s + UTF8SKIP(s); |
fd400ab9 | 6034 | while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
a0ed51b3 LW |
6035 | t += UTF8SKIP(t); |
6036 | if (d + (t - s) > e) | |
cea2e8a9 | 6037 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 LW |
6038 | Copy(s, d, t - s, char); |
6039 | d += t - s; | |
6040 | s = t; | |
6041 | } | |
463ee0b2 LW |
6042 | else { |
6043 | *d = '\0'; | |
6044 | *slp = d - dest; | |
6045 | return s; | |
e929a76b | 6046 | } |
378cc40b LW |
6047 | } |
6048 | } | |
6049 | ||
76e3520e | 6050 | STATIC char * |
cea2e8a9 | 6051 | S_scan_ident(pTHX_ register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni) |
378cc40b LW |
6052 | { |
6053 | register char *d; | |
8903cb82 | 6054 | register char *e; |
79072805 | 6055 | char *bracket = 0; |
748a9306 | 6056 | char funny = *s++; |
378cc40b | 6057 | |
a0d0e21e LW |
6058 | if (isSPACE(*s)) |
6059 | s = skipspace(s); | |
378cc40b | 6060 | d = dest; |
8903cb82 | 6061 | e = d + destlen - 3; /* two-character token, ending NUL */ |
de3bb511 | 6062 | if (isDIGIT(*s)) { |
8903cb82 | 6063 | while (isDIGIT(*s)) { |
6064 | if (d >= e) | |
cea2e8a9 | 6065 | Perl_croak(aTHX_ ident_too_long); |
378cc40b | 6066 | *d++ = *s++; |
8903cb82 | 6067 | } |
378cc40b LW |
6068 | } |
6069 | else { | |
463ee0b2 | 6070 | for (;;) { |
8903cb82 | 6071 | if (d >= e) |
cea2e8a9 | 6072 | Perl_croak(aTHX_ ident_too_long); |
834a4ddd | 6073 | if (isALNUM(*s)) /* UTF handled below */ |
463ee0b2 | 6074 | *d++ = *s++; |
7e2040f0 | 6075 | else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) { |
463ee0b2 LW |
6076 | *d++ = ':'; |
6077 | *d++ = ':'; | |
6078 | s++; | |
6079 | } | |
a0d0e21e | 6080 | else if (*s == ':' && s[1] == ':') { |
463ee0b2 LW |
6081 | *d++ = *s++; |
6082 | *d++ = *s++; | |
6083 | } | |
fd400ab9 | 6084 | else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
a0ed51b3 | 6085 | char *t = s + UTF8SKIP(s); |
fd400ab9 | 6086 | while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
a0ed51b3 LW |
6087 | t += UTF8SKIP(t); |
6088 | if (d + (t - s) > e) | |
cea2e8a9 | 6089 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 LW |
6090 | Copy(s, d, t - s, char); |
6091 | d += t - s; | |
6092 | s = t; | |
6093 | } | |
463ee0b2 LW |
6094 | else |
6095 | break; | |
6096 | } | |
378cc40b LW |
6097 | } |
6098 | *d = '\0'; | |
6099 | d = dest; | |
79072805 | 6100 | if (*d) { |
3280af22 NIS |
6101 | if (PL_lex_state != LEX_NORMAL) |
6102 | PL_lex_state = LEX_INTERPENDMAYBE; | |
79072805 | 6103 | return s; |
378cc40b | 6104 | } |
748a9306 | 6105 | if (*s == '$' && s[1] && |
7e2040f0 | 6106 | (isALNUM_lazy_if(s+1,UTF) || strchr("${", s[1]) || strnEQ(s+1,"::",2)) ) |
5cd24f17 | 6107 | { |
4810e5ec | 6108 | return s; |
5cd24f17 | 6109 | } |
79072805 LW |
6110 | if (*s == '{') { |
6111 | bracket = s; | |
6112 | s++; | |
6113 | } | |
6114 | else if (ck_uni) | |
6115 | check_uni(); | |
93a17b20 | 6116 | if (s < send) |
79072805 LW |
6117 | *d = *s++; |
6118 | d[1] = '\0'; | |
2b92dfce | 6119 | if (*d == '^' && *s && isCONTROLVAR(*s)) { |
bbce6d69 | 6120 | *d = toCTRL(*s); |
6121 | s++; | |
de3bb511 | 6122 | } |
79072805 | 6123 | if (bracket) { |
748a9306 | 6124 | if (isSPACE(s[-1])) { |
fa83b5b6 | 6125 | while (s < send) { |
6126 | char ch = *s++; | |
bf4acbe4 | 6127 | if (!SPACE_OR_TAB(ch)) { |
fa83b5b6 | 6128 | *d = ch; |
6129 | break; | |
6130 | } | |
6131 | } | |
748a9306 | 6132 | } |
7e2040f0 | 6133 | if (isIDFIRST_lazy_if(d,UTF)) { |
79072805 | 6134 | d++; |
a0ed51b3 LW |
6135 | if (UTF) { |
6136 | e = s; | |
155aba94 | 6137 | while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') { |
a0ed51b3 | 6138 | e += UTF8SKIP(e); |
fd400ab9 | 6139 | while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e)) |
a0ed51b3 LW |
6140 | e += UTF8SKIP(e); |
6141 | } | |
6142 | Copy(s, d, e - s, char); | |
6143 | d += e - s; | |
6144 | s = e; | |
6145 | } | |
6146 | else { | |
2b92dfce | 6147 | while ((isALNUM(*s) || *s == ':') && d < e) |
a0ed51b3 | 6148 | *d++ = *s++; |
2b92dfce | 6149 | if (d >= e) |
cea2e8a9 | 6150 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 | 6151 | } |
79072805 | 6152 | *d = '\0'; |
bf4acbe4 | 6153 | while (s < send && SPACE_OR_TAB(*s)) s++; |
ff68c719 | 6154 | if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) { |
599cee73 | 6155 | if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) { |
dff6d3cd | 6156 | const char *brack = *s == '[' ? "[...]" : "{...}"; |
cea2e8a9 | 6157 | Perl_warner(aTHX_ WARN_AMBIGUOUS, |
599cee73 | 6158 | "Ambiguous use of %c{%s%s} resolved to %c%s%s", |
748a9306 LW |
6159 | funny, dest, brack, funny, dest, brack); |
6160 | } | |
79072805 | 6161 | bracket++; |
a0be28da | 6162 | PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK); |
79072805 LW |
6163 | return s; |
6164 | } | |
4e553d73 NIS |
6165 | } |
6166 | /* Handle extended ${^Foo} variables | |
2b92dfce GS |
6167 | * 1999-02-27 mjd-perl-patch@plover.com */ |
6168 | else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */ | |
6169 | && isALNUM(*s)) | |
6170 | { | |
6171 | d++; | |
6172 | while (isALNUM(*s) && d < e) { | |
6173 | *d++ = *s++; | |
6174 | } | |
6175 | if (d >= e) | |
cea2e8a9 | 6176 | Perl_croak(aTHX_ ident_too_long); |
2b92dfce | 6177 | *d = '\0'; |
79072805 LW |
6178 | } |
6179 | if (*s == '}') { | |
6180 | s++; | |
3280af22 NIS |
6181 | if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) |
6182 | PL_lex_state = LEX_INTERPEND; | |
748a9306 LW |
6183 | if (funny == '#') |
6184 | funny = '@'; | |
d008e5eb | 6185 | if (PL_lex_state == LEX_NORMAL) { |
d008e5eb | 6186 | if (ckWARN(WARN_AMBIGUOUS) && |
864dbfa3 | 6187 | (keyword(dest, d - dest) || get_cv(dest, FALSE))) |
d008e5eb | 6188 | { |
cea2e8a9 | 6189 | Perl_warner(aTHX_ WARN_AMBIGUOUS, |
d008e5eb GS |
6190 | "Ambiguous use of %c{%s} resolved to %c%s", |
6191 | funny, dest, funny, dest); | |
6192 | } | |
6193 | } | |
79072805 LW |
6194 | } |
6195 | else { | |
6196 | s = bracket; /* let the parser handle it */ | |
93a17b20 | 6197 | *dest = '\0'; |
79072805 LW |
6198 | } |
6199 | } | |
3280af22 NIS |
6200 | else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s)) |
6201 | PL_lex_state = LEX_INTERPEND; | |
378cc40b LW |
6202 | return s; |
6203 | } | |
6204 | ||
cea2e8a9 GS |
6205 | void |
6206 | Perl_pmflag(pTHX_ U16 *pmfl, int ch) | |
a0d0e21e | 6207 | { |
bbce6d69 | 6208 | if (ch == 'i') |
a0d0e21e | 6209 | *pmfl |= PMf_FOLD; |
a0d0e21e LW |
6210 | else if (ch == 'g') |
6211 | *pmfl |= PMf_GLOBAL; | |
c90c0ff4 | 6212 | else if (ch == 'c') |
6213 | *pmfl |= PMf_CONTINUE; | |
a0d0e21e LW |
6214 | else if (ch == 'o') |
6215 | *pmfl |= PMf_KEEP; | |
6216 | else if (ch == 'm') | |
6217 | *pmfl |= PMf_MULTILINE; | |
6218 | else if (ch == 's') | |
6219 | *pmfl |= PMf_SINGLELINE; | |
6220 | else if (ch == 'x') | |
6221 | *pmfl |= PMf_EXTENDED; | |
6222 | } | |
378cc40b | 6223 | |
76e3520e | 6224 | STATIC char * |
cea2e8a9 | 6225 | S_scan_pat(pTHX_ char *start, I32 type) |
378cc40b | 6226 | { |
79072805 LW |
6227 | PMOP *pm; |
6228 | char *s; | |
378cc40b | 6229 | |
09bef843 | 6230 | s = scan_str(start,FALSE,FALSE); |
37fd879b | 6231 | if (!s) |
cea2e8a9 | 6232 | Perl_croak(aTHX_ "Search pattern not terminated"); |
bbce6d69 | 6233 | |
8782bef2 | 6234 | pm = (PMOP*)newPMOP(type, 0); |
3280af22 | 6235 | if (PL_multi_open == '?') |
79072805 | 6236 | pm->op_pmflags |= PMf_ONCE; |
8782bef2 GB |
6237 | if(type == OP_QR) { |
6238 | while (*s && strchr("iomsx", *s)) | |
6239 | pmflag(&pm->op_pmflags,*s++); | |
6240 | } | |
6241 | else { | |
6242 | while (*s && strchr("iogcmsx", *s)) | |
6243 | pmflag(&pm->op_pmflags,*s++); | |
6244 | } | |
4633a7c4 | 6245 | pm->op_pmpermflags = pm->op_pmflags; |
bbce6d69 | 6246 | |
3280af22 | 6247 | PL_lex_op = (OP*)pm; |
79072805 | 6248 | yylval.ival = OP_MATCH; |
378cc40b LW |
6249 | return s; |
6250 | } | |
6251 | ||
76e3520e | 6252 | STATIC char * |
cea2e8a9 | 6253 | S_scan_subst(pTHX_ char *start) |
79072805 | 6254 | { |
a0d0e21e | 6255 | register char *s; |
79072805 | 6256 | register PMOP *pm; |
4fdae800 | 6257 | I32 first_start; |
79072805 LW |
6258 | I32 es = 0; |
6259 | ||
79072805 LW |
6260 | yylval.ival = OP_NULL; |
6261 | ||
09bef843 | 6262 | s = scan_str(start,FALSE,FALSE); |
79072805 | 6263 | |
37fd879b | 6264 | if (!s) |
cea2e8a9 | 6265 | Perl_croak(aTHX_ "Substitution pattern not terminated"); |
79072805 | 6266 | |
3280af22 | 6267 | if (s[-1] == PL_multi_open) |
79072805 LW |
6268 | s--; |
6269 | ||
3280af22 | 6270 | first_start = PL_multi_start; |
09bef843 | 6271 | s = scan_str(s,FALSE,FALSE); |
79072805 | 6272 | if (!s) { |
37fd879b | 6273 | if (PL_lex_stuff) { |
3280af22 | 6274 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
6275 | PL_lex_stuff = Nullsv; |
6276 | } | |
cea2e8a9 | 6277 | Perl_croak(aTHX_ "Substitution replacement not terminated"); |
a687059c | 6278 | } |
3280af22 | 6279 | PL_multi_start = first_start; /* so whole substitution is taken together */ |
2f3197b3 | 6280 | |
79072805 | 6281 | pm = (PMOP*)newPMOP(OP_SUBST, 0); |
48c036b1 | 6282 | while (*s) { |
a687059c LW |
6283 | if (*s == 'e') { |
6284 | s++; | |
2f3197b3 | 6285 | es++; |
a687059c | 6286 | } |
b3eb6a9b | 6287 | else if (strchr("iogcmsx", *s)) |
a0d0e21e | 6288 | pmflag(&pm->op_pmflags,*s++); |
48c036b1 GS |
6289 | else |
6290 | break; | |
378cc40b | 6291 | } |
79072805 LW |
6292 | |
6293 | if (es) { | |
6294 | SV *repl; | |
0244c3a4 GS |
6295 | PL_sublex_info.super_bufptr = s; |
6296 | PL_sublex_info.super_bufend = PL_bufend; | |
6297 | PL_multi_end = 0; | |
79072805 | 6298 | pm->op_pmflags |= PMf_EVAL; |
79cb57f6 | 6299 | repl = newSVpvn("",0); |
463ee0b2 | 6300 | while (es-- > 0) |
a0d0e21e | 6301 | sv_catpv(repl, es ? "eval " : "do "); |
79072805 | 6302 | sv_catpvn(repl, "{ ", 2); |
3280af22 | 6303 | sv_catsv(repl, PL_lex_repl); |
79072805 | 6304 | sv_catpvn(repl, " };", 2); |
25da4f38 | 6305 | SvEVALED_on(repl); |
3280af22 NIS |
6306 | SvREFCNT_dec(PL_lex_repl); |
6307 | PL_lex_repl = repl; | |
378cc40b | 6308 | } |
79072805 | 6309 | |
4633a7c4 | 6310 | pm->op_pmpermflags = pm->op_pmflags; |
3280af22 | 6311 | PL_lex_op = (OP*)pm; |
79072805 | 6312 | yylval.ival = OP_SUBST; |
378cc40b LW |
6313 | return s; |
6314 | } | |
6315 | ||
76e3520e | 6316 | STATIC char * |
cea2e8a9 | 6317 | S_scan_trans(pTHX_ char *start) |
378cc40b | 6318 | { |
a0d0e21e | 6319 | register char* s; |
11343788 | 6320 | OP *o; |
79072805 LW |
6321 | short *tbl; |
6322 | I32 squash; | |
a0ed51b3 | 6323 | I32 del; |
79072805 LW |
6324 | I32 complement; |
6325 | ||
6326 | yylval.ival = OP_NULL; | |
6327 | ||
09bef843 | 6328 | s = scan_str(start,FALSE,FALSE); |
37fd879b | 6329 | if (!s) |
cea2e8a9 | 6330 | Perl_croak(aTHX_ "Transliteration pattern not terminated"); |
3280af22 | 6331 | if (s[-1] == PL_multi_open) |
2f3197b3 LW |
6332 | s--; |
6333 | ||
09bef843 | 6334 | s = scan_str(s,FALSE,FALSE); |
79072805 | 6335 | if (!s) { |
37fd879b | 6336 | if (PL_lex_stuff) { |
3280af22 | 6337 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
6338 | PL_lex_stuff = Nullsv; |
6339 | } | |
cea2e8a9 | 6340 | Perl_croak(aTHX_ "Transliteration replacement not terminated"); |
a687059c | 6341 | } |
79072805 | 6342 | |
a0ed51b3 | 6343 | complement = del = squash = 0; |
6940069f | 6344 | while (strchr("cds", *s)) { |
395c3793 | 6345 | if (*s == 'c') |
79072805 | 6346 | complement = OPpTRANS_COMPLEMENT; |
395c3793 | 6347 | else if (*s == 'd') |
a0ed51b3 LW |
6348 | del = OPpTRANS_DELETE; |
6349 | else if (*s == 's') | |
79072805 | 6350 | squash = OPpTRANS_SQUASH; |
395c3793 LW |
6351 | s++; |
6352 | } | |
8973db79 JH |
6353 | |
6354 | New(803, tbl, complement&&!del?258:256, short); | |
6355 | o = newPVOP(OP_TRANS, 0, (char*)tbl); | |
7948272d NIS |
6356 | o->op_private = del|squash|complement| |
6357 | (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)| | |
6358 | (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0); | |
79072805 | 6359 | |
3280af22 | 6360 | PL_lex_op = o; |
79072805 LW |
6361 | yylval.ival = OP_TRANS; |
6362 | return s; | |
6363 | } | |
6364 | ||
76e3520e | 6365 | STATIC char * |
cea2e8a9 | 6366 | S_scan_heredoc(pTHX_ register char *s) |
79072805 LW |
6367 | { |
6368 | SV *herewas; | |
6369 | I32 op_type = OP_SCALAR; | |
6370 | I32 len; | |
6371 | SV *tmpstr; | |
6372 | char term; | |
6373 | register char *d; | |
fc36a67e | 6374 | register char *e; |
4633a7c4 | 6375 | char *peek; |
3280af22 | 6376 | int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR)); |
79072805 LW |
6377 | |
6378 | s += 2; | |
3280af22 NIS |
6379 | d = PL_tokenbuf; |
6380 | e = PL_tokenbuf + sizeof PL_tokenbuf - 1; | |
fd2d0953 | 6381 | if (!outer) |
79072805 | 6382 | *d++ = '\n'; |
bf4acbe4 | 6383 | for (peek = s; SPACE_OR_TAB(*peek); peek++) ; |
4633a7c4 LW |
6384 | if (*peek && strchr("`'\"",*peek)) { |
6385 | s = peek; | |
79072805 | 6386 | term = *s++; |
3280af22 | 6387 | s = delimcpy(d, e, s, PL_bufend, term, &len); |
fc36a67e | 6388 | d += len; |
3280af22 | 6389 | if (s < PL_bufend) |
79072805 | 6390 | s++; |
79072805 LW |
6391 | } |
6392 | else { | |
6393 | if (*s == '\\') | |
6394 | s++, term = '\''; | |
6395 | else | |
6396 | term = '"'; | |
7e2040f0 | 6397 | if (!isALNUM_lazy_if(s,UTF)) |
4633a7c4 | 6398 | deprecate("bare << to mean <<\"\""); |
7e2040f0 | 6399 | for (; isALNUM_lazy_if(s,UTF); s++) { |
fc36a67e | 6400 | if (d < e) |
6401 | *d++ = *s; | |
6402 | } | |
6403 | } | |
3280af22 | 6404 | if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1) |
cea2e8a9 | 6405 | Perl_croak(aTHX_ "Delimiter for here document is too long"); |
79072805 LW |
6406 | *d++ = '\n'; |
6407 | *d = '\0'; | |
3280af22 | 6408 | len = d - PL_tokenbuf; |
6a27c188 | 6409 | #ifndef PERL_STRICT_CR |
f63a84b2 LW |
6410 | d = strchr(s, '\r'); |
6411 | if (d) { | |
6412 | char *olds = s; | |
6413 | s = d; | |
3280af22 | 6414 | while (s < PL_bufend) { |
f63a84b2 LW |
6415 | if (*s == '\r') { |
6416 | *d++ = '\n'; | |
6417 | if (*++s == '\n') | |
6418 | s++; | |
6419 | } | |
6420 | else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */ | |
6421 | *d++ = *s++; | |
6422 | s++; | |
6423 | } | |
6424 | else | |
6425 | *d++ = *s++; | |
6426 | } | |
6427 | *d = '\0'; | |
3280af22 NIS |
6428 | PL_bufend = d; |
6429 | SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr)); | |
f63a84b2 LW |
6430 | s = olds; |
6431 | } | |
6432 | #endif | |
79072805 | 6433 | d = "\n"; |
3280af22 | 6434 | if (outer || !(d=ninstr(s,PL_bufend,d,d+1))) |
79cb57f6 | 6435 | herewas = newSVpvn(s,PL_bufend-s); |
79072805 | 6436 | else |
79cb57f6 | 6437 | s--, herewas = newSVpvn(s,d-s); |
79072805 | 6438 | s += SvCUR(herewas); |
748a9306 | 6439 | |
8d6dde3e | 6440 | tmpstr = NEWSV(87,79); |
748a9306 LW |
6441 | sv_upgrade(tmpstr, SVt_PVIV); |
6442 | if (term == '\'') { | |
79072805 | 6443 | op_type = OP_CONST; |
748a9306 LW |
6444 | SvIVX(tmpstr) = -1; |
6445 | } | |
6446 | else if (term == '`') { | |
79072805 | 6447 | op_type = OP_BACKTICK; |
748a9306 LW |
6448 | SvIVX(tmpstr) = '\\'; |
6449 | } | |
79072805 LW |
6450 | |
6451 | CLINE; | |
57843af0 | 6452 | PL_multi_start = CopLINE(PL_curcop); |
3280af22 NIS |
6453 | PL_multi_open = PL_multi_close = '<'; |
6454 | term = *PL_tokenbuf; | |
0244c3a4 GS |
6455 | if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) { |
6456 | char *bufptr = PL_sublex_info.super_bufptr; | |
6457 | char *bufend = PL_sublex_info.super_bufend; | |
6458 | char *olds = s - SvCUR(herewas); | |
6459 | s = strchr(bufptr, '\n'); | |
6460 | if (!s) | |
6461 | s = bufend; | |
6462 | d = s; | |
6463 | while (s < bufend && | |
6464 | (*s != term || memNE(s,PL_tokenbuf,len)) ) { | |
6465 | if (*s++ == '\n') | |
57843af0 | 6466 | CopLINE_inc(PL_curcop); |
0244c3a4 GS |
6467 | } |
6468 | if (s >= bufend) { | |
57843af0 | 6469 | CopLINE_set(PL_curcop, PL_multi_start); |
0244c3a4 GS |
6470 | missingterm(PL_tokenbuf); |
6471 | } | |
6472 | sv_setpvn(herewas,bufptr,d-bufptr+1); | |
6473 | sv_setpvn(tmpstr,d+1,s-d); | |
6474 | s += len - 1; | |
6475 | sv_catpvn(herewas,s,bufend-s); | |
6476 | (void)strcpy(bufptr,SvPVX(herewas)); | |
6477 | ||
6478 | s = olds; | |
6479 | goto retval; | |
6480 | } | |
6481 | else if (!outer) { | |
79072805 | 6482 | d = s; |
3280af22 NIS |
6483 | while (s < PL_bufend && |
6484 | (*s != term || memNE(s,PL_tokenbuf,len)) ) { | |
79072805 | 6485 | if (*s++ == '\n') |
57843af0 | 6486 | CopLINE_inc(PL_curcop); |
79072805 | 6487 | } |
3280af22 | 6488 | if (s >= PL_bufend) { |
57843af0 | 6489 | CopLINE_set(PL_curcop, PL_multi_start); |
3280af22 | 6490 | missingterm(PL_tokenbuf); |
79072805 LW |
6491 | } |
6492 | sv_setpvn(tmpstr,d+1,s-d); | |
6493 | s += len - 1; | |
57843af0 | 6494 | CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */ |
49d8d3a1 | 6495 | |
3280af22 NIS |
6496 | sv_catpvn(herewas,s,PL_bufend-s); |
6497 | sv_setsv(PL_linestr,herewas); | |
6498 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr); | |
6499 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 6500 | PL_last_lop = PL_last_uni = Nullch; |
79072805 LW |
6501 | } |
6502 | else | |
6503 | sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */ | |
3280af22 | 6504 | while (s >= PL_bufend) { /* multiple line string? */ |
fd2d0953 | 6505 | if (!outer || |
3280af22 | 6506 | !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { |
57843af0 | 6507 | CopLINE_set(PL_curcop, PL_multi_start); |
3280af22 | 6508 | missingterm(PL_tokenbuf); |
79072805 | 6509 | } |
57843af0 | 6510 | CopLINE_inc(PL_curcop); |
3280af22 | 6511 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 6512 | PL_last_lop = PL_last_uni = Nullch; |
6a27c188 | 6513 | #ifndef PERL_STRICT_CR |
3280af22 | 6514 | if (PL_bufend - PL_linestart >= 2) { |
a1529941 NIS |
6515 | if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') || |
6516 | (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r')) | |
c6f14548 | 6517 | { |
3280af22 NIS |
6518 | PL_bufend[-2] = '\n'; |
6519 | PL_bufend--; | |
6520 | SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr)); | |
f63a84b2 | 6521 | } |
3280af22 NIS |
6522 | else if (PL_bufend[-1] == '\r') |
6523 | PL_bufend[-1] = '\n'; | |
f63a84b2 | 6524 | } |
3280af22 NIS |
6525 | else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r') |
6526 | PL_bufend[-1] = '\n'; | |
f63a84b2 | 6527 | #endif |
3280af22 | 6528 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
79072805 LW |
6529 | SV *sv = NEWSV(88,0); |
6530 | ||
93a17b20 | 6531 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 6532 | sv_setsv(sv,PL_linestr); |
57843af0 | 6533 | av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv); |
79072805 | 6534 | } |
3280af22 NIS |
6535 | if (*s == term && memEQ(s,PL_tokenbuf,len)) { |
6536 | s = PL_bufend - 1; | |
79072805 | 6537 | *s = ' '; |
3280af22 NIS |
6538 | sv_catsv(PL_linestr,herewas); |
6539 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
79072805 LW |
6540 | } |
6541 | else { | |
3280af22 NIS |
6542 | s = PL_bufend; |
6543 | sv_catsv(tmpstr,PL_linestr); | |
395c3793 LW |
6544 | } |
6545 | } | |
79072805 | 6546 | s++; |
0244c3a4 | 6547 | retval: |
57843af0 | 6548 | PL_multi_end = CopLINE(PL_curcop); |
79072805 LW |
6549 | if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) { |
6550 | SvLEN_set(tmpstr, SvCUR(tmpstr) + 1); | |
463ee0b2 | 6551 | Renew(SvPVX(tmpstr), SvLEN(tmpstr), char); |
79072805 | 6552 | } |
8990e307 | 6553 | SvREFCNT_dec(herewas); |
0064a8a9 | 6554 | if (UTF && !IN_BYTES && is_utf8_string((U8*)SvPVX(tmpstr), SvCUR(tmpstr))) |
7948272d | 6555 | SvUTF8_on(tmpstr); |
3280af22 | 6556 | PL_lex_stuff = tmpstr; |
79072805 LW |
6557 | yylval.ival = op_type; |
6558 | return s; | |
6559 | } | |
6560 | ||
02aa26ce NT |
6561 | /* scan_inputsymbol |
6562 | takes: current position in input buffer | |
6563 | returns: new position in input buffer | |
6564 | side-effects: yylval and lex_op are set. | |
6565 | ||
6566 | This code handles: | |
6567 | ||
6568 | <> read from ARGV | |
6569 | <FH> read from filehandle | |
6570 | <pkg::FH> read from package qualified filehandle | |
6571 | <pkg'FH> read from package qualified filehandle | |
6572 | <$fh> read from filehandle in $fh | |
6573 | <*.h> filename glob | |
6574 | ||
6575 | */ | |
6576 | ||
76e3520e | 6577 | STATIC char * |
cea2e8a9 | 6578 | S_scan_inputsymbol(pTHX_ char *start) |
79072805 | 6579 | { |
02aa26ce | 6580 | register char *s = start; /* current position in buffer */ |
79072805 | 6581 | register char *d; |
fc36a67e | 6582 | register char *e; |
1b420867 | 6583 | char *end; |
79072805 LW |
6584 | I32 len; |
6585 | ||
3280af22 NIS |
6586 | d = PL_tokenbuf; /* start of temp holding space */ |
6587 | e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */ | |
1b420867 GS |
6588 | end = strchr(s, '\n'); |
6589 | if (!end) | |
6590 | end = PL_bufend; | |
6591 | s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */ | |
02aa26ce NT |
6592 | |
6593 | /* die if we didn't have space for the contents of the <>, | |
1b420867 | 6594 | or if it didn't end, or if we see a newline |
02aa26ce NT |
6595 | */ |
6596 | ||
3280af22 | 6597 | if (len >= sizeof PL_tokenbuf) |
cea2e8a9 | 6598 | Perl_croak(aTHX_ "Excessively long <> operator"); |
1b420867 | 6599 | if (s >= end) |
cea2e8a9 | 6600 | Perl_croak(aTHX_ "Unterminated <> operator"); |
02aa26ce | 6601 | |
fc36a67e | 6602 | s++; |
02aa26ce NT |
6603 | |
6604 | /* check for <$fh> | |
6605 | Remember, only scalar variables are interpreted as filehandles by | |
6606 | this code. Anything more complex (e.g., <$fh{$num}>) will be | |
6607 | treated as a glob() call. | |
6608 | This code makes use of the fact that except for the $ at the front, | |
6609 | a scalar variable and a filehandle look the same. | |
6610 | */ | |
4633a7c4 | 6611 | if (*d == '$' && d[1]) d++; |
02aa26ce NT |
6612 | |
6613 | /* allow <Pkg'VALUE> or <Pkg::VALUE> */ | |
7e2040f0 | 6614 | while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':')) |
79072805 | 6615 | d++; |
02aa26ce NT |
6616 | |
6617 | /* If we've tried to read what we allow filehandles to look like, and | |
6618 | there's still text left, then it must be a glob() and not a getline. | |
6619 | Use scan_str to pull out the stuff between the <> and treat it | |
6620 | as nothing more than a string. | |
6621 | */ | |
6622 | ||
3280af22 | 6623 | if (d - PL_tokenbuf != len) { |
79072805 LW |
6624 | yylval.ival = OP_GLOB; |
6625 | set_csh(); | |
09bef843 | 6626 | s = scan_str(start,FALSE,FALSE); |
79072805 | 6627 | if (!s) |
cea2e8a9 | 6628 | Perl_croak(aTHX_ "Glob not terminated"); |
79072805 LW |
6629 | return s; |
6630 | } | |
395c3793 | 6631 | else { |
02aa26ce | 6632 | /* we're in a filehandle read situation */ |
3280af22 | 6633 | d = PL_tokenbuf; |
02aa26ce NT |
6634 | |
6635 | /* turn <> into <ARGV> */ | |
79072805 LW |
6636 | if (!len) |
6637 | (void)strcpy(d,"ARGV"); | |
02aa26ce NT |
6638 | |
6639 | /* if <$fh>, create the ops to turn the variable into a | |
6640 | filehandle | |
6641 | */ | |
79072805 | 6642 | if (*d == '$') { |
a0d0e21e | 6643 | I32 tmp; |
02aa26ce NT |
6644 | |
6645 | /* try to find it in the pad for this block, otherwise find | |
6646 | add symbol table ops | |
6647 | */ | |
11343788 MB |
6648 | if ((tmp = pad_findmy(d)) != NOT_IN_PAD) { |
6649 | OP *o = newOP(OP_PADSV, 0); | |
6650 | o->op_targ = tmp; | |
f5284f61 | 6651 | PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, o); |
a0d0e21e LW |
6652 | } |
6653 | else { | |
6654 | GV *gv = gv_fetchpv(d+1,TRUE, SVt_PV); | |
3280af22 | 6655 | PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, |
a0d0e21e | 6656 | newUNOP(OP_RV2SV, 0, |
f5284f61 | 6657 | newGVOP(OP_GV, 0, gv))); |
a0d0e21e | 6658 | } |
f5284f61 IZ |
6659 | PL_lex_op->op_flags |= OPf_SPECIAL; |
6660 | /* we created the ops in PL_lex_op, so make yylval.ival a null op */ | |
79072805 LW |
6661 | yylval.ival = OP_NULL; |
6662 | } | |
02aa26ce NT |
6663 | |
6664 | /* If it's none of the above, it must be a literal filehandle | |
6665 | (<Foo::BAR> or <FOO>) so build a simple readline OP */ | |
79072805 | 6666 | else { |
85e6fe83 | 6667 | GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO); |
3280af22 | 6668 | PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv)); |
79072805 LW |
6669 | yylval.ival = OP_NULL; |
6670 | } | |
6671 | } | |
02aa26ce | 6672 | |
79072805 LW |
6673 | return s; |
6674 | } | |
6675 | ||
02aa26ce NT |
6676 | |
6677 | /* scan_str | |
6678 | takes: start position in buffer | |
09bef843 SB |
6679 | keep_quoted preserve \ on the embedded delimiter(s) |
6680 | keep_delims preserve the delimiters around the string | |
02aa26ce NT |
6681 | returns: position to continue reading from buffer |
6682 | side-effects: multi_start, multi_close, lex_repl or lex_stuff, and | |
6683 | updates the read buffer. | |
6684 | ||
6685 | This subroutine pulls a string out of the input. It is called for: | |
6686 | q single quotes q(literal text) | |
6687 | ' single quotes 'literal text' | |
6688 | qq double quotes qq(interpolate $here please) | |
6689 | " double quotes "interpolate $here please" | |
6690 | qx backticks qx(/bin/ls -l) | |
6691 | ` backticks `/bin/ls -l` | |
6692 | qw quote words @EXPORT_OK = qw( func() $spam ) | |
6693 | m// regexp match m/this/ | |
6694 | s/// regexp substitute s/this/that/ | |
6695 | tr/// string transliterate tr/this/that/ | |
6696 | y/// string transliterate y/this/that/ | |
6697 | ($*@) sub prototypes sub foo ($) | |
09bef843 | 6698 | (stuff) sub attr parameters sub foo : attr(stuff) |
02aa26ce NT |
6699 | <> readline or globs <FOO>, <>, <$fh>, or <*.c> |
6700 | ||
6701 | In most of these cases (all but <>, patterns and transliterate) | |
6702 | yylex() calls scan_str(). m// makes yylex() call scan_pat() which | |
6703 | calls scan_str(). s/// makes yylex() call scan_subst() which calls | |
6704 | scan_str(). tr/// and y/// make yylex() call scan_trans() which | |
6705 | calls scan_str(). | |
4e553d73 | 6706 | |
02aa26ce NT |
6707 | It skips whitespace before the string starts, and treats the first |
6708 | character as the delimiter. If the delimiter is one of ([{< then | |
6709 | the corresponding "close" character )]}> is used as the closing | |
6710 | delimiter. It allows quoting of delimiters, and if the string has | |
6711 | balanced delimiters ([{<>}]) it allows nesting. | |
6712 | ||
37fd879b HS |
6713 | On success, the SV with the resulting string is put into lex_stuff or, |
6714 | if that is already non-NULL, into lex_repl. The second case occurs only | |
6715 | when parsing the RHS of the special constructs s/// and tr/// (y///). | |
6716 | For convenience, the terminating delimiter character is stuffed into | |
6717 | SvIVX of the SV. | |
02aa26ce NT |
6718 | */ |
6719 | ||
76e3520e | 6720 | STATIC char * |
09bef843 | 6721 | S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims) |
79072805 | 6722 | { |
02aa26ce NT |
6723 | SV *sv; /* scalar value: string */ |
6724 | char *tmps; /* temp string, used for delimiter matching */ | |
6725 | register char *s = start; /* current position in the buffer */ | |
6726 | register char term; /* terminating character */ | |
6727 | register char *to; /* current position in the sv's data */ | |
6728 | I32 brackets = 1; /* bracket nesting level */ | |
89491803 | 6729 | bool has_utf8 = FALSE; /* is there any utf8 content? */ |
02aa26ce NT |
6730 | |
6731 | /* skip space before the delimiter */ | |
fb73857a | 6732 | if (isSPACE(*s)) |
6733 | s = skipspace(s); | |
02aa26ce NT |
6734 | |
6735 | /* mark where we are, in case we need to report errors */ | |
79072805 | 6736 | CLINE; |
02aa26ce NT |
6737 | |
6738 | /* after skipping whitespace, the next character is the terminator */ | |
a0d0e21e | 6739 | term = *s; |
63cd0674 | 6740 | if (!UTF8_IS_INVARIANT((U8)term) && UTF) |
89491803 | 6741 | has_utf8 = TRUE; |
b1c7b182 | 6742 | |
02aa26ce | 6743 | /* mark where we are */ |
57843af0 | 6744 | PL_multi_start = CopLINE(PL_curcop); |
3280af22 | 6745 | PL_multi_open = term; |
02aa26ce NT |
6746 | |
6747 | /* find corresponding closing delimiter */ | |
93a17b20 | 6748 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) |
79072805 | 6749 | term = tmps[5]; |
3280af22 | 6750 | PL_multi_close = term; |
79072805 | 6751 | |
02aa26ce | 6752 | /* create a new SV to hold the contents. 87 is leak category, I'm |
8d6dde3e IZ |
6753 | assuming. 79 is the SV's initial length. What a random number. */ |
6754 | sv = NEWSV(87,79); | |
ed6116ce LW |
6755 | sv_upgrade(sv, SVt_PVIV); |
6756 | SvIVX(sv) = term; | |
a0d0e21e | 6757 | (void)SvPOK_only(sv); /* validate pointer */ |
02aa26ce NT |
6758 | |
6759 | /* move past delimiter and try to read a complete string */ | |
09bef843 SB |
6760 | if (keep_delims) |
6761 | sv_catpvn(sv, s, 1); | |
93a17b20 LW |
6762 | s++; |
6763 | for (;;) { | |
02aa26ce | 6764 | /* extend sv if need be */ |
3280af22 | 6765 | SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1); |
02aa26ce | 6766 | /* set 'to' to the next character in the sv's string */ |
463ee0b2 | 6767 | to = SvPVX(sv)+SvCUR(sv); |
09bef843 | 6768 | |
02aa26ce | 6769 | /* if open delimiter is the close delimiter read unbridle */ |
3280af22 NIS |
6770 | if (PL_multi_open == PL_multi_close) { |
6771 | for (; s < PL_bufend; s++,to++) { | |
02aa26ce | 6772 | /* embedded newlines increment the current line number */ |
3280af22 | 6773 | if (*s == '\n' && !PL_rsfp) |
57843af0 | 6774 | CopLINE_inc(PL_curcop); |
02aa26ce | 6775 | /* handle quoted delimiters */ |
3280af22 | 6776 | if (*s == '\\' && s+1 < PL_bufend && term != '\\') { |
09bef843 | 6777 | if (!keep_quoted && s[1] == term) |
a0d0e21e | 6778 | s++; |
02aa26ce | 6779 | /* any other quotes are simply copied straight through */ |
a0d0e21e LW |
6780 | else |
6781 | *to++ = *s++; | |
6782 | } | |
02aa26ce NT |
6783 | /* terminate when run out of buffer (the for() condition), or |
6784 | have found the terminator */ | |
93a17b20 LW |
6785 | else if (*s == term) |
6786 | break; | |
63cd0674 | 6787 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
89491803 | 6788 | has_utf8 = TRUE; |
93a17b20 LW |
6789 | *to = *s; |
6790 | } | |
6791 | } | |
02aa26ce NT |
6792 | |
6793 | /* if the terminator isn't the same as the start character (e.g., | |
6794 | matched brackets), we have to allow more in the quoting, and | |
6795 | be prepared for nested brackets. | |
6796 | */ | |
93a17b20 | 6797 | else { |
02aa26ce | 6798 | /* read until we run out of string, or we find the terminator */ |
3280af22 | 6799 | for (; s < PL_bufend; s++,to++) { |
02aa26ce | 6800 | /* embedded newlines increment the line count */ |
3280af22 | 6801 | if (*s == '\n' && !PL_rsfp) |
57843af0 | 6802 | CopLINE_inc(PL_curcop); |
02aa26ce | 6803 | /* backslashes can escape the open or closing characters */ |
3280af22 | 6804 | if (*s == '\\' && s+1 < PL_bufend) { |
09bef843 SB |
6805 | if (!keep_quoted && |
6806 | ((s[1] == PL_multi_open) || (s[1] == PL_multi_close))) | |
a0d0e21e LW |
6807 | s++; |
6808 | else | |
6809 | *to++ = *s++; | |
6810 | } | |
02aa26ce | 6811 | /* allow nested opens and closes */ |
3280af22 | 6812 | else if (*s == PL_multi_close && --brackets <= 0) |
93a17b20 | 6813 | break; |
3280af22 | 6814 | else if (*s == PL_multi_open) |
93a17b20 | 6815 | brackets++; |
63cd0674 | 6816 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
89491803 | 6817 | has_utf8 = TRUE; |
93a17b20 LW |
6818 | *to = *s; |
6819 | } | |
6820 | } | |
02aa26ce | 6821 | /* terminate the copied string and update the sv's end-of-string */ |
93a17b20 | 6822 | *to = '\0'; |
463ee0b2 | 6823 | SvCUR_set(sv, to - SvPVX(sv)); |
93a17b20 | 6824 | |
02aa26ce NT |
6825 | /* |
6826 | * this next chunk reads more into the buffer if we're not done yet | |
6827 | */ | |
6828 | ||
b1c7b182 GS |
6829 | if (s < PL_bufend) |
6830 | break; /* handle case where we are done yet :-) */ | |
79072805 | 6831 | |
6a27c188 | 6832 | #ifndef PERL_STRICT_CR |
f63a84b2 | 6833 | if (to - SvPVX(sv) >= 2) { |
c6f14548 GS |
6834 | if ((to[-2] == '\r' && to[-1] == '\n') || |
6835 | (to[-2] == '\n' && to[-1] == '\r')) | |
6836 | { | |
f63a84b2 LW |
6837 | to[-2] = '\n'; |
6838 | to--; | |
6839 | SvCUR_set(sv, to - SvPVX(sv)); | |
6840 | } | |
6841 | else if (to[-1] == '\r') | |
6842 | to[-1] = '\n'; | |
6843 | } | |
6844 | else if (to - SvPVX(sv) == 1 && to[-1] == '\r') | |
6845 | to[-1] = '\n'; | |
6846 | #endif | |
6847 | ||
02aa26ce NT |
6848 | /* if we're out of file, or a read fails, bail and reset the current |
6849 | line marker so we can report where the unterminated string began | |
6850 | */ | |
3280af22 NIS |
6851 | if (!PL_rsfp || |
6852 | !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { | |
c07a80fd | 6853 | sv_free(sv); |
57843af0 | 6854 | CopLINE_set(PL_curcop, PL_multi_start); |
79072805 LW |
6855 | return Nullch; |
6856 | } | |
02aa26ce | 6857 | /* we read a line, so increment our line counter */ |
57843af0 | 6858 | CopLINE_inc(PL_curcop); |
a0ed51b3 | 6859 | |
02aa26ce | 6860 | /* update debugger info */ |
3280af22 | 6861 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
79072805 LW |
6862 | SV *sv = NEWSV(88,0); |
6863 | ||
93a17b20 | 6864 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 6865 | sv_setsv(sv,PL_linestr); |
57843af0 | 6866 | av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv); |
395c3793 | 6867 | } |
a0ed51b3 | 6868 | |
3280af22 NIS |
6869 | /* having changed the buffer, we must update PL_bufend */ |
6870 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 6871 | PL_last_lop = PL_last_uni = Nullch; |
378cc40b | 6872 | } |
4e553d73 | 6873 | |
02aa26ce NT |
6874 | /* at this point, we have successfully read the delimited string */ |
6875 | ||
09bef843 SB |
6876 | if (keep_delims) |
6877 | sv_catpvn(sv, s, 1); | |
89491803 | 6878 | if (has_utf8) |
b1c7b182 | 6879 | SvUTF8_on(sv); |
57843af0 | 6880 | PL_multi_end = CopLINE(PL_curcop); |
79072805 | 6881 | s++; |
02aa26ce NT |
6882 | |
6883 | /* if we allocated too much space, give some back */ | |
93a17b20 LW |
6884 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
6885 | SvLEN_set(sv, SvCUR(sv) + 1); | |
463ee0b2 | 6886 | Renew(SvPVX(sv), SvLEN(sv), char); |
79072805 | 6887 | } |
02aa26ce NT |
6888 | |
6889 | /* decide whether this is the first or second quoted string we've read | |
6890 | for this op | |
6891 | */ | |
4e553d73 | 6892 | |
3280af22 NIS |
6893 | if (PL_lex_stuff) |
6894 | PL_lex_repl = sv; | |
79072805 | 6895 | else |
3280af22 | 6896 | PL_lex_stuff = sv; |
378cc40b LW |
6897 | return s; |
6898 | } | |
6899 | ||
02aa26ce NT |
6900 | /* |
6901 | scan_num | |
6902 | takes: pointer to position in buffer | |
6903 | returns: pointer to new position in buffer | |
6904 | side-effects: builds ops for the constant in yylval.op | |
6905 | ||
6906 | Read a number in any of the formats that Perl accepts: | |
6907 | ||
7fd134d9 JH |
6908 | \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12. |
6909 | \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34 | |
24138b49 JH |
6910 | 0b[01](_?[01])* |
6911 | 0[0-7](_?[0-7])* | |
6912 | 0x[0-9A-Fa-f](_?[0-9A-Fa-f])* | |
02aa26ce | 6913 | |
3280af22 | 6914 | Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the |
02aa26ce NT |
6915 | thing it reads. |
6916 | ||
6917 | If it reads a number without a decimal point or an exponent, it will | |
6918 | try converting the number to an integer and see if it can do so | |
6919 | without loss of precision. | |
6920 | */ | |
4e553d73 | 6921 | |
378cc40b | 6922 | char * |
b73d6f50 | 6923 | Perl_scan_num(pTHX_ char *start, YYSTYPE* lvalp) |
378cc40b | 6924 | { |
02aa26ce NT |
6925 | register char *s = start; /* current position in buffer */ |
6926 | register char *d; /* destination in temp buffer */ | |
6927 | register char *e; /* end of temp buffer */ | |
86554af2 | 6928 | NV nv; /* number read, as a double */ |
a7cb1f99 | 6929 | SV *sv = Nullsv; /* place to put the converted number */ |
a86a20aa | 6930 | bool floatit; /* boolean: int or float? */ |
02aa26ce | 6931 | char *lastub = 0; /* position of last underbar */ |
fc36a67e | 6932 | static char number_too_long[] = "Number too long"; |
378cc40b | 6933 | |
02aa26ce NT |
6934 | /* We use the first character to decide what type of number this is */ |
6935 | ||
378cc40b | 6936 | switch (*s) { |
79072805 | 6937 | default: |
cea2e8a9 | 6938 | Perl_croak(aTHX_ "panic: scan_num"); |
4e553d73 | 6939 | |
02aa26ce | 6940 | /* if it starts with a 0, it could be an octal number, a decimal in |
a7cb1f99 | 6941 | 0.13 disguise, or a hexadecimal number, or a binary number. */ |
378cc40b LW |
6942 | case '0': |
6943 | { | |
02aa26ce NT |
6944 | /* variables: |
6945 | u holds the "number so far" | |
4f19785b WSI |
6946 | shift the power of 2 of the base |
6947 | (hex == 4, octal == 3, binary == 1) | |
02aa26ce NT |
6948 | overflowed was the number more than we can hold? |
6949 | ||
6950 | Shift is used when we add a digit. It also serves as an "are | |
4f19785b WSI |
6951 | we in octal/hex/binary?" indicator to disallow hex characters |
6952 | when in octal mode. | |
02aa26ce | 6953 | */ |
9e24b6e2 JH |
6954 | NV n = 0.0; |
6955 | UV u = 0; | |
79072805 | 6956 | I32 shift; |
9e24b6e2 JH |
6957 | bool overflowed = FALSE; |
6958 | static NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 }; | |
6959 | static char* bases[5] = { "", "binary", "", "octal", | |
6960 | "hexadecimal" }; | |
6961 | static char* Bases[5] = { "", "Binary", "", "Octal", | |
6962 | "Hexadecimal" }; | |
6963 | static char *maxima[5] = { "", | |
6964 | "0b11111111111111111111111111111111", | |
6965 | "", | |
893fe2c2 | 6966 | "037777777777", |
9e24b6e2 JH |
6967 | "0xffffffff" }; |
6968 | char *base, *Base, *max; | |
378cc40b | 6969 | |
02aa26ce | 6970 | /* check for hex */ |
378cc40b LW |
6971 | if (s[1] == 'x') { |
6972 | shift = 4; | |
6973 | s += 2; | |
4f19785b WSI |
6974 | } else if (s[1] == 'b') { |
6975 | shift = 1; | |
6976 | s += 2; | |
378cc40b | 6977 | } |
02aa26ce | 6978 | /* check for a decimal in disguise */ |
b78218b7 | 6979 | else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E') |
378cc40b | 6980 | goto decimal; |
02aa26ce | 6981 | /* so it must be octal */ |
928753ea | 6982 | else { |
378cc40b | 6983 | shift = 3; |
928753ea JH |
6984 | s++; |
6985 | } | |
6986 | ||
6987 | if (*s == '_') { | |
6988 | if (ckWARN(WARN_SYNTAX)) | |
6989 | Perl_warner(aTHX_ WARN_SYNTAX, | |
6990 | "Misplaced _ in number"); | |
6991 | lastub = s++; | |
6992 | } | |
9e24b6e2 JH |
6993 | |
6994 | base = bases[shift]; | |
6995 | Base = Bases[shift]; | |
6996 | max = maxima[shift]; | |
02aa26ce | 6997 | |
4f19785b | 6998 | /* read the rest of the number */ |
378cc40b | 6999 | for (;;) { |
9e24b6e2 | 7000 | /* x is used in the overflow test, |
893fe2c2 | 7001 | b is the digit we're adding on. */ |
9e24b6e2 | 7002 | UV x, b; |
55497cff | 7003 | |
378cc40b | 7004 | switch (*s) { |
02aa26ce NT |
7005 | |
7006 | /* if we don't mention it, we're done */ | |
378cc40b LW |
7007 | default: |
7008 | goto out; | |
02aa26ce | 7009 | |
928753ea | 7010 | /* _ are ignored -- but warned about if consecutive */ |
de3bb511 | 7011 | case '_': |
928753ea JH |
7012 | if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1) |
7013 | Perl_warner(aTHX_ WARN_SYNTAX, | |
7014 | "Misplaced _ in number"); | |
7015 | lastub = s++; | |
de3bb511 | 7016 | break; |
02aa26ce NT |
7017 | |
7018 | /* 8 and 9 are not octal */ | |
378cc40b | 7019 | case '8': case '9': |
4f19785b | 7020 | if (shift == 3) |
cea2e8a9 | 7021 | yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s)); |
378cc40b | 7022 | /* FALL THROUGH */ |
02aa26ce NT |
7023 | |
7024 | /* octal digits */ | |
4f19785b | 7025 | case '2': case '3': case '4': |
378cc40b | 7026 | case '5': case '6': case '7': |
4f19785b | 7027 | if (shift == 1) |
cea2e8a9 | 7028 | yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s)); |
4f19785b WSI |
7029 | /* FALL THROUGH */ |
7030 | ||
7031 | case '0': case '1': | |
02aa26ce | 7032 | b = *s++ & 15; /* ASCII digit -> value of digit */ |
55497cff | 7033 | goto digit; |
02aa26ce NT |
7034 | |
7035 | /* hex digits */ | |
378cc40b LW |
7036 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': |
7037 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': | |
02aa26ce | 7038 | /* make sure they said 0x */ |
378cc40b LW |
7039 | if (shift != 4) |
7040 | goto out; | |
55497cff | 7041 | b = (*s++ & 7) + 9; |
02aa26ce NT |
7042 | |
7043 | /* Prepare to put the digit we have onto the end | |
7044 | of the number so far. We check for overflows. | |
7045 | */ | |
7046 | ||
55497cff | 7047 | digit: |
9e24b6e2 JH |
7048 | if (!overflowed) { |
7049 | x = u << shift; /* make room for the digit */ | |
7050 | ||
7051 | if ((x >> shift) != u | |
7052 | && !(PL_hints & HINT_NEW_BINARY)) { | |
9e24b6e2 JH |
7053 | overflowed = TRUE; |
7054 | n = (NV) u; | |
767a6a26 PM |
7055 | if (ckWARN_d(WARN_OVERFLOW)) |
7056 | Perl_warner(aTHX_ WARN_OVERFLOW, | |
9e24b6e2 JH |
7057 | "Integer overflow in %s number", |
7058 | base); | |
7059 | } else | |
7060 | u = x | b; /* add the digit to the end */ | |
7061 | } | |
7062 | if (overflowed) { | |
7063 | n *= nvshift[shift]; | |
7064 | /* If an NV has not enough bits in its | |
7065 | * mantissa to represent an UV this summing of | |
7066 | * small low-order numbers is a waste of time | |
7067 | * (because the NV cannot preserve the | |
7068 | * low-order bits anyway): we could just | |
7069 | * remember when did we overflow and in the | |
7070 | * end just multiply n by the right | |
7071 | * amount. */ | |
7072 | n += (NV) b; | |
55497cff | 7073 | } |
378cc40b LW |
7074 | break; |
7075 | } | |
7076 | } | |
02aa26ce NT |
7077 | |
7078 | /* if we get here, we had success: make a scalar value from | |
7079 | the number. | |
7080 | */ | |
378cc40b | 7081 | out: |
928753ea JH |
7082 | |
7083 | /* final misplaced underbar check */ | |
7084 | if (s[-1] == '_') { | |
7085 | if (ckWARN(WARN_SYNTAX)) | |
7086 | Perl_warner(aTHX_ WARN_SYNTAX, "Misplaced _ in number"); | |
7087 | } | |
7088 | ||
79072805 | 7089 | sv = NEWSV(92,0); |
9e24b6e2 | 7090 | if (overflowed) { |
767a6a26 PM |
7091 | if (ckWARN(WARN_PORTABLE) && n > 4294967295.0) |
7092 | Perl_warner(aTHX_ WARN_PORTABLE, | |
9e24b6e2 JH |
7093 | "%s number > %s non-portable", |
7094 | Base, max); | |
7095 | sv_setnv(sv, n); | |
7096 | } | |
7097 | else { | |
15041a67 | 7098 | #if UVSIZE > 4 |
767a6a26 PM |
7099 | if (ckWARN(WARN_PORTABLE) && u > 0xffffffff) |
7100 | Perl_warner(aTHX_ WARN_PORTABLE, | |
9e24b6e2 JH |
7101 | "%s number > %s non-portable", |
7102 | Base, max); | |
2cc4c2dc | 7103 | #endif |
9e24b6e2 JH |
7104 | sv_setuv(sv, u); |
7105 | } | |
2cc4c2dc | 7106 | if (PL_hints & HINT_NEW_BINARY) |
b3ac6de7 | 7107 | sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL); |
378cc40b LW |
7108 | } |
7109 | break; | |
02aa26ce NT |
7110 | |
7111 | /* | |
7112 | handle decimal numbers. | |
7113 | we're also sent here when we read a 0 as the first digit | |
7114 | */ | |
378cc40b LW |
7115 | case '1': case '2': case '3': case '4': case '5': |
7116 | case '6': case '7': case '8': case '9': case '.': | |
7117 | decimal: | |
3280af22 NIS |
7118 | d = PL_tokenbuf; |
7119 | e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */ | |
79072805 | 7120 | floatit = FALSE; |
02aa26ce NT |
7121 | |
7122 | /* read next group of digits and _ and copy into d */ | |
de3bb511 | 7123 | while (isDIGIT(*s) || *s == '_') { |
4e553d73 | 7124 | /* skip underscores, checking for misplaced ones |
02aa26ce NT |
7125 | if -w is on |
7126 | */ | |
93a17b20 | 7127 | if (*s == '_') { |
928753ea JH |
7128 | if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1) |
7129 | Perl_warner(aTHX_ WARN_SYNTAX, | |
7130 | "Misplaced _ in number"); | |
7131 | lastub = s++; | |
93a17b20 | 7132 | } |
fc36a67e | 7133 | else { |
02aa26ce | 7134 | /* check for end of fixed-length buffer */ |
fc36a67e | 7135 | if (d >= e) |
cea2e8a9 | 7136 | Perl_croak(aTHX_ number_too_long); |
02aa26ce | 7137 | /* if we're ok, copy the character */ |
378cc40b | 7138 | *d++ = *s++; |
fc36a67e | 7139 | } |
378cc40b | 7140 | } |
02aa26ce NT |
7141 | |
7142 | /* final misplaced underbar check */ | |
928753ea | 7143 | if (lastub && s == lastub + 1) { |
d008e5eb | 7144 | if (ckWARN(WARN_SYNTAX)) |
cea2e8a9 | 7145 | Perl_warner(aTHX_ WARN_SYNTAX, "Misplaced _ in number"); |
d008e5eb | 7146 | } |
02aa26ce NT |
7147 | |
7148 | /* read a decimal portion if there is one. avoid | |
7149 | 3..5 being interpreted as the number 3. followed | |
7150 | by .5 | |
7151 | */ | |
2f3197b3 | 7152 | if (*s == '.' && s[1] != '.') { |
79072805 | 7153 | floatit = TRUE; |
378cc40b | 7154 | *d++ = *s++; |
02aa26ce | 7155 | |
928753ea JH |
7156 | if (*s == '_') { |
7157 | if (ckWARN(WARN_SYNTAX)) | |
7158 | Perl_warner(aTHX_ WARN_SYNTAX, | |
7159 | "Misplaced _ in number"); | |
7160 | lastub = s; | |
7161 | } | |
7162 | ||
7163 | /* copy, ignoring underbars, until we run out of digits. | |
02aa26ce | 7164 | */ |
fc36a67e | 7165 | for (; isDIGIT(*s) || *s == '_'; s++) { |
02aa26ce | 7166 | /* fixed length buffer check */ |
fc36a67e | 7167 | if (d >= e) |
cea2e8a9 | 7168 | Perl_croak(aTHX_ number_too_long); |
928753ea JH |
7169 | if (*s == '_') { |
7170 | if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1) | |
7171 | Perl_warner(aTHX_ WARN_SYNTAX, | |
7172 | "Misplaced _ in number"); | |
7173 | lastub = s; | |
7174 | } | |
7175 | else | |
fc36a67e | 7176 | *d++ = *s; |
378cc40b | 7177 | } |
928753ea JH |
7178 | /* fractional part ending in underbar? */ |
7179 | if (s[-1] == '_') { | |
7180 | if (ckWARN(WARN_SYNTAX)) | |
7181 | Perl_warner(aTHX_ WARN_SYNTAX, | |
7182 | "Misplaced _ in number"); | |
7183 | } | |
dd629d5b GS |
7184 | if (*s == '.' && isDIGIT(s[1])) { |
7185 | /* oops, it's really a v-string, but without the "v" */ | |
7186 | s = start - 1; | |
7187 | goto vstring; | |
7188 | } | |
378cc40b | 7189 | } |
02aa26ce NT |
7190 | |
7191 | /* read exponent part, if present */ | |
7fd134d9 | 7192 | if (*s && strchr("eE",*s) && strchr("+-0123456789_", s[1])) { |
79072805 LW |
7193 | floatit = TRUE; |
7194 | s++; | |
02aa26ce NT |
7195 | |
7196 | /* regardless of whether user said 3E5 or 3e5, use lower 'e' */ | |
79072805 | 7197 | *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */ |
02aa26ce | 7198 | |
7fd134d9 JH |
7199 | /* stray preinitial _ */ |
7200 | if (*s == '_') { | |
7201 | if (ckWARN(WARN_SYNTAX)) | |
7202 | Perl_warner(aTHX_ WARN_SYNTAX, | |
7203 | "Misplaced _ in number"); | |
7204 | lastub = s++; | |
7205 | } | |
7206 | ||
02aa26ce | 7207 | /* allow positive or negative exponent */ |
378cc40b LW |
7208 | if (*s == '+' || *s == '-') |
7209 | *d++ = *s++; | |
02aa26ce | 7210 | |
7fd134d9 JH |
7211 | /* stray initial _ */ |
7212 | if (*s == '_') { | |
7213 | if (ckWARN(WARN_SYNTAX)) | |
7214 | Perl_warner(aTHX_ WARN_SYNTAX, | |
7215 | "Misplaced _ in number"); | |
7216 | lastub = s++; | |
7217 | } | |
7218 | ||
7fd134d9 JH |
7219 | /* read digits of exponent */ |
7220 | while (isDIGIT(*s) || *s == '_') { | |
7221 | if (isDIGIT(*s)) { | |
7222 | if (d >= e) | |
7223 | Perl_croak(aTHX_ number_too_long); | |
b3b48e3e | 7224 | *d++ = *s++; |
7fd134d9 JH |
7225 | } |
7226 | else { | |
7227 | if (ckWARN(WARN_SYNTAX) && | |
7228 | ((lastub && s == lastub + 1) || | |
b3b48e3e | 7229 | (!isDIGIT(s[1]) && s[1] != '_'))) |
7fd134d9 JH |
7230 | Perl_warner(aTHX_ WARN_SYNTAX, |
7231 | "Misplaced _ in number"); | |
b3b48e3e | 7232 | lastub = s++; |
7fd134d9 | 7233 | } |
7fd134d9 | 7234 | } |
378cc40b | 7235 | } |
02aa26ce | 7236 | |
02aa26ce NT |
7237 | |
7238 | /* make an sv from the string */ | |
79072805 | 7239 | sv = NEWSV(92,0); |
097ee67d | 7240 | |
0b7fceb9 | 7241 | /* |
58bb9ec3 NC |
7242 | We try to do an integer conversion first if no characters |
7243 | indicating "float" have been found. | |
0b7fceb9 MU |
7244 | */ |
7245 | ||
7246 | if (!floatit) { | |
58bb9ec3 NC |
7247 | UV uv; |
7248 | int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv); | |
7249 | ||
7250 | if (flags == IS_NUMBER_IN_UV) { | |
7251 | if (uv <= IV_MAX) | |
86554af2 | 7252 | sv_setiv(sv, uv); /* Prefer IVs over UVs. */ |
58bb9ec3 | 7253 | else |
c239479b | 7254 | sv_setuv(sv, uv); |
58bb9ec3 NC |
7255 | } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) { |
7256 | if (uv <= (UV) IV_MIN) | |
7257 | sv_setiv(sv, -(IV)uv); | |
7258 | else | |
7259 | floatit = TRUE; | |
7260 | } else | |
7261 | floatit = TRUE; | |
7262 | } | |
0b7fceb9 | 7263 | if (floatit) { |
58bb9ec3 NC |
7264 | /* terminate the string */ |
7265 | *d = '\0'; | |
86554af2 JH |
7266 | nv = Atof(PL_tokenbuf); |
7267 | sv_setnv(sv, nv); | |
7268 | } | |
86554af2 | 7269 | |
b8403495 JH |
7270 | if ( floatit ? (PL_hints & HINT_NEW_FLOAT) : |
7271 | (PL_hints & HINT_NEW_INTEGER) ) | |
4e553d73 | 7272 | sv = new_constant(PL_tokenbuf, d - PL_tokenbuf, |
b8403495 JH |
7273 | (floatit ? "float" : "integer"), |
7274 | sv, Nullsv, NULL); | |
378cc40b | 7275 | break; |
0b7fceb9 | 7276 | |
e312add1 | 7277 | /* if it starts with a v, it could be a v-string */ |
a7cb1f99 | 7278 | case 'v': |
dd629d5b | 7279 | vstring: |
a7cb1f99 | 7280 | { |
a7cb1f99 GS |
7281 | char *pos = s; |
7282 | pos++; | |
dd629d5b | 7283 | while (isDIGIT(*pos) || *pos == '_') |
a7cb1f99 | 7284 | pos++; |
e526c9e6 | 7285 | if (!isALPHA(*pos)) { |
c4d5f83a | 7286 | UV rev; |
ad391ad9 | 7287 | U8 tmpbuf[UTF8_MAXLEN+1]; |
a7cb1f99 | 7288 | U8 *tmpend; |
a7cb1f99 GS |
7289 | s++; /* get past 'v' */ |
7290 | ||
7291 | sv = NEWSV(92,5); | |
a7cb1f99 GS |
7292 | sv_setpvn(sv, "", 0); |
7293 | ||
e526c9e6 | 7294 | for (;;) { |
3cb0bbe5 GS |
7295 | if (*s == '0' && isDIGIT(s[1])) |
7296 | yyerror("Octal number in vector unsupported"); | |
dd629d5b GS |
7297 | rev = 0; |
7298 | { | |
7299 | /* this is atoi() that tolerates underscores */ | |
7300 | char *end = pos; | |
7301 | UV mult = 1; | |
7302 | while (--end >= s) { | |
7303 | UV orev; | |
7304 | if (*end == '_') | |
7305 | continue; | |
7306 | orev = rev; | |
7307 | rev += (*end - '0') * mult; | |
7308 | mult *= 10; | |
7309 | if (orev > rev && ckWARN_d(WARN_OVERFLOW)) | |
7310 | Perl_warner(aTHX_ WARN_OVERFLOW, | |
7311 | "Integer overflow in decimal number"); | |
7312 | } | |
7313 | } | |
9041c2e3 NIS |
7314 | /* Append native character for the rev point */ |
7315 | tmpend = uvchr_to_utf8(tmpbuf, rev); | |
e526c9e6 | 7316 | sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf); |
c4d5f83a NIS |
7317 | if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev))) |
7318 | SvUTF8_on(sv); | |
e526c9e6 GS |
7319 | if (*pos == '.' && isDIGIT(pos[1])) |
7320 | s = ++pos; | |
3818b22b | 7321 | else { |
e526c9e6 GS |
7322 | s = pos; |
7323 | break; | |
3818b22b | 7324 | } |
dd629d5b | 7325 | while (isDIGIT(*pos) || *pos == '_') |
e526c9e6 GS |
7326 | pos++; |
7327 | } | |
a7cb1f99 | 7328 | SvPOK_on(sv); |
a7cb1f99 | 7329 | SvREADONLY_on(sv); |
a7cb1f99 GS |
7330 | } |
7331 | } | |
7332 | break; | |
79072805 | 7333 | } |
a687059c | 7334 | |
02aa26ce NT |
7335 | /* make the op for the constant and return */ |
7336 | ||
a86a20aa | 7337 | if (sv) |
b73d6f50 | 7338 | lvalp->opval = newSVOP(OP_CONST, 0, sv); |
a7cb1f99 | 7339 | else |
b73d6f50 | 7340 | lvalp->opval = Nullop; |
a687059c | 7341 | |
378cc40b LW |
7342 | return s; |
7343 | } | |
7344 | ||
76e3520e | 7345 | STATIC char * |
cea2e8a9 | 7346 | S_scan_formline(pTHX_ register char *s) |
378cc40b | 7347 | { |
79072805 | 7348 | register char *eol; |
378cc40b | 7349 | register char *t; |
79cb57f6 | 7350 | SV *stuff = newSVpvn("",0); |
79072805 | 7351 | bool needargs = FALSE; |
378cc40b | 7352 | |
79072805 | 7353 | while (!needargs) { |
c2e66d9e | 7354 | if (*s == '.' || *s == /*{*/'}') { |
79072805 | 7355 | /*SUPPRESS 530*/ |
51882d45 | 7356 | #ifdef PERL_STRICT_CR |
bf4acbe4 | 7357 | for (t = s+1;SPACE_OR_TAB(*t); t++) ; |
51882d45 | 7358 | #else |
bf4acbe4 | 7359 | for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ; |
51882d45 | 7360 | #endif |
6a65c6a0 | 7361 | if (*t == '\n' || t == PL_bufend) |
79072805 LW |
7362 | break; |
7363 | } | |
3280af22 | 7364 | if (PL_in_eval && !PL_rsfp) { |
93a17b20 | 7365 | eol = strchr(s,'\n'); |
0f85fab0 | 7366 | if (!eol++) |
3280af22 | 7367 | eol = PL_bufend; |
0f85fab0 LW |
7368 | } |
7369 | else | |
3280af22 | 7370 | eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
79072805 | 7371 | if (*s != '#') { |
a0d0e21e LW |
7372 | for (t = s; t < eol; t++) { |
7373 | if (*t == '~' && t[1] == '~' && SvCUR(stuff)) { | |
7374 | needargs = FALSE; | |
7375 | goto enough; /* ~~ must be first line in formline */ | |
378cc40b | 7376 | } |
a0d0e21e LW |
7377 | if (*t == '@' || *t == '^') |
7378 | needargs = TRUE; | |
378cc40b | 7379 | } |
7121b347 MG |
7380 | if (eol > s) { |
7381 | sv_catpvn(stuff, s, eol-s); | |
2dc4c65b | 7382 | #ifndef PERL_STRICT_CR |
7121b347 MG |
7383 | if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') { |
7384 | char *end = SvPVX(stuff) + SvCUR(stuff); | |
7385 | end[-2] = '\n'; | |
7386 | end[-1] = '\0'; | |
7387 | SvCUR(stuff)--; | |
7388 | } | |
2dc4c65b | 7389 | #endif |
7121b347 MG |
7390 | } |
7391 | else | |
7392 | break; | |
79072805 LW |
7393 | } |
7394 | s = eol; | |
3280af22 NIS |
7395 | if (PL_rsfp) { |
7396 | s = filter_gets(PL_linestr, PL_rsfp, 0); | |
7397 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr); | |
7398 | PL_bufend = PL_bufptr + SvCUR(PL_linestr); | |
207e3d1a | 7399 | PL_last_lop = PL_last_uni = Nullch; |
79072805 | 7400 | if (!s) { |
3280af22 | 7401 | s = PL_bufptr; |
79072805 | 7402 | yyerror("Format not terminated"); |
378cc40b LW |
7403 | break; |
7404 | } | |
378cc40b | 7405 | } |
463ee0b2 | 7406 | incline(s); |
79072805 | 7407 | } |
a0d0e21e LW |
7408 | enough: |
7409 | if (SvCUR(stuff)) { | |
3280af22 | 7410 | PL_expect = XTERM; |
79072805 | 7411 | if (needargs) { |
3280af22 NIS |
7412 | PL_lex_state = LEX_NORMAL; |
7413 | PL_nextval[PL_nexttoke].ival = 0; | |
79072805 LW |
7414 | force_next(','); |
7415 | } | |
a0d0e21e | 7416 | else |
3280af22 NIS |
7417 | PL_lex_state = LEX_FORMLINE; |
7418 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff); | |
79072805 | 7419 | force_next(THING); |
3280af22 | 7420 | PL_nextval[PL_nexttoke].ival = OP_FORMLINE; |
79072805 | 7421 | force_next(LSTOP); |
378cc40b | 7422 | } |
79072805 | 7423 | else { |
8990e307 | 7424 | SvREFCNT_dec(stuff); |
3280af22 NIS |
7425 | PL_lex_formbrack = 0; |
7426 | PL_bufptr = s; | |
79072805 LW |
7427 | } |
7428 | return s; | |
378cc40b | 7429 | } |
a687059c | 7430 | |
76e3520e | 7431 | STATIC void |
cea2e8a9 | 7432 | S_set_csh(pTHX) |
a687059c | 7433 | { |
ae986130 | 7434 | #ifdef CSH |
3280af22 NIS |
7435 | if (!PL_cshlen) |
7436 | PL_cshlen = strlen(PL_cshname); | |
ae986130 | 7437 | #endif |
a687059c | 7438 | } |
463ee0b2 | 7439 | |
ba6d6ac9 | 7440 | I32 |
864dbfa3 | 7441 | Perl_start_subparse(pTHX_ I32 is_format, U32 flags) |
8990e307 | 7442 | { |
3280af22 NIS |
7443 | I32 oldsavestack_ix = PL_savestack_ix; |
7444 | CV* outsidecv = PL_compcv; | |
748a9306 | 7445 | AV* comppadlist; |
8990e307 | 7446 | |
3280af22 NIS |
7447 | if (PL_compcv) { |
7448 | assert(SvTYPE(PL_compcv) == SVt_PVCV); | |
e9a444f0 | 7449 | } |
7766f137 | 7450 | SAVEI32(PL_subline); |
3280af22 NIS |
7451 | save_item(PL_subname); |
7452 | SAVEI32(PL_padix); | |
354992b1 | 7453 | SAVECOMPPAD(); |
3280af22 NIS |
7454 | SAVESPTR(PL_comppad_name); |
7455 | SAVESPTR(PL_compcv); | |
7456 | SAVEI32(PL_comppad_name_fill); | |
7457 | SAVEI32(PL_min_intro_pending); | |
7458 | SAVEI32(PL_max_intro_pending); | |
7459 | SAVEI32(PL_pad_reset_pending); | |
7460 | ||
7461 | PL_compcv = (CV*)NEWSV(1104,0); | |
7462 | sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV); | |
7463 | CvFLAGS(PL_compcv) |= flags; | |
7464 | ||
7465 | PL_comppad = newAV(); | |
7466 | av_push(PL_comppad, Nullsv); | |
7467 | PL_curpad = AvARRAY(PL_comppad); | |
7468 | PL_comppad_name = newAV(); | |
7469 | PL_comppad_name_fill = 0; | |
7470 | PL_min_intro_pending = 0; | |
7471 | PL_padix = 0; | |
57843af0 | 7472 | PL_subline = CopLINE(PL_curcop); |
4d1ff10f | 7473 | #ifdef USE_5005THREADS |
79cb57f6 | 7474 | av_store(PL_comppad_name, 0, newSVpvn("@_", 2)); |
533c011a NIS |
7475 | PL_curpad[0] = (SV*)newAV(); |
7476 | SvPADMY_on(PL_curpad[0]); /* XXX Needed? */ | |
4d1ff10f | 7477 | #endif /* USE_5005THREADS */ |
748a9306 LW |
7478 | |
7479 | comppadlist = newAV(); | |
7480 | AvREAL_off(comppadlist); | |
3280af22 NIS |
7481 | av_store(comppadlist, 0, (SV*)PL_comppad_name); |
7482 | av_store(comppadlist, 1, (SV*)PL_comppad); | |
748a9306 | 7483 | |
3280af22 NIS |
7484 | CvPADLIST(PL_compcv) = comppadlist; |
7485 | CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv); | |
4d1ff10f | 7486 | #ifdef USE_5005THREADS |
533c011a NIS |
7487 | CvOWNER(PL_compcv) = 0; |
7488 | New(666, CvMUTEXP(PL_compcv), 1, perl_mutex); | |
7489 | MUTEX_INIT(CvMUTEXP(PL_compcv)); | |
4d1ff10f | 7490 | #endif /* USE_5005THREADS */ |
748a9306 | 7491 | |
8990e307 LW |
7492 | return oldsavestack_ix; |
7493 | } | |
7494 | ||
084592ab CN |
7495 | #ifdef __SC__ |
7496 | #pragma segment Perl_yylex | |
7497 | #endif | |
8990e307 | 7498 | int |
864dbfa3 | 7499 | Perl_yywarn(pTHX_ char *s) |
8990e307 | 7500 | { |
faef0170 | 7501 | PL_in_eval |= EVAL_WARNONLY; |
748a9306 | 7502 | yyerror(s); |
faef0170 | 7503 | PL_in_eval &= ~EVAL_WARNONLY; |
748a9306 | 7504 | return 0; |
8990e307 LW |
7505 | } |
7506 | ||
7507 | int | |
864dbfa3 | 7508 | Perl_yyerror(pTHX_ char *s) |
463ee0b2 | 7509 | { |
68dc0745 | 7510 | char *where = NULL; |
7511 | char *context = NULL; | |
7512 | int contlen = -1; | |
46fc3d4c | 7513 | SV *msg; |
463ee0b2 | 7514 | |
3280af22 | 7515 | if (!yychar || (yychar == ';' && !PL_rsfp)) |
54310121 | 7516 | where = "at EOF"; |
3280af22 NIS |
7517 | else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 && |
7518 | PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) { | |
7519 | while (isSPACE(*PL_oldoldbufptr)) | |
7520 | PL_oldoldbufptr++; | |
7521 | context = PL_oldoldbufptr; | |
7522 | contlen = PL_bufptr - PL_oldoldbufptr; | |
463ee0b2 | 7523 | } |
3280af22 NIS |
7524 | else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 && |
7525 | PL_oldbufptr != PL_bufptr) { | |
7526 | while (isSPACE(*PL_oldbufptr)) | |
7527 | PL_oldbufptr++; | |
7528 | context = PL_oldbufptr; | |
7529 | contlen = PL_bufptr - PL_oldbufptr; | |
463ee0b2 LW |
7530 | } |
7531 | else if (yychar > 255) | |
68dc0745 | 7532 | where = "next token ???"; |
cdfb297e GS |
7533 | #ifdef USE_PURE_BISON |
7534 | /* GNU Bison sets the value -2 */ | |
7535 | else if (yychar == -2) { | |
7536 | #else | |
463ee0b2 | 7537 | else if ((yychar & 127) == 127) { |
cdfb297e | 7538 | #endif |
3280af22 NIS |
7539 | if (PL_lex_state == LEX_NORMAL || |
7540 | (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL)) | |
68dc0745 | 7541 | where = "at end of line"; |
3280af22 | 7542 | else if (PL_lex_inpat) |
68dc0745 | 7543 | where = "within pattern"; |
463ee0b2 | 7544 | else |
68dc0745 | 7545 | where = "within string"; |
463ee0b2 | 7546 | } |
46fc3d4c | 7547 | else { |
79cb57f6 | 7548 | SV *where_sv = sv_2mortal(newSVpvn("next char ", 10)); |
46fc3d4c | 7549 | if (yychar < 32) |
cea2e8a9 | 7550 | Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar)); |
46fc3d4c | 7551 | else if (isPRINT_LC(yychar)) |
cea2e8a9 | 7552 | Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar); |
463ee0b2 | 7553 | else |
cea2e8a9 | 7554 | Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255); |
46fc3d4c | 7555 | where = SvPVX(where_sv); |
463ee0b2 | 7556 | } |
46fc3d4c | 7557 | msg = sv_2mortal(newSVpv(s, 0)); |
ed094faf GS |
7558 | Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ", |
7559 | CopFILE(PL_curcop), (IV)CopLINE(PL_curcop)); | |
68dc0745 | 7560 | if (context) |
cea2e8a9 | 7561 | Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context); |
463ee0b2 | 7562 | else |
cea2e8a9 | 7563 | Perl_sv_catpvf(aTHX_ msg, "%s\n", where); |
57843af0 | 7564 | if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) { |
cf2093f6 | 7565 | Perl_sv_catpvf(aTHX_ msg, |
57def98f | 7566 | " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n", |
cf2093f6 | 7567 | (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start); |
3280af22 | 7568 | PL_multi_end = 0; |
a0d0e21e | 7569 | } |
faef0170 | 7570 | if (PL_in_eval & EVAL_WARNONLY) |
894356b3 | 7571 | Perl_warn(aTHX_ "%"SVf, msg); |
463ee0b2 | 7572 | else |
5a844595 | 7573 | qerror(msg); |
c7d6bfb2 GS |
7574 | if (PL_error_count >= 10) { |
7575 | if (PL_in_eval && SvCUR(ERRSV)) | |
d2560b70 | 7576 | Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n", |
c7d6bfb2 GS |
7577 | ERRSV, CopFILE(PL_curcop)); |
7578 | else | |
7579 | Perl_croak(aTHX_ "%s has too many errors.\n", | |
7580 | CopFILE(PL_curcop)); | |
7581 | } | |
3280af22 NIS |
7582 | PL_in_my = 0; |
7583 | PL_in_my_stash = Nullhv; | |
463ee0b2 LW |
7584 | return 0; |
7585 | } | |
084592ab CN |
7586 | #ifdef __SC__ |
7587 | #pragma segment Main | |
7588 | #endif | |
4e35701f | 7589 | |
b250498f | 7590 | STATIC char* |
3ae08724 | 7591 | S_swallow_bom(pTHX_ U8 *s) |
01ec43d0 | 7592 | { |
b250498f GS |
7593 | STRLEN slen; |
7594 | slen = SvCUR(PL_linestr); | |
7595 | switch (*s) { | |
4e553d73 NIS |
7596 | case 0xFF: |
7597 | if (s[1] == 0xFE) { | |
01ec43d0 | 7598 | /* UTF-16 little-endian */ |
3ae08724 | 7599 | if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */ |
01ec43d0 GS |
7600 | Perl_croak(aTHX_ "Unsupported script encoding"); |
7601 | #ifndef PERL_NO_UTF16_FILTER | |
dea0fc0b | 7602 | DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-LE script encoding\n")); |
3ae08724 | 7603 | s += 2; |
dea0fc0b JH |
7604 | if (PL_bufend > (char*)s) { |
7605 | U8 *news; | |
7606 | I32 newlen; | |
7607 | ||
7608 | filter_add(utf16rev_textfilter, NULL); | |
7609 | New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8); | |
f72f5f89 JH |
7610 | PL_bufend = (char*)utf16_to_utf8_reversed(s, news, |
7611 | PL_bufend - (char*)s - 1, | |
dea0fc0b JH |
7612 | &newlen); |
7613 | Copy(news, s, newlen, U8); | |
7614 | SvCUR_set(PL_linestr, newlen); | |
7615 | PL_bufend = SvPVX(PL_linestr) + newlen; | |
7616 | news[newlen++] = '\0'; | |
7617 | Safefree(news); | |
7618 | } | |
b250498f | 7619 | #else |
01ec43d0 | 7620 | Perl_croak(aTHX_ "Unsupported script encoding"); |
b250498f | 7621 | #endif |
01ec43d0 GS |
7622 | } |
7623 | break; | |
78ae23f5 | 7624 | case 0xFE: |
3ae08724 | 7625 | if (s[1] == 0xFF) { /* UTF-16 big-endian */ |
01ec43d0 | 7626 | #ifndef PERL_NO_UTF16_FILTER |
dea0fc0b JH |
7627 | DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding\n")); |
7628 | s += 2; | |
7629 | if (PL_bufend > (char *)s) { | |
7630 | U8 *news; | |
7631 | I32 newlen; | |
7632 | ||
7633 | filter_add(utf16_textfilter, NULL); | |
7634 | New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8); | |
7635 | PL_bufend = (char*)utf16_to_utf8(s, news, | |
7636 | PL_bufend - (char*)s, | |
7637 | &newlen); | |
7638 | Copy(news, s, newlen, U8); | |
7639 | SvCUR_set(PL_linestr, newlen); | |
7640 | PL_bufend = SvPVX(PL_linestr) + newlen; | |
7641 | news[newlen++] = '\0'; | |
7642 | Safefree(news); | |
7643 | } | |
b250498f | 7644 | #else |
01ec43d0 | 7645 | Perl_croak(aTHX_ "Unsupported script encoding"); |
b250498f | 7646 | #endif |
01ec43d0 GS |
7647 | } |
7648 | break; | |
3ae08724 GS |
7649 | case 0xEF: |
7650 | if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) { | |
dea0fc0b | 7651 | DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-8 script encoding\n")); |
01ec43d0 GS |
7652 | s += 3; /* UTF-8 */ |
7653 | } | |
7654 | break; | |
7655 | case 0: | |
7656 | if (slen > 3 && s[1] == 0 && /* UTF-32 big-endian */ | |
3ae08724 | 7657 | s[2] == 0xFE && s[3] == 0xFF) |
01ec43d0 GS |
7658 | { |
7659 | Perl_croak(aTHX_ "Unsupported script encoding"); | |
7660 | } | |
7661 | } | |
b8f84bb2 | 7662 | return (char*)s; |
b250498f | 7663 | } |
4755096e | 7664 | |
4755096e GS |
7665 | /* |
7666 | * restore_rsfp | |
7667 | * Restore a source filter. | |
7668 | */ | |
7669 | ||
7670 | static void | |
acfe0abc | 7671 | restore_rsfp(pTHX_ void *f) |
4755096e GS |
7672 | { |
7673 | PerlIO *fp = (PerlIO*)f; | |
7674 | ||
7675 | if (PL_rsfp == PerlIO_stdin()) | |
7676 | PerlIO_clearerr(PL_rsfp); | |
7677 | else if (PL_rsfp && (PL_rsfp != fp)) | |
7678 | PerlIO_close(PL_rsfp); | |
7679 | PL_rsfp = fp; | |
7680 | } | |
6e3aabd6 GS |
7681 | |
7682 | #ifndef PERL_NO_UTF16_FILTER | |
7683 | static I32 | |
acfe0abc | 7684 | utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
6e3aabd6 GS |
7685 | { |
7686 | I32 count = FILTER_READ(idx+1, sv, maxlen); | |
7687 | if (count) { | |
7688 | U8* tmps; | |
7689 | U8* tend; | |
dea0fc0b | 7690 | I32 newlen; |
6e3aabd6 | 7691 | New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8); |
f72f5f89 JH |
7692 | if (!*SvPV_nolen(sv)) |
7693 | /* Game over, but don't feed an odd-length string to utf16_to_utf8 */ | |
7694 | return count; | |
4e553d73 | 7695 | |
dea0fc0b | 7696 | tend = utf16_to_utf8((U8*)SvPVX(sv), tmps, SvCUR(sv), &newlen); |
6e3aabd6 GS |
7697 | sv_usepvn(sv, (char*)tmps, tend - tmps); |
7698 | } | |
7699 | return count; | |
7700 | } | |
7701 | ||
7702 | static I32 | |
acfe0abc | 7703 | utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
6e3aabd6 GS |
7704 | { |
7705 | I32 count = FILTER_READ(idx+1, sv, maxlen); | |
7706 | if (count) { | |
7707 | U8* tmps; | |
7708 | U8* tend; | |
dea0fc0b | 7709 | I32 newlen; |
f72f5f89 JH |
7710 | if (!*SvPV_nolen(sv)) |
7711 | /* Game over, but don't feed an odd-length string to utf16_to_utf8 */ | |
7712 | return count; | |
7713 | ||
6e3aabd6 | 7714 | New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8); |
dea0fc0b | 7715 | tend = utf16_to_utf8_reversed((U8*)SvPVX(sv), tmps, SvCUR(sv), &newlen); |
6e3aabd6 GS |
7716 | sv_usepvn(sv, (char*)tmps, tend - tmps); |
7717 | } | |
7718 | return count; | |
7719 | } | |
7720 | #endif |