3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * "It all comes from here, the stench and the peril." --Frodo
16 * This file is the lexer for Perl. It's closely linked to the
19 * The main routine is yylex(), which returns the next token.
23 #define PERL_IN_TOKE_C
26 #define yychar (*PL_yycharp)
27 #define yylval (*PL_yylvalp)
29 static const char ident_too_long[] = "Identifier too long";
30 static const char commaless_variable_list[] = "comma-less variable list";
32 static void restore_rsfp(pTHX_ void *f);
33 #ifndef PERL_NO_UTF16_FILTER
34 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
35 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
39 # define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
40 # define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
42 # define CURMAD(slot,sv)
43 # define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
46 #define XFAKEBRACK 128
49 #ifdef USE_UTF8_SCRIPTS
50 # define UTF (!IN_BYTES)
52 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
55 /* In variables named $^X, these are the legal values for X.
56 * 1999-02-27 mjd-perl-patch@plover.com */
57 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
59 /* On MacOS, respect nonbreaking spaces */
60 #ifdef MACOS_TRADITIONAL
61 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
63 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
66 /* LEX_* are values for PL_lex_state, the state of the lexer.
67 * They are arranged oddly so that the guard on the switch statement
68 * can get by with a single comparison (if the compiler is smart enough).
71 /* #define LEX_NOTPARSING 11 is done in perl.h. */
73 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
74 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
75 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
76 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
77 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
79 /* at end of code, eg "$x" followed by: */
80 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
81 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
83 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
84 string or after \E, $foo, etc */
85 #define LEX_INTERPCONST 2 /* NOT USED */
86 #define LEX_FORMLINE 1 /* expecting a format line */
87 #define LEX_KNOWNEXT 0 /* next token known; just return it */
91 static const char* const lex_state_names[] = {
110 #include "keywords.h"
112 /* CLINE is a macro that ensures PL_copline has a sane value */
117 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
120 # define SKIPSPACE0(s) skipspace0(s)
121 # define SKIPSPACE1(s) skipspace1(s)
122 # define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
123 # define PEEKSPACE(s) skipspace2(s,0)
125 # define SKIPSPACE0(s) skipspace(s)
126 # define SKIPSPACE1(s) skipspace(s)
127 # define SKIPSPACE2(s,tsv) skipspace(s)
128 # define PEEKSPACE(s) skipspace(s)
132 * Convenience functions to return different tokens and prime the
133 * lexer for the next token. They all take an argument.
135 * TOKEN : generic token (used for '(', DOLSHARP, etc)
136 * OPERATOR : generic operator
137 * AOPERATOR : assignment operator
138 * PREBLOCK : beginning the block after an if, while, foreach, ...
139 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
140 * PREREF : *EXPR where EXPR is not a simple identifier
141 * TERM : expression term
142 * LOOPX : loop exiting command (goto, last, dump, etc)
143 * FTST : file test operator
144 * FUN0 : zero-argument function
145 * FUN1 : not used, except for not, which isn't a UNIOP
146 * BOop : bitwise or or xor
148 * SHop : shift operator
149 * PWop : power operator
150 * PMop : pattern-matching operator
151 * Aop : addition-level operator
152 * Mop : multiplication-level operator
153 * Eop : equality-testing operator
154 * Rop : relational operator <= != gt
156 * Also see LOP and lop() below.
159 #ifdef DEBUGGING /* Serve -DT. */
160 # define REPORT(retval) tokereport((I32)retval)
162 # define REPORT(retval) (retval)
165 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
166 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
167 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
168 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
169 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
170 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
171 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
172 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
173 #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
174 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
175 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
176 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
177 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
178 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
179 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
180 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
181 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
182 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
183 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
184 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
186 /* This bit of chicanery makes a unary function followed by
187 * a parenthesis into a function with one argument, highest precedence.
188 * The UNIDOR macro is for unary functions that can be followed by the //
189 * operator (such as C<shift // 0>).
191 #define UNI2(f,x) { \
195 PL_last_uni = PL_oldbufptr; \
196 PL_last_lop_op = f; \
198 return REPORT( (int)FUNC1 ); \
200 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
202 #define UNI(f) UNI2(f,XTERM)
203 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
205 #define UNIBRACK(f) { \
208 PL_last_uni = PL_oldbufptr; \
210 return REPORT( (int)FUNC1 ); \
212 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
215 /* grandfather return to old style */
216 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
220 /* how to interpret the yylval associated with the token */
224 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
230 static struct debug_tokens {
232 enum token_type type;
234 } const debug_tokens[] =
236 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
237 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
238 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
239 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
240 { ARROW, TOKENTYPE_NONE, "ARROW" },
241 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
242 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
243 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
244 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
245 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
246 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
247 { DO, TOKENTYPE_NONE, "DO" },
248 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
249 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
250 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
251 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
252 { ELSE, TOKENTYPE_NONE, "ELSE" },
253 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
254 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
255 { FOR, TOKENTYPE_IVAL, "FOR" },
256 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
257 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
258 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
259 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
260 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
261 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
262 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
263 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
264 { IF, TOKENTYPE_IVAL, "IF" },
265 { LABEL, TOKENTYPE_PVAL, "LABEL" },
266 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
267 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
268 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
269 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
270 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
271 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
272 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
273 { MY, TOKENTYPE_IVAL, "MY" },
274 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
275 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
276 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
277 { OROP, TOKENTYPE_IVAL, "OROP" },
278 { OROR, TOKENTYPE_NONE, "OROR" },
279 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
280 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
281 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
282 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
283 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
284 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
285 { PREINC, TOKENTYPE_NONE, "PREINC" },
286 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
287 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
288 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
289 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
290 { SUB, TOKENTYPE_NONE, "SUB" },
291 { THING, TOKENTYPE_OPVAL, "THING" },
292 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
293 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
294 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
295 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
296 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
297 { USE, TOKENTYPE_IVAL, "USE" },
298 { WHEN, TOKENTYPE_IVAL, "WHEN" },
299 { WHILE, TOKENTYPE_IVAL, "WHILE" },
300 { WORD, TOKENTYPE_OPVAL, "WORD" },
301 { 0, TOKENTYPE_NONE, NULL }
304 /* dump the returned token in rv, plus any optional arg in yylval */
307 S_tokereport(pTHX_ I32 rv)
311 const char *name = NULL;
312 enum token_type type = TOKENTYPE_NONE;
313 const struct debug_tokens *p;
314 SV* const report = newSVpvs("<== ");
316 for (p = debug_tokens; p->token; p++) {
317 if (p->token == (int)rv) {
324 Perl_sv_catpv(aTHX_ report, name);
325 else if ((char)rv > ' ' && (char)rv < '~')
326 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
328 sv_catpvs(report, "EOF");
330 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
333 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
336 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
338 case TOKENTYPE_OPNUM:
339 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
340 PL_op_name[yylval.ival]);
343 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
345 case TOKENTYPE_OPVAL:
347 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
348 PL_op_name[yylval.opval->op_type]);
349 if (yylval.opval->op_type == OP_CONST) {
350 Perl_sv_catpvf(aTHX_ report, " %s",
351 SvPEEK(cSVOPx_sv(yylval.opval)));
356 sv_catpvs(report, "(opval=null)");
359 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
365 /* print the buffer with suitable escapes */
368 S_printbuf(pTHX_ const char* fmt, const char* s)
370 SV* const tmp = newSVpvs("");
371 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
380 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
381 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
385 S_ao(pTHX_ int toketype)
388 if (*PL_bufptr == '=') {
390 if (toketype == ANDAND)
391 yylval.ival = OP_ANDASSIGN;
392 else if (toketype == OROR)
393 yylval.ival = OP_ORASSIGN;
394 else if (toketype == DORDOR)
395 yylval.ival = OP_DORASSIGN;
403 * When Perl expects an operator and finds something else, no_op
404 * prints the warning. It always prints "<something> found where
405 * operator expected. It prints "Missing semicolon on previous line?"
406 * if the surprise occurs at the start of the line. "do you need to
407 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
408 * where the compiler doesn't know if foo is a method call or a function.
409 * It prints "Missing operator before end of line" if there's nothing
410 * after the missing operator, or "... before <...>" if there is something
411 * after the missing operator.
415 S_no_op(pTHX_ const char *what, char *s)
418 char * const oldbp = PL_bufptr;
419 const bool is_first = (PL_oldbufptr == PL_linestart);
425 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
426 if (ckWARN_d(WARN_SYNTAX)) {
428 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
429 "\t(Missing semicolon on previous line?)\n");
430 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
432 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
434 if (t < PL_bufptr && isSPACE(*t))
435 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
436 "\t(Do you need to predeclare %.*s?)\n",
437 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
441 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
442 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
450 * Complain about missing quote/regexp/heredoc terminator.
451 * If it's called with NULL then it cauterizes the line buffer.
452 * If we're in a delimited string and the delimiter is a control
453 * character, it's reformatted into a two-char sequence like ^C.
458 S_missingterm(pTHX_ char *s)
464 char * const nl = strrchr(s,'\n');
470 iscntrl(PL_multi_close)
472 PL_multi_close < 32 || PL_multi_close == 127
476 tmpbuf[1] = (char)toCTRL(PL_multi_close);
481 *tmpbuf = (char)PL_multi_close;
485 q = strchr(s,'"') ? '\'' : '"';
486 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
489 #define FEATURE_IS_ENABLED(name) \
490 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
491 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
493 * S_feature_is_enabled
494 * Check whether the named feature is enabled.
497 S_feature_is_enabled(pTHX_ const char *name, STRLEN namelen)
500 HV * const hinthv = GvHV(PL_hintgv);
501 char he_name[32] = "feature_";
502 (void) strncpy(&he_name[8], name, 24);
504 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
512 Perl_deprecate(pTHX_ const char *s)
514 if (ckWARN(WARN_DEPRECATED))
515 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
519 Perl_deprecate_old(pTHX_ const char *s)
521 /* This function should NOT be called for any new deprecated warnings */
522 /* Use Perl_deprecate instead */
524 /* It is here to maintain backward compatibility with the pre-5.8 */
525 /* warnings category hierarchy. The "deprecated" category used to */
526 /* live under the "syntax" category. It is now a top-level category */
527 /* in its own right. */
529 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
530 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
531 "Use of %s is deprecated", s);
535 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
536 * utf16-to-utf8-reversed.
539 #ifdef PERL_CR_FILTER
543 register const char *s = SvPVX_const(sv);
544 register const char * const e = s + SvCUR(sv);
545 /* outer loop optimized to do nothing if there are no CR-LFs */
547 if (*s++ == '\r' && *s == '\n') {
548 /* hit a CR-LF, need to copy the rest */
549 register char *d = s - 1;
552 if (*s == '\r' && s[1] == '\n')
563 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
565 const I32 count = FILTER_READ(idx+1, sv, maxlen);
566 if (count > 0 && !maxlen)
574 * Initialize variables. Uses the Perl save_stack to save its state (for
575 * recursive calls to the parser).
579 Perl_lex_start(pTHX_ SV *line)
585 SAVEI32(PL_lex_dojoin);
586 SAVEI32(PL_lex_brackets);
587 SAVEI32(PL_lex_casemods);
588 SAVEI32(PL_lex_starts);
589 SAVEI32(PL_lex_state);
590 SAVEVPTR(PL_lex_inpat);
591 SAVEI32(PL_lex_inwhat);
593 if (PL_lex_state == LEX_KNOWNEXT) {
594 I32 toke = PL_lasttoke;
595 while (--toke >= 0) {
596 SAVEI32(PL_nexttoke[toke].next_type);
597 SAVEVPTR(PL_nexttoke[toke].next_val);
599 SAVEVPTR(PL_nexttoke[toke].next_mad);
601 SAVEI32(PL_lasttoke);
604 SAVESPTR(PL_thistoken);
605 SAVESPTR(PL_thiswhite);
606 SAVESPTR(PL_nextwhite);
607 SAVESPTR(PL_thisopen);
608 SAVESPTR(PL_thisclose);
609 SAVESPTR(PL_thisstuff);
610 SAVEVPTR(PL_thismad);
611 SAVEI32(PL_realtokenstart);
612 SAVEI32(PL_faketokens);
614 SAVEI32(PL_curforce);
616 if (PL_lex_state == LEX_KNOWNEXT) {
617 I32 toke = PL_nexttoke;
618 while (--toke >= 0) {
619 SAVEI32(PL_nexttype[toke]);
620 SAVEVPTR(PL_nextval[toke]);
622 SAVEI32(PL_nexttoke);
625 SAVECOPLINE(PL_curcop);
628 SAVEPPTR(PL_oldbufptr);
629 SAVEPPTR(PL_oldoldbufptr);
630 SAVEPPTR(PL_last_lop);
631 SAVEPPTR(PL_last_uni);
632 SAVEPPTR(PL_linestart);
633 SAVESPTR(PL_linestr);
634 SAVEGENERICPV(PL_lex_brackstack);
635 SAVEGENERICPV(PL_lex_casestack);
636 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
637 SAVESPTR(PL_lex_stuff);
638 SAVEI32(PL_lex_defer);
639 SAVEI32(PL_sublex_info.sub_inwhat);
640 SAVESPTR(PL_lex_repl);
642 SAVEINT(PL_lex_expect);
644 PL_lex_state = LEX_NORMAL;
648 Newx(PL_lex_brackstack, 120, char);
649 Newx(PL_lex_casestack, 12, char);
651 *PL_lex_casestack = '\0';
663 PL_sublex_info.sub_inwhat = 0;
665 if (SvREADONLY(PL_linestr))
666 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
667 s = SvPV_const(PL_linestr, len);
668 if (!len || s[len-1] != ';') {
669 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
670 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
671 sv_catpvs(PL_linestr, "\n;");
673 SvTEMP_off(PL_linestr);
674 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
675 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
676 PL_last_lop = PL_last_uni = NULL;
682 * Finalizer for lexing operations. Must be called when the parser is
683 * done with the lexer.
690 PL_doextract = FALSE;
695 * This subroutine has nothing to do with tilting, whether at windmills
696 * or pinball tables. Its name is short for "increment line". It
697 * increments the current line number in CopLINE(PL_curcop) and checks
698 * to see whether the line starts with a comment of the form
699 * # line 500 "foo.pm"
700 * If so, it sets the current line number and file to the values in the comment.
704 S_incline(pTHX_ char *s)
712 CopLINE_inc(PL_curcop);
715 while (SPACE_OR_TAB(*s))
717 if (strnEQ(s, "line", 4))
721 if (SPACE_OR_TAB(*s))
725 while (SPACE_OR_TAB(*s))
733 while (SPACE_OR_TAB(*s))
735 if (*s == '"' && (t = strchr(s+1, '"'))) {
745 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
747 if (*e != '\n' && *e != '\0')
748 return; /* false alarm */
754 const char * const cf = CopFILE(PL_curcop);
755 STRLEN tmplen = cf ? strlen(cf) : 0;
756 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
757 /* must copy *{"::_<(eval N)[oldfilename:L]"}
758 * to *{"::_<newfilename"} */
759 char smallbuf[256], smallbuf2[256];
760 char *tmpbuf, *tmpbuf2;
762 STRLEN tmplen2 = strlen(s);
763 if (tmplen + 3 < sizeof smallbuf)
766 Newx(tmpbuf, tmplen + 3, char);
767 if (tmplen2 + 3 < sizeof smallbuf2)
770 Newx(tmpbuf2, tmplen2 + 3, char);
771 tmpbuf[0] = tmpbuf2[0] = '_';
772 tmpbuf[1] = tmpbuf2[1] = '<';
773 memcpy(tmpbuf + 2, cf, ++tmplen);
774 memcpy(tmpbuf2 + 2, s, ++tmplen2);
776 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
778 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
780 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
781 /* adjust ${"::_<newfilename"} to store the new file name */
782 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
783 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
784 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
786 if (tmpbuf != smallbuf) Safefree(tmpbuf);
787 if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
790 CopFILE_free(PL_curcop);
791 CopFILE_set(PL_curcop, s);
794 CopLINE_set(PL_curcop, atoi(n)-1);
798 /* skip space before PL_thistoken */
801 S_skipspace0(pTHX_ register char *s)
808 PL_thiswhite = newSVpvn("",0);
809 sv_catsv(PL_thiswhite, PL_skipwhite);
810 sv_free(PL_skipwhite);
813 PL_realtokenstart = s - SvPVX(PL_linestr);
817 /* skip space after PL_thistoken */
820 S_skipspace1(pTHX_ register char *s)
822 const char *start = s;
823 I32 startoff = start - SvPVX(PL_linestr);
828 start = SvPVX(PL_linestr) + startoff;
829 if (!PL_thistoken && PL_realtokenstart >= 0) {
830 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
831 PL_thistoken = newSVpvn(tstart, start - tstart);
833 PL_realtokenstart = -1;
836 PL_nextwhite = newSVpvn("",0);
837 sv_catsv(PL_nextwhite, PL_skipwhite);
838 sv_free(PL_skipwhite);
845 S_skipspace2(pTHX_ register char *s, SV **svp)
848 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
849 const I32 startoff = s - SvPVX(PL_linestr);
852 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
853 if (!PL_madskills || !svp)
855 start = SvPVX(PL_linestr) + startoff;
856 if (!PL_thistoken && PL_realtokenstart >= 0) {
857 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
858 PL_thistoken = newSVpvn(tstart, start - tstart);
859 PL_realtokenstart = -1;
863 *svp = newSVpvn("",0);
864 sv_setsv(*svp, PL_skipwhite);
865 sv_free(PL_skipwhite);
875 * Called to gobble the appropriate amount and type of whitespace.
876 * Skips comments as well.
880 S_skipspace(pTHX_ register char *s)
885 int startoff = s - SvPVX(PL_linestr);
888 sv_free(PL_skipwhite);
893 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
894 while (s < PL_bufend && SPACE_OR_TAB(*s))
904 SSize_t oldprevlen, oldoldprevlen;
905 SSize_t oldloplen = 0, oldunilen = 0;
906 while (s < PL_bufend && isSPACE(*s)) {
907 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
912 if (s < PL_bufend && *s == '#') {
913 while (s < PL_bufend && *s != '\n')
917 if (PL_in_eval && !PL_rsfp) {
924 /* only continue to recharge the buffer if we're at the end
925 * of the buffer, we're not reading from a source filter, and
926 * we're in normal lexing mode
928 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
929 PL_lex_state == LEX_FORMLINE)
936 /* try to recharge the buffer */
938 curoff = s - SvPVX(PL_linestr);
941 if ((s = filter_gets(PL_linestr, PL_rsfp,
942 (prevlen = SvCUR(PL_linestr)))) == NULL)
945 if (PL_madskills && curoff != startoff) {
947 PL_skipwhite = newSVpvn("",0);
948 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
952 /* mustn't throw out old stuff yet if madpropping */
953 SvCUR(PL_linestr) = curoff;
954 s = SvPVX(PL_linestr) + curoff;
956 if (curoff && s[-1] == '\n')
960 /* end of file. Add on the -p or -n magic */
961 /* XXX these shouldn't really be added here, can't set PL_faketokens */
965 ";}continue{print or die qq(-p destination: $!\\n);}");
968 ";}continue{print or die qq(-p destination: $!\\n);}");
970 PL_minus_n = PL_minus_p = 0;
972 else if (PL_minus_n) {
974 sv_catpvn(PL_linestr, ";}", 2);
976 sv_setpvn(PL_linestr, ";}", 2);
982 sv_catpvn(PL_linestr,";", 1);
984 sv_setpvn(PL_linestr,";", 1);
987 /* reset variables for next time we lex */
988 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
994 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
995 PL_last_lop = PL_last_uni = NULL;
997 /* Close the filehandle. Could be from -P preprocessor,
998 * STDIN, or a regular file. If we were reading code from
999 * STDIN (because the commandline held no -e or filename)
1000 * then we don't close it, we reset it so the code can
1001 * read from STDIN too.
1004 if (PL_preprocess && !PL_in_eval)
1005 (void)PerlProc_pclose(PL_rsfp);
1006 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1007 PerlIO_clearerr(PL_rsfp);
1009 (void)PerlIO_close(PL_rsfp);
1014 /* not at end of file, so we only read another line */
1015 /* make corresponding updates to old pointers, for yyerror() */
1016 oldprevlen = PL_oldbufptr - PL_bufend;
1017 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1019 oldunilen = PL_last_uni - PL_bufend;
1021 oldloplen = PL_last_lop - PL_bufend;
1022 PL_linestart = PL_bufptr = s + prevlen;
1023 PL_bufend = s + SvCUR(PL_linestr);
1025 PL_oldbufptr = s + oldprevlen;
1026 PL_oldoldbufptr = s + oldoldprevlen;
1028 PL_last_uni = s + oldunilen;
1030 PL_last_lop = s + oldloplen;
1033 /* debugger active and we're not compiling the debugger code,
1034 * so store the line into the debugger's array of lines
1036 if (PERLDB_LINE && PL_curstash != PL_debstash) {
1037 SV * const sv = newSV(0);
1039 sv_upgrade(sv, SVt_PVMG);
1040 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
1043 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
1051 PL_skipwhite = newSVpvn("",0);
1052 curoff = s - SvPVX(PL_linestr);
1053 if (curoff - startoff)
1054 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1063 * Check the unary operators to ensure there's no ambiguity in how they're
1064 * used. An ambiguous piece of code would be:
1066 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1067 * the +5 is its argument.
1077 if (PL_oldoldbufptr != PL_last_uni)
1079 while (isSPACE(*PL_last_uni))
1082 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1084 if ((t = strchr(s, '(')) && t < PL_bufptr)
1087 if (ckWARN_d(WARN_AMBIGUOUS)){
1088 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1089 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1090 (int)(s - PL_last_uni), PL_last_uni);
1095 * LOP : macro to build a list operator. Its behaviour has been replaced
1096 * with a subroutine, S_lop() for which LOP is just another name.
1099 #define LOP(f,x) return lop(f,x,s)
1103 * Build a list operator (or something that might be one). The rules:
1104 * - if we have a next token, then it's a list operator [why?]
1105 * - if the next thing is an opening paren, then it's a function
1106 * - else it's a list operator
1110 S_lop(pTHX_ I32 f, int x, char *s)
1117 PL_last_lop = PL_oldbufptr;
1118 PL_last_lop_op = (OPCODE)f;
1121 return REPORT(LSTOP);
1124 return REPORT(LSTOP);
1127 return REPORT(FUNC);
1130 return REPORT(FUNC);
1132 return REPORT(LSTOP);
1138 * Sets up for an eventual force_next(). start_force(0) basically does
1139 * an unshift, while start_force(-1) does a push. yylex removes items
1144 S_start_force(pTHX_ int where)
1148 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1149 where = PL_lasttoke;
1150 assert(PL_curforce < 0 || PL_curforce == where);
1151 if (PL_curforce != where) {
1152 for (i = PL_lasttoke; i > where; --i) {
1153 PL_nexttoke[i] = PL_nexttoke[i-1];
1157 if (PL_curforce < 0) /* in case of duplicate start_force() */
1158 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1159 PL_curforce = where;
1162 curmad('^', newSVpvn("",0));
1163 CURMAD('_', PL_nextwhite);
1168 S_curmad(pTHX_ char slot, SV *sv)
1174 if (PL_curforce < 0)
1175 where = &PL_thismad;
1177 where = &PL_nexttoke[PL_curforce].next_mad;
1180 sv_setpvn(sv, "", 0);
1183 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1185 else if (PL_encoding) {
1186 sv_recode_to_utf8(sv, PL_encoding);
1191 /* keep a slot open for the head of the list? */
1192 if (slot != '_' && *where && (*where)->mad_key == '^') {
1193 (*where)->mad_key = slot;
1194 sv_free((*where)->mad_val);
1195 (*where)->mad_val = (void*)sv;
1198 addmad(newMADsv(slot, sv), where, 0);
1201 # define start_force(where) NOOP
1202 # define curmad(slot, sv) NOOP
1207 * When the lexer realizes it knows the next token (for instance,
1208 * it is reordering tokens for the parser) then it can call S_force_next
1209 * to know what token to return the next time the lexer is called. Caller
1210 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1211 * and possibly PL_expect to ensure the lexer handles the token correctly.
1215 S_force_next(pTHX_ I32 type)
1219 if (PL_curforce < 0)
1220 start_force(PL_lasttoke);
1221 PL_nexttoke[PL_curforce].next_type = type;
1222 if (PL_lex_state != LEX_KNOWNEXT)
1223 PL_lex_defer = PL_lex_state;
1224 PL_lex_state = LEX_KNOWNEXT;
1225 PL_lex_expect = PL_expect;
1228 PL_nexttype[PL_nexttoke] = type;
1230 if (PL_lex_state != LEX_KNOWNEXT) {
1231 PL_lex_defer = PL_lex_state;
1232 PL_lex_expect = PL_expect;
1233 PL_lex_state = LEX_KNOWNEXT;
1239 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1242 SV * const sv = newSVpvn(start,len);
1243 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
1250 * When the lexer knows the next thing is a word (for instance, it has
1251 * just seen -> and it knows that the next char is a word char, then
1252 * it calls S_force_word to stick the next word into the PL_next lookahead.
1255 * char *start : buffer position (must be within PL_linestr)
1256 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
1257 * int check_keyword : if true, Perl checks to make sure the word isn't
1258 * a keyword (do this if the word is a label, e.g. goto FOO)
1259 * int allow_pack : if true, : characters will also be allowed (require,
1260 * use, etc. do this)
1261 * int allow_initial_tick : used by the "sub" lexer only.
1265 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1271 start = SKIPSPACE1(start);
1273 if (isIDFIRST_lazy_if(s,UTF) ||
1274 (allow_pack && *s == ':') ||
1275 (allow_initial_tick && *s == '\'') )
1277 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1278 if (check_keyword && keyword(PL_tokenbuf, len))
1280 start_force(PL_curforce);
1282 curmad('X', newSVpvn(start,s-start));
1283 if (token == METHOD) {
1288 PL_expect = XOPERATOR;
1291 NEXTVAL_NEXTTOKE.opval
1292 = (OP*)newSVOP(OP_CONST,0,
1293 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1294 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1302 * Called when the lexer wants $foo *foo &foo etc, but the program
1303 * text only contains the "foo" portion. The first argument is a pointer
1304 * to the "foo", and the second argument is the type symbol to prefix.
1305 * Forces the next token to be a "WORD".
1306 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1310 S_force_ident(pTHX_ register const char *s, int kind)
1314 const STRLEN len = strlen(s);
1315 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1316 start_force(PL_curforce);
1317 NEXTVAL_NEXTTOKE.opval = o;
1320 o->op_private = OPpCONST_ENTERED;
1321 /* XXX see note in pp_entereval() for why we forgo typo
1322 warnings if the symbol must be introduced in an eval.
1324 gv_fetchpvn_flags(s, len,
1325 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1327 kind == '$' ? SVt_PV :
1328 kind == '@' ? SVt_PVAV :
1329 kind == '%' ? SVt_PVHV :
1337 Perl_str_to_version(pTHX_ SV *sv)
1342 const char *start = SvPV_const(sv,len);
1343 const char * const end = start + len;
1344 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1345 while (start < end) {
1349 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1354 retval += ((NV)n)/nshift;
1363 * Forces the next token to be a version number.
1364 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1365 * and if "guessing" is TRUE, then no new token is created (and the caller
1366 * must use an alternative parsing method).
1370 S_force_version(pTHX_ char *s, int guessing)
1376 I32 startoff = s - SvPVX(PL_linestr);
1385 while (isDIGIT(*d) || *d == '_' || *d == '.')
1389 start_force(PL_curforce);
1390 curmad('X', newSVpvn(s,d-s));
1393 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1395 s = scan_num(s, &yylval);
1396 version = yylval.opval;
1397 ver = cSVOPx(version)->op_sv;
1398 if (SvPOK(ver) && !SvNIOK(ver)) {
1399 SvUPGRADE(ver, SVt_PVNV);
1400 SvNV_set(ver, str_to_version(ver));
1401 SvNOK_on(ver); /* hint that it is a version */
1404 else if (guessing) {
1407 sv_free(PL_nextwhite); /* let next token collect whitespace */
1409 s = SvPVX(PL_linestr) + startoff;
1417 if (PL_madskills && !version) {
1418 sv_free(PL_nextwhite); /* let next token collect whitespace */
1420 s = SvPVX(PL_linestr) + startoff;
1423 /* NOTE: The parser sees the package name and the VERSION swapped */
1424 start_force(PL_curforce);
1425 NEXTVAL_NEXTTOKE.opval = version;
1433 * Tokenize a quoted string passed in as an SV. It finds the next
1434 * chunk, up to end of string or a backslash. It may make a new
1435 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1440 S_tokeq(pTHX_ SV *sv)
1444 register char *send;
1452 s = SvPV_force(sv, len);
1453 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1456 while (s < send && *s != '\\')
1461 if ( PL_hints & HINT_NEW_STRING ) {
1462 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1468 if (s + 1 < send && (s[1] == '\\'))
1469 s++; /* all that, just for this */
1474 SvCUR_set(sv, d - SvPVX_const(sv));
1476 if ( PL_hints & HINT_NEW_STRING )
1477 return new_constant(NULL, 0, "q", sv, pv, "q");
1482 * Now come three functions related to double-quote context,
1483 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1484 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1485 * interact with PL_lex_state, and create fake ( ... ) argument lists
1486 * to handle functions and concatenation.
1487 * They assume that whoever calls them will be setting up a fake
1488 * join call, because each subthing puts a ',' after it. This lets
1491 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1493 * (I'm not sure whether the spurious commas at the end of lcfirst's
1494 * arguments and join's arguments are created or not).
1499 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1501 * Pattern matching will set PL_lex_op to the pattern-matching op to
1502 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1504 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1506 * Everything else becomes a FUNC.
1508 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1509 * had an OP_CONST or OP_READLINE). This just sets us up for a
1510 * call to S_sublex_push().
1514 S_sublex_start(pTHX)
1517 register const I32 op_type = yylval.ival;
1519 if (op_type == OP_NULL) {
1520 yylval.opval = PL_lex_op;
1524 if (op_type == OP_CONST || op_type == OP_READLINE) {
1525 SV *sv = tokeq(PL_lex_stuff);
1527 if (SvTYPE(sv) == SVt_PVIV) {
1528 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1530 const char * const p = SvPV_const(sv, len);
1531 SV * const nsv = newSVpvn(p, len);
1537 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1538 PL_lex_stuff = NULL;
1539 /* Allow <FH> // "foo" */
1540 if (op_type == OP_READLINE)
1541 PL_expect = XTERMORDORDOR;
1545 PL_sublex_info.super_state = PL_lex_state;
1546 PL_sublex_info.sub_inwhat = op_type;
1547 PL_sublex_info.sub_op = PL_lex_op;
1548 PL_lex_state = LEX_INTERPPUSH;
1552 yylval.opval = PL_lex_op;
1562 * Create a new scope to save the lexing state. The scope will be
1563 * ended in S_sublex_done. Returns a '(', starting the function arguments
1564 * to the uc, lc, etc. found before.
1565 * Sets PL_lex_state to LEX_INTERPCONCAT.
1574 PL_lex_state = PL_sublex_info.super_state;
1575 SAVEI32(PL_lex_dojoin);
1576 SAVEI32(PL_lex_brackets);
1577 SAVEI32(PL_lex_casemods);
1578 SAVEI32(PL_lex_starts);
1579 SAVEI32(PL_lex_state);
1580 SAVEVPTR(PL_lex_inpat);
1581 SAVEI32(PL_lex_inwhat);
1582 SAVECOPLINE(PL_curcop);
1583 SAVEPPTR(PL_bufptr);
1584 SAVEPPTR(PL_bufend);
1585 SAVEPPTR(PL_oldbufptr);
1586 SAVEPPTR(PL_oldoldbufptr);
1587 SAVEPPTR(PL_last_lop);
1588 SAVEPPTR(PL_last_uni);
1589 SAVEPPTR(PL_linestart);
1590 SAVESPTR(PL_linestr);
1591 SAVEGENERICPV(PL_lex_brackstack);
1592 SAVEGENERICPV(PL_lex_casestack);
1594 PL_linestr = PL_lex_stuff;
1595 PL_lex_stuff = NULL;
1597 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1598 = SvPVX(PL_linestr);
1599 PL_bufend += SvCUR(PL_linestr);
1600 PL_last_lop = PL_last_uni = NULL;
1601 SAVEFREESV(PL_linestr);
1603 PL_lex_dojoin = FALSE;
1604 PL_lex_brackets = 0;
1605 Newx(PL_lex_brackstack, 120, char);
1606 Newx(PL_lex_casestack, 12, char);
1607 PL_lex_casemods = 0;
1608 *PL_lex_casestack = '\0';
1610 PL_lex_state = LEX_INTERPCONCAT;
1611 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1613 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1614 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1615 PL_lex_inpat = PL_sublex_info.sub_op;
1617 PL_lex_inpat = NULL;
1624 * Restores lexer state after a S_sublex_push.
1631 if (!PL_lex_starts++) {
1632 SV * const sv = newSVpvs("");
1633 if (SvUTF8(PL_linestr))
1635 PL_expect = XOPERATOR;
1636 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1640 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1641 PL_lex_state = LEX_INTERPCASEMOD;
1645 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1646 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1647 PL_linestr = PL_lex_repl;
1649 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1650 PL_bufend += SvCUR(PL_linestr);
1651 PL_last_lop = PL_last_uni = NULL;
1652 SAVEFREESV(PL_linestr);
1653 PL_lex_dojoin = FALSE;
1654 PL_lex_brackets = 0;
1655 PL_lex_casemods = 0;
1656 *PL_lex_casestack = '\0';
1658 if (SvEVALED(PL_lex_repl)) {
1659 PL_lex_state = LEX_INTERPNORMAL;
1661 /* we don't clear PL_lex_repl here, so that we can check later
1662 whether this is an evalled subst; that means we rely on the
1663 logic to ensure sublex_done() is called again only via the
1664 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1667 PL_lex_state = LEX_INTERPCONCAT;
1677 PL_endwhite = newSVpvn("",0);
1678 sv_catsv(PL_endwhite, PL_thiswhite);
1682 sv_setpvn(PL_thistoken,"",0);
1684 PL_realtokenstart = -1;
1688 PL_bufend = SvPVX(PL_linestr);
1689 PL_bufend += SvCUR(PL_linestr);
1690 PL_expect = XOPERATOR;
1691 PL_sublex_info.sub_inwhat = 0;
1699 Extracts a pattern, double-quoted string, or transliteration. This
1702 It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1703 processing a pattern (PL_lex_inpat is true), a transliteration
1704 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1706 Returns a pointer to the character scanned up to. Iff this is
1707 advanced from the start pointer supplied (ie if anything was
1708 successfully parsed), will leave an OP for the substring scanned
1709 in yylval. Caller must intuit reason for not parsing further
1710 by looking at the next characters herself.
1714 double-quoted style: \r and \n
1715 regexp special ones: \D \s
1717 backrefs: \1 (deprecated in substitution replacements)
1718 case and quoting: \U \Q \E
1719 stops on @ and $, but not for $ as tail anchor
1721 In transliterations:
1722 characters are VERY literal, except for - not at the start or end
1723 of the string, which indicates a range. scan_const expands the
1724 range to the full set of intermediate characters.
1726 In double-quoted strings:
1728 double-quoted style: \r and \n
1730 backrefs: \1 (deprecated)
1731 case and quoting: \U \Q \E
1734 scan_const does *not* construct ops to handle interpolated strings.
1735 It stops processing as soon as it finds an embedded $ or @ variable
1736 and leaves it to the caller to work out what's going on.
1738 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo.
1740 $ in pattern could be $foo or could be tail anchor. Assumption:
1741 it's a tail anchor if $ is the last thing in the string, or if it's
1742 followed by one of ")| \n\t"
1744 \1 (backreferences) are turned into $1
1746 The structure of the code is
1747 while (there's a character to process) {
1748 handle transliteration ranges
1749 skip regexp comments
1750 skip # initiated comments in //x patterns
1751 check for embedded @foo
1752 check for embedded scalars
1754 leave intact backslashes from leave (below)
1755 deprecate \1 in strings and sub replacements
1756 handle string-changing backslashes \l \U \Q \E, etc.
1757 switch (what was escaped) {
1758 handle - in a transliteration (becomes a literal -)
1759 handle \132 octal characters
1760 handle 0x15 hex characters
1761 handle \cV (control V)
1762 handle printf backslashes (\f, \r, \n, etc)
1764 } (end if backslash)
1765 } (end while character to read)
1770 S_scan_const(pTHX_ char *start)
1773 register char *send = PL_bufend; /* end of the constant */
1774 SV *sv = newSV(send - start); /* sv for the constant */
1775 register char *s = start; /* start of the constant */
1776 register char *d = SvPVX(sv); /* destination for copies */
1777 bool dorange = FALSE; /* are we in a translit range? */
1778 bool didrange = FALSE; /* did we just finish a range? */
1779 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1780 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1783 UV literal_endpoint = 0;
1786 const char * const leaveit = /* set of acceptably-backslashed characters */
1788 ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#"
1791 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1792 /* If we are doing a trans and we know we want UTF8 set expectation */
1793 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1794 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1798 while (s < send || dorange) {
1799 /* get transliterations out of the way (they're most literal) */
1800 if (PL_lex_inwhat == OP_TRANS) {
1801 /* expand a range A-Z to the full set of characters. AIE! */
1803 I32 i; /* current expanded character */
1804 I32 min; /* first character in range */
1805 I32 max; /* last character in range */
1808 char * const c = (char*)utf8_hop((U8*)d, -1);
1812 *c = (char)UTF_TO_NATIVE(0xff);
1813 /* mark the range as done, and continue */
1819 i = d - SvPVX_const(sv); /* remember current offset */
1820 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1821 d = SvPVX(sv) + i; /* refresh d after realloc */
1822 d -= 2; /* eat the first char and the - */
1824 min = (U8)*d; /* first char in range */
1825 max = (U8)d[1]; /* last char in range */
1829 "Invalid range \"%c-%c\" in transliteration operator",
1830 (char)min, (char)max);
1834 if (literal_endpoint == 2 &&
1835 ((isLOWER(min) && isLOWER(max)) ||
1836 (isUPPER(min) && isUPPER(max)))) {
1838 for (i = min; i <= max; i++)
1840 *d++ = NATIVE_TO_NEED(has_utf8,i);
1842 for (i = min; i <= max; i++)
1844 *d++ = NATIVE_TO_NEED(has_utf8,i);
1849 for (i = min; i <= max; i++)
1852 /* mark the range as done, and continue */
1856 literal_endpoint = 0;
1861 /* range begins (ignore - as first or last char) */
1862 else if (*s == '-' && s+1 < send && s != start) {
1864 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1867 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1877 literal_endpoint = 0;
1882 /* if we get here, we're not doing a transliteration */
1884 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1885 except for the last char, which will be done separately. */
1886 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1888 while (s+1 < send && *s != ')')
1889 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1891 else if (s[2] == '{' /* This should match regcomp.c */
1892 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1895 char *regparse = s + (s[2] == '{' ? 3 : 4);
1898 while (count && (c = *regparse)) {
1899 if (c == '\\' && regparse[1])
1907 if (*regparse != ')')
1908 regparse--; /* Leave one char for continuation. */
1909 while (s < regparse)
1910 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1914 /* likewise skip #-initiated comments in //x patterns */
1915 else if (*s == '#' && PL_lex_inpat &&
1916 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1917 while (s+1 < send && *s != '\n')
1918 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1921 /* check for embedded arrays
1922 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
1924 else if (*s == '@' && s[1]
1925 && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1])))
1928 /* check for embedded scalars. only stop if we're sure it's a
1931 else if (*s == '$') {
1932 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
1934 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
1935 break; /* in regexp, $ might be tail anchor */
1938 /* End of else if chain - OP_TRANS rejoin rest */
1941 if (*s == '\\' && s+1 < send) {
1944 /* some backslashes we leave behind */
1945 if (*leaveit && *s && strchr(leaveit, *s)) {
1946 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
1947 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1951 /* deprecate \1 in strings and substitution replacements */
1952 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1953 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1955 if (ckWARN(WARN_SYNTAX))
1956 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
1961 /* string-change backslash escapes */
1962 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1967 /* if we get here, it's either a quoted -, or a digit */
1970 /* quoted - in transliterations */
1972 if (PL_lex_inwhat == OP_TRANS) {
1979 if ((isALPHA(*s) || isDIGIT(*s)) &&
1981 Perl_warner(aTHX_ packWARN(WARN_MISC),
1982 "Unrecognized escape \\%c passed through",
1984 /* default action is to copy the quoted character */
1985 goto default_action;
1988 /* \132 indicates an octal constant */
1989 case '0': case '1': case '2': case '3':
1990 case '4': case '5': case '6': case '7':
1994 uv = grok_oct(s, &len, &flags, NULL);
1997 goto NUM_ESCAPE_INSERT;
1999 /* \x24 indicates a hex constant */
2003 char* const e = strchr(s, '}');
2004 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2005 PERL_SCAN_DISALLOW_PREFIX;
2010 yyerror("Missing right brace on \\x{}");
2014 uv = grok_hex(s, &len, &flags, NULL);
2020 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2021 uv = grok_hex(s, &len, &flags, NULL);
2027 /* Insert oct or hex escaped character.
2028 * There will always enough room in sv since such
2029 * escapes will be longer than any UTF-8 sequence
2030 * they can end up as. */
2032 /* We need to map to chars to ASCII before doing the tests
2035 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2036 if (!has_utf8 && uv > 255) {
2037 /* Might need to recode whatever we have
2038 * accumulated so far if it contains any
2041 * (Can't we keep track of that and avoid
2042 * this rescan? --jhi)
2046 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2047 if (!NATIVE_IS_INVARIANT(*c)) {
2052 const STRLEN offset = d - SvPVX_const(sv);
2054 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2058 while (src >= (const U8 *)SvPVX_const(sv)) {
2059 if (!NATIVE_IS_INVARIANT(*src)) {
2060 const U8 ch = NATIVE_TO_ASCII(*src);
2061 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2062 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2072 if (has_utf8 || uv > 255) {
2073 d = (char*)uvchr_to_utf8((U8*)d, uv);
2075 if (PL_lex_inwhat == OP_TRANS &&
2076 PL_sublex_info.sub_op) {
2077 PL_sublex_info.sub_op->op_private |=
2078 (PL_lex_repl ? OPpTRANS_FROM_UTF
2091 /* \N{LATIN SMALL LETTER A} is a named character */
2095 char* e = strchr(s, '}');
2101 yyerror("Missing right brace on \\N{}");
2105 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2107 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2108 PERL_SCAN_DISALLOW_PREFIX;
2111 uv = grok_hex(s, &len, &flags, NULL);
2113 goto NUM_ESCAPE_INSERT;
2115 res = newSVpvn(s + 1, e - s - 1);
2116 res = new_constant( NULL, 0, "charnames",
2117 res, NULL, "\\N{...}" );
2119 sv_utf8_upgrade(res);
2120 str = SvPV_const(res,len);
2121 #ifdef EBCDIC_NEVER_MIND
2122 /* charnames uses pack U and that has been
2123 * recently changed to do the below uni->native
2124 * mapping, so this would be redundant (and wrong,
2125 * the code point would be doubly converted).
2126 * But leave this in just in case the pack U change
2127 * gets revoked, but the semantics is still
2128 * desireable for charnames. --jhi */
2130 UV uv = utf8_to_uvchr((const U8*)str, 0);
2133 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2135 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2136 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2137 str = SvPV_const(res, len);
2141 if (!has_utf8 && SvUTF8(res)) {
2142 const char * const ostart = SvPVX_const(sv);
2143 SvCUR_set(sv, d - ostart);
2146 sv_utf8_upgrade(sv);
2147 /* this just broke our allocation above... */
2148 SvGROW(sv, (STRLEN)(send - start));
2149 d = SvPVX(sv) + SvCUR(sv);
2152 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2153 const char * const odest = SvPVX_const(sv);
2155 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2156 d = SvPVX(sv) + (d - odest);
2158 Copy(str, d, len, char);
2165 yyerror("Missing braces on \\N{}");
2168 /* \c is a control character */
2177 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2180 yyerror("Missing control char name in \\c");
2184 /* printf-style backslashes, formfeeds, newlines, etc */
2186 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2189 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2192 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2195 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2198 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2201 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2204 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2210 } /* end if (backslash) */
2217 /* If we started with encoded form, or already know we want it
2218 and then encode the next character */
2219 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2221 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2222 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2225 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2226 const STRLEN off = d - SvPVX_const(sv);
2227 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2229 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2233 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2235 } /* while loop to process each character */
2237 /* terminate the string and set up the sv */
2239 SvCUR_set(sv, d - SvPVX_const(sv));
2240 if (SvCUR(sv) >= SvLEN(sv))
2241 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2244 if (PL_encoding && !has_utf8) {
2245 sv_recode_to_utf8(sv, PL_encoding);
2251 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2252 PL_sublex_info.sub_op->op_private |=
2253 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2257 /* shrink the sv if we allocated more than we used */
2258 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2259 SvPV_shrink_to_cur(sv);
2262 /* return the substring (via yylval) only if we parsed anything */
2263 if (s > PL_bufptr) {
2264 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
2265 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
2267 ( PL_lex_inwhat == OP_TRANS
2269 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2272 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2279 * Returns TRUE if there's more to the expression (e.g., a subscript),
2282 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2284 * ->[ and ->{ return TRUE
2285 * { and [ outside a pattern are always subscripts, so return TRUE
2286 * if we're outside a pattern and it's not { or [, then return FALSE
2287 * if we're in a pattern and the first char is a {
2288 * {4,5} (any digits around the comma) returns FALSE
2289 * if we're in a pattern and the first char is a [
2291 * [SOMETHING] has a funky algorithm to decide whether it's a
2292 * character class or not. It has to deal with things like
2293 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2294 * anything else returns TRUE
2297 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2300 S_intuit_more(pTHX_ register char *s)
2303 if (PL_lex_brackets)
2305 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2307 if (*s != '{' && *s != '[')
2312 /* In a pattern, so maybe we have {n,m}. */
2329 /* On the other hand, maybe we have a character class */
2332 if (*s == ']' || *s == '^')
2335 /* this is terrifying, and it works */
2336 int weight = 2; /* let's weigh the evidence */
2338 unsigned char un_char = 255, last_un_char;
2339 const char * const send = strchr(s,']');
2340 char tmpbuf[sizeof PL_tokenbuf * 4];
2342 if (!send) /* has to be an expression */
2345 Zero(seen,256,char);
2348 else if (isDIGIT(*s)) {
2350 if (isDIGIT(s[1]) && s[2] == ']')
2356 for (; s < send; s++) {
2357 last_un_char = un_char;
2358 un_char = (unsigned char)*s;
2363 weight -= seen[un_char] * 10;
2364 if (isALNUM_lazy_if(s+1,UTF)) {
2366 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2367 len = (int)strlen(tmpbuf);
2368 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2373 else if (*s == '$' && s[1] &&
2374 strchr("[#!%*<>()-=",s[1])) {
2375 if (/*{*/ strchr("])} =",s[2]))
2384 if (strchr("wds]",s[1]))
2386 else if (seen['\''] || seen['"'])
2388 else if (strchr("rnftbxcav",s[1]))
2390 else if (isDIGIT(s[1])) {
2392 while (s[1] && isDIGIT(s[1]))
2402 if (strchr("aA01! ",last_un_char))
2404 if (strchr("zZ79~",s[1]))
2406 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2407 weight -= 5; /* cope with negative subscript */
2410 if (!isALNUM(last_un_char)
2411 && !(last_un_char == '$' || last_un_char == '@'
2412 || last_un_char == '&')
2413 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2418 if (keyword(tmpbuf, d - tmpbuf))
2421 if (un_char == last_un_char + 1)
2423 weight -= seen[un_char];
2428 if (weight >= 0) /* probably a character class */
2438 * Does all the checking to disambiguate
2440 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2441 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2443 * First argument is the stuff after the first token, e.g. "bar".
2445 * Not a method if bar is a filehandle.
2446 * Not a method if foo is a subroutine prototyped to take a filehandle.
2447 * Not a method if it's really "Foo $bar"
2448 * Method if it's "foo $bar"
2449 * Not a method if it's really "print foo $bar"
2450 * Method if it's really "foo package::" (interpreted as package->foo)
2451 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2452 * Not a method if bar is a filehandle or package, but is quoted with
2457 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2460 char *s = start + (*start == '$');
2461 char tmpbuf[sizeof PL_tokenbuf];
2469 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2473 const char *proto = SvPVX_const(cv);
2484 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2485 /* start is the beginning of the possible filehandle/object,
2486 * and s is the end of it
2487 * tmpbuf is a copy of it
2490 if (*start == '$') {
2491 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2494 len = start - SvPVX(PL_linestr);
2498 start = SvPVX(PL_linestr) + len;
2502 return *s == '(' ? FUNCMETH : METHOD;
2504 if (!keyword(tmpbuf, len)) {
2505 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2509 soff = s - SvPVX(PL_linestr);
2513 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2514 if (indirgv && GvCVu(indirgv))
2516 /* filehandle or package name makes it a method */
2517 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2519 soff = s - SvPVX(PL_linestr);
2522 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2523 return 0; /* no assumptions -- "=>" quotes bearword */
2525 start_force(PL_curforce);
2526 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2527 newSVpvn(tmpbuf,len));
2528 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2530 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2535 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2537 return *s == '(' ? FUNCMETH : METHOD;
2545 * Return a string of Perl code to load the debugger. If PERL5DB
2546 * is set, it will return the contents of that, otherwise a
2547 * compile-time require of perl5db.pl.
2555 const char * const pdb = PerlEnv_getenv("PERL5DB");
2559 SETERRNO(0,SS_NORMAL);
2560 return "BEGIN { require 'perl5db.pl' }";
2566 /* Encoded script support. filter_add() effectively inserts a
2567 * 'pre-processing' function into the current source input stream.
2568 * Note that the filter function only applies to the current source file
2569 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2571 * The datasv parameter (which may be NULL) can be used to pass
2572 * private data to this instance of the filter. The filter function
2573 * can recover the SV using the FILTER_DATA macro and use it to
2574 * store private buffers and state information.
2576 * The supplied datasv parameter is upgraded to a PVIO type
2577 * and the IoDIRP/IoANY field is used to store the function pointer,
2578 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2579 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2580 * private use must be set using malloc'd pointers.
2584 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2590 if (!PL_rsfp_filters)
2591 PL_rsfp_filters = newAV();
2594 SvUPGRADE(datasv, SVt_PVIO);
2595 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2596 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2597 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2598 FPTR2DPTR(void *, IoANY(datasv)),
2599 SvPV_nolen(datasv)));
2600 av_unshift(PL_rsfp_filters, 1);
2601 av_store(PL_rsfp_filters, 0, datasv) ;
2606 /* Delete most recently added instance of this filter function. */
2608 Perl_filter_del(pTHX_ filter_t funcp)
2614 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2615 FPTR2DPTR(void*, funcp)));
2617 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2619 /* if filter is on top of stack (usual case) just pop it off */
2620 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2621 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2622 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2623 IoANY(datasv) = (void *)NULL;
2624 sv_free(av_pop(PL_rsfp_filters));
2628 /* we need to search for the correct entry and clear it */
2629 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2633 /* Invoke the idxth filter function for the current rsfp. */
2634 /* maxlen 0 = read one text line */
2636 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2641 /* This API is bad. It should have been using unsigned int for maxlen.
2642 Not sure if we want to change the API, but if not we should sanity
2643 check the value here. */
2644 const unsigned int correct_length
2653 if (!PL_rsfp_filters)
2655 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2656 /* Provide a default input filter to make life easy. */
2657 /* Note that we append to the line. This is handy. */
2658 DEBUG_P(PerlIO_printf(Perl_debug_log,
2659 "filter_read %d: from rsfp\n", idx));
2660 if (correct_length) {
2663 const int old_len = SvCUR(buf_sv);
2665 /* ensure buf_sv is large enough */
2666 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2667 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2668 correct_length)) <= 0) {
2669 if (PerlIO_error(PL_rsfp))
2670 return -1; /* error */
2672 return 0 ; /* end of file */
2674 SvCUR_set(buf_sv, old_len + len) ;
2677 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2678 if (PerlIO_error(PL_rsfp))
2679 return -1; /* error */
2681 return 0 ; /* end of file */
2684 return SvCUR(buf_sv);
2686 /* Skip this filter slot if filter has been deleted */
2687 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2688 DEBUG_P(PerlIO_printf(Perl_debug_log,
2689 "filter_read %d: skipped (filter deleted)\n",
2691 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2693 /* Get function pointer hidden within datasv */
2694 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2695 DEBUG_P(PerlIO_printf(Perl_debug_log,
2696 "filter_read %d: via function %p (%s)\n",
2697 idx, (void*)datasv, SvPV_nolen_const(datasv)));
2698 /* Call function. The function is expected to */
2699 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2700 /* Return: <0:error, =0:eof, >0:not eof */
2701 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2705 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2708 #ifdef PERL_CR_FILTER
2709 if (!PL_rsfp_filters) {
2710 filter_add(S_cr_textfilter,NULL);
2713 if (PL_rsfp_filters) {
2715 SvCUR_set(sv, 0); /* start with empty line */
2716 if (FILTER_READ(0, sv, 0) > 0)
2717 return ( SvPVX(sv) ) ;
2722 return (sv_gets(sv, fp, append));
2726 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2731 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2735 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2736 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2738 return GvHV(gv); /* Foo:: */
2741 /* use constant CLASS => 'MyClass' */
2742 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
2743 if (gv && GvCV(gv)) {
2744 SV * const sv = cv_const_sv(GvCV(gv));
2746 pkgname = SvPV_nolen_const(sv);
2749 return gv_stashpv(pkgname, FALSE);
2755 * The intent of this yylex wrapper is to minimize the changes to the
2756 * tokener when we aren't interested in collecting madprops. It remains
2757 * to be seen how successful this strategy will be...
2764 char *s = PL_bufptr;
2766 /* make sure PL_thiswhite is initialized */
2770 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
2771 if (PL_pending_ident)
2772 return S_pending_ident(aTHX);
2774 /* previous token ate up our whitespace? */
2775 if (!PL_lasttoke && PL_nextwhite) {
2776 PL_thiswhite = PL_nextwhite;
2780 /* isolate the token, and figure out where it is without whitespace */
2781 PL_realtokenstart = -1;
2785 assert(PL_curforce < 0);
2787 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
2788 if (!PL_thistoken) {
2789 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
2790 PL_thistoken = newSVpvn("",0);
2792 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
2793 PL_thistoken = newSVpvn(tstart, s - tstart);
2796 if (PL_thismad) /* install head */
2797 CURMAD('X', PL_thistoken);
2800 /* last whitespace of a sublex? */
2801 if (optype == ')' && PL_endwhite) {
2802 CURMAD('X', PL_endwhite);
2807 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
2808 if (!PL_thiswhite && !PL_endwhite && !optype) {
2809 sv_free(PL_thistoken);
2814 /* put off final whitespace till peg */
2815 if (optype == ';' && !PL_rsfp) {
2816 PL_nextwhite = PL_thiswhite;
2819 else if (PL_thisopen) {
2820 CURMAD('q', PL_thisopen);
2822 sv_free(PL_thistoken);
2826 /* Store actual token text as madprop X */
2827 CURMAD('X', PL_thistoken);
2831 /* add preceding whitespace as madprop _ */
2832 CURMAD('_', PL_thiswhite);
2836 /* add quoted material as madprop = */
2837 CURMAD('=', PL_thisstuff);
2841 /* add terminating quote as madprop Q */
2842 CURMAD('Q', PL_thisclose);
2846 /* special processing based on optype */
2850 /* opval doesn't need a TOKEN since it can already store mp */
2861 append_madprops(PL_thismad, yylval.opval, 0);
2869 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
2878 /* remember any fake bracket that lexer is about to discard */
2879 if (PL_lex_brackets == 1 &&
2880 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
2883 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2886 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
2887 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
2890 break; /* don't bother looking for trailing comment */
2899 /* attach a trailing comment to its statement instead of next token */
2903 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
2905 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2907 if (*s == '\n' || *s == '#') {
2908 while (s < PL_bufend && *s != '\n')
2912 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
2913 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
2930 /* Create new token struct. Note: opvals return early above. */
2931 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
2938 S_tokenize_use(pTHX_ int is_use, char *s) {
2940 if (PL_expect != XSTATE)
2941 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
2942 is_use ? "use" : "no"));
2944 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
2945 s = force_version(s, TRUE);
2946 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
2947 start_force(PL_curforce);
2948 NEXTVAL_NEXTTOKE.opval = NULL;
2951 else if (*s == 'v') {
2952 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2953 s = force_version(s, FALSE);
2957 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2958 s = force_version(s, FALSE);
2960 yylval.ival = is_use;
2964 static const char* const exp_name[] =
2965 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2966 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
2973 Works out what to call the token just pulled out of the input
2974 stream. The yacc parser takes care of taking the ops we return and
2975 stitching them into a tree.
2981 if read an identifier
2982 if we're in a my declaration
2983 croak if they tried to say my($foo::bar)
2984 build the ops for a my() declaration
2985 if it's an access to a my() variable
2986 are we in a sort block?
2987 croak if my($a); $a <=> $b
2988 build ops for access to a my() variable
2989 if in a dq string, and they've said @foo and we can't find @foo
2991 build ops for a bareword
2992 if we already built the token before, use it.
2997 #pragma segment Perl_yylex
3003 register char *s = PL_bufptr;
3009 SV* tmp = newSVpvs("");
3010 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3011 (IV)CopLINE(PL_curcop),
3012 lex_state_names[PL_lex_state],
3013 exp_name[PL_expect],
3014 pv_display(tmp, s, strlen(s), 0, 60));
3017 /* check if there's an identifier for us to look at */
3018 if (PL_pending_ident)
3019 return REPORT(S_pending_ident(aTHX));
3021 /* no identifier pending identification */
3023 switch (PL_lex_state) {
3025 case LEX_NORMAL: /* Some compilers will produce faster */
3026 case LEX_INTERPNORMAL: /* code if we comment these out. */
3030 /* when we've already built the next token, just pull it out of the queue */
3034 yylval = PL_nexttoke[PL_lasttoke].next_val;
3036 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3037 PL_nexttoke[PL_lasttoke].next_mad = 0;
3038 if (PL_thismad && PL_thismad->mad_key == '_') {
3039 PL_thiswhite = (SV*)PL_thismad->mad_val;
3040 PL_thismad->mad_val = 0;
3041 mad_free(PL_thismad);
3046 PL_lex_state = PL_lex_defer;
3047 PL_expect = PL_lex_expect;
3048 PL_lex_defer = LEX_NORMAL;
3049 if (!PL_nexttoke[PL_lasttoke].next_type)
3054 yylval = PL_nextval[PL_nexttoke];
3056 PL_lex_state = PL_lex_defer;
3057 PL_expect = PL_lex_expect;
3058 PL_lex_defer = LEX_NORMAL;
3062 /* FIXME - can these be merged? */
3063 return(PL_nexttoke[PL_lasttoke].next_type);
3065 return REPORT(PL_nexttype[PL_nexttoke]);
3068 /* interpolated case modifiers like \L \U, including \Q and \E.
3069 when we get here, PL_bufptr is at the \
3071 case LEX_INTERPCASEMOD:
3073 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3074 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3076 /* handle \E or end of string */
3077 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3079 if (PL_lex_casemods) {
3080 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3081 PL_lex_casestack[PL_lex_casemods] = '\0';
3083 if (PL_bufptr != PL_bufend
3084 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3086 PL_lex_state = LEX_INTERPCONCAT;
3089 PL_thistoken = newSVpvn("\\E",2);
3095 while (PL_bufptr != PL_bufend &&
3096 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3098 PL_thiswhite = newSVpvn("",0);
3099 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3103 if (PL_bufptr != PL_bufend)
3106 PL_lex_state = LEX_INTERPCONCAT;
3110 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3111 "### Saw case modifier\n"); });
3113 if (s[1] == '\\' && s[2] == 'E') {
3116 PL_thiswhite = newSVpvn("",0);
3117 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3120 PL_lex_state = LEX_INTERPCONCAT;
3125 if (!PL_madskills) /* when just compiling don't need correct */
3126 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3127 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3128 if ((*s == 'L' || *s == 'U') &&
3129 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3130 PL_lex_casestack[--PL_lex_casemods] = '\0';
3133 if (PL_lex_casemods > 10)
3134 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3135 PL_lex_casestack[PL_lex_casemods++] = *s;
3136 PL_lex_casestack[PL_lex_casemods] = '\0';
3137 PL_lex_state = LEX_INTERPCONCAT;
3138 start_force(PL_curforce);
3139 NEXTVAL_NEXTTOKE.ival = 0;
3141 start_force(PL_curforce);
3143 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3145 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3147 NEXTVAL_NEXTTOKE.ival = OP_LC;
3149 NEXTVAL_NEXTTOKE.ival = OP_UC;
3151 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3153 Perl_croak(aTHX_ "panic: yylex");
3155 SV* const tmpsv = newSVpvn("",0);
3156 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3162 if (PL_lex_starts) {
3168 sv_free(PL_thistoken);
3169 PL_thistoken = newSVpvn("",0);
3172 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3173 if (PL_lex_casemods == 1 && PL_lex_inpat)
3182 case LEX_INTERPPUSH:
3183 return REPORT(sublex_push());
3185 case LEX_INTERPSTART:
3186 if (PL_bufptr == PL_bufend)
3187 return REPORT(sublex_done());
3188 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3189 "### Interpolated variable\n"); });
3191 PL_lex_dojoin = (*PL_bufptr == '@');
3192 PL_lex_state = LEX_INTERPNORMAL;
3193 if (PL_lex_dojoin) {
3194 start_force(PL_curforce);
3195 NEXTVAL_NEXTTOKE.ival = 0;
3197 start_force(PL_curforce);
3198 force_ident("\"", '$');
3199 start_force(PL_curforce);
3200 NEXTVAL_NEXTTOKE.ival = 0;
3202 start_force(PL_curforce);
3203 NEXTVAL_NEXTTOKE.ival = 0;
3205 start_force(PL_curforce);
3206 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3209 if (PL_lex_starts++) {
3214 sv_free(PL_thistoken);
3215 PL_thistoken = newSVpvn("",0);
3218 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3219 if (!PL_lex_casemods && PL_lex_inpat)
3226 case LEX_INTERPENDMAYBE:
3227 if (intuit_more(PL_bufptr)) {
3228 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3234 if (PL_lex_dojoin) {
3235 PL_lex_dojoin = FALSE;
3236 PL_lex_state = LEX_INTERPCONCAT;
3240 sv_free(PL_thistoken);
3241 PL_thistoken = newSVpvn("",0);
3246 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3247 && SvEVALED(PL_lex_repl))
3249 if (PL_bufptr != PL_bufend)
3250 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3254 case LEX_INTERPCONCAT:
3256 if (PL_lex_brackets)
3257 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3259 if (PL_bufptr == PL_bufend)
3260 return REPORT(sublex_done());
3262 if (SvIVX(PL_linestr) == '\'') {
3263 SV *sv = newSVsv(PL_linestr);
3266 else if ( PL_hints & HINT_NEW_RE )
3267 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
3268 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3272 s = scan_const(PL_bufptr);
3274 PL_lex_state = LEX_INTERPCASEMOD;
3276 PL_lex_state = LEX_INTERPSTART;
3279 if (s != PL_bufptr) {
3280 start_force(PL_curforce);
3282 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3284 NEXTVAL_NEXTTOKE = yylval;
3287 if (PL_lex_starts++) {
3291 sv_free(PL_thistoken);
3292 PL_thistoken = newSVpvn("",0);
3295 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3296 if (!PL_lex_casemods && PL_lex_inpat)
3309 PL_lex_state = LEX_NORMAL;
3310 s = scan_formline(PL_bufptr);
3311 if (!PL_lex_formbrack)
3317 PL_oldoldbufptr = PL_oldbufptr;
3323 sv_free(PL_thistoken);
3326 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3330 if (isIDFIRST_lazy_if(s,UTF))
3332 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
3335 goto fake_eof; /* emulate EOF on ^D or ^Z */
3344 if (PL_lex_brackets) {
3345 yyerror(PL_lex_formbrack
3346 ? "Format not terminated"
3347 : "Missing right curly or square bracket");
3349 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3350 "### Tokener got EOF\n");
3354 if (s++ < PL_bufend)
3355 goto retry; /* ignore stray nulls */
3358 if (!PL_in_eval && !PL_preambled) {
3359 PL_preambled = TRUE;
3364 sv_setpv(PL_linestr,incl_perldb());
3365 if (SvCUR(PL_linestr))
3366 sv_catpvs(PL_linestr,";");
3368 while(AvFILLp(PL_preambleav) >= 0) {
3369 SV *tmpsv = av_shift(PL_preambleav);
3370 sv_catsv(PL_linestr, tmpsv);
3371 sv_catpvs(PL_linestr, ";");
3374 sv_free((SV*)PL_preambleav);
3375 PL_preambleav = NULL;
3377 if (PL_minus_n || PL_minus_p) {
3378 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3380 sv_catpvs(PL_linestr,"chomp;");
3383 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3384 || *PL_splitstr == '"')
3385 && strchr(PL_splitstr + 1, *PL_splitstr))
3386 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3388 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3389 bytes can be used as quoting characters. :-) */
3390 const char *splits = PL_splitstr;
3391 sv_catpvs(PL_linestr, "our @F=split(q\0");
3394 if (*splits == '\\')
3395 sv_catpvn(PL_linestr, splits, 1);
3396 sv_catpvn(PL_linestr, splits, 1);
3397 } while (*splits++);
3398 /* This loop will embed the trailing NUL of
3399 PL_linestr as the last thing it does before
3401 sv_catpvs(PL_linestr, ");");
3405 sv_catpvs(PL_linestr,"our @F=split(' ');");
3409 sv_catpvs(PL_linestr,"use feature ':5.10';");
3410 sv_catpvs(PL_linestr, "\n");
3411 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3412 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3413 PL_last_lop = PL_last_uni = NULL;
3414 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3415 SV * const sv = newSV(0);
3417 sv_upgrade(sv, SVt_PVMG);
3418 sv_setsv(sv,PL_linestr);
3421 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
3426 bof = PL_rsfp ? TRUE : FALSE;
3427 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3430 PL_realtokenstart = -1;
3433 if (PL_preprocess && !PL_in_eval)
3434 (void)PerlProc_pclose(PL_rsfp);
3435 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3436 PerlIO_clearerr(PL_rsfp);
3438 (void)PerlIO_close(PL_rsfp);
3440 PL_doextract = FALSE;
3442 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3447 sv_setpv(PL_linestr,PL_minus_p
3448 ? ";}continue{print;}" : ";}");
3449 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3450 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3451 PL_last_lop = PL_last_uni = NULL;
3452 PL_minus_n = PL_minus_p = 0;
3455 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3456 PL_last_lop = PL_last_uni = NULL;
3457 sv_setpvn(PL_linestr,"",0);
3458 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3460 /* If it looks like the start of a BOM or raw UTF-16,
3461 * check if it in fact is. */
3467 #ifdef PERLIO_IS_STDIO
3468 # ifdef __GNU_LIBRARY__
3469 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3470 # define FTELL_FOR_PIPE_IS_BROKEN
3474 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3475 # define FTELL_FOR_PIPE_IS_BROKEN
3480 #ifdef FTELL_FOR_PIPE_IS_BROKEN
3481 /* This loses the possibility to detect the bof
3482 * situation on perl -P when the libc5 is being used.
3483 * Workaround? Maybe attach some extra state to PL_rsfp?
3486 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
3488 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3491 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3492 s = swallow_bom((U8*)s);
3496 /* Incest with pod. */
3499 sv_catsv(PL_thiswhite, PL_linestr);
3501 if (*s == '=' && strnEQ(s, "=cut", 4)) {
3502 sv_setpvn(PL_linestr, "", 0);
3503 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3504 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3505 PL_last_lop = PL_last_uni = NULL;
3506 PL_doextract = FALSE;
3510 } while (PL_doextract);
3511 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3512 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3513 SV * const sv = newSV(0);
3515 sv_upgrade(sv, SVt_PVMG);
3516 sv_setsv(sv,PL_linestr);
3519 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
3521 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3522 PL_last_lop = PL_last_uni = NULL;
3523 if (CopLINE(PL_curcop) == 1) {
3524 while (s < PL_bufend && isSPACE(*s))
3526 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3530 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3534 if (*s == '#' && *(s+1) == '!')
3536 #ifdef ALTERNATE_SHEBANG
3538 static char const as[] = ALTERNATE_SHEBANG;
3539 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3540 d = s + (sizeof(as) - 1);
3542 #endif /* ALTERNATE_SHEBANG */
3551 while (*d && !isSPACE(*d))
3555 #ifdef ARG_ZERO_IS_SCRIPT
3556 if (ipathend > ipath) {
3558 * HP-UX (at least) sets argv[0] to the script name,
3559 * which makes $^X incorrect. And Digital UNIX and Linux,
3560 * at least, set argv[0] to the basename of the Perl
3561 * interpreter. So, having found "#!", we'll set it right.
3563 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3565 assert(SvPOK(x) || SvGMAGICAL(x));
3566 if (sv_eq(x, CopFILESV(PL_curcop))) {
3567 sv_setpvn(x, ipath, ipathend - ipath);
3573 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3574 const char * const lstart = SvPV_const(x,llen);
3576 bstart += blen - llen;
3577 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3578 sv_setpvn(x, ipath, ipathend - ipath);
3583 TAINT_NOT; /* $^X is always tainted, but that's OK */
3585 #endif /* ARG_ZERO_IS_SCRIPT */
3590 d = instr(s,"perl -");
3592 d = instr(s,"perl");
3594 /* avoid getting into infinite loops when shebang
3595 * line contains "Perl" rather than "perl" */
3597 for (d = ipathend-4; d >= ipath; --d) {
3598 if ((*d == 'p' || *d == 'P')
3599 && !ibcmp(d, "perl", 4))
3609 #ifdef ALTERNATE_SHEBANG
3611 * If the ALTERNATE_SHEBANG on this system starts with a
3612 * character that can be part of a Perl expression, then if
3613 * we see it but not "perl", we're probably looking at the
3614 * start of Perl code, not a request to hand off to some
3615 * other interpreter. Similarly, if "perl" is there, but
3616 * not in the first 'word' of the line, we assume the line
3617 * contains the start of the Perl program.
3619 if (d && *s != '#') {
3620 const char *c = ipath;
3621 while (*c && !strchr("; \t\r\n\f\v#", *c))
3624 d = NULL; /* "perl" not in first word; ignore */
3626 *s = '#'; /* Don't try to parse shebang line */
3628 #endif /* ALTERNATE_SHEBANG */
3629 #ifndef MACOS_TRADITIONAL
3634 !instr(s,"indir") &&
3635 instr(PL_origargv[0],"perl"))
3642 while (s < PL_bufend && isSPACE(*s))
3644 if (s < PL_bufend) {
3645 Newxz(newargv,PL_origargc+3,char*);
3647 while (s < PL_bufend && !isSPACE(*s))
3650 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3653 newargv = PL_origargv;
3656 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3658 Perl_croak(aTHX_ "Can't exec %s", ipath);
3662 while (*d && !isSPACE(*d))
3664 while (SPACE_OR_TAB(*d))
3668 const bool switches_done = PL_doswitches;
3669 const U32 oldpdb = PL_perldb;
3670 const bool oldn = PL_minus_n;
3671 const bool oldp = PL_minus_p;
3674 if (*d == 'M' || *d == 'm' || *d == 'C') {
3675 const char * const m = d;
3676 while (*d && !isSPACE(*d))
3678 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3681 d = moreswitches(d);
3683 if (PL_doswitches && !switches_done) {
3684 int argc = PL_origargc;
3685 char **argv = PL_origargv;
3688 } while (argc && argv[0][0] == '-' && argv[0][1]);
3689 init_argv_symbols(argc,argv);
3691 if ((PERLDB_LINE && !oldpdb) ||
3692 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3693 /* if we have already added "LINE: while (<>) {",
3694 we must not do it again */
3696 sv_setpvn(PL_linestr, "", 0);
3697 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3698 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3699 PL_last_lop = PL_last_uni = NULL;
3700 PL_preambled = FALSE;
3702 (void)gv_fetchfile(PL_origfilename);
3709 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3711 PL_lex_state = LEX_FORMLINE;
3716 #ifdef PERL_STRICT_CR
3717 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3719 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3721 case ' ': case '\t': case '\f': case 013:
3722 #ifdef MACOS_TRADITIONAL
3726 PL_realtokenstart = -1;
3735 PL_realtokenstart = -1;
3739 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3740 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3741 /* handle eval qq[#line 1 "foo"\n ...] */
3742 CopLINE_dec(PL_curcop);
3745 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3747 if (!PL_in_eval || PL_rsfp)
3752 while (d < PL_bufend && *d != '\n')
3756 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3757 Perl_croak(aTHX_ "panic: input overflow");
3760 PL_thiswhite = newSVpvn(s, d - s);
3765 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3767 PL_lex_state = LEX_FORMLINE;
3773 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3774 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3777 TOKEN(PEG); /* make sure any #! line is accessible */
3782 /* if (PL_madskills && PL_lex_formbrack) { */
3784 while (d < PL_bufend && *d != '\n')
3788 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3789 Perl_croak(aTHX_ "panic: input overflow");
3790 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
3792 PL_thiswhite = newSVpvn("",0);
3793 if (CopLINE(PL_curcop) == 1) {
3794 sv_setpvn(PL_thiswhite, "", 0);
3797 sv_catpvn(PL_thiswhite, s, d - s);
3811 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
3819 while (s < PL_bufend && SPACE_OR_TAB(*s))
3822 if (strnEQ(s,"=>",2)) {
3823 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
3824 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
3825 OPERATOR('-'); /* unary minus */
3827 PL_last_uni = PL_oldbufptr;
3829 case 'r': ftst = OP_FTEREAD; break;
3830 case 'w': ftst = OP_FTEWRITE; break;
3831 case 'x': ftst = OP_FTEEXEC; break;
3832 case 'o': ftst = OP_FTEOWNED; break;
3833 case 'R': ftst = OP_FTRREAD; break;
3834 case 'W': ftst = OP_FTRWRITE; break;
3835 case 'X': ftst = OP_FTREXEC; break;
3836 case 'O': ftst = OP_FTROWNED; break;
3837 case 'e': ftst = OP_FTIS; break;
3838 case 'z': ftst = OP_FTZERO; break;
3839 case 's': ftst = OP_FTSIZE; break;
3840 case 'f': ftst = OP_FTFILE; break;
3841 case 'd': ftst = OP_FTDIR; break;
3842 case 'l': ftst = OP_FTLINK; break;
3843 case 'p': ftst = OP_FTPIPE; break;
3844 case 'S': ftst = OP_FTSOCK; break;
3845 case 'u': ftst = OP_FTSUID; break;
3846 case 'g': ftst = OP_FTSGID; break;
3847 case 'k': ftst = OP_FTSVTX; break;
3848 case 'b': ftst = OP_FTBLK; break;
3849 case 'c': ftst = OP_FTCHR; break;
3850 case 't': ftst = OP_FTTTY; break;
3851 case 'T': ftst = OP_FTTEXT; break;
3852 case 'B': ftst = OP_FTBINARY; break;
3853 case 'M': case 'A': case 'C':
3854 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
3856 case 'M': ftst = OP_FTMTIME; break;
3857 case 'A': ftst = OP_FTATIME; break;
3858 case 'C': ftst = OP_FTCTIME; break;
3866 PL_last_lop_op = (OPCODE)ftst;
3867 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3868 "### Saw file test %c\n", (int)tmp);
3873 /* Assume it was a minus followed by a one-letter named
3874 * subroutine call (or a -bareword), then. */
3875 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3876 "### '-%c' looked like a file test but was not\n",
3883 const char tmp = *s++;
3886 if (PL_expect == XOPERATOR)
3891 else if (*s == '>') {
3894 if (isIDFIRST_lazy_if(s,UTF)) {
3895 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
3903 if (PL_expect == XOPERATOR)
3906 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3908 OPERATOR('-'); /* unary minus */
3914 const char tmp = *s++;
3917 if (PL_expect == XOPERATOR)
3922 if (PL_expect == XOPERATOR)
3925 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3932 if (PL_expect != XOPERATOR) {
3933 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3934 PL_expect = XOPERATOR;
3935 force_ident(PL_tokenbuf, '*');
3948 if (PL_expect == XOPERATOR) {
3952 PL_tokenbuf[0] = '%';
3953 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
3954 if (!PL_tokenbuf[1]) {
3957 PL_pending_ident = '%';
3968 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)
3969 && FEATURE_IS_ENABLED("~~"))
3976 const char tmp = *s++;
3982 goto just_a_word_zero_gv;
3985 switch (PL_expect) {
3991 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
3993 PL_bufptr = s; /* update in case we back off */
3999 PL_expect = XTERMBLOCK;
4002 stuffstart = s - SvPVX(PL_linestr) - 1;
4006 while (isIDFIRST_lazy_if(s,UTF)) {
4009 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4010 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
4011 if (tmp < 0) tmp = -tmp;
4026 sv = newSVpvn(s, len);
4028 d = scan_str(d,TRUE,TRUE);
4030 /* MUST advance bufptr here to avoid bogus
4031 "at end of line" context messages from yyerror().
4033 PL_bufptr = s + len;
4034 yyerror("Unterminated attribute parameter in attribute list");
4038 return REPORT(0); /* EOF indicator */
4042 sv_catsv(sv, PL_lex_stuff);
4043 attrs = append_elem(OP_LIST, attrs,
4044 newSVOP(OP_CONST, 0, sv));
4045 SvREFCNT_dec(PL_lex_stuff);
4046 PL_lex_stuff = NULL;
4049 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4051 if (PL_in_my == KEY_our) {
4053 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4055 /* skip to avoid loading attributes.pm */
4057 deprecate(":unique");
4060 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4063 /* NOTE: any CV attrs applied here need to be part of
4064 the CVf_BUILTIN_ATTRS define in cv.h! */
4065 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4067 CvLVALUE_on(PL_compcv);
4069 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4071 CvLOCKED_on(PL_compcv);
4073 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4075 CvMETHOD_on(PL_compcv);
4077 else if (!PL_in_my && len == 9 && strnEQ(SvPVX(sv), "assertion", len)) {
4079 CvASSERTION_on(PL_compcv);
4081 /* After we've set the flags, it could be argued that
4082 we don't need to do the attributes.pm-based setting
4083 process, and shouldn't bother appending recognized
4084 flags. To experiment with that, uncomment the
4085 following "else". (Note that's already been
4086 uncommented. That keeps the above-applied built-in
4087 attributes from being intercepted (and possibly
4088 rejected) by a package's attribute routines, but is
4089 justified by the performance win for the common case
4090 of applying only built-in attributes.) */
4092 attrs = append_elem(OP_LIST, attrs,
4093 newSVOP(OP_CONST, 0,
4097 if (*s == ':' && s[1] != ':')
4100 break; /* require real whitespace or :'s */
4101 /* XXX losing whitespace on sequential attributes here */
4105 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4106 if (*s != ';' && *s != '}' && *s != tmp
4107 && (tmp != '=' || *s != ')')) {
4108 const char q = ((*s == '\'') ? '"' : '\'');
4109 /* If here for an expression, and parsed no attrs, back
4111 if (tmp == '=' && !attrs) {
4115 /* MUST advance bufptr here to avoid bogus "at end of line"
4116 context messages from yyerror().
4120 ? Perl_form(aTHX_ "Invalid separator character "
4121 "%c%c%c in attribute list", q, *s, q)
4122 : "Unterminated attribute list" );
4130 start_force(PL_curforce);
4131 NEXTVAL_NEXTTOKE.opval = attrs;
4132 CURMAD('_', PL_nextwhite);
4137 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4138 (s - SvPVX(PL_linestr)) - stuffstart);
4146 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4147 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4155 const char tmp = *s++;
4160 const char tmp = *s++;
4168 if (PL_lex_brackets <= 0)
4169 yyerror("Unmatched right square bracket");
4172 if (PL_lex_state == LEX_INTERPNORMAL) {
4173 if (PL_lex_brackets == 0) {
4174 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4175 PL_lex_state = LEX_INTERPEND;
4182 if (PL_lex_brackets > 100) {
4183 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4185 switch (PL_expect) {
4187 if (PL_lex_formbrack) {
4191 if (PL_oldoldbufptr == PL_last_lop)
4192 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4194 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4195 OPERATOR(HASHBRACK);
4197 while (s < PL_bufend && SPACE_OR_TAB(*s))
4200 PL_tokenbuf[0] = '\0';
4201 if (d < PL_bufend && *d == '-') {
4202 PL_tokenbuf[0] = '-';
4204 while (d < PL_bufend && SPACE_OR_TAB(*d))
4207 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4208 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4210 while (d < PL_bufend && SPACE_OR_TAB(*d))
4213 const char minus = (PL_tokenbuf[0] == '-');
4214 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4222 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4227 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4232 if (PL_oldoldbufptr == PL_last_lop)
4233 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4235 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4238 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4240 /* This hack is to get the ${} in the message. */
4242 yyerror("syntax error");
4245 OPERATOR(HASHBRACK);
4247 /* This hack serves to disambiguate a pair of curlies
4248 * as being a block or an anon hash. Normally, expectation
4249 * determines that, but in cases where we're not in a
4250 * position to expect anything in particular (like inside
4251 * eval"") we have to resolve the ambiguity. This code
4252 * covers the case where the first term in the curlies is a
4253 * quoted string. Most other cases need to be explicitly
4254 * disambiguated by prepending a "+" before the opening
4255 * curly in order to force resolution as an anon hash.
4257 * XXX should probably propagate the outer expectation
4258 * into eval"" to rely less on this hack, but that could
4259 * potentially break current behavior of eval"".
4263 if (*s == '\'' || *s == '"' || *s == '`') {
4264 /* common case: get past first string, handling escapes */
4265 for (t++; t < PL_bufend && *t != *s;)
4266 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4270 else if (*s == 'q') {
4273 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4276 /* skip q//-like construct */
4278 char open, close, term;
4281 while (t < PL_bufend && isSPACE(*t))
4283 /* check for q => */
4284 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4285 OPERATOR(HASHBRACK);
4289 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4293 for (t++; t < PL_bufend; t++) {
4294 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4296 else if (*t == open)
4300 for (t++; t < PL_bufend; t++) {
4301 if (*t == '\\' && t+1 < PL_bufend)
4303 else if (*t == close && --brackets <= 0)
4305 else if (*t == open)
4312 /* skip plain q word */
4313 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4316 else if (isALNUM_lazy_if(t,UTF)) {
4318 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4321 while (t < PL_bufend && isSPACE(*t))
4323 /* if comma follows first term, call it an anon hash */
4324 /* XXX it could be a comma expression with loop modifiers */
4325 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4326 || (*t == '=' && t[1] == '>')))
4327 OPERATOR(HASHBRACK);
4328 if (PL_expect == XREF)
4331 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4337 yylval.ival = CopLINE(PL_curcop);
4338 if (isSPACE(*s) || *s == '#')
4339 PL_copline = NOLINE; /* invalidate current command line number */
4344 if (PL_lex_brackets <= 0)
4345 yyerror("Unmatched right curly bracket");
4347 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4348 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4349 PL_lex_formbrack = 0;
4350 if (PL_lex_state == LEX_INTERPNORMAL) {
4351 if (PL_lex_brackets == 0) {
4352 if (PL_expect & XFAKEBRACK) {
4353 PL_expect &= XENUMMASK;
4354 PL_lex_state = LEX_INTERPEND;
4359 PL_thiswhite = newSVpvn("",0);
4360 sv_catpvn(PL_thiswhite,"}",1);
4363 return yylex(); /* ignore fake brackets */
4365 if (*s == '-' && s[1] == '>')
4366 PL_lex_state = LEX_INTERPENDMAYBE;
4367 else if (*s != '[' && *s != '{')
4368 PL_lex_state = LEX_INTERPEND;
4371 if (PL_expect & XFAKEBRACK) {
4372 PL_expect &= XENUMMASK;
4374 return yylex(); /* ignore fake brackets */
4376 start_force(PL_curforce);
4378 curmad('X', newSVpvn(s-1,1));
4379 CURMAD('_', PL_thiswhite);
4384 PL_thistoken = newSVpvn("",0);
4392 if (PL_expect == XOPERATOR) {
4393 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4394 && isIDFIRST_lazy_if(s,UTF))
4396 CopLINE_dec(PL_curcop);
4397 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4398 CopLINE_inc(PL_curcop);
4403 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4405 PL_expect = XOPERATOR;
4406 force_ident(PL_tokenbuf, '&');
4410 yylval.ival = (OPpENTERSUB_AMPER<<8);
4422 const char tmp = *s++;
4429 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4430 && strchr("+-*/%.^&|<",tmp))
4431 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4432 "Reversed %c= operator",(int)tmp);
4434 if (PL_expect == XSTATE && isALPHA(tmp) &&
4435 (s == PL_linestart+1 || s[-2] == '\n') )
4437 if (PL_in_eval && !PL_rsfp) {
4442 if (strnEQ(s,"=cut",4)) {
4458 PL_thiswhite = newSVpvn("",0);
4459 sv_catpvn(PL_thiswhite, PL_linestart,
4460 PL_bufend - PL_linestart);
4464 PL_doextract = TRUE;
4468 if (PL_lex_brackets < PL_lex_formbrack) {
4470 #ifdef PERL_STRICT_CR
4471 while (SPACE_OR_TAB(*t))
4473 while (SPACE_OR_TAB(*t) || *t == '\r')
4476 if (*t == '\n' || *t == '#') {
4487 const char tmp = *s++;
4489 /* was this !=~ where !~ was meant?
4490 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4492 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4493 const char *t = s+1;
4495 while (t < PL_bufend && isSPACE(*t))
4498 if (*t == '/' || *t == '?' ||
4499 ((*t == 'm' || *t == 's' || *t == 'y')
4500 && !isALNUM(t[1])) ||
4501 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4502 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4503 "!=~ should be !~");
4513 if (PL_expect != XOPERATOR) {
4514 if (s[1] != '<' && !strchr(s,'>'))
4517 s = scan_heredoc(s);
4519 s = scan_inputsymbol(s);
4520 TERM(sublex_start());
4526 SHop(OP_LEFT_SHIFT);
4540 const char tmp = *s++;
4542 SHop(OP_RIGHT_SHIFT);
4543 else if (tmp == '=')
4552 if (PL_expect == XOPERATOR) {
4553 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4555 deprecate_old(commaless_variable_list);
4556 return REPORT(','); /* grandfather non-comma-format format */
4560 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4561 PL_tokenbuf[0] = '@';
4562 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4563 sizeof PL_tokenbuf - 1, FALSE);
4564 if (PL_expect == XOPERATOR)
4565 no_op("Array length", s);
4566 if (!PL_tokenbuf[1])
4568 PL_expect = XOPERATOR;
4569 PL_pending_ident = '#';
4573 PL_tokenbuf[0] = '$';
4574 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4575 sizeof PL_tokenbuf - 1, FALSE);
4576 if (PL_expect == XOPERATOR)
4578 if (!PL_tokenbuf[1]) {
4580 yyerror("Final $ should be \\$ or $name");
4584 /* This kludge not intended to be bulletproof. */
4585 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4586 yylval.opval = newSVOP(OP_CONST, 0,
4587 newSViv(CopARYBASE_get(&PL_compiling)));
4588 yylval.opval->op_private = OPpCONST_ARYBASE;
4594 const char tmp = *s;
4595 if (PL_lex_state == LEX_NORMAL)
4598 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4599 && intuit_more(s)) {
4601 PL_tokenbuf[0] = '@';
4602 if (ckWARN(WARN_SYNTAX)) {
4605 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4608 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4609 while (t < PL_bufend && *t != ']')
4611 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4612 "Multidimensional syntax %.*s not supported",
4613 (int)((t - PL_bufptr) + 1), PL_bufptr);
4617 else if (*s == '{') {
4619 PL_tokenbuf[0] = '%';
4620 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4621 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4623 char tmpbuf[sizeof PL_tokenbuf];
4626 } while (isSPACE(*t));
4627 if (isIDFIRST_lazy_if(t,UTF)) {
4629 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4633 if (*t == ';' && get_cv(tmpbuf, FALSE))
4634 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4635 "You need to quote \"%s\"",
4642 PL_expect = XOPERATOR;
4643 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4644 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4645 if (!islop || PL_last_lop_op == OP_GREPSTART)
4646 PL_expect = XOPERATOR;
4647 else if (strchr("$@\"'`q", *s))
4648 PL_expect = XTERM; /* e.g. print $fh "foo" */
4649 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4650 PL_expect = XTERM; /* e.g. print $fh &sub */
4651 else if (isIDFIRST_lazy_if(s,UTF)) {
4652 char tmpbuf[sizeof PL_tokenbuf];
4654 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4655 if ((t2 = keyword(tmpbuf, len))) {
4656 /* binary operators exclude handle interpretations */
4668 PL_expect = XTERM; /* e.g. print $fh length() */
4673 PL_expect = XTERM; /* e.g. print $fh subr() */
4676 else if (isDIGIT(*s))
4677 PL_expect = XTERM; /* e.g. print $fh 3 */
4678 else if (*s == '.' && isDIGIT(s[1]))
4679 PL_expect = XTERM; /* e.g. print $fh .3 */
4680 else if ((*s == '?' || *s == '-' || *s == '+')
4681 && !isSPACE(s[1]) && s[1] != '=')
4682 PL_expect = XTERM; /* e.g. print $fh -1 */
4683 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4685 PL_expect = XTERM; /* e.g. print $fh /.../
4686 XXX except DORDOR operator
4688 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4690 PL_expect = XTERM; /* print $fh <<"EOF" */
4693 PL_pending_ident = '$';
4697 if (PL_expect == XOPERATOR)
4699 PL_tokenbuf[0] = '@';
4700 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4701 if (!PL_tokenbuf[1]) {
4704 if (PL_lex_state == LEX_NORMAL)
4706 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4708 PL_tokenbuf[0] = '%';
4710 /* Warn about @ where they meant $. */
4711 if (*s == '[' || *s == '{') {
4712 if (ckWARN(WARN_SYNTAX)) {
4713 const char *t = s + 1;
4714 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4716 if (*t == '}' || *t == ']') {
4718 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4719 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4720 "Scalar value %.*s better written as $%.*s",
4721 (int)(t-PL_bufptr), PL_bufptr,
4722 (int)(t-PL_bufptr-1), PL_bufptr+1);
4727 PL_pending_ident = '@';
4730 case '/': /* may be division, defined-or, or pattern */
4731 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4735 case '?': /* may either be conditional or pattern */
4736 if(PL_expect == XOPERATOR) {
4744 /* A // operator. */
4754 /* Disable warning on "study /blah/" */
4755 if (PL_oldoldbufptr == PL_last_uni
4756 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4757 || memNE(PL_last_uni, "study", 5)
4758 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4761 s = scan_pat(s,OP_MATCH);
4762 TERM(sublex_start());
4766 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4767 #ifdef PERL_STRICT_CR
4770 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4772 && (s == PL_linestart || s[-1] == '\n') )
4774 PL_lex_formbrack = 0;
4778 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4784 yylval.ival = OPf_SPECIAL;
4790 if (PL_expect != XOPERATOR)
4795 case '0': case '1': case '2': case '3': case '4':
4796 case '5': case '6': case '7': case '8': case '9':
4797 s = scan_num(s, &yylval);
4798 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
4799 if (PL_expect == XOPERATOR)
4804 s = scan_str(s,!!PL_madskills,FALSE);
4805 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4806 if (PL_expect == XOPERATOR) {
4807 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4809 deprecate_old(commaless_variable_list);
4810 return REPORT(','); /* grandfather non-comma-format format */
4817 yylval.ival = OP_CONST;
4818 TERM(sublex_start());
4821 s = scan_str(s,!!PL_madskills,FALSE);
4822 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4823 if (PL_expect == XOPERATOR) {
4824 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4826 deprecate_old(commaless_variable_list);
4827 return REPORT(','); /* grandfather non-comma-format format */
4834 yylval.ival = OP_CONST;
4835 /* FIXME. I think that this can be const if char *d is replaced by
4836 more localised variables. */
4837 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
4838 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
4839 yylval.ival = OP_STRINGIFY;
4843 TERM(sublex_start());
4846 s = scan_str(s,!!PL_madskills,FALSE);
4847 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
4848 if (PL_expect == XOPERATOR)
4849 no_op("Backticks",s);
4852 yylval.ival = OP_BACKTICK;
4854 TERM(sublex_start());
4858 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
4859 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
4861 if (PL_expect == XOPERATOR)
4862 no_op("Backslash",s);
4866 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
4867 char *start = s + 2;
4868 while (isDIGIT(*start) || *start == '_')
4870 if (*start == '.' && isDIGIT(start[1])) {
4871 s = scan_num(s, &yylval);
4874 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
4875 else if (!isALPHA(*start) && (PL_expect == XTERM
4876 || PL_expect == XREF || PL_expect == XSTATE
4877 || PL_expect == XTERMORDORDOR)) {
4878 /* XXX Use gv_fetchpvn rather than stomping on a const string */
4879 const char c = *start;
4882 gv = gv_fetchpv(s, 0, SVt_PVCV);
4885 s = scan_num(s, &yylval);
4892 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
4928 I32 orig_keyword = 0;
4933 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4935 /* Some keywords can be followed by any delimiter, including ':' */
4936 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
4937 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
4938 (PL_tokenbuf[0] == 'q' &&
4939 strchr("qwxr", PL_tokenbuf[1])))));
4941 /* x::* is just a word, unless x is "CORE" */
4942 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4946 while (d < PL_bufend && isSPACE(*d))
4947 d++; /* no comments skipped here, or s### is misparsed */
4949 /* Is this a label? */
4950 if (!tmp && PL_expect == XSTATE
4951 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
4953 yylval.pval = savepv(PL_tokenbuf);
4958 /* Check for keywords */
4959 tmp = keyword(PL_tokenbuf, len);
4961 /* Is this a word before a => operator? */
4962 if (*d == '=' && d[1] == '>') {
4965 = (OP*)newSVOP(OP_CONST, 0,
4966 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
4967 yylval.opval->op_private = OPpCONST_BARE;
4971 if (tmp < 0) { /* second-class keyword? */
4972 GV *ogv = NULL; /* override (winner) */
4973 GV *hgv = NULL; /* hidden (loser) */
4974 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
4976 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
4979 if (GvIMPORTED_CV(gv))
4981 else if (! CvMETHOD(cv))
4985 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
4986 (gv = *gvp) != (GV*)&PL_sv_undef &&
4987 GvCVu(gv) && GvIMPORTED_CV(gv))
4994 tmp = 0; /* overridden by import or by GLOBAL */
4997 && -tmp==KEY_lock /* XXX generalizable kludge */
4999 && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
5001 tmp = 0; /* any sub overrides "weak" keyword */
5003 else { /* no override */
5005 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
5006 Perl_warner(aTHX_ packWARN(WARN_MISC),
5007 "dump() better written as CORE::dump()");
5011 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5012 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
5013 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5014 "Ambiguous call resolved as CORE::%s(), %s",
5015 GvENAME(hgv), "qualify as such or use &");
5022 default: /* not a keyword */
5023 /* Trade off - by using this evil construction we can pull the
5024 variable gv into the block labelled keylookup. If not, then
5025 we have to give it function scope so that the goto from the
5026 earlier ':' case doesn't bypass the initialisation. */
5028 just_a_word_zero_gv:
5036 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5039 SV *nextPL_nextwhite = 0;
5043 /* Get the rest if it looks like a package qualifier */
5045 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5047 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5050 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5051 *s == '\'' ? "'" : "::");
5056 if (PL_expect == XOPERATOR) {
5057 if (PL_bufptr == PL_linestart) {
5058 CopLINE_dec(PL_curcop);
5059 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5060 CopLINE_inc(PL_curcop);
5063 no_op("Bareword",s);
5066 /* Look for a subroutine with this name in current package,
5067 unless name is "Foo::", in which case Foo is a bearword
5068 (and a package name). */
5070 if (len > 2 && !PL_madskills &&
5071 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5073 if (ckWARN(WARN_BAREWORD)
5074 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5075 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5076 "Bareword \"%s\" refers to nonexistent package",
5079 PL_tokenbuf[len] = '\0';
5085 /* Mustn't actually add anything to a symbol table.
5086 But also don't want to "initialise" any placeholder
5087 constants that might already be there into full
5088 blown PVGVs with attached PVCV. */
5089 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5090 GV_NOADD_NOINIT, SVt_PVCV);
5095 /* if we saw a global override before, get the right name */
5098 sv = newSVpvs("CORE::GLOBAL::");
5099 sv_catpv(sv,PL_tokenbuf);
5102 /* If len is 0, newSVpv does strlen(), which is correct.
5103 If len is non-zero, then it will be the true length,
5104 and so the scalar will be created correctly. */
5105 sv = newSVpv(PL_tokenbuf,len);
5108 if (PL_madskills && !PL_thistoken) {
5109 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5110 PL_thistoken = newSVpv(start,s - start);
5111 PL_realtokenstart = s - SvPVX(PL_linestr);
5115 /* Presume this is going to be a bareword of some sort. */
5118 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5119 yylval.opval->op_private = OPpCONST_BARE;
5120 /* UTF-8 package name? */
5121 if (UTF && !IN_BYTES &&
5122 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5125 /* And if "Foo::", then that's what it certainly is. */
5130 /* Do the explicit type check so that we don't need to force
5131 the initialisation of the symbol table to have a real GV.
5132 Beware - gv may not really be a PVGV, cv may not really be
5133 a PVCV, (because of the space optimisations that gv_init
5134 understands) But they're true if for this symbol there is
5135 respectively a typeglob and a subroutine.
5137 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5138 /* Real typeglob, so get the real subroutine: */
5140 /* A proxy for a subroutine in this package? */
5141 : SvOK(gv) ? (CV *) gv : NULL)
5144 /* See if it's the indirect object for a list operator. */
5146 if (PL_oldoldbufptr &&
5147 PL_oldoldbufptr < PL_bufptr &&
5148 (PL_oldoldbufptr == PL_last_lop
5149 || PL_oldoldbufptr == PL_last_uni) &&
5150 /* NO SKIPSPACE BEFORE HERE! */
5151 (PL_expect == XREF ||
5152 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5154 bool immediate_paren = *s == '(';
5156 /* (Now we can afford to cross potential line boundary.) */
5157 s = SKIPSPACE2(s,nextPL_nextwhite);
5159 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5162 /* Two barewords in a row may indicate method call. */
5164 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5165 (tmp = intuit_method(s, gv, cv)))
5168 /* If not a declared subroutine, it's an indirect object. */
5169 /* (But it's an indir obj regardless for sort.) */
5170 /* Also, if "_" follows a filetest operator, it's a bareword */
5173 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5175 (PL_last_lop_op != OP_MAPSTART &&
5176 PL_last_lop_op != OP_GREPSTART))))
5177 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5178 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5181 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5186 PL_expect = XOPERATOR;
5189 s = SKIPSPACE2(s,nextPL_nextwhite);
5190 PL_nextwhite = nextPL_nextwhite;
5195 /* Is this a word before a => operator? */
5196 if (*s == '=' && s[1] == '>' && !pkgname) {
5198 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5199 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5200 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5204 /* If followed by a paren, it's certainly a subroutine. */
5209 while (SPACE_OR_TAB(*d))
5211 if (*d == ')' && (sv = gv_const_sv(gv))) {
5215 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5216 sv_catpvn(PL_thistoken, par, s - par);
5218 sv_free(PL_nextwhite);
5228 PL_nextwhite = PL_thiswhite;
5231 start_force(PL_curforce);
5233 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5234 PL_expect = XOPERATOR;
5237 PL_nextwhite = nextPL_nextwhite;
5238 curmad('X', PL_thistoken);
5239 PL_thistoken = newSVpvn("",0);
5247 /* If followed by var or block, call it a method (unless sub) */
5249 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5250 PL_last_lop = PL_oldbufptr;
5251 PL_last_lop_op = OP_METHOD;
5255 /* If followed by a bareword, see if it looks like indir obj. */
5258 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5259 && (tmp = intuit_method(s, gv, cv)))
5262 /* Not a method, so call it a subroutine (if defined) */
5265 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5266 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5267 "Ambiguous use of -%s resolved as -&%s()",
5268 PL_tokenbuf, PL_tokenbuf);
5269 /* Check for a constant sub */
5270 if ((sv = gv_const_sv(gv))) {
5272 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5273 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5274 yylval.opval->op_private = 0;
5278 /* Resolve to GV now. */
5279 if (SvTYPE(gv) != SVt_PVGV) {
5280 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5281 assert (SvTYPE(gv) == SVt_PVGV);
5282 /* cv must have been some sort of placeholder, so
5283 now needs replacing with a real code reference. */
5287 op_free(yylval.opval);
5288 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5289 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5290 PL_last_lop = PL_oldbufptr;
5291 PL_last_lop_op = OP_ENTERSUB;
5292 /* Is there a prototype? */
5299 const char *proto = SvPV_const((SV*)cv, protolen);
5302 if (*proto == '$' && proto[1] == '\0')
5304 while (*proto == ';')
5306 if (*proto == '&' && *s == '{') {
5307 sv_setpv(PL_subname, PL_curstash ?
5308 "__ANON__" : "__ANON__::__ANON__");
5315 PL_nextwhite = PL_thiswhite;
5318 start_force(PL_curforce);
5319 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5322 PL_nextwhite = nextPL_nextwhite;
5323 curmad('X', PL_thistoken);
5324 PL_thistoken = newSVpvn("",0);
5331 /* Guess harder when madskills require "best effort". */
5332 if (PL_madskills && (!gv || !GvCVu(gv))) {
5333 int probable_sub = 0;
5334 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5336 else if (isALPHA(*s)) {
5340 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5341 if (!keyword(tmpbuf,tmplen))
5344 while (d < PL_bufend && isSPACE(*d))
5346 if (*d == '=' && d[1] == '>')
5351 gv = gv_fetchpv(PL_tokenbuf, TRUE, SVt_PVCV);
5352 op_free(yylval.opval);
5353 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5354 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5355 PL_last_lop = PL_oldbufptr;
5356 PL_last_lop_op = OP_ENTERSUB;
5357 PL_nextwhite = PL_thiswhite;
5359 start_force(PL_curforce);
5360 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5362 PL_nextwhite = nextPL_nextwhite;
5363 curmad('X', PL_thistoken);
5364 PL_thistoken = newSVpvn("",0);
5369 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5376 /* Call it a bare word */
5378 if (PL_hints & HINT_STRICT_SUBS)
5379 yylval.opval->op_private |= OPpCONST_STRICT;
5382 if (lastchar != '-') {
5383 if (ckWARN(WARN_RESERVED)) {
5387 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
5388 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5395 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5396 && ckWARN_d(WARN_AMBIGUOUS)) {
5397 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5398 "Operator or semicolon missing before %c%s",
5399 lastchar, PL_tokenbuf);
5400 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5401 "Ambiguous use of %c resolved as operator %c",
5402 lastchar, lastchar);
5408 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5409 newSVpv(CopFILE(PL_curcop),0));
5413 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5414 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5417 case KEY___PACKAGE__:
5418 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5420 ? newSVhek(HvNAME_HEK(PL_curstash))
5427 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5428 const char *pname = "main";
5429 if (PL_tokenbuf[2] == 'D')
5430 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5431 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5435 GvIOp(gv) = newIO();
5436 IoIFP(GvIOp(gv)) = PL_rsfp;
5437 #if defined(HAS_FCNTL) && defined(F_SETFD)
5439 const int fd = PerlIO_fileno(PL_rsfp);
5440 fcntl(fd,F_SETFD,fd >= 3);
5443 /* Mark this internal pseudo-handle as clean */
5444 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5446 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5447 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5448 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5450 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5451 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5452 /* if the script was opened in binmode, we need to revert
5453 * it to text mode for compatibility; but only iff it has CRs
5454 * XXX this is a questionable hack at best. */
5455 if (PL_bufend-PL_bufptr > 2
5456 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5459 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5460 loc = PerlIO_tell(PL_rsfp);
5461 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5464 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5466 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5467 #endif /* NETWARE */
5468 #ifdef PERLIO_IS_STDIO /* really? */
5469 # if defined(__BORLANDC__)
5470 /* XXX see note in do_binmode() */
5471 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5475 PerlIO_seek(PL_rsfp, loc, 0);
5479 #ifdef PERLIO_LAYERS
5482 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5483 else if (PL_encoding) {
5490 XPUSHs(PL_encoding);
5492 call_method("name", G_SCALAR);
5496 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5497 Perl_form(aTHX_ ":encoding(%"SVf")",
5506 if (PL_realtokenstart >= 0) {
5507 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5509 PL_endwhite = newSVpvn("",0);
5510 sv_catsv(PL_endwhite, PL_thiswhite);
5512 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5513 PL_realtokenstart = -1;
5515 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5516 SvCUR(PL_endwhite))) != Nullch) ;
5530 if (PL_expect == XSTATE) {
5537 if (*s == ':' && s[1] == ':') {
5540 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5541 if (!(tmp = keyword(PL_tokenbuf, len)))
5542 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5545 else if (tmp == KEY_require || tmp == KEY_do)
5546 /* that's a way to remember we saw "CORE::" */
5559 LOP(OP_ACCEPT,XTERM);
5565 LOP(OP_ATAN2,XTERM);
5571 LOP(OP_BINMODE,XTERM);
5574 LOP(OP_BLESS,XTERM);
5583 /* When 'use switch' is in effect, continue has a dual
5584 life as a control operator. */
5586 if (!FEATURE_IS_ENABLED("switch"))
5589 /* We have to disambiguate the two senses of
5590 "continue". If the next token is a '{' then
5591 treat it as the start of a continue block;
5592 otherwise treat it as a control operator.
5604 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5621 if (!PL_cryptseen) {
5622 PL_cryptseen = TRUE;
5626 LOP(OP_CRYPT,XTERM);
5629 LOP(OP_CHMOD,XTERM);
5632 LOP(OP_CHOWN,XTERM);
5635 LOP(OP_CONNECT,XTERM);
5654 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5655 if (orig_keyword == KEY_do) {
5664 PL_hints |= HINT_BLOCK_SCOPE;
5674 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5675 LOP(OP_DBMOPEN,XTERM);
5681 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5688 yylval.ival = CopLINE(PL_curcop);
5704 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5705 UNIBRACK(OP_ENTEREVAL);
5723 case KEY_endhostent:
5729 case KEY_endservent:
5732 case KEY_endprotoent:
5743 yylval.ival = CopLINE(PL_curcop);
5745 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5748 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5751 if ((PL_bufend - p) >= 3 &&
5752 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5754 else if ((PL_bufend - p) >= 4 &&
5755 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5758 if (isIDFIRST_lazy_if(p,UTF)) {
5759 p = scan_ident(p, PL_bufend,
5760 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5764 Perl_croak(aTHX_ "Missing $ on loop variable");
5766 s = SvPVX(PL_linestr) + soff;
5772 LOP(OP_FORMLINE,XTERM);
5778 LOP(OP_FCNTL,XTERM);
5784 LOP(OP_FLOCK,XTERM);
5793 LOP(OP_GREPSTART, XREF);
5796 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5811 case KEY_getpriority:
5812 LOP(OP_GETPRIORITY,XTERM);
5814 case KEY_getprotobyname:
5817 case KEY_getprotobynumber:
5818 LOP(OP_GPBYNUMBER,XTERM);
5820 case KEY_getprotoent:
5832 case KEY_getpeername:
5833 UNI(OP_GETPEERNAME);
5835 case KEY_gethostbyname:
5838 case KEY_gethostbyaddr:
5839 LOP(OP_GHBYADDR,XTERM);
5841 case KEY_gethostent:
5844 case KEY_getnetbyname:
5847 case KEY_getnetbyaddr:
5848 LOP(OP_GNBYADDR,XTERM);
5853 case KEY_getservbyname:
5854 LOP(OP_GSBYNAME,XTERM);
5856 case KEY_getservbyport:
5857 LOP(OP_GSBYPORT,XTERM);
5859 case KEY_getservent:
5862 case KEY_getsockname:
5863 UNI(OP_GETSOCKNAME);
5865 case KEY_getsockopt:
5866 LOP(OP_GSOCKOPT,XTERM);
5881 yylval.ival = CopLINE(PL_curcop);
5892 yylval.ival = CopLINE(PL_curcop);
5896 LOP(OP_INDEX,XTERM);
5902 LOP(OP_IOCTL,XTERM);
5914 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5946 LOP(OP_LISTEN,XTERM);
5955 s = scan_pat(s,OP_MATCH);
5956 TERM(sublex_start());
5959 LOP(OP_MAPSTART, XREF);
5962 LOP(OP_MKDIR,XTERM);
5965 LOP(OP_MSGCTL,XTERM);
5968 LOP(OP_MSGGET,XTERM);
5971 LOP(OP_MSGRCV,XTERM);
5974 LOP(OP_MSGSND,XTERM);
5981 if (isIDFIRST_lazy_if(s,UTF)) {
5985 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
5986 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
5988 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
5989 if (!PL_in_my_stash) {
5992 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
5996 if (PL_madskills) { /* just add type to declarator token */
5997 sv_catsv(PL_thistoken, PL_nextwhite);
5999 sv_catpvn(PL_thistoken, start, s - start);
6007 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6014 s = tokenize_use(0, s);
6018 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6025 if (isIDFIRST_lazy_if(s,UTF)) {
6027 for (d = s; isALNUM_lazy_if(d,UTF);)
6029 for (t=d; isSPACE(*t);)
6031 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6033 && !(t[0] == '=' && t[1] == '>')
6035 int parms_len = (int)(d-s);
6036 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6037 "Precedence problem: open %.*s should be open(%.*s)",
6038 parms_len, s, parms_len, s);
6044 yylval.ival = OP_OR;
6054 LOP(OP_OPEN_DIR,XTERM);
6057 checkcomma(s,PL_tokenbuf,"filehandle");
6061 checkcomma(s,PL_tokenbuf,"filehandle");
6080 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6084 LOP(OP_PIPE_OP,XTERM);
6087 s = scan_str(s,!!PL_madskills,FALSE);
6090 yylval.ival = OP_CONST;
6091 TERM(sublex_start());
6097 s = scan_str(s,!!PL_madskills,FALSE);
6100 PL_expect = XOPERATOR;
6102 if (SvCUR(PL_lex_stuff)) {
6105 d = SvPV_force(PL_lex_stuff, len);
6107 for (; isSPACE(*d) && len; --len, ++d)
6112 if (!warned && ckWARN(WARN_QW)) {
6113 for (; !isSPACE(*d) && len; --len, ++d) {
6115 Perl_warner(aTHX_ packWARN(WARN_QW),
6116 "Possible attempt to separate words with commas");
6119 else if (*d == '#') {
6120 Perl_warner(aTHX_ packWARN(WARN_QW),
6121 "Possible attempt to put comments in qw() list");
6127 for (; !isSPACE(*d) && len; --len, ++d)
6130 sv = newSVpvn(b, d-b);
6131 if (DO_UTF8(PL_lex_stuff))
6133 words = append_elem(OP_LIST, words,
6134 newSVOP(OP_CONST, 0, tokeq(sv)));
6138 start_force(PL_curforce);
6139 NEXTVAL_NEXTTOKE.opval = words;
6144 SvREFCNT_dec(PL_lex_stuff);
6145 PL_lex_stuff = NULL;
6151 s = scan_str(s,!!PL_madskills,FALSE);
6154 yylval.ival = OP_STRINGIFY;
6155 if (SvIVX(PL_lex_stuff) == '\'')
6156 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6157 TERM(sublex_start());
6160 s = scan_pat(s,OP_QR);
6161 TERM(sublex_start());
6164 s = scan_str(s,!!PL_madskills,FALSE);
6167 yylval.ival = OP_BACKTICK;
6169 TERM(sublex_start());
6177 s = force_version(s, FALSE);
6179 else if (*s != 'v' || !isDIGIT(s[1])
6180 || (s = force_version(s, TRUE), *s == 'v'))
6182 *PL_tokenbuf = '\0';
6183 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6184 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6185 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
6187 yyerror("<> should be quotes");
6189 if (orig_keyword == KEY_require) {
6197 PL_last_uni = PL_oldbufptr;
6198 PL_last_lop_op = OP_REQUIRE;
6200 return REPORT( (int)REQUIRE );
6206 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6210 LOP(OP_RENAME,XTERM);
6219 LOP(OP_RINDEX,XTERM);
6229 UNIDOR(OP_READLINE);
6242 LOP(OP_REVERSE,XTERM);
6245 UNIDOR(OP_READLINK);
6253 TERM(sublex_start());
6255 TOKEN(1); /* force error */
6258 checkcomma(s,PL_tokenbuf,"filehandle");
6268 LOP(OP_SELECT,XTERM);
6274 LOP(OP_SEMCTL,XTERM);
6277 LOP(OP_SEMGET,XTERM);
6280 LOP(OP_SEMOP,XTERM);
6286 LOP(OP_SETPGRP,XTERM);
6288 case KEY_setpriority:
6289 LOP(OP_SETPRIORITY,XTERM);
6291 case KEY_sethostent:
6297 case KEY_setservent:
6300 case KEY_setprotoent:
6310 LOP(OP_SEEKDIR,XTERM);
6312 case KEY_setsockopt:
6313 LOP(OP_SSOCKOPT,XTERM);
6319 LOP(OP_SHMCTL,XTERM);
6322 LOP(OP_SHMGET,XTERM);
6325 LOP(OP_SHMREAD,XTERM);
6328 LOP(OP_SHMWRITE,XTERM);
6331 LOP(OP_SHUTDOWN,XTERM);
6340 LOP(OP_SOCKET,XTERM);
6342 case KEY_socketpair:
6343 LOP(OP_SOCKPAIR,XTERM);
6346 checkcomma(s,PL_tokenbuf,"subroutine name");
6348 if (*s == ';' || *s == ')') /* probably a close */
6349 Perl_croak(aTHX_ "sort is now a reserved word");
6351 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6355 LOP(OP_SPLIT,XTERM);
6358 LOP(OP_SPRINTF,XTERM);
6361 LOP(OP_SPLICE,XTERM);
6376 LOP(OP_SUBSTR,XTERM);
6382 char tmpbuf[sizeof PL_tokenbuf];
6383 SSize_t tboffset = 0;
6384 expectation attrful;
6385 bool have_name, have_proto, bad_proto;
6386 const int key = tmp;
6391 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6392 SV *subtoken = newSVpvn(tstart, s - tstart);
6396 s = SKIPSPACE2(s,tmpwhite);
6401 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6402 (*s == ':' && s[1] == ':'))
6409 attrful = XATTRBLOCK;
6410 /* remember buffer pos'n for later force_word */
6411 tboffset = s - PL_oldbufptr;
6412 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6415 nametoke = newSVpvn(s, d - s);
6417 if (strchr(tmpbuf, ':'))
6418 sv_setpv(PL_subname, tmpbuf);
6420 sv_setsv(PL_subname,PL_curstname);
6421 sv_catpvs(PL_subname,"::");
6422 sv_catpvn(PL_subname,tmpbuf,len);
6429 CURMAD('X', nametoke);
6430 CURMAD('_', tmpwhite);
6431 (void) force_word(PL_oldbufptr + tboffset, WORD,
6434 s = SKIPSPACE2(d,tmpwhite);
6441 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6442 PL_expect = XTERMBLOCK;
6443 attrful = XATTRTERM;
6444 sv_setpvn(PL_subname,"?",1);
6448 if (key == KEY_format) {
6450 PL_lex_formbrack = PL_lex_brackets + 1;
6452 PL_thistoken = subtoken;
6456 (void) force_word(PL_oldbufptr + tboffset, WORD,
6462 /* Look for a prototype */
6466 s = scan_str(s,!!PL_madskills,FALSE);
6468 Perl_croak(aTHX_ "Prototype not terminated");
6469 /* strip spaces and check for bad characters */
6470 d = SvPVX(PL_lex_stuff);
6473 for (p = d; *p; ++p) {
6476 if (!strchr("$@%*;[]&\\", *p))
6481 if (bad_proto && ckWARN(WARN_SYNTAX))
6482 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6483 "Illegal character in prototype for %"SVf" : %s",
6484 (void*)PL_subname, d);
6485 SvCUR_set(PL_lex_stuff, tmp);
6490 CURMAD('q', PL_thisopen);
6491 CURMAD('_', tmpwhite);
6492 CURMAD('=', PL_thisstuff);
6493 CURMAD('Q', PL_thisclose);
6494 NEXTVAL_NEXTTOKE.opval =
6495 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6496 PL_lex_stuff = Nullsv;
6499 s = SKIPSPACE2(s,tmpwhite);
6507 if (*s == ':' && s[1] != ':')
6508 PL_expect = attrful;
6509 else if (*s != '{' && key == KEY_sub) {
6511 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6513 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, (void*)PL_subname);
6520 curmad('^', newSVpvn("",0));
6521 CURMAD('_', tmpwhite);
6525 PL_thistoken = subtoken;
6528 NEXTVAL_NEXTTOKE.opval =
6529 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6530 PL_lex_stuff = NULL;
6535 sv_setpv(PL_subname,
6536 PL_curstash ? "__ANON__" : "__ANON__::__ANON__");
6540 (void) force_word(PL_oldbufptr + tboffset, WORD,
6550 LOP(OP_SYSTEM,XREF);
6553 LOP(OP_SYMLINK,XTERM);
6556 LOP(OP_SYSCALL,XTERM);
6559 LOP(OP_SYSOPEN,XTERM);
6562 LOP(OP_SYSSEEK,XTERM);
6565 LOP(OP_SYSREAD,XTERM);
6568 LOP(OP_SYSWRITE,XTERM);
6572 TERM(sublex_start());
6593 LOP(OP_TRUNCATE,XTERM);
6605 yylval.ival = CopLINE(PL_curcop);
6609 yylval.ival = CopLINE(PL_curcop);
6613 LOP(OP_UNLINK,XTERM);
6619 LOP(OP_UNPACK,XTERM);
6622 LOP(OP_UTIME,XTERM);
6628 LOP(OP_UNSHIFT,XTERM);
6631 s = tokenize_use(1, s);
6641 yylval.ival = CopLINE(PL_curcop);
6645 yylval.ival = CopLINE(PL_curcop);
6649 PL_hints |= HINT_BLOCK_SCOPE;
6656 LOP(OP_WAITPID,XTERM);
6665 ctl_l[0] = toCTRL('L');
6667 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6670 /* Make sure $^L is defined */
6671 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6676 if (PL_expect == XOPERATOR)
6682 yylval.ival = OP_XOR;
6687 TERM(sublex_start());
6692 #pragma segment Main
6696 S_pending_ident(pTHX)
6701 /* pit holds the identifier we read and pending_ident is reset */
6702 char pit = PL_pending_ident;
6703 PL_pending_ident = 0;
6705 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6706 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6707 "### Pending identifier '%s'\n", PL_tokenbuf); });
6709 /* if we're in a my(), we can't allow dynamics here.
6710 $foo'bar has already been turned into $foo::bar, so
6711 just check for colons.
6713 if it's a legal name, the OP is a PADANY.
6716 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6717 if (strchr(PL_tokenbuf,':'))
6718 yyerror(Perl_form(aTHX_ "No package name allowed for "
6719 "variable %s in \"our\"",
6721 tmp = allocmy(PL_tokenbuf);
6724 if (strchr(PL_tokenbuf,':'))
6725 yyerror(Perl_form(aTHX_ PL_no_myglob,
6726 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
6728 yylval.opval = newOP(OP_PADANY, 0);
6729 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6735 build the ops for accesses to a my() variable.
6737 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6738 then used in a comparison. This catches most, but not
6739 all cases. For instance, it catches
6740 sort { my($a); $a <=> $b }
6742 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6743 (although why you'd do that is anyone's guess).
6746 if (!strchr(PL_tokenbuf,':')) {
6748 tmp = pad_findmy(PL_tokenbuf);
6749 if (tmp != NOT_IN_PAD) {
6750 /* might be an "our" variable" */
6751 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6752 /* build ops for a bareword */
6753 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6754 HEK * const stashname = HvNAME_HEK(stash);
6755 SV * const sym = newSVhek(stashname);
6756 sv_catpvs(sym, "::");
6757 sv_catpv(sym, PL_tokenbuf+1);
6758 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6759 yylval.opval->op_private = OPpCONST_ENTERED;
6762 ? (GV_ADDMULTI | GV_ADDINEVAL)
6765 ((PL_tokenbuf[0] == '$') ? SVt_PV
6766 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6771 /* if it's a sort block and they're naming $a or $b */
6772 if (PL_last_lop_op == OP_SORT &&
6773 PL_tokenbuf[0] == '$' &&
6774 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6777 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6778 d < PL_bufend && *d != '\n';
6781 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6782 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6788 yylval.opval = newOP(OP_PADANY, 0);
6789 yylval.opval->op_targ = tmp;
6795 Whine if they've said @foo in a doublequoted string,
6796 and @foo isn't a variable we can find in the symbol
6799 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
6800 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
6801 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
6802 && ckWARN(WARN_AMBIGUOUS))
6804 /* Downgraded from fatal to warning 20000522 mjd */
6805 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6806 "Possible unintended interpolation of %s in string",
6811 /* build ops for a bareword */
6812 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
6813 yylval.opval->op_private = OPpCONST_ENTERED;
6816 /* If the identifier refers to a stash, don't autovivify it.
6817 * Change 24660 had the side effect of causing symbol table
6818 * hashes to always be defined, even if they were freshly
6819 * created and the only reference in the entire program was
6820 * the single statement with the defined %foo::bar:: test.
6821 * It appears that all code in the wild doing this actually
6822 * wants to know whether sub-packages have been loaded, so
6823 * by avoiding auto-vivifying symbol tables, we ensure that
6824 * defined %foo::bar:: continues to be false, and the existing
6825 * tests still give the expected answers, even though what
6826 * they're actually testing has now changed subtly.
6828 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
6830 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
6831 ((PL_tokenbuf[0] == '$') ? SVt_PV
6832 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6838 * The following code was generated by perl_keyword.pl.
6842 Perl_keyword (pTHX_ const char *name, I32 len)
6847 case 1: /* 5 tokens of length 1 */
6879 case 2: /* 18 tokens of length 2 */
7025 case 3: /* 29 tokens of length 3 */
7029 if (name[1] == 'N' &&
7092 if (name[1] == 'i' &&
7114 return (FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7132 if (name[1] == 'o' &&
7141 if (name[1] == 'e' &&
7150 if (name[1] == 'n' &&
7159 if (name[1] == 'o' &&
7168 if (name[1] == 'a' &&
7177 if (name[1] == 'o' &&
7239 if (name[1] == 'e' &&
7253 return (FEATURE_IS_ENABLED("say") ? -KEY_say : 0);
7279 if (name[1] == 'i' &&
7288 if (name[1] == 's' &&
7297 if (name[1] == 'e' &&
7306 if (name[1] == 'o' &&
7318 case 4: /* 41 tokens of length 4 */
7322 if (name[1] == 'O' &&
7332 if (name[1] == 'N' &&
7342 if (name[1] == 'i' &&
7352 if (name[1] == 'h' &&
7362 if (name[1] == 'u' &&
7375 if (name[2] == 'c' &&
7384 if (name[2] == 's' &&
7393 if (name[2] == 'a' &&
7429 if (name[1] == 'o' &&
7442 if (name[2] == 't' &&
7451 if (name[2] == 'o' &&
7460 if (name[2] == 't' &&
7469 if (name[2] == 'e' &&
7482 if (name[1] == 'o' &&
7495 if (name[2] == 'y' &&
7504 if (name[2] == 'l' &&
7520 if (name[2] == 's' &&
7529 if (name[2] == 'n' &&
7538 if (name[2] == 'c' &&
7551 if (name[1] == 'e' &&
7561 if (name[1] == 'p' &&
7574 if (name[2] == 'c' &&
7583 if (name[2] == 'p' &&
7592 if (name[2] == 's' &&
7608 if (name[2] == 'n' &&
7678 if (name[2] == 'r' &&
7687 if (name[2] == 'r' &&
7696 if (name[2] == 'a' &&
7712 if (name[2] == 'l' &&
7774 if (name[2] == 'e' &&
7777 return (FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
7790 case 5: /* 39 tokens of length 5 */
7794 if (name[1] == 'E' &&
7805 if (name[1] == 'H' &&
7819 if (name[2] == 'a' &&
7829 if (name[2] == 'a' &&
7846 if (name[2] == 'e' &&
7856 if (name[2] == 'e' &&
7860 return (FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
7876 if (name[3] == 'i' &&
7885 if (name[3] == 'o' &&
7921 if (name[2] == 'o' &&
7931 if (name[2] == 'y' &&
7945 if (name[1] == 'l' &&
7959 if (name[2] == 'n' &&
7969 if (name[2] == 'o' &&
7983 if (name[1] == 'i' &&
7988 return (FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
7997 if (name[2] == 'd' &&
8007 if (name[2] == 'c' &&
8024 if (name[2] == 'c' &&
8034 if (name[2] == 't' &&
8048 if (name[1] == 'k' &&
8059 if (name[1] == 'r' &&
8073 if (name[2] == 's' &&
8083 if (name[2] == 'd' &&
8100 if (name[2] == 'm' &&
8110 if (name[2] == 'i' &&
8120 if (name[2] == 'e' &&
8130 if (name[2] == 'l' &&
8140 if (name[2] == 'a' &&
8153 if (name[3] == 't' &&
8156 return (FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8162 if (name[3] == 'd' &&
8179 if (name[1] == 'i' &&
8193 if (name[2] == 'a' &&
8206 if (name[3] == 'e' &&
8241 if (name[2] == 'i' &&
8258 if (name[2] == 'i' &&
8268 if (name[2] == 'i' &&
8285 case 6: /* 33 tokens of length 6 */
8289 if (name[1] == 'c' &&
8304 if (name[2] == 'l' &&
8315 if (name[2] == 'r' &&
8330 if (name[1] == 'e' &&
8345 if (name[2] == 's' &&
8350 if(ckWARN_d(WARN_SYNTAX))
8351 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8357 if (name[2] == 'i' &&
8375 if (name[2] == 'l' &&
8386 if (name[2] == 'r' &&
8401 if (name[1] == 'm' &&
8416 if (name[2] == 'n' &&
8427 if (name[2] == 's' &&
8442 if (name[1] == 's' &&
8448 if (name[4] == 't' &&
8457 if (name[4] == 'e' &&
8466 if (name[4] == 'c' &&
8475 if (name[4] == 'n' &&
8491 if (name[1] == 'r' &&
8509 if (name[3] == 'a' &&
8519 if (name[3] == 'u' &&
8533 if (name[2] == 'n' &&
8551 if (name[2] == 'a' &&
8565 if (name[3] == 'e' &&
8578 if (name[4] == 't' &&
8587 if (name[4] == 'e' &&
8609 if (name[4] == 't' &&
8618 if (name[4] == 'e' &&
8634 if (name[2] == 'c' &&
8645 if (name[2] == 'l' &&
8656 if (name[2] == 'b' &&
8667 if (name[2] == 's' &&
8690 if (name[4] == 's' &&
8699 if (name[4] == 'n' &&
8712 if (name[3] == 'a' &&
8729 if (name[1] == 'a' &&
8744 case 7: /* 29 tokens of length 7 */
8748 if (name[1] == 'E' &&
8761 if (name[1] == '_' &&
8774 if (name[1] == 'i' &&
8781 return -KEY_binmode;
8787 if (name[1] == 'o' &&
8794 return -KEY_connect;
8803 if (name[2] == 'm' &&
8809 return -KEY_dbmopen;
8820 if (name[4] == 'u' &&
8824 return (FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
8830 if (name[4] == 'n' &&
8851 if (name[1] == 'o' &&
8864 if (name[1] == 'e' &&
8871 if (name[5] == 'r' &&
8874 return -KEY_getpgrp;
8880 if (name[5] == 'i' &&
8883 return -KEY_getppid;
8896 if (name[1] == 'c' &&
8903 return -KEY_lcfirst;
8909 if (name[1] == 'p' &&
8916 return -KEY_opendir;
8922 if (name[1] == 'a' &&
8940 if (name[3] == 'd' &&
8945 return -KEY_readdir;
8951 if (name[3] == 'u' &&
8962 if (name[3] == 'e' &&
8967 return -KEY_reverse;
8986 if (name[3] == 'k' &&
8991 return -KEY_seekdir;
8997 if (name[3] == 'p' &&
9002 return -KEY_setpgrp;
9012 if (name[2] == 'm' &&
9018 return -KEY_shmread;
9024 if (name[2] == 'r' &&
9030 return -KEY_sprintf;
9039 if (name[3] == 'l' &&
9044 return -KEY_symlink;
9053 if (name[4] == 'a' &&
9057 return -KEY_syscall;
9063 if (name[4] == 'p' &&
9067 return -KEY_sysopen;
9073 if (name[4] == 'e' &&
9077 return -KEY_sysread;
9083 if (name[4] == 'e' &&
9087 return -KEY_sysseek;
9105 if (name[1] == 'e' &&
9112 return -KEY_telldir;
9121 if (name[2] == 'f' &&
9127 return -KEY_ucfirst;
9133 if (name[2] == 's' &&
9139 return -KEY_unshift;
9149 if (name[1] == 'a' &&
9156 return -KEY_waitpid;
9165 case 8: /* 26 tokens of length 8 */
9169 if (name[1] == 'U' &&
9177 return KEY_AUTOLOAD;
9188 if (name[3] == 'A' &&
9194 return KEY___DATA__;
9200 if (name[3] == 'I' &&
9206 return -KEY___FILE__;
9212 if (name[3] == 'I' &&
9218 return -KEY___LINE__;
9234 if (name[2] == 'o' &&
9241 return -KEY_closedir;
9247 if (name[2] == 'n' &&
9254 return -KEY_continue;
9264 if (name[1] == 'b' &&
9272 return -KEY_dbmclose;
9278 if (name[1] == 'n' &&
9284 if (name[4] == 'r' &&
9289 return -KEY_endgrent;
9295 if (name[4] == 'w' &&
9300 return -KEY_endpwent;
9313 if (name[1] == 'o' &&
9321 return -KEY_formline;
9327 if (name[1] == 'e' &&
9338 if (name[6] == 'n' &&
9341 return -KEY_getgrent;
9347 if (name[6] == 'i' &&
9350 return -KEY_getgrgid;
9356 if (name[6] == 'a' &&
9359 return -KEY_getgrnam;
9372 if (name[4] == 'o' &&
9377 return -KEY_getlogin;
9388 if (name[6] == 'n' &&
9391 return -KEY_getpwent;
9397 if (name[6] == 'a' &&
9400 return -KEY_getpwnam;
9406 if (name[6] == 'i' &&
9409 return -KEY_getpwuid;
9429 if (name[1] == 'e' &&
9436 if (name[5] == 'i' &&
9443 return -KEY_readline;
9448 return -KEY_readlink;
9459 if (name[5] == 'i' &&
9463 return -KEY_readpipe;
9484 if (name[4] == 'r' &&
9489 return -KEY_setgrent;
9495 if (name[4] == 'w' &&
9500 return -KEY_setpwent;
9516 if (name[3] == 'w' &&
9522 return -KEY_shmwrite;
9528 if (name[3] == 't' &&
9534 return -KEY_shutdown;
9544 if (name[2] == 's' &&
9551 return -KEY_syswrite;
9561 if (name[1] == 'r' &&
9569 return -KEY_truncate;
9578 case 9: /* 8 tokens of length 9 */
9582 if (name[1] == 'n' &&
9591 return -KEY_endnetent;
9597 if (name[1] == 'e' &&
9606 return -KEY_getnetent;
9612 if (name[1] == 'o' &&
9621 return -KEY_localtime;
9627 if (name[1] == 'r' &&
9636 return KEY_prototype;
9642 if (name[1] == 'u' &&
9651 return -KEY_quotemeta;
9657 if (name[1] == 'e' &&
9666 return -KEY_rewinddir;
9672 if (name[1] == 'e' &&
9681 return -KEY_setnetent;
9687 if (name[1] == 'a' &&
9696 return -KEY_wantarray;
9705 case 10: /* 9 tokens of length 10 */
9709 if (name[1] == 'n' &&
9715 if (name[4] == 'o' &&
9722 return -KEY_endhostent;
9728 if (name[4] == 'e' &&
9735 return -KEY_endservent;
9748 if (name[1] == 'e' &&
9754 if (name[4] == 'o' &&
9761 return -KEY_gethostent;
9770 if (name[5] == 'r' &&
9776 return -KEY_getservent;
9782 if (name[5] == 'c' &&
9788 return -KEY_getsockopt;
9813 if (name[4] == 'o' &&
9820 return -KEY_sethostent;
9829 if (name[5] == 'r' &&
9835 return -KEY_setservent;
9841 if (name[5] == 'c' &&
9847 return -KEY_setsockopt;
9864 if (name[2] == 'c' &&
9873 return -KEY_socketpair;
9886 case 11: /* 8 tokens of length 11 */
9890 if (name[1] == '_' &&
9901 return -KEY___PACKAGE__;
9907 if (name[1] == 'n' &&
9918 return -KEY_endprotoent;
9924 if (name[1] == 'e' &&
9933 if (name[5] == 'e' &&
9940 return -KEY_getpeername;
9949 if (name[6] == 'o' &&
9955 return -KEY_getpriority;
9961 if (name[6] == 't' &&
9967 return -KEY_getprotoent;
9981 if (name[4] == 'o' &&
9989 return -KEY_getsockname;
10002 if (name[1] == 'e' &&
10010 if (name[6] == 'o' &&
10015 { /* setpriority */
10016 return -KEY_setpriority;
10022 if (name[6] == 't' &&
10027 { /* setprotoent */
10028 return -KEY_setprotoent;
10044 case 12: /* 2 tokens of length 12 */
10045 if (name[0] == 'g' &&
10057 if (name[9] == 'd' &&
10060 { /* getnetbyaddr */
10061 return -KEY_getnetbyaddr;
10067 if (name[9] == 'a' &&
10070 { /* getnetbyname */
10071 return -KEY_getnetbyname;
10083 case 13: /* 4 tokens of length 13 */
10084 if (name[0] == 'g' &&
10091 if (name[4] == 'o' &&
10100 if (name[10] == 'd' &&
10103 { /* gethostbyaddr */
10104 return -KEY_gethostbyaddr;
10110 if (name[10] == 'a' &&
10113 { /* gethostbyname */
10114 return -KEY_gethostbyname;
10127 if (name[4] == 'e' &&
10136 if (name[10] == 'a' &&
10139 { /* getservbyname */
10140 return -KEY_getservbyname;
10146 if (name[10] == 'o' &&
10149 { /* getservbyport */
10150 return -KEY_getservbyport;
10169 case 14: /* 1 tokens of length 14 */
10170 if (name[0] == 'g' &&
10184 { /* getprotobyname */
10185 return -KEY_getprotobyname;
10190 case 16: /* 1 tokens of length 16 */
10191 if (name[0] == 'g' &&
10207 { /* getprotobynumber */
10208 return -KEY_getprotobynumber;
10222 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10226 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10227 if (ckWARN(WARN_SYNTAX)) {
10230 for (w = s+2; *w && level; w++) {
10233 else if (*w == ')')
10236 while (isSPACE(*w))
10238 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
10239 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10240 "%s (...) interpreted as function",name);
10243 while (s < PL_bufend && isSPACE(*s))
10247 while (s < PL_bufend && isSPACE(*s))
10249 if (isIDFIRST_lazy_if(s,UTF)) {
10250 const char * const w = s++;
10251 while (isALNUM_lazy_if(s,UTF))
10253 while (s < PL_bufend && isSPACE(*s))
10257 if (keyword(w, s - w))
10260 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10261 if (gv && GvCVu(gv))
10263 Perl_croak(aTHX_ "No comma allowed after %s", what);
10268 /* Either returns sv, or mortalizes sv and returns a new SV*.
10269 Best used as sv=new_constant(..., sv, ...).
10270 If s, pv are NULL, calls subroutine with one argument,
10271 and type is used with error messages only. */
10274 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10278 HV * const table = GvHV(PL_hintgv); /* ^H */
10282 const char *why1 = "", *why2 = "", *why3 = "";
10284 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10287 why2 = strEQ(key,"charnames")
10288 ? "(possibly a missing \"use charnames ...\")"
10290 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10291 (type ? type: "undef"), why2);
10293 /* This is convoluted and evil ("goto considered harmful")
10294 * but I do not understand the intricacies of all the different
10295 * failure modes of %^H in here. The goal here is to make
10296 * the most probable error message user-friendly. --jhi */
10301 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10302 (type ? type: "undef"), why1, why2, why3);
10304 yyerror(SvPVX_const(msg));
10308 cvp = hv_fetch(table, key, strlen(key), FALSE);
10309 if (!cvp || !SvOK(*cvp)) {
10312 why3 = "} is not defined";
10315 sv_2mortal(sv); /* Parent created it permanently */
10318 pv = sv_2mortal(newSVpvn(s, len));
10320 typesv = sv_2mortal(newSVpv(type, 0));
10322 typesv = &PL_sv_undef;
10324 PUSHSTACKi(PERLSI_OVERLOAD);
10336 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10340 /* Check the eval first */
10341 if (!PL_in_eval && SvTRUE(ERRSV)) {
10342 sv_catpvs(ERRSV, "Propagated");
10343 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10345 res = SvREFCNT_inc_simple(sv);
10349 SvREFCNT_inc_simple_void(res);
10358 why1 = "Call to &{$^H{";
10360 why3 = "}} did not return a defined value";
10368 /* Returns a NUL terminated string, with the length of the string written to
10372 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10375 register char *d = dest;
10376 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10379 Perl_croak(aTHX_ ident_too_long);
10380 if (isALNUM(*s)) /* UTF handled below */
10382 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10387 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10391 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10392 char *t = s + UTF8SKIP(s);
10394 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10398 Perl_croak(aTHX_ ident_too_long);
10399 Copy(s, d, len, char);
10412 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10415 char *bracket = NULL;
10417 register char *d = dest;
10418 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10423 while (isDIGIT(*s)) {
10425 Perl_croak(aTHX_ ident_too_long);
10432 Perl_croak(aTHX_ ident_too_long);
10433 if (isALNUM(*s)) /* UTF handled below */
10435 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10440 else if (*s == ':' && s[1] == ':') {
10444 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10445 char *t = s + UTF8SKIP(s);
10446 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10448 if (d + (t - s) > e)
10449 Perl_croak(aTHX_ ident_too_long);
10450 Copy(s, d, t - s, char);
10461 if (PL_lex_state != LEX_NORMAL)
10462 PL_lex_state = LEX_INTERPENDMAYBE;
10465 if (*s == '$' && s[1] &&
10466 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10479 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10484 if (isSPACE(s[-1])) {
10486 const char ch = *s++;
10487 if (!SPACE_OR_TAB(ch)) {
10493 if (isIDFIRST_lazy_if(d,UTF)) {
10497 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10498 end += UTF8SKIP(end);
10499 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10500 end += UTF8SKIP(end);
10502 Copy(s, d, end - s, char);
10507 while ((isALNUM(*s) || *s == ':') && d < e)
10510 Perl_croak(aTHX_ ident_too_long);
10513 while (s < send && SPACE_OR_TAB(*s))
10515 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10516 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
10517 const char * const brack = (*s == '[') ? "[...]" : "{...}";
10518 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10519 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10520 funny, dest, brack, funny, dest, brack);
10523 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10527 /* Handle extended ${^Foo} variables
10528 * 1999-02-27 mjd-perl-patch@plover.com */
10529 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10533 while (isALNUM(*s) && d < e) {
10537 Perl_croak(aTHX_ ident_too_long);
10542 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10543 PL_lex_state = LEX_INTERPEND;
10546 if (PL_lex_state == LEX_NORMAL) {
10547 if (ckWARN(WARN_AMBIGUOUS) &&
10548 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
10552 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10553 "Ambiguous use of %c{%s} resolved to %c%s",
10554 funny, dest, funny, dest);
10559 s = bracket; /* let the parser handle it */
10563 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10564 PL_lex_state = LEX_INTERPEND;
10569 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10571 PERL_UNUSED_CONTEXT;
10574 else if (ch == 'g')
10575 *pmfl |= PMf_GLOBAL;
10576 else if (ch == 'c')
10577 *pmfl |= PMf_CONTINUE;
10578 else if (ch == 'o')
10580 else if (ch == 'm')
10581 *pmfl |= PMf_MULTILINE;
10582 else if (ch == 's')
10583 *pmfl |= PMf_SINGLELINE;
10584 else if (ch == 'x')
10585 *pmfl |= PMf_EXTENDED;
10589 S_scan_pat(pTHX_ char *start, I32 type)
10593 char *s = scan_str(start,!!PL_madskills,FALSE);
10594 const char * const valid_flags = (type == OP_QR) ? "iomsx" : "iogcmsx";
10601 const char * const delimiter = skipspace(start);
10602 Perl_croak(aTHX_ *delimiter == '?'
10603 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10604 : "Search pattern not terminated" );
10607 pm = (PMOP*)newPMOP(type, 0);
10608 if (PL_multi_open == '?')
10609 pm->op_pmflags |= PMf_ONCE;
10613 while (*s && strchr(valid_flags, *s))
10614 pmflag(&pm->op_pmflags,*s++);
10616 if (PL_madskills && modstart != s) {
10617 SV* tmptoken = newSVpvn(modstart, s - modstart);
10618 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10621 /* issue a warning if /c is specified,but /g is not */
10622 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10623 && ckWARN(WARN_REGEXP))
10625 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" );
10628 pm->op_pmpermflags = pm->op_pmflags;
10630 PL_lex_op = (OP*)pm;
10631 yylval.ival = OP_MATCH;
10636 S_scan_subst(pTHX_ char *start)
10647 yylval.ival = OP_NULL;
10649 s = scan_str(start,!!PL_madskills,FALSE);
10652 Perl_croak(aTHX_ "Substitution pattern not terminated");
10654 if (s[-1] == PL_multi_open)
10657 if (PL_madskills) {
10658 CURMAD('q', PL_thisopen);
10659 CURMAD('_', PL_thiswhite);
10660 CURMAD('E', PL_thisstuff);
10661 CURMAD('Q', PL_thisclose);
10662 PL_realtokenstart = s - SvPVX(PL_linestr);
10666 first_start = PL_multi_start;
10667 s = scan_str(s,!!PL_madskills,FALSE);
10669 if (PL_lex_stuff) {
10670 SvREFCNT_dec(PL_lex_stuff);
10671 PL_lex_stuff = NULL;
10673 Perl_croak(aTHX_ "Substitution replacement not terminated");
10675 PL_multi_start = first_start; /* so whole substitution is taken together */
10677 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10680 if (PL_madskills) {
10681 CURMAD('z', PL_thisopen);
10682 CURMAD('R', PL_thisstuff);
10683 CURMAD('Z', PL_thisclose);
10693 else if (strchr("iogcmsx", *s))
10694 pmflag(&pm->op_pmflags,*s++);
10700 if (PL_madskills) {
10702 curmad('m', newSVpvn(modstart, s - modstart));
10703 append_madprops(PL_thismad, (OP*)pm, 0);
10707 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10708 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10712 SV * const repl = newSVpvs("");
10714 PL_sublex_info.super_bufptr = s;
10715 PL_sublex_info.super_bufend = PL_bufend;
10717 pm->op_pmflags |= PMf_EVAL;
10719 sv_catpv(repl, es ? "eval " : "do ");
10720 sv_catpvs(repl, "{");
10721 sv_catsv(repl, PL_lex_repl);
10722 if (strchr(SvPVX(PL_lex_repl), '#'))
10723 sv_catpvs(repl, "\n");
10724 sv_catpvs(repl, "}");
10726 SvREFCNT_dec(PL_lex_repl);
10727 PL_lex_repl = repl;
10730 pm->op_pmpermflags = pm->op_pmflags;
10731 PL_lex_op = (OP*)pm;
10732 yylval.ival = OP_SUBST;
10737 S_scan_trans(pTHX_ char *start)
10750 yylval.ival = OP_NULL;
10752 s = scan_str(start,!!PL_madskills,FALSE);
10754 Perl_croak(aTHX_ "Transliteration pattern not terminated");
10756 if (s[-1] == PL_multi_open)
10759 if (PL_madskills) {
10760 CURMAD('q', PL_thisopen);
10761 CURMAD('_', PL_thiswhite);
10762 CURMAD('E', PL_thisstuff);
10763 CURMAD('Q', PL_thisclose);
10764 PL_realtokenstart = s - SvPVX(PL_linestr);
10768 s = scan_str(s,!!PL_madskills,FALSE);
10770 if (PL_lex_stuff) {
10771 SvREFCNT_dec(PL_lex_stuff);
10772 PL_lex_stuff = NULL;
10774 Perl_croak(aTHX_ "Transliteration replacement not terminated");
10776 if (PL_madskills) {
10777 CURMAD('z', PL_thisopen);
10778 CURMAD('R', PL_thisstuff);
10779 CURMAD('Z', PL_thisclose);
10782 complement = del = squash = 0;
10789 complement = OPpTRANS_COMPLEMENT;
10792 del = OPpTRANS_DELETE;
10795 squash = OPpTRANS_SQUASH;
10804 Newx(tbl, complement&&!del?258:256, short);
10805 o = newPVOP(OP_TRANS, 0, (char*)tbl);
10806 o->op_private &= ~OPpTRANS_ALL;
10807 o->op_private |= del|squash|complement|
10808 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
10809 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
10812 yylval.ival = OP_TRANS;
10815 if (PL_madskills) {
10817 curmad('m', newSVpvn(modstart, s - modstart));
10818 append_madprops(PL_thismad, o, 0);
10827 S_scan_heredoc(pTHX_ register char *s)
10831 I32 op_type = OP_SCALAR;
10835 const char *found_newline;
10839 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
10841 I32 stuffstart = s - SvPVX(PL_linestr);
10844 PL_realtokenstart = -1;
10849 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
10853 while (SPACE_OR_TAB(*peek))
10855 if (*peek == '`' || *peek == '\'' || *peek =='"') {
10858 s = delimcpy(d, e, s, PL_bufend, term, &len);
10868 if (!isALNUM_lazy_if(s,UTF))
10869 deprecate_old("bare << to mean <<\"\"");
10870 for (; isALNUM_lazy_if(s,UTF); s++) {
10875 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
10876 Perl_croak(aTHX_ "Delimiter for here document is too long");
10879 len = d - PL_tokenbuf;
10882 if (PL_madskills) {
10883 tstart = PL_tokenbuf + !outer;
10884 PL_thisclose = newSVpvn(tstart, len - !outer);
10885 tstart = SvPVX(PL_linestr) + stuffstart;
10886 PL_thisopen = newSVpvn(tstart, s - tstart);
10887 stuffstart = s - SvPVX(PL_linestr);
10890 #ifndef PERL_STRICT_CR
10891 d = strchr(s, '\r');
10893 char * const olds = s;
10895 while (s < PL_bufend) {
10901 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
10910 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
10917 if ( outer || !(found_newline = memchr(s, '\n', PL_bufend - s)) ) {
10918 herewas = newSVpvn(s,PL_bufend-s);
10922 herewas = newSVpvn(s-1,found_newline-s+1);
10925 herewas = newSVpvn(s,found_newline-s);
10929 if (PL_madskills) {
10930 tstart = SvPVX(PL_linestr) + stuffstart;
10932 sv_catpvn(PL_thisstuff, tstart, s - tstart);
10934 PL_thisstuff = newSVpvn(tstart, s - tstart);
10937 s += SvCUR(herewas);
10940 stuffstart = s - SvPVX(PL_linestr);
10946 tmpstr = newSV(79);
10947 sv_upgrade(tmpstr, SVt_PVIV);
10948 if (term == '\'') {
10949 op_type = OP_CONST;
10950 SvIV_set(tmpstr, -1);
10952 else if (term == '`') {
10953 op_type = OP_BACKTICK;
10954 SvIV_set(tmpstr, '\\');
10958 PL_multi_start = CopLINE(PL_curcop);
10959 PL_multi_open = PL_multi_close = '<';
10960 term = *PL_tokenbuf;
10961 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
10962 char * const bufptr = PL_sublex_info.super_bufptr;
10963 char * const bufend = PL_sublex_info.super_bufend;
10964 char * const olds = s - SvCUR(herewas);
10965 s = strchr(bufptr, '\n');
10969 while (s < bufend &&
10970 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
10972 CopLINE_inc(PL_curcop);
10975 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10976 missingterm(PL_tokenbuf);
10978 sv_setpvn(herewas,bufptr,d-bufptr+1);
10979 sv_setpvn(tmpstr,d+1,s-d);
10981 sv_catpvn(herewas,s,bufend-s);
10982 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
10989 while (s < PL_bufend &&
10990 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
10992 CopLINE_inc(PL_curcop);
10994 if (s >= PL_bufend) {
10995 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10996 missingterm(PL_tokenbuf);
10998 sv_setpvn(tmpstr,d+1,s-d);
11000 if (PL_madskills) {
11002 sv_catpvn(PL_thisstuff, d + 1, s - d);
11004 PL_thisstuff = newSVpvn(d + 1, s - d);
11005 stuffstart = s - SvPVX(PL_linestr);
11009 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11011 sv_catpvn(herewas,s,PL_bufend-s);
11012 sv_setsv(PL_linestr,herewas);
11013 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11014 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11015 PL_last_lop = PL_last_uni = NULL;
11018 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
11019 while (s >= PL_bufend) { /* multiple line string? */
11021 if (PL_madskills) {
11022 tstart = SvPVX(PL_linestr) + stuffstart;
11024 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11026 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11030 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11031 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11032 missingterm(PL_tokenbuf);
11035 stuffstart = s - SvPVX(PL_linestr);
11037 CopLINE_inc(PL_curcop);
11038 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11039 PL_last_lop = PL_last_uni = NULL;
11040 #ifndef PERL_STRICT_CR
11041 if (PL_bufend - PL_linestart >= 2) {
11042 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11043 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11045 PL_bufend[-2] = '\n';
11047 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11049 else if (PL_bufend[-1] == '\r')
11050 PL_bufend[-1] = '\n';
11052 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11053 PL_bufend[-1] = '\n';
11055 if (PERLDB_LINE && PL_curstash != PL_debstash) {
11056 SV * const sv = newSV(0);
11058 sv_upgrade(sv, SVt_PVMG);
11059 sv_setsv(sv,PL_linestr);
11060 (void)SvIOK_on(sv);
11062 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop),sv);
11064 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11065 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11066 *(SvPVX(PL_linestr) + off ) = ' ';
11067 sv_catsv(PL_linestr,herewas);
11068 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11069 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11073 sv_catsv(tmpstr,PL_linestr);
11078 PL_multi_end = CopLINE(PL_curcop);
11079 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11080 SvPV_shrink_to_cur(tmpstr);
11082 SvREFCNT_dec(herewas);
11084 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11086 else if (PL_encoding)
11087 sv_recode_to_utf8(tmpstr, PL_encoding);
11089 PL_lex_stuff = tmpstr;
11090 yylval.ival = op_type;
11094 /* scan_inputsymbol
11095 takes: current position in input buffer
11096 returns: new position in input buffer
11097 side-effects: yylval and lex_op are set.
11102 <FH> read from filehandle
11103 <pkg::FH> read from package qualified filehandle
11104 <pkg'FH> read from package qualified filehandle
11105 <$fh> read from filehandle in $fh
11106 <*.h> filename glob
11111 S_scan_inputsymbol(pTHX_ char *start)
11114 register char *s = start; /* current position in buffer */
11118 char *d = PL_tokenbuf; /* start of temp holding space */
11119 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11121 end = strchr(s, '\n');
11124 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11126 /* die if we didn't have space for the contents of the <>,
11127 or if it didn't end, or if we see a newline
11130 if (len >= (I32)sizeof PL_tokenbuf)
11131 Perl_croak(aTHX_ "Excessively long <> operator");
11133 Perl_croak(aTHX_ "Unterminated <> operator");
11138 Remember, only scalar variables are interpreted as filehandles by
11139 this code. Anything more complex (e.g., <$fh{$num}>) will be
11140 treated as a glob() call.
11141 This code makes use of the fact that except for the $ at the front,
11142 a scalar variable and a filehandle look the same.
11144 if (*d == '$' && d[1]) d++;
11146 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11147 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11150 /* If we've tried to read what we allow filehandles to look like, and
11151 there's still text left, then it must be a glob() and not a getline.
11152 Use scan_str to pull out the stuff between the <> and treat it
11153 as nothing more than a string.
11156 if (d - PL_tokenbuf != len) {
11157 yylval.ival = OP_GLOB;
11159 s = scan_str(start,!!PL_madskills,FALSE);
11161 Perl_croak(aTHX_ "Glob not terminated");
11165 bool readline_overriden = FALSE;
11168 /* we're in a filehandle read situation */
11171 /* turn <> into <ARGV> */
11173 Copy("ARGV",d,5,char);
11175 /* Check whether readline() is overriden */
11176 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11178 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11180 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11181 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
11182 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11183 readline_overriden = TRUE;
11185 /* if <$fh>, create the ops to turn the variable into a
11189 /* try to find it in the pad for this block, otherwise find
11190 add symbol table ops
11192 const PADOFFSET tmp = pad_findmy(d);
11193 if (tmp != NOT_IN_PAD) {
11194 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11195 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11196 HEK * const stashname = HvNAME_HEK(stash);
11197 SV * const sym = sv_2mortal(newSVhek(stashname));
11198 sv_catpvs(sym, "::");
11199 sv_catpv(sym, d+1);
11204 OP * const o = newOP(OP_PADSV, 0);
11206 PL_lex_op = readline_overriden
11207 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11208 append_elem(OP_LIST, o,
11209 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11210 : (OP*)newUNOP(OP_READLINE, 0, o);
11219 ? (GV_ADDMULTI | GV_ADDINEVAL)
11222 PL_lex_op = readline_overriden
11223 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11224 append_elem(OP_LIST,
11225 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11226 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11227 : (OP*)newUNOP(OP_READLINE, 0,
11228 newUNOP(OP_RV2SV, 0,
11229 newGVOP(OP_GV, 0, gv)));
11231 if (!readline_overriden)
11232 PL_lex_op->op_flags |= OPf_SPECIAL;
11233 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11234 yylval.ival = OP_NULL;
11237 /* If it's none of the above, it must be a literal filehandle
11238 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11240 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11241 PL_lex_op = readline_overriden
11242 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11243 append_elem(OP_LIST,
11244 newGVOP(OP_GV, 0, gv),
11245 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11246 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11247 yylval.ival = OP_NULL;
11256 takes: start position in buffer
11257 keep_quoted preserve \ on the embedded delimiter(s)
11258 keep_delims preserve the delimiters around the string
11259 returns: position to continue reading from buffer
11260 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11261 updates the read buffer.
11263 This subroutine pulls a string out of the input. It is called for:
11264 q single quotes q(literal text)
11265 ' single quotes 'literal text'
11266 qq double quotes qq(interpolate $here please)
11267 " double quotes "interpolate $here please"
11268 qx backticks qx(/bin/ls -l)
11269 ` backticks `/bin/ls -l`
11270 qw quote words @EXPORT_OK = qw( func() $spam )
11271 m// regexp match m/this/
11272 s/// regexp substitute s/this/that/
11273 tr/// string transliterate tr/this/that/
11274 y/// string transliterate y/this/that/
11275 ($*@) sub prototypes sub foo ($)
11276 (stuff) sub attr parameters sub foo : attr(stuff)
11277 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11279 In most of these cases (all but <>, patterns and transliterate)
11280 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11281 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11282 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11285 It skips whitespace before the string starts, and treats the first
11286 character as the delimiter. If the delimiter is one of ([{< then
11287 the corresponding "close" character )]}> is used as the closing
11288 delimiter. It allows quoting of delimiters, and if the string has
11289 balanced delimiters ([{<>}]) it allows nesting.
11291 On success, the SV with the resulting string is put into lex_stuff or,
11292 if that is already non-NULL, into lex_repl. The second case occurs only
11293 when parsing the RHS of the special constructs s/// and tr/// (y///).
11294 For convenience, the terminating delimiter character is stuffed into
11299 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11302 SV *sv; /* scalar value: string */
11303 char *tmps; /* temp string, used for delimiter matching */
11304 register char *s = start; /* current position in the buffer */
11305 register char term; /* terminating character */
11306 register char *to; /* current position in the sv's data */
11307 I32 brackets = 1; /* bracket nesting level */
11308 bool has_utf8 = FALSE; /* is there any utf8 content? */
11309 I32 termcode; /* terminating char. code */
11310 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11311 STRLEN termlen; /* length of terminating string */
11312 char *last = NULL; /* last position for nesting bracket */
11318 /* skip space before the delimiter */
11324 if (PL_realtokenstart >= 0) {
11325 stuffstart = PL_realtokenstart;
11326 PL_realtokenstart = -1;
11329 stuffstart = start - SvPVX(PL_linestr);
11331 /* mark where we are, in case we need to report errors */
11334 /* after skipping whitespace, the next character is the terminator */
11337 termcode = termstr[0] = term;
11341 termcode = utf8_to_uvchr((U8*)s, &termlen);
11342 Copy(s, termstr, termlen, U8);
11343 if (!UTF8_IS_INVARIANT(term))
11347 /* mark where we are */
11348 PL_multi_start = CopLINE(PL_curcop);
11349 PL_multi_open = term;
11351 /* find corresponding closing delimiter */
11352 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11353 termcode = termstr[0] = term = tmps[5];
11355 PL_multi_close = term;
11357 /* create a new SV to hold the contents. 79 is the SV's initial length.
11358 What a random number. */
11360 sv_upgrade(sv, SVt_PVIV);
11361 SvIV_set(sv, termcode);
11362 (void)SvPOK_only(sv); /* validate pointer */
11364 /* move past delimiter and try to read a complete string */
11366 sv_catpvn(sv, s, termlen);
11369 tstart = SvPVX(PL_linestr) + stuffstart;
11370 if (!PL_thisopen && !keep_delims) {
11371 PL_thisopen = newSVpvn(tstart, s - tstart);
11372 stuffstart = s - SvPVX(PL_linestr);
11376 if (PL_encoding && !UTF) {
11380 int offset = s - SvPVX_const(PL_linestr);
11381 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11382 &offset, (char*)termstr, termlen);
11383 const char * const ns = SvPVX_const(PL_linestr) + offset;
11384 char * const svlast = SvEND(sv) - 1;
11386 for (; s < ns; s++) {
11387 if (*s == '\n' && !PL_rsfp)
11388 CopLINE_inc(PL_curcop);
11391 goto read_more_line;
11393 /* handle quoted delimiters */
11394 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11396 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11398 if ((svlast-1 - t) % 2) {
11399 if (!keep_quoted) {
11400 *(svlast-1) = term;
11402 SvCUR_set(sv, SvCUR(sv) - 1);
11407 if (PL_multi_open == PL_multi_close) {
11415 for (t = w = last; t < svlast; w++, t++) {
11416 /* At here, all closes are "was quoted" one,
11417 so we don't check PL_multi_close. */
11419 if (!keep_quoted && *(t+1) == PL_multi_open)
11424 else if (*t == PL_multi_open)
11432 SvCUR_set(sv, w - SvPVX_const(sv));
11435 if (--brackets <= 0)
11440 if (!keep_delims) {
11441 SvCUR_set(sv, SvCUR(sv) - 1);
11447 /* extend sv if need be */
11448 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11449 /* set 'to' to the next character in the sv's string */
11450 to = SvPVX(sv)+SvCUR(sv);
11452 /* if open delimiter is the close delimiter read unbridle */
11453 if (PL_multi_open == PL_multi_close) {
11454 for (; s < PL_bufend; s++,to++) {
11455 /* embedded newlines increment the current line number */
11456 if (*s == '\n' && !PL_rsfp)
11457 CopLINE_inc(PL_curcop);
11458 /* handle quoted delimiters */
11459 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11460 if (!keep_quoted && s[1] == term)
11462 /* any other quotes are simply copied straight through */
11466 /* terminate when run out of buffer (the for() condition), or
11467 have found the terminator */
11468 else if (*s == term) {
11471 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11474 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11480 /* if the terminator isn't the same as the start character (e.g.,
11481 matched brackets), we have to allow more in the quoting, and
11482 be prepared for nested brackets.
11485 /* read until we run out of string, or we find the terminator */
11486 for (; s < PL_bufend; s++,to++) {
11487 /* embedded newlines increment the line count */
11488 if (*s == '\n' && !PL_rsfp)
11489 CopLINE_inc(PL_curcop);
11490 /* backslashes can escape the open or closing characters */
11491 if (*s == '\\' && s+1 < PL_bufend) {
11492 if (!keep_quoted &&
11493 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11498 /* allow nested opens and closes */
11499 else if (*s == PL_multi_close && --brackets <= 0)
11501 else if (*s == PL_multi_open)
11503 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11508 /* terminate the copied string and update the sv's end-of-string */
11510 SvCUR_set(sv, to - SvPVX_const(sv));
11513 * this next chunk reads more into the buffer if we're not done yet
11517 break; /* handle case where we are done yet :-) */
11519 #ifndef PERL_STRICT_CR
11520 if (to - SvPVX_const(sv) >= 2) {
11521 if ((to[-2] == '\r' && to[-1] == '\n') ||
11522 (to[-2] == '\n' && to[-1] == '\r'))
11526 SvCUR_set(sv, to - SvPVX_const(sv));
11528 else if (to[-1] == '\r')
11531 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11536 /* if we're out of file, or a read fails, bail and reset the current
11537 line marker so we can report where the unterminated string began
11540 if (PL_madskills) {
11541 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11543 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11545 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11549 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11551 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11557 /* we read a line, so increment our line counter */
11558 CopLINE_inc(PL_curcop);
11560 /* update debugger info */
11561 if (PERLDB_LINE && PL_curstash != PL_debstash) {
11562 SV * const line_sv = newSV(0);
11564 sv_upgrade(line_sv, SVt_PVMG);
11565 sv_setsv(line_sv,PL_linestr);
11566 (void)SvIOK_on(line_sv);
11567 SvIV_set(line_sv, 0);
11568 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop), line_sv);
11571 /* having changed the buffer, we must update PL_bufend */
11572 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11573 PL_last_lop = PL_last_uni = NULL;
11576 /* at this point, we have successfully read the delimited string */
11578 if (!PL_encoding || UTF) {
11580 if (PL_madskills) {
11581 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11582 const int len = s - start;
11584 sv_catpvn(PL_thisstuff, tstart, len);
11586 PL_thisstuff = newSVpvn(tstart, len);
11587 if (!PL_thisclose && !keep_delims)
11588 PL_thisclose = newSVpvn(s,termlen);
11593 sv_catpvn(sv, s, termlen);
11598 if (PL_madskills) {
11599 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11600 const int len = s - tstart - termlen;
11602 sv_catpvn(PL_thisstuff, tstart, len);
11604 PL_thisstuff = newSVpvn(tstart, len);
11605 if (!PL_thisclose && !keep_delims)
11606 PL_thisclose = newSVpvn(s - termlen,termlen);
11610 if (has_utf8 || PL_encoding)
11613 PL_multi_end = CopLINE(PL_curcop);
11615 /* if we allocated too much space, give some back */
11616 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11617 SvLEN_set(sv, SvCUR(sv) + 1);
11618 SvPV_renew(sv, SvLEN(sv));
11621 /* decide whether this is the first or second quoted string we've read
11634 takes: pointer to position in buffer
11635 returns: pointer to new position in buffer
11636 side-effects: builds ops for the constant in yylval.op
11638 Read a number in any of the formats that Perl accepts:
11640 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11641 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11644 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11646 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11649 If it reads a number without a decimal point or an exponent, it will
11650 try converting the number to an integer and see if it can do so
11651 without loss of precision.
11655 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11658 register const char *s = start; /* current position in buffer */
11659 register char *d; /* destination in temp buffer */
11660 register char *e; /* end of temp buffer */
11661 NV nv; /* number read, as a double */
11662 SV *sv = NULL; /* place to put the converted number */
11663 bool floatit; /* boolean: int or float? */
11664 const char *lastub = NULL; /* position of last underbar */
11665 static char const number_too_long[] = "Number too long";
11667 /* We use the first character to decide what type of number this is */
11671 Perl_croak(aTHX_ "panic: scan_num");
11673 /* if it starts with a 0, it could be an octal number, a decimal in
11674 0.13 disguise, or a hexadecimal number, or a binary number. */
11678 u holds the "number so far"
11679 shift the power of 2 of the base
11680 (hex == 4, octal == 3, binary == 1)
11681 overflowed was the number more than we can hold?
11683 Shift is used when we add a digit. It also serves as an "are
11684 we in octal/hex/binary?" indicator to disallow hex characters
11685 when in octal mode.
11690 bool overflowed = FALSE;
11691 bool just_zero = TRUE; /* just plain 0 or binary number? */
11692 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11693 static const char* const bases[5] =
11694 { "", "binary", "", "octal", "hexadecimal" };
11695 static const char* const Bases[5] =
11696 { "", "Binary", "", "Octal", "Hexadecimal" };
11697 static const char* const maxima[5] =
11699 "0b11111111111111111111111111111111",
11703 const char *base, *Base, *max;
11705 /* check for hex */
11710 } else if (s[1] == 'b') {
11715 /* check for a decimal in disguise */
11716 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11718 /* so it must be octal */
11725 if (ckWARN(WARN_SYNTAX))
11726 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11727 "Misplaced _ in number");
11731 base = bases[shift];
11732 Base = Bases[shift];
11733 max = maxima[shift];
11735 /* read the rest of the number */
11737 /* x is used in the overflow test,
11738 b is the digit we're adding on. */
11743 /* if we don't mention it, we're done */
11747 /* _ are ignored -- but warned about if consecutive */
11749 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11750 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11751 "Misplaced _ in number");
11755 /* 8 and 9 are not octal */
11756 case '8': case '9':
11758 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11762 case '2': case '3': case '4':
11763 case '5': case '6': case '7':
11765 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11768 case '0': case '1':
11769 b = *s++ & 15; /* ASCII digit -> value of digit */
11773 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11774 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
11775 /* make sure they said 0x */
11778 b = (*s++ & 7) + 9;
11780 /* Prepare to put the digit we have onto the end
11781 of the number so far. We check for overflows.
11787 x = u << shift; /* make room for the digit */
11789 if ((x >> shift) != u
11790 && !(PL_hints & HINT_NEW_BINARY)) {
11793 if (ckWARN_d(WARN_OVERFLOW))
11794 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11795 "Integer overflow in %s number",
11798 u = x | b; /* add the digit to the end */
11801 n *= nvshift[shift];
11802 /* If an NV has not enough bits in its
11803 * mantissa to represent an UV this summing of
11804 * small low-order numbers is a waste of time
11805 * (because the NV cannot preserve the
11806 * low-order bits anyway): we could just
11807 * remember when did we overflow and in the
11808 * end just multiply n by the right
11816 /* if we get here, we had success: make a scalar value from
11821 /* final misplaced underbar check */
11822 if (s[-1] == '_') {
11823 if (ckWARN(WARN_SYNTAX))
11824 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11829 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
11830 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11831 "%s number > %s non-portable",
11837 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
11838 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11839 "%s number > %s non-portable",
11844 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
11845 sv = new_constant(start, s - start, "integer",
11847 else if (PL_hints & HINT_NEW_BINARY)
11848 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
11853 handle decimal numbers.
11854 we're also sent here when we read a 0 as the first digit
11856 case '1': case '2': case '3': case '4': case '5':
11857 case '6': case '7': case '8': case '9': case '.':
11860 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
11863 /* read next group of digits and _ and copy into d */
11864 while (isDIGIT(*s) || *s == '_') {
11865 /* skip underscores, checking for misplaced ones
11869 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11870 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11871 "Misplaced _ in number");
11875 /* check for end of fixed-length buffer */
11877 Perl_croak(aTHX_ number_too_long);
11878 /* if we're ok, copy the character */
11883 /* final misplaced underbar check */
11884 if (lastub && s == lastub + 1) {
11885 if (ckWARN(WARN_SYNTAX))
11886 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11889 /* read a decimal portion if there is one. avoid
11890 3..5 being interpreted as the number 3. followed
11893 if (*s == '.' && s[1] != '.') {
11898 if (ckWARN(WARN_SYNTAX))
11899 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11900 "Misplaced _ in number");
11904 /* copy, ignoring underbars, until we run out of digits.
11906 for (; isDIGIT(*s) || *s == '_'; s++) {
11907 /* fixed length buffer check */
11909 Perl_croak(aTHX_ number_too_long);
11911 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11912 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11913 "Misplaced _ in number");
11919 /* fractional part ending in underbar? */
11920 if (s[-1] == '_') {
11921 if (ckWARN(WARN_SYNTAX))
11922 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11923 "Misplaced _ in number");
11925 if (*s == '.' && isDIGIT(s[1])) {
11926 /* oops, it's really a v-string, but without the "v" */
11932 /* read exponent part, if present */
11933 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
11937 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
11938 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
11940 /* stray preinitial _ */
11942 if (ckWARN(WARN_SYNTAX))
11943 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11944 "Misplaced _ in number");
11948 /* allow positive or negative exponent */
11949 if (*s == '+' || *s == '-')
11952 /* stray initial _ */
11954 if (ckWARN(WARN_SYNTAX))
11955 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11956 "Misplaced _ in number");
11960 /* read digits of exponent */
11961 while (isDIGIT(*s) || *s == '_') {
11964 Perl_croak(aTHX_ number_too_long);
11968 if (((lastub && s == lastub + 1) ||
11969 (!isDIGIT(s[1]) && s[1] != '_'))
11970 && ckWARN(WARN_SYNTAX))
11971 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11972 "Misplaced _ in number");
11979 /* make an sv from the string */
11983 We try to do an integer conversion first if no characters
11984 indicating "float" have been found.
11989 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
11991 if (flags == IS_NUMBER_IN_UV) {
11993 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
11996 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
11997 if (uv <= (UV) IV_MIN)
11998 sv_setiv(sv, -(IV)uv);
12005 /* terminate the string */
12007 nv = Atof(PL_tokenbuf);
12011 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12012 (PL_hints & HINT_NEW_INTEGER) )
12013 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
12014 (floatit ? "float" : "integer"),
12018 /* if it starts with a v, it could be a v-string */
12021 sv = newSV(5); /* preallocate storage space */
12022 s = scan_vstring(s,sv);
12026 /* make the op for the constant and return */
12029 lvalp->opval = newSVOP(OP_CONST, 0, sv);
12031 lvalp->opval = NULL;
12037 S_scan_formline(pTHX_ register char *s)
12040 register char *eol;
12042 SV * const stuff = newSVpvs("");
12043 bool needargs = FALSE;
12044 bool eofmt = FALSE;
12046 char *tokenstart = s;
12049 if (PL_madskills) {
12050 savewhite = PL_thiswhite;
12055 while (!needargs) {
12058 #ifdef PERL_STRICT_CR
12059 while (SPACE_OR_TAB(*t))
12062 while (SPACE_OR_TAB(*t) || *t == '\r')
12065 if (*t == '\n' || t == PL_bufend) {
12070 if (PL_in_eval && !PL_rsfp) {
12071 eol = (char *) memchr(s,'\n',PL_bufend-s);
12076 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12078 for (t = s; t < eol; t++) {
12079 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12081 goto enough; /* ~~ must be first line in formline */
12083 if (*t == '@' || *t == '^')
12087 sv_catpvn(stuff, s, eol-s);
12088 #ifndef PERL_STRICT_CR
12089 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12090 char *end = SvPVX(stuff) + SvCUR(stuff);
12093 SvCUR_set(stuff, SvCUR(stuff) - 1);
12103 if (PL_madskills) {
12105 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12107 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12110 s = filter_gets(PL_linestr, PL_rsfp, 0);
12112 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12114 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12116 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12117 PL_last_lop = PL_last_uni = NULL;
12126 if (SvCUR(stuff)) {
12129 PL_lex_state = LEX_NORMAL;
12130 start_force(PL_curforce);
12131 NEXTVAL_NEXTTOKE.ival = 0;
12135 PL_lex_state = LEX_FORMLINE;
12137 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12139 else if (PL_encoding)
12140 sv_recode_to_utf8(stuff, PL_encoding);
12142 start_force(PL_curforce);
12143 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12145 start_force(PL_curforce);
12146 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12150 SvREFCNT_dec(stuff);
12152 PL_lex_formbrack = 0;
12156 if (PL_madskills) {
12158 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12160 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12161 PL_thiswhite = savewhite;
12173 PL_cshlen = strlen(PL_cshname);
12175 #if defined(USE_ITHREADS)
12176 PERL_UNUSED_CONTEXT;
12182 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12185 const I32 oldsavestack_ix = PL_savestack_ix;
12186 CV* const outsidecv = PL_compcv;
12189 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12191 SAVEI32(PL_subline);
12192 save_item(PL_subname);
12193 SAVESPTR(PL_compcv);
12195 PL_compcv = (CV*)newSV(0);
12196 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
12197 CvFLAGS(PL_compcv) |= flags;
12199 PL_subline = CopLINE(PL_curcop);
12200 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12201 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12202 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12204 return oldsavestack_ix;
12208 #pragma segment Perl_yylex
12211 Perl_yywarn(pTHX_ const char *s)
12214 PL_in_eval |= EVAL_WARNONLY;
12216 PL_in_eval &= ~EVAL_WARNONLY;
12221 Perl_yyerror(pTHX_ const char *s)
12224 const char *where = NULL;
12225 const char *context = NULL;
12229 if (!yychar || (yychar == ';' && !PL_rsfp))
12231 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12232 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12233 PL_oldbufptr != PL_bufptr) {
12236 The code below is removed for NetWare because it abends/crashes on NetWare
12237 when the script has error such as not having the closing quotes like:
12238 if ($var eq "value)
12239 Checking of white spaces is anyway done in NetWare code.
12242 while (isSPACE(*PL_oldoldbufptr))
12245 context = PL_oldoldbufptr;
12246 contlen = PL_bufptr - PL_oldoldbufptr;
12248 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12249 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12252 The code below is removed for NetWare because it abends/crashes on NetWare
12253 when the script has error such as not having the closing quotes like:
12254 if ($var eq "value)
12255 Checking of white spaces is anyway done in NetWare code.
12258 while (isSPACE(*PL_oldbufptr))
12261 context = PL_oldbufptr;
12262 contlen = PL_bufptr - PL_oldbufptr;
12264 else if (yychar > 255)
12265 where = "next token ???";
12266 else if (yychar == -2) { /* YYEMPTY */
12267 if (PL_lex_state == LEX_NORMAL ||
12268 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12269 where = "at end of line";
12270 else if (PL_lex_inpat)
12271 where = "within pattern";
12273 where = "within string";
12276 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12278 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12279 else if (isPRINT_LC(yychar))
12280 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12282 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12283 where = SvPVX_const(where_sv);
12285 msg = sv_2mortal(newSVpv(s, 0));
12286 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12287 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12289 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12291 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12292 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12293 Perl_sv_catpvf(aTHX_ msg,
12294 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12295 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12298 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12299 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, (void*)msg);
12302 if (PL_error_count >= 10) {
12303 if (PL_in_eval && SvCUR(ERRSV))
12304 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12305 (void*)ERRSV, OutCopFILE(PL_curcop));
12307 Perl_croak(aTHX_ "%s has too many errors.\n",
12308 OutCopFILE(PL_curcop));
12311 PL_in_my_stash = NULL;
12315 #pragma segment Main
12319 S_swallow_bom(pTHX_ U8 *s)
12322 const STRLEN slen = SvCUR(PL_linestr);
12325 if (s[1] == 0xFE) {
12326 /* UTF-16 little-endian? (or UTF32-LE?) */
12327 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12328 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12329 #ifndef PERL_NO_UTF16_FILTER
12330 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12333 if (PL_bufend > (char*)s) {
12337 filter_add(utf16rev_textfilter, NULL);
12338 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12339 utf16_to_utf8_reversed(s, news,
12340 PL_bufend - (char*)s - 1,
12342 sv_setpvn(PL_linestr, (const char*)news, newlen);
12344 s = (U8*)SvPVX(PL_linestr);
12345 Copy(news, s, newlen, U8);
12349 SvUTF8_on(PL_linestr);
12350 s = (U8*)SvPVX(PL_linestr);
12352 /* FIXME - is this a general bug fix? */
12355 PL_bufend = SvPVX(PL_linestr) + newlen;
12358 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12363 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12364 #ifndef PERL_NO_UTF16_FILTER
12365 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12368 if (PL_bufend > (char *)s) {
12372 filter_add(utf16_textfilter, NULL);
12373 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12374 utf16_to_utf8(s, news,
12375 PL_bufend - (char*)s,
12377 sv_setpvn(PL_linestr, (const char*)news, newlen);
12379 SvUTF8_on(PL_linestr);
12380 s = (U8*)SvPVX(PL_linestr);
12381 PL_bufend = SvPVX(PL_linestr) + newlen;
12384 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12389 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12390 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12391 s += 3; /* UTF-8 */
12397 if (s[2] == 0xFE && s[3] == 0xFF) {
12398 /* UTF-32 big-endian */
12399 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12402 else if (s[2] == 0 && s[3] != 0) {
12405 * are a good indicator of UTF-16BE. */
12406 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12411 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12414 * are a good indicator of UTF-16LE. */
12415 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12424 * Restore a source filter.
12428 restore_rsfp(pTHX_ void *f)
12431 PerlIO * const fp = (PerlIO*)f;
12433 if (PL_rsfp == PerlIO_stdin())
12434 PerlIO_clearerr(PL_rsfp);
12435 else if (PL_rsfp && (PL_rsfp != fp))
12436 PerlIO_close(PL_rsfp);
12440 #ifndef PERL_NO_UTF16_FILTER
12442 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12445 const STRLEN old = SvCUR(sv);
12446 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12447 DEBUG_P(PerlIO_printf(Perl_debug_log,
12448 "utf16_textfilter(%p): %d %d (%d)\n",
12449 FPTR2DPTR(void *, utf16_textfilter),
12450 idx, maxlen, (int) count));
12454 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12455 Copy(SvPVX_const(sv), tmps, old, char);
12456 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12457 SvCUR(sv) - old, &newlen);
12458 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12460 DEBUG_P({sv_dump(sv);});
12465 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12468 const STRLEN old = SvCUR(sv);
12469 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12470 DEBUG_P(PerlIO_printf(Perl_debug_log,
12471 "utf16rev_textfilter(%p): %d %d (%d)\n",
12472 FPTR2DPTR(void *, utf16rev_textfilter),
12473 idx, maxlen, (int) count));
12477 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12478 Copy(SvPVX_const(sv), tmps, old, char);
12479 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12480 SvCUR(sv) - old, &newlen);
12481 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12483 DEBUG_P({ sv_dump(sv); });
12489 Returns a pointer to the next character after the parsed
12490 vstring, as well as updating the passed in sv.
12492 Function must be called like
12495 s = scan_vstring(s,sv);
12497 The sv should already be large enough to store the vstring
12498 passed in, for performance reasons.
12503 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
12506 const char *pos = s;
12507 const char *start = s;
12508 if (*pos == 'v') pos++; /* get past 'v' */
12509 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12511 if ( *pos != '.') {
12512 /* this may not be a v-string if followed by => */
12513 const char *next = pos;
12514 while (next < PL_bufend && isSPACE(*next))
12516 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
12517 /* return string not v-string */
12518 sv_setpvn(sv,(char *)s,pos-s);
12519 return (char *)pos;
12523 if (!isALPHA(*pos)) {
12524 U8 tmpbuf[UTF8_MAXBYTES+1];
12527 s++; /* get past 'v' */
12529 sv_setpvn(sv, "", 0);
12532 /* this is atoi() that tolerates underscores */
12535 const char *end = pos;
12537 while (--end >= s) {
12539 const UV orev = rev;
12540 rev += (*end - '0') * mult;
12542 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12543 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12544 "Integer overflow in decimal number");
12548 if (rev > 0x7FFFFFFF)
12549 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12551 /* Append native character for the rev point */
12552 tmpend = uvchr_to_utf8(tmpbuf, rev);
12553 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12554 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12556 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
12562 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12566 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12574 * c-indentation-style: bsd
12575 * c-basic-offset: 4
12576 * indent-tabs-mode: t
12579 * ex: set ts=8 sts=4 sw=4 noet: