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 SC |
187 | SV *report; |
188 | DEBUG_T({ | |
189 | report = newSVpv(thing, 0); | |
29b291f7 RB |
190 | Perl_sv_catpvf(aTHX_ report, ":line %d:%"IVdf":", CopLINE(PL_curcop), |
191 | (IV)rv); | |
998054bd SC |
192 | |
193 | if (s - PL_bufptr > 0) | |
194 | sv_catpvn(report, PL_bufptr, s - PL_bufptr); | |
195 | else { | |
196 | if (PL_oldbufptr && *PL_oldbufptr) | |
197 | sv_catpv(report, PL_tokenbuf); | |
198 | } | |
199 | PerlIO_printf(Perl_debug_log, "### %s\n", SvPV_nolen(report)); | |
200 | }) | |
201 | } | |
202 | ||
ffb4593c NT |
203 | /* |
204 | * S_ao | |
205 | * | |
206 | * This subroutine detects &&= and ||= and turns an ANDAND or OROR | |
207 | * into an OP_ANDASSIGN or OP_ORASSIGN | |
208 | */ | |
209 | ||
76e3520e | 210 | STATIC int |
cea2e8a9 | 211 | S_ao(pTHX_ int toketype) |
a0d0e21e | 212 | { |
3280af22 NIS |
213 | if (*PL_bufptr == '=') { |
214 | PL_bufptr++; | |
a0d0e21e LW |
215 | if (toketype == ANDAND) |
216 | yylval.ival = OP_ANDASSIGN; | |
217 | else if (toketype == OROR) | |
218 | yylval.ival = OP_ORASSIGN; | |
219 | toketype = ASSIGNOP; | |
220 | } | |
221 | return toketype; | |
222 | } | |
223 | ||
ffb4593c NT |
224 | /* |
225 | * S_no_op | |
226 | * When Perl expects an operator and finds something else, no_op | |
227 | * prints the warning. It always prints "<something> found where | |
228 | * operator expected. It prints "Missing semicolon on previous line?" | |
229 | * if the surprise occurs at the start of the line. "do you need to | |
230 | * predeclare ..." is printed out for code like "sub bar; foo bar $x" | |
231 | * where the compiler doesn't know if foo is a method call or a function. | |
232 | * It prints "Missing operator before end of line" if there's nothing | |
233 | * after the missing operator, or "... before <...>" if there is something | |
234 | * after the missing operator. | |
235 | */ | |
236 | ||
76e3520e | 237 | STATIC void |
cea2e8a9 | 238 | S_no_op(pTHX_ char *what, char *s) |
463ee0b2 | 239 | { |
3280af22 NIS |
240 | char *oldbp = PL_bufptr; |
241 | bool is_first = (PL_oldbufptr == PL_linestart); | |
68dc0745 | 242 | |
1189a94a GS |
243 | if (!s) |
244 | s = oldbp; | |
07c798fb | 245 | else |
1189a94a | 246 | PL_bufptr = s; |
cea2e8a9 | 247 | yywarn(Perl_form(aTHX_ "%s found where operator expected", what)); |
748a9306 | 248 | if (is_first) |
cea2e8a9 | 249 | Perl_warn(aTHX_ "\t(Missing semicolon on previous line?)\n"); |
7e2040f0 | 250 | else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) { |
748a9306 | 251 | char *t; |
7e2040f0 | 252 | for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ; |
3280af22 | 253 | if (t < PL_bufptr && isSPACE(*t)) |
cea2e8a9 | 254 | Perl_warn(aTHX_ "\t(Do you need to predeclare %.*s?)\n", |
3280af22 | 255 | t - PL_oldoldbufptr, PL_oldoldbufptr); |
748a9306 | 256 | } |
07c798fb HS |
257 | else { |
258 | assert(s >= oldbp); | |
cea2e8a9 | 259 | Perl_warn(aTHX_ "\t(Missing operator before %.*s?)\n", s - oldbp, oldbp); |
07c798fb | 260 | } |
3280af22 | 261 | PL_bufptr = oldbp; |
8990e307 LW |
262 | } |
263 | ||
ffb4593c NT |
264 | /* |
265 | * S_missingterm | |
266 | * Complain about missing quote/regexp/heredoc terminator. | |
267 | * If it's called with (char *)NULL then it cauterizes the line buffer. | |
268 | * If we're in a delimited string and the delimiter is a control | |
269 | * character, it's reformatted into a two-char sequence like ^C. | |
270 | * This is fatal. | |
271 | */ | |
272 | ||
76e3520e | 273 | STATIC void |
cea2e8a9 | 274 | S_missingterm(pTHX_ char *s) |
8990e307 LW |
275 | { |
276 | char tmpbuf[3]; | |
277 | char q; | |
278 | if (s) { | |
279 | char *nl = strrchr(s,'\n'); | |
d2719217 | 280 | if (nl) |
8990e307 LW |
281 | *nl = '\0'; |
282 | } | |
9d116dd7 JH |
283 | else if ( |
284 | #ifdef EBCDIC | |
285 | iscntrl(PL_multi_close) | |
286 | #else | |
287 | PL_multi_close < 32 || PL_multi_close == 127 | |
288 | #endif | |
289 | ) { | |
8990e307 | 290 | *tmpbuf = '^'; |
3280af22 | 291 | tmpbuf[1] = toCTRL(PL_multi_close); |
8990e307 LW |
292 | s = "\\n"; |
293 | tmpbuf[2] = '\0'; | |
294 | s = tmpbuf; | |
295 | } | |
296 | else { | |
3280af22 | 297 | *tmpbuf = PL_multi_close; |
8990e307 LW |
298 | tmpbuf[1] = '\0'; |
299 | s = tmpbuf; | |
300 | } | |
301 | q = strchr(s,'"') ? '\'' : '"'; | |
cea2e8a9 | 302 | Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q); |
463ee0b2 | 303 | } |
79072805 | 304 | |
ffb4593c NT |
305 | /* |
306 | * Perl_deprecate | |
ffb4593c NT |
307 | */ |
308 | ||
79072805 | 309 | void |
864dbfa3 | 310 | Perl_deprecate(pTHX_ char *s) |
a0d0e21e | 311 | { |
599cee73 | 312 | if (ckWARN(WARN_DEPRECATED)) |
cea2e8a9 | 313 | Perl_warner(aTHX_ WARN_DEPRECATED, "Use of %s is deprecated", s); |
a0d0e21e LW |
314 | } |
315 | ||
ffb4593c NT |
316 | /* |
317 | * depcom | |
9cbb5ea2 | 318 | * Deprecate a comma-less variable list. |
ffb4593c NT |
319 | */ |
320 | ||
76e3520e | 321 | STATIC void |
cea2e8a9 | 322 | S_depcom(pTHX) |
a0d0e21e LW |
323 | { |
324 | deprecate("comma-less variable list"); | |
325 | } | |
326 | ||
ffb4593c | 327 | /* |
9cbb5ea2 GS |
328 | * experimental text filters for win32 carriage-returns, utf16-to-utf8 and |
329 | * utf16-to-utf8-reversed. | |
ffb4593c NT |
330 | */ |
331 | ||
c39cd008 GS |
332 | #ifdef PERL_CR_FILTER |
333 | static void | |
334 | strip_return(SV *sv) | |
335 | { | |
336 | register char *s = SvPVX(sv); | |
337 | register char *e = s + SvCUR(sv); | |
338 | /* outer loop optimized to do nothing if there are no CR-LFs */ | |
339 | while (s < e) { | |
340 | if (*s++ == '\r' && *s == '\n') { | |
341 | /* hit a CR-LF, need to copy the rest */ | |
342 | register char *d = s - 1; | |
343 | *d++ = *s++; | |
344 | while (s < e) { | |
345 | if (*s == '\r' && s[1] == '\n') | |
346 | s++; | |
347 | *d++ = *s++; | |
348 | } | |
349 | SvCUR(sv) -= s - d; | |
350 | return; | |
351 | } | |
352 | } | |
353 | } | |
a868473f | 354 | |
76e3520e | 355 | STATIC I32 |
c39cd008 | 356 | S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
a868473f | 357 | { |
c39cd008 GS |
358 | I32 count = FILTER_READ(idx+1, sv, maxlen); |
359 | if (count > 0 && !maxlen) | |
360 | strip_return(sv); | |
361 | return count; | |
a868473f NIS |
362 | } |
363 | #endif | |
364 | ||
ffb4593c NT |
365 | /* |
366 | * Perl_lex_start | |
9cbb5ea2 GS |
367 | * Initialize variables. Uses the Perl save_stack to save its state (for |
368 | * recursive calls to the parser). | |
ffb4593c NT |
369 | */ |
370 | ||
a0d0e21e | 371 | void |
864dbfa3 | 372 | Perl_lex_start(pTHX_ SV *line) |
79072805 | 373 | { |
8990e307 LW |
374 | char *s; |
375 | STRLEN len; | |
376 | ||
3280af22 NIS |
377 | SAVEI32(PL_lex_dojoin); |
378 | SAVEI32(PL_lex_brackets); | |
3280af22 NIS |
379 | SAVEI32(PL_lex_casemods); |
380 | SAVEI32(PL_lex_starts); | |
381 | SAVEI32(PL_lex_state); | |
7766f137 | 382 | SAVEVPTR(PL_lex_inpat); |
3280af22 | 383 | SAVEI32(PL_lex_inwhat); |
18b09519 GS |
384 | if (PL_lex_state == LEX_KNOWNEXT) { |
385 | I32 toke = PL_nexttoke; | |
386 | while (--toke >= 0) { | |
387 | SAVEI32(PL_nexttype[toke]); | |
388 | SAVEVPTR(PL_nextval[toke]); | |
389 | } | |
390 | SAVEI32(PL_nexttoke); | |
18b09519 | 391 | } |
57843af0 | 392 | SAVECOPLINE(PL_curcop); |
3280af22 NIS |
393 | SAVEPPTR(PL_bufptr); |
394 | SAVEPPTR(PL_bufend); | |
395 | SAVEPPTR(PL_oldbufptr); | |
396 | SAVEPPTR(PL_oldoldbufptr); | |
207e3d1a JH |
397 | SAVEPPTR(PL_last_lop); |
398 | SAVEPPTR(PL_last_uni); | |
3280af22 NIS |
399 | SAVEPPTR(PL_linestart); |
400 | SAVESPTR(PL_linestr); | |
401 | SAVEPPTR(PL_lex_brackstack); | |
402 | SAVEPPTR(PL_lex_casestack); | |
c76ac1ee | 403 | SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp); |
3280af22 NIS |
404 | SAVESPTR(PL_lex_stuff); |
405 | SAVEI32(PL_lex_defer); | |
09bef843 | 406 | SAVEI32(PL_sublex_info.sub_inwhat); |
3280af22 | 407 | SAVESPTR(PL_lex_repl); |
bebdddfc GS |
408 | SAVEINT(PL_expect); |
409 | SAVEINT(PL_lex_expect); | |
3280af22 NIS |
410 | |
411 | PL_lex_state = LEX_NORMAL; | |
412 | PL_lex_defer = 0; | |
413 | PL_expect = XSTATE; | |
414 | PL_lex_brackets = 0; | |
3280af22 NIS |
415 | New(899, PL_lex_brackstack, 120, char); |
416 | New(899, PL_lex_casestack, 12, char); | |
417 | SAVEFREEPV(PL_lex_brackstack); | |
418 | SAVEFREEPV(PL_lex_casestack); | |
419 | PL_lex_casemods = 0; | |
420 | *PL_lex_casestack = '\0'; | |
421 | PL_lex_dojoin = 0; | |
422 | PL_lex_starts = 0; | |
423 | PL_lex_stuff = Nullsv; | |
424 | PL_lex_repl = Nullsv; | |
425 | PL_lex_inpat = 0; | |
76be56bc | 426 | PL_nexttoke = 0; |
3280af22 | 427 | PL_lex_inwhat = 0; |
09bef843 | 428 | PL_sublex_info.sub_inwhat = 0; |
3280af22 NIS |
429 | PL_linestr = line; |
430 | if (SvREADONLY(PL_linestr)) | |
431 | PL_linestr = sv_2mortal(newSVsv(PL_linestr)); | |
432 | s = SvPV(PL_linestr, len); | |
8990e307 | 433 | if (len && s[len-1] != ';') { |
3280af22 NIS |
434 | if (!(SvFLAGS(PL_linestr) & SVs_TEMP)) |
435 | PL_linestr = sv_2mortal(newSVsv(PL_linestr)); | |
436 | sv_catpvn(PL_linestr, "\n;", 2); | |
8990e307 | 437 | } |
3280af22 NIS |
438 | SvTEMP_off(PL_linestr); |
439 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr); | |
440 | PL_bufend = PL_bufptr + SvCUR(PL_linestr); | |
207e3d1a | 441 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 442 | SvREFCNT_dec(PL_rs); |
79cb57f6 | 443 | PL_rs = newSVpvn("\n", 1); |
3280af22 | 444 | PL_rsfp = 0; |
79072805 | 445 | } |
a687059c | 446 | |
ffb4593c NT |
447 | /* |
448 | * Perl_lex_end | |
9cbb5ea2 GS |
449 | * Finalizer for lexing operations. Must be called when the parser is |
450 | * done with the lexer. | |
ffb4593c NT |
451 | */ |
452 | ||
463ee0b2 | 453 | void |
864dbfa3 | 454 | Perl_lex_end(pTHX) |
463ee0b2 | 455 | { |
3280af22 | 456 | PL_doextract = FALSE; |
463ee0b2 LW |
457 | } |
458 | ||
ffb4593c NT |
459 | /* |
460 | * S_incline | |
461 | * This subroutine has nothing to do with tilting, whether at windmills | |
462 | * or pinball tables. Its name is short for "increment line". It | |
57843af0 | 463 | * increments the current line number in CopLINE(PL_curcop) and checks |
ffb4593c | 464 | * to see whether the line starts with a comment of the form |
9cbb5ea2 GS |
465 | * # line 500 "foo.pm" |
466 | * If so, it sets the current line number and file to the values in the comment. | |
ffb4593c NT |
467 | */ |
468 | ||
76e3520e | 469 | STATIC void |
cea2e8a9 | 470 | S_incline(pTHX_ char *s) |
463ee0b2 LW |
471 | { |
472 | char *t; | |
473 | char *n; | |
73659bf1 | 474 | char *e; |
463ee0b2 | 475 | char ch; |
463ee0b2 | 476 | |
57843af0 | 477 | CopLINE_inc(PL_curcop); |
463ee0b2 LW |
478 | if (*s++ != '#') |
479 | return; | |
bf4acbe4 | 480 | while (SPACE_OR_TAB(*s)) s++; |
73659bf1 GS |
481 | if (strnEQ(s, "line", 4)) |
482 | s += 4; | |
483 | else | |
484 | return; | |
084592ab | 485 | if (SPACE_OR_TAB(*s)) |
73659bf1 | 486 | s++; |
4e553d73 | 487 | else |
73659bf1 | 488 | return; |
bf4acbe4 | 489 | while (SPACE_OR_TAB(*s)) s++; |
463ee0b2 LW |
490 | if (!isDIGIT(*s)) |
491 | return; | |
492 | n = s; | |
493 | while (isDIGIT(*s)) | |
494 | s++; | |
bf4acbe4 | 495 | while (SPACE_OR_TAB(*s)) |
463ee0b2 | 496 | s++; |
73659bf1 | 497 | if (*s == '"' && (t = strchr(s+1, '"'))) { |
463ee0b2 | 498 | s++; |
73659bf1 GS |
499 | e = t + 1; |
500 | } | |
463ee0b2 | 501 | else { |
463ee0b2 | 502 | for (t = s; !isSPACE(*t); t++) ; |
73659bf1 | 503 | e = t; |
463ee0b2 | 504 | } |
bf4acbe4 | 505 | while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f') |
73659bf1 GS |
506 | e++; |
507 | if (*e != '\n' && *e != '\0') | |
508 | return; /* false alarm */ | |
509 | ||
463ee0b2 LW |
510 | ch = *t; |
511 | *t = '\0'; | |
f4dd75d9 GS |
512 | if (t - s > 0) { |
513 | #ifdef USE_ITHREADS | |
514 | Safefree(CopFILE(PL_curcop)); | |
515 | #else | |
516 | SvREFCNT_dec(CopFILEGV(PL_curcop)); | |
517 | #endif | |
57843af0 | 518 | CopFILE_set(PL_curcop, s); |
f4dd75d9 | 519 | } |
463ee0b2 | 520 | *t = ch; |
57843af0 | 521 | CopLINE_set(PL_curcop, atoi(n)-1); |
463ee0b2 LW |
522 | } |
523 | ||
ffb4593c NT |
524 | /* |
525 | * S_skipspace | |
526 | * Called to gobble the appropriate amount and type of whitespace. | |
527 | * Skips comments as well. | |
528 | */ | |
529 | ||
76e3520e | 530 | STATIC char * |
cea2e8a9 | 531 | S_skipspace(pTHX_ register char *s) |
a687059c | 532 | { |
3280af22 | 533 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
bf4acbe4 | 534 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
463ee0b2 LW |
535 | s++; |
536 | return s; | |
537 | } | |
538 | for (;;) { | |
fd049845 | 539 | STRLEN prevlen; |
09bef843 SB |
540 | SSize_t oldprevlen, oldoldprevlen; |
541 | SSize_t oldloplen, oldunilen; | |
60e6418e GS |
542 | while (s < PL_bufend && isSPACE(*s)) { |
543 | if (*s++ == '\n' && PL_in_eval && !PL_rsfp) | |
544 | incline(s); | |
545 | } | |
ffb4593c NT |
546 | |
547 | /* comment */ | |
3280af22 NIS |
548 | if (s < PL_bufend && *s == '#') { |
549 | while (s < PL_bufend && *s != '\n') | |
463ee0b2 | 550 | s++; |
60e6418e | 551 | if (s < PL_bufend) { |
463ee0b2 | 552 | s++; |
60e6418e GS |
553 | if (PL_in_eval && !PL_rsfp) { |
554 | incline(s); | |
555 | continue; | |
556 | } | |
557 | } | |
463ee0b2 | 558 | } |
ffb4593c NT |
559 | |
560 | /* only continue to recharge the buffer if we're at the end | |
561 | * of the buffer, we're not reading from a source filter, and | |
562 | * we're in normal lexing mode | |
563 | */ | |
09bef843 SB |
564 | if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat || |
565 | PL_lex_state == LEX_FORMLINE) | |
463ee0b2 | 566 | return s; |
ffb4593c NT |
567 | |
568 | /* try to recharge the buffer */ | |
9cbb5ea2 GS |
569 | if ((s = filter_gets(PL_linestr, PL_rsfp, |
570 | (prevlen = SvCUR(PL_linestr)))) == Nullch) | |
571 | { | |
572 | /* end of file. Add on the -p or -n magic */ | |
3280af22 NIS |
573 | if (PL_minus_n || PL_minus_p) { |
574 | sv_setpv(PL_linestr,PL_minus_p ? | |
08e9d68e DD |
575 | ";}continue{print or die qq(-p destination: $!\\n)" : |
576 | ""); | |
3280af22 NIS |
577 | sv_catpv(PL_linestr,";}"); |
578 | PL_minus_n = PL_minus_p = 0; | |
a0d0e21e LW |
579 | } |
580 | else | |
3280af22 | 581 | sv_setpv(PL_linestr,";"); |
ffb4593c NT |
582 | |
583 | /* reset variables for next time we lex */ | |
9cbb5ea2 GS |
584 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart |
585 | = SvPVX(PL_linestr); | |
3280af22 | 586 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 587 | PL_last_lop = PL_last_uni = Nullch; |
ffb4593c NT |
588 | |
589 | /* Close the filehandle. Could be from -P preprocessor, | |
590 | * STDIN, or a regular file. If we were reading code from | |
591 | * STDIN (because the commandline held no -e or filename) | |
592 | * then we don't close it, we reset it so the code can | |
593 | * read from STDIN too. | |
594 | */ | |
595 | ||
3280af22 NIS |
596 | if (PL_preprocess && !PL_in_eval) |
597 | (void)PerlProc_pclose(PL_rsfp); | |
598 | else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) | |
599 | PerlIO_clearerr(PL_rsfp); | |
8990e307 | 600 | else |
3280af22 NIS |
601 | (void)PerlIO_close(PL_rsfp); |
602 | PL_rsfp = Nullfp; | |
463ee0b2 LW |
603 | return s; |
604 | } | |
ffb4593c NT |
605 | |
606 | /* not at end of file, so we only read another line */ | |
09bef843 SB |
607 | /* make corresponding updates to old pointers, for yyerror() */ |
608 | oldprevlen = PL_oldbufptr - PL_bufend; | |
609 | oldoldprevlen = PL_oldoldbufptr - PL_bufend; | |
610 | if (PL_last_uni) | |
611 | oldunilen = PL_last_uni - PL_bufend; | |
612 | if (PL_last_lop) | |
613 | oldloplen = PL_last_lop - PL_bufend; | |
3280af22 NIS |
614 | PL_linestart = PL_bufptr = s + prevlen; |
615 | PL_bufend = s + SvCUR(PL_linestr); | |
616 | s = PL_bufptr; | |
09bef843 SB |
617 | PL_oldbufptr = s + oldprevlen; |
618 | PL_oldoldbufptr = s + oldoldprevlen; | |
619 | if (PL_last_uni) | |
620 | PL_last_uni = s + oldunilen; | |
621 | if (PL_last_lop) | |
622 | PL_last_lop = s + oldloplen; | |
a0d0e21e | 623 | incline(s); |
ffb4593c NT |
624 | |
625 | /* debugger active and we're not compiling the debugger code, | |
626 | * so store the line into the debugger's array of lines | |
627 | */ | |
3280af22 | 628 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
8990e307 LW |
629 | SV *sv = NEWSV(85,0); |
630 | ||
631 | sv_upgrade(sv, SVt_PVMG); | |
3280af22 | 632 | sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr); |
57843af0 | 633 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
8990e307 | 634 | } |
463ee0b2 | 635 | } |
a687059c | 636 | } |
378cc40b | 637 | |
ffb4593c NT |
638 | /* |
639 | * S_check_uni | |
640 | * Check the unary operators to ensure there's no ambiguity in how they're | |
641 | * used. An ambiguous piece of code would be: | |
642 | * rand + 5 | |
643 | * This doesn't mean rand() + 5. Because rand() is a unary operator, | |
644 | * the +5 is its argument. | |
645 | */ | |
646 | ||
76e3520e | 647 | STATIC void |
cea2e8a9 | 648 | S_check_uni(pTHX) |
ba106d47 | 649 | { |
2f3197b3 | 650 | char *s; |
a0d0e21e | 651 | char *t; |
2f3197b3 | 652 | |
3280af22 | 653 | if (PL_oldoldbufptr != PL_last_uni) |
2f3197b3 | 654 | return; |
3280af22 NIS |
655 | while (isSPACE(*PL_last_uni)) |
656 | PL_last_uni++; | |
7e2040f0 | 657 | for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ; |
3280af22 | 658 | if ((t = strchr(s, '(')) && t < PL_bufptr) |
a0d0e21e | 659 | return; |
0453d815 | 660 | if (ckWARN_d(WARN_AMBIGUOUS)){ |
f248d071 | 661 | char ch = *s; |
0453d815 | 662 | *s = '\0'; |
4e553d73 NIS |
663 | Perl_warner(aTHX_ WARN_AMBIGUOUS, |
664 | "Warning: Use of \"%s\" without parens is ambiguous", | |
0453d815 PM |
665 | PL_last_uni); |
666 | *s = ch; | |
667 | } | |
2f3197b3 LW |
668 | } |
669 | ||
ffb4593c NT |
670 | /* workaround to replace the UNI() macro with a function. Only the |
671 | * hints/uts.sh file mentions this. Other comments elsewhere in the | |
672 | * source indicate Microport Unix might need it too. | |
673 | */ | |
674 | ||
ffed7fef LW |
675 | #ifdef CRIPPLED_CC |
676 | ||
677 | #undef UNI | |
ffed7fef | 678 | #define UNI(f) return uni(f,s) |
ffed7fef | 679 | |
76e3520e | 680 | STATIC int |
cea2e8a9 | 681 | S_uni(pTHX_ I32 f, char *s) |
ffed7fef LW |
682 | { |
683 | yylval.ival = f; | |
3280af22 NIS |
684 | PL_expect = XTERM; |
685 | PL_bufptr = s; | |
8f872242 NIS |
686 | PL_last_uni = PL_oldbufptr; |
687 | PL_last_lop_op = f; | |
ffed7fef LW |
688 | if (*s == '(') |
689 | return FUNC1; | |
690 | s = skipspace(s); | |
691 | if (*s == '(') | |
692 | return FUNC1; | |
693 | else | |
694 | return UNIOP; | |
695 | } | |
696 | ||
a0d0e21e LW |
697 | #endif /* CRIPPLED_CC */ |
698 | ||
ffb4593c NT |
699 | /* |
700 | * LOP : macro to build a list operator. Its behaviour has been replaced | |
701 | * with a subroutine, S_lop() for which LOP is just another name. | |
702 | */ | |
703 | ||
a0d0e21e LW |
704 | #define LOP(f,x) return lop(f,x,s) |
705 | ||
ffb4593c NT |
706 | /* |
707 | * S_lop | |
708 | * Build a list operator (or something that might be one). The rules: | |
709 | * - if we have a next token, then it's a list operator [why?] | |
710 | * - if the next thing is an opening paren, then it's a function | |
711 | * - else it's a list operator | |
712 | */ | |
713 | ||
76e3520e | 714 | STATIC I32 |
a0be28da | 715 | S_lop(pTHX_ I32 f, int x, char *s) |
ffed7fef | 716 | { |
79072805 | 717 | yylval.ival = f; |
35c8bce7 | 718 | CLINE; |
075953c3 | 719 | REPORT("lop", f) |
3280af22 NIS |
720 | PL_expect = x; |
721 | PL_bufptr = s; | |
722 | PL_last_lop = PL_oldbufptr; | |
723 | PL_last_lop_op = f; | |
724 | if (PL_nexttoke) | |
a0d0e21e | 725 | return LSTOP; |
79072805 LW |
726 | if (*s == '(') |
727 | return FUNC; | |
728 | s = skipspace(s); | |
729 | if (*s == '(') | |
730 | return FUNC; | |
731 | else | |
732 | return LSTOP; | |
733 | } | |
734 | ||
ffb4593c NT |
735 | /* |
736 | * S_force_next | |
9cbb5ea2 | 737 | * When the lexer realizes it knows the next token (for instance, |
ffb4593c | 738 | * it is reordering tokens for the parser) then it can call S_force_next |
9cbb5ea2 GS |
739 | * to know what token to return the next time the lexer is called. Caller |
740 | * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer | |
741 | * handles the token correctly. | |
ffb4593c NT |
742 | */ |
743 | ||
4e553d73 | 744 | STATIC void |
cea2e8a9 | 745 | S_force_next(pTHX_ I32 type) |
79072805 | 746 | { |
3280af22 NIS |
747 | PL_nexttype[PL_nexttoke] = type; |
748 | PL_nexttoke++; | |
749 | if (PL_lex_state != LEX_KNOWNEXT) { | |
750 | PL_lex_defer = PL_lex_state; | |
751 | PL_lex_expect = PL_expect; | |
752 | PL_lex_state = LEX_KNOWNEXT; | |
79072805 LW |
753 | } |
754 | } | |
755 | ||
ffb4593c NT |
756 | /* |
757 | * S_force_word | |
758 | * When the lexer knows the next thing is a word (for instance, it has | |
759 | * just seen -> and it knows that the next char is a word char, then | |
760 | * it calls S_force_word to stick the next word into the PL_next lookahead. | |
761 | * | |
762 | * Arguments: | |
b1b65b59 | 763 | * char *start : buffer position (must be within PL_linestr) |
ffb4593c NT |
764 | * int token : PL_next will be this type of bare word (e.g., METHOD,WORD) |
765 | * int check_keyword : if true, Perl checks to make sure the word isn't | |
766 | * a keyword (do this if the word is a label, e.g. goto FOO) | |
767 | * int allow_pack : if true, : characters will also be allowed (require, | |
768 | * use, etc. do this) | |
9cbb5ea2 | 769 | * int allow_initial_tick : used by the "sub" lexer only. |
ffb4593c NT |
770 | */ |
771 | ||
76e3520e | 772 | STATIC char * |
cea2e8a9 | 773 | S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick) |
79072805 | 774 | { |
463ee0b2 LW |
775 | register char *s; |
776 | STRLEN len; | |
4e553d73 | 777 | |
463ee0b2 LW |
778 | start = skipspace(start); |
779 | s = start; | |
7e2040f0 | 780 | if (isIDFIRST_lazy_if(s,UTF) || |
a0d0e21e | 781 | (allow_pack && *s == ':') || |
15f0808c | 782 | (allow_initial_tick && *s == '\'') ) |
a0d0e21e | 783 | { |
3280af22 NIS |
784 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len); |
785 | if (check_keyword && keyword(PL_tokenbuf, len)) | |
463ee0b2 LW |
786 | return start; |
787 | if (token == METHOD) { | |
788 | s = skipspace(s); | |
789 | if (*s == '(') | |
3280af22 | 790 | PL_expect = XTERM; |
463ee0b2 | 791 | else { |
3280af22 | 792 | PL_expect = XOPERATOR; |
463ee0b2 | 793 | } |
79072805 | 794 | } |
3280af22 NIS |
795 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(PL_tokenbuf,0)); |
796 | PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE; | |
79072805 LW |
797 | force_next(token); |
798 | } | |
799 | return s; | |
800 | } | |
801 | ||
ffb4593c NT |
802 | /* |
803 | * S_force_ident | |
9cbb5ea2 | 804 | * Called when the lexer wants $foo *foo &foo etc, but the program |
ffb4593c NT |
805 | * text only contains the "foo" portion. The first argument is a pointer |
806 | * to the "foo", and the second argument is the type symbol to prefix. | |
807 | * Forces the next token to be a "WORD". | |
9cbb5ea2 | 808 | * Creates the symbol if it didn't already exist (via gv_fetchpv()). |
ffb4593c NT |
809 | */ |
810 | ||
76e3520e | 811 | STATIC void |
cea2e8a9 | 812 | S_force_ident(pTHX_ register char *s, int kind) |
79072805 LW |
813 | { |
814 | if (s && *s) { | |
11343788 | 815 | OP* o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0)); |
3280af22 | 816 | PL_nextval[PL_nexttoke].opval = o; |
79072805 | 817 | force_next(WORD); |
748a9306 | 818 | if (kind) { |
11343788 | 819 | o->op_private = OPpCONST_ENTERED; |
55497cff | 820 | /* XXX see note in pp_entereval() for why we forgo typo |
821 | warnings if the symbol must be introduced in an eval. | |
822 | GSAR 96-10-12 */ | |
3280af22 | 823 | gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE, |
a0d0e21e LW |
824 | kind == '$' ? SVt_PV : |
825 | kind == '@' ? SVt_PVAV : | |
826 | kind == '%' ? SVt_PVHV : | |
827 | SVt_PVGV | |
828 | ); | |
748a9306 | 829 | } |
79072805 LW |
830 | } |
831 | } | |
832 | ||
1571675a GS |
833 | NV |
834 | Perl_str_to_version(pTHX_ SV *sv) | |
835 | { | |
836 | NV retval = 0.0; | |
837 | NV nshift = 1.0; | |
838 | STRLEN len; | |
839 | char *start = SvPVx(sv,len); | |
3aa33fe5 | 840 | bool utf = SvUTF8(sv) ? TRUE : FALSE; |
1571675a GS |
841 | char *end = start + len; |
842 | while (start < end) { | |
ba210ebe | 843 | STRLEN skip; |
1571675a GS |
844 | UV n; |
845 | if (utf) | |
9041c2e3 | 846 | n = utf8n_to_uvchr((U8*)start, len, &skip, 0); |
1571675a GS |
847 | else { |
848 | n = *(U8*)start; | |
849 | skip = 1; | |
850 | } | |
851 | retval += ((NV)n)/nshift; | |
852 | start += skip; | |
853 | nshift *= 1000; | |
854 | } | |
855 | return retval; | |
856 | } | |
857 | ||
4e553d73 | 858 | /* |
ffb4593c NT |
859 | * S_force_version |
860 | * Forces the next token to be a version number. | |
861 | */ | |
862 | ||
76e3520e | 863 | STATIC char * |
cea2e8a9 | 864 | S_force_version(pTHX_ char *s) |
89bfa8cd | 865 | { |
866 | OP *version = Nullop; | |
44dcb63b | 867 | char *d; |
89bfa8cd | 868 | |
869 | s = skipspace(s); | |
870 | ||
44dcb63b | 871 | d = s; |
dd629d5b | 872 | if (*d == 'v') |
44dcb63b | 873 | d++; |
44dcb63b | 874 | if (isDIGIT(*d)) { |
a7cb1f99 | 875 | for (; isDIGIT(*d) || *d == '_' || *d == '.'; d++); |
9f3d182e | 876 | if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) { |
dd629d5b | 877 | SV *ver; |
b73d6f50 | 878 | s = scan_num(s, &yylval); |
89bfa8cd | 879 | version = yylval.opval; |
dd629d5b GS |
880 | ver = cSVOPx(version)->op_sv; |
881 | if (SvPOK(ver) && !SvNIOK(ver)) { | |
155aba94 | 882 | (void)SvUPGRADE(ver, SVt_PVNV); |
1571675a GS |
883 | SvNVX(ver) = str_to_version(ver); |
884 | SvNOK_on(ver); /* hint that it is a version */ | |
44dcb63b | 885 | } |
89bfa8cd | 886 | } |
887 | } | |
888 | ||
889 | /* NOTE: The parser sees the package name and the VERSION swapped */ | |
3280af22 | 890 | PL_nextval[PL_nexttoke].opval = version; |
4e553d73 | 891 | force_next(WORD); |
89bfa8cd | 892 | |
893 | return (s); | |
894 | } | |
895 | ||
ffb4593c NT |
896 | /* |
897 | * S_tokeq | |
898 | * Tokenize a quoted string passed in as an SV. It finds the next | |
899 | * chunk, up to end of string or a backslash. It may make a new | |
900 | * SV containing that chunk (if HINT_NEW_STRING is on). It also | |
901 | * turns \\ into \. | |
902 | */ | |
903 | ||
76e3520e | 904 | STATIC SV * |
cea2e8a9 | 905 | S_tokeq(pTHX_ SV *sv) |
79072805 LW |
906 | { |
907 | register char *s; | |
908 | register char *send; | |
909 | register char *d; | |
b3ac6de7 IZ |
910 | STRLEN len = 0; |
911 | SV *pv = sv; | |
79072805 LW |
912 | |
913 | if (!SvLEN(sv)) | |
b3ac6de7 | 914 | goto finish; |
79072805 | 915 | |
a0d0e21e | 916 | s = SvPV_force(sv, len); |
21a311ee | 917 | if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1) |
b3ac6de7 | 918 | goto finish; |
463ee0b2 | 919 | send = s + len; |
79072805 LW |
920 | while (s < send && *s != '\\') |
921 | s++; | |
922 | if (s == send) | |
b3ac6de7 | 923 | goto finish; |
79072805 | 924 | d = s; |
be4731d2 | 925 | if ( PL_hints & HINT_NEW_STRING ) { |
79cb57f6 | 926 | pv = sv_2mortal(newSVpvn(SvPVX(pv), len)); |
be4731d2 NIS |
927 | if (SvUTF8(sv)) |
928 | SvUTF8_on(pv); | |
929 | } | |
79072805 LW |
930 | while (s < send) { |
931 | if (*s == '\\') { | |
a0d0e21e | 932 | if (s + 1 < send && (s[1] == '\\')) |
79072805 LW |
933 | s++; /* all that, just for this */ |
934 | } | |
935 | *d++ = *s++; | |
936 | } | |
937 | *d = '\0'; | |
463ee0b2 | 938 | SvCUR_set(sv, d - SvPVX(sv)); |
b3ac6de7 | 939 | finish: |
3280af22 | 940 | if ( PL_hints & HINT_NEW_STRING ) |
b3ac6de7 | 941 | return new_constant(NULL, 0, "q", sv, pv, "q"); |
79072805 LW |
942 | return sv; |
943 | } | |
944 | ||
ffb4593c NT |
945 | /* |
946 | * Now come three functions related to double-quote context, | |
947 | * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when | |
948 | * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They | |
949 | * interact with PL_lex_state, and create fake ( ... ) argument lists | |
950 | * to handle functions and concatenation. | |
951 | * They assume that whoever calls them will be setting up a fake | |
952 | * join call, because each subthing puts a ',' after it. This lets | |
953 | * "lower \luPpEr" | |
954 | * become | |
955 | * join($, , 'lower ', lcfirst( 'uPpEr', ) ,) | |
956 | * | |
957 | * (I'm not sure whether the spurious commas at the end of lcfirst's | |
958 | * arguments and join's arguments are created or not). | |
959 | */ | |
960 | ||
961 | /* | |
962 | * S_sublex_start | |
963 | * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST). | |
964 | * | |
965 | * Pattern matching will set PL_lex_op to the pattern-matching op to | |
966 | * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise). | |
967 | * | |
968 | * OP_CONST and OP_READLINE are easy--just make the new op and return. | |
969 | * | |
970 | * Everything else becomes a FUNC. | |
971 | * | |
972 | * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we | |
973 | * had an OP_CONST or OP_READLINE). This just sets us up for a | |
974 | * call to S_sublex_push(). | |
975 | */ | |
976 | ||
76e3520e | 977 | STATIC I32 |
cea2e8a9 | 978 | S_sublex_start(pTHX) |
79072805 LW |
979 | { |
980 | register I32 op_type = yylval.ival; | |
79072805 LW |
981 | |
982 | if (op_type == OP_NULL) { | |
3280af22 NIS |
983 | yylval.opval = PL_lex_op; |
984 | PL_lex_op = Nullop; | |
79072805 LW |
985 | return THING; |
986 | } | |
987 | if (op_type == OP_CONST || op_type == OP_READLINE) { | |
3280af22 | 988 | SV *sv = tokeq(PL_lex_stuff); |
b3ac6de7 IZ |
989 | |
990 | if (SvTYPE(sv) == SVt_PVIV) { | |
991 | /* Overloaded constants, nothing fancy: Convert to SVt_PV: */ | |
992 | STRLEN len; | |
993 | char *p; | |
994 | SV *nsv; | |
995 | ||
996 | p = SvPV(sv, len); | |
79cb57f6 | 997 | nsv = newSVpvn(p, len); |
01ec43d0 GS |
998 | if (SvUTF8(sv)) |
999 | SvUTF8_on(nsv); | |
b3ac6de7 IZ |
1000 | SvREFCNT_dec(sv); |
1001 | sv = nsv; | |
4e553d73 | 1002 | } |
b3ac6de7 | 1003 | yylval.opval = (OP*)newSVOP(op_type, 0, sv); |
3280af22 | 1004 | PL_lex_stuff = Nullsv; |
79072805 LW |
1005 | return THING; |
1006 | } | |
1007 | ||
3280af22 NIS |
1008 | PL_sublex_info.super_state = PL_lex_state; |
1009 | PL_sublex_info.sub_inwhat = op_type; | |
1010 | PL_sublex_info.sub_op = PL_lex_op; | |
1011 | PL_lex_state = LEX_INTERPPUSH; | |
55497cff | 1012 | |
3280af22 NIS |
1013 | PL_expect = XTERM; |
1014 | if (PL_lex_op) { | |
1015 | yylval.opval = PL_lex_op; | |
1016 | PL_lex_op = Nullop; | |
55497cff | 1017 | return PMFUNC; |
1018 | } | |
1019 | else | |
1020 | return FUNC; | |
1021 | } | |
1022 | ||
ffb4593c NT |
1023 | /* |
1024 | * S_sublex_push | |
1025 | * Create a new scope to save the lexing state. The scope will be | |
1026 | * ended in S_sublex_done. Returns a '(', starting the function arguments | |
1027 | * to the uc, lc, etc. found before. | |
1028 | * Sets PL_lex_state to LEX_INTERPCONCAT. | |
1029 | */ | |
1030 | ||
76e3520e | 1031 | STATIC I32 |
cea2e8a9 | 1032 | S_sublex_push(pTHX) |
55497cff | 1033 | { |
f46d017c | 1034 | ENTER; |
55497cff | 1035 | |
3280af22 NIS |
1036 | PL_lex_state = PL_sublex_info.super_state; |
1037 | SAVEI32(PL_lex_dojoin); | |
1038 | SAVEI32(PL_lex_brackets); | |
3280af22 NIS |
1039 | SAVEI32(PL_lex_casemods); |
1040 | SAVEI32(PL_lex_starts); | |
1041 | SAVEI32(PL_lex_state); | |
7766f137 | 1042 | SAVEVPTR(PL_lex_inpat); |
3280af22 | 1043 | SAVEI32(PL_lex_inwhat); |
57843af0 | 1044 | SAVECOPLINE(PL_curcop); |
3280af22 NIS |
1045 | SAVEPPTR(PL_bufptr); |
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, '}'); | |
adaeee49 | 1441 | if (!e) { |
a0ed51b3 | 1442 | yyerror("Missing right brace on \\x{}"); |
adaeee49 GA |
1443 | e = s; |
1444 | } | |
89491803 | 1445 | else { |
ba210ebe JH |
1446 | STRLEN len = 1; /* allow underscores */ |
1447 | uv = (UV)scan_hex(s + 1, e - s - 1, &len); | |
1448 | } | |
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 NIS |
1636 | if (SvCUR(sv) >= SvLEN(sv)) |
1637 | Perl_croak(aTHX_ "panic:constant overflowed allocated space"); | |
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++; |
463ee0b2 | 2850 | incline(s); |
3280af22 NIS |
2851 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
2852 | PL_bufptr = s; | |
2853 | PL_lex_state = LEX_FORMLINE; | |
cea2e8a9 | 2854 | return yylex(); |
a687059c | 2855 | } |
378cc40b | 2856 | } |
a687059c | 2857 | else { |
378cc40b | 2858 | *s = '\0'; |
3280af22 | 2859 | PL_bufend = s; |
a687059c | 2860 | } |
378cc40b LW |
2861 | goto retry; |
2862 | case '-': | |
79072805 | 2863 | if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) { |
e5edeb50 JH |
2864 | I32 ftst = 0; |
2865 | ||
378cc40b | 2866 | s++; |
3280af22 | 2867 | PL_bufptr = s; |
748a9306 LW |
2868 | tmp = *s++; |
2869 | ||
bf4acbe4 | 2870 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
748a9306 LW |
2871 | s++; |
2872 | ||
2873 | if (strnEQ(s,"=>",2)) { | |
3280af22 | 2874 | s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE); |
4e553d73 | 2875 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
607df283 SC |
2876 | "### Saw unary minus before =>, forcing word '%s'\n", s); |
2877 | } ) | |
748a9306 LW |
2878 | OPERATOR('-'); /* unary minus */ |
2879 | } | |
3280af22 | 2880 | PL_last_uni = PL_oldbufptr; |
748a9306 | 2881 | switch (tmp) { |
e5edeb50 JH |
2882 | case 'r': ftst = OP_FTEREAD; break; |
2883 | case 'w': ftst = OP_FTEWRITE; break; | |
2884 | case 'x': ftst = OP_FTEEXEC; break; | |
2885 | case 'o': ftst = OP_FTEOWNED; break; | |
2886 | case 'R': ftst = OP_FTRREAD; break; | |
2887 | case 'W': ftst = OP_FTRWRITE; break; | |
2888 | case 'X': ftst = OP_FTREXEC; break; | |
2889 | case 'O': ftst = OP_FTROWNED; break; | |
2890 | case 'e': ftst = OP_FTIS; break; | |
2891 | case 'z': ftst = OP_FTZERO; break; | |
2892 | case 's': ftst = OP_FTSIZE; break; | |
2893 | case 'f': ftst = OP_FTFILE; break; | |
2894 | case 'd': ftst = OP_FTDIR; break; | |
2895 | case 'l': ftst = OP_FTLINK; break; | |
2896 | case 'p': ftst = OP_FTPIPE; break; | |
2897 | case 'S': ftst = OP_FTSOCK; break; | |
2898 | case 'u': ftst = OP_FTSUID; break; | |
2899 | case 'g': ftst = OP_FTSGID; break; | |
2900 | case 'k': ftst = OP_FTSVTX; break; | |
2901 | case 'b': ftst = OP_FTBLK; break; | |
2902 | case 'c': ftst = OP_FTCHR; break; | |
2903 | case 't': ftst = OP_FTTTY; break; | |
2904 | case 'T': ftst = OP_FTTEXT; break; | |
2905 | case 'B': ftst = OP_FTBINARY; break; | |
2906 | case 'M': case 'A': case 'C': | |
2907 | gv_fetchpv("\024",TRUE, SVt_PV); | |
2908 | switch (tmp) { | |
2909 | case 'M': ftst = OP_FTMTIME; break; | |
2910 | case 'A': ftst = OP_FTATIME; break; | |
2911 | case 'C': ftst = OP_FTCTIME; break; | |
2912 | default: break; | |
2913 | } | |
2914 | break; | |
378cc40b | 2915 | default: |
378cc40b LW |
2916 | break; |
2917 | } | |
e5edeb50 JH |
2918 | if (ftst) { |
2919 | PL_last_lop_op = ftst; | |
4e553d73 | 2920 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
0844c848 | 2921 | "### Saw file test %c\n", (int)ftst); |
e5edeb50 | 2922 | } ) |
e5edeb50 JH |
2923 | FTST(ftst); |
2924 | } | |
2925 | else { | |
2926 | /* Assume it was a minus followed by a one-letter named | |
2927 | * subroutine call (or a -bareword), then. */ | |
95c31fe3 | 2928 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
0844c848 RB |
2929 | "### %c looked like a file test but was not\n", |
2930 | (int)ftst); | |
95c31fe3 | 2931 | } ) |
e5edeb50 JH |
2932 | s -= 2; |
2933 | } | |
378cc40b | 2934 | } |
a687059c LW |
2935 | tmp = *s++; |
2936 | if (*s == tmp) { | |
2937 | s++; | |
3280af22 | 2938 | if (PL_expect == XOPERATOR) |
79072805 LW |
2939 | TERM(POSTDEC); |
2940 | else | |
2941 | OPERATOR(PREDEC); | |
2942 | } | |
2943 | else if (*s == '>') { | |
2944 | s++; | |
2945 | s = skipspace(s); | |
7e2040f0 | 2946 | if (isIDFIRST_lazy_if(s,UTF)) { |
a0d0e21e | 2947 | s = force_word(s,METHOD,FALSE,TRUE,FALSE); |
463ee0b2 | 2948 | TOKEN(ARROW); |
79072805 | 2949 | } |
748a9306 LW |
2950 | else if (*s == '$') |
2951 | OPERATOR(ARROW); | |
463ee0b2 | 2952 | else |
748a9306 | 2953 | TERM(ARROW); |
a687059c | 2954 | } |
3280af22 | 2955 | if (PL_expect == XOPERATOR) |
79072805 LW |
2956 | Aop(OP_SUBTRACT); |
2957 | else { | |
3280af22 | 2958 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) |
2f3197b3 | 2959 | check_uni(); |
79072805 | 2960 | OPERATOR('-'); /* unary minus */ |
2f3197b3 | 2961 | } |
79072805 | 2962 | |
378cc40b | 2963 | case '+': |
a687059c LW |
2964 | tmp = *s++; |
2965 | if (*s == tmp) { | |
378cc40b | 2966 | s++; |
3280af22 | 2967 | if (PL_expect == XOPERATOR) |
79072805 LW |
2968 | TERM(POSTINC); |
2969 | else | |
2970 | OPERATOR(PREINC); | |
378cc40b | 2971 | } |
3280af22 | 2972 | if (PL_expect == XOPERATOR) |
79072805 LW |
2973 | Aop(OP_ADD); |
2974 | else { | |
3280af22 | 2975 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) |
2f3197b3 | 2976 | check_uni(); |
a687059c | 2977 | OPERATOR('+'); |
2f3197b3 | 2978 | } |
a687059c | 2979 | |
378cc40b | 2980 | case '*': |
3280af22 NIS |
2981 | if (PL_expect != XOPERATOR) { |
2982 | s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); | |
2983 | PL_expect = XOPERATOR; | |
2984 | force_ident(PL_tokenbuf, '*'); | |
2985 | if (!*PL_tokenbuf) | |
a0d0e21e | 2986 | PREREF('*'); |
79072805 | 2987 | TERM('*'); |
a687059c | 2988 | } |
79072805 LW |
2989 | s++; |
2990 | if (*s == '*') { | |
a687059c | 2991 | s++; |
79072805 | 2992 | PWop(OP_POW); |
a687059c | 2993 | } |
79072805 LW |
2994 | Mop(OP_MULTIPLY); |
2995 | ||
378cc40b | 2996 | case '%': |
3280af22 | 2997 | if (PL_expect == XOPERATOR) { |
bbce6d69 | 2998 | ++s; |
2999 | Mop(OP_MODULO); | |
a687059c | 3000 | } |
3280af22 NIS |
3001 | PL_tokenbuf[0] = '%'; |
3002 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE); | |
3003 | if (!PL_tokenbuf[1]) { | |
3004 | if (s == PL_bufend) | |
bbce6d69 | 3005 | yyerror("Final % should be \\% or %name"); |
3006 | PREREF('%'); | |
a687059c | 3007 | } |
3280af22 | 3008 | PL_pending_ident = '%'; |
bbce6d69 | 3009 | TERM('%'); |
a687059c | 3010 | |
378cc40b | 3011 | case '^': |
79072805 | 3012 | s++; |
a0d0e21e | 3013 | BOop(OP_BIT_XOR); |
79072805 | 3014 | case '[': |
3280af22 | 3015 | PL_lex_brackets++; |
79072805 | 3016 | /* FALL THROUGH */ |
378cc40b | 3017 | case '~': |
378cc40b | 3018 | case ',': |
378cc40b LW |
3019 | tmp = *s++; |
3020 | OPERATOR(tmp); | |
a0d0e21e LW |
3021 | case ':': |
3022 | if (s[1] == ':') { | |
3023 | len = 0; | |
3024 | goto just_a_word; | |
3025 | } | |
3026 | s++; | |
09bef843 SB |
3027 | switch (PL_expect) { |
3028 | OP *attrs; | |
3029 | case XOPERATOR: | |
3030 | if (!PL_in_my || PL_lex_state != LEX_NORMAL) | |
3031 | break; | |
3032 | PL_bufptr = s; /* update in case we back off */ | |
3033 | goto grabattrs; | |
3034 | case XATTRBLOCK: | |
3035 | PL_expect = XBLOCK; | |
3036 | goto grabattrs; | |
3037 | case XATTRTERM: | |
3038 | PL_expect = XTERMBLOCK; | |
3039 | grabattrs: | |
3040 | s = skipspace(s); | |
3041 | attrs = Nullop; | |
7e2040f0 | 3042 | while (isIDFIRST_lazy_if(s,UTF)) { |
09bef843 | 3043 | d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
f9829d6b GS |
3044 | if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) { |
3045 | if (tmp < 0) tmp = -tmp; | |
3046 | switch (tmp) { | |
3047 | case KEY_or: | |
3048 | case KEY_and: | |
3049 | case KEY_for: | |
3050 | case KEY_unless: | |
3051 | case KEY_if: | |
3052 | case KEY_while: | |
3053 | case KEY_until: | |
3054 | goto got_attrs; | |
3055 | default: | |
3056 | break; | |
3057 | } | |
3058 | } | |
09bef843 SB |
3059 | if (*d == '(') { |
3060 | d = scan_str(d,TRUE,TRUE); | |
3061 | if (!d) { | |
09bef843 SB |
3062 | /* MUST advance bufptr here to avoid bogus |
3063 | "at end of line" context messages from yyerror(). | |
3064 | */ | |
3065 | PL_bufptr = s + len; | |
3066 | yyerror("Unterminated attribute parameter in attribute list"); | |
3067 | if (attrs) | |
3068 | op_free(attrs); | |
3069 | return 0; /* EOF indicator */ | |
3070 | } | |
3071 | } | |
3072 | if (PL_lex_stuff) { | |
3073 | SV *sv = newSVpvn(s, len); | |
3074 | sv_catsv(sv, PL_lex_stuff); | |
3075 | attrs = append_elem(OP_LIST, attrs, | |
3076 | newSVOP(OP_CONST, 0, sv)); | |
3077 | SvREFCNT_dec(PL_lex_stuff); | |
3078 | PL_lex_stuff = Nullsv; | |
3079 | } | |
3080 | else { | |
78f9721b SM |
3081 | if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len)) |
3082 | CvLVALUE_on(PL_compcv); | |
3083 | else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len)) | |
3084 | CvLOCKED_on(PL_compcv); | |
3085 | else if (!PL_in_my && len == 6 && strnEQ(s, "method", len)) | |
3086 | CvMETHOD_on(PL_compcv); | |
87ecf892 DM |
3087 | #ifdef USE_ITHREADS |
3088 | else if (PL_in_my == KEY_our && len == 6 && strnEQ(s, "shared", len)) | |
3089 | GvSHARED_on(cGVOPx_gv(yylval.opval)); | |
3090 | #endif | |
78f9721b SM |
3091 | /* After we've set the flags, it could be argued that |
3092 | we don't need to do the attributes.pm-based setting | |
3093 | process, and shouldn't bother appending recognized | |
3094 | flags. To experiment with that, uncomment the | |
3095 | following "else": */ | |
0256094b | 3096 | else |
78f9721b SM |
3097 | attrs = append_elem(OP_LIST, attrs, |
3098 | newSVOP(OP_CONST, 0, | |
3099 | newSVpvn(s, len))); | |
09bef843 SB |
3100 | } |
3101 | s = skipspace(d); | |
0120eecf | 3102 | if (*s == ':' && s[1] != ':') |
09bef843 | 3103 | s = skipspace(s+1); |
0120eecf GS |
3104 | else if (s == d) |
3105 | break; /* require real whitespace or :'s */ | |
09bef843 | 3106 | } |
f9829d6b GS |
3107 | tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */ |
3108 | if (*s != ';' && *s != tmp && (tmp != '=' || *s != ')')) { | |
09bef843 SB |
3109 | char q = ((*s == '\'') ? '"' : '\''); |
3110 | /* If here for an expression, and parsed no attrs, back off. */ | |
3111 | if (tmp == '=' && !attrs) { | |
3112 | s = PL_bufptr; | |
3113 | break; | |
3114 | } | |
3115 | /* MUST advance bufptr here to avoid bogus "at end of line" | |
3116 | context messages from yyerror(). | |
3117 | */ | |
3118 | PL_bufptr = s; | |
3119 | if (!*s) | |
3120 | yyerror("Unterminated attribute list"); | |
3121 | else | |
3122 | yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list", | |
3123 | q, *s, q)); | |
3124 | if (attrs) | |
3125 | op_free(attrs); | |
3126 | OPERATOR(':'); | |
3127 | } | |
f9829d6b | 3128 | got_attrs: |
09bef843 SB |
3129 | if (attrs) { |
3130 | PL_nextval[PL_nexttoke].opval = attrs; | |
3131 | force_next(THING); | |
3132 | } | |
3133 | TOKEN(COLONATTR); | |
3134 | } | |
a0d0e21e | 3135 | OPERATOR(':'); |
8990e307 LW |
3136 | case '(': |
3137 | s++; | |
3280af22 NIS |
3138 | if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr) |
3139 | PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */ | |
a0d0e21e | 3140 | else |
3280af22 | 3141 | PL_expect = XTERM; |
a0d0e21e | 3142 | TOKEN('('); |
378cc40b | 3143 | case ';': |
f4dd75d9 | 3144 | CLINE; |
378cc40b LW |
3145 | tmp = *s++; |
3146 | OPERATOR(tmp); | |
3147 | case ')': | |
378cc40b | 3148 | tmp = *s++; |
16d20bd9 AD |
3149 | s = skipspace(s); |
3150 | if (*s == '{') | |
3151 | PREBLOCK(tmp); | |
378cc40b | 3152 | TERM(tmp); |
79072805 LW |
3153 | case ']': |
3154 | s++; | |
3280af22 | 3155 | if (PL_lex_brackets <= 0) |
d98d5fff | 3156 | yyerror("Unmatched right square bracket"); |
463ee0b2 | 3157 | else |
3280af22 NIS |
3158 | --PL_lex_brackets; |
3159 | if (PL_lex_state == LEX_INTERPNORMAL) { | |
3160 | if (PL_lex_brackets == 0) { | |
a0d0e21e | 3161 | if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>')) |
3280af22 | 3162 | PL_lex_state = LEX_INTERPEND; |
79072805 LW |
3163 | } |
3164 | } | |
4633a7c4 | 3165 | TERM(']'); |
79072805 LW |
3166 | case '{': |
3167 | leftbracket: | |
79072805 | 3168 | s++; |
3280af22 NIS |
3169 | if (PL_lex_brackets > 100) { |
3170 | char* newlb = Renew(PL_lex_brackstack, PL_lex_brackets + 1, char); | |
3171 | if (newlb != PL_lex_brackstack) { | |
8990e307 | 3172 | SAVEFREEPV(newlb); |
3280af22 | 3173 | PL_lex_brackstack = newlb; |
8990e307 LW |
3174 | } |
3175 | } | |
3280af22 | 3176 | switch (PL_expect) { |
a0d0e21e | 3177 | case XTERM: |
3280af22 | 3178 | if (PL_lex_formbrack) { |
a0d0e21e LW |
3179 | s--; |
3180 | PRETERMBLOCK(DO); | |
3181 | } | |
3280af22 NIS |
3182 | if (PL_oldoldbufptr == PL_last_lop) |
3183 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; | |
a0d0e21e | 3184 | else |
3280af22 | 3185 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
79072805 | 3186 | OPERATOR(HASHBRACK); |
a0d0e21e | 3187 | case XOPERATOR: |
bf4acbe4 | 3188 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
748a9306 | 3189 | s++; |
44a8e56a | 3190 | d = s; |
3280af22 NIS |
3191 | PL_tokenbuf[0] = '\0'; |
3192 | if (d < PL_bufend && *d == '-') { | |
3193 | PL_tokenbuf[0] = '-'; | |
44a8e56a | 3194 | d++; |
bf4acbe4 | 3195 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
44a8e56a | 3196 | d++; |
3197 | } | |
7e2040f0 | 3198 | if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) { |
3280af22 | 3199 | d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, |
8903cb82 | 3200 | FALSE, &len); |
bf4acbe4 | 3201 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
748a9306 LW |
3202 | d++; |
3203 | if (*d == '}') { | |
3280af22 | 3204 | char minus = (PL_tokenbuf[0] == '-'); |
44a8e56a | 3205 | s = force_word(s + minus, WORD, FALSE, TRUE, FALSE); |
3206 | if (minus) | |
3207 | force_next('-'); | |
748a9306 LW |
3208 | } |
3209 | } | |
3210 | /* FALL THROUGH */ | |
09bef843 | 3211 | case XATTRBLOCK: |
748a9306 | 3212 | case XBLOCK: |
3280af22 NIS |
3213 | PL_lex_brackstack[PL_lex_brackets++] = XSTATE; |
3214 | PL_expect = XSTATE; | |
a0d0e21e | 3215 | break; |
09bef843 | 3216 | case XATTRTERM: |
a0d0e21e | 3217 | case XTERMBLOCK: |
3280af22 NIS |
3218 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
3219 | PL_expect = XSTATE; | |
a0d0e21e LW |
3220 | break; |
3221 | default: { | |
3222 | char *t; | |
3280af22 NIS |
3223 | if (PL_oldoldbufptr == PL_last_lop) |
3224 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; | |
a0d0e21e | 3225 | else |
3280af22 | 3226 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
a0d0e21e | 3227 | s = skipspace(s); |
09ecc4b6 | 3228 | if (*s == '}') |
a0d0e21e | 3229 | OPERATOR(HASHBRACK); |
b8a4b1be GS |
3230 | /* This hack serves to disambiguate a pair of curlies |
3231 | * as being a block or an anon hash. Normally, expectation | |
3232 | * determines that, but in cases where we're not in a | |
3233 | * position to expect anything in particular (like inside | |
3234 | * eval"") we have to resolve the ambiguity. This code | |
3235 | * covers the case where the first term in the curlies is a | |
3236 | * quoted string. Most other cases need to be explicitly | |
3237 | * disambiguated by prepending a `+' before the opening | |
3238 | * curly in order to force resolution as an anon hash. | |
3239 | * | |
3240 | * XXX should probably propagate the outer expectation | |
3241 | * into eval"" to rely less on this hack, but that could | |
3242 | * potentially break current behavior of eval"". | |
3243 | * GSAR 97-07-21 | |
3244 | */ | |
3245 | t = s; | |
3246 | if (*s == '\'' || *s == '"' || *s == '`') { | |
3247 | /* common case: get past first string, handling escapes */ | |
3280af22 | 3248 | for (t++; t < PL_bufend && *t != *s;) |
b8a4b1be GS |
3249 | if (*t++ == '\\' && (*t == '\\' || *t == *s)) |
3250 | t++; | |
3251 | t++; | |
a0d0e21e | 3252 | } |
b8a4b1be | 3253 | else if (*s == 'q') { |
3280af22 | 3254 | if (++t < PL_bufend |
b8a4b1be | 3255 | && (!isALNUM(*t) |
3280af22 | 3256 | || ((*t == 'q' || *t == 'x') && ++t < PL_bufend |
0505442f GS |
3257 | && !isALNUM(*t)))) |
3258 | { | |
b8a4b1be GS |
3259 | char *tmps; |
3260 | char open, close, term; | |
3261 | I32 brackets = 1; | |
3262 | ||
3280af22 | 3263 | while (t < PL_bufend && isSPACE(*t)) |
b8a4b1be GS |
3264 | t++; |
3265 | term = *t; | |
3266 | open = term; | |
3267 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) | |
3268 | term = tmps[5]; | |
3269 | close = term; | |
3270 | if (open == close) | |
3280af22 NIS |
3271 | for (t++; t < PL_bufend; t++) { |
3272 | if (*t == '\\' && t+1 < PL_bufend && open != '\\') | |
b8a4b1be | 3273 | t++; |
6d07e5e9 | 3274 | else if (*t == open) |
b8a4b1be GS |
3275 | break; |
3276 | } | |
3277 | else | |
3280af22 NIS |
3278 | for (t++; t < PL_bufend; t++) { |
3279 | if (*t == '\\' && t+1 < PL_bufend) | |
b8a4b1be | 3280 | t++; |
6d07e5e9 | 3281 | else if (*t == close && --brackets <= 0) |
b8a4b1be GS |
3282 | break; |
3283 | else if (*t == open) | |
3284 | brackets++; | |
3285 | } | |
3286 | } | |
3287 | t++; | |
a0d0e21e | 3288 | } |
7e2040f0 | 3289 | else if (isALNUM_lazy_if(t,UTF)) { |
0505442f | 3290 | t += UTF8SKIP(t); |
7e2040f0 | 3291 | while (t < PL_bufend && isALNUM_lazy_if(t,UTF)) |
0505442f | 3292 | t += UTF8SKIP(t); |
a0d0e21e | 3293 | } |
3280af22 | 3294 | while (t < PL_bufend && isSPACE(*t)) |
a0d0e21e | 3295 | t++; |
b8a4b1be GS |
3296 | /* if comma follows first term, call it an anon hash */ |
3297 | /* XXX it could be a comma expression with loop modifiers */ | |
3280af22 | 3298 | if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s))) |
b8a4b1be | 3299 | || (*t == '=' && t[1] == '>'))) |
a0d0e21e | 3300 | OPERATOR(HASHBRACK); |
3280af22 | 3301 | if (PL_expect == XREF) |
4e4e412b | 3302 | PL_expect = XTERM; |
a0d0e21e | 3303 | else { |
3280af22 NIS |
3304 | PL_lex_brackstack[PL_lex_brackets-1] = XSTATE; |
3305 | PL_expect = XSTATE; | |
a0d0e21e | 3306 | } |
8990e307 | 3307 | } |
a0d0e21e | 3308 | break; |
463ee0b2 | 3309 | } |
57843af0 | 3310 | yylval.ival = CopLINE(PL_curcop); |
79072805 | 3311 | if (isSPACE(*s) || *s == '#') |
3280af22 | 3312 | PL_copline = NOLINE; /* invalidate current command line number */ |
79072805 | 3313 | TOKEN('{'); |
378cc40b | 3314 | case '}': |
79072805 LW |
3315 | rightbracket: |
3316 | s++; | |
3280af22 | 3317 | if (PL_lex_brackets <= 0) |
d98d5fff | 3318 | yyerror("Unmatched right curly bracket"); |
463ee0b2 | 3319 | else |
3280af22 | 3320 | PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets]; |
c2e66d9e | 3321 | if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL) |
3280af22 NIS |
3322 | PL_lex_formbrack = 0; |
3323 | if (PL_lex_state == LEX_INTERPNORMAL) { | |
3324 | if (PL_lex_brackets == 0) { | |
9059aa12 LW |
3325 | if (PL_expect & XFAKEBRACK) { |
3326 | PL_expect &= XENUMMASK; | |
3280af22 NIS |
3327 | PL_lex_state = LEX_INTERPEND; |
3328 | PL_bufptr = s; | |
cea2e8a9 | 3329 | return yylex(); /* ignore fake brackets */ |
79072805 | 3330 | } |
fa83b5b6 | 3331 | if (*s == '-' && s[1] == '>') |
3280af22 | 3332 | PL_lex_state = LEX_INTERPENDMAYBE; |
fa83b5b6 | 3333 | else if (*s != '[' && *s != '{') |
3280af22 | 3334 | PL_lex_state = LEX_INTERPEND; |
79072805 LW |
3335 | } |
3336 | } | |
9059aa12 LW |
3337 | if (PL_expect & XFAKEBRACK) { |
3338 | PL_expect &= XENUMMASK; | |
3280af22 | 3339 | PL_bufptr = s; |
cea2e8a9 | 3340 | return yylex(); /* ignore fake brackets */ |
748a9306 | 3341 | } |
79072805 LW |
3342 | force_next('}'); |
3343 | TOKEN(';'); | |
378cc40b LW |
3344 | case '&': |
3345 | s++; | |
3346 | tmp = *s++; | |
3347 | if (tmp == '&') | |
a0d0e21e | 3348 | AOPERATOR(ANDAND); |
378cc40b | 3349 | s--; |
3280af22 | 3350 | if (PL_expect == XOPERATOR) { |
7e2040f0 GS |
3351 | if (ckWARN(WARN_SEMICOLON) |
3352 | && isIDFIRST_lazy_if(s,UTF) && PL_bufptr == PL_linestart) | |
3353 | { | |
57843af0 | 3354 | CopLINE_dec(PL_curcop); |
cea2e8a9 | 3355 | Perl_warner(aTHX_ WARN_SEMICOLON, PL_warn_nosemi); |
57843af0 | 3356 | CopLINE_inc(PL_curcop); |
463ee0b2 | 3357 | } |
79072805 | 3358 | BAop(OP_BIT_AND); |
463ee0b2 | 3359 | } |
79072805 | 3360 | |
3280af22 NIS |
3361 | s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); |
3362 | if (*PL_tokenbuf) { | |
3363 | PL_expect = XOPERATOR; | |
3364 | force_ident(PL_tokenbuf, '&'); | |
463ee0b2 | 3365 | } |
79072805 LW |
3366 | else |
3367 | PREREF('&'); | |
c07a80fd | 3368 | yylval.ival = (OPpENTERSUB_AMPER<<8); |
79072805 LW |
3369 | TERM('&'); |
3370 | ||
378cc40b LW |
3371 | case '|': |
3372 | s++; | |
3373 | tmp = *s++; | |
3374 | if (tmp == '|') | |
a0d0e21e | 3375 | AOPERATOR(OROR); |
378cc40b | 3376 | s--; |
79072805 | 3377 | BOop(OP_BIT_OR); |
378cc40b LW |
3378 | case '=': |
3379 | s++; | |
3380 | tmp = *s++; | |
3381 | if (tmp == '=') | |
79072805 LW |
3382 | Eop(OP_EQ); |
3383 | if (tmp == '>') | |
3384 | OPERATOR(','); | |
378cc40b | 3385 | if (tmp == '~') |
79072805 | 3386 | PMop(OP_MATCH); |
599cee73 | 3387 | if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp)) |
cea2e8a9 | 3388 | Perl_warner(aTHX_ WARN_SYNTAX, "Reversed %c= operator",(int)tmp); |
378cc40b | 3389 | s--; |
3280af22 NIS |
3390 | if (PL_expect == XSTATE && isALPHA(tmp) && |
3391 | (s == PL_linestart+1 || s[-2] == '\n') ) | |
748a9306 | 3392 | { |
3280af22 NIS |
3393 | if (PL_in_eval && !PL_rsfp) { |
3394 | d = PL_bufend; | |
a5f75d66 AD |
3395 | while (s < d) { |
3396 | if (*s++ == '\n') { | |
3397 | incline(s); | |
3398 | if (strnEQ(s,"=cut",4)) { | |
3399 | s = strchr(s,'\n'); | |
3400 | if (s) | |
3401 | s++; | |
3402 | else | |
3403 | s = d; | |
3404 | incline(s); | |
3405 | goto retry; | |
3406 | } | |
3407 | } | |
3408 | } | |
3409 | goto retry; | |
3410 | } | |
3280af22 NIS |
3411 | s = PL_bufend; |
3412 | PL_doextract = TRUE; | |
a0d0e21e LW |
3413 | goto retry; |
3414 | } | |
3280af22 | 3415 | if (PL_lex_brackets < PL_lex_formbrack) { |
a0d0e21e | 3416 | char *t; |
51882d45 | 3417 | #ifdef PERL_STRICT_CR |
bf4acbe4 | 3418 | for (t = s; SPACE_OR_TAB(*t); t++) ; |
51882d45 | 3419 | #else |
bf4acbe4 | 3420 | for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ; |
51882d45 | 3421 | #endif |
a0d0e21e LW |
3422 | if (*t == '\n' || *t == '#') { |
3423 | s--; | |
3280af22 | 3424 | PL_expect = XBLOCK; |
a0d0e21e LW |
3425 | goto leftbracket; |
3426 | } | |
79072805 | 3427 | } |
a0d0e21e LW |
3428 | yylval.ival = 0; |
3429 | OPERATOR(ASSIGNOP); | |
378cc40b LW |
3430 | case '!': |
3431 | s++; | |
3432 | tmp = *s++; | |
3433 | if (tmp == '=') | |
79072805 | 3434 | Eop(OP_NE); |
378cc40b | 3435 | if (tmp == '~') |
79072805 | 3436 | PMop(OP_NOT); |
378cc40b LW |
3437 | s--; |
3438 | OPERATOR('!'); | |
3439 | case '<': | |
3280af22 | 3440 | if (PL_expect != XOPERATOR) { |
93a17b20 | 3441 | if (s[1] != '<' && !strchr(s,'>')) |
2f3197b3 | 3442 | check_uni(); |
79072805 LW |
3443 | if (s[1] == '<') |
3444 | s = scan_heredoc(s); | |
3445 | else | |
3446 | s = scan_inputsymbol(s); | |
3447 | TERM(sublex_start()); | |
378cc40b LW |
3448 | } |
3449 | s++; | |
3450 | tmp = *s++; | |
3451 | if (tmp == '<') | |
79072805 | 3452 | SHop(OP_LEFT_SHIFT); |
395c3793 LW |
3453 | if (tmp == '=') { |
3454 | tmp = *s++; | |
3455 | if (tmp == '>') | |
79072805 | 3456 | Eop(OP_NCMP); |
395c3793 | 3457 | s--; |
79072805 | 3458 | Rop(OP_LE); |
395c3793 | 3459 | } |
378cc40b | 3460 | s--; |
79072805 | 3461 | Rop(OP_LT); |
378cc40b LW |
3462 | case '>': |
3463 | s++; | |
3464 | tmp = *s++; | |
3465 | if (tmp == '>') | |
79072805 | 3466 | SHop(OP_RIGHT_SHIFT); |
378cc40b | 3467 | if (tmp == '=') |
79072805 | 3468 | Rop(OP_GE); |
378cc40b | 3469 | s--; |
79072805 | 3470 | Rop(OP_GT); |
378cc40b LW |
3471 | |
3472 | case '$': | |
bbce6d69 | 3473 | CLINE; |
3474 | ||
3280af22 NIS |
3475 | if (PL_expect == XOPERATOR) { |
3476 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3477 | PL_expect = XTERM; | |
a0d0e21e | 3478 | depcom(); |
bbce6d69 | 3479 | return ','; /* grandfather non-comma-format format */ |
a0d0e21e | 3480 | } |
8990e307 | 3481 | } |
a0d0e21e | 3482 | |
7e2040f0 | 3483 | if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) { |
3280af22 | 3484 | PL_tokenbuf[0] = '@'; |
376b8730 SM |
3485 | s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1, |
3486 | sizeof PL_tokenbuf - 1, FALSE); | |
3487 | if (PL_expect == XOPERATOR) | |
3488 | no_op("Array length", s); | |
3280af22 | 3489 | if (!PL_tokenbuf[1]) |
a0d0e21e | 3490 | PREREF(DOLSHARP); |
3280af22 NIS |
3491 | PL_expect = XOPERATOR; |
3492 | PL_pending_ident = '#'; | |
463ee0b2 | 3493 | TOKEN(DOLSHARP); |
79072805 | 3494 | } |
bbce6d69 | 3495 | |
3280af22 | 3496 | PL_tokenbuf[0] = '$'; |
376b8730 SM |
3497 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, |
3498 | sizeof PL_tokenbuf - 1, FALSE); | |
3499 | if (PL_expect == XOPERATOR) | |
3500 | no_op("Scalar", s); | |
3280af22 NIS |
3501 | if (!PL_tokenbuf[1]) { |
3502 | if (s == PL_bufend) | |
bbce6d69 | 3503 | yyerror("Final $ should be \\$ or $name"); |
3504 | PREREF('$'); | |
8990e307 | 3505 | } |
a0d0e21e | 3506 | |
bbce6d69 | 3507 | /* This kludge not intended to be bulletproof. */ |
3280af22 | 3508 | if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) { |
bbce6d69 | 3509 | yylval.opval = newSVOP(OP_CONST, 0, |
b448e4fe | 3510 | newSViv(PL_compiling.cop_arybase)); |
bbce6d69 | 3511 | yylval.opval->op_private = OPpCONST_ARYBASE; |
3512 | TERM(THING); | |
3513 | } | |
3514 | ||
ff68c719 | 3515 | d = s; |
69d2bceb | 3516 | tmp = (I32)*s; |
3280af22 | 3517 | if (PL_lex_state == LEX_NORMAL) |
ff68c719 | 3518 | s = skipspace(s); |
3519 | ||
3280af22 | 3520 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) { |
bbce6d69 | 3521 | char *t; |
3522 | if (*s == '[') { | |
3280af22 | 3523 | PL_tokenbuf[0] = '@'; |
599cee73 | 3524 | if (ckWARN(WARN_SYNTAX)) { |
bbce6d69 | 3525 | for(t = s + 1; |
7e2040f0 | 3526 | isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$'; |
bbce6d69 | 3527 | t++) ; |
a0d0e21e | 3528 | if (*t++ == ',') { |
3280af22 NIS |
3529 | PL_bufptr = skipspace(PL_bufptr); |
3530 | while (t < PL_bufend && *t != ']') | |
bbce6d69 | 3531 | t++; |
cea2e8a9 | 3532 | Perl_warner(aTHX_ WARN_SYNTAX, |
599cee73 PM |
3533 | "Multidimensional syntax %.*s not supported", |
3534 | (t - PL_bufptr) + 1, PL_bufptr); | |
a0d0e21e LW |
3535 | } |
3536 | } | |
bbce6d69 | 3537 | } |
3538 | else if (*s == '{') { | |
3280af22 | 3539 | PL_tokenbuf[0] = '%'; |
599cee73 | 3540 | if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") && |
bbce6d69 | 3541 | (t = strchr(s, '}')) && (t = strchr(t, '='))) |
3542 | { | |
3280af22 | 3543 | char tmpbuf[sizeof PL_tokenbuf]; |
a0d0e21e LW |
3544 | STRLEN len; |
3545 | for (t++; isSPACE(*t); t++) ; | |
7e2040f0 | 3546 | if (isIDFIRST_lazy_if(t,UTF)) { |
8903cb82 | 3547 | t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len); |
59a6d928 | 3548 | for (; isSPACE(*t); t++) ; |
864dbfa3 | 3549 | if (*t == ';' && get_cv(tmpbuf, FALSE)) |
cea2e8a9 | 3550 | Perl_warner(aTHX_ WARN_SYNTAX, |
599cee73 | 3551 | "You need to quote \"%s\"", tmpbuf); |
748a9306 | 3552 | } |
93a17b20 LW |
3553 | } |
3554 | } | |
2f3197b3 | 3555 | } |
bbce6d69 | 3556 | |
3280af22 | 3557 | PL_expect = XOPERATOR; |
69d2bceb | 3558 | if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) { |
3280af22 NIS |
3559 | bool islop = (PL_last_lop == PL_oldoldbufptr); |
3560 | if (!islop || PL_last_lop_op == OP_GREPSTART) | |
3561 | PL_expect = XOPERATOR; | |
bbce6d69 | 3562 | else if (strchr("$@\"'`q", *s)) |
3280af22 | 3563 | PL_expect = XTERM; /* e.g. print $fh "foo" */ |
7e2040f0 | 3564 | else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF)) |
3280af22 | 3565 | PL_expect = XTERM; /* e.g. print $fh &sub */ |
7e2040f0 | 3566 | else if (isIDFIRST_lazy_if(s,UTF)) { |
3280af22 | 3567 | char tmpbuf[sizeof PL_tokenbuf]; |
8903cb82 | 3568 | scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
155aba94 | 3569 | if ((tmp = keyword(tmpbuf, len))) { |
84902520 TB |
3570 | /* binary operators exclude handle interpretations */ |
3571 | switch (tmp) { | |
3572 | case -KEY_x: | |
3573 | case -KEY_eq: | |
3574 | case -KEY_ne: | |
3575 | case -KEY_gt: | |
3576 | case -KEY_lt: | |
3577 | case -KEY_ge: | |
3578 | case -KEY_le: | |
3579 | case -KEY_cmp: | |
3580 | break; | |
3581 | default: | |
3280af22 | 3582 | PL_expect = XTERM; /* e.g. print $fh length() */ |
84902520 TB |
3583 | break; |
3584 | } | |
3585 | } | |
68dc0745 | 3586 | else { |
3587 | GV *gv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV); | |
3588 | if (gv && GvCVu(gv)) | |
3280af22 | 3589 | PL_expect = XTERM; /* e.g. print $fh subr() */ |
93a17b20 | 3590 | } |
93a17b20 | 3591 | } |
bbce6d69 | 3592 | else if (isDIGIT(*s)) |
3280af22 | 3593 | PL_expect = XTERM; /* e.g. print $fh 3 */ |
bbce6d69 | 3594 | else if (*s == '.' && isDIGIT(s[1])) |
3280af22 | 3595 | PL_expect = XTERM; /* e.g. print $fh .3 */ |
e0587a03 | 3596 | else if (strchr("/?-+", *s) && !isSPACE(s[1]) && s[1] != '=') |
3280af22 | 3597 | PL_expect = XTERM; /* e.g. print $fh -1 */ |
e0587a03 | 3598 | else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=') |
3280af22 | 3599 | PL_expect = XTERM; /* print $fh <<"EOF" */ |
bbce6d69 | 3600 | } |
3280af22 | 3601 | PL_pending_ident = '$'; |
79072805 | 3602 | TOKEN('$'); |
378cc40b LW |
3603 | |
3604 | case '@': | |
3280af22 | 3605 | if (PL_expect == XOPERATOR) |
bbce6d69 | 3606 | no_op("Array", s); |
3280af22 NIS |
3607 | PL_tokenbuf[0] = '@'; |
3608 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE); | |
3609 | if (!PL_tokenbuf[1]) { | |
3610 | if (s == PL_bufend) | |
bbce6d69 | 3611 | yyerror("Final @ should be \\@ or @name"); |
3612 | PREREF('@'); | |
3613 | } | |
3280af22 | 3614 | if (PL_lex_state == LEX_NORMAL) |
ff68c719 | 3615 | s = skipspace(s); |
3280af22 | 3616 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) { |
bbce6d69 | 3617 | if (*s == '{') |
3280af22 | 3618 | PL_tokenbuf[0] = '%'; |
a0d0e21e LW |
3619 | |
3620 | /* Warn about @ where they meant $. */ | |
599cee73 | 3621 | if (ckWARN(WARN_SYNTAX)) { |
a0d0e21e LW |
3622 | if (*s == '[' || *s == '{') { |
3623 | char *t = s + 1; | |
7e2040f0 | 3624 | while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t))) |
a0d0e21e LW |
3625 | t++; |
3626 | if (*t == '}' || *t == ']') { | |
3627 | t++; | |
3280af22 | 3628 | PL_bufptr = skipspace(PL_bufptr); |
cea2e8a9 | 3629 | Perl_warner(aTHX_ WARN_SYNTAX, |
599cee73 | 3630 | "Scalar value %.*s better written as $%.*s", |
3280af22 | 3631 | t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1); |
a0d0e21e | 3632 | } |
93a17b20 LW |
3633 | } |
3634 | } | |
463ee0b2 | 3635 | } |
3280af22 | 3636 | PL_pending_ident = '@'; |
79072805 | 3637 | TERM('@'); |
378cc40b LW |
3638 | |
3639 | case '/': /* may either be division or pattern */ | |
3640 | case '?': /* may either be conditional or pattern */ | |
3280af22 | 3641 | if (PL_expect != XOPERATOR) { |
c277df42 | 3642 | /* Disable warning on "study /blah/" */ |
4e553d73 NIS |
3643 | if (PL_oldoldbufptr == PL_last_uni |
3644 | && (*PL_last_uni != 's' || s - PL_last_uni < 5 | |
7e2040f0 GS |
3645 | || memNE(PL_last_uni, "study", 5) |
3646 | || isALNUM_lazy_if(PL_last_uni+5,UTF))) | |
c277df42 | 3647 | check_uni(); |
8782bef2 | 3648 | s = scan_pat(s,OP_MATCH); |
79072805 | 3649 | TERM(sublex_start()); |
378cc40b LW |
3650 | } |
3651 | tmp = *s++; | |
a687059c | 3652 | if (tmp == '/') |
79072805 | 3653 | Mop(OP_DIVIDE); |
378cc40b LW |
3654 | OPERATOR(tmp); |
3655 | ||
3656 | case '.': | |
51882d45 GS |
3657 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack |
3658 | #ifdef PERL_STRICT_CR | |
3659 | && s[1] == '\n' | |
3660 | #else | |
3661 | && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n')) | |
3662 | #endif | |
3663 | && (s == PL_linestart || s[-1] == '\n') ) | |
3664 | { | |
3280af22 NIS |
3665 | PL_lex_formbrack = 0; |
3666 | PL_expect = XSTATE; | |
79072805 LW |
3667 | goto rightbracket; |
3668 | } | |
3280af22 | 3669 | if (PL_expect == XOPERATOR || !isDIGIT(s[1])) { |
378cc40b | 3670 | tmp = *s++; |
a687059c LW |
3671 | if (*s == tmp) { |
3672 | s++; | |
2f3197b3 LW |
3673 | if (*s == tmp) { |
3674 | s++; | |
79072805 | 3675 | yylval.ival = OPf_SPECIAL; |
2f3197b3 LW |
3676 | } |
3677 | else | |
79072805 | 3678 | yylval.ival = 0; |
378cc40b | 3679 | OPERATOR(DOTDOT); |
a687059c | 3680 | } |
3280af22 | 3681 | if (PL_expect != XOPERATOR) |
2f3197b3 | 3682 | check_uni(); |
79072805 | 3683 | Aop(OP_CONCAT); |
378cc40b LW |
3684 | } |
3685 | /* FALL THROUGH */ | |
3686 | case '0': case '1': case '2': case '3': case '4': | |
3687 | case '5': case '6': case '7': case '8': case '9': | |
b73d6f50 | 3688 | s = scan_num(s, &yylval); |
4e553d73 | 3689 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
607df283 SC |
3690 | "### Saw number in '%s'\n", s); |
3691 | } ) | |
3280af22 | 3692 | if (PL_expect == XOPERATOR) |
8990e307 | 3693 | no_op("Number",s); |
79072805 LW |
3694 | TERM(THING); |
3695 | ||
3696 | case '\'': | |
09bef843 | 3697 | s = scan_str(s,FALSE,FALSE); |
4e553d73 | 3698 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
207e3d1a | 3699 | "### Saw string before '%s'\n", s); |
607df283 | 3700 | } ) |
3280af22 NIS |
3701 | if (PL_expect == XOPERATOR) { |
3702 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3703 | PL_expect = XTERM; | |
a0d0e21e LW |
3704 | depcom(); |
3705 | return ','; /* grandfather non-comma-format format */ | |
3706 | } | |
463ee0b2 | 3707 | else |
8990e307 | 3708 | no_op("String",s); |
463ee0b2 | 3709 | } |
79072805 | 3710 | if (!s) |
85e6fe83 | 3711 | missingterm((char*)0); |
79072805 LW |
3712 | yylval.ival = OP_CONST; |
3713 | TERM(sublex_start()); | |
3714 | ||
3715 | case '"': | |
09bef843 | 3716 | s = scan_str(s,FALSE,FALSE); |
4e553d73 | 3717 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
207e3d1a | 3718 | "### Saw string before '%s'\n", s); |
607df283 | 3719 | } ) |
3280af22 NIS |
3720 | if (PL_expect == XOPERATOR) { |
3721 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3722 | PL_expect = XTERM; | |
a0d0e21e LW |
3723 | depcom(); |
3724 | return ','; /* grandfather non-comma-format format */ | |
3725 | } | |
463ee0b2 | 3726 | else |
8990e307 | 3727 | no_op("String",s); |
463ee0b2 | 3728 | } |
79072805 | 3729 | if (!s) |
85e6fe83 | 3730 | missingterm((char*)0); |
4633a7c4 | 3731 | yylval.ival = OP_CONST; |
3280af22 | 3732 | for (d = SvPV(PL_lex_stuff, len); len; len--, d++) { |
63cd0674 | 3733 | if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) { |
4633a7c4 LW |
3734 | yylval.ival = OP_STRINGIFY; |
3735 | break; | |
3736 | } | |
3737 | } | |
79072805 LW |
3738 | TERM(sublex_start()); |
3739 | ||
3740 | case '`': | |
09bef843 | 3741 | s = scan_str(s,FALSE,FALSE); |
4e553d73 | 3742 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
207e3d1a | 3743 | "### Saw backtick string before '%s'\n", s); |
607df283 | 3744 | } ) |
3280af22 | 3745 | if (PL_expect == XOPERATOR) |
8990e307 | 3746 | no_op("Backticks",s); |
79072805 | 3747 | if (!s) |
85e6fe83 | 3748 | missingterm((char*)0); |
79072805 LW |
3749 | yylval.ival = OP_BACKTICK; |
3750 | set_csh(); | |
3751 | TERM(sublex_start()); | |
3752 | ||
3753 | case '\\': | |
3754 | s++; | |
599cee73 | 3755 | if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s)) |
cea2e8a9 | 3756 | Perl_warner(aTHX_ WARN_SYNTAX,"Can't use \\%c to mean $%c in expression", |
599cee73 | 3757 | *s, *s); |
3280af22 | 3758 | if (PL_expect == XOPERATOR) |
8990e307 | 3759 | no_op("Backslash",s); |
79072805 LW |
3760 | OPERATOR(REFGEN); |
3761 | ||
a7cb1f99 | 3762 | case 'v': |
e526c9e6 | 3763 | if (isDIGIT(s[1]) && PL_expect != XOPERATOR) { |
a7cb1f99 GS |
3764 | char *start = s; |
3765 | start++; | |
3766 | start++; | |
dd629d5b | 3767 | while (isDIGIT(*start) || *start == '_') |
a7cb1f99 GS |
3768 | start++; |
3769 | if (*start == '.' && isDIGIT(start[1])) { | |
b73d6f50 | 3770 | s = scan_num(s, &yylval); |
a7cb1f99 GS |
3771 | TERM(THING); |
3772 | } | |
e526c9e6 GS |
3773 | /* avoid v123abc() or $h{v1}, allow C<print v10;> */ |
3774 | else if (!isALPHA(*start) && (PL_expect == XTERM || PL_expect == XREF)) { | |
3775 | char c = *start; | |
3776 | GV *gv; | |
3777 | *start = '\0'; | |
3778 | gv = gv_fetchpv(s, FALSE, SVt_PVCV); | |
3779 | *start = c; | |
3780 | if (!gv) { | |
b73d6f50 | 3781 | s = scan_num(s, &yylval); |
e526c9e6 GS |
3782 | TERM(THING); |
3783 | } | |
3784 | } | |
a7cb1f99 GS |
3785 | } |
3786 | goto keylookup; | |
79072805 | 3787 | case 'x': |
3280af22 | 3788 | if (isDIGIT(s[1]) && PL_expect == XOPERATOR) { |
79072805 LW |
3789 | s++; |
3790 | Mop(OP_REPEAT); | |
2f3197b3 | 3791 | } |
79072805 LW |
3792 | goto keylookup; |
3793 | ||
378cc40b | 3794 | case '_': |
79072805 LW |
3795 | case 'a': case 'A': |
3796 | case 'b': case 'B': | |
3797 | case 'c': case 'C': | |
3798 | case 'd': case 'D': | |
3799 | case 'e': case 'E': | |
3800 | case 'f': case 'F': | |
3801 | case 'g': case 'G': | |
3802 | case 'h': case 'H': | |
3803 | case 'i': case 'I': | |
3804 | case 'j': case 'J': | |
3805 | case 'k': case 'K': | |
3806 | case 'l': case 'L': | |
3807 | case 'm': case 'M': | |
3808 | case 'n': case 'N': | |
3809 | case 'o': case 'O': | |
3810 | case 'p': case 'P': | |
3811 | case 'q': case 'Q': | |
3812 | case 'r': case 'R': | |
3813 | case 's': case 'S': | |
3814 | case 't': case 'T': | |
3815 | case 'u': case 'U': | |
a7cb1f99 | 3816 | case 'V': |
79072805 LW |
3817 | case 'w': case 'W': |
3818 | case 'X': | |
3819 | case 'y': case 'Y': | |
3820 | case 'z': case 'Z': | |
3821 | ||
49dc05e3 | 3822 | keylookup: { |
161b471a NIS |
3823 | gv = Nullgv; |
3824 | gvp = 0; | |
49dc05e3 | 3825 | |
3280af22 NIS |
3826 | PL_bufptr = s; |
3827 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); | |
8ebc5c01 | 3828 | |
3829 | /* Some keywords can be followed by any delimiter, including ':' */ | |
155aba94 GS |
3830 | tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) || |
3831 | (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') || | |
3832 | (PL_tokenbuf[0] == 'q' && | |
3833 | strchr("qwxr", PL_tokenbuf[1]))))); | |
8ebc5c01 | 3834 | |
3835 | /* x::* is just a word, unless x is "CORE" */ | |
3280af22 | 3836 | if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE")) |
4633a7c4 LW |
3837 | goto just_a_word; |
3838 | ||
3643fb5f | 3839 | d = s; |
3280af22 | 3840 | while (d < PL_bufend && isSPACE(*d)) |
3643fb5f CS |
3841 | d++; /* no comments skipped here, or s### is misparsed */ |
3842 | ||
3843 | /* Is this a label? */ | |
3280af22 NIS |
3844 | if (!tmp && PL_expect == XSTATE |
3845 | && d < PL_bufend && *d == ':' && *(d + 1) != ':') { | |
8ebc5c01 | 3846 | s = d + 1; |
3280af22 | 3847 | yylval.pval = savepv(PL_tokenbuf); |
8ebc5c01 | 3848 | CLINE; |
3849 | TOKEN(LABEL); | |
3643fb5f CS |
3850 | } |
3851 | ||
3852 | /* Check for keywords */ | |
3280af22 | 3853 | tmp = keyword(PL_tokenbuf, len); |
748a9306 LW |
3854 | |
3855 | /* Is this a word before a => operator? */ | |
1c3923b3 | 3856 | if (*d == '=' && d[1] == '>') { |
748a9306 | 3857 | CLINE; |
3280af22 | 3858 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf,0)); |
748a9306 | 3859 | yylval.opval->op_private = OPpCONST_BARE; |
7948272d NIS |
3860 | if (UTF && !IN_BYTE && is_utf8_string((U8*)PL_tokenbuf, len)) |
3861 | SvUTF8_on(((SVOP*)yylval.opval)->op_sv); | |
748a9306 LW |
3862 | TERM(WORD); |
3863 | } | |
3864 | ||
a0d0e21e | 3865 | if (tmp < 0) { /* second-class keyword? */ |
56f7f34b CS |
3866 | GV *ogv = Nullgv; /* override (winner) */ |
3867 | GV *hgv = Nullgv; /* hidden (loser) */ | |
3280af22 | 3868 | if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) { |
56f7f34b | 3869 | CV *cv; |
3280af22 | 3870 | if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) && |
56f7f34b CS |
3871 | (cv = GvCVu(gv))) |
3872 | { | |
3873 | if (GvIMPORTED_CV(gv)) | |
3874 | ogv = gv; | |
3875 | else if (! CvMETHOD(cv)) | |
3876 | hgv = gv; | |
3877 | } | |
3878 | if (!ogv && | |
3280af22 NIS |
3879 | (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) && |
3880 | (gv = *gvp) != (GV*)&PL_sv_undef && | |
56f7f34b CS |
3881 | GvCVu(gv) && GvIMPORTED_CV(gv)) |
3882 | { | |
3883 | ogv = gv; | |
3884 | } | |
3885 | } | |
3886 | if (ogv) { | |
3887 | tmp = 0; /* overridden by import or by GLOBAL */ | |
6e7b2336 GS |
3888 | } |
3889 | else if (gv && !gvp | |
3890 | && -tmp==KEY_lock /* XXX generalizable kludge */ | |
d0456cad | 3891 | && GvCVu(gv) |
3280af22 | 3892 | && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE)) |
6e7b2336 GS |
3893 | { |
3894 | tmp = 0; /* any sub overrides "weak" keyword */ | |
a0d0e21e | 3895 | } |
56f7f34b CS |
3896 | else { /* no override */ |
3897 | tmp = -tmp; | |
3898 | gv = Nullgv; | |
3899 | gvp = 0; | |
4944e2f7 GS |
3900 | if (ckWARN(WARN_AMBIGUOUS) && hgv |
3901 | && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */ | |
cea2e8a9 | 3902 | Perl_warner(aTHX_ WARN_AMBIGUOUS, |
599cee73 | 3903 | "Ambiguous call resolved as CORE::%s(), %s", |
2f3ca594 | 3904 | GvENAME(hgv), "qualify as such or use &"); |
49dc05e3 | 3905 | } |
a0d0e21e LW |
3906 | } |
3907 | ||
3908 | reserved_word: | |
3909 | switch (tmp) { | |
79072805 LW |
3910 | |
3911 | default: /* not a keyword */ | |
93a17b20 | 3912 | just_a_word: { |
96e4d5b1 | 3913 | SV *sv; |
3280af22 | 3914 | char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]); |
8990e307 LW |
3915 | |
3916 | /* Get the rest if it looks like a package qualifier */ | |
3917 | ||
155aba94 | 3918 | if (*s == '\'' || (*s == ':' && s[1] == ':')) { |
c3e0f903 | 3919 | STRLEN morelen; |
3280af22 | 3920 | s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len, |
c3e0f903 GS |
3921 | TRUE, &morelen); |
3922 | if (!morelen) | |
cea2e8a9 | 3923 | Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf, |
ec2ab091 | 3924 | *s == '\'' ? "'" : "::"); |
c3e0f903 | 3925 | len += morelen; |
a0d0e21e | 3926 | } |
8990e307 | 3927 | |
3280af22 NIS |
3928 | if (PL_expect == XOPERATOR) { |
3929 | if (PL_bufptr == PL_linestart) { | |
57843af0 | 3930 | CopLINE_dec(PL_curcop); |
cea2e8a9 | 3931 | Perl_warner(aTHX_ WARN_SEMICOLON, PL_warn_nosemi); |
57843af0 | 3932 | CopLINE_inc(PL_curcop); |
463ee0b2 LW |
3933 | } |
3934 | else | |
54310121 | 3935 | no_op("Bareword",s); |
463ee0b2 | 3936 | } |
8990e307 | 3937 | |
c3e0f903 GS |
3938 | /* Look for a subroutine with this name in current package, |
3939 | unless name is "Foo::", in which case Foo is a bearword | |
3940 | (and a package name). */ | |
3941 | ||
3942 | if (len > 2 && | |
3280af22 | 3943 | PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':') |
c3e0f903 | 3944 | { |
e476b1b5 | 3945 | if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV)) |
4e553d73 | 3946 | Perl_warner(aTHX_ WARN_BAREWORD, |
599cee73 | 3947 | "Bareword \"%s\" refers to nonexistent package", |
3280af22 | 3948 | PL_tokenbuf); |
c3e0f903 | 3949 | len -= 2; |
3280af22 | 3950 | PL_tokenbuf[len] = '\0'; |
c3e0f903 GS |
3951 | gv = Nullgv; |
3952 | gvp = 0; | |
3953 | } | |
3954 | else { | |
3955 | len = 0; | |
3956 | if (!gv) | |
3280af22 | 3957 | gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV); |
c3e0f903 GS |
3958 | } |
3959 | ||
3960 | /* if we saw a global override before, get the right name */ | |
8990e307 | 3961 | |
49dc05e3 | 3962 | if (gvp) { |
79cb57f6 | 3963 | sv = newSVpvn("CORE::GLOBAL::",14); |
3280af22 | 3964 | sv_catpv(sv,PL_tokenbuf); |
49dc05e3 GS |
3965 | } |
3966 | else | |
3280af22 | 3967 | sv = newSVpv(PL_tokenbuf,0); |
8990e307 | 3968 | |
a0d0e21e LW |
3969 | /* Presume this is going to be a bareword of some sort. */ |
3970 | ||
3971 | CLINE; | |
49dc05e3 | 3972 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
a0d0e21e LW |
3973 | yylval.opval->op_private = OPpCONST_BARE; |
3974 | ||
c3e0f903 GS |
3975 | /* And if "Foo::", then that's what it certainly is. */ |
3976 | ||
3977 | if (len) | |
3978 | goto safe_bareword; | |
3979 | ||
8990e307 LW |
3980 | /* See if it's the indirect object for a list operator. */ |
3981 | ||
3280af22 NIS |
3982 | if (PL_oldoldbufptr && |
3983 | PL_oldoldbufptr < PL_bufptr && | |
65cec589 GS |
3984 | (PL_oldoldbufptr == PL_last_lop |
3985 | || PL_oldoldbufptr == PL_last_uni) && | |
a0d0e21e | 3986 | /* NO SKIPSPACE BEFORE HERE! */ |
a9ef352a GS |
3987 | (PL_expect == XREF || |
3988 | ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF)) | |
a0d0e21e | 3989 | { |
748a9306 LW |
3990 | bool immediate_paren = *s == '('; |
3991 | ||
a0d0e21e LW |
3992 | /* (Now we can afford to cross potential line boundary.) */ |
3993 | s = skipspace(s); | |
3994 | ||
3995 | /* Two barewords in a row may indicate method call. */ | |
3996 | ||
7e2040f0 | 3997 | if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv))) |
a0d0e21e LW |
3998 | return tmp; |
3999 | ||
4000 | /* If not a declared subroutine, it's an indirect object. */ | |
4001 | /* (But it's an indir obj regardless for sort.) */ | |
4002 | ||
7948272d | 4003 | if ( !immediate_paren && (PL_last_lop_op == OP_SORT || |
f0670693 | 4004 | ((!gv || !GvCVu(gv)) && |
a9ef352a | 4005 | (PL_last_lop_op != OP_MAPSTART && |
f0670693 | 4006 | PL_last_lop_op != OP_GREPSTART)))) |
a9ef352a | 4007 | { |
3280af22 | 4008 | PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR; |
748a9306 | 4009 | goto bareword; |
93a17b20 LW |
4010 | } |
4011 | } | |
8990e307 | 4012 | |
8990e307 | 4013 | |
3280af22 | 4014 | PL_expect = XOPERATOR; |
8990e307 | 4015 | s = skipspace(s); |
1c3923b3 GS |
4016 | |
4017 | /* Is this a word before a => operator? */ | |
4018 | if (*s == '=' && s[1] == '>') { | |
4019 | CLINE; | |
4020 | sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf); | |
7948272d NIS |
4021 | if (UTF && !IN_BYTE && is_utf8_string((U8*)PL_tokenbuf, len)) |
4022 | SvUTF8_on(((SVOP*)yylval.opval)->op_sv); | |
1c3923b3 GS |
4023 | TERM(WORD); |
4024 | } | |
4025 | ||
4026 | /* If followed by a paren, it's certainly a subroutine. */ | |
93a17b20 | 4027 | if (*s == '(') { |
79072805 | 4028 | CLINE; |
96e4d5b1 | 4029 | if (gv && GvCVu(gv)) { |
bf4acbe4 | 4030 | for (d = s + 1; SPACE_OR_TAB(*d); d++) ; |
7a52d87a | 4031 | if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) { |
96e4d5b1 | 4032 | s = d + 1; |
4033 | goto its_constant; | |
4034 | } | |
4035 | } | |
3280af22 NIS |
4036 | PL_nextval[PL_nexttoke].opval = yylval.opval; |
4037 | PL_expect = XOPERATOR; | |
93a17b20 | 4038 | force_next(WORD); |
c07a80fd | 4039 | yylval.ival = 0; |
463ee0b2 | 4040 | TOKEN('&'); |
79072805 | 4041 | } |
93a17b20 | 4042 | |
a0d0e21e | 4043 | /* If followed by var or block, call it a method (unless sub) */ |
8990e307 | 4044 | |
8ebc5c01 | 4045 | if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) { |
3280af22 NIS |
4046 | PL_last_lop = PL_oldbufptr; |
4047 | PL_last_lop_op = OP_METHOD; | |
93a17b20 | 4048 | PREBLOCK(METHOD); |
463ee0b2 LW |
4049 | } |
4050 | ||
8990e307 LW |
4051 | /* If followed by a bareword, see if it looks like indir obj. */ |
4052 | ||
7e2040f0 | 4053 | if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp = intuit_method(s,gv))) |
a0d0e21e | 4054 | return tmp; |
93a17b20 | 4055 | |
8990e307 LW |
4056 | /* Not a method, so call it a subroutine (if defined) */ |
4057 | ||
8ebc5c01 | 4058 | if (gv && GvCVu(gv)) { |
46fc3d4c | 4059 | CV* cv; |
0453d815 PM |
4060 | if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS)) |
4061 | Perl_warner(aTHX_ WARN_AMBIGUOUS, | |
4062 | "Ambiguous use of -%s resolved as -&%s()", | |
3280af22 | 4063 | PL_tokenbuf, PL_tokenbuf); |
89bfa8cd | 4064 | /* Check for a constant sub */ |
46fc3d4c | 4065 | cv = GvCV(gv); |
96e4d5b1 | 4066 | if ((sv = cv_const_sv(cv))) { |
4067 | its_constant: | |
4068 | SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv); | |
4069 | ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv); | |
4070 | yylval.opval->op_private = 0; | |
4071 | TOKEN(WORD); | |
89bfa8cd | 4072 | } |
4073 | ||
a5f75d66 AD |
4074 | /* Resolve to GV now. */ |
4075 | op_free(yylval.opval); | |
4076 | yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv)); | |
9675f7ac | 4077 | yylval.opval->op_private |= OPpENTERSUB_NOPAREN; |
7a52d87a | 4078 | PL_last_lop = PL_oldbufptr; |
bf848113 | 4079 | PL_last_lop_op = OP_ENTERSUB; |
4633a7c4 LW |
4080 | /* Is there a prototype? */ |
4081 | if (SvPOK(cv)) { | |
4082 | STRLEN len; | |
7a52d87a | 4083 | char *proto = SvPV((SV*)cv, len); |
4633a7c4 LW |
4084 | if (!len) |
4085 | TERM(FUNC0SUB); | |
7a52d87a | 4086 | if (strEQ(proto, "$")) |
4633a7c4 | 4087 | OPERATOR(UNIOPSUB); |
7a52d87a | 4088 | if (*proto == '&' && *s == '{') { |
3280af22 | 4089 | sv_setpv(PL_subname,"__ANON__"); |
4633a7c4 LW |
4090 | PREBLOCK(LSTOPSUB); |
4091 | } | |
a9ef352a | 4092 | } |
3280af22 NIS |
4093 | PL_nextval[PL_nexttoke].opval = yylval.opval; |
4094 | PL_expect = XTERM; | |
8990e307 LW |
4095 | force_next(WORD); |
4096 | TOKEN(NOAMP); | |
4097 | } | |
748a9306 | 4098 | |
8990e307 LW |
4099 | /* Call it a bare word */ |
4100 | ||
5603f27d GS |
4101 | if (PL_hints & HINT_STRICT_SUBS) |
4102 | yylval.opval->op_private |= OPpCONST_STRICT; | |
4103 | else { | |
4104 | bareword: | |
4105 | if (ckWARN(WARN_RESERVED)) { | |
4106 | if (lastchar != '-') { | |
4107 | for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ; | |
4108 | if (!*d) | |
cea2e8a9 | 4109 | Perl_warner(aTHX_ WARN_RESERVED, PL_warn_reserved, |
5603f27d GS |
4110 | PL_tokenbuf); |
4111 | } | |
748a9306 LW |
4112 | } |
4113 | } | |
c3e0f903 GS |
4114 | |
4115 | safe_bareword: | |
f248d071 | 4116 | if (lastchar && strchr("*%&", lastchar) && ckWARN_d(WARN_AMBIGUOUS)) { |
0453d815 PM |
4117 | Perl_warner(aTHX_ WARN_AMBIGUOUS, |
4118 | "Operator or semicolon missing before %c%s", | |
3280af22 | 4119 | lastchar, PL_tokenbuf); |
0453d815 PM |
4120 | Perl_warner(aTHX_ WARN_AMBIGUOUS, |
4121 | "Ambiguous use of %c resolved as operator %c", | |
748a9306 LW |
4122 | lastchar, lastchar); |
4123 | } | |
93a17b20 | 4124 | TOKEN(WORD); |
79072805 | 4125 | } |
79072805 | 4126 | |
68dc0745 | 4127 | case KEY___FILE__: |
46fc3d4c | 4128 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
ed094faf | 4129 | newSVpv(CopFILE(PL_curcop),0)); |
46fc3d4c | 4130 | TERM(THING); |
4131 | ||
79072805 | 4132 | case KEY___LINE__: |
cf2093f6 | 4133 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
57843af0 | 4134 | Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop))); |
79072805 | 4135 | TERM(THING); |
68dc0745 | 4136 | |
4137 | case KEY___PACKAGE__: | |
4138 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, | |
3280af22 NIS |
4139 | (PL_curstash |
4140 | ? newSVsv(PL_curstname) | |
4141 | : &PL_sv_undef)); | |
79072805 | 4142 | TERM(THING); |
79072805 | 4143 | |
e50aee73 | 4144 | case KEY___DATA__: |
79072805 LW |
4145 | case KEY___END__: { |
4146 | GV *gv; | |
79072805 LW |
4147 | |
4148 | /*SUPPRESS 560*/ | |
3280af22 | 4149 | if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) { |
e50aee73 | 4150 | char *pname = "main"; |
3280af22 NIS |
4151 | if (PL_tokenbuf[2] == 'D') |
4152 | pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash); | |
cea2e8a9 | 4153 | gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO); |
a5f75d66 | 4154 | GvMULTI_on(gv); |
79072805 | 4155 | if (!GvIO(gv)) |
a0d0e21e | 4156 | GvIOp(gv) = newIO(); |
3280af22 | 4157 | IoIFP(GvIOp(gv)) = PL_rsfp; |
a0d0e21e LW |
4158 | #if defined(HAS_FCNTL) && defined(F_SETFD) |
4159 | { | |
3280af22 | 4160 | int fd = PerlIO_fileno(PL_rsfp); |
a0d0e21e LW |
4161 | fcntl(fd,F_SETFD,fd >= 3); |
4162 | } | |
79072805 | 4163 | #endif |
fd049845 | 4164 | /* Mark this internal pseudo-handle as clean */ |
4165 | IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT; | |
3280af22 | 4166 | if (PL_preprocess) |
50952442 | 4167 | IoTYPE(GvIOp(gv)) = IoTYPE_PIPE; |
3280af22 | 4168 | else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) |
50952442 | 4169 | IoTYPE(GvIOp(gv)) = IoTYPE_STD; |
79072805 | 4170 | else |
50952442 | 4171 | IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY; |
c39cd008 GS |
4172 | #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS) |
4173 | /* if the script was opened in binmode, we need to revert | |
53129d29 | 4174 | * it to text mode for compatibility; but only iff it has CRs |
c39cd008 | 4175 | * XXX this is a questionable hack at best. */ |
53129d29 GS |
4176 | if (PL_bufend-PL_bufptr > 2 |
4177 | && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r') | |
c39cd008 GS |
4178 | { |
4179 | Off_t loc = 0; | |
50952442 | 4180 | if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) { |
c39cd008 GS |
4181 | loc = PerlIO_tell(PL_rsfp); |
4182 | (void)PerlIO_seek(PL_rsfp, 0L, 0); | |
4183 | } | |
4184 | if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) { | |
1143fce0 JH |
4185 | #ifdef PERLIO_IS_STDIO /* really? */ |
4186 | # if defined(__BORLANDC__) | |
cb359b41 JH |
4187 | /* XXX see note in do_binmode() */ |
4188 | ((FILE*)PL_rsfp)->flags &= ~_F_BIN; | |
1143fce0 JH |
4189 | # endif |
4190 | #endif | |
c39cd008 GS |
4191 | if (loc > 0) |
4192 | PerlIO_seek(PL_rsfp, loc, 0); | |
4193 | } | |
4194 | } | |
4195 | #endif | |
7948272d NIS |
4196 | #ifdef PERLIO_LAYERS |
4197 | if (UTF && !IN_BYTE) | |
4198 | PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8"); | |
4199 | #endif | |
3280af22 | 4200 | PL_rsfp = Nullfp; |
79072805 LW |
4201 | } |
4202 | goto fake_eof; | |
e929a76b | 4203 | } |
de3bb511 | 4204 | |
8990e307 | 4205 | case KEY_AUTOLOAD: |
ed6116ce | 4206 | case KEY_DESTROY: |
79072805 | 4207 | case KEY_BEGIN: |
7d30b5c4 | 4208 | case KEY_CHECK: |
7d07dbc2 | 4209 | case KEY_INIT: |
7d30b5c4 | 4210 | case KEY_END: |
3280af22 NIS |
4211 | if (PL_expect == XSTATE) { |
4212 | s = PL_bufptr; | |
93a17b20 | 4213 | goto really_sub; |
79072805 LW |
4214 | } |
4215 | goto just_a_word; | |
4216 | ||
a0d0e21e LW |
4217 | case KEY_CORE: |
4218 | if (*s == ':' && s[1] == ':') { | |
4219 | s += 2; | |
748a9306 | 4220 | d = s; |
3280af22 | 4221 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
6798c92b GS |
4222 | if (!(tmp = keyword(PL_tokenbuf, len))) |
4223 | Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf); | |
a0d0e21e LW |
4224 | if (tmp < 0) |
4225 | tmp = -tmp; | |
4226 | goto reserved_word; | |
4227 | } | |
4228 | goto just_a_word; | |
4229 | ||
463ee0b2 LW |
4230 | case KEY_abs: |
4231 | UNI(OP_ABS); | |
4232 | ||
79072805 LW |
4233 | case KEY_alarm: |
4234 | UNI(OP_ALARM); | |
4235 | ||
4236 | case KEY_accept: | |
a0d0e21e | 4237 | LOP(OP_ACCEPT,XTERM); |
79072805 | 4238 | |
463ee0b2 LW |
4239 | case KEY_and: |
4240 | OPERATOR(ANDOP); | |
4241 | ||
79072805 | 4242 | case KEY_atan2: |
a0d0e21e | 4243 | LOP(OP_ATAN2,XTERM); |
85e6fe83 | 4244 | |
79072805 | 4245 | case KEY_bind: |
a0d0e21e | 4246 | LOP(OP_BIND,XTERM); |
79072805 LW |
4247 | |
4248 | case KEY_binmode: | |
1c1fc3ea | 4249 | LOP(OP_BINMODE,XTERM); |
79072805 LW |
4250 | |
4251 | case KEY_bless: | |
a0d0e21e | 4252 | LOP(OP_BLESS,XTERM); |
79072805 LW |
4253 | |
4254 | case KEY_chop: | |
4255 | UNI(OP_CHOP); | |
4256 | ||
4257 | case KEY_continue: | |
4258 | PREBLOCK(CONTINUE); | |
4259 | ||
4260 | case KEY_chdir: | |
85e6fe83 | 4261 | (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */ |
79072805 LW |
4262 | UNI(OP_CHDIR); |
4263 | ||
4264 | case KEY_close: | |
4265 | UNI(OP_CLOSE); | |
4266 | ||
4267 | case KEY_closedir: | |
4268 | UNI(OP_CLOSEDIR); | |
4269 | ||
4270 | case KEY_cmp: | |
4271 | Eop(OP_SCMP); | |
4272 | ||
4273 | case KEY_caller: | |
4274 | UNI(OP_CALLER); | |
4275 | ||
4276 | case KEY_crypt: | |
4277 | #ifdef FCRYPT | |
f4c556ac GS |
4278 | if (!PL_cryptseen) { |
4279 | PL_cryptseen = TRUE; | |
de3bb511 | 4280 | init_des(); |
f4c556ac | 4281 | } |
a687059c | 4282 | #endif |
a0d0e21e | 4283 | LOP(OP_CRYPT,XTERM); |
79072805 LW |
4284 | |
4285 | case KEY_chmod: | |
e476b1b5 | 4286 | if (ckWARN(WARN_CHMOD)) { |
3280af22 | 4287 | for (d = s; d < PL_bufend && (isSPACE(*d) || *d == '('); d++) ; |
748a9306 | 4288 | if (*d != '0' && isDIGIT(*d)) |
e476b1b5 | 4289 | Perl_warner(aTHX_ WARN_CHMOD, |
5a211162 | 4290 | "chmod() mode argument is missing initial 0"); |
748a9306 | 4291 | } |
a0d0e21e | 4292 | LOP(OP_CHMOD,XTERM); |
79072805 LW |
4293 | |
4294 | case KEY_chown: | |
a0d0e21e | 4295 | LOP(OP_CHOWN,XTERM); |
79072805 LW |
4296 | |
4297 | case KEY_connect: | |
a0d0e21e | 4298 | LOP(OP_CONNECT,XTERM); |
79072805 | 4299 | |
463ee0b2 LW |
4300 | case KEY_chr: |
4301 | UNI(OP_CHR); | |
4302 | ||
79072805 LW |
4303 | case KEY_cos: |
4304 | UNI(OP_COS); | |
4305 | ||
4306 | case KEY_chroot: | |
4307 | UNI(OP_CHROOT); | |
4308 | ||
4309 | case KEY_do: | |
4310 | s = skipspace(s); | |
4311 | if (*s == '{') | |
a0d0e21e | 4312 | PRETERMBLOCK(DO); |
79072805 | 4313 | if (*s != '\'') |
a0d0e21e | 4314 | s = force_word(s,WORD,FALSE,TRUE,FALSE); |
378cc40b | 4315 | OPERATOR(DO); |
79072805 LW |
4316 | |
4317 | case KEY_die: | |
3280af22 | 4318 | PL_hints |= HINT_BLOCK_SCOPE; |
a0d0e21e | 4319 | LOP(OP_DIE,XTERM); |
79072805 LW |
4320 | |
4321 | case KEY_defined: | |
4322 | UNI(OP_DEFINED); | |
4323 | ||
4324 | case KEY_delete: | |
a0d0e21e | 4325 | UNI(OP_DELETE); |
79072805 LW |
4326 | |
4327 | case KEY_dbmopen: | |
a0d0e21e LW |
4328 | gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV); |
4329 | LOP(OP_DBMOPEN,XTERM); | |
79072805 LW |
4330 | |
4331 | case KEY_dbmclose: | |
4332 | UNI(OP_DBMCLOSE); | |
4333 | ||
4334 | case KEY_dump: | |
a0d0e21e | 4335 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4336 | LOOPX(OP_DUMP); |
4337 | ||
4338 | case KEY_else: | |
4339 | PREBLOCK(ELSE); | |
4340 | ||
4341 | case KEY_elsif: | |
57843af0 | 4342 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
4343 | OPERATOR(ELSIF); |
4344 | ||
4345 | case KEY_eq: | |
4346 | Eop(OP_SEQ); | |
4347 | ||
a0d0e21e LW |
4348 | case KEY_exists: |
4349 | UNI(OP_EXISTS); | |
4e553d73 | 4350 | |
79072805 LW |
4351 | case KEY_exit: |
4352 | UNI(OP_EXIT); | |
4353 | ||
4354 | case KEY_eval: | |
79072805 | 4355 | s = skipspace(s); |
3280af22 | 4356 | PL_expect = (*s == '{') ? XTERMBLOCK : XTERM; |
463ee0b2 | 4357 | UNIBRACK(OP_ENTEREVAL); |
79072805 LW |
4358 | |
4359 | case KEY_eof: | |
4360 | UNI(OP_EOF); | |
4361 | ||
4362 | case KEY_exp: | |
4363 | UNI(OP_EXP); | |
4364 | ||
4365 | case KEY_each: | |
4366 | UNI(OP_EACH); | |
4367 | ||
4368 | case KEY_exec: | |
4369 | set_csh(); | |
a0d0e21e | 4370 | LOP(OP_EXEC,XREF); |
79072805 LW |
4371 | |
4372 | case KEY_endhostent: | |
4373 | FUN0(OP_EHOSTENT); | |
4374 | ||
4375 | case KEY_endnetent: | |
4376 | FUN0(OP_ENETENT); | |
4377 | ||
4378 | case KEY_endservent: | |
4379 | FUN0(OP_ESERVENT); | |
4380 | ||
4381 | case KEY_endprotoent: | |
4382 | FUN0(OP_EPROTOENT); | |
4383 | ||
4384 | case KEY_endpwent: | |
4385 | FUN0(OP_EPWENT); | |
4386 | ||
4387 | case KEY_endgrent: | |
4388 | FUN0(OP_EGRENT); | |
4389 | ||
4390 | case KEY_for: | |
4391 | case KEY_foreach: | |
57843af0 | 4392 | yylval.ival = CopLINE(PL_curcop); |
55497cff | 4393 | s = skipspace(s); |
7e2040f0 | 4394 | if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) { |
55497cff | 4395 | char *p = s; |
3280af22 | 4396 | if ((PL_bufend - p) >= 3 && |
55497cff | 4397 | strnEQ(p, "my", 2) && isSPACE(*(p + 2))) |
4398 | p += 2; | |
77ca0c92 LW |
4399 | else if ((PL_bufend - p) >= 4 && |
4400 | strnEQ(p, "our", 3) && isSPACE(*(p + 3))) | |
4401 | p += 3; | |
55497cff | 4402 | p = skipspace(p); |
7e2040f0 | 4403 | if (isIDFIRST_lazy_if(p,UTF)) { |
77ca0c92 LW |
4404 | p = scan_ident(p, PL_bufend, |
4405 | PL_tokenbuf, sizeof PL_tokenbuf, TRUE); | |
4406 | p = skipspace(p); | |
4407 | } | |
4408 | if (*p != '$') | |
cea2e8a9 | 4409 | Perl_croak(aTHX_ "Missing $ on loop variable"); |
55497cff | 4410 | } |
79072805 LW |
4411 | OPERATOR(FOR); |
4412 | ||
4413 | case KEY_formline: | |
a0d0e21e | 4414 | LOP(OP_FORMLINE,XTERM); |
79072805 LW |
4415 | |
4416 | case KEY_fork: | |
4417 | FUN0(OP_FORK); | |
4418 | ||
4419 | case KEY_fcntl: | |
a0d0e21e | 4420 | LOP(OP_FCNTL,XTERM); |
79072805 LW |
4421 | |
4422 | case KEY_fileno: | |
4423 | UNI(OP_FILENO); | |
4424 | ||
4425 | case KEY_flock: | |
a0d0e21e | 4426 | LOP(OP_FLOCK,XTERM); |
79072805 LW |
4427 | |
4428 | case KEY_gt: | |
4429 | Rop(OP_SGT); | |
4430 | ||
4431 | case KEY_ge: | |
4432 | Rop(OP_SGE); | |
4433 | ||
4434 | case KEY_grep: | |
2c38e13d | 4435 | LOP(OP_GREPSTART, XREF); |
79072805 LW |
4436 | |
4437 | case KEY_goto: | |
a0d0e21e | 4438 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4439 | LOOPX(OP_GOTO); |
4440 | ||
4441 | case KEY_gmtime: | |
4442 | UNI(OP_GMTIME); | |
4443 | ||
4444 | case KEY_getc: | |
4445 | UNI(OP_GETC); | |
4446 | ||
4447 | case KEY_getppid: | |
4448 | FUN0(OP_GETPPID); | |
4449 | ||
4450 | case KEY_getpgrp: | |
4451 | UNI(OP_GETPGRP); | |
4452 | ||
4453 | case KEY_getpriority: | |
a0d0e21e | 4454 | LOP(OP_GETPRIORITY,XTERM); |
79072805 LW |
4455 | |
4456 | case KEY_getprotobyname: | |
4457 | UNI(OP_GPBYNAME); | |
4458 | ||
4459 | case KEY_getprotobynumber: | |
a0d0e21e | 4460 | LOP(OP_GPBYNUMBER,XTERM); |
79072805 LW |
4461 | |
4462 | case KEY_getprotoent: | |
4463 | FUN0(OP_GPROTOENT); | |
4464 | ||
4465 | case KEY_getpwent: | |
4466 | FUN0(OP_GPWENT); | |
4467 | ||
4468 | case KEY_getpwnam: | |
ff68c719 | 4469 | UNI(OP_GPWNAM); |
79072805 LW |
4470 | |
4471 | case KEY_getpwuid: | |
ff68c719 | 4472 | UNI(OP_GPWUID); |
79072805 LW |
4473 | |
4474 | case KEY_getpeername: | |
4475 | UNI(OP_GETPEERNAME); | |
4476 | ||
4477 | case KEY_gethostbyname: | |
4478 | UNI(OP_GHBYNAME); | |
4479 | ||
4480 | case KEY_gethostbyaddr: | |
a0d0e21e | 4481 | LOP(OP_GHBYADDR,XTERM); |
79072805 LW |
4482 | |
4483 | case KEY_gethostent: | |
4484 | FUN0(OP_GHOSTENT); | |
4485 | ||
4486 | case KEY_getnetbyname: | |
4487 | UNI(OP_GNBYNAME); | |
4488 | ||
4489 | case KEY_getnetbyaddr: | |
a0d0e21e | 4490 | LOP(OP_GNBYADDR,XTERM); |
79072805 LW |
4491 | |
4492 | case KEY_getnetent: | |
4493 | FUN0(OP_GNETENT); | |
4494 | ||
4495 | case KEY_getservbyname: | |
a0d0e21e | 4496 | LOP(OP_GSBYNAME,XTERM); |
79072805 LW |
4497 | |
4498 | case KEY_getservbyport: | |
a0d0e21e | 4499 | LOP(OP_GSBYPORT,XTERM); |
79072805 LW |
4500 | |
4501 | case KEY_getservent: | |
4502 | FUN0(OP_GSERVENT); | |
4503 | ||
4504 | case KEY_getsockname: | |
4505 | UNI(OP_GETSOCKNAME); | |
4506 | ||
4507 | case KEY_getsockopt: | |
a0d0e21e | 4508 | LOP(OP_GSOCKOPT,XTERM); |
79072805 LW |
4509 | |
4510 | case KEY_getgrent: | |
4511 | FUN0(OP_GGRENT); | |
4512 | ||
4513 | case KEY_getgrnam: | |
ff68c719 | 4514 | UNI(OP_GGRNAM); |
79072805 LW |
4515 | |
4516 | case KEY_getgrgid: | |
ff68c719 | 4517 | UNI(OP_GGRGID); |
79072805 LW |
4518 | |
4519 | case KEY_getlogin: | |
4520 | FUN0(OP_GETLOGIN); | |
4521 | ||
93a17b20 | 4522 | case KEY_glob: |
a0d0e21e LW |
4523 | set_csh(); |
4524 | LOP(OP_GLOB,XTERM); | |
93a17b20 | 4525 | |
79072805 LW |
4526 | case KEY_hex: |
4527 | UNI(OP_HEX); | |
4528 | ||
4529 | case KEY_if: | |
57843af0 | 4530 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
4531 | OPERATOR(IF); |
4532 | ||
4533 | case KEY_index: | |
a0d0e21e | 4534 | LOP(OP_INDEX,XTERM); |
79072805 LW |
4535 | |
4536 | case KEY_int: | |
4537 | UNI(OP_INT); | |
4538 | ||
4539 | case KEY_ioctl: | |
a0d0e21e | 4540 | LOP(OP_IOCTL,XTERM); |
79072805 LW |
4541 | |
4542 | case KEY_join: | |
a0d0e21e | 4543 | LOP(OP_JOIN,XTERM); |
79072805 LW |
4544 | |
4545 | case KEY_keys: | |
4546 | UNI(OP_KEYS); | |
4547 | ||
4548 | case KEY_kill: | |
a0d0e21e | 4549 | LOP(OP_KILL,XTERM); |
79072805 LW |
4550 | |
4551 | case KEY_last: | |
a0d0e21e | 4552 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 | 4553 | LOOPX(OP_LAST); |
4e553d73 | 4554 | |
79072805 LW |
4555 | case KEY_lc: |
4556 | UNI(OP_LC); | |
4557 | ||
4558 | case KEY_lcfirst: | |
4559 | UNI(OP_LCFIRST); | |
4560 | ||
4561 | case KEY_local: | |
09bef843 | 4562 | yylval.ival = 0; |
79072805 LW |
4563 | OPERATOR(LOCAL); |
4564 | ||
4565 | case KEY_length: | |
4566 | UNI(OP_LENGTH); | |
4567 | ||
4568 | case KEY_lt: | |
4569 | Rop(OP_SLT); | |
4570 | ||
4571 | case KEY_le: | |
4572 | Rop(OP_SLE); | |
4573 | ||
4574 | case KEY_localtime: | |
4575 | UNI(OP_LOCALTIME); | |
4576 | ||
4577 | case KEY_log: | |
4578 | UNI(OP_LOG); | |
4579 | ||
4580 | case KEY_link: | |
a0d0e21e | 4581 | LOP(OP_LINK,XTERM); |
79072805 LW |
4582 | |
4583 | case KEY_listen: | |
a0d0e21e | 4584 | LOP(OP_LISTEN,XTERM); |
79072805 | 4585 | |
c0329465 MB |
4586 | case KEY_lock: |
4587 | UNI(OP_LOCK); | |
4588 | ||
79072805 LW |
4589 | case KEY_lstat: |
4590 | UNI(OP_LSTAT); | |
4591 | ||
4592 | case KEY_m: | |
8782bef2 | 4593 | s = scan_pat(s,OP_MATCH); |
79072805 LW |
4594 | TERM(sublex_start()); |
4595 | ||
a0d0e21e | 4596 | case KEY_map: |
2c38e13d | 4597 | LOP(OP_MAPSTART, XREF); |
4e4e412b | 4598 | |
79072805 | 4599 | case KEY_mkdir: |
a0d0e21e | 4600 | LOP(OP_MKDIR,XTERM); |
79072805 LW |
4601 | |
4602 | case KEY_msgctl: | |
a0d0e21e | 4603 | LOP(OP_MSGCTL,XTERM); |
79072805 LW |
4604 | |
4605 | case KEY_msgget: | |
a0d0e21e | 4606 | LOP(OP_MSGGET,XTERM); |
79072805 LW |
4607 | |
4608 | case KEY_msgrcv: | |
a0d0e21e | 4609 | LOP(OP_MSGRCV,XTERM); |
79072805 LW |
4610 | |
4611 | case KEY_msgsnd: | |
a0d0e21e | 4612 | LOP(OP_MSGSND,XTERM); |
79072805 | 4613 | |
77ca0c92 | 4614 | case KEY_our: |
93a17b20 | 4615 | case KEY_my: |
77ca0c92 | 4616 | PL_in_my = tmp; |
c750a3ec | 4617 | s = skipspace(s); |
7e2040f0 | 4618 | if (isIDFIRST_lazy_if(s,UTF)) { |
3280af22 | 4619 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len); |
09bef843 SB |
4620 | if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3)) |
4621 | goto really_sub; | |
def3634b | 4622 | PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len); |
3280af22 | 4623 | if (!PL_in_my_stash) { |
c750a3ec | 4624 | char tmpbuf[1024]; |
3280af22 NIS |
4625 | PL_bufptr = s; |
4626 | sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf); | |
c750a3ec MB |
4627 | yyerror(tmpbuf); |
4628 | } | |
4629 | } | |
09bef843 | 4630 | yylval.ival = 1; |
55497cff | 4631 | OPERATOR(MY); |
93a17b20 | 4632 | |
79072805 | 4633 | case KEY_next: |
a0d0e21e | 4634 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4635 | LOOPX(OP_NEXT); |
4636 | ||
4637 | case KEY_ne: | |
4638 | Eop(OP_SNE); | |
4639 | ||
a0d0e21e | 4640 | case KEY_no: |
3280af22 | 4641 | if (PL_expect != XSTATE) |
a0d0e21e LW |
4642 | yyerror("\"no\" not allowed in expression"); |
4643 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
89bfa8cd | 4644 | s = force_version(s); |
a0d0e21e LW |
4645 | yylval.ival = 0; |
4646 | OPERATOR(USE); | |
4647 | ||
4648 | case KEY_not: | |
2d2e263d LW |
4649 | if (*s == '(' || (s = skipspace(s), *s == '(')) |
4650 | FUN1(OP_NOT); | |
4651 | else | |
4652 | OPERATOR(NOTOP); | |
a0d0e21e | 4653 | |
79072805 | 4654 | case KEY_open: |
93a17b20 | 4655 | s = skipspace(s); |
7e2040f0 | 4656 | if (isIDFIRST_lazy_if(s,UTF)) { |
93a17b20 | 4657 | char *t; |
7e2040f0 | 4658 | for (d = s; isALNUM_lazy_if(d,UTF); d++) ; |
93a17b20 | 4659 | t = skipspace(d); |
e476b1b5 GS |
4660 | if (strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)) |
4661 | Perl_warner(aTHX_ WARN_PRECEDENCE, | |
0453d815 PM |
4662 | "Precedence problem: open %.*s should be open(%.*s)", |
4663 | d-s,s, d-s,s); | |
93a17b20 | 4664 | } |
a0d0e21e | 4665 | LOP(OP_OPEN,XTERM); |
79072805 | 4666 | |
463ee0b2 | 4667 | case KEY_or: |
a0d0e21e | 4668 | yylval.ival = OP_OR; |
463ee0b2 LW |
4669 | OPERATOR(OROP); |
4670 | ||
79072805 LW |
4671 | case KEY_ord: |
4672 | UNI(OP_ORD); | |
4673 | ||
4674 | case KEY_oct: | |
4675 | UNI(OP_OCT); | |
4676 | ||
4677 | case KEY_opendir: | |
a0d0e21e | 4678 | LOP(OP_OPEN_DIR,XTERM); |
79072805 LW |
4679 | |
4680 | case KEY_print: | |
3280af22 | 4681 | checkcomma(s,PL_tokenbuf,"filehandle"); |
a0d0e21e | 4682 | LOP(OP_PRINT,XREF); |
79072805 LW |
4683 | |
4684 | case KEY_printf: | |
3280af22 | 4685 | checkcomma(s,PL_tokenbuf,"filehandle"); |
a0d0e21e | 4686 | LOP(OP_PRTF,XREF); |
79072805 | 4687 | |
c07a80fd | 4688 | case KEY_prototype: |
4689 | UNI(OP_PROTOTYPE); | |
4690 | ||
79072805 | 4691 | case KEY_push: |
a0d0e21e | 4692 | LOP(OP_PUSH,XTERM); |
79072805 LW |
4693 | |
4694 | case KEY_pop: | |
4695 | UNI(OP_POP); | |
4696 | ||
a0d0e21e LW |
4697 | case KEY_pos: |
4698 | UNI(OP_POS); | |
4e553d73 | 4699 | |
79072805 | 4700 | case KEY_pack: |
a0d0e21e | 4701 | LOP(OP_PACK,XTERM); |
79072805 LW |
4702 | |
4703 | case KEY_package: | |
a0d0e21e | 4704 | s = force_word(s,WORD,FALSE,TRUE,FALSE); |
79072805 LW |
4705 | OPERATOR(PACKAGE); |
4706 | ||
4707 | case KEY_pipe: | |
a0d0e21e | 4708 | LOP(OP_PIPE_OP,XTERM); |
79072805 LW |
4709 | |
4710 | case KEY_q: | |
09bef843 | 4711 | s = scan_str(s,FALSE,FALSE); |
79072805 | 4712 | if (!s) |
85e6fe83 | 4713 | missingterm((char*)0); |
79072805 LW |
4714 | yylval.ival = OP_CONST; |
4715 | TERM(sublex_start()); | |
4716 | ||
a0d0e21e LW |
4717 | case KEY_quotemeta: |
4718 | UNI(OP_QUOTEMETA); | |
4719 | ||
8990e307 | 4720 | case KEY_qw: |
09bef843 | 4721 | s = scan_str(s,FALSE,FALSE); |
8990e307 | 4722 | if (!s) |
85e6fe83 | 4723 | missingterm((char*)0); |
8127e0e3 GS |
4724 | force_next(')'); |
4725 | if (SvCUR(PL_lex_stuff)) { | |
4726 | OP *words = Nullop; | |
4727 | int warned = 0; | |
3280af22 | 4728 | d = SvPV_force(PL_lex_stuff, len); |
8127e0e3 | 4729 | while (len) { |
7948272d | 4730 | SV *sv; |
8127e0e3 GS |
4731 | for (; isSPACE(*d) && len; --len, ++d) ; |
4732 | if (len) { | |
4733 | char *b = d; | |
e476b1b5 | 4734 | if (!warned && ckWARN(WARN_QW)) { |
8127e0e3 GS |
4735 | for (; !isSPACE(*d) && len; --len, ++d) { |
4736 | if (*d == ',') { | |
e476b1b5 | 4737 | Perl_warner(aTHX_ WARN_QW, |
8127e0e3 GS |
4738 | "Possible attempt to separate words with commas"); |
4739 | ++warned; | |
4740 | } | |
4741 | else if (*d == '#') { | |
e476b1b5 | 4742 | Perl_warner(aTHX_ WARN_QW, |
8127e0e3 GS |
4743 | "Possible attempt to put comments in qw() list"); |
4744 | ++warned; | |
4745 | } | |
4746 | } | |
4747 | } | |
4748 | else { | |
4749 | for (; !isSPACE(*d) && len; --len, ++d) ; | |
4750 | } | |
7948272d NIS |
4751 | sv = newSVpvn(b, d-b); |
4752 | if (DO_UTF8(PL_lex_stuff)) | |
4753 | SvUTF8_on(sv); | |
8127e0e3 | 4754 | words = append_elem(OP_LIST, words, |
7948272d | 4755 | newSVOP(OP_CONST, 0, tokeq(sv))); |
55497cff | 4756 | } |
4757 | } | |
8127e0e3 GS |
4758 | if (words) { |
4759 | PL_nextval[PL_nexttoke].opval = words; | |
4760 | force_next(THING); | |
4761 | } | |
55497cff | 4762 | } |
37fd879b | 4763 | if (PL_lex_stuff) { |
8127e0e3 | 4764 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
4765 | PL_lex_stuff = Nullsv; |
4766 | } | |
3280af22 | 4767 | PL_expect = XTERM; |
8127e0e3 | 4768 | TOKEN('('); |
8990e307 | 4769 | |
79072805 | 4770 | case KEY_qq: |
09bef843 | 4771 | s = scan_str(s,FALSE,FALSE); |
79072805 | 4772 | if (!s) |
85e6fe83 | 4773 | missingterm((char*)0); |
a0d0e21e | 4774 | yylval.ival = OP_STRINGIFY; |
3280af22 NIS |
4775 | if (SvIVX(PL_lex_stuff) == '\'') |
4776 | SvIVX(PL_lex_stuff) = 0; /* qq'$foo' should intepolate */ | |
79072805 LW |
4777 | TERM(sublex_start()); |
4778 | ||
8782bef2 GB |
4779 | case KEY_qr: |
4780 | s = scan_pat(s,OP_QR); | |
4781 | TERM(sublex_start()); | |
4782 | ||
79072805 | 4783 | case KEY_qx: |
09bef843 | 4784 | s = scan_str(s,FALSE,FALSE); |
79072805 | 4785 | if (!s) |
85e6fe83 | 4786 | missingterm((char*)0); |
79072805 LW |
4787 | yylval.ival = OP_BACKTICK; |
4788 | set_csh(); | |
4789 | TERM(sublex_start()); | |
4790 | ||
4791 | case KEY_return: | |
4792 | OLDLOP(OP_RETURN); | |
4793 | ||
4794 | case KEY_require: | |
a7cb1f99 GS |
4795 | s = skipspace(s); |
4796 | if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) { | |
4797 | s = force_version(s); | |
4798 | } | |
4799 | else { | |
4800 | *PL_tokenbuf = '\0'; | |
4801 | s = force_word(s,WORD,TRUE,TRUE,FALSE); | |
7e2040f0 | 4802 | if (isIDFIRST_lazy_if(PL_tokenbuf,UTF)) |
a7cb1f99 GS |
4803 | gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE); |
4804 | else if (*s == '<') | |
4805 | yyerror("<> should be quotes"); | |
4806 | } | |
463ee0b2 | 4807 | UNI(OP_REQUIRE); |
79072805 LW |
4808 | |
4809 | case KEY_reset: | |
4810 | UNI(OP_RESET); | |
4811 | ||
4812 | case KEY_redo: | |
a0d0e21e | 4813 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4814 | LOOPX(OP_REDO); |
4815 | ||
4816 | case KEY_rename: | |
a0d0e21e | 4817 | LOP(OP_RENAME,XTERM); |
79072805 LW |
4818 | |
4819 | case KEY_rand: | |
4820 | UNI(OP_RAND); | |
4821 | ||
4822 | case KEY_rmdir: | |
4823 | UNI(OP_RMDIR); | |
4824 | ||
4825 | case KEY_rindex: | |
a0d0e21e | 4826 | LOP(OP_RINDEX,XTERM); |
79072805 LW |
4827 | |
4828 | case KEY_read: | |
a0d0e21e | 4829 | LOP(OP_READ,XTERM); |
79072805 LW |
4830 | |
4831 | case KEY_readdir: | |
4832 | UNI(OP_READDIR); | |
4833 | ||
93a17b20 LW |
4834 | case KEY_readline: |
4835 | set_csh(); | |
4836 | UNI(OP_READLINE); | |
4837 | ||
4838 | case KEY_readpipe: | |
4839 | set_csh(); | |
4840 | UNI(OP_BACKTICK); | |
4841 | ||
79072805 LW |
4842 | case KEY_rewinddir: |
4843 | UNI(OP_REWINDDIR); | |
4844 | ||
4845 | case KEY_recv: | |
a0d0e21e | 4846 | LOP(OP_RECV,XTERM); |
79072805 LW |
4847 | |
4848 | case KEY_reverse: | |
a0d0e21e | 4849 | LOP(OP_REVERSE,XTERM); |
79072805 LW |
4850 | |
4851 | case KEY_readlink: | |
4852 | UNI(OP_READLINK); | |
4853 | ||
4854 | case KEY_ref: | |
4855 | UNI(OP_REF); | |
4856 | ||
4857 | case KEY_s: | |
4858 | s = scan_subst(s); | |
4859 | if (yylval.opval) | |
4860 | TERM(sublex_start()); | |
4861 | else | |
4862 | TOKEN(1); /* force error */ | |
4863 | ||
a0d0e21e LW |
4864 | case KEY_chomp: |
4865 | UNI(OP_CHOMP); | |
4e553d73 | 4866 | |
79072805 LW |
4867 | case KEY_scalar: |
4868 | UNI(OP_SCALAR); | |
4869 | ||
4870 | case KEY_select: | |
a0d0e21e | 4871 | LOP(OP_SELECT,XTERM); |
79072805 LW |
4872 | |
4873 | case KEY_seek: | |
a0d0e21e | 4874 | LOP(OP_SEEK,XTERM); |
79072805 LW |
4875 | |
4876 | case KEY_semctl: | |
a0d0e21e | 4877 | LOP(OP_SEMCTL,XTERM); |
79072805 LW |
4878 | |
4879 | case KEY_semget: | |
a0d0e21e | 4880 | LOP(OP_SEMGET,XTERM); |
79072805 LW |
4881 | |
4882 | case KEY_semop: | |
a0d0e21e | 4883 | LOP(OP_SEMOP,XTERM); |
79072805 LW |
4884 | |
4885 | case KEY_send: | |
a0d0e21e | 4886 | LOP(OP_SEND,XTERM); |
79072805 LW |
4887 | |
4888 | case KEY_setpgrp: | |
a0d0e21e | 4889 | LOP(OP_SETPGRP,XTERM); |
79072805 LW |
4890 | |
4891 | case KEY_setpriority: | |
a0d0e21e | 4892 | LOP(OP_SETPRIORITY,XTERM); |
79072805 LW |
4893 | |
4894 | case KEY_sethostent: | |
ff68c719 | 4895 | UNI(OP_SHOSTENT); |
79072805 LW |
4896 | |
4897 | case KEY_setnetent: | |
ff68c719 | 4898 | UNI(OP_SNETENT); |
79072805 LW |
4899 | |
4900 | case KEY_setservent: | |
ff68c719 | 4901 | UNI(OP_SSERVENT); |
79072805 LW |
4902 | |
4903 | case KEY_setprotoent: | |
ff68c719 | 4904 | UNI(OP_SPROTOENT); |
79072805 LW |
4905 | |
4906 | case KEY_setpwent: | |
4907 | FUN0(OP_SPWENT); | |
4908 | ||
4909 | case KEY_setgrent: | |
4910 | FUN0(OP_SGRENT); | |
4911 | ||
4912 | case KEY_seekdir: | |
a0d0e21e | 4913 | LOP(OP_SEEKDIR,XTERM); |
79072805 LW |
4914 | |
4915 | case KEY_setsockopt: | |
a0d0e21e | 4916 | LOP(OP_SSOCKOPT,XTERM); |
79072805 LW |
4917 | |
4918 | case KEY_shift: | |
4919 | UNI(OP_SHIFT); | |
4920 | ||
4921 | case KEY_shmctl: | |
a0d0e21e | 4922 | LOP(OP_SHMCTL,XTERM); |
79072805 LW |
4923 | |
4924 | case KEY_shmget: | |
a0d0e21e | 4925 | LOP(OP_SHMGET,XTERM); |
79072805 LW |
4926 | |
4927 | case KEY_shmread: | |
a0d0e21e | 4928 | LOP(OP_SHMREAD,XTERM); |
79072805 LW |
4929 | |
4930 | case KEY_shmwrite: | |
a0d0e21e | 4931 | LOP(OP_SHMWRITE,XTERM); |
79072805 LW |
4932 | |
4933 | case KEY_shutdown: | |
a0d0e21e | 4934 | LOP(OP_SHUTDOWN,XTERM); |
79072805 LW |
4935 | |
4936 | case KEY_sin: | |
4937 | UNI(OP_SIN); | |
4938 | ||
4939 | case KEY_sleep: | |
4940 | UNI(OP_SLEEP); | |
4941 | ||
4942 | case KEY_socket: | |
a0d0e21e | 4943 | LOP(OP_SOCKET,XTERM); |
79072805 LW |
4944 | |
4945 | case KEY_socketpair: | |
a0d0e21e | 4946 | LOP(OP_SOCKPAIR,XTERM); |
79072805 LW |
4947 | |
4948 | case KEY_sort: | |
3280af22 | 4949 | checkcomma(s,PL_tokenbuf,"subroutine name"); |
79072805 LW |
4950 | s = skipspace(s); |
4951 | if (*s == ';' || *s == ')') /* probably a close */ | |
cea2e8a9 | 4952 | Perl_croak(aTHX_ "sort is now a reserved word"); |
3280af22 | 4953 | PL_expect = XTERM; |
15f0808c | 4954 | s = force_word(s,WORD,TRUE,TRUE,FALSE); |
a0d0e21e | 4955 | LOP(OP_SORT,XREF); |
79072805 LW |
4956 | |
4957 | case KEY_split: | |
a0d0e21e | 4958 | LOP(OP_SPLIT,XTERM); |
79072805 LW |
4959 | |
4960 | case KEY_sprintf: | |
a0d0e21e | 4961 | LOP(OP_SPRINTF,XTERM); |
79072805 LW |
4962 | |
4963 | case KEY_splice: | |
a0d0e21e | 4964 | LOP(OP_SPLICE,XTERM); |
79072805 LW |
4965 | |
4966 | case KEY_sqrt: | |
4967 | UNI(OP_SQRT); | |
4968 | ||
4969 | case KEY_srand: | |
4970 | UNI(OP_SRAND); | |
4971 | ||
4972 | case KEY_stat: | |
4973 | UNI(OP_STAT); | |
4974 | ||
4975 | case KEY_study: | |
79072805 LW |
4976 | UNI(OP_STUDY); |
4977 | ||
4978 | case KEY_substr: | |
a0d0e21e | 4979 | LOP(OP_SUBSTR,XTERM); |
79072805 LW |
4980 | |
4981 | case KEY_format: | |
4982 | case KEY_sub: | |
93a17b20 | 4983 | really_sub: |
09bef843 | 4984 | { |
3280af22 | 4985 | char tmpbuf[sizeof PL_tokenbuf]; |
b1b65b59 | 4986 | SSize_t tboffset; |
09bef843 SB |
4987 | expectation attrful; |
4988 | bool have_name, have_proto; | |
4989 | int key = tmp; | |
4990 | ||
4991 | s = skipspace(s); | |
4992 | ||
7e2040f0 | 4993 | if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' || |
09bef843 SB |
4994 | (*s == ':' && s[1] == ':')) |
4995 | { | |
4996 | PL_expect = XBLOCK; | |
4997 | attrful = XATTRBLOCK; | |
b1b65b59 JH |
4998 | /* remember buffer pos'n for later force_word */ |
4999 | tboffset = s - PL_oldbufptr; | |
09bef843 SB |
5000 | d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
5001 | if (strchr(tmpbuf, ':')) | |
5002 | sv_setpv(PL_subname, tmpbuf); | |
5003 | else { | |
5004 | sv_setsv(PL_subname,PL_curstname); | |
5005 | sv_catpvn(PL_subname,"::",2); | |
5006 | sv_catpvn(PL_subname,tmpbuf,len); | |
5007 | } | |
5008 | s = skipspace(d); | |
5009 | have_name = TRUE; | |
5010 | } | |
463ee0b2 | 5011 | else { |
09bef843 SB |
5012 | if (key == KEY_my) |
5013 | Perl_croak(aTHX_ "Missing name in \"my sub\""); | |
5014 | PL_expect = XTERMBLOCK; | |
5015 | attrful = XATTRTERM; | |
5016 | sv_setpv(PL_subname,"?"); | |
5017 | have_name = FALSE; | |
463ee0b2 | 5018 | } |
4633a7c4 | 5019 | |
09bef843 SB |
5020 | if (key == KEY_format) { |
5021 | if (*s == '=') | |
5022 | PL_lex_formbrack = PL_lex_brackets + 1; | |
5023 | if (have_name) | |
b1b65b59 JH |
5024 | (void) force_word(PL_oldbufptr + tboffset, WORD, |
5025 | FALSE, TRUE, TRUE); | |
09bef843 SB |
5026 | OPERATOR(FORMAT); |
5027 | } | |
79072805 | 5028 | |
09bef843 SB |
5029 | /* Look for a prototype */ |
5030 | if (*s == '(') { | |
5031 | char *p; | |
5032 | ||
5033 | s = scan_str(s,FALSE,FALSE); | |
37fd879b | 5034 | if (!s) |
09bef843 | 5035 | Perl_croak(aTHX_ "Prototype not terminated"); |
09bef843 SB |
5036 | /* strip spaces */ |
5037 | d = SvPVX(PL_lex_stuff); | |
5038 | tmp = 0; | |
5039 | for (p = d; *p; ++p) { | |
5040 | if (!isSPACE(*p)) | |
5041 | d[tmp++] = *p; | |
5042 | } | |
5043 | d[tmp] = '\0'; | |
5044 | SvCUR(PL_lex_stuff) = tmp; | |
5045 | have_proto = TRUE; | |
68dc0745 | 5046 | |
09bef843 | 5047 | s = skipspace(s); |
4633a7c4 | 5048 | } |
09bef843 SB |
5049 | else |
5050 | have_proto = FALSE; | |
5051 | ||
5052 | if (*s == ':' && s[1] != ':') | |
5053 | PL_expect = attrful; | |
5054 | ||
5055 | if (have_proto) { | |
b1b65b59 JH |
5056 | PL_nextval[PL_nexttoke].opval = |
5057 | (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff); | |
09bef843 SB |
5058 | PL_lex_stuff = Nullsv; |
5059 | force_next(THING); | |
68dc0745 | 5060 | } |
09bef843 SB |
5061 | if (!have_name) { |
5062 | sv_setpv(PL_subname,"__ANON__"); | |
5063 | TOKEN(ANONSUB); | |
4633a7c4 | 5064 | } |
b1b65b59 JH |
5065 | (void) force_word(PL_oldbufptr + tboffset, WORD, |
5066 | FALSE, TRUE, TRUE); | |
09bef843 SB |
5067 | if (key == KEY_my) |
5068 | TOKEN(MYSUB); | |
5069 | TOKEN(SUB); | |
4633a7c4 | 5070 | } |
79072805 LW |
5071 | |
5072 | case KEY_system: | |
5073 | set_csh(); | |
a0d0e21e | 5074 | LOP(OP_SYSTEM,XREF); |
79072805 LW |
5075 | |
5076 | case KEY_symlink: | |
a0d0e21e | 5077 | LOP(OP_SYMLINK,XTERM); |
79072805 LW |
5078 | |
5079 | case KEY_syscall: | |
a0d0e21e | 5080 | LOP(OP_SYSCALL,XTERM); |
79072805 | 5081 | |
c07a80fd | 5082 | case KEY_sysopen: |
5083 | LOP(OP_SYSOPEN,XTERM); | |
5084 | ||
137443ea | 5085 | case KEY_sysseek: |
5086 | LOP(OP_SYSSEEK,XTERM); | |
5087 | ||
79072805 | 5088 | case KEY_sysread: |
a0d0e21e | 5089 | LOP(OP_SYSREAD,XTERM); |
79072805 LW |
5090 | |
5091 | case KEY_syswrite: | |
a0d0e21e | 5092 | LOP(OP_SYSWRITE,XTERM); |
79072805 LW |
5093 | |
5094 | case KEY_tr: | |
5095 | s = scan_trans(s); | |
5096 | TERM(sublex_start()); | |
5097 | ||
5098 | case KEY_tell: | |
5099 | UNI(OP_TELL); | |
5100 | ||
5101 | case KEY_telldir: | |
5102 | UNI(OP_TELLDIR); | |
5103 | ||
463ee0b2 | 5104 | case KEY_tie: |
a0d0e21e | 5105 | LOP(OP_TIE,XTERM); |
463ee0b2 | 5106 | |
c07a80fd | 5107 | case KEY_tied: |
5108 | UNI(OP_TIED); | |
5109 | ||
79072805 LW |
5110 | case KEY_time: |
5111 | FUN0(OP_TIME); | |
5112 | ||
5113 | case KEY_times: | |
5114 | FUN0(OP_TMS); | |
5115 | ||
5116 | case KEY_truncate: | |
a0d0e21e | 5117 | LOP(OP_TRUNCATE,XTERM); |
79072805 LW |
5118 | |
5119 | case KEY_uc: | |
5120 | UNI(OP_UC); | |
5121 | ||
5122 | case KEY_ucfirst: | |
5123 | UNI(OP_UCFIRST); | |
5124 | ||
463ee0b2 LW |
5125 | case KEY_untie: |
5126 | UNI(OP_UNTIE); | |
5127 | ||
79072805 | 5128 | case KEY_until: |
57843af0 | 5129 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5130 | OPERATOR(UNTIL); |
5131 | ||
5132 | case KEY_unless: | |
57843af0 | 5133 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5134 | OPERATOR(UNLESS); |
5135 | ||
5136 | case KEY_unlink: | |
a0d0e21e | 5137 | LOP(OP_UNLINK,XTERM); |
79072805 LW |
5138 | |
5139 | case KEY_undef: | |
5140 | UNI(OP_UNDEF); | |
5141 | ||
5142 | case KEY_unpack: | |
a0d0e21e | 5143 | LOP(OP_UNPACK,XTERM); |
79072805 LW |
5144 | |
5145 | case KEY_utime: | |
a0d0e21e | 5146 | LOP(OP_UTIME,XTERM); |
79072805 LW |
5147 | |
5148 | case KEY_umask: | |
e476b1b5 | 5149 | if (ckWARN(WARN_UMASK)) { |
3280af22 | 5150 | for (d = s; d < PL_bufend && (isSPACE(*d) || *d == '('); d++) ; |
4e553d73 | 5151 | if (*d != '0' && isDIGIT(*d)) |
e476b1b5 | 5152 | Perl_warner(aTHX_ WARN_UMASK, |
4438c4b7 | 5153 | "umask: argument is missing initial 0"); |
748a9306 | 5154 | } |
79072805 LW |
5155 | UNI(OP_UMASK); |
5156 | ||
5157 | case KEY_unshift: | |
a0d0e21e LW |
5158 | LOP(OP_UNSHIFT,XTERM); |
5159 | ||
5160 | case KEY_use: | |
3280af22 | 5161 | if (PL_expect != XSTATE) |
a0d0e21e | 5162 | yyerror("\"use\" not allowed in expression"); |
89bfa8cd | 5163 | s = skipspace(s); |
a7cb1f99 | 5164 | if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) { |
89bfa8cd | 5165 | s = force_version(s); |
a7cb1f99 | 5166 | if (*s == ';' || (s = skipspace(s), *s == ';')) { |
3280af22 | 5167 | PL_nextval[PL_nexttoke].opval = Nullop; |
89bfa8cd | 5168 | force_next(WORD); |
5169 | } | |
5170 | } | |
5171 | else { | |
5172 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
5173 | s = force_version(s); | |
5174 | } | |
a0d0e21e LW |
5175 | yylval.ival = 1; |
5176 | OPERATOR(USE); | |
79072805 LW |
5177 | |
5178 | case KEY_values: | |
5179 | UNI(OP_VALUES); | |
5180 | ||
5181 | case KEY_vec: | |
a0d0e21e | 5182 | LOP(OP_VEC,XTERM); |
79072805 LW |
5183 | |
5184 | case KEY_while: | |
57843af0 | 5185 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5186 | OPERATOR(WHILE); |
5187 | ||
5188 | case KEY_warn: | |
3280af22 | 5189 | PL_hints |= HINT_BLOCK_SCOPE; |
a0d0e21e | 5190 | LOP(OP_WARN,XTERM); |
79072805 LW |
5191 | |
5192 | case KEY_wait: | |
5193 | FUN0(OP_WAIT); | |
5194 | ||
5195 | case KEY_waitpid: | |
a0d0e21e | 5196 | LOP(OP_WAITPID,XTERM); |
79072805 LW |
5197 | |
5198 | case KEY_wantarray: | |
5199 | FUN0(OP_WANTARRAY); | |
5200 | ||
5201 | case KEY_write: | |
9d116dd7 JH |
5202 | #ifdef EBCDIC |
5203 | { | |
5204 | static char ctl_l[2]; | |
5205 | ||
4e553d73 | 5206 | if (ctl_l[0] == '\0') |
9d116dd7 JH |
5207 | ctl_l[0] = toCTRL('L'); |
5208 | gv_fetchpv(ctl_l,TRUE, SVt_PV); | |
5209 | } | |
5210 | #else | |
5211 | gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */ | |
5212 | #endif | |
79072805 LW |
5213 | UNI(OP_ENTERWRITE); |
5214 | ||
5215 | case KEY_x: | |
3280af22 | 5216 | if (PL_expect == XOPERATOR) |
79072805 LW |
5217 | Mop(OP_REPEAT); |
5218 | check_uni(); | |
5219 | goto just_a_word; | |
5220 | ||
a0d0e21e LW |
5221 | case KEY_xor: |
5222 | yylval.ival = OP_XOR; | |
5223 | OPERATOR(OROP); | |
5224 | ||
79072805 LW |
5225 | case KEY_y: |
5226 | s = scan_trans(s); | |
5227 | TERM(sublex_start()); | |
5228 | } | |
49dc05e3 | 5229 | }} |
79072805 | 5230 | } |
bf4acbe4 GS |
5231 | #ifdef __SC__ |
5232 | #pragma segment Main | |
5233 | #endif | |
79072805 LW |
5234 | |
5235 | I32 | |
864dbfa3 | 5236 | Perl_keyword(pTHX_ register char *d, I32 len) |
79072805 LW |
5237 | { |
5238 | switch (*d) { | |
5239 | case '_': | |
5240 | if (d[1] == '_') { | |
a0d0e21e | 5241 | if (strEQ(d,"__FILE__")) return -KEY___FILE__; |
68dc0745 | 5242 | if (strEQ(d,"__LINE__")) return -KEY___LINE__; |
5243 | if (strEQ(d,"__PACKAGE__")) return -KEY___PACKAGE__; | |
e50aee73 | 5244 | if (strEQ(d,"__DATA__")) return KEY___DATA__; |
79072805 LW |
5245 | if (strEQ(d,"__END__")) return KEY___END__; |
5246 | } | |
5247 | break; | |
8990e307 LW |
5248 | case 'A': |
5249 | if (strEQ(d,"AUTOLOAD")) return KEY_AUTOLOAD; | |
5250 | break; | |
79072805 | 5251 | case 'a': |
463ee0b2 LW |
5252 | switch (len) { |
5253 | case 3: | |
a0d0e21e LW |
5254 | if (strEQ(d,"and")) return -KEY_and; |
5255 | if (strEQ(d,"abs")) return -KEY_abs; | |
85e6fe83 | 5256 | break; |
463ee0b2 | 5257 | case 5: |
a0d0e21e LW |
5258 | if (strEQ(d,"alarm")) return -KEY_alarm; |
5259 | if (strEQ(d,"atan2")) return -KEY_atan2; | |
463ee0b2 LW |
5260 | break; |
5261 | case 6: | |
a0d0e21e | 5262 | if (strEQ(d,"accept")) return -KEY_accept; |
463ee0b2 LW |
5263 | break; |
5264 | } | |
79072805 LW |
5265 | break; |
5266 | case 'B': | |
5267 | if (strEQ(d,"BEGIN")) return KEY_BEGIN; | |
93a17b20 | 5268 | break; |
79072805 | 5269 | case 'b': |
a0d0e21e LW |
5270 | if (strEQ(d,"bless")) return -KEY_bless; |
5271 | if (strEQ(d,"bind")) return -KEY_bind; | |
5272 | if (strEQ(d,"binmode")) return -KEY_binmode; | |
5273 | break; | |
5274 | case 'C': | |
5275 | if (strEQ(d,"CORE")) return -KEY_CORE; | |
7d30b5c4 | 5276 | if (strEQ(d,"CHECK")) return KEY_CHECK; |
79072805 LW |
5277 | break; |
5278 | case 'c': | |
5279 | switch (len) { | |
5280 | case 3: | |
a0d0e21e LW |
5281 | if (strEQ(d,"cmp")) return -KEY_cmp; |
5282 | if (strEQ(d,"chr")) return -KEY_chr; | |
5283 | if (strEQ(d,"cos")) return -KEY_cos; | |
79072805 LW |
5284 | break; |
5285 | case 4: | |
79e5458b | 5286 | if (strEQ(d,"chop")) return -KEY_chop; |
79072805 LW |
5287 | break; |
5288 | case 5: | |
a0d0e21e LW |
5289 | if (strEQ(d,"close")) return -KEY_close; |
5290 | if (strEQ(d,"chdir")) return -KEY_chdir; | |
79e5458b | 5291 | if (strEQ(d,"chomp")) return -KEY_chomp; |
a0d0e21e LW |
5292 | if (strEQ(d,"chmod")) return -KEY_chmod; |
5293 | if (strEQ(d,"chown")) return -KEY_chown; | |
5294 | if (strEQ(d,"crypt")) return -KEY_crypt; | |
79072805 LW |
5295 | break; |
5296 | case 6: | |
a0d0e21e LW |
5297 | if (strEQ(d,"chroot")) return -KEY_chroot; |
5298 | if (strEQ(d,"caller")) return -KEY_caller; | |
79072805 LW |
5299 | break; |
5300 | case 7: | |
a0d0e21e | 5301 | if (strEQ(d,"connect")) return -KEY_connect; |
79072805 LW |
5302 | break; |
5303 | case 8: | |
a0d0e21e LW |
5304 | if (strEQ(d,"closedir")) return -KEY_closedir; |
5305 | if (strEQ(d,"continue")) return -KEY_continue; | |
79072805 LW |
5306 | break; |
5307 | } | |
5308 | break; | |
ed6116ce LW |
5309 | case 'D': |
5310 | if (strEQ(d,"DESTROY")) return KEY_DESTROY; | |
5311 | break; | |
79072805 LW |
5312 | case 'd': |
5313 | switch (len) { | |
5314 | case 2: | |
5315 | if (strEQ(d,"do")) return KEY_do; | |
5316 | break; | |
5317 | case 3: | |
a0d0e21e | 5318 | if (strEQ(d,"die")) return -KEY_die; |
79072805 LW |
5319 | break; |
5320 | case 4: | |
a0d0e21e | 5321 | if (strEQ(d,"dump")) return -KEY_dump; |
79072805 LW |
5322 | break; |
5323 | case 6: | |
5324 | if (strEQ(d,"delete")) return KEY_delete; | |
5325 | break; | |
5326 | case 7: | |
5327 | if (strEQ(d,"defined")) return KEY_defined; | |
a0d0e21e | 5328 | if (strEQ(d,"dbmopen")) return -KEY_dbmopen; |
79072805 LW |
5329 | break; |
5330 | case 8: | |
a0d0e21e | 5331 | if (strEQ(d,"dbmclose")) return -KEY_dbmclose; |
79072805 LW |
5332 | break; |
5333 | } | |
5334 | break; | |
5335 | case 'E': | |
79072805 LW |
5336 | if (strEQ(d,"END")) return KEY_END; |
5337 | break; | |
5338 | case 'e': | |
5339 | switch (len) { | |
5340 | case 2: | |
a0d0e21e | 5341 | if (strEQ(d,"eq")) return -KEY_eq; |
79072805 LW |
5342 | break; |
5343 | case 3: | |
a0d0e21e LW |
5344 | if (strEQ(d,"eof")) return -KEY_eof; |
5345 | if (strEQ(d,"exp")) return -KEY_exp; | |
79072805 LW |
5346 | break; |
5347 | case 4: | |
5348 | if (strEQ(d,"else")) return KEY_else; | |
a0d0e21e | 5349 | if (strEQ(d,"exit")) return -KEY_exit; |
79072805 | 5350 | if (strEQ(d,"eval")) return KEY_eval; |
a0d0e21e | 5351 | if (strEQ(d,"exec")) return -KEY_exec; |
3a6a8333 | 5352 | if (strEQ(d,"each")) return -KEY_each; |
79072805 LW |
5353 | break; |
5354 | case 5: | |
5355 | if (strEQ(d,"elsif")) return KEY_elsif; | |
5356 | break; | |
a0d0e21e LW |
5357 | case 6: |
5358 | if (strEQ(d,"exists")) return KEY_exists; | |
cea2e8a9 | 5359 | if (strEQ(d,"elseif")) Perl_warn(aTHX_ "elseif should be elsif"); |
a0d0e21e | 5360 | break; |
79072805 | 5361 | case 8: |
a0d0e21e LW |
5362 | if (strEQ(d,"endgrent")) return -KEY_endgrent; |
5363 | if (strEQ(d,"endpwent")) return -KEY_endpwent; | |
79072805 LW |
5364 | break; |
5365 | case 9: | |
a0d0e21e | 5366 | if (strEQ(d,"endnetent")) return -KEY_endnetent; |
79072805 LW |
5367 | break; |
5368 | case 10: | |
a0d0e21e LW |
5369 | if (strEQ(d,"endhostent")) return -KEY_endhostent; |
5370 | if (strEQ(d,"endservent")) return -KEY_endservent; | |
79072805 LW |
5371 | break; |
5372 | case 11: | |
a0d0e21e | 5373 | if (strEQ(d,"endprotoent")) return -KEY_endprotoent; |
79072805 | 5374 | break; |
a687059c | 5375 | } |
a687059c | 5376 | break; |
79072805 LW |
5377 | case 'f': |
5378 | switch (len) { | |
5379 | case 3: | |
5380 | if (strEQ(d,"for")) return KEY_for; | |
5381 | break; | |
5382 | case 4: | |
a0d0e21e | 5383 | if (strEQ(d,"fork")) return -KEY_fork; |
79072805 LW |
5384 | break; |
5385 | case 5: | |
a0d0e21e LW |
5386 | if (strEQ(d,"fcntl")) return -KEY_fcntl; |
5387 | if (strEQ(d,"flock")) return -KEY_flock; | |
79072805 LW |
5388 | break; |
5389 | case 6: | |
5390 | if (strEQ(d,"format")) return KEY_format; | |
a0d0e21e | 5391 | if (strEQ(d,"fileno")) return -KEY_fileno; |
79072805 LW |
5392 | break; |
5393 | case 7: | |
5394 | if (strEQ(d,"foreach")) return KEY_foreach; | |
5395 | break; | |
5396 | case 8: | |
a0d0e21e | 5397 | if (strEQ(d,"formline")) return -KEY_formline; |
79072805 | 5398 | break; |
378cc40b | 5399 | } |
a687059c | 5400 | break; |
79072805 | 5401 | case 'g': |
a687059c LW |
5402 | if (strnEQ(d,"get",3)) { |
5403 | d += 3; | |
5404 | if (*d == 'p') { | |
79072805 LW |
5405 | switch (len) { |
5406 | case 7: | |
a0d0e21e LW |
5407 | if (strEQ(d,"ppid")) return -KEY_getppid; |
5408 | if (strEQ(d,"pgrp")) return -KEY_getpgrp; | |
79072805 LW |
5409 | break; |
5410 | case 8: | |
a0d0e21e LW |
5411 | if (strEQ(d,"pwent")) return -KEY_getpwent; |
5412 | if (strEQ(d,"pwnam")) return -KEY_getpwnam; | |
5413 | if (strEQ(d,"pwuid")) return -KEY_getpwuid; | |
79072805 LW |
5414 | break; |
5415 | case 11: | |
a0d0e21e LW |
5416 | if (strEQ(d,"peername")) return -KEY_getpeername; |
5417 | if (strEQ(d,"protoent")) return -KEY_getprotoent; | |
5418 | if (strEQ(d,"priority")) return -KEY_getpriority; | |
79072805 LW |
5419 | break; |
5420 | case 14: | |
a0d0e21e | 5421 | if (strEQ(d,"protobyname")) return -KEY_getprotobyname; |
79072805 LW |
5422 | break; |
5423 | case 16: | |
a0d0e21e | 5424 | if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber; |
79072805 LW |
5425 | break; |
5426 | } | |
a687059c LW |
5427 | } |
5428 | else if (*d == 'h') { | |
a0d0e21e LW |
5429 | if (strEQ(d,"hostbyname")) return -KEY_gethostbyname; |
5430 | if (strEQ(d,"hostbyaddr")) return -KEY_gethostbyaddr; | |
5431 | if (strEQ(d,"hostent")) return -KEY_gethostent; | |
a687059c LW |
5432 | } |
5433 | else if (*d == 'n') { | |
a0d0e21e LW |
5434 | if (strEQ(d,"netbyname")) return -KEY_getnetbyname; |
5435 | if (strEQ(d,"netbyaddr")) return -KEY_getnetbyaddr; | |
5436 | if (strEQ(d,"netent")) return -KEY_getnetent; | |
a687059c LW |
5437 | } |
5438 | else if (*d == 's') { | |
a0d0e21e LW |
5439 | if (strEQ(d,"servbyname")) return -KEY_getservbyname; |
5440 | if (strEQ(d,"servbyport")) return -KEY_getservbyport; | |
5441 | if (strEQ(d,"servent")) return -KEY_getservent; | |
5442 | if (strEQ(d,"sockname")) return -KEY_getsockname; | |
5443 | if (strEQ(d,"sockopt")) return -KEY_getsockopt; | |
a687059c LW |
5444 | } |
5445 | else if (*d == 'g') { | |
a0d0e21e LW |
5446 | if (strEQ(d,"grent")) return -KEY_getgrent; |
5447 | if (strEQ(d,"grnam")) return -KEY_getgrnam; | |
5448 | if (strEQ(d,"grgid")) return -KEY_getgrgid; | |
a687059c LW |
5449 | } |
5450 | else if (*d == 'l') { | |
a0d0e21e | 5451 | if (strEQ(d,"login")) return -KEY_getlogin; |
a687059c | 5452 | } |
a0d0e21e | 5453 | else if (strEQ(d,"c")) return -KEY_getc; |
79072805 | 5454 | break; |
a687059c | 5455 | } |
79072805 LW |
5456 | switch (len) { |
5457 | case 2: | |
a0d0e21e LW |
5458 | if (strEQ(d,"gt")) return -KEY_gt; |
5459 | if (strEQ(d,"ge")) return -KEY_ge; | |
79072805 LW |
5460 | break; |
5461 | case 4: | |
5462 | if (strEQ(d,"grep")) return KEY_grep; | |
5463 | if (strEQ(d,"goto")) return KEY_goto; | |
fb73857a | 5464 | if (strEQ(d,"glob")) return KEY_glob; |
79072805 LW |
5465 | break; |
5466 | case 6: | |
a0d0e21e | 5467 | if (strEQ(d,"gmtime")) return -KEY_gmtime; |
79072805 | 5468 | break; |
378cc40b | 5469 | } |
a687059c | 5470 | break; |
79072805 | 5471 | case 'h': |
a0d0e21e | 5472 | if (strEQ(d,"hex")) return -KEY_hex; |
a687059c | 5473 | break; |
7d07dbc2 MB |
5474 | case 'I': |
5475 | if (strEQ(d,"INIT")) return KEY_INIT; | |
5476 | break; | |
79072805 LW |
5477 | case 'i': |
5478 | switch (len) { | |
5479 | case 2: | |
5480 | if (strEQ(d,"if")) return KEY_if; | |
5481 | break; | |
5482 | case 3: | |
a0d0e21e | 5483 | if (strEQ(d,"int")) return -KEY_int; |
79072805 LW |
5484 | break; |
5485 | case 5: | |
a0d0e21e LW |
5486 | if (strEQ(d,"index")) return -KEY_index; |
5487 | if (strEQ(d,"ioctl")) return -KEY_ioctl; | |
79072805 LW |
5488 | break; |
5489 | } | |
a687059c | 5490 | break; |
79072805 | 5491 | case 'j': |
a0d0e21e | 5492 | if (strEQ(d,"join")) return -KEY_join; |
a687059c | 5493 | break; |
79072805 LW |
5494 | case 'k': |
5495 | if (len == 4) { | |
3a6a8333 | 5496 | if (strEQ(d,"keys")) return -KEY_keys; |
a0d0e21e | 5497 | if (strEQ(d,"kill")) return -KEY_kill; |
663a0e37 | 5498 | } |
79072805 | 5499 | break; |
79072805 LW |
5500 | case 'l': |
5501 | switch (len) { | |
5502 | case 2: | |
a0d0e21e LW |
5503 | if (strEQ(d,"lt")) return -KEY_lt; |
5504 | if (strEQ(d,"le")) return -KEY_le; | |
5505 | if (strEQ(d,"lc")) return -KEY_lc; | |
79072805 LW |
5506 | break; |
5507 | case 3: | |
a0d0e21e | 5508 | if (strEQ(d,"log")) return -KEY_log; |
79072805 LW |
5509 | break; |
5510 | case 4: | |
5511 | if (strEQ(d,"last")) return KEY_last; | |
a0d0e21e | 5512 | if (strEQ(d,"link")) return -KEY_link; |
c0329465 | 5513 | if (strEQ(d,"lock")) return -KEY_lock; |
395c3793 | 5514 | break; |
79072805 LW |
5515 | case 5: |
5516 | if (strEQ(d,"local")) return KEY_local; | |
a0d0e21e | 5517 | if (strEQ(d,"lstat")) return -KEY_lstat; |
79072805 LW |
5518 | break; |
5519 | case 6: | |
a0d0e21e LW |
5520 | if (strEQ(d,"length")) return -KEY_length; |
5521 | if (strEQ(d,"listen")) return -KEY_listen; | |
79072805 LW |
5522 | break; |
5523 | case 7: | |
a0d0e21e | 5524 | if (strEQ(d,"lcfirst")) return -KEY_lcfirst; |
79072805 LW |
5525 | break; |
5526 | case 9: | |
a0d0e21e | 5527 | if (strEQ(d,"localtime")) return -KEY_localtime; |
395c3793 LW |
5528 | break; |
5529 | } | |
a687059c | 5530 | break; |
79072805 LW |
5531 | case 'm': |
5532 | switch (len) { | |
5533 | case 1: return KEY_m; | |
93a17b20 LW |
5534 | case 2: |
5535 | if (strEQ(d,"my")) return KEY_my; | |
5536 | break; | |
a0d0e21e LW |
5537 | case 3: |
5538 | if (strEQ(d,"map")) return KEY_map; | |
5539 | break; | |
79072805 | 5540 | case 5: |
a0d0e21e | 5541 | if (strEQ(d,"mkdir")) return -KEY_mkdir; |
79072805 LW |
5542 | break; |
5543 | case 6: | |
a0d0e21e LW |
5544 | if (strEQ(d,"msgctl")) return -KEY_msgctl; |
5545 | if (strEQ(d,"msgget")) return -KEY_msgget; | |
5546 | if (strEQ(d,"msgrcv")) return -KEY_msgrcv; | |
5547 | if (strEQ(d,"msgsnd")) return -KEY_msgsnd; | |
79072805 LW |
5548 | break; |
5549 | } | |
a687059c | 5550 | break; |
79072805 LW |
5551 | case 'n': |
5552 | if (strEQ(d,"next")) return KEY_next; | |
a0d0e21e LW |
5553 | if (strEQ(d,"ne")) return -KEY_ne; |
5554 | if (strEQ(d,"not")) return -KEY_not; | |
5555 | if (strEQ(d,"no")) return KEY_no; | |
a687059c | 5556 | break; |
79072805 LW |
5557 | case 'o': |
5558 | switch (len) { | |
463ee0b2 | 5559 | case 2: |
a0d0e21e | 5560 | if (strEQ(d,"or")) return -KEY_or; |
463ee0b2 | 5561 | break; |
79072805 | 5562 | case 3: |
a0d0e21e LW |
5563 | if (strEQ(d,"ord")) return -KEY_ord; |
5564 | if (strEQ(d,"oct")) return -KEY_oct; | |
77ca0c92 | 5565 | if (strEQ(d,"our")) return KEY_our; |
79072805 LW |
5566 | break; |
5567 | case 4: | |
a0d0e21e | 5568 | if (strEQ(d,"open")) return -KEY_open; |
79072805 LW |
5569 | break; |
5570 | case 7: | |
a0d0e21e | 5571 | if (strEQ(d,"opendir")) return -KEY_opendir; |
79072805 | 5572 | break; |
fe14fcc3 | 5573 | } |
a687059c | 5574 | break; |
79072805 LW |
5575 | case 'p': |
5576 | switch (len) { | |
5577 | case 3: | |
4e553d73 | 5578 | if (strEQ(d,"pop")) return -KEY_pop; |
a0d0e21e | 5579 | if (strEQ(d,"pos")) return KEY_pos; |
79072805 LW |
5580 | break; |
5581 | case 4: | |
3a6a8333 | 5582 | if (strEQ(d,"push")) return -KEY_push; |
a0d0e21e LW |
5583 | if (strEQ(d,"pack")) return -KEY_pack; |
5584 | if (strEQ(d,"pipe")) return -KEY_pipe; | |
79072805 LW |
5585 | break; |
5586 | case 5: | |
5587 | if (strEQ(d,"print")) return KEY_print; | |
5588 | break; | |
5589 | case 6: | |
5590 | if (strEQ(d,"printf")) return KEY_printf; | |
5591 | break; | |
5592 | case 7: | |
5593 | if (strEQ(d,"package")) return KEY_package; | |
5594 | break; | |
c07a80fd | 5595 | case 9: |
5596 | if (strEQ(d,"prototype")) return KEY_prototype; | |
663a0e37 | 5597 | } |
79072805 LW |
5598 | break; |
5599 | case 'q': | |
5600 | if (len <= 2) { | |
5601 | if (strEQ(d,"q")) return KEY_q; | |
8782bef2 | 5602 | if (strEQ(d,"qr")) return KEY_qr; |
79072805 | 5603 | if (strEQ(d,"qq")) return KEY_qq; |
8990e307 | 5604 | if (strEQ(d,"qw")) return KEY_qw; |
79072805 | 5605 | if (strEQ(d,"qx")) return KEY_qx; |
663a0e37 | 5606 | } |
a0d0e21e | 5607 | else if (strEQ(d,"quotemeta")) return -KEY_quotemeta; |
79072805 LW |
5608 | break; |
5609 | case 'r': | |
5610 | switch (len) { | |
5611 | case 3: | |
a0d0e21e | 5612 | if (strEQ(d,"ref")) return -KEY_ref; |
79072805 LW |
5613 | break; |
5614 | case 4: | |
a0d0e21e LW |
5615 | if (strEQ(d,"read")) return -KEY_read; |
5616 | if (strEQ(d,"rand")) return -KEY_rand; | |
5617 | if (strEQ(d,"recv")) return -KEY_recv; | |
79072805 LW |
5618 | if (strEQ(d,"redo")) return KEY_redo; |
5619 | break; | |
5620 | case 5: | |
a0d0e21e LW |
5621 | if (strEQ(d,"rmdir")) return -KEY_rmdir; |
5622 | if (strEQ(d,"reset")) return -KEY_reset; | |
79072805 LW |
5623 | break; |
5624 | case 6: | |
5625 | if (strEQ(d,"return")) return KEY_return; | |
a0d0e21e LW |
5626 | if (strEQ(d,"rename")) return -KEY_rename; |
5627 | if (strEQ(d,"rindex")) return -KEY_rindex; | |
79072805 LW |
5628 | break; |
5629 | case 7: | |
a0d0e21e LW |
5630 | if (strEQ(d,"require")) return -KEY_require; |
5631 | if (strEQ(d,"reverse")) return -KEY_reverse; | |
5632 | if (strEQ(d,"readdir")) return -KEY_readdir; | |
79072805 LW |
5633 | break; |
5634 | case 8: | |
a0d0e21e LW |
5635 | if (strEQ(d,"readlink")) return -KEY_readlink; |
5636 | if (strEQ(d,"readline")) return -KEY_readline; | |
5637 | if (strEQ(d,"readpipe")) return -KEY_readpipe; | |
79072805 LW |
5638 | break; |
5639 | case 9: | |
a0d0e21e | 5640 | if (strEQ(d,"rewinddir")) return -KEY_rewinddir; |
79072805 | 5641 | break; |
a687059c | 5642 | } |
79072805 LW |
5643 | break; |
5644 | case 's': | |
a687059c | 5645 | switch (d[1]) { |
79072805 | 5646 | case 0: return KEY_s; |
a687059c | 5647 | case 'c': |
79072805 | 5648 | if (strEQ(d,"scalar")) return KEY_scalar; |
a687059c LW |
5649 | break; |
5650 | case 'e': | |
79072805 LW |
5651 | switch (len) { |
5652 | case 4: | |
a0d0e21e LW |
5653 | if (strEQ(d,"seek")) return -KEY_seek; |
5654 | if (strEQ(d,"send")) return -KEY_send; | |
79072805 LW |
5655 | break; |
5656 | case 5: | |
a0d0e21e | 5657 | if (strEQ(d,"semop")) return -KEY_semop; |
79072805 LW |
5658 | break; |
5659 | case 6: | |
a0d0e21e LW |
5660 | if (strEQ(d,"select")) return -KEY_select; |
5661 | if (strEQ(d,"semctl")) return -KEY_semctl; | |
5662 | if (strEQ(d,"semget")) return -KEY_semget; | |
79072805 LW |
5663 | break; |
5664 | case 7: | |
a0d0e21e LW |
5665 | if (strEQ(d,"setpgrp")) return -KEY_setpgrp; |
5666 | if (strEQ(d,"seekdir")) return -KEY_seekdir; | |
79072805 LW |
5667 | break; |
5668 | case 8: | |
a0d0e21e LW |
5669 | if (strEQ(d,"setpwent")) return -KEY_setpwent; |
5670 | if (strEQ(d,"setgrent")) return -KEY_setgrent; | |
79072805 LW |
5671 | break; |
5672 | case 9: | |
a0d0e21e | 5673 | if (strEQ(d,"setnetent")) return -KEY_setnetent; |
79072805 LW |
5674 | break; |
5675 | case 10: | |
a0d0e21e LW |
5676 | if (strEQ(d,"setsockopt")) return -KEY_setsockopt; |
5677 | if (strEQ(d,"sethostent")) return -KEY_sethostent; | |
5678 | if (strEQ(d,"setservent")) return -KEY_setservent; | |
79072805 LW |
5679 | break; |
5680 | case 11: | |
a0d0e21e LW |
5681 | if (strEQ(d,"setpriority")) return -KEY_setpriority; |
5682 | if (strEQ(d,"setprotoent")) return -KEY_setprotoent; | |
79072805 LW |
5683 | break; |
5684 | } | |
a687059c LW |
5685 | break; |
5686 | case 'h': | |
79072805 LW |
5687 | switch (len) { |
5688 | case 5: | |
3a6a8333 | 5689 | if (strEQ(d,"shift")) return -KEY_shift; |
79072805 LW |
5690 | break; |
5691 | case 6: | |
a0d0e21e LW |
5692 | if (strEQ(d,"shmctl")) return -KEY_shmctl; |
5693 | if (strEQ(d,"shmget")) return -KEY_shmget; | |
79072805 LW |
5694 | break; |
5695 | case 7: | |
a0d0e21e | 5696 | if (strEQ(d,"shmread")) return -KEY_shmread; |
79072805 LW |
5697 | break; |
5698 | case 8: | |
a0d0e21e LW |
5699 | if (strEQ(d,"shmwrite")) return -KEY_shmwrite; |
5700 | if (strEQ(d,"shutdown")) return -KEY_shutdown; | |
79072805 LW |
5701 | break; |
5702 | } | |
a687059c LW |
5703 | break; |
5704 | case 'i': | |
a0d0e21e | 5705 | if (strEQ(d,"sin")) return -KEY_sin; |
a687059c LW |
5706 | break; |
5707 | case 'l': | |
a0d0e21e | 5708 | if (strEQ(d,"sleep")) return -KEY_sleep; |
a687059c LW |
5709 | break; |
5710 | case 'o': | |
79072805 | 5711 | if (strEQ(d,"sort")) return KEY_sort; |
a0d0e21e LW |
5712 | if (strEQ(d,"socket")) return -KEY_socket; |
5713 | if (strEQ(d,"socketpair")) return -KEY_socketpair; | |
a687059c LW |
5714 | break; |
5715 | case 'p': | |
79072805 | 5716 | if (strEQ(d,"split")) return KEY_split; |
a0d0e21e | 5717 | if (strEQ(d,"sprintf")) return -KEY_sprintf; |
3a6a8333 | 5718 | if (strEQ(d,"splice")) return -KEY_splice; |
a687059c LW |
5719 | break; |
5720 | case 'q': | |
a0d0e21e | 5721 | if (strEQ(d,"sqrt")) return -KEY_sqrt; |
a687059c LW |
5722 | break; |
5723 | case 'r': | |
a0d0e21e | 5724 | if (strEQ(d,"srand")) return -KEY_srand; |
a687059c LW |
5725 | break; |
5726 | case 't': | |
a0d0e21e | 5727 | if (strEQ(d,"stat")) return -KEY_stat; |
79072805 | 5728 | if (strEQ(d,"study")) return KEY_study; |
a687059c LW |
5729 | break; |
5730 | case 'u': | |
a0d0e21e | 5731 | if (strEQ(d,"substr")) return -KEY_substr; |
79072805 | 5732 | if (strEQ(d,"sub")) return KEY_sub; |
a687059c LW |
5733 | break; |
5734 | case 'y': | |
79072805 LW |
5735 | switch (len) { |
5736 | case 6: | |
a0d0e21e | 5737 | if (strEQ(d,"system")) return -KEY_system; |
79072805 LW |
5738 | break; |
5739 | case 7: | |
a0d0e21e LW |
5740 | if (strEQ(d,"symlink")) return -KEY_symlink; |
5741 | if (strEQ(d,"syscall")) return -KEY_syscall; | |
137443ea | 5742 | if (strEQ(d,"sysopen")) return -KEY_sysopen; |
5743 | if (strEQ(d,"sysread")) return -KEY_sysread; | |
5744 | if (strEQ(d,"sysseek")) return -KEY_sysseek; | |
79072805 LW |
5745 | break; |
5746 | case 8: | |
a0d0e21e | 5747 | if (strEQ(d,"syswrite")) return -KEY_syswrite; |
79072805 | 5748 | break; |
a687059c | 5749 | } |
a687059c LW |
5750 | break; |
5751 | } | |
5752 | break; | |
79072805 LW |
5753 | case 't': |
5754 | switch (len) { | |
5755 | case 2: | |
5756 | if (strEQ(d,"tr")) return KEY_tr; | |
5757 | break; | |
463ee0b2 LW |
5758 | case 3: |
5759 | if (strEQ(d,"tie")) return KEY_tie; | |
5760 | break; | |
79072805 | 5761 | case 4: |
a0d0e21e | 5762 | if (strEQ(d,"tell")) return -KEY_tell; |
c07a80fd | 5763 | if (strEQ(d,"tied")) return KEY_tied; |
a0d0e21e | 5764 | if (strEQ(d,"time")) return -KEY_time; |
79072805 LW |
5765 | break; |
5766 | case 5: | |
a0d0e21e | 5767 | if (strEQ(d,"times")) return -KEY_times; |
79072805 LW |
5768 | break; |
5769 | case 7: | |
a0d0e21e | 5770 | if (strEQ(d,"telldir")) return -KEY_telldir; |
79072805 LW |
5771 | break; |
5772 | case 8: | |
a0d0e21e | 5773 | if (strEQ(d,"truncate")) return -KEY_truncate; |
79072805 | 5774 | break; |
378cc40b | 5775 | } |
a687059c | 5776 | break; |
79072805 LW |
5777 | case 'u': |
5778 | switch (len) { | |
5779 | case 2: | |
a0d0e21e LW |
5780 | if (strEQ(d,"uc")) return -KEY_uc; |
5781 | break; | |
5782 | case 3: | |
5783 | if (strEQ(d,"use")) return KEY_use; | |
79072805 LW |
5784 | break; |
5785 | case 5: | |
5786 | if (strEQ(d,"undef")) return KEY_undef; | |
5787 | if (strEQ(d,"until")) return KEY_until; | |
463ee0b2 | 5788 | if (strEQ(d,"untie")) return KEY_untie; |
a0d0e21e LW |
5789 | if (strEQ(d,"utime")) return -KEY_utime; |
5790 | if (strEQ(d,"umask")) return -KEY_umask; | |
79072805 LW |
5791 | break; |
5792 | case 6: | |
5793 | if (strEQ(d,"unless")) return KEY_unless; | |
a0d0e21e LW |
5794 | if (strEQ(d,"unpack")) return -KEY_unpack; |
5795 | if (strEQ(d,"unlink")) return -KEY_unlink; | |
79072805 LW |
5796 | break; |
5797 | case 7: | |
3a6a8333 | 5798 | if (strEQ(d,"unshift")) return -KEY_unshift; |
a0d0e21e | 5799 | if (strEQ(d,"ucfirst")) return -KEY_ucfirst; |
79072805 | 5800 | break; |
a687059c LW |
5801 | } |
5802 | break; | |
79072805 | 5803 | case 'v': |
a0d0e21e LW |
5804 | if (strEQ(d,"values")) return -KEY_values; |
5805 | if (strEQ(d,"vec")) return -KEY_vec; | |
a687059c | 5806 | break; |
79072805 LW |
5807 | case 'w': |
5808 | switch (len) { | |
5809 | case 4: | |
a0d0e21e LW |
5810 | if (strEQ(d,"warn")) return -KEY_warn; |
5811 | if (strEQ(d,"wait")) return -KEY_wait; | |
79072805 LW |
5812 | break; |
5813 | case 5: | |
5814 | if (strEQ(d,"while")) return KEY_while; | |
a0d0e21e | 5815 | if (strEQ(d,"write")) return -KEY_write; |
79072805 LW |
5816 | break; |
5817 | case 7: | |
a0d0e21e | 5818 | if (strEQ(d,"waitpid")) return -KEY_waitpid; |
79072805 LW |
5819 | break; |
5820 | case 9: | |
a0d0e21e | 5821 | if (strEQ(d,"wantarray")) return -KEY_wantarray; |
79072805 | 5822 | break; |
2f3197b3 | 5823 | } |
a687059c | 5824 | break; |
79072805 | 5825 | case 'x': |
a0d0e21e LW |
5826 | if (len == 1) return -KEY_x; |
5827 | if (strEQ(d,"xor")) return -KEY_xor; | |
a687059c | 5828 | break; |
79072805 LW |
5829 | case 'y': |
5830 | if (len == 1) return KEY_y; | |
5831 | break; | |
5832 | case 'z': | |
a687059c LW |
5833 | break; |
5834 | } | |
79072805 | 5835 | return 0; |
a687059c LW |
5836 | } |
5837 | ||
76e3520e | 5838 | STATIC void |
cea2e8a9 | 5839 | S_checkcomma(pTHX_ register char *s, char *name, char *what) |
a687059c | 5840 | { |
2f3197b3 LW |
5841 | char *w; |
5842 | ||
d008e5eb | 5843 | if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */ |
d008e5eb GS |
5844 | if (ckWARN(WARN_SYNTAX)) { |
5845 | int level = 1; | |
5846 | for (w = s+2; *w && level; w++) { | |
5847 | if (*w == '(') | |
5848 | ++level; | |
5849 | else if (*w == ')') | |
5850 | --level; | |
5851 | } | |
5852 | if (*w) | |
5853 | for (; *w && isSPACE(*w); w++) ; | |
5854 | if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */ | |
65cec589 GS |
5855 | Perl_warner(aTHX_ WARN_SYNTAX, |
5856 | "%s (...) interpreted as function",name); | |
d008e5eb | 5857 | } |
2f3197b3 | 5858 | } |
3280af22 | 5859 | while (s < PL_bufend && isSPACE(*s)) |
2f3197b3 | 5860 | s++; |
a687059c LW |
5861 | if (*s == '(') |
5862 | s++; | |
3280af22 | 5863 | while (s < PL_bufend && isSPACE(*s)) |
a687059c | 5864 | s++; |
7e2040f0 | 5865 | if (isIDFIRST_lazy_if(s,UTF)) { |
2f3197b3 | 5866 | w = s++; |
7e2040f0 | 5867 | while (isALNUM_lazy_if(s,UTF)) |
a687059c | 5868 | s++; |
3280af22 | 5869 | while (s < PL_bufend && isSPACE(*s)) |
a687059c | 5870 | s++; |
e929a76b | 5871 | if (*s == ',') { |
463ee0b2 | 5872 | int kw; |
e929a76b | 5873 | *s = '\0'; |
864dbfa3 | 5874 | kw = keyword(w, s - w) || get_cv(w, FALSE) != 0; |
e929a76b | 5875 | *s = ','; |
463ee0b2 | 5876 | if (kw) |
e929a76b | 5877 | return; |
cea2e8a9 | 5878 | Perl_croak(aTHX_ "No comma allowed after %s", what); |
463ee0b2 LW |
5879 | } |
5880 | } | |
5881 | } | |
5882 | ||
423cee85 JH |
5883 | /* Either returns sv, or mortalizes sv and returns a new SV*. |
5884 | Best used as sv=new_constant(..., sv, ...). | |
5885 | If s, pv are NULL, calls subroutine with one argument, | |
5886 | and type is used with error messages only. */ | |
5887 | ||
b3ac6de7 | 5888 | STATIC SV * |
dff6d3cd | 5889 | S_new_constant(pTHX_ char *s, STRLEN len, const char *key, SV *sv, SV *pv, |
9b0e499b | 5890 | const char *type) |
b3ac6de7 | 5891 | { |
b3ac6de7 | 5892 | dSP; |
3280af22 | 5893 | HV *table = GvHV(PL_hintgv); /* ^H */ |
b3ac6de7 | 5894 | SV *res; |
b3ac6de7 IZ |
5895 | SV **cvp; |
5896 | SV *cv, *typesv; | |
f0af216f | 5897 | const char *why1, *why2, *why3; |
4e553d73 | 5898 | |
f0af216f | 5899 | if (!table || !(PL_hints & HINT_LOCALIZE_HH)) { |
423cee85 JH |
5900 | SV *msg; |
5901 | ||
f0af216f | 5902 | why2 = strEQ(key,"charnames") |
41ab332f | 5903 | ? "(possibly a missing \"use charnames ...\")" |
f0af216f | 5904 | : ""; |
4e553d73 | 5905 | msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s", |
41ab332f JH |
5906 | (type ? type: "undef"), why2); |
5907 | ||
5908 | /* This is convoluted and evil ("goto considered harmful") | |
5909 | * but I do not understand the intricacies of all the different | |
5910 | * failure modes of %^H in here. The goal here is to make | |
5911 | * the most probable error message user-friendly. --jhi */ | |
5912 | ||
5913 | goto msgdone; | |
5914 | ||
423cee85 | 5915 | report: |
4e553d73 | 5916 | msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s", |
f0af216f | 5917 | (type ? type: "undef"), why1, why2, why3); |
41ab332f | 5918 | msgdone: |
423cee85 JH |
5919 | yyerror(SvPVX(msg)); |
5920 | SvREFCNT_dec(msg); | |
5921 | return sv; | |
5922 | } | |
b3ac6de7 IZ |
5923 | cvp = hv_fetch(table, key, strlen(key), FALSE); |
5924 | if (!cvp || !SvOK(*cvp)) { | |
423cee85 JH |
5925 | why1 = "$^H{"; |
5926 | why2 = key; | |
f0af216f | 5927 | why3 = "} is not defined"; |
423cee85 | 5928 | goto report; |
b3ac6de7 IZ |
5929 | } |
5930 | sv_2mortal(sv); /* Parent created it permanently */ | |
5931 | cv = *cvp; | |
423cee85 JH |
5932 | if (!pv && s) |
5933 | pv = sv_2mortal(newSVpvn(s, len)); | |
5934 | if (type && pv) | |
5935 | typesv = sv_2mortal(newSVpv(type, 0)); | |
b3ac6de7 | 5936 | else |
423cee85 | 5937 | typesv = &PL_sv_undef; |
4e553d73 | 5938 | |
e788e7d3 | 5939 | PUSHSTACKi(PERLSI_OVERLOAD); |
423cee85 JH |
5940 | ENTER ; |
5941 | SAVETMPS; | |
4e553d73 | 5942 | |
423cee85 | 5943 | PUSHMARK(SP) ; |
a5845cb7 | 5944 | EXTEND(sp, 3); |
423cee85 JH |
5945 | if (pv) |
5946 | PUSHs(pv); | |
b3ac6de7 | 5947 | PUSHs(sv); |
423cee85 JH |
5948 | if (pv) |
5949 | PUSHs(typesv); | |
b3ac6de7 | 5950 | PUTBACK; |
423cee85 | 5951 | call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL)); |
4e553d73 | 5952 | |
423cee85 | 5953 | SPAGAIN ; |
4e553d73 | 5954 | |
423cee85 | 5955 | /* Check the eval first */ |
9b0e499b | 5956 | if (!PL_in_eval && SvTRUE(ERRSV)) { |
423cee85 JH |
5957 | STRLEN n_a; |
5958 | sv_catpv(ERRSV, "Propagated"); | |
5959 | yyerror(SvPV(ERRSV, n_a)); /* Duplicates the message inside eval */ | |
e1f15930 | 5960 | (void)POPs; |
423cee85 JH |
5961 | res = SvREFCNT_inc(sv); |
5962 | } | |
5963 | else { | |
5964 | res = POPs; | |
e1f15930 | 5965 | (void)SvREFCNT_inc(res); |
423cee85 | 5966 | } |
4e553d73 | 5967 | |
423cee85 JH |
5968 | PUTBACK ; |
5969 | FREETMPS ; | |
5970 | LEAVE ; | |
b3ac6de7 | 5971 | POPSTACK; |
4e553d73 | 5972 | |
b3ac6de7 | 5973 | if (!SvOK(res)) { |
423cee85 JH |
5974 | why1 = "Call to &{$^H{"; |
5975 | why2 = key; | |
f0af216f | 5976 | why3 = "}} did not return a defined value"; |
423cee85 JH |
5977 | sv = res; |
5978 | goto report; | |
9b0e499b | 5979 | } |
423cee85 | 5980 | |
9b0e499b | 5981 | return res; |
b3ac6de7 | 5982 | } |
4e553d73 | 5983 | |
76e3520e | 5984 | STATIC char * |
cea2e8a9 | 5985 | S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp) |
463ee0b2 LW |
5986 | { |
5987 | register char *d = dest; | |
8903cb82 | 5988 | register char *e = d + destlen - 3; /* two-character token, ending NUL */ |
463ee0b2 | 5989 | for (;;) { |
8903cb82 | 5990 | if (d >= e) |
cea2e8a9 | 5991 | Perl_croak(aTHX_ ident_too_long); |
834a4ddd | 5992 | if (isALNUM(*s)) /* UTF handled below */ |
463ee0b2 | 5993 | *d++ = *s++; |
7e2040f0 | 5994 | else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) { |
463ee0b2 LW |
5995 | *d++ = ':'; |
5996 | *d++ = ':'; | |
5997 | s++; | |
5998 | } | |
c3e0f903 | 5999 | else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') { |
463ee0b2 LW |
6000 | *d++ = *s++; |
6001 | *d++ = *s++; | |
6002 | } | |
fd400ab9 | 6003 | else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
a0ed51b3 | 6004 | char *t = s + UTF8SKIP(s); |
fd400ab9 | 6005 | while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
a0ed51b3 LW |
6006 | t += UTF8SKIP(t); |
6007 | if (d + (t - s) > e) | |
cea2e8a9 | 6008 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 LW |
6009 | Copy(s, d, t - s, char); |
6010 | d += t - s; | |
6011 | s = t; | |
6012 | } | |
463ee0b2 LW |
6013 | else { |
6014 | *d = '\0'; | |
6015 | *slp = d - dest; | |
6016 | return s; | |
e929a76b | 6017 | } |
378cc40b LW |
6018 | } |
6019 | } | |
6020 | ||
76e3520e | 6021 | STATIC char * |
cea2e8a9 | 6022 | S_scan_ident(pTHX_ register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni) |
378cc40b LW |
6023 | { |
6024 | register char *d; | |
8903cb82 | 6025 | register char *e; |
79072805 | 6026 | char *bracket = 0; |
748a9306 | 6027 | char funny = *s++; |
378cc40b | 6028 | |
a0d0e21e LW |
6029 | if (isSPACE(*s)) |
6030 | s = skipspace(s); | |
378cc40b | 6031 | d = dest; |
8903cb82 | 6032 | e = d + destlen - 3; /* two-character token, ending NUL */ |
de3bb511 | 6033 | if (isDIGIT(*s)) { |
8903cb82 | 6034 | while (isDIGIT(*s)) { |
6035 | if (d >= e) | |
cea2e8a9 | 6036 | Perl_croak(aTHX_ ident_too_long); |
378cc40b | 6037 | *d++ = *s++; |
8903cb82 | 6038 | } |
378cc40b LW |
6039 | } |
6040 | else { | |
463ee0b2 | 6041 | for (;;) { |
8903cb82 | 6042 | if (d >= e) |
cea2e8a9 | 6043 | Perl_croak(aTHX_ ident_too_long); |
834a4ddd | 6044 | if (isALNUM(*s)) /* UTF handled below */ |
463ee0b2 | 6045 | *d++ = *s++; |
7e2040f0 | 6046 | else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) { |
463ee0b2 LW |
6047 | *d++ = ':'; |
6048 | *d++ = ':'; | |
6049 | s++; | |
6050 | } | |
a0d0e21e | 6051 | else if (*s == ':' && s[1] == ':') { |
463ee0b2 LW |
6052 | *d++ = *s++; |
6053 | *d++ = *s++; | |
6054 | } | |
fd400ab9 | 6055 | else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
a0ed51b3 | 6056 | char *t = s + UTF8SKIP(s); |
fd400ab9 | 6057 | while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
a0ed51b3 LW |
6058 | t += UTF8SKIP(t); |
6059 | if (d + (t - s) > e) | |
cea2e8a9 | 6060 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 LW |
6061 | Copy(s, d, t - s, char); |
6062 | d += t - s; | |
6063 | s = t; | |
6064 | } | |
463ee0b2 LW |
6065 | else |
6066 | break; | |
6067 | } | |
378cc40b LW |
6068 | } |
6069 | *d = '\0'; | |
6070 | d = dest; | |
79072805 | 6071 | if (*d) { |
3280af22 NIS |
6072 | if (PL_lex_state != LEX_NORMAL) |
6073 | PL_lex_state = LEX_INTERPENDMAYBE; | |
79072805 | 6074 | return s; |
378cc40b | 6075 | } |
748a9306 | 6076 | if (*s == '$' && s[1] && |
7e2040f0 | 6077 | (isALNUM_lazy_if(s+1,UTF) || strchr("${", s[1]) || strnEQ(s+1,"::",2)) ) |
5cd24f17 | 6078 | { |
4810e5ec | 6079 | return s; |
5cd24f17 | 6080 | } |
79072805 LW |
6081 | if (*s == '{') { |
6082 | bracket = s; | |
6083 | s++; | |
6084 | } | |
6085 | else if (ck_uni) | |
6086 | check_uni(); | |
93a17b20 | 6087 | if (s < send) |
79072805 LW |
6088 | *d = *s++; |
6089 | d[1] = '\0'; | |
2b92dfce | 6090 | if (*d == '^' && *s && isCONTROLVAR(*s)) { |
bbce6d69 | 6091 | *d = toCTRL(*s); |
6092 | s++; | |
de3bb511 | 6093 | } |
79072805 | 6094 | if (bracket) { |
748a9306 | 6095 | if (isSPACE(s[-1])) { |
fa83b5b6 | 6096 | while (s < send) { |
6097 | char ch = *s++; | |
bf4acbe4 | 6098 | if (!SPACE_OR_TAB(ch)) { |
fa83b5b6 | 6099 | *d = ch; |
6100 | break; | |
6101 | } | |
6102 | } | |
748a9306 | 6103 | } |
7e2040f0 | 6104 | if (isIDFIRST_lazy_if(d,UTF)) { |
79072805 | 6105 | d++; |
a0ed51b3 LW |
6106 | if (UTF) { |
6107 | e = s; | |
155aba94 | 6108 | while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') { |
a0ed51b3 | 6109 | e += UTF8SKIP(e); |
fd400ab9 | 6110 | while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e)) |
a0ed51b3 LW |
6111 | e += UTF8SKIP(e); |
6112 | } | |
6113 | Copy(s, d, e - s, char); | |
6114 | d += e - s; | |
6115 | s = e; | |
6116 | } | |
6117 | else { | |
2b92dfce | 6118 | while ((isALNUM(*s) || *s == ':') && d < e) |
a0ed51b3 | 6119 | *d++ = *s++; |
2b92dfce | 6120 | if (d >= e) |
cea2e8a9 | 6121 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 | 6122 | } |
79072805 | 6123 | *d = '\0'; |
bf4acbe4 | 6124 | while (s < send && SPACE_OR_TAB(*s)) s++; |
ff68c719 | 6125 | if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) { |
599cee73 | 6126 | if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) { |
dff6d3cd | 6127 | const char *brack = *s == '[' ? "[...]" : "{...}"; |
cea2e8a9 | 6128 | Perl_warner(aTHX_ WARN_AMBIGUOUS, |
599cee73 | 6129 | "Ambiguous use of %c{%s%s} resolved to %c%s%s", |
748a9306 LW |
6130 | funny, dest, brack, funny, dest, brack); |
6131 | } | |
79072805 | 6132 | bracket++; |
a0be28da | 6133 | PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK); |
79072805 LW |
6134 | return s; |
6135 | } | |
4e553d73 NIS |
6136 | } |
6137 | /* Handle extended ${^Foo} variables | |
2b92dfce GS |
6138 | * 1999-02-27 mjd-perl-patch@plover.com */ |
6139 | else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */ | |
6140 | && isALNUM(*s)) | |
6141 | { | |
6142 | d++; | |
6143 | while (isALNUM(*s) && d < e) { | |
6144 | *d++ = *s++; | |
6145 | } | |
6146 | if (d >= e) | |
cea2e8a9 | 6147 | Perl_croak(aTHX_ ident_too_long); |
2b92dfce | 6148 | *d = '\0'; |
79072805 LW |
6149 | } |
6150 | if (*s == '}') { | |
6151 | s++; | |
3280af22 NIS |
6152 | if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) |
6153 | PL_lex_state = LEX_INTERPEND; | |
748a9306 LW |
6154 | if (funny == '#') |
6155 | funny = '@'; | |
d008e5eb | 6156 | if (PL_lex_state == LEX_NORMAL) { |
d008e5eb | 6157 | if (ckWARN(WARN_AMBIGUOUS) && |
864dbfa3 | 6158 | (keyword(dest, d - dest) || get_cv(dest, FALSE))) |
d008e5eb | 6159 | { |
cea2e8a9 | 6160 | Perl_warner(aTHX_ WARN_AMBIGUOUS, |
d008e5eb GS |
6161 | "Ambiguous use of %c{%s} resolved to %c%s", |
6162 | funny, dest, funny, dest); | |
6163 | } | |
6164 | } | |
79072805 LW |
6165 | } |
6166 | else { | |
6167 | s = bracket; /* let the parser handle it */ | |
93a17b20 | 6168 | *dest = '\0'; |
79072805 LW |
6169 | } |
6170 | } | |
3280af22 NIS |
6171 | else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s)) |
6172 | PL_lex_state = LEX_INTERPEND; | |
378cc40b LW |
6173 | return s; |
6174 | } | |
6175 | ||
cea2e8a9 GS |
6176 | void |
6177 | Perl_pmflag(pTHX_ U16 *pmfl, int ch) | |
a0d0e21e | 6178 | { |
bbce6d69 | 6179 | if (ch == 'i') |
a0d0e21e | 6180 | *pmfl |= PMf_FOLD; |
a0d0e21e LW |
6181 | else if (ch == 'g') |
6182 | *pmfl |= PMf_GLOBAL; | |
c90c0ff4 | 6183 | else if (ch == 'c') |
6184 | *pmfl |= PMf_CONTINUE; | |
a0d0e21e LW |
6185 | else if (ch == 'o') |
6186 | *pmfl |= PMf_KEEP; | |
6187 | else if (ch == 'm') | |
6188 | *pmfl |= PMf_MULTILINE; | |
6189 | else if (ch == 's') | |
6190 | *pmfl |= PMf_SINGLELINE; | |
6191 | else if (ch == 'x') | |
6192 | *pmfl |= PMf_EXTENDED; | |
6193 | } | |
378cc40b | 6194 | |
76e3520e | 6195 | STATIC char * |
cea2e8a9 | 6196 | S_scan_pat(pTHX_ char *start, I32 type) |
378cc40b | 6197 | { |
79072805 LW |
6198 | PMOP *pm; |
6199 | char *s; | |
378cc40b | 6200 | |
09bef843 | 6201 | s = scan_str(start,FALSE,FALSE); |
37fd879b | 6202 | if (!s) |
cea2e8a9 | 6203 | Perl_croak(aTHX_ "Search pattern not terminated"); |
bbce6d69 | 6204 | |
8782bef2 | 6205 | pm = (PMOP*)newPMOP(type, 0); |
3280af22 | 6206 | if (PL_multi_open == '?') |
79072805 | 6207 | pm->op_pmflags |= PMf_ONCE; |
8782bef2 GB |
6208 | if(type == OP_QR) { |
6209 | while (*s && strchr("iomsx", *s)) | |
6210 | pmflag(&pm->op_pmflags,*s++); | |
6211 | } | |
6212 | else { | |
6213 | while (*s && strchr("iogcmsx", *s)) | |
6214 | pmflag(&pm->op_pmflags,*s++); | |
6215 | } | |
4633a7c4 | 6216 | pm->op_pmpermflags = pm->op_pmflags; |
bbce6d69 | 6217 | |
3280af22 | 6218 | PL_lex_op = (OP*)pm; |
79072805 | 6219 | yylval.ival = OP_MATCH; |
378cc40b LW |
6220 | return s; |
6221 | } | |
6222 | ||
76e3520e | 6223 | STATIC char * |
cea2e8a9 | 6224 | S_scan_subst(pTHX_ char *start) |
79072805 | 6225 | { |
a0d0e21e | 6226 | register char *s; |
79072805 | 6227 | register PMOP *pm; |
4fdae800 | 6228 | I32 first_start; |
79072805 LW |
6229 | I32 es = 0; |
6230 | ||
79072805 LW |
6231 | yylval.ival = OP_NULL; |
6232 | ||
09bef843 | 6233 | s = scan_str(start,FALSE,FALSE); |
79072805 | 6234 | |
37fd879b | 6235 | if (!s) |
cea2e8a9 | 6236 | Perl_croak(aTHX_ "Substitution pattern not terminated"); |
79072805 | 6237 | |
3280af22 | 6238 | if (s[-1] == PL_multi_open) |
79072805 LW |
6239 | s--; |
6240 | ||
3280af22 | 6241 | first_start = PL_multi_start; |
09bef843 | 6242 | s = scan_str(s,FALSE,FALSE); |
79072805 | 6243 | if (!s) { |
37fd879b | 6244 | if (PL_lex_stuff) { |
3280af22 | 6245 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
6246 | PL_lex_stuff = Nullsv; |
6247 | } | |
cea2e8a9 | 6248 | Perl_croak(aTHX_ "Substitution replacement not terminated"); |
a687059c | 6249 | } |
3280af22 | 6250 | PL_multi_start = first_start; /* so whole substitution is taken together */ |
2f3197b3 | 6251 | |
79072805 | 6252 | pm = (PMOP*)newPMOP(OP_SUBST, 0); |
48c036b1 | 6253 | while (*s) { |
a687059c LW |
6254 | if (*s == 'e') { |
6255 | s++; | |
2f3197b3 | 6256 | es++; |
a687059c | 6257 | } |
b3eb6a9b | 6258 | else if (strchr("iogcmsx", *s)) |
a0d0e21e | 6259 | pmflag(&pm->op_pmflags,*s++); |
48c036b1 GS |
6260 | else |
6261 | break; | |
378cc40b | 6262 | } |
79072805 LW |
6263 | |
6264 | if (es) { | |
6265 | SV *repl; | |
0244c3a4 GS |
6266 | PL_sublex_info.super_bufptr = s; |
6267 | PL_sublex_info.super_bufend = PL_bufend; | |
6268 | PL_multi_end = 0; | |
79072805 | 6269 | pm->op_pmflags |= PMf_EVAL; |
79cb57f6 | 6270 | repl = newSVpvn("",0); |
463ee0b2 | 6271 | while (es-- > 0) |
a0d0e21e | 6272 | sv_catpv(repl, es ? "eval " : "do "); |
79072805 | 6273 | sv_catpvn(repl, "{ ", 2); |
3280af22 | 6274 | sv_catsv(repl, PL_lex_repl); |
79072805 | 6275 | sv_catpvn(repl, " };", 2); |
25da4f38 | 6276 | SvEVALED_on(repl); |
3280af22 NIS |
6277 | SvREFCNT_dec(PL_lex_repl); |
6278 | PL_lex_repl = repl; | |
378cc40b | 6279 | } |
79072805 | 6280 | |
4633a7c4 | 6281 | pm->op_pmpermflags = pm->op_pmflags; |
3280af22 | 6282 | PL_lex_op = (OP*)pm; |
79072805 | 6283 | yylval.ival = OP_SUBST; |
378cc40b LW |
6284 | return s; |
6285 | } | |
6286 | ||
76e3520e | 6287 | STATIC char * |
cea2e8a9 | 6288 | S_scan_trans(pTHX_ char *start) |
378cc40b | 6289 | { |
a0d0e21e | 6290 | register char* s; |
11343788 | 6291 | OP *o; |
79072805 LW |
6292 | short *tbl; |
6293 | I32 squash; | |
a0ed51b3 | 6294 | I32 del; |
79072805 LW |
6295 | I32 complement; |
6296 | ||
6297 | yylval.ival = OP_NULL; | |
6298 | ||
09bef843 | 6299 | s = scan_str(start,FALSE,FALSE); |
37fd879b | 6300 | if (!s) |
cea2e8a9 | 6301 | Perl_croak(aTHX_ "Transliteration pattern not terminated"); |
3280af22 | 6302 | if (s[-1] == PL_multi_open) |
2f3197b3 LW |
6303 | s--; |
6304 | ||
09bef843 | 6305 | s = scan_str(s,FALSE,FALSE); |
79072805 | 6306 | if (!s) { |
37fd879b | 6307 | if (PL_lex_stuff) { |
3280af22 | 6308 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
6309 | PL_lex_stuff = Nullsv; |
6310 | } | |
cea2e8a9 | 6311 | Perl_croak(aTHX_ "Transliteration replacement not terminated"); |
a687059c | 6312 | } |
79072805 | 6313 | |
a0ed51b3 | 6314 | complement = del = squash = 0; |
6940069f | 6315 | while (strchr("cds", *s)) { |
395c3793 | 6316 | if (*s == 'c') |
79072805 | 6317 | complement = OPpTRANS_COMPLEMENT; |
395c3793 | 6318 | else if (*s == 'd') |
a0ed51b3 LW |
6319 | del = OPpTRANS_DELETE; |
6320 | else if (*s == 's') | |
79072805 | 6321 | squash = OPpTRANS_SQUASH; |
395c3793 LW |
6322 | s++; |
6323 | } | |
8973db79 JH |
6324 | |
6325 | New(803, tbl, complement&&!del?258:256, short); | |
6326 | o = newPVOP(OP_TRANS, 0, (char*)tbl); | |
7948272d NIS |
6327 | o->op_private = del|squash|complement| |
6328 | (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)| | |
6329 | (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0); | |
79072805 | 6330 | |
3280af22 | 6331 | PL_lex_op = o; |
79072805 LW |
6332 | yylval.ival = OP_TRANS; |
6333 | return s; | |
6334 | } | |
6335 | ||
76e3520e | 6336 | STATIC char * |
cea2e8a9 | 6337 | S_scan_heredoc(pTHX_ register char *s) |
79072805 LW |
6338 | { |
6339 | SV *herewas; | |
6340 | I32 op_type = OP_SCALAR; | |
6341 | I32 len; | |
6342 | SV *tmpstr; | |
6343 | char term; | |
6344 | register char *d; | |
fc36a67e | 6345 | register char *e; |
4633a7c4 | 6346 | char *peek; |
3280af22 | 6347 | int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR)); |
79072805 LW |
6348 | |
6349 | s += 2; | |
3280af22 NIS |
6350 | d = PL_tokenbuf; |
6351 | e = PL_tokenbuf + sizeof PL_tokenbuf - 1; | |
fd2d0953 | 6352 | if (!outer) |
79072805 | 6353 | *d++ = '\n'; |
bf4acbe4 | 6354 | for (peek = s; SPACE_OR_TAB(*peek); peek++) ; |
4633a7c4 LW |
6355 | if (*peek && strchr("`'\"",*peek)) { |
6356 | s = peek; | |
79072805 | 6357 | term = *s++; |
3280af22 | 6358 | s = delimcpy(d, e, s, PL_bufend, term, &len); |
fc36a67e | 6359 | d += len; |
3280af22 | 6360 | if (s < PL_bufend) |
79072805 | 6361 | s++; |
79072805 LW |
6362 | } |
6363 | else { | |
6364 | if (*s == '\\') | |
6365 | s++, term = '\''; | |
6366 | else | |
6367 | term = '"'; | |
7e2040f0 | 6368 | if (!isALNUM_lazy_if(s,UTF)) |
4633a7c4 | 6369 | deprecate("bare << to mean <<\"\""); |
7e2040f0 | 6370 | for (; isALNUM_lazy_if(s,UTF); s++) { |
fc36a67e | 6371 | if (d < e) |
6372 | *d++ = *s; | |
6373 | } | |
6374 | } | |
3280af22 | 6375 | if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1) |
cea2e8a9 | 6376 | Perl_croak(aTHX_ "Delimiter for here document is too long"); |
79072805 LW |
6377 | *d++ = '\n'; |
6378 | *d = '\0'; | |
3280af22 | 6379 | len = d - PL_tokenbuf; |
6a27c188 | 6380 | #ifndef PERL_STRICT_CR |
f63a84b2 LW |
6381 | d = strchr(s, '\r'); |
6382 | if (d) { | |
6383 | char *olds = s; | |
6384 | s = d; | |
3280af22 | 6385 | while (s < PL_bufend) { |
f63a84b2 LW |
6386 | if (*s == '\r') { |
6387 | *d++ = '\n'; | |
6388 | if (*++s == '\n') | |
6389 | s++; | |
6390 | } | |
6391 | else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */ | |
6392 | *d++ = *s++; | |
6393 | s++; | |
6394 | } | |
6395 | else | |
6396 | *d++ = *s++; | |
6397 | } | |
6398 | *d = '\0'; | |
3280af22 NIS |
6399 | PL_bufend = d; |
6400 | SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr)); | |
f63a84b2 LW |
6401 | s = olds; |
6402 | } | |
6403 | #endif | |
79072805 | 6404 | d = "\n"; |
3280af22 | 6405 | if (outer || !(d=ninstr(s,PL_bufend,d,d+1))) |
79cb57f6 | 6406 | herewas = newSVpvn(s,PL_bufend-s); |
79072805 | 6407 | else |
79cb57f6 | 6408 | s--, herewas = newSVpvn(s,d-s); |
79072805 | 6409 | s += SvCUR(herewas); |
748a9306 | 6410 | |
8d6dde3e | 6411 | tmpstr = NEWSV(87,79); |
748a9306 LW |
6412 | sv_upgrade(tmpstr, SVt_PVIV); |
6413 | if (term == '\'') { | |
79072805 | 6414 | op_type = OP_CONST; |
748a9306 LW |
6415 | SvIVX(tmpstr) = -1; |
6416 | } | |
6417 | else if (term == '`') { | |
79072805 | 6418 | op_type = OP_BACKTICK; |
748a9306 LW |
6419 | SvIVX(tmpstr) = '\\'; |
6420 | } | |
79072805 LW |
6421 | |
6422 | CLINE; | |
57843af0 | 6423 | PL_multi_start = CopLINE(PL_curcop); |
3280af22 NIS |
6424 | PL_multi_open = PL_multi_close = '<'; |
6425 | term = *PL_tokenbuf; | |
0244c3a4 GS |
6426 | if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) { |
6427 | char *bufptr = PL_sublex_info.super_bufptr; | |
6428 | char *bufend = PL_sublex_info.super_bufend; | |
6429 | char *olds = s - SvCUR(herewas); | |
6430 | s = strchr(bufptr, '\n'); | |
6431 | if (!s) | |
6432 | s = bufend; | |
6433 | d = s; | |
6434 | while (s < bufend && | |
6435 | (*s != term || memNE(s,PL_tokenbuf,len)) ) { | |
6436 | if (*s++ == '\n') | |
57843af0 | 6437 | CopLINE_inc(PL_curcop); |
0244c3a4 GS |
6438 | } |
6439 | if (s >= bufend) { | |
57843af0 | 6440 | CopLINE_set(PL_curcop, PL_multi_start); |
0244c3a4 GS |
6441 | missingterm(PL_tokenbuf); |
6442 | } | |
6443 | sv_setpvn(herewas,bufptr,d-bufptr+1); | |
6444 | sv_setpvn(tmpstr,d+1,s-d); | |
6445 | s += len - 1; | |
6446 | sv_catpvn(herewas,s,bufend-s); | |
6447 | (void)strcpy(bufptr,SvPVX(herewas)); | |
6448 | ||
6449 | s = olds; | |
6450 | goto retval; | |
6451 | } | |
6452 | else if (!outer) { | |
79072805 | 6453 | d = s; |
3280af22 NIS |
6454 | while (s < PL_bufend && |
6455 | (*s != term || memNE(s,PL_tokenbuf,len)) ) { | |
79072805 | 6456 | if (*s++ == '\n') |
57843af0 | 6457 | CopLINE_inc(PL_curcop); |
79072805 | 6458 | } |
3280af22 | 6459 | if (s >= PL_bufend) { |
57843af0 | 6460 | CopLINE_set(PL_curcop, PL_multi_start); |
3280af22 | 6461 | missingterm(PL_tokenbuf); |
79072805 LW |
6462 | } |
6463 | sv_setpvn(tmpstr,d+1,s-d); | |
6464 | s += len - 1; | |
57843af0 | 6465 | CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */ |
49d8d3a1 | 6466 | |
3280af22 NIS |
6467 | sv_catpvn(herewas,s,PL_bufend-s); |
6468 | sv_setsv(PL_linestr,herewas); | |
6469 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr); | |
6470 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 6471 | PL_last_lop = PL_last_uni = Nullch; |
79072805 LW |
6472 | } |
6473 | else | |
6474 | sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */ | |
3280af22 | 6475 | while (s >= PL_bufend) { /* multiple line string? */ |
fd2d0953 | 6476 | if (!outer || |
3280af22 | 6477 | !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { |
57843af0 | 6478 | CopLINE_set(PL_curcop, PL_multi_start); |
3280af22 | 6479 | missingterm(PL_tokenbuf); |
79072805 | 6480 | } |
57843af0 | 6481 | CopLINE_inc(PL_curcop); |
3280af22 | 6482 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 6483 | PL_last_lop = PL_last_uni = Nullch; |
6a27c188 | 6484 | #ifndef PERL_STRICT_CR |
3280af22 | 6485 | if (PL_bufend - PL_linestart >= 2) { |
a1529941 NIS |
6486 | if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') || |
6487 | (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r')) | |
c6f14548 | 6488 | { |
3280af22 NIS |
6489 | PL_bufend[-2] = '\n'; |
6490 | PL_bufend--; | |
6491 | SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr)); | |
f63a84b2 | 6492 | } |
3280af22 NIS |
6493 | else if (PL_bufend[-1] == '\r') |
6494 | PL_bufend[-1] = '\n'; | |
f63a84b2 | 6495 | } |
3280af22 NIS |
6496 | else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r') |
6497 | PL_bufend[-1] = '\n'; | |
f63a84b2 | 6498 | #endif |
3280af22 | 6499 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
79072805 LW |
6500 | SV *sv = NEWSV(88,0); |
6501 | ||
93a17b20 | 6502 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 6503 | sv_setsv(sv,PL_linestr); |
57843af0 | 6504 | av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv); |
79072805 | 6505 | } |
3280af22 NIS |
6506 | if (*s == term && memEQ(s,PL_tokenbuf,len)) { |
6507 | s = PL_bufend - 1; | |
79072805 | 6508 | *s = ' '; |
3280af22 NIS |
6509 | sv_catsv(PL_linestr,herewas); |
6510 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
79072805 LW |
6511 | } |
6512 | else { | |
3280af22 NIS |
6513 | s = PL_bufend; |
6514 | sv_catsv(tmpstr,PL_linestr); | |
395c3793 LW |
6515 | } |
6516 | } | |
79072805 | 6517 | s++; |
0244c3a4 | 6518 | retval: |
57843af0 | 6519 | PL_multi_end = CopLINE(PL_curcop); |
79072805 LW |
6520 | if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) { |
6521 | SvLEN_set(tmpstr, SvCUR(tmpstr) + 1); | |
463ee0b2 | 6522 | Renew(SvPVX(tmpstr), SvLEN(tmpstr), char); |
79072805 | 6523 | } |
8990e307 | 6524 | SvREFCNT_dec(herewas); |
7948272d NIS |
6525 | if (UTF && !IN_BYTE && is_utf8_string((U8*)SvPVX(tmpstr), SvCUR(tmpstr))) |
6526 | SvUTF8_on(tmpstr); | |
3280af22 | 6527 | PL_lex_stuff = tmpstr; |
79072805 LW |
6528 | yylval.ival = op_type; |
6529 | return s; | |
6530 | } | |
6531 | ||
02aa26ce NT |
6532 | /* scan_inputsymbol |
6533 | takes: current position in input buffer | |
6534 | returns: new position in input buffer | |
6535 | side-effects: yylval and lex_op are set. | |
6536 | ||
6537 | This code handles: | |
6538 | ||
6539 | <> read from ARGV | |
6540 | <FH> read from filehandle | |
6541 | <pkg::FH> read from package qualified filehandle | |
6542 | <pkg'FH> read from package qualified filehandle | |
6543 | <$fh> read from filehandle in $fh | |
6544 | <*.h> filename glob | |
6545 | ||
6546 | */ | |
6547 | ||
76e3520e | 6548 | STATIC char * |
cea2e8a9 | 6549 | S_scan_inputsymbol(pTHX_ char *start) |
79072805 | 6550 | { |
02aa26ce | 6551 | register char *s = start; /* current position in buffer */ |
79072805 | 6552 | register char *d; |
fc36a67e | 6553 | register char *e; |
1b420867 | 6554 | char *end; |
79072805 LW |
6555 | I32 len; |
6556 | ||
3280af22 NIS |
6557 | d = PL_tokenbuf; /* start of temp holding space */ |
6558 | e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */ | |
1b420867 GS |
6559 | end = strchr(s, '\n'); |
6560 | if (!end) | |
6561 | end = PL_bufend; | |
6562 | s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */ | |
02aa26ce NT |
6563 | |
6564 | /* die if we didn't have space for the contents of the <>, | |
1b420867 | 6565 | or if it didn't end, or if we see a newline |
02aa26ce NT |
6566 | */ |
6567 | ||
3280af22 | 6568 | if (len >= sizeof PL_tokenbuf) |
cea2e8a9 | 6569 | Perl_croak(aTHX_ "Excessively long <> operator"); |
1b420867 | 6570 | if (s >= end) |
cea2e8a9 | 6571 | Perl_croak(aTHX_ "Unterminated <> operator"); |
02aa26ce | 6572 | |
fc36a67e | 6573 | s++; |
02aa26ce NT |
6574 | |
6575 | /* check for <$fh> | |
6576 | Remember, only scalar variables are interpreted as filehandles by | |
6577 | this code. Anything more complex (e.g., <$fh{$num}>) will be | |
6578 | treated as a glob() call. | |
6579 | This code makes use of the fact that except for the $ at the front, | |
6580 | a scalar variable and a filehandle look the same. | |
6581 | */ | |
4633a7c4 | 6582 | if (*d == '$' && d[1]) d++; |
02aa26ce NT |
6583 | |
6584 | /* allow <Pkg'VALUE> or <Pkg::VALUE> */ | |
7e2040f0 | 6585 | while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':')) |
79072805 | 6586 | d++; |
02aa26ce NT |
6587 | |
6588 | /* If we've tried to read what we allow filehandles to look like, and | |
6589 | there's still text left, then it must be a glob() and not a getline. | |
6590 | Use scan_str to pull out the stuff between the <> and treat it | |
6591 | as nothing more than a string. | |
6592 | */ | |
6593 | ||
3280af22 | 6594 | if (d - PL_tokenbuf != len) { |
79072805 LW |
6595 | yylval.ival = OP_GLOB; |
6596 | set_csh(); | |
09bef843 | 6597 | s = scan_str(start,FALSE,FALSE); |
79072805 | 6598 | if (!s) |
cea2e8a9 | 6599 | Perl_croak(aTHX_ "Glob not terminated"); |
79072805 LW |
6600 | return s; |
6601 | } | |
395c3793 | 6602 | else { |
02aa26ce | 6603 | /* we're in a filehandle read situation */ |
3280af22 | 6604 | d = PL_tokenbuf; |
02aa26ce NT |
6605 | |
6606 | /* turn <> into <ARGV> */ | |
79072805 LW |
6607 | if (!len) |
6608 | (void)strcpy(d,"ARGV"); | |
02aa26ce NT |
6609 | |
6610 | /* if <$fh>, create the ops to turn the variable into a | |
6611 | filehandle | |
6612 | */ | |
79072805 | 6613 | if (*d == '$') { |
a0d0e21e | 6614 | I32 tmp; |
02aa26ce NT |
6615 | |
6616 | /* try to find it in the pad for this block, otherwise find | |
6617 | add symbol table ops | |
6618 | */ | |
11343788 MB |
6619 | if ((tmp = pad_findmy(d)) != NOT_IN_PAD) { |
6620 | OP *o = newOP(OP_PADSV, 0); | |
6621 | o->op_targ = tmp; | |
f5284f61 | 6622 | PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, o); |
a0d0e21e LW |
6623 | } |
6624 | else { | |
6625 | GV *gv = gv_fetchpv(d+1,TRUE, SVt_PV); | |
3280af22 | 6626 | PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, |
a0d0e21e | 6627 | newUNOP(OP_RV2SV, 0, |
f5284f61 | 6628 | newGVOP(OP_GV, 0, gv))); |
a0d0e21e | 6629 | } |
f5284f61 IZ |
6630 | PL_lex_op->op_flags |= OPf_SPECIAL; |
6631 | /* we created the ops in PL_lex_op, so make yylval.ival a null op */ | |
79072805 LW |
6632 | yylval.ival = OP_NULL; |
6633 | } | |
02aa26ce NT |
6634 | |
6635 | /* If it's none of the above, it must be a literal filehandle | |
6636 | (<Foo::BAR> or <FOO>) so build a simple readline OP */ | |
79072805 | 6637 | else { |
85e6fe83 | 6638 | GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO); |
3280af22 | 6639 | PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv)); |
79072805 LW |
6640 | yylval.ival = OP_NULL; |
6641 | } | |
6642 | } | |
02aa26ce | 6643 | |
79072805 LW |
6644 | return s; |
6645 | } | |
6646 | ||
02aa26ce NT |
6647 | |
6648 | /* scan_str | |
6649 | takes: start position in buffer | |
09bef843 SB |
6650 | keep_quoted preserve \ on the embedded delimiter(s) |
6651 | keep_delims preserve the delimiters around the string | |
02aa26ce NT |
6652 | returns: position to continue reading from buffer |
6653 | side-effects: multi_start, multi_close, lex_repl or lex_stuff, and | |
6654 | updates the read buffer. | |
6655 | ||
6656 | This subroutine pulls a string out of the input. It is called for: | |
6657 | q single quotes q(literal text) | |
6658 | ' single quotes 'literal text' | |
6659 | qq double quotes qq(interpolate $here please) | |
6660 | " double quotes "interpolate $here please" | |
6661 | qx backticks qx(/bin/ls -l) | |
6662 | ` backticks `/bin/ls -l` | |
6663 | qw quote words @EXPORT_OK = qw( func() $spam ) | |
6664 | m// regexp match m/this/ | |
6665 | s/// regexp substitute s/this/that/ | |
6666 | tr/// string transliterate tr/this/that/ | |
6667 | y/// string transliterate y/this/that/ | |
6668 | ($*@) sub prototypes sub foo ($) | |
09bef843 | 6669 | (stuff) sub attr parameters sub foo : attr(stuff) |
02aa26ce NT |
6670 | <> readline or globs <FOO>, <>, <$fh>, or <*.c> |
6671 | ||
6672 | In most of these cases (all but <>, patterns and transliterate) | |
6673 | yylex() calls scan_str(). m// makes yylex() call scan_pat() which | |
6674 | calls scan_str(). s/// makes yylex() call scan_subst() which calls | |
6675 | scan_str(). tr/// and y/// make yylex() call scan_trans() which | |
6676 | calls scan_str(). | |
4e553d73 | 6677 | |
02aa26ce NT |
6678 | It skips whitespace before the string starts, and treats the first |
6679 | character as the delimiter. If the delimiter is one of ([{< then | |
6680 | the corresponding "close" character )]}> is used as the closing | |
6681 | delimiter. It allows quoting of delimiters, and if the string has | |
6682 | balanced delimiters ([{<>}]) it allows nesting. | |
6683 | ||
37fd879b HS |
6684 | On success, the SV with the resulting string is put into lex_stuff or, |
6685 | if that is already non-NULL, into lex_repl. The second case occurs only | |
6686 | when parsing the RHS of the special constructs s/// and tr/// (y///). | |
6687 | For convenience, the terminating delimiter character is stuffed into | |
6688 | SvIVX of the SV. | |
02aa26ce NT |
6689 | */ |
6690 | ||
76e3520e | 6691 | STATIC char * |
09bef843 | 6692 | S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims) |
79072805 | 6693 | { |
02aa26ce NT |
6694 | SV *sv; /* scalar value: string */ |
6695 | char *tmps; /* temp string, used for delimiter matching */ | |
6696 | register char *s = start; /* current position in the buffer */ | |
6697 | register char term; /* terminating character */ | |
6698 | register char *to; /* current position in the sv's data */ | |
6699 | I32 brackets = 1; /* bracket nesting level */ | |
89491803 | 6700 | bool has_utf8 = FALSE; /* is there any utf8 content? */ |
02aa26ce NT |
6701 | |
6702 | /* skip space before the delimiter */ | |
fb73857a | 6703 | if (isSPACE(*s)) |
6704 | s = skipspace(s); | |
02aa26ce NT |
6705 | |
6706 | /* mark where we are, in case we need to report errors */ | |
79072805 | 6707 | CLINE; |
02aa26ce NT |
6708 | |
6709 | /* after skipping whitespace, the next character is the terminator */ | |
a0d0e21e | 6710 | term = *s; |
63cd0674 | 6711 | if (!UTF8_IS_INVARIANT((U8)term) && UTF) |
89491803 | 6712 | has_utf8 = TRUE; |
b1c7b182 | 6713 | |
02aa26ce | 6714 | /* mark where we are */ |
57843af0 | 6715 | PL_multi_start = CopLINE(PL_curcop); |
3280af22 | 6716 | PL_multi_open = term; |
02aa26ce NT |
6717 | |
6718 | /* find corresponding closing delimiter */ | |
93a17b20 | 6719 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) |
79072805 | 6720 | term = tmps[5]; |
3280af22 | 6721 | PL_multi_close = term; |
79072805 | 6722 | |
02aa26ce | 6723 | /* create a new SV to hold the contents. 87 is leak category, I'm |
8d6dde3e IZ |
6724 | assuming. 79 is the SV's initial length. What a random number. */ |
6725 | sv = NEWSV(87,79); | |
ed6116ce LW |
6726 | sv_upgrade(sv, SVt_PVIV); |
6727 | SvIVX(sv) = term; | |
a0d0e21e | 6728 | (void)SvPOK_only(sv); /* validate pointer */ |
02aa26ce NT |
6729 | |
6730 | /* move past delimiter and try to read a complete string */ | |
09bef843 SB |
6731 | if (keep_delims) |
6732 | sv_catpvn(sv, s, 1); | |
93a17b20 LW |
6733 | s++; |
6734 | for (;;) { | |
02aa26ce | 6735 | /* extend sv if need be */ |
3280af22 | 6736 | SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1); |
02aa26ce | 6737 | /* set 'to' to the next character in the sv's string */ |
463ee0b2 | 6738 | to = SvPVX(sv)+SvCUR(sv); |
09bef843 | 6739 | |
02aa26ce | 6740 | /* if open delimiter is the close delimiter read unbridle */ |
3280af22 NIS |
6741 | if (PL_multi_open == PL_multi_close) { |
6742 | for (; s < PL_bufend; s++,to++) { | |
02aa26ce | 6743 | /* embedded newlines increment the current line number */ |
3280af22 | 6744 | if (*s == '\n' && !PL_rsfp) |
57843af0 | 6745 | CopLINE_inc(PL_curcop); |
02aa26ce | 6746 | /* handle quoted delimiters */ |
3280af22 | 6747 | if (*s == '\\' && s+1 < PL_bufend && term != '\\') { |
09bef843 | 6748 | if (!keep_quoted && s[1] == term) |
a0d0e21e | 6749 | s++; |
02aa26ce | 6750 | /* any other quotes are simply copied straight through */ |
a0d0e21e LW |
6751 | else |
6752 | *to++ = *s++; | |
6753 | } | |
02aa26ce NT |
6754 | /* terminate when run out of buffer (the for() condition), or |
6755 | have found the terminator */ | |
93a17b20 LW |
6756 | else if (*s == term) |
6757 | break; | |
63cd0674 | 6758 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
89491803 | 6759 | has_utf8 = TRUE; |
93a17b20 LW |
6760 | *to = *s; |
6761 | } | |
6762 | } | |
02aa26ce NT |
6763 | |
6764 | /* if the terminator isn't the same as the start character (e.g., | |
6765 | matched brackets), we have to allow more in the quoting, and | |
6766 | be prepared for nested brackets. | |
6767 | */ | |
93a17b20 | 6768 | else { |
02aa26ce | 6769 | /* read until we run out of string, or we find the terminator */ |
3280af22 | 6770 | for (; s < PL_bufend; s++,to++) { |
02aa26ce | 6771 | /* embedded newlines increment the line count */ |
3280af22 | 6772 | if (*s == '\n' && !PL_rsfp) |
57843af0 | 6773 | CopLINE_inc(PL_curcop); |
02aa26ce | 6774 | /* backslashes can escape the open or closing characters */ |
3280af22 | 6775 | if (*s == '\\' && s+1 < PL_bufend) { |
09bef843 SB |
6776 | if (!keep_quoted && |
6777 | ((s[1] == PL_multi_open) || (s[1] == PL_multi_close))) | |
a0d0e21e LW |
6778 | s++; |
6779 | else | |
6780 | *to++ = *s++; | |
6781 | } | |
02aa26ce | 6782 | /* allow nested opens and closes */ |
3280af22 | 6783 | else if (*s == PL_multi_close && --brackets <= 0) |
93a17b20 | 6784 | break; |
3280af22 | 6785 | else if (*s == PL_multi_open) |
93a17b20 | 6786 | brackets++; |
63cd0674 | 6787 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
89491803 | 6788 | has_utf8 = TRUE; |
93a17b20 LW |
6789 | *to = *s; |
6790 | } | |
6791 | } | |
02aa26ce | 6792 | /* terminate the copied string and update the sv's end-of-string */ |
93a17b20 | 6793 | *to = '\0'; |
463ee0b2 | 6794 | SvCUR_set(sv, to - SvPVX(sv)); |
93a17b20 | 6795 | |
02aa26ce NT |
6796 | /* |
6797 | * this next chunk reads more into the buffer if we're not done yet | |
6798 | */ | |
6799 | ||
b1c7b182 GS |
6800 | if (s < PL_bufend) |
6801 | break; /* handle case where we are done yet :-) */ | |
79072805 | 6802 | |
6a27c188 | 6803 | #ifndef PERL_STRICT_CR |
f63a84b2 | 6804 | if (to - SvPVX(sv) >= 2) { |
c6f14548 GS |
6805 | if ((to[-2] == '\r' && to[-1] == '\n') || |
6806 | (to[-2] == '\n' && to[-1] == '\r')) | |
6807 | { | |
f63a84b2 LW |
6808 | to[-2] = '\n'; |
6809 | to--; | |
6810 | SvCUR_set(sv, to - SvPVX(sv)); | |
6811 | } | |
6812 | else if (to[-1] == '\r') | |
6813 | to[-1] = '\n'; | |
6814 | } | |
6815 | else if (to - SvPVX(sv) == 1 && to[-1] == '\r') | |
6816 | to[-1] = '\n'; | |
6817 | #endif | |
6818 | ||
02aa26ce NT |
6819 | /* if we're out of file, or a read fails, bail and reset the current |
6820 | line marker so we can report where the unterminated string began | |
6821 | */ | |
3280af22 NIS |
6822 | if (!PL_rsfp || |
6823 | !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { | |
c07a80fd | 6824 | sv_free(sv); |
57843af0 | 6825 | CopLINE_set(PL_curcop, PL_multi_start); |
79072805 LW |
6826 | return Nullch; |
6827 | } | |
02aa26ce | 6828 | /* we read a line, so increment our line counter */ |
57843af0 | 6829 | CopLINE_inc(PL_curcop); |
a0ed51b3 | 6830 | |
02aa26ce | 6831 | /* update debugger info */ |
3280af22 | 6832 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
79072805 LW |
6833 | SV *sv = NEWSV(88,0); |
6834 | ||
93a17b20 | 6835 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 6836 | sv_setsv(sv,PL_linestr); |
57843af0 | 6837 | av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv); |
395c3793 | 6838 | } |
a0ed51b3 | 6839 | |
3280af22 NIS |
6840 | /* having changed the buffer, we must update PL_bufend */ |
6841 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 6842 | PL_last_lop = PL_last_uni = Nullch; |
378cc40b | 6843 | } |
4e553d73 | 6844 | |
02aa26ce NT |
6845 | /* at this point, we have successfully read the delimited string */ |
6846 | ||
09bef843 SB |
6847 | if (keep_delims) |
6848 | sv_catpvn(sv, s, 1); | |
89491803 | 6849 | if (has_utf8) |
b1c7b182 | 6850 | SvUTF8_on(sv); |
57843af0 | 6851 | PL_multi_end = CopLINE(PL_curcop); |
79072805 | 6852 | s++; |
02aa26ce NT |
6853 | |
6854 | /* if we allocated too much space, give some back */ | |
93a17b20 LW |
6855 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
6856 | SvLEN_set(sv, SvCUR(sv) + 1); | |
463ee0b2 | 6857 | Renew(SvPVX(sv), SvLEN(sv), char); |
79072805 | 6858 | } |
02aa26ce NT |
6859 | |
6860 | /* decide whether this is the first or second quoted string we've read | |
6861 | for this op | |
6862 | */ | |
4e553d73 | 6863 | |
3280af22 NIS |
6864 | if (PL_lex_stuff) |
6865 | PL_lex_repl = sv; | |
79072805 | 6866 | else |
3280af22 | 6867 | PL_lex_stuff = sv; |
378cc40b LW |
6868 | return s; |
6869 | } | |
6870 | ||
02aa26ce NT |
6871 | /* |
6872 | scan_num | |
6873 | takes: pointer to position in buffer | |
6874 | returns: pointer to new position in buffer | |
6875 | side-effects: builds ops for the constant in yylval.op | |
6876 | ||
6877 | Read a number in any of the formats that Perl accepts: | |
6878 | ||
4f19785b | 6879 | 0(x[0-7A-F]+)|([0-7]+)|(b[01]) |
928753ea | 6880 | \d([\d_]*\d)?(\.\d([\d_]*\d)?)?[Ee](\d+) |
02aa26ce NT |
6881 | |
6882 | Underbars (_) are allowed in decimal numbers. If -w is on, | |
928753ea JH |
6883 | underbars must not be consecutive, and they cannot start |
6884 | or end integer or fractional parts. | |
02aa26ce | 6885 | |
3280af22 | 6886 | Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the |
02aa26ce NT |
6887 | thing it reads. |
6888 | ||
6889 | If it reads a number without a decimal point or an exponent, it will | |
6890 | try converting the number to an integer and see if it can do so | |
6891 | without loss of precision. | |
6892 | */ | |
4e553d73 | 6893 | |
378cc40b | 6894 | char * |
b73d6f50 | 6895 | Perl_scan_num(pTHX_ char *start, YYSTYPE* lvalp) |
378cc40b | 6896 | { |
02aa26ce NT |
6897 | register char *s = start; /* current position in buffer */ |
6898 | register char *d; /* destination in temp buffer */ | |
6899 | register char *e; /* end of temp buffer */ | |
86554af2 | 6900 | NV nv; /* number read, as a double */ |
a7cb1f99 | 6901 | SV *sv = Nullsv; /* place to put the converted number */ |
b8403495 | 6902 | bool floatit; /* boolean: int or float? */ |
02aa26ce | 6903 | char *lastub = 0; /* position of last underbar */ |
fc36a67e | 6904 | static char number_too_long[] = "Number too long"; |
378cc40b | 6905 | |
02aa26ce NT |
6906 | /* We use the first character to decide what type of number this is */ |
6907 | ||
378cc40b | 6908 | switch (*s) { |
79072805 | 6909 | default: |
cea2e8a9 | 6910 | Perl_croak(aTHX_ "panic: scan_num"); |
4e553d73 | 6911 | |
02aa26ce | 6912 | /* if it starts with a 0, it could be an octal number, a decimal in |
a7cb1f99 | 6913 | 0.13 disguise, or a hexadecimal number, or a binary number. */ |
378cc40b LW |
6914 | case '0': |
6915 | { | |
02aa26ce NT |
6916 | /* variables: |
6917 | u holds the "number so far" | |
4f19785b WSI |
6918 | shift the power of 2 of the base |
6919 | (hex == 4, octal == 3, binary == 1) | |
02aa26ce NT |
6920 | overflowed was the number more than we can hold? |
6921 | ||
6922 | Shift is used when we add a digit. It also serves as an "are | |
4f19785b WSI |
6923 | we in octal/hex/binary?" indicator to disallow hex characters |
6924 | when in octal mode. | |
02aa26ce | 6925 | */ |
9e24b6e2 JH |
6926 | NV n = 0.0; |
6927 | UV u = 0; | |
79072805 | 6928 | I32 shift; |
9e24b6e2 JH |
6929 | bool overflowed = FALSE; |
6930 | static NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 }; | |
6931 | static char* bases[5] = { "", "binary", "", "octal", | |
6932 | "hexadecimal" }; | |
6933 | static char* Bases[5] = { "", "Binary", "", "Octal", | |
6934 | "Hexadecimal" }; | |
6935 | static char *maxima[5] = { "", | |
6936 | "0b11111111111111111111111111111111", | |
6937 | "", | |
893fe2c2 | 6938 | "037777777777", |
9e24b6e2 JH |
6939 | "0xffffffff" }; |
6940 | char *base, *Base, *max; | |
378cc40b | 6941 | |
02aa26ce | 6942 | /* check for hex */ |
378cc40b LW |
6943 | if (s[1] == 'x') { |
6944 | shift = 4; | |
6945 | s += 2; | |
4f19785b WSI |
6946 | } else if (s[1] == 'b') { |
6947 | shift = 1; | |
6948 | s += 2; | |
378cc40b | 6949 | } |
02aa26ce | 6950 | /* check for a decimal in disguise */ |
b78218b7 | 6951 | else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E') |
378cc40b | 6952 | goto decimal; |
02aa26ce | 6953 | /* so it must be octal */ |
928753ea | 6954 | else { |
378cc40b | 6955 | shift = 3; |
928753ea JH |
6956 | s++; |
6957 | } | |
6958 | ||
6959 | if (*s == '_') { | |
6960 | if (ckWARN(WARN_SYNTAX)) | |
6961 | Perl_warner(aTHX_ WARN_SYNTAX, | |
6962 | "Misplaced _ in number"); | |
6963 | lastub = s++; | |
6964 | } | |
9e24b6e2 JH |
6965 | |
6966 | base = bases[shift]; | |
6967 | Base = Bases[shift]; | |
6968 | max = maxima[shift]; | |
02aa26ce | 6969 | |
4f19785b | 6970 | /* read the rest of the number */ |
378cc40b | 6971 | for (;;) { |
9e24b6e2 | 6972 | /* x is used in the overflow test, |
893fe2c2 | 6973 | b is the digit we're adding on. */ |
9e24b6e2 | 6974 | UV x, b; |
55497cff | 6975 | |
378cc40b | 6976 | switch (*s) { |
02aa26ce NT |
6977 | |
6978 | /* if we don't mention it, we're done */ | |
378cc40b LW |
6979 | default: |
6980 | goto out; | |
02aa26ce | 6981 | |
928753ea | 6982 | /* _ are ignored -- but warned about if consecutive */ |
de3bb511 | 6983 | case '_': |
928753ea JH |
6984 | if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1) |
6985 | Perl_warner(aTHX_ WARN_SYNTAX, | |
6986 | "Misplaced _ in number"); | |
6987 | lastub = s++; | |
de3bb511 | 6988 | break; |
02aa26ce NT |
6989 | |
6990 | /* 8 and 9 are not octal */ | |
378cc40b | 6991 | case '8': case '9': |
4f19785b | 6992 | if (shift == 3) |
cea2e8a9 | 6993 | yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s)); |
378cc40b | 6994 | /* FALL THROUGH */ |
02aa26ce NT |
6995 | |
6996 | /* octal digits */ | |
4f19785b | 6997 | case '2': case '3': case '4': |
378cc40b | 6998 | case '5': case '6': case '7': |
4f19785b | 6999 | if (shift == 1) |
cea2e8a9 | 7000 | yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s)); |
4f19785b WSI |
7001 | /* FALL THROUGH */ |
7002 | ||
7003 | case '0': case '1': | |
02aa26ce | 7004 | b = *s++ & 15; /* ASCII digit -> value of digit */ |
55497cff | 7005 | goto digit; |
02aa26ce NT |
7006 | |
7007 | /* hex digits */ | |
378cc40b LW |
7008 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': |
7009 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': | |
02aa26ce | 7010 | /* make sure they said 0x */ |
378cc40b LW |
7011 | if (shift != 4) |
7012 | goto out; | |
55497cff | 7013 | b = (*s++ & 7) + 9; |
02aa26ce NT |
7014 | |
7015 | /* Prepare to put the digit we have onto the end | |
7016 | of the number so far. We check for overflows. | |
7017 | */ | |
7018 | ||
55497cff | 7019 | digit: |
9e24b6e2 JH |
7020 | if (!overflowed) { |
7021 | x = u << shift; /* make room for the digit */ | |
7022 | ||
7023 | if ((x >> shift) != u | |
7024 | && !(PL_hints & HINT_NEW_BINARY)) { | |
9e24b6e2 JH |
7025 | overflowed = TRUE; |
7026 | n = (NV) u; | |
767a6a26 PM |
7027 | if (ckWARN_d(WARN_OVERFLOW)) |
7028 | Perl_warner(aTHX_ WARN_OVERFLOW, | |
9e24b6e2 JH |
7029 | "Integer overflow in %s number", |
7030 | base); | |
7031 | } else | |
7032 | u = x | b; /* add the digit to the end */ | |
7033 | } | |
7034 | if (overflowed) { | |
7035 | n *= nvshift[shift]; | |
7036 | /* If an NV has not enough bits in its | |
7037 | * mantissa to represent an UV this summing of | |
7038 | * small low-order numbers is a waste of time | |
7039 | * (because the NV cannot preserve the | |
7040 | * low-order bits anyway): we could just | |
7041 | * remember when did we overflow and in the | |
7042 | * end just multiply n by the right | |
7043 | * amount. */ | |
7044 | n += (NV) b; | |
55497cff | 7045 | } |
378cc40b LW |
7046 | break; |
7047 | } | |
7048 | } | |
02aa26ce NT |
7049 | |
7050 | /* if we get here, we had success: make a scalar value from | |
7051 | the number. | |
7052 | */ | |
378cc40b | 7053 | out: |
928753ea JH |
7054 | |
7055 | /* final misplaced underbar check */ | |
7056 | if (s[-1] == '_') { | |
7057 | if (ckWARN(WARN_SYNTAX)) | |
7058 | Perl_warner(aTHX_ WARN_SYNTAX, "Misplaced _ in number"); | |
7059 | } | |
7060 | ||
79072805 | 7061 | sv = NEWSV(92,0); |
9e24b6e2 | 7062 | if (overflowed) { |
767a6a26 PM |
7063 | if (ckWARN(WARN_PORTABLE) && n > 4294967295.0) |
7064 | Perl_warner(aTHX_ WARN_PORTABLE, | |
9e24b6e2 JH |
7065 | "%s number > %s non-portable", |
7066 | Base, max); | |
7067 | sv_setnv(sv, n); | |
7068 | } | |
7069 | else { | |
15041a67 | 7070 | #if UVSIZE > 4 |
767a6a26 PM |
7071 | if (ckWARN(WARN_PORTABLE) && u > 0xffffffff) |
7072 | Perl_warner(aTHX_ WARN_PORTABLE, | |
9e24b6e2 JH |
7073 | "%s number > %s non-portable", |
7074 | Base, max); | |
2cc4c2dc | 7075 | #endif |
9e24b6e2 JH |
7076 | sv_setuv(sv, u); |
7077 | } | |
2cc4c2dc | 7078 | if (PL_hints & HINT_NEW_BINARY) |
b3ac6de7 | 7079 | sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL); |
378cc40b LW |
7080 | } |
7081 | break; | |
02aa26ce NT |
7082 | |
7083 | /* | |
7084 | handle decimal numbers. | |
7085 | we're also sent here when we read a 0 as the first digit | |
7086 | */ | |
378cc40b LW |
7087 | case '1': case '2': case '3': case '4': case '5': |
7088 | case '6': case '7': case '8': case '9': case '.': | |
7089 | decimal: | |
3280af22 NIS |
7090 | d = PL_tokenbuf; |
7091 | e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */ | |
79072805 | 7092 | floatit = FALSE; |
02aa26ce NT |
7093 | |
7094 | /* read next group of digits and _ and copy into d */ | |
de3bb511 | 7095 | while (isDIGIT(*s) || *s == '_') { |
4e553d73 | 7096 | /* skip underscores, checking for misplaced ones |
02aa26ce NT |
7097 | if -w is on |
7098 | */ | |
93a17b20 | 7099 | if (*s == '_') { |
928753ea JH |
7100 | if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1) |
7101 | Perl_warner(aTHX_ WARN_SYNTAX, | |
7102 | "Misplaced _ in number"); | |
7103 | lastub = s++; | |
93a17b20 | 7104 | } |
fc36a67e | 7105 | else { |
02aa26ce | 7106 | /* check for end of fixed-length buffer */ |
fc36a67e | 7107 | if (d >= e) |
cea2e8a9 | 7108 | Perl_croak(aTHX_ number_too_long); |
02aa26ce | 7109 | /* if we're ok, copy the character */ |
378cc40b | 7110 | *d++ = *s++; |
fc36a67e | 7111 | } |
378cc40b | 7112 | } |
02aa26ce NT |
7113 | |
7114 | /* final misplaced underbar check */ | |
928753ea | 7115 | if (lastub && s == lastub + 1) { |
d008e5eb | 7116 | if (ckWARN(WARN_SYNTAX)) |
cea2e8a9 | 7117 | Perl_warner(aTHX_ WARN_SYNTAX, "Misplaced _ in number"); |
d008e5eb | 7118 | } |
02aa26ce NT |
7119 | |
7120 | /* read a decimal portion if there is one. avoid | |
7121 | 3..5 being interpreted as the number 3. followed | |
7122 | by .5 | |
7123 | */ | |
2f3197b3 | 7124 | if (*s == '.' && s[1] != '.') { |
79072805 | 7125 | floatit = TRUE; |
378cc40b | 7126 | *d++ = *s++; |
02aa26ce | 7127 | |
928753ea JH |
7128 | if (*s == '_') { |
7129 | if (ckWARN(WARN_SYNTAX)) | |
7130 | Perl_warner(aTHX_ WARN_SYNTAX, | |
7131 | "Misplaced _ in number"); | |
7132 | lastub = s; | |
7133 | } | |
7134 | ||
7135 | /* copy, ignoring underbars, until we run out of digits. | |
02aa26ce | 7136 | */ |
fc36a67e | 7137 | for (; isDIGIT(*s) || *s == '_'; s++) { |
02aa26ce | 7138 | /* fixed length buffer check */ |
fc36a67e | 7139 | if (d >= e) |
cea2e8a9 | 7140 | Perl_croak(aTHX_ number_too_long); |
928753ea JH |
7141 | if (*s == '_') { |
7142 | if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1) | |
7143 | Perl_warner(aTHX_ WARN_SYNTAX, | |
7144 | "Misplaced _ in number"); | |
7145 | lastub = s; | |
7146 | } | |
7147 | else | |
fc36a67e | 7148 | *d++ = *s; |
378cc40b | 7149 | } |
928753ea JH |
7150 | /* fractional part ending in underbar? */ |
7151 | if (s[-1] == '_') { | |
7152 | if (ckWARN(WARN_SYNTAX)) | |
7153 | Perl_warner(aTHX_ WARN_SYNTAX, | |
7154 | "Misplaced _ in number"); | |
7155 | } | |
dd629d5b GS |
7156 | if (*s == '.' && isDIGIT(s[1])) { |
7157 | /* oops, it's really a v-string, but without the "v" */ | |
7158 | s = start - 1; | |
7159 | goto vstring; | |
7160 | } | |
378cc40b | 7161 | } |
02aa26ce NT |
7162 | |
7163 | /* read exponent part, if present */ | |
93a17b20 | 7164 | if (*s && strchr("eE",*s) && strchr("+-0123456789",s[1])) { |
79072805 LW |
7165 | floatit = TRUE; |
7166 | s++; | |
02aa26ce NT |
7167 | |
7168 | /* regardless of whether user said 3E5 or 3e5, use lower 'e' */ | |
79072805 | 7169 | *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */ |
02aa26ce NT |
7170 | |
7171 | /* allow positive or negative exponent */ | |
378cc40b LW |
7172 | if (*s == '+' || *s == '-') |
7173 | *d++ = *s++; | |
02aa26ce NT |
7174 | |
7175 | /* read digits of exponent (no underbars :-) */ | |
fc36a67e | 7176 | while (isDIGIT(*s)) { |
7177 | if (d >= e) | |
cea2e8a9 | 7178 | Perl_croak(aTHX_ number_too_long); |
378cc40b | 7179 | *d++ = *s++; |
fc36a67e | 7180 | } |
378cc40b | 7181 | } |
02aa26ce NT |
7182 | |
7183 | /* terminate the string */ | |
378cc40b | 7184 | *d = '\0'; |
02aa26ce NT |
7185 | |
7186 | /* make an sv from the string */ | |
79072805 | 7187 | sv = NEWSV(92,0); |
097ee67d | 7188 | |
86554af2 | 7189 | #if defined(Strtol) && defined(Strtoul) |
0b7fceb9 MU |
7190 | |
7191 | /* | |
0b7fceb9 MU |
7192 | strtol/strtoll sets errno to ERANGE if the number is too big |
7193 | for an integer. We try to do an integer conversion first | |
7194 | if no characters indicating "float" have been found. | |
7195 | */ | |
7196 | ||
7197 | if (!floatit) { | |
0b7fceb9 MU |
7198 | IV iv; |
7199 | UV uv; | |
7200 | errno = 0; | |
c239479b | 7201 | if (*PL_tokenbuf == '-') |
96989be3 | 7202 | iv = Strtol(PL_tokenbuf, (char**)NULL, 10); |
c239479b | 7203 | else |
96989be3 | 7204 | uv = Strtoul(PL_tokenbuf, (char**)NULL, 10); |
55eb892c | 7205 | if (errno) |
86554af2 | 7206 | floatit = TRUE; /* Probably just too large. */ |
0b7fceb9 MU |
7207 | else if (*PL_tokenbuf == '-') |
7208 | sv_setiv(sv, iv); | |
86554af2 JH |
7209 | else if (uv <= IV_MAX) |
7210 | sv_setiv(sv, uv); /* Prefer IVs over UVs. */ | |
0b7fceb9 | 7211 | else |
c239479b | 7212 | sv_setuv(sv, uv); |
0b7fceb9 MU |
7213 | } |
7214 | if (floatit) { | |
86554af2 JH |
7215 | nv = Atof(PL_tokenbuf); |
7216 | sv_setnv(sv, nv); | |
7217 | } | |
7218 | #else | |
7219 | /* | |
7220 | No working strtou?ll?. | |
7221 | ||
7222 | Unfortunately atol() doesn't do range checks (returning | |
7223 | LONG_MIN/LONG_MAX, and setting errno to ERANGE on overflows) | |
7224 | everywhere [1], so we cannot use use atol() (or atoll()). | |
7225 | If we could, they would be used, as Atol(), very much like | |
7226 | Strtol() and Strtoul() are used above. | |
7227 | ||
7228 | [1] XXX Configure test needed to check for atol() | |
d6c14000 JH |
7229 | (and atoll()) overflow behaviour XXX |
7230 | ||
7231 | --jhi | |
86554af2 JH |
7232 | |
7233 | We need to do this the hard way. */ | |
7234 | ||
7235 | nv = Atof(PL_tokenbuf); | |
7236 | ||
7237 | /* See if we can make do with an integer value without loss of | |
7238 | precision. We use U_V to cast to a UV, because some | |
7239 | compilers have issues. Then we try casting it back and see | |
7240 | if it was the same [1]. We only do this if we know we | |
7241 | specifically read an integer. If floatit is true, then we | |
4e553d73 | 7242 | don't need to do the conversion at all. |
86554af2 JH |
7243 | |
7244 | [1] Note that this is lossy if our NVs cannot preserve our | |
d6c14000 JH |
7245 | UVs. There are metaconfig defines NV_PRESERVES_UV (a boolean) |
7246 | and NV_PRESERVES_UV_BITS (a number), but in general we really | |
7247 | do hope all such potentially lossy platforms have strtou?ll? | |
7248 | to do a lossless IV/UV conversion. | |
7249 | ||
7250 | Maybe could do some tricks with DBL_DIG, LDBL_DIG and | |
7251 | DBL_MANT_DIG and LDBL_MANT_DIG (these are already available | |
7252 | as NV_DIG and NV_MANT_DIG)? | |
4e553d73 | 7253 | |
d6c14000 | 7254 | --jhi |
86554af2 JH |
7255 | */ |
7256 | { | |
7257 | UV uv = U_V(nv); | |
7258 | if (!floatit && (NV)uv == nv) { | |
7259 | if (uv <= IV_MAX) | |
7260 | sv_setiv(sv, uv); /* Prefer IVs over UVs. */ | |
7261 | else | |
7262 | sv_setuv(sv, uv); | |
7263 | } | |
7264 | else | |
7265 | sv_setnv(sv, nv); | |
96989be3 | 7266 | } |
0b7fceb9 | 7267 | #endif |
b8403495 JH |
7268 | if ( floatit ? (PL_hints & HINT_NEW_FLOAT) : |
7269 | (PL_hints & HINT_NEW_INTEGER) ) | |
4e553d73 | 7270 | sv = new_constant(PL_tokenbuf, d - PL_tokenbuf, |
b8403495 JH |
7271 | (floatit ? "float" : "integer"), |
7272 | sv, Nullsv, NULL); | |
378cc40b | 7273 | break; |
0b7fceb9 | 7274 | |
e312add1 | 7275 | /* if it starts with a v, it could be a v-string */ |
a7cb1f99 | 7276 | case 'v': |
dd629d5b | 7277 | vstring: |
a7cb1f99 | 7278 | { |
a7cb1f99 GS |
7279 | char *pos = s; |
7280 | pos++; | |
dd629d5b | 7281 | while (isDIGIT(*pos) || *pos == '_') |
a7cb1f99 | 7282 | pos++; |
e526c9e6 | 7283 | if (!isALPHA(*pos)) { |
c4d5f83a | 7284 | UV rev; |
ad391ad9 | 7285 | U8 tmpbuf[UTF8_MAXLEN+1]; |
a7cb1f99 | 7286 | U8 *tmpend; |
a7cb1f99 GS |
7287 | s++; /* get past 'v' */ |
7288 | ||
7289 | sv = NEWSV(92,5); | |
a7cb1f99 GS |
7290 | sv_setpvn(sv, "", 0); |
7291 | ||
e526c9e6 | 7292 | for (;;) { |
3cb0bbe5 GS |
7293 | if (*s == '0' && isDIGIT(s[1])) |
7294 | yyerror("Octal number in vector unsupported"); | |
dd629d5b GS |
7295 | rev = 0; |
7296 | { | |
7297 | /* this is atoi() that tolerates underscores */ | |
7298 | char *end = pos; | |
7299 | UV mult = 1; | |
7300 | while (--end >= s) { | |
7301 | UV orev; | |
7302 | if (*end == '_') | |
7303 | continue; | |
7304 | orev = rev; | |
7305 | rev += (*end - '0') * mult; | |
7306 | mult *= 10; | |
7307 | if (orev > rev && ckWARN_d(WARN_OVERFLOW)) | |
7308 | Perl_warner(aTHX_ WARN_OVERFLOW, | |
7309 | "Integer overflow in decimal number"); | |
7310 | } | |
7311 | } | |
9041c2e3 NIS |
7312 | /* Append native character for the rev point */ |
7313 | tmpend = uvchr_to_utf8(tmpbuf, rev); | |
e526c9e6 | 7314 | sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf); |
c4d5f83a NIS |
7315 | if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev))) |
7316 | SvUTF8_on(sv); | |
e526c9e6 GS |
7317 | if (*pos == '.' && isDIGIT(pos[1])) |
7318 | s = ++pos; | |
3818b22b | 7319 | else { |
e526c9e6 GS |
7320 | s = pos; |
7321 | break; | |
3818b22b | 7322 | } |
dd629d5b | 7323 | while (isDIGIT(*pos) || *pos == '_') |
e526c9e6 GS |
7324 | pos++; |
7325 | } | |
a7cb1f99 | 7326 | SvPOK_on(sv); |
a7cb1f99 | 7327 | SvREADONLY_on(sv); |
a7cb1f99 GS |
7328 | } |
7329 | } | |
7330 | break; | |
79072805 | 7331 | } |
a687059c | 7332 | |
02aa26ce NT |
7333 | /* make the op for the constant and return */ |
7334 | ||
a7cb1f99 | 7335 | if (sv) |
b73d6f50 | 7336 | lvalp->opval = newSVOP(OP_CONST, 0, sv); |
a7cb1f99 | 7337 | else |
b73d6f50 | 7338 | lvalp->opval = Nullop; |
a687059c | 7339 | |
378cc40b LW |
7340 | return s; |
7341 | } | |
7342 | ||
76e3520e | 7343 | STATIC char * |
cea2e8a9 | 7344 | S_scan_formline(pTHX_ register char *s) |
378cc40b | 7345 | { |
79072805 | 7346 | register char *eol; |
378cc40b | 7347 | register char *t; |
79cb57f6 | 7348 | SV *stuff = newSVpvn("",0); |
79072805 | 7349 | bool needargs = FALSE; |
378cc40b | 7350 | |
79072805 | 7351 | while (!needargs) { |
c2e66d9e | 7352 | if (*s == '.' || *s == /*{*/'}') { |
79072805 | 7353 | /*SUPPRESS 530*/ |
51882d45 | 7354 | #ifdef PERL_STRICT_CR |
bf4acbe4 | 7355 | for (t = s+1;SPACE_OR_TAB(*t); t++) ; |
51882d45 | 7356 | #else |
bf4acbe4 | 7357 | for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ; |
51882d45 | 7358 | #endif |
6a65c6a0 | 7359 | if (*t == '\n' || t == PL_bufend) |
79072805 LW |
7360 | break; |
7361 | } | |
3280af22 | 7362 | if (PL_in_eval && !PL_rsfp) { |
93a17b20 | 7363 | eol = strchr(s,'\n'); |
0f85fab0 | 7364 | if (!eol++) |
3280af22 | 7365 | eol = PL_bufend; |
0f85fab0 LW |
7366 | } |
7367 | else | |
3280af22 | 7368 | eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
79072805 | 7369 | if (*s != '#') { |
a0d0e21e LW |
7370 | for (t = s; t < eol; t++) { |
7371 | if (*t == '~' && t[1] == '~' && SvCUR(stuff)) { | |
7372 | needargs = FALSE; | |
7373 | goto enough; /* ~~ must be first line in formline */ | |
378cc40b | 7374 | } |
a0d0e21e LW |
7375 | if (*t == '@' || *t == '^') |
7376 | needargs = TRUE; | |
378cc40b | 7377 | } |
a0d0e21e | 7378 | sv_catpvn(stuff, s, eol-s); |
2dc4c65b GS |
7379 | #ifndef PERL_STRICT_CR |
7380 | if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') { | |
7381 | char *end = SvPVX(stuff) + SvCUR(stuff); | |
7382 | end[-2] = '\n'; | |
7383 | end[-1] = '\0'; | |
7384 | SvCUR(stuff)--; | |
7385 | } | |
7386 | #endif | |
79072805 LW |
7387 | } |
7388 | s = eol; | |
3280af22 NIS |
7389 | if (PL_rsfp) { |
7390 | s = filter_gets(PL_linestr, PL_rsfp, 0); | |
7391 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr); | |
7392 | PL_bufend = PL_bufptr + SvCUR(PL_linestr); | |
207e3d1a | 7393 | PL_last_lop = PL_last_uni = Nullch; |
79072805 | 7394 | if (!s) { |
3280af22 | 7395 | s = PL_bufptr; |
79072805 | 7396 | yyerror("Format not terminated"); |
378cc40b LW |
7397 | break; |
7398 | } | |
378cc40b | 7399 | } |
463ee0b2 | 7400 | incline(s); |
79072805 | 7401 | } |
a0d0e21e LW |
7402 | enough: |
7403 | if (SvCUR(stuff)) { | |
3280af22 | 7404 | PL_expect = XTERM; |
79072805 | 7405 | if (needargs) { |
3280af22 NIS |
7406 | PL_lex_state = LEX_NORMAL; |
7407 | PL_nextval[PL_nexttoke].ival = 0; | |
79072805 LW |
7408 | force_next(','); |
7409 | } | |
a0d0e21e | 7410 | else |
3280af22 NIS |
7411 | PL_lex_state = LEX_FORMLINE; |
7412 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff); | |
79072805 | 7413 | force_next(THING); |
3280af22 | 7414 | PL_nextval[PL_nexttoke].ival = OP_FORMLINE; |
79072805 | 7415 | force_next(LSTOP); |
378cc40b | 7416 | } |
79072805 | 7417 | else { |
8990e307 | 7418 | SvREFCNT_dec(stuff); |
3280af22 NIS |
7419 | PL_lex_formbrack = 0; |
7420 | PL_bufptr = s; | |
79072805 LW |
7421 | } |
7422 | return s; | |
378cc40b | 7423 | } |
a687059c | 7424 | |
76e3520e | 7425 | STATIC void |
cea2e8a9 | 7426 | S_set_csh(pTHX) |
a687059c | 7427 | { |
ae986130 | 7428 | #ifdef CSH |
3280af22 NIS |
7429 | if (!PL_cshlen) |
7430 | PL_cshlen = strlen(PL_cshname); | |
ae986130 | 7431 | #endif |
a687059c | 7432 | } |
463ee0b2 | 7433 | |
ba6d6ac9 | 7434 | I32 |
864dbfa3 | 7435 | Perl_start_subparse(pTHX_ I32 is_format, U32 flags) |
8990e307 | 7436 | { |
3280af22 NIS |
7437 | I32 oldsavestack_ix = PL_savestack_ix; |
7438 | CV* outsidecv = PL_compcv; | |
748a9306 | 7439 | AV* comppadlist; |
8990e307 | 7440 | |
3280af22 NIS |
7441 | if (PL_compcv) { |
7442 | assert(SvTYPE(PL_compcv) == SVt_PVCV); | |
e9a444f0 | 7443 | } |
7766f137 | 7444 | SAVEI32(PL_subline); |
3280af22 NIS |
7445 | save_item(PL_subname); |
7446 | SAVEI32(PL_padix); | |
354992b1 | 7447 | SAVECOMPPAD(); |
3280af22 NIS |
7448 | SAVESPTR(PL_comppad_name); |
7449 | SAVESPTR(PL_compcv); | |
7450 | SAVEI32(PL_comppad_name_fill); | |
7451 | SAVEI32(PL_min_intro_pending); | |
7452 | SAVEI32(PL_max_intro_pending); | |
7453 | SAVEI32(PL_pad_reset_pending); | |
7454 | ||
7455 | PL_compcv = (CV*)NEWSV(1104,0); | |
7456 | sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV); | |
7457 | CvFLAGS(PL_compcv) |= flags; | |
7458 | ||
7459 | PL_comppad = newAV(); | |
7460 | av_push(PL_comppad, Nullsv); | |
7461 | PL_curpad = AvARRAY(PL_comppad); | |
7462 | PL_comppad_name = newAV(); | |
7463 | PL_comppad_name_fill = 0; | |
7464 | PL_min_intro_pending = 0; | |
7465 | PL_padix = 0; | |
57843af0 | 7466 | PL_subline = CopLINE(PL_curcop); |
6d4ff0d2 | 7467 | #ifdef USE_THREADS |
79cb57f6 | 7468 | av_store(PL_comppad_name, 0, newSVpvn("@_", 2)); |
533c011a NIS |
7469 | PL_curpad[0] = (SV*)newAV(); |
7470 | SvPADMY_on(PL_curpad[0]); /* XXX Needed? */ | |
6d4ff0d2 | 7471 | #endif /* USE_THREADS */ |
748a9306 LW |
7472 | |
7473 | comppadlist = newAV(); | |
7474 | AvREAL_off(comppadlist); | |
3280af22 NIS |
7475 | av_store(comppadlist, 0, (SV*)PL_comppad_name); |
7476 | av_store(comppadlist, 1, (SV*)PL_comppad); | |
748a9306 | 7477 | |
3280af22 NIS |
7478 | CvPADLIST(PL_compcv) = comppadlist; |
7479 | CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv); | |
11343788 | 7480 | #ifdef USE_THREADS |
533c011a NIS |
7481 | CvOWNER(PL_compcv) = 0; |
7482 | New(666, CvMUTEXP(PL_compcv), 1, perl_mutex); | |
7483 | MUTEX_INIT(CvMUTEXP(PL_compcv)); | |
11343788 | 7484 | #endif /* USE_THREADS */ |
748a9306 | 7485 | |
8990e307 LW |
7486 | return oldsavestack_ix; |
7487 | } | |
7488 | ||
084592ab CN |
7489 | #ifdef __SC__ |
7490 | #pragma segment Perl_yylex | |
7491 | #endif | |
8990e307 | 7492 | int |
864dbfa3 | 7493 | Perl_yywarn(pTHX_ char *s) |
8990e307 | 7494 | { |
faef0170 | 7495 | PL_in_eval |= EVAL_WARNONLY; |
748a9306 | 7496 | yyerror(s); |
faef0170 | 7497 | PL_in_eval &= ~EVAL_WARNONLY; |
748a9306 | 7498 | return 0; |
8990e307 LW |
7499 | } |
7500 | ||
7501 | int | |
864dbfa3 | 7502 | Perl_yyerror(pTHX_ char *s) |
463ee0b2 | 7503 | { |
68dc0745 | 7504 | char *where = NULL; |
7505 | char *context = NULL; | |
7506 | int contlen = -1; | |
46fc3d4c | 7507 | SV *msg; |
463ee0b2 | 7508 | |
3280af22 | 7509 | if (!yychar || (yychar == ';' && !PL_rsfp)) |
54310121 | 7510 | where = "at EOF"; |
3280af22 NIS |
7511 | else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 && |
7512 | PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) { | |
7513 | while (isSPACE(*PL_oldoldbufptr)) | |
7514 | PL_oldoldbufptr++; | |
7515 | context = PL_oldoldbufptr; | |
7516 | contlen = PL_bufptr - PL_oldoldbufptr; | |
463ee0b2 | 7517 | } |
3280af22 NIS |
7518 | else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 && |
7519 | PL_oldbufptr != PL_bufptr) { | |
7520 | while (isSPACE(*PL_oldbufptr)) | |
7521 | PL_oldbufptr++; | |
7522 | context = PL_oldbufptr; | |
7523 | contlen = PL_bufptr - PL_oldbufptr; | |
463ee0b2 LW |
7524 | } |
7525 | else if (yychar > 255) | |
68dc0745 | 7526 | where = "next token ???"; |
cdfb297e GS |
7527 | #ifdef USE_PURE_BISON |
7528 | /* GNU Bison sets the value -2 */ | |
7529 | else if (yychar == -2) { | |
7530 | #else | |
463ee0b2 | 7531 | else if ((yychar & 127) == 127) { |
cdfb297e | 7532 | #endif |
3280af22 NIS |
7533 | if (PL_lex_state == LEX_NORMAL || |
7534 | (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL)) | |
68dc0745 | 7535 | where = "at end of line"; |
3280af22 | 7536 | else if (PL_lex_inpat) |
68dc0745 | 7537 | where = "within pattern"; |
463ee0b2 | 7538 | else |
68dc0745 | 7539 | where = "within string"; |
463ee0b2 | 7540 | } |
46fc3d4c | 7541 | else { |
79cb57f6 | 7542 | SV *where_sv = sv_2mortal(newSVpvn("next char ", 10)); |
46fc3d4c | 7543 | if (yychar < 32) |
cea2e8a9 | 7544 | Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar)); |
46fc3d4c | 7545 | else if (isPRINT_LC(yychar)) |
cea2e8a9 | 7546 | Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar); |
463ee0b2 | 7547 | else |
cea2e8a9 | 7548 | Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255); |
46fc3d4c | 7549 | where = SvPVX(where_sv); |
463ee0b2 | 7550 | } |
46fc3d4c | 7551 | msg = sv_2mortal(newSVpv(s, 0)); |
ed094faf GS |
7552 | Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ", |
7553 | CopFILE(PL_curcop), (IV)CopLINE(PL_curcop)); | |
68dc0745 | 7554 | if (context) |
cea2e8a9 | 7555 | Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context); |
463ee0b2 | 7556 | else |
cea2e8a9 | 7557 | Perl_sv_catpvf(aTHX_ msg, "%s\n", where); |
57843af0 | 7558 | if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) { |
cf2093f6 | 7559 | Perl_sv_catpvf(aTHX_ msg, |
57def98f | 7560 | " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n", |
cf2093f6 | 7561 | (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start); |
3280af22 | 7562 | PL_multi_end = 0; |
a0d0e21e | 7563 | } |
faef0170 | 7564 | if (PL_in_eval & EVAL_WARNONLY) |
894356b3 | 7565 | Perl_warn(aTHX_ "%"SVf, msg); |
463ee0b2 | 7566 | else |
5a844595 | 7567 | qerror(msg); |
c7d6bfb2 GS |
7568 | if (PL_error_count >= 10) { |
7569 | if (PL_in_eval && SvCUR(ERRSV)) | |
d2560b70 | 7570 | Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n", |
c7d6bfb2 GS |
7571 | ERRSV, CopFILE(PL_curcop)); |
7572 | else | |
7573 | Perl_croak(aTHX_ "%s has too many errors.\n", | |
7574 | CopFILE(PL_curcop)); | |
7575 | } | |
3280af22 NIS |
7576 | PL_in_my = 0; |
7577 | PL_in_my_stash = Nullhv; | |
463ee0b2 LW |
7578 | return 0; |
7579 | } | |
084592ab CN |
7580 | #ifdef __SC__ |
7581 | #pragma segment Main | |
7582 | #endif | |
4e35701f | 7583 | |
b250498f | 7584 | STATIC char* |
3ae08724 | 7585 | S_swallow_bom(pTHX_ U8 *s) |
01ec43d0 | 7586 | { |
b250498f GS |
7587 | STRLEN slen; |
7588 | slen = SvCUR(PL_linestr); | |
7589 | switch (*s) { | |
4e553d73 NIS |
7590 | case 0xFF: |
7591 | if (s[1] == 0xFE) { | |
01ec43d0 | 7592 | /* UTF-16 little-endian */ |
3ae08724 | 7593 | if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */ |
01ec43d0 GS |
7594 | Perl_croak(aTHX_ "Unsupported script encoding"); |
7595 | #ifndef PERL_NO_UTF16_FILTER | |
dea0fc0b | 7596 | DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-LE script encoding\n")); |
3ae08724 | 7597 | s += 2; |
dea0fc0b JH |
7598 | if (PL_bufend > (char*)s) { |
7599 | U8 *news; | |
7600 | I32 newlen; | |
7601 | ||
7602 | filter_add(utf16rev_textfilter, NULL); | |
7603 | New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8); | |
f72f5f89 JH |
7604 | PL_bufend = (char*)utf16_to_utf8_reversed(s, news, |
7605 | PL_bufend - (char*)s - 1, | |
dea0fc0b JH |
7606 | &newlen); |
7607 | Copy(news, s, newlen, U8); | |
7608 | SvCUR_set(PL_linestr, newlen); | |
7609 | PL_bufend = SvPVX(PL_linestr) + newlen; | |
7610 | news[newlen++] = '\0'; | |
7611 | Safefree(news); | |
7612 | } | |
b250498f | 7613 | #else |
01ec43d0 | 7614 | Perl_croak(aTHX_ "Unsupported script encoding"); |
b250498f | 7615 | #endif |
01ec43d0 GS |
7616 | } |
7617 | break; | |
78ae23f5 | 7618 | case 0xFE: |
3ae08724 | 7619 | if (s[1] == 0xFF) { /* UTF-16 big-endian */ |
01ec43d0 | 7620 | #ifndef PERL_NO_UTF16_FILTER |
dea0fc0b JH |
7621 | DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding\n")); |
7622 | s += 2; | |
7623 | if (PL_bufend > (char *)s) { | |
7624 | U8 *news; | |
7625 | I32 newlen; | |
7626 | ||
7627 | filter_add(utf16_textfilter, NULL); | |
7628 | New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8); | |
7629 | PL_bufend = (char*)utf16_to_utf8(s, news, | |
7630 | PL_bufend - (char*)s, | |
7631 | &newlen); | |
7632 | Copy(news, s, newlen, U8); | |
7633 | SvCUR_set(PL_linestr, newlen); | |
7634 | PL_bufend = SvPVX(PL_linestr) + newlen; | |
7635 | news[newlen++] = '\0'; | |
7636 | Safefree(news); | |
7637 | } | |
b250498f | 7638 | #else |
01ec43d0 | 7639 | Perl_croak(aTHX_ "Unsupported script encoding"); |
b250498f | 7640 | #endif |
01ec43d0 GS |
7641 | } |
7642 | break; | |
3ae08724 GS |
7643 | case 0xEF: |
7644 | if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) { | |
dea0fc0b | 7645 | DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-8 script encoding\n")); |
01ec43d0 GS |
7646 | s += 3; /* UTF-8 */ |
7647 | } | |
7648 | break; | |
7649 | case 0: | |
7650 | if (slen > 3 && s[1] == 0 && /* UTF-32 big-endian */ | |
3ae08724 | 7651 | s[2] == 0xFE && s[3] == 0xFF) |
01ec43d0 GS |
7652 | { |
7653 | Perl_croak(aTHX_ "Unsupported script encoding"); | |
7654 | } | |
7655 | } | |
b8f84bb2 | 7656 | return (char*)s; |
b250498f | 7657 | } |
4755096e GS |
7658 | |
7659 | #ifdef PERL_OBJECT | |
7660 | #include "XSUB.h" | |
7661 | #endif | |
7662 | ||
7663 | /* | |
7664 | * restore_rsfp | |
7665 | * Restore a source filter. | |
7666 | */ | |
7667 | ||
7668 | static void | |
7669 | restore_rsfp(pTHXo_ void *f) | |
7670 | { | |
7671 | PerlIO *fp = (PerlIO*)f; | |
7672 | ||
7673 | if (PL_rsfp == PerlIO_stdin()) | |
7674 | PerlIO_clearerr(PL_rsfp); | |
7675 | else if (PL_rsfp && (PL_rsfp != fp)) | |
7676 | PerlIO_close(PL_rsfp); | |
7677 | PL_rsfp = fp; | |
7678 | } | |
6e3aabd6 GS |
7679 | |
7680 | #ifndef PERL_NO_UTF16_FILTER | |
7681 | static I32 | |
7682 | utf16_textfilter(pTHXo_ int idx, SV *sv, int maxlen) | |
7683 | { | |
7684 | I32 count = FILTER_READ(idx+1, sv, maxlen); | |
7685 | if (count) { | |
7686 | U8* tmps; | |
7687 | U8* tend; | |
dea0fc0b | 7688 | I32 newlen; |
6e3aabd6 | 7689 | New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8); |
f72f5f89 JH |
7690 | if (!*SvPV_nolen(sv)) |
7691 | /* Game over, but don't feed an odd-length string to utf16_to_utf8 */ | |
7692 | return count; | |
4e553d73 | 7693 | |
dea0fc0b | 7694 | tend = utf16_to_utf8((U8*)SvPVX(sv), tmps, SvCUR(sv), &newlen); |
6e3aabd6 GS |
7695 | sv_usepvn(sv, (char*)tmps, tend - tmps); |
7696 | } | |
7697 | return count; | |
7698 | } | |
7699 | ||
7700 | static I32 | |
7701 | utf16rev_textfilter(pTHXo_ int idx, SV *sv, int maxlen) | |
7702 | { | |
7703 | I32 count = FILTER_READ(idx+1, sv, maxlen); | |
7704 | if (count) { | |
7705 | U8* tmps; | |
7706 | U8* tend; | |
dea0fc0b | 7707 | I32 newlen; |
f72f5f89 JH |
7708 | if (!*SvPV_nolen(sv)) |
7709 | /* Game over, but don't feed an odd-length string to utf16_to_utf8 */ | |
7710 | return count; | |
7711 | ||
6e3aabd6 | 7712 | New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8); |
dea0fc0b | 7713 | tend = utf16_to_utf8_reversed((U8*)SvPVX(sv), tmps, SvCUR(sv), &newlen); |
6e3aabd6 GS |
7714 | sv_usepvn(sv, (char*)tmps, tend - tmps); |
7715 | } | |
7716 | return count; | |
7717 | } | |
7718 | #endif |