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