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