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
27 This is the lower layer of the Perl parser, managing characters and tokens.
29 =for apidoc AmU|yy_parser *|PL_parser
31 Pointer to a structure encapsulating the state of the parsing operation
32 currently in progress. The pointer can be locally changed to perform
33 a nested parse without interfering with the state of an outer parse.
34 Individual members of C<PL_parser> have their own documentation.
40 #define PERL_IN_TOKE_C
42 #include "dquote_static.c"
44 #define new_constant(a,b,c,d,e,f,g) \
45 S_new_constant(aTHX_ a,b,STR_WITH_LEN(c),d,e,f, g)
47 #define pl_yylval (PL_parser->yylval)
49 /* XXX temporary backwards compatibility */
50 #define PL_lex_brackets (PL_parser->lex_brackets)
51 #define PL_lex_allbrackets (PL_parser->lex_allbrackets)
52 #define PL_lex_fakeeof (PL_parser->lex_fakeeof)
53 #define PL_lex_brackstack (PL_parser->lex_brackstack)
54 #define PL_lex_casemods (PL_parser->lex_casemods)
55 #define PL_lex_casestack (PL_parser->lex_casestack)
56 #define PL_lex_defer (PL_parser->lex_defer)
57 #define PL_lex_dojoin (PL_parser->lex_dojoin)
58 #define PL_lex_expect (PL_parser->lex_expect)
59 #define PL_lex_formbrack (PL_parser->lex_formbrack)
60 #define PL_lex_inpat (PL_parser->lex_inpat)
61 #define PL_lex_inwhat (PL_parser->lex_inwhat)
62 #define PL_lex_op (PL_parser->lex_op)
63 #define PL_lex_repl (PL_parser->lex_repl)
64 #define PL_lex_starts (PL_parser->lex_starts)
65 #define PL_lex_stuff (PL_parser->lex_stuff)
66 #define PL_multi_start (PL_parser->multi_start)
67 #define PL_multi_open (PL_parser->multi_open)
68 #define PL_multi_close (PL_parser->multi_close)
69 #define PL_pending_ident (PL_parser->pending_ident)
70 #define PL_preambled (PL_parser->preambled)
71 #define PL_sublex_info (PL_parser->sublex_info)
72 #define PL_linestr (PL_parser->linestr)
73 #define PL_expect (PL_parser->expect)
74 #define PL_copline (PL_parser->copline)
75 #define PL_bufptr (PL_parser->bufptr)
76 #define PL_oldbufptr (PL_parser->oldbufptr)
77 #define PL_oldoldbufptr (PL_parser->oldoldbufptr)
78 #define PL_linestart (PL_parser->linestart)
79 #define PL_bufend (PL_parser->bufend)
80 #define PL_last_uni (PL_parser->last_uni)
81 #define PL_last_lop (PL_parser->last_lop)
82 #define PL_last_lop_op (PL_parser->last_lop_op)
83 #define PL_lex_state (PL_parser->lex_state)
84 #define PL_rsfp (PL_parser->rsfp)
85 #define PL_rsfp_filters (PL_parser->rsfp_filters)
86 #define PL_in_my (PL_parser->in_my)
87 #define PL_in_my_stash (PL_parser->in_my_stash)
88 #define PL_tokenbuf (PL_parser->tokenbuf)
89 #define PL_multi_end (PL_parser->multi_end)
90 #define PL_error_count (PL_parser->error_count)
93 # define PL_endwhite (PL_parser->endwhite)
94 # define PL_faketokens (PL_parser->faketokens)
95 # define PL_lasttoke (PL_parser->lasttoke)
96 # define PL_nextwhite (PL_parser->nextwhite)
97 # define PL_realtokenstart (PL_parser->realtokenstart)
98 # define PL_skipwhite (PL_parser->skipwhite)
99 # define PL_thisclose (PL_parser->thisclose)
100 # define PL_thismad (PL_parser->thismad)
101 # define PL_thisopen (PL_parser->thisopen)
102 # define PL_thisstuff (PL_parser->thisstuff)
103 # define PL_thistoken (PL_parser->thistoken)
104 # define PL_thiswhite (PL_parser->thiswhite)
105 # define PL_thiswhite (PL_parser->thiswhite)
106 # define PL_nexttoke (PL_parser->nexttoke)
107 # define PL_curforce (PL_parser->curforce)
109 # define PL_nexttoke (PL_parser->nexttoke)
110 # define PL_nexttype (PL_parser->nexttype)
111 # define PL_nextval (PL_parser->nextval)
114 /* This can't be done with embed.fnc, because struct yy_parser contains a
115 member named pending_ident, which clashes with the generated #define */
117 S_pending_ident(pTHX);
119 static const char ident_too_long[] = "Identifier too long";
122 # define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
123 # define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
125 # define CURMAD(slot,sv)
126 # define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
129 #define XENUMMASK 0x3f
130 #define XFAKEEOF 0x40
131 #define XFAKEBRACK 0x80
133 #ifdef USE_UTF8_SCRIPTS
134 # define UTF (!IN_BYTES)
136 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || ( !(PL_parser->lex_flags & LEX_IGNORE_UTF8_HINTS) && (PL_hints & HINT_UTF8)))
139 /* The maximum number of characters preceding the unrecognized one to display */
140 #define UNRECOGNIZED_PRECEDE_COUNT 10
142 /* In variables named $^X, these are the legal values for X.
143 * 1999-02-27 mjd-perl-patch@plover.com */
144 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
146 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
148 /* LEX_* are values for PL_lex_state, the state of the lexer.
149 * They are arranged oddly so that the guard on the switch statement
150 * can get by with a single comparison (if the compiler is smart enough).
153 /* #define LEX_NOTPARSING 11 is done in perl.h. */
155 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
156 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
157 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
158 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
159 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
161 /* at end of code, eg "$x" followed by: */
162 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
163 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
165 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
166 string or after \E, $foo, etc */
167 #define LEX_INTERPCONST 2 /* NOT USED */
168 #define LEX_FORMLINE 1 /* expecting a format line */
169 #define LEX_KNOWNEXT 0 /* next token known; just return it */
173 static const char* const lex_state_names[] = {
192 #include "keywords.h"
194 /* CLINE is a macro that ensures PL_copline has a sane value */
199 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
202 # define SKIPSPACE0(s) skipspace0(s)
203 # define SKIPSPACE1(s) skipspace1(s)
204 # define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
205 # define PEEKSPACE(s) skipspace2(s,0)
207 # define SKIPSPACE0(s) skipspace(s)
208 # define SKIPSPACE1(s) skipspace(s)
209 # define SKIPSPACE2(s,tsv) skipspace(s)
210 # define PEEKSPACE(s) skipspace(s)
214 * Convenience functions to return different tokens and prime the
215 * lexer for the next token. They all take an argument.
217 * TOKEN : generic token (used for '(', DOLSHARP, etc)
218 * OPERATOR : generic operator
219 * AOPERATOR : assignment operator
220 * PREBLOCK : beginning the block after an if, while, foreach, ...
221 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
222 * PREREF : *EXPR where EXPR is not a simple identifier
223 * TERM : expression term
224 * LOOPX : loop exiting command (goto, last, dump, etc)
225 * FTST : file test operator
226 * FUN0 : zero-argument function
227 * FUN0OP : zero-argument function, with its op created in this file
228 * FUN1 : not used, except for not, which isn't a UNIOP
229 * BOop : bitwise or or xor
231 * SHop : shift operator
232 * PWop : power operator
233 * PMop : pattern-matching operator
234 * Aop : addition-level operator
235 * Mop : multiplication-level operator
236 * Eop : equality-testing operator
237 * Rop : relational operator <= != gt
239 * Also see LOP and lop() below.
242 #ifdef DEBUGGING /* Serve -DT. */
243 # define REPORT(retval) tokereport((I32)retval, &pl_yylval)
245 # define REPORT(retval) (retval)
248 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
249 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
250 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
251 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
252 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
253 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
254 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
255 #define LOOPX(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
256 #define FTST(f) return (pl_yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
257 #define FUN0(f) return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
258 #define FUN0OP(f) return (pl_yylval.opval=f, CLINE, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0OP))
259 #define FUN1(f) return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
260 #define BOop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
261 #define BAop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
262 #define SHop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
263 #define PWop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
264 #define PMop(f) return(pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
265 #define Aop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
266 #define Mop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
267 #define Eop(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
268 #define Rop(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
270 /* This bit of chicanery makes a unary function followed by
271 * a parenthesis into a function with one argument, highest precedence.
272 * The UNIDOR macro is for unary functions that can be followed by the //
273 * operator (such as C<shift // 0>).
275 #define UNI2(f,x) { \
276 pl_yylval.ival = f; \
279 PL_last_uni = PL_oldbufptr; \
280 PL_last_lop_op = f; \
282 return REPORT( (int)FUNC1 ); \
284 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
286 #define UNI(f) UNI2(f,XTERM)
287 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
288 #define UNIPROTO(f,optional) { \
289 if (optional) PL_last_uni = PL_oldbufptr; \
293 #define UNIBRACK(f) { \
294 pl_yylval.ival = f; \
296 PL_last_uni = PL_oldbufptr; \
298 return REPORT( (int)FUNC1 ); \
300 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
303 /* grandfather return to old style */
306 if (!PL_lex_allbrackets && PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC) \
307 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC; \
308 pl_yylval.ival = (f); \
316 /* how to interpret the pl_yylval associated with the token */
320 TOKENTYPE_OPNUM, /* pl_yylval.ival contains an opcode number */
326 static struct debug_tokens {
328 enum token_type type;
330 } const debug_tokens[] =
332 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
333 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
334 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
335 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
336 { ARROW, TOKENTYPE_NONE, "ARROW" },
337 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
338 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
339 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
340 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
341 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
342 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
343 { DO, TOKENTYPE_NONE, "DO" },
344 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
345 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
346 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
347 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
348 { ELSE, TOKENTYPE_NONE, "ELSE" },
349 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
350 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
351 { FOR, TOKENTYPE_IVAL, "FOR" },
352 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
353 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
354 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
355 { FUNC0OP, TOKENTYPE_OPVAL, "FUNC0OP" },
356 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
357 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
358 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
359 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
360 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
361 { IF, TOKENTYPE_IVAL, "IF" },
362 { LABEL, TOKENTYPE_PVAL, "LABEL" },
363 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
364 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
365 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
366 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
367 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
368 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
369 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
370 { MY, TOKENTYPE_IVAL, "MY" },
371 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
372 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
373 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
374 { OROP, TOKENTYPE_IVAL, "OROP" },
375 { OROR, TOKENTYPE_NONE, "OROR" },
376 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
377 { PLUGEXPR, TOKENTYPE_OPVAL, "PLUGEXPR" },
378 { PLUGSTMT, TOKENTYPE_OPVAL, "PLUGSTMT" },
379 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
380 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
381 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
382 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
383 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
384 { PREINC, TOKENTYPE_NONE, "PREINC" },
385 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
386 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
387 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
388 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
389 { SUB, TOKENTYPE_NONE, "SUB" },
390 { THING, TOKENTYPE_OPVAL, "THING" },
391 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
392 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
393 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
394 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
395 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
396 { USE, TOKENTYPE_IVAL, "USE" },
397 { WHEN, TOKENTYPE_IVAL, "WHEN" },
398 { WHILE, TOKENTYPE_IVAL, "WHILE" },
399 { WORD, TOKENTYPE_OPVAL, "WORD" },
400 { YADAYADA, TOKENTYPE_IVAL, "YADAYADA" },
401 { 0, TOKENTYPE_NONE, NULL }
404 /* dump the returned token in rv, plus any optional arg in pl_yylval */
407 S_tokereport(pTHX_ I32 rv, const YYSTYPE* lvalp)
411 PERL_ARGS_ASSERT_TOKEREPORT;
414 const char *name = NULL;
415 enum token_type type = TOKENTYPE_NONE;
416 const struct debug_tokens *p;
417 SV* const report = newSVpvs("<== ");
419 for (p = debug_tokens; p->token; p++) {
420 if (p->token == (int)rv) {
427 Perl_sv_catpv(aTHX_ report, name);
428 else if ((char)rv > ' ' && (char)rv < '~')
429 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
431 sv_catpvs(report, "EOF");
433 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
436 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
439 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)lvalp->ival);
441 case TOKENTYPE_OPNUM:
442 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
443 PL_op_name[lvalp->ival]);
446 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", lvalp->pval);
448 case TOKENTYPE_OPVAL:
450 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
451 PL_op_name[lvalp->opval->op_type]);
452 if (lvalp->opval->op_type == OP_CONST) {
453 Perl_sv_catpvf(aTHX_ report, " %s",
454 SvPEEK(cSVOPx_sv(lvalp->opval)));
459 sv_catpvs(report, "(opval=null)");
462 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
468 /* print the buffer with suitable escapes */
471 S_printbuf(pTHX_ const char *const fmt, const char *const s)
473 SV* const tmp = newSVpvs("");
475 PERL_ARGS_ASSERT_PRINTBUF;
477 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
484 S_deprecate_commaless_var_list(pTHX) {
486 deprecate("comma-less variable list");
487 return REPORT(','); /* grandfather non-comma-format format */
493 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
494 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
498 S_ao(pTHX_ int toketype)
501 if (*PL_bufptr == '=') {
503 if (toketype == ANDAND)
504 pl_yylval.ival = OP_ANDASSIGN;
505 else if (toketype == OROR)
506 pl_yylval.ival = OP_ORASSIGN;
507 else if (toketype == DORDOR)
508 pl_yylval.ival = OP_DORASSIGN;
516 * When Perl expects an operator and finds something else, no_op
517 * prints the warning. It always prints "<something> found where
518 * operator expected. It prints "Missing semicolon on previous line?"
519 * if the surprise occurs at the start of the line. "do you need to
520 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
521 * where the compiler doesn't know if foo is a method call or a function.
522 * It prints "Missing operator before end of line" if there's nothing
523 * after the missing operator, or "... before <...>" if there is something
524 * after the missing operator.
528 S_no_op(pTHX_ const char *const what, char *s)
531 char * const oldbp = PL_bufptr;
532 const bool is_first = (PL_oldbufptr == PL_linestart);
534 PERL_ARGS_ASSERT_NO_OP;
540 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
541 if (ckWARN_d(WARN_SYNTAX)) {
543 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
544 "\t(Missing semicolon on previous line?)\n");
545 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
547 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
549 if (t < PL_bufptr && isSPACE(*t))
550 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
551 "\t(Do you need to predeclare %.*s?)\n",
552 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
556 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
557 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
565 * Complain about missing quote/regexp/heredoc terminator.
566 * If it's called with NULL then it cauterizes the line buffer.
567 * If we're in a delimited string and the delimiter is a control
568 * character, it's reformatted into a two-char sequence like ^C.
573 S_missingterm(pTHX_ char *s)
579 char * const nl = strrchr(s,'\n');
583 else if (isCNTRL(PL_multi_close)) {
585 tmpbuf[1] = (char)toCTRL(PL_multi_close);
590 *tmpbuf = (char)PL_multi_close;
594 q = strchr(s,'"') ? '\'' : '"';
595 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
599 * Check whether the named feature is enabled.
602 Perl_feature_is_enabled(pTHX_ const char *const name, STRLEN namelen)
605 HV * const hinthv = GvHV(PL_hintgv);
606 char he_name[8 + MAX_FEATURE_LEN] = "feature_";
608 PERL_ARGS_ASSERT_FEATURE_IS_ENABLED;
610 if (namelen > MAX_FEATURE_LEN)
612 memcpy(&he_name[8], name, namelen);
614 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
618 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
619 * utf16-to-utf8-reversed.
622 #ifdef PERL_CR_FILTER
626 register const char *s = SvPVX_const(sv);
627 register const char * const e = s + SvCUR(sv);
629 PERL_ARGS_ASSERT_STRIP_RETURN;
631 /* outer loop optimized to do nothing if there are no CR-LFs */
633 if (*s++ == '\r' && *s == '\n') {
634 /* hit a CR-LF, need to copy the rest */
635 register char *d = s - 1;
638 if (*s == '\r' && s[1] == '\n')
649 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
651 const I32 count = FILTER_READ(idx+1, sv, maxlen);
652 if (count > 0 && !maxlen)
659 =for apidoc Amx|void|lex_start|SV *line|PerlIO *rsfp|U32 flags
661 Creates and initialises a new lexer/parser state object, supplying
662 a context in which to lex and parse from a new source of Perl code.
663 A pointer to the new state object is placed in L</PL_parser>. An entry
664 is made on the save stack so that upon unwinding the new state object
665 will be destroyed and the former value of L</PL_parser> will be restored.
666 Nothing else need be done to clean up the parsing context.
668 The code to be parsed comes from I<line> and I<rsfp>. I<line>, if
669 non-null, provides a string (in SV form) containing code to be parsed.
670 A copy of the string is made, so subsequent modification of I<line>
671 does not affect parsing. I<rsfp>, if non-null, provides an input stream
672 from which code will be read to be parsed. If both are non-null, the
673 code in I<line> comes first and must consist of complete lines of input,
674 and I<rsfp> supplies the remainder of the source.
676 The I<flags> parameter is reserved for future use. Currently it is only
677 used by perl internally, so extensions should always pass zero.
682 /* LEX_START_SAME_FILTER indicates that this is not a new file, so it
683 can share filters with the current parser. */
686 Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, U32 flags)
689 const char *s = NULL;
690 yy_parser *parser, *oparser;
691 if (flags && flags & ~LEX_START_FLAGS)
692 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_start");
694 /* create and initialise a parser */
696 Newxz(parser, 1, yy_parser);
697 parser->old_parser = oparser = PL_parser;
700 parser->stack = NULL;
702 parser->stack_size = 0;
704 /* on scope exit, free this parser and restore any outer one */
706 parser->saved_curcop = PL_curcop;
708 /* initialise lexer state */
711 parser->curforce = -1;
713 parser->nexttoke = 0;
715 parser->error_count = oparser ? oparser->error_count : 0;
716 parser->copline = NOLINE;
717 parser->lex_state = LEX_NORMAL;
718 parser->expect = XSTATE;
720 parser->rsfp_filters =
721 !(flags & LEX_START_SAME_FILTER) || !oparser
723 : MUTABLE_AV(SvREFCNT_inc(
724 oparser->rsfp_filters
725 ? oparser->rsfp_filters
726 : (oparser->rsfp_filters = newAV())
729 Newx(parser->lex_brackstack, 120, char);
730 Newx(parser->lex_casestack, 12, char);
731 *parser->lex_casestack = '\0';
735 s = SvPV_const(line, len);
736 parser->linestr = flags & LEX_START_COPIED
737 ? SvREFCNT_inc_simple_NN(line)
738 : newSVpvn_flags(s, len, SvUTF8(line));
739 if (!len || s[len-1] != ';')
740 sv_catpvs(parser->linestr, "\n;");
742 parser->linestr = newSVpvs("\n;");
744 parser->oldoldbufptr =
747 parser->linestart = SvPVX(parser->linestr);
748 parser->bufend = parser->bufptr + SvCUR(parser->linestr);
749 parser->last_lop = parser->last_uni = NULL;
750 parser->lex_flags = flags & (LEX_IGNORE_UTF8_HINTS|LEX_EVALBYTES);
752 parser->in_pod = parser->filtered = 0;
756 /* delete a parser object */
759 Perl_parser_free(pTHX_ const yy_parser *parser)
761 PERL_ARGS_ASSERT_PARSER_FREE;
763 PL_curcop = parser->saved_curcop;
764 SvREFCNT_dec(parser->linestr);
766 if (parser->rsfp == PerlIO_stdin())
767 PerlIO_clearerr(parser->rsfp);
768 else if (parser->rsfp && (!parser->old_parser ||
769 (parser->old_parser && parser->rsfp != parser->old_parser->rsfp)))
770 PerlIO_close(parser->rsfp);
771 SvREFCNT_dec(parser->rsfp_filters);
773 Safefree(parser->lex_brackstack);
774 Safefree(parser->lex_casestack);
775 PL_parser = parser->old_parser;
781 =for apidoc AmxU|SV *|PL_parser-E<gt>linestr
783 Buffer scalar containing the chunk currently under consideration of the
784 text currently being lexed. This is always a plain string scalar (for
785 which C<SvPOK> is true). It is not intended to be used as a scalar by
786 normal scalar means; instead refer to the buffer directly by the pointer
787 variables described below.
789 The lexer maintains various C<char*> pointers to things in the
790 C<PL_parser-E<gt>linestr> buffer. If C<PL_parser-E<gt>linestr> is ever
791 reallocated, all of these pointers must be updated. Don't attempt to
792 do this manually, but rather use L</lex_grow_linestr> if you need to
793 reallocate the buffer.
795 The content of the text chunk in the buffer is commonly exactly one
796 complete line of input, up to and including a newline terminator,
797 but there are situations where it is otherwise. The octets of the
798 buffer may be intended to be interpreted as either UTF-8 or Latin-1.
799 The function L</lex_bufutf8> tells you which. Do not use the C<SvUTF8>
800 flag on this scalar, which may disagree with it.
802 For direct examination of the buffer, the variable
803 L</PL_parser-E<gt>bufend> points to the end of the buffer. The current
804 lexing position is pointed to by L</PL_parser-E<gt>bufptr>. Direct use
805 of these pointers is usually preferable to examination of the scalar
806 through normal scalar means.
808 =for apidoc AmxU|char *|PL_parser-E<gt>bufend
810 Direct pointer to the end of the chunk of text currently being lexed, the
811 end of the lexer buffer. This is equal to C<SvPVX(PL_parser-E<gt>linestr)
812 + SvCUR(PL_parser-E<gt>linestr)>. A NUL character (zero octet) is
813 always located at the end of the buffer, and does not count as part of
814 the buffer's contents.
816 =for apidoc AmxU|char *|PL_parser-E<gt>bufptr
818 Points to the current position of lexing inside the lexer buffer.
819 Characters around this point may be freely examined, within
820 the range delimited by C<SvPVX(L</PL_parser-E<gt>linestr>)> and
821 L</PL_parser-E<gt>bufend>. The octets of the buffer may be intended to be
822 interpreted as either UTF-8 or Latin-1, as indicated by L</lex_bufutf8>.
824 Lexing code (whether in the Perl core or not) moves this pointer past
825 the characters that it consumes. It is also expected to perform some
826 bookkeeping whenever a newline character is consumed. This movement
827 can be more conveniently performed by the function L</lex_read_to>,
828 which handles newlines appropriately.
830 Interpretation of the buffer's octets can be abstracted out by
831 using the slightly higher-level functions L</lex_peek_unichar> and
832 L</lex_read_unichar>.
834 =for apidoc AmxU|char *|PL_parser-E<gt>linestart
836 Points to the start of the current line inside the lexer buffer.
837 This is useful for indicating at which column an error occurred, and
838 not much else. This must be updated by any lexing code that consumes
839 a newline; the function L</lex_read_to> handles this detail.
845 =for apidoc Amx|bool|lex_bufutf8
847 Indicates whether the octets in the lexer buffer
848 (L</PL_parser-E<gt>linestr>) should be interpreted as the UTF-8 encoding
849 of Unicode characters. If not, they should be interpreted as Latin-1
850 characters. This is analogous to the C<SvUTF8> flag for scalars.
852 In UTF-8 mode, it is not guaranteed that the lexer buffer actually
853 contains valid UTF-8. Lexing code must be robust in the face of invalid
856 The actual C<SvUTF8> flag of the L</PL_parser-E<gt>linestr> scalar
857 is significant, but not the whole story regarding the input character
858 encoding. Normally, when a file is being read, the scalar contains octets
859 and its C<SvUTF8> flag is off, but the octets should be interpreted as
860 UTF-8 if the C<use utf8> pragma is in effect. During a string eval,
861 however, the scalar may have the C<SvUTF8> flag on, and in this case its
862 octets should be interpreted as UTF-8 unless the C<use bytes> pragma
863 is in effect. This logic may change in the future; use this function
864 instead of implementing the logic yourself.
870 Perl_lex_bufutf8(pTHX)
876 =for apidoc Amx|char *|lex_grow_linestr|STRLEN len
878 Reallocates the lexer buffer (L</PL_parser-E<gt>linestr>) to accommodate
879 at least I<len> octets (including terminating NUL). Returns a
880 pointer to the reallocated buffer. This is necessary before making
881 any direct modification of the buffer that would increase its length.
882 L</lex_stuff_pvn> provides a more convenient way to insert text into
885 Do not use C<SvGROW> or C<sv_grow> directly on C<PL_parser-E<gt>linestr>;
886 this function updates all of the lexer's variables that point directly
893 Perl_lex_grow_linestr(pTHX_ STRLEN len)
897 STRLEN bufend_pos, bufptr_pos, oldbufptr_pos, oldoldbufptr_pos;
898 STRLEN linestart_pos, last_uni_pos, last_lop_pos;
899 linestr = PL_parser->linestr;
900 buf = SvPVX(linestr);
901 if (len <= SvLEN(linestr))
903 bufend_pos = PL_parser->bufend - buf;
904 bufptr_pos = PL_parser->bufptr - buf;
905 oldbufptr_pos = PL_parser->oldbufptr - buf;
906 oldoldbufptr_pos = PL_parser->oldoldbufptr - buf;
907 linestart_pos = PL_parser->linestart - buf;
908 last_uni_pos = PL_parser->last_uni ? PL_parser->last_uni - buf : 0;
909 last_lop_pos = PL_parser->last_lop ? PL_parser->last_lop - buf : 0;
910 buf = sv_grow(linestr, len);
911 PL_parser->bufend = buf + bufend_pos;
912 PL_parser->bufptr = buf + bufptr_pos;
913 PL_parser->oldbufptr = buf + oldbufptr_pos;
914 PL_parser->oldoldbufptr = buf + oldoldbufptr_pos;
915 PL_parser->linestart = buf + linestart_pos;
916 if (PL_parser->last_uni)
917 PL_parser->last_uni = buf + last_uni_pos;
918 if (PL_parser->last_lop)
919 PL_parser->last_lop = buf + last_lop_pos;
924 =for apidoc Amx|void|lex_stuff_pvn|const char *pv|STRLEN len|U32 flags
926 Insert characters into the lexer buffer (L</PL_parser-E<gt>linestr>),
927 immediately after the current lexing point (L</PL_parser-E<gt>bufptr>),
928 reallocating the buffer if necessary. This means that lexing code that
929 runs later will see the characters as if they had appeared in the input.
930 It is not recommended to do this as part of normal parsing, and most
931 uses of this facility run the risk of the inserted characters being
932 interpreted in an unintended manner.
934 The string to be inserted is represented by I<len> octets starting
935 at I<pv>. These octets are interpreted as either UTF-8 or Latin-1,
936 according to whether the C<LEX_STUFF_UTF8> flag is set in I<flags>.
937 The characters are recoded for the lexer buffer, according to how the
938 buffer is currently being interpreted (L</lex_bufutf8>). If a string
939 to be inserted is available as a Perl scalar, the L</lex_stuff_sv>
940 function is more convenient.
946 Perl_lex_stuff_pvn(pTHX_ const char *pv, STRLEN len, U32 flags)
950 PERL_ARGS_ASSERT_LEX_STUFF_PVN;
951 if (flags & ~(LEX_STUFF_UTF8))
952 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_stuff_pvn");
954 if (flags & LEX_STUFF_UTF8) {
958 const char *p, *e = pv+len;
959 for (p = pv; p != e; p++)
960 highhalf += !!(((U8)*p) & 0x80);
963 lex_grow_linestr(SvCUR(PL_parser->linestr)+1+len+highhalf);
964 bufptr = PL_parser->bufptr;
965 Move(bufptr, bufptr+len+highhalf, PL_parser->bufend+1-bufptr, char);
966 SvCUR_set(PL_parser->linestr,
967 SvCUR(PL_parser->linestr) + len+highhalf);
968 PL_parser->bufend += len+highhalf;
969 for (p = pv; p != e; p++) {
972 *bufptr++ = (char)(0xc0 | (c >> 6));
973 *bufptr++ = (char)(0x80 | (c & 0x3f));
980 if (flags & LEX_STUFF_UTF8) {
982 const char *p, *e = pv+len;
983 for (p = pv; p != e; p++) {
986 Perl_croak(aTHX_ "Lexing code attempted to stuff "
987 "non-Latin-1 character into Latin-1 input");
988 } else if (c >= 0xc2 && p+1 != e &&
989 (((U8)p[1]) & 0xc0) == 0x80) {
992 } else if (c >= 0x80) {
993 /* malformed UTF-8 */
995 SAVESPTR(PL_warnhook);
996 PL_warnhook = PERL_WARNHOOK_FATAL;
997 utf8n_to_uvuni((U8*)p, e-p, NULL, 0);
1003 lex_grow_linestr(SvCUR(PL_parser->linestr)+1+len-highhalf);
1004 bufptr = PL_parser->bufptr;
1005 Move(bufptr, bufptr+len-highhalf, PL_parser->bufend+1-bufptr, char);
1006 SvCUR_set(PL_parser->linestr,
1007 SvCUR(PL_parser->linestr) + len-highhalf);
1008 PL_parser->bufend += len-highhalf;
1009 for (p = pv; p != e; p++) {
1012 *bufptr++ = (char)(((c & 0x3) << 6) | (p[1] & 0x3f));
1015 *bufptr++ = (char)c;
1020 lex_grow_linestr(SvCUR(PL_parser->linestr)+1+len);
1021 bufptr = PL_parser->bufptr;
1022 Move(bufptr, bufptr+len, PL_parser->bufend+1-bufptr, char);
1023 SvCUR_set(PL_parser->linestr, SvCUR(PL_parser->linestr) + len);
1024 PL_parser->bufend += len;
1025 Copy(pv, bufptr, len, char);
1031 =for apidoc Amx|void|lex_stuff_pv|const char *pv|U32 flags
1033 Insert characters into the lexer buffer (L</PL_parser-E<gt>linestr>),
1034 immediately after the current lexing point (L</PL_parser-E<gt>bufptr>),
1035 reallocating the buffer if necessary. This means that lexing code that
1036 runs later will see the characters as if they had appeared in the input.
1037 It is not recommended to do this as part of normal parsing, and most
1038 uses of this facility run the risk of the inserted characters being
1039 interpreted in an unintended manner.
1041 The string to be inserted is represented by octets starting at I<pv>
1042 and continuing to the first nul. These octets are interpreted as either
1043 UTF-8 or Latin-1, according to whether the C<LEX_STUFF_UTF8> flag is set
1044 in I<flags>. The characters are recoded for the lexer buffer, according
1045 to how the buffer is currently being interpreted (L</lex_bufutf8>).
1046 If it is not convenient to nul-terminate a string to be inserted, the
1047 L</lex_stuff_pvn> function is more appropriate.
1053 Perl_lex_stuff_pv(pTHX_ const char *pv, U32 flags)
1055 PERL_ARGS_ASSERT_LEX_STUFF_PV;
1056 lex_stuff_pvn(pv, strlen(pv), flags);
1060 =for apidoc Amx|void|lex_stuff_sv|SV *sv|U32 flags
1062 Insert characters into the lexer buffer (L</PL_parser-E<gt>linestr>),
1063 immediately after the current lexing point (L</PL_parser-E<gt>bufptr>),
1064 reallocating the buffer if necessary. This means that lexing code that
1065 runs later will see the characters as if they had appeared in the input.
1066 It is not recommended to do this as part of normal parsing, and most
1067 uses of this facility run the risk of the inserted characters being
1068 interpreted in an unintended manner.
1070 The string to be inserted is the string value of I<sv>. The characters
1071 are recoded for the lexer buffer, according to how the buffer is currently
1072 being interpreted (L</lex_bufutf8>). If a string to be inserted is
1073 not already a Perl scalar, the L</lex_stuff_pvn> function avoids the
1074 need to construct a scalar.
1080 Perl_lex_stuff_sv(pTHX_ SV *sv, U32 flags)
1084 PERL_ARGS_ASSERT_LEX_STUFF_SV;
1086 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_stuff_sv");
1088 lex_stuff_pvn(pv, len, flags | (SvUTF8(sv) ? LEX_STUFF_UTF8 : 0));
1092 =for apidoc Amx|void|lex_unstuff|char *ptr
1094 Discards text about to be lexed, from L</PL_parser-E<gt>bufptr> up to
1095 I<ptr>. Text following I<ptr> will be moved, and the buffer shortened.
1096 This hides the discarded text from any lexing code that runs later,
1097 as if the text had never appeared.
1099 This is not the normal way to consume lexed text. For that, use
1106 Perl_lex_unstuff(pTHX_ char *ptr)
1110 PERL_ARGS_ASSERT_LEX_UNSTUFF;
1111 buf = PL_parser->bufptr;
1113 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_unstuff");
1116 bufend = PL_parser->bufend;
1118 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_unstuff");
1119 unstuff_len = ptr - buf;
1120 Move(ptr, buf, bufend+1-ptr, char);
1121 SvCUR_set(PL_parser->linestr, SvCUR(PL_parser->linestr) - unstuff_len);
1122 PL_parser->bufend = bufend - unstuff_len;
1126 =for apidoc Amx|void|lex_read_to|char *ptr
1128 Consume text in the lexer buffer, from L</PL_parser-E<gt>bufptr> up
1129 to I<ptr>. This advances L</PL_parser-E<gt>bufptr> to match I<ptr>,
1130 performing the correct bookkeeping whenever a newline character is passed.
1131 This is the normal way to consume lexed text.
1133 Interpretation of the buffer's octets can be abstracted out by
1134 using the slightly higher-level functions L</lex_peek_unichar> and
1135 L</lex_read_unichar>.
1141 Perl_lex_read_to(pTHX_ char *ptr)
1144 PERL_ARGS_ASSERT_LEX_READ_TO;
1145 s = PL_parser->bufptr;
1146 if (ptr < s || ptr > PL_parser->bufend)
1147 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_read_to");
1148 for (; s != ptr; s++)
1150 CopLINE_inc(PL_curcop);
1151 PL_parser->linestart = s+1;
1153 PL_parser->bufptr = ptr;
1157 =for apidoc Amx|void|lex_discard_to|char *ptr
1159 Discards the first part of the L</PL_parser-E<gt>linestr> buffer,
1160 up to I<ptr>. The remaining content of the buffer will be moved, and
1161 all pointers into the buffer updated appropriately. I<ptr> must not
1162 be later in the buffer than the position of L</PL_parser-E<gt>bufptr>:
1163 it is not permitted to discard text that has yet to be lexed.
1165 Normally it is not necessarily to do this directly, because it suffices to
1166 use the implicit discarding behaviour of L</lex_next_chunk> and things
1167 based on it. However, if a token stretches across multiple lines,
1168 and the lexing code has kept multiple lines of text in the buffer for
1169 that purpose, then after completion of the token it would be wise to
1170 explicitly discard the now-unneeded earlier lines, to avoid future
1171 multi-line tokens growing the buffer without bound.
1177 Perl_lex_discard_to(pTHX_ char *ptr)
1181 PERL_ARGS_ASSERT_LEX_DISCARD_TO;
1182 buf = SvPVX(PL_parser->linestr);
1184 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_discard_to");
1187 if (ptr > PL_parser->bufptr)
1188 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_discard_to");
1189 discard_len = ptr - buf;
1190 if (PL_parser->oldbufptr < ptr)
1191 PL_parser->oldbufptr = ptr;
1192 if (PL_parser->oldoldbufptr < ptr)
1193 PL_parser->oldoldbufptr = ptr;
1194 if (PL_parser->last_uni && PL_parser->last_uni < ptr)
1195 PL_parser->last_uni = NULL;
1196 if (PL_parser->last_lop && PL_parser->last_lop < ptr)
1197 PL_parser->last_lop = NULL;
1198 Move(ptr, buf, PL_parser->bufend+1-ptr, char);
1199 SvCUR_set(PL_parser->linestr, SvCUR(PL_parser->linestr) - discard_len);
1200 PL_parser->bufend -= discard_len;
1201 PL_parser->bufptr -= discard_len;
1202 PL_parser->oldbufptr -= discard_len;
1203 PL_parser->oldoldbufptr -= discard_len;
1204 if (PL_parser->last_uni)
1205 PL_parser->last_uni -= discard_len;
1206 if (PL_parser->last_lop)
1207 PL_parser->last_lop -= discard_len;
1211 =for apidoc Amx|bool|lex_next_chunk|U32 flags
1213 Reads in the next chunk of text to be lexed, appending it to
1214 L</PL_parser-E<gt>linestr>. This should be called when lexing code has
1215 looked to the end of the current chunk and wants to know more. It is
1216 usual, but not necessary, for lexing to have consumed the entirety of
1217 the current chunk at this time.
1219 If L</PL_parser-E<gt>bufptr> is pointing to the very end of the current
1220 chunk (i.e., the current chunk has been entirely consumed), normally the
1221 current chunk will be discarded at the same time that the new chunk is
1222 read in. If I<flags> includes C<LEX_KEEP_PREVIOUS>, the current chunk
1223 will not be discarded. If the current chunk has not been entirely
1224 consumed, then it will not be discarded regardless of the flag.
1226 Returns true if some new text was added to the buffer, or false if the
1227 buffer has reached the end of the input text.
1232 #define LEX_FAKE_EOF 0x80000000
1235 Perl_lex_next_chunk(pTHX_ U32 flags)
1239 STRLEN old_bufend_pos, new_bufend_pos;
1240 STRLEN bufptr_pos, oldbufptr_pos, oldoldbufptr_pos;
1241 STRLEN linestart_pos, last_uni_pos, last_lop_pos;
1242 bool got_some_for_debugger = 0;
1244 if (flags & ~(LEX_KEEP_PREVIOUS|LEX_FAKE_EOF))
1245 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_next_chunk");
1246 linestr = PL_parser->linestr;
1247 buf = SvPVX(linestr);
1248 if (!(flags & LEX_KEEP_PREVIOUS) &&
1249 PL_parser->bufptr == PL_parser->bufend) {
1250 old_bufend_pos = bufptr_pos = oldbufptr_pos = oldoldbufptr_pos = 0;
1252 if (PL_parser->last_uni != PL_parser->bufend)
1253 PL_parser->last_uni = NULL;
1254 if (PL_parser->last_lop != PL_parser->bufend)
1255 PL_parser->last_lop = NULL;
1256 last_uni_pos = last_lop_pos = 0;
1260 old_bufend_pos = PL_parser->bufend - buf;
1261 bufptr_pos = PL_parser->bufptr - buf;
1262 oldbufptr_pos = PL_parser->oldbufptr - buf;
1263 oldoldbufptr_pos = PL_parser->oldoldbufptr - buf;
1264 linestart_pos = PL_parser->linestart - buf;
1265 last_uni_pos = PL_parser->last_uni ? PL_parser->last_uni - buf : 0;
1266 last_lop_pos = PL_parser->last_lop ? PL_parser->last_lop - buf : 0;
1268 if (flags & LEX_FAKE_EOF) {
1270 } else if (!PL_parser->rsfp && !PL_parser->filtered) {
1272 } else if (filter_gets(linestr, old_bufend_pos)) {
1274 got_some_for_debugger = 1;
1276 if (!SvPOK(linestr)) /* can get undefined by filter_gets */
1277 sv_setpvs(linestr, "");
1279 /* End of real input. Close filehandle (unless it was STDIN),
1280 * then add implicit termination.
1282 if ((PerlIO*)PL_parser->rsfp == PerlIO_stdin())
1283 PerlIO_clearerr(PL_parser->rsfp);
1284 else if (PL_parser->rsfp)
1285 (void)PerlIO_close(PL_parser->rsfp);
1286 PL_parser->rsfp = NULL;
1287 PL_parser->in_pod = PL_parser->filtered = 0;
1289 if (PL_madskills && !PL_in_eval && (PL_minus_p || PL_minus_n))
1292 if (!PL_in_eval && PL_minus_p) {
1294 /*{*/";}continue{print or die qq(-p destination: $!\\n);}");
1295 PL_minus_n = PL_minus_p = 0;
1296 } else if (!PL_in_eval && PL_minus_n) {
1297 sv_catpvs(linestr, /*{*/";}");
1300 sv_catpvs(linestr, ";");
1303 buf = SvPVX(linestr);
1304 new_bufend_pos = SvCUR(linestr);
1305 PL_parser->bufend = buf + new_bufend_pos;
1306 PL_parser->bufptr = buf + bufptr_pos;
1307 PL_parser->oldbufptr = buf + oldbufptr_pos;
1308 PL_parser->oldoldbufptr = buf + oldoldbufptr_pos;
1309 PL_parser->linestart = buf + linestart_pos;
1310 if (PL_parser->last_uni)
1311 PL_parser->last_uni = buf + last_uni_pos;
1312 if (PL_parser->last_lop)
1313 PL_parser->last_lop = buf + last_lop_pos;
1314 if (got_some_for_debugger && (PERLDB_LINE || PERLDB_SAVESRC) &&
1315 PL_curstash != PL_debstash) {
1316 /* debugger active and we're not compiling the debugger code,
1317 * so store the line into the debugger's array of lines
1319 update_debugger_info(NULL, buf+old_bufend_pos,
1320 new_bufend_pos-old_bufend_pos);
1326 =for apidoc Amx|I32|lex_peek_unichar|U32 flags
1328 Looks ahead one (Unicode) character in the text currently being lexed.
1329 Returns the codepoint (unsigned integer value) of the next character,
1330 or -1 if lexing has reached the end of the input text. To consume the
1331 peeked character, use L</lex_read_unichar>.
1333 If the next character is in (or extends into) the next chunk of input
1334 text, the next chunk will be read in. Normally the current chunk will be
1335 discarded at the same time, but if I<flags> includes C<LEX_KEEP_PREVIOUS>
1336 then the current chunk will not be discarded.
1338 If the input is being interpreted as UTF-8 and a UTF-8 encoding error
1339 is encountered, an exception is generated.
1345 Perl_lex_peek_unichar(pTHX_ U32 flags)
1349 if (flags & ~(LEX_KEEP_PREVIOUS))
1350 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_peek_unichar");
1351 s = PL_parser->bufptr;
1352 bufend = PL_parser->bufend;
1358 if (!lex_next_chunk(flags))
1360 s = PL_parser->bufptr;
1361 bufend = PL_parser->bufend;
1367 len = PL_utf8skip[head];
1368 while ((STRLEN)(bufend-s) < len) {
1369 if (!lex_next_chunk(flags | LEX_KEEP_PREVIOUS))
1371 s = PL_parser->bufptr;
1372 bufend = PL_parser->bufend;
1375 unichar = utf8n_to_uvuni((U8*)s, bufend-s, &retlen, UTF8_CHECK_ONLY);
1376 if (retlen == (STRLEN)-1) {
1377 /* malformed UTF-8 */
1379 SAVESPTR(PL_warnhook);
1380 PL_warnhook = PERL_WARNHOOK_FATAL;
1381 utf8n_to_uvuni((U8*)s, bufend-s, NULL, 0);
1387 if (!lex_next_chunk(flags))
1389 s = PL_parser->bufptr;
1396 =for apidoc Amx|I32|lex_read_unichar|U32 flags
1398 Reads the next (Unicode) character in the text currently being lexed.
1399 Returns the codepoint (unsigned integer value) of the character read,
1400 and moves L</PL_parser-E<gt>bufptr> past the character, or returns -1
1401 if lexing has reached the end of the input text. To non-destructively
1402 examine the next character, use L</lex_peek_unichar> instead.
1404 If the next character is in (or extends into) the next chunk of input
1405 text, the next chunk will be read in. Normally the current chunk will be
1406 discarded at the same time, but if I<flags> includes C<LEX_KEEP_PREVIOUS>
1407 then the current chunk will not be discarded.
1409 If the input is being interpreted as UTF-8 and a UTF-8 encoding error
1410 is encountered, an exception is generated.
1416 Perl_lex_read_unichar(pTHX_ U32 flags)
1419 if (flags & ~(LEX_KEEP_PREVIOUS))
1420 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_read_unichar");
1421 c = lex_peek_unichar(flags);
1424 CopLINE_inc(PL_curcop);
1426 PL_parser->bufptr += UTF8SKIP(PL_parser->bufptr);
1428 ++(PL_parser->bufptr);
1434 =for apidoc Amx|void|lex_read_space|U32 flags
1436 Reads optional spaces, in Perl style, in the text currently being
1437 lexed. The spaces may include ordinary whitespace characters and
1438 Perl-style comments. C<#line> directives are processed if encountered.
1439 L</PL_parser-E<gt>bufptr> is moved past the spaces, so that it points
1440 at a non-space character (or the end of the input text).
1442 If spaces extend into the next chunk of input text, the next chunk will
1443 be read in. Normally the current chunk will be discarded at the same
1444 time, but if I<flags> includes C<LEX_KEEP_PREVIOUS> then the current
1445 chunk will not be discarded.
1450 #define LEX_NO_NEXT_CHUNK 0x80000000
1453 Perl_lex_read_space(pTHX_ U32 flags)
1456 bool need_incline = 0;
1457 if (flags & ~(LEX_KEEP_PREVIOUS|LEX_NO_NEXT_CHUNK))
1458 Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_read_space");
1461 sv_free(PL_skipwhite);
1462 PL_skipwhite = NULL;
1465 PL_skipwhite = newSVpvs("");
1466 #endif /* PERL_MAD */
1467 s = PL_parser->bufptr;
1468 bufend = PL_parser->bufend;
1474 } while (!(c == '\n' || (c == 0 && s == bufend)));
1475 } else if (c == '\n') {
1477 PL_parser->linestart = s;
1482 } else if (isSPACE(c)) {
1484 } else if (c == 0 && s == bufend) {
1488 sv_catpvn(PL_skipwhite, PL_parser->bufptr, s-PL_parser->bufptr);
1489 #endif /* PERL_MAD */
1490 if (flags & LEX_NO_NEXT_CHUNK)
1492 PL_parser->bufptr = s;
1493 CopLINE_inc(PL_curcop);
1494 got_more = lex_next_chunk(flags);
1495 CopLINE_dec(PL_curcop);
1496 s = PL_parser->bufptr;
1497 bufend = PL_parser->bufend;
1500 if (need_incline && PL_parser->rsfp) {
1510 sv_catpvn(PL_skipwhite, PL_parser->bufptr, s-PL_parser->bufptr);
1511 #endif /* PERL_MAD */
1512 PL_parser->bufptr = s;
1517 * This subroutine has nothing to do with tilting, whether at windmills
1518 * or pinball tables. Its name is short for "increment line". It
1519 * increments the current line number in CopLINE(PL_curcop) and checks
1520 * to see whether the line starts with a comment of the form
1521 * # line 500 "foo.pm"
1522 * If so, it sets the current line number and file to the values in the comment.
1526 S_incline(pTHX_ const char *s)
1534 PERL_ARGS_ASSERT_INCLINE;
1536 CopLINE_inc(PL_curcop);
1539 while (SPACE_OR_TAB(*s))
1541 if (strnEQ(s, "line", 4))
1545 if (SPACE_OR_TAB(*s))
1549 while (SPACE_OR_TAB(*s))
1557 if (!SPACE_OR_TAB(*s) && *s != '\r' && *s != '\n' && *s != '\0')
1559 while (SPACE_OR_TAB(*s))
1561 if (*s == '"' && (t = strchr(s+1, '"'))) {
1567 while (!isSPACE(*t))
1571 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
1573 if (*e != '\n' && *e != '\0')
1574 return; /* false alarm */
1576 line_num = atoi(n)-1;
1579 const STRLEN len = t - s;
1580 SV *const temp_sv = CopFILESV(PL_curcop);
1585 cf = SvPVX(temp_sv);
1586 tmplen = SvCUR(temp_sv);
1592 if (!PL_rsfp && !PL_parser->filtered) {
1593 /* must copy *{"::_<(eval N)[oldfilename:L]"}
1594 * to *{"::_<newfilename"} */
1595 /* However, the long form of evals is only turned on by the
1596 debugger - usually they're "(eval %lu)" */
1600 STRLEN tmplen2 = len;
1601 if (tmplen + 2 <= sizeof smallbuf)
1604 Newx(tmpbuf, tmplen + 2, char);
1607 memcpy(tmpbuf + 2, cf, tmplen);
1609 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
1614 if (tmplen2 + 2 <= sizeof smallbuf)
1617 Newx(tmpbuf2, tmplen2 + 2, char);
1619 if (tmpbuf2 != smallbuf || tmpbuf != smallbuf) {
1620 /* Either they malloc'd it, or we malloc'd it,
1621 so no prefix is present in ours. */
1626 memcpy(tmpbuf2 + 2, s, tmplen2);
1629 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
1631 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
1632 /* adjust ${"::_<newfilename"} to store the new file name */
1633 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
1634 /* The line number may differ. If that is the case,
1635 alias the saved lines that are in the array.
1636 Otherwise alias the whole array. */
1637 if (CopLINE(PL_curcop) == line_num) {
1638 GvHV(gv2) = MUTABLE_HV(SvREFCNT_inc(GvHV(*gvp)));
1639 GvAV(gv2) = MUTABLE_AV(SvREFCNT_inc(GvAV(*gvp)));
1641 else if (GvAV(*gvp)) {
1642 AV * const av = GvAV(*gvp);
1643 const I32 start = CopLINE(PL_curcop)+1;
1644 I32 items = AvFILLp(av) - start;
1646 AV * const av2 = GvAVn(gv2);
1647 SV **svp = AvARRAY(av) + start;
1648 I32 l = (I32)line_num+1;
1650 av_store(av2, l++, SvREFCNT_inc(*svp++));
1655 if (tmpbuf2 != smallbuf) Safefree(tmpbuf2);
1657 if (tmpbuf != smallbuf) Safefree(tmpbuf);
1659 CopFILE_free(PL_curcop);
1660 CopFILE_setn(PL_curcop, s, len);
1662 CopLINE_set(PL_curcop, line_num);
1666 /* skip space before PL_thistoken */
1669 S_skipspace0(pTHX_ register char *s)
1671 PERL_ARGS_ASSERT_SKIPSPACE0;
1678 PL_thiswhite = newSVpvs("");
1679 sv_catsv(PL_thiswhite, PL_skipwhite);
1680 sv_free(PL_skipwhite);
1683 PL_realtokenstart = s - SvPVX(PL_linestr);
1687 /* skip space after PL_thistoken */
1690 S_skipspace1(pTHX_ register char *s)
1692 const char *start = s;
1693 I32 startoff = start - SvPVX(PL_linestr);
1695 PERL_ARGS_ASSERT_SKIPSPACE1;
1700 start = SvPVX(PL_linestr) + startoff;
1701 if (!PL_thistoken && PL_realtokenstart >= 0) {
1702 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
1703 PL_thistoken = newSVpvn(tstart, start - tstart);
1705 PL_realtokenstart = -1;
1708 PL_nextwhite = newSVpvs("");
1709 sv_catsv(PL_nextwhite, PL_skipwhite);
1710 sv_free(PL_skipwhite);
1717 S_skipspace2(pTHX_ register char *s, SV **svp)
1720 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
1721 const I32 startoff = s - SvPVX(PL_linestr);
1723 PERL_ARGS_ASSERT_SKIPSPACE2;
1726 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
1727 if (!PL_madskills || !svp)
1729 start = SvPVX(PL_linestr) + startoff;
1730 if (!PL_thistoken && PL_realtokenstart >= 0) {
1731 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
1732 PL_thistoken = newSVpvn(tstart, start - tstart);
1733 PL_realtokenstart = -1;
1737 *svp = newSVpvs("");
1738 sv_setsv(*svp, PL_skipwhite);
1739 sv_free(PL_skipwhite);
1748 S_update_debugger_info(pTHX_ SV *orig_sv, const char *const buf, STRLEN len)
1750 AV *av = CopFILEAVx(PL_curcop);
1752 SV * const sv = newSV_type(SVt_PVMG);
1754 sv_setsv(sv, orig_sv);
1756 sv_setpvn(sv, buf, len);
1759 av_store(av, (I32)CopLINE(PL_curcop), sv);
1765 * Called to gobble the appropriate amount and type of whitespace.
1766 * Skips comments as well.
1770 S_skipspace(pTHX_ register char *s)
1774 #endif /* PERL_MAD */
1775 PERL_ARGS_ASSERT_SKIPSPACE;
1778 sv_free(PL_skipwhite);
1779 PL_skipwhite = NULL;
1781 #endif /* PERL_MAD */
1782 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
1783 while (s < PL_bufend && SPACE_OR_TAB(*s))
1786 STRLEN bufptr_pos = PL_bufptr - SvPVX(PL_linestr);
1788 lex_read_space(LEX_KEEP_PREVIOUS |
1789 (PL_sublex_info.sub_inwhat || PL_lex_state == LEX_FORMLINE ?
1790 LEX_NO_NEXT_CHUNK : 0));
1792 PL_bufptr = SvPVX(PL_linestr) + bufptr_pos;
1793 if (PL_linestart > PL_bufptr)
1794 PL_bufptr = PL_linestart;
1799 PL_skipwhite = newSVpvn(start, s-start);
1800 #endif /* PERL_MAD */
1806 * Check the unary operators to ensure there's no ambiguity in how they're
1807 * used. An ambiguous piece of code would be:
1809 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1810 * the +5 is its argument.
1820 if (PL_oldoldbufptr != PL_last_uni)
1822 while (isSPACE(*PL_last_uni))
1825 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1827 if ((t = strchr(s, '(')) && t < PL_bufptr)
1830 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
1831 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1832 (int)(s - PL_last_uni), PL_last_uni);
1836 * LOP : macro to build a list operator. Its behaviour has been replaced
1837 * with a subroutine, S_lop() for which LOP is just another name.
1840 #define LOP(f,x) return lop(f,x,s)
1844 * Build a list operator (or something that might be one). The rules:
1845 * - if we have a next token, then it's a list operator [why?]
1846 * - if the next thing is an opening paren, then it's a function
1847 * - else it's a list operator
1851 S_lop(pTHX_ I32 f, int x, char *s)
1855 PERL_ARGS_ASSERT_LOP;
1861 PL_last_lop = PL_oldbufptr;
1862 PL_last_lop_op = (OPCODE)f;
1871 return REPORT(FUNC);
1874 return REPORT(FUNC);
1877 if (!PL_lex_allbrackets && PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC)
1878 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC;
1879 return REPORT(LSTOP);
1886 * Sets up for an eventual force_next(). start_force(0) basically does
1887 * an unshift, while start_force(-1) does a push. yylex removes items
1892 S_start_force(pTHX_ int where)
1896 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1897 where = PL_lasttoke;
1898 assert(PL_curforce < 0 || PL_curforce == where);
1899 if (PL_curforce != where) {
1900 for (i = PL_lasttoke; i > where; --i) {
1901 PL_nexttoke[i] = PL_nexttoke[i-1];
1905 if (PL_curforce < 0) /* in case of duplicate start_force() */
1906 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1907 PL_curforce = where;
1910 curmad('^', newSVpvs(""));
1911 CURMAD('_', PL_nextwhite);
1916 S_curmad(pTHX_ char slot, SV *sv)
1922 if (PL_curforce < 0)
1923 where = &PL_thismad;
1925 where = &PL_nexttoke[PL_curforce].next_mad;
1931 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1933 else if (PL_encoding) {
1934 sv_recode_to_utf8(sv, PL_encoding);
1939 /* keep a slot open for the head of the list? */
1940 if (slot != '_' && *where && (*where)->mad_key == '^') {
1941 (*where)->mad_key = slot;
1942 sv_free(MUTABLE_SV(((*where)->mad_val)));
1943 (*where)->mad_val = (void*)sv;
1946 addmad(newMADsv(slot, sv), where, 0);
1949 # define start_force(where) NOOP
1950 # define curmad(slot, sv) NOOP
1955 * When the lexer realizes it knows the next token (for instance,
1956 * it is reordering tokens for the parser) then it can call S_force_next
1957 * to know what token to return the next time the lexer is called. Caller
1958 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1959 * and possibly PL_expect to ensure the lexer handles the token correctly.
1963 S_force_next(pTHX_ I32 type)
1968 PerlIO_printf(Perl_debug_log, "### forced token:\n");
1969 tokereport(type, &NEXTVAL_NEXTTOKE);
1973 if (PL_curforce < 0)
1974 start_force(PL_lasttoke);
1975 PL_nexttoke[PL_curforce].next_type = type;
1976 if (PL_lex_state != LEX_KNOWNEXT)
1977 PL_lex_defer = PL_lex_state;
1978 PL_lex_state = LEX_KNOWNEXT;
1979 PL_lex_expect = PL_expect;
1982 PL_nexttype[PL_nexttoke] = type;
1984 if (PL_lex_state != LEX_KNOWNEXT) {
1985 PL_lex_defer = PL_lex_state;
1986 PL_lex_expect = PL_expect;
1987 PL_lex_state = LEX_KNOWNEXT;
1995 int yyc = PL_parser->yychar;
1996 if (yyc != YYEMPTY) {
1999 NEXTVAL_NEXTTOKE = PL_parser->yylval;
2000 if (yyc == '{'/*}*/ || yyc == HASHBRACK || yyc == '['/*]*/) {
2001 PL_lex_allbrackets--;
2003 yyc |= (3<<24) | (PL_lex_brackstack[PL_lex_brackets] << 16);
2004 } else if (yyc == '('/*)*/) {
2005 PL_lex_allbrackets--;
2010 PL_parser->yychar = YYEMPTY;
2015 S_newSV_maybe_utf8(pTHX_ const char *const start, STRLEN len)
2018 SV * const sv = newSVpvn_utf8(start, len,
2021 && !is_ascii_string((const U8*)start, len)
2022 && is_utf8_string((const U8*)start, len));
2028 * When the lexer knows the next thing is a word (for instance, it has
2029 * just seen -> and it knows that the next char is a word char, then
2030 * it calls S_force_word to stick the next word into the PL_nexttoke/val
2034 * char *start : buffer position (must be within PL_linestr)
2035 * int token : PL_next* will be this type of bare word (e.g., METHOD,WORD)
2036 * int check_keyword : if true, Perl checks to make sure the word isn't
2037 * a keyword (do this if the word is a label, e.g. goto FOO)
2038 * int allow_pack : if true, : characters will also be allowed (require,
2039 * use, etc. do this)
2040 * int allow_initial_tick : used by the "sub" lexer only.
2044 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
2050 PERL_ARGS_ASSERT_FORCE_WORD;
2052 start = SKIPSPACE1(start);
2054 if (isIDFIRST_lazy_if(s,UTF) ||
2055 (allow_pack && *s == ':') ||
2056 (allow_initial_tick && *s == '\'') )
2058 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
2059 if (check_keyword && keyword(PL_tokenbuf, len, 0))
2061 start_force(PL_curforce);
2063 curmad('X', newSVpvn(start,s-start));
2064 if (token == METHOD) {
2069 PL_expect = XOPERATOR;
2073 curmad('g', newSVpvs( "forced" ));
2074 NEXTVAL_NEXTTOKE.opval
2075 = (OP*)newSVOP(OP_CONST,0,
2076 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
2077 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
2085 * Called when the lexer wants $foo *foo &foo etc, but the program
2086 * text only contains the "foo" portion. The first argument is a pointer
2087 * to the "foo", and the second argument is the type symbol to prefix.
2088 * Forces the next token to be a "WORD".
2089 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
2093 S_force_ident(pTHX_ register const char *s, int kind)
2097 PERL_ARGS_ASSERT_FORCE_IDENT;
2100 const STRLEN len = strlen(s);
2101 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn_flags(s, len,
2102 UTF ? SVf_UTF8 : 0));
2103 start_force(PL_curforce);
2104 NEXTVAL_NEXTTOKE.opval = o;
2107 o->op_private = OPpCONST_ENTERED;
2108 /* XXX see note in pp_entereval() for why we forgo typo
2109 warnings if the symbol must be introduced in an eval.
2111 gv_fetchpvn_flags(s, len,
2112 (PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
2113 : GV_ADD) | ( UTF ? SVf_UTF8 : 0 ),
2114 kind == '$' ? SVt_PV :
2115 kind == '@' ? SVt_PVAV :
2116 kind == '%' ? SVt_PVHV :
2124 Perl_str_to_version(pTHX_ SV *sv)
2129 const char *start = SvPV_const(sv,len);
2130 const char * const end = start + len;
2131 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
2133 PERL_ARGS_ASSERT_STR_TO_VERSION;
2135 while (start < end) {
2139 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
2144 retval += ((NV)n)/nshift;
2153 * Forces the next token to be a version number.
2154 * If the next token appears to be an invalid version number, (e.g. "v2b"),
2155 * and if "guessing" is TRUE, then no new token is created (and the caller
2156 * must use an alternative parsing method).
2160 S_force_version(pTHX_ char *s, int guessing)
2166 I32 startoff = s - SvPVX(PL_linestr);
2169 PERL_ARGS_ASSERT_FORCE_VERSION;
2177 while (isDIGIT(*d) || *d == '_' || *d == '.')
2181 start_force(PL_curforce);
2182 curmad('X', newSVpvn(s,d-s));
2185 if (*d == ';' || isSPACE(*d) || *d == '{' || *d == '}' || !*d) {
2187 #ifdef USE_LOCALE_NUMERIC
2188 char *loc = setlocale(LC_NUMERIC, "C");
2190 s = scan_num(s, &pl_yylval);
2191 #ifdef USE_LOCALE_NUMERIC
2192 setlocale(LC_NUMERIC, loc);
2194 version = pl_yylval.opval;
2195 ver = cSVOPx(version)->op_sv;
2196 if (SvPOK(ver) && !SvNIOK(ver)) {
2197 SvUPGRADE(ver, SVt_PVNV);
2198 SvNV_set(ver, str_to_version(ver));
2199 SvNOK_on(ver); /* hint that it is a version */
2202 else if (guessing) {
2205 sv_free(PL_nextwhite); /* let next token collect whitespace */
2207 s = SvPVX(PL_linestr) + startoff;
2215 if (PL_madskills && !version) {
2216 sv_free(PL_nextwhite); /* let next token collect whitespace */
2218 s = SvPVX(PL_linestr) + startoff;
2221 /* NOTE: The parser sees the package name and the VERSION swapped */
2222 start_force(PL_curforce);
2223 NEXTVAL_NEXTTOKE.opval = version;
2230 * S_force_strict_version
2231 * Forces the next token to be a version number using strict syntax rules.
2235 S_force_strict_version(pTHX_ char *s)
2240 I32 startoff = s - SvPVX(PL_linestr);
2242 const char *errstr = NULL;
2244 PERL_ARGS_ASSERT_FORCE_STRICT_VERSION;
2246 while (isSPACE(*s)) /* leading whitespace */
2249 if (is_STRICT_VERSION(s,&errstr)) {
2251 s = (char *)scan_version(s, ver, 0);
2252 version = newSVOP(OP_CONST, 0, ver);
2254 else if ( (*s != ';' && *s != '{' && *s != '}' ) &&
2255 (s = SKIPSPACE1(s), (*s != ';' && *s != '{' && *s != '}' )))
2259 yyerror(errstr); /* version required */
2264 if (PL_madskills && !version) {
2265 sv_free(PL_nextwhite); /* let next token collect whitespace */
2267 s = SvPVX(PL_linestr) + startoff;
2270 /* NOTE: The parser sees the package name and the VERSION swapped */
2271 start_force(PL_curforce);
2272 NEXTVAL_NEXTTOKE.opval = version;
2280 * Tokenize a quoted string passed in as an SV. It finds the next
2281 * chunk, up to end of string or a backslash. It may make a new
2282 * SV containing that chunk (if HINT_NEW_STRING is on). It also
2287 S_tokeq(pTHX_ SV *sv)
2291 register char *send;
2296 PERL_ARGS_ASSERT_TOKEQ;
2301 s = SvPV_force(sv, len);
2302 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
2305 /* This is relying on the SV being "well formed" with a trailing '\0' */
2306 while (s < send && !(*s == '\\' && s[1] == '\\'))
2311 if ( PL_hints & HINT_NEW_STRING ) {
2312 pv = newSVpvn_flags(SvPVX_const(pv), len, SVs_TEMP | SvUTF8(sv));
2316 if (s + 1 < send && (s[1] == '\\'))
2317 s++; /* all that, just for this */
2322 SvCUR_set(sv, d - SvPVX_const(sv));
2324 if ( PL_hints & HINT_NEW_STRING )
2325 return new_constant(NULL, 0, "q", sv, pv, "q", 1);
2330 * Now come three functions related to double-quote context,
2331 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
2332 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
2333 * interact with PL_lex_state, and create fake ( ... ) argument lists
2334 * to handle functions and concatenation.
2335 * They assume that whoever calls them will be setting up a fake
2336 * join call, because each subthing puts a ',' after it. This lets
2339 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
2341 * (I'm not sure whether the spurious commas at the end of lcfirst's
2342 * arguments and join's arguments are created or not).
2347 * Assumes that pl_yylval.ival is the op we're creating (e.g. OP_LCFIRST).
2349 * Pattern matching will set PL_lex_op to the pattern-matching op to
2350 * make (we return THING if pl_yylval.ival is OP_NULL, PMFUNC otherwise).
2352 * OP_CONST and OP_READLINE are easy--just make the new op and return.
2354 * Everything else becomes a FUNC.
2356 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
2357 * had an OP_CONST or OP_READLINE). This just sets us up for a
2358 * call to S_sublex_push().
2362 S_sublex_start(pTHX)
2365 register const I32 op_type = pl_yylval.ival;
2367 if (op_type == OP_NULL) {
2368 pl_yylval.opval = PL_lex_op;
2372 if (op_type == OP_CONST || op_type == OP_READLINE) {
2373 SV *sv = tokeq(PL_lex_stuff);
2375 if (SvTYPE(sv) == SVt_PVIV) {
2376 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
2378 const char * const p = SvPV_const(sv, len);
2379 SV * const nsv = newSVpvn_flags(p, len, SvUTF8(sv));
2383 pl_yylval.opval = (OP*)newSVOP(op_type, 0, sv);
2384 PL_lex_stuff = NULL;
2385 /* Allow <FH> // "foo" */
2386 if (op_type == OP_READLINE)
2387 PL_expect = XTERMORDORDOR;
2390 else if (op_type == OP_BACKTICK && PL_lex_op) {
2391 /* readpipe() vas overriden */
2392 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
2393 pl_yylval.opval = PL_lex_op;
2395 PL_lex_stuff = NULL;
2399 PL_sublex_info.super_state = PL_lex_state;
2400 PL_sublex_info.sub_inwhat = (U16)op_type;
2401 PL_sublex_info.sub_op = PL_lex_op;
2402 PL_lex_state = LEX_INTERPPUSH;
2406 pl_yylval.opval = PL_lex_op;
2416 * Create a new scope to save the lexing state. The scope will be
2417 * ended in S_sublex_done. Returns a '(', starting the function arguments
2418 * to the uc, lc, etc. found before.
2419 * Sets PL_lex_state to LEX_INTERPCONCAT.
2428 PL_lex_state = PL_sublex_info.super_state;
2429 SAVEBOOL(PL_lex_dojoin);
2430 SAVEI32(PL_lex_brackets);
2431 SAVEI32(PL_lex_allbrackets);
2432 SAVEI8(PL_lex_fakeeof);
2433 SAVEI32(PL_lex_casemods);
2434 SAVEI32(PL_lex_starts);
2435 SAVEI8(PL_lex_state);
2436 SAVEVPTR(PL_lex_inpat);
2437 SAVEI16(PL_lex_inwhat);
2438 SAVECOPLINE(PL_curcop);
2439 SAVEPPTR(PL_bufptr);
2440 SAVEPPTR(PL_bufend);
2441 SAVEPPTR(PL_oldbufptr);
2442 SAVEPPTR(PL_oldoldbufptr);
2443 SAVEPPTR(PL_last_lop);
2444 SAVEPPTR(PL_last_uni);
2445 SAVEPPTR(PL_linestart);
2446 SAVESPTR(PL_linestr);
2447 SAVEGENERICPV(PL_lex_brackstack);
2448 SAVEGENERICPV(PL_lex_casestack);
2450 PL_linestr = PL_lex_stuff;
2451 PL_lex_stuff = NULL;
2453 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
2454 = SvPVX(PL_linestr);
2455 PL_bufend += SvCUR(PL_linestr);
2456 PL_last_lop = PL_last_uni = NULL;
2457 SAVEFREESV(PL_linestr);
2459 PL_lex_dojoin = FALSE;
2460 PL_lex_brackets = 0;
2461 PL_lex_allbrackets = 0;
2462 PL_lex_fakeeof = LEX_FAKEEOF_NEVER;
2463 Newx(PL_lex_brackstack, 120, char);
2464 Newx(PL_lex_casestack, 12, char);
2465 PL_lex_casemods = 0;
2466 *PL_lex_casestack = '\0';
2468 PL_lex_state = LEX_INTERPCONCAT;
2469 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
2471 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
2472 if (PL_lex_inwhat == OP_TRANSR) PL_lex_inwhat = OP_TRANS;
2473 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
2474 PL_lex_inpat = PL_sublex_info.sub_op;
2476 PL_lex_inpat = NULL;
2483 * Restores lexer state after a S_sublex_push.
2490 if (!PL_lex_starts++) {
2491 SV * const sv = newSVpvs("");
2492 if (SvUTF8(PL_linestr))
2494 PL_expect = XOPERATOR;
2495 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2499 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
2500 PL_lex_state = LEX_INTERPCASEMOD;
2504 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
2505 assert(PL_lex_inwhat != OP_TRANSR);
2506 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
2507 PL_linestr = PL_lex_repl;
2509 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
2510 PL_bufend += SvCUR(PL_linestr);
2511 PL_last_lop = PL_last_uni = NULL;
2512 SAVEFREESV(PL_linestr);
2513 PL_lex_dojoin = FALSE;
2514 PL_lex_brackets = 0;
2515 PL_lex_allbrackets = 0;
2516 PL_lex_fakeeof = LEX_FAKEEOF_NEVER;
2517 PL_lex_casemods = 0;
2518 *PL_lex_casestack = '\0';
2520 if (SvEVALED(PL_lex_repl)) {
2521 PL_lex_state = LEX_INTERPNORMAL;
2523 /* we don't clear PL_lex_repl here, so that we can check later
2524 whether this is an evalled subst; that means we rely on the
2525 logic to ensure sublex_done() is called again only via the
2526 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
2529 PL_lex_state = LEX_INTERPCONCAT;
2539 PL_endwhite = newSVpvs("");
2540 sv_catsv(PL_endwhite, PL_thiswhite);
2544 sv_setpvs(PL_thistoken,"");
2546 PL_realtokenstart = -1;
2550 PL_bufend = SvPVX(PL_linestr);
2551 PL_bufend += SvCUR(PL_linestr);
2552 PL_expect = XOPERATOR;
2553 PL_sublex_info.sub_inwhat = 0;
2561 Extracts a pattern, double-quoted string, or transliteration. This
2564 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
2565 processing a pattern (PL_lex_inpat is true), a transliteration
2566 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
2568 Returns a pointer to the character scanned up to. If this is
2569 advanced from the start pointer supplied (i.e. if anything was
2570 successfully parsed), will leave an OP for the substring scanned
2571 in pl_yylval. Caller must intuit reason for not parsing further
2572 by looking at the next characters herself.
2576 constants: \N{NAME} only
2577 case and quoting: \U \Q \E
2578 stops on @ and $, but not for $ as tail anchor
2580 In transliterations:
2581 characters are VERY literal, except for - not at the start or end
2582 of the string, which indicates a range. If the range is in bytes,
2583 scan_const expands the range to the full set of intermediate
2584 characters. If the range is in utf8, the hyphen is replaced with
2585 a certain range mark which will be handled by pmtrans() in op.c.
2587 In double-quoted strings:
2589 double-quoted style: \r and \n
2590 constants: \x31, etc.
2591 deprecated backrefs: \1 (in substitution replacements)
2592 case and quoting: \U \Q \E
2595 scan_const does *not* construct ops to handle interpolated strings.
2596 It stops processing as soon as it finds an embedded $ or @ variable
2597 and leaves it to the caller to work out what's going on.
2599 embedded arrays (whether in pattern or not) could be:
2600 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
2602 $ in double-quoted strings must be the symbol of an embedded scalar.
2604 $ in pattern could be $foo or could be tail anchor. Assumption:
2605 it's a tail anchor if $ is the last thing in the string, or if it's
2606 followed by one of "()| \r\n\t"
2608 \1 (backreferences) are turned into $1
2610 The structure of the code is
2611 while (there's a character to process) {
2612 handle transliteration ranges
2613 skip regexp comments /(?#comment)/ and codes /(?{code})/
2614 skip #-initiated comments in //x patterns
2615 check for embedded arrays
2616 check for embedded scalars
2618 deprecate \1 in substitution replacements
2619 handle string-changing backslashes \l \U \Q \E, etc.
2620 switch (what was escaped) {
2621 handle \- in a transliteration (becomes a literal -)
2622 if a pattern and not \N{, go treat as regular character
2623 handle \132 (octal characters)
2624 handle \x15 and \x{1234} (hex characters)
2625 handle \N{name} (named characters, also \N{3,5} in a pattern)
2626 handle \cV (control characters)
2627 handle printf-style backslashes (\f, \r, \n, etc)
2630 } (end if backslash)
2631 handle regular character
2632 } (end while character to read)
2637 S_scan_const(pTHX_ char *start)
2640 register char *send = PL_bufend; /* end of the constant */
2641 SV *sv = newSV(send - start); /* sv for the constant. See
2642 note below on sizing. */
2643 register char *s = start; /* start of the constant */
2644 register char *d = SvPVX(sv); /* destination for copies */
2645 bool dorange = FALSE; /* are we in a translit range? */
2646 bool didrange = FALSE; /* did we just finish a range? */
2647 bool has_utf8 = FALSE; /* Output constant is UTF8 */
2648 bool this_utf8 = cBOOL(UTF); /* Is the source string assumed
2649 to be UTF8? But, this can
2650 show as true when the source
2651 isn't utf8, as for example
2652 when it is entirely composed
2655 /* Note on sizing: The scanned constant is placed into sv, which is
2656 * initialized by newSV() assuming one byte of output for every byte of
2657 * input. This routine expects newSV() to allocate an extra byte for a
2658 * trailing NUL, which this routine will append if it gets to the end of
2659 * the input. There may be more bytes of input than output (eg., \N{LATIN
2660 * CAPITAL LETTER A}), or more output than input if the constant ends up
2661 * recoded to utf8, but each time a construct is found that might increase
2662 * the needed size, SvGROW() is called. Its size parameter each time is
2663 * based on the best guess estimate at the time, namely the length used so
2664 * far, plus the length the current construct will occupy, plus room for
2665 * the trailing NUL, plus one byte for every input byte still unscanned */
2669 UV literal_endpoint = 0;
2670 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
2673 PERL_ARGS_ASSERT_SCAN_CONST;
2675 assert(PL_lex_inwhat != OP_TRANSR);
2676 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2677 /* If we are doing a trans and we know we want UTF8 set expectation */
2678 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
2679 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2683 while (s < send || dorange) {
2685 /* get transliterations out of the way (they're most literal) */
2686 if (PL_lex_inwhat == OP_TRANS) {
2687 /* expand a range A-Z to the full set of characters. AIE! */
2689 I32 i; /* current expanded character */
2690 I32 min; /* first character in range */
2691 I32 max; /* last character in range */
2702 char * const c = (char*)utf8_hop((U8*)d, -1);
2706 *c = (char)UTF_TO_NATIVE(0xff);
2707 /* mark the range as done, and continue */
2713 i = d - SvPVX_const(sv); /* remember current offset */
2716 SvLEN(sv) + (has_utf8 ?
2717 (512 - UTF_CONTINUATION_MARK +
2720 /* How many two-byte within 0..255: 128 in UTF-8,
2721 * 96 in UTF-8-mod. */
2723 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
2725 d = SvPVX(sv) + i; /* refresh d after realloc */
2729 for (j = 0; j <= 1; j++) {
2730 char * const c = (char*)utf8_hop((U8*)d, -1);
2731 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
2737 max = (U8)0xff; /* only to \xff */
2738 uvmax = uv; /* \x{100} to uvmax */
2740 d = c; /* eat endpoint chars */
2745 d -= 2; /* eat the first char and the - */
2746 min = (U8)*d; /* first char in range */
2747 max = (U8)d[1]; /* last char in range */
2754 "Invalid range \"%c-%c\" in transliteration operator",
2755 (char)min, (char)max);
2759 if (literal_endpoint == 2 &&
2760 ((isLOWER(min) && isLOWER(max)) ||
2761 (isUPPER(min) && isUPPER(max)))) {
2763 for (i = min; i <= max; i++)
2765 *d++ = NATIVE_TO_NEED(has_utf8,i);
2767 for (i = min; i <= max; i++)
2769 *d++ = NATIVE_TO_NEED(has_utf8,i);
2774 for (i = min; i <= max; i++)
2777 const U8 ch = (U8)NATIVE_TO_UTF(i);
2778 if (UNI_IS_INVARIANT(ch))
2781 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
2782 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
2791 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
2793 *d++ = (char)UTF_TO_NATIVE(0xff);
2795 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
2799 /* mark the range as done, and continue */
2803 literal_endpoint = 0;
2808 /* range begins (ignore - as first or last char) */
2809 else if (*s == '-' && s+1 < send && s != start) {
2811 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
2818 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
2828 literal_endpoint = 0;
2829 native_range = TRUE;
2834 /* if we get here, we're not doing a transliteration */
2836 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
2837 except for the last char, which will be done separately. */
2838 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
2840 while (s+1 < send && *s != ')')
2841 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2843 else if (s[2] == '{' /* This should match regcomp.c */
2844 || (s[2] == '?' && s[3] == '{'))
2847 char *regparse = s + (s[2] == '{' ? 3 : 4);
2850 while (count && (c = *regparse)) {
2851 if (c == '\\' && regparse[1])
2859 if (*regparse != ')')
2860 regparse--; /* Leave one char for continuation. */
2861 while (s < regparse)
2862 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2866 /* likewise skip #-initiated comments in //x patterns */
2867 else if (*s == '#' && PL_lex_inpat &&
2868 ((PMOP*)PL_lex_inpat)->op_pmflags & RXf_PMf_EXTENDED) {
2869 while (s+1 < send && *s != '\n')
2870 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2873 /* check for embedded arrays
2874 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
2876 else if (*s == '@' && s[1]) {
2877 if (isALNUM_lazy_if(s+1,UTF))
2879 if (strchr(":'{$", s[1]))
2881 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2882 break; /* in regexp, neither @+ nor @- are interpolated */
2885 /* check for embedded scalars. only stop if we're sure it's a
2888 else if (*s == '$') {
2889 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
2891 if (s + 1 < send && !strchr("()| \r\n\t", s[1])) {
2893 Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
2894 "Possible unintended interpolation of $\\ in regex");
2896 break; /* in regexp, $ might be tail anchor */
2900 /* End of else if chain - OP_TRANS rejoin rest */
2903 if (*s == '\\' && s+1 < send) {
2904 char* e; /* Can be used for ending '}', etc. */
2908 /* warn on \1 - \9 in substitution replacements, but note that \11
2909 * is an octal; and \19 is \1 followed by '9' */
2910 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2911 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2913 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2918 /* string-change backslash escapes */
2919 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2923 /* In a pattern, process \N, but skip any other backslash escapes.
2924 * This is because we don't want to translate an escape sequence
2925 * into a meta symbol and have the regex compiler use the meta
2926 * symbol meaning, e.g. \x{2E} would be confused with a dot. But
2927 * in spite of this, we do have to process \N here while the proper
2928 * charnames handler is in scope. See bugs #56444 and #62056.
2929 * There is a complication because \N in a pattern may also stand
2930 * for 'match a non-nl', and not mean a charname, in which case its
2931 * processing should be deferred to the regex compiler. To be a
2932 * charname it must be followed immediately by a '{', and not look
2933 * like \N followed by a curly quantifier, i.e., not something like
2934 * \N{3,}. regcurly returns a boolean indicating if it is a legal
2936 else if (PL_lex_inpat
2939 || regcurly(s + 1)))
2941 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2942 goto default_action;
2947 /* quoted - in transliterations */
2949 if (PL_lex_inwhat == OP_TRANS) {
2956 if ((isALPHA(*s) || isDIGIT(*s)))
2957 Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
2958 "Unrecognized escape \\%c passed through",
2960 /* default action is to copy the quoted character */
2961 goto default_action;
2964 /* eg. \132 indicates the octal constant 0132 */
2965 case '0': case '1': case '2': case '3':
2966 case '4': case '5': case '6': case '7':
2970 uv = NATIVE_TO_UNI(grok_oct(s, &len, &flags, NULL));
2973 goto NUM_ESCAPE_INSERT;
2975 /* eg. \o{24} indicates the octal constant \024 */
2981 bool valid = grok_bslash_o(s, &uv, &len, &error, 1);
2987 goto NUM_ESCAPE_INSERT;
2990 /* eg. \x24 indicates the hex constant 0x24 */
2994 char* const e = strchr(s, '}');
2995 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2996 PERL_SCAN_DISALLOW_PREFIX;
3001 yyerror("Missing right brace on \\x{}");
3005 uv = NATIVE_TO_UNI(grok_hex(s, &len, &flags, NULL));
3011 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
3012 uv = NATIVE_TO_UNI(grok_hex(s, &len, &flags, NULL));
3018 /* Insert oct or hex escaped character. There will always be
3019 * enough room in sv since such escapes will be longer than any
3020 * UTF-8 sequence they can end up as, except if they force us
3021 * to recode the rest of the string into utf8 */
3023 /* Here uv is the ordinal of the next character being added in
3024 * unicode (converted from native). */
3025 if (!UNI_IS_INVARIANT(uv)) {
3026 if (!has_utf8 && uv > 255) {
3027 /* Might need to recode whatever we have accumulated so
3028 * far if it contains any chars variant in utf8 or
3031 SvCUR_set(sv, d - SvPVX_const(sv));
3034 /* See Note on sizing above. */
3035 sv_utf8_upgrade_flags_grow(sv,
3036 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3037 UNISKIP(uv) + (STRLEN)(send - s) + 1);
3038 d = SvPVX(sv) + SvCUR(sv);
3043 d = (char*)uvuni_to_utf8((U8*)d, uv);
3044 if (PL_lex_inwhat == OP_TRANS &&
3045 PL_sublex_info.sub_op) {
3046 PL_sublex_info.sub_op->op_private |=
3047 (PL_lex_repl ? OPpTRANS_FROM_UTF
3051 if (uv > 255 && !dorange)
3052 native_range = FALSE;
3065 /* In a non-pattern \N must be a named character, like \N{LATIN
3066 * SMALL LETTER A} or \N{U+0041}. For patterns, it also can
3067 * mean to match a non-newline. For non-patterns, named
3068 * characters are converted to their string equivalents. In
3069 * patterns, named characters are not converted to their
3070 * ultimate forms for the same reasons that other escapes
3071 * aren't. Instead, they are converted to the \N{U+...} form
3072 * to get the value from the charnames that is in effect right
3073 * now, while preserving the fact that it was a named character
3074 * so that the regex compiler knows this */
3076 /* This section of code doesn't generally use the
3077 * NATIVE_TO_NEED() macro to transform the input. I (khw) did
3078 * a close examination of this macro and determined it is a
3079 * no-op except on utfebcdic variant characters. Every
3080 * character generated by this that would normally need to be
3081 * enclosed by this macro is invariant, so the macro is not
3082 * needed, and would complicate use of copy(). XXX There are
3083 * other parts of this file where the macro is used
3084 * inconsistently, but are saved by it being a no-op */
3086 /* The structure of this section of code (besides checking for
3087 * errors and upgrading to utf8) is:
3088 * Further disambiguate between the two meanings of \N, and if
3089 * not a charname, go process it elsewhere
3090 * If of form \N{U+...}, pass it through if a pattern;
3091 * otherwise convert to utf8
3092 * Otherwise must be \N{NAME}: convert to \N{U+c1.c2...} if a
3093 * pattern; otherwise convert to utf8 */
3095 /* Here, s points to the 'N'; the test below is guaranteed to
3096 * succeed if we are being called on a pattern as we already
3097 * know from a test above that the next character is a '{'.
3098 * On a non-pattern \N must mean 'named sequence, which
3099 * requires braces */
3102 yyerror("Missing braces on \\N{}");
3107 /* If there is no matching '}', it is an error. */
3108 if (! (e = strchr(s, '}'))) {
3109 if (! PL_lex_inpat) {
3110 yyerror("Missing right brace on \\N{}");
3112 yyerror("Missing right brace on \\N{} or unescaped left brace after \\N.");
3117 /* Here it looks like a named character */
3121 /* XXX This block is temporary code. \N{} implies that the
3122 * pattern is to have Unicode semantics, and therefore
3123 * currently has to be encoded in utf8. By putting it in
3124 * utf8 now, we save a whole pass in the regular expression
3125 * compiler. Once that code is changed so Unicode
3126 * semantics doesn't necessarily have to be in utf8, this
3127 * block should be removed. However, the code that parses
3128 * the output of this would have to be changed to not
3129 * necessarily expect utf8 */
3131 SvCUR_set(sv, d - SvPVX_const(sv));
3134 /* See Note on sizing above. */
3135 sv_utf8_upgrade_flags_grow(sv,
3136 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3137 /* 5 = '\N{' + cur char + NUL */
3138 (STRLEN)(send - s) + 5);
3139 d = SvPVX(sv) + SvCUR(sv);
3144 if (*s == 'U' && s[1] == '+') { /* \N{U+...} */
3145 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES
3146 | PERL_SCAN_DISALLOW_PREFIX;
3149 /* For \N{U+...}, the '...' is a unicode value even on
3150 * EBCDIC machines */
3151 s += 2; /* Skip to next char after the 'U+' */
3153 uv = grok_hex(s, &len, &flags, NULL);
3154 if (len == 0 || len != (STRLEN)(e - s)) {
3155 yyerror("Invalid hexadecimal number in \\N{U+...}");
3162 /* On non-EBCDIC platforms, pass through to the regex
3163 * compiler unchanged. The reason we evaluated the
3164 * number above is to make sure there wasn't a syntax
3165 * error. But on EBCDIC we convert to native so
3166 * downstream code can continue to assume it's native
3168 s -= 5; /* Include the '\N{U+' */
3170 d += my_snprintf(d, e - s + 1 + 1, /* includes the }
3173 (unsigned int) UNI_TO_NATIVE(uv));
3175 Copy(s, d, e - s + 1, char); /* 1 = include the } */
3179 else { /* Not a pattern: convert the hex to string */
3181 /* If destination is not in utf8, unconditionally
3182 * recode it to be so. This is because \N{} implies
3183 * Unicode semantics, and scalars have to be in utf8
3184 * to guarantee those semantics */
3186 SvCUR_set(sv, d - SvPVX_const(sv));
3189 /* See Note on sizing above. */
3190 sv_utf8_upgrade_flags_grow(
3192 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3193 UNISKIP(uv) + (STRLEN)(send - e) + 1);
3194 d = SvPVX(sv) + SvCUR(sv);
3198 /* Add the string to the output */
3199 if (UNI_IS_INVARIANT(uv)) {
3202 else d = (char*)uvuni_to_utf8((U8*)d, uv);
3205 else { /* Here is \N{NAME} but not \N{U+...}. */
3207 SV *res; /* result from charnames */
3208 const char *str; /* the string in 'res' */
3209 STRLEN len; /* its length */
3211 /* Get the value for NAME */
3212 res = newSVpvn(s, e - s);
3213 res = new_constant( NULL, 0, "charnames",
3214 /* includes all of: \N{...} */
3215 res, NULL, s - 3, e - s + 4 );
3217 /* Most likely res will be in utf8 already since the
3218 * standard charnames uses pack U, but a custom translator
3219 * can leave it otherwise, so make sure. XXX This can be
3220 * revisited to not have charnames use utf8 for characters
3221 * that don't need it when regexes don't have to be in utf8
3222 * for Unicode semantics. If doing so, remember EBCDIC */
3223 sv_utf8_upgrade(res);
3224 str = SvPV_const(res, len);
3226 /* Don't accept malformed input */
3227 if (! is_utf8_string((U8 *) str, len)) {
3228 yyerror("Malformed UTF-8 returned by \\N");
3230 else if (PL_lex_inpat) {
3232 if (! len) { /* The name resolved to an empty string */
3233 Copy("\\N{}", d, 4, char);
3237 /* In order to not lose information for the regex
3238 * compiler, pass the result in the specially made
3239 * syntax: \N{U+c1.c2.c3...}, where c1 etc. are
3240 * the code points in hex of each character
3241 * returned by charnames */
3243 const char *str_end = str + len;
3244 STRLEN char_length; /* cur char's byte length */
3245 STRLEN output_length; /* and the number of bytes
3246 after this is translated
3248 const STRLEN off = d - SvPVX_const(sv);
3250 /* 2 hex per byte; 2 chars for '\N'; 2 chars for
3251 * max('U+', '.'); and 1 for NUL */
3252 char hex_string[2 * UTF8_MAXBYTES + 5];
3254 /* Get the first character of the result. */
3255 U32 uv = utf8n_to_uvuni((U8 *) str,
3260 /* The call to is_utf8_string() above hopefully
3261 * guarantees that there won't be an error. But
3262 * it's easy here to make sure. The function just
3263 * above warns and returns 0 if invalid utf8, but
3264 * it can also return 0 if the input is validly a
3265 * NUL. Disambiguate */
3266 if (uv == 0 && NATIVE_TO_ASCII(*str) != '\0') {
3267 uv = UNICODE_REPLACEMENT;
3270 /* Convert first code point to hex, including the
3271 * boiler plate before it. For all these, we
3272 * convert to native format so that downstream code
3273 * can continue to assume the input is native */
3275 my_snprintf(hex_string, sizeof(hex_string),
3277 (unsigned int) UNI_TO_NATIVE(uv));
3279 /* Make sure there is enough space to hold it */
3280 d = off + SvGROW(sv, off
3282 + (STRLEN)(send - e)
3283 + 2); /* '}' + NUL */
3285 Copy(hex_string, d, output_length, char);
3288 /* For each subsequent character, append dot and
3289 * its ordinal in hex */
3290 while ((str += char_length) < str_end) {
3291 const STRLEN off = d - SvPVX_const(sv);
3292 U32 uv = utf8n_to_uvuni((U8 *) str,
3296 if (uv == 0 && NATIVE_TO_ASCII(*str) != '\0') {
3297 uv = UNICODE_REPLACEMENT;
3301 my_snprintf(hex_string, sizeof(hex_string),
3303 (unsigned int) UNI_TO_NATIVE(uv));
3305 d = off + SvGROW(sv, off
3307 + (STRLEN)(send - e)
3308 + 2); /* '}' + NUL */
3309 Copy(hex_string, d, output_length, char);
3313 *d++ = '}'; /* Done. Add the trailing brace */
3316 else { /* Here, not in a pattern. Convert the name to a
3319 /* If destination is not in utf8, unconditionally
3320 * recode it to be so. This is because \N{} implies
3321 * Unicode semantics, and scalars have to be in utf8
3322 * to guarantee those semantics */
3324 SvCUR_set(sv, d - SvPVX_const(sv));
3327 /* See Note on sizing above. */
3328 sv_utf8_upgrade_flags_grow(sv,
3329 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3330 len + (STRLEN)(send - s) + 1);
3331 d = SvPVX(sv) + SvCUR(sv);
3333 } else if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
3335 /* See Note on sizing above. (NOTE: SvCUR() is not
3336 * set correctly here). */
3337 const STRLEN off = d - SvPVX_const(sv);
3338 d = off + SvGROW(sv, off + len + (STRLEN)(send - s) + 1);
3340 Copy(str, d, len, char);
3345 /* Deprecate non-approved name syntax */
3346 if (ckWARN_d(WARN_DEPRECATED)) {
3347 bool problematic = FALSE;
3350 /* For non-ut8 input, look to see that the first
3351 * character is an alpha, then loop through the rest
3352 * checking that each is a continuation */
3354 if (! isALPHAU(*i)) problematic = TRUE;
3355 else for (i = s + 1; i < e; i++) {
3356 if (isCHARNAME_CONT(*i)) continue;
3362 /* Similarly for utf8. For invariants can check
3363 * directly. We accept anything above the latin1
3364 * range because it is immaterial to Perl if it is
3365 * correct or not, and is expensive to check. But
3366 * it is fairly easy in the latin1 range to convert
3367 * the variants into a single character and check
3369 if (UTF8_IS_INVARIANT(*i)) {
3370 if (! isALPHAU(*i)) problematic = TRUE;
3371 } else if (UTF8_IS_DOWNGRADEABLE_START(*i)) {
3372 if (! isALPHAU(UNI_TO_NATIVE(TWO_BYTE_UTF8_TO_UNI(*i,
3378 if (! problematic) for (i = s + UTF8SKIP(s);
3382 if (UTF8_IS_INVARIANT(*i)) {
3383 if (isCHARNAME_CONT(*i)) continue;
3384 } else if (! UTF8_IS_DOWNGRADEABLE_START(*i)) {
3386 } else if (isCHARNAME_CONT(
3388 TWO_BYTE_UTF8_TO_UNI(*i, *(i+1)))))
3397 /* The e-i passed to the final %.*s makes sure that
3398 * should the trailing NUL be missing that this
3399 * print won't run off the end of the string */
3400 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
3401 "Deprecated character in \\N{...}; marked by <-- HERE in \\N{%.*s<-- HERE %.*s",
3402 (int)(i - s + 1), s, (int)(e - i), i + 1);
3405 } /* End \N{NAME} */
3408 native_range = FALSE; /* \N{} is defined to be Unicode */
3410 s = e + 1; /* Point to just after the '}' */
3413 /* \c is a control character */
3417 *d++ = grok_bslash_c(*s++, has_utf8, 1);
3420 yyerror("Missing control char name in \\c");
3424 /* printf-style backslashes, formfeeds, newlines, etc */
3426 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
3429 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
3432 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
3435 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
3438 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
3441 *d++ = ASCII_TO_NEED(has_utf8,'\033');
3444 *d++ = ASCII_TO_NEED(has_utf8,'\007');
3450 } /* end if (backslash) */
3457 /* If we started with encoded form, or already know we want it,
3458 then encode the next character */
3459 if (! NATIVE_IS_INVARIANT((U8)(*s)) && (this_utf8 || has_utf8)) {
3463 /* One might think that it is wasted effort in the case of the
3464 * source being utf8 (this_utf8 == TRUE) to take the next character
3465 * in the source, convert it to an unsigned value, and then convert
3466 * it back again. But the source has not been validated here. The
3467 * routine that does the conversion checks for errors like
3470 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
3471 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
3473 SvCUR_set(sv, d - SvPVX_const(sv));
3476 /* See Note on sizing above. */
3477 sv_utf8_upgrade_flags_grow(sv,
3478 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3479 need + (STRLEN)(send - s) + 1);
3480 d = SvPVX(sv) + SvCUR(sv);
3482 } else if (need > len) {
3483 /* encoded value larger than old, may need extra space (NOTE:
3484 * SvCUR() is not set correctly here). See Note on sizing
3486 const STRLEN off = d - SvPVX_const(sv);
3487 d = SvGROW(sv, off + need + (STRLEN)(send - s) + 1) + off;
3491 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
3493 if (uv > 255 && !dorange)
3494 native_range = FALSE;
3498 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
3500 } /* while loop to process each character */
3502 /* terminate the string and set up the sv */
3504 SvCUR_set(sv, d - SvPVX_const(sv));
3505 if (SvCUR(sv) >= SvLEN(sv))
3506 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
3509 if (PL_encoding && !has_utf8) {
3510 sv_recode_to_utf8(sv, PL_encoding);
3516 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
3517 PL_sublex_info.sub_op->op_private |=
3518 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
3522 /* shrink the sv if we allocated more than we used */
3523 if (SvCUR(sv) + 5 < SvLEN(sv)) {
3524 SvPV_shrink_to_cur(sv);
3527 /* return the substring (via pl_yylval) only if we parsed anything */
3528 if (s > PL_bufptr) {
3529 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) {
3530 const char *const key = PL_lex_inpat ? "qr" : "q";
3531 const STRLEN keylen = PL_lex_inpat ? 2 : 1;
3535 if (PL_lex_inwhat == OP_TRANS) {
3538 } else if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) {
3546 sv = S_new_constant(aTHX_ start, s - start, key, keylen, sv, NULL,
3549 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3556 * Returns TRUE if there's more to the expression (e.g., a subscript),
3559 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
3561 * ->[ and ->{ return TRUE
3562 * { and [ outside a pattern are always subscripts, so return TRUE
3563 * if we're outside a pattern and it's not { or [, then return FALSE
3564 * if we're in a pattern and the first char is a {
3565 * {4,5} (any digits around the comma) returns FALSE
3566 * if we're in a pattern and the first char is a [
3568 * [SOMETHING] has a funky algorithm to decide whether it's a
3569 * character class or not. It has to deal with things like
3570 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
3571 * anything else returns TRUE
3574 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
3577 S_intuit_more(pTHX_ register char *s)
3581 PERL_ARGS_ASSERT_INTUIT_MORE;
3583 if (PL_lex_brackets)
3585 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
3587 if (*s != '{' && *s != '[')
3592 /* In a pattern, so maybe we have {n,m}. */
3600 /* On the other hand, maybe we have a character class */
3603 if (*s == ']' || *s == '^')
3606 /* this is terrifying, and it works */
3607 int weight = 2; /* let's weigh the evidence */
3609 unsigned char un_char = 255, last_un_char;
3610 const char * const send = strchr(s,']');
3611 char tmpbuf[sizeof PL_tokenbuf * 4];
3613 if (!send) /* has to be an expression */
3616 Zero(seen,256,char);
3619 else if (isDIGIT(*s)) {
3621 if (isDIGIT(s[1]) && s[2] == ']')
3627 for (; s < send; s++) {
3628 last_un_char = un_char;
3629 un_char = (unsigned char)*s;
3634 weight -= seen[un_char] * 10;
3635 if (isALNUM_lazy_if(s+1,UTF)) {
3637 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
3638 len = (int)strlen(tmpbuf);
3639 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len,
3640 UTF ? SVf_UTF8 : 0, SVt_PV))
3645 else if (*s == '$' && s[1] &&
3646 strchr("[#!%*<>()-=",s[1])) {
3647 if (/*{*/ strchr("])} =",s[2]))
3656 if (strchr("wds]",s[1]))
3658 else if (seen[(U8)'\''] || seen[(U8)'"'])
3660 else if (strchr("rnftbxcav",s[1]))
3662 else if (isDIGIT(s[1])) {
3664 while (s[1] && isDIGIT(s[1]))
3674 if (strchr("aA01! ",last_un_char))
3676 if (strchr("zZ79~",s[1]))
3678 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
3679 weight -= 5; /* cope with negative subscript */
3682 if (!isALNUM(last_un_char)
3683 && !(last_un_char == '$' || last_un_char == '@'
3684 || last_un_char == '&')
3685 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
3690 if (keyword(tmpbuf, d - tmpbuf, 0))
3693 if (un_char == last_un_char + 1)
3695 weight -= seen[un_char];
3700 if (weight >= 0) /* probably a character class */
3710 * Does all the checking to disambiguate
3712 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
3713 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
3715 * First argument is the stuff after the first token, e.g. "bar".
3717 * Not a method if bar is a filehandle.
3718 * Not a method if foo is a subroutine prototyped to take a filehandle.
3719 * Not a method if it's really "Foo $bar"
3720 * Method if it's "foo $bar"
3721 * Not a method if it's really "print foo $bar"
3722 * Method if it's really "foo package::" (interpreted as package->foo)
3723 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
3724 * Not a method if bar is a filehandle or package, but is quoted with
3729 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
3732 char *s = start + (*start == '$');
3733 char tmpbuf[sizeof PL_tokenbuf];
3740 PERL_ARGS_ASSERT_INTUIT_METHOD;
3743 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
3747 const char *proto = CvPROTO(cv);
3758 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3759 /* start is the beginning of the possible filehandle/object,
3760 * and s is the end of it
3761 * tmpbuf is a copy of it
3764 if (*start == '$') {
3765 if (gv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY ||
3766 isUPPER(*PL_tokenbuf))
3769 len = start - SvPVX(PL_linestr);
3773 start = SvPVX(PL_linestr) + len;
3777 return *s == '(' ? FUNCMETH : METHOD;
3779 if (!keyword(tmpbuf, len, 0)) {
3780 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
3784 soff = s - SvPVX(PL_linestr);
3788 indirgv = gv_fetchpvn_flags(tmpbuf, len, ( UTF ? SVf_UTF8 : 0 ), SVt_PVCV);
3789 if (indirgv && GvCVu(indirgv))
3791 /* filehandle or package name makes it a method */
3792 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, UTF ? SVf_UTF8 : 0)) {
3794 soff = s - SvPVX(PL_linestr);
3797 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
3798 return 0; /* no assumptions -- "=>" quotes bareword */
3800 start_force(PL_curforce);
3801 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
3802 S_newSV_maybe_utf8(aTHX_ tmpbuf, len));
3803 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
3805 curmad('X', newSVpvn_flags(start,SvPVX(PL_linestr) + soff - start,
3806 ( UTF ? SVf_UTF8 : 0 )));
3811 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
3813 return *s == '(' ? FUNCMETH : METHOD;
3819 /* Encoded script support. filter_add() effectively inserts a
3820 * 'pre-processing' function into the current source input stream.
3821 * Note that the filter function only applies to the current source file
3822 * (e.g., it will not affect files 'require'd or 'use'd by this one).
3824 * The datasv parameter (which may be NULL) can be used to pass
3825 * private data to this instance of the filter. The filter function
3826 * can recover the SV using the FILTER_DATA macro and use it to
3827 * store private buffers and state information.
3829 * The supplied datasv parameter is upgraded to a PVIO type
3830 * and the IoDIRP/IoANY field is used to store the function pointer,
3831 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
3832 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
3833 * private use must be set using malloc'd pointers.
3837 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
3846 if (PL_parser->lex_flags & LEX_IGNORE_UTF8_HINTS)
3847 Perl_croak(aTHX_ "Source filters apply only to byte streams");
3849 if (!PL_rsfp_filters)
3850 PL_rsfp_filters = newAV();
3853 SvUPGRADE(datasv, SVt_PVIO);
3854 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
3855 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
3856 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
3857 FPTR2DPTR(void *, IoANY(datasv)),
3858 SvPV_nolen(datasv)));
3859 av_unshift(PL_rsfp_filters, 1);
3860 av_store(PL_rsfp_filters, 0, datasv) ;
3862 !PL_parser->filtered
3863 && PL_parser->lex_flags & LEX_EVALBYTES
3864 && PL_bufptr < PL_bufend
3866 const char *s = PL_bufptr;
3867 while (s < PL_bufend) {
3869 SV *linestr = PL_parser->linestr;
3870 char *buf = SvPVX(linestr);
3871 STRLEN const bufptr_pos = PL_parser->bufptr - buf;
3872 STRLEN const oldbufptr_pos = PL_parser->oldbufptr - buf;
3873 STRLEN const oldoldbufptr_pos=PL_parser->oldoldbufptr-buf;
3874 STRLEN const linestart_pos = PL_parser->linestart - buf;
3875 STRLEN const last_uni_pos =
3876 PL_parser->last_uni ? PL_parser->last_uni - buf : 0;
3877 STRLEN const last_lop_pos =
3878 PL_parser->last_lop ? PL_parser->last_lop - buf : 0;
3879 av_push(PL_rsfp_filters, linestr);
3880 PL_parser->linestr =
3881 newSVpvn(SvPVX(linestr), ++s-SvPVX(linestr));
3882 buf = SvPVX(PL_parser->linestr);
3883 PL_parser->bufend = buf + SvCUR(PL_parser->linestr);
3884 PL_parser->bufptr = buf + bufptr_pos;
3885 PL_parser->oldbufptr = buf + oldbufptr_pos;
3886 PL_parser->oldoldbufptr = buf + oldoldbufptr_pos;
3887 PL_parser->linestart = buf + linestart_pos;
3888 if (PL_parser->last_uni)
3889 PL_parser->last_uni = buf + last_uni_pos;
3890 if (PL_parser->last_lop)
3891 PL_parser->last_lop = buf + last_lop_pos;
3892 SvLEN(linestr) = SvCUR(linestr);
3893 SvCUR(linestr) = s-SvPVX(linestr);
3894 PL_parser->filtered = 1;
3904 /* Delete most recently added instance of this filter function. */
3906 Perl_filter_del(pTHX_ filter_t funcp)
3911 PERL_ARGS_ASSERT_FILTER_DEL;
3914 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
3915 FPTR2DPTR(void*, funcp)));
3917 if (!PL_parser || !PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
3919 /* if filter is on top of stack (usual case) just pop it off */
3920 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
3921 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
3922 sv_free(av_pop(PL_rsfp_filters));
3926 /* we need to search for the correct entry and clear it */
3927 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
3931 /* Invoke the idxth filter function for the current rsfp. */
3932 /* maxlen 0 = read one text line */
3934 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
3939 /* This API is bad. It should have been using unsigned int for maxlen.
3940 Not sure if we want to change the API, but if not we should sanity
3941 check the value here. */
3942 unsigned int correct_length
3951 PERL_ARGS_ASSERT_FILTER_READ;
3953 if (!PL_parser || !PL_rsfp_filters)
3955 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
3956 /* Provide a default input filter to make life easy. */
3957 /* Note that we append to the line. This is handy. */
3958 DEBUG_P(PerlIO_printf(Perl_debug_log,
3959 "filter_read %d: from rsfp\n", idx));
3960 if (correct_length) {
3963 const int old_len = SvCUR(buf_sv);
3965 /* ensure buf_sv is large enough */
3966 SvGROW(buf_sv, (STRLEN)(old_len + correct_length + 1)) ;
3967 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
3968 correct_length)) <= 0) {
3969 if (PerlIO_error(PL_rsfp))
3970 return -1; /* error */
3972 return 0 ; /* end of file */
3974 SvCUR_set(buf_sv, old_len + len) ;
3975 SvPVX(buf_sv)[old_len + len] = '\0';
3978 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
3979 if (PerlIO_error(PL_rsfp))
3980 return -1; /* error */
3982 return 0 ; /* end of file */
3985 return SvCUR(buf_sv);
3987 /* Skip this filter slot if filter has been deleted */
3988 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
3989 DEBUG_P(PerlIO_printf(Perl_debug_log,
3990 "filter_read %d: skipped (filter deleted)\n",
3992 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
3994 if (SvTYPE(datasv) != SVt_PVIO) {
3995 if (correct_length) {
3997 const STRLEN remainder = SvLEN(datasv) - SvCUR(datasv);
3998 if (!remainder) return 0; /* eof */
3999 if (correct_length > remainder) correct_length = remainder;
4000 sv_catpvn(buf_sv, SvEND(datasv), correct_length);
4001 SvCUR_set(datasv, SvCUR(datasv) + correct_length);
4004 const char *s = SvEND(datasv);
4005 const char *send = SvPVX(datasv) + SvLEN(datasv);
4013 if (s == send) return 0; /* eof */
4014 sv_catpvn(buf_sv, SvEND(datasv), s-SvEND(datasv));
4015 SvCUR_set(datasv, s-SvPVX(datasv));
4017 return SvCUR(buf_sv);
4019 /* Get function pointer hidden within datasv */
4020 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
4021 DEBUG_P(PerlIO_printf(Perl_debug_log,
4022 "filter_read %d: via function %p (%s)\n",
4023 idx, (void*)datasv, SvPV_nolen_const(datasv)));
4024 /* Call function. The function is expected to */
4025 /* call "FILTER_READ(idx+1, buf_sv)" first. */
4026 /* Return: <0:error, =0:eof, >0:not eof */
4027 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
4031 S_filter_gets(pTHX_ register SV *sv, STRLEN append)
4035 PERL_ARGS_ASSERT_FILTER_GETS;
4037 #ifdef PERL_CR_FILTER
4038 if (!PL_rsfp_filters) {
4039 filter_add(S_cr_textfilter,NULL);
4042 if (PL_rsfp_filters) {
4044 SvCUR_set(sv, 0); /* start with empty line */
4045 if (FILTER_READ(0, sv, 0) > 0)
4046 return ( SvPVX(sv) ) ;
4051 return (sv_gets(sv, PL_rsfp, append));
4055 S_find_in_my_stash(pTHX_ const char *pkgname, STRLEN len)
4060 PERL_ARGS_ASSERT_FIND_IN_MY_STASH;
4062 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
4066 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
4067 (gv = gv_fetchpvn_flags(pkgname, len, ( UTF ? SVf_UTF8 : 0 ), SVt_PVHV)))
4069 return GvHV(gv); /* Foo:: */
4072 /* use constant CLASS => 'MyClass' */
4073 gv = gv_fetchpvn_flags(pkgname, len, UTF ? SVf_UTF8 : 0, SVt_PVCV);
4074 if (gv && GvCV(gv)) {
4075 SV * const sv = cv_const_sv(GvCV(gv));
4077 pkgname = SvPV_const(sv, len);
4080 return gv_stashpvn(pkgname, len, UTF ? SVf_UTF8 : 0);
4084 * S_readpipe_override
4085 * Check whether readpipe() is overridden, and generates the appropriate
4086 * optree, provided sublex_start() is called afterwards.
4089 S_readpipe_override(pTHX)
4092 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
4093 pl_yylval.ival = OP_BACKTICK;
4095 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
4097 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
4098 && (gv_readpipe = *gvp) && isGV_with_GP(gv_readpipe)
4099 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
4101 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
4102 op_append_elem(OP_LIST,
4103 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
4104 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
4111 * The intent of this yylex wrapper is to minimize the changes to the
4112 * tokener when we aren't interested in collecting madprops. It remains
4113 * to be seen how successful this strategy will be...
4120 char *s = PL_bufptr;
4122 /* make sure PL_thiswhite is initialized */
4126 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
4127 if (PL_lex_state != LEX_KNOWNEXT && PL_pending_ident)
4128 return S_pending_ident(aTHX);
4130 /* previous token ate up our whitespace? */
4131 if (!PL_lasttoke && PL_nextwhite) {
4132 PL_thiswhite = PL_nextwhite;
4136 /* isolate the token, and figure out where it is without whitespace */
4137 PL_realtokenstart = -1;
4141 assert(PL_curforce < 0);
4143 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
4144 if (!PL_thistoken) {
4145 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
4146 PL_thistoken = newSVpvs("");
4148 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
4149 PL_thistoken = newSVpvn(tstart, s - tstart);
4152 if (PL_thismad) /* install head */
4153 CURMAD('X', PL_thistoken);
4156 /* last whitespace of a sublex? */
4157 if (optype == ')' && PL_endwhite) {
4158 CURMAD('X', PL_endwhite);
4163 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
4164 if (!PL_thiswhite && !PL_endwhite && !optype) {
4165 sv_free(PL_thistoken);
4170 /* put off final whitespace till peg */
4171 if (optype == ';' && !PL_rsfp && !PL_parser->filtered) {
4172 PL_nextwhite = PL_thiswhite;
4175 else if (PL_thisopen) {
4176 CURMAD('q', PL_thisopen);
4178 sv_free(PL_thistoken);
4182 /* Store actual token text as madprop X */
4183 CURMAD('X', PL_thistoken);
4187 /* add preceding whitespace as madprop _ */
4188 CURMAD('_', PL_thiswhite);
4192 /* add quoted material as madprop = */
4193 CURMAD('=', PL_thisstuff);
4197 /* add terminating quote as madprop Q */
4198 CURMAD('Q', PL_thisclose);
4202 /* special processing based on optype */
4206 /* opval doesn't need a TOKEN since it can already store mp */
4216 if (pl_yylval.opval)
4217 append_madprops(PL_thismad, pl_yylval.opval, 0);
4225 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
4234 /* remember any fake bracket that lexer is about to discard */
4235 if (PL_lex_brackets == 1 &&
4236 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
4239 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
4242 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
4243 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
4246 break; /* don't bother looking for trailing comment */
4255 /* attach a trailing comment to its statement instead of next token */
4259 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
4261 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
4263 if (*s == '\n' || *s == '#') {
4264 while (s < PL_bufend && *s != '\n')
4268 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
4269 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
4286 /* Create new token struct. Note: opvals return early above. */
4287 pl_yylval.tkval = newTOKEN(optype, pl_yylval, PL_thismad);
4294 S_tokenize_use(pTHX_ int is_use, char *s) {
4297 PERL_ARGS_ASSERT_TOKENIZE_USE;
4299 if (PL_expect != XSTATE)
4300 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
4301 is_use ? "use" : "no"));
4303 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
4304 s = force_version(s, TRUE);
4305 if (*s == ';' || *s == '}'
4306 || (s = SKIPSPACE1(s), (*s == ';' || *s == '}'))) {
4307 start_force(PL_curforce);
4308 NEXTVAL_NEXTTOKE.opval = NULL;
4311 else if (*s == 'v') {
4312 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4313 s = force_version(s, FALSE);
4317 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4318 s = force_version(s, FALSE);
4320 pl_yylval.ival = is_use;
4324 static const char* const exp_name[] =
4325 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
4326 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
4330 #define word_takes_any_delimeter(p,l) S_word_takes_any_delimeter(p,l)
4332 S_word_takes_any_delimeter(char *p, STRLEN len)
4334 return (len == 1 && strchr("msyq", p[0])) ||
4336 (p[0] == 't' && p[1] == 'r') ||
4337 (p[0] == 'q' && strchr("qwxr", p[1]))));
4343 Works out what to call the token just pulled out of the input
4344 stream. The yacc parser takes care of taking the ops we return and
4345 stitching them into a tree.
4351 if read an identifier
4352 if we're in a my declaration
4353 croak if they tried to say my($foo::bar)
4354 build the ops for a my() declaration
4355 if it's an access to a my() variable
4356 are we in a sort block?
4357 croak if my($a); $a <=> $b
4358 build ops for access to a my() variable
4359 if in a dq string, and they've said @foo and we can't find @foo
4361 build ops for a bareword
4362 if we already built the token before, use it.
4367 #pragma segment Perl_yylex
4373 register char *s = PL_bufptr;
4379 /* orig_keyword, gvp, and gv are initialized here because
4380 * jump to the label just_a_word_zero can bypass their
4381 * initialization later. */
4382 I32 orig_keyword = 0;
4387 SV* tmp = newSVpvs("");
4388 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
4389 (IV)CopLINE(PL_curcop),
4390 lex_state_names[PL_lex_state],
4391 exp_name[PL_expect],
4392 pv_display(tmp, s, strlen(s), 0, 60));
4395 /* check if there's an identifier for us to look at */
4396 if (PL_lex_state != LEX_KNOWNEXT && PL_pending_ident)
4397 return REPORT(S_pending_ident(aTHX));
4399 /* no identifier pending identification */
4401 switch (PL_lex_state) {
4403 case LEX_NORMAL: /* Some compilers will produce faster */
4404 case LEX_INTERPNORMAL: /* code if we comment these out. */
4408 /* when we've already built the next token, just pull it out of the queue */
4412 pl_yylval = PL_nexttoke[PL_lasttoke].next_val;
4414 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
4415 PL_nexttoke[PL_lasttoke].next_mad = 0;
4416 if (PL_thismad && PL_thismad->mad_key == '_') {
4417 PL_thiswhite = MUTABLE_SV(PL_thismad->mad_val);
4418 PL_thismad->mad_val = 0;
4419 mad_free(PL_thismad);
4424 PL_lex_state = PL_lex_defer;
4425 PL_expect = PL_lex_expect;
4426 PL_lex_defer = LEX_NORMAL;
4427 if (!PL_nexttoke[PL_lasttoke].next_type)
4432 pl_yylval = PL_nextval[PL_nexttoke];
4434 PL_lex_state = PL_lex_defer;
4435 PL_expect = PL_lex_expect;
4436 PL_lex_defer = LEX_NORMAL;
4442 next_type = PL_nexttoke[PL_lasttoke].next_type;
4444 next_type = PL_nexttype[PL_nexttoke];
4446 if (next_type & (7<<24)) {
4447 if (next_type & (1<<24)) {
4448 if (PL_lex_brackets > 100)
4449 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4450 PL_lex_brackstack[PL_lex_brackets++] =
4451 (char) ((next_type >> 16) & 0xff);
4453 if (next_type & (2<<24))
4454 PL_lex_allbrackets++;
4455 if (next_type & (4<<24))
4456 PL_lex_allbrackets--;
4457 next_type &= 0xffff;
4460 /* FIXME - can these be merged? */
4463 return REPORT(next_type);
4467 /* interpolated case modifiers like \L \U, including \Q and \E.
4468 when we get here, PL_bufptr is at the \
4470 case LEX_INTERPCASEMOD:
4472 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
4473 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
4475 /* handle \E or end of string */
4476 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
4478 if (PL_lex_casemods) {
4479 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
4480 PL_lex_casestack[PL_lex_casemods] = '\0';
4482 if (PL_bufptr != PL_bufend
4483 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
4485 PL_lex_state = LEX_INTERPCONCAT;
4488 PL_thistoken = newSVpvs("\\E");
4491 PL_lex_allbrackets--;
4495 while (PL_bufptr != PL_bufend &&
4496 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
4498 PL_thiswhite = newSVpvs("");
4499 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
4503 if (PL_bufptr != PL_bufend)
4506 PL_lex_state = LEX_INTERPCONCAT;
4510 DEBUG_T({ PerlIO_printf(Perl_debug_log,
4511 "### Saw case modifier\n"); });
4513 if (s[1] == '\\' && s[2] == 'E') {
4516 PL_thiswhite = newSVpvs("");
4517 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
4520 PL_lex_state = LEX_INTERPCONCAT;
4525 if (!PL_madskills) /* when just compiling don't need correct */
4526 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
4527 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
4528 if ((*s == 'L' || *s == 'U') &&
4529 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
4530 PL_lex_casestack[--PL_lex_casemods] = '\0';
4531 PL_lex_allbrackets--;
4534 if (PL_lex_casemods > 10)
4535 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
4536 PL_lex_casestack[PL_lex_casemods++] = *s;
4537 PL_lex_casestack[PL_lex_casemods] = '\0';
4538 PL_lex_state = LEX_INTERPCONCAT;
4539 start_force(PL_curforce);
4540 NEXTVAL_NEXTTOKE.ival = 0;
4541 force_next((2<<24)|'(');
4542 start_force(PL_curforce);
4544 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
4546 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
4548 NEXTVAL_NEXTTOKE.ival = OP_LC;
4550 NEXTVAL_NEXTTOKE.ival = OP_UC;
4552 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
4554 Perl_croak(aTHX_ "panic: yylex");
4556 SV* const tmpsv = newSVpvs("\\ ");
4557 /* replace the space with the character we want to escape
4559 SvPVX(tmpsv)[1] = *s;
4565 if (PL_lex_starts) {
4571 sv_free(PL_thistoken);
4572 PL_thistoken = newSVpvs("");
4575 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
4576 if (PL_lex_casemods == 1 && PL_lex_inpat)
4585 case LEX_INTERPPUSH:
4586 return REPORT(sublex_push());
4588 case LEX_INTERPSTART:
4589 if (PL_bufptr == PL_bufend)
4590 return REPORT(sublex_done());
4591 DEBUG_T({ PerlIO_printf(Perl_debug_log,
4592 "### Interpolated variable\n"); });
4594 PL_lex_dojoin = (*PL_bufptr == '@');
4595 PL_lex_state = LEX_INTERPNORMAL;
4596 if (PL_lex_dojoin) {
4597 start_force(PL_curforce);
4598 NEXTVAL_NEXTTOKE.ival = 0;
4600 start_force(PL_curforce);
4601 force_ident("\"", '$');
4602 start_force(PL_curforce);
4603 NEXTVAL_NEXTTOKE.ival = 0;
4605 start_force(PL_curforce);
4606 NEXTVAL_NEXTTOKE.ival = 0;
4607 force_next((2<<24)|'(');
4608 start_force(PL_curforce);
4609 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
4612 if (PL_lex_starts++) {
4617 sv_free(PL_thistoken);
4618 PL_thistoken = newSVpvs("");
4621 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
4622 if (!PL_lex_casemods && PL_lex_inpat)
4629 case LEX_INTERPENDMAYBE:
4630 if (intuit_more(PL_bufptr)) {
4631 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
4637 if (PL_lex_dojoin) {
4638 PL_lex_dojoin = FALSE;
4639 PL_lex_state = LEX_INTERPCONCAT;
4643 sv_free(PL_thistoken);
4644 PL_thistoken = newSVpvs("");
4647 PL_lex_allbrackets--;
4650 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
4651 && SvEVALED(PL_lex_repl))
4653 if (PL_bufptr != PL_bufend)
4654 Perl_croak(aTHX_ "Bad evalled substitution pattern");
4658 case LEX_INTERPCONCAT:
4660 if (PL_lex_brackets)
4661 Perl_croak(aTHX_ "panic: INTERPCONCAT");
4663 if (PL_bufptr == PL_bufend)
4664 return REPORT(sublex_done());
4666 if (SvIVX(PL_linestr) == '\'') {
4667 SV *sv = newSVsv(PL_linestr);
4670 else if ( PL_hints & HINT_NEW_RE )
4671 sv = new_constant(NULL, 0, "qr", sv, sv, "q", 1);
4672 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
4676 s = scan_const(PL_bufptr);
4678 PL_lex_state = LEX_INTERPCASEMOD;
4680 PL_lex_state = LEX_INTERPSTART;
4683 if (s != PL_bufptr) {
4684 start_force(PL_curforce);
4686 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
4688 NEXTVAL_NEXTTOKE = pl_yylval;
4691 if (PL_lex_starts++) {
4695 sv_free(PL_thistoken);
4696 PL_thistoken = newSVpvs("");
4699 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
4700 if (!PL_lex_casemods && PL_lex_inpat)
4713 PL_lex_state = LEX_NORMAL;
4714 s = scan_formline(PL_bufptr);
4715 if (!PL_lex_formbrack)
4721 PL_oldoldbufptr = PL_oldbufptr;
4727 sv_free(PL_thistoken);
4730 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
4734 if (isIDFIRST_lazy_if(s,UTF))
4737 unsigned char c = *s;
4738 len = UTF ? Perl_utf8_length(aTHX_ (U8 *) PL_linestart, (U8 *) s) : (STRLEN) (s - PL_linestart);
4739 if (len > UNRECOGNIZED_PRECEDE_COUNT) {
4740 d = UTF ? (char *) Perl_utf8_hop(aTHX_ (U8 *) s, -UNRECOGNIZED_PRECEDE_COUNT) : s - UNRECOGNIZED_PRECEDE_COUNT;
4745 Perl_croak(aTHX_ "Unrecognized character \\x%02X; marked by <-- HERE after %s<-- HERE near column %d", c, d, (int) len + 1);
4749 goto fake_eof; /* emulate EOF on ^D or ^Z */
4755 if (!PL_rsfp && (!PL_parser->filtered || s+1 < PL_bufend)) {
4758 if (PL_lex_brackets &&
4759 PL_lex_brackstack[PL_lex_brackets-1] != XFAKEEOF) {
4760 yyerror((const char *)
4762 ? "Format not terminated"
4763 : "Missing right curly or square bracket"));
4765 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4766 "### Tokener got EOF\n");
4770 if (s++ < PL_bufend)
4771 goto retry; /* ignore stray nulls */
4774 if (!PL_in_eval && !PL_preambled) {
4775 PL_preambled = TRUE;
4781 /* Generate a string of Perl code to load the debugger.
4782 * If PERL5DB is set, it will return the contents of that,
4783 * otherwise a compile-time require of perl5db.pl. */
4785 const char * const pdb = PerlEnv_getenv("PERL5DB");
4788 sv_setpv(PL_linestr, pdb);
4789 sv_catpvs(PL_linestr,";");
4791 SETERRNO(0,SS_NORMAL);
4792 sv_setpvs(PL_linestr, "BEGIN { require 'perl5db.pl' };");
4795 sv_setpvs(PL_linestr,"");
4796 if (PL_preambleav) {
4797 SV **svp = AvARRAY(PL_preambleav);
4798 SV **const end = svp + AvFILLp(PL_preambleav);
4800 sv_catsv(PL_linestr, *svp);
4802 sv_catpvs(PL_linestr, ";");
4804 sv_free(MUTABLE_SV(PL_preambleav));
4805 PL_preambleav = NULL;
4808 sv_catpvs(PL_linestr,
4809 "use feature ':5." STRINGIFY(PERL_VERSION) "';");
4810 if (PL_minus_n || PL_minus_p) {
4811 sv_catpvs(PL_linestr, "LINE: while (<>) {"/*}*/);
4813 sv_catpvs(PL_linestr,"chomp;");
4816 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
4817 || *PL_splitstr == '"')
4818 && strchr(PL_splitstr + 1, *PL_splitstr))
4819 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
4821 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
4822 bytes can be used as quoting characters. :-) */
4823 const char *splits = PL_splitstr;
4824 sv_catpvs(PL_linestr, "our @F=split(q\0");
4827 if (*splits == '\\')
4828 sv_catpvn(PL_linestr, splits, 1);
4829 sv_catpvn(PL_linestr, splits, 1);
4830 } while (*splits++);
4831 /* This loop will embed the trailing NUL of
4832 PL_linestr as the last thing it does before
4834 sv_catpvs(PL_linestr, ");");
4838 sv_catpvs(PL_linestr,"our @F=split(' ');");
4841 sv_catpvs(PL_linestr, "\n");
4842 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4843 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4844 PL_last_lop = PL_last_uni = NULL;
4845 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
4846 update_debugger_info(PL_linestr, NULL, 0);
4851 bof = PL_rsfp ? TRUE : FALSE;
4854 fake_eof = LEX_FAKE_EOF;
4856 PL_bufptr = PL_bufend;
4857 CopLINE_inc(PL_curcop);
4858 if (!lex_next_chunk(fake_eof)) {
4859 CopLINE_dec(PL_curcop);
4861 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
4863 CopLINE_dec(PL_curcop);
4866 PL_realtokenstart = -1;
4869 /* If it looks like the start of a BOM or raw UTF-16,
4870 * check if it in fact is. */
4871 if (bof && PL_rsfp &&
4876 Off_t offset = (IV)PerlIO_tell(PL_rsfp);
4877 bof = (offset == (Off_t)SvCUR(PL_linestr));
4878 #if defined(PERLIO_USING_CRLF) && defined(PERL_TEXTMODE_SCRIPTS)
4879 /* offset may include swallowed CR */
4881 bof = (offset == (Off_t)SvCUR(PL_linestr)+1);
4884 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4885 s = swallow_bom((U8*)s);
4888 if (PL_parser->in_pod) {
4889 /* Incest with pod. */
4892 sv_catsv(PL_thiswhite, PL_linestr);
4894 if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) {
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_parser->in_pod = 0;
4902 if (PL_rsfp || PL_parser->filtered)
4904 } while (PL_parser->in_pod);
4905 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
4906 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4907 PL_last_lop = PL_last_uni = NULL;
4908 if (CopLINE(PL_curcop) == 1) {
4909 while (s < PL_bufend && isSPACE(*s))
4911 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
4915 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
4919 if (*s == '#' && *(s+1) == '!')
4921 #ifdef ALTERNATE_SHEBANG
4923 static char const as[] = ALTERNATE_SHEBANG;
4924 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
4925 d = s + (sizeof(as) - 1);
4927 #endif /* ALTERNATE_SHEBANG */
4936 while (*d && !isSPACE(*d))
4940 #ifdef ARG_ZERO_IS_SCRIPT
4941 if (ipathend > ipath) {
4943 * HP-UX (at least) sets argv[0] to the script name,
4944 * which makes $^X incorrect. And Digital UNIX and Linux,
4945 * at least, set argv[0] to the basename of the Perl
4946 * interpreter. So, having found "#!", we'll set it right.
4948 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
4950 assert(SvPOK(x) || SvGMAGICAL(x));
4951 if (sv_eq(x, CopFILESV(PL_curcop))) {
4952 sv_setpvn(x, ipath, ipathend - ipath);
4958 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
4959 const char * const lstart = SvPV_const(x,llen);
4961 bstart += blen - llen;
4962 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
4963 sv_setpvn(x, ipath, ipathend - ipath);
4968 TAINT_NOT; /* $^X is always tainted, but that's OK */
4970 #endif /* ARG_ZERO_IS_SCRIPT */
4975 d = instr(s,"perl -");
4977 d = instr(s,"perl");
4979 /* avoid getting into infinite loops when shebang
4980 * line contains "Perl" rather than "perl" */
4982 for (d = ipathend-4; d >= ipath; --d) {
4983 if ((*d == 'p' || *d == 'P')
4984 && !ibcmp(d, "perl", 4))
4994 #ifdef ALTERNATE_SHEBANG
4996 * If the ALTERNATE_SHEBANG on this system starts with a
4997 * character that can be part of a Perl expression, then if
4998 * we see it but not "perl", we're probably looking at the
4999 * start of Perl code, not a request to hand off to some
5000 * other interpreter. Similarly, if "perl" is there, but
5001 * not in the first 'word' of the line, we assume the line
5002 * contains the start of the Perl program.
5004 if (d && *s != '#') {
5005 const char *c = ipath;
5006 while (*c && !strchr("; \t\r\n\f\v#", *c))
5009 d = NULL; /* "perl" not in first word; ignore */
5011 *s = '#'; /* Don't try to parse shebang line */
5013 #endif /* ALTERNATE_SHEBANG */
5018 !instr(s,"indir") &&
5019 instr(PL_origargv[0],"perl"))
5026 while (s < PL_bufend && isSPACE(*s))
5028 if (s < PL_bufend) {
5029 Newx(newargv,PL_origargc+3,char*);
5031 while (s < PL_bufend && !isSPACE(*s))
5034 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
5037 newargv = PL_origargv;
5040 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
5042 Perl_croak(aTHX_ "Can't exec %s", ipath);
5045 while (*d && !isSPACE(*d))
5047 while (SPACE_OR_TAB(*d))
5051 const bool switches_done = PL_doswitches;
5052 const U32 oldpdb = PL_perldb;
5053 const bool oldn = PL_minus_n;
5054 const bool oldp = PL_minus_p;
5058 bool baduni = FALSE;
5060 const char *d2 = d1 + 1;
5061 if (parse_unicode_opts((const char **)&d2)
5065 if (baduni || *d1 == 'M' || *d1 == 'm') {
5066 const char * const m = d1;
5067 while (*d1 && !isSPACE(*d1))
5069 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
5072 d1 = moreswitches(d1);
5074 if (PL_doswitches && !switches_done) {
5075 int argc = PL_origargc;
5076 char **argv = PL_origargv;
5079 } while (argc && argv[0][0] == '-' && argv[0][1]);
5080 init_argv_symbols(argc,argv);
5082 if (((PERLDB_LINE || PERLDB_SAVESRC) && !oldpdb) ||
5083 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
5084 /* if we have already added "LINE: while (<>) {",
5085 we must not do it again */
5087 sv_setpvs(PL_linestr, "");
5088 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
5089 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
5090 PL_last_lop = PL_last_uni = NULL;
5091 PL_preambled = FALSE;
5092 if (PERLDB_LINE || PERLDB_SAVESRC)
5093 (void)gv_fetchfile(PL_origfilename);
5100 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
5102 PL_lex_state = LEX_FORMLINE;
5107 #ifdef PERL_STRICT_CR
5108 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
5110 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
5112 case ' ': case '\t': case '\f': case 013:
5114 PL_realtokenstart = -1;
5116 PL_thiswhite = newSVpvs("");
5117 sv_catpvn(PL_thiswhite, s, 1);
5124 PL_realtokenstart = -1;
5128 if (PL_lex_state != LEX_NORMAL ||
5129 (PL_in_eval && !PL_rsfp && !PL_parser->filtered)) {
5130 if (*s == '#' && s == PL_linestart && PL_in_eval
5131 && !PL_rsfp && !PL_parser->filtered) {
5132 /* handle eval qq[#line 1 "foo"\n ...] */
5133 CopLINE_dec(PL_curcop);
5136 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
5138 if (!PL_in_eval || PL_rsfp || PL_parser->filtered)
5143 while (d < PL_bufend && *d != '\n')
5147 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
5148 Perl_croak(aTHX_ "panic: input overflow");
5151 PL_thiswhite = newSVpvn(s, d - s);
5156 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
5158 PL_lex_state = LEX_FORMLINE;
5164 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
5165 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
5168 TOKEN(PEG); /* make sure any #! line is accessible */
5173 /* if (PL_madskills && PL_lex_formbrack) { */
5175 while (d < PL_bufend && *d != '\n')
5179 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
5180 Perl_croak(aTHX_ "panic: input overflow");
5181 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
5183 PL_thiswhite = newSVpvs("");
5184 if (CopLINE(PL_curcop) == 1) {
5185 sv_setpvs(PL_thiswhite, "");
5188 sv_catpvn(PL_thiswhite, s, d - s);
5202 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
5210 while (s < PL_bufend && SPACE_OR_TAB(*s))
5213 if (strnEQ(s,"=>",2)) {
5214 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
5215 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
5216 OPERATOR('-'); /* unary minus */
5218 PL_last_uni = PL_oldbufptr;
5220 case 'r': ftst = OP_FTEREAD; break;
5221 case 'w': ftst = OP_FTEWRITE; break;
5222 case 'x': ftst = OP_FTEEXEC; break;
5223 case 'o': ftst = OP_FTEOWNED; break;
5224 case 'R': ftst = OP_FTRREAD; break;
5225 case 'W': ftst = OP_FTRWRITE; break;
5226 case 'X': ftst = OP_FTREXEC; break;
5227 case 'O': ftst = OP_FTROWNED; break;
5228 case 'e': ftst = OP_FTIS; break;
5229 case 'z': ftst = OP_FTZERO; break;
5230 case 's': ftst = OP_FTSIZE; break;
5231 case 'f': ftst = OP_FTFILE; break;
5232 case 'd': ftst = OP_FTDIR; break;
5233 case 'l': ftst = OP_FTLINK; break;
5234 case 'p': ftst = OP_FTPIPE; break;
5235 case 'S': ftst = OP_FTSOCK; break;
5236 case 'u': ftst = OP_FTSUID; break;
5237 case 'g': ftst = OP_FTSGID; break;
5238 case 'k': ftst = OP_FTSVTX; break;
5239 case 'b': ftst = OP_FTBLK; break;
5240 case 'c': ftst = OP_FTCHR; break;
5241 case 't': ftst = OP_FTTTY; break;
5242 case 'T': ftst = OP_FTTEXT; break;
5243 case 'B': ftst = OP_FTBINARY; break;
5244 case 'M': case 'A': case 'C':
5245 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
5247 case 'M': ftst = OP_FTMTIME; break;
5248 case 'A': ftst = OP_FTATIME; break;
5249 case 'C': ftst = OP_FTCTIME; break;
5257 PL_last_lop_op = (OPCODE)ftst;
5258 DEBUG_T( { PerlIO_printf(Perl_debug_log,
5259 "### Saw file test %c\n", (int)tmp);
5264 /* Assume it was a minus followed by a one-letter named
5265 * subroutine call (or a -bareword), then. */
5266 DEBUG_T( { PerlIO_printf(Perl_debug_log,
5267 "### '-%c' looked like a file test but was not\n",
5274 const char tmp = *s++;
5277 if (PL_expect == XOPERATOR)
5282 else if (*s == '>') {
5285 if (isIDFIRST_lazy_if(s,UTF)) {
5286 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
5294 if (PL_expect == XOPERATOR) {
5295 if (*s == '=' && !PL_lex_allbrackets &&
5296 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
5303 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
5305 OPERATOR('-'); /* unary minus */
5311 const char tmp = *s++;
5314 if (PL_expect == XOPERATOR)
5319 if (PL_expect == XOPERATOR) {
5320 if (*s == '=' && !PL_lex_allbrackets &&
5321 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
5328 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
5335 if (PL_expect != XOPERATOR) {
5336 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5337 PL_expect = XOPERATOR;
5338 force_ident(PL_tokenbuf, '*');
5346 if (*s == '=' && !PL_lex_allbrackets &&
5347 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
5353 if (*s == '=' && !PL_lex_allbrackets &&
5354 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
5361 if (PL_expect == XOPERATOR) {
5362 if (s[1] == '=' && !PL_lex_allbrackets &&
5363 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN)
5368 PL_tokenbuf[0] = '%';
5369 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
5370 sizeof PL_tokenbuf - 1, FALSE);
5371 if (!PL_tokenbuf[1]) {
5374 PL_pending_ident = '%';
5378 if (!PL_lex_allbrackets && PL_lex_fakeeof >=
5379 (s[1] == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_BITWISE))
5384 if (PL_lex_brackets > 100)
5385 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
5386 PL_lex_brackstack[PL_lex_brackets++] = 0;
5387 PL_lex_allbrackets++;
5389 const char tmp = *s++;
5394 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
5396 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
5404 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMMA)
5411 goto just_a_word_zero_gv;
5414 switch (PL_expect) {
5420 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
5422 PL_bufptr = s; /* update in case we back off */
5425 "Use of := for an empty attribute list is not allowed");
5432 PL_expect = XTERMBLOCK;
5435 stuffstart = s - SvPVX(PL_linestr) - 1;
5439 while (isIDFIRST_lazy_if(s,UTF)) {
5442 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5443 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
5444 if (tmp < 0) tmp = -tmp;
5459 sv = newSVpvn_flags(s, len, UTF ? SVf_UTF8 : 0);
5461 d = scan_str(d,TRUE,TRUE);
5463 /* MUST advance bufptr here to avoid bogus
5464 "at end of line" context messages from yyerror().
5466 PL_bufptr = s + len;
5467 yyerror("Unterminated attribute parameter in attribute list");
5471 return REPORT(0); /* EOF indicator */
5475 sv_catsv(sv, PL_lex_stuff);
5476 attrs = op_append_elem(OP_LIST, attrs,
5477 newSVOP(OP_CONST, 0, sv));
5478 SvREFCNT_dec(PL_lex_stuff);
5479 PL_lex_stuff = NULL;
5482 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
5484 if (PL_in_my == KEY_our) {
5485 deprecate(":unique");
5488 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
5491 /* NOTE: any CV attrs applied here need to be part of
5492 the CVf_BUILTIN_ATTRS define in cv.h! */
5493 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
5495 CvLVALUE_on(PL_compcv);
5497 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
5499 deprecate(":locked");
5501 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
5503 CvMETHOD_on(PL_compcv);
5505 /* After we've set the flags, it could be argued that
5506 we don't need to do the attributes.pm-based setting
5507 process, and shouldn't bother appending recognized
5508 flags. To experiment with that, uncomment the
5509 following "else". (Note that's already been
5510 uncommented. That keeps the above-applied built-in
5511 attributes from being intercepted (and possibly
5512 rejected) by a package's attribute routines, but is
5513 justified by the performance win for the common case
5514 of applying only built-in attributes.) */
5516 attrs = op_append_elem(OP_LIST, attrs,
5517 newSVOP(OP_CONST, 0,
5521 if (*s == ':' && s[1] != ':')
5524 break; /* require real whitespace or :'s */
5525 /* XXX losing whitespace on sequential attributes here */
5529 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
5530 if (*s != ';' && *s != '}' && *s != tmp
5531 && (tmp != '=' || *s != ')')) {
5532 const char q = ((*s == '\'') ? '"' : '\'');
5533 /* If here for an expression, and parsed no attrs, back
5535 if (tmp == '=' && !attrs) {
5539 /* MUST advance bufptr here to avoid bogus "at end of line"
5540 context messages from yyerror().
5543 yyerror( (const char *)
5545 ? Perl_form(aTHX_ "Invalid separator character "
5546 "%c%c%c in attribute list", q, *s, q)
5547 : "Unterminated attribute list" ) );
5555 start_force(PL_curforce);
5556 NEXTVAL_NEXTTOKE.opval = attrs;
5557 CURMAD('_', PL_nextwhite);
5562 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
5563 (s - SvPVX(PL_linestr)) - stuffstart);
5568 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_CLOSING) {
5572 PL_lex_allbrackets--;
5576 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
5577 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
5581 PL_lex_allbrackets++;
5584 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR)
5590 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_CLOSING)
5593 PL_lex_allbrackets--;
5599 if (PL_lex_brackets && PL_lex_brackstack[PL_lex_brackets-1] == XFAKEEOF)
5602 if (PL_lex_brackets <= 0)
5603 yyerror("Unmatched right square bracket");
5606 PL_lex_allbrackets--;
5607 if (PL_lex_state == LEX_INTERPNORMAL) {
5608 if (PL_lex_brackets == 0) {
5609 if (*s == '-' && s[1] == '>')
5610 PL_lex_state = LEX_INTERPENDMAYBE;
5611 else if (*s != '[' && *s != '{')
5612 PL_lex_state = LEX_INTERPEND;
5619 if (PL_lex_brackets > 100) {
5620 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
5622 switch (PL_expect) {
5624 if (PL_lex_formbrack) {
5628 if (PL_oldoldbufptr == PL_last_lop)
5629 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
5631 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
5632 PL_lex_allbrackets++;
5633 OPERATOR(HASHBRACK);
5635 while (s < PL_bufend && SPACE_OR_TAB(*s))
5638 PL_tokenbuf[0] = '\0';
5639 if (d < PL_bufend && *d == '-') {
5640 PL_tokenbuf[0] = '-';
5642 while (d < PL_bufend && SPACE_OR_TAB(*d))
5645 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
5646 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
5648 while (d < PL_bufend && SPACE_OR_TAB(*d))
5651 const char minus = (PL_tokenbuf[0] == '-');
5652 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
5660 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
5661 PL_lex_allbrackets++;
5666 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
5667 PL_lex_allbrackets++;
5672 if (PL_oldoldbufptr == PL_last_lop)
5673 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
5675 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
5676 PL_lex_allbrackets++;
5679 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
5681 /* This hack is to get the ${} in the message. */
5683 yyerror("syntax error");
5686 OPERATOR(HASHBRACK);
5688 /* This hack serves to disambiguate a pair of curlies
5689 * as being a block or an anon hash. Normally, expectation
5690 * determines that, but in cases where we're not in a
5691 * position to expect anything in particular (like inside
5692 * eval"") we have to resolve the ambiguity. This code
5693 * covers the case where the first term in the curlies is a
5694 * quoted string. Most other cases need to be explicitly
5695 * disambiguated by prepending a "+" before the opening
5696 * curly in order to force resolution as an anon hash.
5698 * XXX should probably propagate the outer expectation
5699 * into eval"" to rely less on this hack, but that could
5700 * potentially break current behavior of eval"".
5704 if (*s == '\'' || *s == '"' || *s == '`') {
5705 /* common case: get past first string, handling escapes */
5706 for (t++; t < PL_bufend && *t != *s;)
5707 if (*t++ == '\\' && (*t == '\\' || *t == *s))
5711 else if (*s == 'q') {
5714 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
5717 /* skip q//-like construct */
5719 char open, close, term;
5722 while (t < PL_bufend && isSPACE(*t))
5724 /* check for q => */
5725 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
5726 OPERATOR(HASHBRACK);
5730 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
5734 for (t++; t < PL_bufend; t++) {
5735 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
5737 else if (*t == open)
5741 for (t++; t < PL_bufend; t++) {
5742 if (*t == '\\' && t+1 < PL_bufend)
5744 else if (*t == close && --brackets <= 0)
5746 else if (*t == open)
5753 /* skip plain q word */
5754 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
5757 else if (isALNUM_lazy_if(t,UTF)) {
5759 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
5762 while (t < PL_bufend && isSPACE(*t))
5764 /* if comma follows first term, call it an anon hash */
5765 /* XXX it could be a comma expression with loop modifiers */
5766 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
5767 || (*t == '=' && t[1] == '>')))
5768 OPERATOR(HASHBRACK);
5769 if (PL_expect == XREF)
5772 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
5778 pl_yylval.ival = CopLINE(PL_curcop);
5779 if (isSPACE(*s) || *s == '#')
5780 PL_copline = NOLINE; /* invalidate current command line number */
5783 if (PL_lex_brackets && PL_lex_brackstack[PL_lex_brackets-1] == XFAKEEOF)
5787 if (PL_lex_brackets <= 0)
5788 yyerror("Unmatched right curly bracket");
5790 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
5791 PL_lex_allbrackets--;
5792 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
5793 PL_lex_formbrack = 0;
5794 if (PL_lex_state == LEX_INTERPNORMAL) {
5795 if (PL_lex_brackets == 0) {
5796 if (PL_expect & XFAKEBRACK) {
5797 PL_expect &= XENUMMASK;
5798 PL_lex_state = LEX_INTERPEND;
5803 PL_thiswhite = newSVpvs("");
5804 sv_catpvs(PL_thiswhite,"}");
5807 return yylex(); /* ignore fake brackets */
5809 if (*s == '-' && s[1] == '>')
5810 PL_lex_state = LEX_INTERPENDMAYBE;
5811 else if (*s != '[' && *s != '{')
5812 PL_lex_state = LEX_INTERPEND;
5815 if (PL_expect & XFAKEBRACK) {
5816 PL_expect &= XENUMMASK;
5818 return yylex(); /* ignore fake brackets */
5820 start_force(PL_curforce);
5822 curmad('X', newSVpvn(s-1,1));
5823 CURMAD('_', PL_thiswhite);
5828 PL_thistoken = newSVpvs("");
5834 if (!PL_lex_allbrackets && PL_lex_fakeeof >=
5835 (*s == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_LOGIC)) {
5842 if (PL_expect == XOPERATOR) {
5843 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
5844 && isIDFIRST_lazy_if(s,UTF))
5846 CopLINE_dec(PL_curcop);
5847 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
5848 CopLINE_inc(PL_curcop);
5850 if (!PL_lex_allbrackets && PL_lex_fakeeof >=
5851 (*s == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_BITWISE)) {
5858 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5860 PL_expect = XOPERATOR;
5861 force_ident(PL_tokenbuf, '&');
5865 pl_yylval.ival = (OPpENTERSUB_AMPER<<8);
5871 if (!PL_lex_allbrackets && PL_lex_fakeeof >=
5872 (*s == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_LOGIC)) {
5879 if (!PL_lex_allbrackets && PL_lex_fakeeof >=
5880 (*s == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_BITWISE)) {
5888 const char tmp = *s++;
5890 if (!PL_lex_allbrackets &&
5891 PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) {
5898 if (!PL_lex_allbrackets &&
5899 PL_lex_fakeeof >= LEX_FAKEEOF_COMMA) {
5907 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
5908 && strchr("+-*/%.^&|<",tmp))
5909 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5910 "Reversed %c= operator",(int)tmp);
5912 if (PL_expect == XSTATE && isALPHA(tmp) &&
5913 (s == PL_linestart+1 || s[-2] == '\n') )
5915 if (PL_in_eval && !PL_rsfp && !PL_parser->filtered) {
5920 if (strnEQ(s,"=cut",4)) {
5936 PL_thiswhite = newSVpvs("");
5937 sv_catpvn(PL_thiswhite, PL_linestart,
5938 PL_bufend - PL_linestart);
5942 PL_parser->in_pod = 1;
5946 if (PL_lex_brackets < PL_lex_formbrack) {
5948 #ifdef PERL_STRICT_CR
5949 while (SPACE_OR_TAB(*t))
5951 while (SPACE_OR_TAB(*t) || *t == '\r')
5954 if (*t == '\n' || *t == '#') {
5960 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
5969 const char tmp = *s++;
5971 /* was this !=~ where !~ was meant?
5972 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
5974 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
5975 const char *t = s+1;
5977 while (t < PL_bufend && isSPACE(*t))
5980 if (*t == '/' || *t == '?' ||
5981 ((*t == 'm' || *t == 's' || *t == 'y')
5982 && !isALNUM(t[1])) ||
5983 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
5984 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5985 "!=~ should be !~");
5987 if (!PL_lex_allbrackets &&
5988 PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) {
6000 if (PL_expect != XOPERATOR) {
6001 if (s[1] != '<' && !strchr(s,'>'))
6004 s = scan_heredoc(s);
6006 s = scan_inputsymbol(s);
6007 TERM(sublex_start());
6013 if (*s == '=' && !PL_lex_allbrackets &&
6014 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
6018 SHop(OP_LEFT_SHIFT);
6023 if (!PL_lex_allbrackets &&
6024 PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) {
6031 if (!PL_lex_allbrackets &&
6032 PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) {
6040 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) {
6048 const char tmp = *s++;
6050 if (*s == '=' && !PL_lex_allbrackets &&
6051 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
6055 SHop(OP_RIGHT_SHIFT);
6057 else if (tmp == '=') {
6058 if (!PL_lex_allbrackets &&
6059 PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) {
6067 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) {
6076 if (PL_expect == XOPERATOR) {
6077 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
6078 return deprecate_commaless_var_list();
6082 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-@", s[2]))) {
6083 PL_tokenbuf[0] = '@';
6084 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
6085 sizeof PL_tokenbuf - 1, FALSE);
6086 if (PL_expect == XOPERATOR)
6087 no_op("Array length", s);
6088 if (!PL_tokenbuf[1])
6090 PL_expect = XOPERATOR;
6091 PL_pending_ident = '#';
6095 PL_tokenbuf[0] = '$';
6096 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
6097 sizeof PL_tokenbuf - 1, FALSE);
6098 if (PL_expect == XOPERATOR)
6100 if (!PL_tokenbuf[1]) {
6102 yyerror("Final $ should be \\$ or $name");
6108 const char tmp = *s;
6109 if (PL_lex_state == LEX_NORMAL || PL_lex_brackets)
6112 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
6113 && intuit_more(s)) {
6115 PL_tokenbuf[0] = '@';
6116 if (ckWARN(WARN_SYNTAX)) {
6119 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
6122 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
6123 while (t < PL_bufend && *t != ']')
6125 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6126 "Multidimensional syntax %.*s not supported",
6127 (int)((t - PL_bufptr) + 1), PL_bufptr);
6131 else if (*s == '{') {
6133 PL_tokenbuf[0] = '%';
6134 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
6135 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
6137 char tmpbuf[sizeof PL_tokenbuf];
6140 } while (isSPACE(*t));
6141 if (isIDFIRST_lazy_if(t,UTF)) {
6143 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
6147 if (*t == ';' && get_cvn_flags(tmpbuf, len, 0))
6148 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6149 "You need to quote \"%s\"",
6156 PL_expect = XOPERATOR;
6157 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
6158 const bool islop = (PL_last_lop == PL_oldoldbufptr);
6159 if (!islop || PL_last_lop_op == OP_GREPSTART)
6160 PL_expect = XOPERATOR;
6161 else if (strchr("$@\"'`q", *s))
6162 PL_expect = XTERM; /* e.g. print $fh "foo" */
6163 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
6164 PL_expect = XTERM; /* e.g. print $fh &sub */
6165 else if (isIDFIRST_lazy_if(s,UTF)) {
6166 char tmpbuf[sizeof PL_tokenbuf];
6168 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6169 if ((t2 = keyword(tmpbuf, len, 0))) {
6170 /* binary operators exclude handle interpretations */
6182 PL_expect = XTERM; /* e.g. print $fh length() */
6187 PL_expect = XTERM; /* e.g. print $fh subr() */
6190 else if (isDIGIT(*s))
6191 PL_expect = XTERM; /* e.g. print $fh 3 */
6192 else if (*s == '.' && isDIGIT(s[1]))
6193 PL_expect = XTERM; /* e.g. print $fh .3 */
6194 else if ((*s == '?' || *s == '-' || *s == '+')
6195 && !isSPACE(s[1]) && s[1] != '=')
6196 PL_expect = XTERM; /* e.g. print $fh -1 */
6197 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
6199 PL_expect = XTERM; /* e.g. print $fh /.../
6200 XXX except DORDOR operator
6202 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
6204 PL_expect = XTERM; /* print $fh <<"EOF" */
6207 PL_pending_ident = '$';
6211 if (PL_expect == XOPERATOR)
6213 PL_tokenbuf[0] = '@';
6214 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
6215 if (!PL_tokenbuf[1]) {
6218 if (PL_lex_state == LEX_NORMAL)
6220 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
6222 PL_tokenbuf[0] = '%';
6224 /* Warn about @ where they meant $. */
6225 if (*s == '[' || *s == '{') {
6226 if (ckWARN(WARN_SYNTAX)) {
6227 const char *t = s + 1;
6228 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
6230 if (*t == '}' || *t == ']') {
6232 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
6233 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6234 "Scalar value %.*s better written as $%.*s",
6235 (int)(t-PL_bufptr), PL_bufptr,
6236 (int)(t-PL_bufptr-1), PL_bufptr+1);
6241 PL_pending_ident = '@';
6244 case '/': /* may be division, defined-or, or pattern */
6245 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
6246 if (!PL_lex_allbrackets && PL_lex_fakeeof >=
6247 (s[2] == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_LOGIC))
6252 case '?': /* may either be conditional or pattern */
6253 if (PL_expect == XOPERATOR) {
6256 if (!PL_lex_allbrackets &&
6257 PL_lex_fakeeof >= LEX_FAKEEOF_IFELSE) {
6261 PL_lex_allbrackets++;
6267 /* A // operator. */
6268 if (!PL_lex_allbrackets && PL_lex_fakeeof >=
6269 (*s == '=' ? LEX_FAKEEOF_ASSIGN :
6270 LEX_FAKEEOF_LOGIC)) {
6278 if (*s == '=' && !PL_lex_allbrackets &&
6279 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
6288 /* Disable warning on "study /blah/" */
6289 if (PL_oldoldbufptr == PL_last_uni
6290 && (*PL_last_uni != 's' || s - PL_last_uni < 5
6291 || memNE(PL_last_uni, "study", 5)
6292 || isALNUM_lazy_if(PL_last_uni+5,UTF)
6296 deprecate("?PATTERN? without explicit operator");
6297 s = scan_pat(s,OP_MATCH);
6298 TERM(sublex_start());
6302 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
6303 #ifdef PERL_STRICT_CR
6306 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
6308 && (s == PL_linestart || s[-1] == '\n') )
6310 PL_lex_formbrack = 0;
6314 if (PL_expect == XSTATE && s[1] == '.' && s[2] == '.') {
6318 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
6321 if (!PL_lex_allbrackets &&
6322 PL_lex_fakeeof >= LEX_FAKEEOF_RANGE) {
6329 pl_yylval.ival = OPf_SPECIAL;
6335 if (*s == '=' && !PL_lex_allbrackets &&
6336 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) {
6343 case '0': case '1': case '2': case '3': case '4':
6344 case '5': case '6': case '7': case '8': case '9':
6345 s = scan_num(s, &pl_yylval);
6346 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
6347 if (PL_expect == XOPERATOR)
6352 s = scan_str(s,!!PL_madskills,FALSE);
6353 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
6354 if (PL_expect == XOPERATOR) {
6355 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
6356 return deprecate_commaless_var_list();
6363 pl_yylval.ival = OP_CONST;
6364 TERM(sublex_start());
6367 s = scan_str(s,!!PL_madskills,FALSE);
6368 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
6369 if (PL_expect == XOPERATOR) {
6370 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
6371 return deprecate_commaless_var_list();
6378 pl_yylval.ival = OP_CONST;
6379 /* FIXME. I think that this can be const if char *d is replaced by
6380 more localised variables. */
6381 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
6382 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
6383 pl_yylval.ival = OP_STRINGIFY;
6387 TERM(sublex_start());
6390 s = scan_str(s,!!PL_madskills,FALSE);
6391 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
6392 if (PL_expect == XOPERATOR)
6393 no_op("Backticks",s);
6396 readpipe_override();
6397 TERM(sublex_start());
6401 if (PL_lex_inwhat && isDIGIT(*s))
6402 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
6404 if (PL_expect == XOPERATOR)
6405 no_op("Backslash",s);
6409 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
6410 char *start = s + 2;
6411 while (isDIGIT(*start) || *start == '_')
6413 if (*start == '.' && isDIGIT(start[1])) {
6414 s = scan_num(s, &pl_yylval);
6417 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
6418 else if (!isALPHA(*start) && (PL_expect == XTERM
6419 || PL_expect == XREF || PL_expect == XSTATE
6420 || PL_expect == XTERMORDORDOR)) {
6421 GV *const gv = gv_fetchpvn_flags(s, start - s,
6422 UTF ? SVf_UTF8 : 0, SVt_PVCV);
6424 s = scan_num(s, &pl_yylval);
6431 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
6474 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
6476 /* Some keywords can be followed by any delimiter, including ':' */
6477 anydelim = word_takes_any_delimeter(PL_tokenbuf, len);
6479 /* x::* is just a word, unless x is "CORE" */
6480 if (!anydelim && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
6484 while (d < PL_bufend && isSPACE(*d))
6485 d++; /* no comments skipped here, or s### is misparsed */
6487 /* Is this a word before a => operator? */
6488 if (*d == '=' && d[1] == '>') {
6491 = (OP*)newSVOP(OP_CONST, 0,
6492 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
6493 pl_yylval.opval->op_private = OPpCONST_BARE;
6497 /* Check for plugged-in keyword */
6501 char *saved_bufptr = PL_bufptr;
6503 result = PL_keyword_plugin(aTHX_ PL_tokenbuf, len, &o);
6505 if (result == KEYWORD_PLUGIN_DECLINE) {
6506 /* not a plugged-in keyword */
6507 PL_bufptr = saved_bufptr;
6508 } else if (result == KEYWORD_PLUGIN_STMT) {
6509 pl_yylval.opval = o;
6512 return REPORT(PLUGSTMT);
6513 } else if (result == KEYWORD_PLUGIN_EXPR) {
6514 pl_yylval.opval = o;
6516 PL_expect = XOPERATOR;
6517 return REPORT(PLUGEXPR);
6519 Perl_croak(aTHX_ "Bad plugin affecting keyword '%s'",
6524 /* Check for built-in keyword */
6525 tmp = keyword(PL_tokenbuf, len, 0);
6527 /* Is this a label? */
6528 if (!anydelim && PL_expect == XSTATE
6529 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
6531 pl_yylval.pval = CopLABEL_alloc(PL_tokenbuf);
6536 if (tmp < 0) { /* second-class keyword? */
6537 GV *ogv = NULL; /* override (winner) */
6538 GV *hgv = NULL; /* hidden (loser) */
6539 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
6541 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len,
6542 UTF ? SVf_UTF8 : 0, SVt_PVCV)) &&
6545 if (GvIMPORTED_CV(gv))
6547 else if (! CvMETHOD(cv))
6551 (gvp = (GV**)hv_fetch(PL_globalstash, PL_tokenbuf,
6552 UTF ? -(I32)len : (I32)len, FALSE)) &&
6553 (gv = *gvp) && isGV_with_GP(gv) &&
6554 GvCVu(gv) && GvIMPORTED_CV(gv))
6561 tmp = 0; /* overridden by import or by GLOBAL */
6564 && -tmp==KEY_lock /* XXX generalizable kludge */
6567 tmp = 0; /* any sub overrides "weak" keyword */
6569 else { /* no override */
6571 if (tmp == KEY_dump) {
6572 Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
6573 "dump() better written as CORE::dump()");
6577 if (hgv && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */
6578 Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6579 "Ambiguous call resolved as CORE::%s(), "
6580 "qualify as such or use &",
6588 default: /* not a keyword */
6589 /* Trade off - by using this evil construction we can pull the
6590 variable gv into the block labelled keylookup. If not, then
6591 we have to give it function scope so that the goto from the
6592 earlier ':' case doesn't bypass the initialisation. */
6594 just_a_word_zero_gv:
6602 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
6606 SV *nextPL_nextwhite = 0;
6610 /* Get the rest if it looks like a package qualifier */
6612 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
6614 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
6617 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
6618 *s == '\'' ? "'" : "::");
6623 if (PL_expect == XOPERATOR) {
6624 if (PL_bufptr == PL_linestart) {
6625 CopLINE_dec(PL_curcop);
6626 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
6627 CopLINE_inc(PL_curcop);
6630 no_op("Bareword",s);
6633 /* Look for a subroutine with this name in current package,
6634 unless name is "Foo::", in which case Foo is a bareword
6635 (and a package name). */
6637 if (len > 2 && !PL_madskills &&
6638 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
6640 if (ckWARN(WARN_BAREWORD)
6641 && ! gv_fetchpvn_flags(PL_tokenbuf, len, UTF ? SVf_UTF8 : 0, SVt_PVHV))
6642 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
6643 "Bareword \"%s\" refers to nonexistent package",
6646 PL_tokenbuf[len] = '\0';
6652 /* Mustn't actually add anything to a symbol table.
6653 But also don't want to "initialise" any placeholder
6654 constants that might already be there into full
6655 blown PVGVs with attached PVCV. */
6656 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
6657 GV_NOADD_NOINIT | ( UTF ? SVf_UTF8 : 0 ),
6663 /* if we saw a global override before, get the right name */
6665 sv = S_newSV_maybe_utf8(aTHX_ PL_tokenbuf,
6666 len ? len : strlen(PL_tokenbuf));
6668 SV * const tmp_sv = sv;
6669 sv = newSVpvs("CORE::GLOBAL::");
6670 sv_catsv(sv, tmp_sv);
6671 SvREFCNT_dec(tmp_sv);
6675 if (PL_madskills && !PL_thistoken) {
6676 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
6677 PL_thistoken = newSVpvn(start,s - start);
6678 PL_realtokenstart = s - SvPVX(PL_linestr);
6682 /* Presume this is going to be a bareword of some sort. */
6684 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
6685 pl_yylval.opval->op_private = OPpCONST_BARE;
6687 /* And if "Foo::", then that's what it certainly is. */
6692 OP *const_op = newSVOP(OP_CONST, 0, SvREFCNT_inc_NN(sv));
6693 const_op->op_private = OPpCONST_BARE;
6694 rv2cv_op = newCVREF(0, const_op);
6696 cv = rv2cv_op_cv(rv2cv_op, 0);
6698 /* See if it's the indirect object for a list operator. */
6700 if (PL_oldoldbufptr &&
6701 PL_oldoldbufptr < PL_bufptr &&
6702 (PL_oldoldbufptr == PL_last_lop
6703 || PL_oldoldbufptr == PL_last_uni) &&
6704 /* NO SKIPSPACE BEFORE HERE! */
6705 (PL_expect == XREF ||
6706 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
6708 bool immediate_paren = *s == '(';
6710 /* (Now we can afford to cross potential line boundary.) */
6711 s = SKIPSPACE2(s,nextPL_nextwhite);
6713 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
6716 /* Two barewords in a row may indicate method call. */
6718 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
6719 (tmp = intuit_method(s, gv, cv))) {
6721 if (tmp == METHOD && !PL_lex_allbrackets &&
6722 PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC)
6723 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC;
6727 /* If not a declared subroutine, it's an indirect object. */
6728 /* (But it's an indir obj regardless for sort.) */
6729 /* Also, if "_" follows a filetest operator, it's a bareword */
6732 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
6734 (PL_last_lop_op != OP_MAPSTART &&
6735 PL_last_lop_op != OP_GREPSTART))))
6736 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
6737 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
6740 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
6745 PL_expect = XOPERATOR;
6748 s = SKIPSPACE2(s,nextPL_nextwhite);
6749 PL_nextwhite = nextPL_nextwhite;
6754 /* Is this a word before a => operator? */
6755 if (*s == '=' && s[1] == '>' && !pkgname) {
6758 sv_setpv(((SVOP*)pl_yylval.opval)->op_sv, PL_tokenbuf);
6759 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
6760 SvUTF8_on(((SVOP*)pl_yylval.opval)->op_sv);
6764 /* If followed by a paren, it's certainly a subroutine. */
6769 while (SPACE_OR_TAB(*d))
6771 if (*d == ')' && (sv = cv_const_sv(cv))) {
6778 PL_nextwhite = PL_thiswhite;
6781 start_force(PL_curforce);
6783 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6784 PL_expect = XOPERATOR;
6787 PL_nextwhite = nextPL_nextwhite;
6788 curmad('X', PL_thistoken);
6789 PL_thistoken = newSVpvs("");
6798 /* If followed by var or block, call it a method (unless sub) */
6800 if ((*s == '$' || *s == '{') && !cv) {
6802 PL_last_lop = PL_oldbufptr;
6803 PL_last_lop_op = OP_METHOD;
6804 if (!PL_lex_allbrackets &&
6805 PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC)
6806 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC;
6810 /* If followed by a bareword, see if it looks like indir obj. */
6813 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
6814 && (tmp = intuit_method(s, gv, cv))) {
6816 if (tmp == METHOD && !PL_lex_allbrackets &&
6817 PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC)
6818 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC;
6822 /* Not a method, so call it a subroutine (if defined) */
6825 if (lastchar == '-')
6826 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
6827 "Ambiguous use of -%s resolved as -&%s()",
6828 PL_tokenbuf, PL_tokenbuf);
6829 /* Check for a constant sub */
6830 if ((sv = cv_const_sv(cv))) {
6833 SvREFCNT_dec(((SVOP*)pl_yylval.opval)->op_sv);
6834 ((SVOP*)pl_yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
6835 pl_yylval.opval->op_private = 0;
6836 pl_yylval.opval->op_flags |= OPf_SPECIAL;
6840 op_free(pl_yylval.opval);
6841 pl_yylval.opval = rv2cv_op;
6842 pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
6843 PL_last_lop = PL_oldbufptr;
6844 PL_last_lop_op = OP_ENTERSUB;
6845 /* Is there a prototype? */
6852 STRLEN protolen = CvPROTOLEN(cv);
6853 const char *proto = CvPROTO(cv);
6857 if ((optional = *proto == ';'))
6860 while (*proto == ';');
6864 *proto == '$' || *proto == '_'
6865 || *proto == '*' || *proto == '+'
6870 *proto == '\\' && proto[1] && proto[2] == '\0'
6873 UNIPROTO(UNIOPSUB,optional);
6874 if (*proto == '\\' && proto[1] == '[') {
6875 const char *p = proto + 2;
6876 while(*p && *p != ']')
6878 if(*p == ']' && !p[1])
6879 UNIPROTO(UNIOPSUB,optional);
6881 if (*proto == '&' && *s == '{') {
6883 sv_setpvs(PL_subname, "__ANON__");
6885 sv_setpvs(PL_subname, "__ANON__::__ANON__");
6886 if (!PL_lex_allbrackets &&
6887 PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC)
6888 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC;
6895 PL_nextwhite = PL_thiswhite;
6898 start_force(PL_curforce);
6899 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6902 PL_nextwhite = nextPL_nextwhite;
6903 curmad('X', PL_thistoken);
6904 PL_thistoken = newSVpvs("");
6907 if (!PL_lex_allbrackets &&
6908 PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC)
6909 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC;
6914 /* Guess harder when madskills require "best effort". */
6915 if (PL_madskills && (!gv || !GvCVu(gv))) {
6916 int probable_sub = 0;
6917 if (strchr("\"'`$@%0123456789!*+{[<", *s))
6919 else if (isALPHA(*s)) {
6923 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
6924 if (!keyword(tmpbuf, tmplen, 0))
6927 while (d < PL_bufend && isSPACE(*d))
6929 if (*d == '=' && d[1] == '>')
6934 gv = gv_fetchpv(PL_tokenbuf, GV_ADD | ( UTF ? SVf_UTF8 : 0 ),
6936 op_free(pl_yylval.opval);
6937 pl_yylval.opval = rv2cv_op;
6938 pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
6939 PL_last_lop = PL_oldbufptr;
6940 PL_last_lop_op = OP_ENTERSUB;
6941 PL_nextwhite = PL_thiswhite;
6943 start_force(PL_curforce);
6944 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6946 PL_nextwhite = nextPL_nextwhite;
6947 curmad('X', PL_thistoken);
6948 PL_thistoken = newSVpvs("");
6950 if (!PL_lex_allbrackets &&
6951 PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC)
6952 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC;
6956 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6959 if (!PL_lex_allbrackets &&
6960 PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC)
6961 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC;
6966 /* Call it a bare word */
6968 if (PL_hints & HINT_STRICT_SUBS)
6969 pl_yylval.opval->op_private |= OPpCONST_STRICT;
6972 /* after "print" and similar functions (corresponding to
6973 * "F? L" in opcode.pl), whatever wasn't already parsed as
6974 * a filehandle should be subject to "strict subs".
6975 * Likewise for the optional indirect-object argument to system
6976 * or exec, which can't be a bareword */
6977 if ((PL_last_lop_op == OP_PRINT
6978 || PL_last_lop_op == OP_PRTF
6979 || PL_last_lop_op == OP_SAY
6980 || PL_last_lop_op == OP_SYSTEM
6981 || PL_last_lop_op == OP_EXEC)
6982 && (PL_hints & HINT_STRICT_SUBS))
6983 pl_yylval.opval->op_private |= OPpCONST_STRICT;
6984 if (lastchar != '-') {
6985 if (ckWARN(WARN_RESERVED)) {
6989 if (!*d && !gv_stashpv(PL_tokenbuf, UTF ? SVf_UTF8 : 0))
6990 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
6998 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')) {
6999 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
7000 "Operator or semicolon missing before %c%s",
7001 lastchar, PL_tokenbuf);
7002 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
7003 "Ambiguous use of %c resolved as operator %c",
7004 lastchar, lastchar);
7011 (OP*)newSVOP(OP_CONST, 0, newSVpv(CopFILE(PL_curcop),0))
7016 (OP*)newSVOP(OP_CONST, 0,
7017 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)))
7020 case KEY___PACKAGE__:
7022 (OP*)newSVOP(OP_CONST, 0,
7024 ? newSVhek(HvNAME_HEK(PL_curstash))
7031 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
7032 const char *pname = "main";
7035 if (PL_tokenbuf[2] == 'D')
7038 PL_curstash ? PL_curstash : PL_defstash;
7039 pname = HvNAME_get(stash);
7040 plen = HvNAMELEN (stash);
7041 if(HvNAMEUTF8(stash)) putf8 = SVf_UTF8;
7043 gv = gv_fetchpvn_flags(
7044 Perl_form(aTHX_ "%*s::DATA", (int)plen, pname),
7045 plen+6, GV_ADD|putf8, SVt_PVIO
7049 GvIOp(gv) = newIO();
7050 IoIFP(GvIOp(gv)) = PL_rsfp;
7051 #if defined(HAS_FCNTL) && defined(F_SETFD)
7053 const int fd = PerlIO_fileno(PL_rsfp);
7054 fcntl(fd,F_SETFD,fd >= 3);
7057 /* Mark this internal pseudo-handle as clean */
7058 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
7059 if ((PerlIO*)PL_rsfp == PerlIO_stdin())
7060 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
7062 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
7063 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
7064 /* if the script was opened in binmode, we need to revert
7065 * it to text mode for compatibility; but only iff it has CRs
7066 * XXX this is a questionable hack at best. */
7067 if (PL_bufend-PL_bufptr > 2
7068 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
7071 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
7072 loc = PerlIO_tell(PL_rsfp);
7073 (void)PerlIO_seek(PL_rsfp, 0L, 0);
7076 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
7078 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
7079 #endif /* NETWARE */
7081 PerlIO_seek(PL_rsfp, loc, 0);
7085 #ifdef PERLIO_LAYERS
7088 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
7089 else if (PL_encoding) {
7096 XPUSHs(PL_encoding);
7098 call_method("name", G_SCALAR);
7102 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
7103 Perl_form(aTHX_ ":encoding(%"SVf")",
7112 if (PL_realtokenstart >= 0) {
7113 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
7115 PL_endwhite = newSVpvs("");
7116 sv_catsv(PL_endwhite, PL_thiswhite);
7118 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
7119 PL_realtokenstart = -1;
7121 while ((s = filter_gets(PL_endwhite, SvCUR(PL_endwhite)))
7131 FUN0OP(newPVOP(OP_RUNCV,0,NULL));
7140 if (PL_expect == XSTATE) {
7147 if (*s == ':' && s[1] == ':') {
7150 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
7151 if (!(tmp = keyword(PL_tokenbuf, len, 1)))
7152 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
7155 else if (tmp == KEY_require || tmp == KEY_do
7157 /* that's a way to remember we saw "CORE::" */
7170 LOP(OP_ACCEPT,XTERM);
7173 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_LOWLOGIC)
7178 LOP(OP_ATAN2,XTERM);
7184 LOP(OP_BINMODE,XTERM);
7187 LOP(OP_BLESS,XTERM);
7196 /* We have to disambiguate the two senses of
7197 "continue". If the next token is a '{' then
7198 treat it as the start of a continue block;
7199 otherwise treat it as a control operator.
7209 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
7219 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
7228 if (!PL_cryptseen) {
7229 PL_cryptseen = TRUE;
7233 LOP(OP_CRYPT,XTERM);
7236 LOP(OP_CHMOD,XTERM);
7239 LOP(OP_CHOWN,XTERM);
7242 LOP(OP_CONNECT,XTERM);
7261 s = force_word(s,WORD,TRUE,TRUE,FALSE);
7262 if (orig_keyword == KEY_do) {
7271 PL_hints |= HINT_BLOCK_SCOPE;
7281 Perl_populate_isa(aTHX_ STR_WITH_LEN("AnyDBM_File::ISA"),
7282 STR_WITH_LEN("NDBM_File::"),
7283 STR_WITH_LEN("DB_File::"),
7284 STR_WITH_LEN("GDBM_File::"),
7285 STR_WITH_LEN("SDBM_File::"),
7286 STR_WITH_LEN("ODBM_File::"),
7288 LOP(OP_DBMOPEN,XTERM);
7294 s = force_word(s,WORD,TRUE,FALSE,FALSE);
7301 pl_yylval.ival = CopLINE(PL_curcop);
7305 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
7319 if (*s == '{') { /* block eval */
7320 PL_expect = XTERMBLOCK;
7321 UNIBRACK(OP_ENTERTRY);
7323 else { /* string eval */
7325 UNIBRACK(OP_ENTEREVAL);
7330 UNIBRACK(-OP_ENTEREVAL);
7344 case KEY_endhostent:
7350 case KEY_endservent:
7353 case KEY_endprotoent:
7364 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR)
7366 pl_yylval.ival = CopLINE(PL_curcop);
7368 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
7371 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
7374 if ((PL_bufend - p) >= 3 &&
7375 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
7377 else if ((PL_bufend - p) >= 4 &&
7378 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
7381 if (isIDFIRST_lazy_if(p,UTF)) {
7382 p = scan_ident(p, PL_bufend,
7383 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
7387 Perl_croak(aTHX_ "Missing $ on loop variable");
7389 s = SvPVX(PL_linestr) + soff;
7395 LOP(OP_FORMLINE,XTERM);
7401 LOP(OP_FCNTL,XTERM);
7407 LOP(OP_FLOCK,XTERM);
7410 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
7415 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
7420 LOP(OP_GREPSTART, XREF);
7423 s = force_word(s,WORD,TRUE,FALSE,FALSE);
7438 case KEY_getpriority:
7439 LOP(OP_GETPRIORITY,XTERM);
7441 case KEY_getprotobyname:
7444 case KEY_getprotobynumber:
7445 LOP(OP_GPBYNUMBER,XTERM);
7447 case KEY_getprotoent:
7459 case KEY_getpeername:
7460 UNI(OP_GETPEERNAME);
7462 case KEY_gethostbyname:
7465 case KEY_gethostbyaddr:
7466 LOP(OP_GHBYADDR,XTERM);
7468 case KEY_gethostent:
7471 case KEY_getnetbyname:
7474 case KEY_getnetbyaddr:
7475 LOP(OP_GNBYADDR,XTERM);
7480 case KEY_getservbyname:
7481 LOP(OP_GSBYNAME,XTERM);
7483 case KEY_getservbyport:
7484 LOP(OP_GSBYPORT,XTERM);
7486 case KEY_getservent:
7489 case KEY_getsockname:
7490 UNI(OP_GETSOCKNAME);
7492 case KEY_getsockopt:
7493 LOP(OP_GSOCKOPT,XTERM);
7508 pl_yylval.ival = CopLINE(PL_curcop);
7513 orig_keyword==KEY_glob ? (orig_keyword=0, -OP_GLOB) : OP_GLOB,
7521 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR)
7523 pl_yylval.ival = CopLINE(PL_curcop);
7527 LOP(OP_INDEX,XTERM);
7533 LOP(OP_IOCTL,XTERM);
7545 s = force_word(s,WORD,TRUE,FALSE,FALSE);
7562 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
7567 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
7581 LOP(OP_LISTEN,XTERM);
7590 s = scan_pat(s,OP_MATCH);
7591 TERM(sublex_start());
7594 LOP(OP_MAPSTART, XREF);
7597 LOP(OP_MKDIR,XTERM);
7600 LOP(OP_MSGCTL,XTERM);
7603 LOP(OP_MSGGET,XTERM);
7606 LOP(OP_MSGRCV,XTERM);
7609 LOP(OP_MSGSND,XTERM);
7614 PL_in_my = (U16)tmp;
7616 if (isIDFIRST_lazy_if(s,UTF)) {
7620 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
7621 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
7623 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
7624 if (!PL_in_my_stash) {
7627 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
7631 if (PL_madskills) { /* just add type to declarator token */
7632 sv_catsv(PL_thistoken, PL_nextwhite);
7634 sv_catpvn(PL_thistoken, start, s - start);
7642 s = force_word(s,WORD,TRUE,FALSE,FALSE);
7646 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
7651 s = tokenize_use(0, s);
7655 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
7658 if (!PL_lex_allbrackets &&
7659 PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC)
7660 PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC;
7666 if (isIDFIRST_lazy_if(s,UTF)) {
7668 for (d = s; isALNUM_lazy_if(d,UTF);)
7670 for (t=d; isSPACE(*t);)
7672 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
7674 && !(t[0] == '=' && t[1] == '>')
7675 && !keyword(s, d-s, 0)
7677 int parms_len = (int)(d-s);
7678 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
7679 "Precedence problem: open %.*s should be open(%.*s)",
7680 parms_len, s, parms_len, s);
7686 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_LOWLOGIC)
7688 pl_yylval.ival = OP_OR;
7698 LOP(OP_OPEN_DIR,XTERM);
7701 checkcomma(s,PL_tokenbuf,"filehandle");
7705 checkcomma(s,PL_tokenbuf,"filehandle");
7724 s = force_word(s,WORD,FALSE,TRUE,FALSE);
7726 s = force_strict_version(s);
7727 PL_lex_expect = XBLOCK;
7731 LOP(OP_PIPE_OP,XTERM);
7734 s = scan_str(s,!!PL_madskills,FALSE);
7737 pl_yylval.ival = OP_CONST;
7738 TERM(sublex_start());
7745 s = scan_str(s,!!PL_madskills,FALSE);
7748 PL_expect = XOPERATOR;
7749 if (SvCUR(PL_lex_stuff)) {
7750 int warned_comma = !ckWARN(WARN_QW);
7751 int warned_comment = warned_comma;
7752 d = SvPV_force(PL_lex_stuff, len);
7754 for (; isSPACE(*d) && len; --len, ++d)
7759 if (!warned_comma || !warned_comment) {
7760 for (; !isSPACE(*d) && len; --len, ++d) {
7761 if (!warned_comma && *d == ',') {
7762 Perl_warner(aTHX_ packWARN(WARN_QW),
7763 "Possible attempt to separate words with commas");
7766 else if (!warned_comment && *d == '#') {
7767 Perl_warner(aTHX_ packWARN(WARN_QW),
7768 "Possible attempt to put comments in qw() list");
7774 for (; !isSPACE(*d) && len; --len, ++d)
7777 sv = newSVpvn_utf8(b, d-b, DO_UTF8(PL_lex_stuff));
7778 words = op_append_elem(OP_LIST, words,
7779 newSVOP(OP_CONST, 0, tokeq(sv)));
7784 words = newNULLLIST();
7786 SvREFCNT_dec(PL_lex_stuff);
7787 PL_lex_stuff = NULL;
7789 PL_expect = XOPERATOR;
7790 pl_yylval.opval = sawparens(words);
7795 s = scan_str(s,!!PL_madskills,FALSE);
7798 pl_yylval.ival = OP_STRINGIFY;
7799 if (SvIVX(PL_lex_stuff) == '\'')
7800 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should interpolate */
7801 TERM(sublex_start());
7804 s = scan_pat(s,OP_QR);
7805 TERM(sublex_start());
7808 s = scan_str(s,!!PL_madskills,FALSE);
7811 readpipe_override();
7812 TERM(sublex_start());
7820 s = force_version(s, FALSE);
7822 else if (*s != 'v' || !isDIGIT(s[1])
7823 || (s = force_version(s, TRUE), *s == 'v'))
7825 *PL_tokenbuf = '\0';
7826 s = force_word(s,WORD,TRUE,TRUE,FALSE);
7827 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
7828 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf),
7829 GV_ADD | (UTF ? SVf_UTF8 : 0));
7831 yyerror("<> should be quotes");
7833 if (orig_keyword == KEY_require) {
7841 PL_last_uni = PL_oldbufptr;
7842 PL_last_lop_op = OP_REQUIRE;
7844 return REPORT( (int)REQUIRE );
7850 s = force_word(s,WORD,TRUE,FALSE,FALSE);
7854 LOP(OP_RENAME,XTERM);
7863 LOP(OP_RINDEX,XTERM);
7872 UNIDOR(OP_READLINE);
7875 UNIDOR(OP_BACKTICK);
7884 LOP(OP_REVERSE,XTERM);
7887 UNIDOR(OP_READLINK);
7894 if (pl_yylval.opval)
7895 TERM(sublex_start());
7897 TOKEN(1); /* force error */
7900 checkcomma(s,PL_tokenbuf,"filehandle");
7910 LOP(OP_SELECT,XTERM);
7916 LOP(OP_SEMCTL,XTERM);
7919 LOP(OP_SEMGET,XTERM);
7922 LOP(OP_SEMOP,XTERM);
7928 LOP(OP_SETPGRP,XTERM);
7930 case KEY_setpriority:
7931 LOP(OP_SETPRIORITY,XTERM);
7933 case KEY_sethostent:
7939 case KEY_setservent:
7942 case KEY_setprotoent:
7952 LOP(OP_SEEKDIR,XTERM);
7954 case KEY_setsockopt:
7955 LOP(OP_SSOCKOPT,XTERM);
7961 LOP(OP_SHMCTL,XTERM);
7964 LOP(OP_SHMGET,XTERM);
7967 LOP(OP_SHMREAD,XTERM);
7970 LOP(OP_SHMWRITE,XTERM);
7973 LOP(OP_SHUTDOWN,XTERM);
7982 LOP(OP_SOCKET,XTERM);
7984 case KEY_socketpair:
7985 LOP(OP_SOCKPAIR,XTERM);
7988 checkcomma(s,PL_tokenbuf,"subroutine name");
7990 if (*s == ';' || *s == ')') /* probably a close */
7991 Perl_croak(aTHX_ "sort is now a reserved word");
7993 s = force_word(s,WORD,TRUE,TRUE,FALSE);
7997 LOP(OP_SPLIT,XTERM);
8000 LOP(OP_SPRINTF,XTERM);
8003 LOP(OP_SPLICE,XTERM);
8018 LOP(OP_SUBSTR,XTERM);
8024 char tmpbuf[sizeof PL_tokenbuf];
8025 SSize_t tboffset = 0;
8026 expectation attrful;
8027 bool have_name, have_proto;
8028 const int key = tmp;
8033 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
8034 SV *subtoken = newSVpvn_flags(tstart, s - tstart, SvUTF8(PL_linestr));
8038 s = SKIPSPACE2(s,tmpwhite);
8043 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
8044 (*s == ':' && s[1] == ':'))
8047 SV *nametoke = NULL;
8051 attrful = XATTRBLOCK;
8052 /* remember buffer pos'n for later force_word */
8053 tboffset = s - PL_oldbufptr;
8054 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
8057 nametoke = newSVpvn_flags(s, d - s, SvUTF8(PL_linestr));
8059 if (memchr(tmpbuf, ':', len))
8060 sv_setpvn(PL_subname, tmpbuf, len);
8062 sv_setsv(PL_subname,PL_curstname);
8063 sv_catpvs(PL_subname,"::");
8064 sv_catpvn(PL_subname,tmpbuf,len);
8066 if (SvUTF8(PL_linestr))
8067 SvUTF8_on(PL_subname);
8073 CURMAD('X', nametoke);
8074 CURMAD('_', tmpwhite);
8075 (void) force_word(PL_oldbufptr + tboffset, WORD,
8078 s = SKIPSPACE2(d,tmpwhite);
8085 Perl_croak(aTHX_ "Missing name in \"my sub\"");
8086 PL_expect = XTERMBLOCK;
8087 attrful = XATTRTERM;
8088 sv_setpvs(PL_subname,"?");
8092 if (key == KEY_format) {
8094 PL_lex_formbrack = PL_lex_brackets + 1;
8096 PL_thistoken = subtoken;
8100 (void) force_word(PL_oldbufptr + tboffset, WORD,
8106 /* Look for a prototype */
8109 bool bad_proto = FALSE;
8110 bool in_brackets = FALSE;
8111 char greedy_proto = ' ';
8112 bool proto_after_greedy_proto = FALSE;
8113 bool must_be_last = FALSE;
8114 bool underscore = FALSE;
8115 bool seen_underscore = FALSE;
8116 const bool warnillegalproto = ckWARN(WARN_ILLEGALPROTO);
8119 s = scan_str(s,!!PL_madskills,FALSE);
8121 Perl_croak(aTHX_ "Prototype not terminated");
8122 /* strip spaces and check for bad characters */
8123 d = SvPV(PL_lex_stuff, tmplen);
8125 for (p = d; tmplen; tmplen--, ++p) {
8129 if (warnillegalproto) {
8131 proto_after_greedy_proto = TRUE;
8132 if (!strchr("$@%*;[]&\\_+", *p) || *p == '\0') {
8144 else if ( *p == ']' ) {
8145 in_brackets = FALSE;
8147 else if ( (*p == '@' || *p == '%') &&
8148 ( tmp < 2 || d[tmp-2] != '\\' ) &&
8150 must_be_last = TRUE;
8153 else if ( *p == '_' ) {
8154 underscore = seen_underscore = TRUE;
8161 if (proto_after_greedy_proto)
8162 Perl_warner(aTHX_ packWARN(WARN_ILLEGALPROTO),
8163 "Prototype after '%c' for %"SVf" : %s",
8164 greedy_proto, SVfARG(PL_subname), d);
8166 SV *dsv = newSVpvs_flags("", SVs_TEMP);
8167 Perl_warner(aTHX_ packWARN(WARN_ILLEGALPROTO),
8168 "Illegal character %sin prototype for %"SVf" : %s",
8169 seen_underscore ? "after '_' " : "",
8172 newSVpvn_flags(d, tmp, SVs_TEMP | SvUTF8(PL_lex_stuff)),
8173 tmp, UNI_DISPLAY_ISPRINT));
8175 SvCUR_set(PL_lex_stuff, tmp);
8180 CURMAD('q', PL_thisopen);
8181 CURMAD('_', tmpwhite);
8182 CURMAD('=', PL_thisstuff);
8183 CURMAD('Q', PL_thisclose);
8184 NEXTVAL_NEXTTOKE.opval =
8185 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
8186 PL_lex_stuff = NULL;
8189 s = SKIPSPACE2(s,tmpwhite);
8197 if (*s == ':' && s[1] != ':')
8198 PL_expect = attrful;
8199 else if (*s != '{' && key == KEY_sub) {
8201 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
8202 else if (*s != ';' && *s != '}')
8203 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
8210 curmad('^', newSVpvs(""));
8211 CURMAD('_', tmpwhite);
8215 PL_thistoken = subtoken;
8218 NEXTVAL_NEXTTOKE.opval =
8219 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
8220 PL_lex_stuff = NULL;
8226 sv_setpvs(PL_subname, "__ANON__");
8228 sv_setpvs(PL_subname, "__ANON__::__ANON__");
8232 (void) force_word(PL_oldbufptr + tboffset, WORD,
8241 LOP(OP_SYSTEM,XREF);
8244 LOP(OP_SYMLINK,XTERM);
8247 LOP(OP_SYSCALL,XTERM);
8250 LOP(OP_SYSOPEN,XTERM);
8253 LOP(OP_SYSSEEK,XTERM);
8256 LOP(OP_SYSREAD,XTERM);
8259 LOP(OP_SYSWRITE,XTERM);
8263 TERM(sublex_start());
8284 LOP(OP_TRUNCATE,XTERM);
8296 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR)
8298 pl_yylval.ival = CopLINE(PL_curcop);
8302 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR)
8304 pl_yylval.ival = CopLINE(PL_curcop);
8308 LOP(OP_UNLINK,XTERM);
8314 LOP(OP_UNPACK,XTERM);
8317 LOP(OP_UTIME,XTERM);
8323 LOP(OP_UNSHIFT,XTERM);
8326 s = tokenize_use(1, s);
8336 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR)
8338 pl_yylval.ival = CopLINE(PL_curcop);
8342 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR)
8344 pl_yylval.ival = CopLINE(PL_curcop);
8348 PL_hints |= HINT_BLOCK_SCOPE;
8355 LOP(OP_WAITPID,XTERM);
8364 ctl_l[0] = toCTRL('L');
8366 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
8369 /* Make sure $^L is defined */
8370 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
8375 if (PL_expect == XOPERATOR) {
8376 if (*s == '=' && !PL_lex_allbrackets &&
8377 PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN)
8385 if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_LOWLOGIC)
8387 pl_yylval.ival = OP_XOR;
8392 TERM(sublex_start());
8397 #pragma segment Main
8401 S_pending_ident(pTHX)
8406 /* pit holds the identifier we read and pending_ident is reset */
8407 char pit = PL_pending_ident;
8408 const STRLEN tokenbuf_len = strlen(PL_tokenbuf);
8409 /* All routes through this function want to know if there is a colon. */
8410 const char *const has_colon = (const char*) memchr (PL_tokenbuf, ':', tokenbuf_len);
8411 PL_pending_ident = 0;
8413 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
8414 DEBUG_T({ PerlIO_printf(Perl_debug_log,
8415 "### Pending identifier '%s'\n", PL_tokenbuf); });
8417 /* if we're in a my(), we can't allow dynamics here.
8418 $foo'bar has already been turned into $foo::bar, so
8419 just check for colons.
8421 if it's a legal name, the OP is a PADANY.
8424 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
8426 yyerror(Perl_form(aTHX_ "No package name allowed for "
8427 "variable %s in \"our\"",
8429 tmp = allocmy(PL_tokenbuf, tokenbuf_len, UTF ? SVf_UTF8 : 0);
8433 yyerror(Perl_form(aTHX_ PL_no_myglob,
8434 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
8436 pl_yylval.opval = newOP(OP_PADANY, 0);
8437 pl_yylval.opval->op_targ = allocmy(PL_tokenbuf, tokenbuf_len,
8438 UTF ? SVf_UTF8 : 0);
8444 build the ops for accesses to a my() variable.
8446 Deny my($a) or my($b) in a sort block, *if* $a or $b is
8447 then used in a comparison. This catches most, but not
8448 all cases. For instance, it catches
8449 sort { my($a); $a <=> $b }
8451 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
8452 (although why you'd do that is anyone's guess).
8457 tmp = pad_findmy_pvn(PL_tokenbuf, tokenbuf_len,
8458 UTF ? SVf_UTF8 : 0);
8459 if (tmp != NOT_IN_PAD) {
8460 /* might be an "our" variable" */
8461 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
8462 /* build ops for a bareword */
8463 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
8464 HEK * const stashname = HvNAME_HEK(stash);
8465 SV * const sym = newSVhek(stashname);
8466 sv_catpvs(sym, "::");
8467 sv_catpvn_flags(sym, PL_tokenbuf+1, tokenbuf_len - 1, (UTF ? SV_CATUTF8 : SV_CATBYTES ));
8468 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
8469 pl_yylval.opval->op_private = OPpCONST_ENTERED;
8472 ? (GV_ADDMULTI | GV_ADDINEVAL)
8475 ((PL_tokenbuf[0] == '$') ? SVt_PV
8476 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
8481 /* if it's a sort block and they're naming $a or $b */
8482 if (PL_last_lop_op == OP_SORT &&
8483 PL_tokenbuf[0] == '$' &&
8484 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
8487 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
8488 d < PL_bufend && *d != '\n';
8491 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
8492 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
8498 pl_yylval.opval = newOP(OP_PADANY, 0);
8499 pl_yylval.opval->op_targ = tmp;
8505 Whine if they've said @foo in a doublequoted string,
8506 and @foo isn't a variable we can find in the symbol
8509 if (ckWARN(WARN_AMBIGUOUS) &&
8510 pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
8511 GV *const gv = gv_fetchpvn_flags(PL_tokenbuf + 1, tokenbuf_len - 1,
8512 ( UTF ? SVf_UTF8 : 0 ), SVt_PVAV);
8513 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
8514 /* DO NOT warn for @- and @+ */
8515 && !( PL_tokenbuf[2] == '\0' &&
8516 ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
8519 /* Downgraded from fatal to warning 20000522 mjd */
8520 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
8521 "Possible unintended interpolation of %s in string",
8526 /* build ops for a bareword */
8527 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpvn_flags(PL_tokenbuf + 1,
8529 UTF ? SVf_UTF8 : 0 ));
8530 pl_yylval.opval->op_private = OPpCONST_ENTERED;
8531 gv_fetchpvn_flags(PL_tokenbuf+1, tokenbuf_len - 1,
8532 (PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD)
8533 | ( UTF ? SVf_UTF8 : 0 ),
8534 ((PL_tokenbuf[0] == '$') ? SVt_PV
8535 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
8541 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
8545 PERL_ARGS_ASSERT_CHECKCOMMA;
8547 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
8548 if (ckWARN(WARN_SYNTAX)) {
8551 for (w = s+2; *w && level; w++) {
8559 /* the list of chars below is for end of statements or
8560 * block / parens, boolean operators (&&, ||, //) and branch
8561 * constructs (or, and, if, until, unless, while, err, for).
8562 * Not a very solid hack... */
8563 if (!*w || !strchr(";&/|})]oaiuwef!=", *w))
8564 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
8565 "%s (...) interpreted as function",name);
8568 while (s < PL_bufend && isSPACE(*s))
8572 while (s < PL_bufend && isSPACE(*s))
8574 if (isIDFIRST_lazy_if(s,UTF)) {
8575 const char * const w = s++;
8576 while (isALNUM_lazy_if(s,UTF))
8578 while (s < PL_bufend && isSPACE(*s))
8582 if (keyword(w, s - w, 0))
8585 gv = gv_fetchpvn_flags(w, s - w, ( UTF ? SVf_UTF8 : 0 ), SVt_PVCV);
8586 if (gv && GvCVu(gv))
8588 Perl_croak(aTHX_ "No comma allowed after %s", what);
8593 /* Either returns sv, or mortalizes sv and returns a new SV*.
8594 Best used as sv=new_constant(..., sv, ...).
8595 If s, pv are NULL, calls subroutine with one argument,
8596 and type is used with error messages only. */
8599 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, STRLEN keylen,
8600 SV *sv, SV *pv, const char *type, STRLEN typelen)
8603 HV * const table = GvHV(PL_hintgv); /* ^H */
8607 const char *why1 = "", *why2 = "", *why3 = "";
8609 PERL_ARGS_ASSERT_NEW_CONSTANT;
8611 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
8614 why2 = (const char *)
8615 (strEQ(key,"charnames")
8616 ? "(possibly a missing \"use charnames ...\")"
8618 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
8619 (type ? type: "undef"), why2);
8621 /* This is convoluted and evil ("goto considered harmful")
8622 * but I do not understand the intricacies of all the different
8623 * failure modes of %^H in here. The goal here is to make
8624 * the most probable error message user-friendly. --jhi */
8629 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
8630 (type ? type: "undef"), why1, why2, why3);
8632 yyerror(SvPVX_const(msg));
8637 /* charnames doesn't work well if there have been errors found */
8638 if (PL_error_count > 0 && strEQ(key,"charnames"))
8639 return &PL_sv_undef;
8641 cvp = hv_fetch(table, key, keylen, FALSE);
8642 if (!cvp || !SvOK(*cvp)) {
8645 why3 = "} is not defined";
8648 sv_2mortal(sv); /* Parent created it permanently */
8651 pv = newSVpvn_flags(s, len, SVs_TEMP);
8653 typesv = newSVpvn_flags(type, typelen, SVs_TEMP);
8655 typesv = &PL_sv_undef;
8657 PUSHSTACKi(PERLSI_OVERLOAD);
8669 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
8673 /* Check the eval first */
8674 if (!PL_in_eval && SvTRUE(ERRSV)) {
8675 sv_catpvs(ERRSV, "Propagated");
8676 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
8678 res = SvREFCNT_inc_simple(sv);
8682 SvREFCNT_inc_simple_void(res);
8691 why1 = "Call to &{$^H{";
8693 why3 = "}} did not return a defined value";
8701 /* Returns a NUL terminated string, with the length of the string written to
8705 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
8708 register char *d = dest;
8709 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
8711 PERL_ARGS_ASSERT_SCAN_WORD;
8715 Perl_croak(aTHX_ ident_too_long);
8716 if (isALNUM(*s)) /* UTF handled below */
8718 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
8723 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
8727 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
8728 char *t = s + UTF8SKIP(s);
8730 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
8734 Perl_croak(aTHX_ ident_too_long);
8735 Copy(s, d, len, char);
8748 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
8751 char *bracket = NULL;
8753 register char *d = dest;
8754 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
8756 PERL_ARGS_ASSERT_SCAN_IDENT;
8761 while (isDIGIT(*s)) {
8763 Perl_croak(aTHX_ ident_too_long);
8770 Perl_croak(aTHX_ ident_too_long);
8771 if (isALNUM(*s)) /* UTF handled below */
8773 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
8778 else if (*s == ':' && s[1] == ':') {
8782 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
8783 char *t = s + UTF8SKIP(s);
8784 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
8786 if (d + (t - s) > e)
8787 Perl_croak(aTHX_ ident_too_long);
8788 Copy(s, d, t - s, char);
8799 if (PL_lex_state != LEX_NORMAL)
8800 PL_lex_state = LEX_INTERPENDMAYBE;
8803 if (*s == '$' && s[1] &&
8804 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
8816 const STRLEN skip = UTF8SKIP(s);
8819 for ( i = 0; i < skip; i++ )
8827 if (*d == '^' && *s && isCONTROLVAR(*s)) {
8832 if (isSPACE(s[-1])) {
8834 const char ch = *s++;
8835 if (!SPACE_OR_TAB(ch)) {
8841 if (isIDFIRST_lazy_if(d,UTF)) {
8845 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
8846 end += UTF8SKIP(end);
8847 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
8848 end += UTF8SKIP(end);
8850 Copy(s, d, end - s, char);
8855 while ((isALNUM(*s) || *s == ':') && d < e)
8858 Perl_croak(aTHX_ ident_too_long);
8861 while (s < send && SPACE_OR_TAB(*s))
8863 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
8864 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
8865 const char * const brack =
8867 ((*s == '[') ? "[...]" : "{...}");
8868 /* diag_listed_as: Ambiguous use of %c{%s[...]} resolved to %c%s[...] */
8869 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
8870 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
8871 funny, dest, brack, funny, dest, brack);
8874 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
8875 PL_lex_allbrackets++;
8879 /* Handle extended ${^Foo} variables
8880 * 1999-02-27 mjd-perl-patch@plover.com */
8881 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
8885 while (isALNUM(*s) && d < e) {
8889 Perl_croak(aTHX_ ident_too_long);
8894 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
8895 PL_lex_state = LEX_INTERPEND;
8898 if (PL_lex_state == LEX_NORMAL) {
8899 if (ckWARN(WARN_AMBIGUOUS) &&
8900 (keyword(dest, d - dest, 0)
8901 || get_cvn_flags(dest, d - dest, 0)))
8905 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
8906 "Ambiguous use of %c{%s} resolved to %c%s",
8907 funny, dest, funny, dest);
8912 s = bracket; /* let the parser handle it */
8916 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
8917 PL_lex_state = LEX_INTERPEND;
8922 S_pmflag(pTHX_ const char* const valid_flags, U32 * pmfl, char** s, char* charset) {
8924 /* Adds, subtracts to/from 'pmfl' based on regex modifier flags found in
8925 * the parse starting at 's', based on the subset that are valid in this
8926 * context input to this routine in 'valid_flags'. Advances s. Returns
8927 * TRUE if the input was a valid flag, so the next char may be as well;
8928 * otherwise FALSE. 'charset' should point to a NUL upon first call on the
8929 * current regex. This routine will set it to any charset modifier found.
8930 * The caller shouldn't change it. This way, another charset modifier
8931 * encountered in the parse can be detected as an error, as we have decided
8936 if (! strchr(valid_flags, c)) {
8945 CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl);
8946 case GLOBAL_PAT_MOD: *pmfl |= PMf_GLOBAL; break;
8947 case CONTINUE_PAT_MOD: *pmfl |= PMf_CONTINUE; break;
8948 case ONCE_PAT_MOD: *pmfl |= PMf_KEEP; break;
8949 case KEEPCOPY_PAT_MOD: *pmfl |= RXf_PMf_KEEPCOPY; break;
8950 case NONDESTRUCT_PAT_MOD: *pmfl |= PMf_NONDESTRUCT; break;
8951 case LOCALE_PAT_MOD:
8953 /* In 5.14, qr//lt is legal but deprecated; the 't' means they
8954 * can't be regex modifiers.
8955 * In 5.14, s///le is legal and ambiguous. Try to disambiguate as
8956 * much as easily done. s///lei, for example, has to mean regex
8957 * modifiers if it's not an error (as does any word character
8958 * following the 'e'). Otherwise, we resolve to the backwards-
8959 * compatible, but less likely 's/// le ...', i.e. as meaning
8960 * less-than-or-equal. The reason it's not likely is that s//
8961 * returns a number for code in the field (/r returns a string, but
8962 * that wasn't added until the 5.13 series), and so '<=' should be
8963 * used for comparing, not 'le'. */
8964 if (*((*s) + 1) == 't') {
8967 else if (*((*s) + 1) == 'e' && ! isALNUM(*((*s) + 2))) {
8969 /* 'e' is valid only for substitutes, s///e. If it is not
8970 * valid in the current context, then 'm//le' must mean the
8971 * comparison operator, so use the regular deprecation message.
8973 if (! strchr(valid_flags, 'e')) {
8976 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
8977 "Ambiguous use of 's//le...' resolved as 's// le...'; Rewrite as 's//el' if you meant 'use locale rules and evaluate rhs as an expression'. In Perl 5.16, it will be resolved the other way");
8981 goto multiple_charsets;
8983 set_regex_charset(pmfl, REGEX_LOCALE_CHARSET);
8986 case UNICODE_PAT_MOD:
8987 /* In 5.14, qr//unless and qr//until are legal but deprecated; the
8988 * 'n' means they can't be regex modifiers */
8989 if (*((*s) + 1) == 'n') {
8993 goto multiple_charsets;
8995 set_regex_charset(pmfl, REGEX_UNICODE_CHARSET);
8998 case ASCII_RESTRICT_PAT_MOD:
8999 /* In 5.14, qr//and is legal but deprecated; the 'n' means they
9000 * can't be regex modifiers */
9001 if (*((*s) + 1) == 'n') {
9006 set_regex_charset(pmfl, REGEX_ASCII_RESTRICTED_CHARSET);
9010 /* Error if previous modifier wasn't an 'a', but if it was, see
9011 * if, and accept, a second occurrence (only) */
9013 || get_regex_charset(*pmfl)
9014 != REGEX_ASCII_RESTRICTED_CHARSET)
9016 goto multiple_charsets;
9018 set_regex_charset(pmfl, REGEX_ASCII_MORE_RESTRICTED_CHARSET);
9022 case DEPENDS_PAT_MOD:
9024 goto multiple_charsets;
9026 set_regex_charset(pmfl, REGEX_DEPENDS_CHARSET);
9035 Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX),
9036 "Having no space between pattern and following word is deprecated");
9040 if (*charset != c) {
9041 yyerror(Perl_form(aTHX_ "Regexp modifiers \"/%c\" and \"/%c\" are mutually exclusive", *charset, c));
9043 else if (c == 'a') {
9044 yyerror("Regexp modifier \"/a\" may appear a maximum of twice");
9047 yyerror(Perl_form(aTHX_ "Regexp modifier \"/%c\" may not appear twice", c));
9050 /* Pretend that it worked, so will continue processing before dieing */
9056 S_scan_pat(pTHX_ char *start, I32 type)
9060 char *s = scan_str(start,!!PL_madskills,FALSE);
9061 const char * const valid_flags =
9062 (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
9063 char charset = '\0'; /* character set modifier */
9068 PERL_ARGS_ASSERT_SCAN_PAT;
9071 const char * const delimiter = skipspace(start);
9075 ? "Search pattern not terminated or ternary operator parsed as search pattern"
9076 : "Search pattern not terminated" ));
9079 pm = (PMOP*)newPMOP(type, 0);
9080 if (PL_multi_open == '?') {
9081 /* This is the only point in the code that sets PMf_ONCE: */
9082 pm->op_pmflags |= PMf_ONCE;
9084 /* Hence it's safe to do this bit of PMOP book-keeping here, which
9085 allows us to restrict the list needed by reset to just the ??
9087 assert(type != OP_TRANS);
9089 MAGIC *mg = mg_find((const SV *)PL_curstash, PERL_MAGIC_symtab);
9092 mg = sv_magicext(MUTABLE_SV(PL_curstash), 0, PERL_MAGIC_symtab, 0, 0,
9095 elements = mg->mg_len / sizeof(PMOP**);
9096 Renewc(mg->mg_ptr, elements + 1, PMOP*, char);
9097 ((PMOP**)mg->mg_ptr) [elements++] = pm;
9098 mg->mg_len = elements * sizeof(PMOP**);
9099 PmopSTASH_set(pm,PL_curstash);
9105 while (*s && S_pmflag(aTHX_ valid_flags, &(pm->op_pmflags), &s, &charset)) {};
9107 if (PL_madskills && modstart != s) {
9108 SV* tmptoken = newSVpvn(modstart, s - modstart);
9109 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
9112 /* issue a warning if /c is specified,but /g is not */
9113 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL))
9115 Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP),
9116 "Use of /c modifier is meaningless without /g" );
9119 PL_lex_op = (OP*)pm;
9120 pl_yylval.ival = OP_MATCH;
9125 S_scan_subst(pTHX_ char *start)
9132 char charset = '\0'; /* character set modifier */
9137 PERL_ARGS_ASSERT_SCAN_SUBST;
9139 pl_yylval.ival = OP_NULL;
9141 s = scan_str(start,!!PL_madskills,FALSE);
9144 Perl_croak(aTHX_ "Substitution pattern not terminated");
9146 if (s[-1] == PL_multi_open)
9150 CURMAD('q', PL_thisopen);
9151 CURMAD('_', PL_thiswhite);
9152 CURMAD('E', PL_thisstuff);
9153 CURMAD('Q', PL_thisclose);
9154 PL_realtokenstart = s - SvPVX(PL_linestr);
9158 first_start = PL_multi_start;
9159 s = scan_str(s,!!PL_madskills,FALSE);
9162 SvREFCNT_dec(PL_lex_stuff);
9163 PL_lex_stuff = NULL;
9165 Perl_croak(aTHX_ "Substitution replacement not terminated");
9167 PL_multi_start = first_start; /* so whole substitution is taken together */
9169 pm = (PMOP*)newPMOP(OP_SUBST, 0);
9173 CURMAD('z', PL_thisopen);
9174 CURMAD('R', PL_thisstuff);
9175 CURMAD('Z', PL_thisclose);
9181 if (*s == EXEC_PAT_MOD) {
9185 else if (! S_pmflag(aTHX_ S_PAT_MODS, &(pm->op_pmflags), &s, &charset))
9194 curmad('m', newSVpvn(modstart, s - modstart));
9195 append_madprops(PL_thismad, (OP*)pm, 0);
9199 if ((pm->op_pmflags & PMf_CONTINUE)) {
9200 Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
9204 SV * const repl = newSVpvs("");
9206 PL_sublex_info.super_bufptr = s;
9207 PL_sublex_info.super_bufend = PL_bufend;
9209 pm->op_pmflags |= PMf_EVAL;
9212 sv_catpvs(repl, "eval ");
9214 sv_catpvs(repl, "do ");
9216 sv_catpvs(repl, "{");
9217 sv_catsv(repl, PL_lex_repl);
9218 if (strchr(SvPVX(PL_lex_repl), '#'))
9219 sv_catpvs(repl, "\n");
9220 sv_catpvs(repl, "}");
9222 SvREFCNT_dec(PL_lex_repl);
9226 PL_lex_op = (OP*)pm;
9227 pl_yylval.ival = OP_SUBST;
9232 S_scan_trans(pTHX_ char *start)
9241 bool nondestruct = 0;
9246 PERL_ARGS_ASSERT_SCAN_TRANS;
9248 pl_yylval.ival = OP_NULL;
9250 s = scan_str(start,!!PL_madskills,FALSE);
9252 Perl_croak(aTHX_ "Transliteration pattern not terminated");
9254 if (s[-1] == PL_multi_open)
9258 CURMAD('q', PL_thisopen);
9259 CURMAD('_', PL_thiswhite);
9260 CURMAD('E', PL_thisstuff);
9261 CURMAD('Q', PL_thisclose);
9262 PL_realtokenstart = s - SvPVX(PL_linestr);
9266 s = scan_str(s,!!PL_madskills,FALSE);
9269 SvREFCNT_dec(PL_lex_stuff);
9270 PL_lex_stuff = NULL;
9272 Perl_croak(aTHX_ "Transliteration replacement not terminated");
9275 CURMAD('z', PL_thisopen);
9276 CURMAD('R', PL_thisstuff);
9277 CURMAD('Z', PL_thisclose);
9280 complement = del = squash = 0;
9287 complement = OPpTRANS_COMPLEMENT;
9290 del = OPpTRANS_DELETE;
9293 squash = OPpTRANS_SQUASH;
9305 tbl = (short *)PerlMemShared_calloc(complement&&!del?258:256, sizeof(short));
9306 o = newPVOP(nondestruct ? OP_TRANSR : OP_TRANS, 0, (char*)tbl);
9307 o->op_private &= ~OPpTRANS_ALL;
9308 o->op_private |= del|squash|complement|
9309 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
9310 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
9313 pl_yylval.ival = nondestruct ? OP_TRANSR : OP_TRANS;
9318 curmad('m', newSVpvn(modstart, s - modstart));
9319 append_madprops(PL_thismad, o, 0);
9328 S_scan_heredoc(pTHX_ register char *s)
9332 I32 op_type = OP_SCALAR;
9336 const char *found_newline;
9340 const int outer = (PL_rsfp || PL_parser->filtered)
9341 && !(PL_lex_inwhat == OP_SCALAR);
9343 I32 stuffstart = s - SvPVX(PL_linestr);
9346 PL_realtokenstart = -1;
9349 PERL_ARGS_ASSERT_SCAN_HEREDOC;
9353 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
9357 while (SPACE_OR_TAB(*peek))
9359 if (*peek == '`' || *peek == '\'' || *peek =='"') {
9362 s = delimcpy(d, e, s, PL_bufend, term, &len);
9372 if (!isALNUM_lazy_if(s,UTF))
9373 deprecate("bare << to mean <<\"\"");
9374 for (; isALNUM_lazy_if(s,UTF); s++) {
9379 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
9380 Perl_croak(aTHX_ "Delimiter for here document is too long");
9383 len = d - PL_tokenbuf;
9387 tstart = PL_tokenbuf + !outer;
9388 PL_thisclose = newSVpvn(tstart, len - !outer);
9389 tstart = SvPVX(PL_linestr) + stuffstart;
9390 PL_thisopen = newSVpvn(tstart, s - tstart);
9391 stuffstart = s - SvPVX(PL_linestr);
9394 #ifndef PERL_STRICT_CR
9395 d = strchr(s, '\r');
9397 char * const olds = s;
9399 while (s < PL_bufend) {
9405 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
9414 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
9421 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
9422 herewas = newSVpvn(s,PL_bufend-s);
9426 herewas = newSVpvn(s-1,found_newline-s+1);
9429 herewas = newSVpvn(s,found_newline-s);
9434 tstart = SvPVX(PL_linestr) + stuffstart;
9436 sv_catpvn(PL_thisstuff, tstart, s - tstart);
9438 PL_thisstuff = newSVpvn(tstart, s - tstart);
9441 s += SvCUR(herewas);
9444 stuffstart = s - SvPVX(PL_linestr);
9450 tmpstr = newSV_type(SVt_PVIV);
9454 SvIV_set(tmpstr, -1);
9456 else if (term == '`') {
9457 op_type = OP_BACKTICK;
9458 SvIV_set(tmpstr, '\\');
9462 PL_multi_start = CopLINE(PL_curcop);
9463 PL_multi_open = PL_multi_close = '<';
9464 term = *PL_tokenbuf;
9465 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp
9466 && !PL_parser->filtered) {
9467 char * const bufptr = PL_sublex_info.super_bufptr;
9468 char * const bufend = PL_sublex_info.super_bufend;
9469 char * const olds = s - SvCUR(herewas);
9470 s = strchr(bufptr, '\n');
9474 while (s < bufend &&
9475 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9477 CopLINE_inc(PL_curcop);
9480 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9481 missingterm(PL_tokenbuf);
9483 sv_setpvn(herewas,bufptr,d-bufptr+1);
9484 sv_setpvn(tmpstr,d+1,s-d);
9486 sv_catpvn(herewas,s,bufend-s);
9487 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
9494 while (s < PL_bufend &&
9495 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9497 CopLINE_inc(PL_curcop);
9499 if (s >= PL_bufend) {
9500 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9501 missingterm(PL_tokenbuf);
9503 sv_setpvn(tmpstr,d+1,s-d);
9507 sv_catpvn(PL_thisstuff, d + 1, s - d);
9509 PL_thisstuff = newSVpvn(d + 1, s - d);
9510 stuffstart = s - SvPVX(PL_linestr);
9514 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
9516 sv_catpvn(herewas,s,PL_bufend-s);
9517 sv_setsv(PL_linestr,herewas);
9518 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
9519 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9520 PL_last_lop = PL_last_uni = NULL;
9523 sv_setpvs(tmpstr,""); /* avoid "uninitialized" warning */
9524 while (s >= PL_bufend) { /* multiple line string? */
9527 tstart = SvPVX(PL_linestr) + stuffstart;
9529 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
9531 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
9535 CopLINE_inc(PL_curcop);
9536 if (!outer || !lex_next_chunk(0)) {
9537 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9538 missingterm(PL_tokenbuf);
9540 CopLINE_dec(PL_curcop);
9543 stuffstart = s - SvPVX(PL_linestr);
9545 CopLINE_inc(PL_curcop);
9546 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9547 PL_last_lop = PL_last_uni = NULL;
9548 #ifndef PERL_STRICT_CR
9549 if (PL_bufend - PL_linestart >= 2) {
9550 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
9551 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
9553 PL_bufend[-2] = '\n';
9555 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
9557 else if (PL_bufend[-1] == '\r')
9558 PL_bufend[-1] = '\n';
9560 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
9561 PL_bufend[-1] = '\n';
9563 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
9564 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
9565 *(SvPVX(PL_linestr) + off ) = ' ';
9566 lex_grow_linestr(SvCUR(PL_linestr) + SvCUR(herewas) + 1);
9567 sv_catsv(PL_linestr,herewas);
9568 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9569 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
9573 sv_catsv(tmpstr,PL_linestr);
9578 PL_multi_end = CopLINE(PL_curcop);
9579 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
9580 SvPV_shrink_to_cur(tmpstr);
9582 SvREFCNT_dec(herewas);
9584 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
9586 else if (PL_encoding)
9587 sv_recode_to_utf8(tmpstr, PL_encoding);
9589 PL_lex_stuff = tmpstr;
9590 pl_yylval.ival = op_type;
9595 takes: current position in input buffer
9596 returns: new position in input buffer
9597 side-effects: pl_yylval and lex_op are set.
9602 <FH> read from filehandle
9603 <pkg::FH> read from package qualified filehandle
9604 <pkg'FH> read from package qualified filehandle
9605 <$fh> read from filehandle in $fh
9611 S_scan_inputsymbol(pTHX_ char *start)
9614 register char *s = start; /* current position in buffer */
9617 char *d = PL_tokenbuf; /* start of temp holding space */
9618 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
9620 PERL_ARGS_ASSERT_SCAN_INPUTSYMBOL;
9622 end = strchr(s, '\n');
9625 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
9627 /* die if we didn't have space for the contents of the <>,
9628 or if it didn't end, or if we see a newline
9631 if (len >= (I32)sizeof PL_tokenbuf)
9632 Perl_croak(aTHX_ "Excessively long <> operator");
9634 Perl_croak(aTHX_ "Unterminated <> operator");
9639 Remember, only scalar variables are interpreted as filehandles by
9640 this code. Anything more complex (e.g., <$fh{$num}>) will be
9641 treated as a glob() call.
9642 This code makes use of the fact that except for the $ at the front,
9643 a scalar variable and a filehandle look the same.
9645 if (*d == '$' && d[1]) d++;
9647 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
9648 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
9649 d += UTF ? UTF8SKIP(d) : 1;
9651 /* If we've tried to read what we allow filehandles to look like, and
9652 there's still text left, then it must be a glob() and not a getline.
9653 Use scan_str to pull out the stuff between the <> and treat it
9654 as nothing more than a string.
9657 if (d - PL_tokenbuf != len) {
9658 pl_yylval.ival = OP_GLOB;
9659 s = scan_str(start,!!PL_madskills,FALSE);
9661 Perl_croak(aTHX_ "Glob not terminated");
9665 bool readline_overriden = FALSE;
9668 /* we're in a filehandle read situation */
9671 /* turn <> into <ARGV> */
9673 Copy("ARGV",d,5,char);
9675 /* Check whether readline() is overriden */
9676 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
9678 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
9680 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
9681 && (gv_readline = *gvp) && isGV_with_GP(gv_readline)
9682 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
9683 readline_overriden = TRUE;
9685 /* if <$fh>, create the ops to turn the variable into a
9689 /* try to find it in the pad for this block, otherwise find
9690 add symbol table ops
9692 const PADOFFSET tmp = pad_findmy_pvn(d, len, UTF ? SVf_UTF8 : 0);
9693 if (tmp != NOT_IN_PAD) {
9694 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
9695 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
9696 HEK * const stashname = HvNAME_HEK(stash);
9697 SV * const sym = sv_2mortal(newSVhek(stashname));
9698 sv_catpvs(sym, "::");
9704 OP * const o = newOP(OP_PADSV, 0);
9706 PL_lex_op = readline_overriden
9707 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9708 op_append_elem(OP_LIST, o,
9709 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
9710 : (OP*)newUNOP(OP_READLINE, 0, o);
9719 ? (GV_ADDMULTI | GV_ADDINEVAL)
9720 : GV_ADDMULTI) | ( UTF ? SVf_UTF8 : 0 ),
9722 PL_lex_op = readline_overriden
9723 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9724 op_append_elem(OP_LIST,
9725 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
9726 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9727 : (OP*)newUNOP(OP_READLINE, 0,
9728 newUNOP(OP_RV2SV, 0,
9729 newGVOP(OP_GV, 0, gv)));
9731 if (!readline_overriden)
9732 PL_lex_op->op_flags |= OPf_SPECIAL;
9733 /* we created the ops in PL_lex_op, so make pl_yylval.ival a null op */
9734 pl_yylval.ival = OP_NULL;
9737 /* If it's none of the above, it must be a literal filehandle
9738 (<Foo::BAR> or <FOO>) so build a simple readline OP */
9740 GV * const gv = gv_fetchpv(d, GV_ADD | ( UTF ? SVf_UTF8 : 0 ), SVt_PVIO);
9741 PL_lex_op = readline_overriden
9742 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9743 op_append_elem(OP_LIST,
9744 newGVOP(OP_GV, 0, gv),
9745 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9746 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
9747 pl_yylval.ival = OP_NULL;
9756 takes: start position in buffer
9757 keep_quoted preserve \ on the embedded delimiter(s)
9758 keep_delims preserve the delimiters around the string
9759 returns: position to continue reading from buffer
9760 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
9761 updates the read buffer.
9763 This subroutine pulls a string out of the input. It is called for:
9764 q single quotes q(literal text)
9765 ' single quotes 'literal text'
9766 qq double quotes qq(interpolate $here please)
9767 " double quotes "interpolate $here please"
9768 qx backticks qx(/bin/ls -l)
9769 ` backticks `/bin/ls -l`
9770 qw quote words @EXPORT_OK = qw( func() $spam )
9771 m// regexp match m/this/
9772 s/// regexp substitute s/this/that/
9773 tr/// string transliterate tr/this/that/
9774 y/// string transliterate y/this/that/
9775 ($*@) sub prototypes sub foo ($)
9776 (stuff) sub attr parameters sub foo : attr(stuff)
9777 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
9779 In most of these cases (all but <>, patterns and transliterate)
9780 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
9781 calls scan_str(). s/// makes yylex() call scan_subst() which calls
9782 scan_str(). tr/// and y/// make yylex() call scan_trans() which
9785 It skips whitespace before the string starts, and treats the first
9786 character as the delimiter. If the delimiter is one of ([{< then
9787 the corresponding "close" character )]}> is used as the closing
9788 delimiter. It allows quoting of delimiters, and if the string has
9789 balanced delimiters ([{<>}]) it allows nesting.
9791 On success, the SV with the resulting string is put into lex_stuff or,
9792 if that is already non-NULL, into lex_repl. The second case occurs only
9793 when parsing the RHS of the special constructs s/// and tr/// (y///).
9794 For convenience, the terminating delimiter character is stuffed into
9799 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
9802 SV *sv; /* scalar value: string */
9803 const char *tmps; /* temp string, used for delimiter matching */
9804 register char *s = start; /* current position in the buffer */
9805 register char term; /* terminating character */
9806 register char *to; /* current position in the sv's data */
9807 I32 brackets = 1; /* bracket nesting level */
9808 bool has_utf8 = FALSE; /* is there any utf8 content? */
9809 I32 termcode; /* terminating char. code */
9810 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
9811 STRLEN termlen; /* length of terminating string */
9812 int last_off = 0; /* last position for nesting bracket */
9818 PERL_ARGS_ASSERT_SCAN_STR;
9820 /* skip space before the delimiter */
9826 if (PL_realtokenstart >= 0) {
9827 stuffstart = PL_realtokenstart;
9828 PL_realtokenstart = -1;
9831 stuffstart = start - SvPVX(PL_linestr);
9833 /* mark where we are, in case we need to report errors */
9836 /* after skipping whitespace, the next character is the terminator */
9839 termcode = termstr[0] = term;
9843 termcode = utf8_to_uvchr((U8*)s, &termlen);
9844 Copy(s, termstr, termlen, U8);
9845 if (!UTF8_IS_INVARIANT(term))
9849 /* mark where we are */
9850 PL_multi_start = CopLINE(PL_curcop);
9851 PL_multi_open = term;
9853 /* find corresponding closing delimiter */
9854 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
9855 termcode = termstr[0] = term = tmps[5];
9857 PL_multi_close = term;
9859 /* create a new SV to hold the contents. 79 is the SV's initial length.
9860 What a random number. */
9861 sv = newSV_type(SVt_PVIV);
9863 SvIV_set(sv, termcode);
9864 (void)SvPOK_only(sv); /* validate pointer */
9866 /* move past delimiter and try to read a complete string */
9868 sv_catpvn(sv, s, termlen);
9871 tstart = SvPVX(PL_linestr) + stuffstart;
9872 if (!PL_thisopen && !keep_delims) {
9873 PL_thisopen = newSVpvn(tstart, s - tstart);
9874 stuffstart = s - SvPVX(PL_linestr);
9878 if (PL_encoding && !UTF) {
9882 int offset = s - SvPVX_const(PL_linestr);
9883 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
9884 &offset, (char*)termstr, termlen);
9885 const char * const ns = SvPVX_const(PL_linestr) + offset;
9886 char * const svlast = SvEND(sv) - 1;
9888 for (; s < ns; s++) {
9889 if (*s == '\n' && !PL_rsfp && !PL_parser->filtered)
9890 CopLINE_inc(PL_curcop);
9893 goto read_more_line;
9895 /* handle quoted delimiters */
9896 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
9898 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
9900 if ((svlast-1 - t) % 2) {
9904 SvCUR_set(sv, SvCUR(sv) - 1);
9909 if (PL_multi_open == PL_multi_close) {
9915 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
9916 /* At here, all closes are "was quoted" one,
9917 so we don't check PL_multi_close. */
9919 if (!keep_quoted && *(t+1) == PL_multi_open)
9924 else if (*t == PL_multi_open)
9932 SvCUR_set(sv, w - SvPVX_const(sv));
9934 last_off = w - SvPVX(sv);
9935 if (--brackets <= 0)
9941 SvCUR_set(sv, SvCUR(sv) - 1);
9947 /* extend sv if need be */
9948 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
9949 /* set 'to' to the next character in the sv's string */
9950 to = SvPVX(sv)+SvCUR(sv);
9952 /* if open delimiter is the close delimiter read unbridle */
9953 if (PL_multi_open == PL_multi_close) {
9954 for (; s < PL_bufend; s++,to++) {
9955 /* embedded newlines increment the current line number */
9956 if (*s == '\n' && !PL_rsfp && !PL_parser->filtered)
9957 CopLINE_inc(PL_curcop);
9958 /* handle quoted delimiters */
9959 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
9960 if (!keep_quoted && s[1] == term)
9962 /* any other quotes are simply copied straight through */
9966 /* terminate when run out of buffer (the for() condition), or
9967 have found the terminator */
9968 else if (*s == term) {
9971 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
9974 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
9980 /* if the terminator isn't the same as the start character (e.g.,
9981 matched brackets), we have to allow more in the quoting, and
9982 be prepared for nested brackets.
9985 /* read until we run out of string, or we find the terminator */
9986 for (; s < PL_bufend; s++,to++) {
9987 /* embedded newlines increment the line count */
9988 if (*s == '\n' && !PL_rsfp && !PL_parser->filtered)
9989 CopLINE_inc(PL_curcop);
9990 /* backslashes can escape the open or closing characters */
9991 if (*s == '\\' && s+1 < PL_bufend) {
9993 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
9998 /* allow nested opens and closes */
9999 else if (*s == PL_multi_close && --brackets <= 0)
10001 else if (*s == PL_multi_open)
10003 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
10008 /* terminate the copied string and update the sv's end-of-string */
10010 SvCUR_set(sv, to - SvPVX_const(sv));
10013 * this next chunk reads more into the buffer if we're not done yet
10017 break; /* handle case where we are done yet :-) */
10019 #ifndef PERL_STRICT_CR
10020 if (to - SvPVX_const(sv) >= 2) {
10021 if ((to[-2] == '\r' && to[-1] == '\n') ||
10022 (to[-2] == '\n' && to[-1] == '\r'))
10026 SvCUR_set(sv, to - SvPVX_const(sv));
10028 else if (to[-1] == '\r')
10031 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
10036 /* if we're out of file, or a read fails, bail and reset the current
10037 line marker so we can report where the unterminated string began
10040 if (PL_madskills) {
10041 char * const tstart = SvPVX(PL_linestr) + stuffstart;
10043 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
10045 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
10048 CopLINE_inc(PL_curcop);
10049 PL_bufptr = PL_bufend;
10050 if (!lex_next_chunk(0)) {
10052 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10061 /* at this point, we have successfully read the delimited string */
10063 if (!PL_encoding || UTF) {
10065 if (PL_madskills) {
10066 char * const tstart = SvPVX(PL_linestr) + stuffstart;
10067 const int len = s - tstart;
10069 sv_catpvn(PL_thisstuff, tstart, len);
10071 PL_thisstuff = newSVpvn(tstart, len);
10072 if (!PL_thisclose && !keep_delims)
10073 PL_thisclose = newSVpvn(s,termlen);
10078 sv_catpvn(sv, s, termlen);
10083 if (PL_madskills) {
10084 char * const tstart = SvPVX(PL_linestr) + stuffstart;
10085 const int len = s - tstart - termlen;
10087 sv_catpvn(PL_thisstuff, tstart, len);
10089 PL_thisstuff = newSVpvn(tstart, len);
10090 if (!PL_thisclose && !keep_delims)
10091 PL_thisclose = newSVpvn(s - termlen,termlen);
10095 if (has_utf8 || PL_encoding)
10098 PL_multi_end = CopLINE(PL_curcop);
10100 /* if we allocated too much space, give some back */
10101 if (SvCUR(sv) + 5 < SvLEN(sv)) {
10102 SvLEN_set(sv, SvCUR(sv) + 1);
10103 SvPV_renew(sv, SvLEN(sv));
10106 /* decide whether this is the first or second quoted string we've read
10119 takes: pointer to position in buffer
10120 returns: pointer to new position in buffer
10121 side-effects: builds ops for the constant in pl_yylval.op
10123 Read a number in any of the formats that Perl accepts:
10125 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
10126 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
10129 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
10131 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
10134 If it reads a number without a decimal point or an exponent, it will
10135 try converting the number to an integer and see if it can do so
10136 without loss of precision.
10140 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
10143 register const char *s = start; /* current position in buffer */
10144 register char *d; /* destination in temp buffer */
10145 register char *e; /* end of temp buffer */
10146 NV nv; /* number read, as a double */
10147 SV *sv = NULL; /* place to put the converted number */
10148 bool floatit; /* boolean: int or float? */
10149 const char *lastub = NULL; /* position of last underbar */
10150 static char const number_too_long[] = "Number too long";
10152 PERL_ARGS_ASSERT_SCAN_NUM;
10154 /* We use the first character to decide what type of number this is */
10158 Perl_croak(aTHX_ "panic: scan_num");
10160 /* if it starts with a 0, it could be an octal number, a decimal in
10161 0.13 disguise, or a hexadecimal number, or a binary number. */
10165 u holds the "number so far"
10166 shift the power of 2 of the base
10167 (hex == 4, octal == 3, binary == 1)
10168 overflowed was the number more than we can hold?
10170 Shift is used when we add a digit. It also serves as an "are
10171 we in octal/hex/binary?" indicator to disallow hex characters
10172 when in octal mode.
10177 bool overflowed = FALSE;
10178 bool just_zero = TRUE; /* just plain 0 or binary number? */
10179 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
10180 static const char* const bases[5] =
10181 { "", "binary", "", "octal", "hexadecimal" };
10182 static const char* const Bases[5] =
10183 { "", "Binary", "", "Octal", "Hexadecimal" };
10184 static const char* const maxima[5] =
10186 "0b11111111111111111111111111111111",
10190 const char *base, *Base, *max;
10192 /* check for hex */
10193 if (s[1] == 'x' || s[1] == 'X') {
10197 } else if (s[1] == 'b' || s[1] == 'B') {
10202 /* check for a decimal in disguise */
10203 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
10205 /* so it must be octal */
10212 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
10213 "Misplaced _ in number");
10217 base = bases[shift];
10218 Base = Bases[shift];
10219 max = maxima[shift];
10221 /* read the rest of the number */
10223 /* x is used in the overflow test,
10224 b is the digit we're adding on. */
10229 /* if we don't mention it, we're done */
10233 /* _ are ignored -- but warned about if consecutive */
10235 if (lastub && s == lastub + 1)
10236 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
10237 "Misplaced _ in number");
10241 /* 8 and 9 are not octal */
10242 case '8': case '9':
10244 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
10248 case '2': case '3': case '4':
10249 case '5': case '6': case '7':
10251 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
10254 case '0': case '1':
10255 b = *s++ & 15; /* ASCII digit -> value of digit */
10259 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
10260 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
10261 /* make sure they said 0x */
10264 b = (*s++ & 7) + 9;
10266 /* Prepare to put the digit we have onto the end
10267 of the number so far. We check for overflows.
10273 x = u << shift; /* make room for the digit */
10275 if ((x >> shift) != u
10276 && !(PL_hints & HINT_NEW_BINARY)) {
10279 Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW),
10280 "Integer overflow in %s number",
10283 u = x | b; /* add the digit to the end */
10286 n *= nvshift[shift];
10287 /* If an NV has not enough bits in its
10288 * mantissa to represent an UV this summing of
10289 * small low-order numbers is a waste of time
10290 * (because the NV cannot preserve the
10291 * low-order bits anyway): we could just
10292 * remember when did we overflow and in the
10293 * end just multiply n by the right
10301 /* if we get here, we had success: make a scalar value from
10306 /* final misplaced underbar check */
10307 if (s[-1] == '_') {
10308 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10312 if (n > 4294967295.0)
10313 Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
10314 "%s number > %s non-portable",
10320 if (u > 0xffffffff)
10321 Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
10322 "%s number > %s non-portable",
10327 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
10328 sv = new_constant(start, s - start, "integer",
10329 sv, NULL, NULL, 0);
10330 else if (PL_hints & HINT_NEW_BINARY)
10331 sv = new_constant(start, s - start, "binary", sv, NULL, NULL, 0);
10336 handle decimal numbers.
10337 we're also sent here when we read a 0 as the first digit
10339 case '1': case '2': case '3': case '4': case '5':
10340 case '6': case '7': case '8': case '9': case '.':
10343 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
10346 /* read next group of digits and _ and copy into d */
10347 while (isDIGIT(*s) || *s == '_') {
10348 /* skip underscores, checking for misplaced ones
10352 if (lastub && s == lastub + 1)
10353 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
10354 "Misplaced _ in number");
10358 /* check for end of fixed-length buffer */
10360 Perl_croak(aTHX_ number_too_long);
10361 /* if we're ok, copy the character */
10366 /* final misplaced underbar check */
10367 if (lastub && s == lastub + 1) {
10368 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10371 /* read a decimal portion if there is one. avoid
10372 3..5 being interpreted as the number 3. followed
10375 if (*s == '.' && s[1] != '.') {
10380 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
10381 "Misplaced _ in number");
10385 /* copy, ignoring underbars, until we run out of digits.
10387 for (; isDIGIT(*s) || *s == '_'; s++) {
10388 /* fixed length buffer check */
10390 Perl_croak(aTHX_ number_too_long);
10392 if (lastub && s == lastub + 1)
10393 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
10394 "Misplaced _ in number");
10400 /* fractional part ending in underbar? */
10401 if (s[-1] == '_') {
10402 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
10403 "Misplaced _ in number");
10405 if (*s == '.' && isDIGIT(s[1])) {
10406 /* oops, it's really a v-string, but without the "v" */
10412 /* read exponent part, if present */
10413 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
10417 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
10418 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
10420 /* stray preinitial _ */
10422 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
10423 "Misplaced _ in number");
10427 /* allow positive or negative exponent */
10428 if (*s == '+' || *s == '-')
10431 /* stray initial _ */
10433 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
10434 "Misplaced _ in number");
10438 /* read digits of exponent */
10439 while (isDIGIT(*s) || *s == '_') {
10442 Perl_croak(aTHX_ number_too_long);
10446 if (((lastub && s == lastub + 1) ||
10447 (!isDIGIT(s[1]) && s[1] != '_')))
10448 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
10449 "Misplaced _ in number");
10457 We try to do an integer conversion first if no characters
10458 indicating "float" have been found.
10463 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
10465 if (flags == IS_NUMBER_IN_UV) {
10467 sv = newSViv(uv); /* Prefer IVs over UVs. */
10470 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
10471 if (uv <= (UV) IV_MIN)
10472 sv = newSViv(-(IV)uv);
10479 /* terminate the string */
10481 nv = Atof(PL_tokenbuf);
10486 ? (PL_hints & HINT_NEW_FLOAT) : (PL_hints & HINT_NEW_INTEGER) ) {
10487 const char *const key = floatit ? "float" : "integer";
10488 const STRLEN keylen = floatit ? 5 : 7;
10489 sv = S_new_constant(aTHX_ PL_tokenbuf, d - PL_tokenbuf,
10490 key, keylen, sv, NULL, NULL, 0);
10494 /* if it starts with a v, it could be a v-string */
10497 sv = newSV(5); /* preallocate storage space */
10498 s = scan_vstring(s, PL_bufend, sv);
10502 /* make the op for the constant and return */
10505 lvalp->opval = newSVOP(OP_CONST, 0, sv);
10507 lvalp->opval = NULL;
10513 S_scan_formline(pTHX_ register char *s)
10516 register char *eol;
10518 SV * const stuff = newSVpvs("");
10519 bool needargs = FALSE;
10520 bool eofmt = FALSE;
10522 char *tokenstart = s;
10523 SV* savewhite = NULL;
10525 if (PL_madskills) {
10526 savewhite = PL_thiswhite;
10531 PERL_ARGS_ASSERT_SCAN_FORMLINE;
10533 while (!needargs) {
10536 #ifdef PERL_STRICT_CR
10537 while (SPACE_OR_TAB(*t))
10540 while (SPACE_OR_TAB(*t) || *t == '\r')
10543 if (*t == '\n' || t == PL_bufend) {
10548 if (PL_in_eval && !PL_rsfp && !PL_parser->filtered) {
10549 eol = (char *) memchr(s,'\n',PL_bufend-s);
10554 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10556 for (t = s; t < eol; t++) {
10557 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
10559 goto enough; /* ~~ must be first line in formline */
10561 if (*t == '@' || *t == '^')
10565 sv_catpvn(stuff, s, eol-s);
10566 #ifndef PERL_STRICT_CR
10567 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
10568 char *end = SvPVX(stuff) + SvCUR(stuff);
10571 SvCUR_set(stuff, SvCUR(stuff) - 1);
10579 if (PL_rsfp || PL_parser->filtered) {
10582 if (PL_madskills) {
10584 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
10586 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
10589 PL_bufptr = PL_bufend;
10590 CopLINE_inc(PL_curcop);
10591 got_some = lex_next_chunk(0);
10592 CopLINE_dec(PL_curcop);
10595 tokenstart = PL_bufptr;
10603 if (SvCUR(stuff)) {
10606 PL_lex_state = LEX_NORMAL;
10607 start_force(PL_curforce);
10608 NEXTVAL_NEXTTOKE.ival = 0;
10612 PL_lex_state = LEX_FORMLINE;
10614 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
10616 else if (PL_encoding)
10617 sv_recode_to_utf8(stuff, PL_encoding);
10619 start_force(PL_curforce);
10620 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
10622 start_force(PL_curforce);
10623 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
10627 SvREFCNT_dec(stuff);
10629 PL_lex_formbrack = 0;
10633 if (PL_madskills) {
10635 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
10637 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
10638 PL_thiswhite = savewhite;
10645 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
10648 const I32 oldsavestack_ix = PL_savestack_ix;
10649 CV* const outsidecv = PL_compcv;
10652 assert(SvTYPE(PL_compcv) == SVt_PVCV);
10654 SAVEI32(PL_subline);
10655 save_item(PL_subname);
10656 SAVESPTR(PL_compcv);
10658 PL_compcv = MUTABLE_CV(newSV_type(is_format ? SVt_PVFM : SVt_PVCV));
10659 CvFLAGS(PL_compcv) |= flags;
10661 PL_subline = CopLINE(PL_curcop);
10662 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
10663 CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outsidecv));
10664 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
10666 return oldsavestack_ix;
10670 #pragma segment Perl_yylex
10673 S_yywarn(pTHX_ const char *const s)
10677 PERL_ARGS_ASSERT_YYWARN;
10679 PL_in_eval |= EVAL_WARNONLY;
10681 PL_in_eval &= ~EVAL_WARNONLY;
10686 Perl_yyerror(pTHX_ const char *const s)
10689 const char *where = NULL;
10690 const char *context = NULL;
10693 int yychar = PL_parser->yychar;
10695 PERL_ARGS_ASSERT_YYERROR;
10697 if (!yychar || (yychar == ';' && !PL_rsfp))
10699 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
10700 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
10701 PL_oldbufptr != PL_bufptr) {
10704 The code below is removed for NetWare because it abends/crashes on NetWare
10705 when the script has error such as not having the closing quotes like:
10706 if ($var eq "value)
10707 Checking of white spaces is anyway done in NetWare code.
10710 while (isSPACE(*PL_oldoldbufptr))
10713 context = PL_oldoldbufptr;
10714 contlen = PL_bufptr - PL_oldoldbufptr;
10716 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
10717 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
10720 The code below is removed for NetWare because it abends/crashes on NetWare
10721 when the script has error such as not having the closing quotes like:
10722 if ($var eq "value)
10723 Checking of white spaces is anyway done in NetWare code.
10726 while (isSPACE(*PL_oldbufptr))
10729 context = PL_oldbufptr;
10730 contlen = PL_bufptr - PL_oldbufptr;
10732 else if (yychar > 255)
10733 where = "next token ???";
10734 else if (yychar == -2) { /* YYEMPTY */
10735 if (PL_lex_state == LEX_NORMAL ||
10736 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
10737 where = "at end of line";
10738 else if (PL_lex_inpat)
10739 where = "within pattern";
10741 where = "within string";
10744 SV * const where_sv = newSVpvs_flags("next char ", SVs_TEMP);
10746 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
10747 else if (isPRINT_LC(yychar)) {
10748 const char string = yychar;
10749 sv_catpvn(where_sv, &string, 1);
10752 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
10753 where = SvPVX_const(where_sv);
10755 msg = sv_2mortal(newSVpv(s, 0));
10756 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
10757 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
10759 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
10761 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
10762 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
10763 Perl_sv_catpvf(aTHX_ msg,
10764 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
10765 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
10768 if (PL_in_eval & EVAL_WARNONLY) {
10769 Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
10773 if (PL_error_count >= 10) {
10774 if (PL_in_eval && SvCUR(ERRSV))
10775 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
10776 SVfARG(ERRSV), OutCopFILE(PL_curcop));
10778 Perl_croak(aTHX_ "%s has too many errors.\n",
10779 OutCopFILE(PL_curcop));
10782 PL_in_my_stash = NULL;
10786 #pragma segment Main
10790 S_swallow_bom(pTHX_ U8 *s)
10793 const STRLEN slen = SvCUR(PL_linestr);
10795 PERL_ARGS_ASSERT_SWALLOW_BOM;
10799 if (s[1] == 0xFE) {
10800 /* UTF-16 little-endian? (or UTF-32LE?) */
10801 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
10802 Perl_croak(aTHX_ "Unsupported script encoding UTF-32LE");
10803 #ifndef PERL_NO_UTF16_FILTER
10804 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (BOM)\n");
10806 if (PL_bufend > (char*)s) {
10807 s = add_utf16_textfilter(s, TRUE);
10810 Perl_croak(aTHX_ "Unsupported script encoding UTF-16LE");
10815 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
10816 #ifndef PERL_NO_UTF16_FILTER
10817 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
10819 if (PL_bufend > (char *)s) {
10820 s = add_utf16_textfilter(s, FALSE);
10823 Perl_croak(aTHX_ "Unsupported script encoding UTF-16BE");
10828 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
10829 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
10830 s += 3; /* UTF-8 */
10836 if (s[2] == 0xFE && s[3] == 0xFF) {
10837 /* UTF-32 big-endian */
10838 Perl_croak(aTHX_ "Unsupported script encoding UTF-32BE");
10841 else if (s[2] == 0 && s[3] != 0) {
10844 * are a good indicator of UTF-16BE. */
10845 #ifndef PERL_NO_UTF16_FILTER
10846 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
10847 s = add_utf16_textfilter(s, FALSE);
10849 Perl_croak(aTHX_ "Unsupported script encoding UTF-16BE");
10855 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
10856 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
10857 s += 4; /* UTF-8 */
10863 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
10866 * are a good indicator of UTF-16LE. */
10867 #ifndef PERL_NO_UTF16_FILTER
10868 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
10869 s = add_utf16_textfilter(s, TRUE);
10871 Perl_croak(aTHX_ "Unsupported script encoding UTF-16LE");
10879 #ifndef PERL_NO_UTF16_FILTER
10881 S_utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
10884 SV *const filter = FILTER_DATA(idx);
10885 /* We re-use this each time round, throwing the contents away before we
10887 SV *const utf16_buffer = MUTABLE_SV(IoTOP_GV(filter));
10888 SV *const utf8_buffer = filter;
10889 IV status = IoPAGE(filter);
10890 const bool reverse = cBOOL(IoLINES(filter));
10893 PERL_ARGS_ASSERT_UTF16_TEXTFILTER;
10895 /* As we're automatically added, at the lowest level, and hence only called
10896 from this file, we can be sure that we're not called in block mode. Hence
10897 don't bother writing code to deal with block mode. */
10899 Perl_croak(aTHX_ "panic: utf16_textfilter called in block mode (for %d characters)", maxlen);
10902 Perl_croak(aTHX_ "panic: utf16_textfilter called after error (status=%"IVdf")", status);
10904 DEBUG_P(PerlIO_printf(Perl_debug_log,
10905 "utf16_textfilter(%p,%ce): idx=%d maxlen=%d status=%"IVdf" utf16=%"UVuf" utf8=%"UVuf"\n",
10906 FPTR2DPTR(void *, S_utf16_textfilter),
10907 reverse ? 'l' : 'b', idx, maxlen, status,
10908 (UV)SvCUR(utf16_buffer), (UV)SvCUR(utf8_buffer)));
10915 /* First, look in our buffer of existing UTF-8 data: */
10916 char *nl = (char *)memchr(SvPVX(utf8_buffer), '\n', SvCUR(utf8_buffer));
10920 } else if (status == 0) {
10922 IoPAGE(filter) = 0;
10923 nl = SvEND(utf8_buffer);
10926 STRLEN got = nl - SvPVX(utf8_buffer);
10927 /* Did we have anything to append? */
10929 sv_catpvn(sv, SvPVX(utf8_buffer), got);
10930 /* Everything else in this code works just fine if SVp_POK isn't
10931 set. This, however, needs it, and we need it to work, else
10932 we loop infinitely because the buffer is never consumed. */
10933 sv_chop(utf8_buffer, nl);
10937 /* OK, not a complete line there, so need to read some more UTF-16.
10938 Read an extra octect if the buffer currently has an odd number. */
10942 if (SvCUR(utf16_buffer) >= 2) {
10943 /* Location of the high octet of the last complete code point.
10944 Gosh, UTF-16 is a pain. All the benefits of variable length,
10945 *coupled* with all the benefits of partial reads and
10947 const U8 *const last_hi = (U8*)SvPVX(utf16_buffer)
10948 + ((SvCUR(utf16_buffer) & ~1) - (reverse ? 1 : 2));
10950 if (*last_hi < 0xd8 || *last_hi > 0xdb) {
10954 /* We have the first half of a surrogate. Read more. */
10955 DEBUG_P(PerlIO_printf(Perl_debug_log, "utf16_textfilter partial surrogate detected at %p\n", last_hi));
10958 status = FILTER_READ(idx + 1, utf16_buffer,
10959 160 + (SvCUR(utf16_buffer) & 1));
10960 DEBUG_P(PerlIO_printf(Perl_debug_log, "utf16_textfilter status=%"IVdf" SvCUR(sv)=%"UVuf"\n", status, (UV)SvCUR(utf16_buffer)));
10961 DEBUG_P({ sv_dump(utf16_buffer); sv_dump(utf8_buffer);});
10964 IoPAGE(filter) = status;
10969 chars = SvCUR(utf16_buffer) >> 1;
10970 have = SvCUR(utf8_buffer);
10971 SvGROW(utf8_buffer, have + chars * 3 + 1);
10974 end = utf16_to_utf8_reversed((U8*)SvPVX(utf16_buffer),
10975 (U8*)SvPVX_const(utf8_buffer) + have,
10976 chars * 2, &newlen);
10978 end = utf16_to_utf8((U8*)SvPVX(utf16_buffer),
10979 (U8*)SvPVX_const(utf8_buffer) + have,
10980 chars * 2, &newlen);
10982 SvCUR_set(utf8_buffer, have + newlen);
10985 /* No need to keep this SV "well-formed" with a '\0' after the end, as
10986 it's private to us, and utf16_to_utf8{,reversed} take a
10987 (pointer,length) pair, rather than a NUL-terminated string. */
10988 if(SvCUR(utf16_buffer) & 1) {
10989 *SvPVX(utf16_buffer) = SvEND(utf16_buffer)[-1];
10990 SvCUR_set(utf16_buffer, 1);
10992 SvCUR_set(utf16_buffer, 0);
10995 DEBUG_P(PerlIO_printf(Perl_debug_log,
10996 "utf16_textfilter: returns, status=%"IVdf" utf16=%"UVuf" utf8=%"UVuf"\n",
10998 (UV)SvCUR(utf16_buffer), (UV)SvCUR(utf8_buffer)));
10999 DEBUG_P({ sv_dump(utf8_buffer); sv_dump(sv);});
11004 S_add_utf16_textfilter(pTHX_ U8 *const s, bool reversed)
11006 SV *filter = filter_add(S_utf16_textfilter, NULL);
11008 PERL_ARGS_ASSERT_ADD_UTF16_TEXTFILTER;
11010 IoTOP_GV(filter) = MUTABLE_GV(newSVpvn((char *)s, PL_bufend - (char*)s));
11011 sv_setpvs(filter, "");
11012 IoLINES(filter) = reversed;
11013 IoPAGE(filter) = 1; /* Not EOF */
11015 /* Sadly, we have to return a valid pointer, come what may, so we have to
11016 ignore any error return from this. */
11017 SvCUR_set(PL_linestr, 0);
11018 if (FILTER_READ(0, PL_linestr, 0)) {
11019 SvUTF8_on(PL_linestr);
11021 SvUTF8_on(PL_linestr);
11023 PL_bufend = SvEND(PL_linestr);
11024 return (U8*)SvPVX(PL_linestr);
11029 Returns a pointer to the next character after the parsed
11030 vstring, as well as updating the passed in sv.
11032 Function must be called like
11035 s = scan_vstring(s,e,sv);
11037 where s and e are the start and end of the string.
11038 The sv should already be large enough to store the vstring
11039 passed in, for performance reasons.
11044 Perl_scan_vstring(pTHX_ const char *s, const char *const e, SV *sv)
11047 const char *pos = s;
11048 const char *start = s;
11050 PERL_ARGS_ASSERT_SCAN_VSTRING;
11052 if (*pos == 'v') pos++; /* get past 'v' */
11053 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
11055 if ( *pos != '.') {
11056 /* this may not be a v-string if followed by => */
11057 const char *next = pos;
11058 while (next < e && isSPACE(*next))
11060 if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
11061 /* return string not v-string */
11062 sv_setpvn(sv,(char *)s,pos-s);
11063 return (char *)pos;
11067 if (!isALPHA(*pos)) {
11068 U8 tmpbuf[UTF8_MAXBYTES+1];
11071 s++; /* get past 'v' */
11076 /* this is atoi() that tolerates underscores */
11079 const char *end = pos;
11081 while (--end >= s) {
11083 const UV orev = rev;
11084 rev += (*end - '0') * mult;
11087 Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW),
11088 "Integer overflow in decimal number");
11092 if (rev > 0x7FFFFFFF)
11093 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
11095 /* Append native character for the rev point */
11096 tmpend = uvchr_to_utf8(tmpbuf, rev);
11097 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
11098 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
11100 if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
11106 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
11110 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
11117 Perl_keyword_plugin_standard(pTHX_
11118 char *keyword_ptr, STRLEN keyword_len, OP **op_ptr)
11120 PERL_ARGS_ASSERT_KEYWORD_PLUGIN_STANDARD;
11121 PERL_UNUSED_CONTEXT;
11122 PERL_UNUSED_ARG(keyword_ptr);
11123 PERL_UNUSED_ARG(keyword_len);
11124 PERL_UNUSED_ARG(op_ptr);
11125 return KEYWORD_PLUGIN_DECLINE;
11128 #define parse_recdescent(g,p) S_parse_recdescent(aTHX_ g,p)
11130 S_parse_recdescent(pTHX_ int gramtype, I32 fakeeof)
11132 SAVEI32(PL_lex_brackets);
11133 if (PL_lex_brackets > 100)
11134 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
11135 PL_lex_brackstack[PL_lex_brackets++] = XFAKEEOF;
11136 SAVEI32(PL_lex_allbrackets);
11137 PL_lex_allbrackets = 0;
11138 SAVEI8(PL_lex_fakeeof);
11139 PL_lex_fakeeof = (U8)fakeeof;
11140 if(yyparse(gramtype) && !PL_parser->error_count)
11141 qerror(Perl_mess(aTHX_ "Parse error"));
11144 #define parse_recdescent_for_op(g,p) S_parse_recdescent_for_op(aTHX_ g,p)
11146 S_parse_recdescent_for_op(pTHX_ int gramtype, I32 fakeeof)
11150 SAVEVPTR(PL_eval_root);
11151 PL_eval_root = NULL;
11152 parse_recdescent(gramtype, fakeeof);
11158 #define parse_expr(p,f) S_parse_expr(aTHX_ p,f)
11160 S_parse_expr(pTHX_ I32 fakeeof, U32 flags)
11163 if (flags & ~PARSE_OPTIONAL)
11164 Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_expr");
11165 exprop = parse_recdescent_for_op(GRAMEXPR, fakeeof);
11166 if (!exprop && !(flags & PARSE_OPTIONAL)) {
11167 if (!PL_parser->error_count)
11168 qerror(Perl_mess(aTHX_ "Parse error"));
11169 exprop = newOP(OP_NULL, 0);
11175 =for apidoc Amx|OP *|parse_arithexpr|U32 flags
11177 Parse a Perl arithmetic expression. This may contain operators of precedence
11178 down to the bit shift operators. The expression must be followed (and thus
11179 terminated) either by a comparison or lower-precedence operator or by
11180 something that would normally terminate an expression such as semicolon.
11181 If I<flags> includes C<PARSE_OPTIONAL> then the expression is optional,
11182 otherwise it is mandatory. It is up to the caller to ensure that the
11183 dynamic parser state (L</PL_parser> et al) is correctly set to reflect
11184 the source of the code to be parsed and the lexical context for the
11187 The op tree representing the expression is returned. If an optional
11188 expression is absent, a null pointer is returned, otherwise the pointer
11191 If an error occurs in parsing or compilation, in most cases a valid op
11192 tree is returned anyway. The error is reflected in the parser state,
11193 normally resulting in a single exception at the top level of parsing
11194 which covers all the compilation errors that occurred. Some compilation
11195 errors, however, will throw an exception immediately.
11201 Perl_parse_arithexpr(pTHX_ U32 flags)
11203 return parse_expr(LEX_FAKEEOF_COMPARE, flags);
11207 =for apidoc Amx|OP *|parse_termexpr|U32 flags
11209 Parse a Perl term expression. This may contain operators of precedence
11210 down to the assignment operators. The expression must be followed (and thus
11211 terminated) either by a comma or lower-precedence operator or by
11212 something that would normally terminate an expression such as semicolon.
11213 If I<flags> includes C<PARSE_OPTIONAL> then the expression is optional,
11214 otherwise it is mandatory. It is up to the caller to ensure that the
11215 dynamic parser state (L</PL_parser> et al) is correctly set to reflect
11216 the source of the code to be parsed and the lexical context for the
11219 The op tree representing the expression is returned. If an optional
11220 expression is absent, a null pointer is returned, otherwise the pointer
11223 If an error occurs in parsing or compilation, in most cases a valid op
11224 tree is returned anyway. The error is reflected in the parser state,
11225 normally resulting in a single exception at the top level of parsing
11226 which covers all the compilation errors that occurred. Some compilation
11227 errors, however, will throw an exception immediately.
11233 Perl_parse_termexpr(pTHX_ U32 flags)
11235 return parse_expr(LEX_FAKEEOF_COMMA, flags);
11239 =for apidoc Amx|OP *|parse_listexpr|U32 flags
11241 Parse a Perl list expression. This may contain operators of precedence
11242 down to the comma operator. The expression must be followed (and thus
11243 terminated) either by a low-precedence logic operator such as C<or> or by
11244 something that would normally terminate an expression such as semicolon.
11245 If I<flags> includes C<PARSE_OPTIONAL> then the expression is optional,
11246 otherwise it is mandatory. It is up to the caller to ensure that the
11247 dynamic parser state (L</PL_parser> et al) is correctly set to reflect
11248 the source of the code to be parsed and the lexical context for the
11251 The op tree representing the expression is returned. If an optional
11252 expression is absent, a null pointer is returned, otherwise the pointer
11255 If an error occurs in parsing or compilation, in most cases a valid op
11256 tree is returned anyway. The error is reflected in the parser state,
11257 normally resulting in a single exception at the top level of parsing
11258 which covers all the compilation errors that occurred. Some compilation
11259 errors, however, will throw an exception immediately.
11265 Perl_parse_listexpr(pTHX_ U32 flags)
11267 return parse_expr(LEX_FAKEEOF_LOWLOGIC, flags);
11271 =for apidoc Amx|OP *|parse_fullexpr|U32 flags
11273 Parse a single complete Perl expression. This allows the full
11274 expression grammar, including the lowest-precedence operators such
11275 as C<or>. The expression must be followed (and thus terminated) by a
11276 token that an expression would normally be terminated by: end-of-file,
11277 closing bracketing punctuation, semicolon, or one of the keywords that
11278 signals a postfix expression-statement modifier. If I<flags> includes
11279 C<PARSE_OPTIONAL> then the expression is optional, otherwise it is
11280 mandatory. It is up to the caller to ensure that the dynamic parser
11281 state (L</PL_parser> et al) is correctly set to reflect the source of
11282 the code to be parsed and the lexical context for the expression.
11284 The op tree representing the expression is returned. If an optional
11285 expression is absent, a null pointer is returned, otherwise the pointer
11288 If an error occurs in parsing or compilation, in most cases a valid op
11289 tree is returned anyway. The error is reflected in the parser state,
11290 normally resulting in a single exception at the top level of parsing
11291 which covers all the compilation errors that occurred. Some compilation
11292 errors, however, will throw an exception immediately.
11298 Perl_parse_fullexpr(pTHX_ U32 flags)
11300 return parse_expr(LEX_FAKEEOF_NONEXPR, flags);
11304 =for apidoc Amx|OP *|parse_block|U32 flags
11306 Parse a single complete Perl code block. This consists of an opening
11307 brace, a sequence of statements, and a closing brace. The block
11308 constitutes a lexical scope, so C<my> variables and various compile-time
11309 effects can be contained within it. It is up to the caller to ensure
11310 that the dynamic parser state (L</PL_parser> et al) is correctly set to
11311 reflect the source of the code to be parsed and the lexical context for
11314 The op tree representing the code block is returned. This is always a
11315 real op, never a null pointer. It will normally be a C<lineseq> list,
11316 including C<nextstate> or equivalent ops. No ops to construct any kind
11317 of runtime scope are included by virtue of it being a block.
11319 If an error occurs in parsing or compilation, in most cases a valid op
11320 tree (most likely null) is returned anyway. The error is reflected in
11321 the parser state, normally resulting in a single exception at the top
11322 level of parsing which covers all the compilation errors that occurred.
11323 Some compilation errors, however, will throw an exception immediately.
11325 The I<flags> parameter is reserved for future use, and must always
11332 Perl_parse_block(pTHX_ U32 flags)
11335 Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_block");
11336 return parse_recdescent_for_op(GRAMBLOCK, LEX_FAKEEOF_NEVER);
11340 =for apidoc Amx|OP *|parse_barestmt|U32 flags
11342 Parse a single unadorned Perl statement. This may be a normal imperative
11343 statement or a declaration that has compile-time effect. It does not
11344 include any label or other affixture. It is up to the caller to ensure
11345 that the dynamic parser state (L</PL_parser> et al) is correctly set to
11346 reflect the source of the code to be parsed and the lexical context for
11349 The op tree representing the statement is returned. This may be a
11350 null pointer if the statement is null, for example if it was actually
11351 a subroutine definition (which has compile-time side effects). If not
11352 null, it will be ops directly implementing the statement, suitable to
11353 pass to L</newSTATEOP>. It will not normally include a C<nextstate> or
11354 equivalent op (except for those embedded in a scope contained entirely
11355 within the statement).
11357 If an error occurs in parsing or compilation, in most cases a valid op
11358 tree (most likely null) is returned anyway. The error is reflected in
11359 the parser state, normally resulting in a single exception at the top
11360 level of parsing which covers all the compilation errors that occurred.
11361 Some compilation errors, however, will throw an exception immediately.
11363 The I<flags> parameter is reserved for future use, and must always
11370 Perl_parse_barestmt(pTHX_ U32 flags)
11373 Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_barestmt");
11374 return parse_recdescent_for_op(GRAMBARESTMT, LEX_FAKEEOF_NEVER);
11378 =for apidoc Amx|SV *|parse_label|U32 flags
11380 Parse a single label, possibly optional, of the type that may prefix a
11381 Perl statement. It is up to the caller to ensure that the dynamic parser
11382 state (L</PL_parser> et al) is correctly set to reflect the source of
11383 the code to be parsed. If I<flags> includes C<PARSE_OPTIONAL> then the
11384 label is optional, otherwise it is mandatory.
11386 The name of the label is returned in the form of a fresh scalar. If an
11387 optional label is absent, a null pointer is returned.
11389 If an error occurs in parsing, which can only occur if the label is
11390 mandatory, a valid label is returned anyway. The error is reflected in
11391 the parser state, normally resulting in a single exception at the top
11392 level of parsing which covers all the compilation errors that occurred.
11398 Perl_parse_label(pTHX_ U32 flags)
11400 if (flags & ~PARSE_OPTIONAL)
11401 Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_label");
11402 if (PL_lex_state == LEX_KNOWNEXT) {
11403 PL_parser->yychar = yylex();
11404 if (PL_parser->yychar == LABEL) {
11405 char *lpv = pl_yylval.pval;
11406 STRLEN llen = strlen(lpv);
11408 PL_parser->yychar = YYEMPTY;
11409 lsv = newSV_type(SVt_PV);
11410 SvPV_set(lsv, lpv);
11411 SvCUR_set(lsv, llen);
11412 SvLEN_set(lsv, llen+1);
11422 STRLEN wlen, bufptr_pos;
11426 if (!isIDFIRST_A(c))
11430 } while(isWORDCHAR_A(c));
11432 if (word_takes_any_delimeter(s, wlen))
11434 bufptr_pos = s - SvPVX(PL_linestr);
11436 lex_read_space(LEX_KEEP_PREVIOUS);
11438 s = SvPVX(PL_linestr) + bufptr_pos;
11439 if (t[0] == ':' && t[1] != ':') {
11440 PL_oldoldbufptr = PL_oldbufptr;
11443 return newSVpvn(s, wlen);
11447 if (flags & PARSE_OPTIONAL) {
11450 qerror(Perl_mess(aTHX_ "Parse error"));
11451 return newSVpvs("x");
11458 =for apidoc Amx|OP *|parse_fullstmt|U32 flags
11460 Parse a single complete Perl statement. This may be a normal imperative
11461 statement or a declaration that has compile-time effect, and may include
11462 optional labels. It is up to the caller to ensure that the dynamic
11463 parser state (L</PL_parser> et al) is correctly set to reflect the source
11464 of the code to be parsed and the lexical context for the statement.
11466 The op tree representing the statement is returned. This may be a
11467 null pointer if the statement is null, for example if it was actually
11468 a subroutine definition (which has compile-time side effects). If not
11469 null, it will be the result of a L</newSTATEOP> call, normally including
11470 a C<nextstate> or equivalent op.
11472 If an error occurs in parsing or compilation, in most cases a valid op
11473 tree (most likely null) is returned anyway. The error is reflected in
11474 the parser state, normally resulting in a single exception at the top
11475 level of parsing which covers all the compilation errors that occurred.
11476 Some compilation errors, however, will throw an exception immediately.
11478 The I<flags> parameter is reserved for future use, and must always
11485 Perl_parse_fullstmt(pTHX_ U32 flags)
11488 Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_fullstmt");
11489 return parse_recdescent_for_op(GRAMFULLSTMT, LEX_FAKEEOF_NEVER);
11493 =for apidoc Amx|OP *|parse_stmtseq|U32 flags
11495 Parse a sequence of zero or more Perl statements. These may be normal
11496 imperative statements, including optional labels, or declarations
11497 that have compile-time effect, or any mixture thereof. The statement
11498 sequence ends when a closing brace or end-of-file is encountered in a
11499 place where a new statement could have validly started. It is up to
11500 the caller to ensure that the dynamic parser state (L</PL_parser> et al)
11501 is correctly set to reflect the source of the code to be parsed and the
11502 lexical context for the statements.
11504 The op tree representing the statement sequence is returned. This may
11505 be a null pointer if the statements were all null, for example if there
11506 were no statements or if there were only subroutine definitions (which
11507 have compile-time side effects). If not null, it will be a C<lineseq>
11508 list, normally including C<nextstate> or equivalent ops.
11510 If an error occurs in parsing or compilation, in most cases a valid op
11511 tree is returned anyway. The error is reflected in the parser state,
11512 normally resulting in a single exception at the top level of parsing
11513 which covers all the compilation errors that occurred. Some compilation
11514 errors, however, will throw an exception immediately.
11516 The I<flags> parameter is reserved for future use, and must always
11523 Perl_parse_stmtseq(pTHX_ U32 flags)
11528 Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_stmtseq");
11529 stmtseqop = parse_recdescent_for_op(GRAMSTMTSEQ, LEX_FAKEEOF_CLOSING);
11530 c = lex_peek_unichar(0);
11531 if (c != -1 && c != /*{*/'}')
11532 qerror(Perl_mess(aTHX_ "Parse error"));
11537 Perl_munge_qwlist_to_paren_list(pTHX_ OP *qwlist)
11539 PERL_ARGS_ASSERT_MUNGE_QWLIST_TO_PAREN_LIST;
11540 deprecate("qw(...) as parentheses");
11541 force_next((4<<24)|')');
11542 if (qwlist->op_type == OP_STUB) {
11546 start_force(PL_curforce);
11547 NEXTVAL_NEXTTOKE.opval = qwlist;
11550 force_next((2<<24)|'(');
11555 * c-indentation-style: bsd
11556 * c-basic-offset: 4
11557 * indent-tabs-mode: t
11560 * ex: set ts=8 sts=4 sw=4 noet: