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