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 /* XXX these probably need to be made into PL vars */
40 static I32 realtokenstart;
41 static I32 faketokens = 0;
42 static MADPROP *thismad;
51 static I32 curforce = -1;
53 # define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
54 # define NEXTVAL_NEXTTOKE PL_nexttoke[curforce].next_val
56 # define CURMAD(slot,sv)
57 # define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
60 #define XFAKEBRACK 128
63 #ifdef USE_UTF8_SCRIPTS
64 # define UTF (!IN_BYTES)
66 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
69 /* In variables named $^X, these are the legal values for X.
70 * 1999-02-27 mjd-perl-patch@plover.com */
71 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
73 /* On MacOS, respect nonbreaking spaces */
74 #ifdef MACOS_TRADITIONAL
75 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
77 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
80 /* LEX_* are values for PL_lex_state, the state of the lexer.
81 * They are arranged oddly so that the guard on the switch statement
82 * can get by with a single comparison (if the compiler is smart enough).
85 /* #define LEX_NOTPARSING 11 is done in perl.h. */
87 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
88 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
89 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
90 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
91 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
93 /* at end of code, eg "$x" followed by: */
94 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
95 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
97 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
98 string or after \E, $foo, etc */
99 #define LEX_INTERPCONST 2 /* NOT USED */
100 #define LEX_FORMLINE 1 /* expecting a format line */
101 #define LEX_KNOWNEXT 0 /* next token known; just return it */
105 static const char* const lex_state_names[] = {
124 #include "keywords.h"
126 /* CLINE is a macro that ensures PL_copline has a sane value */
131 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
134 # define SKIPSPACE0(s) skipspace0(s)
135 # define SKIPSPACE1(s) skipspace1(s)
136 # define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
137 # define PEEKSPACE(s) skipspace2(s,0)
139 # define SKIPSPACE0(s) skipspace(s)
140 # define SKIPSPACE1(s) skipspace(s)
141 # define SKIPSPACE2(s,tsv) skipspace(s)
142 # define PEEKSPACE(s) skipspace(s)
146 * Convenience functions to return different tokens and prime the
147 * lexer for the next token. They all take an argument.
149 * TOKEN : generic token (used for '(', DOLSHARP, etc)
150 * OPERATOR : generic operator
151 * AOPERATOR : assignment operator
152 * PREBLOCK : beginning the block after an if, while, foreach, ...
153 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
154 * PREREF : *EXPR where EXPR is not a simple identifier
155 * TERM : expression term
156 * LOOPX : loop exiting command (goto, last, dump, etc)
157 * FTST : file test operator
158 * FUN0 : zero-argument function
159 * FUN1 : not used, except for not, which isn't a UNIOP
160 * BOop : bitwise or or xor
162 * SHop : shift operator
163 * PWop : power operator
164 * PMop : pattern-matching operator
165 * Aop : addition-level operator
166 * Mop : multiplication-level operator
167 * Eop : equality-testing operator
168 * Rop : relational operator <= != gt
170 * Also see LOP and lop() below.
173 #ifdef DEBUGGING /* Serve -DT. */
174 # define REPORT(retval) tokereport((I32)retval)
176 # define REPORT(retval) (retval)
179 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
180 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
181 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
182 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
183 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
184 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
185 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
186 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
187 #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
188 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
189 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
190 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
191 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
192 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
193 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
194 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
195 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
196 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
197 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
198 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
200 /* This bit of chicanery makes a unary function followed by
201 * a parenthesis into a function with one argument, highest precedence.
202 * The UNIDOR macro is for unary functions that can be followed by the //
203 * operator (such as C<shift // 0>).
205 #define UNI2(f,x) { \
209 PL_last_uni = PL_oldbufptr; \
210 PL_last_lop_op = f; \
212 return REPORT( (int)FUNC1 ); \
214 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
216 #define UNI(f) UNI2(f,XTERM)
217 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
219 #define UNIBRACK(f) { \
222 PL_last_uni = PL_oldbufptr; \
224 return REPORT( (int)FUNC1 ); \
226 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
229 /* grandfather return to old style */
230 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
234 /* how to interpret the yylval associated with the token */
238 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
244 static struct debug_tokens {
246 enum token_type type;
248 } const debug_tokens[] =
250 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
251 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
252 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
253 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
254 { ARROW, TOKENTYPE_NONE, "ARROW" },
255 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
256 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
257 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
258 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
259 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
260 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
261 { DO, TOKENTYPE_NONE, "DO" },
262 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
263 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
264 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
265 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
266 { ELSE, TOKENTYPE_NONE, "ELSE" },
267 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
268 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
269 { FOR, TOKENTYPE_IVAL, "FOR" },
270 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
271 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
272 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
273 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
274 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
275 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
276 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
277 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
278 { IF, TOKENTYPE_IVAL, "IF" },
279 { LABEL, TOKENTYPE_PVAL, "LABEL" },
280 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
281 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
282 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
283 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
284 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
285 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
286 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
287 { MY, TOKENTYPE_IVAL, "MY" },
288 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
289 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
290 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
291 { OROP, TOKENTYPE_IVAL, "OROP" },
292 { OROR, TOKENTYPE_NONE, "OROR" },
293 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
294 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
295 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
296 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
297 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
298 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
299 { PREINC, TOKENTYPE_NONE, "PREINC" },
300 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
301 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
302 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
303 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
304 { SUB, TOKENTYPE_NONE, "SUB" },
305 { THING, TOKENTYPE_OPVAL, "THING" },
306 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
307 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
308 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
309 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
310 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
311 { USE, TOKENTYPE_IVAL, "USE" },
312 { WHEN, TOKENTYPE_IVAL, "WHEN" },
313 { WHILE, TOKENTYPE_IVAL, "WHILE" },
314 { WORD, TOKENTYPE_OPVAL, "WORD" },
315 { 0, TOKENTYPE_NONE, 0 }
318 /* dump the returned token in rv, plus any optional arg in yylval */
321 S_tokereport(pTHX_ I32 rv)
325 const char *name = NULL;
326 enum token_type type = TOKENTYPE_NONE;
327 const struct debug_tokens *p;
328 SV* const report = newSVpvs("<== ");
330 for (p = debug_tokens; p->token; p++) {
331 if (p->token == (int)rv) {
338 Perl_sv_catpv(aTHX_ report, name);
339 else if ((char)rv > ' ' && (char)rv < '~')
340 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
342 sv_catpvs(report, "EOF");
344 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
347 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
350 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
352 case TOKENTYPE_OPNUM:
353 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
354 PL_op_name[yylval.ival]);
357 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
359 case TOKENTYPE_OPVAL:
361 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
362 PL_op_name[yylval.opval->op_type]);
363 if (yylval.opval->op_type == OP_CONST) {
364 Perl_sv_catpvf(aTHX_ report, " %s",
365 SvPEEK(cSVOPx_sv(yylval.opval)));
370 sv_catpvs(report, "(opval=null)");
373 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
379 /* print the buffer with suitable escapes */
382 S_printbuf(pTHX_ const char* fmt, const char* s)
384 SV* const tmp = newSVpvs("");
385 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
394 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
395 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
399 S_ao(pTHX_ int toketype)
402 if (*PL_bufptr == '=') {
404 if (toketype == ANDAND)
405 yylval.ival = OP_ANDASSIGN;
406 else if (toketype == OROR)
407 yylval.ival = OP_ORASSIGN;
408 else if (toketype == DORDOR)
409 yylval.ival = OP_DORASSIGN;
417 * When Perl expects an operator and finds something else, no_op
418 * prints the warning. It always prints "<something> found where
419 * operator expected. It prints "Missing semicolon on previous line?"
420 * if the surprise occurs at the start of the line. "do you need to
421 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
422 * where the compiler doesn't know if foo is a method call or a function.
423 * It prints "Missing operator before end of line" if there's nothing
424 * after the missing operator, or "... before <...>" if there is something
425 * after the missing operator.
429 S_no_op(pTHX_ const char *what, char *s)
432 char * const oldbp = PL_bufptr;
433 const bool is_first = (PL_oldbufptr == PL_linestart);
439 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
440 if (ckWARN_d(WARN_SYNTAX)) {
442 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
443 "\t(Missing semicolon on previous line?)\n");
444 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
446 for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ;
447 if (t < PL_bufptr && isSPACE(*t))
448 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
449 "\t(Do you need to predeclare %.*s?)\n",
450 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
454 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
455 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
463 * Complain about missing quote/regexp/heredoc terminator.
464 * If it's called with (char *)NULL then it cauterizes the line buffer.
465 * If we're in a delimited string and the delimiter is a control
466 * character, it's reformatted into a two-char sequence like ^C.
471 S_missingterm(pTHX_ char *s)
477 char * const nl = strrchr(s,'\n');
483 iscntrl(PL_multi_close)
485 PL_multi_close < 32 || PL_multi_close == 127
489 tmpbuf[1] = (char)toCTRL(PL_multi_close);
494 *tmpbuf = (char)PL_multi_close;
498 q = strchr(s,'"') ? '\'' : '"';
499 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
502 #define FEATURE_IS_ENABLED(name) \
503 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
504 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
506 * S_feature_is_enabled
507 * Check whether the named feature is enabled.
510 S_feature_is_enabled(pTHX_ char *name, STRLEN namelen)
513 HV * const hinthv = GvHV(PL_hintgv);
514 char he_name[32] = "feature_";
515 (void) strncpy(&he_name[8], name, 24);
517 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
525 Perl_deprecate(pTHX_ const char *s)
527 if (ckWARN(WARN_DEPRECATED))
528 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
532 Perl_deprecate_old(pTHX_ const char *s)
534 /* This function should NOT be called for any new deprecated warnings */
535 /* Use Perl_deprecate instead */
537 /* It is here to maintain backward compatibility with the pre-5.8 */
538 /* warnings category hierarchy. The "deprecated" category used to */
539 /* live under the "syntax" category. It is now a top-level category */
540 /* in its own right. */
542 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
543 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
544 "Use of %s is deprecated", s);
548 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
549 * utf16-to-utf8-reversed.
552 #ifdef PERL_CR_FILTER
556 register const char *s = SvPVX_const(sv);
557 register const char * const e = s + SvCUR(sv);
558 /* outer loop optimized to do nothing if there are no CR-LFs */
560 if (*s++ == '\r' && *s == '\n') {
561 /* hit a CR-LF, need to copy the rest */
562 register char *d = s - 1;
565 if (*s == '\r' && s[1] == '\n')
576 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
578 const I32 count = FILTER_READ(idx+1, sv, maxlen);
579 if (count > 0 && !maxlen)
587 * Initialize variables. Uses the Perl save_stack to save its state (for
588 * recursive calls to the parser).
592 Perl_lex_start(pTHX_ SV *line)
598 SAVEI32(PL_lex_dojoin);
599 SAVEI32(PL_lex_brackets);
600 SAVEI32(PL_lex_casemods);
601 SAVEI32(PL_lex_starts);
602 SAVEI32(PL_lex_state);
603 SAVEVPTR(PL_lex_inpat);
604 SAVEI32(PL_lex_inwhat);
606 if (PL_lex_state == LEX_KNOWNEXT) {
607 I32 toke = PL_lasttoke;
608 while (--toke >= 0) {
609 SAVEI32(PL_nexttoke[toke].next_type);
610 SAVEVPTR(PL_nexttoke[toke].next_val);
612 SAVEVPTR(PL_nexttoke[toke].next_mad);
614 SAVEI32(PL_lasttoke);
624 SAVEI32(realtokenstart);
629 if (PL_lex_state == LEX_KNOWNEXT) {
630 I32 toke = PL_nexttoke;
631 while (--toke >= 0) {
632 SAVEI32(PL_nexttype[toke]);
633 SAVEVPTR(PL_nextval[toke]);
635 SAVEI32(PL_nexttoke);
638 SAVECOPLINE(PL_curcop);
641 SAVEPPTR(PL_oldbufptr);
642 SAVEPPTR(PL_oldoldbufptr);
643 SAVEPPTR(PL_last_lop);
644 SAVEPPTR(PL_last_uni);
645 SAVEPPTR(PL_linestart);
646 SAVESPTR(PL_linestr);
647 SAVEGENERICPV(PL_lex_brackstack);
648 SAVEGENERICPV(PL_lex_casestack);
649 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
650 SAVESPTR(PL_lex_stuff);
651 SAVEI32(PL_lex_defer);
652 SAVEI32(PL_sublex_info.sub_inwhat);
653 SAVESPTR(PL_lex_repl);
655 SAVEINT(PL_lex_expect);
657 PL_lex_state = LEX_NORMAL;
661 Newx(PL_lex_brackstack, 120, char);
662 Newx(PL_lex_casestack, 12, char);
664 *PL_lex_casestack = '\0';
676 PL_sublex_info.sub_inwhat = 0;
678 if (SvREADONLY(PL_linestr))
679 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
680 s = SvPV_const(PL_linestr, len);
681 if (!len || s[len-1] != ';') {
682 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
683 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
684 sv_catpvs(PL_linestr, "\n;");
686 SvTEMP_off(PL_linestr);
687 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
688 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
689 PL_last_lop = PL_last_uni = NULL;
695 * Finalizer for lexing operations. Must be called when the parser is
696 * done with the lexer.
703 PL_doextract = FALSE;
708 * This subroutine has nothing to do with tilting, whether at windmills
709 * or pinball tables. Its name is short for "increment line". It
710 * increments the current line number in CopLINE(PL_curcop) and checks
711 * to see whether the line starts with a comment of the form
712 * # line 500 "foo.pm"
713 * If so, it sets the current line number and file to the values in the comment.
717 S_incline(pTHX_ char *s)
725 CopLINE_inc(PL_curcop);
728 while (SPACE_OR_TAB(*s)) s++;
729 if (strnEQ(s, "line", 4))
733 if (SPACE_OR_TAB(*s))
737 while (SPACE_OR_TAB(*s)) s++;
743 while (SPACE_OR_TAB(*s))
745 if (*s == '"' && (t = strchr(s+1, '"'))) {
750 for (t = s; !isSPACE(*t); t++) ;
753 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
755 if (*e != '\n' && *e != '\0')
756 return; /* false alarm */
762 const char * const cf = CopFILE(PL_curcop);
763 STRLEN tmplen = cf ? strlen(cf) : 0;
764 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
765 /* must copy *{"::_<(eval N)[oldfilename:L]"}
766 * to *{"::_<newfilename"} */
767 char smallbuf[256], smallbuf2[256];
768 char *tmpbuf, *tmpbuf2;
770 STRLEN tmplen2 = strlen(s);
771 if (tmplen + 3 < sizeof smallbuf)
774 Newx(tmpbuf, tmplen + 3, char);
775 if (tmplen2 + 3 < sizeof smallbuf2)
778 Newx(tmpbuf2, tmplen2 + 3, char);
779 tmpbuf[0] = tmpbuf2[0] = '_';
780 tmpbuf[1] = tmpbuf2[1] = '<';
781 memcpy(tmpbuf + 2, cf, ++tmplen);
782 memcpy(tmpbuf2 + 2, s, ++tmplen2);
784 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
786 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
788 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
789 /* adjust ${"::_<newfilename"} to store the new file name */
790 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
791 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
792 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
794 if (tmpbuf != smallbuf) Safefree(tmpbuf);
795 if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
798 CopFILE_free(PL_curcop);
799 CopFILE_set(PL_curcop, s);
802 CopLINE_set(PL_curcop, atoi(n)-1);
806 /* skip space before thistoken */
809 S_skipspace0(pTHX_ register char *s)
816 thiswhite = newSVpvn("",0);
817 sv_catsv(thiswhite, skipwhite);
821 realtokenstart = s - SvPVX(PL_linestr);
825 /* skip space after thistoken */
828 S_skipspace1(pTHX_ register char *s)
831 I32 startoff = start - SvPVX(PL_linestr);
836 start = SvPVX(PL_linestr) + startoff;
837 if (!thistoken && realtokenstart >= 0) {
838 char *tstart = SvPVX(PL_linestr) + realtokenstart;
839 thistoken = newSVpvn(tstart, start - tstart);
844 nextwhite = newSVpvn("",0);
845 sv_catsv(nextwhite, skipwhite);
853 S_skipspace2(pTHX_ register char *s, SV **svp)
856 I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
857 I32 startoff = start - SvPVX(PL_linestr);
859 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
860 if (!PL_madskills || !svp)
862 start = SvPVX(PL_linestr) + startoff;
863 if (!thistoken && realtokenstart >= 0) {
864 char *tstart = SvPVX(PL_linestr) + realtokenstart;
865 thistoken = newSVpvn(tstart, start - tstart);
870 *svp = newSVpvn("",0);
871 sv_setsv(*svp, skipwhite);
882 * Called to gobble the appropriate amount and type of whitespace.
883 * Skips comments as well.
887 S_skipspace(pTHX_ register char *s)
892 int startoff = s - SvPVX(PL_linestr);
900 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
901 while (s < PL_bufend && SPACE_OR_TAB(*s))
911 SSize_t oldprevlen, oldoldprevlen;
912 SSize_t oldloplen = 0, oldunilen = 0;
913 while (s < PL_bufend && isSPACE(*s)) {
914 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
919 if (s < PL_bufend && *s == '#') {
920 while (s < PL_bufend && *s != '\n')
924 if (PL_in_eval && !PL_rsfp) {
931 /* only continue to recharge the buffer if we're at the end
932 * of the buffer, we're not reading from a source filter, and
933 * we're in normal lexing mode
935 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
936 PL_lex_state == LEX_FORMLINE)
943 /* try to recharge the buffer */
945 curoff = s - SvPVX(PL_linestr);
948 if ((s = filter_gets(PL_linestr, PL_rsfp,
949 (prevlen = SvCUR(PL_linestr)))) == NULL)
952 if (PL_madskills && curoff != startoff) {
954 skipwhite = newSVpvn("",0);
955 sv_catpvn(skipwhite, SvPVX(PL_linestr) + startoff,
959 /* mustn't throw out old stuff yet if madpropping */
960 SvCUR(PL_linestr) = curoff;
961 s = SvPVX(PL_linestr) + curoff;
963 if (curoff && s[-1] == '\n')
967 /* end of file. Add on the -p or -n magic */
968 /* XXX these shouldn't really be added here, can't set faketokens */
972 ";}continue{print or die qq(-p destination: $!\\n);}");
975 ";}continue{print or die qq(-p destination: $!\\n);}");
977 PL_minus_n = PL_minus_p = 0;
979 else if (PL_minus_n) {
981 sv_catpvn(PL_linestr, ";}", 2);
983 sv_setpvn(PL_linestr, ";}", 2);
989 sv_catpvn(PL_linestr,";", 1);
991 sv_setpvn(PL_linestr,";", 1);
994 /* reset variables for next time we lex */
995 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
1001 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1002 PL_last_lop = PL_last_uni = NULL;
1004 /* Close the filehandle. Could be from -P preprocessor,
1005 * STDIN, or a regular file. If we were reading code from
1006 * STDIN (because the commandline held no -e or filename)
1007 * then we don't close it, we reset it so the code can
1008 * read from STDIN too.
1011 if (PL_preprocess && !PL_in_eval)
1012 (void)PerlProc_pclose(PL_rsfp);
1013 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1014 PerlIO_clearerr(PL_rsfp);
1016 (void)PerlIO_close(PL_rsfp);
1021 /* not at end of file, so we only read another line */
1022 /* make corresponding updates to old pointers, for yyerror() */
1023 oldprevlen = PL_oldbufptr - PL_bufend;
1024 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1026 oldunilen = PL_last_uni - PL_bufend;
1028 oldloplen = PL_last_lop - PL_bufend;
1029 PL_linestart = PL_bufptr = s + prevlen;
1030 PL_bufend = s + SvCUR(PL_linestr);
1032 PL_oldbufptr = s + oldprevlen;
1033 PL_oldoldbufptr = s + oldoldprevlen;
1035 PL_last_uni = s + oldunilen;
1037 PL_last_lop = s + oldloplen;
1040 /* debugger active and we're not compiling the debugger code,
1041 * so store the line into the debugger's array of lines
1043 if (PERLDB_LINE && PL_curstash != PL_debstash) {
1044 SV * const sv = newSV(0);
1046 sv_upgrade(sv, SVt_PVMG);
1047 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
1050 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
1058 skipwhite = newSVpvn("",0);
1059 curoff = s - SvPVX(PL_linestr);
1060 if (curoff - startoff)
1061 sv_catpvn(skipwhite, SvPVX(PL_linestr) + startoff,
1070 * Check the unary operators to ensure there's no ambiguity in how they're
1071 * used. An ambiguous piece of code would be:
1073 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1074 * the +5 is its argument.
1084 if (PL_oldoldbufptr != PL_last_uni)
1086 while (isSPACE(*PL_last_uni))
1088 for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ;
1089 if ((t = strchr(s, '(')) && t < PL_bufptr)
1092 if (ckWARN_d(WARN_AMBIGUOUS)){
1093 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1094 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1095 (int)(s - PL_last_uni), PL_last_uni);
1100 * LOP : macro to build a list operator. Its behaviour has been replaced
1101 * with a subroutine, S_lop() for which LOP is just another name.
1104 #define LOP(f,x) return lop(f,x,s)
1108 * Build a list operator (or something that might be one). The rules:
1109 * - if we have a next token, then it's a list operator [why?]
1110 * - if the next thing is an opening paren, then it's a function
1111 * - else it's a list operator
1115 S_lop(pTHX_ I32 f, int x, char *s)
1122 PL_last_lop = PL_oldbufptr;
1123 PL_last_lop_op = (OPCODE)f;
1126 return REPORT(LSTOP);
1129 return REPORT(LSTOP);
1132 return REPORT(FUNC);
1135 return REPORT(FUNC);
1137 return REPORT(LSTOP);
1143 * Sets up for an eventual force_next(). start_force(0) basically does
1144 * an unshift, while start_force(-1) does a push. yylex removes items
1149 S_start_force(pTHX_ int where)
1153 if (where < 0) /* so people can duplicate start_force(curforce) */
1154 where = PL_lasttoke;
1155 assert(curforce < 0 || curforce == where);
1156 if (curforce != where) {
1157 for (i = PL_lasttoke; i > where; --i) {
1158 PL_nexttoke[i] = PL_nexttoke[i-1];
1162 if (curforce < 0) /* in case of duplicate start_force() */
1163 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1167 curmad('^', newSVpvn("",0));
1168 CURMAD('_', nextwhite);
1173 S_curmad(pTHX_ char slot, SV *sv)
1182 where = &PL_nexttoke[curforce].next_mad;
1185 sv_setpvn(sv, "", 0);
1188 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1190 else if (PL_encoding) {
1191 sv_recode_to_utf8(sv, PL_encoding);
1196 /* keep a slot open for the head of the list? */
1197 if (slot != '_' && *where && (*where)->mad_key == '^') {
1198 (*where)->mad_key = slot;
1199 sv_free((*where)->mad_val);
1200 (*where)->mad_val = (void*)sv;
1203 addmad(newMADsv(slot, sv), where, 0);
1206 # define start_force(where)
1207 # define curmad(slot, sv)
1212 * When the lexer realizes it knows the next token (for instance,
1213 * it is reordering tokens for the parser) then it can call S_force_next
1214 * to know what token to return the next time the lexer is called. Caller
1215 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1216 * and possibly PL_expect to ensure the lexer handles the token correctly.
1220 S_force_next(pTHX_ I32 type)
1225 start_force(PL_lasttoke);
1226 PL_nexttoke[curforce].next_type = type;
1227 if (PL_lex_state != LEX_KNOWNEXT)
1228 PL_lex_defer = PL_lex_state;
1229 PL_lex_state = LEX_KNOWNEXT;
1230 PL_lex_expect = PL_expect;
1233 PL_nexttype[PL_nexttoke] = type;
1235 if (PL_lex_state != LEX_KNOWNEXT) {
1236 PL_lex_defer = PL_lex_state;
1237 PL_lex_expect = PL_expect;
1238 PL_lex_state = LEX_KNOWNEXT;
1244 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1247 SV * const sv = newSVpvn(start,len);
1248 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
1255 * When the lexer knows the next thing is a word (for instance, it has
1256 * just seen -> and it knows that the next char is a word char, then
1257 * it calls S_force_word to stick the next word into the PL_next lookahead.
1260 * char *start : buffer position (must be within PL_linestr)
1261 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
1262 * int check_keyword : if true, Perl checks to make sure the word isn't
1263 * a keyword (do this if the word is a label, e.g. goto FOO)
1264 * int allow_pack : if true, : characters will also be allowed (require,
1265 * use, etc. do this)
1266 * int allow_initial_tick : used by the "sub" lexer only.
1270 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1276 start = SKIPSPACE1(start);
1278 if (isIDFIRST_lazy_if(s,UTF) ||
1279 (allow_pack && *s == ':') ||
1280 (allow_initial_tick && *s == '\'') )
1282 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1283 if (check_keyword && keyword(PL_tokenbuf, len))
1285 start_force(curforce);
1287 curmad('X', newSVpvn(start,s-start));
1288 if (token == METHOD) {
1293 PL_expect = XOPERATOR;
1296 NEXTVAL_NEXTTOKE.opval
1297 = (OP*)newSVOP(OP_CONST,0,
1298 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1299 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1307 * Called when the lexer wants $foo *foo &foo etc, but the program
1308 * text only contains the "foo" portion. The first argument is a pointer
1309 * to the "foo", and the second argument is the type symbol to prefix.
1310 * Forces the next token to be a "WORD".
1311 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1315 S_force_ident(pTHX_ register const char *s, int kind)
1319 const STRLEN len = strlen(s);
1320 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1321 start_force(curforce);
1322 NEXTVAL_NEXTTOKE.opval = o;
1325 o->op_private = OPpCONST_ENTERED;
1326 /* XXX see note in pp_entereval() for why we forgo typo
1327 warnings if the symbol must be introduced in an eval.
1329 gv_fetchpvn_flags(s, len,
1330 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1332 kind == '$' ? SVt_PV :
1333 kind == '@' ? SVt_PVAV :
1334 kind == '%' ? SVt_PVHV :
1342 Perl_str_to_version(pTHX_ SV *sv)
1347 const char *start = SvPV_const(sv,len);
1348 const char * const end = start + len;
1349 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1350 while (start < end) {
1354 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1359 retval += ((NV)n)/nshift;
1368 * Forces the next token to be a version number.
1369 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1370 * and if "guessing" is TRUE, then no new token is created (and the caller
1371 * must use an alternative parsing method).
1375 S_force_version(pTHX_ char *s, int guessing)
1381 I32 startoff = s - SvPVX(PL_linestr);
1390 while (isDIGIT(*d) || *d == '_' || *d == '.')
1394 start_force(curforce);
1395 curmad('X', newSVpvn(s,d-s));
1398 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1400 s = scan_num(s, &yylval);
1401 version = yylval.opval;
1402 ver = cSVOPx(version)->op_sv;
1403 if (SvPOK(ver) && !SvNIOK(ver)) {
1404 SvUPGRADE(ver, SVt_PVNV);
1405 SvNV_set(ver, str_to_version(ver));
1406 SvNOK_on(ver); /* hint that it is a version */
1409 else if (guessing) {
1412 sv_free(nextwhite); /* let next token collect whitespace */
1414 s = SvPVX(PL_linestr) + startoff;
1422 if (PL_madskills && !version) {
1423 sv_free(nextwhite); /* let next token collect whitespace */
1425 s = SvPVX(PL_linestr) + startoff;
1428 /* NOTE: The parser sees the package name and the VERSION swapped */
1429 start_force(curforce);
1430 NEXTVAL_NEXTTOKE.opval = version;
1438 * Tokenize a quoted string passed in as an SV. It finds the next
1439 * chunk, up to end of string or a backslash. It may make a new
1440 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1445 S_tokeq(pTHX_ SV *sv)
1449 register char *send;
1457 s = SvPV_force(sv, len);
1458 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1461 while (s < send && *s != '\\')
1466 if ( PL_hints & HINT_NEW_STRING ) {
1467 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1473 if (s + 1 < send && (s[1] == '\\'))
1474 s++; /* all that, just for this */
1479 SvCUR_set(sv, d - SvPVX_const(sv));
1481 if ( PL_hints & HINT_NEW_STRING )
1482 return new_constant(NULL, 0, "q", sv, pv, "q");
1487 * Now come three functions related to double-quote context,
1488 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1489 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1490 * interact with PL_lex_state, and create fake ( ... ) argument lists
1491 * to handle functions and concatenation.
1492 * They assume that whoever calls them will be setting up a fake
1493 * join call, because each subthing puts a ',' after it. This lets
1496 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1498 * (I'm not sure whether the spurious commas at the end of lcfirst's
1499 * arguments and join's arguments are created or not).
1504 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1506 * Pattern matching will set PL_lex_op to the pattern-matching op to
1507 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1509 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1511 * Everything else becomes a FUNC.
1513 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1514 * had an OP_CONST or OP_READLINE). This just sets us up for a
1515 * call to S_sublex_push().
1519 S_sublex_start(pTHX)
1522 register const I32 op_type = yylval.ival;
1524 if (op_type == OP_NULL) {
1525 yylval.opval = PL_lex_op;
1529 if (op_type == OP_CONST || op_type == OP_READLINE) {
1530 SV *sv = tokeq(PL_lex_stuff);
1532 if (SvTYPE(sv) == SVt_PVIV) {
1533 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1535 const char * const p = SvPV_const(sv, len);
1536 SV * const nsv = newSVpvn(p, len);
1542 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1543 PL_lex_stuff = NULL;
1544 /* Allow <FH> // "foo" */
1545 if (op_type == OP_READLINE)
1546 PL_expect = XTERMORDORDOR;
1550 PL_sublex_info.super_state = PL_lex_state;
1551 PL_sublex_info.sub_inwhat = op_type;
1552 PL_sublex_info.sub_op = PL_lex_op;
1553 PL_lex_state = LEX_INTERPPUSH;
1557 yylval.opval = PL_lex_op;
1567 * Create a new scope to save the lexing state. The scope will be
1568 * ended in S_sublex_done. Returns a '(', starting the function arguments
1569 * to the uc, lc, etc. found before.
1570 * Sets PL_lex_state to LEX_INTERPCONCAT.
1579 PL_lex_state = PL_sublex_info.super_state;
1580 SAVEI32(PL_lex_dojoin);
1581 SAVEI32(PL_lex_brackets);
1582 SAVEI32(PL_lex_casemods);
1583 SAVEI32(PL_lex_starts);
1584 SAVEI32(PL_lex_state);
1585 SAVEVPTR(PL_lex_inpat);
1586 SAVEI32(PL_lex_inwhat);
1587 SAVECOPLINE(PL_curcop);
1588 SAVEPPTR(PL_bufptr);
1589 SAVEPPTR(PL_bufend);
1590 SAVEPPTR(PL_oldbufptr);
1591 SAVEPPTR(PL_oldoldbufptr);
1592 SAVEPPTR(PL_last_lop);
1593 SAVEPPTR(PL_last_uni);
1594 SAVEPPTR(PL_linestart);
1595 SAVESPTR(PL_linestr);
1596 SAVEGENERICPV(PL_lex_brackstack);
1597 SAVEGENERICPV(PL_lex_casestack);
1599 PL_linestr = PL_lex_stuff;
1600 PL_lex_stuff = NULL;
1602 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1603 = SvPVX(PL_linestr);
1604 PL_bufend += SvCUR(PL_linestr);
1605 PL_last_lop = PL_last_uni = NULL;
1606 SAVEFREESV(PL_linestr);
1608 PL_lex_dojoin = FALSE;
1609 PL_lex_brackets = 0;
1610 Newx(PL_lex_brackstack, 120, char);
1611 Newx(PL_lex_casestack, 12, char);
1612 PL_lex_casemods = 0;
1613 *PL_lex_casestack = '\0';
1615 PL_lex_state = LEX_INTERPCONCAT;
1616 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1618 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1619 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1620 PL_lex_inpat = PL_sublex_info.sub_op;
1622 PL_lex_inpat = NULL;
1629 * Restores lexer state after a S_sublex_push.
1636 if (!PL_lex_starts++) {
1637 SV * const sv = newSVpvs("");
1638 if (SvUTF8(PL_linestr))
1640 PL_expect = XOPERATOR;
1641 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1645 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1646 PL_lex_state = LEX_INTERPCASEMOD;
1650 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1651 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1652 PL_linestr = PL_lex_repl;
1654 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1655 PL_bufend += SvCUR(PL_linestr);
1656 PL_last_lop = PL_last_uni = NULL;
1657 SAVEFREESV(PL_linestr);
1658 PL_lex_dojoin = FALSE;
1659 PL_lex_brackets = 0;
1660 PL_lex_casemods = 0;
1661 *PL_lex_casestack = '\0';
1663 if (SvEVALED(PL_lex_repl)) {
1664 PL_lex_state = LEX_INTERPNORMAL;
1666 /* we don't clear PL_lex_repl here, so that we can check later
1667 whether this is an evalled subst; that means we rely on the
1668 logic to ensure sublex_done() is called again only via the
1669 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1672 PL_lex_state = LEX_INTERPCONCAT;
1682 endwhite = newSVpvn("",0);
1683 sv_catsv(endwhite, thiswhite);
1687 sv_setpvn(thistoken,"",0);
1689 realtokenstart = -1;
1693 PL_bufend = SvPVX(PL_linestr);
1694 PL_bufend += SvCUR(PL_linestr);
1695 PL_expect = XOPERATOR;
1696 PL_sublex_info.sub_inwhat = 0;
1704 Extracts a pattern, double-quoted string, or transliteration. This
1707 It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1708 processing a pattern (PL_lex_inpat is true), a transliteration
1709 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1711 Returns a pointer to the character scanned up to. Iff this is
1712 advanced from the start pointer supplied (ie if anything was
1713 successfully parsed), will leave an OP for the substring scanned
1714 in yylval. Caller must intuit reason for not parsing further
1715 by looking at the next characters herself.
1719 double-quoted style: \r and \n
1720 regexp special ones: \D \s
1722 backrefs: \1 (deprecated in substitution replacements)
1723 case and quoting: \U \Q \E
1724 stops on @ and $, but not for $ as tail anchor
1726 In transliterations:
1727 characters are VERY literal, except for - not at the start or end
1728 of the string, which indicates a range. scan_const expands the
1729 range to the full set of intermediate characters.
1731 In double-quoted strings:
1733 double-quoted style: \r and \n
1735 backrefs: \1 (deprecated)
1736 case and quoting: \U \Q \E
1739 scan_const does *not* construct ops to handle interpolated strings.
1740 It stops processing as soon as it finds an embedded $ or @ variable
1741 and leaves it to the caller to work out what's going on.
1743 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo.
1745 $ in pattern could be $foo or could be tail anchor. Assumption:
1746 it's a tail anchor if $ is the last thing in the string, or if it's
1747 followed by one of ")| \n\t"
1749 \1 (backreferences) are turned into $1
1751 The structure of the code is
1752 while (there's a character to process) {
1753 handle transliteration ranges
1754 skip regexp comments
1755 skip # initiated comments in //x patterns
1756 check for embedded @foo
1757 check for embedded scalars
1759 leave intact backslashes from leave (below)
1760 deprecate \1 in strings and sub replacements
1761 handle string-changing backslashes \l \U \Q \E, etc.
1762 switch (what was escaped) {
1763 handle - in a transliteration (becomes a literal -)
1764 handle \132 octal characters
1765 handle 0x15 hex characters
1766 handle \cV (control V)
1767 handle printf backslashes (\f, \r, \n, etc)
1769 } (end if backslash)
1770 } (end while character to read)
1775 S_scan_const(pTHX_ char *start)
1778 register char *send = PL_bufend; /* end of the constant */
1779 SV *sv = newSV(send - start); /* sv for the constant */
1780 register char *s = start; /* start of the constant */
1781 register char *d = SvPVX(sv); /* destination for copies */
1782 bool dorange = FALSE; /* are we in a translit range? */
1783 bool didrange = FALSE; /* did we just finish a range? */
1784 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1785 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1788 UV literal_endpoint = 0;
1791 const char *leaveit = /* set of acceptably-backslashed characters */
1793 ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#"
1796 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1797 /* If we are doing a trans and we know we want UTF8 set expectation */
1798 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1799 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1803 while (s < send || dorange) {
1804 /* get transliterations out of the way (they're most literal) */
1805 if (PL_lex_inwhat == OP_TRANS) {
1806 /* expand a range A-Z to the full set of characters. AIE! */
1808 I32 i; /* current expanded character */
1809 I32 min; /* first character in range */
1810 I32 max; /* last character in range */
1813 char * const c = (char*)utf8_hop((U8*)d, -1);
1817 *c = (char)UTF_TO_NATIVE(0xff);
1818 /* mark the range as done, and continue */
1824 i = d - SvPVX_const(sv); /* remember current offset */
1825 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1826 d = SvPVX(sv) + i; /* refresh d after realloc */
1827 d -= 2; /* eat the first char and the - */
1829 min = (U8)*d; /* first char in range */
1830 max = (U8)d[1]; /* last char in range */
1834 "Invalid range \"%c-%c\" in transliteration operator",
1835 (char)min, (char)max);
1839 if (literal_endpoint == 2 &&
1840 ((isLOWER(min) && isLOWER(max)) ||
1841 (isUPPER(min) && isUPPER(max)))) {
1843 for (i = min; i <= max; i++)
1845 *d++ = NATIVE_TO_NEED(has_utf8,i);
1847 for (i = min; i <= max; i++)
1849 *d++ = NATIVE_TO_NEED(has_utf8,i);
1854 for (i = min; i <= max; i++)
1857 /* mark the range as done, and continue */
1861 literal_endpoint = 0;
1866 /* range begins (ignore - as first or last char) */
1867 else if (*s == '-' && s+1 < send && s != start) {
1869 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1872 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1882 literal_endpoint = 0;
1887 /* if we get here, we're not doing a transliteration */
1889 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1890 except for the last char, which will be done separately. */
1891 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1893 while (s+1 < send && *s != ')')
1894 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1896 else if (s[2] == '{' /* This should match regcomp.c */
1897 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1900 char *regparse = s + (s[2] == '{' ? 3 : 4);
1903 while (count && (c = *regparse)) {
1904 if (c == '\\' && regparse[1])
1912 if (*regparse != ')')
1913 regparse--; /* Leave one char for continuation. */
1914 while (s < regparse)
1915 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1919 /* likewise skip #-initiated comments in //x patterns */
1920 else if (*s == '#' && PL_lex_inpat &&
1921 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1922 while (s+1 < send && *s != '\n')
1923 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1926 /* check for embedded arrays
1927 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
1929 else if (*s == '@' && s[1]
1930 && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1])))
1933 /* check for embedded scalars. only stop if we're sure it's a
1936 else if (*s == '$') {
1937 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
1939 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
1940 break; /* in regexp, $ might be tail anchor */
1943 /* End of else if chain - OP_TRANS rejoin rest */
1946 if (*s == '\\' && s+1 < send) {
1949 /* some backslashes we leave behind */
1950 if (*leaveit && *s && strchr(leaveit, *s)) {
1951 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
1952 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1956 /* deprecate \1 in strings and substitution replacements */
1957 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1958 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1960 if (ckWARN(WARN_SYNTAX))
1961 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
1966 /* string-change backslash escapes */
1967 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1972 /* if we get here, it's either a quoted -, or a digit */
1975 /* quoted - in transliterations */
1977 if (PL_lex_inwhat == OP_TRANS) {
1987 Perl_warner(aTHX_ packWARN(WARN_MISC),
1988 "Unrecognized escape \\%c passed through",
1990 /* default action is to copy the quoted character */
1991 goto default_action;
1994 /* \132 indicates an octal constant */
1995 case '0': case '1': case '2': case '3':
1996 case '4': case '5': case '6': case '7':
2000 uv = grok_oct(s, &len, &flags, NULL);
2003 goto NUM_ESCAPE_INSERT;
2005 /* \x24 indicates a hex constant */
2009 char* const e = strchr(s, '}');
2010 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2011 PERL_SCAN_DISALLOW_PREFIX;
2016 yyerror("Missing right brace on \\x{}");
2020 uv = grok_hex(s, &len, &flags, NULL);
2026 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2027 uv = grok_hex(s, &len, &flags, NULL);
2033 /* Insert oct or hex escaped character.
2034 * There will always enough room in sv since such
2035 * escapes will be longer than any UTF-8 sequence
2036 * they can end up as. */
2038 /* We need to map to chars to ASCII before doing the tests
2041 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2042 if (!has_utf8 && uv > 255) {
2043 /* Might need to recode whatever we have
2044 * accumulated so far if it contains any
2047 * (Can't we keep track of that and avoid
2048 * this rescan? --jhi)
2052 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2053 if (!NATIVE_IS_INVARIANT(*c)) {
2058 const STRLEN offset = d - SvPVX_const(sv);
2060 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2064 while (src >= (const U8 *)SvPVX_const(sv)) {
2065 if (!NATIVE_IS_INVARIANT(*src)) {
2066 const U8 ch = NATIVE_TO_ASCII(*src);
2067 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2068 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2078 if (has_utf8 || uv > 255) {
2079 d = (char*)uvchr_to_utf8((U8*)d, uv);
2081 if (PL_lex_inwhat == OP_TRANS &&
2082 PL_sublex_info.sub_op) {
2083 PL_sublex_info.sub_op->op_private |=
2084 (PL_lex_repl ? OPpTRANS_FROM_UTF
2097 /* \N{LATIN SMALL LETTER A} is a named character */
2101 char* e = strchr(s, '}');
2107 yyerror("Missing right brace on \\N{}");
2111 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2113 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2114 PERL_SCAN_DISALLOW_PREFIX;
2117 uv = grok_hex(s, &len, &flags, NULL);
2119 goto NUM_ESCAPE_INSERT;
2121 res = newSVpvn(s + 1, e - s - 1);
2122 res = new_constant( NULL, 0, "charnames",
2123 res, NULL, "\\N{...}" );
2125 sv_utf8_upgrade(res);
2126 str = SvPV_const(res,len);
2127 #ifdef EBCDIC_NEVER_MIND
2128 /* charnames uses pack U and that has been
2129 * recently changed to do the below uni->native
2130 * mapping, so this would be redundant (and wrong,
2131 * the code point would be doubly converted).
2132 * But leave this in just in case the pack U change
2133 * gets revoked, but the semantics is still
2134 * desireable for charnames. --jhi */
2136 UV uv = utf8_to_uvchr((const U8*)str, 0);
2139 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2141 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2142 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2143 str = SvPV_const(res, len);
2147 if (!has_utf8 && SvUTF8(res)) {
2148 const char * const ostart = SvPVX_const(sv);
2149 SvCUR_set(sv, d - ostart);
2152 sv_utf8_upgrade(sv);
2153 /* this just broke our allocation above... */
2154 SvGROW(sv, (STRLEN)(send - start));
2155 d = SvPVX(sv) + SvCUR(sv);
2158 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2159 const char * const odest = SvPVX_const(sv);
2161 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2162 d = SvPVX(sv) + (d - odest);
2164 Copy(str, d, len, char);
2171 yyerror("Missing braces on \\N{}");
2174 /* \c is a control character */
2183 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2186 yyerror("Missing control char name in \\c");
2190 /* printf-style backslashes, formfeeds, newlines, etc */
2192 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2195 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2198 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2201 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2204 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2207 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2210 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2216 } /* end if (backslash) */
2223 /* If we started with encoded form, or already know we want it
2224 and then encode the next character */
2225 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2227 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2228 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2231 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2232 const STRLEN off = d - SvPVX_const(sv);
2233 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2235 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2239 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2241 } /* while loop to process each character */
2243 /* terminate the string and set up the sv */
2245 SvCUR_set(sv, d - SvPVX_const(sv));
2246 if (SvCUR(sv) >= SvLEN(sv))
2247 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2250 if (PL_encoding && !has_utf8) {
2251 sv_recode_to_utf8(sv, PL_encoding);
2257 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2258 PL_sublex_info.sub_op->op_private |=
2259 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2263 /* shrink the sv if we allocated more than we used */
2264 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2265 SvPV_shrink_to_cur(sv);
2268 /* return the substring (via yylval) only if we parsed anything */
2269 if (s > PL_bufptr) {
2270 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
2271 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
2273 ( PL_lex_inwhat == OP_TRANS
2275 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2278 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2285 * Returns TRUE if there's more to the expression (e.g., a subscript),
2288 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2290 * ->[ and ->{ return TRUE
2291 * { and [ outside a pattern are always subscripts, so return TRUE
2292 * if we're outside a pattern and it's not { or [, then return FALSE
2293 * if we're in a pattern and the first char is a {
2294 * {4,5} (any digits around the comma) returns FALSE
2295 * if we're in a pattern and the first char is a [
2297 * [SOMETHING] has a funky algorithm to decide whether it's a
2298 * character class or not. It has to deal with things like
2299 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2300 * anything else returns TRUE
2303 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2306 S_intuit_more(pTHX_ register char *s)
2309 if (PL_lex_brackets)
2311 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2313 if (*s != '{' && *s != '[')
2318 /* In a pattern, so maybe we have {n,m}. */
2335 /* On the other hand, maybe we have a character class */
2338 if (*s == ']' || *s == '^')
2341 /* this is terrifying, and it works */
2342 int weight = 2; /* let's weigh the evidence */
2344 unsigned char un_char = 255, last_un_char;
2345 const char * const send = strchr(s,']');
2346 char tmpbuf[sizeof PL_tokenbuf * 4];
2348 if (!send) /* has to be an expression */
2351 Zero(seen,256,char);
2354 else if (isDIGIT(*s)) {
2356 if (isDIGIT(s[1]) && s[2] == ']')
2362 for (; s < send; s++) {
2363 last_un_char = un_char;
2364 un_char = (unsigned char)*s;
2369 weight -= seen[un_char] * 10;
2370 if (isALNUM_lazy_if(s+1,UTF)) {
2372 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2373 len = (int)strlen(tmpbuf);
2374 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2379 else if (*s == '$' && s[1] &&
2380 strchr("[#!%*<>()-=",s[1])) {
2381 if (/*{*/ strchr("])} =",s[2]))
2390 if (strchr("wds]",s[1]))
2392 else if (seen['\''] || seen['"'])
2394 else if (strchr("rnftbxcav",s[1]))
2396 else if (isDIGIT(s[1])) {
2398 while (s[1] && isDIGIT(s[1]))
2408 if (strchr("aA01! ",last_un_char))
2410 if (strchr("zZ79~",s[1]))
2412 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2413 weight -= 5; /* cope with negative subscript */
2416 if (!isALNUM(last_un_char)
2417 && !(last_un_char == '$' || last_un_char == '@'
2418 || last_un_char == '&')
2419 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2424 if (keyword(tmpbuf, d - tmpbuf))
2427 if (un_char == last_un_char + 1)
2429 weight -= seen[un_char];
2434 if (weight >= 0) /* probably a character class */
2444 * Does all the checking to disambiguate
2446 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2447 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2449 * First argument is the stuff after the first token, e.g. "bar".
2451 * Not a method if bar is a filehandle.
2452 * Not a method if foo is a subroutine prototyped to take a filehandle.
2453 * Not a method if it's really "Foo $bar"
2454 * Method if it's "foo $bar"
2455 * Not a method if it's really "print foo $bar"
2456 * Method if it's really "foo package::" (interpreted as package->foo)
2457 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2458 * Not a method if bar is a filehandle or package, but is quoted with
2463 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2466 char *s = start + (*start == '$');
2467 char tmpbuf[sizeof PL_tokenbuf];
2475 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2479 const char *proto = SvPVX_const(cv);
2490 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2491 /* start is the beginning of the possible filehandle/object,
2492 * and s is the end of it
2493 * tmpbuf is a copy of it
2496 if (*start == '$') {
2497 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2500 len = start - SvPVX(PL_linestr);
2504 start = SvPVX(PL_linestr) + len;
2508 return *s == '(' ? FUNCMETH : METHOD;
2510 if (!keyword(tmpbuf, len)) {
2511 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2515 soff = s - SvPVX(PL_linestr);
2519 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2520 if (indirgv && GvCVu(indirgv))
2522 /* filehandle or package name makes it a method */
2523 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2525 soff = s - SvPVX(PL_linestr);
2528 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2529 return 0; /* no assumptions -- "=>" quotes bearword */
2531 start_force(curforce);
2532 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2533 newSVpvn(tmpbuf,len));
2534 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2536 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2541 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2543 return *s == '(' ? FUNCMETH : METHOD;
2551 * Return a string of Perl code to load the debugger. If PERL5DB
2552 * is set, it will return the contents of that, otherwise a
2553 * compile-time require of perl5db.pl.
2561 const char * const pdb = PerlEnv_getenv("PERL5DB");
2565 SETERRNO(0,SS_NORMAL);
2566 return "BEGIN { require 'perl5db.pl' }";
2572 /* Encoded script support. filter_add() effectively inserts a
2573 * 'pre-processing' function into the current source input stream.
2574 * Note that the filter function only applies to the current source file
2575 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2577 * The datasv parameter (which may be NULL) can be used to pass
2578 * private data to this instance of the filter. The filter function
2579 * can recover the SV using the FILTER_DATA macro and use it to
2580 * store private buffers and state information.
2582 * The supplied datasv parameter is upgraded to a PVIO type
2583 * and the IoDIRP/IoANY field is used to store the function pointer,
2584 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2585 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2586 * private use must be set using malloc'd pointers.
2590 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2596 if (!PL_rsfp_filters)
2597 PL_rsfp_filters = newAV();
2600 SvUPGRADE(datasv, SVt_PVIO);
2601 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2602 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2603 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2604 IoANY(datasv), SvPV_nolen(datasv)));
2605 av_unshift(PL_rsfp_filters, 1);
2606 av_store(PL_rsfp_filters, 0, datasv) ;
2611 /* Delete most recently added instance of this filter function. */
2613 Perl_filter_del(pTHX_ filter_t funcp)
2619 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", FPTR2DPTR(XPVIO *, funcp)));
2621 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2623 /* if filter is on top of stack (usual case) just pop it off */
2624 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2625 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2626 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2627 IoANY(datasv) = (void *)NULL;
2628 sv_free(av_pop(PL_rsfp_filters));
2632 /* we need to search for the correct entry and clear it */
2633 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2637 /* Invoke the idxth filter function for the current rsfp. */
2638 /* maxlen 0 = read one text line */
2640 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2646 if (!PL_rsfp_filters)
2648 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2649 /* Provide a default input filter to make life easy. */
2650 /* Note that we append to the line. This is handy. */
2651 DEBUG_P(PerlIO_printf(Perl_debug_log,
2652 "filter_read %d: from rsfp\n", idx));
2656 const int old_len = SvCUR(buf_sv);
2658 /* ensure buf_sv is large enough */
2659 SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ;
2660 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
2661 if (PerlIO_error(PL_rsfp))
2662 return -1; /* error */
2664 return 0 ; /* end of file */
2666 SvCUR_set(buf_sv, old_len + len) ;
2669 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2670 if (PerlIO_error(PL_rsfp))
2671 return -1; /* error */
2673 return 0 ; /* end of file */
2676 return SvCUR(buf_sv);
2678 /* Skip this filter slot if filter has been deleted */
2679 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2680 DEBUG_P(PerlIO_printf(Perl_debug_log,
2681 "filter_read %d: skipped (filter deleted)\n",
2683 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
2685 /* Get function pointer hidden within datasv */
2686 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2687 DEBUG_P(PerlIO_printf(Perl_debug_log,
2688 "filter_read %d: via function %p (%s)\n",
2689 idx, datasv, SvPV_nolen_const(datasv)));
2690 /* Call function. The function is expected to */
2691 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2692 /* Return: <0:error, =0:eof, >0:not eof */
2693 return (*funcp)(aTHX_ idx, buf_sv, maxlen);
2697 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2700 #ifdef PERL_CR_FILTER
2701 if (!PL_rsfp_filters) {
2702 filter_add(S_cr_textfilter,NULL);
2705 if (PL_rsfp_filters) {
2707 SvCUR_set(sv, 0); /* start with empty line */
2708 if (FILTER_READ(0, sv, 0) > 0)
2709 return ( SvPVX(sv) ) ;
2714 return (sv_gets(sv, fp, append));
2718 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2723 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2727 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2728 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2730 return GvHV(gv); /* Foo:: */
2733 /* use constant CLASS => 'MyClass' */
2734 if ((gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV))) {
2736 if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) {
2737 pkgname = SvPV_nolen_const(sv);
2741 return gv_stashpv(pkgname, FALSE);
2747 * The intent of this yylex wrapper is to minimize the changes to the
2748 * tokener when we aren't interested in collecting madprops. It remains
2749 * to be seen how successful this strategy will be...
2756 char *s = PL_bufptr;
2758 /* make sure thiswhite is initialized */
2762 /* just do what yylex would do on pending identifier; leave thiswhite alone */
2763 if (PL_pending_ident)
2764 return S_pending_ident(aTHX);
2766 /* previous token ate up our whitespace? */
2767 if (!PL_lasttoke && nextwhite) {
2768 thiswhite = nextwhite;
2772 /* isolate the token, and figure out where it is without whitespace */
2773 realtokenstart = -1;
2777 assert(curforce < 0);
2779 if (!thismad || thismad->mad_key == '^') { /* not forced already? */
2781 if (realtokenstart < 0 || !CopLINE(PL_curcop))
2782 thistoken = newSVpvn("",0);
2784 char *tstart = SvPVX(PL_linestr) + realtokenstart;
2785 thistoken = newSVpvn(tstart, s - tstart);
2788 if (thismad) /* install head */
2789 CURMAD('X', thistoken);
2792 /* last whitespace of a sublex? */
2793 if (optype == ')' && endwhite) {
2794 CURMAD('X', endwhite);
2799 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
2800 if (!thiswhite && !endwhite && !optype) {
2806 /* put off final whitespace till peg */
2807 if (optype == ';' && !PL_rsfp) {
2808 nextwhite = thiswhite;
2811 else if (thisopen) {
2812 CURMAD('q', thisopen);
2818 /* Store actual token text as madprop X */
2819 CURMAD('X', thistoken);
2823 /* add preceding whitespace as madprop _ */
2824 CURMAD('_', thiswhite);
2828 /* add quoted material as madprop = */
2829 CURMAD('=', thisstuff);
2833 /* add terminating quote as madprop Q */
2834 CURMAD('Q', thisclose);
2838 /* special processing based on optype */
2842 /* opval doesn't need a TOKEN since it can already store mp */
2853 append_madprops(thismad, yylval.opval, 0);
2861 addmad(newMADsv('p', endwhite), &thismad, 0);
2870 /* remember any fake bracket that lexer is about to discard */
2871 if (PL_lex_brackets == 1 &&
2872 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
2875 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2878 thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
2879 addmad(newMADsv('#', thiswhite), &thismad, 0);
2882 break; /* don't bother looking for trailing comment */
2891 /* attach a trailing comment to its statement instead of next token */
2895 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
2897 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2899 if (*s == '\n' || *s == '#') {
2900 while (s < PL_bufend && *s != '\n')
2904 thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
2905 addmad(newMADsv('#', thiswhite), &thismad, 0);
2922 /* Create new token struct. Note: opvals return early above. */
2923 yylval.tkval = newTOKEN(optype, yylval, thismad);
2930 S_tokenize_use(pTHX_ int is_use, char *s) {
2932 if (PL_expect != XSTATE)
2933 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
2934 is_use ? "use" : "no"));
2936 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
2937 s = force_version(s, TRUE);
2938 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
2939 start_force(curforce);
2940 NEXTVAL_NEXTTOKE.opval = NULL;
2943 else if (*s == 'v') {
2944 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2945 s = force_version(s, FALSE);
2949 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2950 s = force_version(s, FALSE);
2952 yylval.ival = is_use;
2956 static const char* const exp_name[] =
2957 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2958 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
2965 Works out what to call the token just pulled out of the input
2966 stream. The yacc parser takes care of taking the ops we return and
2967 stitching them into a tree.
2973 if read an identifier
2974 if we're in a my declaration
2975 croak if they tried to say my($foo::bar)
2976 build the ops for a my() declaration
2977 if it's an access to a my() variable
2978 are we in a sort block?
2979 croak if my($a); $a <=> $b
2980 build ops for access to a my() variable
2981 if in a dq string, and they've said @foo and we can't find @foo
2983 build ops for a bareword
2984 if we already built the token before, use it.
2989 #pragma segment Perl_yylex
2995 register char *s = PL_bufptr;
3001 SV* tmp = newSVpvs("");
3002 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3003 (IV)CopLINE(PL_curcop),
3004 lex_state_names[PL_lex_state],
3005 exp_name[PL_expect],
3006 pv_display(tmp, s, strlen(s), 0, 60));
3009 /* check if there's an identifier for us to look at */
3010 if (PL_pending_ident)
3011 return REPORT(S_pending_ident(aTHX));
3013 /* no identifier pending identification */
3015 switch (PL_lex_state) {
3017 case LEX_NORMAL: /* Some compilers will produce faster */
3018 case LEX_INTERPNORMAL: /* code if we comment these out. */
3022 /* when we've already built the next token, just pull it out of the queue */
3026 yylval = PL_nexttoke[PL_lasttoke].next_val;
3028 thismad = PL_nexttoke[PL_lasttoke].next_mad;
3029 PL_nexttoke[PL_lasttoke].next_mad = 0;
3030 if (thismad && thismad->mad_key == '_') {
3031 thiswhite = (SV*)thismad->mad_val;
3032 thismad->mad_val = 0;
3038 PL_lex_state = PL_lex_defer;
3039 PL_expect = PL_lex_expect;
3040 PL_lex_defer = LEX_NORMAL;
3041 if (!PL_nexttoke[PL_lasttoke].next_type)
3046 yylval = PL_nextval[PL_nexttoke];
3048 PL_lex_state = PL_lex_defer;
3049 PL_expect = PL_lex_expect;
3050 PL_lex_defer = LEX_NORMAL;
3054 /* FIXME - can these be merged? */
3055 return(PL_nexttoke[PL_lasttoke].next_type);
3057 return REPORT(PL_nexttype[PL_nexttoke]);
3060 /* interpolated case modifiers like \L \U, including \Q and \E.
3061 when we get here, PL_bufptr is at the \
3063 case LEX_INTERPCASEMOD:
3065 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3066 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3068 /* handle \E or end of string */
3069 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3071 if (PL_lex_casemods) {
3072 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3073 PL_lex_casestack[PL_lex_casemods] = '\0';
3075 if (PL_bufptr != PL_bufend
3076 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3078 PL_lex_state = LEX_INTERPCONCAT;
3081 thistoken = newSVpvn("\\E",2);
3087 while (PL_bufptr != PL_bufend &&
3088 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3090 thiswhite = newSVpvn("",0);
3091 sv_catpvn(thiswhite, PL_bufptr, 2);
3095 if (PL_bufptr != PL_bufend)
3098 PL_lex_state = LEX_INTERPCONCAT;
3102 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3103 "### Saw case modifier\n"); });
3105 if (s[1] == '\\' && s[2] == 'E') {
3108 thiswhite = newSVpvn("",0);
3109 sv_catpvn(thiswhite, PL_bufptr, 4);
3112 PL_lex_state = LEX_INTERPCONCAT;
3117 if (!PL_madskills) /* when just compiling don't need correct */
3118 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3119 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3120 if ((*s == 'L' || *s == 'U') &&
3121 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3122 PL_lex_casestack[--PL_lex_casemods] = '\0';
3125 if (PL_lex_casemods > 10)
3126 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3127 PL_lex_casestack[PL_lex_casemods++] = *s;
3128 PL_lex_casestack[PL_lex_casemods] = '\0';
3129 PL_lex_state = LEX_INTERPCONCAT;
3130 start_force(curforce);
3131 NEXTVAL_NEXTTOKE.ival = 0;
3133 start_force(curforce);
3135 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3137 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3139 NEXTVAL_NEXTTOKE.ival = OP_LC;
3141 NEXTVAL_NEXTTOKE.ival = OP_UC;
3143 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3145 Perl_croak(aTHX_ "panic: yylex");
3147 SV* tmpsv = newSVpvn("",0);
3148 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3154 if (PL_lex_starts) {
3161 thistoken = newSVpvn("",0);
3164 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3165 if (PL_lex_casemods == 1 && PL_lex_inpat)
3174 case LEX_INTERPPUSH:
3175 return REPORT(sublex_push());
3177 case LEX_INTERPSTART:
3178 if (PL_bufptr == PL_bufend)
3179 return REPORT(sublex_done());
3180 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3181 "### Interpolated variable\n"); });
3183 PL_lex_dojoin = (*PL_bufptr == '@');
3184 PL_lex_state = LEX_INTERPNORMAL;
3185 if (PL_lex_dojoin) {
3186 start_force(curforce);
3187 NEXTVAL_NEXTTOKE.ival = 0;
3189 start_force(curforce);
3190 force_ident("\"", '$');
3191 start_force(curforce);
3192 NEXTVAL_NEXTTOKE.ival = 0;
3194 start_force(curforce);
3195 NEXTVAL_NEXTTOKE.ival = 0;
3197 start_force(curforce);
3198 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3201 if (PL_lex_starts++) {
3207 thistoken = newSVpvn("",0);
3210 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3211 if (!PL_lex_casemods && PL_lex_inpat)
3218 case LEX_INTERPENDMAYBE:
3219 if (intuit_more(PL_bufptr)) {
3220 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3226 if (PL_lex_dojoin) {
3227 PL_lex_dojoin = FALSE;
3228 PL_lex_state = LEX_INTERPCONCAT;
3233 thistoken = newSVpvn("",0);
3238 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3239 && SvEVALED(PL_lex_repl))
3241 if (PL_bufptr != PL_bufend)
3242 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3246 case LEX_INTERPCONCAT:
3248 if (PL_lex_brackets)
3249 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3251 if (PL_bufptr == PL_bufend)
3252 return REPORT(sublex_done());
3254 if (SvIVX(PL_linestr) == '\'') {
3255 SV *sv = newSVsv(PL_linestr);
3258 else if ( PL_hints & HINT_NEW_RE )
3259 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
3260 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3264 s = scan_const(PL_bufptr);
3266 PL_lex_state = LEX_INTERPCASEMOD;
3268 PL_lex_state = LEX_INTERPSTART;
3271 if (s != PL_bufptr) {
3272 start_force(curforce);
3274 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3276 NEXTVAL_NEXTTOKE = yylval;
3279 if (PL_lex_starts++) {
3284 thistoken = newSVpvn("",0);
3287 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3288 if (!PL_lex_casemods && PL_lex_inpat)
3301 PL_lex_state = LEX_NORMAL;
3302 s = scan_formline(PL_bufptr);
3303 if (!PL_lex_formbrack)
3309 PL_oldoldbufptr = PL_oldbufptr;
3318 realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3322 if (isIDFIRST_lazy_if(s,UTF))
3324 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
3327 goto fake_eof; /* emulate EOF on ^D or ^Z */
3336 if (PL_lex_brackets) {
3337 yyerror(PL_lex_formbrack
3338 ? "Format not terminated"
3339 : "Missing right curly or square bracket");
3341 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3342 "### Tokener got EOF\n");
3346 if (s++ < PL_bufend)
3347 goto retry; /* ignore stray nulls */
3350 if (!PL_in_eval && !PL_preambled) {
3351 PL_preambled = TRUE;
3356 sv_setpv(PL_linestr,incl_perldb());
3357 if (SvCUR(PL_linestr))
3358 sv_catpvs(PL_linestr,";");
3360 while(AvFILLp(PL_preambleav) >= 0) {
3361 SV *tmpsv = av_shift(PL_preambleav);
3362 sv_catsv(PL_linestr, tmpsv);
3363 sv_catpvs(PL_linestr, ";");
3366 sv_free((SV*)PL_preambleav);
3367 PL_preambleav = NULL;
3369 if (PL_minus_n || PL_minus_p) {
3370 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3372 sv_catpvs(PL_linestr,"chomp;");
3375 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3376 || *PL_splitstr == '"')
3377 && strchr(PL_splitstr + 1, *PL_splitstr))
3378 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3380 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3381 bytes can be used as quoting characters. :-) */
3382 const char *splits = PL_splitstr;
3383 sv_catpvs(PL_linestr, "our @F=split(q\0");
3386 if (*splits == '\\')
3387 sv_catpvn(PL_linestr, splits, 1);
3388 sv_catpvn(PL_linestr, splits, 1);
3389 } while (*splits++);
3390 /* This loop will embed the trailing NUL of
3391 PL_linestr as the last thing it does before
3393 sv_catpvs(PL_linestr, ");");
3397 sv_catpvs(PL_linestr,"our @F=split(' ');");
3401 sv_catpvs(PL_linestr,"use feature ':5.10';");
3402 sv_catpvs(PL_linestr, "\n");
3403 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3404 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3405 PL_last_lop = PL_last_uni = NULL;
3406 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3407 SV * const sv = newSV(0);
3409 sv_upgrade(sv, SVt_PVMG);
3410 sv_setsv(sv,PL_linestr);
3413 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
3418 bof = PL_rsfp ? TRUE : FALSE;
3419 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3422 realtokenstart = -1;
3425 if (PL_preprocess && !PL_in_eval)
3426 (void)PerlProc_pclose(PL_rsfp);
3427 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3428 PerlIO_clearerr(PL_rsfp);
3430 (void)PerlIO_close(PL_rsfp);
3432 PL_doextract = FALSE;
3434 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3439 sv_setpv(PL_linestr,PL_minus_p
3440 ? ";}continue{print;}" : ";}");
3441 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3442 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3443 PL_last_lop = PL_last_uni = NULL;
3444 PL_minus_n = PL_minus_p = 0;
3447 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3448 PL_last_lop = PL_last_uni = NULL;
3449 sv_setpvn(PL_linestr,"",0);
3450 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3452 /* If it looks like the start of a BOM or raw UTF-16,
3453 * check if it in fact is. */
3459 #ifdef PERLIO_IS_STDIO
3460 # ifdef __GNU_LIBRARY__
3461 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3462 # define FTELL_FOR_PIPE_IS_BROKEN
3466 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3467 # define FTELL_FOR_PIPE_IS_BROKEN
3472 #ifdef FTELL_FOR_PIPE_IS_BROKEN
3473 /* This loses the possibility to detect the bof
3474 * situation on perl -P when the libc5 is being used.
3475 * Workaround? Maybe attach some extra state to PL_rsfp?
3478 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
3480 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3483 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3484 s = swallow_bom((U8*)s);
3488 /* Incest with pod. */
3491 sv_catsv(thiswhite, PL_linestr);
3493 if (*s == '=' && strnEQ(s, "=cut", 4)) {
3494 sv_setpvn(PL_linestr, "", 0);
3495 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3496 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3497 PL_last_lop = PL_last_uni = NULL;
3498 PL_doextract = FALSE;
3502 } while (PL_doextract);
3503 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3504 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3505 SV * const sv = newSV(0);
3507 sv_upgrade(sv, SVt_PVMG);
3508 sv_setsv(sv,PL_linestr);
3511 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
3513 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3514 PL_last_lop = PL_last_uni = NULL;
3515 if (CopLINE(PL_curcop) == 1) {
3516 while (s < PL_bufend && isSPACE(*s))
3518 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3522 thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3526 if (*s == '#' && *(s+1) == '!')
3528 #ifdef ALTERNATE_SHEBANG
3530 static char const as[] = ALTERNATE_SHEBANG;
3531 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3532 d = s + (sizeof(as) - 1);
3534 #endif /* ALTERNATE_SHEBANG */
3543 while (*d && !isSPACE(*d))
3547 #ifdef ARG_ZERO_IS_SCRIPT
3548 if (ipathend > ipath) {
3550 * HP-UX (at least) sets argv[0] to the script name,
3551 * which makes $^X incorrect. And Digital UNIX and Linux,
3552 * at least, set argv[0] to the basename of the Perl
3553 * interpreter. So, having found "#!", we'll set it right.
3555 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3557 assert(SvPOK(x) || SvGMAGICAL(x));
3558 if (sv_eq(x, CopFILESV(PL_curcop))) {
3559 sv_setpvn(x, ipath, ipathend - ipath);
3565 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3566 const char * const lstart = SvPV_const(x,llen);
3568 bstart += blen - llen;
3569 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3570 sv_setpvn(x, ipath, ipathend - ipath);
3575 TAINT_NOT; /* $^X is always tainted, but that's OK */
3577 #endif /* ARG_ZERO_IS_SCRIPT */
3582 d = instr(s,"perl -");
3584 d = instr(s,"perl");
3586 /* avoid getting into infinite loops when shebang
3587 * line contains "Perl" rather than "perl" */
3589 for (d = ipathend-4; d >= ipath; --d) {
3590 if ((*d == 'p' || *d == 'P')
3591 && !ibcmp(d, "perl", 4))
3601 #ifdef ALTERNATE_SHEBANG
3603 * If the ALTERNATE_SHEBANG on this system starts with a
3604 * character that can be part of a Perl expression, then if
3605 * we see it but not "perl", we're probably looking at the
3606 * start of Perl code, not a request to hand off to some
3607 * other interpreter. Similarly, if "perl" is there, but
3608 * not in the first 'word' of the line, we assume the line
3609 * contains the start of the Perl program.
3611 if (d && *s != '#') {
3612 const char *c = ipath;
3613 while (*c && !strchr("; \t\r\n\f\v#", *c))
3616 d = NULL; /* "perl" not in first word; ignore */
3618 *s = '#'; /* Don't try to parse shebang line */
3620 #endif /* ALTERNATE_SHEBANG */
3621 #ifndef MACOS_TRADITIONAL
3626 !instr(s,"indir") &&
3627 instr(PL_origargv[0],"perl"))
3634 while (s < PL_bufend && isSPACE(*s))
3636 if (s < PL_bufend) {
3637 Newxz(newargv,PL_origargc+3,char*);
3639 while (s < PL_bufend && !isSPACE(*s))
3642 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3645 newargv = PL_origargv;
3648 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3650 Perl_croak(aTHX_ "Can't exec %s", ipath);
3654 while (*d && !isSPACE(*d)) d++;
3655 while (SPACE_OR_TAB(*d)) d++;
3658 const bool switches_done = PL_doswitches;
3659 const U32 oldpdb = PL_perldb;
3660 const bool oldn = PL_minus_n;
3661 const bool oldp = PL_minus_p;
3664 if (*d == 'M' || *d == 'm' || *d == 'C') {
3665 const char * const m = d;
3666 while (*d && !isSPACE(*d)) d++;
3667 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3670 d = moreswitches(d);
3672 if (PL_doswitches && !switches_done) {
3673 int argc = PL_origargc;
3674 char **argv = PL_origargv;
3677 } while (argc && argv[0][0] == '-' && argv[0][1]);
3678 init_argv_symbols(argc,argv);
3680 if ((PERLDB_LINE && !oldpdb) ||
3681 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3682 /* if we have already added "LINE: while (<>) {",
3683 we must not do it again */
3685 sv_setpvn(PL_linestr, "", 0);
3686 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3687 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3688 PL_last_lop = PL_last_uni = NULL;
3689 PL_preambled = FALSE;
3691 (void)gv_fetchfile(PL_origfilename);
3698 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3700 PL_lex_state = LEX_FORMLINE;
3705 #ifdef PERL_STRICT_CR
3706 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3708 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3710 case ' ': case '\t': case '\f': case 013:
3711 #ifdef MACOS_TRADITIONAL
3715 realtokenstart = -1;
3724 realtokenstart = -1;
3728 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3729 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3730 /* handle eval qq[#line 1 "foo"\n ...] */
3731 CopLINE_dec(PL_curcop);
3734 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3736 if (!PL_in_eval || PL_rsfp)
3741 while (d < PL_bufend && *d != '\n')
3745 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3746 Perl_croak(aTHX_ "panic: input overflow");
3749 thiswhite = newSVpvn(s, d - s);
3754 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3756 PL_lex_state = LEX_FORMLINE;
3762 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3763 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3766 TOKEN(PEG); /* make sure any #! line is accessible */
3771 /* if (PL_madskills && PL_lex_formbrack) { */
3773 while (d < PL_bufend && *d != '\n')
3777 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3778 Perl_croak(aTHX_ "panic: input overflow");
3779 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
3781 thiswhite = newSVpvn("",0);
3782 if (CopLINE(PL_curcop) == 1) {
3783 sv_setpvn(thiswhite, "", 0);
3786 sv_catpvn(thiswhite, s, d - s);
3800 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
3808 while (s < PL_bufend && SPACE_OR_TAB(*s))
3811 if (strnEQ(s,"=>",2)) {
3812 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
3813 DEBUG_T( { S_printbuf(aTHX_
3814 "### Saw unary minus before =>, forcing word %s\n", s);
3816 OPERATOR('-'); /* unary minus */
3818 PL_last_uni = PL_oldbufptr;
3820 case 'r': ftst = OP_FTEREAD; break;
3821 case 'w': ftst = OP_FTEWRITE; break;
3822 case 'x': ftst = OP_FTEEXEC; break;
3823 case 'o': ftst = OP_FTEOWNED; break;
3824 case 'R': ftst = OP_FTRREAD; break;
3825 case 'W': ftst = OP_FTRWRITE; break;
3826 case 'X': ftst = OP_FTREXEC; break;
3827 case 'O': ftst = OP_FTROWNED; break;
3828 case 'e': ftst = OP_FTIS; break;
3829 case 'z': ftst = OP_FTZERO; break;
3830 case 's': ftst = OP_FTSIZE; break;
3831 case 'f': ftst = OP_FTFILE; break;
3832 case 'd': ftst = OP_FTDIR; break;
3833 case 'l': ftst = OP_FTLINK; break;
3834 case 'p': ftst = OP_FTPIPE; break;
3835 case 'S': ftst = OP_FTSOCK; break;
3836 case 'u': ftst = OP_FTSUID; break;
3837 case 'g': ftst = OP_FTSGID; break;
3838 case 'k': ftst = OP_FTSVTX; break;
3839 case 'b': ftst = OP_FTBLK; break;
3840 case 'c': ftst = OP_FTCHR; break;
3841 case 't': ftst = OP_FTTTY; break;
3842 case 'T': ftst = OP_FTTEXT; break;
3843 case 'B': ftst = OP_FTBINARY; break;
3844 case 'M': case 'A': case 'C':
3845 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
3847 case 'M': ftst = OP_FTMTIME; break;
3848 case 'A': ftst = OP_FTATIME; break;
3849 case 'C': ftst = OP_FTCTIME; break;
3857 PL_last_lop_op = (OPCODE)ftst;
3858 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3859 "### Saw file test %c\n", (int)tmp);
3864 /* Assume it was a minus followed by a one-letter named
3865 * subroutine call (or a -bareword), then. */
3866 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3867 "### '-%c' looked like a file test but was not\n",
3874 const char tmp = *s++;
3877 if (PL_expect == XOPERATOR)
3882 else if (*s == '>') {
3885 if (isIDFIRST_lazy_if(s,UTF)) {
3886 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
3894 if (PL_expect == XOPERATOR)
3897 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3899 OPERATOR('-'); /* unary minus */
3905 const char tmp = *s++;
3908 if (PL_expect == XOPERATOR)
3913 if (PL_expect == XOPERATOR)
3916 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3923 if (PL_expect != XOPERATOR) {
3924 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3925 PL_expect = XOPERATOR;
3926 force_ident(PL_tokenbuf, '*');
3939 if (PL_expect == XOPERATOR) {
3943 PL_tokenbuf[0] = '%';
3944 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
3945 if (!PL_tokenbuf[1]) {
3948 PL_pending_ident = '%';
3959 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)
3960 && FEATURE_IS_ENABLED("~~"))
3967 const char tmp = *s++;
3973 goto just_a_word_zero_gv;
3976 switch (PL_expect) {
3982 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
3984 PL_bufptr = s; /* update in case we back off */
3990 PL_expect = XTERMBLOCK;
3993 stuffstart = s - SvPVX(PL_linestr) - 1;
3997 while (isIDFIRST_lazy_if(s,UTF)) {
3999 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4000 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
4001 if (tmp < 0) tmp = -tmp;
4017 d = scan_str(d,TRUE,TRUE);
4019 /* MUST advance bufptr here to avoid bogus
4020 "at end of line" context messages from yyerror().
4022 PL_bufptr = s + len;
4023 yyerror("Unterminated attribute parameter in attribute list");
4026 return REPORT(0); /* EOF indicator */
4030 SV *sv = newSVpvn(s, len);
4031 sv_catsv(sv, PL_lex_stuff);
4032 attrs = append_elem(OP_LIST, attrs,
4033 newSVOP(OP_CONST, 0, sv));
4034 SvREFCNT_dec(PL_lex_stuff);
4035 PL_lex_stuff = NULL;
4038 if (len == 6 && strnEQ(s, "unique", len)) {
4039 if (PL_in_my == KEY_our)
4041 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4043 /*EMPTY*/; /* skip to avoid loading attributes.pm */
4046 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4049 /* NOTE: any CV attrs applied here need to be part of
4050 the CVf_BUILTIN_ATTRS define in cv.h! */
4051 else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
4052 CvLVALUE_on(PL_compcv);
4053 else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
4054 CvLOCKED_on(PL_compcv);
4055 else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
4056 CvMETHOD_on(PL_compcv);
4057 else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len))
4058 CvASSERTION_on(PL_compcv);
4059 /* After we've set the flags, it could be argued that
4060 we don't need to do the attributes.pm-based setting
4061 process, and shouldn't bother appending recognized
4062 flags. To experiment with that, uncomment the
4063 following "else". (Note that's already been
4064 uncommented. That keeps the above-applied built-in
4065 attributes from being intercepted (and possibly
4066 rejected) by a package's attribute routines, but is
4067 justified by the performance win for the common case
4068 of applying only built-in attributes.) */
4070 attrs = append_elem(OP_LIST, attrs,
4071 newSVOP(OP_CONST, 0,
4075 if (*s == ':' && s[1] != ':')
4078 break; /* require real whitespace or :'s */
4079 /* XXX losing whitespace on sequential attributes here */
4083 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4084 if (*s != ';' && *s != '}' && *s != tmp
4085 && (tmp != '=' || *s != ')')) {
4086 const char q = ((*s == '\'') ? '"' : '\'');
4087 /* If here for an expression, and parsed no attrs, back
4089 if (tmp == '=' && !attrs) {
4093 /* MUST advance bufptr here to avoid bogus "at end of line"
4094 context messages from yyerror().
4098 ? Perl_form(aTHX_ "Invalid separator character "
4099 "%c%c%c in attribute list", q, *s, q)
4100 : "Unterminated attribute list" );
4108 start_force(curforce);
4109 NEXTVAL_NEXTTOKE.opval = attrs;
4110 CURMAD('_', nextwhite);
4115 thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4116 (s - SvPVX(PL_linestr)) - stuffstart);
4124 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4125 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4133 const char tmp = *s++;
4138 const char tmp = *s++;
4146 if (PL_lex_brackets <= 0)
4147 yyerror("Unmatched right square bracket");
4150 if (PL_lex_state == LEX_INTERPNORMAL) {
4151 if (PL_lex_brackets == 0) {
4152 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4153 PL_lex_state = LEX_INTERPEND;
4160 if (PL_lex_brackets > 100) {
4161 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4163 switch (PL_expect) {
4165 if (PL_lex_formbrack) {
4169 if (PL_oldoldbufptr == PL_last_lop)
4170 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4172 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4173 OPERATOR(HASHBRACK);
4175 while (s < PL_bufend && SPACE_OR_TAB(*s))
4178 PL_tokenbuf[0] = '\0';
4179 if (d < PL_bufend && *d == '-') {
4180 PL_tokenbuf[0] = '-';
4182 while (d < PL_bufend && SPACE_OR_TAB(*d))
4185 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4186 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4188 while (d < PL_bufend && SPACE_OR_TAB(*d))
4191 const char minus = (PL_tokenbuf[0] == '-');
4192 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4200 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4205 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4210 if (PL_oldoldbufptr == PL_last_lop)
4211 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4213 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4216 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4218 /* This hack is to get the ${} in the message. */
4220 yyerror("syntax error");
4223 OPERATOR(HASHBRACK);
4225 /* This hack serves to disambiguate a pair of curlies
4226 * as being a block or an anon hash. Normally, expectation
4227 * determines that, but in cases where we're not in a
4228 * position to expect anything in particular (like inside
4229 * eval"") we have to resolve the ambiguity. This code
4230 * covers the case where the first term in the curlies is a
4231 * quoted string. Most other cases need to be explicitly
4232 * disambiguated by prepending a "+" before the opening
4233 * curly in order to force resolution as an anon hash.
4235 * XXX should probably propagate the outer expectation
4236 * into eval"" to rely less on this hack, but that could
4237 * potentially break current behavior of eval"".
4241 if (*s == '\'' || *s == '"' || *s == '`') {
4242 /* common case: get past first string, handling escapes */
4243 for (t++; t < PL_bufend && *t != *s;)
4244 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4248 else if (*s == 'q') {
4251 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4254 /* skip q//-like construct */
4256 char open, close, term;
4259 while (t < PL_bufend && isSPACE(*t))
4261 /* check for q => */
4262 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4263 OPERATOR(HASHBRACK);
4267 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4271 for (t++; t < PL_bufend; t++) {
4272 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4274 else if (*t == open)
4278 for (t++; t < PL_bufend; t++) {
4279 if (*t == '\\' && t+1 < PL_bufend)
4281 else if (*t == close && --brackets <= 0)
4283 else if (*t == open)
4290 /* skip plain q word */
4291 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4294 else if (isALNUM_lazy_if(t,UTF)) {
4296 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4299 while (t < PL_bufend && isSPACE(*t))
4301 /* if comma follows first term, call it an anon hash */
4302 /* XXX it could be a comma expression with loop modifiers */
4303 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4304 || (*t == '=' && t[1] == '>')))
4305 OPERATOR(HASHBRACK);
4306 if (PL_expect == XREF)
4309 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4315 yylval.ival = CopLINE(PL_curcop);
4316 if (isSPACE(*s) || *s == '#')
4317 PL_copline = NOLINE; /* invalidate current command line number */
4322 if (PL_lex_brackets <= 0)
4323 yyerror("Unmatched right curly bracket");
4325 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4326 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4327 PL_lex_formbrack = 0;
4328 if (PL_lex_state == LEX_INTERPNORMAL) {
4329 if (PL_lex_brackets == 0) {
4330 if (PL_expect & XFAKEBRACK) {
4331 PL_expect &= XENUMMASK;
4332 PL_lex_state = LEX_INTERPEND;
4337 thiswhite = newSVpvn("",0);
4338 sv_catpvn(thiswhite,"}",1);
4341 return yylex(); /* ignore fake brackets */
4343 if (*s == '-' && s[1] == '>')
4344 PL_lex_state = LEX_INTERPENDMAYBE;
4345 else if (*s != '[' && *s != '{')
4346 PL_lex_state = LEX_INTERPEND;
4349 if (PL_expect & XFAKEBRACK) {
4350 PL_expect &= XENUMMASK;
4352 return yylex(); /* ignore fake brackets */
4354 start_force(curforce);
4356 curmad('X', newSVpvn(s-1,1));
4357 CURMAD('_', thiswhite);
4362 thistoken = newSVpvn("",0);
4370 if (PL_expect == XOPERATOR) {
4371 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4372 && isIDFIRST_lazy_if(s,UTF))
4374 CopLINE_dec(PL_curcop);
4375 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4376 CopLINE_inc(PL_curcop);
4381 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4383 PL_expect = XOPERATOR;
4384 force_ident(PL_tokenbuf, '&');
4388 yylval.ival = (OPpENTERSUB_AMPER<<8);
4400 const char tmp = *s++;
4407 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4408 && strchr("+-*/%.^&|<",tmp))
4409 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4410 "Reversed %c= operator",(int)tmp);
4412 if (PL_expect == XSTATE && isALPHA(tmp) &&
4413 (s == PL_linestart+1 || s[-2] == '\n') )
4415 if (PL_in_eval && !PL_rsfp) {
4420 if (strnEQ(s,"=cut",4)) {
4436 thiswhite = newSVpvn("",0);
4437 sv_catpvn(thiswhite, PL_linestart,
4438 PL_bufend - PL_linestart);
4442 PL_doextract = TRUE;
4446 if (PL_lex_brackets < PL_lex_formbrack) {
4448 #ifdef PERL_STRICT_CR
4449 for (t = s; SPACE_OR_TAB(*t); t++) ;
4451 for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
4453 if (*t == '\n' || *t == '#') {
4464 const char tmp = *s++;
4466 /* was this !=~ where !~ was meant?
4467 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4469 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4470 const char *t = s+1;
4472 while (t < PL_bufend && isSPACE(*t))
4475 if (*t == '/' || *t == '?' ||
4476 ((*t == 'm' || *t == 's' || *t == 'y')
4477 && !isALNUM(t[1])) ||
4478 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4479 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4480 "!=~ should be !~");
4490 if (PL_expect != XOPERATOR) {
4491 if (s[1] != '<' && !strchr(s,'>'))
4494 s = scan_heredoc(s);
4496 s = scan_inputsymbol(s);
4497 TERM(sublex_start());
4503 SHop(OP_LEFT_SHIFT);
4517 const char tmp = *s++;
4519 SHop(OP_RIGHT_SHIFT);
4529 if (PL_expect == XOPERATOR) {
4530 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4532 deprecate_old(commaless_variable_list);
4533 return REPORT(','); /* grandfather non-comma-format format */
4537 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4538 PL_tokenbuf[0] = '@';
4539 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4540 sizeof PL_tokenbuf - 1, FALSE);
4541 if (PL_expect == XOPERATOR)
4542 no_op("Array length", s);
4543 if (!PL_tokenbuf[1])
4545 PL_expect = XOPERATOR;
4546 PL_pending_ident = '#';
4550 PL_tokenbuf[0] = '$';
4551 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4552 sizeof PL_tokenbuf - 1, FALSE);
4553 if (PL_expect == XOPERATOR)
4555 if (!PL_tokenbuf[1]) {
4557 yyerror("Final $ should be \\$ or $name");
4561 /* This kludge not intended to be bulletproof. */
4562 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4563 yylval.opval = newSVOP(OP_CONST, 0,
4564 newSViv(PL_compiling.cop_arybase));
4565 yylval.opval->op_private = OPpCONST_ARYBASE;
4571 const char tmp = *s;
4572 if (PL_lex_state == LEX_NORMAL)
4575 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4576 && intuit_more(s)) {
4578 PL_tokenbuf[0] = '@';
4579 if (ckWARN(WARN_SYNTAX)) {
4582 isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
4585 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4586 while (t < PL_bufend && *t != ']')
4588 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4589 "Multidimensional syntax %.*s not supported",
4590 (int)((t - PL_bufptr) + 1), PL_bufptr);
4594 else if (*s == '{') {
4596 PL_tokenbuf[0] = '%';
4597 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4598 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4600 char tmpbuf[sizeof PL_tokenbuf];
4601 for (t++; isSPACE(*t); t++) ;
4602 if (isIDFIRST_lazy_if(t,UTF)) {
4604 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4606 for (; isSPACE(*t); t++) ;
4607 if (*t == ';' && get_cv(tmpbuf, FALSE))
4608 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4609 "You need to quote \"%s\"",
4616 PL_expect = XOPERATOR;
4617 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4618 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4619 if (!islop || PL_last_lop_op == OP_GREPSTART)
4620 PL_expect = XOPERATOR;
4621 else if (strchr("$@\"'`q", *s))
4622 PL_expect = XTERM; /* e.g. print $fh "foo" */
4623 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4624 PL_expect = XTERM; /* e.g. print $fh &sub */
4625 else if (isIDFIRST_lazy_if(s,UTF)) {
4626 char tmpbuf[sizeof PL_tokenbuf];
4628 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4629 if ((t2 = keyword(tmpbuf, len))) {
4630 /* binary operators exclude handle interpretations */
4642 PL_expect = XTERM; /* e.g. print $fh length() */
4647 PL_expect = XTERM; /* e.g. print $fh subr() */
4650 else if (isDIGIT(*s))
4651 PL_expect = XTERM; /* e.g. print $fh 3 */
4652 else if (*s == '.' && isDIGIT(s[1]))
4653 PL_expect = XTERM; /* e.g. print $fh .3 */
4654 else if ((*s == '?' || *s == '-' || *s == '+')
4655 && !isSPACE(s[1]) && s[1] != '=')
4656 PL_expect = XTERM; /* e.g. print $fh -1 */
4657 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4659 PL_expect = XTERM; /* e.g. print $fh /.../
4660 XXX except DORDOR operator
4662 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4664 PL_expect = XTERM; /* print $fh <<"EOF" */
4667 PL_pending_ident = '$';
4671 if (PL_expect == XOPERATOR)
4673 PL_tokenbuf[0] = '@';
4674 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4675 if (!PL_tokenbuf[1]) {
4678 if (PL_lex_state == LEX_NORMAL)
4680 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4682 PL_tokenbuf[0] = '%';
4684 /* Warn about @ where they meant $. */
4685 if (*s == '[' || *s == '{') {
4686 if (ckWARN(WARN_SYNTAX)) {
4687 const char *t = s + 1;
4688 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4690 if (*t == '}' || *t == ']') {
4692 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4693 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4694 "Scalar value %.*s better written as $%.*s",
4695 (int)(t-PL_bufptr), PL_bufptr,
4696 (int)(t-PL_bufptr-1), PL_bufptr+1);
4701 PL_pending_ident = '@';
4704 case '/': /* may be division, defined-or, or pattern */
4705 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4709 case '?': /* may either be conditional or pattern */
4710 if(PL_expect == XOPERATOR) {
4718 /* A // operator. */
4728 /* Disable warning on "study /blah/" */
4729 if (PL_oldoldbufptr == PL_last_uni
4730 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4731 || memNE(PL_last_uni, "study", 5)
4732 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4735 s = scan_pat(s,OP_MATCH);
4736 TERM(sublex_start());
4740 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4741 #ifdef PERL_STRICT_CR
4744 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4746 && (s == PL_linestart || s[-1] == '\n') )
4748 PL_lex_formbrack = 0;
4752 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4758 yylval.ival = OPf_SPECIAL;
4764 if (PL_expect != XOPERATOR)
4769 case '0': case '1': case '2': case '3': case '4':
4770 case '5': case '6': case '7': case '8': case '9':
4771 s = scan_num(s, &yylval);
4772 DEBUG_T( { S_printbuf(aTHX_ "### Saw number in %s\n", s); } );
4773 if (PL_expect == XOPERATOR)
4778 s = scan_str(s,!!PL_madskills,FALSE);
4779 DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } );
4780 if (PL_expect == XOPERATOR) {
4781 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4783 deprecate_old(commaless_variable_list);
4784 return REPORT(','); /* grandfather non-comma-format format */
4790 missingterm((char*)0);
4791 yylval.ival = OP_CONST;
4792 TERM(sublex_start());
4795 s = scan_str(s,!!PL_madskills,FALSE);
4796 DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } );
4797 if (PL_expect == XOPERATOR) {
4798 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4800 deprecate_old(commaless_variable_list);
4801 return REPORT(','); /* grandfather non-comma-format format */
4807 missingterm((char*)0);
4808 yylval.ival = OP_CONST;
4809 /* FIXME. I think that this can be const if char *d is replaced by
4810 more localised variables. */
4811 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
4812 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
4813 yylval.ival = OP_STRINGIFY;
4817 TERM(sublex_start());
4820 s = scan_str(s,!!PL_madskills,FALSE);
4821 DEBUG_T( { S_printbuf(aTHX_ "### Saw backtick string before %s\n", s); } );
4822 if (PL_expect == XOPERATOR)
4823 no_op("Backticks",s);
4825 missingterm((char*)0);
4826 yylval.ival = OP_BACKTICK;
4828 TERM(sublex_start());
4832 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
4833 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
4835 if (PL_expect == XOPERATOR)
4836 no_op("Backslash",s);
4840 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
4841 char *start = s + 2;
4842 while (isDIGIT(*start) || *start == '_')
4844 if (*start == '.' && isDIGIT(start[1])) {
4845 s = scan_num(s, &yylval);
4848 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
4849 else if (!isALPHA(*start) && (PL_expect == XTERM
4850 || PL_expect == XREF || PL_expect == XSTATE
4851 || PL_expect == XTERMORDORDOR)) {
4852 const char c = *start;
4855 gv = gv_fetchpv(s, 0, SVt_PVCV);
4858 s = scan_num(s, &yylval);
4865 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
4901 I32 orig_keyword = 0;
4906 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4908 /* Some keywords can be followed by any delimiter, including ':' */
4909 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
4910 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
4911 (PL_tokenbuf[0] == 'q' &&
4912 strchr("qwxr", PL_tokenbuf[1])))));
4914 /* x::* is just a word, unless x is "CORE" */
4915 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4919 while (d < PL_bufend && isSPACE(*d))
4920 d++; /* no comments skipped here, or s### is misparsed */
4922 /* Is this a label? */
4923 if (!tmp && PL_expect == XSTATE
4924 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
4926 yylval.pval = savepv(PL_tokenbuf);
4931 /* Check for keywords */
4932 tmp = keyword(PL_tokenbuf, len);
4934 /* Is this a word before a => operator? */
4935 if (*d == '=' && d[1] == '>') {
4938 = (OP*)newSVOP(OP_CONST, 0,
4939 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
4940 yylval.opval->op_private = OPpCONST_BARE;
4944 if (tmp < 0) { /* second-class keyword? */
4945 GV *ogv = NULL; /* override (winner) */
4946 GV *hgv = NULL; /* hidden (loser) */
4947 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
4949 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
4952 if (GvIMPORTED_CV(gv))
4954 else if (! CvMETHOD(cv))
4958 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
4959 (gv = *gvp) != (GV*)&PL_sv_undef &&
4960 GvCVu(gv) && GvIMPORTED_CV(gv))
4967 tmp = 0; /* overridden by import or by GLOBAL */
4970 && -tmp==KEY_lock /* XXX generalizable kludge */
4972 && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
4974 tmp = 0; /* any sub overrides "weak" keyword */
4976 else { /* no override */
4978 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
4979 Perl_warner(aTHX_ packWARN(WARN_MISC),
4980 "dump() better written as CORE::dump()");
4984 if (hgv && tmp != KEY_x && tmp != KEY_CORE
4985 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
4986 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4987 "Ambiguous call resolved as CORE::%s(), %s",
4988 GvENAME(hgv), "qualify as such or use &");
4995 default: /* not a keyword */
4996 /* Trade off - by using this evil construction we can pull the
4997 variable gv into the block labelled keylookup. If not, then
4998 we have to give it function scope so that the goto from the
4999 earlier ':' case doesn't bypass the initialisation. */
5001 just_a_word_zero_gv:
5009 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5012 SV *nextnextwhite = 0;
5016 /* Get the rest if it looks like a package qualifier */
5018 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5020 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5023 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5024 *s == '\'' ? "'" : "::");
5029 if (PL_expect == XOPERATOR) {
5030 if (PL_bufptr == PL_linestart) {
5031 CopLINE_dec(PL_curcop);
5032 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5033 CopLINE_inc(PL_curcop);
5036 no_op("Bareword",s);
5039 /* Look for a subroutine with this name in current package,
5040 unless name is "Foo::", in which case Foo is a bearword
5041 (and a package name). */
5043 if (len > 2 && !PL_madskills &&
5044 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5046 if (ckWARN(WARN_BAREWORD)
5047 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5048 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5049 "Bareword \"%s\" refers to nonexistent package",
5052 PL_tokenbuf[len] = '\0';
5058 /* Mustn't actually add anything to a symbol table.
5059 But also don't want to "initialise" any placeholder
5060 constants that might already be there into full
5061 blown PVGVs with attached PVCV. */
5062 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5063 GV_NOADD_NOINIT, SVt_PVCV);
5068 /* if we saw a global override before, get the right name */
5071 sv = newSVpvs("CORE::GLOBAL::");
5072 sv_catpv(sv,PL_tokenbuf);
5075 /* If len is 0, newSVpv does strlen(), which is correct.
5076 If len is non-zero, then it will be the true length,
5077 and so the scalar will be created correctly. */
5078 sv = newSVpv(PL_tokenbuf,len);
5081 if (PL_madskills && !thistoken) {
5082 char *start = SvPVX(PL_linestr) + realtokenstart;
5083 thistoken = newSVpv(start,s - start);
5084 realtokenstart = s - SvPVX(PL_linestr);
5088 /* Presume this is going to be a bareword of some sort. */
5091 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5092 yylval.opval->op_private = OPpCONST_BARE;
5093 /* UTF-8 package name? */
5094 if (UTF && !IN_BYTES &&
5095 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5098 /* And if "Foo::", then that's what it certainly is. */
5103 /* Do the explicit type check so that we don't need to force
5104 the initialisation of the symbol table to have a real GV.
5105 Beware - gv may not really be a PVGV, cv may not really be
5106 a PVCV, (because of the space optimisations that gv_init
5107 understands) But they're true if for this symbol there is
5108 respectively a typeglob and a subroutine.
5110 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5111 /* Real typeglob, so get the real subroutine: */
5113 /* A proxy for a subroutine in this package? */
5114 : SvOK(gv) ? (CV *) gv : NULL)
5117 /* See if it's the indirect object for a list operator. */
5119 if (PL_oldoldbufptr &&
5120 PL_oldoldbufptr < PL_bufptr &&
5121 (PL_oldoldbufptr == PL_last_lop
5122 || PL_oldoldbufptr == PL_last_uni) &&
5123 /* NO SKIPSPACE BEFORE HERE! */
5124 (PL_expect == XREF ||
5125 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5127 bool immediate_paren = *s == '(';
5129 /* (Now we can afford to cross potential line boundary.) */
5130 s = SKIPSPACE2(s,nextnextwhite);
5132 nextwhite = nextnextwhite; /* assume no & deception */
5135 /* Two barewords in a row may indicate method call. */
5137 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5138 (tmp = intuit_method(s, gv, cv)))
5141 /* If not a declared subroutine, it's an indirect object. */
5142 /* (But it's an indir obj regardless for sort.) */
5143 /* Also, if "_" follows a filetest operator, it's a bareword */
5146 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5148 (PL_last_lop_op != OP_MAPSTART &&
5149 PL_last_lop_op != OP_GREPSTART))))
5150 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5151 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5154 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5159 PL_expect = XOPERATOR;
5162 s = SKIPSPACE2(s,nextnextwhite);
5163 nextwhite = nextnextwhite;
5168 /* Is this a word before a => operator? */
5169 if (*s == '=' && s[1] == '>' && !pkgname) {
5171 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5172 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5173 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5177 /* If followed by a paren, it's certainly a subroutine. */
5181 for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
5182 if (*d == ')' && (sv = gv_const_sv(gv))) {
5186 char *par = SvPVX(PL_linestr) + realtokenstart;
5187 sv_catpvn(thistoken, par, s - par);
5199 nextwhite = thiswhite;
5202 start_force(curforce);
5204 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5205 PL_expect = XOPERATOR;
5208 nextwhite = nextnextwhite;
5209 curmad('X', thistoken);
5210 thistoken = newSVpvn("",0);
5218 /* If followed by var or block, call it a method (unless sub) */
5220 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5221 PL_last_lop = PL_oldbufptr;
5222 PL_last_lop_op = OP_METHOD;
5226 /* If followed by a bareword, see if it looks like indir obj. */
5229 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5230 && (tmp = intuit_method(s, gv, cv)))
5233 /* Not a method, so call it a subroutine (if defined) */
5236 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5237 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5238 "Ambiguous use of -%s resolved as -&%s()",
5239 PL_tokenbuf, PL_tokenbuf);
5240 /* Check for a constant sub */
5241 if ((sv = gv_const_sv(gv))) {
5243 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5244 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5245 yylval.opval->op_private = 0;
5249 /* Resolve to GV now. */
5250 if (SvTYPE(gv) != SVt_PVGV) {
5251 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5252 assert (SvTYPE(gv) == SVt_PVGV);
5253 /* cv must have been some sort of placeholder, so
5254 now needs replacing with a real code reference. */
5258 op_free(yylval.opval);
5259 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5260 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5261 PL_last_lop = PL_oldbufptr;
5262 PL_last_lop_op = OP_ENTERSUB;
5263 /* Is there a prototype? */
5270 const char *proto = SvPV_const((SV*)cv, protolen);
5273 if (*proto == '$' && proto[1] == '\0')
5275 while (*proto == ';')
5277 if (*proto == '&' && *s == '{') {
5278 sv_setpv(PL_subname, PL_curstash ?
5279 "__ANON__" : "__ANON__::__ANON__");
5286 nextwhite = thiswhite;
5289 start_force(curforce);
5290 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5293 nextwhite = nextnextwhite;
5294 curmad('X', thistoken);
5295 thistoken = newSVpvn("",0);
5302 /* Guess harder when madskills require "best effort". */
5303 if (PL_madskills && (!gv || !GvCVu(gv))) {
5304 int probable_sub = 0;
5305 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5307 else if (isALPHA(*s)) {
5311 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5312 if (!keyword(tmpbuf,tmplen))
5315 while (d < PL_bufend && isSPACE(*d))
5317 if (*d == '=' && d[1] == '>')
5322 gv = gv_fetchpv(PL_tokenbuf, TRUE, SVt_PVCV);
5323 op_free(yylval.opval);
5324 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5325 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5326 PL_last_lop = PL_oldbufptr;
5327 PL_last_lop_op = OP_ENTERSUB;
5328 nextwhite = thiswhite;
5330 start_force(curforce);
5331 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5333 nextwhite = nextnextwhite;
5334 curmad('X', thistoken);
5335 thistoken = newSVpvn("",0);
5340 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5347 /* Call it a bare word */
5349 if (PL_hints & HINT_STRICT_SUBS)
5350 yylval.opval->op_private |= OPpCONST_STRICT;
5353 if (lastchar != '-') {
5354 if (ckWARN(WARN_RESERVED)) {
5355 for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
5356 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
5357 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5364 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5365 && ckWARN_d(WARN_AMBIGUOUS)) {
5366 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5367 "Operator or semicolon missing before %c%s",
5368 lastchar, PL_tokenbuf);
5369 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5370 "Ambiguous use of %c resolved as operator %c",
5371 lastchar, lastchar);
5377 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5378 newSVpv(CopFILE(PL_curcop),0));
5382 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5383 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5386 case KEY___PACKAGE__:
5387 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5389 ? newSVhek(HvNAME_HEK(PL_curstash))
5396 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5397 const char *pname = "main";
5398 if (PL_tokenbuf[2] == 'D')
5399 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5400 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5404 GvIOp(gv) = newIO();
5405 IoIFP(GvIOp(gv)) = PL_rsfp;
5406 #if defined(HAS_FCNTL) && defined(F_SETFD)
5408 const int fd = PerlIO_fileno(PL_rsfp);
5409 fcntl(fd,F_SETFD,fd >= 3);
5412 /* Mark this internal pseudo-handle as clean */
5413 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5415 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5416 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5417 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5419 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5420 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5421 /* if the script was opened in binmode, we need to revert
5422 * it to text mode for compatibility; but only iff it has CRs
5423 * XXX this is a questionable hack at best. */
5424 if (PL_bufend-PL_bufptr > 2
5425 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5428 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5429 loc = PerlIO_tell(PL_rsfp);
5430 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5433 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5435 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5436 #endif /* NETWARE */
5437 #ifdef PERLIO_IS_STDIO /* really? */
5438 # if defined(__BORLANDC__)
5439 /* XXX see note in do_binmode() */
5440 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5444 PerlIO_seek(PL_rsfp, loc, 0);
5448 #ifdef PERLIO_LAYERS
5451 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5452 else if (PL_encoding) {
5459 XPUSHs(PL_encoding);
5461 call_method("name", G_SCALAR);
5465 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5466 Perl_form(aTHX_ ":encoding(%"SVf")",
5475 if (realtokenstart >= 0) {
5476 char *tstart = SvPVX(PL_linestr) + realtokenstart;
5478 endwhite = newSVpvn("",0);
5479 sv_catsv(endwhite, thiswhite);
5481 sv_catpvn(endwhite, tstart, PL_bufend - tstart);
5482 realtokenstart = -1;
5484 while ((s = filter_gets(endwhite, PL_rsfp,
5485 SvCUR(endwhite))) != Nullch) ;
5499 if (PL_expect == XSTATE) {
5506 if (*s == ':' && s[1] == ':') {
5509 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5510 if (!(tmp = keyword(PL_tokenbuf, len)))
5511 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5514 else if (tmp == KEY_require || tmp == KEY_do)
5515 /* that's a way to remember we saw "CORE::" */
5528 LOP(OP_ACCEPT,XTERM);
5534 LOP(OP_ATAN2,XTERM);
5540 LOP(OP_BINMODE,XTERM);
5543 LOP(OP_BLESS,XTERM);
5552 /* When 'use switch' is in effect, continue has a dual
5553 life as a control operator. */
5555 if (!FEATURE_IS_ENABLED("switch"))
5558 /* We have to disambiguate the two senses of
5559 "continue". If the next token is a '{' then
5560 treat it as the start of a continue block;
5561 otherwise treat it as a control operator.
5573 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5590 if (!PL_cryptseen) {
5591 PL_cryptseen = TRUE;
5595 LOP(OP_CRYPT,XTERM);
5598 LOP(OP_CHMOD,XTERM);
5601 LOP(OP_CHOWN,XTERM);
5604 LOP(OP_CONNECT,XTERM);
5623 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5624 if (orig_keyword == KEY_do) {
5633 PL_hints |= HINT_BLOCK_SCOPE;
5643 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5644 LOP(OP_DBMOPEN,XTERM);
5650 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5657 yylval.ival = CopLINE(PL_curcop);
5673 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5674 UNIBRACK(OP_ENTEREVAL);
5692 case KEY_endhostent:
5698 case KEY_endservent:
5701 case KEY_endprotoent:
5712 yylval.ival = CopLINE(PL_curcop);
5714 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5717 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5720 if ((PL_bufend - p) >= 3 &&
5721 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5723 else if ((PL_bufend - p) >= 4 &&
5724 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5727 if (isIDFIRST_lazy_if(p,UTF)) {
5728 p = scan_ident(p, PL_bufend,
5729 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5733 Perl_croak(aTHX_ "Missing $ on loop variable");
5735 s = SvPVX(PL_linestr) + soff;
5741 LOP(OP_FORMLINE,XTERM);
5747 LOP(OP_FCNTL,XTERM);
5753 LOP(OP_FLOCK,XTERM);
5762 LOP(OP_GREPSTART, XREF);
5765 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5780 case KEY_getpriority:
5781 LOP(OP_GETPRIORITY,XTERM);
5783 case KEY_getprotobyname:
5786 case KEY_getprotobynumber:
5787 LOP(OP_GPBYNUMBER,XTERM);
5789 case KEY_getprotoent:
5801 case KEY_getpeername:
5802 UNI(OP_GETPEERNAME);
5804 case KEY_gethostbyname:
5807 case KEY_gethostbyaddr:
5808 LOP(OP_GHBYADDR,XTERM);
5810 case KEY_gethostent:
5813 case KEY_getnetbyname:
5816 case KEY_getnetbyaddr:
5817 LOP(OP_GNBYADDR,XTERM);
5822 case KEY_getservbyname:
5823 LOP(OP_GSBYNAME,XTERM);
5825 case KEY_getservbyport:
5826 LOP(OP_GSBYPORT,XTERM);
5828 case KEY_getservent:
5831 case KEY_getsockname:
5832 UNI(OP_GETSOCKNAME);
5834 case KEY_getsockopt:
5835 LOP(OP_GSOCKOPT,XTERM);
5850 yylval.ival = CopLINE(PL_curcop);
5861 yylval.ival = CopLINE(PL_curcop);
5865 LOP(OP_INDEX,XTERM);
5871 LOP(OP_IOCTL,XTERM);
5883 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5915 LOP(OP_LISTEN,XTERM);
5924 s = scan_pat(s,OP_MATCH);
5925 TERM(sublex_start());
5928 LOP(OP_MAPSTART, XREF);
5931 LOP(OP_MKDIR,XTERM);
5934 LOP(OP_MSGCTL,XTERM);
5937 LOP(OP_MSGGET,XTERM);
5940 LOP(OP_MSGRCV,XTERM);
5943 LOP(OP_MSGSND,XTERM);
5949 if (isIDFIRST_lazy_if(s,UTF)) {
5953 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
5954 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
5956 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
5957 if (!PL_in_my_stash) {
5960 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
5964 if (PL_madskills) { /* just add type to declarator token */
5965 sv_catsv(thistoken, nextwhite);
5967 sv_catpvn(thistoken, start, s - start);
5975 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5982 s = tokenize_use(0, s);
5986 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
5993 if (isIDFIRST_lazy_if(s,UTF)) {
5995 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
5996 for (t=d; *t && isSPACE(*t); t++) ;
5997 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
5999 && !(t[0] == '=' && t[1] == '>')
6001 int parms_len = (int)(d-s);
6002 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6003 "Precedence problem: open %.*s should be open(%.*s)",
6004 parms_len, s, parms_len, s);
6010 yylval.ival = OP_OR;
6020 LOP(OP_OPEN_DIR,XTERM);
6023 checkcomma(s,PL_tokenbuf,"filehandle");
6027 checkcomma(s,PL_tokenbuf,"filehandle");
6046 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6050 LOP(OP_PIPE_OP,XTERM);
6053 s = scan_str(s,!!PL_madskills,FALSE);
6055 missingterm((char*)0);
6056 yylval.ival = OP_CONST;
6057 TERM(sublex_start());
6063 s = scan_str(s,!!PL_madskills,FALSE);
6065 missingterm((char*)0);
6066 PL_expect = XOPERATOR;
6068 if (SvCUR(PL_lex_stuff)) {
6071 d = SvPV_force(PL_lex_stuff, len);
6074 for (; isSPACE(*d) && len; --len, ++d) ;
6077 if (!warned && ckWARN(WARN_QW)) {
6078 for (; !isSPACE(*d) && len; --len, ++d) {
6080 Perl_warner(aTHX_ packWARN(WARN_QW),
6081 "Possible attempt to separate words with commas");
6084 else if (*d == '#') {
6085 Perl_warner(aTHX_ packWARN(WARN_QW),
6086 "Possible attempt to put comments in qw() list");
6092 for (; !isSPACE(*d) && len; --len, ++d) ;
6094 sv = newSVpvn(b, d-b);
6095 if (DO_UTF8(PL_lex_stuff))
6097 words = append_elem(OP_LIST, words,
6098 newSVOP(OP_CONST, 0, tokeq(sv)));
6102 start_force(curforce);
6103 NEXTVAL_NEXTTOKE.opval = words;
6108 SvREFCNT_dec(PL_lex_stuff);
6109 PL_lex_stuff = NULL;
6115 s = scan_str(s,!!PL_madskills,FALSE);
6117 missingterm((char*)0);
6118 yylval.ival = OP_STRINGIFY;
6119 if (SvIVX(PL_lex_stuff) == '\'')
6120 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6121 TERM(sublex_start());
6124 s = scan_pat(s,OP_QR);
6125 TERM(sublex_start());
6128 s = scan_str(s,!!PL_madskills,FALSE);
6130 missingterm((char*)0);
6131 yylval.ival = OP_BACKTICK;
6133 TERM(sublex_start());
6141 s = force_version(s, FALSE);
6143 else if (*s != 'v' || !isDIGIT(s[1])
6144 || (s = force_version(s, TRUE), *s == 'v'))
6146 *PL_tokenbuf = '\0';
6147 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6148 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6149 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
6151 yyerror("<> should be quotes");
6153 if (orig_keyword == KEY_require) {
6161 PL_last_uni = PL_oldbufptr;
6162 PL_last_lop_op = OP_REQUIRE;
6164 return REPORT( (int)REQUIRE );
6170 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6174 LOP(OP_RENAME,XTERM);
6183 LOP(OP_RINDEX,XTERM);
6193 UNIDOR(OP_READLINE);
6206 LOP(OP_REVERSE,XTERM);
6209 UNIDOR(OP_READLINK);
6217 TERM(sublex_start());
6219 TOKEN(1); /* force error */
6222 checkcomma(s,PL_tokenbuf,"filehandle");
6232 LOP(OP_SELECT,XTERM);
6238 LOP(OP_SEMCTL,XTERM);
6241 LOP(OP_SEMGET,XTERM);
6244 LOP(OP_SEMOP,XTERM);
6250 LOP(OP_SETPGRP,XTERM);
6252 case KEY_setpriority:
6253 LOP(OP_SETPRIORITY,XTERM);
6255 case KEY_sethostent:
6261 case KEY_setservent:
6264 case KEY_setprotoent:
6274 LOP(OP_SEEKDIR,XTERM);
6276 case KEY_setsockopt:
6277 LOP(OP_SSOCKOPT,XTERM);
6283 LOP(OP_SHMCTL,XTERM);
6286 LOP(OP_SHMGET,XTERM);
6289 LOP(OP_SHMREAD,XTERM);
6292 LOP(OP_SHMWRITE,XTERM);
6295 LOP(OP_SHUTDOWN,XTERM);
6304 LOP(OP_SOCKET,XTERM);
6306 case KEY_socketpair:
6307 LOP(OP_SOCKPAIR,XTERM);
6310 checkcomma(s,PL_tokenbuf,"subroutine name");
6312 if (*s == ';' || *s == ')') /* probably a close */
6313 Perl_croak(aTHX_ "sort is now a reserved word");
6315 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6319 LOP(OP_SPLIT,XTERM);
6322 LOP(OP_SPRINTF,XTERM);
6325 LOP(OP_SPLICE,XTERM);
6340 LOP(OP_SUBSTR,XTERM);
6346 char tmpbuf[sizeof PL_tokenbuf];
6347 SSize_t tboffset = 0;
6348 expectation attrful;
6349 bool have_name, have_proto, bad_proto;
6350 const int key = tmp;
6355 char *tstart = SvPVX(PL_linestr) + realtokenstart;
6356 SV *subtoken = newSVpvn(tstart, s - tstart);
6360 s = SKIPSPACE2(s,tmpwhite);
6365 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6366 (*s == ':' && s[1] == ':'))
6373 attrful = XATTRBLOCK;
6374 /* remember buffer pos'n for later force_word */
6375 tboffset = s - PL_oldbufptr;
6376 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6379 nametoke = newSVpvn(s, d - s);
6381 if (strchr(tmpbuf, ':'))
6382 sv_setpv(PL_subname, tmpbuf);
6384 sv_setsv(PL_subname,PL_curstname);
6385 sv_catpvs(PL_subname,"::");
6386 sv_catpvn(PL_subname,tmpbuf,len);
6393 CURMAD('X', nametoke);
6394 CURMAD('_', tmpwhite);
6395 (void) force_word(PL_oldbufptr + tboffset, WORD,
6398 s = SKIPSPACE2(d,tmpwhite);
6405 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6406 PL_expect = XTERMBLOCK;
6407 attrful = XATTRTERM;
6408 sv_setpvn(PL_subname,"?",1);
6412 if (key == KEY_format) {
6414 PL_lex_formbrack = PL_lex_brackets + 1;
6416 thistoken = subtoken;
6420 (void) force_word(PL_oldbufptr + tboffset, WORD,
6426 /* Look for a prototype */
6430 s = scan_str(s,!!PL_madskills,FALSE);
6432 Perl_croak(aTHX_ "Prototype not terminated");
6433 /* strip spaces and check for bad characters */
6434 d = SvPVX(PL_lex_stuff);
6437 for (p = d; *p; ++p) {
6440 if (!strchr("$@%*;[]&\\", *p))
6445 if (bad_proto && ckWARN(WARN_SYNTAX))
6446 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6447 "Illegal character in prototype for %"SVf" : %s",
6449 SvCUR_set(PL_lex_stuff, tmp);
6454 CURMAD('q', thisopen);
6455 CURMAD('_', tmpwhite);
6456 CURMAD('=', thisstuff);
6457 CURMAD('Q', thisclose);
6458 NEXTVAL_NEXTTOKE.opval =
6459 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6460 PL_lex_stuff = Nullsv;
6463 s = SKIPSPACE2(s,tmpwhite);
6471 if (*s == ':' && s[1] != ':')
6472 PL_expect = attrful;
6473 else if (*s != '{' && key == KEY_sub) {
6475 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6477 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname);
6484 curmad('^', newSVpvn("",0));
6485 CURMAD('_', tmpwhite);
6489 thistoken = subtoken;
6492 NEXTVAL_NEXTTOKE.opval =
6493 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6494 PL_lex_stuff = NULL;
6499 sv_setpv(PL_subname,
6500 PL_curstash ? "__ANON__" : "__ANON__::__ANON__");
6504 (void) force_word(PL_oldbufptr + tboffset, WORD,
6514 LOP(OP_SYSTEM,XREF);
6517 LOP(OP_SYMLINK,XTERM);
6520 LOP(OP_SYSCALL,XTERM);
6523 LOP(OP_SYSOPEN,XTERM);
6526 LOP(OP_SYSSEEK,XTERM);
6529 LOP(OP_SYSREAD,XTERM);
6532 LOP(OP_SYSWRITE,XTERM);
6536 TERM(sublex_start());
6557 LOP(OP_TRUNCATE,XTERM);
6569 yylval.ival = CopLINE(PL_curcop);
6573 yylval.ival = CopLINE(PL_curcop);
6577 LOP(OP_UNLINK,XTERM);
6583 LOP(OP_UNPACK,XTERM);
6586 LOP(OP_UTIME,XTERM);
6592 LOP(OP_UNSHIFT,XTERM);
6595 s = tokenize_use(1, s);
6605 yylval.ival = CopLINE(PL_curcop);
6609 yylval.ival = CopLINE(PL_curcop);
6613 PL_hints |= HINT_BLOCK_SCOPE;
6620 LOP(OP_WAITPID,XTERM);
6629 ctl_l[0] = toCTRL('L');
6631 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6634 /* Make sure $^L is defined */
6635 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6640 if (PL_expect == XOPERATOR)
6646 yylval.ival = OP_XOR;
6651 TERM(sublex_start());
6656 #pragma segment Main
6660 S_pending_ident(pTHX)
6664 register I32 tmp = 0;
6665 /* pit holds the identifier we read and pending_ident is reset */
6666 char pit = PL_pending_ident;
6667 PL_pending_ident = 0;
6669 /* realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6670 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6671 "### Pending identifier '%s'\n", PL_tokenbuf); });
6673 /* if we're in a my(), we can't allow dynamics here.
6674 $foo'bar has already been turned into $foo::bar, so
6675 just check for colons.
6677 if it's a legal name, the OP is a PADANY.
6680 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6681 if (strchr(PL_tokenbuf,':'))
6682 yyerror(Perl_form(aTHX_ "No package name allowed for "
6683 "variable %s in \"our\"",
6685 tmp = allocmy(PL_tokenbuf);
6688 if (strchr(PL_tokenbuf,':'))
6689 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
6691 yylval.opval = newOP(OP_PADANY, 0);
6692 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6698 build the ops for accesses to a my() variable.
6700 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6701 then used in a comparison. This catches most, but not
6702 all cases. For instance, it catches
6703 sort { my($a); $a <=> $b }
6705 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6706 (although why you'd do that is anyone's guess).
6709 if (!strchr(PL_tokenbuf,':')) {
6711 tmp = pad_findmy(PL_tokenbuf);
6712 if (tmp != NOT_IN_PAD) {
6713 /* might be an "our" variable" */
6714 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6715 /* build ops for a bareword */
6716 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6717 HEK * const stashname = HvNAME_HEK(stash);
6718 SV * const sym = newSVhek(stashname);
6719 sv_catpvs(sym, "::");
6720 sv_catpv(sym, PL_tokenbuf+1);
6721 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6722 yylval.opval->op_private = OPpCONST_ENTERED;
6725 ? (GV_ADDMULTI | GV_ADDINEVAL)
6728 ((PL_tokenbuf[0] == '$') ? SVt_PV
6729 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6734 /* if it's a sort block and they're naming $a or $b */
6735 if (PL_last_lop_op == OP_SORT &&
6736 PL_tokenbuf[0] == '$' &&
6737 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6740 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6741 d < PL_bufend && *d != '\n';
6744 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6745 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6751 yylval.opval = newOP(OP_PADANY, 0);
6752 yylval.opval->op_targ = tmp;
6758 Whine if they've said @foo in a doublequoted string,
6759 and @foo isn't a variable we can find in the symbol
6762 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
6763 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
6764 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
6765 && ckWARN(WARN_AMBIGUOUS))
6767 /* Downgraded from fatal to warning 20000522 mjd */
6768 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6769 "Possible unintended interpolation of %s in string",
6774 /* build ops for a bareword */
6775 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
6776 yylval.opval->op_private = OPpCONST_ENTERED;
6779 /* If the identifier refers to a stash, don't autovivify it.
6780 * Change 24660 had the side effect of causing symbol table
6781 * hashes to always be defined, even if they were freshly
6782 * created and the only reference in the entire program was
6783 * the single statement with the defined %foo::bar:: test.
6784 * It appears that all code in the wild doing this actually
6785 * wants to know whether sub-packages have been loaded, so
6786 * by avoiding auto-vivifying symbol tables, we ensure that
6787 * defined %foo::bar:: continues to be false, and the existing
6788 * tests still give the expected answers, even though what
6789 * they're actually testing has now changed subtly.
6791 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
6793 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
6794 ((PL_tokenbuf[0] == '$') ? SVt_PV
6795 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6801 * The following code was generated by perl_keyword.pl.
6805 Perl_keyword (pTHX_ const char *name, I32 len)
6810 case 1: /* 5 tokens of length 1 */
6842 case 2: /* 18 tokens of length 2 */
6988 case 3: /* 29 tokens of length 3 */
6992 if (name[1] == 'N' &&
7055 if (name[1] == 'i' &&
7077 return (FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7095 if (name[1] == 'o' &&
7104 if (name[1] == 'e' &&
7113 if (name[1] == 'n' &&
7122 if (name[1] == 'o' &&
7131 if (name[1] == 'a' &&
7140 if (name[1] == 'o' &&
7202 if (name[1] == 'e' &&
7216 return (FEATURE_IS_ENABLED("say") ? -KEY_say : 0);
7242 if (name[1] == 'i' &&
7251 if (name[1] == 's' &&
7260 if (name[1] == 'e' &&
7269 if (name[1] == 'o' &&
7281 case 4: /* 41 tokens of length 4 */
7285 if (name[1] == 'O' &&
7295 if (name[1] == 'N' &&
7305 if (name[1] == 'i' &&
7315 if (name[1] == 'h' &&
7325 if (name[1] == 'u' &&
7338 if (name[2] == 'c' &&
7347 if (name[2] == 's' &&
7356 if (name[2] == 'a' &&
7392 if (name[1] == 'o' &&
7405 if (name[2] == 't' &&
7414 if (name[2] == 'o' &&
7423 if (name[2] == 't' &&
7432 if (name[2] == 'e' &&
7445 if (name[1] == 'o' &&
7458 if (name[2] == 'y' &&
7467 if (name[2] == 'l' &&
7483 if (name[2] == 's' &&
7492 if (name[2] == 'n' &&
7501 if (name[2] == 'c' &&
7514 if (name[1] == 'e' &&
7524 if (name[1] == 'p' &&
7537 if (name[2] == 'c' &&
7546 if (name[2] == 'p' &&
7555 if (name[2] == 's' &&
7571 if (name[2] == 'n' &&
7641 if (name[2] == 'r' &&
7650 if (name[2] == 'r' &&
7659 if (name[2] == 'a' &&
7675 if (name[2] == 'l' &&
7737 if (name[2] == 'e' &&
7740 return (FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
7753 case 5: /* 38 tokens of length 5 */
7757 if (name[1] == 'E' &&
7768 if (name[1] == 'H' &&
7782 if (name[2] == 'a' &&
7792 if (name[2] == 'a' &&
7809 if (name[2] == 'e' &&
7819 if (name[2] == 'e' &&
7823 return (FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
7839 if (name[3] == 'i' &&
7848 if (name[3] == 'o' &&
7884 if (name[2] == 'o' &&
7894 if (name[2] == 'y' &&
7908 if (name[1] == 'l' &&
7922 if (name[2] == 'n' &&
7932 if (name[2] == 'o' &&
7946 if (name[1] == 'i' &&
7951 return (FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
7960 if (name[2] == 'd' &&
7970 if (name[2] == 'c' &&
7987 if (name[2] == 'c' &&
7997 if (name[2] == 't' &&
8011 if (name[1] == 'k' &&
8022 if (name[1] == 'r' &&
8036 if (name[2] == 's' &&
8046 if (name[2] == 'd' &&
8063 if (name[2] == 'm' &&
8073 if (name[2] == 'i' &&
8083 if (name[2] == 'e' &&
8093 if (name[2] == 'l' &&
8103 if (name[2] == 'a' &&
8113 if (name[2] == 'u' &&
8127 if (name[1] == 'i' &&
8141 if (name[2] == 'a' &&
8154 if (name[3] == 'e' &&
8189 if (name[2] == 'i' &&
8206 if (name[2] == 'i' &&
8216 if (name[2] == 'i' &&
8233 case 6: /* 33 tokens of length 6 */
8237 if (name[1] == 'c' &&
8252 if (name[2] == 'l' &&
8263 if (name[2] == 'r' &&
8278 if (name[1] == 'e' &&
8293 if (name[2] == 's' &&
8298 if(ckWARN_d(WARN_SYNTAX))
8299 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8305 if (name[2] == 'i' &&
8323 if (name[2] == 'l' &&
8334 if (name[2] == 'r' &&
8349 if (name[1] == 'm' &&
8364 if (name[2] == 'n' &&
8375 if (name[2] == 's' &&
8390 if (name[1] == 's' &&
8396 if (name[4] == 't' &&
8405 if (name[4] == 'e' &&
8414 if (name[4] == 'c' &&
8423 if (name[4] == 'n' &&
8439 if (name[1] == 'r' &&
8457 if (name[3] == 'a' &&
8467 if (name[3] == 'u' &&
8481 if (name[2] == 'n' &&
8499 if (name[2] == 'a' &&
8513 if (name[3] == 'e' &&
8526 if (name[4] == 't' &&
8535 if (name[4] == 'e' &&
8557 if (name[4] == 't' &&
8566 if (name[4] == 'e' &&
8582 if (name[2] == 'c' &&
8593 if (name[2] == 'l' &&
8604 if (name[2] == 'b' &&
8615 if (name[2] == 's' &&
8638 if (name[4] == 's' &&
8647 if (name[4] == 'n' &&
8660 if (name[3] == 'a' &&
8677 if (name[1] == 'a' &&
8692 case 7: /* 29 tokens of length 7 */
8696 if (name[1] == 'E' &&
8709 if (name[1] == '_' &&
8722 if (name[1] == 'i' &&
8729 return -KEY_binmode;
8735 if (name[1] == 'o' &&
8742 return -KEY_connect;
8751 if (name[2] == 'm' &&
8757 return -KEY_dbmopen;
8768 if (name[4] == 'u' &&
8772 return (FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
8778 if (name[4] == 'n' &&
8799 if (name[1] == 'o' &&
8812 if (name[1] == 'e' &&
8819 if (name[5] == 'r' &&
8822 return -KEY_getpgrp;
8828 if (name[5] == 'i' &&
8831 return -KEY_getppid;
8844 if (name[1] == 'c' &&
8851 return -KEY_lcfirst;
8857 if (name[1] == 'p' &&
8864 return -KEY_opendir;
8870 if (name[1] == 'a' &&
8888 if (name[3] == 'd' &&
8893 return -KEY_readdir;
8899 if (name[3] == 'u' &&
8910 if (name[3] == 'e' &&
8915 return -KEY_reverse;
8934 if (name[3] == 'k' &&
8939 return -KEY_seekdir;
8945 if (name[3] == 'p' &&
8950 return -KEY_setpgrp;
8960 if (name[2] == 'm' &&
8966 return -KEY_shmread;
8972 if (name[2] == 'r' &&
8978 return -KEY_sprintf;
8987 if (name[3] == 'l' &&
8992 return -KEY_symlink;
9001 if (name[4] == 'a' &&
9005 return -KEY_syscall;
9011 if (name[4] == 'p' &&
9015 return -KEY_sysopen;
9021 if (name[4] == 'e' &&
9025 return -KEY_sysread;
9031 if (name[4] == 'e' &&
9035 return -KEY_sysseek;
9053 if (name[1] == 'e' &&
9060 return -KEY_telldir;
9069 if (name[2] == 'f' &&
9075 return -KEY_ucfirst;
9081 if (name[2] == 's' &&
9087 return -KEY_unshift;
9097 if (name[1] == 'a' &&
9104 return -KEY_waitpid;
9113 case 8: /* 26 tokens of length 8 */
9117 if (name[1] == 'U' &&
9125 return KEY_AUTOLOAD;
9136 if (name[3] == 'A' &&
9142 return KEY___DATA__;
9148 if (name[3] == 'I' &&
9154 return -KEY___FILE__;
9160 if (name[3] == 'I' &&
9166 return -KEY___LINE__;
9182 if (name[2] == 'o' &&
9189 return -KEY_closedir;
9195 if (name[2] == 'n' &&
9202 return -KEY_continue;
9212 if (name[1] == 'b' &&
9220 return -KEY_dbmclose;
9226 if (name[1] == 'n' &&
9232 if (name[4] == 'r' &&
9237 return -KEY_endgrent;
9243 if (name[4] == 'w' &&
9248 return -KEY_endpwent;
9261 if (name[1] == 'o' &&
9269 return -KEY_formline;
9275 if (name[1] == 'e' &&
9286 if (name[6] == 'n' &&
9289 return -KEY_getgrent;
9295 if (name[6] == 'i' &&
9298 return -KEY_getgrgid;
9304 if (name[6] == 'a' &&
9307 return -KEY_getgrnam;
9320 if (name[4] == 'o' &&
9325 return -KEY_getlogin;
9336 if (name[6] == 'n' &&
9339 return -KEY_getpwent;
9345 if (name[6] == 'a' &&
9348 return -KEY_getpwnam;
9354 if (name[6] == 'i' &&
9357 return -KEY_getpwuid;
9377 if (name[1] == 'e' &&
9384 if (name[5] == 'i' &&
9391 return -KEY_readline;
9396 return -KEY_readlink;
9407 if (name[5] == 'i' &&
9411 return -KEY_readpipe;
9432 if (name[4] == 'r' &&
9437 return -KEY_setgrent;
9443 if (name[4] == 'w' &&
9448 return -KEY_setpwent;
9464 if (name[3] == 'w' &&
9470 return -KEY_shmwrite;
9476 if (name[3] == 't' &&
9482 return -KEY_shutdown;
9492 if (name[2] == 's' &&
9499 return -KEY_syswrite;
9509 if (name[1] == 'r' &&
9517 return -KEY_truncate;
9526 case 9: /* 8 tokens of length 9 */
9530 if (name[1] == 'n' &&
9539 return -KEY_endnetent;
9545 if (name[1] == 'e' &&
9554 return -KEY_getnetent;
9560 if (name[1] == 'o' &&
9569 return -KEY_localtime;
9575 if (name[1] == 'r' &&
9584 return KEY_prototype;
9590 if (name[1] == 'u' &&
9599 return -KEY_quotemeta;
9605 if (name[1] == 'e' &&
9614 return -KEY_rewinddir;
9620 if (name[1] == 'e' &&
9629 return -KEY_setnetent;
9635 if (name[1] == 'a' &&
9644 return -KEY_wantarray;
9653 case 10: /* 9 tokens of length 10 */
9657 if (name[1] == 'n' &&
9663 if (name[4] == 'o' &&
9670 return -KEY_endhostent;
9676 if (name[4] == 'e' &&
9683 return -KEY_endservent;
9696 if (name[1] == 'e' &&
9702 if (name[4] == 'o' &&
9709 return -KEY_gethostent;
9718 if (name[5] == 'r' &&
9724 return -KEY_getservent;
9730 if (name[5] == 'c' &&
9736 return -KEY_getsockopt;
9761 if (name[4] == 'o' &&
9768 return -KEY_sethostent;
9777 if (name[5] == 'r' &&
9783 return -KEY_setservent;
9789 if (name[5] == 'c' &&
9795 return -KEY_setsockopt;
9812 if (name[2] == 'c' &&
9821 return -KEY_socketpair;
9834 case 11: /* 8 tokens of length 11 */
9838 if (name[1] == '_' &&
9849 return -KEY___PACKAGE__;
9855 if (name[1] == 'n' &&
9866 return -KEY_endprotoent;
9872 if (name[1] == 'e' &&
9881 if (name[5] == 'e' &&
9888 return -KEY_getpeername;
9897 if (name[6] == 'o' &&
9903 return -KEY_getpriority;
9909 if (name[6] == 't' &&
9915 return -KEY_getprotoent;
9929 if (name[4] == 'o' &&
9937 return -KEY_getsockname;
9950 if (name[1] == 'e' &&
9958 if (name[6] == 'o' &&
9964 return -KEY_setpriority;
9970 if (name[6] == 't' &&
9976 return -KEY_setprotoent;
9992 case 12: /* 2 tokens of length 12 */
9993 if (name[0] == 'g' &&
10005 if (name[9] == 'd' &&
10008 { /* getnetbyaddr */
10009 return -KEY_getnetbyaddr;
10015 if (name[9] == 'a' &&
10018 { /* getnetbyname */
10019 return -KEY_getnetbyname;
10031 case 13: /* 4 tokens of length 13 */
10032 if (name[0] == 'g' &&
10039 if (name[4] == 'o' &&
10048 if (name[10] == 'd' &&
10051 { /* gethostbyaddr */
10052 return -KEY_gethostbyaddr;
10058 if (name[10] == 'a' &&
10061 { /* gethostbyname */
10062 return -KEY_gethostbyname;
10075 if (name[4] == 'e' &&
10084 if (name[10] == 'a' &&
10087 { /* getservbyname */
10088 return -KEY_getservbyname;
10094 if (name[10] == 'o' &&
10097 { /* getservbyport */
10098 return -KEY_getservbyport;
10117 case 14: /* 1 tokens of length 14 */
10118 if (name[0] == 'g' &&
10132 { /* getprotobyname */
10133 return -KEY_getprotobyname;
10138 case 16: /* 1 tokens of length 16 */
10139 if (name[0] == 'g' &&
10155 { /* getprotobynumber */
10156 return -KEY_getprotobynumber;
10170 S_checkcomma(pTHX_ register char *s, const char *name, const char *what)
10175 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10176 if (ckWARN(WARN_SYNTAX)) {
10178 for (w = s+2; *w && level; w++) {
10181 else if (*w == ')')
10185 for (; *w && isSPACE(*w); w++) ;
10186 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
10187 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10188 "%s (...) interpreted as function",name);
10191 while (s < PL_bufend && isSPACE(*s))
10195 while (s < PL_bufend && isSPACE(*s))
10197 if (isIDFIRST_lazy_if(s,UTF)) {
10199 while (isALNUM_lazy_if(s,UTF))
10201 while (s < PL_bufend && isSPACE(*s))
10205 *s = '\0'; /* XXX If we didn't do this, we could const a lot of toke.c */
10206 kw = keyword(w, s - w) || get_cv(w, FALSE) != 0;
10210 Perl_croak(aTHX_ "No comma allowed after %s", what);
10215 /* Either returns sv, or mortalizes sv and returns a new SV*.
10216 Best used as sv=new_constant(..., sv, ...).
10217 If s, pv are NULL, calls subroutine with one argument,
10218 and type is used with error messages only. */
10221 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10225 HV * const table = GvHV(PL_hintgv); /* ^H */
10229 const char *why1 = "", *why2 = "", *why3 = "";
10231 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10234 why2 = strEQ(key,"charnames")
10235 ? "(possibly a missing \"use charnames ...\")"
10237 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10238 (type ? type: "undef"), why2);
10240 /* This is convoluted and evil ("goto considered harmful")
10241 * but I do not understand the intricacies of all the different
10242 * failure modes of %^H in here. The goal here is to make
10243 * the most probable error message user-friendly. --jhi */
10248 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10249 (type ? type: "undef"), why1, why2, why3);
10251 yyerror(SvPVX_const(msg));
10255 cvp = hv_fetch(table, key, strlen(key), FALSE);
10256 if (!cvp || !SvOK(*cvp)) {
10259 why3 = "} is not defined";
10262 sv_2mortal(sv); /* Parent created it permanently */
10265 pv = sv_2mortal(newSVpvn(s, len));
10267 typesv = sv_2mortal(newSVpv(type, 0));
10269 typesv = &PL_sv_undef;
10271 PUSHSTACKi(PERLSI_OVERLOAD);
10283 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10287 /* Check the eval first */
10288 if (!PL_in_eval && SvTRUE(ERRSV)) {
10289 sv_catpvs(ERRSV, "Propagated");
10290 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10292 res = SvREFCNT_inc_simple(sv);
10296 SvREFCNT_inc_simple_void(res);
10305 why1 = "Call to &{$^H{";
10307 why3 = "}} did not return a defined value";
10315 /* Returns a NUL terminated string, with the length of the string written to
10319 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10322 register char *d = dest;
10323 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10326 Perl_croak(aTHX_ ident_too_long);
10327 if (isALNUM(*s)) /* UTF handled below */
10329 else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
10334 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
10338 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10339 char *t = s + UTF8SKIP(s);
10340 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10342 if (d + (t - s) > e)
10343 Perl_croak(aTHX_ ident_too_long);
10344 Copy(s, d, t - s, char);
10357 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10360 char *bracket = NULL;
10362 register char *d = dest;
10363 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10368 while (isDIGIT(*s)) {
10370 Perl_croak(aTHX_ ident_too_long);
10377 Perl_croak(aTHX_ ident_too_long);
10378 if (isALNUM(*s)) /* UTF handled below */
10380 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10385 else if (*s == ':' && s[1] == ':') {
10389 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10390 char *t = s + UTF8SKIP(s);
10391 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10393 if (d + (t - s) > e)
10394 Perl_croak(aTHX_ ident_too_long);
10395 Copy(s, d, t - s, char);
10406 if (PL_lex_state != LEX_NORMAL)
10407 PL_lex_state = LEX_INTERPENDMAYBE;
10410 if (*s == '$' && s[1] &&
10411 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10424 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10429 if (isSPACE(s[-1])) {
10431 const char ch = *s++;
10432 if (!SPACE_OR_TAB(ch)) {
10438 if (isIDFIRST_lazy_if(d,UTF)) {
10442 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10443 end += UTF8SKIP(end);
10444 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10445 end += UTF8SKIP(end);
10447 Copy(s, d, end - s, char);
10452 while ((isALNUM(*s) || *s == ':') && d < e)
10455 Perl_croak(aTHX_ ident_too_long);
10458 while (s < send && SPACE_OR_TAB(*s)) s++;
10459 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10460 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
10461 const char *brack = *s == '[' ? "[...]" : "{...}";
10462 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10463 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10464 funny, dest, brack, funny, dest, brack);
10467 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10471 /* Handle extended ${^Foo} variables
10472 * 1999-02-27 mjd-perl-patch@plover.com */
10473 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10477 while (isALNUM(*s) && d < e) {
10481 Perl_croak(aTHX_ ident_too_long);
10486 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10487 PL_lex_state = LEX_INTERPEND;
10492 if (PL_lex_state == LEX_NORMAL) {
10493 if (ckWARN(WARN_AMBIGUOUS) &&
10494 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
10496 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10497 "Ambiguous use of %c{%s} resolved to %c%s",
10498 funny, dest, funny, dest);
10503 s = bracket; /* let the parser handle it */
10507 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10508 PL_lex_state = LEX_INTERPEND;
10513 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10515 PERL_UNUSED_CONTEXT;
10518 else if (ch == 'g')
10519 *pmfl |= PMf_GLOBAL;
10520 else if (ch == 'c')
10521 *pmfl |= PMf_CONTINUE;
10522 else if (ch == 'o')
10524 else if (ch == 'm')
10525 *pmfl |= PMf_MULTILINE;
10526 else if (ch == 's')
10527 *pmfl |= PMf_SINGLELINE;
10528 else if (ch == 'x')
10529 *pmfl |= PMf_EXTENDED;
10533 S_scan_pat(pTHX_ char *start, I32 type)
10537 char *s = scan_str(start,!!PL_madskills,FALSE);
10538 const char * const valid_flags = (type == OP_QR) ? "iomsx" : "iogcmsx";
10545 const char * const delimiter = skipspace(start);
10546 Perl_croak(aTHX_ *delimiter == '?'
10547 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10548 : "Search pattern not terminated" );
10551 pm = (PMOP*)newPMOP(type, 0);
10552 if (PL_multi_open == '?')
10553 pm->op_pmflags |= PMf_ONCE;
10557 while (*s && strchr(valid_flags, *s))
10558 pmflag(&pm->op_pmflags,*s++);
10560 if (PL_madskills && modstart != s) {
10561 SV* tmptoken = newSVpvn(modstart, s - modstart);
10562 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10565 /* issue a warning if /c is specified,but /g is not */
10566 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10567 && ckWARN(WARN_REGEXP))
10569 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" );
10572 pm->op_pmpermflags = pm->op_pmflags;
10574 PL_lex_op = (OP*)pm;
10575 yylval.ival = OP_MATCH;
10580 S_scan_subst(pTHX_ char *start)
10591 yylval.ival = OP_NULL;
10593 s = scan_str(start,!!PL_madskills,FALSE);
10596 Perl_croak(aTHX_ "Substitution pattern not terminated");
10598 if (s[-1] == PL_multi_open)
10601 if (PL_madskills) {
10602 CURMAD('q', thisopen);
10603 CURMAD('_', thiswhite);
10604 CURMAD('E', thisstuff);
10605 CURMAD('Q', thisclose);
10606 realtokenstart = s - SvPVX(PL_linestr);
10610 first_start = PL_multi_start;
10611 s = scan_str(s,!!PL_madskills,FALSE);
10613 if (PL_lex_stuff) {
10614 SvREFCNT_dec(PL_lex_stuff);
10615 PL_lex_stuff = NULL;
10617 Perl_croak(aTHX_ "Substitution replacement not terminated");
10619 PL_multi_start = first_start; /* so whole substitution is taken together */
10621 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10624 if (PL_madskills) {
10625 CURMAD('z', thisopen);
10626 CURMAD('R', thisstuff);
10627 CURMAD('Z', thisclose);
10637 else if (strchr("iogcmsx", *s))
10638 pmflag(&pm->op_pmflags,*s++);
10644 if (PL_madskills) {
10646 curmad('m', newSVpvn(modstart, s - modstart));
10647 append_madprops(thismad, (OP*)pm, 0);
10651 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10652 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10656 SV * const repl = newSVpvs("");
10658 PL_sublex_info.super_bufptr = s;
10659 PL_sublex_info.super_bufend = PL_bufend;
10661 pm->op_pmflags |= PMf_EVAL;
10663 sv_catpv(repl, es ? "eval " : "do ");
10664 sv_catpvs(repl, "{");
10665 sv_catsv(repl, PL_lex_repl);
10666 sv_catpvs(repl, "}");
10668 SvREFCNT_dec(PL_lex_repl);
10669 PL_lex_repl = repl;
10672 pm->op_pmpermflags = pm->op_pmflags;
10673 PL_lex_op = (OP*)pm;
10674 yylval.ival = OP_SUBST;
10679 S_scan_trans(pTHX_ char *start)
10692 yylval.ival = OP_NULL;
10694 s = scan_str(start,!!PL_madskills,FALSE);
10696 Perl_croak(aTHX_ "Transliteration pattern not terminated");
10698 if (s[-1] == PL_multi_open)
10701 if (PL_madskills) {
10702 CURMAD('q', thisopen);
10703 CURMAD('_', thiswhite);
10704 CURMAD('E', thisstuff);
10705 CURMAD('Q', thisclose);
10706 realtokenstart = s - SvPVX(PL_linestr);
10710 s = scan_str(s,!!PL_madskills,FALSE);
10712 if (PL_lex_stuff) {
10713 SvREFCNT_dec(PL_lex_stuff);
10714 PL_lex_stuff = NULL;
10716 Perl_croak(aTHX_ "Transliteration replacement not terminated");
10718 if (PL_madskills) {
10719 CURMAD('z', thisopen);
10720 CURMAD('R', thisstuff);
10721 CURMAD('Z', thisclose);
10724 complement = del = squash = 0;
10731 complement = OPpTRANS_COMPLEMENT;
10734 del = OPpTRANS_DELETE;
10737 squash = OPpTRANS_SQUASH;
10746 Newx(tbl, complement&&!del?258:256, short);
10747 o = newPVOP(OP_TRANS, 0, (char*)tbl);
10748 o->op_private &= ~OPpTRANS_ALL;
10749 o->op_private |= del|squash|complement|
10750 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
10751 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
10754 yylval.ival = OP_TRANS;
10757 if (PL_madskills) {
10759 curmad('m', newSVpvn(modstart, s - modstart));
10760 append_madprops(thismad, o, 0);
10769 S_scan_heredoc(pTHX_ register char *s)
10773 I32 op_type = OP_SCALAR;
10777 const char *found_newline;
10781 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
10783 I32 stuffstart = s - SvPVX(PL_linestr);
10786 realtokenstart = -1;
10791 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
10794 for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
10795 if (*peek == '`' || *peek == '\'' || *peek =='"') {
10798 s = delimcpy(d, e, s, PL_bufend, term, &len);
10808 if (!isALNUM_lazy_if(s,UTF))
10809 deprecate_old("bare << to mean <<\"\"");
10810 for (; isALNUM_lazy_if(s,UTF); s++) {
10815 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
10816 Perl_croak(aTHX_ "Delimiter for here document is too long");
10819 len = d - PL_tokenbuf;
10822 if (PL_madskills) {
10823 tstart = PL_tokenbuf + !outer;
10824 thisclose = newSVpvn(tstart, len - !outer);
10825 tstart = SvPVX(PL_linestr) + stuffstart;
10826 thisopen = newSVpvn(tstart, s - tstart);
10827 stuffstart = s - SvPVX(PL_linestr);
10830 #ifndef PERL_STRICT_CR
10831 d = strchr(s, '\r');
10833 char * const olds = s;
10835 while (s < PL_bufend) {
10841 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
10850 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
10857 if ( outer || !(found_newline = memchr(s, '\n', PL_bufend - s)) ) {
10858 herewas = newSVpvn(s,PL_bufend-s);
10862 herewas = newSVpvn(s-1,found_newline-s+1);
10865 herewas = newSVpvn(s,found_newline-s);
10869 if (PL_madskills) {
10870 tstart = SvPVX(PL_linestr) + stuffstart;
10872 sv_catpvn(thisstuff, tstart, s - tstart);
10874 thisstuff = newSVpvn(tstart, s - tstart);
10877 s += SvCUR(herewas);
10880 stuffstart = s - SvPVX(PL_linestr);
10886 tmpstr = newSV(79);
10887 sv_upgrade(tmpstr, SVt_PVIV);
10888 if (term == '\'') {
10889 op_type = OP_CONST;
10890 SvIV_set(tmpstr, -1);
10892 else if (term == '`') {
10893 op_type = OP_BACKTICK;
10894 SvIV_set(tmpstr, '\\');
10898 PL_multi_start = CopLINE(PL_curcop);
10899 PL_multi_open = PL_multi_close = '<';
10900 term = *PL_tokenbuf;
10901 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
10902 char * const bufptr = PL_sublex_info.super_bufptr;
10903 char * const bufend = PL_sublex_info.super_bufend;
10904 char * const olds = s - SvCUR(herewas);
10905 s = strchr(bufptr, '\n');
10909 while (s < bufend &&
10910 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
10912 CopLINE_inc(PL_curcop);
10915 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10916 missingterm(PL_tokenbuf);
10918 sv_setpvn(herewas,bufptr,d-bufptr+1);
10919 sv_setpvn(tmpstr,d+1,s-d);
10921 sv_catpvn(herewas,s,bufend-s);
10922 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
10929 while (s < PL_bufend &&
10930 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
10932 CopLINE_inc(PL_curcop);
10934 if (s >= PL_bufend) {
10935 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10936 missingterm(PL_tokenbuf);
10938 sv_setpvn(tmpstr,d+1,s-d);
10940 if (PL_madskills) {
10942 sv_catpvn(thisstuff, d + 1, s - d);
10944 thisstuff = newSVpvn(d + 1, s - d);
10945 stuffstart = s - SvPVX(PL_linestr);
10949 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
10951 sv_catpvn(herewas,s,PL_bufend-s);
10952 sv_setsv(PL_linestr,herewas);
10953 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
10954 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10955 PL_last_lop = PL_last_uni = NULL;
10958 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
10959 while (s >= PL_bufend) { /* multiple line string? */
10961 if (PL_madskills) {
10962 tstart = SvPVX(PL_linestr) + stuffstart;
10964 sv_catpvn(thisstuff, tstart, PL_bufend - tstart);
10966 thisstuff = newSVpvn(tstart, PL_bufend - tstart);
10970 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
10971 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10972 missingterm(PL_tokenbuf);
10975 stuffstart = s - SvPVX(PL_linestr);
10977 CopLINE_inc(PL_curcop);
10978 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10979 PL_last_lop = PL_last_uni = NULL;
10980 #ifndef PERL_STRICT_CR
10981 if (PL_bufend - PL_linestart >= 2) {
10982 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
10983 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
10985 PL_bufend[-2] = '\n';
10987 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
10989 else if (PL_bufend[-1] == '\r')
10990 PL_bufend[-1] = '\n';
10992 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
10993 PL_bufend[-1] = '\n';
10995 if (PERLDB_LINE && PL_curstash != PL_debstash) {
10996 SV * const sv = newSV(0);
10998 sv_upgrade(sv, SVt_PVMG);
10999 sv_setsv(sv,PL_linestr);
11000 (void)SvIOK_on(sv);
11002 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop),sv);
11004 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11005 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11006 *(SvPVX(PL_linestr) + off ) = ' ';
11007 sv_catsv(PL_linestr,herewas);
11008 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11009 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11013 sv_catsv(tmpstr,PL_linestr);
11018 PL_multi_end = CopLINE(PL_curcop);
11019 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11020 SvPV_shrink_to_cur(tmpstr);
11022 SvREFCNT_dec(herewas);
11024 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11026 else if (PL_encoding)
11027 sv_recode_to_utf8(tmpstr, PL_encoding);
11029 PL_lex_stuff = tmpstr;
11030 yylval.ival = op_type;
11034 /* scan_inputsymbol
11035 takes: current position in input buffer
11036 returns: new position in input buffer
11037 side-effects: yylval and lex_op are set.
11042 <FH> read from filehandle
11043 <pkg::FH> read from package qualified filehandle
11044 <pkg'FH> read from package qualified filehandle
11045 <$fh> read from filehandle in $fh
11046 <*.h> filename glob
11051 S_scan_inputsymbol(pTHX_ char *start)
11054 register char *s = start; /* current position in buffer */
11058 char *d = PL_tokenbuf; /* start of temp holding space */
11059 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11061 end = strchr(s, '\n');
11064 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11066 /* die if we didn't have space for the contents of the <>,
11067 or if it didn't end, or if we see a newline
11070 if (len >= sizeof PL_tokenbuf)
11071 Perl_croak(aTHX_ "Excessively long <> operator");
11073 Perl_croak(aTHX_ "Unterminated <> operator");
11078 Remember, only scalar variables are interpreted as filehandles by
11079 this code. Anything more complex (e.g., <$fh{$num}>) will be
11080 treated as a glob() call.
11081 This code makes use of the fact that except for the $ at the front,
11082 a scalar variable and a filehandle look the same.
11084 if (*d == '$' && d[1]) d++;
11086 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11087 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11090 /* If we've tried to read what we allow filehandles to look like, and
11091 there's still text left, then it must be a glob() and not a getline.
11092 Use scan_str to pull out the stuff between the <> and treat it
11093 as nothing more than a string.
11096 if (d - PL_tokenbuf != len) {
11097 yylval.ival = OP_GLOB;
11099 s = scan_str(start,!!PL_madskills,FALSE);
11101 Perl_croak(aTHX_ "Glob not terminated");
11105 bool readline_overriden = FALSE;
11108 /* we're in a filehandle read situation */
11111 /* turn <> into <ARGV> */
11113 Copy("ARGV",d,5,char);
11115 /* Check whether readline() is overriden */
11116 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11118 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11120 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11121 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
11122 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11123 readline_overriden = TRUE;
11125 /* if <$fh>, create the ops to turn the variable into a
11131 /* try to find it in the pad for this block, otherwise find
11132 add symbol table ops
11134 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
11135 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11136 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11137 HEK * const stashname = HvNAME_HEK(stash);
11138 SV * const sym = sv_2mortal(newSVhek(stashname));
11139 sv_catpvs(sym, "::");
11140 sv_catpv(sym, d+1);
11145 OP * const o = newOP(OP_PADSV, 0);
11147 PL_lex_op = readline_overriden
11148 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11149 append_elem(OP_LIST, o,
11150 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11151 : (OP*)newUNOP(OP_READLINE, 0, o);
11160 ? (GV_ADDMULTI | GV_ADDINEVAL)
11163 PL_lex_op = readline_overriden
11164 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11165 append_elem(OP_LIST,
11166 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11167 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11168 : (OP*)newUNOP(OP_READLINE, 0,
11169 newUNOP(OP_RV2SV, 0,
11170 newGVOP(OP_GV, 0, gv)));
11172 if (!readline_overriden)
11173 PL_lex_op->op_flags |= OPf_SPECIAL;
11174 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11175 yylval.ival = OP_NULL;
11178 /* If it's none of the above, it must be a literal filehandle
11179 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11181 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11182 PL_lex_op = readline_overriden
11183 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11184 append_elem(OP_LIST,
11185 newGVOP(OP_GV, 0, gv),
11186 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11187 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11188 yylval.ival = OP_NULL;
11197 takes: start position in buffer
11198 keep_quoted preserve \ on the embedded delimiter(s)
11199 keep_delims preserve the delimiters around the string
11200 returns: position to continue reading from buffer
11201 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11202 updates the read buffer.
11204 This subroutine pulls a string out of the input. It is called for:
11205 q single quotes q(literal text)
11206 ' single quotes 'literal text'
11207 qq double quotes qq(interpolate $here please)
11208 " double quotes "interpolate $here please"
11209 qx backticks qx(/bin/ls -l)
11210 ` backticks `/bin/ls -l`
11211 qw quote words @EXPORT_OK = qw( func() $spam )
11212 m// regexp match m/this/
11213 s/// regexp substitute s/this/that/
11214 tr/// string transliterate tr/this/that/
11215 y/// string transliterate y/this/that/
11216 ($*@) sub prototypes sub foo ($)
11217 (stuff) sub attr parameters sub foo : attr(stuff)
11218 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11220 In most of these cases (all but <>, patterns and transliterate)
11221 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11222 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11223 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11226 It skips whitespace before the string starts, and treats the first
11227 character as the delimiter. If the delimiter is one of ([{< then
11228 the corresponding "close" character )]}> is used as the closing
11229 delimiter. It allows quoting of delimiters, and if the string has
11230 balanced delimiters ([{<>}]) it allows nesting.
11232 On success, the SV with the resulting string is put into lex_stuff or,
11233 if that is already non-NULL, into lex_repl. The second case occurs only
11234 when parsing the RHS of the special constructs s/// and tr/// (y///).
11235 For convenience, the terminating delimiter character is stuffed into
11240 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11243 SV *sv; /* scalar value: string */
11244 char *tmps; /* temp string, used for delimiter matching */
11245 register char *s = start; /* current position in the buffer */
11246 register char term; /* terminating character */
11247 register char *to; /* current position in the sv's data */
11248 I32 brackets = 1; /* bracket nesting level */
11249 bool has_utf8 = FALSE; /* is there any utf8 content? */
11250 I32 termcode; /* terminating char. code */
11251 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11252 STRLEN termlen; /* length of terminating string */
11253 char *last = NULL; /* last position for nesting bracket */
11259 /* skip space before the delimiter */
11265 if (realtokenstart >= 0) {
11266 stuffstart = realtokenstart;
11267 realtokenstart = -1;
11270 stuffstart = start - SvPVX(PL_linestr);
11272 /* mark where we are, in case we need to report errors */
11275 /* after skipping whitespace, the next character is the terminator */
11278 termcode = termstr[0] = term;
11282 termcode = utf8_to_uvchr((U8*)s, &termlen);
11283 Copy(s, termstr, termlen, U8);
11284 if (!UTF8_IS_INVARIANT(term))
11288 /* mark where we are */
11289 PL_multi_start = CopLINE(PL_curcop);
11290 PL_multi_open = term;
11292 /* find corresponding closing delimiter */
11293 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11294 termcode = termstr[0] = term = tmps[5];
11296 PL_multi_close = term;
11298 /* create a new SV to hold the contents. 79 is the SV's initial length.
11299 What a random number. */
11301 sv_upgrade(sv, SVt_PVIV);
11302 SvIV_set(sv, termcode);
11303 (void)SvPOK_only(sv); /* validate pointer */
11305 /* move past delimiter and try to read a complete string */
11307 sv_catpvn(sv, s, termlen);
11310 tstart = SvPVX(PL_linestr) + stuffstart;
11311 if (!thisopen && !keep_delims) {
11312 thisopen = newSVpvn(tstart, s - tstart);
11313 stuffstart = s - SvPVX(PL_linestr);
11317 if (PL_encoding && !UTF) {
11321 int offset = s - SvPVX_const(PL_linestr);
11322 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11323 &offset, (char*)termstr, termlen);
11324 const char * const ns = SvPVX_const(PL_linestr) + offset;
11325 char * const svlast = SvEND(sv) - 1;
11327 for (; s < ns; s++) {
11328 if (*s == '\n' && !PL_rsfp)
11329 CopLINE_inc(PL_curcop);
11332 goto read_more_line;
11334 /* handle quoted delimiters */
11335 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11337 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11339 if ((svlast-1 - t) % 2) {
11340 if (!keep_quoted) {
11341 *(svlast-1) = term;
11343 SvCUR_set(sv, SvCUR(sv) - 1);
11348 if (PL_multi_open == PL_multi_close) {
11356 for (t = w = last; t < svlast; w++, t++) {
11357 /* At here, all closes are "was quoted" one,
11358 so we don't check PL_multi_close. */
11360 if (!keep_quoted && *(t+1) == PL_multi_open)
11365 else if (*t == PL_multi_open)
11373 SvCUR_set(sv, w - SvPVX_const(sv));
11376 if (--brackets <= 0)
11381 if (!keep_delims) {
11382 SvCUR_set(sv, SvCUR(sv) - 1);
11388 /* extend sv if need be */
11389 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11390 /* set 'to' to the next character in the sv's string */
11391 to = SvPVX(sv)+SvCUR(sv);
11393 /* if open delimiter is the close delimiter read unbridle */
11394 if (PL_multi_open == PL_multi_close) {
11395 for (; s < PL_bufend; s++,to++) {
11396 /* embedded newlines increment the current line number */
11397 if (*s == '\n' && !PL_rsfp)
11398 CopLINE_inc(PL_curcop);
11399 /* handle quoted delimiters */
11400 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11401 if (!keep_quoted && s[1] == term)
11403 /* any other quotes are simply copied straight through */
11407 /* terminate when run out of buffer (the for() condition), or
11408 have found the terminator */
11409 else if (*s == term) {
11412 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11415 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11421 /* if the terminator isn't the same as the start character (e.g.,
11422 matched brackets), we have to allow more in the quoting, and
11423 be prepared for nested brackets.
11426 /* read until we run out of string, or we find the terminator */
11427 for (; s < PL_bufend; s++,to++) {
11428 /* embedded newlines increment the line count */
11429 if (*s == '\n' && !PL_rsfp)
11430 CopLINE_inc(PL_curcop);
11431 /* backslashes can escape the open or closing characters */
11432 if (*s == '\\' && s+1 < PL_bufend) {
11433 if (!keep_quoted &&
11434 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11439 /* allow nested opens and closes */
11440 else if (*s == PL_multi_close && --brackets <= 0)
11442 else if (*s == PL_multi_open)
11444 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11449 /* terminate the copied string and update the sv's end-of-string */
11451 SvCUR_set(sv, to - SvPVX_const(sv));
11454 * this next chunk reads more into the buffer if we're not done yet
11458 break; /* handle case where we are done yet :-) */
11460 #ifndef PERL_STRICT_CR
11461 if (to - SvPVX_const(sv) >= 2) {
11462 if ((to[-2] == '\r' && to[-1] == '\n') ||
11463 (to[-2] == '\n' && to[-1] == '\r'))
11467 SvCUR_set(sv, to - SvPVX_const(sv));
11469 else if (to[-1] == '\r')
11472 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11477 /* if we're out of file, or a read fails, bail and reset the current
11478 line marker so we can report where the unterminated string began
11481 if (PL_madskills) {
11482 char *tstart = SvPVX(PL_linestr) + stuffstart;
11484 sv_catpvn(thisstuff, tstart, PL_bufend - tstart);
11486 thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11490 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11492 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11498 /* we read a line, so increment our line counter */
11499 CopLINE_inc(PL_curcop);
11501 /* update debugger info */
11502 if (PERLDB_LINE && PL_curstash != PL_debstash) {
11503 SV * const line_sv = newSV(0);
11505 sv_upgrade(line_sv, SVt_PVMG);
11506 sv_setsv(line_sv,PL_linestr);
11507 (void)SvIOK_on(line_sv);
11508 SvIV_set(line_sv, 0);
11509 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop), line_sv);
11512 /* having changed the buffer, we must update PL_bufend */
11513 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11514 PL_last_lop = PL_last_uni = NULL;
11517 /* at this point, we have successfully read the delimited string */
11519 if (!PL_encoding || UTF) {
11521 if (PL_madskills) {
11522 char *tstart = SvPVX(PL_linestr) + stuffstart;
11524 sv_catpvn(thisstuff, tstart, s - tstart);
11526 thisstuff = newSVpvn(tstart, s - tstart);
11527 if (!thisclose && !keep_delims)
11528 thisclose = newSVpvn(s,termlen);
11533 sv_catpvn(sv, s, termlen);
11538 if (PL_madskills) {
11539 char *tstart = SvPVX(PL_linestr) + stuffstart;
11541 sv_catpvn(thisstuff, tstart, s - tstart - termlen);
11543 thisstuff = newSVpvn(tstart, s - tstart - termlen);
11544 if (!thisclose && !keep_delims)
11545 thisclose = newSVpvn(s - termlen,termlen);
11549 if (has_utf8 || PL_encoding)
11552 PL_multi_end = CopLINE(PL_curcop);
11554 /* if we allocated too much space, give some back */
11555 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11556 SvLEN_set(sv, SvCUR(sv) + 1);
11557 SvPV_renew(sv, SvLEN(sv));
11560 /* decide whether this is the first or second quoted string we've read
11573 takes: pointer to position in buffer
11574 returns: pointer to new position in buffer
11575 side-effects: builds ops for the constant in yylval.op
11577 Read a number in any of the formats that Perl accepts:
11579 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11580 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11583 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11585 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11588 If it reads a number without a decimal point or an exponent, it will
11589 try converting the number to an integer and see if it can do so
11590 without loss of precision.
11594 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11597 register const char *s = start; /* current position in buffer */
11598 register char *d; /* destination in temp buffer */
11599 register char *e; /* end of temp buffer */
11600 NV nv; /* number read, as a double */
11601 SV *sv = NULL; /* place to put the converted number */
11602 bool floatit; /* boolean: int or float? */
11603 const char *lastub = NULL; /* position of last underbar */
11604 static char const number_too_long[] = "Number too long";
11606 /* We use the first character to decide what type of number this is */
11610 Perl_croak(aTHX_ "panic: scan_num");
11612 /* if it starts with a 0, it could be an octal number, a decimal in
11613 0.13 disguise, or a hexadecimal number, or a binary number. */
11617 u holds the "number so far"
11618 shift the power of 2 of the base
11619 (hex == 4, octal == 3, binary == 1)
11620 overflowed was the number more than we can hold?
11622 Shift is used when we add a digit. It also serves as an "are
11623 we in octal/hex/binary?" indicator to disallow hex characters
11624 when in octal mode.
11629 bool overflowed = FALSE;
11630 bool just_zero = TRUE; /* just plain 0 or binary number? */
11631 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11632 static const char* const bases[5] =
11633 { "", "binary", "", "octal", "hexadecimal" };
11634 static const char* const Bases[5] =
11635 { "", "Binary", "", "Octal", "Hexadecimal" };
11636 static const char* const maxima[5] =
11638 "0b11111111111111111111111111111111",
11642 const char *base, *Base, *max;
11644 /* check for hex */
11649 } else if (s[1] == 'b') {
11654 /* check for a decimal in disguise */
11655 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11657 /* so it must be octal */
11664 if (ckWARN(WARN_SYNTAX))
11665 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11666 "Misplaced _ in number");
11670 base = bases[shift];
11671 Base = Bases[shift];
11672 max = maxima[shift];
11674 /* read the rest of the number */
11676 /* x is used in the overflow test,
11677 b is the digit we're adding on. */
11682 /* if we don't mention it, we're done */
11686 /* _ are ignored -- but warned about if consecutive */
11688 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11689 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11690 "Misplaced _ in number");
11694 /* 8 and 9 are not octal */
11695 case '8': case '9':
11697 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11701 case '2': case '3': case '4':
11702 case '5': case '6': case '7':
11704 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11707 case '0': case '1':
11708 b = *s++ & 15; /* ASCII digit -> value of digit */
11712 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11713 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
11714 /* make sure they said 0x */
11717 b = (*s++ & 7) + 9;
11719 /* Prepare to put the digit we have onto the end
11720 of the number so far. We check for overflows.
11726 x = u << shift; /* make room for the digit */
11728 if ((x >> shift) != u
11729 && !(PL_hints & HINT_NEW_BINARY)) {
11732 if (ckWARN_d(WARN_OVERFLOW))
11733 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11734 "Integer overflow in %s number",
11737 u = x | b; /* add the digit to the end */
11740 n *= nvshift[shift];
11741 /* If an NV has not enough bits in its
11742 * mantissa to represent an UV this summing of
11743 * small low-order numbers is a waste of time
11744 * (because the NV cannot preserve the
11745 * low-order bits anyway): we could just
11746 * remember when did we overflow and in the
11747 * end just multiply n by the right
11755 /* if we get here, we had success: make a scalar value from
11760 /* final misplaced underbar check */
11761 if (s[-1] == '_') {
11762 if (ckWARN(WARN_SYNTAX))
11763 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11768 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
11769 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11770 "%s number > %s non-portable",
11776 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
11777 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11778 "%s number > %s non-portable",
11783 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
11784 sv = new_constant(start, s - start, "integer",
11786 else if (PL_hints & HINT_NEW_BINARY)
11787 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
11792 handle decimal numbers.
11793 we're also sent here when we read a 0 as the first digit
11795 case '1': case '2': case '3': case '4': case '5':
11796 case '6': case '7': case '8': case '9': case '.':
11799 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
11802 /* read next group of digits and _ and copy into d */
11803 while (isDIGIT(*s) || *s == '_') {
11804 /* skip underscores, checking for misplaced ones
11808 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11809 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11810 "Misplaced _ in number");
11814 /* check for end of fixed-length buffer */
11816 Perl_croak(aTHX_ number_too_long);
11817 /* if we're ok, copy the character */
11822 /* final misplaced underbar check */
11823 if (lastub && s == lastub + 1) {
11824 if (ckWARN(WARN_SYNTAX))
11825 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11828 /* read a decimal portion if there is one. avoid
11829 3..5 being interpreted as the number 3. followed
11832 if (*s == '.' && s[1] != '.') {
11837 if (ckWARN(WARN_SYNTAX))
11838 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11839 "Misplaced _ in number");
11843 /* copy, ignoring underbars, until we run out of digits.
11845 for (; isDIGIT(*s) || *s == '_'; s++) {
11846 /* fixed length buffer check */
11848 Perl_croak(aTHX_ number_too_long);
11850 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11851 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11852 "Misplaced _ in number");
11858 /* fractional part ending in underbar? */
11859 if (s[-1] == '_') {
11860 if (ckWARN(WARN_SYNTAX))
11861 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11862 "Misplaced _ in number");
11864 if (*s == '.' && isDIGIT(s[1])) {
11865 /* oops, it's really a v-string, but without the "v" */
11871 /* read exponent part, if present */
11872 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
11876 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
11877 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
11879 /* stray preinitial _ */
11881 if (ckWARN(WARN_SYNTAX))
11882 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11883 "Misplaced _ in number");
11887 /* allow positive or negative exponent */
11888 if (*s == '+' || *s == '-')
11891 /* stray initial _ */
11893 if (ckWARN(WARN_SYNTAX))
11894 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11895 "Misplaced _ in number");
11899 /* read digits of exponent */
11900 while (isDIGIT(*s) || *s == '_') {
11903 Perl_croak(aTHX_ number_too_long);
11907 if (((lastub && s == lastub + 1) ||
11908 (!isDIGIT(s[1]) && s[1] != '_'))
11909 && ckWARN(WARN_SYNTAX))
11910 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11911 "Misplaced _ in number");
11918 /* make an sv from the string */
11922 We try to do an integer conversion first if no characters
11923 indicating "float" have been found.
11928 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
11930 if (flags == IS_NUMBER_IN_UV) {
11932 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
11935 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
11936 if (uv <= (UV) IV_MIN)
11937 sv_setiv(sv, -(IV)uv);
11944 /* terminate the string */
11946 nv = Atof(PL_tokenbuf);
11950 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
11951 (PL_hints & HINT_NEW_INTEGER) )
11952 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
11953 (floatit ? "float" : "integer"),
11957 /* if it starts with a v, it could be a v-string */
11960 sv = newSV(5); /* preallocate storage space */
11961 s = scan_vstring(s,sv);
11965 /* make the op for the constant and return */
11968 lvalp->opval = newSVOP(OP_CONST, 0, sv);
11970 lvalp->opval = NULL;
11976 S_scan_formline(pTHX_ register char *s)
11979 register char *eol;
11981 SV * const stuff = newSVpvs("");
11982 bool needargs = FALSE;
11983 bool eofmt = FALSE;
11985 char *tokenstart = s;
11988 if (PL_madskills) {
11989 savewhite = thiswhite;
11994 while (!needargs) {
11996 #ifdef PERL_STRICT_CR
11997 for (t = s+1;SPACE_OR_TAB(*t); t++) ;
11999 for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
12001 if (*t == '\n' || t == PL_bufend) {
12006 if (PL_in_eval && !PL_rsfp) {
12007 eol = (char *) memchr(s,'\n',PL_bufend-s);
12012 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12014 for (t = s; t < eol; t++) {
12015 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12017 goto enough; /* ~~ must be first line in formline */
12019 if (*t == '@' || *t == '^')
12023 sv_catpvn(stuff, s, eol-s);
12024 #ifndef PERL_STRICT_CR
12025 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12026 char *end = SvPVX(stuff) + SvCUR(stuff);
12029 SvCUR_set(stuff, SvCUR(stuff) - 1);
12039 if (PL_madskills) {
12041 sv_catpvn(thistoken, tokenstart, PL_bufend - tokenstart);
12043 thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12046 s = filter_gets(PL_linestr, PL_rsfp, 0);
12048 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12050 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12052 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12053 PL_last_lop = PL_last_uni = NULL;
12062 if (SvCUR(stuff)) {
12065 PL_lex_state = LEX_NORMAL;
12066 start_force(curforce);
12067 NEXTVAL_NEXTTOKE.ival = 0;
12071 PL_lex_state = LEX_FORMLINE;
12073 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12075 else if (PL_encoding)
12076 sv_recode_to_utf8(stuff, PL_encoding);
12078 start_force(curforce);
12079 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12081 start_force(curforce);
12082 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12086 SvREFCNT_dec(stuff);
12088 PL_lex_formbrack = 0;
12092 if (PL_madskills) {
12094 sv_catpvn(thistoken, tokenstart, s - tokenstart);
12096 thistoken = newSVpvn(tokenstart, s - tokenstart);
12097 thiswhite = savewhite;
12109 PL_cshlen = strlen(PL_cshname);
12111 #if defined(USE_ITHREADS)
12112 PERL_UNUSED_CONTEXT;
12118 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12121 const I32 oldsavestack_ix = PL_savestack_ix;
12122 CV* const outsidecv = PL_compcv;
12125 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12127 SAVEI32(PL_subline);
12128 save_item(PL_subname);
12129 SAVESPTR(PL_compcv);
12131 PL_compcv = (CV*)newSV(0);
12132 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
12133 CvFLAGS(PL_compcv) |= flags;
12135 PL_subline = CopLINE(PL_curcop);
12136 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12137 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12138 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12140 return oldsavestack_ix;
12144 #pragma segment Perl_yylex
12147 Perl_yywarn(pTHX_ const char *s)
12150 PL_in_eval |= EVAL_WARNONLY;
12152 PL_in_eval &= ~EVAL_WARNONLY;
12157 Perl_yyerror(pTHX_ const char *s)
12160 const char *where = NULL;
12161 const char *context = NULL;
12165 if (!yychar || (yychar == ';' && !PL_rsfp))
12167 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12168 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12169 PL_oldbufptr != PL_bufptr) {
12172 The code below is removed for NetWare because it abends/crashes on NetWare
12173 when the script has error such as not having the closing quotes like:
12174 if ($var eq "value)
12175 Checking of white spaces is anyway done in NetWare code.
12178 while (isSPACE(*PL_oldoldbufptr))
12181 context = PL_oldoldbufptr;
12182 contlen = PL_bufptr - PL_oldoldbufptr;
12184 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12185 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12188 The code below is removed for NetWare because it abends/crashes on NetWare
12189 when the script has error such as not having the closing quotes like:
12190 if ($var eq "value)
12191 Checking of white spaces is anyway done in NetWare code.
12194 while (isSPACE(*PL_oldbufptr))
12197 context = PL_oldbufptr;
12198 contlen = PL_bufptr - PL_oldbufptr;
12200 else if (yychar > 255)
12201 where = "next token ???";
12202 else if (yychar == -2) { /* YYEMPTY */
12203 if (PL_lex_state == LEX_NORMAL ||
12204 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12205 where = "at end of line";
12206 else if (PL_lex_inpat)
12207 where = "within pattern";
12209 where = "within string";
12212 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12214 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12215 else if (isPRINT_LC(yychar))
12216 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12218 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12219 where = SvPVX_const(where_sv);
12221 msg = sv_2mortal(newSVpv(s, 0));
12222 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12223 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12225 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12227 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12228 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12229 Perl_sv_catpvf(aTHX_ msg,
12230 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12231 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12234 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12235 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg);
12238 if (PL_error_count >= 10) {
12239 if (PL_in_eval && SvCUR(ERRSV))
12240 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12241 ERRSV, OutCopFILE(PL_curcop));
12243 Perl_croak(aTHX_ "%s has too many errors.\n",
12244 OutCopFILE(PL_curcop));
12247 PL_in_my_stash = NULL;
12251 #pragma segment Main
12255 S_swallow_bom(pTHX_ U8 *s)
12258 const STRLEN slen = SvCUR(PL_linestr);
12261 if (s[1] == 0xFE) {
12262 /* UTF-16 little-endian? (or UTF32-LE?) */
12263 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12264 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12265 #ifndef PERL_NO_UTF16_FILTER
12266 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12269 if (PL_bufend > (char*)s) {
12273 filter_add(utf16rev_textfilter, NULL);
12274 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12275 utf16_to_utf8_reversed(s, news,
12276 PL_bufend - (char*)s - 1,
12278 sv_setpvn(PL_linestr, (const char*)news, newlen);
12280 s = (U8*)SvPVX(PL_linestr);
12281 Copy(news, s, newlen, U8);
12285 SvUTF8_on(PL_linestr);
12286 s = (U8*)SvPVX(PL_linestr);
12288 /* FIXME - is this a general bug fix? */
12291 PL_bufend = SvPVX(PL_linestr) + newlen;
12294 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12299 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12300 #ifndef PERL_NO_UTF16_FILTER
12301 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12304 if (PL_bufend > (char *)s) {
12308 filter_add(utf16_textfilter, NULL);
12309 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12310 utf16_to_utf8(s, news,
12311 PL_bufend - (char*)s,
12313 sv_setpvn(PL_linestr, (const char*)news, newlen);
12315 SvUTF8_on(PL_linestr);
12316 s = (U8*)SvPVX(PL_linestr);
12317 PL_bufend = SvPVX(PL_linestr) + newlen;
12320 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12325 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12326 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12327 s += 3; /* UTF-8 */
12333 if (s[2] == 0xFE && s[3] == 0xFF) {
12334 /* UTF-32 big-endian */
12335 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12338 else if (s[2] == 0 && s[3] != 0) {
12341 * are a good indicator of UTF-16BE. */
12342 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12347 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12350 * are a good indicator of UTF-16LE. */
12351 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12360 * Restore a source filter.
12364 restore_rsfp(pTHX_ void *f)
12367 PerlIO * const fp = (PerlIO*)f;
12369 if (PL_rsfp == PerlIO_stdin())
12370 PerlIO_clearerr(PL_rsfp);
12371 else if (PL_rsfp && (PL_rsfp != fp))
12372 PerlIO_close(PL_rsfp);
12376 #ifndef PERL_NO_UTF16_FILTER
12378 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12381 const STRLEN old = SvCUR(sv);
12382 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12383 DEBUG_P(PerlIO_printf(Perl_debug_log,
12384 "utf16_textfilter(%p): %d %d (%d)\n",
12385 utf16_textfilter, idx, maxlen, (int) count));
12389 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12390 Copy(SvPVX_const(sv), tmps, old, char);
12391 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12392 SvCUR(sv) - old, &newlen);
12393 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12395 DEBUG_P({sv_dump(sv);});
12400 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12403 const STRLEN old = SvCUR(sv);
12404 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12405 DEBUG_P(PerlIO_printf(Perl_debug_log,
12406 "utf16rev_textfilter(%p): %d %d (%d)\n",
12407 utf16rev_textfilter, idx, maxlen, (int) count));
12411 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12412 Copy(SvPVX_const(sv), tmps, old, char);
12413 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12414 SvCUR(sv) - old, &newlen);
12415 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12417 DEBUG_P({ sv_dump(sv); });
12423 Returns a pointer to the next character after the parsed
12424 vstring, as well as updating the passed in sv.
12426 Function must be called like
12429 s = scan_vstring(s,sv);
12431 The sv should already be large enough to store the vstring
12432 passed in, for performance reasons.
12437 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
12440 const char *pos = s;
12441 const char *start = s;
12442 if (*pos == 'v') pos++; /* get past 'v' */
12443 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12445 if ( *pos != '.') {
12446 /* this may not be a v-string if followed by => */
12447 const char *next = pos;
12448 while (next < PL_bufend && isSPACE(*next))
12450 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
12451 /* return string not v-string */
12452 sv_setpvn(sv,(char *)s,pos-s);
12453 return (char *)pos;
12457 if (!isALPHA(*pos)) {
12458 U8 tmpbuf[UTF8_MAXBYTES+1];
12460 if (*s == 'v') s++; /* get past 'v' */
12462 sv_setpvn(sv, "", 0);
12468 /* this is atoi() that tolerates underscores */
12469 const char *end = pos;
12471 while (--end >= s) {
12476 rev += (*end - '0') * mult;
12478 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12479 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12480 "Integer overflow in decimal number");
12484 if (rev > 0x7FFFFFFF)
12485 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12487 /* Append native character for the rev point */
12488 tmpend = uvchr_to_utf8(tmpbuf, rev);
12489 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12490 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12492 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
12498 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12502 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12510 * c-indentation-style: bsd
12511 * c-basic-offset: 4
12512 * indent-tabs-mode: t
12515 * ex: set ts=8 sts=4 sw=4 noet: