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, 0 }
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; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ;
433 if (t < PL_bufptr && isSPACE(*t))
434 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
435 "\t(Do you need to predeclare %.*s?)\n",
436 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
440 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
441 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
449 * Complain about missing quote/regexp/heredoc terminator.
450 * If it's called with (char *)NULL then it cauterizes the line buffer.
451 * If we're in a delimited string and the delimiter is a control
452 * character, it's reformatted into a two-char sequence like ^C.
457 S_missingterm(pTHX_ char *s)
463 char * const nl = strrchr(s,'\n');
469 iscntrl(PL_multi_close)
471 PL_multi_close < 32 || PL_multi_close == 127
475 tmpbuf[1] = (char)toCTRL(PL_multi_close);
480 *tmpbuf = (char)PL_multi_close;
484 q = strchr(s,'"') ? '\'' : '"';
485 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
488 #define FEATURE_IS_ENABLED(name) \
489 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
490 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
492 * S_feature_is_enabled
493 * Check whether the named feature is enabled.
496 S_feature_is_enabled(pTHX_ char *name, STRLEN namelen)
499 HV * const hinthv = GvHV(PL_hintgv);
500 char he_name[32] = "feature_";
501 (void) strncpy(&he_name[8], name, 24);
503 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
511 Perl_deprecate(pTHX_ const char *s)
513 if (ckWARN(WARN_DEPRECATED))
514 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
518 Perl_deprecate_old(pTHX_ const char *s)
520 /* This function should NOT be called for any new deprecated warnings */
521 /* Use Perl_deprecate instead */
523 /* It is here to maintain backward compatibility with the pre-5.8 */
524 /* warnings category hierarchy. The "deprecated" category used to */
525 /* live under the "syntax" category. It is now a top-level category */
526 /* in its own right. */
528 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
529 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
530 "Use of %s is deprecated", s);
534 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
535 * utf16-to-utf8-reversed.
538 #ifdef PERL_CR_FILTER
542 register const char *s = SvPVX_const(sv);
543 register const char * const e = s + SvCUR(sv);
544 /* outer loop optimized to do nothing if there are no CR-LFs */
546 if (*s++ == '\r' && *s == '\n') {
547 /* hit a CR-LF, need to copy the rest */
548 register char *d = s - 1;
551 if (*s == '\r' && s[1] == '\n')
562 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
564 const I32 count = FILTER_READ(idx+1, sv, maxlen);
565 if (count > 0 && !maxlen)
573 * Initialize variables. Uses the Perl save_stack to save its state (for
574 * recursive calls to the parser).
578 Perl_lex_start(pTHX_ SV *line)
584 SAVEI32(PL_lex_dojoin);
585 SAVEI32(PL_lex_brackets);
586 SAVEI32(PL_lex_casemods);
587 SAVEI32(PL_lex_starts);
588 SAVEI32(PL_lex_state);
589 SAVEVPTR(PL_lex_inpat);
590 SAVEI32(PL_lex_inwhat);
592 if (PL_lex_state == LEX_KNOWNEXT) {
593 I32 toke = PL_lasttoke;
594 while (--toke >= 0) {
595 SAVEI32(PL_nexttoke[toke].next_type);
596 SAVEVPTR(PL_nexttoke[toke].next_val);
598 SAVEVPTR(PL_nexttoke[toke].next_mad);
600 SAVEI32(PL_lasttoke);
603 SAVESPTR(PL_thistoken);
604 SAVESPTR(PL_thiswhite);
605 SAVESPTR(PL_nextwhite);
606 SAVESPTR(PL_thisopen);
607 SAVESPTR(PL_thisclose);
608 SAVESPTR(PL_thisstuff);
609 SAVEVPTR(PL_thismad);
610 SAVEI32(PL_realtokenstart);
611 SAVEI32(PL_faketokens);
613 SAVEI32(PL_curforce);
615 if (PL_lex_state == LEX_KNOWNEXT) {
616 I32 toke = PL_nexttoke;
617 while (--toke >= 0) {
618 SAVEI32(PL_nexttype[toke]);
619 SAVEVPTR(PL_nextval[toke]);
621 SAVEI32(PL_nexttoke);
624 SAVECOPLINE(PL_curcop);
627 SAVEPPTR(PL_oldbufptr);
628 SAVEPPTR(PL_oldoldbufptr);
629 SAVEPPTR(PL_last_lop);
630 SAVEPPTR(PL_last_uni);
631 SAVEPPTR(PL_linestart);
632 SAVESPTR(PL_linestr);
633 SAVEGENERICPV(PL_lex_brackstack);
634 SAVEGENERICPV(PL_lex_casestack);
635 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
636 SAVESPTR(PL_lex_stuff);
637 SAVEI32(PL_lex_defer);
638 SAVEI32(PL_sublex_info.sub_inwhat);
639 SAVESPTR(PL_lex_repl);
641 SAVEINT(PL_lex_expect);
643 PL_lex_state = LEX_NORMAL;
647 Newx(PL_lex_brackstack, 120, char);
648 Newx(PL_lex_casestack, 12, char);
650 *PL_lex_casestack = '\0';
662 PL_sublex_info.sub_inwhat = 0;
664 if (SvREADONLY(PL_linestr))
665 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
666 s = SvPV_const(PL_linestr, len);
667 if (!len || s[len-1] != ';') {
668 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
669 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
670 sv_catpvs(PL_linestr, "\n;");
672 SvTEMP_off(PL_linestr);
673 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
674 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
675 PL_last_lop = PL_last_uni = NULL;
681 * Finalizer for lexing operations. Must be called when the parser is
682 * done with the lexer.
689 PL_doextract = FALSE;
694 * This subroutine has nothing to do with tilting, whether at windmills
695 * or pinball tables. Its name is short for "increment line". It
696 * increments the current line number in CopLINE(PL_curcop) and checks
697 * to see whether the line starts with a comment of the form
698 * # line 500 "foo.pm"
699 * If so, it sets the current line number and file to the values in the comment.
703 S_incline(pTHX_ char *s)
711 CopLINE_inc(PL_curcop);
714 while (SPACE_OR_TAB(*s)) s++;
715 if (strnEQ(s, "line", 4))
719 if (SPACE_OR_TAB(*s))
723 while (SPACE_OR_TAB(*s)) s++;
729 while (SPACE_OR_TAB(*s))
731 if (*s == '"' && (t = strchr(s+1, '"'))) {
736 for (t = s; !isSPACE(*t); t++) ;
739 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
741 if (*e != '\n' && *e != '\0')
742 return; /* false alarm */
748 const char * const cf = CopFILE(PL_curcop);
749 STRLEN tmplen = cf ? strlen(cf) : 0;
750 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
751 /* must copy *{"::_<(eval N)[oldfilename:L]"}
752 * to *{"::_<newfilename"} */
753 char smallbuf[256], smallbuf2[256];
754 char *tmpbuf, *tmpbuf2;
756 STRLEN tmplen2 = strlen(s);
757 if (tmplen + 3 < sizeof smallbuf)
760 Newx(tmpbuf, tmplen + 3, char);
761 if (tmplen2 + 3 < sizeof smallbuf2)
764 Newx(tmpbuf2, tmplen2 + 3, char);
765 tmpbuf[0] = tmpbuf2[0] = '_';
766 tmpbuf[1] = tmpbuf2[1] = '<';
767 memcpy(tmpbuf + 2, cf, ++tmplen);
768 memcpy(tmpbuf2 + 2, s, ++tmplen2);
770 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
772 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
774 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
775 /* adjust ${"::_<newfilename"} to store the new file name */
776 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
777 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
778 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
780 if (tmpbuf != smallbuf) Safefree(tmpbuf);
781 if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
784 CopFILE_free(PL_curcop);
785 CopFILE_set(PL_curcop, s);
788 CopLINE_set(PL_curcop, atoi(n)-1);
792 /* skip space before PL_thistoken */
795 S_skipspace0(pTHX_ register char *s)
802 PL_thiswhite = newSVpvn("",0);
803 sv_catsv(PL_thiswhite, PL_skipwhite);
804 sv_free(PL_skipwhite);
807 PL_realtokenstart = s - SvPVX(PL_linestr);
811 /* skip space after PL_thistoken */
814 S_skipspace1(pTHX_ register char *s)
817 I32 startoff = start - SvPVX(PL_linestr);
822 start = SvPVX(PL_linestr) + startoff;
823 if (!PL_thistoken && PL_realtokenstart >= 0) {
824 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
825 PL_thistoken = newSVpvn(tstart, start - tstart);
827 PL_realtokenstart = -1;
830 PL_nextwhite = newSVpvn("",0);
831 sv_catsv(PL_nextwhite, PL_skipwhite);
832 sv_free(PL_skipwhite);
839 S_skipspace2(pTHX_ register char *s, SV **svp)
842 I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
843 I32 startoff = start - SvPVX(PL_linestr);
845 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
846 if (!PL_madskills || !svp)
848 start = SvPVX(PL_linestr) + startoff;
849 if (!PL_thistoken && PL_realtokenstart >= 0) {
850 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
851 PL_thistoken = newSVpvn(tstart, start - tstart);
852 PL_realtokenstart = -1;
856 *svp = newSVpvn("",0);
857 sv_setsv(*svp, PL_skipwhite);
858 sv_free(PL_skipwhite);
868 * Called to gobble the appropriate amount and type of whitespace.
869 * Skips comments as well.
873 S_skipspace(pTHX_ register char *s)
878 int startoff = s - SvPVX(PL_linestr);
881 sv_free(PL_skipwhite);
886 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
887 while (s < PL_bufend && SPACE_OR_TAB(*s))
897 SSize_t oldprevlen, oldoldprevlen;
898 SSize_t oldloplen = 0, oldunilen = 0;
899 while (s < PL_bufend && isSPACE(*s)) {
900 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
905 if (s < PL_bufend && *s == '#') {
906 while (s < PL_bufend && *s != '\n')
910 if (PL_in_eval && !PL_rsfp) {
917 /* only continue to recharge the buffer if we're at the end
918 * of the buffer, we're not reading from a source filter, and
919 * we're in normal lexing mode
921 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
922 PL_lex_state == LEX_FORMLINE)
929 /* try to recharge the buffer */
931 curoff = s - SvPVX(PL_linestr);
934 if ((s = filter_gets(PL_linestr, PL_rsfp,
935 (prevlen = SvCUR(PL_linestr)))) == NULL)
938 if (PL_madskills && curoff != startoff) {
940 PL_skipwhite = newSVpvn("",0);
941 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
945 /* mustn't throw out old stuff yet if madpropping */
946 SvCUR(PL_linestr) = curoff;
947 s = SvPVX(PL_linestr) + curoff;
949 if (curoff && s[-1] == '\n')
953 /* end of file. Add on the -p or -n magic */
954 /* XXX these shouldn't really be added here, can't set PL_faketokens */
958 ";}continue{print or die qq(-p destination: $!\\n);}");
961 ";}continue{print or die qq(-p destination: $!\\n);}");
963 PL_minus_n = PL_minus_p = 0;
965 else if (PL_minus_n) {
967 sv_catpvn(PL_linestr, ";}", 2);
969 sv_setpvn(PL_linestr, ";}", 2);
975 sv_catpvn(PL_linestr,";", 1);
977 sv_setpvn(PL_linestr,";", 1);
980 /* reset variables for next time we lex */
981 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
987 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
988 PL_last_lop = PL_last_uni = NULL;
990 /* Close the filehandle. Could be from -P preprocessor,
991 * STDIN, or a regular file. If we were reading code from
992 * STDIN (because the commandline held no -e or filename)
993 * then we don't close it, we reset it so the code can
994 * read from STDIN too.
997 if (PL_preprocess && !PL_in_eval)
998 (void)PerlProc_pclose(PL_rsfp);
999 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1000 PerlIO_clearerr(PL_rsfp);
1002 (void)PerlIO_close(PL_rsfp);
1007 /* not at end of file, so we only read another line */
1008 /* make corresponding updates to old pointers, for yyerror() */
1009 oldprevlen = PL_oldbufptr - PL_bufend;
1010 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1012 oldunilen = PL_last_uni - PL_bufend;
1014 oldloplen = PL_last_lop - PL_bufend;
1015 PL_linestart = PL_bufptr = s + prevlen;
1016 PL_bufend = s + SvCUR(PL_linestr);
1018 PL_oldbufptr = s + oldprevlen;
1019 PL_oldoldbufptr = s + oldoldprevlen;
1021 PL_last_uni = s + oldunilen;
1023 PL_last_lop = s + oldloplen;
1026 /* debugger active and we're not compiling the debugger code,
1027 * so store the line into the debugger's array of lines
1029 if (PERLDB_LINE && PL_curstash != PL_debstash) {
1030 SV * const sv = newSV(0);
1032 sv_upgrade(sv, SVt_PVMG);
1033 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
1036 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
1044 PL_skipwhite = newSVpvn("",0);
1045 curoff = s - SvPVX(PL_linestr);
1046 if (curoff - startoff)
1047 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1056 * Check the unary operators to ensure there's no ambiguity in how they're
1057 * used. An ambiguous piece of code would be:
1059 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1060 * the +5 is its argument.
1070 if (PL_oldoldbufptr != PL_last_uni)
1072 while (isSPACE(*PL_last_uni))
1074 for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ;
1075 if ((t = strchr(s, '(')) && t < PL_bufptr)
1078 if (ckWARN_d(WARN_AMBIGUOUS)){
1079 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1080 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1081 (int)(s - PL_last_uni), PL_last_uni);
1086 * LOP : macro to build a list operator. Its behaviour has been replaced
1087 * with a subroutine, S_lop() for which LOP is just another name.
1090 #define LOP(f,x) return lop(f,x,s)
1094 * Build a list operator (or something that might be one). The rules:
1095 * - if we have a next token, then it's a list operator [why?]
1096 * - if the next thing is an opening paren, then it's a function
1097 * - else it's a list operator
1101 S_lop(pTHX_ I32 f, int x, char *s)
1108 PL_last_lop = PL_oldbufptr;
1109 PL_last_lop_op = (OPCODE)f;
1112 return REPORT(LSTOP);
1115 return REPORT(LSTOP);
1118 return REPORT(FUNC);
1121 return REPORT(FUNC);
1123 return REPORT(LSTOP);
1129 * Sets up for an eventual force_next(). start_force(0) basically does
1130 * an unshift, while start_force(-1) does a push. yylex removes items
1135 S_start_force(pTHX_ int where)
1139 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1140 where = PL_lasttoke;
1141 assert(PL_curforce < 0 || PL_curforce == where);
1142 if (PL_curforce != where) {
1143 for (i = PL_lasttoke; i > where; --i) {
1144 PL_nexttoke[i] = PL_nexttoke[i-1];
1148 if (PL_curforce < 0) /* in case of duplicate start_force() */
1149 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1150 PL_curforce = where;
1153 curmad('^', newSVpvn("",0));
1154 CURMAD('_', PL_nextwhite);
1159 S_curmad(pTHX_ char slot, SV *sv)
1165 if (PL_curforce < 0)
1166 where = &PL_thismad;
1168 where = &PL_nexttoke[PL_curforce].next_mad;
1171 sv_setpvn(sv, "", 0);
1174 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1176 else if (PL_encoding) {
1177 sv_recode_to_utf8(sv, PL_encoding);
1182 /* keep a slot open for the head of the list? */
1183 if (slot != '_' && *where && (*where)->mad_key == '^') {
1184 (*where)->mad_key = slot;
1185 sv_free((*where)->mad_val);
1186 (*where)->mad_val = (void*)sv;
1189 addmad(newMADsv(slot, sv), where, 0);
1192 # define start_force(where)
1193 # define curmad(slot, sv)
1198 * When the lexer realizes it knows the next token (for instance,
1199 * it is reordering tokens for the parser) then it can call S_force_next
1200 * to know what token to return the next time the lexer is called. Caller
1201 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1202 * and possibly PL_expect to ensure the lexer handles the token correctly.
1206 S_force_next(pTHX_ I32 type)
1210 if (PL_curforce < 0)
1211 start_force(PL_lasttoke);
1212 PL_nexttoke[PL_curforce].next_type = type;
1213 if (PL_lex_state != LEX_KNOWNEXT)
1214 PL_lex_defer = PL_lex_state;
1215 PL_lex_state = LEX_KNOWNEXT;
1216 PL_lex_expect = PL_expect;
1219 PL_nexttype[PL_nexttoke] = type;
1221 if (PL_lex_state != LEX_KNOWNEXT) {
1222 PL_lex_defer = PL_lex_state;
1223 PL_lex_expect = PL_expect;
1224 PL_lex_state = LEX_KNOWNEXT;
1230 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1233 SV * const sv = newSVpvn(start,len);
1234 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
1241 * When the lexer knows the next thing is a word (for instance, it has
1242 * just seen -> and it knows that the next char is a word char, then
1243 * it calls S_force_word to stick the next word into the PL_next lookahead.
1246 * char *start : buffer position (must be within PL_linestr)
1247 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
1248 * int check_keyword : if true, Perl checks to make sure the word isn't
1249 * a keyword (do this if the word is a label, e.g. goto FOO)
1250 * int allow_pack : if true, : characters will also be allowed (require,
1251 * use, etc. do this)
1252 * int allow_initial_tick : used by the "sub" lexer only.
1256 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1262 start = SKIPSPACE1(start);
1264 if (isIDFIRST_lazy_if(s,UTF) ||
1265 (allow_pack && *s == ':') ||
1266 (allow_initial_tick && *s == '\'') )
1268 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1269 if (check_keyword && keyword(PL_tokenbuf, len))
1271 start_force(PL_curforce);
1273 curmad('X', newSVpvn(start,s-start));
1274 if (token == METHOD) {
1279 PL_expect = XOPERATOR;
1282 NEXTVAL_NEXTTOKE.opval
1283 = (OP*)newSVOP(OP_CONST,0,
1284 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1285 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1293 * Called when the lexer wants $foo *foo &foo etc, but the program
1294 * text only contains the "foo" portion. The first argument is a pointer
1295 * to the "foo", and the second argument is the type symbol to prefix.
1296 * Forces the next token to be a "WORD".
1297 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1301 S_force_ident(pTHX_ register const char *s, int kind)
1305 const STRLEN len = strlen(s);
1306 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1307 start_force(PL_curforce);
1308 NEXTVAL_NEXTTOKE.opval = o;
1311 o->op_private = OPpCONST_ENTERED;
1312 /* XXX see note in pp_entereval() for why we forgo typo
1313 warnings if the symbol must be introduced in an eval.
1315 gv_fetchpvn_flags(s, len,
1316 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1318 kind == '$' ? SVt_PV :
1319 kind == '@' ? SVt_PVAV :
1320 kind == '%' ? SVt_PVHV :
1328 Perl_str_to_version(pTHX_ SV *sv)
1333 const char *start = SvPV_const(sv,len);
1334 const char * const end = start + len;
1335 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1336 while (start < end) {
1340 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1345 retval += ((NV)n)/nshift;
1354 * Forces the next token to be a version number.
1355 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1356 * and if "guessing" is TRUE, then no new token is created (and the caller
1357 * must use an alternative parsing method).
1361 S_force_version(pTHX_ char *s, int guessing)
1367 I32 startoff = s - SvPVX(PL_linestr);
1376 while (isDIGIT(*d) || *d == '_' || *d == '.')
1380 start_force(PL_curforce);
1381 curmad('X', newSVpvn(s,d-s));
1384 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1386 s = scan_num(s, &yylval);
1387 version = yylval.opval;
1388 ver = cSVOPx(version)->op_sv;
1389 if (SvPOK(ver) && !SvNIOK(ver)) {
1390 SvUPGRADE(ver, SVt_PVNV);
1391 SvNV_set(ver, str_to_version(ver));
1392 SvNOK_on(ver); /* hint that it is a version */
1395 else if (guessing) {
1398 sv_free(PL_nextwhite); /* let next token collect whitespace */
1400 s = SvPVX(PL_linestr) + startoff;
1408 if (PL_madskills && !version) {
1409 sv_free(PL_nextwhite); /* let next token collect whitespace */
1411 s = SvPVX(PL_linestr) + startoff;
1414 /* NOTE: The parser sees the package name and the VERSION swapped */
1415 start_force(PL_curforce);
1416 NEXTVAL_NEXTTOKE.opval = version;
1424 * Tokenize a quoted string passed in as an SV. It finds the next
1425 * chunk, up to end of string or a backslash. It may make a new
1426 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1431 S_tokeq(pTHX_ SV *sv)
1435 register char *send;
1443 s = SvPV_force(sv, len);
1444 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1447 while (s < send && *s != '\\')
1452 if ( PL_hints & HINT_NEW_STRING ) {
1453 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1459 if (s + 1 < send && (s[1] == '\\'))
1460 s++; /* all that, just for this */
1465 SvCUR_set(sv, d - SvPVX_const(sv));
1467 if ( PL_hints & HINT_NEW_STRING )
1468 return new_constant(NULL, 0, "q", sv, pv, "q");
1473 * Now come three functions related to double-quote context,
1474 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1475 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1476 * interact with PL_lex_state, and create fake ( ... ) argument lists
1477 * to handle functions and concatenation.
1478 * They assume that whoever calls them will be setting up a fake
1479 * join call, because each subthing puts a ',' after it. This lets
1482 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1484 * (I'm not sure whether the spurious commas at the end of lcfirst's
1485 * arguments and join's arguments are created or not).
1490 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1492 * Pattern matching will set PL_lex_op to the pattern-matching op to
1493 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1495 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1497 * Everything else becomes a FUNC.
1499 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1500 * had an OP_CONST or OP_READLINE). This just sets us up for a
1501 * call to S_sublex_push().
1505 S_sublex_start(pTHX)
1508 register const I32 op_type = yylval.ival;
1510 if (op_type == OP_NULL) {
1511 yylval.opval = PL_lex_op;
1515 if (op_type == OP_CONST || op_type == OP_READLINE) {
1516 SV *sv = tokeq(PL_lex_stuff);
1518 if (SvTYPE(sv) == SVt_PVIV) {
1519 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1521 const char * const p = SvPV_const(sv, len);
1522 SV * const nsv = newSVpvn(p, len);
1528 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1529 PL_lex_stuff = NULL;
1530 /* Allow <FH> // "foo" */
1531 if (op_type == OP_READLINE)
1532 PL_expect = XTERMORDORDOR;
1536 PL_sublex_info.super_state = PL_lex_state;
1537 PL_sublex_info.sub_inwhat = op_type;
1538 PL_sublex_info.sub_op = PL_lex_op;
1539 PL_lex_state = LEX_INTERPPUSH;
1543 yylval.opval = PL_lex_op;
1553 * Create a new scope to save the lexing state. The scope will be
1554 * ended in S_sublex_done. Returns a '(', starting the function arguments
1555 * to the uc, lc, etc. found before.
1556 * Sets PL_lex_state to LEX_INTERPCONCAT.
1565 PL_lex_state = PL_sublex_info.super_state;
1566 SAVEI32(PL_lex_dojoin);
1567 SAVEI32(PL_lex_brackets);
1568 SAVEI32(PL_lex_casemods);
1569 SAVEI32(PL_lex_starts);
1570 SAVEI32(PL_lex_state);
1571 SAVEVPTR(PL_lex_inpat);
1572 SAVEI32(PL_lex_inwhat);
1573 SAVECOPLINE(PL_curcop);
1574 SAVEPPTR(PL_bufptr);
1575 SAVEPPTR(PL_bufend);
1576 SAVEPPTR(PL_oldbufptr);
1577 SAVEPPTR(PL_oldoldbufptr);
1578 SAVEPPTR(PL_last_lop);
1579 SAVEPPTR(PL_last_uni);
1580 SAVEPPTR(PL_linestart);
1581 SAVESPTR(PL_linestr);
1582 SAVEGENERICPV(PL_lex_brackstack);
1583 SAVEGENERICPV(PL_lex_casestack);
1585 PL_linestr = PL_lex_stuff;
1586 PL_lex_stuff = NULL;
1588 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1589 = SvPVX(PL_linestr);
1590 PL_bufend += SvCUR(PL_linestr);
1591 PL_last_lop = PL_last_uni = NULL;
1592 SAVEFREESV(PL_linestr);
1594 PL_lex_dojoin = FALSE;
1595 PL_lex_brackets = 0;
1596 Newx(PL_lex_brackstack, 120, char);
1597 Newx(PL_lex_casestack, 12, char);
1598 PL_lex_casemods = 0;
1599 *PL_lex_casestack = '\0';
1601 PL_lex_state = LEX_INTERPCONCAT;
1602 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1604 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1605 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1606 PL_lex_inpat = PL_sublex_info.sub_op;
1608 PL_lex_inpat = NULL;
1615 * Restores lexer state after a S_sublex_push.
1622 if (!PL_lex_starts++) {
1623 SV * const sv = newSVpvs("");
1624 if (SvUTF8(PL_linestr))
1626 PL_expect = XOPERATOR;
1627 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1631 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1632 PL_lex_state = LEX_INTERPCASEMOD;
1636 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1637 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1638 PL_linestr = PL_lex_repl;
1640 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1641 PL_bufend += SvCUR(PL_linestr);
1642 PL_last_lop = PL_last_uni = NULL;
1643 SAVEFREESV(PL_linestr);
1644 PL_lex_dojoin = FALSE;
1645 PL_lex_brackets = 0;
1646 PL_lex_casemods = 0;
1647 *PL_lex_casestack = '\0';
1649 if (SvEVALED(PL_lex_repl)) {
1650 PL_lex_state = LEX_INTERPNORMAL;
1652 /* we don't clear PL_lex_repl here, so that we can check later
1653 whether this is an evalled subst; that means we rely on the
1654 logic to ensure sublex_done() is called again only via the
1655 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1658 PL_lex_state = LEX_INTERPCONCAT;
1668 PL_endwhite = newSVpvn("",0);
1669 sv_catsv(PL_endwhite, PL_thiswhite);
1673 sv_setpvn(PL_thistoken,"",0);
1675 PL_realtokenstart = -1;
1679 PL_bufend = SvPVX(PL_linestr);
1680 PL_bufend += SvCUR(PL_linestr);
1681 PL_expect = XOPERATOR;
1682 PL_sublex_info.sub_inwhat = 0;
1690 Extracts a pattern, double-quoted string, or transliteration. This
1693 It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1694 processing a pattern (PL_lex_inpat is true), a transliteration
1695 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1697 Returns a pointer to the character scanned up to. Iff this is
1698 advanced from the start pointer supplied (ie if anything was
1699 successfully parsed), will leave an OP for the substring scanned
1700 in yylval. Caller must intuit reason for not parsing further
1701 by looking at the next characters herself.
1705 double-quoted style: \r and \n
1706 regexp special ones: \D \s
1708 backrefs: \1 (deprecated in substitution replacements)
1709 case and quoting: \U \Q \E
1710 stops on @ and $, but not for $ as tail anchor
1712 In transliterations:
1713 characters are VERY literal, except for - not at the start or end
1714 of the string, which indicates a range. scan_const expands the
1715 range to the full set of intermediate characters.
1717 In double-quoted strings:
1719 double-quoted style: \r and \n
1721 backrefs: \1 (deprecated)
1722 case and quoting: \U \Q \E
1725 scan_const does *not* construct ops to handle interpolated strings.
1726 It stops processing as soon as it finds an embedded $ or @ variable
1727 and leaves it to the caller to work out what's going on.
1729 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo.
1731 $ in pattern could be $foo or could be tail anchor. Assumption:
1732 it's a tail anchor if $ is the last thing in the string, or if it's
1733 followed by one of ")| \n\t"
1735 \1 (backreferences) are turned into $1
1737 The structure of the code is
1738 while (there's a character to process) {
1739 handle transliteration ranges
1740 skip regexp comments
1741 skip # initiated comments in //x patterns
1742 check for embedded @foo
1743 check for embedded scalars
1745 leave intact backslashes from leave (below)
1746 deprecate \1 in strings and sub replacements
1747 handle string-changing backslashes \l \U \Q \E, etc.
1748 switch (what was escaped) {
1749 handle - in a transliteration (becomes a literal -)
1750 handle \132 octal characters
1751 handle 0x15 hex characters
1752 handle \cV (control V)
1753 handle printf backslashes (\f, \r, \n, etc)
1755 } (end if backslash)
1756 } (end while character to read)
1761 S_scan_const(pTHX_ char *start)
1764 register char *send = PL_bufend; /* end of the constant */
1765 SV *sv = newSV(send - start); /* sv for the constant */
1766 register char *s = start; /* start of the constant */
1767 register char *d = SvPVX(sv); /* destination for copies */
1768 bool dorange = FALSE; /* are we in a translit range? */
1769 bool didrange = FALSE; /* did we just finish a range? */
1770 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1771 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1774 UV literal_endpoint = 0;
1777 const char *leaveit = /* set of acceptably-backslashed characters */
1779 ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#"
1782 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1783 /* If we are doing a trans and we know we want UTF8 set expectation */
1784 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1785 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1789 while (s < send || dorange) {
1790 /* get transliterations out of the way (they're most literal) */
1791 if (PL_lex_inwhat == OP_TRANS) {
1792 /* expand a range A-Z to the full set of characters. AIE! */
1794 I32 i; /* current expanded character */
1795 I32 min; /* first character in range */
1796 I32 max; /* last character in range */
1799 char * const c = (char*)utf8_hop((U8*)d, -1);
1803 *c = (char)UTF_TO_NATIVE(0xff);
1804 /* mark the range as done, and continue */
1810 i = d - SvPVX_const(sv); /* remember current offset */
1811 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1812 d = SvPVX(sv) + i; /* refresh d after realloc */
1813 d -= 2; /* eat the first char and the - */
1815 min = (U8)*d; /* first char in range */
1816 max = (U8)d[1]; /* last char in range */
1820 "Invalid range \"%c-%c\" in transliteration operator",
1821 (char)min, (char)max);
1825 if (literal_endpoint == 2 &&
1826 ((isLOWER(min) && isLOWER(max)) ||
1827 (isUPPER(min) && isUPPER(max)))) {
1829 for (i = min; i <= max; i++)
1831 *d++ = NATIVE_TO_NEED(has_utf8,i);
1833 for (i = min; i <= max; i++)
1835 *d++ = NATIVE_TO_NEED(has_utf8,i);
1840 for (i = min; i <= max; i++)
1843 /* mark the range as done, and continue */
1847 literal_endpoint = 0;
1852 /* range begins (ignore - as first or last char) */
1853 else if (*s == '-' && s+1 < send && s != start) {
1855 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1858 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1868 literal_endpoint = 0;
1873 /* if we get here, we're not doing a transliteration */
1875 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1876 except for the last char, which will be done separately. */
1877 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1879 while (s+1 < send && *s != ')')
1880 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1882 else if (s[2] == '{' /* This should match regcomp.c */
1883 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1886 char *regparse = s + (s[2] == '{' ? 3 : 4);
1889 while (count && (c = *regparse)) {
1890 if (c == '\\' && regparse[1])
1898 if (*regparse != ')')
1899 regparse--; /* Leave one char for continuation. */
1900 while (s < regparse)
1901 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1905 /* likewise skip #-initiated comments in //x patterns */
1906 else if (*s == '#' && PL_lex_inpat &&
1907 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1908 while (s+1 < send && *s != '\n')
1909 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1912 /* check for embedded arrays
1913 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
1915 else if (*s == '@' && s[1]
1916 && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1])))
1919 /* check for embedded scalars. only stop if we're sure it's a
1922 else if (*s == '$') {
1923 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
1925 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
1926 break; /* in regexp, $ might be tail anchor */
1929 /* End of else if chain - OP_TRANS rejoin rest */
1932 if (*s == '\\' && s+1 < send) {
1935 /* some backslashes we leave behind */
1936 if (*leaveit && *s && strchr(leaveit, *s)) {
1937 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
1938 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1942 /* deprecate \1 in strings and substitution replacements */
1943 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1944 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1946 if (ckWARN(WARN_SYNTAX))
1947 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
1952 /* string-change backslash escapes */
1953 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1958 /* if we get here, it's either a quoted -, or a digit */
1961 /* quoted - in transliterations */
1963 if (PL_lex_inwhat == OP_TRANS) {
1973 Perl_warner(aTHX_ packWARN(WARN_MISC),
1974 "Unrecognized escape \\%c passed through",
1976 /* default action is to copy the quoted character */
1977 goto default_action;
1980 /* \132 indicates an octal constant */
1981 case '0': case '1': case '2': case '3':
1982 case '4': case '5': case '6': case '7':
1986 uv = grok_oct(s, &len, &flags, NULL);
1989 goto NUM_ESCAPE_INSERT;
1991 /* \x24 indicates a hex constant */
1995 char* const e = strchr(s, '}');
1996 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1997 PERL_SCAN_DISALLOW_PREFIX;
2002 yyerror("Missing right brace on \\x{}");
2006 uv = grok_hex(s, &len, &flags, NULL);
2012 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2013 uv = grok_hex(s, &len, &flags, NULL);
2019 /* Insert oct or hex escaped character.
2020 * There will always enough room in sv since such
2021 * escapes will be longer than any UTF-8 sequence
2022 * they can end up as. */
2024 /* We need to map to chars to ASCII before doing the tests
2027 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2028 if (!has_utf8 && uv > 255) {
2029 /* Might need to recode whatever we have
2030 * accumulated so far if it contains any
2033 * (Can't we keep track of that and avoid
2034 * this rescan? --jhi)
2038 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2039 if (!NATIVE_IS_INVARIANT(*c)) {
2044 const STRLEN offset = d - SvPVX_const(sv);
2046 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2050 while (src >= (const U8 *)SvPVX_const(sv)) {
2051 if (!NATIVE_IS_INVARIANT(*src)) {
2052 const U8 ch = NATIVE_TO_ASCII(*src);
2053 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2054 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2064 if (has_utf8 || uv > 255) {
2065 d = (char*)uvchr_to_utf8((U8*)d, uv);
2067 if (PL_lex_inwhat == OP_TRANS &&
2068 PL_sublex_info.sub_op) {
2069 PL_sublex_info.sub_op->op_private |=
2070 (PL_lex_repl ? OPpTRANS_FROM_UTF
2083 /* \N{LATIN SMALL LETTER A} is a named character */
2087 char* e = strchr(s, '}');
2093 yyerror("Missing right brace on \\N{}");
2097 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2099 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2100 PERL_SCAN_DISALLOW_PREFIX;
2103 uv = grok_hex(s, &len, &flags, NULL);
2105 goto NUM_ESCAPE_INSERT;
2107 res = newSVpvn(s + 1, e - s - 1);
2108 res = new_constant( NULL, 0, "charnames",
2109 res, NULL, "\\N{...}" );
2111 sv_utf8_upgrade(res);
2112 str = SvPV_const(res,len);
2113 #ifdef EBCDIC_NEVER_MIND
2114 /* charnames uses pack U and that has been
2115 * recently changed to do the below uni->native
2116 * mapping, so this would be redundant (and wrong,
2117 * the code point would be doubly converted).
2118 * But leave this in just in case the pack U change
2119 * gets revoked, but the semantics is still
2120 * desireable for charnames. --jhi */
2122 UV uv = utf8_to_uvchr((const U8*)str, 0);
2125 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2127 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2128 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2129 str = SvPV_const(res, len);
2133 if (!has_utf8 && SvUTF8(res)) {
2134 const char * const ostart = SvPVX_const(sv);
2135 SvCUR_set(sv, d - ostart);
2138 sv_utf8_upgrade(sv);
2139 /* this just broke our allocation above... */
2140 SvGROW(sv, (STRLEN)(send - start));
2141 d = SvPVX(sv) + SvCUR(sv);
2144 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2145 const char * const odest = SvPVX_const(sv);
2147 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2148 d = SvPVX(sv) + (d - odest);
2150 Copy(str, d, len, char);
2157 yyerror("Missing braces on \\N{}");
2160 /* \c is a control character */
2169 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2172 yyerror("Missing control char name in \\c");
2176 /* printf-style backslashes, formfeeds, newlines, etc */
2178 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2181 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2184 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2187 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2190 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2193 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2196 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2202 } /* end if (backslash) */
2209 /* If we started with encoded form, or already know we want it
2210 and then encode the next character */
2211 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2213 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2214 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2217 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2218 const STRLEN off = d - SvPVX_const(sv);
2219 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2221 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2225 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2227 } /* while loop to process each character */
2229 /* terminate the string and set up the sv */
2231 SvCUR_set(sv, d - SvPVX_const(sv));
2232 if (SvCUR(sv) >= SvLEN(sv))
2233 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2236 if (PL_encoding && !has_utf8) {
2237 sv_recode_to_utf8(sv, PL_encoding);
2243 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2244 PL_sublex_info.sub_op->op_private |=
2245 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2249 /* shrink the sv if we allocated more than we used */
2250 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2251 SvPV_shrink_to_cur(sv);
2254 /* return the substring (via yylval) only if we parsed anything */
2255 if (s > PL_bufptr) {
2256 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
2257 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
2259 ( PL_lex_inwhat == OP_TRANS
2261 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2264 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2271 * Returns TRUE if there's more to the expression (e.g., a subscript),
2274 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2276 * ->[ and ->{ return TRUE
2277 * { and [ outside a pattern are always subscripts, so return TRUE
2278 * if we're outside a pattern and it's not { or [, then return FALSE
2279 * if we're in a pattern and the first char is a {
2280 * {4,5} (any digits around the comma) returns FALSE
2281 * if we're in a pattern and the first char is a [
2283 * [SOMETHING] has a funky algorithm to decide whether it's a
2284 * character class or not. It has to deal with things like
2285 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2286 * anything else returns TRUE
2289 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2292 S_intuit_more(pTHX_ register char *s)
2295 if (PL_lex_brackets)
2297 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2299 if (*s != '{' && *s != '[')
2304 /* In a pattern, so maybe we have {n,m}. */
2321 /* On the other hand, maybe we have a character class */
2324 if (*s == ']' || *s == '^')
2327 /* this is terrifying, and it works */
2328 int weight = 2; /* let's weigh the evidence */
2330 unsigned char un_char = 255, last_un_char;
2331 const char * const send = strchr(s,']');
2332 char tmpbuf[sizeof PL_tokenbuf * 4];
2334 if (!send) /* has to be an expression */
2337 Zero(seen,256,char);
2340 else if (isDIGIT(*s)) {
2342 if (isDIGIT(s[1]) && s[2] == ']')
2348 for (; s < send; s++) {
2349 last_un_char = un_char;
2350 un_char = (unsigned char)*s;
2355 weight -= seen[un_char] * 10;
2356 if (isALNUM_lazy_if(s+1,UTF)) {
2358 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2359 len = (int)strlen(tmpbuf);
2360 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2365 else if (*s == '$' && s[1] &&
2366 strchr("[#!%*<>()-=",s[1])) {
2367 if (/*{*/ strchr("])} =",s[2]))
2376 if (strchr("wds]",s[1]))
2378 else if (seen['\''] || seen['"'])
2380 else if (strchr("rnftbxcav",s[1]))
2382 else if (isDIGIT(s[1])) {
2384 while (s[1] && isDIGIT(s[1]))
2394 if (strchr("aA01! ",last_un_char))
2396 if (strchr("zZ79~",s[1]))
2398 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2399 weight -= 5; /* cope with negative subscript */
2402 if (!isALNUM(last_un_char)
2403 && !(last_un_char == '$' || last_un_char == '@'
2404 || last_un_char == '&')
2405 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2410 if (keyword(tmpbuf, d - tmpbuf))
2413 if (un_char == last_un_char + 1)
2415 weight -= seen[un_char];
2420 if (weight >= 0) /* probably a character class */
2430 * Does all the checking to disambiguate
2432 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2433 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2435 * First argument is the stuff after the first token, e.g. "bar".
2437 * Not a method if bar is a filehandle.
2438 * Not a method if foo is a subroutine prototyped to take a filehandle.
2439 * Not a method if it's really "Foo $bar"
2440 * Method if it's "foo $bar"
2441 * Not a method if it's really "print foo $bar"
2442 * Method if it's really "foo package::" (interpreted as package->foo)
2443 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2444 * Not a method if bar is a filehandle or package, but is quoted with
2449 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2452 char *s = start + (*start == '$');
2453 char tmpbuf[sizeof PL_tokenbuf];
2461 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2465 const char *proto = SvPVX_const(cv);
2476 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2477 /* start is the beginning of the possible filehandle/object,
2478 * and s is the end of it
2479 * tmpbuf is a copy of it
2482 if (*start == '$') {
2483 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2486 len = start - SvPVX(PL_linestr);
2490 start = SvPVX(PL_linestr) + len;
2494 return *s == '(' ? FUNCMETH : METHOD;
2496 if (!keyword(tmpbuf, len)) {
2497 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2501 soff = s - SvPVX(PL_linestr);
2505 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2506 if (indirgv && GvCVu(indirgv))
2508 /* filehandle or package name makes it a method */
2509 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2511 soff = s - SvPVX(PL_linestr);
2514 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2515 return 0; /* no assumptions -- "=>" quotes bearword */
2517 start_force(PL_curforce);
2518 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2519 newSVpvn(tmpbuf,len));
2520 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2522 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2527 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2529 return *s == '(' ? FUNCMETH : METHOD;
2537 * Return a string of Perl code to load the debugger. If PERL5DB
2538 * is set, it will return the contents of that, otherwise a
2539 * compile-time require of perl5db.pl.
2547 const char * const pdb = PerlEnv_getenv("PERL5DB");
2551 SETERRNO(0,SS_NORMAL);
2552 return "BEGIN { require 'perl5db.pl' }";
2558 /* Encoded script support. filter_add() effectively inserts a
2559 * 'pre-processing' function into the current source input stream.
2560 * Note that the filter function only applies to the current source file
2561 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2563 * The datasv parameter (which may be NULL) can be used to pass
2564 * private data to this instance of the filter. The filter function
2565 * can recover the SV using the FILTER_DATA macro and use it to
2566 * store private buffers and state information.
2568 * The supplied datasv parameter is upgraded to a PVIO type
2569 * and the IoDIRP/IoANY field is used to store the function pointer,
2570 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2571 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2572 * private use must be set using malloc'd pointers.
2576 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2582 if (!PL_rsfp_filters)
2583 PL_rsfp_filters = newAV();
2586 SvUPGRADE(datasv, SVt_PVIO);
2587 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2588 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2589 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2590 IoANY(datasv), SvPV_nolen(datasv)));
2591 av_unshift(PL_rsfp_filters, 1);
2592 av_store(PL_rsfp_filters, 0, datasv) ;
2597 /* Delete most recently added instance of this filter function. */
2599 Perl_filter_del(pTHX_ filter_t funcp)
2605 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", FPTR2DPTR(XPVIO *, funcp)));
2607 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2609 /* if filter is on top of stack (usual case) just pop it off */
2610 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2611 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2612 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2613 IoANY(datasv) = (void *)NULL;
2614 sv_free(av_pop(PL_rsfp_filters));
2618 /* we need to search for the correct entry and clear it */
2619 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2623 /* Invoke the idxth filter function for the current rsfp. */
2624 /* maxlen 0 = read one text line */
2626 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2632 if (!PL_rsfp_filters)
2634 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2635 /* Provide a default input filter to make life easy. */
2636 /* Note that we append to the line. This is handy. */
2637 DEBUG_P(PerlIO_printf(Perl_debug_log,
2638 "filter_read %d: from rsfp\n", idx));
2642 const int old_len = SvCUR(buf_sv);
2644 /* ensure buf_sv is large enough */
2645 SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ;
2646 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
2647 if (PerlIO_error(PL_rsfp))
2648 return -1; /* error */
2650 return 0 ; /* end of file */
2652 SvCUR_set(buf_sv, old_len + len) ;
2655 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2656 if (PerlIO_error(PL_rsfp))
2657 return -1; /* error */
2659 return 0 ; /* end of file */
2662 return SvCUR(buf_sv);
2664 /* Skip this filter slot if filter has been deleted */
2665 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2666 DEBUG_P(PerlIO_printf(Perl_debug_log,
2667 "filter_read %d: skipped (filter deleted)\n",
2669 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
2671 /* Get function pointer hidden within datasv */
2672 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2673 DEBUG_P(PerlIO_printf(Perl_debug_log,
2674 "filter_read %d: via function %p (%s)\n",
2675 idx, datasv, SvPV_nolen_const(datasv)));
2676 /* Call function. The function is expected to */
2677 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2678 /* Return: <0:error, =0:eof, >0:not eof */
2679 return (*funcp)(aTHX_ idx, buf_sv, maxlen);
2683 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2686 #ifdef PERL_CR_FILTER
2687 if (!PL_rsfp_filters) {
2688 filter_add(S_cr_textfilter,NULL);
2691 if (PL_rsfp_filters) {
2693 SvCUR_set(sv, 0); /* start with empty line */
2694 if (FILTER_READ(0, sv, 0) > 0)
2695 return ( SvPVX(sv) ) ;
2700 return (sv_gets(sv, fp, append));
2704 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2709 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2713 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2714 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2716 return GvHV(gv); /* Foo:: */
2719 /* use constant CLASS => 'MyClass' */
2720 if ((gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV))) {
2722 if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) {
2723 pkgname = SvPV_nolen_const(sv);
2727 return gv_stashpv(pkgname, FALSE);
2733 * The intent of this yylex wrapper is to minimize the changes to the
2734 * tokener when we aren't interested in collecting madprops. It remains
2735 * to be seen how successful this strategy will be...
2742 char *s = PL_bufptr;
2744 /* make sure PL_thiswhite is initialized */
2748 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
2749 if (PL_pending_ident)
2750 return S_pending_ident(aTHX);
2752 /* previous token ate up our whitespace? */
2753 if (!PL_lasttoke && PL_nextwhite) {
2754 PL_thiswhite = PL_nextwhite;
2758 /* isolate the token, and figure out where it is without whitespace */
2759 PL_realtokenstart = -1;
2763 assert(PL_curforce < 0);
2765 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
2766 if (!PL_thistoken) {
2767 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
2768 PL_thistoken = newSVpvn("",0);
2770 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
2771 PL_thistoken = newSVpvn(tstart, s - tstart);
2774 if (PL_thismad) /* install head */
2775 CURMAD('X', PL_thistoken);
2778 /* last whitespace of a sublex? */
2779 if (optype == ')' && PL_endwhite) {
2780 CURMAD('X', PL_endwhite);
2785 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
2786 if (!PL_thiswhite && !PL_endwhite && !optype) {
2787 sv_free(PL_thistoken);
2792 /* put off final whitespace till peg */
2793 if (optype == ';' && !PL_rsfp) {
2794 PL_nextwhite = PL_thiswhite;
2797 else if (PL_thisopen) {
2798 CURMAD('q', PL_thisopen);
2800 sv_free(PL_thistoken);
2804 /* Store actual token text as madprop X */
2805 CURMAD('X', PL_thistoken);
2809 /* add preceding whitespace as madprop _ */
2810 CURMAD('_', PL_thiswhite);
2814 /* add quoted material as madprop = */
2815 CURMAD('=', PL_thisstuff);
2819 /* add terminating quote as madprop Q */
2820 CURMAD('Q', PL_thisclose);
2824 /* special processing based on optype */
2828 /* opval doesn't need a TOKEN since it can already store mp */
2839 append_madprops(PL_thismad, yylval.opval, 0);
2847 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
2856 /* remember any fake bracket that lexer is about to discard */
2857 if (PL_lex_brackets == 1 &&
2858 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
2861 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2864 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
2865 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
2868 break; /* don't bother looking for trailing comment */
2877 /* attach a trailing comment to its statement instead of next token */
2881 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
2883 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2885 if (*s == '\n' || *s == '#') {
2886 while (s < PL_bufend && *s != '\n')
2890 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
2891 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
2908 /* Create new token struct. Note: opvals return early above. */
2909 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
2916 S_tokenize_use(pTHX_ int is_use, char *s) {
2918 if (PL_expect != XSTATE)
2919 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
2920 is_use ? "use" : "no"));
2922 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
2923 s = force_version(s, TRUE);
2924 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
2925 start_force(PL_curforce);
2926 NEXTVAL_NEXTTOKE.opval = NULL;
2929 else if (*s == 'v') {
2930 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2931 s = force_version(s, FALSE);
2935 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2936 s = force_version(s, FALSE);
2938 yylval.ival = is_use;
2942 static const char* const exp_name[] =
2943 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2944 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
2951 Works out what to call the token just pulled out of the input
2952 stream. The yacc parser takes care of taking the ops we return and
2953 stitching them into a tree.
2959 if read an identifier
2960 if we're in a my declaration
2961 croak if they tried to say my($foo::bar)
2962 build the ops for a my() declaration
2963 if it's an access to a my() variable
2964 are we in a sort block?
2965 croak if my($a); $a <=> $b
2966 build ops for access to a my() variable
2967 if in a dq string, and they've said @foo and we can't find @foo
2969 build ops for a bareword
2970 if we already built the token before, use it.
2975 #pragma segment Perl_yylex
2981 register char *s = PL_bufptr;
2987 SV* tmp = newSVpvs("");
2988 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
2989 (IV)CopLINE(PL_curcop),
2990 lex_state_names[PL_lex_state],
2991 exp_name[PL_expect],
2992 pv_display(tmp, s, strlen(s), 0, 60));
2995 /* check if there's an identifier for us to look at */
2996 if (PL_pending_ident)
2997 return REPORT(S_pending_ident(aTHX));
2999 /* no identifier pending identification */
3001 switch (PL_lex_state) {
3003 case LEX_NORMAL: /* Some compilers will produce faster */
3004 case LEX_INTERPNORMAL: /* code if we comment these out. */
3008 /* when we've already built the next token, just pull it out of the queue */
3012 yylval = PL_nexttoke[PL_lasttoke].next_val;
3014 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3015 PL_nexttoke[PL_lasttoke].next_mad = 0;
3016 if (PL_thismad && PL_thismad->mad_key == '_') {
3017 PL_thiswhite = (SV*)PL_thismad->mad_val;
3018 PL_thismad->mad_val = 0;
3019 mad_free(PL_thismad);
3024 PL_lex_state = PL_lex_defer;
3025 PL_expect = PL_lex_expect;
3026 PL_lex_defer = LEX_NORMAL;
3027 if (!PL_nexttoke[PL_lasttoke].next_type)
3032 yylval = PL_nextval[PL_nexttoke];
3034 PL_lex_state = PL_lex_defer;
3035 PL_expect = PL_lex_expect;
3036 PL_lex_defer = LEX_NORMAL;
3040 /* FIXME - can these be merged? */
3041 return(PL_nexttoke[PL_lasttoke].next_type);
3043 return REPORT(PL_nexttype[PL_nexttoke]);
3046 /* interpolated case modifiers like \L \U, including \Q and \E.
3047 when we get here, PL_bufptr is at the \
3049 case LEX_INTERPCASEMOD:
3051 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3052 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3054 /* handle \E or end of string */
3055 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3057 if (PL_lex_casemods) {
3058 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3059 PL_lex_casestack[PL_lex_casemods] = '\0';
3061 if (PL_bufptr != PL_bufend
3062 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3064 PL_lex_state = LEX_INTERPCONCAT;
3067 PL_thistoken = newSVpvn("\\E",2);
3073 while (PL_bufptr != PL_bufend &&
3074 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3076 PL_thiswhite = newSVpvn("",0);
3077 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3081 if (PL_bufptr != PL_bufend)
3084 PL_lex_state = LEX_INTERPCONCAT;
3088 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3089 "### Saw case modifier\n"); });
3091 if (s[1] == '\\' && s[2] == 'E') {
3094 PL_thiswhite = newSVpvn("",0);
3095 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3098 PL_lex_state = LEX_INTERPCONCAT;
3103 if (!PL_madskills) /* when just compiling don't need correct */
3104 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3105 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3106 if ((*s == 'L' || *s == 'U') &&
3107 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3108 PL_lex_casestack[--PL_lex_casemods] = '\0';
3111 if (PL_lex_casemods > 10)
3112 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3113 PL_lex_casestack[PL_lex_casemods++] = *s;
3114 PL_lex_casestack[PL_lex_casemods] = '\0';
3115 PL_lex_state = LEX_INTERPCONCAT;
3116 start_force(PL_curforce);
3117 NEXTVAL_NEXTTOKE.ival = 0;
3119 start_force(PL_curforce);
3121 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3123 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3125 NEXTVAL_NEXTTOKE.ival = OP_LC;
3127 NEXTVAL_NEXTTOKE.ival = OP_UC;
3129 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3131 Perl_croak(aTHX_ "panic: yylex");
3133 SV* tmpsv = newSVpvn("",0);
3134 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3140 if (PL_lex_starts) {
3146 sv_free(PL_thistoken);
3147 PL_thistoken = newSVpvn("",0);
3150 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3151 if (PL_lex_casemods == 1 && PL_lex_inpat)
3160 case LEX_INTERPPUSH:
3161 return REPORT(sublex_push());
3163 case LEX_INTERPSTART:
3164 if (PL_bufptr == PL_bufend)
3165 return REPORT(sublex_done());
3166 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3167 "### Interpolated variable\n"); });
3169 PL_lex_dojoin = (*PL_bufptr == '@');
3170 PL_lex_state = LEX_INTERPNORMAL;
3171 if (PL_lex_dojoin) {
3172 start_force(PL_curforce);
3173 NEXTVAL_NEXTTOKE.ival = 0;
3175 start_force(PL_curforce);
3176 force_ident("\"", '$');
3177 start_force(PL_curforce);
3178 NEXTVAL_NEXTTOKE.ival = 0;
3180 start_force(PL_curforce);
3181 NEXTVAL_NEXTTOKE.ival = 0;
3183 start_force(PL_curforce);
3184 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3187 if (PL_lex_starts++) {
3192 sv_free(PL_thistoken);
3193 PL_thistoken = newSVpvn("",0);
3196 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3197 if (!PL_lex_casemods && PL_lex_inpat)
3204 case LEX_INTERPENDMAYBE:
3205 if (intuit_more(PL_bufptr)) {
3206 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3212 if (PL_lex_dojoin) {
3213 PL_lex_dojoin = FALSE;
3214 PL_lex_state = LEX_INTERPCONCAT;
3218 sv_free(PL_thistoken);
3219 PL_thistoken = newSVpvn("",0);
3224 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3225 && SvEVALED(PL_lex_repl))
3227 if (PL_bufptr != PL_bufend)
3228 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3232 case LEX_INTERPCONCAT:
3234 if (PL_lex_brackets)
3235 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3237 if (PL_bufptr == PL_bufend)
3238 return REPORT(sublex_done());
3240 if (SvIVX(PL_linestr) == '\'') {
3241 SV *sv = newSVsv(PL_linestr);
3244 else if ( PL_hints & HINT_NEW_RE )
3245 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
3246 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3250 s = scan_const(PL_bufptr);
3252 PL_lex_state = LEX_INTERPCASEMOD;
3254 PL_lex_state = LEX_INTERPSTART;
3257 if (s != PL_bufptr) {
3258 start_force(PL_curforce);
3260 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3262 NEXTVAL_NEXTTOKE = yylval;
3265 if (PL_lex_starts++) {
3269 sv_free(PL_thistoken);
3270 PL_thistoken = newSVpvn("",0);
3273 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3274 if (!PL_lex_casemods && PL_lex_inpat)
3287 PL_lex_state = LEX_NORMAL;
3288 s = scan_formline(PL_bufptr);
3289 if (!PL_lex_formbrack)
3295 PL_oldoldbufptr = PL_oldbufptr;
3301 sv_free(PL_thistoken);
3304 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3308 if (isIDFIRST_lazy_if(s,UTF))
3310 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
3313 goto fake_eof; /* emulate EOF on ^D or ^Z */
3322 if (PL_lex_brackets) {
3323 yyerror(PL_lex_formbrack
3324 ? "Format not terminated"
3325 : "Missing right curly or square bracket");
3327 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3328 "### Tokener got EOF\n");
3332 if (s++ < PL_bufend)
3333 goto retry; /* ignore stray nulls */
3336 if (!PL_in_eval && !PL_preambled) {
3337 PL_preambled = TRUE;
3342 sv_setpv(PL_linestr,incl_perldb());
3343 if (SvCUR(PL_linestr))
3344 sv_catpvs(PL_linestr,";");
3346 while(AvFILLp(PL_preambleav) >= 0) {
3347 SV *tmpsv = av_shift(PL_preambleav);
3348 sv_catsv(PL_linestr, tmpsv);
3349 sv_catpvs(PL_linestr, ";");
3352 sv_free((SV*)PL_preambleav);
3353 PL_preambleav = NULL;
3355 if (PL_minus_n || PL_minus_p) {
3356 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3358 sv_catpvs(PL_linestr,"chomp;");
3361 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3362 || *PL_splitstr == '"')
3363 && strchr(PL_splitstr + 1, *PL_splitstr))
3364 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3366 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3367 bytes can be used as quoting characters. :-) */
3368 const char *splits = PL_splitstr;
3369 sv_catpvs(PL_linestr, "our @F=split(q\0");
3372 if (*splits == '\\')
3373 sv_catpvn(PL_linestr, splits, 1);
3374 sv_catpvn(PL_linestr, splits, 1);
3375 } while (*splits++);
3376 /* This loop will embed the trailing NUL of
3377 PL_linestr as the last thing it does before
3379 sv_catpvs(PL_linestr, ");");
3383 sv_catpvs(PL_linestr,"our @F=split(' ');");
3387 sv_catpvs(PL_linestr,"use feature ':5.10';");
3388 sv_catpvs(PL_linestr, "\n");
3389 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3390 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3391 PL_last_lop = PL_last_uni = NULL;
3392 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3393 SV * const sv = newSV(0);
3395 sv_upgrade(sv, SVt_PVMG);
3396 sv_setsv(sv,PL_linestr);
3399 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
3404 bof = PL_rsfp ? TRUE : FALSE;
3405 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3408 PL_realtokenstart = -1;
3411 if (PL_preprocess && !PL_in_eval)
3412 (void)PerlProc_pclose(PL_rsfp);
3413 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3414 PerlIO_clearerr(PL_rsfp);
3416 (void)PerlIO_close(PL_rsfp);
3418 PL_doextract = FALSE;
3420 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3425 sv_setpv(PL_linestr,PL_minus_p
3426 ? ";}continue{print;}" : ";}");
3427 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3428 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3429 PL_last_lop = PL_last_uni = NULL;
3430 PL_minus_n = PL_minus_p = 0;
3433 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3434 PL_last_lop = PL_last_uni = NULL;
3435 sv_setpvn(PL_linestr,"",0);
3436 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3438 /* If it looks like the start of a BOM or raw UTF-16,
3439 * check if it in fact is. */
3445 #ifdef PERLIO_IS_STDIO
3446 # ifdef __GNU_LIBRARY__
3447 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3448 # define FTELL_FOR_PIPE_IS_BROKEN
3452 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3453 # define FTELL_FOR_PIPE_IS_BROKEN
3458 #ifdef FTELL_FOR_PIPE_IS_BROKEN
3459 /* This loses the possibility to detect the bof
3460 * situation on perl -P when the libc5 is being used.
3461 * Workaround? Maybe attach some extra state to PL_rsfp?
3464 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
3466 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3469 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3470 s = swallow_bom((U8*)s);
3474 /* Incest with pod. */
3477 sv_catsv(PL_thiswhite, PL_linestr);
3479 if (*s == '=' && strnEQ(s, "=cut", 4)) {
3480 sv_setpvn(PL_linestr, "", 0);
3481 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3482 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3483 PL_last_lop = PL_last_uni = NULL;
3484 PL_doextract = FALSE;
3488 } while (PL_doextract);
3489 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3490 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3491 SV * const sv = newSV(0);
3493 sv_upgrade(sv, SVt_PVMG);
3494 sv_setsv(sv,PL_linestr);
3497 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
3499 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3500 PL_last_lop = PL_last_uni = NULL;
3501 if (CopLINE(PL_curcop) == 1) {
3502 while (s < PL_bufend && isSPACE(*s))
3504 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3508 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3512 if (*s == '#' && *(s+1) == '!')
3514 #ifdef ALTERNATE_SHEBANG
3516 static char const as[] = ALTERNATE_SHEBANG;
3517 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3518 d = s + (sizeof(as) - 1);
3520 #endif /* ALTERNATE_SHEBANG */
3529 while (*d && !isSPACE(*d))
3533 #ifdef ARG_ZERO_IS_SCRIPT
3534 if (ipathend > ipath) {
3536 * HP-UX (at least) sets argv[0] to the script name,
3537 * which makes $^X incorrect. And Digital UNIX and Linux,
3538 * at least, set argv[0] to the basename of the Perl
3539 * interpreter. So, having found "#!", we'll set it right.
3541 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3543 assert(SvPOK(x) || SvGMAGICAL(x));
3544 if (sv_eq(x, CopFILESV(PL_curcop))) {
3545 sv_setpvn(x, ipath, ipathend - ipath);
3551 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3552 const char * const lstart = SvPV_const(x,llen);
3554 bstart += blen - llen;
3555 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3556 sv_setpvn(x, ipath, ipathend - ipath);
3561 TAINT_NOT; /* $^X is always tainted, but that's OK */
3563 #endif /* ARG_ZERO_IS_SCRIPT */
3568 d = instr(s,"perl -");
3570 d = instr(s,"perl");
3572 /* avoid getting into infinite loops when shebang
3573 * line contains "Perl" rather than "perl" */
3575 for (d = ipathend-4; d >= ipath; --d) {
3576 if ((*d == 'p' || *d == 'P')
3577 && !ibcmp(d, "perl", 4))
3587 #ifdef ALTERNATE_SHEBANG
3589 * If the ALTERNATE_SHEBANG on this system starts with a
3590 * character that can be part of a Perl expression, then if
3591 * we see it but not "perl", we're probably looking at the
3592 * start of Perl code, not a request to hand off to some
3593 * other interpreter. Similarly, if "perl" is there, but
3594 * not in the first 'word' of the line, we assume the line
3595 * contains the start of the Perl program.
3597 if (d && *s != '#') {
3598 const char *c = ipath;
3599 while (*c && !strchr("; \t\r\n\f\v#", *c))
3602 d = NULL; /* "perl" not in first word; ignore */
3604 *s = '#'; /* Don't try to parse shebang line */
3606 #endif /* ALTERNATE_SHEBANG */
3607 #ifndef MACOS_TRADITIONAL
3612 !instr(s,"indir") &&
3613 instr(PL_origargv[0],"perl"))
3620 while (s < PL_bufend && isSPACE(*s))
3622 if (s < PL_bufend) {
3623 Newxz(newargv,PL_origargc+3,char*);
3625 while (s < PL_bufend && !isSPACE(*s))
3628 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3631 newargv = PL_origargv;
3634 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3636 Perl_croak(aTHX_ "Can't exec %s", ipath);
3640 while (*d && !isSPACE(*d)) d++;
3641 while (SPACE_OR_TAB(*d)) d++;
3644 const bool switches_done = PL_doswitches;
3645 const U32 oldpdb = PL_perldb;
3646 const bool oldn = PL_minus_n;
3647 const bool oldp = PL_minus_p;
3650 if (*d == 'M' || *d == 'm' || *d == 'C') {
3651 const char * const m = d;
3652 while (*d && !isSPACE(*d)) d++;
3653 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3656 d = moreswitches(d);
3658 if (PL_doswitches && !switches_done) {
3659 int argc = PL_origargc;
3660 char **argv = PL_origargv;
3663 } while (argc && argv[0][0] == '-' && argv[0][1]);
3664 init_argv_symbols(argc,argv);
3666 if ((PERLDB_LINE && !oldpdb) ||
3667 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3668 /* if we have already added "LINE: while (<>) {",
3669 we must not do it again */
3671 sv_setpvn(PL_linestr, "", 0);
3672 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3673 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3674 PL_last_lop = PL_last_uni = NULL;
3675 PL_preambled = FALSE;
3677 (void)gv_fetchfile(PL_origfilename);
3684 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3686 PL_lex_state = LEX_FORMLINE;
3691 #ifdef PERL_STRICT_CR
3692 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3694 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3696 case ' ': case '\t': case '\f': case 013:
3697 #ifdef MACOS_TRADITIONAL
3701 PL_realtokenstart = -1;
3710 PL_realtokenstart = -1;
3714 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3715 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3716 /* handle eval qq[#line 1 "foo"\n ...] */
3717 CopLINE_dec(PL_curcop);
3720 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3722 if (!PL_in_eval || PL_rsfp)
3727 while (d < PL_bufend && *d != '\n')
3731 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3732 Perl_croak(aTHX_ "panic: input overflow");
3735 PL_thiswhite = newSVpvn(s, d - s);
3740 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3742 PL_lex_state = LEX_FORMLINE;
3748 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3749 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3752 TOKEN(PEG); /* make sure any #! line is accessible */
3757 /* if (PL_madskills && PL_lex_formbrack) { */
3759 while (d < PL_bufend && *d != '\n')
3763 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3764 Perl_croak(aTHX_ "panic: input overflow");
3765 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
3767 PL_thiswhite = newSVpvn("",0);
3768 if (CopLINE(PL_curcop) == 1) {
3769 sv_setpvn(PL_thiswhite, "", 0);
3772 sv_catpvn(PL_thiswhite, s, d - s);
3786 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
3794 while (s < PL_bufend && SPACE_OR_TAB(*s))
3797 if (strnEQ(s,"=>",2)) {
3798 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
3799 DEBUG_T( { S_printbuf(aTHX_
3800 "### Saw unary minus before =>, forcing word %s\n", s);
3802 OPERATOR('-'); /* unary minus */
3804 PL_last_uni = PL_oldbufptr;
3806 case 'r': ftst = OP_FTEREAD; break;
3807 case 'w': ftst = OP_FTEWRITE; break;
3808 case 'x': ftst = OP_FTEEXEC; break;
3809 case 'o': ftst = OP_FTEOWNED; break;
3810 case 'R': ftst = OP_FTRREAD; break;
3811 case 'W': ftst = OP_FTRWRITE; break;
3812 case 'X': ftst = OP_FTREXEC; break;
3813 case 'O': ftst = OP_FTROWNED; break;
3814 case 'e': ftst = OP_FTIS; break;
3815 case 'z': ftst = OP_FTZERO; break;
3816 case 's': ftst = OP_FTSIZE; break;
3817 case 'f': ftst = OP_FTFILE; break;
3818 case 'd': ftst = OP_FTDIR; break;
3819 case 'l': ftst = OP_FTLINK; break;
3820 case 'p': ftst = OP_FTPIPE; break;
3821 case 'S': ftst = OP_FTSOCK; break;
3822 case 'u': ftst = OP_FTSUID; break;
3823 case 'g': ftst = OP_FTSGID; break;
3824 case 'k': ftst = OP_FTSVTX; break;
3825 case 'b': ftst = OP_FTBLK; break;
3826 case 'c': ftst = OP_FTCHR; break;
3827 case 't': ftst = OP_FTTTY; break;
3828 case 'T': ftst = OP_FTTEXT; break;
3829 case 'B': ftst = OP_FTBINARY; break;
3830 case 'M': case 'A': case 'C':
3831 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
3833 case 'M': ftst = OP_FTMTIME; break;
3834 case 'A': ftst = OP_FTATIME; break;
3835 case 'C': ftst = OP_FTCTIME; break;
3843 PL_last_lop_op = (OPCODE)ftst;
3844 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3845 "### Saw file test %c\n", (int)tmp);
3850 /* Assume it was a minus followed by a one-letter named
3851 * subroutine call (or a -bareword), then. */
3852 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3853 "### '-%c' looked like a file test but was not\n",
3860 const char tmp = *s++;
3863 if (PL_expect == XOPERATOR)
3868 else if (*s == '>') {
3871 if (isIDFIRST_lazy_if(s,UTF)) {
3872 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
3880 if (PL_expect == XOPERATOR)
3883 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3885 OPERATOR('-'); /* unary minus */
3891 const char tmp = *s++;
3894 if (PL_expect == XOPERATOR)
3899 if (PL_expect == XOPERATOR)
3902 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3909 if (PL_expect != XOPERATOR) {
3910 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3911 PL_expect = XOPERATOR;
3912 force_ident(PL_tokenbuf, '*');
3925 if (PL_expect == XOPERATOR) {
3929 PL_tokenbuf[0] = '%';
3930 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
3931 if (!PL_tokenbuf[1]) {
3934 PL_pending_ident = '%';
3945 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)
3946 && FEATURE_IS_ENABLED("~~"))
3953 const char tmp = *s++;
3959 goto just_a_word_zero_gv;
3962 switch (PL_expect) {
3968 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
3970 PL_bufptr = s; /* update in case we back off */
3976 PL_expect = XTERMBLOCK;
3979 stuffstart = s - SvPVX(PL_linestr) - 1;
3983 while (isIDFIRST_lazy_if(s,UTF)) {
3985 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3986 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
3987 if (tmp < 0) tmp = -tmp;
4003 d = scan_str(d,TRUE,TRUE);
4005 /* MUST advance bufptr here to avoid bogus
4006 "at end of line" context messages from yyerror().
4008 PL_bufptr = s + len;
4009 yyerror("Unterminated attribute parameter in attribute list");
4012 return REPORT(0); /* EOF indicator */
4016 SV *sv = newSVpvn(s, len);
4017 sv_catsv(sv, PL_lex_stuff);
4018 attrs = append_elem(OP_LIST, attrs,
4019 newSVOP(OP_CONST, 0, sv));
4020 SvREFCNT_dec(PL_lex_stuff);
4021 PL_lex_stuff = NULL;
4024 if (len == 6 && strnEQ(s, "unique", len)) {
4025 if (PL_in_my == KEY_our) {
4027 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4029 /* skip to avoid loading attributes.pm */
4031 deprecate(":unique");
4034 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4037 /* NOTE: any CV attrs applied here need to be part of
4038 the CVf_BUILTIN_ATTRS define in cv.h! */
4039 else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
4040 CvLVALUE_on(PL_compcv);
4041 else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
4042 CvLOCKED_on(PL_compcv);
4043 else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
4044 CvMETHOD_on(PL_compcv);
4045 else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len))
4046 CvASSERTION_on(PL_compcv);
4047 /* After we've set the flags, it could be argued that
4048 we don't need to do the attributes.pm-based setting
4049 process, and shouldn't bother appending recognized
4050 flags. To experiment with that, uncomment the
4051 following "else". (Note that's already been
4052 uncommented. That keeps the above-applied built-in
4053 attributes from being intercepted (and possibly
4054 rejected) by a package's attribute routines, but is
4055 justified by the performance win for the common case
4056 of applying only built-in attributes.) */
4058 attrs = append_elem(OP_LIST, attrs,
4059 newSVOP(OP_CONST, 0,
4063 if (*s == ':' && s[1] != ':')
4066 break; /* require real whitespace or :'s */
4067 /* XXX losing whitespace on sequential attributes here */
4071 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4072 if (*s != ';' && *s != '}' && *s != tmp
4073 && (tmp != '=' || *s != ')')) {
4074 const char q = ((*s == '\'') ? '"' : '\'');
4075 /* If here for an expression, and parsed no attrs, back
4077 if (tmp == '=' && !attrs) {
4081 /* MUST advance bufptr here to avoid bogus "at end of line"
4082 context messages from yyerror().
4086 ? Perl_form(aTHX_ "Invalid separator character "
4087 "%c%c%c in attribute list", q, *s, q)
4088 : "Unterminated attribute list" );
4096 start_force(PL_curforce);
4097 NEXTVAL_NEXTTOKE.opval = attrs;
4098 CURMAD('_', PL_nextwhite);
4103 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4104 (s - SvPVX(PL_linestr)) - stuffstart);
4112 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4113 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4121 const char tmp = *s++;
4126 const char tmp = *s++;
4134 if (PL_lex_brackets <= 0)
4135 yyerror("Unmatched right square bracket");
4138 if (PL_lex_state == LEX_INTERPNORMAL) {
4139 if (PL_lex_brackets == 0) {
4140 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4141 PL_lex_state = LEX_INTERPEND;
4148 if (PL_lex_brackets > 100) {
4149 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4151 switch (PL_expect) {
4153 if (PL_lex_formbrack) {
4157 if (PL_oldoldbufptr == PL_last_lop)
4158 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4160 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4161 OPERATOR(HASHBRACK);
4163 while (s < PL_bufend && SPACE_OR_TAB(*s))
4166 PL_tokenbuf[0] = '\0';
4167 if (d < PL_bufend && *d == '-') {
4168 PL_tokenbuf[0] = '-';
4170 while (d < PL_bufend && SPACE_OR_TAB(*d))
4173 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4174 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4176 while (d < PL_bufend && SPACE_OR_TAB(*d))
4179 const char minus = (PL_tokenbuf[0] == '-');
4180 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4188 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4193 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4198 if (PL_oldoldbufptr == PL_last_lop)
4199 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4201 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4204 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4206 /* This hack is to get the ${} in the message. */
4208 yyerror("syntax error");
4211 OPERATOR(HASHBRACK);
4213 /* This hack serves to disambiguate a pair of curlies
4214 * as being a block or an anon hash. Normally, expectation
4215 * determines that, but in cases where we're not in a
4216 * position to expect anything in particular (like inside
4217 * eval"") we have to resolve the ambiguity. This code
4218 * covers the case where the first term in the curlies is a
4219 * quoted string. Most other cases need to be explicitly
4220 * disambiguated by prepending a "+" before the opening
4221 * curly in order to force resolution as an anon hash.
4223 * XXX should probably propagate the outer expectation
4224 * into eval"" to rely less on this hack, but that could
4225 * potentially break current behavior of eval"".
4229 if (*s == '\'' || *s == '"' || *s == '`') {
4230 /* common case: get past first string, handling escapes */
4231 for (t++; t < PL_bufend && *t != *s;)
4232 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4236 else if (*s == 'q') {
4239 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4242 /* skip q//-like construct */
4244 char open, close, term;
4247 while (t < PL_bufend && isSPACE(*t))
4249 /* check for q => */
4250 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4251 OPERATOR(HASHBRACK);
4255 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4259 for (t++; t < PL_bufend; t++) {
4260 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4262 else if (*t == open)
4266 for (t++; t < PL_bufend; t++) {
4267 if (*t == '\\' && t+1 < PL_bufend)
4269 else if (*t == close && --brackets <= 0)
4271 else if (*t == open)
4278 /* skip plain q word */
4279 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4282 else if (isALNUM_lazy_if(t,UTF)) {
4284 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4287 while (t < PL_bufend && isSPACE(*t))
4289 /* if comma follows first term, call it an anon hash */
4290 /* XXX it could be a comma expression with loop modifiers */
4291 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4292 || (*t == '=' && t[1] == '>')))
4293 OPERATOR(HASHBRACK);
4294 if (PL_expect == XREF)
4297 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4303 yylval.ival = CopLINE(PL_curcop);
4304 if (isSPACE(*s) || *s == '#')
4305 PL_copline = NOLINE; /* invalidate current command line number */
4310 if (PL_lex_brackets <= 0)
4311 yyerror("Unmatched right curly bracket");
4313 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4314 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4315 PL_lex_formbrack = 0;
4316 if (PL_lex_state == LEX_INTERPNORMAL) {
4317 if (PL_lex_brackets == 0) {
4318 if (PL_expect & XFAKEBRACK) {
4319 PL_expect &= XENUMMASK;
4320 PL_lex_state = LEX_INTERPEND;
4325 PL_thiswhite = newSVpvn("",0);
4326 sv_catpvn(PL_thiswhite,"}",1);
4329 return yylex(); /* ignore fake brackets */
4331 if (*s == '-' && s[1] == '>')
4332 PL_lex_state = LEX_INTERPENDMAYBE;
4333 else if (*s != '[' && *s != '{')
4334 PL_lex_state = LEX_INTERPEND;
4337 if (PL_expect & XFAKEBRACK) {
4338 PL_expect &= XENUMMASK;
4340 return yylex(); /* ignore fake brackets */
4342 start_force(PL_curforce);
4344 curmad('X', newSVpvn(s-1,1));
4345 CURMAD('_', PL_thiswhite);
4350 PL_thistoken = newSVpvn("",0);
4358 if (PL_expect == XOPERATOR) {
4359 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4360 && isIDFIRST_lazy_if(s,UTF))
4362 CopLINE_dec(PL_curcop);
4363 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4364 CopLINE_inc(PL_curcop);
4369 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4371 PL_expect = XOPERATOR;
4372 force_ident(PL_tokenbuf, '&');
4376 yylval.ival = (OPpENTERSUB_AMPER<<8);
4388 const char tmp = *s++;
4395 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4396 && strchr("+-*/%.^&|<",tmp))
4397 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4398 "Reversed %c= operator",(int)tmp);
4400 if (PL_expect == XSTATE && isALPHA(tmp) &&
4401 (s == PL_linestart+1 || s[-2] == '\n') )
4403 if (PL_in_eval && !PL_rsfp) {
4408 if (strnEQ(s,"=cut",4)) {
4424 PL_thiswhite = newSVpvn("",0);
4425 sv_catpvn(PL_thiswhite, PL_linestart,
4426 PL_bufend - PL_linestart);
4430 PL_doextract = TRUE;
4434 if (PL_lex_brackets < PL_lex_formbrack) {
4436 #ifdef PERL_STRICT_CR
4437 for (t = s; SPACE_OR_TAB(*t); t++) ;
4439 for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
4441 if (*t == '\n' || *t == '#') {
4452 const char tmp = *s++;
4454 /* was this !=~ where !~ was meant?
4455 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4457 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4458 const char *t = s+1;
4460 while (t < PL_bufend && isSPACE(*t))
4463 if (*t == '/' || *t == '?' ||
4464 ((*t == 'm' || *t == 's' || *t == 'y')
4465 && !isALNUM(t[1])) ||
4466 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4467 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4468 "!=~ should be !~");
4478 if (PL_expect != XOPERATOR) {
4479 if (s[1] != '<' && !strchr(s,'>'))
4482 s = scan_heredoc(s);
4484 s = scan_inputsymbol(s);
4485 TERM(sublex_start());
4491 SHop(OP_LEFT_SHIFT);
4505 const char tmp = *s++;
4507 SHop(OP_RIGHT_SHIFT);
4517 if (PL_expect == XOPERATOR) {
4518 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4520 deprecate_old(commaless_variable_list);
4521 return REPORT(','); /* grandfather non-comma-format format */
4525 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4526 PL_tokenbuf[0] = '@';
4527 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4528 sizeof PL_tokenbuf - 1, FALSE);
4529 if (PL_expect == XOPERATOR)
4530 no_op("Array length", s);
4531 if (!PL_tokenbuf[1])
4533 PL_expect = XOPERATOR;
4534 PL_pending_ident = '#';
4538 PL_tokenbuf[0] = '$';
4539 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4540 sizeof PL_tokenbuf - 1, FALSE);
4541 if (PL_expect == XOPERATOR)
4543 if (!PL_tokenbuf[1]) {
4545 yyerror("Final $ should be \\$ or $name");
4549 /* This kludge not intended to be bulletproof. */
4550 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4551 yylval.opval = newSVOP(OP_CONST, 0,
4552 newSViv(PL_compiling.cop_arybase));
4553 yylval.opval->op_private = OPpCONST_ARYBASE;
4559 const char tmp = *s;
4560 if (PL_lex_state == LEX_NORMAL)
4563 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4564 && intuit_more(s)) {
4566 PL_tokenbuf[0] = '@';
4567 if (ckWARN(WARN_SYNTAX)) {
4570 isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
4573 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4574 while (t < PL_bufend && *t != ']')
4576 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4577 "Multidimensional syntax %.*s not supported",
4578 (int)((t - PL_bufptr) + 1), PL_bufptr);
4582 else if (*s == '{') {
4584 PL_tokenbuf[0] = '%';
4585 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4586 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4588 char tmpbuf[sizeof PL_tokenbuf];
4589 for (t++; isSPACE(*t); t++) ;
4590 if (isIDFIRST_lazy_if(t,UTF)) {
4592 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4594 for (; isSPACE(*t); t++) ;
4595 if (*t == ';' && get_cv(tmpbuf, FALSE))
4596 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4597 "You need to quote \"%s\"",
4604 PL_expect = XOPERATOR;
4605 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4606 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4607 if (!islop || PL_last_lop_op == OP_GREPSTART)
4608 PL_expect = XOPERATOR;
4609 else if (strchr("$@\"'`q", *s))
4610 PL_expect = XTERM; /* e.g. print $fh "foo" */
4611 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4612 PL_expect = XTERM; /* e.g. print $fh &sub */
4613 else if (isIDFIRST_lazy_if(s,UTF)) {
4614 char tmpbuf[sizeof PL_tokenbuf];
4616 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4617 if ((t2 = keyword(tmpbuf, len))) {
4618 /* binary operators exclude handle interpretations */
4630 PL_expect = XTERM; /* e.g. print $fh length() */
4635 PL_expect = XTERM; /* e.g. print $fh subr() */
4638 else if (isDIGIT(*s))
4639 PL_expect = XTERM; /* e.g. print $fh 3 */
4640 else if (*s == '.' && isDIGIT(s[1]))
4641 PL_expect = XTERM; /* e.g. print $fh .3 */
4642 else if ((*s == '?' || *s == '-' || *s == '+')
4643 && !isSPACE(s[1]) && s[1] != '=')
4644 PL_expect = XTERM; /* e.g. print $fh -1 */
4645 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4647 PL_expect = XTERM; /* e.g. print $fh /.../
4648 XXX except DORDOR operator
4650 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4652 PL_expect = XTERM; /* print $fh <<"EOF" */
4655 PL_pending_ident = '$';
4659 if (PL_expect == XOPERATOR)
4661 PL_tokenbuf[0] = '@';
4662 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4663 if (!PL_tokenbuf[1]) {
4666 if (PL_lex_state == LEX_NORMAL)
4668 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4670 PL_tokenbuf[0] = '%';
4672 /* Warn about @ where they meant $. */
4673 if (*s == '[' || *s == '{') {
4674 if (ckWARN(WARN_SYNTAX)) {
4675 const char *t = s + 1;
4676 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4678 if (*t == '}' || *t == ']') {
4680 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4681 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4682 "Scalar value %.*s better written as $%.*s",
4683 (int)(t-PL_bufptr), PL_bufptr,
4684 (int)(t-PL_bufptr-1), PL_bufptr+1);
4689 PL_pending_ident = '@';
4692 case '/': /* may be division, defined-or, or pattern */
4693 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4697 case '?': /* may either be conditional or pattern */
4698 if(PL_expect == XOPERATOR) {
4706 /* A // operator. */
4716 /* Disable warning on "study /blah/" */
4717 if (PL_oldoldbufptr == PL_last_uni
4718 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4719 || memNE(PL_last_uni, "study", 5)
4720 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4723 s = scan_pat(s,OP_MATCH);
4724 TERM(sublex_start());
4728 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4729 #ifdef PERL_STRICT_CR
4732 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4734 && (s == PL_linestart || s[-1] == '\n') )
4736 PL_lex_formbrack = 0;
4740 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4746 yylval.ival = OPf_SPECIAL;
4752 if (PL_expect != XOPERATOR)
4757 case '0': case '1': case '2': case '3': case '4':
4758 case '5': case '6': case '7': case '8': case '9':
4759 s = scan_num(s, &yylval);
4760 DEBUG_T( { S_printbuf(aTHX_ "### Saw number in %s\n", s); } );
4761 if (PL_expect == XOPERATOR)
4766 s = scan_str(s,!!PL_madskills,FALSE);
4767 DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } );
4768 if (PL_expect == XOPERATOR) {
4769 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4771 deprecate_old(commaless_variable_list);
4772 return REPORT(','); /* grandfather non-comma-format format */
4778 missingterm((char*)0);
4779 yylval.ival = OP_CONST;
4780 TERM(sublex_start());
4783 s = scan_str(s,!!PL_madskills,FALSE);
4784 DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } );
4785 if (PL_expect == XOPERATOR) {
4786 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4788 deprecate_old(commaless_variable_list);
4789 return REPORT(','); /* grandfather non-comma-format format */
4795 missingterm((char*)0);
4796 yylval.ival = OP_CONST;
4797 /* FIXME. I think that this can be const if char *d is replaced by
4798 more localised variables. */
4799 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
4800 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
4801 yylval.ival = OP_STRINGIFY;
4805 TERM(sublex_start());
4808 s = scan_str(s,!!PL_madskills,FALSE);
4809 DEBUG_T( { S_printbuf(aTHX_ "### Saw backtick string before %s\n", s); } );
4810 if (PL_expect == XOPERATOR)
4811 no_op("Backticks",s);
4813 missingterm((char*)0);
4814 yylval.ival = OP_BACKTICK;
4816 TERM(sublex_start());
4820 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
4821 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
4823 if (PL_expect == XOPERATOR)
4824 no_op("Backslash",s);
4828 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
4829 char *start = s + 2;
4830 while (isDIGIT(*start) || *start == '_')
4832 if (*start == '.' && isDIGIT(start[1])) {
4833 s = scan_num(s, &yylval);
4836 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
4837 else if (!isALPHA(*start) && (PL_expect == XTERM
4838 || PL_expect == XREF || PL_expect == XSTATE
4839 || PL_expect == XTERMORDORDOR)) {
4840 const char c = *start;
4843 gv = gv_fetchpv(s, 0, SVt_PVCV);
4846 s = scan_num(s, &yylval);
4853 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
4889 I32 orig_keyword = 0;
4894 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4896 /* Some keywords can be followed by any delimiter, including ':' */
4897 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
4898 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
4899 (PL_tokenbuf[0] == 'q' &&
4900 strchr("qwxr", PL_tokenbuf[1])))));
4902 /* x::* is just a word, unless x is "CORE" */
4903 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4907 while (d < PL_bufend && isSPACE(*d))
4908 d++; /* no comments skipped here, or s### is misparsed */
4910 /* Is this a label? */
4911 if (!tmp && PL_expect == XSTATE
4912 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
4914 yylval.pval = savepv(PL_tokenbuf);
4919 /* Check for keywords */
4920 tmp = keyword(PL_tokenbuf, len);
4922 /* Is this a word before a => operator? */
4923 if (*d == '=' && d[1] == '>') {
4926 = (OP*)newSVOP(OP_CONST, 0,
4927 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
4928 yylval.opval->op_private = OPpCONST_BARE;
4932 if (tmp < 0) { /* second-class keyword? */
4933 GV *ogv = NULL; /* override (winner) */
4934 GV *hgv = NULL; /* hidden (loser) */
4935 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
4937 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
4940 if (GvIMPORTED_CV(gv))
4942 else if (! CvMETHOD(cv))
4946 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
4947 (gv = *gvp) != (GV*)&PL_sv_undef &&
4948 GvCVu(gv) && GvIMPORTED_CV(gv))
4955 tmp = 0; /* overridden by import or by GLOBAL */
4958 && -tmp==KEY_lock /* XXX generalizable kludge */
4960 && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
4962 tmp = 0; /* any sub overrides "weak" keyword */
4964 else { /* no override */
4966 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
4967 Perl_warner(aTHX_ packWARN(WARN_MISC),
4968 "dump() better written as CORE::dump()");
4972 if (hgv && tmp != KEY_x && tmp != KEY_CORE
4973 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
4974 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4975 "Ambiguous call resolved as CORE::%s(), %s",
4976 GvENAME(hgv), "qualify as such or use &");
4983 default: /* not a keyword */
4984 /* Trade off - by using this evil construction we can pull the
4985 variable gv into the block labelled keylookup. If not, then
4986 we have to give it function scope so that the goto from the
4987 earlier ':' case doesn't bypass the initialisation. */
4989 just_a_word_zero_gv:
4997 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5000 SV *nextPL_nextwhite = 0;
5004 /* Get the rest if it looks like a package qualifier */
5006 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5008 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5011 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5012 *s == '\'' ? "'" : "::");
5017 if (PL_expect == XOPERATOR) {
5018 if (PL_bufptr == PL_linestart) {
5019 CopLINE_dec(PL_curcop);
5020 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5021 CopLINE_inc(PL_curcop);
5024 no_op("Bareword",s);
5027 /* Look for a subroutine with this name in current package,
5028 unless name is "Foo::", in which case Foo is a bearword
5029 (and a package name). */
5031 if (len > 2 && !PL_madskills &&
5032 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5034 if (ckWARN(WARN_BAREWORD)
5035 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5036 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5037 "Bareword \"%s\" refers to nonexistent package",
5040 PL_tokenbuf[len] = '\0';
5046 /* Mustn't actually add anything to a symbol table.
5047 But also don't want to "initialise" any placeholder
5048 constants that might already be there into full
5049 blown PVGVs with attached PVCV. */
5050 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5051 GV_NOADD_NOINIT, SVt_PVCV);
5056 /* if we saw a global override before, get the right name */
5059 sv = newSVpvs("CORE::GLOBAL::");
5060 sv_catpv(sv,PL_tokenbuf);
5063 /* If len is 0, newSVpv does strlen(), which is correct.
5064 If len is non-zero, then it will be the true length,
5065 and so the scalar will be created correctly. */
5066 sv = newSVpv(PL_tokenbuf,len);
5069 if (PL_madskills && !PL_thistoken) {
5070 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5071 PL_thistoken = newSVpv(start,s - start);
5072 PL_realtokenstart = s - SvPVX(PL_linestr);
5076 /* Presume this is going to be a bareword of some sort. */
5079 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5080 yylval.opval->op_private = OPpCONST_BARE;
5081 /* UTF-8 package name? */
5082 if (UTF && !IN_BYTES &&
5083 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5086 /* And if "Foo::", then that's what it certainly is. */
5091 /* Do the explicit type check so that we don't need to force
5092 the initialisation of the symbol table to have a real GV.
5093 Beware - gv may not really be a PVGV, cv may not really be
5094 a PVCV, (because of the space optimisations that gv_init
5095 understands) But they're true if for this symbol there is
5096 respectively a typeglob and a subroutine.
5098 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5099 /* Real typeglob, so get the real subroutine: */
5101 /* A proxy for a subroutine in this package? */
5102 : SvOK(gv) ? (CV *) gv : NULL)
5105 /* See if it's the indirect object for a list operator. */
5107 if (PL_oldoldbufptr &&
5108 PL_oldoldbufptr < PL_bufptr &&
5109 (PL_oldoldbufptr == PL_last_lop
5110 || PL_oldoldbufptr == PL_last_uni) &&
5111 /* NO SKIPSPACE BEFORE HERE! */
5112 (PL_expect == XREF ||
5113 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5115 bool immediate_paren = *s == '(';
5117 /* (Now we can afford to cross potential line boundary.) */
5118 s = SKIPSPACE2(s,nextPL_nextwhite);
5120 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5123 /* Two barewords in a row may indicate method call. */
5125 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5126 (tmp = intuit_method(s, gv, cv)))
5129 /* If not a declared subroutine, it's an indirect object. */
5130 /* (But it's an indir obj regardless for sort.) */
5131 /* Also, if "_" follows a filetest operator, it's a bareword */
5134 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5136 (PL_last_lop_op != OP_MAPSTART &&
5137 PL_last_lop_op != OP_GREPSTART))))
5138 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5139 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5142 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5147 PL_expect = XOPERATOR;
5150 s = SKIPSPACE2(s,nextPL_nextwhite);
5151 PL_nextwhite = nextPL_nextwhite;
5156 /* Is this a word before a => operator? */
5157 if (*s == '=' && s[1] == '>' && !pkgname) {
5159 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5160 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5161 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5165 /* If followed by a paren, it's certainly a subroutine. */
5169 for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
5170 if (*d == ')' && (sv = gv_const_sv(gv))) {
5174 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5175 sv_catpvn(PL_thistoken, par, s - par);
5177 sv_free(PL_nextwhite);
5187 PL_nextwhite = PL_thiswhite;
5190 start_force(PL_curforce);
5192 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5193 PL_expect = XOPERATOR;
5196 PL_nextwhite = nextPL_nextwhite;
5197 curmad('X', PL_thistoken);
5198 PL_thistoken = newSVpvn("",0);
5206 /* If followed by var or block, call it a method (unless sub) */
5208 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5209 PL_last_lop = PL_oldbufptr;
5210 PL_last_lop_op = OP_METHOD;
5214 /* If followed by a bareword, see if it looks like indir obj. */
5217 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5218 && (tmp = intuit_method(s, gv, cv)))
5221 /* Not a method, so call it a subroutine (if defined) */
5224 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5225 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5226 "Ambiguous use of -%s resolved as -&%s()",
5227 PL_tokenbuf, PL_tokenbuf);
5228 /* Check for a constant sub */
5229 if ((sv = gv_const_sv(gv))) {
5231 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5232 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5233 yylval.opval->op_private = 0;
5237 /* Resolve to GV now. */
5238 if (SvTYPE(gv) != SVt_PVGV) {
5239 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5240 assert (SvTYPE(gv) == SVt_PVGV);
5241 /* cv must have been some sort of placeholder, so
5242 now needs replacing with a real code reference. */
5246 op_free(yylval.opval);
5247 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5248 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5249 PL_last_lop = PL_oldbufptr;
5250 PL_last_lop_op = OP_ENTERSUB;
5251 /* Is there a prototype? */
5258 const char *proto = SvPV_const((SV*)cv, protolen);
5261 if (*proto == '$' && proto[1] == '\0')
5263 while (*proto == ';')
5265 if (*proto == '&' && *s == '{') {
5266 sv_setpv(PL_subname, PL_curstash ?
5267 "__ANON__" : "__ANON__::__ANON__");
5274 PL_nextwhite = PL_thiswhite;
5277 start_force(PL_curforce);
5278 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5281 PL_nextwhite = nextPL_nextwhite;
5282 curmad('X', PL_thistoken);
5283 PL_thistoken = newSVpvn("",0);
5290 /* Guess harder when madskills require "best effort". */
5291 if (PL_madskills && (!gv || !GvCVu(gv))) {
5292 int probable_sub = 0;
5293 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5295 else if (isALPHA(*s)) {
5299 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5300 if (!keyword(tmpbuf,tmplen))
5303 while (d < PL_bufend && isSPACE(*d))
5305 if (*d == '=' && d[1] == '>')
5310 gv = gv_fetchpv(PL_tokenbuf, TRUE, SVt_PVCV);
5311 op_free(yylval.opval);
5312 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5313 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5314 PL_last_lop = PL_oldbufptr;
5315 PL_last_lop_op = OP_ENTERSUB;
5316 PL_nextwhite = PL_thiswhite;
5318 start_force(PL_curforce);
5319 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5321 PL_nextwhite = nextPL_nextwhite;
5322 curmad('X', PL_thistoken);
5323 PL_thistoken = newSVpvn("",0);
5328 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5335 /* Call it a bare word */
5337 if (PL_hints & HINT_STRICT_SUBS)
5338 yylval.opval->op_private |= OPpCONST_STRICT;
5341 if (lastchar != '-') {
5342 if (ckWARN(WARN_RESERVED)) {
5343 for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
5344 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
5345 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5352 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5353 && ckWARN_d(WARN_AMBIGUOUS)) {
5354 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5355 "Operator or semicolon missing before %c%s",
5356 lastchar, PL_tokenbuf);
5357 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5358 "Ambiguous use of %c resolved as operator %c",
5359 lastchar, lastchar);
5365 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5366 newSVpv(CopFILE(PL_curcop),0));
5370 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5371 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5374 case KEY___PACKAGE__:
5375 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5377 ? newSVhek(HvNAME_HEK(PL_curstash))
5384 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5385 const char *pname = "main";
5386 if (PL_tokenbuf[2] == 'D')
5387 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5388 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5392 GvIOp(gv) = newIO();
5393 IoIFP(GvIOp(gv)) = PL_rsfp;
5394 #if defined(HAS_FCNTL) && defined(F_SETFD)
5396 const int fd = PerlIO_fileno(PL_rsfp);
5397 fcntl(fd,F_SETFD,fd >= 3);
5400 /* Mark this internal pseudo-handle as clean */
5401 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5403 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5404 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5405 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5407 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5408 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5409 /* if the script was opened in binmode, we need to revert
5410 * it to text mode for compatibility; but only iff it has CRs
5411 * XXX this is a questionable hack at best. */
5412 if (PL_bufend-PL_bufptr > 2
5413 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5416 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5417 loc = PerlIO_tell(PL_rsfp);
5418 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5421 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5423 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5424 #endif /* NETWARE */
5425 #ifdef PERLIO_IS_STDIO /* really? */
5426 # if defined(__BORLANDC__)
5427 /* XXX see note in do_binmode() */
5428 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5432 PerlIO_seek(PL_rsfp, loc, 0);
5436 #ifdef PERLIO_LAYERS
5439 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5440 else if (PL_encoding) {
5447 XPUSHs(PL_encoding);
5449 call_method("name", G_SCALAR);
5453 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5454 Perl_form(aTHX_ ":encoding(%"SVf")",
5463 if (PL_realtokenstart >= 0) {
5464 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5466 PL_endwhite = newSVpvn("",0);
5467 sv_catsv(PL_endwhite, PL_thiswhite);
5469 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5470 PL_realtokenstart = -1;
5472 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5473 SvCUR(PL_endwhite))) != Nullch) ;
5487 if (PL_expect == XSTATE) {
5494 if (*s == ':' && s[1] == ':') {
5497 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5498 if (!(tmp = keyword(PL_tokenbuf, len)))
5499 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5502 else if (tmp == KEY_require || tmp == KEY_do)
5503 /* that's a way to remember we saw "CORE::" */
5516 LOP(OP_ACCEPT,XTERM);
5522 LOP(OP_ATAN2,XTERM);
5528 LOP(OP_BINMODE,XTERM);
5531 LOP(OP_BLESS,XTERM);
5540 /* When 'use switch' is in effect, continue has a dual
5541 life as a control operator. */
5543 if (!FEATURE_IS_ENABLED("switch"))
5546 /* We have to disambiguate the two senses of
5547 "continue". If the next token is a '{' then
5548 treat it as the start of a continue block;
5549 otherwise treat it as a control operator.
5561 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5578 if (!PL_cryptseen) {
5579 PL_cryptseen = TRUE;
5583 LOP(OP_CRYPT,XTERM);
5586 LOP(OP_CHMOD,XTERM);
5589 LOP(OP_CHOWN,XTERM);
5592 LOP(OP_CONNECT,XTERM);
5611 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5612 if (orig_keyword == KEY_do) {
5621 PL_hints |= HINT_BLOCK_SCOPE;
5631 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5632 LOP(OP_DBMOPEN,XTERM);
5638 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5645 yylval.ival = CopLINE(PL_curcop);
5661 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5662 UNIBRACK(OP_ENTEREVAL);
5680 case KEY_endhostent:
5686 case KEY_endservent:
5689 case KEY_endprotoent:
5700 yylval.ival = CopLINE(PL_curcop);
5702 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5705 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5708 if ((PL_bufend - p) >= 3 &&
5709 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5711 else if ((PL_bufend - p) >= 4 &&
5712 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5715 if (isIDFIRST_lazy_if(p,UTF)) {
5716 p = scan_ident(p, PL_bufend,
5717 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5721 Perl_croak(aTHX_ "Missing $ on loop variable");
5723 s = SvPVX(PL_linestr) + soff;
5729 LOP(OP_FORMLINE,XTERM);
5735 LOP(OP_FCNTL,XTERM);
5741 LOP(OP_FLOCK,XTERM);
5750 LOP(OP_GREPSTART, XREF);
5753 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5768 case KEY_getpriority:
5769 LOP(OP_GETPRIORITY,XTERM);
5771 case KEY_getprotobyname:
5774 case KEY_getprotobynumber:
5775 LOP(OP_GPBYNUMBER,XTERM);
5777 case KEY_getprotoent:
5789 case KEY_getpeername:
5790 UNI(OP_GETPEERNAME);
5792 case KEY_gethostbyname:
5795 case KEY_gethostbyaddr:
5796 LOP(OP_GHBYADDR,XTERM);
5798 case KEY_gethostent:
5801 case KEY_getnetbyname:
5804 case KEY_getnetbyaddr:
5805 LOP(OP_GNBYADDR,XTERM);
5810 case KEY_getservbyname:
5811 LOP(OP_GSBYNAME,XTERM);
5813 case KEY_getservbyport:
5814 LOP(OP_GSBYPORT,XTERM);
5816 case KEY_getservent:
5819 case KEY_getsockname:
5820 UNI(OP_GETSOCKNAME);
5822 case KEY_getsockopt:
5823 LOP(OP_GSOCKOPT,XTERM);
5838 yylval.ival = CopLINE(PL_curcop);
5849 yylval.ival = CopLINE(PL_curcop);
5853 LOP(OP_INDEX,XTERM);
5859 LOP(OP_IOCTL,XTERM);
5871 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5903 LOP(OP_LISTEN,XTERM);
5912 s = scan_pat(s,OP_MATCH);
5913 TERM(sublex_start());
5916 LOP(OP_MAPSTART, XREF);
5919 LOP(OP_MKDIR,XTERM);
5922 LOP(OP_MSGCTL,XTERM);
5925 LOP(OP_MSGGET,XTERM);
5928 LOP(OP_MSGRCV,XTERM);
5931 LOP(OP_MSGSND,XTERM);
5937 if (isIDFIRST_lazy_if(s,UTF)) {
5941 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
5942 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
5944 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
5945 if (!PL_in_my_stash) {
5948 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
5952 if (PL_madskills) { /* just add type to declarator token */
5953 sv_catsv(PL_thistoken, PL_nextwhite);
5955 sv_catpvn(PL_thistoken, start, s - start);
5963 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5970 s = tokenize_use(0, s);
5974 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
5981 if (isIDFIRST_lazy_if(s,UTF)) {
5983 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
5984 for (t=d; *t && isSPACE(*t); t++) ;
5985 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
5987 && !(t[0] == '=' && t[1] == '>')
5989 int parms_len = (int)(d-s);
5990 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
5991 "Precedence problem: open %.*s should be open(%.*s)",
5992 parms_len, s, parms_len, s);
5998 yylval.ival = OP_OR;
6008 LOP(OP_OPEN_DIR,XTERM);
6011 checkcomma(s,PL_tokenbuf,"filehandle");
6015 checkcomma(s,PL_tokenbuf,"filehandle");
6034 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6038 LOP(OP_PIPE_OP,XTERM);
6041 s = scan_str(s,!!PL_madskills,FALSE);
6043 missingterm((char*)0);
6044 yylval.ival = OP_CONST;
6045 TERM(sublex_start());
6051 s = scan_str(s,!!PL_madskills,FALSE);
6053 missingterm((char*)0);
6054 PL_expect = XOPERATOR;
6056 if (SvCUR(PL_lex_stuff)) {
6059 d = SvPV_force(PL_lex_stuff, len);
6062 for (; isSPACE(*d) && len; --len, ++d) ;
6065 if (!warned && ckWARN(WARN_QW)) {
6066 for (; !isSPACE(*d) && len; --len, ++d) {
6068 Perl_warner(aTHX_ packWARN(WARN_QW),
6069 "Possible attempt to separate words with commas");
6072 else if (*d == '#') {
6073 Perl_warner(aTHX_ packWARN(WARN_QW),
6074 "Possible attempt to put comments in qw() list");
6080 for (; !isSPACE(*d) && len; --len, ++d) ;
6082 sv = newSVpvn(b, d-b);
6083 if (DO_UTF8(PL_lex_stuff))
6085 words = append_elem(OP_LIST, words,
6086 newSVOP(OP_CONST, 0, tokeq(sv)));
6090 start_force(PL_curforce);
6091 NEXTVAL_NEXTTOKE.opval = words;
6096 SvREFCNT_dec(PL_lex_stuff);
6097 PL_lex_stuff = NULL;
6103 s = scan_str(s,!!PL_madskills,FALSE);
6105 missingterm((char*)0);
6106 yylval.ival = OP_STRINGIFY;
6107 if (SvIVX(PL_lex_stuff) == '\'')
6108 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6109 TERM(sublex_start());
6112 s = scan_pat(s,OP_QR);
6113 TERM(sublex_start());
6116 s = scan_str(s,!!PL_madskills,FALSE);
6118 missingterm((char*)0);
6119 yylval.ival = OP_BACKTICK;
6121 TERM(sublex_start());
6129 s = force_version(s, FALSE);
6131 else if (*s != 'v' || !isDIGIT(s[1])
6132 || (s = force_version(s, TRUE), *s == 'v'))
6134 *PL_tokenbuf = '\0';
6135 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6136 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6137 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
6139 yyerror("<> should be quotes");
6141 if (orig_keyword == KEY_require) {
6149 PL_last_uni = PL_oldbufptr;
6150 PL_last_lop_op = OP_REQUIRE;
6152 return REPORT( (int)REQUIRE );
6158 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6162 LOP(OP_RENAME,XTERM);
6171 LOP(OP_RINDEX,XTERM);
6181 UNIDOR(OP_READLINE);
6194 LOP(OP_REVERSE,XTERM);
6197 UNIDOR(OP_READLINK);
6205 TERM(sublex_start());
6207 TOKEN(1); /* force error */
6210 checkcomma(s,PL_tokenbuf,"filehandle");
6220 LOP(OP_SELECT,XTERM);
6226 LOP(OP_SEMCTL,XTERM);
6229 LOP(OP_SEMGET,XTERM);
6232 LOP(OP_SEMOP,XTERM);
6238 LOP(OP_SETPGRP,XTERM);
6240 case KEY_setpriority:
6241 LOP(OP_SETPRIORITY,XTERM);
6243 case KEY_sethostent:
6249 case KEY_setservent:
6252 case KEY_setprotoent:
6262 LOP(OP_SEEKDIR,XTERM);
6264 case KEY_setsockopt:
6265 LOP(OP_SSOCKOPT,XTERM);
6271 LOP(OP_SHMCTL,XTERM);
6274 LOP(OP_SHMGET,XTERM);
6277 LOP(OP_SHMREAD,XTERM);
6280 LOP(OP_SHMWRITE,XTERM);
6283 LOP(OP_SHUTDOWN,XTERM);
6292 LOP(OP_SOCKET,XTERM);
6294 case KEY_socketpair:
6295 LOP(OP_SOCKPAIR,XTERM);
6298 checkcomma(s,PL_tokenbuf,"subroutine name");
6300 if (*s == ';' || *s == ')') /* probably a close */
6301 Perl_croak(aTHX_ "sort is now a reserved word");
6303 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6307 LOP(OP_SPLIT,XTERM);
6310 LOP(OP_SPRINTF,XTERM);
6313 LOP(OP_SPLICE,XTERM);
6328 LOP(OP_SUBSTR,XTERM);
6334 char tmpbuf[sizeof PL_tokenbuf];
6335 SSize_t tboffset = 0;
6336 expectation attrful;
6337 bool have_name, have_proto, bad_proto;
6338 const int key = tmp;
6343 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6344 SV *subtoken = newSVpvn(tstart, s - tstart);
6348 s = SKIPSPACE2(s,tmpwhite);
6353 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6354 (*s == ':' && s[1] == ':'))
6361 attrful = XATTRBLOCK;
6362 /* remember buffer pos'n for later force_word */
6363 tboffset = s - PL_oldbufptr;
6364 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6367 nametoke = newSVpvn(s, d - s);
6369 if (strchr(tmpbuf, ':'))
6370 sv_setpv(PL_subname, tmpbuf);
6372 sv_setsv(PL_subname,PL_curstname);
6373 sv_catpvs(PL_subname,"::");
6374 sv_catpvn(PL_subname,tmpbuf,len);
6381 CURMAD('X', nametoke);
6382 CURMAD('_', tmpwhite);
6383 (void) force_word(PL_oldbufptr + tboffset, WORD,
6386 s = SKIPSPACE2(d,tmpwhite);
6393 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6394 PL_expect = XTERMBLOCK;
6395 attrful = XATTRTERM;
6396 sv_setpvn(PL_subname,"?",1);
6400 if (key == KEY_format) {
6402 PL_lex_formbrack = PL_lex_brackets + 1;
6404 PL_thistoken = subtoken;
6408 (void) force_word(PL_oldbufptr + tboffset, WORD,
6414 /* Look for a prototype */
6418 s = scan_str(s,!!PL_madskills,FALSE);
6420 Perl_croak(aTHX_ "Prototype not terminated");
6421 /* strip spaces and check for bad characters */
6422 d = SvPVX(PL_lex_stuff);
6425 for (p = d; *p; ++p) {
6428 if (!strchr("$@%*;[]&\\", *p))
6433 if (bad_proto && ckWARN(WARN_SYNTAX))
6434 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6435 "Illegal character in prototype for %"SVf" : %s",
6437 SvCUR_set(PL_lex_stuff, tmp);
6442 CURMAD('q', PL_thisopen);
6443 CURMAD('_', tmpwhite);
6444 CURMAD('=', PL_thisstuff);
6445 CURMAD('Q', PL_thisclose);
6446 NEXTVAL_NEXTTOKE.opval =
6447 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6448 PL_lex_stuff = Nullsv;
6451 s = SKIPSPACE2(s,tmpwhite);
6459 if (*s == ':' && s[1] != ':')
6460 PL_expect = attrful;
6461 else if (*s != '{' && key == KEY_sub) {
6463 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6465 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname);
6472 curmad('^', newSVpvn("",0));
6473 CURMAD('_', tmpwhite);
6477 PL_thistoken = subtoken;
6480 NEXTVAL_NEXTTOKE.opval =
6481 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6482 PL_lex_stuff = NULL;
6487 sv_setpv(PL_subname,
6488 PL_curstash ? "__ANON__" : "__ANON__::__ANON__");
6492 (void) force_word(PL_oldbufptr + tboffset, WORD,
6502 LOP(OP_SYSTEM,XREF);
6505 LOP(OP_SYMLINK,XTERM);
6508 LOP(OP_SYSCALL,XTERM);
6511 LOP(OP_SYSOPEN,XTERM);
6514 LOP(OP_SYSSEEK,XTERM);
6517 LOP(OP_SYSREAD,XTERM);
6520 LOP(OP_SYSWRITE,XTERM);
6524 TERM(sublex_start());
6545 LOP(OP_TRUNCATE,XTERM);
6557 yylval.ival = CopLINE(PL_curcop);
6561 yylval.ival = CopLINE(PL_curcop);
6565 LOP(OP_UNLINK,XTERM);
6571 LOP(OP_UNPACK,XTERM);
6574 LOP(OP_UTIME,XTERM);
6580 LOP(OP_UNSHIFT,XTERM);
6583 s = tokenize_use(1, s);
6593 yylval.ival = CopLINE(PL_curcop);
6597 yylval.ival = CopLINE(PL_curcop);
6601 PL_hints |= HINT_BLOCK_SCOPE;
6608 LOP(OP_WAITPID,XTERM);
6617 ctl_l[0] = toCTRL('L');
6619 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6622 /* Make sure $^L is defined */
6623 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6628 if (PL_expect == XOPERATOR)
6634 yylval.ival = OP_XOR;
6639 TERM(sublex_start());
6644 #pragma segment Main
6648 S_pending_ident(pTHX)
6652 register I32 tmp = 0;
6653 /* pit holds the identifier we read and pending_ident is reset */
6654 char pit = PL_pending_ident;
6655 PL_pending_ident = 0;
6657 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6658 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6659 "### Pending identifier '%s'\n", PL_tokenbuf); });
6661 /* if we're in a my(), we can't allow dynamics here.
6662 $foo'bar has already been turned into $foo::bar, so
6663 just check for colons.
6665 if it's a legal name, the OP is a PADANY.
6668 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6669 if (strchr(PL_tokenbuf,':'))
6670 yyerror(Perl_form(aTHX_ "No package name allowed for "
6671 "variable %s in \"our\"",
6673 tmp = allocmy(PL_tokenbuf);
6676 if (strchr(PL_tokenbuf,':'))
6677 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
6679 yylval.opval = newOP(OP_PADANY, 0);
6680 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6686 build the ops for accesses to a my() variable.
6688 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6689 then used in a comparison. This catches most, but not
6690 all cases. For instance, it catches
6691 sort { my($a); $a <=> $b }
6693 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6694 (although why you'd do that is anyone's guess).
6697 if (!strchr(PL_tokenbuf,':')) {
6699 tmp = pad_findmy(PL_tokenbuf);
6700 if (tmp != NOT_IN_PAD) {
6701 /* might be an "our" variable" */
6702 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6703 /* build ops for a bareword */
6704 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6705 HEK * const stashname = HvNAME_HEK(stash);
6706 SV * const sym = newSVhek(stashname);
6707 sv_catpvs(sym, "::");
6708 sv_catpv(sym, PL_tokenbuf+1);
6709 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6710 yylval.opval->op_private = OPpCONST_ENTERED;
6713 ? (GV_ADDMULTI | GV_ADDINEVAL)
6716 ((PL_tokenbuf[0] == '$') ? SVt_PV
6717 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6722 /* if it's a sort block and they're naming $a or $b */
6723 if (PL_last_lop_op == OP_SORT &&
6724 PL_tokenbuf[0] == '$' &&
6725 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6728 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6729 d < PL_bufend && *d != '\n';
6732 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6733 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6739 yylval.opval = newOP(OP_PADANY, 0);
6740 yylval.opval->op_targ = tmp;
6746 Whine if they've said @foo in a doublequoted string,
6747 and @foo isn't a variable we can find in the symbol
6750 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
6751 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
6752 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
6753 && ckWARN(WARN_AMBIGUOUS))
6755 /* Downgraded from fatal to warning 20000522 mjd */
6756 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6757 "Possible unintended interpolation of %s in string",
6762 /* build ops for a bareword */
6763 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
6764 yylval.opval->op_private = OPpCONST_ENTERED;
6767 /* If the identifier refers to a stash, don't autovivify it.
6768 * Change 24660 had the side effect of causing symbol table
6769 * hashes to always be defined, even if they were freshly
6770 * created and the only reference in the entire program was
6771 * the single statement with the defined %foo::bar:: test.
6772 * It appears that all code in the wild doing this actually
6773 * wants to know whether sub-packages have been loaded, so
6774 * by avoiding auto-vivifying symbol tables, we ensure that
6775 * defined %foo::bar:: continues to be false, and the existing
6776 * tests still give the expected answers, even though what
6777 * they're actually testing has now changed subtly.
6779 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
6781 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
6782 ((PL_tokenbuf[0] == '$') ? SVt_PV
6783 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6789 * The following code was generated by perl_keyword.pl.
6793 Perl_keyword (pTHX_ const char *name, I32 len)
6798 case 1: /* 5 tokens of length 1 */
6830 case 2: /* 18 tokens of length 2 */
6976 case 3: /* 29 tokens of length 3 */
6980 if (name[1] == 'N' &&
7043 if (name[1] == 'i' &&
7065 return (FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7083 if (name[1] == 'o' &&
7092 if (name[1] == 'e' &&
7101 if (name[1] == 'n' &&
7110 if (name[1] == 'o' &&
7119 if (name[1] == 'a' &&
7128 if (name[1] == 'o' &&
7190 if (name[1] == 'e' &&
7204 return (FEATURE_IS_ENABLED("say") ? -KEY_say : 0);
7230 if (name[1] == 'i' &&
7239 if (name[1] == 's' &&
7248 if (name[1] == 'e' &&
7257 if (name[1] == 'o' &&
7269 case 4: /* 41 tokens of length 4 */
7273 if (name[1] == 'O' &&
7283 if (name[1] == 'N' &&
7293 if (name[1] == 'i' &&
7303 if (name[1] == 'h' &&
7313 if (name[1] == 'u' &&
7326 if (name[2] == 'c' &&
7335 if (name[2] == 's' &&
7344 if (name[2] == 'a' &&
7380 if (name[1] == 'o' &&
7393 if (name[2] == 't' &&
7402 if (name[2] == 'o' &&
7411 if (name[2] == 't' &&
7420 if (name[2] == 'e' &&
7433 if (name[1] == 'o' &&
7446 if (name[2] == 'y' &&
7455 if (name[2] == 'l' &&
7471 if (name[2] == 's' &&
7480 if (name[2] == 'n' &&
7489 if (name[2] == 'c' &&
7502 if (name[1] == 'e' &&
7512 if (name[1] == 'p' &&
7525 if (name[2] == 'c' &&
7534 if (name[2] == 'p' &&
7543 if (name[2] == 's' &&
7559 if (name[2] == 'n' &&
7629 if (name[2] == 'r' &&
7638 if (name[2] == 'r' &&
7647 if (name[2] == 'a' &&
7663 if (name[2] == 'l' &&
7725 if (name[2] == 'e' &&
7728 return (FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
7741 case 5: /* 38 tokens of length 5 */
7745 if (name[1] == 'E' &&
7756 if (name[1] == 'H' &&
7770 if (name[2] == 'a' &&
7780 if (name[2] == 'a' &&
7797 if (name[2] == 'e' &&
7807 if (name[2] == 'e' &&
7811 return (FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
7827 if (name[3] == 'i' &&
7836 if (name[3] == 'o' &&
7872 if (name[2] == 'o' &&
7882 if (name[2] == 'y' &&
7896 if (name[1] == 'l' &&
7910 if (name[2] == 'n' &&
7920 if (name[2] == 'o' &&
7934 if (name[1] == 'i' &&
7939 return (FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
7948 if (name[2] == 'd' &&
7958 if (name[2] == 'c' &&
7975 if (name[2] == 'c' &&
7985 if (name[2] == 't' &&
7999 if (name[1] == 'k' &&
8010 if (name[1] == 'r' &&
8024 if (name[2] == 's' &&
8034 if (name[2] == 'd' &&
8051 if (name[2] == 'm' &&
8061 if (name[2] == 'i' &&
8071 if (name[2] == 'e' &&
8081 if (name[2] == 'l' &&
8091 if (name[2] == 'a' &&
8101 if (name[2] == 'u' &&
8115 if (name[1] == 'i' &&
8129 if (name[2] == 'a' &&
8142 if (name[3] == 'e' &&
8177 if (name[2] == 'i' &&
8194 if (name[2] == 'i' &&
8204 if (name[2] == 'i' &&
8221 case 6: /* 33 tokens of length 6 */
8225 if (name[1] == 'c' &&
8240 if (name[2] == 'l' &&
8251 if (name[2] == 'r' &&
8266 if (name[1] == 'e' &&
8281 if (name[2] == 's' &&
8286 if(ckWARN_d(WARN_SYNTAX))
8287 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8293 if (name[2] == 'i' &&
8311 if (name[2] == 'l' &&
8322 if (name[2] == 'r' &&
8337 if (name[1] == 'm' &&
8352 if (name[2] == 'n' &&
8363 if (name[2] == 's' &&
8378 if (name[1] == 's' &&
8384 if (name[4] == 't' &&
8393 if (name[4] == 'e' &&
8402 if (name[4] == 'c' &&
8411 if (name[4] == 'n' &&
8427 if (name[1] == 'r' &&
8445 if (name[3] == 'a' &&
8455 if (name[3] == 'u' &&
8469 if (name[2] == 'n' &&
8487 if (name[2] == 'a' &&
8501 if (name[3] == 'e' &&
8514 if (name[4] == 't' &&
8523 if (name[4] == 'e' &&
8545 if (name[4] == 't' &&
8554 if (name[4] == 'e' &&
8570 if (name[2] == 'c' &&
8581 if (name[2] == 'l' &&
8592 if (name[2] == 'b' &&
8603 if (name[2] == 's' &&
8626 if (name[4] == 's' &&
8635 if (name[4] == 'n' &&
8648 if (name[3] == 'a' &&
8665 if (name[1] == 'a' &&
8680 case 7: /* 29 tokens of length 7 */
8684 if (name[1] == 'E' &&
8697 if (name[1] == '_' &&
8710 if (name[1] == 'i' &&
8717 return -KEY_binmode;
8723 if (name[1] == 'o' &&
8730 return -KEY_connect;
8739 if (name[2] == 'm' &&
8745 return -KEY_dbmopen;
8756 if (name[4] == 'u' &&
8760 return (FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
8766 if (name[4] == 'n' &&
8787 if (name[1] == 'o' &&
8800 if (name[1] == 'e' &&
8807 if (name[5] == 'r' &&
8810 return -KEY_getpgrp;
8816 if (name[5] == 'i' &&
8819 return -KEY_getppid;
8832 if (name[1] == 'c' &&
8839 return -KEY_lcfirst;
8845 if (name[1] == 'p' &&
8852 return -KEY_opendir;
8858 if (name[1] == 'a' &&
8876 if (name[3] == 'd' &&
8881 return -KEY_readdir;
8887 if (name[3] == 'u' &&
8898 if (name[3] == 'e' &&
8903 return -KEY_reverse;
8922 if (name[3] == 'k' &&
8927 return -KEY_seekdir;
8933 if (name[3] == 'p' &&
8938 return -KEY_setpgrp;
8948 if (name[2] == 'm' &&
8954 return -KEY_shmread;
8960 if (name[2] == 'r' &&
8966 return -KEY_sprintf;
8975 if (name[3] == 'l' &&
8980 return -KEY_symlink;
8989 if (name[4] == 'a' &&
8993 return -KEY_syscall;
8999 if (name[4] == 'p' &&
9003 return -KEY_sysopen;
9009 if (name[4] == 'e' &&
9013 return -KEY_sysread;
9019 if (name[4] == 'e' &&
9023 return -KEY_sysseek;
9041 if (name[1] == 'e' &&
9048 return -KEY_telldir;
9057 if (name[2] == 'f' &&
9063 return -KEY_ucfirst;
9069 if (name[2] == 's' &&
9075 return -KEY_unshift;
9085 if (name[1] == 'a' &&
9092 return -KEY_waitpid;
9101 case 8: /* 26 tokens of length 8 */
9105 if (name[1] == 'U' &&
9113 return KEY_AUTOLOAD;
9124 if (name[3] == 'A' &&
9130 return KEY___DATA__;
9136 if (name[3] == 'I' &&
9142 return -KEY___FILE__;
9148 if (name[3] == 'I' &&
9154 return -KEY___LINE__;
9170 if (name[2] == 'o' &&
9177 return -KEY_closedir;
9183 if (name[2] == 'n' &&
9190 return -KEY_continue;
9200 if (name[1] == 'b' &&
9208 return -KEY_dbmclose;
9214 if (name[1] == 'n' &&
9220 if (name[4] == 'r' &&
9225 return -KEY_endgrent;
9231 if (name[4] == 'w' &&
9236 return -KEY_endpwent;
9249 if (name[1] == 'o' &&
9257 return -KEY_formline;
9263 if (name[1] == 'e' &&
9274 if (name[6] == 'n' &&
9277 return -KEY_getgrent;
9283 if (name[6] == 'i' &&
9286 return -KEY_getgrgid;
9292 if (name[6] == 'a' &&
9295 return -KEY_getgrnam;
9308 if (name[4] == 'o' &&
9313 return -KEY_getlogin;
9324 if (name[6] == 'n' &&
9327 return -KEY_getpwent;
9333 if (name[6] == 'a' &&
9336 return -KEY_getpwnam;
9342 if (name[6] == 'i' &&
9345 return -KEY_getpwuid;
9365 if (name[1] == 'e' &&
9372 if (name[5] == 'i' &&
9379 return -KEY_readline;
9384 return -KEY_readlink;
9395 if (name[5] == 'i' &&
9399 return -KEY_readpipe;
9420 if (name[4] == 'r' &&
9425 return -KEY_setgrent;
9431 if (name[4] == 'w' &&
9436 return -KEY_setpwent;
9452 if (name[3] == 'w' &&
9458 return -KEY_shmwrite;
9464 if (name[3] == 't' &&
9470 return -KEY_shutdown;
9480 if (name[2] == 's' &&
9487 return -KEY_syswrite;
9497 if (name[1] == 'r' &&
9505 return -KEY_truncate;
9514 case 9: /* 8 tokens of length 9 */
9518 if (name[1] == 'n' &&
9527 return -KEY_endnetent;
9533 if (name[1] == 'e' &&
9542 return -KEY_getnetent;
9548 if (name[1] == 'o' &&
9557 return -KEY_localtime;
9563 if (name[1] == 'r' &&
9572 return KEY_prototype;
9578 if (name[1] == 'u' &&
9587 return -KEY_quotemeta;
9593 if (name[1] == 'e' &&
9602 return -KEY_rewinddir;
9608 if (name[1] == 'e' &&
9617 return -KEY_setnetent;
9623 if (name[1] == 'a' &&
9632 return -KEY_wantarray;
9641 case 10: /* 9 tokens of length 10 */
9645 if (name[1] == 'n' &&
9651 if (name[4] == 'o' &&
9658 return -KEY_endhostent;
9664 if (name[4] == 'e' &&
9671 return -KEY_endservent;
9684 if (name[1] == 'e' &&
9690 if (name[4] == 'o' &&
9697 return -KEY_gethostent;
9706 if (name[5] == 'r' &&
9712 return -KEY_getservent;
9718 if (name[5] == 'c' &&
9724 return -KEY_getsockopt;
9749 if (name[4] == 'o' &&
9756 return -KEY_sethostent;
9765 if (name[5] == 'r' &&
9771 return -KEY_setservent;
9777 if (name[5] == 'c' &&
9783 return -KEY_setsockopt;
9800 if (name[2] == 'c' &&
9809 return -KEY_socketpair;
9822 case 11: /* 8 tokens of length 11 */
9826 if (name[1] == '_' &&
9837 return -KEY___PACKAGE__;
9843 if (name[1] == 'n' &&
9854 return -KEY_endprotoent;
9860 if (name[1] == 'e' &&
9869 if (name[5] == 'e' &&
9876 return -KEY_getpeername;
9885 if (name[6] == 'o' &&
9891 return -KEY_getpriority;
9897 if (name[6] == 't' &&
9903 return -KEY_getprotoent;
9917 if (name[4] == 'o' &&
9925 return -KEY_getsockname;
9938 if (name[1] == 'e' &&
9946 if (name[6] == 'o' &&
9952 return -KEY_setpriority;
9958 if (name[6] == 't' &&
9964 return -KEY_setprotoent;
9980 case 12: /* 2 tokens of length 12 */
9981 if (name[0] == 'g' &&
9993 if (name[9] == 'd' &&
9996 { /* getnetbyaddr */
9997 return -KEY_getnetbyaddr;
10003 if (name[9] == 'a' &&
10006 { /* getnetbyname */
10007 return -KEY_getnetbyname;
10019 case 13: /* 4 tokens of length 13 */
10020 if (name[0] == 'g' &&
10027 if (name[4] == 'o' &&
10036 if (name[10] == 'd' &&
10039 { /* gethostbyaddr */
10040 return -KEY_gethostbyaddr;
10046 if (name[10] == 'a' &&
10049 { /* gethostbyname */
10050 return -KEY_gethostbyname;
10063 if (name[4] == 'e' &&
10072 if (name[10] == 'a' &&
10075 { /* getservbyname */
10076 return -KEY_getservbyname;
10082 if (name[10] == 'o' &&
10085 { /* getservbyport */
10086 return -KEY_getservbyport;
10105 case 14: /* 1 tokens of length 14 */
10106 if (name[0] == 'g' &&
10120 { /* getprotobyname */
10121 return -KEY_getprotobyname;
10126 case 16: /* 1 tokens of length 16 */
10127 if (name[0] == 'g' &&
10143 { /* getprotobynumber */
10144 return -KEY_getprotobynumber;
10158 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10162 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10163 if (ckWARN(WARN_SYNTAX)) {
10166 for (w = s+2; *w && level; w++) {
10169 else if (*w == ')')
10172 while (isSPACE(*w))
10174 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
10175 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10176 "%s (...) interpreted as function",name);
10179 while (s < PL_bufend && isSPACE(*s))
10183 while (s < PL_bufend && isSPACE(*s))
10185 if (isIDFIRST_lazy_if(s,UTF)) {
10186 const char * const w = s++;
10187 while (isALNUM_lazy_if(s,UTF))
10189 while (s < PL_bufend && isSPACE(*s))
10193 if (keyword(w, s - w))
10196 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10197 if (gv && GvCVu(gv))
10199 Perl_croak(aTHX_ "No comma allowed after %s", what);
10204 /* Either returns sv, or mortalizes sv and returns a new SV*.
10205 Best used as sv=new_constant(..., sv, ...).
10206 If s, pv are NULL, calls subroutine with one argument,
10207 and type is used with error messages only. */
10210 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10214 HV * const table = GvHV(PL_hintgv); /* ^H */
10218 const char *why1 = "", *why2 = "", *why3 = "";
10220 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10223 why2 = strEQ(key,"charnames")
10224 ? "(possibly a missing \"use charnames ...\")"
10226 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10227 (type ? type: "undef"), why2);
10229 /* This is convoluted and evil ("goto considered harmful")
10230 * but I do not understand the intricacies of all the different
10231 * failure modes of %^H in here. The goal here is to make
10232 * the most probable error message user-friendly. --jhi */
10237 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10238 (type ? type: "undef"), why1, why2, why3);
10240 yyerror(SvPVX_const(msg));
10244 cvp = hv_fetch(table, key, strlen(key), FALSE);
10245 if (!cvp || !SvOK(*cvp)) {
10248 why3 = "} is not defined";
10251 sv_2mortal(sv); /* Parent created it permanently */
10254 pv = sv_2mortal(newSVpvn(s, len));
10256 typesv = sv_2mortal(newSVpv(type, 0));
10258 typesv = &PL_sv_undef;
10260 PUSHSTACKi(PERLSI_OVERLOAD);
10272 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10276 /* Check the eval first */
10277 if (!PL_in_eval && SvTRUE(ERRSV)) {
10278 sv_catpvs(ERRSV, "Propagated");
10279 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10281 res = SvREFCNT_inc_simple(sv);
10285 SvREFCNT_inc_simple_void(res);
10294 why1 = "Call to &{$^H{";
10296 why3 = "}} did not return a defined value";
10304 /* Returns a NUL terminated string, with the length of the string written to
10308 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10311 register char *d = dest;
10312 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10315 Perl_croak(aTHX_ ident_too_long);
10316 if (isALNUM(*s)) /* UTF handled below */
10318 else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
10323 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
10327 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10328 char *t = s + UTF8SKIP(s);
10329 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10331 if (d + (t - s) > e)
10332 Perl_croak(aTHX_ ident_too_long);
10333 Copy(s, d, t - s, char);
10346 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10349 char *bracket = NULL;
10351 register char *d = dest;
10352 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10357 while (isDIGIT(*s)) {
10359 Perl_croak(aTHX_ ident_too_long);
10366 Perl_croak(aTHX_ ident_too_long);
10367 if (isALNUM(*s)) /* UTF handled below */
10369 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10374 else if (*s == ':' && s[1] == ':') {
10378 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10379 char *t = s + UTF8SKIP(s);
10380 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10382 if (d + (t - s) > e)
10383 Perl_croak(aTHX_ ident_too_long);
10384 Copy(s, d, t - s, char);
10395 if (PL_lex_state != LEX_NORMAL)
10396 PL_lex_state = LEX_INTERPENDMAYBE;
10399 if (*s == '$' && s[1] &&
10400 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10413 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10418 if (isSPACE(s[-1])) {
10420 const char ch = *s++;
10421 if (!SPACE_OR_TAB(ch)) {
10427 if (isIDFIRST_lazy_if(d,UTF)) {
10431 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10432 end += UTF8SKIP(end);
10433 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10434 end += UTF8SKIP(end);
10436 Copy(s, d, end - s, char);
10441 while ((isALNUM(*s) || *s == ':') && d < e)
10444 Perl_croak(aTHX_ ident_too_long);
10447 while (s < send && SPACE_OR_TAB(*s)) s++;
10448 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10449 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
10450 const char *brack = *s == '[' ? "[...]" : "{...}";
10451 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10452 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10453 funny, dest, brack, funny, dest, brack);
10456 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10460 /* Handle extended ${^Foo} variables
10461 * 1999-02-27 mjd-perl-patch@plover.com */
10462 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10466 while (isALNUM(*s) && d < e) {
10470 Perl_croak(aTHX_ ident_too_long);
10475 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10476 PL_lex_state = LEX_INTERPEND;
10481 if (PL_lex_state == LEX_NORMAL) {
10482 if (ckWARN(WARN_AMBIGUOUS) &&
10483 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
10485 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10486 "Ambiguous use of %c{%s} resolved to %c%s",
10487 funny, dest, funny, dest);
10492 s = bracket; /* let the parser handle it */
10496 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10497 PL_lex_state = LEX_INTERPEND;
10502 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10504 PERL_UNUSED_CONTEXT;
10507 else if (ch == 'g')
10508 *pmfl |= PMf_GLOBAL;
10509 else if (ch == 'c')
10510 *pmfl |= PMf_CONTINUE;
10511 else if (ch == 'o')
10513 else if (ch == 'm')
10514 *pmfl |= PMf_MULTILINE;
10515 else if (ch == 's')
10516 *pmfl |= PMf_SINGLELINE;
10517 else if (ch == 'x')
10518 *pmfl |= PMf_EXTENDED;
10522 S_scan_pat(pTHX_ char *start, I32 type)
10526 char *s = scan_str(start,!!PL_madskills,FALSE);
10527 const char * const valid_flags = (type == OP_QR) ? "iomsx" : "iogcmsx";
10534 const char * const delimiter = skipspace(start);
10535 Perl_croak(aTHX_ *delimiter == '?'
10536 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10537 : "Search pattern not terminated" );
10540 pm = (PMOP*)newPMOP(type, 0);
10541 if (PL_multi_open == '?')
10542 pm->op_pmflags |= PMf_ONCE;
10546 while (*s && strchr(valid_flags, *s))
10547 pmflag(&pm->op_pmflags,*s++);
10549 if (PL_madskills && modstart != s) {
10550 SV* tmptoken = newSVpvn(modstart, s - modstart);
10551 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10554 /* issue a warning if /c is specified,but /g is not */
10555 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10556 && ckWARN(WARN_REGEXP))
10558 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" );
10561 pm->op_pmpermflags = pm->op_pmflags;
10563 PL_lex_op = (OP*)pm;
10564 yylval.ival = OP_MATCH;
10569 S_scan_subst(pTHX_ char *start)
10580 yylval.ival = OP_NULL;
10582 s = scan_str(start,!!PL_madskills,FALSE);
10585 Perl_croak(aTHX_ "Substitution pattern not terminated");
10587 if (s[-1] == PL_multi_open)
10590 if (PL_madskills) {
10591 CURMAD('q', PL_thisopen);
10592 CURMAD('_', PL_thiswhite);
10593 CURMAD('E', PL_thisstuff);
10594 CURMAD('Q', PL_thisclose);
10595 PL_realtokenstart = s - SvPVX(PL_linestr);
10599 first_start = PL_multi_start;
10600 s = scan_str(s,!!PL_madskills,FALSE);
10602 if (PL_lex_stuff) {
10603 SvREFCNT_dec(PL_lex_stuff);
10604 PL_lex_stuff = NULL;
10606 Perl_croak(aTHX_ "Substitution replacement not terminated");
10608 PL_multi_start = first_start; /* so whole substitution is taken together */
10610 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10613 if (PL_madskills) {
10614 CURMAD('z', PL_thisopen);
10615 CURMAD('R', PL_thisstuff);
10616 CURMAD('Z', PL_thisclose);
10626 else if (strchr("iogcmsx", *s))
10627 pmflag(&pm->op_pmflags,*s++);
10633 if (PL_madskills) {
10635 curmad('m', newSVpvn(modstart, s - modstart));
10636 append_madprops(PL_thismad, (OP*)pm, 0);
10640 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10641 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10645 SV * const repl = newSVpvs("");
10647 PL_sublex_info.super_bufptr = s;
10648 PL_sublex_info.super_bufend = PL_bufend;
10650 pm->op_pmflags |= PMf_EVAL;
10652 sv_catpv(repl, es ? "eval " : "do ");
10653 sv_catpvs(repl, "{");
10654 sv_catsv(repl, PL_lex_repl);
10655 sv_catpvs(repl, "}");
10657 SvREFCNT_dec(PL_lex_repl);
10658 PL_lex_repl = repl;
10661 pm->op_pmpermflags = pm->op_pmflags;
10662 PL_lex_op = (OP*)pm;
10663 yylval.ival = OP_SUBST;
10668 S_scan_trans(pTHX_ char *start)
10681 yylval.ival = OP_NULL;
10683 s = scan_str(start,!!PL_madskills,FALSE);
10685 Perl_croak(aTHX_ "Transliteration pattern not terminated");
10687 if (s[-1] == PL_multi_open)
10690 if (PL_madskills) {
10691 CURMAD('q', PL_thisopen);
10692 CURMAD('_', PL_thiswhite);
10693 CURMAD('E', PL_thisstuff);
10694 CURMAD('Q', PL_thisclose);
10695 PL_realtokenstart = s - SvPVX(PL_linestr);
10699 s = scan_str(s,!!PL_madskills,FALSE);
10701 if (PL_lex_stuff) {
10702 SvREFCNT_dec(PL_lex_stuff);
10703 PL_lex_stuff = NULL;
10705 Perl_croak(aTHX_ "Transliteration replacement not terminated");
10707 if (PL_madskills) {
10708 CURMAD('z', PL_thisopen);
10709 CURMAD('R', PL_thisstuff);
10710 CURMAD('Z', PL_thisclose);
10713 complement = del = squash = 0;
10720 complement = OPpTRANS_COMPLEMENT;
10723 del = OPpTRANS_DELETE;
10726 squash = OPpTRANS_SQUASH;
10735 Newx(tbl, complement&&!del?258:256, short);
10736 o = newPVOP(OP_TRANS, 0, (char*)tbl);
10737 o->op_private &= ~OPpTRANS_ALL;
10738 o->op_private |= del|squash|complement|
10739 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
10740 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
10743 yylval.ival = OP_TRANS;
10746 if (PL_madskills) {
10748 curmad('m', newSVpvn(modstart, s - modstart));
10749 append_madprops(PL_thismad, o, 0);
10758 S_scan_heredoc(pTHX_ register char *s)
10762 I32 op_type = OP_SCALAR;
10766 const char *found_newline;
10770 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
10772 I32 stuffstart = s - SvPVX(PL_linestr);
10775 PL_realtokenstart = -1;
10780 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
10783 for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
10784 if (*peek == '`' || *peek == '\'' || *peek =='"') {
10787 s = delimcpy(d, e, s, PL_bufend, term, &len);
10797 if (!isALNUM_lazy_if(s,UTF))
10798 deprecate_old("bare << to mean <<\"\"");
10799 for (; isALNUM_lazy_if(s,UTF); s++) {
10804 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
10805 Perl_croak(aTHX_ "Delimiter for here document is too long");
10808 len = d - PL_tokenbuf;
10811 if (PL_madskills) {
10812 tstart = PL_tokenbuf + !outer;
10813 PL_thisclose = newSVpvn(tstart, len - !outer);
10814 tstart = SvPVX(PL_linestr) + stuffstart;
10815 PL_thisopen = newSVpvn(tstart, s - tstart);
10816 stuffstart = s - SvPVX(PL_linestr);
10819 #ifndef PERL_STRICT_CR
10820 d = strchr(s, '\r');
10822 char * const olds = s;
10824 while (s < PL_bufend) {
10830 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
10839 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
10846 if ( outer || !(found_newline = memchr(s, '\n', PL_bufend - s)) ) {
10847 herewas = newSVpvn(s,PL_bufend-s);
10851 herewas = newSVpvn(s-1,found_newline-s+1);
10854 herewas = newSVpvn(s,found_newline-s);
10858 if (PL_madskills) {
10859 tstart = SvPVX(PL_linestr) + stuffstart;
10861 sv_catpvn(PL_thisstuff, tstart, s - tstart);
10863 PL_thisstuff = newSVpvn(tstart, s - tstart);
10866 s += SvCUR(herewas);
10869 stuffstart = s - SvPVX(PL_linestr);
10875 tmpstr = newSV(79);
10876 sv_upgrade(tmpstr, SVt_PVIV);
10877 if (term == '\'') {
10878 op_type = OP_CONST;
10879 SvIV_set(tmpstr, -1);
10881 else if (term == '`') {
10882 op_type = OP_BACKTICK;
10883 SvIV_set(tmpstr, '\\');
10887 PL_multi_start = CopLINE(PL_curcop);
10888 PL_multi_open = PL_multi_close = '<';
10889 term = *PL_tokenbuf;
10890 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
10891 char * const bufptr = PL_sublex_info.super_bufptr;
10892 char * const bufend = PL_sublex_info.super_bufend;
10893 char * const olds = s - SvCUR(herewas);
10894 s = strchr(bufptr, '\n');
10898 while (s < bufend &&
10899 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
10901 CopLINE_inc(PL_curcop);
10904 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10905 missingterm(PL_tokenbuf);
10907 sv_setpvn(herewas,bufptr,d-bufptr+1);
10908 sv_setpvn(tmpstr,d+1,s-d);
10910 sv_catpvn(herewas,s,bufend-s);
10911 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
10918 while (s < PL_bufend &&
10919 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
10921 CopLINE_inc(PL_curcop);
10923 if (s >= PL_bufend) {
10924 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10925 missingterm(PL_tokenbuf);
10927 sv_setpvn(tmpstr,d+1,s-d);
10929 if (PL_madskills) {
10931 sv_catpvn(PL_thisstuff, d + 1, s - d);
10933 PL_thisstuff = newSVpvn(d + 1, s - d);
10934 stuffstart = s - SvPVX(PL_linestr);
10938 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
10940 sv_catpvn(herewas,s,PL_bufend-s);
10941 sv_setsv(PL_linestr,herewas);
10942 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
10943 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10944 PL_last_lop = PL_last_uni = NULL;
10947 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
10948 while (s >= PL_bufend) { /* multiple line string? */
10950 if (PL_madskills) {
10951 tstart = SvPVX(PL_linestr) + stuffstart;
10953 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
10955 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
10959 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
10960 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10961 missingterm(PL_tokenbuf);
10964 stuffstart = s - SvPVX(PL_linestr);
10966 CopLINE_inc(PL_curcop);
10967 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10968 PL_last_lop = PL_last_uni = NULL;
10969 #ifndef PERL_STRICT_CR
10970 if (PL_bufend - PL_linestart >= 2) {
10971 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
10972 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
10974 PL_bufend[-2] = '\n';
10976 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
10978 else if (PL_bufend[-1] == '\r')
10979 PL_bufend[-1] = '\n';
10981 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
10982 PL_bufend[-1] = '\n';
10984 if (PERLDB_LINE && PL_curstash != PL_debstash) {
10985 SV * const sv = newSV(0);
10987 sv_upgrade(sv, SVt_PVMG);
10988 sv_setsv(sv,PL_linestr);
10989 (void)SvIOK_on(sv);
10991 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop),sv);
10993 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
10994 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
10995 *(SvPVX(PL_linestr) + off ) = ' ';
10996 sv_catsv(PL_linestr,herewas);
10997 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10998 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11002 sv_catsv(tmpstr,PL_linestr);
11007 PL_multi_end = CopLINE(PL_curcop);
11008 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11009 SvPV_shrink_to_cur(tmpstr);
11011 SvREFCNT_dec(herewas);
11013 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11015 else if (PL_encoding)
11016 sv_recode_to_utf8(tmpstr, PL_encoding);
11018 PL_lex_stuff = tmpstr;
11019 yylval.ival = op_type;
11023 /* scan_inputsymbol
11024 takes: current position in input buffer
11025 returns: new position in input buffer
11026 side-effects: yylval and lex_op are set.
11031 <FH> read from filehandle
11032 <pkg::FH> read from package qualified filehandle
11033 <pkg'FH> read from package qualified filehandle
11034 <$fh> read from filehandle in $fh
11035 <*.h> filename glob
11040 S_scan_inputsymbol(pTHX_ char *start)
11043 register char *s = start; /* current position in buffer */
11047 char *d = PL_tokenbuf; /* start of temp holding space */
11048 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11050 end = strchr(s, '\n');
11053 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11055 /* die if we didn't have space for the contents of the <>,
11056 or if it didn't end, or if we see a newline
11059 if (len >= sizeof PL_tokenbuf)
11060 Perl_croak(aTHX_ "Excessively long <> operator");
11062 Perl_croak(aTHX_ "Unterminated <> operator");
11067 Remember, only scalar variables are interpreted as filehandles by
11068 this code. Anything more complex (e.g., <$fh{$num}>) will be
11069 treated as a glob() call.
11070 This code makes use of the fact that except for the $ at the front,
11071 a scalar variable and a filehandle look the same.
11073 if (*d == '$' && d[1]) d++;
11075 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11076 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11079 /* If we've tried to read what we allow filehandles to look like, and
11080 there's still text left, then it must be a glob() and not a getline.
11081 Use scan_str to pull out the stuff between the <> and treat it
11082 as nothing more than a string.
11085 if (d - PL_tokenbuf != len) {
11086 yylval.ival = OP_GLOB;
11088 s = scan_str(start,!!PL_madskills,FALSE);
11090 Perl_croak(aTHX_ "Glob not terminated");
11094 bool readline_overriden = FALSE;
11097 /* we're in a filehandle read situation */
11100 /* turn <> into <ARGV> */
11102 Copy("ARGV",d,5,char);
11104 /* Check whether readline() is overriden */
11105 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11107 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11109 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11110 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
11111 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11112 readline_overriden = TRUE;
11114 /* if <$fh>, create the ops to turn the variable into a
11120 /* try to find it in the pad for this block, otherwise find
11121 add symbol table ops
11123 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
11124 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11125 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11126 HEK * const stashname = HvNAME_HEK(stash);
11127 SV * const sym = sv_2mortal(newSVhek(stashname));
11128 sv_catpvs(sym, "::");
11129 sv_catpv(sym, d+1);
11134 OP * const o = newOP(OP_PADSV, 0);
11136 PL_lex_op = readline_overriden
11137 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11138 append_elem(OP_LIST, o,
11139 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11140 : (OP*)newUNOP(OP_READLINE, 0, o);
11149 ? (GV_ADDMULTI | GV_ADDINEVAL)
11152 PL_lex_op = readline_overriden
11153 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11154 append_elem(OP_LIST,
11155 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11156 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11157 : (OP*)newUNOP(OP_READLINE, 0,
11158 newUNOP(OP_RV2SV, 0,
11159 newGVOP(OP_GV, 0, gv)));
11161 if (!readline_overriden)
11162 PL_lex_op->op_flags |= OPf_SPECIAL;
11163 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11164 yylval.ival = OP_NULL;
11167 /* If it's none of the above, it must be a literal filehandle
11168 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11170 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11171 PL_lex_op = readline_overriden
11172 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11173 append_elem(OP_LIST,
11174 newGVOP(OP_GV, 0, gv),
11175 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11176 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11177 yylval.ival = OP_NULL;
11186 takes: start position in buffer
11187 keep_quoted preserve \ on the embedded delimiter(s)
11188 keep_delims preserve the delimiters around the string
11189 returns: position to continue reading from buffer
11190 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11191 updates the read buffer.
11193 This subroutine pulls a string out of the input. It is called for:
11194 q single quotes q(literal text)
11195 ' single quotes 'literal text'
11196 qq double quotes qq(interpolate $here please)
11197 " double quotes "interpolate $here please"
11198 qx backticks qx(/bin/ls -l)
11199 ` backticks `/bin/ls -l`
11200 qw quote words @EXPORT_OK = qw( func() $spam )
11201 m// regexp match m/this/
11202 s/// regexp substitute s/this/that/
11203 tr/// string transliterate tr/this/that/
11204 y/// string transliterate y/this/that/
11205 ($*@) sub prototypes sub foo ($)
11206 (stuff) sub attr parameters sub foo : attr(stuff)
11207 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11209 In most of these cases (all but <>, patterns and transliterate)
11210 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11211 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11212 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11215 It skips whitespace before the string starts, and treats the first
11216 character as the delimiter. If the delimiter is one of ([{< then
11217 the corresponding "close" character )]}> is used as the closing
11218 delimiter. It allows quoting of delimiters, and if the string has
11219 balanced delimiters ([{<>}]) it allows nesting.
11221 On success, the SV with the resulting string is put into lex_stuff or,
11222 if that is already non-NULL, into lex_repl. The second case occurs only
11223 when parsing the RHS of the special constructs s/// and tr/// (y///).
11224 For convenience, the terminating delimiter character is stuffed into
11229 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11232 SV *sv; /* scalar value: string */
11233 char *tmps; /* temp string, used for delimiter matching */
11234 register char *s = start; /* current position in the buffer */
11235 register char term; /* terminating character */
11236 register char *to; /* current position in the sv's data */
11237 I32 brackets = 1; /* bracket nesting level */
11238 bool has_utf8 = FALSE; /* is there any utf8 content? */
11239 I32 termcode; /* terminating char. code */
11240 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11241 STRLEN termlen; /* length of terminating string */
11242 char *last = NULL; /* last position for nesting bracket */
11248 /* skip space before the delimiter */
11254 if (PL_realtokenstart >= 0) {
11255 stuffstart = PL_realtokenstart;
11256 PL_realtokenstart = -1;
11259 stuffstart = start - SvPVX(PL_linestr);
11261 /* mark where we are, in case we need to report errors */
11264 /* after skipping whitespace, the next character is the terminator */
11267 termcode = termstr[0] = term;
11271 termcode = utf8_to_uvchr((U8*)s, &termlen);
11272 Copy(s, termstr, termlen, U8);
11273 if (!UTF8_IS_INVARIANT(term))
11277 /* mark where we are */
11278 PL_multi_start = CopLINE(PL_curcop);
11279 PL_multi_open = term;
11281 /* find corresponding closing delimiter */
11282 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11283 termcode = termstr[0] = term = tmps[5];
11285 PL_multi_close = term;
11287 /* create a new SV to hold the contents. 79 is the SV's initial length.
11288 What a random number. */
11290 sv_upgrade(sv, SVt_PVIV);
11291 SvIV_set(sv, termcode);
11292 (void)SvPOK_only(sv); /* validate pointer */
11294 /* move past delimiter and try to read a complete string */
11296 sv_catpvn(sv, s, termlen);
11299 tstart = SvPVX(PL_linestr) + stuffstart;
11300 if (!PL_thisopen && !keep_delims) {
11301 PL_thisopen = newSVpvn(tstart, s - tstart);
11302 stuffstart = s - SvPVX(PL_linestr);
11306 if (PL_encoding && !UTF) {
11310 int offset = s - SvPVX_const(PL_linestr);
11311 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11312 &offset, (char*)termstr, termlen);
11313 const char * const ns = SvPVX_const(PL_linestr) + offset;
11314 char * const svlast = SvEND(sv) - 1;
11316 for (; s < ns; s++) {
11317 if (*s == '\n' && !PL_rsfp)
11318 CopLINE_inc(PL_curcop);
11321 goto read_more_line;
11323 /* handle quoted delimiters */
11324 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11326 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11328 if ((svlast-1 - t) % 2) {
11329 if (!keep_quoted) {
11330 *(svlast-1) = term;
11332 SvCUR_set(sv, SvCUR(sv) - 1);
11337 if (PL_multi_open == PL_multi_close) {
11345 for (t = w = last; t < svlast; w++, t++) {
11346 /* At here, all closes are "was quoted" one,
11347 so we don't check PL_multi_close. */
11349 if (!keep_quoted && *(t+1) == PL_multi_open)
11354 else if (*t == PL_multi_open)
11362 SvCUR_set(sv, w - SvPVX_const(sv));
11365 if (--brackets <= 0)
11370 if (!keep_delims) {
11371 SvCUR_set(sv, SvCUR(sv) - 1);
11377 /* extend sv if need be */
11378 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11379 /* set 'to' to the next character in the sv's string */
11380 to = SvPVX(sv)+SvCUR(sv);
11382 /* if open delimiter is the close delimiter read unbridle */
11383 if (PL_multi_open == PL_multi_close) {
11384 for (; s < PL_bufend; s++,to++) {
11385 /* embedded newlines increment the current line number */
11386 if (*s == '\n' && !PL_rsfp)
11387 CopLINE_inc(PL_curcop);
11388 /* handle quoted delimiters */
11389 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11390 if (!keep_quoted && s[1] == term)
11392 /* any other quotes are simply copied straight through */
11396 /* terminate when run out of buffer (the for() condition), or
11397 have found the terminator */
11398 else if (*s == term) {
11401 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11404 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11410 /* if the terminator isn't the same as the start character (e.g.,
11411 matched brackets), we have to allow more in the quoting, and
11412 be prepared for nested brackets.
11415 /* read until we run out of string, or we find the terminator */
11416 for (; s < PL_bufend; s++,to++) {
11417 /* embedded newlines increment the line count */
11418 if (*s == '\n' && !PL_rsfp)
11419 CopLINE_inc(PL_curcop);
11420 /* backslashes can escape the open or closing characters */
11421 if (*s == '\\' && s+1 < PL_bufend) {
11422 if (!keep_quoted &&
11423 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11428 /* allow nested opens and closes */
11429 else if (*s == PL_multi_close && --brackets <= 0)
11431 else if (*s == PL_multi_open)
11433 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11438 /* terminate the copied string and update the sv's end-of-string */
11440 SvCUR_set(sv, to - SvPVX_const(sv));
11443 * this next chunk reads more into the buffer if we're not done yet
11447 break; /* handle case where we are done yet :-) */
11449 #ifndef PERL_STRICT_CR
11450 if (to - SvPVX_const(sv) >= 2) {
11451 if ((to[-2] == '\r' && to[-1] == '\n') ||
11452 (to[-2] == '\n' && to[-1] == '\r'))
11456 SvCUR_set(sv, to - SvPVX_const(sv));
11458 else if (to[-1] == '\r')
11461 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11466 /* if we're out of file, or a read fails, bail and reset the current
11467 line marker so we can report where the unterminated string began
11470 if (PL_madskills) {
11471 char *tstart = SvPVX(PL_linestr) + stuffstart;
11473 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11475 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11479 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11481 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11487 /* we read a line, so increment our line counter */
11488 CopLINE_inc(PL_curcop);
11490 /* update debugger info */
11491 if (PERLDB_LINE && PL_curstash != PL_debstash) {
11492 SV * const line_sv = newSV(0);
11494 sv_upgrade(line_sv, SVt_PVMG);
11495 sv_setsv(line_sv,PL_linestr);
11496 (void)SvIOK_on(line_sv);
11497 SvIV_set(line_sv, 0);
11498 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop), line_sv);
11501 /* having changed the buffer, we must update PL_bufend */
11502 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11503 PL_last_lop = PL_last_uni = NULL;
11506 /* at this point, we have successfully read the delimited string */
11508 if (!PL_encoding || UTF) {
11510 if (PL_madskills) {
11511 char *tstart = SvPVX(PL_linestr) + stuffstart;
11513 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11515 PL_thisstuff = newSVpvn(tstart, s - tstart);
11516 if (!PL_thisclose && !keep_delims)
11517 PL_thisclose = newSVpvn(s,termlen);
11522 sv_catpvn(sv, s, termlen);
11527 if (PL_madskills) {
11528 char *tstart = SvPVX(PL_linestr) + stuffstart;
11530 sv_catpvn(PL_thisstuff, tstart, s - tstart - termlen);
11532 PL_thisstuff = newSVpvn(tstart, s - tstart - termlen);
11533 if (!PL_thisclose && !keep_delims)
11534 PL_thisclose = newSVpvn(s - termlen,termlen);
11538 if (has_utf8 || PL_encoding)
11541 PL_multi_end = CopLINE(PL_curcop);
11543 /* if we allocated too much space, give some back */
11544 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11545 SvLEN_set(sv, SvCUR(sv) + 1);
11546 SvPV_renew(sv, SvLEN(sv));
11549 /* decide whether this is the first or second quoted string we've read
11562 takes: pointer to position in buffer
11563 returns: pointer to new position in buffer
11564 side-effects: builds ops for the constant in yylval.op
11566 Read a number in any of the formats that Perl accepts:
11568 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11569 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11572 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11574 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11577 If it reads a number without a decimal point or an exponent, it will
11578 try converting the number to an integer and see if it can do so
11579 without loss of precision.
11583 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11586 register const char *s = start; /* current position in buffer */
11587 register char *d; /* destination in temp buffer */
11588 register char *e; /* end of temp buffer */
11589 NV nv; /* number read, as a double */
11590 SV *sv = NULL; /* place to put the converted number */
11591 bool floatit; /* boolean: int or float? */
11592 const char *lastub = NULL; /* position of last underbar */
11593 static char const number_too_long[] = "Number too long";
11595 /* We use the first character to decide what type of number this is */
11599 Perl_croak(aTHX_ "panic: scan_num");
11601 /* if it starts with a 0, it could be an octal number, a decimal in
11602 0.13 disguise, or a hexadecimal number, or a binary number. */
11606 u holds the "number so far"
11607 shift the power of 2 of the base
11608 (hex == 4, octal == 3, binary == 1)
11609 overflowed was the number more than we can hold?
11611 Shift is used when we add a digit. It also serves as an "are
11612 we in octal/hex/binary?" indicator to disallow hex characters
11613 when in octal mode.
11618 bool overflowed = FALSE;
11619 bool just_zero = TRUE; /* just plain 0 or binary number? */
11620 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11621 static const char* const bases[5] =
11622 { "", "binary", "", "octal", "hexadecimal" };
11623 static const char* const Bases[5] =
11624 { "", "Binary", "", "Octal", "Hexadecimal" };
11625 static const char* const maxima[5] =
11627 "0b11111111111111111111111111111111",
11631 const char *base, *Base, *max;
11633 /* check for hex */
11638 } else if (s[1] == 'b') {
11643 /* check for a decimal in disguise */
11644 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11646 /* so it must be octal */
11653 if (ckWARN(WARN_SYNTAX))
11654 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11655 "Misplaced _ in number");
11659 base = bases[shift];
11660 Base = Bases[shift];
11661 max = maxima[shift];
11663 /* read the rest of the number */
11665 /* x is used in the overflow test,
11666 b is the digit we're adding on. */
11671 /* if we don't mention it, we're done */
11675 /* _ are ignored -- but warned about if consecutive */
11677 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11678 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11679 "Misplaced _ in number");
11683 /* 8 and 9 are not octal */
11684 case '8': case '9':
11686 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11690 case '2': case '3': case '4':
11691 case '5': case '6': case '7':
11693 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11696 case '0': case '1':
11697 b = *s++ & 15; /* ASCII digit -> value of digit */
11701 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11702 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
11703 /* make sure they said 0x */
11706 b = (*s++ & 7) + 9;
11708 /* Prepare to put the digit we have onto the end
11709 of the number so far. We check for overflows.
11715 x = u << shift; /* make room for the digit */
11717 if ((x >> shift) != u
11718 && !(PL_hints & HINT_NEW_BINARY)) {
11721 if (ckWARN_d(WARN_OVERFLOW))
11722 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11723 "Integer overflow in %s number",
11726 u = x | b; /* add the digit to the end */
11729 n *= nvshift[shift];
11730 /* If an NV has not enough bits in its
11731 * mantissa to represent an UV this summing of
11732 * small low-order numbers is a waste of time
11733 * (because the NV cannot preserve the
11734 * low-order bits anyway): we could just
11735 * remember when did we overflow and in the
11736 * end just multiply n by the right
11744 /* if we get here, we had success: make a scalar value from
11749 /* final misplaced underbar check */
11750 if (s[-1] == '_') {
11751 if (ckWARN(WARN_SYNTAX))
11752 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11757 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
11758 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11759 "%s number > %s non-portable",
11765 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
11766 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11767 "%s number > %s non-portable",
11772 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
11773 sv = new_constant(start, s - start, "integer",
11775 else if (PL_hints & HINT_NEW_BINARY)
11776 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
11781 handle decimal numbers.
11782 we're also sent here when we read a 0 as the first digit
11784 case '1': case '2': case '3': case '4': case '5':
11785 case '6': case '7': case '8': case '9': case '.':
11788 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
11791 /* read next group of digits and _ and copy into d */
11792 while (isDIGIT(*s) || *s == '_') {
11793 /* skip underscores, checking for misplaced ones
11797 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11798 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11799 "Misplaced _ in number");
11803 /* check for end of fixed-length buffer */
11805 Perl_croak(aTHX_ number_too_long);
11806 /* if we're ok, copy the character */
11811 /* final misplaced underbar check */
11812 if (lastub && s == lastub + 1) {
11813 if (ckWARN(WARN_SYNTAX))
11814 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11817 /* read a decimal portion if there is one. avoid
11818 3..5 being interpreted as the number 3. followed
11821 if (*s == '.' && s[1] != '.') {
11826 if (ckWARN(WARN_SYNTAX))
11827 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11828 "Misplaced _ in number");
11832 /* copy, ignoring underbars, until we run out of digits.
11834 for (; isDIGIT(*s) || *s == '_'; s++) {
11835 /* fixed length buffer check */
11837 Perl_croak(aTHX_ number_too_long);
11839 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11840 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11841 "Misplaced _ in number");
11847 /* fractional part ending in underbar? */
11848 if (s[-1] == '_') {
11849 if (ckWARN(WARN_SYNTAX))
11850 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11851 "Misplaced _ in number");
11853 if (*s == '.' && isDIGIT(s[1])) {
11854 /* oops, it's really a v-string, but without the "v" */
11860 /* read exponent part, if present */
11861 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
11865 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
11866 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
11868 /* stray preinitial _ */
11870 if (ckWARN(WARN_SYNTAX))
11871 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11872 "Misplaced _ in number");
11876 /* allow positive or negative exponent */
11877 if (*s == '+' || *s == '-')
11880 /* stray initial _ */
11882 if (ckWARN(WARN_SYNTAX))
11883 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11884 "Misplaced _ in number");
11888 /* read digits of exponent */
11889 while (isDIGIT(*s) || *s == '_') {
11892 Perl_croak(aTHX_ number_too_long);
11896 if (((lastub && s == lastub + 1) ||
11897 (!isDIGIT(s[1]) && s[1] != '_'))
11898 && ckWARN(WARN_SYNTAX))
11899 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11900 "Misplaced _ in number");
11907 /* make an sv from the string */
11911 We try to do an integer conversion first if no characters
11912 indicating "float" have been found.
11917 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
11919 if (flags == IS_NUMBER_IN_UV) {
11921 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
11924 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
11925 if (uv <= (UV) IV_MIN)
11926 sv_setiv(sv, -(IV)uv);
11933 /* terminate the string */
11935 nv = Atof(PL_tokenbuf);
11939 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
11940 (PL_hints & HINT_NEW_INTEGER) )
11941 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
11942 (floatit ? "float" : "integer"),
11946 /* if it starts with a v, it could be a v-string */
11949 sv = newSV(5); /* preallocate storage space */
11950 s = scan_vstring(s,sv);
11954 /* make the op for the constant and return */
11957 lvalp->opval = newSVOP(OP_CONST, 0, sv);
11959 lvalp->opval = NULL;
11965 S_scan_formline(pTHX_ register char *s)
11968 register char *eol;
11970 SV * const stuff = newSVpvs("");
11971 bool needargs = FALSE;
11972 bool eofmt = FALSE;
11974 char *tokenstart = s;
11977 if (PL_madskills) {
11978 savewhite = PL_thiswhite;
11983 while (!needargs) {
11985 #ifdef PERL_STRICT_CR
11986 for (t = s+1;SPACE_OR_TAB(*t); t++) ;
11988 for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
11990 if (*t == '\n' || t == PL_bufend) {
11995 if (PL_in_eval && !PL_rsfp) {
11996 eol = (char *) memchr(s,'\n',PL_bufend-s);
12001 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12003 for (t = s; t < eol; t++) {
12004 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12006 goto enough; /* ~~ must be first line in formline */
12008 if (*t == '@' || *t == '^')
12012 sv_catpvn(stuff, s, eol-s);
12013 #ifndef PERL_STRICT_CR
12014 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12015 char *end = SvPVX(stuff) + SvCUR(stuff);
12018 SvCUR_set(stuff, SvCUR(stuff) - 1);
12028 if (PL_madskills) {
12030 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12032 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12035 s = filter_gets(PL_linestr, PL_rsfp, 0);
12037 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12039 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12041 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12042 PL_last_lop = PL_last_uni = NULL;
12051 if (SvCUR(stuff)) {
12054 PL_lex_state = LEX_NORMAL;
12055 start_force(PL_curforce);
12056 NEXTVAL_NEXTTOKE.ival = 0;
12060 PL_lex_state = LEX_FORMLINE;
12062 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12064 else if (PL_encoding)
12065 sv_recode_to_utf8(stuff, PL_encoding);
12067 start_force(PL_curforce);
12068 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12070 start_force(PL_curforce);
12071 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12075 SvREFCNT_dec(stuff);
12077 PL_lex_formbrack = 0;
12081 if (PL_madskills) {
12083 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12085 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12086 PL_thiswhite = savewhite;
12098 PL_cshlen = strlen(PL_cshname);
12100 #if defined(USE_ITHREADS)
12101 PERL_UNUSED_CONTEXT;
12107 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12110 const I32 oldsavestack_ix = PL_savestack_ix;
12111 CV* const outsidecv = PL_compcv;
12114 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12116 SAVEI32(PL_subline);
12117 save_item(PL_subname);
12118 SAVESPTR(PL_compcv);
12120 PL_compcv = (CV*)newSV(0);
12121 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
12122 CvFLAGS(PL_compcv) |= flags;
12124 PL_subline = CopLINE(PL_curcop);
12125 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12126 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12127 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12129 return oldsavestack_ix;
12133 #pragma segment Perl_yylex
12136 Perl_yywarn(pTHX_ const char *s)
12139 PL_in_eval |= EVAL_WARNONLY;
12141 PL_in_eval &= ~EVAL_WARNONLY;
12146 Perl_yyerror(pTHX_ const char *s)
12149 const char *where = NULL;
12150 const char *context = NULL;
12154 if (!yychar || (yychar == ';' && !PL_rsfp))
12156 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12157 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12158 PL_oldbufptr != PL_bufptr) {
12161 The code below is removed for NetWare because it abends/crashes on NetWare
12162 when the script has error such as not having the closing quotes like:
12163 if ($var eq "value)
12164 Checking of white spaces is anyway done in NetWare code.
12167 while (isSPACE(*PL_oldoldbufptr))
12170 context = PL_oldoldbufptr;
12171 contlen = PL_bufptr - PL_oldoldbufptr;
12173 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12174 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12177 The code below is removed for NetWare because it abends/crashes on NetWare
12178 when the script has error such as not having the closing quotes like:
12179 if ($var eq "value)
12180 Checking of white spaces is anyway done in NetWare code.
12183 while (isSPACE(*PL_oldbufptr))
12186 context = PL_oldbufptr;
12187 contlen = PL_bufptr - PL_oldbufptr;
12189 else if (yychar > 255)
12190 where = "next token ???";
12191 else if (yychar == -2) { /* YYEMPTY */
12192 if (PL_lex_state == LEX_NORMAL ||
12193 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12194 where = "at end of line";
12195 else if (PL_lex_inpat)
12196 where = "within pattern";
12198 where = "within string";
12201 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12203 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12204 else if (isPRINT_LC(yychar))
12205 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12207 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12208 where = SvPVX_const(where_sv);
12210 msg = sv_2mortal(newSVpv(s, 0));
12211 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12212 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12214 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12216 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12217 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12218 Perl_sv_catpvf(aTHX_ msg,
12219 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12220 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12223 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12224 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg);
12227 if (PL_error_count >= 10) {
12228 if (PL_in_eval && SvCUR(ERRSV))
12229 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12230 ERRSV, OutCopFILE(PL_curcop));
12232 Perl_croak(aTHX_ "%s has too many errors.\n",
12233 OutCopFILE(PL_curcop));
12236 PL_in_my_stash = NULL;
12240 #pragma segment Main
12244 S_swallow_bom(pTHX_ U8 *s)
12247 const STRLEN slen = SvCUR(PL_linestr);
12250 if (s[1] == 0xFE) {
12251 /* UTF-16 little-endian? (or UTF32-LE?) */
12252 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12253 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12254 #ifndef PERL_NO_UTF16_FILTER
12255 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12258 if (PL_bufend > (char*)s) {
12262 filter_add(utf16rev_textfilter, NULL);
12263 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12264 utf16_to_utf8_reversed(s, news,
12265 PL_bufend - (char*)s - 1,
12267 sv_setpvn(PL_linestr, (const char*)news, newlen);
12269 s = (U8*)SvPVX(PL_linestr);
12270 Copy(news, s, newlen, U8);
12274 SvUTF8_on(PL_linestr);
12275 s = (U8*)SvPVX(PL_linestr);
12277 /* FIXME - is this a general bug fix? */
12280 PL_bufend = SvPVX(PL_linestr) + newlen;
12283 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12288 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12289 #ifndef PERL_NO_UTF16_FILTER
12290 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12293 if (PL_bufend > (char *)s) {
12297 filter_add(utf16_textfilter, NULL);
12298 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12299 utf16_to_utf8(s, news,
12300 PL_bufend - (char*)s,
12302 sv_setpvn(PL_linestr, (const char*)news, newlen);
12304 SvUTF8_on(PL_linestr);
12305 s = (U8*)SvPVX(PL_linestr);
12306 PL_bufend = SvPVX(PL_linestr) + newlen;
12309 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12314 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12315 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12316 s += 3; /* UTF-8 */
12322 if (s[2] == 0xFE && s[3] == 0xFF) {
12323 /* UTF-32 big-endian */
12324 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12327 else if (s[2] == 0 && s[3] != 0) {
12330 * are a good indicator of UTF-16BE. */
12331 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12336 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12339 * are a good indicator of UTF-16LE. */
12340 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12349 * Restore a source filter.
12353 restore_rsfp(pTHX_ void *f)
12356 PerlIO * const fp = (PerlIO*)f;
12358 if (PL_rsfp == PerlIO_stdin())
12359 PerlIO_clearerr(PL_rsfp);
12360 else if (PL_rsfp && (PL_rsfp != fp))
12361 PerlIO_close(PL_rsfp);
12365 #ifndef PERL_NO_UTF16_FILTER
12367 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12370 const STRLEN old = SvCUR(sv);
12371 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12372 DEBUG_P(PerlIO_printf(Perl_debug_log,
12373 "utf16_textfilter(%p): %d %d (%d)\n",
12374 utf16_textfilter, idx, maxlen, (int) count));
12378 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12379 Copy(SvPVX_const(sv), tmps, old, char);
12380 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12381 SvCUR(sv) - old, &newlen);
12382 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12384 DEBUG_P({sv_dump(sv);});
12389 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12392 const STRLEN old = SvCUR(sv);
12393 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12394 DEBUG_P(PerlIO_printf(Perl_debug_log,
12395 "utf16rev_textfilter(%p): %d %d (%d)\n",
12396 utf16rev_textfilter, idx, maxlen, (int) count));
12400 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12401 Copy(SvPVX_const(sv), tmps, old, char);
12402 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12403 SvCUR(sv) - old, &newlen);
12404 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12406 DEBUG_P({ sv_dump(sv); });
12412 Returns a pointer to the next character after the parsed
12413 vstring, as well as updating the passed in sv.
12415 Function must be called like
12418 s = scan_vstring(s,sv);
12420 The sv should already be large enough to store the vstring
12421 passed in, for performance reasons.
12426 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
12429 const char *pos = s;
12430 const char *start = s;
12431 if (*pos == 'v') pos++; /* get past 'v' */
12432 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12434 if ( *pos != '.') {
12435 /* this may not be a v-string if followed by => */
12436 const char *next = pos;
12437 while (next < PL_bufend && isSPACE(*next))
12439 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
12440 /* return string not v-string */
12441 sv_setpvn(sv,(char *)s,pos-s);
12442 return (char *)pos;
12446 if (!isALPHA(*pos)) {
12447 U8 tmpbuf[UTF8_MAXBYTES+1];
12449 if (*s == 'v') s++; /* get past 'v' */
12451 sv_setpvn(sv, "", 0);
12457 /* this is atoi() that tolerates underscores */
12458 const char *end = pos;
12460 while (--end >= s) {
12465 rev += (*end - '0') * mult;
12467 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12468 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12469 "Integer overflow in decimal number");
12473 if (rev > 0x7FFFFFFF)
12474 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12476 /* Append native character for the rev point */
12477 tmpend = uvchr_to_utf8(tmpbuf, rev);
12478 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12479 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12481 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
12487 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12491 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12499 * c-indentation-style: bsd
12500 * c-basic-offset: 4
12501 * indent-tabs-mode: t
12504 * ex: set ts=8 sts=4 sw=4 noet: