Commit | Line | Data |
---|---|---|
a0d0e21e | 1 | /* toke.c |
a687059c | 2 | * |
4bb101f2 | 3 | * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
b94e2f88 | 4 | * 2000, 2001, 2002, 2003, 2004, 2005, 2006, by Larry Wall and others |
a687059c | 5 | * |
d48672a2 LW |
6 | * You may distribute under the terms of either the GNU General Public |
7 | * License or the Artistic License, as specified in the README file. | |
378cc40b | 8 | * |
a0d0e21e LW |
9 | */ |
10 | ||
11 | /* | |
12 | * "It all comes from here, the stench and the peril." --Frodo | |
378cc40b LW |
13 | */ |
14 | ||
9cbb5ea2 GS |
15 | /* |
16 | * This file is the lexer for Perl. It's closely linked to the | |
4e553d73 | 17 | * parser, perly.y. |
ffb4593c NT |
18 | * |
19 | * The main routine is yylex(), which returns the next token. | |
20 | */ | |
21 | ||
378cc40b | 22 | #include "EXTERN.h" |
864dbfa3 | 23 | #define PERL_IN_TOKE_C |
378cc40b | 24 | #include "perl.h" |
378cc40b | 25 | |
12fbd33b DM |
26 | #define yychar (*PL_yycharp) |
27 | #define yylval (*PL_yylvalp) | |
d3b6f988 | 28 | |
0bd48802 | 29 | static const char ident_too_long[] = "Identifier too long"; |
c445ea15 | 30 | static const char commaless_variable_list[] = "comma-less variable list"; |
8903cb82 | 31 | |
acfe0abc | 32 | static void restore_rsfp(pTHX_ void *f); |
6e3aabd6 | 33 | #ifndef PERL_NO_UTF16_FILTER |
acfe0abc GS |
34 | static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen); |
35 | static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen); | |
6e3aabd6 | 36 | #endif |
51371543 | 37 | |
9059aa12 LW |
38 | #define XFAKEBRACK 128 |
39 | #define XENUMMASK 127 | |
40 | ||
39e02b42 JH |
41 | #ifdef USE_UTF8_SCRIPTS |
42 | # define UTF (!IN_BYTES) | |
2b9d42f0 | 43 | #else |
746b446a | 44 | # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8)) |
2b9d42f0 | 45 | #endif |
a0ed51b3 | 46 | |
61f0cdd9 | 47 | /* In variables named $^X, these are the legal values for X. |
2b92dfce GS |
48 | * 1999-02-27 mjd-perl-patch@plover.com */ |
49 | #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x))) | |
50 | ||
bf4acbe4 GS |
51 | /* On MacOS, respect nonbreaking spaces */ |
52 | #ifdef MACOS_TRADITIONAL | |
53 | #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t') | |
54 | #else | |
55 | #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t') | |
56 | #endif | |
57 | ||
ffb4593c NT |
58 | /* LEX_* are values for PL_lex_state, the state of the lexer. |
59 | * They are arranged oddly so that the guard on the switch statement | |
79072805 LW |
60 | * can get by with a single comparison (if the compiler is smart enough). |
61 | */ | |
62 | ||
fb73857a | 63 | /* #define LEX_NOTPARSING 11 is done in perl.h. */ |
64 | ||
b6007c36 DM |
65 | #define LEX_NORMAL 10 /* normal code (ie not within "...") */ |
66 | #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */ | |
67 | #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */ | |
68 | #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */ | |
69 | #define LEX_INTERPSTART 6 /* expecting the start of a $var */ | |
70 | ||
71 | /* at end of code, eg "$x" followed by: */ | |
72 | #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */ | |
73 | #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */ | |
74 | ||
75 | #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of | |
76 | string or after \E, $foo, etc */ | |
77 | #define LEX_INTERPCONST 2 /* NOT USED */ | |
78 | #define LEX_FORMLINE 1 /* expecting a format line */ | |
79 | #define LEX_KNOWNEXT 0 /* next token known; just return it */ | |
80 | ||
79072805 | 81 | |
bbf60fe6 | 82 | #ifdef DEBUGGING |
27da23d5 | 83 | static const char* const lex_state_names[] = { |
bbf60fe6 DM |
84 | "KNOWNEXT", |
85 | "FORMLINE", | |
86 | "INTERPCONST", | |
87 | "INTERPCONCAT", | |
88 | "INTERPENDMAYBE", | |
89 | "INTERPEND", | |
90 | "INTERPSTART", | |
91 | "INTERPPUSH", | |
92 | "INTERPCASEMOD", | |
93 | "INTERPNORMAL", | |
94 | "NORMAL" | |
95 | }; | |
96 | #endif | |
97 | ||
79072805 LW |
98 | #ifdef ff_next |
99 | #undef ff_next | |
d48672a2 LW |
100 | #endif |
101 | ||
79072805 | 102 | #include "keywords.h" |
fe14fcc3 | 103 | |
ffb4593c NT |
104 | /* CLINE is a macro that ensures PL_copline has a sane value */ |
105 | ||
ae986130 LW |
106 | #ifdef CLINE |
107 | #undef CLINE | |
108 | #endif | |
57843af0 | 109 | #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline)) |
3280af22 | 110 | |
ffb4593c NT |
111 | /* |
112 | * Convenience functions to return different tokens and prime the | |
9cbb5ea2 | 113 | * lexer for the next token. They all take an argument. |
ffb4593c NT |
114 | * |
115 | * TOKEN : generic token (used for '(', DOLSHARP, etc) | |
116 | * OPERATOR : generic operator | |
117 | * AOPERATOR : assignment operator | |
118 | * PREBLOCK : beginning the block after an if, while, foreach, ... | |
119 | * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref) | |
120 | * PREREF : *EXPR where EXPR is not a simple identifier | |
121 | * TERM : expression term | |
122 | * LOOPX : loop exiting command (goto, last, dump, etc) | |
123 | * FTST : file test operator | |
124 | * FUN0 : zero-argument function | |
2d2e263d | 125 | * FUN1 : not used, except for not, which isn't a UNIOP |
ffb4593c NT |
126 | * BOop : bitwise or or xor |
127 | * BAop : bitwise and | |
128 | * SHop : shift operator | |
129 | * PWop : power operator | |
9cbb5ea2 | 130 | * PMop : pattern-matching operator |
ffb4593c NT |
131 | * Aop : addition-level operator |
132 | * Mop : multiplication-level operator | |
133 | * Eop : equality-testing operator | |
e5edeb50 | 134 | * Rop : relational operator <= != gt |
ffb4593c NT |
135 | * |
136 | * Also see LOP and lop() below. | |
137 | */ | |
138 | ||
998054bd | 139 | #ifdef DEBUGGING /* Serve -DT. */ |
f5bd084c | 140 | # define REPORT(retval) tokereport((I32)retval) |
998054bd | 141 | #else |
bbf60fe6 | 142 | # define REPORT(retval) (retval) |
998054bd SC |
143 | #endif |
144 | ||
bbf60fe6 DM |
145 | #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval)) |
146 | #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval)) | |
147 | #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval))) | |
148 | #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval)) | |
149 | #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval)) | |
150 | #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval)) | |
151 | #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval)) | |
152 | #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX)) | |
153 | #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP)) | |
154 | #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0)) | |
155 | #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1)) | |
156 | #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP))) | |
157 | #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP))) | |
158 | #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP))) | |
159 | #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP))) | |
160 | #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP)) | |
161 | #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP))) | |
162 | #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP))) | |
163 | #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP)) | |
164 | #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP)) | |
2f3197b3 | 165 | |
a687059c LW |
166 | /* This bit of chicanery makes a unary function followed by |
167 | * a parenthesis into a function with one argument, highest precedence. | |
6f33ba73 RGS |
168 | * The UNIDOR macro is for unary functions that can be followed by the // |
169 | * operator (such as C<shift // 0>). | |
a687059c | 170 | */ |
376fcdbf AL |
171 | #define UNI2(f,x) { \ |
172 | yylval.ival = f; \ | |
173 | PL_expect = x; \ | |
174 | PL_bufptr = s; \ | |
175 | PL_last_uni = PL_oldbufptr; \ | |
176 | PL_last_lop_op = f; \ | |
177 | if (*s == '(') \ | |
178 | return REPORT( (int)FUNC1 ); \ | |
179 | s = skipspace(s); \ | |
180 | return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \ | |
181 | } | |
6f33ba73 RGS |
182 | #define UNI(f) UNI2(f,XTERM) |
183 | #define UNIDOR(f) UNI2(f,XTERMORDORDOR) | |
a687059c | 184 | |
376fcdbf AL |
185 | #define UNIBRACK(f) { \ |
186 | yylval.ival = f; \ | |
187 | PL_bufptr = s; \ | |
188 | PL_last_uni = PL_oldbufptr; \ | |
189 | if (*s == '(') \ | |
190 | return REPORT( (int)FUNC1 ); \ | |
191 | s = skipspace(s); \ | |
192 | return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \ | |
193 | } | |
79072805 | 194 | |
9f68db38 | 195 | /* grandfather return to old style */ |
3280af22 | 196 | #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP) |
79072805 | 197 | |
8fa7f367 JH |
198 | #ifdef DEBUGGING |
199 | ||
bbf60fe6 DM |
200 | /* how to interpret the yylval associated with the token */ |
201 | enum token_type { | |
202 | TOKENTYPE_NONE, | |
203 | TOKENTYPE_IVAL, | |
204 | TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */ | |
205 | TOKENTYPE_PVAL, | |
206 | TOKENTYPE_OPVAL, | |
207 | TOKENTYPE_GVVAL | |
208 | }; | |
209 | ||
6d4a66ac NC |
210 | static struct debug_tokens { |
211 | const int token; | |
212 | enum token_type type; | |
213 | const char *name; | |
214 | } const debug_tokens[] = | |
9041c2e3 | 215 | { |
bbf60fe6 DM |
216 | { ADDOP, TOKENTYPE_OPNUM, "ADDOP" }, |
217 | { ANDAND, TOKENTYPE_NONE, "ANDAND" }, | |
218 | { ANDOP, TOKENTYPE_NONE, "ANDOP" }, | |
219 | { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" }, | |
220 | { ARROW, TOKENTYPE_NONE, "ARROW" }, | |
221 | { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" }, | |
222 | { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" }, | |
223 | { BITOROP, TOKENTYPE_OPNUM, "BITOROP" }, | |
224 | { COLONATTR, TOKENTYPE_NONE, "COLONATTR" }, | |
225 | { CONTINUE, TOKENTYPE_NONE, "CONTINUE" }, | |
0d863452 | 226 | { DEFAULT, TOKENTYPE_NONE, "DEFAULT" }, |
bbf60fe6 DM |
227 | { DO, TOKENTYPE_NONE, "DO" }, |
228 | { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" }, | |
229 | { DORDOR, TOKENTYPE_NONE, "DORDOR" }, | |
230 | { DOROP, TOKENTYPE_OPNUM, "DOROP" }, | |
231 | { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" }, | |
232 | { ELSE, TOKENTYPE_NONE, "ELSE" }, | |
233 | { ELSIF, TOKENTYPE_IVAL, "ELSIF" }, | |
234 | { EQOP, TOKENTYPE_OPNUM, "EQOP" }, | |
235 | { FOR, TOKENTYPE_IVAL, "FOR" }, | |
236 | { FORMAT, TOKENTYPE_NONE, "FORMAT" }, | |
237 | { FUNC, TOKENTYPE_OPNUM, "FUNC" }, | |
238 | { FUNC0, TOKENTYPE_OPNUM, "FUNC0" }, | |
239 | { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" }, | |
240 | { FUNC1, TOKENTYPE_OPNUM, "FUNC1" }, | |
241 | { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" }, | |
0d863452 | 242 | { GIVEN, TOKENTYPE_IVAL, "GIVEN" }, |
bbf60fe6 DM |
243 | { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" }, |
244 | { IF, TOKENTYPE_IVAL, "IF" }, | |
245 | { LABEL, TOKENTYPE_PVAL, "LABEL" }, | |
246 | { LOCAL, TOKENTYPE_IVAL, "LOCAL" }, | |
247 | { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" }, | |
248 | { LSTOP, TOKENTYPE_OPNUM, "LSTOP" }, | |
249 | { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" }, | |
250 | { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" }, | |
251 | { METHOD, TOKENTYPE_OPVAL, "METHOD" }, | |
252 | { MULOP, TOKENTYPE_OPNUM, "MULOP" }, | |
253 | { MY, TOKENTYPE_IVAL, "MY" }, | |
254 | { MYSUB, TOKENTYPE_NONE, "MYSUB" }, | |
255 | { NOAMP, TOKENTYPE_NONE, "NOAMP" }, | |
256 | { NOTOP, TOKENTYPE_NONE, "NOTOP" }, | |
257 | { OROP, TOKENTYPE_IVAL, "OROP" }, | |
258 | { OROR, TOKENTYPE_NONE, "OROR" }, | |
259 | { PACKAGE, TOKENTYPE_NONE, "PACKAGE" }, | |
260 | { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" }, | |
261 | { POSTDEC, TOKENTYPE_NONE, "POSTDEC" }, | |
262 | { POSTINC, TOKENTYPE_NONE, "POSTINC" }, | |
263 | { POWOP, TOKENTYPE_OPNUM, "POWOP" }, | |
264 | { PREDEC, TOKENTYPE_NONE, "PREDEC" }, | |
265 | { PREINC, TOKENTYPE_NONE, "PREINC" }, | |
266 | { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" }, | |
267 | { REFGEN, TOKENTYPE_NONE, "REFGEN" }, | |
268 | { RELOP, TOKENTYPE_OPNUM, "RELOP" }, | |
269 | { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" }, | |
270 | { SUB, TOKENTYPE_NONE, "SUB" }, | |
271 | { THING, TOKENTYPE_OPVAL, "THING" }, | |
272 | { UMINUS, TOKENTYPE_NONE, "UMINUS" }, | |
273 | { UNIOP, TOKENTYPE_OPNUM, "UNIOP" }, | |
274 | { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" }, | |
275 | { UNLESS, TOKENTYPE_IVAL, "UNLESS" }, | |
276 | { UNTIL, TOKENTYPE_IVAL, "UNTIL" }, | |
277 | { USE, TOKENTYPE_IVAL, "USE" }, | |
0d863452 | 278 | { WHEN, TOKENTYPE_IVAL, "WHEN" }, |
bbf60fe6 DM |
279 | { WHILE, TOKENTYPE_IVAL, "WHILE" }, |
280 | { WORD, TOKENTYPE_OPVAL, "WORD" }, | |
281 | { 0, TOKENTYPE_NONE, 0 } | |
282 | }; | |
283 | ||
284 | /* dump the returned token in rv, plus any optional arg in yylval */ | |
998054bd | 285 | |
bbf60fe6 | 286 | STATIC int |
f5bd084c | 287 | S_tokereport(pTHX_ I32 rv) |
bbf60fe6 | 288 | { |
97aff369 | 289 | dVAR; |
bbf60fe6 | 290 | if (DEBUG_T_TEST) { |
bd61b366 | 291 | const char *name = NULL; |
bbf60fe6 | 292 | enum token_type type = TOKENTYPE_NONE; |
f54cb97a | 293 | const struct debug_tokens *p; |
396482e1 | 294 | SV* const report = newSVpvs("<== "); |
bbf60fe6 | 295 | |
f54cb97a | 296 | for (p = debug_tokens; p->token; p++) { |
bbf60fe6 DM |
297 | if (p->token == (int)rv) { |
298 | name = p->name; | |
299 | type = p->type; | |
300 | break; | |
301 | } | |
302 | } | |
303 | if (name) | |
54667de8 | 304 | Perl_sv_catpv(aTHX_ report, name); |
bbf60fe6 DM |
305 | else if ((char)rv > ' ' && (char)rv < '~') |
306 | Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv); | |
307 | else if (!rv) | |
396482e1 | 308 | sv_catpvs(report, "EOF"); |
bbf60fe6 DM |
309 | else |
310 | Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv); | |
311 | switch (type) { | |
312 | case TOKENTYPE_NONE: | |
313 | case TOKENTYPE_GVVAL: /* doesn't appear to be used */ | |
314 | break; | |
315 | case TOKENTYPE_IVAL: | |
e4584336 | 316 | Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival); |
bbf60fe6 DM |
317 | break; |
318 | case TOKENTYPE_OPNUM: | |
319 | Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)", | |
320 | PL_op_name[yylval.ival]); | |
321 | break; | |
322 | case TOKENTYPE_PVAL: | |
323 | Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval); | |
324 | break; | |
325 | case TOKENTYPE_OPVAL: | |
b6007c36 | 326 | if (yylval.opval) { |
401441c0 | 327 | Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)", |
bbf60fe6 | 328 | PL_op_name[yylval.opval->op_type]); |
b6007c36 DM |
329 | if (yylval.opval->op_type == OP_CONST) { |
330 | Perl_sv_catpvf(aTHX_ report, " %s", | |
331 | SvPEEK(cSVOPx_sv(yylval.opval))); | |
332 | } | |
333 | ||
334 | } | |
401441c0 | 335 | else |
396482e1 | 336 | sv_catpvs(report, "(opval=null)"); |
bbf60fe6 DM |
337 | break; |
338 | } | |
b6007c36 | 339 | PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report)); |
bbf60fe6 DM |
340 | }; |
341 | return (int)rv; | |
998054bd SC |
342 | } |
343 | ||
b6007c36 DM |
344 | |
345 | /* print the buffer with suitable escapes */ | |
346 | ||
347 | STATIC void | |
348 | S_printbuf(pTHX_ const char* fmt, const char* s) | |
349 | { | |
396482e1 | 350 | SV* const tmp = newSVpvs(""); |
b6007c36 DM |
351 | PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60)); |
352 | SvREFCNT_dec(tmp); | |
353 | } | |
354 | ||
8fa7f367 JH |
355 | #endif |
356 | ||
ffb4593c NT |
357 | /* |
358 | * S_ao | |
359 | * | |
c963b151 BD |
360 | * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR |
361 | * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN | |
ffb4593c NT |
362 | */ |
363 | ||
76e3520e | 364 | STATIC int |
cea2e8a9 | 365 | S_ao(pTHX_ int toketype) |
a0d0e21e | 366 | { |
97aff369 | 367 | dVAR; |
3280af22 NIS |
368 | if (*PL_bufptr == '=') { |
369 | PL_bufptr++; | |
a0d0e21e LW |
370 | if (toketype == ANDAND) |
371 | yylval.ival = OP_ANDASSIGN; | |
372 | else if (toketype == OROR) | |
373 | yylval.ival = OP_ORASSIGN; | |
c963b151 BD |
374 | else if (toketype == DORDOR) |
375 | yylval.ival = OP_DORASSIGN; | |
a0d0e21e LW |
376 | toketype = ASSIGNOP; |
377 | } | |
378 | return toketype; | |
379 | } | |
380 | ||
ffb4593c NT |
381 | /* |
382 | * S_no_op | |
383 | * When Perl expects an operator and finds something else, no_op | |
384 | * prints the warning. It always prints "<something> found where | |
385 | * operator expected. It prints "Missing semicolon on previous line?" | |
386 | * if the surprise occurs at the start of the line. "do you need to | |
387 | * predeclare ..." is printed out for code like "sub bar; foo bar $x" | |
388 | * where the compiler doesn't know if foo is a method call or a function. | |
389 | * It prints "Missing operator before end of line" if there's nothing | |
390 | * after the missing operator, or "... before <...>" if there is something | |
391 | * after the missing operator. | |
392 | */ | |
393 | ||
76e3520e | 394 | STATIC void |
bfed75c6 | 395 | S_no_op(pTHX_ const char *what, char *s) |
463ee0b2 | 396 | { |
97aff369 | 397 | dVAR; |
9d4ba2ae AL |
398 | char * const oldbp = PL_bufptr; |
399 | const bool is_first = (PL_oldbufptr == PL_linestart); | |
68dc0745 | 400 | |
1189a94a GS |
401 | if (!s) |
402 | s = oldbp; | |
07c798fb | 403 | else |
1189a94a | 404 | PL_bufptr = s; |
cea2e8a9 | 405 | yywarn(Perl_form(aTHX_ "%s found where operator expected", what)); |
56da5a46 RGS |
406 | if (ckWARN_d(WARN_SYNTAX)) { |
407 | if (is_first) | |
408 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
409 | "\t(Missing semicolon on previous line?)\n"); | |
410 | else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) { | |
f54cb97a | 411 | const char *t; |
56da5a46 RGS |
412 | for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ; |
413 | if (t < PL_bufptr && isSPACE(*t)) | |
414 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
415 | "\t(Do you need to predeclare %.*s?)\n", | |
551405c4 | 416 | (int)(t - PL_oldoldbufptr), PL_oldoldbufptr); |
56da5a46 RGS |
417 | } |
418 | else { | |
419 | assert(s >= oldbp); | |
420 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
551405c4 | 421 | "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp); |
56da5a46 | 422 | } |
07c798fb | 423 | } |
3280af22 | 424 | PL_bufptr = oldbp; |
8990e307 LW |
425 | } |
426 | ||
ffb4593c NT |
427 | /* |
428 | * S_missingterm | |
429 | * Complain about missing quote/regexp/heredoc terminator. | |
430 | * If it's called with (char *)NULL then it cauterizes the line buffer. | |
431 | * If we're in a delimited string and the delimiter is a control | |
432 | * character, it's reformatted into a two-char sequence like ^C. | |
433 | * This is fatal. | |
434 | */ | |
435 | ||
76e3520e | 436 | STATIC void |
cea2e8a9 | 437 | S_missingterm(pTHX_ char *s) |
8990e307 | 438 | { |
97aff369 | 439 | dVAR; |
8990e307 LW |
440 | char tmpbuf[3]; |
441 | char q; | |
442 | if (s) { | |
9d4ba2ae | 443 | char * const nl = strrchr(s,'\n'); |
d2719217 | 444 | if (nl) |
8990e307 LW |
445 | *nl = '\0'; |
446 | } | |
9d116dd7 JH |
447 | else if ( |
448 | #ifdef EBCDIC | |
449 | iscntrl(PL_multi_close) | |
450 | #else | |
451 | PL_multi_close < 32 || PL_multi_close == 127 | |
452 | #endif | |
453 | ) { | |
8990e307 | 454 | *tmpbuf = '^'; |
585ec06d | 455 | tmpbuf[1] = (char)toCTRL(PL_multi_close); |
8990e307 LW |
456 | tmpbuf[2] = '\0'; |
457 | s = tmpbuf; | |
458 | } | |
459 | else { | |
eb160463 | 460 | *tmpbuf = (char)PL_multi_close; |
8990e307 LW |
461 | tmpbuf[1] = '\0'; |
462 | s = tmpbuf; | |
463 | } | |
464 | q = strchr(s,'"') ? '\'' : '"'; | |
cea2e8a9 | 465 | Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q); |
463ee0b2 | 466 | } |
79072805 | 467 | |
ef89dcc3 | 468 | #define FEATURE_IS_ENABLED(name) \ |
0d863452 | 469 | ((0 != (PL_hints & HINT_LOCALIZE_HH)) \ |
89529cee | 470 | && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name))) |
0d863452 RH |
471 | /* |
472 | * S_feature_is_enabled | |
473 | * Check whether the named feature is enabled. | |
474 | */ | |
475 | STATIC bool | |
476 | S_feature_is_enabled(pTHX_ char *name, STRLEN namelen) | |
477 | { | |
97aff369 | 478 | dVAR; |
0d863452 | 479 | HV * const hinthv = GvHV(PL_hintgv); |
7b9ef140 RH |
480 | char he_name[32] = "feature_"; |
481 | (void) strncpy(&he_name[8], name, 24); | |
482 | ||
483 | return (hinthv && hv_exists(hinthv, he_name, 8 + namelen)); | |
0d863452 RH |
484 | } |
485 | ||
ffb4593c NT |
486 | /* |
487 | * Perl_deprecate | |
ffb4593c NT |
488 | */ |
489 | ||
79072805 | 490 | void |
bfed75c6 | 491 | Perl_deprecate(pTHX_ const char *s) |
a0d0e21e | 492 | { |
599cee73 | 493 | if (ckWARN(WARN_DEPRECATED)) |
9014280d | 494 | Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s); |
a0d0e21e LW |
495 | } |
496 | ||
12bcd1a6 | 497 | void |
bfed75c6 | 498 | Perl_deprecate_old(pTHX_ const char *s) |
12bcd1a6 PM |
499 | { |
500 | /* This function should NOT be called for any new deprecated warnings */ | |
501 | /* Use Perl_deprecate instead */ | |
502 | /* */ | |
503 | /* It is here to maintain backward compatibility with the pre-5.8 */ | |
504 | /* warnings category hierarchy. The "deprecated" category used to */ | |
505 | /* live under the "syntax" category. It is now a top-level category */ | |
506 | /* in its own right. */ | |
507 | ||
508 | if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX)) | |
bfed75c6 | 509 | Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX), |
12bcd1a6 PM |
510 | "Use of %s is deprecated", s); |
511 | } | |
512 | ||
ffb4593c | 513 | /* |
9cbb5ea2 GS |
514 | * experimental text filters for win32 carriage-returns, utf16-to-utf8 and |
515 | * utf16-to-utf8-reversed. | |
ffb4593c NT |
516 | */ |
517 | ||
c39cd008 GS |
518 | #ifdef PERL_CR_FILTER |
519 | static void | |
520 | strip_return(SV *sv) | |
521 | { | |
95a20fc0 | 522 | register const char *s = SvPVX_const(sv); |
9d4ba2ae | 523 | register const char * const e = s + SvCUR(sv); |
c39cd008 GS |
524 | /* outer loop optimized to do nothing if there are no CR-LFs */ |
525 | while (s < e) { | |
526 | if (*s++ == '\r' && *s == '\n') { | |
527 | /* hit a CR-LF, need to copy the rest */ | |
528 | register char *d = s - 1; | |
529 | *d++ = *s++; | |
530 | while (s < e) { | |
531 | if (*s == '\r' && s[1] == '\n') | |
532 | s++; | |
533 | *d++ = *s++; | |
534 | } | |
535 | SvCUR(sv) -= s - d; | |
536 | return; | |
537 | } | |
538 | } | |
539 | } | |
a868473f | 540 | |
76e3520e | 541 | STATIC I32 |
c39cd008 | 542 | S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
a868473f | 543 | { |
f54cb97a | 544 | const I32 count = FILTER_READ(idx+1, sv, maxlen); |
c39cd008 GS |
545 | if (count > 0 && !maxlen) |
546 | strip_return(sv); | |
547 | return count; | |
a868473f NIS |
548 | } |
549 | #endif | |
550 | ||
ffb4593c NT |
551 | /* |
552 | * Perl_lex_start | |
9cbb5ea2 GS |
553 | * Initialize variables. Uses the Perl save_stack to save its state (for |
554 | * recursive calls to the parser). | |
ffb4593c NT |
555 | */ |
556 | ||
a0d0e21e | 557 | void |
864dbfa3 | 558 | Perl_lex_start(pTHX_ SV *line) |
79072805 | 559 | { |
97aff369 | 560 | dVAR; |
cfd0369c | 561 | const char *s; |
8990e307 LW |
562 | STRLEN len; |
563 | ||
3280af22 NIS |
564 | SAVEI32(PL_lex_dojoin); |
565 | SAVEI32(PL_lex_brackets); | |
3280af22 NIS |
566 | SAVEI32(PL_lex_casemods); |
567 | SAVEI32(PL_lex_starts); | |
568 | SAVEI32(PL_lex_state); | |
7766f137 | 569 | SAVEVPTR(PL_lex_inpat); |
3280af22 | 570 | SAVEI32(PL_lex_inwhat); |
18b09519 GS |
571 | if (PL_lex_state == LEX_KNOWNEXT) { |
572 | I32 toke = PL_nexttoke; | |
573 | while (--toke >= 0) { | |
574 | SAVEI32(PL_nexttype[toke]); | |
575 | SAVEVPTR(PL_nextval[toke]); | |
576 | } | |
577 | SAVEI32(PL_nexttoke); | |
18b09519 | 578 | } |
57843af0 | 579 | SAVECOPLINE(PL_curcop); |
3280af22 NIS |
580 | SAVEPPTR(PL_bufptr); |
581 | SAVEPPTR(PL_bufend); | |
582 | SAVEPPTR(PL_oldbufptr); | |
583 | SAVEPPTR(PL_oldoldbufptr); | |
207e3d1a JH |
584 | SAVEPPTR(PL_last_lop); |
585 | SAVEPPTR(PL_last_uni); | |
3280af22 NIS |
586 | SAVEPPTR(PL_linestart); |
587 | SAVESPTR(PL_linestr); | |
8edd5f42 RGS |
588 | SAVEGENERICPV(PL_lex_brackstack); |
589 | SAVEGENERICPV(PL_lex_casestack); | |
c76ac1ee | 590 | SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp); |
3280af22 NIS |
591 | SAVESPTR(PL_lex_stuff); |
592 | SAVEI32(PL_lex_defer); | |
09bef843 | 593 | SAVEI32(PL_sublex_info.sub_inwhat); |
3280af22 | 594 | SAVESPTR(PL_lex_repl); |
bebdddfc GS |
595 | SAVEINT(PL_expect); |
596 | SAVEINT(PL_lex_expect); | |
3280af22 NIS |
597 | |
598 | PL_lex_state = LEX_NORMAL; | |
599 | PL_lex_defer = 0; | |
600 | PL_expect = XSTATE; | |
601 | PL_lex_brackets = 0; | |
a02a5408 JC |
602 | Newx(PL_lex_brackstack, 120, char); |
603 | Newx(PL_lex_casestack, 12, char); | |
3280af22 NIS |
604 | PL_lex_casemods = 0; |
605 | *PL_lex_casestack = '\0'; | |
606 | PL_lex_dojoin = 0; | |
607 | PL_lex_starts = 0; | |
a0714e2c SS |
608 | PL_lex_stuff = NULL; |
609 | PL_lex_repl = NULL; | |
3280af22 | 610 | PL_lex_inpat = 0; |
76be56bc | 611 | PL_nexttoke = 0; |
3280af22 | 612 | PL_lex_inwhat = 0; |
09bef843 | 613 | PL_sublex_info.sub_inwhat = 0; |
3280af22 NIS |
614 | PL_linestr = line; |
615 | if (SvREADONLY(PL_linestr)) | |
616 | PL_linestr = sv_2mortal(newSVsv(PL_linestr)); | |
cfd0369c | 617 | s = SvPV_const(PL_linestr, len); |
6f27f9a7 | 618 | if (!len || s[len-1] != ';') { |
3280af22 NIS |
619 | if (!(SvFLAGS(PL_linestr) & SVs_TEMP)) |
620 | PL_linestr = sv_2mortal(newSVsv(PL_linestr)); | |
396482e1 | 621 | sv_catpvs(PL_linestr, "\n;"); |
8990e307 | 622 | } |
3280af22 NIS |
623 | SvTEMP_off(PL_linestr); |
624 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr); | |
625 | PL_bufend = PL_bufptr + SvCUR(PL_linestr); | |
bd61b366 | 626 | PL_last_lop = PL_last_uni = NULL; |
3280af22 | 627 | PL_rsfp = 0; |
79072805 | 628 | } |
a687059c | 629 | |
ffb4593c NT |
630 | /* |
631 | * Perl_lex_end | |
9cbb5ea2 GS |
632 | * Finalizer for lexing operations. Must be called when the parser is |
633 | * done with the lexer. | |
ffb4593c NT |
634 | */ |
635 | ||
463ee0b2 | 636 | void |
864dbfa3 | 637 | Perl_lex_end(pTHX) |
463ee0b2 | 638 | { |
97aff369 | 639 | dVAR; |
3280af22 | 640 | PL_doextract = FALSE; |
463ee0b2 LW |
641 | } |
642 | ||
ffb4593c NT |
643 | /* |
644 | * S_incline | |
645 | * This subroutine has nothing to do with tilting, whether at windmills | |
646 | * or pinball tables. Its name is short for "increment line". It | |
57843af0 | 647 | * increments the current line number in CopLINE(PL_curcop) and checks |
ffb4593c | 648 | * to see whether the line starts with a comment of the form |
9cbb5ea2 GS |
649 | * # line 500 "foo.pm" |
650 | * If so, it sets the current line number and file to the values in the comment. | |
ffb4593c NT |
651 | */ |
652 | ||
76e3520e | 653 | STATIC void |
cea2e8a9 | 654 | S_incline(pTHX_ char *s) |
463ee0b2 | 655 | { |
97aff369 | 656 | dVAR; |
463ee0b2 LW |
657 | char *t; |
658 | char *n; | |
73659bf1 | 659 | char *e; |
463ee0b2 | 660 | char ch; |
463ee0b2 | 661 | |
57843af0 | 662 | CopLINE_inc(PL_curcop); |
463ee0b2 LW |
663 | if (*s++ != '#') |
664 | return; | |
bf4acbe4 | 665 | while (SPACE_OR_TAB(*s)) s++; |
73659bf1 GS |
666 | if (strnEQ(s, "line", 4)) |
667 | s += 4; | |
668 | else | |
669 | return; | |
084592ab | 670 | if (SPACE_OR_TAB(*s)) |
73659bf1 | 671 | s++; |
4e553d73 | 672 | else |
73659bf1 | 673 | return; |
bf4acbe4 | 674 | while (SPACE_OR_TAB(*s)) s++; |
463ee0b2 LW |
675 | if (!isDIGIT(*s)) |
676 | return; | |
677 | n = s; | |
678 | while (isDIGIT(*s)) | |
679 | s++; | |
bf4acbe4 | 680 | while (SPACE_OR_TAB(*s)) |
463ee0b2 | 681 | s++; |
73659bf1 | 682 | if (*s == '"' && (t = strchr(s+1, '"'))) { |
463ee0b2 | 683 | s++; |
73659bf1 GS |
684 | e = t + 1; |
685 | } | |
463ee0b2 | 686 | else { |
463ee0b2 | 687 | for (t = s; !isSPACE(*t); t++) ; |
73659bf1 | 688 | e = t; |
463ee0b2 | 689 | } |
bf4acbe4 | 690 | while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f') |
73659bf1 GS |
691 | e++; |
692 | if (*e != '\n' && *e != '\0') | |
693 | return; /* false alarm */ | |
694 | ||
463ee0b2 LW |
695 | ch = *t; |
696 | *t = '\0'; | |
f4dd75d9 | 697 | if (t - s > 0) { |
8a5ee598 | 698 | #ifndef USE_ITHREADS |
c4420975 | 699 | const char * const cf = CopFILE(PL_curcop); |
42d9b98d NC |
700 | STRLEN tmplen = cf ? strlen(cf) : 0; |
701 | if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) { | |
e66cf94c RGS |
702 | /* must copy *{"::_<(eval N)[oldfilename:L]"} |
703 | * to *{"::_<newfilename"} */ | |
704 | char smallbuf[256], smallbuf2[256]; | |
705 | char *tmpbuf, *tmpbuf2; | |
8a5ee598 | 706 | GV **gvp, *gv2; |
e66cf94c RGS |
707 | STRLEN tmplen2 = strlen(s); |
708 | if (tmplen + 3 < sizeof smallbuf) | |
709 | tmpbuf = smallbuf; | |
710 | else | |
711 | Newx(tmpbuf, tmplen + 3, char); | |
712 | if (tmplen2 + 3 < sizeof smallbuf2) | |
713 | tmpbuf2 = smallbuf2; | |
714 | else | |
715 | Newx(tmpbuf2, tmplen2 + 3, char); | |
716 | tmpbuf[0] = tmpbuf2[0] = '_'; | |
717 | tmpbuf[1] = tmpbuf2[1] = '<'; | |
718 | memcpy(tmpbuf + 2, cf, ++tmplen); | |
719 | memcpy(tmpbuf2 + 2, s, ++tmplen2); | |
720 | ++tmplen; ++tmplen2; | |
8a5ee598 RGS |
721 | gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE); |
722 | if (gvp) { | |
723 | gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE); | |
724 | if (!isGV(gv2)) | |
725 | gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE); | |
726 | /* adjust ${"::_<newfilename"} to store the new file name */ | |
727 | GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2); | |
728 | GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp)); | |
729 | GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp)); | |
730 | } | |
e66cf94c RGS |
731 | if (tmpbuf != smallbuf) Safefree(tmpbuf); |
732 | if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2); | |
733 | } | |
8a5ee598 | 734 | #endif |
05ec9bb3 | 735 | CopFILE_free(PL_curcop); |
57843af0 | 736 | CopFILE_set(PL_curcop, s); |
f4dd75d9 | 737 | } |
463ee0b2 | 738 | *t = ch; |
57843af0 | 739 | CopLINE_set(PL_curcop, atoi(n)-1); |
463ee0b2 LW |
740 | } |
741 | ||
ffb4593c NT |
742 | /* |
743 | * S_skipspace | |
744 | * Called to gobble the appropriate amount and type of whitespace. | |
745 | * Skips comments as well. | |
746 | */ | |
747 | ||
76e3520e | 748 | STATIC char * |
cea2e8a9 | 749 | S_skipspace(pTHX_ register char *s) |
a687059c | 750 | { |
97aff369 | 751 | dVAR; |
3280af22 | 752 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
bf4acbe4 | 753 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
463ee0b2 LW |
754 | s++; |
755 | return s; | |
756 | } | |
757 | for (;;) { | |
fd049845 | 758 | STRLEN prevlen; |
09bef843 | 759 | SSize_t oldprevlen, oldoldprevlen; |
9c5ffd7c | 760 | SSize_t oldloplen = 0, oldunilen = 0; |
60e6418e GS |
761 | while (s < PL_bufend && isSPACE(*s)) { |
762 | if (*s++ == '\n' && PL_in_eval && !PL_rsfp) | |
763 | incline(s); | |
764 | } | |
ffb4593c NT |
765 | |
766 | /* comment */ | |
3280af22 NIS |
767 | if (s < PL_bufend && *s == '#') { |
768 | while (s < PL_bufend && *s != '\n') | |
463ee0b2 | 769 | s++; |
60e6418e | 770 | if (s < PL_bufend) { |
463ee0b2 | 771 | s++; |
60e6418e GS |
772 | if (PL_in_eval && !PL_rsfp) { |
773 | incline(s); | |
774 | continue; | |
775 | } | |
776 | } | |
463ee0b2 | 777 | } |
ffb4593c NT |
778 | |
779 | /* only continue to recharge the buffer if we're at the end | |
780 | * of the buffer, we're not reading from a source filter, and | |
781 | * we're in normal lexing mode | |
782 | */ | |
09bef843 SB |
783 | if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat || |
784 | PL_lex_state == LEX_FORMLINE) | |
463ee0b2 | 785 | return s; |
ffb4593c NT |
786 | |
787 | /* try to recharge the buffer */ | |
9cbb5ea2 | 788 | if ((s = filter_gets(PL_linestr, PL_rsfp, |
bd61b366 | 789 | (prevlen = SvCUR(PL_linestr)))) == NULL) |
9cbb5ea2 GS |
790 | { |
791 | /* end of file. Add on the -p or -n magic */ | |
01a19ab0 NC |
792 | if (PL_minus_p) { |
793 | sv_setpv(PL_linestr, | |
794 | ";}continue{print or die qq(-p destination: $!\\n);}"); | |
3280af22 | 795 | PL_minus_n = PL_minus_p = 0; |
a0d0e21e | 796 | } |
01a19ab0 NC |
797 | else if (PL_minus_n) { |
798 | sv_setpvn(PL_linestr, ";}", 2); | |
799 | PL_minus_n = 0; | |
800 | } | |
a0d0e21e | 801 | else |
4147a61b | 802 | sv_setpvn(PL_linestr,";", 1); |
ffb4593c NT |
803 | |
804 | /* reset variables for next time we lex */ | |
9cbb5ea2 GS |
805 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart |
806 | = SvPVX(PL_linestr); | |
3280af22 | 807 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
bd61b366 | 808 | PL_last_lop = PL_last_uni = NULL; |
ffb4593c NT |
809 | |
810 | /* Close the filehandle. Could be from -P preprocessor, | |
811 | * STDIN, or a regular file. If we were reading code from | |
812 | * STDIN (because the commandline held no -e or filename) | |
813 | * then we don't close it, we reset it so the code can | |
814 | * read from STDIN too. | |
815 | */ | |
816 | ||
3280af22 NIS |
817 | if (PL_preprocess && !PL_in_eval) |
818 | (void)PerlProc_pclose(PL_rsfp); | |
819 | else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) | |
820 | PerlIO_clearerr(PL_rsfp); | |
8990e307 | 821 | else |
3280af22 | 822 | (void)PerlIO_close(PL_rsfp); |
4608196e | 823 | PL_rsfp = NULL; |
463ee0b2 LW |
824 | return s; |
825 | } | |
ffb4593c NT |
826 | |
827 | /* not at end of file, so we only read another line */ | |
09bef843 SB |
828 | /* make corresponding updates to old pointers, for yyerror() */ |
829 | oldprevlen = PL_oldbufptr - PL_bufend; | |
830 | oldoldprevlen = PL_oldoldbufptr - PL_bufend; | |
831 | if (PL_last_uni) | |
832 | oldunilen = PL_last_uni - PL_bufend; | |
833 | if (PL_last_lop) | |
834 | oldloplen = PL_last_lop - PL_bufend; | |
3280af22 NIS |
835 | PL_linestart = PL_bufptr = s + prevlen; |
836 | PL_bufend = s + SvCUR(PL_linestr); | |
837 | s = PL_bufptr; | |
09bef843 SB |
838 | PL_oldbufptr = s + oldprevlen; |
839 | PL_oldoldbufptr = s + oldoldprevlen; | |
840 | if (PL_last_uni) | |
841 | PL_last_uni = s + oldunilen; | |
842 | if (PL_last_lop) | |
843 | PL_last_lop = s + oldloplen; | |
a0d0e21e | 844 | incline(s); |
ffb4593c NT |
845 | |
846 | /* debugger active and we're not compiling the debugger code, | |
847 | * so store the line into the debugger's array of lines | |
848 | */ | |
3280af22 | 849 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
561b68a9 | 850 | SV * const sv = newSV(0); |
8990e307 LW |
851 | |
852 | sv_upgrade(sv, SVt_PVMG); | |
3280af22 | 853 | sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr); |
0ac0412a | 854 | (void)SvIOK_on(sv); |
45977657 | 855 | SvIV_set(sv, 0); |
36c7798d | 856 | av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
8990e307 | 857 | } |
463ee0b2 | 858 | } |
a687059c | 859 | } |
378cc40b | 860 | |
ffb4593c NT |
861 | /* |
862 | * S_check_uni | |
863 | * Check the unary operators to ensure there's no ambiguity in how they're | |
864 | * used. An ambiguous piece of code would be: | |
865 | * rand + 5 | |
866 | * This doesn't mean rand() + 5. Because rand() is a unary operator, | |
867 | * the +5 is its argument. | |
868 | */ | |
869 | ||
76e3520e | 870 | STATIC void |
cea2e8a9 | 871 | S_check_uni(pTHX) |
ba106d47 | 872 | { |
97aff369 | 873 | dVAR; |
2f3197b3 | 874 | char *s; |
a0d0e21e | 875 | char *t; |
2f3197b3 | 876 | |
3280af22 | 877 | if (PL_oldoldbufptr != PL_last_uni) |
2f3197b3 | 878 | return; |
3280af22 NIS |
879 | while (isSPACE(*PL_last_uni)) |
880 | PL_last_uni++; | |
7e2040f0 | 881 | for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ; |
3280af22 | 882 | if ((t = strchr(s, '(')) && t < PL_bufptr) |
a0d0e21e | 883 | return; |
6136c704 AL |
884 | |
885 | /* XXX Things like this are just so nasty. We shouldn't be modifying | |
886 | source code, even if we realquick set it back. */ | |
0453d815 | 887 | if (ckWARN_d(WARN_AMBIGUOUS)){ |
9d4ba2ae | 888 | const char ch = *s; |
0453d815 | 889 | *s = '\0'; |
9014280d | 890 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
2d5ccbba | 891 | "Warning: Use of \"%s\" without parentheses is ambiguous", |
0453d815 PM |
892 | PL_last_uni); |
893 | *s = ch; | |
894 | } | |
2f3197b3 LW |
895 | } |
896 | ||
ffb4593c NT |
897 | /* |
898 | * LOP : macro to build a list operator. Its behaviour has been replaced | |
899 | * with a subroutine, S_lop() for which LOP is just another name. | |
900 | */ | |
901 | ||
a0d0e21e LW |
902 | #define LOP(f,x) return lop(f,x,s) |
903 | ||
ffb4593c NT |
904 | /* |
905 | * S_lop | |
906 | * Build a list operator (or something that might be one). The rules: | |
907 | * - if we have a next token, then it's a list operator [why?] | |
908 | * - if the next thing is an opening paren, then it's a function | |
909 | * - else it's a list operator | |
910 | */ | |
911 | ||
76e3520e | 912 | STATIC I32 |
a0be28da | 913 | S_lop(pTHX_ I32 f, int x, char *s) |
ffed7fef | 914 | { |
97aff369 | 915 | dVAR; |
79072805 | 916 | yylval.ival = f; |
35c8bce7 | 917 | CLINE; |
3280af22 NIS |
918 | PL_expect = x; |
919 | PL_bufptr = s; | |
920 | PL_last_lop = PL_oldbufptr; | |
eb160463 | 921 | PL_last_lop_op = (OPCODE)f; |
3280af22 | 922 | if (PL_nexttoke) |
bbf60fe6 | 923 | return REPORT(LSTOP); |
79072805 | 924 | if (*s == '(') |
bbf60fe6 | 925 | return REPORT(FUNC); |
79072805 LW |
926 | s = skipspace(s); |
927 | if (*s == '(') | |
bbf60fe6 | 928 | return REPORT(FUNC); |
79072805 | 929 | else |
bbf60fe6 | 930 | return REPORT(LSTOP); |
79072805 LW |
931 | } |
932 | ||
ffb4593c NT |
933 | /* |
934 | * S_force_next | |
9cbb5ea2 | 935 | * When the lexer realizes it knows the next token (for instance, |
ffb4593c | 936 | * it is reordering tokens for the parser) then it can call S_force_next |
9cbb5ea2 GS |
937 | * to know what token to return the next time the lexer is called. Caller |
938 | * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer | |
939 | * handles the token correctly. | |
ffb4593c NT |
940 | */ |
941 | ||
4e553d73 | 942 | STATIC void |
cea2e8a9 | 943 | S_force_next(pTHX_ I32 type) |
79072805 | 944 | { |
97aff369 | 945 | dVAR; |
3280af22 NIS |
946 | PL_nexttype[PL_nexttoke] = type; |
947 | PL_nexttoke++; | |
948 | if (PL_lex_state != LEX_KNOWNEXT) { | |
949 | PL_lex_defer = PL_lex_state; | |
950 | PL_lex_expect = PL_expect; | |
951 | PL_lex_state = LEX_KNOWNEXT; | |
79072805 LW |
952 | } |
953 | } | |
954 | ||
d0a148a6 NC |
955 | STATIC SV * |
956 | S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len) | |
957 | { | |
97aff369 | 958 | dVAR; |
9d4ba2ae | 959 | SV * const sv = newSVpvn(start,len); |
bfed75c6 | 960 | if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len)) |
d0a148a6 NC |
961 | SvUTF8_on(sv); |
962 | return sv; | |
963 | } | |
964 | ||
ffb4593c NT |
965 | /* |
966 | * S_force_word | |
967 | * When the lexer knows the next thing is a word (for instance, it has | |
968 | * just seen -> and it knows that the next char is a word char, then | |
969 | * it calls S_force_word to stick the next word into the PL_next lookahead. | |
970 | * | |
971 | * Arguments: | |
b1b65b59 | 972 | * char *start : buffer position (must be within PL_linestr) |
ffb4593c NT |
973 | * int token : PL_next will be this type of bare word (e.g., METHOD,WORD) |
974 | * int check_keyword : if true, Perl checks to make sure the word isn't | |
975 | * a keyword (do this if the word is a label, e.g. goto FOO) | |
976 | * int allow_pack : if true, : characters will also be allowed (require, | |
977 | * use, etc. do this) | |
9cbb5ea2 | 978 | * int allow_initial_tick : used by the "sub" lexer only. |
ffb4593c NT |
979 | */ |
980 | ||
76e3520e | 981 | STATIC char * |
cea2e8a9 | 982 | S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick) |
79072805 | 983 | { |
97aff369 | 984 | dVAR; |
463ee0b2 LW |
985 | register char *s; |
986 | STRLEN len; | |
4e553d73 | 987 | |
463ee0b2 LW |
988 | start = skipspace(start); |
989 | s = start; | |
7e2040f0 | 990 | if (isIDFIRST_lazy_if(s,UTF) || |
a0d0e21e | 991 | (allow_pack && *s == ':') || |
15f0808c | 992 | (allow_initial_tick && *s == '\'') ) |
a0d0e21e | 993 | { |
3280af22 NIS |
994 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len); |
995 | if (check_keyword && keyword(PL_tokenbuf, len)) | |
463ee0b2 LW |
996 | return start; |
997 | if (token == METHOD) { | |
998 | s = skipspace(s); | |
999 | if (*s == '(') | |
3280af22 | 1000 | PL_expect = XTERM; |
463ee0b2 | 1001 | else { |
3280af22 | 1002 | PL_expect = XOPERATOR; |
463ee0b2 | 1003 | } |
79072805 | 1004 | } |
d0a148a6 NC |
1005 | PL_nextval[PL_nexttoke].opval |
1006 | = (OP*)newSVOP(OP_CONST,0, | |
1007 | S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len)); | |
3280af22 | 1008 | PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE; |
79072805 LW |
1009 | force_next(token); |
1010 | } | |
1011 | return s; | |
1012 | } | |
1013 | ||
ffb4593c NT |
1014 | /* |
1015 | * S_force_ident | |
9cbb5ea2 | 1016 | * Called when the lexer wants $foo *foo &foo etc, but the program |
ffb4593c NT |
1017 | * text only contains the "foo" portion. The first argument is a pointer |
1018 | * to the "foo", and the second argument is the type symbol to prefix. | |
1019 | * Forces the next token to be a "WORD". | |
9cbb5ea2 | 1020 | * Creates the symbol if it didn't already exist (via gv_fetchpv()). |
ffb4593c NT |
1021 | */ |
1022 | ||
76e3520e | 1023 | STATIC void |
bfed75c6 | 1024 | S_force_ident(pTHX_ register const char *s, int kind) |
79072805 | 1025 | { |
97aff369 | 1026 | dVAR; |
79072805 | 1027 | if (s && *s) { |
90e5519e NC |
1028 | const STRLEN len = strlen(s); |
1029 | OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len)); | |
3280af22 | 1030 | PL_nextval[PL_nexttoke].opval = o; |
79072805 | 1031 | force_next(WORD); |
748a9306 | 1032 | if (kind) { |
11343788 | 1033 | o->op_private = OPpCONST_ENTERED; |
55497cff | 1034 | /* XXX see note in pp_entereval() for why we forgo typo |
1035 | warnings if the symbol must be introduced in an eval. | |
1036 | GSAR 96-10-12 */ | |
90e5519e NC |
1037 | gv_fetchpvn_flags(s, len, |
1038 | PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) | |
1039 | : GV_ADD, | |
1040 | kind == '$' ? SVt_PV : | |
1041 | kind == '@' ? SVt_PVAV : | |
1042 | kind == '%' ? SVt_PVHV : | |
a0d0e21e | 1043 | SVt_PVGV |
90e5519e | 1044 | ); |
748a9306 | 1045 | } |
79072805 LW |
1046 | } |
1047 | } | |
1048 | ||
1571675a GS |
1049 | NV |
1050 | Perl_str_to_version(pTHX_ SV *sv) | |
1051 | { | |
1052 | NV retval = 0.0; | |
1053 | NV nshift = 1.0; | |
1054 | STRLEN len; | |
cfd0369c | 1055 | const char *start = SvPV_const(sv,len); |
9d4ba2ae | 1056 | const char * const end = start + len; |
504618e9 | 1057 | const bool utf = SvUTF8(sv) ? TRUE : FALSE; |
1571675a | 1058 | while (start < end) { |
ba210ebe | 1059 | STRLEN skip; |
1571675a GS |
1060 | UV n; |
1061 | if (utf) | |
9041c2e3 | 1062 | n = utf8n_to_uvchr((U8*)start, len, &skip, 0); |
1571675a GS |
1063 | else { |
1064 | n = *(U8*)start; | |
1065 | skip = 1; | |
1066 | } | |
1067 | retval += ((NV)n)/nshift; | |
1068 | start += skip; | |
1069 | nshift *= 1000; | |
1070 | } | |
1071 | return retval; | |
1072 | } | |
1073 | ||
4e553d73 | 1074 | /* |
ffb4593c NT |
1075 | * S_force_version |
1076 | * Forces the next token to be a version number. | |
e759cc13 RGS |
1077 | * If the next token appears to be an invalid version number, (e.g. "v2b"), |
1078 | * and if "guessing" is TRUE, then no new token is created (and the caller | |
1079 | * must use an alternative parsing method). | |
ffb4593c NT |
1080 | */ |
1081 | ||
76e3520e | 1082 | STATIC char * |
e759cc13 | 1083 | S_force_version(pTHX_ char *s, int guessing) |
89bfa8cd | 1084 | { |
97aff369 | 1085 | dVAR; |
5f66b61c | 1086 | OP *version = NULL; |
44dcb63b | 1087 | char *d; |
89bfa8cd | 1088 | |
1089 | s = skipspace(s); | |
1090 | ||
44dcb63b | 1091 | d = s; |
dd629d5b | 1092 | if (*d == 'v') |
44dcb63b | 1093 | d++; |
44dcb63b | 1094 | if (isDIGIT(*d)) { |
e759cc13 RGS |
1095 | while (isDIGIT(*d) || *d == '_' || *d == '.') |
1096 | d++; | |
9f3d182e | 1097 | if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) { |
dd629d5b | 1098 | SV *ver; |
b73d6f50 | 1099 | s = scan_num(s, &yylval); |
89bfa8cd | 1100 | version = yylval.opval; |
dd629d5b GS |
1101 | ver = cSVOPx(version)->op_sv; |
1102 | if (SvPOK(ver) && !SvNIOK(ver)) { | |
862a34c6 | 1103 | SvUPGRADE(ver, SVt_PVNV); |
9d6ce603 | 1104 | SvNV_set(ver, str_to_version(ver)); |
1571675a | 1105 | SvNOK_on(ver); /* hint that it is a version */ |
44dcb63b | 1106 | } |
89bfa8cd | 1107 | } |
e759cc13 RGS |
1108 | else if (guessing) |
1109 | return s; | |
89bfa8cd | 1110 | } |
1111 | ||
1112 | /* NOTE: The parser sees the package name and the VERSION swapped */ | |
3280af22 | 1113 | PL_nextval[PL_nexttoke].opval = version; |
4e553d73 | 1114 | force_next(WORD); |
89bfa8cd | 1115 | |
e759cc13 | 1116 | return s; |
89bfa8cd | 1117 | } |
1118 | ||
ffb4593c NT |
1119 | /* |
1120 | * S_tokeq | |
1121 | * Tokenize a quoted string passed in as an SV. It finds the next | |
1122 | * chunk, up to end of string or a backslash. It may make a new | |
1123 | * SV containing that chunk (if HINT_NEW_STRING is on). It also | |
1124 | * turns \\ into \. | |
1125 | */ | |
1126 | ||
76e3520e | 1127 | STATIC SV * |
cea2e8a9 | 1128 | S_tokeq(pTHX_ SV *sv) |
79072805 | 1129 | { |
97aff369 | 1130 | dVAR; |
79072805 LW |
1131 | register char *s; |
1132 | register char *send; | |
1133 | register char *d; | |
b3ac6de7 IZ |
1134 | STRLEN len = 0; |
1135 | SV *pv = sv; | |
79072805 LW |
1136 | |
1137 | if (!SvLEN(sv)) | |
b3ac6de7 | 1138 | goto finish; |
79072805 | 1139 | |
a0d0e21e | 1140 | s = SvPV_force(sv, len); |
21a311ee | 1141 | if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1) |
b3ac6de7 | 1142 | goto finish; |
463ee0b2 | 1143 | send = s + len; |
79072805 LW |
1144 | while (s < send && *s != '\\') |
1145 | s++; | |
1146 | if (s == send) | |
b3ac6de7 | 1147 | goto finish; |
79072805 | 1148 | d = s; |
be4731d2 | 1149 | if ( PL_hints & HINT_NEW_STRING ) { |
95a20fc0 | 1150 | pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len)); |
be4731d2 NIS |
1151 | if (SvUTF8(sv)) |
1152 | SvUTF8_on(pv); | |
1153 | } | |
79072805 LW |
1154 | while (s < send) { |
1155 | if (*s == '\\') { | |
a0d0e21e | 1156 | if (s + 1 < send && (s[1] == '\\')) |
79072805 LW |
1157 | s++; /* all that, just for this */ |
1158 | } | |
1159 | *d++ = *s++; | |
1160 | } | |
1161 | *d = '\0'; | |
95a20fc0 | 1162 | SvCUR_set(sv, d - SvPVX_const(sv)); |
b3ac6de7 | 1163 | finish: |
3280af22 | 1164 | if ( PL_hints & HINT_NEW_STRING ) |
b3ac6de7 | 1165 | return new_constant(NULL, 0, "q", sv, pv, "q"); |
79072805 LW |
1166 | return sv; |
1167 | } | |
1168 | ||
ffb4593c NT |
1169 | /* |
1170 | * Now come three functions related to double-quote context, | |
1171 | * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when | |
1172 | * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They | |
1173 | * interact with PL_lex_state, and create fake ( ... ) argument lists | |
1174 | * to handle functions and concatenation. | |
1175 | * They assume that whoever calls them will be setting up a fake | |
1176 | * join call, because each subthing puts a ',' after it. This lets | |
1177 | * "lower \luPpEr" | |
1178 | * become | |
1179 | * join($, , 'lower ', lcfirst( 'uPpEr', ) ,) | |
1180 | * | |
1181 | * (I'm not sure whether the spurious commas at the end of lcfirst's | |
1182 | * arguments and join's arguments are created or not). | |
1183 | */ | |
1184 | ||
1185 | /* | |
1186 | * S_sublex_start | |
1187 | * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST). | |
1188 | * | |
1189 | * Pattern matching will set PL_lex_op to the pattern-matching op to | |
1190 | * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise). | |
1191 | * | |
1192 | * OP_CONST and OP_READLINE are easy--just make the new op and return. | |
1193 | * | |
1194 | * Everything else becomes a FUNC. | |
1195 | * | |
1196 | * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we | |
1197 | * had an OP_CONST or OP_READLINE). This just sets us up for a | |
1198 | * call to S_sublex_push(). | |
1199 | */ | |
1200 | ||
76e3520e | 1201 | STATIC I32 |
cea2e8a9 | 1202 | S_sublex_start(pTHX) |
79072805 | 1203 | { |
97aff369 | 1204 | dVAR; |
0d46e09a | 1205 | register const I32 op_type = yylval.ival; |
79072805 LW |
1206 | |
1207 | if (op_type == OP_NULL) { | |
3280af22 | 1208 | yylval.opval = PL_lex_op; |
5f66b61c | 1209 | PL_lex_op = NULL; |
79072805 LW |
1210 | return THING; |
1211 | } | |
1212 | if (op_type == OP_CONST || op_type == OP_READLINE) { | |
3280af22 | 1213 | SV *sv = tokeq(PL_lex_stuff); |
b3ac6de7 IZ |
1214 | |
1215 | if (SvTYPE(sv) == SVt_PVIV) { | |
1216 | /* Overloaded constants, nothing fancy: Convert to SVt_PV: */ | |
1217 | STRLEN len; | |
96a5add6 | 1218 | const char * const p = SvPV_const(sv, len); |
f54cb97a | 1219 | SV * const nsv = newSVpvn(p, len); |
01ec43d0 GS |
1220 | if (SvUTF8(sv)) |
1221 | SvUTF8_on(nsv); | |
b3ac6de7 IZ |
1222 | SvREFCNT_dec(sv); |
1223 | sv = nsv; | |
4e553d73 | 1224 | } |
b3ac6de7 | 1225 | yylval.opval = (OP*)newSVOP(op_type, 0, sv); |
a0714e2c | 1226 | PL_lex_stuff = NULL; |
6f33ba73 RGS |
1227 | /* Allow <FH> // "foo" */ |
1228 | if (op_type == OP_READLINE) | |
1229 | PL_expect = XTERMORDORDOR; | |
79072805 LW |
1230 | return THING; |
1231 | } | |
1232 | ||
3280af22 NIS |
1233 | PL_sublex_info.super_state = PL_lex_state; |
1234 | PL_sublex_info.sub_inwhat = op_type; | |
1235 | PL_sublex_info.sub_op = PL_lex_op; | |
1236 | PL_lex_state = LEX_INTERPPUSH; | |
55497cff | 1237 | |
3280af22 NIS |
1238 | PL_expect = XTERM; |
1239 | if (PL_lex_op) { | |
1240 | yylval.opval = PL_lex_op; | |
5f66b61c | 1241 | PL_lex_op = NULL; |
55497cff | 1242 | return PMFUNC; |
1243 | } | |
1244 | else | |
1245 | return FUNC; | |
1246 | } | |
1247 | ||
ffb4593c NT |
1248 | /* |
1249 | * S_sublex_push | |
1250 | * Create a new scope to save the lexing state. The scope will be | |
1251 | * ended in S_sublex_done. Returns a '(', starting the function arguments | |
1252 | * to the uc, lc, etc. found before. | |
1253 | * Sets PL_lex_state to LEX_INTERPCONCAT. | |
1254 | */ | |
1255 | ||
76e3520e | 1256 | STATIC I32 |
cea2e8a9 | 1257 | S_sublex_push(pTHX) |
55497cff | 1258 | { |
27da23d5 | 1259 | dVAR; |
f46d017c | 1260 | ENTER; |
55497cff | 1261 | |
3280af22 NIS |
1262 | PL_lex_state = PL_sublex_info.super_state; |
1263 | SAVEI32(PL_lex_dojoin); | |
1264 | SAVEI32(PL_lex_brackets); | |
3280af22 NIS |
1265 | SAVEI32(PL_lex_casemods); |
1266 | SAVEI32(PL_lex_starts); | |
1267 | SAVEI32(PL_lex_state); | |
7766f137 | 1268 | SAVEVPTR(PL_lex_inpat); |
3280af22 | 1269 | SAVEI32(PL_lex_inwhat); |
57843af0 | 1270 | SAVECOPLINE(PL_curcop); |
3280af22 | 1271 | SAVEPPTR(PL_bufptr); |
8452ff4b | 1272 | SAVEPPTR(PL_bufend); |
3280af22 NIS |
1273 | SAVEPPTR(PL_oldbufptr); |
1274 | SAVEPPTR(PL_oldoldbufptr); | |
207e3d1a JH |
1275 | SAVEPPTR(PL_last_lop); |
1276 | SAVEPPTR(PL_last_uni); | |
3280af22 NIS |
1277 | SAVEPPTR(PL_linestart); |
1278 | SAVESPTR(PL_linestr); | |
8edd5f42 RGS |
1279 | SAVEGENERICPV(PL_lex_brackstack); |
1280 | SAVEGENERICPV(PL_lex_casestack); | |
3280af22 NIS |
1281 | |
1282 | PL_linestr = PL_lex_stuff; | |
a0714e2c | 1283 | PL_lex_stuff = NULL; |
3280af22 | 1284 | |
9cbb5ea2 GS |
1285 | PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart |
1286 | = SvPVX(PL_linestr); | |
3280af22 | 1287 | PL_bufend += SvCUR(PL_linestr); |
bd61b366 | 1288 | PL_last_lop = PL_last_uni = NULL; |
3280af22 NIS |
1289 | SAVEFREESV(PL_linestr); |
1290 | ||
1291 | PL_lex_dojoin = FALSE; | |
1292 | PL_lex_brackets = 0; | |
a02a5408 JC |
1293 | Newx(PL_lex_brackstack, 120, char); |
1294 | Newx(PL_lex_casestack, 12, char); | |
3280af22 NIS |
1295 | PL_lex_casemods = 0; |
1296 | *PL_lex_casestack = '\0'; | |
1297 | PL_lex_starts = 0; | |
1298 | PL_lex_state = LEX_INTERPCONCAT; | |
eb160463 | 1299 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
3280af22 NIS |
1300 | |
1301 | PL_lex_inwhat = PL_sublex_info.sub_inwhat; | |
1302 | if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST) | |
1303 | PL_lex_inpat = PL_sublex_info.sub_op; | |
79072805 | 1304 | else |
5f66b61c | 1305 | PL_lex_inpat = NULL; |
79072805 | 1306 | |
55497cff | 1307 | return '('; |
79072805 LW |
1308 | } |
1309 | ||
ffb4593c NT |
1310 | /* |
1311 | * S_sublex_done | |
1312 | * Restores lexer state after a S_sublex_push. | |
1313 | */ | |
1314 | ||
76e3520e | 1315 | STATIC I32 |
cea2e8a9 | 1316 | S_sublex_done(pTHX) |
79072805 | 1317 | { |
27da23d5 | 1318 | dVAR; |
3280af22 | 1319 | if (!PL_lex_starts++) { |
396482e1 | 1320 | SV * const sv = newSVpvs(""); |
9aa983d2 JH |
1321 | if (SvUTF8(PL_linestr)) |
1322 | SvUTF8_on(sv); | |
3280af22 | 1323 | PL_expect = XOPERATOR; |
9aa983d2 | 1324 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
79072805 LW |
1325 | return THING; |
1326 | } | |
1327 | ||
3280af22 NIS |
1328 | if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */ |
1329 | PL_lex_state = LEX_INTERPCASEMOD; | |
cea2e8a9 | 1330 | return yylex(); |
79072805 LW |
1331 | } |
1332 | ||
ffb4593c | 1333 | /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */ |
3280af22 NIS |
1334 | if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) { |
1335 | PL_linestr = PL_lex_repl; | |
1336 | PL_lex_inpat = 0; | |
1337 | PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr); | |
1338 | PL_bufend += SvCUR(PL_linestr); | |
bd61b366 | 1339 | PL_last_lop = PL_last_uni = NULL; |
3280af22 NIS |
1340 | SAVEFREESV(PL_linestr); |
1341 | PL_lex_dojoin = FALSE; | |
1342 | PL_lex_brackets = 0; | |
3280af22 NIS |
1343 | PL_lex_casemods = 0; |
1344 | *PL_lex_casestack = '\0'; | |
1345 | PL_lex_starts = 0; | |
25da4f38 | 1346 | if (SvEVALED(PL_lex_repl)) { |
3280af22 NIS |
1347 | PL_lex_state = LEX_INTERPNORMAL; |
1348 | PL_lex_starts++; | |
e9fa98b2 HS |
1349 | /* we don't clear PL_lex_repl here, so that we can check later |
1350 | whether this is an evalled subst; that means we rely on the | |
1351 | logic to ensure sublex_done() is called again only via the | |
1352 | branch (in yylex()) that clears PL_lex_repl, else we'll loop */ | |
79072805 | 1353 | } |
e9fa98b2 | 1354 | else { |
3280af22 | 1355 | PL_lex_state = LEX_INTERPCONCAT; |
a0714e2c | 1356 | PL_lex_repl = NULL; |
e9fa98b2 | 1357 | } |
79072805 | 1358 | return ','; |
ffed7fef LW |
1359 | } |
1360 | else { | |
f46d017c | 1361 | LEAVE; |
3280af22 NIS |
1362 | PL_bufend = SvPVX(PL_linestr); |
1363 | PL_bufend += SvCUR(PL_linestr); | |
1364 | PL_expect = XOPERATOR; | |
09bef843 | 1365 | PL_sublex_info.sub_inwhat = 0; |
79072805 | 1366 | return ')'; |
ffed7fef LW |
1367 | } |
1368 | } | |
1369 | ||
02aa26ce NT |
1370 | /* |
1371 | scan_const | |
1372 | ||
1373 | Extracts a pattern, double-quoted string, or transliteration. This | |
1374 | is terrifying code. | |
1375 | ||
3280af22 NIS |
1376 | It looks at lex_inwhat and PL_lex_inpat to find out whether it's |
1377 | processing a pattern (PL_lex_inpat is true), a transliteration | |
02aa26ce NT |
1378 | (lex_inwhat & OP_TRANS is true), or a double-quoted string. |
1379 | ||
9b599b2a GS |
1380 | Returns a pointer to the character scanned up to. Iff this is |
1381 | advanced from the start pointer supplied (ie if anything was | |
1382 | successfully parsed), will leave an OP for the substring scanned | |
1383 | in yylval. Caller must intuit reason for not parsing further | |
1384 | by looking at the next characters herself. | |
1385 | ||
02aa26ce NT |
1386 | In patterns: |
1387 | backslashes: | |
1388 | double-quoted style: \r and \n | |
1389 | regexp special ones: \D \s | |
1390 | constants: \x3 | |
1391 | backrefs: \1 (deprecated in substitution replacements) | |
1392 | case and quoting: \U \Q \E | |
1393 | stops on @ and $, but not for $ as tail anchor | |
1394 | ||
1395 | In transliterations: | |
1396 | characters are VERY literal, except for - not at the start or end | |
1397 | of the string, which indicates a range. scan_const expands the | |
1398 | range to the full set of intermediate characters. | |
1399 | ||
1400 | In double-quoted strings: | |
1401 | backslashes: | |
1402 | double-quoted style: \r and \n | |
1403 | constants: \x3 | |
1404 | backrefs: \1 (deprecated) | |
1405 | case and quoting: \U \Q \E | |
1406 | stops on @ and $ | |
1407 | ||
1408 | scan_const does *not* construct ops to handle interpolated strings. | |
1409 | It stops processing as soon as it finds an embedded $ or @ variable | |
1410 | and leaves it to the caller to work out what's going on. | |
1411 | ||
da6eedaa | 1412 | @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo. |
02aa26ce NT |
1413 | |
1414 | $ in pattern could be $foo or could be tail anchor. Assumption: | |
1415 | it's a tail anchor if $ is the last thing in the string, or if it's | |
1416 | followed by one of ")| \n\t" | |
1417 | ||
1418 | \1 (backreferences) are turned into $1 | |
1419 | ||
1420 | The structure of the code is | |
1421 | while (there's a character to process) { | |
1422 | handle transliteration ranges | |
1423 | skip regexp comments | |
1424 | skip # initiated comments in //x patterns | |
1425 | check for embedded @foo | |
1426 | check for embedded scalars | |
1427 | if (backslash) { | |
1428 | leave intact backslashes from leave (below) | |
1429 | deprecate \1 in strings and sub replacements | |
1430 | handle string-changing backslashes \l \U \Q \E, etc. | |
1431 | switch (what was escaped) { | |
1432 | handle - in a transliteration (becomes a literal -) | |
1433 | handle \132 octal characters | |
1434 | handle 0x15 hex characters | |
1435 | handle \cV (control V) | |
1436 | handle printf backslashes (\f, \r, \n, etc) | |
1437 | } (end switch) | |
1438 | } (end if backslash) | |
1439 | } (end while character to read) | |
4e553d73 | 1440 | |
02aa26ce NT |
1441 | */ |
1442 | ||
76e3520e | 1443 | STATIC char * |
cea2e8a9 | 1444 | S_scan_const(pTHX_ char *start) |
79072805 | 1445 | { |
97aff369 | 1446 | dVAR; |
3280af22 | 1447 | register char *send = PL_bufend; /* end of the constant */ |
561b68a9 | 1448 | SV *sv = newSV(send - start); /* sv for the constant */ |
02aa26ce NT |
1449 | register char *s = start; /* start of the constant */ |
1450 | register char *d = SvPVX(sv); /* destination for copies */ | |
1451 | bool dorange = FALSE; /* are we in a translit range? */ | |
c2e66d9e | 1452 | bool didrange = FALSE; /* did we just finish a range? */ |
2b9d42f0 NIS |
1453 | I32 has_utf8 = FALSE; /* Output constant is UTF8 */ |
1454 | I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */ | |
012bcf8d | 1455 | UV uv; |
4c3a8340 TS |
1456 | #ifdef EBCDIC |
1457 | UV literal_endpoint = 0; | |
1458 | #endif | |
012bcf8d | 1459 | |
dff6d3cd | 1460 | const char *leaveit = /* set of acceptably-backslashed characters */ |
3280af22 | 1461 | PL_lex_inpat |
b6d5fef8 | 1462 | ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#" |
9b599b2a | 1463 | : ""; |
79072805 | 1464 | |
2b9d42f0 NIS |
1465 | if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) { |
1466 | /* If we are doing a trans and we know we want UTF8 set expectation */ | |
1467 | has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF); | |
1468 | this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); | |
1469 | } | |
1470 | ||
1471 | ||
79072805 | 1472 | while (s < send || dorange) { |
02aa26ce | 1473 | /* get transliterations out of the way (they're most literal) */ |
3280af22 | 1474 | if (PL_lex_inwhat == OP_TRANS) { |
02aa26ce | 1475 | /* expand a range A-Z to the full set of characters. AIE! */ |
79072805 | 1476 | if (dorange) { |
1ba5c669 JH |
1477 | I32 i; /* current expanded character */ |
1478 | I32 min; /* first character in range */ | |
1479 | I32 max; /* last character in range */ | |
02aa26ce | 1480 | |
2b9d42f0 | 1481 | if (has_utf8) { |
9d4ba2ae | 1482 | char * const c = (char*)utf8_hop((U8*)d, -1); |
8973db79 JH |
1483 | char *e = d++; |
1484 | while (e-- > c) | |
1485 | *(e + 1) = *e; | |
25716404 | 1486 | *c = (char)UTF_TO_NATIVE(0xff); |
8973db79 JH |
1487 | /* mark the range as done, and continue */ |
1488 | dorange = FALSE; | |
1489 | didrange = TRUE; | |
1490 | continue; | |
1491 | } | |
2b9d42f0 | 1492 | |
95a20fc0 | 1493 | i = d - SvPVX_const(sv); /* remember current offset */ |
9cbb5ea2 GS |
1494 | SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */ |
1495 | d = SvPVX(sv) + i; /* refresh d after realloc */ | |
02aa26ce NT |
1496 | d -= 2; /* eat the first char and the - */ |
1497 | ||
8ada0baa JH |
1498 | min = (U8)*d; /* first char in range */ |
1499 | max = (U8)d[1]; /* last char in range */ | |
1500 | ||
c2e66d9e | 1501 | if (min > max) { |
01ec43d0 | 1502 | Perl_croak(aTHX_ |
d1573ac7 | 1503 | "Invalid range \"%c-%c\" in transliteration operator", |
1ba5c669 | 1504 | (char)min, (char)max); |
c2e66d9e GS |
1505 | } |
1506 | ||
c7f1f016 | 1507 | #ifdef EBCDIC |
4c3a8340 TS |
1508 | if (literal_endpoint == 2 && |
1509 | ((isLOWER(min) && isLOWER(max)) || | |
1510 | (isUPPER(min) && isUPPER(max)))) { | |
8ada0baa JH |
1511 | if (isLOWER(min)) { |
1512 | for (i = min; i <= max; i++) | |
1513 | if (isLOWER(i)) | |
db42d148 | 1514 | *d++ = NATIVE_TO_NEED(has_utf8,i); |
8ada0baa JH |
1515 | } else { |
1516 | for (i = min; i <= max; i++) | |
1517 | if (isUPPER(i)) | |
db42d148 | 1518 | *d++ = NATIVE_TO_NEED(has_utf8,i); |
8ada0baa JH |
1519 | } |
1520 | } | |
1521 | else | |
1522 | #endif | |
1523 | for (i = min; i <= max; i++) | |
eb160463 | 1524 | *d++ = (char)i; |
02aa26ce NT |
1525 | |
1526 | /* mark the range as done, and continue */ | |
79072805 | 1527 | dorange = FALSE; |
01ec43d0 | 1528 | didrange = TRUE; |
4c3a8340 TS |
1529 | #ifdef EBCDIC |
1530 | literal_endpoint = 0; | |
1531 | #endif | |
79072805 | 1532 | continue; |
4e553d73 | 1533 | } |
02aa26ce NT |
1534 | |
1535 | /* range begins (ignore - as first or last char) */ | |
79072805 | 1536 | else if (*s == '-' && s+1 < send && s != start) { |
4e553d73 | 1537 | if (didrange) { |
1fafa243 | 1538 | Perl_croak(aTHX_ "Ambiguous range in transliteration operator"); |
01ec43d0 | 1539 | } |
2b9d42f0 | 1540 | if (has_utf8) { |
25716404 | 1541 | *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */ |
a0ed51b3 LW |
1542 | s++; |
1543 | continue; | |
1544 | } | |
79072805 LW |
1545 | dorange = TRUE; |
1546 | s++; | |
01ec43d0 GS |
1547 | } |
1548 | else { | |
1549 | didrange = FALSE; | |
4c3a8340 TS |
1550 | #ifdef EBCDIC |
1551 | literal_endpoint = 0; | |
1552 | #endif | |
01ec43d0 | 1553 | } |
79072805 | 1554 | } |
02aa26ce NT |
1555 | |
1556 | /* if we get here, we're not doing a transliteration */ | |
1557 | ||
0f5d15d6 IZ |
1558 | /* skip for regexp comments /(?#comment)/ and code /(?{code})/, |
1559 | except for the last char, which will be done separately. */ | |
3280af22 | 1560 | else if (*s == '(' && PL_lex_inpat && s[1] == '?') { |
cc6b7395 | 1561 | if (s[2] == '#') { |
e994fd66 | 1562 | while (s+1 < send && *s != ')') |
db42d148 | 1563 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
155aba94 GS |
1564 | } |
1565 | else if (s[2] == '{' /* This should match regcomp.c */ | |
1566 | || ((s[2] == 'p' || s[2] == '?') && s[3] == '{')) | |
1567 | { | |
cc6b7395 | 1568 | I32 count = 1; |
0f5d15d6 | 1569 | char *regparse = s + (s[2] == '{' ? 3 : 4); |
cc6b7395 IZ |
1570 | char c; |
1571 | ||
d9f97599 GS |
1572 | while (count && (c = *regparse)) { |
1573 | if (c == '\\' && regparse[1]) | |
1574 | regparse++; | |
4e553d73 | 1575 | else if (c == '{') |
cc6b7395 | 1576 | count++; |
4e553d73 | 1577 | else if (c == '}') |
cc6b7395 | 1578 | count--; |
d9f97599 | 1579 | regparse++; |
cc6b7395 | 1580 | } |
e994fd66 | 1581 | if (*regparse != ')') |
5bdf89e7 | 1582 | regparse--; /* Leave one char for continuation. */ |
0f5d15d6 | 1583 | while (s < regparse) |
db42d148 | 1584 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
cc6b7395 | 1585 | } |
748a9306 | 1586 | } |
02aa26ce NT |
1587 | |
1588 | /* likewise skip #-initiated comments in //x patterns */ | |
3280af22 NIS |
1589 | else if (*s == '#' && PL_lex_inpat && |
1590 | ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) { | |
748a9306 | 1591 | while (s+1 < send && *s != '\n') |
db42d148 | 1592 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
748a9306 | 1593 | } |
02aa26ce | 1594 | |
5d1d4326 | 1595 | /* check for embedded arrays |
da6eedaa | 1596 | (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-) |
5d1d4326 | 1597 | */ |
7e2040f0 | 1598 | else if (*s == '@' && s[1] |
5d1d4326 | 1599 | && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1]))) |
79072805 | 1600 | break; |
02aa26ce NT |
1601 | |
1602 | /* check for embedded scalars. only stop if we're sure it's a | |
1603 | variable. | |
1604 | */ | |
79072805 | 1605 | else if (*s == '$') { |
3280af22 | 1606 | if (!PL_lex_inpat) /* not a regexp, so $ must be var */ |
79072805 | 1607 | break; |
6002328a | 1608 | if (s + 1 < send && !strchr("()| \r\n\t", s[1])) |
79072805 LW |
1609 | break; /* in regexp, $ might be tail anchor */ |
1610 | } | |
02aa26ce | 1611 | |
2b9d42f0 NIS |
1612 | /* End of else if chain - OP_TRANS rejoin rest */ |
1613 | ||
02aa26ce | 1614 | /* backslashes */ |
79072805 LW |
1615 | if (*s == '\\' && s+1 < send) { |
1616 | s++; | |
02aa26ce NT |
1617 | |
1618 | /* some backslashes we leave behind */ | |
c9f97d15 | 1619 | if (*leaveit && *s && strchr(leaveit, *s)) { |
db42d148 NIS |
1620 | *d++ = NATIVE_TO_NEED(has_utf8,'\\'); |
1621 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); | |
79072805 LW |
1622 | continue; |
1623 | } | |
02aa26ce NT |
1624 | |
1625 | /* deprecate \1 in strings and substitution replacements */ | |
3280af22 | 1626 | if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat && |
a0d0e21e | 1627 | isDIGIT(*s) && *s != '0' && !isDIGIT(s[1])) |
79072805 | 1628 | { |
599cee73 | 1629 | if (ckWARN(WARN_SYNTAX)) |
9014280d | 1630 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s); |
79072805 LW |
1631 | *--s = '$'; |
1632 | break; | |
1633 | } | |
02aa26ce NT |
1634 | |
1635 | /* string-change backslash escapes */ | |
3280af22 | 1636 | if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) { |
79072805 LW |
1637 | --s; |
1638 | break; | |
1639 | } | |
02aa26ce NT |
1640 | |
1641 | /* if we get here, it's either a quoted -, or a digit */ | |
79072805 | 1642 | switch (*s) { |
02aa26ce NT |
1643 | |
1644 | /* quoted - in transliterations */ | |
79072805 | 1645 | case '-': |
3280af22 | 1646 | if (PL_lex_inwhat == OP_TRANS) { |
79072805 LW |
1647 | *d++ = *s++; |
1648 | continue; | |
1649 | } | |
1650 | /* FALL THROUGH */ | |
1651 | default: | |
11b8faa4 | 1652 | { |
041457d9 DM |
1653 | if (isALNUM(*s) && |
1654 | *s != '_' && | |
1655 | ckWARN(WARN_MISC)) | |
9014280d | 1656 | Perl_warner(aTHX_ packWARN(WARN_MISC), |
11b8faa4 JH |
1657 | "Unrecognized escape \\%c passed through", |
1658 | *s); | |
1659 | /* default action is to copy the quoted character */ | |
f9a63242 | 1660 | goto default_action; |
11b8faa4 | 1661 | } |
02aa26ce NT |
1662 | |
1663 | /* \132 indicates an octal constant */ | |
79072805 LW |
1664 | case '0': case '1': case '2': case '3': |
1665 | case '4': case '5': case '6': case '7': | |
ba210ebe | 1666 | { |
53305cf1 NC |
1667 | I32 flags = 0; |
1668 | STRLEN len = 3; | |
1669 | uv = grok_oct(s, &len, &flags, NULL); | |
ba210ebe JH |
1670 | s += len; |
1671 | } | |
012bcf8d | 1672 | goto NUM_ESCAPE_INSERT; |
02aa26ce NT |
1673 | |
1674 | /* \x24 indicates a hex constant */ | |
79072805 | 1675 | case 'x': |
a0ed51b3 LW |
1676 | ++s; |
1677 | if (*s == '{') { | |
9d4ba2ae | 1678 | char* const e = strchr(s, '}'); |
a4c04bdc NC |
1679 | I32 flags = PERL_SCAN_ALLOW_UNDERSCORES | |
1680 | PERL_SCAN_DISALLOW_PREFIX; | |
53305cf1 | 1681 | STRLEN len; |
355860ce | 1682 | |
53305cf1 | 1683 | ++s; |
adaeee49 | 1684 | if (!e) { |
a0ed51b3 | 1685 | yyerror("Missing right brace on \\x{}"); |
355860ce | 1686 | continue; |
ba210ebe | 1687 | } |
53305cf1 NC |
1688 | len = e - s; |
1689 | uv = grok_hex(s, &len, &flags, NULL); | |
ba210ebe | 1690 | s = e + 1; |
a0ed51b3 LW |
1691 | } |
1692 | else { | |
ba210ebe | 1693 | { |
53305cf1 | 1694 | STRLEN len = 2; |
a4c04bdc | 1695 | I32 flags = PERL_SCAN_DISALLOW_PREFIX; |
53305cf1 | 1696 | uv = grok_hex(s, &len, &flags, NULL); |
ba210ebe JH |
1697 | s += len; |
1698 | } | |
012bcf8d GS |
1699 | } |
1700 | ||
1701 | NUM_ESCAPE_INSERT: | |
1702 | /* Insert oct or hex escaped character. | |
301d3d20 | 1703 | * There will always enough room in sv since such |
db42d148 | 1704 | * escapes will be longer than any UTF-8 sequence |
301d3d20 | 1705 | * they can end up as. */ |
ba7cea30 | 1706 | |
c7f1f016 NIS |
1707 | /* We need to map to chars to ASCII before doing the tests |
1708 | to cover EBCDIC | |
1709 | */ | |
c4d5f83a | 1710 | if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) { |
9aa983d2 | 1711 | if (!has_utf8 && uv > 255) { |
301d3d20 JH |
1712 | /* Might need to recode whatever we have |
1713 | * accumulated so far if it contains any | |
1714 | * hibit chars. | |
1715 | * | |
1716 | * (Can't we keep track of that and avoid | |
1717 | * this rescan? --jhi) | |
012bcf8d | 1718 | */ |
c7f1f016 | 1719 | int hicount = 0; |
63cd0674 NIS |
1720 | U8 *c; |
1721 | for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) { | |
c4d5f83a | 1722 | if (!NATIVE_IS_INVARIANT(*c)) { |
012bcf8d | 1723 | hicount++; |
db42d148 | 1724 | } |
012bcf8d | 1725 | } |
63cd0674 | 1726 | if (hicount) { |
9d4ba2ae | 1727 | const STRLEN offset = d - SvPVX_const(sv); |
db42d148 NIS |
1728 | U8 *src, *dst; |
1729 | d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset; | |
1730 | src = (U8 *)d - 1; | |
1731 | dst = src+hicount; | |
1732 | d += hicount; | |
cfd0369c | 1733 | while (src >= (const U8 *)SvPVX_const(sv)) { |
c4d5f83a | 1734 | if (!NATIVE_IS_INVARIANT(*src)) { |
9d4ba2ae | 1735 | const U8 ch = NATIVE_TO_ASCII(*src); |
eb160463 GS |
1736 | *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch); |
1737 | *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch); | |
012bcf8d GS |
1738 | } |
1739 | else { | |
63cd0674 | 1740 | *dst-- = *src; |
012bcf8d | 1741 | } |
c7f1f016 | 1742 | src--; |
012bcf8d GS |
1743 | } |
1744 | } | |
1745 | } | |
1746 | ||
9aa983d2 | 1747 | if (has_utf8 || uv > 255) { |
9041c2e3 | 1748 | d = (char*)uvchr_to_utf8((U8*)d, uv); |
4e553d73 | 1749 | has_utf8 = TRUE; |
f9a63242 JH |
1750 | if (PL_lex_inwhat == OP_TRANS && |
1751 | PL_sublex_info.sub_op) { | |
1752 | PL_sublex_info.sub_op->op_private |= | |
1753 | (PL_lex_repl ? OPpTRANS_FROM_UTF | |
1754 | : OPpTRANS_TO_UTF); | |
f9a63242 | 1755 | } |
012bcf8d | 1756 | } |
a0ed51b3 | 1757 | else { |
012bcf8d | 1758 | *d++ = (char)uv; |
a0ed51b3 | 1759 | } |
012bcf8d GS |
1760 | } |
1761 | else { | |
c4d5f83a | 1762 | *d++ = (char) uv; |
a0ed51b3 | 1763 | } |
79072805 | 1764 | continue; |
02aa26ce | 1765 | |
b239daa5 | 1766 | /* \N{LATIN SMALL LETTER A} is a named character */ |
4a2d328f | 1767 | case 'N': |
55eda711 | 1768 | ++s; |
423cee85 JH |
1769 | if (*s == '{') { |
1770 | char* e = strchr(s, '}'); | |
155aba94 | 1771 | SV *res; |
423cee85 | 1772 | STRLEN len; |
cfd0369c | 1773 | const char *str; |
4e553d73 | 1774 | |
423cee85 | 1775 | if (!e) { |
5777a3f7 | 1776 | yyerror("Missing right brace on \\N{}"); |
423cee85 JH |
1777 | e = s - 1; |
1778 | goto cont_scan; | |
1779 | } | |
dbc0d4f2 JH |
1780 | if (e > s + 2 && s[1] == 'U' && s[2] == '+') { |
1781 | /* \N{U+...} */ | |
1782 | I32 flags = PERL_SCAN_ALLOW_UNDERSCORES | | |
1783 | PERL_SCAN_DISALLOW_PREFIX; | |
1784 | s += 3; | |
1785 | len = e - s; | |
1786 | uv = grok_hex(s, &len, &flags, NULL); | |
1787 | s = e + 1; | |
1788 | goto NUM_ESCAPE_INSERT; | |
1789 | } | |
55eda711 | 1790 | res = newSVpvn(s + 1, e - s - 1); |
bd61b366 | 1791 | res = new_constant( NULL, 0, "charnames", |
a0714e2c | 1792 | res, NULL, "\\N{...}" ); |
f9a63242 JH |
1793 | if (has_utf8) |
1794 | sv_utf8_upgrade(res); | |
cfd0369c | 1795 | str = SvPV_const(res,len); |
1c47067b JH |
1796 | #ifdef EBCDIC_NEVER_MIND |
1797 | /* charnames uses pack U and that has been | |
1798 | * recently changed to do the below uni->native | |
1799 | * mapping, so this would be redundant (and wrong, | |
1800 | * the code point would be doubly converted). | |
1801 | * But leave this in just in case the pack U change | |
1802 | * gets revoked, but the semantics is still | |
1803 | * desireable for charnames. --jhi */ | |
cddc7ef4 | 1804 | { |
cfd0369c | 1805 | UV uv = utf8_to_uvchr((const U8*)str, 0); |
cddc7ef4 JH |
1806 | |
1807 | if (uv < 0x100) { | |
89ebb4a3 | 1808 | U8 tmpbuf[UTF8_MAXBYTES+1], *d; |
cddc7ef4 JH |
1809 | |
1810 | d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv)); | |
1811 | sv_setpvn(res, (char *)tmpbuf, d - tmpbuf); | |
cfd0369c | 1812 | str = SvPV_const(res, len); |
cddc7ef4 JH |
1813 | } |
1814 | } | |
1815 | #endif | |
89491803 | 1816 | if (!has_utf8 && SvUTF8(res)) { |
9d4ba2ae | 1817 | const char * const ostart = SvPVX_const(sv); |
f08d6ad9 GS |
1818 | SvCUR_set(sv, d - ostart); |
1819 | SvPOK_on(sv); | |
e4f3eed8 | 1820 | *d = '\0'; |
f08d6ad9 | 1821 | sv_utf8_upgrade(sv); |
d2f449dd | 1822 | /* this just broke our allocation above... */ |
eb160463 | 1823 | SvGROW(sv, (STRLEN)(send - start)); |
f08d6ad9 | 1824 | d = SvPVX(sv) + SvCUR(sv); |
89491803 | 1825 | has_utf8 = TRUE; |
f08d6ad9 | 1826 | } |
eb160463 | 1827 | if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */ |
9d4ba2ae | 1828 | const char * const odest = SvPVX_const(sv); |
423cee85 | 1829 | |
8973db79 | 1830 | SvGROW(sv, (SvLEN(sv) + len - (e - s + 4))); |
423cee85 JH |
1831 | d = SvPVX(sv) + (d - odest); |
1832 | } | |
1833 | Copy(str, d, len, char); | |
1834 | d += len; | |
1835 | SvREFCNT_dec(res); | |
1836 | cont_scan: | |
1837 | s = e + 1; | |
1838 | } | |
1839 | else | |
5777a3f7 | 1840 | yyerror("Missing braces on \\N{}"); |
423cee85 JH |
1841 | continue; |
1842 | ||
02aa26ce | 1843 | /* \c is a control character */ |
79072805 LW |
1844 | case 'c': |
1845 | s++; | |
961ce445 | 1846 | if (s < send) { |
ba210ebe | 1847 | U8 c = *s++; |
c7f1f016 NIS |
1848 | #ifdef EBCDIC |
1849 | if (isLOWER(c)) | |
1850 | c = toUPPER(c); | |
1851 | #endif | |
db42d148 | 1852 | *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c)); |
ba210ebe | 1853 | } |
961ce445 RGS |
1854 | else { |
1855 | yyerror("Missing control char name in \\c"); | |
1856 | } | |
79072805 | 1857 | continue; |
02aa26ce NT |
1858 | |
1859 | /* printf-style backslashes, formfeeds, newlines, etc */ | |
79072805 | 1860 | case 'b': |
db42d148 | 1861 | *d++ = NATIVE_TO_NEED(has_utf8,'\b'); |
79072805 LW |
1862 | break; |
1863 | case 'n': | |
db42d148 | 1864 | *d++ = NATIVE_TO_NEED(has_utf8,'\n'); |
79072805 LW |
1865 | break; |
1866 | case 'r': | |
db42d148 | 1867 | *d++ = NATIVE_TO_NEED(has_utf8,'\r'); |
79072805 LW |
1868 | break; |
1869 | case 'f': | |
db42d148 | 1870 | *d++ = NATIVE_TO_NEED(has_utf8,'\f'); |
79072805 LW |
1871 | break; |
1872 | case 't': | |
db42d148 | 1873 | *d++ = NATIVE_TO_NEED(has_utf8,'\t'); |
79072805 | 1874 | break; |
34a3fe2a | 1875 | case 'e': |
db42d148 | 1876 | *d++ = ASCII_TO_NEED(has_utf8,'\033'); |
34a3fe2a PP |
1877 | break; |
1878 | case 'a': | |
db42d148 | 1879 | *d++ = ASCII_TO_NEED(has_utf8,'\007'); |
79072805 | 1880 | break; |
02aa26ce NT |
1881 | } /* end switch */ |
1882 | ||
79072805 LW |
1883 | s++; |
1884 | continue; | |
02aa26ce | 1885 | } /* end if (backslash) */ |
4c3a8340 TS |
1886 | #ifdef EBCDIC |
1887 | else | |
1888 | literal_endpoint++; | |
1889 | #endif | |
02aa26ce | 1890 | |
f9a63242 | 1891 | default_action: |
2b9d42f0 NIS |
1892 | /* If we started with encoded form, or already know we want it |
1893 | and then encode the next character */ | |
1894 | if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) { | |
1895 | STRLEN len = 1; | |
5f66b61c AL |
1896 | const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s); |
1897 | const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv)); | |
2b9d42f0 NIS |
1898 | s += len; |
1899 | if (need > len) { | |
1900 | /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */ | |
9d4ba2ae | 1901 | const STRLEN off = d - SvPVX_const(sv); |
2b9d42f0 NIS |
1902 | d = SvGROW(sv, SvLEN(sv) + (need-len)) + off; |
1903 | } | |
5f66b61c | 1904 | d = (char*)uvchr_to_utf8((U8*)d, nextuv); |
2b9d42f0 NIS |
1905 | has_utf8 = TRUE; |
1906 | } | |
1907 | else { | |
1908 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); | |
1909 | } | |
02aa26ce NT |
1910 | } /* while loop to process each character */ |
1911 | ||
1912 | /* terminate the string and set up the sv */ | |
79072805 | 1913 | *d = '\0'; |
95a20fc0 | 1914 | SvCUR_set(sv, d - SvPVX_const(sv)); |
2b9d42f0 | 1915 | if (SvCUR(sv) >= SvLEN(sv)) |
d0063567 | 1916 | Perl_croak(aTHX_ "panic: constant overflowed allocated space"); |
2b9d42f0 | 1917 | |
79072805 | 1918 | SvPOK_on(sv); |
9f4817db | 1919 | if (PL_encoding && !has_utf8) { |
d0063567 DK |
1920 | sv_recode_to_utf8(sv, PL_encoding); |
1921 | if (SvUTF8(sv)) | |
1922 | has_utf8 = TRUE; | |
9f4817db | 1923 | } |
2b9d42f0 | 1924 | if (has_utf8) { |
7e2040f0 | 1925 | SvUTF8_on(sv); |
2b9d42f0 | 1926 | if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) { |
d0063567 | 1927 | PL_sublex_info.sub_op->op_private |= |
2b9d42f0 NIS |
1928 | (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); |
1929 | } | |
1930 | } | |
79072805 | 1931 | |
02aa26ce | 1932 | /* shrink the sv if we allocated more than we used */ |
79072805 | 1933 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
1da4ca5f | 1934 | SvPV_shrink_to_cur(sv); |
79072805 | 1935 | } |
02aa26ce | 1936 | |
9b599b2a | 1937 | /* return the substring (via yylval) only if we parsed anything */ |
3280af22 NIS |
1938 | if (s > PL_bufptr) { |
1939 | if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) | |
4e553d73 | 1940 | sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"), |
a0714e2c | 1941 | sv, NULL, |
4e553d73 | 1942 | ( PL_lex_inwhat == OP_TRANS |
b3ac6de7 | 1943 | ? "tr" |
3280af22 | 1944 | : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) |
b3ac6de7 IZ |
1945 | ? "s" |
1946 | : "qq"))); | |
79072805 | 1947 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
b3ac6de7 | 1948 | } else |
8990e307 | 1949 | SvREFCNT_dec(sv); |
79072805 LW |
1950 | return s; |
1951 | } | |
1952 | ||
ffb4593c NT |
1953 | /* S_intuit_more |
1954 | * Returns TRUE if there's more to the expression (e.g., a subscript), | |
1955 | * FALSE otherwise. | |
ffb4593c NT |
1956 | * |
1957 | * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/ | |
1958 | * | |
1959 | * ->[ and ->{ return TRUE | |
1960 | * { and [ outside a pattern are always subscripts, so return TRUE | |
1961 | * if we're outside a pattern and it's not { or [, then return FALSE | |
1962 | * if we're in a pattern and the first char is a { | |
1963 | * {4,5} (any digits around the comma) returns FALSE | |
1964 | * if we're in a pattern and the first char is a [ | |
1965 | * [] returns FALSE | |
1966 | * [SOMETHING] has a funky algorithm to decide whether it's a | |
1967 | * character class or not. It has to deal with things like | |
1968 | * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/ | |
1969 | * anything else returns TRUE | |
1970 | */ | |
1971 | ||
9cbb5ea2 GS |
1972 | /* This is the one truly awful dwimmer necessary to conflate C and sed. */ |
1973 | ||
76e3520e | 1974 | STATIC int |
cea2e8a9 | 1975 | S_intuit_more(pTHX_ register char *s) |
79072805 | 1976 | { |
97aff369 | 1977 | dVAR; |
3280af22 | 1978 | if (PL_lex_brackets) |
79072805 LW |
1979 | return TRUE; |
1980 | if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{')) | |
1981 | return TRUE; | |
1982 | if (*s != '{' && *s != '[') | |
1983 | return FALSE; | |
3280af22 | 1984 | if (!PL_lex_inpat) |
79072805 LW |
1985 | return TRUE; |
1986 | ||
1987 | /* In a pattern, so maybe we have {n,m}. */ | |
1988 | if (*s == '{') { | |
1989 | s++; | |
1990 | if (!isDIGIT(*s)) | |
1991 | return TRUE; | |
1992 | while (isDIGIT(*s)) | |
1993 | s++; | |
1994 | if (*s == ',') | |
1995 | s++; | |
1996 | while (isDIGIT(*s)) | |
1997 | s++; | |
1998 | if (*s == '}') | |
1999 | return FALSE; | |
2000 | return TRUE; | |
2001 | ||
2002 | } | |
2003 | ||
2004 | /* On the other hand, maybe we have a character class */ | |
2005 | ||
2006 | s++; | |
2007 | if (*s == ']' || *s == '^') | |
2008 | return FALSE; | |
2009 | else { | |
ffb4593c | 2010 | /* this is terrifying, and it works */ |
79072805 LW |
2011 | int weight = 2; /* let's weigh the evidence */ |
2012 | char seen[256]; | |
f27ffc4a | 2013 | unsigned char un_char = 255, last_un_char; |
9d4ba2ae | 2014 | const char * const send = strchr(s,']'); |
3280af22 | 2015 | char tmpbuf[sizeof PL_tokenbuf * 4]; |
79072805 LW |
2016 | |
2017 | if (!send) /* has to be an expression */ | |
2018 | return TRUE; | |
2019 | ||
2020 | Zero(seen,256,char); | |
2021 | if (*s == '$') | |
2022 | weight -= 3; | |
2023 | else if (isDIGIT(*s)) { | |
2024 | if (s[1] != ']') { | |
2025 | if (isDIGIT(s[1]) && s[2] == ']') | |
2026 | weight -= 10; | |
2027 | } | |
2028 | else | |
2029 | weight -= 100; | |
2030 | } | |
2031 | for (; s < send; s++) { | |
2032 | last_un_char = un_char; | |
2033 | un_char = (unsigned char)*s; | |
2034 | switch (*s) { | |
2035 | case '@': | |
2036 | case '&': | |
2037 | case '$': | |
2038 | weight -= seen[un_char] * 10; | |
7e2040f0 | 2039 | if (isALNUM_lazy_if(s+1,UTF)) { |
90e5519e | 2040 | int len; |
8903cb82 | 2041 | scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE); |
90e5519e NC |
2042 | len = (int)strlen(tmpbuf); |
2043 | if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV)) | |
79072805 LW |
2044 | weight -= 100; |
2045 | else | |
2046 | weight -= 10; | |
2047 | } | |
2048 | else if (*s == '$' && s[1] && | |
93a17b20 LW |
2049 | strchr("[#!%*<>()-=",s[1])) { |
2050 | if (/*{*/ strchr("])} =",s[2])) | |
79072805 LW |
2051 | weight -= 10; |
2052 | else | |
2053 | weight -= 1; | |
2054 | } | |
2055 | break; | |
2056 | case '\\': | |
2057 | un_char = 254; | |
2058 | if (s[1]) { | |
93a17b20 | 2059 | if (strchr("wds]",s[1])) |
79072805 LW |
2060 | weight += 100; |
2061 | else if (seen['\''] || seen['"']) | |
2062 | weight += 1; | |
93a17b20 | 2063 | else if (strchr("rnftbxcav",s[1])) |
79072805 LW |
2064 | weight += 40; |
2065 | else if (isDIGIT(s[1])) { | |
2066 | weight += 40; | |
2067 | while (s[1] && isDIGIT(s[1])) | |
2068 | s++; | |
2069 | } | |
2070 | } | |
2071 | else | |
2072 | weight += 100; | |
2073 | break; | |
2074 | case '-': | |
2075 | if (s[1] == '\\') | |
2076 | weight += 50; | |
93a17b20 | 2077 | if (strchr("aA01! ",last_un_char)) |
79072805 | 2078 | weight += 30; |
93a17b20 | 2079 | if (strchr("zZ79~",s[1])) |
79072805 | 2080 | weight += 30; |
f27ffc4a GS |
2081 | if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$')) |
2082 | weight -= 5; /* cope with negative subscript */ | |
79072805 LW |
2083 | break; |
2084 | default: | |
3792a11b NC |
2085 | if (!isALNUM(last_un_char) |
2086 | && !(last_un_char == '$' || last_un_char == '@' | |
2087 | || last_un_char == '&') | |
2088 | && isALPHA(*s) && s[1] && isALPHA(s[1])) { | |
79072805 LW |
2089 | char *d = tmpbuf; |
2090 | while (isALPHA(*s)) | |
2091 | *d++ = *s++; | |
2092 | *d = '\0'; | |
2093 | if (keyword(tmpbuf, d - tmpbuf)) | |
2094 | weight -= 150; | |
2095 | } | |
2096 | if (un_char == last_un_char + 1) | |
2097 | weight += 5; | |
2098 | weight -= seen[un_char]; | |
2099 | break; | |
2100 | } | |
2101 | seen[un_char]++; | |
2102 | } | |
2103 | if (weight >= 0) /* probably a character class */ | |
2104 | return FALSE; | |
2105 | } | |
2106 | ||
2107 | return TRUE; | |
2108 | } | |
ffed7fef | 2109 | |
ffb4593c NT |
2110 | /* |
2111 | * S_intuit_method | |
2112 | * | |
2113 | * Does all the checking to disambiguate | |
2114 | * foo bar | |
2115 | * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise | |
2116 | * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args). | |
2117 | * | |
2118 | * First argument is the stuff after the first token, e.g. "bar". | |
2119 | * | |
2120 | * Not a method if bar is a filehandle. | |
2121 | * Not a method if foo is a subroutine prototyped to take a filehandle. | |
2122 | * Not a method if it's really "Foo $bar" | |
2123 | * Method if it's "foo $bar" | |
2124 | * Not a method if it's really "print foo $bar" | |
2125 | * Method if it's really "foo package::" (interpreted as package->foo) | |
8f8cf39c | 2126 | * Not a method if bar is known to be a subroutine ("sub bar; foo bar") |
3cb0bbe5 | 2127 | * Not a method if bar is a filehandle or package, but is quoted with |
ffb4593c NT |
2128 | * => |
2129 | */ | |
2130 | ||
76e3520e | 2131 | STATIC int |
62d55b22 | 2132 | S_intuit_method(pTHX_ char *start, GV *gv, CV *cv) |
a0d0e21e | 2133 | { |
97aff369 | 2134 | dVAR; |
a0d0e21e | 2135 | char *s = start + (*start == '$'); |
3280af22 | 2136 | char tmpbuf[sizeof PL_tokenbuf]; |
a0d0e21e LW |
2137 | STRLEN len; |
2138 | GV* indirgv; | |
2139 | ||
2140 | if (gv) { | |
62d55b22 | 2141 | if (SvTYPE(gv) == SVt_PVGV && GvIO(gv)) |
a0d0e21e | 2142 | return 0; |
62d55b22 NC |
2143 | if (cv) { |
2144 | if (SvPOK(cv)) { | |
2145 | const char *proto = SvPVX_const(cv); | |
2146 | if (proto) { | |
2147 | if (*proto == ';') | |
2148 | proto++; | |
2149 | if (*proto == '*') | |
2150 | return 0; | |
2151 | } | |
b6c543e3 IZ |
2152 | } |
2153 | } else | |
a0d0e21e LW |
2154 | gv = 0; |
2155 | } | |
8903cb82 | 2156 | s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
ffb4593c NT |
2157 | /* start is the beginning of the possible filehandle/object, |
2158 | * and s is the end of it | |
2159 | * tmpbuf is a copy of it | |
2160 | */ | |
2161 | ||
a0d0e21e | 2162 | if (*start == '$') { |
3280af22 | 2163 | if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf)) |
a0d0e21e LW |
2164 | return 0; |
2165 | s = skipspace(s); | |
3280af22 NIS |
2166 | PL_bufptr = start; |
2167 | PL_expect = XREF; | |
a0d0e21e LW |
2168 | return *s == '(' ? FUNCMETH : METHOD; |
2169 | } | |
2170 | if (!keyword(tmpbuf, len)) { | |
c3e0f903 GS |
2171 | if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') { |
2172 | len -= 2; | |
2173 | tmpbuf[len] = '\0'; | |
2174 | goto bare_package; | |
2175 | } | |
90e5519e | 2176 | indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV); |
8ebc5c01 | 2177 | if (indirgv && GvCVu(indirgv)) |
a0d0e21e LW |
2178 | return 0; |
2179 | /* filehandle or package name makes it a method */ | |
89bfa8cd | 2180 | if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) { |
a0d0e21e | 2181 | s = skipspace(s); |
3280af22 | 2182 | if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>') |
55497cff | 2183 | return 0; /* no assumptions -- "=>" quotes bearword */ |
c3e0f903 | 2184 | bare_package: |
3280af22 | 2185 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, |
79cb57f6 | 2186 | newSVpvn(tmpbuf,len)); |
3280af22 NIS |
2187 | PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE; |
2188 | PL_expect = XTERM; | |
a0d0e21e | 2189 | force_next(WORD); |
3280af22 | 2190 | PL_bufptr = s; |
a0d0e21e LW |
2191 | return *s == '(' ? FUNCMETH : METHOD; |
2192 | } | |
2193 | } | |
2194 | return 0; | |
2195 | } | |
2196 | ||
ffb4593c NT |
2197 | /* |
2198 | * S_incl_perldb | |
2199 | * Return a string of Perl code to load the debugger. If PERL5DB | |
2200 | * is set, it will return the contents of that, otherwise a | |
2201 | * compile-time require of perl5db.pl. | |
2202 | */ | |
2203 | ||
bfed75c6 | 2204 | STATIC const char* |
cea2e8a9 | 2205 | S_incl_perldb(pTHX) |
a0d0e21e | 2206 | { |
97aff369 | 2207 | dVAR; |
3280af22 | 2208 | if (PL_perldb) { |
9d4ba2ae | 2209 | const char * const pdb = PerlEnv_getenv("PERL5DB"); |
a0d0e21e LW |
2210 | |
2211 | if (pdb) | |
2212 | return pdb; | |
93189314 | 2213 | SETERRNO(0,SS_NORMAL); |
a0d0e21e LW |
2214 | return "BEGIN { require 'perl5db.pl' }"; |
2215 | } | |
2216 | return ""; | |
2217 | } | |
2218 | ||
2219 | ||
16d20bd9 | 2220 | /* Encoded script support. filter_add() effectively inserts a |
4e553d73 | 2221 | * 'pre-processing' function into the current source input stream. |
16d20bd9 AD |
2222 | * Note that the filter function only applies to the current source file |
2223 | * (e.g., it will not affect files 'require'd or 'use'd by this one). | |
2224 | * | |
2225 | * The datasv parameter (which may be NULL) can be used to pass | |
2226 | * private data to this instance of the filter. The filter function | |
2227 | * can recover the SV using the FILTER_DATA macro and use it to | |
2228 | * store private buffers and state information. | |
2229 | * | |
2230 | * The supplied datasv parameter is upgraded to a PVIO type | |
4755096e | 2231 | * and the IoDIRP/IoANY field is used to store the function pointer, |
e0c19803 | 2232 | * and IOf_FAKE_DIRP is enabled on datasv to mark this as such. |
16d20bd9 AD |
2233 | * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for |
2234 | * private use must be set using malloc'd pointers. | |
2235 | */ | |
16d20bd9 AD |
2236 | |
2237 | SV * | |
864dbfa3 | 2238 | Perl_filter_add(pTHX_ filter_t funcp, SV *datasv) |
16d20bd9 | 2239 | { |
97aff369 | 2240 | dVAR; |
f4c556ac | 2241 | if (!funcp) |
a0714e2c | 2242 | return NULL; |
f4c556ac | 2243 | |
3280af22 NIS |
2244 | if (!PL_rsfp_filters) |
2245 | PL_rsfp_filters = newAV(); | |
16d20bd9 | 2246 | if (!datasv) |
561b68a9 | 2247 | datasv = newSV(0); |
862a34c6 | 2248 | SvUPGRADE(datasv, SVt_PVIO); |
8141890a | 2249 | IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */ |
e0c19803 | 2250 | IoFLAGS(datasv) |= IOf_FAKE_DIRP; |
f4c556ac | 2251 | DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n", |
8141890a | 2252 | IoANY(datasv), SvPV_nolen(datasv))); |
3280af22 NIS |
2253 | av_unshift(PL_rsfp_filters, 1); |
2254 | av_store(PL_rsfp_filters, 0, datasv) ; | |
16d20bd9 AD |
2255 | return(datasv); |
2256 | } | |
4e553d73 | 2257 | |
16d20bd9 AD |
2258 | |
2259 | /* Delete most recently added instance of this filter function. */ | |
a0d0e21e | 2260 | void |
864dbfa3 | 2261 | Perl_filter_del(pTHX_ filter_t funcp) |
16d20bd9 | 2262 | { |
97aff369 | 2263 | dVAR; |
e0c19803 | 2264 | SV *datasv; |
24801a4b | 2265 | |
33073adb | 2266 | #ifdef DEBUGGING |
8141890a | 2267 | DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", FPTR2DPTR(XPVIO *, funcp))); |
33073adb | 2268 | #endif |
3280af22 | 2269 | if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0) |
16d20bd9 AD |
2270 | return; |
2271 | /* if filter is on top of stack (usual case) just pop it off */ | |
e0c19803 | 2272 | datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters)); |
8141890a | 2273 | if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) { |
e0c19803 | 2274 | IoFLAGS(datasv) &= ~IOf_FAKE_DIRP; |
4755096e | 2275 | IoANY(datasv) = (void *)NULL; |
3280af22 | 2276 | sv_free(av_pop(PL_rsfp_filters)); |
e50aee73 | 2277 | |
16d20bd9 AD |
2278 | return; |
2279 | } | |
2280 | /* we need to search for the correct entry and clear it */ | |
cea2e8a9 | 2281 | Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)"); |
16d20bd9 AD |
2282 | } |
2283 | ||
2284 | ||
1de9afcd RGS |
2285 | /* Invoke the idxth filter function for the current rsfp. */ |
2286 | /* maxlen 0 = read one text line */ | |
16d20bd9 | 2287 | I32 |
864dbfa3 | 2288 | Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen) |
a0d0e21e | 2289 | { |
97aff369 | 2290 | dVAR; |
16d20bd9 AD |
2291 | filter_t funcp; |
2292 | SV *datasv = NULL; | |
e50aee73 | 2293 | |
3280af22 | 2294 | if (!PL_rsfp_filters) |
16d20bd9 | 2295 | return -1; |
1de9afcd | 2296 | if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */ |
16d20bd9 AD |
2297 | /* Provide a default input filter to make life easy. */ |
2298 | /* Note that we append to the line. This is handy. */ | |
f4c556ac GS |
2299 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2300 | "filter_read %d: from rsfp\n", idx)); | |
4e553d73 | 2301 | if (maxlen) { |
16d20bd9 AD |
2302 | /* Want a block */ |
2303 | int len ; | |
f54cb97a | 2304 | const int old_len = SvCUR(buf_sv); |
16d20bd9 AD |
2305 | |
2306 | /* ensure buf_sv is large enough */ | |
eb160463 | 2307 | SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ; |
3280af22 NIS |
2308 | if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){ |
2309 | if (PerlIO_error(PL_rsfp)) | |
37120919 AD |
2310 | return -1; /* error */ |
2311 | else | |
2312 | return 0 ; /* end of file */ | |
2313 | } | |
16d20bd9 AD |
2314 | SvCUR_set(buf_sv, old_len + len) ; |
2315 | } else { | |
2316 | /* Want a line */ | |
3280af22 NIS |
2317 | if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) { |
2318 | if (PerlIO_error(PL_rsfp)) | |
37120919 AD |
2319 | return -1; /* error */ |
2320 | else | |
2321 | return 0 ; /* end of file */ | |
2322 | } | |
16d20bd9 AD |
2323 | } |
2324 | return SvCUR(buf_sv); | |
2325 | } | |
2326 | /* Skip this filter slot if filter has been deleted */ | |
1de9afcd | 2327 | if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) { |
f4c556ac GS |
2328 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2329 | "filter_read %d: skipped (filter deleted)\n", | |
2330 | idx)); | |
16d20bd9 AD |
2331 | return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */ |
2332 | } | |
2333 | /* Get function pointer hidden within datasv */ | |
8141890a | 2334 | funcp = DPTR2FPTR(filter_t, IoANY(datasv)); |
f4c556ac GS |
2335 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2336 | "filter_read %d: via function %p (%s)\n", | |
cfd0369c | 2337 | idx, datasv, SvPV_nolen_const(datasv))); |
16d20bd9 AD |
2338 | /* Call function. The function is expected to */ |
2339 | /* call "FILTER_READ(idx+1, buf_sv)" first. */ | |
37120919 | 2340 | /* Return: <0:error, =0:eof, >0:not eof */ |
acfe0abc | 2341 | return (*funcp)(aTHX_ idx, buf_sv, maxlen); |
16d20bd9 AD |
2342 | } |
2343 | ||
76e3520e | 2344 | STATIC char * |
cea2e8a9 | 2345 | S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append) |
16d20bd9 | 2346 | { |
97aff369 | 2347 | dVAR; |
c39cd008 | 2348 | #ifdef PERL_CR_FILTER |
3280af22 | 2349 | if (!PL_rsfp_filters) { |
c39cd008 | 2350 | filter_add(S_cr_textfilter,NULL); |
a868473f NIS |
2351 | } |
2352 | #endif | |
3280af22 | 2353 | if (PL_rsfp_filters) { |
55497cff | 2354 | if (!append) |
2355 | SvCUR_set(sv, 0); /* start with empty line */ | |
16d20bd9 AD |
2356 | if (FILTER_READ(0, sv, 0) > 0) |
2357 | return ( SvPVX(sv) ) ; | |
2358 | else | |
bd61b366 | 2359 | return NULL ; |
16d20bd9 | 2360 | } |
9d116dd7 | 2361 | else |
fd049845 | 2362 | return (sv_gets(sv, fp, append)); |
a0d0e21e LW |
2363 | } |
2364 | ||
01ec43d0 | 2365 | STATIC HV * |
7fc63493 | 2366 | S_find_in_my_stash(pTHX_ const char *pkgname, I32 len) |
def3634b | 2367 | { |
97aff369 | 2368 | dVAR; |
def3634b GS |
2369 | GV *gv; |
2370 | ||
01ec43d0 | 2371 | if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__")) |
def3634b GS |
2372 | return PL_curstash; |
2373 | ||
2374 | if (len > 2 && | |
2375 | (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') && | |
90e5519e | 2376 | (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV))) |
01ec43d0 GS |
2377 | { |
2378 | return GvHV(gv); /* Foo:: */ | |
def3634b GS |
2379 | } |
2380 | ||
2381 | /* use constant CLASS => 'MyClass' */ | |
90e5519e | 2382 | if ((gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV))) { |
def3634b GS |
2383 | SV *sv; |
2384 | if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) { | |
83003860 | 2385 | pkgname = SvPV_nolen_const(sv); |
def3634b GS |
2386 | } |
2387 | } | |
2388 | ||
2389 | return gv_stashpv(pkgname, FALSE); | |
2390 | } | |
a0d0e21e | 2391 | |
468aa647 | 2392 | STATIC char * |
cc6ed77d | 2393 | S_tokenize_use(pTHX_ int is_use, char *s) { |
97aff369 | 2394 | dVAR; |
468aa647 RGS |
2395 | if (PL_expect != XSTATE) |
2396 | yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression", | |
2397 | is_use ? "use" : "no")); | |
2398 | s = skipspace(s); | |
2399 | if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) { | |
2400 | s = force_version(s, TRUE); | |
2401 | if (*s == ';' || (s = skipspace(s), *s == ';')) { | |
5f66b61c | 2402 | PL_nextval[PL_nexttoke].opval = NULL; |
468aa647 RGS |
2403 | force_next(WORD); |
2404 | } | |
2405 | else if (*s == 'v') { | |
2406 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
2407 | s = force_version(s, FALSE); | |
2408 | } | |
2409 | } | |
2410 | else { | |
2411 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
2412 | s = force_version(s, FALSE); | |
2413 | } | |
2414 | yylval.ival = is_use; | |
2415 | return s; | |
2416 | } | |
748a9306 | 2417 | #ifdef DEBUGGING |
27da23d5 | 2418 | static const char* const exp_name[] = |
09bef843 | 2419 | { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK", |
27308ded | 2420 | "ATTRTERM", "TERMBLOCK", "TERMORDORDOR" |
09bef843 | 2421 | }; |
748a9306 | 2422 | #endif |
463ee0b2 | 2423 | |
02aa26ce NT |
2424 | /* |
2425 | yylex | |
2426 | ||
2427 | Works out what to call the token just pulled out of the input | |
2428 | stream. The yacc parser takes care of taking the ops we return and | |
2429 | stitching them into a tree. | |
2430 | ||
2431 | Returns: | |
2432 | PRIVATEREF | |
2433 | ||
2434 | Structure: | |
2435 | if read an identifier | |
2436 | if we're in a my declaration | |
2437 | croak if they tried to say my($foo::bar) | |
2438 | build the ops for a my() declaration | |
2439 | if it's an access to a my() variable | |
2440 | are we in a sort block? | |
2441 | croak if my($a); $a <=> $b | |
2442 | build ops for access to a my() variable | |
2443 | if in a dq string, and they've said @foo and we can't find @foo | |
2444 | croak | |
2445 | build ops for a bareword | |
2446 | if we already built the token before, use it. | |
2447 | */ | |
2448 | ||
20141f0e | 2449 | |
dba4d153 JH |
2450 | #ifdef __SC__ |
2451 | #pragma segment Perl_yylex | |
2452 | #endif | |
dba4d153 | 2453 | int |
dba4d153 | 2454 | Perl_yylex(pTHX) |
20141f0e | 2455 | { |
97aff369 | 2456 | dVAR; |
3afc138a | 2457 | register char *s = PL_bufptr; |
378cc40b | 2458 | register char *d; |
463ee0b2 | 2459 | STRLEN len; |
aa7440fb | 2460 | bool bof = FALSE; |
a687059c | 2461 | |
bbf60fe6 | 2462 | DEBUG_T( { |
396482e1 | 2463 | SV* tmp = newSVpvs(""); |
b6007c36 DM |
2464 | PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n", |
2465 | (IV)CopLINE(PL_curcop), | |
2466 | lex_state_names[PL_lex_state], | |
2467 | exp_name[PL_expect], | |
2468 | pv_display(tmp, s, strlen(s), 0, 60)); | |
2469 | SvREFCNT_dec(tmp); | |
bbf60fe6 | 2470 | } ); |
02aa26ce | 2471 | /* check if there's an identifier for us to look at */ |
ba979b31 | 2472 | if (PL_pending_ident) |
bbf60fe6 | 2473 | return REPORT(S_pending_ident(aTHX)); |
bbce6d69 | 2474 | |
02aa26ce NT |
2475 | /* no identifier pending identification */ |
2476 | ||
3280af22 | 2477 | switch (PL_lex_state) { |
79072805 LW |
2478 | #ifdef COMMENTARY |
2479 | case LEX_NORMAL: /* Some compilers will produce faster */ | |
2480 | case LEX_INTERPNORMAL: /* code if we comment these out. */ | |
2481 | break; | |
2482 | #endif | |
2483 | ||
09bef843 | 2484 | /* when we've already built the next token, just pull it out of the queue */ |
79072805 | 2485 | case LEX_KNOWNEXT: |
3280af22 NIS |
2486 | PL_nexttoke--; |
2487 | yylval = PL_nextval[PL_nexttoke]; | |
2488 | if (!PL_nexttoke) { | |
2489 | PL_lex_state = PL_lex_defer; | |
2490 | PL_expect = PL_lex_expect; | |
2491 | PL_lex_defer = LEX_NORMAL; | |
463ee0b2 | 2492 | } |
bbf60fe6 | 2493 | return REPORT(PL_nexttype[PL_nexttoke]); |
79072805 | 2494 | |
02aa26ce | 2495 | /* interpolated case modifiers like \L \U, including \Q and \E. |
3280af22 | 2496 | when we get here, PL_bufptr is at the \ |
02aa26ce | 2497 | */ |
79072805 LW |
2498 | case LEX_INTERPCASEMOD: |
2499 | #ifdef DEBUGGING | |
3280af22 | 2500 | if (PL_bufptr != PL_bufend && *PL_bufptr != '\\') |
cea2e8a9 | 2501 | Perl_croak(aTHX_ "panic: INTERPCASEMOD"); |
79072805 | 2502 | #endif |
02aa26ce | 2503 | /* handle \E or end of string */ |
3280af22 | 2504 | if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') { |
02aa26ce | 2505 | /* if at a \E */ |
3280af22 | 2506 | if (PL_lex_casemods) { |
f54cb97a | 2507 | const char oldmod = PL_lex_casestack[--PL_lex_casemods]; |
3280af22 | 2508 | PL_lex_casestack[PL_lex_casemods] = '\0'; |
02aa26ce | 2509 | |
3792a11b NC |
2510 | if (PL_bufptr != PL_bufend |
2511 | && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) { | |
3280af22 NIS |
2512 | PL_bufptr += 2; |
2513 | PL_lex_state = LEX_INTERPCONCAT; | |
a0d0e21e | 2514 | } |
bbf60fe6 | 2515 | return REPORT(')'); |
79072805 | 2516 | } |
3280af22 NIS |
2517 | if (PL_bufptr != PL_bufend) |
2518 | PL_bufptr += 2; | |
2519 | PL_lex_state = LEX_INTERPCONCAT; | |
cea2e8a9 | 2520 | return yylex(); |
79072805 LW |
2521 | } |
2522 | else { | |
607df283 | 2523 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
b6007c36 | 2524 | "### Saw case modifier\n"); }); |
3280af22 | 2525 | s = PL_bufptr + 1; |
6e909404 JH |
2526 | if (s[1] == '\\' && s[2] == 'E') { |
2527 | PL_bufptr = s + 3; | |
2528 | PL_lex_state = LEX_INTERPCONCAT; | |
2529 | return yylex(); | |
a0d0e21e | 2530 | } |
6e909404 | 2531 | else { |
90771dc0 | 2532 | I32 tmp; |
6e909404 JH |
2533 | if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3)) |
2534 | tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */ | |
3792a11b | 2535 | if ((*s == 'L' || *s == 'U') && |
6e909404 JH |
2536 | (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) { |
2537 | PL_lex_casestack[--PL_lex_casemods] = '\0'; | |
bbf60fe6 | 2538 | return REPORT(')'); |
6e909404 JH |
2539 | } |
2540 | if (PL_lex_casemods > 10) | |
2541 | Renew(PL_lex_casestack, PL_lex_casemods + 2, char); | |
2542 | PL_lex_casestack[PL_lex_casemods++] = *s; | |
2543 | PL_lex_casestack[PL_lex_casemods] = '\0'; | |
2544 | PL_lex_state = LEX_INTERPCONCAT; | |
2545 | PL_nextval[PL_nexttoke].ival = 0; | |
2546 | force_next('('); | |
2547 | if (*s == 'l') | |
2548 | PL_nextval[PL_nexttoke].ival = OP_LCFIRST; | |
2549 | else if (*s == 'u') | |
2550 | PL_nextval[PL_nexttoke].ival = OP_UCFIRST; | |
2551 | else if (*s == 'L') | |
2552 | PL_nextval[PL_nexttoke].ival = OP_LC; | |
2553 | else if (*s == 'U') | |
2554 | PL_nextval[PL_nexttoke].ival = OP_UC; | |
2555 | else if (*s == 'Q') | |
2556 | PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA; | |
2557 | else | |
2558 | Perl_croak(aTHX_ "panic: yylex"); | |
2559 | PL_bufptr = s + 1; | |
a0d0e21e | 2560 | } |
79072805 | 2561 | force_next(FUNC); |
3280af22 NIS |
2562 | if (PL_lex_starts) { |
2563 | s = PL_bufptr; | |
2564 | PL_lex_starts = 0; | |
131b3ad0 DM |
2565 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ |
2566 | if (PL_lex_casemods == 1 && PL_lex_inpat) | |
2567 | OPERATOR(','); | |
2568 | else | |
2569 | Aop(OP_CONCAT); | |
79072805 LW |
2570 | } |
2571 | else | |
cea2e8a9 | 2572 | return yylex(); |
79072805 LW |
2573 | } |
2574 | ||
55497cff | 2575 | case LEX_INTERPPUSH: |
bbf60fe6 | 2576 | return REPORT(sublex_push()); |
55497cff | 2577 | |
79072805 | 2578 | case LEX_INTERPSTART: |
3280af22 | 2579 | if (PL_bufptr == PL_bufend) |
bbf60fe6 | 2580 | return REPORT(sublex_done()); |
607df283 | 2581 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
b6007c36 | 2582 | "### Interpolated variable\n"); }); |
3280af22 NIS |
2583 | PL_expect = XTERM; |
2584 | PL_lex_dojoin = (*PL_bufptr == '@'); | |
2585 | PL_lex_state = LEX_INTERPNORMAL; | |
2586 | if (PL_lex_dojoin) { | |
2587 | PL_nextval[PL_nexttoke].ival = 0; | |
79072805 | 2588 | force_next(','); |
a0d0e21e | 2589 | force_ident("\"", '$'); |
3280af22 | 2590 | PL_nextval[PL_nexttoke].ival = 0; |
79072805 | 2591 | force_next('$'); |
3280af22 | 2592 | PL_nextval[PL_nexttoke].ival = 0; |
79072805 | 2593 | force_next('('); |
3280af22 | 2594 | PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */ |
79072805 LW |
2595 | force_next(FUNC); |
2596 | } | |
3280af22 NIS |
2597 | if (PL_lex_starts++) { |
2598 | s = PL_bufptr; | |
131b3ad0 DM |
2599 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ |
2600 | if (!PL_lex_casemods && PL_lex_inpat) | |
2601 | OPERATOR(','); | |
2602 | else | |
2603 | Aop(OP_CONCAT); | |
79072805 | 2604 | } |
cea2e8a9 | 2605 | return yylex(); |
79072805 LW |
2606 | |
2607 | case LEX_INTERPENDMAYBE: | |
3280af22 NIS |
2608 | if (intuit_more(PL_bufptr)) { |
2609 | PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */ | |
79072805 LW |
2610 | break; |
2611 | } | |
2612 | /* FALL THROUGH */ | |
2613 | ||
2614 | case LEX_INTERPEND: | |
3280af22 NIS |
2615 | if (PL_lex_dojoin) { |
2616 | PL_lex_dojoin = FALSE; | |
2617 | PL_lex_state = LEX_INTERPCONCAT; | |
bbf60fe6 | 2618 | return REPORT(')'); |
79072805 | 2619 | } |
43a16006 | 2620 | if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl |
25da4f38 | 2621 | && SvEVALED(PL_lex_repl)) |
43a16006 | 2622 | { |
e9fa98b2 | 2623 | if (PL_bufptr != PL_bufend) |
cea2e8a9 | 2624 | Perl_croak(aTHX_ "Bad evalled substitution pattern"); |
a0714e2c | 2625 | PL_lex_repl = NULL; |
e9fa98b2 | 2626 | } |
79072805 LW |
2627 | /* FALLTHROUGH */ |
2628 | case LEX_INTERPCONCAT: | |
2629 | #ifdef DEBUGGING | |
3280af22 | 2630 | if (PL_lex_brackets) |
cea2e8a9 | 2631 | Perl_croak(aTHX_ "panic: INTERPCONCAT"); |
79072805 | 2632 | #endif |
3280af22 | 2633 | if (PL_bufptr == PL_bufend) |
bbf60fe6 | 2634 | return REPORT(sublex_done()); |
79072805 | 2635 | |
3280af22 NIS |
2636 | if (SvIVX(PL_linestr) == '\'') { |
2637 | SV *sv = newSVsv(PL_linestr); | |
2638 | if (!PL_lex_inpat) | |
76e3520e | 2639 | sv = tokeq(sv); |
3280af22 | 2640 | else if ( PL_hints & HINT_NEW_RE ) |
b3ac6de7 | 2641 | sv = new_constant(NULL, 0, "qr", sv, sv, "q"); |
79072805 | 2642 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
3280af22 | 2643 | s = PL_bufend; |
79072805 LW |
2644 | } |
2645 | else { | |
3280af22 | 2646 | s = scan_const(PL_bufptr); |
79072805 | 2647 | if (*s == '\\') |
3280af22 | 2648 | PL_lex_state = LEX_INTERPCASEMOD; |
79072805 | 2649 | else |
3280af22 | 2650 | PL_lex_state = LEX_INTERPSTART; |
79072805 LW |
2651 | } |
2652 | ||
3280af22 NIS |
2653 | if (s != PL_bufptr) { |
2654 | PL_nextval[PL_nexttoke] = yylval; | |
2655 | PL_expect = XTERM; | |
79072805 | 2656 | force_next(THING); |
131b3ad0 DM |
2657 | if (PL_lex_starts++) { |
2658 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ | |
2659 | if (!PL_lex_casemods && PL_lex_inpat) | |
2660 | OPERATOR(','); | |
2661 | else | |
2662 | Aop(OP_CONCAT); | |
2663 | } | |
79072805 | 2664 | else { |
3280af22 | 2665 | PL_bufptr = s; |
cea2e8a9 | 2666 | return yylex(); |
79072805 LW |
2667 | } |
2668 | } | |
2669 | ||
cea2e8a9 | 2670 | return yylex(); |
a0d0e21e | 2671 | case LEX_FORMLINE: |
3280af22 NIS |
2672 | PL_lex_state = LEX_NORMAL; |
2673 | s = scan_formline(PL_bufptr); | |
2674 | if (!PL_lex_formbrack) | |
a0d0e21e LW |
2675 | goto rightbracket; |
2676 | OPERATOR(';'); | |
79072805 LW |
2677 | } |
2678 | ||
3280af22 NIS |
2679 | s = PL_bufptr; |
2680 | PL_oldoldbufptr = PL_oldbufptr; | |
2681 | PL_oldbufptr = s; | |
463ee0b2 LW |
2682 | |
2683 | retry: | |
378cc40b LW |
2684 | switch (*s) { |
2685 | default: | |
7e2040f0 | 2686 | if (isIDFIRST_lazy_if(s,UTF)) |
834a4ddd | 2687 | goto keylookup; |
cea2e8a9 | 2688 | Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255); |
e929a76b LW |
2689 | case 4: |
2690 | case 26: | |
2691 | goto fake_eof; /* emulate EOF on ^D or ^Z */ | |
378cc40b | 2692 | case 0: |
3280af22 NIS |
2693 | if (!PL_rsfp) { |
2694 | PL_last_uni = 0; | |
2695 | PL_last_lop = 0; | |
c5ee2135 | 2696 | if (PL_lex_brackets) { |
0bd48802 AL |
2697 | yyerror(PL_lex_formbrack |
2698 | ? "Format not terminated" | |
2699 | : "Missing right curly or square bracket"); | |
c5ee2135 | 2700 | } |
4e553d73 | 2701 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
607df283 | 2702 | "### Tokener got EOF\n"); |
5f80b19c | 2703 | } ); |
79072805 | 2704 | TOKEN(0); |
463ee0b2 | 2705 | } |
3280af22 | 2706 | if (s++ < PL_bufend) |
a687059c | 2707 | goto retry; /* ignore stray nulls */ |
3280af22 NIS |
2708 | PL_last_uni = 0; |
2709 | PL_last_lop = 0; | |
2710 | if (!PL_in_eval && !PL_preambled) { | |
2711 | PL_preambled = TRUE; | |
2712 | sv_setpv(PL_linestr,incl_perldb()); | |
2713 | if (SvCUR(PL_linestr)) | |
396482e1 | 2714 | sv_catpvs(PL_linestr,";"); |
3280af22 NIS |
2715 | if (PL_preambleav){ |
2716 | while(AvFILLp(PL_preambleav) >= 0) { | |
2717 | SV *tmpsv = av_shift(PL_preambleav); | |
2718 | sv_catsv(PL_linestr, tmpsv); | |
396482e1 | 2719 | sv_catpvs(PL_linestr, ";"); |
91b7def8 | 2720 | sv_free(tmpsv); |
2721 | } | |
3280af22 NIS |
2722 | sv_free((SV*)PL_preambleav); |
2723 | PL_preambleav = NULL; | |
91b7def8 | 2724 | } |
3280af22 | 2725 | if (PL_minus_n || PL_minus_p) { |
396482e1 | 2726 | sv_catpvs(PL_linestr, "LINE: while (<>) {"); |
3280af22 | 2727 | if (PL_minus_l) |
396482e1 | 2728 | sv_catpvs(PL_linestr,"chomp;"); |
3280af22 | 2729 | if (PL_minus_a) { |
3280af22 | 2730 | if (PL_minus_F) { |
3792a11b NC |
2731 | if ((*PL_splitstr == '/' || *PL_splitstr == '\'' |
2732 | || *PL_splitstr == '"') | |
3280af22 | 2733 | && strchr(PL_splitstr + 1, *PL_splitstr)) |
3db68c4c | 2734 | Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr); |
54310121 | 2735 | else { |
c8ef6a4b NC |
2736 | /* "q\0${splitstr}\0" is legal perl. Yes, even NUL |
2737 | bytes can be used as quoting characters. :-) */ | |
dd374669 | 2738 | const char *splits = PL_splitstr; |
91d456ae | 2739 | sv_catpvs(PL_linestr, "our @F=split(q\0"); |
48c4c863 NC |
2740 | do { |
2741 | /* Need to \ \s */ | |
dd374669 AL |
2742 | if (*splits == '\\') |
2743 | sv_catpvn(PL_linestr, splits, 1); | |
2744 | sv_catpvn(PL_linestr, splits, 1); | |
2745 | } while (*splits++); | |
48c4c863 NC |
2746 | /* This loop will embed the trailing NUL of |
2747 | PL_linestr as the last thing it does before | |
2748 | terminating. */ | |
396482e1 | 2749 | sv_catpvs(PL_linestr, ");"); |
54310121 | 2750 | } |
2304df62 AD |
2751 | } |
2752 | else | |
396482e1 | 2753 | sv_catpvs(PL_linestr,"our @F=split(' ');"); |
2304df62 | 2754 | } |
79072805 | 2755 | } |
bc9b29db | 2756 | if (PL_minus_E) |
396482e1 GA |
2757 | sv_catpvs(PL_linestr,"use feature ':5.10';"); |
2758 | sv_catpvs(PL_linestr, "\n"); | |
3280af22 NIS |
2759 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
2760 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
bd61b366 | 2761 | PL_last_lop = PL_last_uni = NULL; |
3280af22 | 2762 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
561b68a9 | 2763 | SV * const sv = newSV(0); |
a0d0e21e LW |
2764 | |
2765 | sv_upgrade(sv, SVt_PVMG); | |
3280af22 | 2766 | sv_setsv(sv,PL_linestr); |
0ac0412a | 2767 | (void)SvIOK_on(sv); |
45977657 | 2768 | SvIV_set(sv, 0); |
36c7798d | 2769 | av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
a0d0e21e | 2770 | } |
79072805 | 2771 | goto retry; |
a687059c | 2772 | } |
e929a76b | 2773 | do { |
aa7440fb | 2774 | bof = PL_rsfp ? TRUE : FALSE; |
bd61b366 | 2775 | if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) { |
7e28d3af JH |
2776 | fake_eof: |
2777 | if (PL_rsfp) { | |
2778 | if (PL_preprocess && !PL_in_eval) | |
2779 | (void)PerlProc_pclose(PL_rsfp); | |
2780 | else if ((PerlIO *)PL_rsfp == PerlIO_stdin()) | |
2781 | PerlIO_clearerr(PL_rsfp); | |
2782 | else | |
2783 | (void)PerlIO_close(PL_rsfp); | |
4608196e | 2784 | PL_rsfp = NULL; |
7e28d3af JH |
2785 | PL_doextract = FALSE; |
2786 | } | |
2787 | if (!PL_in_eval && (PL_minus_n || PL_minus_p)) { | |
a23c4656 NC |
2788 | sv_setpv(PL_linestr,PL_minus_p |
2789 | ? ";}continue{print;}" : ";}"); | |
7e28d3af JH |
2790 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
2791 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
bd61b366 | 2792 | PL_last_lop = PL_last_uni = NULL; |
7e28d3af JH |
2793 | PL_minus_n = PL_minus_p = 0; |
2794 | goto retry; | |
2795 | } | |
2796 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); | |
bd61b366 | 2797 | PL_last_lop = PL_last_uni = NULL; |
c69006e4 | 2798 | sv_setpvn(PL_linestr,"",0); |
7e28d3af JH |
2799 | TOKEN(';'); /* not infinite loop because rsfp is NULL now */ |
2800 | } | |
7aa207d6 JH |
2801 | /* If it looks like the start of a BOM or raw UTF-16, |
2802 | * check if it in fact is. */ | |
2803 | else if (bof && | |
2804 | (*s == 0 || | |
2805 | *(U8*)s == 0xEF || | |
2806 | *(U8*)s >= 0xFE || | |
2807 | s[1] == 0)) { | |
226017aa | 2808 | #ifdef PERLIO_IS_STDIO |
e3f494f1 JH |
2809 | # ifdef __GNU_LIBRARY__ |
2810 | # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */ | |
226017aa DD |
2811 | # define FTELL_FOR_PIPE_IS_BROKEN |
2812 | # endif | |
e3f494f1 JH |
2813 | # else |
2814 | # ifdef __GLIBC__ | |
2815 | # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */ | |
2816 | # define FTELL_FOR_PIPE_IS_BROKEN | |
2817 | # endif | |
2818 | # endif | |
226017aa DD |
2819 | # endif |
2820 | #endif | |
2821 | #ifdef FTELL_FOR_PIPE_IS_BROKEN | |
2822 | /* This loses the possibility to detect the bof | |
2823 | * situation on perl -P when the libc5 is being used. | |
2824 | * Workaround? Maybe attach some extra state to PL_rsfp? | |
2825 | */ | |
2826 | if (!PL_preprocess) | |
7e28d3af | 2827 | bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr); |
226017aa | 2828 | #else |
eb160463 | 2829 | bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr); |
226017aa | 2830 | #endif |
7e28d3af | 2831 | if (bof) { |
3280af22 | 2832 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
7e28d3af | 2833 | s = swallow_bom((U8*)s); |
e929a76b | 2834 | } |
378cc40b | 2835 | } |
3280af22 | 2836 | if (PL_doextract) { |
a0d0e21e LW |
2837 | /* Incest with pod. */ |
2838 | if (*s == '=' && strnEQ(s, "=cut", 4)) { | |
c69006e4 | 2839 | sv_setpvn(PL_linestr, "", 0); |
3280af22 NIS |
2840 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
2841 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
bd61b366 | 2842 | PL_last_lop = PL_last_uni = NULL; |
3280af22 | 2843 | PL_doextract = FALSE; |
a0d0e21e | 2844 | } |
4e553d73 | 2845 | } |
463ee0b2 | 2846 | incline(s); |
3280af22 NIS |
2847 | } while (PL_doextract); |
2848 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s; | |
2849 | if (PERLDB_LINE && PL_curstash != PL_debstash) { | |
561b68a9 | 2850 | SV * const sv = newSV(0); |
a687059c | 2851 | |
93a17b20 | 2852 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 2853 | sv_setsv(sv,PL_linestr); |
0ac0412a | 2854 | (void)SvIOK_on(sv); |
45977657 | 2855 | SvIV_set(sv, 0); |
36c7798d | 2856 | av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
a687059c | 2857 | } |
3280af22 | 2858 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
bd61b366 | 2859 | PL_last_lop = PL_last_uni = NULL; |
57843af0 | 2860 | if (CopLINE(PL_curcop) == 1) { |
3280af22 | 2861 | while (s < PL_bufend && isSPACE(*s)) |
79072805 | 2862 | s++; |
a0d0e21e | 2863 | if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */ |
79072805 | 2864 | s++; |
bd61b366 | 2865 | d = NULL; |
3280af22 | 2866 | if (!PL_in_eval) { |
44a8e56a | 2867 | if (*s == '#' && *(s+1) == '!') |
2868 | d = s + 2; | |
2869 | #ifdef ALTERNATE_SHEBANG | |
2870 | else { | |
bfed75c6 | 2871 | static char const as[] = ALTERNATE_SHEBANG; |
44a8e56a | 2872 | if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1)) |
2873 | d = s + (sizeof(as) - 1); | |
2874 | } | |
2875 | #endif /* ALTERNATE_SHEBANG */ | |
2876 | } | |
2877 | if (d) { | |
b8378b72 | 2878 | char *ipath; |
774d564b | 2879 | char *ipathend; |
b8378b72 | 2880 | |
774d564b | 2881 | while (isSPACE(*d)) |
b8378b72 CS |
2882 | d++; |
2883 | ipath = d; | |
774d564b | 2884 | while (*d && !isSPACE(*d)) |
2885 | d++; | |
2886 | ipathend = d; | |
2887 | ||
2888 | #ifdef ARG_ZERO_IS_SCRIPT | |
2889 | if (ipathend > ipath) { | |
2890 | /* | |
2891 | * HP-UX (at least) sets argv[0] to the script name, | |
2892 | * which makes $^X incorrect. And Digital UNIX and Linux, | |
2893 | * at least, set argv[0] to the basename of the Perl | |
2894 | * interpreter. So, having found "#!", we'll set it right. | |
2895 | */ | |
fafc274c NC |
2896 | SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL, |
2897 | SVt_PV)); /* $^X */ | |
774d564b | 2898 | assert(SvPOK(x) || SvGMAGICAL(x)); |
cc49e20b | 2899 | if (sv_eq(x, CopFILESV(PL_curcop))) { |
774d564b | 2900 | sv_setpvn(x, ipath, ipathend - ipath); |
9607fc9c | 2901 | SvSETMAGIC(x); |
2902 | } | |
556c1dec JH |
2903 | else { |
2904 | STRLEN blen; | |
2905 | STRLEN llen; | |
cfd0369c | 2906 | const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen); |
9d4ba2ae | 2907 | const char * const lstart = SvPV_const(x,llen); |
556c1dec JH |
2908 | if (llen < blen) { |
2909 | bstart += blen - llen; | |
2910 | if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') { | |
2911 | sv_setpvn(x, ipath, ipathend - ipath); | |
2912 | SvSETMAGIC(x); | |
2913 | } | |
2914 | } | |
2915 | } | |
774d564b | 2916 | TAINT_NOT; /* $^X is always tainted, but that's OK */ |
8ebc5c01 | 2917 | } |
774d564b | 2918 | #endif /* ARG_ZERO_IS_SCRIPT */ |
b8378b72 CS |
2919 | |
2920 | /* | |
2921 | * Look for options. | |
2922 | */ | |
748a9306 | 2923 | d = instr(s,"perl -"); |
84e30d1a | 2924 | if (!d) { |
748a9306 | 2925 | d = instr(s,"perl"); |
84e30d1a GS |
2926 | #if defined(DOSISH) |
2927 | /* avoid getting into infinite loops when shebang | |
2928 | * line contains "Perl" rather than "perl" */ | |
2929 | if (!d) { | |
2930 | for (d = ipathend-4; d >= ipath; --d) { | |
2931 | if ((*d == 'p' || *d == 'P') | |
2932 | && !ibcmp(d, "perl", 4)) | |
2933 | { | |
2934 | break; | |
2935 | } | |
2936 | } | |
2937 | if (d < ipath) | |
bd61b366 | 2938 | d = NULL; |
84e30d1a GS |
2939 | } |
2940 | #endif | |
2941 | } | |
44a8e56a | 2942 | #ifdef ALTERNATE_SHEBANG |
2943 | /* | |
2944 | * If the ALTERNATE_SHEBANG on this system starts with a | |
2945 | * character that can be part of a Perl expression, then if | |
2946 | * we see it but not "perl", we're probably looking at the | |
2947 | * start of Perl code, not a request to hand off to some | |
2948 | * other interpreter. Similarly, if "perl" is there, but | |
2949 | * not in the first 'word' of the line, we assume the line | |
2950 | * contains the start of the Perl program. | |
44a8e56a | 2951 | */ |
2952 | if (d && *s != '#') { | |
f54cb97a | 2953 | const char *c = ipath; |
44a8e56a | 2954 | while (*c && !strchr("; \t\r\n\f\v#", *c)) |
2955 | c++; | |
2956 | if (c < d) | |
bd61b366 | 2957 | d = NULL; /* "perl" not in first word; ignore */ |
44a8e56a | 2958 | else |
2959 | *s = '#'; /* Don't try to parse shebang line */ | |
2960 | } | |
774d564b | 2961 | #endif /* ALTERNATE_SHEBANG */ |
bf4acbe4 | 2962 | #ifndef MACOS_TRADITIONAL |
748a9306 | 2963 | if (!d && |
44a8e56a | 2964 | *s == '#' && |
774d564b | 2965 | ipathend > ipath && |
3280af22 | 2966 | !PL_minus_c && |
748a9306 | 2967 | !instr(s,"indir") && |
3280af22 | 2968 | instr(PL_origargv[0],"perl")) |
748a9306 | 2969 | { |
27da23d5 | 2970 | dVAR; |
9f68db38 | 2971 | char **newargv; |
9f68db38 | 2972 | |
774d564b | 2973 | *ipathend = '\0'; |
2974 | s = ipathend + 1; | |
3280af22 | 2975 | while (s < PL_bufend && isSPACE(*s)) |
9f68db38 | 2976 | s++; |
3280af22 | 2977 | if (s < PL_bufend) { |
a02a5408 | 2978 | Newxz(newargv,PL_origargc+3,char*); |
9f68db38 | 2979 | newargv[1] = s; |
3280af22 | 2980 | while (s < PL_bufend && !isSPACE(*s)) |
9f68db38 LW |
2981 | s++; |
2982 | *s = '\0'; | |
3280af22 | 2983 | Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*); |
9f68db38 LW |
2984 | } |
2985 | else | |
3280af22 | 2986 | newargv = PL_origargv; |
774d564b | 2987 | newargv[0] = ipath; |
b35112e7 | 2988 | PERL_FPU_PRE_EXEC |
b4748376 | 2989 | PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv)); |
b35112e7 | 2990 | PERL_FPU_POST_EXEC |
cea2e8a9 | 2991 | Perl_croak(aTHX_ "Can't exec %s", ipath); |
9f68db38 | 2992 | } |
bf4acbe4 | 2993 | #endif |
748a9306 | 2994 | if (d) { |
748a9306 | 2995 | while (*d && !isSPACE(*d)) d++; |
bf4acbe4 | 2996 | while (SPACE_OR_TAB(*d)) d++; |
748a9306 LW |
2997 | |
2998 | if (*d++ == '-') { | |
f54cb97a | 2999 | const bool switches_done = PL_doswitches; |
fb993905 GA |
3000 | const U32 oldpdb = PL_perldb; |
3001 | const bool oldn = PL_minus_n; | |
3002 | const bool oldp = PL_minus_p; | |
3003 | ||
8cc95fdb | 3004 | do { |
3ffe3ee4 | 3005 | if (*d == 'M' || *d == 'm' || *d == 'C') { |
9d4ba2ae | 3006 | const char * const m = d; |
8cc95fdb | 3007 | while (*d && !isSPACE(*d)) d++; |
cea2e8a9 | 3008 | Perl_croak(aTHX_ "Too late for \"-%.*s\" option", |
8cc95fdb | 3009 | (int)(d - m), m); |
3010 | } | |
97bd5664 | 3011 | d = moreswitches(d); |
8cc95fdb | 3012 | } while (d); |
f0b2cf55 YST |
3013 | if (PL_doswitches && !switches_done) { |
3014 | int argc = PL_origargc; | |
3015 | char **argv = PL_origargv; | |
3016 | do { | |
3017 | argc--,argv++; | |
3018 | } while (argc && argv[0][0] == '-' && argv[0][1]); | |
3019 | init_argv_symbols(argc,argv); | |
3020 | } | |
155aba94 GS |
3021 | if ((PERLDB_LINE && !oldpdb) || |
3022 | ((PL_minus_n || PL_minus_p) && !(oldn || oldp))) | |
b084f20b | 3023 | /* if we have already added "LINE: while (<>) {", |
3024 | we must not do it again */ | |
748a9306 | 3025 | { |
c69006e4 | 3026 | sv_setpvn(PL_linestr, "", 0); |
3280af22 NIS |
3027 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
3028 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
bd61b366 | 3029 | PL_last_lop = PL_last_uni = NULL; |
3280af22 | 3030 | PL_preambled = FALSE; |
84902520 | 3031 | if (PERLDB_LINE) |
3280af22 | 3032 | (void)gv_fetchfile(PL_origfilename); |
748a9306 LW |
3033 | goto retry; |
3034 | } | |
a0d0e21e | 3035 | } |
79072805 | 3036 | } |
9f68db38 | 3037 | } |
79072805 | 3038 | } |
3280af22 NIS |
3039 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
3040 | PL_bufptr = s; | |
3041 | PL_lex_state = LEX_FORMLINE; | |
cea2e8a9 | 3042 | return yylex(); |
ae986130 | 3043 | } |
378cc40b | 3044 | goto retry; |
4fdae800 | 3045 | case '\r': |
6a27c188 | 3046 | #ifdef PERL_STRICT_CR |
cea2e8a9 | 3047 | Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r'); |
4e553d73 | 3048 | Perl_croak(aTHX_ |
cc507455 | 3049 | "\t(Maybe you didn't strip carriage returns after a network transfer?)\n"); |
a868473f | 3050 | #endif |
4fdae800 | 3051 | case ' ': case '\t': case '\f': case 013: |
bf4acbe4 GS |
3052 | #ifdef MACOS_TRADITIONAL |
3053 | case '\312': | |
3054 | #endif | |
378cc40b LW |
3055 | s++; |
3056 | goto retry; | |
378cc40b | 3057 | case '#': |
e929a76b | 3058 | case '\n': |
3280af22 | 3059 | if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) { |
df0deb90 GS |
3060 | if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) { |
3061 | /* handle eval qq[#line 1 "foo"\n ...] */ | |
3062 | CopLINE_dec(PL_curcop); | |
3063 | incline(s); | |
3064 | } | |
3280af22 | 3065 | d = PL_bufend; |
a687059c | 3066 | while (s < d && *s != '\n') |
378cc40b | 3067 | s++; |
0f85fab0 | 3068 | if (s < d) |
378cc40b | 3069 | s++; |
78c267c1 | 3070 | else if (s > d) /* Found by Ilya: feed random input to Perl. */ |
a8406387 | 3071 | Perl_croak(aTHX_ "panic: input overflow"); |
463ee0b2 | 3072 | incline(s); |
3280af22 NIS |
3073 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
3074 | PL_bufptr = s; | |
3075 | PL_lex_state = LEX_FORMLINE; | |
cea2e8a9 | 3076 | return yylex(); |
a687059c | 3077 | } |
378cc40b | 3078 | } |
a687059c | 3079 | else { |
378cc40b | 3080 | *s = '\0'; |
3280af22 | 3081 | PL_bufend = s; |
a687059c | 3082 | } |
378cc40b LW |
3083 | goto retry; |
3084 | case '-': | |
79072805 | 3085 | if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) { |
e5edeb50 | 3086 | I32 ftst = 0; |
90771dc0 | 3087 | char tmp; |
e5edeb50 | 3088 | |
378cc40b | 3089 | s++; |
3280af22 | 3090 | PL_bufptr = s; |
748a9306 LW |
3091 | tmp = *s++; |
3092 | ||
bf4acbe4 | 3093 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
748a9306 LW |
3094 | s++; |
3095 | ||
3096 | if (strnEQ(s,"=>",2)) { | |
3280af22 | 3097 | s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE); |
b6007c36 DM |
3098 | DEBUG_T( { S_printbuf(aTHX_ |
3099 | "### Saw unary minus before =>, forcing word %s\n", s); | |
5f80b19c | 3100 | } ); |
748a9306 LW |
3101 | OPERATOR('-'); /* unary minus */ |
3102 | } | |
3280af22 | 3103 | PL_last_uni = PL_oldbufptr; |
748a9306 | 3104 | switch (tmp) { |
e5edeb50 JH |
3105 | case 'r': ftst = OP_FTEREAD; break; |
3106 | case 'w': ftst = OP_FTEWRITE; break; | |
3107 | case 'x': ftst = OP_FTEEXEC; break; | |
3108 | case 'o': ftst = OP_FTEOWNED; break; | |
3109 | case 'R': ftst = OP_FTRREAD; break; | |
3110 | case 'W': ftst = OP_FTRWRITE; break; | |
3111 | case 'X': ftst = OP_FTREXEC; break; | |
3112 | case 'O': ftst = OP_FTROWNED; break; | |
3113 | case 'e': ftst = OP_FTIS; break; | |
3114 | case 'z': ftst = OP_FTZERO; break; | |
3115 | case 's': ftst = OP_FTSIZE; break; | |
3116 | case 'f': ftst = OP_FTFILE; break; | |
3117 | case 'd': ftst = OP_FTDIR; break; | |
3118 | case 'l': ftst = OP_FTLINK; break; | |
3119 | case 'p': ftst = OP_FTPIPE; break; | |
3120 | case 'S': ftst = OP_FTSOCK; break; | |
3121 | case 'u': ftst = OP_FTSUID; break; | |
3122 | case 'g': ftst = OP_FTSGID; break; | |
3123 | case 'k': ftst = OP_FTSVTX; break; | |
3124 | case 'b': ftst = OP_FTBLK; break; | |
3125 | case 'c': ftst = OP_FTCHR; break; | |
3126 | case 't': ftst = OP_FTTTY; break; | |
3127 | case 'T': ftst = OP_FTTEXT; break; | |
3128 | case 'B': ftst = OP_FTBINARY; break; | |
3129 | case 'M': case 'A': case 'C': | |
fafc274c | 3130 | gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV); |
e5edeb50 JH |
3131 | switch (tmp) { |
3132 | case 'M': ftst = OP_FTMTIME; break; | |
3133 | case 'A': ftst = OP_FTATIME; break; | |
3134 | case 'C': ftst = OP_FTCTIME; break; | |
3135 | default: break; | |
3136 | } | |
3137 | break; | |
378cc40b | 3138 | default: |
378cc40b LW |
3139 | break; |
3140 | } | |
e5edeb50 | 3141 | if (ftst) { |
eb160463 | 3142 | PL_last_lop_op = (OPCODE)ftst; |
4e553d73 | 3143 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
a18d764d | 3144 | "### Saw file test %c\n", (int)tmp); |
5f80b19c | 3145 | } ); |
e5edeb50 JH |
3146 | FTST(ftst); |
3147 | } | |
3148 | else { | |
3149 | /* Assume it was a minus followed by a one-letter named | |
3150 | * subroutine call (or a -bareword), then. */ | |
95c31fe3 | 3151 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
17ad61e0 | 3152 | "### '-%c' looked like a file test but was not\n", |
4fccd7c6 | 3153 | (int) tmp); |
5f80b19c | 3154 | } ); |
3cf7b4c4 | 3155 | s = --PL_bufptr; |
e5edeb50 | 3156 | } |
378cc40b | 3157 | } |
90771dc0 NC |
3158 | { |
3159 | const char tmp = *s++; | |
3160 | if (*s == tmp) { | |
3161 | s++; | |
3162 | if (PL_expect == XOPERATOR) | |
3163 | TERM(POSTDEC); | |
3164 | else | |
3165 | OPERATOR(PREDEC); | |
3166 | } | |
3167 | else if (*s == '>') { | |
3168 | s++; | |
3169 | s = skipspace(s); | |
3170 | if (isIDFIRST_lazy_if(s,UTF)) { | |
3171 | s = force_word(s,METHOD,FALSE,TRUE,FALSE); | |
3172 | TOKEN(ARROW); | |
3173 | } | |
3174 | else if (*s == '$') | |
3175 | OPERATOR(ARROW); | |
3176 | else | |
3177 | TERM(ARROW); | |
3178 | } | |
3280af22 | 3179 | if (PL_expect == XOPERATOR) |
90771dc0 NC |
3180 | Aop(OP_SUBTRACT); |
3181 | else { | |
3182 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) | |
3183 | check_uni(); | |
3184 | OPERATOR('-'); /* unary minus */ | |
79072805 | 3185 | } |
2f3197b3 | 3186 | } |
79072805 | 3187 | |
378cc40b | 3188 | case '+': |
90771dc0 NC |
3189 | { |
3190 | const char tmp = *s++; | |
3191 | if (*s == tmp) { | |
3192 | s++; | |
3193 | if (PL_expect == XOPERATOR) | |
3194 | TERM(POSTINC); | |
3195 | else | |
3196 | OPERATOR(PREINC); | |
3197 | } | |
3280af22 | 3198 | if (PL_expect == XOPERATOR) |
90771dc0 NC |
3199 | Aop(OP_ADD); |
3200 | else { | |
3201 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) | |
3202 | check_uni(); | |
3203 | OPERATOR('+'); | |
3204 | } | |
2f3197b3 | 3205 | } |
a687059c | 3206 | |
378cc40b | 3207 | case '*': |
3280af22 NIS |
3208 | if (PL_expect != XOPERATOR) { |
3209 | s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); | |
3210 | PL_expect = XOPERATOR; | |
3211 | force_ident(PL_tokenbuf, '*'); | |
3212 | if (!*PL_tokenbuf) | |
a0d0e21e | 3213 | PREREF('*'); |
79072805 | 3214 | TERM('*'); |
a687059c | 3215 | } |
79072805 LW |
3216 | s++; |
3217 | if (*s == '*') { | |
a687059c | 3218 | s++; |
79072805 | 3219 | PWop(OP_POW); |
a687059c | 3220 | } |
79072805 LW |
3221 | Mop(OP_MULTIPLY); |
3222 | ||
378cc40b | 3223 | case '%': |
3280af22 | 3224 | if (PL_expect == XOPERATOR) { |
bbce6d69 | 3225 | ++s; |
3226 | Mop(OP_MODULO); | |
a687059c | 3227 | } |
3280af22 NIS |
3228 | PL_tokenbuf[0] = '%'; |
3229 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE); | |
3230 | if (!PL_tokenbuf[1]) { | |
bbce6d69 | 3231 | PREREF('%'); |
a687059c | 3232 | } |
3280af22 | 3233 | PL_pending_ident = '%'; |
bbce6d69 | 3234 | TERM('%'); |
a687059c | 3235 | |
378cc40b | 3236 | case '^': |
79072805 | 3237 | s++; |
a0d0e21e | 3238 | BOop(OP_BIT_XOR); |
79072805 | 3239 | case '[': |
3280af22 | 3240 | PL_lex_brackets++; |
79072805 | 3241 | /* FALL THROUGH */ |
378cc40b | 3242 | case '~': |
0d863452 RH |
3243 | if (s[1] == '~' |
3244 | && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR) | |
ef89dcc3 | 3245 | && FEATURE_IS_ENABLED("~~")) |
0d863452 RH |
3246 | { |
3247 | s += 2; | |
3248 | Eop(OP_SMARTMATCH); | |
3249 | } | |
378cc40b | 3250 | case ',': |
90771dc0 NC |
3251 | { |
3252 | const char tmp = *s++; | |
3253 | OPERATOR(tmp); | |
3254 | } | |
a0d0e21e LW |
3255 | case ':': |
3256 | if (s[1] == ':') { | |
3257 | len = 0; | |
0bfa2a8a | 3258 | goto just_a_word_zero_gv; |
a0d0e21e LW |
3259 | } |
3260 | s++; | |
09bef843 SB |
3261 | switch (PL_expect) { |
3262 | OP *attrs; | |
3263 | case XOPERATOR: | |
3264 | if (!PL_in_my || PL_lex_state != LEX_NORMAL) | |
3265 | break; | |
3266 | PL_bufptr = s; /* update in case we back off */ | |
3267 | goto grabattrs; | |
3268 | case XATTRBLOCK: | |
3269 | PL_expect = XBLOCK; | |
3270 | goto grabattrs; | |
3271 | case XATTRTERM: | |
3272 | PL_expect = XTERMBLOCK; | |
3273 | grabattrs: | |
3274 | s = skipspace(s); | |
5f66b61c | 3275 | attrs = NULL; |
7e2040f0 | 3276 | while (isIDFIRST_lazy_if(s,UTF)) { |
90771dc0 | 3277 | I32 tmp; |
09bef843 | 3278 | d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
f9829d6b GS |
3279 | if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) { |
3280 | if (tmp < 0) tmp = -tmp; | |
3281 | switch (tmp) { | |
3282 | case KEY_or: | |
3283 | case KEY_and: | |
c963b151 | 3284 | case KEY_err: |
f9829d6b GS |
3285 | case KEY_for: |
3286 | case KEY_unless: | |
3287 | case KEY_if: | |
3288 | case KEY_while: | |
3289 | case KEY_until: | |
3290 | goto got_attrs; | |
3291 | default: | |
3292 | break; | |
3293 | } | |
3294 | } | |
09bef843 SB |
3295 | if (*d == '(') { |
3296 | d = scan_str(d,TRUE,TRUE); | |
3297 | if (!d) { | |
09bef843 SB |
3298 | /* MUST advance bufptr here to avoid bogus |
3299 | "at end of line" context messages from yyerror(). | |
3300 | */ | |
3301 | PL_bufptr = s + len; | |
3302 | yyerror("Unterminated attribute parameter in attribute list"); | |
3303 | if (attrs) | |
3304 | op_free(attrs); | |
bbf60fe6 | 3305 | return REPORT(0); /* EOF indicator */ |
09bef843 SB |
3306 | } |
3307 | } | |
3308 | if (PL_lex_stuff) { | |
3309 | SV *sv = newSVpvn(s, len); | |
3310 | sv_catsv(sv, PL_lex_stuff); | |
3311 | attrs = append_elem(OP_LIST, attrs, | |
3312 | newSVOP(OP_CONST, 0, sv)); | |
3313 | SvREFCNT_dec(PL_lex_stuff); | |
a0714e2c | 3314 | PL_lex_stuff = NULL; |
09bef843 SB |
3315 | } |
3316 | else { | |
371fce9b DM |
3317 | if (len == 6 && strnEQ(s, "unique", len)) { |
3318 | if (PL_in_my == KEY_our) | |
3319 | #ifdef USE_ITHREADS | |
3320 | GvUNIQUE_on(cGVOPx_gv(yylval.opval)); | |
3321 | #else | |
bb263b4e | 3322 | /*EMPTY*/; /* skip to avoid loading attributes.pm */ |
371fce9b | 3323 | #endif |
bfed75c6 | 3324 | else |
371fce9b DM |
3325 | Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables"); |
3326 | } | |
3327 | ||
d3cea301 SB |
3328 | /* NOTE: any CV attrs applied here need to be part of |
3329 | the CVf_BUILTIN_ATTRS define in cv.h! */ | |
371fce9b | 3330 | else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len)) |
78f9721b SM |
3331 | CvLVALUE_on(PL_compcv); |
3332 | else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len)) | |
3333 | CvLOCKED_on(PL_compcv); | |
3334 | else if (!PL_in_my && len == 6 && strnEQ(s, "method", len)) | |
3335 | CvMETHOD_on(PL_compcv); | |
06492da6 SF |
3336 | else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len)) |
3337 | CvASSERTION_on(PL_compcv); | |
78f9721b SM |
3338 | /* After we've set the flags, it could be argued that |
3339 | we don't need to do the attributes.pm-based setting | |
3340 | process, and shouldn't bother appending recognized | |
d3cea301 SB |
3341 | flags. To experiment with that, uncomment the |
3342 | following "else". (Note that's already been | |
3343 | uncommented. That keeps the above-applied built-in | |
3344 | attributes from being intercepted (and possibly | |
3345 | rejected) by a package's attribute routines, but is | |
3346 | justified by the performance win for the common case | |
3347 | of applying only built-in attributes.) */ | |
0256094b | 3348 | else |
78f9721b SM |
3349 | attrs = append_elem(OP_LIST, attrs, |
3350 | newSVOP(OP_CONST, 0, | |
3351 | newSVpvn(s, len))); | |
09bef843 SB |
3352 | } |
3353 | s = skipspace(d); | |
0120eecf | 3354 | if (*s == ':' && s[1] != ':') |
09bef843 | 3355 | s = skipspace(s+1); |
0120eecf GS |
3356 | else if (s == d) |
3357 | break; /* require real whitespace or :'s */ | |
09bef843 | 3358 | } |
90771dc0 NC |
3359 | { |
3360 | const char tmp | |
3361 | = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */ | |
3362 | if (*s != ';' && *s != '}' && *s != tmp | |
3363 | && (tmp != '=' || *s != ')')) { | |
3364 | const char q = ((*s == '\'') ? '"' : '\''); | |
3365 | /* If here for an expression, and parsed no attrs, back | |
3366 | off. */ | |
3367 | if (tmp == '=' && !attrs) { | |
3368 | s = PL_bufptr; | |
3369 | break; | |
3370 | } | |
3371 | /* MUST advance bufptr here to avoid bogus "at end of line" | |
3372 | context messages from yyerror(). | |
3373 | */ | |
3374 | PL_bufptr = s; | |
3375 | yyerror( *s | |
3376 | ? Perl_form(aTHX_ "Invalid separator character " | |
3377 | "%c%c%c in attribute list", q, *s, q) | |
3378 | : "Unterminated attribute list" ); | |
3379 | if (attrs) | |
3380 | op_free(attrs); | |
3381 | OPERATOR(':'); | |
09bef843 | 3382 | } |
09bef843 | 3383 | } |
f9829d6b | 3384 | got_attrs: |
09bef843 SB |
3385 | if (attrs) { |
3386 | PL_nextval[PL_nexttoke].opval = attrs; | |
3387 | force_next(THING); | |
3388 | } | |
3389 | TOKEN(COLONATTR); | |
3390 | } | |
a0d0e21e | 3391 | OPERATOR(':'); |
8990e307 LW |
3392 | case '(': |
3393 | s++; | |
3280af22 NIS |
3394 | if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr) |
3395 | PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */ | |
a0d0e21e | 3396 | else |
3280af22 | 3397 | PL_expect = XTERM; |
4a202259 | 3398 | s = skipspace(s); |
a0d0e21e | 3399 | TOKEN('('); |
378cc40b | 3400 | case ';': |
f4dd75d9 | 3401 | CLINE; |
90771dc0 NC |
3402 | { |
3403 | const char tmp = *s++; | |
3404 | OPERATOR(tmp); | |
3405 | } | |
378cc40b | 3406 | case ')': |
90771dc0 NC |
3407 | { |
3408 | const char tmp = *s++; | |
3409 | s = skipspace(s); | |
3410 | if (*s == '{') | |
3411 | PREBLOCK(tmp); | |
3412 | TERM(tmp); | |
3413 | } | |
79072805 LW |
3414 | case ']': |
3415 | s++; | |
3280af22 | 3416 | if (PL_lex_brackets <= 0) |
d98d5fff | 3417 | yyerror("Unmatched right square bracket"); |
463ee0b2 | 3418 | else |
3280af22 NIS |
3419 | --PL_lex_brackets; |
3420 | if (PL_lex_state == LEX_INTERPNORMAL) { | |
3421 | if (PL_lex_brackets == 0) { | |
a0d0e21e | 3422 | if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>')) |
3280af22 | 3423 | PL_lex_state = LEX_INTERPEND; |
79072805 LW |
3424 | } |
3425 | } | |
4633a7c4 | 3426 | TERM(']'); |
79072805 LW |
3427 | case '{': |
3428 | leftbracket: | |
79072805 | 3429 | s++; |
3280af22 | 3430 | if (PL_lex_brackets > 100) { |
8edd5f42 | 3431 | Renew(PL_lex_brackstack, PL_lex_brackets + 10, char); |
8990e307 | 3432 | } |
3280af22 | 3433 | switch (PL_expect) { |
a0d0e21e | 3434 | case XTERM: |
3280af22 | 3435 | if (PL_lex_formbrack) { |
a0d0e21e LW |
3436 | s--; |
3437 | PRETERMBLOCK(DO); | |
3438 | } | |
3280af22 NIS |
3439 | if (PL_oldoldbufptr == PL_last_lop) |
3440 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; | |
a0d0e21e | 3441 | else |
3280af22 | 3442 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
79072805 | 3443 | OPERATOR(HASHBRACK); |
a0d0e21e | 3444 | case XOPERATOR: |
bf4acbe4 | 3445 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
748a9306 | 3446 | s++; |
44a8e56a | 3447 | d = s; |
3280af22 NIS |
3448 | PL_tokenbuf[0] = '\0'; |
3449 | if (d < PL_bufend && *d == '-') { | |
3450 | PL_tokenbuf[0] = '-'; | |
44a8e56a | 3451 | d++; |
bf4acbe4 | 3452 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
44a8e56a | 3453 | d++; |
3454 | } | |
7e2040f0 | 3455 | if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) { |
3280af22 | 3456 | d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, |
8903cb82 | 3457 | FALSE, &len); |
bf4acbe4 | 3458 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
748a9306 LW |
3459 | d++; |
3460 | if (*d == '}') { | |
f54cb97a | 3461 | const char minus = (PL_tokenbuf[0] == '-'); |
44a8e56a | 3462 | s = force_word(s + minus, WORD, FALSE, TRUE, FALSE); |
3463 | if (minus) | |
3464 | force_next('-'); | |
748a9306 LW |
3465 | } |
3466 | } | |
3467 | /* FALL THROUGH */ | |
09bef843 | 3468 | case XATTRBLOCK: |
748a9306 | 3469 | case XBLOCK: |
3280af22 NIS |
3470 | PL_lex_brackstack[PL_lex_brackets++] = XSTATE; |
3471 | PL_expect = XSTATE; | |
a0d0e21e | 3472 | break; |
09bef843 | 3473 | case XATTRTERM: |
a0d0e21e | 3474 | case XTERMBLOCK: |
3280af22 NIS |
3475 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
3476 | PL_expect = XSTATE; | |
a0d0e21e LW |
3477 | break; |
3478 | default: { | |
f54cb97a | 3479 | const char *t; |
3280af22 NIS |
3480 | if (PL_oldoldbufptr == PL_last_lop) |
3481 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; | |
a0d0e21e | 3482 | else |
3280af22 | 3483 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
a0d0e21e | 3484 | s = skipspace(s); |
8452ff4b SB |
3485 | if (*s == '}') { |
3486 | if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) { | |
3487 | PL_expect = XTERM; | |
3488 | /* This hack is to get the ${} in the message. */ | |
3489 | PL_bufptr = s+1; | |
3490 | yyerror("syntax error"); | |
3491 | break; | |
3492 | } | |
a0d0e21e | 3493 | OPERATOR(HASHBRACK); |
8452ff4b | 3494 | } |
b8a4b1be GS |
3495 | /* This hack serves to disambiguate a pair of curlies |
3496 | * as being a block or an anon hash. Normally, expectation | |
3497 | * determines that, but in cases where we're not in a | |
3498 | * position to expect anything in particular (like inside | |
3499 | * eval"") we have to resolve the ambiguity. This code | |
3500 | * covers the case where the first term in the curlies is a | |
3501 | * quoted string. Most other cases need to be explicitly | |
a0288114 | 3502 | * disambiguated by prepending a "+" before the opening |
b8a4b1be GS |
3503 | * curly in order to force resolution as an anon hash. |
3504 | * | |
3505 | * XXX should probably propagate the outer expectation | |
3506 | * into eval"" to rely less on this hack, but that could | |
3507 | * potentially break current behavior of eval"". | |
3508 | * GSAR 97-07-21 | |
3509 | */ | |
3510 | t = s; | |
3511 | if (*s == '\'' || *s == '"' || *s == '`') { | |
3512 | /* common case: get past first string, handling escapes */ | |
3280af22 | 3513 | for (t++; t < PL_bufend && *t != *s;) |
b8a4b1be GS |
3514 | if (*t++ == '\\' && (*t == '\\' || *t == *s)) |
3515 | t++; | |
3516 | t++; | |
a0d0e21e | 3517 | } |
b8a4b1be | 3518 | else if (*s == 'q') { |
3280af22 | 3519 | if (++t < PL_bufend |
b8a4b1be | 3520 | && (!isALNUM(*t) |
3280af22 | 3521 | || ((*t == 'q' || *t == 'x') && ++t < PL_bufend |
0505442f GS |
3522 | && !isALNUM(*t)))) |
3523 | { | |
abc667d1 | 3524 | /* skip q//-like construct */ |
f54cb97a | 3525 | const char *tmps; |
b8a4b1be GS |
3526 | char open, close, term; |
3527 | I32 brackets = 1; | |
3528 | ||
3280af22 | 3529 | while (t < PL_bufend && isSPACE(*t)) |
b8a4b1be | 3530 | t++; |
abc667d1 DM |
3531 | /* check for q => */ |
3532 | if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') { | |
3533 | OPERATOR(HASHBRACK); | |
3534 | } | |
b8a4b1be GS |
3535 | term = *t; |
3536 | open = term; | |
3537 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) | |
3538 | term = tmps[5]; | |
3539 | close = term; | |
3540 | if (open == close) | |
3280af22 NIS |
3541 | for (t++; t < PL_bufend; t++) { |
3542 | if (*t == '\\' && t+1 < PL_bufend && open != '\\') | |
b8a4b1be | 3543 | t++; |
6d07e5e9 | 3544 | else if (*t == open) |
b8a4b1be GS |
3545 | break; |
3546 | } | |
abc667d1 | 3547 | else { |
3280af22 NIS |
3548 | for (t++; t < PL_bufend; t++) { |
3549 | if (*t == '\\' && t+1 < PL_bufend) | |
b8a4b1be | 3550 | t++; |
6d07e5e9 | 3551 | else if (*t == close && --brackets <= 0) |
b8a4b1be GS |
3552 | break; |
3553 | else if (*t == open) | |
3554 | brackets++; | |
3555 | } | |
abc667d1 DM |
3556 | } |
3557 | t++; | |
b8a4b1be | 3558 | } |
abc667d1 DM |
3559 | else |
3560 | /* skip plain q word */ | |
3561 | while (t < PL_bufend && isALNUM_lazy_if(t,UTF)) | |
3562 | t += UTF8SKIP(t); | |
a0d0e21e | 3563 | } |
7e2040f0 | 3564 | else if (isALNUM_lazy_if(t,UTF)) { |
0505442f | 3565 | t += UTF8SKIP(t); |
7e2040f0 | 3566 | while (t < PL_bufend && isALNUM_lazy_if(t,UTF)) |
0505442f | 3567 | t += UTF8SKIP(t); |
a0d0e21e | 3568 | } |
3280af22 | 3569 | while (t < PL_bufend && isSPACE(*t)) |
a0d0e21e | 3570 | t++; |
b8a4b1be GS |
3571 | /* if comma follows first term, call it an anon hash */ |
3572 | /* XXX it could be a comma expression with loop modifiers */ | |
3280af22 | 3573 | if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s))) |
b8a4b1be | 3574 | || (*t == '=' && t[1] == '>'))) |
a0d0e21e | 3575 | OPERATOR(HASHBRACK); |
3280af22 | 3576 | if (PL_expect == XREF) |
4e4e412b | 3577 | PL_expect = XTERM; |
a0d0e21e | 3578 | else { |
3280af22 NIS |
3579 | PL_lex_brackstack[PL_lex_brackets-1] = XSTATE; |
3580 | PL_expect = XSTATE; | |
a0d0e21e | 3581 | } |
8990e307 | 3582 | } |
a0d0e21e | 3583 | break; |
463ee0b2 | 3584 | } |
57843af0 | 3585 | yylval.ival = CopLINE(PL_curcop); |
79072805 | 3586 | if (isSPACE(*s) || *s == '#') |
3280af22 | 3587 | PL_copline = NOLINE; /* invalidate current command line number */ |
79072805 | 3588 | TOKEN('{'); |
378cc40b | 3589 | case '}': |
79072805 LW |
3590 | rightbracket: |
3591 | s++; | |
3280af22 | 3592 | if (PL_lex_brackets <= 0) |
d98d5fff | 3593 | yyerror("Unmatched right curly bracket"); |
463ee0b2 | 3594 | else |
3280af22 | 3595 | PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets]; |
c2e66d9e | 3596 | if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL) |
3280af22 NIS |
3597 | PL_lex_formbrack = 0; |
3598 | if (PL_lex_state == LEX_INTERPNORMAL) { | |
3599 | if (PL_lex_brackets == 0) { | |
9059aa12 LW |
3600 | if (PL_expect & XFAKEBRACK) { |
3601 | PL_expect &= XENUMMASK; | |
3280af22 NIS |
3602 | PL_lex_state = LEX_INTERPEND; |
3603 | PL_bufptr = s; | |
cea2e8a9 | 3604 | return yylex(); /* ignore fake brackets */ |
79072805 | 3605 | } |
fa83b5b6 | 3606 | if (*s == '-' && s[1] == '>') |
3280af22 | 3607 | PL_lex_state = LEX_INTERPENDMAYBE; |
fa83b5b6 | 3608 | else if (*s != '[' && *s != '{') |
3280af22 | 3609 | PL_lex_state = LEX_INTERPEND; |
79072805 LW |
3610 | } |
3611 | } | |
9059aa12 LW |
3612 | if (PL_expect & XFAKEBRACK) { |
3613 | PL_expect &= XENUMMASK; | |
3280af22 | 3614 | PL_bufptr = s; |
cea2e8a9 | 3615 | return yylex(); /* ignore fake brackets */ |
748a9306 | 3616 | } |
79072805 LW |
3617 | force_next('}'); |
3618 | TOKEN(';'); | |
378cc40b LW |
3619 | case '&': |
3620 | s++; | |
90771dc0 | 3621 | if (*s++ == '&') |
a0d0e21e | 3622 | AOPERATOR(ANDAND); |
378cc40b | 3623 | s--; |
3280af22 | 3624 | if (PL_expect == XOPERATOR) { |
041457d9 DM |
3625 | if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON) |
3626 | && isIDFIRST_lazy_if(s,UTF)) | |
7e2040f0 | 3627 | { |
57843af0 | 3628 | CopLINE_dec(PL_curcop); |
9014280d | 3629 | Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi); |
57843af0 | 3630 | CopLINE_inc(PL_curcop); |
463ee0b2 | 3631 | } |
79072805 | 3632 | BAop(OP_BIT_AND); |
463ee0b2 | 3633 | } |
79072805 | 3634 | |
3280af22 NIS |
3635 | s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); |
3636 | if (*PL_tokenbuf) { | |
3637 | PL_expect = XOPERATOR; | |
3638 | force_ident(PL_tokenbuf, '&'); | |
463ee0b2 | 3639 | } |
79072805 LW |
3640 | else |
3641 | PREREF('&'); | |
c07a80fd | 3642 | yylval.ival = (OPpENTERSUB_AMPER<<8); |
79072805 LW |
3643 | TERM('&'); |
3644 | ||
378cc40b LW |
3645 | case '|': |
3646 | s++; | |
90771dc0 | 3647 | if (*s++ == '|') |
a0d0e21e | 3648 | AOPERATOR(OROR); |
378cc40b | 3649 | s--; |
79072805 | 3650 | BOop(OP_BIT_OR); |
378cc40b LW |
3651 | case '=': |
3652 | s++; | |
748a9306 | 3653 | { |
90771dc0 NC |
3654 | const char tmp = *s++; |
3655 | if (tmp == '=') | |
3656 | Eop(OP_EQ); | |
3657 | if (tmp == '>') | |
3658 | OPERATOR(','); | |
3659 | if (tmp == '~') | |
3660 | PMop(OP_MATCH); | |
3661 | if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX) | |
3662 | && strchr("+-*/%.^&|<",tmp)) | |
3663 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
3664 | "Reversed %c= operator",(int)tmp); | |
3665 | s--; | |
3666 | if (PL_expect == XSTATE && isALPHA(tmp) && | |
3667 | (s == PL_linestart+1 || s[-2] == '\n') ) | |
3668 | { | |
3669 | if (PL_in_eval && !PL_rsfp) { | |
3670 | d = PL_bufend; | |
3671 | while (s < d) { | |
3672 | if (*s++ == '\n') { | |
3673 | incline(s); | |
3674 | if (strnEQ(s,"=cut",4)) { | |
3675 | s = strchr(s,'\n'); | |
3676 | if (s) | |
3677 | s++; | |
3678 | else | |
3679 | s = d; | |
3680 | incline(s); | |
3681 | goto retry; | |
3682 | } | |
3683 | } | |
a5f75d66 | 3684 | } |
90771dc0 | 3685 | goto retry; |
a5f75d66 | 3686 | } |
90771dc0 NC |
3687 | s = PL_bufend; |
3688 | PL_doextract = TRUE; | |
3689 | goto retry; | |
a5f75d66 | 3690 | } |
a0d0e21e | 3691 | } |
3280af22 | 3692 | if (PL_lex_brackets < PL_lex_formbrack) { |
f54cb97a | 3693 | const char *t; |
51882d45 | 3694 | #ifdef PERL_STRICT_CR |
bf4acbe4 | 3695 | for (t = s; SPACE_OR_TAB(*t); t++) ; |
51882d45 | 3696 | #else |
bf4acbe4 | 3697 | for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ; |
51882d45 | 3698 | #endif |
a0d0e21e LW |
3699 | if (*t == '\n' || *t == '#') { |
3700 | s--; | |
3280af22 | 3701 | PL_expect = XBLOCK; |
a0d0e21e LW |
3702 | goto leftbracket; |
3703 | } | |
79072805 | 3704 | } |
a0d0e21e LW |
3705 | yylval.ival = 0; |
3706 | OPERATOR(ASSIGNOP); | |
378cc40b LW |
3707 | case '!': |
3708 | s++; | |
90771dc0 NC |
3709 | { |
3710 | const char tmp = *s++; | |
3711 | if (tmp == '=') { | |
3712 | /* was this !=~ where !~ was meant? | |
3713 | * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */ | |
3714 | ||
3715 | if (*s == '~' && ckWARN(WARN_SYNTAX)) { | |
3716 | const char *t = s+1; | |
3717 | ||
3718 | while (t < PL_bufend && isSPACE(*t)) | |
3719 | ++t; | |
3720 | ||
3721 | if (*t == '/' || *t == '?' || | |
3722 | ((*t == 'm' || *t == 's' || *t == 'y') | |
3723 | && !isALNUM(t[1])) || | |
3724 | (*t == 't' && t[1] == 'r' && !isALNUM(t[2]))) | |
3725 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
3726 | "!=~ should be !~"); | |
3727 | } | |
3728 | Eop(OP_NE); | |
3729 | } | |
3730 | if (tmp == '~') | |
3731 | PMop(OP_NOT); | |
3732 | } | |
378cc40b LW |
3733 | s--; |
3734 | OPERATOR('!'); | |
3735 | case '<': | |
3280af22 | 3736 | if (PL_expect != XOPERATOR) { |
93a17b20 | 3737 | if (s[1] != '<' && !strchr(s,'>')) |
2f3197b3 | 3738 | check_uni(); |
79072805 LW |
3739 | if (s[1] == '<') |
3740 | s = scan_heredoc(s); | |
3741 | else | |
3742 | s = scan_inputsymbol(s); | |
3743 | TERM(sublex_start()); | |
378cc40b LW |
3744 | } |
3745 | s++; | |
90771dc0 NC |
3746 | { |
3747 | char tmp = *s++; | |
3748 | if (tmp == '<') | |
3749 | SHop(OP_LEFT_SHIFT); | |
3750 | if (tmp == '=') { | |
3751 | tmp = *s++; | |
3752 | if (tmp == '>') | |
3753 | Eop(OP_NCMP); | |
3754 | s--; | |
3755 | Rop(OP_LE); | |
3756 | } | |
395c3793 | 3757 | } |
378cc40b | 3758 | s--; |
79072805 | 3759 | Rop(OP_LT); |
378cc40b LW |
3760 | case '>': |
3761 | s++; | |
90771dc0 NC |
3762 | { |
3763 | const char tmp = *s++; | |
3764 | if (tmp == '>') | |
3765 | SHop(OP_RIGHT_SHIFT); | |
3766 | if (tmp == '=') | |
3767 | Rop(OP_GE); | |
3768 | } | |
378cc40b | 3769 | s--; |
79072805 | 3770 | Rop(OP_GT); |
378cc40b LW |
3771 | |
3772 | case '$': | |
bbce6d69 | 3773 | CLINE; |
3774 | ||
3280af22 NIS |
3775 | if (PL_expect == XOPERATOR) { |
3776 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3777 | PL_expect = XTERM; | |
c445ea15 | 3778 | deprecate_old(commaless_variable_list); |
bbf60fe6 | 3779 | return REPORT(','); /* grandfather non-comma-format format */ |
a0d0e21e | 3780 | } |
8990e307 | 3781 | } |
a0d0e21e | 3782 | |
7e2040f0 | 3783 | if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) { |
3280af22 | 3784 | PL_tokenbuf[0] = '@'; |
376b8730 SM |
3785 | s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1, |
3786 | sizeof PL_tokenbuf - 1, FALSE); | |
3787 | if (PL_expect == XOPERATOR) | |
3788 | no_op("Array length", s); | |
3280af22 | 3789 | if (!PL_tokenbuf[1]) |
a0d0e21e | 3790 | PREREF(DOLSHARP); |
3280af22 NIS |
3791 | PL_expect = XOPERATOR; |
3792 | PL_pending_ident = '#'; | |
463ee0b2 | 3793 | TOKEN(DOLSHARP); |
79072805 | 3794 | } |
bbce6d69 | 3795 | |
3280af22 | 3796 | PL_tokenbuf[0] = '$'; |
376b8730 SM |
3797 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, |
3798 | sizeof PL_tokenbuf - 1, FALSE); | |
3799 | if (PL_expect == XOPERATOR) | |
3800 | no_op("Scalar", s); | |
3280af22 NIS |
3801 | if (!PL_tokenbuf[1]) { |
3802 | if (s == PL_bufend) | |
bbce6d69 | 3803 | yyerror("Final $ should be \\$ or $name"); |
3804 | PREREF('$'); | |
8990e307 | 3805 | } |
a0d0e21e | 3806 | |
bbce6d69 | 3807 | /* This kludge not intended to be bulletproof. */ |
3280af22 | 3808 | if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) { |
bbce6d69 | 3809 | yylval.opval = newSVOP(OP_CONST, 0, |
b448e4fe | 3810 | newSViv(PL_compiling.cop_arybase)); |
bbce6d69 | 3811 | yylval.opval->op_private = OPpCONST_ARYBASE; |
3812 | TERM(THING); | |
3813 | } | |
3814 | ||
ff68c719 | 3815 | d = s; |
90771dc0 NC |
3816 | { |
3817 | const char tmp = *s; | |
3818 | if (PL_lex_state == LEX_NORMAL) | |
3819 | s = skipspace(s); | |
ff68c719 | 3820 | |
90771dc0 NC |
3821 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) |
3822 | && intuit_more(s)) { | |
3823 | if (*s == '[') { | |
3824 | PL_tokenbuf[0] = '@'; | |
3825 | if (ckWARN(WARN_SYNTAX)) { | |
3826 | char *t; | |
3827 | for(t = s + 1; | |
3828 | isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$'; | |
3829 | t++) ; | |
3830 | if (*t++ == ',') { | |
3831 | PL_bufptr = skipspace(PL_bufptr); | |
3832 | while (t < PL_bufend && *t != ']') | |
3833 | t++; | |
9014280d | 3834 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
90771dc0 | 3835 | "Multidimensional syntax %.*s not supported", |
36c7798d | 3836 | (int)((t - PL_bufptr) + 1), PL_bufptr); |
90771dc0 | 3837 | } |
748a9306 | 3838 | } |
93a17b20 | 3839 | } |
90771dc0 NC |
3840 | else if (*s == '{') { |
3841 | char *t; | |
3842 | PL_tokenbuf[0] = '%'; | |
3843 | if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX) | |
3844 | && (t = strchr(s, '}')) && (t = strchr(t, '='))) | |
3845 | { | |
3846 | char tmpbuf[sizeof PL_tokenbuf]; | |
3847 | for (t++; isSPACE(*t); t++) ; | |
3848 | if (isIDFIRST_lazy_if(t,UTF)) { | |
5f66b61c | 3849 | STRLEN dummylen; |
90771dc0 | 3850 | t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, |
5f66b61c | 3851 | &dummylen); |
90771dc0 NC |
3852 | for (; isSPACE(*t); t++) ; |
3853 | if (*t == ';' && get_cv(tmpbuf, FALSE)) | |
3854 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
3855 | "You need to quote \"%s\"", | |
3856 | tmpbuf); | |
3857 | } | |
3858 | } | |
3859 | } | |
93a17b20 | 3860 | } |
bbce6d69 | 3861 | |
90771dc0 NC |
3862 | PL_expect = XOPERATOR; |
3863 | if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) { | |
3864 | const bool islop = (PL_last_lop == PL_oldoldbufptr); | |
3865 | if (!islop || PL_last_lop_op == OP_GREPSTART) | |
3866 | PL_expect = XOPERATOR; | |
3867 | else if (strchr("$@\"'`q", *s)) | |
3868 | PL_expect = XTERM; /* e.g. print $fh "foo" */ | |
3869 | else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF)) | |
3870 | PL_expect = XTERM; /* e.g. print $fh &sub */ | |
3871 | else if (isIDFIRST_lazy_if(s,UTF)) { | |
3872 | char tmpbuf[sizeof PL_tokenbuf]; | |
3873 | int t2; | |
3874 | scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); | |
3875 | if ((t2 = keyword(tmpbuf, len))) { | |
3876 | /* binary operators exclude handle interpretations */ | |
3877 | switch (t2) { | |
3878 | case -KEY_x: | |
3879 | case -KEY_eq: | |
3880 | case -KEY_ne: | |
3881 | case -KEY_gt: | |
3882 | case -KEY_lt: | |
3883 | case -KEY_ge: | |
3884 | case -KEY_le: | |
3885 | case -KEY_cmp: | |
3886 | break; | |
3887 | default: | |
3888 | PL_expect = XTERM; /* e.g. print $fh length() */ | |
3889 | break; | |
3890 | } | |
3891 | } | |
3892 | else { | |
3893 | PL_expect = XTERM; /* e.g. print $fh subr() */ | |
84902520 TB |
3894 | } |
3895 | } | |
90771dc0 NC |
3896 | else if (isDIGIT(*s)) |
3897 | PL_expect = XTERM; /* e.g. print $fh 3 */ | |
3898 | else if (*s == '.' && isDIGIT(s[1])) | |
3899 | PL_expect = XTERM; /* e.g. print $fh .3 */ | |
3900 | else if ((*s == '?' || *s == '-' || *s == '+') | |
3901 | && !isSPACE(s[1]) && s[1] != '=') | |
3902 | PL_expect = XTERM; /* e.g. print $fh -1 */ | |
3903 | else if (*s == '/' && !isSPACE(s[1]) && s[1] != '=' | |
3904 | && s[1] != '/') | |
3905 | PL_expect = XTERM; /* e.g. print $fh /.../ | |
3906 | XXX except DORDOR operator | |
3907 | */ | |
3908 | else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) | |
3909 | && s[2] != '=') | |
3910 | PL_expect = XTERM; /* print $fh <<"EOF" */ | |
93a17b20 | 3911 | } |
bbce6d69 | 3912 | } |
3280af22 | 3913 | PL_pending_ident = '$'; |
79072805 | 3914 | TOKEN('$'); |
378cc40b LW |
3915 | |
3916 | case '@': | |
3280af22 | 3917 | if (PL_expect == XOPERATOR) |
bbce6d69 | 3918 | no_op("Array", s); |
3280af22 NIS |
3919 | PL_tokenbuf[0] = '@'; |
3920 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE); | |
3921 | if (!PL_tokenbuf[1]) { | |
bbce6d69 | 3922 | PREREF('@'); |
3923 | } | |
3280af22 | 3924 | if (PL_lex_state == LEX_NORMAL) |
ff68c719 | 3925 | s = skipspace(s); |
3280af22 | 3926 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) { |
bbce6d69 | 3927 | if (*s == '{') |
3280af22 | 3928 | PL_tokenbuf[0] = '%'; |
a0d0e21e LW |
3929 | |
3930 | /* Warn about @ where they meant $. */ | |
041457d9 DM |
3931 | if (*s == '[' || *s == '{') { |
3932 | if (ckWARN(WARN_SYNTAX)) { | |
f54cb97a | 3933 | const char *t = s + 1; |
7e2040f0 | 3934 | while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t))) |
a0d0e21e LW |
3935 | t++; |
3936 | if (*t == '}' || *t == ']') { | |
3937 | t++; | |
3280af22 | 3938 | PL_bufptr = skipspace(PL_bufptr); |
9014280d | 3939 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
599cee73 | 3940 | "Scalar value %.*s better written as $%.*s", |
36c7798d DM |
3941 | (int)(t-PL_bufptr), PL_bufptr, |
3942 | (int)(t-PL_bufptr-1), PL_bufptr+1); | |
a0d0e21e | 3943 | } |
93a17b20 LW |
3944 | } |
3945 | } | |
463ee0b2 | 3946 | } |
3280af22 | 3947 | PL_pending_ident = '@'; |
79072805 | 3948 | TERM('@'); |
378cc40b | 3949 | |
c963b151 | 3950 | case '/': /* may be division, defined-or, or pattern */ |
6f33ba73 RGS |
3951 | if (PL_expect == XTERMORDORDOR && s[1] == '/') { |
3952 | s += 2; | |
3953 | AOPERATOR(DORDOR); | |
3954 | } | |
c963b151 BD |
3955 | case '?': /* may either be conditional or pattern */ |
3956 | if(PL_expect == XOPERATOR) { | |
90771dc0 | 3957 | char tmp = *s++; |
c963b151 BD |
3958 | if(tmp == '?') { |
3959 | OPERATOR('?'); | |
3960 | } | |
3961 | else { | |
3962 | tmp = *s++; | |
3963 | if(tmp == '/') { | |
3964 | /* A // operator. */ | |
3965 | AOPERATOR(DORDOR); | |
3966 | } | |
3967 | else { | |
3968 | s--; | |
3969 | Mop(OP_DIVIDE); | |
3970 | } | |
3971 | } | |
3972 | } | |
3973 | else { | |
3974 | /* Disable warning on "study /blah/" */ | |
3975 | if (PL_oldoldbufptr == PL_last_uni | |
3976 | && (*PL_last_uni != 's' || s - PL_last_uni < 5 | |
3977 | || memNE(PL_last_uni, "study", 5) | |
3978 | || isALNUM_lazy_if(PL_last_uni+5,UTF) | |
3979 | )) | |
3980 | check_uni(); | |
3981 | s = scan_pat(s,OP_MATCH); | |
3982 | TERM(sublex_start()); | |
3983 | } | |
378cc40b LW |
3984 | |
3985 | case '.': | |
51882d45 GS |
3986 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack |
3987 | #ifdef PERL_STRICT_CR | |
3988 | && s[1] == '\n' | |
3989 | #else | |
3990 | && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n')) | |
3991 | #endif | |
3992 | && (s == PL_linestart || s[-1] == '\n') ) | |
3993 | { | |
3280af22 NIS |
3994 | PL_lex_formbrack = 0; |
3995 | PL_expect = XSTATE; | |
79072805 LW |
3996 | goto rightbracket; |
3997 | } | |
3280af22 | 3998 | if (PL_expect == XOPERATOR || !isDIGIT(s[1])) { |
90771dc0 | 3999 | char tmp = *s++; |
a687059c LW |
4000 | if (*s == tmp) { |
4001 | s++; | |
2f3197b3 LW |
4002 | if (*s == tmp) { |
4003 | s++; | |
79072805 | 4004 | yylval.ival = OPf_SPECIAL; |
2f3197b3 LW |
4005 | } |
4006 | else | |
79072805 | 4007 | yylval.ival = 0; |
378cc40b | 4008 | OPERATOR(DOTDOT); |
a687059c | 4009 | } |
3280af22 | 4010 | if (PL_expect != XOPERATOR) |
2f3197b3 | 4011 | check_uni(); |
79072805 | 4012 | Aop(OP_CONCAT); |
378cc40b LW |
4013 | } |
4014 | /* FALL THROUGH */ | |
4015 | case '0': case '1': case '2': case '3': case '4': | |
4016 | case '5': case '6': case '7': case '8': case '9': | |
b73d6f50 | 4017 | s = scan_num(s, &yylval); |
b6007c36 | 4018 | DEBUG_T( { S_printbuf(aTHX_ "### Saw number in %s\n", s); } ); |
3280af22 | 4019 | if (PL_expect == XOPERATOR) |
8990e307 | 4020 | no_op("Number",s); |
79072805 LW |
4021 | TERM(THING); |
4022 | ||
4023 | case '\'': | |
09bef843 | 4024 | s = scan_str(s,FALSE,FALSE); |
b6007c36 | 4025 | DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } ); |
3280af22 NIS |
4026 | if (PL_expect == XOPERATOR) { |
4027 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
4028 | PL_expect = XTERM; | |
c445ea15 | 4029 | deprecate_old(commaless_variable_list); |
bbf60fe6 | 4030 | return REPORT(','); /* grandfather non-comma-format format */ |
a0d0e21e | 4031 | } |
463ee0b2 | 4032 | else |
8990e307 | 4033 | no_op("String",s); |
463ee0b2 | 4034 | } |
79072805 | 4035 | if (!s) |
85e6fe83 | 4036 | missingterm((char*)0); |
79072805 LW |
4037 | yylval.ival = OP_CONST; |
4038 | TERM(sublex_start()); | |
4039 | ||
4040 | case '"': | |
09bef843 | 4041 | s = scan_str(s,FALSE,FALSE); |
b6007c36 | 4042 | DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } ); |
3280af22 NIS |
4043 | if (PL_expect == XOPERATOR) { |
4044 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
4045 | PL_expect = XTERM; | |
c445ea15 | 4046 | deprecate_old(commaless_variable_list); |
bbf60fe6 | 4047 | return REPORT(','); /* grandfather non-comma-format format */ |
a0d0e21e | 4048 | } |
463ee0b2 | 4049 | else |
8990e307 | 4050 | no_op("String",s); |
463ee0b2 | 4051 | } |
79072805 | 4052 | if (!s) |
85e6fe83 | 4053 | missingterm((char*)0); |
4633a7c4 | 4054 | yylval.ival = OP_CONST; |
cfd0369c NC |
4055 | /* FIXME. I think that this can be const if char *d is replaced by |
4056 | more localised variables. */ | |
3280af22 | 4057 | for (d = SvPV(PL_lex_stuff, len); len; len--, d++) { |
63cd0674 | 4058 | if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) { |
4633a7c4 LW |
4059 | yylval.ival = OP_STRINGIFY; |
4060 | break; | |
4061 | } | |
4062 | } | |
79072805 LW |
4063 | TERM(sublex_start()); |
4064 | ||
4065 | case '`': | |
09bef843 | 4066 | s = scan_str(s,FALSE,FALSE); |
b6007c36 | 4067 | DEBUG_T( { S_printbuf(aTHX_ "### Saw backtick string before %s\n", s); } ); |
3280af22 | 4068 | if (PL_expect == XOPERATOR) |
8990e307 | 4069 | no_op("Backticks",s); |
79072805 | 4070 | if (!s) |
85e6fe83 | 4071 | missingterm((char*)0); |
79072805 LW |
4072 | yylval.ival = OP_BACKTICK; |
4073 | set_csh(); | |
4074 | TERM(sublex_start()); | |
4075 | ||
4076 | case '\\': | |
4077 | s++; | |
041457d9 | 4078 | if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX)) |
9014280d | 4079 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression", |
599cee73 | 4080 | *s, *s); |
3280af22 | 4081 | if (PL_expect == XOPERATOR) |
8990e307 | 4082 | no_op("Backslash",s); |
79072805 LW |
4083 | OPERATOR(REFGEN); |
4084 | ||
a7cb1f99 | 4085 | case 'v': |
e526c9e6 | 4086 | if (isDIGIT(s[1]) && PL_expect != XOPERATOR) { |
f54cb97a | 4087 | char *start = s + 2; |
dd629d5b | 4088 | while (isDIGIT(*start) || *start == '_') |
a7cb1f99 GS |
4089 | start++; |
4090 | if (*start == '.' && isDIGIT(start[1])) { | |
b73d6f50 | 4091 | s = scan_num(s, &yylval); |
a7cb1f99 GS |
4092 | TERM(THING); |
4093 | } | |
e526c9e6 | 4094 | /* avoid v123abc() or $h{v1}, allow C<print v10;> */ |
6f33ba73 RGS |
4095 | else if (!isALPHA(*start) && (PL_expect == XTERM |
4096 | || PL_expect == XREF || PL_expect == XSTATE | |
4097 | || PL_expect == XTERMORDORDOR)) { | |
f54cb97a | 4098 | const char c = *start; |
e526c9e6 GS |
4099 | GV *gv; |
4100 | *start = '\0'; | |
f776e3cd | 4101 | gv = gv_fetchpv(s, 0, SVt_PVCV); |
e526c9e6 GS |
4102 | *start = c; |
4103 | if (!gv) { | |
b73d6f50 | 4104 | s = scan_num(s, &yylval); |
e526c9e6 GS |
4105 | TERM(THING); |
4106 | } | |
4107 | } | |
a7cb1f99 GS |
4108 | } |
4109 | goto keylookup; | |
79072805 | 4110 | case 'x': |
3280af22 | 4111 | if (isDIGIT(s[1]) && PL_expect == XOPERATOR) { |
79072805 LW |
4112 | s++; |
4113 | Mop(OP_REPEAT); | |
2f3197b3 | 4114 | } |
79072805 LW |
4115 | goto keylookup; |
4116 | ||
378cc40b | 4117 | case '_': |
79072805 LW |
4118 | case 'a': case 'A': |
4119 | case 'b': case 'B': | |
4120 | case 'c': case 'C': | |
4121 | case 'd': case 'D': | |
4122 | case 'e': case 'E': | |
4123 | case 'f': case 'F': | |
4124 | case 'g': case 'G': | |
4125 | case 'h': case 'H': | |
4126 | case 'i': case 'I': | |
4127 | case 'j': case 'J': | |
4128 | case 'k': case 'K': | |
4129 | case 'l': case 'L': | |
4130 | case 'm': case 'M': | |
4131 | case 'n': case 'N': | |
4132 | case 'o': case 'O': | |
4133 | case 'p': case 'P': | |
4134 | case 'q': case 'Q': | |
4135 | case 'r': case 'R': | |
4136 | case 's': case 'S': | |
4137 | case 't': case 'T': | |
4138 | case 'u': case 'U': | |
a7cb1f99 | 4139 | case 'V': |
79072805 LW |
4140 | case 'w': case 'W': |
4141 | case 'X': | |
4142 | case 'y': case 'Y': | |
4143 | case 'z': case 'Z': | |
4144 | ||
49dc05e3 | 4145 | keylookup: { |
90771dc0 | 4146 | I32 tmp; |
0bfa2a8a | 4147 | I32 orig_keyword = 0; |
cbbf8932 AL |
4148 | GV *gv = NULL; |
4149 | GV **gvp = NULL; | |
49dc05e3 | 4150 | |
3280af22 NIS |
4151 | PL_bufptr = s; |
4152 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); | |
8ebc5c01 | 4153 | |
4154 | /* Some keywords can be followed by any delimiter, including ':' */ | |
155aba94 GS |
4155 | tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) || |
4156 | (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') || | |
4157 | (PL_tokenbuf[0] == 'q' && | |
4158 | strchr("qwxr", PL_tokenbuf[1]))))); | |
8ebc5c01 | 4159 | |
4160 | /* x::* is just a word, unless x is "CORE" */ | |
3280af22 | 4161 | if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE")) |
4633a7c4 LW |
4162 | goto just_a_word; |
4163 | ||
3643fb5f | 4164 | d = s; |
3280af22 | 4165 | while (d < PL_bufend && isSPACE(*d)) |
3643fb5f CS |
4166 | d++; /* no comments skipped here, or s### is misparsed */ |
4167 | ||
4168 | /* Is this a label? */ | |
3280af22 NIS |
4169 | if (!tmp && PL_expect == XSTATE |
4170 | && d < PL_bufend && *d == ':' && *(d + 1) != ':') { | |
8ebc5c01 | 4171 | s = d + 1; |
3280af22 | 4172 | yylval.pval = savepv(PL_tokenbuf); |
8ebc5c01 | 4173 | CLINE; |
4174 | TOKEN(LABEL); | |
3643fb5f CS |
4175 | } |
4176 | ||
4177 | /* Check for keywords */ | |
3280af22 | 4178 | tmp = keyword(PL_tokenbuf, len); |
748a9306 LW |
4179 | |
4180 | /* Is this a word before a => operator? */ | |
1c3923b3 | 4181 | if (*d == '=' && d[1] == '>') { |
748a9306 | 4182 | CLINE; |
d0a148a6 NC |
4183 | yylval.opval |
4184 | = (OP*)newSVOP(OP_CONST, 0, | |
4185 | S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len)); | |
748a9306 LW |
4186 | yylval.opval->op_private = OPpCONST_BARE; |
4187 | TERM(WORD); | |
4188 | } | |
4189 | ||
a0d0e21e | 4190 | if (tmp < 0) { /* second-class keyword? */ |
cbbf8932 AL |
4191 | GV *ogv = NULL; /* override (winner) */ |
4192 | GV *hgv = NULL; /* hidden (loser) */ | |
3280af22 | 4193 | if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) { |
56f7f34b | 4194 | CV *cv; |
90e5519e | 4195 | if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) && |
56f7f34b CS |
4196 | (cv = GvCVu(gv))) |
4197 | { | |
4198 | if (GvIMPORTED_CV(gv)) | |
4199 | ogv = gv; | |
4200 | else if (! CvMETHOD(cv)) | |
4201 | hgv = gv; | |
4202 | } | |
4203 | if (!ogv && | |
3280af22 NIS |
4204 | (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) && |
4205 | (gv = *gvp) != (GV*)&PL_sv_undef && | |
56f7f34b CS |
4206 | GvCVu(gv) && GvIMPORTED_CV(gv)) |
4207 | { | |
4208 | ogv = gv; | |
4209 | } | |
4210 | } | |
4211 | if (ogv) { | |
30fe34ed | 4212 | orig_keyword = tmp; |
56f7f34b | 4213 | tmp = 0; /* overridden by import or by GLOBAL */ |
6e7b2336 GS |
4214 | } |
4215 | else if (gv && !gvp | |
4216 | && -tmp==KEY_lock /* XXX generalizable kludge */ | |
d0456cad | 4217 | && GvCVu(gv) |
017a3ce5 | 4218 | && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE)) |
6e7b2336 GS |
4219 | { |
4220 | tmp = 0; /* any sub overrides "weak" keyword */ | |
a0d0e21e | 4221 | } |
56f7f34b CS |
4222 | else { /* no override */ |
4223 | tmp = -tmp; | |
ac206dc8 | 4224 | if (tmp == KEY_dump && ckWARN(WARN_MISC)) { |
9014280d | 4225 | Perl_warner(aTHX_ packWARN(WARN_MISC), |
ac206dc8 RGS |
4226 | "dump() better written as CORE::dump()"); |
4227 | } | |
a0714e2c | 4228 | gv = NULL; |
56f7f34b | 4229 | gvp = 0; |
041457d9 DM |
4230 | if (hgv && tmp != KEY_x && tmp != KEY_CORE |
4231 | && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */ | |
9014280d | 4232 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
599cee73 | 4233 | "Ambiguous call resolved as CORE::%s(), %s", |
2f3ca594 | 4234 | GvENAME(hgv), "qualify as such or use &"); |
49dc05e3 | 4235 | } |
a0d0e21e LW |
4236 | } |
4237 | ||
4238 | reserved_word: | |
4239 | switch (tmp) { | |
79072805 LW |
4240 | |
4241 | default: /* not a keyword */ | |
0bfa2a8a NC |
4242 | /* Trade off - by using this evil construction we can pull the |
4243 | variable gv into the block labelled keylookup. If not, then | |
4244 | we have to give it function scope so that the goto from the | |
4245 | earlier ':' case doesn't bypass the initialisation. */ | |
4246 | if (0) { | |
4247 | just_a_word_zero_gv: | |
4248 | gv = NULL; | |
4249 | gvp = NULL; | |
8bee0991 | 4250 | orig_keyword = 0; |
0bfa2a8a | 4251 | } |
93a17b20 | 4252 | just_a_word: { |
96e4d5b1 | 4253 | SV *sv; |
ce29ac45 | 4254 | int pkgname = 0; |
f54cb97a | 4255 | const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]); |
5069cc75 | 4256 | CV *cv; |
8990e307 LW |
4257 | |
4258 | /* Get the rest if it looks like a package qualifier */ | |
4259 | ||
155aba94 | 4260 | if (*s == '\'' || (*s == ':' && s[1] == ':')) { |
c3e0f903 | 4261 | STRLEN morelen; |
3280af22 | 4262 | s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len, |
c3e0f903 GS |
4263 | TRUE, &morelen); |
4264 | if (!morelen) | |
cea2e8a9 | 4265 | Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf, |
ec2ab091 | 4266 | *s == '\'' ? "'" : "::"); |
c3e0f903 | 4267 | len += morelen; |
ce29ac45 | 4268 | pkgname = 1; |
a0d0e21e | 4269 | } |
8990e307 | 4270 | |
3280af22 NIS |
4271 | if (PL_expect == XOPERATOR) { |
4272 | if (PL_bufptr == PL_linestart) { | |
57843af0 | 4273 | CopLINE_dec(PL_curcop); |
9014280d | 4274 | Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi); |
57843af0 | 4275 | CopLINE_inc(PL_curcop); |
463ee0b2 LW |
4276 | } |
4277 | else | |
54310121 | 4278 | no_op("Bareword",s); |
463ee0b2 | 4279 | } |
8990e307 | 4280 | |
c3e0f903 GS |
4281 | /* Look for a subroutine with this name in current package, |
4282 | unless name is "Foo::", in which case Foo is a bearword | |
4283 | (and a package name). */ | |
4284 | ||
4285 | if (len > 2 && | |
3280af22 | 4286 | PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':') |
c3e0f903 | 4287 | { |
f776e3cd | 4288 | if (ckWARN(WARN_BAREWORD) |
90e5519e | 4289 | && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV)) |
9014280d | 4290 | Perl_warner(aTHX_ packWARN(WARN_BAREWORD), |
599cee73 | 4291 | "Bareword \"%s\" refers to nonexistent package", |
3280af22 | 4292 | PL_tokenbuf); |
c3e0f903 | 4293 | len -= 2; |
3280af22 | 4294 | PL_tokenbuf[len] = '\0'; |
a0714e2c | 4295 | gv = NULL; |
c3e0f903 GS |
4296 | gvp = 0; |
4297 | } | |
4298 | else { | |
62d55b22 NC |
4299 | if (!gv) { |
4300 | /* Mustn't actually add anything to a symbol table. | |
4301 | But also don't want to "initialise" any placeholder | |
4302 | constants that might already be there into full | |
4303 | blown PVGVs with attached PVCV. */ | |
90e5519e NC |
4304 | gv = gv_fetchpvn_flags(PL_tokenbuf, len, |
4305 | GV_NOADD_NOINIT, SVt_PVCV); | |
62d55b22 | 4306 | } |
b3d904f3 | 4307 | len = 0; |
c3e0f903 GS |
4308 | } |
4309 | ||
4310 | /* if we saw a global override before, get the right name */ | |
8990e307 | 4311 | |
49dc05e3 | 4312 | if (gvp) { |
396482e1 | 4313 | sv = newSVpvs("CORE::GLOBAL::"); |
3280af22 | 4314 | sv_catpv(sv,PL_tokenbuf); |
49dc05e3 | 4315 | } |
8a7a129d NC |
4316 | else { |
4317 | /* If len is 0, newSVpv does strlen(), which is correct. | |
4318 | If len is non-zero, then it will be the true length, | |
4319 | and so the scalar will be created correctly. */ | |
4320 | sv = newSVpv(PL_tokenbuf,len); | |
4321 | } | |
8990e307 | 4322 | |
a0d0e21e LW |
4323 | /* Presume this is going to be a bareword of some sort. */ |
4324 | ||
4325 | CLINE; | |
49dc05e3 | 4326 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
a0d0e21e | 4327 | yylval.opval->op_private = OPpCONST_BARE; |
8f8cf39c JH |
4328 | /* UTF-8 package name? */ |
4329 | if (UTF && !IN_BYTES && | |
95a20fc0 | 4330 | is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv))) |
8f8cf39c | 4331 | SvUTF8_on(sv); |
a0d0e21e | 4332 | |
c3e0f903 GS |
4333 | /* And if "Foo::", then that's what it certainly is. */ |
4334 | ||
4335 | if (len) | |
4336 | goto safe_bareword; | |
4337 | ||
5069cc75 NC |
4338 | /* Do the explicit type check so that we don't need to force |
4339 | the initialisation of the symbol table to have a real GV. | |
4340 | Beware - gv may not really be a PVGV, cv may not really be | |
4341 | a PVCV, (because of the space optimisations that gv_init | |
4342 | understands) But they're true if for this symbol there is | |
4343 | respectively a typeglob and a subroutine. | |
4344 | */ | |
4345 | cv = gv ? ((SvTYPE(gv) == SVt_PVGV) | |
4346 | /* Real typeglob, so get the real subroutine: */ | |
4347 | ? GvCVu(gv) | |
4348 | /* A proxy for a subroutine in this package? */ | |
4349 | : SvOK(gv) ? (CV *) gv : NULL) | |
4350 | : NULL; | |
4351 | ||
8990e307 LW |
4352 | /* See if it's the indirect object for a list operator. */ |
4353 | ||
3280af22 NIS |
4354 | if (PL_oldoldbufptr && |
4355 | PL_oldoldbufptr < PL_bufptr && | |
65cec589 GS |
4356 | (PL_oldoldbufptr == PL_last_lop |
4357 | || PL_oldoldbufptr == PL_last_uni) && | |
a0d0e21e | 4358 | /* NO SKIPSPACE BEFORE HERE! */ |
a9ef352a GS |
4359 | (PL_expect == XREF || |
4360 | ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF)) | |
a0d0e21e | 4361 | { |
748a9306 LW |
4362 | bool immediate_paren = *s == '('; |
4363 | ||
a0d0e21e LW |
4364 | /* (Now we can afford to cross potential line boundary.) */ |
4365 | s = skipspace(s); | |
4366 | ||
4367 | /* Two barewords in a row may indicate method call. */ | |
4368 | ||
62d55b22 NC |
4369 | if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && |
4370 | (tmp = intuit_method(s, gv, cv))) | |
bbf60fe6 | 4371 | return REPORT(tmp); |
a0d0e21e LW |
4372 | |
4373 | /* If not a declared subroutine, it's an indirect object. */ | |
4374 | /* (But it's an indir obj regardless for sort.) */ | |
7294df96 | 4375 | /* Also, if "_" follows a filetest operator, it's a bareword */ |
a0d0e21e | 4376 | |
7294df96 RGS |
4377 | if ( |
4378 | ( !immediate_paren && (PL_last_lop_op == OP_SORT || | |
5069cc75 | 4379 | ((!gv || !cv) && |
a9ef352a | 4380 | (PL_last_lop_op != OP_MAPSTART && |
f0670693 | 4381 | PL_last_lop_op != OP_GREPSTART)))) |
7294df96 RGS |
4382 | || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0' |
4383 | && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP)) | |
4384 | ) | |
a9ef352a | 4385 | { |
3280af22 | 4386 | PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR; |
748a9306 | 4387 | goto bareword; |
93a17b20 LW |
4388 | } |
4389 | } | |
8990e307 | 4390 | |
3280af22 | 4391 | PL_expect = XOPERATOR; |
8990e307 | 4392 | s = skipspace(s); |
1c3923b3 GS |
4393 | |
4394 | /* Is this a word before a => operator? */ | |
ce29ac45 | 4395 | if (*s == '=' && s[1] == '>' && !pkgname) { |
1c3923b3 GS |
4396 | CLINE; |
4397 | sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf); | |
0064a8a9 | 4398 | if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len)) |
7948272d | 4399 | SvUTF8_on(((SVOP*)yylval.opval)->op_sv); |
1c3923b3 GS |
4400 | TERM(WORD); |
4401 | } | |
4402 | ||
4403 | /* If followed by a paren, it's certainly a subroutine. */ | |
93a17b20 | 4404 | if (*s == '(') { |
79072805 | 4405 | CLINE; |
5069cc75 | 4406 | if (cv) { |
bf4acbe4 | 4407 | for (d = s + 1; SPACE_OR_TAB(*d); d++) ; |
62d55b22 | 4408 | if (*d == ')' && (sv = gv_const_sv(gv))) { |
96e4d5b1 | 4409 | s = d + 1; |
4410 | goto its_constant; | |
4411 | } | |
4412 | } | |
3280af22 NIS |
4413 | PL_nextval[PL_nexttoke].opval = yylval.opval; |
4414 | PL_expect = XOPERATOR; | |
93a17b20 | 4415 | force_next(WORD); |
c07a80fd | 4416 | yylval.ival = 0; |
463ee0b2 | 4417 | TOKEN('&'); |
79072805 | 4418 | } |
93a17b20 | 4419 | |
a0d0e21e | 4420 | /* If followed by var or block, call it a method (unless sub) */ |
8990e307 | 4421 | |
62d55b22 | 4422 | if ((*s == '$' || *s == '{') && (!gv || !cv)) { |
3280af22 NIS |
4423 | PL_last_lop = PL_oldbufptr; |
4424 | PL_last_lop_op = OP_METHOD; | |
93a17b20 | 4425 | PREBLOCK(METHOD); |
463ee0b2 LW |
4426 | } |
4427 | ||
8990e307 LW |
4428 | /* If followed by a bareword, see if it looks like indir obj. */ |
4429 | ||
30fe34ed RGS |
4430 | if (!orig_keyword |
4431 | && (isIDFIRST_lazy_if(s,UTF) || *s == '$') | |
62d55b22 | 4432 | && (tmp = intuit_method(s, gv, cv))) |
bbf60fe6 | 4433 | return REPORT(tmp); |
93a17b20 | 4434 | |
8990e307 LW |
4435 | /* Not a method, so call it a subroutine (if defined) */ |
4436 | ||
5069cc75 | 4437 | if (cv) { |
0453d815 | 4438 | if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS)) |
9014280d | 4439 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
0453d815 | 4440 | "Ambiguous use of -%s resolved as -&%s()", |
3280af22 | 4441 | PL_tokenbuf, PL_tokenbuf); |
89bfa8cd | 4442 | /* Check for a constant sub */ |
62d55b22 | 4443 | if ((sv = gv_const_sv(gv))) { |
96e4d5b1 | 4444 | its_constant: |
4445 | SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv); | |
4446 | ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv); | |
4447 | yylval.opval->op_private = 0; | |
4448 | TOKEN(WORD); | |
89bfa8cd | 4449 | } |
4450 | ||
a5f75d66 | 4451 | /* Resolve to GV now. */ |
62d55b22 | 4452 | if (SvTYPE(gv) != SVt_PVGV) { |
b3d904f3 | 4453 | gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV); |
62d55b22 NC |
4454 | assert (SvTYPE(gv) == SVt_PVGV); |
4455 | /* cv must have been some sort of placeholder, so | |
4456 | now needs replacing with a real code reference. */ | |
4457 | cv = GvCV(gv); | |
4458 | } | |
4459 | ||
a5f75d66 AD |
4460 | op_free(yylval.opval); |
4461 | yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv)); | |
9675f7ac | 4462 | yylval.opval->op_private |= OPpENTERSUB_NOPAREN; |
7a52d87a | 4463 | PL_last_lop = PL_oldbufptr; |
bf848113 | 4464 | PL_last_lop_op = OP_ENTERSUB; |
4633a7c4 LW |
4465 | /* Is there a prototype? */ |
4466 | if (SvPOK(cv)) { | |
5f66b61c AL |
4467 | STRLEN protolen; |
4468 | const char *proto = SvPV_const((SV*)cv, protolen); | |
4469 | if (!protolen) | |
4633a7c4 | 4470 | TERM(FUNC0SUB); |
770526c1 | 4471 | if (*proto == '$' && proto[1] == '\0') |
4633a7c4 | 4472 | OPERATOR(UNIOPSUB); |
0f5d0394 AE |
4473 | while (*proto == ';') |
4474 | proto++; | |
7a52d87a | 4475 | if (*proto == '&' && *s == '{') { |
bfed75c6 | 4476 | sv_setpv(PL_subname, PL_curstash ? |
c99da370 | 4477 | "__ANON__" : "__ANON__::__ANON__"); |
4633a7c4 LW |
4478 | PREBLOCK(LSTOPSUB); |
4479 | } | |
a9ef352a | 4480 | } |
3280af22 NIS |
4481 | PL_nextval[PL_nexttoke].opval = yylval.opval; |
4482 | PL_expect = XTERM; | |
8990e307 LW |
4483 | force_next(WORD); |
4484 | TOKEN(NOAMP); | |
4485 | } | |
748a9306 | 4486 | |
8990e307 LW |
4487 | /* Call it a bare word */ |
4488 | ||
5603f27d GS |
4489 | if (PL_hints & HINT_STRICT_SUBS) |
4490 | yylval.opval->op_private |= OPpCONST_STRICT; | |
4491 | else { | |
4492 | bareword: | |
041457d9 DM |
4493 | if (lastchar != '-') { |
4494 | if (ckWARN(WARN_RESERVED)) { | |
5603f27d | 4495 | for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ; |
238ae712 | 4496 | if (!*d && !gv_stashpv(PL_tokenbuf,FALSE)) |
9014280d | 4497 | Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved, |
5603f27d GS |
4498 | PL_tokenbuf); |
4499 | } | |
748a9306 LW |
4500 | } |
4501 | } | |
c3e0f903 GS |
4502 | |
4503 | safe_bareword: | |
3792a11b NC |
4504 | if ((lastchar == '*' || lastchar == '%' || lastchar == '&') |
4505 | && ckWARN_d(WARN_AMBIGUOUS)) { | |
9014280d | 4506 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
0453d815 | 4507 | "Operator or semicolon missing before %c%s", |
3280af22 | 4508 | lastchar, PL_tokenbuf); |
9014280d | 4509 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
0453d815 | 4510 | "Ambiguous use of %c resolved as operator %c", |
748a9306 LW |
4511 | lastchar, lastchar); |
4512 | } | |
93a17b20 | 4513 | TOKEN(WORD); |
79072805 | 4514 | } |
79072805 | 4515 | |
68dc0745 | 4516 | case KEY___FILE__: |
46fc3d4c | 4517 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
ed094faf | 4518 | newSVpv(CopFILE(PL_curcop),0)); |
46fc3d4c | 4519 | TERM(THING); |
4520 | ||
79072805 | 4521 | case KEY___LINE__: |
cf2093f6 | 4522 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
57843af0 | 4523 | Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop))); |
79072805 | 4524 | TERM(THING); |
68dc0745 | 4525 | |
4526 | case KEY___PACKAGE__: | |
4527 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, | |
3280af22 | 4528 | (PL_curstash |
5aaec2b4 | 4529 | ? newSVhek(HvNAME_HEK(PL_curstash)) |
3280af22 | 4530 | : &PL_sv_undef)); |
79072805 | 4531 | TERM(THING); |
79072805 | 4532 | |
e50aee73 | 4533 | case KEY___DATA__: |
79072805 LW |
4534 | case KEY___END__: { |
4535 | GV *gv; | |
3280af22 | 4536 | if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) { |
bfed75c6 | 4537 | const char *pname = "main"; |
3280af22 | 4538 | if (PL_tokenbuf[2] == 'D') |
bfcb3514 | 4539 | pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash); |
f776e3cd NC |
4540 | gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD, |
4541 | SVt_PVIO); | |
a5f75d66 | 4542 | GvMULTI_on(gv); |
79072805 | 4543 | if (!GvIO(gv)) |
a0d0e21e | 4544 | GvIOp(gv) = newIO(); |
3280af22 | 4545 | IoIFP(GvIOp(gv)) = PL_rsfp; |
a0d0e21e LW |
4546 | #if defined(HAS_FCNTL) && defined(F_SETFD) |
4547 | { | |
f54cb97a | 4548 | const int fd = PerlIO_fileno(PL_rsfp); |
a0d0e21e LW |
4549 | fcntl(fd,F_SETFD,fd >= 3); |
4550 | } | |
79072805 | 4551 | #endif |
fd049845 | 4552 | /* Mark this internal pseudo-handle as clean */ |
4553 | IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT; | |
3280af22 | 4554 | if (PL_preprocess) |
50952442 | 4555 | IoTYPE(GvIOp(gv)) = IoTYPE_PIPE; |
3280af22 | 4556 | else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) |
50952442 | 4557 | IoTYPE(GvIOp(gv)) = IoTYPE_STD; |
79072805 | 4558 | else |
50952442 | 4559 | IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY; |
c39cd008 GS |
4560 | #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS) |
4561 | /* if the script was opened in binmode, we need to revert | |
53129d29 | 4562 | * it to text mode for compatibility; but only iff it has CRs |
c39cd008 | 4563 | * XXX this is a questionable hack at best. */ |
53129d29 GS |
4564 | if (PL_bufend-PL_bufptr > 2 |
4565 | && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r') | |
c39cd008 GS |
4566 | { |
4567 | Off_t loc = 0; | |
50952442 | 4568 | if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) { |
c39cd008 GS |
4569 | loc = PerlIO_tell(PL_rsfp); |
4570 | (void)PerlIO_seek(PL_rsfp, 0L, 0); | |
4571 | } | |
2986a63f JH |
4572 | #ifdef NETWARE |
4573 | if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) { | |
4574 | #else | |
c39cd008 | 4575 | if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) { |
2986a63f | 4576 | #endif /* NETWARE */ |
1143fce0 JH |
4577 | #ifdef PERLIO_IS_STDIO /* really? */ |
4578 | # if defined(__BORLANDC__) | |
cb359b41 JH |
4579 | /* XXX see note in do_binmode() */ |
4580 | ((FILE*)PL_rsfp)->flags &= ~_F_BIN; | |
1143fce0 JH |
4581 | # endif |
4582 | #endif | |
c39cd008 GS |
4583 | if (loc > 0) |
4584 | PerlIO_seek(PL_rsfp, loc, 0); | |
4585 | } | |
4586 | } | |
4587 | #endif | |
7948272d | 4588 | #ifdef PERLIO_LAYERS |
52d2e0f4 JH |
4589 | if (!IN_BYTES) { |
4590 | if (UTF) | |
4591 | PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8"); | |
4592 | else if (PL_encoding) { | |
4593 | SV *name; | |
4594 | dSP; | |
4595 | ENTER; | |
4596 | SAVETMPS; | |
4597 | PUSHMARK(sp); | |
4598 | EXTEND(SP, 1); | |
4599 | XPUSHs(PL_encoding); | |
4600 | PUTBACK; | |
4601 | call_method("name", G_SCALAR); | |
4602 | SPAGAIN; | |
4603 | name = POPs; | |
4604 | PUTBACK; | |
bfed75c6 | 4605 | PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, |
52d2e0f4 JH |
4606 | Perl_form(aTHX_ ":encoding(%"SVf")", |
4607 | name)); | |
4608 | FREETMPS; | |
4609 | LEAVE; | |
4610 | } | |
4611 | } | |
7948272d | 4612 | #endif |
4608196e | 4613 | PL_rsfp = NULL; |
79072805 LW |
4614 | } |
4615 | goto fake_eof; | |
e929a76b | 4616 | } |
de3bb511 | 4617 | |
8990e307 | 4618 | case KEY_AUTOLOAD: |
ed6116ce | 4619 | case KEY_DESTROY: |
79072805 | 4620 | case KEY_BEGIN: |
7d30b5c4 | 4621 | case KEY_CHECK: |
7d07dbc2 | 4622 | case KEY_INIT: |
7d30b5c4 | 4623 | case KEY_END: |
3280af22 NIS |
4624 | if (PL_expect == XSTATE) { |
4625 | s = PL_bufptr; | |
93a17b20 | 4626 | goto really_sub; |
79072805 LW |
4627 | } |
4628 | goto just_a_word; | |
4629 | ||
a0d0e21e LW |
4630 | case KEY_CORE: |
4631 | if (*s == ':' && s[1] == ':') { | |
4632 | s += 2; | |
748a9306 | 4633 | d = s; |
3280af22 | 4634 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
6798c92b GS |
4635 | if (!(tmp = keyword(PL_tokenbuf, len))) |
4636 | Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf); | |
a0d0e21e LW |
4637 | if (tmp < 0) |
4638 | tmp = -tmp; | |
850e8516 | 4639 | else if (tmp == KEY_require || tmp == KEY_do) |
a72a1c8b | 4640 | /* that's a way to remember we saw "CORE::" */ |
850e8516 | 4641 | orig_keyword = tmp; |
a0d0e21e LW |
4642 | goto reserved_word; |
4643 | } | |
4644 | goto just_a_word; | |
4645 | ||
463ee0b2 LW |
4646 | case KEY_abs: |
4647 | UNI(OP_ABS); | |
4648 | ||
79072805 LW |
4649 | case KEY_alarm: |
4650 | UNI(OP_ALARM); | |
4651 | ||
4652 | case KEY_accept: | |
a0d0e21e | 4653 | LOP(OP_ACCEPT,XTERM); |
79072805 | 4654 | |
463ee0b2 LW |
4655 | case KEY_and: |
4656 | OPERATOR(ANDOP); | |
4657 | ||
79072805 | 4658 | case KEY_atan2: |
a0d0e21e | 4659 | LOP(OP_ATAN2,XTERM); |
85e6fe83 | 4660 | |
79072805 | 4661 | case KEY_bind: |
a0d0e21e | 4662 | LOP(OP_BIND,XTERM); |
79072805 LW |
4663 | |
4664 | case KEY_binmode: | |
1c1fc3ea | 4665 | LOP(OP_BINMODE,XTERM); |
79072805 LW |
4666 | |
4667 | case KEY_bless: | |
a0d0e21e | 4668 | LOP(OP_BLESS,XTERM); |
79072805 | 4669 | |
0d863452 RH |
4670 | case KEY_break: |
4671 | FUN0(OP_BREAK); | |
4672 | ||
79072805 LW |
4673 | case KEY_chop: |
4674 | UNI(OP_CHOP); | |
4675 | ||
4676 | case KEY_continue: | |
0d863452 RH |
4677 | /* When 'use switch' is in effect, continue has a dual |
4678 | life as a control operator. */ | |
4679 | { | |
ef89dcc3 | 4680 | if (!FEATURE_IS_ENABLED("switch")) |
0d863452 RH |
4681 | PREBLOCK(CONTINUE); |
4682 | else { | |
4683 | /* We have to disambiguate the two senses of | |
4684 | "continue". If the next token is a '{' then | |
4685 | treat it as the start of a continue block; | |
4686 | otherwise treat it as a control operator. | |
4687 | */ | |
4688 | s = skipspace(s); | |
4689 | if (*s == '{') | |
79072805 | 4690 | PREBLOCK(CONTINUE); |
0d863452 RH |
4691 | else |
4692 | FUN0(OP_CONTINUE); | |
4693 | } | |
4694 | } | |
79072805 LW |
4695 | |
4696 | case KEY_chdir: | |
fafc274c NC |
4697 | /* may use HOME */ |
4698 | (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV); | |
79072805 LW |
4699 | UNI(OP_CHDIR); |
4700 | ||
4701 | case KEY_close: | |
4702 | UNI(OP_CLOSE); | |
4703 | ||
4704 | case KEY_closedir: | |
4705 | UNI(OP_CLOSEDIR); | |
4706 | ||
4707 | case KEY_cmp: | |
4708 | Eop(OP_SCMP); | |
4709 | ||
4710 | case KEY_caller: | |
4711 | UNI(OP_CALLER); | |
4712 | ||
4713 | case KEY_crypt: | |
4714 | #ifdef FCRYPT | |
f4c556ac GS |
4715 | if (!PL_cryptseen) { |
4716 | PL_cryptseen = TRUE; | |
de3bb511 | 4717 | init_des(); |
f4c556ac | 4718 | } |
a687059c | 4719 | #endif |
a0d0e21e | 4720 | LOP(OP_CRYPT,XTERM); |
79072805 LW |
4721 | |
4722 | case KEY_chmod: | |
a0d0e21e | 4723 | LOP(OP_CHMOD,XTERM); |
79072805 LW |
4724 | |
4725 | case KEY_chown: | |
a0d0e21e | 4726 | LOP(OP_CHOWN,XTERM); |
79072805 LW |
4727 | |
4728 | case KEY_connect: | |
a0d0e21e | 4729 | LOP(OP_CONNECT,XTERM); |
79072805 | 4730 | |
463ee0b2 LW |
4731 | case KEY_chr: |
4732 | UNI(OP_CHR); | |
4733 | ||
79072805 LW |
4734 | case KEY_cos: |
4735 | UNI(OP_COS); | |
4736 | ||
4737 | case KEY_chroot: | |
4738 | UNI(OP_CHROOT); | |
4739 | ||
0d863452 RH |
4740 | case KEY_default: |
4741 | PREBLOCK(DEFAULT); | |
4742 | ||
79072805 LW |
4743 | case KEY_do: |
4744 | s = skipspace(s); | |
4745 | if (*s == '{') | |
a0d0e21e | 4746 | PRETERMBLOCK(DO); |
79072805 | 4747 | if (*s != '\'') |
89c5585f | 4748 | s = force_word(s,WORD,TRUE,TRUE,FALSE); |
850e8516 RGS |
4749 | if (orig_keyword == KEY_do) { |
4750 | orig_keyword = 0; | |
4751 | yylval.ival = 1; | |
4752 | } | |
4753 | else | |
4754 | yylval.ival = 0; | |
378cc40b | 4755 | OPERATOR(DO); |
79072805 LW |
4756 | |
4757 | case KEY_die: | |
3280af22 | 4758 | PL_hints |= HINT_BLOCK_SCOPE; |
a0d0e21e | 4759 | LOP(OP_DIE,XTERM); |
79072805 LW |
4760 | |
4761 | case KEY_defined: | |
4762 | UNI(OP_DEFINED); | |
4763 | ||
4764 | case KEY_delete: | |
a0d0e21e | 4765 | UNI(OP_DELETE); |
79072805 LW |
4766 | |
4767 | case KEY_dbmopen: | |
5c1737d1 | 4768 | gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV); |
a0d0e21e | 4769 | LOP(OP_DBMOPEN,XTERM); |
79072805 LW |
4770 | |
4771 | case KEY_dbmclose: | |
4772 | UNI(OP_DBMCLOSE); | |
4773 | ||
4774 | case KEY_dump: | |
a0d0e21e | 4775 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4776 | LOOPX(OP_DUMP); |
4777 | ||
4778 | case KEY_else: | |
4779 | PREBLOCK(ELSE); | |
4780 | ||
4781 | case KEY_elsif: | |
57843af0 | 4782 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
4783 | OPERATOR(ELSIF); |
4784 | ||
4785 | case KEY_eq: | |
4786 | Eop(OP_SEQ); | |
4787 | ||
a0d0e21e LW |
4788 | case KEY_exists: |
4789 | UNI(OP_EXISTS); | |
4e553d73 | 4790 | |
79072805 LW |
4791 | case KEY_exit: |
4792 | UNI(OP_EXIT); | |
4793 | ||
4794 | case KEY_eval: | |
79072805 | 4795 | s = skipspace(s); |
3280af22 | 4796 | PL_expect = (*s == '{') ? XTERMBLOCK : XTERM; |
463ee0b2 | 4797 | UNIBRACK(OP_ENTEREVAL); |
79072805 LW |
4798 | |
4799 | case KEY_eof: | |
4800 | UNI(OP_EOF); | |
4801 | ||
c963b151 BD |
4802 | case KEY_err: |
4803 | OPERATOR(DOROP); | |
4804 | ||
79072805 LW |
4805 | case KEY_exp: |
4806 | UNI(OP_EXP); | |
4807 | ||
4808 | case KEY_each: | |
4809 | UNI(OP_EACH); | |
4810 | ||
4811 | case KEY_exec: | |
4812 | set_csh(); | |
a0d0e21e | 4813 | LOP(OP_EXEC,XREF); |
79072805 LW |
4814 | |
4815 | case KEY_endhostent: | |
4816 | FUN0(OP_EHOSTENT); | |
4817 | ||
4818 | case KEY_endnetent: | |
4819 | FUN0(OP_ENETENT); | |
4820 | ||
4821 | case KEY_endservent: | |
4822 | FUN0(OP_ESERVENT); | |
4823 | ||
4824 | case KEY_endprotoent: | |
4825 | FUN0(OP_EPROTOENT); | |
4826 | ||
4827 | case KEY_endpwent: | |
4828 | FUN0(OP_EPWENT); | |
4829 | ||
4830 | case KEY_endgrent: | |
4831 | FUN0(OP_EGRENT); | |
4832 | ||
4833 | case KEY_for: | |
4834 | case KEY_foreach: | |
57843af0 | 4835 | yylval.ival = CopLINE(PL_curcop); |
55497cff | 4836 | s = skipspace(s); |
7e2040f0 | 4837 | if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) { |
55497cff | 4838 | char *p = s; |
3280af22 | 4839 | if ((PL_bufend - p) >= 3 && |
55497cff | 4840 | strnEQ(p, "my", 2) && isSPACE(*(p + 2))) |
4841 | p += 2; | |
77ca0c92 LW |
4842 | else if ((PL_bufend - p) >= 4 && |
4843 | strnEQ(p, "our", 3) && isSPACE(*(p + 3))) | |
4844 | p += 3; | |
55497cff | 4845 | p = skipspace(p); |
7e2040f0 | 4846 | if (isIDFIRST_lazy_if(p,UTF)) { |
77ca0c92 LW |
4847 | p = scan_ident(p, PL_bufend, |
4848 | PL_tokenbuf, sizeof PL_tokenbuf, TRUE); | |
4849 | p = skipspace(p); | |
4850 | } | |
4851 | if (*p != '$') | |
cea2e8a9 | 4852 | Perl_croak(aTHX_ "Missing $ on loop variable"); |
55497cff | 4853 | } |
79072805 LW |
4854 | OPERATOR(FOR); |
4855 | ||
4856 | case KEY_formline: | |
a0d0e21e | 4857 | LOP(OP_FORMLINE,XTERM); |
79072805 LW |
4858 | |
4859 | case KEY_fork: | |
4860 | FUN0(OP_FORK); | |
4861 | ||
4862 | case KEY_fcntl: | |
a0d0e21e | 4863 | LOP(OP_FCNTL,XTERM); |
79072805 LW |
4864 | |
4865 | case KEY_fileno: | |
4866 | UNI(OP_FILENO); | |
4867 | ||
4868 | case KEY_flock: | |
a0d0e21e | 4869 | LOP(OP_FLOCK,XTERM); |
79072805 LW |
4870 | |
4871 | case KEY_gt: | |
4872 | Rop(OP_SGT); | |
4873 | ||
4874 | case KEY_ge: | |
4875 | Rop(OP_SGE); | |
4876 | ||
4877 | case KEY_grep: | |
2c38e13d | 4878 | LOP(OP_GREPSTART, XREF); |
79072805 LW |
4879 | |
4880 | case KEY_goto: | |
a0d0e21e | 4881 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4882 | LOOPX(OP_GOTO); |
4883 | ||
4884 | case KEY_gmtime: | |
4885 | UNI(OP_GMTIME); | |
4886 | ||
4887 | case KEY_getc: | |
6f33ba73 | 4888 | UNIDOR(OP_GETC); |
79072805 LW |
4889 | |
4890 | case KEY_getppid: | |
4891 | FUN0(OP_GETPPID); | |
4892 | ||
4893 | case KEY_getpgrp: | |
4894 | UNI(OP_GETPGRP); | |
4895 | ||
4896 | case KEY_getpriority: | |
a0d0e21e | 4897 | LOP(OP_GETPRIORITY,XTERM); |
79072805 LW |
4898 | |
4899 | case KEY_getprotobyname: | |
4900 | UNI(OP_GPBYNAME); | |
4901 | ||
4902 | case KEY_getprotobynumber: | |
a0d0e21e | 4903 | LOP(OP_GPBYNUMBER,XTERM); |
79072805 LW |
4904 | |
4905 | case KEY_getprotoent: | |
4906 | FUN0(OP_GPROTOENT); | |
4907 | ||
4908 | case KEY_getpwent: | |
4909 | FUN0(OP_GPWENT); | |
4910 | ||
4911 | case KEY_getpwnam: | |
ff68c719 | 4912 | UNI(OP_GPWNAM); |
79072805 LW |
4913 | |
4914 | case KEY_getpwuid: | |
ff68c719 | 4915 | UNI(OP_GPWUID); |
79072805 LW |
4916 | |
4917 | case KEY_getpeername: | |
4918 | UNI(OP_GETPEERNAME); | |
4919 | ||
4920 | case KEY_gethostbyname: | |
4921 | UNI(OP_GHBYNAME); | |
4922 | ||
4923 | case KEY_gethostbyaddr: | |
a0d0e21e | 4924 | LOP(OP_GHBYADDR,XTERM); |
79072805 LW |
4925 | |
4926 | case KEY_gethostent: | |
4927 | FUN0(OP_GHOSTENT); | |
4928 | ||
4929 | case KEY_getnetbyname: | |
4930 | UNI(OP_GNBYNAME); | |
4931 | ||
4932 | case KEY_getnetbyaddr: | |
a0d0e21e | 4933 | LOP(OP_GNBYADDR,XTERM); |
79072805 LW |
4934 | |
4935 | case KEY_getnetent: | |
4936 | FUN0(OP_GNETENT); | |
4937 | ||
4938 | case KEY_getservbyname: | |
a0d0e21e | 4939 | LOP(OP_GSBYNAME,XTERM); |
79072805 LW |
4940 | |
4941 | case KEY_getservbyport: | |
a0d0e21e | 4942 | LOP(OP_GSBYPORT,XTERM); |
79072805 LW |
4943 | |
4944 | case KEY_getservent: | |
4945 | FUN0(OP_GSERVENT); | |
4946 | ||
4947 | case KEY_getsockname: | |
4948 | UNI(OP_GETSOCKNAME); | |
4949 | ||
4950 | case KEY_getsockopt: | |
a0d0e21e | 4951 | LOP(OP_GSOCKOPT,XTERM); |
79072805 LW |
4952 | |
4953 | case KEY_getgrent: | |
4954 | FUN0(OP_GGRENT); | |
4955 | ||
4956 | case KEY_getgrnam: | |
ff68c719 | 4957 | UNI(OP_GGRNAM); |
79072805 LW |
4958 | |
4959 | case KEY_getgrgid: | |
ff68c719 | 4960 | UNI(OP_GGRGID); |
79072805 LW |
4961 | |
4962 | case KEY_getlogin: | |
4963 | FUN0(OP_GETLOGIN); | |
4964 | ||
0d863452 RH |
4965 | case KEY_given: |
4966 | yylval.ival = CopLINE(PL_curcop); | |
4967 | OPERATOR(GIVEN); | |
4968 | ||
93a17b20 | 4969 | case KEY_glob: |
a0d0e21e LW |
4970 | set_csh(); |
4971 | LOP(OP_GLOB,XTERM); | |
93a17b20 | 4972 | |
79072805 LW |
4973 | case KEY_hex: |
4974 | UNI(OP_HEX); | |
4975 | ||
4976 | case KEY_if: | |
57843af0 | 4977 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
4978 | OPERATOR(IF); |
4979 | ||
4980 | case KEY_index: | |
a0d0e21e | 4981 | LOP(OP_INDEX,XTERM); |
79072805 LW |
4982 | |
4983 | case KEY_int: | |
4984 | UNI(OP_INT); | |
4985 | ||
4986 | case KEY_ioctl: | |
a0d0e21e | 4987 | LOP(OP_IOCTL,XTERM); |
79072805 LW |
4988 | |
4989 | case KEY_join: | |
a0d0e21e | 4990 | LOP(OP_JOIN,XTERM); |
79072805 LW |
4991 | |
4992 | case KEY_keys: | |
4993 | UNI(OP_KEYS); | |
4994 | ||
4995 | case KEY_kill: | |
a0d0e21e | 4996 | LOP(OP_KILL,XTERM); |
79072805 LW |
4997 | |
4998 | case KEY_last: | |
a0d0e21e | 4999 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 | 5000 | LOOPX(OP_LAST); |
4e553d73 | 5001 | |
79072805 LW |
5002 | case KEY_lc: |
5003 | UNI(OP_LC); | |
5004 | ||
5005 | case KEY_lcfirst: | |
5006 | UNI(OP_LCFIRST); | |
5007 | ||
5008 | case KEY_local: | |
09bef843 | 5009 | yylval.ival = 0; |
79072805 LW |
5010 | OPERATOR(LOCAL); |
5011 | ||
5012 | case KEY_length: | |
5013 | UNI(OP_LENGTH); | |
5014 | ||
5015 | case KEY_lt: | |
5016 | Rop(OP_SLT); | |
5017 | ||
5018 | case KEY_le: | |
5019 | Rop(OP_SLE); | |
5020 | ||
5021 | case KEY_localtime: | |
5022 | UNI(OP_LOCALTIME); | |
5023 | ||
5024 | case KEY_log: | |
5025 | UNI(OP_LOG); | |
5026 | ||
5027 | case KEY_link: | |
a0d0e21e | 5028 | LOP(OP_LINK,XTERM); |
79072805 LW |
5029 | |
5030 | case KEY_listen: | |
a0d0e21e | 5031 | LOP(OP_LISTEN,XTERM); |
79072805 | 5032 | |
c0329465 MB |
5033 | case KEY_lock: |
5034 | UNI(OP_LOCK); | |
5035 | ||
79072805 LW |
5036 | case KEY_lstat: |
5037 | UNI(OP_LSTAT); | |
5038 | ||
5039 | case KEY_m: | |
8782bef2 | 5040 | s = scan_pat(s,OP_MATCH); |
79072805 LW |
5041 | TERM(sublex_start()); |
5042 | ||
a0d0e21e | 5043 | case KEY_map: |
2c38e13d | 5044 | LOP(OP_MAPSTART, XREF); |
4e4e412b | 5045 | |
79072805 | 5046 | case KEY_mkdir: |
a0d0e21e | 5047 | LOP(OP_MKDIR,XTERM); |
79072805 LW |
5048 | |
5049 | case KEY_msgctl: | |
a0d0e21e | 5050 | LOP(OP_MSGCTL,XTERM); |
79072805 LW |
5051 | |
5052 | case KEY_msgget: | |
a0d0e21e | 5053 | LOP(OP_MSGGET,XTERM); |
79072805 LW |
5054 | |
5055 | case KEY_msgrcv: | |
a0d0e21e | 5056 | LOP(OP_MSGRCV,XTERM); |
79072805 LW |
5057 | |
5058 | case KEY_msgsnd: | |
a0d0e21e | 5059 | LOP(OP_MSGSND,XTERM); |
79072805 | 5060 | |
77ca0c92 | 5061 | case KEY_our: |
93a17b20 | 5062 | case KEY_my: |
77ca0c92 | 5063 | PL_in_my = tmp; |
c750a3ec | 5064 | s = skipspace(s); |
7e2040f0 | 5065 | if (isIDFIRST_lazy_if(s,UTF)) { |
3280af22 | 5066 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len); |
09bef843 SB |
5067 | if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3)) |
5068 | goto really_sub; | |
def3634b | 5069 | PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len); |
3280af22 | 5070 | if (!PL_in_my_stash) { |
c750a3ec | 5071 | char tmpbuf[1024]; |
3280af22 NIS |
5072 | PL_bufptr = s; |
5073 | sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf); | |
c750a3ec MB |
5074 | yyerror(tmpbuf); |
5075 | } | |
5076 | } | |
09bef843 | 5077 | yylval.ival = 1; |
55497cff | 5078 | OPERATOR(MY); |
93a17b20 | 5079 | |
79072805 | 5080 | case KEY_next: |
a0d0e21e | 5081 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
5082 | LOOPX(OP_NEXT); |
5083 | ||
5084 | case KEY_ne: | |
5085 | Eop(OP_SNE); | |
5086 | ||
a0d0e21e | 5087 | case KEY_no: |
468aa647 | 5088 | s = tokenize_use(0, s); |
a0d0e21e LW |
5089 | OPERATOR(USE); |
5090 | ||
5091 | case KEY_not: | |
2d2e263d LW |
5092 | if (*s == '(' || (s = skipspace(s), *s == '(')) |
5093 | FUN1(OP_NOT); | |
5094 | else | |
5095 | OPERATOR(NOTOP); | |
a0d0e21e | 5096 | |
79072805 | 5097 | case KEY_open: |
93a17b20 | 5098 | s = skipspace(s); |
7e2040f0 | 5099 | if (isIDFIRST_lazy_if(s,UTF)) { |
f54cb97a | 5100 | const char *t; |
7e2040f0 | 5101 | for (d = s; isALNUM_lazy_if(d,UTF); d++) ; |
e2ab214b DM |
5102 | for (t=d; *t && isSPACE(*t); t++) ; |
5103 | if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE) | |
66fbe8fb HS |
5104 | /* [perl #16184] */ |
5105 | && !(t[0] == '=' && t[1] == '>') | |
5106 | ) { | |
5f66b61c | 5107 | int parms_len = (int)(d-s); |
9014280d | 5108 | Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE), |
0453d815 | 5109 | "Precedence problem: open %.*s should be open(%.*s)", |
5f66b61c | 5110 | parms_len, s, parms_len, s); |
66fbe8fb | 5111 | } |
93a17b20 | 5112 | } |
a0d0e21e | 5113 | LOP(OP_OPEN,XTERM); |
79072805 | 5114 | |
463ee0b2 | 5115 | case KEY_or: |
a0d0e21e | 5116 | yylval.ival = OP_OR; |
463ee0b2 LW |
5117 | OPERATOR(OROP); |
5118 | ||
79072805 LW |
5119 | case KEY_ord: |
5120 | UNI(OP_ORD); | |
5121 | ||
5122 | case KEY_oct: | |
5123 | UNI(OP_OCT); | |
5124 | ||
5125 | case KEY_opendir: | |
a0d0e21e | 5126 | LOP(OP_OPEN_DIR,XTERM); |
79072805 LW |
5127 | |
5128 | case KEY_print: | |
3280af22 | 5129 | checkcomma(s,PL_tokenbuf,"filehandle"); |
a0d0e21e | 5130 | LOP(OP_PRINT,XREF); |
79072805 LW |
5131 | |
5132 | case KEY_printf: | |
3280af22 | 5133 | checkcomma(s,PL_tokenbuf,"filehandle"); |
a0d0e21e | 5134 | LOP(OP_PRTF,XREF); |
79072805 | 5135 | |
c07a80fd | 5136 | case KEY_prototype: |
5137 | UNI(OP_PROTOTYPE); | |
5138 | ||
79072805 | 5139 | case KEY_push: |
a0d0e21e | 5140 | LOP(OP_PUSH,XTERM); |
79072805 LW |
5141 | |
5142 | case KEY_pop: | |
6f33ba73 | 5143 | UNIDOR(OP_POP); |
79072805 | 5144 | |
a0d0e21e | 5145 | case KEY_pos: |
6f33ba73 | 5146 | UNIDOR(OP_POS); |
4e553d73 | 5147 | |
79072805 | 5148 | case KEY_pack: |
a0d0e21e | 5149 | LOP(OP_PACK,XTERM); |
79072805 LW |
5150 | |
5151 | case KEY_package: | |
a0d0e21e | 5152 | s = force_word(s,WORD,FALSE,TRUE,FALSE); |
79072805 LW |
5153 | OPERATOR(PACKAGE); |
5154 | ||
5155 | case KEY_pipe: | |
a0d0e21e | 5156 | LOP(OP_PIPE_OP,XTERM); |
79072805 LW |
5157 | |
5158 | case KEY_q: | |
09bef843 | 5159 | s = scan_str(s,FALSE,FALSE); |
79072805 | 5160 | if (!s) |
85e6fe83 | 5161 | missingterm((char*)0); |
79072805 LW |
5162 | yylval.ival = OP_CONST; |
5163 | TERM(sublex_start()); | |
5164 | ||
a0d0e21e LW |
5165 | case KEY_quotemeta: |
5166 | UNI(OP_QUOTEMETA); | |
5167 | ||
8990e307 | 5168 | case KEY_qw: |
09bef843 | 5169 | s = scan_str(s,FALSE,FALSE); |
8990e307 | 5170 | if (!s) |
85e6fe83 | 5171 | missingterm((char*)0); |
3480a8d2 | 5172 | PL_expect = XOPERATOR; |
8127e0e3 GS |
5173 | force_next(')'); |
5174 | if (SvCUR(PL_lex_stuff)) { | |
5f66b61c | 5175 | OP *words = NULL; |
8127e0e3 | 5176 | int warned = 0; |
3280af22 | 5177 | d = SvPV_force(PL_lex_stuff, len); |
8127e0e3 | 5178 | while (len) { |
7948272d | 5179 | SV *sv; |
8127e0e3 GS |
5180 | for (; isSPACE(*d) && len; --len, ++d) ; |
5181 | if (len) { | |
f54cb97a | 5182 | const char *b = d; |
e476b1b5 | 5183 | if (!warned && ckWARN(WARN_QW)) { |
8127e0e3 GS |
5184 | for (; !isSPACE(*d) && len; --len, ++d) { |
5185 | if (*d == ',') { | |
9014280d | 5186 | Perl_warner(aTHX_ packWARN(WARN_QW), |
8127e0e3 GS |
5187 | "Possible attempt to separate words with commas"); |
5188 | ++warned; | |
5189 | } | |
5190 | else if (*d == '#') { | |
9014280d | 5191 | Perl_warner(aTHX_ packWARN(WARN_QW), |
8127e0e3 GS |
5192 | "Possible attempt to put comments in qw() list"); |
5193 | ++warned; | |
5194 | } | |
5195 | } | |
5196 | } | |
5197 | else { | |
5198 | for (; !isSPACE(*d) && len; --len, ++d) ; | |
5199 | } | |
7948272d NIS |
5200 | sv = newSVpvn(b, d-b); |
5201 | if (DO_UTF8(PL_lex_stuff)) | |
5202 | SvUTF8_on(sv); | |
8127e0e3 | 5203 | words = append_elem(OP_LIST, words, |
7948272d | 5204 | newSVOP(OP_CONST, 0, tokeq(sv))); |
55497cff | 5205 | } |
5206 | } | |
8127e0e3 GS |
5207 | if (words) { |
5208 | PL_nextval[PL_nexttoke].opval = words; | |
5209 | force_next(THING); | |
5210 | } | |
55497cff | 5211 | } |
37fd879b | 5212 | if (PL_lex_stuff) { |
8127e0e3 | 5213 | SvREFCNT_dec(PL_lex_stuff); |
a0714e2c | 5214 | PL_lex_stuff = NULL; |
37fd879b | 5215 | } |
3280af22 | 5216 | PL_expect = XTERM; |
8127e0e3 | 5217 | TOKEN('('); |
8990e307 | 5218 | |
79072805 | 5219 | case KEY_qq: |
09bef843 | 5220 | s = scan_str(s,FALSE,FALSE); |
79072805 | 5221 | if (!s) |
85e6fe83 | 5222 | missingterm((char*)0); |
a0d0e21e | 5223 | yylval.ival = OP_STRINGIFY; |
3280af22 | 5224 | if (SvIVX(PL_lex_stuff) == '\'') |
45977657 | 5225 | SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */ |
79072805 LW |
5226 | TERM(sublex_start()); |
5227 | ||
8782bef2 GB |
5228 | case KEY_qr: |
5229 | s = scan_pat(s,OP_QR); | |
5230 | TERM(sublex_start()); | |
5231 | ||
79072805 | 5232 | case KEY_qx: |
09bef843 | 5233 | s = scan_str(s,FALSE,FALSE); |
79072805 | 5234 | if (!s) |
85e6fe83 | 5235 | missingterm((char*)0); |
79072805 LW |
5236 | yylval.ival = OP_BACKTICK; |
5237 | set_csh(); | |
5238 | TERM(sublex_start()); | |
5239 | ||
5240 | case KEY_return: | |
5241 | OLDLOP(OP_RETURN); | |
5242 | ||
5243 | case KEY_require: | |
a7cb1f99 | 5244 | s = skipspace(s); |
e759cc13 RGS |
5245 | if (isDIGIT(*s)) { |
5246 | s = force_version(s, FALSE); | |
a7cb1f99 | 5247 | } |
e759cc13 RGS |
5248 | else if (*s != 'v' || !isDIGIT(s[1]) |
5249 | || (s = force_version(s, TRUE), *s == 'v')) | |
5250 | { | |
a7cb1f99 GS |
5251 | *PL_tokenbuf = '\0'; |
5252 | s = force_word(s,WORD,TRUE,TRUE,FALSE); | |
7e2040f0 | 5253 | if (isIDFIRST_lazy_if(PL_tokenbuf,UTF)) |
a7cb1f99 GS |
5254 | gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE); |
5255 | else if (*s == '<') | |
5256 | yyerror("<> should be quotes"); | |
5257 | } | |
a72a1c8b RGS |
5258 | if (orig_keyword == KEY_require) { |
5259 | orig_keyword = 0; | |
5260 | yylval.ival = 1; | |
5261 | } | |
5262 | else | |
5263 | yylval.ival = 0; | |
5264 | PL_expect = XTERM; | |
5265 | PL_bufptr = s; | |
5266 | PL_last_uni = PL_oldbufptr; | |
5267 | PL_last_lop_op = OP_REQUIRE; | |
5268 | s = skipspace(s); | |
5269 | return REPORT( (int)REQUIRE ); | |
79072805 LW |
5270 | |
5271 | case KEY_reset: | |
5272 | UNI(OP_RESET); | |
5273 | ||
5274 | case KEY_redo: | |
a0d0e21e | 5275 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
5276 | LOOPX(OP_REDO); |
5277 | ||
5278 | case KEY_rename: | |
a0d0e21e | 5279 | LOP(OP_RENAME,XTERM); |
79072805 LW |
5280 | |
5281 | case KEY_rand: | |
5282 | UNI(OP_RAND); | |
5283 | ||
5284 | case KEY_rmdir: | |
5285 | UNI(OP_RMDIR); | |
5286 | ||
5287 | case KEY_rindex: | |
a0d0e21e | 5288 | LOP(OP_RINDEX,XTERM); |
79072805 LW |
5289 | |
5290 | case KEY_read: | |
a0d0e21e | 5291 | LOP(OP_READ,XTERM); |
79072805 LW |
5292 | |
5293 | case KEY_readdir: | |
5294 | UNI(OP_READDIR); | |
5295 | ||
93a17b20 LW |
5296 | case KEY_readline: |
5297 | set_csh(); | |
6f33ba73 | 5298 | UNIDOR(OP_READLINE); |
93a17b20 LW |
5299 | |
5300 | case KEY_readpipe: | |
5301 | set_csh(); | |
5302 | UNI(OP_BACKTICK); | |
5303 | ||
79072805 LW |
5304 | case KEY_rewinddir: |
5305 | UNI(OP_REWINDDIR); | |
5306 | ||
5307 | case KEY_recv: | |
a0d0e21e | 5308 | LOP(OP_RECV,XTERM); |
79072805 LW |
5309 | |
5310 | case KEY_reverse: | |
a0d0e21e | 5311 | LOP(OP_REVERSE,XTERM); |
79072805 LW |
5312 | |
5313 | case KEY_readlink: | |
6f33ba73 | 5314 | UNIDOR(OP_READLINK); |
79072805 LW |
5315 | |
5316 | case KEY_ref: | |
5317 | UNI(OP_REF); | |
5318 | ||
5319 | case KEY_s: | |
5320 | s = scan_subst(s); | |
5321 | if (yylval.opval) | |
5322 | TERM(sublex_start()); | |
5323 | else | |
5324 | TOKEN(1); /* force error */ | |
5325 | ||
0d863452 RH |
5326 | case KEY_say: |
5327 | checkcomma(s,PL_tokenbuf,"filehandle"); | |
5328 | LOP(OP_SAY,XREF); | |
5329 | ||
a0d0e21e LW |
5330 | case KEY_chomp: |
5331 | UNI(OP_CHOMP); | |
4e553d73 | 5332 | |
79072805 LW |
5333 | case KEY_scalar: |
5334 | UNI(OP_SCALAR); | |
5335 | ||
5336 | case KEY_select: | |
a0d0e21e | 5337 | LOP(OP_SELECT,XTERM); |
79072805 LW |
5338 | |
5339 | case KEY_seek: | |
a0d0e21e | 5340 | LOP(OP_SEEK,XTERM); |
79072805 LW |
5341 | |
5342 | case KEY_semctl: | |
a0d0e21e | 5343 | LOP(OP_SEMCTL,XTERM); |
79072805 LW |
5344 | |
5345 | case KEY_semget: | |
a0d0e21e | 5346 | LOP(OP_SEMGET,XTERM); |
79072805 LW |
5347 | |
5348 | case KEY_semop: | |
a0d0e21e | 5349 | LOP(OP_SEMOP,XTERM); |
79072805 LW |
5350 | |
5351 | case KEY_send: | |
a0d0e21e | 5352 | LOP(OP_SEND,XTERM); |
79072805 LW |
5353 | |
5354 | case KEY_setpgrp: | |
a0d0e21e | 5355 | LOP(OP_SETPGRP,XTERM); |
79072805 LW |
5356 | |
5357 | case KEY_setpriority: | |
a0d0e21e | 5358 | LOP(OP_SETPRIORITY,XTERM); |
79072805 LW |
5359 | |
5360 | case KEY_sethostent: | |
ff68c719 | 5361 | UNI(OP_SHOSTENT); |
79072805 LW |
5362 | |
5363 | case KEY_setnetent: | |
ff68c719 | 5364 | UNI(OP_SNETENT); |
79072805 LW |
5365 | |
5366 | case KEY_setservent: | |
ff68c719 | 5367 | UNI(OP_SSERVENT); |
79072805 LW |
5368 | |
5369 | case KEY_setprotoent: | |
ff68c719 | 5370 | UNI(OP_SPROTOENT); |
79072805 LW |
5371 | |
5372 | case KEY_setpwent: | |
5373 | FUN0(OP_SPWENT); | |
5374 | ||
5375 | case KEY_setgrent: | |
5376 | FUN0(OP_SGRENT); | |
5377 | ||
5378 | case KEY_seekdir: | |
a0d0e21e | 5379 | LOP(OP_SEEKDIR,XTERM); |
79072805 LW |
5380 | |
5381 | case KEY_setsockopt: | |
a0d0e21e | 5382 | LOP(OP_SSOCKOPT,XTERM); |
79072805 LW |
5383 | |
5384 | case KEY_shift: | |
6f33ba73 | 5385 | UNIDOR(OP_SHIFT); |
79072805 LW |
5386 | |
5387 | case KEY_shmctl: | |
a0d0e21e | 5388 | LOP(OP_SHMCTL,XTERM); |
79072805 LW |
5389 | |
5390 | case KEY_shmget: | |
a0d0e21e | 5391 | LOP(OP_SHMGET,XTERM); |
79072805 LW |
5392 | |
5393 | case KEY_shmread: | |
a0d0e21e | 5394 | LOP(OP_SHMREAD,XTERM); |
79072805 LW |
5395 | |
5396 | case KEY_shmwrite: | |
a0d0e21e | 5397 | LOP(OP_SHMWRITE,XTERM); |
79072805 LW |
5398 | |
5399 | case KEY_shutdown: | |
a0d0e21e | 5400 | LOP(OP_SHUTDOWN,XTERM); |
79072805 LW |
5401 | |
5402 | case KEY_sin: | |
5403 | UNI(OP_SIN); | |
5404 | ||
5405 | case KEY_sleep: | |
5406 | UNI(OP_SLEEP); | |
5407 | ||
5408 | case KEY_socket: | |
a0d0e21e | 5409 | LOP(OP_SOCKET,XTERM); |
79072805 LW |
5410 | |
5411 | case KEY_socketpair: | |
a0d0e21e | 5412 | LOP(OP_SOCKPAIR,XTERM); |
79072805 LW |
5413 | |
5414 | case KEY_sort: | |
3280af22 | 5415 | checkcomma(s,PL_tokenbuf,"subroutine name"); |
79072805 LW |
5416 | s = skipspace(s); |
5417 | if (*s == ';' || *s == ')') /* probably a close */ | |
cea2e8a9 | 5418 | Perl_croak(aTHX_ "sort is now a reserved word"); |
3280af22 | 5419 | PL_expect = XTERM; |
15f0808c | 5420 | s = force_word(s,WORD,TRUE,TRUE,FALSE); |
a0d0e21e | 5421 | LOP(OP_SORT,XREF); |
79072805 LW |
5422 | |
5423 | case KEY_split: | |
a0d0e21e | 5424 | LOP(OP_SPLIT,XTERM); |
79072805 LW |
5425 | |
5426 | case KEY_sprintf: | |
a0d0e21e | 5427 | LOP(OP_SPRINTF,XTERM); |
79072805 LW |
5428 | |
5429 | case KEY_splice: | |
a0d0e21e | 5430 | LOP(OP_SPLICE,XTERM); |
79072805 LW |
5431 | |
5432 | case KEY_sqrt: | |
5433 | UNI(OP_SQRT); | |
5434 | ||
5435 | case KEY_srand: | |
5436 | UNI(OP_SRAND); | |
5437 | ||
5438 | case KEY_stat: | |
5439 | UNI(OP_STAT); | |
5440 | ||
5441 | case KEY_study: | |
79072805 LW |
5442 | UNI(OP_STUDY); |
5443 | ||
5444 | case KEY_substr: | |
a0d0e21e | 5445 | LOP(OP_SUBSTR,XTERM); |
79072805 LW |
5446 | |
5447 | case KEY_format: | |
5448 | case KEY_sub: | |
93a17b20 | 5449 | really_sub: |
09bef843 | 5450 | { |
3280af22 | 5451 | char tmpbuf[sizeof PL_tokenbuf]; |
9c5ffd7c | 5452 | SSize_t tboffset = 0; |
09bef843 | 5453 | expectation attrful; |
d731386a | 5454 | bool have_name, have_proto, bad_proto; |
f54cb97a | 5455 | const int key = tmp; |
09bef843 SB |
5456 | |
5457 | s = skipspace(s); | |
5458 | ||
7e2040f0 | 5459 | if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' || |
09bef843 SB |
5460 | (*s == ':' && s[1] == ':')) |
5461 | { | |
5462 | PL_expect = XBLOCK; | |
5463 | attrful = XATTRBLOCK; | |
b1b65b59 JH |
5464 | /* remember buffer pos'n for later force_word */ |
5465 | tboffset = s - PL_oldbufptr; | |
09bef843 SB |
5466 | d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
5467 | if (strchr(tmpbuf, ':')) | |
5468 | sv_setpv(PL_subname, tmpbuf); | |
5469 | else { | |
5470 | sv_setsv(PL_subname,PL_curstname); | |
396482e1 | 5471 | sv_catpvs(PL_subname,"::"); |
09bef843 SB |
5472 | sv_catpvn(PL_subname,tmpbuf,len); |
5473 | } | |
5474 | s = skipspace(d); | |
5475 | have_name = TRUE; | |
5476 | } | |
463ee0b2 | 5477 | else { |
09bef843 SB |
5478 | if (key == KEY_my) |
5479 | Perl_croak(aTHX_ "Missing name in \"my sub\""); | |
5480 | PL_expect = XTERMBLOCK; | |
5481 | attrful = XATTRTERM; | |
c69006e4 | 5482 | sv_setpvn(PL_subname,"?",1); |
09bef843 | 5483 | have_name = FALSE; |
463ee0b2 | 5484 | } |
4633a7c4 | 5485 | |
09bef843 SB |
5486 | if (key == KEY_format) { |
5487 | if (*s == '=') | |
5488 | PL_lex_formbrack = PL_lex_brackets + 1; | |
5489 | if (have_name) | |
b1b65b59 JH |
5490 | (void) force_word(PL_oldbufptr + tboffset, WORD, |
5491 | FALSE, TRUE, TRUE); | |
09bef843 SB |
5492 | OPERATOR(FORMAT); |
5493 | } | |
79072805 | 5494 | |
09bef843 SB |
5495 | /* Look for a prototype */ |
5496 | if (*s == '(') { | |
5497 | char *p; | |
5498 | ||
5499 | s = scan_str(s,FALSE,FALSE); | |
37fd879b | 5500 | if (!s) |
09bef843 | 5501 | Perl_croak(aTHX_ "Prototype not terminated"); |
2f758a16 | 5502 | /* strip spaces and check for bad characters */ |
09bef843 SB |
5503 | d = SvPVX(PL_lex_stuff); |
5504 | tmp = 0; | |
d731386a | 5505 | bad_proto = FALSE; |
09bef843 | 5506 | for (p = d; *p; ++p) { |
d37a9538 | 5507 | if (!isSPACE(*p)) { |
09bef843 | 5508 | d[tmp++] = *p; |
d37a9538 ST |
5509 | if (!strchr("$@%*;[]&\\", *p)) |
5510 | bad_proto = TRUE; | |
5511 | } | |
09bef843 SB |
5512 | } |
5513 | d[tmp] = '\0'; | |
420cdfc1 | 5514 | if (bad_proto && ckWARN(WARN_SYNTAX)) |
9014280d | 5515 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
35c1215d NC |
5516 | "Illegal character in prototype for %"SVf" : %s", |
5517 | PL_subname, d); | |
b162af07 | 5518 | SvCUR_set(PL_lex_stuff, tmp); |
09bef843 | 5519 | have_proto = TRUE; |
68dc0745 | 5520 | |
09bef843 | 5521 | s = skipspace(s); |
4633a7c4 | 5522 | } |
09bef843 SB |
5523 | else |
5524 | have_proto = FALSE; | |
5525 | ||
5526 | if (*s == ':' && s[1] != ':') | |
5527 | PL_expect = attrful; | |
8e742a20 MHM |
5528 | else if (*s != '{' && key == KEY_sub) { |
5529 | if (!have_name) | |
5530 | Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine"); | |
5531 | else if (*s != ';') | |
5532 | Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname); | |
5533 | } | |
09bef843 SB |
5534 | |
5535 | if (have_proto) { | |
b1b65b59 JH |
5536 | PL_nextval[PL_nexttoke].opval = |
5537 | (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff); | |
a0714e2c | 5538 | PL_lex_stuff = NULL; |
09bef843 | 5539 | force_next(THING); |
68dc0745 | 5540 | } |
09bef843 | 5541 | if (!have_name) { |
c99da370 JH |
5542 | sv_setpv(PL_subname, |
5543 | PL_curstash ? "__ANON__" : "__ANON__::__ANON__"); | |
09bef843 | 5544 | TOKEN(ANONSUB); |
4633a7c4 | 5545 | } |
b1b65b59 JH |
5546 | (void) force_word(PL_oldbufptr + tboffset, WORD, |
5547 | FALSE, TRUE, TRUE); | |
09bef843 SB |
5548 | if (key == KEY_my) |
5549 | TOKEN(MYSUB); | |
5550 | TOKEN(SUB); | |
4633a7c4 | 5551 | } |
79072805 LW |
5552 | |
5553 | case KEY_system: | |
5554 | set_csh(); | |
a0d0e21e | 5555 | LOP(OP_SYSTEM,XREF); |
79072805 LW |
5556 | |
5557 | case KEY_symlink: | |
a0d0e21e | 5558 | LOP(OP_SYMLINK,XTERM); |
79072805 LW |
5559 | |
5560 | case KEY_syscall: | |
a0d0e21e | 5561 | LOP(OP_SYSCALL,XTERM); |
79072805 | 5562 | |
c07a80fd | 5563 | case KEY_sysopen: |
5564 | LOP(OP_SYSOPEN,XTERM); | |
5565 | ||
137443ea | 5566 | case KEY_sysseek: |
5567 | LOP(OP_SYSSEEK,XTERM); | |
5568 | ||
79072805 | 5569 | case KEY_sysread: |
a0d0e21e | 5570 | LOP(OP_SYSREAD,XTERM); |
79072805 LW |
5571 | |
5572 | case KEY_syswrite: | |
a0d0e21e | 5573 | LOP(OP_SYSWRITE,XTERM); |
79072805 LW |
5574 | |
5575 | case KEY_tr: | |
5576 | s = scan_trans(s); | |
5577 | TERM(sublex_start()); | |
5578 | ||
5579 | case KEY_tell: | |
5580 | UNI(OP_TELL); | |
5581 | ||
5582 | case KEY_telldir: | |
5583 | UNI(OP_TELLDIR); | |
5584 | ||
463ee0b2 | 5585 | case KEY_tie: |
a0d0e21e | 5586 | LOP(OP_TIE,XTERM); |
463ee0b2 | 5587 | |
c07a80fd | 5588 | case KEY_tied: |
5589 | UNI(OP_TIED); | |
5590 | ||
79072805 LW |
5591 | case KEY_time: |
5592 | FUN0(OP_TIME); | |
5593 | ||
5594 | case KEY_times: | |
5595 | FUN0(OP_TMS); | |
5596 | ||
5597 | case KEY_truncate: | |
a0d0e21e | 5598 | LOP(OP_TRUNCATE,XTERM); |
79072805 LW |
5599 | |
5600 | case KEY_uc: | |
5601 | UNI(OP_UC); | |
5602 | ||
5603 | case KEY_ucfirst: | |
5604 | UNI(OP_UCFIRST); | |
5605 | ||
463ee0b2 LW |
5606 | case KEY_untie: |
5607 | UNI(OP_UNTIE); | |
5608 | ||
79072805 | 5609 | case KEY_until: |
57843af0 | 5610 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5611 | OPERATOR(UNTIL); |
5612 | ||
5613 | case KEY_unless: | |
57843af0 | 5614 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5615 | OPERATOR(UNLESS); |
5616 | ||
5617 | case KEY_unlink: | |
a0d0e21e | 5618 | LOP(OP_UNLINK,XTERM); |
79072805 LW |
5619 | |
5620 | case KEY_undef: | |
6f33ba73 | 5621 | UNIDOR(OP_UNDEF); |
79072805 LW |
5622 | |
5623 | case KEY_unpack: | |
a0d0e21e | 5624 | LOP(OP_UNPACK,XTERM); |
79072805 LW |
5625 | |
5626 | case KEY_utime: | |
a0d0e21e | 5627 | LOP(OP_UTIME,XTERM); |
79072805 LW |
5628 | |
5629 | case KEY_umask: | |
6f33ba73 | 5630 | UNIDOR(OP_UMASK); |
79072805 LW |
5631 | |
5632 | case KEY_unshift: | |
a0d0e21e LW |
5633 | LOP(OP_UNSHIFT,XTERM); |
5634 | ||
5635 | case KEY_use: | |
468aa647 | 5636 | s = tokenize_use(1, s); |
a0d0e21e | 5637 | OPERATOR(USE); |
79072805 LW |
5638 | |
5639 | case KEY_values: | |
5640 | UNI(OP_VALUES); | |
5641 | ||
5642 | case KEY_vec: | |
a0d0e21e | 5643 | LOP(OP_VEC,XTERM); |
79072805 | 5644 | |
0d863452 RH |
5645 | case KEY_when: |
5646 | yylval.ival = CopLINE(PL_curcop); | |
5647 | OPERATOR(WHEN); | |
5648 | ||
79072805 | 5649 | case KEY_while: |
57843af0 | 5650 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5651 | OPERATOR(WHILE); |
5652 | ||
5653 | case KEY_warn: | |
3280af22 | 5654 | PL_hints |= HINT_BLOCK_SCOPE; |
a0d0e21e | 5655 | LOP(OP_WARN,XTERM); |
79072805 LW |
5656 | |
5657 | case KEY_wait: | |
5658 | FUN0(OP_WAIT); | |
5659 | ||
5660 | case KEY_waitpid: | |
a0d0e21e | 5661 | LOP(OP_WAITPID,XTERM); |
79072805 LW |
5662 | |
5663 | case KEY_wantarray: | |
5664 | FUN0(OP_WANTARRAY); | |
5665 | ||
5666 | case KEY_write: | |
9d116dd7 JH |
5667 | #ifdef EBCDIC |
5668 | { | |
df3728a2 JH |
5669 | char ctl_l[2]; |
5670 | ctl_l[0] = toCTRL('L'); | |
5671 | ctl_l[1] = '\0'; | |
fafc274c | 5672 | gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV); |
9d116dd7 JH |
5673 | } |
5674 | #else | |
fafc274c NC |
5675 | /* Make sure $^L is defined */ |
5676 | gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV); | |
9d116dd7 | 5677 | #endif |
79072805 LW |
5678 | UNI(OP_ENTERWRITE); |
5679 | ||
5680 | case KEY_x: | |
3280af22 | 5681 | if (PL_expect == XOPERATOR) |
79072805 LW |
5682 | Mop(OP_REPEAT); |
5683 | check_uni(); | |
5684 | goto just_a_word; | |
5685 | ||
a0d0e21e LW |
5686 | case KEY_xor: |
5687 | yylval.ival = OP_XOR; | |
5688 | OPERATOR(OROP); | |
5689 | ||
79072805 LW |
5690 | case KEY_y: |
5691 | s = scan_trans(s); | |
5692 | TERM(sublex_start()); | |
5693 | } | |
49dc05e3 | 5694 | }} |
79072805 | 5695 | } |
bf4acbe4 GS |
5696 | #ifdef __SC__ |
5697 | #pragma segment Main | |
5698 | #endif | |
79072805 | 5699 | |
e930465f JH |
5700 | static int |
5701 | S_pending_ident(pTHX) | |
8eceec63 | 5702 | { |
97aff369 | 5703 | dVAR; |
8eceec63 | 5704 | register char *d; |
a55b55d8 | 5705 | register I32 tmp = 0; |
8eceec63 SC |
5706 | /* pit holds the identifier we read and pending_ident is reset */ |
5707 | char pit = PL_pending_ident; | |
5708 | PL_pending_ident = 0; | |
5709 | ||
5710 | DEBUG_T({ PerlIO_printf(Perl_debug_log, | |
b6007c36 | 5711 | "### Pending identifier '%s'\n", PL_tokenbuf); }); |
8eceec63 SC |
5712 | |
5713 | /* if we're in a my(), we can't allow dynamics here. | |
5714 | $foo'bar has already been turned into $foo::bar, so | |
5715 | just check for colons. | |
5716 | ||
5717 | if it's a legal name, the OP is a PADANY. | |
5718 | */ | |
5719 | if (PL_in_my) { | |
5720 | if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */ | |
5721 | if (strchr(PL_tokenbuf,':')) | |
5722 | yyerror(Perl_form(aTHX_ "No package name allowed for " | |
5723 | "variable %s in \"our\"", | |
5724 | PL_tokenbuf)); | |
dd2155a4 | 5725 | tmp = allocmy(PL_tokenbuf); |
8eceec63 SC |
5726 | } |
5727 | else { | |
5728 | if (strchr(PL_tokenbuf,':')) | |
5729 | yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf)); | |
5730 | ||
5731 | yylval.opval = newOP(OP_PADANY, 0); | |
dd2155a4 | 5732 | yylval.opval->op_targ = allocmy(PL_tokenbuf); |
8eceec63 SC |
5733 | return PRIVATEREF; |
5734 | } | |
5735 | } | |
5736 | ||
5737 | /* | |
5738 | build the ops for accesses to a my() variable. | |
5739 | ||
5740 | Deny my($a) or my($b) in a sort block, *if* $a or $b is | |
5741 | then used in a comparison. This catches most, but not | |
5742 | all cases. For instance, it catches | |
5743 | sort { my($a); $a <=> $b } | |
5744 | but not | |
5745 | sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; } | |
5746 | (although why you'd do that is anyone's guess). | |
5747 | */ | |
5748 | ||
5749 | if (!strchr(PL_tokenbuf,':')) { | |
8716503d DM |
5750 | if (!PL_in_my) |
5751 | tmp = pad_findmy(PL_tokenbuf); | |
5752 | if (tmp != NOT_IN_PAD) { | |
8eceec63 | 5753 | /* might be an "our" variable" */ |
00b1698f | 5754 | if (PAD_COMPNAME_FLAGS_isOUR(tmp)) { |
8eceec63 | 5755 | /* build ops for a bareword */ |
b64e5050 AL |
5756 | HV * const stash = PAD_COMPNAME_OURSTASH(tmp); |
5757 | HEK * const stashname = HvNAME_HEK(stash); | |
5758 | SV * const sym = newSVhek(stashname); | |
396482e1 | 5759 | sv_catpvs(sym, "::"); |
8eceec63 SC |
5760 | sv_catpv(sym, PL_tokenbuf+1); |
5761 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym); | |
5762 | yylval.opval->op_private = OPpCONST_ENTERED; | |
7a5fd60d | 5763 | gv_fetchsv(sym, |
8eceec63 SC |
5764 | (PL_in_eval |
5765 | ? (GV_ADDMULTI | GV_ADDINEVAL) | |
700078d2 | 5766 | : GV_ADDMULTI |
8eceec63 SC |
5767 | ), |
5768 | ((PL_tokenbuf[0] == '$') ? SVt_PV | |
5769 | : (PL_tokenbuf[0] == '@') ? SVt_PVAV | |
5770 | : SVt_PVHV)); | |
5771 | return WORD; | |
5772 | } | |
5773 | ||
5774 | /* if it's a sort block and they're naming $a or $b */ | |
5775 | if (PL_last_lop_op == OP_SORT && | |
5776 | PL_tokenbuf[0] == '$' && | |
5777 | (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b') | |
5778 | && !PL_tokenbuf[2]) | |
5779 | { | |
5780 | for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart; | |
5781 | d < PL_bufend && *d != '\n'; | |
5782 | d++) | |
5783 | { | |
5784 | if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) { | |
5785 | Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison", | |
5786 | PL_tokenbuf); | |
5787 | } | |
5788 | } | |
5789 | } | |
5790 | ||
5791 | yylval.opval = newOP(OP_PADANY, 0); | |
5792 | yylval.opval->op_targ = tmp; | |
5793 | return PRIVATEREF; | |
5794 | } | |
5795 | } | |
5796 | ||
5797 | /* | |
5798 | Whine if they've said @foo in a doublequoted string, | |
5799 | and @foo isn't a variable we can find in the symbol | |
5800 | table. | |
5801 | */ | |
5802 | if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) { | |
f776e3cd | 5803 | GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV); |
8eceec63 SC |
5804 | if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv))) |
5805 | && ckWARN(WARN_AMBIGUOUS)) | |
5806 | { | |
5807 | /* Downgraded from fatal to warning 20000522 mjd */ | |
9014280d | 5808 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
8eceec63 SC |
5809 | "Possible unintended interpolation of %s in string", |
5810 | PL_tokenbuf); | |
5811 | } | |
5812 | } | |
5813 | ||
5814 | /* build ops for a bareword */ | |
5815 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0)); | |
5816 | yylval.opval->op_private = OPpCONST_ENTERED; | |
adc51b97 RGS |
5817 | gv_fetchpv( |
5818 | PL_tokenbuf+1, | |
d6069db2 RGS |
5819 | /* If the identifier refers to a stash, don't autovivify it. |
5820 | * Change 24660 had the side effect of causing symbol table | |
5821 | * hashes to always be defined, even if they were freshly | |
5822 | * created and the only reference in the entire program was | |
5823 | * the single statement with the defined %foo::bar:: test. | |
5824 | * It appears that all code in the wild doing this actually | |
5825 | * wants to know whether sub-packages have been loaded, so | |
5826 | * by avoiding auto-vivifying symbol tables, we ensure that | |
5827 | * defined %foo::bar:: continues to be false, and the existing | |
5828 | * tests still give the expected answers, even though what | |
5829 | * they're actually testing has now changed subtly. | |
5830 | */ | |
5831 | (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':' | |
5832 | ? 0 | |
5833 | : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD), | |
adc51b97 RGS |
5834 | ((PL_tokenbuf[0] == '$') ? SVt_PV |
5835 | : (PL_tokenbuf[0] == '@') ? SVt_PVAV | |
5836 | : SVt_PVHV)); | |
8eceec63 SC |
5837 | return WORD; |
5838 | } | |
5839 | ||
4c3bbe0f MHM |
5840 | /* |
5841 | * The following code was generated by perl_keyword.pl. | |
5842 | */ | |
e2e1dd5a | 5843 | |
79072805 | 5844 | I32 |
672994ce | 5845 | Perl_keyword (pTHX_ const char *name, I32 len) |
4c3bbe0f | 5846 | { |
97aff369 | 5847 | dVAR; |
4c3bbe0f MHM |
5848 | switch (len) |
5849 | { | |
5850 | case 1: /* 5 tokens of length 1 */ | |
5851 | switch (name[0]) | |
e2e1dd5a | 5852 | { |
4c3bbe0f MHM |
5853 | case 'm': |
5854 | { /* m */ | |
5855 | return KEY_m; | |
5856 | } | |
5857 | ||
4c3bbe0f MHM |
5858 | case 'q': |
5859 | { /* q */ | |
5860 | return KEY_q; | |
5861 | } | |
5862 | ||
4c3bbe0f MHM |
5863 | case 's': |
5864 | { /* s */ | |
5865 | return KEY_s; | |
5866 | } | |
5867 | ||
4c3bbe0f MHM |
5868 | case 'x': |
5869 | { /* x */ | |
5870 | return -KEY_x; | |
5871 | } | |
5872 | ||
4c3bbe0f MHM |
5873 | case 'y': |
5874 | { /* y */ | |
5875 | return KEY_y; | |
5876 | } | |
5877 | ||
4c3bbe0f MHM |
5878 | default: |
5879 | goto unknown; | |
e2e1dd5a | 5880 | } |
4c3bbe0f MHM |
5881 | |
5882 | case 2: /* 18 tokens of length 2 */ | |
5883 | switch (name[0]) | |
e2e1dd5a | 5884 | { |
4c3bbe0f MHM |
5885 | case 'd': |
5886 | if (name[1] == 'o') | |
5887 | { /* do */ | |
5888 | return KEY_do; | |
5889 | } | |
5890 | ||
5891 | goto unknown; | |
5892 | ||
5893 | case 'e': | |
5894 | if (name[1] == 'q') | |
5895 | { /* eq */ | |
5896 | return -KEY_eq; | |
5897 | } | |
5898 | ||
5899 | goto unknown; | |
5900 | ||
5901 | case 'g': | |
5902 | switch (name[1]) | |
5903 | { | |
5904 | case 'e': | |
5905 | { /* ge */ | |
5906 | return -KEY_ge; | |
5907 | } | |
5908 | ||
4c3bbe0f MHM |
5909 | case 't': |
5910 | { /* gt */ | |
5911 | return -KEY_gt; | |
5912 | } | |
5913 | ||
4c3bbe0f MHM |
5914 | default: |
5915 | goto unknown; | |
5916 | } | |
5917 | ||
5918 | case 'i': | |
5919 | if (name[1] == 'f') | |
5920 | { /* if */ | |
5921 | return KEY_if; | |
5922 | } | |
5923 | ||
5924 | goto unknown; | |
5925 | ||
5926 | case 'l': | |
5927 | switch (name[1]) | |
5928 | { | |
5929 | case 'c': | |
5930 | { /* lc */ | |
5931 | return -KEY_lc; | |
5932 | } | |
5933 | ||
4c3bbe0f MHM |
5934 | case 'e': |
5935 | { /* le */ | |
5936 | return -KEY_le; | |
5937 | } | |
5938 | ||
4c3bbe0f MHM |
5939 | case 't': |
5940 | { /* lt */ | |
5941 | return -KEY_lt; | |
5942 | } | |
5943 | ||
4c3bbe0f MHM |
5944 | default: |
5945 | goto unknown; | |
5946 | } | |
5947 | ||
5948 | case 'm': | |
5949 | if (name[1] == 'y') | |
5950 | { /* my */ | |
5951 | return KEY_my; | |
5952 | } | |
5953 | ||
5954 | goto unknown; | |
5955 | ||
5956 | case 'n': | |
5957 | switch (name[1]) | |
5958 | { | |
5959 | case 'e': | |
5960 | { /* ne */ | |
5961 | return -KEY_ne; | |
5962 | } | |
5963 | ||
4c3bbe0f MHM |
5964 | case 'o': |
5965 | { /* no */ | |
5966 | return KEY_no; | |
5967 | } | |
5968 | ||
4c3bbe0f MHM |
5969 | default: |
5970 | goto unknown; | |
5971 | } | |
5972 | ||
5973 | case 'o': | |
5974 | if (name[1] == 'r') | |
5975 | { /* or */ | |
5976 | return -KEY_or; | |
5977 | } | |
5978 | ||
5979 | goto unknown; | |
5980 | ||
5981 | case 'q': | |
5982 | switch (name[1]) | |
5983 | { | |
5984 | case 'q': | |
5985 | { /* qq */ | |
5986 | return KEY_qq; | |
5987 | } | |
5988 | ||
4c3bbe0f MHM |
5989 | case 'r': |
5990 | { /* qr */ | |
5991 | return KEY_qr; | |
5992 | } | |
5993 | ||
4c3bbe0f MHM |
5994 | case 'w': |
5995 | { /* qw */ | |
5996 | return KEY_qw; | |
5997 | } | |
5998 | ||
4c3bbe0f MHM |
5999 | case 'x': |
6000 | { /* qx */ | |
6001 | return KEY_qx; | |
6002 | } | |
6003 | ||
4c3bbe0f MHM |
6004 | default: |
6005 | goto unknown; | |
6006 | } | |
6007 | ||
6008 | case 't': | |
6009 | if (name[1] == 'r') | |
6010 | { /* tr */ | |
6011 | return KEY_tr; | |
6012 | } | |
6013 | ||
6014 | goto unknown; | |
6015 | ||
6016 | case 'u': | |
6017 | if (name[1] == 'c') | |
6018 | { /* uc */ | |
6019 | return -KEY_uc; | |
6020 | } | |
6021 | ||
6022 | goto unknown; | |
6023 | ||
6024 | default: | |
6025 | goto unknown; | |
e2e1dd5a | 6026 | } |
4c3bbe0f | 6027 | |
0d863452 | 6028 | case 3: /* 29 tokens of length 3 */ |
4c3bbe0f | 6029 | switch (name[0]) |
e2e1dd5a | 6030 | { |
4c3bbe0f MHM |
6031 | case 'E': |
6032 | if (name[1] == 'N' && | |
6033 | name[2] == 'D') | |
6034 | { /* END */ | |
6035 | return KEY_END; | |
6036 | } | |
6037 | ||
6038 | goto unknown; | |
6039 | ||
6040 | case 'a': | |
6041 | switch (name[1]) | |
6042 | { | |
6043 | case 'b': | |
6044 | if (name[2] == 's') | |
6045 | { /* abs */ | |
6046 | return -KEY_abs; | |
6047 | } | |
6048 | ||
6049 | goto unknown; | |
6050 | ||
6051 | case 'n': | |
6052 | if (name[2] == 'd') | |
6053 | { /* and */ | |
6054 | return -KEY_and; | |
6055 | } | |
6056 | ||
6057 | goto unknown; | |
6058 | ||
6059 | default: | |
6060 | goto unknown; | |
6061 | } | |
6062 | ||
6063 | case 'c': | |
6064 | switch (name[1]) | |
6065 | { | |
6066 | case 'h': | |
6067 | if (name[2] == 'r') | |
6068 | { /* chr */ | |
6069 | return -KEY_chr; | |
6070 | } | |
6071 | ||
6072 | goto unknown; | |
6073 | ||
6074 | case 'm': | |
6075 | if (name[2] == 'p') | |
6076 | { /* cmp */ | |
6077 | return -KEY_cmp; | |
6078 | } | |
6079 | ||
6080 | goto unknown; | |
6081 | ||
6082 | case 'o': | |
6083 | if (name[2] == 's') | |
6084 | { /* cos */ | |
6085 | return -KEY_cos; | |
6086 | } | |
6087 | ||
6088 | goto unknown; | |
6089 | ||
6090 | default: | |
6091 | goto unknown; | |
6092 | } | |
6093 | ||
6094 | case 'd': | |
6095 | if (name[1] == 'i' && | |
6096 | name[2] == 'e') | |
6097 | { /* die */ | |
6098 | return -KEY_die; | |
6099 | } | |
6100 | ||
6101 | goto unknown; | |
6102 | ||
6103 | case 'e': | |
6104 | switch (name[1]) | |
6105 | { | |
6106 | case 'o': | |
6107 | if (name[2] == 'f') | |
6108 | { /* eof */ | |
6109 | return -KEY_eof; | |
6110 | } | |
6111 | ||
6112 | goto unknown; | |
6113 | ||
6114 | case 'r': | |
6115 | if (name[2] == 'r') | |
6116 | { /* err */ | |
ef89dcc3 | 6117 | return (FEATURE_IS_ENABLED("err") ? -KEY_err : 0); |
4c3bbe0f MHM |
6118 | } |
6119 | ||
6120 | goto unknown; | |
6121 | ||
6122 | case 'x': | |
6123 | if (name[2] == 'p') | |
6124 | { /* exp */ | |
6125 | return -KEY_exp; | |
6126 | } | |
6127 | ||
6128 | goto unknown; | |
6129 | ||
6130 | default: | |
6131 | goto unknown; | |
6132 | } | |
6133 | ||
6134 | case 'f': | |
6135 | if (name[1] == 'o' && | |
6136 | name[2] == 'r') | |
6137 | { /* for */ | |
6138 | return KEY_for; | |
6139 | } | |
6140 | ||
6141 | goto unknown; | |
6142 | ||
6143 | case 'h': | |
6144 | if (name[1] == 'e' && | |
6145 | name[2] == 'x') | |
6146 | { /* hex */ | |
6147 | return -KEY_hex; | |
6148 | } | |
6149 | ||
6150 | goto unknown; | |
6151 | ||
6152 | case 'i': | |
6153 | if (name[1] == 'n' && | |
6154 | name[2] == 't') | |
6155 | { /* int */ | |
6156 | return -KEY_int; | |
6157 | } | |
6158 | ||
6159 | goto unknown; | |
6160 | ||
6161 | case 'l': | |
6162 | if (name[1] == 'o' && | |
6163 | name[2] == 'g') | |
6164 | { /* log */ | |
6165 | return -KEY_log; | |
6166 | } | |
6167 | ||
6168 | goto unknown; | |
6169 | ||
6170 | case 'm': | |
6171 | if (name[1] == 'a' && | |
6172 | name[2] == 'p') | |
6173 | { /* map */ | |
6174 | return KEY_map; | |
6175 | } | |
6176 | ||
6177 | goto unknown; | |
6178 | ||
6179 | case 'n': | |
6180 | if (name[1] == 'o' && | |
6181 | name[2] == 't') | |
6182 | { /* not */ | |
6183 | return -KEY_not; | |
6184 | } | |
6185 | ||
6186 | goto unknown; | |
6187 | ||
6188 | case 'o': | |
6189 | switch (name[1]) | |
6190 | { | |
6191 | case 'c': | |
6192 | if (name[2] == 't') | |
6193 | { /* oct */ | |
6194 | return -KEY_oct; | |
6195 | } | |
6196 | ||
6197 | goto unknown; | |
6198 | ||
6199 | case 'r': | |
6200 | if (name[2] == 'd') | |
6201 | { /* ord */ | |
6202 | return -KEY_ord; | |
6203 | } | |
6204 | ||
6205 | goto unknown; | |
6206 | ||
6207 | case 'u': | |
6208 | if (name[2] == 'r') | |
6209 | { /* our */ | |
6210 | return KEY_our; | |
6211 | } | |
6212 | ||
6213 | goto unknown; | |
6214 | ||
6215 | default: | |
6216 | goto unknown; | |
6217 | } | |
6218 | ||
6219 | case 'p': | |
6220 | if (name[1] == 'o') | |
6221 | { | |
6222 | switch (name[2]) | |
6223 | { | |
6224 | case 'p': | |
6225 | { /* pop */ | |
6226 | return -KEY_pop; | |
6227 | } | |
6228 | ||
4c3bbe0f MHM |
6229 | case 's': |
6230 | { /* pos */ | |
6231 | return KEY_pos; | |
6232 | } | |
6233 | ||
4c3bbe0f MHM |
6234 | default: |
6235 | goto unknown; | |
6236 | } | |
6237 | } | |
6238 | ||
6239 | goto unknown; | |
6240 | ||
6241 | case 'r': | |
6242 | if (name[1] == 'e' && | |
6243 | name[2] == 'f') | |
6244 | { /* ref */ | |
6245 | return -KEY_ref; | |
6246 | } | |
6247 | ||
6248 | goto unknown; | |
6249 | ||
6250 | case 's': | |
6251 | switch (name[1]) | |
6252 | { | |
0d863452 RH |
6253 | case 'a': |
6254 | if (name[2] == 'y') | |
6255 | { /* say */ | |
ef89dcc3 | 6256 | return (FEATURE_IS_ENABLED("say") ? -KEY_say : 0); |
0d863452 RH |
6257 | } |
6258 | ||
6259 | goto unknown; | |
6260 | ||
4c3bbe0f MHM |
6261 | case 'i': |
6262 | if (name[2] == 'n') | |
6263 | { /* sin */ | |
6264 | return -KEY_sin; | |
6265 | } | |
6266 | ||
6267 | goto unknown; | |
6268 | ||
6269 | case 'u': | |
6270 | if (name[2] == 'b') | |
6271 | { /* sub */ | |
6272 | return KEY_sub; | |
6273 | } | |
6274 | ||
6275 | goto unknown; | |
6276 | ||
6277 | default: | |
6278 | goto unknown; | |
6279 | } | |
6280 | ||
6281 | case 't': | |
6282 | if (name[1] == 'i' && | |
6283 | name[2] == 'e') | |
6284 | { /* tie */ | |
6285 | return KEY_tie; | |
6286 | } | |
6287 | ||
6288 | goto unknown; | |
6289 | ||
6290 | case 'u': | |
6291 | if (name[1] == 's' && | |
6292 | name[2] == 'e') | |
6293 | { /* use */ | |
6294 | return KEY_use; | |
6295 | } | |
6296 | ||
6297 | goto unknown; | |
6298 | ||
6299 | case 'v': | |
6300 | if (name[1] == 'e' && | |
6301 | name[2] == 'c') | |
6302 | { /* vec */ | |
6303 | return -KEY_vec; | |
6304 | } | |
6305 | ||
6306 | goto unknown; | |
6307 | ||
6308 | case 'x': | |
6309 | if (name[1] == 'o' && | |
6310 | name[2] == 'r') | |
6311 | { /* xor */ | |
6312 | return -KEY_xor; | |
6313 | } | |
6314 | ||
6315 | goto unknown; | |
6316 | ||
6317 | default: | |
6318 | goto unknown; | |
e2e1dd5a | 6319 | } |
4c3bbe0f | 6320 | |
0d863452 | 6321 | case 4: /* 41 tokens of length 4 */ |
4c3bbe0f | 6322 | switch (name[0]) |
e2e1dd5a | 6323 | { |
4c3bbe0f MHM |
6324 | case 'C': |
6325 | if (name[1] == 'O' && | |
6326 | name[2] == 'R' && | |
6327 | name[3] == 'E') | |
6328 | { /* CORE */ | |
6329 | return -KEY_CORE; | |
6330 | } | |
6331 | ||
6332 | goto unknown; | |
6333 | ||
6334 | case 'I': | |
6335 | if (name[1] == 'N' && | |
6336 | name[2] == 'I' && | |
6337 | name[3] == 'T') | |
6338 | { /* INIT */ | |
6339 | return KEY_INIT; | |
6340 | } | |
6341 | ||
6342 | goto unknown; | |
6343 | ||
6344 | case 'b': | |
6345 | if (name[1] == 'i' && | |
6346 | name[2] == 'n' && | |
6347 | name[3] == 'd') | |
6348 | { /* bind */ | |
6349 | return -KEY_bind; | |
6350 | } | |
6351 | ||
6352 | goto unknown; | |
6353 | ||
6354 | case 'c': | |
6355 | if (name[1] == 'h' && | |
6356 | name[2] == 'o' && | |
6357 | name[3] == 'p') | |
6358 | { /* chop */ | |
6359 | return -KEY_chop; | |
6360 | } | |
6361 | ||
6362 | goto unknown; | |
6363 | ||
6364 | case 'd': | |
6365 | if (name[1] == 'u' && | |
6366 | name[2] == 'm' && | |
6367 | name[3] == 'p') | |
6368 | { /* dump */ | |
6369 | return -KEY_dump; | |
6370 | } | |
6371 | ||
6372 | goto unknown; | |
6373 | ||
6374 | case 'e': | |
6375 | switch (name[1]) | |
6376 | { | |
6377 | case 'a': | |
6378 | if (name[2] == 'c' && | |
6379 | name[3] == 'h') | |
6380 | { /* each */ | |
6381 | return -KEY_each; | |
6382 | } | |
6383 | ||
6384 | goto unknown; | |
6385 | ||
6386 | case 'l': | |
6387 | if (name[2] == 's' && | |
6388 | name[3] == 'e') | |
6389 | { /* else */ | |
6390 | return KEY_else; | |
6391 | } | |
6392 | ||
6393 | goto unknown; | |
6394 | ||
6395 | case 'v': | |
6396 | if (name[2] == 'a' && | |
6397 | name[3] == 'l') | |
6398 | { /* eval */ | |
6399 | return KEY_eval; | |
6400 | } | |
6401 | ||
6402 | goto unknown; | |
6403 | ||
6404 | case 'x': | |
6405 | switch (name[2]) | |
6406 | { | |
6407 | case 'e': | |
6408 | if (name[3] == 'c') | |
6409 | { /* exec */ | |
6410 | return -KEY_exec; | |
6411 | } | |
6412 | ||
6413 | goto unknown; | |
6414 | ||
6415 | case 'i': | |
6416 | if (name[3] == 't') | |
6417 | { /* exit */ | |
6418 | return -KEY_exit; | |
6419 | } | |
6420 | ||
6421 | goto unknown; | |
6422 | ||
6423 | default: | |
6424 | goto unknown; | |
6425 | } | |
6426 | ||
6427 | default: | |
6428 | goto unknown; | |
6429 | } | |
6430 | ||
6431 | case 'f': | |
6432 | if (name[1] == 'o' && | |
6433 | name[2] == 'r' && | |
6434 | name[3] == 'k') | |
6435 | { /* fork */ | |
6436 | return -KEY_fork; | |
6437 | } | |
6438 | ||
6439 | goto unknown; | |
6440 | ||
6441 | case 'g': | |
6442 | switch (name[1]) | |
6443 | { | |
6444 | case 'e': | |
6445 | if (name[2] == 't' && | |
6446 | name[3] == 'c') | |
6447 | { /* getc */ | |
6448 | return -KEY_getc; | |
6449 | } | |
6450 | ||
6451 | goto unknown; | |
6452 | ||
6453 | case 'l': | |
6454 | if (name[2] == 'o' && | |
6455 | name[3] == 'b') | |
6456 | { /* glob */ | |
6457 | return KEY_glob; | |
6458 | } | |
6459 | ||
6460 | goto unknown; | |
6461 | ||
6462 | case 'o': | |
6463 | if (name[2] == 't' && | |
6464 | name[3] == 'o') | |
6465 | { /* goto */ | |
6466 | return KEY_goto; | |
6467 | } | |
6468 | ||
6469 | goto unknown; | |
6470 | ||
6471 | case 'r': | |
6472 | if (name[2] == 'e' && | |
6473 | name[3] == 'p') | |
6474 | { /* grep */ | |
6475 | return KEY_grep; | |
6476 | } | |
6477 | ||
6478 | goto unknown; | |
6479 | ||
6480 | default: | |
6481 | goto unknown; | |
6482 | } | |
6483 | ||
6484 | case 'j': | |
6485 | if (name[1] == 'o' && | |
6486 | name[2] == 'i' && | |
6487 | name[3] == 'n') | |
6488 | { /* join */ | |
6489 | return -KEY_join; | |
6490 | } | |
6491 | ||
6492 | goto unknown; | |
6493 | ||
6494 | case 'k': | |
6495 | switch (name[1]) | |
6496 | { | |
6497 | case 'e': | |
6498 | if (name[2] == 'y' && | |
6499 | name[3] == 's') | |
6500 | { /* keys */ | |
6501 | return -KEY_keys; | |
6502 | } | |
6503 | ||
6504 | goto unknown; | |
6505 | ||
6506 | case 'i': | |
6507 | if (name[2] == 'l' && | |
6508 | name[3] == 'l') | |
6509 | { /* kill */ | |
6510 | return -KEY_kill; | |
6511 | } | |
6512 | ||
6513 | goto unknown; | |
6514 | ||
6515 | default: | |
6516 | goto unknown; | |
6517 | } | |
6518 | ||
6519 | case 'l': | |
6520 | switch (name[1]) | |
6521 | { | |
6522 | case 'a': | |
6523 | if (name[2] == 's' && | |
6524 | name[3] == 't') | |
6525 | { /* last */ | |
6526 | return KEY_last; | |
6527 | } | |
6528 | ||
6529 | goto unknown; | |
6530 | ||
6531 | case 'i': | |
6532 | if (name[2] == 'n' && | |
6533 | name[3] == 'k') | |
6534 | { /* link */ | |
6535 | return -KEY_link; | |
6536 | } | |
6537 | ||
6538 | goto unknown; | |
6539 | ||
6540 | case 'o': | |
6541 | if (name[2] == 'c' && | |
6542 | name[3] == 'k') | |
6543 | { /* lock */ | |
6544 | return -KEY_lock; | |
6545 | } | |
6546 | ||
6547 | goto unknown; | |
6548 | ||
6549 | default: | |
6550 | goto unknown; | |
6551 | } | |
6552 | ||
6553 | case 'n': | |
6554 | if (name[1] == 'e' && | |
6555 | name[2] == 'x' && | |
6556 | name[3] == 't') | |
6557 | { /* next */ | |
6558 | return KEY_next; | |
6559 | } | |
6560 | ||
6561 | goto unknown; | |
6562 | ||
6563 | case 'o': | |
6564 | if (name[1] == 'p' && | |
6565 | name[2] == 'e' && | |
6566 | name[3] == 'n') | |
6567 | { /* open */ | |
6568 | return -KEY_open; | |
6569 | } | |
6570 | ||
6571 | goto unknown; | |
6572 | ||
6573 | case 'p': | |
6574 | switch (name[1]) | |
6575 | { | |
6576 | case 'a': | |
6577 | if (name[2] == 'c' && | |
6578 | name[3] == 'k') | |
6579 | { /* pack */ | |
6580 | return -KEY_pack; | |
6581 | } | |
6582 | ||
6583 | goto unknown; | |
6584 | ||
6585 | case 'i': | |
6586 | if (name[2] == 'p' && | |
6587 | name[3] == 'e') | |
6588 | { /* pipe */ | |
6589 | return -KEY_pipe; | |
6590 | } | |
6591 | ||
6592 | goto unknown; | |
6593 | ||
6594 | case 'u': | |
6595 | if (name[2] == 's' && | |
6596 | name[3] == 'h') | |
6597 | { /* push */ | |
6598 | return -KEY_push; | |
6599 | } | |
6600 | ||
6601 | goto unknown; | |
6602 | ||
6603 | default: | |
6604 | goto unknown; | |
6605 | } | |
6606 | ||
6607 | case 'r': | |
6608 | switch (name[1]) | |
6609 | { | |
6610 | case 'a': | |
6611 | if (name[2] == 'n' && | |
6612 | name[3] == 'd') | |
6613 | { /* rand */ | |
6614 | return -KEY_rand; | |
6615 | } | |
6616 | ||
6617 | goto unknown; | |
6618 | ||
6619 | case 'e': | |
6620 | switch (name[2]) | |
6621 | { | |
6622 | case 'a': | |
6623 | if (name[3] == 'd') | |
6624 | { /* read */ | |
6625 | return -KEY_read; | |
6626 | } | |
6627 | ||
6628 | goto unknown; | |
6629 | ||
6630 | case 'c': | |
6631 | if (name[3] == 'v') | |
6632 | { /* recv */ | |
6633 | return -KEY_recv; | |
6634 | } | |
6635 | ||
6636 | goto unknown; | |
6637 | ||
6638 | case 'd': | |
6639 | if (name[3] == 'o') | |
6640 | { /* redo */ | |
6641 | return KEY_redo; | |
6642 | } | |
6643 | ||
6644 | goto unknown; | |
6645 | ||
6646 | default: | |
6647 | goto unknown; | |
6648 | } | |
6649 | ||
6650 | default: | |
6651 | goto unknown; | |
6652 | } | |
6653 | ||
6654 | case 's': | |
6655 | switch (name[1]) | |
6656 | { | |
6657 | case 'e': | |
6658 | switch (name[2]) | |
6659 | { | |
6660 | case 'e': | |
6661 | if (name[3] == 'k') | |
6662 | { /* seek */ | |
6663 | return -KEY_seek; | |
6664 | } | |
6665 | ||
6666 | goto unknown; | |
6667 | ||
6668 | case 'n': | |
6669 | if (name[3] == 'd') | |
6670 | { /* send */ | |
6671 | return -KEY_send; | |
6672 | } | |
6673 | ||
6674 | goto unknown; | |
6675 | ||
6676 | default: | |
6677 | goto unknown; | |
6678 | } | |
6679 | ||
6680 | case 'o': | |
6681 | if (name[2] == 'r' && | |
6682 | name[3] == 't') | |
6683 | { /* sort */ | |
6684 | return KEY_sort; | |
6685 | } | |
6686 | ||
6687 | goto unknown; | |
6688 | ||
6689 | case 'q': | |
6690 | if (name[2] == 'r' && | |
6691 | name[3] == 't') | |
6692 | { /* sqrt */ | |
6693 | return -KEY_sqrt; | |
6694 | } | |
6695 | ||
6696 | goto unknown; | |
6697 | ||
6698 | case 't': | |
6699 | if (name[2] == 'a' && | |
6700 | name[3] == 't') | |
6701 | { /* stat */ | |
6702 | return -KEY_stat; | |
6703 | } | |
6704 | ||
6705 | goto unknown; | |
6706 | ||
6707 | default: | |
6708 | goto unknown; | |
6709 | } | |
6710 | ||
6711 | case 't': | |
6712 | switch (name[1]) | |
6713 | { | |
6714 | case 'e': | |
6715 | if (name[2] == 'l' && | |
6716 | name[3] == 'l') | |
6717 | { /* tell */ | |
6718 | return -KEY_tell; | |
6719 | } | |
6720 | ||
6721 | goto unknown; | |
6722 | ||
6723 | case 'i': | |
6724 | switch (name[2]) | |
6725 | { | |
6726 | case 'e': | |
6727 | if (name[3] == 'd') | |
6728 | { /* tied */ | |
6729 | return KEY_tied; | |
6730 | } | |
6731 | ||
6732 | goto unknown; | |
6733 | ||
6734 | case 'm': | |
6735 | if (name[3] == 'e') | |
6736 | { /* time */ | |
6737 | return -KEY_time; | |
6738 | } | |
6739 | ||
6740 | goto unknown; | |
6741 | ||
6742 | default: | |
6743 | goto unknown; | |
6744 | } | |
6745 | ||
6746 | default: | |
6747 | goto unknown; | |
6748 | } | |
6749 | ||
6750 | case 'w': | |
0d863452 | 6751 | switch (name[1]) |
4c3bbe0f | 6752 | { |
0d863452 | 6753 | case 'a': |
4c3bbe0f MHM |
6754 | switch (name[2]) |
6755 | { | |
6756 | case 'i': | |
6757 | if (name[3] == 't') | |
6758 | { /* wait */ | |
6759 | return -KEY_wait; | |
6760 | } | |
6761 | ||
6762 | goto unknown; | |
6763 | ||
6764 | case 'r': | |
6765 | if (name[3] == 'n') | |
6766 | { /* warn */ | |
6767 | return -KEY_warn; | |
6768 | } | |
6769 | ||
6770 | goto unknown; | |
6771 | ||
6772 | default: | |
6773 | goto unknown; | |
6774 | } | |
0d863452 RH |
6775 | |
6776 | case 'h': | |
6777 | if (name[2] == 'e' && | |
6778 | name[3] == 'n') | |
6779 | { /* when */ | |
ef89dcc3 | 6780 | return (FEATURE_IS_ENABLED("switch") ? KEY_when : 0); |
4c3bbe0f MHM |
6781 | } |
6782 | ||
6783 | goto unknown; | |
6784 | ||
6785 | default: | |
6786 | goto unknown; | |
e2e1dd5a | 6787 | } |
4c3bbe0f | 6788 | |
0d863452 RH |
6789 | default: |
6790 | goto unknown; | |
6791 | } | |
6792 | ||
6793 | case 5: /* 38 tokens of length 5 */ | |
4c3bbe0f | 6794 | switch (name[0]) |
e2e1dd5a | 6795 | { |
4c3bbe0f MHM |
6796 | case 'B': |
6797 | if (name[1] == 'E' && | |
6798 | name[2] == 'G' && | |
6799 | name[3] == 'I' && | |
6800 | name[4] == 'N') | |
6801 | { /* BEGIN */ | |
6802 | return KEY_BEGIN; | |
6803 | } | |
6804 | ||
6805 | goto unknown; | |
6806 | ||
6807 | case 'C': | |
6808 | if (name[1] == 'H' && | |
6809 | name[2] == 'E' && | |
6810 | name[3] == 'C' && | |
6811 | name[4] == 'K') | |
6812 | { /* CHECK */ | |
6813 | return KEY_CHECK; | |
6814 | } | |
6815 | ||
6816 | goto unknown; | |
6817 | ||
6818 | case 'a': | |
6819 | switch (name[1]) | |
6820 | { | |
6821 | case 'l': | |
6822 | if (name[2] == 'a' && | |
6823 | name[3] == 'r' && | |
6824 | name[4] == 'm') | |
6825 | { /* alarm */ | |
6826 | return -KEY_alarm; | |
6827 | } | |
6828 | ||
6829 | goto unknown; | |
6830 | ||
6831 | case 't': | |
6832 | if (name[2] == 'a' && | |
6833 | name[3] == 'n' && | |
6834 | name[4] == '2') | |
6835 | { /* atan2 */ | |
6836 | return -KEY_atan2; | |
6837 | } | |
6838 | ||
6839 | goto unknown; | |
6840 | ||
6841 | default: | |
6842 | goto unknown; | |
6843 | } | |
6844 | ||
6845 | case 'b': | |
0d863452 RH |
6846 | switch (name[1]) |
6847 | { | |
6848 | case 'l': | |
6849 | if (name[2] == 'e' && | |
4c3bbe0f MHM |
6850 | name[3] == 's' && |
6851 | name[4] == 's') | |
6852 | { /* bless */ | |
6853 | return -KEY_bless; | |
6854 | } | |
6855 | ||
6856 | goto unknown; | |
6857 | ||
0d863452 RH |
6858 | case 'r': |
6859 | if (name[2] == 'e' && | |
6860 | name[3] == 'a' && | |
6861 | name[4] == 'k') | |
6862 | { /* break */ | |
ef89dcc3 | 6863 | return (FEATURE_IS_ENABLED("switch") ? -KEY_break : 0); |
0d863452 RH |
6864 | } |
6865 | ||
6866 | goto unknown; | |
6867 | ||
6868 | default: | |
6869 | goto unknown; | |
6870 | } | |
6871 | ||
4c3bbe0f MHM |
6872 | case 'c': |
6873 | switch (name[1]) | |
6874 | { | |
6875 | case 'h': | |
6876 | switch (name[2]) | |
6877 | { | |
6878 | case 'd': | |
6879 | if (name[3] == 'i' && | |
6880 | name[4] == 'r') | |
6881 | { /* chdir */ | |
6882 | return -KEY_chdir; | |
6883 | } | |
6884 | ||
6885 | goto unknown; | |
6886 | ||
6887 | case 'm': | |
6888 | if (name[3] == 'o' && | |
6889 | name[4] == 'd') | |
6890 | { /* chmod */ | |
6891 | return -KEY_chmod; | |
6892 | } | |
6893 | ||
6894 | goto unknown; | |
6895 | ||
6896 | case 'o': | |
6897 | switch (name[3]) | |
6898 | { | |
6899 | case 'm': | |
6900 | if (name[4] == 'p') | |
6901 | { /* chomp */ | |
6902 | return -KEY_chomp; | |
6903 | } | |
6904 | ||
6905 | goto unknown; | |
6906 | ||
6907 | case 'w': | |
6908 | if (name[4] == 'n') | |
6909 | { /* chown */ | |
6910 | return -KEY_chown; | |
6911 | } | |
6912 | ||
6913 | goto unknown; | |
6914 | ||
6915 | default: | |
6916 | goto unknown; | |
6917 | } | |
6918 | ||
6919 | default: | |
6920 | goto unknown; | |
6921 | } | |
6922 | ||
6923 | case 'l': | |
6924 | if (name[2] == 'o' && | |
6925 | name[3] == 's' && | |
6926 | name[4] == 'e') | |
6927 | { /* close */ | |
6928 | return -KEY_close; | |
6929 | } | |
6930 | ||
6931 | goto unknown; | |
6932 | ||
6933 | case 'r': | |
6934 | if (name[2] == 'y' && | |
6935 | name[3] == 'p' && | |
6936 | name[4] == 't') | |
6937 | { /* crypt */ | |
6938 | return -KEY_crypt; | |
6939 | } | |
6940 | ||
6941 | goto unknown; | |
6942 | ||
6943 | default: | |
6944 | goto unknown; | |
6945 | } | |
6946 | ||
6947 | case 'e': | |
6948 | if (name[1] == 'l' && | |
6949 | name[2] == 's' && | |
6950 | name[3] == 'i' && | |
6951 | name[4] == 'f') | |
6952 | { /* elsif */ | |
6953 | return KEY_elsif; | |
6954 | } | |
6955 | ||
6956 | goto unknown; | |
6957 | ||
6958 | case 'f': | |
6959 | switch (name[1]) | |
6960 | { | |
6961 | case 'c': | |
6962 | if (name[2] == 'n' && | |
6963 | name[3] == 't' && | |
6964 | name[4] == 'l') | |
6965 | { /* fcntl */ | |
6966 | return -KEY_fcntl; | |
6967 | } | |
6968 | ||
6969 | goto unknown; | |
6970 | ||
6971 | case 'l': | |
6972 | if (name[2] == 'o' && | |
6973 | name[3] == 'c' && | |
6974 | name[4] == 'k') | |
6975 | { /* flock */ | |
6976 | return -KEY_flock; | |
6977 | } | |
6978 | ||
6979 | goto unknown; | |
6980 | ||
6981 | default: | |
6982 | goto unknown; | |
6983 | } | |
6984 | ||
0d863452 RH |
6985 | case 'g': |
6986 | if (name[1] == 'i' && | |
6987 | name[2] == 'v' && | |
6988 | name[3] == 'e' && | |
6989 | name[4] == 'n') | |
6990 | { /* given */ | |
ef89dcc3 | 6991 | return (FEATURE_IS_ENABLED("switch") ? KEY_given : 0); |
0d863452 RH |
6992 | } |
6993 | ||
6994 | goto unknown; | |
6995 | ||
4c3bbe0f MHM |
6996 | case 'i': |
6997 | switch (name[1]) | |
6998 | { | |
6999 | case 'n': | |
7000 | if (name[2] == 'd' && | |
7001 | name[3] == 'e' && | |
7002 | name[4] == 'x') | |
7003 | { /* index */ | |
7004 | return -KEY_index; | |
7005 | } | |
7006 | ||
7007 | goto unknown; | |
7008 | ||
7009 | case 'o': | |
7010 | if (name[2] == 'c' && | |
7011 | name[3] == 't' && | |
7012 | name[4] == 'l') | |
7013 | { /* ioctl */ | |
7014 | return -KEY_ioctl; | |
7015 | } | |
7016 | ||
7017 | goto unknown; | |
7018 | ||
7019 | default: | |
7020 | goto unknown; | |
7021 | } | |
7022 | ||
7023 | case 'l': | |
7024 | switch (name[1]) | |
7025 | { | |
7026 | case 'o': | |
7027 | if (name[2] == 'c' && | |
7028 | name[3] == 'a' && | |
7029 | name[4] == 'l') | |
7030 | { /* local */ | |
7031 | return KEY_local; | |
7032 | } | |
7033 | ||
7034 | goto unknown; | |
7035 | ||
7036 | case 's': | |
7037 | if (name[2] == 't' && | |
7038 | name[3] == 'a' && | |
7039 | name[4] == 't') | |
7040 | { /* lstat */ | |
7041 | return -KEY_lstat; | |
7042 | } | |
7043 | ||
7044 | goto unknown; | |
7045 | ||
7046 | default: | |
7047 | goto unknown; | |
7048 | } | |
7049 | ||
7050 | case 'm': | |
7051 | if (name[1] == 'k' && | |
7052 | name[2] == 'd' && | |
7053 | name[3] == 'i' && | |
7054 | name[4] == 'r') | |
7055 | { /* mkdir */ | |
7056 | return -KEY_mkdir; | |
7057 | } | |
7058 | ||
7059 | goto unknown; | |
7060 | ||
7061 | case 'p': | |
7062 | if (name[1] == 'r' && | |
7063 | name[2] == 'i' && | |
7064 | name[3] == 'n' && | |
7065 | name[4] == 't') | |
7066 | { /* print */ | |
7067 | return KEY_print; | |
7068 | } | |
7069 | ||
7070 | goto unknown; | |
7071 | ||
7072 | case 'r': | |
7073 | switch (name[1]) | |
7074 | { | |
7075 | case 'e': | |
7076 | if (name[2] == 's' && | |
7077 | name[3] == 'e' && | |
7078 | name[4] == 't') | |
7079 | { /* reset */ | |
7080 | return -KEY_reset; | |
7081 | } | |
7082 | ||
7083 | goto unknown; | |
7084 | ||
7085 | case 'm': | |
7086 | if (name[2] == 'd' && | |
7087 | name[3] == 'i' && | |
7088 | name[4] == 'r') | |
7089 | { /* rmdir */ | |
7090 | return -KEY_rmdir; | |
7091 | } | |
7092 | ||
7093 | goto unknown; | |
7094 | ||
7095 | default: | |
7096 | goto unknown; | |
7097 | } | |
7098 | ||
7099 | case 's': | |
7100 | switch (name[1]) | |
7101 | { | |
7102 | case 'e': | |
7103 | if (name[2] == 'm' && | |
7104 | name[3] == 'o' && | |
7105 | name[4] == 'p') | |
7106 | { /* semop */ | |
7107 | return -KEY_semop; | |
7108 | } | |
7109 | ||
7110 | goto unknown; | |
7111 | ||
7112 | case 'h': | |
7113 | if (name[2] == 'i' && | |
7114 | name[3] == 'f' && | |
7115 | name[4] == 't') | |
7116 | { /* shift */ | |
7117 | return -KEY_shift; | |
7118 | } | |
7119 | ||
7120 | goto unknown; | |
7121 | ||
7122 | case 'l': | |
7123 | if (name[2] == 'e' && | |
7124 | name[3] == 'e' && | |
7125 | name[4] == 'p') | |
7126 | { /* sleep */ | |
7127 | return -KEY_sleep; | |
7128 | } | |
7129 | ||
7130 | goto unknown; | |
7131 | ||
7132 | case 'p': | |
7133 | if (name[2] == 'l' && | |
7134 | name[3] == 'i' && | |
7135 | name[4] == 't') | |
7136 | { /* split */ | |
7137 | return KEY_split; | |
7138 | } | |
7139 | ||
7140 | goto unknown; | |
7141 | ||
7142 | case 'r': | |
7143 | if (name[2] == 'a' && | |
7144 | name[3] == 'n' && | |
7145 | name[4] == 'd') | |
7146 | { /* srand */ | |
7147 | return -KEY_srand; | |
7148 | } | |
7149 | ||
7150 | goto unknown; | |
7151 | ||
7152 | case 't': | |
7153 | if (name[2] == 'u' && | |
7154 | name[3] == 'd' && | |
7155 | name[4] == 'y') | |
7156 | { /* study */ | |
7157 | return KEY_study; | |
7158 | } | |
7159 | ||
7160 | goto unknown; | |
7161 | ||
7162 | default: | |
7163 | goto unknown; | |
7164 | } | |
7165 | ||
7166 | case 't': | |
7167 | if (name[1] == 'i' && | |
7168 | name[2] == 'm' && | |
7169 | name[3] == 'e' && | |
7170 | name[4] == 's') | |
7171 | { /* times */ | |
7172 | return -KEY_times; | |
7173 | } | |
7174 | ||
7175 | goto unknown; | |
7176 | ||
7177 | case 'u': | |
7178 | switch (name[1]) | |
7179 | { | |
7180 | case 'm': | |
7181 | if (name[2] == 'a' && | |
7182 | name[3] == 's' && | |
7183 | name[4] == 'k') | |
7184 | { /* umask */ | |
7185 | return -KEY_umask; | |
7186 | } | |
7187 | ||
7188 | goto unknown; | |
7189 | ||
7190 | case 'n': | |
7191 | switch (name[2]) | |
7192 | { | |
7193 | case 'd': | |
7194 | if (name[3] == 'e' && | |
7195 | name[4] == 'f') | |
7196 | { /* undef */ | |
7197 | return KEY_undef; | |
7198 | } | |
7199 | ||
7200 | goto unknown; | |
7201 | ||
7202 | case 't': | |
7203 | if (name[3] == 'i') | |
7204 | { | |
7205 | switch (name[4]) | |
7206 | { | |
7207 | case 'e': | |
7208 | { /* untie */ | |
7209 | return KEY_untie; | |
7210 | } | |
7211 | ||
4c3bbe0f MHM |
7212 | case 'l': |
7213 | { /* until */ | |
7214 | return KEY_until; | |
7215 | } | |
7216 | ||
4c3bbe0f MHM |
7217 | default: |
7218 | goto unknown; | |
7219 | } | |
7220 | } | |
7221 | ||
7222 | goto unknown; | |
7223 | ||
7224 | default: | |
7225 | goto unknown; | |
7226 | } | |
7227 | ||
7228 | case 't': | |
7229 | if (name[2] == 'i' && | |
7230 | name[3] == 'm' && | |
7231 | name[4] == 'e') | |
7232 | { /* utime */ | |
7233 | return -KEY_utime; | |
7234 | } | |
7235 | ||
7236 | goto unknown; | |
7237 | ||
7238 | default: | |
7239 | goto unknown; | |
7240 | } | |
7241 | ||
7242 | case 'w': | |
7243 | switch (name[1]) | |
7244 | { | |
7245 | case 'h': | |
7246 | if (name[2] == 'i' && | |
7247 | name[3] == 'l' && | |
7248 | name[4] == 'e') | |
7249 | { /* while */ | |
7250 | return KEY_while; | |
7251 | } | |
7252 | ||
7253 | goto unknown; | |
7254 | ||
7255 | case 'r': | |
7256 | if (name[2] == 'i' && | |
7257 | name[3] == 't' && | |
7258 | name[4] == 'e') | |
7259 | { /* write */ | |
7260 | return -KEY_write; | |
7261 | } | |
7262 | ||
7263 | goto unknown; | |
7264 | ||
7265 | default: | |
7266 | goto unknown; | |
7267 | } | |
7268 | ||
7269 | default: | |
7270 | goto unknown; | |
e2e1dd5a | 7271 | } |
4c3bbe0f MHM |
7272 | |
7273 | case 6: /* 33 tokens of length 6 */ | |
7274 | switch (name[0]) | |
7275 | { | |
7276 | case 'a': | |
7277 | if (name[1] == 'c' && | |
7278 | name[2] == 'c' && | |
7279 | name[3] == 'e' && | |
7280 | name[4] == 'p' && | |
7281 | name[5] == 't') | |
7282 | { /* accept */ | |
7283 | return -KEY_accept; | |
7284 | } | |
7285 | ||
7286 | goto unknown; | |
7287 | ||
7288 | case 'c': | |
7289 | switch (name[1]) | |
7290 | { | |
7291 | case 'a': | |
7292 | if (name[2] == 'l' && | |
7293 | name[3] == 'l' && | |
7294 | name[4] == 'e' && | |
7295 | name[5] == 'r') | |
7296 | { /* caller */ | |
7297 | return -KEY_caller; | |
7298 | } | |
7299 | ||
7300 | goto unknown; | |
7301 | ||
7302 | case 'h': | |
7303 | if (name[2] == 'r' && | |
7304 | name[3] == 'o' && | |
7305 | name[4] == 'o' && | |
7306 | name[5] == 't') | |
7307 | { /* chroot */ | |
7308 | return -KEY_chroot; | |
7309 | } | |
7310 | ||
7311 | goto unknown; | |
7312 | ||
7313 | default: | |
7314 | goto unknown; | |
7315 | } | |
7316 | ||
7317 | case 'd': | |
7318 | if (name[1] == 'e' && | |
7319 | name[2] == 'l' && | |
7320 | name[3] == 'e' && | |
7321 | name[4] == 't' && | |
7322 | name[5] == 'e') | |
7323 | { /* delete */ | |
7324 | return KEY_delete; | |
7325 | } | |
7326 | ||
7327 | goto unknown; | |
7328 | ||
7329 | case 'e': | |
7330 | switch (name[1]) | |
7331 | { | |
7332 | case 'l': | |
7333 | if (name[2] == 's' && | |
7334 | name[3] == 'e' && | |
7335 | name[4] == 'i' && | |
7336 | name[5] == 'f') | |
7337 | { /* elseif */ | |
7338 | if(ckWARN_d(WARN_SYNTAX)) | |
7339 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif"); | |
7340 | } | |
7341 | ||
7342 | goto unknown; | |
7343 | ||
7344 | case 'x': | |
7345 | if (name[2] == 'i' && | |
7346 | name[3] == 's' && | |
7347 | name[4] == 't' && | |
7348 | name[5] == 's') | |
7349 | { /* exists */ | |
7350 | return KEY_exists; | |
7351 | } | |
7352 | ||
7353 | goto unknown; | |
7354 | ||
7355 | default: | |
7356 | goto unknown; | |
7357 | } | |
7358 | ||
7359 | case 'f': | |
7360 | switch (name[1]) | |
7361 | { | |
7362 | case 'i': | |
7363 | if (name[2] == 'l' && | |
7364 | name[3] == 'e' && | |
7365 | name[4] == 'n' && | |
7366 | name[5] == 'o') | |
7367 | { /* fileno */ | |
7368 | return -KEY_fileno; | |
7369 | } | |
7370 | ||
7371 | goto unknown; | |
7372 | ||
7373 | case 'o': | |
7374 | if (name[2] == 'r' && | |
7375 | name[3] == 'm' && | |
7376 | name[4] == 'a' && | |
7377 | name[5] == 't') | |
7378 | { /* format */ | |
7379 | return KEY_format; | |
7380 | } | |
7381 | ||
7382 | goto unknown; | |
7383 | ||
7384 | default: | |
7385 | goto unknown; | |
7386 | } | |
7387 | ||
7388 | case 'g': | |
7389 | if (name[1] == 'm' && | |
7390 | name[2] == 't' && | |
7391 | name[3] == 'i' && | |
7392 | name[4] == 'm' && | |
7393 | name[5] == 'e') | |
7394 | { /* gmtime */ | |
7395 | return -KEY_gmtime; | |
7396 | } | |
7397 | ||
7398 | goto unknown; | |
7399 | ||
7400 | case 'l': | |
7401 | switch (name[1]) | |
7402 | { | |
7403 | case 'e': | |
7404 | if (name[2] == 'n' && | |
7405 | name[3] == 'g' && | |
7406 | name[4] == 't' && | |
7407 | name[5] == 'h') | |
7408 | { /* length */ | |
7409 | return -KEY_length; | |
7410 | } | |
7411 | ||
7412 | goto unknown; | |
7413 | ||
7414 | case 'i': | |
7415 | if (name[2] == 's' && | |
7416 | name[3] == 't' && | |
7417 | name[4] == 'e' && | |
7418 | name[5] == 'n') | |
7419 | { /* listen */ | |
7420 | return -KEY_listen; | |
7421 | } | |
7422 | ||
7423 | goto unknown; | |
7424 | ||
7425 | default: | |
7426 | goto unknown; | |
7427 | } | |
7428 | ||
7429 | case 'm': | |
7430 | if (name[1] == 's' && | |
7431 | name[2] == 'g') | |
7432 | { | |
7433 | switch (name[3]) | |
7434 | { | |
7435 | case 'c': | |
7436 | if (name[4] == 't' && | |
7437 | name[5] == 'l') | |
7438 | { /* msgctl */ | |
7439 | return -KEY_msgctl; | |
7440 | } | |
7441 | ||
7442 | goto unknown; | |
7443 | ||
7444 | case 'g': | |
7445 | if (name[4] == 'e' && | |
7446 | name[5] == 't') | |
7447 | { /* msgget */ | |
7448 | return -KEY_msgget; | |
7449 | } | |
7450 | ||
7451 | goto unknown; | |
7452 | ||
7453 | case 'r': | |
7454 | if (name[4] == 'c' && | |
7455 | name[5] == 'v') | |
7456 | { /* msgrcv */ | |
7457 | return -KEY_msgrcv; | |
7458 | } | |
7459 | ||
7460 | goto unknown; | |
7461 | ||
7462 | case 's': | |
7463 | if (name[4] == 'n' && | |
7464 | name[5] == 'd') | |
7465 | { /* msgsnd */ | |
7466 | return -KEY_msgsnd; | |
7467 | } | |
7468 | ||
7469 | goto unknown; | |
7470 | ||
7471 | default: | |
7472 | goto unknown; | |
7473 | } | |
7474 | } | |
7475 | ||
7476 | goto unknown; | |
7477 | ||
7478 | case 'p': | |
7479 | if (name[1] == 'r' && | |
7480 | name[2] == 'i' && | |
7481 | name[3] == 'n' && | |
7482 | name[4] == 't' && | |
7483 | name[5] == 'f') | |
7484 | { /* printf */ | |
7485 | return KEY_printf; | |
7486 | } | |
7487 | ||
7488 | goto unknown; | |
7489 | ||
7490 | case 'r': | |
7491 | switch (name[1]) | |
7492 | { | |
7493 | case 'e': | |
7494 | switch (name[2]) | |
7495 | { | |
7496 | case 'n': | |
7497 | if (name[3] == 'a' && | |
7498 | name[4] == 'm' && | |
7499 | name[5] == 'e') | |
7500 | { /* rename */ | |
7501 | return -KEY_rename; | |
7502 | } | |
7503 | ||
7504 | goto unknown; | |
7505 | ||
7506 | case 't': | |
7507 | if (name[3] == 'u' && | |
7508 | name[4] == 'r' && | |
7509 | name[5] == 'n') | |
7510 | { /* return */ | |
7511 | return KEY_return; | |
7512 | } | |
7513 | ||
7514 | goto unknown; | |
7515 | ||
7516 | default: | |
7517 | goto unknown; | |
7518 | } | |
7519 | ||
7520 | case 'i': | |
7521 | if (name[2] == 'n' && | |
7522 | name[3] == 'd' && | |
7523 | name[4] == 'e' && | |
7524 | name[5] == 'x') | |
7525 | { /* rindex */ | |
7526 | return -KEY_rindex; | |
7527 | } | |
7528 | ||
7529 | goto unknown; | |
7530 | ||
7531 | default: | |
7532 | goto unknown; | |
7533 | } | |
7534 | ||
7535 | case 's': | |
7536 | switch (name[1]) | |
7537 | { | |
7538 | case 'c': | |
7539 | if (name[2] == 'a' && | |
7540 | name[3] == 'l' && | |
7541 | name[4] == 'a' && | |
7542 | name[5] == 'r') | |
7543 | { /* scalar */ | |
7544 | return KEY_scalar; | |
7545 | } | |
7546 | ||
7547 | goto unknown; | |
7548 | ||
7549 | case 'e': | |
7550 | switch (name[2]) | |
7551 | { | |
7552 | case 'l': | |
7553 | if (name[3] == 'e' && | |
7554 | name[4] == 'c' && | |
7555 | name[5] == 't') | |
7556 | { /* select */ | |
7557 | return -KEY_select; | |
7558 | } | |
7559 | ||
7560 | goto unknown; | |
7561 | ||
7562 | case 'm': | |
7563 | switch (name[3]) | |
7564 | { | |
7565 | case 'c': | |
7566 | if (name[4] == 't' && | |
7567 | name[5] == 'l') | |
7568 | { /* semctl */ | |
7569 | return -KEY_semctl; | |
7570 | } | |
7571 | ||
7572 | goto unknown; | |
7573 | ||
7574 | case 'g': | |
7575 | if (name[4] == 'e' && | |
7576 | name[5] == 't') | |
7577 | { /* semget */ | |
7578 | return -KEY_semget; | |
7579 | } | |
7580 | ||
7581 | goto unknown; | |
7582 | ||
7583 | default: | |
7584 | goto unknown; | |
7585 | } | |
7586 | ||
7587 | default: | |
7588 | goto unknown; | |
7589 | } | |
7590 | ||
7591 | case 'h': | |
7592 | if (name[2] == 'm') | |
7593 | { | |
7594 | switch (name[3]) | |
7595 | { | |
7596 | case 'c': | |
7597 | if (name[4] == 't' && | |
7598 | name[5] == 'l') | |
7599 | { /* shmctl */ | |
7600 | return -KEY_shmctl; | |
7601 | } | |
7602 | ||
7603 | goto unknown; | |
7604 | ||
7605 | case 'g': | |
7606 | if (name[4] == 'e' && | |
7607 | name[5] == 't') | |
7608 | { /* shmget */ | |
7609 | return -KEY_shmget; | |
7610 | } | |
7611 | ||
7612 | goto unknown; | |
7613 | ||
7614 | default: | |
7615 | goto unknown; | |
7616 | } | |
7617 | } | |
7618 | ||
7619 | goto unknown; | |
7620 | ||
7621 | case 'o': | |
7622 | if (name[2] == 'c' && | |
7623 | name[3] == 'k' && | |
7624 | name[4] == 'e' && | |
7625 | name[5] == 't') | |
7626 | { /* socket */ | |
7627 | return -KEY_socket; | |
7628 | } | |
7629 | ||
7630 | goto unknown; | |
7631 | ||
7632 | case 'p': | |
7633 | if (name[2] == 'l' && | |
7634 | name[3] == 'i' && | |
7635 | name[4] == 'c' && | |
7636 | name[5] == 'e') | |
7637 | { /* splice */ | |
7638 | return -KEY_splice; | |
7639 | } | |
7640 | ||
7641 | goto unknown; | |
7642 | ||
7643 | case 'u': | |
7644 | if (name[2] == 'b' && | |
7645 | name[3] == 's' && | |
7646 | name[4] == 't' && | |
7647 | name[5] == 'r') | |
7648 | { /* substr */ | |
7649 | return -KEY_substr; | |
7650 | } | |
7651 | ||
7652 | goto unknown; | |
7653 | ||
7654 | case 'y': | |
7655 | if (name[2] == 's' && | |
7656 | name[3] == 't' && | |
7657 | name[4] == 'e' && | |
7658 | name[5] == 'm') | |
7659 | { /* system */ | |
7660 | return -KEY_system; | |
7661 | } | |
7662 | ||
7663 | goto unknown; | |
7664 | ||
7665 | default: | |
7666 | goto unknown; | |
7667 | } | |
7668 | ||
7669 | case 'u': | |
7670 | if (name[1] == 'n') | |
7671 | { | |
7672 | switch (name[2]) | |
7673 | { | |
7674 | case 'l': | |
7675 | switch (name[3]) | |
7676 | { | |
7677 | case 'e': | |
7678 | if (name[4] == 's' && | |
7679 | name[5] == 's') | |
7680 | { /* unless */ | |
7681 | return KEY_unless; | |
7682 | } | |
7683 | ||
7684 | goto unknown; | |
7685 | ||
7686 | case 'i': | |
7687 | if (name[4] == 'n' && | |
7688 | name[5] == 'k') | |
7689 | { /* unlink */ | |
7690 | return -KEY_unlink; | |
7691 | } | |
7692 | ||
7693 | goto unknown; | |
7694 | ||
7695 | default: | |
7696 | goto unknown; | |
7697 | } | |
7698 | ||
7699 | case 'p': | |
7700 | if (name[3] == 'a' && | |
7701 | name[4] == 'c' && | |
7702 | name[5] == 'k') | |
7703 | { /* unpack */ | |
7704 | return -KEY_unpack; | |
7705 | } | |
7706 | ||
7707 | goto unknown; | |
7708 | ||
7709 | default: | |
7710 | goto unknown; | |
7711 | } | |
7712 | } | |
7713 | ||
7714 | goto unknown; | |
7715 | ||
7716 | case 'v': | |
7717 | if (name[1] == 'a' && | |
7718 | name[2] == 'l' && | |
7719 | name[3] == 'u' && | |
7720 | name[4] == 'e' && | |
7721 | name[5] == 's') | |
7722 | { /* values */ | |
7723 | return -KEY_values; | |
7724 | } | |
7725 | ||
7726 | goto unknown; | |
7727 | ||
7728 | default: | |
7729 | goto unknown; | |
e2e1dd5a | 7730 | } |
4c3bbe0f | 7731 | |
0d863452 | 7732 | case 7: /* 29 tokens of length 7 */ |
4c3bbe0f MHM |
7733 | switch (name[0]) |
7734 | { | |
7735 | case 'D': | |
7736 | if (name[1] == 'E' && | |
7737 | name[2] == 'S' && | |
7738 | name[3] == 'T' && | |
7739 | name[4] == 'R' && | |
7740 | name[5] == 'O' && | |
7741 | name[6] == 'Y') | |
7742 | { /* DESTROY */ | |
7743 | return KEY_DESTROY; | |
7744 | } | |
7745 | ||
7746 | goto unknown; | |
7747 | ||
7748 | case '_': | |
7749 | if (name[1] == '_' && | |
7750 | name[2] == 'E' && | |
7751 | name[3] == 'N' && | |
7752 | name[4] == 'D' && | |
7753 | name[5] == '_' && | |
7754 | name[6] == '_') | |
7755 | { /* __END__ */ | |
7756 | return KEY___END__; | |
7757 | } | |
7758 | ||
7759 | goto unknown; | |
7760 | ||
7761 | case 'b': | |
7762 | if (name[1] == 'i' && | |
7763 | name[2] == 'n' && | |
7764 | name[3] == 'm' && | |
7765 | name[4] == 'o' && | |
7766 | name[5] == 'd' && | |
7767 | name[6] == 'e') | |
7768 | { /* binmode */ | |
7769 | return -KEY_binmode; | |
7770 | } | |
7771 | ||
7772 | goto unknown; | |
7773 | ||
7774 | case 'c': | |
7775 | if (name[1] == 'o' && | |
7776 | name[2] == 'n' && | |
7777 | name[3] == 'n' && | |
7778 | name[4] == 'e' && | |
7779 | name[5] == 'c' && | |
7780 | name[6] == 't') | |
7781 | { /* connect */ | |
7782 | return -KEY_connect; | |
7783 | } | |
7784 | ||
7785 | goto unknown; | |
7786 | ||
7787 | case 'd': | |
7788 | switch (name[1]) | |
7789 | { | |
7790 | case 'b': | |
7791 | if (name[2] == 'm' && | |
7792 | name[3] == 'o' && | |
7793 | name[4] == 'p' && | |
7794 | name[5] == 'e' && | |
7795 | name[6] == 'n') | |
7796 | { /* dbmopen */ | |
7797 | return -KEY_dbmopen; | |
7798 | } | |
7799 | ||
7800 | goto unknown; | |
7801 | ||
7802 | case 'e': | |
0d863452 RH |
7803 | if (name[2] == 'f') |
7804 | { | |
7805 | switch (name[3]) | |
7806 | { | |
7807 | case 'a': | |
7808 | if (name[4] == 'u' && | |
7809 | name[5] == 'l' && | |
7810 | name[6] == 't') | |
7811 | { /* default */ | |
ef89dcc3 | 7812 | return (FEATURE_IS_ENABLED("switch") ? KEY_default : 0); |
0d863452 RH |
7813 | } |
7814 | ||
7815 | goto unknown; | |
7816 | ||
7817 | case 'i': | |
7818 | if (name[4] == 'n' && | |
4c3bbe0f MHM |
7819 | name[5] == 'e' && |
7820 | name[6] == 'd') | |
7821 | { /* defined */ | |
7822 | return KEY_defined; | |
7823 | } | |
7824 | ||
7825 | goto unknown; | |
7826 | ||
7827 | default: | |
7828 | goto unknown; | |
7829 | } | |
0d863452 RH |
7830 | } |
7831 | ||
7832 | goto unknown; | |
7833 | ||
7834 | default: | |
7835 | goto unknown; | |
7836 | } | |
4c3bbe0f MHM |
7837 | |
7838 | case 'f': | |
7839 | if (name[1] == 'o' && | |
7840 | name[2] == 'r' && | |
7841 | name[3] == 'e' && | |
7842 | name[4] == 'a' && | |
7843 | name[5] == 'c' && | |
7844 | name[6] == 'h') | |
7845 | { /* foreach */ | |
7846 | return KEY_foreach; | |
7847 | } | |
7848 | ||
7849 | goto unknown; | |
7850 | ||
7851 | case 'g': | |
7852 | if (name[1] == 'e' && | |
7853 | name[2] == 't' && | |
7854 | name[3] == 'p') | |
7855 | { | |
7856 | switch (name[4]) | |
7857 | { | |
7858 | case 'g': | |
7859 | if (name[5] == 'r' && | |
7860 | name[6] == 'p') | |
7861 | { /* getpgrp */ | |
7862 | return -KEY_getpgrp; | |
7863 | } | |
7864 | ||
7865 | goto unknown; | |
7866 | ||
7867 | case 'p': | |
7868 | if (name[5] == 'i' && | |
7869 | name[6] == 'd') | |
7870 | { /* getppid */ | |
7871 | return -KEY_getppid; | |
7872 | } | |
7873 | ||
7874 | goto unknown; | |
7875 | ||
7876 | default: | |
7877 | goto unknown; | |
7878 | } | |
7879 | } | |
7880 | ||
7881 | goto unknown; | |
7882 | ||
7883 | case 'l': | |
7884 | if (name[1] == 'c' && | |
7885 | name[2] == 'f' && | |
7886 | name[3] == 'i' && | |
7887 | name[4] == 'r' && | |
7888 | name[5] == 's' && | |
7889 | name[6] == 't') | |
7890 | { /* lcfirst */ | |
7891 | return -KEY_lcfirst; | |
7892 | } | |
7893 | ||
7894 | goto unknown; | |
7895 | ||
7896 | case 'o': | |
7897 | if (name[1] == 'p' && | |
7898 | name[2] == 'e' && | |
7899 | name[3] == 'n' && | |
7900 | name[4] == 'd' && | |
7901 | name[5] == 'i' && | |
7902 | name[6] == 'r') | |
7903 | { /* opendir */ | |
7904 | return -KEY_opendir; | |
7905 | } | |
7906 | ||
7907 | goto unknown; | |
7908 | ||
7909 | case 'p': | |
7910 | if (name[1] == 'a' && | |
7911 | name[2] == 'c' && | |
7912 | name[3] == 'k' && | |
7913 | name[4] == 'a' && | |
7914 | name[5] == 'g' && | |
7915 | name[6] == 'e') | |
7916 | { /* package */ | |
7917 | return KEY_package; | |
7918 | } | |
7919 | ||
7920 | goto unknown; | |
7921 | ||
7922 | case 'r': | |
7923 | if (name[1] == 'e') | |
7924 | { | |
7925 | switch (name[2]) | |
7926 | { | |
7927 | case 'a': | |
7928 | if (name[3] == 'd' && | |
7929 | name[4] == 'd' && | |
7930 | name[5] == 'i' && | |
7931 | name[6] == 'r') | |
7932 | { /* readdir */ | |
7933 | return -KEY_readdir; | |
7934 | } | |
7935 | ||
7936 | goto unknown; | |
7937 | ||
7938 | case 'q': | |
7939 | if (name[3] == 'u' && | |
7940 | name[4] == 'i' && | |
7941 | name[5] == 'r' && | |
7942 | name[6] == 'e') | |
7943 | { /* require */ | |
7944 | return KEY_require; | |
7945 | } | |
7946 | ||
7947 | goto unknown; | |
7948 | ||
7949 | case 'v': | |
7950 | if (name[3] == 'e' && | |
7951 | name[4] == 'r' && | |
7952 | name[5] == 's' && | |
7953 | name[6] == 'e') | |
7954 | { /* reverse */ | |
7955 | return -KEY_reverse; | |
7956 | } | |
7957 | ||
7958 | goto unknown; | |
7959 | ||
7960 | default: | |
7961 | goto unknown; | |
7962 | } | |
7963 | } | |
7964 | ||
7965 | goto unknown; | |
7966 | ||
7967 | case 's': | |
7968 | switch (name[1]) | |
7969 | { | |
7970 | case 'e': | |
7971 | switch (name[2]) | |
7972 | { | |
7973 | case 'e': | |
7974 | if (name[3] == 'k' && | |
7975 | name[4] == 'd' && | |
7976 | name[5] == 'i' && | |
7977 | name[6] == 'r') | |
7978 | { /* seekdir */ | |
7979 | return -KEY_seekdir; | |
7980 | } | |
7981 | ||
7982 | goto unknown; | |
7983 | ||
7984 | case 't': | |
7985 | if (name[3] == 'p' && | |
7986 | name[4] == 'g' && | |
7987 | name[5] == 'r' && | |
7988 | name[6] == 'p') | |
7989 | { /* setpgrp */ | |
7990 | return -KEY_setpgrp; | |
7991 | } | |
7992 | ||
7993 | goto unknown; | |
7994 | ||
7995 | default: | |
7996 | goto unknown; | |
7997 | } | |
7998 | ||
7999 | case 'h': | |
8000 | if (name[2] == 'm' && | |
8001 | name[3] == 'r' && | |
8002 | name[4] == 'e' && | |
8003 | name[5] == 'a' && | |
8004 | name[6] == 'd') | |
8005 | { /* shmread */ | |
8006 | return -KEY_shmread; | |
8007 | } | |
8008 | ||
8009 | goto unknown; | |
8010 | ||
8011 | case 'p': | |
8012 | if (name[2] == 'r' && | |
8013 | name[3] == 'i' && | |
8014 | name[4] == 'n' && | |
8015 | name[5] == 't' && | |
8016 | name[6] == 'f') | |
8017 | { /* sprintf */ | |
8018 | return -KEY_sprintf; | |
8019 | } | |
8020 | ||
8021 | goto unknown; | |
8022 | ||
8023 | case 'y': | |
8024 | switch (name[2]) | |
8025 | { | |
8026 | case 'm': | |
8027 | if (name[3] == 'l' && | |
8028 | name[4] == 'i' && | |
8029 | name[5] == 'n' && | |
8030 | name[6] == 'k') | |
8031 | { /* symlink */ | |
8032 | return -KEY_symlink; | |
8033 | } | |
8034 | ||
8035 | goto unknown; | |
8036 | ||
8037 | case 's': | |
8038 | switch (name[3]) | |
8039 | { | |
8040 | case 'c': | |
8041 | if (name[4] == 'a' && | |
8042 | name[5] == 'l' && | |
8043 | name[6] == 'l') | |
8044 | { /* syscall */ | |
8045 | return -KEY_syscall; | |
8046 | } | |
8047 | ||
8048 | goto unknown; | |
8049 | ||
8050 | case 'o': | |
8051 | if (name[4] == 'p' && | |
8052 | name[5] == 'e' && | |
8053 | name[6] == 'n') | |
8054 | { /* sysopen */ | |
8055 | return -KEY_sysopen; | |
8056 | } | |
8057 | ||
8058 | goto unknown; | |
8059 | ||
8060 | case 'r': | |
8061 | if (name[4] == 'e' && | |
8062 | name[5] == 'a' && | |
8063 | name[6] == 'd') | |
8064 | { /* sysread */ | |
8065 | return -KEY_sysread; | |
8066 | } | |
8067 | ||
8068 | goto unknown; | |
8069 | ||
8070 | case 's': | |
8071 | if (name[4] == 'e' && | |
8072 | name[5] == 'e' && | |
8073 | name[6] == 'k') | |
8074 | { /* sysseek */ | |
8075 | return -KEY_sysseek; | |
8076 | } | |
8077 | ||
8078 | goto unknown; | |
8079 | ||
8080 | default: | |
8081 | goto unknown; | |
8082 | } | |
8083 | ||
8084 | default: | |
8085 | goto unknown; | |
8086 | } | |
8087 | ||
8088 | default: | |
8089 | goto unknown; | |
8090 | } | |
8091 | ||
8092 | case 't': | |
8093 | if (name[1] == 'e' && | |
8094 | name[2] == 'l' && | |
8095 | name[3] == 'l' && | |
8096 | name[4] == 'd' && | |
8097 | name[5] == 'i' && | |
8098 | name[6] == 'r') | |
8099 | { /* telldir */ | |
8100 | return -KEY_telldir; | |
8101 | } | |
8102 | ||
8103 | goto unknown; | |
8104 | ||
8105 | case 'u': | |
8106 | switch (name[1]) | |
8107 | { | |
8108 | case 'c': | |
8109 | if (name[2] == 'f' && | |
8110 | name[3] == 'i' && | |
8111 | name[4] == 'r' && | |
8112 | name[5] == 's' && | |
8113 | name[6] == 't') | |
8114 | { /* ucfirst */ | |
8115 | return -KEY_ucfirst; | |
8116 | } | |
8117 | ||
8118 | goto unknown; | |
8119 | ||
8120 | case 'n': | |
8121 | if (name[2] == 's' && | |
8122 | name[3] == 'h' && | |
8123 | name[4] == 'i' && | |
8124 | name[5] == 'f' && | |
8125 | name[6] == 't') | |
8126 | { /* unshift */ | |
8127 | return -KEY_unshift; | |
8128 | } | |
8129 | ||
8130 | goto unknown; | |
8131 | ||
8132 | default: | |
8133 | goto unknown; | |
8134 | } | |
8135 | ||
8136 | case 'w': | |
8137 | if (name[1] == 'a' && | |
8138 | name[2] == 'i' && | |
8139 | name[3] == 't' && | |
8140 | name[4] == 'p' && | |
8141 | name[5] == 'i' && | |
8142 | name[6] == 'd') | |
8143 | { /* waitpid */ | |
8144 | return -KEY_waitpid; | |
8145 | } | |
8146 | ||
8147 | goto unknown; | |
8148 | ||
8149 | default: | |
8150 | goto unknown; | |
8151 | } | |
8152 | ||
8153 | case 8: /* 26 tokens of length 8 */ | |
8154 | switch (name[0]) | |
8155 | { | |
8156 | case 'A': | |
8157 | if (name[1] == 'U' && | |
8158 | name[2] == 'T' && | |
8159 | name[3] == 'O' && | |
8160 | name[4] == 'L' && | |
8161 | name[5] == 'O' && | |
8162 | name[6] == 'A' && | |
8163 | name[7] == 'D') | |
8164 | { /* AUTOLOAD */ | |
8165 | return KEY_AUTOLOAD; | |
8166 | } | |
8167 | ||
8168 | goto unknown; | |
8169 | ||
8170 | case '_': | |
8171 | if (name[1] == '_') | |
8172 | { | |
8173 | switch (name[2]) | |
8174 | { | |
8175 | case 'D': | |
8176 | if (name[3] == 'A' && | |
8177 | name[4] == 'T' && | |
8178 | name[5] == 'A' && | |
8179 | name[6] == '_' && | |
8180 | name[7] == '_') | |
8181 | { /* __DATA__ */ | |
8182 | return KEY___DATA__; | |
8183 | } | |
8184 | ||
8185 | goto unknown; | |
8186 | ||
8187 | case 'F': | |
8188 | if (name[3] == 'I' && | |
8189 | name[4] == 'L' && | |
8190 | name[5] == 'E' && | |
8191 | name[6] == '_' && | |
8192 | name[7] == '_') | |
8193 | { /* __FILE__ */ | |
8194 | return -KEY___FILE__; | |
8195 | } | |
8196 | ||
8197 | goto unknown; | |
8198 | ||
8199 | case 'L': | |
8200 | if (name[3] == 'I' && | |
8201 | name[4] == 'N' && | |
8202 | name[5] == 'E' && | |
8203 | name[6] == '_' && | |
8204 | name[7] == '_') | |
8205 | { /* __LINE__ */ | |
8206 | return -KEY___LINE__; | |
8207 | } | |
8208 | ||
8209 | goto unknown; | |
8210 | ||
8211 | default: | |
8212 | goto unknown; | |
8213 | } | |
8214 | } | |
8215 | ||
8216 | goto unknown; | |
8217 | ||
8218 | case 'c': | |
8219 | switch (name[1]) | |
8220 | { | |
8221 | case 'l': | |
8222 | if (name[2] == 'o' && | |
8223 | name[3] == 's' && | |
8224 | name[4] == 'e' && | |
8225 | name[5] == 'd' && | |
8226 | name[6] == 'i' && | |
8227 | name[7] == 'r') | |
8228 | { /* closedir */ | |
8229 | return -KEY_closedir; | |
8230 | } | |
8231 | ||
8232 | goto unknown; | |
8233 | ||
8234 | case 'o': | |
8235 | if (name[2] == 'n' && | |
8236 | name[3] == 't' && | |
8237 | name[4] == 'i' && | |
8238 | name[5] == 'n' && | |
8239 | name[6] == 'u' && | |
8240 | name[7] == 'e') | |
8241 | { /* continue */ | |
8242 | return -KEY_continue; | |
8243 | } | |
8244 | ||
8245 | goto unknown; | |
8246 | ||
8247 | default: | |
8248 | goto unknown; | |
8249 | } | |
8250 | ||
8251 | case 'd': | |
8252 | if (name[1] == 'b' && | |
8253 | name[2] == 'm' && | |
8254 | name[3] == 'c' && | |
8255 | name[4] == 'l' && | |
8256 | name[5] == 'o' && | |
8257 | name[6] == 's' && | |
8258 | name[7] == 'e') | |
8259 | { /* dbmclose */ | |
8260 | return -KEY_dbmclose; | |
8261 | } | |
8262 | ||
8263 | goto unknown; | |
8264 | ||
8265 | case 'e': | |
8266 | if (name[1] == 'n' && | |
8267 | name[2] == 'd') | |
8268 | { | |
8269 | switch (name[3]) | |
8270 | { | |
8271 | case 'g': | |
8272 | if (name[4] == 'r' && | |
8273 | name[5] == 'e' && | |
8274 | name[6] == 'n' && | |
8275 | name[7] == 't') | |
8276 | { /* endgrent */ | |
8277 | return -KEY_endgrent; | |
8278 | } | |
8279 | ||
8280 | goto unknown; | |
8281 | ||
8282 | case 'p': | |
8283 | if (name[4] == 'w' && | |
8284 | name[5] == 'e' && | |
8285 | name[6] == 'n' && | |
8286 | name[7] == 't') | |
8287 | { /* endpwent */ | |
8288 | return -KEY_endpwent; | |
8289 | } | |
8290 | ||
8291 | goto unknown; | |
8292 | ||
8293 | default: | |
8294 | goto unknown; | |
8295 | } | |
8296 | } | |
8297 | ||
8298 | goto unknown; | |
8299 | ||
8300 | case 'f': | |
8301 | if (name[1] == 'o' && | |
8302 | name[2] == 'r' && | |
8303 | name[3] == 'm' && | |
8304 | name[4] == 'l' && | |
8305 | name[5] == 'i' && | |
8306 | name[6] == 'n' && | |
8307 | name[7] == 'e') | |
8308 | { /* formline */ | |
8309 | return -KEY_formline; | |
8310 | } | |
8311 | ||
8312 | goto unknown; | |
8313 | ||
8314 | case 'g': | |
8315 | if (name[1] == 'e' && | |
8316 | name[2] == 't') | |
8317 | { | |
8318 | switch (name[3]) | |
8319 | { | |
8320 | case 'g': | |
8321 | if (name[4] == 'r') | |
8322 | { | |
8323 | switch (name[5]) | |
8324 | { | |
8325 | case 'e': | |
8326 | if (name[6] == 'n' && | |
8327 | name[7] == 't') | |
8328 | { /* getgrent */ | |
8329 | return -KEY_getgrent; | |
8330 | } | |
8331 | ||
8332 | goto unknown; | |
8333 | ||
8334 | case 'g': | |
8335 | if (name[6] == 'i' && | |
8336 | name[7] == 'd') | |
8337 | { /* getgrgid */ | |
8338 | return -KEY_getgrgid; | |
8339 | } | |
8340 | ||
8341 | goto unknown; | |
8342 | ||
8343 | case 'n': | |
8344 | if (name[6] == 'a' && | |
8345 | name[7] == 'm') | |
8346 | { /* getgrnam */ | |
8347 | return -KEY_getgrnam; | |
8348 | } | |
8349 | ||
8350 | goto unknown; | |
8351 | ||
8352 | default: | |
8353 | goto unknown; | |
8354 | } | |
8355 | } | |
8356 | ||
8357 | goto unknown; | |
8358 | ||
8359 | case 'l': | |
8360 | if (name[4] == 'o' && | |
8361 | name[5] == 'g' && | |
8362 | name[6] == 'i' && | |
8363 | name[7] == 'n') | |
8364 | { /* getlogin */ | |
8365 | return -KEY_getlogin; | |
8366 | } | |
8367 | ||
8368 | goto unknown; | |
8369 | ||
8370 | case 'p': | |
8371 | if (name[4] == 'w') | |
8372 | { | |
8373 | switch (name[5]) | |
8374 | { | |
8375 | case 'e': | |
8376 | if (name[6] == 'n' && | |
8377 | name[7] == 't') | |
8378 | { /* getpwent */ | |
8379 | return -KEY_getpwent; | |
8380 | } | |
8381 | ||
8382 | goto unknown; | |
8383 | ||
8384 | case 'n': | |
8385 | if (name[6] == 'a' && | |
8386 | name[7] == 'm') | |
8387 | { /* getpwnam */ | |
8388 | return -KEY_getpwnam; | |
8389 | } | |
8390 | ||
8391 | goto unknown; | |
8392 | ||
8393 | case 'u': | |
8394 | if (name[6] == 'i' && | |
8395 | name[7] == 'd') | |
8396 | { /* getpwuid */ | |
8397 | return -KEY_getpwuid; | |
8398 | } | |
8399 | ||
8400 | goto unknown; | |
8401 | ||
8402 | default: | |
8403 | goto unknown; | |
8404 | } | |
8405 | } | |
8406 | ||
8407 | goto unknown; | |
8408 | ||
8409 | default: | |
8410 | goto unknown; | |
8411 | } | |
8412 | } | |
8413 | ||
8414 | goto unknown; | |
8415 | ||
8416 | case 'r': | |
8417 | if (name[1] == 'e' && | |
8418 | name[2] == 'a' && | |
8419 | name[3] == 'd') | |
8420 | { | |
8421 | switch (name[4]) | |
8422 | { | |
8423 | case 'l': | |
8424 | if (name[5] == 'i' && | |
8425 | name[6] == 'n') | |
8426 | { | |
8427 | switch (name[7]) | |
8428 | { | |
8429 | case 'e': | |
8430 | { /* readline */ | |
8431 | return -KEY_readline; | |
8432 | } | |
8433 | ||
4c3bbe0f MHM |
8434 | case 'k': |
8435 | { /* readlink */ | |
8436 | return -KEY_readlink; | |
8437 | } | |
8438 | ||
4c3bbe0f MHM |
8439 | default: |
8440 | goto unknown; | |
8441 | } | |
8442 | } | |
8443 | ||
8444 | goto unknown; | |
8445 | ||
8446 | case 'p': | |
8447 | if (name[5] == 'i' && | |
8448 | name[6] == 'p' && | |
8449 | name[7] == 'e') | |
8450 | { /* readpipe */ | |
8451 | return -KEY_readpipe; | |
8452 | } | |
8453 | ||
8454 | goto unknown; | |
8455 | ||
8456 | default: | |
8457 | goto unknown; | |
8458 | } | |
8459 | } | |
8460 | ||
8461 | goto unknown; | |
8462 | ||
8463 | case 's': | |
8464 | switch (name[1]) | |
8465 | { | |
8466 | case 'e': | |
8467 | if (name[2] == 't') | |
8468 | { | |
8469 | switch (name[3]) | |
8470 | { | |
8471 | case 'g': | |
8472 | if (name[4] == 'r' && | |
8473 | name[5] == 'e' && | |
8474 | name[6] == 'n' && | |
8475 | name[7] == 't') | |
8476 | { /* setgrent */ | |
8477 | return -KEY_setgrent; | |
8478 | } | |
8479 | ||
8480 | goto unknown; | |
8481 | ||
8482 | case 'p': | |
8483 | if (name[4] == 'w' && | |
8484 | name[5] == 'e' && | |
8485 | name[6] == 'n' && | |
8486 | name[7] == 't') | |
8487 | { /* setpwent */ | |
8488 | return -KEY_setpwent; | |
8489 | } | |
8490 | ||
8491 | goto unknown; | |
8492 | ||
8493 | default: | |
8494 | goto unknown; | |
8495 | } | |
8496 | } | |
8497 | ||
8498 | goto unknown; | |
8499 | ||
8500 | case 'h': | |
8501 | switch (name[2]) | |
8502 | { | |
8503 | case 'm': | |
8504 | if (name[3] == 'w' && | |
8505 | name[4] == 'r' && | |
8506 | name[5] == 'i' && | |
8507 | name[6] == 't' && | |
8508 | name[7] == 'e') | |
8509 | { /* shmwrite */ | |
8510 | return -KEY_shmwrite; | |
8511 | } | |
8512 | ||
8513 | goto unknown; | |
8514 | ||
8515 | case 'u': | |
8516 | if (name[3] == 't' && | |
8517 | name[4] == 'd' && | |
8518 | name[5] == 'o' && | |
8519 | name[6] == 'w' && | |
8520 | name[7] == 'n') | |
8521 | { /* shutdown */ | |
8522 | return -KEY_shutdown; | |
8523 | } | |
8524 | ||
8525 | goto unknown; | |
8526 | ||
8527 | default: | |
8528 | goto unknown; | |
8529 | } | |
8530 | ||
8531 | case 'y': | |
8532 | if (name[2] == 's' && | |
8533 | name[3] == 'w' && | |
8534 | name[4] == 'r' && | |
8535 | name[5] == 'i' && | |
8536 | name[6] == 't' && | |
8537 | name[7] == 'e') | |
8538 | { /* syswrite */ | |
8539 | return -KEY_syswrite; | |
8540 | } | |
8541 | ||
8542 | goto unknown; | |
8543 | ||
8544 | default: | |
8545 | goto unknown; | |
8546 | } | |
8547 | ||
8548 | case 't': | |
8549 | if (name[1] == 'r' && | |
8550 | name[2] == 'u' && | |
8551 | name[3] == 'n' && | |
8552 | name[4] == 'c' && | |
8553 | name[5] == 'a' && | |
8554 | name[6] == 't' && | |
8555 | name[7] == 'e') | |
8556 | { /* truncate */ | |
8557 | return -KEY_truncate; | |
8558 | } | |
8559 | ||
8560 | goto unknown; | |
8561 | ||
8562 | default: | |
8563 | goto unknown; | |
8564 | } | |
8565 | ||
8566 | case 9: /* 8 tokens of length 9 */ | |
8567 | switch (name[0]) | |
8568 | { | |
8569 | case 'e': | |
8570 | if (name[1] == 'n' && | |
8571 | name[2] == 'd' && | |
8572 | name[3] == 'n' && | |
8573 | name[4] == 'e' && | |
8574 | name[5] == 't' && | |
8575 | name[6] == 'e' && | |
8576 | name[7] == 'n' && | |
8577 | name[8] == 't') | |
8578 | { /* endnetent */ | |
8579 | return -KEY_endnetent; | |
8580 | } | |
8581 | ||
8582 | goto unknown; | |
8583 | ||
8584 | case 'g': | |
8585 | if (name[1] == 'e' && | |
8586 | name[2] == 't' && | |
8587 | name[3] == 'n' && | |
8588 | name[4] == 'e' && | |
8589 | name[5] == 't' && | |
8590 | name[6] == 'e' && | |
8591 | name[7] == 'n' && | |
8592 | name[8] == 't') | |
8593 | { /* getnetent */ | |
8594 | return -KEY_getnetent; | |
8595 | } | |
8596 | ||
8597 | goto unknown; | |
8598 | ||
8599 | case 'l': | |
8600 | if (name[1] == 'o' && | |
8601 | name[2] == 'c' && | |
8602 | name[3] == 'a' && | |
8603 | name[4] == 'l' && | |
8604 | name[5] == 't' && | |
8605 | name[6] == 'i' && | |
8606 | name[7] == 'm' && | |
8607 | name[8] == 'e') | |
8608 | { /* localtime */ | |
8609 | return -KEY_localtime; | |
8610 | } | |
8611 | ||
8612 | goto unknown; | |
8613 | ||
8614 | case 'p': | |
8615 | if (name[1] == 'r' && | |
8616 | name[2] == 'o' && | |
8617 | name[3] == 't' && | |
8618 | name[4] == 'o' && | |
8619 | name[5] == 't' && | |
8620 | name[6] == 'y' && | |
8621 | name[7] == 'p' && | |
8622 | name[8] == 'e') | |
8623 | { /* prototype */ | |
8624 | return KEY_prototype; | |
8625 | } | |
8626 | ||
8627 | goto unknown; | |
8628 | ||
8629 | case 'q': | |
8630 | if (name[1] == 'u' && | |
8631 | name[2] == 'o' && | |
8632 | name[3] == 't' && | |
8633 | name[4] == 'e' && | |
8634 | name[5] == 'm' && | |
8635 | name[6] == 'e' && | |
8636 | name[7] == 't' && | |
8637 | name[8] == 'a') | |
8638 | { /* quotemeta */ | |
8639 | return -KEY_quotemeta; | |
8640 | } | |
8641 | ||
8642 | goto unknown; | |
8643 | ||
8644 | case 'r': | |
8645 | if (name[1] == 'e' && | |
8646 | name[2] == 'w' && | |
8647 | name[3] == 'i' && | |
8648 | name[4] == 'n' && | |
8649 | name[5] == 'd' && | |
8650 | name[6] == 'd' && | |
8651 | name[7] == 'i' && | |
8652 | name[8] == 'r') | |
8653 | { /* rewinddir */ | |
8654 | return -KEY_rewinddir; | |
8655 | } | |
8656 | ||
8657 | goto unknown; | |
8658 | ||
8659 | case 's': | |
8660 | if (name[1] == 'e' && | |
8661 | name[2] == 't' && | |
8662 | name[3] == 'n' && | |
8663 | name[4] == 'e' && | |
8664 | name[5] == 't' && | |
8665 | name[6] == 'e' && | |
8666 | name[7] == 'n' && | |
8667 | name[8] == 't') | |
8668 | { /* setnetent */ | |
8669 | return -KEY_setnetent; | |
8670 | } | |
8671 | ||
8672 | goto unknown; | |
8673 | ||
8674 | case 'w': | |
8675 | if (name[1] == 'a' && | |
8676 | name[2] == 'n' && | |
8677 | name[3] == 't' && | |
8678 | name[4] == 'a' && | |
8679 | name[5] == 'r' && | |
8680 | name[6] == 'r' && | |
8681 | name[7] == 'a' && | |
8682 | name[8] == 'y') | |
8683 | { /* wantarray */ | |
8684 | return -KEY_wantarray; | |
8685 | } | |
8686 | ||
8687 | goto unknown; | |
8688 | ||
8689 | default: | |
8690 | goto unknown; | |
8691 | } | |
8692 | ||
8693 | case 10: /* 9 tokens of length 10 */ | |
8694 | switch (name[0]) | |
8695 | { | |
8696 | case 'e': | |
8697 | if (name[1] == 'n' && | |
8698 | name[2] == 'd') | |
8699 | { | |
8700 | switch (name[3]) | |
8701 | { | |
8702 | case 'h': | |
8703 | if (name[4] == 'o' && | |
8704 | name[5] == 's' && | |
8705 | name[6] == 't' && | |
8706 | name[7] == 'e' && | |
8707 | name[8] == 'n' && | |
8708 | name[9] == 't') | |
8709 | { /* endhostent */ | |
8710 | return -KEY_endhostent; | |
8711 | } | |
8712 | ||
8713 | goto unknown; | |
8714 | ||
8715 | case 's': | |
8716 | if (name[4] == 'e' && | |
8717 | name[5] == 'r' && | |
8718 | name[6] == 'v' && | |
8719 | name[7] == 'e' && | |
8720 | name[8] == 'n' && | |
8721 | name[9] == 't') | |
8722 | { /* endservent */ | |
8723 | return -KEY_endservent; | |
8724 | } | |
8725 | ||
8726 | goto unknown; | |
8727 | ||
8728 | default: | |
8729 | goto unknown; | |
8730 | } | |
8731 | } | |
8732 | ||
8733 | goto unknown; | |
8734 | ||
8735 | case 'g': | |
8736 | if (name[1] == 'e' && | |
8737 | name[2] == 't') | |
8738 | { | |
8739 | switch (name[3]) | |
8740 | { | |
8741 | case 'h': | |
8742 | if (name[4] == 'o' && | |
8743 | name[5] == 's' && | |
8744 | name[6] == 't' && | |
8745 | name[7] == 'e' && | |
8746 | name[8] == 'n' && | |
8747 | name[9] == 't') | |
8748 | { /* gethostent */ | |
8749 | return -KEY_gethostent; | |
8750 | } | |
8751 | ||
8752 | goto unknown; | |
8753 | ||
8754 | case 's': | |
8755 | switch (name[4]) | |
8756 | { | |
8757 | case 'e': | |
8758 | if (name[5] == 'r' && | |
8759 | name[6] == 'v' && | |
8760 | name[7] == 'e' && | |
8761 | name[8] == 'n' && | |
8762 | name[9] == 't') | |
8763 | { /* getservent */ | |
8764 | return -KEY_getservent; | |
8765 | } | |
8766 | ||
8767 | goto unknown; | |
8768 | ||
8769 | case 'o': | |
8770 | if (name[5] == 'c' && | |
8771 | name[6] == 'k' && | |
8772 | name[7] == 'o' && | |
8773 | name[8] == 'p' && | |
8774 | name[9] == 't') | |
8775 | { /* getsockopt */ | |
8776 | return -KEY_getsockopt; | |
8777 | } | |
8778 | ||
8779 | goto unknown; | |
8780 | ||
8781 | default: | |
8782 | goto unknown; | |
8783 | } | |
8784 | ||
8785 | default: | |
8786 | goto unknown; | |
8787 | } | |
8788 | } | |
8789 | ||
8790 | goto unknown; | |
8791 | ||
8792 | case 's': | |
8793 | switch (name[1]) | |
8794 | { | |
8795 | case 'e': | |
8796 | if (name[2] == 't') | |
8797 | { | |
8798 | switch (name[3]) | |
8799 | { | |
8800 | case 'h': | |
8801 | if (name[4] == 'o' && | |
8802 | name[5] == 's' && | |
8803 | name[6] == 't' && | |
8804 | name[7] == 'e' && | |
8805 | name[8] == 'n' && | |
8806 | name[9] == 't') | |
8807 | { /* sethostent */ | |
8808 | return -KEY_sethostent; | |
8809 | } | |
8810 | ||
8811 | goto unknown; | |
8812 | ||
8813 | case 's': | |
8814 | switch (name[4]) | |
8815 | { | |
8816 | case 'e': | |
8817 | if (name[5] == 'r' && | |
8818 | name[6] == 'v' && | |
8819 | name[7] == 'e' && | |
8820 | name[8] == 'n' && | |
8821 | name[9] == 't') | |
8822 | { /* setservent */ | |
8823 | return -KEY_setservent; | |
8824 | } | |
8825 | ||
8826 | goto unknown; | |
8827 | ||
8828 | case 'o': | |
8829 | if (name[5] == 'c' && | |
8830 | name[6] == 'k' && | |
8831 | name[7] == 'o' && | |
8832 | name[8] == 'p' && | |
8833 | name[9] == 't') | |
8834 | { /* setsockopt */ | |
8835 | return -KEY_setsockopt; | |
8836 | } | |
8837 | ||
8838 | goto unknown; | |
8839 | ||
8840 | default: | |
8841 | goto unknown; | |
8842 | } | |
8843 | ||
8844 | default: | |
8845 | goto unknown; | |
8846 | } | |
8847 | } | |
8848 | ||
8849 | goto unknown; | |
8850 | ||
8851 | case 'o': | |
8852 | if (name[2] == 'c' && | |
8853 | name[3] == 'k' && | |
8854 | name[4] == 'e' && | |
8855 | name[5] == 't' && | |
8856 | name[6] == 'p' && | |
8857 | name[7] == 'a' && | |
8858 | name[8] == 'i' && | |
8859 | name[9] == 'r') | |
8860 | { /* socketpair */ | |
8861 | return -KEY_socketpair; | |
8862 | } | |
8863 | ||
8864 | goto unknown; | |
8865 | ||
8866 | default: | |
8867 | goto unknown; | |
8868 | } | |
8869 | ||
8870 | default: | |
8871 | goto unknown; | |
e2e1dd5a | 8872 | } |
4c3bbe0f MHM |
8873 | |
8874 | case 11: /* 8 tokens of length 11 */ | |
8875 | switch (name[0]) | |
8876 | { | |
8877 | case '_': | |
8878 | if (name[1] == '_' && | |
8879 | name[2] == 'P' && | |
8880 | name[3] == 'A' && | |
8881 | name[4] == 'C' && | |
8882 | name[5] == 'K' && | |
8883 | name[6] == 'A' && | |
8884 | name[7] == 'G' && | |
8885 | name[8] == 'E' && | |
8886 | name[9] == '_' && | |
8887 | name[10] == '_') | |
8888 | { /* __PACKAGE__ */ | |
8889 | return -KEY___PACKAGE__; | |
8890 | } | |
8891 | ||
8892 | goto unknown; | |
8893 | ||
8894 | case 'e': | |
8895 | if (name[1] == 'n' && | |
8896 | name[2] == 'd' && | |
8897 | name[3] == 'p' && | |
8898 | name[4] == 'r' && | |
8899 | name[5] == 'o' && | |
8900 | name[6] == 't' && | |
8901 | name[7] == 'o' && | |
8902 | name[8] == 'e' && | |
8903 | name[9] == 'n' && | |
8904 | name[10] == 't') | |
8905 | { /* endprotoent */ | |
8906 | return -KEY_endprotoent; | |
8907 | } | |
8908 | ||
8909 | goto unknown; | |
8910 | ||
8911 | case 'g': | |
8912 | if (name[1] == 'e' && | |
8913 | name[2] == 't') | |
8914 | { | |
8915 | switch (name[3]) | |
8916 | { | |
8917 | case 'p': | |
8918 | switch (name[4]) | |
8919 | { | |
8920 | case 'e': | |
8921 | if (name[5] == 'e' && | |
8922 | name[6] == 'r' && | |
8923 | name[7] == 'n' && | |
8924 | name[8] == 'a' && | |
8925 | name[9] == 'm' && | |
8926 | name[10] == 'e') | |
8927 | { /* getpeername */ | |
8928 | return -KEY_getpeername; | |
8929 | } | |
8930 | ||
8931 | goto unknown; | |
8932 | ||
8933 | case 'r': | |
8934 | switch (name[5]) | |
8935 | { | |
8936 | case 'i': | |
8937 | if (name[6] == 'o' && | |
8938 | name[7] == 'r' && | |
8939 | name[8] == 'i' && | |
8940 | name[9] == 't' && | |
8941 | name[10] == 'y') | |
8942 | { /* getpriority */ | |
8943 | return -KEY_getpriority; | |
8944 | } | |
8945 | ||
8946 | goto unknown; | |
8947 | ||
8948 | case 'o': | |
8949 | if (name[6] == 't' && | |
8950 | name[7] == 'o' && | |
8951 | name[8] == 'e' && | |
8952 | name[9] == 'n' && | |
8953 | name[10] == 't') | |
8954 | { /* getprotoent */ | |
8955 | return -KEY_getprotoent; | |
8956 | } | |
8957 | ||
8958 | goto unknown; | |
8959 | ||
8960 | default: | |
8961 | goto unknown; | |
8962 | } | |
8963 | ||
8964 | default: | |
8965 | goto unknown; | |
8966 | } | |
8967 | ||
8968 | case 's': | |
8969 | if (name[4] == 'o' && | |
8970 | name[5] == 'c' && | |
8971 | name[6] == 'k' && | |
8972 | name[7] == 'n' && | |
8973 | name[8] == 'a' && | |
8974 | name[9] == 'm' && | |
8975 | name[10] == 'e') | |
8976 | { /* getsockname */ | |
8977 | return -KEY_getsockname; | |
8978 | } | |
8979 | ||
8980 | goto unknown; | |
8981 | ||
8982 | default: | |
8983 | goto unknown; | |
8984 | } | |
8985 | } | |
8986 | ||
8987 | goto unknown; | |
8988 | ||
8989 | case 's': | |
8990 | if (name[1] == 'e' && | |
8991 | name[2] == 't' && | |
8992 | name[3] == 'p' && | |
8993 | name[4] == 'r') | |
8994 | { | |
8995 | switch (name[5]) | |
8996 | { | |
8997 | case 'i': | |
8998 | if (name[6] == 'o' && | |
8999 | name[7] == 'r' && | |
9000 | name[8] == 'i' && | |
9001 | name[9] == 't' && | |
9002 | name[10] == 'y') | |
9003 | { /* setpriority */ | |
9004 | return -KEY_setpriority; | |
9005 | } | |
9006 | ||
9007 | goto unknown; | |
9008 | ||
9009 | case 'o': | |
9010 | if (name[6] == 't' && | |
9011 | name[7] == 'o' && | |
9012 | name[8] == 'e' && | |
9013 | name[9] == 'n' && | |
9014 | name[10] == 't') | |
9015 | { /* setprotoent */ | |
9016 | return -KEY_setprotoent; | |
9017 | } | |
9018 | ||
9019 | goto unknown; | |
9020 | ||
9021 | default: | |
9022 | goto unknown; | |
9023 | } | |
9024 | } | |
9025 | ||
9026 | goto unknown; | |
9027 | ||
9028 | default: | |
9029 | goto unknown; | |
e2e1dd5a | 9030 | } |
4c3bbe0f MHM |
9031 | |
9032 | case 12: /* 2 tokens of length 12 */ | |
9033 | if (name[0] == 'g' && | |
9034 | name[1] == 'e' && | |
9035 | name[2] == 't' && | |
9036 | name[3] == 'n' && | |
9037 | name[4] == 'e' && | |
9038 | name[5] == 't' && | |
9039 | name[6] == 'b' && | |
9040 | name[7] == 'y') | |
9041 | { | |
9042 | switch (name[8]) | |
9043 | { | |
9044 | case 'a': | |
9045 | if (name[9] == 'd' && | |
9046 | name[10] == 'd' && | |
9047 | name[11] == 'r') | |
9048 | { /* getnetbyaddr */ | |
9049 | return -KEY_getnetbyaddr; | |
9050 | } | |
9051 | ||
9052 | goto unknown; | |
9053 | ||
9054 | case 'n': | |
9055 | if (name[9] == 'a' && | |
9056 | name[10] == 'm' && | |
9057 | name[11] == 'e') | |
9058 | { /* getnetbyname */ | |
9059 | return -KEY_getnetbyname; | |
9060 | } | |
9061 | ||
9062 | goto unknown; | |
9063 | ||
9064 | default: | |
9065 | goto unknown; | |
9066 | } | |
e2e1dd5a | 9067 | } |
4c3bbe0f MHM |
9068 | |
9069 | goto unknown; | |
9070 | ||
9071 | case 13: /* 4 tokens of length 13 */ | |
9072 | if (name[0] == 'g' && | |
9073 | name[1] == 'e' && | |
9074 | name[2] == 't') | |
9075 | { | |
9076 | switch (name[3]) | |
9077 | { | |
9078 | case 'h': | |
9079 | if (name[4] == 'o' && | |
9080 | name[5] == 's' && | |
9081 | name[6] == 't' && | |
9082 | name[7] == 'b' && | |
9083 | name[8] == 'y') | |
9084 | { | |
9085 | switch (name[9]) | |
9086 | { | |
9087 | case 'a': | |
9088 | if (name[10] == 'd' && | |
9089 | name[11] == 'd' && | |
9090 | name[12] == 'r') | |
9091 | { /* gethostbyaddr */ | |
9092 | return -KEY_gethostbyaddr; | |
9093 | } | |
9094 | ||
9095 | goto unknown; | |
9096 | ||
9097 | case 'n': | |
9098 | if (name[10] == 'a' && | |
9099 | name[11] == 'm' && | |
9100 | name[12] == 'e') | |
9101 | { /* gethostbyname */ | |
9102 | return -KEY_gethostbyname; | |
9103 | } | |
9104 | ||
9105 | goto unknown; | |
9106 | ||
9107 | default: | |
9108 | goto unknown; | |
9109 | } | |
9110 | } | |
9111 | ||
9112 | goto unknown; | |
9113 | ||
9114 | case 's': | |
9115 | if (name[4] == 'e' && | |
9116 | name[5] == 'r' && | |
9117 | name[6] == 'v' && | |
9118 | name[7] == 'b' && | |
9119 | name[8] == 'y') | |
9120 | { | |
9121 | switch (name[9]) | |
9122 | { | |
9123 | case 'n': | |
9124 | if (name[10] == 'a' && | |
9125 | name[11] == 'm' && | |
9126 | name[12] == 'e') | |
9127 | { /* getservbyname */ | |
9128 | return -KEY_getservbyname; | |
9129 | } | |
9130 | ||
9131 | goto unknown; | |
9132 | ||
9133 | case 'p': | |
9134 | if (name[10] == 'o' && | |
9135 | name[11] == 'r' && | |
9136 | name[12] == 't') | |
9137 | { /* getservbyport */ | |
9138 | return -KEY_getservbyport; | |
9139 | } | |
9140 | ||
9141 | goto unknown; | |
9142 | ||
9143 | default: | |
9144 | goto unknown; | |
9145 | } | |
9146 | } | |
9147 | ||
9148 | goto unknown; | |
9149 | ||
9150 | default: | |
9151 | goto unknown; | |
9152 | } | |
e2e1dd5a | 9153 | } |
4c3bbe0f MHM |
9154 | |
9155 | goto unknown; | |
9156 | ||
9157 | case 14: /* 1 tokens of length 14 */ | |
9158 | if (name[0] == 'g' && | |
9159 | name[1] == 'e' && | |
9160 | name[2] == 't' && | |
9161 | name[3] == 'p' && | |
9162 | name[4] == 'r' && | |
9163 | name[5] == 'o' && | |
9164 | name[6] == 't' && | |
9165 | name[7] == 'o' && | |
9166 | name[8] == 'b' && | |
9167 | name[9] == 'y' && | |
9168 | name[10] == 'n' && | |
9169 | name[11] == 'a' && | |
9170 | name[12] == 'm' && | |
9171 | name[13] == 'e') | |
9172 | { /* getprotobyname */ | |
9173 | return -KEY_getprotobyname; | |
9174 | } | |
9175 | ||
9176 | goto unknown; | |
9177 | ||
9178 | case 16: /* 1 tokens of length 16 */ | |
9179 | if (name[0] == 'g' && | |
9180 | name[1] == 'e' && | |
9181 | name[2] == 't' && | |
9182 | name[3] == 'p' && | |
9183 | name[4] == 'r' && | |
9184 | name[5] == 'o' && | |
9185 | name[6] == 't' && | |
9186 | name[7] == 'o' && | |
9187 | name[8] == 'b' && | |
9188 | name[9] == 'y' && | |
9189 | name[10] == 'n' && | |
9190 | name[11] == 'u' && | |
9191 | name[12] == 'm' && | |
9192 | name[13] == 'b' && | |
9193 | name[14] == 'e' && | |
9194 | name[15] == 'r') | |
9195 | { /* getprotobynumber */ | |
9196 | return -KEY_getprotobynumber; | |
9197 | } | |
9198 | ||
9199 | goto unknown; | |
9200 | ||
9201 | default: | |
9202 | goto unknown; | |
e2e1dd5a | 9203 | } |
4c3bbe0f MHM |
9204 | |
9205 | unknown: | |
e2e1dd5a | 9206 | return 0; |
a687059c LW |
9207 | } |
9208 | ||
76e3520e | 9209 | STATIC void |
f54cb97a | 9210 | S_checkcomma(pTHX_ register char *s, const char *name, const char *what) |
a687059c | 9211 | { |
97aff369 | 9212 | dVAR; |
f54cb97a | 9213 | const char *w; |
2f3197b3 | 9214 | |
d008e5eb | 9215 | if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */ |
d008e5eb GS |
9216 | if (ckWARN(WARN_SYNTAX)) { |
9217 | int level = 1; | |
9218 | for (w = s+2; *w && level; w++) { | |
9219 | if (*w == '(') | |
9220 | ++level; | |
9221 | else if (*w == ')') | |
9222 | --level; | |
9223 | } | |
9224 | if (*w) | |
9225 | for (; *w && isSPACE(*w); w++) ; | |
9226 | if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */ | |
9014280d | 9227 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
65cec589 | 9228 | "%s (...) interpreted as function",name); |
d008e5eb | 9229 | } |
2f3197b3 | 9230 | } |
3280af22 | 9231 | while (s < PL_bufend && isSPACE(*s)) |
2f3197b3 | 9232 | s++; |
a687059c LW |
9233 | if (*s == '(') |
9234 | s++; | |
3280af22 | 9235 | while (s < PL_bufend && isSPACE(*s)) |
a687059c | 9236 | s++; |
7e2040f0 | 9237 | if (isIDFIRST_lazy_if(s,UTF)) { |
2f3197b3 | 9238 | w = s++; |
7e2040f0 | 9239 | while (isALNUM_lazy_if(s,UTF)) |
a687059c | 9240 | s++; |
3280af22 | 9241 | while (s < PL_bufend && isSPACE(*s)) |
a687059c | 9242 | s++; |
e929a76b | 9243 | if (*s == ',') { |
0d863452 | 9244 | I32 kw; |
f54cb97a | 9245 | *s = '\0'; /* XXX If we didn't do this, we could const a lot of toke.c */ |
864dbfa3 | 9246 | kw = keyword(w, s - w) || get_cv(w, FALSE) != 0; |
e929a76b | 9247 | *s = ','; |
463ee0b2 | 9248 | if (kw) |
e929a76b | 9249 | return; |
cea2e8a9 | 9250 | Perl_croak(aTHX_ "No comma allowed after %s", what); |
463ee0b2 LW |
9251 | } |
9252 | } | |
9253 | } | |
9254 | ||
423cee85 JH |
9255 | /* Either returns sv, or mortalizes sv and returns a new SV*. |
9256 | Best used as sv=new_constant(..., sv, ...). | |
9257 | If s, pv are NULL, calls subroutine with one argument, | |
9258 | and type is used with error messages only. */ | |
9259 | ||
b3ac6de7 | 9260 | STATIC SV * |
7fc63493 | 9261 | S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv, |
9b0e499b | 9262 | const char *type) |
b3ac6de7 | 9263 | { |
27da23d5 | 9264 | dVAR; dSP; |
890ce7af | 9265 | HV * const table = GvHV(PL_hintgv); /* ^H */ |
b3ac6de7 | 9266 | SV *res; |
b3ac6de7 IZ |
9267 | SV **cvp; |
9268 | SV *cv, *typesv; | |
89e33a05 | 9269 | const char *why1 = "", *why2 = "", *why3 = ""; |
4e553d73 | 9270 | |
f0af216f | 9271 | if (!table || !(PL_hints & HINT_LOCALIZE_HH)) { |
423cee85 JH |
9272 | SV *msg; |
9273 | ||
f0af216f | 9274 | why2 = strEQ(key,"charnames") |
41ab332f | 9275 | ? "(possibly a missing \"use charnames ...\")" |
f0af216f | 9276 | : ""; |
4e553d73 | 9277 | msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s", |
41ab332f JH |
9278 | (type ? type: "undef"), why2); |
9279 | ||
9280 | /* This is convoluted and evil ("goto considered harmful") | |
9281 | * but I do not understand the intricacies of all the different | |
9282 | * failure modes of %^H in here. The goal here is to make | |
9283 | * the most probable error message user-friendly. --jhi */ | |
9284 | ||
9285 | goto msgdone; | |
9286 | ||
423cee85 | 9287 | report: |
4e553d73 | 9288 | msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s", |
f0af216f | 9289 | (type ? type: "undef"), why1, why2, why3); |
41ab332f | 9290 | msgdone: |
95a20fc0 | 9291 | yyerror(SvPVX_const(msg)); |
423cee85 JH |
9292 | SvREFCNT_dec(msg); |
9293 | return sv; | |
9294 | } | |
b3ac6de7 IZ |
9295 | cvp = hv_fetch(table, key, strlen(key), FALSE); |
9296 | if (!cvp || !SvOK(*cvp)) { | |
423cee85 JH |
9297 | why1 = "$^H{"; |
9298 | why2 = key; | |
f0af216f | 9299 | why3 = "} is not defined"; |
423cee85 | 9300 | goto report; |
b3ac6de7 IZ |
9301 | } |
9302 | sv_2mortal(sv); /* Parent created it permanently */ | |
9303 | cv = *cvp; | |
423cee85 JH |
9304 | if (!pv && s) |
9305 | pv = sv_2mortal(newSVpvn(s, len)); | |
9306 | if (type && pv) | |
9307 | typesv = sv_2mortal(newSVpv(type, 0)); | |
b3ac6de7 | 9308 | else |
423cee85 | 9309 | typesv = &PL_sv_undef; |
4e553d73 | 9310 | |
e788e7d3 | 9311 | PUSHSTACKi(PERLSI_OVERLOAD); |
423cee85 JH |
9312 | ENTER ; |
9313 | SAVETMPS; | |
4e553d73 | 9314 | |
423cee85 | 9315 | PUSHMARK(SP) ; |
a5845cb7 | 9316 | EXTEND(sp, 3); |
423cee85 JH |
9317 | if (pv) |
9318 | PUSHs(pv); | |
b3ac6de7 | 9319 | PUSHs(sv); |
423cee85 JH |
9320 | if (pv) |
9321 | PUSHs(typesv); | |
b3ac6de7 | 9322 | PUTBACK; |
423cee85 | 9323 | call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL)); |
4e553d73 | 9324 | |
423cee85 | 9325 | SPAGAIN ; |
4e553d73 | 9326 | |
423cee85 | 9327 | /* Check the eval first */ |
9b0e499b | 9328 | if (!PL_in_eval && SvTRUE(ERRSV)) { |
396482e1 | 9329 | sv_catpvs(ERRSV, "Propagated"); |
8b6b16e7 | 9330 | yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */ |
e1f15930 | 9331 | (void)POPs; |
423cee85 JH |
9332 | res = SvREFCNT_inc(sv); |
9333 | } | |
9334 | else { | |
9335 | res = POPs; | |
e1f15930 | 9336 | (void)SvREFCNT_inc(res); |
423cee85 | 9337 | } |
4e553d73 | 9338 | |
423cee85 JH |
9339 | PUTBACK ; |
9340 | FREETMPS ; | |
9341 | LEAVE ; | |
b3ac6de7 | 9342 | POPSTACK; |
4e553d73 | 9343 | |
b3ac6de7 | 9344 | if (!SvOK(res)) { |
423cee85 JH |
9345 | why1 = "Call to &{$^H{"; |
9346 | why2 = key; | |
f0af216f | 9347 | why3 = "}} did not return a defined value"; |
423cee85 JH |
9348 | sv = res; |
9349 | goto report; | |
9b0e499b | 9350 | } |
423cee85 | 9351 | |
9b0e499b | 9352 | return res; |
b3ac6de7 | 9353 | } |
4e553d73 | 9354 | |
d0a148a6 NC |
9355 | /* Returns a NUL terminated string, with the length of the string written to |
9356 | *slp | |
9357 | */ | |
76e3520e | 9358 | STATIC char * |
cea2e8a9 | 9359 | S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp) |
463ee0b2 | 9360 | { |
97aff369 | 9361 | dVAR; |
463ee0b2 | 9362 | register char *d = dest; |
890ce7af | 9363 | register char * const e = d + destlen - 3; /* two-character token, ending NUL */ |
463ee0b2 | 9364 | for (;;) { |
8903cb82 | 9365 | if (d >= e) |
cea2e8a9 | 9366 | Perl_croak(aTHX_ ident_too_long); |
834a4ddd | 9367 | if (isALNUM(*s)) /* UTF handled below */ |
463ee0b2 | 9368 | *d++ = *s++; |
7e2040f0 | 9369 | else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) { |
463ee0b2 LW |
9370 | *d++ = ':'; |
9371 | *d++ = ':'; | |
9372 | s++; | |
9373 | } | |
c3e0f903 | 9374 | else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') { |
463ee0b2 LW |
9375 | *d++ = *s++; |
9376 | *d++ = *s++; | |
9377 | } | |
fd400ab9 | 9378 | else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
a0ed51b3 | 9379 | char *t = s + UTF8SKIP(s); |
fd400ab9 | 9380 | while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
a0ed51b3 LW |
9381 | t += UTF8SKIP(t); |
9382 | if (d + (t - s) > e) | |
cea2e8a9 | 9383 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 LW |
9384 | Copy(s, d, t - s, char); |
9385 | d += t - s; | |
9386 | s = t; | |
9387 | } | |
463ee0b2 LW |
9388 | else { |
9389 | *d = '\0'; | |
9390 | *slp = d - dest; | |
9391 | return s; | |
e929a76b | 9392 | } |
378cc40b LW |
9393 | } |
9394 | } | |
9395 | ||
76e3520e | 9396 | STATIC char * |
f54cb97a | 9397 | S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni) |
378cc40b | 9398 | { |
97aff369 | 9399 | dVAR; |
6136c704 | 9400 | char *bracket = NULL; |
748a9306 | 9401 | char funny = *s++; |
6136c704 AL |
9402 | register char *d = dest; |
9403 | register char * const e = d + destlen + 3; /* two-character token, ending NUL */ | |
378cc40b | 9404 | |
a0d0e21e LW |
9405 | if (isSPACE(*s)) |
9406 | s = skipspace(s); | |
de3bb511 | 9407 | if (isDIGIT(*s)) { |
8903cb82 | 9408 | while (isDIGIT(*s)) { |
9409 | if (d >= e) | |
cea2e8a9 | 9410 | Perl_croak(aTHX_ ident_too_long); |
378cc40b | 9411 | *d++ = *s++; |
8903cb82 | 9412 | } |
378cc40b LW |
9413 | } |
9414 | else { | |
463ee0b2 | 9415 | for (;;) { |
8903cb82 | 9416 | if (d >= e) |
cea2e8a9 | 9417 | Perl_croak(aTHX_ ident_too_long); |
834a4ddd | 9418 | if (isALNUM(*s)) /* UTF handled below */ |
463ee0b2 | 9419 | *d++ = *s++; |
7e2040f0 | 9420 | else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) { |
463ee0b2 LW |
9421 | *d++ = ':'; |
9422 | *d++ = ':'; | |
9423 | s++; | |
9424 | } | |
a0d0e21e | 9425 | else if (*s == ':' && s[1] == ':') { |
463ee0b2 LW |
9426 | *d++ = *s++; |
9427 | *d++ = *s++; | |
9428 | } | |
fd400ab9 | 9429 | else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
a0ed51b3 | 9430 | char *t = s + UTF8SKIP(s); |
fd400ab9 | 9431 | while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
a0ed51b3 LW |
9432 | t += UTF8SKIP(t); |
9433 | if (d + (t - s) > e) | |
cea2e8a9 | 9434 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 LW |
9435 | Copy(s, d, t - s, char); |
9436 | d += t - s; | |
9437 | s = t; | |
9438 | } | |
463ee0b2 LW |
9439 | else |
9440 | break; | |
9441 | } | |
378cc40b LW |
9442 | } |
9443 | *d = '\0'; | |
9444 | d = dest; | |
79072805 | 9445 | if (*d) { |
3280af22 NIS |
9446 | if (PL_lex_state != LEX_NORMAL) |
9447 | PL_lex_state = LEX_INTERPENDMAYBE; | |
79072805 | 9448 | return s; |
378cc40b | 9449 | } |
748a9306 | 9450 | if (*s == '$' && s[1] && |
3792a11b | 9451 | (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) ) |
5cd24f17 | 9452 | { |
4810e5ec | 9453 | return s; |
5cd24f17 | 9454 | } |
79072805 LW |
9455 | if (*s == '{') { |
9456 | bracket = s; | |
9457 | s++; | |
9458 | } | |
9459 | else if (ck_uni) | |
9460 | check_uni(); | |
93a17b20 | 9461 | if (s < send) |
79072805 LW |
9462 | *d = *s++; |
9463 | d[1] = '\0'; | |
2b92dfce | 9464 | if (*d == '^' && *s && isCONTROLVAR(*s)) { |
bbce6d69 | 9465 | *d = toCTRL(*s); |
9466 | s++; | |
de3bb511 | 9467 | } |
79072805 | 9468 | if (bracket) { |
748a9306 | 9469 | if (isSPACE(s[-1])) { |
fa83b5b6 | 9470 | while (s < send) { |
f54cb97a | 9471 | const char ch = *s++; |
bf4acbe4 | 9472 | if (!SPACE_OR_TAB(ch)) { |
fa83b5b6 | 9473 | *d = ch; |
9474 | break; | |
9475 | } | |
9476 | } | |
748a9306 | 9477 | } |
7e2040f0 | 9478 | if (isIDFIRST_lazy_if(d,UTF)) { |
79072805 | 9479 | d++; |
a0ed51b3 | 9480 | if (UTF) { |
6136c704 AL |
9481 | char *end = s; |
9482 | while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') { | |
9483 | end += UTF8SKIP(end); | |
9484 | while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end)) | |
9485 | end += UTF8SKIP(end); | |
a0ed51b3 | 9486 | } |
6136c704 AL |
9487 | Copy(s, d, end - s, char); |
9488 | d += end - s; | |
9489 | s = end; | |
a0ed51b3 LW |
9490 | } |
9491 | else { | |
2b92dfce | 9492 | while ((isALNUM(*s) || *s == ':') && d < e) |
a0ed51b3 | 9493 | *d++ = *s++; |
2b92dfce | 9494 | if (d >= e) |
cea2e8a9 | 9495 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 | 9496 | } |
79072805 | 9497 | *d = '\0'; |
bf4acbe4 | 9498 | while (s < send && SPACE_OR_TAB(*s)) s++; |
ff68c719 | 9499 | if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) { |
599cee73 | 9500 | if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) { |
dff6d3cd | 9501 | const char *brack = *s == '[' ? "[...]" : "{...}"; |
9014280d | 9502 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
599cee73 | 9503 | "Ambiguous use of %c{%s%s} resolved to %c%s%s", |
748a9306 LW |
9504 | funny, dest, brack, funny, dest, brack); |
9505 | } | |
79072805 | 9506 | bracket++; |
a0be28da | 9507 | PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK); |
79072805 LW |
9508 | return s; |
9509 | } | |
4e553d73 NIS |
9510 | } |
9511 | /* Handle extended ${^Foo} variables | |
2b92dfce GS |
9512 | * 1999-02-27 mjd-perl-patch@plover.com */ |
9513 | else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */ | |
9514 | && isALNUM(*s)) | |
9515 | { | |
9516 | d++; | |
9517 | while (isALNUM(*s) && d < e) { | |
9518 | *d++ = *s++; | |
9519 | } | |
9520 | if (d >= e) | |
cea2e8a9 | 9521 | Perl_croak(aTHX_ ident_too_long); |
2b92dfce | 9522 | *d = '\0'; |
79072805 LW |
9523 | } |
9524 | if (*s == '}') { | |
9525 | s++; | |
7df0d042 | 9526 | if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) { |
3280af22 | 9527 | PL_lex_state = LEX_INTERPEND; |
7df0d042 AE |
9528 | PL_expect = XREF; |
9529 | } | |
748a9306 LW |
9530 | if (funny == '#') |
9531 | funny = '@'; | |
d008e5eb | 9532 | if (PL_lex_state == LEX_NORMAL) { |
d008e5eb | 9533 | if (ckWARN(WARN_AMBIGUOUS) && |
864dbfa3 | 9534 | (keyword(dest, d - dest) || get_cv(dest, FALSE))) |
d008e5eb | 9535 | { |
9014280d | 9536 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
d008e5eb GS |
9537 | "Ambiguous use of %c{%s} resolved to %c%s", |
9538 | funny, dest, funny, dest); | |
9539 | } | |
9540 | } | |
79072805 LW |
9541 | } |
9542 | else { | |
9543 | s = bracket; /* let the parser handle it */ | |
93a17b20 | 9544 | *dest = '\0'; |
79072805 LW |
9545 | } |
9546 | } | |
3280af22 NIS |
9547 | else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s)) |
9548 | PL_lex_state = LEX_INTERPEND; | |
378cc40b LW |
9549 | return s; |
9550 | } | |
9551 | ||
cea2e8a9 | 9552 | void |
2b36a5a0 | 9553 | Perl_pmflag(pTHX_ U32* pmfl, int ch) |
a0d0e21e | 9554 | { |
96a5add6 | 9555 | PERL_UNUSED_CONTEXT; |
bbce6d69 | 9556 | if (ch == 'i') |
a0d0e21e | 9557 | *pmfl |= PMf_FOLD; |
a0d0e21e LW |
9558 | else if (ch == 'g') |
9559 | *pmfl |= PMf_GLOBAL; | |
c90c0ff4 | 9560 | else if (ch == 'c') |
9561 | *pmfl |= PMf_CONTINUE; | |
a0d0e21e LW |
9562 | else if (ch == 'o') |
9563 | *pmfl |= PMf_KEEP; | |
9564 | else if (ch == 'm') | |
9565 | *pmfl |= PMf_MULTILINE; | |
9566 | else if (ch == 's') | |
9567 | *pmfl |= PMf_SINGLELINE; | |
9568 | else if (ch == 'x') | |
9569 | *pmfl |= PMf_EXTENDED; | |
9570 | } | |
378cc40b | 9571 | |
76e3520e | 9572 | STATIC char * |
cea2e8a9 | 9573 | S_scan_pat(pTHX_ char *start, I32 type) |
378cc40b | 9574 | { |
97aff369 | 9575 | dVAR; |
79072805 | 9576 | PMOP *pm; |
f54cb97a | 9577 | char *s = scan_str(start,FALSE,FALSE); |
6136c704 | 9578 | const char * const valid_flags = (type == OP_QR) ? "iomsx" : "iogcmsx"; |
378cc40b | 9579 | |
25c09cbf | 9580 | if (!s) { |
6136c704 | 9581 | const char * const delimiter = skipspace(start); |
25c09cbf SF |
9582 | Perl_croak(aTHX_ *delimiter == '?' |
9583 | ? "Search pattern not terminated or ternary operator parsed as search pattern" | |
9584 | : "Search pattern not terminated" ); | |
9585 | } | |
bbce6d69 | 9586 | |
8782bef2 | 9587 | pm = (PMOP*)newPMOP(type, 0); |
3280af22 | 9588 | if (PL_multi_open == '?') |
79072805 | 9589 | pm->op_pmflags |= PMf_ONCE; |
6136c704 AL |
9590 | while (*s && strchr(valid_flags, *s)) |
9591 | pmflag(&pm->op_pmflags,*s++); | |
4ac733c9 | 9592 | /* issue a warning if /c is specified,but /g is not */ |
041457d9 DM |
9593 | if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL) |
9594 | && ckWARN(WARN_REGEXP)) | |
4ac733c9 | 9595 | { |
0bd48802 | 9596 | Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" ); |
4ac733c9 MJD |
9597 | } |
9598 | ||
4633a7c4 | 9599 | pm->op_pmpermflags = pm->op_pmflags; |
bbce6d69 | 9600 | |
3280af22 | 9601 | PL_lex_op = (OP*)pm; |
79072805 | 9602 | yylval.ival = OP_MATCH; |
378cc40b LW |
9603 | return s; |
9604 | } | |
9605 | ||
76e3520e | 9606 | STATIC char * |
cea2e8a9 | 9607 | S_scan_subst(pTHX_ char *start) |
79072805 | 9608 | { |
27da23d5 | 9609 | dVAR; |
a0d0e21e | 9610 | register char *s; |
79072805 | 9611 | register PMOP *pm; |
4fdae800 | 9612 | I32 first_start; |
79072805 LW |
9613 | I32 es = 0; |
9614 | ||
79072805 LW |
9615 | yylval.ival = OP_NULL; |
9616 | ||
09bef843 | 9617 | s = scan_str(start,FALSE,FALSE); |
79072805 | 9618 | |
37fd879b | 9619 | if (!s) |
cea2e8a9 | 9620 | Perl_croak(aTHX_ "Substitution pattern not terminated"); |
79072805 | 9621 | |
3280af22 | 9622 | if (s[-1] == PL_multi_open) |
79072805 LW |
9623 | s--; |
9624 | ||
3280af22 | 9625 | first_start = PL_multi_start; |
09bef843 | 9626 | s = scan_str(s,FALSE,FALSE); |
79072805 | 9627 | if (!s) { |
37fd879b | 9628 | if (PL_lex_stuff) { |
3280af22 | 9629 | SvREFCNT_dec(PL_lex_stuff); |
a0714e2c | 9630 | PL_lex_stuff = NULL; |
37fd879b | 9631 | } |
cea2e8a9 | 9632 | Perl_croak(aTHX_ "Substitution replacement not terminated"); |
a687059c | 9633 | } |
3280af22 | 9634 | PL_multi_start = first_start; /* so whole substitution is taken together */ |
2f3197b3 | 9635 | |
79072805 | 9636 | pm = (PMOP*)newPMOP(OP_SUBST, 0); |
48c036b1 | 9637 | while (*s) { |
a687059c LW |
9638 | if (*s == 'e') { |
9639 | s++; | |
2f3197b3 | 9640 | es++; |
a687059c | 9641 | } |
b3eb6a9b | 9642 | else if (strchr("iogcmsx", *s)) |
a0d0e21e | 9643 | pmflag(&pm->op_pmflags,*s++); |
48c036b1 GS |
9644 | else |
9645 | break; | |
378cc40b | 9646 | } |
79072805 | 9647 | |
0bd48802 AL |
9648 | if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) { |
9649 | Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" ); | |
4ac733c9 MJD |
9650 | } |
9651 | ||
79072805 | 9652 | if (es) { |
6136c704 AL |
9653 | SV * const repl = newSVpvs(""); |
9654 | ||
0244c3a4 GS |
9655 | PL_sublex_info.super_bufptr = s; |
9656 | PL_sublex_info.super_bufend = PL_bufend; | |
9657 | PL_multi_end = 0; | |
79072805 | 9658 | pm->op_pmflags |= PMf_EVAL; |
463ee0b2 | 9659 | while (es-- > 0) |
a0d0e21e | 9660 | sv_catpv(repl, es ? "eval " : "do "); |
396482e1 | 9661 | sv_catpvs(repl, "{ "); |
3280af22 | 9662 | sv_catsv(repl, PL_lex_repl); |
396482e1 | 9663 | sv_catpvs(repl, " }"); |
25da4f38 | 9664 | SvEVALED_on(repl); |
3280af22 NIS |
9665 | SvREFCNT_dec(PL_lex_repl); |
9666 | PL_lex_repl = repl; | |
378cc40b | 9667 | } |
79072805 | 9668 | |
4633a7c4 | 9669 | pm->op_pmpermflags = pm->op_pmflags; |
3280af22 | 9670 | PL_lex_op = (OP*)pm; |
79072805 | 9671 | yylval.ival = OP_SUBST; |
378cc40b LW |
9672 | return s; |
9673 | } | |
9674 | ||
76e3520e | 9675 | STATIC char * |
cea2e8a9 | 9676 | S_scan_trans(pTHX_ char *start) |
378cc40b | 9677 | { |
97aff369 | 9678 | dVAR; |
a0d0e21e | 9679 | register char* s; |
11343788 | 9680 | OP *o; |
79072805 LW |
9681 | short *tbl; |
9682 | I32 squash; | |
a0ed51b3 | 9683 | I32 del; |
79072805 LW |
9684 | I32 complement; |
9685 | ||
9686 | yylval.ival = OP_NULL; | |
9687 | ||
09bef843 | 9688 | s = scan_str(start,FALSE,FALSE); |
37fd879b | 9689 | if (!s) |
cea2e8a9 | 9690 | Perl_croak(aTHX_ "Transliteration pattern not terminated"); |
3280af22 | 9691 | if (s[-1] == PL_multi_open) |
2f3197b3 LW |
9692 | s--; |
9693 | ||
09bef843 | 9694 | s = scan_str(s,FALSE,FALSE); |
79072805 | 9695 | if (!s) { |
37fd879b | 9696 | if (PL_lex_stuff) { |
3280af22 | 9697 | SvREFCNT_dec(PL_lex_stuff); |
a0714e2c | 9698 | PL_lex_stuff = NULL; |
37fd879b | 9699 | } |
cea2e8a9 | 9700 | Perl_croak(aTHX_ "Transliteration replacement not terminated"); |
a687059c | 9701 | } |
79072805 | 9702 | |
a0ed51b3 | 9703 | complement = del = squash = 0; |
7a1e2023 NC |
9704 | while (1) { |
9705 | switch (*s) { | |
9706 | case 'c': | |
79072805 | 9707 | complement = OPpTRANS_COMPLEMENT; |
7a1e2023 NC |
9708 | break; |
9709 | case 'd': | |
a0ed51b3 | 9710 | del = OPpTRANS_DELETE; |
7a1e2023 NC |
9711 | break; |
9712 | case 's': | |
79072805 | 9713 | squash = OPpTRANS_SQUASH; |
7a1e2023 NC |
9714 | break; |
9715 | default: | |
9716 | goto no_more; | |
9717 | } | |
395c3793 LW |
9718 | s++; |
9719 | } | |
7a1e2023 | 9720 | no_more: |
8973db79 | 9721 | |
a02a5408 | 9722 | Newx(tbl, complement&&!del?258:256, short); |
8973db79 | 9723 | o = newPVOP(OP_TRANS, 0, (char*)tbl); |
59f00321 RGS |
9724 | o->op_private &= ~OPpTRANS_ALL; |
9725 | o->op_private |= del|squash|complement| | |
7948272d NIS |
9726 | (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)| |
9727 | (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0); | |
79072805 | 9728 | |
3280af22 | 9729 | PL_lex_op = o; |
79072805 LW |
9730 | yylval.ival = OP_TRANS; |
9731 | return s; | |
9732 | } | |
9733 | ||
76e3520e | 9734 | STATIC char * |
cea2e8a9 | 9735 | S_scan_heredoc(pTHX_ register char *s) |
79072805 | 9736 | { |
97aff369 | 9737 | dVAR; |
79072805 LW |
9738 | SV *herewas; |
9739 | I32 op_type = OP_SCALAR; | |
9740 | I32 len; | |
9741 | SV *tmpstr; | |
9742 | char term; | |
73d840c0 | 9743 | const char *found_newline; |
79072805 | 9744 | register char *d; |
fc36a67e | 9745 | register char *e; |
4633a7c4 | 9746 | char *peek; |
f54cb97a | 9747 | const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR)); |
79072805 LW |
9748 | |
9749 | s += 2; | |
3280af22 NIS |
9750 | d = PL_tokenbuf; |
9751 | e = PL_tokenbuf + sizeof PL_tokenbuf - 1; | |
fd2d0953 | 9752 | if (!outer) |
79072805 | 9753 | *d++ = '\n'; |
bf4acbe4 | 9754 | for (peek = s; SPACE_OR_TAB(*peek); peek++) ; |
3792a11b | 9755 | if (*peek == '`' || *peek == '\'' || *peek =='"') { |
4633a7c4 | 9756 | s = peek; |
79072805 | 9757 | term = *s++; |
3280af22 | 9758 | s = delimcpy(d, e, s, PL_bufend, term, &len); |
fc36a67e | 9759 | d += len; |
3280af22 | 9760 | if (s < PL_bufend) |
79072805 | 9761 | s++; |
79072805 LW |
9762 | } |
9763 | else { | |
9764 | if (*s == '\\') | |
9765 | s++, term = '\''; | |
9766 | else | |
9767 | term = '"'; | |
7e2040f0 | 9768 | if (!isALNUM_lazy_if(s,UTF)) |
12bcd1a6 | 9769 | deprecate_old("bare << to mean <<\"\""); |
7e2040f0 | 9770 | for (; isALNUM_lazy_if(s,UTF); s++) { |
fc36a67e | 9771 | if (d < e) |
9772 | *d++ = *s; | |
9773 | } | |
9774 | } | |
3280af22 | 9775 | if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1) |
cea2e8a9 | 9776 | Perl_croak(aTHX_ "Delimiter for here document is too long"); |
79072805 LW |
9777 | *d++ = '\n'; |
9778 | *d = '\0'; | |
3280af22 | 9779 | len = d - PL_tokenbuf; |
6a27c188 | 9780 | #ifndef PERL_STRICT_CR |
f63a84b2 LW |
9781 | d = strchr(s, '\r'); |
9782 | if (d) { | |
b464bac0 | 9783 | char * const olds = s; |
f63a84b2 | 9784 | s = d; |
3280af22 | 9785 | while (s < PL_bufend) { |
f63a84b2 LW |
9786 | if (*s == '\r') { |
9787 | *d++ = '\n'; | |
9788 | if (*++s == '\n') | |
9789 | s++; | |
9790 | } | |
9791 | else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */ | |
9792 | *d++ = *s++; | |
9793 | s++; | |
9794 | } | |
9795 | else | |
9796 | *d++ = *s++; | |
9797 | } | |
9798 | *d = '\0'; | |
3280af22 | 9799 | PL_bufend = d; |
95a20fc0 | 9800 | SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr)); |
f63a84b2 LW |
9801 | s = olds; |
9802 | } | |
9803 | #endif | |
e81b0615 | 9804 | if ( outer || !(found_newline = memchr(s, '\n', PL_bufend - s)) ) { |
73d840c0 AL |
9805 | herewas = newSVpvn(s,PL_bufend-s); |
9806 | } | |
9807 | else { | |
9808 | s--; | |
9809 | herewas = newSVpvn(s,found_newline-s); | |
9810 | } | |
79072805 | 9811 | s += SvCUR(herewas); |
748a9306 | 9812 | |
561b68a9 | 9813 | tmpstr = newSV(79); |
748a9306 LW |
9814 | sv_upgrade(tmpstr, SVt_PVIV); |
9815 | if (term == '\'') { | |
79072805 | 9816 | op_type = OP_CONST; |
45977657 | 9817 | SvIV_set(tmpstr, -1); |
748a9306 LW |
9818 | } |
9819 | else if (term == '`') { | |
79072805 | 9820 | op_type = OP_BACKTICK; |
45977657 | 9821 | SvIV_set(tmpstr, '\\'); |
748a9306 | 9822 | } |
79072805 LW |
9823 | |
9824 | CLINE; | |
57843af0 | 9825 | PL_multi_start = CopLINE(PL_curcop); |
3280af22 NIS |
9826 | PL_multi_open = PL_multi_close = '<'; |
9827 | term = *PL_tokenbuf; | |
0244c3a4 | 9828 | if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) { |
6136c704 AL |
9829 | char * const bufptr = PL_sublex_info.super_bufptr; |
9830 | char * const bufend = PL_sublex_info.super_bufend; | |
b464bac0 | 9831 | char * const olds = s - SvCUR(herewas); |
0244c3a4 GS |
9832 | s = strchr(bufptr, '\n'); |
9833 | if (!s) | |
9834 | s = bufend; | |
9835 | d = s; | |
9836 | while (s < bufend && | |
9837 | (*s != term || memNE(s,PL_tokenbuf,len)) ) { | |
9838 | if (*s++ == '\n') | |
57843af0 | 9839 | CopLINE_inc(PL_curcop); |
0244c3a4 GS |
9840 | } |
9841 | if (s >= bufend) { | |
eb160463 | 9842 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
0244c3a4 GS |
9843 | missingterm(PL_tokenbuf); |
9844 | } | |
9845 | sv_setpvn(herewas,bufptr,d-bufptr+1); | |
9846 | sv_setpvn(tmpstr,d+1,s-d); | |
9847 | s += len - 1; | |
9848 | sv_catpvn(herewas,s,bufend-s); | |
95a20fc0 | 9849 | Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char); |
0244c3a4 GS |
9850 | |
9851 | s = olds; | |
9852 | goto retval; | |
9853 | } | |
9854 | else if (!outer) { | |
79072805 | 9855 | d = s; |
3280af22 NIS |
9856 | while (s < PL_bufend && |
9857 | (*s != term || memNE(s,PL_tokenbuf,len)) ) { | |
79072805 | 9858 | if (*s++ == '\n') |
57843af0 | 9859 | CopLINE_inc(PL_curcop); |
79072805 | 9860 | } |
3280af22 | 9861 | if (s >= PL_bufend) { |
eb160463 | 9862 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
3280af22 | 9863 | missingterm(PL_tokenbuf); |
79072805 LW |
9864 | } |
9865 | sv_setpvn(tmpstr,d+1,s-d); | |
9866 | s += len - 1; | |
57843af0 | 9867 | CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */ |
49d8d3a1 | 9868 | |
3280af22 NIS |
9869 | sv_catpvn(herewas,s,PL_bufend-s); |
9870 | sv_setsv(PL_linestr,herewas); | |
9871 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr); | |
9872 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
bd61b366 | 9873 | PL_last_lop = PL_last_uni = NULL; |
79072805 LW |
9874 | } |
9875 | else | |
9876 | sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */ | |
3280af22 | 9877 | while (s >= PL_bufend) { /* multiple line string? */ |
fd2d0953 | 9878 | if (!outer || |
3280af22 | 9879 | !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { |
eb160463 | 9880 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
3280af22 | 9881 | missingterm(PL_tokenbuf); |
79072805 | 9882 | } |
57843af0 | 9883 | CopLINE_inc(PL_curcop); |
3280af22 | 9884 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
bd61b366 | 9885 | PL_last_lop = PL_last_uni = NULL; |
6a27c188 | 9886 | #ifndef PERL_STRICT_CR |
3280af22 | 9887 | if (PL_bufend - PL_linestart >= 2) { |
a1529941 NIS |
9888 | if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') || |
9889 | (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r')) | |
c6f14548 | 9890 | { |
3280af22 NIS |
9891 | PL_bufend[-2] = '\n'; |
9892 | PL_bufend--; | |
95a20fc0 | 9893 | SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr)); |
f63a84b2 | 9894 | } |
3280af22 NIS |
9895 | else if (PL_bufend[-1] == '\r') |
9896 | PL_bufend[-1] = '\n'; | |
f63a84b2 | 9897 | } |
3280af22 NIS |
9898 | else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r') |
9899 | PL_bufend[-1] = '\n'; | |
f63a84b2 | 9900 | #endif |
3280af22 | 9901 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
561b68a9 | 9902 | SV * const sv = newSV(0); |
79072805 | 9903 | |
93a17b20 | 9904 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 9905 | sv_setsv(sv,PL_linestr); |
0ac0412a | 9906 | (void)SvIOK_on(sv); |
45977657 | 9907 | SvIV_set(sv, 0); |
36c7798d | 9908 | av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop),sv); |
79072805 | 9909 | } |
3280af22 | 9910 | if (*s == term && memEQ(s,PL_tokenbuf,len)) { |
95a20fc0 | 9911 | STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr); |
1de9afcd | 9912 | *(SvPVX(PL_linestr) + off ) = ' '; |
3280af22 NIS |
9913 | sv_catsv(PL_linestr,herewas); |
9914 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
1de9afcd | 9915 | s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */ |
79072805 LW |
9916 | } |
9917 | else { | |
3280af22 NIS |
9918 | s = PL_bufend; |
9919 | sv_catsv(tmpstr,PL_linestr); | |
395c3793 LW |
9920 | } |
9921 | } | |
79072805 | 9922 | s++; |
0244c3a4 | 9923 | retval: |
57843af0 | 9924 | PL_multi_end = CopLINE(PL_curcop); |
79072805 | 9925 | if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) { |
1da4ca5f | 9926 | SvPV_shrink_to_cur(tmpstr); |
79072805 | 9927 | } |
8990e307 | 9928 | SvREFCNT_dec(herewas); |
2f31ce75 | 9929 | if (!IN_BYTES) { |
95a20fc0 | 9930 | if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr))) |
2f31ce75 JH |
9931 | SvUTF8_on(tmpstr); |
9932 | else if (PL_encoding) | |
9933 | sv_recode_to_utf8(tmpstr, PL_encoding); | |
9934 | } | |
3280af22 | 9935 | PL_lex_stuff = tmpstr; |
79072805 LW |
9936 | yylval.ival = op_type; |
9937 | return s; | |
9938 | } | |
9939 | ||
02aa26ce NT |
9940 | /* scan_inputsymbol |
9941 | takes: current position in input buffer | |
9942 | returns: new position in input buffer | |
9943 | side-effects: yylval and lex_op are set. | |
9944 | ||
9945 | This code handles: | |
9946 | ||
9947 | <> read from ARGV | |
9948 | <FH> read from filehandle | |
9949 | <pkg::FH> read from package qualified filehandle | |
9950 | <pkg'FH> read from package qualified filehandle | |
9951 | <$fh> read from filehandle in $fh | |
9952 | <*.h> filename glob | |
9953 | ||
9954 | */ | |
9955 | ||
76e3520e | 9956 | STATIC char * |
cea2e8a9 | 9957 | S_scan_inputsymbol(pTHX_ char *start) |
79072805 | 9958 | { |
97aff369 | 9959 | dVAR; |
02aa26ce | 9960 | register char *s = start; /* current position in buffer */ |
1b420867 | 9961 | char *end; |
79072805 LW |
9962 | I32 len; |
9963 | ||
6136c704 AL |
9964 | char *d = PL_tokenbuf; /* start of temp holding space */ |
9965 | const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */ | |
9966 | ||
1b420867 GS |
9967 | end = strchr(s, '\n'); |
9968 | if (!end) | |
9969 | end = PL_bufend; | |
9970 | s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */ | |
02aa26ce NT |
9971 | |
9972 | /* die if we didn't have space for the contents of the <>, | |
1b420867 | 9973 | or if it didn't end, or if we see a newline |
02aa26ce NT |
9974 | */ |
9975 | ||
3280af22 | 9976 | if (len >= sizeof PL_tokenbuf) |
cea2e8a9 | 9977 | Perl_croak(aTHX_ "Excessively long <> operator"); |
1b420867 | 9978 | if (s >= end) |
cea2e8a9 | 9979 | Perl_croak(aTHX_ "Unterminated <> operator"); |
02aa26ce | 9980 | |
fc36a67e | 9981 | s++; |
02aa26ce NT |
9982 | |
9983 | /* check for <$fh> | |
9984 | Remember, only scalar variables are interpreted as filehandles by | |
9985 | this code. Anything more complex (e.g., <$fh{$num}>) will be | |
9986 | treated as a glob() call. | |
9987 | This code makes use of the fact that except for the $ at the front, | |
9988 | a scalar variable and a filehandle look the same. | |
9989 | */ | |
4633a7c4 | 9990 | if (*d == '$' && d[1]) d++; |
02aa26ce NT |
9991 | |
9992 | /* allow <Pkg'VALUE> or <Pkg::VALUE> */ | |
7e2040f0 | 9993 | while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':')) |
79072805 | 9994 | d++; |
02aa26ce NT |
9995 | |
9996 | /* If we've tried to read what we allow filehandles to look like, and | |
9997 | there's still text left, then it must be a glob() and not a getline. | |
9998 | Use scan_str to pull out the stuff between the <> and treat it | |
9999 | as nothing more than a string. | |
10000 | */ | |
10001 | ||
3280af22 | 10002 | if (d - PL_tokenbuf != len) { |
79072805 LW |
10003 | yylval.ival = OP_GLOB; |
10004 | set_csh(); | |
09bef843 | 10005 | s = scan_str(start,FALSE,FALSE); |
79072805 | 10006 | if (!s) |
cea2e8a9 | 10007 | Perl_croak(aTHX_ "Glob not terminated"); |
79072805 LW |
10008 | return s; |
10009 | } | |
395c3793 | 10010 | else { |
9b3023bc | 10011 | bool readline_overriden = FALSE; |
6136c704 | 10012 | GV *gv_readline; |
9b3023bc | 10013 | GV **gvp; |
02aa26ce | 10014 | /* we're in a filehandle read situation */ |
3280af22 | 10015 | d = PL_tokenbuf; |
02aa26ce NT |
10016 | |
10017 | /* turn <> into <ARGV> */ | |
79072805 | 10018 | if (!len) |
689badd5 | 10019 | Copy("ARGV",d,5,char); |
02aa26ce | 10020 | |
9b3023bc | 10021 | /* Check whether readline() is overriden */ |
fafc274c | 10022 | gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV); |
6136c704 | 10023 | if ((gv_readline |
ba979b31 | 10024 | && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)) |
9b3023bc | 10025 | || |
017a3ce5 | 10026 | ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE)) |
9b3023bc | 10027 | && (gv_readline = *gvp) != (GV*)&PL_sv_undef |
ba979b31 | 10028 | && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))) |
9b3023bc RGS |
10029 | readline_overriden = TRUE; |
10030 | ||
02aa26ce NT |
10031 | /* if <$fh>, create the ops to turn the variable into a |
10032 | filehandle | |
10033 | */ | |
79072805 | 10034 | if (*d == '$') { |
a0d0e21e | 10035 | I32 tmp; |
02aa26ce NT |
10036 | |
10037 | /* try to find it in the pad for this block, otherwise find | |
10038 | add symbol table ops | |
10039 | */ | |
11343788 | 10040 | if ((tmp = pad_findmy(d)) != NOT_IN_PAD) { |
00b1698f | 10041 | if (PAD_COMPNAME_FLAGS_isOUR(tmp)) { |
6136c704 AL |
10042 | HV * const stash = PAD_COMPNAME_OURSTASH(tmp); |
10043 | HEK * const stashname = HvNAME_HEK(stash); | |
10044 | SV * const sym = sv_2mortal(newSVhek(stashname)); | |
396482e1 | 10045 | sv_catpvs(sym, "::"); |
f558d5af JH |
10046 | sv_catpv(sym, d+1); |
10047 | d = SvPVX(sym); | |
10048 | goto intro_sym; | |
10049 | } | |
10050 | else { | |
6136c704 | 10051 | OP * const o = newOP(OP_PADSV, 0); |
f558d5af | 10052 | o->op_targ = tmp; |
9b3023bc RGS |
10053 | PL_lex_op = readline_overriden |
10054 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, | |
10055 | append_elem(OP_LIST, o, | |
10056 | newCVREF(0, newGVOP(OP_GV,0,gv_readline)))) | |
10057 | : (OP*)newUNOP(OP_READLINE, 0, o); | |
f558d5af | 10058 | } |
a0d0e21e LW |
10059 | } |
10060 | else { | |
f558d5af JH |
10061 | GV *gv; |
10062 | ++d; | |
10063 | intro_sym: | |
10064 | gv = gv_fetchpv(d, | |
10065 | (PL_in_eval | |
10066 | ? (GV_ADDMULTI | GV_ADDINEVAL) | |
bea70d1e | 10067 | : GV_ADDMULTI), |
f558d5af | 10068 | SVt_PV); |
9b3023bc RGS |
10069 | PL_lex_op = readline_overriden |
10070 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, | |
10071 | append_elem(OP_LIST, | |
10072 | newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)), | |
10073 | newCVREF(0, newGVOP(OP_GV, 0, gv_readline)))) | |
10074 | : (OP*)newUNOP(OP_READLINE, 0, | |
10075 | newUNOP(OP_RV2SV, 0, | |
10076 | newGVOP(OP_GV, 0, gv))); | |
a0d0e21e | 10077 | } |
7c6fadd6 RGS |
10078 | if (!readline_overriden) |
10079 | PL_lex_op->op_flags |= OPf_SPECIAL; | |
f5284f61 | 10080 | /* we created the ops in PL_lex_op, so make yylval.ival a null op */ |
79072805 LW |
10081 | yylval.ival = OP_NULL; |
10082 | } | |
02aa26ce NT |
10083 | |
10084 | /* If it's none of the above, it must be a literal filehandle | |
10085 | (<Foo::BAR> or <FOO>) so build a simple readline OP */ | |
79072805 | 10086 | else { |
6136c704 | 10087 | GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO); |
9b3023bc RGS |
10088 | PL_lex_op = readline_overriden |
10089 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, | |
10090 | append_elem(OP_LIST, | |
10091 | newGVOP(OP_GV, 0, gv), | |
10092 | newCVREF(0, newGVOP(OP_GV, 0, gv_readline)))) | |
10093 | : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv)); | |
79072805 LW |
10094 | yylval.ival = OP_NULL; |
10095 | } | |
10096 | } | |
02aa26ce | 10097 | |
79072805 LW |
10098 | return s; |
10099 | } | |
10100 | ||
02aa26ce NT |
10101 | |
10102 | /* scan_str | |
10103 | takes: start position in buffer | |
09bef843 SB |
10104 | keep_quoted preserve \ on the embedded delimiter(s) |
10105 | keep_delims preserve the delimiters around the string | |
02aa26ce NT |
10106 | returns: position to continue reading from buffer |
10107 | side-effects: multi_start, multi_close, lex_repl or lex_stuff, and | |
10108 | updates the read buffer. | |
10109 | ||
10110 | This subroutine pulls a string out of the input. It is called for: | |
10111 | q single quotes q(literal text) | |
10112 | ' single quotes 'literal text' | |
10113 | qq double quotes qq(interpolate $here please) | |
10114 | " double quotes "interpolate $here please" | |
10115 | qx backticks qx(/bin/ls -l) | |
10116 | ` backticks `/bin/ls -l` | |
10117 | qw quote words @EXPORT_OK = qw( func() $spam ) | |
10118 | m// regexp match m/this/ | |
10119 | s/// regexp substitute s/this/that/ | |
10120 | tr/// string transliterate tr/this/that/ | |
10121 | y/// string transliterate y/this/that/ | |
10122 | ($*@) sub prototypes sub foo ($) | |
09bef843 | 10123 | (stuff) sub attr parameters sub foo : attr(stuff) |
02aa26ce NT |
10124 | <> readline or globs <FOO>, <>, <$fh>, or <*.c> |
10125 | ||
10126 | In most of these cases (all but <>, patterns and transliterate) | |
10127 | yylex() calls scan_str(). m// makes yylex() call scan_pat() which | |
10128 | calls scan_str(). s/// makes yylex() call scan_subst() which calls | |
10129 | scan_str(). tr/// and y/// make yylex() call scan_trans() which | |
10130 | calls scan_str(). | |
4e553d73 | 10131 | |
02aa26ce NT |
10132 | It skips whitespace before the string starts, and treats the first |
10133 | character as the delimiter. If the delimiter is one of ([{< then | |
10134 | the corresponding "close" character )]}> is used as the closing | |
10135 | delimiter. It allows quoting of delimiters, and if the string has | |
10136 | balanced delimiters ([{<>}]) it allows nesting. | |
10137 | ||
37fd879b HS |
10138 | On success, the SV with the resulting string is put into lex_stuff or, |
10139 | if that is already non-NULL, into lex_repl. The second case occurs only | |
10140 | when parsing the RHS of the special constructs s/// and tr/// (y///). | |
10141 | For convenience, the terminating delimiter character is stuffed into | |
10142 | SvIVX of the SV. | |
02aa26ce NT |
10143 | */ |
10144 | ||
76e3520e | 10145 | STATIC char * |
09bef843 | 10146 | S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims) |
79072805 | 10147 | { |
97aff369 | 10148 | dVAR; |
02aa26ce NT |
10149 | SV *sv; /* scalar value: string */ |
10150 | char *tmps; /* temp string, used for delimiter matching */ | |
10151 | register char *s = start; /* current position in the buffer */ | |
10152 | register char term; /* terminating character */ | |
10153 | register char *to; /* current position in the sv's data */ | |
10154 | I32 brackets = 1; /* bracket nesting level */ | |
89491803 | 10155 | bool has_utf8 = FALSE; /* is there any utf8 content? */ |
220e2d4e | 10156 | I32 termcode; /* terminating char. code */ |
89ebb4a3 | 10157 | U8 termstr[UTF8_MAXBYTES]; /* terminating string */ |
220e2d4e IH |
10158 | STRLEN termlen; /* length of terminating string */ |
10159 | char *last = NULL; /* last position for nesting bracket */ | |
02aa26ce NT |
10160 | |
10161 | /* skip space before the delimiter */ | |
fb73857a | 10162 | if (isSPACE(*s)) |
10163 | s = skipspace(s); | |
02aa26ce NT |
10164 | |
10165 | /* mark where we are, in case we need to report errors */ | |
79072805 | 10166 | CLINE; |
02aa26ce NT |
10167 | |
10168 | /* after skipping whitespace, the next character is the terminator */ | |
a0d0e21e | 10169 | term = *s; |
220e2d4e IH |
10170 | if (!UTF) { |
10171 | termcode = termstr[0] = term; | |
10172 | termlen = 1; | |
10173 | } | |
10174 | else { | |
f3b9ce0f | 10175 | termcode = utf8_to_uvchr((U8*)s, &termlen); |
220e2d4e IH |
10176 | Copy(s, termstr, termlen, U8); |
10177 | if (!UTF8_IS_INVARIANT(term)) | |
10178 | has_utf8 = TRUE; | |
10179 | } | |
b1c7b182 | 10180 | |
02aa26ce | 10181 | /* mark where we are */ |
57843af0 | 10182 | PL_multi_start = CopLINE(PL_curcop); |
3280af22 | 10183 | PL_multi_open = term; |
02aa26ce NT |
10184 | |
10185 | /* find corresponding closing delimiter */ | |
93a17b20 | 10186 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) |
220e2d4e IH |
10187 | termcode = termstr[0] = term = tmps[5]; |
10188 | ||
3280af22 | 10189 | PL_multi_close = term; |
79072805 | 10190 | |
561b68a9 SH |
10191 | /* create a new SV to hold the contents. 79 is the SV's initial length. |
10192 | What a random number. */ | |
10193 | sv = newSV(79); | |
ed6116ce | 10194 | sv_upgrade(sv, SVt_PVIV); |
45977657 | 10195 | SvIV_set(sv, termcode); |
a0d0e21e | 10196 | (void)SvPOK_only(sv); /* validate pointer */ |
02aa26ce NT |
10197 | |
10198 | /* move past delimiter and try to read a complete string */ | |
09bef843 | 10199 | if (keep_delims) |
220e2d4e IH |
10200 | sv_catpvn(sv, s, termlen); |
10201 | s += termlen; | |
93a17b20 | 10202 | for (;;) { |
220e2d4e IH |
10203 | if (PL_encoding && !UTF) { |
10204 | bool cont = TRUE; | |
10205 | ||
10206 | while (cont) { | |
95a20fc0 | 10207 | int offset = s - SvPVX_const(PL_linestr); |
66a1b24b | 10208 | const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr, |
f3b9ce0f | 10209 | &offset, (char*)termstr, termlen); |
6136c704 AL |
10210 | const char * const ns = SvPVX_const(PL_linestr) + offset; |
10211 | char * const svlast = SvEND(sv) - 1; | |
220e2d4e IH |
10212 | |
10213 | for (; s < ns; s++) { | |
10214 | if (*s == '\n' && !PL_rsfp) | |
10215 | CopLINE_inc(PL_curcop); | |
10216 | } | |
10217 | if (!found) | |
10218 | goto read_more_line; | |
10219 | else { | |
10220 | /* handle quoted delimiters */ | |
52327caf | 10221 | if (SvCUR(sv) > 1 && *(svlast-1) == '\\') { |
f54cb97a | 10222 | const char *t; |
95a20fc0 | 10223 | for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';) |
220e2d4e IH |
10224 | t--; |
10225 | if ((svlast-1 - t) % 2) { | |
10226 | if (!keep_quoted) { | |
10227 | *(svlast-1) = term; | |
10228 | *svlast = '\0'; | |
10229 | SvCUR_set(sv, SvCUR(sv) - 1); | |
10230 | } | |
10231 | continue; | |
10232 | } | |
10233 | } | |
10234 | if (PL_multi_open == PL_multi_close) { | |
10235 | cont = FALSE; | |
10236 | } | |
10237 | else { | |
f54cb97a AL |
10238 | const char *t; |
10239 | char *w; | |
220e2d4e IH |
10240 | if (!last) |
10241 | last = SvPVX(sv); | |
f54cb97a | 10242 | for (t = w = last; t < svlast; w++, t++) { |
220e2d4e IH |
10243 | /* At here, all closes are "was quoted" one, |
10244 | so we don't check PL_multi_close. */ | |
10245 | if (*t == '\\') { | |
10246 | if (!keep_quoted && *(t+1) == PL_multi_open) | |
10247 | t++; | |
10248 | else | |
10249 | *w++ = *t++; | |
10250 | } | |
10251 | else if (*t == PL_multi_open) | |
10252 | brackets++; | |
10253 | ||
10254 | *w = *t; | |
10255 | } | |
10256 | if (w < t) { | |
10257 | *w++ = term; | |
10258 | *w = '\0'; | |
95a20fc0 | 10259 | SvCUR_set(sv, w - SvPVX_const(sv)); |
220e2d4e IH |
10260 | } |
10261 | last = w; | |
10262 | if (--brackets <= 0) | |
10263 | cont = FALSE; | |
10264 | } | |
10265 | } | |
10266 | } | |
10267 | if (!keep_delims) { | |
10268 | SvCUR_set(sv, SvCUR(sv) - 1); | |
10269 | *SvEND(sv) = '\0'; | |
10270 | } | |
10271 | break; | |
10272 | } | |
10273 | ||
02aa26ce | 10274 | /* extend sv if need be */ |
3280af22 | 10275 | SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1); |
02aa26ce | 10276 | /* set 'to' to the next character in the sv's string */ |
463ee0b2 | 10277 | to = SvPVX(sv)+SvCUR(sv); |
09bef843 | 10278 | |
02aa26ce | 10279 | /* if open delimiter is the close delimiter read unbridle */ |
3280af22 NIS |
10280 | if (PL_multi_open == PL_multi_close) { |
10281 | for (; s < PL_bufend; s++,to++) { | |
02aa26ce | 10282 | /* embedded newlines increment the current line number */ |
3280af22 | 10283 | if (*s == '\n' && !PL_rsfp) |
57843af0 | 10284 | CopLINE_inc(PL_curcop); |
02aa26ce | 10285 | /* handle quoted delimiters */ |
3280af22 | 10286 | if (*s == '\\' && s+1 < PL_bufend && term != '\\') { |
09bef843 | 10287 | if (!keep_quoted && s[1] == term) |
a0d0e21e | 10288 | s++; |
02aa26ce | 10289 | /* any other quotes are simply copied straight through */ |
a0d0e21e LW |
10290 | else |
10291 | *to++ = *s++; | |
10292 | } | |
02aa26ce NT |
10293 | /* terminate when run out of buffer (the for() condition), or |
10294 | have found the terminator */ | |
220e2d4e IH |
10295 | else if (*s == term) { |
10296 | if (termlen == 1) | |
10297 | break; | |
f3b9ce0f | 10298 | if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen)) |
220e2d4e IH |
10299 | break; |
10300 | } | |
63cd0674 | 10301 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
89491803 | 10302 | has_utf8 = TRUE; |
93a17b20 LW |
10303 | *to = *s; |
10304 | } | |
10305 | } | |
02aa26ce NT |
10306 | |
10307 | /* if the terminator isn't the same as the start character (e.g., | |
10308 | matched brackets), we have to allow more in the quoting, and | |
10309 | be prepared for nested brackets. | |
10310 | */ | |
93a17b20 | 10311 | else { |
02aa26ce | 10312 | /* read until we run out of string, or we find the terminator */ |
3280af22 | 10313 | for (; s < PL_bufend; s++,to++) { |
02aa26ce | 10314 | /* embedded newlines increment the line count */ |
3280af22 | 10315 | if (*s == '\n' && !PL_rsfp) |
57843af0 | 10316 | CopLINE_inc(PL_curcop); |
02aa26ce | 10317 | /* backslashes can escape the open or closing characters */ |
3280af22 | 10318 | if (*s == '\\' && s+1 < PL_bufend) { |
09bef843 SB |
10319 | if (!keep_quoted && |
10320 | ((s[1] == PL_multi_open) || (s[1] == PL_multi_close))) | |
a0d0e21e LW |
10321 | s++; |
10322 | else | |
10323 | *to++ = *s++; | |
10324 | } | |
02aa26ce | 10325 | /* allow nested opens and closes */ |
3280af22 | 10326 | else if (*s == PL_multi_close && --brackets <= 0) |
93a17b20 | 10327 | break; |
3280af22 | 10328 | else if (*s == PL_multi_open) |
93a17b20 | 10329 | brackets++; |
63cd0674 | 10330 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
89491803 | 10331 | has_utf8 = TRUE; |
93a17b20 LW |
10332 | *to = *s; |
10333 | } | |
10334 | } | |
02aa26ce | 10335 | /* terminate the copied string and update the sv's end-of-string */ |
93a17b20 | 10336 | *to = '\0'; |
95a20fc0 | 10337 | SvCUR_set(sv, to - SvPVX_const(sv)); |
93a17b20 | 10338 | |
02aa26ce NT |
10339 | /* |
10340 | * this next chunk reads more into the buffer if we're not done yet | |
10341 | */ | |
10342 | ||
b1c7b182 GS |
10343 | if (s < PL_bufend) |
10344 | break; /* handle case where we are done yet :-) */ | |
79072805 | 10345 | |
6a27c188 | 10346 | #ifndef PERL_STRICT_CR |
95a20fc0 | 10347 | if (to - SvPVX_const(sv) >= 2) { |
c6f14548 GS |
10348 | if ((to[-2] == '\r' && to[-1] == '\n') || |
10349 | (to[-2] == '\n' && to[-1] == '\r')) | |
10350 | { | |
f63a84b2 LW |
10351 | to[-2] = '\n'; |
10352 | to--; | |
95a20fc0 | 10353 | SvCUR_set(sv, to - SvPVX_const(sv)); |
f63a84b2 LW |
10354 | } |
10355 | else if (to[-1] == '\r') | |
10356 | to[-1] = '\n'; | |
10357 | } | |
95a20fc0 | 10358 | else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r') |
f63a84b2 LW |
10359 | to[-1] = '\n'; |
10360 | #endif | |
10361 | ||
220e2d4e | 10362 | read_more_line: |
02aa26ce NT |
10363 | /* if we're out of file, or a read fails, bail and reset the current |
10364 | line marker so we can report where the unterminated string began | |
10365 | */ | |
3280af22 NIS |
10366 | if (!PL_rsfp || |
10367 | !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { | |
c07a80fd | 10368 | sv_free(sv); |
eb160463 | 10369 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
bd61b366 | 10370 | return NULL; |
79072805 | 10371 | } |
02aa26ce | 10372 | /* we read a line, so increment our line counter */ |
57843af0 | 10373 | CopLINE_inc(PL_curcop); |
a0ed51b3 | 10374 | |
02aa26ce | 10375 | /* update debugger info */ |
3280af22 | 10376 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
5f66b61c | 10377 | SV * const line_sv = newSV(0); |
79072805 | 10378 | |
5f66b61c AL |
10379 | sv_upgrade(line_sv, SVt_PVMG); |
10380 | sv_setsv(line_sv,PL_linestr); | |
10381 | (void)SvIOK_on(line_sv); | |
10382 | SvIV_set(line_sv, 0); | |
10383 | av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop), line_sv); | |
395c3793 | 10384 | } |
a0ed51b3 | 10385 | |
3280af22 NIS |
10386 | /* having changed the buffer, we must update PL_bufend */ |
10387 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
bd61b366 | 10388 | PL_last_lop = PL_last_uni = NULL; |
378cc40b | 10389 | } |
4e553d73 | 10390 | |
02aa26ce NT |
10391 | /* at this point, we have successfully read the delimited string */ |
10392 | ||
220e2d4e IH |
10393 | if (!PL_encoding || UTF) { |
10394 | if (keep_delims) | |
10395 | sv_catpvn(sv, s, termlen); | |
10396 | s += termlen; | |
10397 | } | |
10398 | if (has_utf8 || PL_encoding) | |
b1c7b182 | 10399 | SvUTF8_on(sv); |
d0063567 | 10400 | |
57843af0 | 10401 | PL_multi_end = CopLINE(PL_curcop); |
02aa26ce NT |
10402 | |
10403 | /* if we allocated too much space, give some back */ | |
93a17b20 LW |
10404 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
10405 | SvLEN_set(sv, SvCUR(sv) + 1); | |
b7e9a5c2 | 10406 | SvPV_renew(sv, SvLEN(sv)); |
79072805 | 10407 | } |
02aa26ce NT |
10408 | |
10409 | /* decide whether this is the first or second quoted string we've read | |
10410 | for this op | |
10411 | */ | |
4e553d73 | 10412 | |
3280af22 NIS |
10413 | if (PL_lex_stuff) |
10414 | PL_lex_repl = sv; | |
79072805 | 10415 | else |
3280af22 | 10416 | PL_lex_stuff = sv; |
378cc40b LW |
10417 | return s; |
10418 | } | |
10419 | ||
02aa26ce NT |
10420 | /* |
10421 | scan_num | |
10422 | takes: pointer to position in buffer | |
10423 | returns: pointer to new position in buffer | |
10424 | side-effects: builds ops for the constant in yylval.op | |
10425 | ||
10426 | Read a number in any of the formats that Perl accepts: | |
10427 | ||
7fd134d9 JH |
10428 | \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12. |
10429 | \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34 | |
24138b49 JH |
10430 | 0b[01](_?[01])* |
10431 | 0[0-7](_?[0-7])* | |
10432 | 0x[0-9A-Fa-f](_?[0-9A-Fa-f])* | |
02aa26ce | 10433 | |
3280af22 | 10434 | Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the |
02aa26ce NT |
10435 | thing it reads. |
10436 | ||
10437 | If it reads a number without a decimal point or an exponent, it will | |
10438 | try converting the number to an integer and see if it can do so | |
10439 | without loss of precision. | |
10440 | */ | |
4e553d73 | 10441 | |
378cc40b | 10442 | char * |
bfed75c6 | 10443 | Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp) |
378cc40b | 10444 | { |
97aff369 | 10445 | dVAR; |
bfed75c6 | 10446 | register const char *s = start; /* current position in buffer */ |
02aa26ce NT |
10447 | register char *d; /* destination in temp buffer */ |
10448 | register char *e; /* end of temp buffer */ | |
86554af2 | 10449 | NV nv; /* number read, as a double */ |
a0714e2c | 10450 | SV *sv = NULL; /* place to put the converted number */ |
a86a20aa | 10451 | bool floatit; /* boolean: int or float? */ |
cbbf8932 | 10452 | const char *lastub = NULL; /* position of last underbar */ |
bfed75c6 | 10453 | static char const number_too_long[] = "Number too long"; |
378cc40b | 10454 | |
02aa26ce NT |
10455 | /* We use the first character to decide what type of number this is */ |
10456 | ||
378cc40b | 10457 | switch (*s) { |
79072805 | 10458 | default: |
cea2e8a9 | 10459 | Perl_croak(aTHX_ "panic: scan_num"); |
4e553d73 | 10460 | |
02aa26ce | 10461 | /* if it starts with a 0, it could be an octal number, a decimal in |
a7cb1f99 | 10462 | 0.13 disguise, or a hexadecimal number, or a binary number. */ |
378cc40b LW |
10463 | case '0': |
10464 | { | |
02aa26ce NT |
10465 | /* variables: |
10466 | u holds the "number so far" | |
4f19785b WSI |
10467 | shift the power of 2 of the base |
10468 | (hex == 4, octal == 3, binary == 1) | |
02aa26ce NT |
10469 | overflowed was the number more than we can hold? |
10470 | ||
10471 | Shift is used when we add a digit. It also serves as an "are | |
4f19785b WSI |
10472 | we in octal/hex/binary?" indicator to disallow hex characters |
10473 | when in octal mode. | |
02aa26ce | 10474 | */ |
9e24b6e2 JH |
10475 | NV n = 0.0; |
10476 | UV u = 0; | |
79072805 | 10477 | I32 shift; |
9e24b6e2 | 10478 | bool overflowed = FALSE; |
61f33854 | 10479 | bool just_zero = TRUE; /* just plain 0 or binary number? */ |
27da23d5 JH |
10480 | static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 }; |
10481 | static const char* const bases[5] = | |
10482 | { "", "binary", "", "octal", "hexadecimal" }; | |
10483 | static const char* const Bases[5] = | |
10484 | { "", "Binary", "", "Octal", "Hexadecimal" }; | |
10485 | static const char* const maxima[5] = | |
10486 | { "", | |
10487 | "0b11111111111111111111111111111111", | |
10488 | "", | |
10489 | "037777777777", | |
10490 | "0xffffffff" }; | |
bfed75c6 | 10491 | const char *base, *Base, *max; |
378cc40b | 10492 | |
02aa26ce | 10493 | /* check for hex */ |
378cc40b LW |
10494 | if (s[1] == 'x') { |
10495 | shift = 4; | |
10496 | s += 2; | |
61f33854 | 10497 | just_zero = FALSE; |
4f19785b WSI |
10498 | } else if (s[1] == 'b') { |
10499 | shift = 1; | |
10500 | s += 2; | |
61f33854 | 10501 | just_zero = FALSE; |
378cc40b | 10502 | } |
02aa26ce | 10503 | /* check for a decimal in disguise */ |
b78218b7 | 10504 | else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E') |
378cc40b | 10505 | goto decimal; |
02aa26ce | 10506 | /* so it must be octal */ |
928753ea | 10507 | else { |
378cc40b | 10508 | shift = 3; |
928753ea JH |
10509 | s++; |
10510 | } | |
10511 | ||
10512 | if (*s == '_') { | |
10513 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10514 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10515 | "Misplaced _ in number"); |
10516 | lastub = s++; | |
10517 | } | |
9e24b6e2 JH |
10518 | |
10519 | base = bases[shift]; | |
10520 | Base = Bases[shift]; | |
10521 | max = maxima[shift]; | |
02aa26ce | 10522 | |
4f19785b | 10523 | /* read the rest of the number */ |
378cc40b | 10524 | for (;;) { |
9e24b6e2 | 10525 | /* x is used in the overflow test, |
893fe2c2 | 10526 | b is the digit we're adding on. */ |
9e24b6e2 | 10527 | UV x, b; |
55497cff | 10528 | |
378cc40b | 10529 | switch (*s) { |
02aa26ce NT |
10530 | |
10531 | /* if we don't mention it, we're done */ | |
378cc40b LW |
10532 | default: |
10533 | goto out; | |
02aa26ce | 10534 | |
928753ea | 10535 | /* _ are ignored -- but warned about if consecutive */ |
de3bb511 | 10536 | case '_': |
041457d9 | 10537 | if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX)) |
9014280d | 10538 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10539 | "Misplaced _ in number"); |
10540 | lastub = s++; | |
de3bb511 | 10541 | break; |
02aa26ce NT |
10542 | |
10543 | /* 8 and 9 are not octal */ | |
378cc40b | 10544 | case '8': case '9': |
4f19785b | 10545 | if (shift == 3) |
cea2e8a9 | 10546 | yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s)); |
378cc40b | 10547 | /* FALL THROUGH */ |
02aa26ce NT |
10548 | |
10549 | /* octal digits */ | |
4f19785b | 10550 | case '2': case '3': case '4': |
378cc40b | 10551 | case '5': case '6': case '7': |
4f19785b | 10552 | if (shift == 1) |
cea2e8a9 | 10553 | yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s)); |
4f19785b WSI |
10554 | /* FALL THROUGH */ |
10555 | ||
10556 | case '0': case '1': | |
02aa26ce | 10557 | b = *s++ & 15; /* ASCII digit -> value of digit */ |
55497cff | 10558 | goto digit; |
02aa26ce NT |
10559 | |
10560 | /* hex digits */ | |
378cc40b LW |
10561 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': |
10562 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': | |
02aa26ce | 10563 | /* make sure they said 0x */ |
378cc40b LW |
10564 | if (shift != 4) |
10565 | goto out; | |
55497cff | 10566 | b = (*s++ & 7) + 9; |
02aa26ce NT |
10567 | |
10568 | /* Prepare to put the digit we have onto the end | |
10569 | of the number so far. We check for overflows. | |
10570 | */ | |
10571 | ||
55497cff | 10572 | digit: |
61f33854 | 10573 | just_zero = FALSE; |
9e24b6e2 JH |
10574 | if (!overflowed) { |
10575 | x = u << shift; /* make room for the digit */ | |
10576 | ||
10577 | if ((x >> shift) != u | |
10578 | && !(PL_hints & HINT_NEW_BINARY)) { | |
9e24b6e2 JH |
10579 | overflowed = TRUE; |
10580 | n = (NV) u; | |
767a6a26 | 10581 | if (ckWARN_d(WARN_OVERFLOW)) |
9014280d | 10582 | Perl_warner(aTHX_ packWARN(WARN_OVERFLOW), |
9e24b6e2 JH |
10583 | "Integer overflow in %s number", |
10584 | base); | |
10585 | } else | |
10586 | u = x | b; /* add the digit to the end */ | |
10587 | } | |
10588 | if (overflowed) { | |
10589 | n *= nvshift[shift]; | |
10590 | /* If an NV has not enough bits in its | |
10591 | * mantissa to represent an UV this summing of | |
10592 | * small low-order numbers is a waste of time | |
10593 | * (because the NV cannot preserve the | |
10594 | * low-order bits anyway): we could just | |
10595 | * remember when did we overflow and in the | |
10596 | * end just multiply n by the right | |
10597 | * amount. */ | |
10598 | n += (NV) b; | |
55497cff | 10599 | } |
378cc40b LW |
10600 | break; |
10601 | } | |
10602 | } | |
02aa26ce NT |
10603 | |
10604 | /* if we get here, we had success: make a scalar value from | |
10605 | the number. | |
10606 | */ | |
378cc40b | 10607 | out: |
928753ea JH |
10608 | |
10609 | /* final misplaced underbar check */ | |
10610 | if (s[-1] == '_') { | |
10611 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10612 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number"); |
928753ea JH |
10613 | } |
10614 | ||
561b68a9 | 10615 | sv = newSV(0); |
9e24b6e2 | 10616 | if (overflowed) { |
041457d9 | 10617 | if (n > 4294967295.0 && ckWARN(WARN_PORTABLE)) |
9014280d | 10618 | Perl_warner(aTHX_ packWARN(WARN_PORTABLE), |
9e24b6e2 JH |
10619 | "%s number > %s non-portable", |
10620 | Base, max); | |
10621 | sv_setnv(sv, n); | |
10622 | } | |
10623 | else { | |
15041a67 | 10624 | #if UVSIZE > 4 |
041457d9 | 10625 | if (u > 0xffffffff && ckWARN(WARN_PORTABLE)) |
9014280d | 10626 | Perl_warner(aTHX_ packWARN(WARN_PORTABLE), |
9e24b6e2 JH |
10627 | "%s number > %s non-portable", |
10628 | Base, max); | |
2cc4c2dc | 10629 | #endif |
9e24b6e2 JH |
10630 | sv_setuv(sv, u); |
10631 | } | |
61f33854 | 10632 | if (just_zero && (PL_hints & HINT_NEW_INTEGER)) |
bfed75c6 | 10633 | sv = new_constant(start, s - start, "integer", |
a0714e2c | 10634 | sv, NULL, NULL); |
61f33854 | 10635 | else if (PL_hints & HINT_NEW_BINARY) |
a0714e2c | 10636 | sv = new_constant(start, s - start, "binary", sv, NULL, NULL); |
378cc40b LW |
10637 | } |
10638 | break; | |
02aa26ce NT |
10639 | |
10640 | /* | |
10641 | handle decimal numbers. | |
10642 | we're also sent here when we read a 0 as the first digit | |
10643 | */ | |
378cc40b LW |
10644 | case '1': case '2': case '3': case '4': case '5': |
10645 | case '6': case '7': case '8': case '9': case '.': | |
10646 | decimal: | |
3280af22 NIS |
10647 | d = PL_tokenbuf; |
10648 | e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */ | |
79072805 | 10649 | floatit = FALSE; |
02aa26ce NT |
10650 | |
10651 | /* read next group of digits and _ and copy into d */ | |
de3bb511 | 10652 | while (isDIGIT(*s) || *s == '_') { |
4e553d73 | 10653 | /* skip underscores, checking for misplaced ones |
02aa26ce NT |
10654 | if -w is on |
10655 | */ | |
93a17b20 | 10656 | if (*s == '_') { |
041457d9 | 10657 | if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX)) |
9014280d | 10658 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10659 | "Misplaced _ in number"); |
10660 | lastub = s++; | |
93a17b20 | 10661 | } |
fc36a67e | 10662 | else { |
02aa26ce | 10663 | /* check for end of fixed-length buffer */ |
fc36a67e | 10664 | if (d >= e) |
cea2e8a9 | 10665 | Perl_croak(aTHX_ number_too_long); |
02aa26ce | 10666 | /* if we're ok, copy the character */ |
378cc40b | 10667 | *d++ = *s++; |
fc36a67e | 10668 | } |
378cc40b | 10669 | } |
02aa26ce NT |
10670 | |
10671 | /* final misplaced underbar check */ | |
928753ea | 10672 | if (lastub && s == lastub + 1) { |
d008e5eb | 10673 | if (ckWARN(WARN_SYNTAX)) |
9014280d | 10674 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number"); |
d008e5eb | 10675 | } |
02aa26ce NT |
10676 | |
10677 | /* read a decimal portion if there is one. avoid | |
10678 | 3..5 being interpreted as the number 3. followed | |
10679 | by .5 | |
10680 | */ | |
2f3197b3 | 10681 | if (*s == '.' && s[1] != '.') { |
79072805 | 10682 | floatit = TRUE; |
378cc40b | 10683 | *d++ = *s++; |
02aa26ce | 10684 | |
928753ea JH |
10685 | if (*s == '_') { |
10686 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10687 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10688 | "Misplaced _ in number"); |
10689 | lastub = s; | |
10690 | } | |
10691 | ||
10692 | /* copy, ignoring underbars, until we run out of digits. | |
02aa26ce | 10693 | */ |
fc36a67e | 10694 | for (; isDIGIT(*s) || *s == '_'; s++) { |
02aa26ce | 10695 | /* fixed length buffer check */ |
fc36a67e | 10696 | if (d >= e) |
cea2e8a9 | 10697 | Perl_croak(aTHX_ number_too_long); |
928753ea | 10698 | if (*s == '_') { |
041457d9 | 10699 | if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX)) |
9014280d | 10700 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10701 | "Misplaced _ in number"); |
10702 | lastub = s; | |
10703 | } | |
10704 | else | |
fc36a67e | 10705 | *d++ = *s; |
378cc40b | 10706 | } |
928753ea JH |
10707 | /* fractional part ending in underbar? */ |
10708 | if (s[-1] == '_') { | |
10709 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10710 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10711 | "Misplaced _ in number"); |
10712 | } | |
dd629d5b GS |
10713 | if (*s == '.' && isDIGIT(s[1])) { |
10714 | /* oops, it's really a v-string, but without the "v" */ | |
f4758303 | 10715 | s = start; |
dd629d5b GS |
10716 | goto vstring; |
10717 | } | |
378cc40b | 10718 | } |
02aa26ce NT |
10719 | |
10720 | /* read exponent part, if present */ | |
3792a11b | 10721 | if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) { |
79072805 LW |
10722 | floatit = TRUE; |
10723 | s++; | |
02aa26ce NT |
10724 | |
10725 | /* regardless of whether user said 3E5 or 3e5, use lower 'e' */ | |
79072805 | 10726 | *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */ |
02aa26ce | 10727 | |
7fd134d9 JH |
10728 | /* stray preinitial _ */ |
10729 | if (*s == '_') { | |
10730 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10731 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
7fd134d9 JH |
10732 | "Misplaced _ in number"); |
10733 | lastub = s++; | |
10734 | } | |
10735 | ||
02aa26ce | 10736 | /* allow positive or negative exponent */ |
378cc40b LW |
10737 | if (*s == '+' || *s == '-') |
10738 | *d++ = *s++; | |
02aa26ce | 10739 | |
7fd134d9 JH |
10740 | /* stray initial _ */ |
10741 | if (*s == '_') { | |
10742 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10743 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
7fd134d9 JH |
10744 | "Misplaced _ in number"); |
10745 | lastub = s++; | |
10746 | } | |
10747 | ||
7fd134d9 JH |
10748 | /* read digits of exponent */ |
10749 | while (isDIGIT(*s) || *s == '_') { | |
10750 | if (isDIGIT(*s)) { | |
10751 | if (d >= e) | |
10752 | Perl_croak(aTHX_ number_too_long); | |
b3b48e3e | 10753 | *d++ = *s++; |
7fd134d9 JH |
10754 | } |
10755 | else { | |
041457d9 DM |
10756 | if (((lastub && s == lastub + 1) || |
10757 | (!isDIGIT(s[1]) && s[1] != '_')) | |
10758 | && ckWARN(WARN_SYNTAX)) | |
9014280d | 10759 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
7fd134d9 | 10760 | "Misplaced _ in number"); |
b3b48e3e | 10761 | lastub = s++; |
7fd134d9 | 10762 | } |
7fd134d9 | 10763 | } |
378cc40b | 10764 | } |
02aa26ce | 10765 | |
02aa26ce NT |
10766 | |
10767 | /* make an sv from the string */ | |
561b68a9 | 10768 | sv = newSV(0); |
097ee67d | 10769 | |
0b7fceb9 | 10770 | /* |
58bb9ec3 NC |
10771 | We try to do an integer conversion first if no characters |
10772 | indicating "float" have been found. | |
0b7fceb9 MU |
10773 | */ |
10774 | ||
10775 | if (!floatit) { | |
58bb9ec3 | 10776 | UV uv; |
6136c704 | 10777 | const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv); |
58bb9ec3 NC |
10778 | |
10779 | if (flags == IS_NUMBER_IN_UV) { | |
10780 | if (uv <= IV_MAX) | |
86554af2 | 10781 | sv_setiv(sv, uv); /* Prefer IVs over UVs. */ |
58bb9ec3 | 10782 | else |
c239479b | 10783 | sv_setuv(sv, uv); |
58bb9ec3 NC |
10784 | } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) { |
10785 | if (uv <= (UV) IV_MIN) | |
10786 | sv_setiv(sv, -(IV)uv); | |
10787 | else | |
10788 | floatit = TRUE; | |
10789 | } else | |
10790 | floatit = TRUE; | |
10791 | } | |
0b7fceb9 | 10792 | if (floatit) { |
58bb9ec3 NC |
10793 | /* terminate the string */ |
10794 | *d = '\0'; | |
86554af2 JH |
10795 | nv = Atof(PL_tokenbuf); |
10796 | sv_setnv(sv, nv); | |
10797 | } | |
86554af2 | 10798 | |
b8403495 JH |
10799 | if ( floatit ? (PL_hints & HINT_NEW_FLOAT) : |
10800 | (PL_hints & HINT_NEW_INTEGER) ) | |
4e553d73 | 10801 | sv = new_constant(PL_tokenbuf, d - PL_tokenbuf, |
b8403495 | 10802 | (floatit ? "float" : "integer"), |
a0714e2c | 10803 | sv, NULL, NULL); |
378cc40b | 10804 | break; |
0b7fceb9 | 10805 | |
e312add1 | 10806 | /* if it starts with a v, it could be a v-string */ |
a7cb1f99 | 10807 | case 'v': |
dd629d5b | 10808 | vstring: |
561b68a9 | 10809 | sv = newSV(5); /* preallocate storage space */ |
b0f01acb | 10810 | s = scan_vstring(s,sv); |
a7cb1f99 | 10811 | break; |
79072805 | 10812 | } |
a687059c | 10813 | |
02aa26ce NT |
10814 | /* make the op for the constant and return */ |
10815 | ||
a86a20aa | 10816 | if (sv) |
b73d6f50 | 10817 | lvalp->opval = newSVOP(OP_CONST, 0, sv); |
a7cb1f99 | 10818 | else |
5f66b61c | 10819 | lvalp->opval = NULL; |
a687059c | 10820 | |
73d840c0 | 10821 | return (char *)s; |
378cc40b LW |
10822 | } |
10823 | ||
76e3520e | 10824 | STATIC char * |
cea2e8a9 | 10825 | S_scan_formline(pTHX_ register char *s) |
378cc40b | 10826 | { |
97aff369 | 10827 | dVAR; |
79072805 | 10828 | register char *eol; |
378cc40b | 10829 | register char *t; |
6136c704 | 10830 | SV * const stuff = newSVpvs(""); |
79072805 | 10831 | bool needargs = FALSE; |
c5ee2135 | 10832 | bool eofmt = FALSE; |
378cc40b | 10833 | |
79072805 | 10834 | while (!needargs) { |
a1b95068 | 10835 | if (*s == '.') { |
51882d45 | 10836 | #ifdef PERL_STRICT_CR |
bf4acbe4 | 10837 | for (t = s+1;SPACE_OR_TAB(*t); t++) ; |
51882d45 | 10838 | #else |
bf4acbe4 | 10839 | for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ; |
51882d45 | 10840 | #endif |
c5ee2135 WL |
10841 | if (*t == '\n' || t == PL_bufend) { |
10842 | eofmt = TRUE; | |
79072805 | 10843 | break; |
c5ee2135 | 10844 | } |
79072805 | 10845 | } |
3280af22 | 10846 | if (PL_in_eval && !PL_rsfp) { |
07409e01 | 10847 | eol = (char *) memchr(s,'\n',PL_bufend-s); |
0f85fab0 | 10848 | if (!eol++) |
3280af22 | 10849 | eol = PL_bufend; |
0f85fab0 LW |
10850 | } |
10851 | else | |
3280af22 | 10852 | eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
79072805 | 10853 | if (*s != '#') { |
a0d0e21e LW |
10854 | for (t = s; t < eol; t++) { |
10855 | if (*t == '~' && t[1] == '~' && SvCUR(stuff)) { | |
10856 | needargs = FALSE; | |
10857 | goto enough; /* ~~ must be first line in formline */ | |
378cc40b | 10858 | } |
a0d0e21e LW |
10859 | if (*t == '@' || *t == '^') |
10860 | needargs = TRUE; | |
378cc40b | 10861 | } |
7121b347 MG |
10862 | if (eol > s) { |
10863 | sv_catpvn(stuff, s, eol-s); | |
2dc4c65b | 10864 | #ifndef PERL_STRICT_CR |
7121b347 MG |
10865 | if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') { |
10866 | char *end = SvPVX(stuff) + SvCUR(stuff); | |
10867 | end[-2] = '\n'; | |
10868 | end[-1] = '\0'; | |
b162af07 | 10869 | SvCUR_set(stuff, SvCUR(stuff) - 1); |
7121b347 | 10870 | } |
2dc4c65b | 10871 | #endif |
7121b347 MG |
10872 | } |
10873 | else | |
10874 | break; | |
79072805 | 10875 | } |
95a20fc0 | 10876 | s = (char*)eol; |
3280af22 NIS |
10877 | if (PL_rsfp) { |
10878 | s = filter_gets(PL_linestr, PL_rsfp, 0); | |
10879 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr); | |
10880 | PL_bufend = PL_bufptr + SvCUR(PL_linestr); | |
bd61b366 | 10881 | PL_last_lop = PL_last_uni = NULL; |
79072805 | 10882 | if (!s) { |
3280af22 | 10883 | s = PL_bufptr; |
378cc40b LW |
10884 | break; |
10885 | } | |
378cc40b | 10886 | } |
463ee0b2 | 10887 | incline(s); |
79072805 | 10888 | } |
a0d0e21e LW |
10889 | enough: |
10890 | if (SvCUR(stuff)) { | |
3280af22 | 10891 | PL_expect = XTERM; |
79072805 | 10892 | if (needargs) { |
3280af22 NIS |
10893 | PL_lex_state = LEX_NORMAL; |
10894 | PL_nextval[PL_nexttoke].ival = 0; | |
79072805 LW |
10895 | force_next(','); |
10896 | } | |
a0d0e21e | 10897 | else |
3280af22 | 10898 | PL_lex_state = LEX_FORMLINE; |
1bd51a4c | 10899 | if (!IN_BYTES) { |
95a20fc0 | 10900 | if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff))) |
1bd51a4c IH |
10901 | SvUTF8_on(stuff); |
10902 | else if (PL_encoding) | |
10903 | sv_recode_to_utf8(stuff, PL_encoding); | |
10904 | } | |
3280af22 | 10905 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff); |
79072805 | 10906 | force_next(THING); |
3280af22 | 10907 | PL_nextval[PL_nexttoke].ival = OP_FORMLINE; |
79072805 | 10908 | force_next(LSTOP); |
378cc40b | 10909 | } |
79072805 | 10910 | else { |
8990e307 | 10911 | SvREFCNT_dec(stuff); |
c5ee2135 WL |
10912 | if (eofmt) |
10913 | PL_lex_formbrack = 0; | |
3280af22 | 10914 | PL_bufptr = s; |
79072805 LW |
10915 | } |
10916 | return s; | |
378cc40b | 10917 | } |
a687059c | 10918 | |
76e3520e | 10919 | STATIC void |
cea2e8a9 | 10920 | S_set_csh(pTHX) |
a687059c | 10921 | { |
ae986130 | 10922 | #ifdef CSH |
97aff369 | 10923 | dVAR; |
3280af22 NIS |
10924 | if (!PL_cshlen) |
10925 | PL_cshlen = strlen(PL_cshname); | |
5f66b61c | 10926 | #else |
b2675967 | 10927 | #if defined(USE_ITHREADS) |
96a5add6 | 10928 | PERL_UNUSED_CONTEXT; |
ae986130 | 10929 | #endif |
b2675967 | 10930 | #endif |
a687059c | 10931 | } |
463ee0b2 | 10932 | |
ba6d6ac9 | 10933 | I32 |
864dbfa3 | 10934 | Perl_start_subparse(pTHX_ I32 is_format, U32 flags) |
8990e307 | 10935 | { |
97aff369 | 10936 | dVAR; |
a3b680e6 | 10937 | const I32 oldsavestack_ix = PL_savestack_ix; |
6136c704 | 10938 | CV* const outsidecv = PL_compcv; |
8990e307 | 10939 | |
3280af22 NIS |
10940 | if (PL_compcv) { |
10941 | assert(SvTYPE(PL_compcv) == SVt_PVCV); | |
e9a444f0 | 10942 | } |
7766f137 | 10943 | SAVEI32(PL_subline); |
3280af22 | 10944 | save_item(PL_subname); |
3280af22 | 10945 | SAVESPTR(PL_compcv); |
3280af22 | 10946 | |
561b68a9 | 10947 | PL_compcv = (CV*)newSV(0); |
3280af22 NIS |
10948 | sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV); |
10949 | CvFLAGS(PL_compcv) |= flags; | |
10950 | ||
57843af0 | 10951 | PL_subline = CopLINE(PL_curcop); |
dd2155a4 | 10952 | CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB); |
3280af22 | 10953 | CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv); |
a3985cdc | 10954 | CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax; |
748a9306 | 10955 | |
8990e307 LW |
10956 | return oldsavestack_ix; |
10957 | } | |
10958 | ||
084592ab CN |
10959 | #ifdef __SC__ |
10960 | #pragma segment Perl_yylex | |
10961 | #endif | |
8990e307 | 10962 | int |
bfed75c6 | 10963 | Perl_yywarn(pTHX_ const char *s) |
8990e307 | 10964 | { |
97aff369 | 10965 | dVAR; |
faef0170 | 10966 | PL_in_eval |= EVAL_WARNONLY; |
748a9306 | 10967 | yyerror(s); |
faef0170 | 10968 | PL_in_eval &= ~EVAL_WARNONLY; |
748a9306 | 10969 | return 0; |
8990e307 LW |
10970 | } |
10971 | ||
10972 | int | |
bfed75c6 | 10973 | Perl_yyerror(pTHX_ const char *s) |
463ee0b2 | 10974 | { |
97aff369 | 10975 | dVAR; |
bfed75c6 AL |
10976 | const char *where = NULL; |
10977 | const char *context = NULL; | |
68dc0745 | 10978 | int contlen = -1; |
46fc3d4c | 10979 | SV *msg; |
463ee0b2 | 10980 | |
3280af22 | 10981 | if (!yychar || (yychar == ';' && !PL_rsfp)) |
54310121 | 10982 | where = "at EOF"; |
8bcfe651 TM |
10983 | else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr && |
10984 | PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr && | |
10985 | PL_oldbufptr != PL_bufptr) { | |
f355267c JH |
10986 | /* |
10987 | Only for NetWare: | |
10988 | The code below is removed for NetWare because it abends/crashes on NetWare | |
10989 | when the script has error such as not having the closing quotes like: | |
10990 | if ($var eq "value) | |
10991 | Checking of white spaces is anyway done in NetWare code. | |
10992 | */ | |
10993 | #ifndef NETWARE | |
3280af22 NIS |
10994 | while (isSPACE(*PL_oldoldbufptr)) |
10995 | PL_oldoldbufptr++; | |
f355267c | 10996 | #endif |
3280af22 NIS |
10997 | context = PL_oldoldbufptr; |
10998 | contlen = PL_bufptr - PL_oldoldbufptr; | |
463ee0b2 | 10999 | } |
8bcfe651 TM |
11000 | else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr && |
11001 | PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) { | |
f355267c JH |
11002 | /* |
11003 | Only for NetWare: | |
11004 | The code below is removed for NetWare because it abends/crashes on NetWare | |
11005 | when the script has error such as not having the closing quotes like: | |
11006 | if ($var eq "value) | |
11007 | Checking of white spaces is anyway done in NetWare code. | |
11008 | */ | |
11009 | #ifndef NETWARE | |
3280af22 NIS |
11010 | while (isSPACE(*PL_oldbufptr)) |
11011 | PL_oldbufptr++; | |
f355267c | 11012 | #endif |
3280af22 NIS |
11013 | context = PL_oldbufptr; |
11014 | contlen = PL_bufptr - PL_oldbufptr; | |
463ee0b2 LW |
11015 | } |
11016 | else if (yychar > 255) | |
68dc0745 | 11017 | where = "next token ???"; |
12fbd33b | 11018 | else if (yychar == -2) { /* YYEMPTY */ |
3280af22 NIS |
11019 | if (PL_lex_state == LEX_NORMAL || |
11020 | (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL)) | |
68dc0745 | 11021 | where = "at end of line"; |
3280af22 | 11022 | else if (PL_lex_inpat) |
68dc0745 | 11023 | where = "within pattern"; |
463ee0b2 | 11024 | else |
68dc0745 | 11025 | where = "within string"; |
463ee0b2 | 11026 | } |
46fc3d4c | 11027 | else { |
6136c704 | 11028 | SV * const where_sv = sv_2mortal(newSVpvs("next char ")); |
46fc3d4c | 11029 | if (yychar < 32) |
cea2e8a9 | 11030 | Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar)); |
46fc3d4c | 11031 | else if (isPRINT_LC(yychar)) |
cea2e8a9 | 11032 | Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar); |
463ee0b2 | 11033 | else |
cea2e8a9 | 11034 | Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255); |
95a20fc0 | 11035 | where = SvPVX_const(where_sv); |
463ee0b2 | 11036 | } |
46fc3d4c | 11037 | msg = sv_2mortal(newSVpv(s, 0)); |
ed094faf | 11038 | Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ", |
248c2a4d | 11039 | OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop)); |
68dc0745 | 11040 | if (context) |
cea2e8a9 | 11041 | Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context); |
463ee0b2 | 11042 | else |
cea2e8a9 | 11043 | Perl_sv_catpvf(aTHX_ msg, "%s\n", where); |
57843af0 | 11044 | if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) { |
cf2093f6 | 11045 | Perl_sv_catpvf(aTHX_ msg, |
57def98f | 11046 | " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n", |
cf2093f6 | 11047 | (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start); |
3280af22 | 11048 | PL_multi_end = 0; |
a0d0e21e | 11049 | } |
56da5a46 RGS |
11050 | if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX)) |
11051 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg); | |
463ee0b2 | 11052 | else |
5a844595 | 11053 | qerror(msg); |
c7d6bfb2 GS |
11054 | if (PL_error_count >= 10) { |
11055 | if (PL_in_eval && SvCUR(ERRSV)) | |
d2560b70 | 11056 | Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n", |
248c2a4d | 11057 | ERRSV, OutCopFILE(PL_curcop)); |
c7d6bfb2 GS |
11058 | else |
11059 | Perl_croak(aTHX_ "%s has too many errors.\n", | |
248c2a4d | 11060 | OutCopFILE(PL_curcop)); |
c7d6bfb2 | 11061 | } |
3280af22 | 11062 | PL_in_my = 0; |
5c284bb0 | 11063 | PL_in_my_stash = NULL; |
463ee0b2 LW |
11064 | return 0; |
11065 | } | |
084592ab CN |
11066 | #ifdef __SC__ |
11067 | #pragma segment Main | |
11068 | #endif | |
4e35701f | 11069 | |
b250498f | 11070 | STATIC char* |
3ae08724 | 11071 | S_swallow_bom(pTHX_ U8 *s) |
01ec43d0 | 11072 | { |
97aff369 | 11073 | dVAR; |
f54cb97a | 11074 | const STRLEN slen = SvCUR(PL_linestr); |
7aa207d6 | 11075 | switch (s[0]) { |
4e553d73 NIS |
11076 | case 0xFF: |
11077 | if (s[1] == 0xFE) { | |
7aa207d6 | 11078 | /* UTF-16 little-endian? (or UTF32-LE?) */ |
3ae08724 | 11079 | if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */ |
7aa207d6 | 11080 | Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE"); |
01ec43d0 | 11081 | #ifndef PERL_NO_UTF16_FILTER |
7aa207d6 | 11082 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n"); |
3ae08724 | 11083 | s += 2; |
7aa207d6 | 11084 | utf16le: |
dea0fc0b JH |
11085 | if (PL_bufend > (char*)s) { |
11086 | U8 *news; | |
11087 | I32 newlen; | |
11088 | ||
11089 | filter_add(utf16rev_textfilter, NULL); | |
a02a5408 | 11090 | Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8); |
1de9afcd RGS |
11091 | utf16_to_utf8_reversed(s, news, |
11092 | PL_bufend - (char*)s - 1, | |
11093 | &newlen); | |
7aa207d6 | 11094 | sv_setpvn(PL_linestr, (const char*)news, newlen); |
dea0fc0b | 11095 | Safefree(news); |
7aa207d6 JH |
11096 | SvUTF8_on(PL_linestr); |
11097 | s = (U8*)SvPVX(PL_linestr); | |
11098 | PL_bufend = SvPVX(PL_linestr) + newlen; | |
dea0fc0b | 11099 | } |
b250498f | 11100 | #else |
7aa207d6 | 11101 | Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE"); |
b250498f | 11102 | #endif |
01ec43d0 GS |
11103 | } |
11104 | break; | |
78ae23f5 | 11105 | case 0xFE: |
7aa207d6 | 11106 | if (s[1] == 0xFF) { /* UTF-16 big-endian? */ |
01ec43d0 | 11107 | #ifndef PERL_NO_UTF16_FILTER |
7aa207d6 | 11108 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n"); |
dea0fc0b | 11109 | s += 2; |
7aa207d6 | 11110 | utf16be: |
dea0fc0b JH |
11111 | if (PL_bufend > (char *)s) { |
11112 | U8 *news; | |
11113 | I32 newlen; | |
11114 | ||
11115 | filter_add(utf16_textfilter, NULL); | |
a02a5408 | 11116 | Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8); |
1de9afcd RGS |
11117 | utf16_to_utf8(s, news, |
11118 | PL_bufend - (char*)s, | |
11119 | &newlen); | |
7aa207d6 | 11120 | sv_setpvn(PL_linestr, (const char*)news, newlen); |
dea0fc0b | 11121 | Safefree(news); |
7aa207d6 JH |
11122 | SvUTF8_on(PL_linestr); |
11123 | s = (U8*)SvPVX(PL_linestr); | |
11124 | PL_bufend = SvPVX(PL_linestr) + newlen; | |
dea0fc0b | 11125 | } |
b250498f | 11126 | #else |
7aa207d6 | 11127 | Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE"); |
b250498f | 11128 | #endif |
01ec43d0 GS |
11129 | } |
11130 | break; | |
3ae08724 GS |
11131 | case 0xEF: |
11132 | if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) { | |
7aa207d6 | 11133 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n"); |
01ec43d0 GS |
11134 | s += 3; /* UTF-8 */ |
11135 | } | |
11136 | break; | |
11137 | case 0: | |
7aa207d6 JH |
11138 | if (slen > 3) { |
11139 | if (s[1] == 0) { | |
11140 | if (s[2] == 0xFE && s[3] == 0xFF) { | |
11141 | /* UTF-32 big-endian */ | |
11142 | Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE"); | |
11143 | } | |
11144 | } | |
11145 | else if (s[2] == 0 && s[3] != 0) { | |
11146 | /* Leading bytes | |
11147 | * 00 xx 00 xx | |
11148 | * are a good indicator of UTF-16BE. */ | |
11149 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n"); | |
11150 | goto utf16be; | |
11151 | } | |
01ec43d0 | 11152 | } |
7aa207d6 JH |
11153 | default: |
11154 | if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) { | |
11155 | /* Leading bytes | |
11156 | * xx 00 xx 00 | |
11157 | * are a good indicator of UTF-16LE. */ | |
11158 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n"); | |
11159 | goto utf16le; | |
11160 | } | |
01ec43d0 | 11161 | } |
b8f84bb2 | 11162 | return (char*)s; |
b250498f | 11163 | } |
4755096e | 11164 | |
4755096e GS |
11165 | /* |
11166 | * restore_rsfp | |
11167 | * Restore a source filter. | |
11168 | */ | |
11169 | ||
11170 | static void | |
acfe0abc | 11171 | restore_rsfp(pTHX_ void *f) |
4755096e | 11172 | { |
97aff369 | 11173 | dVAR; |
0bd48802 | 11174 | PerlIO * const fp = (PerlIO*)f; |
4755096e GS |
11175 | |
11176 | if (PL_rsfp == PerlIO_stdin()) | |
11177 | PerlIO_clearerr(PL_rsfp); | |
11178 | else if (PL_rsfp && (PL_rsfp != fp)) | |
11179 | PerlIO_close(PL_rsfp); | |
11180 | PL_rsfp = fp; | |
11181 | } | |
6e3aabd6 GS |
11182 | |
11183 | #ifndef PERL_NO_UTF16_FILTER | |
11184 | static I32 | |
acfe0abc | 11185 | utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
6e3aabd6 | 11186 | { |
97aff369 | 11187 | dVAR; |
f54cb97a AL |
11188 | const STRLEN old = SvCUR(sv); |
11189 | const I32 count = FILTER_READ(idx+1, sv, maxlen); | |
1de9afcd RGS |
11190 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
11191 | "utf16_textfilter(%p): %d %d (%d)\n", | |
4fccd7c6 | 11192 | utf16_textfilter, idx, maxlen, (int) count)); |
6e3aabd6 GS |
11193 | if (count) { |
11194 | U8* tmps; | |
dea0fc0b | 11195 | I32 newlen; |
a02a5408 | 11196 | Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8); |
95a20fc0 SP |
11197 | Copy(SvPVX_const(sv), tmps, old, char); |
11198 | utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old, | |
1de9afcd RGS |
11199 | SvCUR(sv) - old, &newlen); |
11200 | sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old); | |
6e3aabd6 | 11201 | } |
1de9afcd RGS |
11202 | DEBUG_P({sv_dump(sv);}); |
11203 | return SvCUR(sv); | |
6e3aabd6 GS |
11204 | } |
11205 | ||
11206 | static I32 | |
acfe0abc | 11207 | utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
6e3aabd6 | 11208 | { |
97aff369 | 11209 | dVAR; |
f54cb97a AL |
11210 | const STRLEN old = SvCUR(sv); |
11211 | const I32 count = FILTER_READ(idx+1, sv, maxlen); | |
1de9afcd RGS |
11212 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
11213 | "utf16rev_textfilter(%p): %d %d (%d)\n", | |
4fccd7c6 | 11214 | utf16rev_textfilter, idx, maxlen, (int) count)); |
6e3aabd6 GS |
11215 | if (count) { |
11216 | U8* tmps; | |
dea0fc0b | 11217 | I32 newlen; |
a02a5408 | 11218 | Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8); |
95a20fc0 SP |
11219 | Copy(SvPVX_const(sv), tmps, old, char); |
11220 | utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old, | |
1de9afcd RGS |
11221 | SvCUR(sv) - old, &newlen); |
11222 | sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old); | |
6e3aabd6 | 11223 | } |
1de9afcd | 11224 | DEBUG_P({ sv_dump(sv); }); |
6e3aabd6 GS |
11225 | return count; |
11226 | } | |
11227 | #endif | |
9f4817db | 11228 | |
f333445c JP |
11229 | /* |
11230 | Returns a pointer to the next character after the parsed | |
11231 | vstring, as well as updating the passed in sv. | |
11232 | ||
11233 | Function must be called like | |
11234 | ||
561b68a9 | 11235 | sv = newSV(5); |
f333445c JP |
11236 | s = scan_vstring(s,sv); |
11237 | ||
11238 | The sv should already be large enough to store the vstring | |
11239 | passed in, for performance reasons. | |
11240 | ||
11241 | */ | |
11242 | ||
11243 | char * | |
bfed75c6 | 11244 | Perl_scan_vstring(pTHX_ const char *s, SV *sv) |
f333445c | 11245 | { |
97aff369 | 11246 | dVAR; |
bfed75c6 AL |
11247 | const char *pos = s; |
11248 | const char *start = s; | |
f333445c | 11249 | if (*pos == 'v') pos++; /* get past 'v' */ |
3e884cbf JH |
11250 | while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_')) |
11251 | pos++; | |
f333445c JP |
11252 | if ( *pos != '.') { |
11253 | /* this may not be a v-string if followed by => */ | |
bfed75c6 | 11254 | const char *next = pos; |
8fc7bb1c SM |
11255 | while (next < PL_bufend && isSPACE(*next)) |
11256 | ++next; | |
11257 | if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) { | |
f333445c JP |
11258 | /* return string not v-string */ |
11259 | sv_setpvn(sv,(char *)s,pos-s); | |
73d840c0 | 11260 | return (char *)pos; |
f333445c JP |
11261 | } |
11262 | } | |
11263 | ||
11264 | if (!isALPHA(*pos)) { | |
89ebb4a3 | 11265 | U8 tmpbuf[UTF8_MAXBYTES+1]; |
f333445c JP |
11266 | |
11267 | if (*s == 'v') s++; /* get past 'v' */ | |
11268 | ||
11269 | sv_setpvn(sv, "", 0); | |
11270 | ||
11271 | for (;;) { | |
0bd48802 AL |
11272 | U8 *tmpend; |
11273 | UV rev = 0; | |
f333445c JP |
11274 | { |
11275 | /* this is atoi() that tolerates underscores */ | |
bfed75c6 | 11276 | const char *end = pos; |
f333445c JP |
11277 | UV mult = 1; |
11278 | while (--end >= s) { | |
11279 | UV orev; | |
11280 | if (*end == '_') | |
11281 | continue; | |
11282 | orev = rev; | |
11283 | rev += (*end - '0') * mult; | |
11284 | mult *= 10; | |
11285 | if (orev > rev && ckWARN_d(WARN_OVERFLOW)) | |
11286 | Perl_warner(aTHX_ packWARN(WARN_OVERFLOW), | |
11287 | "Integer overflow in decimal number"); | |
11288 | } | |
11289 | } | |
11290 | #ifdef EBCDIC | |
11291 | if (rev > 0x7FFFFFFF) | |
11292 | Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647"); | |
11293 | #endif | |
11294 | /* Append native character for the rev point */ | |
11295 | tmpend = uvchr_to_utf8(tmpbuf, rev); | |
11296 | sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf); | |
11297 | if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev))) | |
11298 | SvUTF8_on(sv); | |
3e884cbf | 11299 | if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1])) |
f333445c JP |
11300 | s = ++pos; |
11301 | else { | |
11302 | s = pos; | |
11303 | break; | |
11304 | } | |
3e884cbf | 11305 | while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_')) |
f333445c JP |
11306 | pos++; |
11307 | } | |
11308 | SvPOK_on(sv); | |
11309 | sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start); | |
11310 | SvRMAGICAL_on(sv); | |
11311 | } | |
73d840c0 | 11312 | return (char *)s; |
f333445c JP |
11313 | } |
11314 | ||
1da4ca5f NC |
11315 | /* |
11316 | * Local variables: | |
11317 | * c-indentation-style: bsd | |
11318 | * c-basic-offset: 4 | |
11319 | * indent-tabs-mode: t | |
11320 | * End: | |
11321 | * | |
37442d52 RGS |
11322 | * ex: set ts=8 sts=4 sw=4 noet: |
11323 | */ |