Commit | Line | Data |
---|---|---|
a0d0e21e | 1 | /* toke.c |
a687059c | 2 | * |
4bb101f2 | 3 | * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
770526c1 | 4 | * 2000, 2001, 2002, 2003, 2004, 2005, 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"; |
8903cb82 | 30 | |
acfe0abc | 31 | static void restore_rsfp(pTHX_ void *f); |
6e3aabd6 | 32 | #ifndef PERL_NO_UTF16_FILTER |
acfe0abc GS |
33 | static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen); |
34 | static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen); | |
6e3aabd6 | 35 | #endif |
51371543 | 36 | |
9059aa12 LW |
37 | #define XFAKEBRACK 128 |
38 | #define XENUMMASK 127 | |
39 | ||
39e02b42 JH |
40 | #ifdef USE_UTF8_SCRIPTS |
41 | # define UTF (!IN_BYTES) | |
2b9d42f0 | 42 | #else |
746b446a | 43 | # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8)) |
2b9d42f0 | 44 | #endif |
a0ed51b3 | 45 | |
61f0cdd9 | 46 | /* In variables named $^X, these are the legal values for X. |
2b92dfce GS |
47 | * 1999-02-27 mjd-perl-patch@plover.com */ |
48 | #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x))) | |
49 | ||
bf4acbe4 GS |
50 | /* On MacOS, respect nonbreaking spaces */ |
51 | #ifdef MACOS_TRADITIONAL | |
52 | #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t') | |
53 | #else | |
54 | #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t') | |
55 | #endif | |
56 | ||
ffb4593c NT |
57 | /* LEX_* are values for PL_lex_state, the state of the lexer. |
58 | * They are arranged oddly so that the guard on the switch statement | |
79072805 LW |
59 | * can get by with a single comparison (if the compiler is smart enough). |
60 | */ | |
61 | ||
fb73857a | 62 | /* #define LEX_NOTPARSING 11 is done in perl.h. */ |
63 | ||
b6007c36 DM |
64 | #define LEX_NORMAL 10 /* normal code (ie not within "...") */ |
65 | #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */ | |
66 | #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */ | |
67 | #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */ | |
68 | #define LEX_INTERPSTART 6 /* expecting the start of a $var */ | |
69 | ||
70 | /* at end of code, eg "$x" followed by: */ | |
71 | #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */ | |
72 | #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */ | |
73 | ||
74 | #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of | |
75 | string or after \E, $foo, etc */ | |
76 | #define LEX_INTERPCONST 2 /* NOT USED */ | |
77 | #define LEX_FORMLINE 1 /* expecting a format line */ | |
78 | #define LEX_KNOWNEXT 0 /* next token known; just return it */ | |
79 | ||
79072805 | 80 | |
bbf60fe6 | 81 | #ifdef DEBUGGING |
27da23d5 | 82 | static const char* const lex_state_names[] = { |
bbf60fe6 DM |
83 | "KNOWNEXT", |
84 | "FORMLINE", | |
85 | "INTERPCONST", | |
86 | "INTERPCONCAT", | |
87 | "INTERPENDMAYBE", | |
88 | "INTERPEND", | |
89 | "INTERPSTART", | |
90 | "INTERPPUSH", | |
91 | "INTERPCASEMOD", | |
92 | "INTERPNORMAL", | |
93 | "NORMAL" | |
94 | }; | |
95 | #endif | |
96 | ||
79072805 LW |
97 | #ifdef ff_next |
98 | #undef ff_next | |
d48672a2 LW |
99 | #endif |
100 | ||
79072805 | 101 | #include "keywords.h" |
fe14fcc3 | 102 | |
ffb4593c NT |
103 | /* CLINE is a macro that ensures PL_copline has a sane value */ |
104 | ||
ae986130 LW |
105 | #ifdef CLINE |
106 | #undef CLINE | |
107 | #endif | |
57843af0 | 108 | #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline)) |
3280af22 | 109 | |
ffb4593c NT |
110 | /* |
111 | * Convenience functions to return different tokens and prime the | |
9cbb5ea2 | 112 | * lexer for the next token. They all take an argument. |
ffb4593c NT |
113 | * |
114 | * TOKEN : generic token (used for '(', DOLSHARP, etc) | |
115 | * OPERATOR : generic operator | |
116 | * AOPERATOR : assignment operator | |
117 | * PREBLOCK : beginning the block after an if, while, foreach, ... | |
118 | * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref) | |
119 | * PREREF : *EXPR where EXPR is not a simple identifier | |
120 | * TERM : expression term | |
121 | * LOOPX : loop exiting command (goto, last, dump, etc) | |
122 | * FTST : file test operator | |
123 | * FUN0 : zero-argument function | |
2d2e263d | 124 | * FUN1 : not used, except for not, which isn't a UNIOP |
ffb4593c NT |
125 | * BOop : bitwise or or xor |
126 | * BAop : bitwise and | |
127 | * SHop : shift operator | |
128 | * PWop : power operator | |
9cbb5ea2 | 129 | * PMop : pattern-matching operator |
ffb4593c NT |
130 | * Aop : addition-level operator |
131 | * Mop : multiplication-level operator | |
132 | * Eop : equality-testing operator | |
e5edeb50 | 133 | * Rop : relational operator <= != gt |
ffb4593c NT |
134 | * |
135 | * Also see LOP and lop() below. | |
136 | */ | |
137 | ||
998054bd | 138 | #ifdef DEBUGGING /* Serve -DT. */ |
f5bd084c | 139 | # define REPORT(retval) tokereport((I32)retval) |
998054bd | 140 | #else |
bbf60fe6 | 141 | # define REPORT(retval) (retval) |
998054bd SC |
142 | #endif |
143 | ||
bbf60fe6 DM |
144 | #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval)) |
145 | #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval)) | |
146 | #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval))) | |
147 | #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval)) | |
148 | #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval)) | |
149 | #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval)) | |
150 | #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval)) | |
151 | #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX)) | |
152 | #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP)) | |
153 | #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0)) | |
154 | #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1)) | |
155 | #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP))) | |
156 | #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP))) | |
157 | #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP))) | |
158 | #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP))) | |
159 | #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP)) | |
160 | #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP))) | |
161 | #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP))) | |
162 | #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP)) | |
163 | #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP)) | |
2f3197b3 | 164 | |
a687059c LW |
165 | /* This bit of chicanery makes a unary function followed by |
166 | * a parenthesis into a function with one argument, highest precedence. | |
6f33ba73 RGS |
167 | * The UNIDOR macro is for unary functions that can be followed by the // |
168 | * operator (such as C<shift // 0>). | |
a687059c | 169 | */ |
376fcdbf AL |
170 | #define UNI2(f,x) { \ |
171 | yylval.ival = f; \ | |
172 | PL_expect = x; \ | |
173 | PL_bufptr = s; \ | |
174 | PL_last_uni = PL_oldbufptr; \ | |
175 | PL_last_lop_op = f; \ | |
176 | if (*s == '(') \ | |
177 | return REPORT( (int)FUNC1 ); \ | |
178 | s = skipspace(s); \ | |
179 | return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \ | |
180 | } | |
6f33ba73 RGS |
181 | #define UNI(f) UNI2(f,XTERM) |
182 | #define UNIDOR(f) UNI2(f,XTERMORDORDOR) | |
a687059c | 183 | |
376fcdbf AL |
184 | #define UNIBRACK(f) { \ |
185 | yylval.ival = f; \ | |
186 | PL_bufptr = s; \ | |
187 | PL_last_uni = PL_oldbufptr; \ | |
188 | if (*s == '(') \ | |
189 | return REPORT( (int)FUNC1 ); \ | |
190 | s = skipspace(s); \ | |
191 | return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \ | |
192 | } | |
79072805 | 193 | |
9f68db38 | 194 | /* grandfather return to old style */ |
3280af22 | 195 | #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP) |
79072805 | 196 | |
8fa7f367 JH |
197 | #ifdef DEBUGGING |
198 | ||
bbf60fe6 DM |
199 | /* how to interpret the yylval associated with the token */ |
200 | enum token_type { | |
201 | TOKENTYPE_NONE, | |
202 | TOKENTYPE_IVAL, | |
203 | TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */ | |
204 | TOKENTYPE_PVAL, | |
205 | TOKENTYPE_OPVAL, | |
206 | TOKENTYPE_GVVAL | |
207 | }; | |
208 | ||
27da23d5 JH |
209 | static struct debug_tokens { const int token, type; const char *name; } |
210 | const debug_tokens[] = | |
9041c2e3 | 211 | { |
bbf60fe6 DM |
212 | { ADDOP, TOKENTYPE_OPNUM, "ADDOP" }, |
213 | { ANDAND, TOKENTYPE_NONE, "ANDAND" }, | |
214 | { ANDOP, TOKENTYPE_NONE, "ANDOP" }, | |
215 | { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" }, | |
216 | { ARROW, TOKENTYPE_NONE, "ARROW" }, | |
217 | { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" }, | |
218 | { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" }, | |
219 | { BITOROP, TOKENTYPE_OPNUM, "BITOROP" }, | |
220 | { COLONATTR, TOKENTYPE_NONE, "COLONATTR" }, | |
221 | { CONTINUE, TOKENTYPE_NONE, "CONTINUE" }, | |
222 | { DO, TOKENTYPE_NONE, "DO" }, | |
223 | { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" }, | |
224 | { DORDOR, TOKENTYPE_NONE, "DORDOR" }, | |
225 | { DOROP, TOKENTYPE_OPNUM, "DOROP" }, | |
226 | { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" }, | |
227 | { ELSE, TOKENTYPE_NONE, "ELSE" }, | |
228 | { ELSIF, TOKENTYPE_IVAL, "ELSIF" }, | |
229 | { EQOP, TOKENTYPE_OPNUM, "EQOP" }, | |
230 | { FOR, TOKENTYPE_IVAL, "FOR" }, | |
231 | { FORMAT, TOKENTYPE_NONE, "FORMAT" }, | |
232 | { FUNC, TOKENTYPE_OPNUM, "FUNC" }, | |
233 | { FUNC0, TOKENTYPE_OPNUM, "FUNC0" }, | |
234 | { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" }, | |
235 | { FUNC1, TOKENTYPE_OPNUM, "FUNC1" }, | |
236 | { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" }, | |
237 | { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" }, | |
238 | { IF, TOKENTYPE_IVAL, "IF" }, | |
239 | { LABEL, TOKENTYPE_PVAL, "LABEL" }, | |
240 | { LOCAL, TOKENTYPE_IVAL, "LOCAL" }, | |
241 | { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" }, | |
242 | { LSTOP, TOKENTYPE_OPNUM, "LSTOP" }, | |
243 | { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" }, | |
244 | { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" }, | |
245 | { METHOD, TOKENTYPE_OPVAL, "METHOD" }, | |
246 | { MULOP, TOKENTYPE_OPNUM, "MULOP" }, | |
247 | { MY, TOKENTYPE_IVAL, "MY" }, | |
248 | { MYSUB, TOKENTYPE_NONE, "MYSUB" }, | |
249 | { NOAMP, TOKENTYPE_NONE, "NOAMP" }, | |
250 | { NOTOP, TOKENTYPE_NONE, "NOTOP" }, | |
251 | { OROP, TOKENTYPE_IVAL, "OROP" }, | |
252 | { OROR, TOKENTYPE_NONE, "OROR" }, | |
253 | { PACKAGE, TOKENTYPE_NONE, "PACKAGE" }, | |
254 | { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" }, | |
255 | { POSTDEC, TOKENTYPE_NONE, "POSTDEC" }, | |
256 | { POSTINC, TOKENTYPE_NONE, "POSTINC" }, | |
257 | { POWOP, TOKENTYPE_OPNUM, "POWOP" }, | |
258 | { PREDEC, TOKENTYPE_NONE, "PREDEC" }, | |
259 | { PREINC, TOKENTYPE_NONE, "PREINC" }, | |
260 | { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" }, | |
261 | { REFGEN, TOKENTYPE_NONE, "REFGEN" }, | |
262 | { RELOP, TOKENTYPE_OPNUM, "RELOP" }, | |
263 | { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" }, | |
264 | { SUB, TOKENTYPE_NONE, "SUB" }, | |
265 | { THING, TOKENTYPE_OPVAL, "THING" }, | |
266 | { UMINUS, TOKENTYPE_NONE, "UMINUS" }, | |
267 | { UNIOP, TOKENTYPE_OPNUM, "UNIOP" }, | |
268 | { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" }, | |
269 | { UNLESS, TOKENTYPE_IVAL, "UNLESS" }, | |
270 | { UNTIL, TOKENTYPE_IVAL, "UNTIL" }, | |
271 | { USE, TOKENTYPE_IVAL, "USE" }, | |
272 | { WHILE, TOKENTYPE_IVAL, "WHILE" }, | |
273 | { WORD, TOKENTYPE_OPVAL, "WORD" }, | |
274 | { 0, TOKENTYPE_NONE, 0 } | |
275 | }; | |
276 | ||
277 | /* dump the returned token in rv, plus any optional arg in yylval */ | |
998054bd | 278 | |
bbf60fe6 | 279 | STATIC int |
f5bd084c | 280 | S_tokereport(pTHX_ I32 rv) |
bbf60fe6 DM |
281 | { |
282 | if (DEBUG_T_TEST) { | |
bfed75c6 | 283 | const char *name = Nullch; |
bbf60fe6 | 284 | enum token_type type = TOKENTYPE_NONE; |
f54cb97a | 285 | const struct debug_tokens *p; |
9d4ba2ae | 286 | SV* const report = newSVpvn("<== ", 4); |
bbf60fe6 | 287 | |
f54cb97a | 288 | for (p = debug_tokens; p->token; p++) { |
bbf60fe6 DM |
289 | if (p->token == (int)rv) { |
290 | name = p->name; | |
291 | type = p->type; | |
292 | break; | |
293 | } | |
294 | } | |
295 | if (name) | |
54667de8 | 296 | Perl_sv_catpv(aTHX_ report, name); |
bbf60fe6 DM |
297 | else if ((char)rv > ' ' && (char)rv < '~') |
298 | Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv); | |
299 | else if (!rv) | |
54667de8 | 300 | Perl_sv_catpv(aTHX_ report, "EOF"); |
bbf60fe6 DM |
301 | else |
302 | Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv); | |
303 | switch (type) { | |
304 | case TOKENTYPE_NONE: | |
305 | case TOKENTYPE_GVVAL: /* doesn't appear to be used */ | |
306 | break; | |
307 | case TOKENTYPE_IVAL: | |
e4584336 | 308 | Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival); |
bbf60fe6 DM |
309 | break; |
310 | case TOKENTYPE_OPNUM: | |
311 | Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)", | |
312 | PL_op_name[yylval.ival]); | |
313 | break; | |
314 | case TOKENTYPE_PVAL: | |
315 | Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval); | |
316 | break; | |
317 | case TOKENTYPE_OPVAL: | |
b6007c36 | 318 | if (yylval.opval) { |
401441c0 | 319 | Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)", |
bbf60fe6 | 320 | PL_op_name[yylval.opval->op_type]); |
b6007c36 DM |
321 | if (yylval.opval->op_type == OP_CONST) { |
322 | Perl_sv_catpvf(aTHX_ report, " %s", | |
323 | SvPEEK(cSVOPx_sv(yylval.opval))); | |
324 | } | |
325 | ||
326 | } | |
401441c0 RGS |
327 | else |
328 | Perl_sv_catpv(aTHX_ report, "(opval=null)"); | |
bbf60fe6 DM |
329 | break; |
330 | } | |
b6007c36 | 331 | PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report)); |
bbf60fe6 DM |
332 | }; |
333 | return (int)rv; | |
998054bd SC |
334 | } |
335 | ||
b6007c36 DM |
336 | |
337 | /* print the buffer with suitable escapes */ | |
338 | ||
339 | STATIC void | |
340 | S_printbuf(pTHX_ const char* fmt, const char* s) | |
341 | { | |
c4420975 | 342 | SV* const tmp = newSVpvn("", 0); |
b6007c36 DM |
343 | PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60)); |
344 | SvREFCNT_dec(tmp); | |
345 | } | |
346 | ||
8fa7f367 JH |
347 | #endif |
348 | ||
ffb4593c NT |
349 | /* |
350 | * S_ao | |
351 | * | |
c963b151 BD |
352 | * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR |
353 | * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN | |
ffb4593c NT |
354 | */ |
355 | ||
76e3520e | 356 | STATIC int |
cea2e8a9 | 357 | S_ao(pTHX_ int toketype) |
a0d0e21e | 358 | { |
3280af22 NIS |
359 | if (*PL_bufptr == '=') { |
360 | PL_bufptr++; | |
a0d0e21e LW |
361 | if (toketype == ANDAND) |
362 | yylval.ival = OP_ANDASSIGN; | |
363 | else if (toketype == OROR) | |
364 | yylval.ival = OP_ORASSIGN; | |
c963b151 BD |
365 | else if (toketype == DORDOR) |
366 | yylval.ival = OP_DORASSIGN; | |
a0d0e21e LW |
367 | toketype = ASSIGNOP; |
368 | } | |
369 | return toketype; | |
370 | } | |
371 | ||
ffb4593c NT |
372 | /* |
373 | * S_no_op | |
374 | * When Perl expects an operator and finds something else, no_op | |
375 | * prints the warning. It always prints "<something> found where | |
376 | * operator expected. It prints "Missing semicolon on previous line?" | |
377 | * if the surprise occurs at the start of the line. "do you need to | |
378 | * predeclare ..." is printed out for code like "sub bar; foo bar $x" | |
379 | * where the compiler doesn't know if foo is a method call or a function. | |
380 | * It prints "Missing operator before end of line" if there's nothing | |
381 | * after the missing operator, or "... before <...>" if there is something | |
382 | * after the missing operator. | |
383 | */ | |
384 | ||
76e3520e | 385 | STATIC void |
bfed75c6 | 386 | S_no_op(pTHX_ const char *what, char *s) |
463ee0b2 | 387 | { |
9d4ba2ae AL |
388 | char * const oldbp = PL_bufptr; |
389 | const bool is_first = (PL_oldbufptr == PL_linestart); | |
68dc0745 | 390 | |
1189a94a GS |
391 | if (!s) |
392 | s = oldbp; | |
07c798fb | 393 | else |
1189a94a | 394 | PL_bufptr = s; |
cea2e8a9 | 395 | yywarn(Perl_form(aTHX_ "%s found where operator expected", what)); |
56da5a46 RGS |
396 | if (ckWARN_d(WARN_SYNTAX)) { |
397 | if (is_first) | |
398 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
399 | "\t(Missing semicolon on previous line?)\n"); | |
400 | else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) { | |
f54cb97a | 401 | const char *t; |
56da5a46 RGS |
402 | for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ; |
403 | if (t < PL_bufptr && isSPACE(*t)) | |
404 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
405 | "\t(Do you need to predeclare %.*s?)\n", | |
551405c4 | 406 | (int)(t - PL_oldoldbufptr), PL_oldoldbufptr); |
56da5a46 RGS |
407 | } |
408 | else { | |
409 | assert(s >= oldbp); | |
410 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
551405c4 | 411 | "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp); |
56da5a46 | 412 | } |
07c798fb | 413 | } |
3280af22 | 414 | PL_bufptr = oldbp; |
8990e307 LW |
415 | } |
416 | ||
ffb4593c NT |
417 | /* |
418 | * S_missingterm | |
419 | * Complain about missing quote/regexp/heredoc terminator. | |
420 | * If it's called with (char *)NULL then it cauterizes the line buffer. | |
421 | * If we're in a delimited string and the delimiter is a control | |
422 | * character, it's reformatted into a two-char sequence like ^C. | |
423 | * This is fatal. | |
424 | */ | |
425 | ||
76e3520e | 426 | STATIC void |
cea2e8a9 | 427 | S_missingterm(pTHX_ char *s) |
8990e307 LW |
428 | { |
429 | char tmpbuf[3]; | |
430 | char q; | |
431 | if (s) { | |
9d4ba2ae | 432 | char * const nl = strrchr(s,'\n'); |
d2719217 | 433 | if (nl) |
8990e307 LW |
434 | *nl = '\0'; |
435 | } | |
9d116dd7 JH |
436 | else if ( |
437 | #ifdef EBCDIC | |
438 | iscntrl(PL_multi_close) | |
439 | #else | |
440 | PL_multi_close < 32 || PL_multi_close == 127 | |
441 | #endif | |
442 | ) { | |
8990e307 | 443 | *tmpbuf = '^'; |
585ec06d | 444 | tmpbuf[1] = (char)toCTRL(PL_multi_close); |
8990e307 LW |
445 | tmpbuf[2] = '\0'; |
446 | s = tmpbuf; | |
447 | } | |
448 | else { | |
eb160463 | 449 | *tmpbuf = (char)PL_multi_close; |
8990e307 LW |
450 | tmpbuf[1] = '\0'; |
451 | s = tmpbuf; | |
452 | } | |
453 | q = strchr(s,'"') ? '\'' : '"'; | |
cea2e8a9 | 454 | Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q); |
463ee0b2 | 455 | } |
79072805 | 456 | |
ffb4593c NT |
457 | /* |
458 | * Perl_deprecate | |
ffb4593c NT |
459 | */ |
460 | ||
79072805 | 461 | void |
bfed75c6 | 462 | Perl_deprecate(pTHX_ const char *s) |
a0d0e21e | 463 | { |
599cee73 | 464 | if (ckWARN(WARN_DEPRECATED)) |
9014280d | 465 | Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s); |
a0d0e21e LW |
466 | } |
467 | ||
12bcd1a6 | 468 | void |
bfed75c6 | 469 | Perl_deprecate_old(pTHX_ const char *s) |
12bcd1a6 PM |
470 | { |
471 | /* This function should NOT be called for any new deprecated warnings */ | |
472 | /* Use Perl_deprecate instead */ | |
473 | /* */ | |
474 | /* It is here to maintain backward compatibility with the pre-5.8 */ | |
475 | /* warnings category hierarchy. The "deprecated" category used to */ | |
476 | /* live under the "syntax" category. It is now a top-level category */ | |
477 | /* in its own right. */ | |
478 | ||
479 | if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX)) | |
bfed75c6 | 480 | Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX), |
12bcd1a6 PM |
481 | "Use of %s is deprecated", s); |
482 | } | |
483 | ||
ffb4593c NT |
484 | /* |
485 | * depcom | |
9cbb5ea2 | 486 | * Deprecate a comma-less variable list. |
ffb4593c NT |
487 | */ |
488 | ||
76e3520e | 489 | STATIC void |
cea2e8a9 | 490 | S_depcom(pTHX) |
a0d0e21e | 491 | { |
12bcd1a6 | 492 | deprecate_old("comma-less variable list"); |
a0d0e21e LW |
493 | } |
494 | ||
ffb4593c | 495 | /* |
9cbb5ea2 GS |
496 | * experimental text filters for win32 carriage-returns, utf16-to-utf8 and |
497 | * utf16-to-utf8-reversed. | |
ffb4593c NT |
498 | */ |
499 | ||
c39cd008 GS |
500 | #ifdef PERL_CR_FILTER |
501 | static void | |
502 | strip_return(SV *sv) | |
503 | { | |
95a20fc0 | 504 | register const char *s = SvPVX_const(sv); |
9d4ba2ae | 505 | register const char * const e = s + SvCUR(sv); |
c39cd008 GS |
506 | /* outer loop optimized to do nothing if there are no CR-LFs */ |
507 | while (s < e) { | |
508 | if (*s++ == '\r' && *s == '\n') { | |
509 | /* hit a CR-LF, need to copy the rest */ | |
510 | register char *d = s - 1; | |
511 | *d++ = *s++; | |
512 | while (s < e) { | |
513 | if (*s == '\r' && s[1] == '\n') | |
514 | s++; | |
515 | *d++ = *s++; | |
516 | } | |
517 | SvCUR(sv) -= s - d; | |
518 | return; | |
519 | } | |
520 | } | |
521 | } | |
a868473f | 522 | |
76e3520e | 523 | STATIC I32 |
c39cd008 | 524 | S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
a868473f | 525 | { |
f54cb97a | 526 | const I32 count = FILTER_READ(idx+1, sv, maxlen); |
c39cd008 GS |
527 | if (count > 0 && !maxlen) |
528 | strip_return(sv); | |
529 | return count; | |
a868473f NIS |
530 | } |
531 | #endif | |
532 | ||
ffb4593c NT |
533 | /* |
534 | * Perl_lex_start | |
9cbb5ea2 GS |
535 | * Initialize variables. Uses the Perl save_stack to save its state (for |
536 | * recursive calls to the parser). | |
ffb4593c NT |
537 | */ |
538 | ||
a0d0e21e | 539 | void |
864dbfa3 | 540 | Perl_lex_start(pTHX_ SV *line) |
79072805 | 541 | { |
cfd0369c | 542 | const char *s; |
8990e307 LW |
543 | STRLEN len; |
544 | ||
3280af22 NIS |
545 | SAVEI32(PL_lex_dojoin); |
546 | SAVEI32(PL_lex_brackets); | |
3280af22 NIS |
547 | SAVEI32(PL_lex_casemods); |
548 | SAVEI32(PL_lex_starts); | |
549 | SAVEI32(PL_lex_state); | |
7766f137 | 550 | SAVEVPTR(PL_lex_inpat); |
3280af22 | 551 | SAVEI32(PL_lex_inwhat); |
18b09519 GS |
552 | if (PL_lex_state == LEX_KNOWNEXT) { |
553 | I32 toke = PL_nexttoke; | |
554 | while (--toke >= 0) { | |
555 | SAVEI32(PL_nexttype[toke]); | |
556 | SAVEVPTR(PL_nextval[toke]); | |
557 | } | |
558 | SAVEI32(PL_nexttoke); | |
18b09519 | 559 | } |
57843af0 | 560 | SAVECOPLINE(PL_curcop); |
3280af22 NIS |
561 | SAVEPPTR(PL_bufptr); |
562 | SAVEPPTR(PL_bufend); | |
563 | SAVEPPTR(PL_oldbufptr); | |
564 | SAVEPPTR(PL_oldoldbufptr); | |
207e3d1a JH |
565 | SAVEPPTR(PL_last_lop); |
566 | SAVEPPTR(PL_last_uni); | |
3280af22 NIS |
567 | SAVEPPTR(PL_linestart); |
568 | SAVESPTR(PL_linestr); | |
8edd5f42 RGS |
569 | SAVEGENERICPV(PL_lex_brackstack); |
570 | SAVEGENERICPV(PL_lex_casestack); | |
c76ac1ee | 571 | SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp); |
3280af22 NIS |
572 | SAVESPTR(PL_lex_stuff); |
573 | SAVEI32(PL_lex_defer); | |
09bef843 | 574 | SAVEI32(PL_sublex_info.sub_inwhat); |
3280af22 | 575 | SAVESPTR(PL_lex_repl); |
bebdddfc GS |
576 | SAVEINT(PL_expect); |
577 | SAVEINT(PL_lex_expect); | |
3280af22 NIS |
578 | |
579 | PL_lex_state = LEX_NORMAL; | |
580 | PL_lex_defer = 0; | |
581 | PL_expect = XSTATE; | |
582 | PL_lex_brackets = 0; | |
a02a5408 JC |
583 | Newx(PL_lex_brackstack, 120, char); |
584 | Newx(PL_lex_casestack, 12, char); | |
3280af22 NIS |
585 | PL_lex_casemods = 0; |
586 | *PL_lex_casestack = '\0'; | |
587 | PL_lex_dojoin = 0; | |
588 | PL_lex_starts = 0; | |
589 | PL_lex_stuff = Nullsv; | |
590 | PL_lex_repl = Nullsv; | |
591 | PL_lex_inpat = 0; | |
76be56bc | 592 | PL_nexttoke = 0; |
3280af22 | 593 | PL_lex_inwhat = 0; |
09bef843 | 594 | PL_sublex_info.sub_inwhat = 0; |
3280af22 NIS |
595 | PL_linestr = line; |
596 | if (SvREADONLY(PL_linestr)) | |
597 | PL_linestr = sv_2mortal(newSVsv(PL_linestr)); | |
cfd0369c | 598 | s = SvPV_const(PL_linestr, len); |
6f27f9a7 | 599 | if (!len || s[len-1] != ';') { |
3280af22 NIS |
600 | if (!(SvFLAGS(PL_linestr) & SVs_TEMP)) |
601 | PL_linestr = sv_2mortal(newSVsv(PL_linestr)); | |
602 | sv_catpvn(PL_linestr, "\n;", 2); | |
8990e307 | 603 | } |
3280af22 NIS |
604 | SvTEMP_off(PL_linestr); |
605 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr); | |
606 | PL_bufend = PL_bufptr + SvCUR(PL_linestr); | |
207e3d1a | 607 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 608 | PL_rsfp = 0; |
79072805 | 609 | } |
a687059c | 610 | |
ffb4593c NT |
611 | /* |
612 | * Perl_lex_end | |
9cbb5ea2 GS |
613 | * Finalizer for lexing operations. Must be called when the parser is |
614 | * done with the lexer. | |
ffb4593c NT |
615 | */ |
616 | ||
463ee0b2 | 617 | void |
864dbfa3 | 618 | Perl_lex_end(pTHX) |
463ee0b2 | 619 | { |
3280af22 | 620 | PL_doextract = FALSE; |
463ee0b2 LW |
621 | } |
622 | ||
ffb4593c NT |
623 | /* |
624 | * S_incline | |
625 | * This subroutine has nothing to do with tilting, whether at windmills | |
626 | * or pinball tables. Its name is short for "increment line". It | |
57843af0 | 627 | * increments the current line number in CopLINE(PL_curcop) and checks |
ffb4593c | 628 | * to see whether the line starts with a comment of the form |
9cbb5ea2 GS |
629 | * # line 500 "foo.pm" |
630 | * If so, it sets the current line number and file to the values in the comment. | |
ffb4593c NT |
631 | */ |
632 | ||
76e3520e | 633 | STATIC void |
cea2e8a9 | 634 | S_incline(pTHX_ char *s) |
463ee0b2 LW |
635 | { |
636 | char *t; | |
637 | char *n; | |
73659bf1 | 638 | char *e; |
463ee0b2 | 639 | char ch; |
463ee0b2 | 640 | |
57843af0 | 641 | CopLINE_inc(PL_curcop); |
463ee0b2 LW |
642 | if (*s++ != '#') |
643 | return; | |
bf4acbe4 | 644 | while (SPACE_OR_TAB(*s)) s++; |
73659bf1 GS |
645 | if (strnEQ(s, "line", 4)) |
646 | s += 4; | |
647 | else | |
648 | return; | |
084592ab | 649 | if (SPACE_OR_TAB(*s)) |
73659bf1 | 650 | s++; |
4e553d73 | 651 | else |
73659bf1 | 652 | return; |
bf4acbe4 | 653 | while (SPACE_OR_TAB(*s)) s++; |
463ee0b2 LW |
654 | if (!isDIGIT(*s)) |
655 | return; | |
656 | n = s; | |
657 | while (isDIGIT(*s)) | |
658 | s++; | |
bf4acbe4 | 659 | while (SPACE_OR_TAB(*s)) |
463ee0b2 | 660 | s++; |
73659bf1 | 661 | if (*s == '"' && (t = strchr(s+1, '"'))) { |
463ee0b2 | 662 | s++; |
73659bf1 GS |
663 | e = t + 1; |
664 | } | |
463ee0b2 | 665 | else { |
463ee0b2 | 666 | for (t = s; !isSPACE(*t); t++) ; |
73659bf1 | 667 | e = t; |
463ee0b2 | 668 | } |
bf4acbe4 | 669 | while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f') |
73659bf1 GS |
670 | e++; |
671 | if (*e != '\n' && *e != '\0') | |
672 | return; /* false alarm */ | |
673 | ||
463ee0b2 LW |
674 | ch = *t; |
675 | *t = '\0'; | |
f4dd75d9 | 676 | if (t - s > 0) { |
8a5ee598 | 677 | #ifndef USE_ITHREADS |
c4420975 | 678 | const char * const cf = CopFILE(PL_curcop); |
42d9b98d NC |
679 | STRLEN tmplen = cf ? strlen(cf) : 0; |
680 | if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) { | |
e66cf94c RGS |
681 | /* must copy *{"::_<(eval N)[oldfilename:L]"} |
682 | * to *{"::_<newfilename"} */ | |
683 | char smallbuf[256], smallbuf2[256]; | |
684 | char *tmpbuf, *tmpbuf2; | |
8a5ee598 | 685 | GV **gvp, *gv2; |
e66cf94c RGS |
686 | STRLEN tmplen2 = strlen(s); |
687 | if (tmplen + 3 < sizeof smallbuf) | |
688 | tmpbuf = smallbuf; | |
689 | else | |
690 | Newx(tmpbuf, tmplen + 3, char); | |
691 | if (tmplen2 + 3 < sizeof smallbuf2) | |
692 | tmpbuf2 = smallbuf2; | |
693 | else | |
694 | Newx(tmpbuf2, tmplen2 + 3, char); | |
695 | tmpbuf[0] = tmpbuf2[0] = '_'; | |
696 | tmpbuf[1] = tmpbuf2[1] = '<'; | |
697 | memcpy(tmpbuf + 2, cf, ++tmplen); | |
698 | memcpy(tmpbuf2 + 2, s, ++tmplen2); | |
699 | ++tmplen; ++tmplen2; | |
8a5ee598 RGS |
700 | gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE); |
701 | if (gvp) { | |
702 | gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE); | |
703 | if (!isGV(gv2)) | |
704 | gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE); | |
705 | /* adjust ${"::_<newfilename"} to store the new file name */ | |
706 | GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2); | |
707 | GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp)); | |
708 | GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp)); | |
709 | } | |
e66cf94c RGS |
710 | if (tmpbuf != smallbuf) Safefree(tmpbuf); |
711 | if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2); | |
712 | } | |
8a5ee598 | 713 | #endif |
05ec9bb3 | 714 | CopFILE_free(PL_curcop); |
57843af0 | 715 | CopFILE_set(PL_curcop, s); |
f4dd75d9 | 716 | } |
463ee0b2 | 717 | *t = ch; |
57843af0 | 718 | CopLINE_set(PL_curcop, atoi(n)-1); |
463ee0b2 LW |
719 | } |
720 | ||
ffb4593c NT |
721 | /* |
722 | * S_skipspace | |
723 | * Called to gobble the appropriate amount and type of whitespace. | |
724 | * Skips comments as well. | |
725 | */ | |
726 | ||
76e3520e | 727 | STATIC char * |
cea2e8a9 | 728 | S_skipspace(pTHX_ register char *s) |
a687059c | 729 | { |
3280af22 | 730 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
bf4acbe4 | 731 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
463ee0b2 LW |
732 | s++; |
733 | return s; | |
734 | } | |
735 | for (;;) { | |
fd049845 | 736 | STRLEN prevlen; |
09bef843 | 737 | SSize_t oldprevlen, oldoldprevlen; |
9c5ffd7c | 738 | SSize_t oldloplen = 0, oldunilen = 0; |
60e6418e GS |
739 | while (s < PL_bufend && isSPACE(*s)) { |
740 | if (*s++ == '\n' && PL_in_eval && !PL_rsfp) | |
741 | incline(s); | |
742 | } | |
ffb4593c NT |
743 | |
744 | /* comment */ | |
3280af22 NIS |
745 | if (s < PL_bufend && *s == '#') { |
746 | while (s < PL_bufend && *s != '\n') | |
463ee0b2 | 747 | s++; |
60e6418e | 748 | if (s < PL_bufend) { |
463ee0b2 | 749 | s++; |
60e6418e GS |
750 | if (PL_in_eval && !PL_rsfp) { |
751 | incline(s); | |
752 | continue; | |
753 | } | |
754 | } | |
463ee0b2 | 755 | } |
ffb4593c NT |
756 | |
757 | /* only continue to recharge the buffer if we're at the end | |
758 | * of the buffer, we're not reading from a source filter, and | |
759 | * we're in normal lexing mode | |
760 | */ | |
09bef843 SB |
761 | if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat || |
762 | PL_lex_state == LEX_FORMLINE) | |
463ee0b2 | 763 | return s; |
ffb4593c NT |
764 | |
765 | /* try to recharge the buffer */ | |
9cbb5ea2 GS |
766 | if ((s = filter_gets(PL_linestr, PL_rsfp, |
767 | (prevlen = SvCUR(PL_linestr)))) == Nullch) | |
768 | { | |
769 | /* end of file. Add on the -p or -n magic */ | |
01a19ab0 NC |
770 | if (PL_minus_p) { |
771 | sv_setpv(PL_linestr, | |
772 | ";}continue{print or die qq(-p destination: $!\\n);}"); | |
3280af22 | 773 | PL_minus_n = PL_minus_p = 0; |
a0d0e21e | 774 | } |
01a19ab0 NC |
775 | else if (PL_minus_n) { |
776 | sv_setpvn(PL_linestr, ";}", 2); | |
777 | PL_minus_n = 0; | |
778 | } | |
a0d0e21e | 779 | else |
4147a61b | 780 | sv_setpvn(PL_linestr,";", 1); |
ffb4593c NT |
781 | |
782 | /* reset variables for next time we lex */ | |
9cbb5ea2 GS |
783 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart |
784 | = SvPVX(PL_linestr); | |
3280af22 | 785 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 786 | PL_last_lop = PL_last_uni = Nullch; |
ffb4593c NT |
787 | |
788 | /* Close the filehandle. Could be from -P preprocessor, | |
789 | * STDIN, or a regular file. If we were reading code from | |
790 | * STDIN (because the commandline held no -e or filename) | |
791 | * then we don't close it, we reset it so the code can | |
792 | * read from STDIN too. | |
793 | */ | |
794 | ||
3280af22 NIS |
795 | if (PL_preprocess && !PL_in_eval) |
796 | (void)PerlProc_pclose(PL_rsfp); | |
797 | else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) | |
798 | PerlIO_clearerr(PL_rsfp); | |
8990e307 | 799 | else |
3280af22 NIS |
800 | (void)PerlIO_close(PL_rsfp); |
801 | PL_rsfp = Nullfp; | |
463ee0b2 LW |
802 | return s; |
803 | } | |
ffb4593c NT |
804 | |
805 | /* not at end of file, so we only read another line */ | |
09bef843 SB |
806 | /* make corresponding updates to old pointers, for yyerror() */ |
807 | oldprevlen = PL_oldbufptr - PL_bufend; | |
808 | oldoldprevlen = PL_oldoldbufptr - PL_bufend; | |
809 | if (PL_last_uni) | |
810 | oldunilen = PL_last_uni - PL_bufend; | |
811 | if (PL_last_lop) | |
812 | oldloplen = PL_last_lop - PL_bufend; | |
3280af22 NIS |
813 | PL_linestart = PL_bufptr = s + prevlen; |
814 | PL_bufend = s + SvCUR(PL_linestr); | |
815 | s = PL_bufptr; | |
09bef843 SB |
816 | PL_oldbufptr = s + oldprevlen; |
817 | PL_oldoldbufptr = s + oldoldprevlen; | |
818 | if (PL_last_uni) | |
819 | PL_last_uni = s + oldunilen; | |
820 | if (PL_last_lop) | |
821 | PL_last_lop = s + oldloplen; | |
a0d0e21e | 822 | incline(s); |
ffb4593c NT |
823 | |
824 | /* debugger active and we're not compiling the debugger code, | |
825 | * so store the line into the debugger's array of lines | |
826 | */ | |
3280af22 | 827 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
9d4ba2ae | 828 | SV * const sv = NEWSV(85,0); |
8990e307 LW |
829 | |
830 | sv_upgrade(sv, SVt_PVMG); | |
3280af22 | 831 | sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr); |
0ac0412a | 832 | (void)SvIOK_on(sv); |
45977657 | 833 | SvIV_set(sv, 0); |
57843af0 | 834 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
8990e307 | 835 | } |
463ee0b2 | 836 | } |
a687059c | 837 | } |
378cc40b | 838 | |
ffb4593c NT |
839 | /* |
840 | * S_check_uni | |
841 | * Check the unary operators to ensure there's no ambiguity in how they're | |
842 | * used. An ambiguous piece of code would be: | |
843 | * rand + 5 | |
844 | * This doesn't mean rand() + 5. Because rand() is a unary operator, | |
845 | * the +5 is its argument. | |
846 | */ | |
847 | ||
76e3520e | 848 | STATIC void |
cea2e8a9 | 849 | S_check_uni(pTHX) |
ba106d47 | 850 | { |
2f3197b3 | 851 | char *s; |
a0d0e21e | 852 | char *t; |
2f3197b3 | 853 | |
3280af22 | 854 | if (PL_oldoldbufptr != PL_last_uni) |
2f3197b3 | 855 | return; |
3280af22 NIS |
856 | while (isSPACE(*PL_last_uni)) |
857 | PL_last_uni++; | |
7e2040f0 | 858 | for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ; |
3280af22 | 859 | if ((t = strchr(s, '(')) && t < PL_bufptr) |
a0d0e21e | 860 | return; |
0453d815 | 861 | if (ckWARN_d(WARN_AMBIGUOUS)){ |
9d4ba2ae | 862 | const char ch = *s; |
0453d815 | 863 | *s = '\0'; |
9014280d | 864 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
2d5ccbba | 865 | "Warning: Use of \"%s\" without parentheses is ambiguous", |
0453d815 PM |
866 | PL_last_uni); |
867 | *s = ch; | |
868 | } | |
2f3197b3 LW |
869 | } |
870 | ||
ffb4593c NT |
871 | /* |
872 | * LOP : macro to build a list operator. Its behaviour has been replaced | |
873 | * with a subroutine, S_lop() for which LOP is just another name. | |
874 | */ | |
875 | ||
a0d0e21e LW |
876 | #define LOP(f,x) return lop(f,x,s) |
877 | ||
ffb4593c NT |
878 | /* |
879 | * S_lop | |
880 | * Build a list operator (or something that might be one). The rules: | |
881 | * - if we have a next token, then it's a list operator [why?] | |
882 | * - if the next thing is an opening paren, then it's a function | |
883 | * - else it's a list operator | |
884 | */ | |
885 | ||
76e3520e | 886 | STATIC I32 |
a0be28da | 887 | S_lop(pTHX_ I32 f, int x, char *s) |
ffed7fef | 888 | { |
79072805 | 889 | yylval.ival = f; |
35c8bce7 | 890 | CLINE; |
3280af22 NIS |
891 | PL_expect = x; |
892 | PL_bufptr = s; | |
893 | PL_last_lop = PL_oldbufptr; | |
eb160463 | 894 | PL_last_lop_op = (OPCODE)f; |
3280af22 | 895 | if (PL_nexttoke) |
bbf60fe6 | 896 | return REPORT(LSTOP); |
79072805 | 897 | if (*s == '(') |
bbf60fe6 | 898 | return REPORT(FUNC); |
79072805 LW |
899 | s = skipspace(s); |
900 | if (*s == '(') | |
bbf60fe6 | 901 | return REPORT(FUNC); |
79072805 | 902 | else |
bbf60fe6 | 903 | return REPORT(LSTOP); |
79072805 LW |
904 | } |
905 | ||
ffb4593c NT |
906 | /* |
907 | * S_force_next | |
9cbb5ea2 | 908 | * When the lexer realizes it knows the next token (for instance, |
ffb4593c | 909 | * it is reordering tokens for the parser) then it can call S_force_next |
9cbb5ea2 GS |
910 | * to know what token to return the next time the lexer is called. Caller |
911 | * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer | |
912 | * handles the token correctly. | |
ffb4593c NT |
913 | */ |
914 | ||
4e553d73 | 915 | STATIC void |
cea2e8a9 | 916 | S_force_next(pTHX_ I32 type) |
79072805 | 917 | { |
3280af22 NIS |
918 | PL_nexttype[PL_nexttoke] = type; |
919 | PL_nexttoke++; | |
920 | if (PL_lex_state != LEX_KNOWNEXT) { | |
921 | PL_lex_defer = PL_lex_state; | |
922 | PL_lex_expect = PL_expect; | |
923 | PL_lex_state = LEX_KNOWNEXT; | |
79072805 LW |
924 | } |
925 | } | |
926 | ||
d0a148a6 NC |
927 | STATIC SV * |
928 | S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len) | |
929 | { | |
9d4ba2ae | 930 | SV * const sv = newSVpvn(start,len); |
bfed75c6 | 931 | if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len)) |
d0a148a6 NC |
932 | SvUTF8_on(sv); |
933 | return sv; | |
934 | } | |
935 | ||
ffb4593c NT |
936 | /* |
937 | * S_force_word | |
938 | * When the lexer knows the next thing is a word (for instance, it has | |
939 | * just seen -> and it knows that the next char is a word char, then | |
940 | * it calls S_force_word to stick the next word into the PL_next lookahead. | |
941 | * | |
942 | * Arguments: | |
b1b65b59 | 943 | * char *start : buffer position (must be within PL_linestr) |
ffb4593c NT |
944 | * int token : PL_next will be this type of bare word (e.g., METHOD,WORD) |
945 | * int check_keyword : if true, Perl checks to make sure the word isn't | |
946 | * a keyword (do this if the word is a label, e.g. goto FOO) | |
947 | * int allow_pack : if true, : characters will also be allowed (require, | |
948 | * use, etc. do this) | |
9cbb5ea2 | 949 | * int allow_initial_tick : used by the "sub" lexer only. |
ffb4593c NT |
950 | */ |
951 | ||
76e3520e | 952 | STATIC char * |
cea2e8a9 | 953 | S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick) |
79072805 | 954 | { |
463ee0b2 LW |
955 | register char *s; |
956 | STRLEN len; | |
4e553d73 | 957 | |
463ee0b2 LW |
958 | start = skipspace(start); |
959 | s = start; | |
7e2040f0 | 960 | if (isIDFIRST_lazy_if(s,UTF) || |
a0d0e21e | 961 | (allow_pack && *s == ':') || |
15f0808c | 962 | (allow_initial_tick && *s == '\'') ) |
a0d0e21e | 963 | { |
3280af22 NIS |
964 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len); |
965 | if (check_keyword && keyword(PL_tokenbuf, len)) | |
463ee0b2 LW |
966 | return start; |
967 | if (token == METHOD) { | |
968 | s = skipspace(s); | |
969 | if (*s == '(') | |
3280af22 | 970 | PL_expect = XTERM; |
463ee0b2 | 971 | else { |
3280af22 | 972 | PL_expect = XOPERATOR; |
463ee0b2 | 973 | } |
79072805 | 974 | } |
d0a148a6 NC |
975 | PL_nextval[PL_nexttoke].opval |
976 | = (OP*)newSVOP(OP_CONST,0, | |
977 | S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len)); | |
3280af22 | 978 | PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE; |
79072805 LW |
979 | force_next(token); |
980 | } | |
981 | return s; | |
982 | } | |
983 | ||
ffb4593c NT |
984 | /* |
985 | * S_force_ident | |
9cbb5ea2 | 986 | * Called when the lexer wants $foo *foo &foo etc, but the program |
ffb4593c NT |
987 | * text only contains the "foo" portion. The first argument is a pointer |
988 | * to the "foo", and the second argument is the type symbol to prefix. | |
989 | * Forces the next token to be a "WORD". | |
9cbb5ea2 | 990 | * Creates the symbol if it didn't already exist (via gv_fetchpv()). |
ffb4593c NT |
991 | */ |
992 | ||
76e3520e | 993 | STATIC void |
bfed75c6 | 994 | S_force_ident(pTHX_ register const char *s, int kind) |
79072805 LW |
995 | { |
996 | if (s && *s) { | |
bfed75c6 | 997 | OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0)); |
3280af22 | 998 | PL_nextval[PL_nexttoke].opval = o; |
79072805 | 999 | force_next(WORD); |
748a9306 | 1000 | if (kind) { |
11343788 | 1001 | o->op_private = OPpCONST_ENTERED; |
55497cff | 1002 | /* XXX see note in pp_entereval() for why we forgo typo |
1003 | warnings if the symbol must be introduced in an eval. | |
1004 | GSAR 96-10-12 */ | |
3280af22 | 1005 | gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE, |
a0d0e21e LW |
1006 | kind == '$' ? SVt_PV : |
1007 | kind == '@' ? SVt_PVAV : | |
1008 | kind == '%' ? SVt_PVHV : | |
1009 | SVt_PVGV | |
1010 | ); | |
748a9306 | 1011 | } |
79072805 LW |
1012 | } |
1013 | } | |
1014 | ||
1571675a GS |
1015 | NV |
1016 | Perl_str_to_version(pTHX_ SV *sv) | |
1017 | { | |
1018 | NV retval = 0.0; | |
1019 | NV nshift = 1.0; | |
1020 | STRLEN len; | |
cfd0369c | 1021 | const char *start = SvPV_const(sv,len); |
9d4ba2ae | 1022 | const char * const end = start + len; |
504618e9 | 1023 | const bool utf = SvUTF8(sv) ? TRUE : FALSE; |
1571675a | 1024 | while (start < end) { |
ba210ebe | 1025 | STRLEN skip; |
1571675a GS |
1026 | UV n; |
1027 | if (utf) | |
9041c2e3 | 1028 | n = utf8n_to_uvchr((U8*)start, len, &skip, 0); |
1571675a GS |
1029 | else { |
1030 | n = *(U8*)start; | |
1031 | skip = 1; | |
1032 | } | |
1033 | retval += ((NV)n)/nshift; | |
1034 | start += skip; | |
1035 | nshift *= 1000; | |
1036 | } | |
1037 | return retval; | |
1038 | } | |
1039 | ||
4e553d73 | 1040 | /* |
ffb4593c NT |
1041 | * S_force_version |
1042 | * Forces the next token to be a version number. | |
e759cc13 RGS |
1043 | * If the next token appears to be an invalid version number, (e.g. "v2b"), |
1044 | * and if "guessing" is TRUE, then no new token is created (and the caller | |
1045 | * must use an alternative parsing method). | |
ffb4593c NT |
1046 | */ |
1047 | ||
76e3520e | 1048 | STATIC char * |
e759cc13 | 1049 | S_force_version(pTHX_ char *s, int guessing) |
89bfa8cd | 1050 | { |
1051 | OP *version = Nullop; | |
44dcb63b | 1052 | char *d; |
89bfa8cd | 1053 | |
1054 | s = skipspace(s); | |
1055 | ||
44dcb63b | 1056 | d = s; |
dd629d5b | 1057 | if (*d == 'v') |
44dcb63b | 1058 | d++; |
44dcb63b | 1059 | if (isDIGIT(*d)) { |
e759cc13 RGS |
1060 | while (isDIGIT(*d) || *d == '_' || *d == '.') |
1061 | d++; | |
9f3d182e | 1062 | if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) { |
dd629d5b | 1063 | SV *ver; |
b73d6f50 | 1064 | s = scan_num(s, &yylval); |
89bfa8cd | 1065 | version = yylval.opval; |
dd629d5b GS |
1066 | ver = cSVOPx(version)->op_sv; |
1067 | if (SvPOK(ver) && !SvNIOK(ver)) { | |
862a34c6 | 1068 | SvUPGRADE(ver, SVt_PVNV); |
9d6ce603 | 1069 | SvNV_set(ver, str_to_version(ver)); |
1571675a | 1070 | SvNOK_on(ver); /* hint that it is a version */ |
44dcb63b | 1071 | } |
89bfa8cd | 1072 | } |
e759cc13 RGS |
1073 | else if (guessing) |
1074 | return s; | |
89bfa8cd | 1075 | } |
1076 | ||
1077 | /* NOTE: The parser sees the package name and the VERSION swapped */ | |
3280af22 | 1078 | PL_nextval[PL_nexttoke].opval = version; |
4e553d73 | 1079 | force_next(WORD); |
89bfa8cd | 1080 | |
e759cc13 | 1081 | return s; |
89bfa8cd | 1082 | } |
1083 | ||
ffb4593c NT |
1084 | /* |
1085 | * S_tokeq | |
1086 | * Tokenize a quoted string passed in as an SV. It finds the next | |
1087 | * chunk, up to end of string or a backslash. It may make a new | |
1088 | * SV containing that chunk (if HINT_NEW_STRING is on). It also | |
1089 | * turns \\ into \. | |
1090 | */ | |
1091 | ||
76e3520e | 1092 | STATIC SV * |
cea2e8a9 | 1093 | S_tokeq(pTHX_ SV *sv) |
79072805 LW |
1094 | { |
1095 | register char *s; | |
1096 | register char *send; | |
1097 | register char *d; | |
b3ac6de7 IZ |
1098 | STRLEN len = 0; |
1099 | SV *pv = sv; | |
79072805 LW |
1100 | |
1101 | if (!SvLEN(sv)) | |
b3ac6de7 | 1102 | goto finish; |
79072805 | 1103 | |
a0d0e21e | 1104 | s = SvPV_force(sv, len); |
21a311ee | 1105 | if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1) |
b3ac6de7 | 1106 | goto finish; |
463ee0b2 | 1107 | send = s + len; |
79072805 LW |
1108 | while (s < send && *s != '\\') |
1109 | s++; | |
1110 | if (s == send) | |
b3ac6de7 | 1111 | goto finish; |
79072805 | 1112 | d = s; |
be4731d2 | 1113 | if ( PL_hints & HINT_NEW_STRING ) { |
95a20fc0 | 1114 | pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len)); |
be4731d2 NIS |
1115 | if (SvUTF8(sv)) |
1116 | SvUTF8_on(pv); | |
1117 | } | |
79072805 LW |
1118 | while (s < send) { |
1119 | if (*s == '\\') { | |
a0d0e21e | 1120 | if (s + 1 < send && (s[1] == '\\')) |
79072805 LW |
1121 | s++; /* all that, just for this */ |
1122 | } | |
1123 | *d++ = *s++; | |
1124 | } | |
1125 | *d = '\0'; | |
95a20fc0 | 1126 | SvCUR_set(sv, d - SvPVX_const(sv)); |
b3ac6de7 | 1127 | finish: |
3280af22 | 1128 | if ( PL_hints & HINT_NEW_STRING ) |
b3ac6de7 | 1129 | return new_constant(NULL, 0, "q", sv, pv, "q"); |
79072805 LW |
1130 | return sv; |
1131 | } | |
1132 | ||
ffb4593c NT |
1133 | /* |
1134 | * Now come three functions related to double-quote context, | |
1135 | * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when | |
1136 | * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They | |
1137 | * interact with PL_lex_state, and create fake ( ... ) argument lists | |
1138 | * to handle functions and concatenation. | |
1139 | * They assume that whoever calls them will be setting up a fake | |
1140 | * join call, because each subthing puts a ',' after it. This lets | |
1141 | * "lower \luPpEr" | |
1142 | * become | |
1143 | * join($, , 'lower ', lcfirst( 'uPpEr', ) ,) | |
1144 | * | |
1145 | * (I'm not sure whether the spurious commas at the end of lcfirst's | |
1146 | * arguments and join's arguments are created or not). | |
1147 | */ | |
1148 | ||
1149 | /* | |
1150 | * S_sublex_start | |
1151 | * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST). | |
1152 | * | |
1153 | * Pattern matching will set PL_lex_op to the pattern-matching op to | |
1154 | * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise). | |
1155 | * | |
1156 | * OP_CONST and OP_READLINE are easy--just make the new op and return. | |
1157 | * | |
1158 | * Everything else becomes a FUNC. | |
1159 | * | |
1160 | * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we | |
1161 | * had an OP_CONST or OP_READLINE). This just sets us up for a | |
1162 | * call to S_sublex_push(). | |
1163 | */ | |
1164 | ||
76e3520e | 1165 | STATIC I32 |
cea2e8a9 | 1166 | S_sublex_start(pTHX) |
79072805 | 1167 | { |
0d46e09a | 1168 | register const I32 op_type = yylval.ival; |
79072805 LW |
1169 | |
1170 | if (op_type == OP_NULL) { | |
3280af22 NIS |
1171 | yylval.opval = PL_lex_op; |
1172 | PL_lex_op = Nullop; | |
79072805 LW |
1173 | return THING; |
1174 | } | |
1175 | if (op_type == OP_CONST || op_type == OP_READLINE) { | |
3280af22 | 1176 | SV *sv = tokeq(PL_lex_stuff); |
b3ac6de7 IZ |
1177 | |
1178 | if (SvTYPE(sv) == SVt_PVIV) { | |
1179 | /* Overloaded constants, nothing fancy: Convert to SVt_PV: */ | |
1180 | STRLEN len; | |
cfd0369c | 1181 | const char *p = SvPV_const(sv, len); |
f54cb97a | 1182 | SV * const nsv = newSVpvn(p, len); |
01ec43d0 GS |
1183 | if (SvUTF8(sv)) |
1184 | SvUTF8_on(nsv); | |
b3ac6de7 IZ |
1185 | SvREFCNT_dec(sv); |
1186 | sv = nsv; | |
4e553d73 | 1187 | } |
b3ac6de7 | 1188 | yylval.opval = (OP*)newSVOP(op_type, 0, sv); |
3280af22 | 1189 | PL_lex_stuff = Nullsv; |
6f33ba73 RGS |
1190 | /* Allow <FH> // "foo" */ |
1191 | if (op_type == OP_READLINE) | |
1192 | PL_expect = XTERMORDORDOR; | |
79072805 LW |
1193 | return THING; |
1194 | } | |
1195 | ||
3280af22 NIS |
1196 | PL_sublex_info.super_state = PL_lex_state; |
1197 | PL_sublex_info.sub_inwhat = op_type; | |
1198 | PL_sublex_info.sub_op = PL_lex_op; | |
1199 | PL_lex_state = LEX_INTERPPUSH; | |
55497cff | 1200 | |
3280af22 NIS |
1201 | PL_expect = XTERM; |
1202 | if (PL_lex_op) { | |
1203 | yylval.opval = PL_lex_op; | |
1204 | PL_lex_op = Nullop; | |
55497cff | 1205 | return PMFUNC; |
1206 | } | |
1207 | else | |
1208 | return FUNC; | |
1209 | } | |
1210 | ||
ffb4593c NT |
1211 | /* |
1212 | * S_sublex_push | |
1213 | * Create a new scope to save the lexing state. The scope will be | |
1214 | * ended in S_sublex_done. Returns a '(', starting the function arguments | |
1215 | * to the uc, lc, etc. found before. | |
1216 | * Sets PL_lex_state to LEX_INTERPCONCAT. | |
1217 | */ | |
1218 | ||
76e3520e | 1219 | STATIC I32 |
cea2e8a9 | 1220 | S_sublex_push(pTHX) |
55497cff | 1221 | { |
27da23d5 | 1222 | dVAR; |
f46d017c | 1223 | ENTER; |
55497cff | 1224 | |
3280af22 NIS |
1225 | PL_lex_state = PL_sublex_info.super_state; |
1226 | SAVEI32(PL_lex_dojoin); | |
1227 | SAVEI32(PL_lex_brackets); | |
3280af22 NIS |
1228 | SAVEI32(PL_lex_casemods); |
1229 | SAVEI32(PL_lex_starts); | |
1230 | SAVEI32(PL_lex_state); | |
7766f137 | 1231 | SAVEVPTR(PL_lex_inpat); |
3280af22 | 1232 | SAVEI32(PL_lex_inwhat); |
57843af0 | 1233 | SAVECOPLINE(PL_curcop); |
3280af22 | 1234 | SAVEPPTR(PL_bufptr); |
8452ff4b | 1235 | SAVEPPTR(PL_bufend); |
3280af22 NIS |
1236 | SAVEPPTR(PL_oldbufptr); |
1237 | SAVEPPTR(PL_oldoldbufptr); | |
207e3d1a JH |
1238 | SAVEPPTR(PL_last_lop); |
1239 | SAVEPPTR(PL_last_uni); | |
3280af22 NIS |
1240 | SAVEPPTR(PL_linestart); |
1241 | SAVESPTR(PL_linestr); | |
8edd5f42 RGS |
1242 | SAVEGENERICPV(PL_lex_brackstack); |
1243 | SAVEGENERICPV(PL_lex_casestack); | |
3280af22 NIS |
1244 | |
1245 | PL_linestr = PL_lex_stuff; | |
1246 | PL_lex_stuff = Nullsv; | |
1247 | ||
9cbb5ea2 GS |
1248 | PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart |
1249 | = SvPVX(PL_linestr); | |
3280af22 | 1250 | PL_bufend += SvCUR(PL_linestr); |
207e3d1a | 1251 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 NIS |
1252 | SAVEFREESV(PL_linestr); |
1253 | ||
1254 | PL_lex_dojoin = FALSE; | |
1255 | PL_lex_brackets = 0; | |
a02a5408 JC |
1256 | Newx(PL_lex_brackstack, 120, char); |
1257 | Newx(PL_lex_casestack, 12, char); | |
3280af22 NIS |
1258 | PL_lex_casemods = 0; |
1259 | *PL_lex_casestack = '\0'; | |
1260 | PL_lex_starts = 0; | |
1261 | PL_lex_state = LEX_INTERPCONCAT; | |
eb160463 | 1262 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
3280af22 NIS |
1263 | |
1264 | PL_lex_inwhat = PL_sublex_info.sub_inwhat; | |
1265 | if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST) | |
1266 | PL_lex_inpat = PL_sublex_info.sub_op; | |
79072805 | 1267 | else |
3280af22 | 1268 | PL_lex_inpat = Nullop; |
79072805 | 1269 | |
55497cff | 1270 | return '('; |
79072805 LW |
1271 | } |
1272 | ||
ffb4593c NT |
1273 | /* |
1274 | * S_sublex_done | |
1275 | * Restores lexer state after a S_sublex_push. | |
1276 | */ | |
1277 | ||
76e3520e | 1278 | STATIC I32 |
cea2e8a9 | 1279 | S_sublex_done(pTHX) |
79072805 | 1280 | { |
27da23d5 | 1281 | dVAR; |
3280af22 | 1282 | if (!PL_lex_starts++) { |
9d4ba2ae | 1283 | SV * const sv = newSVpvn("",0); |
9aa983d2 JH |
1284 | if (SvUTF8(PL_linestr)) |
1285 | SvUTF8_on(sv); | |
3280af22 | 1286 | PL_expect = XOPERATOR; |
9aa983d2 | 1287 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
79072805 LW |
1288 | return THING; |
1289 | } | |
1290 | ||
3280af22 NIS |
1291 | if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */ |
1292 | PL_lex_state = LEX_INTERPCASEMOD; | |
cea2e8a9 | 1293 | return yylex(); |
79072805 LW |
1294 | } |
1295 | ||
ffb4593c | 1296 | /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */ |
3280af22 NIS |
1297 | if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) { |
1298 | PL_linestr = PL_lex_repl; | |
1299 | PL_lex_inpat = 0; | |
1300 | PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr); | |
1301 | PL_bufend += SvCUR(PL_linestr); | |
207e3d1a | 1302 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 NIS |
1303 | SAVEFREESV(PL_linestr); |
1304 | PL_lex_dojoin = FALSE; | |
1305 | PL_lex_brackets = 0; | |
3280af22 NIS |
1306 | PL_lex_casemods = 0; |
1307 | *PL_lex_casestack = '\0'; | |
1308 | PL_lex_starts = 0; | |
25da4f38 | 1309 | if (SvEVALED(PL_lex_repl)) { |
3280af22 NIS |
1310 | PL_lex_state = LEX_INTERPNORMAL; |
1311 | PL_lex_starts++; | |
e9fa98b2 HS |
1312 | /* we don't clear PL_lex_repl here, so that we can check later |
1313 | whether this is an evalled subst; that means we rely on the | |
1314 | logic to ensure sublex_done() is called again only via the | |
1315 | branch (in yylex()) that clears PL_lex_repl, else we'll loop */ | |
79072805 | 1316 | } |
e9fa98b2 | 1317 | else { |
3280af22 | 1318 | PL_lex_state = LEX_INTERPCONCAT; |
e9fa98b2 HS |
1319 | PL_lex_repl = Nullsv; |
1320 | } | |
79072805 | 1321 | return ','; |
ffed7fef LW |
1322 | } |
1323 | else { | |
f46d017c | 1324 | LEAVE; |
3280af22 NIS |
1325 | PL_bufend = SvPVX(PL_linestr); |
1326 | PL_bufend += SvCUR(PL_linestr); | |
1327 | PL_expect = XOPERATOR; | |
09bef843 | 1328 | PL_sublex_info.sub_inwhat = 0; |
79072805 | 1329 | return ')'; |
ffed7fef LW |
1330 | } |
1331 | } | |
1332 | ||
02aa26ce NT |
1333 | /* |
1334 | scan_const | |
1335 | ||
1336 | Extracts a pattern, double-quoted string, or transliteration. This | |
1337 | is terrifying code. | |
1338 | ||
3280af22 NIS |
1339 | It looks at lex_inwhat and PL_lex_inpat to find out whether it's |
1340 | processing a pattern (PL_lex_inpat is true), a transliteration | |
02aa26ce NT |
1341 | (lex_inwhat & OP_TRANS is true), or a double-quoted string. |
1342 | ||
9b599b2a GS |
1343 | Returns a pointer to the character scanned up to. Iff this is |
1344 | advanced from the start pointer supplied (ie if anything was | |
1345 | successfully parsed), will leave an OP for the substring scanned | |
1346 | in yylval. Caller must intuit reason for not parsing further | |
1347 | by looking at the next characters herself. | |
1348 | ||
02aa26ce NT |
1349 | In patterns: |
1350 | backslashes: | |
1351 | double-quoted style: \r and \n | |
1352 | regexp special ones: \D \s | |
1353 | constants: \x3 | |
1354 | backrefs: \1 (deprecated in substitution replacements) | |
1355 | case and quoting: \U \Q \E | |
1356 | stops on @ and $, but not for $ as tail anchor | |
1357 | ||
1358 | In transliterations: | |
1359 | characters are VERY literal, except for - not at the start or end | |
1360 | of the string, which indicates a range. scan_const expands the | |
1361 | range to the full set of intermediate characters. | |
1362 | ||
1363 | In double-quoted strings: | |
1364 | backslashes: | |
1365 | double-quoted style: \r and \n | |
1366 | constants: \x3 | |
1367 | backrefs: \1 (deprecated) | |
1368 | case and quoting: \U \Q \E | |
1369 | stops on @ and $ | |
1370 | ||
1371 | scan_const does *not* construct ops to handle interpolated strings. | |
1372 | It stops processing as soon as it finds an embedded $ or @ variable | |
1373 | and leaves it to the caller to work out what's going on. | |
1374 | ||
da6eedaa | 1375 | @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo. |
02aa26ce NT |
1376 | |
1377 | $ in pattern could be $foo or could be tail anchor. Assumption: | |
1378 | it's a tail anchor if $ is the last thing in the string, or if it's | |
1379 | followed by one of ")| \n\t" | |
1380 | ||
1381 | \1 (backreferences) are turned into $1 | |
1382 | ||
1383 | The structure of the code is | |
1384 | while (there's a character to process) { | |
1385 | handle transliteration ranges | |
1386 | skip regexp comments | |
1387 | skip # initiated comments in //x patterns | |
1388 | check for embedded @foo | |
1389 | check for embedded scalars | |
1390 | if (backslash) { | |
1391 | leave intact backslashes from leave (below) | |
1392 | deprecate \1 in strings and sub replacements | |
1393 | handle string-changing backslashes \l \U \Q \E, etc. | |
1394 | switch (what was escaped) { | |
1395 | handle - in a transliteration (becomes a literal -) | |
1396 | handle \132 octal characters | |
1397 | handle 0x15 hex characters | |
1398 | handle \cV (control V) | |
1399 | handle printf backslashes (\f, \r, \n, etc) | |
1400 | } (end switch) | |
1401 | } (end if backslash) | |
1402 | } (end while character to read) | |
4e553d73 | 1403 | |
02aa26ce NT |
1404 | */ |
1405 | ||
76e3520e | 1406 | STATIC char * |
cea2e8a9 | 1407 | S_scan_const(pTHX_ char *start) |
79072805 | 1408 | { |
3280af22 | 1409 | register char *send = PL_bufend; /* end of the constant */ |
02aa26ce NT |
1410 | SV *sv = NEWSV(93, send - start); /* sv for the constant */ |
1411 | register char *s = start; /* start of the constant */ | |
1412 | register char *d = SvPVX(sv); /* destination for copies */ | |
1413 | bool dorange = FALSE; /* are we in a translit range? */ | |
c2e66d9e | 1414 | bool didrange = FALSE; /* did we just finish a range? */ |
2b9d42f0 NIS |
1415 | I32 has_utf8 = FALSE; /* Output constant is UTF8 */ |
1416 | I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */ | |
012bcf8d | 1417 | UV uv; |
4c3a8340 TS |
1418 | #ifdef EBCDIC |
1419 | UV literal_endpoint = 0; | |
1420 | #endif | |
012bcf8d | 1421 | |
dff6d3cd | 1422 | const char *leaveit = /* set of acceptably-backslashed characters */ |
3280af22 | 1423 | PL_lex_inpat |
b6d5fef8 | 1424 | ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#" |
9b599b2a | 1425 | : ""; |
79072805 | 1426 | |
2b9d42f0 NIS |
1427 | if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) { |
1428 | /* If we are doing a trans and we know we want UTF8 set expectation */ | |
1429 | has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF); | |
1430 | this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); | |
1431 | } | |
1432 | ||
1433 | ||
79072805 | 1434 | while (s < send || dorange) { |
02aa26ce | 1435 | /* get transliterations out of the way (they're most literal) */ |
3280af22 | 1436 | if (PL_lex_inwhat == OP_TRANS) { |
02aa26ce | 1437 | /* expand a range A-Z to the full set of characters. AIE! */ |
79072805 | 1438 | if (dorange) { |
1ba5c669 JH |
1439 | I32 i; /* current expanded character */ |
1440 | I32 min; /* first character in range */ | |
1441 | I32 max; /* last character in range */ | |
02aa26ce | 1442 | |
2b9d42f0 | 1443 | if (has_utf8) { |
9d4ba2ae | 1444 | char * const c = (char*)utf8_hop((U8*)d, -1); |
8973db79 JH |
1445 | char *e = d++; |
1446 | while (e-- > c) | |
1447 | *(e + 1) = *e; | |
25716404 | 1448 | *c = (char)UTF_TO_NATIVE(0xff); |
8973db79 JH |
1449 | /* mark the range as done, and continue */ |
1450 | dorange = FALSE; | |
1451 | didrange = TRUE; | |
1452 | continue; | |
1453 | } | |
2b9d42f0 | 1454 | |
95a20fc0 | 1455 | i = d - SvPVX_const(sv); /* remember current offset */ |
9cbb5ea2 GS |
1456 | SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */ |
1457 | d = SvPVX(sv) + i; /* refresh d after realloc */ | |
02aa26ce NT |
1458 | d -= 2; /* eat the first char and the - */ |
1459 | ||
8ada0baa JH |
1460 | min = (U8)*d; /* first char in range */ |
1461 | max = (U8)d[1]; /* last char in range */ | |
1462 | ||
c2e66d9e | 1463 | if (min > max) { |
01ec43d0 | 1464 | Perl_croak(aTHX_ |
d1573ac7 | 1465 | "Invalid range \"%c-%c\" in transliteration operator", |
1ba5c669 | 1466 | (char)min, (char)max); |
c2e66d9e GS |
1467 | } |
1468 | ||
c7f1f016 | 1469 | #ifdef EBCDIC |
4c3a8340 TS |
1470 | if (literal_endpoint == 2 && |
1471 | ((isLOWER(min) && isLOWER(max)) || | |
1472 | (isUPPER(min) && isUPPER(max)))) { | |
8ada0baa JH |
1473 | if (isLOWER(min)) { |
1474 | for (i = min; i <= max; i++) | |
1475 | if (isLOWER(i)) | |
db42d148 | 1476 | *d++ = NATIVE_TO_NEED(has_utf8,i); |
8ada0baa JH |
1477 | } else { |
1478 | for (i = min; i <= max; i++) | |
1479 | if (isUPPER(i)) | |
db42d148 | 1480 | *d++ = NATIVE_TO_NEED(has_utf8,i); |
8ada0baa JH |
1481 | } |
1482 | } | |
1483 | else | |
1484 | #endif | |
1485 | for (i = min; i <= max; i++) | |
eb160463 | 1486 | *d++ = (char)i; |
02aa26ce NT |
1487 | |
1488 | /* mark the range as done, and continue */ | |
79072805 | 1489 | dorange = FALSE; |
01ec43d0 | 1490 | didrange = TRUE; |
4c3a8340 TS |
1491 | #ifdef EBCDIC |
1492 | literal_endpoint = 0; | |
1493 | #endif | |
79072805 | 1494 | continue; |
4e553d73 | 1495 | } |
02aa26ce NT |
1496 | |
1497 | /* range begins (ignore - as first or last char) */ | |
79072805 | 1498 | else if (*s == '-' && s+1 < send && s != start) { |
4e553d73 | 1499 | if (didrange) { |
1fafa243 | 1500 | Perl_croak(aTHX_ "Ambiguous range in transliteration operator"); |
01ec43d0 | 1501 | } |
2b9d42f0 | 1502 | if (has_utf8) { |
25716404 | 1503 | *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */ |
a0ed51b3 LW |
1504 | s++; |
1505 | continue; | |
1506 | } | |
79072805 LW |
1507 | dorange = TRUE; |
1508 | s++; | |
01ec43d0 GS |
1509 | } |
1510 | else { | |
1511 | didrange = FALSE; | |
4c3a8340 TS |
1512 | #ifdef EBCDIC |
1513 | literal_endpoint = 0; | |
1514 | #endif | |
01ec43d0 | 1515 | } |
79072805 | 1516 | } |
02aa26ce NT |
1517 | |
1518 | /* if we get here, we're not doing a transliteration */ | |
1519 | ||
0f5d15d6 IZ |
1520 | /* skip for regexp comments /(?#comment)/ and code /(?{code})/, |
1521 | except for the last char, which will be done separately. */ | |
3280af22 | 1522 | else if (*s == '(' && PL_lex_inpat && s[1] == '?') { |
cc6b7395 | 1523 | if (s[2] == '#') { |
e994fd66 | 1524 | while (s+1 < send && *s != ')') |
db42d148 | 1525 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
155aba94 GS |
1526 | } |
1527 | else if (s[2] == '{' /* This should match regcomp.c */ | |
1528 | || ((s[2] == 'p' || s[2] == '?') && s[3] == '{')) | |
1529 | { | |
cc6b7395 | 1530 | I32 count = 1; |
0f5d15d6 | 1531 | char *regparse = s + (s[2] == '{' ? 3 : 4); |
cc6b7395 IZ |
1532 | char c; |
1533 | ||
d9f97599 GS |
1534 | while (count && (c = *regparse)) { |
1535 | if (c == '\\' && regparse[1]) | |
1536 | regparse++; | |
4e553d73 | 1537 | else if (c == '{') |
cc6b7395 | 1538 | count++; |
4e553d73 | 1539 | else if (c == '}') |
cc6b7395 | 1540 | count--; |
d9f97599 | 1541 | regparse++; |
cc6b7395 | 1542 | } |
e994fd66 | 1543 | if (*regparse != ')') |
5bdf89e7 | 1544 | regparse--; /* Leave one char for continuation. */ |
0f5d15d6 | 1545 | while (s < regparse) |
db42d148 | 1546 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
cc6b7395 | 1547 | } |
748a9306 | 1548 | } |
02aa26ce NT |
1549 | |
1550 | /* likewise skip #-initiated comments in //x patterns */ | |
3280af22 NIS |
1551 | else if (*s == '#' && PL_lex_inpat && |
1552 | ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) { | |
748a9306 | 1553 | while (s+1 < send && *s != '\n') |
db42d148 | 1554 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
748a9306 | 1555 | } |
02aa26ce | 1556 | |
5d1d4326 | 1557 | /* check for embedded arrays |
da6eedaa | 1558 | (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-) |
5d1d4326 | 1559 | */ |
7e2040f0 | 1560 | else if (*s == '@' && s[1] |
5d1d4326 | 1561 | && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1]))) |
79072805 | 1562 | break; |
02aa26ce NT |
1563 | |
1564 | /* check for embedded scalars. only stop if we're sure it's a | |
1565 | variable. | |
1566 | */ | |
79072805 | 1567 | else if (*s == '$') { |
3280af22 | 1568 | if (!PL_lex_inpat) /* not a regexp, so $ must be var */ |
79072805 | 1569 | break; |
6002328a | 1570 | if (s + 1 < send && !strchr("()| \r\n\t", s[1])) |
79072805 LW |
1571 | break; /* in regexp, $ might be tail anchor */ |
1572 | } | |
02aa26ce | 1573 | |
2b9d42f0 NIS |
1574 | /* End of else if chain - OP_TRANS rejoin rest */ |
1575 | ||
02aa26ce | 1576 | /* backslashes */ |
79072805 LW |
1577 | if (*s == '\\' && s+1 < send) { |
1578 | s++; | |
02aa26ce NT |
1579 | |
1580 | /* some backslashes we leave behind */ | |
c9f97d15 | 1581 | if (*leaveit && *s && strchr(leaveit, *s)) { |
db42d148 NIS |
1582 | *d++ = NATIVE_TO_NEED(has_utf8,'\\'); |
1583 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); | |
79072805 LW |
1584 | continue; |
1585 | } | |
02aa26ce NT |
1586 | |
1587 | /* deprecate \1 in strings and substitution replacements */ | |
3280af22 | 1588 | if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat && |
a0d0e21e | 1589 | isDIGIT(*s) && *s != '0' && !isDIGIT(s[1])) |
79072805 | 1590 | { |
599cee73 | 1591 | if (ckWARN(WARN_SYNTAX)) |
9014280d | 1592 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s); |
79072805 LW |
1593 | *--s = '$'; |
1594 | break; | |
1595 | } | |
02aa26ce NT |
1596 | |
1597 | /* string-change backslash escapes */ | |
3280af22 | 1598 | if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) { |
79072805 LW |
1599 | --s; |
1600 | break; | |
1601 | } | |
02aa26ce NT |
1602 | |
1603 | /* if we get here, it's either a quoted -, or a digit */ | |
79072805 | 1604 | switch (*s) { |
02aa26ce NT |
1605 | |
1606 | /* quoted - in transliterations */ | |
79072805 | 1607 | case '-': |
3280af22 | 1608 | if (PL_lex_inwhat == OP_TRANS) { |
79072805 LW |
1609 | *d++ = *s++; |
1610 | continue; | |
1611 | } | |
1612 | /* FALL THROUGH */ | |
1613 | default: | |
11b8faa4 | 1614 | { |
041457d9 DM |
1615 | if (isALNUM(*s) && |
1616 | *s != '_' && | |
1617 | ckWARN(WARN_MISC)) | |
9014280d | 1618 | Perl_warner(aTHX_ packWARN(WARN_MISC), |
11b8faa4 JH |
1619 | "Unrecognized escape \\%c passed through", |
1620 | *s); | |
1621 | /* default action is to copy the quoted character */ | |
f9a63242 | 1622 | goto default_action; |
11b8faa4 | 1623 | } |
02aa26ce NT |
1624 | |
1625 | /* \132 indicates an octal constant */ | |
79072805 LW |
1626 | case '0': case '1': case '2': case '3': |
1627 | case '4': case '5': case '6': case '7': | |
ba210ebe | 1628 | { |
53305cf1 NC |
1629 | I32 flags = 0; |
1630 | STRLEN len = 3; | |
1631 | uv = grok_oct(s, &len, &flags, NULL); | |
ba210ebe JH |
1632 | s += len; |
1633 | } | |
012bcf8d | 1634 | goto NUM_ESCAPE_INSERT; |
02aa26ce NT |
1635 | |
1636 | /* \x24 indicates a hex constant */ | |
79072805 | 1637 | case 'x': |
a0ed51b3 LW |
1638 | ++s; |
1639 | if (*s == '{') { | |
9d4ba2ae | 1640 | char* const e = strchr(s, '}'); |
a4c04bdc NC |
1641 | I32 flags = PERL_SCAN_ALLOW_UNDERSCORES | |
1642 | PERL_SCAN_DISALLOW_PREFIX; | |
53305cf1 | 1643 | STRLEN len; |
355860ce | 1644 | |
53305cf1 | 1645 | ++s; |
adaeee49 | 1646 | if (!e) { |
a0ed51b3 | 1647 | yyerror("Missing right brace on \\x{}"); |
355860ce | 1648 | continue; |
ba210ebe | 1649 | } |
53305cf1 NC |
1650 | len = e - s; |
1651 | uv = grok_hex(s, &len, &flags, NULL); | |
ba210ebe | 1652 | s = e + 1; |
a0ed51b3 LW |
1653 | } |
1654 | else { | |
ba210ebe | 1655 | { |
53305cf1 | 1656 | STRLEN len = 2; |
a4c04bdc | 1657 | I32 flags = PERL_SCAN_DISALLOW_PREFIX; |
53305cf1 | 1658 | uv = grok_hex(s, &len, &flags, NULL); |
ba210ebe JH |
1659 | s += len; |
1660 | } | |
012bcf8d GS |
1661 | } |
1662 | ||
1663 | NUM_ESCAPE_INSERT: | |
1664 | /* Insert oct or hex escaped character. | |
301d3d20 | 1665 | * There will always enough room in sv since such |
db42d148 | 1666 | * escapes will be longer than any UTF-8 sequence |
301d3d20 | 1667 | * they can end up as. */ |
ba7cea30 | 1668 | |
c7f1f016 NIS |
1669 | /* We need to map to chars to ASCII before doing the tests |
1670 | to cover EBCDIC | |
1671 | */ | |
c4d5f83a | 1672 | if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) { |
9aa983d2 | 1673 | if (!has_utf8 && uv > 255) { |
301d3d20 JH |
1674 | /* Might need to recode whatever we have |
1675 | * accumulated so far if it contains any | |
1676 | * hibit chars. | |
1677 | * | |
1678 | * (Can't we keep track of that and avoid | |
1679 | * this rescan? --jhi) | |
012bcf8d | 1680 | */ |
c7f1f016 | 1681 | int hicount = 0; |
63cd0674 NIS |
1682 | U8 *c; |
1683 | for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) { | |
c4d5f83a | 1684 | if (!NATIVE_IS_INVARIANT(*c)) { |
012bcf8d | 1685 | hicount++; |
db42d148 | 1686 | } |
012bcf8d | 1687 | } |
63cd0674 | 1688 | if (hicount) { |
9d4ba2ae | 1689 | const STRLEN offset = d - SvPVX_const(sv); |
db42d148 NIS |
1690 | U8 *src, *dst; |
1691 | d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset; | |
1692 | src = (U8 *)d - 1; | |
1693 | dst = src+hicount; | |
1694 | d += hicount; | |
cfd0369c | 1695 | while (src >= (const U8 *)SvPVX_const(sv)) { |
c4d5f83a | 1696 | if (!NATIVE_IS_INVARIANT(*src)) { |
9d4ba2ae | 1697 | const U8 ch = NATIVE_TO_ASCII(*src); |
eb160463 GS |
1698 | *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch); |
1699 | *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch); | |
012bcf8d GS |
1700 | } |
1701 | else { | |
63cd0674 | 1702 | *dst-- = *src; |
012bcf8d | 1703 | } |
c7f1f016 | 1704 | src--; |
012bcf8d GS |
1705 | } |
1706 | } | |
1707 | } | |
1708 | ||
9aa983d2 | 1709 | if (has_utf8 || uv > 255) { |
9041c2e3 | 1710 | d = (char*)uvchr_to_utf8((U8*)d, uv); |
4e553d73 | 1711 | has_utf8 = TRUE; |
f9a63242 JH |
1712 | if (PL_lex_inwhat == OP_TRANS && |
1713 | PL_sublex_info.sub_op) { | |
1714 | PL_sublex_info.sub_op->op_private |= | |
1715 | (PL_lex_repl ? OPpTRANS_FROM_UTF | |
1716 | : OPpTRANS_TO_UTF); | |
f9a63242 | 1717 | } |
012bcf8d | 1718 | } |
a0ed51b3 | 1719 | else { |
012bcf8d | 1720 | *d++ = (char)uv; |
a0ed51b3 | 1721 | } |
012bcf8d GS |
1722 | } |
1723 | else { | |
c4d5f83a | 1724 | *d++ = (char) uv; |
a0ed51b3 | 1725 | } |
79072805 | 1726 | continue; |
02aa26ce | 1727 | |
b239daa5 | 1728 | /* \N{LATIN SMALL LETTER A} is a named character */ |
4a2d328f | 1729 | case 'N': |
55eda711 | 1730 | ++s; |
423cee85 JH |
1731 | if (*s == '{') { |
1732 | char* e = strchr(s, '}'); | |
155aba94 | 1733 | SV *res; |
423cee85 | 1734 | STRLEN len; |
cfd0369c | 1735 | const char *str; |
4e553d73 | 1736 | |
423cee85 | 1737 | if (!e) { |
5777a3f7 | 1738 | yyerror("Missing right brace on \\N{}"); |
423cee85 JH |
1739 | e = s - 1; |
1740 | goto cont_scan; | |
1741 | } | |
dbc0d4f2 JH |
1742 | if (e > s + 2 && s[1] == 'U' && s[2] == '+') { |
1743 | /* \N{U+...} */ | |
1744 | I32 flags = PERL_SCAN_ALLOW_UNDERSCORES | | |
1745 | PERL_SCAN_DISALLOW_PREFIX; | |
1746 | s += 3; | |
1747 | len = e - s; | |
1748 | uv = grok_hex(s, &len, &flags, NULL); | |
1749 | s = e + 1; | |
1750 | goto NUM_ESCAPE_INSERT; | |
1751 | } | |
55eda711 JH |
1752 | res = newSVpvn(s + 1, e - s - 1); |
1753 | res = new_constant( Nullch, 0, "charnames", | |
1754 | res, Nullsv, "\\N{...}" ); | |
f9a63242 JH |
1755 | if (has_utf8) |
1756 | sv_utf8_upgrade(res); | |
cfd0369c | 1757 | str = SvPV_const(res,len); |
1c47067b JH |
1758 | #ifdef EBCDIC_NEVER_MIND |
1759 | /* charnames uses pack U and that has been | |
1760 | * recently changed to do the below uni->native | |
1761 | * mapping, so this would be redundant (and wrong, | |
1762 | * the code point would be doubly converted). | |
1763 | * But leave this in just in case the pack U change | |
1764 | * gets revoked, but the semantics is still | |
1765 | * desireable for charnames. --jhi */ | |
cddc7ef4 | 1766 | { |
cfd0369c | 1767 | UV uv = utf8_to_uvchr((const U8*)str, 0); |
cddc7ef4 JH |
1768 | |
1769 | if (uv < 0x100) { | |
89ebb4a3 | 1770 | U8 tmpbuf[UTF8_MAXBYTES+1], *d; |
cddc7ef4 JH |
1771 | |
1772 | d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv)); | |
1773 | sv_setpvn(res, (char *)tmpbuf, d - tmpbuf); | |
cfd0369c | 1774 | str = SvPV_const(res, len); |
cddc7ef4 JH |
1775 | } |
1776 | } | |
1777 | #endif | |
89491803 | 1778 | if (!has_utf8 && SvUTF8(res)) { |
9d4ba2ae | 1779 | const char * const ostart = SvPVX_const(sv); |
f08d6ad9 GS |
1780 | SvCUR_set(sv, d - ostart); |
1781 | SvPOK_on(sv); | |
e4f3eed8 | 1782 | *d = '\0'; |
f08d6ad9 | 1783 | sv_utf8_upgrade(sv); |
d2f449dd | 1784 | /* this just broke our allocation above... */ |
eb160463 | 1785 | SvGROW(sv, (STRLEN)(send - start)); |
f08d6ad9 | 1786 | d = SvPVX(sv) + SvCUR(sv); |
89491803 | 1787 | has_utf8 = TRUE; |
f08d6ad9 | 1788 | } |
eb160463 | 1789 | if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */ |
9d4ba2ae | 1790 | const char * const odest = SvPVX_const(sv); |
423cee85 | 1791 | |
8973db79 | 1792 | SvGROW(sv, (SvLEN(sv) + len - (e - s + 4))); |
423cee85 JH |
1793 | d = SvPVX(sv) + (d - odest); |
1794 | } | |
1795 | Copy(str, d, len, char); | |
1796 | d += len; | |
1797 | SvREFCNT_dec(res); | |
1798 | cont_scan: | |
1799 | s = e + 1; | |
1800 | } | |
1801 | else | |
5777a3f7 | 1802 | yyerror("Missing braces on \\N{}"); |
423cee85 JH |
1803 | continue; |
1804 | ||
02aa26ce | 1805 | /* \c is a control character */ |
79072805 LW |
1806 | case 'c': |
1807 | s++; | |
961ce445 | 1808 | if (s < send) { |
ba210ebe | 1809 | U8 c = *s++; |
c7f1f016 NIS |
1810 | #ifdef EBCDIC |
1811 | if (isLOWER(c)) | |
1812 | c = toUPPER(c); | |
1813 | #endif | |
db42d148 | 1814 | *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c)); |
ba210ebe | 1815 | } |
961ce445 RGS |
1816 | else { |
1817 | yyerror("Missing control char name in \\c"); | |
1818 | } | |
79072805 | 1819 | continue; |
02aa26ce NT |
1820 | |
1821 | /* printf-style backslashes, formfeeds, newlines, etc */ | |
79072805 | 1822 | case 'b': |
db42d148 | 1823 | *d++ = NATIVE_TO_NEED(has_utf8,'\b'); |
79072805 LW |
1824 | break; |
1825 | case 'n': | |
db42d148 | 1826 | *d++ = NATIVE_TO_NEED(has_utf8,'\n'); |
79072805 LW |
1827 | break; |
1828 | case 'r': | |
db42d148 | 1829 | *d++ = NATIVE_TO_NEED(has_utf8,'\r'); |
79072805 LW |
1830 | break; |
1831 | case 'f': | |
db42d148 | 1832 | *d++ = NATIVE_TO_NEED(has_utf8,'\f'); |
79072805 LW |
1833 | break; |
1834 | case 't': | |
db42d148 | 1835 | *d++ = NATIVE_TO_NEED(has_utf8,'\t'); |
79072805 | 1836 | break; |
34a3fe2a | 1837 | case 'e': |
db42d148 | 1838 | *d++ = ASCII_TO_NEED(has_utf8,'\033'); |
34a3fe2a PP |
1839 | break; |
1840 | case 'a': | |
db42d148 | 1841 | *d++ = ASCII_TO_NEED(has_utf8,'\007'); |
79072805 | 1842 | break; |
02aa26ce NT |
1843 | } /* end switch */ |
1844 | ||
79072805 LW |
1845 | s++; |
1846 | continue; | |
02aa26ce | 1847 | } /* end if (backslash) */ |
4c3a8340 TS |
1848 | #ifdef EBCDIC |
1849 | else | |
1850 | literal_endpoint++; | |
1851 | #endif | |
02aa26ce | 1852 | |
f9a63242 | 1853 | default_action: |
2b9d42f0 NIS |
1854 | /* If we started with encoded form, or already know we want it |
1855 | and then encode the next character */ | |
1856 | if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) { | |
1857 | STRLEN len = 1; | |
9d4ba2ae AL |
1858 | const UV uv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s); |
1859 | const STRLEN need = UNISKIP(NATIVE_TO_UNI(uv)); | |
2b9d42f0 NIS |
1860 | s += len; |
1861 | if (need > len) { | |
1862 | /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */ | |
9d4ba2ae | 1863 | const STRLEN off = d - SvPVX_const(sv); |
2b9d42f0 NIS |
1864 | d = SvGROW(sv, SvLEN(sv) + (need-len)) + off; |
1865 | } | |
1866 | d = (char*)uvchr_to_utf8((U8*)d, uv); | |
1867 | has_utf8 = TRUE; | |
1868 | } | |
1869 | else { | |
1870 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); | |
1871 | } | |
02aa26ce NT |
1872 | } /* while loop to process each character */ |
1873 | ||
1874 | /* terminate the string and set up the sv */ | |
79072805 | 1875 | *d = '\0'; |
95a20fc0 | 1876 | SvCUR_set(sv, d - SvPVX_const(sv)); |
2b9d42f0 | 1877 | if (SvCUR(sv) >= SvLEN(sv)) |
d0063567 | 1878 | Perl_croak(aTHX_ "panic: constant overflowed allocated space"); |
2b9d42f0 | 1879 | |
79072805 | 1880 | SvPOK_on(sv); |
9f4817db | 1881 | if (PL_encoding && !has_utf8) { |
d0063567 DK |
1882 | sv_recode_to_utf8(sv, PL_encoding); |
1883 | if (SvUTF8(sv)) | |
1884 | has_utf8 = TRUE; | |
9f4817db | 1885 | } |
2b9d42f0 | 1886 | if (has_utf8) { |
7e2040f0 | 1887 | SvUTF8_on(sv); |
2b9d42f0 | 1888 | if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) { |
d0063567 | 1889 | PL_sublex_info.sub_op->op_private |= |
2b9d42f0 NIS |
1890 | (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); |
1891 | } | |
1892 | } | |
79072805 | 1893 | |
02aa26ce | 1894 | /* shrink the sv if we allocated more than we used */ |
79072805 | 1895 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
1da4ca5f | 1896 | SvPV_shrink_to_cur(sv); |
79072805 | 1897 | } |
02aa26ce | 1898 | |
9b599b2a | 1899 | /* return the substring (via yylval) only if we parsed anything */ |
3280af22 NIS |
1900 | if (s > PL_bufptr) { |
1901 | if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) | |
4e553d73 | 1902 | sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"), |
b3ac6de7 | 1903 | sv, Nullsv, |
4e553d73 | 1904 | ( PL_lex_inwhat == OP_TRANS |
b3ac6de7 | 1905 | ? "tr" |
3280af22 | 1906 | : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) |
b3ac6de7 IZ |
1907 | ? "s" |
1908 | : "qq"))); | |
79072805 | 1909 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
b3ac6de7 | 1910 | } else |
8990e307 | 1911 | SvREFCNT_dec(sv); |
79072805 LW |
1912 | return s; |
1913 | } | |
1914 | ||
ffb4593c NT |
1915 | /* S_intuit_more |
1916 | * Returns TRUE if there's more to the expression (e.g., a subscript), | |
1917 | * FALSE otherwise. | |
ffb4593c NT |
1918 | * |
1919 | * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/ | |
1920 | * | |
1921 | * ->[ and ->{ return TRUE | |
1922 | * { and [ outside a pattern are always subscripts, so return TRUE | |
1923 | * if we're outside a pattern and it's not { or [, then return FALSE | |
1924 | * if we're in a pattern and the first char is a { | |
1925 | * {4,5} (any digits around the comma) returns FALSE | |
1926 | * if we're in a pattern and the first char is a [ | |
1927 | * [] returns FALSE | |
1928 | * [SOMETHING] has a funky algorithm to decide whether it's a | |
1929 | * character class or not. It has to deal with things like | |
1930 | * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/ | |
1931 | * anything else returns TRUE | |
1932 | */ | |
1933 | ||
9cbb5ea2 GS |
1934 | /* This is the one truly awful dwimmer necessary to conflate C and sed. */ |
1935 | ||
76e3520e | 1936 | STATIC int |
cea2e8a9 | 1937 | S_intuit_more(pTHX_ register char *s) |
79072805 | 1938 | { |
3280af22 | 1939 | if (PL_lex_brackets) |
79072805 LW |
1940 | return TRUE; |
1941 | if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{')) | |
1942 | return TRUE; | |
1943 | if (*s != '{' && *s != '[') | |
1944 | return FALSE; | |
3280af22 | 1945 | if (!PL_lex_inpat) |
79072805 LW |
1946 | return TRUE; |
1947 | ||
1948 | /* In a pattern, so maybe we have {n,m}. */ | |
1949 | if (*s == '{') { | |
1950 | s++; | |
1951 | if (!isDIGIT(*s)) | |
1952 | return TRUE; | |
1953 | while (isDIGIT(*s)) | |
1954 | s++; | |
1955 | if (*s == ',') | |
1956 | s++; | |
1957 | while (isDIGIT(*s)) | |
1958 | s++; | |
1959 | if (*s == '}') | |
1960 | return FALSE; | |
1961 | return TRUE; | |
1962 | ||
1963 | } | |
1964 | ||
1965 | /* On the other hand, maybe we have a character class */ | |
1966 | ||
1967 | s++; | |
1968 | if (*s == ']' || *s == '^') | |
1969 | return FALSE; | |
1970 | else { | |
ffb4593c | 1971 | /* this is terrifying, and it works */ |
79072805 LW |
1972 | int weight = 2; /* let's weigh the evidence */ |
1973 | char seen[256]; | |
f27ffc4a | 1974 | unsigned char un_char = 255, last_un_char; |
9d4ba2ae | 1975 | const char * const send = strchr(s,']'); |
3280af22 | 1976 | char tmpbuf[sizeof PL_tokenbuf * 4]; |
79072805 LW |
1977 | |
1978 | if (!send) /* has to be an expression */ | |
1979 | return TRUE; | |
1980 | ||
1981 | Zero(seen,256,char); | |
1982 | if (*s == '$') | |
1983 | weight -= 3; | |
1984 | else if (isDIGIT(*s)) { | |
1985 | if (s[1] != ']') { | |
1986 | if (isDIGIT(s[1]) && s[2] == ']') | |
1987 | weight -= 10; | |
1988 | } | |
1989 | else | |
1990 | weight -= 100; | |
1991 | } | |
1992 | for (; s < send; s++) { | |
1993 | last_un_char = un_char; | |
1994 | un_char = (unsigned char)*s; | |
1995 | switch (*s) { | |
1996 | case '@': | |
1997 | case '&': | |
1998 | case '$': | |
1999 | weight -= seen[un_char] * 10; | |
7e2040f0 | 2000 | if (isALNUM_lazy_if(s+1,UTF)) { |
8903cb82 | 2001 | scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE); |
a0d0e21e | 2002 | if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV)) |
79072805 LW |
2003 | weight -= 100; |
2004 | else | |
2005 | weight -= 10; | |
2006 | } | |
2007 | else if (*s == '$' && s[1] && | |
93a17b20 LW |
2008 | strchr("[#!%*<>()-=",s[1])) { |
2009 | if (/*{*/ strchr("])} =",s[2])) | |
79072805 LW |
2010 | weight -= 10; |
2011 | else | |
2012 | weight -= 1; | |
2013 | } | |
2014 | break; | |
2015 | case '\\': | |
2016 | un_char = 254; | |
2017 | if (s[1]) { | |
93a17b20 | 2018 | if (strchr("wds]",s[1])) |
79072805 LW |
2019 | weight += 100; |
2020 | else if (seen['\''] || seen['"']) | |
2021 | weight += 1; | |
93a17b20 | 2022 | else if (strchr("rnftbxcav",s[1])) |
79072805 LW |
2023 | weight += 40; |
2024 | else if (isDIGIT(s[1])) { | |
2025 | weight += 40; | |
2026 | while (s[1] && isDIGIT(s[1])) | |
2027 | s++; | |
2028 | } | |
2029 | } | |
2030 | else | |
2031 | weight += 100; | |
2032 | break; | |
2033 | case '-': | |
2034 | if (s[1] == '\\') | |
2035 | weight += 50; | |
93a17b20 | 2036 | if (strchr("aA01! ",last_un_char)) |
79072805 | 2037 | weight += 30; |
93a17b20 | 2038 | if (strchr("zZ79~",s[1])) |
79072805 | 2039 | weight += 30; |
f27ffc4a GS |
2040 | if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$')) |
2041 | weight -= 5; /* cope with negative subscript */ | |
79072805 LW |
2042 | break; |
2043 | default: | |
3792a11b NC |
2044 | if (!isALNUM(last_un_char) |
2045 | && !(last_un_char == '$' || last_un_char == '@' | |
2046 | || last_un_char == '&') | |
2047 | && isALPHA(*s) && s[1] && isALPHA(s[1])) { | |
79072805 LW |
2048 | char *d = tmpbuf; |
2049 | while (isALPHA(*s)) | |
2050 | *d++ = *s++; | |
2051 | *d = '\0'; | |
2052 | if (keyword(tmpbuf, d - tmpbuf)) | |
2053 | weight -= 150; | |
2054 | } | |
2055 | if (un_char == last_un_char + 1) | |
2056 | weight += 5; | |
2057 | weight -= seen[un_char]; | |
2058 | break; | |
2059 | } | |
2060 | seen[un_char]++; | |
2061 | } | |
2062 | if (weight >= 0) /* probably a character class */ | |
2063 | return FALSE; | |
2064 | } | |
2065 | ||
2066 | return TRUE; | |
2067 | } | |
ffed7fef | 2068 | |
ffb4593c NT |
2069 | /* |
2070 | * S_intuit_method | |
2071 | * | |
2072 | * Does all the checking to disambiguate | |
2073 | * foo bar | |
2074 | * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise | |
2075 | * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args). | |
2076 | * | |
2077 | * First argument is the stuff after the first token, e.g. "bar". | |
2078 | * | |
2079 | * Not a method if bar is a filehandle. | |
2080 | * Not a method if foo is a subroutine prototyped to take a filehandle. | |
2081 | * Not a method if it's really "Foo $bar" | |
2082 | * Method if it's "foo $bar" | |
2083 | * Not a method if it's really "print foo $bar" | |
2084 | * Method if it's really "foo package::" (interpreted as package->foo) | |
8f8cf39c | 2085 | * Not a method if bar is known to be a subroutine ("sub bar; foo bar") |
3cb0bbe5 | 2086 | * Not a method if bar is a filehandle or package, but is quoted with |
ffb4593c NT |
2087 | * => |
2088 | */ | |
2089 | ||
76e3520e | 2090 | STATIC int |
cea2e8a9 | 2091 | S_intuit_method(pTHX_ char *start, GV *gv) |
a0d0e21e LW |
2092 | { |
2093 | char *s = start + (*start == '$'); | |
3280af22 | 2094 | char tmpbuf[sizeof PL_tokenbuf]; |
a0d0e21e LW |
2095 | STRLEN len; |
2096 | GV* indirgv; | |
2097 | ||
2098 | if (gv) { | |
b6c543e3 | 2099 | CV *cv; |
a0d0e21e LW |
2100 | if (GvIO(gv)) |
2101 | return 0; | |
b6c543e3 | 2102 | if ((cv = GvCVu(gv))) { |
95a20fc0 | 2103 | const char *proto = SvPVX_const(cv); |
b6c543e3 IZ |
2104 | if (proto) { |
2105 | if (*proto == ';') | |
2106 | proto++; | |
2107 | if (*proto == '*') | |
2108 | return 0; | |
2109 | } | |
2110 | } else | |
a0d0e21e LW |
2111 | gv = 0; |
2112 | } | |
8903cb82 | 2113 | s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
ffb4593c NT |
2114 | /* start is the beginning of the possible filehandle/object, |
2115 | * and s is the end of it | |
2116 | * tmpbuf is a copy of it | |
2117 | */ | |
2118 | ||
a0d0e21e | 2119 | if (*start == '$') { |
3280af22 | 2120 | if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf)) |
a0d0e21e LW |
2121 | return 0; |
2122 | s = skipspace(s); | |
3280af22 NIS |
2123 | PL_bufptr = start; |
2124 | PL_expect = XREF; | |
a0d0e21e LW |
2125 | return *s == '(' ? FUNCMETH : METHOD; |
2126 | } | |
2127 | if (!keyword(tmpbuf, len)) { | |
c3e0f903 GS |
2128 | if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') { |
2129 | len -= 2; | |
2130 | tmpbuf[len] = '\0'; | |
2131 | goto bare_package; | |
2132 | } | |
2133 | indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV); | |
8ebc5c01 | 2134 | if (indirgv && GvCVu(indirgv)) |
a0d0e21e LW |
2135 | return 0; |
2136 | /* filehandle or package name makes it a method */ | |
89bfa8cd | 2137 | if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) { |
a0d0e21e | 2138 | s = skipspace(s); |
3280af22 | 2139 | if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>') |
55497cff | 2140 | return 0; /* no assumptions -- "=>" quotes bearword */ |
c3e0f903 | 2141 | bare_package: |
3280af22 | 2142 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, |
79cb57f6 | 2143 | newSVpvn(tmpbuf,len)); |
3280af22 NIS |
2144 | PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE; |
2145 | PL_expect = XTERM; | |
a0d0e21e | 2146 | force_next(WORD); |
3280af22 | 2147 | PL_bufptr = s; |
a0d0e21e LW |
2148 | return *s == '(' ? FUNCMETH : METHOD; |
2149 | } | |
2150 | } | |
2151 | return 0; | |
2152 | } | |
2153 | ||
ffb4593c NT |
2154 | /* |
2155 | * S_incl_perldb | |
2156 | * Return a string of Perl code to load the debugger. If PERL5DB | |
2157 | * is set, it will return the contents of that, otherwise a | |
2158 | * compile-time require of perl5db.pl. | |
2159 | */ | |
2160 | ||
bfed75c6 | 2161 | STATIC const char* |
cea2e8a9 | 2162 | S_incl_perldb(pTHX) |
a0d0e21e | 2163 | { |
3280af22 | 2164 | if (PL_perldb) { |
9d4ba2ae | 2165 | const char * const pdb = PerlEnv_getenv("PERL5DB"); |
a0d0e21e LW |
2166 | |
2167 | if (pdb) | |
2168 | return pdb; | |
93189314 | 2169 | SETERRNO(0,SS_NORMAL); |
a0d0e21e LW |
2170 | return "BEGIN { require 'perl5db.pl' }"; |
2171 | } | |
2172 | return ""; | |
2173 | } | |
2174 | ||
2175 | ||
16d20bd9 | 2176 | /* Encoded script support. filter_add() effectively inserts a |
4e553d73 | 2177 | * 'pre-processing' function into the current source input stream. |
16d20bd9 AD |
2178 | * Note that the filter function only applies to the current source file |
2179 | * (e.g., it will not affect files 'require'd or 'use'd by this one). | |
2180 | * | |
2181 | * The datasv parameter (which may be NULL) can be used to pass | |
2182 | * private data to this instance of the filter. The filter function | |
2183 | * can recover the SV using the FILTER_DATA macro and use it to | |
2184 | * store private buffers and state information. | |
2185 | * | |
2186 | * The supplied datasv parameter is upgraded to a PVIO type | |
4755096e | 2187 | * and the IoDIRP/IoANY field is used to store the function pointer, |
e0c19803 | 2188 | * and IOf_FAKE_DIRP is enabled on datasv to mark this as such. |
16d20bd9 AD |
2189 | * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for |
2190 | * private use must be set using malloc'd pointers. | |
2191 | */ | |
16d20bd9 AD |
2192 | |
2193 | SV * | |
864dbfa3 | 2194 | Perl_filter_add(pTHX_ filter_t funcp, SV *datasv) |
16d20bd9 | 2195 | { |
f4c556ac GS |
2196 | if (!funcp) |
2197 | return Nullsv; | |
2198 | ||
3280af22 NIS |
2199 | if (!PL_rsfp_filters) |
2200 | PL_rsfp_filters = newAV(); | |
16d20bd9 | 2201 | if (!datasv) |
8c52afec | 2202 | datasv = NEWSV(255,0); |
862a34c6 | 2203 | SvUPGRADE(datasv, SVt_PVIO); |
8141890a | 2204 | IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */ |
e0c19803 | 2205 | IoFLAGS(datasv) |= IOf_FAKE_DIRP; |
f4c556ac | 2206 | DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n", |
8141890a | 2207 | IoANY(datasv), SvPV_nolen(datasv))); |
3280af22 NIS |
2208 | av_unshift(PL_rsfp_filters, 1); |
2209 | av_store(PL_rsfp_filters, 0, datasv) ; | |
16d20bd9 AD |
2210 | return(datasv); |
2211 | } | |
4e553d73 | 2212 | |
16d20bd9 AD |
2213 | |
2214 | /* Delete most recently added instance of this filter function. */ | |
a0d0e21e | 2215 | void |
864dbfa3 | 2216 | Perl_filter_del(pTHX_ filter_t funcp) |
16d20bd9 | 2217 | { |
e0c19803 | 2218 | SV *datasv; |
24801a4b | 2219 | |
33073adb | 2220 | #ifdef DEBUGGING |
8141890a | 2221 | DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", FPTR2DPTR(XPVIO *, funcp))); |
33073adb | 2222 | #endif |
3280af22 | 2223 | if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0) |
16d20bd9 AD |
2224 | return; |
2225 | /* if filter is on top of stack (usual case) just pop it off */ | |
e0c19803 | 2226 | datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters)); |
8141890a | 2227 | if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) { |
e0c19803 | 2228 | IoFLAGS(datasv) &= ~IOf_FAKE_DIRP; |
4755096e | 2229 | IoANY(datasv) = (void *)NULL; |
3280af22 | 2230 | sv_free(av_pop(PL_rsfp_filters)); |
e50aee73 | 2231 | |
16d20bd9 AD |
2232 | return; |
2233 | } | |
2234 | /* we need to search for the correct entry and clear it */ | |
cea2e8a9 | 2235 | Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)"); |
16d20bd9 AD |
2236 | } |
2237 | ||
2238 | ||
1de9afcd RGS |
2239 | /* Invoke the idxth filter function for the current rsfp. */ |
2240 | /* maxlen 0 = read one text line */ | |
16d20bd9 | 2241 | I32 |
864dbfa3 | 2242 | Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen) |
a0d0e21e | 2243 | { |
16d20bd9 AD |
2244 | filter_t funcp; |
2245 | SV *datasv = NULL; | |
e50aee73 | 2246 | |
3280af22 | 2247 | if (!PL_rsfp_filters) |
16d20bd9 | 2248 | return -1; |
1de9afcd | 2249 | if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */ |
16d20bd9 AD |
2250 | /* Provide a default input filter to make life easy. */ |
2251 | /* Note that we append to the line. This is handy. */ | |
f4c556ac GS |
2252 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2253 | "filter_read %d: from rsfp\n", idx)); | |
4e553d73 | 2254 | if (maxlen) { |
16d20bd9 AD |
2255 | /* Want a block */ |
2256 | int len ; | |
f54cb97a | 2257 | const int old_len = SvCUR(buf_sv); |
16d20bd9 AD |
2258 | |
2259 | /* ensure buf_sv is large enough */ | |
eb160463 | 2260 | SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ; |
3280af22 NIS |
2261 | if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){ |
2262 | if (PerlIO_error(PL_rsfp)) | |
37120919 AD |
2263 | return -1; /* error */ |
2264 | else | |
2265 | return 0 ; /* end of file */ | |
2266 | } | |
16d20bd9 AD |
2267 | SvCUR_set(buf_sv, old_len + len) ; |
2268 | } else { | |
2269 | /* Want a line */ | |
3280af22 NIS |
2270 | if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) { |
2271 | if (PerlIO_error(PL_rsfp)) | |
37120919 AD |
2272 | return -1; /* error */ |
2273 | else | |
2274 | return 0 ; /* end of file */ | |
2275 | } | |
16d20bd9 AD |
2276 | } |
2277 | return SvCUR(buf_sv); | |
2278 | } | |
2279 | /* Skip this filter slot if filter has been deleted */ | |
1de9afcd | 2280 | if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) { |
f4c556ac GS |
2281 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2282 | "filter_read %d: skipped (filter deleted)\n", | |
2283 | idx)); | |
16d20bd9 AD |
2284 | return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */ |
2285 | } | |
2286 | /* Get function pointer hidden within datasv */ | |
8141890a | 2287 | funcp = DPTR2FPTR(filter_t, IoANY(datasv)); |
f4c556ac GS |
2288 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2289 | "filter_read %d: via function %p (%s)\n", | |
cfd0369c | 2290 | idx, datasv, SvPV_nolen_const(datasv))); |
16d20bd9 AD |
2291 | /* Call function. The function is expected to */ |
2292 | /* call "FILTER_READ(idx+1, buf_sv)" first. */ | |
37120919 | 2293 | /* Return: <0:error, =0:eof, >0:not eof */ |
acfe0abc | 2294 | return (*funcp)(aTHX_ idx, buf_sv, maxlen); |
16d20bd9 AD |
2295 | } |
2296 | ||
76e3520e | 2297 | STATIC char * |
cea2e8a9 | 2298 | S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append) |
16d20bd9 | 2299 | { |
c39cd008 | 2300 | #ifdef PERL_CR_FILTER |
3280af22 | 2301 | if (!PL_rsfp_filters) { |
c39cd008 | 2302 | filter_add(S_cr_textfilter,NULL); |
a868473f NIS |
2303 | } |
2304 | #endif | |
3280af22 | 2305 | if (PL_rsfp_filters) { |
55497cff | 2306 | if (!append) |
2307 | SvCUR_set(sv, 0); /* start with empty line */ | |
16d20bd9 AD |
2308 | if (FILTER_READ(0, sv, 0) > 0) |
2309 | return ( SvPVX(sv) ) ; | |
2310 | else | |
2311 | return Nullch ; | |
2312 | } | |
9d116dd7 | 2313 | else |
fd049845 | 2314 | return (sv_gets(sv, fp, append)); |
a0d0e21e LW |
2315 | } |
2316 | ||
01ec43d0 | 2317 | STATIC HV * |
7fc63493 | 2318 | S_find_in_my_stash(pTHX_ const char *pkgname, I32 len) |
def3634b GS |
2319 | { |
2320 | GV *gv; | |
2321 | ||
01ec43d0 | 2322 | if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__")) |
def3634b GS |
2323 | return PL_curstash; |
2324 | ||
2325 | if (len > 2 && | |
2326 | (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') && | |
01ec43d0 GS |
2327 | (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV))) |
2328 | { | |
2329 | return GvHV(gv); /* Foo:: */ | |
def3634b GS |
2330 | } |
2331 | ||
2332 | /* use constant CLASS => 'MyClass' */ | |
2333 | if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) { | |
2334 | SV *sv; | |
2335 | if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) { | |
83003860 | 2336 | pkgname = SvPV_nolen_const(sv); |
def3634b GS |
2337 | } |
2338 | } | |
2339 | ||
2340 | return gv_stashpv(pkgname, FALSE); | |
2341 | } | |
a0d0e21e | 2342 | |
468aa647 | 2343 | STATIC char * |
cc6ed77d | 2344 | S_tokenize_use(pTHX_ int is_use, char *s) { |
468aa647 RGS |
2345 | if (PL_expect != XSTATE) |
2346 | yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression", | |
2347 | is_use ? "use" : "no")); | |
2348 | s = skipspace(s); | |
2349 | if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) { | |
2350 | s = force_version(s, TRUE); | |
2351 | if (*s == ';' || (s = skipspace(s), *s == ';')) { | |
2352 | PL_nextval[PL_nexttoke].opval = Nullop; | |
2353 | force_next(WORD); | |
2354 | } | |
2355 | else if (*s == 'v') { | |
2356 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
2357 | s = force_version(s, FALSE); | |
2358 | } | |
2359 | } | |
2360 | else { | |
2361 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
2362 | s = force_version(s, FALSE); | |
2363 | } | |
2364 | yylval.ival = is_use; | |
2365 | return s; | |
2366 | } | |
748a9306 | 2367 | #ifdef DEBUGGING |
27da23d5 | 2368 | static const char* const exp_name[] = |
09bef843 | 2369 | { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK", |
27308ded | 2370 | "ATTRTERM", "TERMBLOCK", "TERMORDORDOR" |
09bef843 | 2371 | }; |
748a9306 | 2372 | #endif |
463ee0b2 | 2373 | |
02aa26ce NT |
2374 | /* |
2375 | yylex | |
2376 | ||
2377 | Works out what to call the token just pulled out of the input | |
2378 | stream. The yacc parser takes care of taking the ops we return and | |
2379 | stitching them into a tree. | |
2380 | ||
2381 | Returns: | |
2382 | PRIVATEREF | |
2383 | ||
2384 | Structure: | |
2385 | if read an identifier | |
2386 | if we're in a my declaration | |
2387 | croak if they tried to say my($foo::bar) | |
2388 | build the ops for a my() declaration | |
2389 | if it's an access to a my() variable | |
2390 | are we in a sort block? | |
2391 | croak if my($a); $a <=> $b | |
2392 | build ops for access to a my() variable | |
2393 | if in a dq string, and they've said @foo and we can't find @foo | |
2394 | croak | |
2395 | build ops for a bareword | |
2396 | if we already built the token before, use it. | |
2397 | */ | |
2398 | ||
20141f0e | 2399 | |
dba4d153 JH |
2400 | #ifdef __SC__ |
2401 | #pragma segment Perl_yylex | |
2402 | #endif | |
dba4d153 | 2403 | int |
dba4d153 | 2404 | Perl_yylex(pTHX) |
20141f0e | 2405 | { |
3afc138a | 2406 | register char *s = PL_bufptr; |
378cc40b | 2407 | register char *d; |
79072805 | 2408 | register I32 tmp; |
463ee0b2 | 2409 | STRLEN len; |
161b471a NIS |
2410 | GV *gv = Nullgv; |
2411 | GV **gvp = 0; | |
aa7440fb | 2412 | bool bof = FALSE; |
1d239bbb | 2413 | I32 orig_keyword = 0; |
a687059c | 2414 | |
bbf60fe6 | 2415 | DEBUG_T( { |
b6007c36 DM |
2416 | SV* tmp = newSVpvn("", 0); |
2417 | PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n", | |
2418 | (IV)CopLINE(PL_curcop), | |
2419 | lex_state_names[PL_lex_state], | |
2420 | exp_name[PL_expect], | |
2421 | pv_display(tmp, s, strlen(s), 0, 60)); | |
2422 | SvREFCNT_dec(tmp); | |
bbf60fe6 | 2423 | } ); |
02aa26ce | 2424 | /* check if there's an identifier for us to look at */ |
ba979b31 | 2425 | if (PL_pending_ident) |
bbf60fe6 | 2426 | return REPORT(S_pending_ident(aTHX)); |
bbce6d69 | 2427 | |
02aa26ce NT |
2428 | /* no identifier pending identification */ |
2429 | ||
3280af22 | 2430 | switch (PL_lex_state) { |
79072805 LW |
2431 | #ifdef COMMENTARY |
2432 | case LEX_NORMAL: /* Some compilers will produce faster */ | |
2433 | case LEX_INTERPNORMAL: /* code if we comment these out. */ | |
2434 | break; | |
2435 | #endif | |
2436 | ||
09bef843 | 2437 | /* when we've already built the next token, just pull it out of the queue */ |
79072805 | 2438 | case LEX_KNOWNEXT: |
3280af22 NIS |
2439 | PL_nexttoke--; |
2440 | yylval = PL_nextval[PL_nexttoke]; | |
2441 | if (!PL_nexttoke) { | |
2442 | PL_lex_state = PL_lex_defer; | |
2443 | PL_expect = PL_lex_expect; | |
2444 | PL_lex_defer = LEX_NORMAL; | |
463ee0b2 | 2445 | } |
bbf60fe6 | 2446 | return REPORT(PL_nexttype[PL_nexttoke]); |
79072805 | 2447 | |
02aa26ce | 2448 | /* interpolated case modifiers like \L \U, including \Q and \E. |
3280af22 | 2449 | when we get here, PL_bufptr is at the \ |
02aa26ce | 2450 | */ |
79072805 LW |
2451 | case LEX_INTERPCASEMOD: |
2452 | #ifdef DEBUGGING | |
3280af22 | 2453 | if (PL_bufptr != PL_bufend && *PL_bufptr != '\\') |
cea2e8a9 | 2454 | Perl_croak(aTHX_ "panic: INTERPCASEMOD"); |
79072805 | 2455 | #endif |
02aa26ce | 2456 | /* handle \E or end of string */ |
3280af22 | 2457 | if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') { |
02aa26ce | 2458 | /* if at a \E */ |
3280af22 | 2459 | if (PL_lex_casemods) { |
f54cb97a | 2460 | const char oldmod = PL_lex_casestack[--PL_lex_casemods]; |
3280af22 | 2461 | PL_lex_casestack[PL_lex_casemods] = '\0'; |
02aa26ce | 2462 | |
3792a11b NC |
2463 | if (PL_bufptr != PL_bufend |
2464 | && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) { | |
3280af22 NIS |
2465 | PL_bufptr += 2; |
2466 | PL_lex_state = LEX_INTERPCONCAT; | |
a0d0e21e | 2467 | } |
bbf60fe6 | 2468 | return REPORT(')'); |
79072805 | 2469 | } |
3280af22 NIS |
2470 | if (PL_bufptr != PL_bufend) |
2471 | PL_bufptr += 2; | |
2472 | PL_lex_state = LEX_INTERPCONCAT; | |
cea2e8a9 | 2473 | return yylex(); |
79072805 LW |
2474 | } |
2475 | else { | |
607df283 | 2476 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
b6007c36 | 2477 | "### Saw case modifier\n"); }); |
3280af22 | 2478 | s = PL_bufptr + 1; |
6e909404 JH |
2479 | if (s[1] == '\\' && s[2] == 'E') { |
2480 | PL_bufptr = s + 3; | |
2481 | PL_lex_state = LEX_INTERPCONCAT; | |
2482 | return yylex(); | |
a0d0e21e | 2483 | } |
6e909404 JH |
2484 | else { |
2485 | if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3)) | |
2486 | tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */ | |
3792a11b | 2487 | if ((*s == 'L' || *s == 'U') && |
6e909404 JH |
2488 | (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) { |
2489 | PL_lex_casestack[--PL_lex_casemods] = '\0'; | |
bbf60fe6 | 2490 | return REPORT(')'); |
6e909404 JH |
2491 | } |
2492 | if (PL_lex_casemods > 10) | |
2493 | Renew(PL_lex_casestack, PL_lex_casemods + 2, char); | |
2494 | PL_lex_casestack[PL_lex_casemods++] = *s; | |
2495 | PL_lex_casestack[PL_lex_casemods] = '\0'; | |
2496 | PL_lex_state = LEX_INTERPCONCAT; | |
2497 | PL_nextval[PL_nexttoke].ival = 0; | |
2498 | force_next('('); | |
2499 | if (*s == 'l') | |
2500 | PL_nextval[PL_nexttoke].ival = OP_LCFIRST; | |
2501 | else if (*s == 'u') | |
2502 | PL_nextval[PL_nexttoke].ival = OP_UCFIRST; | |
2503 | else if (*s == 'L') | |
2504 | PL_nextval[PL_nexttoke].ival = OP_LC; | |
2505 | else if (*s == 'U') | |
2506 | PL_nextval[PL_nexttoke].ival = OP_UC; | |
2507 | else if (*s == 'Q') | |
2508 | PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA; | |
2509 | else | |
2510 | Perl_croak(aTHX_ "panic: yylex"); | |
2511 | PL_bufptr = s + 1; | |
a0d0e21e | 2512 | } |
79072805 | 2513 | force_next(FUNC); |
3280af22 NIS |
2514 | if (PL_lex_starts) { |
2515 | s = PL_bufptr; | |
2516 | PL_lex_starts = 0; | |
131b3ad0 DM |
2517 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ |
2518 | if (PL_lex_casemods == 1 && PL_lex_inpat) | |
2519 | OPERATOR(','); | |
2520 | else | |
2521 | Aop(OP_CONCAT); | |
79072805 LW |
2522 | } |
2523 | else | |
cea2e8a9 | 2524 | return yylex(); |
79072805 LW |
2525 | } |
2526 | ||
55497cff | 2527 | case LEX_INTERPPUSH: |
bbf60fe6 | 2528 | return REPORT(sublex_push()); |
55497cff | 2529 | |
79072805 | 2530 | case LEX_INTERPSTART: |
3280af22 | 2531 | if (PL_bufptr == PL_bufend) |
bbf60fe6 | 2532 | return REPORT(sublex_done()); |
607df283 | 2533 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
b6007c36 | 2534 | "### Interpolated variable\n"); }); |
3280af22 NIS |
2535 | PL_expect = XTERM; |
2536 | PL_lex_dojoin = (*PL_bufptr == '@'); | |
2537 | PL_lex_state = LEX_INTERPNORMAL; | |
2538 | if (PL_lex_dojoin) { | |
2539 | PL_nextval[PL_nexttoke].ival = 0; | |
79072805 | 2540 | force_next(','); |
a0d0e21e | 2541 | force_ident("\"", '$'); |
3280af22 | 2542 | PL_nextval[PL_nexttoke].ival = 0; |
79072805 | 2543 | force_next('$'); |
3280af22 | 2544 | PL_nextval[PL_nexttoke].ival = 0; |
79072805 | 2545 | force_next('('); |
3280af22 | 2546 | PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */ |
79072805 LW |
2547 | force_next(FUNC); |
2548 | } | |
3280af22 NIS |
2549 | if (PL_lex_starts++) { |
2550 | s = PL_bufptr; | |
131b3ad0 DM |
2551 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ |
2552 | if (!PL_lex_casemods && PL_lex_inpat) | |
2553 | OPERATOR(','); | |
2554 | else | |
2555 | Aop(OP_CONCAT); | |
79072805 | 2556 | } |
cea2e8a9 | 2557 | return yylex(); |
79072805 LW |
2558 | |
2559 | case LEX_INTERPENDMAYBE: | |
3280af22 NIS |
2560 | if (intuit_more(PL_bufptr)) { |
2561 | PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */ | |
79072805 LW |
2562 | break; |
2563 | } | |
2564 | /* FALL THROUGH */ | |
2565 | ||
2566 | case LEX_INTERPEND: | |
3280af22 NIS |
2567 | if (PL_lex_dojoin) { |
2568 | PL_lex_dojoin = FALSE; | |
2569 | PL_lex_state = LEX_INTERPCONCAT; | |
bbf60fe6 | 2570 | return REPORT(')'); |
79072805 | 2571 | } |
43a16006 | 2572 | if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl |
25da4f38 | 2573 | && SvEVALED(PL_lex_repl)) |
43a16006 | 2574 | { |
e9fa98b2 | 2575 | if (PL_bufptr != PL_bufend) |
cea2e8a9 | 2576 | Perl_croak(aTHX_ "Bad evalled substitution pattern"); |
e9fa98b2 HS |
2577 | PL_lex_repl = Nullsv; |
2578 | } | |
79072805 LW |
2579 | /* FALLTHROUGH */ |
2580 | case LEX_INTERPCONCAT: | |
2581 | #ifdef DEBUGGING | |
3280af22 | 2582 | if (PL_lex_brackets) |
cea2e8a9 | 2583 | Perl_croak(aTHX_ "panic: INTERPCONCAT"); |
79072805 | 2584 | #endif |
3280af22 | 2585 | if (PL_bufptr == PL_bufend) |
bbf60fe6 | 2586 | return REPORT(sublex_done()); |
79072805 | 2587 | |
3280af22 NIS |
2588 | if (SvIVX(PL_linestr) == '\'') { |
2589 | SV *sv = newSVsv(PL_linestr); | |
2590 | if (!PL_lex_inpat) | |
76e3520e | 2591 | sv = tokeq(sv); |
3280af22 | 2592 | else if ( PL_hints & HINT_NEW_RE ) |
b3ac6de7 | 2593 | sv = new_constant(NULL, 0, "qr", sv, sv, "q"); |
79072805 | 2594 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
3280af22 | 2595 | s = PL_bufend; |
79072805 LW |
2596 | } |
2597 | else { | |
3280af22 | 2598 | s = scan_const(PL_bufptr); |
79072805 | 2599 | if (*s == '\\') |
3280af22 | 2600 | PL_lex_state = LEX_INTERPCASEMOD; |
79072805 | 2601 | else |
3280af22 | 2602 | PL_lex_state = LEX_INTERPSTART; |
79072805 LW |
2603 | } |
2604 | ||
3280af22 NIS |
2605 | if (s != PL_bufptr) { |
2606 | PL_nextval[PL_nexttoke] = yylval; | |
2607 | PL_expect = XTERM; | |
79072805 | 2608 | force_next(THING); |
131b3ad0 DM |
2609 | if (PL_lex_starts++) { |
2610 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ | |
2611 | if (!PL_lex_casemods && PL_lex_inpat) | |
2612 | OPERATOR(','); | |
2613 | else | |
2614 | Aop(OP_CONCAT); | |
2615 | } | |
79072805 | 2616 | else { |
3280af22 | 2617 | PL_bufptr = s; |
cea2e8a9 | 2618 | return yylex(); |
79072805 LW |
2619 | } |
2620 | } | |
2621 | ||
cea2e8a9 | 2622 | return yylex(); |
a0d0e21e | 2623 | case LEX_FORMLINE: |
3280af22 NIS |
2624 | PL_lex_state = LEX_NORMAL; |
2625 | s = scan_formline(PL_bufptr); | |
2626 | if (!PL_lex_formbrack) | |
a0d0e21e LW |
2627 | goto rightbracket; |
2628 | OPERATOR(';'); | |
79072805 LW |
2629 | } |
2630 | ||
3280af22 NIS |
2631 | s = PL_bufptr; |
2632 | PL_oldoldbufptr = PL_oldbufptr; | |
2633 | PL_oldbufptr = s; | |
463ee0b2 LW |
2634 | |
2635 | retry: | |
378cc40b LW |
2636 | switch (*s) { |
2637 | default: | |
7e2040f0 | 2638 | if (isIDFIRST_lazy_if(s,UTF)) |
834a4ddd | 2639 | goto keylookup; |
cea2e8a9 | 2640 | Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255); |
e929a76b LW |
2641 | case 4: |
2642 | case 26: | |
2643 | goto fake_eof; /* emulate EOF on ^D or ^Z */ | |
378cc40b | 2644 | case 0: |
3280af22 NIS |
2645 | if (!PL_rsfp) { |
2646 | PL_last_uni = 0; | |
2647 | PL_last_lop = 0; | |
c5ee2135 | 2648 | if (PL_lex_brackets) { |
0bd48802 AL |
2649 | yyerror(PL_lex_formbrack |
2650 | ? "Format not terminated" | |
2651 | : "Missing right curly or square bracket"); | |
c5ee2135 | 2652 | } |
4e553d73 | 2653 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
607df283 | 2654 | "### Tokener got EOF\n"); |
5f80b19c | 2655 | } ); |
79072805 | 2656 | TOKEN(0); |
463ee0b2 | 2657 | } |
3280af22 | 2658 | if (s++ < PL_bufend) |
a687059c | 2659 | goto retry; /* ignore stray nulls */ |
3280af22 NIS |
2660 | PL_last_uni = 0; |
2661 | PL_last_lop = 0; | |
2662 | if (!PL_in_eval && !PL_preambled) { | |
2663 | PL_preambled = TRUE; | |
2664 | sv_setpv(PL_linestr,incl_perldb()); | |
2665 | if (SvCUR(PL_linestr)) | |
4147a61b | 2666 | sv_catpvn(PL_linestr,";", 1); |
3280af22 NIS |
2667 | if (PL_preambleav){ |
2668 | while(AvFILLp(PL_preambleav) >= 0) { | |
2669 | SV *tmpsv = av_shift(PL_preambleav); | |
2670 | sv_catsv(PL_linestr, tmpsv); | |
4147a61b | 2671 | sv_catpvn(PL_linestr, ";", 1); |
91b7def8 | 2672 | sv_free(tmpsv); |
2673 | } | |
3280af22 NIS |
2674 | sv_free((SV*)PL_preambleav); |
2675 | PL_preambleav = NULL; | |
91b7def8 | 2676 | } |
3280af22 NIS |
2677 | if (PL_minus_n || PL_minus_p) { |
2678 | sv_catpv(PL_linestr, "LINE: while (<>) {"); | |
2679 | if (PL_minus_l) | |
2680 | sv_catpv(PL_linestr,"chomp;"); | |
2681 | if (PL_minus_a) { | |
3280af22 | 2682 | if (PL_minus_F) { |
3792a11b NC |
2683 | if ((*PL_splitstr == '/' || *PL_splitstr == '\'' |
2684 | || *PL_splitstr == '"') | |
3280af22 | 2685 | && strchr(PL_splitstr + 1, *PL_splitstr)) |
3db68c4c | 2686 | Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr); |
54310121 | 2687 | else { |
c8ef6a4b NC |
2688 | /* "q\0${splitstr}\0" is legal perl. Yes, even NUL |
2689 | bytes can be used as quoting characters. :-) */ | |
48c4c863 NC |
2690 | /* The count here deliberately includes the NUL |
2691 | that terminates the C string constant. This | |
2692 | embeds the opening NUL into the string. */ | |
dd374669 | 2693 | const char *splits = PL_splitstr; |
9a3fb652 | 2694 | sv_catpvn(PL_linestr, "our @F=split(q", 15); |
48c4c863 NC |
2695 | do { |
2696 | /* Need to \ \s */ | |
dd374669 AL |
2697 | if (*splits == '\\') |
2698 | sv_catpvn(PL_linestr, splits, 1); | |
2699 | sv_catpvn(PL_linestr, splits, 1); | |
2700 | } while (*splits++); | |
48c4c863 NC |
2701 | /* This loop will embed the trailing NUL of |
2702 | PL_linestr as the last thing it does before | |
2703 | terminating. */ | |
4fccd7c6 | 2704 | sv_catpvn(PL_linestr, ");", 2); |
54310121 | 2705 | } |
2304df62 AD |
2706 | } |
2707 | else | |
75c72d73 | 2708 | sv_catpv(PL_linestr,"our @F=split(' ');"); |
2304df62 | 2709 | } |
79072805 | 2710 | } |
4147a61b | 2711 | sv_catpvn(PL_linestr, "\n", 1); |
3280af22 NIS |
2712 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
2713 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2714 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 2715 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
9d4ba2ae | 2716 | SV * const sv = NEWSV(85,0); |
a0d0e21e LW |
2717 | |
2718 | sv_upgrade(sv, SVt_PVMG); | |
3280af22 | 2719 | sv_setsv(sv,PL_linestr); |
0ac0412a | 2720 | (void)SvIOK_on(sv); |
45977657 | 2721 | SvIV_set(sv, 0); |
57843af0 | 2722 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
a0d0e21e | 2723 | } |
79072805 | 2724 | goto retry; |
a687059c | 2725 | } |
e929a76b | 2726 | do { |
aa7440fb | 2727 | bof = PL_rsfp ? TRUE : FALSE; |
7e28d3af JH |
2728 | if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) { |
2729 | fake_eof: | |
2730 | if (PL_rsfp) { | |
2731 | if (PL_preprocess && !PL_in_eval) | |
2732 | (void)PerlProc_pclose(PL_rsfp); | |
2733 | else if ((PerlIO *)PL_rsfp == PerlIO_stdin()) | |
2734 | PerlIO_clearerr(PL_rsfp); | |
2735 | else | |
2736 | (void)PerlIO_close(PL_rsfp); | |
2737 | PL_rsfp = Nullfp; | |
2738 | PL_doextract = FALSE; | |
2739 | } | |
2740 | if (!PL_in_eval && (PL_minus_n || PL_minus_p)) { | |
a23c4656 NC |
2741 | sv_setpv(PL_linestr,PL_minus_p |
2742 | ? ";}continue{print;}" : ";}"); | |
7e28d3af JH |
2743 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
2744 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2745 | PL_last_lop = PL_last_uni = Nullch; |
7e28d3af JH |
2746 | PL_minus_n = PL_minus_p = 0; |
2747 | goto retry; | |
2748 | } | |
2749 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); | |
207e3d1a | 2750 | PL_last_lop = PL_last_uni = Nullch; |
c69006e4 | 2751 | sv_setpvn(PL_linestr,"",0); |
7e28d3af JH |
2752 | TOKEN(';'); /* not infinite loop because rsfp is NULL now */ |
2753 | } | |
7aa207d6 JH |
2754 | /* If it looks like the start of a BOM or raw UTF-16, |
2755 | * check if it in fact is. */ | |
2756 | else if (bof && | |
2757 | (*s == 0 || | |
2758 | *(U8*)s == 0xEF || | |
2759 | *(U8*)s >= 0xFE || | |
2760 | s[1] == 0)) { | |
226017aa | 2761 | #ifdef PERLIO_IS_STDIO |
e3f494f1 JH |
2762 | # ifdef __GNU_LIBRARY__ |
2763 | # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */ | |
226017aa DD |
2764 | # define FTELL_FOR_PIPE_IS_BROKEN |
2765 | # endif | |
e3f494f1 JH |
2766 | # else |
2767 | # ifdef __GLIBC__ | |
2768 | # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */ | |
2769 | # define FTELL_FOR_PIPE_IS_BROKEN | |
2770 | # endif | |
2771 | # endif | |
226017aa DD |
2772 | # endif |
2773 | #endif | |
2774 | #ifdef FTELL_FOR_PIPE_IS_BROKEN | |
2775 | /* This loses the possibility to detect the bof | |
2776 | * situation on perl -P when the libc5 is being used. | |
2777 | * Workaround? Maybe attach some extra state to PL_rsfp? | |
2778 | */ | |
2779 | if (!PL_preprocess) | |
7e28d3af | 2780 | bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr); |
226017aa | 2781 | #else |
eb160463 | 2782 | bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr); |
226017aa | 2783 | #endif |
7e28d3af | 2784 | if (bof) { |
3280af22 | 2785 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
7e28d3af | 2786 | s = swallow_bom((U8*)s); |
e929a76b | 2787 | } |
378cc40b | 2788 | } |
3280af22 | 2789 | if (PL_doextract) { |
a0d0e21e LW |
2790 | /* Incest with pod. */ |
2791 | if (*s == '=' && strnEQ(s, "=cut", 4)) { | |
c69006e4 | 2792 | sv_setpvn(PL_linestr, "", 0); |
3280af22 NIS |
2793 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
2794 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2795 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 2796 | PL_doextract = FALSE; |
a0d0e21e | 2797 | } |
4e553d73 | 2798 | } |
463ee0b2 | 2799 | incline(s); |
3280af22 NIS |
2800 | } while (PL_doextract); |
2801 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s; | |
2802 | if (PERLDB_LINE && PL_curstash != PL_debstash) { | |
9d4ba2ae | 2803 | SV * const sv = NEWSV(85,0); |
a687059c | 2804 | |
93a17b20 | 2805 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 2806 | sv_setsv(sv,PL_linestr); |
0ac0412a | 2807 | (void)SvIOK_on(sv); |
45977657 | 2808 | SvIV_set(sv, 0); |
57843af0 | 2809 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
a687059c | 2810 | } |
3280af22 | 2811 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 2812 | PL_last_lop = PL_last_uni = Nullch; |
57843af0 | 2813 | if (CopLINE(PL_curcop) == 1) { |
3280af22 | 2814 | while (s < PL_bufend && isSPACE(*s)) |
79072805 | 2815 | s++; |
a0d0e21e | 2816 | if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */ |
79072805 | 2817 | s++; |
44a8e56a | 2818 | d = Nullch; |
3280af22 | 2819 | if (!PL_in_eval) { |
44a8e56a | 2820 | if (*s == '#' && *(s+1) == '!') |
2821 | d = s + 2; | |
2822 | #ifdef ALTERNATE_SHEBANG | |
2823 | else { | |
bfed75c6 | 2824 | static char const as[] = ALTERNATE_SHEBANG; |
44a8e56a | 2825 | if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1)) |
2826 | d = s + (sizeof(as) - 1); | |
2827 | } | |
2828 | #endif /* ALTERNATE_SHEBANG */ | |
2829 | } | |
2830 | if (d) { | |
b8378b72 | 2831 | char *ipath; |
774d564b | 2832 | char *ipathend; |
b8378b72 | 2833 | |
774d564b | 2834 | while (isSPACE(*d)) |
b8378b72 CS |
2835 | d++; |
2836 | ipath = d; | |
774d564b | 2837 | while (*d && !isSPACE(*d)) |
2838 | d++; | |
2839 | ipathend = d; | |
2840 | ||
2841 | #ifdef ARG_ZERO_IS_SCRIPT | |
2842 | if (ipathend > ipath) { | |
2843 | /* | |
2844 | * HP-UX (at least) sets argv[0] to the script name, | |
2845 | * which makes $^X incorrect. And Digital UNIX and Linux, | |
2846 | * at least, set argv[0] to the basename of the Perl | |
2847 | * interpreter. So, having found "#!", we'll set it right. | |
2848 | */ | |
551405c4 | 2849 | SV * const x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV)); /* $^X */ |
774d564b | 2850 | assert(SvPOK(x) || SvGMAGICAL(x)); |
cc49e20b | 2851 | if (sv_eq(x, CopFILESV(PL_curcop))) { |
774d564b | 2852 | sv_setpvn(x, ipath, ipathend - ipath); |
9607fc9c | 2853 | SvSETMAGIC(x); |
2854 | } | |
556c1dec JH |
2855 | else { |
2856 | STRLEN blen; | |
2857 | STRLEN llen; | |
cfd0369c | 2858 | const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen); |
9d4ba2ae | 2859 | const char * const lstart = SvPV_const(x,llen); |
556c1dec JH |
2860 | if (llen < blen) { |
2861 | bstart += blen - llen; | |
2862 | if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') { | |
2863 | sv_setpvn(x, ipath, ipathend - ipath); | |
2864 | SvSETMAGIC(x); | |
2865 | } | |
2866 | } | |
2867 | } | |
774d564b | 2868 | TAINT_NOT; /* $^X is always tainted, but that's OK */ |
8ebc5c01 | 2869 | } |
774d564b | 2870 | #endif /* ARG_ZERO_IS_SCRIPT */ |
b8378b72 CS |
2871 | |
2872 | /* | |
2873 | * Look for options. | |
2874 | */ | |
748a9306 | 2875 | d = instr(s,"perl -"); |
84e30d1a | 2876 | if (!d) { |
748a9306 | 2877 | d = instr(s,"perl"); |
84e30d1a GS |
2878 | #if defined(DOSISH) |
2879 | /* avoid getting into infinite loops when shebang | |
2880 | * line contains "Perl" rather than "perl" */ | |
2881 | if (!d) { | |
2882 | for (d = ipathend-4; d >= ipath; --d) { | |
2883 | if ((*d == 'p' || *d == 'P') | |
2884 | && !ibcmp(d, "perl", 4)) | |
2885 | { | |
2886 | break; | |
2887 | } | |
2888 | } | |
2889 | if (d < ipath) | |
2890 | d = Nullch; | |
2891 | } | |
2892 | #endif | |
2893 | } | |
44a8e56a | 2894 | #ifdef ALTERNATE_SHEBANG |
2895 | /* | |
2896 | * If the ALTERNATE_SHEBANG on this system starts with a | |
2897 | * character that can be part of a Perl expression, then if | |
2898 | * we see it but not "perl", we're probably looking at the | |
2899 | * start of Perl code, not a request to hand off to some | |
2900 | * other interpreter. Similarly, if "perl" is there, but | |
2901 | * not in the first 'word' of the line, we assume the line | |
2902 | * contains the start of the Perl program. | |
44a8e56a | 2903 | */ |
2904 | if (d && *s != '#') { | |
f54cb97a | 2905 | const char *c = ipath; |
44a8e56a | 2906 | while (*c && !strchr("; \t\r\n\f\v#", *c)) |
2907 | c++; | |
2908 | if (c < d) | |
2909 | d = Nullch; /* "perl" not in first word; ignore */ | |
2910 | else | |
2911 | *s = '#'; /* Don't try to parse shebang line */ | |
2912 | } | |
774d564b | 2913 | #endif /* ALTERNATE_SHEBANG */ |
bf4acbe4 | 2914 | #ifndef MACOS_TRADITIONAL |
748a9306 | 2915 | if (!d && |
44a8e56a | 2916 | *s == '#' && |
774d564b | 2917 | ipathend > ipath && |
3280af22 | 2918 | !PL_minus_c && |
748a9306 | 2919 | !instr(s,"indir") && |
3280af22 | 2920 | instr(PL_origargv[0],"perl")) |
748a9306 | 2921 | { |
27da23d5 | 2922 | dVAR; |
9f68db38 | 2923 | char **newargv; |
9f68db38 | 2924 | |
774d564b | 2925 | *ipathend = '\0'; |
2926 | s = ipathend + 1; | |
3280af22 | 2927 | while (s < PL_bufend && isSPACE(*s)) |
9f68db38 | 2928 | s++; |
3280af22 | 2929 | if (s < PL_bufend) { |
a02a5408 | 2930 | Newxz(newargv,PL_origargc+3,char*); |
9f68db38 | 2931 | newargv[1] = s; |
3280af22 | 2932 | while (s < PL_bufend && !isSPACE(*s)) |
9f68db38 LW |
2933 | s++; |
2934 | *s = '\0'; | |
3280af22 | 2935 | Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*); |
9f68db38 LW |
2936 | } |
2937 | else | |
3280af22 | 2938 | newargv = PL_origargv; |
774d564b | 2939 | newargv[0] = ipath; |
b35112e7 | 2940 | PERL_FPU_PRE_EXEC |
b4748376 | 2941 | PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv)); |
b35112e7 | 2942 | PERL_FPU_POST_EXEC |
cea2e8a9 | 2943 | Perl_croak(aTHX_ "Can't exec %s", ipath); |
9f68db38 | 2944 | } |
bf4acbe4 | 2945 | #endif |
748a9306 | 2946 | if (d) { |
f54cb97a AL |
2947 | const U32 oldpdb = PL_perldb; |
2948 | const bool oldn = PL_minus_n; | |
2949 | const bool oldp = PL_minus_p; | |
748a9306 LW |
2950 | |
2951 | while (*d && !isSPACE(*d)) d++; | |
bf4acbe4 | 2952 | while (SPACE_OR_TAB(*d)) d++; |
748a9306 LW |
2953 | |
2954 | if (*d++ == '-') { | |
f54cb97a | 2955 | const bool switches_done = PL_doswitches; |
8cc95fdb | 2956 | do { |
3ffe3ee4 | 2957 | if (*d == 'M' || *d == 'm' || *d == 'C') { |
9d4ba2ae | 2958 | const char * const m = d; |
8cc95fdb | 2959 | while (*d && !isSPACE(*d)) d++; |
cea2e8a9 | 2960 | Perl_croak(aTHX_ "Too late for \"-%.*s\" option", |
8cc95fdb | 2961 | (int)(d - m), m); |
2962 | } | |
2963 | d = moreswitches(d); | |
2964 | } while (d); | |
f0b2cf55 YST |
2965 | if (PL_doswitches && !switches_done) { |
2966 | int argc = PL_origargc; | |
2967 | char **argv = PL_origargv; | |
2968 | do { | |
2969 | argc--,argv++; | |
2970 | } while (argc && argv[0][0] == '-' && argv[0][1]); | |
2971 | init_argv_symbols(argc,argv); | |
2972 | } | |
155aba94 GS |
2973 | if ((PERLDB_LINE && !oldpdb) || |
2974 | ((PL_minus_n || PL_minus_p) && !(oldn || oldp))) | |
b084f20b | 2975 | /* if we have already added "LINE: while (<>) {", |
2976 | we must not do it again */ | |
748a9306 | 2977 | { |
c69006e4 | 2978 | sv_setpvn(PL_linestr, "", 0); |
3280af22 NIS |
2979 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
2980 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2981 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 2982 | PL_preambled = FALSE; |
84902520 | 2983 | if (PERLDB_LINE) |
3280af22 | 2984 | (void)gv_fetchfile(PL_origfilename); |
748a9306 LW |
2985 | goto retry; |
2986 | } | |
a11ec5a9 RGS |
2987 | if (PL_doswitches && !switches_done) { |
2988 | int argc = PL_origargc; | |
2989 | char **argv = PL_origargv; | |
2990 | do { | |
2991 | argc--,argv++; | |
2992 | } while (argc && argv[0][0] == '-' && argv[0][1]); | |
2993 | init_argv_symbols(argc,argv); | |
2994 | } | |
a0d0e21e | 2995 | } |
79072805 | 2996 | } |
9f68db38 | 2997 | } |
79072805 | 2998 | } |
3280af22 NIS |
2999 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
3000 | PL_bufptr = s; | |
3001 | PL_lex_state = LEX_FORMLINE; | |
cea2e8a9 | 3002 | return yylex(); |
ae986130 | 3003 | } |
378cc40b | 3004 | goto retry; |
4fdae800 | 3005 | case '\r': |
6a27c188 | 3006 | #ifdef PERL_STRICT_CR |
cea2e8a9 | 3007 | Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r'); |
4e553d73 | 3008 | Perl_croak(aTHX_ |
cc507455 | 3009 | "\t(Maybe you didn't strip carriage returns after a network transfer?)\n"); |
a868473f | 3010 | #endif |
4fdae800 | 3011 | case ' ': case '\t': case '\f': case 013: |
bf4acbe4 GS |
3012 | #ifdef MACOS_TRADITIONAL |
3013 | case '\312': | |
3014 | #endif | |
378cc40b LW |
3015 | s++; |
3016 | goto retry; | |
378cc40b | 3017 | case '#': |
e929a76b | 3018 | case '\n': |
3280af22 | 3019 | if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) { |
df0deb90 GS |
3020 | if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) { |
3021 | /* handle eval qq[#line 1 "foo"\n ...] */ | |
3022 | CopLINE_dec(PL_curcop); | |
3023 | incline(s); | |
3024 | } | |
3280af22 | 3025 | d = PL_bufend; |
a687059c | 3026 | while (s < d && *s != '\n') |
378cc40b | 3027 | s++; |
0f85fab0 | 3028 | if (s < d) |
378cc40b | 3029 | s++; |
78c267c1 | 3030 | else if (s > d) /* Found by Ilya: feed random input to Perl. */ |
a8406387 | 3031 | Perl_croak(aTHX_ "panic: input overflow"); |
463ee0b2 | 3032 | incline(s); |
3280af22 NIS |
3033 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
3034 | PL_bufptr = s; | |
3035 | PL_lex_state = LEX_FORMLINE; | |
cea2e8a9 | 3036 | return yylex(); |
a687059c | 3037 | } |
378cc40b | 3038 | } |
a687059c | 3039 | else { |
378cc40b | 3040 | *s = '\0'; |
3280af22 | 3041 | PL_bufend = s; |
a687059c | 3042 | } |
378cc40b LW |
3043 | goto retry; |
3044 | case '-': | |
79072805 | 3045 | if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) { |
e5edeb50 JH |
3046 | I32 ftst = 0; |
3047 | ||
378cc40b | 3048 | s++; |
3280af22 | 3049 | PL_bufptr = s; |
748a9306 LW |
3050 | tmp = *s++; |
3051 | ||
bf4acbe4 | 3052 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
748a9306 LW |
3053 | s++; |
3054 | ||
3055 | if (strnEQ(s,"=>",2)) { | |
3280af22 | 3056 | s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE); |
b6007c36 DM |
3057 | DEBUG_T( { S_printbuf(aTHX_ |
3058 | "### Saw unary minus before =>, forcing word %s\n", s); | |
5f80b19c | 3059 | } ); |
748a9306 LW |
3060 | OPERATOR('-'); /* unary minus */ |
3061 | } | |
3280af22 | 3062 | PL_last_uni = PL_oldbufptr; |
748a9306 | 3063 | switch (tmp) { |
e5edeb50 JH |
3064 | case 'r': ftst = OP_FTEREAD; break; |
3065 | case 'w': ftst = OP_FTEWRITE; break; | |
3066 | case 'x': ftst = OP_FTEEXEC; break; | |
3067 | case 'o': ftst = OP_FTEOWNED; break; | |
3068 | case 'R': ftst = OP_FTRREAD; break; | |
3069 | case 'W': ftst = OP_FTRWRITE; break; | |
3070 | case 'X': ftst = OP_FTREXEC; break; | |
3071 | case 'O': ftst = OP_FTROWNED; break; | |
3072 | case 'e': ftst = OP_FTIS; break; | |
3073 | case 'z': ftst = OP_FTZERO; break; | |
3074 | case 's': ftst = OP_FTSIZE; break; | |
3075 | case 'f': ftst = OP_FTFILE; break; | |
3076 | case 'd': ftst = OP_FTDIR; break; | |
3077 | case 'l': ftst = OP_FTLINK; break; | |
3078 | case 'p': ftst = OP_FTPIPE; break; | |
3079 | case 'S': ftst = OP_FTSOCK; break; | |
3080 | case 'u': ftst = OP_FTSUID; break; | |
3081 | case 'g': ftst = OP_FTSGID; break; | |
3082 | case 'k': ftst = OP_FTSVTX; break; | |
3083 | case 'b': ftst = OP_FTBLK; break; | |
3084 | case 'c': ftst = OP_FTCHR; break; | |
3085 | case 't': ftst = OP_FTTTY; break; | |
3086 | case 'T': ftst = OP_FTTEXT; break; | |
3087 | case 'B': ftst = OP_FTBINARY; break; | |
3088 | case 'M': case 'A': case 'C': | |
3089 | gv_fetchpv("\024",TRUE, SVt_PV); | |
3090 | switch (tmp) { | |
3091 | case 'M': ftst = OP_FTMTIME; break; | |
3092 | case 'A': ftst = OP_FTATIME; break; | |
3093 | case 'C': ftst = OP_FTCTIME; break; | |
3094 | default: break; | |
3095 | } | |
3096 | break; | |
378cc40b | 3097 | default: |
378cc40b LW |
3098 | break; |
3099 | } | |
e5edeb50 | 3100 | if (ftst) { |
eb160463 | 3101 | PL_last_lop_op = (OPCODE)ftst; |
4e553d73 | 3102 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
a18d764d | 3103 | "### Saw file test %c\n", (int)tmp); |
5f80b19c | 3104 | } ); |
e5edeb50 JH |
3105 | FTST(ftst); |
3106 | } | |
3107 | else { | |
3108 | /* Assume it was a minus followed by a one-letter named | |
3109 | * subroutine call (or a -bareword), then. */ | |
95c31fe3 | 3110 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
17ad61e0 | 3111 | "### '-%c' looked like a file test but was not\n", |
4fccd7c6 | 3112 | (int) tmp); |
5f80b19c | 3113 | } ); |
3cf7b4c4 | 3114 | s = --PL_bufptr; |
e5edeb50 | 3115 | } |
378cc40b | 3116 | } |
a687059c LW |
3117 | tmp = *s++; |
3118 | if (*s == tmp) { | |
3119 | s++; | |
3280af22 | 3120 | if (PL_expect == XOPERATOR) |
79072805 LW |
3121 | TERM(POSTDEC); |
3122 | else | |
3123 | OPERATOR(PREDEC); | |
3124 | } | |
3125 | else if (*s == '>') { | |
3126 | s++; | |
3127 | s = skipspace(s); | |
7e2040f0 | 3128 | if (isIDFIRST_lazy_if(s,UTF)) { |
a0d0e21e | 3129 | s = force_word(s,METHOD,FALSE,TRUE,FALSE); |
463ee0b2 | 3130 | TOKEN(ARROW); |
79072805 | 3131 | } |
748a9306 LW |
3132 | else if (*s == '$') |
3133 | OPERATOR(ARROW); | |
463ee0b2 | 3134 | else |
748a9306 | 3135 | TERM(ARROW); |
a687059c | 3136 | } |
3280af22 | 3137 | if (PL_expect == XOPERATOR) |
79072805 LW |
3138 | Aop(OP_SUBTRACT); |
3139 | else { | |
3280af22 | 3140 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) |
2f3197b3 | 3141 | check_uni(); |
79072805 | 3142 | OPERATOR('-'); /* unary minus */ |
2f3197b3 | 3143 | } |
79072805 | 3144 | |
378cc40b | 3145 | case '+': |
a687059c LW |
3146 | tmp = *s++; |
3147 | if (*s == tmp) { | |
378cc40b | 3148 | s++; |
3280af22 | 3149 | if (PL_expect == XOPERATOR) |
79072805 LW |
3150 | TERM(POSTINC); |
3151 | else | |
3152 | OPERATOR(PREINC); | |
378cc40b | 3153 | } |
3280af22 | 3154 | if (PL_expect == XOPERATOR) |
79072805 LW |
3155 | Aop(OP_ADD); |
3156 | else { | |
3280af22 | 3157 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) |
2f3197b3 | 3158 | check_uni(); |
a687059c | 3159 | OPERATOR('+'); |
2f3197b3 | 3160 | } |
a687059c | 3161 | |
378cc40b | 3162 | case '*': |
3280af22 NIS |
3163 | if (PL_expect != XOPERATOR) { |
3164 | s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); | |
3165 | PL_expect = XOPERATOR; | |
3166 | force_ident(PL_tokenbuf, '*'); | |
3167 | if (!*PL_tokenbuf) | |
a0d0e21e | 3168 | PREREF('*'); |
79072805 | 3169 | TERM('*'); |
a687059c | 3170 | } |
79072805 LW |
3171 | s++; |
3172 | if (*s == '*') { | |
a687059c | 3173 | s++; |
79072805 | 3174 | PWop(OP_POW); |
a687059c | 3175 | } |
79072805 LW |
3176 | Mop(OP_MULTIPLY); |
3177 | ||
378cc40b | 3178 | case '%': |
3280af22 | 3179 | if (PL_expect == XOPERATOR) { |
bbce6d69 | 3180 | ++s; |
3181 | Mop(OP_MODULO); | |
a687059c | 3182 | } |
3280af22 NIS |
3183 | PL_tokenbuf[0] = '%'; |
3184 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE); | |
3185 | if (!PL_tokenbuf[1]) { | |
bbce6d69 | 3186 | PREREF('%'); |
a687059c | 3187 | } |
3280af22 | 3188 | PL_pending_ident = '%'; |
bbce6d69 | 3189 | TERM('%'); |
a687059c | 3190 | |
378cc40b | 3191 | case '^': |
79072805 | 3192 | s++; |
a0d0e21e | 3193 | BOop(OP_BIT_XOR); |
79072805 | 3194 | case '[': |
3280af22 | 3195 | PL_lex_brackets++; |
79072805 | 3196 | /* FALL THROUGH */ |
378cc40b | 3197 | case '~': |
378cc40b | 3198 | case ',': |
378cc40b LW |
3199 | tmp = *s++; |
3200 | OPERATOR(tmp); | |
a0d0e21e LW |
3201 | case ':': |
3202 | if (s[1] == ':') { | |
3203 | len = 0; | |
3204 | goto just_a_word; | |
3205 | } | |
3206 | s++; | |
09bef843 SB |
3207 | switch (PL_expect) { |
3208 | OP *attrs; | |
3209 | case XOPERATOR: | |
3210 | if (!PL_in_my || PL_lex_state != LEX_NORMAL) | |
3211 | break; | |
3212 | PL_bufptr = s; /* update in case we back off */ | |
3213 | goto grabattrs; | |
3214 | case XATTRBLOCK: | |
3215 | PL_expect = XBLOCK; | |
3216 | goto grabattrs; | |
3217 | case XATTRTERM: | |
3218 | PL_expect = XTERMBLOCK; | |
3219 | grabattrs: | |
3220 | s = skipspace(s); | |
3221 | attrs = Nullop; | |
7e2040f0 | 3222 | while (isIDFIRST_lazy_if(s,UTF)) { |
09bef843 | 3223 | d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
f9829d6b GS |
3224 | if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) { |
3225 | if (tmp < 0) tmp = -tmp; | |
3226 | switch (tmp) { | |
3227 | case KEY_or: | |
3228 | case KEY_and: | |
c963b151 | 3229 | case KEY_err: |
f9829d6b GS |
3230 | case KEY_for: |
3231 | case KEY_unless: | |
3232 | case KEY_if: | |
3233 | case KEY_while: | |
3234 | case KEY_until: | |
3235 | goto got_attrs; | |
3236 | default: | |
3237 | break; | |
3238 | } | |
3239 | } | |
09bef843 SB |
3240 | if (*d == '(') { |
3241 | d = scan_str(d,TRUE,TRUE); | |
3242 | if (!d) { | |
09bef843 SB |
3243 | /* MUST advance bufptr here to avoid bogus |
3244 | "at end of line" context messages from yyerror(). | |
3245 | */ | |
3246 | PL_bufptr = s + len; | |
3247 | yyerror("Unterminated attribute parameter in attribute list"); | |
3248 | if (attrs) | |
3249 | op_free(attrs); | |
bbf60fe6 | 3250 | return REPORT(0); /* EOF indicator */ |
09bef843 SB |
3251 | } |
3252 | } | |
3253 | if (PL_lex_stuff) { | |
3254 | SV *sv = newSVpvn(s, len); | |
3255 | sv_catsv(sv, PL_lex_stuff); | |
3256 | attrs = append_elem(OP_LIST, attrs, | |
3257 | newSVOP(OP_CONST, 0, sv)); | |
3258 | SvREFCNT_dec(PL_lex_stuff); | |
3259 | PL_lex_stuff = Nullsv; | |
3260 | } | |
3261 | else { | |
371fce9b DM |
3262 | if (len == 6 && strnEQ(s, "unique", len)) { |
3263 | if (PL_in_my == KEY_our) | |
3264 | #ifdef USE_ITHREADS | |
3265 | GvUNIQUE_on(cGVOPx_gv(yylval.opval)); | |
3266 | #else | |
3267 | ; /* skip to avoid loading attributes.pm */ | |
3268 | #endif | |
bfed75c6 | 3269 | else |
371fce9b DM |
3270 | Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables"); |
3271 | } | |
3272 | ||
d3cea301 SB |
3273 | /* NOTE: any CV attrs applied here need to be part of |
3274 | the CVf_BUILTIN_ATTRS define in cv.h! */ | |
371fce9b | 3275 | else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len)) |
78f9721b SM |
3276 | CvLVALUE_on(PL_compcv); |
3277 | else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len)) | |
3278 | CvLOCKED_on(PL_compcv); | |
3279 | else if (!PL_in_my && len == 6 && strnEQ(s, "method", len)) | |
3280 | CvMETHOD_on(PL_compcv); | |
06492da6 SF |
3281 | else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len)) |
3282 | CvASSERTION_on(PL_compcv); | |
78f9721b SM |
3283 | /* After we've set the flags, it could be argued that |
3284 | we don't need to do the attributes.pm-based setting | |
3285 | process, and shouldn't bother appending recognized | |
d3cea301 SB |
3286 | flags. To experiment with that, uncomment the |
3287 | following "else". (Note that's already been | |
3288 | uncommented. That keeps the above-applied built-in | |
3289 | attributes from being intercepted (and possibly | |
3290 | rejected) by a package's attribute routines, but is | |
3291 | justified by the performance win for the common case | |
3292 | of applying only built-in attributes.) */ | |
0256094b | 3293 | else |
78f9721b SM |
3294 | attrs = append_elem(OP_LIST, attrs, |
3295 | newSVOP(OP_CONST, 0, | |
3296 | newSVpvn(s, len))); | |
09bef843 SB |
3297 | } |
3298 | s = skipspace(d); | |
0120eecf | 3299 | if (*s == ':' && s[1] != ':') |
09bef843 | 3300 | s = skipspace(s+1); |
0120eecf GS |
3301 | else if (s == d) |
3302 | break; /* require real whitespace or :'s */ | |
09bef843 | 3303 | } |
f9829d6b | 3304 | tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */ |
8e7ae056 | 3305 | if (*s != ';' && *s != '}' && *s != tmp && (tmp != '=' || *s != ')')) { |
f54cb97a | 3306 | const char q = ((*s == '\'') ? '"' : '\''); |
09bef843 SB |
3307 | /* If here for an expression, and parsed no attrs, back off. */ |
3308 | if (tmp == '=' && !attrs) { | |
3309 | s = PL_bufptr; | |
3310 | break; | |
3311 | } | |
3312 | /* MUST advance bufptr here to avoid bogus "at end of line" | |
3313 | context messages from yyerror(). | |
3314 | */ | |
3315 | PL_bufptr = s; | |
0bd48802 AL |
3316 | yyerror( *s |
3317 | ? Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list", q, *s, q) | |
3318 | : "Unterminated attribute list" ); | |
09bef843 SB |
3319 | if (attrs) |
3320 | op_free(attrs); | |
3321 | OPERATOR(':'); | |
3322 | } | |
f9829d6b | 3323 | got_attrs: |
09bef843 SB |
3324 | if (attrs) { |
3325 | PL_nextval[PL_nexttoke].opval = attrs; | |
3326 | force_next(THING); | |
3327 | } | |
3328 | TOKEN(COLONATTR); | |
3329 | } | |
a0d0e21e | 3330 | OPERATOR(':'); |
8990e307 LW |
3331 | case '(': |
3332 | s++; | |
3280af22 NIS |
3333 | if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr) |
3334 | PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */ | |
a0d0e21e | 3335 | else |
3280af22 | 3336 | PL_expect = XTERM; |
4a202259 | 3337 | s = skipspace(s); |
a0d0e21e | 3338 | TOKEN('('); |
378cc40b | 3339 | case ';': |
f4dd75d9 | 3340 | CLINE; |
378cc40b LW |
3341 | tmp = *s++; |
3342 | OPERATOR(tmp); | |
3343 | case ')': | |
378cc40b | 3344 | tmp = *s++; |
16d20bd9 AD |
3345 | s = skipspace(s); |
3346 | if (*s == '{') | |
3347 | PREBLOCK(tmp); | |
378cc40b | 3348 | TERM(tmp); |
79072805 LW |
3349 | case ']': |
3350 | s++; | |
3280af22 | 3351 | if (PL_lex_brackets <= 0) |
d98d5fff | 3352 | yyerror("Unmatched right square bracket"); |
463ee0b2 | 3353 | else |
3280af22 NIS |
3354 | --PL_lex_brackets; |
3355 | if (PL_lex_state == LEX_INTERPNORMAL) { | |
3356 | if (PL_lex_brackets == 0) { | |
a0d0e21e | 3357 | if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>')) |
3280af22 | 3358 | PL_lex_state = LEX_INTERPEND; |
79072805 LW |
3359 | } |
3360 | } | |
4633a7c4 | 3361 | TERM(']'); |
79072805 LW |
3362 | case '{': |
3363 | leftbracket: | |
79072805 | 3364 | s++; |
3280af22 | 3365 | if (PL_lex_brackets > 100) { |
8edd5f42 | 3366 | Renew(PL_lex_brackstack, PL_lex_brackets + 10, char); |
8990e307 | 3367 | } |
3280af22 | 3368 | switch (PL_expect) { |
a0d0e21e | 3369 | case XTERM: |
3280af22 | 3370 | if (PL_lex_formbrack) { |
a0d0e21e LW |
3371 | s--; |
3372 | PRETERMBLOCK(DO); | |
3373 | } | |
3280af22 NIS |
3374 | if (PL_oldoldbufptr == PL_last_lop) |
3375 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; | |
a0d0e21e | 3376 | else |
3280af22 | 3377 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
79072805 | 3378 | OPERATOR(HASHBRACK); |
a0d0e21e | 3379 | case XOPERATOR: |
bf4acbe4 | 3380 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
748a9306 | 3381 | s++; |
44a8e56a | 3382 | d = s; |
3280af22 NIS |
3383 | PL_tokenbuf[0] = '\0'; |
3384 | if (d < PL_bufend && *d == '-') { | |
3385 | PL_tokenbuf[0] = '-'; | |
44a8e56a | 3386 | d++; |
bf4acbe4 | 3387 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
44a8e56a | 3388 | d++; |
3389 | } | |
7e2040f0 | 3390 | if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) { |
3280af22 | 3391 | d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, |
8903cb82 | 3392 | FALSE, &len); |
bf4acbe4 | 3393 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
748a9306 LW |
3394 | d++; |
3395 | if (*d == '}') { | |
f54cb97a | 3396 | const char minus = (PL_tokenbuf[0] == '-'); |
44a8e56a | 3397 | s = force_word(s + minus, WORD, FALSE, TRUE, FALSE); |
3398 | if (minus) | |
3399 | force_next('-'); | |
748a9306 LW |
3400 | } |
3401 | } | |
3402 | /* FALL THROUGH */ | |
09bef843 | 3403 | case XATTRBLOCK: |
748a9306 | 3404 | case XBLOCK: |
3280af22 NIS |
3405 | PL_lex_brackstack[PL_lex_brackets++] = XSTATE; |
3406 | PL_expect = XSTATE; | |
a0d0e21e | 3407 | break; |
09bef843 | 3408 | case XATTRTERM: |
a0d0e21e | 3409 | case XTERMBLOCK: |
3280af22 NIS |
3410 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
3411 | PL_expect = XSTATE; | |
a0d0e21e LW |
3412 | break; |
3413 | default: { | |
f54cb97a | 3414 | const char *t; |
3280af22 NIS |
3415 | if (PL_oldoldbufptr == PL_last_lop) |
3416 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; | |
a0d0e21e | 3417 | else |
3280af22 | 3418 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
a0d0e21e | 3419 | s = skipspace(s); |
8452ff4b SB |
3420 | if (*s == '}') { |
3421 | if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) { | |
3422 | PL_expect = XTERM; | |
3423 | /* This hack is to get the ${} in the message. */ | |
3424 | PL_bufptr = s+1; | |
3425 | yyerror("syntax error"); | |
3426 | break; | |
3427 | } | |
a0d0e21e | 3428 | OPERATOR(HASHBRACK); |
8452ff4b | 3429 | } |
b8a4b1be GS |
3430 | /* This hack serves to disambiguate a pair of curlies |
3431 | * as being a block or an anon hash. Normally, expectation | |
3432 | * determines that, but in cases where we're not in a | |
3433 | * position to expect anything in particular (like inside | |
3434 | * eval"") we have to resolve the ambiguity. This code | |
3435 | * covers the case where the first term in the curlies is a | |
3436 | * quoted string. Most other cases need to be explicitly | |
a0288114 | 3437 | * disambiguated by prepending a "+" before the opening |
b8a4b1be GS |
3438 | * curly in order to force resolution as an anon hash. |
3439 | * | |
3440 | * XXX should probably propagate the outer expectation | |
3441 | * into eval"" to rely less on this hack, but that could | |
3442 | * potentially break current behavior of eval"". | |
3443 | * GSAR 97-07-21 | |
3444 | */ | |
3445 | t = s; | |
3446 | if (*s == '\'' || *s == '"' || *s == '`') { | |
3447 | /* common case: get past first string, handling escapes */ | |
3280af22 | 3448 | for (t++; t < PL_bufend && *t != *s;) |
b8a4b1be GS |
3449 | if (*t++ == '\\' && (*t == '\\' || *t == *s)) |
3450 | t++; | |
3451 | t++; | |
a0d0e21e | 3452 | } |
b8a4b1be | 3453 | else if (*s == 'q') { |
3280af22 | 3454 | if (++t < PL_bufend |
b8a4b1be | 3455 | && (!isALNUM(*t) |
3280af22 | 3456 | || ((*t == 'q' || *t == 'x') && ++t < PL_bufend |
0505442f GS |
3457 | && !isALNUM(*t)))) |
3458 | { | |
abc667d1 | 3459 | /* skip q//-like construct */ |
f54cb97a | 3460 | const char *tmps; |
b8a4b1be GS |
3461 | char open, close, term; |
3462 | I32 brackets = 1; | |
3463 | ||
3280af22 | 3464 | while (t < PL_bufend && isSPACE(*t)) |
b8a4b1be | 3465 | t++; |
abc667d1 DM |
3466 | /* check for q => */ |
3467 | if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') { | |
3468 | OPERATOR(HASHBRACK); | |
3469 | } | |
b8a4b1be GS |
3470 | term = *t; |
3471 | open = term; | |
3472 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) | |
3473 | term = tmps[5]; | |
3474 | close = term; | |
3475 | if (open == close) | |
3280af22 NIS |
3476 | for (t++; t < PL_bufend; t++) { |
3477 | if (*t == '\\' && t+1 < PL_bufend && open != '\\') | |
b8a4b1be | 3478 | t++; |
6d07e5e9 | 3479 | else if (*t == open) |
b8a4b1be GS |
3480 | break; |
3481 | } | |
abc667d1 | 3482 | else { |
3280af22 NIS |
3483 | for (t++; t < PL_bufend; t++) { |
3484 | if (*t == '\\' && t+1 < PL_bufend) | |
b8a4b1be | 3485 | t++; |
6d07e5e9 | 3486 | else if (*t == close && --brackets <= 0) |
b8a4b1be GS |
3487 | break; |
3488 | else if (*t == open) | |
3489 | brackets++; | |
3490 | } | |
abc667d1 DM |
3491 | } |
3492 | t++; | |
b8a4b1be | 3493 | } |
abc667d1 DM |
3494 | else |
3495 | /* skip plain q word */ | |
3496 | while (t < PL_bufend && isALNUM_lazy_if(t,UTF)) | |
3497 | t += UTF8SKIP(t); | |
a0d0e21e | 3498 | } |
7e2040f0 | 3499 | else if (isALNUM_lazy_if(t,UTF)) { |
0505442f | 3500 | t += UTF8SKIP(t); |
7e2040f0 | 3501 | while (t < PL_bufend && isALNUM_lazy_if(t,UTF)) |
0505442f | 3502 | t += UTF8SKIP(t); |
a0d0e21e | 3503 | } |
3280af22 | 3504 | while (t < PL_bufend && isSPACE(*t)) |
a0d0e21e | 3505 | t++; |
b8a4b1be GS |
3506 | /* if comma follows first term, call it an anon hash */ |
3507 | /* XXX it could be a comma expression with loop modifiers */ | |
3280af22 | 3508 | if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s))) |
b8a4b1be | 3509 | || (*t == '=' && t[1] == '>'))) |
a0d0e21e | 3510 | OPERATOR(HASHBRACK); |
3280af22 | 3511 | if (PL_expect == XREF) |
4e4e412b | 3512 | PL_expect = XTERM; |
a0d0e21e | 3513 | else { |
3280af22 NIS |
3514 | PL_lex_brackstack[PL_lex_brackets-1] = XSTATE; |
3515 | PL_expect = XSTATE; | |
a0d0e21e | 3516 | } |
8990e307 | 3517 | } |
a0d0e21e | 3518 | break; |
463ee0b2 | 3519 | } |
57843af0 | 3520 | yylval.ival = CopLINE(PL_curcop); |
79072805 | 3521 | if (isSPACE(*s) || *s == '#') |
3280af22 | 3522 | PL_copline = NOLINE; /* invalidate current command line number */ |
79072805 | 3523 | TOKEN('{'); |
378cc40b | 3524 | case '}': |
79072805 LW |
3525 | rightbracket: |
3526 | s++; | |
3280af22 | 3527 | if (PL_lex_brackets <= 0) |
d98d5fff | 3528 | yyerror("Unmatched right curly bracket"); |
463ee0b2 | 3529 | else |
3280af22 | 3530 | PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets]; |
c2e66d9e | 3531 | if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL) |
3280af22 NIS |
3532 | PL_lex_formbrack = 0; |
3533 | if (PL_lex_state == LEX_INTERPNORMAL) { | |
3534 | if (PL_lex_brackets == 0) { | |
9059aa12 LW |
3535 | if (PL_expect & XFAKEBRACK) { |
3536 | PL_expect &= XENUMMASK; | |
3280af22 NIS |
3537 | PL_lex_state = LEX_INTERPEND; |
3538 | PL_bufptr = s; | |
cea2e8a9 | 3539 | return yylex(); /* ignore fake brackets */ |
79072805 | 3540 | } |
fa83b5b6 | 3541 | if (*s == '-' && s[1] == '>') |
3280af22 | 3542 | PL_lex_state = LEX_INTERPENDMAYBE; |
fa83b5b6 | 3543 | else if (*s != '[' && *s != '{') |
3280af22 | 3544 | PL_lex_state = LEX_INTERPEND; |
79072805 LW |
3545 | } |
3546 | } | |
9059aa12 LW |
3547 | if (PL_expect & XFAKEBRACK) { |
3548 | PL_expect &= XENUMMASK; | |
3280af22 | 3549 | PL_bufptr = s; |
cea2e8a9 | 3550 | return yylex(); /* ignore fake brackets */ |
748a9306 | 3551 | } |
79072805 LW |
3552 | force_next('}'); |
3553 | TOKEN(';'); | |
378cc40b LW |
3554 | case '&': |
3555 | s++; | |
3556 | tmp = *s++; | |
3557 | if (tmp == '&') | |
a0d0e21e | 3558 | AOPERATOR(ANDAND); |
378cc40b | 3559 | s--; |
3280af22 | 3560 | if (PL_expect == XOPERATOR) { |
041457d9 DM |
3561 | if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON) |
3562 | && isIDFIRST_lazy_if(s,UTF)) | |
7e2040f0 | 3563 | { |
57843af0 | 3564 | CopLINE_dec(PL_curcop); |
9014280d | 3565 | Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi); |
57843af0 | 3566 | CopLINE_inc(PL_curcop); |
463ee0b2 | 3567 | } |
79072805 | 3568 | BAop(OP_BIT_AND); |
463ee0b2 | 3569 | } |
79072805 | 3570 | |
3280af22 NIS |
3571 | s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); |
3572 | if (*PL_tokenbuf) { | |
3573 | PL_expect = XOPERATOR; | |
3574 | force_ident(PL_tokenbuf, '&'); | |
463ee0b2 | 3575 | } |
79072805 LW |
3576 | else |
3577 | PREREF('&'); | |
c07a80fd | 3578 | yylval.ival = (OPpENTERSUB_AMPER<<8); |
79072805 LW |
3579 | TERM('&'); |
3580 | ||
378cc40b LW |
3581 | case '|': |
3582 | s++; | |
3583 | tmp = *s++; | |
3584 | if (tmp == '|') | |
a0d0e21e | 3585 | AOPERATOR(OROR); |
378cc40b | 3586 | s--; |
79072805 | 3587 | BOop(OP_BIT_OR); |
378cc40b LW |
3588 | case '=': |
3589 | s++; | |
3590 | tmp = *s++; | |
3591 | if (tmp == '=') | |
79072805 LW |
3592 | Eop(OP_EQ); |
3593 | if (tmp == '>') | |
3594 | OPERATOR(','); | |
378cc40b | 3595 | if (tmp == '~') |
79072805 | 3596 | PMop(OP_MATCH); |
ce44635a | 3597 | if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX) && strchr("+-*/%.^&|<",tmp)) |
9014280d | 3598 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Reversed %c= operator",(int)tmp); |
378cc40b | 3599 | s--; |
3280af22 NIS |
3600 | if (PL_expect == XSTATE && isALPHA(tmp) && |
3601 | (s == PL_linestart+1 || s[-2] == '\n') ) | |
748a9306 | 3602 | { |
3280af22 NIS |
3603 | if (PL_in_eval && !PL_rsfp) { |
3604 | d = PL_bufend; | |
a5f75d66 AD |
3605 | while (s < d) { |
3606 | if (*s++ == '\n') { | |
3607 | incline(s); | |
3608 | if (strnEQ(s,"=cut",4)) { | |
3609 | s = strchr(s,'\n'); | |
3610 | if (s) | |
3611 | s++; | |
3612 | else | |
3613 | s = d; | |
3614 | incline(s); | |
3615 | goto retry; | |
3616 | } | |
3617 | } | |
3618 | } | |
3619 | goto retry; | |
3620 | } | |
3280af22 NIS |
3621 | s = PL_bufend; |
3622 | PL_doextract = TRUE; | |
a0d0e21e LW |
3623 | goto retry; |
3624 | } | |
3280af22 | 3625 | if (PL_lex_brackets < PL_lex_formbrack) { |
f54cb97a | 3626 | const char *t; |
51882d45 | 3627 | #ifdef PERL_STRICT_CR |
bf4acbe4 | 3628 | for (t = s; SPACE_OR_TAB(*t); t++) ; |
51882d45 | 3629 | #else |
bf4acbe4 | 3630 | for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ; |
51882d45 | 3631 | #endif |
a0d0e21e LW |
3632 | if (*t == '\n' || *t == '#') { |
3633 | s--; | |
3280af22 | 3634 | PL_expect = XBLOCK; |
a0d0e21e LW |
3635 | goto leftbracket; |
3636 | } | |
79072805 | 3637 | } |
a0d0e21e LW |
3638 | yylval.ival = 0; |
3639 | OPERATOR(ASSIGNOP); | |
378cc40b LW |
3640 | case '!': |
3641 | s++; | |
3642 | tmp = *s++; | |
984200d0 | 3643 | if (tmp == '=') { |
decca21c YST |
3644 | /* was this !=~ where !~ was meant? |
3645 | * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */ | |
3646 | ||
984200d0 | 3647 | if (*s == '~' && ckWARN(WARN_SYNTAX)) { |
f54cb97a | 3648 | const char *t = s+1; |
984200d0 YST |
3649 | |
3650 | while (t < PL_bufend && isSPACE(*t)) | |
3651 | ++t; | |
3652 | ||
decca21c YST |
3653 | if (*t == '/' || *t == '?' || |
3654 | ((*t == 'm' || *t == 's' || *t == 'y') && !isALNUM(t[1])) || | |
3655 | (*t == 't' && t[1] == 'r' && !isALNUM(t[2]))) | |
984200d0 YST |
3656 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
3657 | "!=~ should be !~"); | |
3658 | } | |
79072805 | 3659 | Eop(OP_NE); |
984200d0 | 3660 | } |
378cc40b | 3661 | if (tmp == '~') |
79072805 | 3662 | PMop(OP_NOT); |
378cc40b LW |
3663 | s--; |
3664 | OPERATOR('!'); | |
3665 | case '<': | |
3280af22 | 3666 | if (PL_expect != XOPERATOR) { |
93a17b20 | 3667 | if (s[1] != '<' && !strchr(s,'>')) |
2f3197b3 | 3668 | check_uni(); |
79072805 LW |
3669 | if (s[1] == '<') |
3670 | s = scan_heredoc(s); | |
3671 | else | |
3672 | s = scan_inputsymbol(s); | |
3673 | TERM(sublex_start()); | |
378cc40b LW |
3674 | } |
3675 | s++; | |
3676 | tmp = *s++; | |
3677 | if (tmp == '<') | |
79072805 | 3678 | SHop(OP_LEFT_SHIFT); |
395c3793 LW |
3679 | if (tmp == '=') { |
3680 | tmp = *s++; | |
3681 | if (tmp == '>') | |
79072805 | 3682 | Eop(OP_NCMP); |
395c3793 | 3683 | s--; |
79072805 | 3684 | Rop(OP_LE); |
395c3793 | 3685 | } |
378cc40b | 3686 | s--; |
79072805 | 3687 | Rop(OP_LT); |
378cc40b LW |
3688 | case '>': |
3689 | s++; | |
3690 | tmp = *s++; | |
3691 | if (tmp == '>') | |
79072805 | 3692 | SHop(OP_RIGHT_SHIFT); |
378cc40b | 3693 | if (tmp == '=') |
79072805 | 3694 | Rop(OP_GE); |
378cc40b | 3695 | s--; |
79072805 | 3696 | Rop(OP_GT); |
378cc40b LW |
3697 | |
3698 | case '$': | |
bbce6d69 | 3699 | CLINE; |
3700 | ||
3280af22 NIS |
3701 | if (PL_expect == XOPERATOR) { |
3702 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3703 | PL_expect = XTERM; | |
a0d0e21e | 3704 | depcom(); |
bbf60fe6 | 3705 | return REPORT(','); /* grandfather non-comma-format format */ |
a0d0e21e | 3706 | } |
8990e307 | 3707 | } |
a0d0e21e | 3708 | |
7e2040f0 | 3709 | if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) { |
3280af22 | 3710 | PL_tokenbuf[0] = '@'; |
376b8730 SM |
3711 | s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1, |
3712 | sizeof PL_tokenbuf - 1, FALSE); | |
3713 | if (PL_expect == XOPERATOR) | |
3714 | no_op("Array length", s); | |
3280af22 | 3715 | if (!PL_tokenbuf[1]) |
a0d0e21e | 3716 | PREREF(DOLSHARP); |
3280af22 NIS |
3717 | PL_expect = XOPERATOR; |
3718 | PL_pending_ident = '#'; | |
463ee0b2 | 3719 | TOKEN(DOLSHARP); |
79072805 | 3720 | } |
bbce6d69 | 3721 | |
3280af22 | 3722 | PL_tokenbuf[0] = '$'; |
376b8730 SM |
3723 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, |
3724 | sizeof PL_tokenbuf - 1, FALSE); | |
3725 | if (PL_expect == XOPERATOR) | |
3726 | no_op("Scalar", s); | |
3280af22 NIS |
3727 | if (!PL_tokenbuf[1]) { |
3728 | if (s == PL_bufend) | |
bbce6d69 | 3729 | yyerror("Final $ should be \\$ or $name"); |
3730 | PREREF('$'); | |
8990e307 | 3731 | } |
a0d0e21e | 3732 | |
bbce6d69 | 3733 | /* This kludge not intended to be bulletproof. */ |
3280af22 | 3734 | if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) { |
bbce6d69 | 3735 | yylval.opval = newSVOP(OP_CONST, 0, |
b448e4fe | 3736 | newSViv(PL_compiling.cop_arybase)); |
bbce6d69 | 3737 | yylval.opval->op_private = OPpCONST_ARYBASE; |
3738 | TERM(THING); | |
3739 | } | |
3740 | ||
ff68c719 | 3741 | d = s; |
69d2bceb | 3742 | tmp = (I32)*s; |
3280af22 | 3743 | if (PL_lex_state == LEX_NORMAL) |
ff68c719 | 3744 | s = skipspace(s); |
3745 | ||
3280af22 | 3746 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) { |
bbce6d69 | 3747 | if (*s == '[') { |
3280af22 | 3748 | PL_tokenbuf[0] = '@'; |
599cee73 | 3749 | if (ckWARN(WARN_SYNTAX)) { |
b64e5050 | 3750 | char *t; |
bbce6d69 | 3751 | for(t = s + 1; |
7e2040f0 | 3752 | isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$'; |
bbce6d69 | 3753 | t++) ; |
a0d0e21e | 3754 | if (*t++ == ',') { |
3280af22 NIS |
3755 | PL_bufptr = skipspace(PL_bufptr); |
3756 | while (t < PL_bufend && *t != ']') | |
bbce6d69 | 3757 | t++; |
9014280d | 3758 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
599cee73 PM |
3759 | "Multidimensional syntax %.*s not supported", |
3760 | (t - PL_bufptr) + 1, PL_bufptr); | |
a0d0e21e LW |
3761 | } |
3762 | } | |
bbce6d69 | 3763 | } |
3764 | else if (*s == '{') { | |
b64e5050 | 3765 | char *t; |
3280af22 | 3766 | PL_tokenbuf[0] = '%'; |
ce44635a DM |
3767 | if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX) |
3768 | && (t = strchr(s, '}')) && (t = strchr(t, '='))) | |
bbce6d69 | 3769 | { |
3280af22 | 3770 | char tmpbuf[sizeof PL_tokenbuf]; |
a0d0e21e | 3771 | for (t++; isSPACE(*t); t++) ; |
7e2040f0 | 3772 | if (isIDFIRST_lazy_if(t,UTF)) { |
f54cb97a | 3773 | STRLEN len; |
8903cb82 | 3774 | t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len); |
59a6d928 | 3775 | for (; isSPACE(*t); t++) ; |
864dbfa3 | 3776 | if (*t == ';' && get_cv(tmpbuf, FALSE)) |
9014280d | 3777 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
599cee73 | 3778 | "You need to quote \"%s\"", tmpbuf); |
748a9306 | 3779 | } |
93a17b20 LW |
3780 | } |
3781 | } | |
2f3197b3 | 3782 | } |
bbce6d69 | 3783 | |
3280af22 | 3784 | PL_expect = XOPERATOR; |
69d2bceb | 3785 | if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) { |
f54cb97a | 3786 | const bool islop = (PL_last_lop == PL_oldoldbufptr); |
3280af22 NIS |
3787 | if (!islop || PL_last_lop_op == OP_GREPSTART) |
3788 | PL_expect = XOPERATOR; | |
bbce6d69 | 3789 | else if (strchr("$@\"'`q", *s)) |
3280af22 | 3790 | PL_expect = XTERM; /* e.g. print $fh "foo" */ |
7e2040f0 | 3791 | else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF)) |
3280af22 | 3792 | PL_expect = XTERM; /* e.g. print $fh &sub */ |
7e2040f0 | 3793 | else if (isIDFIRST_lazy_if(s,UTF)) { |
3280af22 | 3794 | char tmpbuf[sizeof PL_tokenbuf]; |
8903cb82 | 3795 | scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
155aba94 | 3796 | if ((tmp = keyword(tmpbuf, len))) { |
84902520 TB |
3797 | /* binary operators exclude handle interpretations */ |
3798 | switch (tmp) { | |
3799 | case -KEY_x: | |
3800 | case -KEY_eq: | |
3801 | case -KEY_ne: | |
3802 | case -KEY_gt: | |
3803 | case -KEY_lt: | |
3804 | case -KEY_ge: | |
3805 | case -KEY_le: | |
3806 | case -KEY_cmp: | |
3807 | break; | |
3808 | default: | |
3280af22 | 3809 | PL_expect = XTERM; /* e.g. print $fh length() */ |
84902520 TB |
3810 | break; |
3811 | } | |
3812 | } | |
68dc0745 | 3813 | else { |
8a8635f0 | 3814 | PL_expect = XTERM; /* e.g. print $fh subr() */ |
93a17b20 | 3815 | } |
93a17b20 | 3816 | } |
bbce6d69 | 3817 | else if (isDIGIT(*s)) |
3280af22 | 3818 | PL_expect = XTERM; /* e.g. print $fh 3 */ |
bbce6d69 | 3819 | else if (*s == '.' && isDIGIT(s[1])) |
3280af22 | 3820 | PL_expect = XTERM; /* e.g. print $fh .3 */ |
3792a11b NC |
3821 | else if ((*s == '?' || *s == '-' || *s == '+') |
3822 | && !isSPACE(s[1]) && s[1] != '=') | |
c963b151 | 3823 | PL_expect = XTERM; /* e.g. print $fh -1 */ |
7ce6e6b9 RGS |
3824 | else if (*s == '/' && !isSPACE(s[1]) && s[1] != '=' && s[1] != '/') |
3825 | PL_expect = XTERM; /* e.g. print $fh /.../ | |
3826 | XXX except DORDOR operator */ | |
e0587a03 | 3827 | else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=') |
3280af22 | 3828 | PL_expect = XTERM; /* print $fh <<"EOF" */ |
bbce6d69 | 3829 | } |
3280af22 | 3830 | PL_pending_ident = '$'; |
79072805 | 3831 | TOKEN('$'); |
378cc40b LW |
3832 | |
3833 | case '@': | |
3280af22 | 3834 | if (PL_expect == XOPERATOR) |
bbce6d69 | 3835 | no_op("Array", s); |
3280af22 NIS |
3836 | PL_tokenbuf[0] = '@'; |
3837 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE); | |
3838 | if (!PL_tokenbuf[1]) { | |
bbce6d69 | 3839 | PREREF('@'); |
3840 | } | |
3280af22 | 3841 | if (PL_lex_state == LEX_NORMAL) |
ff68c719 | 3842 | s = skipspace(s); |
3280af22 | 3843 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) { |
bbce6d69 | 3844 | if (*s == '{') |
3280af22 | 3845 | PL_tokenbuf[0] = '%'; |
a0d0e21e LW |
3846 | |
3847 | /* Warn about @ where they meant $. */ | |
041457d9 DM |
3848 | if (*s == '[' || *s == '{') { |
3849 | if (ckWARN(WARN_SYNTAX)) { | |
f54cb97a | 3850 | const char *t = s + 1; |
7e2040f0 | 3851 | while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t))) |
a0d0e21e LW |
3852 | t++; |
3853 | if (*t == '}' || *t == ']') { | |
3854 | t++; | |
3280af22 | 3855 | PL_bufptr = skipspace(PL_bufptr); |
9014280d | 3856 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
599cee73 | 3857 | "Scalar value %.*s better written as $%.*s", |
3280af22 | 3858 | t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1); |
a0d0e21e | 3859 | } |
93a17b20 LW |
3860 | } |
3861 | } | |
463ee0b2 | 3862 | } |
3280af22 | 3863 | PL_pending_ident = '@'; |
79072805 | 3864 | TERM('@'); |
378cc40b | 3865 | |
c963b151 | 3866 | case '/': /* may be division, defined-or, or pattern */ |
6f33ba73 RGS |
3867 | if (PL_expect == XTERMORDORDOR && s[1] == '/') { |
3868 | s += 2; | |
3869 | AOPERATOR(DORDOR); | |
3870 | } | |
c963b151 BD |
3871 | case '?': /* may either be conditional or pattern */ |
3872 | if(PL_expect == XOPERATOR) { | |
3873 | tmp = *s++; | |
3874 | if(tmp == '?') { | |
3875 | OPERATOR('?'); | |
3876 | } | |
3877 | else { | |
3878 | tmp = *s++; | |
3879 | if(tmp == '/') { | |
3880 | /* A // operator. */ | |
3881 | AOPERATOR(DORDOR); | |
3882 | } | |
3883 | else { | |
3884 | s--; | |
3885 | Mop(OP_DIVIDE); | |
3886 | } | |
3887 | } | |
3888 | } | |
3889 | else { | |
3890 | /* Disable warning on "study /blah/" */ | |
3891 | if (PL_oldoldbufptr == PL_last_uni | |
3892 | && (*PL_last_uni != 's' || s - PL_last_uni < 5 | |
3893 | || memNE(PL_last_uni, "study", 5) | |
3894 | || isALNUM_lazy_if(PL_last_uni+5,UTF) | |
3895 | )) | |
3896 | check_uni(); | |
3897 | s = scan_pat(s,OP_MATCH); | |
3898 | TERM(sublex_start()); | |
3899 | } | |
378cc40b LW |
3900 | |
3901 | case '.': | |
51882d45 GS |
3902 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack |
3903 | #ifdef PERL_STRICT_CR | |
3904 | && s[1] == '\n' | |
3905 | #else | |
3906 | && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n')) | |
3907 | #endif | |
3908 | && (s == PL_linestart || s[-1] == '\n') ) | |
3909 | { | |
3280af22 NIS |
3910 | PL_lex_formbrack = 0; |
3911 | PL_expect = XSTATE; | |
79072805 LW |
3912 | goto rightbracket; |
3913 | } | |
3280af22 | 3914 | if (PL_expect == XOPERATOR || !isDIGIT(s[1])) { |
378cc40b | 3915 | tmp = *s++; |
a687059c LW |
3916 | if (*s == tmp) { |
3917 | s++; | |
2f3197b3 LW |
3918 | if (*s == tmp) { |
3919 | s++; | |
79072805 | 3920 | yylval.ival = OPf_SPECIAL; |
2f3197b3 LW |
3921 | } |
3922 | else | |
79072805 | 3923 | yylval.ival = 0; |
378cc40b | 3924 | OPERATOR(DOTDOT); |
a687059c | 3925 | } |
3280af22 | 3926 | if (PL_expect != XOPERATOR) |
2f3197b3 | 3927 | check_uni(); |
79072805 | 3928 | Aop(OP_CONCAT); |
378cc40b LW |
3929 | } |
3930 | /* FALL THROUGH */ | |
3931 | case '0': case '1': case '2': case '3': case '4': | |
3932 | case '5': case '6': case '7': case '8': case '9': | |
b73d6f50 | 3933 | s = scan_num(s, &yylval); |
b6007c36 | 3934 | DEBUG_T( { S_printbuf(aTHX_ "### Saw number in %s\n", s); } ); |
3280af22 | 3935 | if (PL_expect == XOPERATOR) |
8990e307 | 3936 | no_op("Number",s); |
79072805 LW |
3937 | TERM(THING); |
3938 | ||
3939 | case '\'': | |
09bef843 | 3940 | s = scan_str(s,FALSE,FALSE); |
b6007c36 | 3941 | DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } ); |
3280af22 NIS |
3942 | if (PL_expect == XOPERATOR) { |
3943 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3944 | PL_expect = XTERM; | |
a0d0e21e | 3945 | depcom(); |
bbf60fe6 | 3946 | return REPORT(','); /* grandfather non-comma-format format */ |
a0d0e21e | 3947 | } |
463ee0b2 | 3948 | else |
8990e307 | 3949 | no_op("String",s); |
463ee0b2 | 3950 | } |
79072805 | 3951 | if (!s) |
85e6fe83 | 3952 | missingterm((char*)0); |
79072805 LW |
3953 | yylval.ival = OP_CONST; |
3954 | TERM(sublex_start()); | |
3955 | ||
3956 | case '"': | |
09bef843 | 3957 | s = scan_str(s,FALSE,FALSE); |
b6007c36 | 3958 | DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } ); |
3280af22 NIS |
3959 | if (PL_expect == XOPERATOR) { |
3960 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3961 | PL_expect = XTERM; | |
a0d0e21e | 3962 | depcom(); |
bbf60fe6 | 3963 | return REPORT(','); /* grandfather non-comma-format format */ |
a0d0e21e | 3964 | } |
463ee0b2 | 3965 | else |
8990e307 | 3966 | no_op("String",s); |
463ee0b2 | 3967 | } |
79072805 | 3968 | if (!s) |
85e6fe83 | 3969 | missingterm((char*)0); |
4633a7c4 | 3970 | yylval.ival = OP_CONST; |
cfd0369c NC |
3971 | /* FIXME. I think that this can be const if char *d is replaced by |
3972 | more localised variables. */ | |
3280af22 | 3973 | for (d = SvPV(PL_lex_stuff, len); len; len--, d++) { |
63cd0674 | 3974 | if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) { |
4633a7c4 LW |
3975 | yylval.ival = OP_STRINGIFY; |
3976 | break; | |
3977 | } | |
3978 | } | |
79072805 LW |
3979 | TERM(sublex_start()); |
3980 | ||
3981 | case '`': | |
09bef843 | 3982 | s = scan_str(s,FALSE,FALSE); |
b6007c36 | 3983 | DEBUG_T( { S_printbuf(aTHX_ "### Saw backtick string before %s\n", s); } ); |
3280af22 | 3984 | if (PL_expect == XOPERATOR) |
8990e307 | 3985 | no_op("Backticks",s); |
79072805 | 3986 | if (!s) |
85e6fe83 | 3987 | missingterm((char*)0); |
79072805 LW |
3988 | yylval.ival = OP_BACKTICK; |
3989 | set_csh(); | |
3990 | TERM(sublex_start()); | |
3991 | ||
3992 | case '\\': | |
3993 | s++; | |
041457d9 | 3994 | if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX)) |
9014280d | 3995 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression", |
599cee73 | 3996 | *s, *s); |
3280af22 | 3997 | if (PL_expect == XOPERATOR) |
8990e307 | 3998 | no_op("Backslash",s); |
79072805 LW |
3999 | OPERATOR(REFGEN); |
4000 | ||
a7cb1f99 | 4001 | case 'v': |
e526c9e6 | 4002 | if (isDIGIT(s[1]) && PL_expect != XOPERATOR) { |
f54cb97a | 4003 | char *start = s + 2; |
dd629d5b | 4004 | while (isDIGIT(*start) || *start == '_') |
a7cb1f99 GS |
4005 | start++; |
4006 | if (*start == '.' && isDIGIT(start[1])) { | |
b73d6f50 | 4007 | s = scan_num(s, &yylval); |
a7cb1f99 GS |
4008 | TERM(THING); |
4009 | } | |
e526c9e6 | 4010 | /* avoid v123abc() or $h{v1}, allow C<print v10;> */ |
6f33ba73 RGS |
4011 | else if (!isALPHA(*start) && (PL_expect == XTERM |
4012 | || PL_expect == XREF || PL_expect == XSTATE | |
4013 | || PL_expect == XTERMORDORDOR)) { | |
f54cb97a | 4014 | const char c = *start; |
e526c9e6 GS |
4015 | GV *gv; |
4016 | *start = '\0'; | |
4017 | gv = gv_fetchpv(s, FALSE, SVt_PVCV); | |
4018 | *start = c; | |
4019 | if (!gv) { | |
b73d6f50 | 4020 | s = scan_num(s, &yylval); |
e526c9e6 GS |
4021 | TERM(THING); |
4022 | } | |
4023 | } | |
a7cb1f99 GS |
4024 | } |
4025 | goto keylookup; | |
79072805 | 4026 | case 'x': |
3280af22 | 4027 | if (isDIGIT(s[1]) && PL_expect == XOPERATOR) { |
79072805 LW |
4028 | s++; |
4029 | Mop(OP_REPEAT); | |
2f3197b3 | 4030 | } |
79072805 LW |
4031 | goto keylookup; |
4032 | ||
378cc40b | 4033 | case '_': |
79072805 LW |
4034 | case 'a': case 'A': |
4035 | case 'b': case 'B': | |
4036 | case 'c': case 'C': | |
4037 | case 'd': case 'D': | |
4038 | case 'e': case 'E': | |
4039 | case 'f': case 'F': | |
4040 | case 'g': case 'G': | |
4041 | case 'h': case 'H': | |
4042 | case 'i': case 'I': | |
4043 | case 'j': case 'J': | |
4044 | case 'k': case 'K': | |
4045 | case 'l': case 'L': | |
4046 | case 'm': case 'M': | |
4047 | case 'n': case 'N': | |
4048 | case 'o': case 'O': | |
4049 | case 'p': case 'P': | |
4050 | case 'q': case 'Q': | |
4051 | case 'r': case 'R': | |
4052 | case 's': case 'S': | |
4053 | case 't': case 'T': | |
4054 | case 'u': case 'U': | |
a7cb1f99 | 4055 | case 'V': |
79072805 LW |
4056 | case 'w': case 'W': |
4057 | case 'X': | |
4058 | case 'y': case 'Y': | |
4059 | case 'z': case 'Z': | |
4060 | ||
49dc05e3 | 4061 | keylookup: { |
1d239bbb | 4062 | orig_keyword = 0; |
161b471a NIS |
4063 | gv = Nullgv; |
4064 | gvp = 0; | |
49dc05e3 | 4065 | |
3280af22 NIS |
4066 | PL_bufptr = s; |
4067 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); | |
8ebc5c01 | 4068 | |
4069 | /* Some keywords can be followed by any delimiter, including ':' */ | |
155aba94 GS |
4070 | tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) || |
4071 | (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') || | |
4072 | (PL_tokenbuf[0] == 'q' && | |
4073 | strchr("qwxr", PL_tokenbuf[1]))))); | |
8ebc5c01 | 4074 | |
4075 | /* x::* is just a word, unless x is "CORE" */ | |
3280af22 | 4076 | if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE")) |
4633a7c4 LW |
4077 | goto just_a_word; |
4078 | ||
3643fb5f | 4079 | d = s; |
3280af22 | 4080 | while (d < PL_bufend && isSPACE(*d)) |
3643fb5f CS |
4081 | d++; /* no comments skipped here, or s### is misparsed */ |
4082 | ||
4083 | /* Is this a label? */ | |
3280af22 NIS |
4084 | if (!tmp && PL_expect == XSTATE |
4085 | && d < PL_bufend && *d == ':' && *(d + 1) != ':') { | |
8ebc5c01 | 4086 | s = d + 1; |
3280af22 | 4087 | yylval.pval = savepv(PL_tokenbuf); |
8ebc5c01 | 4088 | CLINE; |
4089 | TOKEN(LABEL); | |
3643fb5f CS |
4090 | } |
4091 | ||
4092 | /* Check for keywords */ | |
3280af22 | 4093 | tmp = keyword(PL_tokenbuf, len); |
748a9306 LW |
4094 | |
4095 | /* Is this a word before a => operator? */ | |
1c3923b3 | 4096 | if (*d == '=' && d[1] == '>') { |
748a9306 | 4097 | CLINE; |
d0a148a6 NC |
4098 | yylval.opval |
4099 | = (OP*)newSVOP(OP_CONST, 0, | |
4100 | S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len)); | |
748a9306 LW |
4101 | yylval.opval->op_private = OPpCONST_BARE; |
4102 | TERM(WORD); | |
4103 | } | |
4104 | ||
a0d0e21e | 4105 | if (tmp < 0) { /* second-class keyword? */ |
56f7f34b CS |
4106 | GV *ogv = Nullgv; /* override (winner) */ |
4107 | GV *hgv = Nullgv; /* hidden (loser) */ | |
3280af22 | 4108 | if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) { |
56f7f34b | 4109 | CV *cv; |
3280af22 | 4110 | if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) && |
56f7f34b CS |
4111 | (cv = GvCVu(gv))) |
4112 | { | |
4113 | if (GvIMPORTED_CV(gv)) | |
4114 | ogv = gv; | |
4115 | else if (! CvMETHOD(cv)) | |
4116 | hgv = gv; | |
4117 | } | |
4118 | if (!ogv && | |
3280af22 NIS |
4119 | (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) && |
4120 | (gv = *gvp) != (GV*)&PL_sv_undef && | |
56f7f34b CS |
4121 | GvCVu(gv) && GvIMPORTED_CV(gv)) |
4122 | { | |
4123 | ogv = gv; | |
4124 | } | |
4125 | } | |
4126 | if (ogv) { | |
30fe34ed | 4127 | orig_keyword = tmp; |
56f7f34b | 4128 | tmp = 0; /* overridden by import or by GLOBAL */ |
6e7b2336 GS |
4129 | } |
4130 | else if (gv && !gvp | |
4131 | && -tmp==KEY_lock /* XXX generalizable kludge */ | |
d0456cad | 4132 | && GvCVu(gv) |
3280af22 | 4133 | && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE)) |
6e7b2336 GS |
4134 | { |
4135 | tmp = 0; /* any sub overrides "weak" keyword */ | |
a0d0e21e | 4136 | } |
7fc307b5 RGS |
4137 | else if (gv && !gvp |
4138 | && tmp == -KEY_err | |
4139 | && GvCVu(gv) | |
4140 | && PL_expect != XOPERATOR | |
4141 | && PL_expect != XTERMORDORDOR) | |
4142 | { | |
4143 | /* any sub overrides the "err" keyword, except when really an | |
4144 | * operator is expected */ | |
4145 | tmp = 0; | |
4146 | } | |
56f7f34b CS |
4147 | else { /* no override */ |
4148 | tmp = -tmp; | |
ac206dc8 | 4149 | if (tmp == KEY_dump && ckWARN(WARN_MISC)) { |
9014280d | 4150 | Perl_warner(aTHX_ packWARN(WARN_MISC), |
ac206dc8 RGS |
4151 | "dump() better written as CORE::dump()"); |
4152 | } | |
56f7f34b CS |
4153 | gv = Nullgv; |
4154 | gvp = 0; | |
041457d9 DM |
4155 | if (hgv && tmp != KEY_x && tmp != KEY_CORE |
4156 | && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */ | |
9014280d | 4157 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
599cee73 | 4158 | "Ambiguous call resolved as CORE::%s(), %s", |
2f3ca594 | 4159 | GvENAME(hgv), "qualify as such or use &"); |
49dc05e3 | 4160 | } |
a0d0e21e LW |
4161 | } |
4162 | ||
4163 | reserved_word: | |
4164 | switch (tmp) { | |
79072805 LW |
4165 | |
4166 | default: /* not a keyword */ | |
93a17b20 | 4167 | just_a_word: { |
96e4d5b1 | 4168 | SV *sv; |
ce29ac45 | 4169 | int pkgname = 0; |
f54cb97a | 4170 | const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]); |
8990e307 LW |
4171 | |
4172 | /* Get the rest if it looks like a package qualifier */ | |
4173 | ||
155aba94 | 4174 | if (*s == '\'' || (*s == ':' && s[1] == ':')) { |
c3e0f903 | 4175 | STRLEN morelen; |
3280af22 | 4176 | s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len, |
c3e0f903 GS |
4177 | TRUE, &morelen); |
4178 | if (!morelen) | |
cea2e8a9 | 4179 | Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf, |
ec2ab091 | 4180 | *s == '\'' ? "'" : "::"); |
c3e0f903 | 4181 | len += morelen; |
ce29ac45 | 4182 | pkgname = 1; |
a0d0e21e | 4183 | } |
8990e307 | 4184 | |
3280af22 NIS |
4185 | if (PL_expect == XOPERATOR) { |
4186 | if (PL_bufptr == PL_linestart) { | |
57843af0 | 4187 | CopLINE_dec(PL_curcop); |
9014280d | 4188 | Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi); |
57843af0 | 4189 | CopLINE_inc(PL_curcop); |
463ee0b2 LW |
4190 | } |
4191 | else | |
54310121 | 4192 | no_op("Bareword",s); |
463ee0b2 | 4193 | } |
8990e307 | 4194 | |
c3e0f903 GS |
4195 | /* Look for a subroutine with this name in current package, |
4196 | unless name is "Foo::", in which case Foo is a bearword | |
4197 | (and a package name). */ | |
4198 | ||
4199 | if (len > 2 && | |
3280af22 | 4200 | PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':') |
c3e0f903 | 4201 | { |
e476b1b5 | 4202 | if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV)) |
9014280d | 4203 | Perl_warner(aTHX_ packWARN(WARN_BAREWORD), |
599cee73 | 4204 | "Bareword \"%s\" refers to nonexistent package", |
3280af22 | 4205 | PL_tokenbuf); |
c3e0f903 | 4206 | len -= 2; |
3280af22 | 4207 | PL_tokenbuf[len] = '\0'; |
c3e0f903 GS |
4208 | gv = Nullgv; |
4209 | gvp = 0; | |
4210 | } | |
4211 | else { | |
4212 | len = 0; | |
4213 | if (!gv) | |
3280af22 | 4214 | gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV); |
c3e0f903 GS |
4215 | } |
4216 | ||
4217 | /* if we saw a global override before, get the right name */ | |
8990e307 | 4218 | |
49dc05e3 | 4219 | if (gvp) { |
79cb57f6 | 4220 | sv = newSVpvn("CORE::GLOBAL::",14); |
3280af22 | 4221 | sv_catpv(sv,PL_tokenbuf); |
49dc05e3 | 4222 | } |
8a7a129d NC |
4223 | else { |
4224 | /* If len is 0, newSVpv does strlen(), which is correct. | |
4225 | If len is non-zero, then it will be the true length, | |
4226 | and so the scalar will be created correctly. */ | |
4227 | sv = newSVpv(PL_tokenbuf,len); | |
4228 | } | |
8990e307 | 4229 | |
a0d0e21e LW |
4230 | /* Presume this is going to be a bareword of some sort. */ |
4231 | ||
4232 | CLINE; | |
49dc05e3 | 4233 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
a0d0e21e | 4234 | yylval.opval->op_private = OPpCONST_BARE; |
8f8cf39c JH |
4235 | /* UTF-8 package name? */ |
4236 | if (UTF && !IN_BYTES && | |
95a20fc0 | 4237 | is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv))) |
8f8cf39c | 4238 | SvUTF8_on(sv); |
a0d0e21e | 4239 | |
c3e0f903 GS |
4240 | /* And if "Foo::", then that's what it certainly is. */ |
4241 | ||
4242 | if (len) | |
4243 | goto safe_bareword; | |
4244 | ||
8990e307 LW |
4245 | /* See if it's the indirect object for a list operator. */ |
4246 | ||
3280af22 NIS |
4247 | if (PL_oldoldbufptr && |
4248 | PL_oldoldbufptr < PL_bufptr && | |
65cec589 GS |
4249 | (PL_oldoldbufptr == PL_last_lop |
4250 | || PL_oldoldbufptr == PL_last_uni) && | |
a0d0e21e | 4251 | /* NO SKIPSPACE BEFORE HERE! */ |
a9ef352a GS |
4252 | (PL_expect == XREF || |
4253 | ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF)) | |
a0d0e21e | 4254 | { |
748a9306 LW |
4255 | bool immediate_paren = *s == '('; |
4256 | ||
a0d0e21e LW |
4257 | /* (Now we can afford to cross potential line boundary.) */ |
4258 | s = skipspace(s); | |
4259 | ||
4260 | /* Two barewords in a row may indicate method call. */ | |
4261 | ||
7e2040f0 | 4262 | if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv))) |
bbf60fe6 | 4263 | return REPORT(tmp); |
a0d0e21e LW |
4264 | |
4265 | /* If not a declared subroutine, it's an indirect object. */ | |
4266 | /* (But it's an indir obj regardless for sort.) */ | |
7294df96 | 4267 | /* Also, if "_" follows a filetest operator, it's a bareword */ |
a0d0e21e | 4268 | |
7294df96 RGS |
4269 | if ( |
4270 | ( !immediate_paren && (PL_last_lop_op == OP_SORT || | |
f0670693 | 4271 | ((!gv || !GvCVu(gv)) && |
a9ef352a | 4272 | (PL_last_lop_op != OP_MAPSTART && |
f0670693 | 4273 | PL_last_lop_op != OP_GREPSTART)))) |
7294df96 RGS |
4274 | || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0' |
4275 | && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP)) | |
4276 | ) | |
a9ef352a | 4277 | { |
3280af22 | 4278 | PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR; |
748a9306 | 4279 | goto bareword; |
93a17b20 LW |
4280 | } |
4281 | } | |
8990e307 | 4282 | |
3280af22 | 4283 | PL_expect = XOPERATOR; |
8990e307 | 4284 | s = skipspace(s); |
1c3923b3 GS |
4285 | |
4286 | /* Is this a word before a => operator? */ | |
ce29ac45 | 4287 | if (*s == '=' && s[1] == '>' && !pkgname) { |
1c3923b3 GS |
4288 | CLINE; |
4289 | sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf); | |
0064a8a9 | 4290 | if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len)) |
7948272d | 4291 | SvUTF8_on(((SVOP*)yylval.opval)->op_sv); |
1c3923b3 GS |
4292 | TERM(WORD); |
4293 | } | |
4294 | ||
4295 | /* If followed by a paren, it's certainly a subroutine. */ | |
93a17b20 | 4296 | if (*s == '(') { |
79072805 | 4297 | CLINE; |
96e4d5b1 | 4298 | if (gv && GvCVu(gv)) { |
bf4acbe4 | 4299 | for (d = s + 1; SPACE_OR_TAB(*d); d++) ; |
7a52d87a | 4300 | if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) { |
96e4d5b1 | 4301 | s = d + 1; |
4302 | goto its_constant; | |
4303 | } | |
4304 | } | |
3280af22 NIS |
4305 | PL_nextval[PL_nexttoke].opval = yylval.opval; |
4306 | PL_expect = XOPERATOR; | |
93a17b20 | 4307 | force_next(WORD); |
c07a80fd | 4308 | yylval.ival = 0; |
463ee0b2 | 4309 | TOKEN('&'); |
79072805 | 4310 | } |
93a17b20 | 4311 | |
a0d0e21e | 4312 | /* If followed by var or block, call it a method (unless sub) */ |
8990e307 | 4313 | |
8ebc5c01 | 4314 | if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) { |
3280af22 NIS |
4315 | PL_last_lop = PL_oldbufptr; |
4316 | PL_last_lop_op = OP_METHOD; | |
93a17b20 | 4317 | PREBLOCK(METHOD); |
463ee0b2 LW |
4318 | } |
4319 | ||
8990e307 LW |
4320 | /* If followed by a bareword, see if it looks like indir obj. */ |
4321 | ||
30fe34ed RGS |
4322 | if (!orig_keyword |
4323 | && (isIDFIRST_lazy_if(s,UTF) || *s == '$') | |
4324 | && (tmp = intuit_method(s,gv))) | |
bbf60fe6 | 4325 | return REPORT(tmp); |
93a17b20 | 4326 | |
8990e307 LW |
4327 | /* Not a method, so call it a subroutine (if defined) */ |
4328 | ||
8ebc5c01 | 4329 | if (gv && GvCVu(gv)) { |
46fc3d4c | 4330 | CV* cv; |
0453d815 | 4331 | if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS)) |
9014280d | 4332 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
0453d815 | 4333 | "Ambiguous use of -%s resolved as -&%s()", |
3280af22 | 4334 | PL_tokenbuf, PL_tokenbuf); |
89bfa8cd | 4335 | /* Check for a constant sub */ |
46fc3d4c | 4336 | cv = GvCV(gv); |
96e4d5b1 | 4337 | if ((sv = cv_const_sv(cv))) { |
4338 | its_constant: | |
4339 | SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv); | |
4340 | ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv); | |
4341 | yylval.opval->op_private = 0; | |
4342 | TOKEN(WORD); | |
89bfa8cd | 4343 | } |
4344 | ||
a5f75d66 AD |
4345 | /* Resolve to GV now. */ |
4346 | op_free(yylval.opval); | |
4347 | yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv)); | |
9675f7ac | 4348 | yylval.opval->op_private |= OPpENTERSUB_NOPAREN; |
7a52d87a | 4349 | PL_last_lop = PL_oldbufptr; |
bf848113 | 4350 | PL_last_lop_op = OP_ENTERSUB; |
4633a7c4 LW |
4351 | /* Is there a prototype? */ |
4352 | if (SvPOK(cv)) { | |
4353 | STRLEN len; | |
cfd0369c | 4354 | const char *proto = SvPV_const((SV*)cv, len); |
4633a7c4 LW |
4355 | if (!len) |
4356 | TERM(FUNC0SUB); | |
770526c1 | 4357 | if (*proto == '$' && proto[1] == '\0') |
4633a7c4 | 4358 | OPERATOR(UNIOPSUB); |
0f5d0394 AE |
4359 | while (*proto == ';') |
4360 | proto++; | |
7a52d87a | 4361 | if (*proto == '&' && *s == '{') { |
bfed75c6 | 4362 | sv_setpv(PL_subname, PL_curstash ? |
c99da370 | 4363 | "__ANON__" : "__ANON__::__ANON__"); |
4633a7c4 LW |
4364 | PREBLOCK(LSTOPSUB); |
4365 | } | |
a9ef352a | 4366 | } |
3280af22 NIS |
4367 | PL_nextval[PL_nexttoke].opval = yylval.opval; |
4368 | PL_expect = XTERM; | |
8990e307 LW |
4369 | force_next(WORD); |
4370 | TOKEN(NOAMP); | |
4371 | } | |
748a9306 | 4372 | |
8990e307 LW |
4373 | /* Call it a bare word */ |
4374 | ||
5603f27d GS |
4375 | if (PL_hints & HINT_STRICT_SUBS) |
4376 | yylval.opval->op_private |= OPpCONST_STRICT; | |
4377 | else { | |
4378 | bareword: | |
041457d9 DM |
4379 | if (lastchar != '-') { |
4380 | if (ckWARN(WARN_RESERVED)) { | |
5603f27d | 4381 | for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ; |
238ae712 | 4382 | if (!*d && !gv_stashpv(PL_tokenbuf,FALSE)) |
9014280d | 4383 | Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved, |
5603f27d GS |
4384 | PL_tokenbuf); |
4385 | } | |
748a9306 LW |
4386 | } |
4387 | } | |
c3e0f903 GS |
4388 | |
4389 | safe_bareword: | |
3792a11b NC |
4390 | if ((lastchar == '*' || lastchar == '%' || lastchar == '&') |
4391 | && ckWARN_d(WARN_AMBIGUOUS)) { | |
9014280d | 4392 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
0453d815 | 4393 | "Operator or semicolon missing before %c%s", |
3280af22 | 4394 | lastchar, PL_tokenbuf); |
9014280d | 4395 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
0453d815 | 4396 | "Ambiguous use of %c resolved as operator %c", |
748a9306 LW |
4397 | lastchar, lastchar); |
4398 | } | |
93a17b20 | 4399 | TOKEN(WORD); |
79072805 | 4400 | } |
79072805 | 4401 | |
68dc0745 | 4402 | case KEY___FILE__: |
46fc3d4c | 4403 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
ed094faf | 4404 | newSVpv(CopFILE(PL_curcop),0)); |
46fc3d4c | 4405 | TERM(THING); |
4406 | ||
79072805 | 4407 | case KEY___LINE__: |
cf2093f6 | 4408 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
57843af0 | 4409 | Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop))); |
79072805 | 4410 | TERM(THING); |
68dc0745 | 4411 | |
4412 | case KEY___PACKAGE__: | |
4413 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, | |
3280af22 | 4414 | (PL_curstash |
5aaec2b4 | 4415 | ? newSVhek(HvNAME_HEK(PL_curstash)) |
3280af22 | 4416 | : &PL_sv_undef)); |
79072805 | 4417 | TERM(THING); |
79072805 | 4418 | |
e50aee73 | 4419 | case KEY___DATA__: |
79072805 LW |
4420 | case KEY___END__: { |
4421 | GV *gv; | |
3280af22 | 4422 | if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) { |
bfed75c6 | 4423 | const char *pname = "main"; |
3280af22 | 4424 | if (PL_tokenbuf[2] == 'D') |
bfcb3514 | 4425 | pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash); |
cea2e8a9 | 4426 | gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO); |
a5f75d66 | 4427 | GvMULTI_on(gv); |
79072805 | 4428 | if (!GvIO(gv)) |
a0d0e21e | 4429 | GvIOp(gv) = newIO(); |
3280af22 | 4430 | IoIFP(GvIOp(gv)) = PL_rsfp; |
a0d0e21e LW |
4431 | #if defined(HAS_FCNTL) && defined(F_SETFD) |
4432 | { | |
f54cb97a | 4433 | const int fd = PerlIO_fileno(PL_rsfp); |
a0d0e21e LW |
4434 | fcntl(fd,F_SETFD,fd >= 3); |
4435 | } | |
79072805 | 4436 | #endif |
fd049845 | 4437 | /* Mark this internal pseudo-handle as clean */ |
4438 | IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT; | |
3280af22 | 4439 | if (PL_preprocess) |
50952442 | 4440 | IoTYPE(GvIOp(gv)) = IoTYPE_PIPE; |
3280af22 | 4441 | else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) |
50952442 | 4442 | IoTYPE(GvIOp(gv)) = IoTYPE_STD; |
79072805 | 4443 | else |
50952442 | 4444 | IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY; |
c39cd008 GS |
4445 | #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS) |
4446 | /* if the script was opened in binmode, we need to revert | |
53129d29 | 4447 | * it to text mode for compatibility; but only iff it has CRs |
c39cd008 | 4448 | * XXX this is a questionable hack at best. */ |
53129d29 GS |
4449 | if (PL_bufend-PL_bufptr > 2 |
4450 | && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r') | |
c39cd008 GS |
4451 | { |
4452 | Off_t loc = 0; | |
50952442 | 4453 | if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) { |
c39cd008 GS |
4454 | loc = PerlIO_tell(PL_rsfp); |
4455 | (void)PerlIO_seek(PL_rsfp, 0L, 0); | |
4456 | } | |
2986a63f JH |
4457 | #ifdef NETWARE |
4458 | if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) { | |
4459 | #else | |
c39cd008 | 4460 | if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) { |
2986a63f | 4461 | #endif /* NETWARE */ |
1143fce0 JH |
4462 | #ifdef PERLIO_IS_STDIO /* really? */ |
4463 | # if defined(__BORLANDC__) | |
cb359b41 JH |
4464 | /* XXX see note in do_binmode() */ |
4465 | ((FILE*)PL_rsfp)->flags &= ~_F_BIN; | |
1143fce0 JH |
4466 | # endif |
4467 | #endif | |
c39cd008 GS |
4468 | if (loc > 0) |
4469 | PerlIO_seek(PL_rsfp, loc, 0); | |
4470 | } | |
4471 | } | |
4472 | #endif | |
7948272d | 4473 | #ifdef PERLIO_LAYERS |
52d2e0f4 JH |
4474 | if (!IN_BYTES) { |
4475 | if (UTF) | |
4476 | PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8"); | |
4477 | else if (PL_encoding) { | |
4478 | SV *name; | |
4479 | dSP; | |
4480 | ENTER; | |
4481 | SAVETMPS; | |
4482 | PUSHMARK(sp); | |
4483 | EXTEND(SP, 1); | |
4484 | XPUSHs(PL_encoding); | |
4485 | PUTBACK; | |
4486 | call_method("name", G_SCALAR); | |
4487 | SPAGAIN; | |
4488 | name = POPs; | |
4489 | PUTBACK; | |
bfed75c6 | 4490 | PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, |
52d2e0f4 JH |
4491 | Perl_form(aTHX_ ":encoding(%"SVf")", |
4492 | name)); | |
4493 | FREETMPS; | |
4494 | LEAVE; | |
4495 | } | |
4496 | } | |
7948272d | 4497 | #endif |
3280af22 | 4498 | PL_rsfp = Nullfp; |
79072805 LW |
4499 | } |
4500 | goto fake_eof; | |
e929a76b | 4501 | } |
de3bb511 | 4502 | |
8990e307 | 4503 | case KEY_AUTOLOAD: |
ed6116ce | 4504 | case KEY_DESTROY: |
79072805 | 4505 | case KEY_BEGIN: |
7d30b5c4 | 4506 | case KEY_CHECK: |
7d07dbc2 | 4507 | case KEY_INIT: |
7d30b5c4 | 4508 | case KEY_END: |
3280af22 NIS |
4509 | if (PL_expect == XSTATE) { |
4510 | s = PL_bufptr; | |
93a17b20 | 4511 | goto really_sub; |
79072805 LW |
4512 | } |
4513 | goto just_a_word; | |
4514 | ||
a0d0e21e LW |
4515 | case KEY_CORE: |
4516 | if (*s == ':' && s[1] == ':') { | |
4517 | s += 2; | |
748a9306 | 4518 | d = s; |
3280af22 | 4519 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
6798c92b GS |
4520 | if (!(tmp = keyword(PL_tokenbuf, len))) |
4521 | Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf); | |
a0d0e21e LW |
4522 | if (tmp < 0) |
4523 | tmp = -tmp; | |
850e8516 | 4524 | else if (tmp == KEY_require || tmp == KEY_do) |
a72a1c8b | 4525 | /* that's a way to remember we saw "CORE::" */ |
850e8516 | 4526 | orig_keyword = tmp; |
a0d0e21e LW |
4527 | goto reserved_word; |
4528 | } | |
4529 | goto just_a_word; | |
4530 | ||
463ee0b2 LW |
4531 | case KEY_abs: |
4532 | UNI(OP_ABS); | |
4533 | ||
79072805 LW |
4534 | case KEY_alarm: |
4535 | UNI(OP_ALARM); | |
4536 | ||
4537 | case KEY_accept: | |
a0d0e21e | 4538 | LOP(OP_ACCEPT,XTERM); |
79072805 | 4539 | |
463ee0b2 LW |
4540 | case KEY_and: |
4541 | OPERATOR(ANDOP); | |
4542 | ||
79072805 | 4543 | case KEY_atan2: |
a0d0e21e | 4544 | LOP(OP_ATAN2,XTERM); |
85e6fe83 | 4545 | |
79072805 | 4546 | case KEY_bind: |
a0d0e21e | 4547 | LOP(OP_BIND,XTERM); |
79072805 LW |
4548 | |
4549 | case KEY_binmode: | |
1c1fc3ea | 4550 | LOP(OP_BINMODE,XTERM); |
79072805 LW |
4551 | |
4552 | case KEY_bless: | |
a0d0e21e | 4553 | LOP(OP_BLESS,XTERM); |
79072805 LW |
4554 | |
4555 | case KEY_chop: | |
4556 | UNI(OP_CHOP); | |
4557 | ||
4558 | case KEY_continue: | |
4559 | PREBLOCK(CONTINUE); | |
4560 | ||
4561 | case KEY_chdir: | |
85e6fe83 | 4562 | (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */ |
79072805 LW |
4563 | UNI(OP_CHDIR); |
4564 | ||
4565 | case KEY_close: | |
4566 | UNI(OP_CLOSE); | |
4567 | ||
4568 | case KEY_closedir: | |
4569 | UNI(OP_CLOSEDIR); | |
4570 | ||
4571 | case KEY_cmp: | |
4572 | Eop(OP_SCMP); | |
4573 | ||
4574 | case KEY_caller: | |
4575 | UNI(OP_CALLER); | |
4576 | ||
4577 | case KEY_crypt: | |
4578 | #ifdef FCRYPT | |
f4c556ac GS |
4579 | if (!PL_cryptseen) { |
4580 | PL_cryptseen = TRUE; | |
de3bb511 | 4581 | init_des(); |
f4c556ac | 4582 | } |
a687059c | 4583 | #endif |
a0d0e21e | 4584 | LOP(OP_CRYPT,XTERM); |
79072805 LW |
4585 | |
4586 | case KEY_chmod: | |
a0d0e21e | 4587 | LOP(OP_CHMOD,XTERM); |
79072805 LW |
4588 | |
4589 | case KEY_chown: | |
a0d0e21e | 4590 | LOP(OP_CHOWN,XTERM); |
79072805 LW |
4591 | |
4592 | case KEY_connect: | |
a0d0e21e | 4593 | LOP(OP_CONNECT,XTERM); |
79072805 | 4594 | |
463ee0b2 LW |
4595 | case KEY_chr: |
4596 | UNI(OP_CHR); | |
4597 | ||
79072805 LW |
4598 | case KEY_cos: |
4599 | UNI(OP_COS); | |
4600 | ||
4601 | case KEY_chroot: | |
4602 | UNI(OP_CHROOT); | |
4603 | ||
4604 | case KEY_do: | |
4605 | s = skipspace(s); | |
4606 | if (*s == '{') | |
a0d0e21e | 4607 | PRETERMBLOCK(DO); |
79072805 | 4608 | if (*s != '\'') |
89c5585f | 4609 | s = force_word(s,WORD,TRUE,TRUE,FALSE); |
850e8516 RGS |
4610 | if (orig_keyword == KEY_do) { |
4611 | orig_keyword = 0; | |
4612 | yylval.ival = 1; | |
4613 | } | |
4614 | else | |
4615 | yylval.ival = 0; | |
378cc40b | 4616 | OPERATOR(DO); |
79072805 LW |
4617 | |
4618 | case KEY_die: | |
3280af22 | 4619 | PL_hints |= HINT_BLOCK_SCOPE; |
a0d0e21e | 4620 | LOP(OP_DIE,XTERM); |
79072805 LW |
4621 | |
4622 | case KEY_defined: | |
4623 | UNI(OP_DEFINED); | |
4624 | ||
4625 | case KEY_delete: | |
a0d0e21e | 4626 | UNI(OP_DELETE); |
79072805 LW |
4627 | |
4628 | case KEY_dbmopen: | |
a0d0e21e LW |
4629 | gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV); |
4630 | LOP(OP_DBMOPEN,XTERM); | |
79072805 LW |
4631 | |
4632 | case KEY_dbmclose: | |
4633 | UNI(OP_DBMCLOSE); | |
4634 | ||
4635 | case KEY_dump: | |
a0d0e21e | 4636 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4637 | LOOPX(OP_DUMP); |
4638 | ||
4639 | case KEY_else: | |
4640 | PREBLOCK(ELSE); | |
4641 | ||
4642 | case KEY_elsif: | |
57843af0 | 4643 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
4644 | OPERATOR(ELSIF); |
4645 | ||
4646 | case KEY_eq: | |
4647 | Eop(OP_SEQ); | |
4648 | ||
a0d0e21e LW |
4649 | case KEY_exists: |
4650 | UNI(OP_EXISTS); | |
4e553d73 | 4651 | |
79072805 LW |
4652 | case KEY_exit: |
4653 | UNI(OP_EXIT); | |
4654 | ||
4655 | case KEY_eval: | |
79072805 | 4656 | s = skipspace(s); |
3280af22 | 4657 | PL_expect = (*s == '{') ? XTERMBLOCK : XTERM; |
463ee0b2 | 4658 | UNIBRACK(OP_ENTEREVAL); |
79072805 LW |
4659 | |
4660 | case KEY_eof: | |
4661 | UNI(OP_EOF); | |
4662 | ||
c963b151 BD |
4663 | case KEY_err: |
4664 | OPERATOR(DOROP); | |
4665 | ||
79072805 LW |
4666 | case KEY_exp: |
4667 | UNI(OP_EXP); | |
4668 | ||
4669 | case KEY_each: | |
4670 | UNI(OP_EACH); | |
4671 | ||
4672 | case KEY_exec: | |
4673 | set_csh(); | |
a0d0e21e | 4674 | LOP(OP_EXEC,XREF); |
79072805 LW |
4675 | |
4676 | case KEY_endhostent: | |
4677 | FUN0(OP_EHOSTENT); | |
4678 | ||
4679 | case KEY_endnetent: | |
4680 | FUN0(OP_ENETENT); | |
4681 | ||
4682 | case KEY_endservent: | |
4683 | FUN0(OP_ESERVENT); | |
4684 | ||
4685 | case KEY_endprotoent: | |
4686 | FUN0(OP_EPROTOENT); | |
4687 | ||
4688 | case KEY_endpwent: | |
4689 | FUN0(OP_EPWENT); | |
4690 | ||
4691 | case KEY_endgrent: | |
4692 | FUN0(OP_EGRENT); | |
4693 | ||
4694 | case KEY_for: | |
4695 | case KEY_foreach: | |
57843af0 | 4696 | yylval.ival = CopLINE(PL_curcop); |
55497cff | 4697 | s = skipspace(s); |
7e2040f0 | 4698 | if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) { |
55497cff | 4699 | char *p = s; |
3280af22 | 4700 | if ((PL_bufend - p) >= 3 && |
55497cff | 4701 | strnEQ(p, "my", 2) && isSPACE(*(p + 2))) |
4702 | p += 2; | |
77ca0c92 LW |
4703 | else if ((PL_bufend - p) >= 4 && |
4704 | strnEQ(p, "our", 3) && isSPACE(*(p + 3))) | |
4705 | p += 3; | |
55497cff | 4706 | p = skipspace(p); |
7e2040f0 | 4707 | if (isIDFIRST_lazy_if(p,UTF)) { |
77ca0c92 LW |
4708 | p = scan_ident(p, PL_bufend, |
4709 | PL_tokenbuf, sizeof PL_tokenbuf, TRUE); | |
4710 | p = skipspace(p); | |
4711 | } | |
4712 | if (*p != '$') | |
cea2e8a9 | 4713 | Perl_croak(aTHX_ "Missing $ on loop variable"); |
55497cff | 4714 | } |
79072805 LW |
4715 | OPERATOR(FOR); |
4716 | ||
4717 | case KEY_formline: | |
a0d0e21e | 4718 | LOP(OP_FORMLINE,XTERM); |
79072805 LW |
4719 | |
4720 | case KEY_fork: | |
4721 | FUN0(OP_FORK); | |
4722 | ||
4723 | case KEY_fcntl: | |
a0d0e21e | 4724 | LOP(OP_FCNTL,XTERM); |
79072805 LW |
4725 | |
4726 | case KEY_fileno: | |
4727 | UNI(OP_FILENO); | |
4728 | ||
4729 | case KEY_flock: | |
a0d0e21e | 4730 | LOP(OP_FLOCK,XTERM); |
79072805 LW |
4731 | |
4732 | case KEY_gt: | |
4733 | Rop(OP_SGT); | |
4734 | ||
4735 | case KEY_ge: | |
4736 | Rop(OP_SGE); | |
4737 | ||
4738 | case KEY_grep: | |
2c38e13d | 4739 | LOP(OP_GREPSTART, XREF); |
79072805 LW |
4740 | |
4741 | case KEY_goto: | |
a0d0e21e | 4742 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4743 | LOOPX(OP_GOTO); |
4744 | ||
4745 | case KEY_gmtime: | |
4746 | UNI(OP_GMTIME); | |
4747 | ||
4748 | case KEY_getc: | |
6f33ba73 | 4749 | UNIDOR(OP_GETC); |
79072805 LW |
4750 | |
4751 | case KEY_getppid: | |
4752 | FUN0(OP_GETPPID); | |
4753 | ||
4754 | case KEY_getpgrp: | |
4755 | UNI(OP_GETPGRP); | |
4756 | ||
4757 | case KEY_getpriority: | |
a0d0e21e | 4758 | LOP(OP_GETPRIORITY,XTERM); |
79072805 LW |
4759 | |
4760 | case KEY_getprotobyname: | |
4761 | UNI(OP_GPBYNAME); | |
4762 | ||
4763 | case KEY_getprotobynumber: | |
a0d0e21e | 4764 | LOP(OP_GPBYNUMBER,XTERM); |
79072805 LW |
4765 | |
4766 | case KEY_getprotoent: | |
4767 | FUN0(OP_GPROTOENT); | |
4768 | ||
4769 | case KEY_getpwent: | |
4770 | FUN0(OP_GPWENT); | |
4771 | ||
4772 | case KEY_getpwnam: | |
ff68c719 | 4773 | UNI(OP_GPWNAM); |
79072805 LW |
4774 | |
4775 | case KEY_getpwuid: | |
ff68c719 | 4776 | UNI(OP_GPWUID); |
79072805 LW |
4777 | |
4778 | case KEY_getpeername: | |
4779 | UNI(OP_GETPEERNAME); | |
4780 | ||
4781 | case KEY_gethostbyname: | |
4782 | UNI(OP_GHBYNAME); | |
4783 | ||
4784 | case KEY_gethostbyaddr: | |
a0d0e21e | 4785 | LOP(OP_GHBYADDR,XTERM); |
79072805 LW |
4786 | |
4787 | case KEY_gethostent: | |
4788 | FUN0(OP_GHOSTENT); | |
4789 | ||
4790 | case KEY_getnetbyname: | |
4791 | UNI(OP_GNBYNAME); | |
4792 | ||
4793 | case KEY_getnetbyaddr: | |
a0d0e21e | 4794 | LOP(OP_GNBYADDR,XTERM); |
79072805 LW |
4795 | |
4796 | case KEY_getnetent: | |
4797 | FUN0(OP_GNETENT); | |
4798 | ||
4799 | case KEY_getservbyname: | |
a0d0e21e | 4800 | LOP(OP_GSBYNAME,XTERM); |
79072805 LW |
4801 | |
4802 | case KEY_getservbyport: | |
a0d0e21e | 4803 | LOP(OP_GSBYPORT,XTERM); |
79072805 LW |
4804 | |
4805 | case KEY_getservent: | |
4806 | FUN0(OP_GSERVENT); | |
4807 | ||
4808 | case KEY_getsockname: | |
4809 | UNI(OP_GETSOCKNAME); | |
4810 | ||
4811 | case KEY_getsockopt: | |
a0d0e21e | 4812 | LOP(OP_GSOCKOPT,XTERM); |
79072805 LW |
4813 | |
4814 | case KEY_getgrent: | |
4815 | FUN0(OP_GGRENT); | |
4816 | ||
4817 | case KEY_getgrnam: | |
ff68c719 | 4818 | UNI(OP_GGRNAM); |
79072805 LW |
4819 | |
4820 | case KEY_getgrgid: | |
ff68c719 | 4821 | UNI(OP_GGRGID); |
79072805 LW |
4822 | |
4823 | case KEY_getlogin: | |
4824 | FUN0(OP_GETLOGIN); | |
4825 | ||
93a17b20 | 4826 | case KEY_glob: |
a0d0e21e LW |
4827 | set_csh(); |
4828 | LOP(OP_GLOB,XTERM); | |
93a17b20 | 4829 | |
79072805 LW |
4830 | case KEY_hex: |
4831 | UNI(OP_HEX); | |
4832 | ||
4833 | case KEY_if: | |
57843af0 | 4834 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
4835 | OPERATOR(IF); |
4836 | ||
4837 | case KEY_index: | |
a0d0e21e | 4838 | LOP(OP_INDEX,XTERM); |
79072805 LW |
4839 | |
4840 | case KEY_int: | |
4841 | UNI(OP_INT); | |
4842 | ||
4843 | case KEY_ioctl: | |
a0d0e21e | 4844 | LOP(OP_IOCTL,XTERM); |
79072805 LW |
4845 | |
4846 | case KEY_join: | |
a0d0e21e | 4847 | LOP(OP_JOIN,XTERM); |
79072805 LW |
4848 | |
4849 | case KEY_keys: | |
4850 | UNI(OP_KEYS); | |
4851 | ||
4852 | case KEY_kill: | |
a0d0e21e | 4853 | LOP(OP_KILL,XTERM); |
79072805 LW |
4854 | |
4855 | case KEY_last: | |
a0d0e21e | 4856 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 | 4857 | LOOPX(OP_LAST); |
4e553d73 | 4858 | |
79072805 LW |
4859 | case KEY_lc: |
4860 | UNI(OP_LC); | |
4861 | ||
4862 | case KEY_lcfirst: | |
4863 | UNI(OP_LCFIRST); | |
4864 | ||
4865 | case KEY_local: | |
09bef843 | 4866 | yylval.ival = 0; |
79072805 LW |
4867 | OPERATOR(LOCAL); |
4868 | ||
4869 | case KEY_length: | |
4870 | UNI(OP_LENGTH); | |
4871 | ||
4872 | case KEY_lt: | |
4873 | Rop(OP_SLT); | |
4874 | ||
4875 | case KEY_le: | |
4876 | Rop(OP_SLE); | |
4877 | ||
4878 | case KEY_localtime: | |
4879 | UNI(OP_LOCALTIME); | |
4880 | ||
4881 | case KEY_log: | |
4882 | UNI(OP_LOG); | |
4883 | ||
4884 | case KEY_link: | |
a0d0e21e | 4885 | LOP(OP_LINK,XTERM); |
79072805 LW |
4886 | |
4887 | case KEY_listen: | |
a0d0e21e | 4888 | LOP(OP_LISTEN,XTERM); |
79072805 | 4889 | |
c0329465 MB |
4890 | case KEY_lock: |
4891 | UNI(OP_LOCK); | |
4892 | ||
79072805 LW |
4893 | case KEY_lstat: |
4894 | UNI(OP_LSTAT); | |
4895 | ||
4896 | case KEY_m: | |
8782bef2 | 4897 | s = scan_pat(s,OP_MATCH); |
79072805 LW |
4898 | TERM(sublex_start()); |
4899 | ||
a0d0e21e | 4900 | case KEY_map: |
2c38e13d | 4901 | LOP(OP_MAPSTART, XREF); |
4e4e412b | 4902 | |
79072805 | 4903 | case KEY_mkdir: |
a0d0e21e | 4904 | LOP(OP_MKDIR,XTERM); |
79072805 LW |
4905 | |
4906 | case KEY_msgctl: | |
a0d0e21e | 4907 | LOP(OP_MSGCTL,XTERM); |
79072805 LW |
4908 | |
4909 | case KEY_msgget: | |
a0d0e21e | 4910 | LOP(OP_MSGGET,XTERM); |
79072805 LW |
4911 | |
4912 | case KEY_msgrcv: | |
a0d0e21e | 4913 | LOP(OP_MSGRCV,XTERM); |
79072805 LW |
4914 | |
4915 | case KEY_msgsnd: | |
a0d0e21e | 4916 | LOP(OP_MSGSND,XTERM); |
79072805 | 4917 | |
77ca0c92 | 4918 | case KEY_our: |
93a17b20 | 4919 | case KEY_my: |
77ca0c92 | 4920 | PL_in_my = tmp; |
c750a3ec | 4921 | s = skipspace(s); |
7e2040f0 | 4922 | if (isIDFIRST_lazy_if(s,UTF)) { |
3280af22 | 4923 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len); |
09bef843 SB |
4924 | if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3)) |
4925 | goto really_sub; | |
def3634b | 4926 | PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len); |
3280af22 | 4927 | if (!PL_in_my_stash) { |
c750a3ec | 4928 | char tmpbuf[1024]; |
3280af22 NIS |
4929 | PL_bufptr = s; |
4930 | sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf); | |
c750a3ec MB |
4931 | yyerror(tmpbuf); |
4932 | } | |
4933 | } | |
09bef843 | 4934 | yylval.ival = 1; |
55497cff | 4935 | OPERATOR(MY); |
93a17b20 | 4936 | |
79072805 | 4937 | case KEY_next: |
a0d0e21e | 4938 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4939 | LOOPX(OP_NEXT); |
4940 | ||
4941 | case KEY_ne: | |
4942 | Eop(OP_SNE); | |
4943 | ||
a0d0e21e | 4944 | case KEY_no: |
468aa647 | 4945 | s = tokenize_use(0, s); |
a0d0e21e LW |
4946 | OPERATOR(USE); |
4947 | ||
4948 | case KEY_not: | |
2d2e263d LW |
4949 | if (*s == '(' || (s = skipspace(s), *s == '(')) |
4950 | FUN1(OP_NOT); | |
4951 | else | |
4952 | OPERATOR(NOTOP); | |
a0d0e21e | 4953 | |
79072805 | 4954 | case KEY_open: |
93a17b20 | 4955 | s = skipspace(s); |
7e2040f0 | 4956 | if (isIDFIRST_lazy_if(s,UTF)) { |
f54cb97a | 4957 | const char *t; |
7e2040f0 | 4958 | for (d = s; isALNUM_lazy_if(d,UTF); d++) ; |
e2ab214b DM |
4959 | for (t=d; *t && isSPACE(*t); t++) ; |
4960 | if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE) | |
66fbe8fb HS |
4961 | /* [perl #16184] */ |
4962 | && !(t[0] == '=' && t[1] == '>') | |
4963 | ) { | |
551405c4 | 4964 | int len = (int)(d-s); |
9014280d | 4965 | Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE), |
0453d815 | 4966 | "Precedence problem: open %.*s should be open(%.*s)", |
551405c4 | 4967 | len, s, len, s); |
66fbe8fb | 4968 | } |
93a17b20 | 4969 | } |
a0d0e21e | 4970 | LOP(OP_OPEN,XTERM); |
79072805 | 4971 | |
463ee0b2 | 4972 | case KEY_or: |
a0d0e21e | 4973 | yylval.ival = OP_OR; |
463ee0b2 LW |
4974 | OPERATOR(OROP); |
4975 | ||
79072805 LW |
4976 | case KEY_ord: |
4977 | UNI(OP_ORD); | |
4978 | ||
4979 | case KEY_oct: | |
4980 | UNI(OP_OCT); | |
4981 | ||
4982 | case KEY_opendir: | |
a0d0e21e | 4983 | LOP(OP_OPEN_DIR,XTERM); |
79072805 LW |
4984 | |
4985 | case KEY_print: | |
3280af22 | 4986 | checkcomma(s,PL_tokenbuf,"filehandle"); |
a0d0e21e | 4987 | LOP(OP_PRINT,XREF); |
79072805 LW |
4988 | |
4989 | case KEY_printf: | |
3280af22 | 4990 | checkcomma(s,PL_tokenbuf,"filehandle"); |
a0d0e21e | 4991 | LOP(OP_PRTF,XREF); |
79072805 | 4992 | |
c07a80fd | 4993 | case KEY_prototype: |
4994 | UNI(OP_PROTOTYPE); | |
4995 | ||
79072805 | 4996 | case KEY_push: |
a0d0e21e | 4997 | LOP(OP_PUSH,XTERM); |
79072805 LW |
4998 | |
4999 | case KEY_pop: | |
6f33ba73 | 5000 | UNIDOR(OP_POP); |
79072805 | 5001 | |
a0d0e21e | 5002 | case KEY_pos: |
6f33ba73 | 5003 | UNIDOR(OP_POS); |
4e553d73 | 5004 | |
79072805 | 5005 | case KEY_pack: |
a0d0e21e | 5006 | LOP(OP_PACK,XTERM); |
79072805 LW |
5007 | |
5008 | case KEY_package: | |
a0d0e21e | 5009 | s = force_word(s,WORD,FALSE,TRUE,FALSE); |
79072805 LW |
5010 | OPERATOR(PACKAGE); |
5011 | ||
5012 | case KEY_pipe: | |
a0d0e21e | 5013 | LOP(OP_PIPE_OP,XTERM); |
79072805 LW |
5014 | |
5015 | case KEY_q: | |
09bef843 | 5016 | s = scan_str(s,FALSE,FALSE); |
79072805 | 5017 | if (!s) |
85e6fe83 | 5018 | missingterm((char*)0); |
79072805 LW |
5019 | yylval.ival = OP_CONST; |
5020 | TERM(sublex_start()); | |
5021 | ||
a0d0e21e LW |
5022 | case KEY_quotemeta: |
5023 | UNI(OP_QUOTEMETA); | |
5024 | ||
8990e307 | 5025 | case KEY_qw: |
09bef843 | 5026 | s = scan_str(s,FALSE,FALSE); |
8990e307 | 5027 | if (!s) |
85e6fe83 | 5028 | missingterm((char*)0); |
3480a8d2 | 5029 | PL_expect = XOPERATOR; |
8127e0e3 GS |
5030 | force_next(')'); |
5031 | if (SvCUR(PL_lex_stuff)) { | |
5032 | OP *words = Nullop; | |
5033 | int warned = 0; | |
3280af22 | 5034 | d = SvPV_force(PL_lex_stuff, len); |
8127e0e3 | 5035 | while (len) { |
7948272d | 5036 | SV *sv; |
8127e0e3 GS |
5037 | for (; isSPACE(*d) && len; --len, ++d) ; |
5038 | if (len) { | |
f54cb97a | 5039 | const char *b = d; |
e476b1b5 | 5040 | if (!warned && ckWARN(WARN_QW)) { |
8127e0e3 GS |
5041 | for (; !isSPACE(*d) && len; --len, ++d) { |
5042 | if (*d == ',') { | |
9014280d | 5043 | Perl_warner(aTHX_ packWARN(WARN_QW), |
8127e0e3 GS |
5044 | "Possible attempt to separate words with commas"); |
5045 | ++warned; | |
5046 | } | |
5047 | else if (*d == '#') { | |
9014280d | 5048 | Perl_warner(aTHX_ packWARN(WARN_QW), |
8127e0e3 GS |
5049 | "Possible attempt to put comments in qw() list"); |
5050 | ++warned; | |
5051 | } | |
5052 | } | |
5053 | } | |
5054 | else { | |
5055 | for (; !isSPACE(*d) && len; --len, ++d) ; | |
5056 | } | |
7948272d NIS |
5057 | sv = newSVpvn(b, d-b); |
5058 | if (DO_UTF8(PL_lex_stuff)) | |
5059 | SvUTF8_on(sv); | |
8127e0e3 | 5060 | words = append_elem(OP_LIST, words, |
7948272d | 5061 | newSVOP(OP_CONST, 0, tokeq(sv))); |
55497cff | 5062 | } |
5063 | } | |
8127e0e3 GS |
5064 | if (words) { |
5065 | PL_nextval[PL_nexttoke].opval = words; | |
5066 | force_next(THING); | |
5067 | } | |
55497cff | 5068 | } |
37fd879b | 5069 | if (PL_lex_stuff) { |
8127e0e3 | 5070 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
5071 | PL_lex_stuff = Nullsv; |
5072 | } | |
3280af22 | 5073 | PL_expect = XTERM; |
8127e0e3 | 5074 | TOKEN('('); |
8990e307 | 5075 | |
79072805 | 5076 | case KEY_qq: |
09bef843 | 5077 | s = scan_str(s,FALSE,FALSE); |
79072805 | 5078 | if (!s) |
85e6fe83 | 5079 | missingterm((char*)0); |
a0d0e21e | 5080 | yylval.ival = OP_STRINGIFY; |
3280af22 | 5081 | if (SvIVX(PL_lex_stuff) == '\'') |
45977657 | 5082 | SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */ |
79072805 LW |
5083 | TERM(sublex_start()); |
5084 | ||
8782bef2 GB |
5085 | case KEY_qr: |
5086 | s = scan_pat(s,OP_QR); | |
5087 | TERM(sublex_start()); | |
5088 | ||
79072805 | 5089 | case KEY_qx: |
09bef843 | 5090 | s = scan_str(s,FALSE,FALSE); |
79072805 | 5091 | if (!s) |
85e6fe83 | 5092 | missingterm((char*)0); |
79072805 LW |
5093 | yylval.ival = OP_BACKTICK; |
5094 | set_csh(); | |
5095 | TERM(sublex_start()); | |
5096 | ||
5097 | case KEY_return: | |
5098 | OLDLOP(OP_RETURN); | |
5099 | ||
5100 | case KEY_require: | |
a7cb1f99 | 5101 | s = skipspace(s); |
e759cc13 RGS |
5102 | if (isDIGIT(*s)) { |
5103 | s = force_version(s, FALSE); | |
a7cb1f99 | 5104 | } |
e759cc13 RGS |
5105 | else if (*s != 'v' || !isDIGIT(s[1]) |
5106 | || (s = force_version(s, TRUE), *s == 'v')) | |
5107 | { | |
a7cb1f99 GS |
5108 | *PL_tokenbuf = '\0'; |
5109 | s = force_word(s,WORD,TRUE,TRUE,FALSE); | |
7e2040f0 | 5110 | if (isIDFIRST_lazy_if(PL_tokenbuf,UTF)) |
a7cb1f99 GS |
5111 | gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE); |
5112 | else if (*s == '<') | |
5113 | yyerror("<> should be quotes"); | |
5114 | } | |
a72a1c8b RGS |
5115 | if (orig_keyword == KEY_require) { |
5116 | orig_keyword = 0; | |
5117 | yylval.ival = 1; | |
5118 | } | |
5119 | else | |
5120 | yylval.ival = 0; | |
5121 | PL_expect = XTERM; | |
5122 | PL_bufptr = s; | |
5123 | PL_last_uni = PL_oldbufptr; | |
5124 | PL_last_lop_op = OP_REQUIRE; | |
5125 | s = skipspace(s); | |
5126 | return REPORT( (int)REQUIRE ); | |
79072805 LW |
5127 | |
5128 | case KEY_reset: | |
5129 | UNI(OP_RESET); | |
5130 | ||
5131 | case KEY_redo: | |
a0d0e21e | 5132 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
5133 | LOOPX(OP_REDO); |
5134 | ||
5135 | case KEY_rename: | |
a0d0e21e | 5136 | LOP(OP_RENAME,XTERM); |
79072805 LW |
5137 | |
5138 | case KEY_rand: | |
5139 | UNI(OP_RAND); | |
5140 | ||
5141 | case KEY_rmdir: | |
5142 | UNI(OP_RMDIR); | |
5143 | ||
5144 | case KEY_rindex: | |
a0d0e21e | 5145 | LOP(OP_RINDEX,XTERM); |
79072805 LW |
5146 | |
5147 | case KEY_read: | |
a0d0e21e | 5148 | LOP(OP_READ,XTERM); |
79072805 LW |
5149 | |
5150 | case KEY_readdir: | |
5151 | UNI(OP_READDIR); | |
5152 | ||
93a17b20 LW |
5153 | case KEY_readline: |
5154 | set_csh(); | |
6f33ba73 | 5155 | UNIDOR(OP_READLINE); |
93a17b20 LW |
5156 | |
5157 | case KEY_readpipe: | |
5158 | set_csh(); | |
5159 | UNI(OP_BACKTICK); | |
5160 | ||
79072805 LW |
5161 | case KEY_rewinddir: |
5162 | UNI(OP_REWINDDIR); | |
5163 | ||
5164 | case KEY_recv: | |
a0d0e21e | 5165 | LOP(OP_RECV,XTERM); |
79072805 LW |
5166 | |
5167 | case KEY_reverse: | |
a0d0e21e | 5168 | LOP(OP_REVERSE,XTERM); |
79072805 LW |
5169 | |
5170 | case KEY_readlink: | |
6f33ba73 | 5171 | UNIDOR(OP_READLINK); |
79072805 LW |
5172 | |
5173 | case KEY_ref: | |
5174 | UNI(OP_REF); | |
5175 | ||
5176 | case KEY_s: | |
5177 | s = scan_subst(s); | |
5178 | if (yylval.opval) | |
5179 | TERM(sublex_start()); | |
5180 | else | |
5181 | TOKEN(1); /* force error */ | |
5182 | ||
a0d0e21e LW |
5183 | case KEY_chomp: |
5184 | UNI(OP_CHOMP); | |
4e553d73 | 5185 | |
79072805 LW |
5186 | case KEY_scalar: |
5187 | UNI(OP_SCALAR); | |
5188 | ||
5189 | case KEY_select: | |
a0d0e21e | 5190 | LOP(OP_SELECT,XTERM); |
79072805 LW |
5191 | |
5192 | case KEY_seek: | |
a0d0e21e | 5193 | LOP(OP_SEEK,XTERM); |
79072805 LW |
5194 | |
5195 | case KEY_semctl: | |
a0d0e21e | 5196 | LOP(OP_SEMCTL,XTERM); |
79072805 LW |
5197 | |
5198 | case KEY_semget: | |
a0d0e21e | 5199 | LOP(OP_SEMGET,XTERM); |
79072805 LW |
5200 | |
5201 | case KEY_semop: | |
a0d0e21e | 5202 | LOP(OP_SEMOP,XTERM); |
79072805 LW |
5203 | |
5204 | case KEY_send: | |
a0d0e21e | 5205 | LOP(OP_SEND,XTERM); |
79072805 LW |
5206 | |
5207 | case KEY_setpgrp: | |
a0d0e21e | 5208 | LOP(OP_SETPGRP,XTERM); |
79072805 LW |
5209 | |
5210 | case KEY_setpriority: | |
a0d0e21e | 5211 | LOP(OP_SETPRIORITY,XTERM); |
79072805 LW |
5212 | |
5213 | case KEY_sethostent: | |
ff68c719 | 5214 | UNI(OP_SHOSTENT); |
79072805 LW |
5215 | |
5216 | case KEY_setnetent: | |
ff68c719 | 5217 | UNI(OP_SNETENT); |
79072805 LW |
5218 | |
5219 | case KEY_setservent: | |
ff68c719 | 5220 | UNI(OP_SSERVENT); |
79072805 LW |
5221 | |
5222 | case KEY_setprotoent: | |
ff68c719 | 5223 | UNI(OP_SPROTOENT); |
79072805 LW |
5224 | |
5225 | case KEY_setpwent: | |
5226 | FUN0(OP_SPWENT); | |
5227 | ||
5228 | case KEY_setgrent: | |
5229 | FUN0(OP_SGRENT); | |
5230 | ||
5231 | case KEY_seekdir: | |
a0d0e21e | 5232 | LOP(OP_SEEKDIR,XTERM); |
79072805 LW |
5233 | |
5234 | case KEY_setsockopt: | |
a0d0e21e | 5235 | LOP(OP_SSOCKOPT,XTERM); |
79072805 LW |
5236 | |
5237 | case KEY_shift: | |
6f33ba73 | 5238 | UNIDOR(OP_SHIFT); |
79072805 LW |
5239 | |
5240 | case KEY_shmctl: | |
a0d0e21e | 5241 | LOP(OP_SHMCTL,XTERM); |
79072805 LW |
5242 | |
5243 | case KEY_shmget: | |
a0d0e21e | 5244 | LOP(OP_SHMGET,XTERM); |
79072805 LW |
5245 | |
5246 | case KEY_shmread: | |
a0d0e21e | 5247 | LOP(OP_SHMREAD,XTERM); |
79072805 LW |
5248 | |
5249 | case KEY_shmwrite: | |
a0d0e21e | 5250 | LOP(OP_SHMWRITE,XTERM); |
79072805 LW |
5251 | |
5252 | case KEY_shutdown: | |
a0d0e21e | 5253 | LOP(OP_SHUTDOWN,XTERM); |
79072805 LW |
5254 | |
5255 | case KEY_sin: | |
5256 | UNI(OP_SIN); | |
5257 | ||
5258 | case KEY_sleep: | |
5259 | UNI(OP_SLEEP); | |
5260 | ||
5261 | case KEY_socket: | |
a0d0e21e | 5262 | LOP(OP_SOCKET,XTERM); |
79072805 LW |
5263 | |
5264 | case KEY_socketpair: | |
a0d0e21e | 5265 | LOP(OP_SOCKPAIR,XTERM); |
79072805 LW |
5266 | |
5267 | case KEY_sort: | |
3280af22 | 5268 | checkcomma(s,PL_tokenbuf,"subroutine name"); |
79072805 LW |
5269 | s = skipspace(s); |
5270 | if (*s == ';' || *s == ')') /* probably a close */ | |
cea2e8a9 | 5271 | Perl_croak(aTHX_ "sort is now a reserved word"); |
3280af22 | 5272 | PL_expect = XTERM; |
15f0808c | 5273 | s = force_word(s,WORD,TRUE,TRUE,FALSE); |
a0d0e21e | 5274 | LOP(OP_SORT,XREF); |
79072805 LW |
5275 | |
5276 | case KEY_split: | |
a0d0e21e | 5277 | LOP(OP_SPLIT,XTERM); |
79072805 LW |
5278 | |
5279 | case KEY_sprintf: | |
a0d0e21e | 5280 | LOP(OP_SPRINTF,XTERM); |
79072805 LW |
5281 | |
5282 | case KEY_splice: | |
a0d0e21e | 5283 | LOP(OP_SPLICE,XTERM); |
79072805 LW |
5284 | |
5285 | case KEY_sqrt: | |
5286 | UNI(OP_SQRT); | |
5287 | ||
5288 | case KEY_srand: | |
5289 | UNI(OP_SRAND); | |
5290 | ||
5291 | case KEY_stat: | |
5292 | UNI(OP_STAT); | |
5293 | ||
5294 | case KEY_study: | |
79072805 LW |
5295 | UNI(OP_STUDY); |
5296 | ||
5297 | case KEY_substr: | |
a0d0e21e | 5298 | LOP(OP_SUBSTR,XTERM); |
79072805 LW |
5299 | |
5300 | case KEY_format: | |
5301 | case KEY_sub: | |
93a17b20 | 5302 | really_sub: |
09bef843 | 5303 | { |
3280af22 | 5304 | char tmpbuf[sizeof PL_tokenbuf]; |
9c5ffd7c | 5305 | SSize_t tboffset = 0; |
09bef843 | 5306 | expectation attrful; |
d731386a | 5307 | bool have_name, have_proto, bad_proto; |
f54cb97a | 5308 | const int key = tmp; |
09bef843 SB |
5309 | |
5310 | s = skipspace(s); | |
5311 | ||
7e2040f0 | 5312 | if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' || |
09bef843 SB |
5313 | (*s == ':' && s[1] == ':')) |
5314 | { | |
5315 | PL_expect = XBLOCK; | |
5316 | attrful = XATTRBLOCK; | |
b1b65b59 JH |
5317 | /* remember buffer pos'n for later force_word */ |
5318 | tboffset = s - PL_oldbufptr; | |
09bef843 SB |
5319 | d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
5320 | if (strchr(tmpbuf, ':')) | |
5321 | sv_setpv(PL_subname, tmpbuf); | |
5322 | else { | |
5323 | sv_setsv(PL_subname,PL_curstname); | |
5324 | sv_catpvn(PL_subname,"::",2); | |
5325 | sv_catpvn(PL_subname,tmpbuf,len); | |
5326 | } | |
5327 | s = skipspace(d); | |
5328 | have_name = TRUE; | |
5329 | } | |
463ee0b2 | 5330 | else { |
09bef843 SB |
5331 | if (key == KEY_my) |
5332 | Perl_croak(aTHX_ "Missing name in \"my sub\""); | |
5333 | PL_expect = XTERMBLOCK; | |
5334 | attrful = XATTRTERM; | |
c69006e4 | 5335 | sv_setpvn(PL_subname,"?",1); |
09bef843 | 5336 | have_name = FALSE; |
463ee0b2 | 5337 | } |
4633a7c4 | 5338 | |
09bef843 SB |
5339 | if (key == KEY_format) { |
5340 | if (*s == '=') | |
5341 | PL_lex_formbrack = PL_lex_brackets + 1; | |
5342 | if (have_name) | |
b1b65b59 JH |
5343 | (void) force_word(PL_oldbufptr + tboffset, WORD, |
5344 | FALSE, TRUE, TRUE); | |
09bef843 SB |
5345 | OPERATOR(FORMAT); |
5346 | } | |
79072805 | 5347 | |
09bef843 SB |
5348 | /* Look for a prototype */ |
5349 | if (*s == '(') { | |
5350 | char *p; | |
5351 | ||
5352 | s = scan_str(s,FALSE,FALSE); | |
37fd879b | 5353 | if (!s) |
09bef843 | 5354 | Perl_croak(aTHX_ "Prototype not terminated"); |
2f758a16 | 5355 | /* strip spaces and check for bad characters */ |
09bef843 SB |
5356 | d = SvPVX(PL_lex_stuff); |
5357 | tmp = 0; | |
d731386a | 5358 | bad_proto = FALSE; |
09bef843 | 5359 | for (p = d; *p; ++p) { |
d37a9538 | 5360 | if (!isSPACE(*p)) { |
09bef843 | 5361 | d[tmp++] = *p; |
d37a9538 ST |
5362 | if (!strchr("$@%*;[]&\\", *p)) |
5363 | bad_proto = TRUE; | |
5364 | } | |
09bef843 SB |
5365 | } |
5366 | d[tmp] = '\0'; | |
420cdfc1 | 5367 | if (bad_proto && ckWARN(WARN_SYNTAX)) |
9014280d | 5368 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
35c1215d NC |
5369 | "Illegal character in prototype for %"SVf" : %s", |
5370 | PL_subname, d); | |
b162af07 | 5371 | SvCUR_set(PL_lex_stuff, tmp); |
09bef843 | 5372 | have_proto = TRUE; |
68dc0745 | 5373 | |
09bef843 | 5374 | s = skipspace(s); |
4633a7c4 | 5375 | } |
09bef843 SB |
5376 | else |
5377 | have_proto = FALSE; | |
5378 | ||
5379 | if (*s == ':' && s[1] != ':') | |
5380 | PL_expect = attrful; | |
8e742a20 MHM |
5381 | else if (*s != '{' && key == KEY_sub) { |
5382 | if (!have_name) | |
5383 | Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine"); | |
5384 | else if (*s != ';') | |
5385 | Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname); | |
5386 | } | |
09bef843 SB |
5387 | |
5388 | if (have_proto) { | |
b1b65b59 JH |
5389 | PL_nextval[PL_nexttoke].opval = |
5390 | (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff); | |
09bef843 SB |
5391 | PL_lex_stuff = Nullsv; |
5392 | force_next(THING); | |
68dc0745 | 5393 | } |
09bef843 | 5394 | if (!have_name) { |
c99da370 JH |
5395 | sv_setpv(PL_subname, |
5396 | PL_curstash ? "__ANON__" : "__ANON__::__ANON__"); | |
09bef843 | 5397 | TOKEN(ANONSUB); |
4633a7c4 | 5398 | } |
b1b65b59 JH |
5399 | (void) force_word(PL_oldbufptr + tboffset, WORD, |
5400 | FALSE, TRUE, TRUE); | |
09bef843 SB |
5401 | if (key == KEY_my) |
5402 | TOKEN(MYSUB); | |
5403 | TOKEN(SUB); | |
4633a7c4 | 5404 | } |
79072805 LW |
5405 | |
5406 | case KEY_system: | |
5407 | set_csh(); | |
a0d0e21e | 5408 | LOP(OP_SYSTEM,XREF); |
79072805 LW |
5409 | |
5410 | case KEY_symlink: | |
a0d0e21e | 5411 | LOP(OP_SYMLINK,XTERM); |
79072805 LW |
5412 | |
5413 | case KEY_syscall: | |
a0d0e21e | 5414 | LOP(OP_SYSCALL,XTERM); |
79072805 | 5415 | |
c07a80fd | 5416 | case KEY_sysopen: |
5417 | LOP(OP_SYSOPEN,XTERM); | |
5418 | ||
137443ea | 5419 | case KEY_sysseek: |
5420 | LOP(OP_SYSSEEK,XTERM); | |
5421 | ||
79072805 | 5422 | case KEY_sysread: |
a0d0e21e | 5423 | LOP(OP_SYSREAD,XTERM); |
79072805 LW |
5424 | |
5425 | case KEY_syswrite: | |
a0d0e21e | 5426 | LOP(OP_SYSWRITE,XTERM); |
79072805 LW |
5427 | |
5428 | case KEY_tr: | |
5429 | s = scan_trans(s); | |
5430 | TERM(sublex_start()); | |
5431 | ||
5432 | case KEY_tell: | |
5433 | UNI(OP_TELL); | |
5434 | ||
5435 | case KEY_telldir: | |
5436 | UNI(OP_TELLDIR); | |
5437 | ||
463ee0b2 | 5438 | case KEY_tie: |
a0d0e21e | 5439 | LOP(OP_TIE,XTERM); |
463ee0b2 | 5440 | |
c07a80fd | 5441 | case KEY_tied: |
5442 | UNI(OP_TIED); | |
5443 | ||
79072805 LW |
5444 | case KEY_time: |
5445 | FUN0(OP_TIME); | |
5446 | ||
5447 | case KEY_times: | |
5448 | FUN0(OP_TMS); | |
5449 | ||
5450 | case KEY_truncate: | |
a0d0e21e | 5451 | LOP(OP_TRUNCATE,XTERM); |
79072805 LW |
5452 | |
5453 | case KEY_uc: | |
5454 | UNI(OP_UC); | |
5455 | ||
5456 | case KEY_ucfirst: | |
5457 | UNI(OP_UCFIRST); | |
5458 | ||
463ee0b2 LW |
5459 | case KEY_untie: |
5460 | UNI(OP_UNTIE); | |
5461 | ||
79072805 | 5462 | case KEY_until: |
57843af0 | 5463 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5464 | OPERATOR(UNTIL); |
5465 | ||
5466 | case KEY_unless: | |
57843af0 | 5467 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5468 | OPERATOR(UNLESS); |
5469 | ||
5470 | case KEY_unlink: | |
a0d0e21e | 5471 | LOP(OP_UNLINK,XTERM); |
79072805 LW |
5472 | |
5473 | case KEY_undef: | |
6f33ba73 | 5474 | UNIDOR(OP_UNDEF); |
79072805 LW |
5475 | |
5476 | case KEY_unpack: | |
a0d0e21e | 5477 | LOP(OP_UNPACK,XTERM); |
79072805 LW |
5478 | |
5479 | case KEY_utime: | |
a0d0e21e | 5480 | LOP(OP_UTIME,XTERM); |
79072805 LW |
5481 | |
5482 | case KEY_umask: | |
6f33ba73 | 5483 | UNIDOR(OP_UMASK); |
79072805 LW |
5484 | |
5485 | case KEY_unshift: | |
a0d0e21e LW |
5486 | LOP(OP_UNSHIFT,XTERM); |
5487 | ||
5488 | case KEY_use: | |
468aa647 | 5489 | s = tokenize_use(1, s); |
a0d0e21e | 5490 | OPERATOR(USE); |
79072805 LW |
5491 | |
5492 | case KEY_values: | |
5493 | UNI(OP_VALUES); | |
5494 | ||
5495 | case KEY_vec: | |
a0d0e21e | 5496 | LOP(OP_VEC,XTERM); |
79072805 LW |
5497 | |
5498 | case KEY_while: | |
57843af0 | 5499 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5500 | OPERATOR(WHILE); |
5501 | ||
5502 | case KEY_warn: | |
3280af22 | 5503 | PL_hints |= HINT_BLOCK_SCOPE; |
a0d0e21e | 5504 | LOP(OP_WARN,XTERM); |
79072805 LW |
5505 | |
5506 | case KEY_wait: | |
5507 | FUN0(OP_WAIT); | |
5508 | ||
5509 | case KEY_waitpid: | |
a0d0e21e | 5510 | LOP(OP_WAITPID,XTERM); |
79072805 LW |
5511 | |
5512 | case KEY_wantarray: | |
5513 | FUN0(OP_WANTARRAY); | |
5514 | ||
5515 | case KEY_write: | |
9d116dd7 JH |
5516 | #ifdef EBCDIC |
5517 | { | |
df3728a2 JH |
5518 | char ctl_l[2]; |
5519 | ctl_l[0] = toCTRL('L'); | |
5520 | ctl_l[1] = '\0'; | |
9d116dd7 JH |
5521 | gv_fetchpv(ctl_l,TRUE, SVt_PV); |
5522 | } | |
5523 | #else | |
5524 | gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */ | |
5525 | #endif | |
79072805 LW |
5526 | UNI(OP_ENTERWRITE); |
5527 | ||
5528 | case KEY_x: | |
3280af22 | 5529 | if (PL_expect == XOPERATOR) |
79072805 LW |
5530 | Mop(OP_REPEAT); |
5531 | check_uni(); | |
5532 | goto just_a_word; | |
5533 | ||
a0d0e21e LW |
5534 | case KEY_xor: |
5535 | yylval.ival = OP_XOR; | |
5536 | OPERATOR(OROP); | |
5537 | ||
79072805 LW |
5538 | case KEY_y: |
5539 | s = scan_trans(s); | |
5540 | TERM(sublex_start()); | |
5541 | } | |
49dc05e3 | 5542 | }} |
79072805 | 5543 | } |
bf4acbe4 GS |
5544 | #ifdef __SC__ |
5545 | #pragma segment Main | |
5546 | #endif | |
79072805 | 5547 | |
e930465f JH |
5548 | static int |
5549 | S_pending_ident(pTHX) | |
8eceec63 SC |
5550 | { |
5551 | register char *d; | |
a55b55d8 | 5552 | register I32 tmp = 0; |
8eceec63 SC |
5553 | /* pit holds the identifier we read and pending_ident is reset */ |
5554 | char pit = PL_pending_ident; | |
5555 | PL_pending_ident = 0; | |
5556 | ||
5557 | DEBUG_T({ PerlIO_printf(Perl_debug_log, | |
b6007c36 | 5558 | "### Pending identifier '%s'\n", PL_tokenbuf); }); |
8eceec63 SC |
5559 | |
5560 | /* if we're in a my(), we can't allow dynamics here. | |
5561 | $foo'bar has already been turned into $foo::bar, so | |
5562 | just check for colons. | |
5563 | ||
5564 | if it's a legal name, the OP is a PADANY. | |
5565 | */ | |
5566 | if (PL_in_my) { | |
5567 | if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */ | |
5568 | if (strchr(PL_tokenbuf,':')) | |
5569 | yyerror(Perl_form(aTHX_ "No package name allowed for " | |
5570 | "variable %s in \"our\"", | |
5571 | PL_tokenbuf)); | |
dd2155a4 | 5572 | tmp = allocmy(PL_tokenbuf); |
8eceec63 SC |
5573 | } |
5574 | else { | |
5575 | if (strchr(PL_tokenbuf,':')) | |
5576 | yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf)); | |
5577 | ||
5578 | yylval.opval = newOP(OP_PADANY, 0); | |
dd2155a4 | 5579 | yylval.opval->op_targ = allocmy(PL_tokenbuf); |
8eceec63 SC |
5580 | return PRIVATEREF; |
5581 | } | |
5582 | } | |
5583 | ||
5584 | /* | |
5585 | build the ops for accesses to a my() variable. | |
5586 | ||
5587 | Deny my($a) or my($b) in a sort block, *if* $a or $b is | |
5588 | then used in a comparison. This catches most, but not | |
5589 | all cases. For instance, it catches | |
5590 | sort { my($a); $a <=> $b } | |
5591 | but not | |
5592 | sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; } | |
5593 | (although why you'd do that is anyone's guess). | |
5594 | */ | |
5595 | ||
5596 | if (!strchr(PL_tokenbuf,':')) { | |
8716503d DM |
5597 | if (!PL_in_my) |
5598 | tmp = pad_findmy(PL_tokenbuf); | |
5599 | if (tmp != NOT_IN_PAD) { | |
8eceec63 | 5600 | /* might be an "our" variable" */ |
dd2155a4 | 5601 | if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) { |
8eceec63 | 5602 | /* build ops for a bareword */ |
b64e5050 AL |
5603 | HV * const stash = PAD_COMPNAME_OURSTASH(tmp); |
5604 | HEK * const stashname = HvNAME_HEK(stash); | |
5605 | SV * const sym = newSVhek(stashname); | |
8eceec63 SC |
5606 | sv_catpvn(sym, "::", 2); |
5607 | sv_catpv(sym, PL_tokenbuf+1); | |
5608 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym); | |
5609 | yylval.opval->op_private = OPpCONST_ENTERED; | |
7a5fd60d | 5610 | gv_fetchsv(sym, |
8eceec63 SC |
5611 | (PL_in_eval |
5612 | ? (GV_ADDMULTI | GV_ADDINEVAL) | |
700078d2 | 5613 | : GV_ADDMULTI |
8eceec63 SC |
5614 | ), |
5615 | ((PL_tokenbuf[0] == '$') ? SVt_PV | |
5616 | : (PL_tokenbuf[0] == '@') ? SVt_PVAV | |
5617 | : SVt_PVHV)); | |
5618 | return WORD; | |
5619 | } | |
5620 | ||
5621 | /* if it's a sort block and they're naming $a or $b */ | |
5622 | if (PL_last_lop_op == OP_SORT && | |
5623 | PL_tokenbuf[0] == '$' && | |
5624 | (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b') | |
5625 | && !PL_tokenbuf[2]) | |
5626 | { | |
5627 | for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart; | |
5628 | d < PL_bufend && *d != '\n'; | |
5629 | d++) | |
5630 | { | |
5631 | if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) { | |
5632 | Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison", | |
5633 | PL_tokenbuf); | |
5634 | } | |
5635 | } | |
5636 | } | |
5637 | ||
5638 | yylval.opval = newOP(OP_PADANY, 0); | |
5639 | yylval.opval->op_targ = tmp; | |
5640 | return PRIVATEREF; | |
5641 | } | |
5642 | } | |
5643 | ||
5644 | /* | |
5645 | Whine if they've said @foo in a doublequoted string, | |
5646 | and @foo isn't a variable we can find in the symbol | |
5647 | table. | |
5648 | */ | |
5649 | if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) { | |
5650 | GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV); | |
5651 | if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv))) | |
5652 | && ckWARN(WARN_AMBIGUOUS)) | |
5653 | { | |
5654 | /* Downgraded from fatal to warning 20000522 mjd */ | |
9014280d | 5655 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
8eceec63 SC |
5656 | "Possible unintended interpolation of %s in string", |
5657 | PL_tokenbuf); | |
5658 | } | |
5659 | } | |
5660 | ||
5661 | /* build ops for a bareword */ | |
5662 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0)); | |
5663 | yylval.opval->op_private = OPpCONST_ENTERED; | |
5664 | gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE, | |
5665 | ((PL_tokenbuf[0] == '$') ? SVt_PV | |
5666 | : (PL_tokenbuf[0] == '@') ? SVt_PVAV | |
5667 | : SVt_PVHV)); | |
5668 | return WORD; | |
5669 | } | |
5670 | ||
4c3bbe0f MHM |
5671 | /* |
5672 | * The following code was generated by perl_keyword.pl. | |
5673 | */ | |
e2e1dd5a | 5674 | |
79072805 | 5675 | I32 |
672994ce | 5676 | Perl_keyword (pTHX_ const char *name, I32 len) |
4c3bbe0f MHM |
5677 | { |
5678 | switch (len) | |
5679 | { | |
5680 | case 1: /* 5 tokens of length 1 */ | |
5681 | switch (name[0]) | |
e2e1dd5a | 5682 | { |
4c3bbe0f MHM |
5683 | case 'm': |
5684 | { /* m */ | |
5685 | return KEY_m; | |
5686 | } | |
5687 | ||
4c3bbe0f MHM |
5688 | case 'q': |
5689 | { /* q */ | |
5690 | return KEY_q; | |
5691 | } | |
5692 | ||
4c3bbe0f MHM |
5693 | case 's': |
5694 | { /* s */ | |
5695 | return KEY_s; | |
5696 | } | |
5697 | ||
4c3bbe0f MHM |
5698 | case 'x': |
5699 | { /* x */ | |
5700 | return -KEY_x; | |
5701 | } | |
5702 | ||
4c3bbe0f MHM |
5703 | case 'y': |
5704 | { /* y */ | |
5705 | return KEY_y; | |
5706 | } | |
5707 | ||
4c3bbe0f MHM |
5708 | default: |
5709 | goto unknown; | |
e2e1dd5a | 5710 | } |
4c3bbe0f MHM |
5711 | |
5712 | case 2: /* 18 tokens of length 2 */ | |
5713 | switch (name[0]) | |
e2e1dd5a | 5714 | { |
4c3bbe0f MHM |
5715 | case 'd': |
5716 | if (name[1] == 'o') | |
5717 | { /* do */ | |
5718 | return KEY_do; | |
5719 | } | |
5720 | ||
5721 | goto unknown; | |
5722 | ||
5723 | case 'e': | |
5724 | if (name[1] == 'q') | |
5725 | { /* eq */ | |
5726 | return -KEY_eq; | |
5727 | } | |
5728 | ||
5729 | goto unknown; | |
5730 | ||
5731 | case 'g': | |
5732 | switch (name[1]) | |
5733 | { | |
5734 | case 'e': | |
5735 | { /* ge */ | |
5736 | return -KEY_ge; | |
5737 | } | |
5738 | ||
4c3bbe0f MHM |
5739 | case 't': |
5740 | { /* gt */ | |
5741 | return -KEY_gt; | |
5742 | } | |
5743 | ||
4c3bbe0f MHM |
5744 | default: |
5745 | goto unknown; | |
5746 | } | |
5747 | ||
5748 | case 'i': | |
5749 | if (name[1] == 'f') | |
5750 | { /* if */ | |
5751 | return KEY_if; | |
5752 | } | |
5753 | ||
5754 | goto unknown; | |
5755 | ||
5756 | case 'l': | |
5757 | switch (name[1]) | |
5758 | { | |
5759 | case 'c': | |
5760 | { /* lc */ | |
5761 | return -KEY_lc; | |
5762 | } | |
5763 | ||
4c3bbe0f MHM |
5764 | case 'e': |
5765 | { /* le */ | |
5766 | return -KEY_le; | |
5767 | } | |
5768 | ||
4c3bbe0f MHM |
5769 | case 't': |
5770 | { /* lt */ | |
5771 | return -KEY_lt; | |
5772 | } | |
5773 | ||
4c3bbe0f MHM |
5774 | default: |
5775 | goto unknown; | |
5776 | } | |
5777 | ||
5778 | case 'm': | |
5779 | if (name[1] == 'y') | |
5780 | { /* my */ | |
5781 | return KEY_my; | |
5782 | } | |
5783 | ||
5784 | goto unknown; | |
5785 | ||
5786 | case 'n': | |
5787 | switch (name[1]) | |
5788 | { | |
5789 | case 'e': | |
5790 | { /* ne */ | |
5791 | return -KEY_ne; | |
5792 | } | |
5793 | ||
4c3bbe0f MHM |
5794 | case 'o': |
5795 | { /* no */ | |
5796 | return KEY_no; | |
5797 | } | |
5798 | ||
4c3bbe0f MHM |
5799 | default: |
5800 | goto unknown; | |
5801 | } | |
5802 | ||
5803 | case 'o': | |
5804 | if (name[1] == 'r') | |
5805 | { /* or */ | |
5806 | return -KEY_or; | |
5807 | } | |
5808 | ||
5809 | goto unknown; | |
5810 | ||
5811 | case 'q': | |
5812 | switch (name[1]) | |
5813 | { | |
5814 | case 'q': | |
5815 | { /* qq */ | |
5816 | return KEY_qq; | |
5817 | } | |
5818 | ||
4c3bbe0f MHM |
5819 | case 'r': |
5820 | { /* qr */ | |
5821 | return KEY_qr; | |
5822 | } | |
5823 | ||
4c3bbe0f MHM |
5824 | case 'w': |
5825 | { /* qw */ | |
5826 | return KEY_qw; | |
5827 | } | |
5828 | ||
4c3bbe0f MHM |
5829 | case 'x': |
5830 | { /* qx */ | |
5831 | return KEY_qx; | |
5832 | } | |
5833 | ||
4c3bbe0f MHM |
5834 | default: |
5835 | goto unknown; | |
5836 | } | |
5837 | ||
5838 | case 't': | |
5839 | if (name[1] == 'r') | |
5840 | { /* tr */ | |
5841 | return KEY_tr; | |
5842 | } | |
5843 | ||
5844 | goto unknown; | |
5845 | ||
5846 | case 'u': | |
5847 | if (name[1] == 'c') | |
5848 | { /* uc */ | |
5849 | return -KEY_uc; | |
5850 | } | |
5851 | ||
5852 | goto unknown; | |
5853 | ||
5854 | default: | |
5855 | goto unknown; | |
e2e1dd5a | 5856 | } |
4c3bbe0f MHM |
5857 | |
5858 | case 3: /* 28 tokens of length 3 */ | |
5859 | switch (name[0]) | |
e2e1dd5a | 5860 | { |
4c3bbe0f MHM |
5861 | case 'E': |
5862 | if (name[1] == 'N' && | |
5863 | name[2] == 'D') | |
5864 | { /* END */ | |
5865 | return KEY_END; | |
5866 | } | |
5867 | ||
5868 | goto unknown; | |
5869 | ||
5870 | case 'a': | |
5871 | switch (name[1]) | |
5872 | { | |
5873 | case 'b': | |
5874 | if (name[2] == 's') | |
5875 | { /* abs */ | |
5876 | return -KEY_abs; | |
5877 | } | |
5878 | ||
5879 | goto unknown; | |
5880 | ||
5881 | case 'n': | |
5882 | if (name[2] == 'd') | |
5883 | { /* and */ | |
5884 | return -KEY_and; | |
5885 | } | |
5886 | ||
5887 | goto unknown; | |
5888 | ||
5889 | default: | |
5890 | goto unknown; | |
5891 | } | |
5892 | ||
5893 | case 'c': | |
5894 | switch (name[1]) | |
5895 | { | |
5896 | case 'h': | |
5897 | if (name[2] == 'r') | |
5898 | { /* chr */ | |
5899 | return -KEY_chr; | |
5900 | } | |
5901 | ||
5902 | goto unknown; | |
5903 | ||
5904 | case 'm': | |
5905 | if (name[2] == 'p') | |
5906 | { /* cmp */ | |
5907 | return -KEY_cmp; | |
5908 | } | |
5909 | ||
5910 | goto unknown; | |
5911 | ||
5912 | case 'o': | |
5913 | if (name[2] == 's') | |
5914 | { /* cos */ | |
5915 | return -KEY_cos; | |
5916 | } | |
5917 | ||
5918 | goto unknown; | |
5919 | ||
5920 | default: | |
5921 | goto unknown; | |
5922 | } | |
5923 | ||
5924 | case 'd': | |
5925 | if (name[1] == 'i' && | |
5926 | name[2] == 'e') | |
5927 | { /* die */ | |
5928 | return -KEY_die; | |
5929 | } | |
5930 | ||
5931 | goto unknown; | |
5932 | ||
5933 | case 'e': | |
5934 | switch (name[1]) | |
5935 | { | |
5936 | case 'o': | |
5937 | if (name[2] == 'f') | |
5938 | { /* eof */ | |
5939 | return -KEY_eof; | |
5940 | } | |
5941 | ||
5942 | goto unknown; | |
5943 | ||
5944 | case 'r': | |
5945 | if (name[2] == 'r') | |
5946 | { /* err */ | |
5947 | return -KEY_err; | |
5948 | } | |
5949 | ||
5950 | goto unknown; | |
5951 | ||
5952 | case 'x': | |
5953 | if (name[2] == 'p') | |
5954 | { /* exp */ | |
5955 | return -KEY_exp; | |
5956 | } | |
5957 | ||
5958 | goto unknown; | |
5959 | ||
5960 | default: | |
5961 | goto unknown; | |
5962 | } | |
5963 | ||
5964 | case 'f': | |
5965 | if (name[1] == 'o' && | |
5966 | name[2] == 'r') | |
5967 | { /* for */ | |
5968 | return KEY_for; | |
5969 | } | |
5970 | ||
5971 | goto unknown; | |
5972 | ||
5973 | case 'h': | |
5974 | if (name[1] == 'e' && | |
5975 | name[2] == 'x') | |
5976 | { /* hex */ | |
5977 | return -KEY_hex; | |
5978 | } | |
5979 | ||
5980 | goto unknown; | |
5981 | ||
5982 | case 'i': | |
5983 | if (name[1] == 'n' && | |
5984 | name[2] == 't') | |
5985 | { /* int */ | |
5986 | return -KEY_int; | |
5987 | } | |
5988 | ||
5989 | goto unknown; | |
5990 | ||
5991 | case 'l': | |
5992 | if (name[1] == 'o' && | |
5993 | name[2] == 'g') | |
5994 | { /* log */ | |
5995 | return -KEY_log; | |
5996 | } | |
5997 | ||
5998 | goto unknown; | |
5999 | ||
6000 | case 'm': | |
6001 | if (name[1] == 'a' && | |
6002 | name[2] == 'p') | |
6003 | { /* map */ | |
6004 | return KEY_map; | |
6005 | } | |
6006 | ||
6007 | goto unknown; | |
6008 | ||
6009 | case 'n': | |
6010 | if (name[1] == 'o' && | |
6011 | name[2] == 't') | |
6012 | { /* not */ | |
6013 | return -KEY_not; | |
6014 | } | |
6015 | ||
6016 | goto unknown; | |
6017 | ||
6018 | case 'o': | |
6019 | switch (name[1]) | |
6020 | { | |
6021 | case 'c': | |
6022 | if (name[2] == 't') | |
6023 | { /* oct */ | |
6024 | return -KEY_oct; | |
6025 | } | |
6026 | ||
6027 | goto unknown; | |
6028 | ||
6029 | case 'r': | |
6030 | if (name[2] == 'd') | |
6031 | { /* ord */ | |
6032 | return -KEY_ord; | |
6033 | } | |
6034 | ||
6035 | goto unknown; | |
6036 | ||
6037 | case 'u': | |
6038 | if (name[2] == 'r') | |
6039 | { /* our */ | |
6040 | return KEY_our; | |
6041 | } | |
6042 | ||
6043 | goto unknown; | |
6044 | ||
6045 | default: | |
6046 | goto unknown; | |
6047 | } | |
6048 | ||
6049 | case 'p': | |
6050 | if (name[1] == 'o') | |
6051 | { | |
6052 | switch (name[2]) | |
6053 | { | |
6054 | case 'p': | |
6055 | { /* pop */ | |
6056 | return -KEY_pop; | |
6057 | } | |
6058 | ||
4c3bbe0f MHM |
6059 | case 's': |
6060 | { /* pos */ | |
6061 | return KEY_pos; | |
6062 | } | |
6063 | ||
4c3bbe0f MHM |
6064 | default: |
6065 | goto unknown; | |
6066 | } | |
6067 | } | |
6068 | ||
6069 | goto unknown; | |
6070 | ||
6071 | case 'r': | |
6072 | if (name[1] == 'e' && | |
6073 | name[2] == 'f') | |
6074 | { /* ref */ | |
6075 | return -KEY_ref; | |
6076 | } | |
6077 | ||
6078 | goto unknown; | |
6079 | ||
6080 | case 's': | |
6081 | switch (name[1]) | |
6082 | { | |
6083 | case 'i': | |
6084 | if (name[2] == 'n') | |
6085 | { /* sin */ | |
6086 | return -KEY_sin; | |
6087 | } | |
6088 | ||
6089 | goto unknown; | |
6090 | ||
6091 | case 'u': | |
6092 | if (name[2] == 'b') | |
6093 | { /* sub */ | |
6094 | return KEY_sub; | |
6095 | } | |
6096 | ||
6097 | goto unknown; | |
6098 | ||
6099 | default: | |
6100 | goto unknown; | |
6101 | } | |
6102 | ||
6103 | case 't': | |
6104 | if (name[1] == 'i' && | |
6105 | name[2] == 'e') | |
6106 | { /* tie */ | |
6107 | return KEY_tie; | |
6108 | } | |
6109 | ||
6110 | goto unknown; | |
6111 | ||
6112 | case 'u': | |
6113 | if (name[1] == 's' && | |
6114 | name[2] == 'e') | |
6115 | { /* use */ | |
6116 | return KEY_use; | |
6117 | } | |
6118 | ||
6119 | goto unknown; | |
6120 | ||
6121 | case 'v': | |
6122 | if (name[1] == 'e' && | |
6123 | name[2] == 'c') | |
6124 | { /* vec */ | |
6125 | return -KEY_vec; | |
6126 | } | |
6127 | ||
6128 | goto unknown; | |
6129 | ||
6130 | case 'x': | |
6131 | if (name[1] == 'o' && | |
6132 | name[2] == 'r') | |
6133 | { /* xor */ | |
6134 | return -KEY_xor; | |
6135 | } | |
6136 | ||
6137 | goto unknown; | |
6138 | ||
6139 | default: | |
6140 | goto unknown; | |
e2e1dd5a | 6141 | } |
4c3bbe0f MHM |
6142 | |
6143 | case 4: /* 40 tokens of length 4 */ | |
6144 | switch (name[0]) | |
e2e1dd5a | 6145 | { |
4c3bbe0f MHM |
6146 | case 'C': |
6147 | if (name[1] == 'O' && | |
6148 | name[2] == 'R' && | |
6149 | name[3] == 'E') | |
6150 | { /* CORE */ | |
6151 | return -KEY_CORE; | |
6152 | } | |
6153 | ||
6154 | goto unknown; | |
6155 | ||
6156 | case 'I': | |
6157 | if (name[1] == 'N' && | |
6158 | name[2] == 'I' && | |
6159 | name[3] == 'T') | |
6160 | { /* INIT */ | |
6161 | return KEY_INIT; | |
6162 | } | |
6163 | ||
6164 | goto unknown; | |
6165 | ||
6166 | case 'b': | |
6167 | if (name[1] == 'i' && | |
6168 | name[2] == 'n' && | |
6169 | name[3] == 'd') | |
6170 | { /* bind */ | |
6171 | return -KEY_bind; | |
6172 | } | |
6173 | ||
6174 | goto unknown; | |
6175 | ||
6176 | case 'c': | |
6177 | if (name[1] == 'h' && | |
6178 | name[2] == 'o' && | |
6179 | name[3] == 'p') | |
6180 | { /* chop */ | |
6181 | return -KEY_chop; | |
6182 | } | |
6183 | ||
6184 | goto unknown; | |
6185 | ||
6186 | case 'd': | |
6187 | if (name[1] == 'u' && | |
6188 | name[2] == 'm' && | |
6189 | name[3] == 'p') | |
6190 | { /* dump */ | |
6191 | return -KEY_dump; | |
6192 | } | |
6193 | ||
6194 | goto unknown; | |
6195 | ||
6196 | case 'e': | |
6197 | switch (name[1]) | |
6198 | { | |
6199 | case 'a': | |
6200 | if (name[2] == 'c' && | |
6201 | name[3] == 'h') | |
6202 | { /* each */ | |
6203 | return -KEY_each; | |
6204 | } | |
6205 | ||
6206 | goto unknown; | |
6207 | ||
6208 | case 'l': | |
6209 | if (name[2] == 's' && | |
6210 | name[3] == 'e') | |
6211 | { /* else */ | |
6212 | return KEY_else; | |
6213 | } | |
6214 | ||
6215 | goto unknown; | |
6216 | ||
6217 | case 'v': | |
6218 | if (name[2] == 'a' && | |
6219 | name[3] == 'l') | |
6220 | { /* eval */ | |
6221 | return KEY_eval; | |
6222 | } | |
6223 | ||
6224 | goto unknown; | |
6225 | ||
6226 | case 'x': | |
6227 | switch (name[2]) | |
6228 | { | |
6229 | case 'e': | |
6230 | if (name[3] == 'c') | |
6231 | { /* exec */ | |
6232 | return -KEY_exec; | |
6233 | } | |
6234 | ||
6235 | goto unknown; | |
6236 | ||
6237 | case 'i': | |
6238 | if (name[3] == 't') | |
6239 | { /* exit */ | |
6240 | return -KEY_exit; | |
6241 | } | |
6242 | ||
6243 | goto unknown; | |
6244 | ||
6245 | default: | |
6246 | goto unknown; | |
6247 | } | |
6248 | ||
6249 | default: | |
6250 | goto unknown; | |
6251 | } | |
6252 | ||
6253 | case 'f': | |
6254 | if (name[1] == 'o' && | |
6255 | name[2] == 'r' && | |
6256 | name[3] == 'k') | |
6257 | { /* fork */ | |
6258 | return -KEY_fork; | |
6259 | } | |
6260 | ||
6261 | goto unknown; | |
6262 | ||
6263 | case 'g': | |
6264 | switch (name[1]) | |
6265 | { | |
6266 | case 'e': | |
6267 | if (name[2] == 't' && | |
6268 | name[3] == 'c') | |
6269 | { /* getc */ | |
6270 | return -KEY_getc; | |
6271 | } | |
6272 | ||
6273 | goto unknown; | |
6274 | ||
6275 | case 'l': | |
6276 | if (name[2] == 'o' && | |
6277 | name[3] == 'b') | |
6278 | { /* glob */ | |
6279 | return KEY_glob; | |
6280 | } | |
6281 | ||
6282 | goto unknown; | |
6283 | ||
6284 | case 'o': | |
6285 | if (name[2] == 't' && | |
6286 | name[3] == 'o') | |
6287 | { /* goto */ | |
6288 | return KEY_goto; | |
6289 | } | |
6290 | ||
6291 | goto unknown; | |
6292 | ||
6293 | case 'r': | |
6294 | if (name[2] == 'e' && | |
6295 | name[3] == 'p') | |
6296 | { /* grep */ | |
6297 | return KEY_grep; | |
6298 | } | |
6299 | ||
6300 | goto unknown; | |
6301 | ||
6302 | default: | |
6303 | goto unknown; | |
6304 | } | |
6305 | ||
6306 | case 'j': | |
6307 | if (name[1] == 'o' && | |
6308 | name[2] == 'i' && | |
6309 | name[3] == 'n') | |
6310 | { /* join */ | |
6311 | return -KEY_join; | |
6312 | } | |
6313 | ||
6314 | goto unknown; | |
6315 | ||
6316 | case 'k': | |
6317 | switch (name[1]) | |
6318 | { | |
6319 | case 'e': | |
6320 | if (name[2] == 'y' && | |
6321 | name[3] == 's') | |
6322 | { /* keys */ | |
6323 | return -KEY_keys; | |
6324 | } | |
6325 | ||
6326 | goto unknown; | |
6327 | ||
6328 | case 'i': | |
6329 | if (name[2] == 'l' && | |
6330 | name[3] == 'l') | |
6331 | { /* kill */ | |
6332 | return -KEY_kill; | |
6333 | } | |
6334 | ||
6335 | goto unknown; | |
6336 | ||
6337 | default: | |
6338 | goto unknown; | |
6339 | } | |
6340 | ||
6341 | case 'l': | |
6342 | switch (name[1]) | |
6343 | { | |
6344 | case 'a': | |
6345 | if (name[2] == 's' && | |
6346 | name[3] == 't') | |
6347 | { /* last */ | |
6348 | return KEY_last; | |
6349 | } | |
6350 | ||
6351 | goto unknown; | |
6352 | ||
6353 | case 'i': | |
6354 | if (name[2] == 'n' && | |
6355 | name[3] == 'k') | |
6356 | { /* link */ | |
6357 | return -KEY_link; | |
6358 | } | |
6359 | ||
6360 | goto unknown; | |
6361 | ||
6362 | case 'o': | |
6363 | if (name[2] == 'c' && | |
6364 | name[3] == 'k') | |
6365 | { /* lock */ | |
6366 | return -KEY_lock; | |
6367 | } | |
6368 | ||
6369 | goto unknown; | |
6370 | ||
6371 | default: | |
6372 | goto unknown; | |
6373 | } | |
6374 | ||
6375 | case 'n': | |
6376 | if (name[1] == 'e' && | |
6377 | name[2] == 'x' && | |
6378 | name[3] == 't') | |
6379 | { /* next */ | |
6380 | return KEY_next; | |
6381 | } | |
6382 | ||
6383 | goto unknown; | |
6384 | ||
6385 | case 'o': | |
6386 | if (name[1] == 'p' && | |
6387 | name[2] == 'e' && | |
6388 | name[3] == 'n') | |
6389 | { /* open */ | |
6390 | return -KEY_open; | |
6391 | } | |
6392 | ||
6393 | goto unknown; | |
6394 | ||
6395 | case 'p': | |
6396 | switch (name[1]) | |
6397 | { | |
6398 | case 'a': | |
6399 | if (name[2] == 'c' && | |
6400 | name[3] == 'k') | |
6401 | { /* pack */ | |
6402 | return -KEY_pack; | |
6403 | } | |
6404 | ||
6405 | goto unknown; | |
6406 | ||
6407 | case 'i': | |
6408 | if (name[2] == 'p' && | |
6409 | name[3] == 'e') | |
6410 | { /* pipe */ | |
6411 | return -KEY_pipe; | |
6412 | } | |
6413 | ||
6414 | goto unknown; | |
6415 | ||
6416 | case 'u': | |
6417 | if (name[2] == 's' && | |
6418 | name[3] == 'h') | |
6419 | { /* push */ | |
6420 | return -KEY_push; | |
6421 | } | |
6422 | ||
6423 | goto unknown; | |
6424 | ||
6425 | default: | |
6426 | goto unknown; | |
6427 | } | |
6428 | ||
6429 | case 'r': | |
6430 | switch (name[1]) | |
6431 | { | |
6432 | case 'a': | |
6433 | if (name[2] == 'n' && | |
6434 | name[3] == 'd') | |
6435 | { /* rand */ | |
6436 | return -KEY_rand; | |
6437 | } | |
6438 | ||
6439 | goto unknown; | |
6440 | ||
6441 | case 'e': | |
6442 | switch (name[2]) | |
6443 | { | |
6444 | case 'a': | |
6445 | if (name[3] == 'd') | |
6446 | { /* read */ | |
6447 | return -KEY_read; | |
6448 | } | |
6449 | ||
6450 | goto unknown; | |
6451 | ||
6452 | case 'c': | |
6453 | if (name[3] == 'v') | |
6454 | { /* recv */ | |
6455 | return -KEY_recv; | |
6456 | } | |
6457 | ||
6458 | goto unknown; | |
6459 | ||
6460 | case 'd': | |
6461 | if (name[3] == 'o') | |
6462 | { /* redo */ | |
6463 | return KEY_redo; | |
6464 | } | |
6465 | ||
6466 | goto unknown; | |
6467 | ||
6468 | default: | |
6469 | goto unknown; | |
6470 | } | |
6471 | ||
6472 | default: | |
6473 | goto unknown; | |
6474 | } | |
6475 | ||
6476 | case 's': | |
6477 | switch (name[1]) | |
6478 | { | |
6479 | case 'e': | |
6480 | switch (name[2]) | |
6481 | { | |
6482 | case 'e': | |
6483 | if (name[3] == 'k') | |
6484 | { /* seek */ | |
6485 | return -KEY_seek; | |
6486 | } | |
6487 | ||
6488 | goto unknown; | |
6489 | ||
6490 | case 'n': | |
6491 | if (name[3] == 'd') | |
6492 | { /* send */ | |
6493 | return -KEY_send; | |
6494 | } | |
6495 | ||
6496 | goto unknown; | |
6497 | ||
6498 | default: | |
6499 | goto unknown; | |
6500 | } | |
6501 | ||
6502 | case 'o': | |
6503 | if (name[2] == 'r' && | |
6504 | name[3] == 't') | |
6505 | { /* sort */ | |
6506 | return KEY_sort; | |
6507 | } | |
6508 | ||
6509 | goto unknown; | |
6510 | ||
6511 | case 'q': | |
6512 | if (name[2] == 'r' && | |
6513 | name[3] == 't') | |
6514 | { /* sqrt */ | |
6515 | return -KEY_sqrt; | |
6516 | } | |
6517 | ||
6518 | goto unknown; | |
6519 | ||
6520 | case 't': | |
6521 | if (name[2] == 'a' && | |
6522 | name[3] == 't') | |
6523 | { /* stat */ | |
6524 | return -KEY_stat; | |
6525 | } | |
6526 | ||
6527 | goto unknown; | |
6528 | ||
6529 | default: | |
6530 | goto unknown; | |
6531 | } | |
6532 | ||
6533 | case 't': | |
6534 | switch (name[1]) | |
6535 | { | |
6536 | case 'e': | |
6537 | if (name[2] == 'l' && | |
6538 | name[3] == 'l') | |
6539 | { /* tell */ | |
6540 | return -KEY_tell; | |
6541 | } | |
6542 | ||
6543 | goto unknown; | |
6544 | ||
6545 | case 'i': | |
6546 | switch (name[2]) | |
6547 | { | |
6548 | case 'e': | |
6549 | if (name[3] == 'd') | |
6550 | { /* tied */ | |
6551 | return KEY_tied; | |
6552 | } | |
6553 | ||
6554 | goto unknown; | |
6555 | ||
6556 | case 'm': | |
6557 | if (name[3] == 'e') | |
6558 | { /* time */ | |
6559 | return -KEY_time; | |
6560 | } | |
6561 | ||
6562 | goto unknown; | |
6563 | ||
6564 | default: | |
6565 | goto unknown; | |
6566 | } | |
6567 | ||
6568 | default: | |
6569 | goto unknown; | |
6570 | } | |
6571 | ||
6572 | case 'w': | |
6573 | if (name[1] == 'a') | |
6574 | { | |
6575 | switch (name[2]) | |
6576 | { | |
6577 | case 'i': | |
6578 | if (name[3] == 't') | |
6579 | { /* wait */ | |
6580 | return -KEY_wait; | |
6581 | } | |
6582 | ||
6583 | goto unknown; | |
6584 | ||
6585 | case 'r': | |
6586 | if (name[3] == 'n') | |
6587 | { /* warn */ | |
6588 | return -KEY_warn; | |
6589 | } | |
6590 | ||
6591 | goto unknown; | |
6592 | ||
6593 | default: | |
6594 | goto unknown; | |
6595 | } | |
6596 | } | |
6597 | ||
6598 | goto unknown; | |
6599 | ||
6600 | default: | |
6601 | goto unknown; | |
e2e1dd5a | 6602 | } |
4c3bbe0f MHM |
6603 | |
6604 | case 5: /* 36 tokens of length 5 */ | |
6605 | switch (name[0]) | |
e2e1dd5a | 6606 | { |
4c3bbe0f MHM |
6607 | case 'B': |
6608 | if (name[1] == 'E' && | |
6609 | name[2] == 'G' && | |
6610 | name[3] == 'I' && | |
6611 | name[4] == 'N') | |
6612 | { /* BEGIN */ | |
6613 | return KEY_BEGIN; | |
6614 | } | |
6615 | ||
6616 | goto unknown; | |
6617 | ||
6618 | case 'C': | |
6619 | if (name[1] == 'H' && | |
6620 | name[2] == 'E' && | |
6621 | name[3] == 'C' && | |
6622 | name[4] == 'K') | |
6623 | { /* CHECK */ | |
6624 | return KEY_CHECK; | |
6625 | } | |
6626 | ||
6627 | goto unknown; | |
6628 | ||
6629 | case 'a': | |
6630 | switch (name[1]) | |
6631 | { | |
6632 | case 'l': | |
6633 | if (name[2] == 'a' && | |
6634 | name[3] == 'r' && | |
6635 | name[4] == 'm') | |
6636 | { /* alarm */ | |
6637 | return -KEY_alarm; | |
6638 | } | |
6639 | ||
6640 | goto unknown; | |
6641 | ||
6642 | case 't': | |
6643 | if (name[2] == 'a' && | |
6644 | name[3] == 'n' && | |
6645 | name[4] == '2') | |
6646 | { /* atan2 */ | |
6647 | return -KEY_atan2; | |
6648 | } | |
6649 | ||
6650 | goto unknown; | |
6651 | ||
6652 | default: | |
6653 | goto unknown; | |
6654 | } | |
6655 | ||
6656 | case 'b': | |
6657 | if (name[1] == 'l' && | |
6658 | name[2] == 'e' && | |
6659 | name[3] == 's' && | |
6660 | name[4] == 's') | |
6661 | { /* bless */ | |
6662 | return -KEY_bless; | |
6663 | } | |
6664 | ||
6665 | goto unknown; | |
6666 | ||
6667 | case 'c': | |
6668 | switch (name[1]) | |
6669 | { | |
6670 | case 'h': | |
6671 | switch (name[2]) | |
6672 | { | |
6673 | case 'd': | |
6674 | if (name[3] == 'i' && | |
6675 | name[4] == 'r') | |
6676 | { /* chdir */ | |
6677 | return -KEY_chdir; | |
6678 | } | |
6679 | ||
6680 | goto unknown; | |
6681 | ||
6682 | case 'm': | |
6683 | if (name[3] == 'o' && | |
6684 | name[4] == 'd') | |
6685 | { /* chmod */ | |
6686 | return -KEY_chmod; | |
6687 | } | |
6688 | ||
6689 | goto unknown; | |
6690 | ||
6691 | case 'o': | |
6692 | switch (name[3]) | |
6693 | { | |
6694 | case 'm': | |
6695 | if (name[4] == 'p') | |
6696 | { /* chomp */ | |
6697 | return -KEY_chomp; | |
6698 | } | |
6699 | ||
6700 | goto unknown; | |
6701 | ||
6702 | case 'w': | |
6703 | if (name[4] == 'n') | |
6704 | { /* chown */ | |
6705 | return -KEY_chown; | |
6706 | } | |
6707 | ||
6708 | goto unknown; | |
6709 | ||
6710 | default: | |
6711 | goto unknown; | |
6712 | } | |
6713 | ||
6714 | default: | |
6715 | goto unknown; | |
6716 | } | |
6717 | ||
6718 | case 'l': | |
6719 | if (name[2] == 'o' && | |
6720 | name[3] == 's' && | |
6721 | name[4] == 'e') | |
6722 | { /* close */ | |
6723 | return -KEY_close; | |
6724 | } | |
6725 | ||
6726 | goto unknown; | |
6727 | ||
6728 | case 'r': | |
6729 | if (name[2] == 'y' && | |
6730 | name[3] == 'p' && | |
6731 | name[4] == 't') | |
6732 | { /* crypt */ | |
6733 | return -KEY_crypt; | |
6734 | } | |
6735 | ||
6736 | goto unknown; | |
6737 | ||
6738 | default: | |
6739 | goto unknown; | |
6740 | } | |
6741 | ||
6742 | case 'e': | |
6743 | if (name[1] == 'l' && | |
6744 | name[2] == 's' && | |
6745 | name[3] == 'i' && | |
6746 | name[4] == 'f') | |
6747 | { /* elsif */ | |
6748 | return KEY_elsif; | |
6749 | } | |
6750 | ||
6751 | goto unknown; | |
6752 | ||
6753 | case 'f': | |
6754 | switch (name[1]) | |
6755 | { | |
6756 | case 'c': | |
6757 | if (name[2] == 'n' && | |
6758 | name[3] == 't' && | |
6759 | name[4] == 'l') | |
6760 | { /* fcntl */ | |
6761 | return -KEY_fcntl; | |
6762 | } | |
6763 | ||
6764 | goto unknown; | |
6765 | ||
6766 | case 'l': | |
6767 | if (name[2] == 'o' && | |
6768 | name[3] == 'c' && | |
6769 | name[4] == 'k') | |
6770 | { /* flock */ | |
6771 | return -KEY_flock; | |
6772 | } | |
6773 | ||
6774 | goto unknown; | |
6775 | ||
6776 | default: | |
6777 | goto unknown; | |
6778 | } | |
6779 | ||
6780 | case 'i': | |
6781 | switch (name[1]) | |
6782 | { | |
6783 | case 'n': | |
6784 | if (name[2] == 'd' && | |
6785 | name[3] == 'e' && | |
6786 | name[4] == 'x') | |
6787 | { /* index */ | |
6788 | return -KEY_index; | |
6789 | } | |
6790 | ||
6791 | goto unknown; | |
6792 | ||
6793 | case 'o': | |
6794 | if (name[2] == 'c' && | |
6795 | name[3] == 't' && | |
6796 | name[4] == 'l') | |
6797 | { /* ioctl */ | |
6798 | return -KEY_ioctl; | |
6799 | } | |
6800 | ||
6801 | goto unknown; | |
6802 | ||
6803 | default: | |
6804 | goto unknown; | |
6805 | } | |
6806 | ||
6807 | case 'l': | |
6808 | switch (name[1]) | |
6809 | { | |
6810 | case 'o': | |
6811 | if (name[2] == 'c' && | |
6812 | name[3] == 'a' && | |
6813 | name[4] == 'l') | |
6814 | { /* local */ | |
6815 | return KEY_local; | |
6816 | } | |
6817 | ||
6818 | goto unknown; | |
6819 | ||
6820 | case 's': | |
6821 | if (name[2] == 't' && | |
6822 | name[3] == 'a' && | |
6823 | name[4] == 't') | |
6824 | { /* lstat */ | |
6825 | return -KEY_lstat; | |
6826 | } | |
6827 | ||
6828 | goto unknown; | |
6829 | ||
6830 | default: | |
6831 | goto unknown; | |
6832 | } | |
6833 | ||
6834 | case 'm': | |
6835 | if (name[1] == 'k' && | |
6836 | name[2] == 'd' && | |
6837 | name[3] == 'i' && | |
6838 | name[4] == 'r') | |
6839 | { /* mkdir */ | |
6840 | return -KEY_mkdir; | |
6841 | } | |
6842 | ||
6843 | goto unknown; | |
6844 | ||
6845 | case 'p': | |
6846 | if (name[1] == 'r' && | |
6847 | name[2] == 'i' && | |
6848 | name[3] == 'n' && | |
6849 | name[4] == 't') | |
6850 | { /* print */ | |
6851 | return KEY_print; | |
6852 | } | |
6853 | ||
6854 | goto unknown; | |
6855 | ||
6856 | case 'r': | |
6857 | switch (name[1]) | |
6858 | { | |
6859 | case 'e': | |
6860 | if (name[2] == 's' && | |
6861 | name[3] == 'e' && | |
6862 | name[4] == 't') | |
6863 | { /* reset */ | |
6864 | return -KEY_reset; | |
6865 | } | |
6866 | ||
6867 | goto unknown; | |
6868 | ||
6869 | case 'm': | |
6870 | if (name[2] == 'd' && | |
6871 | name[3] == 'i' && | |
6872 | name[4] == 'r') | |
6873 | { /* rmdir */ | |
6874 | return -KEY_rmdir; | |
6875 | } | |
6876 | ||
6877 | goto unknown; | |
6878 | ||
6879 | default: | |
6880 | goto unknown; | |
6881 | } | |
6882 | ||
6883 | case 's': | |
6884 | switch (name[1]) | |
6885 | { | |
6886 | case 'e': | |
6887 | if (name[2] == 'm' && | |
6888 | name[3] == 'o' && | |
6889 | name[4] == 'p') | |
6890 | { /* semop */ | |
6891 | return -KEY_semop; | |
6892 | } | |
6893 | ||
6894 | goto unknown; | |
6895 | ||
6896 | case 'h': | |
6897 | if (name[2] == 'i' && | |
6898 | name[3] == 'f' && | |
6899 | name[4] == 't') | |
6900 | { /* shift */ | |
6901 | return -KEY_shift; | |
6902 | } | |
6903 | ||
6904 | goto unknown; | |
6905 | ||
6906 | case 'l': | |
6907 | if (name[2] == 'e' && | |
6908 | name[3] == 'e' && | |
6909 | name[4] == 'p') | |
6910 | { /* sleep */ | |
6911 | return -KEY_sleep; | |
6912 | } | |
6913 | ||
6914 | goto unknown; | |
6915 | ||
6916 | case 'p': | |
6917 | if (name[2] == 'l' && | |
6918 | name[3] == 'i' && | |
6919 | name[4] == 't') | |
6920 | { /* split */ | |
6921 | return KEY_split; | |
6922 | } | |
6923 | ||
6924 | goto unknown; | |
6925 | ||
6926 | case 'r': | |
6927 | if (name[2] == 'a' && | |
6928 | name[3] == 'n' && | |
6929 | name[4] == 'd') | |
6930 | { /* srand */ | |
6931 | return -KEY_srand; | |
6932 | } | |
6933 | ||
6934 | goto unknown; | |
6935 | ||
6936 | case 't': | |
6937 | if (name[2] == 'u' && | |
6938 | name[3] == 'd' && | |
6939 | name[4] == 'y') | |
6940 | { /* study */ | |
6941 | return KEY_study; | |
6942 | } | |
6943 | ||
6944 | goto unknown; | |
6945 | ||
6946 | default: | |
6947 | goto unknown; | |
6948 | } | |
6949 | ||
6950 | case 't': | |
6951 | if (name[1] == 'i' && | |
6952 | name[2] == 'm' && | |
6953 | name[3] == 'e' && | |
6954 | name[4] == 's') | |
6955 | { /* times */ | |
6956 | return -KEY_times; | |
6957 | } | |
6958 | ||
6959 | goto unknown; | |
6960 | ||
6961 | case 'u': | |
6962 | switch (name[1]) | |
6963 | { | |
6964 | case 'm': | |
6965 | if (name[2] == 'a' && | |
6966 | name[3] == 's' && | |
6967 | name[4] == 'k') | |
6968 | { /* umask */ | |
6969 | return -KEY_umask; | |
6970 | } | |
6971 | ||
6972 | goto unknown; | |
6973 | ||
6974 | case 'n': | |
6975 | switch (name[2]) | |
6976 | { | |
6977 | case 'd': | |
6978 | if (name[3] == 'e' && | |
6979 | name[4] == 'f') | |
6980 | { /* undef */ | |
6981 | return KEY_undef; | |
6982 | } | |
6983 | ||
6984 | goto unknown; | |
6985 | ||
6986 | case 't': | |
6987 | if (name[3] == 'i') | |
6988 | { | |
6989 | switch (name[4]) | |
6990 | { | |
6991 | case 'e': | |
6992 | { /* untie */ | |
6993 | return KEY_untie; | |
6994 | } | |
6995 | ||
4c3bbe0f MHM |
6996 | case 'l': |
6997 | { /* until */ | |
6998 | return KEY_until; | |
6999 | } | |
7000 | ||
4c3bbe0f MHM |
7001 | default: |
7002 | goto unknown; | |
7003 | } | |
7004 | } | |
7005 | ||
7006 | goto unknown; | |
7007 | ||
7008 | default: | |
7009 | goto unknown; | |
7010 | } | |
7011 | ||
7012 | case 't': | |
7013 | if (name[2] == 'i' && | |
7014 | name[3] == 'm' && | |
7015 | name[4] == 'e') | |
7016 | { /* utime */ | |
7017 | return -KEY_utime; | |
7018 | } | |
7019 | ||
7020 | goto unknown; | |
7021 | ||
7022 | default: | |
7023 | goto unknown; | |
7024 | } | |
7025 | ||
7026 | case 'w': | |
7027 | switch (name[1]) | |
7028 | { | |
7029 | case 'h': | |
7030 | if (name[2] == 'i' && | |
7031 | name[3] == 'l' && | |
7032 | name[4] == 'e') | |
7033 | { /* while */ | |
7034 | return KEY_while; | |
7035 | } | |
7036 | ||
7037 | goto unknown; | |
7038 | ||
7039 | case 'r': | |
7040 | if (name[2] == 'i' && | |
7041 | name[3] == 't' && | |
7042 | name[4] == 'e') | |
7043 | { /* write */ | |
7044 | return -KEY_write; | |
7045 | } | |
7046 | ||
7047 | goto unknown; | |
7048 | ||
7049 | default: | |
7050 | goto unknown; | |
7051 | } | |
7052 | ||
7053 | default: | |
7054 | goto unknown; | |
e2e1dd5a | 7055 | } |
4c3bbe0f MHM |
7056 | |
7057 | case 6: /* 33 tokens of length 6 */ | |
7058 | switch (name[0]) | |
7059 | { | |
7060 | case 'a': | |
7061 | if (name[1] == 'c' && | |
7062 | name[2] == 'c' && | |
7063 | name[3] == 'e' && | |
7064 | name[4] == 'p' && | |
7065 | name[5] == 't') | |
7066 | { /* accept */ | |
7067 | return -KEY_accept; | |
7068 | } | |
7069 | ||
7070 | goto unknown; | |
7071 | ||
7072 | case 'c': | |
7073 | switch (name[1]) | |
7074 | { | |
7075 | case 'a': | |
7076 | if (name[2] == 'l' && | |
7077 | name[3] == 'l' && | |
7078 | name[4] == 'e' && | |
7079 | name[5] == 'r') | |
7080 | { /* caller */ | |
7081 | return -KEY_caller; | |
7082 | } | |
7083 | ||
7084 | goto unknown; | |
7085 | ||
7086 | case 'h': | |
7087 | if (name[2] == 'r' && | |
7088 | name[3] == 'o' && | |
7089 | name[4] == 'o' && | |
7090 | name[5] == 't') | |
7091 | { /* chroot */ | |
7092 | return -KEY_chroot; | |
7093 | } | |
7094 | ||
7095 | goto unknown; | |
7096 | ||
7097 | default: | |
7098 | goto unknown; | |
7099 | } | |
7100 | ||
7101 | case 'd': | |
7102 | if (name[1] == 'e' && | |
7103 | name[2] == 'l' && | |
7104 | name[3] == 'e' && | |
7105 | name[4] == 't' && | |
7106 | name[5] == 'e') | |
7107 | { /* delete */ | |
7108 | return KEY_delete; | |
7109 | } | |
7110 | ||
7111 | goto unknown; | |
7112 | ||
7113 | case 'e': | |
7114 | switch (name[1]) | |
7115 | { | |
7116 | case 'l': | |
7117 | if (name[2] == 's' && | |
7118 | name[3] == 'e' && | |
7119 | name[4] == 'i' && | |
7120 | name[5] == 'f') | |
7121 | { /* elseif */ | |
7122 | if(ckWARN_d(WARN_SYNTAX)) | |
7123 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif"); | |
7124 | } | |
7125 | ||
7126 | goto unknown; | |
7127 | ||
7128 | case 'x': | |
7129 | if (name[2] == 'i' && | |
7130 | name[3] == 's' && | |
7131 | name[4] == 't' && | |
7132 | name[5] == 's') | |
7133 | { /* exists */ | |
7134 | return KEY_exists; | |
7135 | } | |
7136 | ||
7137 | goto unknown; | |
7138 | ||
7139 | default: | |
7140 | goto unknown; | |
7141 | } | |
7142 | ||
7143 | case 'f': | |
7144 | switch (name[1]) | |
7145 | { | |
7146 | case 'i': | |
7147 | if (name[2] == 'l' && | |
7148 | name[3] == 'e' && | |
7149 | name[4] == 'n' && | |
7150 | name[5] == 'o') | |
7151 | { /* fileno */ | |
7152 | return -KEY_fileno; | |
7153 | } | |
7154 | ||
7155 | goto unknown; | |
7156 | ||
7157 | case 'o': | |
7158 | if (name[2] == 'r' && | |
7159 | name[3] == 'm' && | |
7160 | name[4] == 'a' && | |
7161 | name[5] == 't') | |
7162 | { /* format */ | |
7163 | return KEY_format; | |
7164 | } | |
7165 | ||
7166 | goto unknown; | |
7167 | ||
7168 | default: | |
7169 | goto unknown; | |
7170 | } | |
7171 | ||
7172 | case 'g': | |
7173 | if (name[1] == 'm' && | |
7174 | name[2] == 't' && | |
7175 | name[3] == 'i' && | |
7176 | name[4] == 'm' && | |
7177 | name[5] == 'e') | |
7178 | { /* gmtime */ | |
7179 | return -KEY_gmtime; | |
7180 | } | |
7181 | ||
7182 | goto unknown; | |
7183 | ||
7184 | case 'l': | |
7185 | switch (name[1]) | |
7186 | { | |
7187 | case 'e': | |
7188 | if (name[2] == 'n' && | |
7189 | name[3] == 'g' && | |
7190 | name[4] == 't' && | |
7191 | name[5] == 'h') | |
7192 | { /* length */ | |
7193 | return -KEY_length; | |
7194 | } | |
7195 | ||
7196 | goto unknown; | |
7197 | ||
7198 | case 'i': | |
7199 | if (name[2] == 's' && | |
7200 | name[3] == 't' && | |
7201 | name[4] == 'e' && | |
7202 | name[5] == 'n') | |
7203 | { /* listen */ | |
7204 | return -KEY_listen; | |
7205 | } | |
7206 | ||
7207 | goto unknown; | |
7208 | ||
7209 | default: | |
7210 | goto unknown; | |
7211 | } | |
7212 | ||
7213 | case 'm': | |
7214 | if (name[1] == 's' && | |
7215 | name[2] == 'g') | |
7216 | { | |
7217 | switch (name[3]) | |
7218 | { | |
7219 | case 'c': | |
7220 | if (name[4] == 't' && | |
7221 | name[5] == 'l') | |
7222 | { /* msgctl */ | |
7223 | return -KEY_msgctl; | |
7224 | } | |
7225 | ||
7226 | goto unknown; | |
7227 | ||
7228 | case 'g': | |
7229 | if (name[4] == 'e' && | |
7230 | name[5] == 't') | |
7231 | { /* msgget */ | |
7232 | return -KEY_msgget; | |
7233 | } | |
7234 | ||
7235 | goto unknown; | |
7236 | ||
7237 | case 'r': | |
7238 | if (name[4] == 'c' && | |
7239 | name[5] == 'v') | |
7240 | { /* msgrcv */ | |
7241 | return -KEY_msgrcv; | |
7242 | } | |
7243 | ||
7244 | goto unknown; | |
7245 | ||
7246 | case 's': | |
7247 | if (name[4] == 'n' && | |
7248 | name[5] == 'd') | |
7249 | { /* msgsnd */ | |
7250 | return -KEY_msgsnd; | |
7251 | } | |
7252 | ||
7253 | goto unknown; | |
7254 | ||
7255 | default: | |
7256 | goto unknown; | |
7257 | } | |
7258 | } | |
7259 | ||
7260 | goto unknown; | |
7261 | ||
7262 | case 'p': | |
7263 | if (name[1] == 'r' && | |
7264 | name[2] == 'i' && | |
7265 | name[3] == 'n' && | |
7266 | name[4] == 't' && | |
7267 | name[5] == 'f') | |
7268 | { /* printf */ | |
7269 | return KEY_printf; | |
7270 | } | |
7271 | ||
7272 | goto unknown; | |
7273 | ||
7274 | case 'r': | |
7275 | switch (name[1]) | |
7276 | { | |
7277 | case 'e': | |
7278 | switch (name[2]) | |
7279 | { | |
7280 | case 'n': | |
7281 | if (name[3] == 'a' && | |
7282 | name[4] == 'm' && | |
7283 | name[5] == 'e') | |
7284 | { /* rename */ | |
7285 | return -KEY_rename; | |
7286 | } | |
7287 | ||
7288 | goto unknown; | |
7289 | ||
7290 | case 't': | |
7291 | if (name[3] == 'u' && | |
7292 | name[4] == 'r' && | |
7293 | name[5] == 'n') | |
7294 | { /* return */ | |
7295 | return KEY_return; | |
7296 | } | |
7297 | ||
7298 | goto unknown; | |
7299 | ||
7300 | default: | |
7301 | goto unknown; | |
7302 | } | |
7303 | ||
7304 | case 'i': | |
7305 | if (name[2] == 'n' && | |
7306 | name[3] == 'd' && | |
7307 | name[4] == 'e' && | |
7308 | name[5] == 'x') | |
7309 | { /* rindex */ | |
7310 | return -KEY_rindex; | |
7311 | } | |
7312 | ||
7313 | goto unknown; | |
7314 | ||
7315 | default: | |
7316 | goto unknown; | |
7317 | } | |
7318 | ||
7319 | case 's': | |
7320 | switch (name[1]) | |
7321 | { | |
7322 | case 'c': | |
7323 | if (name[2] == 'a' && | |
7324 | name[3] == 'l' && | |
7325 | name[4] == 'a' && | |
7326 | name[5] == 'r') | |
7327 | { /* scalar */ | |
7328 | return KEY_scalar; | |
7329 | } | |
7330 | ||
7331 | goto unknown; | |
7332 | ||
7333 | case 'e': | |
7334 | switch (name[2]) | |
7335 | { | |
7336 | case 'l': | |
7337 | if (name[3] == 'e' && | |
7338 | name[4] == 'c' && | |
7339 | name[5] == 't') | |
7340 | { /* select */ | |
7341 | return -KEY_select; | |
7342 | } | |
7343 | ||
7344 | goto unknown; | |
7345 | ||
7346 | case 'm': | |
7347 | switch (name[3]) | |
7348 | { | |
7349 | case 'c': | |
7350 | if (name[4] == 't' && | |
7351 | name[5] == 'l') | |
7352 | { /* semctl */ | |
7353 | return -KEY_semctl; | |
7354 | } | |
7355 | ||
7356 | goto unknown; | |
7357 | ||
7358 | case 'g': | |
7359 | if (name[4] == 'e' && | |
7360 | name[5] == 't') | |
7361 | { /* semget */ | |
7362 | return -KEY_semget; | |
7363 | } | |
7364 | ||
7365 | goto unknown; | |
7366 | ||
7367 | default: | |
7368 | goto unknown; | |
7369 | } | |
7370 | ||
7371 | default: | |
7372 | goto unknown; | |
7373 | } | |
7374 | ||
7375 | case 'h': | |
7376 | if (name[2] == 'm') | |
7377 | { | |
7378 | switch (name[3]) | |
7379 | { | |
7380 | case 'c': | |
7381 | if (name[4] == 't' && | |
7382 | name[5] == 'l') | |
7383 | { /* shmctl */ | |
7384 | return -KEY_shmctl; | |
7385 | } | |
7386 | ||
7387 | goto unknown; | |
7388 | ||
7389 | case 'g': | |
7390 | if (name[4] == 'e' && | |
7391 | name[5] == 't') | |
7392 | { /* shmget */ | |
7393 | return -KEY_shmget; | |
7394 | } | |
7395 | ||
7396 | goto unknown; | |
7397 | ||
7398 | default: | |
7399 | goto unknown; | |
7400 | } | |
7401 | } | |
7402 | ||
7403 | goto unknown; | |
7404 | ||
7405 | case 'o': | |
7406 | if (name[2] == 'c' && | |
7407 | name[3] == 'k' && | |
7408 | name[4] == 'e' && | |
7409 | name[5] == 't') | |
7410 | { /* socket */ | |
7411 | return -KEY_socket; | |
7412 | } | |
7413 | ||
7414 | goto unknown; | |
7415 | ||
7416 | case 'p': | |
7417 | if (name[2] == 'l' && | |
7418 | name[3] == 'i' && | |
7419 | name[4] == 'c' && | |
7420 | name[5] == 'e') | |
7421 | { /* splice */ | |
7422 | return -KEY_splice; | |
7423 | } | |
7424 | ||
7425 | goto unknown; | |
7426 | ||
7427 | case 'u': | |
7428 | if (name[2] == 'b' && | |
7429 | name[3] == 's' && | |
7430 | name[4] == 't' && | |
7431 | name[5] == 'r') | |
7432 | { /* substr */ | |
7433 | return -KEY_substr; | |
7434 | } | |
7435 | ||
7436 | goto unknown; | |
7437 | ||
7438 | case 'y': | |
7439 | if (name[2] == 's' && | |
7440 | name[3] == 't' && | |
7441 | name[4] == 'e' && | |
7442 | name[5] == 'm') | |
7443 | { /* system */ | |
7444 | return -KEY_system; | |
7445 | } | |
7446 | ||
7447 | goto unknown; | |
7448 | ||
7449 | default: | |
7450 | goto unknown; | |
7451 | } | |
7452 | ||
7453 | case 'u': | |
7454 | if (name[1] == 'n') | |
7455 | { | |
7456 | switch (name[2]) | |
7457 | { | |
7458 | case 'l': | |
7459 | switch (name[3]) | |
7460 | { | |
7461 | case 'e': | |
7462 | if (name[4] == 's' && | |
7463 | name[5] == 's') | |
7464 | { /* unless */ | |
7465 | return KEY_unless; | |
7466 | } | |
7467 | ||
7468 | goto unknown; | |
7469 | ||
7470 | case 'i': | |
7471 | if (name[4] == 'n' && | |
7472 | name[5] == 'k') | |
7473 | { /* unlink */ | |
7474 | return -KEY_unlink; | |
7475 | } | |
7476 | ||
7477 | goto unknown; | |
7478 | ||
7479 | default: | |
7480 | goto unknown; | |
7481 | } | |
7482 | ||
7483 | case 'p': | |
7484 | if (name[3] == 'a' && | |
7485 | name[4] == 'c' && | |
7486 | name[5] == 'k') | |
7487 | { /* unpack */ | |
7488 | return -KEY_unpack; | |
7489 | } | |
7490 | ||
7491 | goto unknown; | |
7492 | ||
7493 | default: | |
7494 | goto unknown; | |
7495 | } | |
7496 | } | |
7497 | ||
7498 | goto unknown; | |
7499 | ||
7500 | case 'v': | |
7501 | if (name[1] == 'a' && | |
7502 | name[2] == 'l' && | |
7503 | name[3] == 'u' && | |
7504 | name[4] == 'e' && | |
7505 | name[5] == 's') | |
7506 | { /* values */ | |
7507 | return -KEY_values; | |
7508 | } | |
7509 | ||
7510 | goto unknown; | |
7511 | ||
7512 | default: | |
7513 | goto unknown; | |
e2e1dd5a | 7514 | } |
4c3bbe0f MHM |
7515 | |
7516 | case 7: /* 28 tokens of length 7 */ | |
7517 | switch (name[0]) | |
7518 | { | |
7519 | case 'D': | |
7520 | if (name[1] == 'E' && | |
7521 | name[2] == 'S' && | |
7522 | name[3] == 'T' && | |
7523 | name[4] == 'R' && | |
7524 | name[5] == 'O' && | |
7525 | name[6] == 'Y') | |
7526 | { /* DESTROY */ | |
7527 | return KEY_DESTROY; | |
7528 | } | |
7529 | ||
7530 | goto unknown; | |
7531 | ||
7532 | case '_': | |
7533 | if (name[1] == '_' && | |
7534 | name[2] == 'E' && | |
7535 | name[3] == 'N' && | |
7536 | name[4] == 'D' && | |
7537 | name[5] == '_' && | |
7538 | name[6] == '_') | |
7539 | { /* __END__ */ | |
7540 | return KEY___END__; | |
7541 | } | |
7542 | ||
7543 | goto unknown; | |
7544 | ||
7545 | case 'b': | |
7546 | if (name[1] == 'i' && | |
7547 | name[2] == 'n' && | |
7548 | name[3] == 'm' && | |
7549 | name[4] == 'o' && | |
7550 | name[5] == 'd' && | |
7551 | name[6] == 'e') | |
7552 | { /* binmode */ | |
7553 | return -KEY_binmode; | |
7554 | } | |
7555 | ||
7556 | goto unknown; | |
7557 | ||
7558 | case 'c': | |
7559 | if (name[1] == 'o' && | |
7560 | name[2] == 'n' && | |
7561 | name[3] == 'n' && | |
7562 | name[4] == 'e' && | |
7563 | name[5] == 'c' && | |
7564 | name[6] == 't') | |
7565 | { /* connect */ | |
7566 | return -KEY_connect; | |
7567 | } | |
7568 | ||
7569 | goto unknown; | |
7570 | ||
7571 | case 'd': | |
7572 | switch (name[1]) | |
7573 | { | |
7574 | case 'b': | |
7575 | if (name[2] == 'm' && | |
7576 | name[3] == 'o' && | |
7577 | name[4] == 'p' && | |
7578 | name[5] == 'e' && | |
7579 | name[6] == 'n') | |
7580 | { /* dbmopen */ | |
7581 | return -KEY_dbmopen; | |
7582 | } | |
7583 | ||
7584 | goto unknown; | |
7585 | ||
7586 | case 'e': | |
7587 | if (name[2] == 'f' && | |
7588 | name[3] == 'i' && | |
7589 | name[4] == 'n' && | |
7590 | name[5] == 'e' && | |
7591 | name[6] == 'd') | |
7592 | { /* defined */ | |
7593 | return KEY_defined; | |
7594 | } | |
7595 | ||
7596 | goto unknown; | |
7597 | ||
7598 | default: | |
7599 | goto unknown; | |
7600 | } | |
7601 | ||
7602 | case 'f': | |
7603 | if (name[1] == 'o' && | |
7604 | name[2] == 'r' && | |
7605 | name[3] == 'e' && | |
7606 | name[4] == 'a' && | |
7607 | name[5] == 'c' && | |
7608 | name[6] == 'h') | |
7609 | { /* foreach */ | |
7610 | return KEY_foreach; | |
7611 | } | |
7612 | ||
7613 | goto unknown; | |
7614 | ||
7615 | case 'g': | |
7616 | if (name[1] == 'e' && | |
7617 | name[2] == 't' && | |
7618 | name[3] == 'p') | |
7619 | { | |
7620 | switch (name[4]) | |
7621 | { | |
7622 | case 'g': | |
7623 | if (name[5] == 'r' && | |
7624 | name[6] == 'p') | |
7625 | { /* getpgrp */ | |
7626 | return -KEY_getpgrp; | |
7627 | } | |
7628 | ||
7629 | goto unknown; | |
7630 | ||
7631 | case 'p': | |
7632 | if (name[5] == 'i' && | |
7633 | name[6] == 'd') | |
7634 | { /* getppid */ | |
7635 | return -KEY_getppid; | |
7636 | } | |
7637 | ||
7638 | goto unknown; | |
7639 | ||
7640 | default: | |
7641 | goto unknown; | |
7642 | } | |
7643 | } | |
7644 | ||
7645 | goto unknown; | |
7646 | ||
7647 | case 'l': | |
7648 | if (name[1] == 'c' && | |
7649 | name[2] == 'f' && | |
7650 | name[3] == 'i' && | |
7651 | name[4] == 'r' && | |
7652 | name[5] == 's' && | |
7653 | name[6] == 't') | |
7654 | { /* lcfirst */ | |
7655 | return -KEY_lcfirst; | |
7656 | } | |
7657 | ||
7658 | goto unknown; | |
7659 | ||
7660 | case 'o': | |
7661 | if (name[1] == 'p' && | |
7662 | name[2] == 'e' && | |
7663 | name[3] == 'n' && | |
7664 | name[4] == 'd' && | |
7665 | name[5] == 'i' && | |
7666 | name[6] == 'r') | |
7667 | { /* opendir */ | |
7668 | return -KEY_opendir; | |
7669 | } | |
7670 | ||
7671 | goto unknown; | |
7672 | ||
7673 | case 'p': | |
7674 | if (name[1] == 'a' && | |
7675 | name[2] == 'c' && | |
7676 | name[3] == 'k' && | |
7677 | name[4] == 'a' && | |
7678 | name[5] == 'g' && | |
7679 | name[6] == 'e') | |
7680 | { /* package */ | |
7681 | return KEY_package; | |
7682 | } | |
7683 | ||
7684 | goto unknown; | |
7685 | ||
7686 | case 'r': | |
7687 | if (name[1] == 'e') | |
7688 | { | |
7689 | switch (name[2]) | |
7690 | { | |
7691 | case 'a': | |
7692 | if (name[3] == 'd' && | |
7693 | name[4] == 'd' && | |
7694 | name[5] == 'i' && | |
7695 | name[6] == 'r') | |
7696 | { /* readdir */ | |
7697 | return -KEY_readdir; | |
7698 | } | |
7699 | ||
7700 | goto unknown; | |
7701 | ||
7702 | case 'q': | |
7703 | if (name[3] == 'u' && | |
7704 | name[4] == 'i' && | |
7705 | name[5] == 'r' && | |
7706 | name[6] == 'e') | |
7707 | { /* require */ | |
7708 | return KEY_require; | |
7709 | } | |
7710 | ||
7711 | goto unknown; | |
7712 | ||
7713 | case 'v': | |
7714 | if (name[3] == 'e' && | |
7715 | name[4] == 'r' && | |
7716 | name[5] == 's' && | |
7717 | name[6] == 'e') | |
7718 | { /* reverse */ | |
7719 | return -KEY_reverse; | |
7720 | } | |
7721 | ||
7722 | goto unknown; | |
7723 | ||
7724 | default: | |
7725 | goto unknown; | |
7726 | } | |
7727 | } | |
7728 | ||
7729 | goto unknown; | |
7730 | ||
7731 | case 's': | |
7732 | switch (name[1]) | |
7733 | { | |
7734 | case 'e': | |
7735 | switch (name[2]) | |
7736 | { | |
7737 | case 'e': | |
7738 | if (name[3] == 'k' && | |
7739 | name[4] == 'd' && | |
7740 | name[5] == 'i' && | |
7741 | name[6] == 'r') | |
7742 | { /* seekdir */ | |
7743 | return -KEY_seekdir; | |
7744 | } | |
7745 | ||
7746 | goto unknown; | |
7747 | ||
7748 | case 't': | |
7749 | if (name[3] == 'p' && | |
7750 | name[4] == 'g' && | |
7751 | name[5] == 'r' && | |
7752 | name[6] == 'p') | |
7753 | { /* setpgrp */ | |
7754 | return -KEY_setpgrp; | |
7755 | } | |
7756 | ||
7757 | goto unknown; | |
7758 | ||
7759 | default: | |
7760 | goto unknown; | |
7761 | } | |
7762 | ||
7763 | case 'h': | |
7764 | if (name[2] == 'm' && | |
7765 | name[3] == 'r' && | |
7766 | name[4] == 'e' && | |
7767 | name[5] == 'a' && | |
7768 | name[6] == 'd') | |
7769 | { /* shmread */ | |
7770 | return -KEY_shmread; | |
7771 | } | |
7772 | ||
7773 | goto unknown; | |
7774 | ||
7775 | case 'p': | |
7776 | if (name[2] == 'r' && | |
7777 | name[3] == 'i' && | |
7778 | name[4] == 'n' && | |
7779 | name[5] == 't' && | |
7780 | name[6] == 'f') | |
7781 | { /* sprintf */ | |
7782 | return -KEY_sprintf; | |
7783 | } | |
7784 | ||
7785 | goto unknown; | |
7786 | ||
7787 | case 'y': | |
7788 | switch (name[2]) | |
7789 | { | |
7790 | case 'm': | |
7791 | if (name[3] == 'l' && | |
7792 | name[4] == 'i' && | |
7793 | name[5] == 'n' && | |
7794 | name[6] == 'k') | |
7795 | { /* symlink */ | |
7796 | return -KEY_symlink; | |
7797 | } | |
7798 | ||
7799 | goto unknown; | |
7800 | ||
7801 | case 's': | |
7802 | switch (name[3]) | |
7803 | { | |
7804 | case 'c': | |
7805 | if (name[4] == 'a' && | |
7806 | name[5] == 'l' && | |
7807 | name[6] == 'l') | |
7808 | { /* syscall */ | |
7809 | return -KEY_syscall; | |
7810 | } | |
7811 | ||
7812 | goto unknown; | |
7813 | ||
7814 | case 'o': | |
7815 | if (name[4] == 'p' && | |
7816 | name[5] == 'e' && | |
7817 | name[6] == 'n') | |
7818 | { /* sysopen */ | |
7819 | return -KEY_sysopen; | |
7820 | } | |
7821 | ||
7822 | goto unknown; | |
7823 | ||
7824 | case 'r': | |
7825 | if (name[4] == 'e' && | |
7826 | name[5] == 'a' && | |
7827 | name[6] == 'd') | |
7828 | { /* sysread */ | |
7829 | return -KEY_sysread; | |
7830 | } | |
7831 | ||
7832 | goto unknown; | |
7833 | ||
7834 | case 's': | |
7835 | if (name[4] == 'e' && | |
7836 | name[5] == 'e' && | |
7837 | name[6] == 'k') | |
7838 | { /* sysseek */ | |
7839 | return -KEY_sysseek; | |
7840 | } | |
7841 | ||
7842 | goto unknown; | |
7843 | ||
7844 | default: | |
7845 | goto unknown; | |
7846 | } | |
7847 | ||
7848 | default: | |
7849 | goto unknown; | |
7850 | } | |
7851 | ||
7852 | default: | |
7853 | goto unknown; | |
7854 | } | |
7855 | ||
7856 | case 't': | |
7857 | if (name[1] == 'e' && | |
7858 | name[2] == 'l' && | |
7859 | name[3] == 'l' && | |
7860 | name[4] == 'd' && | |
7861 | name[5] == 'i' && | |
7862 | name[6] == 'r') | |
7863 | { /* telldir */ | |
7864 | return -KEY_telldir; | |
7865 | } | |
7866 | ||
7867 | goto unknown; | |
7868 | ||
7869 | case 'u': | |
7870 | switch (name[1]) | |
7871 | { | |
7872 | case 'c': | |
7873 | if (name[2] == 'f' && | |
7874 | name[3] == 'i' && | |
7875 | name[4] == 'r' && | |
7876 | name[5] == 's' && | |
7877 | name[6] == 't') | |
7878 | { /* ucfirst */ | |
7879 | return -KEY_ucfirst; | |
7880 | } | |
7881 | ||
7882 | goto unknown; | |
7883 | ||
7884 | case 'n': | |
7885 | if (name[2] == 's' && | |
7886 | name[3] == 'h' && | |
7887 | name[4] == 'i' && | |
7888 | name[5] == 'f' && | |
7889 | name[6] == 't') | |
7890 | { /* unshift */ | |
7891 | return -KEY_unshift; | |
7892 | } | |
7893 | ||
7894 | goto unknown; | |
7895 | ||
7896 | default: | |
7897 | goto unknown; | |
7898 | } | |
7899 | ||
7900 | case 'w': | |
7901 | if (name[1] == 'a' && | |
7902 | name[2] == 'i' && | |
7903 | name[3] == 't' && | |
7904 | name[4] == 'p' && | |
7905 | name[5] == 'i' && | |
7906 | name[6] == 'd') | |
7907 | { /* waitpid */ | |
7908 | return -KEY_waitpid; | |
7909 | } | |
7910 | ||
7911 | goto unknown; | |
7912 | ||
7913 | default: | |
7914 | goto unknown; | |
7915 | } | |
7916 | ||
7917 | case 8: /* 26 tokens of length 8 */ | |
7918 | switch (name[0]) | |
7919 | { | |
7920 | case 'A': | |
7921 | if (name[1] == 'U' && | |
7922 | name[2] == 'T' && | |
7923 | name[3] == 'O' && | |
7924 | name[4] == 'L' && | |
7925 | name[5] == 'O' && | |
7926 | name[6] == 'A' && | |
7927 | name[7] == 'D') | |
7928 | { /* AUTOLOAD */ | |
7929 | return KEY_AUTOLOAD; | |
7930 | } | |
7931 | ||
7932 | goto unknown; | |
7933 | ||
7934 | case '_': | |
7935 | if (name[1] == '_') | |
7936 | { | |
7937 | switch (name[2]) | |
7938 | { | |
7939 | case 'D': | |
7940 | if (name[3] == 'A' && | |
7941 | name[4] == 'T' && | |
7942 | name[5] == 'A' && | |
7943 | name[6] == '_' && | |
7944 | name[7] == '_') | |
7945 | { /* __DATA__ */ | |
7946 | return KEY___DATA__; | |
7947 | } | |
7948 | ||
7949 | goto unknown; | |
7950 | ||
7951 | case 'F': | |
7952 | if (name[3] == 'I' && | |
7953 | name[4] == 'L' && | |
7954 | name[5] == 'E' && | |
7955 | name[6] == '_' && | |
7956 | name[7] == '_') | |
7957 | { /* __FILE__ */ | |
7958 | return -KEY___FILE__; | |
7959 | } | |
7960 | ||
7961 | goto unknown; | |
7962 | ||
7963 | case 'L': | |
7964 | if (name[3] == 'I' && | |
7965 | name[4] == 'N' && | |
7966 | name[5] == 'E' && | |
7967 | name[6] == '_' && | |
7968 | name[7] == '_') | |
7969 | { /* __LINE__ */ | |
7970 | return -KEY___LINE__; | |
7971 | } | |
7972 | ||
7973 | goto unknown; | |
7974 | ||
7975 | default: | |
7976 | goto unknown; | |
7977 | } | |
7978 | } | |
7979 | ||
7980 | goto unknown; | |
7981 | ||
7982 | case 'c': | |
7983 | switch (name[1]) | |
7984 | { | |
7985 | case 'l': | |
7986 | if (name[2] == 'o' && | |
7987 | name[3] == 's' && | |
7988 | name[4] == 'e' && | |
7989 | name[5] == 'd' && | |
7990 | name[6] == 'i' && | |
7991 | name[7] == 'r') | |
7992 | { /* closedir */ | |
7993 | return -KEY_closedir; | |
7994 | } | |
7995 | ||
7996 | goto unknown; | |
7997 | ||
7998 | case 'o': | |
7999 | if (name[2] == 'n' && | |
8000 | name[3] == 't' && | |
8001 | name[4] == 'i' && | |
8002 | name[5] == 'n' && | |
8003 | name[6] == 'u' && | |
8004 | name[7] == 'e') | |
8005 | { /* continue */ | |
8006 | return -KEY_continue; | |
8007 | } | |
8008 | ||
8009 | goto unknown; | |
8010 | ||
8011 | default: | |
8012 | goto unknown; | |
8013 | } | |
8014 | ||
8015 | case 'd': | |
8016 | if (name[1] == 'b' && | |
8017 | name[2] == 'm' && | |
8018 | name[3] == 'c' && | |
8019 | name[4] == 'l' && | |
8020 | name[5] == 'o' && | |
8021 | name[6] == 's' && | |
8022 | name[7] == 'e') | |
8023 | { /* dbmclose */ | |
8024 | return -KEY_dbmclose; | |
8025 | } | |
8026 | ||
8027 | goto unknown; | |
8028 | ||
8029 | case 'e': | |
8030 | if (name[1] == 'n' && | |
8031 | name[2] == 'd') | |
8032 | { | |
8033 | switch (name[3]) | |
8034 | { | |
8035 | case 'g': | |
8036 | if (name[4] == 'r' && | |
8037 | name[5] == 'e' && | |
8038 | name[6] == 'n' && | |
8039 | name[7] == 't') | |
8040 | { /* endgrent */ | |
8041 | return -KEY_endgrent; | |
8042 | } | |
8043 | ||
8044 | goto unknown; | |
8045 | ||
8046 | case 'p': | |
8047 | if (name[4] == 'w' && | |
8048 | name[5] == 'e' && | |
8049 | name[6] == 'n' && | |
8050 | name[7] == 't') | |
8051 | { /* endpwent */ | |
8052 | return -KEY_endpwent; | |
8053 | } | |
8054 | ||
8055 | goto unknown; | |
8056 | ||
8057 | default: | |
8058 | goto unknown; | |
8059 | } | |
8060 | } | |
8061 | ||
8062 | goto unknown; | |
8063 | ||
8064 | case 'f': | |
8065 | if (name[1] == 'o' && | |
8066 | name[2] == 'r' && | |
8067 | name[3] == 'm' && | |
8068 | name[4] == 'l' && | |
8069 | name[5] == 'i' && | |
8070 | name[6] == 'n' && | |
8071 | name[7] == 'e') | |
8072 | { /* formline */ | |
8073 | return -KEY_formline; | |
8074 | } | |
8075 | ||
8076 | goto unknown; | |
8077 | ||
8078 | case 'g': | |
8079 | if (name[1] == 'e' && | |
8080 | name[2] == 't') | |
8081 | { | |
8082 | switch (name[3]) | |
8083 | { | |
8084 | case 'g': | |
8085 | if (name[4] == 'r') | |
8086 | { | |
8087 | switch (name[5]) | |
8088 | { | |
8089 | case 'e': | |
8090 | if (name[6] == 'n' && | |
8091 | name[7] == 't') | |
8092 | { /* getgrent */ | |
8093 | return -KEY_getgrent; | |
8094 | } | |
8095 | ||
8096 | goto unknown; | |
8097 | ||
8098 | case 'g': | |
8099 | if (name[6] == 'i' && | |
8100 | name[7] == 'd') | |
8101 | { /* getgrgid */ | |
8102 | return -KEY_getgrgid; | |
8103 | } | |
8104 | ||
8105 | goto unknown; | |
8106 | ||
8107 | case 'n': | |
8108 | if (name[6] == 'a' && | |
8109 | name[7] == 'm') | |
8110 | { /* getgrnam */ | |
8111 | return -KEY_getgrnam; | |
8112 | } | |
8113 | ||
8114 | goto unknown; | |
8115 | ||
8116 | default: | |
8117 | goto unknown; | |
8118 | } | |
8119 | } | |
8120 | ||
8121 | goto unknown; | |
8122 | ||
8123 | case 'l': | |
8124 | if (name[4] == 'o' && | |
8125 | name[5] == 'g' && | |
8126 | name[6] == 'i' && | |
8127 | name[7] == 'n') | |
8128 | { /* getlogin */ | |
8129 | return -KEY_getlogin; | |
8130 | } | |
8131 | ||
8132 | goto unknown; | |
8133 | ||
8134 | case 'p': | |
8135 | if (name[4] == 'w') | |
8136 | { | |
8137 | switch (name[5]) | |
8138 | { | |
8139 | case 'e': | |
8140 | if (name[6] == 'n' && | |
8141 | name[7] == 't') | |
8142 | { /* getpwent */ | |
8143 | return -KEY_getpwent; | |
8144 | } | |
8145 | ||
8146 | goto unknown; | |
8147 | ||
8148 | case 'n': | |
8149 | if (name[6] == 'a' && | |
8150 | name[7] == 'm') | |
8151 | { /* getpwnam */ | |
8152 | return -KEY_getpwnam; | |
8153 | } | |
8154 | ||
8155 | goto unknown; | |
8156 | ||
8157 | case 'u': | |
8158 | if (name[6] == 'i' && | |
8159 | name[7] == 'd') | |
8160 | { /* getpwuid */ | |
8161 | return -KEY_getpwuid; | |
8162 | } | |
8163 | ||
8164 | goto unknown; | |
8165 | ||
8166 | default: | |
8167 | goto unknown; | |
8168 | } | |
8169 | } | |
8170 | ||
8171 | goto unknown; | |
8172 | ||
8173 | default: | |
8174 | goto unknown; | |
8175 | } | |
8176 | } | |
8177 | ||
8178 | goto unknown; | |
8179 | ||
8180 | case 'r': | |
8181 | if (name[1] == 'e' && | |
8182 | name[2] == 'a' && | |
8183 | name[3] == 'd') | |
8184 | { | |
8185 | switch (name[4]) | |
8186 | { | |
8187 | case 'l': | |
8188 | if (name[5] == 'i' && | |
8189 | name[6] == 'n') | |
8190 | { | |
8191 | switch (name[7]) | |
8192 | { | |
8193 | case 'e': | |
8194 | { /* readline */ | |
8195 | return -KEY_readline; | |
8196 | } | |
8197 | ||
4c3bbe0f MHM |
8198 | case 'k': |
8199 | { /* readlink */ | |
8200 | return -KEY_readlink; | |
8201 | } | |
8202 | ||
4c3bbe0f MHM |
8203 | default: |
8204 | goto unknown; | |
8205 | } | |
8206 | } | |
8207 | ||
8208 | goto unknown; | |
8209 | ||
8210 | case 'p': | |
8211 | if (name[5] == 'i' && | |
8212 | name[6] == 'p' && | |
8213 | name[7] == 'e') | |
8214 | { /* readpipe */ | |
8215 | return -KEY_readpipe; | |
8216 | } | |
8217 | ||
8218 | goto unknown; | |
8219 | ||
8220 | default: | |
8221 | goto unknown; | |
8222 | } | |
8223 | } | |
8224 | ||
8225 | goto unknown; | |
8226 | ||
8227 | case 's': | |
8228 | switch (name[1]) | |
8229 | { | |
8230 | case 'e': | |
8231 | if (name[2] == 't') | |
8232 | { | |
8233 | switch (name[3]) | |
8234 | { | |
8235 | case 'g': | |
8236 | if (name[4] == 'r' && | |
8237 | name[5] == 'e' && | |
8238 | name[6] == 'n' && | |
8239 | name[7] == 't') | |
8240 | { /* setgrent */ | |
8241 | return -KEY_setgrent; | |
8242 | } | |
8243 | ||
8244 | goto unknown; | |
8245 | ||
8246 | case 'p': | |
8247 | if (name[4] == 'w' && | |
8248 | name[5] == 'e' && | |
8249 | name[6] == 'n' && | |
8250 | name[7] == 't') | |
8251 | { /* setpwent */ | |
8252 | return -KEY_setpwent; | |
8253 | } | |
8254 | ||
8255 | goto unknown; | |
8256 | ||
8257 | default: | |
8258 | goto unknown; | |
8259 | } | |
8260 | } | |
8261 | ||
8262 | goto unknown; | |
8263 | ||
8264 | case 'h': | |
8265 | switch (name[2]) | |
8266 | { | |
8267 | case 'm': | |
8268 | if (name[3] == 'w' && | |
8269 | name[4] == 'r' && | |
8270 | name[5] == 'i' && | |
8271 | name[6] == 't' && | |
8272 | name[7] == 'e') | |
8273 | { /* shmwrite */ | |
8274 | return -KEY_shmwrite; | |
8275 | } | |
8276 | ||
8277 | goto unknown; | |
8278 | ||
8279 | case 'u': | |
8280 | if (name[3] == 't' && | |
8281 | name[4] == 'd' && | |
8282 | name[5] == 'o' && | |
8283 | name[6] == 'w' && | |
8284 | name[7] == 'n') | |
8285 | { /* shutdown */ | |
8286 | return -KEY_shutdown; | |
8287 | } | |
8288 | ||
8289 | goto unknown; | |
8290 | ||
8291 | default: | |
8292 | goto unknown; | |
8293 | } | |
8294 | ||
8295 | case 'y': | |
8296 | if (name[2] == 's' && | |
8297 | name[3] == 'w' && | |
8298 | name[4] == 'r' && | |
8299 | name[5] == 'i' && | |
8300 | name[6] == 't' && | |
8301 | name[7] == 'e') | |
8302 | { /* syswrite */ | |
8303 | return -KEY_syswrite; | |
8304 | } | |
8305 | ||
8306 | goto unknown; | |
8307 | ||
8308 | default: | |
8309 | goto unknown; | |
8310 | } | |
8311 | ||
8312 | case 't': | |
8313 | if (name[1] == 'r' && | |
8314 | name[2] == 'u' && | |
8315 | name[3] == 'n' && | |
8316 | name[4] == 'c' && | |
8317 | name[5] == 'a' && | |
8318 | name[6] == 't' && | |
8319 | name[7] == 'e') | |
8320 | { /* truncate */ | |
8321 | return -KEY_truncate; | |
8322 | } | |
8323 | ||
8324 | goto unknown; | |
8325 | ||
8326 | default: | |
8327 | goto unknown; | |
8328 | } | |
8329 | ||
8330 | case 9: /* 8 tokens of length 9 */ | |
8331 | switch (name[0]) | |
8332 | { | |
8333 | case 'e': | |
8334 | if (name[1] == 'n' && | |
8335 | name[2] == 'd' && | |
8336 | name[3] == 'n' && | |
8337 | name[4] == 'e' && | |
8338 | name[5] == 't' && | |
8339 | name[6] == 'e' && | |
8340 | name[7] == 'n' && | |
8341 | name[8] == 't') | |
8342 | { /* endnetent */ | |
8343 | return -KEY_endnetent; | |
8344 | } | |
8345 | ||
8346 | goto unknown; | |
8347 | ||
8348 | case 'g': | |
8349 | if (name[1] == 'e' && | |
8350 | name[2] == 't' && | |
8351 | name[3] == 'n' && | |
8352 | name[4] == 'e' && | |
8353 | name[5] == 't' && | |
8354 | name[6] == 'e' && | |
8355 | name[7] == 'n' && | |
8356 | name[8] == 't') | |
8357 | { /* getnetent */ | |
8358 | return -KEY_getnetent; | |
8359 | } | |
8360 | ||
8361 | goto unknown; | |
8362 | ||
8363 | case 'l': | |
8364 | if (name[1] == 'o' && | |
8365 | name[2] == 'c' && | |
8366 | name[3] == 'a' && | |
8367 | name[4] == 'l' && | |
8368 | name[5] == 't' && | |
8369 | name[6] == 'i' && | |
8370 | name[7] == 'm' && | |
8371 | name[8] == 'e') | |
8372 | { /* localtime */ | |
8373 | return -KEY_localtime; | |
8374 | } | |
8375 | ||
8376 | goto unknown; | |
8377 | ||
8378 | case 'p': | |
8379 | if (name[1] == 'r' && | |
8380 | name[2] == 'o' && | |
8381 | name[3] == 't' && | |
8382 | name[4] == 'o' && | |
8383 | name[5] == 't' && | |
8384 | name[6] == 'y' && | |
8385 | name[7] == 'p' && | |
8386 | name[8] == 'e') | |
8387 | { /* prototype */ | |
8388 | return KEY_prototype; | |
8389 | } | |
8390 | ||
8391 | goto unknown; | |
8392 | ||
8393 | case 'q': | |
8394 | if (name[1] == 'u' && | |
8395 | name[2] == 'o' && | |
8396 | name[3] == 't' && | |
8397 | name[4] == 'e' && | |
8398 | name[5] == 'm' && | |
8399 | name[6] == 'e' && | |
8400 | name[7] == 't' && | |
8401 | name[8] == 'a') | |
8402 | { /* quotemeta */ | |
8403 | return -KEY_quotemeta; | |
8404 | } | |
8405 | ||
8406 | goto unknown; | |
8407 | ||
8408 | case 'r': | |
8409 | if (name[1] == 'e' && | |
8410 | name[2] == 'w' && | |
8411 | name[3] == 'i' && | |
8412 | name[4] == 'n' && | |
8413 | name[5] == 'd' && | |
8414 | name[6] == 'd' && | |
8415 | name[7] == 'i' && | |
8416 | name[8] == 'r') | |
8417 | { /* rewinddir */ | |
8418 | return -KEY_rewinddir; | |
8419 | } | |
8420 | ||
8421 | goto unknown; | |
8422 | ||
8423 | case 's': | |
8424 | if (name[1] == 'e' && | |
8425 | name[2] == 't' && | |
8426 | name[3] == 'n' && | |
8427 | name[4] == 'e' && | |
8428 | name[5] == 't' && | |
8429 | name[6] == 'e' && | |
8430 | name[7] == 'n' && | |
8431 | name[8] == 't') | |
8432 | { /* setnetent */ | |
8433 | return -KEY_setnetent; | |
8434 | } | |
8435 | ||
8436 | goto unknown; | |
8437 | ||
8438 | case 'w': | |
8439 | if (name[1] == 'a' && | |
8440 | name[2] == 'n' && | |
8441 | name[3] == 't' && | |
8442 | name[4] == 'a' && | |
8443 | name[5] == 'r' && | |
8444 | name[6] == 'r' && | |
8445 | name[7] == 'a' && | |
8446 | name[8] == 'y') | |
8447 | { /* wantarray */ | |
8448 | return -KEY_wantarray; | |
8449 | } | |
8450 | ||
8451 | goto unknown; | |
8452 | ||
8453 | default: | |
8454 | goto unknown; | |
8455 | } | |
8456 | ||
8457 | case 10: /* 9 tokens of length 10 */ | |
8458 | switch (name[0]) | |
8459 | { | |
8460 | case 'e': | |
8461 | if (name[1] == 'n' && | |
8462 | name[2] == 'd') | |
8463 | { | |
8464 | switch (name[3]) | |
8465 | { | |
8466 | case 'h': | |
8467 | if (name[4] == 'o' && | |
8468 | name[5] == 's' && | |
8469 | name[6] == 't' && | |
8470 | name[7] == 'e' && | |
8471 | name[8] == 'n' && | |
8472 | name[9] == 't') | |
8473 | { /* endhostent */ | |
8474 | return -KEY_endhostent; | |
8475 | } | |
8476 | ||
8477 | goto unknown; | |
8478 | ||
8479 | case 's': | |
8480 | if (name[4] == 'e' && | |
8481 | name[5] == 'r' && | |
8482 | name[6] == 'v' && | |
8483 | name[7] == 'e' && | |
8484 | name[8] == 'n' && | |
8485 | name[9] == 't') | |
8486 | { /* endservent */ | |
8487 | return -KEY_endservent; | |
8488 | } | |
8489 | ||
8490 | goto unknown; | |
8491 | ||
8492 | default: | |
8493 | goto unknown; | |
8494 | } | |
8495 | } | |
8496 | ||
8497 | goto unknown; | |
8498 | ||
8499 | case 'g': | |
8500 | if (name[1] == 'e' && | |
8501 | name[2] == 't') | |
8502 | { | |
8503 | switch (name[3]) | |
8504 | { | |
8505 | case 'h': | |
8506 | if (name[4] == 'o' && | |
8507 | name[5] == 's' && | |
8508 | name[6] == 't' && | |
8509 | name[7] == 'e' && | |
8510 | name[8] == 'n' && | |
8511 | name[9] == 't') | |
8512 | { /* gethostent */ | |
8513 | return -KEY_gethostent; | |
8514 | } | |
8515 | ||
8516 | goto unknown; | |
8517 | ||
8518 | case 's': | |
8519 | switch (name[4]) | |
8520 | { | |
8521 | case 'e': | |
8522 | if (name[5] == 'r' && | |
8523 | name[6] == 'v' && | |
8524 | name[7] == 'e' && | |
8525 | name[8] == 'n' && | |
8526 | name[9] == 't') | |
8527 | { /* getservent */ | |
8528 | return -KEY_getservent; | |
8529 | } | |
8530 | ||
8531 | goto unknown; | |
8532 | ||
8533 | case 'o': | |
8534 | if (name[5] == 'c' && | |
8535 | name[6] == 'k' && | |
8536 | name[7] == 'o' && | |
8537 | name[8] == 'p' && | |
8538 | name[9] == 't') | |
8539 | { /* getsockopt */ | |
8540 | return -KEY_getsockopt; | |
8541 | } | |
8542 | ||
8543 | goto unknown; | |
8544 | ||
8545 | default: | |
8546 | goto unknown; | |
8547 | } | |
8548 | ||
8549 | default: | |
8550 | goto unknown; | |
8551 | } | |
8552 | } | |
8553 | ||
8554 | goto unknown; | |
8555 | ||
8556 | case 's': | |
8557 | switch (name[1]) | |
8558 | { | |
8559 | case 'e': | |
8560 | if (name[2] == 't') | |
8561 | { | |
8562 | switch (name[3]) | |
8563 | { | |
8564 | case 'h': | |
8565 | if (name[4] == 'o' && | |
8566 | name[5] == 's' && | |
8567 | name[6] == 't' && | |
8568 | name[7] == 'e' && | |
8569 | name[8] == 'n' && | |
8570 | name[9] == 't') | |
8571 | { /* sethostent */ | |
8572 | return -KEY_sethostent; | |
8573 | } | |
8574 | ||
8575 | goto unknown; | |
8576 | ||
8577 | case 's': | |
8578 | switch (name[4]) | |
8579 | { | |
8580 | case 'e': | |
8581 | if (name[5] == 'r' && | |
8582 | name[6] == 'v' && | |
8583 | name[7] == 'e' && | |
8584 | name[8] == 'n' && | |
8585 | name[9] == 't') | |
8586 | { /* setservent */ | |
8587 | return -KEY_setservent; | |
8588 | } | |
8589 | ||
8590 | goto unknown; | |
8591 | ||
8592 | case 'o': | |
8593 | if (name[5] == 'c' && | |
8594 | name[6] == 'k' && | |
8595 | name[7] == 'o' && | |
8596 | name[8] == 'p' && | |
8597 | name[9] == 't') | |
8598 | { /* setsockopt */ | |
8599 | return -KEY_setsockopt; | |
8600 | } | |
8601 | ||
8602 | goto unknown; | |
8603 | ||
8604 | default: | |
8605 | goto unknown; | |
8606 | } | |
8607 | ||
8608 | default: | |
8609 | goto unknown; | |
8610 | } | |
8611 | } | |
8612 | ||
8613 | goto unknown; | |
8614 | ||
8615 | case 'o': | |
8616 | if (name[2] == 'c' && | |
8617 | name[3] == 'k' && | |
8618 | name[4] == 'e' && | |
8619 | name[5] == 't' && | |
8620 | name[6] == 'p' && | |
8621 | name[7] == 'a' && | |
8622 | name[8] == 'i' && | |
8623 | name[9] == 'r') | |
8624 | { /* socketpair */ | |
8625 | return -KEY_socketpair; | |
8626 | } | |
8627 | ||
8628 | goto unknown; | |
8629 | ||
8630 | default: | |
8631 | goto unknown; | |
8632 | } | |
8633 | ||
8634 | default: | |
8635 | goto unknown; | |
e2e1dd5a | 8636 | } |
4c3bbe0f MHM |
8637 | |
8638 | case 11: /* 8 tokens of length 11 */ | |
8639 | switch (name[0]) | |
8640 | { | |
8641 | case '_': | |
8642 | if (name[1] == '_' && | |
8643 | name[2] == 'P' && | |
8644 | name[3] == 'A' && | |
8645 | name[4] == 'C' && | |
8646 | name[5] == 'K' && | |
8647 | name[6] == 'A' && | |
8648 | name[7] == 'G' && | |
8649 | name[8] == 'E' && | |
8650 | name[9] == '_' && | |
8651 | name[10] == '_') | |
8652 | { /* __PACKAGE__ */ | |
8653 | return -KEY___PACKAGE__; | |
8654 | } | |
8655 | ||
8656 | goto unknown; | |
8657 | ||
8658 | case 'e': | |
8659 | if (name[1] == 'n' && | |
8660 | name[2] == 'd' && | |
8661 | name[3] == 'p' && | |
8662 | name[4] == 'r' && | |
8663 | name[5] == 'o' && | |
8664 | name[6] == 't' && | |
8665 | name[7] == 'o' && | |
8666 | name[8] == 'e' && | |
8667 | name[9] == 'n' && | |
8668 | name[10] == 't') | |
8669 | { /* endprotoent */ | |
8670 | return -KEY_endprotoent; | |
8671 | } | |
8672 | ||
8673 | goto unknown; | |
8674 | ||
8675 | case 'g': | |
8676 | if (name[1] == 'e' && | |
8677 | name[2] == 't') | |
8678 | { | |
8679 | switch (name[3]) | |
8680 | { | |
8681 | case 'p': | |
8682 | switch (name[4]) | |
8683 | { | |
8684 | case 'e': | |
8685 | if (name[5] == 'e' && | |
8686 | name[6] == 'r' && | |
8687 | name[7] == 'n' && | |
8688 | name[8] == 'a' && | |
8689 | name[9] == 'm' && | |
8690 | name[10] == 'e') | |
8691 | { /* getpeername */ | |
8692 | return -KEY_getpeername; | |
8693 | } | |
8694 | ||
8695 | goto unknown; | |
8696 | ||
8697 | case 'r': | |
8698 | switch (name[5]) | |
8699 | { | |
8700 | case 'i': | |
8701 | if (name[6] == 'o' && | |
8702 | name[7] == 'r' && | |
8703 | name[8] == 'i' && | |
8704 | name[9] == 't' && | |
8705 | name[10] == 'y') | |
8706 | { /* getpriority */ | |
8707 | return -KEY_getpriority; | |
8708 | } | |
8709 | ||
8710 | goto unknown; | |
8711 | ||
8712 | case 'o': | |
8713 | if (name[6] == 't' && | |
8714 | name[7] == 'o' && | |
8715 | name[8] == 'e' && | |
8716 | name[9] == 'n' && | |
8717 | name[10] == 't') | |
8718 | { /* getprotoent */ | |
8719 | return -KEY_getprotoent; | |
8720 | } | |
8721 | ||
8722 | goto unknown; | |
8723 | ||
8724 | default: | |
8725 | goto unknown; | |
8726 | } | |
8727 | ||
8728 | default: | |
8729 | goto unknown; | |
8730 | } | |
8731 | ||
8732 | case 's': | |
8733 | if (name[4] == 'o' && | |
8734 | name[5] == 'c' && | |
8735 | name[6] == 'k' && | |
8736 | name[7] == 'n' && | |
8737 | name[8] == 'a' && | |
8738 | name[9] == 'm' && | |
8739 | name[10] == 'e') | |
8740 | { /* getsockname */ | |
8741 | return -KEY_getsockname; | |
8742 | } | |
8743 | ||
8744 | goto unknown; | |
8745 | ||
8746 | default: | |
8747 | goto unknown; | |
8748 | } | |
8749 | } | |
8750 | ||
8751 | goto unknown; | |
8752 | ||
8753 | case 's': | |
8754 | if (name[1] == 'e' && | |
8755 | name[2] == 't' && | |
8756 | name[3] == 'p' && | |
8757 | name[4] == 'r') | |
8758 | { | |
8759 | switch (name[5]) | |
8760 | { | |
8761 | case 'i': | |
8762 | if (name[6] == 'o' && | |
8763 | name[7] == 'r' && | |
8764 | name[8] == 'i' && | |
8765 | name[9] == 't' && | |
8766 | name[10] == 'y') | |
8767 | { /* setpriority */ | |
8768 | return -KEY_setpriority; | |
8769 | } | |
8770 | ||
8771 | goto unknown; | |
8772 | ||
8773 | case 'o': | |
8774 | if (name[6] == 't' && | |
8775 | name[7] == 'o' && | |
8776 | name[8] == 'e' && | |
8777 | name[9] == 'n' && | |
8778 | name[10] == 't') | |
8779 | { /* setprotoent */ | |
8780 | return -KEY_setprotoent; | |
8781 | } | |
8782 | ||
8783 | goto unknown; | |
8784 | ||
8785 | default: | |
8786 | goto unknown; | |
8787 | } | |
8788 | } | |
8789 | ||
8790 | goto unknown; | |
8791 | ||
8792 | default: | |
8793 | goto unknown; | |
e2e1dd5a | 8794 | } |
4c3bbe0f MHM |
8795 | |
8796 | case 12: /* 2 tokens of length 12 */ | |
8797 | if (name[0] == 'g' && | |
8798 | name[1] == 'e' && | |
8799 | name[2] == 't' && | |
8800 | name[3] == 'n' && | |
8801 | name[4] == 'e' && | |
8802 | name[5] == 't' && | |
8803 | name[6] == 'b' && | |
8804 | name[7] == 'y') | |
8805 | { | |
8806 | switch (name[8]) | |
8807 | { | |
8808 | case 'a': | |
8809 | if (name[9] == 'd' && | |
8810 | name[10] == 'd' && | |
8811 | name[11] == 'r') | |
8812 | { /* getnetbyaddr */ | |
8813 | return -KEY_getnetbyaddr; | |
8814 | } | |
8815 | ||
8816 | goto unknown; | |
8817 | ||
8818 | case 'n': | |
8819 | if (name[9] == 'a' && | |
8820 | name[10] == 'm' && | |
8821 | name[11] == 'e') | |
8822 | { /* getnetbyname */ | |
8823 | return -KEY_getnetbyname; | |
8824 | } | |
8825 | ||
8826 | goto unknown; | |
8827 | ||
8828 | default: | |
8829 | goto unknown; | |
8830 | } | |
e2e1dd5a | 8831 | } |
4c3bbe0f MHM |
8832 | |
8833 | goto unknown; | |
8834 | ||
8835 | case 13: /* 4 tokens of length 13 */ | |
8836 | if (name[0] == 'g' && | |
8837 | name[1] == 'e' && | |
8838 | name[2] == 't') | |
8839 | { | |
8840 | switch (name[3]) | |
8841 | { | |
8842 | case 'h': | |
8843 | if (name[4] == 'o' && | |
8844 | name[5] == 's' && | |
8845 | name[6] == 't' && | |
8846 | name[7] == 'b' && | |
8847 | name[8] == 'y') | |
8848 | { | |
8849 | switch (name[9]) | |
8850 | { | |
8851 | case 'a': | |
8852 | if (name[10] == 'd' && | |
8853 | name[11] == 'd' && | |
8854 | name[12] == 'r') | |
8855 | { /* gethostbyaddr */ | |
8856 | return -KEY_gethostbyaddr; | |
8857 | } | |
8858 | ||
8859 | goto unknown; | |
8860 | ||
8861 | case 'n': | |
8862 | if (name[10] == 'a' && | |
8863 | name[11] == 'm' && | |
8864 | name[12] == 'e') | |
8865 | { /* gethostbyname */ | |
8866 | return -KEY_gethostbyname; | |
8867 | } | |
8868 | ||
8869 | goto unknown; | |
8870 | ||
8871 | default: | |
8872 | goto unknown; | |
8873 | } | |
8874 | } | |
8875 | ||
8876 | goto unknown; | |
8877 | ||
8878 | case 's': | |
8879 | if (name[4] == 'e' && | |
8880 | name[5] == 'r' && | |
8881 | name[6] == 'v' && | |
8882 | name[7] == 'b' && | |
8883 | name[8] == 'y') | |
8884 | { | |
8885 | switch (name[9]) | |
8886 | { | |
8887 | case 'n': | |
8888 | if (name[10] == 'a' && | |
8889 | name[11] == 'm' && | |
8890 | name[12] == 'e') | |
8891 | { /* getservbyname */ | |
8892 | return -KEY_getservbyname; | |
8893 | } | |
8894 | ||
8895 | goto unknown; | |
8896 | ||
8897 | case 'p': | |
8898 | if (name[10] == 'o' && | |
8899 | name[11] == 'r' && | |
8900 | name[12] == 't') | |
8901 | { /* getservbyport */ | |
8902 | return -KEY_getservbyport; | |
8903 | } | |
8904 | ||
8905 | goto unknown; | |
8906 | ||
8907 | default: | |
8908 | goto unknown; | |
8909 | } | |
8910 | } | |
8911 | ||
8912 | goto unknown; | |
8913 | ||
8914 | default: | |
8915 | goto unknown; | |
8916 | } | |
e2e1dd5a | 8917 | } |
4c3bbe0f MHM |
8918 | |
8919 | goto unknown; | |
8920 | ||
8921 | case 14: /* 1 tokens of length 14 */ | |
8922 | if (name[0] == 'g' && | |
8923 | name[1] == 'e' && | |
8924 | name[2] == 't' && | |
8925 | name[3] == 'p' && | |
8926 | name[4] == 'r' && | |
8927 | name[5] == 'o' && | |
8928 | name[6] == 't' && | |
8929 | name[7] == 'o' && | |
8930 | name[8] == 'b' && | |
8931 | name[9] == 'y' && | |
8932 | name[10] == 'n' && | |
8933 | name[11] == 'a' && | |
8934 | name[12] == 'm' && | |
8935 | name[13] == 'e') | |
8936 | { /* getprotobyname */ | |
8937 | return -KEY_getprotobyname; | |
8938 | } | |
8939 | ||
8940 | goto unknown; | |
8941 | ||
8942 | case 16: /* 1 tokens of length 16 */ | |
8943 | if (name[0] == 'g' && | |
8944 | name[1] == 'e' && | |
8945 | name[2] == 't' && | |
8946 | name[3] == 'p' && | |
8947 | name[4] == 'r' && | |
8948 | name[5] == 'o' && | |
8949 | name[6] == 't' && | |
8950 | name[7] == 'o' && | |
8951 | name[8] == 'b' && | |
8952 | name[9] == 'y' && | |
8953 | name[10] == 'n' && | |
8954 | name[11] == 'u' && | |
8955 | name[12] == 'm' && | |
8956 | name[13] == 'b' && | |
8957 | name[14] == 'e' && | |
8958 | name[15] == 'r') | |
8959 | { /* getprotobynumber */ | |
8960 | return -KEY_getprotobynumber; | |
8961 | } | |
8962 | ||
8963 | goto unknown; | |
8964 | ||
8965 | default: | |
8966 | goto unknown; | |
e2e1dd5a | 8967 | } |
4c3bbe0f MHM |
8968 | |
8969 | unknown: | |
e2e1dd5a | 8970 | return 0; |
a687059c LW |
8971 | } |
8972 | ||
76e3520e | 8973 | STATIC void |
f54cb97a | 8974 | S_checkcomma(pTHX_ register char *s, const char *name, const char *what) |
a687059c | 8975 | { |
f54cb97a | 8976 | const char *w; |
2f3197b3 | 8977 | |
d008e5eb | 8978 | if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */ |
d008e5eb GS |
8979 | if (ckWARN(WARN_SYNTAX)) { |
8980 | int level = 1; | |
8981 | for (w = s+2; *w && level; w++) { | |
8982 | if (*w == '(') | |
8983 | ++level; | |
8984 | else if (*w == ')') | |
8985 | --level; | |
8986 | } | |
8987 | if (*w) | |
8988 | for (; *w && isSPACE(*w); w++) ; | |
8989 | if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */ | |
9014280d | 8990 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
65cec589 | 8991 | "%s (...) interpreted as function",name); |
d008e5eb | 8992 | } |
2f3197b3 | 8993 | } |
3280af22 | 8994 | while (s < PL_bufend && isSPACE(*s)) |
2f3197b3 | 8995 | s++; |
a687059c LW |
8996 | if (*s == '(') |
8997 | s++; | |
3280af22 | 8998 | while (s < PL_bufend && isSPACE(*s)) |
a687059c | 8999 | s++; |
7e2040f0 | 9000 | if (isIDFIRST_lazy_if(s,UTF)) { |
2f3197b3 | 9001 | w = s++; |
7e2040f0 | 9002 | while (isALNUM_lazy_if(s,UTF)) |
a687059c | 9003 | s++; |
3280af22 | 9004 | while (s < PL_bufend && isSPACE(*s)) |
a687059c | 9005 | s++; |
e929a76b | 9006 | if (*s == ',') { |
463ee0b2 | 9007 | int kw; |
f54cb97a | 9008 | *s = '\0'; /* XXX If we didn't do this, we could const a lot of toke.c */ |
864dbfa3 | 9009 | kw = keyword(w, s - w) || get_cv(w, FALSE) != 0; |
e929a76b | 9010 | *s = ','; |
463ee0b2 | 9011 | if (kw) |
e929a76b | 9012 | return; |
cea2e8a9 | 9013 | Perl_croak(aTHX_ "No comma allowed after %s", what); |
463ee0b2 LW |
9014 | } |
9015 | } | |
9016 | } | |
9017 | ||
423cee85 JH |
9018 | /* Either returns sv, or mortalizes sv and returns a new SV*. |
9019 | Best used as sv=new_constant(..., sv, ...). | |
9020 | If s, pv are NULL, calls subroutine with one argument, | |
9021 | and type is used with error messages only. */ | |
9022 | ||
b3ac6de7 | 9023 | STATIC SV * |
7fc63493 | 9024 | S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv, |
9b0e499b | 9025 | const char *type) |
b3ac6de7 | 9026 | { |
27da23d5 | 9027 | dVAR; dSP; |
890ce7af | 9028 | HV * const table = GvHV(PL_hintgv); /* ^H */ |
b3ac6de7 | 9029 | SV *res; |
b3ac6de7 IZ |
9030 | SV **cvp; |
9031 | SV *cv, *typesv; | |
89e33a05 | 9032 | const char *why1 = "", *why2 = "", *why3 = ""; |
4e553d73 | 9033 | |
f0af216f | 9034 | if (!table || !(PL_hints & HINT_LOCALIZE_HH)) { |
423cee85 JH |
9035 | SV *msg; |
9036 | ||
f0af216f | 9037 | why2 = strEQ(key,"charnames") |
41ab332f | 9038 | ? "(possibly a missing \"use charnames ...\")" |
f0af216f | 9039 | : ""; |
4e553d73 | 9040 | msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s", |
41ab332f JH |
9041 | (type ? type: "undef"), why2); |
9042 | ||
9043 | /* This is convoluted and evil ("goto considered harmful") | |
9044 | * but I do not understand the intricacies of all the different | |
9045 | * failure modes of %^H in here. The goal here is to make | |
9046 | * the most probable error message user-friendly. --jhi */ | |
9047 | ||
9048 | goto msgdone; | |
9049 | ||
423cee85 | 9050 | report: |
4e553d73 | 9051 | msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s", |
f0af216f | 9052 | (type ? type: "undef"), why1, why2, why3); |
41ab332f | 9053 | msgdone: |
95a20fc0 | 9054 | yyerror(SvPVX_const(msg)); |
423cee85 JH |
9055 | SvREFCNT_dec(msg); |
9056 | return sv; | |
9057 | } | |
b3ac6de7 IZ |
9058 | cvp = hv_fetch(table, key, strlen(key), FALSE); |
9059 | if (!cvp || !SvOK(*cvp)) { | |
423cee85 JH |
9060 | why1 = "$^H{"; |
9061 | why2 = key; | |
f0af216f | 9062 | why3 = "} is not defined"; |
423cee85 | 9063 | goto report; |
b3ac6de7 IZ |
9064 | } |
9065 | sv_2mortal(sv); /* Parent created it permanently */ | |
9066 | cv = *cvp; | |
423cee85 JH |
9067 | if (!pv && s) |
9068 | pv = sv_2mortal(newSVpvn(s, len)); | |
9069 | if (type && pv) | |
9070 | typesv = sv_2mortal(newSVpv(type, 0)); | |
b3ac6de7 | 9071 | else |
423cee85 | 9072 | typesv = &PL_sv_undef; |
4e553d73 | 9073 | |
e788e7d3 | 9074 | PUSHSTACKi(PERLSI_OVERLOAD); |
423cee85 JH |
9075 | ENTER ; |
9076 | SAVETMPS; | |
4e553d73 | 9077 | |
423cee85 | 9078 | PUSHMARK(SP) ; |
a5845cb7 | 9079 | EXTEND(sp, 3); |
423cee85 JH |
9080 | if (pv) |
9081 | PUSHs(pv); | |
b3ac6de7 | 9082 | PUSHs(sv); |
423cee85 JH |
9083 | if (pv) |
9084 | PUSHs(typesv); | |
b3ac6de7 | 9085 | PUTBACK; |
423cee85 | 9086 | call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL)); |
4e553d73 | 9087 | |
423cee85 | 9088 | SPAGAIN ; |
4e553d73 | 9089 | |
423cee85 | 9090 | /* Check the eval first */ |
9b0e499b | 9091 | if (!PL_in_eval && SvTRUE(ERRSV)) { |
423cee85 | 9092 | sv_catpv(ERRSV, "Propagated"); |
8b6b16e7 | 9093 | yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */ |
e1f15930 | 9094 | (void)POPs; |
423cee85 JH |
9095 | res = SvREFCNT_inc(sv); |
9096 | } | |
9097 | else { | |
9098 | res = POPs; | |
e1f15930 | 9099 | (void)SvREFCNT_inc(res); |
423cee85 | 9100 | } |
4e553d73 | 9101 | |
423cee85 JH |
9102 | PUTBACK ; |
9103 | FREETMPS ; | |
9104 | LEAVE ; | |
b3ac6de7 | 9105 | POPSTACK; |
4e553d73 | 9106 | |
b3ac6de7 | 9107 | if (!SvOK(res)) { |
423cee85 JH |
9108 | why1 = "Call to &{$^H{"; |
9109 | why2 = key; | |
f0af216f | 9110 | why3 = "}} did not return a defined value"; |
423cee85 JH |
9111 | sv = res; |
9112 | goto report; | |
9b0e499b | 9113 | } |
423cee85 | 9114 | |
9b0e499b | 9115 | return res; |
b3ac6de7 | 9116 | } |
4e553d73 | 9117 | |
d0a148a6 NC |
9118 | /* Returns a NUL terminated string, with the length of the string written to |
9119 | *slp | |
9120 | */ | |
76e3520e | 9121 | STATIC char * |
cea2e8a9 | 9122 | S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp) |
463ee0b2 LW |
9123 | { |
9124 | register char *d = dest; | |
890ce7af | 9125 | register char * const e = d + destlen - 3; /* two-character token, ending NUL */ |
463ee0b2 | 9126 | for (;;) { |
8903cb82 | 9127 | if (d >= e) |
cea2e8a9 | 9128 | Perl_croak(aTHX_ ident_too_long); |
834a4ddd | 9129 | if (isALNUM(*s)) /* UTF handled below */ |
463ee0b2 | 9130 | *d++ = *s++; |
7e2040f0 | 9131 | else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) { |
463ee0b2 LW |
9132 | *d++ = ':'; |
9133 | *d++ = ':'; | |
9134 | s++; | |
9135 | } | |
c3e0f903 | 9136 | else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') { |
463ee0b2 LW |
9137 | *d++ = *s++; |
9138 | *d++ = *s++; | |
9139 | } | |
fd400ab9 | 9140 | else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
a0ed51b3 | 9141 | char *t = s + UTF8SKIP(s); |
fd400ab9 | 9142 | while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
a0ed51b3 LW |
9143 | t += UTF8SKIP(t); |
9144 | if (d + (t - s) > e) | |
cea2e8a9 | 9145 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 LW |
9146 | Copy(s, d, t - s, char); |
9147 | d += t - s; | |
9148 | s = t; | |
9149 | } | |
463ee0b2 LW |
9150 | else { |
9151 | *d = '\0'; | |
9152 | *slp = d - dest; | |
9153 | return s; | |
e929a76b | 9154 | } |
378cc40b LW |
9155 | } |
9156 | } | |
9157 | ||
76e3520e | 9158 | STATIC char * |
f54cb97a | 9159 | S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni) |
378cc40b LW |
9160 | { |
9161 | register char *d; | |
8903cb82 | 9162 | register char *e; |
46c461b5 | 9163 | char *bracket = Nullch; |
748a9306 | 9164 | char funny = *s++; |
378cc40b | 9165 | |
a0d0e21e LW |
9166 | if (isSPACE(*s)) |
9167 | s = skipspace(s); | |
378cc40b | 9168 | d = dest; |
8903cb82 | 9169 | e = d + destlen - 3; /* two-character token, ending NUL */ |
de3bb511 | 9170 | if (isDIGIT(*s)) { |
8903cb82 | 9171 | while (isDIGIT(*s)) { |
9172 | if (d >= e) | |
cea2e8a9 | 9173 | Perl_croak(aTHX_ ident_too_long); |
378cc40b | 9174 | *d++ = *s++; |
8903cb82 | 9175 | } |
378cc40b LW |
9176 | } |
9177 | else { | |
463ee0b2 | 9178 | for (;;) { |
8903cb82 | 9179 | if (d >= e) |
cea2e8a9 | 9180 | Perl_croak(aTHX_ ident_too_long); |
834a4ddd | 9181 | if (isALNUM(*s)) /* UTF handled below */ |
463ee0b2 | 9182 | *d++ = *s++; |
7e2040f0 | 9183 | else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) { |
463ee0b2 LW |
9184 | *d++ = ':'; |
9185 | *d++ = ':'; | |
9186 | s++; | |
9187 | } | |
a0d0e21e | 9188 | else if (*s == ':' && s[1] == ':') { |
463ee0b2 LW |
9189 | *d++ = *s++; |
9190 | *d++ = *s++; | |
9191 | } | |
fd400ab9 | 9192 | else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
a0ed51b3 | 9193 | char *t = s + UTF8SKIP(s); |
fd400ab9 | 9194 | while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
a0ed51b3 LW |
9195 | t += UTF8SKIP(t); |
9196 | if (d + (t - s) > e) | |
cea2e8a9 | 9197 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 LW |
9198 | Copy(s, d, t - s, char); |
9199 | d += t - s; | |
9200 | s = t; | |
9201 | } | |
463ee0b2 LW |
9202 | else |
9203 | break; | |
9204 | } | |
378cc40b LW |
9205 | } |
9206 | *d = '\0'; | |
9207 | d = dest; | |
79072805 | 9208 | if (*d) { |
3280af22 NIS |
9209 | if (PL_lex_state != LEX_NORMAL) |
9210 | PL_lex_state = LEX_INTERPENDMAYBE; | |
79072805 | 9211 | return s; |
378cc40b | 9212 | } |
748a9306 | 9213 | if (*s == '$' && s[1] && |
3792a11b | 9214 | (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) ) |
5cd24f17 | 9215 | { |
4810e5ec | 9216 | return s; |
5cd24f17 | 9217 | } |
79072805 LW |
9218 | if (*s == '{') { |
9219 | bracket = s; | |
9220 | s++; | |
9221 | } | |
9222 | else if (ck_uni) | |
9223 | check_uni(); | |
93a17b20 | 9224 | if (s < send) |
79072805 LW |
9225 | *d = *s++; |
9226 | d[1] = '\0'; | |
2b92dfce | 9227 | if (*d == '^' && *s && isCONTROLVAR(*s)) { |
bbce6d69 | 9228 | *d = toCTRL(*s); |
9229 | s++; | |
de3bb511 | 9230 | } |
79072805 | 9231 | if (bracket) { |
748a9306 | 9232 | if (isSPACE(s[-1])) { |
fa83b5b6 | 9233 | while (s < send) { |
f54cb97a | 9234 | const char ch = *s++; |
bf4acbe4 | 9235 | if (!SPACE_OR_TAB(ch)) { |
fa83b5b6 | 9236 | *d = ch; |
9237 | break; | |
9238 | } | |
9239 | } | |
748a9306 | 9240 | } |
7e2040f0 | 9241 | if (isIDFIRST_lazy_if(d,UTF)) { |
79072805 | 9242 | d++; |
a0ed51b3 LW |
9243 | if (UTF) { |
9244 | e = s; | |
155aba94 | 9245 | while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') { |
a0ed51b3 | 9246 | e += UTF8SKIP(e); |
fd400ab9 | 9247 | while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e)) |
a0ed51b3 LW |
9248 | e += UTF8SKIP(e); |
9249 | } | |
9250 | Copy(s, d, e - s, char); | |
9251 | d += e - s; | |
9252 | s = e; | |
9253 | } | |
9254 | else { | |
2b92dfce | 9255 | while ((isALNUM(*s) || *s == ':') && d < e) |
a0ed51b3 | 9256 | *d++ = *s++; |
2b92dfce | 9257 | if (d >= e) |
cea2e8a9 | 9258 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 | 9259 | } |
79072805 | 9260 | *d = '\0'; |
bf4acbe4 | 9261 | while (s < send && SPACE_OR_TAB(*s)) s++; |
ff68c719 | 9262 | if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) { |
599cee73 | 9263 | if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) { |
dff6d3cd | 9264 | const char *brack = *s == '[' ? "[...]" : "{...}"; |
9014280d | 9265 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
599cee73 | 9266 | "Ambiguous use of %c{%s%s} resolved to %c%s%s", |
748a9306 LW |
9267 | funny, dest, brack, funny, dest, brack); |
9268 | } | |
79072805 | 9269 | bracket++; |
a0be28da | 9270 | PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK); |
79072805 LW |
9271 | return s; |
9272 | } | |
4e553d73 NIS |
9273 | } |
9274 | /* Handle extended ${^Foo} variables | |
2b92dfce GS |
9275 | * 1999-02-27 mjd-perl-patch@plover.com */ |
9276 | else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */ | |
9277 | && isALNUM(*s)) | |
9278 | { | |
9279 | d++; | |
9280 | while (isALNUM(*s) && d < e) { | |
9281 | *d++ = *s++; | |
9282 | } | |
9283 | if (d >= e) | |
cea2e8a9 | 9284 | Perl_croak(aTHX_ ident_too_long); |
2b92dfce | 9285 | *d = '\0'; |
79072805 LW |
9286 | } |
9287 | if (*s == '}') { | |
9288 | s++; | |
7df0d042 | 9289 | if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) { |
3280af22 | 9290 | PL_lex_state = LEX_INTERPEND; |
7df0d042 AE |
9291 | PL_expect = XREF; |
9292 | } | |
748a9306 LW |
9293 | if (funny == '#') |
9294 | funny = '@'; | |
d008e5eb | 9295 | if (PL_lex_state == LEX_NORMAL) { |
d008e5eb | 9296 | if (ckWARN(WARN_AMBIGUOUS) && |
864dbfa3 | 9297 | (keyword(dest, d - dest) || get_cv(dest, FALSE))) |
d008e5eb | 9298 | { |
9014280d | 9299 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
d008e5eb GS |
9300 | "Ambiguous use of %c{%s} resolved to %c%s", |
9301 | funny, dest, funny, dest); | |
9302 | } | |
9303 | } | |
79072805 LW |
9304 | } |
9305 | else { | |
9306 | s = bracket; /* let the parser handle it */ | |
93a17b20 | 9307 | *dest = '\0'; |
79072805 LW |
9308 | } |
9309 | } | |
3280af22 NIS |
9310 | else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s)) |
9311 | PL_lex_state = LEX_INTERPEND; | |
378cc40b LW |
9312 | return s; |
9313 | } | |
9314 | ||
cea2e8a9 | 9315 | void |
2b36a5a0 | 9316 | Perl_pmflag(pTHX_ U32* pmfl, int ch) |
a0d0e21e | 9317 | { |
bbce6d69 | 9318 | if (ch == 'i') |
a0d0e21e | 9319 | *pmfl |= PMf_FOLD; |
a0d0e21e LW |
9320 | else if (ch == 'g') |
9321 | *pmfl |= PMf_GLOBAL; | |
c90c0ff4 | 9322 | else if (ch == 'c') |
9323 | *pmfl |= PMf_CONTINUE; | |
a0d0e21e LW |
9324 | else if (ch == 'o') |
9325 | *pmfl |= PMf_KEEP; | |
9326 | else if (ch == 'm') | |
9327 | *pmfl |= PMf_MULTILINE; | |
9328 | else if (ch == 's') | |
9329 | *pmfl |= PMf_SINGLELINE; | |
9330 | else if (ch == 'x') | |
9331 | *pmfl |= PMf_EXTENDED; | |
9332 | } | |
378cc40b | 9333 | |
76e3520e | 9334 | STATIC char * |
cea2e8a9 | 9335 | S_scan_pat(pTHX_ char *start, I32 type) |
378cc40b | 9336 | { |
79072805 | 9337 | PMOP *pm; |
f54cb97a | 9338 | char *s = scan_str(start,FALSE,FALSE); |
378cc40b | 9339 | |
25c09cbf | 9340 | if (!s) { |
46c461b5 | 9341 | char * const delimiter = skipspace(start); |
25c09cbf SF |
9342 | Perl_croak(aTHX_ *delimiter == '?' |
9343 | ? "Search pattern not terminated or ternary operator parsed as search pattern" | |
9344 | : "Search pattern not terminated" ); | |
9345 | } | |
bbce6d69 | 9346 | |
8782bef2 | 9347 | pm = (PMOP*)newPMOP(type, 0); |
3280af22 | 9348 | if (PL_multi_open == '?') |
79072805 | 9349 | pm->op_pmflags |= PMf_ONCE; |
8782bef2 GB |
9350 | if(type == OP_QR) { |
9351 | while (*s && strchr("iomsx", *s)) | |
9352 | pmflag(&pm->op_pmflags,*s++); | |
9353 | } | |
9354 | else { | |
9355 | while (*s && strchr("iogcmsx", *s)) | |
9356 | pmflag(&pm->op_pmflags,*s++); | |
9357 | } | |
4ac733c9 | 9358 | /* issue a warning if /c is specified,but /g is not */ |
041457d9 DM |
9359 | if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL) |
9360 | && ckWARN(WARN_REGEXP)) | |
4ac733c9 | 9361 | { |
0bd48802 | 9362 | Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" ); |
4ac733c9 MJD |
9363 | } |
9364 | ||
4633a7c4 | 9365 | pm->op_pmpermflags = pm->op_pmflags; |
bbce6d69 | 9366 | |
3280af22 | 9367 | PL_lex_op = (OP*)pm; |
79072805 | 9368 | yylval.ival = OP_MATCH; |
378cc40b LW |
9369 | return s; |
9370 | } | |
9371 | ||
76e3520e | 9372 | STATIC char * |
cea2e8a9 | 9373 | S_scan_subst(pTHX_ char *start) |
79072805 | 9374 | { |
27da23d5 | 9375 | dVAR; |
a0d0e21e | 9376 | register char *s; |
79072805 | 9377 | register PMOP *pm; |
4fdae800 | 9378 | I32 first_start; |
79072805 LW |
9379 | I32 es = 0; |
9380 | ||
79072805 LW |
9381 | yylval.ival = OP_NULL; |
9382 | ||
09bef843 | 9383 | s = scan_str(start,FALSE,FALSE); |
79072805 | 9384 | |
37fd879b | 9385 | if (!s) |
cea2e8a9 | 9386 | Perl_croak(aTHX_ "Substitution pattern not terminated"); |
79072805 | 9387 | |
3280af22 | 9388 | if (s[-1] == PL_multi_open) |
79072805 LW |
9389 | s--; |
9390 | ||
3280af22 | 9391 | first_start = PL_multi_start; |
09bef843 | 9392 | s = scan_str(s,FALSE,FALSE); |
79072805 | 9393 | if (!s) { |
37fd879b | 9394 | if (PL_lex_stuff) { |
3280af22 | 9395 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
9396 | PL_lex_stuff = Nullsv; |
9397 | } | |
cea2e8a9 | 9398 | Perl_croak(aTHX_ "Substitution replacement not terminated"); |
a687059c | 9399 | } |
3280af22 | 9400 | PL_multi_start = first_start; /* so whole substitution is taken together */ |
2f3197b3 | 9401 | |
79072805 | 9402 | pm = (PMOP*)newPMOP(OP_SUBST, 0); |
48c036b1 | 9403 | while (*s) { |
a687059c LW |
9404 | if (*s == 'e') { |
9405 | s++; | |
2f3197b3 | 9406 | es++; |
a687059c | 9407 | } |
b3eb6a9b | 9408 | else if (strchr("iogcmsx", *s)) |
a0d0e21e | 9409 | pmflag(&pm->op_pmflags,*s++); |
48c036b1 GS |
9410 | else |
9411 | break; | |
378cc40b | 9412 | } |
79072805 | 9413 | |
0bd48802 AL |
9414 | if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) { |
9415 | Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" ); | |
4ac733c9 MJD |
9416 | } |
9417 | ||
79072805 LW |
9418 | if (es) { |
9419 | SV *repl; | |
0244c3a4 GS |
9420 | PL_sublex_info.super_bufptr = s; |
9421 | PL_sublex_info.super_bufend = PL_bufend; | |
9422 | PL_multi_end = 0; | |
79072805 | 9423 | pm->op_pmflags |= PMf_EVAL; |
79cb57f6 | 9424 | repl = newSVpvn("",0); |
463ee0b2 | 9425 | while (es-- > 0) |
a0d0e21e | 9426 | sv_catpv(repl, es ? "eval " : "do "); |
79072805 | 9427 | sv_catpvn(repl, "{ ", 2); |
3280af22 | 9428 | sv_catsv(repl, PL_lex_repl); |
79072805 | 9429 | sv_catpvn(repl, " };", 2); |
25da4f38 | 9430 | SvEVALED_on(repl); |
3280af22 NIS |
9431 | SvREFCNT_dec(PL_lex_repl); |
9432 | PL_lex_repl = repl; | |
378cc40b | 9433 | } |
79072805 | 9434 | |
4633a7c4 | 9435 | pm->op_pmpermflags = pm->op_pmflags; |
3280af22 | 9436 | PL_lex_op = (OP*)pm; |
79072805 | 9437 | yylval.ival = OP_SUBST; |
378cc40b LW |
9438 | return s; |
9439 | } | |
9440 | ||
76e3520e | 9441 | STATIC char * |
cea2e8a9 | 9442 | S_scan_trans(pTHX_ char *start) |
378cc40b | 9443 | { |
a0d0e21e | 9444 | register char* s; |
11343788 | 9445 | OP *o; |
79072805 LW |
9446 | short *tbl; |
9447 | I32 squash; | |
a0ed51b3 | 9448 | I32 del; |
79072805 LW |
9449 | I32 complement; |
9450 | ||
9451 | yylval.ival = OP_NULL; | |
9452 | ||
09bef843 | 9453 | s = scan_str(start,FALSE,FALSE); |
37fd879b | 9454 | if (!s) |
cea2e8a9 | 9455 | Perl_croak(aTHX_ "Transliteration pattern not terminated"); |
3280af22 | 9456 | if (s[-1] == PL_multi_open) |
2f3197b3 LW |
9457 | s--; |
9458 | ||
09bef843 | 9459 | s = scan_str(s,FALSE,FALSE); |
79072805 | 9460 | if (!s) { |
37fd879b | 9461 | if (PL_lex_stuff) { |
3280af22 | 9462 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
9463 | PL_lex_stuff = Nullsv; |
9464 | } | |
cea2e8a9 | 9465 | Perl_croak(aTHX_ "Transliteration replacement not terminated"); |
a687059c | 9466 | } |
79072805 | 9467 | |
a0ed51b3 | 9468 | complement = del = squash = 0; |
7a1e2023 NC |
9469 | while (1) { |
9470 | switch (*s) { | |
9471 | case 'c': | |
79072805 | 9472 | complement = OPpTRANS_COMPLEMENT; |
7a1e2023 NC |
9473 | break; |
9474 | case 'd': | |
a0ed51b3 | 9475 | del = OPpTRANS_DELETE; |
7a1e2023 NC |
9476 | break; |
9477 | case 's': | |
79072805 | 9478 | squash = OPpTRANS_SQUASH; |
7a1e2023 NC |
9479 | break; |
9480 | default: | |
9481 | goto no_more; | |
9482 | } | |
395c3793 LW |
9483 | s++; |
9484 | } | |
7a1e2023 | 9485 | no_more: |
8973db79 | 9486 | |
a02a5408 | 9487 | Newx(tbl, complement&&!del?258:256, short); |
8973db79 | 9488 | o = newPVOP(OP_TRANS, 0, (char*)tbl); |
59f00321 RGS |
9489 | o->op_private &= ~OPpTRANS_ALL; |
9490 | o->op_private |= del|squash|complement| | |
7948272d NIS |
9491 | (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)| |
9492 | (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0); | |
79072805 | 9493 | |
3280af22 | 9494 | PL_lex_op = o; |
79072805 LW |
9495 | yylval.ival = OP_TRANS; |
9496 | return s; | |
9497 | } | |
9498 | ||
76e3520e | 9499 | STATIC char * |
cea2e8a9 | 9500 | S_scan_heredoc(pTHX_ register char *s) |
79072805 LW |
9501 | { |
9502 | SV *herewas; | |
9503 | I32 op_type = OP_SCALAR; | |
9504 | I32 len; | |
9505 | SV *tmpstr; | |
9506 | char term; | |
73d840c0 AL |
9507 | const char newline[] = "\n"; |
9508 | const char *found_newline; | |
79072805 | 9509 | register char *d; |
fc36a67e | 9510 | register char *e; |
4633a7c4 | 9511 | char *peek; |
f54cb97a | 9512 | const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR)); |
79072805 LW |
9513 | |
9514 | s += 2; | |
3280af22 NIS |
9515 | d = PL_tokenbuf; |
9516 | e = PL_tokenbuf + sizeof PL_tokenbuf - 1; | |
fd2d0953 | 9517 | if (!outer) |
79072805 | 9518 | *d++ = '\n'; |
bf4acbe4 | 9519 | for (peek = s; SPACE_OR_TAB(*peek); peek++) ; |
3792a11b | 9520 | if (*peek == '`' || *peek == '\'' || *peek =='"') { |
4633a7c4 | 9521 | s = peek; |
79072805 | 9522 | term = *s++; |
3280af22 | 9523 | s = delimcpy(d, e, s, PL_bufend, term, &len); |
fc36a67e | 9524 | d += len; |
3280af22 | 9525 | if (s < PL_bufend) |
79072805 | 9526 | s++; |
79072805 LW |
9527 | } |
9528 | else { | |
9529 | if (*s == '\\') | |
9530 | s++, term = '\''; | |
9531 | else | |
9532 | term = '"'; | |
7e2040f0 | 9533 | if (!isALNUM_lazy_if(s,UTF)) |
12bcd1a6 | 9534 | deprecate_old("bare << to mean <<\"\""); |
7e2040f0 | 9535 | for (; isALNUM_lazy_if(s,UTF); s++) { |
fc36a67e | 9536 | if (d < e) |
9537 | *d++ = *s; | |
9538 | } | |
9539 | } | |
3280af22 | 9540 | if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1) |
cea2e8a9 | 9541 | Perl_croak(aTHX_ "Delimiter for here document is too long"); |
79072805 LW |
9542 | *d++ = '\n'; |
9543 | *d = '\0'; | |
3280af22 | 9544 | len = d - PL_tokenbuf; |
6a27c188 | 9545 | #ifndef PERL_STRICT_CR |
f63a84b2 LW |
9546 | d = strchr(s, '\r'); |
9547 | if (d) { | |
b464bac0 | 9548 | char * const olds = s; |
f63a84b2 | 9549 | s = d; |
3280af22 | 9550 | while (s < PL_bufend) { |
f63a84b2 LW |
9551 | if (*s == '\r') { |
9552 | *d++ = '\n'; | |
9553 | if (*++s == '\n') | |
9554 | s++; | |
9555 | } | |
9556 | else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */ | |
9557 | *d++ = *s++; | |
9558 | s++; | |
9559 | } | |
9560 | else | |
9561 | *d++ = *s++; | |
9562 | } | |
9563 | *d = '\0'; | |
3280af22 | 9564 | PL_bufend = d; |
95a20fc0 | 9565 | SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr)); |
f63a84b2 LW |
9566 | s = olds; |
9567 | } | |
9568 | #endif | |
73d840c0 AL |
9569 | if ( outer || !(found_newline = ninstr(s,PL_bufend,newline,newline+1)) ) { |
9570 | herewas = newSVpvn(s,PL_bufend-s); | |
9571 | } | |
9572 | else { | |
9573 | s--; | |
9574 | herewas = newSVpvn(s,found_newline-s); | |
9575 | } | |
79072805 | 9576 | s += SvCUR(herewas); |
748a9306 | 9577 | |
8d6dde3e | 9578 | tmpstr = NEWSV(87,79); |
748a9306 LW |
9579 | sv_upgrade(tmpstr, SVt_PVIV); |
9580 | if (term == '\'') { | |
79072805 | 9581 | op_type = OP_CONST; |
45977657 | 9582 | SvIV_set(tmpstr, -1); |
748a9306 LW |
9583 | } |
9584 | else if (term == '`') { | |
79072805 | 9585 | op_type = OP_BACKTICK; |
45977657 | 9586 | SvIV_set(tmpstr, '\\'); |
748a9306 | 9587 | } |
79072805 LW |
9588 | |
9589 | CLINE; | |
57843af0 | 9590 | PL_multi_start = CopLINE(PL_curcop); |
3280af22 NIS |
9591 | PL_multi_open = PL_multi_close = '<'; |
9592 | term = *PL_tokenbuf; | |
0244c3a4 GS |
9593 | if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) { |
9594 | char *bufptr = PL_sublex_info.super_bufptr; | |
9595 | char *bufend = PL_sublex_info.super_bufend; | |
b464bac0 | 9596 | char * const olds = s - SvCUR(herewas); |
0244c3a4 GS |
9597 | s = strchr(bufptr, '\n'); |
9598 | if (!s) | |
9599 | s = bufend; | |
9600 | d = s; | |
9601 | while (s < bufend && | |
9602 | (*s != term || memNE(s,PL_tokenbuf,len)) ) { | |
9603 | if (*s++ == '\n') | |
57843af0 | 9604 | CopLINE_inc(PL_curcop); |
0244c3a4 GS |
9605 | } |
9606 | if (s >= bufend) { | |
eb160463 | 9607 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
0244c3a4 GS |
9608 | missingterm(PL_tokenbuf); |
9609 | } | |
9610 | sv_setpvn(herewas,bufptr,d-bufptr+1); | |
9611 | sv_setpvn(tmpstr,d+1,s-d); | |
9612 | s += len - 1; | |
9613 | sv_catpvn(herewas,s,bufend-s); | |
95a20fc0 | 9614 | Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char); |
0244c3a4 GS |
9615 | |
9616 | s = olds; | |
9617 | goto retval; | |
9618 | } | |
9619 | else if (!outer) { | |
79072805 | 9620 | d = s; |
3280af22 NIS |
9621 | while (s < PL_bufend && |
9622 | (*s != term || memNE(s,PL_tokenbuf,len)) ) { | |
79072805 | 9623 | if (*s++ == '\n') |
57843af0 | 9624 | CopLINE_inc(PL_curcop); |
79072805 | 9625 | } |
3280af22 | 9626 | if (s >= PL_bufend) { |
eb160463 | 9627 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
3280af22 | 9628 | missingterm(PL_tokenbuf); |
79072805 LW |
9629 | } |
9630 | sv_setpvn(tmpstr,d+1,s-d); | |
9631 | s += len - 1; | |
57843af0 | 9632 | CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */ |
49d8d3a1 | 9633 | |
3280af22 NIS |
9634 | sv_catpvn(herewas,s,PL_bufend-s); |
9635 | sv_setsv(PL_linestr,herewas); | |
9636 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr); | |
9637 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 9638 | PL_last_lop = PL_last_uni = Nullch; |
79072805 LW |
9639 | } |
9640 | else | |
9641 | sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */ | |
3280af22 | 9642 | while (s >= PL_bufend) { /* multiple line string? */ |
fd2d0953 | 9643 | if (!outer || |
3280af22 | 9644 | !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { |
eb160463 | 9645 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
3280af22 | 9646 | missingterm(PL_tokenbuf); |
79072805 | 9647 | } |
57843af0 | 9648 | CopLINE_inc(PL_curcop); |
3280af22 | 9649 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 9650 | PL_last_lop = PL_last_uni = Nullch; |
6a27c188 | 9651 | #ifndef PERL_STRICT_CR |
3280af22 | 9652 | if (PL_bufend - PL_linestart >= 2) { |
a1529941 NIS |
9653 | if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') || |
9654 | (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r')) | |
c6f14548 | 9655 | { |
3280af22 NIS |
9656 | PL_bufend[-2] = '\n'; |
9657 | PL_bufend--; | |
95a20fc0 | 9658 | SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr)); |
f63a84b2 | 9659 | } |
3280af22 NIS |
9660 | else if (PL_bufend[-1] == '\r') |
9661 | PL_bufend[-1] = '\n'; | |
f63a84b2 | 9662 | } |
3280af22 NIS |
9663 | else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r') |
9664 | PL_bufend[-1] = '\n'; | |
f63a84b2 | 9665 | #endif |
3280af22 | 9666 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
79072805 LW |
9667 | SV *sv = NEWSV(88,0); |
9668 | ||
93a17b20 | 9669 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 9670 | sv_setsv(sv,PL_linestr); |
0ac0412a | 9671 | (void)SvIOK_on(sv); |
45977657 | 9672 | SvIV_set(sv, 0); |
57843af0 | 9673 | av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv); |
79072805 | 9674 | } |
3280af22 | 9675 | if (*s == term && memEQ(s,PL_tokenbuf,len)) { |
95a20fc0 | 9676 | STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr); |
1de9afcd | 9677 | *(SvPVX(PL_linestr) + off ) = ' '; |
3280af22 NIS |
9678 | sv_catsv(PL_linestr,herewas); |
9679 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
1de9afcd | 9680 | s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */ |
79072805 LW |
9681 | } |
9682 | else { | |
3280af22 NIS |
9683 | s = PL_bufend; |
9684 | sv_catsv(tmpstr,PL_linestr); | |
395c3793 LW |
9685 | } |
9686 | } | |
79072805 | 9687 | s++; |
0244c3a4 | 9688 | retval: |
57843af0 | 9689 | PL_multi_end = CopLINE(PL_curcop); |
79072805 | 9690 | if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) { |
1da4ca5f | 9691 | SvPV_shrink_to_cur(tmpstr); |
79072805 | 9692 | } |
8990e307 | 9693 | SvREFCNT_dec(herewas); |
2f31ce75 | 9694 | if (!IN_BYTES) { |
95a20fc0 | 9695 | if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr))) |
2f31ce75 JH |
9696 | SvUTF8_on(tmpstr); |
9697 | else if (PL_encoding) | |
9698 | sv_recode_to_utf8(tmpstr, PL_encoding); | |
9699 | } | |
3280af22 | 9700 | PL_lex_stuff = tmpstr; |
79072805 LW |
9701 | yylval.ival = op_type; |
9702 | return s; | |
9703 | } | |
9704 | ||
02aa26ce NT |
9705 | /* scan_inputsymbol |
9706 | takes: current position in input buffer | |
9707 | returns: new position in input buffer | |
9708 | side-effects: yylval and lex_op are set. | |
9709 | ||
9710 | This code handles: | |
9711 | ||
9712 | <> read from ARGV | |
9713 | <FH> read from filehandle | |
9714 | <pkg::FH> read from package qualified filehandle | |
9715 | <pkg'FH> read from package qualified filehandle | |
9716 | <$fh> read from filehandle in $fh | |
9717 | <*.h> filename glob | |
9718 | ||
9719 | */ | |
9720 | ||
76e3520e | 9721 | STATIC char * |
cea2e8a9 | 9722 | S_scan_inputsymbol(pTHX_ char *start) |
79072805 | 9723 | { |
02aa26ce | 9724 | register char *s = start; /* current position in buffer */ |
79072805 | 9725 | register char *d; |
cfd0369c | 9726 | const char *e; |
1b420867 | 9727 | char *end; |
79072805 LW |
9728 | I32 len; |
9729 | ||
3280af22 NIS |
9730 | d = PL_tokenbuf; /* start of temp holding space */ |
9731 | e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */ | |
1b420867 GS |
9732 | end = strchr(s, '\n'); |
9733 | if (!end) | |
9734 | end = PL_bufend; | |
9735 | s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */ | |
02aa26ce NT |
9736 | |
9737 | /* die if we didn't have space for the contents of the <>, | |
1b420867 | 9738 | or if it didn't end, or if we see a newline |
02aa26ce NT |
9739 | */ |
9740 | ||
3280af22 | 9741 | if (len >= sizeof PL_tokenbuf) |
cea2e8a9 | 9742 | Perl_croak(aTHX_ "Excessively long <> operator"); |
1b420867 | 9743 | if (s >= end) |
cea2e8a9 | 9744 | Perl_croak(aTHX_ "Unterminated <> operator"); |
02aa26ce | 9745 | |
fc36a67e | 9746 | s++; |
02aa26ce NT |
9747 | |
9748 | /* check for <$fh> | |
9749 | Remember, only scalar variables are interpreted as filehandles by | |
9750 | this code. Anything more complex (e.g., <$fh{$num}>) will be | |
9751 | treated as a glob() call. | |
9752 | This code makes use of the fact that except for the $ at the front, | |
9753 | a scalar variable and a filehandle look the same. | |
9754 | */ | |
4633a7c4 | 9755 | if (*d == '$' && d[1]) d++; |
02aa26ce NT |
9756 | |
9757 | /* allow <Pkg'VALUE> or <Pkg::VALUE> */ | |
7e2040f0 | 9758 | while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':')) |
79072805 | 9759 | d++; |
02aa26ce NT |
9760 | |
9761 | /* If we've tried to read what we allow filehandles to look like, and | |
9762 | there's still text left, then it must be a glob() and not a getline. | |
9763 | Use scan_str to pull out the stuff between the <> and treat it | |
9764 | as nothing more than a string. | |
9765 | */ | |
9766 | ||
3280af22 | 9767 | if (d - PL_tokenbuf != len) { |
79072805 LW |
9768 | yylval.ival = OP_GLOB; |
9769 | set_csh(); | |
09bef843 | 9770 | s = scan_str(start,FALSE,FALSE); |
79072805 | 9771 | if (!s) |
cea2e8a9 | 9772 | Perl_croak(aTHX_ "Glob not terminated"); |
79072805 LW |
9773 | return s; |
9774 | } | |
395c3793 | 9775 | else { |
9b3023bc RGS |
9776 | bool readline_overriden = FALSE; |
9777 | GV *gv_readline = Nullgv; | |
9778 | GV **gvp; | |
02aa26ce | 9779 | /* we're in a filehandle read situation */ |
3280af22 | 9780 | d = PL_tokenbuf; |
02aa26ce NT |
9781 | |
9782 | /* turn <> into <ARGV> */ | |
79072805 | 9783 | if (!len) |
689badd5 | 9784 | Copy("ARGV",d,5,char); |
02aa26ce | 9785 | |
9b3023bc | 9786 | /* Check whether readline() is overriden */ |
ba979b31 NIS |
9787 | if (((gv_readline = gv_fetchpv("readline", FALSE, SVt_PVCV)) |
9788 | && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)) | |
9b3023bc | 9789 | || |
ba979b31 | 9790 | ((gvp = (GV**)hv_fetch(PL_globalstash, "readline", 8, FALSE)) |
9b3023bc | 9791 | && (gv_readline = *gvp) != (GV*)&PL_sv_undef |
ba979b31 | 9792 | && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))) |
9b3023bc RGS |
9793 | readline_overriden = TRUE; |
9794 | ||
02aa26ce NT |
9795 | /* if <$fh>, create the ops to turn the variable into a |
9796 | filehandle | |
9797 | */ | |
79072805 | 9798 | if (*d == '$') { |
a0d0e21e | 9799 | I32 tmp; |
02aa26ce NT |
9800 | |
9801 | /* try to find it in the pad for this block, otherwise find | |
9802 | add symbol table ops | |
9803 | */ | |
11343788 | 9804 | if ((tmp = pad_findmy(d)) != NOT_IN_PAD) { |
dd2155a4 | 9805 | if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) { |
4b6dd97a NC |
9806 | HV *stash = PAD_COMPNAME_OURSTASH(tmp); |
9807 | HEK *stashname = HvNAME_HEK(stash); | |
5aaec2b4 | 9808 | SV *sym = sv_2mortal(newSVhek(stashname)); |
f558d5af JH |
9809 | sv_catpvn(sym, "::", 2); |
9810 | sv_catpv(sym, d+1); | |
9811 | d = SvPVX(sym); | |
9812 | goto intro_sym; | |
9813 | } | |
9814 | else { | |
9815 | OP *o = newOP(OP_PADSV, 0); | |
9816 | o->op_targ = tmp; | |
9b3023bc RGS |
9817 | PL_lex_op = readline_overriden |
9818 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, | |
9819 | append_elem(OP_LIST, o, | |
9820 | newCVREF(0, newGVOP(OP_GV,0,gv_readline)))) | |
9821 | : (OP*)newUNOP(OP_READLINE, 0, o); | |
f558d5af | 9822 | } |
a0d0e21e LW |
9823 | } |
9824 | else { | |
f558d5af JH |
9825 | GV *gv; |
9826 | ++d; | |
9827 | intro_sym: | |
9828 | gv = gv_fetchpv(d, | |
9829 | (PL_in_eval | |
9830 | ? (GV_ADDMULTI | GV_ADDINEVAL) | |
bea70d1e | 9831 | : GV_ADDMULTI), |
f558d5af | 9832 | SVt_PV); |
9b3023bc RGS |
9833 | PL_lex_op = readline_overriden |
9834 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, | |
9835 | append_elem(OP_LIST, | |
9836 | newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)), | |
9837 | newCVREF(0, newGVOP(OP_GV, 0, gv_readline)))) | |
9838 | : (OP*)newUNOP(OP_READLINE, 0, | |
9839 | newUNOP(OP_RV2SV, 0, | |
9840 | newGVOP(OP_GV, 0, gv))); | |
a0d0e21e | 9841 | } |
7c6fadd6 RGS |
9842 | if (!readline_overriden) |
9843 | PL_lex_op->op_flags |= OPf_SPECIAL; | |
f5284f61 | 9844 | /* we created the ops in PL_lex_op, so make yylval.ival a null op */ |
79072805 LW |
9845 | yylval.ival = OP_NULL; |
9846 | } | |
02aa26ce NT |
9847 | |
9848 | /* If it's none of the above, it must be a literal filehandle | |
9849 | (<Foo::BAR> or <FOO>) so build a simple readline OP */ | |
79072805 | 9850 | else { |
85e6fe83 | 9851 | GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO); |
9b3023bc RGS |
9852 | PL_lex_op = readline_overriden |
9853 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, | |
9854 | append_elem(OP_LIST, | |
9855 | newGVOP(OP_GV, 0, gv), | |
9856 | newCVREF(0, newGVOP(OP_GV, 0, gv_readline)))) | |
9857 | : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv)); | |
79072805 LW |
9858 | yylval.ival = OP_NULL; |
9859 | } | |
9860 | } | |
02aa26ce | 9861 | |
79072805 LW |
9862 | return s; |
9863 | } | |
9864 | ||
02aa26ce NT |
9865 | |
9866 | /* scan_str | |
9867 | takes: start position in buffer | |
09bef843 SB |
9868 | keep_quoted preserve \ on the embedded delimiter(s) |
9869 | keep_delims preserve the delimiters around the string | |
02aa26ce NT |
9870 | returns: position to continue reading from buffer |
9871 | side-effects: multi_start, multi_close, lex_repl or lex_stuff, and | |
9872 | updates the read buffer. | |
9873 | ||
9874 | This subroutine pulls a string out of the input. It is called for: | |
9875 | q single quotes q(literal text) | |
9876 | ' single quotes 'literal text' | |
9877 | qq double quotes qq(interpolate $here please) | |
9878 | " double quotes "interpolate $here please" | |
9879 | qx backticks qx(/bin/ls -l) | |
9880 | ` backticks `/bin/ls -l` | |
9881 | qw quote words @EXPORT_OK = qw( func() $spam ) | |
9882 | m// regexp match m/this/ | |
9883 | s/// regexp substitute s/this/that/ | |
9884 | tr/// string transliterate tr/this/that/ | |
9885 | y/// string transliterate y/this/that/ | |
9886 | ($*@) sub prototypes sub foo ($) | |
09bef843 | 9887 | (stuff) sub attr parameters sub foo : attr(stuff) |
02aa26ce NT |
9888 | <> readline or globs <FOO>, <>, <$fh>, or <*.c> |
9889 | ||
9890 | In most of these cases (all but <>, patterns and transliterate) | |
9891 | yylex() calls scan_str(). m// makes yylex() call scan_pat() which | |
9892 | calls scan_str(). s/// makes yylex() call scan_subst() which calls | |
9893 | scan_str(). tr/// and y/// make yylex() call scan_trans() which | |
9894 | calls scan_str(). | |
4e553d73 | 9895 | |
02aa26ce NT |
9896 | It skips whitespace before the string starts, and treats the first |
9897 | character as the delimiter. If the delimiter is one of ([{< then | |
9898 | the corresponding "close" character )]}> is used as the closing | |
9899 | delimiter. It allows quoting of delimiters, and if the string has | |
9900 | balanced delimiters ([{<>}]) it allows nesting. | |
9901 | ||
37fd879b HS |
9902 | On success, the SV with the resulting string is put into lex_stuff or, |
9903 | if that is already non-NULL, into lex_repl. The second case occurs only | |
9904 | when parsing the RHS of the special constructs s/// and tr/// (y///). | |
9905 | For convenience, the terminating delimiter character is stuffed into | |
9906 | SvIVX of the SV. | |
02aa26ce NT |
9907 | */ |
9908 | ||
76e3520e | 9909 | STATIC char * |
09bef843 | 9910 | S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims) |
79072805 | 9911 | { |
02aa26ce NT |
9912 | SV *sv; /* scalar value: string */ |
9913 | char *tmps; /* temp string, used for delimiter matching */ | |
9914 | register char *s = start; /* current position in the buffer */ | |
9915 | register char term; /* terminating character */ | |
9916 | register char *to; /* current position in the sv's data */ | |
9917 | I32 brackets = 1; /* bracket nesting level */ | |
89491803 | 9918 | bool has_utf8 = FALSE; /* is there any utf8 content? */ |
220e2d4e | 9919 | I32 termcode; /* terminating char. code */ |
89ebb4a3 | 9920 | U8 termstr[UTF8_MAXBYTES]; /* terminating string */ |
220e2d4e IH |
9921 | STRLEN termlen; /* length of terminating string */ |
9922 | char *last = NULL; /* last position for nesting bracket */ | |
02aa26ce NT |
9923 | |
9924 | /* skip space before the delimiter */ | |
fb73857a | 9925 | if (isSPACE(*s)) |
9926 | s = skipspace(s); | |
02aa26ce NT |
9927 | |
9928 | /* mark where we are, in case we need to report errors */ | |
79072805 | 9929 | CLINE; |
02aa26ce NT |
9930 | |
9931 | /* after skipping whitespace, the next character is the terminator */ | |
a0d0e21e | 9932 | term = *s; |
220e2d4e IH |
9933 | if (!UTF) { |
9934 | termcode = termstr[0] = term; | |
9935 | termlen = 1; | |
9936 | } | |
9937 | else { | |
f3b9ce0f | 9938 | termcode = utf8_to_uvchr((U8*)s, &termlen); |
220e2d4e IH |
9939 | Copy(s, termstr, termlen, U8); |
9940 | if (!UTF8_IS_INVARIANT(term)) | |
9941 | has_utf8 = TRUE; | |
9942 | } | |
b1c7b182 | 9943 | |
02aa26ce | 9944 | /* mark where we are */ |
57843af0 | 9945 | PL_multi_start = CopLINE(PL_curcop); |
3280af22 | 9946 | PL_multi_open = term; |
02aa26ce NT |
9947 | |
9948 | /* find corresponding closing delimiter */ | |
93a17b20 | 9949 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) |
220e2d4e IH |
9950 | termcode = termstr[0] = term = tmps[5]; |
9951 | ||
3280af22 | 9952 | PL_multi_close = term; |
79072805 | 9953 | |
02aa26ce | 9954 | /* create a new SV to hold the contents. 87 is leak category, I'm |
8d6dde3e IZ |
9955 | assuming. 79 is the SV's initial length. What a random number. */ |
9956 | sv = NEWSV(87,79); | |
ed6116ce | 9957 | sv_upgrade(sv, SVt_PVIV); |
45977657 | 9958 | SvIV_set(sv, termcode); |
a0d0e21e | 9959 | (void)SvPOK_only(sv); /* validate pointer */ |
02aa26ce NT |
9960 | |
9961 | /* move past delimiter and try to read a complete string */ | |
09bef843 | 9962 | if (keep_delims) |
220e2d4e IH |
9963 | sv_catpvn(sv, s, termlen); |
9964 | s += termlen; | |
93a17b20 | 9965 | for (;;) { |
220e2d4e IH |
9966 | if (PL_encoding && !UTF) { |
9967 | bool cont = TRUE; | |
9968 | ||
9969 | while (cont) { | |
95a20fc0 | 9970 | int offset = s - SvPVX_const(PL_linestr); |
66a1b24b | 9971 | const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr, |
f3b9ce0f | 9972 | &offset, (char*)termstr, termlen); |
95a20fc0 | 9973 | const char *ns = SvPVX_const(PL_linestr) + offset; |
220e2d4e IH |
9974 | char *svlast = SvEND(sv) - 1; |
9975 | ||
9976 | for (; s < ns; s++) { | |
9977 | if (*s == '\n' && !PL_rsfp) | |
9978 | CopLINE_inc(PL_curcop); | |
9979 | } | |
9980 | if (!found) | |
9981 | goto read_more_line; | |
9982 | else { | |
9983 | /* handle quoted delimiters */ | |
52327caf | 9984 | if (SvCUR(sv) > 1 && *(svlast-1) == '\\') { |
f54cb97a | 9985 | const char *t; |
95a20fc0 | 9986 | for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';) |
220e2d4e IH |
9987 | t--; |
9988 | if ((svlast-1 - t) % 2) { | |
9989 | if (!keep_quoted) { | |
9990 | *(svlast-1) = term; | |
9991 | *svlast = '\0'; | |
9992 | SvCUR_set(sv, SvCUR(sv) - 1); | |
9993 | } | |
9994 | continue; | |
9995 | } | |
9996 | } | |
9997 | if (PL_multi_open == PL_multi_close) { | |
9998 | cont = FALSE; | |
9999 | } | |
10000 | else { | |
f54cb97a AL |
10001 | const char *t; |
10002 | char *w; | |
220e2d4e IH |
10003 | if (!last) |
10004 | last = SvPVX(sv); | |
f54cb97a | 10005 | for (t = w = last; t < svlast; w++, t++) { |
220e2d4e IH |
10006 | /* At here, all closes are "was quoted" one, |
10007 | so we don't check PL_multi_close. */ | |
10008 | if (*t == '\\') { | |
10009 | if (!keep_quoted && *(t+1) == PL_multi_open) | |
10010 | t++; | |
10011 | else | |
10012 | *w++ = *t++; | |
10013 | } | |
10014 | else if (*t == PL_multi_open) | |
10015 | brackets++; | |
10016 | ||
10017 | *w = *t; | |
10018 | } | |
10019 | if (w < t) { | |
10020 | *w++ = term; | |
10021 | *w = '\0'; | |
95a20fc0 | 10022 | SvCUR_set(sv, w - SvPVX_const(sv)); |
220e2d4e IH |
10023 | } |
10024 | last = w; | |
10025 | if (--brackets <= 0) | |
10026 | cont = FALSE; | |
10027 | } | |
10028 | } | |
10029 | } | |
10030 | if (!keep_delims) { | |
10031 | SvCUR_set(sv, SvCUR(sv) - 1); | |
10032 | *SvEND(sv) = '\0'; | |
10033 | } | |
10034 | break; | |
10035 | } | |
10036 | ||
02aa26ce | 10037 | /* extend sv if need be */ |
3280af22 | 10038 | SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1); |
02aa26ce | 10039 | /* set 'to' to the next character in the sv's string */ |
463ee0b2 | 10040 | to = SvPVX(sv)+SvCUR(sv); |
09bef843 | 10041 | |
02aa26ce | 10042 | /* if open delimiter is the close delimiter read unbridle */ |
3280af22 NIS |
10043 | if (PL_multi_open == PL_multi_close) { |
10044 | for (; s < PL_bufend; s++,to++) { | |
02aa26ce | 10045 | /* embedded newlines increment the current line number */ |
3280af22 | 10046 | if (*s == '\n' && !PL_rsfp) |
57843af0 | 10047 | CopLINE_inc(PL_curcop); |
02aa26ce | 10048 | /* handle quoted delimiters */ |
3280af22 | 10049 | if (*s == '\\' && s+1 < PL_bufend && term != '\\') { |
09bef843 | 10050 | if (!keep_quoted && s[1] == term) |
a0d0e21e | 10051 | s++; |
02aa26ce | 10052 | /* any other quotes are simply copied straight through */ |
a0d0e21e LW |
10053 | else |
10054 | *to++ = *s++; | |
10055 | } | |
02aa26ce NT |
10056 | /* terminate when run out of buffer (the for() condition), or |
10057 | have found the terminator */ | |
220e2d4e IH |
10058 | else if (*s == term) { |
10059 | if (termlen == 1) | |
10060 | break; | |
f3b9ce0f | 10061 | if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen)) |
220e2d4e IH |
10062 | break; |
10063 | } | |
63cd0674 | 10064 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
89491803 | 10065 | has_utf8 = TRUE; |
93a17b20 LW |
10066 | *to = *s; |
10067 | } | |
10068 | } | |
02aa26ce NT |
10069 | |
10070 | /* if the terminator isn't the same as the start character (e.g., | |
10071 | matched brackets), we have to allow more in the quoting, and | |
10072 | be prepared for nested brackets. | |
10073 | */ | |
93a17b20 | 10074 | else { |
02aa26ce | 10075 | /* read until we run out of string, or we find the terminator */ |
3280af22 | 10076 | for (; s < PL_bufend; s++,to++) { |
02aa26ce | 10077 | /* embedded newlines increment the line count */ |
3280af22 | 10078 | if (*s == '\n' && !PL_rsfp) |
57843af0 | 10079 | CopLINE_inc(PL_curcop); |
02aa26ce | 10080 | /* backslashes can escape the open or closing characters */ |
3280af22 | 10081 | if (*s == '\\' && s+1 < PL_bufend) { |
09bef843 SB |
10082 | if (!keep_quoted && |
10083 | ((s[1] == PL_multi_open) || (s[1] == PL_multi_close))) | |
a0d0e21e LW |
10084 | s++; |
10085 | else | |
10086 | *to++ = *s++; | |
10087 | } | |
02aa26ce | 10088 | /* allow nested opens and closes */ |
3280af22 | 10089 | else if (*s == PL_multi_close && --brackets <= 0) |
93a17b20 | 10090 | break; |
3280af22 | 10091 | else if (*s == PL_multi_open) |
93a17b20 | 10092 | brackets++; |
63cd0674 | 10093 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
89491803 | 10094 | has_utf8 = TRUE; |
93a17b20 LW |
10095 | *to = *s; |
10096 | } | |
10097 | } | |
02aa26ce | 10098 | /* terminate the copied string and update the sv's end-of-string */ |
93a17b20 | 10099 | *to = '\0'; |
95a20fc0 | 10100 | SvCUR_set(sv, to - SvPVX_const(sv)); |
93a17b20 | 10101 | |
02aa26ce NT |
10102 | /* |
10103 | * this next chunk reads more into the buffer if we're not done yet | |
10104 | */ | |
10105 | ||
b1c7b182 GS |
10106 | if (s < PL_bufend) |
10107 | break; /* handle case where we are done yet :-) */ | |
79072805 | 10108 | |
6a27c188 | 10109 | #ifndef PERL_STRICT_CR |
95a20fc0 | 10110 | if (to - SvPVX_const(sv) >= 2) { |
c6f14548 GS |
10111 | if ((to[-2] == '\r' && to[-1] == '\n') || |
10112 | (to[-2] == '\n' && to[-1] == '\r')) | |
10113 | { | |
f63a84b2 LW |
10114 | to[-2] = '\n'; |
10115 | to--; | |
95a20fc0 | 10116 | SvCUR_set(sv, to - SvPVX_const(sv)); |
f63a84b2 LW |
10117 | } |
10118 | else if (to[-1] == '\r') | |
10119 | to[-1] = '\n'; | |
10120 | } | |
95a20fc0 | 10121 | else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r') |
f63a84b2 LW |
10122 | to[-1] = '\n'; |
10123 | #endif | |
10124 | ||
220e2d4e | 10125 | read_more_line: |
02aa26ce NT |
10126 | /* if we're out of file, or a read fails, bail and reset the current |
10127 | line marker so we can report where the unterminated string began | |
10128 | */ | |
3280af22 NIS |
10129 | if (!PL_rsfp || |
10130 | !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { | |
c07a80fd | 10131 | sv_free(sv); |
eb160463 | 10132 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
79072805 LW |
10133 | return Nullch; |
10134 | } | |
02aa26ce | 10135 | /* we read a line, so increment our line counter */ |
57843af0 | 10136 | CopLINE_inc(PL_curcop); |
a0ed51b3 | 10137 | |
02aa26ce | 10138 | /* update debugger info */ |
3280af22 | 10139 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
79072805 LW |
10140 | SV *sv = NEWSV(88,0); |
10141 | ||
93a17b20 | 10142 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 10143 | sv_setsv(sv,PL_linestr); |
0ac0412a | 10144 | (void)SvIOK_on(sv); |
45977657 | 10145 | SvIV_set(sv, 0); |
57843af0 | 10146 | av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv); |
395c3793 | 10147 | } |
a0ed51b3 | 10148 | |
3280af22 NIS |
10149 | /* having changed the buffer, we must update PL_bufend */ |
10150 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 10151 | PL_last_lop = PL_last_uni = Nullch; |
378cc40b | 10152 | } |
4e553d73 | 10153 | |
02aa26ce NT |
10154 | /* at this point, we have successfully read the delimited string */ |
10155 | ||
220e2d4e IH |
10156 | if (!PL_encoding || UTF) { |
10157 | if (keep_delims) | |
10158 | sv_catpvn(sv, s, termlen); | |
10159 | s += termlen; | |
10160 | } | |
10161 | if (has_utf8 || PL_encoding) | |
b1c7b182 | 10162 | SvUTF8_on(sv); |
d0063567 | 10163 | |
57843af0 | 10164 | PL_multi_end = CopLINE(PL_curcop); |
02aa26ce NT |
10165 | |
10166 | /* if we allocated too much space, give some back */ | |
93a17b20 LW |
10167 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
10168 | SvLEN_set(sv, SvCUR(sv) + 1); | |
b7e9a5c2 | 10169 | SvPV_renew(sv, SvLEN(sv)); |
79072805 | 10170 | } |
02aa26ce NT |
10171 | |
10172 | /* decide whether this is the first or second quoted string we've read | |
10173 | for this op | |
10174 | */ | |
4e553d73 | 10175 | |
3280af22 NIS |
10176 | if (PL_lex_stuff) |
10177 | PL_lex_repl = sv; | |
79072805 | 10178 | else |
3280af22 | 10179 | PL_lex_stuff = sv; |
378cc40b LW |
10180 | return s; |
10181 | } | |
10182 | ||
02aa26ce NT |
10183 | /* |
10184 | scan_num | |
10185 | takes: pointer to position in buffer | |
10186 | returns: pointer to new position in buffer | |
10187 | side-effects: builds ops for the constant in yylval.op | |
10188 | ||
10189 | Read a number in any of the formats that Perl accepts: | |
10190 | ||
7fd134d9 JH |
10191 | \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12. |
10192 | \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34 | |
24138b49 JH |
10193 | 0b[01](_?[01])* |
10194 | 0[0-7](_?[0-7])* | |
10195 | 0x[0-9A-Fa-f](_?[0-9A-Fa-f])* | |
02aa26ce | 10196 | |
3280af22 | 10197 | Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the |
02aa26ce NT |
10198 | thing it reads. |
10199 | ||
10200 | If it reads a number without a decimal point or an exponent, it will | |
10201 | try converting the number to an integer and see if it can do so | |
10202 | without loss of precision. | |
10203 | */ | |
4e553d73 | 10204 | |
378cc40b | 10205 | char * |
bfed75c6 | 10206 | Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp) |
378cc40b | 10207 | { |
bfed75c6 | 10208 | register const char *s = start; /* current position in buffer */ |
02aa26ce NT |
10209 | register char *d; /* destination in temp buffer */ |
10210 | register char *e; /* end of temp buffer */ | |
86554af2 | 10211 | NV nv; /* number read, as a double */ |
a7cb1f99 | 10212 | SV *sv = Nullsv; /* place to put the converted number */ |
a86a20aa | 10213 | bool floatit; /* boolean: int or float? */ |
bfed75c6 AL |
10214 | const char *lastub = 0; /* position of last underbar */ |
10215 | static char const number_too_long[] = "Number too long"; | |
378cc40b | 10216 | |
02aa26ce NT |
10217 | /* We use the first character to decide what type of number this is */ |
10218 | ||
378cc40b | 10219 | switch (*s) { |
79072805 | 10220 | default: |
cea2e8a9 | 10221 | Perl_croak(aTHX_ "panic: scan_num"); |
4e553d73 | 10222 | |
02aa26ce | 10223 | /* if it starts with a 0, it could be an octal number, a decimal in |
a7cb1f99 | 10224 | 0.13 disguise, or a hexadecimal number, or a binary number. */ |
378cc40b LW |
10225 | case '0': |
10226 | { | |
02aa26ce NT |
10227 | /* variables: |
10228 | u holds the "number so far" | |
4f19785b WSI |
10229 | shift the power of 2 of the base |
10230 | (hex == 4, octal == 3, binary == 1) | |
02aa26ce NT |
10231 | overflowed was the number more than we can hold? |
10232 | ||
10233 | Shift is used when we add a digit. It also serves as an "are | |
4f19785b WSI |
10234 | we in octal/hex/binary?" indicator to disallow hex characters |
10235 | when in octal mode. | |
02aa26ce | 10236 | */ |
9e24b6e2 JH |
10237 | NV n = 0.0; |
10238 | UV u = 0; | |
79072805 | 10239 | I32 shift; |
9e24b6e2 | 10240 | bool overflowed = FALSE; |
61f33854 | 10241 | bool just_zero = TRUE; /* just plain 0 or binary number? */ |
27da23d5 JH |
10242 | static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 }; |
10243 | static const char* const bases[5] = | |
10244 | { "", "binary", "", "octal", "hexadecimal" }; | |
10245 | static const char* const Bases[5] = | |
10246 | { "", "Binary", "", "Octal", "Hexadecimal" }; | |
10247 | static const char* const maxima[5] = | |
10248 | { "", | |
10249 | "0b11111111111111111111111111111111", | |
10250 | "", | |
10251 | "037777777777", | |
10252 | "0xffffffff" }; | |
bfed75c6 | 10253 | const char *base, *Base, *max; |
378cc40b | 10254 | |
02aa26ce | 10255 | /* check for hex */ |
378cc40b LW |
10256 | if (s[1] == 'x') { |
10257 | shift = 4; | |
10258 | s += 2; | |
61f33854 | 10259 | just_zero = FALSE; |
4f19785b WSI |
10260 | } else if (s[1] == 'b') { |
10261 | shift = 1; | |
10262 | s += 2; | |
61f33854 | 10263 | just_zero = FALSE; |
378cc40b | 10264 | } |
02aa26ce | 10265 | /* check for a decimal in disguise */ |
b78218b7 | 10266 | else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E') |
378cc40b | 10267 | goto decimal; |
02aa26ce | 10268 | /* so it must be octal */ |
928753ea | 10269 | else { |
378cc40b | 10270 | shift = 3; |
928753ea JH |
10271 | s++; |
10272 | } | |
10273 | ||
10274 | if (*s == '_') { | |
10275 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10276 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10277 | "Misplaced _ in number"); |
10278 | lastub = s++; | |
10279 | } | |
9e24b6e2 JH |
10280 | |
10281 | base = bases[shift]; | |
10282 | Base = Bases[shift]; | |
10283 | max = maxima[shift]; | |
02aa26ce | 10284 | |
4f19785b | 10285 | /* read the rest of the number */ |
378cc40b | 10286 | for (;;) { |
9e24b6e2 | 10287 | /* x is used in the overflow test, |
893fe2c2 | 10288 | b is the digit we're adding on. */ |
9e24b6e2 | 10289 | UV x, b; |
55497cff | 10290 | |
378cc40b | 10291 | switch (*s) { |
02aa26ce NT |
10292 | |
10293 | /* if we don't mention it, we're done */ | |
378cc40b LW |
10294 | default: |
10295 | goto out; | |
02aa26ce | 10296 | |
928753ea | 10297 | /* _ are ignored -- but warned about if consecutive */ |
de3bb511 | 10298 | case '_': |
041457d9 | 10299 | if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX)) |
9014280d | 10300 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10301 | "Misplaced _ in number"); |
10302 | lastub = s++; | |
de3bb511 | 10303 | break; |
02aa26ce NT |
10304 | |
10305 | /* 8 and 9 are not octal */ | |
378cc40b | 10306 | case '8': case '9': |
4f19785b | 10307 | if (shift == 3) |
cea2e8a9 | 10308 | yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s)); |
378cc40b | 10309 | /* FALL THROUGH */ |
02aa26ce NT |
10310 | |
10311 | /* octal digits */ | |
4f19785b | 10312 | case '2': case '3': case '4': |
378cc40b | 10313 | case '5': case '6': case '7': |
4f19785b | 10314 | if (shift == 1) |
cea2e8a9 | 10315 | yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s)); |
4f19785b WSI |
10316 | /* FALL THROUGH */ |
10317 | ||
10318 | case '0': case '1': | |
02aa26ce | 10319 | b = *s++ & 15; /* ASCII digit -> value of digit */ |
55497cff | 10320 | goto digit; |
02aa26ce NT |
10321 | |
10322 | /* hex digits */ | |
378cc40b LW |
10323 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': |
10324 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': | |
02aa26ce | 10325 | /* make sure they said 0x */ |
378cc40b LW |
10326 | if (shift != 4) |
10327 | goto out; | |
55497cff | 10328 | b = (*s++ & 7) + 9; |
02aa26ce NT |
10329 | |
10330 | /* Prepare to put the digit we have onto the end | |
10331 | of the number so far. We check for overflows. | |
10332 | */ | |
10333 | ||
55497cff | 10334 | digit: |
61f33854 | 10335 | just_zero = FALSE; |
9e24b6e2 JH |
10336 | if (!overflowed) { |
10337 | x = u << shift; /* make room for the digit */ | |
10338 | ||
10339 | if ((x >> shift) != u | |
10340 | && !(PL_hints & HINT_NEW_BINARY)) { | |
9e24b6e2 JH |
10341 | overflowed = TRUE; |
10342 | n = (NV) u; | |
767a6a26 | 10343 | if (ckWARN_d(WARN_OVERFLOW)) |
9014280d | 10344 | Perl_warner(aTHX_ packWARN(WARN_OVERFLOW), |
9e24b6e2 JH |
10345 | "Integer overflow in %s number", |
10346 | base); | |
10347 | } else | |
10348 | u = x | b; /* add the digit to the end */ | |
10349 | } | |
10350 | if (overflowed) { | |
10351 | n *= nvshift[shift]; | |
10352 | /* If an NV has not enough bits in its | |
10353 | * mantissa to represent an UV this summing of | |
10354 | * small low-order numbers is a waste of time | |
10355 | * (because the NV cannot preserve the | |
10356 | * low-order bits anyway): we could just | |
10357 | * remember when did we overflow and in the | |
10358 | * end just multiply n by the right | |
10359 | * amount. */ | |
10360 | n += (NV) b; | |
55497cff | 10361 | } |
378cc40b LW |
10362 | break; |
10363 | } | |
10364 | } | |
02aa26ce NT |
10365 | |
10366 | /* if we get here, we had success: make a scalar value from | |
10367 | the number. | |
10368 | */ | |
378cc40b | 10369 | out: |
928753ea JH |
10370 | |
10371 | /* final misplaced underbar check */ | |
10372 | if (s[-1] == '_') { | |
10373 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10374 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number"); |
928753ea JH |
10375 | } |
10376 | ||
79072805 | 10377 | sv = NEWSV(92,0); |
9e24b6e2 | 10378 | if (overflowed) { |
041457d9 | 10379 | if (n > 4294967295.0 && ckWARN(WARN_PORTABLE)) |
9014280d | 10380 | Perl_warner(aTHX_ packWARN(WARN_PORTABLE), |
9e24b6e2 JH |
10381 | "%s number > %s non-portable", |
10382 | Base, max); | |
10383 | sv_setnv(sv, n); | |
10384 | } | |
10385 | else { | |
15041a67 | 10386 | #if UVSIZE > 4 |
041457d9 | 10387 | if (u > 0xffffffff && ckWARN(WARN_PORTABLE)) |
9014280d | 10388 | Perl_warner(aTHX_ packWARN(WARN_PORTABLE), |
9e24b6e2 JH |
10389 | "%s number > %s non-portable", |
10390 | Base, max); | |
2cc4c2dc | 10391 | #endif |
9e24b6e2 JH |
10392 | sv_setuv(sv, u); |
10393 | } | |
61f33854 | 10394 | if (just_zero && (PL_hints & HINT_NEW_INTEGER)) |
bfed75c6 | 10395 | sv = new_constant(start, s - start, "integer", |
61f33854 RGS |
10396 | sv, Nullsv, NULL); |
10397 | else if (PL_hints & HINT_NEW_BINARY) | |
b3ac6de7 | 10398 | sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL); |
378cc40b LW |
10399 | } |
10400 | break; | |
02aa26ce NT |
10401 | |
10402 | /* | |
10403 | handle decimal numbers. | |
10404 | we're also sent here when we read a 0 as the first digit | |
10405 | */ | |
378cc40b LW |
10406 | case '1': case '2': case '3': case '4': case '5': |
10407 | case '6': case '7': case '8': case '9': case '.': | |
10408 | decimal: | |
3280af22 NIS |
10409 | d = PL_tokenbuf; |
10410 | e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */ | |
79072805 | 10411 | floatit = FALSE; |
02aa26ce NT |
10412 | |
10413 | /* read next group of digits and _ and copy into d */ | |
de3bb511 | 10414 | while (isDIGIT(*s) || *s == '_') { |
4e553d73 | 10415 | /* skip underscores, checking for misplaced ones |
02aa26ce NT |
10416 | if -w is on |
10417 | */ | |
93a17b20 | 10418 | if (*s == '_') { |
041457d9 | 10419 | if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX)) |
9014280d | 10420 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10421 | "Misplaced _ in number"); |
10422 | lastub = s++; | |
93a17b20 | 10423 | } |
fc36a67e | 10424 | else { |
02aa26ce | 10425 | /* check for end of fixed-length buffer */ |
fc36a67e | 10426 | if (d >= e) |
cea2e8a9 | 10427 | Perl_croak(aTHX_ number_too_long); |
02aa26ce | 10428 | /* if we're ok, copy the character */ |
378cc40b | 10429 | *d++ = *s++; |
fc36a67e | 10430 | } |
378cc40b | 10431 | } |
02aa26ce NT |
10432 | |
10433 | /* final misplaced underbar check */ | |
928753ea | 10434 | if (lastub && s == lastub + 1) { |
d008e5eb | 10435 | if (ckWARN(WARN_SYNTAX)) |
9014280d | 10436 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number"); |
d008e5eb | 10437 | } |
02aa26ce NT |
10438 | |
10439 | /* read a decimal portion if there is one. avoid | |
10440 | 3..5 being interpreted as the number 3. followed | |
10441 | by .5 | |
10442 | */ | |
2f3197b3 | 10443 | if (*s == '.' && s[1] != '.') { |
79072805 | 10444 | floatit = TRUE; |
378cc40b | 10445 | *d++ = *s++; |
02aa26ce | 10446 | |
928753ea JH |
10447 | if (*s == '_') { |
10448 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10449 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10450 | "Misplaced _ in number"); |
10451 | lastub = s; | |
10452 | } | |
10453 | ||
10454 | /* copy, ignoring underbars, until we run out of digits. | |
02aa26ce | 10455 | */ |
fc36a67e | 10456 | for (; isDIGIT(*s) || *s == '_'; s++) { |
02aa26ce | 10457 | /* fixed length buffer check */ |
fc36a67e | 10458 | if (d >= e) |
cea2e8a9 | 10459 | Perl_croak(aTHX_ number_too_long); |
928753ea | 10460 | if (*s == '_') { |
041457d9 | 10461 | if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX)) |
9014280d | 10462 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10463 | "Misplaced _ in number"); |
10464 | lastub = s; | |
10465 | } | |
10466 | else | |
fc36a67e | 10467 | *d++ = *s; |
378cc40b | 10468 | } |
928753ea JH |
10469 | /* fractional part ending in underbar? */ |
10470 | if (s[-1] == '_') { | |
10471 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10472 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10473 | "Misplaced _ in number"); |
10474 | } | |
dd629d5b GS |
10475 | if (*s == '.' && isDIGIT(s[1])) { |
10476 | /* oops, it's really a v-string, but without the "v" */ | |
f4758303 | 10477 | s = start; |
dd629d5b GS |
10478 | goto vstring; |
10479 | } | |
378cc40b | 10480 | } |
02aa26ce NT |
10481 | |
10482 | /* read exponent part, if present */ | |
3792a11b | 10483 | if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) { |
79072805 LW |
10484 | floatit = TRUE; |
10485 | s++; | |
02aa26ce NT |
10486 | |
10487 | /* regardless of whether user said 3E5 or 3e5, use lower 'e' */ | |
79072805 | 10488 | *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */ |
02aa26ce | 10489 | |
7fd134d9 JH |
10490 | /* stray preinitial _ */ |
10491 | if (*s == '_') { | |
10492 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10493 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
7fd134d9 JH |
10494 | "Misplaced _ in number"); |
10495 | lastub = s++; | |
10496 | } | |
10497 | ||
02aa26ce | 10498 | /* allow positive or negative exponent */ |
378cc40b LW |
10499 | if (*s == '+' || *s == '-') |
10500 | *d++ = *s++; | |
02aa26ce | 10501 | |
7fd134d9 JH |
10502 | /* stray initial _ */ |
10503 | if (*s == '_') { | |
10504 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10505 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
7fd134d9 JH |
10506 | "Misplaced _ in number"); |
10507 | lastub = s++; | |
10508 | } | |
10509 | ||
7fd134d9 JH |
10510 | /* read digits of exponent */ |
10511 | while (isDIGIT(*s) || *s == '_') { | |
10512 | if (isDIGIT(*s)) { | |
10513 | if (d >= e) | |
10514 | Perl_croak(aTHX_ number_too_long); | |
b3b48e3e | 10515 | *d++ = *s++; |
7fd134d9 JH |
10516 | } |
10517 | else { | |
041457d9 DM |
10518 | if (((lastub && s == lastub + 1) || |
10519 | (!isDIGIT(s[1]) && s[1] != '_')) | |
10520 | && ckWARN(WARN_SYNTAX)) | |
9014280d | 10521 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
7fd134d9 | 10522 | "Misplaced _ in number"); |
b3b48e3e | 10523 | lastub = s++; |
7fd134d9 | 10524 | } |
7fd134d9 | 10525 | } |
378cc40b | 10526 | } |
02aa26ce | 10527 | |
02aa26ce NT |
10528 | |
10529 | /* make an sv from the string */ | |
79072805 | 10530 | sv = NEWSV(92,0); |
097ee67d | 10531 | |
0b7fceb9 | 10532 | /* |
58bb9ec3 NC |
10533 | We try to do an integer conversion first if no characters |
10534 | indicating "float" have been found. | |
0b7fceb9 MU |
10535 | */ |
10536 | ||
10537 | if (!floatit) { | |
58bb9ec3 NC |
10538 | UV uv; |
10539 | int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv); | |
10540 | ||
10541 | if (flags == IS_NUMBER_IN_UV) { | |
10542 | if (uv <= IV_MAX) | |
86554af2 | 10543 | sv_setiv(sv, uv); /* Prefer IVs over UVs. */ |
58bb9ec3 | 10544 | else |
c239479b | 10545 | sv_setuv(sv, uv); |
58bb9ec3 NC |
10546 | } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) { |
10547 | if (uv <= (UV) IV_MIN) | |
10548 | sv_setiv(sv, -(IV)uv); | |
10549 | else | |
10550 | floatit = TRUE; | |
10551 | } else | |
10552 | floatit = TRUE; | |
10553 | } | |
0b7fceb9 | 10554 | if (floatit) { |
58bb9ec3 NC |
10555 | /* terminate the string */ |
10556 | *d = '\0'; | |
86554af2 JH |
10557 | nv = Atof(PL_tokenbuf); |
10558 | sv_setnv(sv, nv); | |
10559 | } | |
86554af2 | 10560 | |
b8403495 JH |
10561 | if ( floatit ? (PL_hints & HINT_NEW_FLOAT) : |
10562 | (PL_hints & HINT_NEW_INTEGER) ) | |
4e553d73 | 10563 | sv = new_constant(PL_tokenbuf, d - PL_tokenbuf, |
b8403495 JH |
10564 | (floatit ? "float" : "integer"), |
10565 | sv, Nullsv, NULL); | |
378cc40b | 10566 | break; |
0b7fceb9 | 10567 | |
e312add1 | 10568 | /* if it starts with a v, it could be a v-string */ |
a7cb1f99 | 10569 | case 'v': |
dd629d5b | 10570 | vstring: |
f4758303 | 10571 | sv = NEWSV(92,5); /* preallocate storage space */ |
b0f01acb | 10572 | s = scan_vstring(s,sv); |
a7cb1f99 | 10573 | break; |
79072805 | 10574 | } |
a687059c | 10575 | |
02aa26ce NT |
10576 | /* make the op for the constant and return */ |
10577 | ||
a86a20aa | 10578 | if (sv) |
b73d6f50 | 10579 | lvalp->opval = newSVOP(OP_CONST, 0, sv); |
a7cb1f99 | 10580 | else |
b73d6f50 | 10581 | lvalp->opval = Nullop; |
a687059c | 10582 | |
73d840c0 | 10583 | return (char *)s; |
378cc40b LW |
10584 | } |
10585 | ||
76e3520e | 10586 | STATIC char * |
cea2e8a9 | 10587 | S_scan_formline(pTHX_ register char *s) |
378cc40b | 10588 | { |
79072805 | 10589 | register char *eol; |
378cc40b | 10590 | register char *t; |
79cb57f6 | 10591 | SV *stuff = newSVpvn("",0); |
79072805 | 10592 | bool needargs = FALSE; |
c5ee2135 | 10593 | bool eofmt = FALSE; |
378cc40b | 10594 | |
79072805 | 10595 | while (!needargs) { |
a1b95068 | 10596 | if (*s == '.') { |
51882d45 | 10597 | #ifdef PERL_STRICT_CR |
bf4acbe4 | 10598 | for (t = s+1;SPACE_OR_TAB(*t); t++) ; |
51882d45 | 10599 | #else |
bf4acbe4 | 10600 | for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ; |
51882d45 | 10601 | #endif |
c5ee2135 WL |
10602 | if (*t == '\n' || t == PL_bufend) { |
10603 | eofmt = TRUE; | |
79072805 | 10604 | break; |
c5ee2135 | 10605 | } |
79072805 | 10606 | } |
3280af22 | 10607 | if (PL_in_eval && !PL_rsfp) { |
07409e01 | 10608 | eol = (char *) memchr(s,'\n',PL_bufend-s); |
0f85fab0 | 10609 | if (!eol++) |
3280af22 | 10610 | eol = PL_bufend; |
0f85fab0 LW |
10611 | } |
10612 | else | |
3280af22 | 10613 | eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
79072805 | 10614 | if (*s != '#') { |
a0d0e21e LW |
10615 | for (t = s; t < eol; t++) { |
10616 | if (*t == '~' && t[1] == '~' && SvCUR(stuff)) { | |
10617 | needargs = FALSE; | |
10618 | goto enough; /* ~~ must be first line in formline */ | |
378cc40b | 10619 | } |
a0d0e21e LW |
10620 | if (*t == '@' || *t == '^') |
10621 | needargs = TRUE; | |
378cc40b | 10622 | } |
7121b347 MG |
10623 | if (eol > s) { |
10624 | sv_catpvn(stuff, s, eol-s); | |
2dc4c65b | 10625 | #ifndef PERL_STRICT_CR |
7121b347 MG |
10626 | if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') { |
10627 | char *end = SvPVX(stuff) + SvCUR(stuff); | |
10628 | end[-2] = '\n'; | |
10629 | end[-1] = '\0'; | |
b162af07 | 10630 | SvCUR_set(stuff, SvCUR(stuff) - 1); |
7121b347 | 10631 | } |
2dc4c65b | 10632 | #endif |
7121b347 MG |
10633 | } |
10634 | else | |
10635 | break; | |
79072805 | 10636 | } |
95a20fc0 | 10637 | s = (char*)eol; |
3280af22 NIS |
10638 | if (PL_rsfp) { |
10639 | s = filter_gets(PL_linestr, PL_rsfp, 0); | |
10640 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr); | |
10641 | PL_bufend = PL_bufptr + SvCUR(PL_linestr); | |
207e3d1a | 10642 | PL_last_lop = PL_last_uni = Nullch; |
79072805 | 10643 | if (!s) { |
3280af22 | 10644 | s = PL_bufptr; |
378cc40b LW |
10645 | break; |
10646 | } | |
378cc40b | 10647 | } |
463ee0b2 | 10648 | incline(s); |
79072805 | 10649 | } |
a0d0e21e LW |
10650 | enough: |
10651 | if (SvCUR(stuff)) { | |
3280af22 | 10652 | PL_expect = XTERM; |
79072805 | 10653 | if (needargs) { |
3280af22 NIS |
10654 | PL_lex_state = LEX_NORMAL; |
10655 | PL_nextval[PL_nexttoke].ival = 0; | |
79072805 LW |
10656 | force_next(','); |
10657 | } | |
a0d0e21e | 10658 | else |
3280af22 | 10659 | PL_lex_state = LEX_FORMLINE; |
1bd51a4c | 10660 | if (!IN_BYTES) { |
95a20fc0 | 10661 | if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff))) |
1bd51a4c IH |
10662 | SvUTF8_on(stuff); |
10663 | else if (PL_encoding) | |
10664 | sv_recode_to_utf8(stuff, PL_encoding); | |
10665 | } | |
3280af22 | 10666 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff); |
79072805 | 10667 | force_next(THING); |
3280af22 | 10668 | PL_nextval[PL_nexttoke].ival = OP_FORMLINE; |
79072805 | 10669 | force_next(LSTOP); |
378cc40b | 10670 | } |
79072805 | 10671 | else { |
8990e307 | 10672 | SvREFCNT_dec(stuff); |
c5ee2135 WL |
10673 | if (eofmt) |
10674 | PL_lex_formbrack = 0; | |
3280af22 | 10675 | PL_bufptr = s; |
79072805 LW |
10676 | } |
10677 | return s; | |
378cc40b | 10678 | } |
a687059c | 10679 | |
76e3520e | 10680 | STATIC void |
cea2e8a9 | 10681 | S_set_csh(pTHX) |
a687059c | 10682 | { |
ae986130 | 10683 | #ifdef CSH |
3280af22 NIS |
10684 | if (!PL_cshlen) |
10685 | PL_cshlen = strlen(PL_cshname); | |
ae986130 | 10686 | #endif |
a687059c | 10687 | } |
463ee0b2 | 10688 | |
ba6d6ac9 | 10689 | I32 |
864dbfa3 | 10690 | Perl_start_subparse(pTHX_ I32 is_format, U32 flags) |
8990e307 | 10691 | { |
a3b680e6 | 10692 | const I32 oldsavestack_ix = PL_savestack_ix; |
3280af22 | 10693 | CV* outsidecv = PL_compcv; |
8990e307 | 10694 | |
3280af22 NIS |
10695 | if (PL_compcv) { |
10696 | assert(SvTYPE(PL_compcv) == SVt_PVCV); | |
e9a444f0 | 10697 | } |
7766f137 | 10698 | SAVEI32(PL_subline); |
3280af22 | 10699 | save_item(PL_subname); |
3280af22 | 10700 | SAVESPTR(PL_compcv); |
3280af22 NIS |
10701 | |
10702 | PL_compcv = (CV*)NEWSV(1104,0); | |
10703 | sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV); | |
10704 | CvFLAGS(PL_compcv) |= flags; | |
10705 | ||
57843af0 | 10706 | PL_subline = CopLINE(PL_curcop); |
dd2155a4 | 10707 | CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB); |
3280af22 | 10708 | CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv); |
a3985cdc | 10709 | CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax; |
748a9306 | 10710 | |
8990e307 LW |
10711 | return oldsavestack_ix; |
10712 | } | |
10713 | ||
084592ab CN |
10714 | #ifdef __SC__ |
10715 | #pragma segment Perl_yylex | |
10716 | #endif | |
8990e307 | 10717 | int |
bfed75c6 | 10718 | Perl_yywarn(pTHX_ const char *s) |
8990e307 | 10719 | { |
faef0170 | 10720 | PL_in_eval |= EVAL_WARNONLY; |
748a9306 | 10721 | yyerror(s); |
faef0170 | 10722 | PL_in_eval &= ~EVAL_WARNONLY; |
748a9306 | 10723 | return 0; |
8990e307 LW |
10724 | } |
10725 | ||
10726 | int | |
bfed75c6 | 10727 | Perl_yyerror(pTHX_ const char *s) |
463ee0b2 | 10728 | { |
bfed75c6 AL |
10729 | const char *where = NULL; |
10730 | const char *context = NULL; | |
68dc0745 | 10731 | int contlen = -1; |
46fc3d4c | 10732 | SV *msg; |
463ee0b2 | 10733 | |
3280af22 | 10734 | if (!yychar || (yychar == ';' && !PL_rsfp)) |
54310121 | 10735 | where = "at EOF"; |
8bcfe651 TM |
10736 | else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr && |
10737 | PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr && | |
10738 | PL_oldbufptr != PL_bufptr) { | |
f355267c JH |
10739 | /* |
10740 | Only for NetWare: | |
10741 | The code below is removed for NetWare because it abends/crashes on NetWare | |
10742 | when the script has error such as not having the closing quotes like: | |
10743 | if ($var eq "value) | |
10744 | Checking of white spaces is anyway done in NetWare code. | |
10745 | */ | |
10746 | #ifndef NETWARE | |
3280af22 NIS |
10747 | while (isSPACE(*PL_oldoldbufptr)) |
10748 | PL_oldoldbufptr++; | |
f355267c | 10749 | #endif |
3280af22 NIS |
10750 | context = PL_oldoldbufptr; |
10751 | contlen = PL_bufptr - PL_oldoldbufptr; | |
463ee0b2 | 10752 | } |
8bcfe651 TM |
10753 | else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr && |
10754 | PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) { | |
f355267c JH |
10755 | /* |
10756 | Only for NetWare: | |
10757 | The code below is removed for NetWare because it abends/crashes on NetWare | |
10758 | when the script has error such as not having the closing quotes like: | |
10759 | if ($var eq "value) | |
10760 | Checking of white spaces is anyway done in NetWare code. | |
10761 | */ | |
10762 | #ifndef NETWARE | |
3280af22 NIS |
10763 | while (isSPACE(*PL_oldbufptr)) |
10764 | PL_oldbufptr++; | |
f355267c | 10765 | #endif |
3280af22 NIS |
10766 | context = PL_oldbufptr; |
10767 | contlen = PL_bufptr - PL_oldbufptr; | |
463ee0b2 LW |
10768 | } |
10769 | else if (yychar > 255) | |
68dc0745 | 10770 | where = "next token ???"; |
12fbd33b | 10771 | else if (yychar == -2) { /* YYEMPTY */ |
3280af22 NIS |
10772 | if (PL_lex_state == LEX_NORMAL || |
10773 | (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL)) | |
68dc0745 | 10774 | where = "at end of line"; |
3280af22 | 10775 | else if (PL_lex_inpat) |
68dc0745 | 10776 | where = "within pattern"; |
463ee0b2 | 10777 | else |
68dc0745 | 10778 | where = "within string"; |
463ee0b2 | 10779 | } |
46fc3d4c | 10780 | else { |
79cb57f6 | 10781 | SV *where_sv = sv_2mortal(newSVpvn("next char ", 10)); |
46fc3d4c | 10782 | if (yychar < 32) |
cea2e8a9 | 10783 | Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar)); |
46fc3d4c | 10784 | else if (isPRINT_LC(yychar)) |
cea2e8a9 | 10785 | Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar); |
463ee0b2 | 10786 | else |
cea2e8a9 | 10787 | Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255); |
95a20fc0 | 10788 | where = SvPVX_const(where_sv); |
463ee0b2 | 10789 | } |
46fc3d4c | 10790 | msg = sv_2mortal(newSVpv(s, 0)); |
ed094faf | 10791 | Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ", |
248c2a4d | 10792 | OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop)); |
68dc0745 | 10793 | if (context) |
cea2e8a9 | 10794 | Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context); |
463ee0b2 | 10795 | else |
cea2e8a9 | 10796 | Perl_sv_catpvf(aTHX_ msg, "%s\n", where); |
57843af0 | 10797 | if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) { |
cf2093f6 | 10798 | Perl_sv_catpvf(aTHX_ msg, |
57def98f | 10799 | " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n", |
cf2093f6 | 10800 | (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start); |
3280af22 | 10801 | PL_multi_end = 0; |
a0d0e21e | 10802 | } |
56da5a46 RGS |
10803 | if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX)) |
10804 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg); | |
463ee0b2 | 10805 | else |
5a844595 | 10806 | qerror(msg); |
c7d6bfb2 GS |
10807 | if (PL_error_count >= 10) { |
10808 | if (PL_in_eval && SvCUR(ERRSV)) | |
d2560b70 | 10809 | Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n", |
248c2a4d | 10810 | ERRSV, OutCopFILE(PL_curcop)); |
c7d6bfb2 GS |
10811 | else |
10812 | Perl_croak(aTHX_ "%s has too many errors.\n", | |
248c2a4d | 10813 | OutCopFILE(PL_curcop)); |
c7d6bfb2 | 10814 | } |
3280af22 NIS |
10815 | PL_in_my = 0; |
10816 | PL_in_my_stash = Nullhv; | |
463ee0b2 LW |
10817 | return 0; |
10818 | } | |
084592ab CN |
10819 | #ifdef __SC__ |
10820 | #pragma segment Main | |
10821 | #endif | |
4e35701f | 10822 | |
b250498f | 10823 | STATIC char* |
3ae08724 | 10824 | S_swallow_bom(pTHX_ U8 *s) |
01ec43d0 | 10825 | { |
f54cb97a | 10826 | const STRLEN slen = SvCUR(PL_linestr); |
7aa207d6 | 10827 | switch (s[0]) { |
4e553d73 NIS |
10828 | case 0xFF: |
10829 | if (s[1] == 0xFE) { | |
7aa207d6 | 10830 | /* UTF-16 little-endian? (or UTF32-LE?) */ |
3ae08724 | 10831 | if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */ |
7aa207d6 | 10832 | Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE"); |
01ec43d0 | 10833 | #ifndef PERL_NO_UTF16_FILTER |
7aa207d6 | 10834 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n"); |
3ae08724 | 10835 | s += 2; |
7aa207d6 | 10836 | utf16le: |
dea0fc0b JH |
10837 | if (PL_bufend > (char*)s) { |
10838 | U8 *news; | |
10839 | I32 newlen; | |
10840 | ||
10841 | filter_add(utf16rev_textfilter, NULL); | |
a02a5408 | 10842 | Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8); |
1de9afcd RGS |
10843 | utf16_to_utf8_reversed(s, news, |
10844 | PL_bufend - (char*)s - 1, | |
10845 | &newlen); | |
7aa207d6 | 10846 | sv_setpvn(PL_linestr, (const char*)news, newlen); |
dea0fc0b | 10847 | Safefree(news); |
7aa207d6 JH |
10848 | SvUTF8_on(PL_linestr); |
10849 | s = (U8*)SvPVX(PL_linestr); | |
10850 | PL_bufend = SvPVX(PL_linestr) + newlen; | |
dea0fc0b | 10851 | } |
b250498f | 10852 | #else |
7aa207d6 | 10853 | Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE"); |
b250498f | 10854 | #endif |
01ec43d0 GS |
10855 | } |
10856 | break; | |
78ae23f5 | 10857 | case 0xFE: |
7aa207d6 | 10858 | if (s[1] == 0xFF) { /* UTF-16 big-endian? */ |
01ec43d0 | 10859 | #ifndef PERL_NO_UTF16_FILTER |
7aa207d6 | 10860 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n"); |
dea0fc0b | 10861 | s += 2; |
7aa207d6 | 10862 | utf16be: |
dea0fc0b JH |
10863 | if (PL_bufend > (char *)s) { |
10864 | U8 *news; | |
10865 | I32 newlen; | |
10866 | ||
10867 | filter_add(utf16_textfilter, NULL); | |
a02a5408 | 10868 | Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8); |
1de9afcd RGS |
10869 | utf16_to_utf8(s, news, |
10870 | PL_bufend - (char*)s, | |
10871 | &newlen); | |
7aa207d6 | 10872 | sv_setpvn(PL_linestr, (const char*)news, newlen); |
dea0fc0b | 10873 | Safefree(news); |
7aa207d6 JH |
10874 | SvUTF8_on(PL_linestr); |
10875 | s = (U8*)SvPVX(PL_linestr); | |
10876 | PL_bufend = SvPVX(PL_linestr) + newlen; | |
dea0fc0b | 10877 | } |
b250498f | 10878 | #else |
7aa207d6 | 10879 | Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE"); |
b250498f | 10880 | #endif |
01ec43d0 GS |
10881 | } |
10882 | break; | |
3ae08724 GS |
10883 | case 0xEF: |
10884 | if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) { | |
7aa207d6 | 10885 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n"); |
01ec43d0 GS |
10886 | s += 3; /* UTF-8 */ |
10887 | } | |
10888 | break; | |
10889 | case 0: | |
7aa207d6 JH |
10890 | if (slen > 3) { |
10891 | if (s[1] == 0) { | |
10892 | if (s[2] == 0xFE && s[3] == 0xFF) { | |
10893 | /* UTF-32 big-endian */ | |
10894 | Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE"); | |
10895 | } | |
10896 | } | |
10897 | else if (s[2] == 0 && s[3] != 0) { | |
10898 | /* Leading bytes | |
10899 | * 00 xx 00 xx | |
10900 | * are a good indicator of UTF-16BE. */ | |
10901 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n"); | |
10902 | goto utf16be; | |
10903 | } | |
01ec43d0 | 10904 | } |
7aa207d6 JH |
10905 | default: |
10906 | if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) { | |
10907 | /* Leading bytes | |
10908 | * xx 00 xx 00 | |
10909 | * are a good indicator of UTF-16LE. */ | |
10910 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n"); | |
10911 | goto utf16le; | |
10912 | } | |
01ec43d0 | 10913 | } |
b8f84bb2 | 10914 | return (char*)s; |
b250498f | 10915 | } |
4755096e | 10916 | |
4755096e GS |
10917 | /* |
10918 | * restore_rsfp | |
10919 | * Restore a source filter. | |
10920 | */ | |
10921 | ||
10922 | static void | |
acfe0abc | 10923 | restore_rsfp(pTHX_ void *f) |
4755096e | 10924 | { |
0bd48802 | 10925 | PerlIO * const fp = (PerlIO*)f; |
4755096e GS |
10926 | |
10927 | if (PL_rsfp == PerlIO_stdin()) | |
10928 | PerlIO_clearerr(PL_rsfp); | |
10929 | else if (PL_rsfp && (PL_rsfp != fp)) | |
10930 | PerlIO_close(PL_rsfp); | |
10931 | PL_rsfp = fp; | |
10932 | } | |
6e3aabd6 GS |
10933 | |
10934 | #ifndef PERL_NO_UTF16_FILTER | |
10935 | static I32 | |
acfe0abc | 10936 | utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
6e3aabd6 | 10937 | { |
f54cb97a AL |
10938 | const STRLEN old = SvCUR(sv); |
10939 | const I32 count = FILTER_READ(idx+1, sv, maxlen); | |
1de9afcd RGS |
10940 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
10941 | "utf16_textfilter(%p): %d %d (%d)\n", | |
4fccd7c6 | 10942 | utf16_textfilter, idx, maxlen, (int) count)); |
6e3aabd6 GS |
10943 | if (count) { |
10944 | U8* tmps; | |
dea0fc0b | 10945 | I32 newlen; |
a02a5408 | 10946 | Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8); |
95a20fc0 SP |
10947 | Copy(SvPVX_const(sv), tmps, old, char); |
10948 | utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old, | |
1de9afcd RGS |
10949 | SvCUR(sv) - old, &newlen); |
10950 | sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old); | |
6e3aabd6 | 10951 | } |
1de9afcd RGS |
10952 | DEBUG_P({sv_dump(sv);}); |
10953 | return SvCUR(sv); | |
6e3aabd6 GS |
10954 | } |
10955 | ||
10956 | static I32 | |
acfe0abc | 10957 | utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
6e3aabd6 | 10958 | { |
f54cb97a AL |
10959 | const STRLEN old = SvCUR(sv); |
10960 | const I32 count = FILTER_READ(idx+1, sv, maxlen); | |
1de9afcd RGS |
10961 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
10962 | "utf16rev_textfilter(%p): %d %d (%d)\n", | |
4fccd7c6 | 10963 | utf16rev_textfilter, idx, maxlen, (int) count)); |
6e3aabd6 GS |
10964 | if (count) { |
10965 | U8* tmps; | |
dea0fc0b | 10966 | I32 newlen; |
a02a5408 | 10967 | Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8); |
95a20fc0 SP |
10968 | Copy(SvPVX_const(sv), tmps, old, char); |
10969 | utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old, | |
1de9afcd RGS |
10970 | SvCUR(sv) - old, &newlen); |
10971 | sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old); | |
6e3aabd6 | 10972 | } |
1de9afcd | 10973 | DEBUG_P({ sv_dump(sv); }); |
6e3aabd6 GS |
10974 | return count; |
10975 | } | |
10976 | #endif | |
9f4817db | 10977 | |
f333445c JP |
10978 | /* |
10979 | Returns a pointer to the next character after the parsed | |
10980 | vstring, as well as updating the passed in sv. | |
10981 | ||
10982 | Function must be called like | |
10983 | ||
10984 | sv = NEWSV(92,5); | |
10985 | s = scan_vstring(s,sv); | |
10986 | ||
10987 | The sv should already be large enough to store the vstring | |
10988 | passed in, for performance reasons. | |
10989 | ||
10990 | */ | |
10991 | ||
10992 | char * | |
bfed75c6 | 10993 | Perl_scan_vstring(pTHX_ const char *s, SV *sv) |
f333445c | 10994 | { |
bfed75c6 AL |
10995 | const char *pos = s; |
10996 | const char *start = s; | |
f333445c | 10997 | if (*pos == 'v') pos++; /* get past 'v' */ |
3e884cbf JH |
10998 | while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_')) |
10999 | pos++; | |
f333445c JP |
11000 | if ( *pos != '.') { |
11001 | /* this may not be a v-string if followed by => */ | |
bfed75c6 | 11002 | const char *next = pos; |
8fc7bb1c SM |
11003 | while (next < PL_bufend && isSPACE(*next)) |
11004 | ++next; | |
11005 | if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) { | |
f333445c JP |
11006 | /* return string not v-string */ |
11007 | sv_setpvn(sv,(char *)s,pos-s); | |
73d840c0 | 11008 | return (char *)pos; |
f333445c JP |
11009 | } |
11010 | } | |
11011 | ||
11012 | if (!isALPHA(*pos)) { | |
89ebb4a3 | 11013 | U8 tmpbuf[UTF8_MAXBYTES+1]; |
f333445c JP |
11014 | |
11015 | if (*s == 'v') s++; /* get past 'v' */ | |
11016 | ||
11017 | sv_setpvn(sv, "", 0); | |
11018 | ||
11019 | for (;;) { | |
0bd48802 AL |
11020 | U8 *tmpend; |
11021 | UV rev = 0; | |
f333445c JP |
11022 | { |
11023 | /* this is atoi() that tolerates underscores */ | |
bfed75c6 | 11024 | const char *end = pos; |
f333445c JP |
11025 | UV mult = 1; |
11026 | while (--end >= s) { | |
11027 | UV orev; | |
11028 | if (*end == '_') | |
11029 | continue; | |
11030 | orev = rev; | |
11031 | rev += (*end - '0') * mult; | |
11032 | mult *= 10; | |
11033 | if (orev > rev && ckWARN_d(WARN_OVERFLOW)) | |
11034 | Perl_warner(aTHX_ packWARN(WARN_OVERFLOW), | |
11035 | "Integer overflow in decimal number"); | |
11036 | } | |
11037 | } | |
11038 | #ifdef EBCDIC | |
11039 | if (rev > 0x7FFFFFFF) | |
11040 | Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647"); | |
11041 | #endif | |
11042 | /* Append native character for the rev point */ | |
11043 | tmpend = uvchr_to_utf8(tmpbuf, rev); | |
11044 | sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf); | |
11045 | if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev))) | |
11046 | SvUTF8_on(sv); | |
3e884cbf | 11047 | if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1])) |
f333445c JP |
11048 | s = ++pos; |
11049 | else { | |
11050 | s = pos; | |
11051 | break; | |
11052 | } | |
3e884cbf | 11053 | while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_')) |
f333445c JP |
11054 | pos++; |
11055 | } | |
11056 | SvPOK_on(sv); | |
11057 | sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start); | |
11058 | SvRMAGICAL_on(sv); | |
11059 | } | |
73d840c0 | 11060 | return (char *)s; |
f333445c JP |
11061 | } |
11062 | ||
1da4ca5f NC |
11063 | /* |
11064 | * Local variables: | |
11065 | * c-indentation-style: bsd | |
11066 | * c-basic-offset: 4 | |
11067 | * indent-tabs-mode: t | |
11068 | * End: | |
11069 | * | |
37442d52 RGS |
11070 | * ex: set ts=8 sts=4 sw=4 noet: |
11071 | */ |