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 | ||
55497cff | 69 | #define LEX_NORMAL 10 |
70 | #define LEX_INTERPNORMAL 9 | |
71 | #define LEX_INTERPCASEMOD 8 | |
72 | #define LEX_INTERPPUSH 7 | |
73 | #define LEX_INTERPSTART 6 | |
74 | #define LEX_INTERPEND 5 | |
75 | #define LEX_INTERPENDMAYBE 4 | |
76 | #define LEX_INTERPCONCAT 3 | |
77 | #define LEX_INTERPCONST 2 | |
78 | #define LEX_FORMLINE 1 | |
79 | #define LEX_KNOWNEXT 0 | |
79072805 | 80 | |
bbf60fe6 | 81 | #ifdef DEBUGGING |
27da23d5 | 82 | static const char* const lex_state_names[] = { |
bbf60fe6 DM |
83 | "KNOWNEXT", |
84 | "FORMLINE", | |
85 | "INTERPCONST", | |
86 | "INTERPCONCAT", | |
87 | "INTERPENDMAYBE", | |
88 | "INTERPEND", | |
89 | "INTERPSTART", | |
90 | "INTERPPUSH", | |
91 | "INTERPCASEMOD", | |
92 | "INTERPNORMAL", | |
93 | "NORMAL" | |
94 | }; | |
95 | #endif | |
96 | ||
79072805 LW |
97 | #ifdef ff_next |
98 | #undef ff_next | |
d48672a2 LW |
99 | #endif |
100 | ||
79072805 | 101 | #include "keywords.h" |
fe14fcc3 | 102 | |
ffb4593c NT |
103 | /* CLINE is a macro that ensures PL_copline has a sane value */ |
104 | ||
ae986130 LW |
105 | #ifdef CLINE |
106 | #undef CLINE | |
107 | #endif | |
57843af0 | 108 | #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline)) |
3280af22 | 109 | |
ffb4593c NT |
110 | /* |
111 | * Convenience functions to return different tokens and prime the | |
9cbb5ea2 | 112 | * lexer for the next token. They all take an argument. |
ffb4593c NT |
113 | * |
114 | * TOKEN : generic token (used for '(', DOLSHARP, etc) | |
115 | * OPERATOR : generic operator | |
116 | * AOPERATOR : assignment operator | |
117 | * PREBLOCK : beginning the block after an if, while, foreach, ... | |
118 | * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref) | |
119 | * PREREF : *EXPR where EXPR is not a simple identifier | |
120 | * TERM : expression term | |
121 | * LOOPX : loop exiting command (goto, last, dump, etc) | |
122 | * FTST : file test operator | |
123 | * FUN0 : zero-argument function | |
2d2e263d | 124 | * FUN1 : not used, except for not, which isn't a UNIOP |
ffb4593c NT |
125 | * BOop : bitwise or or xor |
126 | * BAop : bitwise and | |
127 | * SHop : shift operator | |
128 | * PWop : power operator | |
9cbb5ea2 | 129 | * PMop : pattern-matching operator |
ffb4593c NT |
130 | * Aop : addition-level operator |
131 | * Mop : multiplication-level operator | |
132 | * Eop : equality-testing operator | |
e5edeb50 | 133 | * Rop : relational operator <= != gt |
ffb4593c NT |
134 | * |
135 | * Also see LOP and lop() below. | |
136 | */ | |
137 | ||
998054bd | 138 | #ifdef DEBUGGING /* Serve -DT. */ |
bbf60fe6 | 139 | # define REPORT(retval) tokereport(s,(int)retval) |
998054bd | 140 | #else |
bbf60fe6 | 141 | # define REPORT(retval) (retval) |
998054bd SC |
142 | #endif |
143 | ||
bbf60fe6 DM |
144 | #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval)) |
145 | #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval)) | |
146 | #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval))) | |
147 | #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval)) | |
148 | #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval)) | |
149 | #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval)) | |
150 | #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval)) | |
151 | #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX)) | |
152 | #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP)) | |
153 | #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0)) | |
154 | #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1)) | |
155 | #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP))) | |
156 | #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP))) | |
157 | #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP))) | |
158 | #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP))) | |
159 | #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP)) | |
160 | #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP))) | |
161 | #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP))) | |
162 | #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP)) | |
163 | #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP)) | |
2f3197b3 | 164 | |
a687059c LW |
165 | /* This bit of chicanery makes a unary function followed by |
166 | * a parenthesis into a function with one argument, highest precedence. | |
6f33ba73 RGS |
167 | * The UNIDOR macro is for unary functions that can be followed by the // |
168 | * operator (such as C<shift // 0>). | |
a687059c | 169 | */ |
bbf60fe6 DM |
170 | #define UNI2(f,x) return ( \ |
171 | yylval.ival = f, \ | |
6f33ba73 | 172 | PL_expect = x, \ |
3280af22 NIS |
173 | PL_bufptr = s, \ |
174 | PL_last_uni = PL_oldbufptr, \ | |
175 | PL_last_lop_op = f, \ | |
bbf60fe6 DM |
176 | REPORT( \ |
177 | (*s == '(' || (s = skipspace(s), *s == '(') \ | |
178 | ? (int)FUNC1 : (int)UNIOP))) | |
6f33ba73 RGS |
179 | #define UNI(f) UNI2(f,XTERM) |
180 | #define UNIDOR(f) UNI2(f,XTERMORDORDOR) | |
a687059c | 181 | |
bbf60fe6 DM |
182 | #define UNIBRACK(f) return ( \ |
183 | yylval.ival = f, \ | |
3280af22 NIS |
184 | PL_bufptr = s, \ |
185 | PL_last_uni = PL_oldbufptr, \ | |
bbf60fe6 DM |
186 | REPORT( \ |
187 | (*s == '(' || (s = skipspace(s), *s == '(') \ | |
188 | ? (int)FUNC1 : (int)UNIOP))) | |
79072805 | 189 | |
9f68db38 | 190 | /* grandfather return to old style */ |
3280af22 | 191 | #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP) |
79072805 | 192 | |
8fa7f367 JH |
193 | #ifdef DEBUGGING |
194 | ||
bbf60fe6 DM |
195 | /* how to interpret the yylval associated with the token */ |
196 | enum token_type { | |
197 | TOKENTYPE_NONE, | |
198 | TOKENTYPE_IVAL, | |
199 | TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */ | |
200 | TOKENTYPE_PVAL, | |
201 | TOKENTYPE_OPVAL, | |
202 | TOKENTYPE_GVVAL | |
203 | }; | |
204 | ||
27da23d5 JH |
205 | static struct debug_tokens { const int token, type; const char *name; } |
206 | const debug_tokens[] = | |
9041c2e3 | 207 | { |
bbf60fe6 DM |
208 | { ADDOP, TOKENTYPE_OPNUM, "ADDOP" }, |
209 | { ANDAND, TOKENTYPE_NONE, "ANDAND" }, | |
210 | { ANDOP, TOKENTYPE_NONE, "ANDOP" }, | |
211 | { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" }, | |
212 | { ARROW, TOKENTYPE_NONE, "ARROW" }, | |
213 | { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" }, | |
214 | { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" }, | |
215 | { BITOROP, TOKENTYPE_OPNUM, "BITOROP" }, | |
216 | { COLONATTR, TOKENTYPE_NONE, "COLONATTR" }, | |
217 | { CONTINUE, TOKENTYPE_NONE, "CONTINUE" }, | |
218 | { DO, TOKENTYPE_NONE, "DO" }, | |
219 | { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" }, | |
220 | { DORDOR, TOKENTYPE_NONE, "DORDOR" }, | |
221 | { DOROP, TOKENTYPE_OPNUM, "DOROP" }, | |
222 | { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" }, | |
223 | { ELSE, TOKENTYPE_NONE, "ELSE" }, | |
224 | { ELSIF, TOKENTYPE_IVAL, "ELSIF" }, | |
225 | { EQOP, TOKENTYPE_OPNUM, "EQOP" }, | |
226 | { FOR, TOKENTYPE_IVAL, "FOR" }, | |
227 | { FORMAT, TOKENTYPE_NONE, "FORMAT" }, | |
228 | { FUNC, TOKENTYPE_OPNUM, "FUNC" }, | |
229 | { FUNC0, TOKENTYPE_OPNUM, "FUNC0" }, | |
230 | { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" }, | |
231 | { FUNC1, TOKENTYPE_OPNUM, "FUNC1" }, | |
232 | { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" }, | |
233 | { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" }, | |
234 | { IF, TOKENTYPE_IVAL, "IF" }, | |
235 | { LABEL, TOKENTYPE_PVAL, "LABEL" }, | |
236 | { LOCAL, TOKENTYPE_IVAL, "LOCAL" }, | |
237 | { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" }, | |
238 | { LSTOP, TOKENTYPE_OPNUM, "LSTOP" }, | |
239 | { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" }, | |
240 | { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" }, | |
241 | { METHOD, TOKENTYPE_OPVAL, "METHOD" }, | |
242 | { MULOP, TOKENTYPE_OPNUM, "MULOP" }, | |
243 | { MY, TOKENTYPE_IVAL, "MY" }, | |
244 | { MYSUB, TOKENTYPE_NONE, "MYSUB" }, | |
245 | { NOAMP, TOKENTYPE_NONE, "NOAMP" }, | |
246 | { NOTOP, TOKENTYPE_NONE, "NOTOP" }, | |
247 | { OROP, TOKENTYPE_IVAL, "OROP" }, | |
248 | { OROR, TOKENTYPE_NONE, "OROR" }, | |
249 | { PACKAGE, TOKENTYPE_NONE, "PACKAGE" }, | |
250 | { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" }, | |
251 | { POSTDEC, TOKENTYPE_NONE, "POSTDEC" }, | |
252 | { POSTINC, TOKENTYPE_NONE, "POSTINC" }, | |
253 | { POWOP, TOKENTYPE_OPNUM, "POWOP" }, | |
254 | { PREDEC, TOKENTYPE_NONE, "PREDEC" }, | |
255 | { PREINC, TOKENTYPE_NONE, "PREINC" }, | |
256 | { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" }, | |
257 | { REFGEN, TOKENTYPE_NONE, "REFGEN" }, | |
258 | { RELOP, TOKENTYPE_OPNUM, "RELOP" }, | |
259 | { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" }, | |
260 | { SUB, TOKENTYPE_NONE, "SUB" }, | |
261 | { THING, TOKENTYPE_OPVAL, "THING" }, | |
262 | { UMINUS, TOKENTYPE_NONE, "UMINUS" }, | |
263 | { UNIOP, TOKENTYPE_OPNUM, "UNIOP" }, | |
264 | { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" }, | |
265 | { UNLESS, TOKENTYPE_IVAL, "UNLESS" }, | |
266 | { UNTIL, TOKENTYPE_IVAL, "UNTIL" }, | |
267 | { USE, TOKENTYPE_IVAL, "USE" }, | |
268 | { WHILE, TOKENTYPE_IVAL, "WHILE" }, | |
269 | { WORD, TOKENTYPE_OPVAL, "WORD" }, | |
270 | { 0, TOKENTYPE_NONE, 0 } | |
271 | }; | |
272 | ||
273 | /* dump the returned token in rv, plus any optional arg in yylval */ | |
998054bd | 274 | |
bbf60fe6 | 275 | STATIC int |
bfed75c6 | 276 | S_tokereport(pTHX_ const char* s, I32 rv) |
bbf60fe6 DM |
277 | { |
278 | if (DEBUG_T_TEST) { | |
bfed75c6 | 279 | const char *name = Nullch; |
bbf60fe6 DM |
280 | enum token_type type = TOKENTYPE_NONE; |
281 | struct debug_tokens *p; | |
bfed75c6 | 282 | SV* report = newSVpvn("<== ", 4); |
bbf60fe6 | 283 | |
aadb217d | 284 | for (p = (struct debug_tokens *)debug_tokens; p->token; p++) { |
bbf60fe6 DM |
285 | if (p->token == (int)rv) { |
286 | name = p->name; | |
287 | type = p->type; | |
288 | break; | |
289 | } | |
290 | } | |
291 | if (name) | |
54667de8 | 292 | Perl_sv_catpv(aTHX_ report, name); |
bbf60fe6 DM |
293 | else if ((char)rv > ' ' && (char)rv < '~') |
294 | Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv); | |
295 | else if (!rv) | |
54667de8 | 296 | Perl_sv_catpv(aTHX_ report, "EOF"); |
bbf60fe6 DM |
297 | else |
298 | Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv); | |
299 | switch (type) { | |
300 | case TOKENTYPE_NONE: | |
301 | case TOKENTYPE_GVVAL: /* doesn't appear to be used */ | |
302 | break; | |
303 | case TOKENTYPE_IVAL: | |
e4584336 | 304 | Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival); |
bbf60fe6 DM |
305 | break; |
306 | case TOKENTYPE_OPNUM: | |
307 | Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)", | |
308 | PL_op_name[yylval.ival]); | |
309 | break; | |
310 | case TOKENTYPE_PVAL: | |
311 | Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval); | |
312 | break; | |
313 | case TOKENTYPE_OPVAL: | |
401441c0 RGS |
314 | if (yylval.opval) |
315 | Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)", | |
bbf60fe6 | 316 | PL_op_name[yylval.opval->op_type]); |
401441c0 RGS |
317 | else |
318 | Perl_sv_catpv(aTHX_ report, "(opval=null)"); | |
bbf60fe6 DM |
319 | break; |
320 | } | |
e4584336 | 321 | Perl_sv_catpvf(aTHX_ report, " at line %"IVdf" [", (IV)CopLINE(PL_curcop)); |
998054bd SC |
322 | if (s - PL_bufptr > 0) |
323 | sv_catpvn(report, PL_bufptr, s - PL_bufptr); | |
324 | else { | |
325 | if (PL_oldbufptr && *PL_oldbufptr) | |
326 | sv_catpv(report, PL_tokenbuf); | |
327 | } | |
bbf60fe6 DM |
328 | PerlIO_printf(Perl_debug_log, "### %s]\n", SvPV_nolen(report)); |
329 | }; | |
330 | return (int)rv; | |
998054bd SC |
331 | } |
332 | ||
8fa7f367 JH |
333 | #endif |
334 | ||
ffb4593c NT |
335 | /* |
336 | * S_ao | |
337 | * | |
c963b151 BD |
338 | * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR |
339 | * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN | |
ffb4593c NT |
340 | */ |
341 | ||
76e3520e | 342 | STATIC int |
cea2e8a9 | 343 | S_ao(pTHX_ int toketype) |
a0d0e21e | 344 | { |
3280af22 NIS |
345 | if (*PL_bufptr == '=') { |
346 | PL_bufptr++; | |
a0d0e21e LW |
347 | if (toketype == ANDAND) |
348 | yylval.ival = OP_ANDASSIGN; | |
349 | else if (toketype == OROR) | |
350 | yylval.ival = OP_ORASSIGN; | |
c963b151 BD |
351 | else if (toketype == DORDOR) |
352 | yylval.ival = OP_DORASSIGN; | |
a0d0e21e LW |
353 | toketype = ASSIGNOP; |
354 | } | |
355 | return toketype; | |
356 | } | |
357 | ||
ffb4593c NT |
358 | /* |
359 | * S_no_op | |
360 | * When Perl expects an operator and finds something else, no_op | |
361 | * prints the warning. It always prints "<something> found where | |
362 | * operator expected. It prints "Missing semicolon on previous line?" | |
363 | * if the surprise occurs at the start of the line. "do you need to | |
364 | * predeclare ..." is printed out for code like "sub bar; foo bar $x" | |
365 | * where the compiler doesn't know if foo is a method call or a function. | |
366 | * It prints "Missing operator before end of line" if there's nothing | |
367 | * after the missing operator, or "... before <...>" if there is something | |
368 | * after the missing operator. | |
369 | */ | |
370 | ||
76e3520e | 371 | STATIC void |
bfed75c6 | 372 | S_no_op(pTHX_ const char *what, char *s) |
463ee0b2 | 373 | { |
3280af22 NIS |
374 | char *oldbp = PL_bufptr; |
375 | bool is_first = (PL_oldbufptr == PL_linestart); | |
68dc0745 | 376 | |
1189a94a GS |
377 | if (!s) |
378 | s = oldbp; | |
07c798fb | 379 | else |
1189a94a | 380 | PL_bufptr = s; |
cea2e8a9 | 381 | yywarn(Perl_form(aTHX_ "%s found where operator expected", what)); |
56da5a46 RGS |
382 | if (ckWARN_d(WARN_SYNTAX)) { |
383 | if (is_first) | |
384 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
385 | "\t(Missing semicolon on previous line?)\n"); | |
386 | else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) { | |
387 | char *t; | |
388 | for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ; | |
389 | if (t < PL_bufptr && isSPACE(*t)) | |
390 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
391 | "\t(Do you need to predeclare %.*s?)\n", | |
392 | t - PL_oldoldbufptr, PL_oldoldbufptr); | |
393 | } | |
394 | else { | |
395 | assert(s >= oldbp); | |
396 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
397 | "\t(Missing operator before %.*s?)\n", s - oldbp, oldbp); | |
398 | } | |
07c798fb | 399 | } |
3280af22 | 400 | PL_bufptr = oldbp; |
8990e307 LW |
401 | } |
402 | ||
ffb4593c NT |
403 | /* |
404 | * S_missingterm | |
405 | * Complain about missing quote/regexp/heredoc terminator. | |
406 | * If it's called with (char *)NULL then it cauterizes the line buffer. | |
407 | * If we're in a delimited string and the delimiter is a control | |
408 | * character, it's reformatted into a two-char sequence like ^C. | |
409 | * This is fatal. | |
410 | */ | |
411 | ||
76e3520e | 412 | STATIC void |
cea2e8a9 | 413 | S_missingterm(pTHX_ char *s) |
8990e307 LW |
414 | { |
415 | char tmpbuf[3]; | |
416 | char q; | |
417 | if (s) { | |
418 | char *nl = strrchr(s,'\n'); | |
d2719217 | 419 | if (nl) |
8990e307 LW |
420 | *nl = '\0'; |
421 | } | |
9d116dd7 JH |
422 | else if ( |
423 | #ifdef EBCDIC | |
424 | iscntrl(PL_multi_close) | |
425 | #else | |
426 | PL_multi_close < 32 || PL_multi_close == 127 | |
427 | #endif | |
428 | ) { | |
8990e307 | 429 | *tmpbuf = '^'; |
3280af22 | 430 | tmpbuf[1] = toCTRL(PL_multi_close); |
8990e307 LW |
431 | tmpbuf[2] = '\0'; |
432 | s = tmpbuf; | |
433 | } | |
434 | else { | |
eb160463 | 435 | *tmpbuf = (char)PL_multi_close; |
8990e307 LW |
436 | tmpbuf[1] = '\0'; |
437 | s = tmpbuf; | |
438 | } | |
439 | q = strchr(s,'"') ? '\'' : '"'; | |
cea2e8a9 | 440 | Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q); |
463ee0b2 | 441 | } |
79072805 | 442 | |
ffb4593c NT |
443 | /* |
444 | * Perl_deprecate | |
ffb4593c NT |
445 | */ |
446 | ||
79072805 | 447 | void |
bfed75c6 | 448 | Perl_deprecate(pTHX_ const char *s) |
a0d0e21e | 449 | { |
599cee73 | 450 | if (ckWARN(WARN_DEPRECATED)) |
9014280d | 451 | Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s); |
a0d0e21e LW |
452 | } |
453 | ||
12bcd1a6 | 454 | void |
bfed75c6 | 455 | Perl_deprecate_old(pTHX_ const char *s) |
12bcd1a6 PM |
456 | { |
457 | /* This function should NOT be called for any new deprecated warnings */ | |
458 | /* Use Perl_deprecate instead */ | |
459 | /* */ | |
460 | /* It is here to maintain backward compatibility with the pre-5.8 */ | |
461 | /* warnings category hierarchy. The "deprecated" category used to */ | |
462 | /* live under the "syntax" category. It is now a top-level category */ | |
463 | /* in its own right. */ | |
464 | ||
465 | if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX)) | |
bfed75c6 | 466 | Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX), |
12bcd1a6 PM |
467 | "Use of %s is deprecated", s); |
468 | } | |
469 | ||
ffb4593c NT |
470 | /* |
471 | * depcom | |
9cbb5ea2 | 472 | * Deprecate a comma-less variable list. |
ffb4593c NT |
473 | */ |
474 | ||
76e3520e | 475 | STATIC void |
cea2e8a9 | 476 | S_depcom(pTHX) |
a0d0e21e | 477 | { |
12bcd1a6 | 478 | deprecate_old("comma-less variable list"); |
a0d0e21e LW |
479 | } |
480 | ||
ffb4593c | 481 | /* |
9cbb5ea2 GS |
482 | * experimental text filters for win32 carriage-returns, utf16-to-utf8 and |
483 | * utf16-to-utf8-reversed. | |
ffb4593c NT |
484 | */ |
485 | ||
c39cd008 GS |
486 | #ifdef PERL_CR_FILTER |
487 | static void | |
488 | strip_return(SV *sv) | |
489 | { | |
490 | register char *s = SvPVX(sv); | |
491 | register char *e = s + SvCUR(sv); | |
492 | /* outer loop optimized to do nothing if there are no CR-LFs */ | |
493 | while (s < e) { | |
494 | if (*s++ == '\r' && *s == '\n') { | |
495 | /* hit a CR-LF, need to copy the rest */ | |
496 | register char *d = s - 1; | |
497 | *d++ = *s++; | |
498 | while (s < e) { | |
499 | if (*s == '\r' && s[1] == '\n') | |
500 | s++; | |
501 | *d++ = *s++; | |
502 | } | |
503 | SvCUR(sv) -= s - d; | |
504 | return; | |
505 | } | |
506 | } | |
507 | } | |
a868473f | 508 | |
76e3520e | 509 | STATIC I32 |
c39cd008 | 510 | S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
a868473f | 511 | { |
c39cd008 GS |
512 | I32 count = FILTER_READ(idx+1, sv, maxlen); |
513 | if (count > 0 && !maxlen) | |
514 | strip_return(sv); | |
515 | return count; | |
a868473f NIS |
516 | } |
517 | #endif | |
518 | ||
ffb4593c NT |
519 | /* |
520 | * Perl_lex_start | |
9cbb5ea2 GS |
521 | * Initialize variables. Uses the Perl save_stack to save its state (for |
522 | * recursive calls to the parser). | |
ffb4593c NT |
523 | */ |
524 | ||
a0d0e21e | 525 | void |
864dbfa3 | 526 | Perl_lex_start(pTHX_ SV *line) |
79072805 | 527 | { |
8990e307 LW |
528 | char *s; |
529 | STRLEN len; | |
530 | ||
3280af22 NIS |
531 | SAVEI32(PL_lex_dojoin); |
532 | SAVEI32(PL_lex_brackets); | |
3280af22 NIS |
533 | SAVEI32(PL_lex_casemods); |
534 | SAVEI32(PL_lex_starts); | |
535 | SAVEI32(PL_lex_state); | |
7766f137 | 536 | SAVEVPTR(PL_lex_inpat); |
3280af22 | 537 | SAVEI32(PL_lex_inwhat); |
18b09519 GS |
538 | if (PL_lex_state == LEX_KNOWNEXT) { |
539 | I32 toke = PL_nexttoke; | |
540 | while (--toke >= 0) { | |
541 | SAVEI32(PL_nexttype[toke]); | |
542 | SAVEVPTR(PL_nextval[toke]); | |
543 | } | |
544 | SAVEI32(PL_nexttoke); | |
18b09519 | 545 | } |
57843af0 | 546 | SAVECOPLINE(PL_curcop); |
3280af22 NIS |
547 | SAVEPPTR(PL_bufptr); |
548 | SAVEPPTR(PL_bufend); | |
549 | SAVEPPTR(PL_oldbufptr); | |
550 | SAVEPPTR(PL_oldoldbufptr); | |
207e3d1a JH |
551 | SAVEPPTR(PL_last_lop); |
552 | SAVEPPTR(PL_last_uni); | |
3280af22 NIS |
553 | SAVEPPTR(PL_linestart); |
554 | SAVESPTR(PL_linestr); | |
8edd5f42 RGS |
555 | SAVEGENERICPV(PL_lex_brackstack); |
556 | SAVEGENERICPV(PL_lex_casestack); | |
c76ac1ee | 557 | SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp); |
3280af22 NIS |
558 | SAVESPTR(PL_lex_stuff); |
559 | SAVEI32(PL_lex_defer); | |
09bef843 | 560 | SAVEI32(PL_sublex_info.sub_inwhat); |
3280af22 | 561 | SAVESPTR(PL_lex_repl); |
bebdddfc GS |
562 | SAVEINT(PL_expect); |
563 | SAVEINT(PL_lex_expect); | |
3280af22 NIS |
564 | |
565 | PL_lex_state = LEX_NORMAL; | |
566 | PL_lex_defer = 0; | |
567 | PL_expect = XSTATE; | |
568 | PL_lex_brackets = 0; | |
3280af22 NIS |
569 | New(899, PL_lex_brackstack, 120, char); |
570 | New(899, PL_lex_casestack, 12, char); | |
3280af22 NIS |
571 | PL_lex_casemods = 0; |
572 | *PL_lex_casestack = '\0'; | |
573 | PL_lex_dojoin = 0; | |
574 | PL_lex_starts = 0; | |
575 | PL_lex_stuff = Nullsv; | |
576 | PL_lex_repl = Nullsv; | |
577 | PL_lex_inpat = 0; | |
76be56bc | 578 | PL_nexttoke = 0; |
3280af22 | 579 | PL_lex_inwhat = 0; |
09bef843 | 580 | PL_sublex_info.sub_inwhat = 0; |
3280af22 NIS |
581 | PL_linestr = line; |
582 | if (SvREADONLY(PL_linestr)) | |
583 | PL_linestr = sv_2mortal(newSVsv(PL_linestr)); | |
584 | s = SvPV(PL_linestr, len); | |
6f27f9a7 | 585 | if (!len || s[len-1] != ';') { |
3280af22 NIS |
586 | if (!(SvFLAGS(PL_linestr) & SVs_TEMP)) |
587 | PL_linestr = sv_2mortal(newSVsv(PL_linestr)); | |
588 | sv_catpvn(PL_linestr, "\n;", 2); | |
8990e307 | 589 | } |
3280af22 NIS |
590 | SvTEMP_off(PL_linestr); |
591 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr); | |
592 | PL_bufend = PL_bufptr + SvCUR(PL_linestr); | |
207e3d1a | 593 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 594 | PL_rsfp = 0; |
79072805 | 595 | } |
a687059c | 596 | |
ffb4593c NT |
597 | /* |
598 | * Perl_lex_end | |
9cbb5ea2 GS |
599 | * Finalizer for lexing operations. Must be called when the parser is |
600 | * done with the lexer. | |
ffb4593c NT |
601 | */ |
602 | ||
463ee0b2 | 603 | void |
864dbfa3 | 604 | Perl_lex_end(pTHX) |
463ee0b2 | 605 | { |
3280af22 | 606 | PL_doextract = FALSE; |
463ee0b2 LW |
607 | } |
608 | ||
ffb4593c NT |
609 | /* |
610 | * S_incline | |
611 | * This subroutine has nothing to do with tilting, whether at windmills | |
612 | * or pinball tables. Its name is short for "increment line". It | |
57843af0 | 613 | * increments the current line number in CopLINE(PL_curcop) and checks |
ffb4593c | 614 | * to see whether the line starts with a comment of the form |
9cbb5ea2 GS |
615 | * # line 500 "foo.pm" |
616 | * If so, it sets the current line number and file to the values in the comment. | |
ffb4593c NT |
617 | */ |
618 | ||
76e3520e | 619 | STATIC void |
cea2e8a9 | 620 | S_incline(pTHX_ char *s) |
463ee0b2 LW |
621 | { |
622 | char *t; | |
623 | char *n; | |
73659bf1 | 624 | char *e; |
463ee0b2 | 625 | char ch; |
463ee0b2 | 626 | |
57843af0 | 627 | CopLINE_inc(PL_curcop); |
463ee0b2 LW |
628 | if (*s++ != '#') |
629 | return; | |
bf4acbe4 | 630 | while (SPACE_OR_TAB(*s)) s++; |
73659bf1 GS |
631 | if (strnEQ(s, "line", 4)) |
632 | s += 4; | |
633 | else | |
634 | return; | |
084592ab | 635 | if (SPACE_OR_TAB(*s)) |
73659bf1 | 636 | s++; |
4e553d73 | 637 | else |
73659bf1 | 638 | return; |
bf4acbe4 | 639 | while (SPACE_OR_TAB(*s)) s++; |
463ee0b2 LW |
640 | if (!isDIGIT(*s)) |
641 | return; | |
642 | n = s; | |
643 | while (isDIGIT(*s)) | |
644 | s++; | |
bf4acbe4 | 645 | while (SPACE_OR_TAB(*s)) |
463ee0b2 | 646 | s++; |
73659bf1 | 647 | if (*s == '"' && (t = strchr(s+1, '"'))) { |
463ee0b2 | 648 | s++; |
73659bf1 GS |
649 | e = t + 1; |
650 | } | |
463ee0b2 | 651 | else { |
463ee0b2 | 652 | for (t = s; !isSPACE(*t); t++) ; |
73659bf1 | 653 | e = t; |
463ee0b2 | 654 | } |
bf4acbe4 | 655 | while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f') |
73659bf1 GS |
656 | e++; |
657 | if (*e != '\n' && *e != '\0') | |
658 | return; /* false alarm */ | |
659 | ||
463ee0b2 LW |
660 | ch = *t; |
661 | *t = '\0'; | |
f4dd75d9 | 662 | if (t - s > 0) { |
05ec9bb3 | 663 | CopFILE_free(PL_curcop); |
57843af0 | 664 | CopFILE_set(PL_curcop, s); |
f4dd75d9 | 665 | } |
463ee0b2 | 666 | *t = ch; |
57843af0 | 667 | CopLINE_set(PL_curcop, atoi(n)-1); |
463ee0b2 LW |
668 | } |
669 | ||
ffb4593c NT |
670 | /* |
671 | * S_skipspace | |
672 | * Called to gobble the appropriate amount and type of whitespace. | |
673 | * Skips comments as well. | |
674 | */ | |
675 | ||
76e3520e | 676 | STATIC char * |
cea2e8a9 | 677 | S_skipspace(pTHX_ register char *s) |
a687059c | 678 | { |
3280af22 | 679 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
bf4acbe4 | 680 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
463ee0b2 LW |
681 | s++; |
682 | return s; | |
683 | } | |
684 | for (;;) { | |
fd049845 | 685 | STRLEN prevlen; |
09bef843 | 686 | SSize_t oldprevlen, oldoldprevlen; |
9c5ffd7c | 687 | SSize_t oldloplen = 0, oldunilen = 0; |
60e6418e GS |
688 | while (s < PL_bufend && isSPACE(*s)) { |
689 | if (*s++ == '\n' && PL_in_eval && !PL_rsfp) | |
690 | incline(s); | |
691 | } | |
ffb4593c NT |
692 | |
693 | /* comment */ | |
3280af22 NIS |
694 | if (s < PL_bufend && *s == '#') { |
695 | while (s < PL_bufend && *s != '\n') | |
463ee0b2 | 696 | s++; |
60e6418e | 697 | if (s < PL_bufend) { |
463ee0b2 | 698 | s++; |
60e6418e GS |
699 | if (PL_in_eval && !PL_rsfp) { |
700 | incline(s); | |
701 | continue; | |
702 | } | |
703 | } | |
463ee0b2 | 704 | } |
ffb4593c NT |
705 | |
706 | /* only continue to recharge the buffer if we're at the end | |
707 | * of the buffer, we're not reading from a source filter, and | |
708 | * we're in normal lexing mode | |
709 | */ | |
09bef843 SB |
710 | if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat || |
711 | PL_lex_state == LEX_FORMLINE) | |
463ee0b2 | 712 | return s; |
ffb4593c NT |
713 | |
714 | /* try to recharge the buffer */ | |
9cbb5ea2 GS |
715 | if ((s = filter_gets(PL_linestr, PL_rsfp, |
716 | (prevlen = SvCUR(PL_linestr)))) == Nullch) | |
717 | { | |
718 | /* end of file. Add on the -p or -n magic */ | |
01a19ab0 NC |
719 | if (PL_minus_p) { |
720 | sv_setpv(PL_linestr, | |
721 | ";}continue{print or die qq(-p destination: $!\\n);}"); | |
3280af22 | 722 | PL_minus_n = PL_minus_p = 0; |
a0d0e21e | 723 | } |
01a19ab0 NC |
724 | else if (PL_minus_n) { |
725 | sv_setpvn(PL_linestr, ";}", 2); | |
726 | PL_minus_n = 0; | |
727 | } | |
a0d0e21e | 728 | else |
4147a61b | 729 | sv_setpvn(PL_linestr,";", 1); |
ffb4593c NT |
730 | |
731 | /* reset variables for next time we lex */ | |
9cbb5ea2 GS |
732 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart |
733 | = SvPVX(PL_linestr); | |
3280af22 | 734 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 735 | PL_last_lop = PL_last_uni = Nullch; |
ffb4593c NT |
736 | |
737 | /* Close the filehandle. Could be from -P preprocessor, | |
738 | * STDIN, or a regular file. If we were reading code from | |
739 | * STDIN (because the commandline held no -e or filename) | |
740 | * then we don't close it, we reset it so the code can | |
741 | * read from STDIN too. | |
742 | */ | |
743 | ||
3280af22 NIS |
744 | if (PL_preprocess && !PL_in_eval) |
745 | (void)PerlProc_pclose(PL_rsfp); | |
746 | else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) | |
747 | PerlIO_clearerr(PL_rsfp); | |
8990e307 | 748 | else |
3280af22 NIS |
749 | (void)PerlIO_close(PL_rsfp); |
750 | PL_rsfp = Nullfp; | |
463ee0b2 LW |
751 | return s; |
752 | } | |
ffb4593c NT |
753 | |
754 | /* not at end of file, so we only read another line */ | |
09bef843 SB |
755 | /* make corresponding updates to old pointers, for yyerror() */ |
756 | oldprevlen = PL_oldbufptr - PL_bufend; | |
757 | oldoldprevlen = PL_oldoldbufptr - PL_bufend; | |
758 | if (PL_last_uni) | |
759 | oldunilen = PL_last_uni - PL_bufend; | |
760 | if (PL_last_lop) | |
761 | oldloplen = PL_last_lop - PL_bufend; | |
3280af22 NIS |
762 | PL_linestart = PL_bufptr = s + prevlen; |
763 | PL_bufend = s + SvCUR(PL_linestr); | |
764 | s = PL_bufptr; | |
09bef843 SB |
765 | PL_oldbufptr = s + oldprevlen; |
766 | PL_oldoldbufptr = s + oldoldprevlen; | |
767 | if (PL_last_uni) | |
768 | PL_last_uni = s + oldunilen; | |
769 | if (PL_last_lop) | |
770 | PL_last_lop = s + oldloplen; | |
a0d0e21e | 771 | incline(s); |
ffb4593c NT |
772 | |
773 | /* debugger active and we're not compiling the debugger code, | |
774 | * so store the line into the debugger's array of lines | |
775 | */ | |
3280af22 | 776 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
8990e307 LW |
777 | SV *sv = NEWSV(85,0); |
778 | ||
779 | sv_upgrade(sv, SVt_PVMG); | |
3280af22 | 780 | sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr); |
0ac0412a | 781 | (void)SvIOK_on(sv); |
45977657 | 782 | SvIV_set(sv, 0); |
57843af0 | 783 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
8990e307 | 784 | } |
463ee0b2 | 785 | } |
a687059c | 786 | } |
378cc40b | 787 | |
ffb4593c NT |
788 | /* |
789 | * S_check_uni | |
790 | * Check the unary operators to ensure there's no ambiguity in how they're | |
791 | * used. An ambiguous piece of code would be: | |
792 | * rand + 5 | |
793 | * This doesn't mean rand() + 5. Because rand() is a unary operator, | |
794 | * the +5 is its argument. | |
795 | */ | |
796 | ||
76e3520e | 797 | STATIC void |
cea2e8a9 | 798 | S_check_uni(pTHX) |
ba106d47 | 799 | { |
2f3197b3 | 800 | char *s; |
a0d0e21e | 801 | char *t; |
2f3197b3 | 802 | |
3280af22 | 803 | if (PL_oldoldbufptr != PL_last_uni) |
2f3197b3 | 804 | return; |
3280af22 NIS |
805 | while (isSPACE(*PL_last_uni)) |
806 | PL_last_uni++; | |
7e2040f0 | 807 | for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ; |
3280af22 | 808 | if ((t = strchr(s, '(')) && t < PL_bufptr) |
a0d0e21e | 809 | return; |
0453d815 | 810 | if (ckWARN_d(WARN_AMBIGUOUS)){ |
f248d071 | 811 | char ch = *s; |
0453d815 | 812 | *s = '\0'; |
9014280d | 813 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
2d5ccbba | 814 | "Warning: Use of \"%s\" without parentheses is ambiguous", |
0453d815 PM |
815 | PL_last_uni); |
816 | *s = ch; | |
817 | } | |
2f3197b3 LW |
818 | } |
819 | ||
ffb4593c NT |
820 | /* |
821 | * LOP : macro to build a list operator. Its behaviour has been replaced | |
822 | * with a subroutine, S_lop() for which LOP is just another name. | |
823 | */ | |
824 | ||
a0d0e21e LW |
825 | #define LOP(f,x) return lop(f,x,s) |
826 | ||
ffb4593c NT |
827 | /* |
828 | * S_lop | |
829 | * Build a list operator (or something that might be one). The rules: | |
830 | * - if we have a next token, then it's a list operator [why?] | |
831 | * - if the next thing is an opening paren, then it's a function | |
832 | * - else it's a list operator | |
833 | */ | |
834 | ||
76e3520e | 835 | STATIC I32 |
a0be28da | 836 | S_lop(pTHX_ I32 f, int x, char *s) |
ffed7fef | 837 | { |
79072805 | 838 | yylval.ival = f; |
35c8bce7 | 839 | CLINE; |
3280af22 NIS |
840 | PL_expect = x; |
841 | PL_bufptr = s; | |
842 | PL_last_lop = PL_oldbufptr; | |
eb160463 | 843 | PL_last_lop_op = (OPCODE)f; |
3280af22 | 844 | if (PL_nexttoke) |
bbf60fe6 | 845 | return REPORT(LSTOP); |
79072805 | 846 | if (*s == '(') |
bbf60fe6 | 847 | return REPORT(FUNC); |
79072805 LW |
848 | s = skipspace(s); |
849 | if (*s == '(') | |
bbf60fe6 | 850 | return REPORT(FUNC); |
79072805 | 851 | else |
bbf60fe6 | 852 | return REPORT(LSTOP); |
79072805 LW |
853 | } |
854 | ||
ffb4593c NT |
855 | /* |
856 | * S_force_next | |
9cbb5ea2 | 857 | * When the lexer realizes it knows the next token (for instance, |
ffb4593c | 858 | * it is reordering tokens for the parser) then it can call S_force_next |
9cbb5ea2 GS |
859 | * to know what token to return the next time the lexer is called. Caller |
860 | * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer | |
861 | * handles the token correctly. | |
ffb4593c NT |
862 | */ |
863 | ||
4e553d73 | 864 | STATIC void |
cea2e8a9 | 865 | S_force_next(pTHX_ I32 type) |
79072805 | 866 | { |
3280af22 NIS |
867 | PL_nexttype[PL_nexttoke] = type; |
868 | PL_nexttoke++; | |
869 | if (PL_lex_state != LEX_KNOWNEXT) { | |
870 | PL_lex_defer = PL_lex_state; | |
871 | PL_lex_expect = PL_expect; | |
872 | PL_lex_state = LEX_KNOWNEXT; | |
79072805 LW |
873 | } |
874 | } | |
875 | ||
d0a148a6 NC |
876 | STATIC SV * |
877 | S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len) | |
878 | { | |
879 | SV *sv = newSVpvn(start,len); | |
bfed75c6 | 880 | if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len)) |
d0a148a6 NC |
881 | SvUTF8_on(sv); |
882 | return sv; | |
883 | } | |
884 | ||
ffb4593c NT |
885 | /* |
886 | * S_force_word | |
887 | * When the lexer knows the next thing is a word (for instance, it has | |
888 | * just seen -> and it knows that the next char is a word char, then | |
889 | * it calls S_force_word to stick the next word into the PL_next lookahead. | |
890 | * | |
891 | * Arguments: | |
b1b65b59 | 892 | * char *start : buffer position (must be within PL_linestr) |
ffb4593c NT |
893 | * int token : PL_next will be this type of bare word (e.g., METHOD,WORD) |
894 | * int check_keyword : if true, Perl checks to make sure the word isn't | |
895 | * a keyword (do this if the word is a label, e.g. goto FOO) | |
896 | * int allow_pack : if true, : characters will also be allowed (require, | |
897 | * use, etc. do this) | |
9cbb5ea2 | 898 | * int allow_initial_tick : used by the "sub" lexer only. |
ffb4593c NT |
899 | */ |
900 | ||
76e3520e | 901 | STATIC char * |
cea2e8a9 | 902 | S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick) |
79072805 | 903 | { |
463ee0b2 LW |
904 | register char *s; |
905 | STRLEN len; | |
4e553d73 | 906 | |
463ee0b2 LW |
907 | start = skipspace(start); |
908 | s = start; | |
7e2040f0 | 909 | if (isIDFIRST_lazy_if(s,UTF) || |
a0d0e21e | 910 | (allow_pack && *s == ':') || |
15f0808c | 911 | (allow_initial_tick && *s == '\'') ) |
a0d0e21e | 912 | { |
3280af22 NIS |
913 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len); |
914 | if (check_keyword && keyword(PL_tokenbuf, len)) | |
463ee0b2 LW |
915 | return start; |
916 | if (token == METHOD) { | |
917 | s = skipspace(s); | |
918 | if (*s == '(') | |
3280af22 | 919 | PL_expect = XTERM; |
463ee0b2 | 920 | else { |
3280af22 | 921 | PL_expect = XOPERATOR; |
463ee0b2 | 922 | } |
79072805 | 923 | } |
d0a148a6 NC |
924 | PL_nextval[PL_nexttoke].opval |
925 | = (OP*)newSVOP(OP_CONST,0, | |
926 | S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len)); | |
3280af22 | 927 | PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE; |
79072805 LW |
928 | force_next(token); |
929 | } | |
930 | return s; | |
931 | } | |
932 | ||
ffb4593c NT |
933 | /* |
934 | * S_force_ident | |
9cbb5ea2 | 935 | * Called when the lexer wants $foo *foo &foo etc, but the program |
ffb4593c NT |
936 | * text only contains the "foo" portion. The first argument is a pointer |
937 | * to the "foo", and the second argument is the type symbol to prefix. | |
938 | * Forces the next token to be a "WORD". | |
9cbb5ea2 | 939 | * Creates the symbol if it didn't already exist (via gv_fetchpv()). |
ffb4593c NT |
940 | */ |
941 | ||
76e3520e | 942 | STATIC void |
bfed75c6 | 943 | S_force_ident(pTHX_ register const char *s, int kind) |
79072805 LW |
944 | { |
945 | if (s && *s) { | |
bfed75c6 | 946 | OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0)); |
3280af22 | 947 | PL_nextval[PL_nexttoke].opval = o; |
79072805 | 948 | force_next(WORD); |
748a9306 | 949 | if (kind) { |
11343788 | 950 | o->op_private = OPpCONST_ENTERED; |
55497cff | 951 | /* XXX see note in pp_entereval() for why we forgo typo |
952 | warnings if the symbol must be introduced in an eval. | |
953 | GSAR 96-10-12 */ | |
3280af22 | 954 | gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE, |
a0d0e21e LW |
955 | kind == '$' ? SVt_PV : |
956 | kind == '@' ? SVt_PVAV : | |
957 | kind == '%' ? SVt_PVHV : | |
958 | SVt_PVGV | |
959 | ); | |
748a9306 | 960 | } |
79072805 LW |
961 | } |
962 | } | |
963 | ||
1571675a GS |
964 | NV |
965 | Perl_str_to_version(pTHX_ SV *sv) | |
966 | { | |
967 | NV retval = 0.0; | |
968 | NV nshift = 1.0; | |
969 | STRLEN len; | |
970 | char *start = SvPVx(sv,len); | |
3aa33fe5 | 971 | bool utf = SvUTF8(sv) ? TRUE : FALSE; |
1571675a GS |
972 | char *end = start + len; |
973 | while (start < end) { | |
ba210ebe | 974 | STRLEN skip; |
1571675a GS |
975 | UV n; |
976 | if (utf) | |
9041c2e3 | 977 | n = utf8n_to_uvchr((U8*)start, len, &skip, 0); |
1571675a GS |
978 | else { |
979 | n = *(U8*)start; | |
980 | skip = 1; | |
981 | } | |
982 | retval += ((NV)n)/nshift; | |
983 | start += skip; | |
984 | nshift *= 1000; | |
985 | } | |
986 | return retval; | |
987 | } | |
988 | ||
4e553d73 | 989 | /* |
ffb4593c NT |
990 | * S_force_version |
991 | * Forces the next token to be a version number. | |
e759cc13 RGS |
992 | * If the next token appears to be an invalid version number, (e.g. "v2b"), |
993 | * and if "guessing" is TRUE, then no new token is created (and the caller | |
994 | * must use an alternative parsing method). | |
ffb4593c NT |
995 | */ |
996 | ||
76e3520e | 997 | STATIC char * |
e759cc13 | 998 | S_force_version(pTHX_ char *s, int guessing) |
89bfa8cd | 999 | { |
1000 | OP *version = Nullop; | |
44dcb63b | 1001 | char *d; |
89bfa8cd | 1002 | |
1003 | s = skipspace(s); | |
1004 | ||
44dcb63b | 1005 | d = s; |
dd629d5b | 1006 | if (*d == 'v') |
44dcb63b | 1007 | d++; |
44dcb63b | 1008 | if (isDIGIT(*d)) { |
e759cc13 RGS |
1009 | while (isDIGIT(*d) || *d == '_' || *d == '.') |
1010 | d++; | |
9f3d182e | 1011 | if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) { |
dd629d5b | 1012 | SV *ver; |
b73d6f50 | 1013 | s = scan_num(s, &yylval); |
89bfa8cd | 1014 | version = yylval.opval; |
dd629d5b GS |
1015 | ver = cSVOPx(version)->op_sv; |
1016 | if (SvPOK(ver) && !SvNIOK(ver)) { | |
155aba94 | 1017 | (void)SvUPGRADE(ver, SVt_PVNV); |
9d6ce603 | 1018 | SvNV_set(ver, str_to_version(ver)); |
1571675a | 1019 | SvNOK_on(ver); /* hint that it is a version */ |
44dcb63b | 1020 | } |
89bfa8cd | 1021 | } |
e759cc13 RGS |
1022 | else if (guessing) |
1023 | return s; | |
89bfa8cd | 1024 | } |
1025 | ||
1026 | /* NOTE: The parser sees the package name and the VERSION swapped */ | |
3280af22 | 1027 | PL_nextval[PL_nexttoke].opval = version; |
4e553d73 | 1028 | force_next(WORD); |
89bfa8cd | 1029 | |
e759cc13 | 1030 | return s; |
89bfa8cd | 1031 | } |
1032 | ||
ffb4593c NT |
1033 | /* |
1034 | * S_tokeq | |
1035 | * Tokenize a quoted string passed in as an SV. It finds the next | |
1036 | * chunk, up to end of string or a backslash. It may make a new | |
1037 | * SV containing that chunk (if HINT_NEW_STRING is on). It also | |
1038 | * turns \\ into \. | |
1039 | */ | |
1040 | ||
76e3520e | 1041 | STATIC SV * |
cea2e8a9 | 1042 | S_tokeq(pTHX_ SV *sv) |
79072805 LW |
1043 | { |
1044 | register char *s; | |
1045 | register char *send; | |
1046 | register char *d; | |
b3ac6de7 IZ |
1047 | STRLEN len = 0; |
1048 | SV *pv = sv; | |
79072805 LW |
1049 | |
1050 | if (!SvLEN(sv)) | |
b3ac6de7 | 1051 | goto finish; |
79072805 | 1052 | |
a0d0e21e | 1053 | s = SvPV_force(sv, len); |
21a311ee | 1054 | if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1) |
b3ac6de7 | 1055 | goto finish; |
463ee0b2 | 1056 | send = s + len; |
79072805 LW |
1057 | while (s < send && *s != '\\') |
1058 | s++; | |
1059 | if (s == send) | |
b3ac6de7 | 1060 | goto finish; |
79072805 | 1061 | d = s; |
be4731d2 | 1062 | if ( PL_hints & HINT_NEW_STRING ) { |
79cb57f6 | 1063 | pv = sv_2mortal(newSVpvn(SvPVX(pv), len)); |
be4731d2 NIS |
1064 | if (SvUTF8(sv)) |
1065 | SvUTF8_on(pv); | |
1066 | } | |
79072805 LW |
1067 | while (s < send) { |
1068 | if (*s == '\\') { | |
a0d0e21e | 1069 | if (s + 1 < send && (s[1] == '\\')) |
79072805 LW |
1070 | s++; /* all that, just for this */ |
1071 | } | |
1072 | *d++ = *s++; | |
1073 | } | |
1074 | *d = '\0'; | |
463ee0b2 | 1075 | SvCUR_set(sv, d - SvPVX(sv)); |
b3ac6de7 | 1076 | finish: |
3280af22 | 1077 | if ( PL_hints & HINT_NEW_STRING ) |
b3ac6de7 | 1078 | return new_constant(NULL, 0, "q", sv, pv, "q"); |
79072805 LW |
1079 | return sv; |
1080 | } | |
1081 | ||
ffb4593c NT |
1082 | /* |
1083 | * Now come three functions related to double-quote context, | |
1084 | * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when | |
1085 | * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They | |
1086 | * interact with PL_lex_state, and create fake ( ... ) argument lists | |
1087 | * to handle functions and concatenation. | |
1088 | * They assume that whoever calls them will be setting up a fake | |
1089 | * join call, because each subthing puts a ',' after it. This lets | |
1090 | * "lower \luPpEr" | |
1091 | * become | |
1092 | * join($, , 'lower ', lcfirst( 'uPpEr', ) ,) | |
1093 | * | |
1094 | * (I'm not sure whether the spurious commas at the end of lcfirst's | |
1095 | * arguments and join's arguments are created or not). | |
1096 | */ | |
1097 | ||
1098 | /* | |
1099 | * S_sublex_start | |
1100 | * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST). | |
1101 | * | |
1102 | * Pattern matching will set PL_lex_op to the pattern-matching op to | |
1103 | * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise). | |
1104 | * | |
1105 | * OP_CONST and OP_READLINE are easy--just make the new op and return. | |
1106 | * | |
1107 | * Everything else becomes a FUNC. | |
1108 | * | |
1109 | * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we | |
1110 | * had an OP_CONST or OP_READLINE). This just sets us up for a | |
1111 | * call to S_sublex_push(). | |
1112 | */ | |
1113 | ||
76e3520e | 1114 | STATIC I32 |
cea2e8a9 | 1115 | S_sublex_start(pTHX) |
79072805 LW |
1116 | { |
1117 | register I32 op_type = yylval.ival; | |
79072805 LW |
1118 | |
1119 | if (op_type == OP_NULL) { | |
3280af22 NIS |
1120 | yylval.opval = PL_lex_op; |
1121 | PL_lex_op = Nullop; | |
79072805 LW |
1122 | return THING; |
1123 | } | |
1124 | if (op_type == OP_CONST || op_type == OP_READLINE) { | |
3280af22 | 1125 | SV *sv = tokeq(PL_lex_stuff); |
b3ac6de7 IZ |
1126 | |
1127 | if (SvTYPE(sv) == SVt_PVIV) { | |
1128 | /* Overloaded constants, nothing fancy: Convert to SVt_PV: */ | |
1129 | STRLEN len; | |
1130 | char *p; | |
1131 | SV *nsv; | |
1132 | ||
1133 | p = SvPV(sv, len); | |
79cb57f6 | 1134 | nsv = newSVpvn(p, len); |
01ec43d0 GS |
1135 | if (SvUTF8(sv)) |
1136 | SvUTF8_on(nsv); | |
b3ac6de7 IZ |
1137 | SvREFCNT_dec(sv); |
1138 | sv = nsv; | |
4e553d73 | 1139 | } |
b3ac6de7 | 1140 | yylval.opval = (OP*)newSVOP(op_type, 0, sv); |
3280af22 | 1141 | PL_lex_stuff = Nullsv; |
6f33ba73 RGS |
1142 | /* Allow <FH> // "foo" */ |
1143 | if (op_type == OP_READLINE) | |
1144 | PL_expect = XTERMORDORDOR; | |
79072805 LW |
1145 | return THING; |
1146 | } | |
1147 | ||
3280af22 NIS |
1148 | PL_sublex_info.super_state = PL_lex_state; |
1149 | PL_sublex_info.sub_inwhat = op_type; | |
1150 | PL_sublex_info.sub_op = PL_lex_op; | |
1151 | PL_lex_state = LEX_INTERPPUSH; | |
55497cff | 1152 | |
3280af22 NIS |
1153 | PL_expect = XTERM; |
1154 | if (PL_lex_op) { | |
1155 | yylval.opval = PL_lex_op; | |
1156 | PL_lex_op = Nullop; | |
55497cff | 1157 | return PMFUNC; |
1158 | } | |
1159 | else | |
1160 | return FUNC; | |
1161 | } | |
1162 | ||
ffb4593c NT |
1163 | /* |
1164 | * S_sublex_push | |
1165 | * Create a new scope to save the lexing state. The scope will be | |
1166 | * ended in S_sublex_done. Returns a '(', starting the function arguments | |
1167 | * to the uc, lc, etc. found before. | |
1168 | * Sets PL_lex_state to LEX_INTERPCONCAT. | |
1169 | */ | |
1170 | ||
76e3520e | 1171 | STATIC I32 |
cea2e8a9 | 1172 | S_sublex_push(pTHX) |
55497cff | 1173 | { |
27da23d5 | 1174 | dVAR; |
f46d017c | 1175 | ENTER; |
55497cff | 1176 | |
3280af22 NIS |
1177 | PL_lex_state = PL_sublex_info.super_state; |
1178 | SAVEI32(PL_lex_dojoin); | |
1179 | SAVEI32(PL_lex_brackets); | |
3280af22 NIS |
1180 | SAVEI32(PL_lex_casemods); |
1181 | SAVEI32(PL_lex_starts); | |
1182 | SAVEI32(PL_lex_state); | |
7766f137 | 1183 | SAVEVPTR(PL_lex_inpat); |
3280af22 | 1184 | SAVEI32(PL_lex_inwhat); |
57843af0 | 1185 | SAVECOPLINE(PL_curcop); |
3280af22 | 1186 | SAVEPPTR(PL_bufptr); |
8452ff4b | 1187 | SAVEPPTR(PL_bufend); |
3280af22 NIS |
1188 | SAVEPPTR(PL_oldbufptr); |
1189 | SAVEPPTR(PL_oldoldbufptr); | |
207e3d1a JH |
1190 | SAVEPPTR(PL_last_lop); |
1191 | SAVEPPTR(PL_last_uni); | |
3280af22 NIS |
1192 | SAVEPPTR(PL_linestart); |
1193 | SAVESPTR(PL_linestr); | |
8edd5f42 RGS |
1194 | SAVEGENERICPV(PL_lex_brackstack); |
1195 | SAVEGENERICPV(PL_lex_casestack); | |
3280af22 NIS |
1196 | |
1197 | PL_linestr = PL_lex_stuff; | |
1198 | PL_lex_stuff = Nullsv; | |
1199 | ||
9cbb5ea2 GS |
1200 | PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart |
1201 | = SvPVX(PL_linestr); | |
3280af22 | 1202 | PL_bufend += SvCUR(PL_linestr); |
207e3d1a | 1203 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 NIS |
1204 | SAVEFREESV(PL_linestr); |
1205 | ||
1206 | PL_lex_dojoin = FALSE; | |
1207 | PL_lex_brackets = 0; | |
3280af22 NIS |
1208 | New(899, PL_lex_brackstack, 120, char); |
1209 | New(899, PL_lex_casestack, 12, char); | |
3280af22 NIS |
1210 | PL_lex_casemods = 0; |
1211 | *PL_lex_casestack = '\0'; | |
1212 | PL_lex_starts = 0; | |
1213 | PL_lex_state = LEX_INTERPCONCAT; | |
eb160463 | 1214 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
3280af22 NIS |
1215 | |
1216 | PL_lex_inwhat = PL_sublex_info.sub_inwhat; | |
1217 | if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST) | |
1218 | PL_lex_inpat = PL_sublex_info.sub_op; | |
79072805 | 1219 | else |
3280af22 | 1220 | PL_lex_inpat = Nullop; |
79072805 | 1221 | |
55497cff | 1222 | return '('; |
79072805 LW |
1223 | } |
1224 | ||
ffb4593c NT |
1225 | /* |
1226 | * S_sublex_done | |
1227 | * Restores lexer state after a S_sublex_push. | |
1228 | */ | |
1229 | ||
76e3520e | 1230 | STATIC I32 |
cea2e8a9 | 1231 | S_sublex_done(pTHX) |
79072805 | 1232 | { |
27da23d5 | 1233 | dVAR; |
3280af22 | 1234 | if (!PL_lex_starts++) { |
9aa983d2 JH |
1235 | SV *sv = newSVpvn("",0); |
1236 | if (SvUTF8(PL_linestr)) | |
1237 | SvUTF8_on(sv); | |
3280af22 | 1238 | PL_expect = XOPERATOR; |
9aa983d2 | 1239 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
79072805 LW |
1240 | return THING; |
1241 | } | |
1242 | ||
3280af22 NIS |
1243 | if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */ |
1244 | PL_lex_state = LEX_INTERPCASEMOD; | |
cea2e8a9 | 1245 | return yylex(); |
79072805 LW |
1246 | } |
1247 | ||
ffb4593c | 1248 | /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */ |
3280af22 NIS |
1249 | if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) { |
1250 | PL_linestr = PL_lex_repl; | |
1251 | PL_lex_inpat = 0; | |
1252 | PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr); | |
1253 | PL_bufend += SvCUR(PL_linestr); | |
207e3d1a | 1254 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 NIS |
1255 | SAVEFREESV(PL_linestr); |
1256 | PL_lex_dojoin = FALSE; | |
1257 | PL_lex_brackets = 0; | |
3280af22 NIS |
1258 | PL_lex_casemods = 0; |
1259 | *PL_lex_casestack = '\0'; | |
1260 | PL_lex_starts = 0; | |
25da4f38 | 1261 | if (SvEVALED(PL_lex_repl)) { |
3280af22 NIS |
1262 | PL_lex_state = LEX_INTERPNORMAL; |
1263 | PL_lex_starts++; | |
e9fa98b2 HS |
1264 | /* we don't clear PL_lex_repl here, so that we can check later |
1265 | whether this is an evalled subst; that means we rely on the | |
1266 | logic to ensure sublex_done() is called again only via the | |
1267 | branch (in yylex()) that clears PL_lex_repl, else we'll loop */ | |
79072805 | 1268 | } |
e9fa98b2 | 1269 | else { |
3280af22 | 1270 | PL_lex_state = LEX_INTERPCONCAT; |
e9fa98b2 HS |
1271 | PL_lex_repl = Nullsv; |
1272 | } | |
79072805 | 1273 | return ','; |
ffed7fef LW |
1274 | } |
1275 | else { | |
f46d017c | 1276 | LEAVE; |
3280af22 NIS |
1277 | PL_bufend = SvPVX(PL_linestr); |
1278 | PL_bufend += SvCUR(PL_linestr); | |
1279 | PL_expect = XOPERATOR; | |
09bef843 | 1280 | PL_sublex_info.sub_inwhat = 0; |
79072805 | 1281 | return ')'; |
ffed7fef LW |
1282 | } |
1283 | } | |
1284 | ||
02aa26ce NT |
1285 | /* |
1286 | scan_const | |
1287 | ||
1288 | Extracts a pattern, double-quoted string, or transliteration. This | |
1289 | is terrifying code. | |
1290 | ||
3280af22 NIS |
1291 | It looks at lex_inwhat and PL_lex_inpat to find out whether it's |
1292 | processing a pattern (PL_lex_inpat is true), a transliteration | |
02aa26ce NT |
1293 | (lex_inwhat & OP_TRANS is true), or a double-quoted string. |
1294 | ||
9b599b2a GS |
1295 | Returns a pointer to the character scanned up to. Iff this is |
1296 | advanced from the start pointer supplied (ie if anything was | |
1297 | successfully parsed), will leave an OP for the substring scanned | |
1298 | in yylval. Caller must intuit reason for not parsing further | |
1299 | by looking at the next characters herself. | |
1300 | ||
02aa26ce NT |
1301 | In patterns: |
1302 | backslashes: | |
1303 | double-quoted style: \r and \n | |
1304 | regexp special ones: \D \s | |
1305 | constants: \x3 | |
1306 | backrefs: \1 (deprecated in substitution replacements) | |
1307 | case and quoting: \U \Q \E | |
1308 | stops on @ and $, but not for $ as tail anchor | |
1309 | ||
1310 | In transliterations: | |
1311 | characters are VERY literal, except for - not at the start or end | |
1312 | of the string, which indicates a range. scan_const expands the | |
1313 | range to the full set of intermediate characters. | |
1314 | ||
1315 | In double-quoted strings: | |
1316 | backslashes: | |
1317 | double-quoted style: \r and \n | |
1318 | constants: \x3 | |
1319 | backrefs: \1 (deprecated) | |
1320 | case and quoting: \U \Q \E | |
1321 | stops on @ and $ | |
1322 | ||
1323 | scan_const does *not* construct ops to handle interpolated strings. | |
1324 | It stops processing as soon as it finds an embedded $ or @ variable | |
1325 | and leaves it to the caller to work out what's going on. | |
1326 | ||
da6eedaa | 1327 | @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo. |
02aa26ce NT |
1328 | |
1329 | $ in pattern could be $foo or could be tail anchor. Assumption: | |
1330 | it's a tail anchor if $ is the last thing in the string, or if it's | |
1331 | followed by one of ")| \n\t" | |
1332 | ||
1333 | \1 (backreferences) are turned into $1 | |
1334 | ||
1335 | The structure of the code is | |
1336 | while (there's a character to process) { | |
1337 | handle transliteration ranges | |
1338 | skip regexp comments | |
1339 | skip # initiated comments in //x patterns | |
1340 | check for embedded @foo | |
1341 | check for embedded scalars | |
1342 | if (backslash) { | |
1343 | leave intact backslashes from leave (below) | |
1344 | deprecate \1 in strings and sub replacements | |
1345 | handle string-changing backslashes \l \U \Q \E, etc. | |
1346 | switch (what was escaped) { | |
1347 | handle - in a transliteration (becomes a literal -) | |
1348 | handle \132 octal characters | |
1349 | handle 0x15 hex characters | |
1350 | handle \cV (control V) | |
1351 | handle printf backslashes (\f, \r, \n, etc) | |
1352 | } (end switch) | |
1353 | } (end if backslash) | |
1354 | } (end while character to read) | |
4e553d73 | 1355 | |
02aa26ce NT |
1356 | */ |
1357 | ||
76e3520e | 1358 | STATIC char * |
cea2e8a9 | 1359 | S_scan_const(pTHX_ char *start) |
79072805 | 1360 | { |
3280af22 | 1361 | register char *send = PL_bufend; /* end of the constant */ |
02aa26ce NT |
1362 | SV *sv = NEWSV(93, send - start); /* sv for the constant */ |
1363 | register char *s = start; /* start of the constant */ | |
1364 | register char *d = SvPVX(sv); /* destination for copies */ | |
1365 | bool dorange = FALSE; /* are we in a translit range? */ | |
c2e66d9e | 1366 | bool didrange = FALSE; /* did we just finish a range? */ |
2b9d42f0 NIS |
1367 | I32 has_utf8 = FALSE; /* Output constant is UTF8 */ |
1368 | I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */ | |
012bcf8d GS |
1369 | UV uv; |
1370 | ||
dff6d3cd | 1371 | const char *leaveit = /* set of acceptably-backslashed characters */ |
3280af22 | 1372 | PL_lex_inpat |
b6d5fef8 | 1373 | ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#" |
9b599b2a | 1374 | : ""; |
79072805 | 1375 | |
2b9d42f0 NIS |
1376 | if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) { |
1377 | /* If we are doing a trans and we know we want UTF8 set expectation */ | |
1378 | has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF); | |
1379 | this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); | |
1380 | } | |
1381 | ||
1382 | ||
79072805 | 1383 | while (s < send || dorange) { |
02aa26ce | 1384 | /* get transliterations out of the way (they're most literal) */ |
3280af22 | 1385 | if (PL_lex_inwhat == OP_TRANS) { |
02aa26ce | 1386 | /* expand a range A-Z to the full set of characters. AIE! */ |
79072805 | 1387 | if (dorange) { |
1ba5c669 JH |
1388 | I32 i; /* current expanded character */ |
1389 | I32 min; /* first character in range */ | |
1390 | I32 max; /* last character in range */ | |
02aa26ce | 1391 | |
2b9d42f0 | 1392 | if (has_utf8) { |
8973db79 JH |
1393 | char *c = (char*)utf8_hop((U8*)d, -1); |
1394 | char *e = d++; | |
1395 | while (e-- > c) | |
1396 | *(e + 1) = *e; | |
25716404 | 1397 | *c = (char)UTF_TO_NATIVE(0xff); |
8973db79 JH |
1398 | /* mark the range as done, and continue */ |
1399 | dorange = FALSE; | |
1400 | didrange = TRUE; | |
1401 | continue; | |
1402 | } | |
2b9d42f0 | 1403 | |
02aa26ce | 1404 | i = d - SvPVX(sv); /* remember current offset */ |
9cbb5ea2 GS |
1405 | SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */ |
1406 | d = SvPVX(sv) + i; /* refresh d after realloc */ | |
02aa26ce NT |
1407 | d -= 2; /* eat the first char and the - */ |
1408 | ||
8ada0baa JH |
1409 | min = (U8)*d; /* first char in range */ |
1410 | max = (U8)d[1]; /* last char in range */ | |
1411 | ||
c2e66d9e | 1412 | if (min > max) { |
01ec43d0 | 1413 | Perl_croak(aTHX_ |
d1573ac7 | 1414 | "Invalid range \"%c-%c\" in transliteration operator", |
1ba5c669 | 1415 | (char)min, (char)max); |
c2e66d9e GS |
1416 | } |
1417 | ||
c7f1f016 | 1418 | #ifdef EBCDIC |
8ada0baa JH |
1419 | if ((isLOWER(min) && isLOWER(max)) || |
1420 | (isUPPER(min) && isUPPER(max))) { | |
1421 | if (isLOWER(min)) { | |
1422 | for (i = min; i <= max; i++) | |
1423 | if (isLOWER(i)) | |
db42d148 | 1424 | *d++ = NATIVE_TO_NEED(has_utf8,i); |
8ada0baa JH |
1425 | } else { |
1426 | for (i = min; i <= max; i++) | |
1427 | if (isUPPER(i)) | |
db42d148 | 1428 | *d++ = NATIVE_TO_NEED(has_utf8,i); |
8ada0baa JH |
1429 | } |
1430 | } | |
1431 | else | |
1432 | #endif | |
1433 | for (i = min; i <= max; i++) | |
eb160463 | 1434 | *d++ = (char)i; |
02aa26ce NT |
1435 | |
1436 | /* mark the range as done, and continue */ | |
79072805 | 1437 | dorange = FALSE; |
01ec43d0 | 1438 | didrange = TRUE; |
79072805 | 1439 | continue; |
4e553d73 | 1440 | } |
02aa26ce NT |
1441 | |
1442 | /* range begins (ignore - as first or last char) */ | |
79072805 | 1443 | else if (*s == '-' && s+1 < send && s != start) { |
4e553d73 | 1444 | if (didrange) { |
1fafa243 | 1445 | Perl_croak(aTHX_ "Ambiguous range in transliteration operator"); |
01ec43d0 | 1446 | } |
2b9d42f0 | 1447 | if (has_utf8) { |
25716404 | 1448 | *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */ |
a0ed51b3 LW |
1449 | s++; |
1450 | continue; | |
1451 | } | |
79072805 LW |
1452 | dorange = TRUE; |
1453 | s++; | |
01ec43d0 GS |
1454 | } |
1455 | else { | |
1456 | didrange = FALSE; | |
1457 | } | |
79072805 | 1458 | } |
02aa26ce NT |
1459 | |
1460 | /* if we get here, we're not doing a transliteration */ | |
1461 | ||
0f5d15d6 IZ |
1462 | /* skip for regexp comments /(?#comment)/ and code /(?{code})/, |
1463 | except for the last char, which will be done separately. */ | |
3280af22 | 1464 | else if (*s == '(' && PL_lex_inpat && s[1] == '?') { |
cc6b7395 | 1465 | if (s[2] == '#') { |
e994fd66 | 1466 | while (s+1 < send && *s != ')') |
db42d148 | 1467 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
155aba94 GS |
1468 | } |
1469 | else if (s[2] == '{' /* This should match regcomp.c */ | |
1470 | || ((s[2] == 'p' || s[2] == '?') && s[3] == '{')) | |
1471 | { | |
cc6b7395 | 1472 | I32 count = 1; |
0f5d15d6 | 1473 | char *regparse = s + (s[2] == '{' ? 3 : 4); |
cc6b7395 IZ |
1474 | char c; |
1475 | ||
d9f97599 GS |
1476 | while (count && (c = *regparse)) { |
1477 | if (c == '\\' && regparse[1]) | |
1478 | regparse++; | |
4e553d73 | 1479 | else if (c == '{') |
cc6b7395 | 1480 | count++; |
4e553d73 | 1481 | else if (c == '}') |
cc6b7395 | 1482 | count--; |
d9f97599 | 1483 | regparse++; |
cc6b7395 | 1484 | } |
e994fd66 | 1485 | if (*regparse != ')') |
5bdf89e7 | 1486 | regparse--; /* Leave one char for continuation. */ |
0f5d15d6 | 1487 | while (s < regparse) |
db42d148 | 1488 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
cc6b7395 | 1489 | } |
748a9306 | 1490 | } |
02aa26ce NT |
1491 | |
1492 | /* likewise skip #-initiated comments in //x patterns */ | |
3280af22 NIS |
1493 | else if (*s == '#' && PL_lex_inpat && |
1494 | ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) { | |
748a9306 | 1495 | while (s+1 < send && *s != '\n') |
db42d148 | 1496 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
748a9306 | 1497 | } |
02aa26ce | 1498 | |
5d1d4326 | 1499 | /* check for embedded arrays |
da6eedaa | 1500 | (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-) |
5d1d4326 | 1501 | */ |
7e2040f0 | 1502 | else if (*s == '@' && s[1] |
5d1d4326 | 1503 | && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1]))) |
79072805 | 1504 | break; |
02aa26ce NT |
1505 | |
1506 | /* check for embedded scalars. only stop if we're sure it's a | |
1507 | variable. | |
1508 | */ | |
79072805 | 1509 | else if (*s == '$') { |
3280af22 | 1510 | if (!PL_lex_inpat) /* not a regexp, so $ must be var */ |
79072805 | 1511 | break; |
6002328a | 1512 | if (s + 1 < send && !strchr("()| \r\n\t", s[1])) |
79072805 LW |
1513 | break; /* in regexp, $ might be tail anchor */ |
1514 | } | |
02aa26ce | 1515 | |
2b9d42f0 NIS |
1516 | /* End of else if chain - OP_TRANS rejoin rest */ |
1517 | ||
02aa26ce | 1518 | /* backslashes */ |
79072805 LW |
1519 | if (*s == '\\' && s+1 < send) { |
1520 | s++; | |
02aa26ce NT |
1521 | |
1522 | /* some backslashes we leave behind */ | |
c9f97d15 | 1523 | if (*leaveit && *s && strchr(leaveit, *s)) { |
db42d148 NIS |
1524 | *d++ = NATIVE_TO_NEED(has_utf8,'\\'); |
1525 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); | |
79072805 LW |
1526 | continue; |
1527 | } | |
02aa26ce NT |
1528 | |
1529 | /* deprecate \1 in strings and substitution replacements */ | |
3280af22 | 1530 | if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat && |
a0d0e21e | 1531 | isDIGIT(*s) && *s != '0' && !isDIGIT(s[1])) |
79072805 | 1532 | { |
599cee73 | 1533 | if (ckWARN(WARN_SYNTAX)) |
9014280d | 1534 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s); |
79072805 LW |
1535 | *--s = '$'; |
1536 | break; | |
1537 | } | |
02aa26ce NT |
1538 | |
1539 | /* string-change backslash escapes */ | |
3280af22 | 1540 | if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) { |
79072805 LW |
1541 | --s; |
1542 | break; | |
1543 | } | |
02aa26ce NT |
1544 | |
1545 | /* if we get here, it's either a quoted -, or a digit */ | |
79072805 | 1546 | switch (*s) { |
02aa26ce NT |
1547 | |
1548 | /* quoted - in transliterations */ | |
79072805 | 1549 | case '-': |
3280af22 | 1550 | if (PL_lex_inwhat == OP_TRANS) { |
79072805 LW |
1551 | *d++ = *s++; |
1552 | continue; | |
1553 | } | |
1554 | /* FALL THROUGH */ | |
1555 | default: | |
11b8faa4 | 1556 | { |
707afd92 | 1557 | if (ckWARN(WARN_MISC) && |
bfed75c6 | 1558 | isALNUM(*s) && |
707afd92 | 1559 | *s != '_') |
9014280d | 1560 | Perl_warner(aTHX_ packWARN(WARN_MISC), |
11b8faa4 JH |
1561 | "Unrecognized escape \\%c passed through", |
1562 | *s); | |
1563 | /* default action is to copy the quoted character */ | |
f9a63242 | 1564 | goto default_action; |
11b8faa4 | 1565 | } |
02aa26ce NT |
1566 | |
1567 | /* \132 indicates an octal constant */ | |
79072805 LW |
1568 | case '0': case '1': case '2': case '3': |
1569 | case '4': case '5': case '6': case '7': | |
ba210ebe | 1570 | { |
53305cf1 NC |
1571 | I32 flags = 0; |
1572 | STRLEN len = 3; | |
1573 | uv = grok_oct(s, &len, &flags, NULL); | |
ba210ebe JH |
1574 | s += len; |
1575 | } | |
012bcf8d | 1576 | goto NUM_ESCAPE_INSERT; |
02aa26ce NT |
1577 | |
1578 | /* \x24 indicates a hex constant */ | |
79072805 | 1579 | case 'x': |
a0ed51b3 LW |
1580 | ++s; |
1581 | if (*s == '{') { | |
1582 | char* e = strchr(s, '}'); | |
a4c04bdc NC |
1583 | I32 flags = PERL_SCAN_ALLOW_UNDERSCORES | |
1584 | PERL_SCAN_DISALLOW_PREFIX; | |
53305cf1 | 1585 | STRLEN len; |
355860ce | 1586 | |
53305cf1 | 1587 | ++s; |
adaeee49 | 1588 | if (!e) { |
a0ed51b3 | 1589 | yyerror("Missing right brace on \\x{}"); |
355860ce | 1590 | continue; |
ba210ebe | 1591 | } |
53305cf1 NC |
1592 | len = e - s; |
1593 | uv = grok_hex(s, &len, &flags, NULL); | |
ba210ebe | 1594 | s = e + 1; |
a0ed51b3 LW |
1595 | } |
1596 | else { | |
ba210ebe | 1597 | { |
53305cf1 | 1598 | STRLEN len = 2; |
a4c04bdc | 1599 | I32 flags = PERL_SCAN_DISALLOW_PREFIX; |
53305cf1 | 1600 | uv = grok_hex(s, &len, &flags, NULL); |
ba210ebe JH |
1601 | s += len; |
1602 | } | |
012bcf8d GS |
1603 | } |
1604 | ||
1605 | NUM_ESCAPE_INSERT: | |
1606 | /* Insert oct or hex escaped character. | |
301d3d20 | 1607 | * There will always enough room in sv since such |
db42d148 | 1608 | * escapes will be longer than any UTF-8 sequence |
301d3d20 | 1609 | * they can end up as. */ |
ba7cea30 | 1610 | |
c7f1f016 NIS |
1611 | /* We need to map to chars to ASCII before doing the tests |
1612 | to cover EBCDIC | |
1613 | */ | |
c4d5f83a | 1614 | if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) { |
9aa983d2 | 1615 | if (!has_utf8 && uv > 255) { |
301d3d20 JH |
1616 | /* Might need to recode whatever we have |
1617 | * accumulated so far if it contains any | |
1618 | * hibit chars. | |
1619 | * | |
1620 | * (Can't we keep track of that and avoid | |
1621 | * this rescan? --jhi) | |
012bcf8d | 1622 | */ |
c7f1f016 | 1623 | int hicount = 0; |
63cd0674 NIS |
1624 | U8 *c; |
1625 | for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) { | |
c4d5f83a | 1626 | if (!NATIVE_IS_INVARIANT(*c)) { |
012bcf8d | 1627 | hicount++; |
db42d148 | 1628 | } |
012bcf8d | 1629 | } |
63cd0674 | 1630 | if (hicount) { |
db42d148 NIS |
1631 | STRLEN offset = d - SvPVX(sv); |
1632 | U8 *src, *dst; | |
1633 | d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset; | |
1634 | src = (U8 *)d - 1; | |
1635 | dst = src+hicount; | |
1636 | d += hicount; | |
1637 | while (src >= (U8 *)SvPVX(sv)) { | |
c4d5f83a | 1638 | if (!NATIVE_IS_INVARIANT(*src)) { |
63cd0674 | 1639 | U8 ch = NATIVE_TO_ASCII(*src); |
eb160463 GS |
1640 | *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch); |
1641 | *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch); | |
012bcf8d GS |
1642 | } |
1643 | else { | |
63cd0674 | 1644 | *dst-- = *src; |
012bcf8d | 1645 | } |
c7f1f016 | 1646 | src--; |
012bcf8d GS |
1647 | } |
1648 | } | |
1649 | } | |
1650 | ||
9aa983d2 | 1651 | if (has_utf8 || uv > 255) { |
9041c2e3 | 1652 | d = (char*)uvchr_to_utf8((U8*)d, uv); |
4e553d73 | 1653 | has_utf8 = TRUE; |
f9a63242 JH |
1654 | if (PL_lex_inwhat == OP_TRANS && |
1655 | PL_sublex_info.sub_op) { | |
1656 | PL_sublex_info.sub_op->op_private |= | |
1657 | (PL_lex_repl ? OPpTRANS_FROM_UTF | |
1658 | : OPpTRANS_TO_UTF); | |
f9a63242 | 1659 | } |
012bcf8d | 1660 | } |
a0ed51b3 | 1661 | else { |
012bcf8d | 1662 | *d++ = (char)uv; |
a0ed51b3 | 1663 | } |
012bcf8d GS |
1664 | } |
1665 | else { | |
c4d5f83a | 1666 | *d++ = (char) uv; |
a0ed51b3 | 1667 | } |
79072805 | 1668 | continue; |
02aa26ce | 1669 | |
b239daa5 | 1670 | /* \N{LATIN SMALL LETTER A} is a named character */ |
4a2d328f | 1671 | case 'N': |
55eda711 | 1672 | ++s; |
423cee85 JH |
1673 | if (*s == '{') { |
1674 | char* e = strchr(s, '}'); | |
155aba94 | 1675 | SV *res; |
423cee85 JH |
1676 | STRLEN len; |
1677 | char *str; | |
4e553d73 | 1678 | |
423cee85 | 1679 | if (!e) { |
5777a3f7 | 1680 | yyerror("Missing right brace on \\N{}"); |
423cee85 JH |
1681 | e = s - 1; |
1682 | goto cont_scan; | |
1683 | } | |
dbc0d4f2 JH |
1684 | if (e > s + 2 && s[1] == 'U' && s[2] == '+') { |
1685 | /* \N{U+...} */ | |
1686 | I32 flags = PERL_SCAN_ALLOW_UNDERSCORES | | |
1687 | PERL_SCAN_DISALLOW_PREFIX; | |
1688 | s += 3; | |
1689 | len = e - s; | |
1690 | uv = grok_hex(s, &len, &flags, NULL); | |
1691 | s = e + 1; | |
1692 | goto NUM_ESCAPE_INSERT; | |
1693 | } | |
55eda711 JH |
1694 | res = newSVpvn(s + 1, e - s - 1); |
1695 | res = new_constant( Nullch, 0, "charnames", | |
1696 | res, Nullsv, "\\N{...}" ); | |
f9a63242 JH |
1697 | if (has_utf8) |
1698 | sv_utf8_upgrade(res); | |
423cee85 | 1699 | str = SvPV(res,len); |
1c47067b JH |
1700 | #ifdef EBCDIC_NEVER_MIND |
1701 | /* charnames uses pack U and that has been | |
1702 | * recently changed to do the below uni->native | |
1703 | * mapping, so this would be redundant (and wrong, | |
1704 | * the code point would be doubly converted). | |
1705 | * But leave this in just in case the pack U change | |
1706 | * gets revoked, but the semantics is still | |
1707 | * desireable for charnames. --jhi */ | |
cddc7ef4 JH |
1708 | { |
1709 | UV uv = utf8_to_uvchr((U8*)str, 0); | |
1710 | ||
1711 | if (uv < 0x100) { | |
89ebb4a3 | 1712 | U8 tmpbuf[UTF8_MAXBYTES+1], *d; |
cddc7ef4 JH |
1713 | |
1714 | d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv)); | |
1715 | sv_setpvn(res, (char *)tmpbuf, d - tmpbuf); | |
1716 | str = SvPV(res, len); | |
1717 | } | |
1718 | } | |
1719 | #endif | |
89491803 | 1720 | if (!has_utf8 && SvUTF8(res)) { |
f08d6ad9 GS |
1721 | char *ostart = SvPVX(sv); |
1722 | SvCUR_set(sv, d - ostart); | |
1723 | SvPOK_on(sv); | |
e4f3eed8 | 1724 | *d = '\0'; |
f08d6ad9 | 1725 | sv_utf8_upgrade(sv); |
d2f449dd | 1726 | /* this just broke our allocation above... */ |
eb160463 | 1727 | SvGROW(sv, (STRLEN)(send - start)); |
f08d6ad9 | 1728 | d = SvPVX(sv) + SvCUR(sv); |
89491803 | 1729 | has_utf8 = TRUE; |
f08d6ad9 | 1730 | } |
eb160463 | 1731 | if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */ |
423cee85 JH |
1732 | char *odest = SvPVX(sv); |
1733 | ||
8973db79 | 1734 | SvGROW(sv, (SvLEN(sv) + len - (e - s + 4))); |
423cee85 JH |
1735 | d = SvPVX(sv) + (d - odest); |
1736 | } | |
1737 | Copy(str, d, len, char); | |
1738 | d += len; | |
1739 | SvREFCNT_dec(res); | |
1740 | cont_scan: | |
1741 | s = e + 1; | |
1742 | } | |
1743 | else | |
5777a3f7 | 1744 | yyerror("Missing braces on \\N{}"); |
423cee85 JH |
1745 | continue; |
1746 | ||
02aa26ce | 1747 | /* \c is a control character */ |
79072805 LW |
1748 | case 'c': |
1749 | s++; | |
961ce445 | 1750 | if (s < send) { |
ba210ebe | 1751 | U8 c = *s++; |
c7f1f016 NIS |
1752 | #ifdef EBCDIC |
1753 | if (isLOWER(c)) | |
1754 | c = toUPPER(c); | |
1755 | #endif | |
db42d148 | 1756 | *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c)); |
ba210ebe | 1757 | } |
961ce445 RGS |
1758 | else { |
1759 | yyerror("Missing control char name in \\c"); | |
1760 | } | |
79072805 | 1761 | continue; |
02aa26ce NT |
1762 | |
1763 | /* printf-style backslashes, formfeeds, newlines, etc */ | |
79072805 | 1764 | case 'b': |
db42d148 | 1765 | *d++ = NATIVE_TO_NEED(has_utf8,'\b'); |
79072805 LW |
1766 | break; |
1767 | case 'n': | |
db42d148 | 1768 | *d++ = NATIVE_TO_NEED(has_utf8,'\n'); |
79072805 LW |
1769 | break; |
1770 | case 'r': | |
db42d148 | 1771 | *d++ = NATIVE_TO_NEED(has_utf8,'\r'); |
79072805 LW |
1772 | break; |
1773 | case 'f': | |
db42d148 | 1774 | *d++ = NATIVE_TO_NEED(has_utf8,'\f'); |
79072805 LW |
1775 | break; |
1776 | case 't': | |
db42d148 | 1777 | *d++ = NATIVE_TO_NEED(has_utf8,'\t'); |
79072805 | 1778 | break; |
34a3fe2a | 1779 | case 'e': |
db42d148 | 1780 | *d++ = ASCII_TO_NEED(has_utf8,'\033'); |
34a3fe2a PP |
1781 | break; |
1782 | case 'a': | |
db42d148 | 1783 | *d++ = ASCII_TO_NEED(has_utf8,'\007'); |
79072805 | 1784 | break; |
02aa26ce NT |
1785 | } /* end switch */ |
1786 | ||
79072805 LW |
1787 | s++; |
1788 | continue; | |
02aa26ce NT |
1789 | } /* end if (backslash) */ |
1790 | ||
f9a63242 | 1791 | default_action: |
2b9d42f0 NIS |
1792 | /* If we started with encoded form, or already know we want it |
1793 | and then encode the next character */ | |
1794 | if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) { | |
1795 | STRLEN len = 1; | |
1796 | UV uv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s); | |
1797 | STRLEN need = UNISKIP(NATIVE_TO_UNI(uv)); | |
1798 | s += len; | |
1799 | if (need > len) { | |
1800 | /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */ | |
1801 | STRLEN off = d - SvPVX(sv); | |
1802 | d = SvGROW(sv, SvLEN(sv) + (need-len)) + off; | |
1803 | } | |
1804 | d = (char*)uvchr_to_utf8((U8*)d, uv); | |
1805 | has_utf8 = TRUE; | |
1806 | } | |
1807 | else { | |
1808 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); | |
1809 | } | |
02aa26ce NT |
1810 | } /* while loop to process each character */ |
1811 | ||
1812 | /* terminate the string and set up the sv */ | |
79072805 | 1813 | *d = '\0'; |
463ee0b2 | 1814 | SvCUR_set(sv, d - SvPVX(sv)); |
2b9d42f0 | 1815 | if (SvCUR(sv) >= SvLEN(sv)) |
d0063567 | 1816 | Perl_croak(aTHX_ "panic: constant overflowed allocated space"); |
2b9d42f0 | 1817 | |
79072805 | 1818 | SvPOK_on(sv); |
9f4817db | 1819 | if (PL_encoding && !has_utf8) { |
d0063567 DK |
1820 | sv_recode_to_utf8(sv, PL_encoding); |
1821 | if (SvUTF8(sv)) | |
1822 | has_utf8 = TRUE; | |
9f4817db | 1823 | } |
2b9d42f0 | 1824 | if (has_utf8) { |
7e2040f0 | 1825 | SvUTF8_on(sv); |
2b9d42f0 | 1826 | if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) { |
d0063567 | 1827 | PL_sublex_info.sub_op->op_private |= |
2b9d42f0 NIS |
1828 | (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); |
1829 | } | |
1830 | } | |
79072805 | 1831 | |
02aa26ce | 1832 | /* shrink the sv if we allocated more than we used */ |
79072805 | 1833 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
1da4ca5f | 1834 | SvPV_shrink_to_cur(sv); |
79072805 | 1835 | } |
02aa26ce | 1836 | |
9b599b2a | 1837 | /* return the substring (via yylval) only if we parsed anything */ |
3280af22 NIS |
1838 | if (s > PL_bufptr) { |
1839 | if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) | |
4e553d73 | 1840 | sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"), |
b3ac6de7 | 1841 | sv, Nullsv, |
4e553d73 | 1842 | ( PL_lex_inwhat == OP_TRANS |
b3ac6de7 | 1843 | ? "tr" |
3280af22 | 1844 | : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) |
b3ac6de7 IZ |
1845 | ? "s" |
1846 | : "qq"))); | |
79072805 | 1847 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
b3ac6de7 | 1848 | } else |
8990e307 | 1849 | SvREFCNT_dec(sv); |
79072805 LW |
1850 | return s; |
1851 | } | |
1852 | ||
ffb4593c NT |
1853 | /* S_intuit_more |
1854 | * Returns TRUE if there's more to the expression (e.g., a subscript), | |
1855 | * FALSE otherwise. | |
ffb4593c NT |
1856 | * |
1857 | * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/ | |
1858 | * | |
1859 | * ->[ and ->{ return TRUE | |
1860 | * { and [ outside a pattern are always subscripts, so return TRUE | |
1861 | * if we're outside a pattern and it's not { or [, then return FALSE | |
1862 | * if we're in a pattern and the first char is a { | |
1863 | * {4,5} (any digits around the comma) returns FALSE | |
1864 | * if we're in a pattern and the first char is a [ | |
1865 | * [] returns FALSE | |
1866 | * [SOMETHING] has a funky algorithm to decide whether it's a | |
1867 | * character class or not. It has to deal with things like | |
1868 | * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/ | |
1869 | * anything else returns TRUE | |
1870 | */ | |
1871 | ||
9cbb5ea2 GS |
1872 | /* This is the one truly awful dwimmer necessary to conflate C and sed. */ |
1873 | ||
76e3520e | 1874 | STATIC int |
cea2e8a9 | 1875 | S_intuit_more(pTHX_ register char *s) |
79072805 | 1876 | { |
3280af22 | 1877 | if (PL_lex_brackets) |
79072805 LW |
1878 | return TRUE; |
1879 | if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{')) | |
1880 | return TRUE; | |
1881 | if (*s != '{' && *s != '[') | |
1882 | return FALSE; | |
3280af22 | 1883 | if (!PL_lex_inpat) |
79072805 LW |
1884 | return TRUE; |
1885 | ||
1886 | /* In a pattern, so maybe we have {n,m}. */ | |
1887 | if (*s == '{') { | |
1888 | s++; | |
1889 | if (!isDIGIT(*s)) | |
1890 | return TRUE; | |
1891 | while (isDIGIT(*s)) | |
1892 | s++; | |
1893 | if (*s == ',') | |
1894 | s++; | |
1895 | while (isDIGIT(*s)) | |
1896 | s++; | |
1897 | if (*s == '}') | |
1898 | return FALSE; | |
1899 | return TRUE; | |
1900 | ||
1901 | } | |
1902 | ||
1903 | /* On the other hand, maybe we have a character class */ | |
1904 | ||
1905 | s++; | |
1906 | if (*s == ']' || *s == '^') | |
1907 | return FALSE; | |
1908 | else { | |
ffb4593c | 1909 | /* this is terrifying, and it works */ |
79072805 LW |
1910 | int weight = 2; /* let's weigh the evidence */ |
1911 | char seen[256]; | |
f27ffc4a | 1912 | unsigned char un_char = 255, last_un_char; |
93a17b20 | 1913 | char *send = strchr(s,']'); |
3280af22 | 1914 | char tmpbuf[sizeof PL_tokenbuf * 4]; |
79072805 LW |
1915 | |
1916 | if (!send) /* has to be an expression */ | |
1917 | return TRUE; | |
1918 | ||
1919 | Zero(seen,256,char); | |
1920 | if (*s == '$') | |
1921 | weight -= 3; | |
1922 | else if (isDIGIT(*s)) { | |
1923 | if (s[1] != ']') { | |
1924 | if (isDIGIT(s[1]) && s[2] == ']') | |
1925 | weight -= 10; | |
1926 | } | |
1927 | else | |
1928 | weight -= 100; | |
1929 | } | |
1930 | for (; s < send; s++) { | |
1931 | last_un_char = un_char; | |
1932 | un_char = (unsigned char)*s; | |
1933 | switch (*s) { | |
1934 | case '@': | |
1935 | case '&': | |
1936 | case '$': | |
1937 | weight -= seen[un_char] * 10; | |
7e2040f0 | 1938 | if (isALNUM_lazy_if(s+1,UTF)) { |
8903cb82 | 1939 | scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE); |
a0d0e21e | 1940 | if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV)) |
79072805 LW |
1941 | weight -= 100; |
1942 | else | |
1943 | weight -= 10; | |
1944 | } | |
1945 | else if (*s == '$' && s[1] && | |
93a17b20 LW |
1946 | strchr("[#!%*<>()-=",s[1])) { |
1947 | if (/*{*/ strchr("])} =",s[2])) | |
79072805 LW |
1948 | weight -= 10; |
1949 | else | |
1950 | weight -= 1; | |
1951 | } | |
1952 | break; | |
1953 | case '\\': | |
1954 | un_char = 254; | |
1955 | if (s[1]) { | |
93a17b20 | 1956 | if (strchr("wds]",s[1])) |
79072805 LW |
1957 | weight += 100; |
1958 | else if (seen['\''] || seen['"']) | |
1959 | weight += 1; | |
93a17b20 | 1960 | else if (strchr("rnftbxcav",s[1])) |
79072805 LW |
1961 | weight += 40; |
1962 | else if (isDIGIT(s[1])) { | |
1963 | weight += 40; | |
1964 | while (s[1] && isDIGIT(s[1])) | |
1965 | s++; | |
1966 | } | |
1967 | } | |
1968 | else | |
1969 | weight += 100; | |
1970 | break; | |
1971 | case '-': | |
1972 | if (s[1] == '\\') | |
1973 | weight += 50; | |
93a17b20 | 1974 | if (strchr("aA01! ",last_un_char)) |
79072805 | 1975 | weight += 30; |
93a17b20 | 1976 | if (strchr("zZ79~",s[1])) |
79072805 | 1977 | weight += 30; |
f27ffc4a GS |
1978 | if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$')) |
1979 | weight -= 5; /* cope with negative subscript */ | |
79072805 LW |
1980 | break; |
1981 | default: | |
3792a11b NC |
1982 | if (!isALNUM(last_un_char) |
1983 | && !(last_un_char == '$' || last_un_char == '@' | |
1984 | || last_un_char == '&') | |
1985 | && isALPHA(*s) && s[1] && isALPHA(s[1])) { | |
79072805 LW |
1986 | char *d = tmpbuf; |
1987 | while (isALPHA(*s)) | |
1988 | *d++ = *s++; | |
1989 | *d = '\0'; | |
1990 | if (keyword(tmpbuf, d - tmpbuf)) | |
1991 | weight -= 150; | |
1992 | } | |
1993 | if (un_char == last_un_char + 1) | |
1994 | weight += 5; | |
1995 | weight -= seen[un_char]; | |
1996 | break; | |
1997 | } | |
1998 | seen[un_char]++; | |
1999 | } | |
2000 | if (weight >= 0) /* probably a character class */ | |
2001 | return FALSE; | |
2002 | } | |
2003 | ||
2004 | return TRUE; | |
2005 | } | |
ffed7fef | 2006 | |
ffb4593c NT |
2007 | /* |
2008 | * S_intuit_method | |
2009 | * | |
2010 | * Does all the checking to disambiguate | |
2011 | * foo bar | |
2012 | * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise | |
2013 | * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args). | |
2014 | * | |
2015 | * First argument is the stuff after the first token, e.g. "bar". | |
2016 | * | |
2017 | * Not a method if bar is a filehandle. | |
2018 | * Not a method if foo is a subroutine prototyped to take a filehandle. | |
2019 | * Not a method if it's really "Foo $bar" | |
2020 | * Method if it's "foo $bar" | |
2021 | * Not a method if it's really "print foo $bar" | |
2022 | * Method if it's really "foo package::" (interpreted as package->foo) | |
8f8cf39c | 2023 | * Not a method if bar is known to be a subroutine ("sub bar; foo bar") |
3cb0bbe5 | 2024 | * Not a method if bar is a filehandle or package, but is quoted with |
ffb4593c NT |
2025 | * => |
2026 | */ | |
2027 | ||
76e3520e | 2028 | STATIC int |
cea2e8a9 | 2029 | S_intuit_method(pTHX_ char *start, GV *gv) |
a0d0e21e LW |
2030 | { |
2031 | char *s = start + (*start == '$'); | |
3280af22 | 2032 | char tmpbuf[sizeof PL_tokenbuf]; |
a0d0e21e LW |
2033 | STRLEN len; |
2034 | GV* indirgv; | |
2035 | ||
2036 | if (gv) { | |
b6c543e3 | 2037 | CV *cv; |
a0d0e21e LW |
2038 | if (GvIO(gv)) |
2039 | return 0; | |
b6c543e3 IZ |
2040 | if ((cv = GvCVu(gv))) { |
2041 | char *proto = SvPVX(cv); | |
2042 | if (proto) { | |
2043 | if (*proto == ';') | |
2044 | proto++; | |
2045 | if (*proto == '*') | |
2046 | return 0; | |
2047 | } | |
2048 | } else | |
a0d0e21e LW |
2049 | gv = 0; |
2050 | } | |
8903cb82 | 2051 | s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
ffb4593c NT |
2052 | /* start is the beginning of the possible filehandle/object, |
2053 | * and s is the end of it | |
2054 | * tmpbuf is a copy of it | |
2055 | */ | |
2056 | ||
a0d0e21e | 2057 | if (*start == '$') { |
3280af22 | 2058 | if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf)) |
a0d0e21e LW |
2059 | return 0; |
2060 | s = skipspace(s); | |
3280af22 NIS |
2061 | PL_bufptr = start; |
2062 | PL_expect = XREF; | |
a0d0e21e LW |
2063 | return *s == '(' ? FUNCMETH : METHOD; |
2064 | } | |
2065 | if (!keyword(tmpbuf, len)) { | |
c3e0f903 GS |
2066 | if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') { |
2067 | len -= 2; | |
2068 | tmpbuf[len] = '\0'; | |
2069 | goto bare_package; | |
2070 | } | |
2071 | indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV); | |
8ebc5c01 | 2072 | if (indirgv && GvCVu(indirgv)) |
a0d0e21e LW |
2073 | return 0; |
2074 | /* filehandle or package name makes it a method */ | |
89bfa8cd | 2075 | if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) { |
a0d0e21e | 2076 | s = skipspace(s); |
3280af22 | 2077 | if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>') |
55497cff | 2078 | return 0; /* no assumptions -- "=>" quotes bearword */ |
c3e0f903 | 2079 | bare_package: |
3280af22 | 2080 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, |
79cb57f6 | 2081 | newSVpvn(tmpbuf,len)); |
3280af22 NIS |
2082 | PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE; |
2083 | PL_expect = XTERM; | |
a0d0e21e | 2084 | force_next(WORD); |
3280af22 | 2085 | PL_bufptr = s; |
a0d0e21e LW |
2086 | return *s == '(' ? FUNCMETH : METHOD; |
2087 | } | |
2088 | } | |
2089 | return 0; | |
2090 | } | |
2091 | ||
ffb4593c NT |
2092 | /* |
2093 | * S_incl_perldb | |
2094 | * Return a string of Perl code to load the debugger. If PERL5DB | |
2095 | * is set, it will return the contents of that, otherwise a | |
2096 | * compile-time require of perl5db.pl. | |
2097 | */ | |
2098 | ||
bfed75c6 | 2099 | STATIC const char* |
cea2e8a9 | 2100 | S_incl_perldb(pTHX) |
a0d0e21e | 2101 | { |
3280af22 | 2102 | if (PL_perldb) { |
bfed75c6 | 2103 | const char *pdb = PerlEnv_getenv("PERL5DB"); |
a0d0e21e LW |
2104 | |
2105 | if (pdb) | |
2106 | return pdb; | |
93189314 | 2107 | SETERRNO(0,SS_NORMAL); |
a0d0e21e LW |
2108 | return "BEGIN { require 'perl5db.pl' }"; |
2109 | } | |
2110 | return ""; | |
2111 | } | |
2112 | ||
2113 | ||
16d20bd9 | 2114 | /* Encoded script support. filter_add() effectively inserts a |
4e553d73 | 2115 | * 'pre-processing' function into the current source input stream. |
16d20bd9 AD |
2116 | * Note that the filter function only applies to the current source file |
2117 | * (e.g., it will not affect files 'require'd or 'use'd by this one). | |
2118 | * | |
2119 | * The datasv parameter (which may be NULL) can be used to pass | |
2120 | * private data to this instance of the filter. The filter function | |
2121 | * can recover the SV using the FILTER_DATA macro and use it to | |
2122 | * store private buffers and state information. | |
2123 | * | |
2124 | * The supplied datasv parameter is upgraded to a PVIO type | |
4755096e | 2125 | * and the IoDIRP/IoANY field is used to store the function pointer, |
e0c19803 | 2126 | * and IOf_FAKE_DIRP is enabled on datasv to mark this as such. |
16d20bd9 AD |
2127 | * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for |
2128 | * private use must be set using malloc'd pointers. | |
2129 | */ | |
16d20bd9 AD |
2130 | |
2131 | SV * | |
864dbfa3 | 2132 | Perl_filter_add(pTHX_ filter_t funcp, SV *datasv) |
16d20bd9 | 2133 | { |
f4c556ac GS |
2134 | if (!funcp) |
2135 | return Nullsv; | |
2136 | ||
3280af22 NIS |
2137 | if (!PL_rsfp_filters) |
2138 | PL_rsfp_filters = newAV(); | |
16d20bd9 | 2139 | if (!datasv) |
8c52afec | 2140 | datasv = NEWSV(255,0); |
16d20bd9 | 2141 | if (!SvUPGRADE(datasv, SVt_PVIO)) |
cea2e8a9 | 2142 | Perl_die(aTHX_ "Can't upgrade filter_add data to SVt_PVIO"); |
4755096e | 2143 | IoANY(datasv) = (void *)funcp; /* stash funcp into spare field */ |
e0c19803 | 2144 | IoFLAGS(datasv) |= IOf_FAKE_DIRP; |
f4c556ac | 2145 | DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n", |
fe5a182c | 2146 | (void*)funcp, SvPV_nolen(datasv))); |
3280af22 NIS |
2147 | av_unshift(PL_rsfp_filters, 1); |
2148 | av_store(PL_rsfp_filters, 0, datasv) ; | |
16d20bd9 AD |
2149 | return(datasv); |
2150 | } | |
4e553d73 | 2151 | |
16d20bd9 AD |
2152 | |
2153 | /* Delete most recently added instance of this filter function. */ | |
a0d0e21e | 2154 | void |
864dbfa3 | 2155 | Perl_filter_del(pTHX_ filter_t funcp) |
16d20bd9 | 2156 | { |
e0c19803 | 2157 | SV *datasv; |
fe5a182c | 2158 | DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", (void*)funcp)); |
3280af22 | 2159 | if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0) |
16d20bd9 AD |
2160 | return; |
2161 | /* if filter is on top of stack (usual case) just pop it off */ | |
e0c19803 | 2162 | datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters)); |
4755096e | 2163 | if (IoANY(datasv) == (void *)funcp) { |
e0c19803 | 2164 | IoFLAGS(datasv) &= ~IOf_FAKE_DIRP; |
4755096e | 2165 | IoANY(datasv) = (void *)NULL; |
3280af22 | 2166 | sv_free(av_pop(PL_rsfp_filters)); |
e50aee73 | 2167 | |
16d20bd9 AD |
2168 | return; |
2169 | } | |
2170 | /* we need to search for the correct entry and clear it */ | |
cea2e8a9 | 2171 | Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)"); |
16d20bd9 AD |
2172 | } |
2173 | ||
2174 | ||
1de9afcd RGS |
2175 | /* Invoke the idxth filter function for the current rsfp. */ |
2176 | /* maxlen 0 = read one text line */ | |
16d20bd9 | 2177 | I32 |
864dbfa3 | 2178 | Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen) |
a0d0e21e | 2179 | { |
16d20bd9 AD |
2180 | filter_t funcp; |
2181 | SV *datasv = NULL; | |
e50aee73 | 2182 | |
3280af22 | 2183 | if (!PL_rsfp_filters) |
16d20bd9 | 2184 | return -1; |
1de9afcd | 2185 | if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */ |
16d20bd9 AD |
2186 | /* Provide a default input filter to make life easy. */ |
2187 | /* Note that we append to the line. This is handy. */ | |
f4c556ac GS |
2188 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2189 | "filter_read %d: from rsfp\n", idx)); | |
4e553d73 | 2190 | if (maxlen) { |
16d20bd9 AD |
2191 | /* Want a block */ |
2192 | int len ; | |
2193 | int old_len = SvCUR(buf_sv) ; | |
2194 | ||
2195 | /* ensure buf_sv is large enough */ | |
eb160463 | 2196 | SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ; |
3280af22 NIS |
2197 | if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){ |
2198 | if (PerlIO_error(PL_rsfp)) | |
37120919 AD |
2199 | return -1; /* error */ |
2200 | else | |
2201 | return 0 ; /* end of file */ | |
2202 | } | |
16d20bd9 AD |
2203 | SvCUR_set(buf_sv, old_len + len) ; |
2204 | } else { | |
2205 | /* Want a line */ | |
3280af22 NIS |
2206 | if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) { |
2207 | if (PerlIO_error(PL_rsfp)) | |
37120919 AD |
2208 | return -1; /* error */ |
2209 | else | |
2210 | return 0 ; /* end of file */ | |
2211 | } | |
16d20bd9 AD |
2212 | } |
2213 | return SvCUR(buf_sv); | |
2214 | } | |
2215 | /* Skip this filter slot if filter has been deleted */ | |
1de9afcd | 2216 | if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) { |
f4c556ac GS |
2217 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2218 | "filter_read %d: skipped (filter deleted)\n", | |
2219 | idx)); | |
16d20bd9 AD |
2220 | return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */ |
2221 | } | |
2222 | /* Get function pointer hidden within datasv */ | |
4755096e | 2223 | funcp = (filter_t)IoANY(datasv); |
f4c556ac GS |
2224 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2225 | "filter_read %d: via function %p (%s)\n", | |
fe5a182c | 2226 | idx, (void*)funcp, SvPV_nolen(datasv))); |
16d20bd9 AD |
2227 | /* Call function. The function is expected to */ |
2228 | /* call "FILTER_READ(idx+1, buf_sv)" first. */ | |
37120919 | 2229 | /* Return: <0:error, =0:eof, >0:not eof */ |
acfe0abc | 2230 | return (*funcp)(aTHX_ idx, buf_sv, maxlen); |
16d20bd9 AD |
2231 | } |
2232 | ||
76e3520e | 2233 | STATIC char * |
cea2e8a9 | 2234 | S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append) |
16d20bd9 | 2235 | { |
c39cd008 | 2236 | #ifdef PERL_CR_FILTER |
3280af22 | 2237 | if (!PL_rsfp_filters) { |
c39cd008 | 2238 | filter_add(S_cr_textfilter,NULL); |
a868473f NIS |
2239 | } |
2240 | #endif | |
3280af22 | 2241 | if (PL_rsfp_filters) { |
55497cff | 2242 | if (!append) |
2243 | SvCUR_set(sv, 0); /* start with empty line */ | |
16d20bd9 AD |
2244 | if (FILTER_READ(0, sv, 0) > 0) |
2245 | return ( SvPVX(sv) ) ; | |
2246 | else | |
2247 | return Nullch ; | |
2248 | } | |
9d116dd7 | 2249 | else |
fd049845 | 2250 | return (sv_gets(sv, fp, append)); |
a0d0e21e LW |
2251 | } |
2252 | ||
01ec43d0 | 2253 | STATIC HV * |
7fc63493 | 2254 | S_find_in_my_stash(pTHX_ const char *pkgname, I32 len) |
def3634b GS |
2255 | { |
2256 | GV *gv; | |
2257 | ||
01ec43d0 | 2258 | if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__")) |
def3634b GS |
2259 | return PL_curstash; |
2260 | ||
2261 | if (len > 2 && | |
2262 | (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') && | |
01ec43d0 GS |
2263 | (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV))) |
2264 | { | |
2265 | return GvHV(gv); /* Foo:: */ | |
def3634b GS |
2266 | } |
2267 | ||
2268 | /* use constant CLASS => 'MyClass' */ | |
2269 | if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) { | |
2270 | SV *sv; | |
2271 | if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) { | |
2272 | pkgname = SvPV_nolen(sv); | |
2273 | } | |
2274 | } | |
2275 | ||
2276 | return gv_stashpv(pkgname, FALSE); | |
2277 | } | |
a0d0e21e | 2278 | |
748a9306 | 2279 | #ifdef DEBUGGING |
27da23d5 | 2280 | static const char* const exp_name[] = |
09bef843 | 2281 | { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK", |
27308ded | 2282 | "ATTRTERM", "TERMBLOCK", "TERMORDORDOR" |
09bef843 | 2283 | }; |
748a9306 | 2284 | #endif |
463ee0b2 | 2285 | |
02aa26ce NT |
2286 | /* |
2287 | yylex | |
2288 | ||
2289 | Works out what to call the token just pulled out of the input | |
2290 | stream. The yacc parser takes care of taking the ops we return and | |
2291 | stitching them into a tree. | |
2292 | ||
2293 | Returns: | |
2294 | PRIVATEREF | |
2295 | ||
2296 | Structure: | |
2297 | if read an identifier | |
2298 | if we're in a my declaration | |
2299 | croak if they tried to say my($foo::bar) | |
2300 | build the ops for a my() declaration | |
2301 | if it's an access to a my() variable | |
2302 | are we in a sort block? | |
2303 | croak if my($a); $a <=> $b | |
2304 | build ops for access to a my() variable | |
2305 | if in a dq string, and they've said @foo and we can't find @foo | |
2306 | croak | |
2307 | build ops for a bareword | |
2308 | if we already built the token before, use it. | |
2309 | */ | |
2310 | ||
20141f0e | 2311 | |
dba4d153 JH |
2312 | #ifdef __SC__ |
2313 | #pragma segment Perl_yylex | |
2314 | #endif | |
dba4d153 | 2315 | int |
dba4d153 | 2316 | Perl_yylex(pTHX) |
20141f0e | 2317 | { |
3afc138a | 2318 | register char *s = PL_bufptr; |
378cc40b | 2319 | register char *d; |
79072805 | 2320 | register I32 tmp; |
463ee0b2 | 2321 | STRLEN len; |
161b471a NIS |
2322 | GV *gv = Nullgv; |
2323 | GV **gvp = 0; | |
aa7440fb | 2324 | bool bof = FALSE; |
1d239bbb | 2325 | I32 orig_keyword = 0; |
a687059c | 2326 | |
bbf60fe6 DM |
2327 | DEBUG_T( { |
2328 | PerlIO_printf(Perl_debug_log, "### LEX_%s\n", | |
2329 | lex_state_names[PL_lex_state]); | |
2330 | } ); | |
02aa26ce | 2331 | /* check if there's an identifier for us to look at */ |
ba979b31 | 2332 | if (PL_pending_ident) |
bbf60fe6 | 2333 | return REPORT(S_pending_ident(aTHX)); |
bbce6d69 | 2334 | |
02aa26ce NT |
2335 | /* no identifier pending identification */ |
2336 | ||
3280af22 | 2337 | switch (PL_lex_state) { |
79072805 LW |
2338 | #ifdef COMMENTARY |
2339 | case LEX_NORMAL: /* Some compilers will produce faster */ | |
2340 | case LEX_INTERPNORMAL: /* code if we comment these out. */ | |
2341 | break; | |
2342 | #endif | |
2343 | ||
09bef843 | 2344 | /* when we've already built the next token, just pull it out of the queue */ |
79072805 | 2345 | case LEX_KNOWNEXT: |
3280af22 NIS |
2346 | PL_nexttoke--; |
2347 | yylval = PL_nextval[PL_nexttoke]; | |
2348 | if (!PL_nexttoke) { | |
2349 | PL_lex_state = PL_lex_defer; | |
2350 | PL_expect = PL_lex_expect; | |
2351 | PL_lex_defer = LEX_NORMAL; | |
463ee0b2 | 2352 | } |
607df283 | 2353 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
4659c93f | 2354 | "### Next token after '%s' was known, type %"IVdf"\n", PL_bufptr, |
5f80b19c | 2355 | (IV)PL_nexttype[PL_nexttoke]); }); |
607df283 | 2356 | |
bbf60fe6 | 2357 | return REPORT(PL_nexttype[PL_nexttoke]); |
79072805 | 2358 | |
02aa26ce | 2359 | /* interpolated case modifiers like \L \U, including \Q and \E. |
3280af22 | 2360 | when we get here, PL_bufptr is at the \ |
02aa26ce | 2361 | */ |
79072805 LW |
2362 | case LEX_INTERPCASEMOD: |
2363 | #ifdef DEBUGGING | |
3280af22 | 2364 | if (PL_bufptr != PL_bufend && *PL_bufptr != '\\') |
cea2e8a9 | 2365 | Perl_croak(aTHX_ "panic: INTERPCASEMOD"); |
79072805 | 2366 | #endif |
02aa26ce | 2367 | /* handle \E or end of string */ |
3280af22 | 2368 | if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') { |
a0d0e21e | 2369 | char oldmod; |
02aa26ce NT |
2370 | |
2371 | /* if at a \E */ | |
3280af22 NIS |
2372 | if (PL_lex_casemods) { |
2373 | oldmod = PL_lex_casestack[--PL_lex_casemods]; | |
2374 | PL_lex_casestack[PL_lex_casemods] = '\0'; | |
02aa26ce | 2375 | |
3792a11b NC |
2376 | if (PL_bufptr != PL_bufend |
2377 | && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) { | |
3280af22 NIS |
2378 | PL_bufptr += 2; |
2379 | PL_lex_state = LEX_INTERPCONCAT; | |
a0d0e21e | 2380 | } |
bbf60fe6 | 2381 | return REPORT(')'); |
79072805 | 2382 | } |
3280af22 NIS |
2383 | if (PL_bufptr != PL_bufend) |
2384 | PL_bufptr += 2; | |
2385 | PL_lex_state = LEX_INTERPCONCAT; | |
cea2e8a9 | 2386 | return yylex(); |
79072805 LW |
2387 | } |
2388 | else { | |
607df283 | 2389 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
5f80b19c | 2390 | "### Saw case modifier at '%s'\n", PL_bufptr); }); |
3280af22 | 2391 | s = PL_bufptr + 1; |
6e909404 JH |
2392 | if (s[1] == '\\' && s[2] == 'E') { |
2393 | PL_bufptr = s + 3; | |
2394 | PL_lex_state = LEX_INTERPCONCAT; | |
2395 | return yylex(); | |
a0d0e21e | 2396 | } |
6e909404 JH |
2397 | else { |
2398 | if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3)) | |
2399 | tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */ | |
3792a11b | 2400 | if ((*s == 'L' || *s == 'U') && |
6e909404 JH |
2401 | (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) { |
2402 | PL_lex_casestack[--PL_lex_casemods] = '\0'; | |
bbf60fe6 | 2403 | return REPORT(')'); |
6e909404 JH |
2404 | } |
2405 | if (PL_lex_casemods > 10) | |
2406 | Renew(PL_lex_casestack, PL_lex_casemods + 2, char); | |
2407 | PL_lex_casestack[PL_lex_casemods++] = *s; | |
2408 | PL_lex_casestack[PL_lex_casemods] = '\0'; | |
2409 | PL_lex_state = LEX_INTERPCONCAT; | |
2410 | PL_nextval[PL_nexttoke].ival = 0; | |
2411 | force_next('('); | |
2412 | if (*s == 'l') | |
2413 | PL_nextval[PL_nexttoke].ival = OP_LCFIRST; | |
2414 | else if (*s == 'u') | |
2415 | PL_nextval[PL_nexttoke].ival = OP_UCFIRST; | |
2416 | else if (*s == 'L') | |
2417 | PL_nextval[PL_nexttoke].ival = OP_LC; | |
2418 | else if (*s == 'U') | |
2419 | PL_nextval[PL_nexttoke].ival = OP_UC; | |
2420 | else if (*s == 'Q') | |
2421 | PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA; | |
2422 | else | |
2423 | Perl_croak(aTHX_ "panic: yylex"); | |
2424 | PL_bufptr = s + 1; | |
a0d0e21e | 2425 | } |
79072805 | 2426 | force_next(FUNC); |
3280af22 NIS |
2427 | if (PL_lex_starts) { |
2428 | s = PL_bufptr; | |
2429 | PL_lex_starts = 0; | |
131b3ad0 DM |
2430 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ |
2431 | if (PL_lex_casemods == 1 && PL_lex_inpat) | |
2432 | OPERATOR(','); | |
2433 | else | |
2434 | Aop(OP_CONCAT); | |
79072805 LW |
2435 | } |
2436 | else | |
cea2e8a9 | 2437 | return yylex(); |
79072805 LW |
2438 | } |
2439 | ||
55497cff | 2440 | case LEX_INTERPPUSH: |
bbf60fe6 | 2441 | return REPORT(sublex_push()); |
55497cff | 2442 | |
79072805 | 2443 | case LEX_INTERPSTART: |
3280af22 | 2444 | if (PL_bufptr == PL_bufend) |
bbf60fe6 | 2445 | return REPORT(sublex_done()); |
607df283 | 2446 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
5f80b19c | 2447 | "### Interpolated variable at '%s'\n", PL_bufptr); }); |
3280af22 NIS |
2448 | PL_expect = XTERM; |
2449 | PL_lex_dojoin = (*PL_bufptr == '@'); | |
2450 | PL_lex_state = LEX_INTERPNORMAL; | |
2451 | if (PL_lex_dojoin) { | |
2452 | PL_nextval[PL_nexttoke].ival = 0; | |
79072805 | 2453 | force_next(','); |
a0d0e21e | 2454 | force_ident("\"", '$'); |
3280af22 | 2455 | PL_nextval[PL_nexttoke].ival = 0; |
79072805 | 2456 | force_next('$'); |
3280af22 | 2457 | PL_nextval[PL_nexttoke].ival = 0; |
79072805 | 2458 | force_next('('); |
3280af22 | 2459 | PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */ |
79072805 LW |
2460 | force_next(FUNC); |
2461 | } | |
3280af22 NIS |
2462 | if (PL_lex_starts++) { |
2463 | s = PL_bufptr; | |
131b3ad0 DM |
2464 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ |
2465 | if (!PL_lex_casemods && PL_lex_inpat) | |
2466 | OPERATOR(','); | |
2467 | else | |
2468 | Aop(OP_CONCAT); | |
79072805 | 2469 | } |
cea2e8a9 | 2470 | return yylex(); |
79072805 LW |
2471 | |
2472 | case LEX_INTERPENDMAYBE: | |
3280af22 NIS |
2473 | if (intuit_more(PL_bufptr)) { |
2474 | PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */ | |
79072805 LW |
2475 | break; |
2476 | } | |
2477 | /* FALL THROUGH */ | |
2478 | ||
2479 | case LEX_INTERPEND: | |
3280af22 NIS |
2480 | if (PL_lex_dojoin) { |
2481 | PL_lex_dojoin = FALSE; | |
2482 | PL_lex_state = LEX_INTERPCONCAT; | |
bbf60fe6 | 2483 | return REPORT(')'); |
79072805 | 2484 | } |
43a16006 | 2485 | if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl |
25da4f38 | 2486 | && SvEVALED(PL_lex_repl)) |
43a16006 | 2487 | { |
e9fa98b2 | 2488 | if (PL_bufptr != PL_bufend) |
cea2e8a9 | 2489 | Perl_croak(aTHX_ "Bad evalled substitution pattern"); |
e9fa98b2 HS |
2490 | PL_lex_repl = Nullsv; |
2491 | } | |
79072805 LW |
2492 | /* FALLTHROUGH */ |
2493 | case LEX_INTERPCONCAT: | |
2494 | #ifdef DEBUGGING | |
3280af22 | 2495 | if (PL_lex_brackets) |
cea2e8a9 | 2496 | Perl_croak(aTHX_ "panic: INTERPCONCAT"); |
79072805 | 2497 | #endif |
3280af22 | 2498 | if (PL_bufptr == PL_bufend) |
bbf60fe6 | 2499 | return REPORT(sublex_done()); |
79072805 | 2500 | |
3280af22 NIS |
2501 | if (SvIVX(PL_linestr) == '\'') { |
2502 | SV *sv = newSVsv(PL_linestr); | |
2503 | if (!PL_lex_inpat) | |
76e3520e | 2504 | sv = tokeq(sv); |
3280af22 | 2505 | else if ( PL_hints & HINT_NEW_RE ) |
b3ac6de7 | 2506 | sv = new_constant(NULL, 0, "qr", sv, sv, "q"); |
79072805 | 2507 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
3280af22 | 2508 | s = PL_bufend; |
79072805 LW |
2509 | } |
2510 | else { | |
3280af22 | 2511 | s = scan_const(PL_bufptr); |
79072805 | 2512 | if (*s == '\\') |
3280af22 | 2513 | PL_lex_state = LEX_INTERPCASEMOD; |
79072805 | 2514 | else |
3280af22 | 2515 | PL_lex_state = LEX_INTERPSTART; |
79072805 LW |
2516 | } |
2517 | ||
3280af22 NIS |
2518 | if (s != PL_bufptr) { |
2519 | PL_nextval[PL_nexttoke] = yylval; | |
2520 | PL_expect = XTERM; | |
79072805 | 2521 | force_next(THING); |
131b3ad0 DM |
2522 | if (PL_lex_starts++) { |
2523 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ | |
2524 | if (!PL_lex_casemods && PL_lex_inpat) | |
2525 | OPERATOR(','); | |
2526 | else | |
2527 | Aop(OP_CONCAT); | |
2528 | } | |
79072805 | 2529 | else { |
3280af22 | 2530 | PL_bufptr = s; |
cea2e8a9 | 2531 | return yylex(); |
79072805 LW |
2532 | } |
2533 | } | |
2534 | ||
cea2e8a9 | 2535 | return yylex(); |
a0d0e21e | 2536 | case LEX_FORMLINE: |
3280af22 NIS |
2537 | PL_lex_state = LEX_NORMAL; |
2538 | s = scan_formline(PL_bufptr); | |
2539 | if (!PL_lex_formbrack) | |
a0d0e21e LW |
2540 | goto rightbracket; |
2541 | OPERATOR(';'); | |
79072805 LW |
2542 | } |
2543 | ||
3280af22 NIS |
2544 | s = PL_bufptr; |
2545 | PL_oldoldbufptr = PL_oldbufptr; | |
2546 | PL_oldbufptr = s; | |
607df283 | 2547 | DEBUG_T( { |
bbf60fe6 | 2548 | PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at [%s]\n", |
bf49b057 | 2549 | exp_name[PL_expect], s); |
5f80b19c | 2550 | } ); |
463ee0b2 LW |
2551 | |
2552 | retry: | |
378cc40b LW |
2553 | switch (*s) { |
2554 | default: | |
7e2040f0 | 2555 | if (isIDFIRST_lazy_if(s,UTF)) |
834a4ddd | 2556 | goto keylookup; |
cea2e8a9 | 2557 | Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255); |
e929a76b LW |
2558 | case 4: |
2559 | case 26: | |
2560 | goto fake_eof; /* emulate EOF on ^D or ^Z */ | |
378cc40b | 2561 | case 0: |
3280af22 NIS |
2562 | if (!PL_rsfp) { |
2563 | PL_last_uni = 0; | |
2564 | PL_last_lop = 0; | |
c5ee2135 WL |
2565 | if (PL_lex_brackets) { |
2566 | if (PL_lex_formbrack) | |
2567 | yyerror("Format not terminated"); | |
2568 | else | |
2569 | yyerror("Missing right curly or square bracket"); | |
2570 | } | |
4e553d73 | 2571 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
607df283 | 2572 | "### Tokener got EOF\n"); |
5f80b19c | 2573 | } ); |
79072805 | 2574 | TOKEN(0); |
463ee0b2 | 2575 | } |
3280af22 | 2576 | if (s++ < PL_bufend) |
a687059c | 2577 | goto retry; /* ignore stray nulls */ |
3280af22 NIS |
2578 | PL_last_uni = 0; |
2579 | PL_last_lop = 0; | |
2580 | if (!PL_in_eval && !PL_preambled) { | |
2581 | PL_preambled = TRUE; | |
2582 | sv_setpv(PL_linestr,incl_perldb()); | |
2583 | if (SvCUR(PL_linestr)) | |
4147a61b | 2584 | sv_catpvn(PL_linestr,";", 1); |
3280af22 NIS |
2585 | if (PL_preambleav){ |
2586 | while(AvFILLp(PL_preambleav) >= 0) { | |
2587 | SV *tmpsv = av_shift(PL_preambleav); | |
2588 | sv_catsv(PL_linestr, tmpsv); | |
4147a61b | 2589 | sv_catpvn(PL_linestr, ";", 1); |
91b7def8 | 2590 | sv_free(tmpsv); |
2591 | } | |
3280af22 NIS |
2592 | sv_free((SV*)PL_preambleav); |
2593 | PL_preambleav = NULL; | |
91b7def8 | 2594 | } |
3280af22 NIS |
2595 | if (PL_minus_n || PL_minus_p) { |
2596 | sv_catpv(PL_linestr, "LINE: while (<>) {"); | |
2597 | if (PL_minus_l) | |
2598 | sv_catpv(PL_linestr,"chomp;"); | |
2599 | if (PL_minus_a) { | |
3280af22 | 2600 | if (PL_minus_F) { |
3792a11b NC |
2601 | if ((*PL_splitstr == '/' || *PL_splitstr == '\'' |
2602 | || *PL_splitstr == '"') | |
3280af22 | 2603 | && strchr(PL_splitstr + 1, *PL_splitstr)) |
3db68c4c | 2604 | Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr); |
54310121 | 2605 | else { |
c8ef6a4b NC |
2606 | /* "q\0${splitstr}\0" is legal perl. Yes, even NUL |
2607 | bytes can be used as quoting characters. :-) */ | |
48c4c863 NC |
2608 | /* The count here deliberately includes the NUL |
2609 | that terminates the C string constant. This | |
2610 | embeds the opening NUL into the string. */ | |
dd374669 | 2611 | const char *splits = PL_splitstr; |
9a3fb652 | 2612 | sv_catpvn(PL_linestr, "our @F=split(q", 15); |
48c4c863 NC |
2613 | do { |
2614 | /* Need to \ \s */ | |
dd374669 AL |
2615 | if (*splits == '\\') |
2616 | sv_catpvn(PL_linestr, splits, 1); | |
2617 | sv_catpvn(PL_linestr, splits, 1); | |
2618 | } while (*splits++); | |
48c4c863 NC |
2619 | /* This loop will embed the trailing NUL of |
2620 | PL_linestr as the last thing it does before | |
2621 | terminating. */ | |
4fccd7c6 | 2622 | sv_catpvn(PL_linestr, ");", 2); |
54310121 | 2623 | } |
2304df62 AD |
2624 | } |
2625 | else | |
75c72d73 | 2626 | sv_catpv(PL_linestr,"our @F=split(' ');"); |
2304df62 | 2627 | } |
79072805 | 2628 | } |
4147a61b | 2629 | sv_catpvn(PL_linestr, "\n", 1); |
3280af22 NIS |
2630 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
2631 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2632 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 2633 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
a0d0e21e LW |
2634 | SV *sv = NEWSV(85,0); |
2635 | ||
2636 | sv_upgrade(sv, SVt_PVMG); | |
3280af22 | 2637 | sv_setsv(sv,PL_linestr); |
0ac0412a | 2638 | (void)SvIOK_on(sv); |
45977657 | 2639 | SvIV_set(sv, 0); |
57843af0 | 2640 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
a0d0e21e | 2641 | } |
79072805 | 2642 | goto retry; |
a687059c | 2643 | } |
e929a76b | 2644 | do { |
aa7440fb | 2645 | bof = PL_rsfp ? TRUE : FALSE; |
7e28d3af JH |
2646 | if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) { |
2647 | fake_eof: | |
2648 | if (PL_rsfp) { | |
2649 | if (PL_preprocess && !PL_in_eval) | |
2650 | (void)PerlProc_pclose(PL_rsfp); | |
2651 | else if ((PerlIO *)PL_rsfp == PerlIO_stdin()) | |
2652 | PerlIO_clearerr(PL_rsfp); | |
2653 | else | |
2654 | (void)PerlIO_close(PL_rsfp); | |
2655 | PL_rsfp = Nullfp; | |
2656 | PL_doextract = FALSE; | |
2657 | } | |
2658 | if (!PL_in_eval && (PL_minus_n || PL_minus_p)) { | |
a23c4656 NC |
2659 | sv_setpv(PL_linestr,PL_minus_p |
2660 | ? ";}continue{print;}" : ";}"); | |
7e28d3af JH |
2661 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
2662 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2663 | PL_last_lop = PL_last_uni = Nullch; |
7e28d3af JH |
2664 | PL_minus_n = PL_minus_p = 0; |
2665 | goto retry; | |
2666 | } | |
2667 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); | |
207e3d1a | 2668 | PL_last_lop = PL_last_uni = Nullch; |
7e28d3af JH |
2669 | sv_setpv(PL_linestr,""); |
2670 | TOKEN(';'); /* not infinite loop because rsfp is NULL now */ | |
2671 | } | |
7aa207d6 JH |
2672 | /* If it looks like the start of a BOM or raw UTF-16, |
2673 | * check if it in fact is. */ | |
2674 | else if (bof && | |
2675 | (*s == 0 || | |
2676 | *(U8*)s == 0xEF || | |
2677 | *(U8*)s >= 0xFE || | |
2678 | s[1] == 0)) { | |
226017aa | 2679 | #ifdef PERLIO_IS_STDIO |
e3f494f1 JH |
2680 | # ifdef __GNU_LIBRARY__ |
2681 | # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */ | |
226017aa DD |
2682 | # define FTELL_FOR_PIPE_IS_BROKEN |
2683 | # endif | |
e3f494f1 JH |
2684 | # else |
2685 | # ifdef __GLIBC__ | |
2686 | # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */ | |
2687 | # define FTELL_FOR_PIPE_IS_BROKEN | |
2688 | # endif | |
2689 | # endif | |
226017aa DD |
2690 | # endif |
2691 | #endif | |
2692 | #ifdef FTELL_FOR_PIPE_IS_BROKEN | |
2693 | /* This loses the possibility to detect the bof | |
2694 | * situation on perl -P when the libc5 is being used. | |
2695 | * Workaround? Maybe attach some extra state to PL_rsfp? | |
2696 | */ | |
2697 | if (!PL_preprocess) | |
7e28d3af | 2698 | bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr); |
226017aa | 2699 | #else |
eb160463 | 2700 | bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr); |
226017aa | 2701 | #endif |
7e28d3af | 2702 | if (bof) { |
3280af22 | 2703 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
7e28d3af | 2704 | s = swallow_bom((U8*)s); |
e929a76b | 2705 | } |
378cc40b | 2706 | } |
3280af22 | 2707 | if (PL_doextract) { |
a0d0e21e LW |
2708 | /* Incest with pod. */ |
2709 | if (*s == '=' && strnEQ(s, "=cut", 4)) { | |
3280af22 NIS |
2710 | sv_setpv(PL_linestr, ""); |
2711 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); | |
2712 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2713 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 2714 | PL_doextract = FALSE; |
a0d0e21e | 2715 | } |
4e553d73 | 2716 | } |
463ee0b2 | 2717 | incline(s); |
3280af22 NIS |
2718 | } while (PL_doextract); |
2719 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s; | |
2720 | if (PERLDB_LINE && PL_curstash != PL_debstash) { | |
79072805 | 2721 | SV *sv = NEWSV(85,0); |
a687059c | 2722 | |
93a17b20 | 2723 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 2724 | sv_setsv(sv,PL_linestr); |
0ac0412a | 2725 | (void)SvIOK_on(sv); |
45977657 | 2726 | SvIV_set(sv, 0); |
57843af0 | 2727 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
a687059c | 2728 | } |
3280af22 | 2729 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 2730 | PL_last_lop = PL_last_uni = Nullch; |
57843af0 | 2731 | if (CopLINE(PL_curcop) == 1) { |
3280af22 | 2732 | while (s < PL_bufend && isSPACE(*s)) |
79072805 | 2733 | s++; |
a0d0e21e | 2734 | if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */ |
79072805 | 2735 | s++; |
44a8e56a | 2736 | d = Nullch; |
3280af22 | 2737 | if (!PL_in_eval) { |
44a8e56a | 2738 | if (*s == '#' && *(s+1) == '!') |
2739 | d = s + 2; | |
2740 | #ifdef ALTERNATE_SHEBANG | |
2741 | else { | |
bfed75c6 | 2742 | static char const as[] = ALTERNATE_SHEBANG; |
44a8e56a | 2743 | if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1)) |
2744 | d = s + (sizeof(as) - 1); | |
2745 | } | |
2746 | #endif /* ALTERNATE_SHEBANG */ | |
2747 | } | |
2748 | if (d) { | |
b8378b72 | 2749 | char *ipath; |
774d564b | 2750 | char *ipathend; |
b8378b72 | 2751 | |
774d564b | 2752 | while (isSPACE(*d)) |
b8378b72 CS |
2753 | d++; |
2754 | ipath = d; | |
774d564b | 2755 | while (*d && !isSPACE(*d)) |
2756 | d++; | |
2757 | ipathend = d; | |
2758 | ||
2759 | #ifdef ARG_ZERO_IS_SCRIPT | |
2760 | if (ipathend > ipath) { | |
2761 | /* | |
2762 | * HP-UX (at least) sets argv[0] to the script name, | |
2763 | * which makes $^X incorrect. And Digital UNIX and Linux, | |
2764 | * at least, set argv[0] to the basename of the Perl | |
2765 | * interpreter. So, having found "#!", we'll set it right. | |
2766 | */ | |
ee2f7564 | 2767 | SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV)); /* $^X */ |
774d564b | 2768 | assert(SvPOK(x) || SvGMAGICAL(x)); |
cc49e20b | 2769 | if (sv_eq(x, CopFILESV(PL_curcop))) { |
774d564b | 2770 | sv_setpvn(x, ipath, ipathend - ipath); |
9607fc9c | 2771 | SvSETMAGIC(x); |
2772 | } | |
556c1dec JH |
2773 | else { |
2774 | STRLEN blen; | |
2775 | STRLEN llen; | |
2776 | char *bstart = SvPV(CopFILESV(PL_curcop),blen); | |
2777 | char *lstart = SvPV(x,llen); | |
2778 | if (llen < blen) { | |
2779 | bstart += blen - llen; | |
2780 | if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') { | |
2781 | sv_setpvn(x, ipath, ipathend - ipath); | |
2782 | SvSETMAGIC(x); | |
2783 | } | |
2784 | } | |
2785 | } | |
774d564b | 2786 | TAINT_NOT; /* $^X is always tainted, but that's OK */ |
8ebc5c01 | 2787 | } |
774d564b | 2788 | #endif /* ARG_ZERO_IS_SCRIPT */ |
b8378b72 CS |
2789 | |
2790 | /* | |
2791 | * Look for options. | |
2792 | */ | |
748a9306 | 2793 | d = instr(s,"perl -"); |
84e30d1a | 2794 | if (!d) { |
748a9306 | 2795 | d = instr(s,"perl"); |
84e30d1a GS |
2796 | #if defined(DOSISH) |
2797 | /* avoid getting into infinite loops when shebang | |
2798 | * line contains "Perl" rather than "perl" */ | |
2799 | if (!d) { | |
2800 | for (d = ipathend-4; d >= ipath; --d) { | |
2801 | if ((*d == 'p' || *d == 'P') | |
2802 | && !ibcmp(d, "perl", 4)) | |
2803 | { | |
2804 | break; | |
2805 | } | |
2806 | } | |
2807 | if (d < ipath) | |
2808 | d = Nullch; | |
2809 | } | |
2810 | #endif | |
2811 | } | |
44a8e56a | 2812 | #ifdef ALTERNATE_SHEBANG |
2813 | /* | |
2814 | * If the ALTERNATE_SHEBANG on this system starts with a | |
2815 | * character that can be part of a Perl expression, then if | |
2816 | * we see it but not "perl", we're probably looking at the | |
2817 | * start of Perl code, not a request to hand off to some | |
2818 | * other interpreter. Similarly, if "perl" is there, but | |
2819 | * not in the first 'word' of the line, we assume the line | |
2820 | * contains the start of the Perl program. | |
44a8e56a | 2821 | */ |
2822 | if (d && *s != '#') { | |
774d564b | 2823 | char *c = ipath; |
44a8e56a | 2824 | while (*c && !strchr("; \t\r\n\f\v#", *c)) |
2825 | c++; | |
2826 | if (c < d) | |
2827 | d = Nullch; /* "perl" not in first word; ignore */ | |
2828 | else | |
2829 | *s = '#'; /* Don't try to parse shebang line */ | |
2830 | } | |
774d564b | 2831 | #endif /* ALTERNATE_SHEBANG */ |
bf4acbe4 | 2832 | #ifndef MACOS_TRADITIONAL |
748a9306 | 2833 | if (!d && |
44a8e56a | 2834 | *s == '#' && |
774d564b | 2835 | ipathend > ipath && |
3280af22 | 2836 | !PL_minus_c && |
748a9306 | 2837 | !instr(s,"indir") && |
3280af22 | 2838 | instr(PL_origargv[0],"perl")) |
748a9306 | 2839 | { |
27da23d5 | 2840 | dVAR; |
9f68db38 | 2841 | char **newargv; |
9f68db38 | 2842 | |
774d564b | 2843 | *ipathend = '\0'; |
2844 | s = ipathend + 1; | |
3280af22 | 2845 | while (s < PL_bufend && isSPACE(*s)) |
9f68db38 | 2846 | s++; |
3280af22 NIS |
2847 | if (s < PL_bufend) { |
2848 | Newz(899,newargv,PL_origargc+3,char*); | |
9f68db38 | 2849 | newargv[1] = s; |
3280af22 | 2850 | while (s < PL_bufend && !isSPACE(*s)) |
9f68db38 LW |
2851 | s++; |
2852 | *s = '\0'; | |
3280af22 | 2853 | Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*); |
9f68db38 LW |
2854 | } |
2855 | else | |
3280af22 | 2856 | newargv = PL_origargv; |
774d564b | 2857 | newargv[0] = ipath; |
b35112e7 | 2858 | PERL_FPU_PRE_EXEC |
b4748376 | 2859 | PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv)); |
b35112e7 | 2860 | PERL_FPU_POST_EXEC |
cea2e8a9 | 2861 | Perl_croak(aTHX_ "Can't exec %s", ipath); |
9f68db38 | 2862 | } |
bf4acbe4 | 2863 | #endif |
748a9306 | 2864 | if (d) { |
3280af22 NIS |
2865 | U32 oldpdb = PL_perldb; |
2866 | bool oldn = PL_minus_n; | |
2867 | bool oldp = PL_minus_p; | |
748a9306 LW |
2868 | |
2869 | while (*d && !isSPACE(*d)) d++; | |
bf4acbe4 | 2870 | while (SPACE_OR_TAB(*d)) d++; |
748a9306 LW |
2871 | |
2872 | if (*d++ == '-') { | |
a11ec5a9 | 2873 | bool switches_done = PL_doswitches; |
8cc95fdb | 2874 | do { |
3ffe3ee4 | 2875 | if (*d == 'M' || *d == 'm' || *d == 'C') { |
8cc95fdb | 2876 | char *m = d; |
2877 | while (*d && !isSPACE(*d)) d++; | |
cea2e8a9 | 2878 | Perl_croak(aTHX_ "Too late for \"-%.*s\" option", |
8cc95fdb | 2879 | (int)(d - m), m); |
2880 | } | |
2881 | d = moreswitches(d); | |
2882 | } while (d); | |
f0b2cf55 YST |
2883 | if (PL_doswitches && !switches_done) { |
2884 | int argc = PL_origargc; | |
2885 | char **argv = PL_origargv; | |
2886 | do { | |
2887 | argc--,argv++; | |
2888 | } while (argc && argv[0][0] == '-' && argv[0][1]); | |
2889 | init_argv_symbols(argc,argv); | |
2890 | } | |
155aba94 GS |
2891 | if ((PERLDB_LINE && !oldpdb) || |
2892 | ((PL_minus_n || PL_minus_p) && !(oldn || oldp))) | |
b084f20b | 2893 | /* if we have already added "LINE: while (<>) {", |
2894 | we must not do it again */ | |
748a9306 | 2895 | { |
3280af22 NIS |
2896 | sv_setpv(PL_linestr, ""); |
2897 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); | |
2898 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2899 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 2900 | PL_preambled = FALSE; |
84902520 | 2901 | if (PERLDB_LINE) |
3280af22 | 2902 | (void)gv_fetchfile(PL_origfilename); |
748a9306 LW |
2903 | goto retry; |
2904 | } | |
a11ec5a9 RGS |
2905 | if (PL_doswitches && !switches_done) { |
2906 | int argc = PL_origargc; | |
2907 | char **argv = PL_origargv; | |
2908 | do { | |
2909 | argc--,argv++; | |
2910 | } while (argc && argv[0][0] == '-' && argv[0][1]); | |
2911 | init_argv_symbols(argc,argv); | |
2912 | } | |
a0d0e21e | 2913 | } |
79072805 | 2914 | } |
9f68db38 | 2915 | } |
79072805 | 2916 | } |
3280af22 NIS |
2917 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
2918 | PL_bufptr = s; | |
2919 | PL_lex_state = LEX_FORMLINE; | |
cea2e8a9 | 2920 | return yylex(); |
ae986130 | 2921 | } |
378cc40b | 2922 | goto retry; |
4fdae800 | 2923 | case '\r': |
6a27c188 | 2924 | #ifdef PERL_STRICT_CR |
cea2e8a9 | 2925 | Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r'); |
4e553d73 | 2926 | Perl_croak(aTHX_ |
cc507455 | 2927 | "\t(Maybe you didn't strip carriage returns after a network transfer?)\n"); |
a868473f | 2928 | #endif |
4fdae800 | 2929 | case ' ': case '\t': case '\f': case 013: |
bf4acbe4 GS |
2930 | #ifdef MACOS_TRADITIONAL |
2931 | case '\312': | |
2932 | #endif | |
378cc40b LW |
2933 | s++; |
2934 | goto retry; | |
378cc40b | 2935 | case '#': |
e929a76b | 2936 | case '\n': |
3280af22 | 2937 | if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) { |
df0deb90 GS |
2938 | if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) { |
2939 | /* handle eval qq[#line 1 "foo"\n ...] */ | |
2940 | CopLINE_dec(PL_curcop); | |
2941 | incline(s); | |
2942 | } | |
3280af22 | 2943 | d = PL_bufend; |
a687059c | 2944 | while (s < d && *s != '\n') |
378cc40b | 2945 | s++; |
0f85fab0 | 2946 | if (s < d) |
378cc40b | 2947 | s++; |
78c267c1 | 2948 | else if (s > d) /* Found by Ilya: feed random input to Perl. */ |
a8406387 | 2949 | Perl_croak(aTHX_ "panic: input overflow"); |
463ee0b2 | 2950 | incline(s); |
3280af22 NIS |
2951 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
2952 | PL_bufptr = s; | |
2953 | PL_lex_state = LEX_FORMLINE; | |
cea2e8a9 | 2954 | return yylex(); |
a687059c | 2955 | } |
378cc40b | 2956 | } |
a687059c | 2957 | else { |
378cc40b | 2958 | *s = '\0'; |
3280af22 | 2959 | PL_bufend = s; |
a687059c | 2960 | } |
378cc40b LW |
2961 | goto retry; |
2962 | case '-': | |
79072805 | 2963 | if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) { |
e5edeb50 JH |
2964 | I32 ftst = 0; |
2965 | ||
378cc40b | 2966 | s++; |
3280af22 | 2967 | PL_bufptr = s; |
748a9306 LW |
2968 | tmp = *s++; |
2969 | ||
bf4acbe4 | 2970 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
748a9306 LW |
2971 | s++; |
2972 | ||
2973 | if (strnEQ(s,"=>",2)) { | |
3280af22 | 2974 | s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE); |
4e553d73 | 2975 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
607df283 | 2976 | "### Saw unary minus before =>, forcing word '%s'\n", s); |
5f80b19c | 2977 | } ); |
748a9306 LW |
2978 | OPERATOR('-'); /* unary minus */ |
2979 | } | |
3280af22 | 2980 | PL_last_uni = PL_oldbufptr; |
748a9306 | 2981 | switch (tmp) { |
e5edeb50 JH |
2982 | case 'r': ftst = OP_FTEREAD; break; |
2983 | case 'w': ftst = OP_FTEWRITE; break; | |
2984 | case 'x': ftst = OP_FTEEXEC; break; | |
2985 | case 'o': ftst = OP_FTEOWNED; break; | |
2986 | case 'R': ftst = OP_FTRREAD; break; | |
2987 | case 'W': ftst = OP_FTRWRITE; break; | |
2988 | case 'X': ftst = OP_FTREXEC; break; | |
2989 | case 'O': ftst = OP_FTROWNED; break; | |
2990 | case 'e': ftst = OP_FTIS; break; | |
2991 | case 'z': ftst = OP_FTZERO; break; | |
2992 | case 's': ftst = OP_FTSIZE; break; | |
2993 | case 'f': ftst = OP_FTFILE; break; | |
2994 | case 'd': ftst = OP_FTDIR; break; | |
2995 | case 'l': ftst = OP_FTLINK; break; | |
2996 | case 'p': ftst = OP_FTPIPE; break; | |
2997 | case 'S': ftst = OP_FTSOCK; break; | |
2998 | case 'u': ftst = OP_FTSUID; break; | |
2999 | case 'g': ftst = OP_FTSGID; break; | |
3000 | case 'k': ftst = OP_FTSVTX; break; | |
3001 | case 'b': ftst = OP_FTBLK; break; | |
3002 | case 'c': ftst = OP_FTCHR; break; | |
3003 | case 't': ftst = OP_FTTTY; break; | |
3004 | case 'T': ftst = OP_FTTEXT; break; | |
3005 | case 'B': ftst = OP_FTBINARY; break; | |
3006 | case 'M': case 'A': case 'C': | |
3007 | gv_fetchpv("\024",TRUE, SVt_PV); | |
3008 | switch (tmp) { | |
3009 | case 'M': ftst = OP_FTMTIME; break; | |
3010 | case 'A': ftst = OP_FTATIME; break; | |
3011 | case 'C': ftst = OP_FTCTIME; break; | |
3012 | default: break; | |
3013 | } | |
3014 | break; | |
378cc40b | 3015 | default: |
378cc40b LW |
3016 | break; |
3017 | } | |
e5edeb50 | 3018 | if (ftst) { |
eb160463 | 3019 | PL_last_lop_op = (OPCODE)ftst; |
4e553d73 | 3020 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
0844c848 | 3021 | "### Saw file test %c\n", (int)ftst); |
5f80b19c | 3022 | } ); |
e5edeb50 JH |
3023 | FTST(ftst); |
3024 | } | |
3025 | else { | |
3026 | /* Assume it was a minus followed by a one-letter named | |
3027 | * subroutine call (or a -bareword), then. */ | |
95c31fe3 | 3028 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
17ad61e0 | 3029 | "### '-%c' looked like a file test but was not\n", |
4fccd7c6 | 3030 | (int) tmp); |
5f80b19c | 3031 | } ); |
3cf7b4c4 | 3032 | s = --PL_bufptr; |
e5edeb50 | 3033 | } |
378cc40b | 3034 | } |
a687059c LW |
3035 | tmp = *s++; |
3036 | if (*s == tmp) { | |
3037 | s++; | |
3280af22 | 3038 | if (PL_expect == XOPERATOR) |
79072805 LW |
3039 | TERM(POSTDEC); |
3040 | else | |
3041 | OPERATOR(PREDEC); | |
3042 | } | |
3043 | else if (*s == '>') { | |
3044 | s++; | |
3045 | s = skipspace(s); | |
7e2040f0 | 3046 | if (isIDFIRST_lazy_if(s,UTF)) { |
a0d0e21e | 3047 | s = force_word(s,METHOD,FALSE,TRUE,FALSE); |
463ee0b2 | 3048 | TOKEN(ARROW); |
79072805 | 3049 | } |
748a9306 LW |
3050 | else if (*s == '$') |
3051 | OPERATOR(ARROW); | |
463ee0b2 | 3052 | else |
748a9306 | 3053 | TERM(ARROW); |
a687059c | 3054 | } |
3280af22 | 3055 | if (PL_expect == XOPERATOR) |
79072805 LW |
3056 | Aop(OP_SUBTRACT); |
3057 | else { | |
3280af22 | 3058 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) |
2f3197b3 | 3059 | check_uni(); |
79072805 | 3060 | OPERATOR('-'); /* unary minus */ |
2f3197b3 | 3061 | } |
79072805 | 3062 | |
378cc40b | 3063 | case '+': |
a687059c LW |
3064 | tmp = *s++; |
3065 | if (*s == tmp) { | |
378cc40b | 3066 | s++; |
3280af22 | 3067 | if (PL_expect == XOPERATOR) |
79072805 LW |
3068 | TERM(POSTINC); |
3069 | else | |
3070 | OPERATOR(PREINC); | |
378cc40b | 3071 | } |
3280af22 | 3072 | if (PL_expect == XOPERATOR) |
79072805 LW |
3073 | Aop(OP_ADD); |
3074 | else { | |
3280af22 | 3075 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) |
2f3197b3 | 3076 | check_uni(); |
a687059c | 3077 | OPERATOR('+'); |
2f3197b3 | 3078 | } |
a687059c | 3079 | |
378cc40b | 3080 | case '*': |
3280af22 NIS |
3081 | if (PL_expect != XOPERATOR) { |
3082 | s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); | |
3083 | PL_expect = XOPERATOR; | |
3084 | force_ident(PL_tokenbuf, '*'); | |
3085 | if (!*PL_tokenbuf) | |
a0d0e21e | 3086 | PREREF('*'); |
79072805 | 3087 | TERM('*'); |
a687059c | 3088 | } |
79072805 LW |
3089 | s++; |
3090 | if (*s == '*') { | |
a687059c | 3091 | s++; |
79072805 | 3092 | PWop(OP_POW); |
a687059c | 3093 | } |
79072805 LW |
3094 | Mop(OP_MULTIPLY); |
3095 | ||
378cc40b | 3096 | case '%': |
3280af22 | 3097 | if (PL_expect == XOPERATOR) { |
bbce6d69 | 3098 | ++s; |
3099 | Mop(OP_MODULO); | |
a687059c | 3100 | } |
3280af22 NIS |
3101 | PL_tokenbuf[0] = '%'; |
3102 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE); | |
3103 | if (!PL_tokenbuf[1]) { | |
bbce6d69 | 3104 | PREREF('%'); |
a687059c | 3105 | } |
3280af22 | 3106 | PL_pending_ident = '%'; |
bbce6d69 | 3107 | TERM('%'); |
a687059c | 3108 | |
378cc40b | 3109 | case '^': |
79072805 | 3110 | s++; |
a0d0e21e | 3111 | BOop(OP_BIT_XOR); |
79072805 | 3112 | case '[': |
3280af22 | 3113 | PL_lex_brackets++; |
79072805 | 3114 | /* FALL THROUGH */ |
378cc40b | 3115 | case '~': |
378cc40b | 3116 | case ',': |
378cc40b LW |
3117 | tmp = *s++; |
3118 | OPERATOR(tmp); | |
a0d0e21e LW |
3119 | case ':': |
3120 | if (s[1] == ':') { | |
3121 | len = 0; | |
3122 | goto just_a_word; | |
3123 | } | |
3124 | s++; | |
09bef843 SB |
3125 | switch (PL_expect) { |
3126 | OP *attrs; | |
3127 | case XOPERATOR: | |
3128 | if (!PL_in_my || PL_lex_state != LEX_NORMAL) | |
3129 | break; | |
3130 | PL_bufptr = s; /* update in case we back off */ | |
3131 | goto grabattrs; | |
3132 | case XATTRBLOCK: | |
3133 | PL_expect = XBLOCK; | |
3134 | goto grabattrs; | |
3135 | case XATTRTERM: | |
3136 | PL_expect = XTERMBLOCK; | |
3137 | grabattrs: | |
3138 | s = skipspace(s); | |
3139 | attrs = Nullop; | |
7e2040f0 | 3140 | while (isIDFIRST_lazy_if(s,UTF)) { |
09bef843 | 3141 | d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
f9829d6b GS |
3142 | if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) { |
3143 | if (tmp < 0) tmp = -tmp; | |
3144 | switch (tmp) { | |
3145 | case KEY_or: | |
3146 | case KEY_and: | |
c963b151 | 3147 | case KEY_err: |
f9829d6b GS |
3148 | case KEY_for: |
3149 | case KEY_unless: | |
3150 | case KEY_if: | |
3151 | case KEY_while: | |
3152 | case KEY_until: | |
3153 | goto got_attrs; | |
3154 | default: | |
3155 | break; | |
3156 | } | |
3157 | } | |
09bef843 SB |
3158 | if (*d == '(') { |
3159 | d = scan_str(d,TRUE,TRUE); | |
3160 | if (!d) { | |
09bef843 SB |
3161 | /* MUST advance bufptr here to avoid bogus |
3162 | "at end of line" context messages from yyerror(). | |
3163 | */ | |
3164 | PL_bufptr = s + len; | |
3165 | yyerror("Unterminated attribute parameter in attribute list"); | |
3166 | if (attrs) | |
3167 | op_free(attrs); | |
bbf60fe6 | 3168 | return REPORT(0); /* EOF indicator */ |
09bef843 SB |
3169 | } |
3170 | } | |
3171 | if (PL_lex_stuff) { | |
3172 | SV *sv = newSVpvn(s, len); | |
3173 | sv_catsv(sv, PL_lex_stuff); | |
3174 | attrs = append_elem(OP_LIST, attrs, | |
3175 | newSVOP(OP_CONST, 0, sv)); | |
3176 | SvREFCNT_dec(PL_lex_stuff); | |
3177 | PL_lex_stuff = Nullsv; | |
3178 | } | |
3179 | else { | |
371fce9b DM |
3180 | if (len == 6 && strnEQ(s, "unique", len)) { |
3181 | if (PL_in_my == KEY_our) | |
3182 | #ifdef USE_ITHREADS | |
3183 | GvUNIQUE_on(cGVOPx_gv(yylval.opval)); | |
3184 | #else | |
3185 | ; /* skip to avoid loading attributes.pm */ | |
3186 | #endif | |
bfed75c6 | 3187 | else |
371fce9b DM |
3188 | Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables"); |
3189 | } | |
3190 | ||
d3cea301 SB |
3191 | /* NOTE: any CV attrs applied here need to be part of |
3192 | the CVf_BUILTIN_ATTRS define in cv.h! */ | |
371fce9b | 3193 | else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len)) |
78f9721b SM |
3194 | CvLVALUE_on(PL_compcv); |
3195 | else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len)) | |
3196 | CvLOCKED_on(PL_compcv); | |
3197 | else if (!PL_in_my && len == 6 && strnEQ(s, "method", len)) | |
3198 | CvMETHOD_on(PL_compcv); | |
06492da6 SF |
3199 | else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len)) |
3200 | CvASSERTION_on(PL_compcv); | |
78f9721b SM |
3201 | /* After we've set the flags, it could be argued that |
3202 | we don't need to do the attributes.pm-based setting | |
3203 | process, and shouldn't bother appending recognized | |
d3cea301 SB |
3204 | flags. To experiment with that, uncomment the |
3205 | following "else". (Note that's already been | |
3206 | uncommented. That keeps the above-applied built-in | |
3207 | attributes from being intercepted (and possibly | |
3208 | rejected) by a package's attribute routines, but is | |
3209 | justified by the performance win for the common case | |
3210 | of applying only built-in attributes.) */ | |
0256094b | 3211 | else |
78f9721b SM |
3212 | attrs = append_elem(OP_LIST, attrs, |
3213 | newSVOP(OP_CONST, 0, | |
3214 | newSVpvn(s, len))); | |
09bef843 SB |
3215 | } |
3216 | s = skipspace(d); | |
0120eecf | 3217 | if (*s == ':' && s[1] != ':') |
09bef843 | 3218 | s = skipspace(s+1); |
0120eecf GS |
3219 | else if (s == d) |
3220 | break; /* require real whitespace or :'s */ | |
09bef843 | 3221 | } |
f9829d6b | 3222 | tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */ |
8e7ae056 | 3223 | if (*s != ';' && *s != '}' && *s != tmp && (tmp != '=' || *s != ')')) { |
09bef843 SB |
3224 | char q = ((*s == '\'') ? '"' : '\''); |
3225 | /* If here for an expression, and parsed no attrs, back off. */ | |
3226 | if (tmp == '=' && !attrs) { | |
3227 | s = PL_bufptr; | |
3228 | break; | |
3229 | } | |
3230 | /* MUST advance bufptr here to avoid bogus "at end of line" | |
3231 | context messages from yyerror(). | |
3232 | */ | |
3233 | PL_bufptr = s; | |
3234 | if (!*s) | |
3235 | yyerror("Unterminated attribute list"); | |
3236 | else | |
3237 | yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list", | |
3238 | q, *s, q)); | |
3239 | if (attrs) | |
3240 | op_free(attrs); | |
3241 | OPERATOR(':'); | |
3242 | } | |
f9829d6b | 3243 | got_attrs: |
09bef843 SB |
3244 | if (attrs) { |
3245 | PL_nextval[PL_nexttoke].opval = attrs; | |
3246 | force_next(THING); | |
3247 | } | |
3248 | TOKEN(COLONATTR); | |
3249 | } | |
a0d0e21e | 3250 | OPERATOR(':'); |
8990e307 LW |
3251 | case '(': |
3252 | s++; | |
3280af22 NIS |
3253 | if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr) |
3254 | PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */ | |
a0d0e21e | 3255 | else |
3280af22 | 3256 | PL_expect = XTERM; |
4a202259 | 3257 | s = skipspace(s); |
a0d0e21e | 3258 | TOKEN('('); |
378cc40b | 3259 | case ';': |
f4dd75d9 | 3260 | CLINE; |
378cc40b LW |
3261 | tmp = *s++; |
3262 | OPERATOR(tmp); | |
3263 | case ')': | |
378cc40b | 3264 | tmp = *s++; |
16d20bd9 AD |
3265 | s = skipspace(s); |
3266 | if (*s == '{') | |
3267 | PREBLOCK(tmp); | |
378cc40b | 3268 | TERM(tmp); |
79072805 LW |
3269 | case ']': |
3270 | s++; | |
3280af22 | 3271 | if (PL_lex_brackets <= 0) |
d98d5fff | 3272 | yyerror("Unmatched right square bracket"); |
463ee0b2 | 3273 | else |
3280af22 NIS |
3274 | --PL_lex_brackets; |
3275 | if (PL_lex_state == LEX_INTERPNORMAL) { | |
3276 | if (PL_lex_brackets == 0) { | |
a0d0e21e | 3277 | if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>')) |
3280af22 | 3278 | PL_lex_state = LEX_INTERPEND; |
79072805 LW |
3279 | } |
3280 | } | |
4633a7c4 | 3281 | TERM(']'); |
79072805 LW |
3282 | case '{': |
3283 | leftbracket: | |
79072805 | 3284 | s++; |
3280af22 | 3285 | if (PL_lex_brackets > 100) { |
8edd5f42 | 3286 | Renew(PL_lex_brackstack, PL_lex_brackets + 10, char); |
8990e307 | 3287 | } |
3280af22 | 3288 | switch (PL_expect) { |
a0d0e21e | 3289 | case XTERM: |
3280af22 | 3290 | if (PL_lex_formbrack) { |
a0d0e21e LW |
3291 | s--; |
3292 | PRETERMBLOCK(DO); | |
3293 | } | |
3280af22 NIS |
3294 | if (PL_oldoldbufptr == PL_last_lop) |
3295 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; | |
a0d0e21e | 3296 | else |
3280af22 | 3297 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
79072805 | 3298 | OPERATOR(HASHBRACK); |
a0d0e21e | 3299 | case XOPERATOR: |
bf4acbe4 | 3300 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
748a9306 | 3301 | s++; |
44a8e56a | 3302 | d = s; |
3280af22 NIS |
3303 | PL_tokenbuf[0] = '\0'; |
3304 | if (d < PL_bufend && *d == '-') { | |
3305 | PL_tokenbuf[0] = '-'; | |
44a8e56a | 3306 | d++; |
bf4acbe4 | 3307 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
44a8e56a | 3308 | d++; |
3309 | } | |
7e2040f0 | 3310 | if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) { |
3280af22 | 3311 | d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, |
8903cb82 | 3312 | FALSE, &len); |
bf4acbe4 | 3313 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
748a9306 LW |
3314 | d++; |
3315 | if (*d == '}') { | |
3280af22 | 3316 | char minus = (PL_tokenbuf[0] == '-'); |
44a8e56a | 3317 | s = force_word(s + minus, WORD, FALSE, TRUE, FALSE); |
3318 | if (minus) | |
3319 | force_next('-'); | |
748a9306 LW |
3320 | } |
3321 | } | |
3322 | /* FALL THROUGH */ | |
09bef843 | 3323 | case XATTRBLOCK: |
748a9306 | 3324 | case XBLOCK: |
3280af22 NIS |
3325 | PL_lex_brackstack[PL_lex_brackets++] = XSTATE; |
3326 | PL_expect = XSTATE; | |
a0d0e21e | 3327 | break; |
09bef843 | 3328 | case XATTRTERM: |
a0d0e21e | 3329 | case XTERMBLOCK: |
3280af22 NIS |
3330 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
3331 | PL_expect = XSTATE; | |
a0d0e21e LW |
3332 | break; |
3333 | default: { | |
3334 | char *t; | |
3280af22 NIS |
3335 | if (PL_oldoldbufptr == PL_last_lop) |
3336 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; | |
a0d0e21e | 3337 | else |
3280af22 | 3338 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
a0d0e21e | 3339 | s = skipspace(s); |
8452ff4b SB |
3340 | if (*s == '}') { |
3341 | if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) { | |
3342 | PL_expect = XTERM; | |
3343 | /* This hack is to get the ${} in the message. */ | |
3344 | PL_bufptr = s+1; | |
3345 | yyerror("syntax error"); | |
3346 | break; | |
3347 | } | |
a0d0e21e | 3348 | OPERATOR(HASHBRACK); |
8452ff4b | 3349 | } |
b8a4b1be GS |
3350 | /* This hack serves to disambiguate a pair of curlies |
3351 | * as being a block or an anon hash. Normally, expectation | |
3352 | * determines that, but in cases where we're not in a | |
3353 | * position to expect anything in particular (like inside | |
3354 | * eval"") we have to resolve the ambiguity. This code | |
3355 | * covers the case where the first term in the curlies is a | |
3356 | * quoted string. Most other cases need to be explicitly | |
3357 | * disambiguated by prepending a `+' before the opening | |
3358 | * curly in order to force resolution as an anon hash. | |
3359 | * | |
3360 | * XXX should probably propagate the outer expectation | |
3361 | * into eval"" to rely less on this hack, but that could | |
3362 | * potentially break current behavior of eval"". | |
3363 | * GSAR 97-07-21 | |
3364 | */ | |
3365 | t = s; | |
3366 | if (*s == '\'' || *s == '"' || *s == '`') { | |
3367 | /* common case: get past first string, handling escapes */ | |
3280af22 | 3368 | for (t++; t < PL_bufend && *t != *s;) |
b8a4b1be GS |
3369 | if (*t++ == '\\' && (*t == '\\' || *t == *s)) |
3370 | t++; | |
3371 | t++; | |
a0d0e21e | 3372 | } |
b8a4b1be | 3373 | else if (*s == 'q') { |
3280af22 | 3374 | if (++t < PL_bufend |
b8a4b1be | 3375 | && (!isALNUM(*t) |
3280af22 | 3376 | || ((*t == 'q' || *t == 'x') && ++t < PL_bufend |
0505442f GS |
3377 | && !isALNUM(*t)))) |
3378 | { | |
abc667d1 | 3379 | /* skip q//-like construct */ |
b8a4b1be GS |
3380 | char *tmps; |
3381 | char open, close, term; | |
3382 | I32 brackets = 1; | |
3383 | ||
3280af22 | 3384 | while (t < PL_bufend && isSPACE(*t)) |
b8a4b1be | 3385 | t++; |
abc667d1 DM |
3386 | /* check for q => */ |
3387 | if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') { | |
3388 | OPERATOR(HASHBRACK); | |
3389 | } | |
b8a4b1be GS |
3390 | term = *t; |
3391 | open = term; | |
3392 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) | |
3393 | term = tmps[5]; | |
3394 | close = term; | |
3395 | if (open == close) | |
3280af22 NIS |
3396 | for (t++; t < PL_bufend; t++) { |
3397 | if (*t == '\\' && t+1 < PL_bufend && open != '\\') | |
b8a4b1be | 3398 | t++; |
6d07e5e9 | 3399 | else if (*t == open) |
b8a4b1be GS |
3400 | break; |
3401 | } | |
abc667d1 | 3402 | else { |
3280af22 NIS |
3403 | for (t++; t < PL_bufend; t++) { |
3404 | if (*t == '\\' && t+1 < PL_bufend) | |
b8a4b1be | 3405 | t++; |
6d07e5e9 | 3406 | else if (*t == close && --brackets <= 0) |
b8a4b1be GS |
3407 | break; |
3408 | else if (*t == open) | |
3409 | brackets++; | |
3410 | } | |
abc667d1 DM |
3411 | } |
3412 | t++; | |
b8a4b1be | 3413 | } |
abc667d1 DM |
3414 | else |
3415 | /* skip plain q word */ | |
3416 | while (t < PL_bufend && isALNUM_lazy_if(t,UTF)) | |
3417 | t += UTF8SKIP(t); | |
a0d0e21e | 3418 | } |
7e2040f0 | 3419 | else if (isALNUM_lazy_if(t,UTF)) { |
0505442f | 3420 | t += UTF8SKIP(t); |
7e2040f0 | 3421 | while (t < PL_bufend && isALNUM_lazy_if(t,UTF)) |
0505442f | 3422 | t += UTF8SKIP(t); |
a0d0e21e | 3423 | } |
3280af22 | 3424 | while (t < PL_bufend && isSPACE(*t)) |
a0d0e21e | 3425 | t++; |
b8a4b1be GS |
3426 | /* if comma follows first term, call it an anon hash */ |
3427 | /* XXX it could be a comma expression with loop modifiers */ | |
3280af22 | 3428 | if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s))) |
b8a4b1be | 3429 | || (*t == '=' && t[1] == '>'))) |
a0d0e21e | 3430 | OPERATOR(HASHBRACK); |
3280af22 | 3431 | if (PL_expect == XREF) |
4e4e412b | 3432 | PL_expect = XTERM; |
a0d0e21e | 3433 | else { |
3280af22 NIS |
3434 | PL_lex_brackstack[PL_lex_brackets-1] = XSTATE; |
3435 | PL_expect = XSTATE; | |
a0d0e21e | 3436 | } |
8990e307 | 3437 | } |
a0d0e21e | 3438 | break; |
463ee0b2 | 3439 | } |
57843af0 | 3440 | yylval.ival = CopLINE(PL_curcop); |
79072805 | 3441 | if (isSPACE(*s) || *s == '#') |
3280af22 | 3442 | PL_copline = NOLINE; /* invalidate current command line number */ |
79072805 | 3443 | TOKEN('{'); |
378cc40b | 3444 | case '}': |
79072805 LW |
3445 | rightbracket: |
3446 | s++; | |
3280af22 | 3447 | if (PL_lex_brackets <= 0) |
d98d5fff | 3448 | yyerror("Unmatched right curly bracket"); |
463ee0b2 | 3449 | else |
3280af22 | 3450 | PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets]; |
c2e66d9e | 3451 | if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL) |
3280af22 NIS |
3452 | PL_lex_formbrack = 0; |
3453 | if (PL_lex_state == LEX_INTERPNORMAL) { | |
3454 | if (PL_lex_brackets == 0) { | |
9059aa12 LW |
3455 | if (PL_expect & XFAKEBRACK) { |
3456 | PL_expect &= XENUMMASK; | |
3280af22 NIS |
3457 | PL_lex_state = LEX_INTERPEND; |
3458 | PL_bufptr = s; | |
cea2e8a9 | 3459 | return yylex(); /* ignore fake brackets */ |
79072805 | 3460 | } |
fa83b5b6 | 3461 | if (*s == '-' && s[1] == '>') |
3280af22 | 3462 | PL_lex_state = LEX_INTERPENDMAYBE; |
fa83b5b6 | 3463 | else if (*s != '[' && *s != '{') |
3280af22 | 3464 | PL_lex_state = LEX_INTERPEND; |
79072805 LW |
3465 | } |
3466 | } | |
9059aa12 LW |
3467 | if (PL_expect & XFAKEBRACK) { |
3468 | PL_expect &= XENUMMASK; | |
3280af22 | 3469 | PL_bufptr = s; |
cea2e8a9 | 3470 | return yylex(); /* ignore fake brackets */ |
748a9306 | 3471 | } |
79072805 LW |
3472 | force_next('}'); |
3473 | TOKEN(';'); | |
378cc40b LW |
3474 | case '&': |
3475 | s++; | |
3476 | tmp = *s++; | |
3477 | if (tmp == '&') | |
a0d0e21e | 3478 | AOPERATOR(ANDAND); |
378cc40b | 3479 | s--; |
3280af22 | 3480 | if (PL_expect == XOPERATOR) { |
7e2040f0 GS |
3481 | if (ckWARN(WARN_SEMICOLON) |
3482 | && isIDFIRST_lazy_if(s,UTF) && PL_bufptr == PL_linestart) | |
3483 | { | |
57843af0 | 3484 | CopLINE_dec(PL_curcop); |
9014280d | 3485 | Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi); |
57843af0 | 3486 | CopLINE_inc(PL_curcop); |
463ee0b2 | 3487 | } |
79072805 | 3488 | BAop(OP_BIT_AND); |
463ee0b2 | 3489 | } |
79072805 | 3490 | |
3280af22 NIS |
3491 | s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); |
3492 | if (*PL_tokenbuf) { | |
3493 | PL_expect = XOPERATOR; | |
3494 | force_ident(PL_tokenbuf, '&'); | |
463ee0b2 | 3495 | } |
79072805 LW |
3496 | else |
3497 | PREREF('&'); | |
c07a80fd | 3498 | yylval.ival = (OPpENTERSUB_AMPER<<8); |
79072805 LW |
3499 | TERM('&'); |
3500 | ||
378cc40b LW |
3501 | case '|': |
3502 | s++; | |
3503 | tmp = *s++; | |
3504 | if (tmp == '|') | |
a0d0e21e | 3505 | AOPERATOR(OROR); |
378cc40b | 3506 | s--; |
79072805 | 3507 | BOop(OP_BIT_OR); |
378cc40b LW |
3508 | case '=': |
3509 | s++; | |
3510 | tmp = *s++; | |
3511 | if (tmp == '=') | |
79072805 LW |
3512 | Eop(OP_EQ); |
3513 | if (tmp == '>') | |
3514 | OPERATOR(','); | |
378cc40b | 3515 | if (tmp == '~') |
79072805 | 3516 | PMop(OP_MATCH); |
599cee73 | 3517 | if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp)) |
9014280d | 3518 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Reversed %c= operator",(int)tmp); |
378cc40b | 3519 | s--; |
3280af22 NIS |
3520 | if (PL_expect == XSTATE && isALPHA(tmp) && |
3521 | (s == PL_linestart+1 || s[-2] == '\n') ) | |
748a9306 | 3522 | { |
3280af22 NIS |
3523 | if (PL_in_eval && !PL_rsfp) { |
3524 | d = PL_bufend; | |
a5f75d66 AD |
3525 | while (s < d) { |
3526 | if (*s++ == '\n') { | |
3527 | incline(s); | |
3528 | if (strnEQ(s,"=cut",4)) { | |
3529 | s = strchr(s,'\n'); | |
3530 | if (s) | |
3531 | s++; | |
3532 | else | |
3533 | s = d; | |
3534 | incline(s); | |
3535 | goto retry; | |
3536 | } | |
3537 | } | |
3538 | } | |
3539 | goto retry; | |
3540 | } | |
3280af22 NIS |
3541 | s = PL_bufend; |
3542 | PL_doextract = TRUE; | |
a0d0e21e LW |
3543 | goto retry; |
3544 | } | |
3280af22 | 3545 | if (PL_lex_brackets < PL_lex_formbrack) { |
a0d0e21e | 3546 | char *t; |
51882d45 | 3547 | #ifdef PERL_STRICT_CR |
bf4acbe4 | 3548 | for (t = s; SPACE_OR_TAB(*t); t++) ; |
51882d45 | 3549 | #else |
bf4acbe4 | 3550 | for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ; |
51882d45 | 3551 | #endif |
a0d0e21e LW |
3552 | if (*t == '\n' || *t == '#') { |
3553 | s--; | |
3280af22 | 3554 | PL_expect = XBLOCK; |
a0d0e21e LW |
3555 | goto leftbracket; |
3556 | } | |
79072805 | 3557 | } |
a0d0e21e LW |
3558 | yylval.ival = 0; |
3559 | OPERATOR(ASSIGNOP); | |
378cc40b LW |
3560 | case '!': |
3561 | s++; | |
3562 | tmp = *s++; | |
984200d0 | 3563 | if (tmp == '=') { |
decca21c YST |
3564 | /* was this !=~ where !~ was meant? |
3565 | * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */ | |
3566 | ||
984200d0 YST |
3567 | if (*s == '~' && ckWARN(WARN_SYNTAX)) { |
3568 | char *t = s+1; | |
3569 | ||
3570 | while (t < PL_bufend && isSPACE(*t)) | |
3571 | ++t; | |
3572 | ||
decca21c YST |
3573 | if (*t == '/' || *t == '?' || |
3574 | ((*t == 'm' || *t == 's' || *t == 'y') && !isALNUM(t[1])) || | |
3575 | (*t == 't' && t[1] == 'r' && !isALNUM(t[2]))) | |
984200d0 YST |
3576 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
3577 | "!=~ should be !~"); | |
3578 | } | |
79072805 | 3579 | Eop(OP_NE); |
984200d0 | 3580 | } |
378cc40b | 3581 | if (tmp == '~') |
79072805 | 3582 | PMop(OP_NOT); |
378cc40b LW |
3583 | s--; |
3584 | OPERATOR('!'); | |
3585 | case '<': | |
3280af22 | 3586 | if (PL_expect != XOPERATOR) { |
93a17b20 | 3587 | if (s[1] != '<' && !strchr(s,'>')) |
2f3197b3 | 3588 | check_uni(); |
79072805 LW |
3589 | if (s[1] == '<') |
3590 | s = scan_heredoc(s); | |
3591 | else | |
3592 | s = scan_inputsymbol(s); | |
3593 | TERM(sublex_start()); | |
378cc40b LW |
3594 | } |
3595 | s++; | |
3596 | tmp = *s++; | |
3597 | if (tmp == '<') | |
79072805 | 3598 | SHop(OP_LEFT_SHIFT); |
395c3793 LW |
3599 | if (tmp == '=') { |
3600 | tmp = *s++; | |
3601 | if (tmp == '>') | |
79072805 | 3602 | Eop(OP_NCMP); |
395c3793 | 3603 | s--; |
79072805 | 3604 | Rop(OP_LE); |
395c3793 | 3605 | } |
378cc40b | 3606 | s--; |
79072805 | 3607 | Rop(OP_LT); |
378cc40b LW |
3608 | case '>': |
3609 | s++; | |
3610 | tmp = *s++; | |
3611 | if (tmp == '>') | |
79072805 | 3612 | SHop(OP_RIGHT_SHIFT); |
378cc40b | 3613 | if (tmp == '=') |
79072805 | 3614 | Rop(OP_GE); |
378cc40b | 3615 | s--; |
79072805 | 3616 | Rop(OP_GT); |
378cc40b LW |
3617 | |
3618 | case '$': | |
bbce6d69 | 3619 | CLINE; |
3620 | ||
3280af22 NIS |
3621 | if (PL_expect == XOPERATOR) { |
3622 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3623 | PL_expect = XTERM; | |
a0d0e21e | 3624 | depcom(); |
bbf60fe6 | 3625 | return REPORT(','); /* grandfather non-comma-format format */ |
a0d0e21e | 3626 | } |
8990e307 | 3627 | } |
a0d0e21e | 3628 | |
7e2040f0 | 3629 | if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) { |
3280af22 | 3630 | PL_tokenbuf[0] = '@'; |
376b8730 SM |
3631 | s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1, |
3632 | sizeof PL_tokenbuf - 1, FALSE); | |
3633 | if (PL_expect == XOPERATOR) | |
3634 | no_op("Array length", s); | |
3280af22 | 3635 | if (!PL_tokenbuf[1]) |
a0d0e21e | 3636 | PREREF(DOLSHARP); |
3280af22 NIS |
3637 | PL_expect = XOPERATOR; |
3638 | PL_pending_ident = '#'; | |
463ee0b2 | 3639 | TOKEN(DOLSHARP); |
79072805 | 3640 | } |
bbce6d69 | 3641 | |
3280af22 | 3642 | PL_tokenbuf[0] = '$'; |
376b8730 SM |
3643 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, |
3644 | sizeof PL_tokenbuf - 1, FALSE); | |
3645 | if (PL_expect == XOPERATOR) | |
3646 | no_op("Scalar", s); | |
3280af22 NIS |
3647 | if (!PL_tokenbuf[1]) { |
3648 | if (s == PL_bufend) | |
bbce6d69 | 3649 | yyerror("Final $ should be \\$ or $name"); |
3650 | PREREF('$'); | |
8990e307 | 3651 | } |
a0d0e21e | 3652 | |
bbce6d69 | 3653 | /* This kludge not intended to be bulletproof. */ |
3280af22 | 3654 | if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) { |
bbce6d69 | 3655 | yylval.opval = newSVOP(OP_CONST, 0, |
b448e4fe | 3656 | newSViv(PL_compiling.cop_arybase)); |
bbce6d69 | 3657 | yylval.opval->op_private = OPpCONST_ARYBASE; |
3658 | TERM(THING); | |
3659 | } | |
3660 | ||
ff68c719 | 3661 | d = s; |
69d2bceb | 3662 | tmp = (I32)*s; |
3280af22 | 3663 | if (PL_lex_state == LEX_NORMAL) |
ff68c719 | 3664 | s = skipspace(s); |
3665 | ||
3280af22 | 3666 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) { |
bbce6d69 | 3667 | char *t; |
3668 | if (*s == '[') { | |
3280af22 | 3669 | PL_tokenbuf[0] = '@'; |
599cee73 | 3670 | if (ckWARN(WARN_SYNTAX)) { |
bbce6d69 | 3671 | for(t = s + 1; |
7e2040f0 | 3672 | isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$'; |
bbce6d69 | 3673 | t++) ; |
a0d0e21e | 3674 | if (*t++ == ',') { |
3280af22 NIS |
3675 | PL_bufptr = skipspace(PL_bufptr); |
3676 | while (t < PL_bufend && *t != ']') | |
bbce6d69 | 3677 | t++; |
9014280d | 3678 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
599cee73 PM |
3679 | "Multidimensional syntax %.*s not supported", |
3680 | (t - PL_bufptr) + 1, PL_bufptr); | |
a0d0e21e LW |
3681 | } |
3682 | } | |
bbce6d69 | 3683 | } |
3684 | else if (*s == '{') { | |
3280af22 | 3685 | PL_tokenbuf[0] = '%'; |
599cee73 | 3686 | if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") && |
bbce6d69 | 3687 | (t = strchr(s, '}')) && (t = strchr(t, '='))) |
3688 | { | |
3280af22 | 3689 | char tmpbuf[sizeof PL_tokenbuf]; |
a0d0e21e LW |
3690 | STRLEN len; |
3691 | for (t++; isSPACE(*t); t++) ; | |
7e2040f0 | 3692 | if (isIDFIRST_lazy_if(t,UTF)) { |
8903cb82 | 3693 | t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len); |
59a6d928 | 3694 | for (; isSPACE(*t); t++) ; |
864dbfa3 | 3695 | if (*t == ';' && get_cv(tmpbuf, FALSE)) |
9014280d | 3696 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
599cee73 | 3697 | "You need to quote \"%s\"", tmpbuf); |
748a9306 | 3698 | } |
93a17b20 LW |
3699 | } |
3700 | } | |
2f3197b3 | 3701 | } |
bbce6d69 | 3702 | |
3280af22 | 3703 | PL_expect = XOPERATOR; |
69d2bceb | 3704 | if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) { |
3280af22 NIS |
3705 | bool islop = (PL_last_lop == PL_oldoldbufptr); |
3706 | if (!islop || PL_last_lop_op == OP_GREPSTART) | |
3707 | PL_expect = XOPERATOR; | |
bbce6d69 | 3708 | else if (strchr("$@\"'`q", *s)) |
3280af22 | 3709 | PL_expect = XTERM; /* e.g. print $fh "foo" */ |
7e2040f0 | 3710 | else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF)) |
3280af22 | 3711 | PL_expect = XTERM; /* e.g. print $fh &sub */ |
7e2040f0 | 3712 | else if (isIDFIRST_lazy_if(s,UTF)) { |
3280af22 | 3713 | char tmpbuf[sizeof PL_tokenbuf]; |
8903cb82 | 3714 | scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
155aba94 | 3715 | if ((tmp = keyword(tmpbuf, len))) { |
84902520 TB |
3716 | /* binary operators exclude handle interpretations */ |
3717 | switch (tmp) { | |
3718 | case -KEY_x: | |
3719 | case -KEY_eq: | |
3720 | case -KEY_ne: | |
3721 | case -KEY_gt: | |
3722 | case -KEY_lt: | |
3723 | case -KEY_ge: | |
3724 | case -KEY_le: | |
3725 | case -KEY_cmp: | |
3726 | break; | |
3727 | default: | |
3280af22 | 3728 | PL_expect = XTERM; /* e.g. print $fh length() */ |
84902520 TB |
3729 | break; |
3730 | } | |
3731 | } | |
68dc0745 | 3732 | else { |
8a8635f0 | 3733 | PL_expect = XTERM; /* e.g. print $fh subr() */ |
93a17b20 | 3734 | } |
93a17b20 | 3735 | } |
bbce6d69 | 3736 | else if (isDIGIT(*s)) |
3280af22 | 3737 | PL_expect = XTERM; /* e.g. print $fh 3 */ |
bbce6d69 | 3738 | else if (*s == '.' && isDIGIT(s[1])) |
3280af22 | 3739 | PL_expect = XTERM; /* e.g. print $fh .3 */ |
3792a11b NC |
3740 | else if ((*s == '?' || *s == '-' || *s == '+') |
3741 | && !isSPACE(s[1]) && s[1] != '=') | |
c963b151 | 3742 | PL_expect = XTERM; /* e.g. print $fh -1 */ |
7ce6e6b9 RGS |
3743 | else if (*s == '/' && !isSPACE(s[1]) && s[1] != '=' && s[1] != '/') |
3744 | PL_expect = XTERM; /* e.g. print $fh /.../ | |
3745 | XXX except DORDOR operator */ | |
e0587a03 | 3746 | else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=') |
3280af22 | 3747 | PL_expect = XTERM; /* print $fh <<"EOF" */ |
bbce6d69 | 3748 | } |
3280af22 | 3749 | PL_pending_ident = '$'; |
79072805 | 3750 | TOKEN('$'); |
378cc40b LW |
3751 | |
3752 | case '@': | |
3280af22 | 3753 | if (PL_expect == XOPERATOR) |
bbce6d69 | 3754 | no_op("Array", s); |
3280af22 NIS |
3755 | PL_tokenbuf[0] = '@'; |
3756 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE); | |
3757 | if (!PL_tokenbuf[1]) { | |
bbce6d69 | 3758 | PREREF('@'); |
3759 | } | |
3280af22 | 3760 | if (PL_lex_state == LEX_NORMAL) |
ff68c719 | 3761 | s = skipspace(s); |
3280af22 | 3762 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) { |
bbce6d69 | 3763 | if (*s == '{') |
3280af22 | 3764 | PL_tokenbuf[0] = '%'; |
a0d0e21e LW |
3765 | |
3766 | /* Warn about @ where they meant $. */ | |
599cee73 | 3767 | if (ckWARN(WARN_SYNTAX)) { |
a0d0e21e LW |
3768 | if (*s == '[' || *s == '{') { |
3769 | char *t = s + 1; | |
7e2040f0 | 3770 | while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t))) |
a0d0e21e LW |
3771 | t++; |
3772 | if (*t == '}' || *t == ']') { | |
3773 | t++; | |
3280af22 | 3774 | PL_bufptr = skipspace(PL_bufptr); |
9014280d | 3775 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
599cee73 | 3776 | "Scalar value %.*s better written as $%.*s", |
3280af22 | 3777 | t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1); |
a0d0e21e | 3778 | } |
93a17b20 LW |
3779 | } |
3780 | } | |
463ee0b2 | 3781 | } |
3280af22 | 3782 | PL_pending_ident = '@'; |
79072805 | 3783 | TERM('@'); |
378cc40b | 3784 | |
c963b151 | 3785 | case '/': /* may be division, defined-or, or pattern */ |
6f33ba73 RGS |
3786 | if (PL_expect == XTERMORDORDOR && s[1] == '/') { |
3787 | s += 2; | |
3788 | AOPERATOR(DORDOR); | |
3789 | } | |
c963b151 BD |
3790 | case '?': /* may either be conditional or pattern */ |
3791 | if(PL_expect == XOPERATOR) { | |
3792 | tmp = *s++; | |
3793 | if(tmp == '?') { | |
3794 | OPERATOR('?'); | |
3795 | } | |
3796 | else { | |
3797 | tmp = *s++; | |
3798 | if(tmp == '/') { | |
3799 | /* A // operator. */ | |
3800 | AOPERATOR(DORDOR); | |
3801 | } | |
3802 | else { | |
3803 | s--; | |
3804 | Mop(OP_DIVIDE); | |
3805 | } | |
3806 | } | |
3807 | } | |
3808 | else { | |
3809 | /* Disable warning on "study /blah/" */ | |
3810 | if (PL_oldoldbufptr == PL_last_uni | |
3811 | && (*PL_last_uni != 's' || s - PL_last_uni < 5 | |
3812 | || memNE(PL_last_uni, "study", 5) | |
3813 | || isALNUM_lazy_if(PL_last_uni+5,UTF) | |
3814 | )) | |
3815 | check_uni(); | |
3816 | s = scan_pat(s,OP_MATCH); | |
3817 | TERM(sublex_start()); | |
3818 | } | |
378cc40b LW |
3819 | |
3820 | case '.': | |
51882d45 GS |
3821 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack |
3822 | #ifdef PERL_STRICT_CR | |
3823 | && s[1] == '\n' | |
3824 | #else | |
3825 | && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n')) | |
3826 | #endif | |
3827 | && (s == PL_linestart || s[-1] == '\n') ) | |
3828 | { | |
3280af22 NIS |
3829 | PL_lex_formbrack = 0; |
3830 | PL_expect = XSTATE; | |
79072805 LW |
3831 | goto rightbracket; |
3832 | } | |
3280af22 | 3833 | if (PL_expect == XOPERATOR || !isDIGIT(s[1])) { |
378cc40b | 3834 | tmp = *s++; |
a687059c LW |
3835 | if (*s == tmp) { |
3836 | s++; | |
2f3197b3 LW |
3837 | if (*s == tmp) { |
3838 | s++; | |
79072805 | 3839 | yylval.ival = OPf_SPECIAL; |
2f3197b3 LW |
3840 | } |
3841 | else | |
79072805 | 3842 | yylval.ival = 0; |
378cc40b | 3843 | OPERATOR(DOTDOT); |
a687059c | 3844 | } |
3280af22 | 3845 | if (PL_expect != XOPERATOR) |
2f3197b3 | 3846 | check_uni(); |
79072805 | 3847 | Aop(OP_CONCAT); |
378cc40b LW |
3848 | } |
3849 | /* FALL THROUGH */ | |
3850 | case '0': case '1': case '2': case '3': case '4': | |
3851 | case '5': case '6': case '7': case '8': case '9': | |
b73d6f50 | 3852 | s = scan_num(s, &yylval); |
4e553d73 | 3853 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
607df283 | 3854 | "### Saw number in '%s'\n", s); |
5f80b19c | 3855 | } ); |
3280af22 | 3856 | if (PL_expect == XOPERATOR) |
8990e307 | 3857 | no_op("Number",s); |
79072805 LW |
3858 | TERM(THING); |
3859 | ||
3860 | case '\'': | |
09bef843 | 3861 | s = scan_str(s,FALSE,FALSE); |
4e553d73 | 3862 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
207e3d1a | 3863 | "### Saw string before '%s'\n", s); |
5f80b19c | 3864 | } ); |
3280af22 NIS |
3865 | if (PL_expect == XOPERATOR) { |
3866 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3867 | PL_expect = XTERM; | |
a0d0e21e | 3868 | depcom(); |
bbf60fe6 | 3869 | return REPORT(','); /* grandfather non-comma-format format */ |
a0d0e21e | 3870 | } |
463ee0b2 | 3871 | else |
8990e307 | 3872 | no_op("String",s); |
463ee0b2 | 3873 | } |
79072805 | 3874 | if (!s) |
85e6fe83 | 3875 | missingterm((char*)0); |
79072805 LW |
3876 | yylval.ival = OP_CONST; |
3877 | TERM(sublex_start()); | |
3878 | ||
3879 | case '"': | |
09bef843 | 3880 | s = scan_str(s,FALSE,FALSE); |
4e553d73 | 3881 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
207e3d1a | 3882 | "### Saw string before '%s'\n", s); |
5f80b19c | 3883 | } ); |
3280af22 NIS |
3884 | if (PL_expect == XOPERATOR) { |
3885 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3886 | PL_expect = XTERM; | |
a0d0e21e | 3887 | depcom(); |
bbf60fe6 | 3888 | return REPORT(','); /* grandfather non-comma-format format */ |
a0d0e21e | 3889 | } |
463ee0b2 | 3890 | else |
8990e307 | 3891 | no_op("String",s); |
463ee0b2 | 3892 | } |
79072805 | 3893 | if (!s) |
85e6fe83 | 3894 | missingterm((char*)0); |
4633a7c4 | 3895 | yylval.ival = OP_CONST; |
3280af22 | 3896 | for (d = SvPV(PL_lex_stuff, len); len; len--, d++) { |
63cd0674 | 3897 | if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) { |
4633a7c4 LW |
3898 | yylval.ival = OP_STRINGIFY; |
3899 | break; | |
3900 | } | |
3901 | } | |
79072805 LW |
3902 | TERM(sublex_start()); |
3903 | ||
3904 | case '`': | |
09bef843 | 3905 | s = scan_str(s,FALSE,FALSE); |
4e553d73 | 3906 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
207e3d1a | 3907 | "### Saw backtick string before '%s'\n", s); |
5f80b19c | 3908 | } ); |
3280af22 | 3909 | if (PL_expect == XOPERATOR) |
8990e307 | 3910 | no_op("Backticks",s); |
79072805 | 3911 | if (!s) |
85e6fe83 | 3912 | missingterm((char*)0); |
79072805 LW |
3913 | yylval.ival = OP_BACKTICK; |
3914 | set_csh(); | |
3915 | TERM(sublex_start()); | |
3916 | ||
3917 | case '\\': | |
3918 | s++; | |
599cee73 | 3919 | if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s)) |
9014280d | 3920 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression", |
599cee73 | 3921 | *s, *s); |
3280af22 | 3922 | if (PL_expect == XOPERATOR) |
8990e307 | 3923 | no_op("Backslash",s); |
79072805 LW |
3924 | OPERATOR(REFGEN); |
3925 | ||
a7cb1f99 | 3926 | case 'v': |
e526c9e6 | 3927 | if (isDIGIT(s[1]) && PL_expect != XOPERATOR) { |
a7cb1f99 GS |
3928 | char *start = s; |
3929 | start++; | |
3930 | start++; | |
dd629d5b | 3931 | while (isDIGIT(*start) || *start == '_') |
a7cb1f99 GS |
3932 | start++; |
3933 | if (*start == '.' && isDIGIT(start[1])) { | |
b73d6f50 | 3934 | s = scan_num(s, &yylval); |
a7cb1f99 GS |
3935 | TERM(THING); |
3936 | } | |
e526c9e6 | 3937 | /* avoid v123abc() or $h{v1}, allow C<print v10;> */ |
6f33ba73 RGS |
3938 | else if (!isALPHA(*start) && (PL_expect == XTERM |
3939 | || PL_expect == XREF || PL_expect == XSTATE | |
3940 | || PL_expect == XTERMORDORDOR)) { | |
e526c9e6 GS |
3941 | char c = *start; |
3942 | GV *gv; | |
3943 | *start = '\0'; | |
3944 | gv = gv_fetchpv(s, FALSE, SVt_PVCV); | |
3945 | *start = c; | |
3946 | if (!gv) { | |
b73d6f50 | 3947 | s = scan_num(s, &yylval); |
e526c9e6 GS |
3948 | TERM(THING); |
3949 | } | |
3950 | } | |
a7cb1f99 GS |
3951 | } |
3952 | goto keylookup; | |
79072805 | 3953 | case 'x': |
3280af22 | 3954 | if (isDIGIT(s[1]) && PL_expect == XOPERATOR) { |
79072805 LW |
3955 | s++; |
3956 | Mop(OP_REPEAT); | |
2f3197b3 | 3957 | } |
79072805 LW |
3958 | goto keylookup; |
3959 | ||
378cc40b | 3960 | case '_': |
79072805 LW |
3961 | case 'a': case 'A': |
3962 | case 'b': case 'B': | |
3963 | case 'c': case 'C': | |
3964 | case 'd': case 'D': | |
3965 | case 'e': case 'E': | |
3966 | case 'f': case 'F': | |
3967 | case 'g': case 'G': | |
3968 | case 'h': case 'H': | |
3969 | case 'i': case 'I': | |
3970 | case 'j': case 'J': | |
3971 | case 'k': case 'K': | |
3972 | case 'l': case 'L': | |
3973 | case 'm': case 'M': | |
3974 | case 'n': case 'N': | |
3975 | case 'o': case 'O': | |
3976 | case 'p': case 'P': | |
3977 | case 'q': case 'Q': | |
3978 | case 'r': case 'R': | |
3979 | case 's': case 'S': | |
3980 | case 't': case 'T': | |
3981 | case 'u': case 'U': | |
a7cb1f99 | 3982 | case 'V': |
79072805 LW |
3983 | case 'w': case 'W': |
3984 | case 'X': | |
3985 | case 'y': case 'Y': | |
3986 | case 'z': case 'Z': | |
3987 | ||
49dc05e3 | 3988 | keylookup: { |
1d239bbb | 3989 | orig_keyword = 0; |
161b471a NIS |
3990 | gv = Nullgv; |
3991 | gvp = 0; | |
49dc05e3 | 3992 | |
3280af22 NIS |
3993 | PL_bufptr = s; |
3994 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); | |
8ebc5c01 | 3995 | |
3996 | /* Some keywords can be followed by any delimiter, including ':' */ | |
155aba94 GS |
3997 | tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) || |
3998 | (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') || | |
3999 | (PL_tokenbuf[0] == 'q' && | |
4000 | strchr("qwxr", PL_tokenbuf[1]))))); | |
8ebc5c01 | 4001 | |
4002 | /* x::* is just a word, unless x is "CORE" */ | |
3280af22 | 4003 | if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE")) |
4633a7c4 LW |
4004 | goto just_a_word; |
4005 | ||
3643fb5f | 4006 | d = s; |
3280af22 | 4007 | while (d < PL_bufend && isSPACE(*d)) |
3643fb5f CS |
4008 | d++; /* no comments skipped here, or s### is misparsed */ |
4009 | ||
4010 | /* Is this a label? */ | |
3280af22 NIS |
4011 | if (!tmp && PL_expect == XSTATE |
4012 | && d < PL_bufend && *d == ':' && *(d + 1) != ':') { | |
8ebc5c01 | 4013 | s = d + 1; |
3280af22 | 4014 | yylval.pval = savepv(PL_tokenbuf); |
8ebc5c01 | 4015 | CLINE; |
4016 | TOKEN(LABEL); | |
3643fb5f CS |
4017 | } |
4018 | ||
4019 | /* Check for keywords */ | |
3280af22 | 4020 | tmp = keyword(PL_tokenbuf, len); |
748a9306 LW |
4021 | |
4022 | /* Is this a word before a => operator? */ | |
1c3923b3 | 4023 | if (*d == '=' && d[1] == '>') { |
748a9306 | 4024 | CLINE; |
d0a148a6 NC |
4025 | yylval.opval |
4026 | = (OP*)newSVOP(OP_CONST, 0, | |
4027 | S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len)); | |
748a9306 LW |
4028 | yylval.opval->op_private = OPpCONST_BARE; |
4029 | TERM(WORD); | |
4030 | } | |
4031 | ||
a0d0e21e | 4032 | if (tmp < 0) { /* second-class keyword? */ |
56f7f34b CS |
4033 | GV *ogv = Nullgv; /* override (winner) */ |
4034 | GV *hgv = Nullgv; /* hidden (loser) */ | |
3280af22 | 4035 | if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) { |
56f7f34b | 4036 | CV *cv; |
3280af22 | 4037 | if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) && |
56f7f34b CS |
4038 | (cv = GvCVu(gv))) |
4039 | { | |
4040 | if (GvIMPORTED_CV(gv)) | |
4041 | ogv = gv; | |
4042 | else if (! CvMETHOD(cv)) | |
4043 | hgv = gv; | |
4044 | } | |
4045 | if (!ogv && | |
3280af22 NIS |
4046 | (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) && |
4047 | (gv = *gvp) != (GV*)&PL_sv_undef && | |
56f7f34b CS |
4048 | GvCVu(gv) && GvIMPORTED_CV(gv)) |
4049 | { | |
4050 | ogv = gv; | |
4051 | } | |
4052 | } | |
4053 | if (ogv) { | |
30fe34ed | 4054 | orig_keyword = tmp; |
56f7f34b | 4055 | tmp = 0; /* overridden by import or by GLOBAL */ |
6e7b2336 GS |
4056 | } |
4057 | else if (gv && !gvp | |
4058 | && -tmp==KEY_lock /* XXX generalizable kludge */ | |
d0456cad | 4059 | && GvCVu(gv) |
3280af22 | 4060 | && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE)) |
6e7b2336 GS |
4061 | { |
4062 | tmp = 0; /* any sub overrides "weak" keyword */ | |
a0d0e21e | 4063 | } |
7fc307b5 RGS |
4064 | else if (gv && !gvp |
4065 | && tmp == -KEY_err | |
4066 | && GvCVu(gv) | |
4067 | && PL_expect != XOPERATOR | |
4068 | && PL_expect != XTERMORDORDOR) | |
4069 | { | |
4070 | /* any sub overrides the "err" keyword, except when really an | |
4071 | * operator is expected */ | |
4072 | tmp = 0; | |
4073 | } | |
56f7f34b CS |
4074 | else { /* no override */ |
4075 | tmp = -tmp; | |
ac206dc8 | 4076 | if (tmp == KEY_dump && ckWARN(WARN_MISC)) { |
9014280d | 4077 | Perl_warner(aTHX_ packWARN(WARN_MISC), |
ac206dc8 RGS |
4078 | "dump() better written as CORE::dump()"); |
4079 | } | |
56f7f34b CS |
4080 | gv = Nullgv; |
4081 | gvp = 0; | |
4944e2f7 GS |
4082 | if (ckWARN(WARN_AMBIGUOUS) && hgv |
4083 | && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */ | |
9014280d | 4084 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
599cee73 | 4085 | "Ambiguous call resolved as CORE::%s(), %s", |
2f3ca594 | 4086 | GvENAME(hgv), "qualify as such or use &"); |
49dc05e3 | 4087 | } |
a0d0e21e LW |
4088 | } |
4089 | ||
4090 | reserved_word: | |
4091 | switch (tmp) { | |
79072805 LW |
4092 | |
4093 | default: /* not a keyword */ | |
93a17b20 | 4094 | just_a_word: { |
96e4d5b1 | 4095 | SV *sv; |
ce29ac45 | 4096 | int pkgname = 0; |
3280af22 | 4097 | char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]); |
8990e307 LW |
4098 | |
4099 | /* Get the rest if it looks like a package qualifier */ | |
4100 | ||
155aba94 | 4101 | if (*s == '\'' || (*s == ':' && s[1] == ':')) { |
c3e0f903 | 4102 | STRLEN morelen; |
3280af22 | 4103 | s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len, |
c3e0f903 GS |
4104 | TRUE, &morelen); |
4105 | if (!morelen) | |
cea2e8a9 | 4106 | Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf, |
ec2ab091 | 4107 | *s == '\'' ? "'" : "::"); |
c3e0f903 | 4108 | len += morelen; |
ce29ac45 | 4109 | pkgname = 1; |
a0d0e21e | 4110 | } |
8990e307 | 4111 | |
3280af22 NIS |
4112 | if (PL_expect == XOPERATOR) { |
4113 | if (PL_bufptr == PL_linestart) { | |
57843af0 | 4114 | CopLINE_dec(PL_curcop); |
9014280d | 4115 | Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi); |
57843af0 | 4116 | CopLINE_inc(PL_curcop); |
463ee0b2 LW |
4117 | } |
4118 | else | |
54310121 | 4119 | no_op("Bareword",s); |
463ee0b2 | 4120 | } |
8990e307 | 4121 | |
c3e0f903 GS |
4122 | /* Look for a subroutine with this name in current package, |
4123 | unless name is "Foo::", in which case Foo is a bearword | |
4124 | (and a package name). */ | |
4125 | ||
4126 | if (len > 2 && | |
3280af22 | 4127 | PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':') |
c3e0f903 | 4128 | { |
e476b1b5 | 4129 | if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV)) |
9014280d | 4130 | Perl_warner(aTHX_ packWARN(WARN_BAREWORD), |
599cee73 | 4131 | "Bareword \"%s\" refers to nonexistent package", |
3280af22 | 4132 | PL_tokenbuf); |
c3e0f903 | 4133 | len -= 2; |
3280af22 | 4134 | PL_tokenbuf[len] = '\0'; |
c3e0f903 GS |
4135 | gv = Nullgv; |
4136 | gvp = 0; | |
4137 | } | |
4138 | else { | |
4139 | len = 0; | |
4140 | if (!gv) | |
3280af22 | 4141 | gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV); |
c3e0f903 GS |
4142 | } |
4143 | ||
4144 | /* if we saw a global override before, get the right name */ | |
8990e307 | 4145 | |
49dc05e3 | 4146 | if (gvp) { |
79cb57f6 | 4147 | sv = newSVpvn("CORE::GLOBAL::",14); |
3280af22 | 4148 | sv_catpv(sv,PL_tokenbuf); |
49dc05e3 | 4149 | } |
8a7a129d NC |
4150 | else { |
4151 | /* If len is 0, newSVpv does strlen(), which is correct. | |
4152 | If len is non-zero, then it will be the true length, | |
4153 | and so the scalar will be created correctly. */ | |
4154 | sv = newSVpv(PL_tokenbuf,len); | |
4155 | } | |
8990e307 | 4156 | |
a0d0e21e LW |
4157 | /* Presume this is going to be a bareword of some sort. */ |
4158 | ||
4159 | CLINE; | |
49dc05e3 | 4160 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
a0d0e21e | 4161 | yylval.opval->op_private = OPpCONST_BARE; |
8f8cf39c JH |
4162 | /* UTF-8 package name? */ |
4163 | if (UTF && !IN_BYTES && | |
4164 | is_utf8_string((U8*)SvPVX(sv), SvCUR(sv))) | |
4165 | SvUTF8_on(sv); | |
a0d0e21e | 4166 | |
c3e0f903 GS |
4167 | /* And if "Foo::", then that's what it certainly is. */ |
4168 | ||
4169 | if (len) | |
4170 | goto safe_bareword; | |
4171 | ||
8990e307 LW |
4172 | /* See if it's the indirect object for a list operator. */ |
4173 | ||
3280af22 NIS |
4174 | if (PL_oldoldbufptr && |
4175 | PL_oldoldbufptr < PL_bufptr && | |
65cec589 GS |
4176 | (PL_oldoldbufptr == PL_last_lop |
4177 | || PL_oldoldbufptr == PL_last_uni) && | |
a0d0e21e | 4178 | /* NO SKIPSPACE BEFORE HERE! */ |
a9ef352a GS |
4179 | (PL_expect == XREF || |
4180 | ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF)) | |
a0d0e21e | 4181 | { |
748a9306 LW |
4182 | bool immediate_paren = *s == '('; |
4183 | ||
a0d0e21e LW |
4184 | /* (Now we can afford to cross potential line boundary.) */ |
4185 | s = skipspace(s); | |
4186 | ||
4187 | /* Two barewords in a row may indicate method call. */ | |
4188 | ||
7e2040f0 | 4189 | if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv))) |
bbf60fe6 | 4190 | return REPORT(tmp); |
a0d0e21e LW |
4191 | |
4192 | /* If not a declared subroutine, it's an indirect object. */ | |
4193 | /* (But it's an indir obj regardless for sort.) */ | |
4194 | ||
7948272d | 4195 | if ( !immediate_paren && (PL_last_lop_op == OP_SORT || |
f0670693 | 4196 | ((!gv || !GvCVu(gv)) && |
a9ef352a | 4197 | (PL_last_lop_op != OP_MAPSTART && |
f0670693 | 4198 | PL_last_lop_op != OP_GREPSTART)))) |
a9ef352a | 4199 | { |
3280af22 | 4200 | PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR; |
748a9306 | 4201 | goto bareword; |
93a17b20 LW |
4202 | } |
4203 | } | |
8990e307 | 4204 | |
3280af22 | 4205 | PL_expect = XOPERATOR; |
8990e307 | 4206 | s = skipspace(s); |
1c3923b3 GS |
4207 | |
4208 | /* Is this a word before a => operator? */ | |
ce29ac45 | 4209 | if (*s == '=' && s[1] == '>' && !pkgname) { |
1c3923b3 GS |
4210 | CLINE; |
4211 | sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf); | |
0064a8a9 | 4212 | if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len)) |
7948272d | 4213 | SvUTF8_on(((SVOP*)yylval.opval)->op_sv); |
1c3923b3 GS |
4214 | TERM(WORD); |
4215 | } | |
4216 | ||
4217 | /* If followed by a paren, it's certainly a subroutine. */ | |
93a17b20 | 4218 | if (*s == '(') { |
79072805 | 4219 | CLINE; |
96e4d5b1 | 4220 | if (gv && GvCVu(gv)) { |
bf4acbe4 | 4221 | for (d = s + 1; SPACE_OR_TAB(*d); d++) ; |
7a52d87a | 4222 | if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) { |
96e4d5b1 | 4223 | s = d + 1; |
4224 | goto its_constant; | |
4225 | } | |
4226 | } | |
3280af22 NIS |
4227 | PL_nextval[PL_nexttoke].opval = yylval.opval; |
4228 | PL_expect = XOPERATOR; | |
93a17b20 | 4229 | force_next(WORD); |
c07a80fd | 4230 | yylval.ival = 0; |
463ee0b2 | 4231 | TOKEN('&'); |
79072805 | 4232 | } |
93a17b20 | 4233 | |
a0d0e21e | 4234 | /* If followed by var or block, call it a method (unless sub) */ |
8990e307 | 4235 | |
8ebc5c01 | 4236 | if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) { |
3280af22 NIS |
4237 | PL_last_lop = PL_oldbufptr; |
4238 | PL_last_lop_op = OP_METHOD; | |
93a17b20 | 4239 | PREBLOCK(METHOD); |
463ee0b2 LW |
4240 | } |
4241 | ||
8990e307 LW |
4242 | /* If followed by a bareword, see if it looks like indir obj. */ |
4243 | ||
30fe34ed RGS |
4244 | if (!orig_keyword |
4245 | && (isIDFIRST_lazy_if(s,UTF) || *s == '$') | |
4246 | && (tmp = intuit_method(s,gv))) | |
bbf60fe6 | 4247 | return REPORT(tmp); |
93a17b20 | 4248 | |
8990e307 LW |
4249 | /* Not a method, so call it a subroutine (if defined) */ |
4250 | ||
8ebc5c01 | 4251 | if (gv && GvCVu(gv)) { |
46fc3d4c | 4252 | CV* cv; |
0453d815 | 4253 | if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS)) |
9014280d | 4254 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
0453d815 | 4255 | "Ambiguous use of -%s resolved as -&%s()", |
3280af22 | 4256 | PL_tokenbuf, PL_tokenbuf); |
89bfa8cd | 4257 | /* Check for a constant sub */ |
46fc3d4c | 4258 | cv = GvCV(gv); |
96e4d5b1 | 4259 | if ((sv = cv_const_sv(cv))) { |
4260 | its_constant: | |
4261 | SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv); | |
4262 | ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv); | |
4263 | yylval.opval->op_private = 0; | |
4264 | TOKEN(WORD); | |
89bfa8cd | 4265 | } |
4266 | ||
a5f75d66 AD |
4267 | /* Resolve to GV now. */ |
4268 | op_free(yylval.opval); | |
4269 | yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv)); | |
9675f7ac | 4270 | yylval.opval->op_private |= OPpENTERSUB_NOPAREN; |
7a52d87a | 4271 | PL_last_lop = PL_oldbufptr; |
bf848113 | 4272 | PL_last_lop_op = OP_ENTERSUB; |
4633a7c4 LW |
4273 | /* Is there a prototype? */ |
4274 | if (SvPOK(cv)) { | |
4275 | STRLEN len; | |
7a52d87a | 4276 | char *proto = SvPV((SV*)cv, len); |
4633a7c4 LW |
4277 | if (!len) |
4278 | TERM(FUNC0SUB); | |
770526c1 | 4279 | if (*proto == '$' && proto[1] == '\0') |
4633a7c4 | 4280 | OPERATOR(UNIOPSUB); |
0f5d0394 AE |
4281 | while (*proto == ';') |
4282 | proto++; | |
7a52d87a | 4283 | if (*proto == '&' && *s == '{') { |
bfed75c6 | 4284 | sv_setpv(PL_subname, PL_curstash ? |
c99da370 | 4285 | "__ANON__" : "__ANON__::__ANON__"); |
4633a7c4 LW |
4286 | PREBLOCK(LSTOPSUB); |
4287 | } | |
a9ef352a | 4288 | } |
3280af22 NIS |
4289 | PL_nextval[PL_nexttoke].opval = yylval.opval; |
4290 | PL_expect = XTERM; | |
8990e307 LW |
4291 | force_next(WORD); |
4292 | TOKEN(NOAMP); | |
4293 | } | |
748a9306 | 4294 | |
8990e307 LW |
4295 | /* Call it a bare word */ |
4296 | ||
5603f27d GS |
4297 | if (PL_hints & HINT_STRICT_SUBS) |
4298 | yylval.opval->op_private |= OPpCONST_STRICT; | |
4299 | else { | |
4300 | bareword: | |
4301 | if (ckWARN(WARN_RESERVED)) { | |
4302 | if (lastchar != '-') { | |
4303 | for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ; | |
238ae712 | 4304 | if (!*d && !gv_stashpv(PL_tokenbuf,FALSE)) |
9014280d | 4305 | Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved, |
5603f27d GS |
4306 | PL_tokenbuf); |
4307 | } | |
748a9306 LW |
4308 | } |
4309 | } | |
c3e0f903 GS |
4310 | |
4311 | safe_bareword: | |
3792a11b NC |
4312 | if ((lastchar == '*' || lastchar == '%' || lastchar == '&') |
4313 | && ckWARN_d(WARN_AMBIGUOUS)) { | |
9014280d | 4314 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
0453d815 | 4315 | "Operator or semicolon missing before %c%s", |
3280af22 | 4316 | lastchar, PL_tokenbuf); |
9014280d | 4317 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
0453d815 | 4318 | "Ambiguous use of %c resolved as operator %c", |
748a9306 LW |
4319 | lastchar, lastchar); |
4320 | } | |
93a17b20 | 4321 | TOKEN(WORD); |
79072805 | 4322 | } |
79072805 | 4323 | |
68dc0745 | 4324 | case KEY___FILE__: |
46fc3d4c | 4325 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
ed094faf | 4326 | newSVpv(CopFILE(PL_curcop),0)); |
46fc3d4c | 4327 | TERM(THING); |
4328 | ||
79072805 | 4329 | case KEY___LINE__: |
cf2093f6 | 4330 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
57843af0 | 4331 | Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop))); |
79072805 | 4332 | TERM(THING); |
68dc0745 | 4333 | |
4334 | case KEY___PACKAGE__: | |
4335 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, | |
3280af22 | 4336 | (PL_curstash |
9508c957 | 4337 | ? newSVpv(HvNAME(PL_curstash), 0) |
3280af22 | 4338 | : &PL_sv_undef)); |
79072805 | 4339 | TERM(THING); |
79072805 | 4340 | |
e50aee73 | 4341 | case KEY___DATA__: |
79072805 LW |
4342 | case KEY___END__: { |
4343 | GV *gv; | |
79072805 LW |
4344 | |
4345 | /*SUPPRESS 560*/ | |
3280af22 | 4346 | if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) { |
bfed75c6 | 4347 | const char *pname = "main"; |
3280af22 NIS |
4348 | if (PL_tokenbuf[2] == 'D') |
4349 | pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash); | |
cea2e8a9 | 4350 | gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO); |
a5f75d66 | 4351 | GvMULTI_on(gv); |
79072805 | 4352 | if (!GvIO(gv)) |
a0d0e21e | 4353 | GvIOp(gv) = newIO(); |
3280af22 | 4354 | IoIFP(GvIOp(gv)) = PL_rsfp; |
a0d0e21e LW |
4355 | #if defined(HAS_FCNTL) && defined(F_SETFD) |
4356 | { | |
3280af22 | 4357 | int fd = PerlIO_fileno(PL_rsfp); |
a0d0e21e LW |
4358 | fcntl(fd,F_SETFD,fd >= 3); |
4359 | } | |
79072805 | 4360 | #endif |
fd049845 | 4361 | /* Mark this internal pseudo-handle as clean */ |
4362 | IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT; | |
3280af22 | 4363 | if (PL_preprocess) |
50952442 | 4364 | IoTYPE(GvIOp(gv)) = IoTYPE_PIPE; |
3280af22 | 4365 | else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) |
50952442 | 4366 | IoTYPE(GvIOp(gv)) = IoTYPE_STD; |
79072805 | 4367 | else |
50952442 | 4368 | IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY; |
c39cd008 GS |
4369 | #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS) |
4370 | /* if the script was opened in binmode, we need to revert | |
53129d29 | 4371 | * it to text mode for compatibility; but only iff it has CRs |
c39cd008 | 4372 | * XXX this is a questionable hack at best. */ |
53129d29 GS |
4373 | if (PL_bufend-PL_bufptr > 2 |
4374 | && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r') | |
c39cd008 GS |
4375 | { |
4376 | Off_t loc = 0; | |
50952442 | 4377 | if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) { |
c39cd008 GS |
4378 | loc = PerlIO_tell(PL_rsfp); |
4379 | (void)PerlIO_seek(PL_rsfp, 0L, 0); | |
4380 | } | |
2986a63f JH |
4381 | #ifdef NETWARE |
4382 | if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) { | |
4383 | #else | |
c39cd008 | 4384 | if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) { |
2986a63f | 4385 | #endif /* NETWARE */ |
1143fce0 JH |
4386 | #ifdef PERLIO_IS_STDIO /* really? */ |
4387 | # if defined(__BORLANDC__) | |
cb359b41 JH |
4388 | /* XXX see note in do_binmode() */ |
4389 | ((FILE*)PL_rsfp)->flags &= ~_F_BIN; | |
1143fce0 JH |
4390 | # endif |
4391 | #endif | |
c39cd008 GS |
4392 | if (loc > 0) |
4393 | PerlIO_seek(PL_rsfp, loc, 0); | |
4394 | } | |
4395 | } | |
4396 | #endif | |
7948272d | 4397 | #ifdef PERLIO_LAYERS |
52d2e0f4 JH |
4398 | if (!IN_BYTES) { |
4399 | if (UTF) | |
4400 | PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8"); | |
4401 | else if (PL_encoding) { | |
4402 | SV *name; | |
4403 | dSP; | |
4404 | ENTER; | |
4405 | SAVETMPS; | |
4406 | PUSHMARK(sp); | |
4407 | EXTEND(SP, 1); | |
4408 | XPUSHs(PL_encoding); | |
4409 | PUTBACK; | |
4410 | call_method("name", G_SCALAR); | |
4411 | SPAGAIN; | |
4412 | name = POPs; | |
4413 | PUTBACK; | |
bfed75c6 | 4414 | PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, |
52d2e0f4 JH |
4415 | Perl_form(aTHX_ ":encoding(%"SVf")", |
4416 | name)); | |
4417 | FREETMPS; | |
4418 | LEAVE; | |
4419 | } | |
4420 | } | |
7948272d | 4421 | #endif |
3280af22 | 4422 | PL_rsfp = Nullfp; |
79072805 LW |
4423 | } |
4424 | goto fake_eof; | |
e929a76b | 4425 | } |
de3bb511 | 4426 | |
8990e307 | 4427 | case KEY_AUTOLOAD: |
ed6116ce | 4428 | case KEY_DESTROY: |
79072805 | 4429 | case KEY_BEGIN: |
7d30b5c4 | 4430 | case KEY_CHECK: |
7d07dbc2 | 4431 | case KEY_INIT: |
7d30b5c4 | 4432 | case KEY_END: |
3280af22 NIS |
4433 | if (PL_expect == XSTATE) { |
4434 | s = PL_bufptr; | |
93a17b20 | 4435 | goto really_sub; |
79072805 LW |
4436 | } |
4437 | goto just_a_word; | |
4438 | ||
a0d0e21e LW |
4439 | case KEY_CORE: |
4440 | if (*s == ':' && s[1] == ':') { | |
4441 | s += 2; | |
748a9306 | 4442 | d = s; |
3280af22 | 4443 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
6798c92b GS |
4444 | if (!(tmp = keyword(PL_tokenbuf, len))) |
4445 | Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf); | |
a0d0e21e LW |
4446 | if (tmp < 0) |
4447 | tmp = -tmp; | |
4448 | goto reserved_word; | |
4449 | } | |
4450 | goto just_a_word; | |
4451 | ||
463ee0b2 LW |
4452 | case KEY_abs: |
4453 | UNI(OP_ABS); | |
4454 | ||
79072805 LW |
4455 | case KEY_alarm: |
4456 | UNI(OP_ALARM); | |
4457 | ||
4458 | case KEY_accept: | |
a0d0e21e | 4459 | LOP(OP_ACCEPT,XTERM); |
79072805 | 4460 | |
463ee0b2 LW |
4461 | case KEY_and: |
4462 | OPERATOR(ANDOP); | |
4463 | ||
79072805 | 4464 | case KEY_atan2: |
a0d0e21e | 4465 | LOP(OP_ATAN2,XTERM); |
85e6fe83 | 4466 | |
79072805 | 4467 | case KEY_bind: |
a0d0e21e | 4468 | LOP(OP_BIND,XTERM); |
79072805 LW |
4469 | |
4470 | case KEY_binmode: | |
1c1fc3ea | 4471 | LOP(OP_BINMODE,XTERM); |
79072805 LW |
4472 | |
4473 | case KEY_bless: | |
a0d0e21e | 4474 | LOP(OP_BLESS,XTERM); |
79072805 LW |
4475 | |
4476 | case KEY_chop: | |
4477 | UNI(OP_CHOP); | |
4478 | ||
4479 | case KEY_continue: | |
4480 | PREBLOCK(CONTINUE); | |
4481 | ||
4482 | case KEY_chdir: | |
85e6fe83 | 4483 | (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */ |
79072805 LW |
4484 | UNI(OP_CHDIR); |
4485 | ||
4486 | case KEY_close: | |
4487 | UNI(OP_CLOSE); | |
4488 | ||
4489 | case KEY_closedir: | |
4490 | UNI(OP_CLOSEDIR); | |
4491 | ||
4492 | case KEY_cmp: | |
4493 | Eop(OP_SCMP); | |
4494 | ||
4495 | case KEY_caller: | |
4496 | UNI(OP_CALLER); | |
4497 | ||
4498 | case KEY_crypt: | |
4499 | #ifdef FCRYPT | |
f4c556ac GS |
4500 | if (!PL_cryptseen) { |
4501 | PL_cryptseen = TRUE; | |
de3bb511 | 4502 | init_des(); |
f4c556ac | 4503 | } |
a687059c | 4504 | #endif |
a0d0e21e | 4505 | LOP(OP_CRYPT,XTERM); |
79072805 LW |
4506 | |
4507 | case KEY_chmod: | |
a0d0e21e | 4508 | LOP(OP_CHMOD,XTERM); |
79072805 LW |
4509 | |
4510 | case KEY_chown: | |
a0d0e21e | 4511 | LOP(OP_CHOWN,XTERM); |
79072805 LW |
4512 | |
4513 | case KEY_connect: | |
a0d0e21e | 4514 | LOP(OP_CONNECT,XTERM); |
79072805 | 4515 | |
463ee0b2 LW |
4516 | case KEY_chr: |
4517 | UNI(OP_CHR); | |
4518 | ||
79072805 LW |
4519 | case KEY_cos: |
4520 | UNI(OP_COS); | |
4521 | ||
4522 | case KEY_chroot: | |
4523 | UNI(OP_CHROOT); | |
4524 | ||
4525 | case KEY_do: | |
4526 | s = skipspace(s); | |
4527 | if (*s == '{') | |
a0d0e21e | 4528 | PRETERMBLOCK(DO); |
79072805 | 4529 | if (*s != '\'') |
89c5585f | 4530 | s = force_word(s,WORD,TRUE,TRUE,FALSE); |
378cc40b | 4531 | OPERATOR(DO); |
79072805 LW |
4532 | |
4533 | case KEY_die: | |
3280af22 | 4534 | PL_hints |= HINT_BLOCK_SCOPE; |
a0d0e21e | 4535 | LOP(OP_DIE,XTERM); |
79072805 LW |
4536 | |
4537 | case KEY_defined: | |
4538 | UNI(OP_DEFINED); | |
4539 | ||
4540 | case KEY_delete: | |
a0d0e21e | 4541 | UNI(OP_DELETE); |
79072805 LW |
4542 | |
4543 | case KEY_dbmopen: | |
a0d0e21e LW |
4544 | gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV); |
4545 | LOP(OP_DBMOPEN,XTERM); | |
79072805 LW |
4546 | |
4547 | case KEY_dbmclose: | |
4548 | UNI(OP_DBMCLOSE); | |
4549 | ||
4550 | case KEY_dump: | |
a0d0e21e | 4551 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4552 | LOOPX(OP_DUMP); |
4553 | ||
4554 | case KEY_else: | |
4555 | PREBLOCK(ELSE); | |
4556 | ||
4557 | case KEY_elsif: | |
57843af0 | 4558 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
4559 | OPERATOR(ELSIF); |
4560 | ||
4561 | case KEY_eq: | |
4562 | Eop(OP_SEQ); | |
4563 | ||
a0d0e21e LW |
4564 | case KEY_exists: |
4565 | UNI(OP_EXISTS); | |
4e553d73 | 4566 | |
79072805 LW |
4567 | case KEY_exit: |
4568 | UNI(OP_EXIT); | |
4569 | ||
4570 | case KEY_eval: | |
79072805 | 4571 | s = skipspace(s); |
3280af22 | 4572 | PL_expect = (*s == '{') ? XTERMBLOCK : XTERM; |
463ee0b2 | 4573 | UNIBRACK(OP_ENTEREVAL); |
79072805 LW |
4574 | |
4575 | case KEY_eof: | |
4576 | UNI(OP_EOF); | |
4577 | ||
c963b151 BD |
4578 | case KEY_err: |
4579 | OPERATOR(DOROP); | |
4580 | ||
79072805 LW |
4581 | case KEY_exp: |
4582 | UNI(OP_EXP); | |
4583 | ||
4584 | case KEY_each: | |
4585 | UNI(OP_EACH); | |
4586 | ||
4587 | case KEY_exec: | |
4588 | set_csh(); | |
a0d0e21e | 4589 | LOP(OP_EXEC,XREF); |
79072805 LW |
4590 | |
4591 | case KEY_endhostent: | |
4592 | FUN0(OP_EHOSTENT); | |
4593 | ||
4594 | case KEY_endnetent: | |
4595 | FUN0(OP_ENETENT); | |
4596 | ||
4597 | case KEY_endservent: | |
4598 | FUN0(OP_ESERVENT); | |
4599 | ||
4600 | case KEY_endprotoent: | |
4601 | FUN0(OP_EPROTOENT); | |
4602 | ||
4603 | case KEY_endpwent: | |
4604 | FUN0(OP_EPWENT); | |
4605 | ||
4606 | case KEY_endgrent: | |
4607 | FUN0(OP_EGRENT); | |
4608 | ||
4609 | case KEY_for: | |
4610 | case KEY_foreach: | |
57843af0 | 4611 | yylval.ival = CopLINE(PL_curcop); |
55497cff | 4612 | s = skipspace(s); |
7e2040f0 | 4613 | if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) { |
55497cff | 4614 | char *p = s; |
3280af22 | 4615 | if ((PL_bufend - p) >= 3 && |
55497cff | 4616 | strnEQ(p, "my", 2) && isSPACE(*(p + 2))) |
4617 | p += 2; | |
77ca0c92 LW |
4618 | else if ((PL_bufend - p) >= 4 && |
4619 | strnEQ(p, "our", 3) && isSPACE(*(p + 3))) | |
4620 | p += 3; | |
55497cff | 4621 | p = skipspace(p); |
7e2040f0 | 4622 | if (isIDFIRST_lazy_if(p,UTF)) { |
77ca0c92 LW |
4623 | p = scan_ident(p, PL_bufend, |
4624 | PL_tokenbuf, sizeof PL_tokenbuf, TRUE); | |
4625 | p = skipspace(p); | |
4626 | } | |
4627 | if (*p != '$') | |
cea2e8a9 | 4628 | Perl_croak(aTHX_ "Missing $ on loop variable"); |
55497cff | 4629 | } |
79072805 LW |
4630 | OPERATOR(FOR); |
4631 | ||
4632 | case KEY_formline: | |
a0d0e21e | 4633 | LOP(OP_FORMLINE,XTERM); |
79072805 LW |
4634 | |
4635 | case KEY_fork: | |
4636 | FUN0(OP_FORK); | |
4637 | ||
4638 | case KEY_fcntl: | |
a0d0e21e | 4639 | LOP(OP_FCNTL,XTERM); |
79072805 LW |
4640 | |
4641 | case KEY_fileno: | |
4642 | UNI(OP_FILENO); | |
4643 | ||
4644 | case KEY_flock: | |
a0d0e21e | 4645 | LOP(OP_FLOCK,XTERM); |
79072805 LW |
4646 | |
4647 | case KEY_gt: | |
4648 | Rop(OP_SGT); | |
4649 | ||
4650 | case KEY_ge: | |
4651 | Rop(OP_SGE); | |
4652 | ||
4653 | case KEY_grep: | |
2c38e13d | 4654 | LOP(OP_GREPSTART, XREF); |
79072805 LW |
4655 | |
4656 | case KEY_goto: | |
a0d0e21e | 4657 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4658 | LOOPX(OP_GOTO); |
4659 | ||
4660 | case KEY_gmtime: | |
4661 | UNI(OP_GMTIME); | |
4662 | ||
4663 | case KEY_getc: | |
6f33ba73 | 4664 | UNIDOR(OP_GETC); |
79072805 LW |
4665 | |
4666 | case KEY_getppid: | |
4667 | FUN0(OP_GETPPID); | |
4668 | ||
4669 | case KEY_getpgrp: | |
4670 | UNI(OP_GETPGRP); | |
4671 | ||
4672 | case KEY_getpriority: | |
a0d0e21e | 4673 | LOP(OP_GETPRIORITY,XTERM); |
79072805 LW |
4674 | |
4675 | case KEY_getprotobyname: | |
4676 | UNI(OP_GPBYNAME); | |
4677 | ||
4678 | case KEY_getprotobynumber: | |
a0d0e21e | 4679 | LOP(OP_GPBYNUMBER,XTERM); |
79072805 LW |
4680 | |
4681 | case KEY_getprotoent: | |
4682 | FUN0(OP_GPROTOENT); | |
4683 | ||
4684 | case KEY_getpwent: | |
4685 | FUN0(OP_GPWENT); | |
4686 | ||
4687 | case KEY_getpwnam: | |
ff68c719 | 4688 | UNI(OP_GPWNAM); |
79072805 LW |
4689 | |
4690 | case KEY_getpwuid: | |
ff68c719 | 4691 | UNI(OP_GPWUID); |
79072805 LW |
4692 | |
4693 | case KEY_getpeername: | |
4694 | UNI(OP_GETPEERNAME); | |
4695 | ||
4696 | case KEY_gethostbyname: | |
4697 | UNI(OP_GHBYNAME); | |
4698 | ||
4699 | case KEY_gethostbyaddr: | |
a0d0e21e | 4700 | LOP(OP_GHBYADDR,XTERM); |
79072805 LW |
4701 | |
4702 | case KEY_gethostent: | |
4703 | FUN0(OP_GHOSTENT); | |
4704 | ||
4705 | case KEY_getnetbyname: | |
4706 | UNI(OP_GNBYNAME); | |
4707 | ||
4708 | case KEY_getnetbyaddr: | |
a0d0e21e | 4709 | LOP(OP_GNBYADDR,XTERM); |
79072805 LW |
4710 | |
4711 | case KEY_getnetent: | |
4712 | FUN0(OP_GNETENT); | |
4713 | ||
4714 | case KEY_getservbyname: | |
a0d0e21e | 4715 | LOP(OP_GSBYNAME,XTERM); |
79072805 LW |
4716 | |
4717 | case KEY_getservbyport: | |
a0d0e21e | 4718 | LOP(OP_GSBYPORT,XTERM); |
79072805 LW |
4719 | |
4720 | case KEY_getservent: | |
4721 | FUN0(OP_GSERVENT); | |
4722 | ||
4723 | case KEY_getsockname: | |
4724 | UNI(OP_GETSOCKNAME); | |
4725 | ||
4726 | case KEY_getsockopt: | |
a0d0e21e | 4727 | LOP(OP_GSOCKOPT,XTERM); |
79072805 LW |
4728 | |
4729 | case KEY_getgrent: | |
4730 | FUN0(OP_GGRENT); | |
4731 | ||
4732 | case KEY_getgrnam: | |
ff68c719 | 4733 | UNI(OP_GGRNAM); |
79072805 LW |
4734 | |
4735 | case KEY_getgrgid: | |
ff68c719 | 4736 | UNI(OP_GGRGID); |
79072805 LW |
4737 | |
4738 | case KEY_getlogin: | |
4739 | FUN0(OP_GETLOGIN); | |
4740 | ||
93a17b20 | 4741 | case KEY_glob: |
a0d0e21e LW |
4742 | set_csh(); |
4743 | LOP(OP_GLOB,XTERM); | |
93a17b20 | 4744 | |
79072805 LW |
4745 | case KEY_hex: |
4746 | UNI(OP_HEX); | |
4747 | ||
4748 | case KEY_if: | |
57843af0 | 4749 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
4750 | OPERATOR(IF); |
4751 | ||
4752 | case KEY_index: | |
a0d0e21e | 4753 | LOP(OP_INDEX,XTERM); |
79072805 LW |
4754 | |
4755 | case KEY_int: | |
4756 | UNI(OP_INT); | |
4757 | ||
4758 | case KEY_ioctl: | |
a0d0e21e | 4759 | LOP(OP_IOCTL,XTERM); |
79072805 LW |
4760 | |
4761 | case KEY_join: | |
a0d0e21e | 4762 | LOP(OP_JOIN,XTERM); |
79072805 LW |
4763 | |
4764 | case KEY_keys: | |
4765 | UNI(OP_KEYS); | |
4766 | ||
4767 | case KEY_kill: | |
a0d0e21e | 4768 | LOP(OP_KILL,XTERM); |
79072805 LW |
4769 | |
4770 | case KEY_last: | |
a0d0e21e | 4771 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 | 4772 | LOOPX(OP_LAST); |
4e553d73 | 4773 | |
79072805 LW |
4774 | case KEY_lc: |
4775 | UNI(OP_LC); | |
4776 | ||
4777 | case KEY_lcfirst: | |
4778 | UNI(OP_LCFIRST); | |
4779 | ||
4780 | case KEY_local: | |
09bef843 | 4781 | yylval.ival = 0; |
79072805 LW |
4782 | OPERATOR(LOCAL); |
4783 | ||
4784 | case KEY_length: | |
4785 | UNI(OP_LENGTH); | |
4786 | ||
4787 | case KEY_lt: | |
4788 | Rop(OP_SLT); | |
4789 | ||
4790 | case KEY_le: | |
4791 | Rop(OP_SLE); | |
4792 | ||
4793 | case KEY_localtime: | |
4794 | UNI(OP_LOCALTIME); | |
4795 | ||
4796 | case KEY_log: | |
4797 | UNI(OP_LOG); | |
4798 | ||
4799 | case KEY_link: | |
a0d0e21e | 4800 | LOP(OP_LINK,XTERM); |
79072805 LW |
4801 | |
4802 | case KEY_listen: | |
a0d0e21e | 4803 | LOP(OP_LISTEN,XTERM); |
79072805 | 4804 | |
c0329465 MB |
4805 | case KEY_lock: |
4806 | UNI(OP_LOCK); | |
4807 | ||
79072805 LW |
4808 | case KEY_lstat: |
4809 | UNI(OP_LSTAT); | |
4810 | ||
4811 | case KEY_m: | |
8782bef2 | 4812 | s = scan_pat(s,OP_MATCH); |
79072805 LW |
4813 | TERM(sublex_start()); |
4814 | ||
a0d0e21e | 4815 | case KEY_map: |
2c38e13d | 4816 | LOP(OP_MAPSTART, XREF); |
4e4e412b | 4817 | |
79072805 | 4818 | case KEY_mkdir: |
a0d0e21e | 4819 | LOP(OP_MKDIR,XTERM); |
79072805 LW |
4820 | |
4821 | case KEY_msgctl: | |
a0d0e21e | 4822 | LOP(OP_MSGCTL,XTERM); |
79072805 LW |
4823 | |
4824 | case KEY_msgget: | |
a0d0e21e | 4825 | LOP(OP_MSGGET,XTERM); |
79072805 LW |
4826 | |
4827 | case KEY_msgrcv: | |
a0d0e21e | 4828 | LOP(OP_MSGRCV,XTERM); |
79072805 LW |
4829 | |
4830 | case KEY_msgsnd: | |
a0d0e21e | 4831 | LOP(OP_MSGSND,XTERM); |
79072805 | 4832 | |
77ca0c92 | 4833 | case KEY_our: |
93a17b20 | 4834 | case KEY_my: |
77ca0c92 | 4835 | PL_in_my = tmp; |
c750a3ec | 4836 | s = skipspace(s); |
7e2040f0 | 4837 | if (isIDFIRST_lazy_if(s,UTF)) { |
3280af22 | 4838 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len); |
09bef843 SB |
4839 | if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3)) |
4840 | goto really_sub; | |
def3634b | 4841 | PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len); |
3280af22 | 4842 | if (!PL_in_my_stash) { |
c750a3ec | 4843 | char tmpbuf[1024]; |
3280af22 NIS |
4844 | PL_bufptr = s; |
4845 | sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf); | |
c750a3ec MB |
4846 | yyerror(tmpbuf); |
4847 | } | |
4848 | } | |
09bef843 | 4849 | yylval.ival = 1; |
55497cff | 4850 | OPERATOR(MY); |
93a17b20 | 4851 | |
79072805 | 4852 | case KEY_next: |
a0d0e21e | 4853 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4854 | LOOPX(OP_NEXT); |
4855 | ||
4856 | case KEY_ne: | |
4857 | Eop(OP_SNE); | |
4858 | ||
a0d0e21e | 4859 | case KEY_no: |
3280af22 | 4860 | if (PL_expect != XSTATE) |
a0d0e21e LW |
4861 | yyerror("\"no\" not allowed in expression"); |
4862 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
e759cc13 | 4863 | s = force_version(s, FALSE); |
a0d0e21e LW |
4864 | yylval.ival = 0; |
4865 | OPERATOR(USE); | |
4866 | ||
4867 | case KEY_not: | |
2d2e263d LW |
4868 | if (*s == '(' || (s = skipspace(s), *s == '(')) |
4869 | FUN1(OP_NOT); | |
4870 | else | |
4871 | OPERATOR(NOTOP); | |
a0d0e21e | 4872 | |
79072805 | 4873 | case KEY_open: |
93a17b20 | 4874 | s = skipspace(s); |
7e2040f0 | 4875 | if (isIDFIRST_lazy_if(s,UTF)) { |
93a17b20 | 4876 | char *t; |
7e2040f0 | 4877 | for (d = s; isALNUM_lazy_if(d,UTF); d++) ; |
e2ab214b DM |
4878 | for (t=d; *t && isSPACE(*t); t++) ; |
4879 | if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE) | |
66fbe8fb HS |
4880 | /* [perl #16184] */ |
4881 | && !(t[0] == '=' && t[1] == '>') | |
4882 | ) { | |
9014280d | 4883 | Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE), |
0453d815 | 4884 | "Precedence problem: open %.*s should be open(%.*s)", |
66fbe8fb HS |
4885 | d - s, s, d - s, s); |
4886 | } | |
93a17b20 | 4887 | } |
a0d0e21e | 4888 | LOP(OP_OPEN,XTERM); |
79072805 | 4889 | |
463ee0b2 | 4890 | case KEY_or: |
a0d0e21e | 4891 | yylval.ival = OP_OR; |
463ee0b2 LW |
4892 | OPERATOR(OROP); |
4893 | ||
79072805 LW |
4894 | case KEY_ord: |
4895 | UNI(OP_ORD); | |
4896 | ||
4897 | case KEY_oct: | |
4898 | UNI(OP_OCT); | |
4899 | ||
4900 | case KEY_opendir: | |
a0d0e21e | 4901 | LOP(OP_OPEN_DIR,XTERM); |
79072805 LW |
4902 | |
4903 | case KEY_print: | |
3280af22 | 4904 | checkcomma(s,PL_tokenbuf,"filehandle"); |
a0d0e21e | 4905 | LOP(OP_PRINT,XREF); |
79072805 LW |
4906 | |
4907 | case KEY_printf: | |
3280af22 | 4908 | checkcomma(s,PL_tokenbuf,"filehandle"); |
a0d0e21e | 4909 | LOP(OP_PRTF,XREF); |
79072805 | 4910 | |
c07a80fd | 4911 | case KEY_prototype: |
4912 | UNI(OP_PROTOTYPE); | |
4913 | ||
79072805 | 4914 | case KEY_push: |
a0d0e21e | 4915 | LOP(OP_PUSH,XTERM); |
79072805 LW |
4916 | |
4917 | case KEY_pop: | |
6f33ba73 | 4918 | UNIDOR(OP_POP); |
79072805 | 4919 | |
a0d0e21e | 4920 | case KEY_pos: |
6f33ba73 | 4921 | UNIDOR(OP_POS); |
4e553d73 | 4922 | |
79072805 | 4923 | case KEY_pack: |
a0d0e21e | 4924 | LOP(OP_PACK,XTERM); |
79072805 LW |
4925 | |
4926 | case KEY_package: | |
a0d0e21e | 4927 | s = force_word(s,WORD,FALSE,TRUE,FALSE); |
79072805 LW |
4928 | OPERATOR(PACKAGE); |
4929 | ||
4930 | case KEY_pipe: | |
a0d0e21e | 4931 | LOP(OP_PIPE_OP,XTERM); |
79072805 LW |
4932 | |
4933 | case KEY_q: | |
09bef843 | 4934 | s = scan_str(s,FALSE,FALSE); |
79072805 | 4935 | if (!s) |
85e6fe83 | 4936 | missingterm((char*)0); |
79072805 LW |
4937 | yylval.ival = OP_CONST; |
4938 | TERM(sublex_start()); | |
4939 | ||
a0d0e21e LW |
4940 | case KEY_quotemeta: |
4941 | UNI(OP_QUOTEMETA); | |
4942 | ||
8990e307 | 4943 | case KEY_qw: |
09bef843 | 4944 | s = scan_str(s,FALSE,FALSE); |
8990e307 | 4945 | if (!s) |
85e6fe83 | 4946 | missingterm((char*)0); |
8127e0e3 GS |
4947 | force_next(')'); |
4948 | if (SvCUR(PL_lex_stuff)) { | |
4949 | OP *words = Nullop; | |
4950 | int warned = 0; | |
3280af22 | 4951 | d = SvPV_force(PL_lex_stuff, len); |
8127e0e3 | 4952 | while (len) { |
7948272d | 4953 | SV *sv; |
8127e0e3 GS |
4954 | for (; isSPACE(*d) && len; --len, ++d) ; |
4955 | if (len) { | |
4956 | char *b = d; | |
e476b1b5 | 4957 | if (!warned && ckWARN(WARN_QW)) { |
8127e0e3 GS |
4958 | for (; !isSPACE(*d) && len; --len, ++d) { |
4959 | if (*d == ',') { | |
9014280d | 4960 | Perl_warner(aTHX_ packWARN(WARN_QW), |
8127e0e3 GS |
4961 | "Possible attempt to separate words with commas"); |
4962 | ++warned; | |
4963 | } | |
4964 | else if (*d == '#') { | |
9014280d | 4965 | Perl_warner(aTHX_ packWARN(WARN_QW), |
8127e0e3 GS |
4966 | "Possible attempt to put comments in qw() list"); |
4967 | ++warned; | |
4968 | } | |
4969 | } | |
4970 | } | |
4971 | else { | |
4972 | for (; !isSPACE(*d) && len; --len, ++d) ; | |
4973 | } | |
7948272d NIS |
4974 | sv = newSVpvn(b, d-b); |
4975 | if (DO_UTF8(PL_lex_stuff)) | |
4976 | SvUTF8_on(sv); | |
8127e0e3 | 4977 | words = append_elem(OP_LIST, words, |
7948272d | 4978 | newSVOP(OP_CONST, 0, tokeq(sv))); |
55497cff | 4979 | } |
4980 | } | |
8127e0e3 GS |
4981 | if (words) { |
4982 | PL_nextval[PL_nexttoke].opval = words; | |
4983 | force_next(THING); | |
4984 | } | |
55497cff | 4985 | } |
37fd879b | 4986 | if (PL_lex_stuff) { |
8127e0e3 | 4987 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
4988 | PL_lex_stuff = Nullsv; |
4989 | } | |
3280af22 | 4990 | PL_expect = XTERM; |
8127e0e3 | 4991 | TOKEN('('); |
8990e307 | 4992 | |
79072805 | 4993 | case KEY_qq: |
09bef843 | 4994 | s = scan_str(s,FALSE,FALSE); |
79072805 | 4995 | if (!s) |
85e6fe83 | 4996 | missingterm((char*)0); |
a0d0e21e | 4997 | yylval.ival = OP_STRINGIFY; |
3280af22 | 4998 | if (SvIVX(PL_lex_stuff) == '\'') |
45977657 | 4999 | SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */ |
79072805 LW |
5000 | TERM(sublex_start()); |
5001 | ||
8782bef2 GB |
5002 | case KEY_qr: |
5003 | s = scan_pat(s,OP_QR); | |
5004 | TERM(sublex_start()); | |
5005 | ||
79072805 | 5006 | case KEY_qx: |
09bef843 | 5007 | s = scan_str(s,FALSE,FALSE); |
79072805 | 5008 | if (!s) |
85e6fe83 | 5009 | missingterm((char*)0); |
79072805 LW |
5010 | yylval.ival = OP_BACKTICK; |
5011 | set_csh(); | |
5012 | TERM(sublex_start()); | |
5013 | ||
5014 | case KEY_return: | |
5015 | OLDLOP(OP_RETURN); | |
5016 | ||
5017 | case KEY_require: | |
a7cb1f99 | 5018 | s = skipspace(s); |
e759cc13 RGS |
5019 | if (isDIGIT(*s)) { |
5020 | s = force_version(s, FALSE); | |
a7cb1f99 | 5021 | } |
e759cc13 RGS |
5022 | else if (*s != 'v' || !isDIGIT(s[1]) |
5023 | || (s = force_version(s, TRUE), *s == 'v')) | |
5024 | { | |
a7cb1f99 GS |
5025 | *PL_tokenbuf = '\0'; |
5026 | s = force_word(s,WORD,TRUE,TRUE,FALSE); | |
7e2040f0 | 5027 | if (isIDFIRST_lazy_if(PL_tokenbuf,UTF)) |
a7cb1f99 GS |
5028 | gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE); |
5029 | else if (*s == '<') | |
5030 | yyerror("<> should be quotes"); | |
5031 | } | |
463ee0b2 | 5032 | UNI(OP_REQUIRE); |
79072805 LW |
5033 | |
5034 | case KEY_reset: | |
5035 | UNI(OP_RESET); | |
5036 | ||
5037 | case KEY_redo: | |
a0d0e21e | 5038 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
5039 | LOOPX(OP_REDO); |
5040 | ||
5041 | case KEY_rename: | |
a0d0e21e | 5042 | LOP(OP_RENAME,XTERM); |
79072805 LW |
5043 | |
5044 | case KEY_rand: | |
5045 | UNI(OP_RAND); | |
5046 | ||
5047 | case KEY_rmdir: | |
5048 | UNI(OP_RMDIR); | |
5049 | ||
5050 | case KEY_rindex: | |
a0d0e21e | 5051 | LOP(OP_RINDEX,XTERM); |
79072805 LW |
5052 | |
5053 | case KEY_read: | |
a0d0e21e | 5054 | LOP(OP_READ,XTERM); |
79072805 LW |
5055 | |
5056 | case KEY_readdir: | |
5057 | UNI(OP_READDIR); | |
5058 | ||
93a17b20 LW |
5059 | case KEY_readline: |
5060 | set_csh(); | |
6f33ba73 | 5061 | UNIDOR(OP_READLINE); |
93a17b20 LW |
5062 | |
5063 | case KEY_readpipe: | |
5064 | set_csh(); | |
5065 | UNI(OP_BACKTICK); | |
5066 | ||
79072805 LW |
5067 | case KEY_rewinddir: |
5068 | UNI(OP_REWINDDIR); | |
5069 | ||
5070 | case KEY_recv: | |
a0d0e21e | 5071 | LOP(OP_RECV,XTERM); |
79072805 LW |
5072 | |
5073 | case KEY_reverse: | |
a0d0e21e | 5074 | LOP(OP_REVERSE,XTERM); |
79072805 LW |
5075 | |
5076 | case KEY_readlink: | |
6f33ba73 | 5077 | UNIDOR(OP_READLINK); |
79072805 LW |
5078 | |
5079 | case KEY_ref: | |
5080 | UNI(OP_REF); | |
5081 | ||
5082 | case KEY_s: | |
5083 | s = scan_subst(s); | |
5084 | if (yylval.opval) | |
5085 | TERM(sublex_start()); | |
5086 | else | |
5087 | TOKEN(1); /* force error */ | |
5088 | ||
a0d0e21e LW |
5089 | case KEY_chomp: |
5090 | UNI(OP_CHOMP); | |
4e553d73 | 5091 | |
79072805 LW |
5092 | case KEY_scalar: |
5093 | UNI(OP_SCALAR); | |
5094 | ||
5095 | case KEY_select: | |
a0d0e21e | 5096 | LOP(OP_SELECT,XTERM); |
79072805 LW |
5097 | |
5098 | case KEY_seek: | |
a0d0e21e | 5099 | LOP(OP_SEEK,XTERM); |
79072805 LW |
5100 | |
5101 | case KEY_semctl: | |
a0d0e21e | 5102 | LOP(OP_SEMCTL,XTERM); |
79072805 LW |
5103 | |
5104 | case KEY_semget: | |
a0d0e21e | 5105 | LOP(OP_SEMGET,XTERM); |
79072805 LW |
5106 | |
5107 | case KEY_semop: | |
a0d0e21e | 5108 | LOP(OP_SEMOP,XTERM); |
79072805 LW |
5109 | |
5110 | case KEY_send: | |
a0d0e21e | 5111 | LOP(OP_SEND,XTERM); |
79072805 LW |
5112 | |
5113 | case KEY_setpgrp: | |
a0d0e21e | 5114 | LOP(OP_SETPGRP,XTERM); |
79072805 LW |
5115 | |
5116 | case KEY_setpriority: | |
a0d0e21e | 5117 | LOP(OP_SETPRIORITY,XTERM); |
79072805 LW |
5118 | |
5119 | case KEY_sethostent: | |
ff68c719 | 5120 | UNI(OP_SHOSTENT); |
79072805 LW |
5121 | |
5122 | case KEY_setnetent: | |
ff68c719 | 5123 | UNI(OP_SNETENT); |
79072805 LW |
5124 | |
5125 | case KEY_setservent: | |
ff68c719 | 5126 | UNI(OP_SSERVENT); |
79072805 LW |
5127 | |
5128 | case KEY_setprotoent: | |
ff68c719 | 5129 | UNI(OP_SPROTOENT); |
79072805 LW |
5130 | |
5131 | case KEY_setpwent: | |
5132 | FUN0(OP_SPWENT); | |
5133 | ||
5134 | case KEY_setgrent: | |
5135 | FUN0(OP_SGRENT); | |
5136 | ||
5137 | case KEY_seekdir: | |
a0d0e21e | 5138 | LOP(OP_SEEKDIR,XTERM); |
79072805 LW |
5139 | |
5140 | case KEY_setsockopt: | |
a0d0e21e | 5141 | LOP(OP_SSOCKOPT,XTERM); |
79072805 LW |
5142 | |
5143 | case KEY_shift: | |
6f33ba73 | 5144 | UNIDOR(OP_SHIFT); |
79072805 LW |
5145 | |
5146 | case KEY_shmctl: | |
a0d0e21e | 5147 | LOP(OP_SHMCTL,XTERM); |
79072805 LW |
5148 | |
5149 | case KEY_shmget: | |
a0d0e21e | 5150 | LOP(OP_SHMGET,XTERM); |
79072805 LW |
5151 | |
5152 | case KEY_shmread: | |
a0d0e21e | 5153 | LOP(OP_SHMREAD,XTERM); |
79072805 LW |
5154 | |
5155 | case KEY_shmwrite: | |
a0d0e21e | 5156 | LOP(OP_SHMWRITE,XTERM); |
79072805 LW |
5157 | |
5158 | case KEY_shutdown: | |
a0d0e21e | 5159 | LOP(OP_SHUTDOWN,XTERM); |
79072805 LW |
5160 | |
5161 | case KEY_sin: | |
5162 | UNI(OP_SIN); | |
5163 | ||
5164 | case KEY_sleep: | |
5165 | UNI(OP_SLEEP); | |
5166 | ||
5167 | case KEY_socket: | |
a0d0e21e | 5168 | LOP(OP_SOCKET,XTERM); |
79072805 LW |
5169 | |
5170 | case KEY_socketpair: | |
a0d0e21e | 5171 | LOP(OP_SOCKPAIR,XTERM); |
79072805 LW |
5172 | |
5173 | case KEY_sort: | |
3280af22 | 5174 | checkcomma(s,PL_tokenbuf,"subroutine name"); |
79072805 LW |
5175 | s = skipspace(s); |
5176 | if (*s == ';' || *s == ')') /* probably a close */ | |
cea2e8a9 | 5177 | Perl_croak(aTHX_ "sort is now a reserved word"); |
3280af22 | 5178 | PL_expect = XTERM; |
15f0808c | 5179 | s = force_word(s,WORD,TRUE,TRUE,FALSE); |
a0d0e21e | 5180 | LOP(OP_SORT,XREF); |
79072805 LW |
5181 | |
5182 | case KEY_split: | |
a0d0e21e | 5183 | LOP(OP_SPLIT,XTERM); |
79072805 LW |
5184 | |
5185 | case KEY_sprintf: | |
a0d0e21e | 5186 | LOP(OP_SPRINTF,XTERM); |
79072805 LW |
5187 | |
5188 | case KEY_splice: | |
a0d0e21e | 5189 | LOP(OP_SPLICE,XTERM); |
79072805 LW |
5190 | |
5191 | case KEY_sqrt: | |
5192 | UNI(OP_SQRT); | |
5193 | ||
5194 | case KEY_srand: | |
5195 | UNI(OP_SRAND); | |
5196 | ||
5197 | case KEY_stat: | |
5198 | UNI(OP_STAT); | |
5199 | ||
5200 | case KEY_study: | |
79072805 LW |
5201 | UNI(OP_STUDY); |
5202 | ||
5203 | case KEY_substr: | |
a0d0e21e | 5204 | LOP(OP_SUBSTR,XTERM); |
79072805 LW |
5205 | |
5206 | case KEY_format: | |
5207 | case KEY_sub: | |
93a17b20 | 5208 | really_sub: |
09bef843 | 5209 | { |
3280af22 | 5210 | char tmpbuf[sizeof PL_tokenbuf]; |
9c5ffd7c | 5211 | SSize_t tboffset = 0; |
09bef843 | 5212 | expectation attrful; |
d731386a | 5213 | bool have_name, have_proto, bad_proto; |
09bef843 SB |
5214 | int key = tmp; |
5215 | ||
5216 | s = skipspace(s); | |
5217 | ||
7e2040f0 | 5218 | if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' || |
09bef843 SB |
5219 | (*s == ':' && s[1] == ':')) |
5220 | { | |
5221 | PL_expect = XBLOCK; | |
5222 | attrful = XATTRBLOCK; | |
b1b65b59 JH |
5223 | /* remember buffer pos'n for later force_word */ |
5224 | tboffset = s - PL_oldbufptr; | |
09bef843 SB |
5225 | d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
5226 | if (strchr(tmpbuf, ':')) | |
5227 | sv_setpv(PL_subname, tmpbuf); | |
5228 | else { | |
5229 | sv_setsv(PL_subname,PL_curstname); | |
5230 | sv_catpvn(PL_subname,"::",2); | |
5231 | sv_catpvn(PL_subname,tmpbuf,len); | |
5232 | } | |
5233 | s = skipspace(d); | |
5234 | have_name = TRUE; | |
5235 | } | |
463ee0b2 | 5236 | else { |
09bef843 SB |
5237 | if (key == KEY_my) |
5238 | Perl_croak(aTHX_ "Missing name in \"my sub\""); | |
5239 | PL_expect = XTERMBLOCK; | |
5240 | attrful = XATTRTERM; | |
5241 | sv_setpv(PL_subname,"?"); | |
5242 | have_name = FALSE; | |
463ee0b2 | 5243 | } |
4633a7c4 | 5244 | |
09bef843 SB |
5245 | if (key == KEY_format) { |
5246 | if (*s == '=') | |
5247 | PL_lex_formbrack = PL_lex_brackets + 1; | |
5248 | if (have_name) | |
b1b65b59 JH |
5249 | (void) force_word(PL_oldbufptr + tboffset, WORD, |
5250 | FALSE, TRUE, TRUE); | |
09bef843 SB |
5251 | OPERATOR(FORMAT); |
5252 | } | |
79072805 | 5253 | |
09bef843 SB |
5254 | /* Look for a prototype */ |
5255 | if (*s == '(') { | |
5256 | char *p; | |
5257 | ||
5258 | s = scan_str(s,FALSE,FALSE); | |
37fd879b | 5259 | if (!s) |
09bef843 | 5260 | Perl_croak(aTHX_ "Prototype not terminated"); |
2f758a16 | 5261 | /* strip spaces and check for bad characters */ |
09bef843 SB |
5262 | d = SvPVX(PL_lex_stuff); |
5263 | tmp = 0; | |
d731386a | 5264 | bad_proto = FALSE; |
09bef843 | 5265 | for (p = d; *p; ++p) { |
d37a9538 | 5266 | if (!isSPACE(*p)) { |
09bef843 | 5267 | d[tmp++] = *p; |
d37a9538 ST |
5268 | if (!strchr("$@%*;[]&\\", *p)) |
5269 | bad_proto = TRUE; | |
5270 | } | |
09bef843 SB |
5271 | } |
5272 | d[tmp] = '\0'; | |
420cdfc1 | 5273 | if (bad_proto && ckWARN(WARN_SYNTAX)) |
9014280d | 5274 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
35c1215d NC |
5275 | "Illegal character in prototype for %"SVf" : %s", |
5276 | PL_subname, d); | |
b162af07 | 5277 | SvCUR_set(PL_lex_stuff, tmp); |
09bef843 | 5278 | have_proto = TRUE; |
68dc0745 | 5279 | |
09bef843 | 5280 | s = skipspace(s); |
4633a7c4 | 5281 | } |
09bef843 SB |
5282 | else |
5283 | have_proto = FALSE; | |
5284 | ||
5285 | if (*s == ':' && s[1] != ':') | |
5286 | PL_expect = attrful; | |
8e742a20 MHM |
5287 | else if (*s != '{' && key == KEY_sub) { |
5288 | if (!have_name) | |
5289 | Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine"); | |
5290 | else if (*s != ';') | |
5291 | Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname); | |
5292 | } | |
09bef843 SB |
5293 | |
5294 | if (have_proto) { | |
b1b65b59 JH |
5295 | PL_nextval[PL_nexttoke].opval = |
5296 | (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff); | |
09bef843 SB |
5297 | PL_lex_stuff = Nullsv; |
5298 | force_next(THING); | |
68dc0745 | 5299 | } |
09bef843 | 5300 | if (!have_name) { |
c99da370 JH |
5301 | sv_setpv(PL_subname, |
5302 | PL_curstash ? "__ANON__" : "__ANON__::__ANON__"); | |
09bef843 | 5303 | TOKEN(ANONSUB); |
4633a7c4 | 5304 | } |
b1b65b59 JH |
5305 | (void) force_word(PL_oldbufptr + tboffset, WORD, |
5306 | FALSE, TRUE, TRUE); | |
09bef843 SB |
5307 | if (key == KEY_my) |
5308 | TOKEN(MYSUB); | |
5309 | TOKEN(SUB); | |
4633a7c4 | 5310 | } |
79072805 LW |
5311 | |
5312 | case KEY_system: | |
5313 | set_csh(); | |
a0d0e21e | 5314 | LOP(OP_SYSTEM,XREF); |
79072805 LW |
5315 | |
5316 | case KEY_symlink: | |
a0d0e21e | 5317 | LOP(OP_SYMLINK,XTERM); |
79072805 LW |
5318 | |
5319 | case KEY_syscall: | |
a0d0e21e | 5320 | LOP(OP_SYSCALL,XTERM); |
79072805 | 5321 | |
c07a80fd | 5322 | case KEY_sysopen: |
5323 | LOP(OP_SYSOPEN,XTERM); | |
5324 | ||
137443ea | 5325 | case KEY_sysseek: |
5326 | LOP(OP_SYSSEEK,XTERM); | |
5327 | ||
79072805 | 5328 | case KEY_sysread: |
a0d0e21e | 5329 | LOP(OP_SYSREAD,XTERM); |
79072805 LW |
5330 | |
5331 | case KEY_syswrite: | |
a0d0e21e | 5332 | LOP(OP_SYSWRITE,XTERM); |
79072805 LW |
5333 | |
5334 | case KEY_tr: | |
5335 | s = scan_trans(s); | |
5336 | TERM(sublex_start()); | |
5337 | ||
5338 | case KEY_tell: | |
5339 | UNI(OP_TELL); | |
5340 | ||
5341 | case KEY_telldir: | |
5342 | UNI(OP_TELLDIR); | |
5343 | ||
463ee0b2 | 5344 | case KEY_tie: |
a0d0e21e | 5345 | LOP(OP_TIE,XTERM); |
463ee0b2 | 5346 | |
c07a80fd | 5347 | case KEY_tied: |
5348 | UNI(OP_TIED); | |
5349 | ||
79072805 LW |
5350 | case KEY_time: |
5351 | FUN0(OP_TIME); | |
5352 | ||
5353 | case KEY_times: | |
5354 | FUN0(OP_TMS); | |
5355 | ||
5356 | case KEY_truncate: | |
a0d0e21e | 5357 | LOP(OP_TRUNCATE,XTERM); |
79072805 LW |
5358 | |
5359 | case KEY_uc: | |
5360 | UNI(OP_UC); | |
5361 | ||
5362 | case KEY_ucfirst: | |
5363 | UNI(OP_UCFIRST); | |
5364 | ||
463ee0b2 LW |
5365 | case KEY_untie: |
5366 | UNI(OP_UNTIE); | |
5367 | ||
79072805 | 5368 | case KEY_until: |
57843af0 | 5369 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5370 | OPERATOR(UNTIL); |
5371 | ||
5372 | case KEY_unless: | |
57843af0 | 5373 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5374 | OPERATOR(UNLESS); |
5375 | ||
5376 | case KEY_unlink: | |
a0d0e21e | 5377 | LOP(OP_UNLINK,XTERM); |
79072805 LW |
5378 | |
5379 | case KEY_undef: | |
6f33ba73 | 5380 | UNIDOR(OP_UNDEF); |
79072805 LW |
5381 | |
5382 | case KEY_unpack: | |
a0d0e21e | 5383 | LOP(OP_UNPACK,XTERM); |
79072805 LW |
5384 | |
5385 | case KEY_utime: | |
a0d0e21e | 5386 | LOP(OP_UTIME,XTERM); |
79072805 LW |
5387 | |
5388 | case KEY_umask: | |
6f33ba73 | 5389 | UNIDOR(OP_UMASK); |
79072805 LW |
5390 | |
5391 | case KEY_unshift: | |
a0d0e21e LW |
5392 | LOP(OP_UNSHIFT,XTERM); |
5393 | ||
5394 | case KEY_use: | |
3280af22 | 5395 | if (PL_expect != XSTATE) |
a0d0e21e | 5396 | yyerror("\"use\" not allowed in expression"); |
89bfa8cd | 5397 | s = skipspace(s); |
a7cb1f99 | 5398 | if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) { |
e759cc13 | 5399 | s = force_version(s, TRUE); |
a7cb1f99 | 5400 | if (*s == ';' || (s = skipspace(s), *s == ';')) { |
3280af22 | 5401 | PL_nextval[PL_nexttoke].opval = Nullop; |
89bfa8cd | 5402 | force_next(WORD); |
5403 | } | |
e759cc13 RGS |
5404 | else if (*s == 'v') { |
5405 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
5406 | s = force_version(s, FALSE); | |
5407 | } | |
89bfa8cd | 5408 | } |
5409 | else { | |
5410 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
e759cc13 | 5411 | s = force_version(s, FALSE); |
89bfa8cd | 5412 | } |
a0d0e21e LW |
5413 | yylval.ival = 1; |
5414 | OPERATOR(USE); | |
79072805 LW |
5415 | |
5416 | case KEY_values: | |
5417 | UNI(OP_VALUES); | |
5418 | ||
5419 | case KEY_vec: | |
a0d0e21e | 5420 | LOP(OP_VEC,XTERM); |
79072805 LW |
5421 | |
5422 | case KEY_while: | |
57843af0 | 5423 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5424 | OPERATOR(WHILE); |
5425 | ||
5426 | case KEY_warn: | |
3280af22 | 5427 | PL_hints |= HINT_BLOCK_SCOPE; |
a0d0e21e | 5428 | LOP(OP_WARN,XTERM); |
79072805 LW |
5429 | |
5430 | case KEY_wait: | |
5431 | FUN0(OP_WAIT); | |
5432 | ||
5433 | case KEY_waitpid: | |
a0d0e21e | 5434 | LOP(OP_WAITPID,XTERM); |
79072805 LW |
5435 | |
5436 | case KEY_wantarray: | |
5437 | FUN0(OP_WANTARRAY); | |
5438 | ||
5439 | case KEY_write: | |
9d116dd7 JH |
5440 | #ifdef EBCDIC |
5441 | { | |
df3728a2 JH |
5442 | char ctl_l[2]; |
5443 | ctl_l[0] = toCTRL('L'); | |
5444 | ctl_l[1] = '\0'; | |
9d116dd7 JH |
5445 | gv_fetchpv(ctl_l,TRUE, SVt_PV); |
5446 | } | |
5447 | #else | |
5448 | gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */ | |
5449 | #endif | |
79072805 LW |
5450 | UNI(OP_ENTERWRITE); |
5451 | ||
5452 | case KEY_x: | |
3280af22 | 5453 | if (PL_expect == XOPERATOR) |
79072805 LW |
5454 | Mop(OP_REPEAT); |
5455 | check_uni(); | |
5456 | goto just_a_word; | |
5457 | ||
a0d0e21e LW |
5458 | case KEY_xor: |
5459 | yylval.ival = OP_XOR; | |
5460 | OPERATOR(OROP); | |
5461 | ||
79072805 LW |
5462 | case KEY_y: |
5463 | s = scan_trans(s); | |
5464 | TERM(sublex_start()); | |
5465 | } | |
49dc05e3 | 5466 | }} |
79072805 | 5467 | } |
bf4acbe4 GS |
5468 | #ifdef __SC__ |
5469 | #pragma segment Main | |
5470 | #endif | |
79072805 | 5471 | |
e930465f JH |
5472 | static int |
5473 | S_pending_ident(pTHX) | |
8eceec63 SC |
5474 | { |
5475 | register char *d; | |
a55b55d8 | 5476 | register I32 tmp = 0; |
8eceec63 SC |
5477 | /* pit holds the identifier we read and pending_ident is reset */ |
5478 | char pit = PL_pending_ident; | |
5479 | PL_pending_ident = 0; | |
5480 | ||
5481 | DEBUG_T({ PerlIO_printf(Perl_debug_log, | |
5482 | "### Tokener saw identifier '%s'\n", PL_tokenbuf); }); | |
5483 | ||
5484 | /* if we're in a my(), we can't allow dynamics here. | |
5485 | $foo'bar has already been turned into $foo::bar, so | |
5486 | just check for colons. | |
5487 | ||
5488 | if it's a legal name, the OP is a PADANY. | |
5489 | */ | |
5490 | if (PL_in_my) { | |
5491 | if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */ | |
5492 | if (strchr(PL_tokenbuf,':')) | |
5493 | yyerror(Perl_form(aTHX_ "No package name allowed for " | |
5494 | "variable %s in \"our\"", | |
5495 | PL_tokenbuf)); | |
dd2155a4 | 5496 | tmp = allocmy(PL_tokenbuf); |
8eceec63 SC |
5497 | } |
5498 | else { | |
5499 | if (strchr(PL_tokenbuf,':')) | |
5500 | yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf)); | |
5501 | ||
5502 | yylval.opval = newOP(OP_PADANY, 0); | |
dd2155a4 | 5503 | yylval.opval->op_targ = allocmy(PL_tokenbuf); |
8eceec63 SC |
5504 | return PRIVATEREF; |
5505 | } | |
5506 | } | |
5507 | ||
5508 | /* | |
5509 | build the ops for accesses to a my() variable. | |
5510 | ||
5511 | Deny my($a) or my($b) in a sort block, *if* $a or $b is | |
5512 | then used in a comparison. This catches most, but not | |
5513 | all cases. For instance, it catches | |
5514 | sort { my($a); $a <=> $b } | |
5515 | but not | |
5516 | sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; } | |
5517 | (although why you'd do that is anyone's guess). | |
5518 | */ | |
5519 | ||
5520 | if (!strchr(PL_tokenbuf,':')) { | |
8716503d DM |
5521 | if (!PL_in_my) |
5522 | tmp = pad_findmy(PL_tokenbuf); | |
5523 | if (tmp != NOT_IN_PAD) { | |
8eceec63 | 5524 | /* might be an "our" variable" */ |
dd2155a4 | 5525 | if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) { |
8eceec63 | 5526 | /* build ops for a bareword */ |
dd2155a4 | 5527 | SV *sym = newSVpv(HvNAME(PAD_COMPNAME_OURSTASH(tmp)), 0); |
8eceec63 SC |
5528 | sv_catpvn(sym, "::", 2); |
5529 | sv_catpv(sym, PL_tokenbuf+1); | |
5530 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym); | |
5531 | yylval.opval->op_private = OPpCONST_ENTERED; | |
7a5fd60d | 5532 | gv_fetchsv(sym, |
8eceec63 SC |
5533 | (PL_in_eval |
5534 | ? (GV_ADDMULTI | GV_ADDINEVAL) | |
700078d2 | 5535 | : GV_ADDMULTI |
8eceec63 SC |
5536 | ), |
5537 | ((PL_tokenbuf[0] == '$') ? SVt_PV | |
5538 | : (PL_tokenbuf[0] == '@') ? SVt_PVAV | |
5539 | : SVt_PVHV)); | |
5540 | return WORD; | |
5541 | } | |
5542 | ||
5543 | /* if it's a sort block and they're naming $a or $b */ | |
5544 | if (PL_last_lop_op == OP_SORT && | |
5545 | PL_tokenbuf[0] == '$' && | |
5546 | (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b') | |
5547 | && !PL_tokenbuf[2]) | |
5548 | { | |
5549 | for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart; | |
5550 | d < PL_bufend && *d != '\n'; | |
5551 | d++) | |
5552 | { | |
5553 | if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) { | |
5554 | Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison", | |
5555 | PL_tokenbuf); | |
5556 | } | |
5557 | } | |
5558 | } | |
5559 | ||
5560 | yylval.opval = newOP(OP_PADANY, 0); | |
5561 | yylval.opval->op_targ = tmp; | |
5562 | return PRIVATEREF; | |
5563 | } | |
5564 | } | |
5565 | ||
5566 | /* | |
5567 | Whine if they've said @foo in a doublequoted string, | |
5568 | and @foo isn't a variable we can find in the symbol | |
5569 | table. | |
5570 | */ | |
5571 | if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) { | |
5572 | GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV); | |
5573 | if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv))) | |
5574 | && ckWARN(WARN_AMBIGUOUS)) | |
5575 | { | |
5576 | /* Downgraded from fatal to warning 20000522 mjd */ | |
9014280d | 5577 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
8eceec63 SC |
5578 | "Possible unintended interpolation of %s in string", |
5579 | PL_tokenbuf); | |
5580 | } | |
5581 | } | |
5582 | ||
5583 | /* build ops for a bareword */ | |
5584 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0)); | |
5585 | yylval.opval->op_private = OPpCONST_ENTERED; | |
5586 | gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE, | |
5587 | ((PL_tokenbuf[0] == '$') ? SVt_PV | |
5588 | : (PL_tokenbuf[0] == '@') ? SVt_PVAV | |
5589 | : SVt_PVHV)); | |
5590 | return WORD; | |
5591 | } | |
5592 | ||
4c3bbe0f MHM |
5593 | /* |
5594 | * The following code was generated by perl_keyword.pl. | |
5595 | */ | |
e2e1dd5a | 5596 | |
79072805 | 5597 | I32 |
4c3bbe0f MHM |
5598 | Perl_keyword (pTHX_ char *name, I32 len) |
5599 | { | |
5600 | switch (len) | |
5601 | { | |
5602 | case 1: /* 5 tokens of length 1 */ | |
5603 | switch (name[0]) | |
e2e1dd5a | 5604 | { |
4c3bbe0f MHM |
5605 | case 'm': |
5606 | { /* m */ | |
5607 | return KEY_m; | |
5608 | } | |
5609 | ||
4c3bbe0f MHM |
5610 | case 'q': |
5611 | { /* q */ | |
5612 | return KEY_q; | |
5613 | } | |
5614 | ||
4c3bbe0f MHM |
5615 | case 's': |
5616 | { /* s */ | |
5617 | return KEY_s; | |
5618 | } | |
5619 | ||
4c3bbe0f MHM |
5620 | case 'x': |
5621 | { /* x */ | |
5622 | return -KEY_x; | |
5623 | } | |
5624 | ||
4c3bbe0f MHM |
5625 | case 'y': |
5626 | { /* y */ | |
5627 | return KEY_y; | |
5628 | } | |
5629 | ||
4c3bbe0f MHM |
5630 | default: |
5631 | goto unknown; | |
e2e1dd5a | 5632 | } |
4c3bbe0f MHM |
5633 | |
5634 | case 2: /* 18 tokens of length 2 */ | |
5635 | switch (name[0]) | |
e2e1dd5a | 5636 | { |
4c3bbe0f MHM |
5637 | case 'd': |
5638 | if (name[1] == 'o') | |
5639 | { /* do */ | |
5640 | return KEY_do; | |
5641 | } | |
5642 | ||
5643 | goto unknown; | |
5644 | ||
5645 | case 'e': | |
5646 | if (name[1] == 'q') | |
5647 | { /* eq */ | |
5648 | return -KEY_eq; | |
5649 | } | |
5650 | ||
5651 | goto unknown; | |
5652 | ||
5653 | case 'g': | |
5654 | switch (name[1]) | |
5655 | { | |
5656 | case 'e': | |
5657 | { /* ge */ | |
5658 | return -KEY_ge; | |
5659 | } | |
5660 | ||
4c3bbe0f MHM |
5661 | case 't': |
5662 | { /* gt */ | |
5663 | return -KEY_gt; | |
5664 | } | |
5665 | ||
4c3bbe0f MHM |
5666 | default: |
5667 | goto unknown; | |
5668 | } | |
5669 | ||
5670 | case 'i': | |
5671 | if (name[1] == 'f') | |
5672 | { /* if */ | |
5673 | return KEY_if; | |
5674 | } | |
5675 | ||
5676 | goto unknown; | |
5677 | ||
5678 | case 'l': | |
5679 | switch (name[1]) | |
5680 | { | |
5681 | case 'c': | |
5682 | { /* lc */ | |
5683 | return -KEY_lc; | |
5684 | } | |
5685 | ||
4c3bbe0f MHM |
5686 | case 'e': |
5687 | { /* le */ | |
5688 | return -KEY_le; | |
5689 | } | |
5690 | ||
4c3bbe0f MHM |
5691 | case 't': |
5692 | { /* lt */ | |
5693 | return -KEY_lt; | |
5694 | } | |
5695 | ||
4c3bbe0f MHM |
5696 | default: |
5697 | goto unknown; | |
5698 | } | |
5699 | ||
5700 | case 'm': | |
5701 | if (name[1] == 'y') | |
5702 | { /* my */ | |
5703 | return KEY_my; | |
5704 | } | |
5705 | ||
5706 | goto unknown; | |
5707 | ||
5708 | case 'n': | |
5709 | switch (name[1]) | |
5710 | { | |
5711 | case 'e': | |
5712 | { /* ne */ | |
5713 | return -KEY_ne; | |
5714 | } | |
5715 | ||
4c3bbe0f MHM |
5716 | case 'o': |
5717 | { /* no */ | |
5718 | return KEY_no; | |
5719 | } | |
5720 | ||
4c3bbe0f MHM |
5721 | default: |
5722 | goto unknown; | |
5723 | } | |
5724 | ||
5725 | case 'o': | |
5726 | if (name[1] == 'r') | |
5727 | { /* or */ | |
5728 | return -KEY_or; | |
5729 | } | |
5730 | ||
5731 | goto unknown; | |
5732 | ||
5733 | case 'q': | |
5734 | switch (name[1]) | |
5735 | { | |
5736 | case 'q': | |
5737 | { /* qq */ | |
5738 | return KEY_qq; | |
5739 | } | |
5740 | ||
4c3bbe0f MHM |
5741 | case 'r': |
5742 | { /* qr */ | |
5743 | return KEY_qr; | |
5744 | } | |
5745 | ||
4c3bbe0f MHM |
5746 | case 'w': |
5747 | { /* qw */ | |
5748 | return KEY_qw; | |
5749 | } | |
5750 | ||
4c3bbe0f MHM |
5751 | case 'x': |
5752 | { /* qx */ | |
5753 | return KEY_qx; | |
5754 | } | |
5755 | ||
4c3bbe0f MHM |
5756 | default: |
5757 | goto unknown; | |
5758 | } | |
5759 | ||
5760 | case 't': | |
5761 | if (name[1] == 'r') | |
5762 | { /* tr */ | |
5763 | return KEY_tr; | |
5764 | } | |
5765 | ||
5766 | goto unknown; | |
5767 | ||
5768 | case 'u': | |
5769 | if (name[1] == 'c') | |
5770 | { /* uc */ | |
5771 | return -KEY_uc; | |
5772 | } | |
5773 | ||
5774 | goto unknown; | |
5775 | ||
5776 | default: | |
5777 | goto unknown; | |
e2e1dd5a | 5778 | } |
4c3bbe0f MHM |
5779 | |
5780 | case 3: /* 28 tokens of length 3 */ | |
5781 | switch (name[0]) | |
e2e1dd5a | 5782 | { |
4c3bbe0f MHM |
5783 | case 'E': |
5784 | if (name[1] == 'N' && | |
5785 | name[2] == 'D') | |
5786 | { /* END */ | |
5787 | return KEY_END; | |
5788 | } | |
5789 | ||
5790 | goto unknown; | |
5791 | ||
5792 | case 'a': | |
5793 | switch (name[1]) | |
5794 | { | |
5795 | case 'b': | |
5796 | if (name[2] == 's') | |
5797 | { /* abs */ | |
5798 | return -KEY_abs; | |
5799 | } | |
5800 | ||
5801 | goto unknown; | |
5802 | ||
5803 | case 'n': | |
5804 | if (name[2] == 'd') | |
5805 | { /* and */ | |
5806 | return -KEY_and; | |
5807 | } | |
5808 | ||
5809 | goto unknown; | |
5810 | ||
5811 | default: | |
5812 | goto unknown; | |
5813 | } | |
5814 | ||
5815 | case 'c': | |
5816 | switch (name[1]) | |
5817 | { | |
5818 | case 'h': | |
5819 | if (name[2] == 'r') | |
5820 | { /* chr */ | |
5821 | return -KEY_chr; | |
5822 | } | |
5823 | ||
5824 | goto unknown; | |
5825 | ||
5826 | case 'm': | |
5827 | if (name[2] == 'p') | |
5828 | { /* cmp */ | |
5829 | return -KEY_cmp; | |
5830 | } | |
5831 | ||
5832 | goto unknown; | |
5833 | ||
5834 | case 'o': | |
5835 | if (name[2] == 's') | |
5836 | { /* cos */ | |
5837 | return -KEY_cos; | |
5838 | } | |
5839 | ||
5840 | goto unknown; | |
5841 | ||
5842 | default: | |
5843 | goto unknown; | |
5844 | } | |
5845 | ||
5846 | case 'd': | |
5847 | if (name[1] == 'i' && | |
5848 | name[2] == 'e') | |
5849 | { /* die */ | |
5850 | return -KEY_die; | |
5851 | } | |
5852 | ||
5853 | goto unknown; | |
5854 | ||
5855 | case 'e': | |
5856 | switch (name[1]) | |
5857 | { | |
5858 | case 'o': | |
5859 | if (name[2] == 'f') | |
5860 | { /* eof */ | |
5861 | return -KEY_eof; | |
5862 | } | |
5863 | ||
5864 | goto unknown; | |
5865 | ||
5866 | case 'r': | |
5867 | if (name[2] == 'r') | |
5868 | { /* err */ | |
5869 | return -KEY_err; | |
5870 | } | |
5871 | ||
5872 | goto unknown; | |
5873 | ||
5874 | case 'x': | |
5875 | if (name[2] == 'p') | |
5876 | { /* exp */ | |
5877 | return -KEY_exp; | |
5878 | } | |
5879 | ||
5880 | goto unknown; | |
5881 | ||
5882 | default: | |
5883 | goto unknown; | |
5884 | } | |
5885 | ||
5886 | case 'f': | |
5887 | if (name[1] == 'o' && | |
5888 | name[2] == 'r') | |
5889 | { /* for */ | |
5890 | return KEY_for; | |
5891 | } | |
5892 | ||
5893 | goto unknown; | |
5894 | ||
5895 | case 'h': | |
5896 | if (name[1] == 'e' && | |
5897 | name[2] == 'x') | |
5898 | { /* hex */ | |
5899 | return -KEY_hex; | |
5900 | } | |
5901 | ||
5902 | goto unknown; | |
5903 | ||
5904 | case 'i': | |
5905 | if (name[1] == 'n' && | |
5906 | name[2] == 't') | |
5907 | { /* int */ | |
5908 | return -KEY_int; | |
5909 | } | |
5910 | ||
5911 | goto unknown; | |
5912 | ||
5913 | case 'l': | |
5914 | if (name[1] == 'o' && | |
5915 | name[2] == 'g') | |
5916 | { /* log */ | |
5917 | return -KEY_log; | |
5918 | } | |
5919 | ||
5920 | goto unknown; | |
5921 | ||
5922 | case 'm': | |
5923 | if (name[1] == 'a' && | |
5924 | name[2] == 'p') | |
5925 | { /* map */ | |
5926 | return KEY_map; | |
5927 | } | |
5928 | ||
5929 | goto unknown; | |
5930 | ||
5931 | case 'n': | |
5932 | if (name[1] == 'o' && | |
5933 | name[2] == 't') | |
5934 | { /* not */ | |
5935 | return -KEY_not; | |
5936 | } | |
5937 | ||
5938 | goto unknown; | |
5939 | ||
5940 | case 'o': | |
5941 | switch (name[1]) | |
5942 | { | |
5943 | case 'c': | |
5944 | if (name[2] == 't') | |
5945 | { /* oct */ | |
5946 | return -KEY_oct; | |
5947 | } | |
5948 | ||
5949 | goto unknown; | |
5950 | ||
5951 | case 'r': | |
5952 | if (name[2] == 'd') | |
5953 | { /* ord */ | |
5954 | return -KEY_ord; | |
5955 | } | |
5956 | ||
5957 | goto unknown; | |
5958 | ||
5959 | case 'u': | |
5960 | if (name[2] == 'r') | |
5961 | { /* our */ | |
5962 | return KEY_our; | |
5963 | } | |
5964 | ||
5965 | goto unknown; | |
5966 | ||
5967 | default: | |
5968 | goto unknown; | |
5969 | } | |
5970 | ||
5971 | case 'p': | |
5972 | if (name[1] == 'o') | |
5973 | { | |
5974 | switch (name[2]) | |
5975 | { | |
5976 | case 'p': | |
5977 | { /* pop */ | |
5978 | return -KEY_pop; | |
5979 | } | |
5980 | ||
4c3bbe0f MHM |
5981 | case 's': |
5982 | { /* pos */ | |
5983 | return KEY_pos; | |
5984 | } | |
5985 | ||
4c3bbe0f MHM |
5986 | default: |
5987 | goto unknown; | |
5988 | } | |
5989 | } | |
5990 | ||
5991 | goto unknown; | |
5992 | ||
5993 | case 'r': | |
5994 | if (name[1] == 'e' && | |
5995 | name[2] == 'f') | |
5996 | { /* ref */ | |
5997 | return -KEY_ref; | |
5998 | } | |
5999 | ||
6000 | goto unknown; | |
6001 | ||
6002 | case 's': | |
6003 | switch (name[1]) | |
6004 | { | |
6005 | case 'i': | |
6006 | if (name[2] == 'n') | |
6007 | { /* sin */ | |
6008 | return -KEY_sin; | |
6009 | } | |
6010 | ||
6011 | goto unknown; | |
6012 | ||
6013 | case 'u': | |
6014 | if (name[2] == 'b') | |
6015 | { /* sub */ | |
6016 | return KEY_sub; | |
6017 | } | |
6018 | ||
6019 | goto unknown; | |
6020 | ||
6021 | default: | |
6022 | goto unknown; | |
6023 | } | |
6024 | ||
6025 | case 't': | |
6026 | if (name[1] == 'i' && | |
6027 | name[2] == 'e') | |
6028 | { /* tie */ | |
6029 | return KEY_tie; | |
6030 | } | |
6031 | ||
6032 | goto unknown; | |
6033 | ||
6034 | case 'u': | |
6035 | if (name[1] == 's' && | |
6036 | name[2] == 'e') | |
6037 | { /* use */ | |
6038 | return KEY_use; | |
6039 | } | |
6040 | ||
6041 | goto unknown; | |
6042 | ||
6043 | case 'v': | |
6044 | if (name[1] == 'e' && | |
6045 | name[2] == 'c') | |
6046 | { /* vec */ | |
6047 | return -KEY_vec; | |
6048 | } | |
6049 | ||
6050 | goto unknown; | |
6051 | ||
6052 | case 'x': | |
6053 | if (name[1] == 'o' && | |
6054 | name[2] == 'r') | |
6055 | { /* xor */ | |
6056 | return -KEY_xor; | |
6057 | } | |
6058 | ||
6059 | goto unknown; | |
6060 | ||
6061 | default: | |
6062 | goto unknown; | |
e2e1dd5a | 6063 | } |
4c3bbe0f MHM |
6064 | |
6065 | case 4: /* 40 tokens of length 4 */ | |
6066 | switch (name[0]) | |
e2e1dd5a | 6067 | { |
4c3bbe0f MHM |
6068 | case 'C': |
6069 | if (name[1] == 'O' && | |
6070 | name[2] == 'R' && | |
6071 | name[3] == 'E') | |
6072 | { /* CORE */ | |
6073 | return -KEY_CORE; | |
6074 | } | |
6075 | ||
6076 | goto unknown; | |
6077 | ||
6078 | case 'I': | |
6079 | if (name[1] == 'N' && | |
6080 | name[2] == 'I' && | |
6081 | name[3] == 'T') | |
6082 | { /* INIT */ | |
6083 | return KEY_INIT; | |
6084 | } | |
6085 | ||
6086 | goto unknown; | |
6087 | ||
6088 | case 'b': | |
6089 | if (name[1] == 'i' && | |
6090 | name[2] == 'n' && | |
6091 | name[3] == 'd') | |
6092 | { /* bind */ | |
6093 | return -KEY_bind; | |
6094 | } | |
6095 | ||
6096 | goto unknown; | |
6097 | ||
6098 | case 'c': | |
6099 | if (name[1] == 'h' && | |
6100 | name[2] == 'o' && | |
6101 | name[3] == 'p') | |
6102 | { /* chop */ | |
6103 | return -KEY_chop; | |
6104 | } | |
6105 | ||
6106 | goto unknown; | |
6107 | ||
6108 | case 'd': | |
6109 | if (name[1] == 'u' && | |
6110 | name[2] == 'm' && | |
6111 | name[3] == 'p') | |
6112 | { /* dump */ | |
6113 | return -KEY_dump; | |
6114 | } | |
6115 | ||
6116 | goto unknown; | |
6117 | ||
6118 | case 'e': | |
6119 | switch (name[1]) | |
6120 | { | |
6121 | case 'a': | |
6122 | if (name[2] == 'c' && | |
6123 | name[3] == 'h') | |
6124 | { /* each */ | |
6125 | return -KEY_each; | |
6126 | } | |
6127 | ||
6128 | goto unknown; | |
6129 | ||
6130 | case 'l': | |
6131 | if (name[2] == 's' && | |
6132 | name[3] == 'e') | |
6133 | { /* else */ | |
6134 | return KEY_else; | |
6135 | } | |
6136 | ||
6137 | goto unknown; | |
6138 | ||
6139 | case 'v': | |
6140 | if (name[2] == 'a' && | |
6141 | name[3] == 'l') | |
6142 | { /* eval */ | |
6143 | return KEY_eval; | |
6144 | } | |
6145 | ||
6146 | goto unknown; | |
6147 | ||
6148 | case 'x': | |
6149 | switch (name[2]) | |
6150 | { | |
6151 | case 'e': | |
6152 | if (name[3] == 'c') | |
6153 | { /* exec */ | |
6154 | return -KEY_exec; | |
6155 | } | |
6156 | ||
6157 | goto unknown; | |
6158 | ||
6159 | case 'i': | |
6160 | if (name[3] == 't') | |
6161 | { /* exit */ | |
6162 | return -KEY_exit; | |
6163 | } | |
6164 | ||
6165 | goto unknown; | |
6166 | ||
6167 | default: | |
6168 | goto unknown; | |
6169 | } | |
6170 | ||
6171 | default: | |
6172 | goto unknown; | |
6173 | } | |
6174 | ||
6175 | case 'f': | |
6176 | if (name[1] == 'o' && | |
6177 | name[2] == 'r' && | |
6178 | name[3] == 'k') | |
6179 | { /* fork */ | |
6180 | return -KEY_fork; | |
6181 | } | |
6182 | ||
6183 | goto unknown; | |
6184 | ||
6185 | case 'g': | |
6186 | switch (name[1]) | |
6187 | { | |
6188 | case 'e': | |
6189 | if (name[2] == 't' && | |
6190 | name[3] == 'c') | |
6191 | { /* getc */ | |
6192 | return -KEY_getc; | |
6193 | } | |
6194 | ||
6195 | goto unknown; | |
6196 | ||
6197 | case 'l': | |
6198 | if (name[2] == 'o' && | |
6199 | name[3] == 'b') | |
6200 | { /* glob */ | |
6201 | return KEY_glob; | |
6202 | } | |
6203 | ||
6204 | goto unknown; | |
6205 | ||
6206 | case 'o': | |
6207 | if (name[2] == 't' && | |
6208 | name[3] == 'o') | |
6209 | { /* goto */ | |
6210 | return KEY_goto; | |
6211 | } | |
6212 | ||
6213 | goto unknown; | |
6214 | ||
6215 | case 'r': | |
6216 | if (name[2] == 'e' && | |
6217 | name[3] == 'p') | |
6218 | { /* grep */ | |
6219 | return KEY_grep; | |
6220 | } | |
6221 | ||
6222 | goto unknown; | |
6223 | ||
6224 | default: | |
6225 | goto unknown; | |
6226 | } | |
6227 | ||
6228 | case 'j': | |
6229 | if (name[1] == 'o' && | |
6230 | name[2] == 'i' && | |
6231 | name[3] == 'n') | |
6232 | { /* join */ | |
6233 | return -KEY_join; | |
6234 | } | |
6235 | ||
6236 | goto unknown; | |
6237 | ||
6238 | case 'k': | |
6239 | switch (name[1]) | |
6240 | { | |
6241 | case 'e': | |
6242 | if (name[2] == 'y' && | |
6243 | name[3] == 's') | |
6244 | { /* keys */ | |
6245 | return -KEY_keys; | |
6246 | } | |
6247 | ||
6248 | goto unknown; | |
6249 | ||
6250 | case 'i': | |
6251 | if (name[2] == 'l' && | |
6252 | name[3] == 'l') | |
6253 | { /* kill */ | |
6254 | return -KEY_kill; | |
6255 | } | |
6256 | ||
6257 | goto unknown; | |
6258 | ||
6259 | default: | |
6260 | goto unknown; | |
6261 | } | |
6262 | ||
6263 | case 'l': | |
6264 | switch (name[1]) | |
6265 | { | |
6266 | case 'a': | |
6267 | if (name[2] == 's' && | |
6268 | name[3] == 't') | |
6269 | { /* last */ | |
6270 | return KEY_last; | |
6271 | } | |
6272 | ||
6273 | goto unknown; | |
6274 | ||
6275 | case 'i': | |
6276 | if (name[2] == 'n' && | |
6277 | name[3] == 'k') | |
6278 | { /* link */ | |
6279 | return -KEY_link; | |
6280 | } | |
6281 | ||
6282 | goto unknown; | |
6283 | ||
6284 | case 'o': | |
6285 | if (name[2] == 'c' && | |
6286 | name[3] == 'k') | |
6287 | { /* lock */ | |
6288 | return -KEY_lock; | |
6289 | } | |
6290 | ||
6291 | goto unknown; | |
6292 | ||
6293 | default: | |
6294 | goto unknown; | |
6295 | } | |
6296 | ||
6297 | case 'n': | |
6298 | if (name[1] == 'e' && | |
6299 | name[2] == 'x' && | |
6300 | name[3] == 't') | |
6301 | { /* next */ | |
6302 | return KEY_next; | |
6303 | } | |
6304 | ||
6305 | goto unknown; | |
6306 | ||
6307 | case 'o': | |
6308 | if (name[1] == 'p' && | |
6309 | name[2] == 'e' && | |
6310 | name[3] == 'n') | |
6311 | { /* open */ | |
6312 | return -KEY_open; | |
6313 | } | |
6314 | ||
6315 | goto unknown; | |
6316 | ||
6317 | case 'p': | |
6318 | switch (name[1]) | |
6319 | { | |
6320 | case 'a': | |
6321 | if (name[2] == 'c' && | |
6322 | name[3] == 'k') | |
6323 | { /* pack */ | |
6324 | return -KEY_pack; | |
6325 | } | |
6326 | ||
6327 | goto unknown; | |
6328 | ||
6329 | case 'i': | |
6330 | if (name[2] == 'p' && | |
6331 | name[3] == 'e') | |
6332 | { /* pipe */ | |
6333 | return -KEY_pipe; | |
6334 | } | |
6335 | ||
6336 | goto unknown; | |
6337 | ||
6338 | case 'u': | |
6339 | if (name[2] == 's' && | |
6340 | name[3] == 'h') | |
6341 | { /* push */ | |
6342 | return -KEY_push; | |
6343 | } | |
6344 | ||
6345 | goto unknown; | |
6346 | ||
6347 | default: | |
6348 | goto unknown; | |
6349 | } | |
6350 | ||
6351 | case 'r': | |
6352 | switch (name[1]) | |
6353 | { | |
6354 | case 'a': | |
6355 | if (name[2] == 'n' && | |
6356 | name[3] == 'd') | |
6357 | { /* rand */ | |
6358 | return -KEY_rand; | |
6359 | } | |
6360 | ||
6361 | goto unknown; | |
6362 | ||
6363 | case 'e': | |
6364 | switch (name[2]) | |
6365 | { | |
6366 | case 'a': | |
6367 | if (name[3] == 'd') | |
6368 | { /* read */ | |
6369 | return -KEY_read; | |
6370 | } | |
6371 | ||
6372 | goto unknown; | |
6373 | ||
6374 | case 'c': | |
6375 | if (name[3] == 'v') | |
6376 | { /* recv */ | |
6377 | return -KEY_recv; | |
6378 | } | |
6379 | ||
6380 | goto unknown; | |
6381 | ||
6382 | case 'd': | |
6383 | if (name[3] == 'o') | |
6384 | { /* redo */ | |
6385 | return KEY_redo; | |
6386 | } | |
6387 | ||
6388 | goto unknown; | |
6389 | ||
6390 | default: | |
6391 | goto unknown; | |
6392 | } | |
6393 | ||
6394 | default: | |
6395 | goto unknown; | |
6396 | } | |
6397 | ||
6398 | case 's': | |
6399 | switch (name[1]) | |
6400 | { | |
6401 | case 'e': | |
6402 | switch (name[2]) | |
6403 | { | |
6404 | case 'e': | |
6405 | if (name[3] == 'k') | |
6406 | { /* seek */ | |
6407 | return -KEY_seek; | |
6408 | } | |
6409 | ||
6410 | goto unknown; | |
6411 | ||
6412 | case 'n': | |
6413 | if (name[3] == 'd') | |
6414 | { /* send */ | |
6415 | return -KEY_send; | |
6416 | } | |
6417 | ||
6418 | goto unknown; | |
6419 | ||
6420 | default: | |
6421 | goto unknown; | |
6422 | } | |
6423 | ||
6424 | case 'o': | |
6425 | if (name[2] == 'r' && | |
6426 | name[3] == 't') | |
6427 | { /* sort */ | |
6428 | return KEY_sort; | |
6429 | } | |
6430 | ||
6431 | goto unknown; | |
6432 | ||
6433 | case 'q': | |
6434 | if (name[2] == 'r' && | |
6435 | name[3] == 't') | |
6436 | { /* sqrt */ | |
6437 | return -KEY_sqrt; | |
6438 | } | |
6439 | ||
6440 | goto unknown; | |
6441 | ||
6442 | case 't': | |
6443 | if (name[2] == 'a' && | |
6444 | name[3] == 't') | |
6445 | { /* stat */ | |
6446 | return -KEY_stat; | |
6447 | } | |
6448 | ||
6449 | goto unknown; | |
6450 | ||
6451 | default: | |
6452 | goto unknown; | |
6453 | } | |
6454 | ||
6455 | case 't': | |
6456 | switch (name[1]) | |
6457 | { | |
6458 | case 'e': | |
6459 | if (name[2] == 'l' && | |
6460 | name[3] == 'l') | |
6461 | { /* tell */ | |
6462 | return -KEY_tell; | |
6463 | } | |
6464 | ||
6465 | goto unknown; | |
6466 | ||
6467 | case 'i': | |
6468 | switch (name[2]) | |
6469 | { | |
6470 | case 'e': | |
6471 | if (name[3] == 'd') | |
6472 | { /* tied */ | |
6473 | return KEY_tied; | |
6474 | } | |
6475 | ||
6476 | goto unknown; | |
6477 | ||
6478 | case 'm': | |
6479 | if (name[3] == 'e') | |
6480 | { /* time */ | |
6481 | return -KEY_time; | |
6482 | } | |
6483 | ||
6484 | goto unknown; | |
6485 | ||
6486 | default: | |
6487 | goto unknown; | |
6488 | } | |
6489 | ||
6490 | default: | |
6491 | goto unknown; | |
6492 | } | |
6493 | ||
6494 | case 'w': | |
6495 | if (name[1] == 'a') | |
6496 | { | |
6497 | switch (name[2]) | |
6498 | { | |
6499 | case 'i': | |
6500 | if (name[3] == 't') | |
6501 | { /* wait */ | |
6502 | return -KEY_wait; | |
6503 | } | |
6504 | ||
6505 | goto unknown; | |
6506 | ||
6507 | case 'r': | |
6508 | if (name[3] == 'n') | |
6509 | { /* warn */ | |
6510 | return -KEY_warn; | |
6511 | } | |
6512 | ||
6513 | goto unknown; | |
6514 | ||
6515 | default: | |
6516 | goto unknown; | |
6517 | } | |
6518 | } | |
6519 | ||
6520 | goto unknown; | |
6521 | ||
6522 | default: | |
6523 | goto unknown; | |
e2e1dd5a | 6524 | } |
4c3bbe0f MHM |
6525 | |
6526 | case 5: /* 36 tokens of length 5 */ | |
6527 | switch (name[0]) | |
e2e1dd5a | 6528 | { |
4c3bbe0f MHM |
6529 | case 'B': |
6530 | if (name[1] == 'E' && | |
6531 | name[2] == 'G' && | |
6532 | name[3] == 'I' && | |
6533 | name[4] == 'N') | |
6534 | { /* BEGIN */ | |
6535 | return KEY_BEGIN; | |
6536 | } | |
6537 | ||
6538 | goto unknown; | |
6539 | ||
6540 | case 'C': | |
6541 | if (name[1] == 'H' && | |
6542 | name[2] == 'E' && | |
6543 | name[3] == 'C' && | |
6544 | name[4] == 'K') | |
6545 | { /* CHECK */ | |
6546 | return KEY_CHECK; | |
6547 | } | |
6548 | ||
6549 | goto unknown; | |
6550 | ||
6551 | case 'a': | |
6552 | switch (name[1]) | |
6553 | { | |
6554 | case 'l': | |
6555 | if (name[2] == 'a' && | |
6556 | name[3] == 'r' && | |
6557 | name[4] == 'm') | |
6558 | { /* alarm */ | |
6559 | return -KEY_alarm; | |
6560 | } | |
6561 | ||
6562 | goto unknown; | |
6563 | ||
6564 | case 't': | |
6565 | if (name[2] == 'a' && | |
6566 | name[3] == 'n' && | |
6567 | name[4] == '2') | |
6568 | { /* atan2 */ | |
6569 | return -KEY_atan2; | |
6570 | } | |
6571 | ||
6572 | goto unknown; | |
6573 | ||
6574 | default: | |
6575 | goto unknown; | |
6576 | } | |
6577 | ||
6578 | case 'b': | |
6579 | if (name[1] == 'l' && | |
6580 | name[2] == 'e' && | |
6581 | name[3] == 's' && | |
6582 | name[4] == 's') | |
6583 | { /* bless */ | |
6584 | return -KEY_bless; | |
6585 | } | |
6586 | ||
6587 | goto unknown; | |
6588 | ||
6589 | case 'c': | |
6590 | switch (name[1]) | |
6591 | { | |
6592 | case 'h': | |
6593 | switch (name[2]) | |
6594 | { | |
6595 | case 'd': | |
6596 | if (name[3] == 'i' && | |
6597 | name[4] == 'r') | |
6598 | { /* chdir */ | |
6599 | return -KEY_chdir; | |
6600 | } | |
6601 | ||
6602 | goto unknown; | |
6603 | ||
6604 | case 'm': | |
6605 | if (name[3] == 'o' && | |
6606 | name[4] == 'd') | |
6607 | { /* chmod */ | |
6608 | return -KEY_chmod; | |
6609 | } | |
6610 | ||
6611 | goto unknown; | |
6612 | ||
6613 | case 'o': | |
6614 | switch (name[3]) | |
6615 | { | |
6616 | case 'm': | |
6617 | if (name[4] == 'p') | |
6618 | { /* chomp */ | |
6619 | return -KEY_chomp; | |
6620 | } | |
6621 | ||
6622 | goto unknown; | |
6623 | ||
6624 | case 'w': | |
6625 | if (name[4] == 'n') | |
6626 | { /* chown */ | |
6627 | return -KEY_chown; | |
6628 | } | |
6629 | ||
6630 | goto unknown; | |
6631 | ||
6632 | default: | |
6633 | goto unknown; | |
6634 | } | |
6635 | ||
6636 | default: | |
6637 | goto unknown; | |
6638 | } | |
6639 | ||
6640 | case 'l': | |
6641 | if (name[2] == 'o' && | |
6642 | name[3] == 's' && | |
6643 | name[4] == 'e') | |
6644 | { /* close */ | |
6645 | return -KEY_close; | |
6646 | } | |
6647 | ||
6648 | goto unknown; | |
6649 | ||
6650 | case 'r': | |
6651 | if (name[2] == 'y' && | |
6652 | name[3] == 'p' && | |
6653 | name[4] == 't') | |
6654 | { /* crypt */ | |
6655 | return -KEY_crypt; | |
6656 | } | |
6657 | ||
6658 | goto unknown; | |
6659 | ||
6660 | default: | |
6661 | goto unknown; | |
6662 | } | |
6663 | ||
6664 | case 'e': | |
6665 | if (name[1] == 'l' && | |
6666 | name[2] == 's' && | |
6667 | name[3] == 'i' && | |
6668 | name[4] == 'f') | |
6669 | { /* elsif */ | |
6670 | return KEY_elsif; | |
6671 | } | |
6672 | ||
6673 | goto unknown; | |
6674 | ||
6675 | case 'f': | |
6676 | switch (name[1]) | |
6677 | { | |
6678 | case 'c': | |
6679 | if (name[2] == 'n' && | |
6680 | name[3] == 't' && | |
6681 | name[4] == 'l') | |
6682 | { /* fcntl */ | |
6683 | return -KEY_fcntl; | |
6684 | } | |
6685 | ||
6686 | goto unknown; | |
6687 | ||
6688 | case 'l': | |
6689 | if (name[2] == 'o' && | |
6690 | name[3] == 'c' && | |
6691 | name[4] == 'k') | |
6692 | { /* flock */ | |
6693 | return -KEY_flock; | |
6694 | } | |
6695 | ||
6696 | goto unknown; | |
6697 | ||
6698 | default: | |
6699 | goto unknown; | |
6700 | } | |
6701 | ||
6702 | case 'i': | |
6703 | switch (name[1]) | |
6704 | { | |
6705 | case 'n': | |
6706 | if (name[2] == 'd' && | |
6707 | name[3] == 'e' && | |
6708 | name[4] == 'x') | |
6709 | { /* index */ | |
6710 | return -KEY_index; | |
6711 | } | |
6712 | ||
6713 | goto unknown; | |
6714 | ||
6715 | case 'o': | |
6716 | if (name[2] == 'c' && | |
6717 | name[3] == 't' && | |
6718 | name[4] == 'l') | |
6719 | { /* ioctl */ | |
6720 | return -KEY_ioctl; | |
6721 | } | |
6722 | ||
6723 | goto unknown; | |
6724 | ||
6725 | default: | |
6726 | goto unknown; | |
6727 | } | |
6728 | ||
6729 | case 'l': | |
6730 | switch (name[1]) | |
6731 | { | |
6732 | case 'o': | |
6733 | if (name[2] == 'c' && | |
6734 | name[3] == 'a' && | |
6735 | name[4] == 'l') | |
6736 | { /* local */ | |
6737 | return KEY_local; | |
6738 | } | |
6739 | ||
6740 | goto unknown; | |
6741 | ||
6742 | case 's': | |
6743 | if (name[2] == 't' && | |
6744 | name[3] == 'a' && | |
6745 | name[4] == 't') | |
6746 | { /* lstat */ | |
6747 | return -KEY_lstat; | |
6748 | } | |
6749 | ||
6750 | goto unknown; | |
6751 | ||
6752 | default: | |
6753 | goto unknown; | |
6754 | } | |
6755 | ||
6756 | case 'm': | |
6757 | if (name[1] == 'k' && | |
6758 | name[2] == 'd' && | |
6759 | name[3] == 'i' && | |
6760 | name[4] == 'r') | |
6761 | { /* mkdir */ | |
6762 | return -KEY_mkdir; | |
6763 | } | |
6764 | ||
6765 | goto unknown; | |
6766 | ||
6767 | case 'p': | |
6768 | if (name[1] == 'r' && | |
6769 | name[2] == 'i' && | |
6770 | name[3] == 'n' && | |
6771 | name[4] == 't') | |
6772 | { /* print */ | |
6773 | return KEY_print; | |
6774 | } | |
6775 | ||
6776 | goto unknown; | |
6777 | ||
6778 | case 'r': | |
6779 | switch (name[1]) | |
6780 | { | |
6781 | case 'e': | |
6782 | if (name[2] == 's' && | |
6783 | name[3] == 'e' && | |
6784 | name[4] == 't') | |
6785 | { /* reset */ | |
6786 | return -KEY_reset; | |
6787 | } | |
6788 | ||
6789 | goto unknown; | |
6790 | ||
6791 | case 'm': | |
6792 | if (name[2] == 'd' && | |
6793 | name[3] == 'i' && | |
6794 | name[4] == 'r') | |
6795 | { /* rmdir */ | |
6796 | return -KEY_rmdir; | |
6797 | } | |
6798 | ||
6799 | goto unknown; | |
6800 | ||
6801 | default: | |
6802 | goto unknown; | |
6803 | } | |
6804 | ||
6805 | case 's': | |
6806 | switch (name[1]) | |
6807 | { | |
6808 | case 'e': | |
6809 | if (name[2] == 'm' && | |
6810 | name[3] == 'o' && | |
6811 | name[4] == 'p') | |
6812 | { /* semop */ | |
6813 | return -KEY_semop; | |
6814 | } | |
6815 | ||
6816 | goto unknown; | |
6817 | ||
6818 | case 'h': | |
6819 | if (name[2] == 'i' && | |
6820 | name[3] == 'f' && | |
6821 | name[4] == 't') | |
6822 | { /* shift */ | |
6823 | return -KEY_shift; | |
6824 | } | |
6825 | ||
6826 | goto unknown; | |
6827 | ||
6828 | case 'l': | |
6829 | if (name[2] == 'e' && | |
6830 | name[3] == 'e' && | |
6831 | name[4] == 'p') | |
6832 | { /* sleep */ | |
6833 | return -KEY_sleep; | |
6834 | } | |
6835 | ||
6836 | goto unknown; | |
6837 | ||
6838 | case 'p': | |
6839 | if (name[2] == 'l' && | |
6840 | name[3] == 'i' && | |
6841 | name[4] == 't') | |
6842 | { /* split */ | |
6843 | return KEY_split; | |
6844 | } | |
6845 | ||
6846 | goto unknown; | |
6847 | ||
6848 | case 'r': | |
6849 | if (name[2] == 'a' && | |
6850 | name[3] == 'n' && | |
6851 | name[4] == 'd') | |
6852 | { /* srand */ | |
6853 | return -KEY_srand; | |
6854 | } | |
6855 | ||
6856 | goto unknown; | |
6857 | ||
6858 | case 't': | |
6859 | if (name[2] == 'u' && | |
6860 | name[3] == 'd' && | |
6861 | name[4] == 'y') | |
6862 | { /* study */ | |
6863 | return KEY_study; | |
6864 | } | |
6865 | ||
6866 | goto unknown; | |
6867 | ||
6868 | default: | |
6869 | goto unknown; | |
6870 | } | |
6871 | ||
6872 | case 't': | |
6873 | if (name[1] == 'i' && | |
6874 | name[2] == 'm' && | |
6875 | name[3] == 'e' && | |
6876 | name[4] == 's') | |
6877 | { /* times */ | |
6878 | return -KEY_times; | |
6879 | } | |
6880 | ||
6881 | goto unknown; | |
6882 | ||
6883 | case 'u': | |
6884 | switch (name[1]) | |
6885 | { | |
6886 | case 'm': | |
6887 | if (name[2] == 'a' && | |
6888 | name[3] == 's' && | |
6889 | name[4] == 'k') | |
6890 | { /* umask */ | |
6891 | return -KEY_umask; | |
6892 | } | |
6893 | ||
6894 | goto unknown; | |
6895 | ||
6896 | case 'n': | |
6897 | switch (name[2]) | |
6898 | { | |
6899 | case 'd': | |
6900 | if (name[3] == 'e' && | |
6901 | name[4] == 'f') | |
6902 | { /* undef */ | |
6903 | return KEY_undef; | |
6904 | } | |
6905 | ||
6906 | goto unknown; | |
6907 | ||
6908 | case 't': | |
6909 | if (name[3] == 'i') | |
6910 | { | |
6911 | switch (name[4]) | |
6912 | { | |
6913 | case 'e': | |
6914 | { /* untie */ | |
6915 | return KEY_untie; | |
6916 | } | |
6917 | ||
4c3bbe0f MHM |
6918 | case 'l': |
6919 | { /* until */ | |
6920 | return KEY_until; | |
6921 | } | |
6922 | ||
4c3bbe0f MHM |
6923 | default: |
6924 | goto unknown; | |
6925 | } | |
6926 | } | |
6927 | ||
6928 | goto unknown; | |
6929 | ||
6930 | default: | |
6931 | goto unknown; | |
6932 | } | |
6933 | ||
6934 | case 't': | |
6935 | if (name[2] == 'i' && | |
6936 | name[3] == 'm' && | |
6937 | name[4] == 'e') | |
6938 | { /* utime */ | |
6939 | return -KEY_utime; | |
6940 | } | |
6941 | ||
6942 | goto unknown; | |
6943 | ||
6944 | default: | |
6945 | goto unknown; | |
6946 | } | |
6947 | ||
6948 | case 'w': | |
6949 | switch (name[1]) | |
6950 | { | |
6951 | case 'h': | |
6952 | if (name[2] == 'i' && | |
6953 | name[3] == 'l' && | |
6954 | name[4] == 'e') | |
6955 | { /* while */ | |
6956 | return KEY_while; | |
6957 | } | |
6958 | ||
6959 | goto unknown; | |
6960 | ||
6961 | case 'r': | |
6962 | if (name[2] == 'i' && | |
6963 | name[3] == 't' && | |
6964 | name[4] == 'e') | |
6965 | { /* write */ | |
6966 | return -KEY_write; | |
6967 | } | |
6968 | ||
6969 | goto unknown; | |
6970 | ||
6971 | default: | |
6972 | goto unknown; | |
6973 | } | |
6974 | ||
6975 | default: | |
6976 | goto unknown; | |
e2e1dd5a | 6977 | } |
4c3bbe0f MHM |
6978 | |
6979 | case 6: /* 33 tokens of length 6 */ | |
6980 | switch (name[0]) | |
6981 | { | |
6982 | case 'a': | |
6983 | if (name[1] == 'c' && | |
6984 | name[2] == 'c' && | |
6985 | name[3] == 'e' && | |
6986 | name[4] == 'p' && | |
6987 | name[5] == 't') | |
6988 | { /* accept */ | |
6989 | return -KEY_accept; | |
6990 | } | |
6991 | ||
6992 | goto unknown; | |
6993 | ||
6994 | case 'c': | |
6995 | switch (name[1]) | |
6996 | { | |
6997 | case 'a': | |
6998 | if (name[2] == 'l' && | |
6999 | name[3] == 'l' && | |
7000 | name[4] == 'e' && | |
7001 | name[5] == 'r') | |
7002 | { /* caller */ | |
7003 | return -KEY_caller; | |
7004 | } | |
7005 | ||
7006 | goto unknown; | |
7007 | ||
7008 | case 'h': | |
7009 | if (name[2] == 'r' && | |
7010 | name[3] == 'o' && | |
7011 | name[4] == 'o' && | |
7012 | name[5] == 't') | |
7013 | { /* chroot */ | |
7014 | return -KEY_chroot; | |
7015 | } | |
7016 | ||
7017 | goto unknown; | |
7018 | ||
7019 | default: | |
7020 | goto unknown; | |
7021 | } | |
7022 | ||
7023 | case 'd': | |
7024 | if (name[1] == 'e' && | |
7025 | name[2] == 'l' && | |
7026 | name[3] == 'e' && | |
7027 | name[4] == 't' && | |
7028 | name[5] == 'e') | |
7029 | { /* delete */ | |
7030 | return KEY_delete; | |
7031 | } | |
7032 | ||
7033 | goto unknown; | |
7034 | ||
7035 | case 'e': | |
7036 | switch (name[1]) | |
7037 | { | |
7038 | case 'l': | |
7039 | if (name[2] == 's' && | |
7040 | name[3] == 'e' && | |
7041 | name[4] == 'i' && | |
7042 | name[5] == 'f') | |
7043 | { /* elseif */ | |
7044 | if(ckWARN_d(WARN_SYNTAX)) | |
7045 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif"); | |
7046 | } | |
7047 | ||
7048 | goto unknown; | |
7049 | ||
7050 | case 'x': | |
7051 | if (name[2] == 'i' && | |
7052 | name[3] == 's' && | |
7053 | name[4] == 't' && | |
7054 | name[5] == 's') | |
7055 | { /* exists */ | |
7056 | return KEY_exists; | |
7057 | } | |
7058 | ||
7059 | goto unknown; | |
7060 | ||
7061 | default: | |
7062 | goto unknown; | |
7063 | } | |
7064 | ||
7065 | case 'f': | |
7066 | switch (name[1]) | |
7067 | { | |
7068 | case 'i': | |
7069 | if (name[2] == 'l' && | |
7070 | name[3] == 'e' && | |
7071 | name[4] == 'n' && | |
7072 | name[5] == 'o') | |
7073 | { /* fileno */ | |
7074 | return -KEY_fileno; | |
7075 | } | |
7076 | ||
7077 | goto unknown; | |
7078 | ||
7079 | case 'o': | |
7080 | if (name[2] == 'r' && | |
7081 | name[3] == 'm' && | |
7082 | name[4] == 'a' && | |
7083 | name[5] == 't') | |
7084 | { /* format */ | |
7085 | return KEY_format; | |
7086 | } | |
7087 | ||
7088 | goto unknown; | |
7089 | ||
7090 | default: | |
7091 | goto unknown; | |
7092 | } | |
7093 | ||
7094 | case 'g': | |
7095 | if (name[1] == 'm' && | |
7096 | name[2] == 't' && | |
7097 | name[3] == 'i' && | |
7098 | name[4] == 'm' && | |
7099 | name[5] == 'e') | |
7100 | { /* gmtime */ | |
7101 | return -KEY_gmtime; | |
7102 | } | |
7103 | ||
7104 | goto unknown; | |
7105 | ||
7106 | case 'l': | |
7107 | switch (name[1]) | |
7108 | { | |
7109 | case 'e': | |
7110 | if (name[2] == 'n' && | |
7111 | name[3] == 'g' && | |
7112 | name[4] == 't' && | |
7113 | name[5] == 'h') | |
7114 | { /* length */ | |
7115 | return -KEY_length; | |
7116 | } | |
7117 | ||
7118 | goto unknown; | |
7119 | ||
7120 | case 'i': | |
7121 | if (name[2] == 's' && | |
7122 | name[3] == 't' && | |
7123 | name[4] == 'e' && | |
7124 | name[5] == 'n') | |
7125 | { /* listen */ | |
7126 | return -KEY_listen; | |
7127 | } | |
7128 | ||
7129 | goto unknown; | |
7130 | ||
7131 | default: | |
7132 | goto unknown; | |
7133 | } | |
7134 | ||
7135 | case 'm': | |
7136 | if (name[1] == 's' && | |
7137 | name[2] == 'g') | |
7138 | { | |
7139 | switch (name[3]) | |
7140 | { | |
7141 | case 'c': | |
7142 | if (name[4] == 't' && | |
7143 | name[5] == 'l') | |
7144 | { /* msgctl */ | |
7145 | return -KEY_msgctl; | |
7146 | } | |
7147 | ||
7148 | goto unknown; | |
7149 | ||
7150 | case 'g': | |
7151 | if (name[4] == 'e' && | |
7152 | name[5] == 't') | |
7153 | { /* msgget */ | |
7154 | return -KEY_msgget; | |
7155 | } | |
7156 | ||
7157 | goto unknown; | |
7158 | ||
7159 | case 'r': | |
7160 | if (name[4] == 'c' && | |
7161 | name[5] == 'v') | |
7162 | { /* msgrcv */ | |
7163 | return -KEY_msgrcv; | |
7164 | } | |
7165 | ||
7166 | goto unknown; | |
7167 | ||
7168 | case 's': | |
7169 | if (name[4] == 'n' && | |
7170 | name[5] == 'd') | |
7171 | { /* msgsnd */ | |
7172 | return -KEY_msgsnd; | |
7173 | } | |
7174 | ||
7175 | goto unknown; | |
7176 | ||
7177 | default: | |
7178 | goto unknown; | |
7179 | } | |
7180 | } | |
7181 | ||
7182 | goto unknown; | |
7183 | ||
7184 | case 'p': | |
7185 | if (name[1] == 'r' && | |
7186 | name[2] == 'i' && | |
7187 | name[3] == 'n' && | |
7188 | name[4] == 't' && | |
7189 | name[5] == 'f') | |
7190 | { /* printf */ | |
7191 | return KEY_printf; | |
7192 | } | |
7193 | ||
7194 | goto unknown; | |
7195 | ||
7196 | case 'r': | |
7197 | switch (name[1]) | |
7198 | { | |
7199 | case 'e': | |
7200 | switch (name[2]) | |
7201 | { | |
7202 | case 'n': | |
7203 | if (name[3] == 'a' && | |
7204 | name[4] == 'm' && | |
7205 | name[5] == 'e') | |
7206 | { /* rename */ | |
7207 | return -KEY_rename; | |
7208 | } | |
7209 | ||
7210 | goto unknown; | |
7211 | ||
7212 | case 't': | |
7213 | if (name[3] == 'u' && | |
7214 | name[4] == 'r' && | |
7215 | name[5] == 'n') | |
7216 | { /* return */ | |
7217 | return KEY_return; | |
7218 | } | |
7219 | ||
7220 | goto unknown; | |
7221 | ||
7222 | default: | |
7223 | goto unknown; | |
7224 | } | |
7225 | ||
7226 | case 'i': | |
7227 | if (name[2] == 'n' && | |
7228 | name[3] == 'd' && | |
7229 | name[4] == 'e' && | |
7230 | name[5] == 'x') | |
7231 | { /* rindex */ | |
7232 | return -KEY_rindex; | |
7233 | } | |
7234 | ||
7235 | goto unknown; | |
7236 | ||
7237 | default: | |
7238 | goto unknown; | |
7239 | } | |
7240 | ||
7241 | case 's': | |
7242 | switch (name[1]) | |
7243 | { | |
7244 | case 'c': | |
7245 | if (name[2] == 'a' && | |
7246 | name[3] == 'l' && | |
7247 | name[4] == 'a' && | |
7248 | name[5] == 'r') | |
7249 | { /* scalar */ | |
7250 | return KEY_scalar; | |
7251 | } | |
7252 | ||
7253 | goto unknown; | |
7254 | ||
7255 | case 'e': | |
7256 | switch (name[2]) | |
7257 | { | |
7258 | case 'l': | |
7259 | if (name[3] == 'e' && | |
7260 | name[4] == 'c' && | |
7261 | name[5] == 't') | |
7262 | { /* select */ | |
7263 | return -KEY_select; | |
7264 | } | |
7265 | ||
7266 | goto unknown; | |
7267 | ||
7268 | case 'm': | |
7269 | switch (name[3]) | |
7270 | { | |
7271 | case 'c': | |
7272 | if (name[4] == 't' && | |
7273 | name[5] == 'l') | |
7274 | { /* semctl */ | |
7275 | return -KEY_semctl; | |
7276 | } | |
7277 | ||
7278 | goto unknown; | |
7279 | ||
7280 | case 'g': | |
7281 | if (name[4] == 'e' && | |
7282 | name[5] == 't') | |
7283 | { /* semget */ | |
7284 | return -KEY_semget; | |
7285 | } | |
7286 | ||
7287 | goto unknown; | |
7288 | ||
7289 | default: | |
7290 | goto unknown; | |
7291 | } | |
7292 | ||
7293 | default: | |
7294 | goto unknown; | |
7295 | } | |
7296 | ||
7297 | case 'h': | |
7298 | if (name[2] == 'm') | |
7299 | { | |
7300 | switch (name[3]) | |
7301 | { | |
7302 | case 'c': | |
7303 | if (name[4] == 't' && | |
7304 | name[5] == 'l') | |
7305 | { /* shmctl */ | |
7306 | return -KEY_shmctl; | |
7307 | } | |
7308 | ||
7309 | goto unknown; | |
7310 | ||
7311 | case 'g': | |
7312 | if (name[4] == 'e' && | |
7313 | name[5] == 't') | |
7314 | { /* shmget */ | |
7315 | return -KEY_shmget; | |
7316 | } | |
7317 | ||
7318 | goto unknown; | |
7319 | ||
7320 | default: | |
7321 | goto unknown; | |
7322 | } | |
7323 | } | |
7324 | ||
7325 | goto unknown; | |
7326 | ||
7327 | case 'o': | |
7328 | if (name[2] == 'c' && | |
7329 | name[3] == 'k' && | |
7330 | name[4] == 'e' && | |
7331 | name[5] == 't') | |
7332 | { /* socket */ | |
7333 | return -KEY_socket; | |
7334 | } | |
7335 | ||
7336 | goto unknown; | |
7337 | ||
7338 | case 'p': | |
7339 | if (name[2] == 'l' && | |
7340 | name[3] == 'i' && | |
7341 | name[4] == 'c' && | |
7342 | name[5] == 'e') | |
7343 | { /* splice */ | |
7344 | return -KEY_splice; | |
7345 | } | |
7346 | ||
7347 | goto unknown; | |
7348 | ||
7349 | case 'u': | |
7350 | if (name[2] == 'b' && | |
7351 | name[3] == 's' && | |
7352 | name[4] == 't' && | |
7353 | name[5] == 'r') | |
7354 | { /* substr */ | |
7355 | return -KEY_substr; | |
7356 | } | |
7357 | ||
7358 | goto unknown; | |
7359 | ||
7360 | case 'y': | |
7361 | if (name[2] == 's' && | |
7362 | name[3] == 't' && | |
7363 | name[4] == 'e' && | |
7364 | name[5] == 'm') | |
7365 | { /* system */ | |
7366 | return -KEY_system; | |
7367 | } | |
7368 | ||
7369 | goto unknown; | |
7370 | ||
7371 | default: | |
7372 | goto unknown; | |
7373 | } | |
7374 | ||
7375 | case 'u': | |
7376 | if (name[1] == 'n') | |
7377 | { | |
7378 | switch (name[2]) | |
7379 | { | |
7380 | case 'l': | |
7381 | switch (name[3]) | |
7382 | { | |
7383 | case 'e': | |
7384 | if (name[4] == 's' && | |
7385 | name[5] == 's') | |
7386 | { /* unless */ | |
7387 | return KEY_unless; | |
7388 | } | |
7389 | ||
7390 | goto unknown; | |
7391 | ||
7392 | case 'i': | |
7393 | if (name[4] == 'n' && | |
7394 | name[5] == 'k') | |
7395 | { /* unlink */ | |
7396 | return -KEY_unlink; | |
7397 | } | |
7398 | ||
7399 | goto unknown; | |
7400 | ||
7401 | default: | |
7402 | goto unknown; | |
7403 | } | |
7404 | ||
7405 | case 'p': | |
7406 | if (name[3] == 'a' && | |
7407 | name[4] == 'c' && | |
7408 | name[5] == 'k') | |
7409 | { /* unpack */ | |
7410 | return -KEY_unpack; | |
7411 | } | |
7412 | ||
7413 | goto unknown; | |
7414 | ||
7415 | default: | |
7416 | goto unknown; | |
7417 | } | |
7418 | } | |
7419 | ||
7420 | goto unknown; | |
7421 | ||
7422 | case 'v': | |
7423 | if (name[1] == 'a' && | |
7424 | name[2] == 'l' && | |
7425 | name[3] == 'u' && | |
7426 | name[4] == 'e' && | |
7427 | name[5] == 's') | |
7428 | { /* values */ | |
7429 | return -KEY_values; | |
7430 | } | |
7431 | ||
7432 | goto unknown; | |
7433 | ||
7434 | default: | |
7435 | goto unknown; | |
e2e1dd5a | 7436 | } |
4c3bbe0f MHM |
7437 | |
7438 | case 7: /* 28 tokens of length 7 */ | |
7439 | switch (name[0]) | |
7440 | { | |
7441 | case 'D': | |
7442 | if (name[1] == 'E' && | |
7443 | name[2] == 'S' && | |
7444 | name[3] == 'T' && | |
7445 | name[4] == 'R' && | |
7446 | name[5] == 'O' && | |
7447 | name[6] == 'Y') | |
7448 | { /* DESTROY */ | |
7449 | return KEY_DESTROY; | |
7450 | } | |
7451 | ||
7452 | goto unknown; | |
7453 | ||
7454 | case '_': | |
7455 | if (name[1] == '_' && | |
7456 | name[2] == 'E' && | |
7457 | name[3] == 'N' && | |
7458 | name[4] == 'D' && | |
7459 | name[5] == '_' && | |
7460 | name[6] == '_') | |
7461 | { /* __END__ */ | |
7462 | return KEY___END__; | |
7463 | } | |
7464 | ||
7465 | goto unknown; | |
7466 | ||
7467 | case 'b': | |
7468 | if (name[1] == 'i' && | |
7469 | name[2] == 'n' && | |
7470 | name[3] == 'm' && | |
7471 | name[4] == 'o' && | |
7472 | name[5] == 'd' && | |
7473 | name[6] == 'e') | |
7474 | { /* binmode */ | |
7475 | return -KEY_binmode; | |
7476 | } | |
7477 | ||
7478 | goto unknown; | |
7479 | ||
7480 | case 'c': | |
7481 | if (name[1] == 'o' && | |
7482 | name[2] == 'n' && | |
7483 | name[3] == 'n' && | |
7484 | name[4] == 'e' && | |
7485 | name[5] == 'c' && | |
7486 | name[6] == 't') | |
7487 | { /* connect */ | |
7488 | return -KEY_connect; | |
7489 | } | |
7490 | ||
7491 | goto unknown; | |
7492 | ||
7493 | case 'd': | |
7494 | switch (name[1]) | |
7495 | { | |
7496 | case 'b': | |
7497 | if (name[2] == 'm' && | |
7498 | name[3] == 'o' && | |
7499 | name[4] == 'p' && | |
7500 | name[5] == 'e' && | |
7501 | name[6] == 'n') | |
7502 | { /* dbmopen */ | |
7503 | return -KEY_dbmopen; | |
7504 | } | |
7505 | ||
7506 | goto unknown; | |
7507 | ||
7508 | case 'e': | |
7509 | if (name[2] == 'f' && | |
7510 | name[3] == 'i' && | |
7511 | name[4] == 'n' && | |
7512 | name[5] == 'e' && | |
7513 | name[6] == 'd') | |
7514 | { /* defined */ | |
7515 | return KEY_defined; | |
7516 | } | |
7517 | ||
7518 | goto unknown; | |
7519 | ||
7520 | default: | |
7521 | goto unknown; | |
7522 | } | |
7523 | ||
7524 | case 'f': | |
7525 | if (name[1] == 'o' && | |
7526 | name[2] == 'r' && | |
7527 | name[3] == 'e' && | |
7528 | name[4] == 'a' && | |
7529 | name[5] == 'c' && | |
7530 | name[6] == 'h') | |
7531 | { /* foreach */ | |
7532 | return KEY_foreach; | |
7533 | } | |
7534 | ||
7535 | goto unknown; | |
7536 | ||
7537 | case 'g': | |
7538 | if (name[1] == 'e' && | |
7539 | name[2] == 't' && | |
7540 | name[3] == 'p') | |
7541 | { | |
7542 | switch (name[4]) | |
7543 | { | |
7544 | case 'g': | |
7545 | if (name[5] == 'r' && | |
7546 | name[6] == 'p') | |
7547 | { /* getpgrp */ | |
7548 | return -KEY_getpgrp; | |
7549 | } | |
7550 | ||
7551 | goto unknown; | |
7552 | ||
7553 | case 'p': | |
7554 | if (name[5] == 'i' && | |
7555 | name[6] == 'd') | |
7556 | { /* getppid */ | |
7557 | return -KEY_getppid; | |
7558 | } | |
7559 | ||
7560 | goto unknown; | |
7561 | ||
7562 | default: | |
7563 | goto unknown; | |
7564 | } | |
7565 | } | |
7566 | ||
7567 | goto unknown; | |
7568 | ||
7569 | case 'l': | |
7570 | if (name[1] == 'c' && | |
7571 | name[2] == 'f' && | |
7572 | name[3] == 'i' && | |
7573 | name[4] == 'r' && | |
7574 | name[5] == 's' && | |
7575 | name[6] == 't') | |
7576 | { /* lcfirst */ | |
7577 | return -KEY_lcfirst; | |
7578 | } | |
7579 | ||
7580 | goto unknown; | |
7581 | ||
7582 | case 'o': | |
7583 | if (name[1] == 'p' && | |
7584 | name[2] == 'e' && | |
7585 | name[3] == 'n' && | |
7586 | name[4] == 'd' && | |
7587 | name[5] == 'i' && | |
7588 | name[6] == 'r') | |
7589 | { /* opendir */ | |
7590 | return -KEY_opendir; | |
7591 | } | |
7592 | ||
7593 | goto unknown; | |
7594 | ||
7595 | case 'p': | |
7596 | if (name[1] == 'a' && | |
7597 | name[2] == 'c' && | |
7598 | name[3] == 'k' && | |
7599 | name[4] == 'a' && | |
7600 | name[5] == 'g' && | |
7601 | name[6] == 'e') | |
7602 | { /* package */ | |
7603 | return KEY_package; | |
7604 | } | |
7605 | ||
7606 | goto unknown; | |
7607 | ||
7608 | case 'r': | |
7609 | if (name[1] == 'e') | |
7610 | { | |
7611 | switch (name[2]) | |
7612 | { | |
7613 | case 'a': | |
7614 | if (name[3] == 'd' && | |
7615 | name[4] == 'd' && | |
7616 | name[5] == 'i' && | |
7617 | name[6] == 'r') | |
7618 | { /* readdir */ | |
7619 | return -KEY_readdir; | |
7620 | } | |
7621 | ||
7622 | goto unknown; | |
7623 | ||
7624 | case 'q': | |
7625 | if (name[3] == 'u' && | |
7626 | name[4] == 'i' && | |
7627 | name[5] == 'r' && | |
7628 | name[6] == 'e') | |
7629 | { /* require */ | |
7630 | return KEY_require; | |
7631 | } | |
7632 | ||
7633 | goto unknown; | |
7634 | ||
7635 | case 'v': | |
7636 | if (name[3] == 'e' && | |
7637 | name[4] == 'r' && | |
7638 | name[5] == 's' && | |
7639 | name[6] == 'e') | |
7640 | { /* reverse */ | |
7641 | return -KEY_reverse; | |
7642 | } | |
7643 | ||
7644 | goto unknown; | |
7645 | ||
7646 | default: | |
7647 | goto unknown; | |
7648 | } | |
7649 | } | |
7650 | ||
7651 | goto unknown; | |
7652 | ||
7653 | case 's': | |
7654 | switch (name[1]) | |
7655 | { | |
7656 | case 'e': | |
7657 | switch (name[2]) | |
7658 | { | |
7659 | case 'e': | |
7660 | if (name[3] == 'k' && | |
7661 | name[4] == 'd' && | |
7662 | name[5] == 'i' && | |
7663 | name[6] == 'r') | |
7664 | { /* seekdir */ | |
7665 | return -KEY_seekdir; | |
7666 | } | |
7667 | ||
7668 | goto unknown; | |
7669 | ||
7670 | case 't': | |
7671 | if (name[3] == 'p' && | |
7672 | name[4] == 'g' && | |
7673 | name[5] == 'r' && | |
7674 | name[6] == 'p') | |
7675 | { /* setpgrp */ | |
7676 | return -KEY_setpgrp; | |
7677 | } | |
7678 | ||
7679 | goto unknown; | |
7680 | ||
7681 | default: | |
7682 | goto unknown; | |
7683 | } | |
7684 | ||
7685 | case 'h': | |
7686 | if (name[2] == 'm' && | |
7687 | name[3] == 'r' && | |
7688 | name[4] == 'e' && | |
7689 | name[5] == 'a' && | |
7690 | name[6] == 'd') | |
7691 | { /* shmread */ | |
7692 | return -KEY_shmread; | |
7693 | } | |
7694 | ||
7695 | goto unknown; | |
7696 | ||
7697 | case 'p': | |
7698 | if (name[2] == 'r' && | |
7699 | name[3] == 'i' && | |
7700 | name[4] == 'n' && | |
7701 | name[5] == 't' && | |
7702 | name[6] == 'f') | |
7703 | { /* sprintf */ | |
7704 | return -KEY_sprintf; | |
7705 | } | |
7706 | ||
7707 | goto unknown; | |
7708 | ||
7709 | case 'y': | |
7710 | switch (name[2]) | |
7711 | { | |
7712 | case 'm': | |
7713 | if (name[3] == 'l' && | |
7714 | name[4] == 'i' && | |
7715 | name[5] == 'n' && | |
7716 | name[6] == 'k') | |
7717 | { /* symlink */ | |
7718 | return -KEY_symlink; | |
7719 | } | |
7720 | ||
7721 | goto unknown; | |
7722 | ||
7723 | case 's': | |
7724 | switch (name[3]) | |
7725 | { | |
7726 | case 'c': | |
7727 | if (name[4] == 'a' && | |
7728 | name[5] == 'l' && | |
7729 | name[6] == 'l') | |
7730 | { /* syscall */ | |
7731 | return -KEY_syscall; | |
7732 | } | |
7733 | ||
7734 | goto unknown; | |
7735 | ||
7736 | case 'o': | |
7737 | if (name[4] == 'p' && | |
7738 | name[5] == 'e' && | |
7739 | name[6] == 'n') | |
7740 | { /* sysopen */ | |
7741 | return -KEY_sysopen; | |
7742 | } | |
7743 | ||
7744 | goto unknown; | |
7745 | ||
7746 | case 'r': | |
7747 | if (name[4] == 'e' && | |
7748 | name[5] == 'a' && | |
7749 | name[6] == 'd') | |
7750 | { /* sysread */ | |
7751 | return -KEY_sysread; | |
7752 | } | |
7753 | ||
7754 | goto unknown; | |
7755 | ||
7756 | case 's': | |
7757 | if (name[4] == 'e' && | |
7758 | name[5] == 'e' && | |
7759 | name[6] == 'k') | |
7760 | { /* sysseek */ | |
7761 | return -KEY_sysseek; | |
7762 | } | |
7763 | ||
7764 | goto unknown; | |
7765 | ||
7766 | default: | |
7767 | goto unknown; | |
7768 | } | |
7769 | ||
7770 | default: | |
7771 | goto unknown; | |
7772 | } | |
7773 | ||
7774 | default: | |
7775 | goto unknown; | |
7776 | } | |
7777 | ||
7778 | case 't': | |
7779 | if (name[1] == 'e' && | |
7780 | name[2] == 'l' && | |
7781 | name[3] == 'l' && | |
7782 | name[4] == 'd' && | |
7783 | name[5] == 'i' && | |
7784 | name[6] == 'r') | |
7785 | { /* telldir */ | |
7786 | return -KEY_telldir; | |
7787 | } | |
7788 | ||
7789 | goto unknown; | |
7790 | ||
7791 | case 'u': | |
7792 | switch (name[1]) | |
7793 | { | |
7794 | case 'c': | |
7795 | if (name[2] == 'f' && | |
7796 | name[3] == 'i' && | |
7797 | name[4] == 'r' && | |
7798 | name[5] == 's' && | |
7799 | name[6] == 't') | |
7800 | { /* ucfirst */ | |
7801 | return -KEY_ucfirst; | |
7802 | } | |
7803 | ||
7804 | goto unknown; | |
7805 | ||
7806 | case 'n': | |
7807 | if (name[2] == 's' && | |
7808 | name[3] == 'h' && | |
7809 | name[4] == 'i' && | |
7810 | name[5] == 'f' && | |
7811 | name[6] == 't') | |
7812 | { /* unshift */ | |
7813 | return -KEY_unshift; | |
7814 | } | |
7815 | ||
7816 | goto unknown; | |
7817 | ||
7818 | default: | |
7819 | goto unknown; | |
7820 | } | |
7821 | ||
7822 | case 'w': | |
7823 | if (name[1] == 'a' && | |
7824 | name[2] == 'i' && | |
7825 | name[3] == 't' && | |
7826 | name[4] == 'p' && | |
7827 | name[5] == 'i' && | |
7828 | name[6] == 'd') | |
7829 | { /* waitpid */ | |
7830 | return -KEY_waitpid; | |
7831 | } | |
7832 | ||
7833 | goto unknown; | |
7834 | ||
7835 | default: | |
7836 | goto unknown; | |
7837 | } | |
7838 | ||
7839 | case 8: /* 26 tokens of length 8 */ | |
7840 | switch (name[0]) | |
7841 | { | |
7842 | case 'A': | |
7843 | if (name[1] == 'U' && | |
7844 | name[2] == 'T' && | |
7845 | name[3] == 'O' && | |
7846 | name[4] == 'L' && | |
7847 | name[5] == 'O' && | |
7848 | name[6] == 'A' && | |
7849 | name[7] == 'D') | |
7850 | { /* AUTOLOAD */ | |
7851 | return KEY_AUTOLOAD; | |
7852 | } | |
7853 | ||
7854 | goto unknown; | |
7855 | ||
7856 | case '_': | |
7857 | if (name[1] == '_') | |
7858 | { | |
7859 | switch (name[2]) | |
7860 | { | |
7861 | case 'D': | |
7862 | if (name[3] == 'A' && | |
7863 | name[4] == 'T' && | |
7864 | name[5] == 'A' && | |
7865 | name[6] == '_' && | |
7866 | name[7] == '_') | |
7867 | { /* __DATA__ */ | |
7868 | return KEY___DATA__; | |
7869 | } | |
7870 | ||
7871 | goto unknown; | |
7872 | ||
7873 | case 'F': | |
7874 | if (name[3] == 'I' && | |
7875 | name[4] == 'L' && | |
7876 | name[5] == 'E' && | |
7877 | name[6] == '_' && | |
7878 | name[7] == '_') | |
7879 | { /* __FILE__ */ | |
7880 | return -KEY___FILE__; | |
7881 | } | |
7882 | ||
7883 | goto unknown; | |
7884 | ||
7885 | case 'L': | |
7886 | if (name[3] == 'I' && | |
7887 | name[4] == 'N' && | |
7888 | name[5] == 'E' && | |
7889 | name[6] == '_' && | |
7890 | name[7] == '_') | |
7891 | { /* __LINE__ */ | |
7892 | return -KEY___LINE__; | |
7893 | } | |
7894 | ||
7895 | goto unknown; | |
7896 | ||
7897 | default: | |
7898 | goto unknown; | |
7899 | } | |
7900 | } | |
7901 | ||
7902 | goto unknown; | |
7903 | ||
7904 | case 'c': | |
7905 | switch (name[1]) | |
7906 | { | |
7907 | case 'l': | |
7908 | if (name[2] == 'o' && | |
7909 | name[3] == 's' && | |
7910 | name[4] == 'e' && | |
7911 | name[5] == 'd' && | |
7912 | name[6] == 'i' && | |
7913 | name[7] == 'r') | |
7914 | { /* closedir */ | |
7915 | return -KEY_closedir; | |
7916 | } | |
7917 | ||
7918 | goto unknown; | |
7919 | ||
7920 | case 'o': | |
7921 | if (name[2] == 'n' && | |
7922 | name[3] == 't' && | |
7923 | name[4] == 'i' && | |
7924 | name[5] == 'n' && | |
7925 | name[6] == 'u' && | |
7926 | name[7] == 'e') | |
7927 | { /* continue */ | |
7928 | return -KEY_continue; | |
7929 | } | |
7930 | ||
7931 | goto unknown; | |
7932 | ||
7933 | default: | |
7934 | goto unknown; | |
7935 | } | |
7936 | ||
7937 | case 'd': | |
7938 | if (name[1] == 'b' && | |
7939 | name[2] == 'm' && | |
7940 | name[3] == 'c' && | |
7941 | name[4] == 'l' && | |
7942 | name[5] == 'o' && | |
7943 | name[6] == 's' && | |
7944 | name[7] == 'e') | |
7945 | { /* dbmclose */ | |
7946 | return -KEY_dbmclose; | |
7947 | } | |
7948 | ||
7949 | goto unknown; | |
7950 | ||
7951 | case 'e': | |
7952 | if (name[1] == 'n' && | |
7953 | name[2] == 'd') | |
7954 | { | |
7955 | switch (name[3]) | |
7956 | { | |
7957 | case 'g': | |
7958 | if (name[4] == 'r' && | |
7959 | name[5] == 'e' && | |
7960 | name[6] == 'n' && | |
7961 | name[7] == 't') | |
7962 | { /* endgrent */ | |
7963 | return -KEY_endgrent; | |
7964 | } | |
7965 | ||
7966 | goto unknown; | |
7967 | ||
7968 | case 'p': | |
7969 | if (name[4] == 'w' && | |
7970 | name[5] == 'e' && | |
7971 | name[6] == 'n' && | |
7972 | name[7] == 't') | |
7973 | { /* endpwent */ | |
7974 | return -KEY_endpwent; | |
7975 | } | |
7976 | ||
7977 | goto unknown; | |
7978 | ||
7979 | default: | |
7980 | goto unknown; | |
7981 | } | |
7982 | } | |
7983 | ||
7984 | goto unknown; | |
7985 | ||
7986 | case 'f': | |
7987 | if (name[1] == 'o' && | |
7988 | name[2] == 'r' && | |
7989 | name[3] == 'm' && | |
7990 | name[4] == 'l' && | |
7991 | name[5] == 'i' && | |
7992 | name[6] == 'n' && | |
7993 | name[7] == 'e') | |
7994 | { /* formline */ | |
7995 | return -KEY_formline; | |
7996 | } | |
7997 | ||
7998 | goto unknown; | |
7999 | ||
8000 | case 'g': | |
8001 | if (name[1] == 'e' && | |
8002 | name[2] == 't') | |
8003 | { | |
8004 | switch (name[3]) | |
8005 | { | |
8006 | case 'g': | |
8007 | if (name[4] == 'r') | |
8008 | { | |
8009 | switch (name[5]) | |
8010 | { | |
8011 | case 'e': | |
8012 | if (name[6] == 'n' && | |
8013 | name[7] == 't') | |
8014 | { /* getgrent */ | |
8015 | return -KEY_getgrent; | |
8016 | } | |
8017 | ||
8018 | goto unknown; | |
8019 | ||
8020 | case 'g': | |
8021 | if (name[6] == 'i' && | |
8022 | name[7] == 'd') | |
8023 | { /* getgrgid */ | |
8024 | return -KEY_getgrgid; | |
8025 | } | |
8026 | ||
8027 | goto unknown; | |
8028 | ||
8029 | case 'n': | |
8030 | if (name[6] == 'a' && | |
8031 | name[7] == 'm') | |
8032 | { /* getgrnam */ | |
8033 | return -KEY_getgrnam; | |
8034 | } | |
8035 | ||
8036 | goto unknown; | |
8037 | ||
8038 | default: | |
8039 | goto unknown; | |
8040 | } | |
8041 | } | |
8042 | ||
8043 | goto unknown; | |
8044 | ||
8045 | case 'l': | |
8046 | if (name[4] == 'o' && | |
8047 | name[5] == 'g' && | |
8048 | name[6] == 'i' && | |
8049 | name[7] == 'n') | |
8050 | { /* getlogin */ | |
8051 | return -KEY_getlogin; | |
8052 | } | |
8053 | ||
8054 | goto unknown; | |
8055 | ||
8056 | case 'p': | |
8057 | if (name[4] == 'w') | |
8058 | { | |
8059 | switch (name[5]) | |
8060 | { | |
8061 | case 'e': | |
8062 | if (name[6] == 'n' && | |
8063 | name[7] == 't') | |
8064 | { /* getpwent */ | |
8065 | return -KEY_getpwent; | |
8066 | } | |
8067 | ||
8068 | goto unknown; | |
8069 | ||
8070 | case 'n': | |
8071 | if (name[6] == 'a' && | |
8072 | name[7] == 'm') | |
8073 | { /* getpwnam */ | |
8074 | return -KEY_getpwnam; | |
8075 | } | |
8076 | ||
8077 | goto unknown; | |
8078 | ||
8079 | case 'u': | |
8080 | if (name[6] == 'i' && | |
8081 | name[7] == 'd') | |
8082 | { /* getpwuid */ | |
8083 | return -KEY_getpwuid; | |
8084 | } | |
8085 | ||
8086 | goto unknown; | |
8087 | ||
8088 | default: | |
8089 | goto unknown; | |
8090 | } | |
8091 | } | |
8092 | ||
8093 | goto unknown; | |
8094 | ||
8095 | default: | |
8096 | goto unknown; | |
8097 | } | |
8098 | } | |
8099 | ||
8100 | goto unknown; | |
8101 | ||
8102 | case 'r': | |
8103 | if (name[1] == 'e' && | |
8104 | name[2] == 'a' && | |
8105 | name[3] == 'd') | |
8106 | { | |
8107 | switch (name[4]) | |
8108 | { | |
8109 | case 'l': | |
8110 | if (name[5] == 'i' && | |
8111 | name[6] == 'n') | |
8112 | { | |
8113 | switch (name[7]) | |
8114 | { | |
8115 | case 'e': | |
8116 | { /* readline */ | |
8117 | return -KEY_readline; | |
8118 | } | |
8119 | ||
4c3bbe0f MHM |
8120 | case 'k': |
8121 | { /* readlink */ | |
8122 | return -KEY_readlink; | |
8123 | } | |
8124 | ||
4c3bbe0f MHM |
8125 | default: |
8126 | goto unknown; | |
8127 | } | |
8128 | } | |
8129 | ||
8130 | goto unknown; | |
8131 | ||
8132 | case 'p': | |
8133 | if (name[5] == 'i' && | |
8134 | name[6] == 'p' && | |
8135 | name[7] == 'e') | |
8136 | { /* readpipe */ | |
8137 | return -KEY_readpipe; | |
8138 | } | |
8139 | ||
8140 | goto unknown; | |
8141 | ||
8142 | default: | |
8143 | goto unknown; | |
8144 | } | |
8145 | } | |
8146 | ||
8147 | goto unknown; | |
8148 | ||
8149 | case 's': | |
8150 | switch (name[1]) | |
8151 | { | |
8152 | case 'e': | |
8153 | if (name[2] == 't') | |
8154 | { | |
8155 | switch (name[3]) | |
8156 | { | |
8157 | case 'g': | |
8158 | if (name[4] == 'r' && | |
8159 | name[5] == 'e' && | |
8160 | name[6] == 'n' && | |
8161 | name[7] == 't') | |
8162 | { /* setgrent */ | |
8163 | return -KEY_setgrent; | |
8164 | } | |
8165 | ||
8166 | goto unknown; | |
8167 | ||
8168 | case 'p': | |
8169 | if (name[4] == 'w' && | |
8170 | name[5] == 'e' && | |
8171 | name[6] == 'n' && | |
8172 | name[7] == 't') | |
8173 | { /* setpwent */ | |
8174 | return -KEY_setpwent; | |
8175 | } | |
8176 | ||
8177 | goto unknown; | |
8178 | ||
8179 | default: | |
8180 | goto unknown; | |
8181 | } | |
8182 | } | |
8183 | ||
8184 | goto unknown; | |
8185 | ||
8186 | case 'h': | |
8187 | switch (name[2]) | |
8188 | { | |
8189 | case 'm': | |
8190 | if (name[3] == 'w' && | |
8191 | name[4] == 'r' && | |
8192 | name[5] == 'i' && | |
8193 | name[6] == 't' && | |
8194 | name[7] == 'e') | |
8195 | { /* shmwrite */ | |
8196 | return -KEY_shmwrite; | |
8197 | } | |
8198 | ||
8199 | goto unknown; | |
8200 | ||
8201 | case 'u': | |
8202 | if (name[3] == 't' && | |
8203 | name[4] == 'd' && | |
8204 | name[5] == 'o' && | |
8205 | name[6] == 'w' && | |
8206 | name[7] == 'n') | |
8207 | { /* shutdown */ | |
8208 | return -KEY_shutdown; | |
8209 | } | |
8210 | ||
8211 | goto unknown; | |
8212 | ||
8213 | default: | |
8214 | goto unknown; | |
8215 | } | |
8216 | ||
8217 | case 'y': | |
8218 | if (name[2] == 's' && | |
8219 | name[3] == 'w' && | |
8220 | name[4] == 'r' && | |
8221 | name[5] == 'i' && | |
8222 | name[6] == 't' && | |
8223 | name[7] == 'e') | |
8224 | { /* syswrite */ | |
8225 | return -KEY_syswrite; | |
8226 | } | |
8227 | ||
8228 | goto unknown; | |
8229 | ||
8230 | default: | |
8231 | goto unknown; | |
8232 | } | |
8233 | ||
8234 | case 't': | |
8235 | if (name[1] == 'r' && | |
8236 | name[2] == 'u' && | |
8237 | name[3] == 'n' && | |
8238 | name[4] == 'c' && | |
8239 | name[5] == 'a' && | |
8240 | name[6] == 't' && | |
8241 | name[7] == 'e') | |
8242 | { /* truncate */ | |
8243 | return -KEY_truncate; | |
8244 | } | |
8245 | ||
8246 | goto unknown; | |
8247 | ||
8248 | default: | |
8249 | goto unknown; | |
8250 | } | |
8251 | ||
8252 | case 9: /* 8 tokens of length 9 */ | |
8253 | switch (name[0]) | |
8254 | { | |
8255 | case 'e': | |
8256 | if (name[1] == 'n' && | |
8257 | name[2] == 'd' && | |
8258 | name[3] == 'n' && | |
8259 | name[4] == 'e' && | |
8260 | name[5] == 't' && | |
8261 | name[6] == 'e' && | |
8262 | name[7] == 'n' && | |
8263 | name[8] == 't') | |
8264 | { /* endnetent */ | |
8265 | return -KEY_endnetent; | |
8266 | } | |
8267 | ||
8268 | goto unknown; | |
8269 | ||
8270 | case 'g': | |
8271 | if (name[1] == 'e' && | |
8272 | name[2] == 't' && | |
8273 | name[3] == 'n' && | |
8274 | name[4] == 'e' && | |
8275 | name[5] == 't' && | |
8276 | name[6] == 'e' && | |
8277 | name[7] == 'n' && | |
8278 | name[8] == 't') | |
8279 | { /* getnetent */ | |
8280 | return -KEY_getnetent; | |
8281 | } | |
8282 | ||
8283 | goto unknown; | |
8284 | ||
8285 | case 'l': | |
8286 | if (name[1] == 'o' && | |
8287 | name[2] == 'c' && | |
8288 | name[3] == 'a' && | |
8289 | name[4] == 'l' && | |
8290 | name[5] == 't' && | |
8291 | name[6] == 'i' && | |
8292 | name[7] == 'm' && | |
8293 | name[8] == 'e') | |
8294 | { /* localtime */ | |
8295 | return -KEY_localtime; | |
8296 | } | |
8297 | ||
8298 | goto unknown; | |
8299 | ||
8300 | case 'p': | |
8301 | if (name[1] == 'r' && | |
8302 | name[2] == 'o' && | |
8303 | name[3] == 't' && | |
8304 | name[4] == 'o' && | |
8305 | name[5] == 't' && | |
8306 | name[6] == 'y' && | |
8307 | name[7] == 'p' && | |
8308 | name[8] == 'e') | |
8309 | { /* prototype */ | |
8310 | return KEY_prototype; | |
8311 | } | |
8312 | ||
8313 | goto unknown; | |
8314 | ||
8315 | case 'q': | |
8316 | if (name[1] == 'u' && | |
8317 | name[2] == 'o' && | |
8318 | name[3] == 't' && | |
8319 | name[4] == 'e' && | |
8320 | name[5] == 'm' && | |
8321 | name[6] == 'e' && | |
8322 | name[7] == 't' && | |
8323 | name[8] == 'a') | |
8324 | { /* quotemeta */ | |
8325 | return -KEY_quotemeta; | |
8326 | } | |
8327 | ||
8328 | goto unknown; | |
8329 | ||
8330 | case 'r': | |
8331 | if (name[1] == 'e' && | |
8332 | name[2] == 'w' && | |
8333 | name[3] == 'i' && | |
8334 | name[4] == 'n' && | |
8335 | name[5] == 'd' && | |
8336 | name[6] == 'd' && | |
8337 | name[7] == 'i' && | |
8338 | name[8] == 'r') | |
8339 | { /* rewinddir */ | |
8340 | return -KEY_rewinddir; | |
8341 | } | |
8342 | ||
8343 | goto unknown; | |
8344 | ||
8345 | case 's': | |
8346 | if (name[1] == 'e' && | |
8347 | name[2] == 't' && | |
8348 | name[3] == 'n' && | |
8349 | name[4] == 'e' && | |
8350 | name[5] == 't' && | |
8351 | name[6] == 'e' && | |
8352 | name[7] == 'n' && | |
8353 | name[8] == 't') | |
8354 | { /* setnetent */ | |
8355 | return -KEY_setnetent; | |
8356 | } | |
8357 | ||
8358 | goto unknown; | |
8359 | ||
8360 | case 'w': | |
8361 | if (name[1] == 'a' && | |
8362 | name[2] == 'n' && | |
8363 | name[3] == 't' && | |
8364 | name[4] == 'a' && | |
8365 | name[5] == 'r' && | |
8366 | name[6] == 'r' && | |
8367 | name[7] == 'a' && | |
8368 | name[8] == 'y') | |
8369 | { /* wantarray */ | |
8370 | return -KEY_wantarray; | |
8371 | } | |
8372 | ||
8373 | goto unknown; | |
8374 | ||
8375 | default: | |
8376 | goto unknown; | |
8377 | } | |
8378 | ||
8379 | case 10: /* 9 tokens of length 10 */ | |
8380 | switch (name[0]) | |
8381 | { | |
8382 | case 'e': | |
8383 | if (name[1] == 'n' && | |
8384 | name[2] == 'd') | |
8385 | { | |
8386 | switch (name[3]) | |
8387 | { | |
8388 | case 'h': | |
8389 | if (name[4] == 'o' && | |
8390 | name[5] == 's' && | |
8391 | name[6] == 't' && | |
8392 | name[7] == 'e' && | |
8393 | name[8] == 'n' && | |
8394 | name[9] == 't') | |
8395 | { /* endhostent */ | |
8396 | return -KEY_endhostent; | |
8397 | } | |
8398 | ||
8399 | goto unknown; | |
8400 | ||
8401 | case 's': | |
8402 | if (name[4] == 'e' && | |
8403 | name[5] == 'r' && | |
8404 | name[6] == 'v' && | |
8405 | name[7] == 'e' && | |
8406 | name[8] == 'n' && | |
8407 | name[9] == 't') | |
8408 | { /* endservent */ | |
8409 | return -KEY_endservent; | |
8410 | } | |
8411 | ||
8412 | goto unknown; | |
8413 | ||
8414 | default: | |
8415 | goto unknown; | |
8416 | } | |
8417 | } | |
8418 | ||
8419 | goto unknown; | |
8420 | ||
8421 | case 'g': | |
8422 | if (name[1] == 'e' && | |
8423 | name[2] == 't') | |
8424 | { | |
8425 | switch (name[3]) | |
8426 | { | |
8427 | case 'h': | |
8428 | if (name[4] == 'o' && | |
8429 | name[5] == 's' && | |
8430 | name[6] == 't' && | |
8431 | name[7] == 'e' && | |
8432 | name[8] == 'n' && | |
8433 | name[9] == 't') | |
8434 | { /* gethostent */ | |
8435 | return -KEY_gethostent; | |
8436 | } | |
8437 | ||
8438 | goto unknown; | |
8439 | ||
8440 | case 's': | |
8441 | switch (name[4]) | |
8442 | { | |
8443 | case 'e': | |
8444 | if (name[5] == 'r' && | |
8445 | name[6] == 'v' && | |
8446 | name[7] == 'e' && | |
8447 | name[8] == 'n' && | |
8448 | name[9] == 't') | |
8449 | { /* getservent */ | |
8450 | return -KEY_getservent; | |
8451 | } | |
8452 | ||
8453 | goto unknown; | |
8454 | ||
8455 | case 'o': | |
8456 | if (name[5] == 'c' && | |
8457 | name[6] == 'k' && | |
8458 | name[7] == 'o' && | |
8459 | name[8] == 'p' && | |
8460 | name[9] == 't') | |
8461 | { /* getsockopt */ | |
8462 | return -KEY_getsockopt; | |
8463 | } | |
8464 | ||
8465 | goto unknown; | |
8466 | ||
8467 | default: | |
8468 | goto unknown; | |
8469 | } | |
8470 | ||
8471 | default: | |
8472 | goto unknown; | |
8473 | } | |
8474 | } | |
8475 | ||
8476 | goto unknown; | |
8477 | ||
8478 | case 's': | |
8479 | switch (name[1]) | |
8480 | { | |
8481 | case 'e': | |
8482 | if (name[2] == 't') | |
8483 | { | |
8484 | switch (name[3]) | |
8485 | { | |
8486 | case 'h': | |
8487 | if (name[4] == 'o' && | |
8488 | name[5] == 's' && | |
8489 | name[6] == 't' && | |
8490 | name[7] == 'e' && | |
8491 | name[8] == 'n' && | |
8492 | name[9] == 't') | |
8493 | { /* sethostent */ | |
8494 | return -KEY_sethostent; | |
8495 | } | |
8496 | ||
8497 | goto unknown; | |
8498 | ||
8499 | case 's': | |
8500 | switch (name[4]) | |
8501 | { | |
8502 | case 'e': | |
8503 | if (name[5] == 'r' && | |
8504 | name[6] == 'v' && | |
8505 | name[7] == 'e' && | |
8506 | name[8] == 'n' && | |
8507 | name[9] == 't') | |
8508 | { /* setservent */ | |
8509 | return -KEY_setservent; | |
8510 | } | |
8511 | ||
8512 | goto unknown; | |
8513 | ||
8514 | case 'o': | |
8515 | if (name[5] == 'c' && | |
8516 | name[6] == 'k' && | |
8517 | name[7] == 'o' && | |
8518 | name[8] == 'p' && | |
8519 | name[9] == 't') | |
8520 | { /* setsockopt */ | |
8521 | return -KEY_setsockopt; | |
8522 | } | |
8523 | ||
8524 | goto unknown; | |
8525 | ||
8526 | default: | |
8527 | goto unknown; | |
8528 | } | |
8529 | ||
8530 | default: | |
8531 | goto unknown; | |
8532 | } | |
8533 | } | |
8534 | ||
8535 | goto unknown; | |
8536 | ||
8537 | case 'o': | |
8538 | if (name[2] == 'c' && | |
8539 | name[3] == 'k' && | |
8540 | name[4] == 'e' && | |
8541 | name[5] == 't' && | |
8542 | name[6] == 'p' && | |
8543 | name[7] == 'a' && | |
8544 | name[8] == 'i' && | |
8545 | name[9] == 'r') | |
8546 | { /* socketpair */ | |
8547 | return -KEY_socketpair; | |
8548 | } | |
8549 | ||
8550 | goto unknown; | |
8551 | ||
8552 | default: | |
8553 | goto unknown; | |
8554 | } | |
8555 | ||
8556 | default: | |
8557 | goto unknown; | |
e2e1dd5a | 8558 | } |
4c3bbe0f MHM |
8559 | |
8560 | case 11: /* 8 tokens of length 11 */ | |
8561 | switch (name[0]) | |
8562 | { | |
8563 | case '_': | |
8564 | if (name[1] == '_' && | |
8565 | name[2] == 'P' && | |
8566 | name[3] == 'A' && | |
8567 | name[4] == 'C' && | |
8568 | name[5] == 'K' && | |
8569 | name[6] == 'A' && | |
8570 | name[7] == 'G' && | |
8571 | name[8] == 'E' && | |
8572 | name[9] == '_' && | |
8573 | name[10] == '_') | |
8574 | { /* __PACKAGE__ */ | |
8575 | return -KEY___PACKAGE__; | |
8576 | } | |
8577 | ||
8578 | goto unknown; | |
8579 | ||
8580 | case 'e': | |
8581 | if (name[1] == 'n' && | |
8582 | name[2] == 'd' && | |
8583 | name[3] == 'p' && | |
8584 | name[4] == 'r' && | |
8585 | name[5] == 'o' && | |
8586 | name[6] == 't' && | |
8587 | name[7] == 'o' && | |
8588 | name[8] == 'e' && | |
8589 | name[9] == 'n' && | |
8590 | name[10] == 't') | |
8591 | { /* endprotoent */ | |
8592 | return -KEY_endprotoent; | |
8593 | } | |
8594 | ||
8595 | goto unknown; | |
8596 | ||
8597 | case 'g': | |
8598 | if (name[1] == 'e' && | |
8599 | name[2] == 't') | |
8600 | { | |
8601 | switch (name[3]) | |
8602 | { | |
8603 | case 'p': | |
8604 | switch (name[4]) | |
8605 | { | |
8606 | case 'e': | |
8607 | if (name[5] == 'e' && | |
8608 | name[6] == 'r' && | |
8609 | name[7] == 'n' && | |
8610 | name[8] == 'a' && | |
8611 | name[9] == 'm' && | |
8612 | name[10] == 'e') | |
8613 | { /* getpeername */ | |
8614 | return -KEY_getpeername; | |
8615 | } | |
8616 | ||
8617 | goto unknown; | |
8618 | ||
8619 | case 'r': | |
8620 | switch (name[5]) | |
8621 | { | |
8622 | case 'i': | |
8623 | if (name[6] == 'o' && | |
8624 | name[7] == 'r' && | |
8625 | name[8] == 'i' && | |
8626 | name[9] == 't' && | |
8627 | name[10] == 'y') | |
8628 | { /* getpriority */ | |
8629 | return -KEY_getpriority; | |
8630 | } | |
8631 | ||
8632 | goto unknown; | |
8633 | ||
8634 | case 'o': | |
8635 | if (name[6] == 't' && | |
8636 | name[7] == 'o' && | |
8637 | name[8] == 'e' && | |
8638 | name[9] == 'n' && | |
8639 | name[10] == 't') | |
8640 | { /* getprotoent */ | |
8641 | return -KEY_getprotoent; | |
8642 | } | |
8643 | ||
8644 | goto unknown; | |
8645 | ||
8646 | default: | |
8647 | goto unknown; | |
8648 | } | |
8649 | ||
8650 | default: | |
8651 | goto unknown; | |
8652 | } | |
8653 | ||
8654 | case 's': | |
8655 | if (name[4] == 'o' && | |
8656 | name[5] == 'c' && | |
8657 | name[6] == 'k' && | |
8658 | name[7] == 'n' && | |
8659 | name[8] == 'a' && | |
8660 | name[9] == 'm' && | |
8661 | name[10] == 'e') | |
8662 | { /* getsockname */ | |
8663 | return -KEY_getsockname; | |
8664 | } | |
8665 | ||
8666 | goto unknown; | |
8667 | ||
8668 | default: | |
8669 | goto unknown; | |
8670 | } | |
8671 | } | |
8672 | ||
8673 | goto unknown; | |
8674 | ||
8675 | case 's': | |
8676 | if (name[1] == 'e' && | |
8677 | name[2] == 't' && | |
8678 | name[3] == 'p' && | |
8679 | name[4] == 'r') | |
8680 | { | |
8681 | switch (name[5]) | |
8682 | { | |
8683 | case 'i': | |
8684 | if (name[6] == 'o' && | |
8685 | name[7] == 'r' && | |
8686 | name[8] == 'i' && | |
8687 | name[9] == 't' && | |
8688 | name[10] == 'y') | |
8689 | { /* setpriority */ | |
8690 | return -KEY_setpriority; | |
8691 | } | |
8692 | ||
8693 | goto unknown; | |
8694 | ||
8695 | case 'o': | |
8696 | if (name[6] == 't' && | |
8697 | name[7] == 'o' && | |
8698 | name[8] == 'e' && | |
8699 | name[9] == 'n' && | |
8700 | name[10] == 't') | |
8701 | { /* setprotoent */ | |
8702 | return -KEY_setprotoent; | |
8703 | } | |
8704 | ||
8705 | goto unknown; | |
8706 | ||
8707 | default: | |
8708 | goto unknown; | |
8709 | } | |
8710 | } | |
8711 | ||
8712 | goto unknown; | |
8713 | ||
8714 | default: | |
8715 | goto unknown; | |
e2e1dd5a | 8716 | } |
4c3bbe0f MHM |
8717 | |
8718 | case 12: /* 2 tokens of length 12 */ | |
8719 | if (name[0] == 'g' && | |
8720 | name[1] == 'e' && | |
8721 | name[2] == 't' && | |
8722 | name[3] == 'n' && | |
8723 | name[4] == 'e' && | |
8724 | name[5] == 't' && | |
8725 | name[6] == 'b' && | |
8726 | name[7] == 'y') | |
8727 | { | |
8728 | switch (name[8]) | |
8729 | { | |
8730 | case 'a': | |
8731 | if (name[9] == 'd' && | |
8732 | name[10] == 'd' && | |
8733 | name[11] == 'r') | |
8734 | { /* getnetbyaddr */ | |
8735 | return -KEY_getnetbyaddr; | |
8736 | } | |
8737 | ||
8738 | goto unknown; | |
8739 | ||
8740 | case 'n': | |
8741 | if (name[9] == 'a' && | |
8742 | name[10] == 'm' && | |
8743 | name[11] == 'e') | |
8744 | { /* getnetbyname */ | |
8745 | return -KEY_getnetbyname; | |
8746 | } | |
8747 | ||
8748 | goto unknown; | |
8749 | ||
8750 | default: | |
8751 | goto unknown; | |
8752 | } | |
e2e1dd5a | 8753 | } |
4c3bbe0f MHM |
8754 | |
8755 | goto unknown; | |
8756 | ||
8757 | case 13: /* 4 tokens of length 13 */ | |
8758 | if (name[0] == 'g' && | |
8759 | name[1] == 'e' && | |
8760 | name[2] == 't') | |
8761 | { | |
8762 | switch (name[3]) | |
8763 | { | |
8764 | case 'h': | |
8765 | if (name[4] == 'o' && | |
8766 | name[5] == 's' && | |
8767 | name[6] == 't' && | |
8768 | name[7] == 'b' && | |
8769 | name[8] == 'y') | |
8770 | { | |
8771 | switch (name[9]) | |
8772 | { | |
8773 | case 'a': | |
8774 | if (name[10] == 'd' && | |
8775 | name[11] == 'd' && | |
8776 | name[12] == 'r') | |
8777 | { /* gethostbyaddr */ | |
8778 | return -KEY_gethostbyaddr; | |
8779 | } | |
8780 | ||
8781 | goto unknown; | |
8782 | ||
8783 | case 'n': | |
8784 | if (name[10] == 'a' && | |
8785 | name[11] == 'm' && | |
8786 | name[12] == 'e') | |
8787 | { /* gethostbyname */ | |
8788 | return -KEY_gethostbyname; | |
8789 | } | |
8790 | ||
8791 | goto unknown; | |
8792 | ||
8793 | default: | |
8794 | goto unknown; | |
8795 | } | |
8796 | } | |
8797 | ||
8798 | goto unknown; | |
8799 | ||
8800 | case 's': | |
8801 | if (name[4] == 'e' && | |
8802 | name[5] == 'r' && | |
8803 | name[6] == 'v' && | |
8804 | name[7] == 'b' && | |
8805 | name[8] == 'y') | |
8806 | { | |
8807 | switch (name[9]) | |
8808 | { | |
8809 | case 'n': | |
8810 | if (name[10] == 'a' && | |
8811 | name[11] == 'm' && | |
8812 | name[12] == 'e') | |
8813 | { /* getservbyname */ | |
8814 | return -KEY_getservbyname; | |
8815 | } | |
8816 | ||
8817 | goto unknown; | |
8818 | ||
8819 | case 'p': | |
8820 | if (name[10] == 'o' && | |
8821 | name[11] == 'r' && | |
8822 | name[12] == 't') | |
8823 | { /* getservbyport */ | |
8824 | return -KEY_getservbyport; | |
8825 | } | |
8826 | ||
8827 | goto unknown; | |
8828 | ||
8829 | default: | |
8830 | goto unknown; | |
8831 | } | |
8832 | } | |
8833 | ||
8834 | goto unknown; | |
8835 | ||
8836 | default: | |
8837 | goto unknown; | |
8838 | } | |
e2e1dd5a | 8839 | } |
4c3bbe0f MHM |
8840 | |
8841 | goto unknown; | |
8842 | ||
8843 | case 14: /* 1 tokens of length 14 */ | |
8844 | if (name[0] == 'g' && | |
8845 | name[1] == 'e' && | |
8846 | name[2] == 't' && | |
8847 | name[3] == 'p' && | |
8848 | name[4] == 'r' && | |
8849 | name[5] == 'o' && | |
8850 | name[6] == 't' && | |
8851 | name[7] == 'o' && | |
8852 | name[8] == 'b' && | |
8853 | name[9] == 'y' && | |
8854 | name[10] == 'n' && | |
8855 | name[11] == 'a' && | |
8856 | name[12] == 'm' && | |
8857 | name[13] == 'e') | |
8858 | { /* getprotobyname */ | |
8859 | return -KEY_getprotobyname; | |
8860 | } | |
8861 | ||
8862 | goto unknown; | |
8863 | ||
8864 | case 16: /* 1 tokens of length 16 */ | |
8865 | if (name[0] == 'g' && | |
8866 | name[1] == 'e' && | |
8867 | name[2] == 't' && | |
8868 | name[3] == 'p' && | |
8869 | name[4] == 'r' && | |
8870 | name[5] == 'o' && | |
8871 | name[6] == 't' && | |
8872 | name[7] == 'o' && | |
8873 | name[8] == 'b' && | |
8874 | name[9] == 'y' && | |
8875 | name[10] == 'n' && | |
8876 | name[11] == 'u' && | |
8877 | name[12] == 'm' && | |
8878 | name[13] == 'b' && | |
8879 | name[14] == 'e' && | |
8880 | name[15] == 'r') | |
8881 | { /* getprotobynumber */ | |
8882 | return -KEY_getprotobynumber; | |
8883 | } | |
8884 | ||
8885 | goto unknown; | |
8886 | ||
8887 | default: | |
8888 | goto unknown; | |
e2e1dd5a | 8889 | } |
4c3bbe0f MHM |
8890 | |
8891 | unknown: | |
e2e1dd5a | 8892 | return 0; |
a687059c LW |
8893 | } |
8894 | ||
76e3520e | 8895 | STATIC void |
bfed75c6 | 8896 | S_checkcomma(pTHX_ register char *s, char *name, const char *what) |
a687059c | 8897 | { |
2f3197b3 LW |
8898 | char *w; |
8899 | ||
d008e5eb | 8900 | if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */ |
d008e5eb GS |
8901 | if (ckWARN(WARN_SYNTAX)) { |
8902 | int level = 1; | |
8903 | for (w = s+2; *w && level; w++) { | |
8904 | if (*w == '(') | |
8905 | ++level; | |
8906 | else if (*w == ')') | |
8907 | --level; | |
8908 | } | |
8909 | if (*w) | |
8910 | for (; *w && isSPACE(*w); w++) ; | |
8911 | if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */ | |
9014280d | 8912 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
65cec589 | 8913 | "%s (...) interpreted as function",name); |
d008e5eb | 8914 | } |
2f3197b3 | 8915 | } |
3280af22 | 8916 | while (s < PL_bufend && isSPACE(*s)) |
2f3197b3 | 8917 | s++; |
a687059c LW |
8918 | if (*s == '(') |
8919 | s++; | |
3280af22 | 8920 | while (s < PL_bufend && isSPACE(*s)) |
a687059c | 8921 | s++; |
7e2040f0 | 8922 | if (isIDFIRST_lazy_if(s,UTF)) { |
2f3197b3 | 8923 | w = s++; |
7e2040f0 | 8924 | while (isALNUM_lazy_if(s,UTF)) |
a687059c | 8925 | s++; |
3280af22 | 8926 | while (s < PL_bufend && isSPACE(*s)) |
a687059c | 8927 | s++; |
e929a76b | 8928 | if (*s == ',') { |
463ee0b2 | 8929 | int kw; |
e929a76b | 8930 | *s = '\0'; |
864dbfa3 | 8931 | kw = keyword(w, s - w) || get_cv(w, FALSE) != 0; |
e929a76b | 8932 | *s = ','; |
463ee0b2 | 8933 | if (kw) |
e929a76b | 8934 | return; |
cea2e8a9 | 8935 | Perl_croak(aTHX_ "No comma allowed after %s", what); |
463ee0b2 LW |
8936 | } |
8937 | } | |
8938 | } | |
8939 | ||
423cee85 JH |
8940 | /* Either returns sv, or mortalizes sv and returns a new SV*. |
8941 | Best used as sv=new_constant(..., sv, ...). | |
8942 | If s, pv are NULL, calls subroutine with one argument, | |
8943 | and type is used with error messages only. */ | |
8944 | ||
b3ac6de7 | 8945 | STATIC SV * |
7fc63493 | 8946 | S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv, |
9b0e499b | 8947 | const char *type) |
b3ac6de7 | 8948 | { |
27da23d5 | 8949 | dVAR; dSP; |
3280af22 | 8950 | HV *table = GvHV(PL_hintgv); /* ^H */ |
b3ac6de7 | 8951 | SV *res; |
b3ac6de7 IZ |
8952 | SV **cvp; |
8953 | SV *cv, *typesv; | |
f0af216f | 8954 | const char *why1, *why2, *why3; |
4e553d73 | 8955 | |
f0af216f | 8956 | if (!table || !(PL_hints & HINT_LOCALIZE_HH)) { |
423cee85 JH |
8957 | SV *msg; |
8958 | ||
f0af216f | 8959 | why2 = strEQ(key,"charnames") |
41ab332f | 8960 | ? "(possibly a missing \"use charnames ...\")" |
f0af216f | 8961 | : ""; |
4e553d73 | 8962 | msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s", |
41ab332f JH |
8963 | (type ? type: "undef"), why2); |
8964 | ||
8965 | /* This is convoluted and evil ("goto considered harmful") | |
8966 | * but I do not understand the intricacies of all the different | |
8967 | * failure modes of %^H in here. The goal here is to make | |
8968 | * the most probable error message user-friendly. --jhi */ | |
8969 | ||
8970 | goto msgdone; | |
8971 | ||
423cee85 | 8972 | report: |
4e553d73 | 8973 | msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s", |
f0af216f | 8974 | (type ? type: "undef"), why1, why2, why3); |
41ab332f | 8975 | msgdone: |
423cee85 JH |
8976 | yyerror(SvPVX(msg)); |
8977 | SvREFCNT_dec(msg); | |
8978 | return sv; | |
8979 | } | |
b3ac6de7 IZ |
8980 | cvp = hv_fetch(table, key, strlen(key), FALSE); |
8981 | if (!cvp || !SvOK(*cvp)) { | |
423cee85 JH |
8982 | why1 = "$^H{"; |
8983 | why2 = key; | |
f0af216f | 8984 | why3 = "} is not defined"; |
423cee85 | 8985 | goto report; |
b3ac6de7 IZ |
8986 | } |
8987 | sv_2mortal(sv); /* Parent created it permanently */ | |
8988 | cv = *cvp; | |
423cee85 JH |
8989 | if (!pv && s) |
8990 | pv = sv_2mortal(newSVpvn(s, len)); | |
8991 | if (type && pv) | |
8992 | typesv = sv_2mortal(newSVpv(type, 0)); | |
b3ac6de7 | 8993 | else |
423cee85 | 8994 | typesv = &PL_sv_undef; |
4e553d73 | 8995 | |
e788e7d3 | 8996 | PUSHSTACKi(PERLSI_OVERLOAD); |
423cee85 JH |
8997 | ENTER ; |
8998 | SAVETMPS; | |
4e553d73 | 8999 | |
423cee85 | 9000 | PUSHMARK(SP) ; |
a5845cb7 | 9001 | EXTEND(sp, 3); |
423cee85 JH |
9002 | if (pv) |
9003 | PUSHs(pv); | |
b3ac6de7 | 9004 | PUSHs(sv); |
423cee85 JH |
9005 | if (pv) |
9006 | PUSHs(typesv); | |
b3ac6de7 | 9007 | PUTBACK; |
423cee85 | 9008 | call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL)); |
4e553d73 | 9009 | |
423cee85 | 9010 | SPAGAIN ; |
4e553d73 | 9011 | |
423cee85 | 9012 | /* Check the eval first */ |
9b0e499b | 9013 | if (!PL_in_eval && SvTRUE(ERRSV)) { |
423cee85 JH |
9014 | STRLEN n_a; |
9015 | sv_catpv(ERRSV, "Propagated"); | |
9016 | yyerror(SvPV(ERRSV, n_a)); /* Duplicates the message inside eval */ | |
e1f15930 | 9017 | (void)POPs; |
423cee85 JH |
9018 | res = SvREFCNT_inc(sv); |
9019 | } | |
9020 | else { | |
9021 | res = POPs; | |
e1f15930 | 9022 | (void)SvREFCNT_inc(res); |
423cee85 | 9023 | } |
4e553d73 | 9024 | |
423cee85 JH |
9025 | PUTBACK ; |
9026 | FREETMPS ; | |
9027 | LEAVE ; | |
b3ac6de7 | 9028 | POPSTACK; |
4e553d73 | 9029 | |
b3ac6de7 | 9030 | if (!SvOK(res)) { |
423cee85 JH |
9031 | why1 = "Call to &{$^H{"; |
9032 | why2 = key; | |
f0af216f | 9033 | why3 = "}} did not return a defined value"; |
423cee85 JH |
9034 | sv = res; |
9035 | goto report; | |
9b0e499b | 9036 | } |
423cee85 | 9037 | |
9b0e499b | 9038 | return res; |
b3ac6de7 | 9039 | } |
4e553d73 | 9040 | |
d0a148a6 NC |
9041 | /* Returns a NUL terminated string, with the length of the string written to |
9042 | *slp | |
9043 | */ | |
76e3520e | 9044 | STATIC char * |
cea2e8a9 | 9045 | S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp) |
463ee0b2 LW |
9046 | { |
9047 | register char *d = dest; | |
8903cb82 | 9048 | register char *e = d + destlen - 3; /* two-character token, ending NUL */ |
463ee0b2 | 9049 | for (;;) { |
8903cb82 | 9050 | if (d >= e) |
cea2e8a9 | 9051 | Perl_croak(aTHX_ ident_too_long); |
834a4ddd | 9052 | if (isALNUM(*s)) /* UTF handled below */ |
463ee0b2 | 9053 | *d++ = *s++; |
7e2040f0 | 9054 | else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) { |
463ee0b2 LW |
9055 | *d++ = ':'; |
9056 | *d++ = ':'; | |
9057 | s++; | |
9058 | } | |
c3e0f903 | 9059 | else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') { |
463ee0b2 LW |
9060 | *d++ = *s++; |
9061 | *d++ = *s++; | |
9062 | } | |
fd400ab9 | 9063 | else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
a0ed51b3 | 9064 | char *t = s + UTF8SKIP(s); |
fd400ab9 | 9065 | while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
a0ed51b3 LW |
9066 | t += UTF8SKIP(t); |
9067 | if (d + (t - s) > e) | |
cea2e8a9 | 9068 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 LW |
9069 | Copy(s, d, t - s, char); |
9070 | d += t - s; | |
9071 | s = t; | |
9072 | } | |
463ee0b2 LW |
9073 | else { |
9074 | *d = '\0'; | |
9075 | *slp = d - dest; | |
9076 | return s; | |
e929a76b | 9077 | } |
378cc40b LW |
9078 | } |
9079 | } | |
9080 | ||
76e3520e | 9081 | STATIC char * |
cea2e8a9 | 9082 | S_scan_ident(pTHX_ register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni) |
378cc40b LW |
9083 | { |
9084 | register char *d; | |
8903cb82 | 9085 | register char *e; |
79072805 | 9086 | char *bracket = 0; |
748a9306 | 9087 | char funny = *s++; |
378cc40b | 9088 | |
a0d0e21e LW |
9089 | if (isSPACE(*s)) |
9090 | s = skipspace(s); | |
378cc40b | 9091 | d = dest; |
8903cb82 | 9092 | e = d + destlen - 3; /* two-character token, ending NUL */ |
de3bb511 | 9093 | if (isDIGIT(*s)) { |
8903cb82 | 9094 | while (isDIGIT(*s)) { |
9095 | if (d >= e) | |
cea2e8a9 | 9096 | Perl_croak(aTHX_ ident_too_long); |
378cc40b | 9097 | *d++ = *s++; |
8903cb82 | 9098 | } |
378cc40b LW |
9099 | } |
9100 | else { | |
463ee0b2 | 9101 | for (;;) { |
8903cb82 | 9102 | if (d >= e) |
cea2e8a9 | 9103 | Perl_croak(aTHX_ ident_too_long); |
834a4ddd | 9104 | if (isALNUM(*s)) /* UTF handled below */ |
463ee0b2 | 9105 | *d++ = *s++; |
7e2040f0 | 9106 | else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) { |
463ee0b2 LW |
9107 | *d++ = ':'; |
9108 | *d++ = ':'; | |
9109 | s++; | |
9110 | } | |
a0d0e21e | 9111 | else if (*s == ':' && s[1] == ':') { |
463ee0b2 LW |
9112 | *d++ = *s++; |
9113 | *d++ = *s++; | |
9114 | } | |
fd400ab9 | 9115 | else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
a0ed51b3 | 9116 | char *t = s + UTF8SKIP(s); |
fd400ab9 | 9117 | while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
a0ed51b3 LW |
9118 | t += UTF8SKIP(t); |
9119 | if (d + (t - s) > e) | |
cea2e8a9 | 9120 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 LW |
9121 | Copy(s, d, t - s, char); |
9122 | d += t - s; | |
9123 | s = t; | |
9124 | } | |
463ee0b2 LW |
9125 | else |
9126 | break; | |
9127 | } | |
378cc40b LW |
9128 | } |
9129 | *d = '\0'; | |
9130 | d = dest; | |
79072805 | 9131 | if (*d) { |
3280af22 NIS |
9132 | if (PL_lex_state != LEX_NORMAL) |
9133 | PL_lex_state = LEX_INTERPENDMAYBE; | |
79072805 | 9134 | return s; |
378cc40b | 9135 | } |
748a9306 | 9136 | if (*s == '$' && s[1] && |
3792a11b | 9137 | (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) ) |
5cd24f17 | 9138 | { |
4810e5ec | 9139 | return s; |
5cd24f17 | 9140 | } |
79072805 LW |
9141 | if (*s == '{') { |
9142 | bracket = s; | |
9143 | s++; | |
9144 | } | |
9145 | else if (ck_uni) | |
9146 | check_uni(); | |
93a17b20 | 9147 | if (s < send) |
79072805 LW |
9148 | *d = *s++; |
9149 | d[1] = '\0'; | |
2b92dfce | 9150 | if (*d == '^' && *s && isCONTROLVAR(*s)) { |
bbce6d69 | 9151 | *d = toCTRL(*s); |
9152 | s++; | |
de3bb511 | 9153 | } |
79072805 | 9154 | if (bracket) { |
748a9306 | 9155 | if (isSPACE(s[-1])) { |
fa83b5b6 | 9156 | while (s < send) { |
9157 | char ch = *s++; | |
bf4acbe4 | 9158 | if (!SPACE_OR_TAB(ch)) { |
fa83b5b6 | 9159 | *d = ch; |
9160 | break; | |
9161 | } | |
9162 | } | |
748a9306 | 9163 | } |
7e2040f0 | 9164 | if (isIDFIRST_lazy_if(d,UTF)) { |
79072805 | 9165 | d++; |
a0ed51b3 LW |
9166 | if (UTF) { |
9167 | e = s; | |
155aba94 | 9168 | while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') { |
a0ed51b3 | 9169 | e += UTF8SKIP(e); |
fd400ab9 | 9170 | while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e)) |
a0ed51b3 LW |
9171 | e += UTF8SKIP(e); |
9172 | } | |
9173 | Copy(s, d, e - s, char); | |
9174 | d += e - s; | |
9175 | s = e; | |
9176 | } | |
9177 | else { | |
2b92dfce | 9178 | while ((isALNUM(*s) || *s == ':') && d < e) |
a0ed51b3 | 9179 | *d++ = *s++; |
2b92dfce | 9180 | if (d >= e) |
cea2e8a9 | 9181 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 | 9182 | } |
79072805 | 9183 | *d = '\0'; |
bf4acbe4 | 9184 | while (s < send && SPACE_OR_TAB(*s)) s++; |
ff68c719 | 9185 | if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) { |
599cee73 | 9186 | if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) { |
dff6d3cd | 9187 | const char *brack = *s == '[' ? "[...]" : "{...}"; |
9014280d | 9188 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
599cee73 | 9189 | "Ambiguous use of %c{%s%s} resolved to %c%s%s", |
748a9306 LW |
9190 | funny, dest, brack, funny, dest, brack); |
9191 | } | |
79072805 | 9192 | bracket++; |
a0be28da | 9193 | PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK); |
79072805 LW |
9194 | return s; |
9195 | } | |
4e553d73 NIS |
9196 | } |
9197 | /* Handle extended ${^Foo} variables | |
2b92dfce GS |
9198 | * 1999-02-27 mjd-perl-patch@plover.com */ |
9199 | else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */ | |
9200 | && isALNUM(*s)) | |
9201 | { | |
9202 | d++; | |
9203 | while (isALNUM(*s) && d < e) { | |
9204 | *d++ = *s++; | |
9205 | } | |
9206 | if (d >= e) | |
cea2e8a9 | 9207 | Perl_croak(aTHX_ ident_too_long); |
2b92dfce | 9208 | *d = '\0'; |
79072805 LW |
9209 | } |
9210 | if (*s == '}') { | |
9211 | s++; | |
7df0d042 | 9212 | if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) { |
3280af22 | 9213 | PL_lex_state = LEX_INTERPEND; |
7df0d042 AE |
9214 | PL_expect = XREF; |
9215 | } | |
748a9306 LW |
9216 | if (funny == '#') |
9217 | funny = '@'; | |
d008e5eb | 9218 | if (PL_lex_state == LEX_NORMAL) { |
d008e5eb | 9219 | if (ckWARN(WARN_AMBIGUOUS) && |
864dbfa3 | 9220 | (keyword(dest, d - dest) || get_cv(dest, FALSE))) |
d008e5eb | 9221 | { |
9014280d | 9222 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
d008e5eb GS |
9223 | "Ambiguous use of %c{%s} resolved to %c%s", |
9224 | funny, dest, funny, dest); | |
9225 | } | |
9226 | } | |
79072805 LW |
9227 | } |
9228 | else { | |
9229 | s = bracket; /* let the parser handle it */ | |
93a17b20 | 9230 | *dest = '\0'; |
79072805 LW |
9231 | } |
9232 | } | |
3280af22 NIS |
9233 | else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s)) |
9234 | PL_lex_state = LEX_INTERPEND; | |
378cc40b LW |
9235 | return s; |
9236 | } | |
9237 | ||
cea2e8a9 | 9238 | void |
2b36a5a0 | 9239 | Perl_pmflag(pTHX_ U32* pmfl, int ch) |
a0d0e21e | 9240 | { |
bbce6d69 | 9241 | if (ch == 'i') |
a0d0e21e | 9242 | *pmfl |= PMf_FOLD; |
a0d0e21e LW |
9243 | else if (ch == 'g') |
9244 | *pmfl |= PMf_GLOBAL; | |
c90c0ff4 | 9245 | else if (ch == 'c') |
9246 | *pmfl |= PMf_CONTINUE; | |
a0d0e21e LW |
9247 | else if (ch == 'o') |
9248 | *pmfl |= PMf_KEEP; | |
9249 | else if (ch == 'm') | |
9250 | *pmfl |= PMf_MULTILINE; | |
9251 | else if (ch == 's') | |
9252 | *pmfl |= PMf_SINGLELINE; | |
9253 | else if (ch == 'x') | |
9254 | *pmfl |= PMf_EXTENDED; | |
9255 | } | |
378cc40b | 9256 | |
76e3520e | 9257 | STATIC char * |
cea2e8a9 | 9258 | S_scan_pat(pTHX_ char *start, I32 type) |
378cc40b | 9259 | { |
79072805 LW |
9260 | PMOP *pm; |
9261 | char *s; | |
378cc40b | 9262 | |
09bef843 | 9263 | s = scan_str(start,FALSE,FALSE); |
37fd879b | 9264 | if (!s) |
cea2e8a9 | 9265 | Perl_croak(aTHX_ "Search pattern not terminated"); |
bbce6d69 | 9266 | |
8782bef2 | 9267 | pm = (PMOP*)newPMOP(type, 0); |
3280af22 | 9268 | if (PL_multi_open == '?') |
79072805 | 9269 | pm->op_pmflags |= PMf_ONCE; |
8782bef2 GB |
9270 | if(type == OP_QR) { |
9271 | while (*s && strchr("iomsx", *s)) | |
9272 | pmflag(&pm->op_pmflags,*s++); | |
9273 | } | |
9274 | else { | |
9275 | while (*s && strchr("iogcmsx", *s)) | |
9276 | pmflag(&pm->op_pmflags,*s++); | |
9277 | } | |
4ac733c9 | 9278 | /* issue a warning if /c is specified,but /g is not */ |
bfed75c6 | 9279 | if (ckWARN(WARN_REGEXP) && |
4ac733c9 MJD |
9280 | (pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)) |
9281 | { | |
9282 | Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_without_g); | |
9283 | } | |
9284 | ||
4633a7c4 | 9285 | pm->op_pmpermflags = pm->op_pmflags; |
bbce6d69 | 9286 | |
3280af22 | 9287 | PL_lex_op = (OP*)pm; |
79072805 | 9288 | yylval.ival = OP_MATCH; |
378cc40b LW |
9289 | return s; |
9290 | } | |
9291 | ||
76e3520e | 9292 | STATIC char * |
cea2e8a9 | 9293 | S_scan_subst(pTHX_ char *start) |
79072805 | 9294 | { |
27da23d5 | 9295 | dVAR; |
a0d0e21e | 9296 | register char *s; |
79072805 | 9297 | register PMOP *pm; |
4fdae800 | 9298 | I32 first_start; |
79072805 LW |
9299 | I32 es = 0; |
9300 | ||
79072805 LW |
9301 | yylval.ival = OP_NULL; |
9302 | ||
09bef843 | 9303 | s = scan_str(start,FALSE,FALSE); |
79072805 | 9304 | |
37fd879b | 9305 | if (!s) |
cea2e8a9 | 9306 | Perl_croak(aTHX_ "Substitution pattern not terminated"); |
79072805 | 9307 | |
3280af22 | 9308 | if (s[-1] == PL_multi_open) |
79072805 LW |
9309 | s--; |
9310 | ||
3280af22 | 9311 | first_start = PL_multi_start; |
09bef843 | 9312 | s = scan_str(s,FALSE,FALSE); |
79072805 | 9313 | if (!s) { |
37fd879b | 9314 | if (PL_lex_stuff) { |
3280af22 | 9315 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
9316 | PL_lex_stuff = Nullsv; |
9317 | } | |
cea2e8a9 | 9318 | Perl_croak(aTHX_ "Substitution replacement not terminated"); |
a687059c | 9319 | } |
3280af22 | 9320 | PL_multi_start = first_start; /* so whole substitution is taken together */ |
2f3197b3 | 9321 | |
79072805 | 9322 | pm = (PMOP*)newPMOP(OP_SUBST, 0); |
48c036b1 | 9323 | while (*s) { |
a687059c LW |
9324 | if (*s == 'e') { |
9325 | s++; | |
2f3197b3 | 9326 | es++; |
a687059c | 9327 | } |
b3eb6a9b | 9328 | else if (strchr("iogcmsx", *s)) |
a0d0e21e | 9329 | pmflag(&pm->op_pmflags,*s++); |
48c036b1 GS |
9330 | else |
9331 | break; | |
378cc40b | 9332 | } |
79072805 | 9333 | |
64e578a2 MJD |
9334 | /* /c is not meaningful with s/// */ |
9335 | if (ckWARN(WARN_REGEXP) && (pm->op_pmflags & PMf_CONTINUE)) | |
4ac733c9 | 9336 | { |
64e578a2 | 9337 | Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_in_subst); |
4ac733c9 MJD |
9338 | } |
9339 | ||
79072805 LW |
9340 | if (es) { |
9341 | SV *repl; | |
0244c3a4 GS |
9342 | PL_sublex_info.super_bufptr = s; |
9343 | PL_sublex_info.super_bufend = PL_bufend; | |
9344 | PL_multi_end = 0; | |
79072805 | 9345 | pm->op_pmflags |= PMf_EVAL; |
79cb57f6 | 9346 | repl = newSVpvn("",0); |
463ee0b2 | 9347 | while (es-- > 0) |
a0d0e21e | 9348 | sv_catpv(repl, es ? "eval " : "do "); |
79072805 | 9349 | sv_catpvn(repl, "{ ", 2); |
3280af22 | 9350 | sv_catsv(repl, PL_lex_repl); |
79072805 | 9351 | sv_catpvn(repl, " };", 2); |
25da4f38 | 9352 | SvEVALED_on(repl); |
3280af22 NIS |
9353 | SvREFCNT_dec(PL_lex_repl); |
9354 | PL_lex_repl = repl; | |
378cc40b | 9355 | } |
79072805 | 9356 | |
4633a7c4 | 9357 | pm->op_pmpermflags = pm->op_pmflags; |
3280af22 | 9358 | PL_lex_op = (OP*)pm; |
79072805 | 9359 | yylval.ival = OP_SUBST; |
378cc40b LW |
9360 | return s; |
9361 | } | |
9362 | ||
76e3520e | 9363 | STATIC char * |
cea2e8a9 | 9364 | S_scan_trans(pTHX_ char *start) |
378cc40b | 9365 | { |
a0d0e21e | 9366 | register char* s; |
11343788 | 9367 | OP *o; |
79072805 LW |
9368 | short *tbl; |
9369 | I32 squash; | |
a0ed51b3 | 9370 | I32 del; |
79072805 LW |
9371 | I32 complement; |
9372 | ||
9373 | yylval.ival = OP_NULL; | |
9374 | ||
09bef843 | 9375 | s = scan_str(start,FALSE,FALSE); |
37fd879b | 9376 | if (!s) |
cea2e8a9 | 9377 | Perl_croak(aTHX_ "Transliteration pattern not terminated"); |
3280af22 | 9378 | if (s[-1] == PL_multi_open) |
2f3197b3 LW |
9379 | s--; |
9380 | ||
09bef843 | 9381 | s = scan_str(s,FALSE,FALSE); |
79072805 | 9382 | if (!s) { |
37fd879b | 9383 | if (PL_lex_stuff) { |
3280af22 | 9384 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
9385 | PL_lex_stuff = Nullsv; |
9386 | } | |
cea2e8a9 | 9387 | Perl_croak(aTHX_ "Transliteration replacement not terminated"); |
a687059c | 9388 | } |
79072805 | 9389 | |
a0ed51b3 | 9390 | complement = del = squash = 0; |
7a1e2023 NC |
9391 | while (1) { |
9392 | switch (*s) { | |
9393 | case 'c': | |
79072805 | 9394 | complement = OPpTRANS_COMPLEMENT; |
7a1e2023 NC |
9395 | break; |
9396 | case 'd': | |
a0ed51b3 | 9397 | del = OPpTRANS_DELETE; |
7a1e2023 NC |
9398 | break; |
9399 | case 's': | |
79072805 | 9400 | squash = OPpTRANS_SQUASH; |
7a1e2023 NC |
9401 | break; |
9402 | default: | |
9403 | goto no_more; | |
9404 | } | |
395c3793 LW |
9405 | s++; |
9406 | } | |
7a1e2023 | 9407 | no_more: |
8973db79 JH |
9408 | |
9409 | New(803, tbl, complement&&!del?258:256, short); | |
9410 | o = newPVOP(OP_TRANS, 0, (char*)tbl); | |
59f00321 RGS |
9411 | o->op_private &= ~OPpTRANS_ALL; |
9412 | o->op_private |= del|squash|complement| | |
7948272d NIS |
9413 | (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)| |
9414 | (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0); | |
79072805 | 9415 | |
3280af22 | 9416 | PL_lex_op = o; |
79072805 LW |
9417 | yylval.ival = OP_TRANS; |
9418 | return s; | |
9419 | } | |
9420 | ||
76e3520e | 9421 | STATIC char * |
cea2e8a9 | 9422 | S_scan_heredoc(pTHX_ register char *s) |
79072805 LW |
9423 | { |
9424 | SV *herewas; | |
9425 | I32 op_type = OP_SCALAR; | |
9426 | I32 len; | |
9427 | SV *tmpstr; | |
9428 | char term; | |
73d840c0 AL |
9429 | const char newline[] = "\n"; |
9430 | const char *found_newline; | |
79072805 | 9431 | register char *d; |
fc36a67e | 9432 | register char *e; |
4633a7c4 | 9433 | char *peek; |
3280af22 | 9434 | int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR)); |
79072805 LW |
9435 | |
9436 | s += 2; | |
3280af22 NIS |
9437 | d = PL_tokenbuf; |
9438 | e = PL_tokenbuf + sizeof PL_tokenbuf - 1; | |
fd2d0953 | 9439 | if (!outer) |
79072805 | 9440 | *d++ = '\n'; |
bf4acbe4 | 9441 | for (peek = s; SPACE_OR_TAB(*peek); peek++) ; |
3792a11b | 9442 | if (*peek == '`' || *peek == '\'' || *peek =='"') { |
4633a7c4 | 9443 | s = peek; |
79072805 | 9444 | term = *s++; |
3280af22 | 9445 | s = delimcpy(d, e, s, PL_bufend, term, &len); |
fc36a67e | 9446 | d += len; |
3280af22 | 9447 | if (s < PL_bufend) |
79072805 | 9448 | s++; |
79072805 LW |
9449 | } |
9450 | else { | |
9451 | if (*s == '\\') | |
9452 | s++, term = '\''; | |
9453 | else | |
9454 | term = '"'; | |
7e2040f0 | 9455 | if (!isALNUM_lazy_if(s,UTF)) |
12bcd1a6 | 9456 | deprecate_old("bare << to mean <<\"\""); |
7e2040f0 | 9457 | for (; isALNUM_lazy_if(s,UTF); s++) { |
fc36a67e | 9458 | if (d < e) |
9459 | *d++ = *s; | |
9460 | } | |
9461 | } | |
3280af22 | 9462 | if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1) |
cea2e8a9 | 9463 | Perl_croak(aTHX_ "Delimiter for here document is too long"); |
79072805 LW |
9464 | *d++ = '\n'; |
9465 | *d = '\0'; | |
3280af22 | 9466 | len = d - PL_tokenbuf; |
6a27c188 | 9467 | #ifndef PERL_STRICT_CR |
f63a84b2 LW |
9468 | d = strchr(s, '\r'); |
9469 | if (d) { | |
9470 | char *olds = s; | |
9471 | s = d; | |
3280af22 | 9472 | while (s < PL_bufend) { |
f63a84b2 LW |
9473 | if (*s == '\r') { |
9474 | *d++ = '\n'; | |
9475 | if (*++s == '\n') | |
9476 | s++; | |
9477 | } | |
9478 | else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */ | |
9479 | *d++ = *s++; | |
9480 | s++; | |
9481 | } | |
9482 | else | |
9483 | *d++ = *s++; | |
9484 | } | |
9485 | *d = '\0'; | |
3280af22 NIS |
9486 | PL_bufend = d; |
9487 | SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr)); | |
f63a84b2 LW |
9488 | s = olds; |
9489 | } | |
9490 | #endif | |
73d840c0 AL |
9491 | if ( outer || !(found_newline = ninstr(s,PL_bufend,newline,newline+1)) ) { |
9492 | herewas = newSVpvn(s,PL_bufend-s); | |
9493 | } | |
9494 | else { | |
9495 | s--; | |
9496 | herewas = newSVpvn(s,found_newline-s); | |
9497 | } | |
79072805 | 9498 | s += SvCUR(herewas); |
748a9306 | 9499 | |
8d6dde3e | 9500 | tmpstr = NEWSV(87,79); |
748a9306 LW |
9501 | sv_upgrade(tmpstr, SVt_PVIV); |
9502 | if (term == '\'') { | |
79072805 | 9503 | op_type = OP_CONST; |
45977657 | 9504 | SvIV_set(tmpstr, -1); |
748a9306 LW |
9505 | } |
9506 | else if (term == '`') { | |
79072805 | 9507 | op_type = OP_BACKTICK; |
45977657 | 9508 | SvIV_set(tmpstr, '\\'); |
748a9306 | 9509 | } |
79072805 LW |
9510 | |
9511 | CLINE; | |
57843af0 | 9512 | PL_multi_start = CopLINE(PL_curcop); |
3280af22 NIS |
9513 | PL_multi_open = PL_multi_close = '<'; |
9514 | term = *PL_tokenbuf; | |
0244c3a4 GS |
9515 | if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) { |
9516 | char *bufptr = PL_sublex_info.super_bufptr; | |
9517 | char *bufend = PL_sublex_info.super_bufend; | |
9518 | char *olds = s - SvCUR(herewas); | |
9519 | s = strchr(bufptr, '\n'); | |
9520 | if (!s) | |
9521 | s = bufend; | |
9522 | d = s; | |
9523 | while (s < bufend && | |
9524 | (*s != term || memNE(s,PL_tokenbuf,len)) ) { | |
9525 | if (*s++ == '\n') | |
57843af0 | 9526 | CopLINE_inc(PL_curcop); |
0244c3a4 GS |
9527 | } |
9528 | if (s >= bufend) { | |
eb160463 | 9529 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
0244c3a4 GS |
9530 | missingterm(PL_tokenbuf); |
9531 | } | |
9532 | sv_setpvn(herewas,bufptr,d-bufptr+1); | |
9533 | sv_setpvn(tmpstr,d+1,s-d); | |
9534 | s += len - 1; | |
9535 | sv_catpvn(herewas,s,bufend-s); | |
689badd5 | 9536 | Copy(SvPVX(herewas),bufptr,SvCUR(herewas) + 1,char); |
0244c3a4 GS |
9537 | |
9538 | s = olds; | |
9539 | goto retval; | |
9540 | } | |
9541 | else if (!outer) { | |
79072805 | 9542 | d = s; |
3280af22 NIS |
9543 | while (s < PL_bufend && |
9544 | (*s != term || memNE(s,PL_tokenbuf,len)) ) { | |
79072805 | 9545 | if (*s++ == '\n') |
57843af0 | 9546 | CopLINE_inc(PL_curcop); |
79072805 | 9547 | } |
3280af22 | 9548 | if (s >= PL_bufend) { |
eb160463 | 9549 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
3280af22 | 9550 | missingterm(PL_tokenbuf); |
79072805 LW |
9551 | } |
9552 | sv_setpvn(tmpstr,d+1,s-d); | |
9553 | s += len - 1; | |
57843af0 | 9554 | CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */ |
49d8d3a1 | 9555 | |
3280af22 NIS |
9556 | sv_catpvn(herewas,s,PL_bufend-s); |
9557 | sv_setsv(PL_linestr,herewas); | |
9558 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr); | |
9559 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 9560 | PL_last_lop = PL_last_uni = Nullch; |
79072805 LW |
9561 | } |
9562 | else | |
9563 | sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */ | |
3280af22 | 9564 | while (s >= PL_bufend) { /* multiple line string? */ |
fd2d0953 | 9565 | if (!outer || |
3280af22 | 9566 | !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { |
eb160463 | 9567 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
3280af22 | 9568 | missingterm(PL_tokenbuf); |
79072805 | 9569 | } |
57843af0 | 9570 | CopLINE_inc(PL_curcop); |
3280af22 | 9571 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 9572 | PL_last_lop = PL_last_uni = Nullch; |
6a27c188 | 9573 | #ifndef PERL_STRICT_CR |
3280af22 | 9574 | if (PL_bufend - PL_linestart >= 2) { |
a1529941 NIS |
9575 | if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') || |
9576 | (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r')) | |
c6f14548 | 9577 | { |
3280af22 NIS |
9578 | PL_bufend[-2] = '\n'; |
9579 | PL_bufend--; | |
9580 | SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr)); | |
f63a84b2 | 9581 | } |
3280af22 NIS |
9582 | else if (PL_bufend[-1] == '\r') |
9583 | PL_bufend[-1] = '\n'; | |
f63a84b2 | 9584 | } |
3280af22 NIS |
9585 | else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r') |
9586 | PL_bufend[-1] = '\n'; | |
f63a84b2 | 9587 | #endif |
3280af22 | 9588 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
79072805 LW |
9589 | SV *sv = NEWSV(88,0); |
9590 | ||
93a17b20 | 9591 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 9592 | sv_setsv(sv,PL_linestr); |
0ac0412a | 9593 | (void)SvIOK_on(sv); |
45977657 | 9594 | SvIV_set(sv, 0); |
57843af0 | 9595 | av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv); |
79072805 | 9596 | } |
3280af22 | 9597 | if (*s == term && memEQ(s,PL_tokenbuf,len)) { |
1de9afcd RGS |
9598 | STRLEN off = PL_bufend - 1 - SvPVX(PL_linestr); |
9599 | *(SvPVX(PL_linestr) + off ) = ' '; | |
3280af22 NIS |
9600 | sv_catsv(PL_linestr,herewas); |
9601 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
1de9afcd | 9602 | s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */ |
79072805 LW |
9603 | } |
9604 | else { | |
3280af22 NIS |
9605 | s = PL_bufend; |
9606 | sv_catsv(tmpstr,PL_linestr); | |
395c3793 LW |
9607 | } |
9608 | } | |
79072805 | 9609 | s++; |
0244c3a4 | 9610 | retval: |
57843af0 | 9611 | PL_multi_end = CopLINE(PL_curcop); |
79072805 | 9612 | if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) { |
1da4ca5f | 9613 | SvPV_shrink_to_cur(tmpstr); |
79072805 | 9614 | } |
8990e307 | 9615 | SvREFCNT_dec(herewas); |
2f31ce75 JH |
9616 | if (!IN_BYTES) { |
9617 | if (UTF && is_utf8_string((U8*)SvPVX(tmpstr), SvCUR(tmpstr))) | |
9618 | SvUTF8_on(tmpstr); | |
9619 | else if (PL_encoding) | |
9620 | sv_recode_to_utf8(tmpstr, PL_encoding); | |
9621 | } | |
3280af22 | 9622 | PL_lex_stuff = tmpstr; |
79072805 LW |
9623 | yylval.ival = op_type; |
9624 | return s; | |
9625 | } | |
9626 | ||
02aa26ce NT |
9627 | /* scan_inputsymbol |
9628 | takes: current position in input buffer | |
9629 | returns: new position in input buffer | |
9630 | side-effects: yylval and lex_op are set. | |
9631 | ||
9632 | This code handles: | |
9633 | ||
9634 | <> read from ARGV | |
9635 | <FH> read from filehandle | |
9636 | <pkg::FH> read from package qualified filehandle | |
9637 | <pkg'FH> read from package qualified filehandle | |
9638 | <$fh> read from filehandle in $fh | |
9639 | <*.h> filename glob | |
9640 | ||
9641 | */ | |
9642 | ||
76e3520e | 9643 | STATIC char * |
cea2e8a9 | 9644 | S_scan_inputsymbol(pTHX_ char *start) |
79072805 | 9645 | { |
02aa26ce | 9646 | register char *s = start; /* current position in buffer */ |
79072805 | 9647 | register char *d; |
fc36a67e | 9648 | register char *e; |
1b420867 | 9649 | char *end; |
79072805 LW |
9650 | I32 len; |
9651 | ||
3280af22 NIS |
9652 | d = PL_tokenbuf; /* start of temp holding space */ |
9653 | e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */ | |
1b420867 GS |
9654 | end = strchr(s, '\n'); |
9655 | if (!end) | |
9656 | end = PL_bufend; | |
9657 | s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */ | |
02aa26ce NT |
9658 | |
9659 | /* die if we didn't have space for the contents of the <>, | |
1b420867 | 9660 | or if it didn't end, or if we see a newline |
02aa26ce NT |
9661 | */ |
9662 | ||
3280af22 | 9663 | if (len >= sizeof PL_tokenbuf) |
cea2e8a9 | 9664 | Perl_croak(aTHX_ "Excessively long <> operator"); |
1b420867 | 9665 | if (s >= end) |
cea2e8a9 | 9666 | Perl_croak(aTHX_ "Unterminated <> operator"); |
02aa26ce | 9667 | |
fc36a67e | 9668 | s++; |
02aa26ce NT |
9669 | |
9670 | /* check for <$fh> | |
9671 | Remember, only scalar variables are interpreted as filehandles by | |
9672 | this code. Anything more complex (e.g., <$fh{$num}>) will be | |
9673 | treated as a glob() call. | |
9674 | This code makes use of the fact that except for the $ at the front, | |
9675 | a scalar variable and a filehandle look the same. | |
9676 | */ | |
4633a7c4 | 9677 | if (*d == '$' && d[1]) d++; |
02aa26ce NT |
9678 | |
9679 | /* allow <Pkg'VALUE> or <Pkg::VALUE> */ | |
7e2040f0 | 9680 | while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':')) |
79072805 | 9681 | d++; |
02aa26ce NT |
9682 | |
9683 | /* If we've tried to read what we allow filehandles to look like, and | |
9684 | there's still text left, then it must be a glob() and not a getline. | |
9685 | Use scan_str to pull out the stuff between the <> and treat it | |
9686 | as nothing more than a string. | |
9687 | */ | |
9688 | ||
3280af22 | 9689 | if (d - PL_tokenbuf != len) { |
79072805 LW |
9690 | yylval.ival = OP_GLOB; |
9691 | set_csh(); | |
09bef843 | 9692 | s = scan_str(start,FALSE,FALSE); |
79072805 | 9693 | if (!s) |
cea2e8a9 | 9694 | Perl_croak(aTHX_ "Glob not terminated"); |
79072805 LW |
9695 | return s; |
9696 | } | |
395c3793 | 9697 | else { |
9b3023bc RGS |
9698 | bool readline_overriden = FALSE; |
9699 | GV *gv_readline = Nullgv; | |
9700 | GV **gvp; | |
02aa26ce | 9701 | /* we're in a filehandle read situation */ |
3280af22 | 9702 | d = PL_tokenbuf; |
02aa26ce NT |
9703 | |
9704 | /* turn <> into <ARGV> */ | |
79072805 | 9705 | if (!len) |
689badd5 | 9706 | Copy("ARGV",d,5,char); |
02aa26ce | 9707 | |
9b3023bc | 9708 | /* Check whether readline() is overriden */ |
ba979b31 NIS |
9709 | if (((gv_readline = gv_fetchpv("readline", FALSE, SVt_PVCV)) |
9710 | && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)) | |
9b3023bc | 9711 | || |
ba979b31 | 9712 | ((gvp = (GV**)hv_fetch(PL_globalstash, "readline", 8, FALSE)) |
9b3023bc | 9713 | && (gv_readline = *gvp) != (GV*)&PL_sv_undef |
ba979b31 | 9714 | && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))) |
9b3023bc RGS |
9715 | readline_overriden = TRUE; |
9716 | ||
02aa26ce NT |
9717 | /* if <$fh>, create the ops to turn the variable into a |
9718 | filehandle | |
9719 | */ | |
79072805 | 9720 | if (*d == '$') { |
a0d0e21e | 9721 | I32 tmp; |
02aa26ce NT |
9722 | |
9723 | /* try to find it in the pad for this block, otherwise find | |
9724 | add symbol table ops | |
9725 | */ | |
11343788 | 9726 | if ((tmp = pad_findmy(d)) != NOT_IN_PAD) { |
dd2155a4 DM |
9727 | if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) { |
9728 | SV *sym = sv_2mortal( | |
9729 | newSVpv(HvNAME(PAD_COMPNAME_OURSTASH(tmp)),0)); | |
f558d5af JH |
9730 | sv_catpvn(sym, "::", 2); |
9731 | sv_catpv(sym, d+1); | |
9732 | d = SvPVX(sym); | |
9733 | goto intro_sym; | |
9734 | } | |
9735 | else { | |
9736 | OP *o = newOP(OP_PADSV, 0); | |
9737 | o->op_targ = tmp; | |
9b3023bc RGS |
9738 | PL_lex_op = readline_overriden |
9739 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, | |
9740 | append_elem(OP_LIST, o, | |
9741 | newCVREF(0, newGVOP(OP_GV,0,gv_readline)))) | |
9742 | : (OP*)newUNOP(OP_READLINE, 0, o); | |
f558d5af | 9743 | } |
a0d0e21e LW |
9744 | } |
9745 | else { | |
f558d5af JH |
9746 | GV *gv; |
9747 | ++d; | |
9748 | intro_sym: | |
9749 | gv = gv_fetchpv(d, | |
9750 | (PL_in_eval | |
9751 | ? (GV_ADDMULTI | GV_ADDINEVAL) | |
bea70d1e | 9752 | : GV_ADDMULTI), |
f558d5af | 9753 | SVt_PV); |
9b3023bc RGS |
9754 | PL_lex_op = readline_overriden |
9755 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, | |
9756 | append_elem(OP_LIST, | |
9757 | newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)), | |
9758 | newCVREF(0, newGVOP(OP_GV, 0, gv_readline)))) | |
9759 | : (OP*)newUNOP(OP_READLINE, 0, | |
9760 | newUNOP(OP_RV2SV, 0, | |
9761 | newGVOP(OP_GV, 0, gv))); | |
a0d0e21e | 9762 | } |
7c6fadd6 RGS |
9763 | if (!readline_overriden) |
9764 | PL_lex_op->op_flags |= OPf_SPECIAL; | |
f5284f61 | 9765 | /* we created the ops in PL_lex_op, so make yylval.ival a null op */ |
79072805 LW |
9766 | yylval.ival = OP_NULL; |
9767 | } | |
02aa26ce NT |
9768 | |
9769 | /* If it's none of the above, it must be a literal filehandle | |
9770 | (<Foo::BAR> or <FOO>) so build a simple readline OP */ | |
79072805 | 9771 | else { |
85e6fe83 | 9772 | GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO); |
9b3023bc RGS |
9773 | PL_lex_op = readline_overriden |
9774 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, | |
9775 | append_elem(OP_LIST, | |
9776 | newGVOP(OP_GV, 0, gv), | |
9777 | newCVREF(0, newGVOP(OP_GV, 0, gv_readline)))) | |
9778 | : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv)); | |
79072805 LW |
9779 | yylval.ival = OP_NULL; |
9780 | } | |
9781 | } | |
02aa26ce | 9782 | |
79072805 LW |
9783 | return s; |
9784 | } | |
9785 | ||
02aa26ce NT |
9786 | |
9787 | /* scan_str | |
9788 | takes: start position in buffer | |
09bef843 SB |
9789 | keep_quoted preserve \ on the embedded delimiter(s) |
9790 | keep_delims preserve the delimiters around the string | |
02aa26ce NT |
9791 | returns: position to continue reading from buffer |
9792 | side-effects: multi_start, multi_close, lex_repl or lex_stuff, and | |
9793 | updates the read buffer. | |
9794 | ||
9795 | This subroutine pulls a string out of the input. It is called for: | |
9796 | q single quotes q(literal text) | |
9797 | ' single quotes 'literal text' | |
9798 | qq double quotes qq(interpolate $here please) | |
9799 | " double quotes "interpolate $here please" | |
9800 | qx backticks qx(/bin/ls -l) | |
9801 | ` backticks `/bin/ls -l` | |
9802 | qw quote words @EXPORT_OK = qw( func() $spam ) | |
9803 | m// regexp match m/this/ | |
9804 | s/// regexp substitute s/this/that/ | |
9805 | tr/// string transliterate tr/this/that/ | |
9806 | y/// string transliterate y/this/that/ | |
9807 | ($*@) sub prototypes sub foo ($) | |
09bef843 | 9808 | (stuff) sub attr parameters sub foo : attr(stuff) |
02aa26ce NT |
9809 | <> readline or globs <FOO>, <>, <$fh>, or <*.c> |
9810 | ||
9811 | In most of these cases (all but <>, patterns and transliterate) | |
9812 | yylex() calls scan_str(). m// makes yylex() call scan_pat() which | |
9813 | calls scan_str(). s/// makes yylex() call scan_subst() which calls | |
9814 | scan_str(). tr/// and y/// make yylex() call scan_trans() which | |
9815 | calls scan_str(). | |
4e553d73 | 9816 | |
02aa26ce NT |
9817 | It skips whitespace before the string starts, and treats the first |
9818 | character as the delimiter. If the delimiter is one of ([{< then | |
9819 | the corresponding "close" character )]}> is used as the closing | |
9820 | delimiter. It allows quoting of delimiters, and if the string has | |
9821 | balanced delimiters ([{<>}]) it allows nesting. | |
9822 | ||
37fd879b HS |
9823 | On success, the SV with the resulting string is put into lex_stuff or, |
9824 | if that is already non-NULL, into lex_repl. The second case occurs only | |
9825 | when parsing the RHS of the special constructs s/// and tr/// (y///). | |
9826 | For convenience, the terminating delimiter character is stuffed into | |
9827 | SvIVX of the SV. | |
02aa26ce NT |
9828 | */ |
9829 | ||
76e3520e | 9830 | STATIC char * |
09bef843 | 9831 | S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims) |
79072805 | 9832 | { |
02aa26ce NT |
9833 | SV *sv; /* scalar value: string */ |
9834 | char *tmps; /* temp string, used for delimiter matching */ | |
9835 | register char *s = start; /* current position in the buffer */ | |
9836 | register char term; /* terminating character */ | |
9837 | register char *to; /* current position in the sv's data */ | |
9838 | I32 brackets = 1; /* bracket nesting level */ | |
89491803 | 9839 | bool has_utf8 = FALSE; /* is there any utf8 content? */ |
220e2d4e | 9840 | I32 termcode; /* terminating char. code */ |
89ebb4a3 | 9841 | U8 termstr[UTF8_MAXBYTES]; /* terminating string */ |
220e2d4e IH |
9842 | STRLEN termlen; /* length of terminating string */ |
9843 | char *last = NULL; /* last position for nesting bracket */ | |
02aa26ce NT |
9844 | |
9845 | /* skip space before the delimiter */ | |
fb73857a | 9846 | if (isSPACE(*s)) |
9847 | s = skipspace(s); | |
02aa26ce NT |
9848 | |
9849 | /* mark where we are, in case we need to report errors */ | |
79072805 | 9850 | CLINE; |
02aa26ce NT |
9851 | |
9852 | /* after skipping whitespace, the next character is the terminator */ | |
a0d0e21e | 9853 | term = *s; |
220e2d4e IH |
9854 | if (!UTF) { |
9855 | termcode = termstr[0] = term; | |
9856 | termlen = 1; | |
9857 | } | |
9858 | else { | |
f3b9ce0f | 9859 | termcode = utf8_to_uvchr((U8*)s, &termlen); |
220e2d4e IH |
9860 | Copy(s, termstr, termlen, U8); |
9861 | if (!UTF8_IS_INVARIANT(term)) | |
9862 | has_utf8 = TRUE; | |
9863 | } | |
b1c7b182 | 9864 | |
02aa26ce | 9865 | /* mark where we are */ |
57843af0 | 9866 | PL_multi_start = CopLINE(PL_curcop); |
3280af22 | 9867 | PL_multi_open = term; |
02aa26ce NT |
9868 | |
9869 | /* find corresponding closing delimiter */ | |
93a17b20 | 9870 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) |
220e2d4e IH |
9871 | termcode = termstr[0] = term = tmps[5]; |
9872 | ||
3280af22 | 9873 | PL_multi_close = term; |
79072805 | 9874 | |
02aa26ce | 9875 | /* create a new SV to hold the contents. 87 is leak category, I'm |
8d6dde3e IZ |
9876 | assuming. 79 is the SV's initial length. What a random number. */ |
9877 | sv = NEWSV(87,79); | |
ed6116ce | 9878 | sv_upgrade(sv, SVt_PVIV); |
45977657 | 9879 | SvIV_set(sv, termcode); |
a0d0e21e | 9880 | (void)SvPOK_only(sv); /* validate pointer */ |
02aa26ce NT |
9881 | |
9882 | /* move past delimiter and try to read a complete string */ | |
09bef843 | 9883 | if (keep_delims) |
220e2d4e IH |
9884 | sv_catpvn(sv, s, termlen); |
9885 | s += termlen; | |
93a17b20 | 9886 | for (;;) { |
220e2d4e IH |
9887 | if (PL_encoding && !UTF) { |
9888 | bool cont = TRUE; | |
9889 | ||
9890 | while (cont) { | |
9891 | int offset = s - SvPVX(PL_linestr); | |
9892 | bool found = sv_cat_decode(sv, PL_encoding, PL_linestr, | |
f3b9ce0f | 9893 | &offset, (char*)termstr, termlen); |
220e2d4e IH |
9894 | char *ns = SvPVX(PL_linestr) + offset; |
9895 | char *svlast = SvEND(sv) - 1; | |
9896 | ||
9897 | for (; s < ns; s++) { | |
9898 | if (*s == '\n' && !PL_rsfp) | |
9899 | CopLINE_inc(PL_curcop); | |
9900 | } | |
9901 | if (!found) | |
9902 | goto read_more_line; | |
9903 | else { | |
9904 | /* handle quoted delimiters */ | |
52327caf | 9905 | if (SvCUR(sv) > 1 && *(svlast-1) == '\\') { |
220e2d4e IH |
9906 | char *t; |
9907 | for (t = svlast-2; t >= SvPVX(sv) && *t == '\\';) | |
9908 | t--; | |
9909 | if ((svlast-1 - t) % 2) { | |
9910 | if (!keep_quoted) { | |
9911 | *(svlast-1) = term; | |
9912 | *svlast = '\0'; | |
9913 | SvCUR_set(sv, SvCUR(sv) - 1); | |
9914 | } | |
9915 | continue; | |
9916 | } | |
9917 | } | |
9918 | if (PL_multi_open == PL_multi_close) { | |
9919 | cont = FALSE; | |
9920 | } | |
9921 | else { | |
9922 | char *t, *w; | |
9923 | if (!last) | |
9924 | last = SvPVX(sv); | |
9925 | for (w = t = last; t < svlast; w++, t++) { | |
9926 | /* At here, all closes are "was quoted" one, | |
9927 | so we don't check PL_multi_close. */ | |
9928 | if (*t == '\\') { | |
9929 | if (!keep_quoted && *(t+1) == PL_multi_open) | |
9930 | t++; | |
9931 | else | |
9932 | *w++ = *t++; | |
9933 | } | |
9934 | else if (*t == PL_multi_open) | |
9935 | brackets++; | |
9936 | ||
9937 | *w = *t; | |
9938 | } | |
9939 | if (w < t) { | |
9940 | *w++ = term; | |
9941 | *w = '\0'; | |
9942 | SvCUR_set(sv, w - SvPVX(sv)); | |
9943 | } | |
9944 | last = w; | |
9945 | if (--brackets <= 0) | |
9946 | cont = FALSE; | |
9947 | } | |
9948 | } | |
9949 | } | |
9950 | if (!keep_delims) { | |
9951 | SvCUR_set(sv, SvCUR(sv) - 1); | |
9952 | *SvEND(sv) = '\0'; | |
9953 | } | |
9954 | break; | |
9955 | } | |
9956 | ||
02aa26ce | 9957 | /* extend sv if need be */ |
3280af22 | 9958 | SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1); |
02aa26ce | 9959 | /* set 'to' to the next character in the sv's string */ |
463ee0b2 | 9960 | to = SvPVX(sv)+SvCUR(sv); |
09bef843 | 9961 | |
02aa26ce | 9962 | /* if open delimiter is the close delimiter read unbridle */ |
3280af22 NIS |
9963 | if (PL_multi_open == PL_multi_close) { |
9964 | for (; s < PL_bufend; s++,to++) { | |
02aa26ce | 9965 | /* embedded newlines increment the current line number */ |
3280af22 | 9966 | if (*s == '\n' && !PL_rsfp) |
57843af0 | 9967 | CopLINE_inc(PL_curcop); |
02aa26ce | 9968 | /* handle quoted delimiters */ |
3280af22 | 9969 | if (*s == '\\' && s+1 < PL_bufend && term != '\\') { |
09bef843 | 9970 | if (!keep_quoted && s[1] == term) |
a0d0e21e | 9971 | s++; |
02aa26ce | 9972 | /* any other quotes are simply copied straight through */ |
a0d0e21e LW |
9973 | else |
9974 | *to++ = *s++; | |
9975 | } | |
02aa26ce NT |
9976 | /* terminate when run out of buffer (the for() condition), or |
9977 | have found the terminator */ | |
220e2d4e IH |
9978 | else if (*s == term) { |
9979 | if (termlen == 1) | |
9980 | break; | |
f3b9ce0f | 9981 | if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen)) |
220e2d4e IH |
9982 | break; |
9983 | } | |
63cd0674 | 9984 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
89491803 | 9985 | has_utf8 = TRUE; |
93a17b20 LW |
9986 | *to = *s; |
9987 | } | |
9988 | } | |
02aa26ce NT |
9989 | |
9990 | /* if the terminator isn't the same as the start character (e.g., | |
9991 | matched brackets), we have to allow more in the quoting, and | |
9992 | be prepared for nested brackets. | |
9993 | */ | |
93a17b20 | 9994 | else { |
02aa26ce | 9995 | /* read until we run out of string, or we find the terminator */ |
3280af22 | 9996 | for (; s < PL_bufend; s++,to++) { |
02aa26ce | 9997 | /* embedded newlines increment the line count */ |
3280af22 | 9998 | if (*s == '\n' && !PL_rsfp) |
57843af0 | 9999 | CopLINE_inc(PL_curcop); |
02aa26ce | 10000 | /* backslashes can escape the open or closing characters */ |
3280af22 | 10001 | if (*s == '\\' && s+1 < PL_bufend) { |
09bef843 SB |
10002 | if (!keep_quoted && |
10003 | ((s[1] == PL_multi_open) || (s[1] == PL_multi_close))) | |
a0d0e21e LW |
10004 | s++; |
10005 | else | |
10006 | *to++ = *s++; | |
10007 | } | |
02aa26ce | 10008 | /* allow nested opens and closes */ |
3280af22 | 10009 | else if (*s == PL_multi_close && --brackets <= 0) |
93a17b20 | 10010 | break; |
3280af22 | 10011 | else if (*s == PL_multi_open) |
93a17b20 | 10012 | brackets++; |
63cd0674 | 10013 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
89491803 | 10014 | has_utf8 = TRUE; |
93a17b20 LW |
10015 | *to = *s; |
10016 | } | |
10017 | } | |
02aa26ce | 10018 | /* terminate the copied string and update the sv's end-of-string */ |
93a17b20 | 10019 | *to = '\0'; |
463ee0b2 | 10020 | SvCUR_set(sv, to - SvPVX(sv)); |
93a17b20 | 10021 | |
02aa26ce NT |
10022 | /* |
10023 | * this next chunk reads more into the buffer if we're not done yet | |
10024 | */ | |
10025 | ||
b1c7b182 GS |
10026 | if (s < PL_bufend) |
10027 | break; /* handle case where we are done yet :-) */ | |
79072805 | 10028 | |
6a27c188 | 10029 | #ifndef PERL_STRICT_CR |
f63a84b2 | 10030 | if (to - SvPVX(sv) >= 2) { |
c6f14548 GS |
10031 | if ((to[-2] == '\r' && to[-1] == '\n') || |
10032 | (to[-2] == '\n' && to[-1] == '\r')) | |
10033 | { | |
f63a84b2 LW |
10034 | to[-2] = '\n'; |
10035 | to--; | |
10036 | SvCUR_set(sv, to - SvPVX(sv)); | |
10037 | } | |
10038 | else if (to[-1] == '\r') | |
10039 | to[-1] = '\n'; | |
10040 | } | |
10041 | else if (to - SvPVX(sv) == 1 && to[-1] == '\r') | |
10042 | to[-1] = '\n'; | |
10043 | #endif | |
10044 | ||
220e2d4e | 10045 | read_more_line: |
02aa26ce NT |
10046 | /* if we're out of file, or a read fails, bail and reset the current |
10047 | line marker so we can report where the unterminated string began | |
10048 | */ | |
3280af22 NIS |
10049 | if (!PL_rsfp || |
10050 | !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { | |
c07a80fd | 10051 | sv_free(sv); |
eb160463 | 10052 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
79072805 LW |
10053 | return Nullch; |
10054 | } | |
02aa26ce | 10055 | /* we read a line, so increment our line counter */ |
57843af0 | 10056 | CopLINE_inc(PL_curcop); |
a0ed51b3 | 10057 | |
02aa26ce | 10058 | /* update debugger info */ |
3280af22 | 10059 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
79072805 LW |
10060 | SV *sv = NEWSV(88,0); |
10061 | ||
93a17b20 | 10062 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 10063 | sv_setsv(sv,PL_linestr); |
0ac0412a | 10064 | (void)SvIOK_on(sv); |
45977657 | 10065 | SvIV_set(sv, 0); |
57843af0 | 10066 | av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv); |
395c3793 | 10067 | } |
a0ed51b3 | 10068 | |
3280af22 NIS |
10069 | /* having changed the buffer, we must update PL_bufend */ |
10070 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 10071 | PL_last_lop = PL_last_uni = Nullch; |
378cc40b | 10072 | } |
4e553d73 | 10073 | |
02aa26ce NT |
10074 | /* at this point, we have successfully read the delimited string */ |
10075 | ||
220e2d4e IH |
10076 | if (!PL_encoding || UTF) { |
10077 | if (keep_delims) | |
10078 | sv_catpvn(sv, s, termlen); | |
10079 | s += termlen; | |
10080 | } | |
10081 | if (has_utf8 || PL_encoding) | |
b1c7b182 | 10082 | SvUTF8_on(sv); |
d0063567 | 10083 | |
57843af0 | 10084 | PL_multi_end = CopLINE(PL_curcop); |
02aa26ce NT |
10085 | |
10086 | /* if we allocated too much space, give some back */ | |
93a17b20 LW |
10087 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
10088 | SvLEN_set(sv, SvCUR(sv) + 1); | |
b7e9a5c2 | 10089 | SvPV_renew(sv, SvLEN(sv)); |
79072805 | 10090 | } |
02aa26ce NT |
10091 | |
10092 | /* decide whether this is the first or second quoted string we've read | |
10093 | for this op | |
10094 | */ | |
4e553d73 | 10095 | |
3280af22 NIS |
10096 | if (PL_lex_stuff) |
10097 | PL_lex_repl = sv; | |
79072805 | 10098 | else |
3280af22 | 10099 | PL_lex_stuff = sv; |
378cc40b LW |
10100 | return s; |
10101 | } | |
10102 | ||
02aa26ce NT |
10103 | /* |
10104 | scan_num | |
10105 | takes: pointer to position in buffer | |
10106 | returns: pointer to new position in buffer | |
10107 | side-effects: builds ops for the constant in yylval.op | |
10108 | ||
10109 | Read a number in any of the formats that Perl accepts: | |
10110 | ||
7fd134d9 JH |
10111 | \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12. |
10112 | \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34 | |
24138b49 JH |
10113 | 0b[01](_?[01])* |
10114 | 0[0-7](_?[0-7])* | |
10115 | 0x[0-9A-Fa-f](_?[0-9A-Fa-f])* | |
02aa26ce | 10116 | |
3280af22 | 10117 | Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the |
02aa26ce NT |
10118 | thing it reads. |
10119 | ||
10120 | If it reads a number without a decimal point or an exponent, it will | |
10121 | try converting the number to an integer and see if it can do so | |
10122 | without loss of precision. | |
10123 | */ | |
4e553d73 | 10124 | |
378cc40b | 10125 | char * |
bfed75c6 | 10126 | Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp) |
378cc40b | 10127 | { |
bfed75c6 | 10128 | register const char *s = start; /* current position in buffer */ |
02aa26ce NT |
10129 | register char *d; /* destination in temp buffer */ |
10130 | register char *e; /* end of temp buffer */ | |
86554af2 | 10131 | NV nv; /* number read, as a double */ |
a7cb1f99 | 10132 | SV *sv = Nullsv; /* place to put the converted number */ |
a86a20aa | 10133 | bool floatit; /* boolean: int or float? */ |
bfed75c6 AL |
10134 | const char *lastub = 0; /* position of last underbar */ |
10135 | static char const number_too_long[] = "Number too long"; | |
378cc40b | 10136 | |
02aa26ce NT |
10137 | /* We use the first character to decide what type of number this is */ |
10138 | ||
378cc40b | 10139 | switch (*s) { |
79072805 | 10140 | default: |
cea2e8a9 | 10141 | Perl_croak(aTHX_ "panic: scan_num"); |
4e553d73 | 10142 | |
02aa26ce | 10143 | /* if it starts with a 0, it could be an octal number, a decimal in |
a7cb1f99 | 10144 | 0.13 disguise, or a hexadecimal number, or a binary number. */ |
378cc40b LW |
10145 | case '0': |
10146 | { | |
02aa26ce NT |
10147 | /* variables: |
10148 | u holds the "number so far" | |
4f19785b WSI |
10149 | shift the power of 2 of the base |
10150 | (hex == 4, octal == 3, binary == 1) | |
02aa26ce NT |
10151 | overflowed was the number more than we can hold? |
10152 | ||
10153 | Shift is used when we add a digit. It also serves as an "are | |
4f19785b WSI |
10154 | we in octal/hex/binary?" indicator to disallow hex characters |
10155 | when in octal mode. | |
02aa26ce | 10156 | */ |
9e24b6e2 JH |
10157 | NV n = 0.0; |
10158 | UV u = 0; | |
79072805 | 10159 | I32 shift; |
9e24b6e2 | 10160 | bool overflowed = FALSE; |
61f33854 | 10161 | bool just_zero = TRUE; /* just plain 0 or binary number? */ |
27da23d5 JH |
10162 | static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 }; |
10163 | static const char* const bases[5] = | |
10164 | { "", "binary", "", "octal", "hexadecimal" }; | |
10165 | static const char* const Bases[5] = | |
10166 | { "", "Binary", "", "Octal", "Hexadecimal" }; | |
10167 | static const char* const maxima[5] = | |
10168 | { "", | |
10169 | "0b11111111111111111111111111111111", | |
10170 | "", | |
10171 | "037777777777", | |
10172 | "0xffffffff" }; | |
bfed75c6 | 10173 | const char *base, *Base, *max; |
378cc40b | 10174 | |
02aa26ce | 10175 | /* check for hex */ |
378cc40b LW |
10176 | if (s[1] == 'x') { |
10177 | shift = 4; | |
10178 | s += 2; | |
61f33854 | 10179 | just_zero = FALSE; |
4f19785b WSI |
10180 | } else if (s[1] == 'b') { |
10181 | shift = 1; | |
10182 | s += 2; | |
61f33854 | 10183 | just_zero = FALSE; |
378cc40b | 10184 | } |
02aa26ce | 10185 | /* check for a decimal in disguise */ |
b78218b7 | 10186 | else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E') |
378cc40b | 10187 | goto decimal; |
02aa26ce | 10188 | /* so it must be octal */ |
928753ea | 10189 | else { |
378cc40b | 10190 | shift = 3; |
928753ea JH |
10191 | s++; |
10192 | } | |
10193 | ||
10194 | if (*s == '_') { | |
10195 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10196 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10197 | "Misplaced _ in number"); |
10198 | lastub = s++; | |
10199 | } | |
9e24b6e2 JH |
10200 | |
10201 | base = bases[shift]; | |
10202 | Base = Bases[shift]; | |
10203 | max = maxima[shift]; | |
02aa26ce | 10204 | |
4f19785b | 10205 | /* read the rest of the number */ |
378cc40b | 10206 | for (;;) { |
9e24b6e2 | 10207 | /* x is used in the overflow test, |
893fe2c2 | 10208 | b is the digit we're adding on. */ |
9e24b6e2 | 10209 | UV x, b; |
55497cff | 10210 | |
378cc40b | 10211 | switch (*s) { |
02aa26ce NT |
10212 | |
10213 | /* if we don't mention it, we're done */ | |
378cc40b LW |
10214 | default: |
10215 | goto out; | |
02aa26ce | 10216 | |
928753ea | 10217 | /* _ are ignored -- but warned about if consecutive */ |
de3bb511 | 10218 | case '_': |
928753ea | 10219 | if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1) |
9014280d | 10220 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10221 | "Misplaced _ in number"); |
10222 | lastub = s++; | |
de3bb511 | 10223 | break; |
02aa26ce NT |
10224 | |
10225 | /* 8 and 9 are not octal */ | |
378cc40b | 10226 | case '8': case '9': |
4f19785b | 10227 | if (shift == 3) |
cea2e8a9 | 10228 | yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s)); |
378cc40b | 10229 | /* FALL THROUGH */ |
02aa26ce NT |
10230 | |
10231 | /* octal digits */ | |
4f19785b | 10232 | case '2': case '3': case '4': |
378cc40b | 10233 | case '5': case '6': case '7': |
4f19785b | 10234 | if (shift == 1) |
cea2e8a9 | 10235 | yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s)); |
4f19785b WSI |
10236 | /* FALL THROUGH */ |
10237 | ||
10238 | case '0': case '1': | |
02aa26ce | 10239 | b = *s++ & 15; /* ASCII digit -> value of digit */ |
55497cff | 10240 | goto digit; |
02aa26ce NT |
10241 | |
10242 | /* hex digits */ | |
378cc40b LW |
10243 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': |
10244 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': | |
02aa26ce | 10245 | /* make sure they said 0x */ |
378cc40b LW |
10246 | if (shift != 4) |
10247 | goto out; | |
55497cff | 10248 | b = (*s++ & 7) + 9; |
02aa26ce NT |
10249 | |
10250 | /* Prepare to put the digit we have onto the end | |
10251 | of the number so far. We check for overflows. | |
10252 | */ | |
10253 | ||
55497cff | 10254 | digit: |
61f33854 | 10255 | just_zero = FALSE; |
9e24b6e2 JH |
10256 | if (!overflowed) { |
10257 | x = u << shift; /* make room for the digit */ | |
10258 | ||
10259 | if ((x >> shift) != u | |
10260 | && !(PL_hints & HINT_NEW_BINARY)) { | |
9e24b6e2 JH |
10261 | overflowed = TRUE; |
10262 | n = (NV) u; | |
767a6a26 | 10263 | if (ckWARN_d(WARN_OVERFLOW)) |
9014280d | 10264 | Perl_warner(aTHX_ packWARN(WARN_OVERFLOW), |
9e24b6e2 JH |
10265 | "Integer overflow in %s number", |
10266 | base); | |
10267 | } else | |
10268 | u = x | b; /* add the digit to the end */ | |
10269 | } | |
10270 | if (overflowed) { | |
10271 | n *= nvshift[shift]; | |
10272 | /* If an NV has not enough bits in its | |
10273 | * mantissa to represent an UV this summing of | |
10274 | * small low-order numbers is a waste of time | |
10275 | * (because the NV cannot preserve the | |
10276 | * low-order bits anyway): we could just | |
10277 | * remember when did we overflow and in the | |
10278 | * end just multiply n by the right | |
10279 | * amount. */ | |
10280 | n += (NV) b; | |
55497cff | 10281 | } |
378cc40b LW |
10282 | break; |
10283 | } | |
10284 | } | |
02aa26ce NT |
10285 | |
10286 | /* if we get here, we had success: make a scalar value from | |
10287 | the number. | |
10288 | */ | |
378cc40b | 10289 | out: |
928753ea JH |
10290 | |
10291 | /* final misplaced underbar check */ | |
10292 | if (s[-1] == '_') { | |
10293 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10294 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number"); |
928753ea JH |
10295 | } |
10296 | ||
79072805 | 10297 | sv = NEWSV(92,0); |
9e24b6e2 | 10298 | if (overflowed) { |
767a6a26 | 10299 | if (ckWARN(WARN_PORTABLE) && n > 4294967295.0) |
9014280d | 10300 | Perl_warner(aTHX_ packWARN(WARN_PORTABLE), |
9e24b6e2 JH |
10301 | "%s number > %s non-portable", |
10302 | Base, max); | |
10303 | sv_setnv(sv, n); | |
10304 | } | |
10305 | else { | |
15041a67 | 10306 | #if UVSIZE > 4 |
767a6a26 | 10307 | if (ckWARN(WARN_PORTABLE) && u > 0xffffffff) |
9014280d | 10308 | Perl_warner(aTHX_ packWARN(WARN_PORTABLE), |
9e24b6e2 JH |
10309 | "%s number > %s non-portable", |
10310 | Base, max); | |
2cc4c2dc | 10311 | #endif |
9e24b6e2 JH |
10312 | sv_setuv(sv, u); |
10313 | } | |
61f33854 | 10314 | if (just_zero && (PL_hints & HINT_NEW_INTEGER)) |
bfed75c6 | 10315 | sv = new_constant(start, s - start, "integer", |
61f33854 RGS |
10316 | sv, Nullsv, NULL); |
10317 | else if (PL_hints & HINT_NEW_BINARY) | |
b3ac6de7 | 10318 | sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL); |
378cc40b LW |
10319 | } |
10320 | break; | |
02aa26ce NT |
10321 | |
10322 | /* | |
10323 | handle decimal numbers. | |
10324 | we're also sent here when we read a 0 as the first digit | |
10325 | */ | |
378cc40b LW |
10326 | case '1': case '2': case '3': case '4': case '5': |
10327 | case '6': case '7': case '8': case '9': case '.': | |
10328 | decimal: | |
3280af22 NIS |
10329 | d = PL_tokenbuf; |
10330 | e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */ | |
79072805 | 10331 | floatit = FALSE; |
02aa26ce NT |
10332 | |
10333 | /* read next group of digits and _ and copy into d */ | |
de3bb511 | 10334 | while (isDIGIT(*s) || *s == '_') { |
4e553d73 | 10335 | /* skip underscores, checking for misplaced ones |
02aa26ce NT |
10336 | if -w is on |
10337 | */ | |
93a17b20 | 10338 | if (*s == '_') { |
928753ea | 10339 | if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1) |
9014280d | 10340 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10341 | "Misplaced _ in number"); |
10342 | lastub = s++; | |
93a17b20 | 10343 | } |
fc36a67e | 10344 | else { |
02aa26ce | 10345 | /* check for end of fixed-length buffer */ |
fc36a67e | 10346 | if (d >= e) |
cea2e8a9 | 10347 | Perl_croak(aTHX_ number_too_long); |
02aa26ce | 10348 | /* if we're ok, copy the character */ |
378cc40b | 10349 | *d++ = *s++; |
fc36a67e | 10350 | } |
378cc40b | 10351 | } |
02aa26ce NT |
10352 | |
10353 | /* final misplaced underbar check */ | |
928753ea | 10354 | if (lastub && s == lastub + 1) { |
d008e5eb | 10355 | if (ckWARN(WARN_SYNTAX)) |
9014280d | 10356 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number"); |
d008e5eb | 10357 | } |
02aa26ce NT |
10358 | |
10359 | /* read a decimal portion if there is one. avoid | |
10360 | 3..5 being interpreted as the number 3. followed | |
10361 | by .5 | |
10362 | */ | |
2f3197b3 | 10363 | if (*s == '.' && s[1] != '.') { |
79072805 | 10364 | floatit = TRUE; |
378cc40b | 10365 | *d++ = *s++; |
02aa26ce | 10366 | |
928753ea JH |
10367 | if (*s == '_') { |
10368 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10369 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10370 | "Misplaced _ in number"); |
10371 | lastub = s; | |
10372 | } | |
10373 | ||
10374 | /* copy, ignoring underbars, until we run out of digits. | |
02aa26ce | 10375 | */ |
fc36a67e | 10376 | for (; isDIGIT(*s) || *s == '_'; s++) { |
02aa26ce | 10377 | /* fixed length buffer check */ |
fc36a67e | 10378 | if (d >= e) |
cea2e8a9 | 10379 | Perl_croak(aTHX_ number_too_long); |
928753ea JH |
10380 | if (*s == '_') { |
10381 | if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1) | |
9014280d | 10382 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10383 | "Misplaced _ in number"); |
10384 | lastub = s; | |
10385 | } | |
10386 | else | |
fc36a67e | 10387 | *d++ = *s; |
378cc40b | 10388 | } |
928753ea JH |
10389 | /* fractional part ending in underbar? */ |
10390 | if (s[-1] == '_') { | |
10391 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10392 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10393 | "Misplaced _ in number"); |
10394 | } | |
dd629d5b GS |
10395 | if (*s == '.' && isDIGIT(s[1])) { |
10396 | /* oops, it's really a v-string, but without the "v" */ | |
f4758303 | 10397 | s = start; |
dd629d5b GS |
10398 | goto vstring; |
10399 | } | |
378cc40b | 10400 | } |
02aa26ce NT |
10401 | |
10402 | /* read exponent part, if present */ | |
3792a11b | 10403 | if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) { |
79072805 LW |
10404 | floatit = TRUE; |
10405 | s++; | |
02aa26ce NT |
10406 | |
10407 | /* regardless of whether user said 3E5 or 3e5, use lower 'e' */ | |
79072805 | 10408 | *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */ |
02aa26ce | 10409 | |
7fd134d9 JH |
10410 | /* stray preinitial _ */ |
10411 | if (*s == '_') { | |
10412 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10413 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
7fd134d9 JH |
10414 | "Misplaced _ in number"); |
10415 | lastub = s++; | |
10416 | } | |
10417 | ||
02aa26ce | 10418 | /* allow positive or negative exponent */ |
378cc40b LW |
10419 | if (*s == '+' || *s == '-') |
10420 | *d++ = *s++; | |
02aa26ce | 10421 | |
7fd134d9 JH |
10422 | /* stray initial _ */ |
10423 | if (*s == '_') { | |
10424 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10425 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
7fd134d9 JH |
10426 | "Misplaced _ in number"); |
10427 | lastub = s++; | |
10428 | } | |
10429 | ||
7fd134d9 JH |
10430 | /* read digits of exponent */ |
10431 | while (isDIGIT(*s) || *s == '_') { | |
10432 | if (isDIGIT(*s)) { | |
10433 | if (d >= e) | |
10434 | Perl_croak(aTHX_ number_too_long); | |
b3b48e3e | 10435 | *d++ = *s++; |
7fd134d9 JH |
10436 | } |
10437 | else { | |
10438 | if (ckWARN(WARN_SYNTAX) && | |
10439 | ((lastub && s == lastub + 1) || | |
b3b48e3e | 10440 | (!isDIGIT(s[1]) && s[1] != '_'))) |
9014280d | 10441 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
7fd134d9 | 10442 | "Misplaced _ in number"); |
b3b48e3e | 10443 | lastub = s++; |
7fd134d9 | 10444 | } |
7fd134d9 | 10445 | } |
378cc40b | 10446 | } |
02aa26ce | 10447 | |
02aa26ce NT |
10448 | |
10449 | /* make an sv from the string */ | |
79072805 | 10450 | sv = NEWSV(92,0); |
097ee67d | 10451 | |
0b7fceb9 | 10452 | /* |
58bb9ec3 NC |
10453 | We try to do an integer conversion first if no characters |
10454 | indicating "float" have been found. | |
0b7fceb9 MU |
10455 | */ |
10456 | ||
10457 | if (!floatit) { | |
58bb9ec3 NC |
10458 | UV uv; |
10459 | int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv); | |
10460 | ||
10461 | if (flags == IS_NUMBER_IN_UV) { | |
10462 | if (uv <= IV_MAX) | |
86554af2 | 10463 | sv_setiv(sv, uv); /* Prefer IVs over UVs. */ |
58bb9ec3 | 10464 | else |
c239479b | 10465 | sv_setuv(sv, uv); |
58bb9ec3 NC |
10466 | } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) { |
10467 | if (uv <= (UV) IV_MIN) | |
10468 | sv_setiv(sv, -(IV)uv); | |
10469 | else | |
10470 | floatit = TRUE; | |
10471 | } else | |
10472 | floatit = TRUE; | |
10473 | } | |
0b7fceb9 | 10474 | if (floatit) { |
58bb9ec3 NC |
10475 | /* terminate the string */ |
10476 | *d = '\0'; | |
86554af2 JH |
10477 | nv = Atof(PL_tokenbuf); |
10478 | sv_setnv(sv, nv); | |
10479 | } | |
86554af2 | 10480 | |
b8403495 JH |
10481 | if ( floatit ? (PL_hints & HINT_NEW_FLOAT) : |
10482 | (PL_hints & HINT_NEW_INTEGER) ) | |
4e553d73 | 10483 | sv = new_constant(PL_tokenbuf, d - PL_tokenbuf, |
b8403495 JH |
10484 | (floatit ? "float" : "integer"), |
10485 | sv, Nullsv, NULL); | |
378cc40b | 10486 | break; |
0b7fceb9 | 10487 | |
e312add1 | 10488 | /* if it starts with a v, it could be a v-string */ |
a7cb1f99 | 10489 | case 'v': |
dd629d5b | 10490 | vstring: |
f4758303 | 10491 | sv = NEWSV(92,5); /* preallocate storage space */ |
b0f01acb | 10492 | s = scan_vstring(s,sv); |
a7cb1f99 | 10493 | break; |
79072805 | 10494 | } |
a687059c | 10495 | |
02aa26ce NT |
10496 | /* make the op for the constant and return */ |
10497 | ||
a86a20aa | 10498 | if (sv) |
b73d6f50 | 10499 | lvalp->opval = newSVOP(OP_CONST, 0, sv); |
a7cb1f99 | 10500 | else |
b73d6f50 | 10501 | lvalp->opval = Nullop; |
a687059c | 10502 | |
73d840c0 | 10503 | return (char *)s; |
378cc40b LW |
10504 | } |
10505 | ||
76e3520e | 10506 | STATIC char * |
cea2e8a9 | 10507 | S_scan_formline(pTHX_ register char *s) |
378cc40b | 10508 | { |
79072805 | 10509 | register char *eol; |
378cc40b | 10510 | register char *t; |
79cb57f6 | 10511 | SV *stuff = newSVpvn("",0); |
79072805 | 10512 | bool needargs = FALSE; |
c5ee2135 | 10513 | bool eofmt = FALSE; |
378cc40b | 10514 | |
79072805 | 10515 | while (!needargs) { |
a1b95068 | 10516 | if (*s == '.') { |
79072805 | 10517 | /*SUPPRESS 530*/ |
51882d45 | 10518 | #ifdef PERL_STRICT_CR |
bf4acbe4 | 10519 | for (t = s+1;SPACE_OR_TAB(*t); t++) ; |
51882d45 | 10520 | #else |
bf4acbe4 | 10521 | for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ; |
51882d45 | 10522 | #endif |
c5ee2135 WL |
10523 | if (*t == '\n' || t == PL_bufend) { |
10524 | eofmt = TRUE; | |
79072805 | 10525 | break; |
c5ee2135 | 10526 | } |
79072805 | 10527 | } |
3280af22 | 10528 | if (PL_in_eval && !PL_rsfp) { |
07409e01 | 10529 | eol = (char *) memchr(s,'\n',PL_bufend-s); |
0f85fab0 | 10530 | if (!eol++) |
3280af22 | 10531 | eol = PL_bufend; |
0f85fab0 LW |
10532 | } |
10533 | else | |
3280af22 | 10534 | eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
79072805 | 10535 | if (*s != '#') { |
a0d0e21e LW |
10536 | for (t = s; t < eol; t++) { |
10537 | if (*t == '~' && t[1] == '~' && SvCUR(stuff)) { | |
10538 | needargs = FALSE; | |
10539 | goto enough; /* ~~ must be first line in formline */ | |
378cc40b | 10540 | } |
a0d0e21e LW |
10541 | if (*t == '@' || *t == '^') |
10542 | needargs = TRUE; | |
378cc40b | 10543 | } |
7121b347 MG |
10544 | if (eol > s) { |
10545 | sv_catpvn(stuff, s, eol-s); | |
2dc4c65b | 10546 | #ifndef PERL_STRICT_CR |
7121b347 MG |
10547 | if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') { |
10548 | char *end = SvPVX(stuff) + SvCUR(stuff); | |
10549 | end[-2] = '\n'; | |
10550 | end[-1] = '\0'; | |
b162af07 | 10551 | SvCUR_set(stuff, SvCUR(stuff) - 1); |
7121b347 | 10552 | } |
2dc4c65b | 10553 | #endif |
7121b347 MG |
10554 | } |
10555 | else | |
10556 | break; | |
79072805 LW |
10557 | } |
10558 | s = eol; | |
3280af22 NIS |
10559 | if (PL_rsfp) { |
10560 | s = filter_gets(PL_linestr, PL_rsfp, 0); | |
10561 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr); | |
10562 | PL_bufend = PL_bufptr + SvCUR(PL_linestr); | |
207e3d1a | 10563 | PL_last_lop = PL_last_uni = Nullch; |
79072805 | 10564 | if (!s) { |
3280af22 | 10565 | s = PL_bufptr; |
378cc40b LW |
10566 | break; |
10567 | } | |
378cc40b | 10568 | } |
463ee0b2 | 10569 | incline(s); |
79072805 | 10570 | } |
a0d0e21e LW |
10571 | enough: |
10572 | if (SvCUR(stuff)) { | |
3280af22 | 10573 | PL_expect = XTERM; |
79072805 | 10574 | if (needargs) { |
3280af22 NIS |
10575 | PL_lex_state = LEX_NORMAL; |
10576 | PL_nextval[PL_nexttoke].ival = 0; | |
79072805 LW |
10577 | force_next(','); |
10578 | } | |
a0d0e21e | 10579 | else |
3280af22 | 10580 | PL_lex_state = LEX_FORMLINE; |
1bd51a4c IH |
10581 | if (!IN_BYTES) { |
10582 | if (UTF && is_utf8_string((U8*)SvPVX(stuff), SvCUR(stuff))) | |
10583 | SvUTF8_on(stuff); | |
10584 | else if (PL_encoding) | |
10585 | sv_recode_to_utf8(stuff, PL_encoding); | |
10586 | } | |
3280af22 | 10587 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff); |
79072805 | 10588 | force_next(THING); |
3280af22 | 10589 | PL_nextval[PL_nexttoke].ival = OP_FORMLINE; |
79072805 | 10590 | force_next(LSTOP); |
378cc40b | 10591 | } |
79072805 | 10592 | else { |
8990e307 | 10593 | SvREFCNT_dec(stuff); |
c5ee2135 WL |
10594 | if (eofmt) |
10595 | PL_lex_formbrack = 0; | |
3280af22 | 10596 | PL_bufptr = s; |
79072805 LW |
10597 | } |
10598 | return s; | |
378cc40b | 10599 | } |
a687059c | 10600 | |
76e3520e | 10601 | STATIC void |
cea2e8a9 | 10602 | S_set_csh(pTHX) |
a687059c | 10603 | { |
ae986130 | 10604 | #ifdef CSH |
3280af22 NIS |
10605 | if (!PL_cshlen) |
10606 | PL_cshlen = strlen(PL_cshname); | |
ae986130 | 10607 | #endif |
a687059c | 10608 | } |
463ee0b2 | 10609 | |
ba6d6ac9 | 10610 | I32 |
864dbfa3 | 10611 | Perl_start_subparse(pTHX_ I32 is_format, U32 flags) |
8990e307 | 10612 | { |
3280af22 NIS |
10613 | I32 oldsavestack_ix = PL_savestack_ix; |
10614 | CV* outsidecv = PL_compcv; | |
8990e307 | 10615 | |
3280af22 NIS |
10616 | if (PL_compcv) { |
10617 | assert(SvTYPE(PL_compcv) == SVt_PVCV); | |
e9a444f0 | 10618 | } |
7766f137 | 10619 | SAVEI32(PL_subline); |
3280af22 | 10620 | save_item(PL_subname); |
3280af22 | 10621 | SAVESPTR(PL_compcv); |
3280af22 NIS |
10622 | |
10623 | PL_compcv = (CV*)NEWSV(1104,0); | |
10624 | sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV); | |
10625 | CvFLAGS(PL_compcv) |= flags; | |
10626 | ||
57843af0 | 10627 | PL_subline = CopLINE(PL_curcop); |
dd2155a4 | 10628 | CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB); |
3280af22 | 10629 | CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv); |
a3985cdc | 10630 | CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax; |
748a9306 | 10631 | |
8990e307 LW |
10632 | return oldsavestack_ix; |
10633 | } | |
10634 | ||
084592ab CN |
10635 | #ifdef __SC__ |
10636 | #pragma segment Perl_yylex | |
10637 | #endif | |
8990e307 | 10638 | int |
bfed75c6 | 10639 | Perl_yywarn(pTHX_ const char *s) |
8990e307 | 10640 | { |
faef0170 | 10641 | PL_in_eval |= EVAL_WARNONLY; |
748a9306 | 10642 | yyerror(s); |
faef0170 | 10643 | PL_in_eval &= ~EVAL_WARNONLY; |
748a9306 | 10644 | return 0; |
8990e307 LW |
10645 | } |
10646 | ||
10647 | int | |
bfed75c6 | 10648 | Perl_yyerror(pTHX_ const char *s) |
463ee0b2 | 10649 | { |
bfed75c6 AL |
10650 | const char *where = NULL; |
10651 | const char *context = NULL; | |
68dc0745 | 10652 | int contlen = -1; |
46fc3d4c | 10653 | SV *msg; |
463ee0b2 | 10654 | |
3280af22 | 10655 | if (!yychar || (yychar == ';' && !PL_rsfp)) |
54310121 | 10656 | where = "at EOF"; |
3280af22 NIS |
10657 | else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 && |
10658 | PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) { | |
f355267c JH |
10659 | /* |
10660 | Only for NetWare: | |
10661 | The code below is removed for NetWare because it abends/crashes on NetWare | |
10662 | when the script has error such as not having the closing quotes like: | |
10663 | if ($var eq "value) | |
10664 | Checking of white spaces is anyway done in NetWare code. | |
10665 | */ | |
10666 | #ifndef NETWARE | |
3280af22 NIS |
10667 | while (isSPACE(*PL_oldoldbufptr)) |
10668 | PL_oldoldbufptr++; | |
f355267c | 10669 | #endif |
3280af22 NIS |
10670 | context = PL_oldoldbufptr; |
10671 | contlen = PL_bufptr - PL_oldoldbufptr; | |
463ee0b2 | 10672 | } |
3280af22 NIS |
10673 | else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 && |
10674 | PL_oldbufptr != PL_bufptr) { | |
f355267c JH |
10675 | /* |
10676 | Only for NetWare: | |
10677 | The code below is removed for NetWare because it abends/crashes on NetWare | |
10678 | when the script has error such as not having the closing quotes like: | |
10679 | if ($var eq "value) | |
10680 | Checking of white spaces is anyway done in NetWare code. | |
10681 | */ | |
10682 | #ifndef NETWARE | |
3280af22 NIS |
10683 | while (isSPACE(*PL_oldbufptr)) |
10684 | PL_oldbufptr++; | |
f355267c | 10685 | #endif |
3280af22 NIS |
10686 | context = PL_oldbufptr; |
10687 | contlen = PL_bufptr - PL_oldbufptr; | |
463ee0b2 LW |
10688 | } |
10689 | else if (yychar > 255) | |
68dc0745 | 10690 | where = "next token ???"; |
12fbd33b | 10691 | else if (yychar == -2) { /* YYEMPTY */ |
3280af22 NIS |
10692 | if (PL_lex_state == LEX_NORMAL || |
10693 | (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL)) | |
68dc0745 | 10694 | where = "at end of line"; |
3280af22 | 10695 | else if (PL_lex_inpat) |
68dc0745 | 10696 | where = "within pattern"; |
463ee0b2 | 10697 | else |
68dc0745 | 10698 | where = "within string"; |
463ee0b2 | 10699 | } |
46fc3d4c | 10700 | else { |
79cb57f6 | 10701 | SV *where_sv = sv_2mortal(newSVpvn("next char ", 10)); |
46fc3d4c | 10702 | if (yychar < 32) |
cea2e8a9 | 10703 | Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar)); |
46fc3d4c | 10704 | else if (isPRINT_LC(yychar)) |
cea2e8a9 | 10705 | Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar); |
463ee0b2 | 10706 | else |
cea2e8a9 | 10707 | Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255); |
46fc3d4c | 10708 | where = SvPVX(where_sv); |
463ee0b2 | 10709 | } |
46fc3d4c | 10710 | msg = sv_2mortal(newSVpv(s, 0)); |
ed094faf | 10711 | Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ", |
248c2a4d | 10712 | OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop)); |
68dc0745 | 10713 | if (context) |
cea2e8a9 | 10714 | Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context); |
463ee0b2 | 10715 | else |
cea2e8a9 | 10716 | Perl_sv_catpvf(aTHX_ msg, "%s\n", where); |
57843af0 | 10717 | if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) { |
cf2093f6 | 10718 | Perl_sv_catpvf(aTHX_ msg, |
57def98f | 10719 | " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n", |
cf2093f6 | 10720 | (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start); |
3280af22 | 10721 | PL_multi_end = 0; |
a0d0e21e | 10722 | } |
56da5a46 RGS |
10723 | if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX)) |
10724 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg); | |
463ee0b2 | 10725 | else |
5a844595 | 10726 | qerror(msg); |
c7d6bfb2 GS |
10727 | if (PL_error_count >= 10) { |
10728 | if (PL_in_eval && SvCUR(ERRSV)) | |
d2560b70 | 10729 | Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n", |
248c2a4d | 10730 | ERRSV, OutCopFILE(PL_curcop)); |
c7d6bfb2 GS |
10731 | else |
10732 | Perl_croak(aTHX_ "%s has too many errors.\n", | |
248c2a4d | 10733 | OutCopFILE(PL_curcop)); |
c7d6bfb2 | 10734 | } |
3280af22 NIS |
10735 | PL_in_my = 0; |
10736 | PL_in_my_stash = Nullhv; | |
463ee0b2 LW |
10737 | return 0; |
10738 | } | |
084592ab CN |
10739 | #ifdef __SC__ |
10740 | #pragma segment Main | |
10741 | #endif | |
4e35701f | 10742 | |
b250498f | 10743 | STATIC char* |
3ae08724 | 10744 | S_swallow_bom(pTHX_ U8 *s) |
01ec43d0 | 10745 | { |
b250498f GS |
10746 | STRLEN slen; |
10747 | slen = SvCUR(PL_linestr); | |
7aa207d6 | 10748 | switch (s[0]) { |
4e553d73 NIS |
10749 | case 0xFF: |
10750 | if (s[1] == 0xFE) { | |
7aa207d6 | 10751 | /* UTF-16 little-endian? (or UTF32-LE?) */ |
3ae08724 | 10752 | if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */ |
7aa207d6 | 10753 | Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE"); |
01ec43d0 | 10754 | #ifndef PERL_NO_UTF16_FILTER |
7aa207d6 | 10755 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n"); |
3ae08724 | 10756 | s += 2; |
7aa207d6 | 10757 | utf16le: |
dea0fc0b JH |
10758 | if (PL_bufend > (char*)s) { |
10759 | U8 *news; | |
10760 | I32 newlen; | |
10761 | ||
10762 | filter_add(utf16rev_textfilter, NULL); | |
10763 | New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8); | |
1de9afcd RGS |
10764 | utf16_to_utf8_reversed(s, news, |
10765 | PL_bufend - (char*)s - 1, | |
10766 | &newlen); | |
7aa207d6 | 10767 | sv_setpvn(PL_linestr, (const char*)news, newlen); |
dea0fc0b | 10768 | Safefree(news); |
7aa207d6 JH |
10769 | SvUTF8_on(PL_linestr); |
10770 | s = (U8*)SvPVX(PL_linestr); | |
10771 | PL_bufend = SvPVX(PL_linestr) + newlen; | |
dea0fc0b | 10772 | } |
b250498f | 10773 | #else |
7aa207d6 | 10774 | Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE"); |
b250498f | 10775 | #endif |
01ec43d0 GS |
10776 | } |
10777 | break; | |
78ae23f5 | 10778 | case 0xFE: |
7aa207d6 | 10779 | if (s[1] == 0xFF) { /* UTF-16 big-endian? */ |
01ec43d0 | 10780 | #ifndef PERL_NO_UTF16_FILTER |
7aa207d6 | 10781 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n"); |
dea0fc0b | 10782 | s += 2; |
7aa207d6 | 10783 | utf16be: |
dea0fc0b JH |
10784 | if (PL_bufend > (char *)s) { |
10785 | U8 *news; | |
10786 | I32 newlen; | |
10787 | ||
10788 | filter_add(utf16_textfilter, NULL); | |
10789 | New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8); | |
1de9afcd RGS |
10790 | utf16_to_utf8(s, news, |
10791 | PL_bufend - (char*)s, | |
10792 | &newlen); | |
7aa207d6 | 10793 | sv_setpvn(PL_linestr, (const char*)news, newlen); |
dea0fc0b | 10794 | Safefree(news); |
7aa207d6 JH |
10795 | SvUTF8_on(PL_linestr); |
10796 | s = (U8*)SvPVX(PL_linestr); | |
10797 | PL_bufend = SvPVX(PL_linestr) + newlen; | |
dea0fc0b | 10798 | } |
b250498f | 10799 | #else |
7aa207d6 | 10800 | Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE"); |
b250498f | 10801 | #endif |
01ec43d0 GS |
10802 | } |
10803 | break; | |
3ae08724 GS |
10804 | case 0xEF: |
10805 | if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) { | |
7aa207d6 | 10806 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n"); |
01ec43d0 GS |
10807 | s += 3; /* UTF-8 */ |
10808 | } | |
10809 | break; | |
10810 | case 0: | |
7aa207d6 JH |
10811 | if (slen > 3) { |
10812 | if (s[1] == 0) { | |
10813 | if (s[2] == 0xFE && s[3] == 0xFF) { | |
10814 | /* UTF-32 big-endian */ | |
10815 | Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE"); | |
10816 | } | |
10817 | } | |
10818 | else if (s[2] == 0 && s[3] != 0) { | |
10819 | /* Leading bytes | |
10820 | * 00 xx 00 xx | |
10821 | * are a good indicator of UTF-16BE. */ | |
10822 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n"); | |
10823 | goto utf16be; | |
10824 | } | |
01ec43d0 | 10825 | } |
7aa207d6 JH |
10826 | default: |
10827 | if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) { | |
10828 | /* Leading bytes | |
10829 | * xx 00 xx 00 | |
10830 | * are a good indicator of UTF-16LE. */ | |
10831 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n"); | |
10832 | goto utf16le; | |
10833 | } | |
01ec43d0 | 10834 | } |
b8f84bb2 | 10835 | return (char*)s; |
b250498f | 10836 | } |
4755096e | 10837 | |
4755096e GS |
10838 | /* |
10839 | * restore_rsfp | |
10840 | * Restore a source filter. | |
10841 | */ | |
10842 | ||
10843 | static void | |
acfe0abc | 10844 | restore_rsfp(pTHX_ void *f) |
4755096e GS |
10845 | { |
10846 | PerlIO *fp = (PerlIO*)f; | |
10847 | ||
10848 | if (PL_rsfp == PerlIO_stdin()) | |
10849 | PerlIO_clearerr(PL_rsfp); | |
10850 | else if (PL_rsfp && (PL_rsfp != fp)) | |
10851 | PerlIO_close(PL_rsfp); | |
10852 | PL_rsfp = fp; | |
10853 | } | |
6e3aabd6 GS |
10854 | |
10855 | #ifndef PERL_NO_UTF16_FILTER | |
10856 | static I32 | |
acfe0abc | 10857 | utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
6e3aabd6 | 10858 | { |
1de9afcd | 10859 | STRLEN old = SvCUR(sv); |
6e3aabd6 | 10860 | I32 count = FILTER_READ(idx+1, sv, maxlen); |
1de9afcd RGS |
10861 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
10862 | "utf16_textfilter(%p): %d %d (%d)\n", | |
4fccd7c6 | 10863 | utf16_textfilter, idx, maxlen, (int) count)); |
6e3aabd6 GS |
10864 | if (count) { |
10865 | U8* tmps; | |
dea0fc0b | 10866 | I32 newlen; |
6e3aabd6 | 10867 | New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8); |
1de9afcd RGS |
10868 | Copy(SvPVX(sv), tmps, old, char); |
10869 | utf16_to_utf8((U8*)SvPVX(sv) + old, tmps + old, | |
10870 | SvCUR(sv) - old, &newlen); | |
10871 | sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old); | |
6e3aabd6 | 10872 | } |
1de9afcd RGS |
10873 | DEBUG_P({sv_dump(sv);}); |
10874 | return SvCUR(sv); | |
6e3aabd6 GS |
10875 | } |
10876 | ||
10877 | static I32 | |
acfe0abc | 10878 | utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
6e3aabd6 | 10879 | { |
1de9afcd | 10880 | STRLEN old = SvCUR(sv); |
6e3aabd6 | 10881 | I32 count = FILTER_READ(idx+1, sv, maxlen); |
1de9afcd RGS |
10882 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
10883 | "utf16rev_textfilter(%p): %d %d (%d)\n", | |
4fccd7c6 | 10884 | utf16rev_textfilter, idx, maxlen, (int) count)); |
6e3aabd6 GS |
10885 | if (count) { |
10886 | U8* tmps; | |
dea0fc0b | 10887 | I32 newlen; |
6e3aabd6 | 10888 | New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8); |
1de9afcd RGS |
10889 | Copy(SvPVX(sv), tmps, old, char); |
10890 | utf16_to_utf8((U8*)SvPVX(sv) + old, tmps + old, | |
10891 | SvCUR(sv) - old, &newlen); | |
10892 | sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old); | |
6e3aabd6 | 10893 | } |
1de9afcd | 10894 | DEBUG_P({ sv_dump(sv); }); |
6e3aabd6 GS |
10895 | return count; |
10896 | } | |
10897 | #endif | |
9f4817db | 10898 | |
f333445c JP |
10899 | /* |
10900 | Returns a pointer to the next character after the parsed | |
10901 | vstring, as well as updating the passed in sv. | |
10902 | ||
10903 | Function must be called like | |
10904 | ||
10905 | sv = NEWSV(92,5); | |
10906 | s = scan_vstring(s,sv); | |
10907 | ||
10908 | The sv should already be large enough to store the vstring | |
10909 | passed in, for performance reasons. | |
10910 | ||
10911 | */ | |
10912 | ||
10913 | char * | |
bfed75c6 | 10914 | Perl_scan_vstring(pTHX_ const char *s, SV *sv) |
f333445c | 10915 | { |
bfed75c6 AL |
10916 | const char *pos = s; |
10917 | const char *start = s; | |
f333445c | 10918 | if (*pos == 'v') pos++; /* get past 'v' */ |
3e884cbf JH |
10919 | while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_')) |
10920 | pos++; | |
f333445c JP |
10921 | if ( *pos != '.') { |
10922 | /* this may not be a v-string if followed by => */ | |
bfed75c6 | 10923 | const char *next = pos; |
8fc7bb1c SM |
10924 | while (next < PL_bufend && isSPACE(*next)) |
10925 | ++next; | |
10926 | if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) { | |
f333445c JP |
10927 | /* return string not v-string */ |
10928 | sv_setpvn(sv,(char *)s,pos-s); | |
73d840c0 | 10929 | return (char *)pos; |
f333445c JP |
10930 | } |
10931 | } | |
10932 | ||
10933 | if (!isALPHA(*pos)) { | |
10934 | UV rev; | |
89ebb4a3 | 10935 | U8 tmpbuf[UTF8_MAXBYTES+1]; |
f333445c JP |
10936 | U8 *tmpend; |
10937 | ||
10938 | if (*s == 'v') s++; /* get past 'v' */ | |
10939 | ||
10940 | sv_setpvn(sv, "", 0); | |
10941 | ||
10942 | for (;;) { | |
10943 | rev = 0; | |
10944 | { | |
10945 | /* this is atoi() that tolerates underscores */ | |
bfed75c6 | 10946 | const char *end = pos; |
f333445c JP |
10947 | UV mult = 1; |
10948 | while (--end >= s) { | |
10949 | UV orev; | |
10950 | if (*end == '_') | |
10951 | continue; | |
10952 | orev = rev; | |
10953 | rev += (*end - '0') * mult; | |
10954 | mult *= 10; | |
10955 | if (orev > rev && ckWARN_d(WARN_OVERFLOW)) | |
10956 | Perl_warner(aTHX_ packWARN(WARN_OVERFLOW), | |
10957 | "Integer overflow in decimal number"); | |
10958 | } | |
10959 | } | |
10960 | #ifdef EBCDIC | |
10961 | if (rev > 0x7FFFFFFF) | |
10962 | Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647"); | |
10963 | #endif | |
10964 | /* Append native character for the rev point */ | |
10965 | tmpend = uvchr_to_utf8(tmpbuf, rev); | |
10966 | sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf); | |
10967 | if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev))) | |
10968 | SvUTF8_on(sv); | |
3e884cbf | 10969 | if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1])) |
f333445c JP |
10970 | s = ++pos; |
10971 | else { | |
10972 | s = pos; | |
10973 | break; | |
10974 | } | |
3e884cbf | 10975 | while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_')) |
f333445c JP |
10976 | pos++; |
10977 | } | |
10978 | SvPOK_on(sv); | |
10979 | sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start); | |
10980 | SvRMAGICAL_on(sv); | |
10981 | } | |
73d840c0 | 10982 | return (char *)s; |
f333445c JP |
10983 | } |
10984 | ||
1da4ca5f NC |
10985 | /* |
10986 | * Local variables: | |
10987 | * c-indentation-style: bsd | |
10988 | * c-basic-offset: 4 | |
10989 | * indent-tabs-mode: t | |
10990 | * End: | |
10991 | * | |
10992 | * vim: shiftwidth=4: | |
10993 | */ |