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