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