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 | |
bfed75c6 AL |
29 | static char const ident_too_long[] = "Identifier too long"; |
30 | static char const c_without_g[] = "Use of /c modifier is meaningless without /g"; | |
31 | static char const c_in_subst[] = "Use of /c modifier is meaningless in s///"; | |
8903cb82 | 32 | |
acfe0abc | 33 | static void restore_rsfp(pTHX_ void *f); |
6e3aabd6 | 34 | #ifndef PERL_NO_UTF16_FILTER |
acfe0abc GS |
35 | static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen); |
36 | static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen); | |
6e3aabd6 | 37 | #endif |
51371543 | 38 | |
9059aa12 LW |
39 | #define XFAKEBRACK 128 |
40 | #define XENUMMASK 127 | |
41 | ||
39e02b42 JH |
42 | #ifdef USE_UTF8_SCRIPTS |
43 | # define UTF (!IN_BYTES) | |
2b9d42f0 | 44 | #else |
746b446a | 45 | # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8)) |
2b9d42f0 | 46 | #endif |
a0ed51b3 | 47 | |
61f0cdd9 | 48 | /* In variables named $^X, these are the legal values for X. |
2b92dfce GS |
49 | * 1999-02-27 mjd-perl-patch@plover.com */ |
50 | #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x))) | |
51 | ||
bf4acbe4 GS |
52 | /* On MacOS, respect nonbreaking spaces */ |
53 | #ifdef MACOS_TRADITIONAL | |
54 | #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t') | |
55 | #else | |
56 | #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t') | |
57 | #endif | |
58 | ||
ffb4593c NT |
59 | /* LEX_* are values for PL_lex_state, the state of the lexer. |
60 | * They are arranged oddly so that the guard on the switch statement | |
79072805 LW |
61 | * can get by with a single comparison (if the compiler is smart enough). |
62 | */ | |
63 | ||
fb73857a | 64 | /* #define LEX_NOTPARSING 11 is done in perl.h. */ |
65 | ||
55497cff | 66 | #define LEX_NORMAL 10 |
67 | #define LEX_INTERPNORMAL 9 | |
68 | #define LEX_INTERPCASEMOD 8 | |
69 | #define LEX_INTERPPUSH 7 | |
70 | #define LEX_INTERPSTART 6 | |
71 | #define LEX_INTERPEND 5 | |
72 | #define LEX_INTERPENDMAYBE 4 | |
73 | #define LEX_INTERPCONCAT 3 | |
74 | #define LEX_INTERPCONST 2 | |
75 | #define LEX_FORMLINE 1 | |
76 | #define LEX_KNOWNEXT 0 | |
79072805 | 77 | |
bbf60fe6 | 78 | #ifdef DEBUGGING |
bfed75c6 | 79 | static char const* lex_state_names[] = { |
bbf60fe6 DM |
80 | "KNOWNEXT", |
81 | "FORMLINE", | |
82 | "INTERPCONST", | |
83 | "INTERPCONCAT", | |
84 | "INTERPENDMAYBE", | |
85 | "INTERPEND", | |
86 | "INTERPSTART", | |
87 | "INTERPPUSH", | |
88 | "INTERPCASEMOD", | |
89 | "INTERPNORMAL", | |
90 | "NORMAL" | |
91 | }; | |
92 | #endif | |
93 | ||
79072805 LW |
94 | #ifdef ff_next |
95 | #undef ff_next | |
d48672a2 LW |
96 | #endif |
97 | ||
79072805 | 98 | #include "keywords.h" |
fe14fcc3 | 99 | |
ffb4593c NT |
100 | /* CLINE is a macro that ensures PL_copline has a sane value */ |
101 | ||
ae986130 LW |
102 | #ifdef CLINE |
103 | #undef CLINE | |
104 | #endif | |
57843af0 | 105 | #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline)) |
3280af22 | 106 | |
ffb4593c NT |
107 | /* |
108 | * Convenience functions to return different tokens and prime the | |
9cbb5ea2 | 109 | * lexer for the next token. They all take an argument. |
ffb4593c NT |
110 | * |
111 | * TOKEN : generic token (used for '(', DOLSHARP, etc) | |
112 | * OPERATOR : generic operator | |
113 | * AOPERATOR : assignment operator | |
114 | * PREBLOCK : beginning the block after an if, while, foreach, ... | |
115 | * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref) | |
116 | * PREREF : *EXPR where EXPR is not a simple identifier | |
117 | * TERM : expression term | |
118 | * LOOPX : loop exiting command (goto, last, dump, etc) | |
119 | * FTST : file test operator | |
120 | * FUN0 : zero-argument function | |
2d2e263d | 121 | * FUN1 : not used, except for not, which isn't a UNIOP |
ffb4593c NT |
122 | * BOop : bitwise or or xor |
123 | * BAop : bitwise and | |
124 | * SHop : shift operator | |
125 | * PWop : power operator | |
9cbb5ea2 | 126 | * PMop : pattern-matching operator |
ffb4593c NT |
127 | * Aop : addition-level operator |
128 | * Mop : multiplication-level operator | |
129 | * Eop : equality-testing operator | |
e5edeb50 | 130 | * Rop : relational operator <= != gt |
ffb4593c NT |
131 | * |
132 | * Also see LOP and lop() below. | |
133 | */ | |
134 | ||
998054bd | 135 | #ifdef DEBUGGING /* Serve -DT. */ |
bbf60fe6 | 136 | # define REPORT(retval) tokereport(s,(int)retval) |
998054bd | 137 | #else |
bbf60fe6 | 138 | # define REPORT(retval) (retval) |
998054bd SC |
139 | #endif |
140 | ||
bbf60fe6 DM |
141 | #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval)) |
142 | #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval)) | |
143 | #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval))) | |
144 | #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval)) | |
145 | #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval)) | |
146 | #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval)) | |
147 | #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval)) | |
148 | #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX)) | |
149 | #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP)) | |
150 | #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0)) | |
151 | #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1)) | |
152 | #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP))) | |
153 | #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP))) | |
154 | #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP))) | |
155 | #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP))) | |
156 | #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP)) | |
157 | #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP))) | |
158 | #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP))) | |
159 | #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP)) | |
160 | #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP)) | |
2f3197b3 | 161 | |
a687059c LW |
162 | /* This bit of chicanery makes a unary function followed by |
163 | * a parenthesis into a function with one argument, highest precedence. | |
6f33ba73 RGS |
164 | * The UNIDOR macro is for unary functions that can be followed by the // |
165 | * operator (such as C<shift // 0>). | |
a687059c | 166 | */ |
bbf60fe6 DM |
167 | #define UNI2(f,x) return ( \ |
168 | yylval.ival = f, \ | |
6f33ba73 | 169 | PL_expect = x, \ |
3280af22 NIS |
170 | PL_bufptr = s, \ |
171 | PL_last_uni = PL_oldbufptr, \ | |
172 | PL_last_lop_op = f, \ | |
bbf60fe6 DM |
173 | REPORT( \ |
174 | (*s == '(' || (s = skipspace(s), *s == '(') \ | |
175 | ? (int)FUNC1 : (int)UNIOP))) | |
6f33ba73 RGS |
176 | #define UNI(f) UNI2(f,XTERM) |
177 | #define UNIDOR(f) UNI2(f,XTERMORDORDOR) | |
a687059c | 178 | |
bbf60fe6 DM |
179 | #define UNIBRACK(f) return ( \ |
180 | yylval.ival = f, \ | |
3280af22 NIS |
181 | PL_bufptr = s, \ |
182 | PL_last_uni = PL_oldbufptr, \ | |
bbf60fe6 DM |
183 | REPORT( \ |
184 | (*s == '(' || (s = skipspace(s), *s == '(') \ | |
185 | ? (int)FUNC1 : (int)UNIOP))) | |
79072805 | 186 | |
9f68db38 | 187 | /* grandfather return to old style */ |
3280af22 | 188 | #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP) |
79072805 | 189 | |
8fa7f367 JH |
190 | #ifdef DEBUGGING |
191 | ||
bbf60fe6 DM |
192 | /* how to interpret the yylval associated with the token */ |
193 | enum token_type { | |
194 | TOKENTYPE_NONE, | |
195 | TOKENTYPE_IVAL, | |
196 | TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */ | |
197 | TOKENTYPE_PVAL, | |
198 | TOKENTYPE_OPVAL, | |
199 | TOKENTYPE_GVVAL | |
200 | }; | |
201 | ||
bfed75c6 | 202 | static struct debug_tokens { const int token, type; const char *name; } debug_tokens[] = |
9041c2e3 | 203 | { |
bbf60fe6 DM |
204 | { ADDOP, TOKENTYPE_OPNUM, "ADDOP" }, |
205 | { ANDAND, TOKENTYPE_NONE, "ANDAND" }, | |
206 | { ANDOP, TOKENTYPE_NONE, "ANDOP" }, | |
207 | { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" }, | |
208 | { ARROW, TOKENTYPE_NONE, "ARROW" }, | |
209 | { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" }, | |
210 | { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" }, | |
211 | { BITOROP, TOKENTYPE_OPNUM, "BITOROP" }, | |
212 | { COLONATTR, TOKENTYPE_NONE, "COLONATTR" }, | |
213 | { CONTINUE, TOKENTYPE_NONE, "CONTINUE" }, | |
214 | { DO, TOKENTYPE_NONE, "DO" }, | |
215 | { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" }, | |
216 | { DORDOR, TOKENTYPE_NONE, "DORDOR" }, | |
217 | { DOROP, TOKENTYPE_OPNUM, "DOROP" }, | |
218 | { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" }, | |
219 | { ELSE, TOKENTYPE_NONE, "ELSE" }, | |
220 | { ELSIF, TOKENTYPE_IVAL, "ELSIF" }, | |
221 | { EQOP, TOKENTYPE_OPNUM, "EQOP" }, | |
222 | { FOR, TOKENTYPE_IVAL, "FOR" }, | |
223 | { FORMAT, TOKENTYPE_NONE, "FORMAT" }, | |
224 | { FUNC, TOKENTYPE_OPNUM, "FUNC" }, | |
225 | { FUNC0, TOKENTYPE_OPNUM, "FUNC0" }, | |
226 | { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" }, | |
227 | { FUNC1, TOKENTYPE_OPNUM, "FUNC1" }, | |
228 | { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" }, | |
229 | { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" }, | |
230 | { IF, TOKENTYPE_IVAL, "IF" }, | |
231 | { LABEL, TOKENTYPE_PVAL, "LABEL" }, | |
232 | { LOCAL, TOKENTYPE_IVAL, "LOCAL" }, | |
233 | { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" }, | |
234 | { LSTOP, TOKENTYPE_OPNUM, "LSTOP" }, | |
235 | { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" }, | |
236 | { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" }, | |
237 | { METHOD, TOKENTYPE_OPVAL, "METHOD" }, | |
238 | { MULOP, TOKENTYPE_OPNUM, "MULOP" }, | |
239 | { MY, TOKENTYPE_IVAL, "MY" }, | |
240 | { MYSUB, TOKENTYPE_NONE, "MYSUB" }, | |
241 | { NOAMP, TOKENTYPE_NONE, "NOAMP" }, | |
242 | { NOTOP, TOKENTYPE_NONE, "NOTOP" }, | |
243 | { OROP, TOKENTYPE_IVAL, "OROP" }, | |
244 | { OROR, TOKENTYPE_NONE, "OROR" }, | |
245 | { PACKAGE, TOKENTYPE_NONE, "PACKAGE" }, | |
246 | { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" }, | |
247 | { POSTDEC, TOKENTYPE_NONE, "POSTDEC" }, | |
248 | { POSTINC, TOKENTYPE_NONE, "POSTINC" }, | |
249 | { POWOP, TOKENTYPE_OPNUM, "POWOP" }, | |
250 | { PREDEC, TOKENTYPE_NONE, "PREDEC" }, | |
251 | { PREINC, TOKENTYPE_NONE, "PREINC" }, | |
252 | { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" }, | |
253 | { REFGEN, TOKENTYPE_NONE, "REFGEN" }, | |
254 | { RELOP, TOKENTYPE_OPNUM, "RELOP" }, | |
255 | { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" }, | |
256 | { SUB, TOKENTYPE_NONE, "SUB" }, | |
257 | { THING, TOKENTYPE_OPVAL, "THING" }, | |
258 | { UMINUS, TOKENTYPE_NONE, "UMINUS" }, | |
259 | { UNIOP, TOKENTYPE_OPNUM, "UNIOP" }, | |
260 | { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" }, | |
261 | { UNLESS, TOKENTYPE_IVAL, "UNLESS" }, | |
262 | { UNTIL, TOKENTYPE_IVAL, "UNTIL" }, | |
263 | { USE, TOKENTYPE_IVAL, "USE" }, | |
264 | { WHILE, TOKENTYPE_IVAL, "WHILE" }, | |
265 | { WORD, TOKENTYPE_OPVAL, "WORD" }, | |
266 | { 0, TOKENTYPE_NONE, 0 } | |
267 | }; | |
268 | ||
269 | /* dump the returned token in rv, plus any optional arg in yylval */ | |
998054bd | 270 | |
bbf60fe6 | 271 | STATIC int |
bfed75c6 | 272 | S_tokereport(pTHX_ const char* s, I32 rv) |
bbf60fe6 DM |
273 | { |
274 | if (DEBUG_T_TEST) { | |
bfed75c6 | 275 | const char *name = Nullch; |
bbf60fe6 DM |
276 | enum token_type type = TOKENTYPE_NONE; |
277 | struct debug_tokens *p; | |
bfed75c6 | 278 | SV* report = newSVpvn("<== ", 4); |
bbf60fe6 DM |
279 | |
280 | for (p = debug_tokens; p->token; p++) { | |
281 | if (p->token == (int)rv) { | |
282 | name = p->name; | |
283 | type = p->type; | |
284 | break; | |
285 | } | |
286 | } | |
287 | if (name) | |
54667de8 | 288 | Perl_sv_catpv(aTHX_ report, name); |
bbf60fe6 DM |
289 | else if ((char)rv > ' ' && (char)rv < '~') |
290 | Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv); | |
291 | else if (!rv) | |
54667de8 | 292 | Perl_sv_catpv(aTHX_ report, "EOF"); |
bbf60fe6 DM |
293 | else |
294 | Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv); | |
295 | switch (type) { | |
296 | case TOKENTYPE_NONE: | |
297 | case TOKENTYPE_GVVAL: /* doesn't appear to be used */ | |
298 | break; | |
299 | case TOKENTYPE_IVAL: | |
300 | Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", yylval.ival); | |
301 | break; | |
302 | case TOKENTYPE_OPNUM: | |
303 | Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)", | |
304 | PL_op_name[yylval.ival]); | |
305 | break; | |
306 | case TOKENTYPE_PVAL: | |
307 | Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval); | |
308 | break; | |
309 | case TOKENTYPE_OPVAL: | |
401441c0 RGS |
310 | if (yylval.opval) |
311 | Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)", | |
bbf60fe6 | 312 | PL_op_name[yylval.opval->op_type]); |
401441c0 RGS |
313 | else |
314 | Perl_sv_catpv(aTHX_ report, "(opval=null)"); | |
bbf60fe6 DM |
315 | break; |
316 | } | |
317 | Perl_sv_catpvf(aTHX_ report, " at line %d [", CopLINE(PL_curcop)); | |
998054bd SC |
318 | if (s - PL_bufptr > 0) |
319 | sv_catpvn(report, PL_bufptr, s - PL_bufptr); | |
320 | else { | |
321 | if (PL_oldbufptr && *PL_oldbufptr) | |
322 | sv_catpv(report, PL_tokenbuf); | |
323 | } | |
bbf60fe6 DM |
324 | PerlIO_printf(Perl_debug_log, "### %s]\n", SvPV_nolen(report)); |
325 | }; | |
326 | return (int)rv; | |
998054bd SC |
327 | } |
328 | ||
8fa7f367 JH |
329 | #endif |
330 | ||
ffb4593c NT |
331 | /* |
332 | * S_ao | |
333 | * | |
c963b151 BD |
334 | * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR |
335 | * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN | |
ffb4593c NT |
336 | */ |
337 | ||
76e3520e | 338 | STATIC int |
cea2e8a9 | 339 | S_ao(pTHX_ int toketype) |
a0d0e21e | 340 | { |
3280af22 NIS |
341 | if (*PL_bufptr == '=') { |
342 | PL_bufptr++; | |
a0d0e21e LW |
343 | if (toketype == ANDAND) |
344 | yylval.ival = OP_ANDASSIGN; | |
345 | else if (toketype == OROR) | |
346 | yylval.ival = OP_ORASSIGN; | |
c963b151 BD |
347 | else if (toketype == DORDOR) |
348 | yylval.ival = OP_DORASSIGN; | |
a0d0e21e LW |
349 | toketype = ASSIGNOP; |
350 | } | |
351 | return toketype; | |
352 | } | |
353 | ||
ffb4593c NT |
354 | /* |
355 | * S_no_op | |
356 | * When Perl expects an operator and finds something else, no_op | |
357 | * prints the warning. It always prints "<something> found where | |
358 | * operator expected. It prints "Missing semicolon on previous line?" | |
359 | * if the surprise occurs at the start of the line. "do you need to | |
360 | * predeclare ..." is printed out for code like "sub bar; foo bar $x" | |
361 | * where the compiler doesn't know if foo is a method call or a function. | |
362 | * It prints "Missing operator before end of line" if there's nothing | |
363 | * after the missing operator, or "... before <...>" if there is something | |
364 | * after the missing operator. | |
365 | */ | |
366 | ||
76e3520e | 367 | STATIC void |
bfed75c6 | 368 | S_no_op(pTHX_ const char *what, char *s) |
463ee0b2 | 369 | { |
3280af22 NIS |
370 | char *oldbp = PL_bufptr; |
371 | bool is_first = (PL_oldbufptr == PL_linestart); | |
68dc0745 | 372 | |
1189a94a GS |
373 | if (!s) |
374 | s = oldbp; | |
07c798fb | 375 | else |
1189a94a | 376 | PL_bufptr = s; |
cea2e8a9 | 377 | yywarn(Perl_form(aTHX_ "%s found where operator expected", what)); |
56da5a46 RGS |
378 | if (ckWARN_d(WARN_SYNTAX)) { |
379 | if (is_first) | |
380 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
381 | "\t(Missing semicolon on previous line?)\n"); | |
382 | else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) { | |
383 | char *t; | |
384 | for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ; | |
385 | if (t < PL_bufptr && isSPACE(*t)) | |
386 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
387 | "\t(Do you need to predeclare %.*s?)\n", | |
388 | t - PL_oldoldbufptr, PL_oldoldbufptr); | |
389 | } | |
390 | else { | |
391 | assert(s >= oldbp); | |
392 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), | |
393 | "\t(Missing operator before %.*s?)\n", s - oldbp, oldbp); | |
394 | } | |
07c798fb | 395 | } |
3280af22 | 396 | PL_bufptr = oldbp; |
8990e307 LW |
397 | } |
398 | ||
ffb4593c NT |
399 | /* |
400 | * S_missingterm | |
401 | * Complain about missing quote/regexp/heredoc terminator. | |
402 | * If it's called with (char *)NULL then it cauterizes the line buffer. | |
403 | * If we're in a delimited string and the delimiter is a control | |
404 | * character, it's reformatted into a two-char sequence like ^C. | |
405 | * This is fatal. | |
406 | */ | |
407 | ||
76e3520e | 408 | STATIC void |
cea2e8a9 | 409 | S_missingterm(pTHX_ char *s) |
8990e307 LW |
410 | { |
411 | char tmpbuf[3]; | |
412 | char q; | |
413 | if (s) { | |
414 | char *nl = strrchr(s,'\n'); | |
d2719217 | 415 | if (nl) |
8990e307 LW |
416 | *nl = '\0'; |
417 | } | |
9d116dd7 JH |
418 | else if ( |
419 | #ifdef EBCDIC | |
420 | iscntrl(PL_multi_close) | |
421 | #else | |
422 | PL_multi_close < 32 || PL_multi_close == 127 | |
423 | #endif | |
424 | ) { | |
8990e307 | 425 | *tmpbuf = '^'; |
3280af22 | 426 | tmpbuf[1] = toCTRL(PL_multi_close); |
8990e307 LW |
427 | tmpbuf[2] = '\0'; |
428 | s = tmpbuf; | |
429 | } | |
430 | else { | |
eb160463 | 431 | *tmpbuf = (char)PL_multi_close; |
8990e307 LW |
432 | tmpbuf[1] = '\0'; |
433 | s = tmpbuf; | |
434 | } | |
435 | q = strchr(s,'"') ? '\'' : '"'; | |
cea2e8a9 | 436 | Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q); |
463ee0b2 | 437 | } |
79072805 | 438 | |
ffb4593c NT |
439 | /* |
440 | * Perl_deprecate | |
ffb4593c NT |
441 | */ |
442 | ||
79072805 | 443 | void |
bfed75c6 | 444 | Perl_deprecate(pTHX_ const char *s) |
a0d0e21e | 445 | { |
599cee73 | 446 | if (ckWARN(WARN_DEPRECATED)) |
9014280d | 447 | Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s); |
a0d0e21e LW |
448 | } |
449 | ||
12bcd1a6 | 450 | void |
bfed75c6 | 451 | Perl_deprecate_old(pTHX_ const char *s) |
12bcd1a6 PM |
452 | { |
453 | /* This function should NOT be called for any new deprecated warnings */ | |
454 | /* Use Perl_deprecate instead */ | |
455 | /* */ | |
456 | /* It is here to maintain backward compatibility with the pre-5.8 */ | |
457 | /* warnings category hierarchy. The "deprecated" category used to */ | |
458 | /* live under the "syntax" category. It is now a top-level category */ | |
459 | /* in its own right. */ | |
460 | ||
461 | if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX)) | |
bfed75c6 | 462 | Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX), |
12bcd1a6 PM |
463 | "Use of %s is deprecated", s); |
464 | } | |
465 | ||
ffb4593c NT |
466 | /* |
467 | * depcom | |
9cbb5ea2 | 468 | * Deprecate a comma-less variable list. |
ffb4593c NT |
469 | */ |
470 | ||
76e3520e | 471 | STATIC void |
cea2e8a9 | 472 | S_depcom(pTHX) |
a0d0e21e | 473 | { |
12bcd1a6 | 474 | deprecate_old("comma-less variable list"); |
a0d0e21e LW |
475 | } |
476 | ||
ffb4593c | 477 | /* |
9cbb5ea2 GS |
478 | * experimental text filters for win32 carriage-returns, utf16-to-utf8 and |
479 | * utf16-to-utf8-reversed. | |
ffb4593c NT |
480 | */ |
481 | ||
c39cd008 GS |
482 | #ifdef PERL_CR_FILTER |
483 | static void | |
484 | strip_return(SV *sv) | |
485 | { | |
486 | register char *s = SvPVX(sv); | |
487 | register char *e = s + SvCUR(sv); | |
488 | /* outer loop optimized to do nothing if there are no CR-LFs */ | |
489 | while (s < e) { | |
490 | if (*s++ == '\r' && *s == '\n') { | |
491 | /* hit a CR-LF, need to copy the rest */ | |
492 | register char *d = s - 1; | |
493 | *d++ = *s++; | |
494 | while (s < e) { | |
495 | if (*s == '\r' && s[1] == '\n') | |
496 | s++; | |
497 | *d++ = *s++; | |
498 | } | |
499 | SvCUR(sv) -= s - d; | |
500 | return; | |
501 | } | |
502 | } | |
503 | } | |
a868473f | 504 | |
76e3520e | 505 | STATIC I32 |
c39cd008 | 506 | S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
a868473f | 507 | { |
c39cd008 GS |
508 | I32 count = FILTER_READ(idx+1, sv, maxlen); |
509 | if (count > 0 && !maxlen) | |
510 | strip_return(sv); | |
511 | return count; | |
a868473f NIS |
512 | } |
513 | #endif | |
514 | ||
ffb4593c NT |
515 | /* |
516 | * Perl_lex_start | |
9cbb5ea2 GS |
517 | * Initialize variables. Uses the Perl save_stack to save its state (for |
518 | * recursive calls to the parser). | |
ffb4593c NT |
519 | */ |
520 | ||
a0d0e21e | 521 | void |
864dbfa3 | 522 | Perl_lex_start(pTHX_ SV *line) |
79072805 | 523 | { |
8990e307 LW |
524 | char *s; |
525 | STRLEN len; | |
526 | ||
3280af22 NIS |
527 | SAVEI32(PL_lex_dojoin); |
528 | SAVEI32(PL_lex_brackets); | |
3280af22 NIS |
529 | SAVEI32(PL_lex_casemods); |
530 | SAVEI32(PL_lex_starts); | |
531 | SAVEI32(PL_lex_state); | |
7766f137 | 532 | SAVEVPTR(PL_lex_inpat); |
3280af22 | 533 | SAVEI32(PL_lex_inwhat); |
18b09519 GS |
534 | if (PL_lex_state == LEX_KNOWNEXT) { |
535 | I32 toke = PL_nexttoke; | |
536 | while (--toke >= 0) { | |
537 | SAVEI32(PL_nexttype[toke]); | |
538 | SAVEVPTR(PL_nextval[toke]); | |
539 | } | |
540 | SAVEI32(PL_nexttoke); | |
18b09519 | 541 | } |
57843af0 | 542 | SAVECOPLINE(PL_curcop); |
3280af22 NIS |
543 | SAVEPPTR(PL_bufptr); |
544 | SAVEPPTR(PL_bufend); | |
545 | SAVEPPTR(PL_oldbufptr); | |
546 | SAVEPPTR(PL_oldoldbufptr); | |
207e3d1a JH |
547 | SAVEPPTR(PL_last_lop); |
548 | SAVEPPTR(PL_last_uni); | |
3280af22 NIS |
549 | SAVEPPTR(PL_linestart); |
550 | SAVESPTR(PL_linestr); | |
8edd5f42 RGS |
551 | SAVEGENERICPV(PL_lex_brackstack); |
552 | SAVEGENERICPV(PL_lex_casestack); | |
c76ac1ee | 553 | SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp); |
3280af22 NIS |
554 | SAVESPTR(PL_lex_stuff); |
555 | SAVEI32(PL_lex_defer); | |
09bef843 | 556 | SAVEI32(PL_sublex_info.sub_inwhat); |
3280af22 | 557 | SAVESPTR(PL_lex_repl); |
bebdddfc GS |
558 | SAVEINT(PL_expect); |
559 | SAVEINT(PL_lex_expect); | |
3280af22 NIS |
560 | |
561 | PL_lex_state = LEX_NORMAL; | |
562 | PL_lex_defer = 0; | |
563 | PL_expect = XSTATE; | |
564 | PL_lex_brackets = 0; | |
3280af22 NIS |
565 | New(899, PL_lex_brackstack, 120, char); |
566 | New(899, PL_lex_casestack, 12, char); | |
3280af22 NIS |
567 | PL_lex_casemods = 0; |
568 | *PL_lex_casestack = '\0'; | |
569 | PL_lex_dojoin = 0; | |
570 | PL_lex_starts = 0; | |
571 | PL_lex_stuff = Nullsv; | |
572 | PL_lex_repl = Nullsv; | |
573 | PL_lex_inpat = 0; | |
76be56bc | 574 | PL_nexttoke = 0; |
3280af22 | 575 | PL_lex_inwhat = 0; |
09bef843 | 576 | PL_sublex_info.sub_inwhat = 0; |
3280af22 NIS |
577 | PL_linestr = line; |
578 | if (SvREADONLY(PL_linestr)) | |
579 | PL_linestr = sv_2mortal(newSVsv(PL_linestr)); | |
580 | s = SvPV(PL_linestr, len); | |
6f27f9a7 | 581 | if (!len || s[len-1] != ';') { |
3280af22 NIS |
582 | if (!(SvFLAGS(PL_linestr) & SVs_TEMP)) |
583 | PL_linestr = sv_2mortal(newSVsv(PL_linestr)); | |
584 | sv_catpvn(PL_linestr, "\n;", 2); | |
8990e307 | 585 | } |
3280af22 NIS |
586 | SvTEMP_off(PL_linestr); |
587 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr); | |
588 | PL_bufend = PL_bufptr + SvCUR(PL_linestr); | |
207e3d1a | 589 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 590 | PL_rsfp = 0; |
79072805 | 591 | } |
a687059c | 592 | |
ffb4593c NT |
593 | /* |
594 | * Perl_lex_end | |
9cbb5ea2 GS |
595 | * Finalizer for lexing operations. Must be called when the parser is |
596 | * done with the lexer. | |
ffb4593c NT |
597 | */ |
598 | ||
463ee0b2 | 599 | void |
864dbfa3 | 600 | Perl_lex_end(pTHX) |
463ee0b2 | 601 | { |
3280af22 | 602 | PL_doextract = FALSE; |
463ee0b2 LW |
603 | } |
604 | ||
ffb4593c NT |
605 | /* |
606 | * S_incline | |
607 | * This subroutine has nothing to do with tilting, whether at windmills | |
608 | * or pinball tables. Its name is short for "increment line". It | |
57843af0 | 609 | * increments the current line number in CopLINE(PL_curcop) and checks |
ffb4593c | 610 | * to see whether the line starts with a comment of the form |
9cbb5ea2 GS |
611 | * # line 500 "foo.pm" |
612 | * If so, it sets the current line number and file to the values in the comment. | |
ffb4593c NT |
613 | */ |
614 | ||
76e3520e | 615 | STATIC void |
cea2e8a9 | 616 | S_incline(pTHX_ char *s) |
463ee0b2 LW |
617 | { |
618 | char *t; | |
619 | char *n; | |
73659bf1 | 620 | char *e; |
463ee0b2 | 621 | char ch; |
463ee0b2 | 622 | |
57843af0 | 623 | CopLINE_inc(PL_curcop); |
463ee0b2 LW |
624 | if (*s++ != '#') |
625 | return; | |
bf4acbe4 | 626 | while (SPACE_OR_TAB(*s)) s++; |
73659bf1 GS |
627 | if (strnEQ(s, "line", 4)) |
628 | s += 4; | |
629 | else | |
630 | return; | |
084592ab | 631 | if (SPACE_OR_TAB(*s)) |
73659bf1 | 632 | s++; |
4e553d73 | 633 | else |
73659bf1 | 634 | return; |
bf4acbe4 | 635 | while (SPACE_OR_TAB(*s)) s++; |
463ee0b2 LW |
636 | if (!isDIGIT(*s)) |
637 | return; | |
638 | n = s; | |
639 | while (isDIGIT(*s)) | |
640 | s++; | |
bf4acbe4 | 641 | while (SPACE_OR_TAB(*s)) |
463ee0b2 | 642 | s++; |
73659bf1 | 643 | if (*s == '"' && (t = strchr(s+1, '"'))) { |
463ee0b2 | 644 | s++; |
73659bf1 GS |
645 | e = t + 1; |
646 | } | |
463ee0b2 | 647 | else { |
463ee0b2 | 648 | for (t = s; !isSPACE(*t); t++) ; |
73659bf1 | 649 | e = t; |
463ee0b2 | 650 | } |
bf4acbe4 | 651 | while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f') |
73659bf1 GS |
652 | e++; |
653 | if (*e != '\n' && *e != '\0') | |
654 | return; /* false alarm */ | |
655 | ||
463ee0b2 LW |
656 | ch = *t; |
657 | *t = '\0'; | |
f4dd75d9 | 658 | if (t - s > 0) { |
05ec9bb3 | 659 | CopFILE_free(PL_curcop); |
57843af0 | 660 | CopFILE_set(PL_curcop, s); |
f4dd75d9 | 661 | } |
463ee0b2 | 662 | *t = ch; |
57843af0 | 663 | CopLINE_set(PL_curcop, atoi(n)-1); |
463ee0b2 LW |
664 | } |
665 | ||
ffb4593c NT |
666 | /* |
667 | * S_skipspace | |
668 | * Called to gobble the appropriate amount and type of whitespace. | |
669 | * Skips comments as well. | |
670 | */ | |
671 | ||
76e3520e | 672 | STATIC char * |
cea2e8a9 | 673 | S_skipspace(pTHX_ register char *s) |
a687059c | 674 | { |
3280af22 | 675 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
bf4acbe4 | 676 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
463ee0b2 LW |
677 | s++; |
678 | return s; | |
679 | } | |
680 | for (;;) { | |
fd049845 | 681 | STRLEN prevlen; |
09bef843 | 682 | SSize_t oldprevlen, oldoldprevlen; |
9c5ffd7c | 683 | SSize_t oldloplen = 0, oldunilen = 0; |
60e6418e GS |
684 | while (s < PL_bufend && isSPACE(*s)) { |
685 | if (*s++ == '\n' && PL_in_eval && !PL_rsfp) | |
686 | incline(s); | |
687 | } | |
ffb4593c NT |
688 | |
689 | /* comment */ | |
3280af22 NIS |
690 | if (s < PL_bufend && *s == '#') { |
691 | while (s < PL_bufend && *s != '\n') | |
463ee0b2 | 692 | s++; |
60e6418e | 693 | if (s < PL_bufend) { |
463ee0b2 | 694 | s++; |
60e6418e GS |
695 | if (PL_in_eval && !PL_rsfp) { |
696 | incline(s); | |
697 | continue; | |
698 | } | |
699 | } | |
463ee0b2 | 700 | } |
ffb4593c NT |
701 | |
702 | /* only continue to recharge the buffer if we're at the end | |
703 | * of the buffer, we're not reading from a source filter, and | |
704 | * we're in normal lexing mode | |
705 | */ | |
09bef843 SB |
706 | if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat || |
707 | PL_lex_state == LEX_FORMLINE) | |
463ee0b2 | 708 | return s; |
ffb4593c NT |
709 | |
710 | /* try to recharge the buffer */ | |
9cbb5ea2 GS |
711 | if ((s = filter_gets(PL_linestr, PL_rsfp, |
712 | (prevlen = SvCUR(PL_linestr)))) == Nullch) | |
713 | { | |
714 | /* end of file. Add on the -p or -n magic */ | |
01a19ab0 NC |
715 | if (PL_minus_p) { |
716 | sv_setpv(PL_linestr, | |
717 | ";}continue{print or die qq(-p destination: $!\\n);}"); | |
3280af22 | 718 | PL_minus_n = PL_minus_p = 0; |
a0d0e21e | 719 | } |
01a19ab0 NC |
720 | else if (PL_minus_n) { |
721 | sv_setpvn(PL_linestr, ";}", 2); | |
722 | PL_minus_n = 0; | |
723 | } | |
a0d0e21e | 724 | else |
4147a61b | 725 | sv_setpvn(PL_linestr,";", 1); |
ffb4593c NT |
726 | |
727 | /* reset variables for next time we lex */ | |
9cbb5ea2 GS |
728 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart |
729 | = SvPVX(PL_linestr); | |
3280af22 | 730 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 731 | PL_last_lop = PL_last_uni = Nullch; |
ffb4593c NT |
732 | |
733 | /* Close the filehandle. Could be from -P preprocessor, | |
734 | * STDIN, or a regular file. If we were reading code from | |
735 | * STDIN (because the commandline held no -e or filename) | |
736 | * then we don't close it, we reset it so the code can | |
737 | * read from STDIN too. | |
738 | */ | |
739 | ||
3280af22 NIS |
740 | if (PL_preprocess && !PL_in_eval) |
741 | (void)PerlProc_pclose(PL_rsfp); | |
742 | else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) | |
743 | PerlIO_clearerr(PL_rsfp); | |
8990e307 | 744 | else |
3280af22 NIS |
745 | (void)PerlIO_close(PL_rsfp); |
746 | PL_rsfp = Nullfp; | |
463ee0b2 LW |
747 | return s; |
748 | } | |
ffb4593c NT |
749 | |
750 | /* not at end of file, so we only read another line */ | |
09bef843 SB |
751 | /* make corresponding updates to old pointers, for yyerror() */ |
752 | oldprevlen = PL_oldbufptr - PL_bufend; | |
753 | oldoldprevlen = PL_oldoldbufptr - PL_bufend; | |
754 | if (PL_last_uni) | |
755 | oldunilen = PL_last_uni - PL_bufend; | |
756 | if (PL_last_lop) | |
757 | oldloplen = PL_last_lop - PL_bufend; | |
3280af22 NIS |
758 | PL_linestart = PL_bufptr = s + prevlen; |
759 | PL_bufend = s + SvCUR(PL_linestr); | |
760 | s = PL_bufptr; | |
09bef843 SB |
761 | PL_oldbufptr = s + oldprevlen; |
762 | PL_oldoldbufptr = s + oldoldprevlen; | |
763 | if (PL_last_uni) | |
764 | PL_last_uni = s + oldunilen; | |
765 | if (PL_last_lop) | |
766 | PL_last_lop = s + oldloplen; | |
a0d0e21e | 767 | incline(s); |
ffb4593c NT |
768 | |
769 | /* debugger active and we're not compiling the debugger code, | |
770 | * so store the line into the debugger's array of lines | |
771 | */ | |
3280af22 | 772 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
8990e307 LW |
773 | SV *sv = NEWSV(85,0); |
774 | ||
775 | sv_upgrade(sv, SVt_PVMG); | |
3280af22 | 776 | sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr); |
0ac0412a MJD |
777 | (void)SvIOK_on(sv); |
778 | SvIVX(sv) = 0; | |
57843af0 | 779 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
8990e307 | 780 | } |
463ee0b2 | 781 | } |
a687059c | 782 | } |
378cc40b | 783 | |
ffb4593c NT |
784 | /* |
785 | * S_check_uni | |
786 | * Check the unary operators to ensure there's no ambiguity in how they're | |
787 | * used. An ambiguous piece of code would be: | |
788 | * rand + 5 | |
789 | * This doesn't mean rand() + 5. Because rand() is a unary operator, | |
790 | * the +5 is its argument. | |
791 | */ | |
792 | ||
76e3520e | 793 | STATIC void |
cea2e8a9 | 794 | S_check_uni(pTHX) |
ba106d47 | 795 | { |
2f3197b3 | 796 | char *s; |
a0d0e21e | 797 | char *t; |
2f3197b3 | 798 | |
3280af22 | 799 | if (PL_oldoldbufptr != PL_last_uni) |
2f3197b3 | 800 | return; |
3280af22 NIS |
801 | while (isSPACE(*PL_last_uni)) |
802 | PL_last_uni++; | |
7e2040f0 | 803 | for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ; |
3280af22 | 804 | if ((t = strchr(s, '(')) && t < PL_bufptr) |
a0d0e21e | 805 | return; |
0453d815 | 806 | if (ckWARN_d(WARN_AMBIGUOUS)){ |
f248d071 | 807 | char ch = *s; |
0453d815 | 808 | *s = '\0'; |
9014280d | 809 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
2d5ccbba | 810 | "Warning: Use of \"%s\" without parentheses is ambiguous", |
0453d815 PM |
811 | PL_last_uni); |
812 | *s = ch; | |
813 | } | |
2f3197b3 LW |
814 | } |
815 | ||
ffb4593c NT |
816 | /* |
817 | * LOP : macro to build a list operator. Its behaviour has been replaced | |
818 | * with a subroutine, S_lop() for which LOP is just another name. | |
819 | */ | |
820 | ||
a0d0e21e LW |
821 | #define LOP(f,x) return lop(f,x,s) |
822 | ||
ffb4593c NT |
823 | /* |
824 | * S_lop | |
825 | * Build a list operator (or something that might be one). The rules: | |
826 | * - if we have a next token, then it's a list operator [why?] | |
827 | * - if the next thing is an opening paren, then it's a function | |
828 | * - else it's a list operator | |
829 | */ | |
830 | ||
76e3520e | 831 | STATIC I32 |
a0be28da | 832 | S_lop(pTHX_ I32 f, int x, char *s) |
ffed7fef | 833 | { |
79072805 | 834 | yylval.ival = f; |
35c8bce7 | 835 | CLINE; |
3280af22 NIS |
836 | PL_expect = x; |
837 | PL_bufptr = s; | |
838 | PL_last_lop = PL_oldbufptr; | |
eb160463 | 839 | PL_last_lop_op = (OPCODE)f; |
3280af22 | 840 | if (PL_nexttoke) |
bbf60fe6 | 841 | return REPORT(LSTOP); |
79072805 | 842 | if (*s == '(') |
bbf60fe6 | 843 | return REPORT(FUNC); |
79072805 LW |
844 | s = skipspace(s); |
845 | if (*s == '(') | |
bbf60fe6 | 846 | return REPORT(FUNC); |
79072805 | 847 | else |
bbf60fe6 | 848 | return REPORT(LSTOP); |
79072805 LW |
849 | } |
850 | ||
ffb4593c NT |
851 | /* |
852 | * S_force_next | |
9cbb5ea2 | 853 | * When the lexer realizes it knows the next token (for instance, |
ffb4593c | 854 | * it is reordering tokens for the parser) then it can call S_force_next |
9cbb5ea2 GS |
855 | * to know what token to return the next time the lexer is called. Caller |
856 | * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer | |
857 | * handles the token correctly. | |
ffb4593c NT |
858 | */ |
859 | ||
4e553d73 | 860 | STATIC void |
cea2e8a9 | 861 | S_force_next(pTHX_ I32 type) |
79072805 | 862 | { |
3280af22 NIS |
863 | PL_nexttype[PL_nexttoke] = type; |
864 | PL_nexttoke++; | |
865 | if (PL_lex_state != LEX_KNOWNEXT) { | |
866 | PL_lex_defer = PL_lex_state; | |
867 | PL_lex_expect = PL_expect; | |
868 | PL_lex_state = LEX_KNOWNEXT; | |
79072805 LW |
869 | } |
870 | } | |
871 | ||
d0a148a6 NC |
872 | STATIC SV * |
873 | S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len) | |
874 | { | |
875 | SV *sv = newSVpvn(start,len); | |
bfed75c6 | 876 | if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len)) |
d0a148a6 NC |
877 | SvUTF8_on(sv); |
878 | return sv; | |
879 | } | |
880 | ||
ffb4593c NT |
881 | /* |
882 | * S_force_word | |
883 | * When the lexer knows the next thing is a word (for instance, it has | |
884 | * just seen -> and it knows that the next char is a word char, then | |
885 | * it calls S_force_word to stick the next word into the PL_next lookahead. | |
886 | * | |
887 | * Arguments: | |
b1b65b59 | 888 | * char *start : buffer position (must be within PL_linestr) |
ffb4593c NT |
889 | * int token : PL_next will be this type of bare word (e.g., METHOD,WORD) |
890 | * int check_keyword : if true, Perl checks to make sure the word isn't | |
891 | * a keyword (do this if the word is a label, e.g. goto FOO) | |
892 | * int allow_pack : if true, : characters will also be allowed (require, | |
893 | * use, etc. do this) | |
9cbb5ea2 | 894 | * int allow_initial_tick : used by the "sub" lexer only. |
ffb4593c NT |
895 | */ |
896 | ||
76e3520e | 897 | STATIC char * |
cea2e8a9 | 898 | S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick) |
79072805 | 899 | { |
463ee0b2 LW |
900 | register char *s; |
901 | STRLEN len; | |
4e553d73 | 902 | |
463ee0b2 LW |
903 | start = skipspace(start); |
904 | s = start; | |
7e2040f0 | 905 | if (isIDFIRST_lazy_if(s,UTF) || |
a0d0e21e | 906 | (allow_pack && *s == ':') || |
15f0808c | 907 | (allow_initial_tick && *s == '\'') ) |
a0d0e21e | 908 | { |
3280af22 NIS |
909 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len); |
910 | if (check_keyword && keyword(PL_tokenbuf, len)) | |
463ee0b2 LW |
911 | return start; |
912 | if (token == METHOD) { | |
913 | s = skipspace(s); | |
914 | if (*s == '(') | |
3280af22 | 915 | PL_expect = XTERM; |
463ee0b2 | 916 | else { |
3280af22 | 917 | PL_expect = XOPERATOR; |
463ee0b2 | 918 | } |
79072805 | 919 | } |
d0a148a6 NC |
920 | PL_nextval[PL_nexttoke].opval |
921 | = (OP*)newSVOP(OP_CONST,0, | |
922 | S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len)); | |
3280af22 | 923 | PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE; |
79072805 LW |
924 | force_next(token); |
925 | } | |
926 | return s; | |
927 | } | |
928 | ||
ffb4593c NT |
929 | /* |
930 | * S_force_ident | |
9cbb5ea2 | 931 | * Called when the lexer wants $foo *foo &foo etc, but the program |
ffb4593c NT |
932 | * text only contains the "foo" portion. The first argument is a pointer |
933 | * to the "foo", and the second argument is the type symbol to prefix. | |
934 | * Forces the next token to be a "WORD". | |
9cbb5ea2 | 935 | * Creates the symbol if it didn't already exist (via gv_fetchpv()). |
ffb4593c NT |
936 | */ |
937 | ||
76e3520e | 938 | STATIC void |
bfed75c6 | 939 | S_force_ident(pTHX_ register const char *s, int kind) |
79072805 LW |
940 | { |
941 | if (s && *s) { | |
bfed75c6 | 942 | OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0)); |
3280af22 | 943 | PL_nextval[PL_nexttoke].opval = o; |
79072805 | 944 | force_next(WORD); |
748a9306 | 945 | if (kind) { |
11343788 | 946 | o->op_private = OPpCONST_ENTERED; |
55497cff | 947 | /* XXX see note in pp_entereval() for why we forgo typo |
948 | warnings if the symbol must be introduced in an eval. | |
949 | GSAR 96-10-12 */ | |
3280af22 | 950 | gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE, |
a0d0e21e LW |
951 | kind == '$' ? SVt_PV : |
952 | kind == '@' ? SVt_PVAV : | |
953 | kind == '%' ? SVt_PVHV : | |
954 | SVt_PVGV | |
955 | ); | |
748a9306 | 956 | } |
79072805 LW |
957 | } |
958 | } | |
959 | ||
1571675a GS |
960 | NV |
961 | Perl_str_to_version(pTHX_ SV *sv) | |
962 | { | |
963 | NV retval = 0.0; | |
964 | NV nshift = 1.0; | |
965 | STRLEN len; | |
966 | char *start = SvPVx(sv,len); | |
3aa33fe5 | 967 | bool utf = SvUTF8(sv) ? TRUE : FALSE; |
1571675a GS |
968 | char *end = start + len; |
969 | while (start < end) { | |
ba210ebe | 970 | STRLEN skip; |
1571675a GS |
971 | UV n; |
972 | if (utf) | |
9041c2e3 | 973 | n = utf8n_to_uvchr((U8*)start, len, &skip, 0); |
1571675a GS |
974 | else { |
975 | n = *(U8*)start; | |
976 | skip = 1; | |
977 | } | |
978 | retval += ((NV)n)/nshift; | |
979 | start += skip; | |
980 | nshift *= 1000; | |
981 | } | |
982 | return retval; | |
983 | } | |
984 | ||
4e553d73 | 985 | /* |
ffb4593c NT |
986 | * S_force_version |
987 | * Forces the next token to be a version number. | |
e759cc13 RGS |
988 | * If the next token appears to be an invalid version number, (e.g. "v2b"), |
989 | * and if "guessing" is TRUE, then no new token is created (and the caller | |
990 | * must use an alternative parsing method). | |
ffb4593c NT |
991 | */ |
992 | ||
76e3520e | 993 | STATIC char * |
e759cc13 | 994 | S_force_version(pTHX_ char *s, int guessing) |
89bfa8cd | 995 | { |
996 | OP *version = Nullop; | |
44dcb63b | 997 | char *d; |
89bfa8cd | 998 | |
999 | s = skipspace(s); | |
1000 | ||
44dcb63b | 1001 | d = s; |
dd629d5b | 1002 | if (*d == 'v') |
44dcb63b | 1003 | d++; |
44dcb63b | 1004 | if (isDIGIT(*d)) { |
e759cc13 RGS |
1005 | while (isDIGIT(*d) || *d == '_' || *d == '.') |
1006 | d++; | |
9f3d182e | 1007 | if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) { |
dd629d5b | 1008 | SV *ver; |
b73d6f50 | 1009 | s = scan_num(s, &yylval); |
89bfa8cd | 1010 | version = yylval.opval; |
dd629d5b GS |
1011 | ver = cSVOPx(version)->op_sv; |
1012 | if (SvPOK(ver) && !SvNIOK(ver)) { | |
155aba94 | 1013 | (void)SvUPGRADE(ver, SVt_PVNV); |
1571675a GS |
1014 | SvNVX(ver) = str_to_version(ver); |
1015 | SvNOK_on(ver); /* hint that it is a version */ | |
44dcb63b | 1016 | } |
89bfa8cd | 1017 | } |
e759cc13 RGS |
1018 | else if (guessing) |
1019 | return s; | |
89bfa8cd | 1020 | } |
1021 | ||
1022 | /* NOTE: The parser sees the package name and the VERSION swapped */ | |
3280af22 | 1023 | PL_nextval[PL_nexttoke].opval = version; |
4e553d73 | 1024 | force_next(WORD); |
89bfa8cd | 1025 | |
e759cc13 | 1026 | return s; |
89bfa8cd | 1027 | } |
1028 | ||
ffb4593c NT |
1029 | /* |
1030 | * S_tokeq | |
1031 | * Tokenize a quoted string passed in as an SV. It finds the next | |
1032 | * chunk, up to end of string or a backslash. It may make a new | |
1033 | * SV containing that chunk (if HINT_NEW_STRING is on). It also | |
1034 | * turns \\ into \. | |
1035 | */ | |
1036 | ||
76e3520e | 1037 | STATIC SV * |
cea2e8a9 | 1038 | S_tokeq(pTHX_ SV *sv) |
79072805 LW |
1039 | { |
1040 | register char *s; | |
1041 | register char *send; | |
1042 | register char *d; | |
b3ac6de7 IZ |
1043 | STRLEN len = 0; |
1044 | SV *pv = sv; | |
79072805 LW |
1045 | |
1046 | if (!SvLEN(sv)) | |
b3ac6de7 | 1047 | goto finish; |
79072805 | 1048 | |
a0d0e21e | 1049 | s = SvPV_force(sv, len); |
21a311ee | 1050 | if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1) |
b3ac6de7 | 1051 | goto finish; |
463ee0b2 | 1052 | send = s + len; |
79072805 LW |
1053 | while (s < send && *s != '\\') |
1054 | s++; | |
1055 | if (s == send) | |
b3ac6de7 | 1056 | goto finish; |
79072805 | 1057 | d = s; |
be4731d2 | 1058 | if ( PL_hints & HINT_NEW_STRING ) { |
79cb57f6 | 1059 | pv = sv_2mortal(newSVpvn(SvPVX(pv), len)); |
be4731d2 NIS |
1060 | if (SvUTF8(sv)) |
1061 | SvUTF8_on(pv); | |
1062 | } | |
79072805 LW |
1063 | while (s < send) { |
1064 | if (*s == '\\') { | |
a0d0e21e | 1065 | if (s + 1 < send && (s[1] == '\\')) |
79072805 LW |
1066 | s++; /* all that, just for this */ |
1067 | } | |
1068 | *d++ = *s++; | |
1069 | } | |
1070 | *d = '\0'; | |
463ee0b2 | 1071 | SvCUR_set(sv, d - SvPVX(sv)); |
b3ac6de7 | 1072 | finish: |
3280af22 | 1073 | if ( PL_hints & HINT_NEW_STRING ) |
b3ac6de7 | 1074 | return new_constant(NULL, 0, "q", sv, pv, "q"); |
79072805 LW |
1075 | return sv; |
1076 | } | |
1077 | ||
ffb4593c NT |
1078 | /* |
1079 | * Now come three functions related to double-quote context, | |
1080 | * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when | |
1081 | * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They | |
1082 | * interact with PL_lex_state, and create fake ( ... ) argument lists | |
1083 | * to handle functions and concatenation. | |
1084 | * They assume that whoever calls them will be setting up a fake | |
1085 | * join call, because each subthing puts a ',' after it. This lets | |
1086 | * "lower \luPpEr" | |
1087 | * become | |
1088 | * join($, , 'lower ', lcfirst( 'uPpEr', ) ,) | |
1089 | * | |
1090 | * (I'm not sure whether the spurious commas at the end of lcfirst's | |
1091 | * arguments and join's arguments are created or not). | |
1092 | */ | |
1093 | ||
1094 | /* | |
1095 | * S_sublex_start | |
1096 | * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST). | |
1097 | * | |
1098 | * Pattern matching will set PL_lex_op to the pattern-matching op to | |
1099 | * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise). | |
1100 | * | |
1101 | * OP_CONST and OP_READLINE are easy--just make the new op and return. | |
1102 | * | |
1103 | * Everything else becomes a FUNC. | |
1104 | * | |
1105 | * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we | |
1106 | * had an OP_CONST or OP_READLINE). This just sets us up for a | |
1107 | * call to S_sublex_push(). | |
1108 | */ | |
1109 | ||
76e3520e | 1110 | STATIC I32 |
cea2e8a9 | 1111 | S_sublex_start(pTHX) |
79072805 LW |
1112 | { |
1113 | register I32 op_type = yylval.ival; | |
79072805 LW |
1114 | |
1115 | if (op_type == OP_NULL) { | |
3280af22 NIS |
1116 | yylval.opval = PL_lex_op; |
1117 | PL_lex_op = Nullop; | |
79072805 LW |
1118 | return THING; |
1119 | } | |
1120 | if (op_type == OP_CONST || op_type == OP_READLINE) { | |
3280af22 | 1121 | SV *sv = tokeq(PL_lex_stuff); |
b3ac6de7 IZ |
1122 | |
1123 | if (SvTYPE(sv) == SVt_PVIV) { | |
1124 | /* Overloaded constants, nothing fancy: Convert to SVt_PV: */ | |
1125 | STRLEN len; | |
1126 | char *p; | |
1127 | SV *nsv; | |
1128 | ||
1129 | p = SvPV(sv, len); | |
79cb57f6 | 1130 | nsv = newSVpvn(p, len); |
01ec43d0 GS |
1131 | if (SvUTF8(sv)) |
1132 | SvUTF8_on(nsv); | |
b3ac6de7 IZ |
1133 | SvREFCNT_dec(sv); |
1134 | sv = nsv; | |
4e553d73 | 1135 | } |
b3ac6de7 | 1136 | yylval.opval = (OP*)newSVOP(op_type, 0, sv); |
3280af22 | 1137 | PL_lex_stuff = Nullsv; |
6f33ba73 RGS |
1138 | /* Allow <FH> // "foo" */ |
1139 | if (op_type == OP_READLINE) | |
1140 | PL_expect = XTERMORDORDOR; | |
79072805 LW |
1141 | return THING; |
1142 | } | |
1143 | ||
3280af22 NIS |
1144 | PL_sublex_info.super_state = PL_lex_state; |
1145 | PL_sublex_info.sub_inwhat = op_type; | |
1146 | PL_sublex_info.sub_op = PL_lex_op; | |
1147 | PL_lex_state = LEX_INTERPPUSH; | |
55497cff | 1148 | |
3280af22 NIS |
1149 | PL_expect = XTERM; |
1150 | if (PL_lex_op) { | |
1151 | yylval.opval = PL_lex_op; | |
1152 | PL_lex_op = Nullop; | |
55497cff | 1153 | return PMFUNC; |
1154 | } | |
1155 | else | |
1156 | return FUNC; | |
1157 | } | |
1158 | ||
ffb4593c NT |
1159 | /* |
1160 | * S_sublex_push | |
1161 | * Create a new scope to save the lexing state. The scope will be | |
1162 | * ended in S_sublex_done. Returns a '(', starting the function arguments | |
1163 | * to the uc, lc, etc. found before. | |
1164 | * Sets PL_lex_state to LEX_INTERPCONCAT. | |
1165 | */ | |
1166 | ||
76e3520e | 1167 | STATIC I32 |
cea2e8a9 | 1168 | S_sublex_push(pTHX) |
55497cff | 1169 | { |
f46d017c | 1170 | ENTER; |
55497cff | 1171 | |
3280af22 NIS |
1172 | PL_lex_state = PL_sublex_info.super_state; |
1173 | SAVEI32(PL_lex_dojoin); | |
1174 | SAVEI32(PL_lex_brackets); | |
3280af22 NIS |
1175 | SAVEI32(PL_lex_casemods); |
1176 | SAVEI32(PL_lex_starts); | |
1177 | SAVEI32(PL_lex_state); | |
7766f137 | 1178 | SAVEVPTR(PL_lex_inpat); |
3280af22 | 1179 | SAVEI32(PL_lex_inwhat); |
57843af0 | 1180 | SAVECOPLINE(PL_curcop); |
3280af22 | 1181 | SAVEPPTR(PL_bufptr); |
8452ff4b | 1182 | SAVEPPTR(PL_bufend); |
3280af22 NIS |
1183 | SAVEPPTR(PL_oldbufptr); |
1184 | SAVEPPTR(PL_oldoldbufptr); | |
207e3d1a JH |
1185 | SAVEPPTR(PL_last_lop); |
1186 | SAVEPPTR(PL_last_uni); | |
3280af22 NIS |
1187 | SAVEPPTR(PL_linestart); |
1188 | SAVESPTR(PL_linestr); | |
8edd5f42 RGS |
1189 | SAVEGENERICPV(PL_lex_brackstack); |
1190 | SAVEGENERICPV(PL_lex_casestack); | |
3280af22 NIS |
1191 | |
1192 | PL_linestr = PL_lex_stuff; | |
1193 | PL_lex_stuff = Nullsv; | |
1194 | ||
9cbb5ea2 GS |
1195 | PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart |
1196 | = SvPVX(PL_linestr); | |
3280af22 | 1197 | PL_bufend += SvCUR(PL_linestr); |
207e3d1a | 1198 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 NIS |
1199 | SAVEFREESV(PL_linestr); |
1200 | ||
1201 | PL_lex_dojoin = FALSE; | |
1202 | PL_lex_brackets = 0; | |
3280af22 NIS |
1203 | New(899, PL_lex_brackstack, 120, char); |
1204 | New(899, PL_lex_casestack, 12, char); | |
3280af22 NIS |
1205 | PL_lex_casemods = 0; |
1206 | *PL_lex_casestack = '\0'; | |
1207 | PL_lex_starts = 0; | |
1208 | PL_lex_state = LEX_INTERPCONCAT; | |
eb160463 | 1209 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
3280af22 NIS |
1210 | |
1211 | PL_lex_inwhat = PL_sublex_info.sub_inwhat; | |
1212 | if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST) | |
1213 | PL_lex_inpat = PL_sublex_info.sub_op; | |
79072805 | 1214 | else |
3280af22 | 1215 | PL_lex_inpat = Nullop; |
79072805 | 1216 | |
55497cff | 1217 | return '('; |
79072805 LW |
1218 | } |
1219 | ||
ffb4593c NT |
1220 | /* |
1221 | * S_sublex_done | |
1222 | * Restores lexer state after a S_sublex_push. | |
1223 | */ | |
1224 | ||
76e3520e | 1225 | STATIC I32 |
cea2e8a9 | 1226 | S_sublex_done(pTHX) |
79072805 | 1227 | { |
3280af22 | 1228 | if (!PL_lex_starts++) { |
9aa983d2 JH |
1229 | SV *sv = newSVpvn("",0); |
1230 | if (SvUTF8(PL_linestr)) | |
1231 | SvUTF8_on(sv); | |
3280af22 | 1232 | PL_expect = XOPERATOR; |
9aa983d2 | 1233 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
79072805 LW |
1234 | return THING; |
1235 | } | |
1236 | ||
3280af22 NIS |
1237 | if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */ |
1238 | PL_lex_state = LEX_INTERPCASEMOD; | |
cea2e8a9 | 1239 | return yylex(); |
79072805 LW |
1240 | } |
1241 | ||
ffb4593c | 1242 | /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */ |
3280af22 NIS |
1243 | if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) { |
1244 | PL_linestr = PL_lex_repl; | |
1245 | PL_lex_inpat = 0; | |
1246 | PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr); | |
1247 | PL_bufend += SvCUR(PL_linestr); | |
207e3d1a | 1248 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 NIS |
1249 | SAVEFREESV(PL_linestr); |
1250 | PL_lex_dojoin = FALSE; | |
1251 | PL_lex_brackets = 0; | |
3280af22 NIS |
1252 | PL_lex_casemods = 0; |
1253 | *PL_lex_casestack = '\0'; | |
1254 | PL_lex_starts = 0; | |
25da4f38 | 1255 | if (SvEVALED(PL_lex_repl)) { |
3280af22 NIS |
1256 | PL_lex_state = LEX_INTERPNORMAL; |
1257 | PL_lex_starts++; | |
e9fa98b2 HS |
1258 | /* we don't clear PL_lex_repl here, so that we can check later |
1259 | whether this is an evalled subst; that means we rely on the | |
1260 | logic to ensure sublex_done() is called again only via the | |
1261 | branch (in yylex()) that clears PL_lex_repl, else we'll loop */ | |
79072805 | 1262 | } |
e9fa98b2 | 1263 | else { |
3280af22 | 1264 | PL_lex_state = LEX_INTERPCONCAT; |
e9fa98b2 HS |
1265 | PL_lex_repl = Nullsv; |
1266 | } | |
79072805 | 1267 | return ','; |
ffed7fef LW |
1268 | } |
1269 | else { | |
f46d017c | 1270 | LEAVE; |
3280af22 NIS |
1271 | PL_bufend = SvPVX(PL_linestr); |
1272 | PL_bufend += SvCUR(PL_linestr); | |
1273 | PL_expect = XOPERATOR; | |
09bef843 | 1274 | PL_sublex_info.sub_inwhat = 0; |
79072805 | 1275 | return ')'; |
ffed7fef LW |
1276 | } |
1277 | } | |
1278 | ||
02aa26ce NT |
1279 | /* |
1280 | scan_const | |
1281 | ||
1282 | Extracts a pattern, double-quoted string, or transliteration. This | |
1283 | is terrifying code. | |
1284 | ||
3280af22 NIS |
1285 | It looks at lex_inwhat and PL_lex_inpat to find out whether it's |
1286 | processing a pattern (PL_lex_inpat is true), a transliteration | |
02aa26ce NT |
1287 | (lex_inwhat & OP_TRANS is true), or a double-quoted string. |
1288 | ||
9b599b2a GS |
1289 | Returns a pointer to the character scanned up to. Iff this is |
1290 | advanced from the start pointer supplied (ie if anything was | |
1291 | successfully parsed), will leave an OP for the substring scanned | |
1292 | in yylval. Caller must intuit reason for not parsing further | |
1293 | by looking at the next characters herself. | |
1294 | ||
02aa26ce NT |
1295 | In patterns: |
1296 | backslashes: | |
1297 | double-quoted style: \r and \n | |
1298 | regexp special ones: \D \s | |
1299 | constants: \x3 | |
1300 | backrefs: \1 (deprecated in substitution replacements) | |
1301 | case and quoting: \U \Q \E | |
1302 | stops on @ and $, but not for $ as tail anchor | |
1303 | ||
1304 | In transliterations: | |
1305 | characters are VERY literal, except for - not at the start or end | |
1306 | of the string, which indicates a range. scan_const expands the | |
1307 | range to the full set of intermediate characters. | |
1308 | ||
1309 | In double-quoted strings: | |
1310 | backslashes: | |
1311 | double-quoted style: \r and \n | |
1312 | constants: \x3 | |
1313 | backrefs: \1 (deprecated) | |
1314 | case and quoting: \U \Q \E | |
1315 | stops on @ and $ | |
1316 | ||
1317 | scan_const does *not* construct ops to handle interpolated strings. | |
1318 | It stops processing as soon as it finds an embedded $ or @ variable | |
1319 | and leaves it to the caller to work out what's going on. | |
1320 | ||
da6eedaa | 1321 | @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo. |
02aa26ce NT |
1322 | |
1323 | $ in pattern could be $foo or could be tail anchor. Assumption: | |
1324 | it's a tail anchor if $ is the last thing in the string, or if it's | |
1325 | followed by one of ")| \n\t" | |
1326 | ||
1327 | \1 (backreferences) are turned into $1 | |
1328 | ||
1329 | The structure of the code is | |
1330 | while (there's a character to process) { | |
1331 | handle transliteration ranges | |
1332 | skip regexp comments | |
1333 | skip # initiated comments in //x patterns | |
1334 | check for embedded @foo | |
1335 | check for embedded scalars | |
1336 | if (backslash) { | |
1337 | leave intact backslashes from leave (below) | |
1338 | deprecate \1 in strings and sub replacements | |
1339 | handle string-changing backslashes \l \U \Q \E, etc. | |
1340 | switch (what was escaped) { | |
1341 | handle - in a transliteration (becomes a literal -) | |
1342 | handle \132 octal characters | |
1343 | handle 0x15 hex characters | |
1344 | handle \cV (control V) | |
1345 | handle printf backslashes (\f, \r, \n, etc) | |
1346 | } (end switch) | |
1347 | } (end if backslash) | |
1348 | } (end while character to read) | |
4e553d73 | 1349 | |
02aa26ce NT |
1350 | */ |
1351 | ||
76e3520e | 1352 | STATIC char * |
cea2e8a9 | 1353 | S_scan_const(pTHX_ char *start) |
79072805 | 1354 | { |
3280af22 | 1355 | register char *send = PL_bufend; /* end of the constant */ |
02aa26ce NT |
1356 | SV *sv = NEWSV(93, send - start); /* sv for the constant */ |
1357 | register char *s = start; /* start of the constant */ | |
1358 | register char *d = SvPVX(sv); /* destination for copies */ | |
1359 | bool dorange = FALSE; /* are we in a translit range? */ | |
c2e66d9e | 1360 | bool didrange = FALSE; /* did we just finish a range? */ |
2b9d42f0 NIS |
1361 | I32 has_utf8 = FALSE; /* Output constant is UTF8 */ |
1362 | I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */ | |
012bcf8d GS |
1363 | UV uv; |
1364 | ||
dff6d3cd | 1365 | const char *leaveit = /* set of acceptably-backslashed characters */ |
3280af22 | 1366 | PL_lex_inpat |
b6d5fef8 | 1367 | ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#" |
9b599b2a | 1368 | : ""; |
79072805 | 1369 | |
2b9d42f0 NIS |
1370 | if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) { |
1371 | /* If we are doing a trans and we know we want UTF8 set expectation */ | |
1372 | has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF); | |
1373 | this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); | |
1374 | } | |
1375 | ||
1376 | ||
79072805 | 1377 | while (s < send || dorange) { |
02aa26ce | 1378 | /* get transliterations out of the way (they're most literal) */ |
3280af22 | 1379 | if (PL_lex_inwhat == OP_TRANS) { |
02aa26ce | 1380 | /* expand a range A-Z to the full set of characters. AIE! */ |
79072805 | 1381 | if (dorange) { |
1ba5c669 JH |
1382 | I32 i; /* current expanded character */ |
1383 | I32 min; /* first character in range */ | |
1384 | I32 max; /* last character in range */ | |
02aa26ce | 1385 | |
2b9d42f0 | 1386 | if (has_utf8) { |
8973db79 JH |
1387 | char *c = (char*)utf8_hop((U8*)d, -1); |
1388 | char *e = d++; | |
1389 | while (e-- > c) | |
1390 | *(e + 1) = *e; | |
25716404 | 1391 | *c = (char)UTF_TO_NATIVE(0xff); |
8973db79 JH |
1392 | /* mark the range as done, and continue */ |
1393 | dorange = FALSE; | |
1394 | didrange = TRUE; | |
1395 | continue; | |
1396 | } | |
2b9d42f0 | 1397 | |
02aa26ce | 1398 | i = d - SvPVX(sv); /* remember current offset */ |
9cbb5ea2 GS |
1399 | SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */ |
1400 | d = SvPVX(sv) + i; /* refresh d after realloc */ | |
02aa26ce NT |
1401 | d -= 2; /* eat the first char and the - */ |
1402 | ||
8ada0baa JH |
1403 | min = (U8)*d; /* first char in range */ |
1404 | max = (U8)d[1]; /* last char in range */ | |
1405 | ||
c2e66d9e | 1406 | if (min > max) { |
01ec43d0 | 1407 | Perl_croak(aTHX_ |
d1573ac7 | 1408 | "Invalid range \"%c-%c\" in transliteration operator", |
1ba5c669 | 1409 | (char)min, (char)max); |
c2e66d9e GS |
1410 | } |
1411 | ||
c7f1f016 | 1412 | #ifdef EBCDIC |
8ada0baa JH |
1413 | if ((isLOWER(min) && isLOWER(max)) || |
1414 | (isUPPER(min) && isUPPER(max))) { | |
1415 | if (isLOWER(min)) { | |
1416 | for (i = min; i <= max; i++) | |
1417 | if (isLOWER(i)) | |
db42d148 | 1418 | *d++ = NATIVE_TO_NEED(has_utf8,i); |
8ada0baa JH |
1419 | } else { |
1420 | for (i = min; i <= max; i++) | |
1421 | if (isUPPER(i)) | |
db42d148 | 1422 | *d++ = NATIVE_TO_NEED(has_utf8,i); |
8ada0baa JH |
1423 | } |
1424 | } | |
1425 | else | |
1426 | #endif | |
1427 | for (i = min; i <= max; i++) | |
eb160463 | 1428 | *d++ = (char)i; |
02aa26ce NT |
1429 | |
1430 | /* mark the range as done, and continue */ | |
79072805 | 1431 | dorange = FALSE; |
01ec43d0 | 1432 | didrange = TRUE; |
79072805 | 1433 | continue; |
4e553d73 | 1434 | } |
02aa26ce NT |
1435 | |
1436 | /* range begins (ignore - as first or last char) */ | |
79072805 | 1437 | else if (*s == '-' && s+1 < send && s != start) { |
4e553d73 | 1438 | if (didrange) { |
1fafa243 | 1439 | Perl_croak(aTHX_ "Ambiguous range in transliteration operator"); |
01ec43d0 | 1440 | } |
2b9d42f0 | 1441 | if (has_utf8) { |
25716404 | 1442 | *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */ |
a0ed51b3 LW |
1443 | s++; |
1444 | continue; | |
1445 | } | |
79072805 LW |
1446 | dorange = TRUE; |
1447 | s++; | |
01ec43d0 GS |
1448 | } |
1449 | else { | |
1450 | didrange = FALSE; | |
1451 | } | |
79072805 | 1452 | } |
02aa26ce NT |
1453 | |
1454 | /* if we get here, we're not doing a transliteration */ | |
1455 | ||
0f5d15d6 IZ |
1456 | /* skip for regexp comments /(?#comment)/ and code /(?{code})/, |
1457 | except for the last char, which will be done separately. */ | |
3280af22 | 1458 | else if (*s == '(' && PL_lex_inpat && s[1] == '?') { |
cc6b7395 | 1459 | if (s[2] == '#') { |
e994fd66 | 1460 | while (s+1 < send && *s != ')') |
db42d148 | 1461 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
155aba94 GS |
1462 | } |
1463 | else if (s[2] == '{' /* This should match regcomp.c */ | |
1464 | || ((s[2] == 'p' || s[2] == '?') && s[3] == '{')) | |
1465 | { | |
cc6b7395 | 1466 | I32 count = 1; |
0f5d15d6 | 1467 | char *regparse = s + (s[2] == '{' ? 3 : 4); |
cc6b7395 IZ |
1468 | char c; |
1469 | ||
d9f97599 GS |
1470 | while (count && (c = *regparse)) { |
1471 | if (c == '\\' && regparse[1]) | |
1472 | regparse++; | |
4e553d73 | 1473 | else if (c == '{') |
cc6b7395 | 1474 | count++; |
4e553d73 | 1475 | else if (c == '}') |
cc6b7395 | 1476 | count--; |
d9f97599 | 1477 | regparse++; |
cc6b7395 | 1478 | } |
e994fd66 | 1479 | if (*regparse != ')') |
5bdf89e7 | 1480 | regparse--; /* Leave one char for continuation. */ |
0f5d15d6 | 1481 | while (s < regparse) |
db42d148 | 1482 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
cc6b7395 | 1483 | } |
748a9306 | 1484 | } |
02aa26ce NT |
1485 | |
1486 | /* likewise skip #-initiated comments in //x patterns */ | |
3280af22 NIS |
1487 | else if (*s == '#' && PL_lex_inpat && |
1488 | ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) { | |
748a9306 | 1489 | while (s+1 < send && *s != '\n') |
db42d148 | 1490 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
748a9306 | 1491 | } |
02aa26ce | 1492 | |
5d1d4326 | 1493 | /* check for embedded arrays |
da6eedaa | 1494 | (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-) |
5d1d4326 | 1495 | */ |
7e2040f0 | 1496 | else if (*s == '@' && s[1] |
5d1d4326 | 1497 | && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1]))) |
79072805 | 1498 | break; |
02aa26ce NT |
1499 | |
1500 | /* check for embedded scalars. only stop if we're sure it's a | |
1501 | variable. | |
1502 | */ | |
79072805 | 1503 | else if (*s == '$') { |
3280af22 | 1504 | if (!PL_lex_inpat) /* not a regexp, so $ must be var */ |
79072805 | 1505 | break; |
6002328a | 1506 | if (s + 1 < send && !strchr("()| \r\n\t", s[1])) |
79072805 LW |
1507 | break; /* in regexp, $ might be tail anchor */ |
1508 | } | |
02aa26ce | 1509 | |
2b9d42f0 NIS |
1510 | /* End of else if chain - OP_TRANS rejoin rest */ |
1511 | ||
02aa26ce | 1512 | /* backslashes */ |
79072805 LW |
1513 | if (*s == '\\' && s+1 < send) { |
1514 | s++; | |
02aa26ce NT |
1515 | |
1516 | /* some backslashes we leave behind */ | |
c9f97d15 | 1517 | if (*leaveit && *s && strchr(leaveit, *s)) { |
db42d148 NIS |
1518 | *d++ = NATIVE_TO_NEED(has_utf8,'\\'); |
1519 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); | |
79072805 LW |
1520 | continue; |
1521 | } | |
02aa26ce NT |
1522 | |
1523 | /* deprecate \1 in strings and substitution replacements */ | |
3280af22 | 1524 | if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat && |
a0d0e21e | 1525 | isDIGIT(*s) && *s != '0' && !isDIGIT(s[1])) |
79072805 | 1526 | { |
599cee73 | 1527 | if (ckWARN(WARN_SYNTAX)) |
9014280d | 1528 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s); |
79072805 LW |
1529 | *--s = '$'; |
1530 | break; | |
1531 | } | |
02aa26ce NT |
1532 | |
1533 | /* string-change backslash escapes */ | |
3280af22 | 1534 | if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) { |
79072805 LW |
1535 | --s; |
1536 | break; | |
1537 | } | |
02aa26ce NT |
1538 | |
1539 | /* if we get here, it's either a quoted -, or a digit */ | |
79072805 | 1540 | switch (*s) { |
02aa26ce NT |
1541 | |
1542 | /* quoted - in transliterations */ | |
79072805 | 1543 | case '-': |
3280af22 | 1544 | if (PL_lex_inwhat == OP_TRANS) { |
79072805 LW |
1545 | *d++ = *s++; |
1546 | continue; | |
1547 | } | |
1548 | /* FALL THROUGH */ | |
1549 | default: | |
11b8faa4 | 1550 | { |
707afd92 | 1551 | if (ckWARN(WARN_MISC) && |
bfed75c6 | 1552 | isALNUM(*s) && |
707afd92 | 1553 | *s != '_') |
9014280d | 1554 | Perl_warner(aTHX_ packWARN(WARN_MISC), |
11b8faa4 JH |
1555 | "Unrecognized escape \\%c passed through", |
1556 | *s); | |
1557 | /* default action is to copy the quoted character */ | |
f9a63242 | 1558 | goto default_action; |
11b8faa4 | 1559 | } |
02aa26ce NT |
1560 | |
1561 | /* \132 indicates an octal constant */ | |
79072805 LW |
1562 | case '0': case '1': case '2': case '3': |
1563 | case '4': case '5': case '6': case '7': | |
ba210ebe | 1564 | { |
53305cf1 NC |
1565 | I32 flags = 0; |
1566 | STRLEN len = 3; | |
1567 | uv = grok_oct(s, &len, &flags, NULL); | |
ba210ebe JH |
1568 | s += len; |
1569 | } | |
012bcf8d | 1570 | goto NUM_ESCAPE_INSERT; |
02aa26ce NT |
1571 | |
1572 | /* \x24 indicates a hex constant */ | |
79072805 | 1573 | case 'x': |
a0ed51b3 LW |
1574 | ++s; |
1575 | if (*s == '{') { | |
1576 | char* e = strchr(s, '}'); | |
a4c04bdc NC |
1577 | I32 flags = PERL_SCAN_ALLOW_UNDERSCORES | |
1578 | PERL_SCAN_DISALLOW_PREFIX; | |
53305cf1 | 1579 | STRLEN len; |
355860ce | 1580 | |
53305cf1 | 1581 | ++s; |
adaeee49 | 1582 | if (!e) { |
a0ed51b3 | 1583 | yyerror("Missing right brace on \\x{}"); |
355860ce | 1584 | continue; |
ba210ebe | 1585 | } |
53305cf1 NC |
1586 | len = e - s; |
1587 | uv = grok_hex(s, &len, &flags, NULL); | |
ba210ebe | 1588 | s = e + 1; |
a0ed51b3 LW |
1589 | } |
1590 | else { | |
ba210ebe | 1591 | { |
53305cf1 | 1592 | STRLEN len = 2; |
a4c04bdc | 1593 | I32 flags = PERL_SCAN_DISALLOW_PREFIX; |
53305cf1 | 1594 | uv = grok_hex(s, &len, &flags, NULL); |
ba210ebe JH |
1595 | s += len; |
1596 | } | |
012bcf8d GS |
1597 | } |
1598 | ||
1599 | NUM_ESCAPE_INSERT: | |
1600 | /* Insert oct or hex escaped character. | |
301d3d20 | 1601 | * There will always enough room in sv since such |
db42d148 | 1602 | * escapes will be longer than any UTF-8 sequence |
301d3d20 | 1603 | * they can end up as. */ |
ba7cea30 | 1604 | |
c7f1f016 NIS |
1605 | /* We need to map to chars to ASCII before doing the tests |
1606 | to cover EBCDIC | |
1607 | */ | |
c4d5f83a | 1608 | if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) { |
9aa983d2 | 1609 | if (!has_utf8 && uv > 255) { |
301d3d20 JH |
1610 | /* Might need to recode whatever we have |
1611 | * accumulated so far if it contains any | |
1612 | * hibit chars. | |
1613 | * | |
1614 | * (Can't we keep track of that and avoid | |
1615 | * this rescan? --jhi) | |
012bcf8d | 1616 | */ |
c7f1f016 | 1617 | int hicount = 0; |
63cd0674 NIS |
1618 | U8 *c; |
1619 | for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) { | |
c4d5f83a | 1620 | if (!NATIVE_IS_INVARIANT(*c)) { |
012bcf8d | 1621 | hicount++; |
db42d148 | 1622 | } |
012bcf8d | 1623 | } |
63cd0674 | 1624 | if (hicount) { |
db42d148 NIS |
1625 | STRLEN offset = d - SvPVX(sv); |
1626 | U8 *src, *dst; | |
1627 | d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset; | |
1628 | src = (U8 *)d - 1; | |
1629 | dst = src+hicount; | |
1630 | d += hicount; | |
1631 | while (src >= (U8 *)SvPVX(sv)) { | |
c4d5f83a | 1632 | if (!NATIVE_IS_INVARIANT(*src)) { |
63cd0674 | 1633 | U8 ch = NATIVE_TO_ASCII(*src); |
eb160463 GS |
1634 | *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch); |
1635 | *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch); | |
012bcf8d GS |
1636 | } |
1637 | else { | |
63cd0674 | 1638 | *dst-- = *src; |
012bcf8d | 1639 | } |
c7f1f016 | 1640 | src--; |
012bcf8d GS |
1641 | } |
1642 | } | |
1643 | } | |
1644 | ||
9aa983d2 | 1645 | if (has_utf8 || uv > 255) { |
9041c2e3 | 1646 | d = (char*)uvchr_to_utf8((U8*)d, uv); |
4e553d73 | 1647 | has_utf8 = TRUE; |
f9a63242 JH |
1648 | if (PL_lex_inwhat == OP_TRANS && |
1649 | PL_sublex_info.sub_op) { | |
1650 | PL_sublex_info.sub_op->op_private |= | |
1651 | (PL_lex_repl ? OPpTRANS_FROM_UTF | |
1652 | : OPpTRANS_TO_UTF); | |
f9a63242 | 1653 | } |
012bcf8d | 1654 | } |
a0ed51b3 | 1655 | else { |
012bcf8d | 1656 | *d++ = (char)uv; |
a0ed51b3 | 1657 | } |
012bcf8d GS |
1658 | } |
1659 | else { | |
c4d5f83a | 1660 | *d++ = (char) uv; |
a0ed51b3 | 1661 | } |
79072805 | 1662 | continue; |
02aa26ce | 1663 | |
b239daa5 | 1664 | /* \N{LATIN SMALL LETTER A} is a named character */ |
4a2d328f | 1665 | case 'N': |
55eda711 | 1666 | ++s; |
423cee85 JH |
1667 | if (*s == '{') { |
1668 | char* e = strchr(s, '}'); | |
155aba94 | 1669 | SV *res; |
423cee85 JH |
1670 | STRLEN len; |
1671 | char *str; | |
4e553d73 | 1672 | |
423cee85 | 1673 | if (!e) { |
5777a3f7 | 1674 | yyerror("Missing right brace on \\N{}"); |
423cee85 JH |
1675 | e = s - 1; |
1676 | goto cont_scan; | |
1677 | } | |
dbc0d4f2 JH |
1678 | if (e > s + 2 && s[1] == 'U' && s[2] == '+') { |
1679 | /* \N{U+...} */ | |
1680 | I32 flags = PERL_SCAN_ALLOW_UNDERSCORES | | |
1681 | PERL_SCAN_DISALLOW_PREFIX; | |
1682 | s += 3; | |
1683 | len = e - s; | |
1684 | uv = grok_hex(s, &len, &flags, NULL); | |
1685 | s = e + 1; | |
1686 | goto NUM_ESCAPE_INSERT; | |
1687 | } | |
55eda711 JH |
1688 | res = newSVpvn(s + 1, e - s - 1); |
1689 | res = new_constant( Nullch, 0, "charnames", | |
1690 | res, Nullsv, "\\N{...}" ); | |
f9a63242 JH |
1691 | if (has_utf8) |
1692 | sv_utf8_upgrade(res); | |
423cee85 | 1693 | str = SvPV(res,len); |
1c47067b JH |
1694 | #ifdef EBCDIC_NEVER_MIND |
1695 | /* charnames uses pack U and that has been | |
1696 | * recently changed to do the below uni->native | |
1697 | * mapping, so this would be redundant (and wrong, | |
1698 | * the code point would be doubly converted). | |
1699 | * But leave this in just in case the pack U change | |
1700 | * gets revoked, but the semantics is still | |
1701 | * desireable for charnames. --jhi */ | |
cddc7ef4 JH |
1702 | { |
1703 | UV uv = utf8_to_uvchr((U8*)str, 0); | |
1704 | ||
1705 | if (uv < 0x100) { | |
89ebb4a3 | 1706 | U8 tmpbuf[UTF8_MAXBYTES+1], *d; |
cddc7ef4 JH |
1707 | |
1708 | d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv)); | |
1709 | sv_setpvn(res, (char *)tmpbuf, d - tmpbuf); | |
1710 | str = SvPV(res, len); | |
1711 | } | |
1712 | } | |
1713 | #endif | |
89491803 | 1714 | if (!has_utf8 && SvUTF8(res)) { |
f08d6ad9 GS |
1715 | char *ostart = SvPVX(sv); |
1716 | SvCUR_set(sv, d - ostart); | |
1717 | SvPOK_on(sv); | |
e4f3eed8 | 1718 | *d = '\0'; |
f08d6ad9 | 1719 | sv_utf8_upgrade(sv); |
d2f449dd | 1720 | /* this just broke our allocation above... */ |
eb160463 | 1721 | SvGROW(sv, (STRLEN)(send - start)); |
f08d6ad9 | 1722 | d = SvPVX(sv) + SvCUR(sv); |
89491803 | 1723 | has_utf8 = TRUE; |
f08d6ad9 | 1724 | } |
eb160463 | 1725 | if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */ |
423cee85 JH |
1726 | char *odest = SvPVX(sv); |
1727 | ||
8973db79 | 1728 | SvGROW(sv, (SvLEN(sv) + len - (e - s + 4))); |
423cee85 JH |
1729 | d = SvPVX(sv) + (d - odest); |
1730 | } | |
1731 | Copy(str, d, len, char); | |
1732 | d += len; | |
1733 | SvREFCNT_dec(res); | |
1734 | cont_scan: | |
1735 | s = e + 1; | |
1736 | } | |
1737 | else | |
5777a3f7 | 1738 | yyerror("Missing braces on \\N{}"); |
423cee85 JH |
1739 | continue; |
1740 | ||
02aa26ce | 1741 | /* \c is a control character */ |
79072805 LW |
1742 | case 'c': |
1743 | s++; | |
961ce445 | 1744 | if (s < send) { |
ba210ebe | 1745 | U8 c = *s++; |
c7f1f016 NIS |
1746 | #ifdef EBCDIC |
1747 | if (isLOWER(c)) | |
1748 | c = toUPPER(c); | |
1749 | #endif | |
db42d148 | 1750 | *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c)); |
ba210ebe | 1751 | } |
961ce445 RGS |
1752 | else { |
1753 | yyerror("Missing control char name in \\c"); | |
1754 | } | |
79072805 | 1755 | continue; |
02aa26ce NT |
1756 | |
1757 | /* printf-style backslashes, formfeeds, newlines, etc */ | |
79072805 | 1758 | case 'b': |
db42d148 | 1759 | *d++ = NATIVE_TO_NEED(has_utf8,'\b'); |
79072805 LW |
1760 | break; |
1761 | case 'n': | |
db42d148 | 1762 | *d++ = NATIVE_TO_NEED(has_utf8,'\n'); |
79072805 LW |
1763 | break; |
1764 | case 'r': | |
db42d148 | 1765 | *d++ = NATIVE_TO_NEED(has_utf8,'\r'); |
79072805 LW |
1766 | break; |
1767 | case 'f': | |
db42d148 | 1768 | *d++ = NATIVE_TO_NEED(has_utf8,'\f'); |
79072805 LW |
1769 | break; |
1770 | case 't': | |
db42d148 | 1771 | *d++ = NATIVE_TO_NEED(has_utf8,'\t'); |
79072805 | 1772 | break; |
34a3fe2a | 1773 | case 'e': |
db42d148 | 1774 | *d++ = ASCII_TO_NEED(has_utf8,'\033'); |
34a3fe2a PP |
1775 | break; |
1776 | case 'a': | |
db42d148 | 1777 | *d++ = ASCII_TO_NEED(has_utf8,'\007'); |
79072805 | 1778 | break; |
02aa26ce NT |
1779 | } /* end switch */ |
1780 | ||
79072805 LW |
1781 | s++; |
1782 | continue; | |
02aa26ce NT |
1783 | } /* end if (backslash) */ |
1784 | ||
f9a63242 | 1785 | default_action: |
2b9d42f0 NIS |
1786 | /* If we started with encoded form, or already know we want it |
1787 | and then encode the next character */ | |
1788 | if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) { | |
1789 | STRLEN len = 1; | |
1790 | UV uv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s); | |
1791 | STRLEN need = UNISKIP(NATIVE_TO_UNI(uv)); | |
1792 | s += len; | |
1793 | if (need > len) { | |
1794 | /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */ | |
1795 | STRLEN off = d - SvPVX(sv); | |
1796 | d = SvGROW(sv, SvLEN(sv) + (need-len)) + off; | |
1797 | } | |
1798 | d = (char*)uvchr_to_utf8((U8*)d, uv); | |
1799 | has_utf8 = TRUE; | |
1800 | } | |
1801 | else { | |
1802 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); | |
1803 | } | |
02aa26ce NT |
1804 | } /* while loop to process each character */ |
1805 | ||
1806 | /* terminate the string and set up the sv */ | |
79072805 | 1807 | *d = '\0'; |
463ee0b2 | 1808 | SvCUR_set(sv, d - SvPVX(sv)); |
2b9d42f0 | 1809 | if (SvCUR(sv) >= SvLEN(sv)) |
d0063567 | 1810 | Perl_croak(aTHX_ "panic: constant overflowed allocated space"); |
2b9d42f0 | 1811 | |
79072805 | 1812 | SvPOK_on(sv); |
9f4817db | 1813 | if (PL_encoding && !has_utf8) { |
d0063567 DK |
1814 | sv_recode_to_utf8(sv, PL_encoding); |
1815 | if (SvUTF8(sv)) | |
1816 | has_utf8 = TRUE; | |
9f4817db | 1817 | } |
2b9d42f0 | 1818 | if (has_utf8) { |
7e2040f0 | 1819 | SvUTF8_on(sv); |
2b9d42f0 | 1820 | if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) { |
d0063567 | 1821 | PL_sublex_info.sub_op->op_private |= |
2b9d42f0 NIS |
1822 | (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); |
1823 | } | |
1824 | } | |
79072805 | 1825 | |
02aa26ce | 1826 | /* shrink the sv if we allocated more than we used */ |
79072805 LW |
1827 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
1828 | SvLEN_set(sv, SvCUR(sv) + 1); | |
463ee0b2 | 1829 | Renew(SvPVX(sv), SvLEN(sv), char); |
79072805 | 1830 | } |
02aa26ce | 1831 | |
9b599b2a | 1832 | /* return the substring (via yylval) only if we parsed anything */ |
3280af22 NIS |
1833 | if (s > PL_bufptr) { |
1834 | if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) | |
4e553d73 | 1835 | sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"), |
b3ac6de7 | 1836 | sv, Nullsv, |
4e553d73 | 1837 | ( PL_lex_inwhat == OP_TRANS |
b3ac6de7 | 1838 | ? "tr" |
3280af22 | 1839 | : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) |
b3ac6de7 IZ |
1840 | ? "s" |
1841 | : "qq"))); | |
79072805 | 1842 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
b3ac6de7 | 1843 | } else |
8990e307 | 1844 | SvREFCNT_dec(sv); |
79072805 LW |
1845 | return s; |
1846 | } | |
1847 | ||
ffb4593c NT |
1848 | /* S_intuit_more |
1849 | * Returns TRUE if there's more to the expression (e.g., a subscript), | |
1850 | * FALSE otherwise. | |
ffb4593c NT |
1851 | * |
1852 | * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/ | |
1853 | * | |
1854 | * ->[ and ->{ return TRUE | |
1855 | * { and [ outside a pattern are always subscripts, so return TRUE | |
1856 | * if we're outside a pattern and it's not { or [, then return FALSE | |
1857 | * if we're in a pattern and the first char is a { | |
1858 | * {4,5} (any digits around the comma) returns FALSE | |
1859 | * if we're in a pattern and the first char is a [ | |
1860 | * [] returns FALSE | |
1861 | * [SOMETHING] has a funky algorithm to decide whether it's a | |
1862 | * character class or not. It has to deal with things like | |
1863 | * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/ | |
1864 | * anything else returns TRUE | |
1865 | */ | |
1866 | ||
9cbb5ea2 GS |
1867 | /* This is the one truly awful dwimmer necessary to conflate C and sed. */ |
1868 | ||
76e3520e | 1869 | STATIC int |
cea2e8a9 | 1870 | S_intuit_more(pTHX_ register char *s) |
79072805 | 1871 | { |
3280af22 | 1872 | if (PL_lex_brackets) |
79072805 LW |
1873 | return TRUE; |
1874 | if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{')) | |
1875 | return TRUE; | |
1876 | if (*s != '{' && *s != '[') | |
1877 | return FALSE; | |
3280af22 | 1878 | if (!PL_lex_inpat) |
79072805 LW |
1879 | return TRUE; |
1880 | ||
1881 | /* In a pattern, so maybe we have {n,m}. */ | |
1882 | if (*s == '{') { | |
1883 | s++; | |
1884 | if (!isDIGIT(*s)) | |
1885 | return TRUE; | |
1886 | while (isDIGIT(*s)) | |
1887 | s++; | |
1888 | if (*s == ',') | |
1889 | s++; | |
1890 | while (isDIGIT(*s)) | |
1891 | s++; | |
1892 | if (*s == '}') | |
1893 | return FALSE; | |
1894 | return TRUE; | |
1895 | ||
1896 | } | |
1897 | ||
1898 | /* On the other hand, maybe we have a character class */ | |
1899 | ||
1900 | s++; | |
1901 | if (*s == ']' || *s == '^') | |
1902 | return FALSE; | |
1903 | else { | |
ffb4593c | 1904 | /* this is terrifying, and it works */ |
79072805 LW |
1905 | int weight = 2; /* let's weigh the evidence */ |
1906 | char seen[256]; | |
f27ffc4a | 1907 | unsigned char un_char = 255, last_un_char; |
93a17b20 | 1908 | char *send = strchr(s,']'); |
3280af22 | 1909 | char tmpbuf[sizeof PL_tokenbuf * 4]; |
79072805 LW |
1910 | |
1911 | if (!send) /* has to be an expression */ | |
1912 | return TRUE; | |
1913 | ||
1914 | Zero(seen,256,char); | |
1915 | if (*s == '$') | |
1916 | weight -= 3; | |
1917 | else if (isDIGIT(*s)) { | |
1918 | if (s[1] != ']') { | |
1919 | if (isDIGIT(s[1]) && s[2] == ']') | |
1920 | weight -= 10; | |
1921 | } | |
1922 | else | |
1923 | weight -= 100; | |
1924 | } | |
1925 | for (; s < send; s++) { | |
1926 | last_un_char = un_char; | |
1927 | un_char = (unsigned char)*s; | |
1928 | switch (*s) { | |
1929 | case '@': | |
1930 | case '&': | |
1931 | case '$': | |
1932 | weight -= seen[un_char] * 10; | |
7e2040f0 | 1933 | if (isALNUM_lazy_if(s+1,UTF)) { |
8903cb82 | 1934 | scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE); |
a0d0e21e | 1935 | if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV)) |
79072805 LW |
1936 | weight -= 100; |
1937 | else | |
1938 | weight -= 10; | |
1939 | } | |
1940 | else if (*s == '$' && s[1] && | |
93a17b20 LW |
1941 | strchr("[#!%*<>()-=",s[1])) { |
1942 | if (/*{*/ strchr("])} =",s[2])) | |
79072805 LW |
1943 | weight -= 10; |
1944 | else | |
1945 | weight -= 1; | |
1946 | } | |
1947 | break; | |
1948 | case '\\': | |
1949 | un_char = 254; | |
1950 | if (s[1]) { | |
93a17b20 | 1951 | if (strchr("wds]",s[1])) |
79072805 LW |
1952 | weight += 100; |
1953 | else if (seen['\''] || seen['"']) | |
1954 | weight += 1; | |
93a17b20 | 1955 | else if (strchr("rnftbxcav",s[1])) |
79072805 LW |
1956 | weight += 40; |
1957 | else if (isDIGIT(s[1])) { | |
1958 | weight += 40; | |
1959 | while (s[1] && isDIGIT(s[1])) | |
1960 | s++; | |
1961 | } | |
1962 | } | |
1963 | else | |
1964 | weight += 100; | |
1965 | break; | |
1966 | case '-': | |
1967 | if (s[1] == '\\') | |
1968 | weight += 50; | |
93a17b20 | 1969 | if (strchr("aA01! ",last_un_char)) |
79072805 | 1970 | weight += 30; |
93a17b20 | 1971 | if (strchr("zZ79~",s[1])) |
79072805 | 1972 | weight += 30; |
f27ffc4a GS |
1973 | if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$')) |
1974 | weight -= 5; /* cope with negative subscript */ | |
79072805 LW |
1975 | break; |
1976 | default: | |
3792a11b NC |
1977 | if (!isALNUM(last_un_char) |
1978 | && !(last_un_char == '$' || last_un_char == '@' | |
1979 | || last_un_char == '&') | |
1980 | && isALPHA(*s) && s[1] && isALPHA(s[1])) { | |
79072805 LW |
1981 | char *d = tmpbuf; |
1982 | while (isALPHA(*s)) | |
1983 | *d++ = *s++; | |
1984 | *d = '\0'; | |
1985 | if (keyword(tmpbuf, d - tmpbuf)) | |
1986 | weight -= 150; | |
1987 | } | |
1988 | if (un_char == last_un_char + 1) | |
1989 | weight += 5; | |
1990 | weight -= seen[un_char]; | |
1991 | break; | |
1992 | } | |
1993 | seen[un_char]++; | |
1994 | } | |
1995 | if (weight >= 0) /* probably a character class */ | |
1996 | return FALSE; | |
1997 | } | |
1998 | ||
1999 | return TRUE; | |
2000 | } | |
ffed7fef | 2001 | |
ffb4593c NT |
2002 | /* |
2003 | * S_intuit_method | |
2004 | * | |
2005 | * Does all the checking to disambiguate | |
2006 | * foo bar | |
2007 | * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise | |
2008 | * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args). | |
2009 | * | |
2010 | * First argument is the stuff after the first token, e.g. "bar". | |
2011 | * | |
2012 | * Not a method if bar is a filehandle. | |
2013 | * Not a method if foo is a subroutine prototyped to take a filehandle. | |
2014 | * Not a method if it's really "Foo $bar" | |
2015 | * Method if it's "foo $bar" | |
2016 | * Not a method if it's really "print foo $bar" | |
2017 | * Method if it's really "foo package::" (interpreted as package->foo) | |
8f8cf39c | 2018 | * Not a method if bar is known to be a subroutine ("sub bar; foo bar") |
3cb0bbe5 | 2019 | * Not a method if bar is a filehandle or package, but is quoted with |
ffb4593c NT |
2020 | * => |
2021 | */ | |
2022 | ||
76e3520e | 2023 | STATIC int |
cea2e8a9 | 2024 | S_intuit_method(pTHX_ char *start, GV *gv) |
a0d0e21e LW |
2025 | { |
2026 | char *s = start + (*start == '$'); | |
3280af22 | 2027 | char tmpbuf[sizeof PL_tokenbuf]; |
a0d0e21e LW |
2028 | STRLEN len; |
2029 | GV* indirgv; | |
2030 | ||
2031 | if (gv) { | |
b6c543e3 | 2032 | CV *cv; |
a0d0e21e LW |
2033 | if (GvIO(gv)) |
2034 | return 0; | |
b6c543e3 IZ |
2035 | if ((cv = GvCVu(gv))) { |
2036 | char *proto = SvPVX(cv); | |
2037 | if (proto) { | |
2038 | if (*proto == ';') | |
2039 | proto++; | |
2040 | if (*proto == '*') | |
2041 | return 0; | |
2042 | } | |
2043 | } else | |
a0d0e21e LW |
2044 | gv = 0; |
2045 | } | |
8903cb82 | 2046 | s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
ffb4593c NT |
2047 | /* start is the beginning of the possible filehandle/object, |
2048 | * and s is the end of it | |
2049 | * tmpbuf is a copy of it | |
2050 | */ | |
2051 | ||
a0d0e21e | 2052 | if (*start == '$') { |
3280af22 | 2053 | if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf)) |
a0d0e21e LW |
2054 | return 0; |
2055 | s = skipspace(s); | |
3280af22 NIS |
2056 | PL_bufptr = start; |
2057 | PL_expect = XREF; | |
a0d0e21e LW |
2058 | return *s == '(' ? FUNCMETH : METHOD; |
2059 | } | |
2060 | if (!keyword(tmpbuf, len)) { | |
c3e0f903 GS |
2061 | if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') { |
2062 | len -= 2; | |
2063 | tmpbuf[len] = '\0'; | |
2064 | goto bare_package; | |
2065 | } | |
2066 | indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV); | |
8ebc5c01 | 2067 | if (indirgv && GvCVu(indirgv)) |
a0d0e21e LW |
2068 | return 0; |
2069 | /* filehandle or package name makes it a method */ | |
89bfa8cd | 2070 | if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) { |
a0d0e21e | 2071 | s = skipspace(s); |
3280af22 | 2072 | if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>') |
55497cff | 2073 | return 0; /* no assumptions -- "=>" quotes bearword */ |
c3e0f903 | 2074 | bare_package: |
3280af22 | 2075 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, |
79cb57f6 | 2076 | newSVpvn(tmpbuf,len)); |
3280af22 NIS |
2077 | PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE; |
2078 | PL_expect = XTERM; | |
a0d0e21e | 2079 | force_next(WORD); |
3280af22 | 2080 | PL_bufptr = s; |
a0d0e21e LW |
2081 | return *s == '(' ? FUNCMETH : METHOD; |
2082 | } | |
2083 | } | |
2084 | return 0; | |
2085 | } | |
2086 | ||
ffb4593c NT |
2087 | /* |
2088 | * S_incl_perldb | |
2089 | * Return a string of Perl code to load the debugger. If PERL5DB | |
2090 | * is set, it will return the contents of that, otherwise a | |
2091 | * compile-time require of perl5db.pl. | |
2092 | */ | |
2093 | ||
bfed75c6 | 2094 | STATIC const char* |
cea2e8a9 | 2095 | S_incl_perldb(pTHX) |
a0d0e21e | 2096 | { |
3280af22 | 2097 | if (PL_perldb) { |
bfed75c6 | 2098 | const char *pdb = PerlEnv_getenv("PERL5DB"); |
a0d0e21e LW |
2099 | |
2100 | if (pdb) | |
2101 | return pdb; | |
93189314 | 2102 | SETERRNO(0,SS_NORMAL); |
a0d0e21e LW |
2103 | return "BEGIN { require 'perl5db.pl' }"; |
2104 | } | |
2105 | return ""; | |
2106 | } | |
2107 | ||
2108 | ||
16d20bd9 | 2109 | /* Encoded script support. filter_add() effectively inserts a |
4e553d73 | 2110 | * 'pre-processing' function into the current source input stream. |
16d20bd9 AD |
2111 | * Note that the filter function only applies to the current source file |
2112 | * (e.g., it will not affect files 'require'd or 'use'd by this one). | |
2113 | * | |
2114 | * The datasv parameter (which may be NULL) can be used to pass | |
2115 | * private data to this instance of the filter. The filter function | |
2116 | * can recover the SV using the FILTER_DATA macro and use it to | |
2117 | * store private buffers and state information. | |
2118 | * | |
2119 | * The supplied datasv parameter is upgraded to a PVIO type | |
4755096e | 2120 | * and the IoDIRP/IoANY field is used to store the function pointer, |
e0c19803 | 2121 | * and IOf_FAKE_DIRP is enabled on datasv to mark this as such. |
16d20bd9 AD |
2122 | * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for |
2123 | * private use must be set using malloc'd pointers. | |
2124 | */ | |
16d20bd9 AD |
2125 | |
2126 | SV * | |
864dbfa3 | 2127 | Perl_filter_add(pTHX_ filter_t funcp, SV *datasv) |
16d20bd9 | 2128 | { |
f4c556ac GS |
2129 | if (!funcp) |
2130 | return Nullsv; | |
2131 | ||
3280af22 NIS |
2132 | if (!PL_rsfp_filters) |
2133 | PL_rsfp_filters = newAV(); | |
16d20bd9 | 2134 | if (!datasv) |
8c52afec | 2135 | datasv = NEWSV(255,0); |
16d20bd9 | 2136 | if (!SvUPGRADE(datasv, SVt_PVIO)) |
cea2e8a9 | 2137 | Perl_die(aTHX_ "Can't upgrade filter_add data to SVt_PVIO"); |
4755096e | 2138 | IoANY(datasv) = (void *)funcp; /* stash funcp into spare field */ |
e0c19803 | 2139 | IoFLAGS(datasv) |= IOf_FAKE_DIRP; |
f4c556ac | 2140 | DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n", |
fe5a182c | 2141 | (void*)funcp, SvPV_nolen(datasv))); |
3280af22 NIS |
2142 | av_unshift(PL_rsfp_filters, 1); |
2143 | av_store(PL_rsfp_filters, 0, datasv) ; | |
16d20bd9 AD |
2144 | return(datasv); |
2145 | } | |
4e553d73 | 2146 | |
16d20bd9 AD |
2147 | |
2148 | /* Delete most recently added instance of this filter function. */ | |
a0d0e21e | 2149 | void |
864dbfa3 | 2150 | Perl_filter_del(pTHX_ filter_t funcp) |
16d20bd9 | 2151 | { |
e0c19803 | 2152 | SV *datasv; |
fe5a182c | 2153 | DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", (void*)funcp)); |
3280af22 | 2154 | if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0) |
16d20bd9 AD |
2155 | return; |
2156 | /* if filter is on top of stack (usual case) just pop it off */ | |
e0c19803 | 2157 | datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters)); |
4755096e | 2158 | if (IoANY(datasv) == (void *)funcp) { |
e0c19803 | 2159 | IoFLAGS(datasv) &= ~IOf_FAKE_DIRP; |
4755096e | 2160 | IoANY(datasv) = (void *)NULL; |
3280af22 | 2161 | sv_free(av_pop(PL_rsfp_filters)); |
e50aee73 | 2162 | |
16d20bd9 AD |
2163 | return; |
2164 | } | |
2165 | /* we need to search for the correct entry and clear it */ | |
cea2e8a9 | 2166 | Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)"); |
16d20bd9 AD |
2167 | } |
2168 | ||
2169 | ||
1de9afcd RGS |
2170 | /* Invoke the idxth filter function for the current rsfp. */ |
2171 | /* maxlen 0 = read one text line */ | |
16d20bd9 | 2172 | I32 |
864dbfa3 | 2173 | Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen) |
a0d0e21e | 2174 | { |
16d20bd9 AD |
2175 | filter_t funcp; |
2176 | SV *datasv = NULL; | |
e50aee73 | 2177 | |
3280af22 | 2178 | if (!PL_rsfp_filters) |
16d20bd9 | 2179 | return -1; |
1de9afcd | 2180 | if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */ |
16d20bd9 AD |
2181 | /* Provide a default input filter to make life easy. */ |
2182 | /* Note that we append to the line. This is handy. */ | |
f4c556ac GS |
2183 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2184 | "filter_read %d: from rsfp\n", idx)); | |
4e553d73 | 2185 | if (maxlen) { |
16d20bd9 AD |
2186 | /* Want a block */ |
2187 | int len ; | |
2188 | int old_len = SvCUR(buf_sv) ; | |
2189 | ||
2190 | /* ensure buf_sv is large enough */ | |
eb160463 | 2191 | SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ; |
3280af22 NIS |
2192 | if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){ |
2193 | if (PerlIO_error(PL_rsfp)) | |
37120919 AD |
2194 | return -1; /* error */ |
2195 | else | |
2196 | return 0 ; /* end of file */ | |
2197 | } | |
16d20bd9 AD |
2198 | SvCUR_set(buf_sv, old_len + len) ; |
2199 | } else { | |
2200 | /* Want a line */ | |
3280af22 NIS |
2201 | if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) { |
2202 | if (PerlIO_error(PL_rsfp)) | |
37120919 AD |
2203 | return -1; /* error */ |
2204 | else | |
2205 | return 0 ; /* end of file */ | |
2206 | } | |
16d20bd9 AD |
2207 | } |
2208 | return SvCUR(buf_sv); | |
2209 | } | |
2210 | /* Skip this filter slot if filter has been deleted */ | |
1de9afcd | 2211 | if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) { |
f4c556ac GS |
2212 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2213 | "filter_read %d: skipped (filter deleted)\n", | |
2214 | idx)); | |
16d20bd9 AD |
2215 | return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */ |
2216 | } | |
2217 | /* Get function pointer hidden within datasv */ | |
4755096e | 2218 | funcp = (filter_t)IoANY(datasv); |
f4c556ac GS |
2219 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
2220 | "filter_read %d: via function %p (%s)\n", | |
fe5a182c | 2221 | idx, (void*)funcp, SvPV_nolen(datasv))); |
16d20bd9 AD |
2222 | /* Call function. The function is expected to */ |
2223 | /* call "FILTER_READ(idx+1, buf_sv)" first. */ | |
37120919 | 2224 | /* Return: <0:error, =0:eof, >0:not eof */ |
acfe0abc | 2225 | return (*funcp)(aTHX_ idx, buf_sv, maxlen); |
16d20bd9 AD |
2226 | } |
2227 | ||
76e3520e | 2228 | STATIC char * |
cea2e8a9 | 2229 | S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append) |
16d20bd9 | 2230 | { |
c39cd008 | 2231 | #ifdef PERL_CR_FILTER |
3280af22 | 2232 | if (!PL_rsfp_filters) { |
c39cd008 | 2233 | filter_add(S_cr_textfilter,NULL); |
a868473f NIS |
2234 | } |
2235 | #endif | |
3280af22 | 2236 | if (PL_rsfp_filters) { |
55497cff | 2237 | if (!append) |
2238 | SvCUR_set(sv, 0); /* start with empty line */ | |
16d20bd9 AD |
2239 | if (FILTER_READ(0, sv, 0) > 0) |
2240 | return ( SvPVX(sv) ) ; | |
2241 | else | |
2242 | return Nullch ; | |
2243 | } | |
9d116dd7 | 2244 | else |
fd049845 | 2245 | return (sv_gets(sv, fp, append)); |
a0d0e21e LW |
2246 | } |
2247 | ||
01ec43d0 | 2248 | STATIC HV * |
7fc63493 | 2249 | S_find_in_my_stash(pTHX_ const char *pkgname, I32 len) |
def3634b GS |
2250 | { |
2251 | GV *gv; | |
2252 | ||
01ec43d0 | 2253 | if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__")) |
def3634b GS |
2254 | return PL_curstash; |
2255 | ||
2256 | if (len > 2 && | |
2257 | (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') && | |
01ec43d0 GS |
2258 | (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV))) |
2259 | { | |
2260 | return GvHV(gv); /* Foo:: */ | |
def3634b GS |
2261 | } |
2262 | ||
2263 | /* use constant CLASS => 'MyClass' */ | |
2264 | if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) { | |
2265 | SV *sv; | |
2266 | if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) { | |
2267 | pkgname = SvPV_nolen(sv); | |
2268 | } | |
2269 | } | |
2270 | ||
2271 | return gv_stashpv(pkgname, FALSE); | |
2272 | } | |
a0d0e21e | 2273 | |
748a9306 | 2274 | #ifdef DEBUGGING |
bfed75c6 | 2275 | static char const* exp_name[] = |
09bef843 | 2276 | { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK", |
27308ded | 2277 | "ATTRTERM", "TERMBLOCK", "TERMORDORDOR" |
09bef843 | 2278 | }; |
748a9306 | 2279 | #endif |
463ee0b2 | 2280 | |
02aa26ce NT |
2281 | /* |
2282 | yylex | |
2283 | ||
2284 | Works out what to call the token just pulled out of the input | |
2285 | stream. The yacc parser takes care of taking the ops we return and | |
2286 | stitching them into a tree. | |
2287 | ||
2288 | Returns: | |
2289 | PRIVATEREF | |
2290 | ||
2291 | Structure: | |
2292 | if read an identifier | |
2293 | if we're in a my declaration | |
2294 | croak if they tried to say my($foo::bar) | |
2295 | build the ops for a my() declaration | |
2296 | if it's an access to a my() variable | |
2297 | are we in a sort block? | |
2298 | croak if my($a); $a <=> $b | |
2299 | build ops for access to a my() variable | |
2300 | if in a dq string, and they've said @foo and we can't find @foo | |
2301 | croak | |
2302 | build ops for a bareword | |
2303 | if we already built the token before, use it. | |
2304 | */ | |
2305 | ||
20141f0e | 2306 | |
dba4d153 JH |
2307 | #ifdef __SC__ |
2308 | #pragma segment Perl_yylex | |
2309 | #endif | |
dba4d153 | 2310 | int |
dba4d153 | 2311 | Perl_yylex(pTHX) |
20141f0e | 2312 | { |
3afc138a | 2313 | register char *s = PL_bufptr; |
378cc40b | 2314 | register char *d; |
79072805 | 2315 | register I32 tmp; |
463ee0b2 | 2316 | STRLEN len; |
161b471a NIS |
2317 | GV *gv = Nullgv; |
2318 | GV **gvp = 0; | |
aa7440fb | 2319 | bool bof = FALSE; |
1d239bbb | 2320 | I32 orig_keyword = 0; |
a687059c | 2321 | |
bbf60fe6 DM |
2322 | DEBUG_T( { |
2323 | PerlIO_printf(Perl_debug_log, "### LEX_%s\n", | |
2324 | lex_state_names[PL_lex_state]); | |
2325 | } ); | |
02aa26ce | 2326 | /* check if there's an identifier for us to look at */ |
ba979b31 | 2327 | if (PL_pending_ident) |
bbf60fe6 | 2328 | return REPORT(S_pending_ident(aTHX)); |
bbce6d69 | 2329 | |
02aa26ce NT |
2330 | /* no identifier pending identification */ |
2331 | ||
3280af22 | 2332 | switch (PL_lex_state) { |
79072805 LW |
2333 | #ifdef COMMENTARY |
2334 | case LEX_NORMAL: /* Some compilers will produce faster */ | |
2335 | case LEX_INTERPNORMAL: /* code if we comment these out. */ | |
2336 | break; | |
2337 | #endif | |
2338 | ||
09bef843 | 2339 | /* when we've already built the next token, just pull it out of the queue */ |
79072805 | 2340 | case LEX_KNOWNEXT: |
3280af22 NIS |
2341 | PL_nexttoke--; |
2342 | yylval = PL_nextval[PL_nexttoke]; | |
2343 | if (!PL_nexttoke) { | |
2344 | PL_lex_state = PL_lex_defer; | |
2345 | PL_expect = PL_lex_expect; | |
2346 | PL_lex_defer = LEX_NORMAL; | |
463ee0b2 | 2347 | } |
607df283 | 2348 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
4659c93f | 2349 | "### Next token after '%s' was known, type %"IVdf"\n", PL_bufptr, |
5f80b19c | 2350 | (IV)PL_nexttype[PL_nexttoke]); }); |
607df283 | 2351 | |
bbf60fe6 | 2352 | return REPORT(PL_nexttype[PL_nexttoke]); |
79072805 | 2353 | |
02aa26ce | 2354 | /* interpolated case modifiers like \L \U, including \Q and \E. |
3280af22 | 2355 | when we get here, PL_bufptr is at the \ |
02aa26ce | 2356 | */ |
79072805 LW |
2357 | case LEX_INTERPCASEMOD: |
2358 | #ifdef DEBUGGING | |
3280af22 | 2359 | if (PL_bufptr != PL_bufend && *PL_bufptr != '\\') |
cea2e8a9 | 2360 | Perl_croak(aTHX_ "panic: INTERPCASEMOD"); |
79072805 | 2361 | #endif |
02aa26ce | 2362 | /* handle \E or end of string */ |
3280af22 | 2363 | if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') { |
a0d0e21e | 2364 | char oldmod; |
02aa26ce NT |
2365 | |
2366 | /* if at a \E */ | |
3280af22 NIS |
2367 | if (PL_lex_casemods) { |
2368 | oldmod = PL_lex_casestack[--PL_lex_casemods]; | |
2369 | PL_lex_casestack[PL_lex_casemods] = '\0'; | |
02aa26ce | 2370 | |
3792a11b NC |
2371 | if (PL_bufptr != PL_bufend |
2372 | && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) { | |
3280af22 NIS |
2373 | PL_bufptr += 2; |
2374 | PL_lex_state = LEX_INTERPCONCAT; | |
a0d0e21e | 2375 | } |
bbf60fe6 | 2376 | return REPORT(')'); |
79072805 | 2377 | } |
3280af22 NIS |
2378 | if (PL_bufptr != PL_bufend) |
2379 | PL_bufptr += 2; | |
2380 | PL_lex_state = LEX_INTERPCONCAT; | |
cea2e8a9 | 2381 | return yylex(); |
79072805 LW |
2382 | } |
2383 | else { | |
607df283 | 2384 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
5f80b19c | 2385 | "### Saw case modifier at '%s'\n", PL_bufptr); }); |
3280af22 | 2386 | s = PL_bufptr + 1; |
6e909404 JH |
2387 | if (s[1] == '\\' && s[2] == 'E') { |
2388 | PL_bufptr = s + 3; | |
2389 | PL_lex_state = LEX_INTERPCONCAT; | |
2390 | return yylex(); | |
a0d0e21e | 2391 | } |
6e909404 JH |
2392 | else { |
2393 | if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3)) | |
2394 | tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */ | |
3792a11b | 2395 | if ((*s == 'L' || *s == 'U') && |
6e909404 JH |
2396 | (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) { |
2397 | PL_lex_casestack[--PL_lex_casemods] = '\0'; | |
bbf60fe6 | 2398 | return REPORT(')'); |
6e909404 JH |
2399 | } |
2400 | if (PL_lex_casemods > 10) | |
2401 | Renew(PL_lex_casestack, PL_lex_casemods + 2, char); | |
2402 | PL_lex_casestack[PL_lex_casemods++] = *s; | |
2403 | PL_lex_casestack[PL_lex_casemods] = '\0'; | |
2404 | PL_lex_state = LEX_INTERPCONCAT; | |
2405 | PL_nextval[PL_nexttoke].ival = 0; | |
2406 | force_next('('); | |
2407 | if (*s == 'l') | |
2408 | PL_nextval[PL_nexttoke].ival = OP_LCFIRST; | |
2409 | else if (*s == 'u') | |
2410 | PL_nextval[PL_nexttoke].ival = OP_UCFIRST; | |
2411 | else if (*s == 'L') | |
2412 | PL_nextval[PL_nexttoke].ival = OP_LC; | |
2413 | else if (*s == 'U') | |
2414 | PL_nextval[PL_nexttoke].ival = OP_UC; | |
2415 | else if (*s == 'Q') | |
2416 | PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA; | |
2417 | else | |
2418 | Perl_croak(aTHX_ "panic: yylex"); | |
2419 | PL_bufptr = s + 1; | |
a0d0e21e | 2420 | } |
79072805 | 2421 | force_next(FUNC); |
3280af22 NIS |
2422 | if (PL_lex_starts) { |
2423 | s = PL_bufptr; | |
2424 | PL_lex_starts = 0; | |
131b3ad0 DM |
2425 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ |
2426 | if (PL_lex_casemods == 1 && PL_lex_inpat) | |
2427 | OPERATOR(','); | |
2428 | else | |
2429 | Aop(OP_CONCAT); | |
79072805 LW |
2430 | } |
2431 | else | |
cea2e8a9 | 2432 | return yylex(); |
79072805 LW |
2433 | } |
2434 | ||
55497cff | 2435 | case LEX_INTERPPUSH: |
bbf60fe6 | 2436 | return REPORT(sublex_push()); |
55497cff | 2437 | |
79072805 | 2438 | case LEX_INTERPSTART: |
3280af22 | 2439 | if (PL_bufptr == PL_bufend) |
bbf60fe6 | 2440 | return REPORT(sublex_done()); |
607df283 | 2441 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
5f80b19c | 2442 | "### Interpolated variable at '%s'\n", PL_bufptr); }); |
3280af22 NIS |
2443 | PL_expect = XTERM; |
2444 | PL_lex_dojoin = (*PL_bufptr == '@'); | |
2445 | PL_lex_state = LEX_INTERPNORMAL; | |
2446 | if (PL_lex_dojoin) { | |
2447 | PL_nextval[PL_nexttoke].ival = 0; | |
79072805 | 2448 | force_next(','); |
a0d0e21e | 2449 | force_ident("\"", '$'); |
3280af22 | 2450 | PL_nextval[PL_nexttoke].ival = 0; |
79072805 | 2451 | force_next('$'); |
3280af22 | 2452 | PL_nextval[PL_nexttoke].ival = 0; |
79072805 | 2453 | force_next('('); |
3280af22 | 2454 | PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */ |
79072805 LW |
2455 | force_next(FUNC); |
2456 | } | |
3280af22 NIS |
2457 | if (PL_lex_starts++) { |
2458 | s = PL_bufptr; | |
131b3ad0 DM |
2459 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ |
2460 | if (!PL_lex_casemods && PL_lex_inpat) | |
2461 | OPERATOR(','); | |
2462 | else | |
2463 | Aop(OP_CONCAT); | |
79072805 | 2464 | } |
cea2e8a9 | 2465 | return yylex(); |
79072805 LW |
2466 | |
2467 | case LEX_INTERPENDMAYBE: | |
3280af22 NIS |
2468 | if (intuit_more(PL_bufptr)) { |
2469 | PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */ | |
79072805 LW |
2470 | break; |
2471 | } | |
2472 | /* FALL THROUGH */ | |
2473 | ||
2474 | case LEX_INTERPEND: | |
3280af22 NIS |
2475 | if (PL_lex_dojoin) { |
2476 | PL_lex_dojoin = FALSE; | |
2477 | PL_lex_state = LEX_INTERPCONCAT; | |
bbf60fe6 | 2478 | return REPORT(')'); |
79072805 | 2479 | } |
43a16006 | 2480 | if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl |
25da4f38 | 2481 | && SvEVALED(PL_lex_repl)) |
43a16006 | 2482 | { |
e9fa98b2 | 2483 | if (PL_bufptr != PL_bufend) |
cea2e8a9 | 2484 | Perl_croak(aTHX_ "Bad evalled substitution pattern"); |
e9fa98b2 HS |
2485 | PL_lex_repl = Nullsv; |
2486 | } | |
79072805 LW |
2487 | /* FALLTHROUGH */ |
2488 | case LEX_INTERPCONCAT: | |
2489 | #ifdef DEBUGGING | |
3280af22 | 2490 | if (PL_lex_brackets) |
cea2e8a9 | 2491 | Perl_croak(aTHX_ "panic: INTERPCONCAT"); |
79072805 | 2492 | #endif |
3280af22 | 2493 | if (PL_bufptr == PL_bufend) |
bbf60fe6 | 2494 | return REPORT(sublex_done()); |
79072805 | 2495 | |
3280af22 NIS |
2496 | if (SvIVX(PL_linestr) == '\'') { |
2497 | SV *sv = newSVsv(PL_linestr); | |
2498 | if (!PL_lex_inpat) | |
76e3520e | 2499 | sv = tokeq(sv); |
3280af22 | 2500 | else if ( PL_hints & HINT_NEW_RE ) |
b3ac6de7 | 2501 | sv = new_constant(NULL, 0, "qr", sv, sv, "q"); |
79072805 | 2502 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
3280af22 | 2503 | s = PL_bufend; |
79072805 LW |
2504 | } |
2505 | else { | |
3280af22 | 2506 | s = scan_const(PL_bufptr); |
79072805 | 2507 | if (*s == '\\') |
3280af22 | 2508 | PL_lex_state = LEX_INTERPCASEMOD; |
79072805 | 2509 | else |
3280af22 | 2510 | PL_lex_state = LEX_INTERPSTART; |
79072805 LW |
2511 | } |
2512 | ||
3280af22 NIS |
2513 | if (s != PL_bufptr) { |
2514 | PL_nextval[PL_nexttoke] = yylval; | |
2515 | PL_expect = XTERM; | |
79072805 | 2516 | force_next(THING); |
131b3ad0 DM |
2517 | if (PL_lex_starts++) { |
2518 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ | |
2519 | if (!PL_lex_casemods && PL_lex_inpat) | |
2520 | OPERATOR(','); | |
2521 | else | |
2522 | Aop(OP_CONCAT); | |
2523 | } | |
79072805 | 2524 | else { |
3280af22 | 2525 | PL_bufptr = s; |
cea2e8a9 | 2526 | return yylex(); |
79072805 LW |
2527 | } |
2528 | } | |
2529 | ||
cea2e8a9 | 2530 | return yylex(); |
a0d0e21e | 2531 | case LEX_FORMLINE: |
3280af22 NIS |
2532 | PL_lex_state = LEX_NORMAL; |
2533 | s = scan_formline(PL_bufptr); | |
2534 | if (!PL_lex_formbrack) | |
a0d0e21e LW |
2535 | goto rightbracket; |
2536 | OPERATOR(';'); | |
79072805 LW |
2537 | } |
2538 | ||
3280af22 NIS |
2539 | s = PL_bufptr; |
2540 | PL_oldoldbufptr = PL_oldbufptr; | |
2541 | PL_oldbufptr = s; | |
607df283 | 2542 | DEBUG_T( { |
bbf60fe6 | 2543 | PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at [%s]\n", |
bf49b057 | 2544 | exp_name[PL_expect], s); |
5f80b19c | 2545 | } ); |
463ee0b2 LW |
2546 | |
2547 | retry: | |
378cc40b LW |
2548 | switch (*s) { |
2549 | default: | |
7e2040f0 | 2550 | if (isIDFIRST_lazy_if(s,UTF)) |
834a4ddd | 2551 | goto keylookup; |
cea2e8a9 | 2552 | Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255); |
e929a76b LW |
2553 | case 4: |
2554 | case 26: | |
2555 | goto fake_eof; /* emulate EOF on ^D or ^Z */ | |
378cc40b | 2556 | case 0: |
3280af22 NIS |
2557 | if (!PL_rsfp) { |
2558 | PL_last_uni = 0; | |
2559 | PL_last_lop = 0; | |
c5ee2135 WL |
2560 | if (PL_lex_brackets) { |
2561 | if (PL_lex_formbrack) | |
2562 | yyerror("Format not terminated"); | |
2563 | else | |
2564 | yyerror("Missing right curly or square bracket"); | |
2565 | } | |
4e553d73 | 2566 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
607df283 | 2567 | "### Tokener got EOF\n"); |
5f80b19c | 2568 | } ); |
79072805 | 2569 | TOKEN(0); |
463ee0b2 | 2570 | } |
3280af22 | 2571 | if (s++ < PL_bufend) |
a687059c | 2572 | goto retry; /* ignore stray nulls */ |
3280af22 NIS |
2573 | PL_last_uni = 0; |
2574 | PL_last_lop = 0; | |
2575 | if (!PL_in_eval && !PL_preambled) { | |
2576 | PL_preambled = TRUE; | |
2577 | sv_setpv(PL_linestr,incl_perldb()); | |
2578 | if (SvCUR(PL_linestr)) | |
4147a61b | 2579 | sv_catpvn(PL_linestr,";", 1); |
3280af22 NIS |
2580 | if (PL_preambleav){ |
2581 | while(AvFILLp(PL_preambleav) >= 0) { | |
2582 | SV *tmpsv = av_shift(PL_preambleav); | |
2583 | sv_catsv(PL_linestr, tmpsv); | |
4147a61b | 2584 | sv_catpvn(PL_linestr, ";", 1); |
91b7def8 | 2585 | sv_free(tmpsv); |
2586 | } | |
3280af22 NIS |
2587 | sv_free((SV*)PL_preambleav); |
2588 | PL_preambleav = NULL; | |
91b7def8 | 2589 | } |
3280af22 NIS |
2590 | if (PL_minus_n || PL_minus_p) { |
2591 | sv_catpv(PL_linestr, "LINE: while (<>) {"); | |
2592 | if (PL_minus_l) | |
2593 | sv_catpv(PL_linestr,"chomp;"); | |
2594 | if (PL_minus_a) { | |
3280af22 | 2595 | if (PL_minus_F) { |
3792a11b NC |
2596 | if ((*PL_splitstr == '/' || *PL_splitstr == '\'' |
2597 | || *PL_splitstr == '"') | |
3280af22 | 2598 | && strchr(PL_splitstr + 1, *PL_splitstr)) |
3db68c4c | 2599 | Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr); |
54310121 | 2600 | else { |
c8ef6a4b NC |
2601 | /* "q\0${splitstr}\0" is legal perl. Yes, even NUL |
2602 | bytes can be used as quoting characters. :-) */ | |
48c4c863 NC |
2603 | /* The count here deliberately includes the NUL |
2604 | that terminates the C string constant. This | |
2605 | embeds the opening NUL into the string. */ | |
dd374669 | 2606 | const char *splits = PL_splitstr; |
9a3fb652 | 2607 | sv_catpvn(PL_linestr, "our @F=split(q", 15); |
48c4c863 NC |
2608 | do { |
2609 | /* Need to \ \s */ | |
dd374669 AL |
2610 | if (*splits == '\\') |
2611 | sv_catpvn(PL_linestr, splits, 1); | |
2612 | sv_catpvn(PL_linestr, splits, 1); | |
2613 | } while (*splits++); | |
48c4c863 NC |
2614 | /* This loop will embed the trailing NUL of |
2615 | PL_linestr as the last thing it does before | |
2616 | terminating. */ | |
4fccd7c6 | 2617 | sv_catpvn(PL_linestr, ");", 2); |
54310121 | 2618 | } |
2304df62 AD |
2619 | } |
2620 | else | |
75c72d73 | 2621 | sv_catpv(PL_linestr,"our @F=split(' ');"); |
2304df62 | 2622 | } |
79072805 | 2623 | } |
4147a61b | 2624 | sv_catpvn(PL_linestr, "\n", 1); |
3280af22 NIS |
2625 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
2626 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2627 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 2628 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
a0d0e21e LW |
2629 | SV *sv = NEWSV(85,0); |
2630 | ||
2631 | sv_upgrade(sv, SVt_PVMG); | |
3280af22 | 2632 | sv_setsv(sv,PL_linestr); |
0ac0412a MJD |
2633 | (void)SvIOK_on(sv); |
2634 | SvIVX(sv) = 0; | |
57843af0 | 2635 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
a0d0e21e | 2636 | } |
79072805 | 2637 | goto retry; |
a687059c | 2638 | } |
e929a76b | 2639 | do { |
aa7440fb | 2640 | bof = PL_rsfp ? TRUE : FALSE; |
7e28d3af JH |
2641 | if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) { |
2642 | fake_eof: | |
2643 | if (PL_rsfp) { | |
2644 | if (PL_preprocess && !PL_in_eval) | |
2645 | (void)PerlProc_pclose(PL_rsfp); | |
2646 | else if ((PerlIO *)PL_rsfp == PerlIO_stdin()) | |
2647 | PerlIO_clearerr(PL_rsfp); | |
2648 | else | |
2649 | (void)PerlIO_close(PL_rsfp); | |
2650 | PL_rsfp = Nullfp; | |
2651 | PL_doextract = FALSE; | |
2652 | } | |
2653 | if (!PL_in_eval && (PL_minus_n || PL_minus_p)) { | |
a23c4656 NC |
2654 | sv_setpv(PL_linestr,PL_minus_p |
2655 | ? ";}continue{print;}" : ";}"); | |
7e28d3af JH |
2656 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
2657 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2658 | PL_last_lop = PL_last_uni = Nullch; |
7e28d3af JH |
2659 | PL_minus_n = PL_minus_p = 0; |
2660 | goto retry; | |
2661 | } | |
2662 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); | |
207e3d1a | 2663 | PL_last_lop = PL_last_uni = Nullch; |
7e28d3af JH |
2664 | sv_setpv(PL_linestr,""); |
2665 | TOKEN(';'); /* not infinite loop because rsfp is NULL now */ | |
2666 | } | |
7aa207d6 JH |
2667 | /* If it looks like the start of a BOM or raw UTF-16, |
2668 | * check if it in fact is. */ | |
2669 | else if (bof && | |
2670 | (*s == 0 || | |
2671 | *(U8*)s == 0xEF || | |
2672 | *(U8*)s >= 0xFE || | |
2673 | s[1] == 0)) { | |
226017aa | 2674 | #ifdef PERLIO_IS_STDIO |
e3f494f1 JH |
2675 | # ifdef __GNU_LIBRARY__ |
2676 | # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */ | |
226017aa DD |
2677 | # define FTELL_FOR_PIPE_IS_BROKEN |
2678 | # endif | |
e3f494f1 JH |
2679 | # else |
2680 | # ifdef __GLIBC__ | |
2681 | # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */ | |
2682 | # define FTELL_FOR_PIPE_IS_BROKEN | |
2683 | # endif | |
2684 | # endif | |
226017aa DD |
2685 | # endif |
2686 | #endif | |
2687 | #ifdef FTELL_FOR_PIPE_IS_BROKEN | |
2688 | /* This loses the possibility to detect the bof | |
2689 | * situation on perl -P when the libc5 is being used. | |
2690 | * Workaround? Maybe attach some extra state to PL_rsfp? | |
2691 | */ | |
2692 | if (!PL_preprocess) | |
7e28d3af | 2693 | bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr); |
226017aa | 2694 | #else |
eb160463 | 2695 | bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr); |
226017aa | 2696 | #endif |
7e28d3af | 2697 | if (bof) { |
3280af22 | 2698 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
7e28d3af | 2699 | s = swallow_bom((U8*)s); |
e929a76b | 2700 | } |
378cc40b | 2701 | } |
3280af22 | 2702 | if (PL_doextract) { |
a0d0e21e LW |
2703 | /* Incest with pod. */ |
2704 | if (*s == '=' && strnEQ(s, "=cut", 4)) { | |
3280af22 NIS |
2705 | sv_setpv(PL_linestr, ""); |
2706 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); | |
2707 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2708 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 2709 | PL_doextract = FALSE; |
a0d0e21e | 2710 | } |
4e553d73 | 2711 | } |
463ee0b2 | 2712 | incline(s); |
3280af22 NIS |
2713 | } while (PL_doextract); |
2714 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s; | |
2715 | if (PERLDB_LINE && PL_curstash != PL_debstash) { | |
79072805 | 2716 | SV *sv = NEWSV(85,0); |
a687059c | 2717 | |
93a17b20 | 2718 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 2719 | sv_setsv(sv,PL_linestr); |
0ac0412a MJD |
2720 | (void)SvIOK_on(sv); |
2721 | SvIVX(sv) = 0; | |
57843af0 | 2722 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
a687059c | 2723 | } |
3280af22 | 2724 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 2725 | PL_last_lop = PL_last_uni = Nullch; |
57843af0 | 2726 | if (CopLINE(PL_curcop) == 1) { |
3280af22 | 2727 | while (s < PL_bufend && isSPACE(*s)) |
79072805 | 2728 | s++; |
a0d0e21e | 2729 | if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */ |
79072805 | 2730 | s++; |
44a8e56a | 2731 | d = Nullch; |
3280af22 | 2732 | if (!PL_in_eval) { |
44a8e56a | 2733 | if (*s == '#' && *(s+1) == '!') |
2734 | d = s + 2; | |
2735 | #ifdef ALTERNATE_SHEBANG | |
2736 | else { | |
bfed75c6 | 2737 | static char const as[] = ALTERNATE_SHEBANG; |
44a8e56a | 2738 | if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1)) |
2739 | d = s + (sizeof(as) - 1); | |
2740 | } | |
2741 | #endif /* ALTERNATE_SHEBANG */ | |
2742 | } | |
2743 | if (d) { | |
b8378b72 | 2744 | char *ipath; |
774d564b | 2745 | char *ipathend; |
b8378b72 | 2746 | |
774d564b | 2747 | while (isSPACE(*d)) |
b8378b72 CS |
2748 | d++; |
2749 | ipath = d; | |
774d564b | 2750 | while (*d && !isSPACE(*d)) |
2751 | d++; | |
2752 | ipathend = d; | |
2753 | ||
2754 | #ifdef ARG_ZERO_IS_SCRIPT | |
2755 | if (ipathend > ipath) { | |
2756 | /* | |
2757 | * HP-UX (at least) sets argv[0] to the script name, | |
2758 | * which makes $^X incorrect. And Digital UNIX and Linux, | |
2759 | * at least, set argv[0] to the basename of the Perl | |
2760 | * interpreter. So, having found "#!", we'll set it right. | |
2761 | */ | |
ee2f7564 | 2762 | SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV)); /* $^X */ |
774d564b | 2763 | assert(SvPOK(x) || SvGMAGICAL(x)); |
cc49e20b | 2764 | if (sv_eq(x, CopFILESV(PL_curcop))) { |
774d564b | 2765 | sv_setpvn(x, ipath, ipathend - ipath); |
9607fc9c | 2766 | SvSETMAGIC(x); |
2767 | } | |
556c1dec JH |
2768 | else { |
2769 | STRLEN blen; | |
2770 | STRLEN llen; | |
2771 | char *bstart = SvPV(CopFILESV(PL_curcop),blen); | |
2772 | char *lstart = SvPV(x,llen); | |
2773 | if (llen < blen) { | |
2774 | bstart += blen - llen; | |
2775 | if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') { | |
2776 | sv_setpvn(x, ipath, ipathend - ipath); | |
2777 | SvSETMAGIC(x); | |
2778 | } | |
2779 | } | |
2780 | } | |
774d564b | 2781 | TAINT_NOT; /* $^X is always tainted, but that's OK */ |
8ebc5c01 | 2782 | } |
774d564b | 2783 | #endif /* ARG_ZERO_IS_SCRIPT */ |
b8378b72 CS |
2784 | |
2785 | /* | |
2786 | * Look for options. | |
2787 | */ | |
748a9306 | 2788 | d = instr(s,"perl -"); |
84e30d1a | 2789 | if (!d) { |
748a9306 | 2790 | d = instr(s,"perl"); |
84e30d1a GS |
2791 | #if defined(DOSISH) |
2792 | /* avoid getting into infinite loops when shebang | |
2793 | * line contains "Perl" rather than "perl" */ | |
2794 | if (!d) { | |
2795 | for (d = ipathend-4; d >= ipath; --d) { | |
2796 | if ((*d == 'p' || *d == 'P') | |
2797 | && !ibcmp(d, "perl", 4)) | |
2798 | { | |
2799 | break; | |
2800 | } | |
2801 | } | |
2802 | if (d < ipath) | |
2803 | d = Nullch; | |
2804 | } | |
2805 | #endif | |
2806 | } | |
44a8e56a | 2807 | #ifdef ALTERNATE_SHEBANG |
2808 | /* | |
2809 | * If the ALTERNATE_SHEBANG on this system starts with a | |
2810 | * character that can be part of a Perl expression, then if | |
2811 | * we see it but not "perl", we're probably looking at the | |
2812 | * start of Perl code, not a request to hand off to some | |
2813 | * other interpreter. Similarly, if "perl" is there, but | |
2814 | * not in the first 'word' of the line, we assume the line | |
2815 | * contains the start of the Perl program. | |
44a8e56a | 2816 | */ |
2817 | if (d && *s != '#') { | |
774d564b | 2818 | char *c = ipath; |
44a8e56a | 2819 | while (*c && !strchr("; \t\r\n\f\v#", *c)) |
2820 | c++; | |
2821 | if (c < d) | |
2822 | d = Nullch; /* "perl" not in first word; ignore */ | |
2823 | else | |
2824 | *s = '#'; /* Don't try to parse shebang line */ | |
2825 | } | |
774d564b | 2826 | #endif /* ALTERNATE_SHEBANG */ |
bf4acbe4 | 2827 | #ifndef MACOS_TRADITIONAL |
748a9306 | 2828 | if (!d && |
44a8e56a | 2829 | *s == '#' && |
774d564b | 2830 | ipathend > ipath && |
3280af22 | 2831 | !PL_minus_c && |
748a9306 | 2832 | !instr(s,"indir") && |
3280af22 | 2833 | instr(PL_origargv[0],"perl")) |
748a9306 | 2834 | { |
9f68db38 | 2835 | char **newargv; |
9f68db38 | 2836 | |
774d564b | 2837 | *ipathend = '\0'; |
2838 | s = ipathend + 1; | |
3280af22 | 2839 | while (s < PL_bufend && isSPACE(*s)) |
9f68db38 | 2840 | s++; |
3280af22 NIS |
2841 | if (s < PL_bufend) { |
2842 | Newz(899,newargv,PL_origargc+3,char*); | |
9f68db38 | 2843 | newargv[1] = s; |
3280af22 | 2844 | while (s < PL_bufend && !isSPACE(*s)) |
9f68db38 LW |
2845 | s++; |
2846 | *s = '\0'; | |
3280af22 | 2847 | Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*); |
9f68db38 LW |
2848 | } |
2849 | else | |
3280af22 | 2850 | newargv = PL_origargv; |
774d564b | 2851 | newargv[0] = ipath; |
b35112e7 | 2852 | PERL_FPU_PRE_EXEC |
b4748376 | 2853 | PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv)); |
b35112e7 | 2854 | PERL_FPU_POST_EXEC |
cea2e8a9 | 2855 | Perl_croak(aTHX_ "Can't exec %s", ipath); |
9f68db38 | 2856 | } |
bf4acbe4 | 2857 | #endif |
748a9306 | 2858 | if (d) { |
3280af22 NIS |
2859 | U32 oldpdb = PL_perldb; |
2860 | bool oldn = PL_minus_n; | |
2861 | bool oldp = PL_minus_p; | |
748a9306 LW |
2862 | |
2863 | while (*d && !isSPACE(*d)) d++; | |
bf4acbe4 | 2864 | while (SPACE_OR_TAB(*d)) d++; |
748a9306 LW |
2865 | |
2866 | if (*d++ == '-') { | |
a11ec5a9 | 2867 | bool switches_done = PL_doswitches; |
8cc95fdb | 2868 | do { |
3ffe3ee4 | 2869 | if (*d == 'M' || *d == 'm' || *d == 'C') { |
8cc95fdb | 2870 | char *m = d; |
2871 | while (*d && !isSPACE(*d)) d++; | |
cea2e8a9 | 2872 | Perl_croak(aTHX_ "Too late for \"-%.*s\" option", |
8cc95fdb | 2873 | (int)(d - m), m); |
2874 | } | |
2875 | d = moreswitches(d); | |
2876 | } while (d); | |
f0b2cf55 YST |
2877 | if (PL_doswitches && !switches_done) { |
2878 | int argc = PL_origargc; | |
2879 | char **argv = PL_origargv; | |
2880 | do { | |
2881 | argc--,argv++; | |
2882 | } while (argc && argv[0][0] == '-' && argv[0][1]); | |
2883 | init_argv_symbols(argc,argv); | |
2884 | } | |
155aba94 GS |
2885 | if ((PERLDB_LINE && !oldpdb) || |
2886 | ((PL_minus_n || PL_minus_p) && !(oldn || oldp))) | |
b084f20b | 2887 | /* if we have already added "LINE: while (<>) {", |
2888 | we must not do it again */ | |
748a9306 | 2889 | { |
3280af22 NIS |
2890 | sv_setpv(PL_linestr, ""); |
2891 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); | |
2892 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 2893 | PL_last_lop = PL_last_uni = Nullch; |
3280af22 | 2894 | PL_preambled = FALSE; |
84902520 | 2895 | if (PERLDB_LINE) |
3280af22 | 2896 | (void)gv_fetchfile(PL_origfilename); |
748a9306 LW |
2897 | goto retry; |
2898 | } | |
a11ec5a9 RGS |
2899 | if (PL_doswitches && !switches_done) { |
2900 | int argc = PL_origargc; | |
2901 | char **argv = PL_origargv; | |
2902 | do { | |
2903 | argc--,argv++; | |
2904 | } while (argc && argv[0][0] == '-' && argv[0][1]); | |
2905 | init_argv_symbols(argc,argv); | |
2906 | } | |
a0d0e21e | 2907 | } |
79072805 | 2908 | } |
9f68db38 | 2909 | } |
79072805 | 2910 | } |
3280af22 NIS |
2911 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
2912 | PL_bufptr = s; | |
2913 | PL_lex_state = LEX_FORMLINE; | |
cea2e8a9 | 2914 | return yylex(); |
ae986130 | 2915 | } |
378cc40b | 2916 | goto retry; |
4fdae800 | 2917 | case '\r': |
6a27c188 | 2918 | #ifdef PERL_STRICT_CR |
cea2e8a9 | 2919 | Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r'); |
4e553d73 | 2920 | Perl_croak(aTHX_ |
cc507455 | 2921 | "\t(Maybe you didn't strip carriage returns after a network transfer?)\n"); |
a868473f | 2922 | #endif |
4fdae800 | 2923 | case ' ': case '\t': case '\f': case 013: |
bf4acbe4 GS |
2924 | #ifdef MACOS_TRADITIONAL |
2925 | case '\312': | |
2926 | #endif | |
378cc40b LW |
2927 | s++; |
2928 | goto retry; | |
378cc40b | 2929 | case '#': |
e929a76b | 2930 | case '\n': |
3280af22 | 2931 | if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) { |
df0deb90 GS |
2932 | if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) { |
2933 | /* handle eval qq[#line 1 "foo"\n ...] */ | |
2934 | CopLINE_dec(PL_curcop); | |
2935 | incline(s); | |
2936 | } | |
3280af22 | 2937 | d = PL_bufend; |
a687059c | 2938 | while (s < d && *s != '\n') |
378cc40b | 2939 | s++; |
0f85fab0 | 2940 | if (s < d) |
378cc40b | 2941 | s++; |
78c267c1 | 2942 | else if (s > d) /* Found by Ilya: feed random input to Perl. */ |
a8406387 | 2943 | Perl_croak(aTHX_ "panic: input overflow"); |
463ee0b2 | 2944 | incline(s); |
3280af22 NIS |
2945 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
2946 | PL_bufptr = s; | |
2947 | PL_lex_state = LEX_FORMLINE; | |
cea2e8a9 | 2948 | return yylex(); |
a687059c | 2949 | } |
378cc40b | 2950 | } |
a687059c | 2951 | else { |
378cc40b | 2952 | *s = '\0'; |
3280af22 | 2953 | PL_bufend = s; |
a687059c | 2954 | } |
378cc40b LW |
2955 | goto retry; |
2956 | case '-': | |
79072805 | 2957 | if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) { |
e5edeb50 JH |
2958 | I32 ftst = 0; |
2959 | ||
378cc40b | 2960 | s++; |
3280af22 | 2961 | PL_bufptr = s; |
748a9306 LW |
2962 | tmp = *s++; |
2963 | ||
bf4acbe4 | 2964 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
748a9306 LW |
2965 | s++; |
2966 | ||
2967 | if (strnEQ(s,"=>",2)) { | |
3280af22 | 2968 | s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE); |
4e553d73 | 2969 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
607df283 | 2970 | "### Saw unary minus before =>, forcing word '%s'\n", s); |
5f80b19c | 2971 | } ); |
748a9306 LW |
2972 | OPERATOR('-'); /* unary minus */ |
2973 | } | |
3280af22 | 2974 | PL_last_uni = PL_oldbufptr; |
748a9306 | 2975 | switch (tmp) { |
e5edeb50 JH |
2976 | case 'r': ftst = OP_FTEREAD; break; |
2977 | case 'w': ftst = OP_FTEWRITE; break; | |
2978 | case 'x': ftst = OP_FTEEXEC; break; | |
2979 | case 'o': ftst = OP_FTEOWNED; break; | |
2980 | case 'R': ftst = OP_FTRREAD; break; | |
2981 | case 'W': ftst = OP_FTRWRITE; break; | |
2982 | case 'X': ftst = OP_FTREXEC; break; | |
2983 | case 'O': ftst = OP_FTROWNED; break; | |
2984 | case 'e': ftst = OP_FTIS; break; | |
2985 | case 'z': ftst = OP_FTZERO; break; | |
2986 | case 's': ftst = OP_FTSIZE; break; | |
2987 | case 'f': ftst = OP_FTFILE; break; | |
2988 | case 'd': ftst = OP_FTDIR; break; | |
2989 | case 'l': ftst = OP_FTLINK; break; | |
2990 | case 'p': ftst = OP_FTPIPE; break; | |
2991 | case 'S': ftst = OP_FTSOCK; break; | |
2992 | case 'u': ftst = OP_FTSUID; break; | |
2993 | case 'g': ftst = OP_FTSGID; break; | |
2994 | case 'k': ftst = OP_FTSVTX; break; | |
2995 | case 'b': ftst = OP_FTBLK; break; | |
2996 | case 'c': ftst = OP_FTCHR; break; | |
2997 | case 't': ftst = OP_FTTTY; break; | |
2998 | case 'T': ftst = OP_FTTEXT; break; | |
2999 | case 'B': ftst = OP_FTBINARY; break; | |
3000 | case 'M': case 'A': case 'C': | |
3001 | gv_fetchpv("\024",TRUE, SVt_PV); | |
3002 | switch (tmp) { | |
3003 | case 'M': ftst = OP_FTMTIME; break; | |
3004 | case 'A': ftst = OP_FTATIME; break; | |
3005 | case 'C': ftst = OP_FTCTIME; break; | |
3006 | default: break; | |
3007 | } | |
3008 | break; | |
378cc40b | 3009 | default: |
378cc40b LW |
3010 | break; |
3011 | } | |
e5edeb50 | 3012 | if (ftst) { |
eb160463 | 3013 | PL_last_lop_op = (OPCODE)ftst; |
4e553d73 | 3014 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
0844c848 | 3015 | "### Saw file test %c\n", (int)ftst); |
5f80b19c | 3016 | } ); |
e5edeb50 JH |
3017 | FTST(ftst); |
3018 | } | |
3019 | else { | |
3020 | /* Assume it was a minus followed by a one-letter named | |
3021 | * subroutine call (or a -bareword), then. */ | |
95c31fe3 | 3022 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
17ad61e0 | 3023 | "### '-%c' looked like a file test but was not\n", |
4fccd7c6 | 3024 | (int) tmp); |
5f80b19c | 3025 | } ); |
3cf7b4c4 | 3026 | s = --PL_bufptr; |
e5edeb50 | 3027 | } |
378cc40b | 3028 | } |
a687059c LW |
3029 | tmp = *s++; |
3030 | if (*s == tmp) { | |
3031 | s++; | |
3280af22 | 3032 | if (PL_expect == XOPERATOR) |
79072805 LW |
3033 | TERM(POSTDEC); |
3034 | else | |
3035 | OPERATOR(PREDEC); | |
3036 | } | |
3037 | else if (*s == '>') { | |
3038 | s++; | |
3039 | s = skipspace(s); | |
7e2040f0 | 3040 | if (isIDFIRST_lazy_if(s,UTF)) { |
a0d0e21e | 3041 | s = force_word(s,METHOD,FALSE,TRUE,FALSE); |
463ee0b2 | 3042 | TOKEN(ARROW); |
79072805 | 3043 | } |
748a9306 LW |
3044 | else if (*s == '$') |
3045 | OPERATOR(ARROW); | |
463ee0b2 | 3046 | else |
748a9306 | 3047 | TERM(ARROW); |
a687059c | 3048 | } |
3280af22 | 3049 | if (PL_expect == XOPERATOR) |
79072805 LW |
3050 | Aop(OP_SUBTRACT); |
3051 | else { | |
3280af22 | 3052 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) |
2f3197b3 | 3053 | check_uni(); |
79072805 | 3054 | OPERATOR('-'); /* unary minus */ |
2f3197b3 | 3055 | } |
79072805 | 3056 | |
378cc40b | 3057 | case '+': |
a687059c LW |
3058 | tmp = *s++; |
3059 | if (*s == tmp) { | |
378cc40b | 3060 | s++; |
3280af22 | 3061 | if (PL_expect == XOPERATOR) |
79072805 LW |
3062 | TERM(POSTINC); |
3063 | else | |
3064 | OPERATOR(PREINC); | |
378cc40b | 3065 | } |
3280af22 | 3066 | if (PL_expect == XOPERATOR) |
79072805 LW |
3067 | Aop(OP_ADD); |
3068 | else { | |
3280af22 | 3069 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) |
2f3197b3 | 3070 | check_uni(); |
a687059c | 3071 | OPERATOR('+'); |
2f3197b3 | 3072 | } |
a687059c | 3073 | |
378cc40b | 3074 | case '*': |
3280af22 NIS |
3075 | if (PL_expect != XOPERATOR) { |
3076 | s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); | |
3077 | PL_expect = XOPERATOR; | |
3078 | force_ident(PL_tokenbuf, '*'); | |
3079 | if (!*PL_tokenbuf) | |
a0d0e21e | 3080 | PREREF('*'); |
79072805 | 3081 | TERM('*'); |
a687059c | 3082 | } |
79072805 LW |
3083 | s++; |
3084 | if (*s == '*') { | |
a687059c | 3085 | s++; |
79072805 | 3086 | PWop(OP_POW); |
a687059c | 3087 | } |
79072805 LW |
3088 | Mop(OP_MULTIPLY); |
3089 | ||
378cc40b | 3090 | case '%': |
3280af22 | 3091 | if (PL_expect == XOPERATOR) { |
bbce6d69 | 3092 | ++s; |
3093 | Mop(OP_MODULO); | |
a687059c | 3094 | } |
3280af22 NIS |
3095 | PL_tokenbuf[0] = '%'; |
3096 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE); | |
3097 | if (!PL_tokenbuf[1]) { | |
bbce6d69 | 3098 | PREREF('%'); |
a687059c | 3099 | } |
3280af22 | 3100 | PL_pending_ident = '%'; |
bbce6d69 | 3101 | TERM('%'); |
a687059c | 3102 | |
378cc40b | 3103 | case '^': |
79072805 | 3104 | s++; |
a0d0e21e | 3105 | BOop(OP_BIT_XOR); |
79072805 | 3106 | case '[': |
3280af22 | 3107 | PL_lex_brackets++; |
79072805 | 3108 | /* FALL THROUGH */ |
378cc40b | 3109 | case '~': |
378cc40b | 3110 | case ',': |
378cc40b LW |
3111 | tmp = *s++; |
3112 | OPERATOR(tmp); | |
a0d0e21e LW |
3113 | case ':': |
3114 | if (s[1] == ':') { | |
3115 | len = 0; | |
3116 | goto just_a_word; | |
3117 | } | |
3118 | s++; | |
09bef843 SB |
3119 | switch (PL_expect) { |
3120 | OP *attrs; | |
3121 | case XOPERATOR: | |
3122 | if (!PL_in_my || PL_lex_state != LEX_NORMAL) | |
3123 | break; | |
3124 | PL_bufptr = s; /* update in case we back off */ | |
3125 | goto grabattrs; | |
3126 | case XATTRBLOCK: | |
3127 | PL_expect = XBLOCK; | |
3128 | goto grabattrs; | |
3129 | case XATTRTERM: | |
3130 | PL_expect = XTERMBLOCK; | |
3131 | grabattrs: | |
3132 | s = skipspace(s); | |
3133 | attrs = Nullop; | |
7e2040f0 | 3134 | while (isIDFIRST_lazy_if(s,UTF)) { |
09bef843 | 3135 | d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
f9829d6b GS |
3136 | if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) { |
3137 | if (tmp < 0) tmp = -tmp; | |
3138 | switch (tmp) { | |
3139 | case KEY_or: | |
3140 | case KEY_and: | |
c963b151 | 3141 | case KEY_err: |
f9829d6b GS |
3142 | case KEY_for: |
3143 | case KEY_unless: | |
3144 | case KEY_if: | |
3145 | case KEY_while: | |
3146 | case KEY_until: | |
3147 | goto got_attrs; | |
3148 | default: | |
3149 | break; | |
3150 | } | |
3151 | } | |
09bef843 SB |
3152 | if (*d == '(') { |
3153 | d = scan_str(d,TRUE,TRUE); | |
3154 | if (!d) { | |
09bef843 SB |
3155 | /* MUST advance bufptr here to avoid bogus |
3156 | "at end of line" context messages from yyerror(). | |
3157 | */ | |
3158 | PL_bufptr = s + len; | |
3159 | yyerror("Unterminated attribute parameter in attribute list"); | |
3160 | if (attrs) | |
3161 | op_free(attrs); | |
bbf60fe6 | 3162 | return REPORT(0); /* EOF indicator */ |
09bef843 SB |
3163 | } |
3164 | } | |
3165 | if (PL_lex_stuff) { | |
3166 | SV *sv = newSVpvn(s, len); | |
3167 | sv_catsv(sv, PL_lex_stuff); | |
3168 | attrs = append_elem(OP_LIST, attrs, | |
3169 | newSVOP(OP_CONST, 0, sv)); | |
3170 | SvREFCNT_dec(PL_lex_stuff); | |
3171 | PL_lex_stuff = Nullsv; | |
3172 | } | |
3173 | else { | |
371fce9b DM |
3174 | if (len == 6 && strnEQ(s, "unique", len)) { |
3175 | if (PL_in_my == KEY_our) | |
3176 | #ifdef USE_ITHREADS | |
3177 | GvUNIQUE_on(cGVOPx_gv(yylval.opval)); | |
3178 | #else | |
3179 | ; /* skip to avoid loading attributes.pm */ | |
3180 | #endif | |
bfed75c6 | 3181 | else |
371fce9b DM |
3182 | Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables"); |
3183 | } | |
3184 | ||
d3cea301 SB |
3185 | /* NOTE: any CV attrs applied here need to be part of |
3186 | the CVf_BUILTIN_ATTRS define in cv.h! */ | |
371fce9b | 3187 | else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len)) |
78f9721b SM |
3188 | CvLVALUE_on(PL_compcv); |
3189 | else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len)) | |
3190 | CvLOCKED_on(PL_compcv); | |
3191 | else if (!PL_in_my && len == 6 && strnEQ(s, "method", len)) | |
3192 | CvMETHOD_on(PL_compcv); | |
06492da6 SF |
3193 | else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len)) |
3194 | CvASSERTION_on(PL_compcv); | |
78f9721b SM |
3195 | /* After we've set the flags, it could be argued that |
3196 | we don't need to do the attributes.pm-based setting | |
3197 | process, and shouldn't bother appending recognized | |
d3cea301 SB |
3198 | flags. To experiment with that, uncomment the |
3199 | following "else". (Note that's already been | |
3200 | uncommented. That keeps the above-applied built-in | |
3201 | attributes from being intercepted (and possibly | |
3202 | rejected) by a package's attribute routines, but is | |
3203 | justified by the performance win for the common case | |
3204 | of applying only built-in attributes.) */ | |
0256094b | 3205 | else |
78f9721b SM |
3206 | attrs = append_elem(OP_LIST, attrs, |
3207 | newSVOP(OP_CONST, 0, | |
3208 | newSVpvn(s, len))); | |
09bef843 SB |
3209 | } |
3210 | s = skipspace(d); | |
0120eecf | 3211 | if (*s == ':' && s[1] != ':') |
09bef843 | 3212 | s = skipspace(s+1); |
0120eecf GS |
3213 | else if (s == d) |
3214 | break; /* require real whitespace or :'s */ | |
09bef843 | 3215 | } |
f9829d6b | 3216 | tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */ |
8e7ae056 | 3217 | if (*s != ';' && *s != '}' && *s != tmp && (tmp != '=' || *s != ')')) { |
09bef843 SB |
3218 | char q = ((*s == '\'') ? '"' : '\''); |
3219 | /* If here for an expression, and parsed no attrs, back off. */ | |
3220 | if (tmp == '=' && !attrs) { | |
3221 | s = PL_bufptr; | |
3222 | break; | |
3223 | } | |
3224 | /* MUST advance bufptr here to avoid bogus "at end of line" | |
3225 | context messages from yyerror(). | |
3226 | */ | |
3227 | PL_bufptr = s; | |
3228 | if (!*s) | |
3229 | yyerror("Unterminated attribute list"); | |
3230 | else | |
3231 | yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list", | |
3232 | q, *s, q)); | |
3233 | if (attrs) | |
3234 | op_free(attrs); | |
3235 | OPERATOR(':'); | |
3236 | } | |
f9829d6b | 3237 | got_attrs: |
09bef843 SB |
3238 | if (attrs) { |
3239 | PL_nextval[PL_nexttoke].opval = attrs; | |
3240 | force_next(THING); | |
3241 | } | |
3242 | TOKEN(COLONATTR); | |
3243 | } | |
a0d0e21e | 3244 | OPERATOR(':'); |
8990e307 LW |
3245 | case '(': |
3246 | s++; | |
3280af22 NIS |
3247 | if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr) |
3248 | PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */ | |
a0d0e21e | 3249 | else |
3280af22 | 3250 | PL_expect = XTERM; |
4a202259 | 3251 | s = skipspace(s); |
a0d0e21e | 3252 | TOKEN('('); |
378cc40b | 3253 | case ';': |
f4dd75d9 | 3254 | CLINE; |
378cc40b LW |
3255 | tmp = *s++; |
3256 | OPERATOR(tmp); | |
3257 | case ')': | |
378cc40b | 3258 | tmp = *s++; |
16d20bd9 AD |
3259 | s = skipspace(s); |
3260 | if (*s == '{') | |
3261 | PREBLOCK(tmp); | |
378cc40b | 3262 | TERM(tmp); |
79072805 LW |
3263 | case ']': |
3264 | s++; | |
3280af22 | 3265 | if (PL_lex_brackets <= 0) |
d98d5fff | 3266 | yyerror("Unmatched right square bracket"); |
463ee0b2 | 3267 | else |
3280af22 NIS |
3268 | --PL_lex_brackets; |
3269 | if (PL_lex_state == LEX_INTERPNORMAL) { | |
3270 | if (PL_lex_brackets == 0) { | |
a0d0e21e | 3271 | if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>')) |
3280af22 | 3272 | PL_lex_state = LEX_INTERPEND; |
79072805 LW |
3273 | } |
3274 | } | |
4633a7c4 | 3275 | TERM(']'); |
79072805 LW |
3276 | case '{': |
3277 | leftbracket: | |
79072805 | 3278 | s++; |
3280af22 | 3279 | if (PL_lex_brackets > 100) { |
8edd5f42 | 3280 | Renew(PL_lex_brackstack, PL_lex_brackets + 10, char); |
8990e307 | 3281 | } |
3280af22 | 3282 | switch (PL_expect) { |
a0d0e21e | 3283 | case XTERM: |
3280af22 | 3284 | if (PL_lex_formbrack) { |
a0d0e21e LW |
3285 | s--; |
3286 | PRETERMBLOCK(DO); | |
3287 | } | |
3280af22 NIS |
3288 | if (PL_oldoldbufptr == PL_last_lop) |
3289 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; | |
a0d0e21e | 3290 | else |
3280af22 | 3291 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
79072805 | 3292 | OPERATOR(HASHBRACK); |
a0d0e21e | 3293 | case XOPERATOR: |
bf4acbe4 | 3294 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
748a9306 | 3295 | s++; |
44a8e56a | 3296 | d = s; |
3280af22 NIS |
3297 | PL_tokenbuf[0] = '\0'; |
3298 | if (d < PL_bufend && *d == '-') { | |
3299 | PL_tokenbuf[0] = '-'; | |
44a8e56a | 3300 | d++; |
bf4acbe4 | 3301 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
44a8e56a | 3302 | d++; |
3303 | } | |
7e2040f0 | 3304 | if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) { |
3280af22 | 3305 | d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, |
8903cb82 | 3306 | FALSE, &len); |
bf4acbe4 | 3307 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
748a9306 LW |
3308 | d++; |
3309 | if (*d == '}') { | |
3280af22 | 3310 | char minus = (PL_tokenbuf[0] == '-'); |
44a8e56a | 3311 | s = force_word(s + minus, WORD, FALSE, TRUE, FALSE); |
3312 | if (minus) | |
3313 | force_next('-'); | |
748a9306 LW |
3314 | } |
3315 | } | |
3316 | /* FALL THROUGH */ | |
09bef843 | 3317 | case XATTRBLOCK: |
748a9306 | 3318 | case XBLOCK: |
3280af22 NIS |
3319 | PL_lex_brackstack[PL_lex_brackets++] = XSTATE; |
3320 | PL_expect = XSTATE; | |
a0d0e21e | 3321 | break; |
09bef843 | 3322 | case XATTRTERM: |
a0d0e21e | 3323 | case XTERMBLOCK: |
3280af22 NIS |
3324 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
3325 | PL_expect = XSTATE; | |
a0d0e21e LW |
3326 | break; |
3327 | default: { | |
3328 | char *t; | |
3280af22 NIS |
3329 | if (PL_oldoldbufptr == PL_last_lop) |
3330 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; | |
a0d0e21e | 3331 | else |
3280af22 | 3332 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
a0d0e21e | 3333 | s = skipspace(s); |
8452ff4b SB |
3334 | if (*s == '}') { |
3335 | if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) { | |
3336 | PL_expect = XTERM; | |
3337 | /* This hack is to get the ${} in the message. */ | |
3338 | PL_bufptr = s+1; | |
3339 | yyerror("syntax error"); | |
3340 | break; | |
3341 | } | |
a0d0e21e | 3342 | OPERATOR(HASHBRACK); |
8452ff4b | 3343 | } |
b8a4b1be GS |
3344 | /* This hack serves to disambiguate a pair of curlies |
3345 | * as being a block or an anon hash. Normally, expectation | |
3346 | * determines that, but in cases where we're not in a | |
3347 | * position to expect anything in particular (like inside | |
3348 | * eval"") we have to resolve the ambiguity. This code | |
3349 | * covers the case where the first term in the curlies is a | |
3350 | * quoted string. Most other cases need to be explicitly | |
3351 | * disambiguated by prepending a `+' before the opening | |
3352 | * curly in order to force resolution as an anon hash. | |
3353 | * | |
3354 | * XXX should probably propagate the outer expectation | |
3355 | * into eval"" to rely less on this hack, but that could | |
3356 | * potentially break current behavior of eval"". | |
3357 | * GSAR 97-07-21 | |
3358 | */ | |
3359 | t = s; | |
3360 | if (*s == '\'' || *s == '"' || *s == '`') { | |
3361 | /* common case: get past first string, handling escapes */ | |
3280af22 | 3362 | for (t++; t < PL_bufend && *t != *s;) |
b8a4b1be GS |
3363 | if (*t++ == '\\' && (*t == '\\' || *t == *s)) |
3364 | t++; | |
3365 | t++; | |
a0d0e21e | 3366 | } |
b8a4b1be | 3367 | else if (*s == 'q') { |
3280af22 | 3368 | if (++t < PL_bufend |
b8a4b1be | 3369 | && (!isALNUM(*t) |
3280af22 | 3370 | || ((*t == 'q' || *t == 'x') && ++t < PL_bufend |
0505442f GS |
3371 | && !isALNUM(*t)))) |
3372 | { | |
abc667d1 | 3373 | /* skip q//-like construct */ |
b8a4b1be GS |
3374 | char *tmps; |
3375 | char open, close, term; | |
3376 | I32 brackets = 1; | |
3377 | ||
3280af22 | 3378 | while (t < PL_bufend && isSPACE(*t)) |
b8a4b1be | 3379 | t++; |
abc667d1 DM |
3380 | /* check for q => */ |
3381 | if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') { | |
3382 | OPERATOR(HASHBRACK); | |
3383 | } | |
b8a4b1be GS |
3384 | term = *t; |
3385 | open = term; | |
3386 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) | |
3387 | term = tmps[5]; | |
3388 | close = term; | |
3389 | if (open == close) | |
3280af22 NIS |
3390 | for (t++; t < PL_bufend; t++) { |
3391 | if (*t == '\\' && t+1 < PL_bufend && open != '\\') | |
b8a4b1be | 3392 | t++; |
6d07e5e9 | 3393 | else if (*t == open) |
b8a4b1be GS |
3394 | break; |
3395 | } | |
abc667d1 | 3396 | else { |
3280af22 NIS |
3397 | for (t++; t < PL_bufend; t++) { |
3398 | if (*t == '\\' && t+1 < PL_bufend) | |
b8a4b1be | 3399 | t++; |
6d07e5e9 | 3400 | else if (*t == close && --brackets <= 0) |
b8a4b1be GS |
3401 | break; |
3402 | else if (*t == open) | |
3403 | brackets++; | |
3404 | } | |
abc667d1 DM |
3405 | } |
3406 | t++; | |
b8a4b1be | 3407 | } |
abc667d1 DM |
3408 | else |
3409 | /* skip plain q word */ | |
3410 | while (t < PL_bufend && isALNUM_lazy_if(t,UTF)) | |
3411 | t += UTF8SKIP(t); | |
a0d0e21e | 3412 | } |
7e2040f0 | 3413 | else if (isALNUM_lazy_if(t,UTF)) { |
0505442f | 3414 | t += UTF8SKIP(t); |
7e2040f0 | 3415 | while (t < PL_bufend && isALNUM_lazy_if(t,UTF)) |
0505442f | 3416 | t += UTF8SKIP(t); |
a0d0e21e | 3417 | } |
3280af22 | 3418 | while (t < PL_bufend && isSPACE(*t)) |
a0d0e21e | 3419 | t++; |
b8a4b1be GS |
3420 | /* if comma follows first term, call it an anon hash */ |
3421 | /* XXX it could be a comma expression with loop modifiers */ | |
3280af22 | 3422 | if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s))) |
b8a4b1be | 3423 | || (*t == '=' && t[1] == '>'))) |
a0d0e21e | 3424 | OPERATOR(HASHBRACK); |
3280af22 | 3425 | if (PL_expect == XREF) |
4e4e412b | 3426 | PL_expect = XTERM; |
a0d0e21e | 3427 | else { |
3280af22 NIS |
3428 | PL_lex_brackstack[PL_lex_brackets-1] = XSTATE; |
3429 | PL_expect = XSTATE; | |
a0d0e21e | 3430 | } |
8990e307 | 3431 | } |
a0d0e21e | 3432 | break; |
463ee0b2 | 3433 | } |
57843af0 | 3434 | yylval.ival = CopLINE(PL_curcop); |
79072805 | 3435 | if (isSPACE(*s) || *s == '#') |
3280af22 | 3436 | PL_copline = NOLINE; /* invalidate current command line number */ |
79072805 | 3437 | TOKEN('{'); |
378cc40b | 3438 | case '}': |
79072805 LW |
3439 | rightbracket: |
3440 | s++; | |
3280af22 | 3441 | if (PL_lex_brackets <= 0) |
d98d5fff | 3442 | yyerror("Unmatched right curly bracket"); |
463ee0b2 | 3443 | else |
3280af22 | 3444 | PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets]; |
c2e66d9e | 3445 | if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL) |
3280af22 NIS |
3446 | PL_lex_formbrack = 0; |
3447 | if (PL_lex_state == LEX_INTERPNORMAL) { | |
3448 | if (PL_lex_brackets == 0) { | |
9059aa12 LW |
3449 | if (PL_expect & XFAKEBRACK) { |
3450 | PL_expect &= XENUMMASK; | |
3280af22 NIS |
3451 | PL_lex_state = LEX_INTERPEND; |
3452 | PL_bufptr = s; | |
cea2e8a9 | 3453 | return yylex(); /* ignore fake brackets */ |
79072805 | 3454 | } |
fa83b5b6 | 3455 | if (*s == '-' && s[1] == '>') |
3280af22 | 3456 | PL_lex_state = LEX_INTERPENDMAYBE; |
fa83b5b6 | 3457 | else if (*s != '[' && *s != '{') |
3280af22 | 3458 | PL_lex_state = LEX_INTERPEND; |
79072805 LW |
3459 | } |
3460 | } | |
9059aa12 LW |
3461 | if (PL_expect & XFAKEBRACK) { |
3462 | PL_expect &= XENUMMASK; | |
3280af22 | 3463 | PL_bufptr = s; |
cea2e8a9 | 3464 | return yylex(); /* ignore fake brackets */ |
748a9306 | 3465 | } |
79072805 LW |
3466 | force_next('}'); |
3467 | TOKEN(';'); | |
378cc40b LW |
3468 | case '&': |
3469 | s++; | |
3470 | tmp = *s++; | |
3471 | if (tmp == '&') | |
a0d0e21e | 3472 | AOPERATOR(ANDAND); |
378cc40b | 3473 | s--; |
3280af22 | 3474 | if (PL_expect == XOPERATOR) { |
7e2040f0 GS |
3475 | if (ckWARN(WARN_SEMICOLON) |
3476 | && isIDFIRST_lazy_if(s,UTF) && PL_bufptr == PL_linestart) | |
3477 | { | |
57843af0 | 3478 | CopLINE_dec(PL_curcop); |
9014280d | 3479 | Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi); |
57843af0 | 3480 | CopLINE_inc(PL_curcop); |
463ee0b2 | 3481 | } |
79072805 | 3482 | BAop(OP_BIT_AND); |
463ee0b2 | 3483 | } |
79072805 | 3484 | |
3280af22 NIS |
3485 | s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); |
3486 | if (*PL_tokenbuf) { | |
3487 | PL_expect = XOPERATOR; | |
3488 | force_ident(PL_tokenbuf, '&'); | |
463ee0b2 | 3489 | } |
79072805 LW |
3490 | else |
3491 | PREREF('&'); | |
c07a80fd | 3492 | yylval.ival = (OPpENTERSUB_AMPER<<8); |
79072805 LW |
3493 | TERM('&'); |
3494 | ||
378cc40b LW |
3495 | case '|': |
3496 | s++; | |
3497 | tmp = *s++; | |
3498 | if (tmp == '|') | |
a0d0e21e | 3499 | AOPERATOR(OROR); |
378cc40b | 3500 | s--; |
79072805 | 3501 | BOop(OP_BIT_OR); |
378cc40b LW |
3502 | case '=': |
3503 | s++; | |
3504 | tmp = *s++; | |
3505 | if (tmp == '=') | |
79072805 LW |
3506 | Eop(OP_EQ); |
3507 | if (tmp == '>') | |
3508 | OPERATOR(','); | |
378cc40b | 3509 | if (tmp == '~') |
79072805 | 3510 | PMop(OP_MATCH); |
599cee73 | 3511 | if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp)) |
9014280d | 3512 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Reversed %c= operator",(int)tmp); |
378cc40b | 3513 | s--; |
3280af22 NIS |
3514 | if (PL_expect == XSTATE && isALPHA(tmp) && |
3515 | (s == PL_linestart+1 || s[-2] == '\n') ) | |
748a9306 | 3516 | { |
3280af22 NIS |
3517 | if (PL_in_eval && !PL_rsfp) { |
3518 | d = PL_bufend; | |
a5f75d66 AD |
3519 | while (s < d) { |
3520 | if (*s++ == '\n') { | |
3521 | incline(s); | |
3522 | if (strnEQ(s,"=cut",4)) { | |
3523 | s = strchr(s,'\n'); | |
3524 | if (s) | |
3525 | s++; | |
3526 | else | |
3527 | s = d; | |
3528 | incline(s); | |
3529 | goto retry; | |
3530 | } | |
3531 | } | |
3532 | } | |
3533 | goto retry; | |
3534 | } | |
3280af22 NIS |
3535 | s = PL_bufend; |
3536 | PL_doextract = TRUE; | |
a0d0e21e LW |
3537 | goto retry; |
3538 | } | |
3280af22 | 3539 | if (PL_lex_brackets < PL_lex_formbrack) { |
a0d0e21e | 3540 | char *t; |
51882d45 | 3541 | #ifdef PERL_STRICT_CR |
bf4acbe4 | 3542 | for (t = s; SPACE_OR_TAB(*t); t++) ; |
51882d45 | 3543 | #else |
bf4acbe4 | 3544 | for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ; |
51882d45 | 3545 | #endif |
a0d0e21e LW |
3546 | if (*t == '\n' || *t == '#') { |
3547 | s--; | |
3280af22 | 3548 | PL_expect = XBLOCK; |
a0d0e21e LW |
3549 | goto leftbracket; |
3550 | } | |
79072805 | 3551 | } |
a0d0e21e LW |
3552 | yylval.ival = 0; |
3553 | OPERATOR(ASSIGNOP); | |
378cc40b LW |
3554 | case '!': |
3555 | s++; | |
3556 | tmp = *s++; | |
984200d0 | 3557 | if (tmp == '=') { |
decca21c YST |
3558 | /* was this !=~ where !~ was meant? |
3559 | * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */ | |
3560 | ||
984200d0 YST |
3561 | if (*s == '~' && ckWARN(WARN_SYNTAX)) { |
3562 | char *t = s+1; | |
3563 | ||
3564 | while (t < PL_bufend && isSPACE(*t)) | |
3565 | ++t; | |
3566 | ||
decca21c YST |
3567 | if (*t == '/' || *t == '?' || |
3568 | ((*t == 'm' || *t == 's' || *t == 'y') && !isALNUM(t[1])) || | |
3569 | (*t == 't' && t[1] == 'r' && !isALNUM(t[2]))) | |
984200d0 YST |
3570 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
3571 | "!=~ should be !~"); | |
3572 | } | |
79072805 | 3573 | Eop(OP_NE); |
984200d0 | 3574 | } |
378cc40b | 3575 | if (tmp == '~') |
79072805 | 3576 | PMop(OP_NOT); |
378cc40b LW |
3577 | s--; |
3578 | OPERATOR('!'); | |
3579 | case '<': | |
3280af22 | 3580 | if (PL_expect != XOPERATOR) { |
93a17b20 | 3581 | if (s[1] != '<' && !strchr(s,'>')) |
2f3197b3 | 3582 | check_uni(); |
79072805 LW |
3583 | if (s[1] == '<') |
3584 | s = scan_heredoc(s); | |
3585 | else | |
3586 | s = scan_inputsymbol(s); | |
3587 | TERM(sublex_start()); | |
378cc40b LW |
3588 | } |
3589 | s++; | |
3590 | tmp = *s++; | |
3591 | if (tmp == '<') | |
79072805 | 3592 | SHop(OP_LEFT_SHIFT); |
395c3793 LW |
3593 | if (tmp == '=') { |
3594 | tmp = *s++; | |
3595 | if (tmp == '>') | |
79072805 | 3596 | Eop(OP_NCMP); |
395c3793 | 3597 | s--; |
79072805 | 3598 | Rop(OP_LE); |
395c3793 | 3599 | } |
378cc40b | 3600 | s--; |
79072805 | 3601 | Rop(OP_LT); |
378cc40b LW |
3602 | case '>': |
3603 | s++; | |
3604 | tmp = *s++; | |
3605 | if (tmp == '>') | |
79072805 | 3606 | SHop(OP_RIGHT_SHIFT); |
378cc40b | 3607 | if (tmp == '=') |
79072805 | 3608 | Rop(OP_GE); |
378cc40b | 3609 | s--; |
79072805 | 3610 | Rop(OP_GT); |
378cc40b LW |
3611 | |
3612 | case '$': | |
bbce6d69 | 3613 | CLINE; |
3614 | ||
3280af22 NIS |
3615 | if (PL_expect == XOPERATOR) { |
3616 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3617 | PL_expect = XTERM; | |
a0d0e21e | 3618 | depcom(); |
bbf60fe6 | 3619 | return REPORT(','); /* grandfather non-comma-format format */ |
a0d0e21e | 3620 | } |
8990e307 | 3621 | } |
a0d0e21e | 3622 | |
7e2040f0 | 3623 | if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) { |
3280af22 | 3624 | PL_tokenbuf[0] = '@'; |
376b8730 SM |
3625 | s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1, |
3626 | sizeof PL_tokenbuf - 1, FALSE); | |
3627 | if (PL_expect == XOPERATOR) | |
3628 | no_op("Array length", s); | |
3280af22 | 3629 | if (!PL_tokenbuf[1]) |
a0d0e21e | 3630 | PREREF(DOLSHARP); |
3280af22 NIS |
3631 | PL_expect = XOPERATOR; |
3632 | PL_pending_ident = '#'; | |
463ee0b2 | 3633 | TOKEN(DOLSHARP); |
79072805 | 3634 | } |
bbce6d69 | 3635 | |
3280af22 | 3636 | PL_tokenbuf[0] = '$'; |
376b8730 SM |
3637 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, |
3638 | sizeof PL_tokenbuf - 1, FALSE); | |
3639 | if (PL_expect == XOPERATOR) | |
3640 | no_op("Scalar", s); | |
3280af22 NIS |
3641 | if (!PL_tokenbuf[1]) { |
3642 | if (s == PL_bufend) | |
bbce6d69 | 3643 | yyerror("Final $ should be \\$ or $name"); |
3644 | PREREF('$'); | |
8990e307 | 3645 | } |
a0d0e21e | 3646 | |
bbce6d69 | 3647 | /* This kludge not intended to be bulletproof. */ |
3280af22 | 3648 | if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) { |
bbce6d69 | 3649 | yylval.opval = newSVOP(OP_CONST, 0, |
b448e4fe | 3650 | newSViv(PL_compiling.cop_arybase)); |
bbce6d69 | 3651 | yylval.opval->op_private = OPpCONST_ARYBASE; |
3652 | TERM(THING); | |
3653 | } | |
3654 | ||
ff68c719 | 3655 | d = s; |
69d2bceb | 3656 | tmp = (I32)*s; |
3280af22 | 3657 | if (PL_lex_state == LEX_NORMAL) |
ff68c719 | 3658 | s = skipspace(s); |
3659 | ||
3280af22 | 3660 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) { |
bbce6d69 | 3661 | char *t; |
3662 | if (*s == '[') { | |
3280af22 | 3663 | PL_tokenbuf[0] = '@'; |
599cee73 | 3664 | if (ckWARN(WARN_SYNTAX)) { |
bbce6d69 | 3665 | for(t = s + 1; |
7e2040f0 | 3666 | isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$'; |
bbce6d69 | 3667 | t++) ; |
a0d0e21e | 3668 | if (*t++ == ',') { |
3280af22 NIS |
3669 | PL_bufptr = skipspace(PL_bufptr); |
3670 | while (t < PL_bufend && *t != ']') | |
bbce6d69 | 3671 | t++; |
9014280d | 3672 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
599cee73 PM |
3673 | "Multidimensional syntax %.*s not supported", |
3674 | (t - PL_bufptr) + 1, PL_bufptr); | |
a0d0e21e LW |
3675 | } |
3676 | } | |
bbce6d69 | 3677 | } |
3678 | else if (*s == '{') { | |
3280af22 | 3679 | PL_tokenbuf[0] = '%'; |
599cee73 | 3680 | if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") && |
bbce6d69 | 3681 | (t = strchr(s, '}')) && (t = strchr(t, '='))) |
3682 | { | |
3280af22 | 3683 | char tmpbuf[sizeof PL_tokenbuf]; |
a0d0e21e LW |
3684 | STRLEN len; |
3685 | for (t++; isSPACE(*t); t++) ; | |
7e2040f0 | 3686 | if (isIDFIRST_lazy_if(t,UTF)) { |
8903cb82 | 3687 | t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len); |
59a6d928 | 3688 | for (; isSPACE(*t); t++) ; |
864dbfa3 | 3689 | if (*t == ';' && get_cv(tmpbuf, FALSE)) |
9014280d | 3690 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
599cee73 | 3691 | "You need to quote \"%s\"", tmpbuf); |
748a9306 | 3692 | } |
93a17b20 LW |
3693 | } |
3694 | } | |
2f3197b3 | 3695 | } |
bbce6d69 | 3696 | |
3280af22 | 3697 | PL_expect = XOPERATOR; |
69d2bceb | 3698 | if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) { |
3280af22 NIS |
3699 | bool islop = (PL_last_lop == PL_oldoldbufptr); |
3700 | if (!islop || PL_last_lop_op == OP_GREPSTART) | |
3701 | PL_expect = XOPERATOR; | |
bbce6d69 | 3702 | else if (strchr("$@\"'`q", *s)) |
3280af22 | 3703 | PL_expect = XTERM; /* e.g. print $fh "foo" */ |
7e2040f0 | 3704 | else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF)) |
3280af22 | 3705 | PL_expect = XTERM; /* e.g. print $fh &sub */ |
7e2040f0 | 3706 | else if (isIDFIRST_lazy_if(s,UTF)) { |
3280af22 | 3707 | char tmpbuf[sizeof PL_tokenbuf]; |
8903cb82 | 3708 | scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
155aba94 | 3709 | if ((tmp = keyword(tmpbuf, len))) { |
84902520 TB |
3710 | /* binary operators exclude handle interpretations */ |
3711 | switch (tmp) { | |
3712 | case -KEY_x: | |
3713 | case -KEY_eq: | |
3714 | case -KEY_ne: | |
3715 | case -KEY_gt: | |
3716 | case -KEY_lt: | |
3717 | case -KEY_ge: | |
3718 | case -KEY_le: | |
3719 | case -KEY_cmp: | |
3720 | break; | |
3721 | default: | |
3280af22 | 3722 | PL_expect = XTERM; /* e.g. print $fh length() */ |
84902520 TB |
3723 | break; |
3724 | } | |
3725 | } | |
68dc0745 | 3726 | else { |
8a8635f0 | 3727 | PL_expect = XTERM; /* e.g. print $fh subr() */ |
93a17b20 | 3728 | } |
93a17b20 | 3729 | } |
bbce6d69 | 3730 | else if (isDIGIT(*s)) |
3280af22 | 3731 | PL_expect = XTERM; /* e.g. print $fh 3 */ |
bbce6d69 | 3732 | else if (*s == '.' && isDIGIT(s[1])) |
3280af22 | 3733 | PL_expect = XTERM; /* e.g. print $fh .3 */ |
3792a11b NC |
3734 | else if ((*s == '?' || *s == '-' || *s == '+') |
3735 | && !isSPACE(s[1]) && s[1] != '=') | |
c963b151 | 3736 | PL_expect = XTERM; /* e.g. print $fh -1 */ |
7ce6e6b9 RGS |
3737 | else if (*s == '/' && !isSPACE(s[1]) && s[1] != '=' && s[1] != '/') |
3738 | PL_expect = XTERM; /* e.g. print $fh /.../ | |
3739 | XXX except DORDOR operator */ | |
e0587a03 | 3740 | else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=') |
3280af22 | 3741 | PL_expect = XTERM; /* print $fh <<"EOF" */ |
bbce6d69 | 3742 | } |
3280af22 | 3743 | PL_pending_ident = '$'; |
79072805 | 3744 | TOKEN('$'); |
378cc40b LW |
3745 | |
3746 | case '@': | |
3280af22 | 3747 | if (PL_expect == XOPERATOR) |
bbce6d69 | 3748 | no_op("Array", s); |
3280af22 NIS |
3749 | PL_tokenbuf[0] = '@'; |
3750 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE); | |
3751 | if (!PL_tokenbuf[1]) { | |
bbce6d69 | 3752 | PREREF('@'); |
3753 | } | |
3280af22 | 3754 | if (PL_lex_state == LEX_NORMAL) |
ff68c719 | 3755 | s = skipspace(s); |
3280af22 | 3756 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) { |
bbce6d69 | 3757 | if (*s == '{') |
3280af22 | 3758 | PL_tokenbuf[0] = '%'; |
a0d0e21e LW |
3759 | |
3760 | /* Warn about @ where they meant $. */ | |
599cee73 | 3761 | if (ckWARN(WARN_SYNTAX)) { |
a0d0e21e LW |
3762 | if (*s == '[' || *s == '{') { |
3763 | char *t = s + 1; | |
7e2040f0 | 3764 | while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t))) |
a0d0e21e LW |
3765 | t++; |
3766 | if (*t == '}' || *t == ']') { | |
3767 | t++; | |
3280af22 | 3768 | PL_bufptr = skipspace(PL_bufptr); |
9014280d | 3769 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
599cee73 | 3770 | "Scalar value %.*s better written as $%.*s", |
3280af22 | 3771 | t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1); |
a0d0e21e | 3772 | } |
93a17b20 LW |
3773 | } |
3774 | } | |
463ee0b2 | 3775 | } |
3280af22 | 3776 | PL_pending_ident = '@'; |
79072805 | 3777 | TERM('@'); |
378cc40b | 3778 | |
c963b151 | 3779 | case '/': /* may be division, defined-or, or pattern */ |
6f33ba73 RGS |
3780 | if (PL_expect == XTERMORDORDOR && s[1] == '/') { |
3781 | s += 2; | |
3782 | AOPERATOR(DORDOR); | |
3783 | } | |
c963b151 BD |
3784 | case '?': /* may either be conditional or pattern */ |
3785 | if(PL_expect == XOPERATOR) { | |
3786 | tmp = *s++; | |
3787 | if(tmp == '?') { | |
3788 | OPERATOR('?'); | |
3789 | } | |
3790 | else { | |
3791 | tmp = *s++; | |
3792 | if(tmp == '/') { | |
3793 | /* A // operator. */ | |
3794 | AOPERATOR(DORDOR); | |
3795 | } | |
3796 | else { | |
3797 | s--; | |
3798 | Mop(OP_DIVIDE); | |
3799 | } | |
3800 | } | |
3801 | } | |
3802 | else { | |
3803 | /* Disable warning on "study /blah/" */ | |
3804 | if (PL_oldoldbufptr == PL_last_uni | |
3805 | && (*PL_last_uni != 's' || s - PL_last_uni < 5 | |
3806 | || memNE(PL_last_uni, "study", 5) | |
3807 | || isALNUM_lazy_if(PL_last_uni+5,UTF) | |
3808 | )) | |
3809 | check_uni(); | |
3810 | s = scan_pat(s,OP_MATCH); | |
3811 | TERM(sublex_start()); | |
3812 | } | |
378cc40b LW |
3813 | |
3814 | case '.': | |
51882d45 GS |
3815 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack |
3816 | #ifdef PERL_STRICT_CR | |
3817 | && s[1] == '\n' | |
3818 | #else | |
3819 | && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n')) | |
3820 | #endif | |
3821 | && (s == PL_linestart || s[-1] == '\n') ) | |
3822 | { | |
3280af22 NIS |
3823 | PL_lex_formbrack = 0; |
3824 | PL_expect = XSTATE; | |
79072805 LW |
3825 | goto rightbracket; |
3826 | } | |
3280af22 | 3827 | if (PL_expect == XOPERATOR || !isDIGIT(s[1])) { |
378cc40b | 3828 | tmp = *s++; |
a687059c LW |
3829 | if (*s == tmp) { |
3830 | s++; | |
2f3197b3 LW |
3831 | if (*s == tmp) { |
3832 | s++; | |
79072805 | 3833 | yylval.ival = OPf_SPECIAL; |
2f3197b3 LW |
3834 | } |
3835 | else | |
79072805 | 3836 | yylval.ival = 0; |
378cc40b | 3837 | OPERATOR(DOTDOT); |
a687059c | 3838 | } |
3280af22 | 3839 | if (PL_expect != XOPERATOR) |
2f3197b3 | 3840 | check_uni(); |
79072805 | 3841 | Aop(OP_CONCAT); |
378cc40b LW |
3842 | } |
3843 | /* FALL THROUGH */ | |
3844 | case '0': case '1': case '2': case '3': case '4': | |
3845 | case '5': case '6': case '7': case '8': case '9': | |
b73d6f50 | 3846 | s = scan_num(s, &yylval); |
4e553d73 | 3847 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
607df283 | 3848 | "### Saw number in '%s'\n", s); |
5f80b19c | 3849 | } ); |
3280af22 | 3850 | if (PL_expect == XOPERATOR) |
8990e307 | 3851 | no_op("Number",s); |
79072805 LW |
3852 | TERM(THING); |
3853 | ||
3854 | case '\'': | |
09bef843 | 3855 | s = scan_str(s,FALSE,FALSE); |
4e553d73 | 3856 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
207e3d1a | 3857 | "### Saw string before '%s'\n", s); |
5f80b19c | 3858 | } ); |
3280af22 NIS |
3859 | if (PL_expect == XOPERATOR) { |
3860 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3861 | PL_expect = XTERM; | |
a0d0e21e | 3862 | depcom(); |
bbf60fe6 | 3863 | return REPORT(','); /* grandfather non-comma-format format */ |
a0d0e21e | 3864 | } |
463ee0b2 | 3865 | else |
8990e307 | 3866 | no_op("String",s); |
463ee0b2 | 3867 | } |
79072805 | 3868 | if (!s) |
85e6fe83 | 3869 | missingterm((char*)0); |
79072805 LW |
3870 | yylval.ival = OP_CONST; |
3871 | TERM(sublex_start()); | |
3872 | ||
3873 | case '"': | |
09bef843 | 3874 | s = scan_str(s,FALSE,FALSE); |
4e553d73 | 3875 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
207e3d1a | 3876 | "### Saw string before '%s'\n", s); |
5f80b19c | 3877 | } ); |
3280af22 NIS |
3878 | if (PL_expect == XOPERATOR) { |
3879 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { | |
3880 | PL_expect = XTERM; | |
a0d0e21e | 3881 | depcom(); |
bbf60fe6 | 3882 | return REPORT(','); /* grandfather non-comma-format format */ |
a0d0e21e | 3883 | } |
463ee0b2 | 3884 | else |
8990e307 | 3885 | no_op("String",s); |
463ee0b2 | 3886 | } |
79072805 | 3887 | if (!s) |
85e6fe83 | 3888 | missingterm((char*)0); |
4633a7c4 | 3889 | yylval.ival = OP_CONST; |
3280af22 | 3890 | for (d = SvPV(PL_lex_stuff, len); len; len--, d++) { |
63cd0674 | 3891 | if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) { |
4633a7c4 LW |
3892 | yylval.ival = OP_STRINGIFY; |
3893 | break; | |
3894 | } | |
3895 | } | |
79072805 LW |
3896 | TERM(sublex_start()); |
3897 | ||
3898 | case '`': | |
09bef843 | 3899 | s = scan_str(s,FALSE,FALSE); |
4e553d73 | 3900 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
207e3d1a | 3901 | "### Saw backtick string before '%s'\n", s); |
5f80b19c | 3902 | } ); |
3280af22 | 3903 | if (PL_expect == XOPERATOR) |
8990e307 | 3904 | no_op("Backticks",s); |
79072805 | 3905 | if (!s) |
85e6fe83 | 3906 | missingterm((char*)0); |
79072805 LW |
3907 | yylval.ival = OP_BACKTICK; |
3908 | set_csh(); | |
3909 | TERM(sublex_start()); | |
3910 | ||
3911 | case '\\': | |
3912 | s++; | |
599cee73 | 3913 | if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s)) |
9014280d | 3914 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression", |
599cee73 | 3915 | *s, *s); |
3280af22 | 3916 | if (PL_expect == XOPERATOR) |
8990e307 | 3917 | no_op("Backslash",s); |
79072805 LW |
3918 | OPERATOR(REFGEN); |
3919 | ||
a7cb1f99 | 3920 | case 'v': |
e526c9e6 | 3921 | if (isDIGIT(s[1]) && PL_expect != XOPERATOR) { |
a7cb1f99 GS |
3922 | char *start = s; |
3923 | start++; | |
3924 | start++; | |
dd629d5b | 3925 | while (isDIGIT(*start) || *start == '_') |
a7cb1f99 GS |
3926 | start++; |
3927 | if (*start == '.' && isDIGIT(start[1])) { | |
b73d6f50 | 3928 | s = scan_num(s, &yylval); |
a7cb1f99 GS |
3929 | TERM(THING); |
3930 | } | |
e526c9e6 | 3931 | /* avoid v123abc() or $h{v1}, allow C<print v10;> */ |
6f33ba73 RGS |
3932 | else if (!isALPHA(*start) && (PL_expect == XTERM |
3933 | || PL_expect == XREF || PL_expect == XSTATE | |
3934 | || PL_expect == XTERMORDORDOR)) { | |
e526c9e6 GS |
3935 | char c = *start; |
3936 | GV *gv; | |
3937 | *start = '\0'; | |
3938 | gv = gv_fetchpv(s, FALSE, SVt_PVCV); | |
3939 | *start = c; | |
3940 | if (!gv) { | |
b73d6f50 | 3941 | s = scan_num(s, &yylval); |
e526c9e6 GS |
3942 | TERM(THING); |
3943 | } | |
3944 | } | |
a7cb1f99 GS |
3945 | } |
3946 | goto keylookup; | |
79072805 | 3947 | case 'x': |
3280af22 | 3948 | if (isDIGIT(s[1]) && PL_expect == XOPERATOR) { |
79072805 LW |
3949 | s++; |
3950 | Mop(OP_REPEAT); | |
2f3197b3 | 3951 | } |
79072805 LW |
3952 | goto keylookup; |
3953 | ||
378cc40b | 3954 | case '_': |
79072805 LW |
3955 | case 'a': case 'A': |
3956 | case 'b': case 'B': | |
3957 | case 'c': case 'C': | |
3958 | case 'd': case 'D': | |
3959 | case 'e': case 'E': | |
3960 | case 'f': case 'F': | |
3961 | case 'g': case 'G': | |
3962 | case 'h': case 'H': | |
3963 | case 'i': case 'I': | |
3964 | case 'j': case 'J': | |
3965 | case 'k': case 'K': | |
3966 | case 'l': case 'L': | |
3967 | case 'm': case 'M': | |
3968 | case 'n': case 'N': | |
3969 | case 'o': case 'O': | |
3970 | case 'p': case 'P': | |
3971 | case 'q': case 'Q': | |
3972 | case 'r': case 'R': | |
3973 | case 's': case 'S': | |
3974 | case 't': case 'T': | |
3975 | case 'u': case 'U': | |
a7cb1f99 | 3976 | case 'V': |
79072805 LW |
3977 | case 'w': case 'W': |
3978 | case 'X': | |
3979 | case 'y': case 'Y': | |
3980 | case 'z': case 'Z': | |
3981 | ||
49dc05e3 | 3982 | keylookup: { |
1d239bbb | 3983 | orig_keyword = 0; |
161b471a NIS |
3984 | gv = Nullgv; |
3985 | gvp = 0; | |
49dc05e3 | 3986 | |
3280af22 NIS |
3987 | PL_bufptr = s; |
3988 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); | |
8ebc5c01 | 3989 | |
3990 | /* Some keywords can be followed by any delimiter, including ':' */ | |
155aba94 GS |
3991 | tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) || |
3992 | (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') || | |
3993 | (PL_tokenbuf[0] == 'q' && | |
3994 | strchr("qwxr", PL_tokenbuf[1]))))); | |
8ebc5c01 | 3995 | |
3996 | /* x::* is just a word, unless x is "CORE" */ | |
3280af22 | 3997 | if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE")) |
4633a7c4 LW |
3998 | goto just_a_word; |
3999 | ||
3643fb5f | 4000 | d = s; |
3280af22 | 4001 | while (d < PL_bufend && isSPACE(*d)) |
3643fb5f CS |
4002 | d++; /* no comments skipped here, or s### is misparsed */ |
4003 | ||
4004 | /* Is this a label? */ | |
3280af22 NIS |
4005 | if (!tmp && PL_expect == XSTATE |
4006 | && d < PL_bufend && *d == ':' && *(d + 1) != ':') { | |
8ebc5c01 | 4007 | s = d + 1; |
3280af22 | 4008 | yylval.pval = savepv(PL_tokenbuf); |
8ebc5c01 | 4009 | CLINE; |
4010 | TOKEN(LABEL); | |
3643fb5f CS |
4011 | } |
4012 | ||
4013 | /* Check for keywords */ | |
3280af22 | 4014 | tmp = keyword(PL_tokenbuf, len); |
748a9306 LW |
4015 | |
4016 | /* Is this a word before a => operator? */ | |
1c3923b3 | 4017 | if (*d == '=' && d[1] == '>') { |
748a9306 | 4018 | CLINE; |
d0a148a6 NC |
4019 | yylval.opval |
4020 | = (OP*)newSVOP(OP_CONST, 0, | |
4021 | S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len)); | |
748a9306 LW |
4022 | yylval.opval->op_private = OPpCONST_BARE; |
4023 | TERM(WORD); | |
4024 | } | |
4025 | ||
a0d0e21e | 4026 | if (tmp < 0) { /* second-class keyword? */ |
56f7f34b CS |
4027 | GV *ogv = Nullgv; /* override (winner) */ |
4028 | GV *hgv = Nullgv; /* hidden (loser) */ | |
3280af22 | 4029 | if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) { |
56f7f34b | 4030 | CV *cv; |
3280af22 | 4031 | if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) && |
56f7f34b CS |
4032 | (cv = GvCVu(gv))) |
4033 | { | |
4034 | if (GvIMPORTED_CV(gv)) | |
4035 | ogv = gv; | |
4036 | else if (! CvMETHOD(cv)) | |
4037 | hgv = gv; | |
4038 | } | |
4039 | if (!ogv && | |
3280af22 NIS |
4040 | (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) && |
4041 | (gv = *gvp) != (GV*)&PL_sv_undef && | |
56f7f34b CS |
4042 | GvCVu(gv) && GvIMPORTED_CV(gv)) |
4043 | { | |
4044 | ogv = gv; | |
4045 | } | |
4046 | } | |
4047 | if (ogv) { | |
30fe34ed | 4048 | orig_keyword = tmp; |
56f7f34b | 4049 | tmp = 0; /* overridden by import or by GLOBAL */ |
6e7b2336 GS |
4050 | } |
4051 | else if (gv && !gvp | |
4052 | && -tmp==KEY_lock /* XXX generalizable kludge */ | |
d0456cad | 4053 | && GvCVu(gv) |
3280af22 | 4054 | && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE)) |
6e7b2336 GS |
4055 | { |
4056 | tmp = 0; /* any sub overrides "weak" keyword */ | |
a0d0e21e | 4057 | } |
7fc307b5 RGS |
4058 | else if (gv && !gvp |
4059 | && tmp == -KEY_err | |
4060 | && GvCVu(gv) | |
4061 | && PL_expect != XOPERATOR | |
4062 | && PL_expect != XTERMORDORDOR) | |
4063 | { | |
4064 | /* any sub overrides the "err" keyword, except when really an | |
4065 | * operator is expected */ | |
4066 | tmp = 0; | |
4067 | } | |
56f7f34b CS |
4068 | else { /* no override */ |
4069 | tmp = -tmp; | |
ac206dc8 | 4070 | if (tmp == KEY_dump && ckWARN(WARN_MISC)) { |
9014280d | 4071 | Perl_warner(aTHX_ packWARN(WARN_MISC), |
ac206dc8 RGS |
4072 | "dump() better written as CORE::dump()"); |
4073 | } | |
56f7f34b CS |
4074 | gv = Nullgv; |
4075 | gvp = 0; | |
4944e2f7 GS |
4076 | if (ckWARN(WARN_AMBIGUOUS) && hgv |
4077 | && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */ | |
9014280d | 4078 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
599cee73 | 4079 | "Ambiguous call resolved as CORE::%s(), %s", |
2f3ca594 | 4080 | GvENAME(hgv), "qualify as such or use &"); |
49dc05e3 | 4081 | } |
a0d0e21e LW |
4082 | } |
4083 | ||
4084 | reserved_word: | |
4085 | switch (tmp) { | |
79072805 LW |
4086 | |
4087 | default: /* not a keyword */ | |
93a17b20 | 4088 | just_a_word: { |
96e4d5b1 | 4089 | SV *sv; |
ce29ac45 | 4090 | int pkgname = 0; |
3280af22 | 4091 | char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]); |
8990e307 LW |
4092 | |
4093 | /* Get the rest if it looks like a package qualifier */ | |
4094 | ||
155aba94 | 4095 | if (*s == '\'' || (*s == ':' && s[1] == ':')) { |
c3e0f903 | 4096 | STRLEN morelen; |
3280af22 | 4097 | s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len, |
c3e0f903 GS |
4098 | TRUE, &morelen); |
4099 | if (!morelen) | |
cea2e8a9 | 4100 | Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf, |
ec2ab091 | 4101 | *s == '\'' ? "'" : "::"); |
c3e0f903 | 4102 | len += morelen; |
ce29ac45 | 4103 | pkgname = 1; |
a0d0e21e | 4104 | } |
8990e307 | 4105 | |
3280af22 NIS |
4106 | if (PL_expect == XOPERATOR) { |
4107 | if (PL_bufptr == PL_linestart) { | |
57843af0 | 4108 | CopLINE_dec(PL_curcop); |
9014280d | 4109 | Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi); |
57843af0 | 4110 | CopLINE_inc(PL_curcop); |
463ee0b2 LW |
4111 | } |
4112 | else | |
54310121 | 4113 | no_op("Bareword",s); |
463ee0b2 | 4114 | } |
8990e307 | 4115 | |
c3e0f903 GS |
4116 | /* Look for a subroutine with this name in current package, |
4117 | unless name is "Foo::", in which case Foo is a bearword | |
4118 | (and a package name). */ | |
4119 | ||
4120 | if (len > 2 && | |
3280af22 | 4121 | PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':') |
c3e0f903 | 4122 | { |
e476b1b5 | 4123 | if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV)) |
9014280d | 4124 | Perl_warner(aTHX_ packWARN(WARN_BAREWORD), |
599cee73 | 4125 | "Bareword \"%s\" refers to nonexistent package", |
3280af22 | 4126 | PL_tokenbuf); |
c3e0f903 | 4127 | len -= 2; |
3280af22 | 4128 | PL_tokenbuf[len] = '\0'; |
c3e0f903 GS |
4129 | gv = Nullgv; |
4130 | gvp = 0; | |
4131 | } | |
4132 | else { | |
4133 | len = 0; | |
4134 | if (!gv) | |
3280af22 | 4135 | gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV); |
c3e0f903 GS |
4136 | } |
4137 | ||
4138 | /* if we saw a global override before, get the right name */ | |
8990e307 | 4139 | |
49dc05e3 | 4140 | if (gvp) { |
79cb57f6 | 4141 | sv = newSVpvn("CORE::GLOBAL::",14); |
3280af22 | 4142 | sv_catpv(sv,PL_tokenbuf); |
49dc05e3 | 4143 | } |
8a7a129d NC |
4144 | else { |
4145 | /* If len is 0, newSVpv does strlen(), which is correct. | |
4146 | If len is non-zero, then it will be the true length, | |
4147 | and so the scalar will be created correctly. */ | |
4148 | sv = newSVpv(PL_tokenbuf,len); | |
4149 | } | |
8990e307 | 4150 | |
a0d0e21e LW |
4151 | /* Presume this is going to be a bareword of some sort. */ |
4152 | ||
4153 | CLINE; | |
49dc05e3 | 4154 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
a0d0e21e | 4155 | yylval.opval->op_private = OPpCONST_BARE; |
8f8cf39c JH |
4156 | /* UTF-8 package name? */ |
4157 | if (UTF && !IN_BYTES && | |
4158 | is_utf8_string((U8*)SvPVX(sv), SvCUR(sv))) | |
4159 | SvUTF8_on(sv); | |
a0d0e21e | 4160 | |
c3e0f903 GS |
4161 | /* And if "Foo::", then that's what it certainly is. */ |
4162 | ||
4163 | if (len) | |
4164 | goto safe_bareword; | |
4165 | ||
8990e307 LW |
4166 | /* See if it's the indirect object for a list operator. */ |
4167 | ||
3280af22 NIS |
4168 | if (PL_oldoldbufptr && |
4169 | PL_oldoldbufptr < PL_bufptr && | |
65cec589 GS |
4170 | (PL_oldoldbufptr == PL_last_lop |
4171 | || PL_oldoldbufptr == PL_last_uni) && | |
a0d0e21e | 4172 | /* NO SKIPSPACE BEFORE HERE! */ |
a9ef352a GS |
4173 | (PL_expect == XREF || |
4174 | ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF)) | |
a0d0e21e | 4175 | { |
748a9306 LW |
4176 | bool immediate_paren = *s == '('; |
4177 | ||
a0d0e21e LW |
4178 | /* (Now we can afford to cross potential line boundary.) */ |
4179 | s = skipspace(s); | |
4180 | ||
4181 | /* Two barewords in a row may indicate method call. */ | |
4182 | ||
7e2040f0 | 4183 | if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv))) |
bbf60fe6 | 4184 | return REPORT(tmp); |
a0d0e21e LW |
4185 | |
4186 | /* If not a declared subroutine, it's an indirect object. */ | |
4187 | /* (But it's an indir obj regardless for sort.) */ | |
4188 | ||
7948272d | 4189 | if ( !immediate_paren && (PL_last_lop_op == OP_SORT || |
f0670693 | 4190 | ((!gv || !GvCVu(gv)) && |
a9ef352a | 4191 | (PL_last_lop_op != OP_MAPSTART && |
f0670693 | 4192 | PL_last_lop_op != OP_GREPSTART)))) |
a9ef352a | 4193 | { |
3280af22 | 4194 | PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR; |
748a9306 | 4195 | goto bareword; |
93a17b20 LW |
4196 | } |
4197 | } | |
8990e307 | 4198 | |
3280af22 | 4199 | PL_expect = XOPERATOR; |
8990e307 | 4200 | s = skipspace(s); |
1c3923b3 GS |
4201 | |
4202 | /* Is this a word before a => operator? */ | |
ce29ac45 | 4203 | if (*s == '=' && s[1] == '>' && !pkgname) { |
1c3923b3 GS |
4204 | CLINE; |
4205 | sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf); | |
0064a8a9 | 4206 | if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len)) |
7948272d | 4207 | SvUTF8_on(((SVOP*)yylval.opval)->op_sv); |
1c3923b3 GS |
4208 | TERM(WORD); |
4209 | } | |
4210 | ||
4211 | /* If followed by a paren, it's certainly a subroutine. */ | |
93a17b20 | 4212 | if (*s == '(') { |
79072805 | 4213 | CLINE; |
96e4d5b1 | 4214 | if (gv && GvCVu(gv)) { |
bf4acbe4 | 4215 | for (d = s + 1; SPACE_OR_TAB(*d); d++) ; |
7a52d87a | 4216 | if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) { |
96e4d5b1 | 4217 | s = d + 1; |
4218 | goto its_constant; | |
4219 | } | |
4220 | } | |
3280af22 NIS |
4221 | PL_nextval[PL_nexttoke].opval = yylval.opval; |
4222 | PL_expect = XOPERATOR; | |
93a17b20 | 4223 | force_next(WORD); |
c07a80fd | 4224 | yylval.ival = 0; |
463ee0b2 | 4225 | TOKEN('&'); |
79072805 | 4226 | } |
93a17b20 | 4227 | |
a0d0e21e | 4228 | /* If followed by var or block, call it a method (unless sub) */ |
8990e307 | 4229 | |
8ebc5c01 | 4230 | if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) { |
3280af22 NIS |
4231 | PL_last_lop = PL_oldbufptr; |
4232 | PL_last_lop_op = OP_METHOD; | |
93a17b20 | 4233 | PREBLOCK(METHOD); |
463ee0b2 LW |
4234 | } |
4235 | ||
8990e307 LW |
4236 | /* If followed by a bareword, see if it looks like indir obj. */ |
4237 | ||
30fe34ed RGS |
4238 | if (!orig_keyword |
4239 | && (isIDFIRST_lazy_if(s,UTF) || *s == '$') | |
4240 | && (tmp = intuit_method(s,gv))) | |
bbf60fe6 | 4241 | return REPORT(tmp); |
93a17b20 | 4242 | |
8990e307 LW |
4243 | /* Not a method, so call it a subroutine (if defined) */ |
4244 | ||
8ebc5c01 | 4245 | if (gv && GvCVu(gv)) { |
46fc3d4c | 4246 | CV* cv; |
0453d815 | 4247 | if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS)) |
9014280d | 4248 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
0453d815 | 4249 | "Ambiguous use of -%s resolved as -&%s()", |
3280af22 | 4250 | PL_tokenbuf, PL_tokenbuf); |
89bfa8cd | 4251 | /* Check for a constant sub */ |
46fc3d4c | 4252 | cv = GvCV(gv); |
96e4d5b1 | 4253 | if ((sv = cv_const_sv(cv))) { |
4254 | its_constant: | |
4255 | SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv); | |
4256 | ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv); | |
4257 | yylval.opval->op_private = 0; | |
4258 | TOKEN(WORD); | |
89bfa8cd | 4259 | } |
4260 | ||
a5f75d66 AD |
4261 | /* Resolve to GV now. */ |
4262 | op_free(yylval.opval); | |
4263 | yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv)); | |
9675f7ac | 4264 | yylval.opval->op_private |= OPpENTERSUB_NOPAREN; |
7a52d87a | 4265 | PL_last_lop = PL_oldbufptr; |
bf848113 | 4266 | PL_last_lop_op = OP_ENTERSUB; |
4633a7c4 LW |
4267 | /* Is there a prototype? */ |
4268 | if (SvPOK(cv)) { | |
4269 | STRLEN len; | |
7a52d87a | 4270 | char *proto = SvPV((SV*)cv, len); |
4633a7c4 LW |
4271 | if (!len) |
4272 | TERM(FUNC0SUB); | |
770526c1 | 4273 | if (*proto == '$' && proto[1] == '\0') |
4633a7c4 | 4274 | OPERATOR(UNIOPSUB); |
0f5d0394 AE |
4275 | while (*proto == ';') |
4276 | proto++; | |
7a52d87a | 4277 | if (*proto == '&' && *s == '{') { |
bfed75c6 | 4278 | sv_setpv(PL_subname, PL_curstash ? |
c99da370 | 4279 | "__ANON__" : "__ANON__::__ANON__"); |
4633a7c4 LW |
4280 | PREBLOCK(LSTOPSUB); |
4281 | } | |
a9ef352a | 4282 | } |
3280af22 NIS |
4283 | PL_nextval[PL_nexttoke].opval = yylval.opval; |
4284 | PL_expect = XTERM; | |
8990e307 LW |
4285 | force_next(WORD); |
4286 | TOKEN(NOAMP); | |
4287 | } | |
748a9306 | 4288 | |
8990e307 LW |
4289 | /* Call it a bare word */ |
4290 | ||
5603f27d GS |
4291 | if (PL_hints & HINT_STRICT_SUBS) |
4292 | yylval.opval->op_private |= OPpCONST_STRICT; | |
4293 | else { | |
4294 | bareword: | |
4295 | if (ckWARN(WARN_RESERVED)) { | |
4296 | if (lastchar != '-') { | |
4297 | for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ; | |
238ae712 | 4298 | if (!*d && !gv_stashpv(PL_tokenbuf,FALSE)) |
9014280d | 4299 | Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved, |
5603f27d GS |
4300 | PL_tokenbuf); |
4301 | } | |
748a9306 LW |
4302 | } |
4303 | } | |
c3e0f903 GS |
4304 | |
4305 | safe_bareword: | |
3792a11b NC |
4306 | if ((lastchar == '*' || lastchar == '%' || lastchar == '&') |
4307 | && ckWARN_d(WARN_AMBIGUOUS)) { | |
9014280d | 4308 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
0453d815 | 4309 | "Operator or semicolon missing before %c%s", |
3280af22 | 4310 | lastchar, PL_tokenbuf); |
9014280d | 4311 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
0453d815 | 4312 | "Ambiguous use of %c resolved as operator %c", |
748a9306 LW |
4313 | lastchar, lastchar); |
4314 | } | |
93a17b20 | 4315 | TOKEN(WORD); |
79072805 | 4316 | } |
79072805 | 4317 | |
68dc0745 | 4318 | case KEY___FILE__: |
46fc3d4c | 4319 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
ed094faf | 4320 | newSVpv(CopFILE(PL_curcop),0)); |
46fc3d4c | 4321 | TERM(THING); |
4322 | ||
79072805 | 4323 | case KEY___LINE__: |
cf2093f6 | 4324 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
57843af0 | 4325 | Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop))); |
79072805 | 4326 | TERM(THING); |
68dc0745 | 4327 | |
4328 | case KEY___PACKAGE__: | |
4329 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, | |
3280af22 | 4330 | (PL_curstash |
9508c957 | 4331 | ? newSVpv(HvNAME(PL_curstash), 0) |
3280af22 | 4332 | : &PL_sv_undef)); |
79072805 | 4333 | TERM(THING); |
79072805 | 4334 | |
e50aee73 | 4335 | case KEY___DATA__: |
79072805 LW |
4336 | case KEY___END__: { |
4337 | GV *gv; | |
79072805 LW |
4338 | |
4339 | /*SUPPRESS 560*/ | |
3280af22 | 4340 | if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) { |
bfed75c6 | 4341 | const char *pname = "main"; |
3280af22 NIS |
4342 | if (PL_tokenbuf[2] == 'D') |
4343 | pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash); | |
cea2e8a9 | 4344 | gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO); |
a5f75d66 | 4345 | GvMULTI_on(gv); |
79072805 | 4346 | if (!GvIO(gv)) |
a0d0e21e | 4347 | GvIOp(gv) = newIO(); |
3280af22 | 4348 | IoIFP(GvIOp(gv)) = PL_rsfp; |
a0d0e21e LW |
4349 | #if defined(HAS_FCNTL) && defined(F_SETFD) |
4350 | { | |
3280af22 | 4351 | int fd = PerlIO_fileno(PL_rsfp); |
a0d0e21e LW |
4352 | fcntl(fd,F_SETFD,fd >= 3); |
4353 | } | |
79072805 | 4354 | #endif |
fd049845 | 4355 | /* Mark this internal pseudo-handle as clean */ |
4356 | IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT; | |
3280af22 | 4357 | if (PL_preprocess) |
50952442 | 4358 | IoTYPE(GvIOp(gv)) = IoTYPE_PIPE; |
3280af22 | 4359 | else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) |
50952442 | 4360 | IoTYPE(GvIOp(gv)) = IoTYPE_STD; |
79072805 | 4361 | else |
50952442 | 4362 | IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY; |
c39cd008 GS |
4363 | #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS) |
4364 | /* if the script was opened in binmode, we need to revert | |
53129d29 | 4365 | * it to text mode for compatibility; but only iff it has CRs |
c39cd008 | 4366 | * XXX this is a questionable hack at best. */ |
53129d29 GS |
4367 | if (PL_bufend-PL_bufptr > 2 |
4368 | && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r') | |
c39cd008 GS |
4369 | { |
4370 | Off_t loc = 0; | |
50952442 | 4371 | if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) { |
c39cd008 GS |
4372 | loc = PerlIO_tell(PL_rsfp); |
4373 | (void)PerlIO_seek(PL_rsfp, 0L, 0); | |
4374 | } | |
2986a63f JH |
4375 | #ifdef NETWARE |
4376 | if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) { | |
4377 | #else | |
c39cd008 | 4378 | if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) { |
2986a63f | 4379 | #endif /* NETWARE */ |
1143fce0 JH |
4380 | #ifdef PERLIO_IS_STDIO /* really? */ |
4381 | # if defined(__BORLANDC__) | |
cb359b41 JH |
4382 | /* XXX see note in do_binmode() */ |
4383 | ((FILE*)PL_rsfp)->flags &= ~_F_BIN; | |
1143fce0 JH |
4384 | # endif |
4385 | #endif | |
c39cd008 GS |
4386 | if (loc > 0) |
4387 | PerlIO_seek(PL_rsfp, loc, 0); | |
4388 | } | |
4389 | } | |
4390 | #endif | |
7948272d | 4391 | #ifdef PERLIO_LAYERS |
52d2e0f4 JH |
4392 | if (!IN_BYTES) { |
4393 | if (UTF) | |
4394 | PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8"); | |
4395 | else if (PL_encoding) { | |
4396 | SV *name; | |
4397 | dSP; | |
4398 | ENTER; | |
4399 | SAVETMPS; | |
4400 | PUSHMARK(sp); | |
4401 | EXTEND(SP, 1); | |
4402 | XPUSHs(PL_encoding); | |
4403 | PUTBACK; | |
4404 | call_method("name", G_SCALAR); | |
4405 | SPAGAIN; | |
4406 | name = POPs; | |
4407 | PUTBACK; | |
bfed75c6 | 4408 | PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, |
52d2e0f4 JH |
4409 | Perl_form(aTHX_ ":encoding(%"SVf")", |
4410 | name)); | |
4411 | FREETMPS; | |
4412 | LEAVE; | |
4413 | } | |
4414 | } | |
7948272d | 4415 | #endif |
3280af22 | 4416 | PL_rsfp = Nullfp; |
79072805 LW |
4417 | } |
4418 | goto fake_eof; | |
e929a76b | 4419 | } |
de3bb511 | 4420 | |
8990e307 | 4421 | case KEY_AUTOLOAD: |
ed6116ce | 4422 | case KEY_DESTROY: |
79072805 | 4423 | case KEY_BEGIN: |
7d30b5c4 | 4424 | case KEY_CHECK: |
7d07dbc2 | 4425 | case KEY_INIT: |
7d30b5c4 | 4426 | case KEY_END: |
3280af22 NIS |
4427 | if (PL_expect == XSTATE) { |
4428 | s = PL_bufptr; | |
93a17b20 | 4429 | goto really_sub; |
79072805 LW |
4430 | } |
4431 | goto just_a_word; | |
4432 | ||
a0d0e21e LW |
4433 | case KEY_CORE: |
4434 | if (*s == ':' && s[1] == ':') { | |
4435 | s += 2; | |
748a9306 | 4436 | d = s; |
3280af22 | 4437 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
6798c92b GS |
4438 | if (!(tmp = keyword(PL_tokenbuf, len))) |
4439 | Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf); | |
a0d0e21e LW |
4440 | if (tmp < 0) |
4441 | tmp = -tmp; | |
4442 | goto reserved_word; | |
4443 | } | |
4444 | goto just_a_word; | |
4445 | ||
463ee0b2 LW |
4446 | case KEY_abs: |
4447 | UNI(OP_ABS); | |
4448 | ||
79072805 LW |
4449 | case KEY_alarm: |
4450 | UNI(OP_ALARM); | |
4451 | ||
4452 | case KEY_accept: | |
a0d0e21e | 4453 | LOP(OP_ACCEPT,XTERM); |
79072805 | 4454 | |
463ee0b2 LW |
4455 | case KEY_and: |
4456 | OPERATOR(ANDOP); | |
4457 | ||
79072805 | 4458 | case KEY_atan2: |
a0d0e21e | 4459 | LOP(OP_ATAN2,XTERM); |
85e6fe83 | 4460 | |
79072805 | 4461 | case KEY_bind: |
a0d0e21e | 4462 | LOP(OP_BIND,XTERM); |
79072805 LW |
4463 | |
4464 | case KEY_binmode: | |
1c1fc3ea | 4465 | LOP(OP_BINMODE,XTERM); |
79072805 LW |
4466 | |
4467 | case KEY_bless: | |
a0d0e21e | 4468 | LOP(OP_BLESS,XTERM); |
79072805 LW |
4469 | |
4470 | case KEY_chop: | |
4471 | UNI(OP_CHOP); | |
4472 | ||
4473 | case KEY_continue: | |
4474 | PREBLOCK(CONTINUE); | |
4475 | ||
4476 | case KEY_chdir: | |
85e6fe83 | 4477 | (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */ |
79072805 LW |
4478 | UNI(OP_CHDIR); |
4479 | ||
4480 | case KEY_close: | |
4481 | UNI(OP_CLOSE); | |
4482 | ||
4483 | case KEY_closedir: | |
4484 | UNI(OP_CLOSEDIR); | |
4485 | ||
4486 | case KEY_cmp: | |
4487 | Eop(OP_SCMP); | |
4488 | ||
4489 | case KEY_caller: | |
4490 | UNI(OP_CALLER); | |
4491 | ||
4492 | case KEY_crypt: | |
4493 | #ifdef FCRYPT | |
f4c556ac GS |
4494 | if (!PL_cryptseen) { |
4495 | PL_cryptseen = TRUE; | |
de3bb511 | 4496 | init_des(); |
f4c556ac | 4497 | } |
a687059c | 4498 | #endif |
a0d0e21e | 4499 | LOP(OP_CRYPT,XTERM); |
79072805 LW |
4500 | |
4501 | case KEY_chmod: | |
a0d0e21e | 4502 | LOP(OP_CHMOD,XTERM); |
79072805 LW |
4503 | |
4504 | case KEY_chown: | |
a0d0e21e | 4505 | LOP(OP_CHOWN,XTERM); |
79072805 LW |
4506 | |
4507 | case KEY_connect: | |
a0d0e21e | 4508 | LOP(OP_CONNECT,XTERM); |
79072805 | 4509 | |
463ee0b2 LW |
4510 | case KEY_chr: |
4511 | UNI(OP_CHR); | |
4512 | ||
79072805 LW |
4513 | case KEY_cos: |
4514 | UNI(OP_COS); | |
4515 | ||
4516 | case KEY_chroot: | |
4517 | UNI(OP_CHROOT); | |
4518 | ||
4519 | case KEY_do: | |
4520 | s = skipspace(s); | |
4521 | if (*s == '{') | |
a0d0e21e | 4522 | PRETERMBLOCK(DO); |
79072805 | 4523 | if (*s != '\'') |
89c5585f | 4524 | s = force_word(s,WORD,TRUE,TRUE,FALSE); |
378cc40b | 4525 | OPERATOR(DO); |
79072805 LW |
4526 | |
4527 | case KEY_die: | |
3280af22 | 4528 | PL_hints |= HINT_BLOCK_SCOPE; |
a0d0e21e | 4529 | LOP(OP_DIE,XTERM); |
79072805 LW |
4530 | |
4531 | case KEY_defined: | |
4532 | UNI(OP_DEFINED); | |
4533 | ||
4534 | case KEY_delete: | |
a0d0e21e | 4535 | UNI(OP_DELETE); |
79072805 LW |
4536 | |
4537 | case KEY_dbmopen: | |
a0d0e21e LW |
4538 | gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV); |
4539 | LOP(OP_DBMOPEN,XTERM); | |
79072805 LW |
4540 | |
4541 | case KEY_dbmclose: | |
4542 | UNI(OP_DBMCLOSE); | |
4543 | ||
4544 | case KEY_dump: | |
a0d0e21e | 4545 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4546 | LOOPX(OP_DUMP); |
4547 | ||
4548 | case KEY_else: | |
4549 | PREBLOCK(ELSE); | |
4550 | ||
4551 | case KEY_elsif: | |
57843af0 | 4552 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
4553 | OPERATOR(ELSIF); |
4554 | ||
4555 | case KEY_eq: | |
4556 | Eop(OP_SEQ); | |
4557 | ||
a0d0e21e LW |
4558 | case KEY_exists: |
4559 | UNI(OP_EXISTS); | |
4e553d73 | 4560 | |
79072805 LW |
4561 | case KEY_exit: |
4562 | UNI(OP_EXIT); | |
4563 | ||
4564 | case KEY_eval: | |
79072805 | 4565 | s = skipspace(s); |
3280af22 | 4566 | PL_expect = (*s == '{') ? XTERMBLOCK : XTERM; |
463ee0b2 | 4567 | UNIBRACK(OP_ENTEREVAL); |
79072805 LW |
4568 | |
4569 | case KEY_eof: | |
4570 | UNI(OP_EOF); | |
4571 | ||
c963b151 BD |
4572 | case KEY_err: |
4573 | OPERATOR(DOROP); | |
4574 | ||
79072805 LW |
4575 | case KEY_exp: |
4576 | UNI(OP_EXP); | |
4577 | ||
4578 | case KEY_each: | |
4579 | UNI(OP_EACH); | |
4580 | ||
4581 | case KEY_exec: | |
4582 | set_csh(); | |
a0d0e21e | 4583 | LOP(OP_EXEC,XREF); |
79072805 LW |
4584 | |
4585 | case KEY_endhostent: | |
4586 | FUN0(OP_EHOSTENT); | |
4587 | ||
4588 | case KEY_endnetent: | |
4589 | FUN0(OP_ENETENT); | |
4590 | ||
4591 | case KEY_endservent: | |
4592 | FUN0(OP_ESERVENT); | |
4593 | ||
4594 | case KEY_endprotoent: | |
4595 | FUN0(OP_EPROTOENT); | |
4596 | ||
4597 | case KEY_endpwent: | |
4598 | FUN0(OP_EPWENT); | |
4599 | ||
4600 | case KEY_endgrent: | |
4601 | FUN0(OP_EGRENT); | |
4602 | ||
4603 | case KEY_for: | |
4604 | case KEY_foreach: | |
57843af0 | 4605 | yylval.ival = CopLINE(PL_curcop); |
55497cff | 4606 | s = skipspace(s); |
7e2040f0 | 4607 | if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) { |
55497cff | 4608 | char *p = s; |
3280af22 | 4609 | if ((PL_bufend - p) >= 3 && |
55497cff | 4610 | strnEQ(p, "my", 2) && isSPACE(*(p + 2))) |
4611 | p += 2; | |
77ca0c92 LW |
4612 | else if ((PL_bufend - p) >= 4 && |
4613 | strnEQ(p, "our", 3) && isSPACE(*(p + 3))) | |
4614 | p += 3; | |
55497cff | 4615 | p = skipspace(p); |
7e2040f0 | 4616 | if (isIDFIRST_lazy_if(p,UTF)) { |
77ca0c92 LW |
4617 | p = scan_ident(p, PL_bufend, |
4618 | PL_tokenbuf, sizeof PL_tokenbuf, TRUE); | |
4619 | p = skipspace(p); | |
4620 | } | |
4621 | if (*p != '$') | |
cea2e8a9 | 4622 | Perl_croak(aTHX_ "Missing $ on loop variable"); |
55497cff | 4623 | } |
79072805 LW |
4624 | OPERATOR(FOR); |
4625 | ||
4626 | case KEY_formline: | |
a0d0e21e | 4627 | LOP(OP_FORMLINE,XTERM); |
79072805 LW |
4628 | |
4629 | case KEY_fork: | |
4630 | FUN0(OP_FORK); | |
4631 | ||
4632 | case KEY_fcntl: | |
a0d0e21e | 4633 | LOP(OP_FCNTL,XTERM); |
79072805 LW |
4634 | |
4635 | case KEY_fileno: | |
4636 | UNI(OP_FILENO); | |
4637 | ||
4638 | case KEY_flock: | |
a0d0e21e | 4639 | LOP(OP_FLOCK,XTERM); |
79072805 LW |
4640 | |
4641 | case KEY_gt: | |
4642 | Rop(OP_SGT); | |
4643 | ||
4644 | case KEY_ge: | |
4645 | Rop(OP_SGE); | |
4646 | ||
4647 | case KEY_grep: | |
2c38e13d | 4648 | LOP(OP_GREPSTART, XREF); |
79072805 LW |
4649 | |
4650 | case KEY_goto: | |
a0d0e21e | 4651 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4652 | LOOPX(OP_GOTO); |
4653 | ||
4654 | case KEY_gmtime: | |
4655 | UNI(OP_GMTIME); | |
4656 | ||
4657 | case KEY_getc: | |
6f33ba73 | 4658 | UNIDOR(OP_GETC); |
79072805 LW |
4659 | |
4660 | case KEY_getppid: | |
4661 | FUN0(OP_GETPPID); | |
4662 | ||
4663 | case KEY_getpgrp: | |
4664 | UNI(OP_GETPGRP); | |
4665 | ||
4666 | case KEY_getpriority: | |
a0d0e21e | 4667 | LOP(OP_GETPRIORITY,XTERM); |
79072805 LW |
4668 | |
4669 | case KEY_getprotobyname: | |
4670 | UNI(OP_GPBYNAME); | |
4671 | ||
4672 | case KEY_getprotobynumber: | |
a0d0e21e | 4673 | LOP(OP_GPBYNUMBER,XTERM); |
79072805 LW |
4674 | |
4675 | case KEY_getprotoent: | |
4676 | FUN0(OP_GPROTOENT); | |
4677 | ||
4678 | case KEY_getpwent: | |
4679 | FUN0(OP_GPWENT); | |
4680 | ||
4681 | case KEY_getpwnam: | |
ff68c719 | 4682 | UNI(OP_GPWNAM); |
79072805 LW |
4683 | |
4684 | case KEY_getpwuid: | |
ff68c719 | 4685 | UNI(OP_GPWUID); |
79072805 LW |
4686 | |
4687 | case KEY_getpeername: | |
4688 | UNI(OP_GETPEERNAME); | |
4689 | ||
4690 | case KEY_gethostbyname: | |
4691 | UNI(OP_GHBYNAME); | |
4692 | ||
4693 | case KEY_gethostbyaddr: | |
a0d0e21e | 4694 | LOP(OP_GHBYADDR,XTERM); |
79072805 LW |
4695 | |
4696 | case KEY_gethostent: | |
4697 | FUN0(OP_GHOSTENT); | |
4698 | ||
4699 | case KEY_getnetbyname: | |
4700 | UNI(OP_GNBYNAME); | |
4701 | ||
4702 | case KEY_getnetbyaddr: | |
a0d0e21e | 4703 | LOP(OP_GNBYADDR,XTERM); |
79072805 LW |
4704 | |
4705 | case KEY_getnetent: | |
4706 | FUN0(OP_GNETENT); | |
4707 | ||
4708 | case KEY_getservbyname: | |
a0d0e21e | 4709 | LOP(OP_GSBYNAME,XTERM); |
79072805 LW |
4710 | |
4711 | case KEY_getservbyport: | |
a0d0e21e | 4712 | LOP(OP_GSBYPORT,XTERM); |
79072805 LW |
4713 | |
4714 | case KEY_getservent: | |
4715 | FUN0(OP_GSERVENT); | |
4716 | ||
4717 | case KEY_getsockname: | |
4718 | UNI(OP_GETSOCKNAME); | |
4719 | ||
4720 | case KEY_getsockopt: | |
a0d0e21e | 4721 | LOP(OP_GSOCKOPT,XTERM); |
79072805 LW |
4722 | |
4723 | case KEY_getgrent: | |
4724 | FUN0(OP_GGRENT); | |
4725 | ||
4726 | case KEY_getgrnam: | |
ff68c719 | 4727 | UNI(OP_GGRNAM); |
79072805 LW |
4728 | |
4729 | case KEY_getgrgid: | |
ff68c719 | 4730 | UNI(OP_GGRGID); |
79072805 LW |
4731 | |
4732 | case KEY_getlogin: | |
4733 | FUN0(OP_GETLOGIN); | |
4734 | ||
93a17b20 | 4735 | case KEY_glob: |
a0d0e21e LW |
4736 | set_csh(); |
4737 | LOP(OP_GLOB,XTERM); | |
93a17b20 | 4738 | |
79072805 LW |
4739 | case KEY_hex: |
4740 | UNI(OP_HEX); | |
4741 | ||
4742 | case KEY_if: | |
57843af0 | 4743 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
4744 | OPERATOR(IF); |
4745 | ||
4746 | case KEY_index: | |
a0d0e21e | 4747 | LOP(OP_INDEX,XTERM); |
79072805 LW |
4748 | |
4749 | case KEY_int: | |
4750 | UNI(OP_INT); | |
4751 | ||
4752 | case KEY_ioctl: | |
a0d0e21e | 4753 | LOP(OP_IOCTL,XTERM); |
79072805 LW |
4754 | |
4755 | case KEY_join: | |
a0d0e21e | 4756 | LOP(OP_JOIN,XTERM); |
79072805 LW |
4757 | |
4758 | case KEY_keys: | |
4759 | UNI(OP_KEYS); | |
4760 | ||
4761 | case KEY_kill: | |
a0d0e21e | 4762 | LOP(OP_KILL,XTERM); |
79072805 LW |
4763 | |
4764 | case KEY_last: | |
a0d0e21e | 4765 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 | 4766 | LOOPX(OP_LAST); |
4e553d73 | 4767 | |
79072805 LW |
4768 | case KEY_lc: |
4769 | UNI(OP_LC); | |
4770 | ||
4771 | case KEY_lcfirst: | |
4772 | UNI(OP_LCFIRST); | |
4773 | ||
4774 | case KEY_local: | |
09bef843 | 4775 | yylval.ival = 0; |
79072805 LW |
4776 | OPERATOR(LOCAL); |
4777 | ||
4778 | case KEY_length: | |
4779 | UNI(OP_LENGTH); | |
4780 | ||
4781 | case KEY_lt: | |
4782 | Rop(OP_SLT); | |
4783 | ||
4784 | case KEY_le: | |
4785 | Rop(OP_SLE); | |
4786 | ||
4787 | case KEY_localtime: | |
4788 | UNI(OP_LOCALTIME); | |
4789 | ||
4790 | case KEY_log: | |
4791 | UNI(OP_LOG); | |
4792 | ||
4793 | case KEY_link: | |
a0d0e21e | 4794 | LOP(OP_LINK,XTERM); |
79072805 LW |
4795 | |
4796 | case KEY_listen: | |
a0d0e21e | 4797 | LOP(OP_LISTEN,XTERM); |
79072805 | 4798 | |
c0329465 MB |
4799 | case KEY_lock: |
4800 | UNI(OP_LOCK); | |
4801 | ||
79072805 LW |
4802 | case KEY_lstat: |
4803 | UNI(OP_LSTAT); | |
4804 | ||
4805 | case KEY_m: | |
8782bef2 | 4806 | s = scan_pat(s,OP_MATCH); |
79072805 LW |
4807 | TERM(sublex_start()); |
4808 | ||
a0d0e21e | 4809 | case KEY_map: |
2c38e13d | 4810 | LOP(OP_MAPSTART, XREF); |
4e4e412b | 4811 | |
79072805 | 4812 | case KEY_mkdir: |
a0d0e21e | 4813 | LOP(OP_MKDIR,XTERM); |
79072805 LW |
4814 | |
4815 | case KEY_msgctl: | |
a0d0e21e | 4816 | LOP(OP_MSGCTL,XTERM); |
79072805 LW |
4817 | |
4818 | case KEY_msgget: | |
a0d0e21e | 4819 | LOP(OP_MSGGET,XTERM); |
79072805 LW |
4820 | |
4821 | case KEY_msgrcv: | |
a0d0e21e | 4822 | LOP(OP_MSGRCV,XTERM); |
79072805 LW |
4823 | |
4824 | case KEY_msgsnd: | |
a0d0e21e | 4825 | LOP(OP_MSGSND,XTERM); |
79072805 | 4826 | |
77ca0c92 | 4827 | case KEY_our: |
93a17b20 | 4828 | case KEY_my: |
77ca0c92 | 4829 | PL_in_my = tmp; |
c750a3ec | 4830 | s = skipspace(s); |
7e2040f0 | 4831 | if (isIDFIRST_lazy_if(s,UTF)) { |
3280af22 | 4832 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len); |
09bef843 SB |
4833 | if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3)) |
4834 | goto really_sub; | |
def3634b | 4835 | PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len); |
3280af22 | 4836 | if (!PL_in_my_stash) { |
c750a3ec | 4837 | char tmpbuf[1024]; |
3280af22 NIS |
4838 | PL_bufptr = s; |
4839 | sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf); | |
c750a3ec MB |
4840 | yyerror(tmpbuf); |
4841 | } | |
4842 | } | |
09bef843 | 4843 | yylval.ival = 1; |
55497cff | 4844 | OPERATOR(MY); |
93a17b20 | 4845 | |
79072805 | 4846 | case KEY_next: |
a0d0e21e | 4847 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
4848 | LOOPX(OP_NEXT); |
4849 | ||
4850 | case KEY_ne: | |
4851 | Eop(OP_SNE); | |
4852 | ||
a0d0e21e | 4853 | case KEY_no: |
3280af22 | 4854 | if (PL_expect != XSTATE) |
a0d0e21e LW |
4855 | yyerror("\"no\" not allowed in expression"); |
4856 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
e759cc13 | 4857 | s = force_version(s, FALSE); |
a0d0e21e LW |
4858 | yylval.ival = 0; |
4859 | OPERATOR(USE); | |
4860 | ||
4861 | case KEY_not: | |
2d2e263d LW |
4862 | if (*s == '(' || (s = skipspace(s), *s == '(')) |
4863 | FUN1(OP_NOT); | |
4864 | else | |
4865 | OPERATOR(NOTOP); | |
a0d0e21e | 4866 | |
79072805 | 4867 | case KEY_open: |
93a17b20 | 4868 | s = skipspace(s); |
7e2040f0 | 4869 | if (isIDFIRST_lazy_if(s,UTF)) { |
93a17b20 | 4870 | char *t; |
7e2040f0 | 4871 | for (d = s; isALNUM_lazy_if(d,UTF); d++) ; |
e2ab214b DM |
4872 | for (t=d; *t && isSPACE(*t); t++) ; |
4873 | if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE) | |
66fbe8fb HS |
4874 | /* [perl #16184] */ |
4875 | && !(t[0] == '=' && t[1] == '>') | |
4876 | ) { | |
9014280d | 4877 | Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE), |
0453d815 | 4878 | "Precedence problem: open %.*s should be open(%.*s)", |
66fbe8fb HS |
4879 | d - s, s, d - s, s); |
4880 | } | |
93a17b20 | 4881 | } |
a0d0e21e | 4882 | LOP(OP_OPEN,XTERM); |
79072805 | 4883 | |
463ee0b2 | 4884 | case KEY_or: |
a0d0e21e | 4885 | yylval.ival = OP_OR; |
463ee0b2 LW |
4886 | OPERATOR(OROP); |
4887 | ||
79072805 LW |
4888 | case KEY_ord: |
4889 | UNI(OP_ORD); | |
4890 | ||
4891 | case KEY_oct: | |
4892 | UNI(OP_OCT); | |
4893 | ||
4894 | case KEY_opendir: | |
a0d0e21e | 4895 | LOP(OP_OPEN_DIR,XTERM); |
79072805 LW |
4896 | |
4897 | case KEY_print: | |
3280af22 | 4898 | checkcomma(s,PL_tokenbuf,"filehandle"); |
a0d0e21e | 4899 | LOP(OP_PRINT,XREF); |
79072805 LW |
4900 | |
4901 | case KEY_printf: | |
3280af22 | 4902 | checkcomma(s,PL_tokenbuf,"filehandle"); |
a0d0e21e | 4903 | LOP(OP_PRTF,XREF); |
79072805 | 4904 | |
c07a80fd | 4905 | case KEY_prototype: |
4906 | UNI(OP_PROTOTYPE); | |
4907 | ||
79072805 | 4908 | case KEY_push: |
a0d0e21e | 4909 | LOP(OP_PUSH,XTERM); |
79072805 LW |
4910 | |
4911 | case KEY_pop: | |
6f33ba73 | 4912 | UNIDOR(OP_POP); |
79072805 | 4913 | |
a0d0e21e | 4914 | case KEY_pos: |
6f33ba73 | 4915 | UNIDOR(OP_POS); |
4e553d73 | 4916 | |
79072805 | 4917 | case KEY_pack: |
a0d0e21e | 4918 | LOP(OP_PACK,XTERM); |
79072805 LW |
4919 | |
4920 | case KEY_package: | |
a0d0e21e | 4921 | s = force_word(s,WORD,FALSE,TRUE,FALSE); |
79072805 LW |
4922 | OPERATOR(PACKAGE); |
4923 | ||
4924 | case KEY_pipe: | |
a0d0e21e | 4925 | LOP(OP_PIPE_OP,XTERM); |
79072805 LW |
4926 | |
4927 | case KEY_q: | |
09bef843 | 4928 | s = scan_str(s,FALSE,FALSE); |
79072805 | 4929 | if (!s) |
85e6fe83 | 4930 | missingterm((char*)0); |
79072805 LW |
4931 | yylval.ival = OP_CONST; |
4932 | TERM(sublex_start()); | |
4933 | ||
a0d0e21e LW |
4934 | case KEY_quotemeta: |
4935 | UNI(OP_QUOTEMETA); | |
4936 | ||
8990e307 | 4937 | case KEY_qw: |
09bef843 | 4938 | s = scan_str(s,FALSE,FALSE); |
8990e307 | 4939 | if (!s) |
85e6fe83 | 4940 | missingterm((char*)0); |
8127e0e3 GS |
4941 | force_next(')'); |
4942 | if (SvCUR(PL_lex_stuff)) { | |
4943 | OP *words = Nullop; | |
4944 | int warned = 0; | |
3280af22 | 4945 | d = SvPV_force(PL_lex_stuff, len); |
8127e0e3 | 4946 | while (len) { |
7948272d | 4947 | SV *sv; |
8127e0e3 GS |
4948 | for (; isSPACE(*d) && len; --len, ++d) ; |
4949 | if (len) { | |
4950 | char *b = d; | |
e476b1b5 | 4951 | if (!warned && ckWARN(WARN_QW)) { |
8127e0e3 GS |
4952 | for (; !isSPACE(*d) && len; --len, ++d) { |
4953 | if (*d == ',') { | |
9014280d | 4954 | Perl_warner(aTHX_ packWARN(WARN_QW), |
8127e0e3 GS |
4955 | "Possible attempt to separate words with commas"); |
4956 | ++warned; | |
4957 | } | |
4958 | else if (*d == '#') { | |
9014280d | 4959 | Perl_warner(aTHX_ packWARN(WARN_QW), |
8127e0e3 GS |
4960 | "Possible attempt to put comments in qw() list"); |
4961 | ++warned; | |
4962 | } | |
4963 | } | |
4964 | } | |
4965 | else { | |
4966 | for (; !isSPACE(*d) && len; --len, ++d) ; | |
4967 | } | |
7948272d NIS |
4968 | sv = newSVpvn(b, d-b); |
4969 | if (DO_UTF8(PL_lex_stuff)) | |
4970 | SvUTF8_on(sv); | |
8127e0e3 | 4971 | words = append_elem(OP_LIST, words, |
7948272d | 4972 | newSVOP(OP_CONST, 0, tokeq(sv))); |
55497cff | 4973 | } |
4974 | } | |
8127e0e3 GS |
4975 | if (words) { |
4976 | PL_nextval[PL_nexttoke].opval = words; | |
4977 | force_next(THING); | |
4978 | } | |
55497cff | 4979 | } |
37fd879b | 4980 | if (PL_lex_stuff) { |
8127e0e3 | 4981 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
4982 | PL_lex_stuff = Nullsv; |
4983 | } | |
3280af22 | 4984 | PL_expect = XTERM; |
8127e0e3 | 4985 | TOKEN('('); |
8990e307 | 4986 | |
79072805 | 4987 | case KEY_qq: |
09bef843 | 4988 | s = scan_str(s,FALSE,FALSE); |
79072805 | 4989 | if (!s) |
85e6fe83 | 4990 | missingterm((char*)0); |
a0d0e21e | 4991 | yylval.ival = OP_STRINGIFY; |
3280af22 NIS |
4992 | if (SvIVX(PL_lex_stuff) == '\'') |
4993 | SvIVX(PL_lex_stuff) = 0; /* qq'$foo' should intepolate */ | |
79072805 LW |
4994 | TERM(sublex_start()); |
4995 | ||
8782bef2 GB |
4996 | case KEY_qr: |
4997 | s = scan_pat(s,OP_QR); | |
4998 | TERM(sublex_start()); | |
4999 | ||
79072805 | 5000 | case KEY_qx: |
09bef843 | 5001 | s = scan_str(s,FALSE,FALSE); |
79072805 | 5002 | if (!s) |
85e6fe83 | 5003 | missingterm((char*)0); |
79072805 LW |
5004 | yylval.ival = OP_BACKTICK; |
5005 | set_csh(); | |
5006 | TERM(sublex_start()); | |
5007 | ||
5008 | case KEY_return: | |
5009 | OLDLOP(OP_RETURN); | |
5010 | ||
5011 | case KEY_require: | |
a7cb1f99 | 5012 | s = skipspace(s); |
e759cc13 RGS |
5013 | if (isDIGIT(*s)) { |
5014 | s = force_version(s, FALSE); | |
a7cb1f99 | 5015 | } |
e759cc13 RGS |
5016 | else if (*s != 'v' || !isDIGIT(s[1]) |
5017 | || (s = force_version(s, TRUE), *s == 'v')) | |
5018 | { | |
a7cb1f99 GS |
5019 | *PL_tokenbuf = '\0'; |
5020 | s = force_word(s,WORD,TRUE,TRUE,FALSE); | |
7e2040f0 | 5021 | if (isIDFIRST_lazy_if(PL_tokenbuf,UTF)) |
a7cb1f99 GS |
5022 | gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE); |
5023 | else if (*s == '<') | |
5024 | yyerror("<> should be quotes"); | |
5025 | } | |
463ee0b2 | 5026 | UNI(OP_REQUIRE); |
79072805 LW |
5027 | |
5028 | case KEY_reset: | |
5029 | UNI(OP_RESET); | |
5030 | ||
5031 | case KEY_redo: | |
a0d0e21e | 5032 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
79072805 LW |
5033 | LOOPX(OP_REDO); |
5034 | ||
5035 | case KEY_rename: | |
a0d0e21e | 5036 | LOP(OP_RENAME,XTERM); |
79072805 LW |
5037 | |
5038 | case KEY_rand: | |
5039 | UNI(OP_RAND); | |
5040 | ||
5041 | case KEY_rmdir: | |
5042 | UNI(OP_RMDIR); | |
5043 | ||
5044 | case KEY_rindex: | |
a0d0e21e | 5045 | LOP(OP_RINDEX,XTERM); |
79072805 LW |
5046 | |
5047 | case KEY_read: | |
a0d0e21e | 5048 | LOP(OP_READ,XTERM); |
79072805 LW |
5049 | |
5050 | case KEY_readdir: | |
5051 | UNI(OP_READDIR); | |
5052 | ||
93a17b20 LW |
5053 | case KEY_readline: |
5054 | set_csh(); | |
6f33ba73 | 5055 | UNIDOR(OP_READLINE); |
93a17b20 LW |
5056 | |
5057 | case KEY_readpipe: | |
5058 | set_csh(); | |
5059 | UNI(OP_BACKTICK); | |
5060 | ||
79072805 LW |
5061 | case KEY_rewinddir: |
5062 | UNI(OP_REWINDDIR); | |
5063 | ||
5064 | case KEY_recv: | |
a0d0e21e | 5065 | LOP(OP_RECV,XTERM); |
79072805 LW |
5066 | |
5067 | case KEY_reverse: | |
a0d0e21e | 5068 | LOP(OP_REVERSE,XTERM); |
79072805 LW |
5069 | |
5070 | case KEY_readlink: | |
6f33ba73 | 5071 | UNIDOR(OP_READLINK); |
79072805 LW |
5072 | |
5073 | case KEY_ref: | |
5074 | UNI(OP_REF); | |
5075 | ||
5076 | case KEY_s: | |
5077 | s = scan_subst(s); | |
5078 | if (yylval.opval) | |
5079 | TERM(sublex_start()); | |
5080 | else | |
5081 | TOKEN(1); /* force error */ | |
5082 | ||
a0d0e21e LW |
5083 | case KEY_chomp: |
5084 | UNI(OP_CHOMP); | |
4e553d73 | 5085 | |
79072805 LW |
5086 | case KEY_scalar: |
5087 | UNI(OP_SCALAR); | |
5088 | ||
5089 | case KEY_select: | |
a0d0e21e | 5090 | LOP(OP_SELECT,XTERM); |
79072805 LW |
5091 | |
5092 | case KEY_seek: | |
a0d0e21e | 5093 | LOP(OP_SEEK,XTERM); |
79072805 LW |
5094 | |
5095 | case KEY_semctl: | |
a0d0e21e | 5096 | LOP(OP_SEMCTL,XTERM); |
79072805 LW |
5097 | |
5098 | case KEY_semget: | |
a0d0e21e | 5099 | LOP(OP_SEMGET,XTERM); |
79072805 LW |
5100 | |
5101 | case KEY_semop: | |
a0d0e21e | 5102 | LOP(OP_SEMOP,XTERM); |
79072805 LW |
5103 | |
5104 | case KEY_send: | |
a0d0e21e | 5105 | LOP(OP_SEND,XTERM); |
79072805 LW |
5106 | |
5107 | case KEY_setpgrp: | |
a0d0e21e | 5108 | LOP(OP_SETPGRP,XTERM); |
79072805 LW |
5109 | |
5110 | case KEY_setpriority: | |
a0d0e21e | 5111 | LOP(OP_SETPRIORITY,XTERM); |
79072805 LW |
5112 | |
5113 | case KEY_sethostent: | |
ff68c719 | 5114 | UNI(OP_SHOSTENT); |
79072805 LW |
5115 | |
5116 | case KEY_setnetent: | |
ff68c719 | 5117 | UNI(OP_SNETENT); |
79072805 LW |
5118 | |
5119 | case KEY_setservent: | |
ff68c719 | 5120 | UNI(OP_SSERVENT); |
79072805 LW |
5121 | |
5122 | case KEY_setprotoent: | |
ff68c719 | 5123 | UNI(OP_SPROTOENT); |
79072805 LW |
5124 | |
5125 | case KEY_setpwent: | |
5126 | FUN0(OP_SPWENT); | |
5127 | ||
5128 | case KEY_setgrent: | |
5129 | FUN0(OP_SGRENT); | |
5130 | ||
5131 | case KEY_seekdir: | |
a0d0e21e | 5132 | LOP(OP_SEEKDIR,XTERM); |
79072805 LW |
5133 | |
5134 | case KEY_setsockopt: | |
a0d0e21e | 5135 | LOP(OP_SSOCKOPT,XTERM); |
79072805 LW |
5136 | |
5137 | case KEY_shift: | |
6f33ba73 | 5138 | UNIDOR(OP_SHIFT); |
79072805 LW |
5139 | |
5140 | case KEY_shmctl: | |
a0d0e21e | 5141 | LOP(OP_SHMCTL,XTERM); |
79072805 LW |
5142 | |
5143 | case KEY_shmget: | |
a0d0e21e | 5144 | LOP(OP_SHMGET,XTERM); |
79072805 LW |
5145 | |
5146 | case KEY_shmread: | |
a0d0e21e | 5147 | LOP(OP_SHMREAD,XTERM); |
79072805 LW |
5148 | |
5149 | case KEY_shmwrite: | |
a0d0e21e | 5150 | LOP(OP_SHMWRITE,XTERM); |
79072805 LW |
5151 | |
5152 | case KEY_shutdown: | |
a0d0e21e | 5153 | LOP(OP_SHUTDOWN,XTERM); |
79072805 LW |
5154 | |
5155 | case KEY_sin: | |
5156 | UNI(OP_SIN); | |
5157 | ||
5158 | case KEY_sleep: | |
5159 | UNI(OP_SLEEP); | |
5160 | ||
5161 | case KEY_socket: | |
a0d0e21e | 5162 | LOP(OP_SOCKET,XTERM); |
79072805 LW |
5163 | |
5164 | case KEY_socketpair: | |
a0d0e21e | 5165 | LOP(OP_SOCKPAIR,XTERM); |
79072805 LW |
5166 | |
5167 | case KEY_sort: | |
3280af22 | 5168 | checkcomma(s,PL_tokenbuf,"subroutine name"); |
79072805 LW |
5169 | s = skipspace(s); |
5170 | if (*s == ';' || *s == ')') /* probably a close */ | |
cea2e8a9 | 5171 | Perl_croak(aTHX_ "sort is now a reserved word"); |
3280af22 | 5172 | PL_expect = XTERM; |
15f0808c | 5173 | s = force_word(s,WORD,TRUE,TRUE,FALSE); |
a0d0e21e | 5174 | LOP(OP_SORT,XREF); |
79072805 LW |
5175 | |
5176 | case KEY_split: | |
a0d0e21e | 5177 | LOP(OP_SPLIT,XTERM); |
79072805 LW |
5178 | |
5179 | case KEY_sprintf: | |
a0d0e21e | 5180 | LOP(OP_SPRINTF,XTERM); |
79072805 LW |
5181 | |
5182 | case KEY_splice: | |
a0d0e21e | 5183 | LOP(OP_SPLICE,XTERM); |
79072805 LW |
5184 | |
5185 | case KEY_sqrt: | |
5186 | UNI(OP_SQRT); | |
5187 | ||
5188 | case KEY_srand: | |
5189 | UNI(OP_SRAND); | |
5190 | ||
5191 | case KEY_stat: | |
5192 | UNI(OP_STAT); | |
5193 | ||
5194 | case KEY_study: | |
79072805 LW |
5195 | UNI(OP_STUDY); |
5196 | ||
5197 | case KEY_substr: | |
a0d0e21e | 5198 | LOP(OP_SUBSTR,XTERM); |
79072805 LW |
5199 | |
5200 | case KEY_format: | |
5201 | case KEY_sub: | |
93a17b20 | 5202 | really_sub: |
09bef843 | 5203 | { |
3280af22 | 5204 | char tmpbuf[sizeof PL_tokenbuf]; |
9c5ffd7c | 5205 | SSize_t tboffset = 0; |
09bef843 | 5206 | expectation attrful; |
d731386a | 5207 | bool have_name, have_proto, bad_proto; |
09bef843 SB |
5208 | int key = tmp; |
5209 | ||
5210 | s = skipspace(s); | |
5211 | ||
7e2040f0 | 5212 | if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' || |
09bef843 SB |
5213 | (*s == ':' && s[1] == ':')) |
5214 | { | |
5215 | PL_expect = XBLOCK; | |
5216 | attrful = XATTRBLOCK; | |
b1b65b59 JH |
5217 | /* remember buffer pos'n for later force_word */ |
5218 | tboffset = s - PL_oldbufptr; | |
09bef843 SB |
5219 | d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
5220 | if (strchr(tmpbuf, ':')) | |
5221 | sv_setpv(PL_subname, tmpbuf); | |
5222 | else { | |
5223 | sv_setsv(PL_subname,PL_curstname); | |
5224 | sv_catpvn(PL_subname,"::",2); | |
5225 | sv_catpvn(PL_subname,tmpbuf,len); | |
5226 | } | |
5227 | s = skipspace(d); | |
5228 | have_name = TRUE; | |
5229 | } | |
463ee0b2 | 5230 | else { |
09bef843 SB |
5231 | if (key == KEY_my) |
5232 | Perl_croak(aTHX_ "Missing name in \"my sub\""); | |
5233 | PL_expect = XTERMBLOCK; | |
5234 | attrful = XATTRTERM; | |
5235 | sv_setpv(PL_subname,"?"); | |
5236 | have_name = FALSE; | |
463ee0b2 | 5237 | } |
4633a7c4 | 5238 | |
09bef843 SB |
5239 | if (key == KEY_format) { |
5240 | if (*s == '=') | |
5241 | PL_lex_formbrack = PL_lex_brackets + 1; | |
5242 | if (have_name) | |
b1b65b59 JH |
5243 | (void) force_word(PL_oldbufptr + tboffset, WORD, |
5244 | FALSE, TRUE, TRUE); | |
09bef843 SB |
5245 | OPERATOR(FORMAT); |
5246 | } | |
79072805 | 5247 | |
09bef843 SB |
5248 | /* Look for a prototype */ |
5249 | if (*s == '(') { | |
5250 | char *p; | |
5251 | ||
5252 | s = scan_str(s,FALSE,FALSE); | |
37fd879b | 5253 | if (!s) |
09bef843 | 5254 | Perl_croak(aTHX_ "Prototype not terminated"); |
2f758a16 | 5255 | /* strip spaces and check for bad characters */ |
09bef843 SB |
5256 | d = SvPVX(PL_lex_stuff); |
5257 | tmp = 0; | |
d731386a | 5258 | bad_proto = FALSE; |
09bef843 | 5259 | for (p = d; *p; ++p) { |
d37a9538 | 5260 | if (!isSPACE(*p)) { |
09bef843 | 5261 | d[tmp++] = *p; |
d37a9538 ST |
5262 | if (!strchr("$@%*;[]&\\", *p)) |
5263 | bad_proto = TRUE; | |
5264 | } | |
09bef843 SB |
5265 | } |
5266 | d[tmp] = '\0'; | |
420cdfc1 | 5267 | if (bad_proto && ckWARN(WARN_SYNTAX)) |
9014280d | 5268 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
35c1215d NC |
5269 | "Illegal character in prototype for %"SVf" : %s", |
5270 | PL_subname, d); | |
09bef843 SB |
5271 | SvCUR(PL_lex_stuff) = tmp; |
5272 | have_proto = TRUE; | |
68dc0745 | 5273 | |
09bef843 | 5274 | s = skipspace(s); |
4633a7c4 | 5275 | } |
09bef843 SB |
5276 | else |
5277 | have_proto = FALSE; | |
5278 | ||
5279 | if (*s == ':' && s[1] != ':') | |
5280 | PL_expect = attrful; | |
8e742a20 MHM |
5281 | else if (*s != '{' && key == KEY_sub) { |
5282 | if (!have_name) | |
5283 | Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine"); | |
5284 | else if (*s != ';') | |
5285 | Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname); | |
5286 | } | |
09bef843 SB |
5287 | |
5288 | if (have_proto) { | |
b1b65b59 JH |
5289 | PL_nextval[PL_nexttoke].opval = |
5290 | (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff); | |
09bef843 SB |
5291 | PL_lex_stuff = Nullsv; |
5292 | force_next(THING); | |
68dc0745 | 5293 | } |
09bef843 | 5294 | if (!have_name) { |
c99da370 JH |
5295 | sv_setpv(PL_subname, |
5296 | PL_curstash ? "__ANON__" : "__ANON__::__ANON__"); | |
09bef843 | 5297 | TOKEN(ANONSUB); |
4633a7c4 | 5298 | } |
b1b65b59 JH |
5299 | (void) force_word(PL_oldbufptr + tboffset, WORD, |
5300 | FALSE, TRUE, TRUE); | |
09bef843 SB |
5301 | if (key == KEY_my) |
5302 | TOKEN(MYSUB); | |
5303 | TOKEN(SUB); | |
4633a7c4 | 5304 | } |
79072805 LW |
5305 | |
5306 | case KEY_system: | |
5307 | set_csh(); | |
a0d0e21e | 5308 | LOP(OP_SYSTEM,XREF); |
79072805 LW |
5309 | |
5310 | case KEY_symlink: | |
a0d0e21e | 5311 | LOP(OP_SYMLINK,XTERM); |
79072805 LW |
5312 | |
5313 | case KEY_syscall: | |
a0d0e21e | 5314 | LOP(OP_SYSCALL,XTERM); |
79072805 | 5315 | |
c07a80fd | 5316 | case KEY_sysopen: |
5317 | LOP(OP_SYSOPEN,XTERM); | |
5318 | ||
137443ea | 5319 | case KEY_sysseek: |
5320 | LOP(OP_SYSSEEK,XTERM); | |
5321 | ||
79072805 | 5322 | case KEY_sysread: |
a0d0e21e | 5323 | LOP(OP_SYSREAD,XTERM); |
79072805 LW |
5324 | |
5325 | case KEY_syswrite: | |
a0d0e21e | 5326 | LOP(OP_SYSWRITE,XTERM); |
79072805 LW |
5327 | |
5328 | case KEY_tr: | |
5329 | s = scan_trans(s); | |
5330 | TERM(sublex_start()); | |
5331 | ||
5332 | case KEY_tell: | |
5333 | UNI(OP_TELL); | |
5334 | ||
5335 | case KEY_telldir: | |
5336 | UNI(OP_TELLDIR); | |
5337 | ||
463ee0b2 | 5338 | case KEY_tie: |
a0d0e21e | 5339 | LOP(OP_TIE,XTERM); |
463ee0b2 | 5340 | |
c07a80fd | 5341 | case KEY_tied: |
5342 | UNI(OP_TIED); | |
5343 | ||
79072805 LW |
5344 | case KEY_time: |
5345 | FUN0(OP_TIME); | |
5346 | ||
5347 | case KEY_times: | |
5348 | FUN0(OP_TMS); | |
5349 | ||
5350 | case KEY_truncate: | |
a0d0e21e | 5351 | LOP(OP_TRUNCATE,XTERM); |
79072805 LW |
5352 | |
5353 | case KEY_uc: | |
5354 | UNI(OP_UC); | |
5355 | ||
5356 | case KEY_ucfirst: | |
5357 | UNI(OP_UCFIRST); | |
5358 | ||
463ee0b2 LW |
5359 | case KEY_untie: |
5360 | UNI(OP_UNTIE); | |
5361 | ||
79072805 | 5362 | case KEY_until: |
57843af0 | 5363 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5364 | OPERATOR(UNTIL); |
5365 | ||
5366 | case KEY_unless: | |
57843af0 | 5367 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5368 | OPERATOR(UNLESS); |
5369 | ||
5370 | case KEY_unlink: | |
a0d0e21e | 5371 | LOP(OP_UNLINK,XTERM); |
79072805 LW |
5372 | |
5373 | case KEY_undef: | |
6f33ba73 | 5374 | UNIDOR(OP_UNDEF); |
79072805 LW |
5375 | |
5376 | case KEY_unpack: | |
a0d0e21e | 5377 | LOP(OP_UNPACK,XTERM); |
79072805 LW |
5378 | |
5379 | case KEY_utime: | |
a0d0e21e | 5380 | LOP(OP_UTIME,XTERM); |
79072805 LW |
5381 | |
5382 | case KEY_umask: | |
6f33ba73 | 5383 | UNIDOR(OP_UMASK); |
79072805 LW |
5384 | |
5385 | case KEY_unshift: | |
a0d0e21e LW |
5386 | LOP(OP_UNSHIFT,XTERM); |
5387 | ||
5388 | case KEY_use: | |
3280af22 | 5389 | if (PL_expect != XSTATE) |
a0d0e21e | 5390 | yyerror("\"use\" not allowed in expression"); |
89bfa8cd | 5391 | s = skipspace(s); |
a7cb1f99 | 5392 | if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) { |
e759cc13 | 5393 | s = force_version(s, TRUE); |
a7cb1f99 | 5394 | if (*s == ';' || (s = skipspace(s), *s == ';')) { |
3280af22 | 5395 | PL_nextval[PL_nexttoke].opval = Nullop; |
89bfa8cd | 5396 | force_next(WORD); |
5397 | } | |
e759cc13 RGS |
5398 | else if (*s == 'v') { |
5399 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
5400 | s = force_version(s, FALSE); | |
5401 | } | |
89bfa8cd | 5402 | } |
5403 | else { | |
5404 | s = force_word(s,WORD,FALSE,TRUE,FALSE); | |
e759cc13 | 5405 | s = force_version(s, FALSE); |
89bfa8cd | 5406 | } |
a0d0e21e LW |
5407 | yylval.ival = 1; |
5408 | OPERATOR(USE); | |
79072805 LW |
5409 | |
5410 | case KEY_values: | |
5411 | UNI(OP_VALUES); | |
5412 | ||
5413 | case KEY_vec: | |
a0d0e21e | 5414 | LOP(OP_VEC,XTERM); |
79072805 LW |
5415 | |
5416 | case KEY_while: | |
57843af0 | 5417 | yylval.ival = CopLINE(PL_curcop); |
79072805 LW |
5418 | OPERATOR(WHILE); |
5419 | ||
5420 | case KEY_warn: | |
3280af22 | 5421 | PL_hints |= HINT_BLOCK_SCOPE; |
a0d0e21e | 5422 | LOP(OP_WARN,XTERM); |
79072805 LW |
5423 | |
5424 | case KEY_wait: | |
5425 | FUN0(OP_WAIT); | |
5426 | ||
5427 | case KEY_waitpid: | |
a0d0e21e | 5428 | LOP(OP_WAITPID,XTERM); |
79072805 LW |
5429 | |
5430 | case KEY_wantarray: | |
5431 | FUN0(OP_WANTARRAY); | |
5432 | ||
5433 | case KEY_write: | |
9d116dd7 JH |
5434 | #ifdef EBCDIC |
5435 | { | |
df3728a2 JH |
5436 | char ctl_l[2]; |
5437 | ctl_l[0] = toCTRL('L'); | |
5438 | ctl_l[1] = '\0'; | |
9d116dd7 JH |
5439 | gv_fetchpv(ctl_l,TRUE, SVt_PV); |
5440 | } | |
5441 | #else | |
5442 | gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */ | |
5443 | #endif | |
79072805 LW |
5444 | UNI(OP_ENTERWRITE); |
5445 | ||
5446 | case KEY_x: | |
3280af22 | 5447 | if (PL_expect == XOPERATOR) |
79072805 LW |
5448 | Mop(OP_REPEAT); |
5449 | check_uni(); | |
5450 | goto just_a_word; | |
5451 | ||
a0d0e21e LW |
5452 | case KEY_xor: |
5453 | yylval.ival = OP_XOR; | |
5454 | OPERATOR(OROP); | |
5455 | ||
79072805 LW |
5456 | case KEY_y: |
5457 | s = scan_trans(s); | |
5458 | TERM(sublex_start()); | |
5459 | } | |
49dc05e3 | 5460 | }} |
79072805 | 5461 | } |
bf4acbe4 GS |
5462 | #ifdef __SC__ |
5463 | #pragma segment Main | |
5464 | #endif | |
79072805 | 5465 | |
e930465f JH |
5466 | static int |
5467 | S_pending_ident(pTHX) | |
8eceec63 SC |
5468 | { |
5469 | register char *d; | |
a55b55d8 | 5470 | register I32 tmp = 0; |
8eceec63 SC |
5471 | /* pit holds the identifier we read and pending_ident is reset */ |
5472 | char pit = PL_pending_ident; | |
5473 | PL_pending_ident = 0; | |
5474 | ||
5475 | DEBUG_T({ PerlIO_printf(Perl_debug_log, | |
5476 | "### Tokener saw identifier '%s'\n", PL_tokenbuf); }); | |
5477 | ||
5478 | /* if we're in a my(), we can't allow dynamics here. | |
5479 | $foo'bar has already been turned into $foo::bar, so | |
5480 | just check for colons. | |
5481 | ||
5482 | if it's a legal name, the OP is a PADANY. | |
5483 | */ | |
5484 | if (PL_in_my) { | |
5485 | if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */ | |
5486 | if (strchr(PL_tokenbuf,':')) | |
5487 | yyerror(Perl_form(aTHX_ "No package name allowed for " | |
5488 | "variable %s in \"our\"", | |
5489 | PL_tokenbuf)); | |
dd2155a4 | 5490 | tmp = allocmy(PL_tokenbuf); |
8eceec63 SC |
5491 | } |
5492 | else { | |
5493 | if (strchr(PL_tokenbuf,':')) | |
5494 | yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf)); | |
5495 | ||
5496 | yylval.opval = newOP(OP_PADANY, 0); | |
dd2155a4 | 5497 | yylval.opval->op_targ = allocmy(PL_tokenbuf); |
8eceec63 SC |
5498 | return PRIVATEREF; |
5499 | } | |
5500 | } | |
5501 | ||
5502 | /* | |
5503 | build the ops for accesses to a my() variable. | |
5504 | ||
5505 | Deny my($a) or my($b) in a sort block, *if* $a or $b is | |
5506 | then used in a comparison. This catches most, but not | |
5507 | all cases. For instance, it catches | |
5508 | sort { my($a); $a <=> $b } | |
5509 | but not | |
5510 | sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; } | |
5511 | (although why you'd do that is anyone's guess). | |
5512 | */ | |
5513 | ||
5514 | if (!strchr(PL_tokenbuf,':')) { | |
8716503d DM |
5515 | if (!PL_in_my) |
5516 | tmp = pad_findmy(PL_tokenbuf); | |
5517 | if (tmp != NOT_IN_PAD) { | |
8eceec63 | 5518 | /* might be an "our" variable" */ |
dd2155a4 | 5519 | if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) { |
8eceec63 | 5520 | /* build ops for a bareword */ |
dd2155a4 | 5521 | SV *sym = newSVpv(HvNAME(PAD_COMPNAME_OURSTASH(tmp)), 0); |
8eceec63 SC |
5522 | sv_catpvn(sym, "::", 2); |
5523 | sv_catpv(sym, PL_tokenbuf+1); | |
5524 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym); | |
5525 | yylval.opval->op_private = OPpCONST_ENTERED; | |
7a5fd60d | 5526 | gv_fetchsv(sym, |
8eceec63 SC |
5527 | (PL_in_eval |
5528 | ? (GV_ADDMULTI | GV_ADDINEVAL) | |
700078d2 | 5529 | : GV_ADDMULTI |
8eceec63 SC |
5530 | ), |
5531 | ((PL_tokenbuf[0] == '$') ? SVt_PV | |
5532 | : (PL_tokenbuf[0] == '@') ? SVt_PVAV | |
5533 | : SVt_PVHV)); | |
5534 | return WORD; | |
5535 | } | |
5536 | ||
5537 | /* if it's a sort block and they're naming $a or $b */ | |
5538 | if (PL_last_lop_op == OP_SORT && | |
5539 | PL_tokenbuf[0] == '$' && | |
5540 | (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b') | |
5541 | && !PL_tokenbuf[2]) | |
5542 | { | |
5543 | for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart; | |
5544 | d < PL_bufend && *d != '\n'; | |
5545 | d++) | |
5546 | { | |
5547 | if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) { | |
5548 | Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison", | |
5549 | PL_tokenbuf); | |
5550 | } | |
5551 | } | |
5552 | } | |
5553 | ||
5554 | yylval.opval = newOP(OP_PADANY, 0); | |
5555 | yylval.opval->op_targ = tmp; | |
5556 | return PRIVATEREF; | |
5557 | } | |
5558 | } | |
5559 | ||
5560 | /* | |
5561 | Whine if they've said @foo in a doublequoted string, | |
5562 | and @foo isn't a variable we can find in the symbol | |
5563 | table. | |
5564 | */ | |
5565 | if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) { | |
5566 | GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV); | |
5567 | if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv))) | |
5568 | && ckWARN(WARN_AMBIGUOUS)) | |
5569 | { | |
5570 | /* Downgraded from fatal to warning 20000522 mjd */ | |
9014280d | 5571 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
8eceec63 SC |
5572 | "Possible unintended interpolation of %s in string", |
5573 | PL_tokenbuf); | |
5574 | } | |
5575 | } | |
5576 | ||
5577 | /* build ops for a bareword */ | |
5578 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0)); | |
5579 | yylval.opval->op_private = OPpCONST_ENTERED; | |
5580 | gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE, | |
5581 | ((PL_tokenbuf[0] == '$') ? SVt_PV | |
5582 | : (PL_tokenbuf[0] == '@') ? SVt_PVAV | |
5583 | : SVt_PVHV)); | |
5584 | return WORD; | |
5585 | } | |
5586 | ||
4c3bbe0f MHM |
5587 | /* |
5588 | * The following code was generated by perl_keyword.pl. | |
5589 | */ | |
e2e1dd5a | 5590 | |
79072805 | 5591 | I32 |
4c3bbe0f MHM |
5592 | Perl_keyword (pTHX_ char *name, I32 len) |
5593 | { | |
5594 | switch (len) | |
5595 | { | |
5596 | case 1: /* 5 tokens of length 1 */ | |
5597 | switch (name[0]) | |
e2e1dd5a | 5598 | { |
4c3bbe0f MHM |
5599 | case 'm': |
5600 | { /* m */ | |
5601 | return KEY_m; | |
5602 | } | |
5603 | ||
4c3bbe0f MHM |
5604 | case 'q': |
5605 | { /* q */ | |
5606 | return KEY_q; | |
5607 | } | |
5608 | ||
4c3bbe0f MHM |
5609 | case 's': |
5610 | { /* s */ | |
5611 | return KEY_s; | |
5612 | } | |
5613 | ||
4c3bbe0f MHM |
5614 | case 'x': |
5615 | { /* x */ | |
5616 | return -KEY_x; | |
5617 | } | |
5618 | ||
4c3bbe0f MHM |
5619 | case 'y': |
5620 | { /* y */ | |
5621 | return KEY_y; | |
5622 | } | |
5623 | ||
4c3bbe0f MHM |
5624 | default: |
5625 | goto unknown; | |
e2e1dd5a | 5626 | } |
4c3bbe0f MHM |
5627 | |
5628 | case 2: /* 18 tokens of length 2 */ | |
5629 | switch (name[0]) | |
e2e1dd5a | 5630 | { |
4c3bbe0f MHM |
5631 | case 'd': |
5632 | if (name[1] == 'o') | |
5633 | { /* do */ | |
5634 | return KEY_do; | |
5635 | } | |
5636 | ||
5637 | goto unknown; | |
5638 | ||
5639 | case 'e': | |
5640 | if (name[1] == 'q') | |
5641 | { /* eq */ | |
5642 | return -KEY_eq; | |
5643 | } | |
5644 | ||
5645 | goto unknown; | |
5646 | ||
5647 | case 'g': | |
5648 | switch (name[1]) | |
5649 | { | |
5650 | case 'e': | |
5651 | { /* ge */ | |
5652 | return -KEY_ge; | |
5653 | } | |
5654 | ||
4c3bbe0f MHM |
5655 | case 't': |
5656 | { /* gt */ | |
5657 | return -KEY_gt; | |
5658 | } | |
5659 | ||
4c3bbe0f MHM |
5660 | default: |
5661 | goto unknown; | |
5662 | } | |
5663 | ||
5664 | case 'i': | |
5665 | if (name[1] == 'f') | |
5666 | { /* if */ | |
5667 | return KEY_if; | |
5668 | } | |
5669 | ||
5670 | goto unknown; | |
5671 | ||
5672 | case 'l': | |
5673 | switch (name[1]) | |
5674 | { | |
5675 | case 'c': | |
5676 | { /* lc */ | |
5677 | return -KEY_lc; | |
5678 | } | |
5679 | ||
4c3bbe0f MHM |
5680 | case 'e': |
5681 | { /* le */ | |
5682 | return -KEY_le; | |
5683 | } | |
5684 | ||
4c3bbe0f MHM |
5685 | case 't': |
5686 | { /* lt */ | |
5687 | return -KEY_lt; | |
5688 | } | |
5689 | ||
4c3bbe0f MHM |
5690 | default: |
5691 | goto unknown; | |
5692 | } | |
5693 | ||
5694 | case 'm': | |
5695 | if (name[1] == 'y') | |
5696 | { /* my */ | |
5697 | return KEY_my; | |
5698 | } | |
5699 | ||
5700 | goto unknown; | |
5701 | ||
5702 | case 'n': | |
5703 | switch (name[1]) | |
5704 | { | |
5705 | case 'e': | |
5706 | { /* ne */ | |
5707 | return -KEY_ne; | |
5708 | } | |
5709 | ||
4c3bbe0f MHM |
5710 | case 'o': |
5711 | { /* no */ | |
5712 | return KEY_no; | |
5713 | } | |
5714 | ||
4c3bbe0f MHM |
5715 | default: |
5716 | goto unknown; | |
5717 | } | |
5718 | ||
5719 | case 'o': | |
5720 | if (name[1] == 'r') | |
5721 | { /* or */ | |
5722 | return -KEY_or; | |
5723 | } | |
5724 | ||
5725 | goto unknown; | |
5726 | ||
5727 | case 'q': | |
5728 | switch (name[1]) | |
5729 | { | |
5730 | case 'q': | |
5731 | { /* qq */ | |
5732 | return KEY_qq; | |
5733 | } | |
5734 | ||
4c3bbe0f MHM |
5735 | case 'r': |
5736 | { /* qr */ | |
5737 | return KEY_qr; | |
5738 | } | |
5739 | ||
4c3bbe0f MHM |
5740 | case 'w': |
5741 | { /* qw */ | |
5742 | return KEY_qw; | |
5743 | } | |
5744 | ||
4c3bbe0f MHM |
5745 | case 'x': |
5746 | { /* qx */ | |
5747 | return KEY_qx; | |
5748 | } | |
5749 | ||
4c3bbe0f MHM |
5750 | default: |
5751 | goto unknown; | |
5752 | } | |
5753 | ||
5754 | case 't': | |
5755 | if (name[1] == 'r') | |
5756 | { /* tr */ | |
5757 | return KEY_tr; | |
5758 | } | |
5759 | ||
5760 | goto unknown; | |
5761 | ||
5762 | case 'u': | |
5763 | if (name[1] == 'c') | |
5764 | { /* uc */ | |
5765 | return -KEY_uc; | |
5766 | } | |
5767 | ||
5768 | goto unknown; | |
5769 | ||
5770 | default: | |
5771 | goto unknown; | |
e2e1dd5a | 5772 | } |
4c3bbe0f MHM |
5773 | |
5774 | case 3: /* 28 tokens of length 3 */ | |
5775 | switch (name[0]) | |
e2e1dd5a | 5776 | { |
4c3bbe0f MHM |
5777 | case 'E': |
5778 | if (name[1] == 'N' && | |
5779 | name[2] == 'D') | |
5780 | { /* END */ | |
5781 | return KEY_END; | |
5782 | } | |
5783 | ||
5784 | goto unknown; | |
5785 | ||
5786 | case 'a': | |
5787 | switch (name[1]) | |
5788 | { | |
5789 | case 'b': | |
5790 | if (name[2] == 's') | |
5791 | { /* abs */ | |
5792 | return -KEY_abs; | |
5793 | } | |
5794 | ||
5795 | goto unknown; | |
5796 | ||
5797 | case 'n': | |
5798 | if (name[2] == 'd') | |
5799 | { /* and */ | |
5800 | return -KEY_and; | |
5801 | } | |
5802 | ||
5803 | goto unknown; | |
5804 | ||
5805 | default: | |
5806 | goto unknown; | |
5807 | } | |
5808 | ||
5809 | case 'c': | |
5810 | switch (name[1]) | |
5811 | { | |
5812 | case 'h': | |
5813 | if (name[2] == 'r') | |
5814 | { /* chr */ | |
5815 | return -KEY_chr; | |
5816 | } | |
5817 | ||
5818 | goto unknown; | |
5819 | ||
5820 | case 'm': | |
5821 | if (name[2] == 'p') | |
5822 | { /* cmp */ | |
5823 | return -KEY_cmp; | |
5824 | } | |
5825 | ||
5826 | goto unknown; | |
5827 | ||
5828 | case 'o': | |
5829 | if (name[2] == 's') | |
5830 | { /* cos */ | |
5831 | return -KEY_cos; | |
5832 | } | |
5833 | ||
5834 | goto unknown; | |
5835 | ||
5836 | default: | |
5837 | goto unknown; | |
5838 | } | |
5839 | ||
5840 | case 'd': | |
5841 | if (name[1] == 'i' && | |
5842 | name[2] == 'e') | |
5843 | { /* die */ | |
5844 | return -KEY_die; | |
5845 | } | |
5846 | ||
5847 | goto unknown; | |
5848 | ||
5849 | case 'e': | |
5850 | switch (name[1]) | |
5851 | { | |
5852 | case 'o': | |
5853 | if (name[2] == 'f') | |
5854 | { /* eof */ | |
5855 | return -KEY_eof; | |
5856 | } | |
5857 | ||
5858 | goto unknown; | |
5859 | ||
5860 | case 'r': | |
5861 | if (name[2] == 'r') | |
5862 | { /* err */ | |
5863 | return -KEY_err; | |
5864 | } | |
5865 | ||
5866 | goto unknown; | |
5867 | ||
5868 | case 'x': | |
5869 | if (name[2] == 'p') | |
5870 | { /* exp */ | |
5871 | return -KEY_exp; | |
5872 | } | |
5873 | ||
5874 | goto unknown; | |
5875 | ||
5876 | default: | |
5877 | goto unknown; | |
5878 | } | |
5879 | ||
5880 | case 'f': | |
5881 | if (name[1] == 'o' && | |
5882 | name[2] == 'r') | |
5883 | { /* for */ | |
5884 | return KEY_for; | |
5885 | } | |
5886 | ||
5887 | goto unknown; | |
5888 | ||
5889 | case 'h': | |
5890 | if (name[1] == 'e' && | |
5891 | name[2] == 'x') | |
5892 | { /* hex */ | |
5893 | return -KEY_hex; | |
5894 | } | |
5895 | ||
5896 | goto unknown; | |
5897 | ||
5898 | case 'i': | |
5899 | if (name[1] == 'n' && | |
5900 | name[2] == 't') | |
5901 | { /* int */ | |
5902 | return -KEY_int; | |
5903 | } | |
5904 | ||
5905 | goto unknown; | |
5906 | ||
5907 | case 'l': | |
5908 | if (name[1] == 'o' && | |
5909 | name[2] == 'g') | |
5910 | { /* log */ | |
5911 | return -KEY_log; | |
5912 | } | |
5913 | ||
5914 | goto unknown; | |
5915 | ||
5916 | case 'm': | |
5917 | if (name[1] == 'a' && | |
5918 | name[2] == 'p') | |
5919 | { /* map */ | |
5920 | return KEY_map; | |
5921 | } | |
5922 | ||
5923 | goto unknown; | |
5924 | ||
5925 | case 'n': | |
5926 | if (name[1] == 'o' && | |
5927 | name[2] == 't') | |
5928 | { /* not */ | |
5929 | return -KEY_not; | |
5930 | } | |
5931 | ||
5932 | goto unknown; | |
5933 | ||
5934 | case 'o': | |
5935 | switch (name[1]) | |
5936 | { | |
5937 | case 'c': | |
5938 | if (name[2] == 't') | |
5939 | { /* oct */ | |
5940 | return -KEY_oct; | |
5941 | } | |
5942 | ||
5943 | goto unknown; | |
5944 | ||
5945 | case 'r': | |
5946 | if (name[2] == 'd') | |
5947 | { /* ord */ | |
5948 | return -KEY_ord; | |
5949 | } | |
5950 | ||
5951 | goto unknown; | |
5952 | ||
5953 | case 'u': | |
5954 | if (name[2] == 'r') | |
5955 | { /* our */ | |
5956 | return KEY_our; | |
5957 | } | |
5958 | ||
5959 | goto unknown; | |
5960 | ||
5961 | default: | |
5962 | goto unknown; | |
5963 | } | |
5964 | ||
5965 | case 'p': | |
5966 | if (name[1] == 'o') | |
5967 | { | |
5968 | switch (name[2]) | |
5969 | { | |
5970 | case 'p': | |
5971 | { /* pop */ | |
5972 | return -KEY_pop; | |
5973 | } | |
5974 | ||
4c3bbe0f MHM |
5975 | case 's': |
5976 | { /* pos */ | |
5977 | return KEY_pos; | |
5978 | } | |
5979 | ||
4c3bbe0f MHM |
5980 | default: |
5981 | goto unknown; | |
5982 | } | |
5983 | } | |
5984 | ||
5985 | goto unknown; | |
5986 | ||
5987 | case 'r': | |
5988 | if (name[1] == 'e' && | |
5989 | name[2] == 'f') | |
5990 | { /* ref */ | |
5991 | return -KEY_ref; | |
5992 | } | |
5993 | ||
5994 | goto unknown; | |
5995 | ||
5996 | case 's': | |
5997 | switch (name[1]) | |
5998 | { | |
5999 | case 'i': | |
6000 | if (name[2] == 'n') | |
6001 | { /* sin */ | |
6002 | return -KEY_sin; | |
6003 | } | |
6004 | ||
6005 | goto unknown; | |
6006 | ||
6007 | case 'u': | |
6008 | if (name[2] == 'b') | |
6009 | { /* sub */ | |
6010 | return KEY_sub; | |
6011 | } | |
6012 | ||
6013 | goto unknown; | |
6014 | ||
6015 | default: | |
6016 | goto unknown; | |
6017 | } | |
6018 | ||
6019 | case 't': | |
6020 | if (name[1] == 'i' && | |
6021 | name[2] == 'e') | |
6022 | { /* tie */ | |
6023 | return KEY_tie; | |
6024 | } | |
6025 | ||
6026 | goto unknown; | |
6027 | ||
6028 | case 'u': | |
6029 | if (name[1] == 's' && | |
6030 | name[2] == 'e') | |
6031 | { /* use */ | |
6032 | return KEY_use; | |
6033 | } | |
6034 | ||
6035 | goto unknown; | |
6036 | ||
6037 | case 'v': | |
6038 | if (name[1] == 'e' && | |
6039 | name[2] == 'c') | |
6040 | { /* vec */ | |
6041 | return -KEY_vec; | |
6042 | } | |
6043 | ||
6044 | goto unknown; | |
6045 | ||
6046 | case 'x': | |
6047 | if (name[1] == 'o' && | |
6048 | name[2] == 'r') | |
6049 | { /* xor */ | |
6050 | return -KEY_xor; | |
6051 | } | |
6052 | ||
6053 | goto unknown; | |
6054 | ||
6055 | default: | |
6056 | goto unknown; | |
e2e1dd5a | 6057 | } |
4c3bbe0f MHM |
6058 | |
6059 | case 4: /* 40 tokens of length 4 */ | |
6060 | switch (name[0]) | |
e2e1dd5a | 6061 | { |
4c3bbe0f MHM |
6062 | case 'C': |
6063 | if (name[1] == 'O' && | |
6064 | name[2] == 'R' && | |
6065 | name[3] == 'E') | |
6066 | { /* CORE */ | |
6067 | return -KEY_CORE; | |
6068 | } | |
6069 | ||
6070 | goto unknown; | |
6071 | ||
6072 | case 'I': | |
6073 | if (name[1] == 'N' && | |
6074 | name[2] == 'I' && | |
6075 | name[3] == 'T') | |
6076 | { /* INIT */ | |
6077 | return KEY_INIT; | |
6078 | } | |
6079 | ||
6080 | goto unknown; | |
6081 | ||
6082 | case 'b': | |
6083 | if (name[1] == 'i' && | |
6084 | name[2] == 'n' && | |
6085 | name[3] == 'd') | |
6086 | { /* bind */ | |
6087 | return -KEY_bind; | |
6088 | } | |
6089 | ||
6090 | goto unknown; | |
6091 | ||
6092 | case 'c': | |
6093 | if (name[1] == 'h' && | |
6094 | name[2] == 'o' && | |
6095 | name[3] == 'p') | |
6096 | { /* chop */ | |
6097 | return -KEY_chop; | |
6098 | } | |
6099 | ||
6100 | goto unknown; | |
6101 | ||
6102 | case 'd': | |
6103 | if (name[1] == 'u' && | |
6104 | name[2] == 'm' && | |
6105 | name[3] == 'p') | |
6106 | { /* dump */ | |
6107 | return -KEY_dump; | |
6108 | } | |
6109 | ||
6110 | goto unknown; | |
6111 | ||
6112 | case 'e': | |
6113 | switch (name[1]) | |
6114 | { | |
6115 | case 'a': | |
6116 | if (name[2] == 'c' && | |
6117 | name[3] == 'h') | |
6118 | { /* each */ | |
6119 | return -KEY_each; | |
6120 | } | |
6121 | ||
6122 | goto unknown; | |
6123 | ||
6124 | case 'l': | |
6125 | if (name[2] == 's' && | |
6126 | name[3] == 'e') | |
6127 | { /* else */ | |
6128 | return KEY_else; | |
6129 | } | |
6130 | ||
6131 | goto unknown; | |
6132 | ||
6133 | case 'v': | |
6134 | if (name[2] == 'a' && | |
6135 | name[3] == 'l') | |
6136 | { /* eval */ | |
6137 | return KEY_eval; | |
6138 | } | |
6139 | ||
6140 | goto unknown; | |
6141 | ||
6142 | case 'x': | |
6143 | switch (name[2]) | |
6144 | { | |
6145 | case 'e': | |
6146 | if (name[3] == 'c') | |
6147 | { /* exec */ | |
6148 | return -KEY_exec; | |
6149 | } | |
6150 | ||
6151 | goto unknown; | |
6152 | ||
6153 | case 'i': | |
6154 | if (name[3] == 't') | |
6155 | { /* exit */ | |
6156 | return -KEY_exit; | |
6157 | } | |
6158 | ||
6159 | goto unknown; | |
6160 | ||
6161 | default: | |
6162 | goto unknown; | |
6163 | } | |
6164 | ||
6165 | default: | |
6166 | goto unknown; | |
6167 | } | |
6168 | ||
6169 | case 'f': | |
6170 | if (name[1] == 'o' && | |
6171 | name[2] == 'r' && | |
6172 | name[3] == 'k') | |
6173 | { /* fork */ | |
6174 | return -KEY_fork; | |
6175 | } | |
6176 | ||
6177 | goto unknown; | |
6178 | ||
6179 | case 'g': | |
6180 | switch (name[1]) | |
6181 | { | |
6182 | case 'e': | |
6183 | if (name[2] == 't' && | |
6184 | name[3] == 'c') | |
6185 | { /* getc */ | |
6186 | return -KEY_getc; | |
6187 | } | |
6188 | ||
6189 | goto unknown; | |
6190 | ||
6191 | case 'l': | |
6192 | if (name[2] == 'o' && | |
6193 | name[3] == 'b') | |
6194 | { /* glob */ | |
6195 | return KEY_glob; | |
6196 | } | |
6197 | ||
6198 | goto unknown; | |
6199 | ||
6200 | case 'o': | |
6201 | if (name[2] == 't' && | |
6202 | name[3] == 'o') | |
6203 | { /* goto */ | |
6204 | return KEY_goto; | |
6205 | } | |
6206 | ||
6207 | goto unknown; | |
6208 | ||
6209 | case 'r': | |
6210 | if (name[2] == 'e' && | |
6211 | name[3] == 'p') | |
6212 | { /* grep */ | |
6213 | return KEY_grep; | |
6214 | } | |
6215 | ||
6216 | goto unknown; | |
6217 | ||
6218 | default: | |
6219 | goto unknown; | |
6220 | } | |
6221 | ||
6222 | case 'j': | |
6223 | if (name[1] == 'o' && | |
6224 | name[2] == 'i' && | |
6225 | name[3] == 'n') | |
6226 | { /* join */ | |
6227 | return -KEY_join; | |
6228 | } | |
6229 | ||
6230 | goto unknown; | |
6231 | ||
6232 | case 'k': | |
6233 | switch (name[1]) | |
6234 | { | |
6235 | case 'e': | |
6236 | if (name[2] == 'y' && | |
6237 | name[3] == 's') | |
6238 | { /* keys */ | |
6239 | return -KEY_keys; | |
6240 | } | |
6241 | ||
6242 | goto unknown; | |
6243 | ||
6244 | case 'i': | |
6245 | if (name[2] == 'l' && | |
6246 | name[3] == 'l') | |
6247 | { /* kill */ | |
6248 | return -KEY_kill; | |
6249 | } | |
6250 | ||
6251 | goto unknown; | |
6252 | ||
6253 | default: | |
6254 | goto unknown; | |
6255 | } | |
6256 | ||
6257 | case 'l': | |
6258 | switch (name[1]) | |
6259 | { | |
6260 | case 'a': | |
6261 | if (name[2] == 's' && | |
6262 | name[3] == 't') | |
6263 | { /* last */ | |
6264 | return KEY_last; | |
6265 | } | |
6266 | ||
6267 | goto unknown; | |
6268 | ||
6269 | case 'i': | |
6270 | if (name[2] == 'n' && | |
6271 | name[3] == 'k') | |
6272 | { /* link */ | |
6273 | return -KEY_link; | |
6274 | } | |
6275 | ||
6276 | goto unknown; | |
6277 | ||
6278 | case 'o': | |
6279 | if (name[2] == 'c' && | |
6280 | name[3] == 'k') | |
6281 | { /* lock */ | |
6282 | return -KEY_lock; | |
6283 | } | |
6284 | ||
6285 | goto unknown; | |
6286 | ||
6287 | default: | |
6288 | goto unknown; | |
6289 | } | |
6290 | ||
6291 | case 'n': | |
6292 | if (name[1] == 'e' && | |
6293 | name[2] == 'x' && | |
6294 | name[3] == 't') | |
6295 | { /* next */ | |
6296 | return KEY_next; | |
6297 | } | |
6298 | ||
6299 | goto unknown; | |
6300 | ||
6301 | case 'o': | |
6302 | if (name[1] == 'p' && | |
6303 | name[2] == 'e' && | |
6304 | name[3] == 'n') | |
6305 | { /* open */ | |
6306 | return -KEY_open; | |
6307 | } | |
6308 | ||
6309 | goto unknown; | |
6310 | ||
6311 | case 'p': | |
6312 | switch (name[1]) | |
6313 | { | |
6314 | case 'a': | |
6315 | if (name[2] == 'c' && | |
6316 | name[3] == 'k') | |
6317 | { /* pack */ | |
6318 | return -KEY_pack; | |
6319 | } | |
6320 | ||
6321 | goto unknown; | |
6322 | ||
6323 | case 'i': | |
6324 | if (name[2] == 'p' && | |
6325 | name[3] == 'e') | |
6326 | { /* pipe */ | |
6327 | return -KEY_pipe; | |
6328 | } | |
6329 | ||
6330 | goto unknown; | |
6331 | ||
6332 | case 'u': | |
6333 | if (name[2] == 's' && | |
6334 | name[3] == 'h') | |
6335 | { /* push */ | |
6336 | return -KEY_push; | |
6337 | } | |
6338 | ||
6339 | goto unknown; | |
6340 | ||
6341 | default: | |
6342 | goto unknown; | |
6343 | } | |
6344 | ||
6345 | case 'r': | |
6346 | switch (name[1]) | |
6347 | { | |
6348 | case 'a': | |
6349 | if (name[2] == 'n' && | |
6350 | name[3] == 'd') | |
6351 | { /* rand */ | |
6352 | return -KEY_rand; | |
6353 | } | |
6354 | ||
6355 | goto unknown; | |
6356 | ||
6357 | case 'e': | |
6358 | switch (name[2]) | |
6359 | { | |
6360 | case 'a': | |
6361 | if (name[3] == 'd') | |
6362 | { /* read */ | |
6363 | return -KEY_read; | |
6364 | } | |
6365 | ||
6366 | goto unknown; | |
6367 | ||
6368 | case 'c': | |
6369 | if (name[3] == 'v') | |
6370 | { /* recv */ | |
6371 | return -KEY_recv; | |
6372 | } | |
6373 | ||
6374 | goto unknown; | |
6375 | ||
6376 | case 'd': | |
6377 | if (name[3] == 'o') | |
6378 | { /* redo */ | |
6379 | return KEY_redo; | |
6380 | } | |
6381 | ||
6382 | goto unknown; | |
6383 | ||
6384 | default: | |
6385 | goto unknown; | |
6386 | } | |
6387 | ||
6388 | default: | |
6389 | goto unknown; | |
6390 | } | |
6391 | ||
6392 | case 's': | |
6393 | switch (name[1]) | |
6394 | { | |
6395 | case 'e': | |
6396 | switch (name[2]) | |
6397 | { | |
6398 | case 'e': | |
6399 | if (name[3] == 'k') | |
6400 | { /* seek */ | |
6401 | return -KEY_seek; | |
6402 | } | |
6403 | ||
6404 | goto unknown; | |
6405 | ||
6406 | case 'n': | |
6407 | if (name[3] == 'd') | |
6408 | { /* send */ | |
6409 | return -KEY_send; | |
6410 | } | |
6411 | ||
6412 | goto unknown; | |
6413 | ||
6414 | default: | |
6415 | goto unknown; | |
6416 | } | |
6417 | ||
6418 | case 'o': | |
6419 | if (name[2] == 'r' && | |
6420 | name[3] == 't') | |
6421 | { /* sort */ | |
6422 | return KEY_sort; | |
6423 | } | |
6424 | ||
6425 | goto unknown; | |
6426 | ||
6427 | case 'q': | |
6428 | if (name[2] == 'r' && | |
6429 | name[3] == 't') | |
6430 | { /* sqrt */ | |
6431 | return -KEY_sqrt; | |
6432 | } | |
6433 | ||
6434 | goto unknown; | |
6435 | ||
6436 | case 't': | |
6437 | if (name[2] == 'a' && | |
6438 | name[3] == 't') | |
6439 | { /* stat */ | |
6440 | return -KEY_stat; | |
6441 | } | |
6442 | ||
6443 | goto unknown; | |
6444 | ||
6445 | default: | |
6446 | goto unknown; | |
6447 | } | |
6448 | ||
6449 | case 't': | |
6450 | switch (name[1]) | |
6451 | { | |
6452 | case 'e': | |
6453 | if (name[2] == 'l' && | |
6454 | name[3] == 'l') | |
6455 | { /* tell */ | |
6456 | return -KEY_tell; | |
6457 | } | |
6458 | ||
6459 | goto unknown; | |
6460 | ||
6461 | case 'i': | |
6462 | switch (name[2]) | |
6463 | { | |
6464 | case 'e': | |
6465 | if (name[3] == 'd') | |
6466 | { /* tied */ | |
6467 | return KEY_tied; | |
6468 | } | |
6469 | ||
6470 | goto unknown; | |
6471 | ||
6472 | case 'm': | |
6473 | if (name[3] == 'e') | |
6474 | { /* time */ | |
6475 | return -KEY_time; | |
6476 | } | |
6477 | ||
6478 | goto unknown; | |
6479 | ||
6480 | default: | |
6481 | goto unknown; | |
6482 | } | |
6483 | ||
6484 | default: | |
6485 | goto unknown; | |
6486 | } | |
6487 | ||
6488 | case 'w': | |
6489 | if (name[1] == 'a') | |
6490 | { | |
6491 | switch (name[2]) | |
6492 | { | |
6493 | case 'i': | |
6494 | if (name[3] == 't') | |
6495 | { /* wait */ | |
6496 | return -KEY_wait; | |
6497 | } | |
6498 | ||
6499 | goto unknown; | |
6500 | ||
6501 | case 'r': | |
6502 | if (name[3] == 'n') | |
6503 | { /* warn */ | |
6504 | return -KEY_warn; | |
6505 | } | |
6506 | ||
6507 | goto unknown; | |
6508 | ||
6509 | default: | |
6510 | goto unknown; | |
6511 | } | |
6512 | } | |
6513 | ||
6514 | goto unknown; | |
6515 | ||
6516 | default: | |
6517 | goto unknown; | |
e2e1dd5a | 6518 | } |
4c3bbe0f MHM |
6519 | |
6520 | case 5: /* 36 tokens of length 5 */ | |
6521 | switch (name[0]) | |
e2e1dd5a | 6522 | { |
4c3bbe0f MHM |
6523 | case 'B': |
6524 | if (name[1] == 'E' && | |
6525 | name[2] == 'G' && | |
6526 | name[3] == 'I' && | |
6527 | name[4] == 'N') | |
6528 | { /* BEGIN */ | |
6529 | return KEY_BEGIN; | |
6530 | } | |
6531 | ||
6532 | goto unknown; | |
6533 | ||
6534 | case 'C': | |
6535 | if (name[1] == 'H' && | |
6536 | name[2] == 'E' && | |
6537 | name[3] == 'C' && | |
6538 | name[4] == 'K') | |
6539 | { /* CHECK */ | |
6540 | return KEY_CHECK; | |
6541 | } | |
6542 | ||
6543 | goto unknown; | |
6544 | ||
6545 | case 'a': | |
6546 | switch (name[1]) | |
6547 | { | |
6548 | case 'l': | |
6549 | if (name[2] == 'a' && | |
6550 | name[3] == 'r' && | |
6551 | name[4] == 'm') | |
6552 | { /* alarm */ | |
6553 | return -KEY_alarm; | |
6554 | } | |
6555 | ||
6556 | goto unknown; | |
6557 | ||
6558 | case 't': | |
6559 | if (name[2] == 'a' && | |
6560 | name[3] == 'n' && | |
6561 | name[4] == '2') | |
6562 | { /* atan2 */ | |
6563 | return -KEY_atan2; | |
6564 | } | |
6565 | ||
6566 | goto unknown; | |
6567 | ||
6568 | default: | |
6569 | goto unknown; | |
6570 | } | |
6571 | ||
6572 | case 'b': | |
6573 | if (name[1] == 'l' && | |
6574 | name[2] == 'e' && | |
6575 | name[3] == 's' && | |
6576 | name[4] == 's') | |
6577 | { /* bless */ | |
6578 | return -KEY_bless; | |
6579 | } | |
6580 | ||
6581 | goto unknown; | |
6582 | ||
6583 | case 'c': | |
6584 | switch (name[1]) | |
6585 | { | |
6586 | case 'h': | |
6587 | switch (name[2]) | |
6588 | { | |
6589 | case 'd': | |
6590 | if (name[3] == 'i' && | |
6591 | name[4] == 'r') | |
6592 | { /* chdir */ | |
6593 | return -KEY_chdir; | |
6594 | } | |
6595 | ||
6596 | goto unknown; | |
6597 | ||
6598 | case 'm': | |
6599 | if (name[3] == 'o' && | |
6600 | name[4] == 'd') | |
6601 | { /* chmod */ | |
6602 | return -KEY_chmod; | |
6603 | } | |
6604 | ||
6605 | goto unknown; | |
6606 | ||
6607 | case 'o': | |
6608 | switch (name[3]) | |
6609 | { | |
6610 | case 'm': | |
6611 | if (name[4] == 'p') | |
6612 | { /* chomp */ | |
6613 | return -KEY_chomp; | |
6614 | } | |
6615 | ||
6616 | goto unknown; | |
6617 | ||
6618 | case 'w': | |
6619 | if (name[4] == 'n') | |
6620 | { /* chown */ | |
6621 | return -KEY_chown; | |
6622 | } | |
6623 | ||
6624 | goto unknown; | |
6625 | ||
6626 | default: | |
6627 | goto unknown; | |
6628 | } | |
6629 | ||
6630 | default: | |
6631 | goto unknown; | |
6632 | } | |
6633 | ||
6634 | case 'l': | |
6635 | if (name[2] == 'o' && | |
6636 | name[3] == 's' && | |
6637 | name[4] == 'e') | |
6638 | { /* close */ | |
6639 | return -KEY_close; | |
6640 | } | |
6641 | ||
6642 | goto unknown; | |
6643 | ||
6644 | case 'r': | |
6645 | if (name[2] == 'y' && | |
6646 | name[3] == 'p' && | |
6647 | name[4] == 't') | |
6648 | { /* crypt */ | |
6649 | return -KEY_crypt; | |
6650 | } | |
6651 | ||
6652 | goto unknown; | |
6653 | ||
6654 | default: | |
6655 | goto unknown; | |
6656 | } | |
6657 | ||
6658 | case 'e': | |
6659 | if (name[1] == 'l' && | |
6660 | name[2] == 's' && | |
6661 | name[3] == 'i' && | |
6662 | name[4] == 'f') | |
6663 | { /* elsif */ | |
6664 | return KEY_elsif; | |
6665 | } | |
6666 | ||
6667 | goto unknown; | |
6668 | ||
6669 | case 'f': | |
6670 | switch (name[1]) | |
6671 | { | |
6672 | case 'c': | |
6673 | if (name[2] == 'n' && | |
6674 | name[3] == 't' && | |
6675 | name[4] == 'l') | |
6676 | { /* fcntl */ | |
6677 | return -KEY_fcntl; | |
6678 | } | |
6679 | ||
6680 | goto unknown; | |
6681 | ||
6682 | case 'l': | |
6683 | if (name[2] == 'o' && | |
6684 | name[3] == 'c' && | |
6685 | name[4] == 'k') | |
6686 | { /* flock */ | |
6687 | return -KEY_flock; | |
6688 | } | |
6689 | ||
6690 | goto unknown; | |
6691 | ||
6692 | default: | |
6693 | goto unknown; | |
6694 | } | |
6695 | ||
6696 | case 'i': | |
6697 | switch (name[1]) | |
6698 | { | |
6699 | case 'n': | |
6700 | if (name[2] == 'd' && | |
6701 | name[3] == 'e' && | |
6702 | name[4] == 'x') | |
6703 | { /* index */ | |
6704 | return -KEY_index; | |
6705 | } | |
6706 | ||
6707 | goto unknown; | |
6708 | ||
6709 | case 'o': | |
6710 | if (name[2] == 'c' && | |
6711 | name[3] == 't' && | |
6712 | name[4] == 'l') | |
6713 | { /* ioctl */ | |
6714 | return -KEY_ioctl; | |
6715 | } | |
6716 | ||
6717 | goto unknown; | |
6718 | ||
6719 | default: | |
6720 | goto unknown; | |
6721 | } | |
6722 | ||
6723 | case 'l': | |
6724 | switch (name[1]) | |
6725 | { | |
6726 | case 'o': | |
6727 | if (name[2] == 'c' && | |
6728 | name[3] == 'a' && | |
6729 | name[4] == 'l') | |
6730 | { /* local */ | |
6731 | return KEY_local; | |
6732 | } | |
6733 | ||
6734 | goto unknown; | |
6735 | ||
6736 | case 's': | |
6737 | if (name[2] == 't' && | |
6738 | name[3] == 'a' && | |
6739 | name[4] == 't') | |
6740 | { /* lstat */ | |
6741 | return -KEY_lstat; | |
6742 | } | |
6743 | ||
6744 | goto unknown; | |
6745 | ||
6746 | default: | |
6747 | goto unknown; | |
6748 | } | |
6749 | ||
6750 | case 'm': | |
6751 | if (name[1] == 'k' && | |
6752 | name[2] == 'd' && | |
6753 | name[3] == 'i' && | |
6754 | name[4] == 'r') | |
6755 | { /* mkdir */ | |
6756 | return -KEY_mkdir; | |
6757 | } | |
6758 | ||
6759 | goto unknown; | |
6760 | ||
6761 | case 'p': | |
6762 | if (name[1] == 'r' && | |
6763 | name[2] == 'i' && | |
6764 | name[3] == 'n' && | |
6765 | name[4] == 't') | |
6766 | { /* print */ | |
6767 | return KEY_print; | |
6768 | } | |
6769 | ||
6770 | goto unknown; | |
6771 | ||
6772 | case 'r': | |
6773 | switch (name[1]) | |
6774 | { | |
6775 | case 'e': | |
6776 | if (name[2] == 's' && | |
6777 | name[3] == 'e' && | |
6778 | name[4] == 't') | |
6779 | { /* reset */ | |
6780 | return -KEY_reset; | |
6781 | } | |
6782 | ||
6783 | goto unknown; | |
6784 | ||
6785 | case 'm': | |
6786 | if (name[2] == 'd' && | |
6787 | name[3] == 'i' && | |
6788 | name[4] == 'r') | |
6789 | { /* rmdir */ | |
6790 | return -KEY_rmdir; | |
6791 | } | |
6792 | ||
6793 | goto unknown; | |
6794 | ||
6795 | default: | |
6796 | goto unknown; | |
6797 | } | |
6798 | ||
6799 | case 's': | |
6800 | switch (name[1]) | |
6801 | { | |
6802 | case 'e': | |
6803 | if (name[2] == 'm' && | |
6804 | name[3] == 'o' && | |
6805 | name[4] == 'p') | |
6806 | { /* semop */ | |
6807 | return -KEY_semop; | |
6808 | } | |
6809 | ||
6810 | goto unknown; | |
6811 | ||
6812 | case 'h': | |
6813 | if (name[2] == 'i' && | |
6814 | name[3] == 'f' && | |
6815 | name[4] == 't') | |
6816 | { /* shift */ | |
6817 | return -KEY_shift; | |
6818 | } | |
6819 | ||
6820 | goto unknown; | |
6821 | ||
6822 | case 'l': | |
6823 | if (name[2] == 'e' && | |
6824 | name[3] == 'e' && | |
6825 | name[4] == 'p') | |
6826 | { /* sleep */ | |
6827 | return -KEY_sleep; | |
6828 | } | |
6829 | ||
6830 | goto unknown; | |
6831 | ||
6832 | case 'p': | |
6833 | if (name[2] == 'l' && | |
6834 | name[3] == 'i' && | |
6835 | name[4] == 't') | |
6836 | { /* split */ | |
6837 | return KEY_split; | |
6838 | } | |
6839 | ||
6840 | goto unknown; | |
6841 | ||
6842 | case 'r': | |
6843 | if (name[2] == 'a' && | |
6844 | name[3] == 'n' && | |
6845 | name[4] == 'd') | |
6846 | { /* srand */ | |
6847 | return -KEY_srand; | |
6848 | } | |
6849 | ||
6850 | goto unknown; | |
6851 | ||
6852 | case 't': | |
6853 | if (name[2] == 'u' && | |
6854 | name[3] == 'd' && | |
6855 | name[4] == 'y') | |
6856 | { /* study */ | |
6857 | return KEY_study; | |
6858 | } | |
6859 | ||
6860 | goto unknown; | |
6861 | ||
6862 | default: | |
6863 | goto unknown; | |
6864 | } | |
6865 | ||
6866 | case 't': | |
6867 | if (name[1] == 'i' && | |
6868 | name[2] == 'm' && | |
6869 | name[3] == 'e' && | |
6870 | name[4] == 's') | |
6871 | { /* times */ | |
6872 | return -KEY_times; | |
6873 | } | |
6874 | ||
6875 | goto unknown; | |
6876 | ||
6877 | case 'u': | |
6878 | switch (name[1]) | |
6879 | { | |
6880 | case 'm': | |
6881 | if (name[2] == 'a' && | |
6882 | name[3] == 's' && | |
6883 | name[4] == 'k') | |
6884 | { /* umask */ | |
6885 | return -KEY_umask; | |
6886 | } | |
6887 | ||
6888 | goto unknown; | |
6889 | ||
6890 | case 'n': | |
6891 | switch (name[2]) | |
6892 | { | |
6893 | case 'd': | |
6894 | if (name[3] == 'e' && | |
6895 | name[4] == 'f') | |
6896 | { /* undef */ | |
6897 | return KEY_undef; | |
6898 | } | |
6899 | ||
6900 | goto unknown; | |
6901 | ||
6902 | case 't': | |
6903 | if (name[3] == 'i') | |
6904 | { | |
6905 | switch (name[4]) | |
6906 | { | |
6907 | case 'e': | |
6908 | { /* untie */ | |
6909 | return KEY_untie; | |
6910 | } | |
6911 | ||
4c3bbe0f MHM |
6912 | case 'l': |
6913 | { /* until */ | |
6914 | return KEY_until; | |
6915 | } | |
6916 | ||
4c3bbe0f MHM |
6917 | default: |
6918 | goto unknown; | |
6919 | } | |
6920 | } | |
6921 | ||
6922 | goto unknown; | |
6923 | ||
6924 | default: | |
6925 | goto unknown; | |
6926 | } | |
6927 | ||
6928 | case 't': | |
6929 | if (name[2] == 'i' && | |
6930 | name[3] == 'm' && | |
6931 | name[4] == 'e') | |
6932 | { /* utime */ | |
6933 | return -KEY_utime; | |
6934 | } | |
6935 | ||
6936 | goto unknown; | |
6937 | ||
6938 | default: | |
6939 | goto unknown; | |
6940 | } | |
6941 | ||
6942 | case 'w': | |
6943 | switch (name[1]) | |
6944 | { | |
6945 | case 'h': | |
6946 | if (name[2] == 'i' && | |
6947 | name[3] == 'l' && | |
6948 | name[4] == 'e') | |
6949 | { /* while */ | |
6950 | return KEY_while; | |
6951 | } | |
6952 | ||
6953 | goto unknown; | |
6954 | ||
6955 | case 'r': | |
6956 | if (name[2] == 'i' && | |
6957 | name[3] == 't' && | |
6958 | name[4] == 'e') | |
6959 | { /* write */ | |
6960 | return -KEY_write; | |
6961 | } | |
6962 | ||
6963 | goto unknown; | |
6964 | ||
6965 | default: | |
6966 | goto unknown; | |
6967 | } | |
6968 | ||
6969 | default: | |
6970 | goto unknown; | |
e2e1dd5a | 6971 | } |
4c3bbe0f MHM |
6972 | |
6973 | case 6: /* 33 tokens of length 6 */ | |
6974 | switch (name[0]) | |
6975 | { | |
6976 | case 'a': | |
6977 | if (name[1] == 'c' && | |
6978 | name[2] == 'c' && | |
6979 | name[3] == 'e' && | |
6980 | name[4] == 'p' && | |
6981 | name[5] == 't') | |
6982 | { /* accept */ | |
6983 | return -KEY_accept; | |
6984 | } | |
6985 | ||
6986 | goto unknown; | |
6987 | ||
6988 | case 'c': | |
6989 | switch (name[1]) | |
6990 | { | |
6991 | case 'a': | |
6992 | if (name[2] == 'l' && | |
6993 | name[3] == 'l' && | |
6994 | name[4] == 'e' && | |
6995 | name[5] == 'r') | |
6996 | { /* caller */ | |
6997 | return -KEY_caller; | |
6998 | } | |
6999 | ||
7000 | goto unknown; | |
7001 | ||
7002 | case 'h': | |
7003 | if (name[2] == 'r' && | |
7004 | name[3] == 'o' && | |
7005 | name[4] == 'o' && | |
7006 | name[5] == 't') | |
7007 | { /* chroot */ | |
7008 | return -KEY_chroot; | |
7009 | } | |
7010 | ||
7011 | goto unknown; | |
7012 | ||
7013 | default: | |
7014 | goto unknown; | |
7015 | } | |
7016 | ||
7017 | case 'd': | |
7018 | if (name[1] == 'e' && | |
7019 | name[2] == 'l' && | |
7020 | name[3] == 'e' && | |
7021 | name[4] == 't' && | |
7022 | name[5] == 'e') | |
7023 | { /* delete */ | |
7024 | return KEY_delete; | |
7025 | } | |
7026 | ||
7027 | goto unknown; | |
7028 | ||
7029 | case 'e': | |
7030 | switch (name[1]) | |
7031 | { | |
7032 | case 'l': | |
7033 | if (name[2] == 's' && | |
7034 | name[3] == 'e' && | |
7035 | name[4] == 'i' && | |
7036 | name[5] == 'f') | |
7037 | { /* elseif */ | |
7038 | if(ckWARN_d(WARN_SYNTAX)) | |
7039 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif"); | |
7040 | } | |
7041 | ||
7042 | goto unknown; | |
7043 | ||
7044 | case 'x': | |
7045 | if (name[2] == 'i' && | |
7046 | name[3] == 's' && | |
7047 | name[4] == 't' && | |
7048 | name[5] == 's') | |
7049 | { /* exists */ | |
7050 | return KEY_exists; | |
7051 | } | |
7052 | ||
7053 | goto unknown; | |
7054 | ||
7055 | default: | |
7056 | goto unknown; | |
7057 | } | |
7058 | ||
7059 | case 'f': | |
7060 | switch (name[1]) | |
7061 | { | |
7062 | case 'i': | |
7063 | if (name[2] == 'l' && | |
7064 | name[3] == 'e' && | |
7065 | name[4] == 'n' && | |
7066 | name[5] == 'o') | |
7067 | { /* fileno */ | |
7068 | return -KEY_fileno; | |
7069 | } | |
7070 | ||
7071 | goto unknown; | |
7072 | ||
7073 | case 'o': | |
7074 | if (name[2] == 'r' && | |
7075 | name[3] == 'm' && | |
7076 | name[4] == 'a' && | |
7077 | name[5] == 't') | |
7078 | { /* format */ | |
7079 | return KEY_format; | |
7080 | } | |
7081 | ||
7082 | goto unknown; | |
7083 | ||
7084 | default: | |
7085 | goto unknown; | |
7086 | } | |
7087 | ||
7088 | case 'g': | |
7089 | if (name[1] == 'm' && | |
7090 | name[2] == 't' && | |
7091 | name[3] == 'i' && | |
7092 | name[4] == 'm' && | |
7093 | name[5] == 'e') | |
7094 | { /* gmtime */ | |
7095 | return -KEY_gmtime; | |
7096 | } | |
7097 | ||
7098 | goto unknown; | |
7099 | ||
7100 | case 'l': | |
7101 | switch (name[1]) | |
7102 | { | |
7103 | case 'e': | |
7104 | if (name[2] == 'n' && | |
7105 | name[3] == 'g' && | |
7106 | name[4] == 't' && | |
7107 | name[5] == 'h') | |
7108 | { /* length */ | |
7109 | return -KEY_length; | |
7110 | } | |
7111 | ||
7112 | goto unknown; | |
7113 | ||
7114 | case 'i': | |
7115 | if (name[2] == 's' && | |
7116 | name[3] == 't' && | |
7117 | name[4] == 'e' && | |
7118 | name[5] == 'n') | |
7119 | { /* listen */ | |
7120 | return -KEY_listen; | |
7121 | } | |
7122 | ||
7123 | goto unknown; | |
7124 | ||
7125 | default: | |
7126 | goto unknown; | |
7127 | } | |
7128 | ||
7129 | case 'm': | |
7130 | if (name[1] == 's' && | |
7131 | name[2] == 'g') | |
7132 | { | |
7133 | switch (name[3]) | |
7134 | { | |
7135 | case 'c': | |
7136 | if (name[4] == 't' && | |
7137 | name[5] == 'l') | |
7138 | { /* msgctl */ | |
7139 | return -KEY_msgctl; | |
7140 | } | |
7141 | ||
7142 | goto unknown; | |
7143 | ||
7144 | case 'g': | |
7145 | if (name[4] == 'e' && | |
7146 | name[5] == 't') | |
7147 | { /* msgget */ | |
7148 | return -KEY_msgget; | |
7149 | } | |
7150 | ||
7151 | goto unknown; | |
7152 | ||
7153 | case 'r': | |
7154 | if (name[4] == 'c' && | |
7155 | name[5] == 'v') | |
7156 | { /* msgrcv */ | |
7157 | return -KEY_msgrcv; | |
7158 | } | |
7159 | ||
7160 | goto unknown; | |
7161 | ||
7162 | case 's': | |
7163 | if (name[4] == 'n' && | |
7164 | name[5] == 'd') | |
7165 | { /* msgsnd */ | |
7166 | return -KEY_msgsnd; | |
7167 | } | |
7168 | ||
7169 | goto unknown; | |
7170 | ||
7171 | default: | |
7172 | goto unknown; | |
7173 | } | |
7174 | } | |
7175 | ||
7176 | goto unknown; | |
7177 | ||
7178 | case 'p': | |
7179 | if (name[1] == 'r' && | |
7180 | name[2] == 'i' && | |
7181 | name[3] == 'n' && | |
7182 | name[4] == 't' && | |
7183 | name[5] == 'f') | |
7184 | { /* printf */ | |
7185 | return KEY_printf; | |
7186 | } | |
7187 | ||
7188 | goto unknown; | |
7189 | ||
7190 | case 'r': | |
7191 | switch (name[1]) | |
7192 | { | |
7193 | case 'e': | |
7194 | switch (name[2]) | |
7195 | { | |
7196 | case 'n': | |
7197 | if (name[3] == 'a' && | |
7198 | name[4] == 'm' && | |
7199 | name[5] == 'e') | |
7200 | { /* rename */ | |
7201 | return -KEY_rename; | |
7202 | } | |
7203 | ||
7204 | goto unknown; | |
7205 | ||
7206 | case 't': | |
7207 | if (name[3] == 'u' && | |
7208 | name[4] == 'r' && | |
7209 | name[5] == 'n') | |
7210 | { /* return */ | |
7211 | return KEY_return; | |
7212 | } | |
7213 | ||
7214 | goto unknown; | |
7215 | ||
7216 | default: | |
7217 | goto unknown; | |
7218 | } | |
7219 | ||
7220 | case 'i': | |
7221 | if (name[2] == 'n' && | |
7222 | name[3] == 'd' && | |
7223 | name[4] == 'e' && | |
7224 | name[5] == 'x') | |
7225 | { /* rindex */ | |
7226 | return -KEY_rindex; | |
7227 | } | |
7228 | ||
7229 | goto unknown; | |
7230 | ||
7231 | default: | |
7232 | goto unknown; | |
7233 | } | |
7234 | ||
7235 | case 's': | |
7236 | switch (name[1]) | |
7237 | { | |
7238 | case 'c': | |
7239 | if (name[2] == 'a' && | |
7240 | name[3] == 'l' && | |
7241 | name[4] == 'a' && | |
7242 | name[5] == 'r') | |
7243 | { /* scalar */ | |
7244 | return KEY_scalar; | |
7245 | } | |
7246 | ||
7247 | goto unknown; | |
7248 | ||
7249 | case 'e': | |
7250 | switch (name[2]) | |
7251 | { | |
7252 | case 'l': | |
7253 | if (name[3] == 'e' && | |
7254 | name[4] == 'c' && | |
7255 | name[5] == 't') | |
7256 | { /* select */ | |
7257 | return -KEY_select; | |
7258 | } | |
7259 | ||
7260 | goto unknown; | |
7261 | ||
7262 | case 'm': | |
7263 | switch (name[3]) | |
7264 | { | |
7265 | case 'c': | |
7266 | if (name[4] == 't' && | |
7267 | name[5] == 'l') | |
7268 | { /* semctl */ | |
7269 | return -KEY_semctl; | |
7270 | } | |
7271 | ||
7272 | goto unknown; | |
7273 | ||
7274 | case 'g': | |
7275 | if (name[4] == 'e' && | |
7276 | name[5] == 't') | |
7277 | { /* semget */ | |
7278 | return -KEY_semget; | |
7279 | } | |
7280 | ||
7281 | goto unknown; | |
7282 | ||
7283 | default: | |
7284 | goto unknown; | |
7285 | } | |
7286 | ||
7287 | default: | |
7288 | goto unknown; | |
7289 | } | |
7290 | ||
7291 | case 'h': | |
7292 | if (name[2] == 'm') | |
7293 | { | |
7294 | switch (name[3]) | |
7295 | { | |
7296 | case 'c': | |
7297 | if (name[4] == 't' && | |
7298 | name[5] == 'l') | |
7299 | { /* shmctl */ | |
7300 | return -KEY_shmctl; | |
7301 | } | |
7302 | ||
7303 | goto unknown; | |
7304 | ||
7305 | case 'g': | |
7306 | if (name[4] == 'e' && | |
7307 | name[5] == 't') | |
7308 | { /* shmget */ | |
7309 | return -KEY_shmget; | |
7310 | } | |
7311 | ||
7312 | goto unknown; | |
7313 | ||
7314 | default: | |
7315 | goto unknown; | |
7316 | } | |
7317 | } | |
7318 | ||
7319 | goto unknown; | |
7320 | ||
7321 | case 'o': | |
7322 | if (name[2] == 'c' && | |
7323 | name[3] == 'k' && | |
7324 | name[4] == 'e' && | |
7325 | name[5] == 't') | |
7326 | { /* socket */ | |
7327 | return -KEY_socket; | |
7328 | } | |
7329 | ||
7330 | goto unknown; | |
7331 | ||
7332 | case 'p': | |
7333 | if (name[2] == 'l' && | |
7334 | name[3] == 'i' && | |
7335 | name[4] == 'c' && | |
7336 | name[5] == 'e') | |
7337 | { /* splice */ | |
7338 | return -KEY_splice; | |
7339 | } | |
7340 | ||
7341 | goto unknown; | |
7342 | ||
7343 | case 'u': | |
7344 | if (name[2] == 'b' && | |
7345 | name[3] == 's' && | |
7346 | name[4] == 't' && | |
7347 | name[5] == 'r') | |
7348 | { /* substr */ | |
7349 | return -KEY_substr; | |
7350 | } | |
7351 | ||
7352 | goto unknown; | |
7353 | ||
7354 | case 'y': | |
7355 | if (name[2] == 's' && | |
7356 | name[3] == 't' && | |
7357 | name[4] == 'e' && | |
7358 | name[5] == 'm') | |
7359 | { /* system */ | |
7360 | return -KEY_system; | |
7361 | } | |
7362 | ||
7363 | goto unknown; | |
7364 | ||
7365 | default: | |
7366 | goto unknown; | |
7367 | } | |
7368 | ||
7369 | case 'u': | |
7370 | if (name[1] == 'n') | |
7371 | { | |
7372 | switch (name[2]) | |
7373 | { | |
7374 | case 'l': | |
7375 | switch (name[3]) | |
7376 | { | |
7377 | case 'e': | |
7378 | if (name[4] == 's' && | |
7379 | name[5] == 's') | |
7380 | { /* unless */ | |
7381 | return KEY_unless; | |
7382 | } | |
7383 | ||
7384 | goto unknown; | |
7385 | ||
7386 | case 'i': | |
7387 | if (name[4] == 'n' && | |
7388 | name[5] == 'k') | |
7389 | { /* unlink */ | |
7390 | return -KEY_unlink; | |
7391 | } | |
7392 | ||
7393 | goto unknown; | |
7394 | ||
7395 | default: | |
7396 | goto unknown; | |
7397 | } | |
7398 | ||
7399 | case 'p': | |
7400 | if (name[3] == 'a' && | |
7401 | name[4] == 'c' && | |
7402 | name[5] == 'k') | |
7403 | { /* unpack */ | |
7404 | return -KEY_unpack; | |
7405 | } | |
7406 | ||
7407 | goto unknown; | |
7408 | ||
7409 | default: | |
7410 | goto unknown; | |
7411 | } | |
7412 | } | |
7413 | ||
7414 | goto unknown; | |
7415 | ||
7416 | case 'v': | |
7417 | if (name[1] == 'a' && | |
7418 | name[2] == 'l' && | |
7419 | name[3] == 'u' && | |
7420 | name[4] == 'e' && | |
7421 | name[5] == 's') | |
7422 | { /* values */ | |
7423 | return -KEY_values; | |
7424 | } | |
7425 | ||
7426 | goto unknown; | |
7427 | ||
7428 | default: | |
7429 | goto unknown; | |
e2e1dd5a | 7430 | } |
4c3bbe0f MHM |
7431 | |
7432 | case 7: /* 28 tokens of length 7 */ | |
7433 | switch (name[0]) | |
7434 | { | |
7435 | case 'D': | |
7436 | if (name[1] == 'E' && | |
7437 | name[2] == 'S' && | |
7438 | name[3] == 'T' && | |
7439 | name[4] == 'R' && | |
7440 | name[5] == 'O' && | |
7441 | name[6] == 'Y') | |
7442 | { /* DESTROY */ | |
7443 | return KEY_DESTROY; | |
7444 | } | |
7445 | ||
7446 | goto unknown; | |
7447 | ||
7448 | case '_': | |
7449 | if (name[1] == '_' && | |
7450 | name[2] == 'E' && | |
7451 | name[3] == 'N' && | |
7452 | name[4] == 'D' && | |
7453 | name[5] == '_' && | |
7454 | name[6] == '_') | |
7455 | { /* __END__ */ | |
7456 | return KEY___END__; | |
7457 | } | |
7458 | ||
7459 | goto unknown; | |
7460 | ||
7461 | case 'b': | |
7462 | if (name[1] == 'i' && | |
7463 | name[2] == 'n' && | |
7464 | name[3] == 'm' && | |
7465 | name[4] == 'o' && | |
7466 | name[5] == 'd' && | |
7467 | name[6] == 'e') | |
7468 | { /* binmode */ | |
7469 | return -KEY_binmode; | |
7470 | } | |
7471 | ||
7472 | goto unknown; | |
7473 | ||
7474 | case 'c': | |
7475 | if (name[1] == 'o' && | |
7476 | name[2] == 'n' && | |
7477 | name[3] == 'n' && | |
7478 | name[4] == 'e' && | |
7479 | name[5] == 'c' && | |
7480 | name[6] == 't') | |
7481 | { /* connect */ | |
7482 | return -KEY_connect; | |
7483 | } | |
7484 | ||
7485 | goto unknown; | |
7486 | ||
7487 | case 'd': | |
7488 | switch (name[1]) | |
7489 | { | |
7490 | case 'b': | |
7491 | if (name[2] == 'm' && | |
7492 | name[3] == 'o' && | |
7493 | name[4] == 'p' && | |
7494 | name[5] == 'e' && | |
7495 | name[6] == 'n') | |
7496 | { /* dbmopen */ | |
7497 | return -KEY_dbmopen; | |
7498 | } | |
7499 | ||
7500 | goto unknown; | |
7501 | ||
7502 | case 'e': | |
7503 | if (name[2] == 'f' && | |
7504 | name[3] == 'i' && | |
7505 | name[4] == 'n' && | |
7506 | name[5] == 'e' && | |
7507 | name[6] == 'd') | |
7508 | { /* defined */ | |
7509 | return KEY_defined; | |
7510 | } | |
7511 | ||
7512 | goto unknown; | |
7513 | ||
7514 | default: | |
7515 | goto unknown; | |
7516 | } | |
7517 | ||
7518 | case 'f': | |
7519 | if (name[1] == 'o' && | |
7520 | name[2] == 'r' && | |
7521 | name[3] == 'e' && | |
7522 | name[4] == 'a' && | |
7523 | name[5] == 'c' && | |
7524 | name[6] == 'h') | |
7525 | { /* foreach */ | |
7526 | return KEY_foreach; | |
7527 | } | |
7528 | ||
7529 | goto unknown; | |
7530 | ||
7531 | case 'g': | |
7532 | if (name[1] == 'e' && | |
7533 | name[2] == 't' && | |
7534 | name[3] == 'p') | |
7535 | { | |
7536 | switch (name[4]) | |
7537 | { | |
7538 | case 'g': | |
7539 | if (name[5] == 'r' && | |
7540 | name[6] == 'p') | |
7541 | { /* getpgrp */ | |
7542 | return -KEY_getpgrp; | |
7543 | } | |
7544 | ||
7545 | goto unknown; | |
7546 | ||
7547 | case 'p': | |
7548 | if (name[5] == 'i' && | |
7549 | name[6] == 'd') | |
7550 | { /* getppid */ | |
7551 | return -KEY_getppid; | |
7552 | } | |
7553 | ||
7554 | goto unknown; | |
7555 | ||
7556 | default: | |
7557 | goto unknown; | |
7558 | } | |
7559 | } | |
7560 | ||
7561 | goto unknown; | |
7562 | ||
7563 | case 'l': | |
7564 | if (name[1] == 'c' && | |
7565 | name[2] == 'f' && | |
7566 | name[3] == 'i' && | |
7567 | name[4] == 'r' && | |
7568 | name[5] == 's' && | |
7569 | name[6] == 't') | |
7570 | { /* lcfirst */ | |
7571 | return -KEY_lcfirst; | |
7572 | } | |
7573 | ||
7574 | goto unknown; | |
7575 | ||
7576 | case 'o': | |
7577 | if (name[1] == 'p' && | |
7578 | name[2] == 'e' && | |
7579 | name[3] == 'n' && | |
7580 | name[4] == 'd' && | |
7581 | name[5] == 'i' && | |
7582 | name[6] == 'r') | |
7583 | { /* opendir */ | |
7584 | return -KEY_opendir; | |
7585 | } | |
7586 | ||
7587 | goto unknown; | |
7588 | ||
7589 | case 'p': | |
7590 | if (name[1] == 'a' && | |
7591 | name[2] == 'c' && | |
7592 | name[3] == 'k' && | |
7593 | name[4] == 'a' && | |
7594 | name[5] == 'g' && | |
7595 | name[6] == 'e') | |
7596 | { /* package */ | |
7597 | return KEY_package; | |
7598 | } | |
7599 | ||
7600 | goto unknown; | |
7601 | ||
7602 | case 'r': | |
7603 | if (name[1] == 'e') | |
7604 | { | |
7605 | switch (name[2]) | |
7606 | { | |
7607 | case 'a': | |
7608 | if (name[3] == 'd' && | |
7609 | name[4] == 'd' && | |
7610 | name[5] == 'i' && | |
7611 | name[6] == 'r') | |
7612 | { /* readdir */ | |
7613 | return -KEY_readdir; | |
7614 | } | |
7615 | ||
7616 | goto unknown; | |
7617 | ||
7618 | case 'q': | |
7619 | if (name[3] == 'u' && | |
7620 | name[4] == 'i' && | |
7621 | name[5] == 'r' && | |
7622 | name[6] == 'e') | |
7623 | { /* require */ | |
7624 | return KEY_require; | |
7625 | } | |
7626 | ||
7627 | goto unknown; | |
7628 | ||
7629 | case 'v': | |
7630 | if (name[3] == 'e' && | |
7631 | name[4] == 'r' && | |
7632 | name[5] == 's' && | |
7633 | name[6] == 'e') | |
7634 | { /* reverse */ | |
7635 | return -KEY_reverse; | |
7636 | } | |
7637 | ||
7638 | goto unknown; | |
7639 | ||
7640 | default: | |
7641 | goto unknown; | |
7642 | } | |
7643 | } | |
7644 | ||
7645 | goto unknown; | |
7646 | ||
7647 | case 's': | |
7648 | switch (name[1]) | |
7649 | { | |
7650 | case 'e': | |
7651 | switch (name[2]) | |
7652 | { | |
7653 | case 'e': | |
7654 | if (name[3] == 'k' && | |
7655 | name[4] == 'd' && | |
7656 | name[5] == 'i' && | |
7657 | name[6] == 'r') | |
7658 | { /* seekdir */ | |
7659 | return -KEY_seekdir; | |
7660 | } | |
7661 | ||
7662 | goto unknown; | |
7663 | ||
7664 | case 't': | |
7665 | if (name[3] == 'p' && | |
7666 | name[4] == 'g' && | |
7667 | name[5] == 'r' && | |
7668 | name[6] == 'p') | |
7669 | { /* setpgrp */ | |
7670 | return -KEY_setpgrp; | |
7671 | } | |
7672 | ||
7673 | goto unknown; | |
7674 | ||
7675 | default: | |
7676 | goto unknown; | |
7677 | } | |
7678 | ||
7679 | case 'h': | |
7680 | if (name[2] == 'm' && | |
7681 | name[3] == 'r' && | |
7682 | name[4] == 'e' && | |
7683 | name[5] == 'a' && | |
7684 | name[6] == 'd') | |
7685 | { /* shmread */ | |
7686 | return -KEY_shmread; | |
7687 | } | |
7688 | ||
7689 | goto unknown; | |
7690 | ||
7691 | case 'p': | |
7692 | if (name[2] == 'r' && | |
7693 | name[3] == 'i' && | |
7694 | name[4] == 'n' && | |
7695 | name[5] == 't' && | |
7696 | name[6] == 'f') | |
7697 | { /* sprintf */ | |
7698 | return -KEY_sprintf; | |
7699 | } | |
7700 | ||
7701 | goto unknown; | |
7702 | ||
7703 | case 'y': | |
7704 | switch (name[2]) | |
7705 | { | |
7706 | case 'm': | |
7707 | if (name[3] == 'l' && | |
7708 | name[4] == 'i' && | |
7709 | name[5] == 'n' && | |
7710 | name[6] == 'k') | |
7711 | { /* symlink */ | |
7712 | return -KEY_symlink; | |
7713 | } | |
7714 | ||
7715 | goto unknown; | |
7716 | ||
7717 | case 's': | |
7718 | switch (name[3]) | |
7719 | { | |
7720 | case 'c': | |
7721 | if (name[4] == 'a' && | |
7722 | name[5] == 'l' && | |
7723 | name[6] == 'l') | |
7724 | { /* syscall */ | |
7725 | return -KEY_syscall; | |
7726 | } | |
7727 | ||
7728 | goto unknown; | |
7729 | ||
7730 | case 'o': | |
7731 | if (name[4] == 'p' && | |
7732 | name[5] == 'e' && | |
7733 | name[6] == 'n') | |
7734 | { /* sysopen */ | |
7735 | return -KEY_sysopen; | |
7736 | } | |
7737 | ||
7738 | goto unknown; | |
7739 | ||
7740 | case 'r': | |
7741 | if (name[4] == 'e' && | |
7742 | name[5] == 'a' && | |
7743 | name[6] == 'd') | |
7744 | { /* sysread */ | |
7745 | return -KEY_sysread; | |
7746 | } | |
7747 | ||
7748 | goto unknown; | |
7749 | ||
7750 | case 's': | |
7751 | if (name[4] == 'e' && | |
7752 | name[5] == 'e' && | |
7753 | name[6] == 'k') | |
7754 | { /* sysseek */ | |
7755 | return -KEY_sysseek; | |
7756 | } | |
7757 | ||
7758 | goto unknown; | |
7759 | ||
7760 | default: | |
7761 | goto unknown; | |
7762 | } | |
7763 | ||
7764 | default: | |
7765 | goto unknown; | |
7766 | } | |
7767 | ||
7768 | default: | |
7769 | goto unknown; | |
7770 | } | |
7771 | ||
7772 | case 't': | |
7773 | if (name[1] == 'e' && | |
7774 | name[2] == 'l' && | |
7775 | name[3] == 'l' && | |
7776 | name[4] == 'd' && | |
7777 | name[5] == 'i' && | |
7778 | name[6] == 'r') | |
7779 | { /* telldir */ | |
7780 | return -KEY_telldir; | |
7781 | } | |
7782 | ||
7783 | goto unknown; | |
7784 | ||
7785 | case 'u': | |
7786 | switch (name[1]) | |
7787 | { | |
7788 | case 'c': | |
7789 | if (name[2] == 'f' && | |
7790 | name[3] == 'i' && | |
7791 | name[4] == 'r' && | |
7792 | name[5] == 's' && | |
7793 | name[6] == 't') | |
7794 | { /* ucfirst */ | |
7795 | return -KEY_ucfirst; | |
7796 | } | |
7797 | ||
7798 | goto unknown; | |
7799 | ||
7800 | case 'n': | |
7801 | if (name[2] == 's' && | |
7802 | name[3] == 'h' && | |
7803 | name[4] == 'i' && | |
7804 | name[5] == 'f' && | |
7805 | name[6] == 't') | |
7806 | { /* unshift */ | |
7807 | return -KEY_unshift; | |
7808 | } | |
7809 | ||
7810 | goto unknown; | |
7811 | ||
7812 | default: | |
7813 | goto unknown; | |
7814 | } | |
7815 | ||
7816 | case 'w': | |
7817 | if (name[1] == 'a' && | |
7818 | name[2] == 'i' && | |
7819 | name[3] == 't' && | |
7820 | name[4] == 'p' && | |
7821 | name[5] == 'i' && | |
7822 | name[6] == 'd') | |
7823 | { /* waitpid */ | |
7824 | return -KEY_waitpid; | |
7825 | } | |
7826 | ||
7827 | goto unknown; | |
7828 | ||
7829 | default: | |
7830 | goto unknown; | |
7831 | } | |
7832 | ||
7833 | case 8: /* 26 tokens of length 8 */ | |
7834 | switch (name[0]) | |
7835 | { | |
7836 | case 'A': | |
7837 | if (name[1] == 'U' && | |
7838 | name[2] == 'T' && | |
7839 | name[3] == 'O' && | |
7840 | name[4] == 'L' && | |
7841 | name[5] == 'O' && | |
7842 | name[6] == 'A' && | |
7843 | name[7] == 'D') | |
7844 | { /* AUTOLOAD */ | |
7845 | return KEY_AUTOLOAD; | |
7846 | } | |
7847 | ||
7848 | goto unknown; | |
7849 | ||
7850 | case '_': | |
7851 | if (name[1] == '_') | |
7852 | { | |
7853 | switch (name[2]) | |
7854 | { | |
7855 | case 'D': | |
7856 | if (name[3] == 'A' && | |
7857 | name[4] == 'T' && | |
7858 | name[5] == 'A' && | |
7859 | name[6] == '_' && | |
7860 | name[7] == '_') | |
7861 | { /* __DATA__ */ | |
7862 | return KEY___DATA__; | |
7863 | } | |
7864 | ||
7865 | goto unknown; | |
7866 | ||
7867 | case 'F': | |
7868 | if (name[3] == 'I' && | |
7869 | name[4] == 'L' && | |
7870 | name[5] == 'E' && | |
7871 | name[6] == '_' && | |
7872 | name[7] == '_') | |
7873 | { /* __FILE__ */ | |
7874 | return -KEY___FILE__; | |
7875 | } | |
7876 | ||
7877 | goto unknown; | |
7878 | ||
7879 | case 'L': | |
7880 | if (name[3] == 'I' && | |
7881 | name[4] == 'N' && | |
7882 | name[5] == 'E' && | |
7883 | name[6] == '_' && | |
7884 | name[7] == '_') | |
7885 | { /* __LINE__ */ | |
7886 | return -KEY___LINE__; | |
7887 | } | |
7888 | ||
7889 | goto unknown; | |
7890 | ||
7891 | default: | |
7892 | goto unknown; | |
7893 | } | |
7894 | } | |
7895 | ||
7896 | goto unknown; | |
7897 | ||
7898 | case 'c': | |
7899 | switch (name[1]) | |
7900 | { | |
7901 | case 'l': | |
7902 | if (name[2] == 'o' && | |
7903 | name[3] == 's' && | |
7904 | name[4] == 'e' && | |
7905 | name[5] == 'd' && | |
7906 | name[6] == 'i' && | |
7907 | name[7] == 'r') | |
7908 | { /* closedir */ | |
7909 | return -KEY_closedir; | |
7910 | } | |
7911 | ||
7912 | goto unknown; | |
7913 | ||
7914 | case 'o': | |
7915 | if (name[2] == 'n' && | |
7916 | name[3] == 't' && | |
7917 | name[4] == 'i' && | |
7918 | name[5] == 'n' && | |
7919 | name[6] == 'u' && | |
7920 | name[7] == 'e') | |
7921 | { /* continue */ | |
7922 | return -KEY_continue; | |
7923 | } | |
7924 | ||
7925 | goto unknown; | |
7926 | ||
7927 | default: | |
7928 | goto unknown; | |
7929 | } | |
7930 | ||
7931 | case 'd': | |
7932 | if (name[1] == 'b' && | |
7933 | name[2] == 'm' && | |
7934 | name[3] == 'c' && | |
7935 | name[4] == 'l' && | |
7936 | name[5] == 'o' && | |
7937 | name[6] == 's' && | |
7938 | name[7] == 'e') | |
7939 | { /* dbmclose */ | |
7940 | return -KEY_dbmclose; | |
7941 | } | |
7942 | ||
7943 | goto unknown; | |
7944 | ||
7945 | case 'e': | |
7946 | if (name[1] == 'n' && | |
7947 | name[2] == 'd') | |
7948 | { | |
7949 | switch (name[3]) | |
7950 | { | |
7951 | case 'g': | |
7952 | if (name[4] == 'r' && | |
7953 | name[5] == 'e' && | |
7954 | name[6] == 'n' && | |
7955 | name[7] == 't') | |
7956 | { /* endgrent */ | |
7957 | return -KEY_endgrent; | |
7958 | } | |
7959 | ||
7960 | goto unknown; | |
7961 | ||
7962 | case 'p': | |
7963 | if (name[4] == 'w' && | |
7964 | name[5] == 'e' && | |
7965 | name[6] == 'n' && | |
7966 | name[7] == 't') | |
7967 | { /* endpwent */ | |
7968 | return -KEY_endpwent; | |
7969 | } | |
7970 | ||
7971 | goto unknown; | |
7972 | ||
7973 | default: | |
7974 | goto unknown; | |
7975 | } | |
7976 | } | |
7977 | ||
7978 | goto unknown; | |
7979 | ||
7980 | case 'f': | |
7981 | if (name[1] == 'o' && | |
7982 | name[2] == 'r' && | |
7983 | name[3] == 'm' && | |
7984 | name[4] == 'l' && | |
7985 | name[5] == 'i' && | |
7986 | name[6] == 'n' && | |
7987 | name[7] == 'e') | |
7988 | { /* formline */ | |
7989 | return -KEY_formline; | |
7990 | } | |
7991 | ||
7992 | goto unknown; | |
7993 | ||
7994 | case 'g': | |
7995 | if (name[1] == 'e' && | |
7996 | name[2] == 't') | |
7997 | { | |
7998 | switch (name[3]) | |
7999 | { | |
8000 | case 'g': | |
8001 | if (name[4] == 'r') | |
8002 | { | |
8003 | switch (name[5]) | |
8004 | { | |
8005 | case 'e': | |
8006 | if (name[6] == 'n' && | |
8007 | name[7] == 't') | |
8008 | { /* getgrent */ | |
8009 | return -KEY_getgrent; | |
8010 | } | |
8011 | ||
8012 | goto unknown; | |
8013 | ||
8014 | case 'g': | |
8015 | if (name[6] == 'i' && | |
8016 | name[7] == 'd') | |
8017 | { /* getgrgid */ | |
8018 | return -KEY_getgrgid; | |
8019 | } | |
8020 | ||
8021 | goto unknown; | |
8022 | ||
8023 | case 'n': | |
8024 | if (name[6] == 'a' && | |
8025 | name[7] == 'm') | |
8026 | { /* getgrnam */ | |
8027 | return -KEY_getgrnam; | |
8028 | } | |
8029 | ||
8030 | goto unknown; | |
8031 | ||
8032 | default: | |
8033 | goto unknown; | |
8034 | } | |
8035 | } | |
8036 | ||
8037 | goto unknown; | |
8038 | ||
8039 | case 'l': | |
8040 | if (name[4] == 'o' && | |
8041 | name[5] == 'g' && | |
8042 | name[6] == 'i' && | |
8043 | name[7] == 'n') | |
8044 | { /* getlogin */ | |
8045 | return -KEY_getlogin; | |
8046 | } | |
8047 | ||
8048 | goto unknown; | |
8049 | ||
8050 | case 'p': | |
8051 | if (name[4] == 'w') | |
8052 | { | |
8053 | switch (name[5]) | |
8054 | { | |
8055 | case 'e': | |
8056 | if (name[6] == 'n' && | |
8057 | name[7] == 't') | |
8058 | { /* getpwent */ | |
8059 | return -KEY_getpwent; | |
8060 | } | |
8061 | ||
8062 | goto unknown; | |
8063 | ||
8064 | case 'n': | |
8065 | if (name[6] == 'a' && | |
8066 | name[7] == 'm') | |
8067 | { /* getpwnam */ | |
8068 | return -KEY_getpwnam; | |
8069 | } | |
8070 | ||
8071 | goto unknown; | |
8072 | ||
8073 | case 'u': | |
8074 | if (name[6] == 'i' && | |
8075 | name[7] == 'd') | |
8076 | { /* getpwuid */ | |
8077 | return -KEY_getpwuid; | |
8078 | } | |
8079 | ||
8080 | goto unknown; | |
8081 | ||
8082 | default: | |
8083 | goto unknown; | |
8084 | } | |
8085 | } | |
8086 | ||
8087 | goto unknown; | |
8088 | ||
8089 | default: | |
8090 | goto unknown; | |
8091 | } | |
8092 | } | |
8093 | ||
8094 | goto unknown; | |
8095 | ||
8096 | case 'r': | |
8097 | if (name[1] == 'e' && | |
8098 | name[2] == 'a' && | |
8099 | name[3] == 'd') | |
8100 | { | |
8101 | switch (name[4]) | |
8102 | { | |
8103 | case 'l': | |
8104 | if (name[5] == 'i' && | |
8105 | name[6] == 'n') | |
8106 | { | |
8107 | switch (name[7]) | |
8108 | { | |
8109 | case 'e': | |
8110 | { /* readline */ | |
8111 | return -KEY_readline; | |
8112 | } | |
8113 | ||
4c3bbe0f MHM |
8114 | case 'k': |
8115 | { /* readlink */ | |
8116 | return -KEY_readlink; | |
8117 | } | |
8118 | ||
4c3bbe0f MHM |
8119 | default: |
8120 | goto unknown; | |
8121 | } | |
8122 | } | |
8123 | ||
8124 | goto unknown; | |
8125 | ||
8126 | case 'p': | |
8127 | if (name[5] == 'i' && | |
8128 | name[6] == 'p' && | |
8129 | name[7] == 'e') | |
8130 | { /* readpipe */ | |
8131 | return -KEY_readpipe; | |
8132 | } | |
8133 | ||
8134 | goto unknown; | |
8135 | ||
8136 | default: | |
8137 | goto unknown; | |
8138 | } | |
8139 | } | |
8140 | ||
8141 | goto unknown; | |
8142 | ||
8143 | case 's': | |
8144 | switch (name[1]) | |
8145 | { | |
8146 | case 'e': | |
8147 | if (name[2] == 't') | |
8148 | { | |
8149 | switch (name[3]) | |
8150 | { | |
8151 | case 'g': | |
8152 | if (name[4] == 'r' && | |
8153 | name[5] == 'e' && | |
8154 | name[6] == 'n' && | |
8155 | name[7] == 't') | |
8156 | { /* setgrent */ | |
8157 | return -KEY_setgrent; | |
8158 | } | |
8159 | ||
8160 | goto unknown; | |
8161 | ||
8162 | case 'p': | |
8163 | if (name[4] == 'w' && | |
8164 | name[5] == 'e' && | |
8165 | name[6] == 'n' && | |
8166 | name[7] == 't') | |
8167 | { /* setpwent */ | |
8168 | return -KEY_setpwent; | |
8169 | } | |
8170 | ||
8171 | goto unknown; | |
8172 | ||
8173 | default: | |
8174 | goto unknown; | |
8175 | } | |
8176 | } | |
8177 | ||
8178 | goto unknown; | |
8179 | ||
8180 | case 'h': | |
8181 | switch (name[2]) | |
8182 | { | |
8183 | case 'm': | |
8184 | if (name[3] == 'w' && | |
8185 | name[4] == 'r' && | |
8186 | name[5] == 'i' && | |
8187 | name[6] == 't' && | |
8188 | name[7] == 'e') | |
8189 | { /* shmwrite */ | |
8190 | return -KEY_shmwrite; | |
8191 | } | |
8192 | ||
8193 | goto unknown; | |
8194 | ||
8195 | case 'u': | |
8196 | if (name[3] == 't' && | |
8197 | name[4] == 'd' && | |
8198 | name[5] == 'o' && | |
8199 | name[6] == 'w' && | |
8200 | name[7] == 'n') | |
8201 | { /* shutdown */ | |
8202 | return -KEY_shutdown; | |
8203 | } | |
8204 | ||
8205 | goto unknown; | |
8206 | ||
8207 | default: | |
8208 | goto unknown; | |
8209 | } | |
8210 | ||
8211 | case 'y': | |
8212 | if (name[2] == 's' && | |
8213 | name[3] == 'w' && | |
8214 | name[4] == 'r' && | |
8215 | name[5] == 'i' && | |
8216 | name[6] == 't' && | |
8217 | name[7] == 'e') | |
8218 | { /* syswrite */ | |
8219 | return -KEY_syswrite; | |
8220 | } | |
8221 | ||
8222 | goto unknown; | |
8223 | ||
8224 | default: | |
8225 | goto unknown; | |
8226 | } | |
8227 | ||
8228 | case 't': | |
8229 | if (name[1] == 'r' && | |
8230 | name[2] == 'u' && | |
8231 | name[3] == 'n' && | |
8232 | name[4] == 'c' && | |
8233 | name[5] == 'a' && | |
8234 | name[6] == 't' && | |
8235 | name[7] == 'e') | |
8236 | { /* truncate */ | |
8237 | return -KEY_truncate; | |
8238 | } | |
8239 | ||
8240 | goto unknown; | |
8241 | ||
8242 | default: | |
8243 | goto unknown; | |
8244 | } | |
8245 | ||
8246 | case 9: /* 8 tokens of length 9 */ | |
8247 | switch (name[0]) | |
8248 | { | |
8249 | case 'e': | |
8250 | if (name[1] == 'n' && | |
8251 | name[2] == 'd' && | |
8252 | name[3] == 'n' && | |
8253 | name[4] == 'e' && | |
8254 | name[5] == 't' && | |
8255 | name[6] == 'e' && | |
8256 | name[7] == 'n' && | |
8257 | name[8] == 't') | |
8258 | { /* endnetent */ | |
8259 | return -KEY_endnetent; | |
8260 | } | |
8261 | ||
8262 | goto unknown; | |
8263 | ||
8264 | case 'g': | |
8265 | if (name[1] == 'e' && | |
8266 | name[2] == 't' && | |
8267 | name[3] == 'n' && | |
8268 | name[4] == 'e' && | |
8269 | name[5] == 't' && | |
8270 | name[6] == 'e' && | |
8271 | name[7] == 'n' && | |
8272 | name[8] == 't') | |
8273 | { /* getnetent */ | |
8274 | return -KEY_getnetent; | |
8275 | } | |
8276 | ||
8277 | goto unknown; | |
8278 | ||
8279 | case 'l': | |
8280 | if (name[1] == 'o' && | |
8281 | name[2] == 'c' && | |
8282 | name[3] == 'a' && | |
8283 | name[4] == 'l' && | |
8284 | name[5] == 't' && | |
8285 | name[6] == 'i' && | |
8286 | name[7] == 'm' && | |
8287 | name[8] == 'e') | |
8288 | { /* localtime */ | |
8289 | return -KEY_localtime; | |
8290 | } | |
8291 | ||
8292 | goto unknown; | |
8293 | ||
8294 | case 'p': | |
8295 | if (name[1] == 'r' && | |
8296 | name[2] == 'o' && | |
8297 | name[3] == 't' && | |
8298 | name[4] == 'o' && | |
8299 | name[5] == 't' && | |
8300 | name[6] == 'y' && | |
8301 | name[7] == 'p' && | |
8302 | name[8] == 'e') | |
8303 | { /* prototype */ | |
8304 | return KEY_prototype; | |
8305 | } | |
8306 | ||
8307 | goto unknown; | |
8308 | ||
8309 | case 'q': | |
8310 | if (name[1] == 'u' && | |
8311 | name[2] == 'o' && | |
8312 | name[3] == 't' && | |
8313 | name[4] == 'e' && | |
8314 | name[5] == 'm' && | |
8315 | name[6] == 'e' && | |
8316 | name[7] == 't' && | |
8317 | name[8] == 'a') | |
8318 | { /* quotemeta */ | |
8319 | return -KEY_quotemeta; | |
8320 | } | |
8321 | ||
8322 | goto unknown; | |
8323 | ||
8324 | case 'r': | |
8325 | if (name[1] == 'e' && | |
8326 | name[2] == 'w' && | |
8327 | name[3] == 'i' && | |
8328 | name[4] == 'n' && | |
8329 | name[5] == 'd' && | |
8330 | name[6] == 'd' && | |
8331 | name[7] == 'i' && | |
8332 | name[8] == 'r') | |
8333 | { /* rewinddir */ | |
8334 | return -KEY_rewinddir; | |
8335 | } | |
8336 | ||
8337 | goto unknown; | |
8338 | ||
8339 | case 's': | |
8340 | if (name[1] == 'e' && | |
8341 | name[2] == 't' && | |
8342 | name[3] == 'n' && | |
8343 | name[4] == 'e' && | |
8344 | name[5] == 't' && | |
8345 | name[6] == 'e' && | |
8346 | name[7] == 'n' && | |
8347 | name[8] == 't') | |
8348 | { /* setnetent */ | |
8349 | return -KEY_setnetent; | |
8350 | } | |
8351 | ||
8352 | goto unknown; | |
8353 | ||
8354 | case 'w': | |
8355 | if (name[1] == 'a' && | |
8356 | name[2] == 'n' && | |
8357 | name[3] == 't' && | |
8358 | name[4] == 'a' && | |
8359 | name[5] == 'r' && | |
8360 | name[6] == 'r' && | |
8361 | name[7] == 'a' && | |
8362 | name[8] == 'y') | |
8363 | { /* wantarray */ | |
8364 | return -KEY_wantarray; | |
8365 | } | |
8366 | ||
8367 | goto unknown; | |
8368 | ||
8369 | default: | |
8370 | goto unknown; | |
8371 | } | |
8372 | ||
8373 | case 10: /* 9 tokens of length 10 */ | |
8374 | switch (name[0]) | |
8375 | { | |
8376 | case 'e': | |
8377 | if (name[1] == 'n' && | |
8378 | name[2] == 'd') | |
8379 | { | |
8380 | switch (name[3]) | |
8381 | { | |
8382 | case 'h': | |
8383 | if (name[4] == 'o' && | |
8384 | name[5] == 's' && | |
8385 | name[6] == 't' && | |
8386 | name[7] == 'e' && | |
8387 | name[8] == 'n' && | |
8388 | name[9] == 't') | |
8389 | { /* endhostent */ | |
8390 | return -KEY_endhostent; | |
8391 | } | |
8392 | ||
8393 | goto unknown; | |
8394 | ||
8395 | case 's': | |
8396 | if (name[4] == 'e' && | |
8397 | name[5] == 'r' && | |
8398 | name[6] == 'v' && | |
8399 | name[7] == 'e' && | |
8400 | name[8] == 'n' && | |
8401 | name[9] == 't') | |
8402 | { /* endservent */ | |
8403 | return -KEY_endservent; | |
8404 | } | |
8405 | ||
8406 | goto unknown; | |
8407 | ||
8408 | default: | |
8409 | goto unknown; | |
8410 | } | |
8411 | } | |
8412 | ||
8413 | goto unknown; | |
8414 | ||
8415 | case 'g': | |
8416 | if (name[1] == 'e' && | |
8417 | name[2] == 't') | |
8418 | { | |
8419 | switch (name[3]) | |
8420 | { | |
8421 | case 'h': | |
8422 | if (name[4] == 'o' && | |
8423 | name[5] == 's' && | |
8424 | name[6] == 't' && | |
8425 | name[7] == 'e' && | |
8426 | name[8] == 'n' && | |
8427 | name[9] == 't') | |
8428 | { /* gethostent */ | |
8429 | return -KEY_gethostent; | |
8430 | } | |
8431 | ||
8432 | goto unknown; | |
8433 | ||
8434 | case 's': | |
8435 | switch (name[4]) | |
8436 | { | |
8437 | case 'e': | |
8438 | if (name[5] == 'r' && | |
8439 | name[6] == 'v' && | |
8440 | name[7] == 'e' && | |
8441 | name[8] == 'n' && | |
8442 | name[9] == 't') | |
8443 | { /* getservent */ | |
8444 | return -KEY_getservent; | |
8445 | } | |
8446 | ||
8447 | goto unknown; | |
8448 | ||
8449 | case 'o': | |
8450 | if (name[5] == 'c' && | |
8451 | name[6] == 'k' && | |
8452 | name[7] == 'o' && | |
8453 | name[8] == 'p' && | |
8454 | name[9] == 't') | |
8455 | { /* getsockopt */ | |
8456 | return -KEY_getsockopt; | |
8457 | } | |
8458 | ||
8459 | goto unknown; | |
8460 | ||
8461 | default: | |
8462 | goto unknown; | |
8463 | } | |
8464 | ||
8465 | default: | |
8466 | goto unknown; | |
8467 | } | |
8468 | } | |
8469 | ||
8470 | goto unknown; | |
8471 | ||
8472 | case 's': | |
8473 | switch (name[1]) | |
8474 | { | |
8475 | case 'e': | |
8476 | if (name[2] == 't') | |
8477 | { | |
8478 | switch (name[3]) | |
8479 | { | |
8480 | case 'h': | |
8481 | if (name[4] == 'o' && | |
8482 | name[5] == 's' && | |
8483 | name[6] == 't' && | |
8484 | name[7] == 'e' && | |
8485 | name[8] == 'n' && | |
8486 | name[9] == 't') | |
8487 | { /* sethostent */ | |
8488 | return -KEY_sethostent; | |
8489 | } | |
8490 | ||
8491 | goto unknown; | |
8492 | ||
8493 | case 's': | |
8494 | switch (name[4]) | |
8495 | { | |
8496 | case 'e': | |
8497 | if (name[5] == 'r' && | |
8498 | name[6] == 'v' && | |
8499 | name[7] == 'e' && | |
8500 | name[8] == 'n' && | |
8501 | name[9] == 't') | |
8502 | { /* setservent */ | |
8503 | return -KEY_setservent; | |
8504 | } | |
8505 | ||
8506 | goto unknown; | |
8507 | ||
8508 | case 'o': | |
8509 | if (name[5] == 'c' && | |
8510 | name[6] == 'k' && | |
8511 | name[7] == 'o' && | |
8512 | name[8] == 'p' && | |
8513 | name[9] == 't') | |
8514 | { /* setsockopt */ | |
8515 | return -KEY_setsockopt; | |
8516 | } | |
8517 | ||
8518 | goto unknown; | |
8519 | ||
8520 | default: | |
8521 | goto unknown; | |
8522 | } | |
8523 | ||
8524 | default: | |
8525 | goto unknown; | |
8526 | } | |
8527 | } | |
8528 | ||
8529 | goto unknown; | |
8530 | ||
8531 | case 'o': | |
8532 | if (name[2] == 'c' && | |
8533 | name[3] == 'k' && | |
8534 | name[4] == 'e' && | |
8535 | name[5] == 't' && | |
8536 | name[6] == 'p' && | |
8537 | name[7] == 'a' && | |
8538 | name[8] == 'i' && | |
8539 | name[9] == 'r') | |
8540 | { /* socketpair */ | |
8541 | return -KEY_socketpair; | |
8542 | } | |
8543 | ||
8544 | goto unknown; | |
8545 | ||
8546 | default: | |
8547 | goto unknown; | |
8548 | } | |
8549 | ||
8550 | default: | |
8551 | goto unknown; | |
e2e1dd5a | 8552 | } |
4c3bbe0f MHM |
8553 | |
8554 | case 11: /* 8 tokens of length 11 */ | |
8555 | switch (name[0]) | |
8556 | { | |
8557 | case '_': | |
8558 | if (name[1] == '_' && | |
8559 | name[2] == 'P' && | |
8560 | name[3] == 'A' && | |
8561 | name[4] == 'C' && | |
8562 | name[5] == 'K' && | |
8563 | name[6] == 'A' && | |
8564 | name[7] == 'G' && | |
8565 | name[8] == 'E' && | |
8566 | name[9] == '_' && | |
8567 | name[10] == '_') | |
8568 | { /* __PACKAGE__ */ | |
8569 | return -KEY___PACKAGE__; | |
8570 | } | |
8571 | ||
8572 | goto unknown; | |
8573 | ||
8574 | case 'e': | |
8575 | if (name[1] == 'n' && | |
8576 | name[2] == 'd' && | |
8577 | name[3] == 'p' && | |
8578 | name[4] == 'r' && | |
8579 | name[5] == 'o' && | |
8580 | name[6] == 't' && | |
8581 | name[7] == 'o' && | |
8582 | name[8] == 'e' && | |
8583 | name[9] == 'n' && | |
8584 | name[10] == 't') | |
8585 | { /* endprotoent */ | |
8586 | return -KEY_endprotoent; | |
8587 | } | |
8588 | ||
8589 | goto unknown; | |
8590 | ||
8591 | case 'g': | |
8592 | if (name[1] == 'e' && | |
8593 | name[2] == 't') | |
8594 | { | |
8595 | switch (name[3]) | |
8596 | { | |
8597 | case 'p': | |
8598 | switch (name[4]) | |
8599 | { | |
8600 | case 'e': | |
8601 | if (name[5] == 'e' && | |
8602 | name[6] == 'r' && | |
8603 | name[7] == 'n' && | |
8604 | name[8] == 'a' && | |
8605 | name[9] == 'm' && | |
8606 | name[10] == 'e') | |
8607 | { /* getpeername */ | |
8608 | return -KEY_getpeername; | |
8609 | } | |
8610 | ||
8611 | goto unknown; | |
8612 | ||
8613 | case 'r': | |
8614 | switch (name[5]) | |
8615 | { | |
8616 | case 'i': | |
8617 | if (name[6] == 'o' && | |
8618 | name[7] == 'r' && | |
8619 | name[8] == 'i' && | |
8620 | name[9] == 't' && | |
8621 | name[10] == 'y') | |
8622 | { /* getpriority */ | |
8623 | return -KEY_getpriority; | |
8624 | } | |
8625 | ||
8626 | goto unknown; | |
8627 | ||
8628 | case 'o': | |
8629 | if (name[6] == 't' && | |
8630 | name[7] == 'o' && | |
8631 | name[8] == 'e' && | |
8632 | name[9] == 'n' && | |
8633 | name[10] == 't') | |
8634 | { /* getprotoent */ | |
8635 | return -KEY_getprotoent; | |
8636 | } | |
8637 | ||
8638 | goto unknown; | |
8639 | ||
8640 | default: | |
8641 | goto unknown; | |
8642 | } | |
8643 | ||
8644 | default: | |
8645 | goto unknown; | |
8646 | } | |
8647 | ||
8648 | case 's': | |
8649 | if (name[4] == 'o' && | |
8650 | name[5] == 'c' && | |
8651 | name[6] == 'k' && | |
8652 | name[7] == 'n' && | |
8653 | name[8] == 'a' && | |
8654 | name[9] == 'm' && | |
8655 | name[10] == 'e') | |
8656 | { /* getsockname */ | |
8657 | return -KEY_getsockname; | |
8658 | } | |
8659 | ||
8660 | goto unknown; | |
8661 | ||
8662 | default: | |
8663 | goto unknown; | |
8664 | } | |
8665 | } | |
8666 | ||
8667 | goto unknown; | |
8668 | ||
8669 | case 's': | |
8670 | if (name[1] == 'e' && | |
8671 | name[2] == 't' && | |
8672 | name[3] == 'p' && | |
8673 | name[4] == 'r') | |
8674 | { | |
8675 | switch (name[5]) | |
8676 | { | |
8677 | case 'i': | |
8678 | if (name[6] == 'o' && | |
8679 | name[7] == 'r' && | |
8680 | name[8] == 'i' && | |
8681 | name[9] == 't' && | |
8682 | name[10] == 'y') | |
8683 | { /* setpriority */ | |
8684 | return -KEY_setpriority; | |
8685 | } | |
8686 | ||
8687 | goto unknown; | |
8688 | ||
8689 | case 'o': | |
8690 | if (name[6] == 't' && | |
8691 | name[7] == 'o' && | |
8692 | name[8] == 'e' && | |
8693 | name[9] == 'n' && | |
8694 | name[10] == 't') | |
8695 | { /* setprotoent */ | |
8696 | return -KEY_setprotoent; | |
8697 | } | |
8698 | ||
8699 | goto unknown; | |
8700 | ||
8701 | default: | |
8702 | goto unknown; | |
8703 | } | |
8704 | } | |
8705 | ||
8706 | goto unknown; | |
8707 | ||
8708 | default: | |
8709 | goto unknown; | |
e2e1dd5a | 8710 | } |
4c3bbe0f MHM |
8711 | |
8712 | case 12: /* 2 tokens of length 12 */ | |
8713 | if (name[0] == 'g' && | |
8714 | name[1] == 'e' && | |
8715 | name[2] == 't' && | |
8716 | name[3] == 'n' && | |
8717 | name[4] == 'e' && | |
8718 | name[5] == 't' && | |
8719 | name[6] == 'b' && | |
8720 | name[7] == 'y') | |
8721 | { | |
8722 | switch (name[8]) | |
8723 | { | |
8724 | case 'a': | |
8725 | if (name[9] == 'd' && | |
8726 | name[10] == 'd' && | |
8727 | name[11] == 'r') | |
8728 | { /* getnetbyaddr */ | |
8729 | return -KEY_getnetbyaddr; | |
8730 | } | |
8731 | ||
8732 | goto unknown; | |
8733 | ||
8734 | case 'n': | |
8735 | if (name[9] == 'a' && | |
8736 | name[10] == 'm' && | |
8737 | name[11] == 'e') | |
8738 | { /* getnetbyname */ | |
8739 | return -KEY_getnetbyname; | |
8740 | } | |
8741 | ||
8742 | goto unknown; | |
8743 | ||
8744 | default: | |
8745 | goto unknown; | |
8746 | } | |
e2e1dd5a | 8747 | } |
4c3bbe0f MHM |
8748 | |
8749 | goto unknown; | |
8750 | ||
8751 | case 13: /* 4 tokens of length 13 */ | |
8752 | if (name[0] == 'g' && | |
8753 | name[1] == 'e' && | |
8754 | name[2] == 't') | |
8755 | { | |
8756 | switch (name[3]) | |
8757 | { | |
8758 | case 'h': | |
8759 | if (name[4] == 'o' && | |
8760 | name[5] == 's' && | |
8761 | name[6] == 't' && | |
8762 | name[7] == 'b' && | |
8763 | name[8] == 'y') | |
8764 | { | |
8765 | switch (name[9]) | |
8766 | { | |
8767 | case 'a': | |
8768 | if (name[10] == 'd' && | |
8769 | name[11] == 'd' && | |
8770 | name[12] == 'r') | |
8771 | { /* gethostbyaddr */ | |
8772 | return -KEY_gethostbyaddr; | |
8773 | } | |
8774 | ||
8775 | goto unknown; | |
8776 | ||
8777 | case 'n': | |
8778 | if (name[10] == 'a' && | |
8779 | name[11] == 'm' && | |
8780 | name[12] == 'e') | |
8781 | { /* gethostbyname */ | |
8782 | return -KEY_gethostbyname; | |
8783 | } | |
8784 | ||
8785 | goto unknown; | |
8786 | ||
8787 | default: | |
8788 | goto unknown; | |
8789 | } | |
8790 | } | |
8791 | ||
8792 | goto unknown; | |
8793 | ||
8794 | case 's': | |
8795 | if (name[4] == 'e' && | |
8796 | name[5] == 'r' && | |
8797 | name[6] == 'v' && | |
8798 | name[7] == 'b' && | |
8799 | name[8] == 'y') | |
8800 | { | |
8801 | switch (name[9]) | |
8802 | { | |
8803 | case 'n': | |
8804 | if (name[10] == 'a' && | |
8805 | name[11] == 'm' && | |
8806 | name[12] == 'e') | |
8807 | { /* getservbyname */ | |
8808 | return -KEY_getservbyname; | |
8809 | } | |
8810 | ||
8811 | goto unknown; | |
8812 | ||
8813 | case 'p': | |
8814 | if (name[10] == 'o' && | |
8815 | name[11] == 'r' && | |
8816 | name[12] == 't') | |
8817 | { /* getservbyport */ | |
8818 | return -KEY_getservbyport; | |
8819 | } | |
8820 | ||
8821 | goto unknown; | |
8822 | ||
8823 | default: | |
8824 | goto unknown; | |
8825 | } | |
8826 | } | |
8827 | ||
8828 | goto unknown; | |
8829 | ||
8830 | default: | |
8831 | goto unknown; | |
8832 | } | |
e2e1dd5a | 8833 | } |
4c3bbe0f MHM |
8834 | |
8835 | goto unknown; | |
8836 | ||
8837 | case 14: /* 1 tokens of length 14 */ | |
8838 | if (name[0] == 'g' && | |
8839 | name[1] == 'e' && | |
8840 | name[2] == 't' && | |
8841 | name[3] == 'p' && | |
8842 | name[4] == 'r' && | |
8843 | name[5] == 'o' && | |
8844 | name[6] == 't' && | |
8845 | name[7] == 'o' && | |
8846 | name[8] == 'b' && | |
8847 | name[9] == 'y' && | |
8848 | name[10] == 'n' && | |
8849 | name[11] == 'a' && | |
8850 | name[12] == 'm' && | |
8851 | name[13] == 'e') | |
8852 | { /* getprotobyname */ | |
8853 | return -KEY_getprotobyname; | |
8854 | } | |
8855 | ||
8856 | goto unknown; | |
8857 | ||
8858 | case 16: /* 1 tokens of length 16 */ | |
8859 | if (name[0] == 'g' && | |
8860 | name[1] == 'e' && | |
8861 | name[2] == 't' && | |
8862 | name[3] == 'p' && | |
8863 | name[4] == 'r' && | |
8864 | name[5] == 'o' && | |
8865 | name[6] == 't' && | |
8866 | name[7] == 'o' && | |
8867 | name[8] == 'b' && | |
8868 | name[9] == 'y' && | |
8869 | name[10] == 'n' && | |
8870 | name[11] == 'u' && | |
8871 | name[12] == 'm' && | |
8872 | name[13] == 'b' && | |
8873 | name[14] == 'e' && | |
8874 | name[15] == 'r') | |
8875 | { /* getprotobynumber */ | |
8876 | return -KEY_getprotobynumber; | |
8877 | } | |
8878 | ||
8879 | goto unknown; | |
8880 | ||
8881 | default: | |
8882 | goto unknown; | |
e2e1dd5a | 8883 | } |
4c3bbe0f MHM |
8884 | |
8885 | unknown: | |
e2e1dd5a | 8886 | return 0; |
a687059c LW |
8887 | } |
8888 | ||
76e3520e | 8889 | STATIC void |
bfed75c6 | 8890 | S_checkcomma(pTHX_ register char *s, char *name, const char *what) |
a687059c | 8891 | { |
2f3197b3 LW |
8892 | char *w; |
8893 | ||
d008e5eb | 8894 | if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */ |
d008e5eb GS |
8895 | if (ckWARN(WARN_SYNTAX)) { |
8896 | int level = 1; | |
8897 | for (w = s+2; *w && level; w++) { | |
8898 | if (*w == '(') | |
8899 | ++level; | |
8900 | else if (*w == ')') | |
8901 | --level; | |
8902 | } | |
8903 | if (*w) | |
8904 | for (; *w && isSPACE(*w); w++) ; | |
8905 | if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */ | |
9014280d | 8906 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
65cec589 | 8907 | "%s (...) interpreted as function",name); |
d008e5eb | 8908 | } |
2f3197b3 | 8909 | } |
3280af22 | 8910 | while (s < PL_bufend && isSPACE(*s)) |
2f3197b3 | 8911 | s++; |
a687059c LW |
8912 | if (*s == '(') |
8913 | s++; | |
3280af22 | 8914 | while (s < PL_bufend && isSPACE(*s)) |
a687059c | 8915 | s++; |
7e2040f0 | 8916 | if (isIDFIRST_lazy_if(s,UTF)) { |
2f3197b3 | 8917 | w = s++; |
7e2040f0 | 8918 | while (isALNUM_lazy_if(s,UTF)) |
a687059c | 8919 | s++; |
3280af22 | 8920 | while (s < PL_bufend && isSPACE(*s)) |
a687059c | 8921 | s++; |
e929a76b | 8922 | if (*s == ',') { |
463ee0b2 | 8923 | int kw; |
e929a76b | 8924 | *s = '\0'; |
864dbfa3 | 8925 | kw = keyword(w, s - w) || get_cv(w, FALSE) != 0; |
e929a76b | 8926 | *s = ','; |
463ee0b2 | 8927 | if (kw) |
e929a76b | 8928 | return; |
cea2e8a9 | 8929 | Perl_croak(aTHX_ "No comma allowed after %s", what); |
463ee0b2 LW |
8930 | } |
8931 | } | |
8932 | } | |
8933 | ||
423cee85 JH |
8934 | /* Either returns sv, or mortalizes sv and returns a new SV*. |
8935 | Best used as sv=new_constant(..., sv, ...). | |
8936 | If s, pv are NULL, calls subroutine with one argument, | |
8937 | and type is used with error messages only. */ | |
8938 | ||
b3ac6de7 | 8939 | STATIC SV * |
7fc63493 | 8940 | S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv, |
9b0e499b | 8941 | const char *type) |
b3ac6de7 | 8942 | { |
b3ac6de7 | 8943 | dSP; |
3280af22 | 8944 | HV *table = GvHV(PL_hintgv); /* ^H */ |
b3ac6de7 | 8945 | SV *res; |
b3ac6de7 IZ |
8946 | SV **cvp; |
8947 | SV *cv, *typesv; | |
f0af216f | 8948 | const char *why1, *why2, *why3; |
4e553d73 | 8949 | |
f0af216f | 8950 | if (!table || !(PL_hints & HINT_LOCALIZE_HH)) { |
423cee85 JH |
8951 | SV *msg; |
8952 | ||
f0af216f | 8953 | why2 = strEQ(key,"charnames") |
41ab332f | 8954 | ? "(possibly a missing \"use charnames ...\")" |
f0af216f | 8955 | : ""; |
4e553d73 | 8956 | msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s", |
41ab332f JH |
8957 | (type ? type: "undef"), why2); |
8958 | ||
8959 | /* This is convoluted and evil ("goto considered harmful") | |
8960 | * but I do not understand the intricacies of all the different | |
8961 | * failure modes of %^H in here. The goal here is to make | |
8962 | * the most probable error message user-friendly. --jhi */ | |
8963 | ||
8964 | goto msgdone; | |
8965 | ||
423cee85 | 8966 | report: |
4e553d73 | 8967 | msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s", |
f0af216f | 8968 | (type ? type: "undef"), why1, why2, why3); |
41ab332f | 8969 | msgdone: |
423cee85 JH |
8970 | yyerror(SvPVX(msg)); |
8971 | SvREFCNT_dec(msg); | |
8972 | return sv; | |
8973 | } | |
b3ac6de7 IZ |
8974 | cvp = hv_fetch(table, key, strlen(key), FALSE); |
8975 | if (!cvp || !SvOK(*cvp)) { | |
423cee85 JH |
8976 | why1 = "$^H{"; |
8977 | why2 = key; | |
f0af216f | 8978 | why3 = "} is not defined"; |
423cee85 | 8979 | goto report; |
b3ac6de7 IZ |
8980 | } |
8981 | sv_2mortal(sv); /* Parent created it permanently */ | |
8982 | cv = *cvp; | |
423cee85 JH |
8983 | if (!pv && s) |
8984 | pv = sv_2mortal(newSVpvn(s, len)); | |
8985 | if (type && pv) | |
8986 | typesv = sv_2mortal(newSVpv(type, 0)); | |
b3ac6de7 | 8987 | else |
423cee85 | 8988 | typesv = &PL_sv_undef; |
4e553d73 | 8989 | |
e788e7d3 | 8990 | PUSHSTACKi(PERLSI_OVERLOAD); |
423cee85 JH |
8991 | ENTER ; |
8992 | SAVETMPS; | |
4e553d73 | 8993 | |
423cee85 | 8994 | PUSHMARK(SP) ; |
a5845cb7 | 8995 | EXTEND(sp, 3); |
423cee85 JH |
8996 | if (pv) |
8997 | PUSHs(pv); | |
b3ac6de7 | 8998 | PUSHs(sv); |
423cee85 JH |
8999 | if (pv) |
9000 | PUSHs(typesv); | |
b3ac6de7 | 9001 | PUTBACK; |
423cee85 | 9002 | call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL)); |
4e553d73 | 9003 | |
423cee85 | 9004 | SPAGAIN ; |
4e553d73 | 9005 | |
423cee85 | 9006 | /* Check the eval first */ |
9b0e499b | 9007 | if (!PL_in_eval && SvTRUE(ERRSV)) { |
423cee85 JH |
9008 | STRLEN n_a; |
9009 | sv_catpv(ERRSV, "Propagated"); | |
9010 | yyerror(SvPV(ERRSV, n_a)); /* Duplicates the message inside eval */ | |
e1f15930 | 9011 | (void)POPs; |
423cee85 JH |
9012 | res = SvREFCNT_inc(sv); |
9013 | } | |
9014 | else { | |
9015 | res = POPs; | |
e1f15930 | 9016 | (void)SvREFCNT_inc(res); |
423cee85 | 9017 | } |
4e553d73 | 9018 | |
423cee85 JH |
9019 | PUTBACK ; |
9020 | FREETMPS ; | |
9021 | LEAVE ; | |
b3ac6de7 | 9022 | POPSTACK; |
4e553d73 | 9023 | |
b3ac6de7 | 9024 | if (!SvOK(res)) { |
423cee85 JH |
9025 | why1 = "Call to &{$^H{"; |
9026 | why2 = key; | |
f0af216f | 9027 | why3 = "}} did not return a defined value"; |
423cee85 JH |
9028 | sv = res; |
9029 | goto report; | |
9b0e499b | 9030 | } |
423cee85 | 9031 | |
9b0e499b | 9032 | return res; |
b3ac6de7 | 9033 | } |
4e553d73 | 9034 | |
d0a148a6 NC |
9035 | /* Returns a NUL terminated string, with the length of the string written to |
9036 | *slp | |
9037 | */ | |
76e3520e | 9038 | STATIC char * |
cea2e8a9 | 9039 | S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp) |
463ee0b2 LW |
9040 | { |
9041 | register char *d = dest; | |
8903cb82 | 9042 | register char *e = d + destlen - 3; /* two-character token, ending NUL */ |
463ee0b2 | 9043 | for (;;) { |
8903cb82 | 9044 | if (d >= e) |
cea2e8a9 | 9045 | Perl_croak(aTHX_ ident_too_long); |
834a4ddd | 9046 | if (isALNUM(*s)) /* UTF handled below */ |
463ee0b2 | 9047 | *d++ = *s++; |
7e2040f0 | 9048 | else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) { |
463ee0b2 LW |
9049 | *d++ = ':'; |
9050 | *d++ = ':'; | |
9051 | s++; | |
9052 | } | |
c3e0f903 | 9053 | else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') { |
463ee0b2 LW |
9054 | *d++ = *s++; |
9055 | *d++ = *s++; | |
9056 | } | |
fd400ab9 | 9057 | else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
a0ed51b3 | 9058 | char *t = s + UTF8SKIP(s); |
fd400ab9 | 9059 | while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
a0ed51b3 LW |
9060 | t += UTF8SKIP(t); |
9061 | if (d + (t - s) > e) | |
cea2e8a9 | 9062 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 LW |
9063 | Copy(s, d, t - s, char); |
9064 | d += t - s; | |
9065 | s = t; | |
9066 | } | |
463ee0b2 LW |
9067 | else { |
9068 | *d = '\0'; | |
9069 | *slp = d - dest; | |
9070 | return s; | |
e929a76b | 9071 | } |
378cc40b LW |
9072 | } |
9073 | } | |
9074 | ||
76e3520e | 9075 | STATIC char * |
cea2e8a9 | 9076 | S_scan_ident(pTHX_ register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni) |
378cc40b LW |
9077 | { |
9078 | register char *d; | |
8903cb82 | 9079 | register char *e; |
79072805 | 9080 | char *bracket = 0; |
748a9306 | 9081 | char funny = *s++; |
378cc40b | 9082 | |
a0d0e21e LW |
9083 | if (isSPACE(*s)) |
9084 | s = skipspace(s); | |
378cc40b | 9085 | d = dest; |
8903cb82 | 9086 | e = d + destlen - 3; /* two-character token, ending NUL */ |
de3bb511 | 9087 | if (isDIGIT(*s)) { |
8903cb82 | 9088 | while (isDIGIT(*s)) { |
9089 | if (d >= e) | |
cea2e8a9 | 9090 | Perl_croak(aTHX_ ident_too_long); |
378cc40b | 9091 | *d++ = *s++; |
8903cb82 | 9092 | } |
378cc40b LW |
9093 | } |
9094 | else { | |
463ee0b2 | 9095 | for (;;) { |
8903cb82 | 9096 | if (d >= e) |
cea2e8a9 | 9097 | Perl_croak(aTHX_ ident_too_long); |
834a4ddd | 9098 | if (isALNUM(*s)) /* UTF handled below */ |
463ee0b2 | 9099 | *d++ = *s++; |
7e2040f0 | 9100 | else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) { |
463ee0b2 LW |
9101 | *d++ = ':'; |
9102 | *d++ = ':'; | |
9103 | s++; | |
9104 | } | |
a0d0e21e | 9105 | else if (*s == ':' && s[1] == ':') { |
463ee0b2 LW |
9106 | *d++ = *s++; |
9107 | *d++ = *s++; | |
9108 | } | |
fd400ab9 | 9109 | else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
a0ed51b3 | 9110 | char *t = s + UTF8SKIP(s); |
fd400ab9 | 9111 | while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
a0ed51b3 LW |
9112 | t += UTF8SKIP(t); |
9113 | if (d + (t - s) > e) | |
cea2e8a9 | 9114 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 LW |
9115 | Copy(s, d, t - s, char); |
9116 | d += t - s; | |
9117 | s = t; | |
9118 | } | |
463ee0b2 LW |
9119 | else |
9120 | break; | |
9121 | } | |
378cc40b LW |
9122 | } |
9123 | *d = '\0'; | |
9124 | d = dest; | |
79072805 | 9125 | if (*d) { |
3280af22 NIS |
9126 | if (PL_lex_state != LEX_NORMAL) |
9127 | PL_lex_state = LEX_INTERPENDMAYBE; | |
79072805 | 9128 | return s; |
378cc40b | 9129 | } |
748a9306 | 9130 | if (*s == '$' && s[1] && |
3792a11b | 9131 | (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) ) |
5cd24f17 | 9132 | { |
4810e5ec | 9133 | return s; |
5cd24f17 | 9134 | } |
79072805 LW |
9135 | if (*s == '{') { |
9136 | bracket = s; | |
9137 | s++; | |
9138 | } | |
9139 | else if (ck_uni) | |
9140 | check_uni(); | |
93a17b20 | 9141 | if (s < send) |
79072805 LW |
9142 | *d = *s++; |
9143 | d[1] = '\0'; | |
2b92dfce | 9144 | if (*d == '^' && *s && isCONTROLVAR(*s)) { |
bbce6d69 | 9145 | *d = toCTRL(*s); |
9146 | s++; | |
de3bb511 | 9147 | } |
79072805 | 9148 | if (bracket) { |
748a9306 | 9149 | if (isSPACE(s[-1])) { |
fa83b5b6 | 9150 | while (s < send) { |
9151 | char ch = *s++; | |
bf4acbe4 | 9152 | if (!SPACE_OR_TAB(ch)) { |
fa83b5b6 | 9153 | *d = ch; |
9154 | break; | |
9155 | } | |
9156 | } | |
748a9306 | 9157 | } |
7e2040f0 | 9158 | if (isIDFIRST_lazy_if(d,UTF)) { |
79072805 | 9159 | d++; |
a0ed51b3 LW |
9160 | if (UTF) { |
9161 | e = s; | |
155aba94 | 9162 | while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') { |
a0ed51b3 | 9163 | e += UTF8SKIP(e); |
fd400ab9 | 9164 | while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e)) |
a0ed51b3 LW |
9165 | e += UTF8SKIP(e); |
9166 | } | |
9167 | Copy(s, d, e - s, char); | |
9168 | d += e - s; | |
9169 | s = e; | |
9170 | } | |
9171 | else { | |
2b92dfce | 9172 | while ((isALNUM(*s) || *s == ':') && d < e) |
a0ed51b3 | 9173 | *d++ = *s++; |
2b92dfce | 9174 | if (d >= e) |
cea2e8a9 | 9175 | Perl_croak(aTHX_ ident_too_long); |
a0ed51b3 | 9176 | } |
79072805 | 9177 | *d = '\0'; |
bf4acbe4 | 9178 | while (s < send && SPACE_OR_TAB(*s)) s++; |
ff68c719 | 9179 | if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) { |
599cee73 | 9180 | if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) { |
dff6d3cd | 9181 | const char *brack = *s == '[' ? "[...]" : "{...}"; |
9014280d | 9182 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
599cee73 | 9183 | "Ambiguous use of %c{%s%s} resolved to %c%s%s", |
748a9306 LW |
9184 | funny, dest, brack, funny, dest, brack); |
9185 | } | |
79072805 | 9186 | bracket++; |
a0be28da | 9187 | PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK); |
79072805 LW |
9188 | return s; |
9189 | } | |
4e553d73 NIS |
9190 | } |
9191 | /* Handle extended ${^Foo} variables | |
2b92dfce GS |
9192 | * 1999-02-27 mjd-perl-patch@plover.com */ |
9193 | else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */ | |
9194 | && isALNUM(*s)) | |
9195 | { | |
9196 | d++; | |
9197 | while (isALNUM(*s) && d < e) { | |
9198 | *d++ = *s++; | |
9199 | } | |
9200 | if (d >= e) | |
cea2e8a9 | 9201 | Perl_croak(aTHX_ ident_too_long); |
2b92dfce | 9202 | *d = '\0'; |
79072805 LW |
9203 | } |
9204 | if (*s == '}') { | |
9205 | s++; | |
7df0d042 | 9206 | if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) { |
3280af22 | 9207 | PL_lex_state = LEX_INTERPEND; |
7df0d042 AE |
9208 | PL_expect = XREF; |
9209 | } | |
748a9306 LW |
9210 | if (funny == '#') |
9211 | funny = '@'; | |
d008e5eb | 9212 | if (PL_lex_state == LEX_NORMAL) { |
d008e5eb | 9213 | if (ckWARN(WARN_AMBIGUOUS) && |
864dbfa3 | 9214 | (keyword(dest, d - dest) || get_cv(dest, FALSE))) |
d008e5eb | 9215 | { |
9014280d | 9216 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
d008e5eb GS |
9217 | "Ambiguous use of %c{%s} resolved to %c%s", |
9218 | funny, dest, funny, dest); | |
9219 | } | |
9220 | } | |
79072805 LW |
9221 | } |
9222 | else { | |
9223 | s = bracket; /* let the parser handle it */ | |
93a17b20 | 9224 | *dest = '\0'; |
79072805 LW |
9225 | } |
9226 | } | |
3280af22 NIS |
9227 | else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s)) |
9228 | PL_lex_state = LEX_INTERPEND; | |
378cc40b LW |
9229 | return s; |
9230 | } | |
9231 | ||
cea2e8a9 | 9232 | void |
2b36a5a0 | 9233 | Perl_pmflag(pTHX_ U32* pmfl, int ch) |
a0d0e21e | 9234 | { |
bbce6d69 | 9235 | if (ch == 'i') |
a0d0e21e | 9236 | *pmfl |= PMf_FOLD; |
a0d0e21e LW |
9237 | else if (ch == 'g') |
9238 | *pmfl |= PMf_GLOBAL; | |
c90c0ff4 | 9239 | else if (ch == 'c') |
9240 | *pmfl |= PMf_CONTINUE; | |
a0d0e21e LW |
9241 | else if (ch == 'o') |
9242 | *pmfl |= PMf_KEEP; | |
9243 | else if (ch == 'm') | |
9244 | *pmfl |= PMf_MULTILINE; | |
9245 | else if (ch == 's') | |
9246 | *pmfl |= PMf_SINGLELINE; | |
9247 | else if (ch == 'x') | |
9248 | *pmfl |= PMf_EXTENDED; | |
9249 | } | |
378cc40b | 9250 | |
76e3520e | 9251 | STATIC char * |
cea2e8a9 | 9252 | S_scan_pat(pTHX_ char *start, I32 type) |
378cc40b | 9253 | { |
79072805 LW |
9254 | PMOP *pm; |
9255 | char *s; | |
378cc40b | 9256 | |
09bef843 | 9257 | s = scan_str(start,FALSE,FALSE); |
37fd879b | 9258 | if (!s) |
cea2e8a9 | 9259 | Perl_croak(aTHX_ "Search pattern not terminated"); |
bbce6d69 | 9260 | |
8782bef2 | 9261 | pm = (PMOP*)newPMOP(type, 0); |
3280af22 | 9262 | if (PL_multi_open == '?') |
79072805 | 9263 | pm->op_pmflags |= PMf_ONCE; |
8782bef2 GB |
9264 | if(type == OP_QR) { |
9265 | while (*s && strchr("iomsx", *s)) | |
9266 | pmflag(&pm->op_pmflags,*s++); | |
9267 | } | |
9268 | else { | |
9269 | while (*s && strchr("iogcmsx", *s)) | |
9270 | pmflag(&pm->op_pmflags,*s++); | |
9271 | } | |
4ac733c9 | 9272 | /* issue a warning if /c is specified,but /g is not */ |
bfed75c6 | 9273 | if (ckWARN(WARN_REGEXP) && |
4ac733c9 MJD |
9274 | (pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)) |
9275 | { | |
9276 | Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_without_g); | |
9277 | } | |
9278 | ||
4633a7c4 | 9279 | pm->op_pmpermflags = pm->op_pmflags; |
bbce6d69 | 9280 | |
3280af22 | 9281 | PL_lex_op = (OP*)pm; |
79072805 | 9282 | yylval.ival = OP_MATCH; |
378cc40b LW |
9283 | return s; |
9284 | } | |
9285 | ||
76e3520e | 9286 | STATIC char * |
cea2e8a9 | 9287 | S_scan_subst(pTHX_ char *start) |
79072805 | 9288 | { |
a0d0e21e | 9289 | register char *s; |
79072805 | 9290 | register PMOP *pm; |
4fdae800 | 9291 | I32 first_start; |
79072805 LW |
9292 | I32 es = 0; |
9293 | ||
79072805 LW |
9294 | yylval.ival = OP_NULL; |
9295 | ||
09bef843 | 9296 | s = scan_str(start,FALSE,FALSE); |
79072805 | 9297 | |
37fd879b | 9298 | if (!s) |
cea2e8a9 | 9299 | Perl_croak(aTHX_ "Substitution pattern not terminated"); |
79072805 | 9300 | |
3280af22 | 9301 | if (s[-1] == PL_multi_open) |
79072805 LW |
9302 | s--; |
9303 | ||
3280af22 | 9304 | first_start = PL_multi_start; |
09bef843 | 9305 | s = scan_str(s,FALSE,FALSE); |
79072805 | 9306 | if (!s) { |
37fd879b | 9307 | if (PL_lex_stuff) { |
3280af22 | 9308 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
9309 | PL_lex_stuff = Nullsv; |
9310 | } | |
cea2e8a9 | 9311 | Perl_croak(aTHX_ "Substitution replacement not terminated"); |
a687059c | 9312 | } |
3280af22 | 9313 | PL_multi_start = first_start; /* so whole substitution is taken together */ |
2f3197b3 | 9314 | |
79072805 | 9315 | pm = (PMOP*)newPMOP(OP_SUBST, 0); |
48c036b1 | 9316 | while (*s) { |
a687059c LW |
9317 | if (*s == 'e') { |
9318 | s++; | |
2f3197b3 | 9319 | es++; |
a687059c | 9320 | } |
b3eb6a9b | 9321 | else if (strchr("iogcmsx", *s)) |
a0d0e21e | 9322 | pmflag(&pm->op_pmflags,*s++); |
48c036b1 GS |
9323 | else |
9324 | break; | |
378cc40b | 9325 | } |
79072805 | 9326 | |
64e578a2 MJD |
9327 | /* /c is not meaningful with s/// */ |
9328 | if (ckWARN(WARN_REGEXP) && (pm->op_pmflags & PMf_CONTINUE)) | |
4ac733c9 | 9329 | { |
64e578a2 | 9330 | Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_in_subst); |
4ac733c9 MJD |
9331 | } |
9332 | ||
79072805 LW |
9333 | if (es) { |
9334 | SV *repl; | |
0244c3a4 GS |
9335 | PL_sublex_info.super_bufptr = s; |
9336 | PL_sublex_info.super_bufend = PL_bufend; | |
9337 | PL_multi_end = 0; | |
79072805 | 9338 | pm->op_pmflags |= PMf_EVAL; |
79cb57f6 | 9339 | repl = newSVpvn("",0); |
463ee0b2 | 9340 | while (es-- > 0) |
a0d0e21e | 9341 | sv_catpv(repl, es ? "eval " : "do "); |
79072805 | 9342 | sv_catpvn(repl, "{ ", 2); |
3280af22 | 9343 | sv_catsv(repl, PL_lex_repl); |
79072805 | 9344 | sv_catpvn(repl, " };", 2); |
25da4f38 | 9345 | SvEVALED_on(repl); |
3280af22 NIS |
9346 | SvREFCNT_dec(PL_lex_repl); |
9347 | PL_lex_repl = repl; | |
378cc40b | 9348 | } |
79072805 | 9349 | |
4633a7c4 | 9350 | pm->op_pmpermflags = pm->op_pmflags; |
3280af22 | 9351 | PL_lex_op = (OP*)pm; |
79072805 | 9352 | yylval.ival = OP_SUBST; |
378cc40b LW |
9353 | return s; |
9354 | } | |
9355 | ||
76e3520e | 9356 | STATIC char * |
cea2e8a9 | 9357 | S_scan_trans(pTHX_ char *start) |
378cc40b | 9358 | { |
a0d0e21e | 9359 | register char* s; |
11343788 | 9360 | OP *o; |
79072805 LW |
9361 | short *tbl; |
9362 | I32 squash; | |
a0ed51b3 | 9363 | I32 del; |
79072805 LW |
9364 | I32 complement; |
9365 | ||
9366 | yylval.ival = OP_NULL; | |
9367 | ||
09bef843 | 9368 | s = scan_str(start,FALSE,FALSE); |
37fd879b | 9369 | if (!s) |
cea2e8a9 | 9370 | Perl_croak(aTHX_ "Transliteration pattern not terminated"); |
3280af22 | 9371 | if (s[-1] == PL_multi_open) |
2f3197b3 LW |
9372 | s--; |
9373 | ||
09bef843 | 9374 | s = scan_str(s,FALSE,FALSE); |
79072805 | 9375 | if (!s) { |
37fd879b | 9376 | if (PL_lex_stuff) { |
3280af22 | 9377 | SvREFCNT_dec(PL_lex_stuff); |
37fd879b HS |
9378 | PL_lex_stuff = Nullsv; |
9379 | } | |
cea2e8a9 | 9380 | Perl_croak(aTHX_ "Transliteration replacement not terminated"); |
a687059c | 9381 | } |
79072805 | 9382 | |
a0ed51b3 | 9383 | complement = del = squash = 0; |
7a1e2023 NC |
9384 | while (1) { |
9385 | switch (*s) { | |
9386 | case 'c': | |
79072805 | 9387 | complement = OPpTRANS_COMPLEMENT; |
7a1e2023 NC |
9388 | break; |
9389 | case 'd': | |
a0ed51b3 | 9390 | del = OPpTRANS_DELETE; |
7a1e2023 NC |
9391 | break; |
9392 | case 's': | |
79072805 | 9393 | squash = OPpTRANS_SQUASH; |
7a1e2023 NC |
9394 | break; |
9395 | default: | |
9396 | goto no_more; | |
9397 | } | |
395c3793 LW |
9398 | s++; |
9399 | } | |
7a1e2023 | 9400 | no_more: |
8973db79 JH |
9401 | |
9402 | New(803, tbl, complement&&!del?258:256, short); | |
9403 | o = newPVOP(OP_TRANS, 0, (char*)tbl); | |
59f00321 RGS |
9404 | o->op_private &= ~OPpTRANS_ALL; |
9405 | o->op_private |= del|squash|complement| | |
7948272d NIS |
9406 | (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)| |
9407 | (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0); | |
79072805 | 9408 | |
3280af22 | 9409 | PL_lex_op = o; |
79072805 LW |
9410 | yylval.ival = OP_TRANS; |
9411 | return s; | |
9412 | } | |
9413 | ||
76e3520e | 9414 | STATIC char * |
cea2e8a9 | 9415 | S_scan_heredoc(pTHX_ register char *s) |
79072805 LW |
9416 | { |
9417 | SV *herewas; | |
9418 | I32 op_type = OP_SCALAR; | |
9419 | I32 len; | |
9420 | SV *tmpstr; | |
9421 | char term; | |
73d840c0 AL |
9422 | const char newline[] = "\n"; |
9423 | const char *found_newline; | |
79072805 | 9424 | register char *d; |
fc36a67e | 9425 | register char *e; |
4633a7c4 | 9426 | char *peek; |
3280af22 | 9427 | int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR)); |
79072805 LW |
9428 | |
9429 | s += 2; | |
3280af22 NIS |
9430 | d = PL_tokenbuf; |
9431 | e = PL_tokenbuf + sizeof PL_tokenbuf - 1; | |
fd2d0953 | 9432 | if (!outer) |
79072805 | 9433 | *d++ = '\n'; |
bf4acbe4 | 9434 | for (peek = s; SPACE_OR_TAB(*peek); peek++) ; |
3792a11b | 9435 | if (*peek == '`' || *peek == '\'' || *peek =='"') { |
4633a7c4 | 9436 | s = peek; |
79072805 | 9437 | term = *s++; |
3280af22 | 9438 | s = delimcpy(d, e, s, PL_bufend, term, &len); |
fc36a67e | 9439 | d += len; |
3280af22 | 9440 | if (s < PL_bufend) |
79072805 | 9441 | s++; |
79072805 LW |
9442 | } |
9443 | else { | |
9444 | if (*s == '\\') | |
9445 | s++, term = '\''; | |
9446 | else | |
9447 | term = '"'; | |
7e2040f0 | 9448 | if (!isALNUM_lazy_if(s,UTF)) |
12bcd1a6 | 9449 | deprecate_old("bare << to mean <<\"\""); |
7e2040f0 | 9450 | for (; isALNUM_lazy_if(s,UTF); s++) { |
fc36a67e | 9451 | if (d < e) |
9452 | *d++ = *s; | |
9453 | } | |
9454 | } | |
3280af22 | 9455 | if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1) |
cea2e8a9 | 9456 | Perl_croak(aTHX_ "Delimiter for here document is too long"); |
79072805 LW |
9457 | *d++ = '\n'; |
9458 | *d = '\0'; | |
3280af22 | 9459 | len = d - PL_tokenbuf; |
6a27c188 | 9460 | #ifndef PERL_STRICT_CR |
f63a84b2 LW |
9461 | d = strchr(s, '\r'); |
9462 | if (d) { | |
9463 | char *olds = s; | |
9464 | s = d; | |
3280af22 | 9465 | while (s < PL_bufend) { |
f63a84b2 LW |
9466 | if (*s == '\r') { |
9467 | *d++ = '\n'; | |
9468 | if (*++s == '\n') | |
9469 | s++; | |
9470 | } | |
9471 | else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */ | |
9472 | *d++ = *s++; | |
9473 | s++; | |
9474 | } | |
9475 | else | |
9476 | *d++ = *s++; | |
9477 | } | |
9478 | *d = '\0'; | |
3280af22 NIS |
9479 | PL_bufend = d; |
9480 | SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr)); | |
f63a84b2 LW |
9481 | s = olds; |
9482 | } | |
9483 | #endif | |
73d840c0 AL |
9484 | if ( outer || !(found_newline = ninstr(s,PL_bufend,newline,newline+1)) ) { |
9485 | herewas = newSVpvn(s,PL_bufend-s); | |
9486 | } | |
9487 | else { | |
9488 | s--; | |
9489 | herewas = newSVpvn(s,found_newline-s); | |
9490 | } | |
79072805 | 9491 | s += SvCUR(herewas); |
748a9306 | 9492 | |
8d6dde3e | 9493 | tmpstr = NEWSV(87,79); |
748a9306 LW |
9494 | sv_upgrade(tmpstr, SVt_PVIV); |
9495 | if (term == '\'') { | |
79072805 | 9496 | op_type = OP_CONST; |
748a9306 LW |
9497 | SvIVX(tmpstr) = -1; |
9498 | } | |
9499 | else if (term == '`') { | |
79072805 | 9500 | op_type = OP_BACKTICK; |
748a9306 LW |
9501 | SvIVX(tmpstr) = '\\'; |
9502 | } | |
79072805 LW |
9503 | |
9504 | CLINE; | |
57843af0 | 9505 | PL_multi_start = CopLINE(PL_curcop); |
3280af22 NIS |
9506 | PL_multi_open = PL_multi_close = '<'; |
9507 | term = *PL_tokenbuf; | |
0244c3a4 GS |
9508 | if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) { |
9509 | char *bufptr = PL_sublex_info.super_bufptr; | |
9510 | char *bufend = PL_sublex_info.super_bufend; | |
9511 | char *olds = s - SvCUR(herewas); | |
9512 | s = strchr(bufptr, '\n'); | |
9513 | if (!s) | |
9514 | s = bufend; | |
9515 | d = s; | |
9516 | while (s < bufend && | |
9517 | (*s != term || memNE(s,PL_tokenbuf,len)) ) { | |
9518 | if (*s++ == '\n') | |
57843af0 | 9519 | CopLINE_inc(PL_curcop); |
0244c3a4 GS |
9520 | } |
9521 | if (s >= bufend) { | |
eb160463 | 9522 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
0244c3a4 GS |
9523 | missingterm(PL_tokenbuf); |
9524 | } | |
9525 | sv_setpvn(herewas,bufptr,d-bufptr+1); | |
9526 | sv_setpvn(tmpstr,d+1,s-d); | |
9527 | s += len - 1; | |
9528 | sv_catpvn(herewas,s,bufend-s); | |
689badd5 | 9529 | Copy(SvPVX(herewas),bufptr,SvCUR(herewas) + 1,char); |
0244c3a4 GS |
9530 | |
9531 | s = olds; | |
9532 | goto retval; | |
9533 | } | |
9534 | else if (!outer) { | |
79072805 | 9535 | d = s; |
3280af22 NIS |
9536 | while (s < PL_bufend && |
9537 | (*s != term || memNE(s,PL_tokenbuf,len)) ) { | |
79072805 | 9538 | if (*s++ == '\n') |
57843af0 | 9539 | CopLINE_inc(PL_curcop); |
79072805 | 9540 | } |
3280af22 | 9541 | if (s >= PL_bufend) { |
eb160463 | 9542 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
3280af22 | 9543 | missingterm(PL_tokenbuf); |
79072805 LW |
9544 | } |
9545 | sv_setpvn(tmpstr,d+1,s-d); | |
9546 | s += len - 1; | |
57843af0 | 9547 | CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */ |
49d8d3a1 | 9548 | |
3280af22 NIS |
9549 | sv_catpvn(herewas,s,PL_bufend-s); |
9550 | sv_setsv(PL_linestr,herewas); | |
9551 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr); | |
9552 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 9553 | PL_last_lop = PL_last_uni = Nullch; |
79072805 LW |
9554 | } |
9555 | else | |
9556 | sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */ | |
3280af22 | 9557 | while (s >= PL_bufend) { /* multiple line string? */ |
fd2d0953 | 9558 | if (!outer || |
3280af22 | 9559 | !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { |
eb160463 | 9560 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
3280af22 | 9561 | missingterm(PL_tokenbuf); |
79072805 | 9562 | } |
57843af0 | 9563 | CopLINE_inc(PL_curcop); |
3280af22 | 9564 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
207e3d1a | 9565 | PL_last_lop = PL_last_uni = Nullch; |
6a27c188 | 9566 | #ifndef PERL_STRICT_CR |
3280af22 | 9567 | if (PL_bufend - PL_linestart >= 2) { |
a1529941 NIS |
9568 | if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') || |
9569 | (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r')) | |
c6f14548 | 9570 | { |
3280af22 NIS |
9571 | PL_bufend[-2] = '\n'; |
9572 | PL_bufend--; | |
9573 | SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr)); | |
f63a84b2 | 9574 | } |
3280af22 NIS |
9575 | else if (PL_bufend[-1] == '\r') |
9576 | PL_bufend[-1] = '\n'; | |
f63a84b2 | 9577 | } |
3280af22 NIS |
9578 | else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r') |
9579 | PL_bufend[-1] = '\n'; | |
f63a84b2 | 9580 | #endif |
3280af22 | 9581 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
79072805 LW |
9582 | SV *sv = NEWSV(88,0); |
9583 | ||
93a17b20 | 9584 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 9585 | sv_setsv(sv,PL_linestr); |
0ac0412a MJD |
9586 | (void)SvIOK_on(sv); |
9587 | SvIVX(sv) = 0; | |
57843af0 | 9588 | av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv); |
79072805 | 9589 | } |
3280af22 | 9590 | if (*s == term && memEQ(s,PL_tokenbuf,len)) { |
1de9afcd RGS |
9591 | STRLEN off = PL_bufend - 1 - SvPVX(PL_linestr); |
9592 | *(SvPVX(PL_linestr) + off ) = ' '; | |
3280af22 NIS |
9593 | sv_catsv(PL_linestr,herewas); |
9594 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
1de9afcd | 9595 | s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */ |
79072805 LW |
9596 | } |
9597 | else { | |
3280af22 NIS |
9598 | s = PL_bufend; |
9599 | sv_catsv(tmpstr,PL_linestr); | |
395c3793 LW |
9600 | } |
9601 | } | |
79072805 | 9602 | s++; |
0244c3a4 | 9603 | retval: |
57843af0 | 9604 | PL_multi_end = CopLINE(PL_curcop); |
79072805 LW |
9605 | if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) { |
9606 | SvLEN_set(tmpstr, SvCUR(tmpstr) + 1); | |
463ee0b2 | 9607 | Renew(SvPVX(tmpstr), SvLEN(tmpstr), char); |
79072805 | 9608 | } |
8990e307 | 9609 | SvREFCNT_dec(herewas); |
2f31ce75 JH |
9610 | if (!IN_BYTES) { |
9611 | if (UTF && is_utf8_string((U8*)SvPVX(tmpstr), SvCUR(tmpstr))) | |
9612 | SvUTF8_on(tmpstr); | |
9613 | else if (PL_encoding) | |
9614 | sv_recode_to_utf8(tmpstr, PL_encoding); | |
9615 | } | |
3280af22 | 9616 | PL_lex_stuff = tmpstr; |
79072805 LW |
9617 | yylval.ival = op_type; |
9618 | return s; | |
9619 | } | |
9620 | ||
02aa26ce NT |
9621 | /* scan_inputsymbol |
9622 | takes: current position in input buffer | |
9623 | returns: new position in input buffer | |
9624 | side-effects: yylval and lex_op are set. | |
9625 | ||
9626 | This code handles: | |
9627 | ||
9628 | <> read from ARGV | |
9629 | <FH> read from filehandle | |
9630 | <pkg::FH> read from package qualified filehandle | |
9631 | <pkg'FH> read from package qualified filehandle | |
9632 | <$fh> read from filehandle in $fh | |
9633 | <*.h> filename glob | |
9634 | ||
9635 | */ | |
9636 | ||
76e3520e | 9637 | STATIC char * |
cea2e8a9 | 9638 | S_scan_inputsymbol(pTHX_ char *start) |
79072805 | 9639 | { |
02aa26ce | 9640 | register char *s = start; /* current position in buffer */ |
79072805 | 9641 | register char *d; |
fc36a67e | 9642 | register char *e; |
1b420867 | 9643 | char *end; |
79072805 LW |
9644 | I32 len; |
9645 | ||
3280af22 NIS |
9646 | d = PL_tokenbuf; /* start of temp holding space */ |
9647 | e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */ | |
1b420867 GS |
9648 | end = strchr(s, '\n'); |
9649 | if (!end) | |
9650 | end = PL_bufend; | |
9651 | s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */ | |
02aa26ce NT |
9652 | |
9653 | /* die if we didn't have space for the contents of the <>, | |
1b420867 | 9654 | or if it didn't end, or if we see a newline |
02aa26ce NT |
9655 | */ |
9656 | ||
3280af22 | 9657 | if (len >= sizeof PL_tokenbuf) |
cea2e8a9 | 9658 | Perl_croak(aTHX_ "Excessively long <> operator"); |
1b420867 | 9659 | if (s >= end) |
cea2e8a9 | 9660 | Perl_croak(aTHX_ "Unterminated <> operator"); |
02aa26ce | 9661 | |
fc36a67e | 9662 | s++; |
02aa26ce NT |
9663 | |
9664 | /* check for <$fh> | |
9665 | Remember, only scalar variables are interpreted as filehandles by | |
9666 | this code. Anything more complex (e.g., <$fh{$num}>) will be | |
9667 | treated as a glob() call. | |
9668 | This code makes use of the fact that except for the $ at the front, | |
9669 | a scalar variable and a filehandle look the same. | |
9670 | */ | |
4633a7c4 | 9671 | if (*d == '$' && d[1]) d++; |
02aa26ce NT |
9672 | |
9673 | /* allow <Pkg'VALUE> or <Pkg::VALUE> */ | |
7e2040f0 | 9674 | while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':')) |
79072805 | 9675 | d++; |
02aa26ce NT |
9676 | |
9677 | /* If we've tried to read what we allow filehandles to look like, and | |
9678 | there's still text left, then it must be a glob() and not a getline. | |
9679 | Use scan_str to pull out the stuff between the <> and treat it | |
9680 | as nothing more than a string. | |
9681 | */ | |
9682 | ||
3280af22 | 9683 | if (d - PL_tokenbuf != len) { |
79072805 LW |
9684 | yylval.ival = OP_GLOB; |
9685 | set_csh(); | |
09bef843 | 9686 | s = scan_str(start,FALSE,FALSE); |
79072805 | 9687 | if (!s) |
cea2e8a9 | 9688 | Perl_croak(aTHX_ "Glob not terminated"); |
79072805 LW |
9689 | return s; |
9690 | } | |
395c3793 | 9691 | else { |
9b3023bc RGS |
9692 | bool readline_overriden = FALSE; |
9693 | GV *gv_readline = Nullgv; | |
9694 | GV **gvp; | |
02aa26ce | 9695 | /* we're in a filehandle read situation */ |
3280af22 | 9696 | d = PL_tokenbuf; |
02aa26ce NT |
9697 | |
9698 | /* turn <> into <ARGV> */ | |
79072805 | 9699 | if (!len) |
689badd5 | 9700 | Copy("ARGV",d,5,char); |
02aa26ce | 9701 | |
9b3023bc | 9702 | /* Check whether readline() is overriden */ |
ba979b31 NIS |
9703 | if (((gv_readline = gv_fetchpv("readline", FALSE, SVt_PVCV)) |
9704 | && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)) | |
9b3023bc | 9705 | || |
ba979b31 | 9706 | ((gvp = (GV**)hv_fetch(PL_globalstash, "readline", 8, FALSE)) |
9b3023bc | 9707 | && (gv_readline = *gvp) != (GV*)&PL_sv_undef |
ba979b31 | 9708 | && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))) |
9b3023bc RGS |
9709 | readline_overriden = TRUE; |
9710 | ||
02aa26ce NT |
9711 | /* if <$fh>, create the ops to turn the variable into a |
9712 | filehandle | |
9713 | */ | |
79072805 | 9714 | if (*d == '$') { |
a0d0e21e | 9715 | I32 tmp; |
02aa26ce NT |
9716 | |
9717 | /* try to find it in the pad for this block, otherwise find | |
9718 | add symbol table ops | |
9719 | */ | |
11343788 | 9720 | if ((tmp = pad_findmy(d)) != NOT_IN_PAD) { |
dd2155a4 DM |
9721 | if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) { |
9722 | SV *sym = sv_2mortal( | |
9723 | newSVpv(HvNAME(PAD_COMPNAME_OURSTASH(tmp)),0)); | |
f558d5af JH |
9724 | sv_catpvn(sym, "::", 2); |
9725 | sv_catpv(sym, d+1); | |
9726 | d = SvPVX(sym); | |
9727 | goto intro_sym; | |
9728 | } | |
9729 | else { | |
9730 | OP *o = newOP(OP_PADSV, 0); | |
9731 | o->op_targ = tmp; | |
9b3023bc RGS |
9732 | PL_lex_op = readline_overriden |
9733 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, | |
9734 | append_elem(OP_LIST, o, | |
9735 | newCVREF(0, newGVOP(OP_GV,0,gv_readline)))) | |
9736 | : (OP*)newUNOP(OP_READLINE, 0, o); | |
f558d5af | 9737 | } |
a0d0e21e LW |
9738 | } |
9739 | else { | |
f558d5af JH |
9740 | GV *gv; |
9741 | ++d; | |
9742 | intro_sym: | |
9743 | gv = gv_fetchpv(d, | |
9744 | (PL_in_eval | |
9745 | ? (GV_ADDMULTI | GV_ADDINEVAL) | |
bea70d1e | 9746 | : GV_ADDMULTI), |
f558d5af | 9747 | SVt_PV); |
9b3023bc RGS |
9748 | PL_lex_op = readline_overriden |
9749 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, | |
9750 | append_elem(OP_LIST, | |
9751 | newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)), | |
9752 | newCVREF(0, newGVOP(OP_GV, 0, gv_readline)))) | |
9753 | : (OP*)newUNOP(OP_READLINE, 0, | |
9754 | newUNOP(OP_RV2SV, 0, | |
9755 | newGVOP(OP_GV, 0, gv))); | |
a0d0e21e | 9756 | } |
7c6fadd6 RGS |
9757 | if (!readline_overriden) |
9758 | PL_lex_op->op_flags |= OPf_SPECIAL; | |
f5284f61 | 9759 | /* we created the ops in PL_lex_op, so make yylval.ival a null op */ |
79072805 LW |
9760 | yylval.ival = OP_NULL; |
9761 | } | |
02aa26ce NT |
9762 | |
9763 | /* If it's none of the above, it must be a literal filehandle | |
9764 | (<Foo::BAR> or <FOO>) so build a simple readline OP */ | |
79072805 | 9765 | else { |
85e6fe83 | 9766 | GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO); |
9b3023bc RGS |
9767 | PL_lex_op = readline_overriden |
9768 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, | |
9769 | append_elem(OP_LIST, | |
9770 | newGVOP(OP_GV, 0, gv), | |
9771 | newCVREF(0, newGVOP(OP_GV, 0, gv_readline)))) | |
9772 | : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv)); | |
79072805 LW |
9773 | yylval.ival = OP_NULL; |
9774 | } | |
9775 | } | |
02aa26ce | 9776 | |
79072805 LW |
9777 | return s; |
9778 | } | |
9779 | ||
02aa26ce NT |
9780 | |
9781 | /* scan_str | |
9782 | takes: start position in buffer | |
09bef843 SB |
9783 | keep_quoted preserve \ on the embedded delimiter(s) |
9784 | keep_delims preserve the delimiters around the string | |
02aa26ce NT |
9785 | returns: position to continue reading from buffer |
9786 | side-effects: multi_start, multi_close, lex_repl or lex_stuff, and | |
9787 | updates the read buffer. | |
9788 | ||
9789 | This subroutine pulls a string out of the input. It is called for: | |
9790 | q single quotes q(literal text) | |
9791 | ' single quotes 'literal text' | |
9792 | qq double quotes qq(interpolate $here please) | |
9793 | " double quotes "interpolate $here please" | |
9794 | qx backticks qx(/bin/ls -l) | |
9795 | ` backticks `/bin/ls -l` | |
9796 | qw quote words @EXPORT_OK = qw( func() $spam ) | |
9797 | m// regexp match m/this/ | |
9798 | s/// regexp substitute s/this/that/ | |
9799 | tr/// string transliterate tr/this/that/ | |
9800 | y/// string transliterate y/this/that/ | |
9801 | ($*@) sub prototypes sub foo ($) | |
09bef843 | 9802 | (stuff) sub attr parameters sub foo : attr(stuff) |
02aa26ce NT |
9803 | <> readline or globs <FOO>, <>, <$fh>, or <*.c> |
9804 | ||
9805 | In most of these cases (all but <>, patterns and transliterate) | |
9806 | yylex() calls scan_str(). m// makes yylex() call scan_pat() which | |
9807 | calls scan_str(). s/// makes yylex() call scan_subst() which calls | |
9808 | scan_str(). tr/// and y/// make yylex() call scan_trans() which | |
9809 | calls scan_str(). | |
4e553d73 | 9810 | |
02aa26ce NT |
9811 | It skips whitespace before the string starts, and treats the first |
9812 | character as the delimiter. If the delimiter is one of ([{< then | |
9813 | the corresponding "close" character )]}> is used as the closing | |
9814 | delimiter. It allows quoting of delimiters, and if the string has | |
9815 | balanced delimiters ([{<>}]) it allows nesting. | |
9816 | ||
37fd879b HS |
9817 | On success, the SV with the resulting string is put into lex_stuff or, |
9818 | if that is already non-NULL, into lex_repl. The second case occurs only | |
9819 | when parsing the RHS of the special constructs s/// and tr/// (y///). | |
9820 | For convenience, the terminating delimiter character is stuffed into | |
9821 | SvIVX of the SV. | |
02aa26ce NT |
9822 | */ |
9823 | ||
76e3520e | 9824 | STATIC char * |
09bef843 | 9825 | S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims) |
79072805 | 9826 | { |
02aa26ce NT |
9827 | SV *sv; /* scalar value: string */ |
9828 | char *tmps; /* temp string, used for delimiter matching */ | |
9829 | register char *s = start; /* current position in the buffer */ | |
9830 | register char term; /* terminating character */ | |
9831 | register char *to; /* current position in the sv's data */ | |
9832 | I32 brackets = 1; /* bracket nesting level */ | |
89491803 | 9833 | bool has_utf8 = FALSE; /* is there any utf8 content? */ |
220e2d4e | 9834 | I32 termcode; /* terminating char. code */ |
89ebb4a3 | 9835 | U8 termstr[UTF8_MAXBYTES]; /* terminating string */ |
220e2d4e IH |
9836 | STRLEN termlen; /* length of terminating string */ |
9837 | char *last = NULL; /* last position for nesting bracket */ | |
02aa26ce NT |
9838 | |
9839 | /* skip space before the delimiter */ | |
fb73857a | 9840 | if (isSPACE(*s)) |
9841 | s = skipspace(s); | |
02aa26ce NT |
9842 | |
9843 | /* mark where we are, in case we need to report errors */ | |
79072805 | 9844 | CLINE; |
02aa26ce NT |
9845 | |
9846 | /* after skipping whitespace, the next character is the terminator */ | |
a0d0e21e | 9847 | term = *s; |
220e2d4e IH |
9848 | if (!UTF) { |
9849 | termcode = termstr[0] = term; | |
9850 | termlen = 1; | |
9851 | } | |
9852 | else { | |
f3b9ce0f | 9853 | termcode = utf8_to_uvchr((U8*)s, &termlen); |
220e2d4e IH |
9854 | Copy(s, termstr, termlen, U8); |
9855 | if (!UTF8_IS_INVARIANT(term)) | |
9856 | has_utf8 = TRUE; | |
9857 | } | |
b1c7b182 | 9858 | |
02aa26ce | 9859 | /* mark where we are */ |
57843af0 | 9860 | PL_multi_start = CopLINE(PL_curcop); |
3280af22 | 9861 | PL_multi_open = term; |
02aa26ce NT |
9862 | |
9863 | /* find corresponding closing delimiter */ | |
93a17b20 | 9864 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) |
220e2d4e IH |
9865 | termcode = termstr[0] = term = tmps[5]; |
9866 | ||
3280af22 | 9867 | PL_multi_close = term; |
79072805 | 9868 | |
02aa26ce | 9869 | /* create a new SV to hold the contents. 87 is leak category, I'm |
8d6dde3e IZ |
9870 | assuming. 79 is the SV's initial length. What a random number. */ |
9871 | sv = NEWSV(87,79); | |
ed6116ce | 9872 | sv_upgrade(sv, SVt_PVIV); |
220e2d4e | 9873 | SvIVX(sv) = termcode; |
a0d0e21e | 9874 | (void)SvPOK_only(sv); /* validate pointer */ |
02aa26ce NT |
9875 | |
9876 | /* move past delimiter and try to read a complete string */ | |
09bef843 | 9877 | if (keep_delims) |
220e2d4e IH |
9878 | sv_catpvn(sv, s, termlen); |
9879 | s += termlen; | |
93a17b20 | 9880 | for (;;) { |
220e2d4e IH |
9881 | if (PL_encoding && !UTF) { |
9882 | bool cont = TRUE; | |
9883 | ||
9884 | while (cont) { | |
9885 | int offset = s - SvPVX(PL_linestr); | |
9886 | bool found = sv_cat_decode(sv, PL_encoding, PL_linestr, | |
f3b9ce0f | 9887 | &offset, (char*)termstr, termlen); |
220e2d4e IH |
9888 | char *ns = SvPVX(PL_linestr) + offset; |
9889 | char *svlast = SvEND(sv) - 1; | |
9890 | ||
9891 | for (; s < ns; s++) { | |
9892 | if (*s == '\n' && !PL_rsfp) | |
9893 | CopLINE_inc(PL_curcop); | |
9894 | } | |
9895 | if (!found) | |
9896 | goto read_more_line; | |
9897 | else { | |
9898 | /* handle quoted delimiters */ | |
52327caf | 9899 | if (SvCUR(sv) > 1 && *(svlast-1) == '\\') { |
220e2d4e IH |
9900 | char *t; |
9901 | for (t = svlast-2; t >= SvPVX(sv) && *t == '\\';) | |
9902 | t--; | |
9903 | if ((svlast-1 - t) % 2) { | |
9904 | if (!keep_quoted) { | |
9905 | *(svlast-1) = term; | |
9906 | *svlast = '\0'; | |
9907 | SvCUR_set(sv, SvCUR(sv) - 1); | |
9908 | } | |
9909 | continue; | |
9910 | } | |
9911 | } | |
9912 | if (PL_multi_open == PL_multi_close) { | |
9913 | cont = FALSE; | |
9914 | } | |
9915 | else { | |
9916 | char *t, *w; | |
9917 | if (!last) | |
9918 | last = SvPVX(sv); | |
9919 | for (w = t = last; t < svlast; w++, t++) { | |
9920 | /* At here, all closes are "was quoted" one, | |
9921 | so we don't check PL_multi_close. */ | |
9922 | if (*t == '\\') { | |
9923 | if (!keep_quoted && *(t+1) == PL_multi_open) | |
9924 | t++; | |
9925 | else | |
9926 | *w++ = *t++; | |
9927 | } | |
9928 | else if (*t == PL_multi_open) | |
9929 | brackets++; | |
9930 | ||
9931 | *w = *t; | |
9932 | } | |
9933 | if (w < t) { | |
9934 | *w++ = term; | |
9935 | *w = '\0'; | |
9936 | SvCUR_set(sv, w - SvPVX(sv)); | |
9937 | } | |
9938 | last = w; | |
9939 | if (--brackets <= 0) | |
9940 | cont = FALSE; | |
9941 | } | |
9942 | } | |
9943 | } | |
9944 | if (!keep_delims) { | |
9945 | SvCUR_set(sv, SvCUR(sv) - 1); | |
9946 | *SvEND(sv) = '\0'; | |
9947 | } | |
9948 | break; | |
9949 | } | |
9950 | ||
02aa26ce | 9951 | /* extend sv if need be */ |
3280af22 | 9952 | SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1); |
02aa26ce | 9953 | /* set 'to' to the next character in the sv's string */ |
463ee0b2 | 9954 | to = SvPVX(sv)+SvCUR(sv); |
09bef843 | 9955 | |
02aa26ce | 9956 | /* if open delimiter is the close delimiter read unbridle */ |
3280af22 NIS |
9957 | if (PL_multi_open == PL_multi_close) { |
9958 | for (; s < PL_bufend; s++,to++) { | |
02aa26ce | 9959 | /* embedded newlines increment the current line number */ |
3280af22 | 9960 | if (*s == '\n' && !PL_rsfp) |
57843af0 | 9961 | CopLINE_inc(PL_curcop); |
02aa26ce | 9962 | /* handle quoted delimiters */ |
3280af22 | 9963 | if (*s == '\\' && s+1 < PL_bufend && term != '\\') { |
09bef843 | 9964 | if (!keep_quoted && s[1] == term) |
a0d0e21e | 9965 | s++; |
02aa26ce | 9966 | /* any other quotes are simply copied straight through */ |
a0d0e21e LW |
9967 | else |
9968 | *to++ = *s++; | |
9969 | } | |
02aa26ce NT |
9970 | /* terminate when run out of buffer (the for() condition), or |
9971 | have found the terminator */ | |
220e2d4e IH |
9972 | else if (*s == term) { |
9973 | if (termlen == 1) | |
9974 | break; | |
f3b9ce0f | 9975 | if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen)) |
220e2d4e IH |
9976 | break; |
9977 | } | |
63cd0674 | 9978 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
89491803 | 9979 | has_utf8 = TRUE; |
93a17b20 LW |
9980 | *to = *s; |
9981 | } | |
9982 | } | |
02aa26ce NT |
9983 | |
9984 | /* if the terminator isn't the same as the start character (e.g., | |
9985 | matched brackets), we have to allow more in the quoting, and | |
9986 | be prepared for nested brackets. | |
9987 | */ | |
93a17b20 | 9988 | else { |
02aa26ce | 9989 | /* read until we run out of string, or we find the terminator */ |
3280af22 | 9990 | for (; s < PL_bufend; s++,to++) { |
02aa26ce | 9991 | /* embedded newlines increment the line count */ |
3280af22 | 9992 | if (*s == '\n' && !PL_rsfp) |
57843af0 | 9993 | CopLINE_inc(PL_curcop); |
02aa26ce | 9994 | /* backslashes can escape the open or closing characters */ |
3280af22 | 9995 | if (*s == '\\' && s+1 < PL_bufend) { |
09bef843 SB |
9996 | if (!keep_quoted && |
9997 | ((s[1] == PL_multi_open) || (s[1] == PL_multi_close))) | |
a0d0e21e LW |
9998 | s++; |
9999 | else | |
10000 | *to++ = *s++; | |
10001 | } | |
02aa26ce | 10002 | /* allow nested opens and closes */ |
3280af22 | 10003 | else if (*s == PL_multi_close && --brackets <= 0) |
93a17b20 | 10004 | break; |
3280af22 | 10005 | else if (*s == PL_multi_open) |
93a17b20 | 10006 | brackets++; |
63cd0674 | 10007 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
89491803 | 10008 | has_utf8 = TRUE; |
93a17b20 LW |
10009 | *to = *s; |
10010 | } | |
10011 | } | |
02aa26ce | 10012 | /* terminate the copied string and update the sv's end-of-string */ |
93a17b20 | 10013 | *to = '\0'; |
463ee0b2 | 10014 | SvCUR_set(sv, to - SvPVX(sv)); |
93a17b20 | 10015 | |
02aa26ce NT |
10016 | /* |
10017 | * this next chunk reads more into the buffer if we're not done yet | |
10018 | */ | |
10019 | ||
b1c7b182 GS |
10020 | if (s < PL_bufend) |
10021 | break; /* handle case where we are done yet :-) */ | |
79072805 | 10022 | |
6a27c188 | 10023 | #ifndef PERL_STRICT_CR |
f63a84b2 | 10024 | if (to - SvPVX(sv) >= 2) { |
c6f14548 GS |
10025 | if ((to[-2] == '\r' && to[-1] == '\n') || |
10026 | (to[-2] == '\n' && to[-1] == '\r')) | |
10027 | { | |
f63a84b2 LW |
10028 | to[-2] = '\n'; |
10029 | to--; | |
10030 | SvCUR_set(sv, to - SvPVX(sv)); | |
10031 | } | |
10032 | else if (to[-1] == '\r') | |
10033 | to[-1] = '\n'; | |
10034 | } | |
10035 | else if (to - SvPVX(sv) == 1 && to[-1] == '\r') | |
10036 | to[-1] = '\n'; | |
10037 | #endif | |
10038 | ||
220e2d4e | 10039 | read_more_line: |
02aa26ce NT |
10040 | /* if we're out of file, or a read fails, bail and reset the current |
10041 | line marker so we can report where the unterminated string began | |
10042 | */ | |
3280af22 NIS |
10043 | if (!PL_rsfp || |
10044 | !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { | |
c07a80fd | 10045 | sv_free(sv); |
eb160463 | 10046 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
79072805 LW |
10047 | return Nullch; |
10048 | } | |
02aa26ce | 10049 | /* we read a line, so increment our line counter */ |
57843af0 | 10050 | CopLINE_inc(PL_curcop); |
a0ed51b3 | 10051 | |
02aa26ce | 10052 | /* update debugger info */ |
3280af22 | 10053 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
79072805 LW |
10054 | SV *sv = NEWSV(88,0); |
10055 | ||
93a17b20 | 10056 | sv_upgrade(sv, SVt_PVMG); |
3280af22 | 10057 | sv_setsv(sv,PL_linestr); |
0ac0412a MJD |
10058 | (void)SvIOK_on(sv); |
10059 | SvIVX(sv) = 0; | |
57843af0 | 10060 | av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv); |
395c3793 | 10061 | } |
a0ed51b3 | 10062 | |
3280af22 NIS |
10063 | /* having changed the buffer, we must update PL_bufend */ |
10064 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); | |
207e3d1a | 10065 | PL_last_lop = PL_last_uni = Nullch; |
378cc40b | 10066 | } |
4e553d73 | 10067 | |
02aa26ce NT |
10068 | /* at this point, we have successfully read the delimited string */ |
10069 | ||
220e2d4e IH |
10070 | if (!PL_encoding || UTF) { |
10071 | if (keep_delims) | |
10072 | sv_catpvn(sv, s, termlen); | |
10073 | s += termlen; | |
10074 | } | |
10075 | if (has_utf8 || PL_encoding) | |
b1c7b182 | 10076 | SvUTF8_on(sv); |
d0063567 | 10077 | |
57843af0 | 10078 | PL_multi_end = CopLINE(PL_curcop); |
02aa26ce NT |
10079 | |
10080 | /* if we allocated too much space, give some back */ | |
93a17b20 LW |
10081 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
10082 | SvLEN_set(sv, SvCUR(sv) + 1); | |
463ee0b2 | 10083 | Renew(SvPVX(sv), SvLEN(sv), char); |
79072805 | 10084 | } |
02aa26ce NT |
10085 | |
10086 | /* decide whether this is the first or second quoted string we've read | |
10087 | for this op | |
10088 | */ | |
4e553d73 | 10089 | |
3280af22 NIS |
10090 | if (PL_lex_stuff) |
10091 | PL_lex_repl = sv; | |
79072805 | 10092 | else |
3280af22 | 10093 | PL_lex_stuff = sv; |
378cc40b LW |
10094 | return s; |
10095 | } | |
10096 | ||
02aa26ce NT |
10097 | /* |
10098 | scan_num | |
10099 | takes: pointer to position in buffer | |
10100 | returns: pointer to new position in buffer | |
10101 | side-effects: builds ops for the constant in yylval.op | |
10102 | ||
10103 | Read a number in any of the formats that Perl accepts: | |
10104 | ||
7fd134d9 JH |
10105 | \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12. |
10106 | \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34 | |
24138b49 JH |
10107 | 0b[01](_?[01])* |
10108 | 0[0-7](_?[0-7])* | |
10109 | 0x[0-9A-Fa-f](_?[0-9A-Fa-f])* | |
02aa26ce | 10110 | |
3280af22 | 10111 | Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the |
02aa26ce NT |
10112 | thing it reads. |
10113 | ||
10114 | If it reads a number without a decimal point or an exponent, it will | |
10115 | try converting the number to an integer and see if it can do so | |
10116 | without loss of precision. | |
10117 | */ | |
4e553d73 | 10118 | |
378cc40b | 10119 | char * |
bfed75c6 | 10120 | Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp) |
378cc40b | 10121 | { |
bfed75c6 | 10122 | register const char *s = start; /* current position in buffer */ |
02aa26ce NT |
10123 | register char *d; /* destination in temp buffer */ |
10124 | register char *e; /* end of temp buffer */ | |
86554af2 | 10125 | NV nv; /* number read, as a double */ |
a7cb1f99 | 10126 | SV *sv = Nullsv; /* place to put the converted number */ |
a86a20aa | 10127 | bool floatit; /* boolean: int or float? */ |
bfed75c6 AL |
10128 | const char *lastub = 0; /* position of last underbar */ |
10129 | static char const number_too_long[] = "Number too long"; | |
378cc40b | 10130 | |
02aa26ce NT |
10131 | /* We use the first character to decide what type of number this is */ |
10132 | ||
378cc40b | 10133 | switch (*s) { |
79072805 | 10134 | default: |
cea2e8a9 | 10135 | Perl_croak(aTHX_ "panic: scan_num"); |
4e553d73 | 10136 | |
02aa26ce | 10137 | /* if it starts with a 0, it could be an octal number, a decimal in |
a7cb1f99 | 10138 | 0.13 disguise, or a hexadecimal number, or a binary number. */ |
378cc40b LW |
10139 | case '0': |
10140 | { | |
02aa26ce NT |
10141 | /* variables: |
10142 | u holds the "number so far" | |
4f19785b WSI |
10143 | shift the power of 2 of the base |
10144 | (hex == 4, octal == 3, binary == 1) | |
02aa26ce NT |
10145 | overflowed was the number more than we can hold? |
10146 | ||
10147 | Shift is used when we add a digit. It also serves as an "are | |
4f19785b WSI |
10148 | we in octal/hex/binary?" indicator to disallow hex characters |
10149 | when in octal mode. | |
02aa26ce | 10150 | */ |
9e24b6e2 JH |
10151 | NV n = 0.0; |
10152 | UV u = 0; | |
79072805 | 10153 | I32 shift; |
9e24b6e2 | 10154 | bool overflowed = FALSE; |
61f33854 | 10155 | bool just_zero = TRUE; /* just plain 0 or binary number? */ |
9e24b6e2 | 10156 | static NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 }; |
bfed75c6 | 10157 | static char const* bases[5] = { "", "binary", "", "octal", |
9e24b6e2 | 10158 | "hexadecimal" }; |
bfed75c6 | 10159 | static char const* Bases[5] = { "", "Binary", "", "Octal", |
9e24b6e2 | 10160 | "Hexadecimal" }; |
bfed75c6 | 10161 | static char const *maxima[5] = { "", |
9e24b6e2 JH |
10162 | "0b11111111111111111111111111111111", |
10163 | "", | |
893fe2c2 | 10164 | "037777777777", |
9e24b6e2 | 10165 | "0xffffffff" }; |
bfed75c6 | 10166 | const char *base, *Base, *max; |
378cc40b | 10167 | |
02aa26ce | 10168 | /* check for hex */ |
378cc40b LW |
10169 | if (s[1] == 'x') { |
10170 | shift = 4; | |
10171 | s += 2; | |
61f33854 | 10172 | just_zero = FALSE; |
4f19785b WSI |
10173 | } else if (s[1] == 'b') { |
10174 | shift = 1; | |
10175 | s += 2; | |
61f33854 | 10176 | just_zero = FALSE; |
378cc40b | 10177 | } |
02aa26ce | 10178 | /* check for a decimal in disguise */ |
b78218b7 | 10179 | else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E') |
378cc40b | 10180 | goto decimal; |
02aa26ce | 10181 | /* so it must be octal */ |
928753ea | 10182 | else { |
378cc40b | 10183 | shift = 3; |
928753ea JH |
10184 | s++; |
10185 | } | |
10186 | ||
10187 | if (*s == '_') { | |
10188 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10189 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10190 | "Misplaced _ in number"); |
10191 | lastub = s++; | |
10192 | } | |
9e24b6e2 JH |
10193 | |
10194 | base = bases[shift]; | |
10195 | Base = Bases[shift]; | |
10196 | max = maxima[shift]; | |
02aa26ce | 10197 | |
4f19785b | 10198 | /* read the rest of the number */ |
378cc40b | 10199 | for (;;) { |
9e24b6e2 | 10200 | /* x is used in the overflow test, |
893fe2c2 | 10201 | b is the digit we're adding on. */ |
9e24b6e2 | 10202 | UV x, b; |
55497cff | 10203 | |
378cc40b | 10204 | switch (*s) { |
02aa26ce NT |
10205 | |
10206 | /* if we don't mention it, we're done */ | |
378cc40b LW |
10207 | default: |
10208 | goto out; | |
02aa26ce | 10209 | |
928753ea | 10210 | /* _ are ignored -- but warned about if consecutive */ |
de3bb511 | 10211 | case '_': |
928753ea | 10212 | if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1) |
9014280d | 10213 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10214 | "Misplaced _ in number"); |
10215 | lastub = s++; | |
de3bb511 | 10216 | break; |
02aa26ce NT |
10217 | |
10218 | /* 8 and 9 are not octal */ | |
378cc40b | 10219 | case '8': case '9': |
4f19785b | 10220 | if (shift == 3) |
cea2e8a9 | 10221 | yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s)); |
378cc40b | 10222 | /* FALL THROUGH */ |
02aa26ce NT |
10223 | |
10224 | /* octal digits */ | |
4f19785b | 10225 | case '2': case '3': case '4': |
378cc40b | 10226 | case '5': case '6': case '7': |
4f19785b | 10227 | if (shift == 1) |
cea2e8a9 | 10228 | yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s)); |
4f19785b WSI |
10229 | /* FALL THROUGH */ |
10230 | ||
10231 | case '0': case '1': | |
02aa26ce | 10232 | b = *s++ & 15; /* ASCII digit -> value of digit */ |
55497cff | 10233 | goto digit; |
02aa26ce NT |
10234 | |
10235 | /* hex digits */ | |
378cc40b LW |
10236 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': |
10237 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': | |
02aa26ce | 10238 | /* make sure they said 0x */ |
378cc40b LW |
10239 | if (shift != 4) |
10240 | goto out; | |
55497cff | 10241 | b = (*s++ & 7) + 9; |
02aa26ce NT |
10242 | |
10243 | /* Prepare to put the digit we have onto the end | |
10244 | of the number so far. We check for overflows. | |
10245 | */ | |
10246 | ||
55497cff | 10247 | digit: |
61f33854 | 10248 | just_zero = FALSE; |
9e24b6e2 JH |
10249 | if (!overflowed) { |
10250 | x = u << shift; /* make room for the digit */ | |
10251 | ||
10252 | if ((x >> shift) != u | |
10253 | && !(PL_hints & HINT_NEW_BINARY)) { | |
9e24b6e2 JH |
10254 | overflowed = TRUE; |
10255 | n = (NV) u; | |
767a6a26 | 10256 | if (ckWARN_d(WARN_OVERFLOW)) |
9014280d | 10257 | Perl_warner(aTHX_ packWARN(WARN_OVERFLOW), |
9e24b6e2 JH |
10258 | "Integer overflow in %s number", |
10259 | base); | |
10260 | } else | |
10261 | u = x | b; /* add the digit to the end */ | |
10262 | } | |
10263 | if (overflowed) { | |
10264 | n *= nvshift[shift]; | |
10265 | /* If an NV has not enough bits in its | |
10266 | * mantissa to represent an UV this summing of | |
10267 | * small low-order numbers is a waste of time | |
10268 | * (because the NV cannot preserve the | |
10269 | * low-order bits anyway): we could just | |
10270 | * remember when did we overflow and in the | |
10271 | * end just multiply n by the right | |
10272 | * amount. */ | |
10273 | n += (NV) b; | |
55497cff | 10274 | } |
378cc40b LW |
10275 | break; |
10276 | } | |
10277 | } | |
02aa26ce NT |
10278 | |
10279 | /* if we get here, we had success: make a scalar value from | |
10280 | the number. | |
10281 | */ | |
378cc40b | 10282 | out: |
928753ea JH |
10283 | |
10284 | /* final misplaced underbar check */ | |
10285 | if (s[-1] == '_') { | |
10286 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10287 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number"); |
928753ea JH |
10288 | } |
10289 | ||
79072805 | 10290 | sv = NEWSV(92,0); |
9e24b6e2 | 10291 | if (overflowed) { |
767a6a26 | 10292 | if (ckWARN(WARN_PORTABLE) && n > 4294967295.0) |
9014280d | 10293 | Perl_warner(aTHX_ packWARN(WARN_PORTABLE), |
9e24b6e2 JH |
10294 | "%s number > %s non-portable", |
10295 | Base, max); | |
10296 | sv_setnv(sv, n); | |
10297 | } | |
10298 | else { | |
15041a67 | 10299 | #if UVSIZE > 4 |
767a6a26 | 10300 | if (ckWARN(WARN_PORTABLE) && u > 0xffffffff) |
9014280d | 10301 | Perl_warner(aTHX_ packWARN(WARN_PORTABLE), |
9e24b6e2 JH |
10302 | "%s number > %s non-portable", |
10303 | Base, max); | |
2cc4c2dc | 10304 | #endif |
9e24b6e2 JH |
10305 | sv_setuv(sv, u); |
10306 | } | |
61f33854 | 10307 | if (just_zero && (PL_hints & HINT_NEW_INTEGER)) |
bfed75c6 | 10308 | sv = new_constant(start, s - start, "integer", |
61f33854 RGS |
10309 | sv, Nullsv, NULL); |
10310 | else if (PL_hints & HINT_NEW_BINARY) | |
b3ac6de7 | 10311 | sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL); |
378cc40b LW |
10312 | } |
10313 | break; | |
02aa26ce NT |
10314 | |
10315 | /* | |
10316 | handle decimal numbers. | |
10317 | we're also sent here when we read a 0 as the first digit | |
10318 | */ | |
378cc40b LW |
10319 | case '1': case '2': case '3': case '4': case '5': |
10320 | case '6': case '7': case '8': case '9': case '.': | |
10321 | decimal: | |
3280af22 NIS |
10322 | d = PL_tokenbuf; |
10323 | e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */ | |
79072805 | 10324 | floatit = FALSE; |
02aa26ce NT |
10325 | |
10326 | /* read next group of digits and _ and copy into d */ | |
de3bb511 | 10327 | while (isDIGIT(*s) || *s == '_') { |
4e553d73 | 10328 | /* skip underscores, checking for misplaced ones |
02aa26ce NT |
10329 | if -w is on |
10330 | */ | |
93a17b20 | 10331 | if (*s == '_') { |
928753ea | 10332 | if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1) |
9014280d | 10333 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10334 | "Misplaced _ in number"); |
10335 | lastub = s++; | |
93a17b20 | 10336 | } |
fc36a67e | 10337 | else { |
02aa26ce | 10338 | /* check for end of fixed-length buffer */ |
fc36a67e | 10339 | if (d >= e) |
cea2e8a9 | 10340 | Perl_croak(aTHX_ number_too_long); |
02aa26ce | 10341 | /* if we're ok, copy the character */ |
378cc40b | 10342 | *d++ = *s++; |
fc36a67e | 10343 | } |
378cc40b | 10344 | } |
02aa26ce NT |
10345 | |
10346 | /* final misplaced underbar check */ | |
928753ea | 10347 | if (lastub && s == lastub + 1) { |
d008e5eb | 10348 | if (ckWARN(WARN_SYNTAX)) |
9014280d | 10349 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number"); |
d008e5eb | 10350 | } |
02aa26ce NT |
10351 | |
10352 | /* read a decimal portion if there is one. avoid | |
10353 | 3..5 being interpreted as the number 3. followed | |
10354 | by .5 | |
10355 | */ | |
2f3197b3 | 10356 | if (*s == '.' && s[1] != '.') { |
79072805 | 10357 | floatit = TRUE; |
378cc40b | 10358 | *d++ = *s++; |
02aa26ce | 10359 | |
928753ea JH |
10360 | if (*s == '_') { |
10361 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10362 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10363 | "Misplaced _ in number"); |
10364 | lastub = s; | |
10365 | } | |
10366 | ||
10367 | /* copy, ignoring underbars, until we run out of digits. | |
02aa26ce | 10368 | */ |
fc36a67e | 10369 | for (; isDIGIT(*s) || *s == '_'; s++) { |
02aa26ce | 10370 | /* fixed length buffer check */ |
fc36a67e | 10371 | if (d >= e) |
cea2e8a9 | 10372 | Perl_croak(aTHX_ number_too_long); |
928753ea JH |
10373 | if (*s == '_') { |
10374 | if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1) | |
9014280d | 10375 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10376 | "Misplaced _ in number"); |
10377 | lastub = s; | |
10378 | } | |
10379 | else | |
fc36a67e | 10380 | *d++ = *s; |
378cc40b | 10381 | } |
928753ea JH |
10382 | /* fractional part ending in underbar? */ |
10383 | if (s[-1] == '_') { | |
10384 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10385 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
928753ea JH |
10386 | "Misplaced _ in number"); |
10387 | } | |
dd629d5b GS |
10388 | if (*s == '.' && isDIGIT(s[1])) { |
10389 | /* oops, it's really a v-string, but without the "v" */ | |
f4758303 | 10390 | s = start; |
dd629d5b GS |
10391 | goto vstring; |
10392 | } | |
378cc40b | 10393 | } |
02aa26ce NT |
10394 | |
10395 | /* read exponent part, if present */ | |
3792a11b | 10396 | if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) { |
79072805 LW |
10397 | floatit = TRUE; |
10398 | s++; | |
02aa26ce NT |
10399 | |
10400 | /* regardless of whether user said 3E5 or 3e5, use lower 'e' */ | |
79072805 | 10401 | *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */ |
02aa26ce | 10402 | |
7fd134d9 JH |
10403 | /* stray preinitial _ */ |
10404 | if (*s == '_') { | |
10405 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10406 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
7fd134d9 JH |
10407 | "Misplaced _ in number"); |
10408 | lastub = s++; | |
10409 | } | |
10410 | ||
02aa26ce | 10411 | /* allow positive or negative exponent */ |
378cc40b LW |
10412 | if (*s == '+' || *s == '-') |
10413 | *d++ = *s++; | |
02aa26ce | 10414 | |
7fd134d9 JH |
10415 | /* stray initial _ */ |
10416 | if (*s == '_') { | |
10417 | if (ckWARN(WARN_SYNTAX)) | |
9014280d | 10418 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
7fd134d9 JH |
10419 | "Misplaced _ in number"); |
10420 | lastub = s++; | |
10421 | } | |
10422 | ||
7fd134d9 JH |
10423 | /* read digits of exponent */ |
10424 | while (isDIGIT(*s) || *s == '_') { | |
10425 | if (isDIGIT(*s)) { | |
10426 | if (d >= e) | |
10427 | Perl_croak(aTHX_ number_too_long); | |
b3b48e3e | 10428 | *d++ = *s++; |
7fd134d9 JH |
10429 | } |
10430 | else { | |
10431 | if (ckWARN(WARN_SYNTAX) && | |
10432 | ((lastub && s == lastub + 1) || | |
b3b48e3e | 10433 | (!isDIGIT(s[1]) && s[1] != '_'))) |
9014280d | 10434 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
7fd134d9 | 10435 | "Misplaced _ in number"); |
b3b48e3e | 10436 | lastub = s++; |
7fd134d9 | 10437 | } |
7fd134d9 | 10438 | } |
378cc40b | 10439 | } |
02aa26ce | 10440 | |
02aa26ce NT |
10441 | |
10442 | /* make an sv from the string */ | |
79072805 | 10443 | sv = NEWSV(92,0); |
097ee67d | 10444 | |
0b7fceb9 | 10445 | /* |
58bb9ec3 NC |
10446 | We try to do an integer conversion first if no characters |
10447 | indicating "float" have been found. | |
0b7fceb9 MU |
10448 | */ |
10449 | ||
10450 | if (!floatit) { | |
58bb9ec3 NC |
10451 | UV uv; |
10452 | int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv); | |
10453 | ||
10454 | if (flags == IS_NUMBER_IN_UV) { | |
10455 | if (uv <= IV_MAX) | |
86554af2 | 10456 | sv_setiv(sv, uv); /* Prefer IVs over UVs. */ |
58bb9ec3 | 10457 | else |
c239479b | 10458 | sv_setuv(sv, uv); |
58bb9ec3 NC |
10459 | } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) { |
10460 | if (uv <= (UV) IV_MIN) | |
10461 | sv_setiv(sv, -(IV)uv); | |
10462 | else | |
10463 | floatit = TRUE; | |
10464 | } else | |
10465 | floatit = TRUE; | |
10466 | } | |
0b7fceb9 | 10467 | if (floatit) { |
58bb9ec3 NC |
10468 | /* terminate the string */ |
10469 | *d = '\0'; | |
86554af2 JH |
10470 | nv = Atof(PL_tokenbuf); |
10471 | sv_setnv(sv, nv); | |
10472 | } | |
86554af2 | 10473 | |
b8403495 JH |
10474 | if ( floatit ? (PL_hints & HINT_NEW_FLOAT) : |
10475 | (PL_hints & HINT_NEW_INTEGER) ) | |
4e553d73 | 10476 | sv = new_constant(PL_tokenbuf, d - PL_tokenbuf, |
b8403495 JH |
10477 | (floatit ? "float" : "integer"), |
10478 | sv, Nullsv, NULL); | |
378cc40b | 10479 | break; |
0b7fceb9 | 10480 | |
e312add1 | 10481 | /* if it starts with a v, it could be a v-string */ |
a7cb1f99 | 10482 | case 'v': |
dd629d5b | 10483 | vstring: |
f4758303 | 10484 | sv = NEWSV(92,5); /* preallocate storage space */ |
b0f01acb | 10485 | s = scan_vstring(s,sv); |
a7cb1f99 | 10486 | break; |
79072805 | 10487 | } |
a687059c | 10488 | |
02aa26ce NT |
10489 | /* make the op for the constant and return */ |
10490 | ||
a86a20aa | 10491 | if (sv) |
b73d6f50 | 10492 | lvalp->opval = newSVOP(OP_CONST, 0, sv); |
a7cb1f99 | 10493 | else |
b73d6f50 | 10494 | lvalp->opval = Nullop; |
a687059c | 10495 | |
73d840c0 | 10496 | return (char *)s; |
378cc40b LW |
10497 | } |
10498 | ||
76e3520e | 10499 | STATIC char * |
cea2e8a9 | 10500 | S_scan_formline(pTHX_ register char *s) |
378cc40b | 10501 | { |
79072805 | 10502 | register char *eol; |
378cc40b | 10503 | register char *t; |
79cb57f6 | 10504 | SV *stuff = newSVpvn("",0); |
79072805 | 10505 | bool needargs = FALSE; |
c5ee2135 | 10506 | bool eofmt = FALSE; |
378cc40b | 10507 | |
79072805 | 10508 | while (!needargs) { |
a1b95068 | 10509 | if (*s == '.') { |
79072805 | 10510 | /*SUPPRESS 530*/ |
51882d45 | 10511 | #ifdef PERL_STRICT_CR |
bf4acbe4 | 10512 | for (t = s+1;SPACE_OR_TAB(*t); t++) ; |
51882d45 | 10513 | #else |
bf4acbe4 | 10514 | for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ; |
51882d45 | 10515 | #endif |
c5ee2135 WL |
10516 | if (*t == '\n' || t == PL_bufend) { |
10517 | eofmt = TRUE; | |
79072805 | 10518 | break; |
c5ee2135 | 10519 | } |
79072805 | 10520 | } |
3280af22 | 10521 | if (PL_in_eval && !PL_rsfp) { |
07409e01 | 10522 | eol = (char *) memchr(s,'\n',PL_bufend-s); |
0f85fab0 | 10523 | if (!eol++) |
3280af22 | 10524 | eol = PL_bufend; |
0f85fab0 LW |
10525 | } |
10526 | else | |
3280af22 | 10527 | eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
79072805 | 10528 | if (*s != '#') { |
a0d0e21e LW |
10529 | for (t = s; t < eol; t++) { |
10530 | if (*t == '~' && t[1] == '~' && SvCUR(stuff)) { | |
10531 | needargs = FALSE; | |
10532 | goto enough; /* ~~ must be first line in formline */ | |
378cc40b | 10533 | } |
a0d0e21e LW |
10534 | if (*t == '@' || *t == '^') |
10535 | needargs = TRUE; | |
378cc40b | 10536 | } |
7121b347 MG |
10537 | if (eol > s) { |
10538 | sv_catpvn(stuff, s, eol-s); | |
2dc4c65b | 10539 | #ifndef PERL_STRICT_CR |
7121b347 MG |
10540 | if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') { |
10541 | char *end = SvPVX(stuff) + SvCUR(stuff); | |
10542 | end[-2] = '\n'; | |
10543 | end[-1] = '\0'; | |
10544 | SvCUR(stuff)--; | |
10545 | } | |
2dc4c65b | 10546 | #endif |
7121b347 MG |
10547 | } |
10548 | else | |
10549 | break; | |
79072805 LW |
10550 | } |
10551 | s = eol; | |
3280af22 NIS |
10552 | if (PL_rsfp) { |
10553 | s = filter_gets(PL_linestr, PL_rsfp, 0); | |
10554 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr); | |
10555 | PL_bufend = PL_bufptr + SvCUR(PL_linestr); | |
207e3d1a | 10556 | PL_last_lop = PL_last_uni = Nullch; |
79072805 | 10557 | if (!s) { |
3280af22 | 10558 | s = PL_bufptr; |
378cc40b LW |
10559 | break; |
10560 | } | |
378cc40b | 10561 | } |
463ee0b2 | 10562 | incline(s); |
79072805 | 10563 | } |
a0d0e21e LW |
10564 | enough: |
10565 | if (SvCUR(stuff)) { | |
3280af22 | 10566 | PL_expect = XTERM; |
79072805 | 10567 | if (needargs) { |
3280af22 NIS |
10568 | PL_lex_state = LEX_NORMAL; |
10569 | PL_nextval[PL_nexttoke].ival = 0; | |
79072805 LW |
10570 | force_next(','); |
10571 | } | |
a0d0e21e | 10572 | else |
3280af22 | 10573 | PL_lex_state = LEX_FORMLINE; |
1bd51a4c IH |
10574 | if (!IN_BYTES) { |
10575 | if (UTF && is_utf8_string((U8*)SvPVX(stuff), SvCUR(stuff))) | |
10576 | SvUTF8_on(stuff); | |
10577 | else if (PL_encoding) | |
10578 | sv_recode_to_utf8(stuff, PL_encoding); | |
10579 | } | |
3280af22 | 10580 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff); |
79072805 | 10581 | force_next(THING); |
3280af22 | 10582 | PL_nextval[PL_nexttoke].ival = OP_FORMLINE; |
79072805 | 10583 | force_next(LSTOP); |
378cc40b | 10584 | } |
79072805 | 10585 | else { |
8990e307 | 10586 | SvREFCNT_dec(stuff); |
c5ee2135 WL |
10587 | if (eofmt) |
10588 | PL_lex_formbrack = 0; | |
3280af22 | 10589 | PL_bufptr = s; |
79072805 LW |
10590 | } |
10591 | return s; | |
378cc40b | 10592 | } |
a687059c | 10593 | |
76e3520e | 10594 | STATIC void |
cea2e8a9 | 10595 | S_set_csh(pTHX) |
a687059c | 10596 | { |
ae986130 | 10597 | #ifdef CSH |
3280af22 NIS |
10598 | if (!PL_cshlen) |
10599 | PL_cshlen = strlen(PL_cshname); | |
ae986130 | 10600 | #endif |
a687059c | 10601 | } |
463ee0b2 | 10602 | |
ba6d6ac9 | 10603 | I32 |
864dbfa3 | 10604 | Perl_start_subparse(pTHX_ I32 is_format, U32 flags) |
8990e307 | 10605 | { |
3280af22 NIS |
10606 | I32 oldsavestack_ix = PL_savestack_ix; |
10607 | CV* outsidecv = PL_compcv; | |
8990e307 | 10608 | |
3280af22 NIS |
10609 | if (PL_compcv) { |
10610 | assert(SvTYPE(PL_compcv) == SVt_PVCV); | |
e9a444f0 | 10611 | } |
7766f137 | 10612 | SAVEI32(PL_subline); |
3280af22 | 10613 | save_item(PL_subname); |
3280af22 | 10614 | SAVESPTR(PL_compcv); |
3280af22 NIS |
10615 | |
10616 | PL_compcv = (CV*)NEWSV(1104,0); | |
10617 | sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV); | |
10618 | CvFLAGS(PL_compcv) |= flags; | |
10619 | ||
57843af0 | 10620 | PL_subline = CopLINE(PL_curcop); |
dd2155a4 | 10621 | CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB); |
3280af22 | 10622 | CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv); |
a3985cdc | 10623 | CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax; |
748a9306 | 10624 | |
8990e307 LW |
10625 | return oldsavestack_ix; |
10626 | } | |
10627 | ||
084592ab CN |
10628 | #ifdef __SC__ |
10629 | #pragma segment Perl_yylex | |
10630 | #endif | |
8990e307 | 10631 | int |
bfed75c6 | 10632 | Perl_yywarn(pTHX_ const char *s) |
8990e307 | 10633 | { |
faef0170 | 10634 | PL_in_eval |= EVAL_WARNONLY; |
748a9306 | 10635 | yyerror(s); |
faef0170 | 10636 | PL_in_eval &= ~EVAL_WARNONLY; |
748a9306 | 10637 | return 0; |
8990e307 LW |
10638 | } |
10639 | ||
10640 | int | |
bfed75c6 | 10641 | Perl_yyerror(pTHX_ const char *s) |
463ee0b2 | 10642 | { |
bfed75c6 AL |
10643 | const char *where = NULL; |
10644 | const char *context = NULL; | |
68dc0745 | 10645 | int contlen = -1; |
46fc3d4c | 10646 | SV *msg; |
463ee0b2 | 10647 | |
3280af22 | 10648 | if (!yychar || (yychar == ';' && !PL_rsfp)) |
54310121 | 10649 | where = "at EOF"; |
3280af22 NIS |
10650 | else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 && |
10651 | PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) { | |
f355267c JH |
10652 | /* |
10653 | Only for NetWare: | |
10654 | The code below is removed for NetWare because it abends/crashes on NetWare | |
10655 | when the script has error such as not having the closing quotes like: | |
10656 | if ($var eq "value) | |
10657 | Checking of white spaces is anyway done in NetWare code. | |
10658 | */ | |
10659 | #ifndef NETWARE | |
3280af22 NIS |
10660 | while (isSPACE(*PL_oldoldbufptr)) |
10661 | PL_oldoldbufptr++; | |
f355267c | 10662 | #endif |
3280af22 NIS |
10663 | context = PL_oldoldbufptr; |
10664 | contlen = PL_bufptr - PL_oldoldbufptr; | |
463ee0b2 | 10665 | } |
3280af22 NIS |
10666 | else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 && |
10667 | PL_oldbufptr != PL_bufptr) { | |
f355267c JH |
10668 | /* |
10669 | Only for NetWare: | |
10670 | The code below is removed for NetWare because it abends/crashes on NetWare | |
10671 | when the script has error such as not having the closing quotes like: | |
10672 | if ($var eq "value) | |
10673 | Checking of white spaces is anyway done in NetWare code. | |
10674 | */ | |
10675 | #ifndef NETWARE | |
3280af22 NIS |
10676 | while (isSPACE(*PL_oldbufptr)) |
10677 | PL_oldbufptr++; | |
f355267c | 10678 | #endif |
3280af22 NIS |
10679 | context = PL_oldbufptr; |
10680 | contlen = PL_bufptr - PL_oldbufptr; | |
463ee0b2 LW |
10681 | } |
10682 | else if (yychar > 255) | |
68dc0745 | 10683 | where = "next token ???"; |
12fbd33b | 10684 | else if (yychar == -2) { /* YYEMPTY */ |
3280af22 NIS |
10685 | if (PL_lex_state == LEX_NORMAL || |
10686 | (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL)) | |
68dc0745 | 10687 | where = "at end of line"; |
3280af22 | 10688 | else if (PL_lex_inpat) |
68dc0745 | 10689 | where = "within pattern"; |
463ee0b2 | 10690 | else |
68dc0745 | 10691 | where = "within string"; |
463ee0b2 | 10692 | } |
46fc3d4c | 10693 | else { |
79cb57f6 | 10694 | SV *where_sv = sv_2mortal(newSVpvn("next char ", 10)); |
46fc3d4c | 10695 | if (yychar < 32) |
cea2e8a9 | 10696 | Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar)); |
46fc3d4c | 10697 | else if (isPRINT_LC(yychar)) |
cea2e8a9 | 10698 | Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar); |
463ee0b2 | 10699 | else |
cea2e8a9 | 10700 | Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255); |
46fc3d4c | 10701 | where = SvPVX(where_sv); |
463ee0b2 | 10702 | } |
46fc3d4c | 10703 | msg = sv_2mortal(newSVpv(s, 0)); |
ed094faf | 10704 | Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ", |
248c2a4d | 10705 | OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop)); |
68dc0745 | 10706 | if (context) |
cea2e8a9 | 10707 | Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context); |
463ee0b2 | 10708 | else |
cea2e8a9 | 10709 | Perl_sv_catpvf(aTHX_ msg, "%s\n", where); |
57843af0 | 10710 | if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) { |
cf2093f6 | 10711 | Perl_sv_catpvf(aTHX_ msg, |
57def98f | 10712 | " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n", |
cf2093f6 | 10713 | (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start); |
3280af22 | 10714 | PL_multi_end = 0; |
a0d0e21e | 10715 | } |
56da5a46 RGS |
10716 | if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX)) |
10717 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg); | |
463ee0b2 | 10718 | else |
5a844595 | 10719 | qerror(msg); |
c7d6bfb2 GS |
10720 | if (PL_error_count >= 10) { |
10721 | if (PL_in_eval && SvCUR(ERRSV)) | |
d2560b70 | 10722 | Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n", |
248c2a4d | 10723 | ERRSV, OutCopFILE(PL_curcop)); |
c7d6bfb2 GS |
10724 | else |
10725 | Perl_croak(aTHX_ "%s has too many errors.\n", | |
248c2a4d | 10726 | OutCopFILE(PL_curcop)); |
c7d6bfb2 | 10727 | } |
3280af22 NIS |
10728 | PL_in_my = 0; |
10729 | PL_in_my_stash = Nullhv; | |
463ee0b2 LW |
10730 | return 0; |
10731 | } | |
084592ab CN |
10732 | #ifdef __SC__ |
10733 | #pragma segment Main | |
10734 | #endif | |
4e35701f | 10735 | |
b250498f | 10736 | STATIC char* |
3ae08724 | 10737 | S_swallow_bom(pTHX_ U8 *s) |
01ec43d0 | 10738 | { |
b250498f GS |
10739 | STRLEN slen; |
10740 | slen = SvCUR(PL_linestr); | |
7aa207d6 | 10741 | switch (s[0]) { |
4e553d73 NIS |
10742 | case 0xFF: |
10743 | if (s[1] == 0xFE) { | |
7aa207d6 | 10744 | /* UTF-16 little-endian? (or UTF32-LE?) */ |
3ae08724 | 10745 | if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */ |
7aa207d6 | 10746 | Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE"); |
01ec43d0 | 10747 | #ifndef PERL_NO_UTF16_FILTER |
7aa207d6 | 10748 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n"); |
3ae08724 | 10749 | s += 2; |
7aa207d6 | 10750 | utf16le: |
dea0fc0b JH |
10751 | if (PL_bufend > (char*)s) { |
10752 | U8 *news; | |
10753 | I32 newlen; | |
10754 | ||
10755 | filter_add(utf16rev_textfilter, NULL); | |
10756 | New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8); | |
1de9afcd RGS |
10757 | utf16_to_utf8_reversed(s, news, |
10758 | PL_bufend - (char*)s - 1, | |
10759 | &newlen); | |
7aa207d6 | 10760 | sv_setpvn(PL_linestr, (const char*)news, newlen); |
dea0fc0b | 10761 | Safefree(news); |
7aa207d6 JH |
10762 | SvUTF8_on(PL_linestr); |
10763 | s = (U8*)SvPVX(PL_linestr); | |
10764 | PL_bufend = SvPVX(PL_linestr) + newlen; | |
dea0fc0b | 10765 | } |
b250498f | 10766 | #else |
7aa207d6 | 10767 | Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE"); |
b250498f | 10768 | #endif |
01ec43d0 GS |
10769 | } |
10770 | break; | |
78ae23f5 | 10771 | case 0xFE: |
7aa207d6 | 10772 | if (s[1] == 0xFF) { /* UTF-16 big-endian? */ |
01ec43d0 | 10773 | #ifndef PERL_NO_UTF16_FILTER |
7aa207d6 | 10774 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n"); |
dea0fc0b | 10775 | s += 2; |
7aa207d6 | 10776 | utf16be: |
dea0fc0b JH |
10777 | if (PL_bufend > (char *)s) { |
10778 | U8 *news; | |
10779 | I32 newlen; | |
10780 | ||
10781 | filter_add(utf16_textfilter, NULL); | |
10782 | New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8); | |
1de9afcd RGS |
10783 | utf16_to_utf8(s, news, |
10784 | PL_bufend - (char*)s, | |
10785 | &newlen); | |
7aa207d6 | 10786 | sv_setpvn(PL_linestr, (const char*)news, newlen); |
dea0fc0b | 10787 | Safefree(news); |
7aa207d6 JH |
10788 | SvUTF8_on(PL_linestr); |
10789 | s = (U8*)SvPVX(PL_linestr); | |
10790 | PL_bufend = SvPVX(PL_linestr) + newlen; | |
dea0fc0b | 10791 | } |
b250498f | 10792 | #else |
7aa207d6 | 10793 | Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE"); |
b250498f | 10794 | #endif |
01ec43d0 GS |
10795 | } |
10796 | break; | |
3ae08724 GS |
10797 | case 0xEF: |
10798 | if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) { | |
7aa207d6 | 10799 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n"); |
01ec43d0 GS |
10800 | s += 3; /* UTF-8 */ |
10801 | } | |
10802 | break; | |
10803 | case 0: | |
7aa207d6 JH |
10804 | if (slen > 3) { |
10805 | if (s[1] == 0) { | |
10806 | if (s[2] == 0xFE && s[3] == 0xFF) { | |
10807 | /* UTF-32 big-endian */ | |
10808 | Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE"); | |
10809 | } | |
10810 | } | |
10811 | else if (s[2] == 0 && s[3] != 0) { | |
10812 | /* Leading bytes | |
10813 | * 00 xx 00 xx | |
10814 | * are a good indicator of UTF-16BE. */ | |
10815 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n"); | |
10816 | goto utf16be; | |
10817 | } | |
01ec43d0 | 10818 | } |
7aa207d6 JH |
10819 | default: |
10820 | if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) { | |
10821 | /* Leading bytes | |
10822 | * xx 00 xx 00 | |
10823 | * are a good indicator of UTF-16LE. */ | |
10824 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n"); | |
10825 | goto utf16le; | |
10826 | } | |
01ec43d0 | 10827 | } |
b8f84bb2 | 10828 | return (char*)s; |
b250498f | 10829 | } |
4755096e | 10830 | |
4755096e GS |
10831 | /* |
10832 | * restore_rsfp | |
10833 | * Restore a source filter. | |
10834 | */ | |
10835 | ||
10836 | static void | |
acfe0abc | 10837 | restore_rsfp(pTHX_ void *f) |
4755096e GS |
10838 | { |
10839 | PerlIO *fp = (PerlIO*)f; | |
10840 | ||
10841 | if (PL_rsfp == PerlIO_stdin()) | |
10842 | PerlIO_clearerr(PL_rsfp); | |
10843 | else if (PL_rsfp && (PL_rsfp != fp)) | |
10844 | PerlIO_close(PL_rsfp); | |
10845 | PL_rsfp = fp; | |
10846 | } | |
6e3aabd6 GS |
10847 | |
10848 | #ifndef PERL_NO_UTF16_FILTER | |
10849 | static I32 | |
acfe0abc | 10850 | utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
6e3aabd6 | 10851 | { |
1de9afcd | 10852 | STRLEN old = SvCUR(sv); |
6e3aabd6 | 10853 | I32 count = FILTER_READ(idx+1, sv, maxlen); |
1de9afcd RGS |
10854 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
10855 | "utf16_textfilter(%p): %d %d (%d)\n", | |
4fccd7c6 | 10856 | utf16_textfilter, idx, maxlen, (int) count)); |
6e3aabd6 GS |
10857 | if (count) { |
10858 | U8* tmps; | |
dea0fc0b | 10859 | I32 newlen; |
6e3aabd6 | 10860 | New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8); |
1de9afcd RGS |
10861 | Copy(SvPVX(sv), tmps, old, char); |
10862 | utf16_to_utf8((U8*)SvPVX(sv) + old, tmps + old, | |
10863 | SvCUR(sv) - old, &newlen); | |
10864 | sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old); | |
6e3aabd6 | 10865 | } |
1de9afcd RGS |
10866 | DEBUG_P({sv_dump(sv);}); |
10867 | return SvCUR(sv); | |
6e3aabd6 GS |
10868 | } |
10869 | ||
10870 | static I32 | |
acfe0abc | 10871 | utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
6e3aabd6 | 10872 | { |
1de9afcd | 10873 | STRLEN old = SvCUR(sv); |
6e3aabd6 | 10874 | I32 count = FILTER_READ(idx+1, sv, maxlen); |
1de9afcd RGS |
10875 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
10876 | "utf16rev_textfilter(%p): %d %d (%d)\n", | |
4fccd7c6 | 10877 | utf16rev_textfilter, idx, maxlen, (int) count)); |
6e3aabd6 GS |
10878 | if (count) { |
10879 | U8* tmps; | |
dea0fc0b | 10880 | I32 newlen; |
6e3aabd6 | 10881 | New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8); |
1de9afcd RGS |
10882 | Copy(SvPVX(sv), tmps, old, char); |
10883 | utf16_to_utf8((U8*)SvPVX(sv) + old, tmps + old, | |
10884 | SvCUR(sv) - old, &newlen); | |
10885 | sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old); | |
6e3aabd6 | 10886 | } |
1de9afcd | 10887 | DEBUG_P({ sv_dump(sv); }); |
6e3aabd6 GS |
10888 | return count; |
10889 | } | |
10890 | #endif | |
9f4817db | 10891 | |
f333445c JP |
10892 | /* |
10893 | Returns a pointer to the next character after the parsed | |
10894 | vstring, as well as updating the passed in sv. | |
10895 | ||
10896 | Function must be called like | |
10897 | ||
10898 | sv = NEWSV(92,5); | |
10899 | s = scan_vstring(s,sv); | |
10900 | ||
10901 | The sv should already be large enough to store the vstring | |
10902 | passed in, for performance reasons. | |
10903 | ||
10904 | */ | |
10905 | ||
10906 | char * | |
bfed75c6 | 10907 | Perl_scan_vstring(pTHX_ const char *s, SV *sv) |
f333445c | 10908 | { |
bfed75c6 AL |
10909 | const char *pos = s; |
10910 | const char *start = s; | |
f333445c | 10911 | if (*pos == 'v') pos++; /* get past 'v' */ |
3e884cbf JH |
10912 | while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_')) |
10913 | pos++; | |
f333445c JP |
10914 | if ( *pos != '.') { |
10915 | /* this may not be a v-string if followed by => */ | |
bfed75c6 | 10916 | const char *next = pos; |
8fc7bb1c SM |
10917 | while (next < PL_bufend && isSPACE(*next)) |
10918 | ++next; | |
10919 | if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) { | |
f333445c JP |
10920 | /* return string not v-string */ |
10921 | sv_setpvn(sv,(char *)s,pos-s); | |
73d840c0 | 10922 | return (char *)pos; |
f333445c JP |
10923 | } |
10924 | } | |
10925 | ||
10926 | if (!isALPHA(*pos)) { | |
10927 | UV rev; | |
89ebb4a3 | 10928 | U8 tmpbuf[UTF8_MAXBYTES+1]; |
f333445c JP |
10929 | U8 *tmpend; |
10930 | ||
10931 | if (*s == 'v') s++; /* get past 'v' */ | |
10932 | ||
10933 | sv_setpvn(sv, "", 0); | |
10934 | ||
10935 | for (;;) { | |
10936 | rev = 0; | |
10937 | { | |
10938 | /* this is atoi() that tolerates underscores */ | |
bfed75c6 | 10939 | const char *end = pos; |
f333445c JP |
10940 | UV mult = 1; |
10941 | while (--end >= s) { | |
10942 | UV orev; | |
10943 | if (*end == '_') | |
10944 | continue; | |
10945 | orev = rev; | |
10946 | rev += (*end - '0') * mult; | |
10947 | mult *= 10; | |
10948 | if (orev > rev && ckWARN_d(WARN_OVERFLOW)) | |
10949 | Perl_warner(aTHX_ packWARN(WARN_OVERFLOW), | |
10950 | "Integer overflow in decimal number"); | |
10951 | } | |
10952 | } | |
10953 | #ifdef EBCDIC | |
10954 | if (rev > 0x7FFFFFFF) | |
10955 | Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647"); | |
10956 | #endif | |
10957 | /* Append native character for the rev point */ | |
10958 | tmpend = uvchr_to_utf8(tmpbuf, rev); | |
10959 | sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf); | |
10960 | if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev))) | |
10961 | SvUTF8_on(sv); | |
3e884cbf | 10962 | if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1])) |
f333445c JP |
10963 | s = ++pos; |
10964 | else { | |
10965 | s = pos; | |
10966 | break; | |
10967 | } | |
3e884cbf | 10968 | while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_')) |
f333445c JP |
10969 | pos++; |
10970 | } | |
10971 | SvPOK_on(sv); | |
10972 | sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start); | |
10973 | SvRMAGICAL_on(sv); | |
10974 | } | |
73d840c0 | 10975 | return (char *)s; |
f333445c JP |
10976 | } |
10977 |