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