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