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 | |
27da23d5 JH |
29 | static const char ident_too_long[] = |
30 | "Identifier too long"; | |
31 | static const char c_without_g[] = | |
32 | "Use of /c modifier is meaningless without /g"; | |
33 | static const char c_in_subst[] = | |
34 | "Use of /c modifier is meaningless in s///"; | |
8903cb82 | 35 | |
acfe0abc | 36 | static void restore_rsfp(pTHX_ void *f); |
6e3aabd6 | 37 | #ifndef PERL_NO_UTF16_FILTER |
acfe0abc GS |
38 | static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen); |
39 | static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen); | |
6e3aabd6 | 40 | #endif |
51371543 | 41 | |
9059aa12 LW |
42 | #define XFAKEBRACK 128 |
43 | #define XENUMMASK 127 | |
44 | ||
39e02b42 JH |
45 | #ifdef USE_UTF8_SCRIPTS |
46 | # define UTF (!IN_BYTES) | |
2b9d42f0 | 47 | #else |
746b446a | 48 | # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8)) |
2b9d42f0 | 49 | #endif |
a0ed51b3 | 50 | |
61f0cdd9 | 51 | /* In variables named $^X, these are the legal values for X. |
2b92dfce GS |
52 | * 1999-02-27 mjd-perl-patch@plover.com */ |
53 | #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x))) | |
54 | ||
bf4acbe4 GS |
55 | /* On MacOS, respect nonbreaking spaces */ |
56 | #ifdef MACOS_TRADITIONAL | |
57 | #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t') | |
58 | #else | |
59 | #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t') | |
60 | #endif | |
61 | ||
ffb4593c NT |
62 | /* LEX_* are values for PL_lex_state, the state of the lexer. |
63 | * They are arranged oddly so that the guard on the switch statement | |
79072805 LW |
64 | * can get by with a single comparison (if the compiler is smart enough). |
65 | */ | |
66 | ||
fb73857a | 67 | /* #define LEX_NOTPARSING 11 is done in perl.h. */ |
68 | ||
b6007c36 DM |
69 | #define LEX_NORMAL 10 /* normal code (ie not within "...") */ |
70 | #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */ | |
71 | #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */ | |
72 | #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */ | |
73 | #define LEX_INTERPSTART 6 /* expecting the start of a $var */ | |
74 | ||
75 | /* at end of code, eg "$x" followed by: */ | |
76 | #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */ | |
77 | #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */ | |
78 | ||
79 | #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of | |
80 | string or after \E, $foo, etc */ | |
81 | #define LEX_INTERPCONST 2 /* NOT USED */ | |
82 | #define LEX_FORMLINE 1 /* expecting a format line */ | |
83 | #define LEX_KNOWNEXT 0 /* next token known; just return it */ | |
84 | ||
79072805 | 85 | |
bbf60fe6 | 86 | #ifdef DEBUGGING |
27da23d5 | 87 | static const char* const lex_state_names[] = { |
bbf60fe6 DM |
88 | "KNOWNEXT", |
89 | "FORMLINE", | |
90 | "INTERPCONST", | |
91 | "INTERPCONCAT", | |
92 | "INTERPENDMAYBE", | |
93 | "INTERPEND", | |
94 | "INTERPSTART", | |
95 | "INTERPPUSH", | |
96 | "INTERPCASEMOD", | |
97 | "INTERPNORMAL", | |
98 | "NORMAL" | |
99 | }; | |
100 | #endif | |
101 | ||
79072805 LW |
102 | #ifdef ff_next |
103 | #undef ff_next | |
d48672a2 LW |
104 | #endif |
105 | ||
79072805 | 106 | #include "keywords.h" |
fe14fcc3 | 107 | |
ffb4593c NT |
108 | /* CLINE is a macro that ensures PL_copline has a sane value */ |
109 | ||
ae986130 LW |
110 | #ifdef CLINE |
111 | #undef CLINE | |
112 | #endif | |
57843af0 | 113 | #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline)) |
3280af22 | 114 | |
ffb4593c NT |
115 | /* |
116 | * Convenience functions to return different tokens and prime the | |
9cbb5ea2 | 117 | * lexer for the next token. They all take an argument. |
ffb4593c NT |
118 | * |
119 | * TOKEN : generic token (used for '(', DOLSHARP, etc) | |
120 | * OPERATOR : generic operator | |
121 | * AOPERATOR : assignment operator | |
122 | * PREBLOCK : beginning the block after an if, while, foreach, ... | |
123 | * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref) | |
124 | * PREREF : *EXPR where EXPR is not a simple identifier | |
125 | * TERM : expression term | |
126 | * LOOPX : loop exiting command (goto, last, dump, etc) | |
127 | * FTST : file test operator | |
128 | * FUN0 : zero-argument function | |
2d2e263d | 129 | * FUN1 : not used, except for not, which isn't a UNIOP |
ffb4593c NT |
130 | * BOop : bitwise or or xor |
131 | * BAop : bitwise and | |
132 | * SHop : shift operator | |
133 | * PWop : power operator | |
9cbb5ea2 | 134 | * PMop : pattern-matching operator |
ffb4593c NT |
135 | * Aop : addition-level operator |
136 | * Mop : multiplication-level operator | |
137 | * Eop : equality-testing operator | |
e5edeb50 | 138 | * Rop : relational operator <= != gt |
ffb4593c NT |
139 | * |
140 | * Also see LOP and lop() below. | |
141 | */ | |
142 | ||
998054bd | 143 | #ifdef DEBUGGING /* Serve -DT. */ |
bbf60fe6 | 144 | # define REPORT(retval) tokereport(s,(int)retval) |
998054bd | 145 | #else |
bbf60fe6 | 146 | # define REPORT(retval) (retval) |
998054bd SC |
147 | #endif |
148 | ||
bbf60fe6 DM |
149 | #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval)) |
150 | #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval)) | |
151 | #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval))) | |
152 | #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval)) | |
153 | #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval)) | |
154 | #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval)) | |
155 | #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval)) | |
156 | #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX)) | |
157 | #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP)) | |
158 | #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0)) | |
159 | #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1)) | |
160 | #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP))) | |
161 | #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP))) | |
162 | #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP))) | |
163 | #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP))) | |
164 | #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP)) | |
165 | #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP))) | |
166 | #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP))) | |
167 | #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP)) | |
168 | #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP)) | |
2f3197b3 | 169 | |
a687059c LW |
170 | /* This bit of chicanery makes a unary function followed by |
171 | * a parenthesis into a function with one argument, highest precedence. | |
6f33ba73 RGS |
172 | * The UNIDOR macro is for unary functions that can be followed by the // |
173 | * operator (such as C<shift // 0>). | |
a687059c | 174 | */ |
376fcdbf AL |
175 | #define UNI2(f,x) { \ |
176 | yylval.ival = f; \ | |
177 | PL_expect = x; \ | |
178 | PL_bufptr = s; \ | |
179 | PL_last_uni = PL_oldbufptr; \ | |
180 | PL_last_lop_op = f; \ | |
181 | if (*s == '(') \ | |
182 | return REPORT( (int)FUNC1 ); \ | |
183 | s = skipspace(s); \ | |
184 | return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \ | |
185 | } | |
6f33ba73 RGS |
186 | #define UNI(f) UNI2(f,XTERM) |
187 | #define UNIDOR(f) UNI2(f,XTERMORDORDOR) | |
a687059c | 188 | |
376fcdbf AL |
189 | #define UNIBRACK(f) { \ |
190 | yylval.ival = f; \ | |
191 | PL_bufptr = s; \ | |
192 | PL_last_uni = PL_oldbufptr; \ | |
193 | if (*s == '(') \ | |
194 | return REPORT( (int)FUNC1 ); \ | |
195 | s = skipspace(s); \ | |
196 | return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \ | |
197 | } | |
79072805 | 198 | |
9f68db38 | 199 | /* grandfather return to old style */ |
3280af22 | 200 | #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP) |
79072805 | 201 | |
8fa7f367 JH |
202 | #ifdef DEBUGGING |
203 | ||
bbf60fe6 DM |
204 | /* how to interpret the yylval associated with the token */ |
205 | enum token_type { | |
206 | TOKENTYPE_NONE, | |
207 | TOKENTYPE_IVAL, | |
208 | TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */ | |
209 | TOKENTYPE_PVAL, | |
210 | TOKENTYPE_OPVAL, | |
211 | TOKENTYPE_GVVAL | |
212 | }; | |
213 | ||
27da23d5 JH |
214 | static struct debug_tokens { const int token, type; const char *name; } |
215 | const debug_tokens[] = | |
9041c2e3 | 216 | { |
bbf60fe6 DM |
217 | { ADDOP, TOKENTYPE_OPNUM, "ADDOP" }, |
218 | { ANDAND, TOKENTYPE_NONE, "ANDAND" }, | |
219 | { ANDOP, TOKENTYPE_NONE, "ANDOP" }, | |
220 | { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" }, | |
221 | { ARROW, TOKENTYPE_NONE, "ARROW" }, | |
222 | { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" }, | |
223 | { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" }, | |
224 | { BITOROP, TOKENTYPE_OPNUM, "BITOROP" }, | |
225 | { COLONATTR, TOKENTYPE_NONE, "COLONATTR" }, | |
226 | { CONTINUE, TOKENTYPE_NONE, "CONTINUE" }, | |
227 | { DO, TOKENTYPE_NONE, "DO" }, | |
228 | { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" }, | |
229 | { DORDOR, TOKENTYPE_NONE, "DORDOR" }, | |
230 | { DOROP, TOKENTYPE_OPNUM, "DOROP" }, | |
231 | { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" }, | |
232 | { ELSE, TOKENTYPE_NONE, "ELSE" }, | |
233 | { ELSIF, TOKENTYPE_IVAL, "ELSIF" }, | |
234 | { EQOP, TOKENTYPE_OPNUM, "EQOP" }, | |
235 | { FOR, TOKENTYPE_IVAL, "FOR" }, | |
236 | { FORMAT, TOKENTYPE_NONE, "FORMAT" }, | |
237 | { FUNC, TOKENTYPE_OPNUM, "FUNC" }, | |
238 | { FUNC0, TOKENTYPE_OPNUM, "FUNC0" }, | |
239 | { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" }, | |
240 | { FUNC1, TOKENTYPE_OPNUM, "FUNC1" }, | |
241 | { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" }, | |
242 | { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" }, | |
243 | { IF, TOKENTYPE_IVAL, "IF" }, | |
244 | { LABEL, TOKENTYPE_PVAL, "LABEL" }, | |
245 | { LOCAL, TOKENTYPE_IVAL, "LOCAL" }, | |
246 | { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" }, | |
247 | { LSTOP, TOKENTYPE_OPNUM, "LSTOP" }, | |
248 | { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" }, | |
249 | { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" }, | |
250 | { METHOD, TOKENTYPE_OPVAL, "METHOD" }, | |
251 | { MULOP, TOKENTYPE_OPNUM, "MULOP" }, | |
252 | { MY, TOKENTYPE_IVAL, "MY" }, | |
253 | { MYSUB, TOKENTYPE_NONE, "MYSUB" }, | |
254 | { NOAMP, TOKENTYPE_NONE, "NOAMP" }, | |
255 | { NOTOP, TOKENTYPE_NONE, "NOTOP" }, | |
256 | { OROP, TOKENTYPE_IVAL, "OROP" }, | |
257 | { OROR, TOKENTYPE_NONE, "OROR" }, | |
258 | { PACKAGE, TOKENTYPE_NONE, "PACKAGE" }, | |
259 | { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" }, | |
260 | { POSTDEC, TOKENTYPE_NONE, "POSTDEC" }, | |
261 | { POSTINC, TOKENTYPE_NONE, "POSTINC" }, | |
262 | { POWOP, TOKENTYPE_OPNUM, "POWOP" }, | |
263 | { PREDEC, TOKENTYPE_NONE, "PREDEC" }, | |
264 | { PREINC, TOKENTYPE_NONE, "PREINC" }, | |
265 | { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" }, | |
266 | { REFGEN, TOKENTYPE_NONE, "REFGEN" }, | |
267 | { RELOP, TOKENTYPE_OPNUM, "RELOP" }, | |
268 | { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" }, | |
269 | { SUB, TOKENTYPE_NONE, "SUB" }, | |
270 | { THING, TOKENTYPE_OPVAL, "THING" }, | |
271 | { UMINUS, TOKENTYPE_NONE, "UMINUS" }, | |
272 | { UNIOP, TOKENTYPE_OPNUM, "UNIOP" }, | |
273 | { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" }, | |
274 | { UNLESS, TOKENTYPE_IVAL, "UNLESS" }, | |
275 | { UNTIL, TOKENTYPE_IVAL, "UNTIL" }, | |
276 | { USE, TOKENTYPE_IVAL, "USE" }, | |
277 | { WHILE, TOKENTYPE_IVAL, "WHILE" }, | |
278 | { WORD, TOKENTYPE_OPVAL, "WORD" }, | |
279 | { 0, TOKENTYPE_NONE, 0 } | |
280 | }; | |
281 | ||
282 | /* dump the returned token in rv, plus any optional arg in yylval */ | |
998054bd | 283 | |
bbf60fe6 | 284 | STATIC int |
bfed75c6 | 285 | S_tokereport(pTHX_ const char* s, I32 rv) |
bbf60fe6 DM |
286 | { |
287 | if (DEBUG_T_TEST) { | |
bfed75c6 | 288 | const char *name = Nullch; |
bbf60fe6 | 289 | enum token_type type = TOKENTYPE_NONE; |
f54cb97a | 290 | const struct debug_tokens *p; |
9d4ba2ae | 291 | SV* const report = newSVpvn("<== ", 4); |
bbf60fe6 | 292 | |
f54cb97a | 293 | for (p = debug_tokens; p->token; p++) { |
bbf60fe6 DM |
294 | if (p->token == (int)rv) { |
295 | name = p->name; | |
296 | type = p->type; | |
297 | break; | |
298 | } | |
299 | } | |
300 | if (name) | |
54667de8 | 301 | Perl_sv_catpv(aTHX_ report, name); |
bbf60fe6 DM |
302 | else if ((char)rv > ' ' && (char)rv < '~') |
303 | Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv); | |
304 | else if (!rv) | |
54667de8 | 305 | Perl_sv_catpv(aTHX_ report, "EOF"); |
bbf60fe6 DM |
306 | else |
307 | Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv); | |
308 | switch (type) { | |
309 | case TOKENTYPE_NONE: | |
310 | case TOKENTYPE_GVVAL: /* doesn't appear to be used */ | |
311 | break; | |
312 | case TOKENTYPE_IVAL: | |
e4584336 | 313 | Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival); |
bbf60fe6 DM |
314 | break; |
315 | case TOKENTYPE_OPNUM: | |
316 | Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)", | |
317 | PL_op_name[yylval.ival]); | |
318 | break; | |
319 | case TOKENTYPE_PVAL: | |
320 | Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval); | |
321 | break; | |
322 | case TOKENTYPE_OPVAL: | |
b6007c36 | 323 | if (yylval.opval) { |
401441c0 | 324 | Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)", |
bbf60fe6 | 325 | PL_op_name[yylval.opval->op_type]); |
b6007c36 DM |
326 | if (yylval.opval->op_type == OP_CONST) { |
327 | Perl_sv_catpvf(aTHX_ report, " %s", | |
328 | SvPEEK(cSVOPx_sv(yylval.opval))); | |
329 | } | |
330 | ||
331 | } | |
401441c0 RGS |
332 | else |
333 | Perl_sv_catpv(aTHX_ report, "(opval=null)"); | |
bbf60fe6 DM |
334 | break; |
335 | } | |
b6007c36 | 336 | PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report)); |
bbf60fe6 DM |
337 | }; |
338 | return (int)rv; | |
998054bd SC |
339 | } |
340 | ||
b6007c36 DM |
341 | |
342 | /* print the buffer with suitable escapes */ | |
343 | ||
344 | STATIC void | |
345 | S_printbuf(pTHX_ const char* fmt, const char* s) | |
346 | { | |
347 | SV* tmp = newSVpvn("", 0); | |
348 | PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60)); | |
349 | SvREFCNT_dec(tmp); | |
350 | } | |
351 | ||
8fa7f367 JH |
352 | #endif |
353 | ||
ffb4593c NT |
354 | /* |
355 | * S_ao | |
356 | * | |
c963b151 BD |
357 | * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR |
358 | * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN | |
ffb4593c NT |
359 | */ |
360 | ||
76e3520e | 361 | STATIC int |
cea2e8a9 | 362 | S_ao(pTHX_ int toketype) |
a0d0e21e | 363 | { |
3280af22 NIS |
364 | if (*PL_bufptr == '=') { |
365 | PL_bufptr++; | |
a0d0e21e LW |
366 | if (toketype == ANDAND) |
367 | yylval.ival = OP_ANDASSIGN; | |
368 | else if (toketype == OROR) | |
369 | yylval.ival = OP_ORASSIGN; | |
c963b151 BD |
370 | else if (toketype == DORDOR) |
371 | yylval.ival = OP_DORASSIGN; | |
a0d0e21e LW |
372 | toketype = ASSIGNOP; |
373 | } | |
374 | return toketype; | |
375 | } | |
376 | ||
ffb4593c NT |
377 | /* |
378 | * S_no_op | |
379 | * When Perl expects an operator and finds something else, no_op | |
380 | * prints the warning. It always prints "<something> found where | |
381 | * operator expected. It prints "Missing semicolon on previous line?" | |
382 | * if the surprise occurs at the start of the line. "do you need to | |
383 | * predeclare ..." is printed out for code like "sub bar; foo bar $x" | |
384 | * where the compiler doesn't know if foo is a method call or a function. | |
385 | * It prints "Missing operator before end of line" if there's nothing | |
386 | * after the missing operator, or "... before <...>" if there is something | |
387 | * after the missing operator. | |
388 | */ | |
389 | ||
76e3520e | 390 | STATIC void |
bfed75c6 | 391 | S_no_op(pTHX_ const char *what, char *s) |
463ee0b2 | 392 | { |
9d4ba2ae AL |
393 | char * const oldbp = PL_bufptr; |
394 | const bool is_first = (PL_oldbufptr == PL_linestart); | |
68dc0745 | 395 | |
1189a94a GS |
396 | if (!s) |
397 | s = oldbp; | |
07c798fb | 398 | else |
1189a94a | 399 | PL_bufptr = s; |
cea2e8a9 | 400 | yywarn(Perl_form(aTHX_ "%s found where operator expected", what)); |
56da5a46 RGS |
401 | if (ckWARN_d(WARN_SYNTAX)) { |
402 | if (is_first) | |
403 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
404 | "\t(Missing semicolon on previous line?)\n"); | |
405 | else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) { | |
f54cb97a | 406 | const char *t; |
56da5a46 RGS |
407 | for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ; |
408 | if (t < PL_bufptr && isSPACE(*t)) | |
409 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
410 | "\t(Do you need to predeclare %.*s?)\n", | |
551405c4 | 411 | (int)(t - PL_oldoldbufptr), PL_oldoldbufptr); |
56da5a46 RGS |
412 | } |
413 | else { | |
414 | assert(s >= oldbp); | |
415 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
551405c4 | 416 | "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp); |
56da5a46 | 417 | } |
07c798fb | 418 | } |
3280af22 | 419 | PL_bufptr = oldbp; |
8990e307 LW |
420 | } |
421 | ||
ffb4593c NT |
422 | /* |
423 | * S_missingterm | |
424 | * Complain about missing quote/regexp/heredoc terminator. | |
425 | * If it's called with (char *)NULL then it cauterizes the line buffer. | |
426 | * If we're in a delimited string and the delimiter is a control | |
427 | * character, it's reformatted into a two-char sequence like ^C. | |
428 | * This is fatal. | |
429 | */ | |
430 | ||
76e3520e | 431 | STATIC void |
cea2e8a9 | 432 | S_missingterm(pTHX_ char *s) |
8990e307 LW |
433 | { |
434 | char tmpbuf[3]; | |
435 | char q; | |
436 | if (s) { | |
9d4ba2ae | 437 | char * const nl = strrchr(s,'\n'); |
d2719217 | 438 | if (nl) |
8990e307 LW |
439 | *nl = '\0'; |
440 | } | |
9d116dd7 JH |
441 | else if ( |
442 | #ifdef EBCDIC | |
443 | iscntrl(PL_multi_close) | |
444 | #else | |
445 | PL_multi_close < 32 || PL_multi_close == 127 | |
446 | #endif | |
447 | ) { | |
8990e307 | 448 | *tmpbuf = '^'; |
585ec06d | 449 | tmpbuf[1] = (char)toCTRL(PL_multi_close); |
8990e307 LW |
450 | tmpbuf[2] = '\0'; |
451 | s = tmpbuf; | |
452 | } | |
453 | else { | |
eb160463 | 454 | *tmpbuf = (char)PL_multi_close; |
8990e307 LW |
455 | tmpbuf[1] = '\0'; |
456 | s = tmpbuf; | |
457 | } | |
458 | q = strchr(s,'"') ? '\'' : '"'; | |
cea2e8a9 | 459 | Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q); |
463ee0b2 | 460 | } |
79072805 | 461 | |
ffb4593c NT |
462 | /* |
463 | * Perl_deprecate | |
ffb4593c NT |
464 | */ |
465 | ||
79072805 | 466 | void |
bfed75c6 | 467 | Perl_deprecate(pTHX_ const char *s) |
a0d0e21e | 468 | { |
599cee73 | 469 | if (ckWARN(WARN_DEPRECATED)) |
9014280d | 470 | Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s); |
a0d0e21e LW |
471 | } |
472 | ||
12bcd1a6 | 473 | void |
bfed75c6 | 474 | Perl_deprecate_old(pTHX_ const char *s) |
12bcd1a6 PM |
475 | { |
476 | /* This function should NOT be called for any new deprecated warnings */ | |
477 | /* Use Perl_deprecate instead */ | |
478 | /* */ | |
479 | /* It is here to maintain backward compatibility with the pre-5.8 */ | |
480 | /* warnings category hierarchy. The "deprecated" category used to */ | |
481 | /* live under the "syntax" category. It is now a top-level category */ | |
482 | /* in its own right. */ | |
483 | ||
484 | if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX)) | |
bfed75c6 | 485 | Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX), |
12bcd1a6 PM |
486 | "Use of %s is deprecated", s); |
487 | } | |
488 | ||
ffb4593c NT |
489 | /* |
490 | * depcom | |
9cbb5ea2 | 491 | * Deprecate a comma-less variable list. |
ffb4593c NT |
492 | */ |
493 | ||
76e3520e | 494 | STATIC void |
cea2e8a9 | 495 | S_depcom(pTHX) |
a0d0e21e | 496 | { |
12bcd1a6 | 497 | deprecate_old("comma-less variable list"); |
a0d0e21e LW |
498 | } |
499 | ||
ffb4593c | 500 | /* |
9cbb5ea2 GS |
501 | * experimental text filters for win32 carriage-returns, utf16-to-utf8 and |
502 | * utf16-to-utf8-reversed. | |
ffb4593c NT |
503 | */ |
504 | ||
c39cd008 GS |
505 | #ifdef PERL_CR_FILTER |
506 | static void | |
507 | strip_return(SV *sv) | |
508 | { | |
95a20fc0 | 509 | register const char *s = SvPVX_const(sv); |
9d4ba2ae | 510 | register const char * const e = s + SvCUR(sv); |
c39cd008 GS |
511 | /* outer loop optimized to do nothing if there are no CR-LFs */ |
512 | while (s < e) { | |
513 | if (*s++ == '\r' && *s == '\n') { | |
514 | /* hit a CR-LF, need to copy the rest */ | |
515 | register char *d = s - 1; | |
516 | *d++ = *s++; | |
517 | while (s < e) { | |
518 | if (*s == '\r' && s[1] == '\n') | |
519 | s++; | |
520 | *d++ = *s++; | |
521 | } | |
522 | SvCUR(sv) -= s - d; | |
523 | return; | |
524 | } | |
525 | } | |
526 | } | |
a868473f | 527 | |
76e3520e | 528 | STATIC I32 |
c39cd008 | 529 | S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
a868473f | 530 | { |
f54cb97a | 531 | const I32 count = FILTER_READ(idx+1, sv, maxlen); |
c39cd008 GS |
532 | if (count > 0 && !maxlen) |
533 | strip_return(sv); | |
534 | return count; | |
a868473f NIS |
535 | } |
536 | #endif | |
537 | ||
ffb4593c NT |
538 | /* |
539 | * Perl_lex_start | |
9cbb5ea2 GS |
540 | * Initialize variables. Uses the Perl save_stack to save its state (for |
541 | * recursive calls to the parser). | |
ffb4593c NT |
542 | */ |
543 | ||
a0d0e21e | 544 | void |
864dbfa3 | 545 | Perl_lex_start(pTHX_ SV *line) |
79072805 | 546 | { |
cfd0369c | 547 | const char *s; |
8990e307 LW |
548 | STRLEN len; |
549 | ||
3280af22 NIS |
550 | SAVEI32(PL_lex_dojoin); |
551 | SAVEI32(PL_lex_brackets); | |
3280af22 NIS |
552 | SAVEI32(PL_lex_casemods); |
553 | SAVEI32(PL_lex_starts); | |
554 | SAVEI32(PL_lex_state); | |
7766f137 | 555 | SAVEVPTR(PL_lex_inpat); |
3280af22 | 556 | SAVEI32(PL_lex_inwhat); |
18b09519 GS |
557 | if (PL_lex_state == LEX_KNOWNEXT) { |
558 | I32 toke = PL_nexttoke; | |
559 | while (--toke >= 0) { | |
560 | SAVEI32(PL_nexttype[toke]); | |
561 | SAVEVPTR(PL_nextval[toke]); | |
562 | } | |
563 | SAVEI32(PL_nexttoke); | |
18b09519 | 564 | } |
57843af0 | 565 | SAVECOPLINE(PL_curcop); |
3280af22 NIS |
566 | SAVEPPTR(PL_bufptr); |
567 | SAVEPPTR(PL_bufend); | |
568 | SAVEPPTR(PL_oldbufptr); | |
569 | SAVEPPTR(PL_oldoldbufptr); | |
207e3d1a JH |
570 | SAVEPPTR(PL_last_lop); |
571 | SAVEPPTR(PL_last_uni); | |
3280af22 NIS |
572 | SAVEPPTR(PL_linestart); |
573 | SAVESPTR(PL_linestr); | |
8edd5f42 RGS |
574 | SAVEGENERICPV(PL_lex_brackstack); |
575 | SAVEGENERICPV(PL_lex_casestack); | |
c76ac1ee | 576 | SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp); |
3280af22 NIS |
577 | SAVESPTR(PL_lex_stuff); |
578 | SAVEI32(PL_lex_defer); | |
09bef843 | 579 | SAVEI32(PL_sublex_info.sub_inwhat); |
3280af22 | 580 | SAVESPTR(PL_lex_repl); |
bebdddfc GS |
581 | SAVEINT(PL_expect); |
582 | SAVEINT(PL_lex_expect); | |
3280af22 NIS |
583 | |
584 | PL_lex_state = LEX_NORMAL; | |
585 | PL_lex_defer = 0; | |
586 | PL_expect = XSTATE; | |
587 | PL_lex_brackets = 0; | |
a02a5408 JC |
588 | Newx(PL_lex_brackstack, 120, char); |
589 | Newx(PL_lex_casestack, 12, char); | |
3280af22 NIS |
590 | PL_lex_casemods = 0; |
591 | *PL_lex_casestack = '\0'; | |
592 | PL_lex_dojoin = 0; | |
593 | PL_lex_starts = 0; | |
594 | PL_lex_stuff = Nullsv; | |
595 | PL_lex_repl = Nullsv; | |
596 | PL_lex_inpat = 0; | |
76be56bc | 597 | PL_nexttoke = 0; |
3280af22 | 598 | PL_lex_inwhat = 0; |
09bef843 | 599 | PL_sublex_info.sub_inwhat = 0; |
3280af22 NIS |
600 | PL_linestr = line; |
601 | if (SvREADONLY(PL_linestr)) | |
602 | PL_linestr = sv_2mortal(newSVsv(PL_linestr)); | |
cfd0369c | 603 | s = SvPV_const(PL_linestr, len); |
6f27f9a7 | 604 | if (!len || s[len-1] != ';') { |
3280af22 NIS |
605 | if (!(SvFLAGS(PL_linestr) & SVs_TEMP)) |
606 | PL_linestr = sv_2mortal(newSVsv(PL_linestr)); | |
607 | sv_catpvn(PL_linestr, "\n;", 2); | |
8990e307 | 608 | } |
3280af22 NIS |
609 | SvTEMP_off(PL_linestr); |
610 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr); | |
611 | PL_bufend = PL_bufptr + SvCUR(PL_linestr); | |
207e3d1a | 612 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 613 | PL_rsfp = 0; |
79072805 | 614 | } |
a687059c | 615 | |
ffb4593c NT |
616 | /* |
617 | * Perl_lex_end | |
9cbb5ea2 GS |
618 | * Finalizer for lexing operations. Must be called when the parser is |
619 | * done with the lexer. | |
ffb4593c NT |
620 | */ |
621 | ||
463ee0b2 | 622 | void |
864dbfa3 | 623 | Perl_lex_end(pTHX) |
463ee0b2 | 624 | { |
3280af22 | 625 | PL_doextract = FALSE; |
463ee0b2 LW |
626 | } |
627 | ||
ffb4593c NT |
628 | /* |
629 | * S_incline | |
630 | * This subroutine has nothing to do with tilting, whether at windmills | |
631 | * or pinball tables. Its name is short for "increment line". It | |
57843af0 | 632 | * increments the current line number in CopLINE(PL_curcop) and checks |
ffb4593c | 633 | * to see whether the line starts with a comment of the form |
9cbb5ea2 GS |
634 | * # line 500 "foo.pm" |
635 | * If so, it sets the current line number and file to the values in the comment. | |
ffb4593c NT |
636 | */ |
637 | ||
76e3520e | 638 | STATIC void |
cea2e8a9 | 639 | S_incline(pTHX_ char *s) |
463ee0b2 LW |
640 | { |
641 | char *t; | |
642 | char *n; | |
73659bf1 | 643 | char *e; |
463ee0b2 | 644 | char ch; |
463ee0b2 | 645 | |
57843af0 | 646 | CopLINE_inc(PL_curcop); |
463ee0b2 LW |
647 | if (*s++ != '#') |
648 | return; | |
bf4acbe4 | 649 | while (SPACE_OR_TAB(*s)) s++; |
73659bf1 GS |
650 | if (strnEQ(s, "line", 4)) |
651 | s += 4; | |
652 | else | |
653 | return; | |
084592ab | 654 | if (SPACE_OR_TAB(*s)) |
73659bf1 | 655 | s++; |
4e553d73 | 656 | else |
73659bf1 | 657 | return; |
bf4acbe4 | 658 | while (SPACE_OR_TAB(*s)) s++; |
463ee0b2 LW |
659 | if (!isDIGIT(*s)) |
660 | return; | |
661 | n = s; | |
662 | while (isDIGIT(*s)) | |
663 | s++; | |
bf4acbe4 | 664 | while (SPACE_OR_TAB(*s)) |
463ee0b2 | 665 | s++; |
73659bf1 | 666 | if (*s == '"' && (t = strchr(s+1, '"'))) { |
463ee0b2 | 667 | s++; |
73659bf1 GS |
668 | e = t + 1; |
669 | } | |
463ee0b2 | 670 | else { |
463ee0b2 | 671 | for (t = s; !isSPACE(*t); t++) ; |
73659bf1 | 672 | e = t; |
463ee0b2 | 673 | } |
bf4acbe4 | 674 | while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f') |
73659bf1 GS |
675 | e++; |
676 | if (*e != '\n' && *e != '\0') | |
677 | return; /* false alarm */ | |
678 | ||
463ee0b2 LW |
679 | ch = *t; |
680 | *t = '\0'; | |
f4dd75d9 | 681 | if (t - s > 0) { |
8a5ee598 | 682 | #ifndef USE_ITHREADS |
e66cf94c RGS |
683 | const char *cf = CopFILE(PL_curcop); |
684 | if (cf && strlen(cf) > 7 && strnEQ(cf, "(eval ", 6)) { | |
685 | /* must copy *{"::_<(eval N)[oldfilename:L]"} | |
686 | * to *{"::_<newfilename"} */ | |
687 | char smallbuf[256], smallbuf2[256]; | |
688 | char *tmpbuf, *tmpbuf2; | |
8a5ee598 | 689 | GV **gvp, *gv2; |
e66cf94c RGS |
690 | STRLEN tmplen = strlen(cf); |
691 | STRLEN tmplen2 = strlen(s); | |
692 | if (tmplen + 3 < sizeof smallbuf) | |
693 | tmpbuf = smallbuf; | |
694 | else | |
695 | Newx(tmpbuf, tmplen + 3, char); | |
696 | if (tmplen2 + 3 < sizeof smallbuf2) | |
697 | tmpbuf2 = smallbuf2; | |
698 | else | |
699 | Newx(tmpbuf2, tmplen2 + 3, char); | |
700 | tmpbuf[0] = tmpbuf2[0] = '_'; | |
701 | tmpbuf[1] = tmpbuf2[1] = '<'; | |
702 | memcpy(tmpbuf + 2, cf, ++tmplen); | |
703 | memcpy(tmpbuf2 + 2, s, ++tmplen2); | |
704 | ++tmplen; ++tmplen2; | |
8a5ee598 RGS |
705 | gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE); |
706 | if (gvp) { | |
707 | gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE); | |
708 | if (!isGV(gv2)) | |
709 | gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE); | |
710 | /* adjust ${"::_<newfilename"} to store the new file name */ | |
711 | GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2); | |
712 | GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp)); | |
713 | GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp)); | |
714 | } | |
e66cf94c RGS |
715 | if (tmpbuf != smallbuf) Safefree(tmpbuf); |
716 | if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2); | |
717 | } | |
8a5ee598 | 718 | #endif |
05ec9bb3 | 719 | CopFILE_free(PL_curcop); |
57843af0 | 720 | CopFILE_set(PL_curcop, s); |
f4dd75d9 | 721 | } |
463ee0b2 | 722 | *t = ch; |
57843af0 | 723 | CopLINE_set(PL_curcop, atoi(n)-1); |
463ee0b2 LW |
724 | } |
725 | ||
ffb4593c NT |
726 | /* |
727 | * S_skipspace | |
728 | * Called to gobble the appropriate amount and type of whitespace. | |
729 | * Skips comments as well. | |
730 | */ | |
731 | ||
76e3520e | 732 | STATIC char * |
cea2e8a9 | 733 | S_skipspace(pTHX_ register char *s) |
a687059c | 734 | { |
3280af22 | 735 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
bf4acbe4 | 736 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
463ee0b2 LW |
737 | s++; |
738 | return s; | |
739 | } | |
740 | for (;;) { | |
fd049845 | 741 | STRLEN prevlen; |
09bef843 | 742 | SSize_t oldprevlen, oldoldprevlen; |
9c5ffd7c | 743 | SSize_t oldloplen = 0, oldunilen = 0; |
60e6418e GS |
744 | while (s < PL_bufend && isSPACE(*s)) { |
745 | if (*s++ == '\n' && PL_in_eval && !PL_rsfp) | |
746 | incline(s); | |
747 | } | |
ffb4593c NT |
748 | |
749 | /* comment */ | |
3280af22 NIS |
750 | if (s < PL_bufend && *s == '#') { |
751 | while (s < PL_bufend && *s != '\n') | |
463ee0b2 | 752 | s++; |
60e6418e | 753 | if (s < PL_bufend) { |
463ee0b2 | 754 | s++; |
60e6418e GS |
755 | if (PL_in_eval && !PL_rsfp) { |
756 | incline(s); | |
757 | continue; | |
758 | } | |
759 | } | |
463ee0b2 | 760 | } |
ffb4593c NT |
761 | |
762 | /* only continue to recharge the buffer if we're at the end | |
763 | * of the buffer, we're not reading from a source filter, and | |
764 | * we're in normal lexing mode | |
765 | */ | |
09bef843 SB |
766 | if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat || |
767 | PL_lex_state == LEX_FORMLINE) | |
463ee0b2 | 768 | return s; |
ffb4593c NT |
769 | |
770 | /* try to recharge the buffer */ | |
9cbb5ea2 GS |
771 | if ((s = filter_gets(PL_linestr, PL_rsfp, |
772 | (prevlen = SvCUR(PL_linestr)))) == Nullch) | |
773 | { | |
774 | /* end of file. Add on the -p or -n magic */ | |
01a19ab0 NC |
775 | if (PL_minus_p) { |
776 | sv_setpv(PL_linestr, | |
777 | ";}continue{print or die qq(-p destination: $!\\n);}"); | |
3280af22 | 778 | PL_minus_n = PL_minus_p = 0; |
a0d0e21e | 779 | } |
01a19ab0 NC |
780 | else if (PL_minus_n) { |
781 | sv_setpvn(PL_linestr, ";}", 2); | |
782 | PL_minus_n = 0; | |
783 | } | |
a0d0e21e | 784 | else |
4147a61b | 785 | sv_setpvn(PL_linestr,";", 1); |
ffb4593c NT |
786 | |
787 | /* reset variables for next time we lex */ | |
9cbb5ea2 GS |
788 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart |
789 | = SvPVX(PL_linestr); | |
3280af22 | 790 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 791 | PL_last_lop = PL_last_uni = Nullch; |
ffb4593c NT |
792 | |
793 | /* Close the filehandle. Could be from -P preprocessor, | |
794 | * STDIN, or a regular file. If we were reading code from | |
795 | * STDIN (because the commandline held no -e or filename) | |
796 | * then we don't close it, we reset it so the code can | |
797 | * read from STDIN too. | |
798 | */ | |
799 | ||
3280af22 NIS |
800 | if (PL_preprocess && !PL_in_eval) |
801 | (void)PerlProc_pclose(PL_rsfp); | |
802 | else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) | |
803 | PerlIO_clearerr(PL_rsfp); | |
8990e307 | 804 | else |
3280af22 NIS |
805 | (void)PerlIO_close(PL_rsfp); |
806 | PL_rsfp = Nullfp; | |
463ee0b2 LW |
807 | return s; |
808 | } | |
ffb4593c NT |
809 | |
810 | /* not at end of file, so we only read another line */ | |
09bef843 SB |
811 | /* make corresponding updates to old pointers, for yyerror() */ |
812 | oldprevlen = PL_oldbufptr - PL_bufend; | |
813 | oldoldprevlen = PL_oldoldbufptr - PL_bufend; | |
814 | if (PL_last_uni) | |
815 | oldunilen = PL_last_uni - PL_bufend; | |
816 | if (PL_last_lop) | |
817 | oldloplen = PL_last_lop - PL_bufend; | |
3280af22 NIS |
818 | PL_linestart = PL_bufptr = s + prevlen; |
819 | PL_bufend = s + SvCUR(PL_linestr); | |
820 | s = PL_bufptr; | |
09bef843 SB |
821 | PL_oldbufptr = s + oldprevlen; |
822 | PL_oldoldbufptr = s + oldoldprevlen; | |
823 | if (PL_last_uni) | |
824 | PL_last_uni = s + oldunilen; | |
825 | if (PL_last_lop) | |
826 | PL_last_lop = s + oldloplen; | |
a0d0e21e | 827 | incline(s); |
ffb4593c NT |
828 | |
829 | /* debugger active and we're not compiling the debugger code, | |
830 | * so store the line into the debugger's array of lines | |
831 | */ | |
3280af22 | 832 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
9d4ba2ae | 833 | SV * const sv = NEWSV(85,0); |
8990e307 LW |
834 | |
835 | sv_upgrade(sv, SVt_PVMG); | |
3280af22 | 836 | sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr); |
0ac0412a | 837 | (void)SvIOK_on(sv); |
45977657 | 838 | SvIV_set(sv, 0); |
57843af0 | 839 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
8990e307 | 840 | } |
463ee0b2 | 841 | } |
a687059c | 842 | } |
378cc40b | 843 | |
ffb4593c NT |
844 | /* |
845 | * S_check_uni | |
846 | * Check the unary operators to ensure there's no ambiguity in how they're | |
847 | * used. An ambiguous piece of code would be: | |
848 | * rand + 5 | |
849 | * This doesn't mean rand() + 5. Because rand() is a unary operator, | |
850 | * the +5 is its argument. | |
851 | */ | |
852 | ||
76e3520e | 853 | STATIC void |
cea2e8a9 | 854 | S_check_uni(pTHX) |
ba106d47 | 855 | { |
2f3197b3 | 856 | char *s; |
a0d0e21e | 857 | char *t; |
2f3197b3 | 858 | |
3280af22 | 859 | if (PL_oldoldbufptr != PL_last_uni) |
2f3197b3 | 860 | return; |
3280af22 NIS |
861 | while (isSPACE(*PL_last_uni)) |
862 | PL_last_uni++; | |
7e2040f0 | 863 | for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ; |
3280af22 | 864 | if ((t = strchr(s, '(')) && t < PL_bufptr) |
a0d0e21e | 865 | return; |
0453d815 | 866 | if (ckWARN_d(WARN_AMBIGUOUS)){ |
9d4ba2ae | 867 | const char ch = *s; |
0453d815 | 868 | *s = '\0'; |
9014280d | 869 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
2d5ccbba | 870 | "Warning: Use of \"%s\" without parentheses is ambiguous", |
0453d815 PM |
871 | PL_last_uni); |
872 | *s = ch; | |
873 | } | |
2f3197b3 LW |
874 | } |
875 | ||
ffb4593c NT |
876 | /* |
877 | * LOP : macro to build a list operator. Its behaviour has been replaced | |
878 | * with a subroutine, S_lop() for which LOP is just another name. | |
879 | */ | |
880 | ||
a0d0e21e LW |
881 | #define LOP(f,x) return lop(f,x,s) |
882 | ||
ffb4593c NT |
883 | /* |
884 | * S_lop | |
885 | * Build a list operator (or something that might be one). The rules: | |
886 | * - if we have a next token, then it's a list operator [why?] | |
887 | * - if the next thing is an opening paren, then it's a function | |
888 | * - else it's a list operator | |
889 | */ | |
890 | ||
76e3520e | 891 | STATIC I32 |
a0be28da | 892 | S_lop(pTHX_ I32 f, int x, char *s) |
ffed7fef | 893 | { |
79072805 | 894 | yylval.ival = f; |
35c8bce7 | 895 | CLINE; |
3280af22 NIS |
896 | PL_expect = x; |
897 | PL_bufptr = s; | |
898 | PL_last_lop = PL_oldbufptr; | |
eb160463 | 899 | PL_last_lop_op = (OPCODE)f; |
3280af22 | 900 | if (PL_nexttoke) |
bbf60fe6 | 901 | return REPORT(LSTOP); |
79072805 | 902 | if (*s == '(') |
bbf60fe6 | 903 | return REPORT(FUNC); |
79072805 LW |
904 | s = skipspace(s); |
905 | if (*s == '(') | |
bbf60fe6 | 906 | return REPORT(FUNC); |
79072805 | 907 | else |
bbf60fe6 | 908 | return REPORT(LSTOP); |
79072805 LW |
909 | } |
910 | ||
ffb4593c NT |
911 | /* |
912 | * S_force_next | |
9cbb5ea2 | 913 | * When the lexer realizes it knows the next token (for instance, |
ffb4593c | 914 | * it is reordering tokens for the parser) then it can call S_force_next |
9cbb5ea2 GS |
915 | * to know what token to return the next time the lexer is called. Caller |
916 | * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer | |
917 | * handles the token correctly. | |
ffb4593c NT |
918 | */ |
919 | ||
4e553d73 | 920 | STATIC void |
cea2e8a9 | 921 | S_force_next(pTHX_ I32 type) |
79072805 | 922 | { |
3280af22 NIS |
923 | PL_nexttype[PL_nexttoke] = type; |
924 | PL_nexttoke++; | |
925 | if (PL_lex_state != LEX_KNOWNEXT) { | |
926 | PL_lex_defer = PL_lex_state; | |
927 | PL_lex_expect = PL_expect; | |
928 | PL_lex_state = LEX_KNOWNEXT; | |
79072805 LW |
929 | } |
930 | } | |
931 | ||
d0a148a6 NC |
932 | STATIC SV * |
933 | S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len) | |
934 | { | |
9d4ba2ae | 935 | SV * const sv = newSVpvn(start,len); |
bfed75c6 | 936 | if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len)) |
d0a148a6 NC |
937 | SvUTF8_on(sv); |
938 | return sv; | |
939 | } | |
940 | ||
ffb4593c NT |
941 | /* |
942 | * S_force_word | |
943 | * When the lexer knows the next thing is a word (for instance, it has | |
944 | * just seen -> and it knows that the next char is a word char, then | |
945 | * it calls S_force_word to stick the next word into the PL_next lookahead. | |
946 | * | |
947 | * Arguments: | |
b1b65b59 | 948 | * char *start : buffer position (must be within PL_linestr) |
ffb4593c NT |
949 | * int token : PL_next will be this type of bare word (e.g., METHOD,WORD) |
950 | * int check_keyword : if true, Perl checks to make sure the word isn't | |
951 | * a keyword (do this if the word is a label, e.g. goto FOO) | |
952 | * int allow_pack : if true, : characters will also be allowed (require, | |
953 | * use, etc. do this) | |
9cbb5ea2 | 954 | * int allow_initial_tick : used by the "sub" lexer only. |
ffb4593c NT |
955 | */ |
956 | ||
76e3520e | 957 | STATIC char * |
cea2e8a9 | 958 | S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick) |
79072805 | 959 | { |
463ee0b2 LW |
960 | register char *s; |
961 | STRLEN len; | |
4e553d73 | 962 | |
463ee0b2 LW |
963 | start = skipspace(start); |
964 | s = start; | |
7e2040f0 | 965 | if (isIDFIRST_lazy_if(s,UTF) || |
a0d0e21e | 966 | (allow_pack && *s == ':') || |
15f0808c | 967 | (allow_initial_tick && *s == '\'') ) |
a0d0e21e | 968 | { |
3280af22 NIS |
969 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len); |
970 | if (check_keyword && keyword(PL_tokenbuf, len)) | |
463ee0b2 LW |
971 | return start; |
972 | if (token == METHOD) { | |
973 | s = skipspace(s); | |
974 | if (*s == '(') | |
3280af22 | 975 | PL_expect = XTERM; |
463ee0b2 | 976 | else { |
3280af22 | 977 | PL_expect = XOPERATOR; |
463ee0b2 | 978 | } |
79072805 | 979 | } |
d0a148a6 NC |
980 | PL_nextval[PL_nexttoke].opval |
981 | = (OP*)newSVOP(OP_CONST,0, | |
982 | S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len)); | |
3280af22 | 983 | PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE; |
79072805 LW |
984 | force_next(token); |
985 | } | |
986 | return s; | |
987 | } | |
988 | ||
ffb4593c NT |
989 | /* |
990 | * S_force_ident | |
9cbb5ea2 | 991 | * Called when the lexer wants $foo *foo &foo etc, but the program |
ffb4593c NT |
992 | * text only contains the "foo" portion. The first argument is a pointer |
993 | * to the "foo", and the second argument is the type symbol to prefix. | |
994 | * Forces the next token to be a "WORD". | |
9cbb5ea2 | 995 | * Creates the symbol if it didn't already exist (via gv_fetchpv()). |
ffb4593c NT |
996 | */ |
997 | ||
76e3520e | 998 | STATIC void |
bfed75c6 | 999 | S_force_ident(pTHX_ register const char *s, int kind) |
79072805 LW |
1000 | { |
1001 | if (s && *s) { | |
bfed75c6 | 1002 | OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0)); |
3280af22 | 1003 | PL_nextval[PL_nexttoke].opval = o; |
79072805 | 1004 | force_next(WORD); |
748a9306 | 1005 | if (kind) { |
11343788 | 1006 | o->op_private = OPpCONST_ENTERED; |
55497cff | 1007 | /* XXX see note in pp_entereval() for why we forgo typo |
1008 | warnings if the symbol must be introduced in an eval. | |
1009 | GSAR 96-10-12 */ | |
3280af22 | 1010 | gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE, |
a0d0e21e LW |
1011 | kind == '$' ? SVt_PV : |
1012 | kind == '@' ? SVt_PVAV : | |
1013 | kind == '%' ? SVt_PVHV : | |
1014 | SVt_PVGV | |
1015 | ); | |
748a9306 | 1016 | } |
79072805 LW |
1017 | } |
1018 | } | |
1019 | ||
1571675a GS |
1020 | NV |
1021 | Perl_str_to_version(pTHX_ SV *sv) | |
1022 | { | |
1023 | NV retval = 0.0; | |
1024 | NV nshift = 1.0; | |
1025 | STRLEN len; | |
cfd0369c | 1026 | const char *start = SvPV_const(sv,len); |
9d4ba2ae | 1027 | const char * const end = start + len; |
504618e9 | 1028 | const bool utf = SvUTF8(sv) ? TRUE : FALSE; |
1571675a | 1029 | while (start < end) { |
ba210ebe | 1030 | STRLEN skip; |
1571675a GS |
1031 | UV n; |
1032 | if (utf) | |
9041c2e3 | 1033 | n = utf8n_to_uvchr((U8*)start, len, &skip, 0); |
1571675a GS |
1034 | else { |
1035 | n = *(U8*)start; | |
1036 | skip = 1; | |
1037 | } | |
1038 | retval += ((NV)n)/nshift; | |
1039 | start += skip; | |
1040 | nshift *= 1000; | |
1041 | } | |
1042 | return retval; | |
1043 | } | |
1044 | ||
4e553d73 | 1045 | /* |
ffb4593c NT |
1046 | * S_force_version |
1047 | * Forces the next token to be a version number. | |
e759cc13 RGS |
1048 | * If the next token appears to be an invalid version number, (e.g. "v2b"), |
1049 | * and if "guessing" is TRUE, then no new token is created (and the caller | |
1050 | * must use an alternative parsing method). | |
ffb4593c NT |
1051 | */ |
1052 | ||
76e3520e | 1053 | STATIC char * |
e759cc13 | 1054 | S_force_version(pTHX_ char *s, int guessing) |
89bfa8cd | 1055 | { |
1056 | OP *version = Nullop; | |
44dcb63b | 1057 | char *d; |
89bfa8cd | 1058 | |
1059 | s = skipspace(s); | |
1060 | ||
44dcb63b | 1061 | d = s; |
dd629d5b | 1062 | if (*d == 'v') |
44dcb63b | 1063 | d++; |
44dcb63b | 1064 | if (isDIGIT(*d)) { |
e759cc13 RGS |
1065 | while (isDIGIT(*d) || *d == '_' || *d == '.') |
1066 | d++; | |
9f3d182e | 1067 | if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) { |
dd629d5b | 1068 | SV *ver; |
b73d6f50 | 1069 | s = scan_num(s, &yylval); |
89bfa8cd | 1070 | version = yylval.opval; |
dd629d5b GS |
1071 | ver = cSVOPx(version)->op_sv; |
1072 | if (SvPOK(ver) && !SvNIOK(ver)) { | |
862a34c6 | 1073 | SvUPGRADE(ver, SVt_PVNV); |
9d6ce603 | 1074 | SvNV_set(ver, str_to_version(ver)); |
1571675a | 1075 | SvNOK_on(ver); /* hint that it is a version */ |
44dcb63b | 1076 | } |
89bfa8cd | 1077 | } |
e759cc13 RGS |
1078 | else if (guessing) |
1079 | return s; | |
89bfa8cd | 1080 | } |
1081 | ||
1082 | /* NOTE: The parser sees the package name and the VERSION swapped */ | |
3280af22 | 1083 | PL_nextval[PL_nexttoke].opval = version; |
4e553d73 | 1084 | force_next(WORD); |
89bfa8cd | 1085 | |
e759cc13 | 1086 | return s; |
89bfa8cd | 1087 | } |
1088 | ||
ffb4593c NT |
1089 | /* |
1090 | * S_tokeq | |
1091 | * Tokenize a quoted string passed in as an SV. It finds the next | |
1092 | * chunk, up to end of string or a backslash. It may make a new | |
1093 | * SV containing that chunk (if HINT_NEW_STRING is on). It also | |
1094 | * turns \\ into \. | |
1095 | */ | |
1096 | ||
76e3520e | 1097 | STATIC SV * |
cea2e8a9 | 1098 | S_tokeq(pTHX_ SV *sv) |
79072805 LW |
1099 | { |
1100 | register char *s; | |
1101 | register char *send; | |
1102 | register char *d; | |
b3ac6de7 IZ |
1103 | STRLEN len = 0; |
1104 | SV *pv = sv; | |
79072805 LW |
1105 | |
1106 | if (!SvLEN(sv)) | |
b3ac6de7 | 1107 | goto finish; |
79072805 | 1108 | |
a0d0e21e | 1109 | s = SvPV_force(sv, len); |
21a311ee | 1110 | if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1) |
b3ac6de7 | 1111 | goto finish; |
463ee0b2 | 1112 | send = s + len; |
79072805 LW |
1113 | while (s < send && *s != '\\') |
1114 | s++; | |
1115 | if (s == send) | |
b3ac6de7 | 1116 | goto finish; |
79072805 | 1117 | d = s; |
be4731d2 | 1118 | if ( PL_hints & HINT_NEW_STRING ) { |
95a20fc0 | 1119 | pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len)); |
be4731d2 NIS |
1120 | if (SvUTF8(sv)) |
1121 | SvUTF8_on(pv); | |
1122 | } | |
79072805 LW |
1123 | while (s < send) { |
1124 | if (*s == '\\') { | |
a0d0e21e | 1125 | if (s + 1 < send && (s[1] == '\\')) |
79072805 LW |
1126 | s++; /* all that, just for this */ |
1127 | } | |
1128 | *d++ = *s++; | |
1129 | } | |
1130 | *d = '\0'; | |
95a20fc0 | 1131 | SvCUR_set(sv, d - SvPVX_const(sv)); |
b3ac6de7 | 1132 | finish: |
3280af22 | 1133 | if ( PL_hints & HINT_NEW_STRING ) |
b3ac6de7 | 1134 | return new_constant(NULL, 0, "q", sv, pv, "q"); |
79072805 LW |
1135 | return sv; |
1136 | } | |
1137 | ||
ffb4593c NT |
1138 | /* |
1139 | * Now come three functions related to double-quote context, | |
1140 | * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when | |
1141 | * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They | |
1142 | * interact with PL_lex_state, and create fake ( ... ) argument lists | |
1143 | * to handle functions and concatenation. | |
1144 | * They assume that whoever calls them will be setting up a fake | |
1145 | * join call, because each subthing puts a ',' after it. This lets | |
1146 | * "lower \luPpEr" | |
1147 | * become | |
1148 | * join($, , 'lower ', lcfirst( 'uPpEr', ) ,) | |
1149 | * | |
1150 | * (I'm not sure whether the spurious commas at the end of lcfirst's | |
1151 | * arguments and join's arguments are created or not). | |
1152 | */ | |
1153 | ||
1154 | /* | |
1155 | * S_sublex_start | |
1156 | * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST). | |
1157 | * | |
1158 | * Pattern matching will set PL_lex_op to the pattern-matching op to | |
1159 | * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise). | |
1160 | * | |
1161 | * OP_CONST and OP_READLINE are easy--just make the new op and return. | |
1162 | * | |
1163 | * Everything else becomes a FUNC. | |
1164 | * | |
1165 | * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we | |
1166 | * had an OP_CONST or OP_READLINE). This just sets us up for a | |
1167 | * call to S_sublex_push(). | |
1168 | */ | |
1169 | ||
76e3520e | 1170 | STATIC I32 |
cea2e8a9 | 1171 | S_sublex_start(pTHX) |
79072805 | 1172 | { |
0d46e09a | 1173 | register const I32 op_type = yylval.ival; |
79072805 LW |
1174 | |
1175 | if (op_type == OP_NULL) { | |
3280af22 NIS |
1176 | yylval.opval = PL_lex_op; |
1177 | PL_lex_op = Nullop; | |
79072805 LW |
1178 | return THING; |
1179 | } | |
1180 | if (op_type == OP_CONST || op_type == OP_READLINE) { | |
3280af22 | 1181 | SV *sv = tokeq(PL_lex_stuff); |
b3ac6de7 IZ |
1182 | |
1183 | if (SvTYPE(sv) == SVt_PVIV) { | |
1184 | /* Overloaded constants, nothing fancy: Convert to SVt_PV: */ | |
1185 | STRLEN len; | |
cfd0369c | 1186 | const char *p = SvPV_const(sv, len); |
f54cb97a | 1187 | SV * const nsv = newSVpvn(p, len); |
01ec43d0 GS |
1188 | if (SvUTF8(sv)) |
1189 | SvUTF8_on(nsv); | |
b3ac6de7 IZ |
1190 | SvREFCNT_dec(sv); |
1191 | sv = nsv; | |
4e553d73 | 1192 | } |
b3ac6de7 | 1193 | yylval.opval = (OP*)newSVOP(op_type, 0, sv); |
3280af22 | 1194 | PL_lex_stuff = Nullsv; |
6f33ba73 RGS |
1195 | /* Allow <FH> // "foo" */ |
1196 | if (op_type == OP_READLINE) | |
1197 | PL_expect = XTERMORDORDOR; | |
79072805 LW |
1198 | return THING; |
1199 | } | |
1200 | ||
3280af22 NIS |
1201 | PL_sublex_info.super_state = PL_lex_state; |
1202 | PL_sublex_info.sub_inwhat = op_type; | |
1203 | PL_sublex_info.sub_op = PL_lex_op; | |
1204 | PL_lex_state = LEX_INTERPPUSH; | |
55497cff | 1205 | |
3280af22 NIS |
1206 | PL_expect = XTERM; |
1207 | if (PL_lex_op) { | |
1208 | yylval.opval = PL_lex_op; | |
1209 | PL_lex_op = Nullop; | |
55497cff | 1210 | return PMFUNC; |
1211 | } | |
1212 | else | |
1213 | return FUNC; | |
1214 | } | |
1215 | ||
ffb4593c NT |
1216 | /* |
1217 | * S_sublex_push | |
1218 | * Create a new scope to save the lexing state. The scope will be | |
1219 | * ended in S_sublex_done. Returns a '(', starting the function arguments | |
1220 | * to the uc, lc, etc. found before. | |
1221 | * Sets PL_lex_state to LEX_INTERPCONCAT. | |
1222 | */ | |
1223 | ||
76e3520e | 1224 | STATIC I32 |
cea2e8a9 | 1225 | S_sublex_push(pTHX) |
55497cff | 1226 | { |
27da23d5 | 1227 | dVAR; |
f46d017c | 1228 | ENTER; |
55497cff | 1229 | |
3280af22 NIS |
1230 | PL_lex_state = PL_sublex_info.super_state; |
1231 | SAVEI32(PL_lex_dojoin); | |
1232 | SAVEI32(PL_lex_brackets); | |
3280af22 NIS |
1233 | SAVEI32(PL_lex_casemods); |
1234 | SAVEI32(PL_lex_starts); | |
1235 | SAVEI32(PL_lex_state); | |
7766f137 | 1236 | SAVEVPTR(PL_lex_inpat); |
3280af22 | 1237 | SAVEI32(PL_lex_inwhat); |
57843af0 | 1238 | SAVECOPLINE(PL_curcop); |
3280af22 | 1239 | SAVEPPTR(PL_bufptr); |
8452ff4b | 1240 | SAVEPPTR(PL_bufend); |
3280af22 NIS |
1241 | SAVEPPTR(PL_oldbufptr); |
1242 | SAVEPPTR(PL_oldoldbufptr); | |
207e3d1a JH |
1243 | SAVEPPTR(PL_last_lop); |
1244 | SAVEPPTR(PL_last_uni); | |
3280af22 NIS |
1245 | SAVEPPTR(PL_linestart); |
1246 | SAVESPTR(PL_linestr); | |
8edd5f42 RGS |
1247 | SAVEGENERICPV(PL_lex_brackstack); |
1248 | SAVEGENERICPV(PL_lex_casestack); | |
3280af22 NIS |
1249 | |
1250 | PL_linestr = PL_lex_stuff; | |
1251 | PL_lex_stuff = Nullsv; | |
1252 | ||
9cbb5ea2 GS |
1253 | PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart |
1254 | = SvPVX(PL_linestr); | |
3280af22 | 1255 | PL_bufend += SvCUR(PL_linestr); |
207e3d1a | 1256 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 NIS |
1257 | SAVEFREESV(PL_linestr); |
1258 | ||
1259 | PL_lex_dojoin = FALSE; | |
1260 | PL_lex_brackets = 0; | |
a02a5408 JC |
1261 | Newx(PL_lex_brackstack, 120, char); |
1262 | Newx(PL_lex_casestack, 12, char); | |
3280af22 NIS |
1263 | PL_lex_casemods = 0; |
1264 | *PL_lex_casestack = '\0'; | |
1265 | PL_lex_starts = 0; | |
1266 | PL_lex_state = LEX_INTERPCONCAT; | |
eb160463 | 1267 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
3280af22 NIS |
1268 | |
1269 | PL_lex_inwhat = PL_sublex_info.sub_inwhat; | |
1270 | if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST) | |
1271 | PL_lex_inpat = PL_sublex_info.sub_op; | |
79072805 | 1272 | else |
3280af22 | 1273 | PL_lex_inpat = Nullop; |
79072805 | 1274 | |
55497cff | 1275 | return '('; |
79072805 LW |
1276 | } |
1277 | ||
ffb4593c NT |
1278 | /* |
1279 | * S_sublex_done | |
1280 | * Restores lexer state after a S_sublex_push. | |
1281 | */ | |
1282 | ||
76e3520e | 1283 | STATIC I32 |
cea2e8a9 | 1284 | S_sublex_done(pTHX) |
79072805 | 1285 | { |
27da23d5 | 1286 | dVAR; |
3280af22 | 1287 | if (!PL_lex_starts++) { |
9d4ba2ae | 1288 | SV * const sv = newSVpvn("",0); |
9aa983d2 JH |
1289 | if (SvUTF8(PL_linestr)) |
1290 | SvUTF8_on(sv); | |
3280af22 | 1291 | PL_expect = XOPERATOR; |
9aa983d2 | 1292 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
79072805 LW |
1293 | return THING; |
1294 | } | |
1295 | ||
3280af22 NIS |
1296 | if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */ |
1297 | PL_lex_state = LEX_INTERPCASEMOD; | |
cea2e8a9 | 1298 | return yylex(); |
79072805 LW |
1299 | } |
1300 | ||
ffb4593c | 1301 | /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */ |
3280af22 NIS |
1302 | if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) { |
1303 | PL_linestr = PL_lex_repl; | |
1304 | PL_lex_inpat = 0; | |
1305 | PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr); | |
1306 | PL_bufend += SvCUR(PL_linestr); | |
207e3d1a | 1307 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 NIS |
1308 | SAVEFREESV(PL_linestr); |
1309 | PL_lex_dojoin = FALSE; | |
1310 | PL_lex_brackets = 0; | |
3280af22 NIS |
1311 | PL_lex_casemods = 0; |
1312 | *PL_lex_casestack = '\0'; | |
1313 | PL_lex_starts = 0; | |
25da4f38 | 1314 | if (SvEVALED(PL_lex_repl)) { |
3280af22 NIS |
1315 | PL_lex_state = LEX_INTERPNORMAL; |
1316 | PL_lex_starts++; | |
e9fa98b2 HS |
1317 | /* we don't clear PL_lex_repl here, so that we can check later |
1318 | whether this is an evalled subst; that means we rely on the | |
1319 | logic to ensure sublex_done() is called again only via the | |
1320 | branch (in yylex()) that clears PL_lex_repl, else we'll loop */ | |
79072805 | 1321 | } |
e9fa98b2 | 1322 | else { |
3280af22 | 1323 | PL_lex_state = LEX_INTERPCONCAT; |
e9fa98b2 HS |
1324 | PL_lex_repl = Nullsv; |
1325 | } | |
79072805 | 1326 | return ','; |
ffed7fef LW |
1327 | } |
1328 | else { | |
f46d017c | 1329 | LEAVE; |
3280af22 NIS |
1330 | PL_bufend = SvPVX(PL_linestr); |
1331 | PL_bufend += SvCUR(PL_linestr); | |
1332 | PL_expect = XOPERATOR; | |
09bef843 | 1333 | PL_sublex_info.sub_inwhat = 0; |
79072805 | 1334 | return ')'; |
ffed7fef LW |
1335 | } |
1336 | } | |
1337 | ||
02aa26ce NT |
1338 | /* |
1339 | scan_const | |
1340 | ||
1341 | Extracts a pattern, double-quoted string, or transliteration. This | |
1342 | is terrifying code. | |
1343 | ||
3280af22 NIS |
1344 | It looks at lex_inwhat and PL_lex_inpat to find out whether it's |
1345 | processing a pattern (PL_lex_inpat is true), a transliteration | |
02aa26ce NT |
1346 | (lex_inwhat & OP_TRANS is true), or a double-quoted string. |
1347 | ||
9b599b2a GS |
1348 | Returns a pointer to the character scanned up to. Iff this is |
1349 | advanced from the start pointer supplied (ie if anything was | |
1350 | successfully parsed), will leave an OP for the substring scanned | |
1351 | in yylval. Caller must intuit reason for not parsing further | |
1352 | by looking at the next characters herself. | |
1353 | ||
02aa26ce NT |
1354 | In patterns: |
1355 | backslashes: | |
1356 | double-quoted style: \r and \n | |
1357 | regexp special ones: \D \s | |
1358 | constants: \x3 | |
1359 | backrefs: \1 (deprecated in substitution replacements) | |
1360 | case and quoting: \U \Q \E | |
1361 | stops on @ and $, but not for $ as tail anchor | |
1362 | ||
1363 | In transliterations: | |
1364 | characters are VERY literal, except for - not at the start or end | |
1365 | of the string, which indicates a range. scan_const expands the | |
1366 | range to the full set of intermediate characters. | |
1367 | ||
1368 | In double-quoted strings: | |
1369 | backslashes: | |
1370 | double-quoted style: \r and \n | |
1371 | constants: \x3 | |
1372 | backrefs: \1 (deprecated) | |
1373 | case and quoting: \U \Q \E | |
1374 | stops on @ and $ | |
1375 | ||
1376 | scan_const does *not* construct ops to handle interpolated strings. | |
1377 | It stops processing as soon as it finds an embedded $ or @ variable | |
1378 | and leaves it to the caller to work out what's going on. | |
1379 | ||
da6eedaa | 1380 | @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo. |
02aa26ce NT |
1381 | |
1382 | $ in pattern could be $foo or could be tail anchor. Assumption: | |
1383 | it's a tail anchor if $ is the last thing in the string, or if it's | |
1384 | followed by one of ")| \n\t" | |
1385 | ||
1386 | \1 (backreferences) are turned into $1 | |
1387 | ||
1388 | The structure of the code is | |
1389 | while (there's a character to process) { | |
1390 | handle transliteration ranges | |
1391 | skip regexp comments | |
1392 | skip # initiated comments in //x patterns | |
1393 | check for embedded @foo | |
1394 | check for embedded scalars | |
1395 | if (backslash) { | |
1396 | leave intact backslashes from leave (below) | |
1397 | deprecate \1 in strings and sub replacements | |
1398 | handle string-changing backslashes \l \U \Q \E, etc. | |
1399 | switch (what was escaped) { | |
1400 | handle - in a transliteration (becomes a literal -) | |
1401 | handle \132 octal characters | |
1402 | handle 0x15 hex characters | |
1403 | handle \cV (control V) | |
1404 | handle printf backslashes (\f, \r, \n, etc) | |
1405 | } (end switch) | |
1406 | } (end if backslash) | |
1407 | } (end while character to read) | |
4e553d73 | 1408 | |
02aa26ce NT |
1409 | */ |
1410 | ||
76e3520e | 1411 | STATIC char * |
cea2e8a9 | 1412 | S_scan_const(pTHX_ char *start) |
79072805 | 1413 | { |
3280af22 | 1414 | register char *send = PL_bufend; /* end of the constant */ |
02aa26ce NT |
1415 | SV *sv = NEWSV(93, send - start); /* sv for the constant */ |
1416 | register char *s = start; /* start of the constant */ | |
1417 | register char *d = SvPVX(sv); /* destination for copies */ | |
1418 | bool dorange = FALSE; /* are we in a translit range? */ | |
c2e66d9e | 1419 | bool didrange = FALSE; /* did we just finish a range? */ |
2b9d42f0 NIS |
1420 | I32 has_utf8 = FALSE; /* Output constant is UTF8 */ |
1421 | I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */ | |
012bcf8d | 1422 | UV uv; |
4c3a8340 TS |
1423 | #ifdef EBCDIC |
1424 | UV literal_endpoint = 0; | |
1425 | #endif | |
012bcf8d | 1426 | |
dff6d3cd | 1427 | const char *leaveit = /* set of acceptably-backslashed characters */ |
3280af22 | 1428 | PL_lex_inpat |
b6d5fef8 | 1429 | ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#" |
9b599b2a | 1430 | : ""; |
79072805 | 1431 | |
2b9d42f0 NIS |
1432 | if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) { |
1433 | /* If we are doing a trans and we know we want UTF8 set expectation */ | |
1434 | has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF); | |
1435 | this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); | |
1436 | } | |
1437 | ||
1438 | ||
79072805 | 1439 | while (s < send || dorange) { |
02aa26ce | 1440 | /* get transliterations out of the way (they're most literal) */ |
3280af22 | 1441 | if (PL_lex_inwhat == OP_TRANS) { |
02aa26ce | 1442 | /* expand a range A-Z to the full set of characters. AIE! */ |
79072805 | 1443 | if (dorange) { |
1ba5c669 JH |
1444 | I32 i; /* current expanded character */ |
1445 | I32 min; /* first character in range */ | |
1446 | I32 max; /* last character in range */ | |
02aa26ce | 1447 | |
2b9d42f0 | 1448 | if (has_utf8) { |
9d4ba2ae | 1449 | char * const c = (char*)utf8_hop((U8*)d, -1); |
8973db79 JH |
1450 | char *e = d++; |
1451 | while (e-- > c) | |
1452 | *(e + 1) = *e; | |
25716404 | 1453 | *c = (char)UTF_TO_NATIVE(0xff); |
8973db79 JH |
1454 | /* mark the range as done, and continue */ |
1455 | dorange = FALSE; | |
1456 | didrange = TRUE; | |
1457 | continue; | |
1458 | } | |
2b9d42f0 | 1459 | |
95a20fc0 | 1460 | i = d - SvPVX_const(sv); /* remember current offset */ |
9cbb5ea2 GS |
1461 | SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */ |
1462 | d = SvPVX(sv) + i; /* refresh d after realloc */ | |
02aa26ce NT |
1463 | d -= 2; /* eat the first char and the - */ |
1464 | ||
8ada0baa JH |
1465 | min = (U8)*d; /* first char in range */ |
1466 | max = (U8)d[1]; /* last char in range */ | |
1467 | ||
c2e66d9e | 1468 | if (min > max) { |
01ec43d0 | 1469 | Perl_croak(aTHX_ |
d1573ac7 | 1470 | "Invalid range \"%c-%c\" in transliteration operator", |
1ba5c669 | 1471 | (char)min, (char)max); |
c2e66d9e GS |
1472 | } |
1473 | ||
c7f1f016 | 1474 | #ifdef EBCDIC |
4c3a8340 TS |
1475 | if (literal_endpoint == 2 && |
1476 | ((isLOWER(min) && isLOWER(max)) || | |
1477 | (isUPPER(min) && isUPPER(max)))) { | |
8ada0baa JH |
1478 | if (isLOWER(min)) { |
1479 | for (i = min; i <= max; i++) | |
1480 | if (isLOWER(i)) | |
db42d148 | 1481 | *d++ = NATIVE_TO_NEED(has_utf8,i); |
8ada0baa JH |
1482 | } else { |
1483 | for (i = min; i <= max; i++) | |
1484 | if (isUPPER(i)) | |
db42d148 | 1485 | *d++ = NATIVE_TO_NEED(has_utf8,i); |
8ada0baa JH |
1486 | } |
1487 | } | |
1488 | else | |
1489 | #endif | |
1490 | for (i = min; i <= max; i++) | |
eb160463 | 1491 | *d++ = (char)i; |
02aa26ce NT |
1492 | |
1493 | /* mark the range as done, and continue */ | |
79072805 | 1494 | dorange = FALSE; |
01ec43d0 | 1495 | didrange = TRUE; |
4c3a8340 TS |
1496 | #ifdef EBCDIC |
1497 | literal_endpoint = 0; | |
1498 | #endif | |
79072805 | 1499 | continue; |
4e553d73 | 1500 | } |
02aa26ce NT |
1501 | |
1502 | /* range begins (ignore - as first or last char) */ | |
79072805 | 1503 | else if (*s == '-' && s+1 < send && s != start) { |
4e553d73 | 1504 | if (didrange) { |
1fafa243 | 1505 | Perl_croak(aTHX_ "Ambiguous range in transliteration operator"); |
01ec43d0 | 1506 | } |
2b9d42f0 | 1507 | if (has_utf8) { |
25716404 | 1508 | *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */ |
a0ed51b3 LW |
1509 | s++; |
1510 | continue; | |
1511 | } | |
79072805 LW |
1512 | dorange = TRUE; |
1513 | s++; | |
01ec43d0 GS |
1514 | } |
1515 | else { | |
1516 | didrange = FALSE; | |
4c3a8340 TS |
1517 | #ifdef EBCDIC |
1518 | literal_endpoint = 0; | |
1519 | #endif | |
01ec43d0 | 1520 | } |
79072805 | 1521 | } |
02aa26ce NT |
1522 | |
1523 | /* if we get here, we're not doing a transliteration */ | |
1524 | ||
0f5d15d6 IZ |
1525 | /* skip for regexp comments /(?#comment)/ and code /(?{code})/, |
1526 | except for the last char, which will be done separately. */ | |
3280af22 | 1527 | else if (*s == '(' && PL_lex_inpat && s[1] == '?') { |
cc6b7395 | 1528 | if (s[2] == '#') { |
e994fd66 | 1529 | while (s+1 < send && *s != ')') |
db42d148 | 1530 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
155aba94 GS |
1531 | } |
1532 | else if (s[2] == '{' /* This should match regcomp.c */ | |
1533 | || ((s[2] == 'p' || s[2] == '?') && s[3] == '{')) | |
1534 | { | |
cc6b7395 | 1535 | I32 count = 1; |
0f5d15d6 | 1536 | char *regparse = s + (s[2] == '{' ? 3 : 4); |
cc6b7395 IZ |
1537 | char c; |
1538 | ||
d9f97599 GS |
1539 | while (count && (c = *regparse)) { |
1540 | if (c == '\\' && regparse[1]) | |
1541 | regparse++; | |
4e553d73 | 1542 | else if (c == '{') |
cc6b7395 | 1543 | count++; |
4e553d73 | 1544 | else if (c == '}') |
cc6b7395 | 1545 | count--; |
d9f97599 | 1546 | regparse++; |
cc6b7395 | 1547 | } |
e994fd66 | 1548 | if (*regparse != ')') |
5bdf89e7 | 1549 | regparse--; /* Leave one char for continuation. */ |
0f5d15d6 | 1550 | while (s < regparse) |
db42d148 | 1551 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
cc6b7395 | 1552 | } |
748a9306 | 1553 | } |
02aa26ce NT |
1554 | |
1555 | /* likewise skip #-initiated comments in //x patterns */ | |
3280af22 NIS |
1556 | else if (*s == '#' && PL_lex_inpat && |
1557 | ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) { | |
748a9306 | 1558 | while (s+1 < send && *s != '\n') |
db42d148 | 1559 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
748a9306 | 1560 | } |
02aa26ce | 1561 | |
5d1d4326 | 1562 | /* check for embedded arrays |
da6eedaa | 1563 | (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-) |
5d1d4326 | 1564 | */ |
7e2040f0 | 1565 | else if (*s == '@' && s[1] |
5d1d4326 | 1566 | && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1]))) |
79072805 | 1567 | break; |
02aa26ce NT |
1568 | |
1569 | /* check for embedded scalars. only stop if we're sure it's a | |
1570 | variable. | |
1571 | */ | |
79072805 | 1572 | else if (*s == '$') { |
3280af22 | 1573 | if (!PL_lex_inpat) /* not a regexp, so $ must be var */ |
79072805 | 1574 | break; |
6002328a | 1575 | if (s + 1 < send && !strchr("()| \r\n\t", s[1])) |
79072805 LW |
1576 | break; /* in regexp, $ might be tail anchor */ |
1577 | } | |
02aa26ce | 1578 | |
2b9d42f0 NIS |
1579 | /* End of else if chain - OP_TRANS rejoin rest */ |
1580 | ||
02aa26ce | 1581 | /* backslashes */ |
79072805 LW |
1582 | if (*s == '\\' && s+1 < send) { |
1583 | s++; | |
02aa26ce NT |
1584 | |
1585 | /* some backslashes we leave behind */ | |
c9f97d15 | 1586 | if (*leaveit && *s && strchr(leaveit, *s)) { |
db42d148 NIS |
1587 | *d++ = NATIVE_TO_NEED(has_utf8,'\\'); |
1588 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); | |
79072805 LW |
1589 | continue; |
1590 | } | |
02aa26ce NT |
1591 | |
1592 | /* deprecate \1 in strings and substitution replacements */ | |
3280af22 | 1593 | if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat && |
a0d0e21e | 1594 | isDIGIT(*s) && *s != '0' && !isDIGIT(s[1])) |
79072805 | 1595 | { |
599cee73 | 1596 | if (ckWARN(WARN_SYNTAX)) |
9014280d | 1597 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s); |
79072805 LW |
1598 | *--s = '$'; |
1599 | break; | |
1600 | } | |
02aa26ce NT |
1601 | |
1602 | /* string-change backslash escapes */ | |
3280af22 | 1603 | if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) { |
79072805 LW |
1604 | --s; |
1605 | break; | |
1606 | } | |
02aa26ce NT |
1607 | |
1608 | /* if we get here, it's either a quoted -, or a digit */ | |
79072805 | 1609 | switch (*s) { |
02aa26ce NT |
1610 | |
1611 | /* quoted - in transliterations */ | |
79072805 | 1612 | case '-': |
3280af22 | 1613 | if (PL_lex_inwhat == OP_TRANS) { |
79072805 LW |
1614 | *d++ = *s++; |
1615 | continue; | |
1616 | } | |
1617 | /* FALL THROUGH */ | |
1618 | default: | |
11b8faa4 | 1619 | { |
041457d9 DM |
1620 | if (isALNUM(*s) && |
1621 | *s != '_' && | |
1622 | ckWARN(WARN_MISC)) | |
9014280d | 1623 | Perl_warner(aTHX_ packWARN(WARN_MISC), |
11b8faa4 JH |
1624 | "Unrecognized escape \\%c passed through", |
1625 | *s); | |
1626 | /* default action is to copy the quoted character */ | |
f9a63242 | 1627 | goto default_action; |
11b8faa4 | 1628 | } |
02aa26ce NT |
1629 | |
1630 | /* \132 indicates an octal constant */ | |
79072805 LW |
1631 | case '0': case '1': case '2': case '3': |
1632 | case '4': case '5': case '6': case '7': | |
ba210ebe | 1633 | { |
53305cf1 NC |
1634 | I32 flags = 0; |
1635 | STRLEN len = 3; | |
1636 | uv = grok_oct(s, &len, &flags, NULL); | |
ba210ebe JH |
1637 | s += len; |
1638 | } | |
012bcf8d | 1639 | goto NUM_ESCAPE_INSERT; |
02aa26ce NT |
1640 | |
1641 | /* \x24 indicates a hex constant */ | |
79072805 | 1642 | case 'x': |
a0ed51b3 LW |
1643 | ++s; |
1644 | if (*s == '{') { | |
9d4ba2ae | 1645 | char* const e = strchr(s, '}'); |
a4c04bdc NC |
1646 | I32 flags = PERL_SCAN_ALLOW_UNDERSCORES | |
1647 | PERL_SCAN_DISALLOW_PREFIX; | |
53305cf1 | 1648 | STRLEN len; |
355860ce | 1649 | |
53305cf1 | 1650 | ++s; |
adaeee49 | 1651 | if (!e) { |
a0ed51b3 | 1652 | yyerror("Missing right brace on \\x{}"); |
355860ce | 1653 | continue; |
ba210ebe | 1654 | } |
53305cf1 NC |
1655 | len = e - s; |
1656 | uv = grok_hex(s, &len, &flags, NULL); | |
ba210ebe | 1657 | s = e + 1; |
a0ed51b3 LW |
1658 | } |
1659 | else { | |
ba210ebe | 1660 | { |
53305cf1 | 1661 | STRLEN len = 2; |
a4c04bdc | 1662 | I32 flags = PERL_SCAN_DISALLOW_PREFIX; |
53305cf1 | 1663 | uv = grok_hex(s, &len, &flags, NULL); |
ba210ebe JH |
1664 | s += len; |
1665 | } | |
012bcf8d GS |
1666 | } |
1667 | ||
1668 | NUM_ESCAPE_INSERT: | |
1669 | /* Insert oct or hex escaped character. | |
301d3d20 | 1670 | * There will always enough room in sv since such |
db42d148 | 1671 | * escapes will be longer than any UTF-8 sequence |
301d3d20 | 1672 | * they can end up as. */ |
ba7cea30 | 1673 | |
c7f1f016 NIS |
1674 | /* We need to map to chars to ASCII before doing the tests |
1675 | to cover EBCDIC | |
1676 | */ | |
c4d5f83a | 1677 | if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) { |
9aa983d2 | 1678 | if (!has_utf8 && uv > 255) { |
301d3d20 JH |
1679 | /* Might need to recode whatever we have |
1680 | * accumulated so far if it contains any | |
1681 | * hibit chars. | |
1682 | * | |
1683 | * (Can't we keep track of that and avoid | |
1684 | * this rescan? --jhi) | |
012bcf8d | 1685 | */ |
c7f1f016 | 1686 | int hicount = 0; |
63cd0674 NIS |
1687 | U8 *c; |
1688 | for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) { | |
c4d5f83a | 1689 | if (!NATIVE_IS_INVARIANT(*c)) { |
012bcf8d | 1690 | hicount++; |
db42d148 | 1691 | } |
012bcf8d | 1692 | } |
63cd0674 | 1693 | if (hicount) { |
9d4ba2ae | 1694 | const STRLEN offset = d - SvPVX_const(sv); |
db42d148 NIS |
1695 | U8 *src, *dst; |
1696 | d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset; | |
1697 | src = (U8 *)d - 1; | |
1698 | dst = src+hicount; | |
1699 | d += hicount; | |
cfd0369c | 1700 | while (src >= (const U8 *)SvPVX_const(sv)) { |
c4d5f83a | 1701 | if (!NATIVE_IS_INVARIANT(*src)) { |
9d4ba2ae | 1702 | const U8 ch = NATIVE_TO_ASCII(*src); |
eb160463 GS |
1703 | *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch); |
1704 | *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch); | |
012bcf8d GS |
1705 | } |
1706 | else { | |
63cd0674 | 1707 | *dst-- = *src; |
012bcf8d | 1708 | } |
c7f1f016 | 1709 | src--; |
012bcf8d GS |
1710 | } |
1711 | } | |
1712 | } | |
1713 | ||
9aa983d2 | 1714 | if (has_utf8 || uv > 255) { |
9041c2e3 | 1715 | d = (char*)uvchr_to_utf8((U8*)d, uv); |
4e553d73 | 1716 | has_utf8 = TRUE; |
f9a63242 JH |
1717 | if (PL_lex_inwhat == OP_TRANS && |
1718 | PL_sublex_info.sub_op) { | |
1719 | PL_sublex_info.sub_op->op_private |= | |
1720 | (PL_lex_repl ? OPpTRANS_FROM_UTF | |
1721 | : OPpTRANS_TO_UTF); | |
f9a63242 | 1722 | } |
012bcf8d | 1723 | } |
a0ed51b3 | 1724 | else { |
012bcf8d | 1725 | *d++ = (char)uv; |
a0ed51b3 | 1726 | } |
012bcf8d GS |
1727 | } |
1728 | else { | |
c4d5f83a | 1729 | *d++ = (char) uv; |
a0ed51b3 | 1730 | } |
79072805 | 1731 | continue; |
02aa26ce | 1732 | |
b239daa5 | 1733 | /* \N{LATIN SMALL LETTER A} is a named character */ |
4a2d328f | 1734 | case 'N': |
55eda711 | 1735 | ++s; |
423cee85 JH |
1736 | if (*s == '{') { |
1737 | char* e = strchr(s, '}'); | |
155aba94 | 1738 | SV *res; |
423cee85 | 1739 | STRLEN len; |
cfd0369c | 1740 | const char *str; |
4e553d73 | 1741 | |
423cee85 | 1742 | if (!e) { |
5777a3f7 | 1743 | yyerror("Missing right brace on \\N{}"); |
423cee85 JH |
1744 | e = s - 1; |
1745 | goto cont_scan; | |
1746 | } | |
dbc0d4f2 JH |
1747 | if (e > s + 2 && s[1] == 'U' && s[2] == '+') { |
1748 | /* \N{U+...} */ | |
1749 | I32 flags = PERL_SCAN_ALLOW_UNDERSCORES | | |
1750 | PERL_SCAN_DISALLOW_PREFIX; | |
1751 | s += 3; | |
1752 | len = e - s; | |
1753 | uv = grok_hex(s, &len, &flags, NULL); | |
1754 | s = e + 1; | |
1755 | goto NUM_ESCAPE_INSERT; | |
1756 | } | |
55eda711 JH |
1757 | res = newSVpvn(s + 1, e - s - 1); |
1758 | res = new_constant( Nullch, 0, "charnames", | |
1759 | res, Nullsv, "\\N{...}" ); | |
f9a63242 JH |
1760 | if (has_utf8) |
1761 | sv_utf8_upgrade(res); | |
cfd0369c | 1762 | str = SvPV_const(res,len); |
1c47067b JH |
1763 | #ifdef EBCDIC_NEVER_MIND |
1764 | /* charnames uses pack U and that has been | |
1765 | * recently changed to do the below uni->native | |
1766 | * mapping, so this would be redundant (and wrong, | |
1767 | * the code point would be doubly converted). | |
1768 | * But leave this in just in case the pack U change | |
1769 | * gets revoked, but the semantics is still | |
1770 | * desireable for charnames. --jhi */ | |
cddc7ef4 | 1771 | { |
cfd0369c | 1772 | UV uv = utf8_to_uvchr((const U8*)str, 0); |
cddc7ef4 JH |
1773 | |
1774 | if (uv < 0x100) { | |
89ebb4a3 | 1775 | U8 tmpbuf[UTF8_MAXBYTES+1], *d; |
cddc7ef4 JH |
1776 | |
1777 | d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv)); | |
1778 | sv_setpvn(res, (char *)tmpbuf, d - tmpbuf); | |
cfd0369c | 1779 | str = SvPV_const(res, len); |
cddc7ef4 JH |
1780 | } |
1781 | } | |
1782 | #endif | |
89491803 | 1783 | if (!has_utf8 && SvUTF8(res)) { |
9d4ba2ae | 1784 | const char * const ostart = SvPVX_const(sv); |
f08d6ad9 GS |
1785 | SvCUR_set(sv, d - ostart); |
1786 | SvPOK_on(sv); | |
e4f3eed8 | 1787 | *d = '\0'; |
f08d6ad9 | 1788 | sv_utf8_upgrade(sv); |
d2f449dd | 1789 | /* this just broke our allocation above... */ |
eb160463 | 1790 | SvGROW(sv, (STRLEN)(send - start)); |
f08d6ad9 | 1791 | d = SvPVX(sv) + SvCUR(sv); |
89491803 | 1792 | has_utf8 = TRUE; |
f08d6ad9 | 1793 | } |
eb160463 | 1794 | if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */ |
9d4ba2ae | 1795 | const char * const odest = SvPVX_const(sv); |
423cee85 | 1796 | |
8973db79 | 1797 | SvGROW(sv, (SvLEN(sv) + len - (e - s + 4))); |
423cee85 JH |
1798 | d = SvPVX(sv) + (d - odest); |
1799 | } | |
1800 | Copy(str, d, len, char); | |
1801 | d += len; | |
1802 | SvREFCNT_dec(res); | |
1803 | cont_scan: | |
1804 | s = e + 1; | |
1805 | } | |
1806 | else | |
5777a3f7 | 1807 | yyerror("Missing braces on \\N{}"); |
423cee85 JH |
1808 | continue; |
1809 | ||
02aa26ce | 1810 | /* \c is a control character */ |
79072805 LW |
1811 | case 'c': |
1812 | s++; | |
961ce445 | 1813 | if (s < send) { |
ba210ebe | 1814 | U8 c = *s++; |
c7f1f016 NIS |
1815 | #ifdef EBCDIC |
1816 | if (isLOWER(c)) | |
1817 | c = toUPPER(c); | |
1818 | #endif | |
db42d148 | 1819 | *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c)); |
ba210ebe | 1820 | } |
961ce445 RGS |
1821 | else { |
1822 | yyerror("Missing control char name in \\c"); | |
1823 | } | |
79072805 | 1824 | continue; |
02aa26ce NT |
1825 | |
1826 | /* printf-style backslashes, formfeeds, newlines, etc */ | |
79072805 | 1827 | case 'b': |
db42d148 | 1828 | *d++ = NATIVE_TO_NEED(has_utf8,'\b'); |
79072805 LW |
1829 | break; |
1830 | case 'n': | |
db42d148 | 1831 | *d++ = NATIVE_TO_NEED(has_utf8,'\n'); |
79072805 LW |
1832 | break; |
1833 | case 'r': | |
db42d148 | 1834 | *d++ = NATIVE_TO_NEED(has_utf8,'\r'); |
79072805 LW |
1835 | break; |
1836 | case 'f': | |
db42d148 | 1837 | *d++ = NATIVE_TO_NEED(has_utf8,'\f'); |
79072805 LW |
1838 | break; |
1839 | case 't': | |
db42d148 | 1840 | *d++ = NATIVE_TO_NEED(has_utf8,'\t'); |
79072805 | 1841 | break; |
34a3fe2a | 1842 | case 'e': |
db42d148 | 1843 | *d++ = ASCII_TO_NEED(has_utf8,'\033'); |
34a3fe2a PP |
1844 | break; |
1845 | case 'a': | |
db42d148 | 1846 | *d++ = ASCII_TO_NEED(has_utf8,'\007'); |
79072805 | 1847 | break; |
02aa26ce NT |
1848 | } /* end switch */ |
1849 | ||
79072805 LW |
1850 | s++; |
1851 | continue; | |
02aa26ce | 1852 | } /* end if (backslash) */ |
4c3a8340 TS |
1853 | #ifdef EBCDIC |
1854 | else | |
1855 | literal_endpoint++; | |
1856 | #endif | |
02aa26ce | 1857 | |
f9a63242 | 1858 | default_action: |
2b9d42f0 NIS |
1859 | /* If we started with encoded form, or already know we want it |
1860 | and then encode the next character */ | |
1861 | if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) { | |
1862 | STRLEN len = 1; | |
9d4ba2ae AL |
1863 | const UV uv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s); |
1864 | const STRLEN need = UNISKIP(NATIVE_TO_UNI(uv)); | |
2b9d42f0 NIS |
1865 | s += len; |
1866 | if (need > len) { | |
1867 | /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */ | |
9d4ba2ae | 1868 | const STRLEN off = d - SvPVX_const(sv); |
2b9d42f0 NIS |
1869 | d = SvGROW(sv, SvLEN(sv) + (need-len)) + off; |
1870 | } | |
1871 | d = (char*)uvchr_to_utf8((U8*)d, uv); | |
1872 | has_utf8 = TRUE; | |
1873 | } | |
1874 | else { | |
1875 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); | |
1876 | } | |
02aa26ce NT |
1877 | } /* while loop to process each character */ |
1878 | ||
1879 | /* terminate the string and set up the sv */ | |
79072805 | 1880 | *d = '\0'; |
95a20fc0 | 1881 | SvCUR_set(sv, d - SvPVX_const(sv)); |
2b9d42f0 | 1882 | if (SvCUR(sv) >= SvLEN(sv)) |
d0063567 | 1883 | Perl_croak(aTHX_ "panic: constant overflowed allocated space"); |
2b9d42f0 | 1884 | |
79072805 | 1885 | SvPOK_on(sv); |
9f4817db | 1886 | if (PL_encoding && !has_utf8) { |
d0063567 DK |
1887 | sv_recode_to_utf8(sv, PL_encoding); |
1888 | if (SvUTF8(sv)) | |
1889 | has_utf8 = TRUE; | |
9f4817db | 1890 | } |
2b9d42f0 | 1891 | if (has_utf8) { |
7e2040f0 | 1892 | SvUTF8_on(sv); |
2b9d42f0 | 1893 | if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) { |
d0063567 | 1894 | PL_sublex_info.sub_op->op_private |= |
2b9d42f0 NIS |
1895 | (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); |
1896 | } | |
1897 | } | |
79072805 | 1898 | |
02aa26ce | 1899 | /* shrink the sv if we allocated more than we used */ |
79072805 | 1900 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
1da4ca5f | 1901 | SvPV_shrink_to_cur(sv); |
79072805 | 1902 | } |
02aa26ce | 1903 | |
9b599b2a | 1904 | /* return the substring (via yylval) only if we parsed anything */ |
3280af22 NIS |
1905 | if (s > PL_bufptr) { |
1906 | if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) | |
4e553d73 | 1907 | sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"), |
b3ac6de7 | 1908 | sv, Nullsv, |
4e553d73 | 1909 | ( PL_lex_inwhat == OP_TRANS |
b3ac6de7 | 1910 | ? "tr" |
3280af22 | 1911 | : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) |
b3ac6de7 IZ |
1912 | ? "s" |
1913 | : "qq"))); | |
79072805 | 1914 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
b3ac6de7 | 1915 | } else |
8990e307 | 1916 | SvREFCNT_dec(sv); |
79072805 LW |
1917 | return s; |
1918 | } | |
1919 | ||
ffb4593c NT |
1920 | /* S_intuit_more |
1921 | * Returns TRUE if there's more to the expression (e.g., a subscript), | |
1922 | * FALSE otherwise. | |
ffb4593c NT |
1923 | * |
1924 | * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/ | |
1925 | * | |
1926 | * ->[ and ->{ return TRUE | |
1927 | * { and [ outside a pattern are always subscripts, so return TRUE | |
1928 | * if we're outside a pattern and it's not { or [, then return FALSE | |
1929 | * if we're in a pattern and the first char is a { | |
1930 | * {4,5} (any digits around the comma) returns FALSE | |
1931 | * if we're in a pattern and the first char is a [ | |
1932 | * [] returns FALSE | |
1933 | * [SOMETHING] has a funky algorithm to decide whether it's a | |
1934 | * character class or not. It has to deal with things like | |
1935 | * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/ | |
1936 | * anything else returns TRUE | |
1937 | */ | |
1938 | ||
9cbb5ea2 GS |
1939 | /* This is the one truly awful dwimmer necessary to conflate C and sed. */ |
1940 | ||
76e3520e | 1941 | STATIC int |
cea2e8a9 | 1942 | S_intuit_more(pTHX_ register char *s) |
79072805 | 1943 | { |
3280af22 | 1944 | if (PL_lex_brackets) |
79072805 LW |
1945 | return TRUE; |
1946 | if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{')) | |
1947 | return TRUE; | |
1948 | if (*s != '{' && *s != '[') | |
1949 | return FALSE; | |
3280af22 | 1950 | if (!PL_lex_inpat) |
79072805 LW |
1951 | return TRUE; |
1952 | ||
1953 | /* In a pattern, so maybe we have {n,m}. */ | |
1954 | if (*s == '{') { | |
1955 | s++; | |
1956 | if (!isDIGIT(*s)) | |
1957 | return TRUE; | |
1958 | while (isDIGIT(*s)) | |
1959 | s++; | |
1960 | if (*s == ',') | |
1961 | s++; | |
1962 | while (isDIGIT(*s)) | |
1963 | s++; | |
1964 | if (*s == '}') | |
1965 | return FALSE; | |
1966 | return TRUE; | |
1967 | ||
1968 | } | |
1969 | ||
1970 | /* On the other hand, maybe we have a character class */ | |
1971 | ||
1972 | s++; | |
1973 | if (*s == ']' || *s == '^') | |
1974 | return FALSE; | |
1975 | else { | |
ffb4593c | 1976 | /* this is terrifying, and it works */ |
79072805 LW |
1977 | int weight = 2; /* let's weigh the evidence */ |
1978 | char seen[256]; | |
f27ffc4a | 1979 | unsigned char un_char = 255, last_un_char; |
9d4ba2ae | 1980 | const char * const send = strchr(s,']'); |
3280af22 | 1981 | char tmpbuf[sizeof PL_tokenbuf * 4]; |
79072805 LW |
1982 | |
1983 | if (!send) /* has to be an expression */ | |
1984 | return TRUE; | |
1985 | ||
1986 | Zero(seen,256,char); | |
1987 | if (*s == '$') | |
1988 | weight -= 3; | |
1989 | else if (isDIGIT(*s)) { | |
1990 | if (s[1] != ']') { | |
1991 | if (isDIGIT(s[1]) && s[2] == ']') | |
1992 | weight -= 10; | |
1993 | } | |
1994 | else | |
1995 | weight -= 100; | |
1996 | } | |
1997 | for (; s < send; s++) { | |
1998 | last_un_char = un_char; | |
1999 | un_char = (unsigned char)*s; | |
2000 | switch (*s) { | |
2001 | case '@': | |
2002 | case '&': | |
2003 | case '$': | |
2004 | weight -= seen[un_char] * 10; | |
7e2040f0 | 2005 | if (isALNUM_lazy_if(s+1,UTF)) { |
8903cb82 | 2006 | scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE); |
a0d0e21e | 2007 | if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV)) |
79072805 LW |
2008 | weight -= 100; |
2009 | else | |
2010 | weight -= 10; | |
2011 | } | |
2012 | else if (*s == '$' && s[1] && | |
93a17b20 LW |
2013 | strchr("[#!%*<>()-=",s[1])) { |
2014 | if (/*{*/ strchr("])} =",s[2])) | |
79072805 LW |
2015 | weight -= 10; |
2016 | else | |
2017 | weight -= 1; | |
2018 | } | |
2019 | break; | |
2020 | case '\\': | |
2021 | un_char = 254; | |
2022 | if (s[1]) { | |
93a17b20 | 2023 | if (strchr("wds]",s[1])) |
79072805 LW |
2024 | weight += 100; |
2025 | else if (seen['\''] || seen['"']) | |
2026 | weight += 1; | |
93a17b20 | 2027 | else if (strchr("rnftbxcav",s[1])) |
79072805 LW |
2028 | weight += 40; |
2029 | else if (isDIGIT(s[1])) { | |
2030 | weight += 40; | |
2031 | while (s[1] && isDIGIT(s[1])) | |
2032 | s++; | |
2033 | } | |
2034 | } | |
2035 | else | |
2036 | weight += 100; | |
2037 | break; | |
2038 | case '-': | |
2039 | if (s[1] == '\\') | |
2040 | weight += 50; | |
93a17b20 | 2041 | if (strchr("aA01! ",last_un_char)) |
79072805 | 2042 | weight += 30; |
93a17b20 | 2043 | if (strchr("zZ79~",s[1])) |
79072805 | 2044 | weight += 30; |
f27ffc4a GS |
2045 | if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$')) |
2046 | weight -= 5; /* cope with negative subscript */ | |
79072805 LW |
2047 | break; |
2048 | default: | |
3792a11b NC |
2049 | if (!isALNUM(last_un_char) |
2050 | && !(last_un_char == '$' || last_un_char == '@' | |
2051 | || last_un_char == '&') | |
2052 | && isALPHA(*s) && s[1] && isALPHA(s[1])) { | |
79072805 LW |
2053 | char *d = tmpbuf; |
2054 | while (isALPHA(*s)) | |
2055 | *d++ = *s++; | |
2056 | *d = '\0'; | |
2057 | if (keyword(tmpbuf, d - tmpbuf)) | |
2058 | weight -= 150; | |
2059 | } | |
2060 | if (un_char == last_un_char + 1) | |
2061 | weight += 5; | |
2062 | weight -= seen[un_char]; | |
2063 | break; | |
2064 | } | |
2065 | seen[un_char]++; | |
2066 | } | |
2067 | if (weight >= 0) /* probably a character class */ | |
2068 | return FALSE; | |
2069 | } | |
2070 | ||
2071 | return TRUE; | |
2072 | } | |
ffed7fef | 2073 | |
ffb4593c NT |
2074 | /* |
2075 | * S_intuit_method | |
2076 | * | |
2077 | * Does all the checking to disambiguate | |
2078 | * foo bar | |
2079 | * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise | |
2080 | * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args). | |
2081 | * | |
2082 | * First argument is the stuff after the first token, e.g. "bar". | |
2083 | * | |
2084 | * Not a method if bar is a filehandle. | |
2085 | * Not a method if foo is a subroutine prototyped to take a filehandle. | |
2086 | * Not a method if it's really "Foo $bar" | |
2087 | * Method if it's "foo $bar" | |
2088 | * Not a method if it's really "print foo $bar" | |
2089 | * Method if it's really "foo package::" (interpreted as package->foo) | |
8f8cf39c | 2090 | * Not a method if bar is known to be a subroutine ("sub bar; foo bar") |
3cb0bbe5 | 2091 | * Not a method if bar is a filehandle or package, but is quoted with |
ffb4593c NT |
2092 | * => |
2093 | */ | |
2094 | ||
76e3520e | 2095 | STATIC int |
cea2e8a9 | 2096 | S_intuit_method(pTHX_ char *start, GV *gv) |
a0d0e21e LW |
2097 | { |
2098 | char *s = start + (*start == '$'); | |
3280af22 | 2099 | char tmpbuf[sizeof PL_tokenbuf]; |
a0d0e21e LW |
2100 | STRLEN len; |
2101 | GV* indirgv; | |
2102 | ||
2103 | if (gv) { | |
b6c543e3 | 2104 | CV *cv; |
a0d0e21e LW |
2105 | if (GvIO(gv)) |
2106 | return 0; | |
b6c543e3 | 2107 | if ((cv = GvCVu(gv))) { |
95a20fc0 | 2108 | const char *proto = SvPVX_const(cv); |
b6c543e3 IZ |
2109 | if (proto) { |
2110 | if (*proto == ';') | |
2111 | proto++; | |
2112 | if (*proto == '*') | |
2113 | return 0; | |
2114 | } | |
2115 | } else | |
a0d0e21e LW |
2116 | gv = 0; |
2117 | } | |
8903cb82 | 2118 | s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
ffb4593c NT |
2119 | /* start is the beginning of the possible filehandle/object, |
2120 | * and s is the end of it | |
2121 | * tmpbuf is a copy of it | |
2122 | */ | |
2123 | ||
a0d0e21e | 2124 | if (*start == '$') { |
3280af22 | 2125 | if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf)) |
a0d0e21e LW |
2126 | return 0; |
2127 | s = skipspace(s); | |
3280af22 NIS |
2128 | PL_bufptr = start; |
2129 | PL_expect = XREF; | |
a0d0e21e LW |
2130 | return *s == '(' ? FUNCMETH : METHOD; |
2131 | } | |
2132 | if (!keyword(tmpbuf, len)) { | |
c3e0f903 GS |
2133 | if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') { |
2134 | len -= 2; | |
2135 | tmpbuf[len] = '\0'; | |
2136 | goto bare_package; | |
2137 | } | |
2138 | indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV); | |
8ebc5c01 | 2139 | if (indirgv && GvCVu(indirgv)) |
a0d0e21e LW |
2140 | return 0; |
2141 | /* filehandle or package name makes it a method */ | |
89bfa8cd | 2142 | if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) { |
a0d0e21e | 2143 | s = skipspace(s); |
3280af22 | 2144 | if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>') |
55497cff | 2145 | return 0; /* no assumptions -- "=>" quotes bearword */ |
c3e0f903 | 2146 | bare_package: |
3280af22 | 2147 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, |
79cb57f6 | 2148 | newSVpvn(tmpbuf,len)); |
3280af22 NIS |
2149 | PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE; |
2150 | PL_expect = XTERM; | |
a0d0e21e | 2151 | force_next(WORD); |
3280af22 | 2152 | PL_bufptr = s; |
a0d0e21e LW |
2153 | return *s == '(' ? FUNCMETH : METHOD; |
2154 | } | |
2155 | } | |
2156 | return 0; | |
2157 | } | |
2158 | ||
ffb4593c NT |
2159 | /* |
2160 | * S_incl_perldb | |
2161 | * Return a string of Perl code to load the debugger. If PERL5DB | |
2162 | * is set, it will return the contents of that, otherwise a | |
2163 | * compile-time require of perl5db.pl. | |
2164 | */ | |
2165 | ||
bfed75c6 | 2166 | STATIC const char* |
cea2e8a9 | 2167 | S_incl_perldb(pTHX) |
a0d0e21e | 2168 | { |
3280af22 | 2169 | if (PL_perldb) { |
9d4ba2ae | 2170 | const char * const pdb = PerlEnv_getenv("PERL5DB"); |
a0d0e21e LW |
2171 | |
2172 | if (pdb) | |
2173 | return pdb; | |
93189314 | 2174 | SETERRNO(0,SS_NORMAL); |
a0d0e21e LW |
2175 | return "BEGIN { require 'perl5db.pl' }"; |
2176 | } | |
2177 | return ""; | |
2178 | } | |
2179 | ||
2180 | ||
16d20bd9 | 2181 | /* Encoded script support. filter_add() effectively inserts a |
4e553d73 | 2182 | * 'pre-processing' function into the current source input stream. |
16d20bd9 AD |
2183 | * Note that the filter function only applies to the current source file |
2184 | * (e.g., it will not affect files 'require'd or 'use'd by this one). | |
2185 | * | |
2186 | * The datasv parameter (which may be NULL) can be used to pass | |
2187 | * private data to this instance of the filter. The filter function | |
2188 | * can recover the SV using the FILTER_DATA macro and use it to | |
2189 | * store private buffers and state information. | |
2190 | * | |
2191 | * The supplied datasv parameter is upgraded to a PVIO type | |
4755096e | 2192 | * and the IoDIRP/IoANY field is used to store the function pointer, |
e0c19803 | 2193 | * and IOf_FAKE_DIRP is enabled on datasv to mark this as such. |
16d20bd9 AD |
2194 | * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for |
2195 | * private use must be set using malloc'd pointers. | |
2196 | */ | |
16d20bd9 AD |
2197 | |
2198 | SV * | |
864dbfa3 | 2199 | Perl_filter_add(pTHX_ filter_t funcp, SV *datasv) |
16d20bd9 | 2200 | { |
f4c556ac GS |
2201 | if (!funcp) |
2202 | return Nullsv; | |
2203 | ||
3280af22 NIS |
2204 | if (!PL_rsfp_filters) |
2205 | PL_rsfp_filters = newAV(); | |
16d20bd9 | 2206 | if (!datasv) |
8c52afec | 2207 | datasv = NEWSV(255,0); |
862a34c6 | 2208 | SvUPGRADE(datasv, SVt_PVIO); |
8141890a | 2209 | IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */ |
e0c19803 | 2210 | IoFLAGS(datasv) |= IOf_FAKE_DIRP; |
f4c556ac | 2211 | DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n", |
8141890a | 2212 | IoANY(datasv), SvPV_nolen(datasv))); |
3280af22 NIS |
2213 | av_unshift(PL_rsfp_filters, 1); |
2214 | av_store(PL_rsfp_filters, 0, datasv) ; | |
16d20bd9 AD |
2215 | return(datasv); |
2216 | } | |
4e553d73 | 2217 | |
16d20bd9 AD |
2218 | |
2219 | /* Delete most recently added instance of this filter function. */ | |
a0d0e21e | 2220 | void |
864dbfa3 | 2221 | Perl_filter_del(pTHX_ filter_t funcp) |
16d20bd9 | 2222 | { |
e0c19803 | 2223 | SV *datasv; |
24801a4b | 2224 | |
33073adb | 2225 | #ifdef DEBUGGING |
8141890a | 2226 | DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", FPTR2DPTR(XPVIO *, funcp))); |
33073adb | 2227 | #endif |
3280af22 | 2228 | if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0) |
16d20bd9 AD |
2229 | return; |
2230 | /* if filter is on top of stack (usual case) just pop it off */ | |
e0c19803 | 2231 | datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters)); |
8141890a | 2232 | if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) { |
e0c19803 | 2233 | IoFLAGS(datasv) &= ~IOf_FAKE_DIRP; |
4755096e | 2234 | IoANY(datasv) = (void *)NULL; |
3280af22 | 2235 | sv_free(av_pop(PL_rsfp_filters)); |
e50aee73 | 2236 | |
16d20bd9 AD |
2237 | return; |
2238 | } | |
2239 | /* we need to search for the correct entry and clear it */ | |
cea2e8a9 | 2240 | Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)"); |
16d20bd9 AD |
2241 | } |
2242 | ||
2243 | ||
1de9afcd RGS |
2244 | /* Invoke the idxth filter function for the current rsfp. */ |
2245 | /* maxlen 0 = read one text line */ | |
16d20bd9 | 2246 | I32 |
864dbfa3 | 2247 | Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen) |
a0d0e21e | 2248 | { |
16d20bd9 AD |
2249 | filter_t funcp; |
2250 | SV *datasv = NULL; | |
e50aee73 | 2251 | |
3280af22 | 2252 | if (!PL_rsfp_filters) |
16d20bd9 | 2253 | return -1; |
1de9afcd | 2254 | if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */ |
16d20bd9 AD |
2255 | /* Provide a default input filter to make life easy. */ |
2256 | /* Note that we append to the line. This is handy. */ | |
f4c556ac GS |
2257 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2258 | "filter_read %d: from rsfp\n", idx)); | |
4e553d73 | 2259 | if (maxlen) { |
16d20bd9 AD |
2260 | /* Want a block */ |
2261 | int len ; | |
f54cb97a | 2262 | const int old_len = SvCUR(buf_sv); |
16d20bd9 AD |
2263 | |
2264 | /* ensure buf_sv is large enough */ | |
eb160463 | 2265 | SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ; |
3280af22 NIS |
2266 | if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){ |
2267 | if (PerlIO_error(PL_rsfp)) | |
37120919 AD |
2268 | return -1; /* error */ |
2269 | else | |
2270 | return 0 ; /* end of file */ | |
2271 | } | |
16d20bd9 AD |
2272 | SvCUR_set(buf_sv, old_len + len) ; |
2273 | } else { | |
2274 | /* Want a line */ | |
3280af22 NIS |
2275 | if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) { |
2276 | if (PerlIO_error(PL_rsfp)) | |
37120919 AD |
2277 | return -1; /* error */ |
2278 | else | |
2279 | return 0 ; /* end of file */ | |
2280 | } | |
16d20bd9 AD |
2281 | } |
2282 | return SvCUR(buf_sv); | |
2283 | } | |
2284 | /* Skip this filter slot if filter has been deleted */ | |
1de9afcd | 2285 | if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) { |
f4c556ac GS |
2286 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2287 | "filter_read %d: skipped (filter deleted)\n", | |
2288 | idx)); | |
16d20bd9 AD |
2289 | return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */ |
2290 | } | |
2291 | /* Get function pointer hidden within datasv */ | |
8141890a | 2292 | funcp = DPTR2FPTR(filter_t, IoANY(datasv)); |
f4c556ac GS |
2293 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2294 | "filter_read %d: via function %p (%s)\n", | |
cfd0369c | 2295 | idx, datasv, SvPV_nolen_const(datasv))); |
16d20bd9 AD |
2296 | /* Call function. The function is expected to */ |
2297 | /* call "FILTER_READ(idx+1, buf_sv)" first. */ | |
37120919 | 2298 | /* Return: <0:error, =0:eof, >0:not eof */ |
acfe0abc | 2299 | return (*funcp)(aTHX_ idx, buf_sv, maxlen); |
16d20bd9 AD |
2300 | } |
2301 | ||
76e3520e | 2302 | STATIC char * |
cea2e8a9 | 2303 | S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append) |
16d20bd9 | 2304 | { |
c39cd008 | 2305 | #ifdef PERL_CR_FILTER |
3280af22 | 2306 | if (!PL_rsfp_filters) { |
c39cd008 | 2307 | filter_add(S_cr_textfilter,NULL); |
a868473f NIS |
2308 | } |
2309 | #endif | |
3280af22 | 2310 | if (PL_rsfp_filters) { |
55497cff | 2311 | if (!append) |
2312 | SvCUR_set(sv, 0); /* start with empty line */ | |
16d20bd9 AD |
2313 | if (FILTER_READ(0, sv, 0) > 0) |
2314 | return ( SvPVX(sv) ) ; | |
2315 | else | |
2316 | return Nullch ; | |
2317 | } | |
9d116dd7 | 2318 | else |
fd049845 | 2319 | return (sv_gets(sv, fp, append)); |
a0d0e21e LW |
2320 | } |
2321 | ||
01ec43d0 | 2322 | STATIC HV * |
7fc63493 | 2323 | S_find_in_my_stash(pTHX_ const char *pkgname, I32 len) |
def3634b GS |
2324 | { |
2325 | GV *gv; | |
2326 | ||
01ec43d0 | 2327 | if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__")) |
def3634b GS |
2328 | return PL_curstash; |
2329 | ||
2330 | if (len > 2 && | |
2331 | (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') && | |
01ec43d0 GS |
2332 | (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV))) |
2333 | { | |
2334 | return GvHV(gv); /* Foo:: */ | |
def3634b GS |
2335 | } |
2336 | ||
2337 | /* use constant CLASS => 'MyClass' */ | |
2338 | if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) { | |
2339 | SV *sv; | |
2340 | if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) { | |
83003860 | 2341 | pkgname = SvPV_nolen_const(sv); |
def3634b GS |
2342 | } |
2343 | } | |
2344 | ||
2345 | return gv_stashpv(pkgname, FALSE); | |
2346 | } | |
a0d0e21e | 2347 | |
468aa647 | 2348 | STATIC char * |
cc6ed77d | 2349 | S_tokenize_use(pTHX_ int is_use, char *s) { |
468aa647 RGS |
2350 | if (PL_expect != XSTATE) |
2351 | yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression", | |
2352 | is_use ? "use" : "no")); | |
2353 | s = skipspace(s); | |
2354 | if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) { | |
2355 | s = force_version(s, TRUE); | |
2356 | if (*s == ';' || (s = skipspace(s), *s == ';')) { | |
2357 | PL_nextval[PL_nexttoke].opval = Nullop; | |
2358 | force_next(WORD); | |
2359 | } | |
2360 | else if (*s == 'v') { | |
2361 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
2362 | s = force_version(s, FALSE); | |
2363 | } | |
2364 | } | |
2365 | else { | |
2366 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
2367 | s = force_version(s, FALSE); | |
2368 | } | |
2369 | yylval.ival = is_use; | |
2370 | return s; | |
2371 | } | |
748a9306 | 2372 | #ifdef DEBUGGING |
27da23d5 | 2373 | static const char* const exp_name[] = |
09bef843 | 2374 | { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK", |
27308ded | 2375 | "ATTRTERM", "TERMBLOCK", "TERMORDORDOR" |
09bef843 | 2376 | }; |
748a9306 | 2377 | #endif |
463ee0b2 | 2378 | |
02aa26ce NT |
2379 | /* |
2380 | yylex | |
2381 | ||
2382 | Works out what to call the token just pulled out of the input | |
2383 | stream. The yacc parser takes care of taking the ops we return and | |
2384 | stitching them into a tree. | |
2385 | ||
2386 | Returns: | |
2387 | PRIVATEREF | |
2388 | ||
2389 | Structure: | |
2390 | if read an identifier | |
2391 | if we're in a my declaration | |
2392 | croak if they tried to say my($foo::bar) | |
2393 | build the ops for a my() declaration | |
2394 | if it's an access to a my() variable | |
2395 | are we in a sort block? | |
2396 | croak if my($a); $a <=> $b | |
2397 | build ops for access to a my() variable | |
2398 | if in a dq string, and they've said @foo and we can't find @foo | |
2399 | croak | |
2400 | build ops for a bareword | |
2401 | if we already built the token before, use it. | |
2402 | */ | |
2403 | ||
20141f0e | 2404 | |
dba4d153 JH |
2405 | #ifdef __SC__ |
2406 | #pragma segment Perl_yylex | |
2407 | #endif | |
dba4d153 | 2408 | int |
dba4d153 | 2409 | Perl_yylex(pTHX) |
20141f0e | 2410 | { |
3afc138a | 2411 | register char *s = PL_bufptr; |
378cc40b | 2412 | register char *d; |
79072805 | 2413 | register I32 tmp; |
463ee0b2 | 2414 | STRLEN len; |
161b471a NIS |
2415 | GV *gv = Nullgv; |
2416 | GV **gvp = 0; | |
aa7440fb | 2417 | bool bof = FALSE; |
1d239bbb | 2418 | I32 orig_keyword = 0; |
a687059c | 2419 | |
bbf60fe6 | 2420 | DEBUG_T( { |
b6007c36 DM |
2421 | SV* tmp = newSVpvn("", 0); |
2422 | PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n", | |
2423 | (IV)CopLINE(PL_curcop), | |
2424 | lex_state_names[PL_lex_state], | |
2425 | exp_name[PL_expect], | |
2426 | pv_display(tmp, s, strlen(s), 0, 60)); | |
2427 | SvREFCNT_dec(tmp); | |
bbf60fe6 | 2428 | } ); |
02aa26ce | 2429 | /* check if there's an identifier for us to look at */ |
ba979b31 | 2430 | if (PL_pending_ident) |
bbf60fe6 | 2431 | return REPORT(S_pending_ident(aTHX)); |
bbce6d69 | 2432 | |
02aa26ce NT |
2433 | /* no identifier pending identification */ |
2434 | ||
3280af22 | 2435 | switch (PL_lex_state) { |
79072805 LW |
2436 | #ifdef COMMENTARY |
2437 | case LEX_NORMAL: /* Some compilers will produce faster */ | |
2438 | case LEX_INTERPNORMAL: /* code if we comment these out. */ | |
2439 | break; | |
2440 | #endif | |
2441 | ||
09bef843 | 2442 | /* when we've already built the next token, just pull it out of the queue */ |
79072805 | 2443 | case LEX_KNOWNEXT: |
3280af22 NIS |
2444 | PL_nexttoke--; |
2445 | yylval = PL_nextval[PL_nexttoke]; | |
2446 | if (!PL_nexttoke) { | |
2447 | PL_lex_state = PL_lex_defer; | |
2448 | PL_expect = PL_lex_expect; | |
2449 | PL_lex_defer = LEX_NORMAL; | |
463ee0b2 | 2450 | } |
bbf60fe6 | 2451 | return REPORT(PL_nexttype[PL_nexttoke]); |
79072805 | 2452 | |
02aa26ce | 2453 | /* interpolated case modifiers like \L \U, including \Q and \E. |
3280af22 | 2454 | when we get here, PL_bufptr is at the \ |
02aa26ce | 2455 | */ |
79072805 LW |
2456 | case LEX_INTERPCASEMOD: |
2457 | #ifdef DEBUGGING | |
3280af22 | 2458 | if (PL_bufptr != PL_bufend && *PL_bufptr != '\\') |
cea2e8a9 | 2459 | Perl_croak(aTHX_ "panic: INTERPCASEMOD"); |
79072805 | 2460 | #endif |
02aa26ce | 2461 | /* handle \E or end of string */ |
3280af22 | 2462 | if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') { |
02aa26ce | 2463 | /* if at a \E */ |
3280af22 | 2464 | if (PL_lex_casemods) { |
f54cb97a | 2465 | const char oldmod = PL_lex_casestack[--PL_lex_casemods]; |
3280af22 | 2466 | PL_lex_casestack[PL_lex_casemods] = '\0'; |
02aa26ce | 2467 | |
3792a11b NC |
2468 | if (PL_bufptr != PL_bufend |
2469 | && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) { | |
3280af22 NIS |
2470 | PL_bufptr += 2; |
2471 | PL_lex_state = LEX_INTERPCONCAT; | |
a0d0e21e | 2472 | } |
bbf60fe6 | 2473 | return REPORT(')'); |
79072805 | 2474 | } |
3280af22 NIS |
2475 | if (PL_bufptr != PL_bufend) |
2476 | PL_bufptr += 2; | |
2477 | PL_lex_state = LEX_INTERPCONCAT; | |
cea2e8a9 | 2478 | return yylex(); |
79072805 LW |
2479 | } |
2480 | else { | |
607df283 | 2481 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
b6007c36 | 2482 | "### Saw case modifier\n"); }); |
3280af22 | 2483 | s = PL_bufptr + 1; |
6e909404 JH |
2484 | if (s[1] == '\\' && s[2] == 'E') { |
2485 | PL_bufptr = s + 3; | |
2486 | PL_lex_state = LEX_INTERPCONCAT; | |
2487 | return yylex(); | |
a0d0e21e | 2488 | } |
6e909404 JH |
2489 | else { |
2490 | if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3)) | |
2491 | tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */ | |
3792a11b | 2492 | if ((*s == 'L' || *s == 'U') && |
6e909404 JH |
2493 | (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) { |
2494 | PL_lex_casestack[--PL_lex_casemods] = '\0'; | |
bbf60fe6 | 2495 | return REPORT(')'); |
6e909404 JH |
2496 | } |
2497 | if (PL_lex_casemods > 10) | |
2498 | Renew(PL_lex_casestack, PL_lex_casemods + 2, char); | |
2499 | PL_lex_casestack[PL_lex_casemods++] = *s; | |
2500 | PL_lex_casestack[PL_lex_casemods] = '\0'; | |
2501 | PL_lex_state = LEX_INTERPCONCAT; | |
2502 | PL_nextval[PL_nexttoke].ival = 0; | |
2503 | force_next('('); | |
2504 | if (*s == 'l') | |
2505 | PL_nextval[PL_nexttoke].ival = OP_LCFIRST; | |
2506 | else if (*s == 'u') | |
2507 | PL_nextval[PL_nexttoke].ival = OP_UCFIRST; | |
2508 | else if (*s == 'L') | |
2509 | PL_nextval[PL_nexttoke].ival = OP_LC; | |
2510 | else if (*s == 'U') | |
2511 | PL_nextval[PL_nexttoke].ival = OP_UC; | |
2512 | else if (*s == 'Q') | |
2513 | PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA; | |
2514 | else | |
2515 | Perl_croak(aTHX_ "panic: yylex"); | |
2516 | PL_bufptr = s + 1; | |
a0d0e21e | 2517 | } |
79072805 | 2518 | force_next(FUNC); |
3280af22 NIS |
2519 | if (PL_lex_starts) { |
2520 | s = PL_bufptr; | |
2521 | PL_lex_starts = 0; | |
131b3ad0 DM |
2522 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ |
2523 | if (PL_lex_casemods == 1 && PL_lex_inpat) | |
2524 | OPERATOR(','); | |
2525 | else | |
2526 | Aop(OP_CONCAT); | |
79072805 LW |
2527 | } |
2528 | else | |
cea2e8a9 | 2529 | return yylex(); |
79072805 LW |
2530 | } |
2531 | ||
55497cff | 2532 | case LEX_INTERPPUSH: |
bbf60fe6 | 2533 | return REPORT(sublex_push()); |
55497cff | 2534 | |
79072805 | 2535 | case LEX_INTERPSTART: |
3280af22 | 2536 | if (PL_bufptr == PL_bufend) |
bbf60fe6 | 2537 | return REPORT(sublex_done()); |
607df283 | 2538 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
b6007c36 | 2539 | "### Interpolated variable\n"); }); |
3280af22 NIS |
2540 | PL_expect = XTERM; |
2541 | PL_lex_dojoin = (*PL_bufptr == '@'); | |
2542 | PL_lex_state = LEX_INTERPNORMAL; | |
2543 | if (PL_lex_dojoin) { | |
2544 | PL_nextval[PL_nexttoke].ival = 0; | |
79072805 | 2545 | force_next(','); |
a0d0e21e | 2546 | force_ident("\"", '$'); |
3280af22 | 2547 | PL_nextval[PL_nexttoke].ival = 0; |
79072805 | 2548 | force_next('$'); |
3280af22 | 2549 | PL_nextval[PL_nexttoke].ival = 0; |
79072805 | 2550 | force_next('('); |
3280af22 | 2551 | PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */ |
79072805 LW |
2552 | force_next(FUNC); |
2553 | } | |
3280af22 NIS |
2554 | if (PL_lex_starts++) { |
2555 | s = PL_bufptr; | |
131b3ad0 DM |
2556 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ |
2557 | if (!PL_lex_casemods && PL_lex_inpat) | |
2558 | OPERATOR(','); | |
2559 | else | |
2560 | Aop(OP_CONCAT); | |
79072805 | 2561 | } |
cea2e8a9 | 2562 | return yylex(); |
79072805 LW |
2563 | |
2564 | case LEX_INTERPENDMAYBE: | |
3280af22 NIS |
2565 | if (intuit_more(PL_bufptr)) { |
2566 | PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */ | |
79072805 LW |
2567 | break; |
2568 | } | |
2569 | /* FALL THROUGH */ | |
2570 | ||
2571 | case LEX_INTERPEND: | |
3280af22 NIS |
2572 | if (PL_lex_dojoin) { |
2573 | PL_lex_dojoin = FALSE; | |
2574 | PL_lex_state = LEX_INTERPCONCAT; | |
bbf60fe6 | 2575 | return REPORT(')'); |
79072805 | 2576 | } |
43a16006 | 2577 | if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl |
25da4f38 | 2578 | && SvEVALED(PL_lex_repl)) |
43a16006 | 2579 | { |
e9fa98b2 | 2580 | if (PL_bufptr != PL_bufend) |
cea2e8a9 | 2581 | Perl_croak(aTHX_ "Bad evalled substitution pattern"); |
e9fa98b2 HS |
2582 | PL_lex_repl = Nullsv; |
2583 | } | |
79072805 LW |
2584 | /* FALLTHROUGH */ |
2585 | case LEX_INTERPCONCAT: | |
2586 | #ifdef DEBUGGING | |
3280af22 | 2587 | if (PL_lex_brackets) |
cea2e8a9 | 2588 | Perl_croak(aTHX_ "panic: INTERPCONCAT"); |
79072805 | 2589 | #endif |
3280af22 | 2590 | if (PL_bufptr == PL_bufend) |
bbf60fe6 | 2591 | return REPORT(sublex_done()); |
79072805 | 2592 | |
3280af22 NIS |
2593 | if (SvIVX(PL_linestr) == '\'') { |
2594 | SV *sv = newSVsv(PL_linestr); | |
2595 | if (!PL_lex_inpat) | |
76e3520e | 2596 | sv = tokeq(sv); |
3280af22 | 2597 | else if ( PL_hints & HINT_NEW_RE ) |
b3ac6de7 | 2598 | sv = new_constant(NULL, 0, "qr", sv, sv, "q"); |
79072805 | 2599 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
3280af22 | 2600 | s = PL_bufend; |
79072805 LW |
2601 | } |
2602 | else { | |
3280af22 | 2603 | s = scan_const(PL_bufptr); |
79072805 | 2604 | if (*s == '\\') |
3280af22 | 2605 | PL_lex_state = LEX_INTERPCASEMOD; |
79072805 | 2606 | else |
3280af22 | 2607 | PL_lex_state = LEX_INTERPSTART; |
79072805 LW |
2608 | } |
2609 | ||
3280af22 NIS |
2610 | if (s != PL_bufptr) { |
2611 | PL_nextval[PL_nexttoke] = yylval; | |
2612 | PL_expect = XTERM; | |
79072805 | 2613 | force_next(THING); |
131b3ad0 DM |
2614 | if (PL_lex_starts++) { |
2615 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ | |
2616 | if (!PL_lex_casemods && PL_lex_inpat) | |
2617 | OPERATOR(','); | |
2618 | else | |
2619 | Aop(OP_CONCAT); | |
2620 | } | |
79072805 | 2621 | else { |
3280af22 | 2622 | PL_bufptr = s; |
cea2e8a9 | 2623 | return yylex(); |
79072805 LW |
2624 | } |
2625 | } | |
2626 | ||
cea2e8a9 | 2627 | return yylex(); |
a0d0e21e | 2628 | case LEX_FORMLINE: |
3280af22 NIS |
2629 | PL_lex_state = LEX_NORMAL; |
2630 | s = scan_formline(PL_bufptr); | |
2631 | if (!PL_lex_formbrack) | |
a0d0e21e LW |
2632 | goto rightbracket; |
2633 | OPERATOR(';'); | |
79072805 LW |
2634 | } |
2635 | ||
3280af22 NIS |
2636 | s = PL_bufptr; |
2637 | PL_oldoldbufptr = PL_oldbufptr; | |
2638 | PL_oldbufptr = s; | |
463ee0b2 LW |
2639 | |
2640 | retry: | |
378cc40b LW |
2641 | switch (*s) { |
2642 | default: | |
7e2040f0 | 2643 | if (isIDFIRST_lazy_if(s,UTF)) |
834a4ddd | 2644 | goto keylookup; |
cea2e8a9 | 2645 | Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255); |
e929a76b LW |
2646 | case 4: |
2647 | case 26: | |
2648 | goto fake_eof; /* emulate EOF on ^D or ^Z */ | |
378cc40b | 2649 | case 0: |
3280af22 NIS |
2650 | if (!PL_rsfp) { |
2651 | PL_last_uni = 0; | |
2652 | PL_last_lop = 0; | |
c5ee2135 WL |
2653 | if (PL_lex_brackets) { |
2654 | if (PL_lex_formbrack) | |
2655 | yyerror("Format not terminated"); | |
2656 | else | |
2657 | yyerror("Missing right curly or square bracket"); | |
2658 | } | |
4e553d73 | 2659 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
607df283 | 2660 | "### Tokener got EOF\n"); |
5f80b19c | 2661 | } ); |
79072805 | 2662 | TOKEN(0); |
463ee0b2 | 2663 | } |
3280af22 | 2664 | if (s++ < PL_bufend) |
a687059c | 2665 | goto retry; /* ignore stray nulls */ |
3280af22 NIS |
2666 | PL_last_uni = 0; |
2667 | PL_last_lop = 0; | |
2668 | if (!PL_in_eval && !PL_preambled) { | |
2669 | PL_preambled = TRUE; | |
2670 | sv_setpv(PL_linestr,incl_perldb()); | |
2671 | if (SvCUR(PL_linestr)) | |
4147a61b | 2672 | sv_catpvn(PL_linestr,";", 1); |
3280af22 NIS |
2673 | if (PL_preambleav){ |
2674 | while(AvFILLp(PL_preambleav) >= 0) { | |
2675 | SV *tmpsv = av_shift(PL_preambleav); | |
2676 | sv_catsv(PL_linestr, tmpsv); | |
4147a61b | 2677 | sv_catpvn(PL_linestr, ";", 1); |
91b7def8 | 2678 | sv_free(tmpsv); |
2679 | } | |
3280af22 NIS |
2680 | sv_free((SV*)PL_preambleav); |
2681 | PL_preambleav = NULL; | |
91b7def8 | 2682 | } |
3280af22 NIS |
2683 | if (PL_minus_n || PL_minus_p) { |
2684 | sv_catpv(PL_linestr, "LINE: while (<>) {"); | |
2685 | if (PL_minus_l) | |
2686 | sv_catpv(PL_linestr,"chomp;"); | |
2687 | if (PL_minus_a) { | |
3280af22 | 2688 | if (PL_minus_F) { |
3792a11b NC |
2689 | if ((*PL_splitstr == '/' || *PL_splitstr == '\'' |
2690 | || *PL_splitstr == '"') | |
3280af22 | 2691 | && strchr(PL_splitstr + 1, *PL_splitstr)) |
3db68c4c | 2692 | Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr); |
54310121 | 2693 | else { |
c8ef6a4b NC |
2694 | /* "q\0${splitstr}\0" is legal perl. Yes, even NUL |
2695 | bytes can be used as quoting characters. :-) */ | |
48c4c863 NC |
2696 | /* The count here deliberately includes the NUL |
2697 | that terminates the C string constant. This | |
2698 | embeds the opening NUL into the string. */ | |
dd374669 | 2699 | const char *splits = PL_splitstr; |
9a3fb652 | 2700 | sv_catpvn(PL_linestr, "our @F=split(q", 15); |
48c4c863 NC |
2701 | do { |
2702 | /* Need to \ \s */ | |
dd374669 AL |
2703 | if (*splits == '\\') |
2704 | sv_catpvn(PL_linestr, splits, 1); | |
2705 | sv_catpvn(PL_linestr, splits, 1); | |
2706 | } while (*splits++); | |
48c4c863 NC |
2707 | /* This loop will embed the trailing NUL of |
2708 | PL_linestr as the last thing it does before | |
2709 | terminating. */ | |
4fccd7c6 | 2710 | sv_catpvn(PL_linestr, ");", 2); |
54310121 | 2711 | } |
2304df62 AD |
2712 | } |
2713 | else | |
75c72d73 | 2714 | sv_catpv(PL_linestr,"our @F=split(' ');"); |
2304df62 | 2715 | } |
79072805 | 2716 | } |
4147a61b | 2717 | sv_catpvn(PL_linestr, "\n", 1); |
3280af22 NIS |
2718 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
2719 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2720 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 2721 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
9d4ba2ae | 2722 | SV * const sv = NEWSV(85,0); |
a0d0e21e LW |
2723 | |
2724 | sv_upgrade(sv, SVt_PVMG); | |
3280af22 | 2725 | sv_setsv(sv,PL_linestr); |
0ac0412a | 2726 | (void)SvIOK_on(sv); |
45977657 | 2727 | SvIV_set(sv, 0); |
57843af0 | 2728 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
a0d0e21e | 2729 | } |
79072805 | 2730 | goto retry; |
a687059c | 2731 | } |
e929a76b | 2732 | do { |
aa7440fb | 2733 | bof = PL_rsfp ? TRUE : FALSE; |
7e28d3af JH |
2734 | if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) { |
2735 | fake_eof: | |
2736 | if (PL_rsfp) { | |
2737 | if (PL_preprocess && !PL_in_eval) | |
2738 | (void)PerlProc_pclose(PL_rsfp); | |
2739 | else if ((PerlIO *)PL_rsfp == PerlIO_stdin()) | |
2740 | PerlIO_clearerr(PL_rsfp); | |
2741 | else | |
2742 | (void)PerlIO_close(PL_rsfp); | |
2743 | PL_rsfp = Nullfp; | |
2744 | PL_doextract = FALSE; | |
2745 | } | |
2746 | if (!PL_in_eval && (PL_minus_n || PL_minus_p)) { | |
a23c4656 NC |
2747 | sv_setpv(PL_linestr,PL_minus_p |
2748 | ? ";}continue{print;}" : ";}"); | |
7e28d3af JH |
2749 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
2750 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2751 | PL_last_lop = PL_last_uni = Nullch; |
7e28d3af JH |
2752 | PL_minus_n = PL_minus_p = 0; |
2753 | goto retry; | |
2754 | } | |
2755 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); | |
207e3d1a | 2756 | PL_last_lop = PL_last_uni = Nullch; |
c69006e4 | 2757 | sv_setpvn(PL_linestr,"",0); |
7e28d3af JH |
2758 | TOKEN(';'); /* not infinite loop because rsfp is NULL now */ |
2759 | } | |
7aa207d6 JH |
2760 | /* If it looks like the start of a BOM or raw UTF-16, |
2761 | * check if it in fact is. */ | |
2762 | else if (bof && | |
2763 | (*s == 0 || | |
2764 | *(U8*)s == 0xEF || | |
2765 | *(U8*)s >= 0xFE || | |
2766 | s[1] == 0)) { | |
226017aa | 2767 | #ifdef PERLIO_IS_STDIO |
e3f494f1 JH |
2768 | # ifdef __GNU_LIBRARY__ |
2769 | # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */ | |
226017aa DD |
2770 | # define FTELL_FOR_PIPE_IS_BROKEN |
2771 | # endif | |
e3f494f1 JH |
2772 | # else |
2773 | # ifdef __GLIBC__ | |
2774 | # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */ | |
2775 | # define FTELL_FOR_PIPE_IS_BROKEN | |
2776 | # endif | |
2777 | # endif | |
226017aa DD |
2778 | # endif |
2779 | #endif | |
2780 | #ifdef FTELL_FOR_PIPE_IS_BROKEN | |
2781 | /* This loses the possibility to detect the bof | |
2782 | * situation on perl -P when the libc5 is being used. | |
2783 | * Workaround? Maybe attach some extra state to PL_rsfp? | |
2784 | */ | |
2785 | if (!PL_preprocess) | |
7e28d3af | 2786 | bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr); |
226017aa | 2787 | #else |
eb160463 | 2788 | bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr); |
226017aa | 2789 | #endif |
7e28d3af | 2790 | if (bof) { |
3280af22 | 2791 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
7e28d3af | 2792 | s = swallow_bom((U8*)s); |
e929a76b | 2793 | } |
378cc40b | 2794 | } |
3280af22 | 2795 | if (PL_doextract) { |
a0d0e21e LW |
2796 | /* Incest with pod. */ |
2797 | if (*s == '=' && strnEQ(s, "=cut", 4)) { | |
c69006e4 | 2798 | sv_setpvn(PL_linestr, "", 0); |
3280af22 NIS |
2799 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
2800 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2801 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 2802 | PL_doextract = FALSE; |
a0d0e21e | 2803 | } |
4e553d73 | 2804 | } |
463ee0b2 | 2805 | incline(s); |
3280af22 NIS |
2806 | } while (PL_doextract); |
2807 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s; | |
2808 | if (PERLDB_LINE && PL_curstash != PL_debstash) { | |
9d4ba2ae | 2809 | SV * const sv = NEWSV(85,0); |
a687059c | 2810 | |
93a17b20 | 2811 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 2812 | sv_setsv(sv,PL_linestr); |
0ac0412a | 2813 | (void)SvIOK_on(sv); |
45977657 | 2814 | SvIV_set(sv, 0); |
57843af0 | 2815 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
a687059c | 2816 | } |
3280af22 | 2817 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 2818 | PL_last_lop = PL_last_uni = Nullch; |
57843af0 | 2819 | if (CopLINE(PL_curcop) == 1) { |
3280af22 | 2820 | while (s < PL_bufend && isSPACE(*s)) |
79072805 | 2821 | s++; |
a0d0e21e | 2822 | if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */ |
79072805 | 2823 | s++; |
44a8e56a | 2824 | d = Nullch; |
3280af22 | 2825 | if (!PL_in_eval) { |
44a8e56a | 2826 | if (*s == '#' && *(s+1) == '!') |
2827 | d = s + 2; | |
2828 | #ifdef ALTERNATE_SHEBANG | |
2829 | else { | |
bfed75c6 | 2830 | static char const as[] = ALTERNATE_SHEBANG; |
44a8e56a | 2831 | if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1)) |
2832 | d = s + (sizeof(as) - 1); | |
2833 | } | |
2834 | #endif /* ALTERNATE_SHEBANG */ | |
2835 | } | |
2836 | if (d) { | |
b8378b72 | 2837 | char *ipath; |
774d564b | 2838 | char *ipathend; |
b8378b72 | 2839 | |
774d564b | 2840 | while (isSPACE(*d)) |
b8378b72 CS |
2841 | d++; |
2842 | ipath = d; | |
774d564b | 2843 | while (*d && !isSPACE(*d)) |
2844 | d++; | |
2845 | ipathend = d; | |
2846 | ||
2847 | #ifdef ARG_ZERO_IS_SCRIPT | |
2848 | if (ipathend > ipath) { | |
2849 | /* | |
2850 | * HP-UX (at least) sets argv[0] to the script name, | |
2851 | * which makes $^X incorrect. And Digital UNIX and Linux, | |
2852 | * at least, set argv[0] to the basename of the Perl | |
2853 | * interpreter. So, having found "#!", we'll set it right. | |
2854 | */ | |
551405c4 | 2855 | SV * const x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV)); /* $^X */ |
774d564b | 2856 | assert(SvPOK(x) || SvGMAGICAL(x)); |
cc49e20b | 2857 | if (sv_eq(x, CopFILESV(PL_curcop))) { |
774d564b | 2858 | sv_setpvn(x, ipath, ipathend - ipath); |
9607fc9c | 2859 | SvSETMAGIC(x); |
2860 | } | |
556c1dec JH |
2861 | else { |
2862 | STRLEN blen; | |
2863 | STRLEN llen; | |
cfd0369c | 2864 | const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen); |
9d4ba2ae | 2865 | const char * const lstart = SvPV_const(x,llen); |
556c1dec JH |
2866 | if (llen < blen) { |
2867 | bstart += blen - llen; | |
2868 | if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') { | |
2869 | sv_setpvn(x, ipath, ipathend - ipath); | |
2870 | SvSETMAGIC(x); | |
2871 | } | |
2872 | } | |
2873 | } | |
774d564b | 2874 | TAINT_NOT; /* $^X is always tainted, but that's OK */ |
8ebc5c01 | 2875 | } |
774d564b | 2876 | #endif /* ARG_ZERO_IS_SCRIPT */ |
b8378b72 CS |
2877 | |
2878 | /* | |
2879 | * Look for options. | |
2880 | */ | |
748a9306 | 2881 | d = instr(s,"perl -"); |
84e30d1a | 2882 | if (!d) { |
748a9306 | 2883 | d = instr(s,"perl"); |
84e30d1a GS |
2884 | #if defined(DOSISH) |
2885 | /* avoid getting into infinite loops when shebang | |
2886 | * line contains "Perl" rather than "perl" */ | |
2887 | if (!d) { | |
2888 | for (d = ipathend-4; d >= ipath; --d) { | |
2889 | if ((*d == 'p' || *d == 'P') | |
2890 | && !ibcmp(d, "perl", 4)) | |
2891 | { | |
2892 | break; | |
2893 | } | |
2894 | } | |
2895 | if (d < ipath) | |
2896 | d = Nullch; | |
2897 | } | |
2898 | #endif | |
2899 | } | |
44a8e56a | 2900 | #ifdef ALTERNATE_SHEBANG |
2901 | /* | |
2902 | * If the ALTERNATE_SHEBANG on this system starts with a | |
2903 | * character that can be part of a Perl expression, then if | |
2904 | * we see it but not "perl", we're probably looking at the | |
2905 | * start of Perl code, not a request to hand off to some | |
2906 | * other interpreter. Similarly, if "perl" is there, but | |
2907 | * not in the first 'word' of the line, we assume the line | |
2908 | * contains the start of the Perl program. | |
44a8e56a | 2909 | */ |
2910 | if (d && *s != '#') { | |
f54cb97a | 2911 | const char *c = ipath; |
44a8e56a | 2912 | while (*c && !strchr("; \t\r\n\f\v#", *c)) |
2913 | c++; | |
2914 | if (c < d) | |
2915 | d = Nullch; /* "perl" not in first word; ignore */ | |
2916 | else | |
2917 | *s = '#'; /* Don't try to parse shebang line */ | |
2918 | } | |
774d564b | 2919 | #endif /* ALTERNATE_SHEBANG */ |
bf4acbe4 | 2920 | #ifndef MACOS_TRADITIONAL |
748a9306 | 2921 | if (!d && |
44a8e56a | 2922 | *s == '#' && |
774d564b | 2923 | ipathend > ipath && |
3280af22 | 2924 | !PL_minus_c && |
748a9306 | 2925 | !instr(s,"indir") && |
3280af22 | 2926 | instr(PL_origargv[0],"perl")) |
748a9306 | 2927 | { |
27da23d5 | 2928 | dVAR; |
9f68db38 | 2929 | char **newargv; |
9f68db38 | 2930 | |
774d564b | 2931 | *ipathend = '\0'; |
2932 | s = ipathend + 1; | |
3280af22 | 2933 | while (s < PL_bufend && isSPACE(*s)) |
9f68db38 | 2934 | s++; |
3280af22 | 2935 | if (s < PL_bufend) { |
a02a5408 | 2936 | Newxz(newargv,PL_origargc+3,char*); |
9f68db38 | 2937 | newargv[1] = s; |
3280af22 | 2938 | while (s < PL_bufend && !isSPACE(*s)) |
9f68db38 LW |
2939 | s++; |
2940 | *s = '\0'; | |
3280af22 | 2941 | Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*); |
9f68db38 LW |
2942 | } |
2943 | else | |
3280af22 | 2944 | newargv = PL_origargv; |
774d564b | 2945 | newargv[0] = ipath; |
b35112e7 | 2946 | PERL_FPU_PRE_EXEC |
b4748376 | 2947 | PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv)); |
b35112e7 | 2948 | PERL_FPU_POST_EXEC |
cea2e8a9 | 2949 | Perl_croak(aTHX_ "Can't exec %s", ipath); |
9f68db38 | 2950 | } |
bf4acbe4 | 2951 | #endif |
748a9306 | 2952 | if (d) { |
f54cb97a AL |
2953 | const U32 oldpdb = PL_perldb; |
2954 | const bool oldn = PL_minus_n; | |
2955 | const bool oldp = PL_minus_p; | |
748a9306 LW |
2956 | |
2957 | while (*d && !isSPACE(*d)) d++; | |
bf4acbe4 | 2958 | while (SPACE_OR_TAB(*d)) d++; |
748a9306 LW |
2959 | |
2960 | if (*d++ == '-') { | |
f54cb97a | 2961 | const bool switches_done = PL_doswitches; |
8cc95fdb | 2962 | do { |
3ffe3ee4 | 2963 | if (*d == 'M' || *d == 'm' || *d == 'C') { |
9d4ba2ae | 2964 | const char * const m = d; |
8cc95fdb | 2965 | while (*d && !isSPACE(*d)) d++; |
cea2e8a9 | 2966 | Perl_croak(aTHX_ "Too late for \"-%.*s\" option", |
8cc95fdb | 2967 | (int)(d - m), m); |
2968 | } | |
2969 | d = moreswitches(d); | |
2970 | } while (d); | |
f0b2cf55 YST |
2971 | if (PL_doswitches && !switches_done) { |
2972 | int argc = PL_origargc; | |
2973 | char **argv = PL_origargv; | |
2974 | do { | |
2975 | argc--,argv++; | |
2976 | } while (argc && argv[0][0] == '-' && argv[0][1]); | |
2977 | init_argv_symbols(argc,argv); | |
2978 | } | |
155aba94 GS |
2979 | if ((PERLDB_LINE && !oldpdb) || |
2980 | ((PL_minus_n || PL_minus_p) && !(oldn || oldp))) | |
b084f20b | 2981 | /* if we have already added "LINE: while (<>) {", |
2982 | we must not do it again */ | |
748a9306 | 2983 | { |
c69006e4 | 2984 | sv_setpvn(PL_linestr, "", 0); |
3280af22 NIS |
2985 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
2986 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2987 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 2988 | PL_preambled = FALSE; |
84902520 | 2989 | if (PERLDB_LINE) |
3280af22 | 2990 | (void)gv_fetchfile(PL_origfilename); |
748a9306 LW |
2991 | goto retry; |
2992 | } | |
a11ec5a9 RGS |
2993 | if (PL_doswitches && !switches_done) { |
2994 | int argc = PL_origargc; | |
2995 | char **argv = PL_origargv; | |
2996 | do { | |
2997 | argc--,argv++; | |
2998 | } while (argc && argv[0][0] == '-' && argv[0][1]); | |
2999 | init_argv_symbols(argc,argv); | |
3000 | } | |
a0d0e21e | 3001 | } |
79072805 | 3002 | } |
9f68db38 | 3003 | } |
79072805 | 3004 | } |
3280af22 NIS |
3005 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
3006 | PL_bufptr = s; | |
3007 | PL_lex_state = LEX_FORMLINE; | |
cea2e8a9 | 3008 | return yylex(); |
ae986130 | 3009 | } |
378cc40b | 3010 | goto retry; |
4fdae800 | 3011 | case '\r': |
6a27c188 | 3012 | #ifdef PERL_STRICT_CR |
cea2e8a9 | 3013 | Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r'); |
4e553d73 | 3014 | Perl_croak(aTHX_ |
cc507455 | 3015 | "\t(Maybe you didn't strip carriage returns after a network transfer?)\n"); |
a868473f | 3016 | #endif |
4fdae800 | 3017 | case ' ': case '\t': case '\f': case 013: |
bf4acbe4 GS |
3018 | #ifdef MACOS_TRADITIONAL |
3019 | case '\312': | |
3020 | #endif | |
378cc40b LW |
3021 | s++; |
3022 | goto retry; | |
378cc40b | 3023 | case '#': |
e929a76b | 3024 | case '\n': |
3280af22 | 3025 | if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) { |
df0deb90 GS |
3026 | if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) { |
3027 | /* handle eval qq[#line 1 "foo"\n ...] */ | |
3028 | CopLINE_dec(PL_curcop); | |
3029 | incline(s); | |
3030 | } | |
3280af22 | 3031 | d = PL_bufend; |
a687059c | 3032 | while (s < d && *s != '\n') |
378cc40b | 3033 | s++; |
0f85fab0 | 3034 | if (s < d) |
378cc40b | 3035 | s++; |
78c267c1 | 3036 | else if (s > d) /* Found by Ilya: feed random input to Perl. */ |
a8406387 | 3037 | Perl_croak(aTHX_ "panic: input overflow"); |
463ee0b2 | 3038 | incline(s); |
3280af22 NIS |
3039 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
3040 | PL_bufptr = s; | |
3041 | PL_lex_state = LEX_FORMLINE; | |
cea2e8a9 | 3042 | return yylex(); |
a687059c | 3043 | } |
378cc40b | 3044 | } |
a687059c | 3045 | else { |
378cc40b | 3046 | *s = '\0'; |
3280af22 | 3047 | PL_bufend = s; |
a687059c | 3048 | } |
378cc40b LW |
3049 | goto retry; |
3050 | case '-': | |
79072805 | 3051 | if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) { |
e5edeb50 JH |
3052 | I32 ftst = 0; |
3053 | ||
378cc40b | 3054 | s++; |
3280af22 | 3055 | PL_bufptr = s; |
748a9306 LW |
3056 | tmp = *s++; |
3057 | ||
bf4acbe4 | 3058 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
748a9306 LW |
3059 | s++; |
3060 | ||
3061 | if (strnEQ(s,"=>",2)) { | |
3280af22 | 3062 | s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE); |
b6007c36 DM |
3063 | DEBUG_T( { S_printbuf(aTHX_ |
3064 | "### Saw unary minus before =>, forcing word %s\n", s); | |
5f80b19c | 3065 | } ); |
748a9306 LW |
3066 | OPERATOR('-'); /* unary minus */ |
3067 | } | |
3280af22 | 3068 | PL_last_uni = PL_oldbufptr; |
748a9306 | 3069 | switch (tmp) { |
e5edeb50 JH |
3070 | case 'r': ftst = OP_FTEREAD; break; |
3071 | case 'w': ftst = OP_FTEWRITE; break; | |
3072 | case 'x': ftst = OP_FTEEXEC; break; | |
3073 | case 'o': ftst = OP_FTEOWNED; break; | |
3074 | case 'R': ftst = OP_FTRREAD; break; | |
3075 | case 'W': ftst = OP_FTRWRITE; break; | |
3076 | case 'X': ftst = OP_FTREXEC; break; | |
3077 | case 'O': ftst = OP_FTROWNED; break; | |
3078 | case 'e': ftst = OP_FTIS; break; | |
3079 | case 'z': ftst = OP_FTZERO; break; | |
3080 | case 's': ftst = OP_FTSIZE; break; | |
3081 | case 'f': ftst = OP_FTFILE; break; | |
3082 | case 'd': ftst = OP_FTDIR; break; | |
3083 | case 'l': ftst = OP_FTLINK; break; | |
3084 | case 'p': ftst = OP_FTPIPE; break; | |
3085 | case 'S': ftst = OP_FTSOCK; break; | |
3086 | case 'u': ftst = OP_FTSUID; break; | |
3087 | case 'g': ftst = OP_FTSGID; break; | |
3088 | case 'k': ftst = OP_FTSVTX; break; | |
3089 | case 'b': ftst = OP_FTBLK; break; | |
3090 | case 'c': ftst = OP_FTCHR; break; | |
3091 | case 't': ftst = OP_FTTTY; break; | |
3092 | case 'T': ftst = OP_FTTEXT; break; | |
3093 | case 'B': ftst = OP_FTBINARY; break; | |
3094 | case 'M': case 'A': case 'C': | |
3095 | gv_fetchpv("\024",TRUE, SVt_PV); | |
3096 | switch (tmp) { | |
3097 | case 'M': ftst = OP_FTMTIME; break; | |
3098 | case 'A': ftst = OP_FTATIME; break; | |
3099 | case 'C': ftst = OP_FTCTIME; break; | |
3100 | default: break; | |
3101 | } | |
3102 | break; | |
378cc40b | 3103 | default: |
378cc40b LW |
3104 | break; |
3105 | } | |
e5edeb50 | 3106 | if (ftst) { |
eb160463 | 3107 | PL_last_lop_op = (OPCODE)ftst; |
4e553d73 | 3108 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
a18d764d | 3109 | "### Saw file test %c\n", (int)tmp); |
5f80b19c | 3110 | } ); |
e5edeb50 JH |
3111 | FTST(ftst); |
3112 | } | |
3113 | else { | |
3114 | /* Assume it was a minus followed by a one-letter named | |
3115 | * subroutine call (or a -bareword), then. */ | |
95c31fe3 | 3116 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
17ad61e0 | 3117 | "### '-%c' looked like a file test but was not\n", |
4fccd7c6 | 3118 | (int) tmp); |
5f80b19c | 3119 | } ); |
3cf7b4c4 | 3120 | s = --PL_bufptr; |
e5edeb50 | 3121 | } |
378cc40b | 3122 | } |
a687059c LW |
3123 | tmp = *s++; |
3124 | if (*s == tmp) { | |
3125 | s++; | |
3280af22 | 3126 | if (PL_expect == XOPERATOR) |
79072805 LW |
3127 | TERM(POSTDEC); |
3128 | else | |
3129 | OPERATOR(PREDEC); | |
3130 | } | |
3131 | else if (*s == '>') { | |
3132 | s++; | |
3133 | s = skipspace(s); | |
7e2040f0 | 3134 | if (isIDFIRST_lazy_if(s,UTF)) { |
a0d0e21e | 3135 | s = force_word(s,METHOD,FALSE,TRUE,FALSE); |
463ee0b2 | 3136 | TOKEN(ARROW); |
79072805 | 3137 | } |
748a9306 LW |
3138 | else if (*s == '$') |
3139 | OPERATOR(ARROW); | |
463ee0b2 | 3140 | else |
748a9306 | 3141 | TERM(ARROW); |
a687059c | 3142 | } |
3280af22 | 3143 | if (PL_expect == XOPERATOR) |
79072805 LW |
3144 | Aop(OP_SUBTRACT); |
3145 | else { | |
3280af22 | 3146 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) |
2f3197b3 | 3147 | check_uni(); |
79072805 | 3148 | OPERATOR('-'); /* unary minus */ |
2f3197b3 | 3149 | } |
79072805 | 3150 | |
378cc40b | 3151 | case '+': |
a687059c LW |
3152 | tmp = *s++; |
3153 | if (*s == tmp) { | |
378cc40b | 3154 | s++; |
3280af22 | 3155 | if (PL_expect == XOPERATOR) |
79072805 LW |
3156 | TERM(POSTINC); |
3157 | else | |
3158 | OPERATOR(PREINC); | |
378cc40b | 3159 | } |
3280af22 | 3160 | if (PL_expect == XOPERATOR) |
79072805 LW |
3161 | Aop(OP_ADD); |
3162 | else { | |
3280af22 | 3163 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) |
2f3197b3 | 3164 | check_uni(); |
a687059c | 3165 | OPERATOR('+'); |
2f3197b3 | 3166 | } |
a687059c | 3167 | |
378cc40b | 3168 | case '*': |
3280af22 NIS |
3169 | if (PL_expect != XOPERATOR) { |
3170 | s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); | |
3171 | PL_expect = XOPERATOR; | |
3172 | force_ident(PL_tokenbuf, '*'); | |
3173 | if (!*PL_tokenbuf) | |
a0d0e21e | 3174 | PREREF('*'); |
79072805 | 3175 | TERM('*'); |
a687059c | 3176 | } |
79072805 LW |
3177 | s++; |
3178 | if (*s == '*') { | |
a687059c | 3179 | s++; |
79072805 | 3180 | PWop(OP_POW); |
a687059c | 3181 | } |
79072805 LW |
3182 | Mop(OP_MULTIPLY); |
3183 | ||
378cc40b | 3184 | case '%': |
3280af22 | 3185 | if (PL_expect == XOPERATOR) { |
bbce6d69 | 3186 | ++s; |
3187 | Mop(OP_MODULO); | |
a687059c | 3188 | } |
3280af22 NIS |
3189 | PL_tokenbuf[0] = '%'; |
3190 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE); | |
3191 | if (!PL_tokenbuf[1]) { | |
bbce6d69 | 3192 | PREREF('%'); |
a687059c | 3193 | } |
3280af22 | 3194 | PL_pending_ident = '%'; |
bbce6d69 | 3195 | TERM('%'); |
a687059c | 3196 | |
378cc40b | 3197 | case '^': |
79072805 | 3198 | s++; |
a0d0e21e | 3199 | BOop(OP_BIT_XOR); |
79072805 | 3200 | case '[': |
3280af22 | 3201 | PL_lex_brackets++; |
79072805 | 3202 | /* FALL THROUGH */ |
378cc40b | 3203 | case '~': |
378cc40b | 3204 | case ',': |
378cc40b LW |
3205 | tmp = *s++; |
3206 | OPERATOR(tmp); | |
a0d0e21e LW |
3207 | case ':': |
3208 | if (s[1] == ':') { | |
3209 | len = 0; | |
3210 | goto just_a_word; | |
3211 | } | |
3212 | s++; | |
09bef843 SB |
3213 | switch (PL_expect) { |
3214 | OP *attrs; | |
3215 | case XOPERATOR: | |
3216 | if (!PL_in_my || PL_lex_state != LEX_NORMAL) | |
3217 | break; | |
3218 | PL_bufptr = s; /* update in case we back off */ | |
3219 | goto grabattrs; | |
3220 | case XATTRBLOCK: | |
3221 | PL_expect = XBLOCK; | |
3222 | goto grabattrs; | |
3223 | case XATTRTERM: | |
3224 | PL_expect = XTERMBLOCK; | |
3225 | grabattrs: | |
3226 | s = skipspace(s); | |
3227 | attrs = Nullop; | |
7e2040f0 | 3228 | while (isIDFIRST_lazy_if(s,UTF)) { |
09bef843 | 3229 | d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
f9829d6b GS |
3230 | if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) { |
3231 | if (tmp < 0) tmp = -tmp; | |
3232 | switch (tmp) { | |
3233 | case KEY_or: | |
3234 | case KEY_and: | |
c963b151 | 3235 | case KEY_err: |
f9829d6b GS |
3236 | case KEY_for: |
3237 | case KEY_unless: | |
3238 | case KEY_if: | |
3239 | case KEY_while: | |
3240 | case KEY_until: | |
3241 | goto got_attrs; | |
3242 | default: | |
3243 | break; | |
3244 | } | |
3245 | } | |
09bef843 SB |
3246 | if (*d == '(') { |
3247 | d = scan_str(d,TRUE,TRUE); | |
3248 | if (!d) { | |
09bef843 SB |
3249 | /* MUST advance bufptr here to avoid bogus |
3250 | "at end of line" context messages from yyerror(). | |
3251 | */ | |
3252 | PL_bufptr = s + len; | |
3253 | yyerror("Unterminated attribute parameter in attribute list"); | |
3254 | if (attrs) | |
3255 | op_free(attrs); | |
bbf60fe6 | 3256 | return REPORT(0); /* EOF indicator */ |
09bef843 SB |
3257 | } |
3258 | } | |
3259 | if (PL_lex_stuff) { | |
3260 | SV *sv = newSVpvn(s, len); | |
3261 | sv_catsv(sv, PL_lex_stuff); | |
3262 | attrs = append_elem(OP_LIST, attrs, | |
3263 | newSVOP(OP_CONST, 0, sv)); | |
3264 | SvREFCNT_dec(PL_lex_stuff); | |
3265 | PL_lex_stuff = Nullsv; | |
3266 | } | |
3267 | else { | |
371fce9b DM |
3268 | if (len == 6 && strnEQ(s, "unique", len)) { |
3269 | if (PL_in_my == KEY_our) | |
3270 | #ifdef USE_ITHREADS | |
3271 | GvUNIQUE_on(cGVOPx_gv(yylval.opval)); | |
3272 | #else | |
3273 | ; /* skip to avoid loading attributes.pm */ | |
3274 | #endif | |
bfed75c6 | 3275 | else |
371fce9b DM |
3276 | Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables"); |
3277 | } | |
3278 | ||
d3cea301 SB |
3279 | /* NOTE: any CV attrs applied here need to be part of |
3280 | the CVf_BUILTIN_ATTRS define in cv.h! */ | |
371fce9b | 3281 | else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len)) |
78f9721b SM |
3282 | CvLVALUE_on(PL_compcv); |
3283 | else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len)) | |
3284 | CvLOCKED_on(PL_compcv); | |
3285 | else if (!PL_in_my && len == 6 && strnEQ(s, "method", len)) | |
3286 | CvMETHOD_on(PL_compcv); | |
06492da6 SF |
3287 | else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len)) |
3288 | CvASSERTION_on(PL_compcv); | |
78f9721b SM |
3289 | /* After we've set the flags, it could be argued that |
3290 | we don't need to do the attributes.pm-based setting | |
3291 | process, and shouldn't bother appending recognized | |
d3cea301 SB |
3292 | flags. To experiment with that, uncomment the |
3293 | following "else". (Note that's already been | |
3294 | uncommented. That keeps the above-applied built-in | |
3295 | attributes from being intercepted (and possibly | |
3296 | rejected) by a package's attribute routines, but is | |
3297 | justified by the performance win for the common case | |
3298 | of applying only built-in attributes.) */ | |
0256094b | 3299 | else |
78f9721b SM |
3300 | attrs = append_elem(OP_LIST, attrs, |
3301 | newSVOP(OP_CONST, 0, | |
3302 | newSVpvn(s, len))); | |
09bef843 SB |
3303 | } |
3304 | s = skipspace(d); | |
0120eecf | 3305 | if (*s == ':' && s[1] != ':') |
09bef843 | 3306 | s = skipspace(s+1); |
0120eecf GS |
3307 | else if (s == d) |
3308 | break; /* require real whitespace or :'s */ | |
09bef843 | 3309 | } |
f9829d6b | 3310 | tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */ |
8e7ae056 | 3311 | if (*s != ';' && *s != '}' && *s != tmp && (tmp != '=' || *s != ')')) { |
f54cb97a | 3312 | const char q = ((*s == '\'') ? '"' : '\''); |
09bef843 SB |
3313 | /* If here for an expression, and parsed no attrs, back off. */ |
3314 | if (tmp == '=' && !attrs) { | |
3315 | s = PL_bufptr; | |
3316 | break; | |
3317 | } | |
3318 | /* MUST advance bufptr here to avoid bogus "at end of line" | |
3319 | context messages from yyerror(). | |
3320 | */ | |
3321 | PL_bufptr = s; | |
3322 | if (!*s) | |
3323 | yyerror("Unterminated attribute list"); | |
3324 | else | |
3325 | yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list", | |
3326 | q, *s, q)); | |
3327 | if (attrs) | |
3328 | op_free(attrs); | |
3329 | OPERATOR(':'); | |
3330 | } | |
f9829d6b | 3331 | got_attrs: |
09bef843 SB |
3332 | if (attrs) { |
3333 | PL_nextval[PL_nexttoke].opval = attrs; | |
3334 | force_next(THING); | |
3335 | } | |
3336 | TOKEN(COLONATTR); | |
3337 | } | |
a0d0e21e | 3338 | OPERATOR(':'); |
8990e307 LW |
3339 | case '(': |
3340 | s++; | |
3280af22 NIS |
3341 | if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr) |
3342 | PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */ | |
a0d0e21e | 3343 | else |
3280af22 | 3344 | PL_expect = XTERM; |
4a202259 | 3345 | s = skipspace(s); |
a0d0e21e | 3346 | TOKEN('('); |
378cc40b | 3347 | case ';': |
f4dd75d9 | 3348 | CLINE; |
378cc40b LW |
3349 | tmp = *s++; |
3350 | OPERATOR(tmp); | |
3351 | case ')': | |
378cc40b | 3352 | tmp = *s++; |
16d20bd9 AD |
3353 | s = skipspace(s); |
3354 | if (*s == '{') | |
3355 | PREBLOCK(tmp); | |
378cc40b | 3356 | TERM(tmp); |
79072805 LW |
3357 | case ']': |
3358 | s++; | |
3280af22 | 3359 | if (PL_lex_brackets <= 0) |
d98d5fff | 3360 | yyerror("Unmatched right square bracket"); |
463ee0b2 | 3361 | else |
3280af22 NIS |
3362 | --PL_lex_brackets; |
3363 | if (PL_lex_state == LEX_INTERPNORMAL) { | |
3364 | if (PL_lex_brackets == 0) { | |
a0d0e21e | 3365 | if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>')) |
3280af22 | 3366 | PL_lex_state = LEX_INTERPEND; |
79072805 LW |
3367 | } |
3368 | } | |
4633a7c4 | 3369 | TERM(']'); |
79072805 LW |
3370 | case '{': |
3371 | leftbracket: | |
79072805 | 3372 | s++; |
3280af22 | 3373 | if (PL_lex_brackets > 100) { |
8edd5f42 | 3374 | Renew(PL_lex_brackstack, PL_lex_brackets + 10, char); |
8990e307 | 3375 | } |
3280af22 | 3376 | switch (PL_expect) { |
a0d0e21e | 3377 | case XTERM: |
3280af22 | 3378 | if (PL_lex_formbrack) { |
a0d0e21e LW |
3379 | s--; |
3380 | PRETERMBLOCK(DO); | |
3381 | } | |
3280af22 NIS |
3382 | if (PL_oldoldbufptr == PL_last_lop) |
3383 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; | |
a0d0e21e | 3384 | else |
3280af22 | 3385 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
79072805 | 3386 | OPERATOR(HASHBRACK); |
a0d0e21e | 3387 | case XOPERATOR: |
bf4acbe4 | 3388 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
748a9306 | 3389 | s++; |
44a8e56a | 3390 | d = s; |
3280af22 NIS |
3391 | PL_tokenbuf[0] = '\0'; |
3392 | if (d < PL_bufend && *d == '-') { | |
3393 | PL_tokenbuf[0] = '-'; | |
44a8e56a | 3394 | d++; |
bf4acbe4 | 3395 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
44a8e56a | 3396 | d++; |
3397 | } | |
7e2040f0 | 3398 | if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) { |
3280af22 | 3399 | d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, |
8903cb82 | 3400 | FALSE, &len); |
bf4acbe4 | 3401 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
748a9306 LW |
3402 | d++; |
3403 | if (*d == '}') { | |
f54cb97a | 3404 | const char minus = (PL_tokenbuf[0] == '-'); |
44a8e56a | 3405 | s = force_word(s + minus, WORD, FALSE, TRUE, FALSE); |
3406 | if (minus) | |
3407 | force_next('-'); | |
748a9306 LW |
3408 | } |
3409 | } | |
3410 | /* FALL THROUGH */ | |
09bef843 | 3411 | case XATTRBLOCK: |
748a9306 | 3412 | case XBLOCK: |
3280af22 NIS |
3413 | PL_lex_brackstack[PL_lex_brackets++] = XSTATE; |
3414 | PL_expect = XSTATE; | |
a0d0e21e | 3415 | break; |
09bef843 | 3416 | case XATTRTERM: |
a0d0e21e | 3417 | case XTERMBLOCK: |
3280af22 NIS |
3418 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
3419 | PL_expect = XSTATE; | |
a0d0e21e LW |
3420 | break; |
3421 | default: { | |
f54cb97a | 3422 | const char *t; |
3280af22 NIS |
3423 | if (PL_oldoldbufptr == PL_last_lop) |
3424 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; | |
a0d0e21e | 3425 | else |
3280af22 | 3426 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
a0d0e21e | 3427 | s = skipspace(s); |
8452ff4b SB |
3428 | if (*s == '}') { |
3429 | if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) { | |
3430 | PL_expect = XTERM; | |
3431 | /* This hack is to get the ${} in the message. */ | |
3432 | PL_bufptr = s+1; | |
3433 | yyerror("syntax error"); | |
3434 | break; | |
3435 | } | |
a0d0e21e | 3436 | OPERATOR(HASHBRACK); |
8452ff4b | 3437 | } |
b8a4b1be GS |
3438 | /* This hack serves to disambiguate a pair of curlies |
3439 | * as being a block or an anon hash. Normally, expectation | |
3440 | * determines that, but in cases where we're not in a | |
3441 | * position to expect anything in particular (like inside | |
3442 | * eval"") we have to resolve the ambiguity. This code | |
3443 | * covers the case where the first term in the curlies is a | |
3444 | * quoted string. Most other cases need to be explicitly | |
a0288114 | 3445 | * disambiguated by prepending a "+" before the opening |
b8a4b1be GS |
3446 | * curly in order to force resolution as an anon hash. |
3447 | * | |
3448 | * XXX should probably propagate the outer expectation | |
3449 | * into eval"" to rely less on this hack, but that could | |
3450 | * potentially break current behavior of eval"". | |
3451 | * GSAR 97-07-21 | |
3452 | */ | |
3453 | t = s; | |
3454 | if (*s == '\'' || *s == '"' || *s == '`') { | |
3455 | /* common case: get past first string, handling escapes */ | |
3280af22 | 3456 | for (t++; t < PL_bufend && *t != *s;) |
b8a4b1be GS |
3457 | if (*t++ == '\\' && (*t == '\\' || *t == *s)) |
3458 | t++; | |
3459 | t++; | |
a0d0e21e | 3460 | } |
b8a4b1be | 3461 | else if (*s == 'q') { |
3280af22 | 3462 | if (++t < PL_bufend |
b8a4b1be | 3463 | && (!isALNUM(*t) |
3280af22 | 3464 | || ((*t == 'q' || *t == 'x') && ++t < PL_bufend |
0505442f GS |
3465 | && !isALNUM(*t)))) |
3466 | { | |
abc667d1 | 3467 | /* skip q//-like construct */ |
f54cb97a | 3468 | const char *tmps; |
b8a4b1be GS |
3469 | char open, close, term; |
3470 | I32 brackets = 1; | |
3471 | ||
3280af22 | 3472 | while (t < PL_bufend && isSPACE(*t)) |
b8a4b1be | 3473 | t++; |
abc667d1 DM |
3474 | /* check for q => */ |
3475 | if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') { | |
3476 | OPERATOR(HASHBRACK); | |
3477 | } | |
b8a4b1be GS |
3478 | term = *t; |
3479 | open = term; | |
3480 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) | |
3481 | term = tmps[5]; | |
3482 | close = term; | |
3483 | if (open == close) | |
3280af22 NIS |
3484 | for (t++; t < PL_bufend; t++) { |
3485 | if (*t == '\\' && t+1 < PL_bufend && open != '\\') | |
b8a4b1be | 3486 | t++; |
6d07e5e9 | 3487 | else if (*t == open) |
b8a4b1be GS |
3488 | break; |
3489 | } | |
abc667d1 | 3490 | else { |
3280af22 NIS |
3491 | for (t++; t < PL_bufend; t++) { |
3492 | if (*t == '\\' && t+1 < PL_bufend) | |
b8a4b1be | 3493 | t++; |
6d07e5e9 | 3494 | else if (*t == close && --brackets <= 0) |
b8a4b1be GS |
3495 | break; |
3496 | else if (*t == open) | |
3497 | brackets++; | |
3498 | } | |
abc667d1 DM |
3499 | } |
3500 | t++; | |
b8a4b1be | 3501 | } |
abc667d1 DM |
3502 | else |
3503 | /* skip plain q word */ | |
3504 | while (t < PL_bufend && isALNUM_lazy_if(t,UTF)) | |
3505 | t += UTF8SKIP(t); | |
a0d0e21e | 3506 | } |
7e2040f0 | 3507 | else if (isALNUM_lazy_if(t,UTF)) { |
0505442f | 3508 | t += UTF8SKIP(t); |
7e2040f0 | 3509 | while (t < PL_bufend && isALNUM_lazy_if(t,UTF)) |
0505442f | 3510 | t += UTF8SKIP(t); |
a0d0e21e | 3511 | } |
3280af22 | 3512 | while (t < PL_bufend && isSPACE(*t)) |
a0d0e21e | 3513 | t++; |
b8a4b1be GS |
3514 | /* if comma follows first term, call it an anon hash */ |
3515 | /* XXX it could be a comma expression with loop modifiers */ | |
3280af22 | 3516 | if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s))) |
b8a4b1be | 3517 | || (*t == '=' && t[1] == '>'))) |
a0d0e21e | 3518 | OPERATOR(HASHBRACK); |
3280af22 | 3519 | if (PL_expect == XREF) |
4e4e412b | 3520 | PL_expect = XTERM; |
a0d0e21e | 3521 | else { |
3280af22 NIS |
3522 | PL_lex_brackstack[PL_lex_brackets-1] = XSTATE; |
3523 | PL_expect = XSTATE; | |
a0d0e21e | 3524 | } |
8990e307 | 3525 | } |
a0d0e21e | 3526 | break; |
463ee0b2 | 3527 | } |
57843af0 | 3528 | yylval.ival = CopLINE(PL_curcop); |
79072805 | 3529 | if (isSPACE(*s) || *s == '#') |
3280af22 | 3530 | PL_copline = NOLINE; /* invalidate current command line number */ |
79072805 | 3531 | TOKEN('{'); |
378cc40b | 3532 | case '}': |
79072805 LW |
3533 | rightbracket: |
3534 | s++; | |
3280af22 | 3535 | if (PL_lex_brackets <= 0) |
d98d5fff | 3536 | yyerror("Unmatched right curly bracket"); |
463ee0b2 | 3537 | else |
3280af22 | 3538 | PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets]; |
c2e66d9e | 3539 | if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL) |
3280af22 NIS |
3540 | PL_lex_formbrack = 0; |
3541 | if (PL_lex_state == LEX_INTERPNORMAL) { | |
3542 | if (PL_lex_brackets == 0) { | |
9059aa12 LW |
3543 | if (PL_expect & XFAKEBRACK) { |
3544 | PL_expect &= XENUMMASK; | |
3280af22 NIS |
3545 | PL_lex_state = LEX_INTERPEND; |
3546 | PL_bufptr = s; | |
cea2e8a9 | 3547 | return yylex(); /* ignore fake brackets */ |
79072805 | 3548 | } |
fa83b5b6 | 3549 | if (*s == '-' && s[1] == '>') |
3280af22 | 3550 | PL_lex_state = LEX_INTERPENDMAYBE; |
fa83b5b6 | 3551 | else if (*s != '[' && *s != '{') |
3280af22 | 3552 | PL_lex_state = LEX_INTERPEND; |
79072805 LW |
3553 | } |
3554 | } | |
9059aa12 LW |
3555 | if (PL_expect & XFAKEBRACK) { |
3556 | PL_expect &= XENUMMASK; | |
3280af22 | 3557 | PL_bufptr = s; |
cea2e8a9 | 3558 | return yylex(); /* ignore fake brackets */ |
748a9306 | 3559 | } |
79072805 LW |
3560 | force_next('}'); |
3561 | TOKEN(';'); | |
378cc40b LW |
3562 | case '&': |
3563 | s++; | |
3564 | tmp = *s++; | |
3565 | if (tmp == '&') | |
a0d0e21e | 3566 | AOPERATOR(ANDAND); |
378cc40b | 3567 | s--; |
3280af22 | 3568 | if (PL_expect == XOPERATOR) { |
041457d9 DM |
3569 | if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON) |
3570 | && isIDFIRST_lazy_if(s,UTF)) | |
7e2040f0 | 3571 | { |
57843af0 | 3572 | CopLINE_dec(PL_curcop); |
9014280d | 3573 | Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi); |
57843af0 | 3574 | CopLINE_inc(PL_curcop); |
463ee0b2 | 3575 | } |
79072805 | 3576 | BAop(OP_BIT_AND); |
463ee0b2 | 3577 | } |
79072805 | 3578 | |
3280af22 NIS |
3579 | s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); |
3580 | if (*PL_tokenbuf) { | |
3581 | PL_expect = XOPERATOR; | |
3582 | force_ident(PL_tokenbuf, '&'); | |
463ee0b2 | 3583 | } |
79072805 LW |
3584 | else |
3585 | PREREF('&'); | |
c07a80fd | 3586 | yylval.ival = (OPpENTERSUB_AMPER<<8); |
79072805 LW |
3587 | TERM('&'); |
3588 | ||
378cc40b LW |
3589 | case '|': |
3590 | s++; | |
3591 | tmp = *s++; | |
3592 | if (tmp == '|') | |
a0d0e21e | 3593 | AOPERATOR(OROR); |
378cc40b | 3594 | s--; |
79072805 | 3595 | BOop(OP_BIT_OR); |
378cc40b LW |
3596 | case '=': |
3597 | s++; | |
3598 | tmp = *s++; | |
3599 | if (tmp == '=') | |
79072805 LW |
3600 | Eop(OP_EQ); |
3601 | if (tmp == '>') | |
3602 | OPERATOR(','); | |
378cc40b | 3603 | if (tmp == '~') |
79072805 | 3604 | PMop(OP_MATCH); |
ce44635a | 3605 | if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX) && strchr("+-*/%.^&|<",tmp)) |
9014280d | 3606 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Reversed %c= operator",(int)tmp); |
378cc40b | 3607 | s--; |
3280af22 NIS |
3608 | if (PL_expect == XSTATE && isALPHA(tmp) && |
3609 | (s == PL_linestart+1 || s[-2] == '\n') ) | |
748a9306 | 3610 | { |
3280af22 NIS |
3611 | if (PL_in_eval && !PL_rsfp) { |
3612 | d = PL_bufend; | |
a5f75d66 AD |
3613 | while (s < d) { |
3614 | if (*s++ == '\n') { | |
3615 | incline(s); | |
3616 | if (strnEQ(s,"=cut",4)) { | |
3617 | s = strchr(s,'\n'); | |
3618 | if (s) | |
3619 | s++; | |
3620 | else | |
3621 | s = d; | |
3622 | incline(s); | |
3623 | goto retry; | |
3624 | } | |
3625 | } | |
3626 | } | |
3627 | goto retry; | |
3628 | } | |
3280af22 NIS |
3629 | s = PL_bufend; |
3630 | PL_doextract = TRUE; | |
a0d0e21e LW |
3631 | goto retry; |
3632 | } | |
3280af22 | 3633 | if (PL_lex_brackets < PL_lex_formbrack) { |
f54cb97a | 3634 | const char *t; |
51882d45 | 3635 | #ifdef PERL_STRICT_CR |
bf4acbe4 | 3636 | for (t = s; SPACE_OR_TAB(*t); t++) ; |
51882d45 | 3637 | #else |
bf4acbe4 | 3638 | for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ; |
51882d45 | 3639 | #endif |
a0d0e21e LW |
3640 | if (*t == '\n' || *t == '#') { |
3641 | s--; | |
3280af22 | 3642 | PL_expect = XBLOCK; |
a0d0e21e LW |
3643 | goto leftbracket; |
3644 | } | |
79072805 | 3645 | } |
a0d0e21e LW |
3646 | yylval.ival = 0; |
3647 | OPERATOR(ASSIGNOP); | |
378cc40b LW |
3648 | case '!': |
3649 | s++; | |
3650 | tmp = *s++; | |
984200d0 | 3651 | if (tmp == '=') { |
decca21c YST |
3652 | /* was this !=~ where !~ was meant? |
3653 | * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */ | |
3654 | ||
984200d0 | 3655 | if (*s == '~' && ckWARN(WARN_SYNTAX)) { |
f54cb97a | 3656 | const char *t = s+1; |
984200d0 YST |
3657 | |
3658 | while (t < PL_bufend && isSPACE(*t)) | |
3659 | ++t; | |
3660 | ||
decca21c YST |
3661 | if (*t == '/' || *t == '?' || |
3662 | ((*t == 'm' || *t == 's' || *t == 'y') && !isALNUM(t[1])) || | |
3663 | (*t == 't' && t[1] == 'r' && !isALNUM(t[2]))) | |
984200d0 YST |
3664 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
3665 | "!=~ should be !~"); | |
3666 | } | |
79072805 | 3667 | Eop(OP_NE); |
984200d0 | 3668 | } |
378cc40b | 3669 | if (tmp == '~') |
79072805 | 3670 | PMop(OP_NOT); |
378cc40b LW |
3671 | s--; |
3672 | OPERATOR('!'); | |
3673 | case '<': | |
3280af22 | 3674 | if (PL_expect != XOPERATOR) { |
93a17b20 | 3675 | if (s[1] != '<' && !strchr(s,'>')) |
2f3197b3 | 3676 | check_uni(); |
79072805 LW |
3677 | if (s[1] == '<') |
3678 | s = scan_heredoc(s); | |
3679 | else | |
3680 | s = scan_inputsymbol(s); | |
3681 | TERM(sublex_start()); | |
378cc40b LW |
3682 | } |
3683 | s++; | |
3684 | tmp = *s++; | |
3685 | if (tmp == '<') | |
79072805 | 3686 | SHop(OP_LEFT_SHIFT); |
395c3793 LW |
3687 | if (tmp == '=') { |
3688 | tmp = *s++; | |
3689 | if (tmp == '>') | |
79072805 | 3690 | Eop(OP_NCMP); |
395c3793 | 3691 | s--; |
79072805 | 3692 | Rop(OP_LE); |
395c3793 | 3693 | } |
378cc40b | 3694 | s--; |
79072805 | 3695 | Rop(OP_LT); |
378cc40b LW |
3696 | case '>': |
3697 | s++; | |
3698 | tmp = *s++; | |
3699 | if (tmp == '>') | |
79072805 | 3700 | SHop(OP_RIGHT_SHIFT); |
378cc40b | 3701 | if (tmp == '=') |
79072805 | 3702 | Rop(OP_GE); |
378cc40b | 3703 | s--; |
79072805 | 3704 | Rop(OP_GT); |
378cc40b LW |
3705 | |
3706 | case '$': | |
bbce6d69 | 3707 | CLINE; |
3708 | ||
3280af22 NIS |
3709 | if (PL_expect == XOPERATOR) { |
3710 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3711 | PL_expect = XTERM; | |
a0d0e21e | 3712 | depcom(); |
bbf60fe6 | 3713 | return REPORT(','); /* grandfather non-comma-format format */ |
a0d0e21e | 3714 | } |
8990e307 | 3715 | } |
a0d0e21e | 3716 | |
7e2040f0 | 3717 | if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) { |
3280af22 | 3718 | PL_tokenbuf[0] = '@'; |
376b8730 SM |
3719 | s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1, |
3720 | sizeof PL_tokenbuf - 1, FALSE); | |
3721 | if (PL_expect == XOPERATOR) | |
3722 | no_op("Array length", s); | |
3280af22 | 3723 | if (!PL_tokenbuf[1]) |
a0d0e21e | 3724 | PREREF(DOLSHARP); |
3280af22 NIS |
3725 | PL_expect = XOPERATOR; |
3726 | PL_pending_ident = '#'; | |
463ee0b2 | 3727 | TOKEN(DOLSHARP); |
79072805 | 3728 | } |
bbce6d69 | 3729 | |
3280af22 | 3730 | PL_tokenbuf[0] = '$'; |
376b8730 SM |
3731 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, |
3732 | sizeof PL_tokenbuf - 1, FALSE); | |
3733 | if (PL_expect == XOPERATOR) | |
3734 | no_op("Scalar", s); | |
3280af22 NIS |
3735 | if (!PL_tokenbuf[1]) { |
3736 | if (s == PL_bufend) | |
bbce6d69 | 3737 | yyerror("Final $ should be \\$ or $name"); |
3738 | PREREF('$'); | |
8990e307 | 3739 | } |
a0d0e21e | 3740 | |
bbce6d69 | 3741 | /* This kludge not intended to be bulletproof. */ |
3280af22 | 3742 | if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) { |
bbce6d69 | 3743 | yylval.opval = newSVOP(OP_CONST, 0, |
b448e4fe | 3744 | newSViv(PL_compiling.cop_arybase)); |
bbce6d69 | 3745 | yylval.opval->op_private = OPpCONST_ARYBASE; |
3746 | TERM(THING); | |
3747 | } | |
3748 | ||
ff68c719 | 3749 | d = s; |
69d2bceb | 3750 | tmp = (I32)*s; |
3280af22 | 3751 | if (PL_lex_state == LEX_NORMAL) |
ff68c719 | 3752 | s = skipspace(s); |
3753 | ||
3280af22 | 3754 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) { |
bbce6d69 | 3755 | if (*s == '[') { |
3280af22 | 3756 | PL_tokenbuf[0] = '@'; |
599cee73 | 3757 | if (ckWARN(WARN_SYNTAX)) { |
b64e5050 | 3758 | char *t; |
bbce6d69 | 3759 | for(t = s + 1; |
7e2040f0 | 3760 | isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$'; |
bbce6d69 | 3761 | t++) ; |
a0d0e21e | 3762 | if (*t++ == ',') { |
3280af22 NIS |
3763 | PL_bufptr = skipspace(PL_bufptr); |
3764 | while (t < PL_bufend && *t != ']') | |
bbce6d69 | 3765 | t++; |
9014280d | 3766 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
599cee73 PM |
3767 | "Multidimensional syntax %.*s not supported", |
3768 | (t - PL_bufptr) + 1, PL_bufptr); | |
a0d0e21e LW |
3769 | } |
3770 | } | |
bbce6d69 | 3771 | } |
3772 | else if (*s == '{') { | |
b64e5050 | 3773 | char *t; |
3280af22 | 3774 | PL_tokenbuf[0] = '%'; |
ce44635a DM |
3775 | if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX) |
3776 | && (t = strchr(s, '}')) && (t = strchr(t, '='))) | |
bbce6d69 | 3777 | { |
3280af22 | 3778 | char tmpbuf[sizeof PL_tokenbuf]; |
a0d0e21e | 3779 | for (t++; isSPACE(*t); t++) ; |
7e2040f0 | 3780 | if (isIDFIRST_lazy_if(t,UTF)) { |
f54cb97a | 3781 | STRLEN len; |
8903cb82 | 3782 | t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len); |
59a6d928 | 3783 | for (; isSPACE(*t); t++) ; |
864dbfa3 | 3784 | if (*t == ';' && get_cv(tmpbuf, FALSE)) |
9014280d | 3785 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
599cee73 | 3786 | "You need to quote \"%s\"", tmpbuf); |
748a9306 | 3787 | } |
93a17b20 LW |
3788 | } |
3789 | } | |
2f3197b3 | 3790 | } |
bbce6d69 | 3791 | |
3280af22 | 3792 | PL_expect = XOPERATOR; |
69d2bceb | 3793 | if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) { |
f54cb97a | 3794 | const bool islop = (PL_last_lop == PL_oldoldbufptr); |
3280af22 NIS |
3795 | if (!islop || PL_last_lop_op == OP_GREPSTART) |
3796 | PL_expect = XOPERATOR; | |
bbce6d69 | 3797 | else if (strchr("$@\"'`q", *s)) |
3280af22 | 3798 | PL_expect = XTERM; /* e.g. print $fh "foo" */ |
7e2040f0 | 3799 | else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF)) |
3280af22 | 3800 | PL_expect = XTERM; /* e.g. print $fh &sub */ |
7e2040f0 | 3801 | else if (isIDFIRST_lazy_if(s,UTF)) { |
3280af22 | 3802 | char tmpbuf[sizeof PL_tokenbuf]; |
8903cb82 | 3803 | scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
155aba94 | 3804 | if ((tmp = keyword(tmpbuf, len))) { |
84902520 TB |
3805 | /* binary operators exclude handle interpretations */ |
3806 | switch (tmp) { | |
3807 | case -KEY_x: | |
3808 | case -KEY_eq: | |
3809 | case -KEY_ne: | |
3810 | case -KEY_gt: | |
3811 | case -KEY_lt: | |
3812 | case -KEY_ge: | |
3813 | case -KEY_le: | |
3814 | case -KEY_cmp: | |
3815 | break; | |
3816 | default: | |
3280af22 | 3817 | PL_expect = XTERM; /* e.g. print $fh length() */ |
84902520 TB |
3818 | break; |
3819 | } | |
3820 | } | |
68dc0745 | 3821 | else { |
8a8635f0 | 3822 | PL_expect = XTERM; /* e.g. print $fh subr() */ |
93a17b20 | 3823 | } |
93a17b20 | 3824 | } |
bbce6d69 | 3825 | else if (isDIGIT(*s)) |
3280af22 | 3826 | PL_expect = XTERM; /* e.g. print $fh 3 */ |
bbce6d69 | 3827 | else if (*s == '.' && isDIGIT(s[1])) |
3280af22 | 3828 | PL_expect = XTERM; /* e.g. print $fh .3 */ |
3792a11b NC |
3829 | else if ((*s == '?' || *s == '-' || *s == '+') |
3830 | && !isSPACE(s[1]) && s[1] != '=') | |
c963b151 | 3831 | PL_expect = XTERM; /* e.g. print $fh -1 */ |
7ce6e6b9 RGS |
3832 | else if (*s == '/' && !isSPACE(s[1]) && s[1] != '=' && s[1] != '/') |
3833 | PL_expect = XTERM; /* e.g. print $fh /.../ | |
3834 | XXX except DORDOR operator */ | |
e0587a03 | 3835 | else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=') |
3280af22 | 3836 | PL_expect = XTERM; /* print $fh <<"EOF" */ |
bbce6d69 | 3837 | } |
3280af22 | 3838 | PL_pending_ident = '$'; |
79072805 | 3839 | TOKEN('$'); |
378cc40b LW |
3840 | |
3841 | case '@': | |
3280af22 | 3842 | if (PL_expect == XOPERATOR) |
bbce6d69 | 3843 | no_op("Array", s); |
3280af22 NIS |
3844 | PL_tokenbuf[0] = '@'; |
3845 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE); | |
3846 | if (!PL_tokenbuf[1]) { | |
bbce6d69 | 3847 | PREREF('@'); |
3848 | } | |
3280af22 | 3849 | if (PL_lex_state == LEX_NORMAL) |
ff68c719 | 3850 | s = skipspace(s); |
3280af22 | 3851 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) { |
bbce6d69 | 3852 | if (*s == '{') |
3280af22 | 3853 | PL_tokenbuf[0] = '%'; |
a0d0e21e LW |
3854 | |
3855 | /* Warn about @ where they meant $. */ | |
041457d9 DM |
3856 | if (*s == '[' || *s == '{') { |
3857 | if (ckWARN(WARN_SYNTAX)) { | |
f54cb97a | 3858 | const char *t = s + 1; |
7e2040f0 | 3859 | while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t))) |
a0d0e21e LW |
3860 | t++; |
3861 | if (*t == '}' || *t == ']') { | |
3862 | t++; | |
3280af22 | 3863 | PL_bufptr = skipspace(PL_bufptr); |
9014280d | 3864 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
599cee73 | 3865 | "Scalar value %.*s better written as $%.*s", |
3280af22 | 3866 | t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1); |
a0d0e21e | 3867 | } |
93a17b20 LW |
3868 | } |
3869 | } | |
463ee0b2 | 3870 | } |
3280af22 | 3871 | PL_pending_ident = '@'; |
79072805 | 3872 | TERM('@'); |
378cc40b | 3873 | |
c963b151 | 3874 | case '/': /* may be division, defined-or, or pattern */ |
6f33ba73 RGS |
3875 | if (PL_expect == XTERMORDORDOR && s[1] == '/') { |
3876 | s += 2; | |
3877 | AOPERATOR(DORDOR); | |
3878 | } | |
c963b151 BD |
3879 | case '?': /* may either be conditional or pattern */ |
3880 | if(PL_expect == XOPERATOR) { | |
3881 | tmp = *s++; | |
3882 | if(tmp == '?') { | |
3883 | OPERATOR('?'); | |
3884 | } | |
3885 | else { | |
3886 | tmp = *s++; | |
3887 | if(tmp == '/') { | |
3888 | /* A // operator. */ | |
3889 | AOPERATOR(DORDOR); | |
3890 | } | |
3891 | else { | |
3892 | s--; | |
3893 | Mop(OP_DIVIDE); | |
3894 | } | |
3895 | } | |
3896 | } | |
3897 | else { | |
3898 | /* Disable warning on "study /blah/" */ | |
3899 | if (PL_oldoldbufptr == PL_last_uni | |
3900 | && (*PL_last_uni != 's' || s - PL_last_uni < 5 | |
3901 | || memNE(PL_last_uni, "study", 5) | |
3902 | || isALNUM_lazy_if(PL_last_uni+5,UTF) | |
3903 | )) | |
3904 | check_uni(); | |
3905 | s = scan_pat(s,OP_MATCH); | |
3906 | TERM(sublex_start()); | |
3907 | } | |
378cc40b LW |
3908 | |
3909 | case '.': | |
51882d45 GS |
3910 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack |
3911 | #ifdef PERL_STRICT_CR | |
3912 | && s[1] == '\n' | |
3913 | #else | |
3914 | && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n')) | |
3915 | #endif | |
3916 | && (s == PL_linestart || s[-1] == '\n') ) | |
3917 | { | |
3280af22 NIS |
3918 | PL_lex_formbrack = 0; |
3919 | PL_expect = XSTATE; | |
79072805 LW |
3920 | goto rightbracket; |
3921 | } | |
3280af22 | 3922 | if (PL_expect == XOPERATOR || !isDIGIT(s[1])) { |
378cc40b | 3923 | tmp = *s++; |
a687059c LW |
3924 | if (*s == tmp) { |
3925 | s++; | |
2f3197b3 LW |
3926 | if (*s == tmp) { |
3927 | s++; | |
79072805 | 3928 | yylval.ival = OPf_SPECIAL; |
2f3197b3 LW |
3929 | } |
3930 | else | |
79072805 | 3931 | yylval.ival = 0; |
378cc40b | 3932 | OPERATOR(DOTDOT); |
a687059c | 3933 | } |
3280af22 | 3934 | if (PL_expect != XOPERATOR) |
2f3197b3 | 3935 | check_uni(); |
79072805 | 3936 | Aop(OP_CONCAT); |
378cc40b LW |
3937 | } |
3938 | /* FALL THROUGH */ | |
3939 | case '0': case '1': case '2': case '3': case '4': | |
3940 | case '5': case '6': case '7': case '8': case '9': | |
b73d6f50 | 3941 | s = scan_num(s, &yylval); |
b6007c36 | 3942 | DEBUG_T( { S_printbuf(aTHX_ "### Saw number in %s\n", s); } ); |
3280af22 | 3943 | if (PL_expect == XOPERATOR) |
8990e307 | 3944 | no_op("Number",s); |
79072805 LW |
3945 | TERM(THING); |
3946 | ||
3947 | case '\'': | |
09bef843 | 3948 | s = scan_str(s,FALSE,FALSE); |
b6007c36 | 3949 | DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } ); |
3280af22 NIS |
3950 | if (PL_expect == XOPERATOR) { |
3951 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3952 | PL_expect = XTERM; | |
a0d0e21e | 3953 | depcom(); |
bbf60fe6 | 3954 | return REPORT(','); /* grandfather non-comma-format format */ |
a0d0e21e | 3955 | } |
463ee0b2 | 3956 | else |
8990e307 | 3957 | no_op("String",s); |
463ee0b2 | 3958 | } |
79072805 | 3959 | if (!s) |
85e6fe83 | 3960 | missingterm((char*)0); |
79072805 LW |
3961 | yylval.ival = OP_CONST; |
3962 | TERM(sublex_start()); | |
3963 | ||
3964 | case '"': | |
09bef843 | 3965 | s = scan_str(s,FALSE,FALSE); |
b6007c36 | 3966 | DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } ); |
3280af22 NIS |
3967 | if (PL_expect == XOPERATOR) { |
3968 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3969 | PL_expect = XTERM; | |
a0d0e21e | 3970 | depcom(); |
bbf60fe6 | 3971 | return REPORT(','); /* grandfather non-comma-format format */ |
a0d0e21e | 3972 | } |
463ee0b2 | 3973 | else |
8990e307 | 3974 | no_op("String",s); |
463ee0b2 | 3975 | } |
79072805 | 3976 | if (!s) |
85e6fe83 | 3977 | missingterm((char*)0); |
4633a7c4 | 3978 | yylval.ival = OP_CONST; |
cfd0369c NC |
3979 | /* FIXME. I think that this can be const if char *d is replaced by |
3980 | more localised variables. */ | |
3280af22 | 3981 | for (d = SvPV(PL_lex_stuff, len); len; len--, d++) { |
63cd0674 | 3982 | if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) { |
4633a7c4 LW |
3983 | yylval.ival = OP_STRINGIFY; |
3984 | break; | |
3985 | } | |
3986 | } | |
79072805 LW |
3987 | TERM(sublex_start()); |
3988 | ||
3989 | case '`': | |
09bef843 | 3990 | s = scan_str(s,FALSE,FALSE); |
b6007c36 | 3991 | DEBUG_T( { S_printbuf(aTHX_ "### Saw backtick string before %s\n", s); } ); |
3280af22 | 3992 | if (PL_expect == XOPERATOR) |
8990e307 | 3993 | no_op("Backticks",s); |
79072805 | 3994 | if (!s) |
85e6fe83 | 3995 | missingterm((char*)0); |
79072805 LW |
3996 | yylval.ival = OP_BACKTICK; |
3997 | set_csh(); | |
3998 | TERM(sublex_start()); | |
3999 | ||
4000 | case '\\': | |
4001 | s++; | |
041457d9 | 4002 | if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX)) |
9014280d | 4003 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression", |
599cee73 | 4004 | *s, *s); |
3280af22 | 4005 | if (PL_expect == XOPERATOR) |
8990e307 | 4006 | no_op("Backslash",s); |
79072805 LW |
4007 | OPERATOR(REFGEN); |
4008 | ||
a7cb1f99 | 4009 | case 'v': |
e526c9e6 | 4010 | if (isDIGIT(s[1]) && PL_expect != XOPERATOR) { |
f54cb97a | 4011 | char *start = s + 2; |
dd629d5b | 4012 | while (isDIGIT(*start) || *start == '_') |
a7cb1f99 GS |
4013 | start++; |
4014 | if (*start == '.' && isDIGIT(start[1])) { | |
b73d6f50 | 4015 | s = scan_num(s, &yylval); |
a7cb1f99 GS |
4016 | TERM(THING); |
4017 | } | |
e526c9e6 | 4018 | /* avoid v123abc() or $h{v1}, allow C<print v10;> */ |
6f33ba73 RGS |
4019 | else if (!isALPHA(*start) && (PL_expect == XTERM |
4020 | || PL_expect == XREF || PL_expect == XSTATE | |
4021 | || PL_expect == XTERMORDORDOR)) { | |
f54cb97a | 4022 | const char c = *start; |
e526c9e6 GS |
4023 | GV *gv; |
4024 | *start = '\0'; | |
4025 | gv = gv_fetchpv(s, FALSE, SVt_PVCV); | |
4026 | *start = c; | |
4027 | if (!gv) { | |
b73d6f50 | 4028 | s = scan_num(s, &yylval); |
e526c9e6 GS |
4029 | TERM(THING); |
4030 | } | |
4031 | } | |
a7cb1f99 GS |
4032 | } |
4033 | goto keylookup; | |
79072805 | 4034 | case 'x': |
3280af22 | 4035 | if (isDIGIT(s[1]) && PL_expect == XOPERATOR) { |
79072805 LW |
4036 | s++; |
4037 | Mop(OP_REPEAT); | |
2f3197b3 | 4038 | } |
79072805 LW |
4039 | goto keylookup; |
4040 | ||
378cc40b | 4041 | case '_': |
79072805 LW |
4042 | case 'a': case 'A': |
4043 | case 'b': case 'B': | |
4044 | case 'c': case 'C': | |
4045 | case 'd': case 'D': | |
4046 | case 'e': case 'E': | |
4047 | case 'f': case 'F': | |
4048 | case 'g': case 'G': | |
4049 | case 'h': case 'H': | |
4050 | case 'i': case 'I': | |
4051 | case 'j': case 'J': | |
4052 | case 'k': case 'K': | |
4053 | case 'l': case 'L': | |
4054 | case 'm': case 'M': | |
4055 | case 'n': case 'N': | |
4056 | case 'o': case 'O': | |
4057 | case 'p': case 'P': | |
4058 | case 'q': case 'Q': | |
4059 | case 'r': case 'R': | |
4060 | case 's': case 'S': | |
4061 | case 't': case 'T': | |
4062 | case 'u': case 'U': | |
a7cb1f99 | 4063 | case 'V': |
79072805 LW |
4064 | case 'w': case 'W': |
4065 | case 'X': | |
4066 | case 'y': case 'Y': | |
4067 | case 'z': case 'Z': | |
4068 | ||
49dc05e3 | 4069 | keylookup: { |
1d239bbb | 4070 | orig_keyword = 0; |
161b471a NIS |
4071 | gv = Nullgv; |
4072 | gvp = 0; | |
49dc05e3 | 4073 | |
3280af22 NIS |
4074 | PL_bufptr = s; |
4075 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); | |
8ebc5c01 | 4076 | |
4077 | /* Some keywords can be followed by any delimiter, including ':' */ | |
155aba94 GS |
4078 | tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) || |
4079 | (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') || | |
4080 | (PL_tokenbuf[0] == 'q' && | |
4081 | strchr("qwxr", PL_tokenbuf[1]))))); | |
8ebc5c01 | 4082 | |
4083 | /* x::* is just a word, unless x is "CORE" */ | |
3280af22 | 4084 | if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE")) |
4633a7c4 LW |
4085 | goto just_a_word; |
4086 | ||
3643fb5f | 4087 | d = s; |
3280af22 | 4088 | while (d < PL_bufend && isSPACE(*d)) |
3643fb5f CS |
4089 | d++; /* no comments skipped here, or s### is misparsed */ |
4090 | ||
4091 | /* Is this a label? */ | |
3280af22 NIS |
4092 | if (!tmp && PL_expect == XSTATE |
4093 | && d < PL_bufend && *d == ':' && *(d + 1) != ':') { | |
8ebc5c01 | 4094 | s = d + 1; |
3280af22 | 4095 | yylval.pval = savepv(PL_tokenbuf); |
8ebc5c01 | 4096 | CLINE; |
4097 | TOKEN(LABEL); | |
3643fb5f CS |
4098 | } |
4099 | ||
4100 | /* Check for keywords */ | |
3280af22 | 4101 | tmp = keyword(PL_tokenbuf, len); |
748a9306 LW |
4102 | |
4103 | /* Is this a word before a => operator? */ | |
1c3923b3 | 4104 | if (*d == '=' && d[1] == '>') { |
748a9306 | 4105 | CLINE; |
d0a148a6 NC |
4106 | yylval.opval |
4107 | = (OP*)newSVOP(OP_CONST, 0, | |
4108 | S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len)); | |
748a9306 LW |
4109 | yylval.opval->op_private = OPpCONST_BARE; |
4110 | TERM(WORD); | |
4111 | } | |
4112 | ||
a0d0e21e | 4113 | if (tmp < 0) { /* second-class keyword? */ |
56f7f34b CS |
4114 | GV *ogv = Nullgv; /* override (winner) */ |
4115 | GV *hgv = Nullgv; /* hidden (loser) */ | |
3280af22 | 4116 | if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) { |
56f7f34b | 4117 | CV *cv; |
3280af22 | 4118 | if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) && |
56f7f34b CS |
4119 | (cv = GvCVu(gv))) |
4120 | { | |
4121 | if (GvIMPORTED_CV(gv)) | |
4122 | ogv = gv; | |
4123 | else if (! CvMETHOD(cv)) | |
4124 | hgv = gv; | |
4125 | } | |
4126 | if (!ogv && | |
3280af22 NIS |
4127 | (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) && |
4128 | (gv = *gvp) != (GV*)&PL_sv_undef && | |
56f7f34b CS |
4129 | GvCVu(gv) && GvIMPORTED_CV(gv)) |
4130 | { | |
4131 | ogv = gv; | |
4132 | } | |
4133 | } | |
4134 | if (ogv) { | |
30fe34ed | 4135 | orig_keyword = tmp; |
56f7f34b | 4136 | tmp = 0; /* overridden by import or by GLOBAL */ |
6e7b2336 GS |
4137 | } |
4138 | else if (gv && !gvp | |
4139 | && -tmp==KEY_lock /* XXX generalizable kludge */ | |
d0456cad | 4140 | && GvCVu(gv) |
3280af22 | 4141 | && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE)) |
6e7b2336 GS |
4142 | { |
4143 | tmp = 0; /* any sub overrides "weak" keyword */ | |
a0d0e21e | 4144 | } |
7fc307b5 RGS |
4145 | else if (gv && !gvp |
4146 | && tmp == -KEY_err | |
4147 | && GvCVu(gv) | |
4148 | && PL_expect != XOPERATOR | |
4149 | && PL_expect != XTERMORDORDOR) | |
4150 | { | |
4151 | /* any sub overrides the "err" keyword, except when really an | |
4152 | * operator is expected */ | |
4153 | tmp = 0; | |
4154 | } | |
56f7f34b CS |
4155 | else { /* no override */ |
4156 | tmp = -tmp; | |
ac206dc8 | 4157 | if (tmp == KEY_dump && ckWARN(WARN_MISC)) { |
9014280d | 4158 | Perl_warner(aTHX_ packWARN(WARN_MISC), |
ac206dc8 RGS |
4159 | "dump() better written as CORE::dump()"); |
4160 | } | |
56f7f34b CS |
4161 | gv = Nullgv; |
4162 | gvp = 0; | |
041457d9 DM |
4163 | if (hgv && tmp != KEY_x && tmp != KEY_CORE |
4164 | && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */ | |
9014280d | 4165 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
599cee73 | 4166 | "Ambiguous call resolved as CORE::%s(), %s", |
2f3ca594 | 4167 | GvENAME(hgv), "qualify as such or use &"); |
49dc05e3 | 4168 | } |
a0d0e21e LW |
4169 | } |
4170 | ||
4171 | reserved_word: | |
4172 | switch (tmp) { | |
79072805 LW |
4173 | |
4174 | default: /* not a keyword */ | |
93a17b20 | 4175 | just_a_word: { |
96e4d5b1 | 4176 | SV *sv; |
ce29ac45 | 4177 | int pkgname = 0; |
f54cb97a | 4178 | const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]); |
8990e307 LW |
4179 | |
4180 | /* Get the rest if it looks like a package qualifier */ | |
4181 | ||
155aba94 | 4182 | if (*s == '\'' || (*s == ':' && s[1] == ':')) { |
c3e0f903 | 4183 | STRLEN morelen; |
3280af22 | 4184 | s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len, |
c3e0f903 GS |
4185 | TRUE, &morelen); |
4186 | if (!morelen) | |
cea2e8a9 | 4187 | Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf, |
ec2ab091 | 4188 | *s == '\'' ? "'" : "::"); |
c3e0f903 | 4189 | len += morelen; |
ce29ac45 | 4190 | pkgname = 1; |
a0d0e21e | 4191 | } |
8990e307 | 4192 | |
3280af22 NIS |
4193 | if (PL_expect == XOPERATOR) { |
4194 | if (PL_bufptr == PL_linestart) { | |
57843af0 | 4195 | CopLINE_dec(PL_curcop); |
9014280d | 4196 | Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi); |
57843af0 | 4197 | CopLINE_inc(PL_curcop); |
463ee0b2 LW |
4198 | } |
4199 | else | |
54310121 | 4200 | no_op("Bareword",s); |
463ee0b2 | 4201 | } |
8990e307 | 4202 | |
c3e0f903 GS |
4203 | /* Look for a subroutine with this name in current package, |
4204 | unless name is "Foo::", in which case Foo is a bearword | |
4205 | (and a package name). */ | |
4206 | ||
4207 | if (len > 2 && | |
3280af22 | 4208 | PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':') |
c3e0f903 | 4209 | { |
e476b1b5 | 4210 | if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV)) |
9014280d | 4211 | Perl_warner(aTHX_ packWARN(WARN_BAREWORD), |
599cee73 | 4212 | "Bareword \"%s\" refers to nonexistent package", |
3280af22 | 4213 | PL_tokenbuf); |
c3e0f903 | 4214 | len -= 2; |
3280af22 | 4215 | PL_tokenbuf[len] = '\0'; |
c3e0f903 GS |
4216 | gv = Nullgv; |
4217 | gvp = 0; | |
4218 | } | |
4219 | else { | |
4220 | len = 0; | |
4221 | if (!gv) | |
3280af22 | 4222 | gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV); |
c3e0f903 GS |
4223 | } |
4224 | ||
4225 | /* if we saw a global override before, get the right name */ | |
8990e307 | 4226 | |
49dc05e3 | 4227 | if (gvp) { |
79cb57f6 | 4228 | sv = newSVpvn("CORE::GLOBAL::",14); |
3280af22 | 4229 | sv_catpv(sv,PL_tokenbuf); |
49dc05e3 | 4230 | } |
8a7a129d NC |
4231 | else { |
4232 | /* If len is 0, newSVpv does strlen(), which is correct. | |
4233 | If len is non-zero, then it will be the true length, | |
4234 | and so the scalar will be created correctly. */ | |
4235 | sv = newSVpv(PL_tokenbuf,len); | |
4236 | } | |
8990e307 | 4237 | |
a0d0e21e LW |
4238 | /* Presume this is going to be a bareword of some sort. */ |
4239 | ||
4240 | CLINE; | |
49dc05e3 | 4241 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
a0d0e21e | 4242 | yylval.opval->op_private = OPpCONST_BARE; |
8f8cf39c JH |
4243 | /* UTF-8 package name? */ |
4244 | if (UTF && !IN_BYTES && | |
95a20fc0 | 4245 | is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv))) |
8f8cf39c | 4246 | SvUTF8_on(sv); |
a0d0e21e | 4247 | |
c3e0f903 GS |
4248 | /* And if "Foo::", then that's what it certainly is. */ |
4249 | ||
4250 | if (len) | |
4251 | goto safe_bareword; | |
4252 | ||
8990e307 LW |
4253 | /* See if it's the indirect object for a list operator. */ |
4254 | ||
3280af22 NIS |
4255 | if (PL_oldoldbufptr && |
4256 | PL_oldoldbufptr < PL_bufptr && | |
65cec589 GS |
4257 | (PL_oldoldbufptr == PL_last_lop |
4258 | || PL_oldoldbufptr == PL_last_uni) && | |
a0d0e21e | 4259 | /* NO SKIPSPACE BEFORE HERE! */ |
a9ef352a GS |
4260 | (PL_expect == XREF || |
4261 | ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF)) | |
a0d0e21e | 4262 | { |
748a9306 LW |
4263 | bool immediate_paren = *s == '('; |
4264 | ||
a0d0e21e LW |
4265 | /* (Now we can afford to cross potential line boundary.) */ |
4266 | s = skipspace(s); | |
4267 | ||
4268 | /* Two barewords in a row may indicate method call. */ | |
4269 | ||
7e2040f0 | 4270 | if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv))) |
bbf60fe6 | 4271 | return REPORT(tmp); |
a0d0e21e LW |
4272 | |
4273 | /* If not a declared subroutine, it's an indirect object. */ | |
4274 | /* (But it's an indir obj regardless for sort.) */ | |
7294df96 | 4275 | /* Also, if "_" follows a filetest operator, it's a bareword */ |
a0d0e21e | 4276 | |
7294df96 RGS |
4277 | if ( |
4278 | ( !immediate_paren && (PL_last_lop_op == OP_SORT || | |
f0670693 | 4279 | ((!gv || !GvCVu(gv)) && |
a9ef352a | 4280 | (PL_last_lop_op != OP_MAPSTART && |
f0670693 | 4281 | PL_last_lop_op != OP_GREPSTART)))) |
7294df96 RGS |
4282 | || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0' |
4283 | && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP)) | |
4284 | ) | |
a9ef352a | 4285 | { |
3280af22 | 4286 | PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR; |
748a9306 | 4287 | goto bareword; |
93a17b20 LW |
4288 | } |
4289 | } | |
8990e307 | 4290 | |
3280af22 | 4291 | PL_expect = XOPERATOR; |
8990e307 | 4292 | s = skipspace(s); |
1c3923b3 GS |
4293 | |
4294 | /* Is this a word before a => operator? */ | |
ce29ac45 | 4295 | if (*s == '=' && s[1] == '>' && !pkgname) { |
1c3923b3 GS |
4296 | CLINE; |
4297 | sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf); | |
0064a8a9 | 4298 | if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len)) |
7948272d | 4299 | SvUTF8_on(((SVOP*)yylval.opval)->op_sv); |
1c3923b3 GS |
4300 | TERM(WORD); |
4301 | } | |
4302 | ||
4303 | /* If followed by a paren, it's certainly a subroutine. */ | |
93a17b20 | 4304 | if (*s == '(') { |
79072805 | 4305 | CLINE; |
96e4d5b1 | 4306 | if (gv && GvCVu(gv)) { |
bf4acbe4 | 4307 | for (d = s + 1; SPACE_OR_TAB(*d); d++) ; |
7a52d87a | 4308 | if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) { |
96e4d5b1 | 4309 | s = d + 1; |
4310 | goto its_constant; | |
4311 | } | |
4312 | } | |
3280af22 NIS |
4313 | PL_nextval[PL_nexttoke].opval = yylval.opval; |
4314 | PL_expect = XOPERATOR; | |
93a17b20 | 4315 | force_next(WORD); |
c07a80fd | 4316 | yylval.ival = 0; |
463ee0b2 | 4317 | TOKEN('&'); |
79072805 | 4318 | } |
93a17b20 | 4319 | |
a0d0e21e | 4320 | /* If followed by var or block, call it a method (unless sub) */ |
8990e307 | 4321 | |
8ebc5c01 | 4322 | if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) { |
3280af22 NIS |
4323 | PL_last_lop = PL_oldbufptr; |
4324 | PL_last_lop_op = OP_METHOD; | |
93a17b20 | 4325 | PREBLOCK(METHOD); |
463ee0b2 LW |
4326 | } |
4327 | ||
8990e307 LW |
4328 | /* If followed by a bareword, see if it looks like indir obj. */ |
4329 | ||
30fe34ed RGS |
4330 | if (!orig_keyword |
4331 | && (isIDFIRST_lazy_if(s,UTF) || *s == '$') | |
4332 | && (tmp = intuit_method(s,gv))) | |
bbf60fe6 | 4333 | return REPORT(tmp); |
93a17b20 | 4334 | |
8990e307 LW |
4335 | /* Not a method, so call it a subroutine (if defined) */ |
4336 | ||
8ebc5c01 | 4337 | if (gv && GvCVu(gv)) { |
46fc3d4c | 4338 | CV* cv; |
0453d815 | 4339 | if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS)) |
9014280d | 4340 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
0453d815 | 4341 | "Ambiguous use of -%s resolved as -&%s()", |
3280af22 | 4342 | PL_tokenbuf, PL_tokenbuf); |
89bfa8cd | 4343 | /* Check for a constant sub */ |
46fc3d4c | 4344 | cv = GvCV(gv); |
96e4d5b1 | 4345 | if ((sv = cv_const_sv(cv))) { |
4346 | its_constant: | |
4347 | SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv); | |
4348 | ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv); | |
4349 | yylval.opval->op_private = 0; | |
4350 | TOKEN(WORD); | |
89bfa8cd | 4351 | } |
4352 | ||
a5f75d66 AD |
4353 | /* Resolve to GV now. */ |
4354 | op_free(yylval.opval); | |
4355 | yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv)); | |
9675f7ac | 4356 | yylval.opval->op_private |= OPpENTERSUB_NOPAREN; |
7a52d87a | 4357 | PL_last_lop = PL_oldbufptr; |
bf848113 | 4358 | PL_last_lop_op = OP_ENTERSUB; |
4633a7c4 LW |
4359 | /* Is there a prototype? */ |
4360 | if (SvPOK(cv)) { | |
4361 | STRLEN len; | |
cfd0369c | 4362 | const char *proto = SvPV_const((SV*)cv, len); |
4633a7c4 LW |
4363 | if (!len) |
4364 | TERM(FUNC0SUB); | |
770526c1 | 4365 | if (*proto == '$' && proto[1] == '\0') |
4633a7c4 | 4366 | OPERATOR(UNIOPSUB); |
0f5d0394 AE |
4367 | while (*proto == ';') |
4368 | proto++; | |
7a52d87a | 4369 | if (*proto == '&' && *s == '{') { |
bfed75c6 | 4370 | sv_setpv(PL_subname, PL_curstash ? |
c99da370 | 4371 | "__ANON__" : "__ANON__::__ANON__"); |
4633a7c4 LW |
4372 | PREBLOCK(LSTOPSUB); |
4373 | } | |
a9ef352a | 4374 | } |
3280af22 NIS |
4375 | PL_nextval[PL_nexttoke].opval = yylval.opval; |
4376 | PL_expect = XTERM; | |
8990e307 LW |
4377 | force_next(WORD); |
4378 | TOKEN(NOAMP); | |
4379 | } | |
748a9306 | 4380 | |
8990e307 LW |
4381 | /* Call it a bare word */ |
4382 | ||
5603f27d GS |
4383 | if (PL_hints & HINT_STRICT_SUBS) |
4384 | yylval.opval->op_private |= OPpCONST_STRICT; | |
4385 | else { | |
4386 | bareword: | |
041457d9 DM |
4387 | if (lastchar != '-') { |
4388 | if (ckWARN(WARN_RESERVED)) { | |
5603f27d | 4389 | for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ; |
238ae712 | 4390 | if (!*d && !gv_stashpv(PL_tokenbuf,FALSE)) |
9014280d | 4391 | Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved, |
5603f27d GS |
4392 | PL_tokenbuf); |
4393 | } | |
748a9306 LW |
4394 | } |
4395 | } | |
c3e0f903 GS |
4396 | |
4397 | safe_bareword: | |
3792a11b NC |
4398 | if ((lastchar == '*' || lastchar == '%' || lastchar == '&') |
4399 | && ckWARN_d(WARN_AMBIGUOUS)) { | |
9014280d | 4400 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
0453d815 | 4401 | "Operator or semicolon missing before %c%s", |
3280af22 | 4402 | lastchar, PL_tokenbuf); |
9014280d | 4403 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
0453d815 | 4404 | "Ambiguous use of %c resolved as operator %c", |
748a9306 LW |
4405 | lastchar, lastchar); |
4406 | } | |
93a17b20 | 4407 | TOKEN(WORD); |
79072805 | 4408 | } |
79072805 | 4409 | |
68dc0745 | 4410 | case KEY___FILE__: |
46fc3d4c | 4411 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
ed094faf | 4412 | newSVpv(CopFILE(PL_curcop),0)); |
46fc3d4c | 4413 | TERM(THING); |
4414 | ||
79072805 | 4415 | case KEY___LINE__: |
cf2093f6 | 4416 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
57843af0 | 4417 | Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop))); |
79072805 | 4418 | TERM(THING); |
68dc0745 | 4419 | |
4420 | case KEY___PACKAGE__: | |
4421 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, | |
3280af22 | 4422 | (PL_curstash |
5aaec2b4 | 4423 | ? newSVhek(HvNAME_HEK(PL_curstash)) |
3280af22 | 4424 | : &PL_sv_undef)); |
79072805 | 4425 | TERM(THING); |
79072805 | 4426 | |
e50aee73 | 4427 | case KEY___DATA__: |
79072805 LW |
4428 | case KEY___END__: { |
4429 | GV *gv; | |
3280af22 | 4430 | if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) { |
bfed75c6 | 4431 | const char *pname = "main"; |
3280af22 | 4432 | if (PL_tokenbuf[2] == 'D') |
bfcb3514 | 4433 | pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash); |
cea2e8a9 | 4434 | gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO); |
a5f75d66 | 4435 | GvMULTI_on(gv); |
79072805 | 4436 | if (!GvIO(gv)) |
a0d0e21e | 4437 | GvIOp(gv) = newIO(); |
3280af22 | 4438 | IoIFP(GvIOp(gv)) = PL_rsfp; |
a0d0e21e LW |
4439 | #if defined(HAS_FCNTL) && defined(F_SETFD) |
4440 | { | |
f54cb97a | 4441 | const int fd = PerlIO_fileno(PL_rsfp); |
a0d0e21e LW |
4442 | fcntl(fd,F_SETFD,fd >= 3); |
4443 | } | |
79072805 | 4444 | #endif |
fd049845 | 4445 | /* Mark this internal pseudo-handle as clean */ |
4446 | IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT; | |
3280af22 | 4447 | if (PL_preprocess) |
50952442 | 4448 | IoTYPE(GvIOp(gv)) = IoTYPE_PIPE; |
3280af22 | 4449 | else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) |
50952442 | 4450 | IoTYPE(GvIOp(gv)) = IoTYPE_STD; |
79072805 | 4451 | else |
50952442 | 4452 | IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY; |
c39cd008 GS |
4453 | #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS) |
4454 | /* if the script was opened in binmode, we need to revert | |
53129d29 | 4455 | * it to text mode for compatibility; but only iff it has CRs |
c39cd008 | 4456 | * XXX this is a questionable hack at best. */ |
53129d29 GS |
4457 | if (PL_bufend-PL_bufptr > 2 |
4458 | && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r') | |
c39cd008 GS |
4459 | { |
4460 | Off_t loc = 0; | |
50952442 | 4461 | if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) { |
c39cd008 GS |
4462 | loc = PerlIO_tell(PL_rsfp); |
4463 | (void)PerlIO_seek(PL_rsfp, 0L, 0); | |
4464 | } | |
2986a63f JH |
4465 | #ifdef NETWARE |
4466 | if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) { | |
4467 | #else | |
c39cd008 | 4468 | if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) { |
2986a63f | 4469 | #endif /* NETWARE */ |
1143fce0 JH |
4470 | #ifdef PERLIO_IS_STDIO /* really? */ |
4471 | # if defined(__BORLANDC__) | |
cb359b41 JH |
4472 | /* XXX see note in do_binmode() */ |
4473 | ((FILE*)PL_rsfp)->flags &= ~_F_BIN; | |
1143fce0 JH |
4474 | # endif |
4475 | #endif | |
c39cd008 GS |
4476 | if (loc > 0) |
4477 | PerlIO_seek(PL_rsfp, loc, 0); | |
4478 | } | |
4479 | } | |
4480 | #endif | |
7948272d | 4481 | #ifdef PERLIO_LAYERS |
52d2e0f4 JH |
4482 | if (!IN_BYTES) { |
4483 | if (UTF) | |
4484 | PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8"); | |
4485 | else if (PL_encoding) { | |
4486 | SV *name; | |
4487 | dSP; | |
4488 | ENTER; | |
4489 | SAVETMPS; | |
4490 | PUSHMARK(sp); | |
4491 | EXTEND(SP, 1); | |
4492 | XPUSHs(PL_encoding); | |
4493 | PUTBACK; | |
4494 | call_method("name", G_SCALAR); | |
4495 | SPAGAIN; | |
4496 | name = POPs; | |
4497 | PUTBACK; | |
bfed75c6 | 4498 | PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, |
52d2e0f4 JH |
4499 | Perl_form(aTHX_ ":encoding(%"SVf")", |
4500 | name)); | |
4501 | FREETMPS; | |
4502 | LEAVE; | |
4503 | } | |
4504 | } | |
7948272d | 4505 | #endif |
3280af22 | 4506 | PL_rsfp = Nullfp; |
79072805 LW |
4507 | } |
4508 | goto fake_eof; | |
e929a76b | 4509 | } |
de3bb511 | 4510 | |
8990e307 | 4511 | case KEY_AUTOLOAD: |
ed6116ce | 4512 | case KEY_DESTROY: |
79072805 | 4513 | case KEY_BEGIN: |
7d30b5c4 | 4514 | case KEY_CHECK: |
7d07dbc2 | 4515 | case KEY_INIT: |
7d30b5c4 | 4516 | case KEY_END: |
3280af22 NIS |
4517 | if (PL_expect == XSTATE) { |
4518 | s = PL_bufptr; | |
93a17b20 | 4519 | goto really_sub; |
79072805 LW |
4520 | } |
4521 | goto just_a_word; | |
4522 | ||
a0d0e21e LW |
4523 | case KEY_CORE: |
4524 | if (*s == ':' && s[1] == ':') { | |
4525 | s += 2; | |
748a9306 | 4526 | d = s; |
3280af22 | 4527 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
6798c92b GS |
4528 | if (!(tmp = keyword(PL_tokenbuf, len))) |
4529 | Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf); | |
a0d0e21e LW |
4530 | if (tmp < 0) |
4531 | tmp = -tmp; | |
850e8516 | 4532 | else if (tmp == KEY_require || tmp == KEY_do) |
a72a1c8b | 4533 | /* that's a way to remember we saw "CORE::" */ |
850e8516 | 4534 | orig_keyword = tmp; |
a0d0e21e LW |
4535 | goto reserved_word; |
4536 | } | |
4537 | goto just_a_word; | |
4538 | ||
463ee0b2 LW |
4539 | case KEY_abs: |
4540 | UNI(OP_ABS); | |
4541 | ||
79072805 LW |
4542 | case KEY_alarm: |
4543 | UNI(OP_ALARM); | |
4544 | ||
4545 | case KEY_accept: | |
a0d0e21e | 4546 | LOP(OP_ACCEPT,XTERM); |
79072805 | 4547 | |
463ee0b2 LW |
4548 | case KEY_and: |
4549 | OPERATOR(ANDOP); | |
4550 | ||
79072805 | 4551 | case KEY_atan2: |
a0d0e21e | 4552 | LOP(OP_ATAN2,XTERM); |
85e6fe83 | 4553 | |
79072805 | 4554 | case KEY_bind: |
a0d0e21e | 4555 | LOP(OP_BIND,XTERM); |
79072805 LW |
4556 | |
4557 | case KEY_binmode: | |
1c1fc3ea | 4558 | LOP(OP_BINMODE,XTERM); |
79072805 LW |
4559 | |
4560 | case KEY_bless: | |
a0d0e21e | 4561 | LOP(OP_BLESS,XTERM); |
79072805 LW |
4562 | |
4563 | case KEY_chop: | |
4564 | UNI(OP_CHOP); | |
4565 | ||
4566 | case KEY_continue: | |
4567 | PREBLOCK(CONTINUE); | |
4568 | ||
4569 | case KEY_chdir: | |
85e6fe83 | 4570 | (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */ |
79072805 LW |
4571 | UNI(OP_CHDIR); |
4572 | ||
4573 | case KEY_close: | |
4574 | UNI(OP_CLOSE); | |
4575 | ||
4576 | case KEY_closedir: | |
4577 | UNI(OP_CLOSEDIR); | |
4578 | ||
4579 | case KEY_cmp: | |
4580 | Eop(OP_SCMP); | |
4581 | ||
4582 | case KEY_caller: | |
4583 | UNI(OP_CALLER); | |
4584 | ||
4585 | case KEY_crypt: | |
4586 | #ifdef FCRYPT | |
f4c556ac GS |
4587 | if (!PL_cryptseen) { |
4588 | PL_cryptseen = TRUE; | |
de3bb511 | 4589 | init_des(); |
f4c556ac | 4590 | } |
a687059c | 4591 | #endif |
a0d0e21e | 4592 | LOP(OP_CRYPT,XTERM); |
79072805 LW |
4593 | |
4594 | case KEY_chmod: | |
a0d0e21e | 4595 | LOP(OP_CHMOD,XTERM); |
79072805 LW |
4596 | |
4597 | case KEY_chown: | |
a0d0e21e | 4598 | LOP(OP_CHOWN,XTERM); |
79072805 LW |
4599 | |
4600 | case KEY_connect: | |
a0d0e21e | 4601 | LOP(OP_CONNECT,XTERM); |
79072805 | 4602 | |
463ee0b2 LW |
4603 | case KEY_chr: |
4604 | UNI(OP_CHR); | |
4605 | ||
79072805 LW |
4606 | case KEY_cos: |
4607 | UNI(OP_COS); | |
4608 | ||
4609 | case KEY_chroot: | |
4610 | UNI(OP_CHROOT); | |
4611 | ||
4612 | case KEY_do: | |
4613 | s = skipspace(s); | |
4614 | if (*s == '{') | |
a0d0e21e | 4615 | PRETERMBLOCK(DO); |
79072805 | 4616 | if (*s != '\'') |
89c5585f | 4617 | s = force_word(s,WORD,TRUE,TRUE,FALSE); |
850e8516 RGS |
4618 | if (orig_keyword == KEY_do) { |
4619 | orig_keyword = 0; | |
4620 | yylval.ival = 1; | |
4621 | } | |
4622 | else | |
4623 | yylval.ival = 0; | |
378cc40b | 4624 | OPERATOR(DO); |
79072805 LW |
4625 | |
4626 | case KEY_die: | |
3280af22 | 4627 | PL_hints |= HINT_BLOCK_SCOPE; |
a0d0e21e | 4628 | LOP(OP_DIE,XTERM); |
79072805 LW |
4629 | |
4630 | case KEY_defined: | |
4631 | UNI(OP_DEFINED); | |
4632 | ||
4633 | case KEY_delete: | |
a0d0e21e | 4634 | UNI(OP_DELETE); |
79072805 LW |
4635 | |
4636 | case KEY_dbmopen: | |
a0d0e21e LW |
4637 | gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV); |
4638 | LOP(OP_DBMOPEN,XTERM); | |
79072805 LW |
4639 | |
4640 | case KEY_dbmclose: | |
4641 | UNI(OP_DBMCLOSE); | |
4642 | ||
4643 | case KEY_dump: | |
a0d0e21e | 4644 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4645 | LOOPX(OP_DUMP); |
4646 | ||
4647 | case KEY_else: | |
4648 | PREBLOCK(ELSE); | |
4649 | ||
4650 | case KEY_elsif: | |
57843af0 | 4651 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
4652 | OPERATOR(ELSIF); |
4653 | ||
4654 | case KEY_eq: | |
4655 | Eop(OP_SEQ); | |
4656 | ||
a0d0e21e LW |
4657 | case KEY_exists: |
4658 | UNI(OP_EXISTS); | |
4e553d73 | 4659 | |
79072805 LW |
4660 | case KEY_exit: |
4661 | UNI(OP_EXIT); | |
4662 | ||
4663 | case KEY_eval: | |
79072805 | 4664 | s = skipspace(s); |
3280af22 | 4665 | PL_expect = (*s == '{') ? XTERMBLOCK : XTERM; |
463ee0b2 | 4666 | UNIBRACK(OP_ENTEREVAL); |
79072805 LW |
4667 | |
4668 | case KEY_eof: | |
4669 | UNI(OP_EOF); | |
4670 | ||
c963b151 BD |
4671 | case KEY_err: |
4672 | OPERATOR(DOROP); | |
4673 | ||
79072805 LW |
4674 | case KEY_exp: |
4675 | UNI(OP_EXP); | |
4676 | ||
4677 | case KEY_each: | |
4678 | UNI(OP_EACH); | |
4679 | ||
4680 | case KEY_exec: | |
4681 | set_csh(); | |
a0d0e21e | 4682 | LOP(OP_EXEC,XREF); |
79072805 LW |
4683 | |
4684 | case KEY_endhostent: | |
4685 | FUN0(OP_EHOSTENT); | |
4686 | ||
4687 | case KEY_endnetent: | |
4688 | FUN0(OP_ENETENT); | |
4689 | ||
4690 | case KEY_endservent: | |
4691 | FUN0(OP_ESERVENT); | |
4692 | ||
4693 | case KEY_endprotoent: | |
4694 | FUN0(OP_EPROTOENT); | |
4695 | ||
4696 | case KEY_endpwent: | |
4697 | FUN0(OP_EPWENT); | |
4698 | ||
4699 | case KEY_endgrent: | |
4700 | FUN0(OP_EGRENT); | |
4701 | ||
4702 | case KEY_for: | |
4703 | case KEY_foreach: | |
57843af0 | 4704 | yylval.ival = CopLINE(PL_curcop); |
55497cff | 4705 | s = skipspace(s); |
7e2040f0 | 4706 | if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) { |
55497cff | 4707 | char *p = s; |
3280af22 | 4708 | if ((PL_bufend - p) >= 3 && |
55497cff | 4709 | strnEQ(p, "my", 2) && isSPACE(*(p + 2))) |
4710 | p += 2; | |
77ca0c92 LW |
4711 | else if ((PL_bufend - p) >= 4 && |
4712 | strnEQ(p, "our", 3) && isSPACE(*(p + 3))) | |
4713 | p += 3; | |
55497cff | 4714 | p = skipspace(p); |
7e2040f0 | 4715 | if (isIDFIRST_lazy_if(p,UTF)) { |
77ca0c92 LW |
4716 | p = scan_ident(p, PL_bufend, |
4717 | PL_tokenbuf, sizeof PL_tokenbuf, TRUE); | |
4718 | p = skipspace(p); | |
4719 | } | |
4720 | if (*p != '$') | |
cea2e8a9 | 4721 | Perl_croak(aTHX_ "Missing $ on loop variable"); |
55497cff | 4722 | } |
79072805 LW |
4723 | OPERATOR(FOR); |
4724 | ||
4725 | case KEY_formline: | |
a0d0e21e | 4726 | LOP(OP_FORMLINE,XTERM); |
79072805 LW |
4727 | |
4728 | case KEY_fork: | |
4729 | FUN0(OP_FORK); | |
4730 | ||
4731 | case KEY_fcntl: | |
a0d0e21e | 4732 | LOP(OP_FCNTL,XTERM); |
79072805 LW |
4733 | |
4734 | case KEY_fileno: | |
4735 | UNI(OP_FILENO); | |
4736 | ||
4737 | case KEY_flock: | |
a0d0e21e | 4738 | LOP(OP_FLOCK,XTERM); |
79072805 LW |
4739 | |
4740 | case KEY_gt: | |
4741 | Rop(OP_SGT); | |
4742 | ||
4743 | case KEY_ge: | |
4744 | Rop(OP_SGE); | |
4745 | ||
4746 | case KEY_grep: | |
2c38e13d | 4747 | LOP(OP_GREPSTART, XREF); |
79072805 LW |
4748 | |
4749 | case KEY_goto: | |
a0d0e21e | 4750 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4751 | LOOPX(OP_GOTO); |
4752 | ||
4753 | case KEY_gmtime: | |
4754 | UNI(OP_GMTIME); | |
4755 | ||
4756 | case KEY_getc: | |
6f33ba73 | 4757 | UNIDOR(OP_GETC); |
79072805 LW |
4758 | |
4759 | case KEY_getppid: | |
4760 | FUN0(OP_GETPPID); | |
4761 | ||
4762 | case KEY_getpgrp: | |
4763 | UNI(OP_GETPGRP); | |
4764 | ||
4765 | case KEY_getpriority: | |
a0d0e21e | 4766 | LOP(OP_GETPRIORITY,XTERM); |
79072805 LW |
4767 | |
4768 | case KEY_getprotobyname: | |
4769 | UNI(OP_GPBYNAME); | |
4770 | ||
4771 | case KEY_getprotobynumber: | |
a0d0e21e | 4772 | LOP(OP_GPBYNUMBER,XTERM); |
79072805 LW |
4773 | |
4774 | case KEY_getprotoent: | |
4775 | FUN0(OP_GPROTOENT); | |
4776 | ||
4777 | case KEY_getpwent: | |
4778 | FUN0(OP_GPWENT); | |
4779 | ||
4780 | case KEY_getpwnam: | |
ff68c719 | 4781 | UNI(OP_GPWNAM); |
79072805 LW |
4782 | |
4783 | case KEY_getpwuid: | |
ff68c719 | 4784 | UNI(OP_GPWUID); |
79072805 LW |
4785 | |
4786 | case KEY_getpeername: | |
4787 | UNI(OP_GETPEERNAME); | |
4788 | ||
4789 | case KEY_gethostbyname: | |
4790 | UNI(OP_GHBYNAME); | |
4791 | ||
4792 | case KEY_gethostbyaddr: | |
a0d0e21e | 4793 | LOP(OP_GHBYADDR,XTERM); |
79072805 LW |
4794 | |
4795 | case KEY_gethostent: | |
4796 | FUN0(OP_GHOSTENT); | |
4797 | ||
4798 | case KEY_getnetbyname: | |
4799 | UNI(OP_GNBYNAME); | |
4800 | ||
4801 | case KEY_getnetbyaddr: | |
a0d0e21e | 4802 | LOP(OP_GNBYADDR,XTERM); |
79072805 LW |
4803 | |
4804 | case KEY_getnetent: | |
4805 | FUN0(OP_GNETENT); | |
4806 | ||
4807 | case KEY_getservbyname: | |
a0d0e21e | 4808 | LOP(OP_GSBYNAME,XTERM); |
79072805 LW |
4809 | |
4810 | case KEY_getservbyport: | |
a0d0e21e | 4811 | LOP(OP_GSBYPORT,XTERM); |
79072805 LW |
4812 | |
4813 | case KEY_getservent: | |
4814 | FUN0(OP_GSERVENT); | |
4815 | ||
4816 | case KEY_getsockname: | |
4817 | UNI(OP_GETSOCKNAME); | |
4818 | ||
4819 | case KEY_getsockopt: | |
a0d0e21e | 4820 | LOP(OP_GSOCKOPT,XTERM); |
79072805 LW |
4821 | |
4822 | case KEY_getgrent: | |
4823 | FUN0(OP_GGRENT); | |
4824 | ||
4825 | case KEY_getgrnam: | |
ff68c719 | 4826 | UNI(OP_GGRNAM); |
79072805 LW |
4827 | |
4828 | case KEY_getgrgid: | |
ff68c719 | 4829 | UNI(OP_GGRGID); |
79072805 LW |
4830 | |
4831 | case KEY_getlogin: | |
4832 | FUN0(OP_GETLOGIN); | |
4833 | ||
93a17b20 | 4834 | case KEY_glob: |
a0d0e21e LW |
4835 | set_csh(); |
4836 | LOP(OP_GLOB,XTERM); | |
93a17b20 | 4837 | |
79072805 LW |
4838 | case KEY_hex: |
4839 | UNI(OP_HEX); | |
4840 | ||
4841 | case KEY_if: | |
57843af0 | 4842 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
4843 | OPERATOR(IF); |
4844 | ||
4845 | case KEY_index: | |
a0d0e21e | 4846 | LOP(OP_INDEX,XTERM); |
79072805 LW |
4847 | |
4848 | case KEY_int: | |
4849 | UNI(OP_INT); | |
4850 | ||
4851 | case KEY_ioctl: | |
a0d0e21e | 4852 | LOP(OP_IOCTL,XTERM); |
79072805 LW |
4853 | |
4854 | case KEY_join: | |
a0d0e21e | 4855 | LOP(OP_JOIN,XTERM); |
79072805 LW |
4856 | |
4857 | case KEY_keys: | |
4858 | UNI(OP_KEYS); | |
4859 | ||
4860 | case KEY_kill: | |
a0d0e21e | 4861 | LOP(OP_KILL,XTERM); |
79072805 LW |
4862 | |
4863 | case KEY_last: | |
a0d0e21e | 4864 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 | 4865 | LOOPX(OP_LAST); |
4e553d73 | 4866 | |
79072805 LW |
4867 | case KEY_lc: |
4868 | UNI(OP_LC); | |
4869 | ||
4870 | case KEY_lcfirst: | |
4871 | UNI(OP_LCFIRST); | |
4872 | ||
4873 | case KEY_local: | |
09bef843 | 4874 | yylval.ival = 0; |
79072805 LW |
4875 | OPERATOR(LOCAL); |
4876 | ||
4877 | case KEY_length: | |
4878 | UNI(OP_LENGTH); | |
4879 | ||
4880 | case KEY_lt: | |
4881 | Rop(OP_SLT); | |
4882 | ||
4883 | case KEY_le: | |
4884 | Rop(OP_SLE); | |
4885 | ||
4886 | case KEY_localtime: | |
4887 | UNI(OP_LOCALTIME); | |
4888 | ||
4889 | case KEY_log: | |
4890 | UNI(OP_LOG); | |
4891 | ||
4892 | case KEY_link: | |
a0d0e21e | 4893 | LOP(OP_LINK,XTERM); |
79072805 LW |
4894 | |
4895 | case KEY_listen: | |
a0d0e21e | 4896 | LOP(OP_LISTEN,XTERM); |
79072805 | 4897 | |
c0329465 MB |
4898 | case KEY_lock: |
4899 | UNI(OP_LOCK); | |
4900 | ||
79072805 LW |
4901 | case KEY_lstat: |
4902 | UNI(OP_LSTAT); | |
4903 | ||
4904 | case KEY_m: | |
8782bef2 | 4905 | s = scan_pat(s,OP_MATCH); |
79072805 LW |
4906 | TERM(sublex_start()); |
4907 | ||
a0d0e21e | 4908 | case KEY_map: |
2c38e13d | 4909 | LOP(OP_MAPSTART, XREF); |
4e4e412b | 4910 | |
79072805 | 4911 | case KEY_mkdir: |
a0d0e21e | 4912 | LOP(OP_MKDIR,XTERM); |
79072805 LW |
4913 | |
4914 | case KEY_msgctl: | |
a0d0e21e | 4915 | LOP(OP_MSGCTL,XTERM); |
79072805 LW |
4916 | |
4917 | case KEY_msgget: | |
a0d0e21e | 4918 | LOP(OP_MSGGET,XTERM); |
79072805 LW |
4919 | |
4920 | case KEY_msgrcv: | |
a0d0e21e | 4921 | LOP(OP_MSGRCV,XTERM); |
79072805 LW |
4922 | |
4923 | case KEY_msgsnd: | |
a0d0e21e | 4924 | LOP(OP_MSGSND,XTERM); |
79072805 | 4925 | |
77ca0c92 | 4926 | case KEY_our: |
93a17b20 | 4927 | case KEY_my: |
77ca0c92 | 4928 | PL_in_my = tmp; |
c750a3ec | 4929 | s = skipspace(s); |
7e2040f0 | 4930 | if (isIDFIRST_lazy_if(s,UTF)) { |
3280af22 | 4931 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len); |
09bef843 SB |
4932 | if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3)) |
4933 | goto really_sub; | |
def3634b | 4934 | PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len); |
3280af22 | 4935 | if (!PL_in_my_stash) { |
c750a3ec | 4936 | char tmpbuf[1024]; |
3280af22 NIS |
4937 | PL_bufptr = s; |
4938 | sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf); | |
c750a3ec MB |
4939 | yyerror(tmpbuf); |
4940 | } | |
4941 | } | |
09bef843 | 4942 | yylval.ival = 1; |
55497cff | 4943 | OPERATOR(MY); |
93a17b20 | 4944 | |
79072805 | 4945 | case KEY_next: |
a0d0e21e | 4946 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4947 | LOOPX(OP_NEXT); |
4948 | ||
4949 | case KEY_ne: | |
4950 | Eop(OP_SNE); | |
4951 | ||
a0d0e21e | 4952 | case KEY_no: |
468aa647 | 4953 | s = tokenize_use(0, s); |
a0d0e21e LW |
4954 | OPERATOR(USE); |
4955 | ||
4956 | case KEY_not: | |
2d2e263d LW |
4957 | if (*s == '(' || (s = skipspace(s), *s == '(')) |
4958 | FUN1(OP_NOT); | |
4959 | else | |
4960 | OPERATOR(NOTOP); | |
a0d0e21e | 4961 | |
79072805 | 4962 | case KEY_open: |
93a17b20 | 4963 | s = skipspace(s); |
7e2040f0 | 4964 | if (isIDFIRST_lazy_if(s,UTF)) { |
f54cb97a | 4965 | const char *t; |
7e2040f0 | 4966 | for (d = s; isALNUM_lazy_if(d,UTF); d++) ; |
e2ab214b DM |
4967 | for (t=d; *t && isSPACE(*t); t++) ; |
4968 | if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE) | |
66fbe8fb HS |
4969 | /* [perl #16184] */ |
4970 | && !(t[0] == '=' && t[1] == '>') | |
4971 | ) { | |
551405c4 | 4972 | int len = (int)(d-s); |
9014280d | 4973 | Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE), |
0453d815 | 4974 | "Precedence problem: open %.*s should be open(%.*s)", |
551405c4 | 4975 | len, s, len, s); |
66fbe8fb | 4976 | } |
93a17b20 | 4977 | } |
a0d0e21e | 4978 | LOP(OP_OPEN,XTERM); |
79072805 | 4979 | |
463ee0b2 | 4980 | case KEY_or: |
a0d0e21e | 4981 | yylval.ival = OP_OR; |
463ee0b2 LW |
4982 | OPERATOR(OROP); |
4983 | ||
79072805 LW |
4984 | case KEY_ord: |
4985 | UNI(OP_ORD); | |
4986 | ||
4987 | case KEY_oct: | |
4988 | UNI(OP_OCT); | |
4989 | ||
4990 | case KEY_opendir: | |
a0d0e21e | 4991 | LOP(OP_OPEN_DIR,XTERM); |
79072805 LW |
4992 | |
4993 | case KEY_print: | |
3280af22 | 4994 | checkcomma(s,PL_tokenbuf,"filehandle"); |
a0d0e21e | 4995 | LOP(OP_PRINT,XREF); |
79072805 LW |
4996 | |
4997 | case KEY_printf: | |
3280af22 | 4998 | checkcomma(s,PL_tokenbuf,"filehandle"); |
a0d0e21e | 4999 | LOP(OP_PRTF,XREF); |
79072805 | 5000 | |
c07a80fd | 5001 | case KEY_prototype: |
5002 | UNI(OP_PROTOTYPE); | |
5003 | ||
79072805 | 5004 | case KEY_push: |
a0d0e21e | 5005 | LOP(OP_PUSH,XTERM); |
79072805 LW |
5006 | |
5007 | case KEY_pop: | |
6f33ba73 | 5008 | UNIDOR(OP_POP); |
79072805 | 5009 | |
a0d0e21e | 5010 | case KEY_pos: |
6f33ba73 | 5011 | UNIDOR(OP_POS); |
4e553d73 | 5012 | |
79072805 | 5013 | case KEY_pack: |
a0d0e21e | 5014 | LOP(OP_PACK,XTERM); |
79072805 LW |
5015 | |
5016 | case KEY_package: | |
a0d0e21e | 5017 | s = force_word(s,WORD,FALSE,TRUE,FALSE); |
79072805 LW |
5018 | OPERATOR(PACKAGE); |
5019 | ||
5020 | case KEY_pipe: | |
a0d0e21e | 5021 | LOP(OP_PIPE_OP,XTERM); |
79072805 LW |
5022 | |
5023 | case KEY_q: | |
09bef843 | 5024 | s = scan_str(s,FALSE,FALSE); |
79072805 | 5025 | if (!s) |
85e6fe83 | 5026 | missingterm((char*)0); |
79072805 LW |
5027 | yylval.ival = OP_CONST; |
5028 | TERM(sublex_start()); | |
5029 | ||
a0d0e21e LW |
5030 | case KEY_quotemeta: |
5031 | UNI(OP_QUOTEMETA); | |
5032 | ||
8990e307 | 5033 | case KEY_qw: |
09bef843 | 5034 | s = scan_str(s,FALSE,FALSE); |
8990e307 | 5035 | if (!s) |
85e6fe83 | 5036 | missingterm((char*)0); |
3480a8d2 | 5037 | PL_expect = XOPERATOR; |
8127e0e3 GS |
5038 | force_next(')'); |
5039 | if (SvCUR(PL_lex_stuff)) { | |
5040 | OP *words = Nullop; | |
5041 | int warned = 0; | |
3280af22 | 5042 | d = SvPV_force(PL_lex_stuff, len); |
8127e0e3 | 5043 | while (len) { |
7948272d | 5044 | SV *sv; |
8127e0e3 GS |
5045 | for (; isSPACE(*d) && len; --len, ++d) ; |
5046 | if (len) { | |
f54cb97a | 5047 | const char *b = d; |
e476b1b5 | 5048 | if (!warned && ckWARN(WARN_QW)) { |
8127e0e3 GS |
5049 | for (; !isSPACE(*d) && len; --len, ++d) { |
5050 | if (*d == ',') { | |
9014280d | 5051 | Perl_warner(aTHX_ packWARN(WARN_QW), |
8127e0e3 GS |
5052 | "Possible attempt to separate words with commas"); |
5053 | ++warned; | |
5054 | } | |
5055 | else if (*d == '#') { | |
9014280d | 5056 | Perl_warner(aTHX_ packWARN(WARN_QW), |
8127e0e3 GS |
5057 | "Possible attempt to put comments in qw() list"); |
5058 | ++warned; | |
5059 | } | |
5060 | } | |
5061 | } | |
5062 | else { | |
5063 | for (; !isSPACE(*d) && len; --len, ++d) ; | |
5064 | } | |
7948272d NIS |
5065 | sv = newSVpvn(b, d-b); |
5066 | if (DO_UTF8(PL_lex_stuff)) | |
5067 | SvUTF8_on(sv); | |
8127e0e3 | 5068 | words = append_elem(OP_LIST, words, |
7948272d | 5069 | newSVOP(OP_CONST, 0, tokeq(sv))); |
55497cff | 5070 | } |
5071 | } | |
8127e0e3 GS |
5072 | if (words) { |
5073 | PL_nextval[PL_nexttoke].opval = words; | |
5074 | force_next(THING); | |
5075 | } | |
55497cff | 5076 | } |
37fd879b | 5077 | if (PL_lex_stuff) { |
8127e0e3 | 5078 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
5079 | PL_lex_stuff = Nullsv; |
5080 | } | |
3280af22 | 5081 | PL_expect = XTERM; |
8127e0e3 | 5082 | TOKEN('('); |
8990e307 | 5083 | |
79072805 | 5084 | case KEY_qq: |
09bef843 | 5085 | s = scan_str(s,FALSE,FALSE); |
79072805 | 5086 | if (!s) |
85e6fe83 | 5087 | missingterm((char*)0); |
a0d0e21e | 5088 | yylval.ival = OP_STRINGIFY; |
3280af22 | 5089 | if (SvIVX(PL_lex_stuff) == '\'') |
45977657 | 5090 | SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */ |
79072805 LW |
5091 | TERM(sublex_start()); |
5092 | ||
8782bef2 GB |
5093 | case KEY_qr: |
5094 | s = scan_pat(s,OP_QR); | |
5095 | TERM(sublex_start()); | |
5096 | ||
79072805 | 5097 | case KEY_qx: |
09bef843 | 5098 | s = scan_str(s,FALSE,FALSE); |
79072805 | 5099 | if (!s) |
85e6fe83 | 5100 | missingterm((char*)0); |
79072805 LW |
5101 | yylval.ival = OP_BACKTICK; |
5102 | set_csh(); | |
5103 | TERM(sublex_start()); | |
5104 | ||
5105 | case KEY_return: | |
5106 | OLDLOP(OP_RETURN); | |
5107 | ||
5108 | case KEY_require: | |
a7cb1f99 | 5109 | s = skipspace(s); |
e759cc13 RGS |
5110 | if (isDIGIT(*s)) { |
5111 | s = force_version(s, FALSE); | |
a7cb1f99 | 5112 | } |
e759cc13 RGS |
5113 | else if (*s != 'v' || !isDIGIT(s[1]) |
5114 | || (s = force_version(s, TRUE), *s == 'v')) | |
5115 | { | |
a7cb1f99 GS |
5116 | *PL_tokenbuf = '\0'; |
5117 | s = force_word(s,WORD,TRUE,TRUE,FALSE); | |
7e2040f0 | 5118 | if (isIDFIRST_lazy_if(PL_tokenbuf,UTF)) |
a7cb1f99 GS |
5119 | gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE); |
5120 | else if (*s == '<') | |
5121 | yyerror("<> should be quotes"); | |
5122 | } | |
a72a1c8b RGS |
5123 | if (orig_keyword == KEY_require) { |
5124 | orig_keyword = 0; | |
5125 | yylval.ival = 1; | |
5126 | } | |
5127 | else | |
5128 | yylval.ival = 0; | |
5129 | PL_expect = XTERM; | |
5130 | PL_bufptr = s; | |
5131 | PL_last_uni = PL_oldbufptr; | |
5132 | PL_last_lop_op = OP_REQUIRE; | |
5133 | s = skipspace(s); | |
5134 | return REPORT( (int)REQUIRE ); | |
79072805 LW |
5135 | |
5136 | case KEY_reset: | |
5137 | UNI(OP_RESET); | |
5138 | ||
5139 | case KEY_redo: | |
a0d0e21e | 5140 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
5141 | LOOPX(OP_REDO); |
5142 | ||
5143 | case KEY_rename: | |
a0d0e21e | 5144 | LOP(OP_RENAME,XTERM); |
79072805 LW |
5145 | |
5146 | case KEY_rand: | |
5147 | UNI(OP_RAND); | |
5148 | ||
5149 | case KEY_rmdir: | |
5150 | UNI(OP_RMDIR); | |
5151 | ||
5152 | case KEY_rindex: | |
a0d0e21e | 5153 | LOP(OP_RINDEX,XTERM); |
79072805 LW |
5154 | |
5155 | case KEY_read: | |
a0d0e21e | 5156 | LOP(OP_READ,XTERM); |
79072805 LW |
5157 | |
5158 | case KEY_readdir: | |
5159 | UNI(OP_READDIR); | |
5160 | ||
93a17b20 LW |
5161 | case KEY_readline: |
5162 | set_csh(); | |
6f33ba73 | 5163 | UNIDOR(OP_READLINE); |
93a17b20 LW |
5164 | |
5165 | case KEY_readpipe: | |
5166 | set_csh(); | |
5167 | UNI(OP_BACKTICK); | |
5168 | ||
79072805 LW |
5169 | case KEY_rewinddir: |
5170 | UNI(OP_REWINDDIR); | |
5171 | ||
5172 | case KEY_recv: | |
a0d0e21e | 5173 | LOP(OP_RECV,XTERM); |
79072805 LW |
5174 | |
5175 | case KEY_reverse: | |
a0d0e21e | 5176 | LOP(OP_REVERSE,XTERM); |
79072805 LW |
5177 | |
5178 | case KEY_readlink: | |
6f33ba73 | 5179 | UNIDOR(OP_READLINK); |
79072805 LW |
5180 | |
5181 | case KEY_ref: | |
5182 | UNI(OP_REF); | |
5183 | ||
5184 | case KEY_s: | |
5185 | s = scan_subst(s); | |
5186 | if (yylval.opval) | |
5187 | TERM(sublex_start()); | |
5188 | else | |
5189 | TOKEN(1); /* force error */ | |
5190 | ||
a0d0e21e LW |
5191 | case KEY_chomp: |
5192 | UNI(OP_CHOMP); | |
4e553d73 | 5193 | |
79072805 LW |
5194 | case KEY_scalar: |
5195 | UNI(OP_SCALAR); | |
5196 | ||
5197 | case KEY_select: | |
a0d0e21e | 5198 | LOP(OP_SELECT,XTERM); |
79072805 LW |
5199 | |
5200 | case KEY_seek: | |
a0d0e21e | 5201 | LOP(OP_SEEK,XTERM); |
79072805 LW |
5202 | |
5203 | case KEY_semctl: | |
a0d0e21e | 5204 | LOP(OP_SEMCTL,XTERM); |
79072805 LW |
5205 | |
5206 | case KEY_semget: | |
a0d0e21e | 5207 | LOP(OP_SEMGET,XTERM); |
79072805 LW |
5208 | |
5209 | case KEY_semop: | |
a0d0e21e | 5210 | LOP(OP_SEMOP,XTERM); |
79072805 LW |
5211 | |
5212 | case KEY_send: | |
a0d0e21e | 5213 | LOP(OP_SEND,XTERM); |
79072805 LW |
5214 | |
5215 | case KEY_setpgrp: | |
a0d0e21e | 5216 | LOP(OP_SETPGRP,XTERM); |
79072805 LW |
5217 | |
5218 | case KEY_setpriority: | |
a0d0e21e | 5219 | LOP(OP_SETPRIORITY,XTERM); |
79072805 LW |
5220 | |
5221 | case KEY_sethostent: | |
ff68c719 | 5222 | UNI(OP_SHOSTENT); |
79072805 LW |
5223 | |
5224 | case KEY_setnetent: | |
ff68c719 | 5225 | UNI(OP_SNETENT); |
79072805 LW |
5226 | |
5227 | case KEY_setservent: | |
ff68c719 | 5228 | UNI(OP_SSERVENT); |
79072805 LW |
5229 | |
5230 | case KEY_setprotoent: | |
ff68c719 | 5231 | UNI(OP_SPROTOENT); |
79072805 LW |
5232 | |
5233 | case KEY_setpwent: | |
5234 | FUN0(OP_SPWENT); | |
5235 | ||
5236 | case KEY_setgrent: | |
5237 | FUN0(OP_SGRENT); | |
5238 | ||
5239 | case KEY_seekdir: | |
a0d0e21e | 5240 | LOP(OP_SEEKDIR,XTERM); |
79072805 LW |
5241 | |
5242 | case KEY_setsockopt: | |
a0d0e21e | 5243 | LOP(OP_SSOCKOPT,XTERM); |
79072805 LW |
5244 | |
5245 | case KEY_shift: | |
6f33ba73 | 5246 | UNIDOR(OP_SHIFT); |
79072805 LW |
5247 | |
5248 | case KEY_shmctl: | |
a0d0e21e | 5249 | LOP(OP_SHMCTL,XTERM); |
79072805 LW |
5250 | |
5251 | case KEY_shmget: | |
a0d0e21e | 5252 | LOP(OP_SHMGET,XTERM); |
79072805 LW |
5253 | |
5254 | case KEY_shmread: | |
a0d0e21e | 5255 | LOP(OP_SHMREAD,XTERM); |
79072805 LW |
5256 | |
5257 | case KEY_shmwrite: | |
a0d0e21e | 5258 | LOP(OP_SHMWRITE,XTERM); |
79072805 LW |
5259 | |
5260 | case KEY_shutdown: | |
a0d0e21e | 5261 | LOP(OP_SHUTDOWN,XTERM); |
79072805 LW |
5262 | |
5263 | case KEY_sin: | |
5264 | UNI(OP_SIN); | |
5265 | ||
5266 | case KEY_sleep: | |
5267 | UNI(OP_SLEEP); | |
5268 | ||
5269 | case KEY_socket: | |
a0d0e21e | 5270 | LOP(OP_SOCKET,XTERM); |
79072805 LW |
5271 | |
5272 | case KEY_socketpair: | |
a0d0e21e | 5273 | LOP(OP_SOCKPAIR,XTERM); |
79072805 LW |
5274 | |
5275 | case KEY_sort: | |
3280af22 | 5276 | checkcomma(s,PL_tokenbuf,"subroutine name"); |
79072805 LW |
5277 | s = skipspace(s); |
5278 | if (*s == ';' || *s == ')') /* probably a close */ | |
cea2e8a9 | 5279 | Perl_croak(aTHX_ "sort is now a reserved word"); |
3280af22 | 5280 | PL_expect = XTERM; |
15f0808c | 5281 | s = force_word(s,WORD,TRUE,TRUE,FALSE); |
a0d0e21e | 5282 | LOP(OP_SORT,XREF); |
79072805 LW |
5283 | |
5284 | case KEY_split: | |
a0d0e21e | 5285 | LOP(OP_SPLIT,XTERM); |
79072805 LW |
5286 | |
5287 | case KEY_sprintf: | |
a0d0e21e | 5288 | LOP(OP_SPRINTF,XTERM); |
79072805 LW |
5289 | |
5290 | case KEY_splice: | |
a0d0e21e | 5291 | LOP(OP_SPLICE,XTERM); |
79072805 LW |
5292 | |
5293 | case KEY_sqrt: | |
5294 | UNI(OP_SQRT); | |
5295 | ||
5296 | case KEY_srand: | |
5297 | UNI(OP_SRAND); | |
5298 | ||
5299 | case KEY_stat: | |
5300 | UNI(OP_STAT); | |
5301 | ||
5302 | case KEY_study: | |
79072805 LW |
5303 | UNI(OP_STUDY); |
5304 | ||
5305 | case KEY_substr: | |
a0d0e21e | 5306 | LOP(OP_SUBSTR,XTERM); |
79072805 LW |
5307 | |
5308 | case KEY_format: | |
5309 | case KEY_sub: | |
93a17b20 | 5310 | really_sub: |
09bef843 | 5311 | { |
3280af22 | 5312 | char tmpbuf[sizeof PL_tokenbuf]; |
9c5ffd7c | 5313 | SSize_t tboffset = 0; |
09bef843 | 5314 | expectation attrful; |
d731386a | 5315 | bool have_name, have_proto, bad_proto; |
f54cb97a | 5316 | const int key = tmp; |
09bef843 SB |
5317 | |
5318 | s = skipspace(s); | |
5319 | ||
7e2040f0 | 5320 | if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' || |
09bef843 SB |
5321 | (*s == ':' && s[1] == ':')) |
5322 | { | |
5323 | PL_expect = XBLOCK; | |
5324 | attrful = XATTRBLOCK; | |
b1b65b59 JH |
5325 | /* remember buffer pos'n for later force_word */ |
5326 | tboffset = s - PL_oldbufptr; | |
09bef843 SB |
5327 | d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
5328 | if (strchr(tmpbuf, ':')) | |
5329 | sv_setpv(PL_subname, tmpbuf); | |
5330 | else { | |
5331 | sv_setsv(PL_subname,PL_curstname); | |
5332 | sv_catpvn(PL_subname,"::",2); | |
5333 | sv_catpvn(PL_subname,tmpbuf,len); | |
5334 | } | |
5335 | s = skipspace(d); | |
5336 | have_name = TRUE; | |
5337 | } | |
463ee0b2 | 5338 | else { |
09bef843 SB |
5339 | if (key == KEY_my) |
5340 | Perl_croak(aTHX_ "Missing name in \"my sub\""); | |
5341 | PL_expect = XTERMBLOCK; | |
5342 | attrful = XATTRTERM; | |
c69006e4 | 5343 | sv_setpvn(PL_subname,"?",1); |
09bef843 | 5344 | have_name = FALSE; |
463ee0b2 | 5345 | } |
4633a7c4 | 5346 | |
09bef843 SB |
5347 | if (key == KEY_format) { |
5348 | if (*s == '=') | |
5349 | PL_lex_formbrack = PL_lex_brackets + 1; | |
5350 | if (have_name) | |
b1b65b59 JH |
5351 | (void) force_word(PL_oldbufptr + tboffset, WORD, |
5352 | FALSE, TRUE, TRUE); | |
09bef843 SB |
5353 | OPERATOR(FORMAT); |
5354 | } | |
79072805 | 5355 | |
09bef843 SB |
5356 | /* Look for a prototype */ |
5357 | if (*s == '(') { | |
5358 | char *p; | |
5359 | ||
5360 | s = scan_str(s,FALSE,FALSE); | |
37fd879b | 5361 | if (!s) |
09bef843 | 5362 | Perl_croak(aTHX_ "Prototype not terminated"); |
2f758a16 | 5363 | /* strip spaces and check for bad characters */ |
09bef843 SB |
5364 | d = SvPVX(PL_lex_stuff); |
5365 | tmp = 0; | |
d731386a | 5366 | bad_proto = FALSE; |
09bef843 | 5367 | for (p = d; *p; ++p) { |
d37a9538 | 5368 | if (!isSPACE(*p)) { |
09bef843 | 5369 | d[tmp++] = *p; |
d37a9538 ST |
5370 | if (!strchr("$@%*;[]&\\", *p)) |
5371 | bad_proto = TRUE; | |
5372 | } | |
09bef843 SB |
5373 | } |
5374 | d[tmp] = '\0'; | |
420cdfc1 | 5375 | if (bad_proto && ckWARN(WARN_SYNTAX)) |
9014280d | 5376 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
35c1215d NC |
5377 | "Illegal character in prototype for %"SVf" : %s", |
5378 | PL_subname, d); | |
b162af07 | 5379 | SvCUR_set(PL_lex_stuff, tmp); |
09bef843 | 5380 | have_proto = TRUE; |
68dc0745 | 5381 | |
09bef843 | 5382 | s = skipspace(s); |
4633a7c4 | 5383 | } |
09bef843 SB |
5384 | else |
5385 | have_proto = FALSE; | |
5386 | ||
5387 | if (*s == ':' && s[1] != ':') | |
5388 | PL_expect = attrful; | |
8e742a20 MHM |
5389 | else if (*s != '{' && key == KEY_sub) { |
5390 | if (!have_name) | |
5391 | Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine"); | |
5392 | else if (*s != ';') | |
5393 | Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname); | |
5394 | } | |
09bef843 SB |
5395 | |
5396 | if (have_proto) { | |
b1b65b59 JH |
5397 | PL_nextval[PL_nexttoke].opval = |
5398 | (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff); | |
09bef843 SB |
5399 | PL_lex_stuff = Nullsv; |
5400 | force_next(THING); | |
68dc0745 | 5401 | } |
09bef843 | 5402 | if (!have_name) { |
c99da370 JH |
5403 | sv_setpv(PL_subname, |
5404 | PL_curstash ? "__ANON__" : "__ANON__::__ANON__"); | |
09bef843 | 5405 | TOKEN(ANONSUB); |
4633a7c4 | 5406 | } |
b1b65b59 JH |
5407 | (void) force_word(PL_oldbufptr + tboffset, WORD, |
5408 | FALSE, TRUE, TRUE); | |
09bef843 SB |
5409 | if (key == KEY_my) |
5410 | TOKEN(MYSUB); | |
5411 | TOKEN(SUB); | |
4633a7c4 | 5412 | } |
79072805 LW |
5413 | |
5414 | case KEY_system: | |
5415 | set_csh(); | |
a0d0e21e | 5416 | LOP(OP_SYSTEM,XREF); |
79072805 LW |
5417 | |
5418 | case KEY_symlink: | |
a0d0e21e | 5419 | LOP(OP_SYMLINK,XTERM); |
79072805 LW |
5420 | |
5421 | case KEY_syscall: | |
a0d0e21e | 5422 | LOP(OP_SYSCALL,XTERM); |
79072805 | 5423 | |
c07a80fd | 5424 | case KEY_sysopen: |
5425 | LOP(OP_SYSOPEN,XTERM); | |
5426 | ||
137443ea | 5427 | case KEY_sysseek: |
5428 | LOP(OP_SYSSEEK,XTERM); | |
5429 | ||
79072805 | 5430 | case KEY_sysread: |
a0d0e21e | 5431 | LOP(OP_SYSREAD,XTERM); |
79072805 LW |
5432 | |
5433 | case KEY_syswrite: | |
a0d0e21e | 5434 | LOP(OP_SYSWRITE,XTERM); |
79072805 LW |
5435 | |
5436 | case KEY_tr: | |
5437 | s = scan_trans(s); | |
5438 | TERM(sublex_start()); | |
5439 | ||
5440 | case KEY_tell: | |
5441 | UNI(OP_TELL); | |
5442 | ||
5443 | case KEY_telldir: | |
5444 | UNI(OP_TELLDIR); | |
5445 | ||
463ee0b2 | 5446 | case KEY_tie: |
a0d0e21e | 5447 | LOP(OP_TIE,XTERM); |
463ee0b2 | 5448 | |
c07a80fd | 5449 | case KEY_tied: |
5450 | UNI(OP_TIED); | |
5451 | ||
79072805 LW |
5452 | case KEY_time: |
5453 | FUN0(OP_TIME); | |
5454 | ||
5455 | case KEY_times: | |
5456 | FUN0(OP_TMS); | |
5457 | ||
5458 | case KEY_truncate: | |
a0d0e21e | 5459 | LOP(OP_TRUNCATE,XTERM); |
79072805 LW |
5460 | |
5461 | case KEY_uc: | |
5462 | UNI(OP_UC); | |
5463 | ||
5464 | case KEY_ucfirst: | |
5465 | UNI(OP_UCFIRST); | |
5466 | ||
463ee0b2 LW |
5467 | case KEY_untie: |
5468 | UNI(OP_UNTIE); | |
5469 | ||
79072805 | 5470 | case KEY_until: |
57843af0 | 5471 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5472 | OPERATOR(UNTIL); |
5473 | ||
5474 | case KEY_unless: | |
57843af0 | 5475 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5476 | OPERATOR(UNLESS); |
5477 | ||
5478 | case KEY_unlink: | |
a0d0e21e | 5479 | LOP(OP_UNLINK,XTERM); |
79072805 LW |
5480 | |
5481 | case KEY_undef: | |
6f33ba73 | 5482 | UNIDOR(OP_UNDEF); |
79072805 LW |
5483 | |
5484 | case KEY_unpack: | |
a0d0e21e | 5485 | LOP(OP_UNPACK,XTERM); |
79072805 LW |
5486 | |
5487 | case KEY_utime: | |
a0d0e21e | 5488 | LOP(OP_UTIME,XTERM); |
79072805 LW |
5489 | |
5490 | case KEY_umask: | |
6f33ba73 | 5491 | UNIDOR(OP_UMASK); |
79072805 LW |
5492 | |
5493 | case KEY_unshift: | |
a0d0e21e LW |
5494 | LOP(OP_UNSHIFT,XTERM); |
5495 | ||
5496 | case KEY_use: | |
468aa647 | 5497 | s = tokenize_use(1, s); |
a0d0e21e | 5498 | OPERATOR(USE); |
79072805 LW |
5499 | |
5500 | case KEY_values: | |
5501 | UNI(OP_VALUES); | |
5502 | ||
5503 | case KEY_vec: | |
a0d0e21e | 5504 | LOP(OP_VEC,XTERM); |
79072805 LW |
5505 | |
5506 | case KEY_while: | |
57843af0 | 5507 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5508 | OPERATOR(WHILE); |
5509 | ||
5510 | case KEY_warn: | |
3280af22 | 5511 | PL_hints |= HINT_BLOCK_SCOPE; |
a0d0e21e | 5512 | LOP(OP_WARN,XTERM); |
79072805 LW |
5513 | |
5514 | case KEY_wait: | |
5515 | FUN0(OP_WAIT); | |
5516 | ||
5517 | case KEY_waitpid: | |
a0d0e21e | 5518 | LOP(OP_WAITPID,XTERM); |
79072805 LW |
5519 | |
5520 | case KEY_wantarray: | |
5521 | FUN0(OP_WANTARRAY); | |
5522 | ||
5523 | case KEY_write: | |
9d116dd7 JH |
5524 | #ifdef EBCDIC |
5525 | { | |
df3728a2 JH |
5526 | char ctl_l[2]; |
5527 | ctl_l[0] = toCTRL('L'); | |
5528 | ctl_l[1] = '\0'; | |
9d116dd7 JH |
5529 | gv_fetchpv(ctl_l,TRUE, SVt_PV); |
5530 | } | |
5531 | #else | |
5532 | gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */ | |
5533 | #endif | |
79072805 LW |
5534 | UNI(OP_ENTERWRITE); |
5535 | ||
5536 | case KEY_x: | |
3280af22 | 5537 | if (PL_expect == XOPERATOR) |
79072805 LW |
5538 | Mop(OP_REPEAT); |
5539 | check_uni(); | |
5540 | goto just_a_word; | |
5541 | ||
a0d0e21e LW |
5542 | case KEY_xor: |
5543 | yylval.ival = OP_XOR; | |
5544 | OPERATOR(OROP); | |
5545 | ||
79072805 LW |
5546 | case KEY_y: |
5547 | s = scan_trans(s); | |
5548 | TERM(sublex_start()); | |
5549 | } | |
49dc05e3 | 5550 | }} |
79072805 | 5551 | } |
bf4acbe4 GS |
5552 | #ifdef __SC__ |
5553 | #pragma segment Main | |
5554 | #endif | |
79072805 | 5555 | |
e930465f JH |
5556 | static int |
5557 | S_pending_ident(pTHX) | |
8eceec63 SC |
5558 | { |
5559 | register char *d; | |
a55b55d8 | 5560 | register I32 tmp = 0; |
8eceec63 SC |
5561 | /* pit holds the identifier we read and pending_ident is reset */ |
5562 | char pit = PL_pending_ident; | |
5563 | PL_pending_ident = 0; | |
5564 | ||
5565 | DEBUG_T({ PerlIO_printf(Perl_debug_log, | |
b6007c36 | 5566 | "### Pending identifier '%s'\n", PL_tokenbuf); }); |
8eceec63 SC |
5567 | |
5568 | /* if we're in a my(), we can't allow dynamics here. | |
5569 | $foo'bar has already been turned into $foo::bar, so | |
5570 | just check for colons. | |
5571 | ||
5572 | if it's a legal name, the OP is a PADANY. | |
5573 | */ | |
5574 | if (PL_in_my) { | |
5575 | if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */ | |
5576 | if (strchr(PL_tokenbuf,':')) | |
5577 | yyerror(Perl_form(aTHX_ "No package name allowed for " | |
5578 | "variable %s in \"our\"", | |
5579 | PL_tokenbuf)); | |
dd2155a4 | 5580 | tmp = allocmy(PL_tokenbuf); |
8eceec63 SC |
5581 | } |
5582 | else { | |
5583 | if (strchr(PL_tokenbuf,':')) | |
5584 | yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf)); | |
5585 | ||
5586 | yylval.opval = newOP(OP_PADANY, 0); | |
dd2155a4 | 5587 | yylval.opval->op_targ = allocmy(PL_tokenbuf); |
8eceec63 SC |
5588 | return PRIVATEREF; |
5589 | } | |
5590 | } | |
5591 | ||
5592 | /* | |
5593 | build the ops for accesses to a my() variable. | |
5594 | ||
5595 | Deny my($a) or my($b) in a sort block, *if* $a or $b is | |
5596 | then used in a comparison. This catches most, but not | |
5597 | all cases. For instance, it catches | |
5598 | sort { my($a); $a <=> $b } | |
5599 | but not | |
5600 | sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; } | |
5601 | (although why you'd do that is anyone's guess). | |
5602 | */ | |
5603 | ||
5604 | if (!strchr(PL_tokenbuf,':')) { | |
8716503d DM |
5605 | if (!PL_in_my) |
5606 | tmp = pad_findmy(PL_tokenbuf); | |
5607 | if (tmp != NOT_IN_PAD) { | |
8eceec63 | 5608 | /* might be an "our" variable" */ |
dd2155a4 | 5609 | if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) { |
8eceec63 | 5610 | /* build ops for a bareword */ |
b64e5050 AL |
5611 | HV * const stash = PAD_COMPNAME_OURSTASH(tmp); |
5612 | HEK * const stashname = HvNAME_HEK(stash); | |
5613 | SV * const sym = newSVhek(stashname); | |
8eceec63 SC |
5614 | sv_catpvn(sym, "::", 2); |
5615 | sv_catpv(sym, PL_tokenbuf+1); | |
5616 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym); | |
5617 | yylval.opval->op_private = OPpCONST_ENTERED; | |
7a5fd60d | 5618 | gv_fetchsv(sym, |
8eceec63 SC |
5619 | (PL_in_eval |
5620 | ? (GV_ADDMULTI | GV_ADDINEVAL) | |
700078d2 | 5621 | : GV_ADDMULTI |
8eceec63 SC |
5622 | ), |
5623 | ((PL_tokenbuf[0] == '$') ? SVt_PV | |
5624 | : (PL_tokenbuf[0] == '@') ? SVt_PVAV | |
5625 | : SVt_PVHV)); | |
5626 | return WORD; | |
5627 | } | |
5628 | ||
5629 | /* if it's a sort block and they're naming $a or $b */ | |
5630 | if (PL_last_lop_op == OP_SORT && | |
5631 | PL_tokenbuf[0] == '$' && | |
5632 | (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b') | |
5633 | && !PL_tokenbuf[2]) | |
5634 | { | |
5635 | for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart; | |
5636 | d < PL_bufend && *d != '\n'; | |
5637 | d++) | |
5638 | { | |
5639 | if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) { | |
5640 | Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison", | |
5641 | PL_tokenbuf); | |
5642 | } | |
5643 | } | |
5644 | } | |
5645 | ||
5646 | yylval.opval = newOP(OP_PADANY, 0); | |
5647 | yylval.opval->op_targ = tmp; | |
5648 | return PRIVATEREF; | |
5649 | } | |
5650 | } | |
5651 | ||
5652 | /* | |
5653 | Whine if they've said @foo in a doublequoted string, | |
5654 | and @foo isn't a variable we can find in the symbol | |
5655 | table. | |
5656 | */ | |
5657 | if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) { | |
5658 | GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV); | |
5659 | if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv))) | |
5660 | && ckWARN(WARN_AMBIGUOUS)) | |
5661 | { | |
5662 | /* Downgraded from fatal to warning 20000522 mjd */ | |
9014280d | 5663 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
8eceec63 SC |
5664 | "Possible unintended interpolation of %s in string", |
5665 | PL_tokenbuf); | |
5666 | } | |
5667 | } | |
5668 | ||
5669 | /* build ops for a bareword */ | |
5670 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0)); | |
5671 | yylval.opval->op_private = OPpCONST_ENTERED; | |
5672 | gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE, | |
5673 | ((PL_tokenbuf[0] == '$') ? SVt_PV | |
5674 | : (PL_tokenbuf[0] == '@') ? SVt_PVAV | |
5675 | : SVt_PVHV)); | |
5676 | return WORD; | |
5677 | } | |
5678 | ||
4c3bbe0f MHM |
5679 | /* |
5680 | * The following code was generated by perl_keyword.pl. | |
5681 | */ | |
e2e1dd5a | 5682 | |
79072805 | 5683 | I32 |
672994ce | 5684 | Perl_keyword (pTHX_ const char *name, I32 len) |
4c3bbe0f MHM |
5685 | { |
5686 | switch (len) | |
5687 | { | |
5688 | case 1: /* 5 tokens of length 1 */ | |
5689 | switch (name[0]) | |
e2e1dd5a | 5690 | { |
4c3bbe0f MHM |
5691 | case 'm': |
5692 | { /* m */ | |
5693 | return KEY_m; | |
5694 | } | |
5695 | ||
4c3bbe0f MHM |
5696 | case 'q': |
5697 | { /* q */ | |
5698 | return KEY_q; | |
5699 | } | |
5700 | ||
4c3bbe0f MHM |
5701 | case 's': |
5702 | { /* s */ | |
5703 | return KEY_s; | |
5704 | } | |
5705 | ||
4c3bbe0f MHM |
5706 | case 'x': |
5707 | { /* x */ | |
5708 | return -KEY_x; | |
5709 | } | |
5710 | ||
4c3bbe0f MHM |
5711 | case 'y': |
5712 | { /* y */ | |
5713 | return KEY_y; | |
5714 | } | |
5715 | ||
4c3bbe0f MHM |
5716 | default: |
5717 | goto unknown; | |
e2e1dd5a | 5718 | } |
4c3bbe0f MHM |
5719 | |
5720 | case 2: /* 18 tokens of length 2 */ | |
5721 | switch (name[0]) | |
e2e1dd5a | 5722 | { |
4c3bbe0f MHM |
5723 | case 'd': |
5724 | if (name[1] == 'o') | |
5725 | { /* do */ | |
5726 | return KEY_do; | |
5727 | } | |
5728 | ||
5729 | goto unknown; | |
5730 | ||
5731 | case 'e': | |
5732 | if (name[1] == 'q') | |
5733 | { /* eq */ | |
5734 | return -KEY_eq; | |
5735 | } | |
5736 | ||
5737 | goto unknown; | |
5738 | ||
5739 | case 'g': | |
5740 | switch (name[1]) | |
5741 | { | |
5742 | case 'e': | |
5743 | { /* ge */ | |
5744 | return -KEY_ge; | |
5745 | } | |
5746 | ||
4c3bbe0f MHM |
5747 | case 't': |
5748 | { /* gt */ | |
5749 | return -KEY_gt; | |
5750 | } | |
5751 | ||
4c3bbe0f MHM |
5752 | default: |
5753 | goto unknown; | |
5754 | } | |
5755 | ||
5756 | case 'i': | |
5757 | if (name[1] == 'f') | |
5758 | { /* if */ | |
5759 | return KEY_if; | |
5760 | } | |
5761 | ||
5762 | goto unknown; | |
5763 | ||
5764 | case 'l': | |
5765 | switch (name[1]) | |
5766 | { | |
5767 | case 'c': | |
5768 | { /* lc */ | |
5769 | return -KEY_lc; | |
5770 | } | |
5771 | ||
4c3bbe0f MHM |
5772 | case 'e': |
5773 | { /* le */ | |
5774 | return -KEY_le; | |
5775 | } | |
5776 | ||
4c3bbe0f MHM |
5777 | case 't': |
5778 | { /* lt */ | |
5779 | return -KEY_lt; | |
5780 | } | |
5781 | ||
4c3bbe0f MHM |
5782 | default: |
5783 | goto unknown; | |
5784 | } | |
5785 | ||
5786 | case 'm': | |
5787 | if (name[1] == 'y') | |
5788 | { /* my */ | |
5789 | return KEY_my; | |
5790 | } | |
5791 | ||
5792 | goto unknown; | |
5793 | ||
5794 | case 'n': | |
5795 | switch (name[1]) | |
5796 | { | |
5797 | case 'e': | |
5798 | { /* ne */ | |
5799 | return -KEY_ne; | |
5800 | } | |
5801 | ||
4c3bbe0f MHM |
5802 | case 'o': |
5803 | { /* no */ | |
5804 | return KEY_no; | |
5805 | } | |
5806 | ||
4c3bbe0f MHM |
5807 | default: |
5808 | goto unknown; | |
5809 | } | |
5810 | ||
5811 | case 'o': | |
5812 | if (name[1] == 'r') | |
5813 | { /* or */ | |
5814 | return -KEY_or; | |
5815 | } | |
5816 | ||
5817 | goto unknown; | |
5818 | ||
5819 | case 'q': | |
5820 | switch (name[1]) | |
5821 | { | |
5822 | case 'q': | |
5823 | { /* qq */ | |
5824 | return KEY_qq; | |
5825 | } | |
5826 | ||
4c3bbe0f MHM |
5827 | case 'r': |
5828 | { /* qr */ | |
5829 | return KEY_qr; | |
5830 | } | |
5831 | ||
4c3bbe0f MHM |
5832 | case 'w': |
5833 | { /* qw */ | |
5834 | return KEY_qw; | |
5835 | } | |
5836 | ||
4c3bbe0f MHM |
5837 | case 'x': |
5838 | { /* qx */ | |
5839 | return KEY_qx; | |
5840 | } | |
5841 | ||
4c3bbe0f MHM |
5842 | default: |
5843 | goto unknown; | |
5844 | } | |
5845 | ||
5846 | case 't': | |
5847 | if (name[1] == 'r') | |
5848 | { /* tr */ | |
5849 | return KEY_tr; | |
5850 | } | |
5851 | ||
5852 | goto unknown; | |
5853 | ||
5854 | case 'u': | |
5855 | if (name[1] == 'c') | |
5856 | { /* uc */ | |
5857 | return -KEY_uc; | |
5858 | } | |
5859 | ||
5860 | goto unknown; | |
5861 | ||
5862 | default: | |
5863 | goto unknown; | |
e2e1dd5a | 5864 | } |
4c3bbe0f MHM |
5865 | |
5866 | case 3: /* 28 tokens of length 3 */ | |
5867 | switch (name[0]) | |
e2e1dd5a | 5868 | { |
4c3bbe0f MHM |
5869 | case 'E': |
5870 | if (name[1] == 'N' && | |
5871 | name[2] == 'D') | |
5872 | { /* END */ | |
5873 | return KEY_END; | |
5874 | } | |
5875 | ||
5876 | goto unknown; | |
5877 | ||
5878 | case 'a': | |
5879 | switch (name[1]) | |
5880 | { | |
5881 | case 'b': | |
5882 | if (name[2] == 's') | |
5883 | { /* abs */ | |
5884 | return -KEY_abs; | |
5885 | } | |
5886 | ||
5887 | goto unknown; | |
5888 | ||
5889 | case 'n': | |
5890 | if (name[2] == 'd') | |
5891 | { /* and */ | |
5892 | return -KEY_and; | |
5893 | } | |
5894 | ||
5895 | goto unknown; | |
5896 | ||
5897 | default: | |
5898 | goto unknown; | |
5899 | } | |
5900 | ||
5901 | case 'c': | |
5902 | switch (name[1]) | |
5903 | { | |
5904 | case 'h': | |
5905 | if (name[2] == 'r') | |
5906 | { /* chr */ | |
5907 | return -KEY_chr; | |
5908 | } | |
5909 | ||
5910 | goto unknown; | |
5911 | ||
5912 | case 'm': | |
5913 | if (name[2] == 'p') | |
5914 | { /* cmp */ | |
5915 | return -KEY_cmp; | |
5916 | } | |
5917 | ||
5918 | goto unknown; | |
5919 | ||
5920 | case 'o': | |
5921 | if (name[2] == 's') | |
5922 | { /* cos */ | |
5923 | return -KEY_cos; | |
5924 | } | |
5925 | ||
5926 | goto unknown; | |
5927 | ||
5928 | default: | |
5929 | goto unknown; | |
5930 | } | |
5931 | ||
5932 | case 'd': | |
5933 | if (name[1] == 'i' && | |
5934 | name[2] == 'e') | |
5935 | { /* die */ | |
5936 | return -KEY_die; | |
5937 | } | |
5938 | ||
5939 | goto unknown; | |
5940 | ||
5941 | case 'e': | |
5942 | switch (name[1]) | |
5943 | { | |
5944 | case 'o': | |
5945 | if (name[2] == 'f') | |
5946 | { /* eof */ | |
5947 | return -KEY_eof; | |
5948 | } | |
5949 | ||
5950 | goto unknown; | |
5951 | ||
5952 | case 'r': | |
5953 | if (name[2] == 'r') | |
5954 | { /* err */ | |
5955 | return -KEY_err; | |
5956 | } | |
5957 | ||
5958 | goto unknown; | |
5959 | ||
5960 | case 'x': | |
5961 | if (name[2] == 'p') | |
5962 | { /* exp */ | |
5963 | return -KEY_exp; | |
5964 | } | |
5965 | ||
5966 | goto unknown; | |
5967 | ||
5968 | default: | |
5969 | goto unknown; | |
5970 | } | |
5971 | ||
5972 | case 'f': | |
5973 | if (name[1] == 'o' && | |
5974 | name[2] == 'r') | |
5975 | { /* for */ | |
5976 | return KEY_for; | |
5977 | } | |
5978 | ||
5979 | goto unknown; | |
5980 | ||
5981 | case 'h': | |
5982 | if (name[1] == 'e' && | |
5983 | name[2] == 'x') | |
5984 | { /* hex */ | |
5985 | return -KEY_hex; | |
5986 | } | |
5987 | ||
5988 | goto unknown; | |
5989 | ||
5990 | case 'i': | |
5991 | if (name[1] == 'n' && | |
5992 | name[2] == 't') | |
5993 | { /* int */ | |
5994 | return -KEY_int; | |
5995 | } | |
5996 | ||
5997 | goto unknown; | |
5998 | ||
5999 | case 'l': | |
6000 | if (name[1] == 'o' && | |
6001 | name[2] == 'g') | |
6002 | { /* log */ | |
6003 | return -KEY_log; | |
6004 | } | |
6005 | ||
6006 | goto unknown; | |
6007 | ||
6008 | case 'm': | |
6009 | if (name[1] == 'a' && | |
6010 | name[2] == 'p') | |
6011 | { /* map */ | |
6012 | return KEY_map; | |
6013 | } | |
6014 | ||
6015 | goto unknown; | |
6016 | ||
6017 | case 'n': | |
6018 | if (name[1] == 'o' && | |
6019 | name[2] == 't') | |
6020 | { /* not */ | |
6021 | return -KEY_not; | |
6022 | } | |
6023 | ||
6024 | goto unknown; | |
6025 | ||
6026 | case 'o': | |
6027 | switch (name[1]) | |
6028 | { | |
6029 | case 'c': | |
6030 | if (name[2] == 't') | |
6031 | { /* oct */ | |
6032 | return -KEY_oct; | |
6033 | } | |
6034 | ||
6035 | goto unknown; | |
6036 | ||
6037 | case 'r': | |
6038 | if (name[2] == 'd') | |
6039 | { /* ord */ | |
6040 | return -KEY_ord; | |
6041 | } | |
6042 | ||
6043 | goto unknown; | |
6044 | ||
6045 | case 'u': | |
6046 | if (name[2] == 'r') | |
6047 | { /* our */ | |
6048 | return KEY_our; | |
6049 | } | |
6050 | ||
6051 | goto unknown; | |
6052 | ||
6053 | default: | |
6054 | goto unknown; | |
6055 | } | |
6056 | ||
6057 | case 'p': | |
6058 | if (name[1] == 'o') | |
6059 | { | |
6060 | switch (name[2]) | |
6061 | { | |
6062 | case 'p': | |
6063 | { /* pop */ | |
6064 | return -KEY_pop; | |
6065 | } | |
6066 | ||
4c3bbe0f MHM |
6067 | case 's': |
6068 | { /* pos */ | |
6069 | return KEY_pos; | |
6070 | } | |
6071 | ||
4c3bbe0f MHM |
6072 | default: |
6073 | goto unknown; | |
6074 | } | |
6075 | } | |
6076 | ||
6077 | goto unknown; | |
6078 | ||
6079 | case 'r': | |
6080 | if (name[1] == 'e' && | |
6081 | name[2] == 'f') | |
6082 | { /* ref */ | |
6083 | return -KEY_ref; | |
6084 | } | |
6085 | ||
6086 | goto unknown; | |
6087 | ||
6088 | case 's': | |
6089 | switch (name[1]) | |
6090 | { | |
6091 | case 'i': | |
6092 | if (name[2] == 'n') | |
6093 | { /* sin */ | |
6094 | return -KEY_sin; | |
6095 | } | |
6096 | ||
6097 | goto unknown; | |
6098 | ||
6099 | case 'u': | |
6100 | if (name[2] == 'b') | |
6101 | { /* sub */ | |
6102 | return KEY_sub; | |
6103 | } | |
6104 | ||
6105 | goto unknown; | |
6106 | ||
6107 | default: | |
6108 | goto unknown; | |
6109 | } | |
6110 | ||
6111 | case 't': | |
6112 | if (name[1] == 'i' && | |
6113 | name[2] == 'e') | |
6114 | { /* tie */ | |
6115 | return KEY_tie; | |
6116 | } | |
6117 | ||
6118 | goto unknown; | |
6119 | ||
6120 | case 'u': | |
6121 | if (name[1] == 's' && | |
6122 | name[2] == 'e') | |
6123 | { /* use */ | |
6124 | return KEY_use; | |
6125 | } | |
6126 | ||
6127 | goto unknown; | |
6128 | ||
6129 | case 'v': | |
6130 | if (name[1] == 'e' && | |
6131 | name[2] == 'c') | |
6132 | { /* vec */ | |
6133 | return -KEY_vec; | |
6134 | } | |
6135 | ||
6136 | goto unknown; | |
6137 | ||
6138 | case 'x': | |
6139 | if (name[1] == 'o' && | |
6140 | name[2] == 'r') | |
6141 | { /* xor */ | |
6142 | return -KEY_xor; | |
6143 | } | |
6144 | ||
6145 | goto unknown; | |
6146 | ||
6147 | default: | |
6148 | goto unknown; | |
e2e1dd5a | 6149 | } |
4c3bbe0f MHM |
6150 | |
6151 | case 4: /* 40 tokens of length 4 */ | |
6152 | switch (name[0]) | |
e2e1dd5a | 6153 | { |
4c3bbe0f MHM |
6154 | case 'C': |
6155 | if (name[1] == 'O' && | |
6156 | name[2] == 'R' && | |
6157 | name[3] == 'E') | |
6158 | { /* CORE */ | |
6159 | return -KEY_CORE; | |
6160 | } | |
6161 | ||
6162 | goto unknown; | |
6163 | ||
6164 | case 'I': | |
6165 | if (name[1] == 'N' && | |
6166 | name[2] == 'I' && | |
6167 | name[3] == 'T') | |
6168 | { /* INIT */ | |
6169 | return KEY_INIT; | |
6170 | } | |
6171 | ||
6172 | goto unknown; | |
6173 | ||
6174 | case 'b': | |
6175 | if (name[1] == 'i' && | |
6176 | name[2] == 'n' && | |
6177 | name[3] == 'd') | |
6178 | { /* bind */ | |
6179 | return -KEY_bind; | |
6180 | } | |
6181 | ||
6182 | goto unknown; | |
6183 | ||
6184 | case 'c': | |
6185 | if (name[1] == 'h' && | |
6186 | name[2] == 'o' && | |
6187 | name[3] == 'p') | |
6188 | { /* chop */ | |
6189 | return -KEY_chop; | |
6190 | } | |
6191 | ||
6192 | goto unknown; | |
6193 | ||
6194 | case 'd': | |
6195 | if (name[1] == 'u' && | |
6196 | name[2] == 'm' && | |
6197 | name[3] == 'p') | |
6198 | { /* dump */ | |
6199 | return -KEY_dump; | |
6200 | } | |
6201 | ||
6202 | goto unknown; | |
6203 | ||
6204 | case 'e': | |
6205 | switch (name[1]) | |
6206 | { | |
6207 | case 'a': | |
6208 | if (name[2] == 'c' && | |
6209 | name[3] == 'h') | |
6210 | { /* each */ | |
6211 | return -KEY_each; | |
6212 | } | |
6213 | ||
6214 | goto unknown; | |
6215 | ||
6216 | case 'l': | |
6217 | if (name[2] == 's' && | |
6218 | name[3] == 'e') | |
6219 | { /* else */ | |
6220 | return KEY_else; | |
6221 | } | |
6222 | ||
6223 | goto unknown; | |
6224 | ||
6225 | case 'v': | |
6226 | if (name[2] == 'a' && | |
6227 | name[3] == 'l') | |
6228 | { /* eval */ | |
6229 | return KEY_eval; | |
6230 | } | |
6231 | ||
6232 | goto unknown; | |
6233 | ||
6234 | case 'x': | |
6235 | switch (name[2]) | |
6236 | { | |
6237 | case 'e': | |
6238 | if (name[3] == 'c') | |
6239 | { /* exec */ | |
6240 | return -KEY_exec; | |
6241 | } | |
6242 | ||
6243 | goto unknown; | |
6244 | ||
6245 | case 'i': | |
6246 | if (name[3] == 't') | |
6247 | { /* exit */ | |
6248 | return -KEY_exit; | |
6249 | } | |
6250 | ||
6251 | goto unknown; | |
6252 | ||
6253 | default: | |
6254 | goto unknown; | |
6255 | } | |
6256 | ||
6257 | default: | |
6258 | goto unknown; | |
6259 | } | |
6260 | ||
6261 | case 'f': | |
6262 | if (name[1] == 'o' && | |
6263 | name[2] == 'r' && | |
6264 | name[3] == 'k') | |
6265 | { /* fork */ | |
6266 | return -KEY_fork; | |
6267 | } | |
6268 | ||
6269 | goto unknown; | |
6270 | ||
6271 | case 'g': | |
6272 | switch (name[1]) | |
6273 | { | |
6274 | case 'e': | |
6275 | if (name[2] == 't' && | |
6276 | name[3] == 'c') | |
6277 | { /* getc */ | |
6278 | return -KEY_getc; | |
6279 | } | |
6280 | ||
6281 | goto unknown; | |
6282 | ||
6283 | case 'l': | |
6284 | if (name[2] == 'o' && | |
6285 | name[3] == 'b') | |
6286 | { /* glob */ | |
6287 | return KEY_glob; | |
6288 | } | |
6289 | ||
6290 | goto unknown; | |
6291 | ||
6292 | case 'o': | |
6293 | if (name[2] == 't' && | |
6294 | name[3] == 'o') | |
6295 | { /* goto */ | |
6296 | return KEY_goto; | |
6297 | } | |
6298 | ||
6299 | goto unknown; | |
6300 | ||
6301 | case 'r': | |
6302 | if (name[2] == 'e' && | |
6303 | name[3] == 'p') | |
6304 | { /* grep */ | |
6305 | return KEY_grep; | |
6306 | } | |
6307 | ||
6308 | goto unknown; | |
6309 | ||
6310 | default: | |
6311 | goto unknown; | |
6312 | } | |
6313 | ||
6314 | case 'j': | |
6315 | if (name[1] == 'o' && | |
6316 | name[2] == 'i' && | |
6317 | name[3] == 'n') | |
6318 | { /* join */ | |
6319 | return -KEY_join; | |
6320 | } | |
6321 | ||
6322 | goto unknown; | |
6323 | ||
6324 | case 'k': | |
6325 | switch (name[1]) | |
6326 | { | |
6327 | case 'e': | |
6328 | if (name[2] == 'y' && | |
6329 | name[3] == 's') | |
6330 | { /* keys */ | |
6331 | return -KEY_keys; | |
6332 | } | |
6333 | ||
6334 | goto unknown; | |
6335 | ||
6336 | case 'i': | |
6337 | if (name[2] == 'l' && | |
6338 | name[3] == 'l') | |
6339 | { /* kill */ | |
6340 | return -KEY_kill; | |
6341 | } | |
6342 | ||
6343 | goto unknown; | |
6344 | ||
6345 | default: | |
6346 | goto unknown; | |
6347 | } | |
6348 | ||
6349 | case 'l': | |
6350 | switch (name[1]) | |
6351 | { | |
6352 | case 'a': | |
6353 | if (name[2] == 's' && | |
6354 | name[3] == 't') | |
6355 | { /* last */ | |
6356 | return KEY_last; | |
6357 | } | |
6358 | ||
6359 | goto unknown; | |
6360 | ||
6361 | case 'i': | |
6362 | if (name[2] == 'n' && | |
6363 | name[3] == 'k') | |
6364 | { /* link */ | |
6365 | return -KEY_link; | |
6366 | } | |
6367 | ||
6368 | goto unknown; | |
6369 | ||
6370 | case 'o': | |
6371 | if (name[2] == 'c' && | |
6372 | name[3] == 'k') | |
6373 | { /* lock */ | |
6374 | return -KEY_lock; | |
6375 | } | |
6376 | ||
6377 | goto unknown; | |
6378 | ||
6379 | default: | |
6380 | goto unknown; | |
6381 | } | |
6382 | ||
6383 | case 'n': | |
6384 | if (name[1] == 'e' && | |
6385 | name[2] == 'x' && | |
6386 | name[3] == 't') | |
6387 | { /* next */ | |
6388 | return KEY_next; | |
6389 | } | |
6390 | ||
6391 | goto unknown; | |
6392 | ||
6393 | case 'o': | |
6394 | if (name[1] == 'p' && | |
6395 | name[2] == 'e' && | |
6396 | name[3] == 'n') | |
6397 | { /* open */ | |
6398 | return -KEY_open; | |
6399 | } | |
6400 | ||
6401 | goto unknown; | |
6402 | ||
6403 | case 'p': | |
6404 | switch (name[1]) | |
6405 | { | |
6406 | case 'a': | |
6407 | if (name[2] == 'c' && | |
6408 | name[3] == 'k') | |
6409 | { /* pack */ | |
6410 | return -KEY_pack; | |
6411 | } | |
6412 | ||
6413 | goto unknown; | |
6414 | ||
6415 | case 'i': | |
6416 | if (name[2] == 'p' && | |
6417 | name[3] == 'e') | |
6418 | { /* pipe */ | |
6419 | return -KEY_pipe; | |
6420 | } | |
6421 | ||
6422 | goto unknown; | |
6423 | ||
6424 | case 'u': | |
6425 | if (name[2] == 's' && | |
6426 | name[3] == 'h') | |
6427 | { /* push */ | |
6428 | return -KEY_push; | |
6429 | } | |
6430 | ||
6431 | goto unknown; | |
6432 | ||
6433 | default: | |
6434 | goto unknown; | |
6435 | } | |
6436 | ||
6437 | case 'r': | |
6438 | switch (name[1]) | |
6439 | { | |
6440 | case 'a': | |
6441 | if (name[2] == 'n' && | |
6442 | name[3] == 'd') | |
6443 | { /* rand */ | |
6444 | return -KEY_rand; | |
6445 | } | |
6446 | ||
6447 | goto unknown; | |
6448 | ||
6449 | case 'e': | |
6450 | switch (name[2]) | |
6451 | { | |
6452 | case 'a': | |
6453 | if (name[3] == 'd') | |
6454 | { /* read */ | |
6455 | return -KEY_read; | |
6456 | } | |
6457 | ||
6458 | goto unknown; | |
6459 | ||
6460 | case 'c': | |
6461 | if (name[3] == 'v') | |
6462 | { /* recv */ | |
6463 | return -KEY_recv; | |
6464 | } | |
6465 | ||
6466 | goto unknown; | |
6467 | ||
6468 | case 'd': | |
6469 | if (name[3] == 'o') | |
6470 | { /* redo */ | |
6471 | return KEY_redo; | |
6472 | } | |
6473 | ||
6474 | goto unknown; | |
6475 | ||
6476 | default: | |
6477 | goto unknown; | |
6478 | } | |
6479 | ||
6480 | default: | |
6481 | goto unknown; | |
6482 | } | |
6483 | ||
6484 | case 's': | |
6485 | switch (name[1]) | |
6486 | { | |
6487 | case 'e': | |
6488 | switch (name[2]) | |
6489 | { | |
6490 | case 'e': | |
6491 | if (name[3] == 'k') | |
6492 | { /* seek */ | |
6493 | return -KEY_seek; | |
6494 | } | |
6495 | ||
6496 | goto unknown; | |
6497 | ||
6498 | case 'n': | |
6499 | if (name[3] == 'd') | |
6500 | { /* send */ | |
6501 | return -KEY_send; | |
6502 | } | |
6503 | ||
6504 | goto unknown; | |
6505 | ||
6506 | default: | |
6507 | goto unknown; | |
6508 | } | |
6509 | ||
6510 | case 'o': | |
6511 | if (name[2] == 'r' && | |
6512 | name[3] == 't') | |
6513 | { /* sort */ | |
6514 | return KEY_sort; | |
6515 | } | |
6516 | ||
6517 | goto unknown; | |
6518 | ||
6519 | case 'q': | |
6520 | if (name[2] == 'r' && | |
6521 | name[3] == 't') | |
6522 | { /* sqrt */ | |
6523 | return -KEY_sqrt; | |
6524 | } | |
6525 | ||
6526 | goto unknown; | |
6527 | ||
6528 | case 't': | |
6529 | if (name[2] == 'a' && | |
6530 | name[3] == 't') | |
6531 | { /* stat */ | |
6532 | return -KEY_stat; | |
6533 | } | |
6534 | ||
6535 | goto unknown; | |
6536 | ||
6537 | default: | |
6538 | goto unknown; | |
6539 | } | |
6540 | ||
6541 | case 't': | |
6542 | switch (name[1]) | |
6543 | { | |
6544 | case 'e': | |
6545 | if (name[2] == 'l' && | |
6546 | name[3] == 'l') | |
6547 | { /* tell */ | |
6548 | return -KEY_tell; | |
6549 | } | |
6550 | ||
6551 | goto unknown; | |
6552 | ||
6553 | case 'i': | |
6554 | switch (name[2]) | |
6555 | { | |
6556 | case 'e': | |
6557 | if (name[3] == 'd') | |
6558 | { /* tied */ | |
6559 | return KEY_tied; | |
6560 | } | |
6561 | ||
6562 | goto unknown; | |
6563 | ||
6564 | case 'm': | |
6565 | if (name[3] == 'e') | |
6566 | { /* time */ | |
6567 | return -KEY_time; | |
6568 | } | |
6569 | ||
6570 | goto unknown; | |
6571 | ||
6572 | default: | |
6573 | goto unknown; | |
6574 | } | |
6575 | ||
6576 | default: | |
6577 | goto unknown; | |
6578 | } | |
6579 | ||
6580 | case 'w': | |
6581 | if (name[1] == 'a') | |
6582 | { | |
6583 | switch (name[2]) | |
6584 | { | |
6585 | case 'i': | |
6586 | if (name[3] == 't') | |
6587 | { /* wait */ | |
6588 | return -KEY_wait; | |
6589 | } | |
6590 | ||
6591 | goto unknown; | |
6592 | ||
6593 | case 'r': | |
6594 | if (name[3] == 'n') | |
6595 | { /* warn */ | |
6596 | return -KEY_warn; | |
6597 | } | |
6598 | ||
6599 | goto unknown; | |
6600 | ||
6601 | default: | |
6602 | goto unknown; | |
6603 | } | |
6604 | } | |
6605 | ||
6606 | goto unknown; | |
6607 | ||
6608 | default: | |
6609 | goto unknown; | |
e2e1dd5a | 6610 | } |
4c3bbe0f MHM |
6611 | |
6612 | case 5: /* 36 tokens of length 5 */ | |
6613 | switch (name[0]) | |
e2e1dd5a | 6614 | { |
4c3bbe0f MHM |
6615 | case 'B': |
6616 | if (name[1] == 'E' && | |
6617 | name[2] == 'G' && | |
6618 | name[3] == 'I' && | |
6619 | name[4] == 'N') | |
6620 | { /* BEGIN */ | |
6621 | return KEY_BEGIN; | |
6622 | } | |
6623 | ||
6624 | goto unknown; | |
6625 | ||
6626 | case 'C': | |
6627 | if (name[1] == 'H' && | |
6628 | name[2] == 'E' && | |
6629 | name[3] == 'C' && | |
6630 | name[4] == 'K') | |
6631 | { /* CHECK */ | |
6632 | return KEY_CHECK; | |
6633 | } | |
6634 | ||
6635 | goto unknown; | |
6636 | ||
6637 | case 'a': | |
6638 | switch (name[1]) | |
6639 | { | |
6640 | case 'l': | |
6641 | if (name[2] == 'a' && | |
6642 | name[3] == 'r' && | |
6643 | name[4] == 'm') | |
6644 | { /* alarm */ | |
6645 | return -KEY_alarm; | |
6646 | } | |
6647 | ||
6648 | goto unknown; | |
6649 | ||
6650 | case 't': | |
6651 | if (name[2] == 'a' && | |
6652 | name[3] == 'n' && | |
6653 | name[4] == '2') | |
6654 | { /* atan2 */ | |
6655 | return -KEY_atan2; | |
6656 | } | |
6657 | ||
6658 | goto unknown; | |
6659 | ||
6660 | default: | |
6661 | goto unknown; | |
6662 | } | |
6663 | ||
6664 | case 'b': | |
6665 | if (name[1] == 'l' && | |
6666 | name[2] == 'e' && | |
6667 | name[3] == 's' && | |
6668 | name[4] == 's') | |
6669 | { /* bless */ | |
6670 | return -KEY_bless; | |
6671 | } | |
6672 | ||
6673 | goto unknown; | |
6674 | ||
6675 | case 'c': | |
6676 | switch (name[1]) | |
6677 | { | |
6678 | case 'h': | |
6679 | switch (name[2]) | |
6680 | { | |
6681 | case 'd': | |
6682 | if (name[3] == 'i' && | |
6683 | name[4] == 'r') | |
6684 | { /* chdir */ | |
6685 | return -KEY_chdir; | |
6686 | } | |
6687 | ||
6688 | goto unknown; | |
6689 | ||
6690 | case 'm': | |
6691 | if (name[3] == 'o' && | |
6692 | name[4] == 'd') | |
6693 | { /* chmod */ | |
6694 | return -KEY_chmod; | |
6695 | } | |
6696 | ||
6697 | goto unknown; | |
6698 | ||
6699 | case 'o': | |
6700 | switch (name[3]) | |
6701 | { | |
6702 | case 'm': | |
6703 | if (name[4] == 'p') | |
6704 | { /* chomp */ | |
6705 | return -KEY_chomp; | |
6706 | } | |
6707 | ||
6708 | goto unknown; | |
6709 | ||
6710 | case 'w': | |
6711 | if (name[4] == 'n') | |
6712 | { /* chown */ | |
6713 | return -KEY_chown; | |
6714 | } | |
6715 | ||
6716 | goto unknown; | |
6717 | ||
6718 | default: | |
6719 | goto unknown; | |
6720 | } | |
6721 | ||
6722 | default: | |
6723 | goto unknown; | |
6724 | } | |
6725 | ||
6726 | case 'l': | |
6727 | if (name[2] == 'o' && | |
6728 | name[3] == 's' && | |
6729 | name[4] == 'e') | |
6730 | { /* close */ | |
6731 | return -KEY_close; | |
6732 | } | |
6733 | ||
6734 | goto unknown; | |
6735 | ||
6736 | case 'r': | |
6737 | if (name[2] == 'y' && | |
6738 | name[3] == 'p' && | |
6739 | name[4] == 't') | |
6740 | { /* crypt */ | |
6741 | return -KEY_crypt; | |
6742 | } | |
6743 | ||
6744 | goto unknown; | |
6745 | ||
6746 | default: | |
6747 | goto unknown; | |
6748 | } | |
6749 | ||
6750 | case 'e': | |
6751 | if (name[1] == 'l' && | |
6752 | name[2] == 's' && | |
6753 | name[3] == 'i' && | |
6754 | name[4] == 'f') | |
6755 | { /* elsif */ | |
6756 | return KEY_elsif; | |
6757 | } | |
6758 | ||
6759 | goto unknown; | |
6760 | ||
6761 | case 'f': | |
6762 | switch (name[1]) | |
6763 | { | |
6764 | case 'c': | |
6765 | if (name[2] == 'n' && | |
6766 | name[3] == 't' && | |
6767 | name[4] == 'l') | |
6768 | { /* fcntl */ | |
6769 | return -KEY_fcntl; | |
6770 | } | |
6771 | ||
6772 | goto unknown; | |
6773 | ||
6774 | case 'l': | |
6775 | if (name[2] == 'o' && | |
6776 | name[3] == 'c' && | |
6777 | name[4] == 'k') | |
6778 | { /* flock */ | |
6779 | return -KEY_flock; | |
6780 | } | |
6781 | ||
6782 | goto unknown; | |
6783 | ||
6784 | default: | |
6785 | goto unknown; | |
6786 | } | |
6787 | ||
6788 | case 'i': | |
6789 | switch (name[1]) | |
6790 | { | |
6791 | case 'n': | |
6792 | if (name[2] == 'd' && | |
6793 | name[3] == 'e' && | |
6794 | name[4] == 'x') | |
6795 | { /* index */ | |
6796 | return -KEY_index; | |
6797 | } | |
6798 | ||
6799 | goto unknown; | |
6800 | ||
6801 | case 'o': | |
6802 | if (name[2] == 'c' && | |
6803 | name[3] == 't' && | |
6804 | name[4] == 'l') | |
6805 | { /* ioctl */ | |
6806 | return -KEY_ioctl; | |
6807 | } | |
6808 | ||
6809 | goto unknown; | |
6810 | ||
6811 | default: | |
6812 | goto unknown; | |
6813 | } | |
6814 | ||
6815 | case 'l': | |
6816 | switch (name[1]) | |
6817 | { | |
6818 | case 'o': | |
6819 | if (name[2] == 'c' && | |
6820 | name[3] == 'a' && | |
6821 | name[4] == 'l') | |
6822 | { /* local */ | |
6823 | return KEY_local; | |
6824 | } | |
6825 | ||
6826 | goto unknown; | |
6827 | ||
6828 | case 's': | |
6829 | if (name[2] == 't' && | |
6830 | name[3] == 'a' && | |
6831 | name[4] == 't') | |
6832 | { /* lstat */ | |
6833 | return -KEY_lstat; | |
6834 | } | |
6835 | ||
6836 | goto unknown; | |
6837 | ||
6838 | default: | |
6839 | goto unknown; | |
6840 | } | |
6841 | ||
6842 | case 'm': | |
6843 | if (name[1] == 'k' && | |
6844 | name[2] == 'd' && | |
6845 | name[3] == 'i' && | |
6846 | name[4] == 'r') | |
6847 | { /* mkdir */ | |
6848 | return -KEY_mkdir; | |
6849 | } | |
6850 | ||
6851 | goto unknown; | |
6852 | ||
6853 | case 'p': | |
6854 | if (name[1] == 'r' && | |
6855 | name[2] == 'i' && | |
6856 | name[3] == 'n' && | |
6857 | name[4] == 't') | |
6858 | { /* print */ | |
6859 | return KEY_print; | |
6860 | } | |
6861 | ||
6862 | goto unknown; | |
6863 | ||
6864 | case 'r': | |
6865 | switch (name[1]) | |
6866 | { | |
6867 | case 'e': | |
6868 | if (name[2] == 's' && | |
6869 | name[3] == 'e' && | |
6870 | name[4] == 't') | |
6871 | { /* reset */ | |
6872 | return -KEY_reset; | |
6873 | } | |
6874 | ||
6875 | goto unknown; | |
6876 | ||
6877 | case 'm': | |
6878 | if (name[2] == 'd' && | |
6879 | name[3] == 'i' && | |
6880 | name[4] == 'r') | |
6881 | { /* rmdir */ | |
6882 | return -KEY_rmdir; | |
6883 | } | |
6884 | ||
6885 | goto unknown; | |
6886 | ||
6887 | default: | |
6888 | goto unknown; | |
6889 | } | |
6890 | ||
6891 | case 's': | |
6892 | switch (name[1]) | |
6893 | { | |
6894 | case 'e': | |
6895 | if (name[2] == 'm' && | |
6896 | name[3] == 'o' && | |
6897 | name[4] == 'p') | |
6898 | { /* semop */ | |
6899 | return -KEY_semop; | |
6900 | } | |
6901 | ||
6902 | goto unknown; | |
6903 | ||
6904 | case 'h': | |
6905 | if (name[2] == 'i' && | |
6906 | name[3] == 'f' && | |
6907 | name[4] == 't') | |
6908 | { /* shift */ | |
6909 | return -KEY_shift; | |
6910 | } | |
6911 | ||
6912 | goto unknown; | |
6913 | ||
6914 | case 'l': | |
6915 | if (name[2] == 'e' && | |
6916 | name[3] == 'e' && | |
6917 | name[4] == 'p') | |
6918 | { /* sleep */ | |
6919 | return -KEY_sleep; | |
6920 | } | |
6921 | ||
6922 | goto unknown; | |
6923 | ||
6924 | case 'p': | |
6925 | if (name[2] == 'l' && | |
6926 | name[3] == 'i' && | |
6927 | name[4] == 't') | |
6928 | { /* split */ | |
6929 | return KEY_split; | |
6930 | } | |
6931 | ||
6932 | goto unknown; | |
6933 | ||
6934 | case 'r': | |
6935 | if (name[2] == 'a' && | |
6936 | name[3] == 'n' && | |
6937 | name[4] == 'd') | |
6938 | { /* srand */ | |
6939 | return -KEY_srand; | |
6940 | } | |
6941 | ||
6942 | goto unknown; | |
6943 | ||
6944 | case 't': | |
6945 | if (name[2] == 'u' && | |
6946 | name[3] == 'd' && | |
6947 | name[4] == 'y') | |
6948 | { /* study */ | |
6949 | return KEY_study; | |
6950 | } | |
6951 | ||
6952 | goto unknown; | |
6953 | ||
6954 | default: | |
6955 | goto unknown; | |
6956 | } | |
6957 | ||
6958 | case 't': | |
6959 | if (name[1] == 'i' && | |
6960 | name[2] == 'm' && | |
6961 | name[3] == 'e' && | |
6962 | name[4] == 's') | |
6963 | { /* times */ | |
6964 | return -KEY_times; | |
6965 | } | |
6966 | ||
6967 | goto unknown; | |
6968 | ||
6969 | case 'u': | |
6970 | switch (name[1]) | |
6971 | { | |
6972 | case 'm': | |
6973 | if (name[2] == 'a' && | |
6974 | name[3] == 's' && | |
6975 | name[4] == 'k') | |
6976 | { /* umask */ | |
6977 | return -KEY_umask; | |
6978 | } | |
6979 | ||
6980 | goto unknown; | |
6981 | ||
6982 | case 'n': | |
6983 | switch (name[2]) | |
6984 | { | |
6985 | case 'd': | |
6986 | if (name[3] == 'e' && | |
6987 | name[4] == 'f') | |
6988 | { /* undef */ | |
6989 | return KEY_undef; | |
6990 | } | |
6991 | ||
6992 | goto unknown; | |
6993 | ||
6994 | case 't': | |
6995 | if (name[3] == 'i') | |
6996 | { | |
6997 | switch (name[4]) | |
6998 | { | |
6999 | case 'e': | |
7000 | { /* untie */ | |
7001 | return KEY_untie; | |
7002 | } | |
7003 | ||
4c3bbe0f MHM |
7004 | case 'l': |
7005 | { /* until */ | |
7006 | return KEY_until; | |
7007 | } | |
7008 | ||
4c3bbe0f MHM |
7009 | default: |
7010 | goto unknown; | |
7011 | } | |
7012 | } | |
7013 | ||
7014 | goto unknown; | |
7015 | ||
7016 | default: | |
7017 | goto unknown; | |
7018 | } | |
7019 | ||
7020 | case 't': | |
7021 | if (name[2] == 'i' && | |
7022 | name[3] == 'm' && | |
7023 | name[4] == 'e') | |
7024 | { /* utime */ | |
7025 | return -KEY_utime; | |
7026 | } | |
7027 | ||
7028 | goto unknown; | |
7029 | ||
7030 | default: | |
7031 | goto unknown; | |
7032 | } | |
7033 | ||
7034 | case 'w': | |
7035 | switch (name[1]) | |
7036 | { | |
7037 | case 'h': | |
7038 | if (name[2] == 'i' && | |
7039 | name[3] == 'l' && | |
7040 | name[4] == 'e') | |
7041 | { /* while */ | |
7042 | return KEY_while; | |
7043 | } | |
7044 | ||
7045 | goto unknown; | |
7046 | ||
7047 | case 'r': | |
7048 | if (name[2] == 'i' && | |
7049 | name[3] == 't' && | |
7050 | name[4] == 'e') | |
7051 | { /* write */ | |
7052 | return -KEY_write; | |
7053 | } | |
7054 | ||
7055 | goto unknown; | |
7056 | ||
7057 | default: | |
7058 | goto unknown; | |
7059 | } | |
7060 | ||
7061 | default: | |
7062 | goto unknown; | |
e2e1dd5a | 7063 | } |
4c3bbe0f MHM |
7064 | |
7065 | case 6: /* 33 tokens of length 6 */ | |
7066 | switch (name[0]) | |
7067 | { | |
7068 | case 'a': | |
7069 | if (name[1] == 'c' && | |
7070 | name[2] == 'c' && | |
7071 | name[3] == 'e' && | |
7072 | name[4] == 'p' && | |
7073 | name[5] == 't') | |
7074 | { /* accept */ | |
7075 | return -KEY_accept; | |
7076 | } | |
7077 | ||
7078 | goto unknown; | |
7079 | ||
7080 | case 'c': | |
7081 | switch (name[1]) | |
7082 | { | |
7083 | case 'a': | |
7084 | if (name[2] == 'l' && | |
7085 | name[3] == 'l' && | |
7086 | name[4] == 'e' && | |
7087 | name[5] == 'r') | |
7088 | { /* caller */ | |
7089 | return -KEY_caller; | |
7090 | } | |
7091 | ||
7092 | goto unknown; | |
7093 | ||
7094 | case 'h': | |
7095 | if (name[2] == 'r' && | |
7096 | name[3] == 'o' && | |
7097 | name[4] == 'o' && | |
7098 | name[5] == 't') | |
7099 | { /* chroot */ | |
7100 | return -KEY_chroot; | |
7101 | } | |
7102 | ||
7103 | goto unknown; | |
7104 | ||
7105 | default: | |
7106 | goto unknown; | |
7107 | } | |
7108 | ||
7109 | case 'd': | |
7110 | if (name[1] == 'e' && | |
7111 | name[2] == 'l' && | |
7112 | name[3] == 'e' && | |
7113 | name[4] == 't' && | |
7114 | name[5] == 'e') | |
7115 | { /* delete */ | |
7116 | return KEY_delete; | |
7117 | } | |
7118 | ||
7119 | goto unknown; | |
7120 | ||
7121 | case 'e': | |
7122 | switch (name[1]) | |
7123 | { | |
7124 | case 'l': | |
7125 | if (name[2] == 's' && | |
7126 | name[3] == 'e' && | |
7127 | name[4] == 'i' && | |
7128 | name[5] == 'f') | |
7129 | { /* elseif */ | |
7130 | if(ckWARN_d(WARN_SYNTAX)) | |
7131 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif"); | |
7132 | } | |
7133 | ||
7134 | goto unknown; | |
7135 | ||
7136 | case 'x': | |
7137 | if (name[2] == 'i' && | |
7138 | name[3] == 's' && | |
7139 | name[4] == 't' && | |
7140 | name[5] == 's') | |
7141 | { /* exists */ | |
7142 | return KEY_exists; | |
7143 | } | |
7144 | ||
7145 | goto unknown; | |
7146 | ||
7147 | default: | |
7148 | goto unknown; | |
7149 | } | |
7150 | ||
7151 | case 'f': | |
7152 | switch (name[1]) | |
7153 | { | |
7154 | case 'i': | |
7155 | if (name[2] == 'l' && | |
7156 | name[3] == 'e' && | |
7157 | name[4] == 'n' && | |
7158 | name[5] == 'o') | |
7159 | { /* fileno */ | |
7160 | return -KEY_fileno; | |
7161 | } | |
7162 | ||
7163 | goto unknown; | |
7164 | ||
7165 | case 'o': | |
7166 | if (name[2] == 'r' && | |
7167 | name[3] == 'm' && | |
7168 | name[4] == 'a' && | |
7169 | name[5] == 't') | |
7170 | { /* format */ | |
7171 | return KEY_format; | |
7172 | } | |
7173 | ||
7174 | goto unknown; | |
7175 | ||
7176 | default: | |
7177 | goto unknown; | |
7178 | } | |
7179 | ||
7180 | case 'g': | |
7181 | if (name[1] == 'm' && | |
7182 | name[2] == 't' && | |
7183 | name[3] == 'i' && | |
7184 | name[4] == 'm' && | |
7185 | name[5] == 'e') | |
7186 | { /* gmtime */ | |
7187 | return -KEY_gmtime; | |
7188 | } | |
7189 | ||
7190 | goto unknown; | |
7191 | ||
7192 | case 'l': | |
7193 | switch (name[1]) | |
7194 | { | |
7195 | case 'e': | |
7196 | if (name[2] == 'n' && | |
7197 | name[3] == 'g' && | |
7198 | name[4] == 't' && | |
7199 | name[5] == 'h') | |
7200 | { /* length */ | |
7201 | return -KEY_length; | |
7202 | } | |
7203 | ||
7204 | goto unknown; | |
7205 | ||
7206 | case 'i': | |
7207 | if (name[2] == 's' && | |
7208 | name[3] == 't' && | |
7209 | name[4] == 'e' && | |
7210 | name[5] == 'n') | |
7211 | { /* listen */ | |
7212 | return -KEY_listen; | |
7213 | } | |
7214 | ||
7215 | goto unknown; | |
7216 | ||
7217 | default: | |
7218 | goto unknown; | |
7219 | } | |
7220 | ||
7221 | case 'm': | |
7222 | if (name[1] == 's' && | |
7223 | name[2] == 'g') | |
7224 | { | |
7225 | switch (name[3]) | |
7226 | { | |
7227 | case 'c': | |
7228 | if (name[4] == 't' && | |
7229 | name[5] == 'l') | |
7230 | { /* msgctl */ | |
7231 | return -KEY_msgctl; | |
7232 | } | |
7233 | ||
7234 | goto unknown; | |
7235 | ||
7236 | case 'g': | |
7237 | if (name[4] == 'e' && | |
7238 | name[5] == 't') | |
7239 | { /* msgget */ | |
7240 | return -KEY_msgget; | |
7241 | } | |
7242 | ||
7243 | goto unknown; | |
7244 | ||
7245 | case 'r': | |
7246 | if (name[4] == 'c' && | |
7247 | name[5] == 'v') | |
7248 | { /* msgrcv */ | |
7249 | return -KEY_msgrcv; | |
7250 | } | |
7251 | ||
7252 | goto unknown; | |
7253 | ||
7254 | case 's': | |
7255 | if (name[4] == 'n' && | |
7256 | name[5] == 'd') | |
7257 | { /* msgsnd */ | |
7258 | return -KEY_msgsnd; | |
7259 | } | |
7260 | ||
7261 | goto unknown; | |
7262 | ||
7263 | default: | |
7264 | goto unknown; | |
7265 | } | |
7266 | } | |
7267 | ||
7268 | goto unknown; | |
7269 | ||
7270 | case 'p': | |
7271 | if (name[1] == 'r' && | |
7272 | name[2] == 'i' && | |
7273 | name[3] == 'n' && | |
7274 | name[4] == 't' && | |
7275 | name[5] == 'f') | |
7276 | { /* printf */ | |
7277 | return KEY_printf; | |
7278 | } | |
7279 | ||
7280 | goto unknown; | |
7281 | ||
7282 | case 'r': | |
7283 | switch (name[1]) | |
7284 | { | |
7285 | case 'e': | |
7286 | switch (name[2]) | |
7287 | { | |
7288 | case 'n': | |
7289 | if (name[3] == 'a' && | |
7290 | name[4] == 'm' && | |
7291 | name[5] == 'e') | |
7292 | { /* rename */ | |
7293 | return -KEY_rename; | |
7294 | } | |
7295 | ||
7296 | goto unknown; | |
7297 | ||
7298 | case 't': | |
7299 | if (name[3] == 'u' && | |
7300 | name[4] == 'r' && | |
7301 | name[5] == 'n') | |
7302 | { /* return */ | |
7303 | return KEY_return; | |
7304 | } | |
7305 | ||
7306 | goto unknown; | |
7307 | ||
7308 | default: | |
7309 | goto unknown; | |
7310 | } | |
7311 | ||
7312 | case 'i': | |
7313 | if (name[2] == 'n' && | |
7314 | name[3] == 'd' && | |
7315 | name[4] == 'e' && | |
7316 | name[5] == 'x') | |
7317 | { /* rindex */ | |
7318 | return -KEY_rindex; | |
7319 | } | |
7320 | ||
7321 | goto unknown; | |
7322 | ||
7323 | default: | |
7324 | goto unknown; | |
7325 | } | |
7326 | ||
7327 | case 's': | |
7328 | switch (name[1]) | |
7329 | { | |
7330 | case 'c': | |
7331 | if (name[2] == 'a' && | |
7332 | name[3] == 'l' && | |
7333 | name[4] == 'a' && | |
7334 | name[5] == 'r') | |
7335 | { /* scalar */ | |
7336 | return KEY_scalar; | |
7337 | } | |
7338 | ||
7339 | goto unknown; | |
7340 | ||
7341 | case 'e': | |
7342 | switch (name[2]) | |
7343 | { | |
7344 | case 'l': | |
7345 | if (name[3] == 'e' && | |
7346 | name[4] == 'c' && | |
7347 | name[5] == 't') | |
7348 | { /* select */ | |
7349 | return -KEY_select; | |
7350 | } | |
7351 | ||
7352 | goto unknown; | |
7353 | ||
7354 | case 'm': | |
7355 | switch (name[3]) | |
7356 | { | |
7357 | case 'c': | |
7358 | if (name[4] == 't' && | |
7359 | name[5] == 'l') | |
7360 | { /* semctl */ | |
7361 | return -KEY_semctl; | |
7362 | } | |
7363 | ||
7364 | goto unknown; | |
7365 | ||
7366 | case 'g': | |
7367 | if (name[4] == 'e' && | |
7368 | name[5] == 't') | |
7369 | { /* semget */ | |
7370 | return -KEY_semget; | |
7371 | } | |
7372 | ||
7373 | goto unknown; | |
7374 | ||
7375 | default: | |
7376 | goto unknown; | |
7377 | } | |
7378 | ||
7379 | default: | |
7380 | goto unknown; | |
7381 | } | |
7382 | ||
7383 | case 'h': | |
7384 | if (name[2] == 'm') | |
7385 | { | |
7386 | switch (name[3]) | |
7387 | { | |
7388 | case 'c': | |
7389 | if (name[4] == 't' && | |
7390 | name[5] == 'l') | |
7391 | { /* shmctl */ | |
7392 | return -KEY_shmctl; | |
7393 | } | |
7394 | ||
7395 | goto unknown; | |
7396 | ||
7397 | case 'g': | |
7398 | if (name[4] == 'e' && | |
7399 | name[5] == 't') | |
7400 | { /* shmget */ | |
7401 | return -KEY_shmget; | |
7402 | } | |
7403 | ||
7404 | goto unknown; | |
7405 | ||
7406 | default: | |
7407 | goto unknown; | |
7408 | } | |
7409 | } | |
7410 | ||
7411 | goto unknown; | |
7412 | ||
7413 | case 'o': | |
7414 | if (name[2] == 'c' && | |
7415 | name[3] == 'k' && | |
7416 | name[4] == 'e' && | |
7417 | name[5] == 't') | |
7418 | { /* socket */ | |
7419 | return -KEY_socket; | |
7420 | } | |
7421 | ||
7422 | goto unknown; | |
7423 | ||
7424 | case 'p': | |
7425 | if (name[2] == 'l' && | |
7426 | name[3] == 'i' && | |
7427 | name[4] == 'c' && | |
7428 | name[5] == 'e') | |
7429 | { /* splice */ | |
7430 | return -KEY_splice; | |
7431 | } | |
7432 | ||
7433 | goto unknown; | |
7434 | ||
7435 | case 'u': | |
7436 | if (name[2] == 'b' && | |
7437 | name[3] == 's' && | |
7438 | name[4] == 't' && | |
7439 | name[5] == 'r') | |
7440 | { /* substr */ | |
7441 | return -KEY_substr; | |
7442 | } | |
7443 | ||
7444 | goto unknown; | |
7445 | ||
7446 | case 'y': | |
7447 | if (name[2] == 's' && | |
7448 | name[3] == 't' && | |
7449 | name[4] == 'e' && | |
7450 | name[5] == 'm') | |
7451 | { /* system */ | |
7452 | return -KEY_system; | |
7453 | } | |
7454 | ||
7455 | goto unknown; | |
7456 | ||
7457 | default: | |
7458 | goto unknown; | |
7459 | } | |
7460 | ||
7461 | case 'u': | |
7462 | if (name[1] == 'n') | |
7463 | { | |
7464 | switch (name[2]) | |
7465 | { | |
7466 | case 'l': | |
7467 | switch (name[3]) | |
7468 | { | |
7469 | case 'e': | |
7470 | if (name[4] == 's' && | |
7471 | name[5] == 's') | |
7472 | { /* unless */ | |
7473 | return KEY_unless; | |
7474 | } | |
7475 | ||
7476 | goto unknown; | |
7477 | ||
7478 | case 'i': | |
7479 | if (name[4] == 'n' && | |
7480 | name[5] == 'k') | |
7481 | { /* unlink */ | |
7482 | return -KEY_unlink; | |
7483 | } | |
7484 | ||
7485 | goto unknown; | |
7486 | ||
7487 | default: | |
7488 | goto unknown; | |
7489 | } | |
7490 | ||
7491 | case 'p': | |
7492 | if (name[3] == 'a' && | |
7493 | name[4] == 'c' && | |
7494 | name[5] == 'k') | |
7495 | { /* unpack */ | |
7496 | return -KEY_unpack; | |
7497 | } | |
7498 | ||
7499 | goto unknown; | |
7500 | ||
7501 | default: | |
7502 | goto unknown; | |
7503 | } | |
7504 | } | |
7505 | ||
7506 | goto unknown; | |
7507 | ||
7508 | case 'v': | |
7509 | if (name[1] == 'a' && | |
7510 | name[2] == 'l' && | |
7511 | name[3] == 'u' && | |
7512 | name[4] == 'e' && | |
7513 | name[5] == 's') | |
7514 | { /* values */ | |
7515 | return -KEY_values; | |
7516 | } | |
7517 | ||
7518 | goto unknown; | |
7519 | ||
7520 | default: | |
7521 | goto unknown; | |
e2e1dd5a | 7522 | } |
4c3bbe0f MHM |
7523 | |
7524 | case 7: /* 28 tokens of length 7 */ | |
7525 | switch (name[0]) | |
7526 | { | |
7527 | case 'D': | |
7528 | if (name[1] == 'E' && | |
7529 | name[2] == 'S' && | |
7530 | name[3] == 'T' && | |
7531 | name[4] == 'R' && | |
7532 | name[5] == 'O' && | |
7533 | name[6] == 'Y') | |
7534 | { /* DESTROY */ | |
7535 | return KEY_DESTROY; | |
7536 | } | |
7537 | ||
7538 | goto unknown; | |
7539 | ||
7540 | case '_': | |
7541 | if (name[1] == '_' && | |
7542 | name[2] == 'E' && | |
7543 | name[3] == 'N' && | |
7544 | name[4] == 'D' && | |
7545 | name[5] == '_' && | |
7546 | name[6] == '_') | |
7547 | { /* __END__ */ | |
7548 | return KEY___END__; | |
7549 | } | |
7550 | ||
7551 | goto unknown; | |
7552 | ||
7553 | case 'b': | |
7554 | if (name[1] == 'i' && | |
7555 | name[2] == 'n' && | |
7556 | name[3] == 'm' && | |
7557 | name[4] == 'o' && | |
7558 | name[5] == 'd' && | |
7559 | name[6] == 'e') | |
7560 | { /* binmode */ | |
7561 | return -KEY_binmode; | |
7562 | } | |
7563 | ||
7564 | goto unknown; | |
7565 | ||
7566 | case 'c': | |
7567 | if (name[1] == 'o' && | |
7568 | name[2] == 'n' && | |
7569 | name[3] == 'n' && | |
7570 | name[4] == 'e' && | |
7571 | name[5] == 'c' && | |
7572 | name[6] == 't') | |
7573 | { /* connect */ | |
7574 | return -KEY_connect; | |
7575 | } | |
7576 | ||
7577 | goto unknown; | |
7578 | ||
7579 | case 'd': | |
7580 | switch (name[1]) | |
7581 | { | |
7582 | case 'b': | |
7583 | if (name[2] == 'm' && | |
7584 | name[3] == 'o' && | |
7585 | name[4] == 'p' && | |
7586 | name[5] == 'e' && | |
7587 | name[6] == 'n') | |
7588 | { /* dbmopen */ | |
7589 | return -KEY_dbmopen; | |
7590 | } | |
7591 | ||
7592 | goto unknown; | |
7593 | ||
7594 | case 'e': | |
7595 | if (name[2] == 'f' && | |
7596 | name[3] == 'i' && | |
7597 | name[4] == 'n' && | |
7598 | name[5] == 'e' && | |
7599 | name[6] == 'd') | |
7600 | { /* defined */ | |
7601 | return KEY_defined; | |
7602 | } | |
7603 | ||
7604 | goto unknown; | |
7605 | ||
7606 | default: | |
7607 | goto unknown; | |
7608 | } | |
7609 | ||
7610 | case 'f': | |
7611 | if (name[1] == 'o' && | |
7612 | name[2] == 'r' && | |
7613 | name[3] == 'e' && | |
7614 | name[4] == 'a' && | |
7615 | name[5] == 'c' && | |
7616 | name[6] == 'h') | |
7617 | { /* foreach */ | |
7618 | return KEY_foreach; | |
7619 | } | |
7620 | ||
7621 | goto unknown; | |
7622 | ||
7623 | case 'g': | |
7624 | if (name[1] == 'e' && | |
7625 | name[2] == 't' && | |
7626 | name[3] == 'p') | |
7627 | { | |
7628 | switch (name[4]) | |
7629 | { | |
7630 | case 'g': | |
7631 | if (name[5] == 'r' && | |
7632 | name[6] == 'p') | |
7633 | { /* getpgrp */ | |
7634 | return -KEY_getpgrp; | |
7635 | } | |
7636 | ||
7637 | goto unknown; | |
7638 | ||
7639 | case 'p': | |
7640 | if (name[5] == 'i' && | |
7641 | name[6] == 'd') | |
7642 | { /* getppid */ | |
7643 | return -KEY_getppid; | |
7644 | } | |
7645 | ||
7646 | goto unknown; | |
7647 | ||
7648 | default: | |
7649 | goto unknown; | |
7650 | } | |
7651 | } | |
7652 | ||
7653 | goto unknown; | |
7654 | ||
7655 | case 'l': | |
7656 | if (name[1] == 'c' && | |
7657 | name[2] == 'f' && | |
7658 | name[3] == 'i' && | |
7659 | name[4] == 'r' && | |
7660 | name[5] == 's' && | |
7661 | name[6] == 't') | |
7662 | { /* lcfirst */ | |
7663 | return -KEY_lcfirst; | |
7664 | } | |
7665 | ||
7666 | goto unknown; | |
7667 | ||
7668 | case 'o': | |
7669 | if (name[1] == 'p' && | |
7670 | name[2] == 'e' && | |
7671 | name[3] == 'n' && | |
7672 | name[4] == 'd' && | |
7673 | name[5] == 'i' && | |
7674 | name[6] == 'r') | |
7675 | { /* opendir */ | |
7676 | return -KEY_opendir; | |
7677 | } | |
7678 | ||
7679 | goto unknown; | |
7680 | ||
7681 | case 'p': | |
7682 | if (name[1] == 'a' && | |
7683 | name[2] == 'c' && | |
7684 | name[3] == 'k' && | |
7685 | name[4] == 'a' && | |
7686 | name[5] == 'g' && | |
7687 | name[6] == 'e') | |
7688 | { /* package */ | |
7689 | return KEY_package; | |
7690 | } | |
7691 | ||
7692 | goto unknown; | |
7693 | ||
7694 | case 'r': | |
7695 | if (name[1] == 'e') | |
7696 | { | |
7697 | switch (name[2]) | |
7698 | { | |
7699 | case 'a': | |
7700 | if (name[3] == 'd' && | |
7701 | name[4] == 'd' && | |
7702 | name[5] == 'i' && | |
7703 | name[6] == 'r') | |
7704 | { /* readdir */ | |
7705 | return -KEY_readdir; | |
7706 | } | |
7707 | ||
7708 | goto unknown; | |
7709 | ||
7710 | case 'q': | |
7711 | if (name[3] == 'u' && | |
7712 | name[4] == 'i' && | |
7713 | name[5] == 'r' && | |
7714 | name[6] == 'e') | |
7715 | { /* require */ | |
7716 | return KEY_require; | |
7717 | } | |
7718 | ||
7719 | goto unknown; | |
7720 | ||
7721 | case 'v': | |
7722 | if (name[3] == 'e' && | |
7723 | name[4] == 'r' && | |
7724 | name[5] == 's' && | |
7725 | name[6] == 'e') | |
7726 | { /* reverse */ | |
7727 | return -KEY_reverse; | |
7728 | } | |
7729 | ||
7730 | goto unknown; | |
7731 | ||
7732 | default: | |
7733 | goto unknown; | |
7734 | } | |
7735 | } | |
7736 | ||
7737 | goto unknown; | |
7738 | ||
7739 | case 's': | |
7740 | switch (name[1]) | |
7741 | { | |
7742 | case 'e': | |
7743 | switch (name[2]) | |
7744 | { | |
7745 | case 'e': | |
7746 | if (name[3] == 'k' && | |
7747 | name[4] == 'd' && | |
7748 | name[5] == 'i' && | |
7749 | name[6] == 'r') | |
7750 | { /* seekdir */ | |
7751 | return -KEY_seekdir; | |
7752 | } | |
7753 | ||
7754 | goto unknown; | |
7755 | ||
7756 | case 't': | |
7757 | if (name[3] == 'p' && | |
7758 | name[4] == 'g' && | |
7759 | name[5] == 'r' && | |
7760 | name[6] == 'p') | |
7761 | { /* setpgrp */ | |
7762 | return -KEY_setpgrp; | |
7763 | } | |
7764 | ||
7765 | goto unknown; | |
7766 | ||
7767 | default: | |
7768 | goto unknown; | |
7769 | } | |
7770 | ||
7771 | case 'h': | |
7772 | if (name[2] == 'm' && | |
7773 | name[3] == 'r' && | |
7774 | name[4] == 'e' && | |
7775 | name[5] == 'a' && | |
7776 | name[6] == 'd') | |
7777 | { /* shmread */ | |
7778 | return -KEY_shmread; | |
7779 | } | |
7780 | ||
7781 | goto unknown; | |
7782 | ||
7783 | case 'p': | |
7784 | if (name[2] == 'r' && | |
7785 | name[3] == 'i' && | |
7786 | name[4] == 'n' && | |
7787 | name[5] == 't' && | |
7788 | name[6] == 'f') | |
7789 | { /* sprintf */ | |
7790 | return -KEY_sprintf; | |
7791 | } | |
7792 | ||
7793 | goto unknown; | |
7794 | ||
7795 | case 'y': | |
7796 | switch (name[2]) | |
7797 | { | |
7798 | case 'm': | |
7799 | if (name[3] == 'l' && | |
7800 | name[4] == 'i' && | |
7801 | name[5] == 'n' && | |
7802 | name[6] == 'k') | |
7803 | { /* symlink */ | |
7804 | return -KEY_symlink; | |
7805 | } | |
7806 | ||
7807 | goto unknown; | |
7808 | ||
7809 | case 's': | |
7810 | switch (name[3]) | |
7811 | { | |
7812 | case 'c': | |
7813 | if (name[4] == 'a' && | |
7814 | name[5] == 'l' && | |
7815 | name[6] == 'l') | |
7816 | { /* syscall */ | |
7817 | return -KEY_syscall; | |
7818 | } | |
7819 | ||
7820 | goto unknown; | |
7821 | ||
7822 | case 'o': | |
7823 | if (name[4] == 'p' && | |
7824 | name[5] == 'e' && | |
7825 | name[6] == 'n') | |
7826 | { /* sysopen */ | |
7827 | return -KEY_sysopen; | |
7828 | } | |
7829 | ||
7830 | goto unknown; | |
7831 | ||
7832 | case 'r': | |
7833 | if (name[4] == 'e' && | |
7834 | name[5] == 'a' && | |
7835 | name[6] == 'd') | |
7836 | { /* sysread */ | |
7837 | return -KEY_sysread; | |
7838 | } | |
7839 | ||
7840 | goto unknown; | |
7841 | ||
7842 | case 's': | |
7843 | if (name[4] == 'e' && | |
7844 | name[5] == 'e' && | |
7845 | name[6] == 'k') | |
7846 | { /* sysseek */ | |
7847 | return -KEY_sysseek; | |
7848 | } | |
7849 | ||
7850 | goto unknown; | |
7851 | ||
7852 | default: | |
7853 | goto unknown; | |
7854 | } | |
7855 | ||
7856 | default: | |
7857 | goto unknown; | |
7858 | } | |
7859 | ||
7860 | default: | |
7861 | goto unknown; | |
7862 | } | |
7863 | ||
7864 | case 't': | |
7865 | if (name[1] == 'e' && | |
7866 | name[2] == 'l' && | |
7867 | name[3] == 'l' && | |
7868 | name[4] == 'd' && | |
7869 | name[5] == 'i' && | |
7870 | name[6] == 'r') | |
7871 | { /* telldir */ | |
7872 | return -KEY_telldir; | |
7873 | } | |
7874 | ||
7875 | goto unknown; | |
7876 | ||
7877 | case 'u': | |
7878 | switch (name[1]) | |
7879 | { | |
7880 | case 'c': | |
7881 | if (name[2] == 'f' && | |
7882 | name[3] == 'i' && | |
7883 | name[4] == 'r' && | |
7884 | name[5] == 's' && | |
7885 | name[6] == 't') | |
7886 | { /* ucfirst */ | |
7887 | return -KEY_ucfirst; | |
7888 | } | |
7889 | ||
7890 | goto unknown; | |
7891 | ||
7892 | case 'n': | |
7893 | if (name[2] == 's' && | |
7894 | name[3] == 'h' && | |
7895 | name[4] == 'i' && | |
7896 | name[5] == 'f' && | |
7897 | name[6] == 't') | |
7898 | { /* unshift */ | |
7899 | return -KEY_unshift; | |
7900 | } | |
7901 | ||
7902 | goto unknown; | |
7903 | ||
7904 | default: | |
7905 | goto unknown; | |
7906 | } | |
7907 | ||
7908 | case 'w': | |
7909 | if (name[1] == 'a' && | |
7910 | name[2] == 'i' && | |
7911 | name[3] == 't' && | |
7912 | name[4] == 'p' && | |
7913 | name[5] == 'i' && | |
7914 | name[6] == 'd') | |
7915 | { /* waitpid */ | |
7916 | return -KEY_waitpid; | |
7917 | } | |
7918 | ||
7919 | goto unknown; | |
7920 | ||
7921 | default: | |
7922 | goto unknown; | |
7923 | } | |
7924 | ||
7925 | case 8: /* 26 tokens of length 8 */ | |
7926 | switch (name[0]) | |
7927 | { | |
7928 | case 'A': | |
7929 | if (name[1] == 'U' && | |
7930 | name[2] == 'T' && | |
7931 | name[3] == 'O' && | |
7932 | name[4] == 'L' && | |
7933 | name[5] == 'O' && | |
7934 | name[6] == 'A' && | |
7935 | name[7] == 'D') | |
7936 | { /* AUTOLOAD */ | |
7937 | return KEY_AUTOLOAD; | |
7938 | } | |
7939 | ||
7940 | goto unknown; | |
7941 | ||
7942 | case '_': | |
7943 | if (name[1] == '_') | |
7944 | { | |
7945 | switch (name[2]) | |
7946 | { | |
7947 | case 'D': | |
7948 | if (name[3] == 'A' && | |
7949 | name[4] == 'T' && | |
7950 | name[5] == 'A' && | |
7951 | name[6] == '_' && | |
7952 | name[7] == '_') | |
7953 | { /* __DATA__ */ | |
7954 | return KEY___DATA__; | |
7955 | } | |
7956 | ||
7957 | goto unknown; | |
7958 | ||
7959 | case 'F': | |
7960 | if (name[3] == 'I' && | |
7961 | name[4] == 'L' && | |
7962 | name[5] == 'E' && | |
7963 | name[6] == '_' && | |
7964 | name[7] == '_') | |
7965 | { /* __FILE__ */ | |
7966 | return -KEY___FILE__; | |
7967 | } | |
7968 | ||
7969 | goto unknown; | |
7970 | ||
7971 | case 'L': | |
7972 | if (name[3] == 'I' && | |
7973 | name[4] == 'N' && | |
7974 | name[5] == 'E' && | |
7975 | name[6] == '_' && | |
7976 | name[7] == '_') | |
7977 | { /* __LINE__ */ | |
7978 | return -KEY___LINE__; | |
7979 | } | |
7980 | ||
7981 | goto unknown; | |
7982 | ||
7983 | default: | |
7984 | goto unknown; | |
7985 | } | |
7986 | } | |
7987 | ||
7988 | goto unknown; | |
7989 | ||
7990 | case 'c': | |
7991 | switch (name[1]) | |
7992 | { | |
7993 | case 'l': | |
7994 | if (name[2] == 'o' && | |
7995 | name[3] == 's' && | |
7996 | name[4] == 'e' && | |
7997 | name[5] == 'd' && | |
7998 | name[6] == 'i' && | |
7999 | name[7] == 'r') | |
8000 | { /* closedir */ | |
8001 | return -KEY_closedir; | |
8002 | } | |
8003 | ||
8004 | goto unknown; | |
8005 | ||
8006 | case 'o': | |
8007 | if (name[2] == 'n' && | |
8008 | name[3] == 't' && | |
8009 | name[4] == 'i' && | |
8010 | name[5] == 'n' && | |
8011 | name[6] == 'u' && | |
8012 | name[7] == 'e') | |
8013 | { /* continue */ | |
8014 | return -KEY_continue; | |
8015 | } | |
8016 | ||
8017 | goto unknown; | |
8018 | ||
8019 | default: | |
8020 | goto unknown; | |
8021 | } | |
8022 | ||
8023 | case 'd': | |
8024 | if (name[1] == 'b' && | |
8025 | name[2] == 'm' && | |
8026 | name[3] == 'c' && | |
8027 | name[4] == 'l' && | |
8028 | name[5] == 'o' && | |
8029 | name[6] == 's' && | |
8030 | name[7] == 'e') | |
8031 | { /* dbmclose */ | |
8032 | return -KEY_dbmclose; | |
8033 | } | |
8034 | ||
8035 | goto unknown; | |
8036 | ||
8037 | case 'e': | |
8038 | if (name[1] == 'n' && | |
8039 | name[2] == 'd') | |
8040 | { | |
8041 | switch (name[3]) | |
8042 | { | |
8043 | case 'g': | |
8044 | if (name[4] == 'r' && | |
8045 | name[5] == 'e' && | |
8046 | name[6] == 'n' && | |
8047 | name[7] == 't') | |
8048 | { /* endgrent */ | |
8049 | return -KEY_endgrent; | |
8050 | } | |
8051 | ||
8052 | goto unknown; | |
8053 | ||
8054 | case 'p': | |
8055 | if (name[4] == 'w' && | |
8056 | name[5] == 'e' && | |
8057 | name[6] == 'n' && | |
8058 | name[7] == 't') | |
8059 | { /* endpwent */ | |
8060 | return -KEY_endpwent; | |
8061 | } | |
8062 | ||
8063 | goto unknown; | |
8064 | ||
8065 | default: | |
8066 | goto unknown; | |
8067 | } | |
8068 | } | |
8069 | ||
8070 | goto unknown; | |
8071 | ||
8072 | case 'f': | |
8073 | if (name[1] == 'o' && | |
8074 | name[2] == 'r' && | |
8075 | name[3] == 'm' && | |
8076 | name[4] == 'l' && | |
8077 | name[5] == 'i' && | |
8078 | name[6] == 'n' && | |
8079 | name[7] == 'e') | |
8080 | { /* formline */ | |
8081 | return -KEY_formline; | |
8082 | } | |
8083 | ||
8084 | goto unknown; | |
8085 | ||
8086 | case 'g': | |
8087 | if (name[1] == 'e' && | |
8088 | name[2] == 't') | |
8089 | { | |
8090 | switch (name[3]) | |
8091 | { | |
8092 | case 'g': | |
8093 | if (name[4] == 'r') | |
8094 | { | |
8095 | switch (name[5]) | |
8096 | { | |
8097 | case 'e': | |
8098 | if (name[6] == 'n' && | |
8099 | name[7] == 't') | |
8100 | { /* getgrent */ | |
8101 | return -KEY_getgrent; | |
8102 | } | |
8103 | ||
8104 | goto unknown; | |
8105 | ||
8106 | case 'g': | |
8107 | if (name[6] == 'i' && | |
8108 | name[7] == 'd') | |
8109 | { /* getgrgid */ | |
8110 | return -KEY_getgrgid; | |
8111 | } | |
8112 | ||
8113 | goto unknown; | |
8114 | ||
8115 | case 'n': | |
8116 | if (name[6] == 'a' && | |
8117 | name[7] == 'm') | |
8118 | { /* getgrnam */ | |
8119 | return -KEY_getgrnam; | |
8120 | } | |
8121 | ||
8122 | goto unknown; | |
8123 | ||
8124 | default: | |
8125 | goto unknown; | |
8126 | } | |
8127 | } | |
8128 | ||
8129 | goto unknown; | |
8130 | ||
8131 | case 'l': | |
8132 | if (name[4] == 'o' && | |
8133 | name[5] == 'g' && | |
8134 | name[6] == 'i' && | |
8135 | name[7] == 'n') | |
8136 | { /* getlogin */ | |
8137 | return -KEY_getlogin; | |
8138 | } | |
8139 | ||
8140 | goto unknown; | |
8141 | ||
8142 | case 'p': | |
8143 | if (name[4] == 'w') | |
8144 | { | |
8145 | switch (name[5]) | |
8146 | { | |
8147 | case 'e': | |
8148 | if (name[6] == 'n' && | |
8149 | name[7] == 't') | |
8150 | { /* getpwent */ | |
8151 | return -KEY_getpwent; | |
8152 | } | |
8153 | ||
8154 | goto unknown; | |
8155 | ||
8156 | case 'n': | |
8157 | if (name[6] == 'a' && | |
8158 | name[7] == 'm') | |
8159 | { /* getpwnam */ | |
8160 | return -KEY_getpwnam; | |
8161 | } | |
8162 | ||
8163 | goto unknown; | |
8164 | ||
8165 | case 'u': | |
8166 | if (name[6] == 'i' && | |
8167 | name[7] == 'd') | |
8168 | { /* getpwuid */ | |
8169 | return -KEY_getpwuid; | |
8170 | } | |
8171 | ||
8172 | goto unknown; | |
8173 | ||
8174 | default: | |
8175 | goto unknown; | |
8176 | } | |
8177 | } | |
8178 | ||
8179 | goto unknown; | |
8180 | ||
8181 | default: | |
8182 | goto unknown; | |
8183 | } | |
8184 | } | |
8185 | ||
8186 | goto unknown; | |
8187 | ||
8188 | case 'r': | |
8189 | if (name[1] == 'e' && | |
8190 | name[2] == 'a' && | |
8191 | name[3] == 'd') | |
8192 | { | |
8193 | switch (name[4]) | |
8194 | { | |
8195 | case 'l': | |
8196 | if (name[5] == 'i' && | |
8197 | name[6] == 'n') | |
8198 | { | |
8199 | switch (name[7]) | |
8200 | { | |
8201 | case 'e': | |
8202 | { /* readline */ | |
8203 | return -KEY_readline; | |
8204 | } | |
8205 | ||
4c3bbe0f MHM |
8206 | case 'k': |
8207 | { /* readlink */ | |
8208 | return -KEY_readlink; | |
8209 | } | |
8210 | ||
4c3bbe0f MHM |
8211 | default: |
8212 | goto unknown; | |
8213 | } | |
8214 | } | |
8215 | ||
8216 | goto unknown; | |
8217 | ||
8218 | case 'p': | |
8219 | if (name[5] == 'i' && | |
8220 | name[6] == 'p' && | |
8221 | name[7] == 'e') | |
8222 | { /* readpipe */ | |
8223 | return -KEY_readpipe; | |
8224 | } | |
8225 | ||
8226 | goto unknown; | |
8227 | ||
8228 | default: | |
8229 | goto unknown; | |
8230 | } | |
8231 | } | |
8232 | ||
8233 | goto unknown; | |
8234 | ||
8235 | case 's': | |
8236 | switch (name[1]) | |
8237 | { | |
8238 | case 'e': | |
8239 | if (name[2] == 't') | |
8240 | { | |
8241 | switch (name[3]) | |
8242 | { | |
8243 | case 'g': | |
8244 | if (name[4] == 'r' && | |
8245 | name[5] == 'e' && | |
8246 | name[6] == 'n' && | |
8247 | name[7] == 't') | |
8248 | { /* setgrent */ | |
8249 | return -KEY_setgrent; | |
8250 | } | |
8251 | ||
8252 | goto unknown; | |
8253 | ||
8254 | case 'p': | |
8255 | if (name[4] == 'w' && | |
8256 | name[5] == 'e' && | |
8257 | name[6] == 'n' && | |
8258 | name[7] == 't') | |
8259 | { /* setpwent */ | |
8260 | return -KEY_setpwent; | |
8261 | } | |
8262 | ||
8263 | goto unknown; | |
8264 | ||
8265 | default: | |
8266 | goto unknown; | |
8267 | } | |
8268 | } | |
8269 | ||
8270 | goto unknown; | |
8271 | ||
8272 | case 'h': | |
8273 | switch (name[2]) | |
8274 | { | |
8275 | case 'm': | |
8276 | if (name[3] == 'w' && | |
8277 | name[4] == 'r' && | |
8278 | name[5] == 'i' && | |
8279 | name[6] == 't' && | |
8280 | name[7] == 'e') | |
8281 | { /* shmwrite */ | |
8282 | return -KEY_shmwrite; | |
8283 | } | |
8284 | ||
8285 | goto unknown; | |
8286 | ||
8287 | case 'u': | |
8288 | if (name[3] == 't' && | |
8289 | name[4] == 'd' && | |
8290 | name[5] == 'o' && | |
8291 | name[6] == 'w' && | |
8292 | name[7] == 'n') | |
8293 | { /* shutdown */ | |
8294 | return -KEY_shutdown; | |
8295 | } | |
8296 | ||
8297 | goto unknown; | |
8298 | ||
8299 | default: | |
8300 | goto unknown; | |
8301 | } | |
8302 | ||
8303 | case 'y': | |
8304 | if (name[2] == 's' && | |
8305 | name[3] == 'w' && | |
8306 | name[4] == 'r' && | |
8307 | name[5] == 'i' && | |
8308 | name[6] == 't' && | |
8309 | name[7] == 'e') | |
8310 | { /* syswrite */ | |
8311 | return -KEY_syswrite; | |
8312 | } | |
8313 | ||
8314 | goto unknown; | |
8315 | ||
8316 | default: | |
8317 | goto unknown; | |
8318 | } | |
8319 | ||
8320 | case 't': | |
8321 | if (name[1] == 'r' && | |
8322 | name[2] == 'u' && | |
8323 | name[3] == 'n' && | |
8324 | name[4] == 'c' && | |
8325 | name[5] == 'a' && | |
8326 | name[6] == 't' && | |
8327 | name[7] == 'e') | |
8328 | { /* truncate */ | |
8329 | return -KEY_truncate; | |
8330 | } | |
8331 | ||
8332 | goto unknown; | |
8333 | ||
8334 | default: | |
8335 | goto unknown; | |
8336 | } | |
8337 | ||
8338 | case 9: /* 8 tokens of length 9 */ | |
8339 | switch (name[0]) | |
8340 | { | |
8341 | case 'e': | |
8342 | if (name[1] == 'n' && | |
8343 | name[2] == 'd' && | |
8344 | name[3] == 'n' && | |
8345 | name[4] == 'e' && | |
8346 | name[5] == 't' && | |
8347 | name[6] == 'e' && | |
8348 | name[7] == 'n' && | |
8349 | name[8] == 't') | |
8350 | { /* endnetent */ | |
8351 | return -KEY_endnetent; | |
8352 | } | |
8353 | ||
8354 | goto unknown; | |
8355 | ||
8356 | case 'g': | |
8357 | if (name[1] == 'e' && | |
8358 | name[2] == 't' && | |
8359 | name[3] == 'n' && | |
8360 | name[4] == 'e' && | |
8361 | name[5] == 't' && | |
8362 | name[6] == 'e' && | |
8363 | name[7] == 'n' && | |
8364 | name[8] == 't') | |
8365 | { /* getnetent */ | |
8366 | return -KEY_getnetent; | |
8367 | } | |
8368 | ||
8369 | goto unknown; | |
8370 | ||
8371 | case 'l': | |
8372 | if (name[1] == 'o' && | |
8373 | name[2] == 'c' && | |
8374 | name[3] == 'a' && | |
8375 | name[4] == 'l' && | |
8376 | name[5] == 't' && | |
8377 | name[6] == 'i' && | |
8378 | name[7] == 'm' && | |
8379 | name[8] == 'e') | |
8380 | { /* localtime */ | |
8381 | return -KEY_localtime; | |
8382 | } | |
8383 | ||
8384 | goto unknown; | |
8385 | ||
8386 | case 'p': | |
8387 | if (name[1] == 'r' && | |
8388 | name[2] == 'o' && | |
8389 | name[3] == 't' && | |
8390 | name[4] == 'o' && | |
8391 | name[5] == 't' && | |
8392 | name[6] == 'y' && | |
8393 | name[7] == 'p' && | |
8394 | name[8] == 'e') | |
8395 | { /* prototype */ | |
8396 | return KEY_prototype; | |
8397 | } | |
8398 | ||
8399 | goto unknown; | |
8400 | ||
8401 | case 'q': | |
8402 | if (name[1] == 'u' && | |
8403 | name[2] == 'o' && | |
8404 | name[3] == 't' && | |
8405 | name[4] == 'e' && | |
8406 | name[5] == 'm' && | |
8407 | name[6] == 'e' && | |
8408 | name[7] == 't' && | |
8409 | name[8] == 'a') | |
8410 | { /* quotemeta */ | |
8411 | return -KEY_quotemeta; | |
8412 | } | |
8413 | ||
8414 | goto unknown; | |
8415 | ||
8416 | case 'r': | |
8417 | if (name[1] == 'e' && | |
8418 | name[2] == 'w' && | |
8419 | name[3] == 'i' && | |
8420 | name[4] == 'n' && | |
8421 | name[5] == 'd' && | |
8422 | name[6] == 'd' && | |
8423 | name[7] == 'i' && | |
8424 | name[8] == 'r') | |
8425 | { /* rewinddir */ | |
8426 | return -KEY_rewinddir; | |
8427 | } | |
8428 | ||
8429 | goto unknown; | |
8430 | ||
8431 | case 's': | |
8432 | if (name[1] == 'e' && | |
8433 | name[2] == 't' && | |
8434 | name[3] == 'n' && | |
8435 | name[4] == 'e' && | |
8436 | name[5] == 't' && | |
8437 | name[6] == 'e' && | |
8438 | name[7] == 'n' && | |
8439 | name[8] == 't') | |
8440 | { /* setnetent */ | |
8441 | return -KEY_setnetent; | |
8442 | } | |
8443 | ||
8444 | goto unknown; | |
8445 | ||
8446 | case 'w': | |
8447 | if (name[1] == 'a' && | |
8448 | name[2] == 'n' && | |
8449 | name[3] == 't' && | |
8450 | name[4] == 'a' && | |
8451 | name[5] == 'r' && | |
8452 | name[6] == 'r' && | |
8453 | name[7] == 'a' && | |
8454 | name[8] == 'y') | |
8455 | { /* wantarray */ | |
8456 | return -KEY_wantarray; | |
8457 | } | |
8458 | ||
8459 | goto unknown; | |
8460 | ||
8461 | default: | |
8462 | goto unknown; | |
8463 | } | |
8464 | ||
8465 | case 10: /* 9 tokens of length 10 */ | |
8466 | switch (name[0]) | |
8467 | { | |
8468 | case 'e': | |
8469 | if (name[1] == 'n' && | |
8470 | name[2] == 'd') | |
8471 | { | |
8472 | switch (name[3]) | |
8473 | { | |
8474 | case 'h': | |
8475 | if (name[4] == 'o' && | |
8476 | name[5] == 's' && | |
8477 | name[6] == 't' && | |
8478 | name[7] == 'e' && | |
8479 | name[8] == 'n' && | |
8480 | name[9] == 't') | |
8481 | { /* endhostent */ | |
8482 | return -KEY_endhostent; | |
8483 | } | |
8484 | ||
8485 | goto unknown; | |
8486 | ||
8487 | case 's': | |
8488 | if (name[4] == 'e' && | |
8489 | name[5] == 'r' && | |
8490 | name[6] == 'v' && | |
8491 | name[7] == 'e' && | |
8492 | name[8] == 'n' && | |
8493 | name[9] == 't') | |
8494 | { /* endservent */ | |
8495 | return -KEY_endservent; | |
8496 | } | |
8497 | ||
8498 | goto unknown; | |
8499 | ||
8500 | default: | |
8501 | goto unknown; | |
8502 | } | |
8503 | } | |
8504 | ||
8505 | goto unknown; | |
8506 | ||
8507 | case 'g': | |
8508 | if (name[1] == 'e' && | |
8509 | name[2] == 't') | |
8510 | { | |
8511 | switch (name[3]) | |
8512 | { | |
8513 | case 'h': | |
8514 | if (name[4] == 'o' && | |
8515 | name[5] == 's' && | |
8516 | name[6] == 't' && | |
8517 | name[7] == 'e' && | |
8518 | name[8] == 'n' && | |
8519 | name[9] == 't') | |
8520 | { /* gethostent */ | |
8521 | return -KEY_gethostent; | |
8522 | } | |
8523 | ||
8524 | goto unknown; | |
8525 | ||
8526 | case 's': | |
8527 | switch (name[4]) | |
8528 | { | |
8529 | case 'e': | |
8530 | if (name[5] == 'r' && | |
8531 | name[6] == 'v' && | |
8532 | name[7] == 'e' && | |
8533 | name[8] == 'n' && | |
8534 | name[9] == 't') | |
8535 | { /* getservent */ | |
8536 | return -KEY_getservent; | |
8537 | } | |
8538 | ||
8539 | goto unknown; | |
8540 | ||
8541 | case 'o': | |
8542 | if (name[5] == 'c' && | |
8543 | name[6] == 'k' && | |
8544 | name[7] == 'o' && | |
8545 | name[8] == 'p' && | |
8546 | name[9] == 't') | |
8547 | { /* getsockopt */ | |
8548 | return -KEY_getsockopt; | |
8549 | } | |
8550 | ||
8551 | goto unknown; | |
8552 | ||
8553 | default: | |
8554 | goto unknown; | |
8555 | } | |
8556 | ||
8557 | default: | |
8558 | goto unknown; | |
8559 | } | |
8560 | } | |
8561 | ||
8562 | goto unknown; | |
8563 | ||
8564 | case 's': | |
8565 | switch (name[1]) | |
8566 | { | |
8567 | case 'e': | |
8568 | if (name[2] == 't') | |
8569 | { | |
8570 | switch (name[3]) | |
8571 | { | |
8572 | case 'h': | |
8573 | if (name[4] == 'o' && | |
8574 | name[5] == 's' && | |
8575 | name[6] == 't' && | |
8576 | name[7] == 'e' && | |
8577 | name[8] == 'n' && | |
8578 | name[9] == 't') | |
8579 | { /* sethostent */ | |
8580 | return -KEY_sethostent; | |
8581 | } | |
8582 | ||
8583 | goto unknown; | |
8584 | ||
8585 | case 's': | |
8586 | switch (name[4]) | |
8587 | { | |
8588 | case 'e': | |
8589 | if (name[5] == 'r' && | |
8590 | name[6] == 'v' && | |
8591 | name[7] == 'e' && | |
8592 | name[8] == 'n' && | |
8593 | name[9] == 't') | |
8594 | { /* setservent */ | |
8595 | return -KEY_setservent; | |
8596 | } | |
8597 | ||
8598 | goto unknown; | |
8599 | ||
8600 | case 'o': | |
8601 | if (name[5] == 'c' && | |
8602 | name[6] == 'k' && | |
8603 | name[7] == 'o' && | |
8604 | name[8] == 'p' && | |
8605 | name[9] == 't') | |
8606 | { /* setsockopt */ | |
8607 | return -KEY_setsockopt; | |
8608 | } | |
8609 | ||
8610 | goto unknown; | |
8611 | ||
8612 | default: | |
8613 | goto unknown; | |
8614 | } | |
8615 | ||
8616 | default: | |
8617 | goto unknown; | |
8618 | } | |
8619 | } | |
8620 | ||
8621 | goto unknown; | |
8622 | ||
8623 | case 'o': | |
8624 | if (name[2] == 'c' && | |
8625 | name[3] == 'k' && | |
8626 | name[4] == 'e' && | |
8627 | name[5] == 't' && | |
8628 | name[6] == 'p' && | |
8629 | name[7] == 'a' && | |
8630 | name[8] == 'i' && | |
8631 | name[9] == 'r') | |
8632 | { /* socketpair */ | |
8633 | return -KEY_socketpair; | |
8634 | } | |
8635 | ||
8636 | goto unknown; | |
8637 | ||
8638 | default: | |
8639 | goto unknown; | |
8640 | } | |
8641 | ||
8642 | default: | |
8643 | goto unknown; | |
e2e1dd5a | 8644 | } |
4c3bbe0f MHM |
8645 | |
8646 | case 11: /* 8 tokens of length 11 */ | |
8647 | switch (name[0]) | |
8648 | { | |
8649 | case '_': | |
8650 | if (name[1] == '_' && | |
8651 | name[2] == 'P' && | |
8652 | name[3] == 'A' && | |
8653 | name[4] == 'C' && | |
8654 | name[5] == 'K' && | |
8655 | name[6] == 'A' && | |
8656 | name[7] == 'G' && | |
8657 | name[8] == 'E' && | |
8658 | name[9] == '_' && | |
8659 | name[10] == '_') | |
8660 | { /* __PACKAGE__ */ | |
8661 | return -KEY___PACKAGE__; | |
8662 | } | |
8663 | ||
8664 | goto unknown; | |
8665 | ||
8666 | case 'e': | |
8667 | if (name[1] == 'n' && | |
8668 | name[2] == 'd' && | |
8669 | name[3] == 'p' && | |
8670 | name[4] == 'r' && | |
8671 | name[5] == 'o' && | |
8672 | name[6] == 't' && | |
8673 | name[7] == 'o' && | |
8674 | name[8] == 'e' && | |
8675 | name[9] == 'n' && | |
8676 | name[10] == 't') | |
8677 | { /* endprotoent */ | |
8678 | return -KEY_endprotoent; | |
8679 | } | |
8680 | ||
8681 | goto unknown; | |
8682 | ||
8683 | case 'g': | |
8684 | if (name[1] == 'e' && | |
8685 | name[2] == 't') | |
8686 | { | |
8687 | switch (name[3]) | |
8688 | { | |
8689 | case 'p': | |
8690 | switch (name[4]) | |
8691 | { | |
8692 | case 'e': | |
8693 | if (name[5] == 'e' && | |
8694 | name[6] == 'r' && | |
8695 | name[7] == 'n' && | |
8696 | name[8] == 'a' && | |
8697 | name[9] == 'm' && | |
8698 | name[10] == 'e') | |
8699 | { /* getpeername */ | |
8700 | return -KEY_getpeername; | |
8701 | } | |
8702 | ||
8703 | goto unknown; | |
8704 | ||
8705 | case 'r': | |
8706 | switch (name[5]) | |
8707 | { | |
8708 | case 'i': | |
8709 | if (name[6] == 'o' && | |
8710 | name[7] == 'r' && | |
8711 | name[8] == 'i' && | |
8712 | name[9] == 't' && | |
8713 | name[10] == 'y') | |
8714 | { /* getpriority */ | |
8715 | return -KEY_getpriority; | |
8716 | } | |
8717 | ||
8718 | goto unknown; | |
8719 | ||
8720 | case 'o': | |
8721 | if (name[6] == 't' && | |
8722 | name[7] == 'o' && | |
8723 | name[8] == 'e' && | |
8724 | name[9] == 'n' && | |
8725 | name[10] == 't') | |
8726 | { /* getprotoent */ | |
8727 | return -KEY_getprotoent; | |
8728 | } | |
8729 | ||
8730 | goto unknown; | |
8731 | ||
8732 | default: | |
8733 | goto unknown; | |
8734 | } | |
8735 | ||
8736 | default: | |
8737 | goto unknown; | |
8738 | } | |
8739 | ||
8740 | case 's': | |
8741 | if (name[4] == 'o' && | |
8742 | name[5] == 'c' && | |
8743 | name[6] == 'k' && | |
8744 | name[7] == 'n' && | |
8745 | name[8] == 'a' && | |
8746 | name[9] == 'm' && | |
8747 | name[10] == 'e') | |
8748 | { /* getsockname */ | |
8749 | return -KEY_getsockname; | |
8750 | } | |
8751 | ||
8752 | goto unknown; | |
8753 | ||
8754 | default: | |
8755 | goto unknown; | |
8756 | } | |
8757 | } | |
8758 | ||
8759 | goto unknown; | |
8760 | ||
8761 | case 's': | |
8762 | if (name[1] == 'e' && | |
8763 | name[2] == 't' && | |
8764 | name[3] == 'p' && | |
8765 | name[4] == 'r') | |
8766 | { | |
8767 | switch (name[5]) | |
8768 | { | |
8769 | case 'i': | |
8770 | if (name[6] == 'o' && | |
8771 | name[7] == 'r' && | |
8772 | name[8] == 'i' && | |
8773 | name[9] == 't' && | |
8774 | name[10] == 'y') | |
8775 | { /* setpriority */ | |
8776 | return -KEY_setpriority; | |
8777 | } | |
8778 | ||
8779 | goto unknown; | |
8780 | ||
8781 | case 'o': | |
8782 | if (name[6] == 't' && | |
8783 | name[7] == 'o' && | |
8784 | name[8] == 'e' && | |
8785 | name[9] == 'n' && | |
8786 | name[10] == 't') | |
8787 | { /* setprotoent */ | |
8788 | return -KEY_setprotoent; | |
8789 | } | |
8790 | ||
8791 | goto unknown; | |
8792 | ||
8793 | default: | |
8794 | goto unknown; | |
8795 | } | |
8796 | } | |
8797 | ||
8798 | goto unknown; | |
8799 | ||
8800 | default: | |
8801 | goto unknown; | |
e2e1dd5a | 8802 | } |
4c3bbe0f MHM |
8803 | |
8804 | case 12: /* 2 tokens of length 12 */ | |
8805 | if (name[0] == 'g' && | |
8806 | name[1] == 'e' && | |
8807 | name[2] == 't' && | |
8808 | name[3] == 'n' && | |
8809 | name[4] == 'e' && | |
8810 | name[5] == 't' && | |
8811 | name[6] == 'b' && | |
8812 | name[7] == 'y') | |
8813 | { | |
8814 | switch (name[8]) | |
8815 | { | |
8816 | case 'a': | |
8817 | if (name[9] == 'd' && | |
8818 | name[10] == 'd' && | |
8819 | name[11] == 'r') | |
8820 | { /* getnetbyaddr */ | |
8821 | return -KEY_getnetbyaddr; | |
8822 | } | |
8823 | ||
8824 | goto unknown; | |
8825 | ||
8826 | case 'n': | |
8827 | if (name[9] == 'a' && | |
8828 | name[10] == 'm' && | |
8829 | name[11] == 'e') | |
8830 | { /* getnetbyname */ | |
8831 | return -KEY_getnetbyname; | |
8832 | } | |
8833 | ||
8834 | goto unknown; | |
8835 | ||
8836 | default: | |
8837 | goto unknown; | |
8838 | } | |
e2e1dd5a | 8839 | } |
4c3bbe0f MHM |
8840 | |
8841 | goto unknown; | |
8842 | ||
8843 | case 13: /* 4 tokens of length 13 */ | |
8844 | if (name[0] == 'g' && | |
8845 | name[1] == 'e' && | |
8846 | name[2] == 't') | |
8847 | { | |
8848 | switch (name[3]) | |
8849 | { | |
8850 | case 'h': | |
8851 | if (name[4] == 'o' && | |
8852 | name[5] == 's' && | |
8853 | name[6] == 't' && | |
8854 | name[7] == 'b' && | |
8855 | name[8] == 'y') | |
8856 | { | |
8857 | switch (name[9]) | |
8858 | { | |
8859 | case 'a': | |
8860 | if (name[10] == 'd' && | |
8861 | name[11] == 'd' && | |
8862 | name[12] == 'r') | |
8863 | { /* gethostbyaddr */ | |
8864 | return -KEY_gethostbyaddr; | |
8865 | } | |
8866 | ||
8867 | goto unknown; | |
8868 | ||
8869 | case 'n': | |
8870 | if (name[10] == 'a' && | |
8871 | name[11] == 'm' && | |
8872 | name[12] == 'e') | |
8873 | { /* gethostbyname */ | |
8874 | return -KEY_gethostbyname; | |
8875 | } | |
8876 | ||
8877 | goto unknown; | |
8878 | ||
8879 | default: | |
8880 | goto unknown; | |
8881 | } | |
8882 | } | |
8883 | ||
8884 | goto unknown; | |
8885 | ||
8886 | case 's': | |
8887 | if (name[4] == 'e' && | |
8888 | name[5] == 'r' && | |
8889 | name[6] == 'v' && | |
8890 | name[7] == 'b' && | |
8891 | name[8] == 'y') | |
8892 | { | |
8893 | switch (name[9]) | |
8894 | { | |
8895 | case 'n': | |
8896 | if (name[10] == 'a' && | |
8897 | name[11] == 'm' && | |
8898 | name[12] == 'e') | |
8899 | { /* getservbyname */ | |
8900 | return -KEY_getservbyname; | |
8901 | } | |
8902 | ||
8903 | goto unknown; | |
8904 | ||
8905 | case 'p': | |
8906 | if (name[10] == 'o' && | |
8907 | name[11] == 'r' && | |
8908 | name[12] == 't') | |
8909 | { /* getservbyport */ | |
8910 | return -KEY_getservbyport; | |
8911 | } | |
8912 | ||
8913 | goto unknown; | |
8914 | ||
8915 | default: | |
8916 | goto unknown; | |
8917 | } | |
8918 | } | |
8919 | ||
8920 | goto unknown; | |
8921 | ||
8922 | default: | |
8923 | goto unknown; | |
8924 | } | |
e2e1dd5a | 8925 | } |
4c3bbe0f MHM |
8926 | |
8927 | goto unknown; | |
8928 | ||
8929 | case 14: /* 1 tokens of length 14 */ | |
8930 | if (name[0] == 'g' && | |
8931 | name[1] == 'e' && | |
8932 | name[2] == 't' && | |
8933 | name[3] == 'p' && | |
8934 | name[4] == 'r' && | |
8935 | name[5] == 'o' && | |
8936 | name[6] == 't' && | |
8937 | name[7] == 'o' && | |
8938 | name[8] == 'b' && | |
8939 | name[9] == 'y' && | |
8940 | name[10] == 'n' && | |
8941 | name[11] == 'a' && | |
8942 | name[12] == 'm' && | |
8943 | name[13] == 'e') | |
8944 | { /* getprotobyname */ | |
8945 | return -KEY_getprotobyname; | |
8946 | } | |
8947 | ||
8948 | goto unknown; | |
8949 | ||
8950 | case 16: /* 1 tokens of length 16 */ | |
8951 | if (name[0] == 'g' && | |
8952 | name[1] == 'e' && | |
8953 | name[2] == 't' && | |
8954 | name[3] == 'p' && | |
8955 | name[4] == 'r' && | |
8956 | name[5] == 'o' && | |
8957 | name[6] == 't' && | |
8958 | name[7] == 'o' && | |
8959 | name[8] == 'b' && | |
8960 | name[9] == 'y' && | |
8961 | name[10] == 'n' && | |
8962 | name[11] == 'u' && | |
8963 | name[12] == 'm' && | |
8964 | name[13] == 'b' && | |
8965 | name[14] == 'e' && | |
8966 | name[15] == 'r') | |
8967 | { /* getprotobynumber */ | |
8968 | return -KEY_getprotobynumber; | |
8969 | } | |
8970 | ||
8971 | goto unknown; | |
8972 | ||
8973 | default: | |
8974 | goto unknown; | |
e2e1dd5a | 8975 | } |
4c3bbe0f MHM |
8976 | |
8977 | unknown: | |
e2e1dd5a | 8978 | return 0; |
a687059c LW |
8979 | } |
8980 | ||
76e3520e | 8981 | STATIC void |
f54cb97a | 8982 | S_checkcomma(pTHX_ register char *s, const char *name, const char *what) |
a687059c | 8983 | { |
f54cb97a | 8984 | const char *w; |
2f3197b3 | 8985 | |
d008e5eb | 8986 | if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */ |
d008e5eb GS |
8987 | if (ckWARN(WARN_SYNTAX)) { |
8988 | int level = 1; | |
8989 | for (w = s+2; *w && level; w++) { | |
8990 | if (*w == '(') | |
8991 | ++level; | |
8992 | else if (*w == ')') | |
8993 | --level; | |
8994 | } | |
8995 | if (*w) | |
8996 | for (; *w && isSPACE(*w); w++) ; | |
8997 | if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */ | |
9014280d | 8998 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
65cec589 | 8999 | "%s (...) interpreted as function",name); |
d008e5eb | 9000 | } |
2f3197b3 | 9001 | } |
3280af22 | 9002 | while (s < PL_bufend && isSPACE(*s)) |
2f3197b3 | 9003 | s++; |
a687059c LW |
9004 | if (*s == '(') |
9005 | s++; | |
3280af22 | 9006 | while (s < PL_bufend && isSPACE(*s)) |
a687059c | 9007 | s++; |
7e2040f0 | 9008 | if (isIDFIRST_lazy_if(s,UTF)) { |
2f3197b3 | 9009 | w = s++; |
7e2040f0 | 9010 | while (isALNUM_lazy_if(s,UTF)) |
a687059c | 9011 | s++; |
3280af22 | 9012 | while (s < PL_bufend && isSPACE(*s)) |
a687059c | 9013 | s++; |
e929a76b | 9014 | if (*s == ',') { |
463ee0b2 | 9015 | int kw; |
f54cb97a | 9016 | *s = '\0'; /* XXX If we didn't do this, we could const a lot of toke.c */ |
864dbfa3 | 9017 | kw = keyword(w, s - w) || get_cv(w, FALSE) != 0; |
e929a76b | 9018 | *s = ','; |
463ee0b2 | 9019 | if (kw) |
e929a76b | 9020 | return; |
cea2e8a9 | 9021 | Perl_croak(aTHX_ "No comma allowed after %s", what); |
463ee0b2 LW |
9022 | } |
9023 | } | |
9024 | } | |
9025 | ||
423cee85 JH |
9026 | /* Either returns sv, or mortalizes sv and returns a new SV*. |
9027 | Best used as sv=new_constant(..., sv, ...). | |
9028 | If s, pv are NULL, calls subroutine with one argument, | |
9029 | and type is used with error messages only. */ | |
9030 | ||
b3ac6de7 | 9031 | STATIC SV * |
7fc63493 | 9032 | S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv, |
9b0e499b | 9033 | const char *type) |
b3ac6de7 | 9034 | { |
27da23d5 | 9035 | dVAR; dSP; |
890ce7af | 9036 | HV * const table = GvHV(PL_hintgv); /* ^H */ |
b3ac6de7 | 9037 | SV *res; |
b3ac6de7 IZ |
9038 | SV **cvp; |
9039 | SV *cv, *typesv; | |
89e33a05 | 9040 | const char *why1 = "", *why2 = "", *why3 = ""; |
4e553d73 | 9041 | |
f0af216f | 9042 | if (!table || !(PL_hints & HINT_LOCALIZE_HH)) { |
423cee85 JH |
9043 | SV *msg; |
9044 | ||
f0af216f | 9045 | why2 = strEQ(key,"charnames") |
41ab332f | 9046 | ? "(possibly a missing \"use charnames ...\")" |
f0af216f | 9047 | : ""; |
4e553d73 | 9048 | msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s", |
41ab332f JH |
9049 | (type ? type: "undef"), why2); |
9050 | ||
9051 | /* This is convoluted and evil ("goto considered harmful") | |
9052 | * but I do not understand the intricacies of all the different | |
9053 | * failure modes of %^H in here. The goal here is to make | |
9054 | * the most probable error message user-friendly. --jhi */ | |
9055 | ||
9056 | goto msgdone; | |
9057 | ||
423cee85 | 9058 | report: |
4e553d73 | 9059 | msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s", |
f0af216f | 9060 | (type ? type: "undef"), why1, why2, why3); |
41ab332f | 9061 | msgdone: |
95a20fc0 | 9062 | yyerror(SvPVX_const(msg)); |
423cee85 JH |
9063 | SvREFCNT_dec(msg); |
9064 | return sv; | |
9065 | } | |
b3ac6de7 IZ |
9066 | cvp = hv_fetch(table, key, strlen(key), FALSE); |
9067 | if (!cvp || !SvOK(*cvp)) { | |
423cee85 JH |
9068 | why1 = "$^H{"; |
9069 | why2 = key; | |
f0af216f | 9070 | why3 = "} is not defined"; |
423cee85 | 9071 | goto report; |
b3ac6de7 IZ |
9072 | } |
9073 | sv_2mortal(sv); /* Parent created it permanently */ | |
9074 | cv = *cvp; | |
423cee85 JH |
9075 | if (!pv && s) |
9076 | pv = sv_2mortal(newSVpvn(s, len)); | |
9077 | if (type && pv) | |
9078 | typesv = sv_2mortal(newSVpv(type, 0)); | |
b3ac6de7 | 9079 | else |
423cee85 | 9080 | typesv = &PL_sv_undef; |
4e553d73 | 9081 | |
e788e7d3 | 9082 | PUSHSTACKi(PERLSI_OVERLOAD); |
423cee85 JH |
9083 | ENTER ; |
9084 | SAVETMPS; | |
4e553d73 | 9085 | |
423cee85 | 9086 | PUSHMARK(SP) ; |
a5845cb7 | 9087 | EXTEND(sp, 3); |
423cee85 JH |
9088 | if (pv) |
9089 | PUSHs(pv); | |
b3ac6de7 | 9090 | PUSHs(sv); |
423cee85 JH |
9091 | if (pv) |
9092 | PUSHs(typesv); | |
b3ac6de7 | 9093 | PUTBACK; |
423cee85 | 9094 | call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL)); |
4e553d73 | 9095 | |
423cee85 | 9096 | SPAGAIN ; |
4e553d73 | 9097 | |
423cee85 | 9098 | /* Check the eval first */ |
9b0e499b | 9099 | if (!PL_in_eval && SvTRUE(ERRSV)) { |
423cee85 | 9100 | sv_catpv(ERRSV, "Propagated"); |
8b6b16e7 | 9101 | yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */ |
e1f15930 | 9102 | (void)POPs; |
423cee85 JH |
9103 | res = SvREFCNT_inc(sv); |
9104 | } | |
9105 | else { | |
9106 | res = POPs; | |
e1f15930 | 9107 | (void)SvREFCNT_inc(res); |
423cee85 | 9108 | } |
4e553d73 | 9109 | |
423cee85 JH |
9110 | PUTBACK ; |
9111 | FREETMPS ; | |
9112 | LEAVE ; | |
b3ac6de7 | 9113 | POPSTACK; |
4e553d73 | 9114 | |
b3ac6de7 | 9115 | if (!SvOK(res)) { |
423cee85 JH |
9116 | why1 = "Call to &{$^H{"; |
9117 | why2 = key; | |
f0af216f | 9118 | why3 = "}} did not return a defined value"; |
423cee85 JH |
9119 | sv = res; |
9120 | goto report; | |
9b0e499b | 9121 | } |
423cee85 | 9122 | |
9b0e499b | 9123 | return res; |
b3ac6de7 | 9124 | } |
4e553d73 | 9125 | |
d0a148a6 NC |
9126 | /* Returns a NUL terminated string, with the length of the string written to |
9127 | *slp | |
9128 | */ | |
76e3520e | 9129 | STATIC char * |
cea2e8a9 | 9130 | S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp) |
463ee0b2 LW |
9131 | { |
9132 | register char *d = dest; | |
890ce7af | 9133 | register char * const e = d + destlen - 3; /* two-character token, ending NUL */ |
463ee0b2 | 9134 | for (;;) { |
8903cb82 | 9135 | if (d >= e) |
cea2e8a9 | 9136 | Perl_croak(aTHX_ ident_too_long); |
834a4ddd | 9137 | if (isALNUM(*s)) /* UTF handled below */ |
463ee0b2 | 9138 | *d++ = *s++; |
7e2040f0 | 9139 | else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) { |
463ee0b2 LW |
9140 | *d++ = ':'; |
9141 | *d++ = ':'; | |
9142 | s++; | |
9143 | } | |
c3e0f903 | 9144 | else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') { |
463ee0b2 LW |
9145 | *d++ = *s++; |
9146 | *d++ = *s++; | |
9147 | } | |
fd400ab9 | 9148 | else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
a0ed51b3 | 9149 | char *t = s + UTF8SKIP(s); |
fd400ab9 | 9150 | while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
a0ed51b3 LW |
9151 | t += UTF8SKIP(t); |
9152 | if (d + (t - s) > e) | |
cea2e8a9 | 9153 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 LW |
9154 | Copy(s, d, t - s, char); |
9155 | d += t - s; | |
9156 | s = t; | |
9157 | } | |
463ee0b2 LW |
9158 | else { |
9159 | *d = '\0'; | |
9160 | *slp = d - dest; | |
9161 | return s; | |
e929a76b | 9162 | } |
378cc40b LW |
9163 | } |
9164 | } | |
9165 | ||
76e3520e | 9166 | STATIC char * |
f54cb97a | 9167 | S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni) |
378cc40b LW |
9168 | { |
9169 | register char *d; | |
8903cb82 | 9170 | register char *e; |
46c461b5 | 9171 | char *bracket = Nullch; |
748a9306 | 9172 | char funny = *s++; |
378cc40b | 9173 | |
a0d0e21e LW |
9174 | if (isSPACE(*s)) |
9175 | s = skipspace(s); | |
378cc40b | 9176 | d = dest; |
8903cb82 | 9177 | e = d + destlen - 3; /* two-character token, ending NUL */ |
de3bb511 | 9178 | if (isDIGIT(*s)) { |
8903cb82 | 9179 | while (isDIGIT(*s)) { |
9180 | if (d >= e) | |
cea2e8a9 | 9181 | Perl_croak(aTHX_ ident_too_long); |
378cc40b | 9182 | *d++ = *s++; |
8903cb82 | 9183 | } |
378cc40b LW |
9184 | } |
9185 | else { | |
463ee0b2 | 9186 | for (;;) { |
8903cb82 | 9187 | if (d >= e) |
cea2e8a9 | 9188 | Perl_croak(aTHX_ ident_too_long); |
834a4ddd | 9189 | if (isALNUM(*s)) /* UTF handled below */ |
463ee0b2 | 9190 | *d++ = *s++; |
7e2040f0 | 9191 | else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) { |
463ee0b2 LW |
9192 | *d++ = ':'; |
9193 | *d++ = ':'; | |
9194 | s++; | |
9195 | } | |
a0d0e21e | 9196 | else if (*s == ':' && s[1] == ':') { |
463ee0b2 LW |
9197 | *d++ = *s++; |
9198 | *d++ = *s++; | |
9199 | } | |
fd400ab9 | 9200 | else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
a0ed51b3 | 9201 | char *t = s + UTF8SKIP(s); |
fd400ab9 | 9202 | while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
a0ed51b3 LW |
9203 | t += UTF8SKIP(t); |
9204 | if (d + (t - s) > e) | |
cea2e8a9 | 9205 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 LW |
9206 | Copy(s, d, t - s, char); |
9207 | d += t - s; | |
9208 | s = t; | |
9209 | } | |
463ee0b2 LW |
9210 | else |
9211 | break; | |
9212 | } | |
378cc40b LW |
9213 | } |
9214 | *d = '\0'; | |
9215 | d = dest; | |
79072805 | 9216 | if (*d) { |
3280af22 NIS |
9217 | if (PL_lex_state != LEX_NORMAL) |
9218 | PL_lex_state = LEX_INTERPENDMAYBE; | |
79072805 | 9219 | return s; |
378cc40b | 9220 | } |
748a9306 | 9221 | if (*s == '$' && s[1] && |
3792a11b | 9222 | (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) ) |
5cd24f17 | 9223 | { |
4810e5ec | 9224 | return s; |
5cd24f17 | 9225 | } |
79072805 LW |
9226 | if (*s == '{') { |
9227 | bracket = s; | |
9228 | s++; | |
9229 | } | |
9230 | else if (ck_uni) | |
9231 | check_uni(); | |
93a17b20 | 9232 | if (s < send) |
79072805 LW |
9233 | *d = *s++; |
9234 | d[1] = '\0'; | |
2b92dfce | 9235 | if (*d == '^' && *s && isCONTROLVAR(*s)) { |
bbce6d69 | 9236 | *d = toCTRL(*s); |
9237 | s++; | |
de3bb511 | 9238 | } |
79072805 | 9239 | if (bracket) { |
748a9306 | 9240 | if (isSPACE(s[-1])) { |
fa83b5b6 | 9241 | while (s < send) { |
f54cb97a | 9242 | const char ch = *s++; |
bf4acbe4 | 9243 | if (!SPACE_OR_TAB(ch)) { |
fa83b5b6 | 9244 | *d = ch; |
9245 | break; | |
9246 | } | |
9247 | } | |
748a9306 | 9248 | } |
7e2040f0 | 9249 | if (isIDFIRST_lazy_if(d,UTF)) { |
79072805 | 9250 | d++; |
a0ed51b3 LW |
9251 | if (UTF) { |
9252 | e = s; | |
155aba94 | 9253 | while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') { |
a0ed51b3 | 9254 | e += UTF8SKIP(e); |
fd400ab9 | 9255 | while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e)) |
a0ed51b3 LW |
9256 | e += UTF8SKIP(e); |
9257 | } | |
9258 | Copy(s, d, e - s, char); | |
9259 | d += e - s; | |
9260 | s = e; | |
9261 | } | |
9262 | else { | |
2b92dfce | 9263 | while ((isALNUM(*s) || *s == ':') && d < e) |
a0ed51b3 | 9264 | *d++ = *s++; |
2b92dfce | 9265 | if (d >= e) |
cea2e8a9 | 9266 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 | 9267 | } |
79072805 | 9268 | *d = '\0'; |
bf4acbe4 | 9269 | while (s < send && SPACE_OR_TAB(*s)) s++; |
ff68c719 | 9270 | if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) { |
599cee73 | 9271 | if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) { |
dff6d3cd | 9272 | const char *brack = *s == '[' ? "[...]" : "{...}"; |
9014280d | 9273 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
599cee73 | 9274 | "Ambiguous use of %c{%s%s} resolved to %c%s%s", |
748a9306 LW |
9275 | funny, dest, brack, funny, dest, brack); |
9276 | } | |
79072805 | 9277 | bracket++; |
a0be28da | 9278 | PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK); |
79072805 LW |
9279 | return s; |
9280 | } | |
4e553d73 NIS |
9281 | } |
9282 | /* Handle extended ${^Foo} variables | |
2b92dfce GS |
9283 | * 1999-02-27 mjd-perl-patch@plover.com */ |
9284 | else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */ | |
9285 | && isALNUM(*s)) | |
9286 | { | |
9287 | d++; | |
9288 | while (isALNUM(*s) && d < e) { | |
9289 | *d++ = *s++; | |
9290 | } | |
9291 | if (d >= e) | |
cea2e8a9 | 9292 | Perl_croak(aTHX_ ident_too_long); |
2b92dfce | 9293 | *d = '\0'; |
79072805 LW |
9294 | } |
9295 | if (*s == '}') { | |
9296 | s++; | |
7df0d042 | 9297 | if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) { |
3280af22 | 9298 | PL_lex_state = LEX_INTERPEND; |
7df0d042 AE |
9299 | PL_expect = XREF; |
9300 | } | |
748a9306 LW |
9301 | if (funny == '#') |
9302 | funny = '@'; | |
d008e5eb | 9303 | if (PL_lex_state == LEX_NORMAL) { |
d008e5eb | 9304 | if (ckWARN(WARN_AMBIGUOUS) && |
864dbfa3 | 9305 | (keyword(dest, d - dest) || get_cv(dest, FALSE))) |
d008e5eb | 9306 | { |
9014280d | 9307 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
d008e5eb GS |
9308 | "Ambiguous use of %c{%s} resolved to %c%s", |
9309 | funny, dest, funny, dest); | |
9310 | } | |
9311 | } | |
79072805 LW |
9312 | } |
9313 | else { | |
9314 | s = bracket; /* let the parser handle it */ | |
93a17b20 | 9315 | *dest = '\0'; |
79072805 LW |
9316 | } |
9317 | } | |
3280af22 NIS |
9318 | else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s)) |
9319 | PL_lex_state = LEX_INTERPEND; | |
378cc40b LW |
9320 | return s; |
9321 | } | |
9322 | ||
cea2e8a9 | 9323 | void |
2b36a5a0 | 9324 | Perl_pmflag(pTHX_ U32* pmfl, int ch) |
a0d0e21e | 9325 | { |
bbce6d69 | 9326 | if (ch == 'i') |
a0d0e21e | 9327 | *pmfl |= PMf_FOLD; |
a0d0e21e LW |
9328 | else if (ch == 'g') |
9329 | *pmfl |= PMf_GLOBAL; | |
c90c0ff4 | 9330 | else if (ch == 'c') |
9331 | *pmfl |= PMf_CONTINUE; | |
a0d0e21e LW |
9332 | else if (ch == 'o') |
9333 | *pmfl |= PMf_KEEP; | |
9334 | else if (ch == 'm') | |
9335 | *pmfl |= PMf_MULTILINE; | |
9336 | else if (ch == 's') | |
9337 | *pmfl |= PMf_SINGLELINE; | |
9338 | else if (ch == 'x') | |
9339 | *pmfl |= PMf_EXTENDED; | |
9340 | } | |
378cc40b | 9341 | |
76e3520e | 9342 | STATIC char * |
cea2e8a9 | 9343 | S_scan_pat(pTHX_ char *start, I32 type) |
378cc40b | 9344 | { |
79072805 | 9345 | PMOP *pm; |
f54cb97a | 9346 | char *s = scan_str(start,FALSE,FALSE); |
378cc40b | 9347 | |
25c09cbf | 9348 | if (!s) { |
46c461b5 | 9349 | char * const delimiter = skipspace(start); |
25c09cbf SF |
9350 | Perl_croak(aTHX_ *delimiter == '?' |
9351 | ? "Search pattern not terminated or ternary operator parsed as search pattern" | |
9352 | : "Search pattern not terminated" ); | |
9353 | } | |
bbce6d69 | 9354 | |
8782bef2 | 9355 | pm = (PMOP*)newPMOP(type, 0); |
3280af22 | 9356 | if (PL_multi_open == '?') |
79072805 | 9357 | pm->op_pmflags |= PMf_ONCE; |
8782bef2 GB |
9358 | if(type == OP_QR) { |
9359 | while (*s && strchr("iomsx", *s)) | |
9360 | pmflag(&pm->op_pmflags,*s++); | |
9361 | } | |
9362 | else { | |
9363 | while (*s && strchr("iogcmsx", *s)) | |
9364 | pmflag(&pm->op_pmflags,*s++); | |
9365 | } | |
4ac733c9 | 9366 | /* issue a warning if /c is specified,but /g is not */ |
041457d9 DM |
9367 | if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL) |
9368 | && ckWARN(WARN_REGEXP)) | |
4ac733c9 MJD |
9369 | { |
9370 | Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_without_g); | |
9371 | } | |
9372 | ||
4633a7c4 | 9373 | pm->op_pmpermflags = pm->op_pmflags; |
bbce6d69 | 9374 | |
3280af22 | 9375 | PL_lex_op = (OP*)pm; |
79072805 | 9376 | yylval.ival = OP_MATCH; |
378cc40b LW |
9377 | return s; |
9378 | } | |
9379 | ||
76e3520e | 9380 | STATIC char * |
cea2e8a9 | 9381 | S_scan_subst(pTHX_ char *start) |
79072805 | 9382 | { |
27da23d5 | 9383 | dVAR; |
a0d0e21e | 9384 | register char *s; |
79072805 | 9385 | register PMOP *pm; |
4fdae800 | 9386 | I32 first_start; |
79072805 LW |
9387 | I32 es = 0; |
9388 | ||
79072805 LW |
9389 | yylval.ival = OP_NULL; |
9390 | ||
09bef843 | 9391 | s = scan_str(start,FALSE,FALSE); |
79072805 | 9392 | |
37fd879b | 9393 | if (!s) |
cea2e8a9 | 9394 | Perl_croak(aTHX_ "Substitution pattern not terminated"); |
79072805 | 9395 | |
3280af22 | 9396 | if (s[-1] == PL_multi_open) |
79072805 LW |
9397 | s--; |
9398 | ||
3280af22 | 9399 | first_start = PL_multi_start; |
09bef843 | 9400 | s = scan_str(s,FALSE,FALSE); |
79072805 | 9401 | if (!s) { |
37fd879b | 9402 | if (PL_lex_stuff) { |
3280af22 | 9403 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
9404 | PL_lex_stuff = Nullsv; |
9405 | } | |
cea2e8a9 | 9406 | Perl_croak(aTHX_ "Substitution replacement not terminated"); |
a687059c | 9407 | } |
3280af22 | 9408 | PL_multi_start = first_start; /* so whole substitution is taken together */ |
2f3197b3 | 9409 | |
79072805 | 9410 | pm = (PMOP*)newPMOP(OP_SUBST, 0); |
48c036b1 | 9411 | while (*s) { |
a687059c LW |
9412 | if (*s == 'e') { |
9413 | s++; | |
2f3197b3 | 9414 | es++; |
a687059c | 9415 | } |
b3eb6a9b | 9416 | else if (strchr("iogcmsx", *s)) |
a0d0e21e | 9417 | pmflag(&pm->op_pmflags,*s++); |
48c036b1 GS |
9418 | else |
9419 | break; | |
378cc40b | 9420 | } |
79072805 | 9421 | |
64e578a2 | 9422 | /* /c is not meaningful with s/// */ |
041457d9 | 9423 | if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) |
4ac733c9 | 9424 | { |
64e578a2 | 9425 | Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_in_subst); |
4ac733c9 MJD |
9426 | } |
9427 | ||
79072805 LW |
9428 | if (es) { |
9429 | SV *repl; | |
0244c3a4 GS |
9430 | PL_sublex_info.super_bufptr = s; |
9431 | PL_sublex_info.super_bufend = PL_bufend; | |
9432 | PL_multi_end = 0; | |
79072805 | 9433 | pm->op_pmflags |= PMf_EVAL; |
79cb57f6 | 9434 | repl = newSVpvn("",0); |
463ee0b2 | 9435 | while (es-- > 0) |
a0d0e21e | 9436 | sv_catpv(repl, es ? "eval " : "do "); |
79072805 | 9437 | sv_catpvn(repl, "{ ", 2); |
3280af22 | 9438 | sv_catsv(repl, PL_lex_repl); |
79072805 | 9439 | sv_catpvn(repl, " };", 2); |
25da4f38 | 9440 | SvEVALED_on(repl); |
3280af22 NIS |
9441 | SvREFCNT_dec(PL_lex_repl); |
9442 | PL_lex_repl = repl; | |
378cc40b | 9443 | } |
79072805 | 9444 | |
4633a7c4 | 9445 | pm->op_pmpermflags = pm->op_pmflags; |
3280af22 | 9446 | PL_lex_op = (OP*)pm; |
79072805 | 9447 | yylval.ival = OP_SUBST; |
378cc40b LW |
9448 | return s; |
9449 | } | |
9450 | ||
76e3520e | 9451 | STATIC char * |
cea2e8a9 | 9452 | S_scan_trans(pTHX_ char *start) |
378cc40b | 9453 | { |
a0d0e21e | 9454 | register char* s; |
11343788 | 9455 | OP *o; |
79072805 LW |
9456 | short *tbl; |
9457 | I32 squash; | |
a0ed51b3 | 9458 | I32 del; |
79072805 LW |
9459 | I32 complement; |
9460 | ||
9461 | yylval.ival = OP_NULL; | |
9462 | ||
09bef843 | 9463 | s = scan_str(start,FALSE,FALSE); |
37fd879b | 9464 | if (!s) |
cea2e8a9 | 9465 | Perl_croak(aTHX_ "Transliteration pattern not terminated"); |
3280af22 | 9466 | if (s[-1] == PL_multi_open) |
2f3197b3 LW |
9467 | s--; |
9468 | ||
09bef843 | 9469 | s = scan_str(s,FALSE,FALSE); |
79072805 | 9470 | if (!s) { |
37fd879b | 9471 | if (PL_lex_stuff) { |
3280af22 | 9472 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
9473 | PL_lex_stuff = Nullsv; |
9474 | } | |
cea2e8a9 | 9475 | Perl_croak(aTHX_ "Transliteration replacement not terminated"); |
a687059c | 9476 | } |
79072805 | 9477 | |
a0ed51b3 | 9478 | complement = del = squash = 0; |
7a1e2023 NC |
9479 | while (1) { |
9480 | switch (*s) { | |
9481 | case 'c': | |
79072805 | 9482 | complement = OPpTRANS_COMPLEMENT; |
7a1e2023 NC |
9483 | break; |
9484 | case 'd': | |
a0ed51b3 | 9485 | del = OPpTRANS_DELETE; |
7a1e2023 NC |
9486 | break; |
9487 | case 's': | |
79072805 | 9488 | squash = OPpTRANS_SQUASH; |
7a1e2023 NC |
9489 | break; |
9490 | default: | |
9491 | goto no_more; | |
9492 | } | |
395c3793 LW |
9493 | s++; |
9494 | } | |
7a1e2023 | 9495 | no_more: |
8973db79 | 9496 | |
a02a5408 | 9497 | Newx(tbl, complement&&!del?258:256, short); |
8973db79 | 9498 | o = newPVOP(OP_TRANS, 0, (char*)tbl); |
59f00321 RGS |
9499 | o->op_private &= ~OPpTRANS_ALL; |
9500 | o->op_private |= del|squash|complement| | |
7948272d NIS |
9501 | (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)| |
9502 | (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0); | |
79072805 | 9503 | |
3280af22 | 9504 | PL_lex_op = o; |
79072805 LW |
9505 | yylval.ival = OP_TRANS; |
9506 | return s; | |
9507 | } | |
9508 | ||
76e3520e | 9509 | STATIC char * |
cea2e8a9 | 9510 | S_scan_heredoc(pTHX_ register char *s) |
79072805 LW |
9511 | { |
9512 | SV *herewas; | |
9513 | I32 op_type = OP_SCALAR; | |
9514 | I32 len; | |
9515 | SV *tmpstr; | |
9516 | char term; | |
73d840c0 AL |
9517 | const char newline[] = "\n"; |
9518 | const char *found_newline; | |
79072805 | 9519 | register char *d; |
fc36a67e | 9520 | register char *e; |
4633a7c4 | 9521 | char *peek; |
f54cb97a | 9522 | const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR)); |
79072805 LW |
9523 | |
9524 | s += 2; | |
3280af22 NIS |
9525 | d = PL_tokenbuf; |
9526 | e = PL_tokenbuf + sizeof PL_tokenbuf - 1; | |
fd2d0953 | 9527 | if (!outer) |
79072805 | 9528 | *d++ = '\n'; |
bf4acbe4 | 9529 | for (peek = s; SPACE_OR_TAB(*peek); peek++) ; |
3792a11b | 9530 | if (*peek == '`' || *peek == '\'' || *peek =='"') { |
4633a7c4 | 9531 | s = peek; |
79072805 | 9532 | term = *s++; |
3280af22 | 9533 | s = delimcpy(d, e, s, PL_bufend, term, &len); |
fc36a67e | 9534 | d += len; |
3280af22 | 9535 | if (s < PL_bufend) |
79072805 | 9536 | s++; |
79072805 LW |
9537 | } |
9538 | else { | |
9539 | if (*s == '\\') | |
9540 | s++, term = '\''; | |
9541 | else | |
9542 | term = '"'; | |
7e2040f0 | 9543 | if (!isALNUM_lazy_if(s,UTF)) |
12bcd1a6 | 9544 | deprecate_old("bare << to mean <<\"\""); |
7e2040f0 | 9545 | for (; isALNUM_lazy_if(s,UTF); s++) { |
fc36a67e | 9546 | if (d < e) |
9547 | *d++ = *s; | |
9548 | } | |
9549 | } | |
3280af22 | 9550 | if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1) |
cea2e8a9 | 9551 | Perl_croak(aTHX_ "Delimiter for here document is too long"); |
79072805 LW |
9552 | *d++ = '\n'; |
9553 | *d = '\0'; | |
3280af22 | 9554 | len = d - PL_tokenbuf; |
6a27c188 | 9555 | #ifndef PERL_STRICT_CR |
f63a84b2 LW |
9556 | d = strchr(s, '\r'); |
9557 | if (d) { | |
b464bac0 | 9558 | char * const olds = s; |
f63a84b2 | 9559 | s = d; |
3280af22 | 9560 | while (s < PL_bufend) { |
f63a84b2 LW |
9561 | if (*s == '\r') { |
9562 | *d++ = '\n'; | |
9563 | if (*++s == '\n') | |
9564 | s++; | |
9565 | } | |
9566 | else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */ | |
9567 | *d++ = *s++; | |
9568 | s++; | |
9569 | } | |
9570 | else | |
9571 | *d++ = *s++; | |
9572 | } | |
9573 | *d = '\0'; | |
3280af22 | 9574 | PL_bufend = d; |
95a20fc0 | 9575 | SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr)); |
f63a84b2 LW |
9576 | s = olds; |
9577 | } | |
9578 | #endif | |
73d840c0 AL |
9579 | if ( outer || !(found_newline = ninstr(s,PL_bufend,newline,newline+1)) ) { |
9580 | herewas = newSVpvn(s,PL_bufend-s); | |
9581 | } | |
9582 | else { | |
9583 | s--; | |
9584 | herewas = newSVpvn(s,found_newline-s); | |
9585 | } | |
79072805 | 9586 | s += SvCUR(herewas); |
748a9306 | 9587 | |
8d6dde3e | 9588 | tmpstr = NEWSV(87,79); |
748a9306 LW |
9589 | sv_upgrade(tmpstr, SVt_PVIV); |
9590 | if (term == '\'') { | |
79072805 | 9591 | op_type = OP_CONST; |
45977657 | 9592 | SvIV_set(tmpstr, -1); |
748a9306 LW |
9593 | } |
9594 | else if (term == '`') { | |
79072805 | 9595 | op_type = OP_BACKTICK; |
45977657 | 9596 | SvIV_set(tmpstr, '\\'); |
748a9306 | 9597 | } |
79072805 LW |
9598 | |
9599 | CLINE; | |
57843af0 | 9600 | PL_multi_start = CopLINE(PL_curcop); |
3280af22 NIS |
9601 | PL_multi_open = PL_multi_close = '<'; |
9602 | term = *PL_tokenbuf; | |
0244c3a4 GS |
9603 | if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) { |
9604 | char *bufptr = PL_sublex_info.super_bufptr; | |
9605 | char *bufend = PL_sublex_info.super_bufend; | |
b464bac0 | 9606 | char * const olds = s - SvCUR(herewas); |
0244c3a4 GS |
9607 | s = strchr(bufptr, '\n'); |
9608 | if (!s) | |
9609 | s = bufend; | |
9610 | d = s; | |
9611 | while (s < bufend && | |
9612 | (*s != term || memNE(s,PL_tokenbuf,len)) ) { | |
9613 | if (*s++ == '\n') | |
57843af0 | 9614 | CopLINE_inc(PL_curcop); |
0244c3a4 GS |
9615 | } |
9616 | if (s >= bufend) { | |
eb160463 | 9617 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
0244c3a4 GS |
9618 | missingterm(PL_tokenbuf); |
9619 | } | |
9620 | sv_setpvn(herewas,bufptr,d-bufptr+1); | |
9621 | sv_setpvn(tmpstr,d+1,s-d); | |
9622 | s += len - 1; | |
9623 | sv_catpvn(herewas,s,bufend-s); | |
95a20fc0 | 9624 | Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char); |
0244c3a4 GS |
9625 | |
9626 | s = olds; | |
9627 | goto retval; | |
9628 | } | |
9629 | else if (!outer) { | |
79072805 | 9630 | d = s; |
3280af22 NIS |
9631 | while (s < PL_bufend && |
9632 | (*s != term || memNE(s,PL_tokenbuf,len)) ) { | |
79072805 | 9633 | if (*s++ == '\n') |
57843af0 | 9634 | CopLINE_inc(PL_curcop); |
79072805 | 9635 | } |
3280af22 | 9636 | if (s >= PL_bufend) { |
eb160463 | 9637 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
3280af22 | 9638 | missingterm(PL_tokenbuf); |
79072805 LW |
9639 | } |
9640 | sv_setpvn(tmpstr,d+1,s-d); | |
9641 | s += len - 1; | |
57843af0 | 9642 | CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */ |
49d8d3a1 | 9643 | |
3280af22 NIS |
9644 | sv_catpvn(herewas,s,PL_bufend-s); |
9645 | sv_setsv(PL_linestr,herewas); | |
9646 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr); | |
9647 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 9648 | PL_last_lop = PL_last_uni = Nullch; |
79072805 LW |
9649 | } |
9650 | else | |
9651 | sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */ | |
3280af22 | 9652 | while (s >= PL_bufend) { /* multiple line string? */ |
fd2d0953 | 9653 | if (!outer || |
3280af22 | 9654 | !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { |
eb160463 | 9655 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
3280af22 | 9656 | missingterm(PL_tokenbuf); |
79072805 | 9657 | } |
57843af0 | 9658 | CopLINE_inc(PL_curcop); |
3280af22 | 9659 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 9660 | PL_last_lop = PL_last_uni = Nullch; |
6a27c188 | 9661 | #ifndef PERL_STRICT_CR |
3280af22 | 9662 | if (PL_bufend - PL_linestart >= 2) { |
a1529941 NIS |
9663 | if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') || |
9664 | (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r')) | |
c6f14548 | 9665 | { |
3280af22 NIS |
9666 | PL_bufend[-2] = '\n'; |
9667 | PL_bufend--; | |
95a20fc0 | 9668 | SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr)); |
f63a84b2 | 9669 | } |
3280af22 NIS |
9670 | else if (PL_bufend[-1] == '\r') |
9671 | PL_bufend[-1] = '\n'; | |
f63a84b2 | 9672 | } |
3280af22 NIS |
9673 | else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r') |
9674 | PL_bufend[-1] = '\n'; | |
f63a84b2 | 9675 | #endif |
3280af22 | 9676 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
79072805 LW |
9677 | SV *sv = NEWSV(88,0); |
9678 | ||
93a17b20 | 9679 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 9680 | sv_setsv(sv,PL_linestr); |
0ac0412a | 9681 | (void)SvIOK_on(sv); |
45977657 | 9682 | SvIV_set(sv, 0); |
57843af0 | 9683 | av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv); |
79072805 | 9684 | } |
3280af22 | 9685 | if (*s == term && memEQ(s,PL_tokenbuf,len)) { |
95a20fc0 | 9686 | STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr); |
1de9afcd | 9687 | *(SvPVX(PL_linestr) + off ) = ' '; |
3280af22 NIS |
9688 | sv_catsv(PL_linestr,herewas); |
9689 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
1de9afcd | 9690 | s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */ |
79072805 LW |
9691 | } |
9692 | else { | |
3280af22 NIS |
9693 | s = PL_bufend; |
9694 | sv_catsv(tmpstr,PL_linestr); | |
395c3793 LW |
9695 | } |
9696 | } | |
79072805 | 9697 | s++; |
0244c3a4 | 9698 | retval: |
57843af0 | 9699 | PL_multi_end = CopLINE(PL_curcop); |
79072805 | 9700 | if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) { |
1da4ca5f | 9701 | SvPV_shrink_to_cur(tmpstr); |
79072805 | 9702 | } |
8990e307 | 9703 | SvREFCNT_dec(herewas); |
2f31ce75 | 9704 | if (!IN_BYTES) { |
95a20fc0 | 9705 | if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr))) |
2f31ce75 JH |
9706 | SvUTF8_on(tmpstr); |
9707 | else if (PL_encoding) | |
9708 | sv_recode_to_utf8(tmpstr, PL_encoding); | |
9709 | } | |
3280af22 | 9710 | PL_lex_stuff = tmpstr; |
79072805 LW |
9711 | yylval.ival = op_type; |
9712 | return s; | |
9713 | } | |
9714 | ||
02aa26ce NT |
9715 | /* scan_inputsymbol |
9716 | takes: current position in input buffer | |
9717 | returns: new position in input buffer | |
9718 | side-effects: yylval and lex_op are set. | |
9719 | ||
9720 | This code handles: | |
9721 | ||
9722 | <> read from ARGV | |
9723 | <FH> read from filehandle | |
9724 | <pkg::FH> read from package qualified filehandle | |
9725 | <pkg'FH> read from package qualified filehandle | |
9726 | <$fh> read from filehandle in $fh | |
9727 | <*.h> filename glob | |
9728 | ||
9729 | */ | |
9730 | ||
76e3520e | 9731 | STATIC char * |
cea2e8a9 | 9732 | S_scan_inputsymbol(pTHX_ char *start) |
79072805 | 9733 | { |
02aa26ce | 9734 | register char *s = start; /* current position in buffer */ |
79072805 | 9735 | register char *d; |
cfd0369c | 9736 | const char *e; |
1b420867 | 9737 | char *end; |
79072805 LW |
9738 | I32 len; |
9739 | ||
3280af22 NIS |
9740 | d = PL_tokenbuf; /* start of temp holding space */ |
9741 | e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */ | |
1b420867 GS |
9742 | end = strchr(s, '\n'); |
9743 | if (!end) | |
9744 | end = PL_bufend; | |
9745 | s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */ | |
02aa26ce NT |
9746 | |
9747 | /* die if we didn't have space for the contents of the <>, | |
1b420867 | 9748 | or if it didn't end, or if we see a newline |
02aa26ce NT |
9749 | */ |
9750 | ||
3280af22 | 9751 | if (len >= sizeof PL_tokenbuf) |
cea2e8a9 | 9752 | Perl_croak(aTHX_ "Excessively long <> operator"); |
1b420867 | 9753 | if (s >= end) |
cea2e8a9 | 9754 | Perl_croak(aTHX_ "Unterminated <> operator"); |
02aa26ce | 9755 | |
fc36a67e | 9756 | s++; |
02aa26ce NT |
9757 | |
9758 | /* check for <$fh> | |
9759 | Remember, only scalar variables are interpreted as filehandles by | |
9760 | this code. Anything more complex (e.g., <$fh{$num}>) will be | |
9761 | treated as a glob() call. | |
9762 | This code makes use of the fact that except for the $ at the front, | |
9763 | a scalar variable and a filehandle look the same. | |
9764 | */ | |
4633a7c4 | 9765 | if (*d == '$' && d[1]) d++; |
02aa26ce NT |
9766 | |
9767 | /* allow <Pkg'VALUE> or <Pkg::VALUE> */ | |
7e2040f0 | 9768 | while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':')) |
79072805 | 9769 | d++; |
02aa26ce NT |
9770 | |
9771 | /* If we've tried to read what we allow filehandles to look like, and | |
9772 | there's still text left, then it must be a glob() and not a getline. | |
9773 | Use scan_str to pull out the stuff between the <> and treat it | |
9774 | as nothing more than a string. | |
9775 | */ | |
9776 | ||
3280af22 | 9777 | if (d - PL_tokenbuf != len) { |
79072805 LW |
9778 | yylval.ival = OP_GLOB; |
9779 | set_csh(); | |
09bef843 | 9780 | s = scan_str(start,FALSE,FALSE); |
79072805 | 9781 | if (!s) |
cea2e8a9 | 9782 | Perl_croak(aTHX_ "Glob not terminated"); |
79072805 LW |
9783 | return s; |
9784 | } | |
395c3793 | 9785 | else { |
9b3023bc RGS |
9786 | bool readline_overriden = FALSE; |
9787 | GV *gv_readline = Nullgv; | |
9788 | GV **gvp; | |
02aa26ce | 9789 | /* we're in a filehandle read situation */ |
3280af22 | 9790 | d = PL_tokenbuf; |
02aa26ce NT |
9791 | |
9792 | /* turn <> into <ARGV> */ | |
79072805 | 9793 | if (!len) |
689badd5 | 9794 | Copy("ARGV",d,5,char); |
02aa26ce | 9795 | |
9b3023bc | 9796 | /* Check whether readline() is overriden */ |
ba979b31 NIS |
9797 | if (((gv_readline = gv_fetchpv("readline", FALSE, SVt_PVCV)) |
9798 | && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)) | |
9b3023bc | 9799 | || |
ba979b31 | 9800 | ((gvp = (GV**)hv_fetch(PL_globalstash, "readline", 8, FALSE)) |
9b3023bc | 9801 | && (gv_readline = *gvp) != (GV*)&PL_sv_undef |
ba979b31 | 9802 | && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))) |
9b3023bc RGS |
9803 | readline_overriden = TRUE; |
9804 | ||
02aa26ce NT |
9805 | /* if <$fh>, create the ops to turn the variable into a |
9806 | filehandle | |
9807 | */ | |
79072805 | 9808 | if (*d == '$') { |
a0d0e21e | 9809 | I32 tmp; |
02aa26ce NT |
9810 | |
9811 | /* try to find it in the pad for this block, otherwise find | |
9812 | add symbol table ops | |
9813 | */ | |
11343788 | 9814 | if ((tmp = pad_findmy(d)) != NOT_IN_PAD) { |
dd2155a4 | 9815 | if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) { |
4b6dd97a NC |
9816 | HV *stash = PAD_COMPNAME_OURSTASH(tmp); |
9817 | HEK *stashname = HvNAME_HEK(stash); | |
5aaec2b4 | 9818 | SV *sym = sv_2mortal(newSVhek(stashname)); |
f558d5af JH |
9819 | sv_catpvn(sym, "::", 2); |
9820 | sv_catpv(sym, d+1); | |
9821 | d = SvPVX(sym); | |
9822 | goto intro_sym; | |
9823 | } | |
9824 | else { | |
9825 | OP *o = newOP(OP_PADSV, 0); | |
9826 | o->op_targ = tmp; | |
9b3023bc RGS |
9827 | PL_lex_op = readline_overriden |
9828 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, | |
9829 | append_elem(OP_LIST, o, | |
9830 | newCVREF(0, newGVOP(OP_GV,0,gv_readline)))) | |
9831 | : (OP*)newUNOP(OP_READLINE, 0, o); | |
f558d5af | 9832 | } |
a0d0e21e LW |
9833 | } |
9834 | else { | |
f558d5af JH |
9835 | GV *gv; |
9836 | ++d; | |
9837 | intro_sym: | |
9838 | gv = gv_fetchpv(d, | |
9839 | (PL_in_eval | |
9840 | ? (GV_ADDMULTI | GV_ADDINEVAL) | |
bea70d1e | 9841 | : GV_ADDMULTI), |
f558d5af | 9842 | SVt_PV); |
9b3023bc RGS |
9843 | PL_lex_op = readline_overriden |
9844 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, | |
9845 | append_elem(OP_LIST, | |
9846 | newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)), | |
9847 | newCVREF(0, newGVOP(OP_GV, 0, gv_readline)))) | |
9848 | : (OP*)newUNOP(OP_READLINE, 0, | |
9849 | newUNOP(OP_RV2SV, 0, | |
9850 | newGVOP(OP_GV, 0, gv))); | |
a0d0e21e | 9851 | } |
7c6fadd6 RGS |
9852 | if (!readline_overriden) |
9853 | PL_lex_op->op_flags |= OPf_SPECIAL; | |
f5284f61 | 9854 | /* we created the ops in PL_lex_op, so make yylval.ival a null op */ |
79072805 LW |
9855 | yylval.ival = OP_NULL; |
9856 | } | |
02aa26ce NT |
9857 | |
9858 | /* If it's none of the above, it must be a literal filehandle | |
9859 | (<Foo::BAR> or <FOO>) so build a simple readline OP */ | |
79072805 | 9860 | else { |
85e6fe83 | 9861 | GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO); |
9b3023bc RGS |
9862 | PL_lex_op = readline_overriden |
9863 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, | |
9864 | append_elem(OP_LIST, | |
9865 | newGVOP(OP_GV, 0, gv), | |
9866 | newCVREF(0, newGVOP(OP_GV, 0, gv_readline)))) | |
9867 | : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv)); | |
79072805 LW |
9868 | yylval.ival = OP_NULL; |
9869 | } | |
9870 | } | |
02aa26ce | 9871 | |
79072805 LW |
9872 | return s; |
9873 | } | |
9874 | ||
02aa26ce NT |
9875 | |
9876 | /* scan_str | |
9877 | takes: start position in buffer | |
09bef843 SB |
9878 | keep_quoted preserve \ on the embedded delimiter(s) |
9879 | keep_delims preserve the delimiters around the string | |
02aa26ce NT |
9880 | returns: position to continue reading from buffer |
9881 | side-effects: multi_start, multi_close, lex_repl or lex_stuff, and | |
9882 | updates the read buffer. | |
9883 | ||
9884 | This subroutine pulls a string out of the input. It is called for: | |
9885 | q single quotes q(literal text) | |
9886 | ' single quotes 'literal text' | |
9887 | qq double quotes qq(interpolate $here please) | |
9888 | " double quotes "interpolate $here please" | |
9889 | qx backticks qx(/bin/ls -l) | |
9890 | ` backticks `/bin/ls -l` | |
9891 | qw quote words @EXPORT_OK = qw( func() $spam ) | |
9892 | m// regexp match m/this/ | |
9893 | s/// regexp substitute s/this/that/ | |
9894 | tr/// string transliterate tr/this/that/ | |
9895 | y/// string transliterate y/this/that/ | |
9896 | ($*@) sub prototypes sub foo ($) | |
09bef843 | 9897 | (stuff) sub attr parameters sub foo : attr(stuff) |
02aa26ce NT |
9898 | <> readline or globs <FOO>, <>, <$fh>, or <*.c> |
9899 | ||
9900 | In most of these cases (all but <>, patterns and transliterate) | |
9901 | yylex() calls scan_str(). m// makes yylex() call scan_pat() which | |
9902 | calls scan_str(). s/// makes yylex() call scan_subst() which calls | |
9903 | scan_str(). tr/// and y/// make yylex() call scan_trans() which | |
9904 | calls scan_str(). | |
4e553d73 | 9905 | |
02aa26ce NT |
9906 | It skips whitespace before the string starts, and treats the first |
9907 | character as the delimiter. If the delimiter is one of ([{< then | |
9908 | the corresponding "close" character )]}> is used as the closing | |
9909 | delimiter. It allows quoting of delimiters, and if the string has | |
9910 | balanced delimiters ([{<>}]) it allows nesting. | |
9911 | ||
37fd879b HS |
9912 | On success, the SV with the resulting string is put into lex_stuff or, |
9913 | if that is already non-NULL, into lex_repl. The second case occurs only | |
9914 | when parsing the RHS of the special constructs s/// and tr/// (y///). | |
9915 | For convenience, the terminating delimiter character is stuffed into | |
9916 | SvIVX of the SV. | |
02aa26ce NT |
9917 | */ |
9918 | ||
76e3520e | 9919 | STATIC char * |
09bef843 | 9920 | S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims) |
79072805 | 9921 | { |
02aa26ce NT |
9922 | SV *sv; /* scalar value: string */ |
9923 | char *tmps; /* temp string, used for delimiter matching */ | |
9924 | register char *s = start; /* current position in the buffer */ | |
9925 | register char term; /* terminating character */ | |
9926 | register char *to; /* current position in the sv's data */ | |
9927 | I32 brackets = 1; /* bracket nesting level */ | |
89491803 | 9928 | bool has_utf8 = FALSE; /* is there any utf8 content? */ |
220e2d4e | 9929 | I32 termcode; /* terminating char. code */ |
89ebb4a3 | 9930 | U8 termstr[UTF8_MAXBYTES]; /* terminating string */ |
220e2d4e IH |
9931 | STRLEN termlen; /* length of terminating string */ |
9932 | char *last = NULL; /* last position for nesting bracket */ | |
02aa26ce NT |
9933 | |
9934 | /* skip space before the delimiter */ | |
fb73857a | 9935 | if (isSPACE(*s)) |
9936 | s = skipspace(s); | |
02aa26ce NT |
9937 | |
9938 | /* mark where we are, in case we need to report errors */ | |
79072805 | 9939 | CLINE; |
02aa26ce NT |
9940 | |
9941 | /* after skipping whitespace, the next character is the terminator */ | |
a0d0e21e | 9942 | term = *s; |
220e2d4e IH |
9943 | if (!UTF) { |
9944 | termcode = termstr[0] = term; | |
9945 | termlen = 1; | |
9946 | } | |
9947 | else { | |
f3b9ce0f | 9948 | termcode = utf8_to_uvchr((U8*)s, &termlen); |
220e2d4e IH |
9949 | Copy(s, termstr, termlen, U8); |
9950 | if (!UTF8_IS_INVARIANT(term)) | |
9951 | has_utf8 = TRUE; | |
9952 | } | |
b1c7b182 | 9953 | |
02aa26ce | 9954 | /* mark where we are */ |
57843af0 | 9955 | PL_multi_start = CopLINE(PL_curcop); |
3280af22 | 9956 | PL_multi_open = term; |
02aa26ce NT |
9957 | |
9958 | /* find corresponding closing delimiter */ | |
93a17b20 | 9959 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) |
220e2d4e IH |
9960 | termcode = termstr[0] = term = tmps[5]; |
9961 | ||
3280af22 | 9962 | PL_multi_close = term; |
79072805 | 9963 | |
02aa26ce | 9964 | /* create a new SV to hold the contents. 87 is leak category, I'm |
8d6dde3e IZ |
9965 | assuming. 79 is the SV's initial length. What a random number. */ |
9966 | sv = NEWSV(87,79); | |
ed6116ce | 9967 | sv_upgrade(sv, SVt_PVIV); |
45977657 | 9968 | SvIV_set(sv, termcode); |
a0d0e21e | 9969 | (void)SvPOK_only(sv); /* validate pointer */ |
02aa26ce NT |
9970 | |
9971 | /* move past delimiter and try to read a complete string */ | |
09bef843 | 9972 | if (keep_delims) |
220e2d4e IH |
9973 | sv_catpvn(sv, s, termlen); |
9974 | s += termlen; | |
93a17b20 | 9975 | for (;;) { |
220e2d4e IH |
9976 | if (PL_encoding && !UTF) { |
9977 | bool cont = TRUE; | |
9978 | ||
9979 | while (cont) { | |
95a20fc0 | 9980 | int offset = s - SvPVX_const(PL_linestr); |
66a1b24b | 9981 | const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr, |
f3b9ce0f | 9982 | &offset, (char*)termstr, termlen); |
95a20fc0 | 9983 | const char *ns = SvPVX_const(PL_linestr) + offset; |
220e2d4e IH |
9984 | char *svlast = SvEND(sv) - 1; |
9985 | ||
9986 | for (; s < ns; s++) { | |
9987 | if (*s == '\n' && !PL_rsfp) | |
9988 | CopLINE_inc(PL_curcop); | |
9989 | } | |
9990 | if (!found) | |
9991 | goto read_more_line; | |
9992 | else { | |
9993 | /* handle quoted delimiters */ | |
52327caf | 9994 | if (SvCUR(sv) > 1 && *(svlast-1) == '\\') { |
f54cb97a | 9995 | const char *t; |
95a20fc0 | 9996 | for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';) |
220e2d4e IH |
9997 | t--; |
9998 | if ((svlast-1 - t) % 2) { | |
9999 | if (!keep_quoted) { | |
10000 | *(svlast-1) = term; | |
10001 | *svlast = '\0'; | |
10002 | SvCUR_set(sv, SvCUR(sv) - 1); | |
10003 | } | |
10004 | continue; | |
10005 | } | |
10006 | } | |
10007 | if (PL_multi_open == PL_multi_close) { | |
10008 | cont = FALSE; | |
10009 | } | |
10010 | else { | |
f54cb97a AL |
10011 | const char *t; |
10012 | char *w; | |
220e2d4e IH |
10013 | if (!last) |
10014 | last = SvPVX(sv); | |
f54cb97a | 10015 | for (t = w = last; t < svlast; w++, t++) { |
220e2d4e IH |
10016 | /* At here, all closes are "was quoted" one, |
10017 | so we don't check PL_multi_close. */ | |
10018 | if (*t == '\\') { | |
10019 | if (!keep_quoted && *(t+1) == PL_multi_open) | |
10020 | t++; | |
10021 | else | |
10022 | *w++ = *t++; | |
10023 | } | |
10024 | else if (*t == PL_multi_open) | |
10025 | brackets++; | |
10026 | ||
10027 | *w = *t; | |
10028 | } | |
10029 | if (w < t) { | |
10030 | *w++ = term; | |
10031 | *w = '\0'; | |
95a20fc0 | 10032 | SvCUR_set(sv, w - SvPVX_const(sv)); |
220e2d4e IH |
10033 | } |
10034 | last = w; | |
10035 | if (--brackets <= 0) | |
10036 | cont = FALSE; | |
10037 | } | |
10038 | } | |
10039 | } | |
10040 | if (!keep_delims) { | |
10041 | SvCUR_set(sv, SvCUR(sv) - 1); | |
10042 | *SvEND(sv) = '\0'; | |
10043 | } | |
10044 | break; | |
10045 | } | |
10046 | ||
02aa26ce | 10047 | /* extend sv if need be */ |
3280af22 | 10048 | SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1); |
02aa26ce | 10049 | /* set 'to' to the next character in the sv's string */ |
463ee0b2 | 10050 | to = SvPVX(sv)+SvCUR(sv); |
09bef843 | 10051 | |
02aa26ce | 10052 | /* if open delimiter is the close delimiter read unbridle */ |
3280af22 NIS |
10053 | if (PL_multi_open == PL_multi_close) { |
10054 | for (; s < PL_bufend; s++,to++) { | |
02aa26ce | 10055 | /* embedded newlines increment the current line number */ |
3280af22 | 10056 | if (*s == '\n' && !PL_rsfp) |
57843af0 | 10057 | CopLINE_inc(PL_curcop); |
02aa26ce | 10058 | /* handle quoted delimiters */ |
3280af22 | 10059 | if (*s == '\\' && s+1 < PL_bufend && term != '\\') { |
09bef843 | 10060 | if (!keep_quoted && s[1] == term) |
a0d0e21e | 10061 | s++; |
02aa26ce | 10062 | /* any other quotes are simply copied straight through */ |
a0d0e21e LW |
10063 | else |
10064 | *to++ = *s++; | |
10065 | } | |
02aa26ce NT |
10066 | /* terminate when run out of buffer (the for() condition), or |
10067 | have found the terminator */ | |
220e2d4e IH |
10068 | else if (*s == term) { |
10069 | if (termlen == 1) | |
10070 | break; | |
f3b9ce0f | 10071 | if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen)) |
220e2d4e IH |
10072 | break; |
10073 | } | |
63cd0674 | 10074 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
89491803 | 10075 | has_utf8 = TRUE; |
93a17b20 LW |
10076 | *to = *s; |
10077 | } | |
10078 | } | |
02aa26ce NT |
10079 | |
10080 | /* if the terminator isn't the same as the start character (e.g., | |
10081 | matched brackets), we have to allow more in the quoting, and | |
10082 | be prepared for nested brackets. | |
10083 | */ | |
93a17b20 | 10084 | else { |
02aa26ce | 10085 | /* read until we run out of string, or we find the terminator */ |
3280af22 | 10086 | for (; s < PL_bufend; s++,to++) { |
02aa26ce | 10087 | /* embedded newlines increment the line count */ |
3280af22 | 10088 | if (*s == '\n' && !PL_rsfp) |
57843af0 | 10089 | CopLINE_inc(PL_curcop); |
02aa26ce | 10090 | /* backslashes can escape the open or closing characters */ |
3280af22 | 10091 | if (*s == '\\' && s+1 < PL_bufend) { |
09bef843 SB |
10092 | if (!keep_quoted && |
10093 | ((s[1] == PL_multi_open) || (s[1] == PL_multi_close))) | |
a0d0e21e LW |
10094 | s++; |
10095 | else | |
10096 | *to++ = *s++; | |
10097 | } | |
02aa26ce | 10098 | /* allow nested opens and closes */ |
3280af22 | 10099 | else if (*s == PL_multi_close && --brackets <= 0) |
93a17b20 | 10100 | break; |
3280af22 | 10101 | else if (*s == PL_multi_open) |
93a17b20 | 10102 | brackets++; |
63cd0674 | 10103 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
89491803 | 10104 | has_utf8 = TRUE; |
93a17b20 LW |
10105 | *to = *s; |
10106 | } | |
10107 | } | |
02aa26ce | 10108 | /* terminate the copied string and update the sv's end-of-string */ |
93a17b20 | 10109 | *to = '\0'; |
95a20fc0 | 10110 | SvCUR_set(sv, to - SvPVX_const(sv)); |
93a17b20 | 10111 | |
02aa26ce NT |
10112 | /* |
10113 | * this next chunk reads more into the buffer if we're not done yet | |
10114 | */ | |
10115 | ||
b1c7b182 GS |
10116 | if (s < PL_bufend) |
10117 | break; /* handle case where we are done yet :-) */ | |
79072805 | 10118 | |
6a27c188 | 10119 | #ifndef PERL_STRICT_CR |
95a20fc0 | 10120 | if (to - SvPVX_const(sv) >= 2) { |
c6f14548 GS |
10121 | if ((to[-2] == '\r' && to[-1] == '\n') || |
10122 | (to[-2] == '\n' && to[-1] == '\r')) | |
10123 | { | |
f63a84b2 LW |
10124 | to[-2] = '\n'; |
10125 | to--; | |
95a20fc0 | 10126 | SvCUR_set(sv, to - SvPVX_const(sv)); |
f63a84b2 LW |
10127 | } |
10128 | else if (to[-1] == '\r') | |
10129 | to[-1] = '\n'; | |
10130 | } | |
95a20fc0 | 10131 | else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r') |
f63a84b2 LW |
10132 | to[-1] = '\n'; |
10133 | #endif | |
10134 | ||
220e2d4e | 10135 | read_more_line: |
02aa26ce NT |
10136 | /* if we're out of file, or a read fails, bail and reset the current |
10137 | line marker so we can report where the unterminated string began | |
10138 | */ | |
3280af22 NIS |
10139 | if (!PL_rsfp || |
10140 | !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { | |
c07a80fd | 10141 | sv_free(sv); |
eb160463 | 10142 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
79072805 LW |
10143 | return Nullch; |
10144 | } | |
02aa26ce | 10145 | /* we read a line, so increment our line counter */ |
57843af0 | 10146 | CopLINE_inc(PL_curcop); |
a0ed51b3 | 10147 | |
02aa26ce | 10148 | /* update debugger info */ |
3280af22 | 10149 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
79072805 LW |
10150 | SV *sv = NEWSV(88,0); |
10151 | ||
93a17b20 | 10152 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 10153 | sv_setsv(sv,PL_linestr); |
0ac0412a | 10154 | (void)SvIOK_on(sv); |
45977657 | 10155 | SvIV_set(sv, 0); |
57843af0 | 10156 | av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv); |
395c3793 | 10157 | } |
a0ed51b3 | 10158 | |
3280af22 NIS |
10159 | /* having changed the buffer, we must update PL_bufend */ |
10160 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 10161 | PL_last_lop = PL_last_uni = Nullch; |
378cc40b | 10162 | } |
4e553d73 | 10163 | |
02aa26ce NT |
10164 | /* at this point, we have successfully read the delimited string */ |
10165 | ||
220e2d4e IH |
10166 | if (!PL_encoding || UTF) { |
10167 | if (keep_delims) | |
10168 | sv_catpvn(sv, s, termlen); | |
10169 | s += termlen; | |
10170 | } | |
10171 | if (has_utf8 || PL_encoding) | |
b1c7b182 | 10172 | SvUTF8_on(sv); |
d0063567 | 10173 | |
57843af0 | 10174 | PL_multi_end = CopLINE(PL_curcop); |
02aa26ce NT |
10175 | |
10176 | /* if we allocated too much space, give some back */ | |
93a17b20 LW |
10177 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
10178 | SvLEN_set(sv, SvCUR(sv) + 1); | |
b7e9a5c2 | 10179 | SvPV_renew(sv, SvLEN(sv)); |
79072805 | 10180 | } |
02aa26ce NT |
10181 | |
10182 | /* decide whether this is the first or second quoted string we've read | |
10183 | for this op | |
10184 | */ | |
4e553d73 | 10185 | |
3280af22 NIS |
10186 | if (PL_lex_stuff) |
10187 | PL_lex_repl = sv; | |
79072805 | 10188 | else |
3280af22 | 10189 | PL_lex_stuff = sv; |
378cc40b LW |
10190 | return s; |
10191 | } | |
10192 | ||
02aa26ce NT |
10193 | /* |
10194 | scan_num | |
10195 | takes: pointer to position in buffer | |
10196 | returns: pointer to new position in buffer | |
10197 | side-effects: builds ops for the constant in yylval.op | |
10198 | ||
10199 | Read a number in any of the formats that Perl accepts: | |
10200 | ||
7fd134d9 JH |
10201 | \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12. |
10202 | \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34 | |
24138b49 JH |
10203 | 0b[01](_?[01])* |
10204 | 0[0-7](_?[0-7])* | |
10205 | 0x[0-9A-Fa-f](_?[0-9A-Fa-f])* | |
02aa26ce | 10206 | |
3280af22 | 10207 | Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the |
02aa26ce NT |
10208 | thing it reads. |
10209 | ||
10210 | If it reads a number without a decimal point or an exponent, it will | |
10211 | try converting the number to an integer and see if it can do so | |
10212 | without loss of precision. | |
10213 | */ | |
4e553d73 | 10214 | |
378cc40b | 10215 | char * |
bfed75c6 | 10216 | Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp) |
378cc40b | 10217 | { |
bfed75c6 | 10218 | register const char *s = start; /* current position in buffer */ |
02aa26ce NT |
10219 | register char *d; /* destination in temp buffer */ |
10220 | register char *e; /* end of temp buffer */ | |
86554af2 | 10221 | NV nv; /* number read, as a double */ |
a7cb1f99 | 10222 | SV *sv = Nullsv; /* place to put the converted number */ |
a86a20aa | 10223 | bool floatit; /* boolean: int or float? */ |
bfed75c6 AL |
10224 | const char *lastub = 0; /* position of last underbar */ |
10225 | static char const number_too_long[] = "Number too long"; | |
378cc40b | 10226 | |
02aa26ce NT |
10227 | /* We use the first character to decide what type of number this is */ |
10228 | ||
378cc40b | 10229 | switch (*s) { |
79072805 | 10230 | default: |
cea2e8a9 | 10231 | Perl_croak(aTHX_ "panic: scan_num"); |
4e553d73 | 10232 | |
02aa26ce | 10233 | /* if it starts with a 0, it could be an octal number, a decimal in |
a7cb1f99 | 10234 | 0.13 disguise, or a hexadecimal number, or a binary number. */ |
378cc40b LW |
10235 | case '0': |
10236 | { | |
02aa26ce NT |
10237 | /* variables: |
10238 | u holds the "number so far" | |
4f19785b WSI |
10239 | shift the power of 2 of the base |
10240 | (hex == 4, octal == 3, binary == 1) | |
02aa26ce NT |
10241 | overflowed was the number more than we can hold? |
10242 | ||
10243 | Shift is used when we add a digit. It also serves as an "are | |
4f19785b WSI |
10244 | we in octal/hex/binary?" indicator to disallow hex characters |
10245 | when in octal mode. | |
02aa26ce | 10246 | */ |
9e24b6e2 JH |
10247 | NV n = 0.0; |
10248 | UV u = 0; | |
79072805 | 10249 | I32 shift; |
9e24b6e2 | 10250 | bool overflowed = FALSE; |
61f33854 | 10251 | bool just_zero = TRUE; /* just plain 0 or binary number? */ |
27da23d5 JH |
10252 | static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 }; |
10253 | static const char* const bases[5] = | |
10254 | { "", "binary", "", "octal", "hexadecimal" }; | |
10255 | static const char* const Bases[5] = | |
10256 | { "", "Binary", "", "Octal", "Hexadecimal" }; | |
10257 | static const char* const maxima[5] = | |
10258 | { "", | |
10259 | "0b11111111111111111111111111111111", | |
10260 | "", | |
10261 | "037777777777", | |
10262 | "0xffffffff" }; | |
bfed75c6 | 10263 | const char *base, *Base, *max; |
378cc40b | 10264 | |
02aa26ce | 10265 | /* check for hex */ |
378cc40b LW |
10266 | if (s[1] == 'x') { |
10267 | shift = 4; | |
10268 | s += 2; | |
61f33854 | 10269 | just_zero = FALSE; |
4f19785b WSI |
10270 | } else if (s[1] == 'b') { |
10271 | shift = 1; | |
10272 | s += 2; | |
61f33854 | 10273 | just_zero = FALSE; |
378cc40b | 10274 | } |
02aa26ce | 10275 | /* check for a decimal in disguise */ |
b78218b7 | 10276 | else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E') |
378cc40b | 10277 | goto decimal; |
02aa26ce | 10278 | /* so it must be octal */ |
928753ea | 10279 | else { |
378cc40b | 10280 | shift = 3; |
928753ea JH |
10281 | s++; |
10282 | } | |
10283 | ||
10284 | if (*s == '_') { | |
10285 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10286 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10287 | "Misplaced _ in number"); |
10288 | lastub = s++; | |
10289 | } | |
9e24b6e2 JH |
10290 | |
10291 | base = bases[shift]; | |
10292 | Base = Bases[shift]; | |
10293 | max = maxima[shift]; | |
02aa26ce | 10294 | |
4f19785b | 10295 | /* read the rest of the number */ |
378cc40b | 10296 | for (;;) { |
9e24b6e2 | 10297 | /* x is used in the overflow test, |
893fe2c2 | 10298 | b is the digit we're adding on. */ |
9e24b6e2 | 10299 | UV x, b; |
55497cff | 10300 | |
378cc40b | 10301 | switch (*s) { |
02aa26ce NT |
10302 | |
10303 | /* if we don't mention it, we're done */ | |
378cc40b LW |
10304 | default: |
10305 | goto out; | |
02aa26ce | 10306 | |
928753ea | 10307 | /* _ are ignored -- but warned about if consecutive */ |
de3bb511 | 10308 | case '_': |
041457d9 | 10309 | if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX)) |
9014280d | 10310 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10311 | "Misplaced _ in number"); |
10312 | lastub = s++; | |
de3bb511 | 10313 | break; |
02aa26ce NT |
10314 | |
10315 | /* 8 and 9 are not octal */ | |
378cc40b | 10316 | case '8': case '9': |
4f19785b | 10317 | if (shift == 3) |
cea2e8a9 | 10318 | yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s)); |
378cc40b | 10319 | /* FALL THROUGH */ |
02aa26ce NT |
10320 | |
10321 | /* octal digits */ | |
4f19785b | 10322 | case '2': case '3': case '4': |
378cc40b | 10323 | case '5': case '6': case '7': |
4f19785b | 10324 | if (shift == 1) |
cea2e8a9 | 10325 | yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s)); |
4f19785b WSI |
10326 | /* FALL THROUGH */ |
10327 | ||
10328 | case '0': case '1': | |
02aa26ce | 10329 | b = *s++ & 15; /* ASCII digit -> value of digit */ |
55497cff | 10330 | goto digit; |
02aa26ce NT |
10331 | |
10332 | /* hex digits */ | |
378cc40b LW |
10333 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': |
10334 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': | |
02aa26ce | 10335 | /* make sure they said 0x */ |
378cc40b LW |
10336 | if (shift != 4) |
10337 | goto out; | |
55497cff | 10338 | b = (*s++ & 7) + 9; |
02aa26ce NT |
10339 | |
10340 | /* Prepare to put the digit we have onto the end | |
10341 | of the number so far. We check for overflows. | |
10342 | */ | |
10343 | ||
55497cff | 10344 | digit: |
61f33854 | 10345 | just_zero = FALSE; |
9e24b6e2 JH |
10346 | if (!overflowed) { |
10347 | x = u << shift; /* make room for the digit */ | |
10348 | ||
10349 | if ((x >> shift) != u | |
10350 | && !(PL_hints & HINT_NEW_BINARY)) { | |
9e24b6e2 JH |
10351 | overflowed = TRUE; |
10352 | n = (NV) u; | |
767a6a26 | 10353 | if (ckWARN_d(WARN_OVERFLOW)) |
9014280d | 10354 | Perl_warner(aTHX_ packWARN(WARN_OVERFLOW), |
9e24b6e2 JH |
10355 | "Integer overflow in %s number", |
10356 | base); | |
10357 | } else | |
10358 | u = x | b; /* add the digit to the end */ | |
10359 | } | |
10360 | if (overflowed) { | |
10361 | n *= nvshift[shift]; | |
10362 | /* If an NV has not enough bits in its | |
10363 | * mantissa to represent an UV this summing of | |
10364 | * small low-order numbers is a waste of time | |
10365 | * (because the NV cannot preserve the | |
10366 | * low-order bits anyway): we could just | |
10367 | * remember when did we overflow and in the | |
10368 | * end just multiply n by the right | |
10369 | * amount. */ | |
10370 | n += (NV) b; | |
55497cff | 10371 | } |
378cc40b LW |
10372 | break; |
10373 | } | |
10374 | } | |
02aa26ce NT |
10375 | |
10376 | /* if we get here, we had success: make a scalar value from | |
10377 | the number. | |
10378 | */ | |
378cc40b | 10379 | out: |
928753ea JH |
10380 | |
10381 | /* final misplaced underbar check */ | |
10382 | if (s[-1] == '_') { | |
10383 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10384 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number"); |
928753ea JH |
10385 | } |
10386 | ||
79072805 | 10387 | sv = NEWSV(92,0); |
9e24b6e2 | 10388 | if (overflowed) { |
041457d9 | 10389 | if (n > 4294967295.0 && ckWARN(WARN_PORTABLE)) |
9014280d | 10390 | Perl_warner(aTHX_ packWARN(WARN_PORTABLE), |
9e24b6e2 JH |
10391 | "%s number > %s non-portable", |
10392 | Base, max); | |
10393 | sv_setnv(sv, n); | |
10394 | } | |
10395 | else { | |
15041a67 | 10396 | #if UVSIZE > 4 |
041457d9 | 10397 | if (u > 0xffffffff && ckWARN(WARN_PORTABLE)) |
9014280d | 10398 | Perl_warner(aTHX_ packWARN(WARN_PORTABLE), |
9e24b6e2 JH |
10399 | "%s number > %s non-portable", |
10400 | Base, max); | |
2cc4c2dc | 10401 | #endif |
9e24b6e2 JH |
10402 | sv_setuv(sv, u); |
10403 | } | |
61f33854 | 10404 | if (just_zero && (PL_hints & HINT_NEW_INTEGER)) |
bfed75c6 | 10405 | sv = new_constant(start, s - start, "integer", |
61f33854 RGS |
10406 | sv, Nullsv, NULL); |
10407 | else if (PL_hints & HINT_NEW_BINARY) | |
b3ac6de7 | 10408 | sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL); |
378cc40b LW |
10409 | } |
10410 | break; | |
02aa26ce NT |
10411 | |
10412 | /* | |
10413 | handle decimal numbers. | |
10414 | we're also sent here when we read a 0 as the first digit | |
10415 | */ | |
378cc40b LW |
10416 | case '1': case '2': case '3': case '4': case '5': |
10417 | case '6': case '7': case '8': case '9': case '.': | |
10418 | decimal: | |
3280af22 NIS |
10419 | d = PL_tokenbuf; |
10420 | e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */ | |
79072805 | 10421 | floatit = FALSE; |
02aa26ce NT |
10422 | |
10423 | /* read next group of digits and _ and copy into d */ | |
de3bb511 | 10424 | while (isDIGIT(*s) || *s == '_') { |
4e553d73 | 10425 | /* skip underscores, checking for misplaced ones |
02aa26ce NT |
10426 | if -w is on |
10427 | */ | |
93a17b20 | 10428 | if (*s == '_') { |
041457d9 | 10429 | if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX)) |
9014280d | 10430 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10431 | "Misplaced _ in number"); |
10432 | lastub = s++; | |
93a17b20 | 10433 | } |
fc36a67e | 10434 | else { |
02aa26ce | 10435 | /* check for end of fixed-length buffer */ |
fc36a67e | 10436 | if (d >= e) |
cea2e8a9 | 10437 | Perl_croak(aTHX_ number_too_long); |
02aa26ce | 10438 | /* if we're ok, copy the character */ |
378cc40b | 10439 | *d++ = *s++; |
fc36a67e | 10440 | } |
378cc40b | 10441 | } |
02aa26ce NT |
10442 | |
10443 | /* final misplaced underbar check */ | |
928753ea | 10444 | if (lastub && s == lastub + 1) { |
d008e5eb | 10445 | if (ckWARN(WARN_SYNTAX)) |
9014280d | 10446 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number"); |
d008e5eb | 10447 | } |
02aa26ce NT |
10448 | |
10449 | /* read a decimal portion if there is one. avoid | |
10450 | 3..5 being interpreted as the number 3. followed | |
10451 | by .5 | |
10452 | */ | |
2f3197b3 | 10453 | if (*s == '.' && s[1] != '.') { |
79072805 | 10454 | floatit = TRUE; |
378cc40b | 10455 | *d++ = *s++; |
02aa26ce | 10456 | |
928753ea JH |
10457 | if (*s == '_') { |
10458 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10459 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10460 | "Misplaced _ in number"); |
10461 | lastub = s; | |
10462 | } | |
10463 | ||
10464 | /* copy, ignoring underbars, until we run out of digits. | |
02aa26ce | 10465 | */ |
fc36a67e | 10466 | for (; isDIGIT(*s) || *s == '_'; s++) { |
02aa26ce | 10467 | /* fixed length buffer check */ |
fc36a67e | 10468 | if (d >= e) |
cea2e8a9 | 10469 | Perl_croak(aTHX_ number_too_long); |
928753ea | 10470 | if (*s == '_') { |
041457d9 | 10471 | if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX)) |
9014280d | 10472 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10473 | "Misplaced _ in number"); |
10474 | lastub = s; | |
10475 | } | |
10476 | else | |
fc36a67e | 10477 | *d++ = *s; |
378cc40b | 10478 | } |
928753ea JH |
10479 | /* fractional part ending in underbar? */ |
10480 | if (s[-1] == '_') { | |
10481 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10482 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10483 | "Misplaced _ in number"); |
10484 | } | |
dd629d5b GS |
10485 | if (*s == '.' && isDIGIT(s[1])) { |
10486 | /* oops, it's really a v-string, but without the "v" */ | |
f4758303 | 10487 | s = start; |
dd629d5b GS |
10488 | goto vstring; |
10489 | } | |
378cc40b | 10490 | } |
02aa26ce NT |
10491 | |
10492 | /* read exponent part, if present */ | |
3792a11b | 10493 | if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) { |
79072805 LW |
10494 | floatit = TRUE; |
10495 | s++; | |
02aa26ce NT |
10496 | |
10497 | /* regardless of whether user said 3E5 or 3e5, use lower 'e' */ | |
79072805 | 10498 | *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */ |
02aa26ce | 10499 | |
7fd134d9 JH |
10500 | /* stray preinitial _ */ |
10501 | if (*s == '_') { | |
10502 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10503 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
7fd134d9 JH |
10504 | "Misplaced _ in number"); |
10505 | lastub = s++; | |
10506 | } | |
10507 | ||
02aa26ce | 10508 | /* allow positive or negative exponent */ |
378cc40b LW |
10509 | if (*s == '+' || *s == '-') |
10510 | *d++ = *s++; | |
02aa26ce | 10511 | |
7fd134d9 JH |
10512 | /* stray initial _ */ |
10513 | if (*s == '_') { | |
10514 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10515 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
7fd134d9 JH |
10516 | "Misplaced _ in number"); |
10517 | lastub = s++; | |
10518 | } | |
10519 | ||
7fd134d9 JH |
10520 | /* read digits of exponent */ |
10521 | while (isDIGIT(*s) || *s == '_') { | |
10522 | if (isDIGIT(*s)) { | |
10523 | if (d >= e) | |
10524 | Perl_croak(aTHX_ number_too_long); | |
b3b48e3e | 10525 | *d++ = *s++; |
7fd134d9 JH |
10526 | } |
10527 | else { | |
041457d9 DM |
10528 | if (((lastub && s == lastub + 1) || |
10529 | (!isDIGIT(s[1]) && s[1] != '_')) | |
10530 | && ckWARN(WARN_SYNTAX)) | |
9014280d | 10531 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
7fd134d9 | 10532 | "Misplaced _ in number"); |
b3b48e3e | 10533 | lastub = s++; |
7fd134d9 | 10534 | } |
7fd134d9 | 10535 | } |
378cc40b | 10536 | } |
02aa26ce | 10537 | |
02aa26ce NT |
10538 | |
10539 | /* make an sv from the string */ | |
79072805 | 10540 | sv = NEWSV(92,0); |
097ee67d | 10541 | |
0b7fceb9 | 10542 | /* |
58bb9ec3 NC |
10543 | We try to do an integer conversion first if no characters |
10544 | indicating "float" have been found. | |
0b7fceb9 MU |
10545 | */ |
10546 | ||
10547 | if (!floatit) { | |
58bb9ec3 NC |
10548 | UV uv; |
10549 | int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv); | |
10550 | ||
10551 | if (flags == IS_NUMBER_IN_UV) { | |
10552 | if (uv <= IV_MAX) | |
86554af2 | 10553 | sv_setiv(sv, uv); /* Prefer IVs over UVs. */ |
58bb9ec3 | 10554 | else |
c239479b | 10555 | sv_setuv(sv, uv); |
58bb9ec3 NC |
10556 | } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) { |
10557 | if (uv <= (UV) IV_MIN) | |
10558 | sv_setiv(sv, -(IV)uv); | |
10559 | else | |
10560 | floatit = TRUE; | |
10561 | } else | |
10562 | floatit = TRUE; | |
10563 | } | |
0b7fceb9 | 10564 | if (floatit) { |
58bb9ec3 NC |
10565 | /* terminate the string */ |
10566 | *d = '\0'; | |
86554af2 JH |
10567 | nv = Atof(PL_tokenbuf); |
10568 | sv_setnv(sv, nv); | |
10569 | } | |
86554af2 | 10570 | |
b8403495 JH |
10571 | if ( floatit ? (PL_hints & HINT_NEW_FLOAT) : |
10572 | (PL_hints & HINT_NEW_INTEGER) ) | |
4e553d73 | 10573 | sv = new_constant(PL_tokenbuf, d - PL_tokenbuf, |
b8403495 JH |
10574 | (floatit ? "float" : "integer"), |
10575 | sv, Nullsv, NULL); | |
378cc40b | 10576 | break; |
0b7fceb9 | 10577 | |
e312add1 | 10578 | /* if it starts with a v, it could be a v-string */ |
a7cb1f99 | 10579 | case 'v': |
dd629d5b | 10580 | vstring: |
f4758303 | 10581 | sv = NEWSV(92,5); /* preallocate storage space */ |
b0f01acb | 10582 | s = scan_vstring(s,sv); |
a7cb1f99 | 10583 | break; |
79072805 | 10584 | } |
a687059c | 10585 | |
02aa26ce NT |
10586 | /* make the op for the constant and return */ |
10587 | ||
a86a20aa | 10588 | if (sv) |
b73d6f50 | 10589 | lvalp->opval = newSVOP(OP_CONST, 0, sv); |
a7cb1f99 | 10590 | else |
b73d6f50 | 10591 | lvalp->opval = Nullop; |
a687059c | 10592 | |
73d840c0 | 10593 | return (char *)s; |
378cc40b LW |
10594 | } |
10595 | ||
76e3520e | 10596 | STATIC char * |
cea2e8a9 | 10597 | S_scan_formline(pTHX_ register char *s) |
378cc40b | 10598 | { |
79072805 | 10599 | register char *eol; |
378cc40b | 10600 | register char *t; |
79cb57f6 | 10601 | SV *stuff = newSVpvn("",0); |
79072805 | 10602 | bool needargs = FALSE; |
c5ee2135 | 10603 | bool eofmt = FALSE; |
378cc40b | 10604 | |
79072805 | 10605 | while (!needargs) { |
a1b95068 | 10606 | if (*s == '.') { |
51882d45 | 10607 | #ifdef PERL_STRICT_CR |
bf4acbe4 | 10608 | for (t = s+1;SPACE_OR_TAB(*t); t++) ; |
51882d45 | 10609 | #else |
bf4acbe4 | 10610 | for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ; |
51882d45 | 10611 | #endif |
c5ee2135 WL |
10612 | if (*t == '\n' || t == PL_bufend) { |
10613 | eofmt = TRUE; | |
79072805 | 10614 | break; |
c5ee2135 | 10615 | } |
79072805 | 10616 | } |
3280af22 | 10617 | if (PL_in_eval && !PL_rsfp) { |
07409e01 | 10618 | eol = (char *) memchr(s,'\n',PL_bufend-s); |
0f85fab0 | 10619 | if (!eol++) |
3280af22 | 10620 | eol = PL_bufend; |
0f85fab0 LW |
10621 | } |
10622 | else | |
3280af22 | 10623 | eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
79072805 | 10624 | if (*s != '#') { |
a0d0e21e LW |
10625 | for (t = s; t < eol; t++) { |
10626 | if (*t == '~' && t[1] == '~' && SvCUR(stuff)) { | |
10627 | needargs = FALSE; | |
10628 | goto enough; /* ~~ must be first line in formline */ | |
378cc40b | 10629 | } |
a0d0e21e LW |
10630 | if (*t == '@' || *t == '^') |
10631 | needargs = TRUE; | |
378cc40b | 10632 | } |
7121b347 MG |
10633 | if (eol > s) { |
10634 | sv_catpvn(stuff, s, eol-s); | |
2dc4c65b | 10635 | #ifndef PERL_STRICT_CR |
7121b347 MG |
10636 | if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') { |
10637 | char *end = SvPVX(stuff) + SvCUR(stuff); | |
10638 | end[-2] = '\n'; | |
10639 | end[-1] = '\0'; | |
b162af07 | 10640 | SvCUR_set(stuff, SvCUR(stuff) - 1); |
7121b347 | 10641 | } |
2dc4c65b | 10642 | #endif |
7121b347 MG |
10643 | } |
10644 | else | |
10645 | break; | |
79072805 | 10646 | } |
95a20fc0 | 10647 | s = (char*)eol; |
3280af22 NIS |
10648 | if (PL_rsfp) { |
10649 | s = filter_gets(PL_linestr, PL_rsfp, 0); | |
10650 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr); | |
10651 | PL_bufend = PL_bufptr + SvCUR(PL_linestr); | |
207e3d1a | 10652 | PL_last_lop = PL_last_uni = Nullch; |
79072805 | 10653 | if (!s) { |
3280af22 | 10654 | s = PL_bufptr; |
378cc40b LW |
10655 | break; |
10656 | } | |
378cc40b | 10657 | } |
463ee0b2 | 10658 | incline(s); |
79072805 | 10659 | } |
a0d0e21e LW |
10660 | enough: |
10661 | if (SvCUR(stuff)) { | |
3280af22 | 10662 | PL_expect = XTERM; |
79072805 | 10663 | if (needargs) { |
3280af22 NIS |
10664 | PL_lex_state = LEX_NORMAL; |
10665 | PL_nextval[PL_nexttoke].ival = 0; | |
79072805 LW |
10666 | force_next(','); |
10667 | } | |
a0d0e21e | 10668 | else |
3280af22 | 10669 | PL_lex_state = LEX_FORMLINE; |
1bd51a4c | 10670 | if (!IN_BYTES) { |
95a20fc0 | 10671 | if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff))) |
1bd51a4c IH |
10672 | SvUTF8_on(stuff); |
10673 | else if (PL_encoding) | |
10674 | sv_recode_to_utf8(stuff, PL_encoding); | |
10675 | } | |
3280af22 | 10676 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff); |
79072805 | 10677 | force_next(THING); |
3280af22 | 10678 | PL_nextval[PL_nexttoke].ival = OP_FORMLINE; |
79072805 | 10679 | force_next(LSTOP); |
378cc40b | 10680 | } |
79072805 | 10681 | else { |
8990e307 | 10682 | SvREFCNT_dec(stuff); |
c5ee2135 WL |
10683 | if (eofmt) |
10684 | PL_lex_formbrack = 0; | |
3280af22 | 10685 | PL_bufptr = s; |
79072805 LW |
10686 | } |
10687 | return s; | |
378cc40b | 10688 | } |
a687059c | 10689 | |
76e3520e | 10690 | STATIC void |
cea2e8a9 | 10691 | S_set_csh(pTHX) |
a687059c | 10692 | { |
ae986130 | 10693 | #ifdef CSH |
3280af22 NIS |
10694 | if (!PL_cshlen) |
10695 | PL_cshlen = strlen(PL_cshname); | |
ae986130 | 10696 | #endif |
a687059c | 10697 | } |
463ee0b2 | 10698 | |
ba6d6ac9 | 10699 | I32 |
864dbfa3 | 10700 | Perl_start_subparse(pTHX_ I32 is_format, U32 flags) |
8990e307 | 10701 | { |
a3b680e6 | 10702 | const I32 oldsavestack_ix = PL_savestack_ix; |
3280af22 | 10703 | CV* outsidecv = PL_compcv; |
8990e307 | 10704 | |
3280af22 NIS |
10705 | if (PL_compcv) { |
10706 | assert(SvTYPE(PL_compcv) == SVt_PVCV); | |
e9a444f0 | 10707 | } |
7766f137 | 10708 | SAVEI32(PL_subline); |
3280af22 | 10709 | save_item(PL_subname); |
3280af22 | 10710 | SAVESPTR(PL_compcv); |
3280af22 NIS |
10711 | |
10712 | PL_compcv = (CV*)NEWSV(1104,0); | |
10713 | sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV); | |
10714 | CvFLAGS(PL_compcv) |= flags; | |
10715 | ||
57843af0 | 10716 | PL_subline = CopLINE(PL_curcop); |
dd2155a4 | 10717 | CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB); |
3280af22 | 10718 | CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv); |
a3985cdc | 10719 | CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax; |
748a9306 | 10720 | |
8990e307 LW |
10721 | return oldsavestack_ix; |
10722 | } | |
10723 | ||
084592ab CN |
10724 | #ifdef __SC__ |
10725 | #pragma segment Perl_yylex | |
10726 | #endif | |
8990e307 | 10727 | int |
bfed75c6 | 10728 | Perl_yywarn(pTHX_ const char *s) |
8990e307 | 10729 | { |
faef0170 | 10730 | PL_in_eval |= EVAL_WARNONLY; |
748a9306 | 10731 | yyerror(s); |
faef0170 | 10732 | PL_in_eval &= ~EVAL_WARNONLY; |
748a9306 | 10733 | return 0; |
8990e307 LW |
10734 | } |
10735 | ||
10736 | int | |
bfed75c6 | 10737 | Perl_yyerror(pTHX_ const char *s) |
463ee0b2 | 10738 | { |
bfed75c6 AL |
10739 | const char *where = NULL; |
10740 | const char *context = NULL; | |
68dc0745 | 10741 | int contlen = -1; |
46fc3d4c | 10742 | SV *msg; |
463ee0b2 | 10743 | |
3280af22 | 10744 | if (!yychar || (yychar == ';' && !PL_rsfp)) |
54310121 | 10745 | where = "at EOF"; |
8bcfe651 TM |
10746 | else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr && |
10747 | PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr && | |
10748 | PL_oldbufptr != PL_bufptr) { | |
f355267c JH |
10749 | /* |
10750 | Only for NetWare: | |
10751 | The code below is removed for NetWare because it abends/crashes on NetWare | |
10752 | when the script has error such as not having the closing quotes like: | |
10753 | if ($var eq "value) | |
10754 | Checking of white spaces is anyway done in NetWare code. | |
10755 | */ | |
10756 | #ifndef NETWARE | |
3280af22 NIS |
10757 | while (isSPACE(*PL_oldoldbufptr)) |
10758 | PL_oldoldbufptr++; | |
f355267c | 10759 | #endif |
3280af22 NIS |
10760 | context = PL_oldoldbufptr; |
10761 | contlen = PL_bufptr - PL_oldoldbufptr; | |
463ee0b2 | 10762 | } |
8bcfe651 TM |
10763 | else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr && |
10764 | PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) { | |
f355267c JH |
10765 | /* |
10766 | Only for NetWare: | |
10767 | The code below is removed for NetWare because it abends/crashes on NetWare | |
10768 | when the script has error such as not having the closing quotes like: | |
10769 | if ($var eq "value) | |
10770 | Checking of white spaces is anyway done in NetWare code. | |
10771 | */ | |
10772 | #ifndef NETWARE | |
3280af22 NIS |
10773 | while (isSPACE(*PL_oldbufptr)) |
10774 | PL_oldbufptr++; | |
f355267c | 10775 | #endif |
3280af22 NIS |
10776 | context = PL_oldbufptr; |
10777 | contlen = PL_bufptr - PL_oldbufptr; | |
463ee0b2 LW |
10778 | } |
10779 | else if (yychar > 255) | |
68dc0745 | 10780 | where = "next token ???"; |
12fbd33b | 10781 | else if (yychar == -2) { /* YYEMPTY */ |
3280af22 NIS |
10782 | if (PL_lex_state == LEX_NORMAL || |
10783 | (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL)) | |
68dc0745 | 10784 | where = "at end of line"; |
3280af22 | 10785 | else if (PL_lex_inpat) |
68dc0745 | 10786 | where = "within pattern"; |
463ee0b2 | 10787 | else |
68dc0745 | 10788 | where = "within string"; |
463ee0b2 | 10789 | } |
46fc3d4c | 10790 | else { |
79cb57f6 | 10791 | SV *where_sv = sv_2mortal(newSVpvn("next char ", 10)); |
46fc3d4c | 10792 | if (yychar < 32) |
cea2e8a9 | 10793 | Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar)); |
46fc3d4c | 10794 | else if (isPRINT_LC(yychar)) |
cea2e8a9 | 10795 | Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar); |
463ee0b2 | 10796 | else |
cea2e8a9 | 10797 | Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255); |
95a20fc0 | 10798 | where = SvPVX_const(where_sv); |
463ee0b2 | 10799 | } |
46fc3d4c | 10800 | msg = sv_2mortal(newSVpv(s, 0)); |
ed094faf | 10801 | Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ", |
248c2a4d | 10802 | OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop)); |
68dc0745 | 10803 | if (context) |
cea2e8a9 | 10804 | Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context); |
463ee0b2 | 10805 | else |
cea2e8a9 | 10806 | Perl_sv_catpvf(aTHX_ msg, "%s\n", where); |
57843af0 | 10807 | if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) { |
cf2093f6 | 10808 | Perl_sv_catpvf(aTHX_ msg, |
57def98f | 10809 | " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n", |
cf2093f6 | 10810 | (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start); |
3280af22 | 10811 | PL_multi_end = 0; |
a0d0e21e | 10812 | } |
56da5a46 RGS |
10813 | if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX)) |
10814 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg); | |
463ee0b2 | 10815 | else |
5a844595 | 10816 | qerror(msg); |
c7d6bfb2 GS |
10817 | if (PL_error_count >= 10) { |
10818 | if (PL_in_eval && SvCUR(ERRSV)) | |
d2560b70 | 10819 | Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n", |
248c2a4d | 10820 | ERRSV, OutCopFILE(PL_curcop)); |
c7d6bfb2 GS |
10821 | else |
10822 | Perl_croak(aTHX_ "%s has too many errors.\n", | |
248c2a4d | 10823 | OutCopFILE(PL_curcop)); |
c7d6bfb2 | 10824 | } |
3280af22 NIS |
10825 | PL_in_my = 0; |
10826 | PL_in_my_stash = Nullhv; | |
463ee0b2 LW |
10827 | return 0; |
10828 | } | |
084592ab CN |
10829 | #ifdef __SC__ |
10830 | #pragma segment Main | |
10831 | #endif | |
4e35701f | 10832 | |
b250498f | 10833 | STATIC char* |
3ae08724 | 10834 | S_swallow_bom(pTHX_ U8 *s) |
01ec43d0 | 10835 | { |
f54cb97a | 10836 | const STRLEN slen = SvCUR(PL_linestr); |
7aa207d6 | 10837 | switch (s[0]) { |
4e553d73 NIS |
10838 | case 0xFF: |
10839 | if (s[1] == 0xFE) { | |
7aa207d6 | 10840 | /* UTF-16 little-endian? (or UTF32-LE?) */ |
3ae08724 | 10841 | if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */ |
7aa207d6 | 10842 | Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE"); |
01ec43d0 | 10843 | #ifndef PERL_NO_UTF16_FILTER |
7aa207d6 | 10844 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n"); |
3ae08724 | 10845 | s += 2; |
7aa207d6 | 10846 | utf16le: |
dea0fc0b JH |
10847 | if (PL_bufend > (char*)s) { |
10848 | U8 *news; | |
10849 | I32 newlen; | |
10850 | ||
10851 | filter_add(utf16rev_textfilter, NULL); | |
a02a5408 | 10852 | Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8); |
1de9afcd RGS |
10853 | utf16_to_utf8_reversed(s, news, |
10854 | PL_bufend - (char*)s - 1, | |
10855 | &newlen); | |
7aa207d6 | 10856 | sv_setpvn(PL_linestr, (const char*)news, newlen); |
dea0fc0b | 10857 | Safefree(news); |
7aa207d6 JH |
10858 | SvUTF8_on(PL_linestr); |
10859 | s = (U8*)SvPVX(PL_linestr); | |
10860 | PL_bufend = SvPVX(PL_linestr) + newlen; | |
dea0fc0b | 10861 | } |
b250498f | 10862 | #else |
7aa207d6 | 10863 | Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE"); |
b250498f | 10864 | #endif |
01ec43d0 GS |
10865 | } |
10866 | break; | |
78ae23f5 | 10867 | case 0xFE: |
7aa207d6 | 10868 | if (s[1] == 0xFF) { /* UTF-16 big-endian? */ |
01ec43d0 | 10869 | #ifndef PERL_NO_UTF16_FILTER |
7aa207d6 | 10870 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n"); |
dea0fc0b | 10871 | s += 2; |
7aa207d6 | 10872 | utf16be: |
dea0fc0b JH |
10873 | if (PL_bufend > (char *)s) { |
10874 | U8 *news; | |
10875 | I32 newlen; | |
10876 | ||
10877 | filter_add(utf16_textfilter, NULL); | |
a02a5408 | 10878 | Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8); |
1de9afcd RGS |
10879 | utf16_to_utf8(s, news, |
10880 | PL_bufend - (char*)s, | |
10881 | &newlen); | |
7aa207d6 | 10882 | sv_setpvn(PL_linestr, (const char*)news, newlen); |
dea0fc0b | 10883 | Safefree(news); |
7aa207d6 JH |
10884 | SvUTF8_on(PL_linestr); |
10885 | s = (U8*)SvPVX(PL_linestr); | |
10886 | PL_bufend = SvPVX(PL_linestr) + newlen; | |
dea0fc0b | 10887 | } |
b250498f | 10888 | #else |
7aa207d6 | 10889 | Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE"); |
b250498f | 10890 | #endif |
01ec43d0 GS |
10891 | } |
10892 | break; | |
3ae08724 GS |
10893 | case 0xEF: |
10894 | if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) { | |
7aa207d6 | 10895 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n"); |
01ec43d0 GS |
10896 | s += 3; /* UTF-8 */ |
10897 | } | |
10898 | break; | |
10899 | case 0: | |
7aa207d6 JH |
10900 | if (slen > 3) { |
10901 | if (s[1] == 0) { | |
10902 | if (s[2] == 0xFE && s[3] == 0xFF) { | |
10903 | /* UTF-32 big-endian */ | |
10904 | Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE"); | |
10905 | } | |
10906 | } | |
10907 | else if (s[2] == 0 && s[3] != 0) { | |
10908 | /* Leading bytes | |
10909 | * 00 xx 00 xx | |
10910 | * are a good indicator of UTF-16BE. */ | |
10911 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n"); | |
10912 | goto utf16be; | |
10913 | } | |
01ec43d0 | 10914 | } |
7aa207d6 JH |
10915 | default: |
10916 | if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) { | |
10917 | /* Leading bytes | |
10918 | * xx 00 xx 00 | |
10919 | * are a good indicator of UTF-16LE. */ | |
10920 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n"); | |
10921 | goto utf16le; | |
10922 | } | |
01ec43d0 | 10923 | } |
b8f84bb2 | 10924 | return (char*)s; |
b250498f | 10925 | } |
4755096e | 10926 | |
4755096e GS |
10927 | /* |
10928 | * restore_rsfp | |
10929 | * Restore a source filter. | |
10930 | */ | |
10931 | ||
10932 | static void | |
acfe0abc | 10933 | restore_rsfp(pTHX_ void *f) |
4755096e GS |
10934 | { |
10935 | PerlIO *fp = (PerlIO*)f; | |
10936 | ||
10937 | if (PL_rsfp == PerlIO_stdin()) | |
10938 | PerlIO_clearerr(PL_rsfp); | |
10939 | else if (PL_rsfp && (PL_rsfp != fp)) | |
10940 | PerlIO_close(PL_rsfp); | |
10941 | PL_rsfp = fp; | |
10942 | } | |
6e3aabd6 GS |
10943 | |
10944 | #ifndef PERL_NO_UTF16_FILTER | |
10945 | static I32 | |
acfe0abc | 10946 | utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
6e3aabd6 | 10947 | { |
f54cb97a AL |
10948 | const STRLEN old = SvCUR(sv); |
10949 | const I32 count = FILTER_READ(idx+1, sv, maxlen); | |
1de9afcd RGS |
10950 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
10951 | "utf16_textfilter(%p): %d %d (%d)\n", | |
4fccd7c6 | 10952 | utf16_textfilter, idx, maxlen, (int) count)); |
6e3aabd6 GS |
10953 | if (count) { |
10954 | U8* tmps; | |
dea0fc0b | 10955 | I32 newlen; |
a02a5408 | 10956 | Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8); |
95a20fc0 SP |
10957 | Copy(SvPVX_const(sv), tmps, old, char); |
10958 | utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old, | |
1de9afcd RGS |
10959 | SvCUR(sv) - old, &newlen); |
10960 | sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old); | |
6e3aabd6 | 10961 | } |
1de9afcd RGS |
10962 | DEBUG_P({sv_dump(sv);}); |
10963 | return SvCUR(sv); | |
6e3aabd6 GS |
10964 | } |
10965 | ||
10966 | static I32 | |
acfe0abc | 10967 | utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
6e3aabd6 | 10968 | { |
f54cb97a AL |
10969 | const STRLEN old = SvCUR(sv); |
10970 | const I32 count = FILTER_READ(idx+1, sv, maxlen); | |
1de9afcd RGS |
10971 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
10972 | "utf16rev_textfilter(%p): %d %d (%d)\n", | |
4fccd7c6 | 10973 | utf16rev_textfilter, idx, maxlen, (int) count)); |
6e3aabd6 GS |
10974 | if (count) { |
10975 | U8* tmps; | |
dea0fc0b | 10976 | I32 newlen; |
a02a5408 | 10977 | Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8); |
95a20fc0 SP |
10978 | Copy(SvPVX_const(sv), tmps, old, char); |
10979 | utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old, | |
1de9afcd RGS |
10980 | SvCUR(sv) - old, &newlen); |
10981 | sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old); | |
6e3aabd6 | 10982 | } |
1de9afcd | 10983 | DEBUG_P({ sv_dump(sv); }); |
6e3aabd6 GS |
10984 | return count; |
10985 | } | |
10986 | #endif | |
9f4817db | 10987 | |
f333445c JP |
10988 | /* |
10989 | Returns a pointer to the next character after the parsed | |
10990 | vstring, as well as updating the passed in sv. | |
10991 | ||
10992 | Function must be called like | |
10993 | ||
10994 | sv = NEWSV(92,5); | |
10995 | s = scan_vstring(s,sv); | |
10996 | ||
10997 | The sv should already be large enough to store the vstring | |
10998 | passed in, for performance reasons. | |
10999 | ||
11000 | */ | |
11001 | ||
11002 | char * | |
bfed75c6 | 11003 | Perl_scan_vstring(pTHX_ const char *s, SV *sv) |
f333445c | 11004 | { |
bfed75c6 AL |
11005 | const char *pos = s; |
11006 | const char *start = s; | |
f333445c | 11007 | if (*pos == 'v') pos++; /* get past 'v' */ |
3e884cbf JH |
11008 | while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_')) |
11009 | pos++; | |
f333445c JP |
11010 | if ( *pos != '.') { |
11011 | /* this may not be a v-string if followed by => */ | |
bfed75c6 | 11012 | const char *next = pos; |
8fc7bb1c SM |
11013 | while (next < PL_bufend && isSPACE(*next)) |
11014 | ++next; | |
11015 | if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) { | |
f333445c JP |
11016 | /* return string not v-string */ |
11017 | sv_setpvn(sv,(char *)s,pos-s); | |
73d840c0 | 11018 | return (char *)pos; |
f333445c JP |
11019 | } |
11020 | } | |
11021 | ||
11022 | if (!isALPHA(*pos)) { | |
11023 | UV rev; | |
89ebb4a3 | 11024 | U8 tmpbuf[UTF8_MAXBYTES+1]; |
f333445c JP |
11025 | U8 *tmpend; |
11026 | ||
11027 | if (*s == 'v') s++; /* get past 'v' */ | |
11028 | ||
11029 | sv_setpvn(sv, "", 0); | |
11030 | ||
11031 | for (;;) { | |
11032 | rev = 0; | |
11033 | { | |
11034 | /* this is atoi() that tolerates underscores */ | |
bfed75c6 | 11035 | const char *end = pos; |
f333445c JP |
11036 | UV mult = 1; |
11037 | while (--end >= s) { | |
11038 | UV orev; | |
11039 | if (*end == '_') | |
11040 | continue; | |
11041 | orev = rev; | |
11042 | rev += (*end - '0') * mult; | |
11043 | mult *= 10; | |
11044 | if (orev > rev && ckWARN_d(WARN_OVERFLOW)) | |
11045 | Perl_warner(aTHX_ packWARN(WARN_OVERFLOW), | |
11046 | "Integer overflow in decimal number"); | |
11047 | } | |
11048 | } | |
11049 | #ifdef EBCDIC | |
11050 | if (rev > 0x7FFFFFFF) | |
11051 | Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647"); | |
11052 | #endif | |
11053 | /* Append native character for the rev point */ | |
11054 | tmpend = uvchr_to_utf8(tmpbuf, rev); | |
11055 | sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf); | |
11056 | if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev))) | |
11057 | SvUTF8_on(sv); | |
3e884cbf | 11058 | if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1])) |
f333445c JP |
11059 | s = ++pos; |
11060 | else { | |
11061 | s = pos; | |
11062 | break; | |
11063 | } | |
3e884cbf | 11064 | while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_')) |
f333445c JP |
11065 | pos++; |
11066 | } | |
11067 | SvPOK_on(sv); | |
11068 | sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start); | |
11069 | SvRMAGICAL_on(sv); | |
11070 | } | |
73d840c0 | 11071 | return (char *)s; |
f333445c JP |
11072 | } |
11073 | ||
1da4ca5f NC |
11074 | /* |
11075 | * Local variables: | |
11076 | * c-indentation-style: bsd | |
11077 | * c-basic-offset: 4 | |
11078 | * indent-tabs-mode: t | |
11079 | * End: | |
11080 | * | |
37442d52 RGS |
11081 | * ex: set ts=8 sts=4 sw=4 noet: |
11082 | */ |