3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, by Larry Wall and others
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.
12 * "It all comes from here, the stench and the peril." --Frodo
16 * This file is the lexer for Perl. It's closely linked to the
19 * The main routine is yylex(), which returns the next token.
23 #define PERL_IN_TOKE_C
26 #define yychar (*PL_yycharp)
27 #define yylval (*PL_yylvalp)
29 static const char ident_too_long[] = "Identifier too long";
30 static const char commaless_variable_list[] = "comma-less variable list";
32 static void restore_rsfp(pTHX_ void *f);
33 #ifndef PERL_NO_UTF16_FILTER
34 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
35 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
39 # define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
40 # define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
42 # define CURMAD(slot,sv)
43 # define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
46 #define XFAKEBRACK 128
49 #ifdef USE_UTF8_SCRIPTS
50 # define UTF (!IN_BYTES)
52 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
55 /* In variables named $^X, these are the legal values for X.
56 * 1999-02-27 mjd-perl-patch@plover.com */
57 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
59 /* On MacOS, respect nonbreaking spaces */
60 #ifdef MACOS_TRADITIONAL
61 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
63 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
66 /* LEX_* are values for PL_lex_state, the state of the lexer.
67 * They are arranged oddly so that the guard on the switch statement
68 * can get by with a single comparison (if the compiler is smart enough).
71 /* #define LEX_NOTPARSING 11 is done in perl.h. */
73 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
74 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
75 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
76 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
77 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
79 /* at end of code, eg "$x" followed by: */
80 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
81 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
83 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
84 string or after \E, $foo, etc */
85 #define LEX_INTERPCONST 2 /* NOT USED */
86 #define LEX_FORMLINE 1 /* expecting a format line */
87 #define LEX_KNOWNEXT 0 /* next token known; just return it */
91 static const char* const lex_state_names[] = {
110 #include "keywords.h"
112 /* CLINE is a macro that ensures PL_copline has a sane value */
117 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
120 # define SKIPSPACE0(s) skipspace0(s)
121 # define SKIPSPACE1(s) skipspace1(s)
122 # define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
123 # define PEEKSPACE(s) skipspace2(s,0)
125 # define SKIPSPACE0(s) skipspace(s)
126 # define SKIPSPACE1(s) skipspace(s)
127 # define SKIPSPACE2(s,tsv) skipspace(s)
128 # define PEEKSPACE(s) skipspace(s)
132 * Convenience functions to return different tokens and prime the
133 * lexer for the next token. They all take an argument.
135 * TOKEN : generic token (used for '(', DOLSHARP, etc)
136 * OPERATOR : generic operator
137 * AOPERATOR : assignment operator
138 * PREBLOCK : beginning the block after an if, while, foreach, ...
139 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
140 * PREREF : *EXPR where EXPR is not a simple identifier
141 * TERM : expression term
142 * LOOPX : loop exiting command (goto, last, dump, etc)
143 * FTST : file test operator
144 * FUN0 : zero-argument function
145 * FUN1 : not used, except for not, which isn't a UNIOP
146 * BOop : bitwise or or xor
148 * SHop : shift operator
149 * PWop : power operator
150 * PMop : pattern-matching operator
151 * Aop : addition-level operator
152 * Mop : multiplication-level operator
153 * Eop : equality-testing operator
154 * Rop : relational operator <= != gt
156 * Also see LOP and lop() below.
159 #ifdef DEBUGGING /* Serve -DT. */
160 # define REPORT(retval) tokereport((I32)retval)
162 # define REPORT(retval) (retval)
165 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
166 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
167 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
168 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
169 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
170 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
171 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
172 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
173 #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
174 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
175 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
176 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
177 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
178 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
179 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
180 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
181 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
182 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
183 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
184 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
186 /* This bit of chicanery makes a unary function followed by
187 * a parenthesis into a function with one argument, highest precedence.
188 * The UNIDOR macro is for unary functions that can be followed by the //
189 * operator (such as C<shift // 0>).
191 #define UNI2(f,x) { \
195 PL_last_uni = PL_oldbufptr; \
196 PL_last_lop_op = f; \
198 return REPORT( (int)FUNC1 ); \
200 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
202 #define UNI(f) UNI2(f,XTERM)
203 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
205 #define UNIBRACK(f) { \
208 PL_last_uni = PL_oldbufptr; \
210 return REPORT( (int)FUNC1 ); \
212 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
215 /* grandfather return to old style */
216 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
220 /* how to interpret the yylval associated with the token */
224 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
230 static struct debug_tokens {
232 enum token_type type;
234 } const debug_tokens[] =
236 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
237 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
238 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
239 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
240 { ARROW, TOKENTYPE_NONE, "ARROW" },
241 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
242 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
243 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
244 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
245 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
246 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
247 { DO, TOKENTYPE_NONE, "DO" },
248 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
249 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
250 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
251 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
252 { ELSE, TOKENTYPE_NONE, "ELSE" },
253 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
254 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
255 { FOR, TOKENTYPE_IVAL, "FOR" },
256 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
257 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
258 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
259 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
260 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
261 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
262 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
263 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
264 { IF, TOKENTYPE_IVAL, "IF" },
265 { LABEL, TOKENTYPE_PVAL, "LABEL" },
266 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
267 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
268 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
269 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
270 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
271 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
272 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
273 { MY, TOKENTYPE_IVAL, "MY" },
274 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
275 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
276 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
277 { OROP, TOKENTYPE_IVAL, "OROP" },
278 { OROR, TOKENTYPE_NONE, "OROR" },
279 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
280 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
281 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
282 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
283 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
284 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
285 { PREINC, TOKENTYPE_NONE, "PREINC" },
286 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
287 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
288 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
289 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
290 { SUB, TOKENTYPE_NONE, "SUB" },
291 { THING, TOKENTYPE_OPVAL, "THING" },
292 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
293 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
294 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
295 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
296 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
297 { USE, TOKENTYPE_IVAL, "USE" },
298 { WHEN, TOKENTYPE_IVAL, "WHEN" },
299 { WHILE, TOKENTYPE_IVAL, "WHILE" },
300 { WORD, TOKENTYPE_OPVAL, "WORD" },
301 { 0, TOKENTYPE_NONE, NULL }
304 /* dump the returned token in rv, plus any optional arg in yylval */
307 S_tokereport(pTHX_ I32 rv)
311 const char *name = NULL;
312 enum token_type type = TOKENTYPE_NONE;
313 const struct debug_tokens *p;
314 SV* const report = newSVpvs("<== ");
316 for (p = debug_tokens; p->token; p++) {
317 if (p->token == (int)rv) {
324 Perl_sv_catpv(aTHX_ report, name);
325 else if ((char)rv > ' ' && (char)rv < '~')
326 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
328 sv_catpvs(report, "EOF");
330 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
333 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
336 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
338 case TOKENTYPE_OPNUM:
339 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
340 PL_op_name[yylval.ival]);
343 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
345 case TOKENTYPE_OPVAL:
347 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
348 PL_op_name[yylval.opval->op_type]);
349 if (yylval.opval->op_type == OP_CONST) {
350 Perl_sv_catpvf(aTHX_ report, " %s",
351 SvPEEK(cSVOPx_sv(yylval.opval)));
356 sv_catpvs(report, "(opval=null)");
359 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
365 /* print the buffer with suitable escapes */
368 S_printbuf(pTHX_ const char* fmt, const char* s)
370 SV* const tmp = newSVpvs("");
371 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
380 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
381 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
385 S_ao(pTHX_ int toketype)
388 if (*PL_bufptr == '=') {
390 if (toketype == ANDAND)
391 yylval.ival = OP_ANDASSIGN;
392 else if (toketype == OROR)
393 yylval.ival = OP_ORASSIGN;
394 else if (toketype == DORDOR)
395 yylval.ival = OP_DORASSIGN;
403 * When Perl expects an operator and finds something else, no_op
404 * prints the warning. It always prints "<something> found where
405 * operator expected. It prints "Missing semicolon on previous line?"
406 * if the surprise occurs at the start of the line. "do you need to
407 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
408 * where the compiler doesn't know if foo is a method call or a function.
409 * It prints "Missing operator before end of line" if there's nothing
410 * after the missing operator, or "... before <...>" if there is something
411 * after the missing operator.
415 S_no_op(pTHX_ const char *what, char *s)
418 char * const oldbp = PL_bufptr;
419 const bool is_first = (PL_oldbufptr == PL_linestart);
425 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
426 if (ckWARN_d(WARN_SYNTAX)) {
428 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
429 "\t(Missing semicolon on previous line?)\n");
430 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
432 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
434 if (t < PL_bufptr && isSPACE(*t))
435 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
436 "\t(Do you need to predeclare %.*s?)\n",
437 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
441 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
442 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
450 * Complain about missing quote/regexp/heredoc terminator.
451 * If it's called with NULL then it cauterizes the line buffer.
452 * If we're in a delimited string and the delimiter is a control
453 * character, it's reformatted into a two-char sequence like ^C.
458 S_missingterm(pTHX_ char *s)
464 char * const nl = strrchr(s,'\n');
470 iscntrl(PL_multi_close)
472 PL_multi_close < 32 || PL_multi_close == 127
476 tmpbuf[1] = (char)toCTRL(PL_multi_close);
481 *tmpbuf = (char)PL_multi_close;
485 q = strchr(s,'"') ? '\'' : '"';
486 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
489 #define FEATURE_IS_ENABLED(name) \
490 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
491 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
493 * S_feature_is_enabled
494 * Check whether the named feature is enabled.
497 S_feature_is_enabled(pTHX_ const char *name, STRLEN namelen)
500 HV * const hinthv = GvHV(PL_hintgv);
501 char he_name[32] = "feature_";
502 (void) strncpy(&he_name[8], name, 24);
504 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
512 Perl_deprecate(pTHX_ const char *s)
514 if (ckWARN(WARN_DEPRECATED))
515 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
519 Perl_deprecate_old(pTHX_ const char *s)
521 /* This function should NOT be called for any new deprecated warnings */
522 /* Use Perl_deprecate instead */
524 /* It is here to maintain backward compatibility with the pre-5.8 */
525 /* warnings category hierarchy. The "deprecated" category used to */
526 /* live under the "syntax" category. It is now a top-level category */
527 /* in its own right. */
529 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
530 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
531 "Use of %s is deprecated", s);
535 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
536 * utf16-to-utf8-reversed.
539 #ifdef PERL_CR_FILTER
543 register const char *s = SvPVX_const(sv);
544 register const char * const e = s + SvCUR(sv);
545 /* outer loop optimized to do nothing if there are no CR-LFs */
547 if (*s++ == '\r' && *s == '\n') {
548 /* hit a CR-LF, need to copy the rest */
549 register char *d = s - 1;
552 if (*s == '\r' && s[1] == '\n')
563 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
565 const I32 count = FILTER_READ(idx+1, sv, maxlen);
566 if (count > 0 && !maxlen)
574 * Initialize variables. Uses the Perl save_stack to save its state (for
575 * recursive calls to the parser).
579 Perl_lex_start(pTHX_ SV *line)
585 SAVEI32(PL_lex_dojoin);
586 SAVEI32(PL_lex_brackets);
587 SAVEI32(PL_lex_casemods);
588 SAVEI32(PL_lex_starts);
589 SAVEI32(PL_lex_state);
590 SAVEVPTR(PL_lex_inpat);
591 SAVEI32(PL_lex_inwhat);
593 if (PL_lex_state == LEX_KNOWNEXT) {
594 I32 toke = PL_lasttoke;
595 while (--toke >= 0) {
596 SAVEI32(PL_nexttoke[toke].next_type);
597 SAVEVPTR(PL_nexttoke[toke].next_val);
599 SAVEVPTR(PL_nexttoke[toke].next_mad);
601 SAVEI32(PL_lasttoke);
604 SAVESPTR(PL_thistoken);
605 SAVESPTR(PL_thiswhite);
606 SAVESPTR(PL_nextwhite);
607 SAVESPTR(PL_thisopen);
608 SAVESPTR(PL_thisclose);
609 SAVESPTR(PL_thisstuff);
610 SAVEVPTR(PL_thismad);
611 SAVEI32(PL_realtokenstart);
612 SAVEI32(PL_faketokens);
614 SAVEI32(PL_curforce);
616 if (PL_lex_state == LEX_KNOWNEXT) {
617 I32 toke = PL_nexttoke;
618 while (--toke >= 0) {
619 SAVEI32(PL_nexttype[toke]);
620 SAVEVPTR(PL_nextval[toke]);
622 SAVEI32(PL_nexttoke);
625 SAVECOPLINE(PL_curcop);
628 SAVEPPTR(PL_oldbufptr);
629 SAVEPPTR(PL_oldoldbufptr);
630 SAVEPPTR(PL_last_lop);
631 SAVEPPTR(PL_last_uni);
632 SAVEPPTR(PL_linestart);
633 SAVESPTR(PL_linestr);
634 SAVEGENERICPV(PL_lex_brackstack);
635 SAVEGENERICPV(PL_lex_casestack);
636 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
637 SAVESPTR(PL_lex_stuff);
638 SAVEI32(PL_lex_defer);
639 SAVEI32(PL_sublex_info.sub_inwhat);
640 SAVESPTR(PL_lex_repl);
642 SAVEINT(PL_lex_expect);
644 PL_lex_state = LEX_NORMAL;
648 Newx(PL_lex_brackstack, 120, char);
649 Newx(PL_lex_casestack, 12, char);
651 *PL_lex_casestack = '\0';
663 PL_sublex_info.sub_inwhat = 0;
665 if (SvREADONLY(PL_linestr))
666 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
667 s = SvPV_const(PL_linestr, len);
668 if (!len || s[len-1] != ';') {
669 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
670 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
671 sv_catpvs(PL_linestr, "\n;");
673 SvTEMP_off(PL_linestr);
674 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
675 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
676 PL_last_lop = PL_last_uni = NULL;
682 * Finalizer for lexing operations. Must be called when the parser is
683 * done with the lexer.
690 PL_doextract = FALSE;
695 * This subroutine has nothing to do with tilting, whether at windmills
696 * or pinball tables. Its name is short for "increment line". It
697 * increments the current line number in CopLINE(PL_curcop) and checks
698 * to see whether the line starts with a comment of the form
699 * # line 500 "foo.pm"
700 * If so, it sets the current line number and file to the values in the comment.
704 S_incline(pTHX_ char *s)
712 CopLINE_inc(PL_curcop);
715 while (SPACE_OR_TAB(*s))
717 if (strnEQ(s, "line", 4))
721 if (SPACE_OR_TAB(*s))
725 while (SPACE_OR_TAB(*s))
733 while (SPACE_OR_TAB(*s))
735 if (*s == '"' && (t = strchr(s+1, '"'))) {
745 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
747 if (*e != '\n' && *e != '\0')
748 return; /* false alarm */
754 const char * const cf = CopFILE(PL_curcop);
755 STRLEN tmplen = cf ? strlen(cf) : 0;
756 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
757 /* must copy *{"::_<(eval N)[oldfilename:L]"}
758 * to *{"::_<newfilename"} */
759 char smallbuf[256], smallbuf2[256];
760 char *tmpbuf, *tmpbuf2;
762 STRLEN tmplen2 = strlen(s);
763 if (tmplen + 3 < sizeof smallbuf)
766 Newx(tmpbuf, tmplen + 3, char);
767 if (tmplen2 + 3 < sizeof smallbuf2)
770 Newx(tmpbuf2, tmplen2 + 3, char);
771 tmpbuf[0] = tmpbuf2[0] = '_';
772 tmpbuf[1] = tmpbuf2[1] = '<';
773 memcpy(tmpbuf + 2, cf, ++tmplen);
774 memcpy(tmpbuf2 + 2, s, ++tmplen2);
776 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
778 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
780 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
781 /* adjust ${"::_<newfilename"} to store the new file name */
782 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
783 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
784 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
786 if (tmpbuf != smallbuf) Safefree(tmpbuf);
787 if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
790 CopFILE_free(PL_curcop);
791 CopFILE_set(PL_curcop, s);
794 CopLINE_set(PL_curcop, atoi(n)-1);
798 /* skip space before PL_thistoken */
801 S_skipspace0(pTHX_ register char *s)
808 PL_thiswhite = newSVpvn("",0);
809 sv_catsv(PL_thiswhite, PL_skipwhite);
810 sv_free(PL_skipwhite);
813 PL_realtokenstart = s - SvPVX(PL_linestr);
817 /* skip space after PL_thistoken */
820 S_skipspace1(pTHX_ register char *s)
822 const char *start = s;
823 I32 startoff = start - SvPVX(PL_linestr);
828 start = SvPVX(PL_linestr) + startoff;
829 if (!PL_thistoken && PL_realtokenstart >= 0) {
830 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
831 PL_thistoken = newSVpvn(tstart, start - tstart);
833 PL_realtokenstart = -1;
836 PL_nextwhite = newSVpvn("",0);
837 sv_catsv(PL_nextwhite, PL_skipwhite);
838 sv_free(PL_skipwhite);
845 S_skipspace2(pTHX_ register char *s, SV **svp)
848 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
849 const I32 startoff = s - SvPVX(PL_linestr);
852 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
853 if (!PL_madskills || !svp)
855 start = SvPVX(PL_linestr) + startoff;
856 if (!PL_thistoken && PL_realtokenstart >= 0) {
857 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
858 PL_thistoken = newSVpvn(tstart, start - tstart);
859 PL_realtokenstart = -1;
863 *svp = newSVpvn("",0);
864 sv_setsv(*svp, PL_skipwhite);
865 sv_free(PL_skipwhite);
875 * Called to gobble the appropriate amount and type of whitespace.
876 * Skips comments as well.
880 S_skipspace(pTHX_ register char *s)
885 int startoff = s - SvPVX(PL_linestr);
888 sv_free(PL_skipwhite);
893 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
894 while (s < PL_bufend && SPACE_OR_TAB(*s))
904 SSize_t oldprevlen, oldoldprevlen;
905 SSize_t oldloplen = 0, oldunilen = 0;
906 while (s < PL_bufend && isSPACE(*s)) {
907 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
912 if (s < PL_bufend && *s == '#') {
913 while (s < PL_bufend && *s != '\n')
917 if (PL_in_eval && !PL_rsfp) {
924 /* only continue to recharge the buffer if we're at the end
925 * of the buffer, we're not reading from a source filter, and
926 * we're in normal lexing mode
928 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
929 PL_lex_state == LEX_FORMLINE)
936 /* try to recharge the buffer */
938 curoff = s - SvPVX(PL_linestr);
941 if ((s = filter_gets(PL_linestr, PL_rsfp,
942 (prevlen = SvCUR(PL_linestr)))) == NULL)
945 if (PL_madskills && curoff != startoff) {
947 PL_skipwhite = newSVpvn("",0);
948 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
952 /* mustn't throw out old stuff yet if madpropping */
953 SvCUR(PL_linestr) = curoff;
954 s = SvPVX(PL_linestr) + curoff;
956 if (curoff && s[-1] == '\n')
960 /* end of file. Add on the -p or -n magic */
961 /* XXX these shouldn't really be added here, can't set PL_faketokens */
965 ";}continue{print or die qq(-p destination: $!\\n);}");
968 ";}continue{print or die qq(-p destination: $!\\n);}");
970 PL_minus_n = PL_minus_p = 0;
972 else if (PL_minus_n) {
974 sv_catpvn(PL_linestr, ";}", 2);
976 sv_setpvn(PL_linestr, ";}", 2);
982 sv_catpvn(PL_linestr,";", 1);
984 sv_setpvn(PL_linestr,";", 1);
987 /* reset variables for next time we lex */
988 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
994 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
995 PL_last_lop = PL_last_uni = NULL;
997 /* Close the filehandle. Could be from -P preprocessor,
998 * STDIN, or a regular file. If we were reading code from
999 * STDIN (because the commandline held no -e or filename)
1000 * then we don't close it, we reset it so the code can
1001 * read from STDIN too.
1004 if (PL_preprocess && !PL_in_eval)
1005 (void)PerlProc_pclose(PL_rsfp);
1006 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1007 PerlIO_clearerr(PL_rsfp);
1009 (void)PerlIO_close(PL_rsfp);
1014 /* not at end of file, so we only read another line */
1015 /* make corresponding updates to old pointers, for yyerror() */
1016 oldprevlen = PL_oldbufptr - PL_bufend;
1017 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1019 oldunilen = PL_last_uni - PL_bufend;
1021 oldloplen = PL_last_lop - PL_bufend;
1022 PL_linestart = PL_bufptr = s + prevlen;
1023 PL_bufend = s + SvCUR(PL_linestr);
1025 PL_oldbufptr = s + oldprevlen;
1026 PL_oldoldbufptr = s + oldoldprevlen;
1028 PL_last_uni = s + oldunilen;
1030 PL_last_lop = s + oldloplen;
1033 /* debugger active and we're not compiling the debugger code,
1034 * so store the line into the debugger's array of lines
1036 if (PERLDB_LINE && PL_curstash != PL_debstash) {
1037 SV * const sv = newSV(0);
1039 sv_upgrade(sv, SVt_PVMG);
1040 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
1043 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
1051 PL_skipwhite = newSVpvn("",0);
1052 curoff = s - SvPVX(PL_linestr);
1053 if (curoff - startoff)
1054 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1063 * Check the unary operators to ensure there's no ambiguity in how they're
1064 * used. An ambiguous piece of code would be:
1066 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1067 * the +5 is its argument.
1077 if (PL_oldoldbufptr != PL_last_uni)
1079 while (isSPACE(*PL_last_uni))
1082 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1084 if ((t = strchr(s, '(')) && t < PL_bufptr)
1087 if (ckWARN_d(WARN_AMBIGUOUS)){
1088 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1089 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1090 (int)(s - PL_last_uni), PL_last_uni);
1095 * LOP : macro to build a list operator. Its behaviour has been replaced
1096 * with a subroutine, S_lop() for which LOP is just another name.
1099 #define LOP(f,x) return lop(f,x,s)
1103 * Build a list operator (or something that might be one). The rules:
1104 * - if we have a next token, then it's a list operator [why?]
1105 * - if the next thing is an opening paren, then it's a function
1106 * - else it's a list operator
1110 S_lop(pTHX_ I32 f, int x, char *s)
1117 PL_last_lop = PL_oldbufptr;
1118 PL_last_lop_op = (OPCODE)f;
1121 return REPORT(LSTOP);
1124 return REPORT(LSTOP);
1127 return REPORT(FUNC);
1130 return REPORT(FUNC);
1132 return REPORT(LSTOP);
1138 * Sets up for an eventual force_next(). start_force(0) basically does
1139 * an unshift, while start_force(-1) does a push. yylex removes items
1144 S_start_force(pTHX_ int where)
1148 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1149 where = PL_lasttoke;
1150 assert(PL_curforce < 0 || PL_curforce == where);
1151 if (PL_curforce != where) {
1152 for (i = PL_lasttoke; i > where; --i) {
1153 PL_nexttoke[i] = PL_nexttoke[i-1];
1157 if (PL_curforce < 0) /* in case of duplicate start_force() */
1158 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1159 PL_curforce = where;
1162 curmad('^', newSVpvn("",0));
1163 CURMAD('_', PL_nextwhite);
1168 S_curmad(pTHX_ char slot, SV *sv)
1174 if (PL_curforce < 0)
1175 where = &PL_thismad;
1177 where = &PL_nexttoke[PL_curforce].next_mad;
1180 sv_setpvn(sv, "", 0);
1183 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1185 else if (PL_encoding) {
1186 sv_recode_to_utf8(sv, PL_encoding);
1191 /* keep a slot open for the head of the list? */
1192 if (slot != '_' && *where && (*where)->mad_key == '^') {
1193 (*where)->mad_key = slot;
1194 sv_free((*where)->mad_val);
1195 (*where)->mad_val = (void*)sv;
1198 addmad(newMADsv(slot, sv), where, 0);
1201 # define start_force(where) NOOP
1202 # define curmad(slot, sv) NOOP
1207 * When the lexer realizes it knows the next token (for instance,
1208 * it is reordering tokens for the parser) then it can call S_force_next
1209 * to know what token to return the next time the lexer is called. Caller
1210 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1211 * and possibly PL_expect to ensure the lexer handles the token correctly.
1215 S_force_next(pTHX_ I32 type)
1219 if (PL_curforce < 0)
1220 start_force(PL_lasttoke);
1221 PL_nexttoke[PL_curforce].next_type = type;
1222 if (PL_lex_state != LEX_KNOWNEXT)
1223 PL_lex_defer = PL_lex_state;
1224 PL_lex_state = LEX_KNOWNEXT;
1225 PL_lex_expect = PL_expect;
1228 PL_nexttype[PL_nexttoke] = type;
1230 if (PL_lex_state != LEX_KNOWNEXT) {
1231 PL_lex_defer = PL_lex_state;
1232 PL_lex_expect = PL_expect;
1233 PL_lex_state = LEX_KNOWNEXT;
1239 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1242 SV * const sv = newSVpvn(start,len);
1243 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
1250 * When the lexer knows the next thing is a word (for instance, it has
1251 * just seen -> and it knows that the next char is a word char, then
1252 * it calls S_force_word to stick the next word into the PL_next lookahead.
1255 * char *start : buffer position (must be within PL_linestr)
1256 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
1257 * int check_keyword : if true, Perl checks to make sure the word isn't
1258 * a keyword (do this if the word is a label, e.g. goto FOO)
1259 * int allow_pack : if true, : characters will also be allowed (require,
1260 * use, etc. do this)
1261 * int allow_initial_tick : used by the "sub" lexer only.
1265 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1271 start = SKIPSPACE1(start);
1273 if (isIDFIRST_lazy_if(s,UTF) ||
1274 (allow_pack && *s == ':') ||
1275 (allow_initial_tick && *s == '\'') )
1277 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1278 if (check_keyword && keyword(PL_tokenbuf, len))
1280 start_force(PL_curforce);
1282 curmad('X', newSVpvn(start,s-start));
1283 if (token == METHOD) {
1288 PL_expect = XOPERATOR;
1291 NEXTVAL_NEXTTOKE.opval
1292 = (OP*)newSVOP(OP_CONST,0,
1293 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1294 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1302 * Called when the lexer wants $foo *foo &foo etc, but the program
1303 * text only contains the "foo" portion. The first argument is a pointer
1304 * to the "foo", and the second argument is the type symbol to prefix.
1305 * Forces the next token to be a "WORD".
1306 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1310 S_force_ident(pTHX_ register const char *s, int kind)
1314 const STRLEN len = strlen(s);
1315 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1316 start_force(PL_curforce);
1317 NEXTVAL_NEXTTOKE.opval = o;
1320 o->op_private = OPpCONST_ENTERED;
1321 /* XXX see note in pp_entereval() for why we forgo typo
1322 warnings if the symbol must be introduced in an eval.
1324 gv_fetchpvn_flags(s, len,
1325 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1327 kind == '$' ? SVt_PV :
1328 kind == '@' ? SVt_PVAV :
1329 kind == '%' ? SVt_PVHV :
1337 Perl_str_to_version(pTHX_ SV *sv)
1342 const char *start = SvPV_const(sv,len);
1343 const char * const end = start + len;
1344 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1345 while (start < end) {
1349 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1354 retval += ((NV)n)/nshift;
1363 * Forces the next token to be a version number.
1364 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1365 * and if "guessing" is TRUE, then no new token is created (and the caller
1366 * must use an alternative parsing method).
1370 S_force_version(pTHX_ char *s, int guessing)
1376 I32 startoff = s - SvPVX(PL_linestr);
1385 while (isDIGIT(*d) || *d == '_' || *d == '.')
1389 start_force(PL_curforce);
1390 curmad('X', newSVpvn(s,d-s));
1393 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1395 s = scan_num(s, &yylval);
1396 version = yylval.opval;
1397 ver = cSVOPx(version)->op_sv;
1398 if (SvPOK(ver) && !SvNIOK(ver)) {
1399 SvUPGRADE(ver, SVt_PVNV);
1400 SvNV_set(ver, str_to_version(ver));
1401 SvNOK_on(ver); /* hint that it is a version */
1404 else if (guessing) {
1407 sv_free(PL_nextwhite); /* let next token collect whitespace */
1409 s = SvPVX(PL_linestr) + startoff;
1417 if (PL_madskills && !version) {
1418 sv_free(PL_nextwhite); /* let next token collect whitespace */
1420 s = SvPVX(PL_linestr) + startoff;
1423 /* NOTE: The parser sees the package name and the VERSION swapped */
1424 start_force(PL_curforce);
1425 NEXTVAL_NEXTTOKE.opval = version;
1433 * Tokenize a quoted string passed in as an SV. It finds the next
1434 * chunk, up to end of string or a backslash. It may make a new
1435 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1440 S_tokeq(pTHX_ SV *sv)
1444 register char *send;
1452 s = SvPV_force(sv, len);
1453 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1456 while (s < send && *s != '\\')
1461 if ( PL_hints & HINT_NEW_STRING ) {
1462 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1468 if (s + 1 < send && (s[1] == '\\'))
1469 s++; /* all that, just for this */
1474 SvCUR_set(sv, d - SvPVX_const(sv));
1476 if ( PL_hints & HINT_NEW_STRING )
1477 return new_constant(NULL, 0, "q", sv, pv, "q");
1482 * Now come three functions related to double-quote context,
1483 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1484 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1485 * interact with PL_lex_state, and create fake ( ... ) argument lists
1486 * to handle functions and concatenation.
1487 * They assume that whoever calls them will be setting up a fake
1488 * join call, because each subthing puts a ',' after it. This lets
1491 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1493 * (I'm not sure whether the spurious commas at the end of lcfirst's
1494 * arguments and join's arguments are created or not).
1499 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1501 * Pattern matching will set PL_lex_op to the pattern-matching op to
1502 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1504 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1506 * Everything else becomes a FUNC.
1508 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1509 * had an OP_CONST or OP_READLINE). This just sets us up for a
1510 * call to S_sublex_push().
1514 S_sublex_start(pTHX)
1517 register const I32 op_type = yylval.ival;
1519 if (op_type == OP_NULL) {
1520 yylval.opval = PL_lex_op;
1524 if (op_type == OP_CONST || op_type == OP_READLINE) {
1525 SV *sv = tokeq(PL_lex_stuff);
1527 if (SvTYPE(sv) == SVt_PVIV) {
1528 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1530 const char * const p = SvPV_const(sv, len);
1531 SV * const nsv = newSVpvn(p, len);
1537 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1538 PL_lex_stuff = NULL;
1539 /* Allow <FH> // "foo" */
1540 if (op_type == OP_READLINE)
1541 PL_expect = XTERMORDORDOR;
1545 PL_sublex_info.super_state = PL_lex_state;
1546 PL_sublex_info.sub_inwhat = op_type;
1547 PL_sublex_info.sub_op = PL_lex_op;
1548 PL_lex_state = LEX_INTERPPUSH;
1552 yylval.opval = PL_lex_op;
1562 * Create a new scope to save the lexing state. The scope will be
1563 * ended in S_sublex_done. Returns a '(', starting the function arguments
1564 * to the uc, lc, etc. found before.
1565 * Sets PL_lex_state to LEX_INTERPCONCAT.
1574 PL_lex_state = PL_sublex_info.super_state;
1575 SAVEI32(PL_lex_dojoin);
1576 SAVEI32(PL_lex_brackets);
1577 SAVEI32(PL_lex_casemods);
1578 SAVEI32(PL_lex_starts);
1579 SAVEI32(PL_lex_state);
1580 SAVEVPTR(PL_lex_inpat);
1581 SAVEI32(PL_lex_inwhat);
1582 SAVECOPLINE(PL_curcop);
1583 SAVEPPTR(PL_bufptr);
1584 SAVEPPTR(PL_bufend);
1585 SAVEPPTR(PL_oldbufptr);
1586 SAVEPPTR(PL_oldoldbufptr);
1587 SAVEPPTR(PL_last_lop);
1588 SAVEPPTR(PL_last_uni);
1589 SAVEPPTR(PL_linestart);
1590 SAVESPTR(PL_linestr);
1591 SAVEGENERICPV(PL_lex_brackstack);
1592 SAVEGENERICPV(PL_lex_casestack);
1594 PL_linestr = PL_lex_stuff;
1595 PL_lex_stuff = NULL;
1597 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1598 = SvPVX(PL_linestr);
1599 PL_bufend += SvCUR(PL_linestr);
1600 PL_last_lop = PL_last_uni = NULL;
1601 SAVEFREESV(PL_linestr);
1603 PL_lex_dojoin = FALSE;
1604 PL_lex_brackets = 0;
1605 Newx(PL_lex_brackstack, 120, char);
1606 Newx(PL_lex_casestack, 12, char);
1607 PL_lex_casemods = 0;
1608 *PL_lex_casestack = '\0';
1610 PL_lex_state = LEX_INTERPCONCAT;
1611 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1613 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1614 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1615 PL_lex_inpat = PL_sublex_info.sub_op;
1617 PL_lex_inpat = NULL;
1624 * Restores lexer state after a S_sublex_push.
1631 if (!PL_lex_starts++) {
1632 SV * const sv = newSVpvs("");
1633 if (SvUTF8(PL_linestr))
1635 PL_expect = XOPERATOR;
1636 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1640 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1641 PL_lex_state = LEX_INTERPCASEMOD;
1645 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1646 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1647 PL_linestr = PL_lex_repl;
1649 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1650 PL_bufend += SvCUR(PL_linestr);
1651 PL_last_lop = PL_last_uni = NULL;
1652 SAVEFREESV(PL_linestr);
1653 PL_lex_dojoin = FALSE;
1654 PL_lex_brackets = 0;
1655 PL_lex_casemods = 0;
1656 *PL_lex_casestack = '\0';
1658 if (SvEVALED(PL_lex_repl)) {
1659 PL_lex_state = LEX_INTERPNORMAL;
1661 /* we don't clear PL_lex_repl here, so that we can check later
1662 whether this is an evalled subst; that means we rely on the
1663 logic to ensure sublex_done() is called again only via the
1664 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1667 PL_lex_state = LEX_INTERPCONCAT;
1677 PL_endwhite = newSVpvn("",0);
1678 sv_catsv(PL_endwhite, PL_thiswhite);
1682 sv_setpvn(PL_thistoken,"",0);
1684 PL_realtokenstart = -1;
1688 PL_bufend = SvPVX(PL_linestr);
1689 PL_bufend += SvCUR(PL_linestr);
1690 PL_expect = XOPERATOR;
1691 PL_sublex_info.sub_inwhat = 0;
1699 Extracts a pattern, double-quoted string, or transliteration. This
1702 It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1703 processing a pattern (PL_lex_inpat is true), a transliteration
1704 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1706 Returns a pointer to the character scanned up to. Iff this is
1707 advanced from the start pointer supplied (ie if anything was
1708 successfully parsed), will leave an OP for the substring scanned
1709 in yylval. Caller must intuit reason for not parsing further
1710 by looking at the next characters herself.
1714 double-quoted style: \r and \n
1715 regexp special ones: \D \s
1717 backrefs: \1 (deprecated in substitution replacements)
1718 case and quoting: \U \Q \E
1719 stops on @ and $, but not for $ as tail anchor
1721 In transliterations:
1722 characters are VERY literal, except for - not at the start or end
1723 of the string, which indicates a range. scan_const expands the
1724 range to the full set of intermediate characters.
1726 In double-quoted strings:
1728 double-quoted style: \r and \n
1730 backrefs: \1 (deprecated)
1731 case and quoting: \U \Q \E
1734 scan_const does *not* construct ops to handle interpolated strings.
1735 It stops processing as soon as it finds an embedded $ or @ variable
1736 and leaves it to the caller to work out what's going on.
1738 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo.
1740 $ in pattern could be $foo or could be tail anchor. Assumption:
1741 it's a tail anchor if $ is the last thing in the string, or if it's
1742 followed by one of ")| \n\t"
1744 \1 (backreferences) are turned into $1
1746 The structure of the code is
1747 while (there's a character to process) {
1748 handle transliteration ranges
1749 skip regexp comments
1750 skip # initiated comments in //x patterns
1751 check for embedded @foo
1752 check for embedded scalars
1754 leave intact backslashes from leave (below)
1755 deprecate \1 in strings and sub replacements
1756 handle string-changing backslashes \l \U \Q \E, etc.
1757 switch (what was escaped) {
1758 handle - in a transliteration (becomes a literal -)
1759 handle \132 octal characters
1760 handle 0x15 hex characters
1761 handle \cV (control V)
1762 handle printf backslashes (\f, \r, \n, etc)
1764 } (end if backslash)
1765 } (end while character to read)
1770 S_scan_const(pTHX_ char *start)
1773 register char *send = PL_bufend; /* end of the constant */
1774 SV *sv = newSV(send - start); /* sv for the constant */
1775 register char *s = start; /* start of the constant */
1776 register char *d = SvPVX(sv); /* destination for copies */
1777 bool dorange = FALSE; /* are we in a translit range? */
1778 bool didrange = FALSE; /* did we just finish a range? */
1779 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1780 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1783 UV literal_endpoint = 0;
1786 const char * const leaveit = /* set of acceptably-backslashed characters */
1788 ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#"
1791 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1792 /* If we are doing a trans and we know we want UTF8 set expectation */
1793 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1794 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1798 while (s < send || dorange) {
1799 /* get transliterations out of the way (they're most literal) */
1800 if (PL_lex_inwhat == OP_TRANS) {
1801 /* expand a range A-Z to the full set of characters. AIE! */
1803 I32 i; /* current expanded character */
1804 I32 min; /* first character in range */
1805 I32 max; /* last character in range */
1808 char * const c = (char*)utf8_hop((U8*)d, -1);
1812 *c = (char)UTF_TO_NATIVE(0xff);
1813 /* mark the range as done, and continue */
1819 i = d - SvPVX_const(sv); /* remember current offset */
1820 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1821 d = SvPVX(sv) + i; /* refresh d after realloc */
1822 d -= 2; /* eat the first char and the - */
1824 min = (U8)*d; /* first char in range */
1825 max = (U8)d[1]; /* last char in range */
1829 "Invalid range \"%c-%c\" in transliteration operator",
1830 (char)min, (char)max);
1834 if (literal_endpoint == 2 &&
1835 ((isLOWER(min) && isLOWER(max)) ||
1836 (isUPPER(min) && isUPPER(max)))) {
1838 for (i = min; i <= max; i++)
1840 *d++ = NATIVE_TO_NEED(has_utf8,i);
1842 for (i = min; i <= max; i++)
1844 *d++ = NATIVE_TO_NEED(has_utf8,i);
1849 for (i = min; i <= max; i++)
1852 /* mark the range as done, and continue */
1856 literal_endpoint = 0;
1861 /* range begins (ignore - as first or last char) */
1862 else if (*s == '-' && s+1 < send && s != start) {
1864 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1867 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1877 literal_endpoint = 0;
1882 /* if we get here, we're not doing a transliteration */
1884 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1885 except for the last char, which will be done separately. */
1886 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1888 while (s+1 < send && *s != ')')
1889 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1891 else if (s[2] == '{' /* This should match regcomp.c */
1892 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1895 char *regparse = s + (s[2] == '{' ? 3 : 4);
1898 while (count && (c = *regparse)) {
1899 if (c == '\\' && regparse[1])
1907 if (*regparse != ')')
1908 regparse--; /* Leave one char for continuation. */
1909 while (s < regparse)
1910 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1914 /* likewise skip #-initiated comments in //x patterns */
1915 else if (*s == '#' && PL_lex_inpat &&
1916 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1917 while (s+1 < send && *s != '\n')
1918 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1921 /* check for embedded arrays
1922 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
1924 else if (*s == '@' && s[1]
1925 && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1])))
1928 /* check for embedded scalars. only stop if we're sure it's a
1931 else if (*s == '$') {
1932 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
1934 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
1935 break; /* in regexp, $ might be tail anchor */
1938 /* End of else if chain - OP_TRANS rejoin rest */
1941 if (*s == '\\' && s+1 < send) {
1944 /* some backslashes we leave behind */
1945 if (*leaveit && *s && strchr(leaveit, *s)) {
1946 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
1947 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1951 /* deprecate \1 in strings and substitution replacements */
1952 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1953 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1955 if (ckWARN(WARN_SYNTAX))
1956 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
1961 /* string-change backslash escapes */
1962 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1967 /* if we get here, it's either a quoted -, or a digit */
1970 /* quoted - in transliterations */
1972 if (PL_lex_inwhat == OP_TRANS) {
1982 Perl_warner(aTHX_ packWARN(WARN_MISC),
1983 "Unrecognized escape \\%c passed through",
1985 /* default action is to copy the quoted character */
1986 goto default_action;
1989 /* \132 indicates an octal constant */
1990 case '0': case '1': case '2': case '3':
1991 case '4': case '5': case '6': case '7':
1995 uv = grok_oct(s, &len, &flags, NULL);
1998 goto NUM_ESCAPE_INSERT;
2000 /* \x24 indicates a hex constant */
2004 char* const e = strchr(s, '}');
2005 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2006 PERL_SCAN_DISALLOW_PREFIX;
2011 yyerror("Missing right brace on \\x{}");
2015 uv = grok_hex(s, &len, &flags, NULL);
2021 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2022 uv = grok_hex(s, &len, &flags, NULL);
2028 /* Insert oct or hex escaped character.
2029 * There will always enough room in sv since such
2030 * escapes will be longer than any UTF-8 sequence
2031 * they can end up as. */
2033 /* We need to map to chars to ASCII before doing the tests
2036 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2037 if (!has_utf8 && uv > 255) {
2038 /* Might need to recode whatever we have
2039 * accumulated so far if it contains any
2042 * (Can't we keep track of that and avoid
2043 * this rescan? --jhi)
2047 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2048 if (!NATIVE_IS_INVARIANT(*c)) {
2053 const STRLEN offset = d - SvPVX_const(sv);
2055 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2059 while (src >= (const U8 *)SvPVX_const(sv)) {
2060 if (!NATIVE_IS_INVARIANT(*src)) {
2061 const U8 ch = NATIVE_TO_ASCII(*src);
2062 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2063 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2073 if (has_utf8 || uv > 255) {
2074 d = (char*)uvchr_to_utf8((U8*)d, uv);
2076 if (PL_lex_inwhat == OP_TRANS &&
2077 PL_sublex_info.sub_op) {
2078 PL_sublex_info.sub_op->op_private |=
2079 (PL_lex_repl ? OPpTRANS_FROM_UTF
2092 /* \N{LATIN SMALL LETTER A} is a named character */
2096 char* e = strchr(s, '}');
2102 yyerror("Missing right brace on \\N{}");
2106 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2108 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2109 PERL_SCAN_DISALLOW_PREFIX;
2112 uv = grok_hex(s, &len, &flags, NULL);
2114 goto NUM_ESCAPE_INSERT;
2116 res = newSVpvn(s + 1, e - s - 1);
2117 res = new_constant( NULL, 0, "charnames",
2118 res, NULL, "\\N{...}" );
2120 sv_utf8_upgrade(res);
2121 str = SvPV_const(res,len);
2122 #ifdef EBCDIC_NEVER_MIND
2123 /* charnames uses pack U and that has been
2124 * recently changed to do the below uni->native
2125 * mapping, so this would be redundant (and wrong,
2126 * the code point would be doubly converted).
2127 * But leave this in just in case the pack U change
2128 * gets revoked, but the semantics is still
2129 * desireable for charnames. --jhi */
2131 UV uv = utf8_to_uvchr((const U8*)str, 0);
2134 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2136 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2137 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2138 str = SvPV_const(res, len);
2142 if (!has_utf8 && SvUTF8(res)) {
2143 const char * const ostart = SvPVX_const(sv);
2144 SvCUR_set(sv, d - ostart);
2147 sv_utf8_upgrade(sv);
2148 /* this just broke our allocation above... */
2149 SvGROW(sv, (STRLEN)(send - start));
2150 d = SvPVX(sv) + SvCUR(sv);
2153 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2154 const char * const odest = SvPVX_const(sv);
2156 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2157 d = SvPVX(sv) + (d - odest);
2159 Copy(str, d, len, char);
2166 yyerror("Missing braces on \\N{}");
2169 /* \c is a control character */
2178 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2181 yyerror("Missing control char name in \\c");
2185 /* printf-style backslashes, formfeeds, newlines, etc */
2187 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2190 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2193 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2196 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2199 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2202 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2205 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2211 } /* end if (backslash) */
2218 /* If we started with encoded form, or already know we want it
2219 and then encode the next character */
2220 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2222 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2223 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2226 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2227 const STRLEN off = d - SvPVX_const(sv);
2228 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2230 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2234 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2236 } /* while loop to process each character */
2238 /* terminate the string and set up the sv */
2240 SvCUR_set(sv, d - SvPVX_const(sv));
2241 if (SvCUR(sv) >= SvLEN(sv))
2242 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2245 if (PL_encoding && !has_utf8) {
2246 sv_recode_to_utf8(sv, PL_encoding);
2252 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2253 PL_sublex_info.sub_op->op_private |=
2254 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2258 /* shrink the sv if we allocated more than we used */
2259 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2260 SvPV_shrink_to_cur(sv);
2263 /* return the substring (via yylval) only if we parsed anything */
2264 if (s > PL_bufptr) {
2265 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
2266 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
2268 ( PL_lex_inwhat == OP_TRANS
2270 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2273 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2280 * Returns TRUE if there's more to the expression (e.g., a subscript),
2283 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2285 * ->[ and ->{ return TRUE
2286 * { and [ outside a pattern are always subscripts, so return TRUE
2287 * if we're outside a pattern and it's not { or [, then return FALSE
2288 * if we're in a pattern and the first char is a {
2289 * {4,5} (any digits around the comma) returns FALSE
2290 * if we're in a pattern and the first char is a [
2292 * [SOMETHING] has a funky algorithm to decide whether it's a
2293 * character class or not. It has to deal with things like
2294 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2295 * anything else returns TRUE
2298 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2301 S_intuit_more(pTHX_ register char *s)
2304 if (PL_lex_brackets)
2306 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2308 if (*s != '{' && *s != '[')
2313 /* In a pattern, so maybe we have {n,m}. */
2330 /* On the other hand, maybe we have a character class */
2333 if (*s == ']' || *s == '^')
2336 /* this is terrifying, and it works */
2337 int weight = 2; /* let's weigh the evidence */
2339 unsigned char un_char = 255, last_un_char;
2340 const char * const send = strchr(s,']');
2341 char tmpbuf[sizeof PL_tokenbuf * 4];
2343 if (!send) /* has to be an expression */
2346 Zero(seen,256,char);
2349 else if (isDIGIT(*s)) {
2351 if (isDIGIT(s[1]) && s[2] == ']')
2357 for (; s < send; s++) {
2358 last_un_char = un_char;
2359 un_char = (unsigned char)*s;
2364 weight -= seen[un_char] * 10;
2365 if (isALNUM_lazy_if(s+1,UTF)) {
2367 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2368 len = (int)strlen(tmpbuf);
2369 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2374 else if (*s == '$' && s[1] &&
2375 strchr("[#!%*<>()-=",s[1])) {
2376 if (/*{*/ strchr("])} =",s[2]))
2385 if (strchr("wds]",s[1]))
2387 else if (seen['\''] || seen['"'])
2389 else if (strchr("rnftbxcav",s[1]))
2391 else if (isDIGIT(s[1])) {
2393 while (s[1] && isDIGIT(s[1]))
2403 if (strchr("aA01! ",last_un_char))
2405 if (strchr("zZ79~",s[1]))
2407 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2408 weight -= 5; /* cope with negative subscript */
2411 if (!isALNUM(last_un_char)
2412 && !(last_un_char == '$' || last_un_char == '@'
2413 || last_un_char == '&')
2414 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2419 if (keyword(tmpbuf, d - tmpbuf))
2422 if (un_char == last_un_char + 1)
2424 weight -= seen[un_char];
2429 if (weight >= 0) /* probably a character class */
2439 * Does all the checking to disambiguate
2441 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2442 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2444 * First argument is the stuff after the first token, e.g. "bar".
2446 * Not a method if bar is a filehandle.
2447 * Not a method if foo is a subroutine prototyped to take a filehandle.
2448 * Not a method if it's really "Foo $bar"
2449 * Method if it's "foo $bar"
2450 * Not a method if it's really "print foo $bar"
2451 * Method if it's really "foo package::" (interpreted as package->foo)
2452 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2453 * Not a method if bar is a filehandle or package, but is quoted with
2458 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2461 char *s = start + (*start == '$');
2462 char tmpbuf[sizeof PL_tokenbuf];
2470 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2474 const char *proto = SvPVX_const(cv);
2485 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2486 /* start is the beginning of the possible filehandle/object,
2487 * and s is the end of it
2488 * tmpbuf is a copy of it
2491 if (*start == '$') {
2492 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2495 len = start - SvPVX(PL_linestr);
2499 start = SvPVX(PL_linestr) + len;
2503 return *s == '(' ? FUNCMETH : METHOD;
2505 if (!keyword(tmpbuf, len)) {
2506 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2510 soff = s - SvPVX(PL_linestr);
2514 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2515 if (indirgv && GvCVu(indirgv))
2517 /* filehandle or package name makes it a method */
2518 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2520 soff = s - SvPVX(PL_linestr);
2523 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2524 return 0; /* no assumptions -- "=>" quotes bearword */
2526 start_force(PL_curforce);
2527 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2528 newSVpvn(tmpbuf,len));
2529 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2531 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2536 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2538 return *s == '(' ? FUNCMETH : METHOD;
2546 * Return a string of Perl code to load the debugger. If PERL5DB
2547 * is set, it will return the contents of that, otherwise a
2548 * compile-time require of perl5db.pl.
2556 const char * const pdb = PerlEnv_getenv("PERL5DB");
2560 SETERRNO(0,SS_NORMAL);
2561 return "BEGIN { require 'perl5db.pl' }";
2567 /* Encoded script support. filter_add() effectively inserts a
2568 * 'pre-processing' function into the current source input stream.
2569 * Note that the filter function only applies to the current source file
2570 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2572 * The datasv parameter (which may be NULL) can be used to pass
2573 * private data to this instance of the filter. The filter function
2574 * can recover the SV using the FILTER_DATA macro and use it to
2575 * store private buffers and state information.
2577 * The supplied datasv parameter is upgraded to a PVIO type
2578 * and the IoDIRP/IoANY field is used to store the function pointer,
2579 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2580 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2581 * private use must be set using malloc'd pointers.
2585 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2591 if (!PL_rsfp_filters)
2592 PL_rsfp_filters = newAV();
2595 SvUPGRADE(datasv, SVt_PVIO);
2596 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2597 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2598 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2599 FPTR2DPTR(void *, IoANY(datasv)),
2600 SvPV_nolen(datasv)));
2601 av_unshift(PL_rsfp_filters, 1);
2602 av_store(PL_rsfp_filters, 0, datasv) ;
2607 /* Delete most recently added instance of this filter function. */
2609 Perl_filter_del(pTHX_ filter_t funcp)
2615 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2616 FPTR2DPTR(void*, funcp)));
2618 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2620 /* if filter is on top of stack (usual case) just pop it off */
2621 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2622 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2623 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2624 IoANY(datasv) = (void *)NULL;
2625 sv_free(av_pop(PL_rsfp_filters));
2629 /* we need to search for the correct entry and clear it */
2630 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2634 /* Invoke the idxth filter function for the current rsfp. */
2635 /* maxlen 0 = read one text line */
2637 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2642 /* This API is bad. It should have been using unsigned int for maxlen.
2643 Not sure if we want to change the API, but if not we should sanity
2644 check the value here. */
2645 const unsigned int correct_length
2654 if (!PL_rsfp_filters)
2656 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2657 /* Provide a default input filter to make life easy. */
2658 /* Note that we append to the line. This is handy. */
2659 DEBUG_P(PerlIO_printf(Perl_debug_log,
2660 "filter_read %d: from rsfp\n", idx));
2661 if (correct_length) {
2664 const int old_len = SvCUR(buf_sv);
2666 /* ensure buf_sv is large enough */
2667 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2668 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2669 correct_length)) <= 0) {
2670 if (PerlIO_error(PL_rsfp))
2671 return -1; /* error */
2673 return 0 ; /* end of file */
2675 SvCUR_set(buf_sv, old_len + len) ;
2678 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2679 if (PerlIO_error(PL_rsfp))
2680 return -1; /* error */
2682 return 0 ; /* end of file */
2685 return SvCUR(buf_sv);
2687 /* Skip this filter slot if filter has been deleted */
2688 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2689 DEBUG_P(PerlIO_printf(Perl_debug_log,
2690 "filter_read %d: skipped (filter deleted)\n",
2692 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2694 /* Get function pointer hidden within datasv */
2695 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2696 DEBUG_P(PerlIO_printf(Perl_debug_log,
2697 "filter_read %d: via function %p (%s)\n",
2698 idx, (void*)datasv, SvPV_nolen_const(datasv)));
2699 /* Call function. The function is expected to */
2700 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2701 /* Return: <0:error, =0:eof, >0:not eof */
2702 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2706 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2709 #ifdef PERL_CR_FILTER
2710 if (!PL_rsfp_filters) {
2711 filter_add(S_cr_textfilter,NULL);
2714 if (PL_rsfp_filters) {
2716 SvCUR_set(sv, 0); /* start with empty line */
2717 if (FILTER_READ(0, sv, 0) > 0)
2718 return ( SvPVX(sv) ) ;
2723 return (sv_gets(sv, fp, append));
2727 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2732 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2736 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2737 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2739 return GvHV(gv); /* Foo:: */
2742 /* use constant CLASS => 'MyClass' */
2743 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
2744 if (gv && GvCV(gv)) {
2745 SV * const sv = cv_const_sv(GvCV(gv));
2747 pkgname = SvPV_nolen_const(sv);
2750 return gv_stashpv(pkgname, FALSE);
2756 * The intent of this yylex wrapper is to minimize the changes to the
2757 * tokener when we aren't interested in collecting madprops. It remains
2758 * to be seen how successful this strategy will be...
2765 char *s = PL_bufptr;
2767 /* make sure PL_thiswhite is initialized */
2771 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
2772 if (PL_pending_ident)
2773 return S_pending_ident(aTHX);
2775 /* previous token ate up our whitespace? */
2776 if (!PL_lasttoke && PL_nextwhite) {
2777 PL_thiswhite = PL_nextwhite;
2781 /* isolate the token, and figure out where it is without whitespace */
2782 PL_realtokenstart = -1;
2786 assert(PL_curforce < 0);
2788 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
2789 if (!PL_thistoken) {
2790 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
2791 PL_thistoken = newSVpvn("",0);
2793 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
2794 PL_thistoken = newSVpvn(tstart, s - tstart);
2797 if (PL_thismad) /* install head */
2798 CURMAD('X', PL_thistoken);
2801 /* last whitespace of a sublex? */
2802 if (optype == ')' && PL_endwhite) {
2803 CURMAD('X', PL_endwhite);
2808 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
2809 if (!PL_thiswhite && !PL_endwhite && !optype) {
2810 sv_free(PL_thistoken);
2815 /* put off final whitespace till peg */
2816 if (optype == ';' && !PL_rsfp) {
2817 PL_nextwhite = PL_thiswhite;
2820 else if (PL_thisopen) {
2821 CURMAD('q', PL_thisopen);
2823 sv_free(PL_thistoken);
2827 /* Store actual token text as madprop X */
2828 CURMAD('X', PL_thistoken);
2832 /* add preceding whitespace as madprop _ */
2833 CURMAD('_', PL_thiswhite);
2837 /* add quoted material as madprop = */
2838 CURMAD('=', PL_thisstuff);
2842 /* add terminating quote as madprop Q */
2843 CURMAD('Q', PL_thisclose);
2847 /* special processing based on optype */
2851 /* opval doesn't need a TOKEN since it can already store mp */
2862 append_madprops(PL_thismad, yylval.opval, 0);
2870 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
2879 /* remember any fake bracket that lexer is about to discard */
2880 if (PL_lex_brackets == 1 &&
2881 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
2884 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2887 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
2888 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
2891 break; /* don't bother looking for trailing comment */
2900 /* attach a trailing comment to its statement instead of next token */
2904 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
2906 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2908 if (*s == '\n' || *s == '#') {
2909 while (s < PL_bufend && *s != '\n')
2913 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
2914 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
2931 /* Create new token struct. Note: opvals return early above. */
2932 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
2939 S_tokenize_use(pTHX_ int is_use, char *s) {
2941 if (PL_expect != XSTATE)
2942 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
2943 is_use ? "use" : "no"));
2945 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
2946 s = force_version(s, TRUE);
2947 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
2948 start_force(PL_curforce);
2949 NEXTVAL_NEXTTOKE.opval = NULL;
2952 else if (*s == 'v') {
2953 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2954 s = force_version(s, FALSE);
2958 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2959 s = force_version(s, FALSE);
2961 yylval.ival = is_use;
2965 static const char* const exp_name[] =
2966 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2967 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
2974 Works out what to call the token just pulled out of the input
2975 stream. The yacc parser takes care of taking the ops we return and
2976 stitching them into a tree.
2982 if read an identifier
2983 if we're in a my declaration
2984 croak if they tried to say my($foo::bar)
2985 build the ops for a my() declaration
2986 if it's an access to a my() variable
2987 are we in a sort block?
2988 croak if my($a); $a <=> $b
2989 build ops for access to a my() variable
2990 if in a dq string, and they've said @foo and we can't find @foo
2992 build ops for a bareword
2993 if we already built the token before, use it.
2998 #pragma segment Perl_yylex
3004 register char *s = PL_bufptr;
3010 SV* tmp = newSVpvs("");
3011 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3012 (IV)CopLINE(PL_curcop),
3013 lex_state_names[PL_lex_state],
3014 exp_name[PL_expect],
3015 pv_display(tmp, s, strlen(s), 0, 60));
3018 /* check if there's an identifier for us to look at */
3019 if (PL_pending_ident)
3020 return REPORT(S_pending_ident(aTHX));
3022 /* no identifier pending identification */
3024 switch (PL_lex_state) {
3026 case LEX_NORMAL: /* Some compilers will produce faster */
3027 case LEX_INTERPNORMAL: /* code if we comment these out. */
3031 /* when we've already built the next token, just pull it out of the queue */
3035 yylval = PL_nexttoke[PL_lasttoke].next_val;
3037 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3038 PL_nexttoke[PL_lasttoke].next_mad = 0;
3039 if (PL_thismad && PL_thismad->mad_key == '_') {
3040 PL_thiswhite = (SV*)PL_thismad->mad_val;
3041 PL_thismad->mad_val = 0;
3042 mad_free(PL_thismad);
3047 PL_lex_state = PL_lex_defer;
3048 PL_expect = PL_lex_expect;
3049 PL_lex_defer = LEX_NORMAL;
3050 if (!PL_nexttoke[PL_lasttoke].next_type)
3055 yylval = PL_nextval[PL_nexttoke];
3057 PL_lex_state = PL_lex_defer;
3058 PL_expect = PL_lex_expect;
3059 PL_lex_defer = LEX_NORMAL;
3063 /* FIXME - can these be merged? */
3064 return(PL_nexttoke[PL_lasttoke].next_type);
3066 return REPORT(PL_nexttype[PL_nexttoke]);
3069 /* interpolated case modifiers like \L \U, including \Q and \E.
3070 when we get here, PL_bufptr is at the \
3072 case LEX_INTERPCASEMOD:
3074 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3075 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3077 /* handle \E or end of string */
3078 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3080 if (PL_lex_casemods) {
3081 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3082 PL_lex_casestack[PL_lex_casemods] = '\0';
3084 if (PL_bufptr != PL_bufend
3085 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3087 PL_lex_state = LEX_INTERPCONCAT;
3090 PL_thistoken = newSVpvn("\\E",2);
3096 while (PL_bufptr != PL_bufend &&
3097 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3099 PL_thiswhite = newSVpvn("",0);
3100 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3104 if (PL_bufptr != PL_bufend)
3107 PL_lex_state = LEX_INTERPCONCAT;
3111 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3112 "### Saw case modifier\n"); });
3114 if (s[1] == '\\' && s[2] == 'E') {
3117 PL_thiswhite = newSVpvn("",0);
3118 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3121 PL_lex_state = LEX_INTERPCONCAT;
3126 if (!PL_madskills) /* when just compiling don't need correct */
3127 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3128 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3129 if ((*s == 'L' || *s == 'U') &&
3130 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3131 PL_lex_casestack[--PL_lex_casemods] = '\0';
3134 if (PL_lex_casemods > 10)
3135 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3136 PL_lex_casestack[PL_lex_casemods++] = *s;
3137 PL_lex_casestack[PL_lex_casemods] = '\0';
3138 PL_lex_state = LEX_INTERPCONCAT;
3139 start_force(PL_curforce);
3140 NEXTVAL_NEXTTOKE.ival = 0;
3142 start_force(PL_curforce);
3144 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3146 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3148 NEXTVAL_NEXTTOKE.ival = OP_LC;
3150 NEXTVAL_NEXTTOKE.ival = OP_UC;
3152 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3154 Perl_croak(aTHX_ "panic: yylex");
3156 SV* const tmpsv = newSVpvn("",0);
3157 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3163 if (PL_lex_starts) {
3169 sv_free(PL_thistoken);
3170 PL_thistoken = newSVpvn("",0);
3173 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3174 if (PL_lex_casemods == 1 && PL_lex_inpat)
3183 case LEX_INTERPPUSH:
3184 return REPORT(sublex_push());
3186 case LEX_INTERPSTART:
3187 if (PL_bufptr == PL_bufend)
3188 return REPORT(sublex_done());
3189 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3190 "### Interpolated variable\n"); });
3192 PL_lex_dojoin = (*PL_bufptr == '@');
3193 PL_lex_state = LEX_INTERPNORMAL;
3194 if (PL_lex_dojoin) {
3195 start_force(PL_curforce);
3196 NEXTVAL_NEXTTOKE.ival = 0;
3198 start_force(PL_curforce);
3199 force_ident("\"", '$');
3200 start_force(PL_curforce);
3201 NEXTVAL_NEXTTOKE.ival = 0;
3203 start_force(PL_curforce);
3204 NEXTVAL_NEXTTOKE.ival = 0;
3206 start_force(PL_curforce);
3207 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3210 if (PL_lex_starts++) {
3215 sv_free(PL_thistoken);
3216 PL_thistoken = newSVpvn("",0);
3219 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3220 if (!PL_lex_casemods && PL_lex_inpat)
3227 case LEX_INTERPENDMAYBE:
3228 if (intuit_more(PL_bufptr)) {
3229 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3235 if (PL_lex_dojoin) {
3236 PL_lex_dojoin = FALSE;
3237 PL_lex_state = LEX_INTERPCONCAT;
3241 sv_free(PL_thistoken);
3242 PL_thistoken = newSVpvn("",0);
3247 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3248 && SvEVALED(PL_lex_repl))
3250 if (PL_bufptr != PL_bufend)
3251 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3255 case LEX_INTERPCONCAT:
3257 if (PL_lex_brackets)
3258 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3260 if (PL_bufptr == PL_bufend)
3261 return REPORT(sublex_done());
3263 if (SvIVX(PL_linestr) == '\'') {
3264 SV *sv = newSVsv(PL_linestr);
3267 else if ( PL_hints & HINT_NEW_RE )
3268 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
3269 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3273 s = scan_const(PL_bufptr);
3275 PL_lex_state = LEX_INTERPCASEMOD;
3277 PL_lex_state = LEX_INTERPSTART;
3280 if (s != PL_bufptr) {
3281 start_force(PL_curforce);
3283 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3285 NEXTVAL_NEXTTOKE = yylval;
3288 if (PL_lex_starts++) {
3292 sv_free(PL_thistoken);
3293 PL_thistoken = newSVpvn("",0);
3296 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3297 if (!PL_lex_casemods && PL_lex_inpat)
3310 PL_lex_state = LEX_NORMAL;
3311 s = scan_formline(PL_bufptr);
3312 if (!PL_lex_formbrack)
3318 PL_oldoldbufptr = PL_oldbufptr;
3324 sv_free(PL_thistoken);
3327 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3331 if (isIDFIRST_lazy_if(s,UTF))
3333 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
3336 goto fake_eof; /* emulate EOF on ^D or ^Z */
3345 if (PL_lex_brackets) {
3346 yyerror(PL_lex_formbrack
3347 ? "Format not terminated"
3348 : "Missing right curly or square bracket");
3350 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3351 "### Tokener got EOF\n");
3355 if (s++ < PL_bufend)
3356 goto retry; /* ignore stray nulls */
3359 if (!PL_in_eval && !PL_preambled) {
3360 PL_preambled = TRUE;
3365 sv_setpv(PL_linestr,incl_perldb());
3366 if (SvCUR(PL_linestr))
3367 sv_catpvs(PL_linestr,";");
3369 while(AvFILLp(PL_preambleav) >= 0) {
3370 SV *tmpsv = av_shift(PL_preambleav);
3371 sv_catsv(PL_linestr, tmpsv);
3372 sv_catpvs(PL_linestr, ";");
3375 sv_free((SV*)PL_preambleav);
3376 PL_preambleav = NULL;
3378 if (PL_minus_n || PL_minus_p) {
3379 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3381 sv_catpvs(PL_linestr,"chomp;");
3384 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3385 || *PL_splitstr == '"')
3386 && strchr(PL_splitstr + 1, *PL_splitstr))
3387 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3389 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3390 bytes can be used as quoting characters. :-) */
3391 const char *splits = PL_splitstr;
3392 sv_catpvs(PL_linestr, "our @F=split(q\0");
3395 if (*splits == '\\')
3396 sv_catpvn(PL_linestr, splits, 1);
3397 sv_catpvn(PL_linestr, splits, 1);
3398 } while (*splits++);
3399 /* This loop will embed the trailing NUL of
3400 PL_linestr as the last thing it does before
3402 sv_catpvs(PL_linestr, ");");
3406 sv_catpvs(PL_linestr,"our @F=split(' ');");
3410 sv_catpvs(PL_linestr,"use feature ':5.10';");
3411 sv_catpvs(PL_linestr, "\n");
3412 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3413 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3414 PL_last_lop = PL_last_uni = NULL;
3415 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3416 SV * const sv = newSV(0);
3418 sv_upgrade(sv, SVt_PVMG);
3419 sv_setsv(sv,PL_linestr);
3422 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
3427 bof = PL_rsfp ? TRUE : FALSE;
3428 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3431 PL_realtokenstart = -1;
3434 if (PL_preprocess && !PL_in_eval)
3435 (void)PerlProc_pclose(PL_rsfp);
3436 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3437 PerlIO_clearerr(PL_rsfp);
3439 (void)PerlIO_close(PL_rsfp);
3441 PL_doextract = FALSE;
3443 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3448 sv_setpv(PL_linestr,PL_minus_p
3449 ? ";}continue{print;}" : ";}");
3450 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3451 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3452 PL_last_lop = PL_last_uni = NULL;
3453 PL_minus_n = PL_minus_p = 0;
3456 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3457 PL_last_lop = PL_last_uni = NULL;
3458 sv_setpvn(PL_linestr,"",0);
3459 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3461 /* If it looks like the start of a BOM or raw UTF-16,
3462 * check if it in fact is. */
3468 #ifdef PERLIO_IS_STDIO
3469 # ifdef __GNU_LIBRARY__
3470 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3471 # define FTELL_FOR_PIPE_IS_BROKEN
3475 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3476 # define FTELL_FOR_PIPE_IS_BROKEN
3481 #ifdef FTELL_FOR_PIPE_IS_BROKEN
3482 /* This loses the possibility to detect the bof
3483 * situation on perl -P when the libc5 is being used.
3484 * Workaround? Maybe attach some extra state to PL_rsfp?
3487 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
3489 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3492 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3493 s = swallow_bom((U8*)s);
3497 /* Incest with pod. */
3500 sv_catsv(PL_thiswhite, PL_linestr);
3502 if (*s == '=' && strnEQ(s, "=cut", 4)) {
3503 sv_setpvn(PL_linestr, "", 0);
3504 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3505 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3506 PL_last_lop = PL_last_uni = NULL;
3507 PL_doextract = FALSE;
3511 } while (PL_doextract);
3512 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3513 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3514 SV * const sv = newSV(0);
3516 sv_upgrade(sv, SVt_PVMG);
3517 sv_setsv(sv,PL_linestr);
3520 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
3522 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3523 PL_last_lop = PL_last_uni = NULL;
3524 if (CopLINE(PL_curcop) == 1) {
3525 while (s < PL_bufend && isSPACE(*s))
3527 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3531 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3535 if (*s == '#' && *(s+1) == '!')
3537 #ifdef ALTERNATE_SHEBANG
3539 static char const as[] = ALTERNATE_SHEBANG;
3540 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3541 d = s + (sizeof(as) - 1);
3543 #endif /* ALTERNATE_SHEBANG */
3552 while (*d && !isSPACE(*d))
3556 #ifdef ARG_ZERO_IS_SCRIPT
3557 if (ipathend > ipath) {
3559 * HP-UX (at least) sets argv[0] to the script name,
3560 * which makes $^X incorrect. And Digital UNIX and Linux,
3561 * at least, set argv[0] to the basename of the Perl
3562 * interpreter. So, having found "#!", we'll set it right.
3564 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3566 assert(SvPOK(x) || SvGMAGICAL(x));
3567 if (sv_eq(x, CopFILESV(PL_curcop))) {
3568 sv_setpvn(x, ipath, ipathend - ipath);
3574 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3575 const char * const lstart = SvPV_const(x,llen);
3577 bstart += blen - llen;
3578 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3579 sv_setpvn(x, ipath, ipathend - ipath);
3584 TAINT_NOT; /* $^X is always tainted, but that's OK */
3586 #endif /* ARG_ZERO_IS_SCRIPT */
3591 d = instr(s,"perl -");
3593 d = instr(s,"perl");
3595 /* avoid getting into infinite loops when shebang
3596 * line contains "Perl" rather than "perl" */
3598 for (d = ipathend-4; d >= ipath; --d) {
3599 if ((*d == 'p' || *d == 'P')
3600 && !ibcmp(d, "perl", 4))
3610 #ifdef ALTERNATE_SHEBANG
3612 * If the ALTERNATE_SHEBANG on this system starts with a
3613 * character that can be part of a Perl expression, then if
3614 * we see it but not "perl", we're probably looking at the
3615 * start of Perl code, not a request to hand off to some
3616 * other interpreter. Similarly, if "perl" is there, but
3617 * not in the first 'word' of the line, we assume the line
3618 * contains the start of the Perl program.
3620 if (d && *s != '#') {
3621 const char *c = ipath;
3622 while (*c && !strchr("; \t\r\n\f\v#", *c))
3625 d = NULL; /* "perl" not in first word; ignore */
3627 *s = '#'; /* Don't try to parse shebang line */
3629 #endif /* ALTERNATE_SHEBANG */
3630 #ifndef MACOS_TRADITIONAL
3635 !instr(s,"indir") &&
3636 instr(PL_origargv[0],"perl"))
3643 while (s < PL_bufend && isSPACE(*s))
3645 if (s < PL_bufend) {
3646 Newxz(newargv,PL_origargc+3,char*);
3648 while (s < PL_bufend && !isSPACE(*s))
3651 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3654 newargv = PL_origargv;
3657 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3659 Perl_croak(aTHX_ "Can't exec %s", ipath);
3663 while (*d && !isSPACE(*d))
3665 while (SPACE_OR_TAB(*d))
3669 const bool switches_done = PL_doswitches;
3670 const U32 oldpdb = PL_perldb;
3671 const bool oldn = PL_minus_n;
3672 const bool oldp = PL_minus_p;
3675 if (*d == 'M' || *d == 'm' || *d == 'C') {
3676 const char * const m = d;
3677 while (*d && !isSPACE(*d))
3679 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3682 d = moreswitches(d);
3684 if (PL_doswitches && !switches_done) {
3685 int argc = PL_origargc;
3686 char **argv = PL_origargv;
3689 } while (argc && argv[0][0] == '-' && argv[0][1]);
3690 init_argv_symbols(argc,argv);
3692 if ((PERLDB_LINE && !oldpdb) ||
3693 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3694 /* if we have already added "LINE: while (<>) {",
3695 we must not do it again */
3697 sv_setpvn(PL_linestr, "", 0);
3698 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3699 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3700 PL_last_lop = PL_last_uni = NULL;
3701 PL_preambled = FALSE;
3703 (void)gv_fetchfile(PL_origfilename);
3710 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3712 PL_lex_state = LEX_FORMLINE;
3717 #ifdef PERL_STRICT_CR
3718 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3720 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3722 case ' ': case '\t': case '\f': case 013:
3723 #ifdef MACOS_TRADITIONAL
3727 PL_realtokenstart = -1;
3736 PL_realtokenstart = -1;
3740 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3741 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3742 /* handle eval qq[#line 1 "foo"\n ...] */
3743 CopLINE_dec(PL_curcop);
3746 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3748 if (!PL_in_eval || PL_rsfp)
3753 while (d < PL_bufend && *d != '\n')
3757 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3758 Perl_croak(aTHX_ "panic: input overflow");
3761 PL_thiswhite = newSVpvn(s, d - s);
3766 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3768 PL_lex_state = LEX_FORMLINE;
3774 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3775 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3778 TOKEN(PEG); /* make sure any #! line is accessible */
3783 /* if (PL_madskills && PL_lex_formbrack) { */
3785 while (d < PL_bufend && *d != '\n')
3789 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3790 Perl_croak(aTHX_ "panic: input overflow");
3791 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
3793 PL_thiswhite = newSVpvn("",0);
3794 if (CopLINE(PL_curcop) == 1) {
3795 sv_setpvn(PL_thiswhite, "", 0);
3798 sv_catpvn(PL_thiswhite, s, d - s);
3812 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
3820 while (s < PL_bufend && SPACE_OR_TAB(*s))
3823 if (strnEQ(s,"=>",2)) {
3824 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
3825 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
3826 OPERATOR('-'); /* unary minus */
3828 PL_last_uni = PL_oldbufptr;
3830 case 'r': ftst = OP_FTEREAD; break;
3831 case 'w': ftst = OP_FTEWRITE; break;
3832 case 'x': ftst = OP_FTEEXEC; break;
3833 case 'o': ftst = OP_FTEOWNED; break;
3834 case 'R': ftst = OP_FTRREAD; break;
3835 case 'W': ftst = OP_FTRWRITE; break;
3836 case 'X': ftst = OP_FTREXEC; break;
3837 case 'O': ftst = OP_FTROWNED; break;
3838 case 'e': ftst = OP_FTIS; break;
3839 case 'z': ftst = OP_FTZERO; break;
3840 case 's': ftst = OP_FTSIZE; break;
3841 case 'f': ftst = OP_FTFILE; break;
3842 case 'd': ftst = OP_FTDIR; break;
3843 case 'l': ftst = OP_FTLINK; break;
3844 case 'p': ftst = OP_FTPIPE; break;
3845 case 'S': ftst = OP_FTSOCK; break;
3846 case 'u': ftst = OP_FTSUID; break;
3847 case 'g': ftst = OP_FTSGID; break;
3848 case 'k': ftst = OP_FTSVTX; break;
3849 case 'b': ftst = OP_FTBLK; break;
3850 case 'c': ftst = OP_FTCHR; break;
3851 case 't': ftst = OP_FTTTY; break;
3852 case 'T': ftst = OP_FTTEXT; break;
3853 case 'B': ftst = OP_FTBINARY; break;
3854 case 'M': case 'A': case 'C':
3855 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
3857 case 'M': ftst = OP_FTMTIME; break;
3858 case 'A': ftst = OP_FTATIME; break;
3859 case 'C': ftst = OP_FTCTIME; break;
3867 PL_last_lop_op = (OPCODE)ftst;
3868 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3869 "### Saw file test %c\n", (int)tmp);
3874 /* Assume it was a minus followed by a one-letter named
3875 * subroutine call (or a -bareword), then. */
3876 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3877 "### '-%c' looked like a file test but was not\n",
3884 const char tmp = *s++;
3887 if (PL_expect == XOPERATOR)
3892 else if (*s == '>') {
3895 if (isIDFIRST_lazy_if(s,UTF)) {
3896 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
3904 if (PL_expect == XOPERATOR)
3907 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3909 OPERATOR('-'); /* unary minus */
3915 const char tmp = *s++;
3918 if (PL_expect == XOPERATOR)
3923 if (PL_expect == XOPERATOR)
3926 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3933 if (PL_expect != XOPERATOR) {
3934 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3935 PL_expect = XOPERATOR;
3936 force_ident(PL_tokenbuf, '*');
3949 if (PL_expect == XOPERATOR) {
3953 PL_tokenbuf[0] = '%';
3954 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
3955 if (!PL_tokenbuf[1]) {
3958 PL_pending_ident = '%';
3969 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)
3970 && FEATURE_IS_ENABLED("~~"))
3977 const char tmp = *s++;
3983 goto just_a_word_zero_gv;
3986 switch (PL_expect) {
3992 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
3994 PL_bufptr = s; /* update in case we back off */
4000 PL_expect = XTERMBLOCK;
4003 stuffstart = s - SvPVX(PL_linestr) - 1;
4007 while (isIDFIRST_lazy_if(s,UTF)) {
4010 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4011 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
4012 if (tmp < 0) tmp = -tmp;
4027 sv = newSVpvn(s, len);
4029 d = scan_str(d,TRUE,TRUE);
4031 /* MUST advance bufptr here to avoid bogus
4032 "at end of line" context messages from yyerror().
4034 PL_bufptr = s + len;
4035 yyerror("Unterminated attribute parameter in attribute list");
4039 return REPORT(0); /* EOF indicator */
4043 sv_catsv(sv, PL_lex_stuff);
4044 attrs = append_elem(OP_LIST, attrs,
4045 newSVOP(OP_CONST, 0, sv));
4046 SvREFCNT_dec(PL_lex_stuff);
4047 PL_lex_stuff = NULL;
4050 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4052 if (PL_in_my == KEY_our) {
4054 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4056 /* skip to avoid loading attributes.pm */
4058 deprecate(":unique");
4061 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4064 /* NOTE: any CV attrs applied here need to be part of
4065 the CVf_BUILTIN_ATTRS define in cv.h! */
4066 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4068 CvLVALUE_on(PL_compcv);
4070 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4072 CvLOCKED_on(PL_compcv);
4074 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4076 CvMETHOD_on(PL_compcv);
4078 else if (!PL_in_my && len == 9 && strnEQ(SvPVX(sv), "assertion", len)) {
4080 CvASSERTION_on(PL_compcv);
4082 /* After we've set the flags, it could be argued that
4083 we don't need to do the attributes.pm-based setting
4084 process, and shouldn't bother appending recognized
4085 flags. To experiment with that, uncomment the
4086 following "else". (Note that's already been
4087 uncommented. That keeps the above-applied built-in
4088 attributes from being intercepted (and possibly
4089 rejected) by a package's attribute routines, but is
4090 justified by the performance win for the common case
4091 of applying only built-in attributes.) */
4093 attrs = append_elem(OP_LIST, attrs,
4094 newSVOP(OP_CONST, 0,
4098 if (*s == ':' && s[1] != ':')
4101 break; /* require real whitespace or :'s */
4102 /* XXX losing whitespace on sequential attributes here */
4106 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4107 if (*s != ';' && *s != '}' && *s != tmp
4108 && (tmp != '=' || *s != ')')) {
4109 const char q = ((*s == '\'') ? '"' : '\'');
4110 /* If here for an expression, and parsed no attrs, back
4112 if (tmp == '=' && !attrs) {
4116 /* MUST advance bufptr here to avoid bogus "at end of line"
4117 context messages from yyerror().
4121 ? Perl_form(aTHX_ "Invalid separator character "
4122 "%c%c%c in attribute list", q, *s, q)
4123 : "Unterminated attribute list" );
4131 start_force(PL_curforce);
4132 NEXTVAL_NEXTTOKE.opval = attrs;
4133 CURMAD('_', PL_nextwhite);
4138 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4139 (s - SvPVX(PL_linestr)) - stuffstart);
4147 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4148 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4156 const char tmp = *s++;
4161 const char tmp = *s++;
4169 if (PL_lex_brackets <= 0)
4170 yyerror("Unmatched right square bracket");
4173 if (PL_lex_state == LEX_INTERPNORMAL) {
4174 if (PL_lex_brackets == 0) {
4175 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4176 PL_lex_state = LEX_INTERPEND;
4183 if (PL_lex_brackets > 100) {
4184 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4186 switch (PL_expect) {
4188 if (PL_lex_formbrack) {
4192 if (PL_oldoldbufptr == PL_last_lop)
4193 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4195 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4196 OPERATOR(HASHBRACK);
4198 while (s < PL_bufend && SPACE_OR_TAB(*s))
4201 PL_tokenbuf[0] = '\0';
4202 if (d < PL_bufend && *d == '-') {
4203 PL_tokenbuf[0] = '-';
4205 while (d < PL_bufend && SPACE_OR_TAB(*d))
4208 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4209 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4211 while (d < PL_bufend && SPACE_OR_TAB(*d))
4214 const char minus = (PL_tokenbuf[0] == '-');
4215 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4223 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4228 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4233 if (PL_oldoldbufptr == PL_last_lop)
4234 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4236 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4239 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4241 /* This hack is to get the ${} in the message. */
4243 yyerror("syntax error");
4246 OPERATOR(HASHBRACK);
4248 /* This hack serves to disambiguate a pair of curlies
4249 * as being a block or an anon hash. Normally, expectation
4250 * determines that, but in cases where we're not in a
4251 * position to expect anything in particular (like inside
4252 * eval"") we have to resolve the ambiguity. This code
4253 * covers the case where the first term in the curlies is a
4254 * quoted string. Most other cases need to be explicitly
4255 * disambiguated by prepending a "+" before the opening
4256 * curly in order to force resolution as an anon hash.
4258 * XXX should probably propagate the outer expectation
4259 * into eval"" to rely less on this hack, but that could
4260 * potentially break current behavior of eval"".
4264 if (*s == '\'' || *s == '"' || *s == '`') {
4265 /* common case: get past first string, handling escapes */
4266 for (t++; t < PL_bufend && *t != *s;)
4267 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4271 else if (*s == 'q') {
4274 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4277 /* skip q//-like construct */
4279 char open, close, term;
4282 while (t < PL_bufend && isSPACE(*t))
4284 /* check for q => */
4285 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4286 OPERATOR(HASHBRACK);
4290 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4294 for (t++; t < PL_bufend; t++) {
4295 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4297 else if (*t == open)
4301 for (t++; t < PL_bufend; t++) {
4302 if (*t == '\\' && t+1 < PL_bufend)
4304 else if (*t == close && --brackets <= 0)
4306 else if (*t == open)
4313 /* skip plain q word */
4314 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4317 else if (isALNUM_lazy_if(t,UTF)) {
4319 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4322 while (t < PL_bufend && isSPACE(*t))
4324 /* if comma follows first term, call it an anon hash */
4325 /* XXX it could be a comma expression with loop modifiers */
4326 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4327 || (*t == '=' && t[1] == '>')))
4328 OPERATOR(HASHBRACK);
4329 if (PL_expect == XREF)
4332 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4338 yylval.ival = CopLINE(PL_curcop);
4339 if (isSPACE(*s) || *s == '#')
4340 PL_copline = NOLINE; /* invalidate current command line number */
4345 if (PL_lex_brackets <= 0)
4346 yyerror("Unmatched right curly bracket");
4348 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4349 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4350 PL_lex_formbrack = 0;
4351 if (PL_lex_state == LEX_INTERPNORMAL) {
4352 if (PL_lex_brackets == 0) {
4353 if (PL_expect & XFAKEBRACK) {
4354 PL_expect &= XENUMMASK;
4355 PL_lex_state = LEX_INTERPEND;
4360 PL_thiswhite = newSVpvn("",0);
4361 sv_catpvn(PL_thiswhite,"}",1);
4364 return yylex(); /* ignore fake brackets */
4366 if (*s == '-' && s[1] == '>')
4367 PL_lex_state = LEX_INTERPENDMAYBE;
4368 else if (*s != '[' && *s != '{')
4369 PL_lex_state = LEX_INTERPEND;
4372 if (PL_expect & XFAKEBRACK) {
4373 PL_expect &= XENUMMASK;
4375 return yylex(); /* ignore fake brackets */
4377 start_force(PL_curforce);
4379 curmad('X', newSVpvn(s-1,1));
4380 CURMAD('_', PL_thiswhite);
4385 PL_thistoken = newSVpvn("",0);
4393 if (PL_expect == XOPERATOR) {
4394 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4395 && isIDFIRST_lazy_if(s,UTF))
4397 CopLINE_dec(PL_curcop);
4398 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4399 CopLINE_inc(PL_curcop);
4404 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4406 PL_expect = XOPERATOR;
4407 force_ident(PL_tokenbuf, '&');
4411 yylval.ival = (OPpENTERSUB_AMPER<<8);
4423 const char tmp = *s++;
4430 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4431 && strchr("+-*/%.^&|<",tmp))
4432 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4433 "Reversed %c= operator",(int)tmp);
4435 if (PL_expect == XSTATE && isALPHA(tmp) &&
4436 (s == PL_linestart+1 || s[-2] == '\n') )
4438 if (PL_in_eval && !PL_rsfp) {
4443 if (strnEQ(s,"=cut",4)) {
4459 PL_thiswhite = newSVpvn("",0);
4460 sv_catpvn(PL_thiswhite, PL_linestart,
4461 PL_bufend - PL_linestart);
4465 PL_doextract = TRUE;
4469 if (PL_lex_brackets < PL_lex_formbrack) {
4471 #ifdef PERL_STRICT_CR
4472 while (SPACE_OR_TAB(*t))
4474 while (SPACE_OR_TAB(*t) || *t == '\r')
4477 if (*t == '\n' || *t == '#') {
4488 const char tmp = *s++;
4490 /* was this !=~ where !~ was meant?
4491 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4493 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4494 const char *t = s+1;
4496 while (t < PL_bufend && isSPACE(*t))
4499 if (*t == '/' || *t == '?' ||
4500 ((*t == 'm' || *t == 's' || *t == 'y')
4501 && !isALNUM(t[1])) ||
4502 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4503 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4504 "!=~ should be !~");
4514 if (PL_expect != XOPERATOR) {
4515 if (s[1] != '<' && !strchr(s,'>'))
4518 s = scan_heredoc(s);
4520 s = scan_inputsymbol(s);
4521 TERM(sublex_start());
4527 SHop(OP_LEFT_SHIFT);
4541 const char tmp = *s++;
4543 SHop(OP_RIGHT_SHIFT);
4544 else if (tmp == '=')
4553 if (PL_expect == XOPERATOR) {
4554 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4556 deprecate_old(commaless_variable_list);
4557 return REPORT(','); /* grandfather non-comma-format format */
4561 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4562 PL_tokenbuf[0] = '@';
4563 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4564 sizeof PL_tokenbuf - 1, FALSE);
4565 if (PL_expect == XOPERATOR)
4566 no_op("Array length", s);
4567 if (!PL_tokenbuf[1])
4569 PL_expect = XOPERATOR;
4570 PL_pending_ident = '#';
4574 PL_tokenbuf[0] = '$';
4575 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4576 sizeof PL_tokenbuf - 1, FALSE);
4577 if (PL_expect == XOPERATOR)
4579 if (!PL_tokenbuf[1]) {
4581 yyerror("Final $ should be \\$ or $name");
4585 /* This kludge not intended to be bulletproof. */
4586 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4587 yylval.opval = newSVOP(OP_CONST, 0,
4588 newSViv(CopARYBASE_get(&PL_compiling)));
4589 yylval.opval->op_private = OPpCONST_ARYBASE;
4595 const char tmp = *s;
4596 if (PL_lex_state == LEX_NORMAL)
4599 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4600 && intuit_more(s)) {
4602 PL_tokenbuf[0] = '@';
4603 if (ckWARN(WARN_SYNTAX)) {
4606 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4609 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4610 while (t < PL_bufend && *t != ']')
4612 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4613 "Multidimensional syntax %.*s not supported",
4614 (int)((t - PL_bufptr) + 1), PL_bufptr);
4618 else if (*s == '{') {
4620 PL_tokenbuf[0] = '%';
4621 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4622 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4624 char tmpbuf[sizeof PL_tokenbuf];
4627 } while (isSPACE(*t));
4628 if (isIDFIRST_lazy_if(t,UTF)) {
4630 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4634 if (*t == ';' && get_cv(tmpbuf, FALSE))
4635 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4636 "You need to quote \"%s\"",
4643 PL_expect = XOPERATOR;
4644 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4645 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4646 if (!islop || PL_last_lop_op == OP_GREPSTART)
4647 PL_expect = XOPERATOR;
4648 else if (strchr("$@\"'`q", *s))
4649 PL_expect = XTERM; /* e.g. print $fh "foo" */
4650 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4651 PL_expect = XTERM; /* e.g. print $fh &sub */
4652 else if (isIDFIRST_lazy_if(s,UTF)) {
4653 char tmpbuf[sizeof PL_tokenbuf];
4655 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4656 if ((t2 = keyword(tmpbuf, len))) {
4657 /* binary operators exclude handle interpretations */
4669 PL_expect = XTERM; /* e.g. print $fh length() */
4674 PL_expect = XTERM; /* e.g. print $fh subr() */
4677 else if (isDIGIT(*s))
4678 PL_expect = XTERM; /* e.g. print $fh 3 */
4679 else if (*s == '.' && isDIGIT(s[1]))
4680 PL_expect = XTERM; /* e.g. print $fh .3 */
4681 else if ((*s == '?' || *s == '-' || *s == '+')
4682 && !isSPACE(s[1]) && s[1] != '=')
4683 PL_expect = XTERM; /* e.g. print $fh -1 */
4684 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4686 PL_expect = XTERM; /* e.g. print $fh /.../
4687 XXX except DORDOR operator
4689 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4691 PL_expect = XTERM; /* print $fh <<"EOF" */
4694 PL_pending_ident = '$';
4698 if (PL_expect == XOPERATOR)
4700 PL_tokenbuf[0] = '@';
4701 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4702 if (!PL_tokenbuf[1]) {
4705 if (PL_lex_state == LEX_NORMAL)
4707 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4709 PL_tokenbuf[0] = '%';
4711 /* Warn about @ where they meant $. */
4712 if (*s == '[' || *s == '{') {
4713 if (ckWARN(WARN_SYNTAX)) {
4714 const char *t = s + 1;
4715 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4717 if (*t == '}' || *t == ']') {
4719 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4720 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4721 "Scalar value %.*s better written as $%.*s",
4722 (int)(t-PL_bufptr), PL_bufptr,
4723 (int)(t-PL_bufptr-1), PL_bufptr+1);
4728 PL_pending_ident = '@';
4731 case '/': /* may be division, defined-or, or pattern */
4732 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4736 case '?': /* may either be conditional or pattern */
4737 if(PL_expect == XOPERATOR) {
4745 /* A // operator. */
4755 /* Disable warning on "study /blah/" */
4756 if (PL_oldoldbufptr == PL_last_uni
4757 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4758 || memNE(PL_last_uni, "study", 5)
4759 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4762 s = scan_pat(s,OP_MATCH);
4763 TERM(sublex_start());
4767 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4768 #ifdef PERL_STRICT_CR
4771 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4773 && (s == PL_linestart || s[-1] == '\n') )
4775 PL_lex_formbrack = 0;
4779 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4785 yylval.ival = OPf_SPECIAL;
4791 if (PL_expect != XOPERATOR)
4796 case '0': case '1': case '2': case '3': case '4':
4797 case '5': case '6': case '7': case '8': case '9':
4798 s = scan_num(s, &yylval);
4799 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
4800 if (PL_expect == XOPERATOR)
4805 s = scan_str(s,!!PL_madskills,FALSE);
4806 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4807 if (PL_expect == XOPERATOR) {
4808 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4810 deprecate_old(commaless_variable_list);
4811 return REPORT(','); /* grandfather non-comma-format format */
4818 yylval.ival = OP_CONST;
4819 TERM(sublex_start());
4822 s = scan_str(s,!!PL_madskills,FALSE);
4823 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4824 if (PL_expect == XOPERATOR) {
4825 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4827 deprecate_old(commaless_variable_list);
4828 return REPORT(','); /* grandfather non-comma-format format */
4835 yylval.ival = OP_CONST;
4836 /* FIXME. I think that this can be const if char *d is replaced by
4837 more localised variables. */
4838 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
4839 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
4840 yylval.ival = OP_STRINGIFY;
4844 TERM(sublex_start());
4847 s = scan_str(s,!!PL_madskills,FALSE);
4848 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
4849 if (PL_expect == XOPERATOR)
4850 no_op("Backticks",s);
4853 yylval.ival = OP_BACKTICK;
4855 TERM(sublex_start());
4859 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
4860 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
4862 if (PL_expect == XOPERATOR)
4863 no_op("Backslash",s);
4867 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
4868 char *start = s + 2;
4869 while (isDIGIT(*start) || *start == '_')
4871 if (*start == '.' && isDIGIT(start[1])) {
4872 s = scan_num(s, &yylval);
4875 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
4876 else if (!isALPHA(*start) && (PL_expect == XTERM
4877 || PL_expect == XREF || PL_expect == XSTATE
4878 || PL_expect == XTERMORDORDOR)) {
4879 /* XXX Use gv_fetchpvn rather than stomping on a const string */
4880 const char c = *start;
4883 gv = gv_fetchpv(s, 0, SVt_PVCV);
4886 s = scan_num(s, &yylval);
4893 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
4929 I32 orig_keyword = 0;
4934 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4936 /* Some keywords can be followed by any delimiter, including ':' */
4937 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
4938 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
4939 (PL_tokenbuf[0] == 'q' &&
4940 strchr("qwxr", PL_tokenbuf[1])))));
4942 /* x::* is just a word, unless x is "CORE" */
4943 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4947 while (d < PL_bufend && isSPACE(*d))
4948 d++; /* no comments skipped here, or s### is misparsed */
4950 /* Is this a label? */
4951 if (!tmp && PL_expect == XSTATE
4952 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
4954 yylval.pval = savepv(PL_tokenbuf);
4959 /* Check for keywords */
4960 tmp = keyword(PL_tokenbuf, len);
4962 /* Is this a word before a => operator? */
4963 if (*d == '=' && d[1] == '>') {
4966 = (OP*)newSVOP(OP_CONST, 0,
4967 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
4968 yylval.opval->op_private = OPpCONST_BARE;
4972 if (tmp < 0) { /* second-class keyword? */
4973 GV *ogv = NULL; /* override (winner) */
4974 GV *hgv = NULL; /* hidden (loser) */
4975 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
4977 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
4980 if (GvIMPORTED_CV(gv))
4982 else if (! CvMETHOD(cv))
4986 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
4987 (gv = *gvp) != (GV*)&PL_sv_undef &&
4988 GvCVu(gv) && GvIMPORTED_CV(gv))
4995 tmp = 0; /* overridden by import or by GLOBAL */
4998 && -tmp==KEY_lock /* XXX generalizable kludge */
5000 && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
5002 tmp = 0; /* any sub overrides "weak" keyword */
5004 else { /* no override */
5006 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
5007 Perl_warner(aTHX_ packWARN(WARN_MISC),
5008 "dump() better written as CORE::dump()");
5012 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5013 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
5014 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5015 "Ambiguous call resolved as CORE::%s(), %s",
5016 GvENAME(hgv), "qualify as such or use &");
5023 default: /* not a keyword */
5024 /* Trade off - by using this evil construction we can pull the
5025 variable gv into the block labelled keylookup. If not, then
5026 we have to give it function scope so that the goto from the
5027 earlier ':' case doesn't bypass the initialisation. */
5029 just_a_word_zero_gv:
5037 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5040 SV *nextPL_nextwhite = 0;
5044 /* Get the rest if it looks like a package qualifier */
5046 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5048 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5051 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5052 *s == '\'' ? "'" : "::");
5057 if (PL_expect == XOPERATOR) {
5058 if (PL_bufptr == PL_linestart) {
5059 CopLINE_dec(PL_curcop);
5060 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5061 CopLINE_inc(PL_curcop);
5064 no_op("Bareword",s);
5067 /* Look for a subroutine with this name in current package,
5068 unless name is "Foo::", in which case Foo is a bearword
5069 (and a package name). */
5071 if (len > 2 && !PL_madskills &&
5072 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5074 if (ckWARN(WARN_BAREWORD)
5075 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5076 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5077 "Bareword \"%s\" refers to nonexistent package",
5080 PL_tokenbuf[len] = '\0';
5086 /* Mustn't actually add anything to a symbol table.
5087 But also don't want to "initialise" any placeholder
5088 constants that might already be there into full
5089 blown PVGVs with attached PVCV. */
5090 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5091 GV_NOADD_NOINIT, SVt_PVCV);
5096 /* if we saw a global override before, get the right name */
5099 sv = newSVpvs("CORE::GLOBAL::");
5100 sv_catpv(sv,PL_tokenbuf);
5103 /* If len is 0, newSVpv does strlen(), which is correct.
5104 If len is non-zero, then it will be the true length,
5105 and so the scalar will be created correctly. */
5106 sv = newSVpv(PL_tokenbuf,len);
5109 if (PL_madskills && !PL_thistoken) {
5110 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5111 PL_thistoken = newSVpv(start,s - start);
5112 PL_realtokenstart = s - SvPVX(PL_linestr);
5116 /* Presume this is going to be a bareword of some sort. */
5119 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5120 yylval.opval->op_private = OPpCONST_BARE;
5121 /* UTF-8 package name? */
5122 if (UTF && !IN_BYTES &&
5123 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5126 /* And if "Foo::", then that's what it certainly is. */
5131 /* Do the explicit type check so that we don't need to force
5132 the initialisation of the symbol table to have a real GV.
5133 Beware - gv may not really be a PVGV, cv may not really be
5134 a PVCV, (because of the space optimisations that gv_init
5135 understands) But they're true if for this symbol there is
5136 respectively a typeglob and a subroutine.
5138 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5139 /* Real typeglob, so get the real subroutine: */
5141 /* A proxy for a subroutine in this package? */
5142 : SvOK(gv) ? (CV *) gv : NULL)
5145 /* See if it's the indirect object for a list operator. */
5147 if (PL_oldoldbufptr &&
5148 PL_oldoldbufptr < PL_bufptr &&
5149 (PL_oldoldbufptr == PL_last_lop
5150 || PL_oldoldbufptr == PL_last_uni) &&
5151 /* NO SKIPSPACE BEFORE HERE! */
5152 (PL_expect == XREF ||
5153 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5155 bool immediate_paren = *s == '(';
5157 /* (Now we can afford to cross potential line boundary.) */
5158 s = SKIPSPACE2(s,nextPL_nextwhite);
5160 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5163 /* Two barewords in a row may indicate method call. */
5165 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5166 (tmp = intuit_method(s, gv, cv)))
5169 /* If not a declared subroutine, it's an indirect object. */
5170 /* (But it's an indir obj regardless for sort.) */
5171 /* Also, if "_" follows a filetest operator, it's a bareword */
5174 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5176 (PL_last_lop_op != OP_MAPSTART &&
5177 PL_last_lop_op != OP_GREPSTART))))
5178 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5179 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5182 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5187 PL_expect = XOPERATOR;
5190 s = SKIPSPACE2(s,nextPL_nextwhite);
5191 PL_nextwhite = nextPL_nextwhite;
5196 /* Is this a word before a => operator? */
5197 if (*s == '=' && s[1] == '>' && !pkgname) {
5199 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5200 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5201 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5205 /* If followed by a paren, it's certainly a subroutine. */
5210 while (SPACE_OR_TAB(*d))
5212 if (*d == ')' && (sv = gv_const_sv(gv))) {
5216 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5217 sv_catpvn(PL_thistoken, par, s - par);
5219 sv_free(PL_nextwhite);
5229 PL_nextwhite = PL_thiswhite;
5232 start_force(PL_curforce);
5234 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5235 PL_expect = XOPERATOR;
5238 PL_nextwhite = nextPL_nextwhite;
5239 curmad('X', PL_thistoken);
5240 PL_thistoken = newSVpvn("",0);
5248 /* If followed by var or block, call it a method (unless sub) */
5250 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5251 PL_last_lop = PL_oldbufptr;
5252 PL_last_lop_op = OP_METHOD;
5256 /* If followed by a bareword, see if it looks like indir obj. */
5259 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5260 && (tmp = intuit_method(s, gv, cv)))
5263 /* Not a method, so call it a subroutine (if defined) */
5266 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5267 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5268 "Ambiguous use of -%s resolved as -&%s()",
5269 PL_tokenbuf, PL_tokenbuf);
5270 /* Check for a constant sub */
5271 if ((sv = gv_const_sv(gv))) {
5273 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5274 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5275 yylval.opval->op_private = 0;
5279 /* Resolve to GV now. */
5280 if (SvTYPE(gv) != SVt_PVGV) {
5281 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5282 assert (SvTYPE(gv) == SVt_PVGV);
5283 /* cv must have been some sort of placeholder, so
5284 now needs replacing with a real code reference. */
5288 op_free(yylval.opval);
5289 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5290 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5291 PL_last_lop = PL_oldbufptr;
5292 PL_last_lop_op = OP_ENTERSUB;
5293 /* Is there a prototype? */
5300 const char *proto = SvPV_const((SV*)cv, protolen);
5303 if (*proto == '$' && proto[1] == '\0')
5305 while (*proto == ';')
5307 if (*proto == '&' && *s == '{') {
5308 sv_setpv(PL_subname, PL_curstash ?
5309 "__ANON__" : "__ANON__::__ANON__");
5316 PL_nextwhite = PL_thiswhite;
5319 start_force(PL_curforce);
5320 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5323 PL_nextwhite = nextPL_nextwhite;
5324 curmad('X', PL_thistoken);
5325 PL_thistoken = newSVpvn("",0);
5332 /* Guess harder when madskills require "best effort". */
5333 if (PL_madskills && (!gv || !GvCVu(gv))) {
5334 int probable_sub = 0;
5335 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5337 else if (isALPHA(*s)) {
5341 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5342 if (!keyword(tmpbuf,tmplen))
5345 while (d < PL_bufend && isSPACE(*d))
5347 if (*d == '=' && d[1] == '>')
5352 gv = gv_fetchpv(PL_tokenbuf, TRUE, SVt_PVCV);
5353 op_free(yylval.opval);
5354 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5355 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5356 PL_last_lop = PL_oldbufptr;
5357 PL_last_lop_op = OP_ENTERSUB;
5358 PL_nextwhite = PL_thiswhite;
5360 start_force(PL_curforce);
5361 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5363 PL_nextwhite = nextPL_nextwhite;
5364 curmad('X', PL_thistoken);
5365 PL_thistoken = newSVpvn("",0);
5370 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5377 /* Call it a bare word */
5379 if (PL_hints & HINT_STRICT_SUBS)
5380 yylval.opval->op_private |= OPpCONST_STRICT;
5383 if (lastchar != '-') {
5384 if (ckWARN(WARN_RESERVED)) {
5388 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
5389 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5396 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5397 && ckWARN_d(WARN_AMBIGUOUS)) {
5398 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5399 "Operator or semicolon missing before %c%s",
5400 lastchar, PL_tokenbuf);
5401 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5402 "Ambiguous use of %c resolved as operator %c",
5403 lastchar, lastchar);
5409 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5410 newSVpv(CopFILE(PL_curcop),0));
5414 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5415 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5418 case KEY___PACKAGE__:
5419 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5421 ? newSVhek(HvNAME_HEK(PL_curstash))
5428 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5429 const char *pname = "main";
5430 if (PL_tokenbuf[2] == 'D')
5431 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5432 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5436 GvIOp(gv) = newIO();
5437 IoIFP(GvIOp(gv)) = PL_rsfp;
5438 #if defined(HAS_FCNTL) && defined(F_SETFD)
5440 const int fd = PerlIO_fileno(PL_rsfp);
5441 fcntl(fd,F_SETFD,fd >= 3);
5444 /* Mark this internal pseudo-handle as clean */
5445 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5447 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5448 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5449 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5451 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5452 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5453 /* if the script was opened in binmode, we need to revert
5454 * it to text mode for compatibility; but only iff it has CRs
5455 * XXX this is a questionable hack at best. */
5456 if (PL_bufend-PL_bufptr > 2
5457 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5460 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5461 loc = PerlIO_tell(PL_rsfp);
5462 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5465 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5467 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5468 #endif /* NETWARE */
5469 #ifdef PERLIO_IS_STDIO /* really? */
5470 # if defined(__BORLANDC__)
5471 /* XXX see note in do_binmode() */
5472 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5476 PerlIO_seek(PL_rsfp, loc, 0);
5480 #ifdef PERLIO_LAYERS
5483 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5484 else if (PL_encoding) {
5491 XPUSHs(PL_encoding);
5493 call_method("name", G_SCALAR);
5497 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5498 Perl_form(aTHX_ ":encoding(%"SVf")",
5507 if (PL_realtokenstart >= 0) {
5508 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5510 PL_endwhite = newSVpvn("",0);
5511 sv_catsv(PL_endwhite, PL_thiswhite);
5513 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5514 PL_realtokenstart = -1;
5516 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5517 SvCUR(PL_endwhite))) != Nullch) ;
5531 if (PL_expect == XSTATE) {
5538 if (*s == ':' && s[1] == ':') {
5541 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5542 if (!(tmp = keyword(PL_tokenbuf, len)))
5543 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5546 else if (tmp == KEY_require || tmp == KEY_do)
5547 /* that's a way to remember we saw "CORE::" */
5560 LOP(OP_ACCEPT,XTERM);
5566 LOP(OP_ATAN2,XTERM);
5572 LOP(OP_BINMODE,XTERM);
5575 LOP(OP_BLESS,XTERM);
5584 /* When 'use switch' is in effect, continue has a dual
5585 life as a control operator. */
5587 if (!FEATURE_IS_ENABLED("switch"))
5590 /* We have to disambiguate the two senses of
5591 "continue". If the next token is a '{' then
5592 treat it as the start of a continue block;
5593 otherwise treat it as a control operator.
5605 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5622 if (!PL_cryptseen) {
5623 PL_cryptseen = TRUE;
5627 LOP(OP_CRYPT,XTERM);
5630 LOP(OP_CHMOD,XTERM);
5633 LOP(OP_CHOWN,XTERM);
5636 LOP(OP_CONNECT,XTERM);
5655 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5656 if (orig_keyword == KEY_do) {
5665 PL_hints |= HINT_BLOCK_SCOPE;
5675 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5676 LOP(OP_DBMOPEN,XTERM);
5682 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5689 yylval.ival = CopLINE(PL_curcop);
5705 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5706 UNIBRACK(OP_ENTEREVAL);
5724 case KEY_endhostent:
5730 case KEY_endservent:
5733 case KEY_endprotoent:
5744 yylval.ival = CopLINE(PL_curcop);
5746 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5749 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5752 if ((PL_bufend - p) >= 3 &&
5753 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5755 else if ((PL_bufend - p) >= 4 &&
5756 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5759 if (isIDFIRST_lazy_if(p,UTF)) {
5760 p = scan_ident(p, PL_bufend,
5761 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5765 Perl_croak(aTHX_ "Missing $ on loop variable");
5767 s = SvPVX(PL_linestr) + soff;
5773 LOP(OP_FORMLINE,XTERM);
5779 LOP(OP_FCNTL,XTERM);
5785 LOP(OP_FLOCK,XTERM);
5794 LOP(OP_GREPSTART, XREF);
5797 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5812 case KEY_getpriority:
5813 LOP(OP_GETPRIORITY,XTERM);
5815 case KEY_getprotobyname:
5818 case KEY_getprotobynumber:
5819 LOP(OP_GPBYNUMBER,XTERM);
5821 case KEY_getprotoent:
5833 case KEY_getpeername:
5834 UNI(OP_GETPEERNAME);
5836 case KEY_gethostbyname:
5839 case KEY_gethostbyaddr:
5840 LOP(OP_GHBYADDR,XTERM);
5842 case KEY_gethostent:
5845 case KEY_getnetbyname:
5848 case KEY_getnetbyaddr:
5849 LOP(OP_GNBYADDR,XTERM);
5854 case KEY_getservbyname:
5855 LOP(OP_GSBYNAME,XTERM);
5857 case KEY_getservbyport:
5858 LOP(OP_GSBYPORT,XTERM);
5860 case KEY_getservent:
5863 case KEY_getsockname:
5864 UNI(OP_GETSOCKNAME);
5866 case KEY_getsockopt:
5867 LOP(OP_GSOCKOPT,XTERM);
5882 yylval.ival = CopLINE(PL_curcop);
5893 yylval.ival = CopLINE(PL_curcop);
5897 LOP(OP_INDEX,XTERM);
5903 LOP(OP_IOCTL,XTERM);
5915 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5947 LOP(OP_LISTEN,XTERM);
5956 s = scan_pat(s,OP_MATCH);
5957 TERM(sublex_start());
5960 LOP(OP_MAPSTART, XREF);
5963 LOP(OP_MKDIR,XTERM);
5966 LOP(OP_MSGCTL,XTERM);
5969 LOP(OP_MSGGET,XTERM);
5972 LOP(OP_MSGRCV,XTERM);
5975 LOP(OP_MSGSND,XTERM);
5982 if (isIDFIRST_lazy_if(s,UTF)) {
5986 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
5987 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
5989 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
5990 if (!PL_in_my_stash) {
5993 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
5997 if (PL_madskills) { /* just add type to declarator token */
5998 sv_catsv(PL_thistoken, PL_nextwhite);
6000 sv_catpvn(PL_thistoken, start, s - start);
6008 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6015 s = tokenize_use(0, s);
6019 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6026 if (isIDFIRST_lazy_if(s,UTF)) {
6028 for (d = s; isALNUM_lazy_if(d,UTF);)
6030 for (t=d; isSPACE(*t);)
6032 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6034 && !(t[0] == '=' && t[1] == '>')
6036 int parms_len = (int)(d-s);
6037 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6038 "Precedence problem: open %.*s should be open(%.*s)",
6039 parms_len, s, parms_len, s);
6045 yylval.ival = OP_OR;
6055 LOP(OP_OPEN_DIR,XTERM);
6058 checkcomma(s,PL_tokenbuf,"filehandle");
6062 checkcomma(s,PL_tokenbuf,"filehandle");
6081 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6085 LOP(OP_PIPE_OP,XTERM);
6088 s = scan_str(s,!!PL_madskills,FALSE);
6091 yylval.ival = OP_CONST;
6092 TERM(sublex_start());
6098 s = scan_str(s,!!PL_madskills,FALSE);
6101 PL_expect = XOPERATOR;
6103 if (SvCUR(PL_lex_stuff)) {
6106 d = SvPV_force(PL_lex_stuff, len);
6108 for (; isSPACE(*d) && len; --len, ++d)
6113 if (!warned && ckWARN(WARN_QW)) {
6114 for (; !isSPACE(*d) && len; --len, ++d) {
6116 Perl_warner(aTHX_ packWARN(WARN_QW),
6117 "Possible attempt to separate words with commas");
6120 else if (*d == '#') {
6121 Perl_warner(aTHX_ packWARN(WARN_QW),
6122 "Possible attempt to put comments in qw() list");
6128 for (; !isSPACE(*d) && len; --len, ++d)
6131 sv = newSVpvn(b, d-b);
6132 if (DO_UTF8(PL_lex_stuff))
6134 words = append_elem(OP_LIST, words,
6135 newSVOP(OP_CONST, 0, tokeq(sv)));
6139 start_force(PL_curforce);
6140 NEXTVAL_NEXTTOKE.opval = words;
6145 SvREFCNT_dec(PL_lex_stuff);
6146 PL_lex_stuff = NULL;
6152 s = scan_str(s,!!PL_madskills,FALSE);
6155 yylval.ival = OP_STRINGIFY;
6156 if (SvIVX(PL_lex_stuff) == '\'')
6157 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6158 TERM(sublex_start());
6161 s = scan_pat(s,OP_QR);
6162 TERM(sublex_start());
6165 s = scan_str(s,!!PL_madskills,FALSE);
6168 yylval.ival = OP_BACKTICK;
6170 TERM(sublex_start());
6178 s = force_version(s, FALSE);
6180 else if (*s != 'v' || !isDIGIT(s[1])
6181 || (s = force_version(s, TRUE), *s == 'v'))
6183 *PL_tokenbuf = '\0';
6184 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6185 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6186 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
6188 yyerror("<> should be quotes");
6190 if (orig_keyword == KEY_require) {
6198 PL_last_uni = PL_oldbufptr;
6199 PL_last_lop_op = OP_REQUIRE;
6201 return REPORT( (int)REQUIRE );
6207 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6211 LOP(OP_RENAME,XTERM);
6220 LOP(OP_RINDEX,XTERM);
6230 UNIDOR(OP_READLINE);
6243 LOP(OP_REVERSE,XTERM);
6246 UNIDOR(OP_READLINK);
6254 TERM(sublex_start());
6256 TOKEN(1); /* force error */
6259 checkcomma(s,PL_tokenbuf,"filehandle");
6269 LOP(OP_SELECT,XTERM);
6275 LOP(OP_SEMCTL,XTERM);
6278 LOP(OP_SEMGET,XTERM);
6281 LOP(OP_SEMOP,XTERM);
6287 LOP(OP_SETPGRP,XTERM);
6289 case KEY_setpriority:
6290 LOP(OP_SETPRIORITY,XTERM);
6292 case KEY_sethostent:
6298 case KEY_setservent:
6301 case KEY_setprotoent:
6311 LOP(OP_SEEKDIR,XTERM);
6313 case KEY_setsockopt:
6314 LOP(OP_SSOCKOPT,XTERM);
6320 LOP(OP_SHMCTL,XTERM);
6323 LOP(OP_SHMGET,XTERM);
6326 LOP(OP_SHMREAD,XTERM);
6329 LOP(OP_SHMWRITE,XTERM);
6332 LOP(OP_SHUTDOWN,XTERM);
6341 LOP(OP_SOCKET,XTERM);
6343 case KEY_socketpair:
6344 LOP(OP_SOCKPAIR,XTERM);
6347 checkcomma(s,PL_tokenbuf,"subroutine name");
6349 if (*s == ';' || *s == ')') /* probably a close */
6350 Perl_croak(aTHX_ "sort is now a reserved word");
6352 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6356 LOP(OP_SPLIT,XTERM);
6359 LOP(OP_SPRINTF,XTERM);
6362 LOP(OP_SPLICE,XTERM);
6377 LOP(OP_SUBSTR,XTERM);
6383 char tmpbuf[sizeof PL_tokenbuf];
6384 SSize_t tboffset = 0;
6385 expectation attrful;
6386 bool have_name, have_proto, bad_proto;
6387 const int key = tmp;
6392 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6393 SV *subtoken = newSVpvn(tstart, s - tstart);
6397 s = SKIPSPACE2(s,tmpwhite);
6402 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6403 (*s == ':' && s[1] == ':'))
6410 attrful = XATTRBLOCK;
6411 /* remember buffer pos'n for later force_word */
6412 tboffset = s - PL_oldbufptr;
6413 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6416 nametoke = newSVpvn(s, d - s);
6418 if (strchr(tmpbuf, ':'))
6419 sv_setpv(PL_subname, tmpbuf);
6421 sv_setsv(PL_subname,PL_curstname);
6422 sv_catpvs(PL_subname,"::");
6423 sv_catpvn(PL_subname,tmpbuf,len);
6430 CURMAD('X', nametoke);
6431 CURMAD('_', tmpwhite);
6432 (void) force_word(PL_oldbufptr + tboffset, WORD,
6435 s = SKIPSPACE2(d,tmpwhite);
6442 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6443 PL_expect = XTERMBLOCK;
6444 attrful = XATTRTERM;
6445 sv_setpvn(PL_subname,"?",1);
6449 if (key == KEY_format) {
6451 PL_lex_formbrack = PL_lex_brackets + 1;
6453 PL_thistoken = subtoken;
6457 (void) force_word(PL_oldbufptr + tboffset, WORD,
6463 /* Look for a prototype */
6467 s = scan_str(s,!!PL_madskills,FALSE);
6469 Perl_croak(aTHX_ "Prototype not terminated");
6470 /* strip spaces and check for bad characters */
6471 d = SvPVX(PL_lex_stuff);
6474 for (p = d; *p; ++p) {
6477 if (!strchr("$@%*;[]&\\", *p))
6482 if (bad_proto && ckWARN(WARN_SYNTAX))
6483 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6484 "Illegal character in prototype for %"SVf" : %s",
6485 (void*)PL_subname, d);
6486 SvCUR_set(PL_lex_stuff, tmp);
6491 CURMAD('q', PL_thisopen);
6492 CURMAD('_', tmpwhite);
6493 CURMAD('=', PL_thisstuff);
6494 CURMAD('Q', PL_thisclose);
6495 NEXTVAL_NEXTTOKE.opval =
6496 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6497 PL_lex_stuff = Nullsv;
6500 s = SKIPSPACE2(s,tmpwhite);
6508 if (*s == ':' && s[1] != ':')
6509 PL_expect = attrful;
6510 else if (*s != '{' && key == KEY_sub) {
6512 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6514 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, (void*)PL_subname);
6521 curmad('^', newSVpvn("",0));
6522 CURMAD('_', tmpwhite);
6526 PL_thistoken = subtoken;
6529 NEXTVAL_NEXTTOKE.opval =
6530 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6531 PL_lex_stuff = NULL;
6536 sv_setpv(PL_subname,
6537 PL_curstash ? "__ANON__" : "__ANON__::__ANON__");
6541 (void) force_word(PL_oldbufptr + tboffset, WORD,
6551 LOP(OP_SYSTEM,XREF);
6554 LOP(OP_SYMLINK,XTERM);
6557 LOP(OP_SYSCALL,XTERM);
6560 LOP(OP_SYSOPEN,XTERM);
6563 LOP(OP_SYSSEEK,XTERM);
6566 LOP(OP_SYSREAD,XTERM);
6569 LOP(OP_SYSWRITE,XTERM);
6573 TERM(sublex_start());
6594 LOP(OP_TRUNCATE,XTERM);
6606 yylval.ival = CopLINE(PL_curcop);
6610 yylval.ival = CopLINE(PL_curcop);
6614 LOP(OP_UNLINK,XTERM);
6620 LOP(OP_UNPACK,XTERM);
6623 LOP(OP_UTIME,XTERM);
6629 LOP(OP_UNSHIFT,XTERM);
6632 s = tokenize_use(1, s);
6642 yylval.ival = CopLINE(PL_curcop);
6646 yylval.ival = CopLINE(PL_curcop);
6650 PL_hints |= HINT_BLOCK_SCOPE;
6657 LOP(OP_WAITPID,XTERM);
6666 ctl_l[0] = toCTRL('L');
6668 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6671 /* Make sure $^L is defined */
6672 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6677 if (PL_expect == XOPERATOR)
6683 yylval.ival = OP_XOR;
6688 TERM(sublex_start());
6693 #pragma segment Main
6697 S_pending_ident(pTHX)
6701 register I32 tmp = 0;
6702 /* pit holds the identifier we read and pending_ident is reset */
6703 char pit = PL_pending_ident;
6704 PL_pending_ident = 0;
6706 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6707 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6708 "### Pending identifier '%s'\n", PL_tokenbuf); });
6710 /* if we're in a my(), we can't allow dynamics here.
6711 $foo'bar has already been turned into $foo::bar, so
6712 just check for colons.
6714 if it's a legal name, the OP is a PADANY.
6717 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6718 if (strchr(PL_tokenbuf,':'))
6719 yyerror(Perl_form(aTHX_ "No package name allowed for "
6720 "variable %s in \"our\"",
6722 tmp = allocmy(PL_tokenbuf);
6725 if (strchr(PL_tokenbuf,':'))
6726 yyerror(Perl_form(aTHX_ PL_no_myglob,
6727 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
6729 yylval.opval = newOP(OP_PADANY, 0);
6730 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6736 build the ops for accesses to a my() variable.
6738 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6739 then used in a comparison. This catches most, but not
6740 all cases. For instance, it catches
6741 sort { my($a); $a <=> $b }
6743 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6744 (although why you'd do that is anyone's guess).
6747 if (!strchr(PL_tokenbuf,':')) {
6749 tmp = pad_findmy(PL_tokenbuf);
6750 if (tmp != NOT_IN_PAD) {
6751 /* might be an "our" variable" */
6752 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6753 /* build ops for a bareword */
6754 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6755 HEK * const stashname = HvNAME_HEK(stash);
6756 SV * const sym = newSVhek(stashname);
6757 sv_catpvs(sym, "::");
6758 sv_catpv(sym, PL_tokenbuf+1);
6759 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6760 yylval.opval->op_private = OPpCONST_ENTERED;
6763 ? (GV_ADDMULTI | GV_ADDINEVAL)
6766 ((PL_tokenbuf[0] == '$') ? SVt_PV
6767 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6772 /* if it's a sort block and they're naming $a or $b */
6773 if (PL_last_lop_op == OP_SORT &&
6774 PL_tokenbuf[0] == '$' &&
6775 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6778 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6779 d < PL_bufend && *d != '\n';
6782 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6783 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6789 yylval.opval = newOP(OP_PADANY, 0);
6790 yylval.opval->op_targ = tmp;
6796 Whine if they've said @foo in a doublequoted string,
6797 and @foo isn't a variable we can find in the symbol
6800 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
6801 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
6802 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
6803 && ckWARN(WARN_AMBIGUOUS))
6805 /* Downgraded from fatal to warning 20000522 mjd */
6806 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6807 "Possible unintended interpolation of %s in string",
6812 /* build ops for a bareword */
6813 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
6814 yylval.opval->op_private = OPpCONST_ENTERED;
6817 /* If the identifier refers to a stash, don't autovivify it.
6818 * Change 24660 had the side effect of causing symbol table
6819 * hashes to always be defined, even if they were freshly
6820 * created and the only reference in the entire program was
6821 * the single statement with the defined %foo::bar:: test.
6822 * It appears that all code in the wild doing this actually
6823 * wants to know whether sub-packages have been loaded, so
6824 * by avoiding auto-vivifying symbol tables, we ensure that
6825 * defined %foo::bar:: continues to be false, and the existing
6826 * tests still give the expected answers, even though what
6827 * they're actually testing has now changed subtly.
6829 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
6831 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
6832 ((PL_tokenbuf[0] == '$') ? SVt_PV
6833 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6839 * The following code was generated by perl_keyword.pl.
6843 Perl_keyword (pTHX_ const char *name, I32 len)
6848 case 1: /* 5 tokens of length 1 */
6880 case 2: /* 18 tokens of length 2 */
7026 case 3: /* 29 tokens of length 3 */
7030 if (name[1] == 'N' &&
7093 if (name[1] == 'i' &&
7115 return (FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7133 if (name[1] == 'o' &&
7142 if (name[1] == 'e' &&
7151 if (name[1] == 'n' &&
7160 if (name[1] == 'o' &&
7169 if (name[1] == 'a' &&
7178 if (name[1] == 'o' &&
7240 if (name[1] == 'e' &&
7254 return (FEATURE_IS_ENABLED("say") ? -KEY_say : 0);
7280 if (name[1] == 'i' &&
7289 if (name[1] == 's' &&
7298 if (name[1] == 'e' &&
7307 if (name[1] == 'o' &&
7319 case 4: /* 41 tokens of length 4 */
7323 if (name[1] == 'O' &&
7333 if (name[1] == 'N' &&
7343 if (name[1] == 'i' &&
7353 if (name[1] == 'h' &&
7363 if (name[1] == 'u' &&
7376 if (name[2] == 'c' &&
7385 if (name[2] == 's' &&
7394 if (name[2] == 'a' &&
7430 if (name[1] == 'o' &&
7443 if (name[2] == 't' &&
7452 if (name[2] == 'o' &&
7461 if (name[2] == 't' &&
7470 if (name[2] == 'e' &&
7483 if (name[1] == 'o' &&
7496 if (name[2] == 'y' &&
7505 if (name[2] == 'l' &&
7521 if (name[2] == 's' &&
7530 if (name[2] == 'n' &&
7539 if (name[2] == 'c' &&
7552 if (name[1] == 'e' &&
7562 if (name[1] == 'p' &&
7575 if (name[2] == 'c' &&
7584 if (name[2] == 'p' &&
7593 if (name[2] == 's' &&
7609 if (name[2] == 'n' &&
7679 if (name[2] == 'r' &&
7688 if (name[2] == 'r' &&
7697 if (name[2] == 'a' &&
7713 if (name[2] == 'l' &&
7775 if (name[2] == 'e' &&
7778 return (FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
7791 case 5: /* 39 tokens of length 5 */
7795 if (name[1] == 'E' &&
7806 if (name[1] == 'H' &&
7820 if (name[2] == 'a' &&
7830 if (name[2] == 'a' &&
7847 if (name[2] == 'e' &&
7857 if (name[2] == 'e' &&
7861 return (FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
7877 if (name[3] == 'i' &&
7886 if (name[3] == 'o' &&
7922 if (name[2] == 'o' &&
7932 if (name[2] == 'y' &&
7946 if (name[1] == 'l' &&
7960 if (name[2] == 'n' &&
7970 if (name[2] == 'o' &&
7984 if (name[1] == 'i' &&
7989 return (FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
7998 if (name[2] == 'd' &&
8008 if (name[2] == 'c' &&
8025 if (name[2] == 'c' &&
8035 if (name[2] == 't' &&
8049 if (name[1] == 'k' &&
8060 if (name[1] == 'r' &&
8074 if (name[2] == 's' &&
8084 if (name[2] == 'd' &&
8101 if (name[2] == 'm' &&
8111 if (name[2] == 'i' &&
8121 if (name[2] == 'e' &&
8131 if (name[2] == 'l' &&
8141 if (name[2] == 'a' &&
8154 if (name[3] == 't' &&
8157 return (FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8163 if (name[3] == 'd' &&
8180 if (name[1] == 'i' &&
8194 if (name[2] == 'a' &&
8207 if (name[3] == 'e' &&
8242 if (name[2] == 'i' &&
8259 if (name[2] == 'i' &&
8269 if (name[2] == 'i' &&
8286 case 6: /* 33 tokens of length 6 */
8290 if (name[1] == 'c' &&
8305 if (name[2] == 'l' &&
8316 if (name[2] == 'r' &&
8331 if (name[1] == 'e' &&
8346 if (name[2] == 's' &&
8351 if(ckWARN_d(WARN_SYNTAX))
8352 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8358 if (name[2] == 'i' &&
8376 if (name[2] == 'l' &&
8387 if (name[2] == 'r' &&
8402 if (name[1] == 'm' &&
8417 if (name[2] == 'n' &&
8428 if (name[2] == 's' &&
8443 if (name[1] == 's' &&
8449 if (name[4] == 't' &&
8458 if (name[4] == 'e' &&
8467 if (name[4] == 'c' &&
8476 if (name[4] == 'n' &&
8492 if (name[1] == 'r' &&
8510 if (name[3] == 'a' &&
8520 if (name[3] == 'u' &&
8534 if (name[2] == 'n' &&
8552 if (name[2] == 'a' &&
8566 if (name[3] == 'e' &&
8579 if (name[4] == 't' &&
8588 if (name[4] == 'e' &&
8610 if (name[4] == 't' &&
8619 if (name[4] == 'e' &&
8635 if (name[2] == 'c' &&
8646 if (name[2] == 'l' &&
8657 if (name[2] == 'b' &&
8668 if (name[2] == 's' &&
8691 if (name[4] == 's' &&
8700 if (name[4] == 'n' &&
8713 if (name[3] == 'a' &&
8730 if (name[1] == 'a' &&
8745 case 7: /* 29 tokens of length 7 */
8749 if (name[1] == 'E' &&
8762 if (name[1] == '_' &&
8775 if (name[1] == 'i' &&
8782 return -KEY_binmode;
8788 if (name[1] == 'o' &&
8795 return -KEY_connect;
8804 if (name[2] == 'm' &&
8810 return -KEY_dbmopen;
8821 if (name[4] == 'u' &&
8825 return (FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
8831 if (name[4] == 'n' &&
8852 if (name[1] == 'o' &&
8865 if (name[1] == 'e' &&
8872 if (name[5] == 'r' &&
8875 return -KEY_getpgrp;
8881 if (name[5] == 'i' &&
8884 return -KEY_getppid;
8897 if (name[1] == 'c' &&
8904 return -KEY_lcfirst;
8910 if (name[1] == 'p' &&
8917 return -KEY_opendir;
8923 if (name[1] == 'a' &&
8941 if (name[3] == 'd' &&
8946 return -KEY_readdir;
8952 if (name[3] == 'u' &&
8963 if (name[3] == 'e' &&
8968 return -KEY_reverse;
8987 if (name[3] == 'k' &&
8992 return -KEY_seekdir;
8998 if (name[3] == 'p' &&
9003 return -KEY_setpgrp;
9013 if (name[2] == 'm' &&
9019 return -KEY_shmread;
9025 if (name[2] == 'r' &&
9031 return -KEY_sprintf;
9040 if (name[3] == 'l' &&
9045 return -KEY_symlink;
9054 if (name[4] == 'a' &&
9058 return -KEY_syscall;
9064 if (name[4] == 'p' &&
9068 return -KEY_sysopen;
9074 if (name[4] == 'e' &&
9078 return -KEY_sysread;
9084 if (name[4] == 'e' &&
9088 return -KEY_sysseek;
9106 if (name[1] == 'e' &&
9113 return -KEY_telldir;
9122 if (name[2] == 'f' &&
9128 return -KEY_ucfirst;
9134 if (name[2] == 's' &&
9140 return -KEY_unshift;
9150 if (name[1] == 'a' &&
9157 return -KEY_waitpid;
9166 case 8: /* 26 tokens of length 8 */
9170 if (name[1] == 'U' &&
9178 return KEY_AUTOLOAD;
9189 if (name[3] == 'A' &&
9195 return KEY___DATA__;
9201 if (name[3] == 'I' &&
9207 return -KEY___FILE__;
9213 if (name[3] == 'I' &&
9219 return -KEY___LINE__;
9235 if (name[2] == 'o' &&
9242 return -KEY_closedir;
9248 if (name[2] == 'n' &&
9255 return -KEY_continue;
9265 if (name[1] == 'b' &&
9273 return -KEY_dbmclose;
9279 if (name[1] == 'n' &&
9285 if (name[4] == 'r' &&
9290 return -KEY_endgrent;
9296 if (name[4] == 'w' &&
9301 return -KEY_endpwent;
9314 if (name[1] == 'o' &&
9322 return -KEY_formline;
9328 if (name[1] == 'e' &&
9339 if (name[6] == 'n' &&
9342 return -KEY_getgrent;
9348 if (name[6] == 'i' &&
9351 return -KEY_getgrgid;
9357 if (name[6] == 'a' &&
9360 return -KEY_getgrnam;
9373 if (name[4] == 'o' &&
9378 return -KEY_getlogin;
9389 if (name[6] == 'n' &&
9392 return -KEY_getpwent;
9398 if (name[6] == 'a' &&
9401 return -KEY_getpwnam;
9407 if (name[6] == 'i' &&
9410 return -KEY_getpwuid;
9430 if (name[1] == 'e' &&
9437 if (name[5] == 'i' &&
9444 return -KEY_readline;
9449 return -KEY_readlink;
9460 if (name[5] == 'i' &&
9464 return -KEY_readpipe;
9485 if (name[4] == 'r' &&
9490 return -KEY_setgrent;
9496 if (name[4] == 'w' &&
9501 return -KEY_setpwent;
9517 if (name[3] == 'w' &&
9523 return -KEY_shmwrite;
9529 if (name[3] == 't' &&
9535 return -KEY_shutdown;
9545 if (name[2] == 's' &&
9552 return -KEY_syswrite;
9562 if (name[1] == 'r' &&
9570 return -KEY_truncate;
9579 case 9: /* 8 tokens of length 9 */
9583 if (name[1] == 'n' &&
9592 return -KEY_endnetent;
9598 if (name[1] == 'e' &&
9607 return -KEY_getnetent;
9613 if (name[1] == 'o' &&
9622 return -KEY_localtime;
9628 if (name[1] == 'r' &&
9637 return KEY_prototype;
9643 if (name[1] == 'u' &&
9652 return -KEY_quotemeta;
9658 if (name[1] == 'e' &&
9667 return -KEY_rewinddir;
9673 if (name[1] == 'e' &&
9682 return -KEY_setnetent;
9688 if (name[1] == 'a' &&
9697 return -KEY_wantarray;
9706 case 10: /* 9 tokens of length 10 */
9710 if (name[1] == 'n' &&
9716 if (name[4] == 'o' &&
9723 return -KEY_endhostent;
9729 if (name[4] == 'e' &&
9736 return -KEY_endservent;
9749 if (name[1] == 'e' &&
9755 if (name[4] == 'o' &&
9762 return -KEY_gethostent;
9771 if (name[5] == 'r' &&
9777 return -KEY_getservent;
9783 if (name[5] == 'c' &&
9789 return -KEY_getsockopt;
9814 if (name[4] == 'o' &&
9821 return -KEY_sethostent;
9830 if (name[5] == 'r' &&
9836 return -KEY_setservent;
9842 if (name[5] == 'c' &&
9848 return -KEY_setsockopt;
9865 if (name[2] == 'c' &&
9874 return -KEY_socketpair;
9887 case 11: /* 8 tokens of length 11 */
9891 if (name[1] == '_' &&
9902 return -KEY___PACKAGE__;
9908 if (name[1] == 'n' &&
9919 return -KEY_endprotoent;
9925 if (name[1] == 'e' &&
9934 if (name[5] == 'e' &&
9941 return -KEY_getpeername;
9950 if (name[6] == 'o' &&
9956 return -KEY_getpriority;
9962 if (name[6] == 't' &&
9968 return -KEY_getprotoent;
9982 if (name[4] == 'o' &&
9990 return -KEY_getsockname;
10003 if (name[1] == 'e' &&
10011 if (name[6] == 'o' &&
10016 { /* setpriority */
10017 return -KEY_setpriority;
10023 if (name[6] == 't' &&
10028 { /* setprotoent */
10029 return -KEY_setprotoent;
10045 case 12: /* 2 tokens of length 12 */
10046 if (name[0] == 'g' &&
10058 if (name[9] == 'd' &&
10061 { /* getnetbyaddr */
10062 return -KEY_getnetbyaddr;
10068 if (name[9] == 'a' &&
10071 { /* getnetbyname */
10072 return -KEY_getnetbyname;
10084 case 13: /* 4 tokens of length 13 */
10085 if (name[0] == 'g' &&
10092 if (name[4] == 'o' &&
10101 if (name[10] == 'd' &&
10104 { /* gethostbyaddr */
10105 return -KEY_gethostbyaddr;
10111 if (name[10] == 'a' &&
10114 { /* gethostbyname */
10115 return -KEY_gethostbyname;
10128 if (name[4] == 'e' &&
10137 if (name[10] == 'a' &&
10140 { /* getservbyname */
10141 return -KEY_getservbyname;
10147 if (name[10] == 'o' &&
10150 { /* getservbyport */
10151 return -KEY_getservbyport;
10170 case 14: /* 1 tokens of length 14 */
10171 if (name[0] == 'g' &&
10185 { /* getprotobyname */
10186 return -KEY_getprotobyname;
10191 case 16: /* 1 tokens of length 16 */
10192 if (name[0] == 'g' &&
10208 { /* getprotobynumber */
10209 return -KEY_getprotobynumber;
10223 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10227 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10228 if (ckWARN(WARN_SYNTAX)) {
10231 for (w = s+2; *w && level; w++) {
10234 else if (*w == ')')
10237 while (isSPACE(*w))
10239 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
10240 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10241 "%s (...) interpreted as function",name);
10244 while (s < PL_bufend && isSPACE(*s))
10248 while (s < PL_bufend && isSPACE(*s))
10250 if (isIDFIRST_lazy_if(s,UTF)) {
10251 const char * const w = s++;
10252 while (isALNUM_lazy_if(s,UTF))
10254 while (s < PL_bufend && isSPACE(*s))
10258 if (keyword(w, s - w))
10261 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10262 if (gv && GvCVu(gv))
10264 Perl_croak(aTHX_ "No comma allowed after %s", what);
10269 /* Either returns sv, or mortalizes sv and returns a new SV*.
10270 Best used as sv=new_constant(..., sv, ...).
10271 If s, pv are NULL, calls subroutine with one argument,
10272 and type is used with error messages only. */
10275 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10279 HV * const table = GvHV(PL_hintgv); /* ^H */
10283 const char *why1 = "", *why2 = "", *why3 = "";
10285 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10288 why2 = strEQ(key,"charnames")
10289 ? "(possibly a missing \"use charnames ...\")"
10291 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10292 (type ? type: "undef"), why2);
10294 /* This is convoluted and evil ("goto considered harmful")
10295 * but I do not understand the intricacies of all the different
10296 * failure modes of %^H in here. The goal here is to make
10297 * the most probable error message user-friendly. --jhi */
10302 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10303 (type ? type: "undef"), why1, why2, why3);
10305 yyerror(SvPVX_const(msg));
10309 cvp = hv_fetch(table, key, strlen(key), FALSE);
10310 if (!cvp || !SvOK(*cvp)) {
10313 why3 = "} is not defined";
10316 sv_2mortal(sv); /* Parent created it permanently */
10319 pv = sv_2mortal(newSVpvn(s, len));
10321 typesv = sv_2mortal(newSVpv(type, 0));
10323 typesv = &PL_sv_undef;
10325 PUSHSTACKi(PERLSI_OVERLOAD);
10337 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10341 /* Check the eval first */
10342 if (!PL_in_eval && SvTRUE(ERRSV)) {
10343 sv_catpvs(ERRSV, "Propagated");
10344 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10346 res = SvREFCNT_inc_simple(sv);
10350 SvREFCNT_inc_simple_void(res);
10359 why1 = "Call to &{$^H{";
10361 why3 = "}} did not return a defined value";
10369 /* Returns a NUL terminated string, with the length of the string written to
10373 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10376 register char *d = dest;
10377 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10380 Perl_croak(aTHX_ ident_too_long);
10381 if (isALNUM(*s)) /* UTF handled below */
10383 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10388 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10392 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10393 char *t = s + UTF8SKIP(s);
10395 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10399 Perl_croak(aTHX_ ident_too_long);
10400 Copy(s, d, len, char);
10413 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10416 char *bracket = NULL;
10418 register char *d = dest;
10419 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10424 while (isDIGIT(*s)) {
10426 Perl_croak(aTHX_ ident_too_long);
10433 Perl_croak(aTHX_ ident_too_long);
10434 if (isALNUM(*s)) /* UTF handled below */
10436 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10441 else if (*s == ':' && s[1] == ':') {
10445 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10446 char *t = s + UTF8SKIP(s);
10447 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10449 if (d + (t - s) > e)
10450 Perl_croak(aTHX_ ident_too_long);
10451 Copy(s, d, t - s, char);
10462 if (PL_lex_state != LEX_NORMAL)
10463 PL_lex_state = LEX_INTERPENDMAYBE;
10466 if (*s == '$' && s[1] &&
10467 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10480 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10485 if (isSPACE(s[-1])) {
10487 const char ch = *s++;
10488 if (!SPACE_OR_TAB(ch)) {
10494 if (isIDFIRST_lazy_if(d,UTF)) {
10498 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10499 end += UTF8SKIP(end);
10500 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10501 end += UTF8SKIP(end);
10503 Copy(s, d, end - s, char);
10508 while ((isALNUM(*s) || *s == ':') && d < e)
10511 Perl_croak(aTHX_ ident_too_long);
10514 while (s < send && SPACE_OR_TAB(*s))
10516 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10517 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
10518 const char * const brack = (*s == '[') ? "[...]" : "{...}";
10519 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10520 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10521 funny, dest, brack, funny, dest, brack);
10524 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10528 /* Handle extended ${^Foo} variables
10529 * 1999-02-27 mjd-perl-patch@plover.com */
10530 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10534 while (isALNUM(*s) && d < e) {
10538 Perl_croak(aTHX_ ident_too_long);
10543 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10544 PL_lex_state = LEX_INTERPEND;
10547 if (PL_lex_state == LEX_NORMAL) {
10548 if (ckWARN(WARN_AMBIGUOUS) &&
10549 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
10553 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10554 "Ambiguous use of %c{%s} resolved to %c%s",
10555 funny, dest, funny, dest);
10560 s = bracket; /* let the parser handle it */
10564 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10565 PL_lex_state = LEX_INTERPEND;
10570 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10572 PERL_UNUSED_CONTEXT;
10575 else if (ch == 'g')
10576 *pmfl |= PMf_GLOBAL;
10577 else if (ch == 'c')
10578 *pmfl |= PMf_CONTINUE;
10579 else if (ch == 'o')
10581 else if (ch == 'm')
10582 *pmfl |= PMf_MULTILINE;
10583 else if (ch == 's')
10584 *pmfl |= PMf_SINGLELINE;
10585 else if (ch == 'x')
10586 *pmfl |= PMf_EXTENDED;
10590 S_scan_pat(pTHX_ char *start, I32 type)
10594 char *s = scan_str(start,!!PL_madskills,FALSE);
10595 const char * const valid_flags = (type == OP_QR) ? "iomsx" : "iogcmsx";
10602 const char * const delimiter = skipspace(start);
10603 Perl_croak(aTHX_ *delimiter == '?'
10604 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10605 : "Search pattern not terminated" );
10608 pm = (PMOP*)newPMOP(type, 0);
10609 if (PL_multi_open == '?')
10610 pm->op_pmflags |= PMf_ONCE;
10614 while (*s && strchr(valid_flags, *s))
10615 pmflag(&pm->op_pmflags,*s++);
10617 if (PL_madskills && modstart != s) {
10618 SV* tmptoken = newSVpvn(modstart, s - modstart);
10619 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10622 /* issue a warning if /c is specified,but /g is not */
10623 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10624 && ckWARN(WARN_REGEXP))
10626 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" );
10629 pm->op_pmpermflags = pm->op_pmflags;
10631 PL_lex_op = (OP*)pm;
10632 yylval.ival = OP_MATCH;
10637 S_scan_subst(pTHX_ char *start)
10648 yylval.ival = OP_NULL;
10650 s = scan_str(start,!!PL_madskills,FALSE);
10653 Perl_croak(aTHX_ "Substitution pattern not terminated");
10655 if (s[-1] == PL_multi_open)
10658 if (PL_madskills) {
10659 CURMAD('q', PL_thisopen);
10660 CURMAD('_', PL_thiswhite);
10661 CURMAD('E', PL_thisstuff);
10662 CURMAD('Q', PL_thisclose);
10663 PL_realtokenstart = s - SvPVX(PL_linestr);
10667 first_start = PL_multi_start;
10668 s = scan_str(s,!!PL_madskills,FALSE);
10670 if (PL_lex_stuff) {
10671 SvREFCNT_dec(PL_lex_stuff);
10672 PL_lex_stuff = NULL;
10674 Perl_croak(aTHX_ "Substitution replacement not terminated");
10676 PL_multi_start = first_start; /* so whole substitution is taken together */
10678 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10681 if (PL_madskills) {
10682 CURMAD('z', PL_thisopen);
10683 CURMAD('R', PL_thisstuff);
10684 CURMAD('Z', PL_thisclose);
10694 else if (strchr("iogcmsx", *s))
10695 pmflag(&pm->op_pmflags,*s++);
10701 if (PL_madskills) {
10703 curmad('m', newSVpvn(modstart, s - modstart));
10704 append_madprops(PL_thismad, (OP*)pm, 0);
10708 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10709 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10713 SV * const repl = newSVpvs("");
10715 PL_sublex_info.super_bufptr = s;
10716 PL_sublex_info.super_bufend = PL_bufend;
10718 pm->op_pmflags |= PMf_EVAL;
10720 sv_catpv(repl, es ? "eval " : "do ");
10721 sv_catpvs(repl, "{");
10722 sv_catsv(repl, PL_lex_repl);
10723 if (strchr(SvPVX(PL_lex_repl), '#'))
10724 sv_catpvs(repl, "\n");
10725 sv_catpvs(repl, "}");
10727 SvREFCNT_dec(PL_lex_repl);
10728 PL_lex_repl = repl;
10731 pm->op_pmpermflags = pm->op_pmflags;
10732 PL_lex_op = (OP*)pm;
10733 yylval.ival = OP_SUBST;
10738 S_scan_trans(pTHX_ char *start)
10751 yylval.ival = OP_NULL;
10753 s = scan_str(start,!!PL_madskills,FALSE);
10755 Perl_croak(aTHX_ "Transliteration pattern not terminated");
10757 if (s[-1] == PL_multi_open)
10760 if (PL_madskills) {
10761 CURMAD('q', PL_thisopen);
10762 CURMAD('_', PL_thiswhite);
10763 CURMAD('E', PL_thisstuff);
10764 CURMAD('Q', PL_thisclose);
10765 PL_realtokenstart = s - SvPVX(PL_linestr);
10769 s = scan_str(s,!!PL_madskills,FALSE);
10771 if (PL_lex_stuff) {
10772 SvREFCNT_dec(PL_lex_stuff);
10773 PL_lex_stuff = NULL;
10775 Perl_croak(aTHX_ "Transliteration replacement not terminated");
10777 if (PL_madskills) {
10778 CURMAD('z', PL_thisopen);
10779 CURMAD('R', PL_thisstuff);
10780 CURMAD('Z', PL_thisclose);
10783 complement = del = squash = 0;
10790 complement = OPpTRANS_COMPLEMENT;
10793 del = OPpTRANS_DELETE;
10796 squash = OPpTRANS_SQUASH;
10805 Newx(tbl, complement&&!del?258:256, short);
10806 o = newPVOP(OP_TRANS, 0, (char*)tbl);
10807 o->op_private &= ~OPpTRANS_ALL;
10808 o->op_private |= del|squash|complement|
10809 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
10810 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
10813 yylval.ival = OP_TRANS;
10816 if (PL_madskills) {
10818 curmad('m', newSVpvn(modstart, s - modstart));
10819 append_madprops(PL_thismad, o, 0);
10828 S_scan_heredoc(pTHX_ register char *s)
10832 I32 op_type = OP_SCALAR;
10836 const char *found_newline;
10840 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
10842 I32 stuffstart = s - SvPVX(PL_linestr);
10845 PL_realtokenstart = -1;
10850 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
10854 while (SPACE_OR_TAB(*peek))
10856 if (*peek == '`' || *peek == '\'' || *peek =='"') {
10859 s = delimcpy(d, e, s, PL_bufend, term, &len);
10869 if (!isALNUM_lazy_if(s,UTF))
10870 deprecate_old("bare << to mean <<\"\"");
10871 for (; isALNUM_lazy_if(s,UTF); s++) {
10876 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
10877 Perl_croak(aTHX_ "Delimiter for here document is too long");
10880 len = d - PL_tokenbuf;
10883 if (PL_madskills) {
10884 tstart = PL_tokenbuf + !outer;
10885 PL_thisclose = newSVpvn(tstart, len - !outer);
10886 tstart = SvPVX(PL_linestr) + stuffstart;
10887 PL_thisopen = newSVpvn(tstart, s - tstart);
10888 stuffstart = s - SvPVX(PL_linestr);
10891 #ifndef PERL_STRICT_CR
10892 d = strchr(s, '\r');
10894 char * const olds = s;
10896 while (s < PL_bufend) {
10902 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
10911 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
10918 if ( outer || !(found_newline = memchr(s, '\n', PL_bufend - s)) ) {
10919 herewas = newSVpvn(s,PL_bufend-s);
10923 herewas = newSVpvn(s-1,found_newline-s+1);
10926 herewas = newSVpvn(s,found_newline-s);
10930 if (PL_madskills) {
10931 tstart = SvPVX(PL_linestr) + stuffstart;
10933 sv_catpvn(PL_thisstuff, tstart, s - tstart);
10935 PL_thisstuff = newSVpvn(tstart, s - tstart);
10938 s += SvCUR(herewas);
10941 stuffstart = s - SvPVX(PL_linestr);
10947 tmpstr = newSV(79);
10948 sv_upgrade(tmpstr, SVt_PVIV);
10949 if (term == '\'') {
10950 op_type = OP_CONST;
10951 SvIV_set(tmpstr, -1);
10953 else if (term == '`') {
10954 op_type = OP_BACKTICK;
10955 SvIV_set(tmpstr, '\\');
10959 PL_multi_start = CopLINE(PL_curcop);
10960 PL_multi_open = PL_multi_close = '<';
10961 term = *PL_tokenbuf;
10962 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
10963 char * const bufptr = PL_sublex_info.super_bufptr;
10964 char * const bufend = PL_sublex_info.super_bufend;
10965 char * const olds = s - SvCUR(herewas);
10966 s = strchr(bufptr, '\n');
10970 while (s < bufend &&
10971 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
10973 CopLINE_inc(PL_curcop);
10976 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10977 missingterm(PL_tokenbuf);
10979 sv_setpvn(herewas,bufptr,d-bufptr+1);
10980 sv_setpvn(tmpstr,d+1,s-d);
10982 sv_catpvn(herewas,s,bufend-s);
10983 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
10990 while (s < PL_bufend &&
10991 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
10993 CopLINE_inc(PL_curcop);
10995 if (s >= PL_bufend) {
10996 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10997 missingterm(PL_tokenbuf);
10999 sv_setpvn(tmpstr,d+1,s-d);
11001 if (PL_madskills) {
11003 sv_catpvn(PL_thisstuff, d + 1, s - d);
11005 PL_thisstuff = newSVpvn(d + 1, s - d);
11006 stuffstart = s - SvPVX(PL_linestr);
11010 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11012 sv_catpvn(herewas,s,PL_bufend-s);
11013 sv_setsv(PL_linestr,herewas);
11014 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11015 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11016 PL_last_lop = PL_last_uni = NULL;
11019 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
11020 while (s >= PL_bufend) { /* multiple line string? */
11022 if (PL_madskills) {
11023 tstart = SvPVX(PL_linestr) + stuffstart;
11025 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11027 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11031 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11032 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11033 missingterm(PL_tokenbuf);
11036 stuffstart = s - SvPVX(PL_linestr);
11038 CopLINE_inc(PL_curcop);
11039 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11040 PL_last_lop = PL_last_uni = NULL;
11041 #ifndef PERL_STRICT_CR
11042 if (PL_bufend - PL_linestart >= 2) {
11043 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11044 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11046 PL_bufend[-2] = '\n';
11048 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11050 else if (PL_bufend[-1] == '\r')
11051 PL_bufend[-1] = '\n';
11053 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11054 PL_bufend[-1] = '\n';
11056 if (PERLDB_LINE && PL_curstash != PL_debstash) {
11057 SV * const sv = newSV(0);
11059 sv_upgrade(sv, SVt_PVMG);
11060 sv_setsv(sv,PL_linestr);
11061 (void)SvIOK_on(sv);
11063 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop),sv);
11065 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11066 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11067 *(SvPVX(PL_linestr) + off ) = ' ';
11068 sv_catsv(PL_linestr,herewas);
11069 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11070 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11074 sv_catsv(tmpstr,PL_linestr);
11079 PL_multi_end = CopLINE(PL_curcop);
11080 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11081 SvPV_shrink_to_cur(tmpstr);
11083 SvREFCNT_dec(herewas);
11085 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11087 else if (PL_encoding)
11088 sv_recode_to_utf8(tmpstr, PL_encoding);
11090 PL_lex_stuff = tmpstr;
11091 yylval.ival = op_type;
11095 /* scan_inputsymbol
11096 takes: current position in input buffer
11097 returns: new position in input buffer
11098 side-effects: yylval and lex_op are set.
11103 <FH> read from filehandle
11104 <pkg::FH> read from package qualified filehandle
11105 <pkg'FH> read from package qualified filehandle
11106 <$fh> read from filehandle in $fh
11107 <*.h> filename glob
11112 S_scan_inputsymbol(pTHX_ char *start)
11115 register char *s = start; /* current position in buffer */
11119 char *d = PL_tokenbuf; /* start of temp holding space */
11120 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11122 end = strchr(s, '\n');
11125 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11127 /* die if we didn't have space for the contents of the <>,
11128 or if it didn't end, or if we see a newline
11131 if (len >= (I32)sizeof PL_tokenbuf)
11132 Perl_croak(aTHX_ "Excessively long <> operator");
11134 Perl_croak(aTHX_ "Unterminated <> operator");
11139 Remember, only scalar variables are interpreted as filehandles by
11140 this code. Anything more complex (e.g., <$fh{$num}>) will be
11141 treated as a glob() call.
11142 This code makes use of the fact that except for the $ at the front,
11143 a scalar variable and a filehandle look the same.
11145 if (*d == '$' && d[1]) d++;
11147 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11148 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11151 /* If we've tried to read what we allow filehandles to look like, and
11152 there's still text left, then it must be a glob() and not a getline.
11153 Use scan_str to pull out the stuff between the <> and treat it
11154 as nothing more than a string.
11157 if (d - PL_tokenbuf != len) {
11158 yylval.ival = OP_GLOB;
11160 s = scan_str(start,!!PL_madskills,FALSE);
11162 Perl_croak(aTHX_ "Glob not terminated");
11166 bool readline_overriden = FALSE;
11169 /* we're in a filehandle read situation */
11172 /* turn <> into <ARGV> */
11174 Copy("ARGV",d,5,char);
11176 /* Check whether readline() is overriden */
11177 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11179 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11181 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11182 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
11183 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11184 readline_overriden = TRUE;
11186 /* if <$fh>, create the ops to turn the variable into a
11192 /* try to find it in the pad for this block, otherwise find
11193 add symbol table ops
11195 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
11196 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11197 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11198 HEK * const stashname = HvNAME_HEK(stash);
11199 SV * const sym = sv_2mortal(newSVhek(stashname));
11200 sv_catpvs(sym, "::");
11201 sv_catpv(sym, d+1);
11206 OP * const o = newOP(OP_PADSV, 0);
11208 PL_lex_op = readline_overriden
11209 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11210 append_elem(OP_LIST, o,
11211 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11212 : (OP*)newUNOP(OP_READLINE, 0, o);
11221 ? (GV_ADDMULTI | GV_ADDINEVAL)
11224 PL_lex_op = readline_overriden
11225 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11226 append_elem(OP_LIST,
11227 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11228 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11229 : (OP*)newUNOP(OP_READLINE, 0,
11230 newUNOP(OP_RV2SV, 0,
11231 newGVOP(OP_GV, 0, gv)));
11233 if (!readline_overriden)
11234 PL_lex_op->op_flags |= OPf_SPECIAL;
11235 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11236 yylval.ival = OP_NULL;
11239 /* If it's none of the above, it must be a literal filehandle
11240 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11242 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11243 PL_lex_op = readline_overriden
11244 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11245 append_elem(OP_LIST,
11246 newGVOP(OP_GV, 0, gv),
11247 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11248 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11249 yylval.ival = OP_NULL;
11258 takes: start position in buffer
11259 keep_quoted preserve \ on the embedded delimiter(s)
11260 keep_delims preserve the delimiters around the string
11261 returns: position to continue reading from buffer
11262 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11263 updates the read buffer.
11265 This subroutine pulls a string out of the input. It is called for:
11266 q single quotes q(literal text)
11267 ' single quotes 'literal text'
11268 qq double quotes qq(interpolate $here please)
11269 " double quotes "interpolate $here please"
11270 qx backticks qx(/bin/ls -l)
11271 ` backticks `/bin/ls -l`
11272 qw quote words @EXPORT_OK = qw( func() $spam )
11273 m// regexp match m/this/
11274 s/// regexp substitute s/this/that/
11275 tr/// string transliterate tr/this/that/
11276 y/// string transliterate y/this/that/
11277 ($*@) sub prototypes sub foo ($)
11278 (stuff) sub attr parameters sub foo : attr(stuff)
11279 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11281 In most of these cases (all but <>, patterns and transliterate)
11282 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11283 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11284 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11287 It skips whitespace before the string starts, and treats the first
11288 character as the delimiter. If the delimiter is one of ([{< then
11289 the corresponding "close" character )]}> is used as the closing
11290 delimiter. It allows quoting of delimiters, and if the string has
11291 balanced delimiters ([{<>}]) it allows nesting.
11293 On success, the SV with the resulting string is put into lex_stuff or,
11294 if that is already non-NULL, into lex_repl. The second case occurs only
11295 when parsing the RHS of the special constructs s/// and tr/// (y///).
11296 For convenience, the terminating delimiter character is stuffed into
11301 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11304 SV *sv; /* scalar value: string */
11305 char *tmps; /* temp string, used for delimiter matching */
11306 register char *s = start; /* current position in the buffer */
11307 register char term; /* terminating character */
11308 register char *to; /* current position in the sv's data */
11309 I32 brackets = 1; /* bracket nesting level */
11310 bool has_utf8 = FALSE; /* is there any utf8 content? */
11311 I32 termcode; /* terminating char. code */
11312 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11313 STRLEN termlen; /* length of terminating string */
11314 char *last = NULL; /* last position for nesting bracket */
11320 /* skip space before the delimiter */
11326 if (PL_realtokenstart >= 0) {
11327 stuffstart = PL_realtokenstart;
11328 PL_realtokenstart = -1;
11331 stuffstart = start - SvPVX(PL_linestr);
11333 /* mark where we are, in case we need to report errors */
11336 /* after skipping whitespace, the next character is the terminator */
11339 termcode = termstr[0] = term;
11343 termcode = utf8_to_uvchr((U8*)s, &termlen);
11344 Copy(s, termstr, termlen, U8);
11345 if (!UTF8_IS_INVARIANT(term))
11349 /* mark where we are */
11350 PL_multi_start = CopLINE(PL_curcop);
11351 PL_multi_open = term;
11353 /* find corresponding closing delimiter */
11354 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11355 termcode = termstr[0] = term = tmps[5];
11357 PL_multi_close = term;
11359 /* create a new SV to hold the contents. 79 is the SV's initial length.
11360 What a random number. */
11362 sv_upgrade(sv, SVt_PVIV);
11363 SvIV_set(sv, termcode);
11364 (void)SvPOK_only(sv); /* validate pointer */
11366 /* move past delimiter and try to read a complete string */
11368 sv_catpvn(sv, s, termlen);
11371 tstart = SvPVX(PL_linestr) + stuffstart;
11372 if (!PL_thisopen && !keep_delims) {
11373 PL_thisopen = newSVpvn(tstart, s - tstart);
11374 stuffstart = s - SvPVX(PL_linestr);
11378 if (PL_encoding && !UTF) {
11382 int offset = s - SvPVX_const(PL_linestr);
11383 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11384 &offset, (char*)termstr, termlen);
11385 const char * const ns = SvPVX_const(PL_linestr) + offset;
11386 char * const svlast = SvEND(sv) - 1;
11388 for (; s < ns; s++) {
11389 if (*s == '\n' && !PL_rsfp)
11390 CopLINE_inc(PL_curcop);
11393 goto read_more_line;
11395 /* handle quoted delimiters */
11396 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11398 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11400 if ((svlast-1 - t) % 2) {
11401 if (!keep_quoted) {
11402 *(svlast-1) = term;
11404 SvCUR_set(sv, SvCUR(sv) - 1);
11409 if (PL_multi_open == PL_multi_close) {
11417 for (t = w = last; t < svlast; w++, t++) {
11418 /* At here, all closes are "was quoted" one,
11419 so we don't check PL_multi_close. */
11421 if (!keep_quoted && *(t+1) == PL_multi_open)
11426 else if (*t == PL_multi_open)
11434 SvCUR_set(sv, w - SvPVX_const(sv));
11437 if (--brackets <= 0)
11442 if (!keep_delims) {
11443 SvCUR_set(sv, SvCUR(sv) - 1);
11449 /* extend sv if need be */
11450 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11451 /* set 'to' to the next character in the sv's string */
11452 to = SvPVX(sv)+SvCUR(sv);
11454 /* if open delimiter is the close delimiter read unbridle */
11455 if (PL_multi_open == PL_multi_close) {
11456 for (; s < PL_bufend; s++,to++) {
11457 /* embedded newlines increment the current line number */
11458 if (*s == '\n' && !PL_rsfp)
11459 CopLINE_inc(PL_curcop);
11460 /* handle quoted delimiters */
11461 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11462 if (!keep_quoted && s[1] == term)
11464 /* any other quotes are simply copied straight through */
11468 /* terminate when run out of buffer (the for() condition), or
11469 have found the terminator */
11470 else if (*s == term) {
11473 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11476 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11482 /* if the terminator isn't the same as the start character (e.g.,
11483 matched brackets), we have to allow more in the quoting, and
11484 be prepared for nested brackets.
11487 /* read until we run out of string, or we find the terminator */
11488 for (; s < PL_bufend; s++,to++) {
11489 /* embedded newlines increment the line count */
11490 if (*s == '\n' && !PL_rsfp)
11491 CopLINE_inc(PL_curcop);
11492 /* backslashes can escape the open or closing characters */
11493 if (*s == '\\' && s+1 < PL_bufend) {
11494 if (!keep_quoted &&
11495 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11500 /* allow nested opens and closes */
11501 else if (*s == PL_multi_close && --brackets <= 0)
11503 else if (*s == PL_multi_open)
11505 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11510 /* terminate the copied string and update the sv's end-of-string */
11512 SvCUR_set(sv, to - SvPVX_const(sv));
11515 * this next chunk reads more into the buffer if we're not done yet
11519 break; /* handle case where we are done yet :-) */
11521 #ifndef PERL_STRICT_CR
11522 if (to - SvPVX_const(sv) >= 2) {
11523 if ((to[-2] == '\r' && to[-1] == '\n') ||
11524 (to[-2] == '\n' && to[-1] == '\r'))
11528 SvCUR_set(sv, to - SvPVX_const(sv));
11530 else if (to[-1] == '\r')
11533 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11538 /* if we're out of file, or a read fails, bail and reset the current
11539 line marker so we can report where the unterminated string began
11542 if (PL_madskills) {
11543 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11545 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11547 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11551 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11553 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11559 /* we read a line, so increment our line counter */
11560 CopLINE_inc(PL_curcop);
11562 /* update debugger info */
11563 if (PERLDB_LINE && PL_curstash != PL_debstash) {
11564 SV * const line_sv = newSV(0);
11566 sv_upgrade(line_sv, SVt_PVMG);
11567 sv_setsv(line_sv,PL_linestr);
11568 (void)SvIOK_on(line_sv);
11569 SvIV_set(line_sv, 0);
11570 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop), line_sv);
11573 /* having changed the buffer, we must update PL_bufend */
11574 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11575 PL_last_lop = PL_last_uni = NULL;
11578 /* at this point, we have successfully read the delimited string */
11580 if (!PL_encoding || UTF) {
11582 if (PL_madskills) {
11583 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11584 const int len = s - start;
11586 sv_catpvn(PL_thisstuff, tstart, len);
11588 PL_thisstuff = newSVpvn(tstart, len);
11589 if (!PL_thisclose && !keep_delims)
11590 PL_thisclose = newSVpvn(s,termlen);
11595 sv_catpvn(sv, s, termlen);
11600 if (PL_madskills) {
11601 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11602 const int len = s - tstart - termlen;
11604 sv_catpvn(PL_thisstuff, tstart, len);
11606 PL_thisstuff = newSVpvn(tstart, len);
11607 if (!PL_thisclose && !keep_delims)
11608 PL_thisclose = newSVpvn(s - termlen,termlen);
11612 if (has_utf8 || PL_encoding)
11615 PL_multi_end = CopLINE(PL_curcop);
11617 /* if we allocated too much space, give some back */
11618 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11619 SvLEN_set(sv, SvCUR(sv) + 1);
11620 SvPV_renew(sv, SvLEN(sv));
11623 /* decide whether this is the first or second quoted string we've read
11636 takes: pointer to position in buffer
11637 returns: pointer to new position in buffer
11638 side-effects: builds ops for the constant in yylval.op
11640 Read a number in any of the formats that Perl accepts:
11642 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11643 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11646 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11648 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11651 If it reads a number without a decimal point or an exponent, it will
11652 try converting the number to an integer and see if it can do so
11653 without loss of precision.
11657 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11660 register const char *s = start; /* current position in buffer */
11661 register char *d; /* destination in temp buffer */
11662 register char *e; /* end of temp buffer */
11663 NV nv; /* number read, as a double */
11664 SV *sv = NULL; /* place to put the converted number */
11665 bool floatit; /* boolean: int or float? */
11666 const char *lastub = NULL; /* position of last underbar */
11667 static char const number_too_long[] = "Number too long";
11669 /* We use the first character to decide what type of number this is */
11673 Perl_croak(aTHX_ "panic: scan_num");
11675 /* if it starts with a 0, it could be an octal number, a decimal in
11676 0.13 disguise, or a hexadecimal number, or a binary number. */
11680 u holds the "number so far"
11681 shift the power of 2 of the base
11682 (hex == 4, octal == 3, binary == 1)
11683 overflowed was the number more than we can hold?
11685 Shift is used when we add a digit. It also serves as an "are
11686 we in octal/hex/binary?" indicator to disallow hex characters
11687 when in octal mode.
11692 bool overflowed = FALSE;
11693 bool just_zero = TRUE; /* just plain 0 or binary number? */
11694 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11695 static const char* const bases[5] =
11696 { "", "binary", "", "octal", "hexadecimal" };
11697 static const char* const Bases[5] =
11698 { "", "Binary", "", "Octal", "Hexadecimal" };
11699 static const char* const maxima[5] =
11701 "0b11111111111111111111111111111111",
11705 const char *base, *Base, *max;
11707 /* check for hex */
11712 } else if (s[1] == 'b') {
11717 /* check for a decimal in disguise */
11718 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11720 /* so it must be octal */
11727 if (ckWARN(WARN_SYNTAX))
11728 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11729 "Misplaced _ in number");
11733 base = bases[shift];
11734 Base = Bases[shift];
11735 max = maxima[shift];
11737 /* read the rest of the number */
11739 /* x is used in the overflow test,
11740 b is the digit we're adding on. */
11745 /* if we don't mention it, we're done */
11749 /* _ are ignored -- but warned about if consecutive */
11751 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11752 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11753 "Misplaced _ in number");
11757 /* 8 and 9 are not octal */
11758 case '8': case '9':
11760 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11764 case '2': case '3': case '4':
11765 case '5': case '6': case '7':
11767 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11770 case '0': case '1':
11771 b = *s++ & 15; /* ASCII digit -> value of digit */
11775 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11776 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
11777 /* make sure they said 0x */
11780 b = (*s++ & 7) + 9;
11782 /* Prepare to put the digit we have onto the end
11783 of the number so far. We check for overflows.
11789 x = u << shift; /* make room for the digit */
11791 if ((x >> shift) != u
11792 && !(PL_hints & HINT_NEW_BINARY)) {
11795 if (ckWARN_d(WARN_OVERFLOW))
11796 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11797 "Integer overflow in %s number",
11800 u = x | b; /* add the digit to the end */
11803 n *= nvshift[shift];
11804 /* If an NV has not enough bits in its
11805 * mantissa to represent an UV this summing of
11806 * small low-order numbers is a waste of time
11807 * (because the NV cannot preserve the
11808 * low-order bits anyway): we could just
11809 * remember when did we overflow and in the
11810 * end just multiply n by the right
11818 /* if we get here, we had success: make a scalar value from
11823 /* final misplaced underbar check */
11824 if (s[-1] == '_') {
11825 if (ckWARN(WARN_SYNTAX))
11826 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11831 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
11832 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11833 "%s number > %s non-portable",
11839 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
11840 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11841 "%s number > %s non-portable",
11846 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
11847 sv = new_constant(start, s - start, "integer",
11849 else if (PL_hints & HINT_NEW_BINARY)
11850 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
11855 handle decimal numbers.
11856 we're also sent here when we read a 0 as the first digit
11858 case '1': case '2': case '3': case '4': case '5':
11859 case '6': case '7': case '8': case '9': case '.':
11862 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
11865 /* read next group of digits and _ and copy into d */
11866 while (isDIGIT(*s) || *s == '_') {
11867 /* skip underscores, checking for misplaced ones
11871 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11872 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11873 "Misplaced _ in number");
11877 /* check for end of fixed-length buffer */
11879 Perl_croak(aTHX_ number_too_long);
11880 /* if we're ok, copy the character */
11885 /* final misplaced underbar check */
11886 if (lastub && s == lastub + 1) {
11887 if (ckWARN(WARN_SYNTAX))
11888 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11891 /* read a decimal portion if there is one. avoid
11892 3..5 being interpreted as the number 3. followed
11895 if (*s == '.' && s[1] != '.') {
11900 if (ckWARN(WARN_SYNTAX))
11901 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11902 "Misplaced _ in number");
11906 /* copy, ignoring underbars, until we run out of digits.
11908 for (; isDIGIT(*s) || *s == '_'; s++) {
11909 /* fixed length buffer check */
11911 Perl_croak(aTHX_ number_too_long);
11913 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11914 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11915 "Misplaced _ in number");
11921 /* fractional part ending in underbar? */
11922 if (s[-1] == '_') {
11923 if (ckWARN(WARN_SYNTAX))
11924 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11925 "Misplaced _ in number");
11927 if (*s == '.' && isDIGIT(s[1])) {
11928 /* oops, it's really a v-string, but without the "v" */
11934 /* read exponent part, if present */
11935 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
11939 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
11940 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
11942 /* stray preinitial _ */
11944 if (ckWARN(WARN_SYNTAX))
11945 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11946 "Misplaced _ in number");
11950 /* allow positive or negative exponent */
11951 if (*s == '+' || *s == '-')
11954 /* stray initial _ */
11956 if (ckWARN(WARN_SYNTAX))
11957 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11958 "Misplaced _ in number");
11962 /* read digits of exponent */
11963 while (isDIGIT(*s) || *s == '_') {
11966 Perl_croak(aTHX_ number_too_long);
11970 if (((lastub && s == lastub + 1) ||
11971 (!isDIGIT(s[1]) && s[1] != '_'))
11972 && ckWARN(WARN_SYNTAX))
11973 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11974 "Misplaced _ in number");
11981 /* make an sv from the string */
11985 We try to do an integer conversion first if no characters
11986 indicating "float" have been found.
11991 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
11993 if (flags == IS_NUMBER_IN_UV) {
11995 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
11998 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
11999 if (uv <= (UV) IV_MIN)
12000 sv_setiv(sv, -(IV)uv);
12007 /* terminate the string */
12009 nv = Atof(PL_tokenbuf);
12013 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12014 (PL_hints & HINT_NEW_INTEGER) )
12015 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
12016 (floatit ? "float" : "integer"),
12020 /* if it starts with a v, it could be a v-string */
12023 sv = newSV(5); /* preallocate storage space */
12024 s = scan_vstring(s,sv);
12028 /* make the op for the constant and return */
12031 lvalp->opval = newSVOP(OP_CONST, 0, sv);
12033 lvalp->opval = NULL;
12039 S_scan_formline(pTHX_ register char *s)
12042 register char *eol;
12044 SV * const stuff = newSVpvs("");
12045 bool needargs = FALSE;
12046 bool eofmt = FALSE;
12048 char *tokenstart = s;
12051 if (PL_madskills) {
12052 savewhite = PL_thiswhite;
12057 while (!needargs) {
12060 #ifdef PERL_STRICT_CR
12061 while (SPACE_OR_TAB(*t))
12064 while (SPACE_OR_TAB(*t) || *t == '\r')
12067 if (*t == '\n' || t == PL_bufend) {
12072 if (PL_in_eval && !PL_rsfp) {
12073 eol = (char *) memchr(s,'\n',PL_bufend-s);
12078 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12080 for (t = s; t < eol; t++) {
12081 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12083 goto enough; /* ~~ must be first line in formline */
12085 if (*t == '@' || *t == '^')
12089 sv_catpvn(stuff, s, eol-s);
12090 #ifndef PERL_STRICT_CR
12091 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12092 char *end = SvPVX(stuff) + SvCUR(stuff);
12095 SvCUR_set(stuff, SvCUR(stuff) - 1);
12105 if (PL_madskills) {
12107 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12109 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12112 s = filter_gets(PL_linestr, PL_rsfp, 0);
12114 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12116 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12118 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12119 PL_last_lop = PL_last_uni = NULL;
12128 if (SvCUR(stuff)) {
12131 PL_lex_state = LEX_NORMAL;
12132 start_force(PL_curforce);
12133 NEXTVAL_NEXTTOKE.ival = 0;
12137 PL_lex_state = LEX_FORMLINE;
12139 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12141 else if (PL_encoding)
12142 sv_recode_to_utf8(stuff, PL_encoding);
12144 start_force(PL_curforce);
12145 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12147 start_force(PL_curforce);
12148 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12152 SvREFCNT_dec(stuff);
12154 PL_lex_formbrack = 0;
12158 if (PL_madskills) {
12160 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12162 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12163 PL_thiswhite = savewhite;
12175 PL_cshlen = strlen(PL_cshname);
12177 #if defined(USE_ITHREADS)
12178 PERL_UNUSED_CONTEXT;
12184 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12187 const I32 oldsavestack_ix = PL_savestack_ix;
12188 CV* const outsidecv = PL_compcv;
12191 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12193 SAVEI32(PL_subline);
12194 save_item(PL_subname);
12195 SAVESPTR(PL_compcv);
12197 PL_compcv = (CV*)newSV(0);
12198 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
12199 CvFLAGS(PL_compcv) |= flags;
12201 PL_subline = CopLINE(PL_curcop);
12202 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12203 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12204 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12206 return oldsavestack_ix;
12210 #pragma segment Perl_yylex
12213 Perl_yywarn(pTHX_ const char *s)
12216 PL_in_eval |= EVAL_WARNONLY;
12218 PL_in_eval &= ~EVAL_WARNONLY;
12223 Perl_yyerror(pTHX_ const char *s)
12226 const char *where = NULL;
12227 const char *context = NULL;
12231 if (!yychar || (yychar == ';' && !PL_rsfp))
12233 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12234 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12235 PL_oldbufptr != PL_bufptr) {
12238 The code below is removed for NetWare because it abends/crashes on NetWare
12239 when the script has error such as not having the closing quotes like:
12240 if ($var eq "value)
12241 Checking of white spaces is anyway done in NetWare code.
12244 while (isSPACE(*PL_oldoldbufptr))
12247 context = PL_oldoldbufptr;
12248 contlen = PL_bufptr - PL_oldoldbufptr;
12250 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12251 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12254 The code below is removed for NetWare because it abends/crashes on NetWare
12255 when the script has error such as not having the closing quotes like:
12256 if ($var eq "value)
12257 Checking of white spaces is anyway done in NetWare code.
12260 while (isSPACE(*PL_oldbufptr))
12263 context = PL_oldbufptr;
12264 contlen = PL_bufptr - PL_oldbufptr;
12266 else if (yychar > 255)
12267 where = "next token ???";
12268 else if (yychar == -2) { /* YYEMPTY */
12269 if (PL_lex_state == LEX_NORMAL ||
12270 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12271 where = "at end of line";
12272 else if (PL_lex_inpat)
12273 where = "within pattern";
12275 where = "within string";
12278 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12280 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12281 else if (isPRINT_LC(yychar))
12282 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12284 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12285 where = SvPVX_const(where_sv);
12287 msg = sv_2mortal(newSVpv(s, 0));
12288 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12289 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12291 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12293 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12294 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12295 Perl_sv_catpvf(aTHX_ msg,
12296 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12297 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12300 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12301 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, (void*)msg);
12304 if (PL_error_count >= 10) {
12305 if (PL_in_eval && SvCUR(ERRSV))
12306 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12307 (void*)ERRSV, OutCopFILE(PL_curcop));
12309 Perl_croak(aTHX_ "%s has too many errors.\n",
12310 OutCopFILE(PL_curcop));
12313 PL_in_my_stash = NULL;
12317 #pragma segment Main
12321 S_swallow_bom(pTHX_ U8 *s)
12324 const STRLEN slen = SvCUR(PL_linestr);
12327 if (s[1] == 0xFE) {
12328 /* UTF-16 little-endian? (or UTF32-LE?) */
12329 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12330 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12331 #ifndef PERL_NO_UTF16_FILTER
12332 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12335 if (PL_bufend > (char*)s) {
12339 filter_add(utf16rev_textfilter, NULL);
12340 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12341 utf16_to_utf8_reversed(s, news,
12342 PL_bufend - (char*)s - 1,
12344 sv_setpvn(PL_linestr, (const char*)news, newlen);
12346 s = (U8*)SvPVX(PL_linestr);
12347 Copy(news, s, newlen, U8);
12351 SvUTF8_on(PL_linestr);
12352 s = (U8*)SvPVX(PL_linestr);
12354 /* FIXME - is this a general bug fix? */
12357 PL_bufend = SvPVX(PL_linestr) + newlen;
12360 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12365 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12366 #ifndef PERL_NO_UTF16_FILTER
12367 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12370 if (PL_bufend > (char *)s) {
12374 filter_add(utf16_textfilter, NULL);
12375 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12376 utf16_to_utf8(s, news,
12377 PL_bufend - (char*)s,
12379 sv_setpvn(PL_linestr, (const char*)news, newlen);
12381 SvUTF8_on(PL_linestr);
12382 s = (U8*)SvPVX(PL_linestr);
12383 PL_bufend = SvPVX(PL_linestr) + newlen;
12386 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12391 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12392 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12393 s += 3; /* UTF-8 */
12399 if (s[2] == 0xFE && s[3] == 0xFF) {
12400 /* UTF-32 big-endian */
12401 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12404 else if (s[2] == 0 && s[3] != 0) {
12407 * are a good indicator of UTF-16BE. */
12408 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12413 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12416 * are a good indicator of UTF-16LE. */
12417 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12426 * Restore a source filter.
12430 restore_rsfp(pTHX_ void *f)
12433 PerlIO * const fp = (PerlIO*)f;
12435 if (PL_rsfp == PerlIO_stdin())
12436 PerlIO_clearerr(PL_rsfp);
12437 else if (PL_rsfp && (PL_rsfp != fp))
12438 PerlIO_close(PL_rsfp);
12442 #ifndef PERL_NO_UTF16_FILTER
12444 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12447 const STRLEN old = SvCUR(sv);
12448 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12449 DEBUG_P(PerlIO_printf(Perl_debug_log,
12450 "utf16_textfilter(%p): %d %d (%d)\n",
12451 FPTR2DPTR(void *, utf16_textfilter),
12452 idx, maxlen, (int) count));
12456 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12457 Copy(SvPVX_const(sv), tmps, old, char);
12458 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12459 SvCUR(sv) - old, &newlen);
12460 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12462 DEBUG_P({sv_dump(sv);});
12467 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12470 const STRLEN old = SvCUR(sv);
12471 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12472 DEBUG_P(PerlIO_printf(Perl_debug_log,
12473 "utf16rev_textfilter(%p): %d %d (%d)\n",
12474 FPTR2DPTR(void *, utf16rev_textfilter),
12475 idx, maxlen, (int) count));
12479 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12480 Copy(SvPVX_const(sv), tmps, old, char);
12481 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12482 SvCUR(sv) - old, &newlen);
12483 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12485 DEBUG_P({ sv_dump(sv); });
12491 Returns a pointer to the next character after the parsed
12492 vstring, as well as updating the passed in sv.
12494 Function must be called like
12497 s = scan_vstring(s,sv);
12499 The sv should already be large enough to store the vstring
12500 passed in, for performance reasons.
12505 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
12508 const char *pos = s;
12509 const char *start = s;
12510 if (*pos == 'v') pos++; /* get past 'v' */
12511 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12513 if ( *pos != '.') {
12514 /* this may not be a v-string if followed by => */
12515 const char *next = pos;
12516 while (next < PL_bufend && isSPACE(*next))
12518 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
12519 /* return string not v-string */
12520 sv_setpvn(sv,(char *)s,pos-s);
12521 return (char *)pos;
12525 if (!isALPHA(*pos)) {
12526 U8 tmpbuf[UTF8_MAXBYTES+1];
12529 s++; /* get past 'v' */
12531 sv_setpvn(sv, "", 0);
12534 /* this is atoi() that tolerates underscores */
12537 const char *end = pos;
12539 while (--end >= s) {
12541 const UV orev = rev;
12542 rev += (*end - '0') * mult;
12544 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12545 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12546 "Integer overflow in decimal number");
12550 if (rev > 0x7FFFFFFF)
12551 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12553 /* Append native character for the rev point */
12554 tmpend = uvchr_to_utf8(tmpbuf, rev);
12555 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12556 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12558 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
12564 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12568 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12576 * c-indentation-style: bsd
12577 * c-basic-offset: 4
12578 * indent-tabs-mode: t
12581 * ex: set ts=8 sts=4 sw=4 noet: