3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 * 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 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
14 * [p.719 of _The Lord of the Rings_, IV/ix: "Shelob's Lair"]
18 * This file is the lexer for Perl. It's closely linked to the
21 * The main routine is yylex(), which returns the next token.
25 =head1 Lexer interface
26 This is the lower layer of the Perl parser, managing characters and tokens.
28 =for apidoc AmU|yy_parser *|PL_parser
30 Pointer to a structure encapsulating the state of the parsing operation
31 currently in progress. The pointer can be locally changed to perform
32 a nested parse without interfering with the state of an outer parse.
33 Individual members of C<PL_parser> have their own documentation.
39 #define PERL_IN_TOKE_C
41 #include "dquote_static.c"
43 #define new_constant(a,b,c,d,e,f,g) \
44 S_new_constant(aTHX_ a,b,STR_WITH_LEN(c),d,e,f, g)
46 #define pl_yylval (PL_parser->yylval)
48 /* XXX temporary backwards compatibility */
49 #define PL_lex_brackets (PL_parser->lex_brackets)
50 #define PL_lex_allbrackets (PL_parser->lex_allbrackets)
51 #define PL_lex_fakeeof (PL_parser->lex_fakeeof)
52 #define PL_lex_brackstack (PL_parser->lex_brackstack)
53 #define PL_lex_casemods (PL_parser->lex_casemods)
54 #define PL_lex_casestack (PL_parser->lex_casestack)
55 #define PL_lex_defer (PL_parser->lex_defer)
56 #define PL_lex_dojoin (PL_parser->lex_dojoin)
57 #define PL_lex_expect (PL_parser->lex_expect)
58 #define PL_lex_formbrack (PL_parser->lex_formbrack)
59 #define PL_lex_inpat (PL_parser->lex_inpat)
60 #define PL_lex_inwhat (PL_parser->lex_inwhat)
61 #define PL_lex_op (PL_parser->lex_op)
62 #define PL_lex_repl (PL_parser->lex_repl)
63 #define PL_lex_starts (PL_parser->lex_starts)
64 #define PL_lex_stuff (PL_parser->lex_stuff)
65 #define PL_multi_start (PL_parser->multi_start)
66 #define PL_multi_open (PL_parser->multi_open)
67 #define PL_multi_close (PL_parser->multi_close)
68 #define PL_preambled (PL_parser->preambled)
69 #define PL_sublex_info (PL_parser->sublex_info)
70 #define PL_linestr (PL_parser->linestr)
71 #define PL_expect (PL_parser->expect)
72 #define PL_copline (PL_parser->copline)
73 #define PL_bufptr (PL_parser->bufptr)
74 #define PL_oldbufptr (PL_parser->oldbufptr)
75 #define PL_oldoldbufptr (PL_parser->oldoldbufptr)
76 #define PL_linestart (PL_parser->linestart)
77 #define PL_bufend (PL_parser->bufend)
78 #define PL_last_uni (PL_parser->last_uni)
79 #define PL_last_lop (PL_parser->last_lop)
80 #define PL_last_lop_op (PL_parser->last_lop_op)
81 #define PL_lex_state (PL_parser->lex_state)
82 #define PL_rsfp (PL_parser->rsfp)
83 #define PL_rsfp_filters (PL_parser->rsfp_filters)
84 #define PL_in_my (PL_parser->in_my)
85 #define PL_in_my_stash (PL_parser->in_my_stash)
86 #define PL_tokenbuf (PL_parser->tokenbuf)
87 #define PL_multi_end (PL_parser->multi_end)
88 #define PL_error_count (PL_parser->error_count)
90 # define PL_nexttoke (PL_parser->nexttoke)
91 # define PL_nexttype (PL_parser->nexttype)
92 # define PL_nextval (PL_parser->nextval)
94 static const char* const ident_too_long = "Identifier too long";
96 # define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
98 #define XENUMMASK 0x3f
100 #define XFAKEBRACK 0x80
102 #ifdef USE_UTF8_SCRIPTS
103 # define UTF (!IN_BYTES)
105 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || ( !(PL_parser->lex_flags & LEX_IGNORE_UTF8_HINTS) && (PL_hints & HINT_UTF8)))
108 /* The maximum number of characters preceding the unrecognized one to display */
109 #define UNRECOGNIZED_PRECEDE_COUNT 10
111 /* In variables named $^X, these are the legal values for X.
112 * 1999-02-27 mjd-perl-patch@plover.com */
113 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
115 #define SPACE_OR_TAB(c) isBLANK_A(c)
117 /* LEX_* are values for PL_lex_state, the state of the lexer.
118 * They are arranged oddly so that the guard on the switch statement
119 * can get by with a single comparison (if the compiler is smart enough).
121 * These values refer to the various states within a sublex parse,
122 * i.e. within a double quotish string
125 /* #define LEX_NOTPARSING 11 is done in perl.h. */
127 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
128 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
129 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
130 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
131 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
133 /* at end of code, eg "$x" followed by: */
134 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
135 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
137 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
138 string or after \E, $foo, etc */
139 #define LEX_INTERPCONST 2 /* NOT USED */
140 #define LEX_FORMLINE 1 /* expecting a format line */
141 #define LEX_KNOWNEXT 0 /* next token known; just return it */
145 static const char* const lex_state_names[] = {
160 #include "keywords.h"
162 /* CLINE is a macro that ensures PL_copline has a sane value */
164 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
166 # define SKIPSPACE0(s) skipspace(s)
167 # define SKIPSPACE1(s) skipspace(s)
168 # define SKIPSPACE2(s,tsv) skipspace(s)
169 # define PEEKSPACE(s) skipspace(s)
172 * Convenience functions to return different tokens and prime the
173 * lexer for the next token. They all take an argument.
175 * TOKEN : generic token (used for '(', DOLSHARP, etc)
176 * OPERATOR : generic operator
177 * AOPERATOR : assignment operator
178 * PREBLOCK : beginning the block after an if, while, foreach, ...
179 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
180 * PREREF : *EXPR where EXPR is not a simple identifier
181 * TERM : expression term
182 * POSTDEREF : postfix dereference (->$* ->@[...] etc.)
183 * LOOPX : loop exiting command (goto, last, dump, etc)
184 * FTST : file test operator
185 * FUN0 : zero-argument function
186 * FUN0OP : zero-argument function, with its op created in this file
187 * FUN1 : not used, except for not, which isn't a UNIOP
188 * BOop : bitwise or or xor
190 * SHop : shift operator
191 * PWop : power operator
192 * PMop : pattern-matching operator
193 * Aop : addition-level operator
194 * Mop : multiplication-level operator
195 * Eop : equality-testing operator
196 * Rop : relational operator <= != gt
198 * Also see LOP and lop() below.
201 #ifdef DEBUGGING /* Serve -DT. */
202 # define REPORT(retval) tokereport((I32)retval, &pl_yylval)
204 # define REPORT(retval) (retval)
207 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
208 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
209 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
210 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
211 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
212 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
213 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
214 #define POSTDEREF(f) return (PL_bufptr = s, S_postderef(aTHX_ REPORT(f),s[1]))
215 #define LOOPX(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
216 #define FTST(f) return (pl_yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
217 #define FUN0(f) return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
218 #define FUN0OP(f) return (pl_yylval.opval=f, CLINE, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0OP))
219 #define FUN1(f) return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
220 #define BOop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
221 #define BAop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
222 #define SHop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
223 #define PWop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
224 #define PMop(f) return(pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
225 #define Aop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
226 #define Mop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
227 #define Eop(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
228 #define Rop(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
230 /* This bit of chicanery makes a unary function followed by
231 * a parenthesis into a function with one argument, highest precedence.
232 * The UNIDOR macro is for unary functions that can be followed by the //
233 * operator (such as C<shift // 0>).
235 #define UNI3(f,x,have_x) { \
236 pl_yylval.ival = f; \
237 if (have_x) PL_expect = x; \
239 PL_last_uni = PL_oldbufptr; \
240 PL_last_lop_op = f; \
242 return REPORT( (int)FUNC1 ); \
244 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
246 #define UNI(f) UNI3(f,XTERM,1)
247 #define UNIDOR(f) UNI3(f,XTERMORDORDOR,1)
248 #define UNIPROTO(f,optional) { \
249 if (optional) PL_last_uni = PL_oldbufptr; \
253 #define UNIBRACK(f) UNI3(f,0,0)
255 /* grandfather return to old style */
258 if (!PL_lex_allbrackets && PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC) \
259 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC; \
260 pl_yylval.ival = (f); \
266 #define COPLINE_INC_WITH_HERELINES \
268 CopLINE_inc(PL_curcop); \
269 if (PL_parser->herelines) \
270 CopLINE(PL_curcop) += PL_parser->herelines, \
271 PL_parser->herelines = 0; \
273 /* Called after scan_str to update CopLINE(PL_curcop), but only when there
274 * is no sublex_push to follow. */
275 #define COPLINE_SET_FROM_MULTI_END \
277 CopLINE_set(PL_curcop, PL_multi_end); \
278 if (PL_multi_end != PL_multi_start) \
279 PL_parser->herelines = 0; \
285 /* how to interpret the pl_yylval associated with the token */
289 TOKENTYPE_OPNUM, /* pl_yylval.ival contains an opcode number */
294 static struct debug_tokens {
296 enum token_type type;
298 } const debug_tokens[] =
300 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
301 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
302 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
303 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
304 { ARROW, TOKENTYPE_NONE, "ARROW" },
305 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
306 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
307 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
308 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
309 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
310 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
311 { DO, TOKENTYPE_NONE, "DO" },
312 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
313 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
314 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
315 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
316 { ELSE, TOKENTYPE_NONE, "ELSE" },
317 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
318 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
319 { FOR, TOKENTYPE_IVAL, "FOR" },
320 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
321 { FORMLBRACK, TOKENTYPE_NONE, "FORMLBRACK" },
322 { FORMRBRACK, TOKENTYPE_NONE, "FORMRBRACK" },
323 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
324 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
325 { FUNC0OP, TOKENTYPE_OPVAL, "FUNC0OP" },
326 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
327 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
328 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
329 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
330 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
331 { IF, TOKENTYPE_IVAL, "IF" },
332 { LABEL, TOKENTYPE_PVAL, "LABEL" },
333 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
334 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
335 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
336 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
337 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
338 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
339 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
340 { MY, TOKENTYPE_IVAL, "MY" },
341 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
342 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
343 { OROP, TOKENTYPE_IVAL, "OROP" },
344 { OROR, TOKENTYPE_NONE, "OROR" },
345 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
346 { PLUGEXPR, TOKENTYPE_OPVAL, "PLUGEXPR" },
347 { PLUGSTMT, TOKENTYPE_OPVAL, "PLUGSTMT" },
348 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
349 { POSTJOIN, TOKENTYPE_NONE, "POSTJOIN" },
350 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
351 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
352 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
353 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
354 { PREINC, TOKENTYPE_NONE, "PREINC" },
355 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
356 { QWLIST, TOKENTYPE_OPVAL, "QWLIST" },
357 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
358 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
359 { REQUIRE, TOKENTYPE_NONE, "REQUIRE" },
360 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
361 { SUB, TOKENTYPE_NONE, "SUB" },
362 { THING, TOKENTYPE_OPVAL, "THING" },
363 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
364 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
365 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
366 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
367 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
368 { USE, TOKENTYPE_IVAL, "USE" },
369 { WHEN, TOKENTYPE_IVAL, "WHEN" },
370 { WHILE, TOKENTYPE_IVAL, "WHILE" },
371 { WORD, TOKENTYPE_OPVAL, "WORD" },
372 { YADAYADA, TOKENTYPE_IVAL, "YADAYADA" },
373 { 0, TOKENTYPE_NONE, NULL }
376 /* dump the returned token in rv, plus any optional arg in pl_yylval */
379 S_tokereport(pTHX_ I32 rv, const YYSTYPE* lvalp)
381 PERL_ARGS_ASSERT_TOKEREPORT;
384 const char *name = NULL;
385 enum token_type type = TOKENTYPE_NONE;
386 const struct debug_tokens *p;
387 SV* const report = newSVpvs("<== ");
389 for (p = debug_tokens; p->token; p++) {
390 if (p->token == (int)rv) {
397 Perl_sv_catpv(aTHX_ report, name);
398 else if ((char)rv > ' ' && (char)rv <= '~')
400 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
402 sv_catpvs(report, " (pending identifier)");
405 sv_catpvs(report, "EOF");
407 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
412 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)lvalp->ival);
414 case TOKENTYPE_OPNUM:
415 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
416 PL_op_name[lvalp->ival]);
419 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", lvalp->pval);
421 case TOKENTYPE_OPVAL:
423 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
424 PL_op_name[lvalp->opval->op_type]);
425 if (lvalp->opval->op_type == OP_CONST) {
426 Perl_sv_catpvf(aTHX_ report, " %s",
427 SvPEEK(cSVOPx_sv(lvalp->opval)));
432 sv_catpvs(report, "(opval=null)");
435 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
441 /* print the buffer with suitable escapes */
444 S_printbuf(pTHX_ const char *const fmt, const char *const s)
446 SV* const tmp = newSVpvs("");
448 PERL_ARGS_ASSERT_PRINTBUF;
450 GCC_DIAG_IGNORE(-Wformat-nonliteral); /* fmt checked by caller */
451 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
459 S_deprecate_commaless_var_list(pTHX) {
461 deprecate("comma-less variable list");
462 return REPORT(','); /* grandfather non-comma-format format */
468 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
469 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
473 S_ao(pTHX_ int toketype)
475 if (*PL_bufptr == '=') {
477 if (toketype == ANDAND)
478 pl_yylval.ival = OP_ANDASSIGN;
479 else if (toketype == OROR)
480 pl_yylval.ival = OP_ORASSIGN;
481 else if (toketype == DORDOR)
482 pl_yylval.ival = OP_DORASSIGN;
490 * When Perl expects an operator and finds something else, no_op
491 * prints the warning. It always prints "<something> found where
492 * operator expected. It prints "Missing semicolon on previous line?"
493 * if the surprise occurs at the start of the line. "do you need to
494 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
495 * where the compiler doesn't know if foo is a method call or a function.
496 * It prints "Missing operator before end of line" if there's nothing
497 * after the missing operator, or "... before <...>" if there is something
498 * after the missing operator.
502 S_no_op(pTHX_ const char *const what, char *s)
504 char * const oldbp = PL_bufptr;
505 const bool is_first = (PL_oldbufptr == PL_linestart);
507 PERL_ARGS_ASSERT_NO_OP;
513 yywarn(Perl_form(aTHX_ "%s found where operator expected", what), UTF ? SVf_UTF8 : 0);
514 if (ckWARN_d(WARN_SYNTAX)) {
516 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
517 "\t(Missing semicolon on previous line?)\n");
518 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
520 for (t = PL_oldoldbufptr; (isWORDCHAR_lazy_if(t,UTF) || *t == ':');
521 t += UTF ? UTF8SKIP(t) : 1)
523 if (t < PL_bufptr && isSPACE(*t))
524 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
525 "\t(Do you need to predeclare %"UTF8f"?)\n",
526 UTF8fARG(UTF, t - PL_oldoldbufptr, PL_oldoldbufptr));
530 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
531 "\t(Missing operator before %"UTF8f"?)\n",
532 UTF8fARG(UTF, s - oldbp, oldbp));
540 * Complain about missing quote/regexp/heredoc terminator.
541 * If it's called with NULL then it cauterizes the line buffer.
542 * If we're in a delimited string and the delimiter is a control
543 * character, it's reformatted into a two-char sequence like ^C.
548 S_missingterm(pTHX_ char *s)
553 char * const nl = strrchr(s,'\n');
557 else if ((U8) PL_multi_close < 32) {
559 tmpbuf[1] = (char)toCTRL(PL_multi_close);
564 *tmpbuf = (char)PL_multi_close;
568 q = strchr(s,'"') ? '\'' : '"';
569 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
575 * Check whether the named feature is enabled.
578 Perl_feature_is_enabled(pTHX_ const char *const name, STRLEN namelen)
580 char he_name[8 + MAX_FEATURE_LEN] = "feature_";
582 PERL_ARGS_ASSERT_FEATURE_IS_ENABLED;
584 assert(CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM);
586 if (namelen > MAX_FEATURE_LEN)
588 memcpy(&he_name[8], name, namelen);
590 return cBOOL(cop_hints_fetch_pvn(PL_curcop, he_name, 8 + namelen, 0,
591 REFCOUNTED_HE_EXISTS));
595 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
596 * utf16-to-utf8-reversed.
599 #ifdef PERL_CR_FILTER
603 const char *s = SvPVX_const(sv);
604 const char * const e = s + SvCUR(sv);
606 PERL_ARGS_ASSERT_STRIP_RETURN;
608 /* outer loop optimized to do nothing if there are no CR-LFs */
610 if (*s++ == '\r' && *s == '\n') {
611 /* hit a CR-LF, need to copy the rest */
615 if (*s == '\r' && s[1] == '\n')
626 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
628 const I32 count = FILTER_READ(idx+1, sv, maxlen);
629 if (count > 0 && !maxlen)
636 =for apidoc Amx|void|lex_start|SV *line|PerlIO *rsfp|U32 flags
638 Creates and initialises a new lexer/parser state object, supplying
639 a context in which to lex and parse from a new source of Perl code.
640 A pointer to the new state object is placed in L</PL_parser>. An entry
641 is made on the save stack so that upon unwinding the new state object
642 will be destroyed and the former value of L</PL_parser> will be restored.
643 Nothing else need be done to clean up the parsing context.
645 The code to be parsed comes from I<line> and I<rsfp>. I<line>, if
646 non-null, provides a string (in SV form) containing code to be parsed.
647 A copy of the string is made, so subsequent modification of I<line>
648 does not affect parsing. I<rsfp>, if non-null, provides an input stream
649 from which code will be read to be parsed. If both are non-null, the
650 code in I<line> comes first and must consist of complete lines of input,
651 and I<rsfp> supplies the remainder of the source.
653 The I<flags> parameter is reserved for future use. Currently it is only
654 used by perl internally, so extensions should always pass zero.
659 /* LEX_START_SAME_FILTER indicates that this is not a new file, so it
660 can share filters with the current parser.
661 LEX_START_DONT_CLOSE indicates that the file handle wasn't opened by the
662 caller, hence isn't owned by the parser, so shouldn't be closed on parser
663 destruction. This is used to handle the case of defaulting to reading the
664 script from the standard input because no filename was given on the command
665 line (without getting confused by situation where STDIN has been closed, so
666 the script handle is opened on fd 0) */
669 Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, U32 flags)
671 const char *s = NULL;
672 yy_parser *parser, *oparser;
673 if (flags && flags & ~LEX_START_FLAGS)
674 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_start");
676 /* create and initialise a parser */
678 Newxz(parser, 1, yy_parser);
679 parser->old_parser = oparser = PL_parser;
682 parser->stack = NULL;
684 parser->stack_size = 0;
686 /* on scope exit, free this parser and restore any outer one */
688 parser->saved_curcop = PL_curcop;
690 /* initialise lexer state */
692 parser->nexttoke = 0;
693 parser->error_count = oparser ? oparser->error_count : 0;
694 parser->copline = parser->preambling = NOLINE;
695 parser->lex_state = LEX_NORMAL;
696 parser->expect = XSTATE;
698 parser->rsfp_filters =
699 !(flags & LEX_START_SAME_FILTER) || !oparser
701 : MUTABLE_AV(SvREFCNT_inc(
702 oparser->rsfp_filters
703 ? oparser->rsfp_filters
704 : (oparser->rsfp_filters = newAV())
707 Newx(parser->lex_brackstack, 120, char);
708 Newx(parser->lex_casestack, 12, char);
709 *parser->lex_casestack = '\0';
710 Newxz(parser->lex_shared, 1, LEXSHARED);
714 s = SvPV_const(line, len);
715 parser->linestr = flags & LEX_START_COPIED
716 ? SvREFCNT_inc_simple_NN(line)
717 : newSVpvn_flags(s, len, SvUTF8(line));
718 sv_catpvn(parser->linestr, "\n;", rsfp ? 1 : 2);
720 parser->linestr = newSVpvn("\n;", rsfp ? 1 : 2);
722 parser->oldoldbufptr =
725 parser->linestart = SvPVX(parser->linestr);
726 parser->bufend = parser->bufptr + SvCUR(parser->linestr);
727 parser->last_lop = parser->last_uni = NULL;
729 assert(FITS_IN_8_BITS(LEX_IGNORE_UTF8_HINTS|LEX_EVALBYTES
730 |LEX_DONT_CLOSE_RSFP));
731 parser->lex_flags = (U8) (flags & (LEX_IGNORE_UTF8_HINTS|LEX_EVALBYTES
732 |LEX_DONT_CLOSE_RSFP));
734 parser->in_pod = parser->filtered = 0;
738 /* delete a parser object */
741 Perl_parser_free(pTHX_ const yy_parser *parser)
743 PERL_ARGS_ASSERT_PARSER_FREE;
745 PL_curcop = parser->saved_curcop;
746 SvREFCNT_dec(parser->linestr);
748 if (PL_parser->lex_flags & LEX_DONT_CLOSE_RSFP)
749 PerlIO_clearerr(parser->rsfp);
750 else if (parser->rsfp && (!parser->old_parser ||
751 (parser->old_parser && parser->rsfp != parser->old_parser->rsfp)))
752 PerlIO_close(parser->rsfp);
753 SvREFCNT_dec(parser->rsfp_filters);
754 SvREFCNT_dec(parser->lex_stuff);
755 SvREFCNT_dec(parser->sublex_info.repl);
757 Safefree(parser->lex_brackstack);
758 Safefree(parser->lex_casestack);
759 Safefree(parser->lex_shared);
760 PL_parser = parser->old_parser;
765 Perl_parser_free_nexttoke_ops(pTHX_ yy_parser *parser, OPSLAB *slab)
767 I32 nexttoke = parser->nexttoke;
768 PERL_ARGS_ASSERT_PARSER_FREE_NEXTTOKE_OPS;
770 if (S_is_opval_token(parser->nexttype[nexttoke] & 0xffff)
771 && parser->nextval[nexttoke].opval
772 && parser->nextval[nexttoke].opval->op_slabbed
773 && OpSLAB(parser->nextval[nexttoke].opval) == slab) {
774 op_free(parser->nextval[nexttoke].opval);
775 parser->nextval[nexttoke].opval = NULL;
782 =for apidoc AmxU|SV *|PL_parser-E<gt>linestr
784 Buffer scalar containing the chunk currently under consideration of the
785 text currently being lexed. This is always a plain string scalar (for
786 which C<SvPOK> is true). It is not intended to be used as a scalar by
787 normal scalar means; instead refer to the buffer directly by the pointer
788 variables described below.
790 The lexer maintains various C<char*> pointers to things in the
791 C<PL_parser-E<gt>linestr> buffer. If C<PL_parser-E<gt>linestr> is ever
792 reallocated, all of these pointers must be updated. Don't attempt to
793 do this manually, but rather use L</lex_grow_linestr> if you need to
794 reallocate the buffer.
796 The content of the text chunk in the buffer is commonly exactly one
797 complete line of input, up to and including a newline terminator,
798 but there are situations where it is otherwise. The octets of the
799 buffer may be intended to be interpreted as either UTF-8 or Latin-1.
800 The function L</lex_bufutf8> tells you which. Do not use the C<SvUTF8>
801 flag on this scalar, which may disagree with it.
803 For direct examination of the buffer, the variable
804 L</PL_parser-E<gt>bufend> points to the end of the buffer. The current
805 lexing position is pointed to by L</PL_parser-E<gt>bufptr>. Direct use
806 of these pointers is usually preferable to examination of the scalar
807 through normal scalar means.
809 =for apidoc AmxU|char *|PL_parser-E<gt>bufend
811 Direct pointer to the end of the chunk of text currently being lexed, the
812 end of the lexer buffer. This is equal to C<SvPVX(PL_parser-E<gt>linestr)
813 + SvCUR(PL_parser-E<gt>linestr)>. A C<NUL> character (zero octet) is
814 always located at the end of the buffer, and does not count as part of
815 the buffer's contents.
817 =for apidoc AmxU|char *|PL_parser-E<gt>bufptr
819 Points to the current position of lexing inside the lexer buffer.
820 Characters around this point may be freely examined, within
821 the range delimited by C<SvPVX(L</PL_parser-E<gt>linestr>)> and
822 L</PL_parser-E<gt>bufend>. The octets of the buffer may be intended to be
823 interpreted as either UTF-8 or Latin-1, as indicated by L</lex_bufutf8>.
825 Lexing code (whether in the Perl core or not) moves this pointer past
826 the characters that it consumes. It is also expected to perform some
827 bookkeeping whenever a newline character is consumed. This movement
828 can be more conveniently performed by the function L</lex_read_to>,
829 which handles newlines appropriately.
831 Interpretation of the buffer's octets can be abstracted out by
832 using the slightly higher-level functions L</lex_peek_unichar> and
833 L</lex_read_unichar>.
835 =for apidoc AmxU|char *|PL_parser-E<gt>linestart
837 Points to the start of the current line inside the lexer buffer.
838 This is useful for indicating at which column an error occurred, and
839 not much else. This must be updated by any lexing code that consumes
840 a newline; the function L</lex_read_to> handles this detail.
846 =for apidoc Amx|bool|lex_bufutf8
848 Indicates whether the octets in the lexer buffer
849 (L</PL_parser-E<gt>linestr>) should be interpreted as the UTF-8 encoding
850 of Unicode characters. If not, they should be interpreted as Latin-1
851 characters. This is analogous to the C<SvUTF8> flag for scalars.
853 In UTF-8 mode, it is not guaranteed that the lexer buffer actually
854 contains valid UTF-8. Lexing code must be robust in the face of invalid
857 The actual C<SvUTF8> flag of the L</PL_parser-E<gt>linestr> scalar
858 is significant, but not the whole story regarding the input character
859 encoding. Normally, when a file is being read, the scalar contains octets
860 and its C<SvUTF8> flag is off, but the octets should be interpreted as
861 UTF-8 if the C<use utf8> pragma is in effect. During a string eval,
862 however, the scalar may have the C<SvUTF8> flag on, and in this case its
863 octets should be interpreted as UTF-8 unless the C<use bytes> pragma
864 is in effect. This logic may change in the future; use this function
865 instead of implementing the logic yourself.
871 Perl_lex_bufutf8(pTHX)
877 =for apidoc Amx|char *|lex_grow_linestr|STRLEN len
879 Reallocates the lexer buffer (L</PL_parser-E<gt>linestr>) to accommodate
880 at least I<len> octets (including terminating C<NUL>). Returns a
881 pointer to the reallocated buffer. This is necessary before making
882 any direct modification of the buffer that would increase its length.
883 L</lex_stuff_pvn> provides a more convenient way to insert text into
886 Do not use C<SvGROW> or C<sv_grow> directly on C<PL_parser-E<gt>linestr>;
887 this function updates all of the lexer's variables that point directly
894 Perl_lex_grow_linestr(pTHX_ STRLEN len)
898 STRLEN bufend_pos, bufptr_pos, oldbufptr_pos, oldoldbufptr_pos;
899 STRLEN linestart_pos, last_uni_pos, last_lop_pos, re_eval_start_pos;
900 linestr = PL_parser->linestr;
901 buf = SvPVX(linestr);
902 if (len <= SvLEN(linestr))
904 bufend_pos = PL_parser->bufend - buf;
905 bufptr_pos = PL_parser->bufptr - buf;
906 oldbufptr_pos = PL_parser->oldbufptr - buf;
907 oldoldbufptr_pos = PL_parser->oldoldbufptr - buf;
908 linestart_pos = PL_parser->linestart - buf;
909 last_uni_pos = PL_parser->last_uni ? PL_parser->last_uni - buf : 0;
910 last_lop_pos = PL_parser->last_lop ? PL_parser->last_lop - buf : 0;
911 re_eval_start_pos = PL_parser->lex_shared->re_eval_start ?
912 PL_parser->lex_shared->re_eval_start - buf : 0;
914 buf = sv_grow(linestr, len);
916 PL_parser->bufend = buf + bufend_pos;
917 PL_parser->bufptr = buf + bufptr_pos;
918 PL_parser->oldbufptr = buf + oldbufptr_pos;
919 PL_parser->oldoldbufptr = buf + oldoldbufptr_pos;
920 PL_parser->linestart = buf + linestart_pos;
921 if (PL_parser->last_uni)
922 PL_parser->last_uni = buf + last_uni_pos;
923 if (PL_parser->last_lop)
924 PL_parser->last_lop = buf + last_lop_pos;
925 if (PL_parser->lex_shared->re_eval_start)
926 PL_parser->lex_shared->re_eval_start = buf + re_eval_start_pos;
931 =for apidoc Amx|void|lex_stuff_pvn|const char *pv|STRLEN len|U32 flags
933 Insert characters into the lexer buffer (L</PL_parser-E<gt>linestr>),
934 immediately after the current lexing point (L</PL_parser-E<gt>bufptr>),
935 reallocating the buffer if necessary. This means that lexing code that
936 runs later will see the characters as if they had appeared in the input.
937 It is not recommended to do this as part of normal parsing, and most
938 uses of this facility run the risk of the inserted characters being
939 interpreted in an unintended manner.
941 The string to be inserted is represented by I<len> octets starting
942 at I<pv>. These octets are interpreted as either UTF-8 or Latin-1,
943 according to whether the C<LEX_STUFF_UTF8> flag is set in I<flags>.
944 The characters are recoded for the lexer buffer, according to how the
945 buffer is currently being interpreted (L</lex_bufutf8>). If a string
946 to be inserted is available as a Perl scalar, the L</lex_stuff_sv>
947 function is more convenient.
953 Perl_lex_stuff_pvn(pTHX_ const char *pv, STRLEN len, U32 flags)
957 PERL_ARGS_ASSERT_LEX_STUFF_PVN;
958 if (flags & ~(LEX_STUFF_UTF8))
959 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_stuff_pvn");
961 if (flags & LEX_STUFF_UTF8) {
964 STRLEN highhalf = 0; /* Count of variants */
965 const char *p, *e = pv+len;
966 for (p = pv; p != e; p++) {
967 if (! UTF8_IS_INVARIANT(*p)) {
973 lex_grow_linestr(SvCUR(PL_parser->linestr)+1+len+highhalf);
974 bufptr = PL_parser->bufptr;
975 Move(bufptr, bufptr+len+highhalf, PL_parser->bufend+1-bufptr, char);
976 SvCUR_set(PL_parser->linestr,
977 SvCUR(PL_parser->linestr) + len+highhalf);
978 PL_parser->bufend += len+highhalf;
979 for (p = pv; p != e; p++) {
981 if (! UTF8_IS_INVARIANT(c)) {
982 *bufptr++ = UTF8_TWO_BYTE_HI(c);
983 *bufptr++ = UTF8_TWO_BYTE_LO(c);
990 if (flags & LEX_STUFF_UTF8) {
992 const char *p, *e = pv+len;
993 for (p = pv; p != e; p++) {
995 if (UTF8_IS_ABOVE_LATIN1(c)) {
996 Perl_croak(aTHX_ "Lexing code attempted to stuff "
997 "non-Latin-1 character into Latin-1 input");
998 } else if (UTF8_IS_NEXT_CHAR_DOWNGRADEABLE(p, e)) {
1001 } else if (! UTF8_IS_INVARIANT(c)) {
1002 /* malformed UTF-8 */
1004 SAVESPTR(PL_warnhook);
1005 PL_warnhook = PERL_WARNHOOK_FATAL;
1006 utf8n_to_uvchr((U8*)p, e-p, NULL, 0);
1012 lex_grow_linestr(SvCUR(PL_parser->linestr)+1+len-highhalf);
1013 bufptr = PL_parser->bufptr;
1014 Move(bufptr, bufptr+len-highhalf, PL_parser->bufend+1-bufptr, char);
1015 SvCUR_set(PL_parser->linestr,
1016 SvCUR(PL_parser->linestr) + len-highhalf);
1017 PL_parser->bufend += len-highhalf;
1020 if (UTF8_IS_INVARIANT(*p)) {
1026 *bufptr++ = TWO_BYTE_UTF8_TO_NATIVE(*p, *(p+1));
1032 lex_grow_linestr(SvCUR(PL_parser->linestr)+1+len);
1033 bufptr = PL_parser->bufptr;
1034 Move(bufptr, bufptr+len, PL_parser->bufend+1-bufptr, char);
1035 SvCUR_set(PL_parser->linestr, SvCUR(PL_parser->linestr) + len);
1036 PL_parser->bufend += len;
1037 Copy(pv, bufptr, len, char);
1043 =for apidoc Amx|void|lex_stuff_pv|const char *pv|U32 flags
1045 Insert characters into the lexer buffer (L</PL_parser-E<gt>linestr>),
1046 immediately after the current lexing point (L</PL_parser-E<gt>bufptr>),
1047 reallocating the buffer if necessary. This means that lexing code that
1048 runs later will see the characters as if they had appeared in the input.
1049 It is not recommended to do this as part of normal parsing, and most
1050 uses of this facility run the risk of the inserted characters being
1051 interpreted in an unintended manner.
1053 The string to be inserted is represented by octets starting at I<pv>
1054 and continuing to the first nul. These octets are interpreted as either
1055 UTF-8 or Latin-1, according to whether the C<LEX_STUFF_UTF8> flag is set
1056 in I<flags>. The characters are recoded for the lexer buffer, according
1057 to how the buffer is currently being interpreted (L</lex_bufutf8>).
1058 If it is not convenient to nul-terminate a string to be inserted, the
1059 L</lex_stuff_pvn> function is more appropriate.
1065 Perl_lex_stuff_pv(pTHX_ const char *pv, U32 flags)
1067 PERL_ARGS_ASSERT_LEX_STUFF_PV;
1068 lex_stuff_pvn(pv, strlen(pv), flags);
1072 =for apidoc Amx|void|lex_stuff_sv|SV *sv|U32 flags
1074 Insert characters into the lexer buffer (L</PL_parser-E<gt>linestr>),
1075 immediately after the current lexing point (L</PL_parser-E<gt>bufptr>),
1076 reallocating the buffer if necessary. This means that lexing code that
1077 runs later will see the characters as if they had appeared in the input.
1078 It is not recommended to do this as part of normal parsing, and most
1079 uses of this facility run the risk of the inserted characters being
1080 interpreted in an unintended manner.
1082 The string to be inserted is the string value of I<sv>. The characters
1083 are recoded for the lexer buffer, according to how the buffer is currently
1084 being interpreted (L</lex_bufutf8>). If a string to be inserted is
1085 not already a Perl scalar, the L</lex_stuff_pvn> function avoids the
1086 need to construct a scalar.
1092 Perl_lex_stuff_sv(pTHX_ SV *sv, U32 flags)
1096 PERL_ARGS_ASSERT_LEX_STUFF_SV;
1098 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_stuff_sv");
1100 lex_stuff_pvn(pv, len, flags | (SvUTF8(sv) ? LEX_STUFF_UTF8 : 0));
1104 =for apidoc Amx|void|lex_unstuff|char *ptr
1106 Discards text about to be lexed, from L</PL_parser-E<gt>bufptr> up to
1107 I<ptr>. Text following I<ptr> will be moved, and the buffer shortened.
1108 This hides the discarded text from any lexing code that runs later,
1109 as if the text had never appeared.
1111 This is not the normal way to consume lexed text. For that, use
1118 Perl_lex_unstuff(pTHX_ char *ptr)
1122 PERL_ARGS_ASSERT_LEX_UNSTUFF;
1123 buf = PL_parser->bufptr;
1125 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_unstuff");
1128 bufend = PL_parser->bufend;
1130 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_unstuff");
1131 unstuff_len = ptr - buf;
1132 Move(ptr, buf, bufend+1-ptr, char);
1133 SvCUR_set(PL_parser->linestr, SvCUR(PL_parser->linestr) - unstuff_len);
1134 PL_parser->bufend = bufend - unstuff_len;
1138 =for apidoc Amx|void|lex_read_to|char *ptr
1140 Consume text in the lexer buffer, from L</PL_parser-E<gt>bufptr> up
1141 to I<ptr>. This advances L</PL_parser-E<gt>bufptr> to match I<ptr>,
1142 performing the correct bookkeeping whenever a newline character is passed.
1143 This is the normal way to consume lexed text.
1145 Interpretation of the buffer's octets can be abstracted out by
1146 using the slightly higher-level functions L</lex_peek_unichar> and
1147 L</lex_read_unichar>.
1153 Perl_lex_read_to(pTHX_ char *ptr)
1156 PERL_ARGS_ASSERT_LEX_READ_TO;
1157 s = PL_parser->bufptr;
1158 if (ptr < s || ptr > PL_parser->bufend)
1159 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_read_to");
1160 for (; s != ptr; s++)
1162 COPLINE_INC_WITH_HERELINES;
1163 PL_parser->linestart = s+1;
1165 PL_parser->bufptr = ptr;
1169 =for apidoc Amx|void|lex_discard_to|char *ptr
1171 Discards the first part of the L</PL_parser-E<gt>linestr> buffer,
1172 up to I<ptr>. The remaining content of the buffer will be moved, and
1173 all pointers into the buffer updated appropriately. I<ptr> must not
1174 be later in the buffer than the position of L</PL_parser-E<gt>bufptr>:
1175 it is not permitted to discard text that has yet to be lexed.
1177 Normally it is not necessarily to do this directly, because it suffices to
1178 use the implicit discarding behaviour of L</lex_next_chunk> and things
1179 based on it. However, if a token stretches across multiple lines,
1180 and the lexing code has kept multiple lines of text in the buffer for
1181 that purpose, then after completion of the token it would be wise to
1182 explicitly discard the now-unneeded earlier lines, to avoid future
1183 multi-line tokens growing the buffer without bound.
1189 Perl_lex_discard_to(pTHX_ char *ptr)
1193 PERL_ARGS_ASSERT_LEX_DISCARD_TO;
1194 buf = SvPVX(PL_parser->linestr);
1196 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_discard_to");
1199 if (ptr > PL_parser->bufptr)
1200 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_discard_to");
1201 discard_len = ptr - buf;
1202 if (PL_parser->oldbufptr < ptr)
1203 PL_parser->oldbufptr = ptr;
1204 if (PL_parser->oldoldbufptr < ptr)
1205 PL_parser->oldoldbufptr = ptr;
1206 if (PL_parser->last_uni && PL_parser->last_uni < ptr)
1207 PL_parser->last_uni = NULL;
1208 if (PL_parser->last_lop && PL_parser->last_lop < ptr)
1209 PL_parser->last_lop = NULL;
1210 Move(ptr, buf, PL_parser->bufend+1-ptr, char);
1211 SvCUR_set(PL_parser->linestr, SvCUR(PL_parser->linestr) - discard_len);
1212 PL_parser->bufend -= discard_len;
1213 PL_parser->bufptr -= discard_len;
1214 PL_parser->oldbufptr -= discard_len;
1215 PL_parser->oldoldbufptr -= discard_len;
1216 if (PL_parser->last_uni)
1217 PL_parser->last_uni -= discard_len;
1218 if (PL_parser->last_lop)
1219 PL_parser->last_lop -= discard_len;
1223 =for apidoc Amx|bool|lex_next_chunk|U32 flags
1225 Reads in the next chunk of text to be lexed, appending it to
1226 L</PL_parser-E<gt>linestr>. This should be called when lexing code has
1227 looked to the end of the current chunk and wants to know more. It is
1228 usual, but not necessary, for lexing to have consumed the entirety of
1229 the current chunk at this time.
1231 If L</PL_parser-E<gt>bufptr> is pointing to the very end of the current
1232 chunk (i.e., the current chunk has been entirely consumed), normally the
1233 current chunk will be discarded at the same time that the new chunk is
1234 read in. If I<flags> includes C<LEX_KEEP_PREVIOUS>, the current chunk
1235 will not be discarded. If the current chunk has not been entirely
1236 consumed, then it will not be discarded regardless of the flag.
1238 Returns true if some new text was added to the buffer, or false if the
1239 buffer has reached the end of the input text.
1244 #define LEX_FAKE_EOF 0x80000000
1245 #define LEX_NO_TERM 0x40000000
1248 Perl_lex_next_chunk(pTHX_ U32 flags)
1252 STRLEN old_bufend_pos, new_bufend_pos;
1253 STRLEN bufptr_pos, oldbufptr_pos, oldoldbufptr_pos;
1254 STRLEN linestart_pos, last_uni_pos, last_lop_pos;
1255 bool got_some_for_debugger = 0;
1257 if (flags & ~(LEX_KEEP_PREVIOUS|LEX_FAKE_EOF|LEX_NO_TERM))
1258 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_next_chunk");
1259 linestr = PL_parser->linestr;
1260 buf = SvPVX(linestr);
1261 if (!(flags & LEX_KEEP_PREVIOUS) &&
1262 PL_parser->bufptr == PL_parser->bufend) {
1263 old_bufend_pos = bufptr_pos = oldbufptr_pos = oldoldbufptr_pos = 0;
1265 if (PL_parser->last_uni != PL_parser->bufend)
1266 PL_parser->last_uni = NULL;
1267 if (PL_parser->last_lop != PL_parser->bufend)
1268 PL_parser->last_lop = NULL;
1269 last_uni_pos = last_lop_pos = 0;
1273 old_bufend_pos = PL_parser->bufend - buf;
1274 bufptr_pos = PL_parser->bufptr - buf;
1275 oldbufptr_pos = PL_parser->oldbufptr - buf;
1276 oldoldbufptr_pos = PL_parser->oldoldbufptr - buf;
1277 linestart_pos = PL_parser->linestart - buf;
1278 last_uni_pos = PL_parser->last_uni ? PL_parser->last_uni - buf : 0;
1279 last_lop_pos = PL_parser->last_lop ? PL_parser->last_lop - buf : 0;
1281 if (flags & LEX_FAKE_EOF) {
1283 } else if (!PL_parser->rsfp && !PL_parser->filtered) {
1285 } else if (filter_gets(linestr, old_bufend_pos)) {
1287 got_some_for_debugger = 1;
1288 } else if (flags & LEX_NO_TERM) {
1291 if (!SvPOK(linestr)) /* can get undefined by filter_gets */
1292 sv_setpvs(linestr, "");
1294 /* End of real input. Close filehandle (unless it was STDIN),
1295 * then add implicit termination.
1297 if (PL_parser->lex_flags & LEX_DONT_CLOSE_RSFP)
1298 PerlIO_clearerr(PL_parser->rsfp);
1299 else if (PL_parser->rsfp)
1300 (void)PerlIO_close(PL_parser->rsfp);
1301 PL_parser->rsfp = NULL;
1302 PL_parser->in_pod = PL_parser->filtered = 0;
1303 if (!PL_in_eval && PL_minus_p) {
1305 /*{*/";}continue{print or die qq(-p destination: $!\\n);}");
1306 PL_minus_n = PL_minus_p = 0;
1307 } else if (!PL_in_eval && PL_minus_n) {
1308 sv_catpvs(linestr, /*{*/";}");
1311 sv_catpvs(linestr, ";");
1314 buf = SvPVX(linestr);
1315 new_bufend_pos = SvCUR(linestr);
1316 PL_parser->bufend = buf + new_bufend_pos;
1317 PL_parser->bufptr = buf + bufptr_pos;
1318 PL_parser->oldbufptr = buf + oldbufptr_pos;
1319 PL_parser->oldoldbufptr = buf + oldoldbufptr_pos;
1320 PL_parser->linestart = buf + linestart_pos;
1321 if (PL_parser->last_uni)
1322 PL_parser->last_uni = buf + last_uni_pos;
1323 if (PL_parser->last_lop)
1324 PL_parser->last_lop = buf + last_lop_pos;
1325 if (PL_parser->preambling != NOLINE) {
1326 CopLINE_set(PL_curcop, PL_parser->preambling + 1);
1327 PL_parser->preambling = NOLINE;
1329 if (got_some_for_debugger && (PERLDB_LINE || PERLDB_SAVESRC) &&
1330 PL_curstash != PL_debstash) {
1331 /* debugger active and we're not compiling the debugger code,
1332 * so store the line into the debugger's array of lines
1334 update_debugger_info(NULL, buf+old_bufend_pos,
1335 new_bufend_pos-old_bufend_pos);
1341 =for apidoc Amx|I32|lex_peek_unichar|U32 flags
1343 Looks ahead one (Unicode) character in the text currently being lexed.
1344 Returns the codepoint (unsigned integer value) of the next character,
1345 or -1 if lexing has reached the end of the input text. To consume the
1346 peeked character, use L</lex_read_unichar>.
1348 If the next character is in (or extends into) the next chunk of input
1349 text, the next chunk will be read in. Normally the current chunk will be
1350 discarded at the same time, but if I<flags> includes C<LEX_KEEP_PREVIOUS>
1351 then the current chunk will not be discarded.
1353 If the input is being interpreted as UTF-8 and a UTF-8 encoding error
1354 is encountered, an exception is generated.
1360 Perl_lex_peek_unichar(pTHX_ U32 flags)
1364 if (flags & ~(LEX_KEEP_PREVIOUS))
1365 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_peek_unichar");
1366 s = PL_parser->bufptr;
1367 bufend = PL_parser->bufend;
1373 if (!lex_next_chunk(flags))
1375 s = PL_parser->bufptr;
1376 bufend = PL_parser->bufend;
1379 if (UTF8_IS_INVARIANT(head))
1381 if (UTF8_IS_START(head)) {
1382 len = UTF8SKIP(&head);
1383 while ((STRLEN)(bufend-s) < len) {
1384 if (!lex_next_chunk(flags | LEX_KEEP_PREVIOUS))
1386 s = PL_parser->bufptr;
1387 bufend = PL_parser->bufend;
1390 unichar = utf8n_to_uvchr((U8*)s, bufend-s, &retlen, UTF8_CHECK_ONLY);
1391 if (retlen == (STRLEN)-1) {
1392 /* malformed UTF-8 */
1394 SAVESPTR(PL_warnhook);
1395 PL_warnhook = PERL_WARNHOOK_FATAL;
1396 utf8n_to_uvchr((U8*)s, bufend-s, NULL, 0);
1402 if (!lex_next_chunk(flags))
1404 s = PL_parser->bufptr;
1411 =for apidoc Amx|I32|lex_read_unichar|U32 flags
1413 Reads the next (Unicode) character in the text currently being lexed.
1414 Returns the codepoint (unsigned integer value) of the character read,
1415 and moves L</PL_parser-E<gt>bufptr> past the character, or returns -1
1416 if lexing has reached the end of the input text. To non-destructively
1417 examine the next character, use L</lex_peek_unichar> instead.
1419 If the next character is in (or extends into) the next chunk of input
1420 text, the next chunk will be read in. Normally the current chunk will be
1421 discarded at the same time, but if I<flags> includes C<LEX_KEEP_PREVIOUS>
1422 then the current chunk will not be discarded.
1424 If the input is being interpreted as UTF-8 and a UTF-8 encoding error
1425 is encountered, an exception is generated.
1431 Perl_lex_read_unichar(pTHX_ U32 flags)
1434 if (flags & ~(LEX_KEEP_PREVIOUS))
1435 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_read_unichar");
1436 c = lex_peek_unichar(flags);
1439 COPLINE_INC_WITH_HERELINES;
1441 PL_parser->bufptr += UTF8SKIP(PL_parser->bufptr);
1443 ++(PL_parser->bufptr);
1449 =for apidoc Amx|void|lex_read_space|U32 flags
1451 Reads optional spaces, in Perl style, in the text currently being
1452 lexed. The spaces may include ordinary whitespace characters and
1453 Perl-style comments. C<#line> directives are processed if encountered.
1454 L</PL_parser-E<gt>bufptr> is moved past the spaces, so that it points
1455 at a non-space character (or the end of the input text).
1457 If spaces extend into the next chunk of input text, the next chunk will
1458 be read in. Normally the current chunk will be discarded at the same
1459 time, but if I<flags> includes C<LEX_KEEP_PREVIOUS> then the current
1460 chunk will not be discarded.
1465 #define LEX_NO_INCLINE 0x40000000
1466 #define LEX_NO_NEXT_CHUNK 0x80000000
1469 Perl_lex_read_space(pTHX_ U32 flags)
1472 const bool can_incline = !(flags & LEX_NO_INCLINE);
1473 bool need_incline = 0;
1474 if (flags & ~(LEX_KEEP_PREVIOUS|LEX_NO_NEXT_CHUNK|LEX_NO_INCLINE))
1475 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_read_space");
1476 s = PL_parser->bufptr;
1477 bufend = PL_parser->bufend;
1483 } while (!(c == '\n' || (c == 0 && s == bufend)));
1484 } else if (c == '\n') {
1487 PL_parser->linestart = s;
1493 } else if (isSPACE(c)) {
1495 } else if (c == 0 && s == bufend) {
1498 if (flags & LEX_NO_NEXT_CHUNK)
1500 PL_parser->bufptr = s;
1501 l = CopLINE(PL_curcop);
1502 CopLINE(PL_curcop) += PL_parser->herelines + 1;
1503 got_more = lex_next_chunk(flags);
1504 CopLINE_set(PL_curcop, l);
1505 s = PL_parser->bufptr;
1506 bufend = PL_parser->bufend;
1509 if (can_incline && need_incline && PL_parser->rsfp) {
1517 PL_parser->bufptr = s;
1522 =for apidoc EXMp|bool|validate_proto|SV *name|SV *proto|bool warn
1524 This function performs syntax checking on a prototype, C<proto>.
1525 If C<warn> is true, any illegal characters or mismatched brackets
1526 will trigger illegalproto warnings, declaring that they were
1527 detected in the prototype for C<name>.
1529 The return value is C<true> if this is a valid prototype, and
1530 C<false> if it is not, regardless of whether C<warn> was C<true> or
1533 Note that C<NULL> is a valid C<proto> and will always return C<true>.
1540 Perl_validate_proto(pTHX_ SV *name, SV *proto, bool warn)
1542 STRLEN len, origlen;
1543 char *p = proto ? SvPV(proto, len) : NULL;
1544 bool bad_proto = FALSE;
1545 bool in_brackets = FALSE;
1546 bool after_slash = FALSE;
1547 char greedy_proto = ' ';
1548 bool proto_after_greedy_proto = FALSE;
1549 bool must_be_last = FALSE;
1550 bool underscore = FALSE;
1551 bool bad_proto_after_underscore = FALSE;
1553 PERL_ARGS_ASSERT_VALIDATE_PROTO;
1559 for (; len--; p++) {
1562 proto_after_greedy_proto = TRUE;
1564 if (!strchr(";@%", *p))
1565 bad_proto_after_underscore = TRUE;
1568 if (!strchr("$@%*;[]&\\_+", *p) || *p == '\0') {
1575 in_brackets = FALSE;
1576 else if ((*p == '@' || *p == '%') &&
1579 must_be_last = TRUE;
1588 after_slash = FALSE;
1593 SV *tmpsv = newSVpvs_flags("", SVs_TEMP);
1596 ? sv_uni_display(tmpsv, newSVpvn_flags(p, origlen, SVs_TEMP | SVf_UTF8),
1597 origlen, UNI_DISPLAY_ISPRINT)
1598 : pv_pretty(tmpsv, p, origlen, 60, NULL, NULL, PERL_PV_ESCAPE_NONASCII);
1600 if (proto_after_greedy_proto)
1601 Perl_warner(aTHX_ packWARN(WARN_ILLEGALPROTO),
1602 "Prototype after '%c' for %"SVf" : %s",
1603 greedy_proto, SVfARG(name), p);
1605 Perl_warner(aTHX_ packWARN(WARN_ILLEGALPROTO),
1606 "Missing ']' in prototype for %"SVf" : %s",
1609 Perl_warner(aTHX_ packWARN(WARN_ILLEGALPROTO),
1610 "Illegal character in prototype for %"SVf" : %s",
1612 if (bad_proto_after_underscore)
1613 Perl_warner(aTHX_ packWARN(WARN_ILLEGALPROTO),
1614 "Illegal character after '_' in prototype for %"SVf" : %s",
1618 return (! (proto_after_greedy_proto || bad_proto) );
1623 * This subroutine has nothing to do with tilting, whether at windmills
1624 * or pinball tables. Its name is short for "increment line". It
1625 * increments the current line number in CopLINE(PL_curcop) and checks
1626 * to see whether the line starts with a comment of the form
1627 * # line 500 "foo.pm"
1628 * If so, it sets the current line number and file to the values in the comment.
1632 S_incline(pTHX_ const char *s)
1639 PERL_ARGS_ASSERT_INCLINE;
1641 COPLINE_INC_WITH_HERELINES;
1642 if (!PL_rsfp && !PL_parser->filtered && PL_lex_state == LEX_NORMAL
1643 && s+1 == PL_bufend && *s == ';') {
1644 /* fake newline in string eval */
1645 CopLINE_dec(PL_curcop);
1650 while (SPACE_OR_TAB(*s))
1652 if (strnEQ(s, "line", 4))
1656 if (SPACE_OR_TAB(*s))
1660 while (SPACE_OR_TAB(*s))
1668 if (!SPACE_OR_TAB(*s) && *s != '\r' && *s != '\n' && *s != '\0')
1670 while (SPACE_OR_TAB(*s))
1672 if (*s == '"' && (t = strchr(s+1, '"'))) {
1678 while (!isSPACE(*t))
1682 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
1684 if (*e != '\n' && *e != '\0')
1685 return; /* false alarm */
1687 line_num = grok_atou(n, &e) - 1;
1690 const STRLEN len = t - s;
1692 if (!PL_rsfp && !PL_parser->filtered) {
1693 /* must copy *{"::_<(eval N)[oldfilename:L]"}
1694 * to *{"::_<newfilename"} */
1695 /* However, the long form of evals is only turned on by the
1696 debugger - usually they're "(eval %lu)" */
1697 GV * const cfgv = CopFILEGV(PL_curcop);
1700 STRLEN tmplen2 = len;
1704 if (tmplen2 + 2 <= sizeof smallbuf)
1707 Newx(tmpbuf2, tmplen2 + 2, char);
1712 memcpy(tmpbuf2 + 2, s, tmplen2);
1715 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
1717 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
1718 /* adjust ${"::_<newfilename"} to store the new file name */
1719 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
1720 /* The line number may differ. If that is the case,
1721 alias the saved lines that are in the array.
1722 Otherwise alias the whole array. */
1723 if (CopLINE(PL_curcop) == line_num) {
1724 GvHV(gv2) = MUTABLE_HV(SvREFCNT_inc(GvHV(cfgv)));
1725 GvAV(gv2) = MUTABLE_AV(SvREFCNT_inc(GvAV(cfgv)));
1727 else if (GvAV(cfgv)) {
1728 AV * const av = GvAV(cfgv);
1729 const I32 start = CopLINE(PL_curcop)+1;
1730 I32 items = AvFILLp(av) - start;
1732 AV * const av2 = GvAVn(gv2);
1733 SV **svp = AvARRAY(av) + start;
1734 I32 l = (I32)line_num+1;
1736 av_store(av2, l++, SvREFCNT_inc(*svp++));
1741 if (tmpbuf2 != smallbuf) Safefree(tmpbuf2);
1744 CopFILE_free(PL_curcop);
1745 CopFILE_setn(PL_curcop, s, len);
1747 CopLINE_set(PL_curcop, line_num);
1750 #define skipspace(s) skipspace_flags(s, 0)
1754 S_update_debugger_info(pTHX_ SV *orig_sv, const char *const buf, STRLEN len)
1756 AV *av = CopFILEAVx(PL_curcop);
1759 if (PL_parser->preambling == NOLINE) sv = newSV_type(SVt_PVMG);
1761 sv = *av_fetch(av, 0, 1);
1762 SvUPGRADE(sv, SVt_PVMG);
1764 if (!SvPOK(sv)) sv_setpvs(sv,"");
1766 sv_catsv(sv, orig_sv);
1768 sv_catpvn(sv, buf, len);
1773 if (PL_parser->preambling == NOLINE)
1774 av_store(av, CopLINE(PL_curcop), sv);
1780 * Called to gobble the appropriate amount and type of whitespace.
1781 * Skips comments as well.
1785 S_skipspace_flags(pTHX_ char *s, U32 flags)
1787 PERL_ARGS_ASSERT_SKIPSPACE_FLAGS;
1788 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
1789 while (s < PL_bufend && SPACE_OR_TAB(*s))
1792 STRLEN bufptr_pos = PL_bufptr - SvPVX(PL_linestr);
1794 lex_read_space(flags | LEX_KEEP_PREVIOUS |
1795 (PL_sublex_info.sub_inwhat || PL_lex_state == LEX_FORMLINE ?
1796 LEX_NO_NEXT_CHUNK : 0));
1798 PL_bufptr = SvPVX(PL_linestr) + bufptr_pos;
1799 if (PL_linestart > PL_bufptr)
1800 PL_bufptr = PL_linestart;
1808 * Check the unary operators to ensure there's no ambiguity in how they're
1809 * used. An ambiguous piece of code would be:
1811 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1812 * the +5 is its argument.
1821 if (PL_oldoldbufptr != PL_last_uni)
1823 while (isSPACE(*PL_last_uni))
1826 while (isWORDCHAR_lazy_if(s,UTF) || *s == '-')
1828 if ((t = strchr(s, '(')) && t < PL_bufptr)
1831 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
1832 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1833 (int)(s - PL_last_uni), PL_last_uni);
1837 * LOP : macro to build a list operator. Its behaviour has been replaced
1838 * with a subroutine, S_lop() for which LOP is just another name.
1841 #define LOP(f,x) return lop(f,x,s)
1845 * Build a list operator (or something that might be one). The rules:
1846 * - if we have a next token, then it's a list operator [why?]
1847 * - if the next thing is an opening paren, then it's a function
1848 * - else it's a list operator
1852 S_lop(pTHX_ I32 f, int x, char *s)
1854 PERL_ARGS_ASSERT_LOP;
1860 PL_last_lop = PL_oldbufptr;
1861 PL_last_lop_op = (OPCODE)f;
1865 return REPORT(FUNC);
1868 return REPORT(FUNC);
1871 if (!PL_lex_allbrackets && PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC)
1872 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC;
1873 return REPORT(LSTOP);
1879 * When the lexer realizes it knows the next token (for instance,
1880 * it is reordering tokens for the parser) then it can call S_force_next
1881 * to know what token to return the next time the lexer is called. Caller
1882 * will need to set PL_nextval[] and possibly PL_expect to ensure
1883 * the lexer handles the token correctly.
1887 S_force_next(pTHX_ I32 type)
1891 PerlIO_printf(Perl_debug_log, "### forced token:\n");
1892 tokereport(type, &NEXTVAL_NEXTTOKE);
1895 PL_nexttype[PL_nexttoke] = type;
1897 if (PL_lex_state != LEX_KNOWNEXT) {
1898 PL_lex_defer = PL_lex_state;
1899 PL_lex_expect = PL_expect;
1900 PL_lex_state = LEX_KNOWNEXT;
1907 * This subroutine handles postfix deref syntax after the arrow has already
1908 * been emitted. @* $* etc. are emitted as two separate token right here.
1909 * @[ @{ %[ %{ *{ are emitted also as two tokens, but this function emits
1910 * only the first, leaving yylex to find the next.
1914 S_postderef(pTHX_ int const funny, char const next)
1916 assert(funny == DOLSHARP || strchr("$@%&*", funny));
1917 assert(strchr("*[{", next));
1919 PL_expect = XOPERATOR;
1920 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
1921 assert('@' == funny || '$' == funny || DOLSHARP == funny);
1922 PL_lex_state = LEX_INTERPEND;
1923 force_next(POSTJOIN);
1929 if ('@' == funny && PL_lex_state == LEX_INTERPNORMAL
1930 && !PL_lex_brackets)
1932 PL_expect = XOPERATOR;
1941 int yyc = PL_parser->yychar;
1942 if (yyc != YYEMPTY) {
1944 NEXTVAL_NEXTTOKE = PL_parser->yylval;
1945 if (yyc == '{'/*}*/ || yyc == HASHBRACK || yyc == '['/*]*/) {
1946 PL_lex_allbrackets--;
1948 yyc |= (3<<24) | (PL_lex_brackstack[PL_lex_brackets] << 16);
1949 } else if (yyc == '('/*)*/) {
1950 PL_lex_allbrackets--;
1955 PL_parser->yychar = YYEMPTY;
1960 S_newSV_maybe_utf8(pTHX_ const char *const start, STRLEN len)
1962 SV * const sv = newSVpvn_utf8(start, len,
1965 && !is_ascii_string((const U8*)start, len)
1966 && is_utf8_string((const U8*)start, len));
1972 * When the lexer knows the next thing is a word (for instance, it has
1973 * just seen -> and it knows that the next char is a word char, then
1974 * it calls S_force_word to stick the next word into the PL_nexttoke/val
1978 * char *start : buffer position (must be within PL_linestr)
1979 * int token : PL_next* will be this type of bare word (e.g., METHOD,WORD)
1980 * int check_keyword : if true, Perl checks to make sure the word isn't
1981 * a keyword (do this if the word is a label, e.g. goto FOO)
1982 * int allow_pack : if true, : characters will also be allowed (require,
1983 * use, etc. do this)
1984 * int allow_initial_tick : used by the "sub" lexer only.
1988 S_force_word(pTHX_ char *start, int token, int check_keyword, int allow_pack)
1993 PERL_ARGS_ASSERT_FORCE_WORD;
1995 start = SKIPSPACE1(start);
1997 if (isIDFIRST_lazy_if(s,UTF) ||
1998 (allow_pack && *s == ':') )
2000 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
2001 if (check_keyword) {
2002 char *s2 = PL_tokenbuf;
2003 if (allow_pack && len > 6 && strnEQ(s2, "CORE::", 6))
2005 if (keyword(s2, len, 0))
2008 if (token == METHOD) {
2013 PL_expect = XOPERATOR;
2016 NEXTVAL_NEXTTOKE.opval
2017 = (OP*)newSVOP(OP_CONST,0,
2018 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
2019 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
2027 * Called when the lexer wants $foo *foo &foo etc, but the program
2028 * text only contains the "foo" portion. The first argument is a pointer
2029 * to the "foo", and the second argument is the type symbol to prefix.
2030 * Forces the next token to be a "WORD".
2031 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
2035 S_force_ident(pTHX_ const char *s, int kind)
2037 PERL_ARGS_ASSERT_FORCE_IDENT;
2040 const STRLEN len = s[1] ? strlen(s) : 1; /* s = "\"" see yylex */
2041 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn_flags(s, len,
2042 UTF ? SVf_UTF8 : 0));
2043 NEXTVAL_NEXTTOKE.opval = o;
2046 o->op_private = OPpCONST_ENTERED;
2047 /* XXX see note in pp_entereval() for why we forgo typo
2048 warnings if the symbol must be introduced in an eval.
2050 gv_fetchpvn_flags(s, len,
2051 (PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
2052 : GV_ADD) | ( UTF ? SVf_UTF8 : 0 ),
2053 kind == '$' ? SVt_PV :
2054 kind == '@' ? SVt_PVAV :
2055 kind == '%' ? SVt_PVHV :
2063 S_force_ident_maybe_lex(pTHX_ char pit)
2065 NEXTVAL_NEXTTOKE.ival = pit;
2070 Perl_str_to_version(pTHX_ SV *sv)
2075 const char *start = SvPV_const(sv,len);
2076 const char * const end = start + len;
2077 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
2079 PERL_ARGS_ASSERT_STR_TO_VERSION;
2081 while (start < end) {
2085 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
2090 retval += ((NV)n)/nshift;
2099 * Forces the next token to be a version number.
2100 * If the next token appears to be an invalid version number, (e.g. "v2b"),
2101 * and if "guessing" is TRUE, then no new token is created (and the caller
2102 * must use an alternative parsing method).
2106 S_force_version(pTHX_ char *s, int guessing)
2111 PERL_ARGS_ASSERT_FORCE_VERSION;
2119 while (isDIGIT(*d) || *d == '_' || *d == '.')
2121 if (*d == ';' || isSPACE(*d) || *d == '{' || *d == '}' || !*d) {
2123 s = scan_num(s, &pl_yylval);
2124 version = pl_yylval.opval;
2125 ver = cSVOPx(version)->op_sv;
2126 if (SvPOK(ver) && !SvNIOK(ver)) {
2127 SvUPGRADE(ver, SVt_PVNV);
2128 SvNV_set(ver, str_to_version(ver));
2129 SvNOK_on(ver); /* hint that it is a version */
2132 else if (guessing) {
2137 /* NOTE: The parser sees the package name and the VERSION swapped */
2138 NEXTVAL_NEXTTOKE.opval = version;
2145 * S_force_strict_version
2146 * Forces the next token to be a version number using strict syntax rules.
2150 S_force_strict_version(pTHX_ char *s)
2153 const char *errstr = NULL;
2155 PERL_ARGS_ASSERT_FORCE_STRICT_VERSION;
2157 while (isSPACE(*s)) /* leading whitespace */
2160 if (is_STRICT_VERSION(s,&errstr)) {
2162 s = (char *)scan_version(s, ver, 0);
2163 version = newSVOP(OP_CONST, 0, ver);
2165 else if ( (*s != ';' && *s != '{' && *s != '}' ) &&
2166 (s = SKIPSPACE1(s), (*s != ';' && *s != '{' && *s != '}' )))
2170 yyerror(errstr); /* version required */
2174 /* NOTE: The parser sees the package name and the VERSION swapped */
2175 NEXTVAL_NEXTTOKE.opval = version;
2183 * Tokenize a quoted string passed in as an SV. It finds the next
2184 * chunk, up to end of string or a backslash. It may make a new
2185 * SV containing that chunk (if HINT_NEW_STRING is on). It also
2190 S_tokeq(pTHX_ SV *sv)
2197 PERL_ARGS_ASSERT_TOKEQ;
2201 assert (!SvIsCOW(sv));
2202 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1) /* <<'heredoc' */
2206 /* This is relying on the SV being "well formed" with a trailing '\0' */
2207 while (s < send && !(*s == '\\' && s[1] == '\\'))
2212 if ( PL_hints & HINT_NEW_STRING ) {
2213 pv = newSVpvn_flags(SvPVX_const(pv), SvCUR(sv),
2214 SVs_TEMP | SvUTF8(sv));
2218 if (s + 1 < send && (s[1] == '\\'))
2219 s++; /* all that, just for this */
2224 SvCUR_set(sv, d - SvPVX_const(sv));
2226 if ( PL_hints & HINT_NEW_STRING )
2227 return new_constant(NULL, 0, "q", sv, pv, "q", 1);
2232 * Now come three functions related to double-quote context,
2233 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
2234 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
2235 * interact with PL_lex_state, and create fake ( ... ) argument lists
2236 * to handle functions and concatenation.
2240 * stringify ( const[foo] concat lcfirst ( const[bar] ) )
2245 * Assumes that pl_yylval.ival is the op we're creating (e.g. OP_LCFIRST).
2247 * Pattern matching will set PL_lex_op to the pattern-matching op to
2248 * make (we return THING if pl_yylval.ival is OP_NULL, PMFUNC otherwise).
2250 * OP_CONST and OP_READLINE are easy--just make the new op and return.
2252 * Everything else becomes a FUNC.
2254 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
2255 * had an OP_CONST or OP_READLINE). This just sets us up for a
2256 * call to S_sublex_push().
2260 S_sublex_start(pTHX)
2262 const I32 op_type = pl_yylval.ival;
2264 if (op_type == OP_NULL) {
2265 pl_yylval.opval = PL_lex_op;
2269 if (op_type == OP_CONST) {
2270 SV *sv = tokeq(PL_lex_stuff);
2272 if (SvTYPE(sv) == SVt_PVIV) {
2273 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
2275 const char * const p = SvPV_const(sv, len);
2276 SV * const nsv = newSVpvn_flags(p, len, SvUTF8(sv));
2280 pl_yylval.opval = (OP*)newSVOP(op_type, 0, sv);
2281 PL_lex_stuff = NULL;
2285 PL_sublex_info.super_state = PL_lex_state;
2286 PL_sublex_info.sub_inwhat = (U16)op_type;
2287 PL_sublex_info.sub_op = PL_lex_op;
2288 PL_lex_state = LEX_INTERPPUSH;
2292 pl_yylval.opval = PL_lex_op;
2302 * Create a new scope to save the lexing state. The scope will be
2303 * ended in S_sublex_done. Returns a '(', starting the function arguments
2304 * to the uc, lc, etc. found before.
2305 * Sets PL_lex_state to LEX_INTERPCONCAT.
2312 const bool is_heredoc = PL_multi_close == '<';
2315 PL_lex_state = PL_sublex_info.super_state;
2316 SAVEI8(PL_lex_dojoin);
2317 SAVEI32(PL_lex_brackets);
2318 SAVEI32(PL_lex_allbrackets);
2319 SAVEI32(PL_lex_formbrack);
2320 SAVEI8(PL_lex_fakeeof);
2321 SAVEI32(PL_lex_casemods);
2322 SAVEI32(PL_lex_starts);
2323 SAVEI8(PL_lex_state);
2324 SAVESPTR(PL_lex_repl);
2325 SAVEVPTR(PL_lex_inpat);
2326 SAVEI16(PL_lex_inwhat);
2329 SAVECOPLINE(PL_curcop);
2330 SAVEI32(PL_multi_end);
2331 SAVEI32(PL_parser->herelines);
2332 PL_parser->herelines = 0;
2334 SAVEI8(PL_multi_close);
2335 SAVEPPTR(PL_bufptr);
2336 SAVEPPTR(PL_bufend);
2337 SAVEPPTR(PL_oldbufptr);
2338 SAVEPPTR(PL_oldoldbufptr);
2339 SAVEPPTR(PL_last_lop);
2340 SAVEPPTR(PL_last_uni);
2341 SAVEPPTR(PL_linestart);
2342 SAVESPTR(PL_linestr);
2343 SAVEGENERICPV(PL_lex_brackstack);
2344 SAVEGENERICPV(PL_lex_casestack);
2345 SAVEGENERICPV(PL_parser->lex_shared);
2346 SAVEBOOL(PL_parser->lex_re_reparsing);
2347 SAVEI32(PL_copline);
2349 /* The here-doc parser needs to be able to peek into outer lexing
2350 scopes to find the body of the here-doc. So we put PL_linestr and
2351 PL_bufptr into lex_shared, to ‘share’ those values.
2353 PL_parser->lex_shared->ls_linestr = PL_linestr;
2354 PL_parser->lex_shared->ls_bufptr = PL_bufptr;
2356 PL_linestr = PL_lex_stuff;
2357 PL_lex_repl = PL_sublex_info.repl;
2358 PL_lex_stuff = NULL;
2359 PL_sublex_info.repl = NULL;
2361 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
2362 = SvPVX(PL_linestr);
2363 PL_bufend += SvCUR(PL_linestr);
2364 PL_last_lop = PL_last_uni = NULL;
2365 SAVEFREESV(PL_linestr);
2366 if (PL_lex_repl) SAVEFREESV(PL_lex_repl);
2368 PL_lex_dojoin = FALSE;
2369 PL_lex_brackets = PL_lex_formbrack = 0;
2370 PL_lex_allbrackets = 0;
2371 PL_lex_fakeeof = LEX_FAKEEOF_NEVER;
2372 Newx(PL_lex_brackstack, 120, char);
2373 Newx(PL_lex_casestack, 12, char);
2374 PL_lex_casemods = 0;
2375 *PL_lex_casestack = '\0';
2377 PL_lex_state = LEX_INTERPCONCAT;
2379 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
2380 PL_copline = NOLINE;
2382 Newxz(shared, 1, LEXSHARED);
2383 shared->ls_prev = PL_parser->lex_shared;
2384 PL_parser->lex_shared = shared;
2386 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
2387 if (PL_lex_inwhat == OP_TRANSR) PL_lex_inwhat = OP_TRANS;
2388 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
2389 PL_lex_inpat = PL_sublex_info.sub_op;
2391 PL_lex_inpat = NULL;
2393 PL_parser->lex_re_reparsing = cBOOL(PL_in_eval & EVAL_RE_REPARSING);
2394 PL_in_eval &= ~EVAL_RE_REPARSING;
2401 * Restores lexer state after a S_sublex_push.
2407 if (!PL_lex_starts++) {
2408 SV * const sv = newSVpvs("");
2409 if (SvUTF8(PL_linestr))
2411 PL_expect = XOPERATOR;
2412 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2416 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
2417 PL_lex_state = LEX_INTERPCASEMOD;
2421 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
2422 assert(PL_lex_inwhat != OP_TRANSR);
2424 assert (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS);
2425 PL_linestr = PL_lex_repl;
2427 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
2428 PL_bufend += SvCUR(PL_linestr);
2429 PL_last_lop = PL_last_uni = NULL;
2430 PL_lex_dojoin = FALSE;
2431 PL_lex_brackets = 0;
2432 PL_lex_allbrackets = 0;
2433 PL_lex_fakeeof = LEX_FAKEEOF_NEVER;
2434 PL_lex_casemods = 0;
2435 *PL_lex_casestack = '\0';
2437 if (SvEVALED(PL_lex_repl)) {
2438 PL_lex_state = LEX_INTERPNORMAL;
2440 /* we don't clear PL_lex_repl here, so that we can check later
2441 whether this is an evalled subst; that means we rely on the
2442 logic to ensure sublex_done() is called again only via the
2443 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
2446 PL_lex_state = LEX_INTERPCONCAT;
2449 if (SvTYPE(PL_linestr) >= SVt_PVNV) {
2450 CopLINE(PL_curcop) +=
2451 ((XPVNV*)SvANY(PL_linestr))->xnv_u.xpad_cop_seq.xlow
2452 + PL_parser->herelines;
2453 PL_parser->herelines = 0;
2458 const line_t l = CopLINE(PL_curcop);
2460 if (PL_multi_close == '<')
2461 PL_parser->herelines += l - PL_multi_end;
2462 PL_bufend = SvPVX(PL_linestr);
2463 PL_bufend += SvCUR(PL_linestr);
2464 PL_expect = XOPERATOR;
2465 PL_sublex_info.sub_inwhat = 0;
2470 PERL_STATIC_INLINE SV*
2471 S_get_and_check_backslash_N_name(pTHX_ const char* s, const char* const e)
2473 /* <s> points to first character of interior of \N{}, <e> to one beyond the
2474 * interior, hence to the "}". Finds what the name resolves to, returning
2475 * an SV* containing it; NULL if no valid one found */
2477 SV* res = newSVpvn_flags(s, e - s, UTF ? SVf_UTF8 : 0);
2484 const U8* first_bad_char_loc;
2485 const char* backslash_ptr = s - 3; /* Points to the <\> of \N{... */
2487 PERL_ARGS_ASSERT_GET_AND_CHECK_BACKSLASH_N_NAME;
2489 if (UTF && ! is_utf8_string_loc((U8 *) backslash_ptr,
2491 &first_bad_char_loc))
2493 /* If warnings are on, this will print a more detailed analysis of what
2494 * is wrong than the error message below */
2495 utf8n_to_uvchr(first_bad_char_loc,
2496 e - ((char *) first_bad_char_loc),
2499 /* We deliberately don't try to print the malformed character, which
2500 * might not print very well; it also may be just the first of many
2501 * malformations, so don't print what comes after it */
2502 yyerror(Perl_form(aTHX_
2503 "Malformed UTF-8 character immediately after '%.*s'",
2504 (int) (first_bad_char_loc - (U8 *) backslash_ptr), backslash_ptr));
2508 res = new_constant( NULL, 0, "charnames", res, NULL, backslash_ptr,
2509 /* include the <}> */
2510 e - backslash_ptr + 1);
2512 SvREFCNT_dec_NN(res);
2516 /* See if the charnames handler is the Perl core's, and if so, we can skip
2517 * the validation needed for a user-supplied one, as Perl's does its own
2519 table = GvHV(PL_hintgv); /* ^H */
2520 cvp = hv_fetchs(table, "charnames", FALSE);
2521 if (cvp && (cv = *cvp) && SvROK(cv) && (rv = SvRV(cv),
2522 SvTYPE(rv) == SVt_PVCV) && ((stash = CvSTASH(rv)) != NULL))
2524 const char * const name = HvNAME(stash);
2525 if (HvNAMELEN(stash) == sizeof("_charnames")-1
2526 && strEQ(name, "_charnames")) {
2531 /* Here, it isn't Perl's charname handler. We can't rely on a
2532 * user-supplied handler to validate the input name. For non-ut8 input,
2533 * look to see that the first character is legal. Then loop through the
2534 * rest checking that each is a continuation */
2536 /* This code makes the reasonable assumption that the only Latin1-range
2537 * characters that begin a character name alias are alphabetic, otherwise
2538 * would have to create a isCHARNAME_BEGIN macro */
2541 if (! isALPHAU(*s)) {
2546 if (! isCHARNAME_CONT(*s)) {
2549 if (*s == ' ' && *(s-1) == ' ') {
2552 if ((U8) *s == NBSP_NATIVE && ckWARN_d(WARN_DEPRECATED)) {
2553 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
2554 "NO-BREAK SPACE in a charnames "
2555 "alias definition is deprecated");
2561 /* Similarly for utf8. For invariants can check directly; for other
2562 * Latin1, can calculate their code point and check; otherwise use a
2564 if (UTF8_IS_INVARIANT(*s)) {
2565 if (! isALPHAU(*s)) {
2569 } else if (UTF8_IS_DOWNGRADEABLE_START(*s)) {
2570 if (! isALPHAU(TWO_BYTE_UTF8_TO_NATIVE(*s, *(s+1)))) {
2576 if (! PL_utf8_charname_begin) {
2577 U8 flags = _CORE_SWASH_INIT_ACCEPT_INVLIST;
2578 PL_utf8_charname_begin = _core_swash_init("utf8",
2579 "_Perl_Charname_Begin",
2581 1, 0, NULL, &flags);
2583 if (! swash_fetch(PL_utf8_charname_begin, (U8 *) s, TRUE)) {
2590 if (UTF8_IS_INVARIANT(*s)) {
2591 if (! isCHARNAME_CONT(*s)) {
2594 if (*s == ' ' && *(s-1) == ' ') {
2599 else if (UTF8_IS_DOWNGRADEABLE_START(*s)) {
2600 if (! isCHARNAME_CONT(TWO_BYTE_UTF8_TO_NATIVE(*s, *(s+1))))
2604 if (*s == *NBSP_UTF8
2605 && *(s+1) == *(NBSP_UTF8+1)
2606 && ckWARN_d(WARN_DEPRECATED))
2608 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
2609 "NO-BREAK SPACE in a charnames "
2610 "alias definition is deprecated");
2615 if (! PL_utf8_charname_continue) {
2616 U8 flags = _CORE_SWASH_INIT_ACCEPT_INVLIST;
2617 PL_utf8_charname_continue = _core_swash_init("utf8",
2618 "_Perl_Charname_Continue",
2620 1, 0, NULL, &flags);
2622 if (! swash_fetch(PL_utf8_charname_continue, (U8 *) s, TRUE)) {
2629 if (*(s-1) == ' ') {
2632 "charnames alias definitions may not contain trailing "
2633 "white-space; marked by <-- HERE in %.*s<-- HERE %.*s",
2634 (int)(s - backslash_ptr + 1), backslash_ptr,
2635 (int)(e - s + 1), s + 1
2637 UTF ? SVf_UTF8 : 0);
2641 if (SvUTF8(res)) { /* Don't accept malformed input */
2642 const U8* first_bad_char_loc;
2644 const char* const str = SvPV_const(res, len);
2645 if (! is_utf8_string_loc((U8 *) str, len, &first_bad_char_loc)) {
2646 /* If warnings are on, this will print a more detailed analysis of
2647 * what is wrong than the error message below */
2648 utf8n_to_uvchr(first_bad_char_loc,
2649 (char *) first_bad_char_loc - str,
2652 /* We deliberately don't try to print the malformed character,
2653 * which might not print very well; it also may be just the first
2654 * of many malformations, so don't print what comes after it */
2657 "Malformed UTF-8 returned by %.*s immediately after '%.*s'",
2658 (int) (e - backslash_ptr + 1), backslash_ptr,
2659 (int) ((char *) first_bad_char_loc - str), str
2670 /* The final %.*s makes sure that should the trailing NUL be missing
2671 * that this print won't run off the end of the string */
2674 "Invalid character in \\N{...}; marked by <-- HERE in %.*s<-- HERE %.*s",
2675 (int)(s - backslash_ptr + 1), backslash_ptr,
2676 (int)(e - s + 1), s + 1
2678 UTF ? SVf_UTF8 : 0);
2685 "charnames alias definitions may not contain a sequence of "
2686 "multiple spaces; marked by <-- HERE in %.*s<-- HERE %.*s",
2687 (int)(s - backslash_ptr + 1), backslash_ptr,
2688 (int)(e - s + 1), s + 1
2690 UTF ? SVf_UTF8 : 0);
2697 Extracts the next constant part of a pattern, double-quoted string,
2698 or transliteration. This is terrifying code.
2700 For example, in parsing the double-quoted string "ab\x63$d", it would
2701 stop at the '$' and return an OP_CONST containing 'abc'.
2703 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
2704 processing a pattern (PL_lex_inpat is true), a transliteration
2705 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
2707 Returns a pointer to the character scanned up to. If this is
2708 advanced from the start pointer supplied (i.e. if anything was
2709 successfully parsed), will leave an OP_CONST for the substring scanned
2710 in pl_yylval. Caller must intuit reason for not parsing further
2711 by looking at the next characters herself.
2715 \N{FOO} => \N{U+hex_for_character_FOO}
2716 (if FOO expands to multiple characters, expands to \N{U+xx.XX.yy ...})
2719 all other \-char, including \N and \N{ apart from \N{ABC}
2722 @ and $ where it appears to be a var, but not for $ as tail anchor
2727 In transliterations:
2728 characters are VERY literal, except for - not at the start or end
2729 of the string, which indicates a range. If the range is in bytes,
2730 scan_const expands the range to the full set of intermediate
2731 characters. If the range is in utf8, the hyphen is replaced with
2732 a certain range mark which will be handled by pmtrans() in op.c.
2734 In double-quoted strings:
2736 double-quoted style: \r and \n
2737 constants: \x31, etc.
2738 deprecated backrefs: \1 (in substitution replacements)
2739 case and quoting: \U \Q \E
2742 scan_const does *not* construct ops to handle interpolated strings.
2743 It stops processing as soon as it finds an embedded $ or @ variable
2744 and leaves it to the caller to work out what's going on.
2746 embedded arrays (whether in pattern or not) could be:
2747 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
2749 $ in double-quoted strings must be the symbol of an embedded scalar.
2751 $ in pattern could be $foo or could be tail anchor. Assumption:
2752 it's a tail anchor if $ is the last thing in the string, or if it's
2753 followed by one of "()| \r\n\t"
2755 \1 (backreferences) are turned into $1 in substitutions
2757 The structure of the code is
2758 while (there's a character to process) {
2759 handle transliteration ranges
2760 skip regexp comments /(?#comment)/ and codes /(?{code})/
2761 skip #-initiated comments in //x patterns
2762 check for embedded arrays
2763 check for embedded scalars
2765 deprecate \1 in substitution replacements
2766 handle string-changing backslashes \l \U \Q \E, etc.
2767 switch (what was escaped) {
2768 handle \- in a transliteration (becomes a literal -)
2769 if a pattern and not \N{, go treat as regular character
2770 handle \132 (octal characters)
2771 handle \x15 and \x{1234} (hex characters)
2772 handle \N{name} (named characters, also \N{3,5} in a pattern)
2773 handle \cV (control characters)
2774 handle printf-style backslashes (\f, \r, \n, etc)
2777 } (end if backslash)
2778 handle regular character
2779 } (end while character to read)
2784 S_scan_const(pTHX_ char *start)
2786 char *send = PL_bufend; /* end of the constant */
2787 SV *sv = newSV(send - start); /* sv for the constant. See note below
2789 char *s = start; /* start of the constant */
2790 char *d = SvPVX(sv); /* destination for copies */
2791 bool dorange = FALSE; /* are we in a translit range? */
2792 bool didrange = FALSE; /* did we just finish a range? */
2793 bool in_charclass = FALSE; /* within /[...]/ */
2794 bool has_utf8 = FALSE; /* Output constant is UTF8 */
2795 bool this_utf8 = cBOOL(UTF); /* Is the source string assumed to be
2796 UTF8? But, this can show as true
2797 when the source isn't utf8, as for
2798 example when it is entirely composed
2800 SV *res; /* result from charnames */
2802 /* Note on sizing: The scanned constant is placed into sv, which is
2803 * initialized by newSV() assuming one byte of output for every byte of
2804 * input. This routine expects newSV() to allocate an extra byte for a
2805 * trailing NUL, which this routine will append if it gets to the end of
2806 * the input. There may be more bytes of input than output (eg., \N{LATIN
2807 * CAPITAL LETTER A}), or more output than input if the constant ends up
2808 * recoded to utf8, but each time a construct is found that might increase
2809 * the needed size, SvGROW() is called. Its size parameter each time is
2810 * based on the best guess estimate at the time, namely the length used so
2811 * far, plus the length the current construct will occupy, plus room for
2812 * the trailing NUL, plus one byte for every input byte still unscanned */
2814 UV uv = UV_MAX; /* Initialize to weird value to try to catch any uses
2817 UV literal_endpoint = 0;
2818 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
2821 PERL_ARGS_ASSERT_SCAN_CONST;
2823 assert(PL_lex_inwhat != OP_TRANSR);
2824 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2825 /* If we are doing a trans and we know we want UTF8 set expectation */
2826 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
2827 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2830 /* Protect sv from errors and fatal warnings. */
2831 ENTER_with_name("scan_const");
2834 while (s < send || dorange) {
2836 /* get transliterations out of the way (they're most literal) */
2837 if (PL_lex_inwhat == OP_TRANS) {
2838 /* expand a range A-Z to the full set of characters. AIE! */
2840 I32 i; /* current expanded character */
2841 I32 min; /* first character in range */
2842 I32 max; /* last character in range */
2853 char * const c = (char*)utf8_hop((U8*)d, -1);
2857 *c = (char) ILLEGAL_UTF8_BYTE;
2858 /* mark the range as done, and continue */
2864 i = d - SvPVX_const(sv); /* remember current offset */
2867 SvLEN(sv) + ((has_utf8)
2868 ? (512 - UTF_CONTINUATION_MARK
2871 /* How many two-byte within 0..255: 128 in UTF-8,
2872 * 96 in UTF-8-mod. */
2874 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
2876 d = SvPVX(sv) + i; /* refresh d after realloc */
2880 for (j = 0; j <= 1; j++) {
2881 char * const c = (char*)utf8_hop((U8*)d, -1);
2882 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
2888 max = (U8)0xff; /* only to \xff */
2889 uvmax = uv; /* \x{100} to uvmax */
2891 d = c; /* eat endpoint chars */
2896 d -= 2; /* eat the first char and the - */
2897 min = (U8)*d; /* first char in range */
2898 max = (U8)d[1]; /* last char in range */
2905 "Invalid range \"%c-%c\" in transliteration operator",
2906 (char)min, (char)max);
2910 /* Because of the discontinuities in EBCDIC A-Z and a-z, expand
2911 * any subsets of these ranges into individual characters */
2912 if (literal_endpoint == 2 &&
2913 ((isLOWER_A(min) && isLOWER_A(max)) ||
2914 (isUPPER_A(min) && isUPPER_A(max))))
2916 for (i = min; i <= max; i++) {
2923 for (i = min; i <= max; i++)
2926 append_utf8_from_native_byte(i, &d);
2934 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
2936 *d++ = (char) ILLEGAL_UTF8_BYTE;
2938 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
2942 /* mark the range as done, and continue */
2946 literal_endpoint = 0;
2951 /* range begins (ignore - as first or last char) */
2952 else if (*s == '-' && s+1 < send && s != start) {
2954 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
2961 *d++ = (char) ILLEGAL_UTF8_BYTE; /* use illegal utf8 byte--see pmtrans */
2971 literal_endpoint = 0;
2972 native_range = TRUE;
2977 /* if we get here, we're not doing a transliteration */
2979 else if (*s == '[' && PL_lex_inpat && !in_charclass) {
2982 while (s1 >= start && *s1-- == '\\')
2985 in_charclass = TRUE;
2988 else if (*s == ']' && PL_lex_inpat && in_charclass) {
2991 while (s1 >= start && *s1-- == '\\')
2994 in_charclass = FALSE;
2997 /* skip for regexp comments /(?#comment)/, except for the last
2998 * char, which will be done separately.
2999 * Stop on (?{..}) and friends */
3001 else if (*s == '(' && PL_lex_inpat && s[1] == '?' && !in_charclass) {
3003 while (s+1 < send && *s != ')')
3006 else if (!PL_lex_casemods &&
3007 ( s[2] == '{' /* This should match regcomp.c */
3008 || (s[2] == '?' && s[3] == '{')))
3014 /* likewise skip #-initiated comments in //x patterns */
3015 else if (*s == '#' && PL_lex_inpat && !in_charclass &&
3016 ((PMOP*)PL_lex_inpat)->op_pmflags & RXf_PMf_EXTENDED) {
3017 while (s+1 < send && *s != '\n')
3021 /* no further processing of single-quoted regex */
3022 else if (PL_lex_inpat && SvIVX(PL_linestr) == '\'')
3023 goto default_action;
3025 /* check for embedded arrays
3026 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
3028 else if (*s == '@' && s[1]) {
3029 if (isWORDCHAR_lazy_if(s+1,UTF))
3031 if (strchr(":'{$", s[1]))
3033 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
3034 break; /* in regexp, neither @+ nor @- are interpolated */
3037 /* check for embedded scalars. only stop if we're sure it's a
3040 else if (*s == '$') {
3041 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
3043 if (s + 1 < send && !strchr("()| \r\n\t", s[1])) {
3045 Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
3046 "Possible unintended interpolation of $\\ in regex");
3048 break; /* in regexp, $ might be tail anchor */
3052 /* End of else if chain - OP_TRANS rejoin rest */
3055 if (*s == '\\' && s+1 < send) {
3056 char* e; /* Can be used for ending '}', etc. */
3060 /* warn on \1 - \9 in substitution replacements, but note that \11
3061 * is an octal; and \19 is \1 followed by '9' */
3062 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
3063 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
3065 /* diag_listed_as: \%d better written as $%d */
3066 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
3071 /* string-change backslash escapes */
3072 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQF", *s)) {
3076 /* In a pattern, process \N, but skip any other backslash escapes.
3077 * This is because we don't want to translate an escape sequence
3078 * into a meta symbol and have the regex compiler use the meta
3079 * symbol meaning, e.g. \x{2E} would be confused with a dot. But
3080 * in spite of this, we do have to process \N here while the proper
3081 * charnames handler is in scope. See bugs #56444 and #62056.
3082 * There is a complication because \N in a pattern may also stand
3083 * for 'match a non-nl', and not mean a charname, in which case its
3084 * processing should be deferred to the regex compiler. To be a
3085 * charname it must be followed immediately by a '{', and not look
3086 * like \N followed by a curly quantifier, i.e., not something like
3087 * \N{3,}. regcurly returns a boolean indicating if it is a legal
3089 else if (PL_lex_inpat
3092 || regcurly(s + 1)))
3095 goto default_action;
3100 /* quoted - in transliterations */
3102 if (PL_lex_inwhat == OP_TRANS) {
3109 if ((isALPHANUMERIC(*s)))
3110 Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
3111 "Unrecognized escape \\%c passed through",
3113 /* default action is to copy the quoted character */
3114 goto default_action;
3117 /* eg. \132 indicates the octal constant 0132 */
3118 case '0': case '1': case '2': case '3':
3119 case '4': case '5': case '6': case '7':
3121 I32 flags = PERL_SCAN_SILENT_ILLDIGIT;
3123 uv = grok_oct(s, &len, &flags, NULL);
3125 if (len < 3 && s < send && isDIGIT(*s)
3126 && ckWARN(WARN_MISC))
3128 Perl_warner(aTHX_ packWARN(WARN_MISC),
3129 "%s", form_short_octal_warning(s, len));
3132 goto NUM_ESCAPE_INSERT;
3134 /* eg. \o{24} indicates the octal constant \024 */
3139 bool valid = grok_bslash_o(&s, &uv, &error,
3140 TRUE, /* Output warning */
3141 FALSE, /* Not strict */
3142 TRUE, /* Output warnings for
3149 goto NUM_ESCAPE_INSERT;
3152 /* eg. \x24 indicates the hex constant 0x24 */
3157 bool valid = grok_bslash_x(&s, &uv, &error,
3158 TRUE, /* Output warning */
3159 FALSE, /* Not strict */
3160 TRUE, /* Output warnings for
3170 /* Insert oct or hex escaped character. There will always be
3171 * enough room in sv since such escapes will be longer than any
3172 * UTF-8 sequence they can end up as, except if they force us
3173 * to recode the rest of the string into utf8 */
3175 /* Here uv is the ordinal of the next character being added */
3176 if (!UVCHR_IS_INVARIANT(uv)) {
3177 if (!has_utf8 && uv > 255) {
3178 /* Might need to recode whatever we have accumulated so
3179 * far if it contains any chars variant in utf8 or
3182 SvCUR_set(sv, d - SvPVX_const(sv));
3185 /* See Note on sizing above. */
3186 sv_utf8_upgrade_flags_grow(sv,
3187 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3188 UNISKIP(uv) + (STRLEN)(send - s) + 1);
3189 d = SvPVX(sv) + SvCUR(sv);
3194 d = (char*)uvchr_to_utf8((U8*)d, uv);
3195 if (PL_lex_inwhat == OP_TRANS &&
3196 PL_sublex_info.sub_op) {
3197 PL_sublex_info.sub_op->op_private |=
3198 (PL_lex_repl ? OPpTRANS_FROM_UTF
3202 if (uv > 255 && !dorange)
3203 native_range = FALSE;
3216 /* In a non-pattern \N must be a named character, like \N{LATIN
3217 * SMALL LETTER A} or \N{U+0041}. For patterns, it also can
3218 * mean to match a non-newline. For non-patterns, named
3219 * characters are converted to their string equivalents. In
3220 * patterns, named characters are not converted to their
3221 * ultimate forms for the same reasons that other escapes
3222 * aren't. Instead, they are converted to the \N{U+...} form
3223 * to get the value from the charnames that is in effect right
3224 * now, while preserving the fact that it was a named character
3225 * so that the regex compiler knows this */
3227 /* The structure of this section of code (besides checking for
3228 * errors and upgrading to utf8) is:
3229 * Further disambiguate between the two meanings of \N, and if
3230 * not a charname, go process it elsewhere
3231 * If of form \N{U+...}, pass it through if a pattern;
3232 * otherwise convert to utf8
3233 * Otherwise must be \N{NAME}: convert to \N{U+c1.c2...} if a
3234 * pattern; otherwise convert to utf8 */
3236 /* Here, s points to the 'N'; the test below is guaranteed to
3237 * succeed if we are being called on a pattern as we already
3238 * know from a test above that the next character is a '{'.
3239 * On a non-pattern \N must mean 'named sequence, which
3240 * requires braces */
3243 yyerror("Missing braces on \\N{}");
3248 /* If there is no matching '}', it is an error. */
3249 if (! (e = strchr(s, '}'))) {
3250 if (! PL_lex_inpat) {
3251 yyerror("Missing right brace on \\N{}");
3253 yyerror("Missing right brace on \\N{} or unescaped left brace after \\N");
3258 /* Here it looks like a named character */
3260 if (*s == 'U' && s[1] == '+') { /* \N{U+...} */
3261 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES
3262 | PERL_SCAN_DISALLOW_PREFIX;
3265 /* For \N{U+...}, the '...' is a unicode value even on
3266 * EBCDIC machines */
3267 s += 2; /* Skip to next char after the 'U+' */
3269 uv = grok_hex(s, &len, &flags, NULL);
3270 if (len == 0 || len != (STRLEN)(e - s)) {
3271 yyerror("Invalid hexadecimal number in \\N{U+...}");
3278 /* On non-EBCDIC platforms, pass through to the regex
3279 * compiler unchanged. The reason we evaluated the
3280 * number above is to make sure there wasn't a syntax
3281 * error. But on EBCDIC we convert to native so
3282 * downstream code can continue to assume it's native
3284 s -= 5; /* Include the '\N{U+' */
3286 d += my_snprintf(d, e - s + 1 + 1, /* includes the }
3289 (unsigned int) UNI_TO_NATIVE(uv));
3291 Copy(s, d, e - s + 1, char); /* 1 = include the } */
3295 else { /* Not a pattern: convert the hex to string */
3297 /* If destination is not in utf8, unconditionally
3298 * recode it to be so. This is because \N{} implies
3299 * Unicode semantics, and scalars have to be in utf8
3300 * to guarantee those semantics */
3302 SvCUR_set(sv, d - SvPVX_const(sv));
3305 /* See Note on sizing above. */
3306 sv_utf8_upgrade_flags_grow(
3308 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3309 UNISKIP(uv) + (STRLEN)(send - e) + 1);
3310 d = SvPVX(sv) + SvCUR(sv);
3314 /* Add the (Unicode) code point to the output. */
3315 if (UNI_IS_INVARIANT(uv)) {
3316 *d++ = (char) LATIN1_TO_NATIVE(uv);
3319 d = (char*) uvoffuni_to_utf8_flags((U8*)d, uv, 0);
3323 else /* Here is \N{NAME} but not \N{U+...}. */
3324 if ((res = get_and_check_backslash_N_name(s, e)))
3327 const char *str = SvPV_const(res, len);
3330 if (! len) { /* The name resolved to an empty string */
3331 Copy("\\N{}", d, 4, char);
3335 /* In order to not lose information for the regex
3336 * compiler, pass the result in the specially made
3337 * syntax: \N{U+c1.c2.c3...}, where c1 etc. are
3338 * the code points in hex of each character
3339 * returned by charnames */
3341 const char *str_end = str + len;
3342 const STRLEN off = d - SvPVX_const(sv);
3344 if (! SvUTF8(res)) {
3345 /* For the non-UTF-8 case, we can determine the
3346 * exact length needed without having to parse
3347 * through the string. Each character takes up
3348 * 2 hex digits plus either a trailing dot or
3350 d = off + SvGROW(sv, off
3352 + 6 /* For the "\N{U+", and
3354 + (STRLEN)(send - e));
3355 Copy("\\N{U+", d, 5, char);
3357 while (str < str_end) {
3360 my_snprintf(hex_string,
3362 "%02X.", (U8) *str);
3363 PERL_MY_SNPRINTF_POST_GUARD(len, sizeof(hex_string));
3364 Copy(hex_string, d, 3, char);
3368 d--; /* We will overwrite below the final
3369 dot with a right brace */
3372 STRLEN char_length; /* cur char's byte length */
3374 /* and the number of bytes after this is
3375 * translated into hex digits */
3376 STRLEN output_length;
3378 /* 2 hex per byte; 2 chars for '\N'; 2 chars
3379 * for max('U+', '.'); and 1 for NUL */
3380 char hex_string[2 * UTF8_MAXBYTES + 5];
3382 /* Get the first character of the result. */
3383 U32 uv = utf8n_to_uvchr((U8 *) str,
3387 /* Convert first code point to hex, including
3388 * the boiler plate before it. */
3390 my_snprintf(hex_string, sizeof(hex_string),
3394 /* Make sure there is enough space to hold it */
3395 d = off + SvGROW(sv, off
3397 + (STRLEN)(send - e)
3398 + 2); /* '}' + NUL */
3400 Copy(hex_string, d, output_length, char);
3403 /* For each subsequent character, append dot and
3404 * its ordinal in hex */
3405 while ((str += char_length) < str_end) {
3406 const STRLEN off = d - SvPVX_const(sv);
3407 U32 uv = utf8n_to_uvchr((U8 *) str,
3412 my_snprintf(hex_string,
3417 d = off + SvGROW(sv, off
3419 + (STRLEN)(send - e)
3420 + 2); /* '}' + NUL */
3421 Copy(hex_string, d, output_length, char);
3426 *d++ = '}'; /* Done. Add the trailing brace */
3429 else { /* Here, not in a pattern. Convert the name to a
3432 /* If destination is not in utf8, unconditionally
3433 * recode it to be so. This is because \N{} implies
3434 * Unicode semantics, and scalars have to be in utf8
3435 * to guarantee those semantics */
3437 SvCUR_set(sv, d - SvPVX_const(sv));
3440 /* See Note on sizing above. */
3441 sv_utf8_upgrade_flags_grow(sv,
3442 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3443 len + (STRLEN)(send - s) + 1);
3444 d = SvPVX(sv) + SvCUR(sv);
3446 } else if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
3448 /* See Note on sizing above. (NOTE: SvCUR() is not
3449 * set correctly here). */
3450 const STRLEN off = d - SvPVX_const(sv);
3451 d = off + SvGROW(sv, off + len + (STRLEN)(send - s) + 1);
3453 if (! SvUTF8(res)) { /* Make sure is \N{} return is UTF-8 */
3454 sv_utf8_upgrade(res);
3455 str = SvPV_const(res, len);
3457 Copy(str, d, len, char);
3463 } /* End \N{NAME} */
3466 native_range = FALSE; /* \N{} is defined to be Unicode */
3468 s = e + 1; /* Point to just after the '}' */
3471 /* \c is a control character */
3475 *d++ = grok_bslash_c(*s++, 1);
3478 yyerror("Missing control char name in \\c");
3482 /* printf-style backslashes, formfeeds, newlines, etc */
3499 *d++ = ASCII_TO_NATIVE('\033');
3508 } /* end if (backslash) */
3515 /* If we started with encoded form, or already know we want it,
3516 then encode the next character */
3517 if (! NATIVE_BYTE_IS_INVARIANT((U8)(*s)) && (this_utf8 || has_utf8)) {
3521 /* One might think that it is wasted effort in the case of the
3522 * source being utf8 (this_utf8 == TRUE) to take the next character
3523 * in the source, convert it to an unsigned value, and then convert
3524 * it back again. But the source has not been validated here. The
3525 * routine that does the conversion checks for errors like
3528 const UV nextuv = (this_utf8)
3529 ? utf8n_to_uvchr((U8*)s, send - s, &len, 0)
3531 const STRLEN need = UNISKIP(nextuv);
3533 SvCUR_set(sv, d - SvPVX_const(sv));
3536 /* See Note on sizing above. */
3537 sv_utf8_upgrade_flags_grow(sv,
3538 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3539 need + (STRLEN)(send - s) + 1);
3540 d = SvPVX(sv) + SvCUR(sv);
3542 } else if (need > len) {
3543 /* encoded value larger than old, may need extra space (NOTE:
3544 * SvCUR() is not set correctly here). See Note on sizing
3546 const STRLEN off = d - SvPVX_const(sv);
3547 d = SvGROW(sv, off + need + (STRLEN)(send - s) + 1) + off;
3551 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
3553 if (uv > 255 && !dorange)
3554 native_range = FALSE;
3560 } /* while loop to process each character */
3562 /* terminate the string and set up the sv */
3564 SvCUR_set(sv, d - SvPVX_const(sv));
3565 if (SvCUR(sv) >= SvLEN(sv))
3566 Perl_croak(aTHX_ "panic: constant overflowed allocated space, %"UVuf
3567 " >= %"UVuf, (UV)SvCUR(sv), (UV)SvLEN(sv));
3570 if (PL_encoding && !has_utf8) {
3571 sv_recode_to_utf8(sv, PL_encoding);
3577 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
3578 PL_sublex_info.sub_op->op_private |=
3579 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
3583 /* shrink the sv if we allocated more than we used */
3584 if (SvCUR(sv) + 5 < SvLEN(sv)) {
3585 SvPV_shrink_to_cur(sv);
3588 /* return the substring (via pl_yylval) only if we parsed anything */
3591 for (; s2 < s; s2++) {
3593 COPLINE_INC_WITH_HERELINES;
3595 SvREFCNT_inc_simple_void_NN(sv);
3596 if ( (PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ))
3597 && ! PL_parser->lex_re_reparsing)
3599 const char *const key = PL_lex_inpat ? "qr" : "q";
3600 const STRLEN keylen = PL_lex_inpat ? 2 : 1;
3604 if (PL_lex_inwhat == OP_TRANS) {
3607 } else if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) {
3610 } else if (PL_lex_inpat && SvIVX(PL_linestr) == '\'') {
3618 sv = S_new_constant(aTHX_ start, s - start, key, keylen, sv, NULL,
3621 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3623 LEAVE_with_name("scan_const");
3628 * Returns TRUE if there's more to the expression (e.g., a subscript),
3631 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
3633 * ->[ and ->{ return TRUE
3634 * ->$* ->$#* ->@* ->@[ ->@{ return TRUE if postderef_qq is enabled
3635 * { and [ outside a pattern are always subscripts, so return TRUE
3636 * if we're outside a pattern and it's not { or [, then return FALSE
3637 * if we're in a pattern and the first char is a {
3638 * {4,5} (any digits around the comma) returns FALSE
3639 * if we're in a pattern and the first char is a [
3641 * [SOMETHING] has a funky algorithm to decide whether it's a
3642 * character class or not. It has to deal with things like
3643 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
3644 * anything else returns TRUE
3647 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
3650 S_intuit_more(pTHX_ char *s)
3652 PERL_ARGS_ASSERT_INTUIT_MORE;
3654 if (PL_lex_brackets)
3656 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
3658 if (*s == '-' && s[1] == '>'
3659 && FEATURE_POSTDEREF_QQ_IS_ENABLED
3660 && ( (s[2] == '$' && (s[3] == '*' || (s[3] == '#' && s[4] == '*')))
3661 ||(s[2] == '@' && strchr("*[{",s[3])) ))
3663 if (*s != '{' && *s != '[')
3668 /* In a pattern, so maybe we have {n,m}. */
3676 /* On the other hand, maybe we have a character class */
3679 if (*s == ']' || *s == '^')
3682 /* this is terrifying, and it works */
3685 const char * const send = strchr(s,']');
3686 unsigned char un_char, last_un_char;
3687 char tmpbuf[sizeof PL_tokenbuf * 4];
3689 if (!send) /* has to be an expression */
3691 weight = 2; /* let's weigh the evidence */
3695 else if (isDIGIT(*s)) {
3697 if (isDIGIT(s[1]) && s[2] == ']')
3703 Zero(seen,256,char);
3705 for (; s < send; s++) {
3706 last_un_char = un_char;
3707 un_char = (unsigned char)*s;
3712 weight -= seen[un_char] * 10;
3713 if (isWORDCHAR_lazy_if(s+1,UTF)) {
3715 char *tmp = PL_bufend;
3716 PL_bufend = (char*)send;
3717 scan_ident(s, tmpbuf, sizeof tmpbuf, FALSE);
3719 len = (int)strlen(tmpbuf);
3720 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len,
3721 UTF ? SVf_UTF8 : 0, SVt_PV))
3726 else if (*s == '$' && s[1] &&
3727 strchr("[#!%*<>()-=",s[1])) {
3728 if (/*{*/ strchr("])} =",s[2]))
3737 if (strchr("wds]",s[1]))
3739 else if (seen[(U8)'\''] || seen[(U8)'"'])
3741 else if (strchr("rnftbxcav",s[1]))
3743 else if (isDIGIT(s[1])) {
3745 while (s[1] && isDIGIT(s[1]))
3755 if (strchr("aA01! ",last_un_char))
3757 if (strchr("zZ79~",s[1]))
3759 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
3760 weight -= 5; /* cope with negative subscript */
3763 if (!isWORDCHAR(last_un_char)
3764 && !(last_un_char == '$' || last_un_char == '@'
3765 || last_un_char == '&')
3766 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
3771 if (keyword(tmpbuf, d - tmpbuf, 0))
3774 if (un_char == last_un_char + 1)
3776 weight -= seen[un_char];
3781 if (weight >= 0) /* probably a character class */
3791 * Does all the checking to disambiguate
3793 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
3794 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
3796 * First argument is the stuff after the first token, e.g. "bar".
3798 * Not a method if foo is a filehandle.
3799 * Not a method if foo is a subroutine prototyped to take a filehandle.
3800 * Not a method if it's really "Foo $bar"
3801 * Method if it's "foo $bar"
3802 * Not a method if it's really "print foo $bar"
3803 * Method if it's really "foo package::" (interpreted as package->foo)
3804 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
3805 * Not a method if bar is a filehandle or package, but is quoted with
3810 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
3812 char *s = start + (*start == '$');
3813 char tmpbuf[sizeof PL_tokenbuf];
3817 PERL_ARGS_ASSERT_INTUIT_METHOD;
3819 if (gv && SvTYPE(gv) == SVt_PVGV && GvIO(gv))
3821 if (cv && SvPOK(cv)) {
3822 const char *proto = CvPROTO(cv);
3824 while (*proto && (isSPACE(*proto) || *proto == ';'))
3831 if (*start == '$') {
3832 if (cv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY ||
3833 isUPPER(*PL_tokenbuf))
3838 return *s == '(' ? FUNCMETH : METHOD;
3841 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3842 /* start is the beginning of the possible filehandle/object,
3843 * and s is the end of it
3844 * tmpbuf is a copy of it (but with single quotes as double colons)
3847 if (!keyword(tmpbuf, len, 0)) {
3848 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
3853 indirgv = gv_fetchpvn_flags(tmpbuf, len, ( UTF ? SVf_UTF8 : 0 ), SVt_PVCV);
3854 if (indirgv && GvCVu(indirgv))
3856 /* filehandle or package name makes it a method */
3857 if (!cv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, UTF ? SVf_UTF8 : 0)) {
3859 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
3860 return 0; /* no assumptions -- "=>" quotes bareword */
3862 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
3863 S_newSV_maybe_utf8(aTHX_ tmpbuf, len));
3864 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
3868 return *s == '(' ? FUNCMETH : METHOD;
3874 /* Encoded script support. filter_add() effectively inserts a
3875 * 'pre-processing' function into the current source input stream.
3876 * Note that the filter function only applies to the current source file
3877 * (e.g., it will not affect files 'require'd or 'use'd by this one).
3879 * The datasv parameter (which may be NULL) can be used to pass
3880 * private data to this instance of the filter. The filter function
3881 * can recover the SV using the FILTER_DATA macro and use it to
3882 * store private buffers and state information.
3884 * The supplied datasv parameter is upgraded to a PVIO type
3885 * and the IoDIRP/IoANY field is used to store the function pointer,
3886 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
3887 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
3888 * private use must be set using malloc'd pointers.
3892 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
3900 if (PL_parser->lex_flags & LEX_IGNORE_UTF8_HINTS)
3901 Perl_croak(aTHX_ "Source filters apply only to byte streams");
3903 if (!PL_rsfp_filters)
3904 PL_rsfp_filters = newAV();
3907 SvUPGRADE(datasv, SVt_PVIO);
3908 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
3909 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
3910 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
3911 FPTR2DPTR(void *, IoANY(datasv)),
3912 SvPV_nolen(datasv)));
3913 av_unshift(PL_rsfp_filters, 1);
3914 av_store(PL_rsfp_filters, 0, datasv) ;
3916 !PL_parser->filtered
3917 && PL_parser->lex_flags & LEX_EVALBYTES
3918 && PL_bufptr < PL_bufend
3920 const char *s = PL_bufptr;
3921 while (s < PL_bufend) {
3923 SV *linestr = PL_parser->linestr;
3924 char *buf = SvPVX(linestr);
3925 STRLEN const bufptr_pos = PL_parser->bufptr - buf;
3926 STRLEN const oldbufptr_pos = PL_parser->oldbufptr - buf;
3927 STRLEN const oldoldbufptr_pos=PL_parser->oldoldbufptr-buf;
3928 STRLEN const linestart_pos = PL_parser->linestart - buf;
3929 STRLEN const last_uni_pos =
3930 PL_parser->last_uni ? PL_parser->last_uni - buf : 0;
3931 STRLEN const last_lop_pos =
3932 PL_parser->last_lop ? PL_parser->last_lop - buf : 0;
3933 av_push(PL_rsfp_filters, linestr);
3934 PL_parser->linestr =
3935 newSVpvn(SvPVX(linestr), ++s-SvPVX(linestr));
3936 buf = SvPVX(PL_parser->linestr);
3937 PL_parser->bufend = buf + SvCUR(PL_parser->linestr);
3938 PL_parser->bufptr = buf + bufptr_pos;
3939 PL_parser->oldbufptr = buf + oldbufptr_pos;
3940 PL_parser->oldoldbufptr = buf + oldoldbufptr_pos;
3941 PL_parser->linestart = buf + linestart_pos;
3942 if (PL_parser->last_uni)
3943 PL_parser->last_uni = buf + last_uni_pos;
3944 if (PL_parser->last_lop)
3945 PL_parser->last_lop = buf + last_lop_pos;
3946 SvLEN(linestr) = SvCUR(linestr);
3947 SvCUR(linestr) = s-SvPVX(linestr);
3948 PL_parser->filtered = 1;
3958 /* Delete most recently added instance of this filter function. */
3960 Perl_filter_del(pTHX_ filter_t funcp)
3964 PERL_ARGS_ASSERT_FILTER_DEL;
3967 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
3968 FPTR2DPTR(void*, funcp)));
3970 if (!PL_parser || !PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
3972 /* if filter is on top of stack (usual case) just pop it off */
3973 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
3974 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
3975 sv_free(av_pop(PL_rsfp_filters));
3979 /* we need to search for the correct entry and clear it */
3980 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
3984 /* Invoke the idxth filter function for the current rsfp. */
3985 /* maxlen 0 = read one text line */
3987 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
3991 /* This API is bad. It should have been using unsigned int for maxlen.
3992 Not sure if we want to change the API, but if not we should sanity
3993 check the value here. */
3994 unsigned int correct_length = maxlen < 0 ? PERL_INT_MAX : maxlen;
3996 PERL_ARGS_ASSERT_FILTER_READ;
3998 if (!PL_parser || !PL_rsfp_filters)
4000 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
4001 /* Provide a default input filter to make life easy. */
4002 /* Note that we append to the line. This is handy. */
4003 DEBUG_P(PerlIO_printf(Perl_debug_log,
4004 "filter_read %d: from rsfp\n", idx));
4005 if (correct_length) {
4008 const int old_len = SvCUR(buf_sv);
4010 /* ensure buf_sv is large enough */
4011 SvGROW(buf_sv, (STRLEN)(old_len + correct_length + 1)) ;
4012 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
4013 correct_length)) <= 0) {
4014 if (PerlIO_error(PL_rsfp))
4015 return -1; /* error */
4017 return 0 ; /* end of file */
4019 SvCUR_set(buf_sv, old_len + len) ;
4020 SvPVX(buf_sv)[old_len + len] = '\0';
4023 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
4024 if (PerlIO_error(PL_rsfp))
4025 return -1; /* error */
4027 return 0 ; /* end of file */
4030 return SvCUR(buf_sv);
4032 /* Skip this filter slot if filter has been deleted */
4033 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
4034 DEBUG_P(PerlIO_printf(Perl_debug_log,
4035 "filter_read %d: skipped (filter deleted)\n",
4037 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
4039 if (SvTYPE(datasv) != SVt_PVIO) {
4040 if (correct_length) {
4042 const STRLEN remainder = SvLEN(datasv) - SvCUR(datasv);
4043 if (!remainder) return 0; /* eof */
4044 if (correct_length > remainder) correct_length = remainder;
4045 sv_catpvn(buf_sv, SvEND(datasv), correct_length);
4046 SvCUR_set(datasv, SvCUR(datasv) + correct_length);
4049 const char *s = SvEND(datasv);
4050 const char *send = SvPVX(datasv) + SvLEN(datasv);
4058 if (s == send) return 0; /* eof */
4059 sv_catpvn(buf_sv, SvEND(datasv), s-SvEND(datasv));
4060 SvCUR_set(datasv, s-SvPVX(datasv));
4062 return SvCUR(buf_sv);
4064 /* Get function pointer hidden within datasv */
4065 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
4066 DEBUG_P(PerlIO_printf(Perl_debug_log,
4067 "filter_read %d: via function %p (%s)\n",
4068 idx, (void*)datasv, SvPV_nolen_const(datasv)));
4069 /* Call function. The function is expected to */
4070 /* call "FILTER_READ(idx+1, buf_sv)" first. */
4071 /* Return: <0:error, =0:eof, >0:not eof */
4072 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
4076 S_filter_gets(pTHX_ SV *sv, STRLEN append)
4078 PERL_ARGS_ASSERT_FILTER_GETS;
4080 #ifdef PERL_CR_FILTER
4081 if (!PL_rsfp_filters) {
4082 filter_add(S_cr_textfilter,NULL);
4085 if (PL_rsfp_filters) {
4087 SvCUR_set(sv, 0); /* start with empty line */
4088 if (FILTER_READ(0, sv, 0) > 0)
4089 return ( SvPVX(sv) ) ;
4094 return (sv_gets(sv, PL_rsfp, append));
4098 S_find_in_my_stash(pTHX_ const char *pkgname, STRLEN len)
4102 PERL_ARGS_ASSERT_FIND_IN_MY_STASH;
4104 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
4108 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
4109 (gv = gv_fetchpvn_flags(pkgname, len, ( UTF ? SVf_UTF8 : 0 ), SVt_PVHV)))
4111 return GvHV(gv); /* Foo:: */
4114 /* use constant CLASS => 'MyClass' */
4115 gv = gv_fetchpvn_flags(pkgname, len, UTF ? SVf_UTF8 : 0, SVt_PVCV);
4116 if (gv && GvCV(gv)) {
4117 SV * const sv = cv_const_sv(GvCV(gv));
4119 pkgname = SvPV_const(sv, len);
4122 return gv_stashpvn(pkgname, len, UTF ? SVf_UTF8 : 0);
4127 S_tokenize_use(pTHX_ int is_use, char *s) {
4128 PERL_ARGS_ASSERT_TOKENIZE_USE;
4130 if (PL_expect != XSTATE)
4131 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
4132 is_use ? "use" : "no"));
4135 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
4136 s = force_version(s, TRUE);
4137 if (*s == ';' || *s == '}'
4138 || (s = SKIPSPACE1(s), (*s == ';' || *s == '}'))) {
4139 NEXTVAL_NEXTTOKE.opval = NULL;
4142 else if (*s == 'v') {
4143 s = force_word(s,WORD,FALSE,TRUE);
4144 s = force_version(s, FALSE);
4148 s = force_word(s,WORD,FALSE,TRUE);
4149 s = force_version(s, FALSE);
4151 pl_yylval.ival = is_use;
4155 static const char* const exp_name[] =
4156 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
4157 "ATTRTERM", "TERMBLOCK", "XBLOCKTERM", "POSTDEREF",
4162 #define word_takes_any_delimeter(p,l) S_word_takes_any_delimeter(p,l)
4164 S_word_takes_any_delimeter(char *p, STRLEN len)
4166 return (len == 1 && strchr("msyq", p[0])) ||
4168 (p[0] == 't' && p[1] == 'r') ||
4169 (p[0] == 'q' && strchr("qwxr", p[1]))));
4173 S_check_scalar_slice(pTHX_ char *s)
4176 while (*s == ' ' || *s == '\t') s++;
4177 if (*s == 'q' && s[1] == 'w'
4178 && !isWORDCHAR_lazy_if(s+2,UTF))
4180 while (*s && (isWORDCHAR_lazy_if(s,UTF) || strchr(" \t$#+-'\"", *s)))
4181 s += UTF ? UTF8SKIP(s) : 1;
4182 if (*s == '}' || *s == ']')
4183 pl_yylval.ival = OPpSLICEWARNING;
4189 Works out what to call the token just pulled out of the input
4190 stream. The yacc parser takes care of taking the ops we return and
4191 stitching them into a tree.
4194 The type of the next token
4197 Switch based on the current state:
4198 - if we already built the token before, use it
4199 - if we have a case modifier in a string, deal with that
4200 - handle other cases of interpolation inside a string
4201 - scan the next line if we are inside a format
4202 In the normal state switch on the next character:
4204 if alphabetic, go to key lookup
4205 unrecoginized character - croak
4206 - 0/4/26: handle end-of-line or EOF
4207 - cases for whitespace
4208 - \n and #: handle comments and line numbers
4209 - various operators, brackets and sigils
4212 - 'v': vstrings (or go to key lookup)
4213 - 'x' repetition operator (or go to key lookup)
4214 - other ASCII alphanumerics (key lookup begins here):
4217 scan built-in keyword (but do nothing with it yet)
4218 check for statement label
4219 check for lexical subs
4220 goto just_a_word if there is one
4221 see whether built-in keyword is overridden
4222 switch on keyword number:
4223 - default: just_a_word:
4224 not a built-in keyword; handle bareword lookup
4225 disambiguate between method and sub call
4226 fall back to bareword
4227 - cases for built-in keywords
4235 char *s = PL_bufptr;
4239 const bool saw_infix_sigil = cBOOL(PL_parser->saw_infix_sigil);
4243 /* orig_keyword, gvp, and gv are initialized here because
4244 * jump to the label just_a_word_zero can bypass their
4245 * initialization later. */
4246 I32 orig_keyword = 0;
4251 SV* tmp = newSVpvs("");
4252 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
4253 (IV)CopLINE(PL_curcop),
4254 lex_state_names[PL_lex_state],
4255 exp_name[PL_expect],
4256 pv_display(tmp, s, strlen(s), 0, 60));
4260 switch (PL_lex_state) {
4262 case LEX_INTERPNORMAL:
4265 /* when we've already built the next token, just pull it out of the queue */
4268 pl_yylval = PL_nextval[PL_nexttoke];
4270 PL_lex_state = PL_lex_defer;
4271 PL_expect = PL_lex_expect;
4272 PL_lex_defer = LEX_NORMAL;
4276 next_type = PL_nexttype[PL_nexttoke];
4277 if (next_type & (7<<24)) {
4278 if (next_type & (1<<24)) {
4279 if (PL_lex_brackets > 100)
4280 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4281 PL_lex_brackstack[PL_lex_brackets++] =
4282 (char) ((next_type >> 16) & 0xff);
4284 if (next_type & (2<<24))
4285 PL_lex_allbrackets++;
4286 if (next_type & (4<<24))
4287 PL_lex_allbrackets--;
4288 next_type &= 0xffff;
4290 return REPORT(next_type == 'p' ? pending_ident() : next_type);
4293 /* interpolated case modifiers like \L \U, including \Q and \E.
4294 when we get here, PL_bufptr is at the \
4296 case LEX_INTERPCASEMOD:
4298 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
4300 "panic: INTERPCASEMOD bufptr=%p, bufend=%p, *bufptr=%u",
4301 PL_bufptr, PL_bufend, *PL_bufptr);
4303 /* handle \E or end of string */
4304 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
4306 if (PL_lex_casemods) {
4307 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
4308 PL_lex_casestack[PL_lex_casemods] = '\0';
4310 if (PL_bufptr != PL_bufend
4311 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q'
4312 || oldmod == 'F')) {
4314 PL_lex_state = LEX_INTERPCONCAT;
4316 PL_lex_allbrackets--;
4319 else if ( PL_bufptr != PL_bufend && PL_bufptr[1] == 'E' ) {
4320 /* Got an unpaired \E */
4321 Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
4322 "Useless use of \\E");
4324 if (PL_bufptr != PL_bufend)
4326 PL_lex_state = LEX_INTERPCONCAT;
4330 DEBUG_T({ PerlIO_printf(Perl_debug_log,
4331 "### Saw case modifier\n"); });
4333 if (s[1] == '\\' && s[2] == 'E') {
4335 PL_lex_state = LEX_INTERPCONCAT;
4340 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
4341 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
4342 if ((*s == 'L' || *s == 'U' || *s == 'F') &&
4343 (strchr(PL_lex_casestack, 'L')
4344 || strchr(PL_lex_casestack, 'U')
4345 || strchr(PL_lex_casestack, 'F'))) {
4346 PL_lex_casestack[--PL_lex_casemods] = '\0';
4347 PL_lex_allbrackets--;
4350 if (PL_lex_casemods > 10)
4351 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
4352 PL_lex_casestack[PL_lex_casemods++] = *s;
4353 PL_lex_casestack[PL_lex_casemods] = '\0';
4354 PL_lex_state = LEX_INTERPCONCAT;
4355 NEXTVAL_NEXTTOKE.ival = 0;
4356 force_next((2<<24)|'(');
4358 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
4360 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
4362 NEXTVAL_NEXTTOKE.ival = OP_LC;
4364 NEXTVAL_NEXTTOKE.ival = OP_UC;
4366 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
4368 NEXTVAL_NEXTTOKE.ival = OP_FC;
4370 Perl_croak(aTHX_ "panic: yylex, *s=%u", *s);
4374 if (PL_lex_starts) {
4377 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
4378 if (PL_lex_casemods == 1 && PL_lex_inpat)
4387 case LEX_INTERPPUSH:
4388 return REPORT(sublex_push());
4390 case LEX_INTERPSTART:
4391 if (PL_bufptr == PL_bufend)
4392 return REPORT(sublex_done());
4393 DEBUG_T({ if(*PL_bufptr != '(') PerlIO_printf(Perl_debug_log,
4394 "### Interpolated variable\n"); });
4396 /* for /@a/, we leave the joining for the regex engine to do
4397 * (unless we're within \Q etc) */
4398 PL_lex_dojoin = (*PL_bufptr == '@'
4399 && (!PL_lex_inpat || PL_lex_casemods));
4400 PL_lex_state = LEX_INTERPNORMAL;
4401 if (PL_lex_dojoin) {
4402 NEXTVAL_NEXTTOKE.ival = 0;
4404 force_ident("\"", '$');
4405 NEXTVAL_NEXTTOKE.ival = 0;
4407 NEXTVAL_NEXTTOKE.ival = 0;
4408 force_next((2<<24)|'(');
4409 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
4412 /* Convert (?{...}) and friends to 'do {...}' */
4413 if (PL_lex_inpat && *PL_bufptr == '(') {
4414 PL_parser->lex_shared->re_eval_start = PL_bufptr;
4416 if (*PL_bufptr != '{')
4418 PL_expect = XTERMBLOCK;
4422 if (PL_lex_starts++) {
4424 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
4425 if (!PL_lex_casemods && PL_lex_inpat)
4432 case LEX_INTERPENDMAYBE:
4433 if (intuit_more(PL_bufptr)) {
4434 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
4440 if (PL_lex_dojoin) {
4441 const U8 dojoin_was = PL_lex_dojoin;
4442 PL_lex_dojoin = FALSE;
4443 PL_lex_state = LEX_INTERPCONCAT;
4444 PL_lex_allbrackets--;
4445 return REPORT(dojoin_was == 1 ? ')' : POSTJOIN);
4447 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
4448 && SvEVALED(PL_lex_repl))
4450 if (PL_bufptr != PL_bufend)
4451 Perl_croak(aTHX_ "Bad evalled substitution pattern");
4454 /* Paranoia. re_eval_start is adjusted when S_scan_heredoc sets
4455 re_eval_str. If the here-doc body’s length equals the previous
4456 value of re_eval_start, re_eval_start will now be null. So
4457 check re_eval_str as well. */
4458 if (PL_parser->lex_shared->re_eval_start
4459 || PL_parser->lex_shared->re_eval_str) {
4461 if (*PL_bufptr != ')')
4462 Perl_croak(aTHX_ "Sequence (?{...}) not terminated with ')'");
4464 /* having compiled a (?{..}) expression, return the original
4465 * text too, as a const */
4466 if (PL_parser->lex_shared->re_eval_str) {
4467 sv = PL_parser->lex_shared->re_eval_str;
4468 PL_parser->lex_shared->re_eval_str = NULL;
4470 PL_bufptr - PL_parser->lex_shared->re_eval_start);
4471 SvPV_shrink_to_cur(sv);
4473 else sv = newSVpvn(PL_parser->lex_shared->re_eval_start,
4474 PL_bufptr - PL_parser->lex_shared->re_eval_start);
4475 NEXTVAL_NEXTTOKE.opval =
4476 (OP*)newSVOP(OP_CONST, 0,
4479 PL_parser->lex_shared->re_eval_start = NULL;
4485 case LEX_INTERPCONCAT:
4487 if (PL_lex_brackets)
4488 Perl_croak(aTHX_ "panic: INTERPCONCAT, lex_brackets=%ld",
4489 (long) PL_lex_brackets);
4491 if (PL_bufptr == PL_bufend)
4492 return REPORT(sublex_done());
4494 /* m'foo' still needs to be parsed for possible (?{...}) */
4495 if (SvIVX(PL_linestr) == '\'' && !PL_lex_inpat) {
4496 SV *sv = newSVsv(PL_linestr);
4498 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
4502 s = scan_const(PL_bufptr);
4504 PL_lex_state = LEX_INTERPCASEMOD;
4506 PL_lex_state = LEX_INTERPSTART;
4509 if (s != PL_bufptr) {
4510 NEXTVAL_NEXTTOKE = pl_yylval;
4513 if (PL_lex_starts++) {
4514 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
4515 if (!PL_lex_casemods && PL_lex_inpat)
4528 s = scan_formline(PL_bufptr);
4529 if (!PL_lex_formbrack)
4538 /* We really do *not* want PL_linestr ever becoming a COW. */
4539 assert (!SvIsCOW(PL_linestr));
4541 PL_oldoldbufptr = PL_oldbufptr;
4543 PL_parser->saw_infix_sigil = 0;
4548 if (UTF ? isIDFIRST_utf8((U8*)s) : isALNUMC(*s))
4551 SV *dsv = newSVpvs_flags("", SVs_TEMP);
4552 const char *c = UTF ? sv_uni_display(dsv, newSVpvn_flags(s,
4554 SVs_TEMP | SVf_UTF8),
4555 10, UNI_DISPLAY_ISPRINT)
4556 : Perl_form(aTHX_ "\\x%02X", (unsigned char)*s);
4557 len = UTF ? Perl_utf8_length(aTHX_ (U8 *) PL_linestart, (U8 *) s) : (STRLEN) (s - PL_linestart);
4558 if (len > UNRECOGNIZED_PRECEDE_COUNT) {
4559 d = UTF ? (char *) utf8_hop((U8 *) s, -UNRECOGNIZED_PRECEDE_COUNT) : s - UNRECOGNIZED_PRECEDE_COUNT;
4563 Perl_croak(aTHX_ "Unrecognized character %s; marked by <-- HERE after %"UTF8f"<-- HERE near column %d", c,
4564 UTF8fARG(UTF, (s - d), d),
4569 goto fake_eof; /* emulate EOF on ^D or ^Z */
4571 if (!PL_rsfp && (!PL_parser->filtered || s+1 < PL_bufend)) {
4574 if (PL_lex_brackets &&
4575 PL_lex_brackstack[PL_lex_brackets-1] != XFAKEEOF) {
4576 yyerror((const char *)
4578 ? "Format not terminated"
4579 : "Missing right curly or square bracket"));
4581 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4582 "### Tokener got EOF\n");
4586 if (s++ < PL_bufend)
4587 goto retry; /* ignore stray nulls */
4590 if (!PL_in_eval && !PL_preambled) {
4591 PL_preambled = TRUE;
4593 /* Generate a string of Perl code to load the debugger.
4594 * If PERL5DB is set, it will return the contents of that,
4595 * otherwise a compile-time require of perl5db.pl. */
4597 const char * const pdb = PerlEnv_getenv("PERL5DB");
4600 sv_setpv(PL_linestr, pdb);
4601 sv_catpvs(PL_linestr,";");
4603 SETERRNO(0,SS_NORMAL);
4604 sv_setpvs(PL_linestr, "BEGIN { require 'perl5db.pl' };");
4606 PL_parser->preambling = CopLINE(PL_curcop);
4608 sv_setpvs(PL_linestr,"");
4609 if (PL_preambleav) {
4610 SV **svp = AvARRAY(PL_preambleav);
4611 SV **const end = svp + AvFILLp(PL_preambleav);
4613 sv_catsv(PL_linestr, *svp);
4615 sv_catpvs(PL_linestr, ";");
4617 sv_free(MUTABLE_SV(PL_preambleav));
4618 PL_preambleav = NULL;
4621 sv_catpvs(PL_linestr,
4622 "use feature ':5." STRINGIFY(PERL_VERSION) "';");
4623 if (PL_minus_n || PL_minus_p) {
4624 sv_catpvs(PL_linestr, "LINE: while (<>) {"/*}*/);
4626 sv_catpvs(PL_linestr,"chomp;");
4629 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
4630 || *PL_splitstr == '"')
4631 && strchr(PL_splitstr + 1, *PL_splitstr))
4632 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
4634 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
4635 bytes can be used as quoting characters. :-) */
4636 const char *splits = PL_splitstr;
4637 sv_catpvs(PL_linestr, "our @F=split(q\0");
4640 if (*splits == '\\')
4641 sv_catpvn(PL_linestr, splits, 1);
4642 sv_catpvn(PL_linestr, splits, 1);
4643 } while (*splits++);
4644 /* This loop will embed the trailing NUL of
4645 PL_linestr as the last thing it does before
4647 sv_catpvs(PL_linestr, ");");
4651 sv_catpvs(PL_linestr,"our @F=split(' ');");
4654 sv_catpvs(PL_linestr, "\n");
4655 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4656 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4657 PL_last_lop = PL_last_uni = NULL;
4658 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
4659 update_debugger_info(PL_linestr, NULL, 0);
4664 bof = PL_rsfp ? TRUE : FALSE;
4667 fake_eof = LEX_FAKE_EOF;
4669 PL_bufptr = PL_bufend;
4670 COPLINE_INC_WITH_HERELINES;
4671 if (!lex_next_chunk(fake_eof)) {
4672 CopLINE_dec(PL_curcop);
4674 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
4676 CopLINE_dec(PL_curcop);
4678 /* If it looks like the start of a BOM or raw UTF-16,
4679 * check if it in fact is. */
4680 if (bof && PL_rsfp &&
4682 *(U8*)s == BOM_UTF8_FIRST_BYTE ||
4685 Off_t offset = (IV)PerlIO_tell(PL_rsfp);
4686 bof = (offset == (Off_t)SvCUR(PL_linestr));
4687 #if defined(PERLIO_USING_CRLF) && defined(PERL_TEXTMODE_SCRIPTS)
4688 /* offset may include swallowed CR */
4690 bof = (offset == (Off_t)SvCUR(PL_linestr)+1);
4693 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4694 s = swallow_bom((U8*)s);
4697 if (PL_parser->in_pod) {
4698 /* Incest with pod. */
4699 if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) {
4700 sv_setpvs(PL_linestr, "");
4701 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4702 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4703 PL_last_lop = PL_last_uni = NULL;
4704 PL_parser->in_pod = 0;
4707 if (PL_rsfp || PL_parser->filtered)
4709 } while (PL_parser->in_pod);
4710 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
4711 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4712 PL_last_lop = PL_last_uni = NULL;
4713 if (CopLINE(PL_curcop) == 1) {
4714 while (s < PL_bufend && isSPACE(*s))
4716 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
4720 if (*s == '#' && *(s+1) == '!')
4722 #ifdef ALTERNATE_SHEBANG
4724 static char const as[] = ALTERNATE_SHEBANG;
4725 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
4726 d = s + (sizeof(as) - 1);
4728 #endif /* ALTERNATE_SHEBANG */
4737 while (*d && !isSPACE(*d))
4741 #ifdef ARG_ZERO_IS_SCRIPT
4742 if (ipathend > ipath) {
4744 * HP-UX (at least) sets argv[0] to the script name,
4745 * which makes $^X incorrect. And Digital UNIX and Linux,
4746 * at least, set argv[0] to the basename of the Perl
4747 * interpreter. So, having found "#!", we'll set it right.
4749 SV* copfilesv = CopFILESV(PL_curcop);
4752 GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
4754 assert(SvPOK(x) || SvGMAGICAL(x));
4755 if (sv_eq(x, copfilesv)) {
4756 sv_setpvn(x, ipath, ipathend - ipath);
4762 const char *bstart = SvPV_const(copfilesv, blen);
4763 const char * const lstart = SvPV_const(x, llen);
4765 bstart += blen - llen;
4766 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
4767 sv_setpvn(x, ipath, ipathend - ipath);
4774 /* Anything to do if no copfilesv? */
4776 TAINT_NOT; /* $^X is always tainted, but that's OK */
4778 #endif /* ARG_ZERO_IS_SCRIPT */
4783 d = instr(s,"perl -");
4785 d = instr(s,"perl");
4787 /* avoid getting into infinite loops when shebang
4788 * line contains "Perl" rather than "perl" */
4790 for (d = ipathend-4; d >= ipath; --d) {
4791 if ((*d == 'p' || *d == 'P')
4792 && !ibcmp(d, "perl", 4))
4802 #ifdef ALTERNATE_SHEBANG
4804 * If the ALTERNATE_SHEBANG on this system starts with a
4805 * character that can be part of a Perl expression, then if
4806 * we see it but not "perl", we're probably looking at the
4807 * start of Perl code, not a request to hand off to some
4808 * other interpreter. Similarly, if "perl" is there, but
4809 * not in the first 'word' of the line, we assume the line
4810 * contains the start of the Perl program.
4812 if (d && *s != '#') {
4813 const char *c = ipath;
4814 while (*c && !strchr("; \t\r\n\f\v#", *c))
4817 d = NULL; /* "perl" not in first word; ignore */
4819 *s = '#'; /* Don't try to parse shebang line */
4821 #endif /* ALTERNATE_SHEBANG */
4826 !instr(s,"indir") &&
4827 instr(PL_origargv[0],"perl"))
4834 while (s < PL_bufend && isSPACE(*s))
4836 if (s < PL_bufend) {
4837 Newx(newargv,PL_origargc+3,char*);
4839 while (s < PL_bufend && !isSPACE(*s))
4842 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
4845 newargv = PL_origargv;
4848 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
4850 Perl_croak(aTHX_ "Can't exec %s", ipath);
4853 while (*d && !isSPACE(*d))
4855 while (SPACE_OR_TAB(*d))
4859 const bool switches_done = PL_doswitches;
4860 const U32 oldpdb = PL_perldb;
4861 const bool oldn = PL_minus_n;
4862 const bool oldp = PL_minus_p;
4866 bool baduni = FALSE;
4868 const char *d2 = d1 + 1;
4869 if (parse_unicode_opts((const char **)&d2)
4873 if (baduni || *d1 == 'M' || *d1 == 'm') {
4874 const char * const m = d1;
4875 while (*d1 && !isSPACE(*d1))
4877 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
4880 d1 = moreswitches(d1);
4882 if (PL_doswitches && !switches_done) {
4883 int argc = PL_origargc;
4884 char **argv = PL_origargv;
4887 } while (argc && argv[0][0] == '-' && argv[0][1]);
4888 init_argv_symbols(argc,argv);
4890 if (((PERLDB_LINE || PERLDB_SAVESRC) && !oldpdb) ||
4891 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
4892 /* if we have already added "LINE: while (<>) {",
4893 we must not do it again */
4895 sv_setpvs(PL_linestr, "");
4896 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4897 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4898 PL_last_lop = PL_last_uni = NULL;
4899 PL_preambled = FALSE;
4900 if (PERLDB_LINE || PERLDB_SAVESRC)
4901 (void)gv_fetchfile(PL_origfilename);
4908 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4909 PL_lex_state = LEX_FORMLINE;
4910 NEXTVAL_NEXTTOKE.ival = 0;
4911 force_next(FORMRBRACK);
4916 #ifdef PERL_STRICT_CR
4917 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
4919 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
4921 case ' ': case '\t': case '\f': case 013:
4926 if (PL_lex_state != LEX_NORMAL ||
4927 (PL_in_eval && !PL_rsfp && !PL_parser->filtered)) {
4928 const bool in_comment = *s == '#';
4929 if (*s == '#' && s == PL_linestart && PL_in_eval
4930 && !PL_rsfp && !PL_parser->filtered) {
4931 /* handle eval qq[#line 1 "foo"\n ...] */
4932 CopLINE_dec(PL_curcop);
4936 while (d < PL_bufend && *d != '\n')
4940 else if (d > PL_bufend)
4941 /* Found by Ilya: feed random input to Perl. */
4942 Perl_croak(aTHX_ "panic: input overflow, %p > %p",
4945 if (in_comment && d == PL_bufend
4946 && PL_lex_state == LEX_INTERPNORMAL
4947 && PL_lex_inwhat == OP_SUBST && PL_lex_repl == PL_linestr
4948 && SvEVALED(PL_lex_repl) && d[-1] == '}') s--;
4951 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4952 PL_lex_state = LEX_FORMLINE;
4953 NEXTVAL_NEXTTOKE.ival = 0;
4954 force_next(FORMRBRACK);
4959 while (s < PL_bufend && *s != '\n')
4967 else if (s > PL_bufend)
4968 /* Found by Ilya: feed random input to Perl. */
4969 Perl_croak(aTHX_ "panic: input overflow");
4973 if (s[1] && isALPHA(s[1]) && !isWORDCHAR(s[2])) {
4981 while (s < PL_bufend && SPACE_OR_TAB(*s))
4984 if (strnEQ(s,"=>",2)) {
4985 s = force_word(PL_bufptr,WORD,FALSE,FALSE);
4986 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
4987 OPERATOR('-'); /* unary minus */
4990 case 'r': ftst = OP_FTEREAD; break;
4991 case 'w': ftst = OP_FTEWRITE; break;
4992 case 'x': ftst = OP_FTEEXEC; break;
4993 case 'o': ftst = OP_FTEOWNED; break;
4994 case 'R': ftst = OP_FTRREAD; break;
4995 case 'W': ftst = OP_FTRWRITE; break;
4996 case 'X': ftst = OP_FTREXEC; break;
4997 case 'O': ftst = OP_FTROWNED; break;
4998 case 'e': ftst = OP_FTIS; break;
4999 case 'z': ftst = OP_FTZERO; break;
5000 case 's': ftst = OP_FTSIZE; break;
5001 case 'f': ftst = OP_FTFILE; break;
5002 case 'd': ftst = OP_FTDIR; break;
5003 case 'l': ftst = OP_FTLINK; break;
5004 case 'p': ftst = OP_FTPIPE; break;
5005 case 'S': ftst = OP_FTSOCK; break;
5006 case 'u': ftst = OP_FTSUID; break;
5007 case 'g': ftst = OP_FTSGID; break;
5008 case 'k': ftst = OP_FTSVTX; break;
5009 case 'b': ftst = OP_FTBLK; break;
5010 case 'c': ftst = OP_FTCHR; break;
5011 case 't': ftst = OP_FTTTY; break;
5012 case 'T': ftst = OP_FTTEXT; break;
5013 case 'B': ftst = OP_FTBINARY; break;
5014 case 'M': case 'A': case 'C':
5015 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
5017 case 'M': ftst = OP_FTMTIME; break;
5018 case 'A': ftst = OP_FTATIME; break;
5019 case 'C': ftst = OP_FTCTIME; break;
5027 PL_last_uni = PL_oldbufptr;
5028 PL_last_lop_op = (OPCODE)ftst;
5029 DEBUG_T( { PerlIO_printf(Perl_debug_log,
5030 "### Saw file test %c\n", (int)tmp);
5035 /* Assume it was a minus followed by a one-letter named
5036 * subroutine call (or a -bareword), then. */
5037 DEBUG_T( { PerlIO_printf(Perl_debug_log,
5038 "### '-%c' looked like a file test but was not\n",
5045 const char tmp = *s++;
5048 if (PL_expect == XOPERATOR)
5053 else if (*s == '>') {
5056 if (FEATURE_POSTDEREF_IS_ENABLED && (
5057 ((*s == '$' || *s == '&') && s[1] == '*')
5058 ||(*s == '$' && s[1] == '#' && s[2] == '*')
5059 ||((*s == '@' || *s == '%') && strchr("*[{", s[1]))
5060 ||(*s == '*' && (s[1] == '*' || s[1] == '{'))
5063 Perl_ck_warner_d(aTHX_
5064 packWARN(WARN_EXPERIMENTAL__POSTDEREF),
5065 "Postfix dereference is experimental"
5067 PL_expect = XPOSTDEREF;
5070 if (isIDFIRST_lazy_if(s,UTF)) {
5071 s = force_word(s,METHOD,FALSE,TRUE);
5079 if (PL_expect == XOPERATOR) {
5080 if (*s == '=' && !PL_lex_allbrackets &&
5081 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
5088 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
5090 OPERATOR('-'); /* unary minus */
5096 const char tmp = *s++;
5099 if (PL_expect == XOPERATOR)
5104 if (PL_expect == XOPERATOR) {
5105 if (*s == '=' && !PL_lex_allbrackets &&
5106 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
5113 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
5120 if (PL_expect == XPOSTDEREF) POSTDEREF('*');
5121 if (PL_expect != XOPERATOR) {
5122 s = scan_ident(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5123 PL_expect = XOPERATOR;
5124 force_ident(PL_tokenbuf, '*');
5132 if (*s == '=' && !PL_lex_allbrackets &&
5133 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
5139 if (*s == '=' && !PL_lex_allbrackets &&
5140 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
5144 PL_parser->saw_infix_sigil = 1;
5149 if (PL_expect == XOPERATOR) {
5150 if (s[1] == '=' && !PL_lex_allbrackets &&
5151 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN)
5154 PL_parser->saw_infix_sigil = 1;
5157 else if (PL_expect == XPOSTDEREF) POSTDEREF('%');
5158 PL_tokenbuf[0] = '%';
5159 s = scan_ident(s, PL_tokenbuf + 1,
5160 sizeof PL_tokenbuf - 1, FALSE);
5162 if (!PL_tokenbuf[1]) {
5165 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
5167 PL_tokenbuf[0] = '@';
5169 PL_expect = XOPERATOR;
5170 force_ident_maybe_lex('%');
5174 if (!PL_lex_allbrackets && PL_lex_fakeeof >=
5175 (s[1] == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_BITWISE))
5180 if (PL_lex_brackets > 100)
5181 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
5182 PL_lex_brackstack[PL_lex_brackets++] = 0;
5183 PL_lex_allbrackets++;
5185 const char tmp = *s++;
5190 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
5192 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
5195 Perl_ck_warner_d(aTHX_
5196 packWARN(WARN_EXPERIMENTAL__SMARTMATCH),
5197 "Smartmatch is experimental");
5203 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMMA)
5210 goto just_a_word_zero_gv;
5216 switch (PL_expect) {
5218 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
5220 PL_bufptr = s; /* update in case we back off */
5223 "Use of := for an empty attribute list is not allowed");
5230 PL_expect = XTERMBLOCK;
5234 while (isIDFIRST_lazy_if(s,UTF)) {
5237 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5238 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
5239 if (tmp < 0) tmp = -tmp;
5254 sv = newSVpvn_flags(s, len, UTF ? SVf_UTF8 : 0);
5256 d = scan_str(d,TRUE,TRUE,FALSE,NULL);
5257 COPLINE_SET_FROM_MULTI_END;
5259 /* MUST advance bufptr here to avoid bogus
5260 "at end of line" context messages from yyerror().
5262 PL_bufptr = s + len;
5263 yyerror("Unterminated attribute parameter in attribute list");
5267 return REPORT(0); /* EOF indicator */
5271 sv_catsv(sv, PL_lex_stuff);
5272 attrs = op_append_elem(OP_LIST, attrs,
5273 newSVOP(OP_CONST, 0, sv));
5274 SvREFCNT_dec(PL_lex_stuff);
5275 PL_lex_stuff = NULL;
5278 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
5280 if (PL_in_my == KEY_our) {
5281 deprecate(":unique");
5284 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
5287 /* NOTE: any CV attrs applied here need to be part of
5288 the CVf_BUILTIN_ATTRS define in cv.h! */
5289 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
5291 CvLVALUE_on(PL_compcv);
5293 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
5295 deprecate(":locked");
5297 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
5299 CvMETHOD_on(PL_compcv);
5301 /* After we've set the flags, it could be argued that
5302 we don't need to do the attributes.pm-based setting
5303 process, and shouldn't bother appending recognized
5304 flags. To experiment with that, uncomment the
5305 following "else". (Note that's already been
5306 uncommented. That keeps the above-applied built-in
5307 attributes from being intercepted (and possibly
5308 rejected) by a package's attribute routines, but is
5309 justified by the performance win for the common case
5310 of applying only built-in attributes.) */
5312 attrs = op_append_elem(OP_LIST, attrs,
5313 newSVOP(OP_CONST, 0,
5317 if (*s == ':' && s[1] != ':')
5320 break; /* require real whitespace or :'s */
5321 /* XXX losing whitespace on sequential attributes here */
5324 if (*s != ';' && *s != '}' &&
5325 !(PL_expect == XOPERATOR
5326 ? (*s == '=' || *s == ')')
5327 : (*s == '{' || *s == '('))) {
5328 const char q = ((*s == '\'') ? '"' : '\'');
5329 /* If here for an expression, and parsed no attrs, back
5331 if (PL_expect == XOPERATOR && !attrs) {
5335 /* MUST advance bufptr here to avoid bogus "at end of line"
5336 context messages from yyerror().
5339 yyerror( (const char *)
5341 ? Perl_form(aTHX_ "Invalid separator character "
5342 "%c%c%c in attribute list", q, *s, q)
5343 : "Unterminated attribute list" ) );
5351 NEXTVAL_NEXTTOKE.opval = attrs;
5357 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_CLOSING) {
5361 PL_lex_allbrackets--;
5365 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
5366 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
5370 PL_lex_allbrackets++;
5373 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR)
5379 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_CLOSING)
5382 PL_lex_allbrackets--;
5388 if (PL_lex_brackets && PL_lex_brackstack[PL_lex_brackets-1] == XFAKEEOF)
5391 if (PL_lex_brackets <= 0)
5392 /* diag_listed_as: Unmatched right %s bracket */
5393 yyerror("Unmatched right square bracket");
5396 PL_lex_allbrackets--;
5397 if (PL_lex_state == LEX_INTERPNORMAL) {
5398 if (PL_lex_brackets == 0) {
5399 if (*s == '-' && s[1] == '>')
5400 PL_lex_state = LEX_INTERPENDMAYBE;
5401 else if (*s != '[' && *s != '{')
5402 PL_lex_state = LEX_INTERPEND;
5409 if (PL_lex_brackets > 100) {
5410 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
5412 switch (PL_expect) {
5414 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
5415 PL_lex_allbrackets++;
5416 OPERATOR(HASHBRACK);
5418 while (s < PL_bufend && SPACE_OR_TAB(*s))
5421 PL_tokenbuf[0] = '\0';
5422 if (d < PL_bufend && *d == '-') {
5423 PL_tokenbuf[0] = '-';
5425 while (d < PL_bufend && SPACE_OR_TAB(*d))
5428 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
5429 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
5431 while (d < PL_bufend && SPACE_OR_TAB(*d))
5434 const char minus = (PL_tokenbuf[0] == '-');
5435 s = force_word(s + minus, WORD, FALSE, TRUE);
5443 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
5444 PL_lex_allbrackets++;
5449 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
5450 PL_lex_allbrackets++;
5454 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
5455 PL_lex_allbrackets++;
5460 if (PL_oldoldbufptr == PL_last_lop)
5461 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
5463 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
5464 PL_lex_allbrackets++;
5467 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
5469 /* This hack is to get the ${} in the message. */
5471 yyerror("syntax error");
5474 OPERATOR(HASHBRACK);
5476 /* This hack serves to disambiguate a pair of curlies
5477 * as being a block or an anon hash. Normally, expectation
5478 * determines that, but in cases where we're not in a
5479 * position to expect anything in particular (like inside
5480 * eval"") we have to resolve the ambiguity. This code
5481 * covers the case where the first term in the curlies is a
5482 * quoted string. Most other cases need to be explicitly
5483 * disambiguated by prepending a "+" before the opening
5484 * curly in order to force resolution as an anon hash.
5486 * XXX should probably propagate the outer expectation
5487 * into eval"" to rely less on this hack, but that could
5488 * potentially break current behavior of eval"".
5492 if (*s == '\'' || *s == '"' || *s == '`') {
5493 /* common case: get past first string, handling escapes */
5494 for (t++; t < PL_bufend && *t != *s;)
5495 if (*t++ == '\\' && (*t == '\\' || *t == *s))
5499 else if (*s == 'q') {
5502 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
5503 && !isWORDCHAR(*t))))
5505 /* skip q//-like construct */
5507 char open, close, term;
5510 while (t < PL_bufend && isSPACE(*t))
5512 /* check for q => */
5513 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
5514 OPERATOR(HASHBRACK);
5518 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
5522 for (t++; t < PL_bufend; t++) {
5523 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
5525 else if (*t == open)
5529 for (t++; t < PL_bufend; t++) {
5530 if (*t == '\\' && t+1 < PL_bufend)
5532 else if (*t == close && --brackets <= 0)
5534 else if (*t == open)
5541 /* skip plain q word */
5542 while (t < PL_bufend && isWORDCHAR_lazy_if(t,UTF))
5545 else if (isWORDCHAR_lazy_if(t,UTF)) {
5547 while (t < PL_bufend && isWORDCHAR_lazy_if(t,UTF))
5550 while (t < PL_bufend && isSPACE(*t))
5552 /* if comma follows first term, call it an anon hash */
5553 /* XXX it could be a comma expression with loop modifiers */
5554 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
5555 || (*t == '=' && t[1] == '>')))
5556 OPERATOR(HASHBRACK);
5557 if (PL_expect == XREF)
5560 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
5566 pl_yylval.ival = CopLINE(PL_curcop);
5567 if (isSPACE(*s) || *s == '#')
5568 PL_copline = NOLINE; /* invalidate current command line number */
5569 TOKEN(formbrack ? '=' : '{');
5571 if (PL_lex_brackets && PL_lex_brackstack[PL_lex_brackets-1] == XFAKEEOF)
5575 if (PL_lex_brackets <= 0)
5576 /* diag_listed_as: Unmatched right %s bracket */
5577 yyerror("Unmatched right curly bracket");
5579 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
5580 PL_lex_allbrackets--;
5581 if (PL_lex_state == LEX_INTERPNORMAL) {
5582 if (PL_lex_brackets == 0) {
5583 if (PL_expect & XFAKEBRACK) {
5584 PL_expect &= XENUMMASK;
5585 PL_lex_state = LEX_INTERPEND;
5587 return yylex(); /* ignore fake brackets */
5589 if (PL_lex_inwhat == OP_SUBST && PL_lex_repl == PL_linestr
5590 && SvEVALED(PL_lex_repl))
5591 PL_lex_state = LEX_INTERPEND;
5592 else if (*s == '-' && s[1] == '>')
5593 PL_lex_state = LEX_INTERPENDMAYBE;
5594 else if (*s != '[' && *s != '{')
5595 PL_lex_state = LEX_INTERPEND;
5598 if (PL_expect & XFAKEBRACK) {
5599 PL_expect &= XENUMMASK;
5601 return yylex(); /* ignore fake brackets */
5603 force_next(formbrack ? '.' : '}');
5604 if (formbrack) LEAVE;
5605 if (formbrack == 2) { /* means . where arguments were expected */
5611 if (PL_expect == XPOSTDEREF) POSTDEREF('&');
5614 if (!PL_lex_allbrackets && PL_lex_fakeeof >=
5615 (*s == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_LOGIC)) {
5622 if (PL_expect == XOPERATOR) {
5623 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
5624 && isIDFIRST_lazy_if(s,UTF))
5626 CopLINE_dec(PL_curcop);
5627 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
5628 CopLINE_inc(PL_curcop);
5630 if (!PL_lex_allbrackets && PL_lex_fakeeof >=
5631 (*s == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_BITWISE)) {
5635 PL_parser->saw_infix_sigil = 1;
5639 PL_tokenbuf[0] = '&';
5640 s = scan_ident(s - 1, PL_tokenbuf + 1,
5641 sizeof PL_tokenbuf - 1, TRUE);
5642 if (PL_tokenbuf[1]) {
5643 PL_expect = XOPERATOR;
5644 force_ident_maybe_lex('&');
5648 pl_yylval.ival = (OPpENTERSUB_AMPER<<8);
5654 if (!PL_lex_allbrackets && PL_lex_fakeeof >=
5655 (*s == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_LOGIC)) {
5662 if (!PL_lex_allbrackets && PL_lex_fakeeof >=
5663 (*s == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_BITWISE)) {
5671 const char tmp = *s++;
5673 if (!PL_lex_allbrackets &&
5674 PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) {
5681 if (!PL_lex_allbrackets &&
5682 PL_lex_fakeeof >= LEX_FAKEEOF_COMMA) {
5690 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
5691 && strchr("+-*/%.^&|<",tmp))
5692 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5693 "Reversed %c= operator",(int)tmp);
5695 if (PL_expect == XSTATE && isALPHA(tmp) &&
5696 (s == PL_linestart+1 || s[-2] == '\n') )
5698 if ((PL_in_eval && !PL_rsfp && !PL_parser->filtered)
5699 || PL_lex_state != LEX_NORMAL) {
5704 if (strnEQ(s,"=cut",4)) {
5718 PL_parser->in_pod = 1;
5722 if (PL_expect == XBLOCK) {
5724 #ifdef PERL_STRICT_CR
5725 while (SPACE_OR_TAB(*t))
5727 while (SPACE_OR_TAB(*t) || *t == '\r')
5730 if (*t == '\n' || *t == '#') {
5733 SAVEI8(PL_parser->form_lex_state);
5734 SAVEI32(PL_lex_formbrack);
5735 PL_parser->form_lex_state = PL_lex_state;
5736 PL_lex_formbrack = PL_lex_brackets + 1;
5740 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
5749 const char tmp = *s++;
5751 /* was this !=~ where !~ was meant?
5752 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
5754 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
5755 const char *t = s+1;
5757 while (t < PL_bufend && isSPACE(*t))
5760 if (*t == '/' || *t == '?' ||
5761 ((*t == 'm' || *t == 's' || *t == 'y')
5762 && !isWORDCHAR(t[1])) ||
5763 (*t == 't' && t[1] == 'r' && !isWORDCHAR(t[2])))
5764 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5765 "!=~ should be !~");
5767 if (!PL_lex_allbrackets &&
5768 PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) {
5780 if (PL_expect != XOPERATOR) {
5781 if (s[1] != '<' && !strchr(s,'>'))
5784 s = scan_heredoc(s);
5786 s = scan_inputsymbol(s);
5787 PL_expect = XOPERATOR;
5788 TOKEN(sublex_start());
5794 if (*s == '=' && !PL_lex_allbrackets &&
5795 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
5799 SHop(OP_LEFT_SHIFT);
5804 if (!PL_lex_allbrackets &&
5805 PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) {
5812 if (!PL_lex_allbrackets &&
5813 PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) {
5821 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) {
5829 const char tmp = *s++;
5831 if (*s == '=' && !PL_lex_allbrackets &&
5832 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
5836 SHop(OP_RIGHT_SHIFT);
5838 else if (tmp == '=') {
5839 if (!PL_lex_allbrackets &&
5840 PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) {
5848 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) {
5857 if (PL_expect == XOPERATOR) {
5858 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5859 return deprecate_commaless_var_list();
5862 else if (PL_expect == XPOSTDEREF) {
5865 POSTDEREF(DOLSHARP);
5870 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-@", s[2]))) {
5871 PL_tokenbuf[0] = '@';
5872 s = scan_ident(s + 1, PL_tokenbuf + 1,
5873 sizeof PL_tokenbuf - 1, FALSE);
5874 if (PL_expect == XOPERATOR)
5875 no_op("Array length", s);
5876 if (!PL_tokenbuf[1])
5878 PL_expect = XOPERATOR;
5879 force_ident_maybe_lex('#');
5883 PL_tokenbuf[0] = '$';
5884 s = scan_ident(s, PL_tokenbuf + 1,
5885 sizeof PL_tokenbuf - 1, FALSE);
5886 if (PL_expect == XOPERATOR)
5888 if (!PL_tokenbuf[1]) {
5890 yyerror("Final $ should be \\$ or $name");
5896 const char tmp = *s;
5897 if (PL_lex_state == LEX_NORMAL || PL_lex_brackets)
5900 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
5901 && intuit_more(s)) {
5903 PL_tokenbuf[0] = '@';
5904 if (ckWARN(WARN_SYNTAX)) {
5907 while (isSPACE(*t) || isWORDCHAR_lazy_if(t,UTF) || *t == '$')
5910 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
5911 while (t < PL_bufend && *t != ']')
5913 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5914 "Multidimensional syntax %.*s not supported",
5915 (int)((t - PL_bufptr) + 1), PL_bufptr);
5919 else if (*s == '{') {
5921 PL_tokenbuf[0] = '%';
5922 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
5923 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
5925 char tmpbuf[sizeof PL_tokenbuf];
5928 } while (isSPACE(*t));
5929 if (isIDFIRST_lazy_if(t,UTF)) {
5931 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
5936 && get_cvn_flags(tmpbuf, len, UTF ? SVf_UTF8 : 0))
5937 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5938 "You need to quote \"%"UTF8f"\"",
5939 UTF8fARG(UTF, len, tmpbuf));
5945 PL_expect = XOPERATOR;
5946 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
5947 const bool islop = (PL_last_lop == PL_oldoldbufptr);
5948 if (!islop || PL_last_lop_op == OP_GREPSTART)
5949 PL_expect = XOPERATOR;
5950 else if (strchr("$@\"'`q", *s))
5951 PL_expect = XTERM; /* e.g. print $fh "foo" */
5952 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
5953 PL_expect = XTERM; /* e.g. print $fh &sub */
5954 else if (isIDFIRST_lazy_if(s,UTF)) {
5955 char tmpbuf[sizeof PL_tokenbuf];
5957 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5958 if ((t2 = keyword(tmpbuf, len, 0))) {
5959 /* binary operators exclude handle interpretations */
5971 PL_expect = XTERM; /* e.g. print $fh length() */
5976 PL_expect = XTERM; /* e.g. print $fh subr() */
5979 else if (isDIGIT(*s))
5980 PL_expect = XTERM; /* e.g. print $fh 3 */
5981 else if (*s == '.' && isDIGIT(s[1]))
5982 PL_expect = XTERM; /* e.g. print $fh .3 */
5983 else if ((*s == '?' || *s == '-' || *s == '+')
5984 && !isSPACE(s[1]) && s[1] != '=')
5985 PL_expect = XTERM; /* e.g. print $fh -1 */
5986 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
5988 PL_expect = XTERM; /* e.g. print $fh /.../
5989 XXX except DORDOR operator
5991 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
5993 PL_expect = XTERM; /* print $fh <<"EOF" */
5996 force_ident_maybe_lex('$');
6000 if (PL_expect == XOPERATOR)
6002 else if (PL_expect == XPOSTDEREF) POSTDEREF('@');
6003 PL_tokenbuf[0] = '@';
6004 s = scan_ident(s, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
6006 if (!PL_tokenbuf[1]) {
6009 if (PL_lex_state == LEX_NORMAL)
6011 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
6013 PL_tokenbuf[0] = '%';
6015 /* Warn about @ where they meant $. */
6016 if (*s == '[' || *s == '{') {
6017 if (ckWARN(WARN_SYNTAX)) {
6018 S_check_scalar_slice(aTHX_ s);
6022 PL_expect = XOPERATOR;
6023 force_ident_maybe_lex('@');
6026 case '/': /* may be division, defined-or, or pattern */
6027 if ((PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR) && s[1] == '/') {
6028 if (!PL_lex_allbrackets && PL_lex_fakeeof >=
6029 (s[2] == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_LOGIC))
6034 else if (PL_expect == XOPERATOR) {
6036 if (*s == '=' && !PL_lex_allbrackets &&
6037 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
6044 /* Disable warning on "study /blah/" */
6045 if (PL_oldoldbufptr == PL_last_uni
6046 && (*PL_last_uni != 's' || s - PL_last_uni < 5
6047 || memNE(PL_last_uni, "study", 5)
6048 || isWORDCHAR_lazy_if(PL_last_uni+5,UTF)
6051 s = scan_pat(s,OP_MATCH);
6052 TERM(sublex_start());
6055 case '?': /* conditional */
6057 if (!PL_lex_allbrackets &&
6058 PL_lex_fakeeof >= LEX_FAKEEOF_IFELSE) {
6062 PL_lex_allbrackets++;
6066 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
6067 #ifdef PERL_STRICT_CR
6070 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
6072 && (s == PL_linestart || s[-1] == '\n') )
6075 formbrack = 2; /* dot seen where arguments expected */
6078 if (PL_expect == XSTATE && s[1] == '.' && s[2] == '.') {
6082 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
6085 if (!PL_lex_allbrackets &&
6086 PL_lex_fakeeof >= LEX_FAKEEOF_RANGE) {
6093 pl_yylval.ival = OPf_SPECIAL;
6099 if (*s == '=' && !PL_lex_allbrackets &&
6100 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
6107 case '0': case '1': case '2': case '3': case '4':
6108 case '5': case '6': case '7': case '8': case '9':
6109 s = scan_num(s, &pl_yylval);
6110 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
6111 if (PL_expect == XOPERATOR)
6116 s = scan_str(s,FALSE,FALSE,FALSE,NULL);
6119 COPLINE_SET_FROM_MULTI_END;
6120 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
6121 if (PL_expect == XOPERATOR) {
6122 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
6123 return deprecate_commaless_var_list();
6128 pl_yylval.ival = OP_CONST;
6129 TERM(sublex_start());
6132 s = scan_str(s,FALSE,FALSE,FALSE,NULL);
6135 printbuf("### Saw string before %s\n", s);
6137 PerlIO_printf(Perl_debug_log,
6138 "### Saw unterminated string\n");
6140 if (PL_expect == XOPERATOR) {
6141 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
6142 return deprecate_commaless_var_list();
6149 pl_yylval.ival = OP_CONST;
6150 /* FIXME. I think that this can be const if char *d is replaced by
6151 more localised variables. */
6152 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
6153 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
6154 pl_yylval.ival = OP_STRINGIFY;
6158 if (pl_yylval.ival == OP_CONST)
6159 COPLINE_SET_FROM_MULTI_END;
6160 TERM(sublex_start());
6163 s = scan_str(s,FALSE,FALSE,FALSE,NULL);
6164 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
6165 if (PL_expect == XOPERATOR)
6166 no_op("Backticks",s);
6169 pl_yylval.ival = OP_BACKTICK;
6170 TERM(sublex_start());
6174 if (PL_lex_inwhat == OP_SUBST && PL_lex_repl == PL_linestr
6176 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
6178 if (PL_expect == XOPERATOR)
6179 no_op("Backslash",s);
6183 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
6184 char *start = s + 2;
6185 while (isDIGIT(*start) || *start == '_')
6187 if (*start == '.' && isDIGIT(start[1])) {
6188 s = scan_num(s, &pl_yylval);
6191 else if ((*start == ':' && start[1] == ':')
6192 || (PL_expect == XSTATE && *start == ':'))
6194 else if (PL_expect == XSTATE) {
6196 while (d < PL_bufend && isSPACE(*d)) d++;
6197 if (*d == ':') goto keylookup;
6199 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
6200 if (!isALPHA(*start) && (PL_expect == XTERM
6201 || PL_expect == XREF || PL_expect == XSTATE
6202 || PL_expect == XTERMORDORDOR)) {
6203 GV *const gv = gv_fetchpvn_flags(s, start - s,
6204 UTF ? SVf_UTF8 : 0, SVt_PVCV);
6206 s = scan_num(s, &pl_yylval);
6213 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
6266 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
6268 /* Some keywords can be followed by any delimiter, including ':' */
6269 anydelim = word_takes_any_delimeter(PL_tokenbuf, len);
6271 /* x::* is just a word, unless x is "CORE" */
6272 if (!anydelim && *s == ':' && s[1] == ':') {
6273 if (strEQ(PL_tokenbuf, "CORE")) goto case_KEY_CORE;
6278 while (d < PL_bufend && isSPACE(*d))
6279 d++; /* no comments skipped here, or s### is misparsed */
6281 /* Is this a word before a => operator? */
6282 if (*d == '=' && d[1] == '>') {
6286 = (OP*)newSVOP(OP_CONST, 0,
6287 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
6288 pl_yylval.opval->op_private = OPpCONST_BARE;
6292 /* Check for plugged-in keyword */
6296 char *saved_bufptr = PL_bufptr;
6298 result = PL_keyword_plugin(aTHX_ PL_tokenbuf, len, &o);
6300 if (result == KEYWORD_PLUGIN_DECLINE) {
6301 /* not a plugged-in keyword */
6302 PL_bufptr = saved_bufptr;
6303 } else if (result == KEYWORD_PLUGIN_STMT) {
6304 pl_yylval.opval = o;
6307 return REPORT(PLUGSTMT);
6308 } else if (result == KEYWORD_PLUGIN_EXPR) {
6309 pl_yylval.opval = o;
6311 PL_expect = XOPERATOR;
6312 return REPORT(PLUGEXPR);
6314 Perl_croak(aTHX_ "Bad plugin affecting keyword '%s'",
6319 /* Check for built-in keyword */
6320 tmp = keyword(PL_tokenbuf, len, 0);
6322 /* Is this a label? */
6323 if (!anydelim && PL_expect == XSTATE
6324 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
6326 pl_yylval.pval = savepvn(PL_tokenbuf, len+1);
6327 pl_yylval.pval[len] = '\0';
6328 pl_yylval.pval[len+1] = UTF ? 1 : 0;
6333 /* Check for lexical sub */
6334 if (PL_expect != XOPERATOR) {
6335 char tmpbuf[sizeof PL_tokenbuf + 1];
6337 Copy(PL_tokenbuf, tmpbuf+1, len, char);
6338 off = pad_findmy_pvn(tmpbuf, len+1, UTF ? SVf_UTF8 : 0);
6339 if (off != NOT_IN_PAD) {
6340 assert(off); /* we assume this is boolean-true below */
6341 if (PAD_COMPNAME_FLAGS_isOUR(off)) {
6342 HV * const stash = PAD_COMPNAME_OURSTASH(off);
6343 HEK * const stashname = HvNAME_HEK(stash);
6344 sv = newSVhek(stashname);
6345 sv_catpvs(sv, "::");
6346 sv_catpvn_flags(sv, PL_tokenbuf, len,
6347 (UTF ? SV_CATUTF8 : SV_CATBYTES));
6348 gv = gv_fetchsv(sv, GV_NOADD_NOINIT | SvUTF8(sv),
6358 rv2cv_op = newOP(OP_PADANY, 0);
6359 rv2cv_op->op_targ = off;
6360 cv = find_lexical_cv(off);
6368 if (tmp < 0) { /* second-class keyword? */
6369 GV *ogv = NULL; /* override (winner) */
6370 GV *hgv = NULL; /* hidden (loser) */
6371 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
6373 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len,
6374 (UTF ? SVf_UTF8 : 0)|GV_NOTQUAL,
6378 if (GvIMPORTED_CV(gv))
6380 else if (! CvMETHOD(cv))
6384 (gvp = (GV**)hv_fetch(PL_globalstash, PL_tokenbuf,
6388 ? GvCVu(gv) && GvIMPORTED_CV(gv)
6389 : SvPCS_IMPORTED(gv)
6390 && (gv_init(gv, PL_globalstash, PL_tokenbuf,
6399 tmp = 0; /* overridden by import or by GLOBAL */
6402 && -tmp==KEY_lock /* XXX generalizable kludge */
6405 tmp = 0; /* any sub overrides "weak" keyword */
6407 else { /* no override */
6409 if (tmp == KEY_dump) {
6410 Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
6411 "dump() better written as CORE::dump()");
6415 if (hgv && tmp != KEY_x) /* never ambiguous */
6416 Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6417 "Ambiguous call resolved as CORE::%s(), "
6418 "qualify as such or use &",
6423 if (tmp && tmp != KEY___DATA__ && tmp != KEY___END__
6424 && (!anydelim || *s != '#')) {
6425 /* no override, and not s### either; skipspace is safe here
6426 * check for => on following line */
6428 STRLEN bufoff = PL_bufptr - SvPVX(PL_linestr);
6429 STRLEN soff = s - SvPVX(PL_linestr);
6430 s = skipspace_flags(s, LEX_NO_INCLINE);
6431 arrow = *s == '=' && s[1] == '>';
6432 PL_bufptr = SvPVX(PL_linestr) + bufoff;
6433 s = SvPVX(PL_linestr) + soff;
6441 default: /* not a keyword */
6442 /* Trade off - by using this evil construction we can pull the
6443 variable gv into the block labelled keylookup. If not, then
6444 we have to give it function scope so that the goto from the
6445 earlier ':' case doesn't bypass the initialisation. */
6447 just_a_word_zero_gv:
6459 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
6460 const char penultchar =
6461 lastchar && PL_bufptr - 2 >= PL_linestart
6466 /* Get the rest if it looks like a package qualifier */
6468 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
6470 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
6473 Perl_croak(aTHX_ "Bad name after %"UTF8f"%s",
6474 UTF8fARG(UTF, len, PL_tokenbuf),
6475 *s == '\'' ? "'" : "::");
6480 if (PL_expect == XOPERATOR) {
6481 if (PL_bufptr == PL_linestart) {
6482 CopLINE_dec(PL_curcop);
6483 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
6484 CopLINE_inc(PL_curcop);
6487 no_op("Bareword",s);
6490 /* Look for a subroutine with this name in current package,
6491 unless this is a lexical sub, or name is "Foo::",
6492 in which case Foo is a bareword
6493 (and a package name). */
6496 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
6498 if (ckWARN(WARN_BAREWORD)
6499 && ! gv_fetchpvn_flags(PL_tokenbuf, len, UTF ? SVf_UTF8 : 0, SVt_PVHV))
6500 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
6501 "Bareword \"%"UTF8f"\" refers to nonexistent package",
6502 UTF8fARG(UTF, len, PL_tokenbuf));
6504 PL_tokenbuf[len] = '\0';
6510 /* Mustn't actually add anything to a symbol table.
6511 But also don't want to "initialise" any placeholder
6512 constants that might already be there into full
6513 blown PVGVs with attached PVCV. */
6514 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
6515 GV_NOADD_NOINIT | ( UTF ? SVf_UTF8 : 0 ),
6521 /* if we saw a global override before, get the right name */
6524 sv = S_newSV_maybe_utf8(aTHX_ PL_tokenbuf,
6525 len ? len : strlen(PL_tokenbuf));
6527 SV * const tmp_sv = sv;
6528 sv = newSVpvs("CORE::GLOBAL::");
6529 sv_catsv(sv, tmp_sv);
6530 SvREFCNT_dec(tmp_sv);
6534 /* Presume this is going to be a bareword of some sort. */
6536 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
6537 pl_yylval.opval->op_private = OPpCONST_BARE;
6539 /* And if "Foo::", then that's what it certainly is. */
6545 OP *const_op = newSVOP(OP_CONST, 0, SvREFCNT_inc_NN(sv));
6546 const_op->op_private = OPpCONST_BARE;
6547 rv2cv_op = newCVREF(0, const_op);
6548 cv = lex ? GvCV(gv) : rv2cv_op_cv(rv2cv_op, 0);
6551 /* See if it's the indirect object for a list operator. */
6553 if (PL_oldoldbufptr &&
6554 PL_oldoldbufptr < PL_bufptr &&
6555 (PL_oldoldbufptr == PL_last_lop
6556 || PL_oldoldbufptr == PL_last_uni) &&
6557 /* NO SKIPSPACE BEFORE HERE! */
6558 (PL_expect == XREF ||
6559 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
6561 bool immediate_paren = *s == '(';
6563 /* (Now we can afford to cross potential line boundary.) */
6564 s = SKIPSPACE2(s,nextPL_nextwhite);
6566 /* Two barewords in a row may indicate method call. */
6568 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
6569 (tmp = intuit_method(s, gv, cv))) {
6571 if (tmp == METHOD && !PL_lex_allbrackets &&
6572 PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC)
6573 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC;
6577 /* If not a declared subroutine, it's an indirect object. */
6578 /* (But it's an indir obj regardless for sort.) */
6579 /* Also, if "_" follows a filetest operator, it's a bareword */
6582 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
6584 (PL_last_lop_op != OP_MAPSTART &&
6585 PL_last_lop_op != OP_GREPSTART))))
6586 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
6587 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
6590 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
6595 PL_expect = XOPERATOR;
6598 /* Is this a word before a => operator? */
6599 if (*s == '=' && s[1] == '>' && !pkgname) {
6602 /* This is our own scalar, created a few lines above,
6604 SvREADONLY_off(cSVOPx(pl_yylval.opval)->op_sv);
6605 sv_setpv(((SVOP*)pl_yylval.opval)->op_sv, PL_tokenbuf);
6606 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
6607 SvUTF8_on(((SVOP*)pl_yylval.opval)->op_sv);
6608 SvREADONLY_on(cSVOPx(pl_yylval.opval)->op_sv);
6612 /* If followed by a paren, it's certainly a subroutine. */
6617 while (SPACE_OR_TAB(*d))
6619 if (*d == ')' && (sv = cv_const_sv_or_av(cv))) {
6624 NEXTVAL_NEXTTOKE.opval =
6625 off ? rv2cv_op : pl_yylval.opval;
6626 PL_expect = XOPERATOR;
6628 op_free(pl_yylval.opval), force_next(PRIVATEREF);
6629 else op_free(rv2cv_op), force_next(WORD);
6634 /* If followed by var or block, call it a method (unless sub) */
6636 if ((*s == '$' || *s == '{') && !cv) {
6638 PL_last_lop = PL_oldbufptr;
6639 PL_last_lop_op = OP_METHOD;
6640 if (!PL_lex_allbrackets &&
6641 PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC)
6642 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC;
6643 PL_expect = XBLOCKTERM;
6645 return REPORT(METHOD);
6648 /* If followed by a bareword, see if it looks like indir obj. */
6651 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
6652 && (tmp = intuit_method(s, gv, cv))) {
6654 if (tmp == METHOD && !PL_lex_allbrackets &&
6655 PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC)
6656 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC;
6660 /* Not a method, so call it a subroutine (if defined) */
6663 if (lastchar == '-' && penultchar != '-') {
6664 const STRLEN l = len ? len : strlen(PL_tokenbuf);
6665 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
6666 "Ambiguous use of -%"UTF8f" resolved as -&%"UTF8f"()",
6667 UTF8fARG(UTF, l, PL_tokenbuf),
6668 UTF8fARG(UTF, l, PL_tokenbuf));
6670 /* Check for a constant sub */
6671 if ((sv = cv_const_sv_or_av(cv))) {
6674 SvREFCNT_dec(((SVOP*)pl_yylval.opval)->op_sv);
6675 ((SVOP*)pl_yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
6676 if (SvTYPE(sv) == SVt_PVAV)
6677 pl_yylval.opval = newUNOP(OP_RV2AV, OPf_PARENS,
6680 pl_yylval.opval->op_private = 0;
6681 pl_yylval.opval->op_folded = 1;
6682 pl_yylval.opval->op_flags |= OPf_SPECIAL;
6687 op_free(pl_yylval.opval);
6689 off ? (OP *)newCVREF(0, rv2cv_op) : rv2cv_op;
6690 pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
6691 PL_last_lop = PL_oldbufptr;
6692 PL_last_lop_op = OP_ENTERSUB;
6693 /* Is there a prototype? */
6697 STRLEN protolen = CvPROTOLEN(cv);
6698 const char *proto = CvPROTO(cv);
6700 proto = S_strip_spaces(aTHX_ proto, &protolen);
6703 if ((optional = *proto == ';'))
6706 while (*proto == ';');
6710 *proto == '$' || *proto == '_'
6711 || *proto == '*' || *proto == '+'
6716 *proto == '\\' && proto[1] && proto[2] == '\0'
6719 UNIPROTO(UNIOPSUB,optional);
6720 if (*proto == '\\' && proto[1] == '[') {
6721 const char *p = proto + 2;
6722 while(*p && *p != ']')
6724 if(*p == ']' && !p[1])
6725 UNIPROTO(UNIOPSUB,optional);
6727 if (*proto == '&' && *s == '{') {
6729 sv_setpvs(PL_subname, "__ANON__");
6731 sv_setpvs(PL_subname, "__ANON__::__ANON__");
6732 if (!PL_lex_allbrackets &&
6733 PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC)
6734 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC;
6738 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6740 force_next(off ? PRIVATEREF : WORD);
6741 if (!PL_lex_allbrackets &&
6742 PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC)
6743 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC;
6747 /* Call it a bare word */
6749 if (PL_hints & HINT_STRICT_SUBS)
6750 pl_yylval.opval->op_private |= OPpCONST_STRICT;
6753 /* after "print" and similar functions (corresponding to
6754 * "F? L" in opcode.pl), whatever wasn't already parsed as
6755 * a filehandle should be subject to "strict subs".
6756 * Likewise for the optional indirect-object argument to system
6757 * or exec, which can't be a bareword */
6758 if ((PL_last_lop_op == OP_PRINT
6759 || PL_last_lop_op == OP_PRTF
6760 || PL_last_lop_op == OP_SAY
6761 || PL_last_lop_op == OP_SYSTEM
6762 || PL_last_lop_op == OP_EXEC)
6763 && (PL_hints & HINT_STRICT_SUBS))
6764 pl_yylval.opval->op_private |= OPpCONST_STRICT;
6765 if (lastchar != '-') {
6766 if (ckWARN(WARN_RESERVED)) {
6770 if (!*d && !gv_stashpv(PL_tokenbuf, UTF ? SVf_UTF8 : 0))
6772 /* PL_warn_reserved is constant */
6773 GCC_DIAG_IGNORE(-Wformat-nonliteral);
6774 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
6784 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
6785 && saw_infix_sigil) {
6786 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
6787 "Operator or semicolon missing before %c%"UTF8f,
6789 UTF8fARG(UTF, strlen(PL_tokenbuf),
6791 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
6792 "Ambiguous use of %c resolved as operator %c",
6793 lastchar, lastchar);
6800 (OP*)newSVOP(OP_CONST, 0, newSVpv(CopFILE(PL_curcop),0))
6805 (OP*)newSVOP(OP_CONST, 0,
6806 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)))
6809 case KEY___PACKAGE__:
6811 (OP*)newSVOP(OP_CONST, 0,
6813 ? newSVhek(HvNAME_HEK(PL_curstash))
6820 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
6821 HV * const stash = PL_tokenbuf[2] == 'D' && PL_curstash
6824 gv = (GV *)*hv_fetchs(stash, "DATA", 1);
6826 gv_init(gv,stash,"DATA",4,0);
6829 GvIOp(gv) = newIO();
6830 IoIFP(GvIOp(gv)) = PL_rsfp;
6831 #if defined(HAS_FCNTL) && defined(F_SETFD)
6833 const int fd = PerlIO_fileno(PL_rsfp);
6834 fcntl(fd,F_SETFD,fd >= 3);
6837 /* Mark this internal pseudo-handle as clean */
6838 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
6839 if ((PerlIO*)PL_rsfp == PerlIO_stdin())
6840 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
6842 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
6843 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
6844 /* if the script was opened in binmode, we need to revert
6845 * it to text mode for compatibility; but only iff it has CRs
6846 * XXX this is a questionable hack at best. */
6847 if (PL_bufend-PL_bufptr > 2
6848 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
6851 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
6852 loc = PerlIO_tell(PL_rsfp);
6853 (void)PerlIO_seek(PL_rsfp, 0L, 0);
6856 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
6858 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
6859 #endif /* NETWARE */
6861 PerlIO_seek(PL_rsfp, loc, 0);
6865 #ifdef PERLIO_LAYERS
6868 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
6869 else if (PL_encoding) {
6875 XPUSHs(PL_encoding);
6877 call_method("name", G_SCALAR);
6881 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
6882 Perl_form(aTHX_ ":encoding(%"SVf")",
6895 FUN0OP(newPVOP(OP_RUNCV,0,NULL));
6904 if (PL_expect == XSTATE) {
6915 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
6916 if ((*s == ':' && s[1] == ':')
6917 || (!(tmp = keyword(PL_tokenbuf, len, 1)) && *s == '\''))
6921 Copy(PL_bufptr, PL_tokenbuf, olen, char);
6925 Perl_croak(aTHX_ "CORE::%"UTF8f" is not a keyword",
6926 UTF8fARG(UTF, len, PL_tokenbuf));
6929 else if (tmp == KEY_require || tmp == KEY_do
6931 /* that's a way to remember we saw "CORE::" */
6943 LOP(OP_ACCEPT,XTERM);
6946 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_LOWLOGIC)
6951 LOP(OP_ATAN2,XTERM);
6957 LOP(OP_BINMODE,XTERM);
6960 LOP(OP_BLESS,XTERM);
6969 /* We have to disambiguate the two senses of
6970 "continue". If the next token is a '{' then
6971 treat it as the start of a continue block;
6972 otherwise treat it as a control operator.
6982 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
6992 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
7001 if (!PL_cryptseen) {
7002 PL_cryptseen = TRUE;
7006 LOP(OP_CRYPT,XTERM);
7009 LOP(OP_CHMOD,XTERM);
7012 LOP(OP_CHOWN,XTERM);
7015 LOP(OP_CONNECT,XTERM);
7035 d = scan_word(s, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
7037 if (len && (len != 4 || strNE(PL_tokenbuf+1, "CORE"))
7038 && !keyword(PL_tokenbuf + 1, len, 0)) {
7041 force_ident_maybe_lex('&');
7046 if (orig_keyword == KEY_do) {
7055 PL_hints |= HINT_BLOCK_SCOPE;
7065 Perl_populate_isa(aTHX_ STR_WITH_LEN("AnyDBM_File::ISA"),
7066 STR_WITH_LEN("NDBM_File::"),
7067 STR_WITH_LEN("DB_File::"),
7068 STR_WITH_LEN("GDBM_File::"),
7069 STR_WITH_LEN("SDBM_File::"),
7070 STR_WITH_LEN("ODBM_File::"),
7072 LOP(OP_DBMOPEN,XTERM);
7078 PL_expect = XOPERATOR;
7079 s = force_word(s,WORD,TRUE,FALSE);
7086 pl_yylval.ival = CopLINE(PL_curcop);
7090 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
7102 if (*s == '{') { /* block eval */
7103 PL_expect = XTERMBLOCK;
7104 UNIBRACK(OP_ENTERTRY);
7106 else { /* string eval */
7108 UNIBRACK(OP_ENTEREVAL);
7113 UNIBRACK(-OP_ENTEREVAL);
7127 case KEY_endhostent:
7133 case KEY_endservent:
7136 case KEY_endprotoent:
7147 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR)
7149 pl_yylval.ival = CopLINE(PL_curcop);
7151 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
7154 if ((PL_bufend - p) >= 3 &&
7155 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
7157 else if ((PL_bufend - p) >= 4 &&
7158 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
7161 /* skip optional package name, as in "for my abc $x (..)" */
7162 if (isIDFIRST_lazy_if(p,UTF)) {
7163 p = scan_word(p, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
7167 Perl_croak(aTHX_ "Missing $ on loop variable");
7172 LOP(OP_FORMLINE,XTERM);
7181 LOP(OP_FCNTL,XTERM);
7187 LOP(OP_FLOCK,XTERM);
7190 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
7195 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
7200 LOP(OP_GREPSTART, XREF);
7203 PL_expect = XOPERATOR;
7204 s = force_word(s,WORD,TRUE,FALSE);
7219 case KEY_getpriority:
7220 LOP(OP_GETPRIORITY,XTERM);
7222 case KEY_getprotobyname:
7225 case KEY_getprotobynumber:
7226 LOP(OP_GPBYNUMBER,XTERM);
7228 case KEY_getprotoent:
7240 case KEY_getpeername:
7241 UNI(OP_GETPEERNAME);
7243 case KEY_gethostbyname:
7246 case KEY_gethostbyaddr:
7247 LOP(OP_GHBYADDR,XTERM);
7249 case KEY_gethostent:
7252 case KEY_getnetbyname:
7255 case KEY_getnetbyaddr:
7256 LOP(OP_GNBYADDR,XTERM);
7261 case KEY_getservbyname:
7262 LOP(OP_GSBYNAME,XTERM);
7264 case KEY_getservbyport:
7265 LOP(OP_GSBYPORT,XTERM);
7267 case KEY_getservent:
7270 case KEY_getsockname:
7271 UNI(OP_GETSOCKNAME);
7273 case KEY_getsockopt:
7274 LOP(OP_GSOCKOPT,XTERM);
7289 pl_yylval.ival = CopLINE(PL_curcop);
7290 Perl_ck_warner_d(aTHX_
7291 packWARN(WARN_EXPERIMENTAL__SMARTMATCH),
7292 "given is experimental");
7297 orig_keyword==KEY_glob ? -OP_GLOB : OP_GLOB,
7305 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR)
7307 pl_yylval.ival = CopLINE(PL_curcop);
7311 LOP(OP_INDEX,XTERM);
7317 LOP(OP_IOCTL,XTERM);
7329 PL_expect = XOPERATOR;
7330 s = force_word(s,WORD,TRUE,FALSE);
7347 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
7352 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
7366 LOP(OP_LISTEN,XTERM);
7375 s = scan_pat(s,OP_MATCH);
7376 TERM(sublex_start());
7379 LOP(OP_MAPSTART, XREF);
7382 LOP(OP_MKDIR,XTERM);
7385 LOP(OP_MSGCTL,XTERM);
7388 LOP(OP_MSGGET,XTERM);
7391 LOP(OP_MSGRCV,XTERM);
7394 LOP(OP_MSGSND,XTERM);
7399 PL_in_my = (U16)tmp;
7401 if (isIDFIRST_lazy_if(s,UTF)) {
7402 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
7403 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
7405 if (!FEATURE_LEXSUBS_IS_ENABLED)
7407 "Experimental \"%s\" subs not enabled",
7408 tmp == KEY_my ? "my" :
7409 tmp == KEY_state ? "state" : "our");
7410 Perl_ck_warner_d(aTHX_
7411 packWARN(WARN_EXPERIMENTAL__LEXICAL_SUBS),
7412 "The lexical_subs feature is experimental");
7415 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
7416 if (!PL_in_my_stash) {
7420 len = my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
7421 PERL_MY_SNPRINTF_POST_GUARD(len, sizeof(tmpbuf));
7422 yyerror_pv(tmpbuf, UTF ? SVf_UTF8 : 0);
7429 PL_expect = XOPERATOR;
7430 s = force_word(s,WORD,TRUE,FALSE);
7434 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
7439 s = tokenize_use(0, s);
7443 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
7446 if (!PL_lex_allbrackets &&
7447 PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC)
7448 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC;
7454 if (isIDFIRST_lazy_if(s,UTF)) {
7456 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE,
7458 for (t=d; isSPACE(*t);)
7460 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
7462 && !(t[0] == '=' && t[1] == '>')
7463 && !(t[0] == ':' && t[1] == ':')
7464 && !keyword(s, d-s, 0)
7466 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
7467 "Precedence problem: open %"UTF8f" should be open(%"UTF8f")",
7468 UTF8fARG(UTF, d-s, s), UTF8fARG(UTF, d-s, s));
7474 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_LOWLOGIC)
7476 pl_yylval.ival = OP_OR;
7486 LOP(OP_OPEN_DIR,XTERM);
7489 checkcomma(s,PL_tokenbuf,"filehandle");
7493 checkcomma(s,PL_tokenbuf,"filehandle");
7512 s = force_word(s,WORD,FALSE,TRUE);
7514 s = force_strict_version(s);
7515 PL_lex_expect = XBLOCK;
7519 LOP(OP_PIPE_OP,XTERM);
7522 s = scan_str(s,FALSE,FALSE,FALSE,NULL);
7525 COPLINE_SET_FROM_MULTI_END;
7526 pl_yylval.ival = OP_CONST;
7527 TERM(sublex_start());
7534 s = scan_str(s,FALSE,FALSE,FALSE,NULL);
7537 COPLINE_SET_FROM_MULTI_END;
7538 PL_expect = XOPERATOR;
7539 if (SvCUR(PL_lex_stuff)) {
7540 int warned_comma = !ckWARN(WARN_QW);
7541 int warned_comment = warned_comma;
7542 d = SvPV_force(PL_lex_stuff, len);
7544 for (; isSPACE(*d) && len; --len, ++d)
7549 if (!warned_comma || !warned_comment) {
7550 for (; !isSPACE(*d) && len; --len, ++d) {
7551 if (!warned_comma && *d == ',') {
7552 Perl_warner(aTHX_ packWARN(WARN_QW),
7553 "Possible attempt to separate words with commas");
7556 else if (!warned_comment && *d == '#') {
7557 Perl_warner(aTHX_ packWARN(WARN_QW),
7558 "Possible attempt to put comments in qw() list");
7564 for (; !isSPACE(*d) && len; --len, ++d)
7567 sv = newSVpvn_utf8(b, d-b, DO_UTF8(PL_lex_stuff));
7568 words = op_append_elem(OP_LIST, words,
7569 newSVOP(OP_CONST, 0, tokeq(sv)));
7574 words = newNULLLIST();
7576 SvREFCNT_dec(PL_lex_stuff);
7577 PL_lex_stuff = NULL;
7579 PL_expect = XOPERATOR;
7580 pl_yylval.opval = sawparens(words);
7585 s = scan_str(s,FALSE,FALSE,FALSE,NULL);
7588 pl_yylval.ival = OP_STRINGIFY;
7589 if (SvIVX(PL_lex_stuff) == '\'')
7590 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should interpolate */
7591 TERM(sublex_start());
7594 s = scan_pat(s,OP_QR);
7595 TERM(sublex_start());
7598 s = scan_str(s,FALSE,FALSE,FALSE,NULL);
7601 pl_yylval.ival = OP_BACKTICK;
7602 TERM(sublex_start());
7609 PL_expect = XOPERATOR;
7611 s = force_version(s, FALSE);
7613 else if (*s != 'v' || !isDIGIT(s[1])
7614 || (s = force_version(s, TRUE), *s == 'v'))
7616 *PL_tokenbuf = '\0';
7617 s = force_word(s,WORD,TRUE,TRUE);
7618 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
7619 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf),
7620 GV_ADD | (UTF ? SVf_UTF8 : 0));
7622 yyerror("<> at require-statement should be quotes");
7624 if (orig_keyword == KEY_require) {
7632 PL_last_uni = PL_oldbufptr;
7633 PL_last_lop_op = OP_REQUIRE;
7635 return REPORT( (int)REQUIRE );
7641 PL_expect = XOPERATOR;
7642 s = force_word(s,WORD,TRUE,FALSE);
7646 LOP(OP_RENAME,XTERM);
7655 LOP(OP_RINDEX,XTERM);
7664 UNIDOR(OP_READLINE);
7667 UNIDOR(OP_BACKTICK);
7676 LOP(OP_REVERSE,XTERM);
7679 UNIDOR(OP_READLINK);
7686 if (pl_yylval.opval)
7687 TERM(sublex_start());
7689 TOKEN(1); /* force error */
7692 checkcomma(s,PL_tokenbuf,"filehandle");
7702 LOP(OP_SELECT,XTERM);
7708 LOP(OP_SEMCTL,XTERM);
7711 LOP(OP_SEMGET,XTERM);
7714 LOP(OP_SEMOP,XTERM);
7720 LOP(OP_SETPGRP,XTERM);
7722 case KEY_setpriority:
7723 LOP(OP_SETPRIORITY,XTERM);
7725 case KEY_sethostent:
7731 case KEY_setservent:
7734 case KEY_setprotoent:
7744 LOP(OP_SEEKDIR,XTERM);
7746 case KEY_setsockopt:
7747 LOP(OP_SSOCKOPT,XTERM);
7753 LOP(OP_SHMCTL,XTERM);
7756 LOP(OP_SHMGET,XTERM);
7759 LOP(OP_SHMREAD,XTERM);
7762 LOP(OP_SHMWRITE,XTERM);
7765 LOP(OP_SHUTDOWN,XTERM);
7774 LOP(OP_SOCKET,XTERM);
7776 case KEY_socketpair:
7777 LOP(OP_SOCKPAIR,XTERM);
7780 checkcomma(s,PL_tokenbuf,"subroutine name");
7783 s = force_word(s,WORD,TRUE,TRUE);
7787 LOP(OP_SPLIT,XTERM);
7790 LOP(OP_SPRINTF,XTERM);
7793 LOP(OP_SPLICE,XTERM);
7808 LOP(OP_SUBSTR,XTERM);
7814 char * const tmpbuf = PL_tokenbuf + 1;
7815 expectation attrful;
7816 bool have_name, have_proto;
7817 const int key = tmp;
7818 SV *format_name = NULL;
7823 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
7824 (*s == ':' && s[1] == ':'))
7828 attrful = XATTRBLOCK;
7829 d = scan_word(s, tmpbuf, sizeof PL_tokenbuf - 1, TRUE,
7831 if (key == KEY_format)
7832 format_name = S_newSV_maybe_utf8(aTHX_ s, d - s);
7834 if (memchr(tmpbuf, ':', len) || key != KEY_sub
7836 PL_tokenbuf, len + 1, UTF ? SVf_UTF8 : 0
7838 sv_setpvn(PL_subname, tmpbuf, len);
7840 sv_setsv(PL_subname,PL_curstname);
7841 sv_catpvs(PL_subname,"::");
7842 sv_catpvn(PL_subname,tmpbuf,len);
7844 if (SvUTF8(PL_linestr))
7845 SvUTF8_on(PL_subname);
7852 if (key == KEY_my || key == KEY_our || key==KEY_state)
7855 /* diag_listed_as: Missing name in "%s sub" */
7857 "Missing name in \"%s\"", PL_bufptr);
7859 PL_expect = XTERMBLOCK;
7860 attrful = XATTRTERM;
7861 sv_setpvs(PL_subname,"?");
7865 if (key == KEY_format) {
7867 NEXTVAL_NEXTTOKE.opval
7868 = (OP*)newSVOP(OP_CONST,0, format_name);
7869 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
7875 /* Look for a prototype */
7876 if (*s == '(' && !FEATURE_SIGNATURES_IS_ENABLED) {
7877 s = scan_str(s,FALSE,FALSE,FALSE,NULL);
7878 COPLINE_SET_FROM_MULTI_END;
7880 Perl_croak(aTHX_ "Prototype not terminated");
7881 (void)validate_proto(PL_subname, PL_lex_stuff, ckWARN(WARN_ILLEGALPROTO));
7889 if (*s == ':' && s[1] != ':')
7890 PL_expect = attrful;
7891 else if ((*s != '{' && *s != '(') && key == KEY_sub) {
7893 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
7894 else if (*s != ';' && *s != '}')
7895 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
7899 NEXTVAL_NEXTTOKE.opval =
7900 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
7901 PL_lex_stuff = NULL;
7906 sv_setpvs(PL_subname, "__ANON__");
7908 sv_setpvs(PL_subname, "__ANON__::__ANON__");
7911 force_ident_maybe_lex('&');
7916 LOP(OP_SYSTEM,XREF);
7919 LOP(OP_SYMLINK,XTERM);
7922 LOP(OP_SYSCALL,XTERM);
7925 LOP(OP_SYSOPEN,XTERM);
7928 LOP(OP_SYSSEEK,XTERM);
7931 LOP(OP_SYSREAD,XTERM);
7934 LOP(OP_SYSWRITE,XTERM);
7939 TERM(sublex_start());
7960 LOP(OP_TRUNCATE,XTERM);
7972 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR)
7974 pl_yylval.ival = CopLINE(PL_curcop);
7978 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR)
7980 pl_yylval.ival = CopLINE(PL_curcop);
7984 LOP(OP_UNLINK,XTERM);
7990 LOP(OP_UNPACK,XTERM);
7993 LOP(OP_UTIME,XTERM);
7999 LOP(OP_UNSHIFT,XTERM);
8002 s = tokenize_use(1, s);
8012 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR)
8014 pl_yylval.ival = CopLINE(PL_curcop);
8015 Perl_ck_warner_d(aTHX_
8016 packWARN(WARN_EXPERIMENTAL__SMARTMATCH),
8017 "when is experimental");
8021 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR)
8023 pl_yylval.ival = CopLINE(PL_curcop);
8027 PL_hints |= HINT_BLOCK_SCOPE;
8034 LOP(OP_WAITPID,XTERM);
8040 /* Make sure $^L is defined. 0x0C is CTRL-L on ASCII platforms, and
8041 * we use the same number on EBCDIC */
8042 gv_fetchpvs("\x0C", GV_ADD|GV_NOTQUAL, SVt_PV);
8046 if (PL_expect == XOPERATOR) {
8047 if (*s == '=' && !PL_lex_allbrackets &&
8048 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN)
8056 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_LOWLOGIC)
8058 pl_yylval.ival = OP_XOR;
8067 Looks up an identifier in the pad or in a package
8070 PRIVATEREF if this is a lexical name.
8071 WORD if this belongs to a package.
8074 if we're in a my declaration
8075 croak if they tried to say my($foo::bar)
8076 build the ops for a my() declaration
8077 if it's an access to a my() variable
8078 build ops for access to a my() variable
8079 if in a dq string, and they've said @foo and we can't find @foo
8081 build ops for a bareword
8085 S_pending_ident(pTHX)
8088 const char pit = (char)pl_yylval.ival;
8089 const STRLEN tokenbuf_len = strlen(PL_tokenbuf);
8090 /* All routes through this function want to know if there is a colon. */
8091 const char *const has_colon = (const char*) memchr (PL_tokenbuf, ':', tokenbuf_len);
8093 DEBUG_T({ PerlIO_printf(Perl_debug_log,
8094 "### Pending identifier '%s'\n", PL_tokenbuf); });
8096 /* if we're in a my(), we can't allow dynamics here.
8097 $foo'bar has already been turned into $foo::bar, so
8098 just check for colons.
8100 if it's a legal name, the OP is a PADANY.
8103 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
8105 yyerror_pv(Perl_form(aTHX_ "No package name allowed for "
8106 "variable %s in \"our\"",
8107 PL_tokenbuf), UTF ? SVf_UTF8 : 0);
8108 tmp = allocmy(PL_tokenbuf, tokenbuf_len, UTF ? SVf_UTF8 : 0);
8112 /* PL_no_myglob is constant */
8113 GCC_DIAG_IGNORE(-Wformat-nonliteral);
8114 yyerror_pv(Perl_form(aTHX_ PL_no_myglob,
8115 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf),
8116 UTF ? SVf_UTF8 : 0);
8120 pl_yylval.opval = newOP(OP_PADANY, 0);
8121 pl_yylval.opval->op_targ = allocmy(PL_tokenbuf, tokenbuf_len,
8122 UTF ? SVf_UTF8 : 0);
8128 build the ops for accesses to a my() variable.
8133 tmp = pad_findmy_pvn(PL_tokenbuf, tokenbuf_len,
8134 UTF ? SVf_UTF8 : 0);
8135 if (tmp != NOT_IN_PAD) {
8136 /* might be an "our" variable" */
8137 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
8138 /* build ops for a bareword */
8139 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
8140 HEK * const stashname = HvNAME_HEK(stash);
8141 SV * const sym = newSVhek(stashname);
8142 sv_catpvs(sym, "::");
8143 sv_catpvn_flags(sym, PL_tokenbuf+1, tokenbuf_len - 1, (UTF ? SV_CATUTF8 : SV_CATBYTES ));
8144 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
8145 pl_yylval.opval->op_private = OPpCONST_ENTERED;
8149 ? (GV_ADDMULTI | GV_ADDINEVAL)
8152 ((PL_tokenbuf[0] == '$') ? SVt_PV
8153 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
8158 pl_yylval.opval = newOP(OP_PADANY, 0);
8159 pl_yylval.opval->op_targ = tmp;
8165 Whine if they've said @foo in a doublequoted string,
8166 and @foo isn't a variable we can find in the symbol
8169 if (ckWARN(WARN_AMBIGUOUS) &&
8170 pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
8171 GV *const gv = gv_fetchpvn_flags(PL_tokenbuf + 1, tokenbuf_len - 1,
8172 ( UTF ? SVf_UTF8 : 0 ), SVt_PVAV);
8173 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
8174 /* DO NOT warn for @- and @+ */
8175 && !( PL_tokenbuf[2] == '\0' &&
8176 ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
8179 /* Downgraded from fatal to warning 20000522 mjd */
8180 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
8181 "Possible unintended interpolation of %"UTF8f
8183 UTF8fARG(UTF, tokenbuf_len, PL_tokenbuf));
8187 /* build ops for a bareword */
8188 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
8189 newSVpvn_flags(PL_tokenbuf + 1,
8191 UTF ? SVf_UTF8 : 0 ));
8192 pl_yylval.opval->op_private = OPpCONST_ENTERED;
8194 gv_fetchpvn_flags(PL_tokenbuf+1, tokenbuf_len - 1,
8195 (PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD)
8196 | ( UTF ? SVf_UTF8 : 0 ),
8197 ((PL_tokenbuf[0] == '$') ? SVt_PV
8198 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
8204 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
8206 PERL_ARGS_ASSERT_CHECKCOMMA;
8208 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
8209 if (ckWARN(WARN_SYNTAX)) {
8212 for (w = s+2; *w && level; w++) {
8220 /* the list of chars below is for end of statements or
8221 * block / parens, boolean operators (&&, ||, //) and branch
8222 * constructs (or, and, if, until, unless, while, err, for).
8223 * Not a very solid hack... */
8224 if (!*w || !strchr(";&/|})]oaiuwef!=", *w))
8225 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
8226 "%s (...) interpreted as function",name);
8229 while (s < PL_bufend && isSPACE(*s))
8233 while (s < PL_bufend && isSPACE(*s))
8235 if (isIDFIRST_lazy_if(s,UTF)) {
8236 const char * const w = s;
8237 s += UTF ? UTF8SKIP(s) : 1;
8238 while (isWORDCHAR_lazy_if(s,UTF))
8239 s += UTF ? UTF8SKIP(s) : 1;
8240 while (s < PL_bufend && isSPACE(*s))
8244 if (keyword(w, s - w, 0))
8247 gv = gv_fetchpvn_flags(w, s - w, ( UTF ? SVf_UTF8 : 0 ), SVt_PVCV);
8248 if (gv && GvCVu(gv))
8250 Perl_croak(aTHX_ "No comma allowed after %s", what);
8255 /* S_new_constant(): do any overload::constant lookup.
8257 Either returns sv, or mortalizes/frees sv and returns a new SV*.
8258 Best used as sv=new_constant(..., sv, ...).
8259 If s, pv are NULL, calls subroutine with one argument,
8260 and <type> is used with error messages only.
8261 <type> is assumed to be well formed UTF-8 */
8264 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, STRLEN keylen,
8265 SV *sv, SV *pv, const char *type, STRLEN typelen)
8268 HV * table = GvHV(PL_hintgv); /* ^H */
8273 const char *why1 = "", *why2 = "", *why3 = "";
8275 PERL_ARGS_ASSERT_NEW_CONSTANT;
8276 /* We assume that this is true: */
8277 if (*key == 'c') { assert (strEQ(key, "charnames")); }
8280 /* charnames doesn't work well if there have been errors found */
8281 if (PL_error_count > 0 && *key == 'c')
8283 SvREFCNT_dec_NN(sv);
8284 return &PL_sv_undef;
8287 sv_2mortal(sv); /* Parent created it permanently */
8289 || ! (PL_hints & HINT_LOCALIZE_HH)
8290 || ! (cvp = hv_fetch(table, key, keylen, FALSE))
8295 /* Here haven't found what we're looking for. If it is charnames,
8296 * perhaps it needs to be loaded. Try doing that before giving up */
8298 Perl_load_module(aTHX_
8300 newSVpvs("_charnames"),
8301 /* version parameter; no need to specify it, as if
8302 * we get too early a version, will fail anyway,
8303 * not being able to find '_charnames' */
8308 assert(sp == PL_stack_sp);
8309 table = GvHV(PL_hintgv);
8311 && (PL_hints & HINT_LOCALIZE_HH)
8312 && (cvp = hv_fetch(table, key, keylen, FALSE))
8318 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
8319 msg = Perl_form(aTHX_
8320 "Constant(%.*s) unknown",
8321 (int)(type ? typelen : len),
8327 why3 = "} is not defined";
8330 msg = Perl_form(aTHX_
8331 /* The +3 is for '\N{'; -4 for that, plus '}' */
8332 "Unknown charname '%.*s'", (int)typelen - 4, type + 3
8336 msg = Perl_form(aTHX_ "Constant(%.*s): %s%s%s",
8337 (int)(type ? typelen : len),
8338 (type ? type: s), why1, why2, why3);
8341 yyerror_pv(msg, UTF ? SVf_UTF8 : 0);
8342 return SvREFCNT_inc_simple_NN(sv);
8347 pv = newSVpvn_flags(s, len, SVs_TEMP);
8349 typesv = newSVpvn_flags(type, typelen, SVs_TEMP);
8351 typesv = &PL_sv_undef;
8353 PUSHSTACKi(PERLSI_OVERLOAD);
8365 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
8369 /* Check the eval first */
8370 if (!PL_in_eval && ((errsv = ERRSV), SvTRUE_NN(errsv))) {
8372 const char * errstr;
8373 sv_catpvs(errsv, "Propagated");
8374 errstr = SvPV_const(errsv, errlen);
8375 yyerror_pvn(errstr, errlen, 0); /* Duplicates the message inside eval */
8377 res = SvREFCNT_inc_simple_NN(sv);
8381 SvREFCNT_inc_simple_void_NN(res);
8390 why1 = "Call to &{$^H{";
8392 why3 = "}} did not return a defined value";
8394 (void)sv_2mortal(sv);
8401 PERL_STATIC_INLINE void
8402 S_parse_ident(pTHX_ char **s, char **d, char * const e, int allow_package, bool is_utf8) {
8403 PERL_ARGS_ASSERT_PARSE_IDENT;
8407 Perl_croak(aTHX_ "%s", ident_too_long);
8408 if (is_utf8 && isIDFIRST_utf8((U8*)*s)) {
8409 /* The UTF-8 case must come first, otherwise things
8410 * like c\N{COMBINING TILDE} would start failing, as the
8411 * isWORDCHAR_A case below would gobble the 'c' up.
8414 char *t = *s + UTF8SKIP(*s);
8415 while (isIDCONT_utf8((U8*)t))
8417 if (*d + (t - *s) > e)
8418 Perl_croak(aTHX_ "%s", ident_too_long);
8419 Copy(*s, *d, t - *s, char);
8423 else if ( isWORDCHAR_A(**s) ) {
8426 } while (isWORDCHAR_A(**s) && *d < e);
8428 else if (allow_package && **s == '\'' && isIDFIRST_lazy_if(*s+1,is_utf8)) {
8433 else if (allow_package && **s == ':' && (*s)[1] == ':'
8434 /* Disallow things like Foo::$bar. For the curious, this is
8435 * the code path that triggers the "Bad name after" warning
8436 * when looking for barewords.
8438 && (*s)[2] != '$') {
8448 /* Returns a NUL terminated string, with the length of the string written to
8452 S_scan_word(pTHX_ char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
8455 char * const e = d + destlen - 3; /* two-character token, ending NUL */
8456 bool is_utf8 = cBOOL(UTF);
8458 PERL_ARGS_ASSERT_SCAN_WORD;
8460 parse_ident(&s, &d, e, allow_package, is_utf8);
8467 S_scan_ident(pTHX_ char *s, char *dest, STRLEN destlen, I32 ck_uni)
8469 I32 herelines = PL_parser->herelines;
8470 SSize_t bracket = -1;
8473 char * const e = d + destlen - 3; /* two-character token, ending NUL */
8474 bool is_utf8 = cBOOL(UTF);
8475 I32 orig_copline = 0, tmp_copline = 0;
8477 PERL_ARGS_ASSERT_SCAN_IDENT;
8482 while (isDIGIT(*s)) {
8484 Perl_croak(aTHX_ "%s", ident_too_long);
8489 parse_ident(&s, &d, e, 1, is_utf8);
8494 /* Either a digit variable, or parse_ident() found an identifier
8495 (anything valid as a bareword), so job done and return. */
8496 if (PL_lex_state != LEX_NORMAL)
8497 PL_lex_state = LEX_INTERPENDMAYBE;
8500 if (*s == '$' && s[1] &&
8501 (isIDFIRST_lazy_if(s+1,is_utf8)
8502 || isDIGIT_A((U8)s[1])
8505 || strnEQ(s+1,"::",2)) )
8507 /* Dereferencing a value in a scalar variable.
8508 The alternatives are different syntaxes for a scalar variable.
8509 Using ' as a leading package separator isn't allowed. :: is. */
8512 /* Handle the opening { of @{...}, &{...}, *{...}, %{...}, ${...} */
8514 bracket = s - SvPVX(PL_linestr);
8516 orig_copline = CopLINE(PL_curcop);
8517 if (s < PL_bufend && isSPACE(*s)) {
8522 /* Is the byte 'd' a legal single character identifier name? 'u' is true
8523 * iff Unicode semantics are to be used. The legal ones are any of:
8525 * b) ASCII punctuation
8526 * c) When not under Unicode rules, any upper Latin1 character
8527 * d) \c?, \c\, \c^, \c_, and \cA..\cZ, minus the ones that have traditionally
8528 * been matched by \s on ASCII platforms. That is: \c?, plus 1-32, minus
8530 #define VALID_LEN_ONE_IDENT(d, u) (isPUNCT_A((U8)(d)) \
8531 || isDIGIT_A((U8)(d)) \
8532 || (!(u) && !isASCII((U8)(d))) \
8533 || ((((U8)(d)) < 32) \
8534 && (((((U8)(d)) >= 14) \
8535 || (((U8)(d)) <= 8 && (d) != 0) \
8536 || (((U8)(d)) == 13)))) \
8537 || (((U8)(d)) == toCTRL('?')))
8539 && (isIDFIRST_lazy_if(s, is_utf8) || VALID_LEN_ONE_IDENT(*s, is_utf8)))
8541 if ( isCNTRL_A((U8)*s) ) {
8542 deprecate("literal control characters in variable names");
8546 const STRLEN skip = UTF8SKIP(s);
8549 for ( i = 0; i < skip; i++ )
8557 /* Convert $^F, ${^F} and the ^F of ${^FOO} to control characters */
8558 if (*d == '^' && *s && isCONTROLVAR(*s)) {
8562 /* Warn about ambiguous code after unary operators if {...} notation isn't
8563 used. There's no difference in ambiguity; it's merely a heuristic
8564 about when not to warn. */
8565 else if (ck_uni && bracket == -1)
8567 if (bracket != -1) {
8568 /* If we were processing {...} notation then... */
8569 if (isIDFIRST_lazy_if(d,is_utf8)) {
8570 /* if it starts as a valid identifier, assume that it is one.
8571 (the later check for } being at the expected point will trap
8572 cases where this doesn't pan out.) */
8573 d += is_utf8 ? UTF8SKIP(d) : 1;
8574 parse_ident(&s, &d, e, 1, is_utf8);
8576 tmp_copline = CopLINE(PL_curcop);
8577 if (s < PL_bufend && isSPACE(*s)) {
8580 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
8581 /* ${foo[0]} and ${foo{bar}} notation. */
8582 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
8583 const char * const brack =
8585 ((*s == '[') ? "[...]" : "{...}");
8586 orig_copline = CopLINE(PL_curcop);
8587 CopLINE_set(PL_curcop, tmp_copline);
8588 /* diag_listed_as: Ambiguous use of %c{%s[...]} resolved to %c%s[...] */
8589 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
8590 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
8591 funny, dest, brack, funny, dest, brack);
8592 CopLINE_set(PL_curcop, orig_copline);
8595 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
8596 PL_lex_allbrackets++;
8600 /* Handle extended ${^Foo} variables
8601 * 1999-02-27 mjd-perl-patch@plover.com */
8602 else if (! isPRINT(*d) /* isCNTRL(d), plus all non-ASCII */
8606 while (isWORDCHAR(*s) && d < e) {
8610 Perl_croak(aTHX_ "%s", ident_too_long);
8615 tmp_copline = CopLINE(PL_curcop);
8616 if (s < PL_bufend && isSPACE(*s)) {
8620 /* Expect to find a closing } after consuming any trailing whitespace.
8624 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
8625 PL_lex_state = LEX_INTERPEND;
8628 if (PL_lex_state == LEX_NORMAL) {
8629 if (ckWARN(WARN_AMBIGUOUS) &&
8630 (keyword(dest, d - dest, 0)
8631 || get_cvn_flags(dest, d - dest, is_utf8 ? SVf_UTF8 : 0)))
8633 SV *tmp = newSVpvn_flags( dest, d - dest,
8634 SVs_TEMP | (is_utf8 ? SVf_UTF8 : 0) );
8637 orig_copline = CopLINE(PL_curcop);
8638 CopLINE_set(PL_curcop, tmp_copline);
8639 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
8640 "Ambiguous use of %c{%"SVf"} resolved to %c%"SVf,
8641 funny, SVfARG(tmp), funny, SVfARG(tmp));
8642 CopLINE_set(PL_curcop, orig_copline);
8647 /* Didn't find the closing } at the point we expected, so restore
8648 state such that the next thing to process is the opening { and */
8649 s = SvPVX(PL_linestr) + bracket; /* let the parser handle it */
8650 CopLINE_set(PL_curcop, orig_copline);
8651 PL_parser->herelines = herelines;
8655 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
8656 PL_lex_state = LEX_INTERPEND;
8661 S_pmflag(pTHX_ const char* const valid_flags, U32 * pmfl, char** s, char* charset) {
8663 /* Adds, subtracts to/from 'pmfl' based on regex modifier flags found in
8664 * the parse starting at 's', based on the subset that are valid in this
8665 * context input to this routine in 'valid_flags'. Advances s. Returns
8666 * TRUE if the input should be treated as a valid flag, so the next char
8667 * may be as well; otherwise FALSE. 'charset' should point to a NUL upon
8668 * first call on the current regex. This routine will set it to any
8669 * charset modifier found. The caller shouldn't change it. This way,
8670 * another charset modifier encountered in the parse can be detected as an
8671 * error, as we have decided to allow only one */
8674 STRLEN charlen = UTF ? UTF8SKIP(*s) : 1;
8676 if ( charlen != 1 || ! strchr(valid_flags, c) ) {
8677 if (isWORDCHAR_lazy_if(*s, UTF)) {
8678 yyerror_pv(Perl_form(aTHX_ "Unknown regexp modifier \"/%.*s\"", (int)charlen, *s),
8679 UTF ? SVf_UTF8 : 0);
8681 /* Pretend that it worked, so will continue processing before
8690 CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl);
8691 case GLOBAL_PAT_MOD: *pmfl |= PMf_GLOBAL; break;
8692 case CONTINUE_PAT_MOD: *pmfl |= PMf_CONTINUE; break;
8693 case ONCE_PAT_MOD: *pmfl |= PMf_KEEP; break;
8694 case KEEPCOPY_PAT_MOD: *pmfl |= RXf_PMf_KEEPCOPY; break;
8695 case NONDESTRUCT_PAT_MOD: *pmfl |= PMf_NONDESTRUCT; break;
8696 case LOCALE_PAT_MOD:
8698 goto multiple_charsets;
8700 set_regex_charset(pmfl, REGEX_LOCALE_CHARSET);
8703 case UNICODE_PAT_MOD:
8705 goto multiple_charsets;
8707 set_regex_charset(pmfl, REGEX_UNICODE_CHARSET);
8710 case ASCII_RESTRICT_PAT_MOD:
8712 set_regex_charset(pmfl, REGEX_ASCII_RESTRICTED_CHARSET);
8716 /* Error if previous modifier wasn't an 'a', but if it was, see
8717 * if, and accept, a second occurrence (only) */
8719 || get_regex_charset(*pmfl)
8720 != REGEX_ASCII_RESTRICTED_CHARSET)
8722 goto multiple_charsets;
8724 set_regex_charset(pmfl, REGEX_ASCII_MORE_RESTRICTED_CHARSET);
8728 case DEPENDS_PAT_MOD:
8730 goto multiple_charsets;
8732 set_regex_charset(pmfl, REGEX_DEPENDS_CHARSET);
8741 if (*charset != c) {
8742 yyerror(Perl_form(aTHX_ "Regexp modifiers \"/%c\" and \"/%c\" are mutually exclusive", *charset, c));
8744 else if (c == 'a') {
8745 /* diag_listed_as: Regexp modifier "/%c" may appear a maximum of twice */
8746 yyerror("Regexp modifier \"/a\" may appear a maximum of twice");
8749 yyerror(Perl_form(aTHX_ "Regexp modifier \"/%c\" may not appear twice", c));
8752 /* Pretend that it worked, so will continue processing before dieing */
8758 S_scan_pat(pTHX_ char *start, I32 type)
8762 const char * const valid_flags =
8763 (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
8764 char charset = '\0'; /* character set modifier */
8766 PERL_ARGS_ASSERT_SCAN_PAT;
8768 s = scan_str(start,TRUE,FALSE, (PL_in_eval & EVAL_RE_REPARSING), NULL);
8770 Perl_croak(aTHX_ "Search pattern not terminated");
8772 pm = (PMOP*)newPMOP(type, 0);
8773 if (PL_multi_open == '?') {
8774 /* This is the only point in the code that sets PMf_ONCE: */
8775 pm->op_pmflags |= PMf_ONCE;
8777 /* Hence it's safe to do this bit of PMOP book-keeping here, which
8778 allows us to restrict the list needed by reset to just the ??
8780 assert(type != OP_TRANS);
8782 MAGIC *mg = mg_find((const SV *)PL_curstash, PERL_MAGIC_symtab);
8785 mg = sv_magicext(MUTABLE_SV(PL_curstash), 0, PERL_MAGIC_symtab, 0, 0,
8788 elements = mg->mg_len / sizeof(PMOP**);
8789 Renewc(mg->mg_ptr, elements + 1, PMOP*, char);
8790 ((PMOP**)mg->mg_ptr) [elements++] = pm;
8791 mg->mg_len = elements * sizeof(PMOP**);
8792 PmopSTASH_set(pm,PL_curstash);
8796 /* if qr/...(?{..}).../, then need to parse the pattern within a new
8797 * anon CV. False positives like qr/[(?{]/ are harmless */
8799 if (type == OP_QR) {
8801 char *e, *p = SvPV(PL_lex_stuff, len);
8803 for (; p < e; p++) {
8804 if (p[0] == '(' && p[1] == '?'
8805 && (p[2] == '{' || (p[2] == '?' && p[3] == '{')))
8807 pm->op_pmflags |= PMf_HAS_CV;
8811 pm->op_pmflags |= PMf_IS_QR;
8814 while (*s && S_pmflag(aTHX_ valid_flags, &(pm->op_pmflags), &s, &charset)) {};
8815 /* issue a warning if /c is specified,but /g is not */
8816 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL))
8818 Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP),
8819 "Use of /c modifier is meaningless without /g" );
8822 PL_lex_op = (OP*)pm;
8823 pl_yylval.ival = OP_MATCH;
8828 S_scan_subst(pTHX_ char *start)
8835 char charset = '\0'; /* character set modifier */
8838 PERL_ARGS_ASSERT_SCAN_SUBST;
8840 pl_yylval.ival = OP_NULL;
8842 s = scan_str(start, TRUE, FALSE, FALSE, &t);
8845 Perl_croak(aTHX_ "Substitution pattern not terminated");
8849 first_start = PL_multi_start;
8850 first_line = CopLINE(PL_curcop);
8851 s = scan_str(s,FALSE,FALSE,FALSE,NULL);
8854 SvREFCNT_dec(PL_lex_stuff);
8855 PL_lex_stuff = NULL;
8857 Perl_croak(aTHX_ "Substitution replacement not terminated");
8859 PL_multi_start = first_start; /* so whole substitution is taken together */
8861 pm = (PMOP*)newPMOP(OP_SUBST, 0);
8865 if (*s == EXEC_PAT_MOD) {
8869 else if (! S_pmflag(aTHX_ S_PAT_MODS, &(pm->op_pmflags), &s, &charset))
8875 if ((pm->op_pmflags & PMf_CONTINUE)) {
8876 Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
8880 SV * const repl = newSVpvs("");
8883 pm->op_pmflags |= PMf_EVAL;
8886 sv_catpvs(repl, "eval ");
8888 sv_catpvs(repl, "do ");
8890 sv_catpvs(repl, "{");
8891 sv_catsv(repl, PL_sublex_info.repl);
8892 sv_catpvs(repl, "}");
8894 SvREFCNT_dec(PL_sublex_info.repl);
8895 PL_sublex_info.repl = repl;
8897 if (CopLINE(PL_curcop) != first_line) {
8898 sv_upgrade(PL_sublex_info.repl, SVt_PVNV);
8899 ((XPVNV*)SvANY(PL_sublex_info.repl))->xnv_u.xpad_cop_seq.xlow =
8900 CopLINE(PL_curcop) - first_line;
8901 CopLINE_set(PL_curcop, first_line);
8904 PL_lex_op = (OP*)pm;
8905 pl_yylval.ival = OP_SUBST;
8910 S_scan_trans(pTHX_ char *start)
8917 bool nondestruct = 0;
8920 PERL_ARGS_ASSERT_SCAN_TRANS;
8922 pl_yylval.ival = OP_NULL;
8924 s = scan_str(start,FALSE,FALSE,FALSE,&t);
8926 Perl_croak(aTHX_ "Transliteration pattern not terminated");
8930 s = scan_str(s,FALSE,FALSE,FALSE,NULL);
8933 SvREFCNT_dec(PL_lex_stuff);
8934 PL_lex_stuff = NULL;
8936 Perl_croak(aTHX_ "Transliteration replacement not terminated");
8939 complement = del = squash = 0;
8943 complement = OPpTRANS_COMPLEMENT;
8946 del = OPpTRANS_DELETE;
8949 squash = OPpTRANS_SQUASH;
8961 o = newPVOP(nondestruct ? OP_TRANSR : OP_TRANS, 0, (char*)NULL);
8962 o->op_private &= ~OPpTRANS_ALL;
8963 o->op_private |= del|squash|complement|
8964 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
8965 (DO_UTF8(PL_sublex_info.repl) ? OPpTRANS_TO_UTF : 0);
8968 pl_yylval.ival = nondestruct ? OP_TRANSR : OP_TRANS;
8975 Takes a pointer to the first < in <<FOO.
8976 Returns a pointer to the byte following <<FOO.
8978 This function scans a heredoc, which involves different methods
8979 depending on whether we are in a string eval, quoted construct, etc.
8980 This is because PL_linestr could containing a single line of input, or
8981 a whole string being evalled, or the contents of the current quote-
8984 The two basic methods are:
8985 - Steal lines from the input stream
8986 - Scan the heredoc in PL_linestr and remove it therefrom
8988 In a file scope or filtered eval, the first method is used; in a
8989 string eval, the second.
8991 In a quote-like operator, we have to choose between the two,
8992 depending on where we can find a newline. We peek into outer lex-
8993 ing scopes until we find one with a newline in it. If we reach the
8994 outermost lexing scope and it is a file, we use the stream method.
8995 Otherwise it is treated as an eval.
8999 S_scan_heredoc(pTHX_ char *s)
9001 I32 op_type = OP_SCALAR;
9008 const bool infile = PL_rsfp || PL_parser->filtered;
9009 const line_t origline = CopLINE(PL_curcop);
9010 LEXSHARED *shared = PL_parser->lex_shared;
9012 PERL_ARGS_ASSERT_SCAN_HEREDOC;
9015 d = PL_tokenbuf + 1;
9016 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
9017 *PL_tokenbuf = '\n';
9019 while (SPACE_OR_TAB(*peek))
9021 if (*peek == '`' || *peek == '\'' || *peek =='"') {
9024 s = delimcpy(d, e, s, PL_bufend, term, &len);
9026 Perl_croak(aTHX_ "Unterminated delimiter for here document");
9032 /* <<\FOO is equivalent to <<'FOO' */
9036 if (!isWORDCHAR_lazy_if(s,UTF))
9037 deprecate("bare << to mean <<\"\"");
9038 for (; isWORDCHAR_lazy_if(s,UTF); s++) {
9043 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
9044 Perl_croak(aTHX_ "Delimiter for here document is too long");
9047 len = d - PL_tokenbuf;
9049 #ifndef PERL_STRICT_CR
9050 d = strchr(s, '\r');
9052 char * const olds = s;
9054 while (s < PL_bufend) {
9060 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
9069 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
9074 tmpstr = newSV_type(SVt_PVIV);
9078 SvIV_set(tmpstr, -1);
9080 else if (term == '`') {
9081 op_type = OP_BACKTICK;
9082 SvIV_set(tmpstr, '\\');
9085 PL_multi_start = origline + 1 + PL_parser->herelines;
9086 PL_multi_open = PL_multi_close = '<';
9087 /* inside a string eval or quote-like operator */
9088 if (!infile || PL_lex_inwhat) {
9091 char * const olds = s;
9092 PERL_CONTEXT * const cx = &cxstack[cxstack_ix];
9093 /* These two fields are not set until an inner lexing scope is
9094 entered. But we need them set here. */
9095 shared->ls_bufptr = s;
9096 shared->ls_linestr = PL_linestr;
9098 /* Look for a newline. If the current buffer does not have one,
9099 peek into the line buffer of the parent lexing scope, going
9100 up as many levels as necessary to find one with a newline
9103 while (!(s = (char *)memchr(
9104 (void *)shared->ls_bufptr, '\n',
9105 SvEND(shared->ls_linestr)-shared->ls_bufptr
9107 shared = shared->ls_prev;
9108 /* shared is only null if we have gone beyond the outermost
9109 lexing scope. In a file, we will have broken out of the
9110 loop in the previous iteration. In an eval, the string buf-
9111 fer ends with "\n;", so the while condition above will have
9112 evaluated to false. So shared can never be null. */
9114 /* A LEXSHARED struct with a null ls_prev pointer is the outer-
9115 most lexing scope. In a file, shared->ls_linestr at that
9116 level is just one line, so there is no body to steal. */
9117 if (infile && !shared->ls_prev) {
9123 s = (char*)memchr((void*)s, '\n', PL_bufend - s);
9126 linestr = shared->ls_linestr;
9127 bufend = SvEND(linestr);
9129 while (s < bufend - len + 1 &&
9130 memNE(s,PL_tokenbuf,len) ) {
9132 ++PL_parser->herelines;
9134 if (s >= bufend - len + 1) {
9137 sv_setpvn(tmpstr,d+1,s-d);
9139 /* the preceding stmt passes a newline */
9140 PL_parser->herelines++;
9142 /* s now points to the newline after the heredoc terminator.
9143 d points to the newline before the body of the heredoc.
9146 /* We are going to modify linestr in place here, so set
9147 aside copies of the string if necessary for re-evals or
9149 /* See the Paranoia note in case LEX_INTERPEND in yylex, for why we
9150 check shared->re_eval_str. */
9151 if (shared->re_eval_start || shared->re_eval_str) {
9152 /* Set aside the rest of the regexp */
9153 if (!shared->re_eval_str)
9154 shared->re_eval_str =
9155 newSVpvn(shared->re_eval_start,
9156 bufend - shared->re_eval_start);
9157 shared->re_eval_start -= s-d;
9159 if (cxstack_ix >= 0 && CxTYPE(cx) == CXt_EVAL &&
9160 CxOLD_OP_TYPE(cx) == OP_ENTEREVAL &&
9161 cx->blk_eval.cur_text == linestr)
9163 cx->blk_eval.cur_text = newSVsv(linestr);
9164 SvSCREAM_on(cx->blk_eval.cur_text);
9166 /* Copy everything from s onwards back to d. */
9167 Move(s,d,bufend-s + 1,char);
9168 SvCUR_set(linestr, SvCUR(linestr) - (s-d));
9169 /* Setting PL_bufend only applies when we have not dug deeper
9170 into other scopes, because sublex_done sets PL_bufend to
9171 SvEND(PL_linestr). */
9172 if (shared == PL_parser->lex_shared) PL_bufend = SvEND(linestr);
9179 sv_setpvs(tmpstr,""); /* avoid "uninitialized" warning */
9180 term = PL_tokenbuf[1];
9182 linestr_save = PL_linestr; /* must restore this afterwards */
9183 d = s; /* and this */
9184 PL_linestr = newSVpvs("");
9185 PL_bufend = SvPVX(PL_linestr);
9187 PL_bufptr = PL_bufend;
9188 CopLINE_set(PL_curcop,
9189 origline + 1 + PL_parser->herelines);
9190 if (!lex_next_chunk(LEX_NO_TERM)
9191 && (!SvCUR(tmpstr) || SvEND(tmpstr)[-1] != '\n')) {
9192 SvREFCNT_dec(linestr_save);
9195 CopLINE_set(PL_curcop, origline);
9196 if (!SvCUR(PL_linestr) || PL_bufend[-1] != '\n') {
9197 s = lex_grow_linestr(SvLEN(PL_linestr) + 3);
9198 /* ^That should be enough to avoid this needing to grow: */
9199 sv_catpvs(PL_linestr, "\n\0");
9200 assert(s == SvPVX(PL_linestr));
9201 PL_bufend = SvEND(PL_linestr);
9204 PL_parser->herelines++;
9205 PL_last_lop = PL_last_uni = NULL;
9206 #ifndef PERL_STRICT_CR
9207 if (PL_bufend - PL_linestart >= 2) {
9208 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
9209 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
9211 PL_bufend[-2] = '\n';
9213 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
9215 else if (PL_bufend[-1] == '\r')
9216 PL_bufend[-1] = '\n';
9218 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
9219 PL_bufend[-1] = '\n';
9221 if (*s == term && memEQ(s,PL_tokenbuf + 1,len)) {
9222 SvREFCNT_dec(PL_linestr);
9223 PL_linestr = linestr_save;
9224 PL_linestart = SvPVX(linestr_save);
9225 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9230 sv_catsv(tmpstr,PL_linestr);
9234 PL_multi_end = origline + PL_parser->herelines;
9235 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
9236 SvPV_shrink_to_cur(tmpstr);
9239 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
9241 else if (PL_encoding)
9242 sv_recode_to_utf8(tmpstr, PL_encoding);
9244 PL_lex_stuff = tmpstr;
9245 pl_yylval.ival = op_type;
9249 SvREFCNT_dec(tmpstr);
9250 CopLINE_set(PL_curcop, origline);
9251 missingterm(PL_tokenbuf + 1);
9255 takes: current position in input buffer
9256 returns: new position in input buffer
9257 side-effects: pl_yylval and lex_op are set.
9262 <FH> read from filehandle
9263 <pkg::FH> read from package qualified filehandle
9264 <pkg'FH> read from package qualified filehandle
9265 <$fh> read from filehandle in $fh
9271 S_scan_inputsymbol(pTHX_ char *start)
9273 char *s = start; /* current position in buffer */
9276 char *d = PL_tokenbuf; /* start of temp holding space */
9277 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
9279 PERL_ARGS_ASSERT_SCAN_INPUTSYMBOL;
9281 end = strchr(s, '\n');
9284 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
9286 /* die if we didn't have space for the contents of the <>,
9287 or if it didn't end, or if we see a newline
9290 if (len >= (I32)sizeof PL_tokenbuf)
9291 Perl_croak(aTHX_ "Excessively long <> operator");
9293 Perl_croak(aTHX_ "Unterminated <> operator");
9298 Remember, only scalar variables are interpreted as filehandles by
9299 this code. Anything more complex (e.g., <$fh{$num}>) will be
9300 treated as a glob() call.
9301 This code makes use of the fact that except for the $ at the front,
9302 a scalar variable and a filehandle look the same.
9304 if (*d == '$' && d[1]) d++;
9306 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
9307 while (*d && (isWORDCHAR_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
9308 d += UTF ? UTF8SKIP(d) : 1;
9310 /* If we've tried to read what we allow filehandles to look like, and
9311 there's still text left, then it must be a glob() and not a getline.
9312 Use scan_str to pull out the stuff between the <> and treat it
9313 as nothing more than a string.
9316 if (d - PL_tokenbuf != len) {
9317 pl_yylval.ival = OP_GLOB;
9318 s = scan_str(start,FALSE,FALSE,FALSE,NULL);
9320 Perl_croak(aTHX_ "Glob not terminated");
9324 bool readline_overriden = FALSE;
9326 /* we're in a filehandle read situation */
9329 /* turn <> into <ARGV> */
9331 Copy("ARGV",d,5,char);
9333 /* Check whether readline() is overriden */
9334 if ((gv_readline = gv_override("readline",8)))
9335 readline_overriden = TRUE;
9337 /* if <$fh>, create the ops to turn the variable into a
9341 /* try to find it in the pad for this block, otherwise find
9342 add symbol table ops
9344 const PADOFFSET tmp = pad_findmy_pvn(d, len, UTF ? SVf_UTF8 : 0);
9345 if (tmp != NOT_IN_PAD) {
9346 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
9347 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
9348 HEK * const stashname = HvNAME_HEK(stash);
9349 SV * const sym = sv_2mortal(newSVhek(stashname));
9350 sv_catpvs(sym, "::");
9356 OP * const o = newOP(OP_PADSV, 0);
9358 PL_lex_op = readline_overriden
9359 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9360 op_append_elem(OP_LIST, o,
9361 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
9362 : (OP*)newUNOP(OP_READLINE, 0, o);
9371 ? (GV_ADDMULTI | GV_ADDINEVAL)
9372 : GV_ADDMULTI) | ( UTF ? SVf_UTF8 : 0 ),
9374 PL_lex_op = readline_overriden
9375 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9376 op_append_elem(OP_LIST,
9377 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
9378 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9379 : (OP*)newUNOP(OP_READLINE, 0,
9380 newUNOP(OP_RV2SV, 0,
9381 newGVOP(OP_GV, 0, gv)));
9383 /* we created the ops in PL_lex_op, so make pl_yylval.ival a null op */
9384 pl_yylval.ival = OP_NULL;
9387 /* If it's none of the above, it must be a literal filehandle
9388 (<Foo::BAR> or <FOO>) so build a simple readline OP */
9390 GV * const gv = gv_fetchpv(d, GV_ADD | ( UTF ? SVf_UTF8 : 0 ), SVt_PVIO);
9391 PL_lex_op = readline_overriden
9392 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9393 op_append_elem(OP_LIST,
9394 newGVOP(OP_GV, 0, gv),
9395 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9396 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
9397 pl_yylval.ival = OP_NULL;
9407 start position in buffer
9408 keep_bracketed_quoted preserve \ quoting of embedded delimiters, but
9409 only if they are of the open/close form
9410 keep_delims preserve the delimiters around the string
9411 re_reparse compiling a run-time /(?{})/:
9412 collapse // to /, and skip encoding src
9413 delimp if non-null, this is set to the position of
9414 the closing delimiter, or just after it if
9415 the closing and opening delimiters differ
9416 (i.e., the opening delimiter of a substitu-
9418 returns: position to continue reading from buffer
9419 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
9420 updates the read buffer.
9422 This subroutine pulls a string out of the input. It is called for:
9423 q single quotes q(literal text)
9424 ' single quotes 'literal text'
9425 qq double quotes qq(interpolate $here please)
9426 " double quotes "interpolate $here please"
9427 qx backticks qx(/bin/ls -l)
9428 ` backticks `/bin/ls -l`
9429 qw quote words @EXPORT_OK = qw( func() $spam )
9430 m// regexp match m/this/
9431 s/// regexp substitute s/this/that/
9432 tr/// string transliterate tr/this/that/
9433 y/// string transliterate y/this/that/
9434 ($*@) sub prototypes sub foo ($)
9435 (stuff) sub attr parameters sub foo : attr(stuff)
9436 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
9438 In most of these cases (all but <>, patterns and transliterate)
9439 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
9440 calls scan_str(). s/// makes yylex() call scan_subst() which calls
9441 scan_str(). tr/// and y/// make yylex() call scan_trans() which
9444 It skips whitespace before the string starts, and treats the first
9445 character as the delimiter. If the delimiter is one of ([{< then
9446 the corresponding "close" character )]}> is used as the closing
9447 delimiter. It allows quoting of delimiters, and if the string has
9448 balanced delimiters ([{<>}]) it allows nesting.
9450 On success, the SV with the resulting string is put into lex_stuff or,
9451 if that is already non-NULL, into lex_repl. The second case occurs only
9452 when parsing the RHS of the special constructs s/// and tr/// (y///).
9453 For convenience, the terminating delimiter character is stuffed into
9458 S_scan_str(pTHX_ char *start, int keep_bracketed_quoted, int keep_delims, int re_reparse,
9462 SV *sv; /* scalar value: string */
9463 const char *tmps; /* temp string, used for delimiter matching */
9464 char *s = start; /* current position in the buffer */
9465 char term; /* terminating character */
9466 char *to; /* current position in the sv's data */
9467 I32 brackets = 1; /* bracket nesting level */
9468 bool has_utf8 = FALSE; /* is there any utf8 content? */
9469 I32 termcode; /* terminating char. code */
9470 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
9471 STRLEN termlen; /* length of terminating string */
9472 int last_off = 0; /* last position for nesting bracket */
9475 PERL_ARGS_ASSERT_SCAN_STR;
9477 /* skip space before the delimiter */
9482 /* mark where we are, in case we need to report errors */
9485 /* after skipping whitespace, the next character is the terminator */
9488 termcode = termstr[0] = term;
9492 termcode = utf8_to_uvchr_buf((U8*)s, (U8*)PL_bufend, &termlen);
9493 Copy(s, termstr, termlen, U8);
9494 if (!UTF8_IS_INVARIANT(term))
9498 /* mark where we are */
9499 PL_multi_start = CopLINE(PL_curcop);
9500 PL_multi_open = term;
9501 herelines = PL_parser->herelines;
9503 /* find corresponding closing delimiter */
9504 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
9505 termcode = termstr[0] = term = tmps[5];
9507 PL_multi_close = term;
9509 if (PL_multi_open == PL_multi_close) {
9510 keep_bracketed_quoted = FALSE;
9513 /* create a new SV to hold the contents. 79 is the SV's initial length.
9514 What a random number. */
9515 sv = newSV_type(SVt_PVIV);
9517 SvIV_set(sv, termcode);
9518 (void)SvPOK_only(sv); /* validate pointer */
9520 /* move past delimiter and try to read a complete string */
9522 sv_catpvn(sv, s, termlen);
9525 if (PL_encoding && !UTF && !re_reparse) {
9529 int offset = s - SvPVX_const(PL_linestr);
9530 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
9531 &offset, (char*)termstr, termlen);
9535 if (SvIsCOW(PL_linestr)) {
9536 STRLEN bufend_pos, bufptr_pos, oldbufptr_pos;
9537 STRLEN oldoldbufptr_pos, linestart_pos, last_uni_pos;
9538 STRLEN last_lop_pos, re_eval_start_pos, s_pos;
9539 char *buf = SvPVX(PL_linestr);
9540 bufend_pos = PL_parser->bufend - buf;
9541 bufptr_pos = PL_parser->bufptr - buf;
9542 oldbufptr_pos = PL_parser->oldbufptr - buf;
9543 oldoldbufptr_pos = PL_parser->oldoldbufptr - buf;
9544 linestart_pos = PL_parser->linestart - buf;
9545 last_uni_pos = PL_parser->last_uni
9546 ? PL_parser->last_uni - buf
9548 last_lop_pos = PL_parser->last_lop
9549 ? PL_parser->last_lop - buf
9552 PL_parser->lex_shared->re_eval_start ?
9553 PL_parser->lex_shared->re_eval_start - buf : 0;
9556 sv_force_normal(PL_linestr);
9558 buf = SvPVX(PL_linestr);
9559 PL_parser->bufend = buf + bufend_pos;
9560 PL_parser->bufptr = buf + bufptr_pos;
9561 PL_parser->oldbufptr = buf + oldbufptr_pos;
9562 PL_parser->oldoldbufptr = buf + oldoldbufptr_pos;
9563 PL_parser->linestart = buf + linestart_pos;
9564 if (PL_parser->last_uni)
9565 PL_parser->last_uni = buf + last_uni_pos;
9566 if (PL_parser->last_lop)
9567 PL_parser->last_lop = buf + last_lop_pos;
9568 if (PL_parser->lex_shared->re_eval_start)
9569 PL_parser->lex_shared->re_eval_start =
9570 buf + re_eval_start_pos;
9573 ns = SvPVX_const(PL_linestr) + offset;
9574 svlast = SvEND(sv) - 1;
9576 for (; s < ns; s++) {
9577 if (*s == '\n' && !PL_rsfp && !PL_parser->filtered)
9578 COPLINE_INC_WITH_HERELINES;
9581 goto read_more_line;
9583 /* handle quoted delimiters */
9584 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
9586 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
9588 if ((svlast-1 - t) % 2) {
9589 if (!keep_bracketed_quoted) {
9592 SvCUR_set(sv, SvCUR(sv) - 1);
9597 if (PL_multi_open == PL_multi_close) {
9603 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
9604 /* At here, all closes are "was quoted" one,
9605 so we don't check PL_multi_close. */
9607 if (!keep_bracketed_quoted && *(t+1) == PL_multi_open)
9612 else if (*t == PL_multi_open)
9620 SvCUR_set(sv, w - SvPVX_const(sv));
9622 last_off = w - SvPVX(sv);
9623 if (--brackets <= 0)
9629 SvCUR_set(sv, SvCUR(sv) - 1);
9635 /* extend sv if need be */
9636 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
9637 /* set 'to' to the next character in the sv's string */
9638 to = SvPVX(sv)+SvCUR(sv);
9640 /* if open delimiter is the close delimiter read unbridle */
9641 if (PL_multi_open == PL_multi_close) {
9642 for (; s < PL_bufend; s++,to++) {
9643 /* embedded newlines increment the current line number */
9644 if (*s == '\n' && !PL_rsfp && !PL_parser->filtered)
9645 COPLINE_INC_WITH_HERELINES;
9646 /* handle quoted delimiters */
9647 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
9648 if (!keep_bracketed_quoted
9650 || (re_reparse && s[1] == '\\'))
9653 else /* any other quotes are simply copied straight through */
9656 /* terminate when run out of buffer (the for() condition), or
9657 have found the terminator */
9658 else if (*s == term) {
9661 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
9664 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
9670 /* if the terminator isn't the same as the start character (e.g.,
9671 matched brackets), we have to allow more in the quoting, and
9672 be prepared for nested brackets.
9675 /* read until we run out of string, or we find the terminator */
9676 for (; s < PL_bufend; s++,to++) {
9677 /* embedded newlines increment the line count */
9678 if (*s == '\n' && !PL_rsfp && !PL_parser->filtered)
9679 COPLINE_INC_WITH_HERELINES;
9680 /* backslashes can escape the open or closing characters */
9681 if (*s == '\\' && s+1 < PL_bufend) {
9682 if (!keep_bracketed_quoted &&
9683 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
9690 /* allow nested opens and closes */
9691 else if (*s == PL_multi_close && --brackets <= 0)
9693 else if (*s == PL_multi_open)
9695 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
9700 /* terminate the copied string and update the sv's end-of-string */
9702 SvCUR_set(sv, to - SvPVX_const(sv));
9705 * this next chunk reads more into the buffer if we're not done yet
9709 break; /* handle case where we are done yet :-) */
9711 #ifndef PERL_STRICT_CR
9712 if (to - SvPVX_const(sv) >= 2) {
9713 if ((to[-2] == '\r' && to[-1] == '\n') ||
9714 (to[-2] == '\n' && to[-1] == '\r'))
9718 SvCUR_set(sv, to - SvPVX_const(sv));
9720 else if (to[-1] == '\r')
9723 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
9728 /* if we're out of file, or a read fails, bail and reset the current
9729 line marker so we can report where the unterminated string began
9731 COPLINE_INC_WITH_HERELINES;
9732 PL_bufptr = PL_bufend;
9733 if (!lex_next_chunk(0)) {
9735 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9741 /* at this point, we have successfully read the delimited string */
9743 if (!PL_encoding || UTF || re_reparse) {
9746 sv_catpvn(sv, s, termlen);
9749 if (has_utf8 || (PL_encoding && !re_reparse))
9752 PL_multi_end = CopLINE(PL_curcop);
9753 CopLINE_set(PL_curcop, PL_multi_start);
9754 PL_parser->herelines = herelines;
9756 /* if we allocated too much space, give some back */
9757 if (SvCUR(sv) + 5 < SvLEN(sv)) {
9758 SvLEN_set(sv, SvCUR(sv) + 1);
9759 SvPV_renew(sv, SvLEN(sv));
9762 /* decide whether this is the first or second quoted string we've read
9767 PL_sublex_info.repl = sv;
9770 if (delimp) *delimp = PL_multi_open == PL_multi_close ? s-termlen : s;
9776 takes: pointer to position in buffer
9777 returns: pointer to new position in buffer
9778 side-effects: builds ops for the constant in pl_yylval.op
9780 Read a number in any of the formats that Perl accepts:
9782 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
9783 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
9786 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
9788 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
9791 If it reads a number without a decimal point or an exponent, it will
9792 try converting the number to an integer and see if it can do so
9793 without loss of precision.
9797 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
9799 const char *s = start; /* current position in buffer */
9800 char *d; /* destination in temp buffer */
9801 char *e; /* end of temp buffer */
9802 NV nv; /* number read, as a double */
9803 SV *sv = NULL; /* place to put the converted number */
9804 bool floatit; /* boolean: int or float? */
9805 const char *lastub = NULL; /* position of last underbar */
9806 static const char* const number_too_long = "Number too long";
9807 /* Hexadecimal floating point.
9809 * In many places (where we have quads and NV is IEEE 754 double)
9810 * we can fit the mantissa bits of a NV into an unsigned quad.
9811 * (Note that UVs might not be quads even when we have quads.)
9812 * This will not work everywhere, though (either no quads, or
9813 * using long doubles), in which case we have to resort to NV,
9814 * which will probably mean horrible loss of precision due to
9815 * multiple fp operations. */
9818 #if NVSIZE == 8 && defined(HAS_QUAD) && defined(Uquad_t)
9819 # define HEXFP_UQUAD
9820 Uquad_t hexfp_uquad = 0;
9821 int hexfp_frac_bits = 0;
9826 NV hexfp_mult = 1.0;
9827 UV high_non_zero = 0; /* highest digit */
9829 PERL_ARGS_ASSERT_SCAN_NUM;
9831 /* We use the first character to decide what type of number this is */
9835 Perl_croak(aTHX_ "panic: scan_num, *s=%d", *s);
9837 /* if it starts with a 0, it could be an octal number, a decimal in
9838 0.13 disguise, or a hexadecimal number, or a binary number. */
9842 u holds the "number so far"
9843 shift the power of 2 of the base
9844 (hex == 4, octal == 3, binary == 1)
9845 overflowed was the number more than we can hold?
9847 Shift is used when we add a digit. It also serves as an "are
9848 we in octal/hex/binary?" indicator to disallow hex characters
9854 bool overflowed = FALSE;
9855 bool just_zero = TRUE; /* just plain 0 or binary number? */
9856 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
9857 static const char* const bases[5] =
9858 { "", "binary", "", "octal", "hexadecimal" };
9859 static const char* const Bases[5] =
9860 { "", "Binary", "", "Octal", "Hexadecimal" };
9861 static const char* const maxima[5] =
9863 "0b11111111111111111111111111111111",
9867 const char *base, *Base, *max;
9870 if (s[1] == 'x' || s[1] == 'X') {
9874 } else if (s[1] == 'b' || s[1] == 'B') {
9879 /* check for a decimal in disguise */
9880 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
9882 /* so it must be octal */
9889 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
9890 "Misplaced _ in number");
9894 base = bases[shift];
9895 Base = Bases[shift];
9896 max = maxima[shift];
9898 /* read the rest of the number */
9900 /* x is used in the overflow test,
9901 b is the digit we're adding on. */
9906 /* if we don't mention it, we're done */
9910 /* _ are ignored -- but warned about if consecutive */
9912 if (lastub && s == lastub + 1)
9913 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
9914 "Misplaced _ in number");
9918 /* 8 and 9 are not octal */
9921 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
9925 case '2': case '3': case '4':
9926 case '5': case '6': case '7':
9928 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
9932 b = *s++ & 15; /* ASCII digit -> value of digit */
9936 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
9937 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
9938 /* make sure they said 0x */
9943 /* Prepare to put the digit we have onto the end
9944 of the number so far. We check for overflows.
9950 x = u << shift; /* make room for the digit */
9952 total_bits += shift;
9954 if ((x >> shift) != u
9955 && !(PL_hints & HINT_NEW_BINARY)) {
9958 Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW),
9959 "Integer overflow in %s number",
9962 u = x | b; /* add the digit to the end */
9965 n *= nvshift[shift];
9966 /* If an NV has not enough bits in its
9967 * mantissa to represent an UV this summing of
9968 * small low-order numbers is a waste of time
9969 * (because the NV cannot preserve the
9970 * low-order bits anyway): we could just
9971 * remember when did we overflow and in the
9972 * end just multiply n by the right
9977 if (high_non_zero == 0 && b > 0)
9980 /* this could be hexfp, but peek ahead
9981 * to avoid matching ".." */
9982 #define HEXFP_PEEK(s) \
9983 (((s[0] == '.') && \
9984 (isXDIGIT(s[1]) || s[1] == 'p' || s[1] == 'P')) \
9985 || s[0] == 'p' || s[0] == 'P')
9986 if (UNLIKELY(HEXFP_PEEK(s))) {
9994 /* if we get here, we had success: make a scalar value from
9999 /* final misplaced underbar check */
10000 if (s[-1] == '_') {
10001 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10004 if (UNLIKELY(HEXFP_PEEK(s))) {
10005 /* Do sloppy (on the underbars) but quick detection
10006 * (and value construction) for hexfp, the decimal
10007 * detection will shortly be more thorough with the
10008 * underbar checks. */
10012 #else /* HEXFP_NV */
10017 NV mult = 1 / 16.0;
10020 while (isXDIGIT(*h) || *h == '_') {
10021 if (isXDIGIT(*h)) {
10022 U8 b = XDIGIT_VALUE(*h);
10023 total_bits += shift;
10025 hexfp_uquad <<= shift;
10027 hexfp_frac_bits += shift;
10028 #else /* HEXFP_NV */
10029 hexfp_nv += b * mult;
10037 if (total_bits >= 4) {
10038 if (high_non_zero < 0x8)
10040 if (high_non_zero < 0x4)
10042 if (high_non_zero < 0x2)
10046 if (total_bits > 0 && (*h == 'p' || *h == 'P')) {
10047 bool negexp = FALSE;
10051 else if (*h == '-') {
10057 while (isDIGIT(*h) || *h == '_') {
10060 hexfp_exp += *h - '0';
10063 -hexfp_exp < NV_MIN_EXP - 1) {
10064 Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW),
10065 "Hexadecimal float: exponent underflow");
10072 hexfp_exp > NV_MAX_EXP - 1) {
10073 Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW),
10074 "Hexadecimal float: exponent overflow");
10083 hexfp_exp = -hexfp_exp;
10085 hexfp_exp -= hexfp_frac_bits;
10087 hexfp_mult = pow(2.0, hexfp_exp);
10095 if (n > 4294967295.0)
10096 Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
10097 "%s number > %s non-portable",
10103 if (u > 0xffffffff)
10104 Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
10105 "%s number > %s non-portable",
10110 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
10111 sv = new_constant(start, s - start, "integer",
10112 sv, NULL, NULL, 0);
10113 else if (PL_hints & HINT_NEW_BINARY)
10114 sv = new_constant(start, s - start, "binary", sv, NULL, NULL, 0);
10119 handle decimal numbers.
10120 we're also sent here when we read a 0 as the first digit
10122 case '1': case '2': case '3': case '4': case '5':
10123 case '6': case '7': case '8': case '9': case '.':
10126 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
10135 /* read next group of digits and _ and copy into d */
10136 while (isDIGIT(*s) || *s == '_' ||
10137 UNLIKELY(hexfp && isXDIGIT(*s))) {
10138 /* skip underscores, checking for misplaced ones
10142 if (lastub && s == lastub + 1)
10143 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
10144 "Misplaced _ in number");
10148 /* check for end of fixed-length buffer */
10150 Perl_croak(aTHX_ "%s", number_too_long);
10151 /* if we're ok, copy the character */
10156 /* final misplaced underbar check */
10157 if (lastub && s == lastub + 1) {
10158 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10161 /* read a decimal portion if there is one. avoid
10162 3..5 being interpreted as the number 3. followed
10165 if (*s == '.' && s[1] != '.') {
10170 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
10171 "Misplaced _ in number");
10175 /* copy, ignoring underbars, until we run out of digits.
10177 for (; isDIGIT(*s) || *s == '_' ||
10178 UNLIKELY(hexfp && isXDIGIT(*s));
10180 /* fixed length buffer check */
10182 Perl_croak(aTHX_ "%s", number_too_long);
10184 if (lastub && s == lastub + 1)
10185 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
10186 "Misplaced _ in number");
10192 /* fractional part ending in underbar? */
10193 if (s[-1] == '_') {
10194 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
10195 "Misplaced _ in number");
10197 if (*s == '.' && isDIGIT(s[1])) {
10198 /* oops, it's really a v-string, but without the "v" */
10204 /* read exponent part, if present */
10205 if (((*s == 'e' || *s == 'E') ||
10206 UNLIKELY(hexfp && (*s == 'p' || *s == 'P'))) &&
10207 strchr("+-0123456789_", s[1])) {
10210 /* regardless of whether user said 3E5 or 3e5, use lower 'e',
10211 ditto for p (hexfloats) */
10212 if ((*s == 'e' || *s == 'E')) {
10213 /* At least some Mach atof()s don't grok 'E' */
10216 else if (UNLIKELY(hexfp && (*s == 'p' || *s == 'P'))) {
10223 /* stray preinitial _ */
10225 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
10226 "Misplaced _ in number");
10230 /* allow positive or negative exponent */
10231 if (*s == '+' || *s == '-')
10234 /* stray initial _ */
10236 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
10237 "Misplaced _ in number");
10241 /* read digits of exponent */
10242 while (isDIGIT(*s) || *s == '_') {
10245 Perl_croak(aTHX_ "%s", number_too_long);
10249 if (((lastub && s == lastub + 1) ||
10250 (!isDIGIT(s[1]) && s[1] != '_')))
10251 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
10252 "Misplaced _ in number");
10260 We try to do an integer conversion first if no characters
10261 indicating "float" have been found.
10266 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
10268 if (flags == IS_NUMBER_IN_UV) {
10270 sv = newSViv(uv); /* Prefer IVs over UVs. */
10273 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
10274 if (uv <= (UV) IV_MIN)
10275 sv = newSViv(-(IV)uv);
10282 STORE_NUMERIC_LOCAL_SET_STANDARD();
10283 /* terminate the string */
10285 if (UNLIKELY(hexfp)) {
10286 # ifdef NV_MANT_DIG
10287 if (total_bits > NV_MANT_DIG)
10288 Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW),
10289 "Hexadecimal float: mantissa overflow");
10292 nv = hexfp_uquad * hexfp_mult;
10293 #else /* HEXFP_NV */
10294 nv = hexfp_nv * hexfp_mult;
10297 nv = Atof(PL_tokenbuf);
10299 RESTORE_NUMERIC_LOCAL();
10304 ? (PL_hints & HINT_NEW_FLOAT) : (PL_hints & HINT_NEW_INTEGER) ) {
10305 const char *const key = floatit ? "float" : "integer";
10306 const STRLEN keylen = floatit ? 5 : 7;
10307 sv = S_new_constant(aTHX_ PL_tokenbuf, d - PL_tokenbuf,
10308 key, keylen, sv, NULL, NULL, 0);
10312 /* if it starts with a v, it could be a v-string */
10315 sv = newSV(5); /* preallocate storage space */
10316 ENTER_with_name("scan_vstring");
10318 s = scan_vstring(s, PL_bufend, sv);
10319 SvREFCNT_inc_simple_void_NN(sv);
10320 LEAVE_with_name("scan_vstring");
10324 /* make the op for the constant and return */
10327 lvalp->opval = newSVOP(OP_CONST, 0, sv);
10329 lvalp->opval = NULL;
10335 S_scan_formline(pTHX_ char *s)
10339 SV * const stuff = newSVpvs("");
10340 bool needargs = FALSE;
10341 bool eofmt = FALSE;
10343 PERL_ARGS_ASSERT_SCAN_FORMLINE;
10345 while (!needargs) {
10348 #ifdef PERL_STRICT_CR
10349 while (SPACE_OR_TAB(*t))
10352 while (SPACE_OR_TAB(*t) || *t == '\r')
10355 if (*t == '\n' || t == PL_bufend) {
10360 eol = (char *) memchr(s,'\n',PL_bufend-s);
10364 for (t = s; t < eol; t++) {
10365 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
10367 goto enough; /* ~~ must be first line in formline */
10369 if (*t == '@' || *t == '^')
10373 sv_catpvn(stuff, s, eol-s);
10374 #ifndef PERL_STRICT_CR
10375 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
10376 char *end = SvPVX(stuff) + SvCUR(stuff);
10379 SvCUR_set(stuff, SvCUR(stuff) - 1);
10387 if ((PL_rsfp || PL_parser->filtered)
10388 && PL_parser->form_lex_state == LEX_NORMAL) {
10390 PL_bufptr = PL_bufend;
10391 COPLINE_INC_WITH_HERELINES;
10392 got_some = lex_next_chunk(0);
10393 CopLINE_dec(PL_curcop);
10401 if (!SvCUR(stuff) || needargs)
10402 PL_lex_state = PL_parser->form_lex_state;
10403 if (SvCUR(stuff)) {
10404 PL_expect = XSTATE;
10406 const char *s2 = s;
10407 while (*s2 == '\r' || *s2 == ' ' || *s2 == '\t' || *s2 == '\f'
10411 PL_expect = XTERMBLOCK;
10412 NEXTVAL_NEXTTOKE.ival = 0;
10415 NEXTVAL_NEXTTOKE.ival = 0;
10416 force_next(FORMLBRACK);
10419 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
10421 else if (PL_encoding)
10422 sv_recode_to_utf8(stuff, PL_encoding);
10424 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
10428 SvREFCNT_dec(stuff);
10430 PL_lex_formbrack = 0;
10436 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
10438 const I32 oldsavestack_ix = PL_savestack_ix;
10439 CV* const outsidecv = PL_compcv;
10441 SAVEI32(PL_subline);
10442 save_item(PL_subname);
10443 SAVESPTR(PL_compcv);
10445 PL_compcv = MUTABLE_CV(newSV_type(is_format ? SVt_PVFM : SVt_PVCV));
10446 CvFLAGS(PL_compcv) |= flags;
10448 PL_subline = CopLINE(PL_curcop);
10449 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
10450 CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outsidecv));
10451 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
10452 if (outsidecv && CvPADLIST(outsidecv))
10453 CvPADLIST(PL_compcv)->xpadl_outid =
10454 PadlistNAMES(CvPADLIST(outsidecv));
10456 return oldsavestack_ix;
10460 S_yywarn(pTHX_ const char *const s, U32 flags)
10462 PERL_ARGS_ASSERT_YYWARN;
10464 PL_in_eval |= EVAL_WARNONLY;
10465 yyerror_pv(s, flags);
10466 PL_in_eval &= ~EVAL_WARNONLY;
10471 Perl_yyerror(pTHX_ const char *const s)
10473 PERL_ARGS_ASSERT_YYERROR;
10474 return yyerror_pvn(s, strlen(s), 0);
10478 Perl_yyerror_pv(pTHX_ const char *const s, U32 flags)
10480 PERL_ARGS_ASSERT_YYERROR_PV;
10481 return yyerror_pvn(s, strlen(s), flags);
10485 Perl_yyerror_pvn(pTHX_ const char *const s, STRLEN len, U32 flags)
10487 const char *context = NULL;
10490 SV * const where_sv = newSVpvs_flags("", SVs_TEMP);
10491 int yychar = PL_parser->yychar;
10493 PERL_ARGS_ASSERT_YYERROR_PVN;
10495 if (!yychar || (yychar == ';' && !PL_rsfp))
10496 sv_catpvs(where_sv, "at EOF");
10497 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
10498 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
10499 PL_oldbufptr != PL_bufptr) {
10502 The code below is removed for NetWare because it abends/crashes on NetWare
10503 when the script has error such as not having the closing quotes like:
10504 if ($var eq "value)
10505 Checking of white spaces is anyway done in NetWare code.
10508 while (isSPACE(*PL_oldoldbufptr))
10511 context = PL_oldoldbufptr;
10512 contlen = PL_bufptr - PL_oldoldbufptr;
10514 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
10515 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
10518 The code below is removed for NetWare because it abends/crashes on NetWare
10519 when the script has error such as not having the closing quotes like:
10520 if ($var eq "value)
10521 Checking of white spaces is anyway done in NetWare code.
10524 while (isSPACE(*PL_oldbufptr))
10527 context = PL_oldbufptr;
10528 contlen = PL_bufptr - PL_oldbufptr;
10530 else if (yychar > 255)
10531 sv_catpvs(where_sv, "next token ???");
10532 else if (yychar == -2) { /* YYEMPTY */
10533 if (PL_lex_state == LEX_NORMAL ||
10534 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
10535 sv_catpvs(where_sv, "at end of line");
10536 else if (PL_lex_inpat)
10537 sv_catpvs(where_sv, "within pattern");
10539 sv_catpvs(where_sv, "within string");
10542 sv_catpvs(where_sv, "next char ");
10544 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
10545 else if (isPRINT_LC(yychar)) {
10546 const char string = yychar;
10547 sv_catpvn(where_sv, &string, 1);
10550 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
10552 msg = newSVpvn_flags(s, len, (flags & SVf_UTF8) | SVs_TEMP);
10553 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
10554 OutCopFILE(PL_curcop),
10555 (IV)(PL_parser->preambling == NOLINE
10556 ? CopLINE(PL_curcop)
10557 : PL_parser->preambling));
10559 Perl_sv_catpvf(aTHX_ msg, "near \"%"UTF8f"\"\n",
10560 UTF8fARG(UTF, contlen, context));
10562 Perl_sv_catpvf(aTHX_ msg, "%"SVf"\n", SVfARG(where_sv));
10563 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
10564 Perl_sv_catpvf(aTHX_ msg,
10565 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
10566 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
10569 if (PL_in_eval & EVAL_WARNONLY) {
10570 Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
10574 if (PL_error_count >= 10) {
10576 if (PL_in_eval && ((errsv = ERRSV), SvCUR(errsv)))
10577 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
10578 SVfARG(errsv), OutCopFILE(PL_curcop));
10580 Perl_croak(aTHX_ "%s has too many errors.\n",
10581 OutCopFILE(PL_curcop));
10584 PL_in_my_stash = NULL;
10589 S_swallow_bom(pTHX_ U8 *s)
10591 const STRLEN slen = SvCUR(PL_linestr);
10593 PERL_ARGS_ASSERT_SWALLOW_BOM;
10597 if (s[1] == 0xFE) {
10598 /* UTF-16 little-endian? (or UTF-32LE?) */
10599 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
10600 /* diag_listed_as: Unsupported script encoding %s */
10601 Perl_croak(aTHX_ "Unsupported script encoding UTF-32LE");
10602 #ifndef PERL_NO_UTF16_FILTER
10603 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (BOM)\n");
10605 if (PL_bufend > (char*)s) {
10606 s = add_utf16_textfilter(s, TRUE);
10609 /* diag_listed_as: Unsupported script encoding %s */
10610 Perl_croak(aTHX_ "Unsupported script encoding UTF-16LE");
10615 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
10616 #ifndef PERL_NO_UTF16_FILTER
10617 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
10619 if (PL_bufend > (char *)s) {
10620 s = add_utf16_textfilter(s, FALSE);
10623 /* diag_listed_as: Unsupported script encoding %s */
10624 Perl_croak(aTHX_ "Unsupported script encoding UTF-16BE");
10628 case BOM_UTF8_FIRST_BYTE: {
10629 const STRLEN len = sizeof(BOM_UTF8_TAIL) - 1; /* Exclude trailing NUL */
10630 if (slen > len && memEQ(s+1, BOM_UTF8_TAIL, len)) {
10631 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
10632 s += len + 1; /* UTF-8 */
10639 if (s[2] == 0xFE && s[3] == 0xFF) {
10640 /* UTF-32 big-endian */
10641 /* diag_listed_as: Unsupported script encoding %s */
10642 Perl_croak(aTHX_ "Unsupported script encoding UTF-32BE");
10645 else if (s[2] == 0 && s[3] != 0) {
10648 * are a good indicator of UTF-16BE. */
10649 #ifndef PERL_NO_UTF16_FILTER
10650 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
10651 s = add_utf16_textfilter(s, FALSE);
10653 /* diag_listed_as: Unsupported script encoding %s */
10654 Perl_croak(aTHX_ "Unsupported script encoding UTF-16BE");
10661 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
10664 * are a good indicator of UTF-16LE. */
10665 #ifndef PERL_NO_UTF16_FILTER
10666 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
10667 s = add_utf16_textfilter(s, TRUE);
10669 /* diag_listed_as: Unsupported script encoding %s */
10670 Perl_croak(aTHX_ "Unsupported script encoding UTF-16LE");
10678 #ifndef PERL_NO_UTF16_FILTER
10680 S_utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
10682 SV *const filter = FILTER_DATA(idx);
10683 /* We re-use this each time round, throwing the contents away before we
10685 SV *const utf16_buffer = MUTABLE_SV(IoTOP_GV(filter));
10686 SV *const utf8_buffer = filter;
10687 IV status = IoPAGE(filter);
10688 const bool reverse = cBOOL(IoLINES(filter));
10691 PERL_ARGS_ASSERT_UTF16_TEXTFILTER;
10693 /* As we're automatically added, at the lowest level, and hence only called
10694 from this file, we can be sure that we're not called in block mode. Hence
10695 don't bother writing code to deal with block mode. */
10697 Perl_croak(aTHX_ "panic: utf16_textfilter called in block mode (for %d characters)", maxlen);
10700 Perl_croak(aTHX_ "panic: utf16_textfilter called after error (status=%"IVdf")", status);
10702 DEBUG_P(PerlIO_printf(Perl_debug_log,
10703 "utf16_textfilter(%p,%ce): idx=%d maxlen=%d status=%"IVdf" utf16=%"UVuf" utf8=%"UVuf"\n",
10704 FPTR2DPTR(void *, S_utf16_textfilter),
10705 reverse ? 'l' : 'b', idx, maxlen, status,
10706 (UV)SvCUR(utf16_buffer), (UV)SvCUR(utf8_buffer)));
10713 /* First, look in our buffer of existing UTF-8 data: */
10714 char *nl = (char *)memchr(SvPVX(utf8_buffer), '\n', SvCUR(utf8_buffer));
10718 } else if (status == 0) {
10720 IoPAGE(filter) = 0;
10721 nl = SvEND(utf8_buffer);
10724 STRLEN got = nl - SvPVX(utf8_buffer);
10725 /* Did we have anything to append? */
10727 sv_catpvn(sv, SvPVX(utf8_buffer), got);
10728 /* Everything else in this code works just fine if SVp_POK isn't
10729 set. This, however, needs it, and we need it to work, else
10730 we loop infinitely because the buffer is never consumed. */
10731 sv_chop(utf8_buffer, nl);
10735 /* OK, not a complete line there, so need to read some more UTF-16.
10736 Read an extra octect if the buffer currently has an odd number. */
10740 if (SvCUR(utf16_buffer) >= 2) {
10741 /* Location of the high octet of the last complete code point.
10742 Gosh, UTF-16 is a pain. All the benefits of variable length,
10743 *coupled* with all the benefits of partial reads and
10745 const U8 *const last_hi = (U8*)SvPVX(utf16_buffer)
10746 + ((SvCUR(utf16_buffer) & ~1) - (reverse ? 1 : 2));
10748 if (*last_hi < 0xd8 || *last_hi > 0xdb) {
10752 /* We have the first half of a surrogate. Read more. */
10753 DEBUG_P(PerlIO_printf(Perl_debug_log, "utf16_textfilter partial surrogate detected at %p\n", last_hi));
10756 status = FILTER_READ(idx + 1, utf16_buffer,
10757 160 + (SvCUR(utf16_buffer) & 1));
10758 DEBUG_P(PerlIO_printf(Perl_debug_log, "utf16_textfilter status=%"IVdf" SvCUR(sv)=%"UVuf"\n", status, (UV)SvCUR(utf16_buffer)));
10759 DEBUG_P({ sv_dump(utf16_buffer); sv_dump(utf8_buffer);});
10762 IoPAGE(filter) = status;
10767 chars = SvCUR(utf16_buffer) >> 1;
10768 have = SvCUR(utf8_buffer);
10769 SvGROW(utf8_buffer, have + chars * 3 + 1);
10772 end = utf16_to_utf8_reversed((U8*)SvPVX(utf16_buffer),
10773 (U8*)SvPVX_const(utf8_buffer) + have,
10774 chars * 2, &newlen);
10776 end = utf16_to_utf8((U8*)SvPVX(utf16_buffer),
10777 (U8*)SvPVX_const(utf8_buffer) + have,
10778 chars * 2, &newlen);
10780 SvCUR_set(utf8_buffer, have + newlen);
10783 /* No need to keep this SV "well-formed" with a '\0' after the end, as
10784 it's private to us, and utf16_to_utf8{,reversed} take a
10785 (pointer,length) pair, rather than a NUL-terminated string. */
10786 if(SvCUR(utf16_buffer) & 1) {
10787 *SvPVX(utf16_buffer) = SvEND(utf16_buffer)[-1];
10788 SvCUR_set(utf16_buffer, 1);
10790 SvCUR_set(utf16_buffer, 0);
10793 DEBUG_P(PerlIO_printf(Perl_debug_log,
10794 "utf16_textfilter: returns, status=%"IVdf" utf16=%"UVuf" utf8=%"UVuf"\n",
10796 (UV)SvCUR(utf16_buffer), (UV)SvCUR(utf8_buffer)));
10797 DEBUG_P({ sv_dump(utf8_buffer); sv_dump(sv);});
10802 S_add_utf16_textfilter(pTHX_ U8 *const s, bool reversed)
10804 SV *filter = filter_add(S_utf16_textfilter, NULL);
10806 PERL_ARGS_ASSERT_ADD_UTF16_TEXTFILTER;
10808 IoTOP_GV(filter) = MUTABLE_GV(newSVpvn((char *)s, PL_bufend - (char*)s));
10809 sv_setpvs(filter, "");
10810 IoLINES(filter) = reversed;
10811 IoPAGE(filter) = 1; /* Not EOF */
10813 /* Sadly, we have to return a valid pointer, come what may, so we have to
10814 ignore any error return from this. */
10815 SvCUR_set(PL_linestr, 0);
10816 if (FILTER_READ(0, PL_linestr, 0)) {
10817 SvUTF8_on(PL_linestr);
10819 SvUTF8_on(PL_linestr);
10821 PL_bufend = SvEND(PL_linestr);
10822 return (U8*)SvPVX(PL_linestr);
10827 Returns a pointer to the next character after the parsed
10828 vstring, as well as updating the passed in sv.
10830 Function must be called like
10832 sv = sv_2mortal(newSV(5));
10833 s = scan_vstring(s,e,sv);
10835 where s and e are the start and end of the string.
10836 The sv should already be large enough to store the vstring
10837 passed in, for performance reasons.
10839 This function may croak if fatal warnings are enabled in the
10840 calling scope, hence the sv_2mortal in the example (to prevent
10841 a leak). Make sure to do SvREFCNT_inc afterwards if you use
10847 Perl_scan_vstring(pTHX_ const char *s, const char *const e, SV *sv)
10849 const char *pos = s;
10850 const char *start = s;
10852 PERL_ARGS_ASSERT_SCAN_VSTRING;
10854 if (*pos == 'v') pos++; /* get past 'v' */
10855 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
10857 if ( *pos != '.') {
10858 /* this may not be a v-string if followed by => */
10859 const char *next = pos;
10860 while (next < e && isSPACE(*next))
10862 if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
10863 /* return string not v-string */
10864 sv_setpvn(sv,(char *)s,pos-s);
10865 return (char *)pos;
10869 if (!isALPHA(*pos)) {
10870 U8 tmpbuf[UTF8_MAXBYTES+1];
10873 s++; /* get past 'v' */
10878 /* this is atoi() that tolerates underscores */
10881 const char *end = pos;
10883 while (--end >= s) {
10885 const UV orev = rev;
10886 rev += (*end - '0') * mult;
10889 /* diag_listed_as: Integer overflow in %s number */
10890 Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW),
10891 "Integer overflow in decimal number");
10895 if (rev > 0x7FFFFFFF)
10896 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
10898 /* Append native character for the rev point */
10899 tmpend = uvchr_to_utf8(tmpbuf, rev);
10900 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
10901 if (!UVCHR_IS_INVARIANT(rev))
10903 if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
10909 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
10913 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
10920 Perl_keyword_plugin_standard(pTHX_
10921 char *keyword_ptr, STRLEN keyword_len, OP **op_ptr)
10923 PERL_ARGS_ASSERT_KEYWORD_PLUGIN_STANDARD;
10924 PERL_UNUSED_CONTEXT;
10925 PERL_UNUSED_ARG(keyword_ptr);
10926 PERL_UNUSED_ARG(keyword_len);
10927 PERL_UNUSED_ARG(op_ptr);
10928 return KEYWORD_PLUGIN_DECLINE;
10931 #define parse_recdescent(g,p) S_parse_recdescent(aTHX_ g,p)
10933 S_parse_recdescent(pTHX_ int gramtype, I32 fakeeof)
10935 SAVEI32(PL_lex_brackets);
10936 if (PL_lex_brackets > 100)
10937 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
10938 PL_lex_brackstack[PL_lex_brackets++] = XFAKEEOF;
10939 SAVEI32(PL_lex_allbrackets);
10940 PL_lex_allbrackets = 0;
10941 SAVEI8(PL_lex_fakeeof);
10942 PL_lex_fakeeof = (U8)fakeeof;
10943 if(yyparse(gramtype) && !PL_parser->error_count)
10944 qerror(Perl_mess(aTHX_ "Parse error"));
10947 #define parse_recdescent_for_op(g,p) S_parse_recdescent_for_op(aTHX_ g,p)
10949 S_parse_recdescent_for_op(pTHX_ int gramtype, I32 fakeeof)
10953 SAVEVPTR(PL_eval_root);
10954 PL_eval_root = NULL;
10955 parse_recdescent(gramtype, fakeeof);
10961 #define parse_expr(p,f) S_parse_expr(aTHX_ p,f)
10963 S_parse_expr(pTHX_ I32 fakeeof, U32 flags)
10966 if (flags & ~PARSE_OPTIONAL)
10967 Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_expr");
10968 exprop = parse_recdescent_for_op(GRAMEXPR, fakeeof);
10969 if (!exprop && !(flags & PARSE_OPTIONAL)) {
10970 if (!PL_parser->error_count)
10971 qerror(Perl_mess(aTHX_ "Parse error"));
10972 exprop = newOP(OP_NULL, 0);
10978 =for apidoc Amx|OP *|parse_arithexpr|U32 flags
10980 Parse a Perl arithmetic expression. This may contain operators of precedence
10981 down to the bit shift operators. The expression must be followed (and thus
10982 terminated) either by a comparison or lower-precedence operator or by
10983 something that would normally terminate an expression such as semicolon.
10984 If I<flags> includes C<PARSE_OPTIONAL> then the expression is optional,
10985 otherwise it is mandatory. It is up to the caller to ensure that the
10986 dynamic parser state (L</PL_parser> et al) is correctly set to reflect
10987 the source of the code to be parsed and the lexical context for the
10990 The op tree representing the expression is returned. If an optional
10991 expression is absent, a null pointer is returned, otherwise the pointer
10994 If an error occurs in parsing or compilation, in most cases a valid op
10995 tree is returned anyway. The error is reflected in the parser state,
10996 normally resulting in a single exception at the top level of parsing
10997 which covers all the compilation errors that occurred. Some compilation
10998 errors, however, will throw an exception immediately.
11004 Perl_parse_arithexpr(pTHX_ U32 flags)
11006 return parse_expr(LEX_FAKEEOF_COMPARE, flags);
11010 =for apidoc Amx|OP *|parse_termexpr|U32 flags
11012 Parse a Perl term expression. This may contain operators of precedence
11013 down to the assignment operators. The expression must be followed (and thus
11014 terminated) either by a comma or lower-precedence operator or by
11015 something that would normally terminate an expression such as semicolon.
11016 If I<flags> includes C<PARSE_OPTIONAL> then the expression is optional,
11017 otherwise it is mandatory. It is up to the caller to ensure that the
11018 dynamic parser state (L</PL_parser> et al) is correctly set to reflect
11019 the source of the code to be parsed and the lexical context for the
11022 The op tree representing the expression is returned. If an optional
11023 expression is absent, a null pointer is returned, otherwise the pointer
11026 If an error occurs in parsing or compilation, in most cases a valid op
11027 tree is returned anyway. The error is reflected in the parser state,
11028 normally resulting in a single exception at the top level of parsing
11029 which covers all the compilation errors that occurred. Some compilation
11030 errors, however, will throw an exception immediately.
11036 Perl_parse_termexpr(pTHX_ U32 flags)
11038 return parse_expr(LEX_FAKEEOF_COMMA, flags);
11042 =for apidoc Amx|OP *|parse_listexpr|U32 flags
11044 Parse a Perl list expression. This may contain operators of precedence
11045 down to the comma operator. The expression must be followed (and thus
11046 terminated) either by a low-precedence logic operator such as C<or> or by
11047 something that would normally terminate an expression such as semicolon.
11048 If I<flags> includes C<PARSE_OPTIONAL> then the expression is optional,
11049 otherwise it is mandatory. It is up to the caller to ensure that the
11050 dynamic parser state (L</PL_parser> et al) is correctly set to reflect
11051 the source of the code to be parsed and the lexical context for the
11054 The op tree representing the expression is returned. If an optional
11055 expression is absent, a null pointer is returned, otherwise the pointer
11058 If an error occurs in parsing or compilation, in most cases a valid op
11059 tree is returned anyway. The error is reflected in the parser state,
11060 normally resulting in a single exception at the top level of parsing
11061 which covers all the compilation errors that occurred. Some compilation
11062 errors, however, will throw an exception immediately.
11068 Perl_parse_listexpr(pTHX_ U32 flags)
11070 return parse_expr(LEX_FAKEEOF_LOWLOGIC, flags);
11074 =for apidoc Amx|OP *|parse_fullexpr|U32 flags
11076 Parse a single complete Perl expression. This allows the full
11077 expression grammar, including the lowest-precedence operators such
11078 as C<or>. The expression must be followed (and thus terminated) by a
11079 token that an expression would normally be terminated by: end-of-file,
11080 closing bracketing punctuation, semicolon, or one of the keywords that
11081 signals a postfix expression-statement modifier. If I<flags> includes
11082 C<PARSE_OPTIONAL> then the expression is optional, otherwise it is
11083 mandatory. It is up to the caller to ensure that the dynamic parser
11084 state (L</PL_parser> et al) is correctly set to reflect the source of
11085 the code to be parsed and the lexical context for the expression.
11087 The op tree representing the expression is returned. If an optional
11088 expression is absent, a null pointer is returned, otherwise the pointer
11091 If an error occurs in parsing or compilation, in most cases a valid op
11092 tree is returned anyway. The error is reflected in the parser state,
11093 normally resulting in a single exception at the top level of parsing
11094 which covers all the compilation errors that occurred. Some compilation
11095 errors, however, will throw an exception immediately.
11101 Perl_parse_fullexpr(pTHX_ U32 flags)
11103 return parse_expr(LEX_FAKEEOF_NONEXPR, flags);
11107 =for apidoc Amx|OP *|parse_block|U32 flags
11109 Parse a single complete Perl code block. This consists of an opening
11110 brace, a sequence of statements, and a closing brace. The block
11111 constitutes a lexical scope, so C<my> variables and various compile-time
11112 effects can be contained within it. It is up to the caller to ensure
11113 that the dynamic parser state (L</PL_parser> et al) is correctly set to
11114 reflect the source of the code to be parsed and the lexical context for
11117 The op tree representing the code block is returned. This is always a
11118 real op, never a null pointer. It will normally be a C<lineseq> list,
11119 including C<nextstate> or equivalent ops. No ops to construct any kind
11120 of runtime scope are included by virtue of it being a block.
11122 If an error occurs in parsing or compilation, in most cases a valid op
11123 tree (most likely null) is returned anyway. The error is reflected in
11124 the parser state, normally resulting in a single exception at the top
11125 level of parsing which covers all the compilation errors that occurred.
11126 Some compilation errors, however, will throw an exception immediately.
11128 The I<flags> parameter is reserved for future use, and must always
11135 Perl_parse_block(pTHX_ U32 flags)
11138 Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_block");
11139 return parse_recdescent_for_op(GRAMBLOCK, LEX_FAKEEOF_NEVER);
11143 =for apidoc Amx|OP *|parse_barestmt|U32 flags
11145 Parse a single unadorned Perl statement. This may be a normal imperative
11146 statement or a declaration that has compile-time effect. It does not
11147 include any label or other affixture. It is up to the caller to ensure
11148 that the dynamic parser state (L</PL_parser> et al) is correctly set to
11149 reflect the source of the code to be parsed and the lexical context for
11152 The op tree representing the statement is returned. This may be a
11153 null pointer if the statement is null, for example if it was actually
11154 a subroutine definition (which has compile-time side effects). If not
11155 null, it will be ops directly implementing the statement, suitable to
11156 pass to L</newSTATEOP>. It will not normally include a C<nextstate> or
11157 equivalent op (except for those embedded in a scope contained entirely
11158 within the statement).
11160 If an error occurs in parsing or compilation, in most cases a valid op
11161 tree (most likely null) is returned anyway. The error is reflected in
11162 the parser state, normally resulting in a single exception at the top
11163 level of parsing which covers all the compilation errors that occurred.
11164 Some compilation errors, however, will throw an exception immediately.
11166 The I<flags> parameter is reserved for future use, and must always
11173 Perl_parse_barestmt(pTHX_ U32 flags)
11176 Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_barestmt");
11177 return parse_recdescent_for_op(GRAMBARESTMT, LEX_FAKEEOF_NEVER);
11181 =for apidoc Amx|SV *|parse_label|U32 flags
11183 Parse a single label, possibly optional, of the type that may prefix a
11184 Perl statement. It is up to the caller to ensure that the dynamic parser
11185 state (L</PL_parser> et al) is correctly set to reflect the source of
11186 the code to be parsed. If I<flags> includes C<PARSE_OPTIONAL> then the
11187 label is optional, otherwise it is mandatory.
11189 The name of the label is returned in the form of a fresh scalar. If an
11190 optional label is absent, a null pointer is returned.
11192 If an error occurs in parsing, which can only occur if the label is
11193 mandatory, a valid label is returned anyway. The error is reflected in
11194 the parser state, normally resulting in a single exception at the top
11195 level of parsing which covers all the compilation errors that occurred.
11201 Perl_parse_label(pTHX_ U32 flags)
11203 if (flags & ~PARSE_OPTIONAL)
11204 Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_label");
11205 if (PL_lex_state == LEX_KNOWNEXT) {
11206 PL_parser->yychar = yylex();
11207 if (PL_parser->yychar == LABEL) {
11208 char * const lpv = pl_yylval.pval;
11209 STRLEN llen = strlen(lpv);
11210 PL_parser->yychar = YYEMPTY;
11211 return newSVpvn_flags(lpv, llen, lpv[llen+1] ? SVf_UTF8 : 0);
11218 STRLEN wlen, bufptr_pos;
11221 if (!isIDFIRST_lazy_if(s, UTF))
11223 t = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &wlen);
11224 if (word_takes_any_delimeter(s, wlen))
11226 bufptr_pos = s - SvPVX(PL_linestr);
11228 lex_read_space(LEX_KEEP_PREVIOUS);
11230 s = SvPVX(PL_linestr) + bufptr_pos;
11231 if (t[0] == ':' && t[1] != ':') {
11232 PL_oldoldbufptr = PL_oldbufptr;
11235 return newSVpvn_flags(s, wlen, UTF ? SVf_UTF8 : 0);
11239 if (flags & PARSE_OPTIONAL) {
11242 qerror(Perl_mess(aTHX_ "Parse error"));
11243 return newSVpvs("x");
11250 =for apidoc Amx|OP *|parse_fullstmt|U32 flags
11252 Parse a single complete Perl statement. This may be a normal imperative
11253 statement or a declaration that has compile-time effect, and may include
11254 optional labels. It is up to the caller to ensure that the dynamic
11255 parser state (L</PL_parser> et al) is correctly set to reflect the source
11256 of the code to be parsed and the lexical context for the statement.
11258 The op tree representing the statement is returned. This may be a
11259 null pointer if the statement is null, for example if it was actually
11260 a subroutine definition (which has compile-time side effects). If not
11261 null, it will be the result of a L</newSTATEOP> call, normally including
11262 a C<nextstate> or equivalent op.
11264 If an error occurs in parsing or compilation, in most cases a valid op
11265 tree (most likely null) is returned anyway. The error is reflected in
11266 the parser state, normally resulting in a single exception at the top
11267 level of parsing which covers all the compilation errors that occurred.
11268 Some compilation errors, however, will throw an exception immediately.
11270 The I<flags> parameter is reserved for future use, and must always
11277 Perl_parse_fullstmt(pTHX_ U32 flags)
11280 Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_fullstmt");
11281 return parse_recdescent_for_op(GRAMFULLSTMT, LEX_FAKEEOF_NEVER);
11285 =for apidoc Amx|OP *|parse_stmtseq|U32 flags
11287 Parse a sequence of zero or more Perl statements. These may be normal
11288 imperative statements, including optional labels, or declarations
11289 that have compile-time effect, or any mixture thereof. The statement
11290 sequence ends when a closing brace or end-of-file is encountered in a
11291 place where a new statement could have validly started. It is up to
11292 the caller to ensure that the dynamic parser state (L</PL_parser> et al)
11293 is correctly set to reflect the source of the code to be parsed and the
11294 lexical context for the statements.
11296 The op tree representing the statement sequence is returned. This may
11297 be a null pointer if the statements were all null, for example if there
11298 were no statements or if there were only subroutine definitions (which
11299 have compile-time side effects). If not null, it will be a C<lineseq>
11300 list, normally including C<nextstate> or equivalent ops.
11302 If an error occurs in parsing or compilation, in most cases a valid op
11303 tree is returned anyway. The error is reflected in the parser state,
11304 normally resulting in a single exception at the top level of parsing
11305 which covers all the compilation errors that occurred. Some compilation
11306 errors, however, will throw an exception immediately.
11308 The I<flags> parameter is reserved for future use, and must always
11315 Perl_parse_stmtseq(pTHX_ U32 flags)
11320 Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_stmtseq");
11321 stmtseqop = parse_recdescent_for_op(GRAMSTMTSEQ, LEX_FAKEEOF_CLOSING);
11322 c = lex_peek_unichar(0);
11323 if (c != -1 && c != /*{*/'}')
11324 qerror(Perl_mess(aTHX_ "Parse error"));
11328 #define lex_token_boundary() S_lex_token_boundary(aTHX)
11330 S_lex_token_boundary(pTHX)
11332 PL_oldoldbufptr = PL_oldbufptr;
11333 PL_oldbufptr = PL_bufptr;
11336 #define parse_opt_lexvar() S_parse_opt_lexvar(aTHX)
11338 S_parse_opt_lexvar(pTHX)
11343 lex_token_boundary();
11344 sigil = lex_read_unichar(0);
11345 if (lex_peek_unichar(0) == '#') {
11346 qerror(Perl_mess(aTHX_ "Parse error"));
11350 c = lex_peek_unichar(0);
11351 if (c == -1 || !(UTF ? isIDFIRST_uni(c) : isIDFIRST_A(c)))
11354 d = PL_tokenbuf + 1;
11355 PL_tokenbuf[0] = (char)sigil;
11356 parse_ident(&s, &d, PL_tokenbuf + sizeof(PL_tokenbuf) - 1, 0, cBOOL(UTF));
11358 if (d == PL_tokenbuf+1)
11361 var = newOP(sigil == '$' ? OP_PADSV : sigil == '@' ? OP_PADAV : OP_PADHV,
11362 OPf_MOD | (OPpLVAL_INTRO<<8));
11363 var->op_targ = allocmy(PL_tokenbuf, d - PL_tokenbuf, UTF ? SVf_UTF8 : 0);
11368 Perl_parse_subsignature(pTHX)
11371 int prev_type = 0, pos = 0, min_arity = 0, max_arity = 0;
11372 OP *initops = NULL;
11374 c = lex_peek_unichar(0);
11375 while (c != /*(*/')') {
11379 if (prev_type == 2)
11380 qerror(Perl_mess(aTHX_ "Slurpy parameter not last"));
11381 var = parse_opt_lexvar();
11383 newBINOP(OP_AELEM, 0,
11384 ref(newUNOP(OP_RV2AV, 0, newGVOP(OP_GV, 0, PL_defgv)),
11386 newSVOP(OP_CONST, 0, newSViv(pos))) :
11389 c = lex_peek_unichar(0);
11391 lex_token_boundary();
11392 lex_read_unichar(0);
11394 c = lex_peek_unichar(0);
11395 if (c == ',' || c == /*(*/')') {
11397 qerror(Perl_mess(aTHX_ "Optional parameter "
11398 "lacks default expression"));
11400 OP *defexpr = parse_termexpr(0);
11401 if (defexpr->op_type == OP_UNDEF &&
11402 !(defexpr->op_flags & OPf_KIDS)) {
11407 scalar(newUNOP(OP_RV2AV, 0,
11408 newGVOP(OP_GV, 0, PL_defgv))),
11409 newSVOP(OP_CONST, 0, newSViv(pos+1)));
11411 newCONDOP(0, ifop, expr, defexpr) :
11412 newLOGOP(OP_OR, 0, ifop, defexpr);
11417 if (prev_type == 1)
11418 qerror(Perl_mess(aTHX_ "Mandatory parameter "
11419 "follows optional parameter"));
11421 min_arity = pos + 1;
11423 if (var) expr = newASSIGNOP(OPf_STACKED, var, 0, expr);
11425 initops = op_append_list(OP_LINESEQ, initops,
11426 newSTATEOP(0, NULL, expr));
11432 if (prev_type == 2)
11433 qerror(Perl_mess(aTHX_ "Slurpy parameter not last"));
11434 var = parse_opt_lexvar();
11436 OP *chkop = newLOGOP((pos & 1) ? OP_OR : OP_AND, 0,
11437 newBINOP(OP_BIT_AND, 0,
11438 scalar(newUNOP(OP_RV2AV, 0,
11439 newGVOP(OP_GV, 0, PL_defgv))),
11440 newSVOP(OP_CONST, 0, newSViv(1))),
11441 newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
11442 newSVOP(OP_CONST, 0,
11443 newSVpvs("Odd name/value argument "
11444 "for subroutine"))));
11445 if (pos != min_arity)
11446 chkop = newLOGOP(OP_AND, 0,
11448 scalar(newUNOP(OP_RV2AV, 0,
11449 newGVOP(OP_GV, 0, PL_defgv))),
11450 newSVOP(OP_CONST, 0, newSViv(pos))),
11452 initops = op_append_list(OP_LINESEQ,
11453 newSTATEOP(0, NULL, chkop),
11458 op_prepend_elem(OP_ASLICE,
11459 newOP(OP_PUSHMARK, 0),
11460 newLISTOP(OP_ASLICE, 0,
11462 newSVOP(OP_CONST, 0, newSViv(pos)),
11463 newUNOP(OP_AV2ARYLEN, 0,
11464 ref(newUNOP(OP_RV2AV, 0,
11465 newGVOP(OP_GV, 0, PL_defgv)),
11467 ref(newUNOP(OP_RV2AV, 0,
11468 newGVOP(OP_GV, 0, PL_defgv)),
11470 newUNOP(OP_RV2AV, 0, newGVOP(OP_GV, 0, PL_defgv));
11471 initops = op_append_list(OP_LINESEQ, initops,
11472 newSTATEOP(0, NULL,
11473 newASSIGNOP(OPf_STACKED, var, 0, slice)));
11480 qerror(Perl_mess(aTHX_ "Parse error"));
11484 c = lex_peek_unichar(0);
11486 case /*(*/')': break;
11489 lex_token_boundary();
11490 lex_read_unichar(0);
11492 c = lex_peek_unichar(0);
11493 } while (c == ',');
11499 if (min_arity != 0) {
11500 initops = op_append_list(OP_LINESEQ,
11501 newSTATEOP(0, NULL,
11504 scalar(newUNOP(OP_RV2AV, 0,
11505 newGVOP(OP_GV, 0, PL_defgv))),
11506 newSVOP(OP_CONST, 0, newSViv(min_arity))),
11507 newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
11508 newSVOP(OP_CONST, 0,
11509 newSVpvs("Too few arguments for subroutine"))))),
11512 if (max_arity != -1) {
11513 initops = op_append_list(OP_LINESEQ,
11514 newSTATEOP(0, NULL,
11517 scalar(newUNOP(OP_RV2AV, 0,
11518 newGVOP(OP_GV, 0, PL_defgv))),
11519 newSVOP(OP_CONST, 0, newSViv(max_arity))),
11520 newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
11521 newSVOP(OP_CONST, 0,
11522 newSVpvs("Too many arguments for subroutine"))))),
11530 * c-indentation-style: bsd
11531 * c-basic-offset: 4
11532 * indent-tabs-mode: nil
11535 * ex: set ts=8 sts=4 sw=4 et: