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