| 1 | /* toke.c |
| 2 | * |
| 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 |
| 5 | * |
| 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. |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * 'It all comes from here, the stench and the peril.' --Frodo |
| 13 | * |
| 14 | * [p.719 of _The Lord of the Rings_, IV/ix: "Shelob's Lair"] |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * This file is the lexer for Perl. It's closely linked to the |
| 19 | * parser, perly.y. |
| 20 | * |
| 21 | * The main routine is yylex(), which returns the next token. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | =head1 Lexer interface |
| 26 | |
| 27 | This is the lower layer of the Perl parser, managing characters and tokens. |
| 28 | |
| 29 | =for apidoc AmU|yy_parser *|PL_parser |
| 30 | |
| 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. |
| 35 | |
| 36 | =cut |
| 37 | */ |
| 38 | |
| 39 | #include "EXTERN.h" |
| 40 | #define PERL_IN_TOKE_C |
| 41 | #include "perl.h" |
| 42 | #include "dquote_static.c" |
| 43 | |
| 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) |
| 46 | |
| 47 | #define pl_yylval (PL_parser->yylval) |
| 48 | |
| 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_preambled (PL_parser->preambled) |
| 70 | #define PL_sublex_info (PL_parser->sublex_info) |
| 71 | #define PL_linestr (PL_parser->linestr) |
| 72 | #define PL_expect (PL_parser->expect) |
| 73 | #define PL_copline (PL_parser->copline) |
| 74 | #define PL_bufptr (PL_parser->bufptr) |
| 75 | #define PL_oldbufptr (PL_parser->oldbufptr) |
| 76 | #define PL_oldoldbufptr (PL_parser->oldoldbufptr) |
| 77 | #define PL_linestart (PL_parser->linestart) |
| 78 | #define PL_bufend (PL_parser->bufend) |
| 79 | #define PL_last_uni (PL_parser->last_uni) |
| 80 | #define PL_last_lop (PL_parser->last_lop) |
| 81 | #define PL_last_lop_op (PL_parser->last_lop_op) |
| 82 | #define PL_lex_state (PL_parser->lex_state) |
| 83 | #define PL_rsfp (PL_parser->rsfp) |
| 84 | #define PL_rsfp_filters (PL_parser->rsfp_filters) |
| 85 | #define PL_in_my (PL_parser->in_my) |
| 86 | #define PL_in_my_stash (PL_parser->in_my_stash) |
| 87 | #define PL_tokenbuf (PL_parser->tokenbuf) |
| 88 | #define PL_multi_end (PL_parser->multi_end) |
| 89 | #define PL_error_count (PL_parser->error_count) |
| 90 | |
| 91 | #ifdef PERL_MAD |
| 92 | # define PL_endwhite (PL_parser->endwhite) |
| 93 | # define PL_faketokens (PL_parser->faketokens) |
| 94 | # define PL_lasttoke (PL_parser->lasttoke) |
| 95 | # define PL_nextwhite (PL_parser->nextwhite) |
| 96 | # define PL_realtokenstart (PL_parser->realtokenstart) |
| 97 | # define PL_skipwhite (PL_parser->skipwhite) |
| 98 | # define PL_thisclose (PL_parser->thisclose) |
| 99 | # define PL_thismad (PL_parser->thismad) |
| 100 | # define PL_thisopen (PL_parser->thisopen) |
| 101 | # define PL_thisstuff (PL_parser->thisstuff) |
| 102 | # define PL_thistoken (PL_parser->thistoken) |
| 103 | # define PL_thiswhite (PL_parser->thiswhite) |
| 104 | # define PL_thiswhite (PL_parser->thiswhite) |
| 105 | # define PL_nexttoke (PL_parser->nexttoke) |
| 106 | # define PL_curforce (PL_parser->curforce) |
| 107 | #else |
| 108 | # define PL_nexttoke (PL_parser->nexttoke) |
| 109 | # define PL_nexttype (PL_parser->nexttype) |
| 110 | # define PL_nextval (PL_parser->nextval) |
| 111 | #endif |
| 112 | |
| 113 | static const char* const ident_too_long = "Identifier too long"; |
| 114 | |
| 115 | #ifdef PERL_MAD |
| 116 | # define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; } |
| 117 | # define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val |
| 118 | #else |
| 119 | # define CURMAD(slot,sv) |
| 120 | # define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke] |
| 121 | #endif |
| 122 | |
| 123 | #define XENUMMASK 0x3f |
| 124 | #define XFAKEEOF 0x40 |
| 125 | #define XFAKEBRACK 0x80 |
| 126 | |
| 127 | #ifdef USE_UTF8_SCRIPTS |
| 128 | # define UTF (!IN_BYTES) |
| 129 | #else |
| 130 | # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || ( !(PL_parser->lex_flags & LEX_IGNORE_UTF8_HINTS) && (PL_hints & HINT_UTF8))) |
| 131 | #endif |
| 132 | |
| 133 | /* The maximum number of characters preceding the unrecognized one to display */ |
| 134 | #define UNRECOGNIZED_PRECEDE_COUNT 10 |
| 135 | |
| 136 | /* In variables named $^X, these are the legal values for X. |
| 137 | * 1999-02-27 mjd-perl-patch@plover.com */ |
| 138 | #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x))) |
| 139 | |
| 140 | #define SPACE_OR_TAB(c) isBLANK_A(c) |
| 141 | |
| 142 | /* LEX_* are values for PL_lex_state, the state of the lexer. |
| 143 | * They are arranged oddly so that the guard on the switch statement |
| 144 | * can get by with a single comparison (if the compiler is smart enough). |
| 145 | * |
| 146 | * These values refer to the various states within a sublex parse, |
| 147 | * i.e. within a double quotish string |
| 148 | */ |
| 149 | |
| 150 | /* #define LEX_NOTPARSING 11 is done in perl.h. */ |
| 151 | |
| 152 | #define LEX_NORMAL 10 /* normal code (ie not within "...") */ |
| 153 | #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */ |
| 154 | #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */ |
| 155 | #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */ |
| 156 | #define LEX_INTERPSTART 6 /* expecting the start of a $var */ |
| 157 | |
| 158 | /* at end of code, eg "$x" followed by: */ |
| 159 | #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */ |
| 160 | #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */ |
| 161 | |
| 162 | #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of |
| 163 | string or after \E, $foo, etc */ |
| 164 | #define LEX_INTERPCONST 2 /* NOT USED */ |
| 165 | #define LEX_FORMLINE 1 /* expecting a format line */ |
| 166 | #define LEX_KNOWNEXT 0 /* next token known; just return it */ |
| 167 | |
| 168 | |
| 169 | #ifdef DEBUGGING |
| 170 | static const char* const lex_state_names[] = { |
| 171 | "KNOWNEXT", |
| 172 | "FORMLINE", |
| 173 | "INTERPCONST", |
| 174 | "INTERPCONCAT", |
| 175 | "INTERPENDMAYBE", |
| 176 | "INTERPEND", |
| 177 | "INTERPSTART", |
| 178 | "INTERPPUSH", |
| 179 | "INTERPCASEMOD", |
| 180 | "INTERPNORMAL", |
| 181 | "NORMAL" |
| 182 | }; |
| 183 | #endif |
| 184 | |
| 185 | #ifdef ff_next |
| 186 | #undef ff_next |
| 187 | #endif |
| 188 | |
| 189 | #include "keywords.h" |
| 190 | |
| 191 | /* CLINE is a macro that ensures PL_copline has a sane value */ |
| 192 | |
| 193 | #ifdef CLINE |
| 194 | #undef CLINE |
| 195 | #endif |
| 196 | #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline)) |
| 197 | |
| 198 | #ifdef PERL_MAD |
| 199 | # define SKIPSPACE0(s) skipspace0(s) |
| 200 | # define SKIPSPACE1(s) skipspace1(s) |
| 201 | # define SKIPSPACE2(s,tsv) skipspace2(s,&tsv) |
| 202 | # define PEEKSPACE(s) skipspace2(s,0) |
| 203 | #else |
| 204 | # define SKIPSPACE0(s) skipspace(s) |
| 205 | # define SKIPSPACE1(s) skipspace(s) |
| 206 | # define SKIPSPACE2(s,tsv) skipspace(s) |
| 207 | # define PEEKSPACE(s) skipspace(s) |
| 208 | #endif |
| 209 | |
| 210 | /* |
| 211 | * Convenience functions to return different tokens and prime the |
| 212 | * lexer for the next token. They all take an argument. |
| 213 | * |
| 214 | * TOKEN : generic token (used for '(', DOLSHARP, etc) |
| 215 | * OPERATOR : generic operator |
| 216 | * AOPERATOR : assignment operator |
| 217 | * PREBLOCK : beginning the block after an if, while, foreach, ... |
| 218 | * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref) |
| 219 | * PREREF : *EXPR where EXPR is not a simple identifier |
| 220 | * TERM : expression term |
| 221 | * LOOPX : loop exiting command (goto, last, dump, etc) |
| 222 | * FTST : file test operator |
| 223 | * FUN0 : zero-argument function |
| 224 | * FUN0OP : zero-argument function, with its op created in this file |
| 225 | * FUN1 : not used, except for not, which isn't a UNIOP |
| 226 | * BOop : bitwise or or xor |
| 227 | * BAop : bitwise and |
| 228 | * SHop : shift operator |
| 229 | * PWop : power operator |
| 230 | * PMop : pattern-matching operator |
| 231 | * Aop : addition-level operator |
| 232 | * Mop : multiplication-level operator |
| 233 | * Eop : equality-testing operator |
| 234 | * Rop : relational operator <= != gt |
| 235 | * |
| 236 | * Also see LOP and lop() below. |
| 237 | */ |
| 238 | |
| 239 | #ifdef DEBUGGING /* Serve -DT. */ |
| 240 | # define REPORT(retval) tokereport((I32)retval, &pl_yylval) |
| 241 | #else |
| 242 | # define REPORT(retval) (retval) |
| 243 | #endif |
| 244 | |
| 245 | #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval)) |
| 246 | #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval)) |
| 247 | #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval))) |
| 248 | #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval)) |
| 249 | #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval)) |
| 250 | #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval)) |
| 251 | #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval)) |
| 252 | #define LOOPX(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX)) |
| 253 | #define FTST(f) return (pl_yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP)) |
| 254 | #define FUN0(f) return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0)) |
| 255 | #define FUN0OP(f) return (pl_yylval.opval=f, CLINE, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0OP)) |
| 256 | #define FUN1(f) return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1)) |
| 257 | #define BOop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP))) |
| 258 | #define BAop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP))) |
| 259 | #define SHop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP))) |
| 260 | #define PWop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP))) |
| 261 | #define PMop(f) return(pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP)) |
| 262 | #define Aop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP))) |
| 263 | #define Mop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP))) |
| 264 | #define Eop(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP)) |
| 265 | #define Rop(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP)) |
| 266 | |
| 267 | /* This bit of chicanery makes a unary function followed by |
| 268 | * a parenthesis into a function with one argument, highest precedence. |
| 269 | * The UNIDOR macro is for unary functions that can be followed by the // |
| 270 | * operator (such as C<shift // 0>). |
| 271 | */ |
| 272 | #define UNI3(f,x,have_x) { \ |
| 273 | pl_yylval.ival = f; \ |
| 274 | if (have_x) PL_expect = x; \ |
| 275 | PL_bufptr = s; \ |
| 276 | PL_last_uni = PL_oldbufptr; \ |
| 277 | PL_last_lop_op = f; \ |
| 278 | if (*s == '(') \ |
| 279 | return REPORT( (int)FUNC1 ); \ |
| 280 | s = PEEKSPACE(s); \ |
| 281 | return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \ |
| 282 | } |
| 283 | #define UNI(f) UNI3(f,XTERM,1) |
| 284 | #define UNIDOR(f) UNI3(f,XTERMORDORDOR,1) |
| 285 | #define UNIPROTO(f,optional) { \ |
| 286 | if (optional) PL_last_uni = PL_oldbufptr; \ |
| 287 | OPERATOR(f); \ |
| 288 | } |
| 289 | |
| 290 | #define UNIBRACK(f) UNI3(f,0,0) |
| 291 | |
| 292 | /* grandfather return to old style */ |
| 293 | #define OLDLOP(f) \ |
| 294 | do { \ |
| 295 | if (!PL_lex_allbrackets && PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC) \ |
| 296 | PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC; \ |
| 297 | pl_yylval.ival = (f); \ |
| 298 | PL_expect = XTERM; \ |
| 299 | PL_bufptr = s; \ |
| 300 | return (int)LSTOP; \ |
| 301 | } while(0) |
| 302 | |
| 303 | #define COPLINE_INC_WITH_HERELINES \ |
| 304 | STMT_START { \ |
| 305 | CopLINE_inc(PL_curcop); \ |
| 306 | if (PL_parser->lex_shared->herelines) \ |
| 307 | CopLINE(PL_curcop) += PL_parser->lex_shared->herelines, \ |
| 308 | PL_parser->lex_shared->herelines = 0; \ |
| 309 | } STMT_END |
| 310 | |
| 311 | |
| 312 | #ifdef DEBUGGING |
| 313 | |
| 314 | /* how to interpret the pl_yylval associated with the token */ |
| 315 | enum token_type { |
| 316 | TOKENTYPE_NONE, |
| 317 | TOKENTYPE_IVAL, |
| 318 | TOKENTYPE_OPNUM, /* pl_yylval.ival contains an opcode number */ |
| 319 | TOKENTYPE_PVAL, |
| 320 | TOKENTYPE_OPVAL |
| 321 | }; |
| 322 | |
| 323 | static struct debug_tokens { |
| 324 | const int token; |
| 325 | enum token_type type; |
| 326 | const char *name; |
| 327 | } const debug_tokens[] = |
| 328 | { |
| 329 | { ADDOP, TOKENTYPE_OPNUM, "ADDOP" }, |
| 330 | { ANDAND, TOKENTYPE_NONE, "ANDAND" }, |
| 331 | { ANDOP, TOKENTYPE_NONE, "ANDOP" }, |
| 332 | { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" }, |
| 333 | { ARROW, TOKENTYPE_NONE, "ARROW" }, |
| 334 | { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" }, |
| 335 | { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" }, |
| 336 | { BITOROP, TOKENTYPE_OPNUM, "BITOROP" }, |
| 337 | { COLONATTR, TOKENTYPE_NONE, "COLONATTR" }, |
| 338 | { CONTINUE, TOKENTYPE_NONE, "CONTINUE" }, |
| 339 | { DEFAULT, TOKENTYPE_NONE, "DEFAULT" }, |
| 340 | { DO, TOKENTYPE_NONE, "DO" }, |
| 341 | { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" }, |
| 342 | { DORDOR, TOKENTYPE_NONE, "DORDOR" }, |
| 343 | { DOROP, TOKENTYPE_OPNUM, "DOROP" }, |
| 344 | { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" }, |
| 345 | { ELSE, TOKENTYPE_NONE, "ELSE" }, |
| 346 | { ELSIF, TOKENTYPE_IVAL, "ELSIF" }, |
| 347 | { EQOP, TOKENTYPE_OPNUM, "EQOP" }, |
| 348 | { FOR, TOKENTYPE_IVAL, "FOR" }, |
| 349 | { FORMAT, TOKENTYPE_NONE, "FORMAT" }, |
| 350 | { FORMLBRACK, TOKENTYPE_NONE, "FORMLBRACK" }, |
| 351 | { FORMRBRACK, TOKENTYPE_NONE, "FORMRBRACK" }, |
| 352 | { FUNC, TOKENTYPE_OPNUM, "FUNC" }, |
| 353 | { FUNC0, TOKENTYPE_OPNUM, "FUNC0" }, |
| 354 | { FUNC0OP, TOKENTYPE_OPVAL, "FUNC0OP" }, |
| 355 | { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" }, |
| 356 | { FUNC1, TOKENTYPE_OPNUM, "FUNC1" }, |
| 357 | { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" }, |
| 358 | { GIVEN, TOKENTYPE_IVAL, "GIVEN" }, |
| 359 | { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" }, |
| 360 | { IF, TOKENTYPE_IVAL, "IF" }, |
| 361 | { LABEL, TOKENTYPE_PVAL, "LABEL" }, |
| 362 | { LOCAL, TOKENTYPE_IVAL, "LOCAL" }, |
| 363 | { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" }, |
| 364 | { LSTOP, TOKENTYPE_OPNUM, "LSTOP" }, |
| 365 | { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" }, |
| 366 | { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" }, |
| 367 | { METHOD, TOKENTYPE_OPVAL, "METHOD" }, |
| 368 | { MULOP, TOKENTYPE_OPNUM, "MULOP" }, |
| 369 | { MY, TOKENTYPE_IVAL, "MY" }, |
| 370 | { NOAMP, TOKENTYPE_NONE, "NOAMP" }, |
| 371 | { NOTOP, TOKENTYPE_NONE, "NOTOP" }, |
| 372 | { OROP, TOKENTYPE_IVAL, "OROP" }, |
| 373 | { OROR, TOKENTYPE_NONE, "OROR" }, |
| 374 | { PACKAGE, TOKENTYPE_NONE, "PACKAGE" }, |
| 375 | { PEG, TOKENTYPE_NONE, "PEG" }, |
| 376 | { PLUGEXPR, TOKENTYPE_OPVAL, "PLUGEXPR" }, |
| 377 | { PLUGSTMT, TOKENTYPE_OPVAL, "PLUGSTMT" }, |
| 378 | { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" }, |
| 379 | { POSTDEC, TOKENTYPE_NONE, "POSTDEC" }, |
| 380 | { POSTINC, TOKENTYPE_NONE, "POSTINC" }, |
| 381 | { POWOP, TOKENTYPE_OPNUM, "POWOP" }, |
| 382 | { PREDEC, TOKENTYPE_NONE, "PREDEC" }, |
| 383 | { PREINC, TOKENTYPE_NONE, "PREINC" }, |
| 384 | { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" }, |
| 385 | { QWLIST, TOKENTYPE_OPVAL, "QWLIST" }, |
| 386 | { REFGEN, TOKENTYPE_NONE, "REFGEN" }, |
| 387 | { RELOP, TOKENTYPE_OPNUM, "RELOP" }, |
| 388 | { REQUIRE, TOKENTYPE_NONE, "REQUIRE" }, |
| 389 | { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" }, |
| 390 | { SUB, TOKENTYPE_NONE, "SUB" }, |
| 391 | { THING, TOKENTYPE_OPVAL, "THING" }, |
| 392 | { UMINUS, TOKENTYPE_NONE, "UMINUS" }, |
| 393 | { UNIOP, TOKENTYPE_OPNUM, "UNIOP" }, |
| 394 | { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" }, |
| 395 | { UNLESS, TOKENTYPE_IVAL, "UNLESS" }, |
| 396 | { UNTIL, TOKENTYPE_IVAL, "UNTIL" }, |
| 397 | { USE, TOKENTYPE_IVAL, "USE" }, |
| 398 | { WHEN, TOKENTYPE_IVAL, "WHEN" }, |
| 399 | { WHILE, TOKENTYPE_IVAL, "WHILE" }, |
| 400 | { WORD, TOKENTYPE_OPVAL, "WORD" }, |
| 401 | { YADAYADA, TOKENTYPE_IVAL, "YADAYADA" }, |
| 402 | { 0, TOKENTYPE_NONE, NULL } |
| 403 | }; |
| 404 | |
| 405 | /* dump the returned token in rv, plus any optional arg in pl_yylval */ |
| 406 | |
| 407 | STATIC int |
| 408 | S_tokereport(pTHX_ I32 rv, const YYSTYPE* lvalp) |
| 409 | { |
| 410 | dVAR; |
| 411 | |
| 412 | PERL_ARGS_ASSERT_TOKEREPORT; |
| 413 | |
| 414 | if (DEBUG_T_TEST) { |
| 415 | const char *name = NULL; |
| 416 | enum token_type type = TOKENTYPE_NONE; |
| 417 | const struct debug_tokens *p; |
| 418 | SV* const report = newSVpvs("<== "); |
| 419 | |
| 420 | for (p = debug_tokens; p->token; p++) { |
| 421 | if (p->token == (int)rv) { |
| 422 | name = p->name; |
| 423 | type = p->type; |
| 424 | break; |
| 425 | } |
| 426 | } |
| 427 | if (name) |
| 428 | Perl_sv_catpv(aTHX_ report, name); |
| 429 | else if ((char)rv > ' ' && (char)rv <= '~') |
| 430 | { |
| 431 | Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv); |
| 432 | if ((char)rv == 'p') |
| 433 | sv_catpvs(report, " (pending identifier)"); |
| 434 | } |
| 435 | else if (!rv) |
| 436 | sv_catpvs(report, "EOF"); |
| 437 | else |
| 438 | Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv); |
| 439 | switch (type) { |
| 440 | case TOKENTYPE_NONE: |
| 441 | break; |
| 442 | case TOKENTYPE_IVAL: |
| 443 | Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)lvalp->ival); |
| 444 | break; |
| 445 | case TOKENTYPE_OPNUM: |
| 446 | Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)", |
| 447 | PL_op_name[lvalp->ival]); |
| 448 | break; |
| 449 | case TOKENTYPE_PVAL: |
| 450 | Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", lvalp->pval); |
| 451 | break; |
| 452 | case TOKENTYPE_OPVAL: |
| 453 | if (lvalp->opval) { |
| 454 | Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)", |
| 455 | PL_op_name[lvalp->opval->op_type]); |
| 456 | if (lvalp->opval->op_type == OP_CONST) { |
| 457 | Perl_sv_catpvf(aTHX_ report, " %s", |
| 458 | SvPEEK(cSVOPx_sv(lvalp->opval))); |
| 459 | } |
| 460 | |
| 461 | } |
| 462 | else |
| 463 | sv_catpvs(report, "(opval=null)"); |
| 464 | break; |
| 465 | } |
| 466 | PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report)); |
| 467 | }; |
| 468 | return (int)rv; |
| 469 | } |
| 470 | |
| 471 | |
| 472 | /* print the buffer with suitable escapes */ |
| 473 | |
| 474 | STATIC void |
| 475 | S_printbuf(pTHX_ const char *const fmt, const char *const s) |
| 476 | { |
| 477 | SV* const tmp = newSVpvs(""); |
| 478 | |
| 479 | PERL_ARGS_ASSERT_PRINTBUF; |
| 480 | |
| 481 | PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60)); |
| 482 | SvREFCNT_dec(tmp); |
| 483 | } |
| 484 | |
| 485 | #endif |
| 486 | |
| 487 | static int |
| 488 | S_deprecate_commaless_var_list(pTHX) { |
| 489 | PL_expect = XTERM; |
| 490 | deprecate("comma-less variable list"); |
| 491 | return REPORT(','); /* grandfather non-comma-format format */ |
| 492 | } |
| 493 | |
| 494 | /* |
| 495 | * S_ao |
| 496 | * |
| 497 | * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR |
| 498 | * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN |
| 499 | */ |
| 500 | |
| 501 | STATIC int |
| 502 | S_ao(pTHX_ int toketype) |
| 503 | { |
| 504 | dVAR; |
| 505 | if (*PL_bufptr == '=') { |
| 506 | PL_bufptr++; |
| 507 | if (toketype == ANDAND) |
| 508 | pl_yylval.ival = OP_ANDASSIGN; |
| 509 | else if (toketype == OROR) |
| 510 | pl_yylval.ival = OP_ORASSIGN; |
| 511 | else if (toketype == DORDOR) |
| 512 | pl_yylval.ival = OP_DORASSIGN; |
| 513 | toketype = ASSIGNOP; |
| 514 | } |
| 515 | return toketype; |
| 516 | } |
| 517 | |
| 518 | /* |
| 519 | * S_no_op |
| 520 | * When Perl expects an operator and finds something else, no_op |
| 521 | * prints the warning. It always prints "<something> found where |
| 522 | * operator expected. It prints "Missing semicolon on previous line?" |
| 523 | * if the surprise occurs at the start of the line. "do you need to |
| 524 | * predeclare ..." is printed out for code like "sub bar; foo bar $x" |
| 525 | * where the compiler doesn't know if foo is a method call or a function. |
| 526 | * It prints "Missing operator before end of line" if there's nothing |
| 527 | * after the missing operator, or "... before <...>" if there is something |
| 528 | * after the missing operator. |
| 529 | */ |
| 530 | |
| 531 | STATIC void |
| 532 | S_no_op(pTHX_ const char *const what, char *s) |
| 533 | { |
| 534 | dVAR; |
| 535 | char * const oldbp = PL_bufptr; |
| 536 | const bool is_first = (PL_oldbufptr == PL_linestart); |
| 537 | |
| 538 | PERL_ARGS_ASSERT_NO_OP; |
| 539 | |
| 540 | if (!s) |
| 541 | s = oldbp; |
| 542 | else |
| 543 | PL_bufptr = s; |
| 544 | yywarn(Perl_form(aTHX_ "%s found where operator expected", what), UTF ? SVf_UTF8 : 0); |
| 545 | if (ckWARN_d(WARN_SYNTAX)) { |
| 546 | if (is_first) |
| 547 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 548 | "\t(Missing semicolon on previous line?)\n"); |
| 549 | else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) { |
| 550 | const char *t; |
| 551 | for (t = PL_oldoldbufptr; (isWORDCHAR_lazy_if(t,UTF) || *t == ':'); |
| 552 | t += UTF ? UTF8SKIP(t) : 1) |
| 553 | NOOP; |
| 554 | if (t < PL_bufptr && isSPACE(*t)) |
| 555 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 556 | "\t(Do you need to predeclare %"UTF8f"?)\n", |
| 557 | UTF8fARG(UTF, t - PL_oldoldbufptr, PL_oldoldbufptr)); |
| 558 | } |
| 559 | else { |
| 560 | assert(s >= oldbp); |
| 561 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 562 | "\t(Missing operator before %"UTF8f"?)\n", |
| 563 | UTF8fARG(UTF, s - oldbp, oldbp)); |
| 564 | } |
| 565 | } |
| 566 | PL_bufptr = oldbp; |
| 567 | } |
| 568 | |
| 569 | /* |
| 570 | * S_missingterm |
| 571 | * Complain about missing quote/regexp/heredoc terminator. |
| 572 | * If it's called with NULL then it cauterizes the line buffer. |
| 573 | * If we're in a delimited string and the delimiter is a control |
| 574 | * character, it's reformatted into a two-char sequence like ^C. |
| 575 | * This is fatal. |
| 576 | */ |
| 577 | |
| 578 | STATIC void |
| 579 | S_missingterm(pTHX_ char *s) |
| 580 | { |
| 581 | dVAR; |
| 582 | char tmpbuf[3]; |
| 583 | char q; |
| 584 | if (s) { |
| 585 | char * const nl = strrchr(s,'\n'); |
| 586 | if (nl) |
| 587 | *nl = '\0'; |
| 588 | } |
| 589 | else if (isCNTRL(PL_multi_close)) { |
| 590 | *tmpbuf = '^'; |
| 591 | tmpbuf[1] = (char)toCTRL(PL_multi_close); |
| 592 | tmpbuf[2] = '\0'; |
| 593 | s = tmpbuf; |
| 594 | } |
| 595 | else { |
| 596 | *tmpbuf = (char)PL_multi_close; |
| 597 | tmpbuf[1] = '\0'; |
| 598 | s = tmpbuf; |
| 599 | } |
| 600 | q = strchr(s,'"') ? '\'' : '"'; |
| 601 | Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q); |
| 602 | } |
| 603 | |
| 604 | #include "feature.h" |
| 605 | |
| 606 | /* |
| 607 | * Check whether the named feature is enabled. |
| 608 | */ |
| 609 | bool |
| 610 | Perl_feature_is_enabled(pTHX_ const char *const name, STRLEN namelen) |
| 611 | { |
| 612 | dVAR; |
| 613 | char he_name[8 + MAX_FEATURE_LEN] = "feature_"; |
| 614 | |
| 615 | PERL_ARGS_ASSERT_FEATURE_IS_ENABLED; |
| 616 | |
| 617 | assert(CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM); |
| 618 | |
| 619 | if (namelen > MAX_FEATURE_LEN) |
| 620 | return FALSE; |
| 621 | memcpy(&he_name[8], name, namelen); |
| 622 | |
| 623 | return cBOOL(cop_hints_fetch_pvn(PL_curcop, he_name, 8 + namelen, 0, |
| 624 | REFCOUNTED_HE_EXISTS)); |
| 625 | } |
| 626 | |
| 627 | /* |
| 628 | * experimental text filters for win32 carriage-returns, utf16-to-utf8 and |
| 629 | * utf16-to-utf8-reversed. |
| 630 | */ |
| 631 | |
| 632 | #ifdef PERL_CR_FILTER |
| 633 | static void |
| 634 | strip_return(SV *sv) |
| 635 | { |
| 636 | const char *s = SvPVX_const(sv); |
| 637 | const char * const e = s + SvCUR(sv); |
| 638 | |
| 639 | PERL_ARGS_ASSERT_STRIP_RETURN; |
| 640 | |
| 641 | /* outer loop optimized to do nothing if there are no CR-LFs */ |
| 642 | while (s < e) { |
| 643 | if (*s++ == '\r' && *s == '\n') { |
| 644 | /* hit a CR-LF, need to copy the rest */ |
| 645 | char *d = s - 1; |
| 646 | *d++ = *s++; |
| 647 | while (s < e) { |
| 648 | if (*s == '\r' && s[1] == '\n') |
| 649 | s++; |
| 650 | *d++ = *s++; |
| 651 | } |
| 652 | SvCUR(sv) -= s - d; |
| 653 | return; |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | STATIC I32 |
| 659 | S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
| 660 | { |
| 661 | const I32 count = FILTER_READ(idx+1, sv, maxlen); |
| 662 | if (count > 0 && !maxlen) |
| 663 | strip_return(sv); |
| 664 | return count; |
| 665 | } |
| 666 | #endif |
| 667 | |
| 668 | /* |
| 669 | =for apidoc Amx|void|lex_start|SV *line|PerlIO *rsfp|U32 flags |
| 670 | |
| 671 | Creates and initialises a new lexer/parser state object, supplying |
| 672 | a context in which to lex and parse from a new source of Perl code. |
| 673 | A pointer to the new state object is placed in L</PL_parser>. An entry |
| 674 | is made on the save stack so that upon unwinding the new state object |
| 675 | will be destroyed and the former value of L</PL_parser> will be restored. |
| 676 | Nothing else need be done to clean up the parsing context. |
| 677 | |
| 678 | The code to be parsed comes from I<line> and I<rsfp>. I<line>, if |
| 679 | non-null, provides a string (in SV form) containing code to be parsed. |
| 680 | A copy of the string is made, so subsequent modification of I<line> |
| 681 | does not affect parsing. I<rsfp>, if non-null, provides an input stream |
| 682 | from which code will be read to be parsed. If both are non-null, the |
| 683 | code in I<line> comes first and must consist of complete lines of input, |
| 684 | and I<rsfp> supplies the remainder of the source. |
| 685 | |
| 686 | The I<flags> parameter is reserved for future use. Currently it is only |
| 687 | used by perl internally, so extensions should always pass zero. |
| 688 | |
| 689 | =cut |
| 690 | */ |
| 691 | |
| 692 | /* LEX_START_SAME_FILTER indicates that this is not a new file, so it |
| 693 | can share filters with the current parser. |
| 694 | LEX_START_DONT_CLOSE indicates that the file handle wasn't opened by the |
| 695 | caller, hence isn't owned by the parser, so shouldn't be closed on parser |
| 696 | destruction. This is used to handle the case of defaulting to reading the |
| 697 | script from the standard input because no filename was given on the command |
| 698 | line (without getting confused by situation where STDIN has been closed, so |
| 699 | the script handle is opened on fd 0) */ |
| 700 | |
| 701 | void |
| 702 | Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, U32 flags) |
| 703 | { |
| 704 | dVAR; |
| 705 | const char *s = NULL; |
| 706 | yy_parser *parser, *oparser; |
| 707 | if (flags && flags & ~LEX_START_FLAGS) |
| 708 | Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_start"); |
| 709 | |
| 710 | /* create and initialise a parser */ |
| 711 | |
| 712 | Newxz(parser, 1, yy_parser); |
| 713 | parser->old_parser = oparser = PL_parser; |
| 714 | PL_parser = parser; |
| 715 | |
| 716 | parser->stack = NULL; |
| 717 | parser->ps = NULL; |
| 718 | parser->stack_size = 0; |
| 719 | |
| 720 | /* on scope exit, free this parser and restore any outer one */ |
| 721 | SAVEPARSER(parser); |
| 722 | parser->saved_curcop = PL_curcop; |
| 723 | |
| 724 | /* initialise lexer state */ |
| 725 | |
| 726 | #ifdef PERL_MAD |
| 727 | parser->curforce = -1; |
| 728 | #else |
| 729 | parser->nexttoke = 0; |
| 730 | #endif |
| 731 | parser->error_count = oparser ? oparser->error_count : 0; |
| 732 | parser->copline = NOLINE; |
| 733 | parser->lex_state = LEX_NORMAL; |
| 734 | parser->expect = XSTATE; |
| 735 | parser->rsfp = rsfp; |
| 736 | parser->rsfp_filters = |
| 737 | !(flags & LEX_START_SAME_FILTER) || !oparser |
| 738 | ? NULL |
| 739 | : MUTABLE_AV(SvREFCNT_inc( |
| 740 | oparser->rsfp_filters |
| 741 | ? oparser->rsfp_filters |
| 742 | : (oparser->rsfp_filters = newAV()) |
| 743 | )); |
| 744 | |
| 745 | Newx(parser->lex_brackstack, 120, char); |
| 746 | Newx(parser->lex_casestack, 12, char); |
| 747 | *parser->lex_casestack = '\0'; |
| 748 | Newxz(parser->lex_shared, 1, LEXSHARED); |
| 749 | |
| 750 | if (line) { |
| 751 | STRLEN len; |
| 752 | s = SvPV_const(line, len); |
| 753 | parser->linestr = flags & LEX_START_COPIED |
| 754 | ? SvREFCNT_inc_simple_NN(line) |
| 755 | : newSVpvn_flags(s, len, SvUTF8(line)); |
| 756 | sv_catpvs(parser->linestr, "\n;"); |
| 757 | } else { |
| 758 | parser->linestr = newSVpvs("\n;"); |
| 759 | } |
| 760 | parser->oldoldbufptr = |
| 761 | parser->oldbufptr = |
| 762 | parser->bufptr = |
| 763 | parser->linestart = SvPVX(parser->linestr); |
| 764 | parser->bufend = parser->bufptr + SvCUR(parser->linestr); |
| 765 | parser->last_lop = parser->last_uni = NULL; |
| 766 | parser->lex_flags = flags & (LEX_IGNORE_UTF8_HINTS|LEX_EVALBYTES |
| 767 | |LEX_DONT_CLOSE_RSFP); |
| 768 | |
| 769 | parser->in_pod = parser->filtered = 0; |
| 770 | } |
| 771 | |
| 772 | |
| 773 | /* delete a parser object */ |
| 774 | |
| 775 | void |
| 776 | Perl_parser_free(pTHX_ const yy_parser *parser) |
| 777 | { |
| 778 | PERL_ARGS_ASSERT_PARSER_FREE; |
| 779 | |
| 780 | PL_curcop = parser->saved_curcop; |
| 781 | SvREFCNT_dec(parser->linestr); |
| 782 | |
| 783 | if (PL_parser->lex_flags & LEX_DONT_CLOSE_RSFP) |
| 784 | PerlIO_clearerr(parser->rsfp); |
| 785 | else if (parser->rsfp && (!parser->old_parser || |
| 786 | (parser->old_parser && parser->rsfp != parser->old_parser->rsfp))) |
| 787 | PerlIO_close(parser->rsfp); |
| 788 | SvREFCNT_dec(parser->rsfp_filters); |
| 789 | SvREFCNT_dec(parser->lex_stuff); |
| 790 | SvREFCNT_dec(parser->sublex_info.repl); |
| 791 | |
| 792 | Safefree(parser->lex_brackstack); |
| 793 | Safefree(parser->lex_casestack); |
| 794 | Safefree(parser->lex_shared); |
| 795 | PL_parser = parser->old_parser; |
| 796 | Safefree(parser); |
| 797 | } |
| 798 | |
| 799 | void |
| 800 | Perl_parser_free_nexttoke_ops(pTHX_ yy_parser *parser, OPSLAB *slab) |
| 801 | { |
| 802 | #ifdef PERL_MAD |
| 803 | I32 nexttoke = parser->lasttoke; |
| 804 | #else |
| 805 | I32 nexttoke = parser->nexttoke; |
| 806 | #endif |
| 807 | PERL_ARGS_ASSERT_PARSER_FREE_NEXTTOKE_OPS; |
| 808 | while (nexttoke--) { |
| 809 | #ifdef PERL_MAD |
| 810 | if (S_is_opval_token(parser->nexttoke[nexttoke].next_type |
| 811 | & 0xffff) |
| 812 | && parser->nexttoke[nexttoke].next_val.opval |
| 813 | && parser->nexttoke[nexttoke].next_val.opval->op_slabbed |
| 814 | && OpSLAB(parser->nexttoke[nexttoke].next_val.opval) == slab) { |
| 815 | op_free(parser->nexttoke[nexttoke].next_val.opval); |
| 816 | parser->nexttoke[nexttoke].next_val.opval = NULL; |
| 817 | } |
| 818 | #else |
| 819 | if (S_is_opval_token(parser->nexttype[nexttoke] & 0xffff) |
| 820 | && parser->nextval[nexttoke].opval |
| 821 | && parser->nextval[nexttoke].opval->op_slabbed |
| 822 | && OpSLAB(parser->nextval[nexttoke].opval) == slab) { |
| 823 | op_free(parser->nextval[nexttoke].opval); |
| 824 | parser->nextval[nexttoke].opval = NULL; |
| 825 | } |
| 826 | #endif |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | |
| 831 | /* |
| 832 | =for apidoc AmxU|SV *|PL_parser-E<gt>linestr |
| 833 | |
| 834 | Buffer scalar containing the chunk currently under consideration of the |
| 835 | text currently being lexed. This is always a plain string scalar (for |
| 836 | which C<SvPOK> is true). It is not intended to be used as a scalar by |
| 837 | normal scalar means; instead refer to the buffer directly by the pointer |
| 838 | variables described below. |
| 839 | |
| 840 | The lexer maintains various C<char*> pointers to things in the |
| 841 | C<PL_parser-E<gt>linestr> buffer. If C<PL_parser-E<gt>linestr> is ever |
| 842 | reallocated, all of these pointers must be updated. Don't attempt to |
| 843 | do this manually, but rather use L</lex_grow_linestr> if you need to |
| 844 | reallocate the buffer. |
| 845 | |
| 846 | The content of the text chunk in the buffer is commonly exactly one |
| 847 | complete line of input, up to and including a newline terminator, |
| 848 | but there are situations where it is otherwise. The octets of the |
| 849 | buffer may be intended to be interpreted as either UTF-8 or Latin-1. |
| 850 | The function L</lex_bufutf8> tells you which. Do not use the C<SvUTF8> |
| 851 | flag on this scalar, which may disagree with it. |
| 852 | |
| 853 | For direct examination of the buffer, the variable |
| 854 | L</PL_parser-E<gt>bufend> points to the end of the buffer. The current |
| 855 | lexing position is pointed to by L</PL_parser-E<gt>bufptr>. Direct use |
| 856 | of these pointers is usually preferable to examination of the scalar |
| 857 | through normal scalar means. |
| 858 | |
| 859 | =for apidoc AmxU|char *|PL_parser-E<gt>bufend |
| 860 | |
| 861 | Direct pointer to the end of the chunk of text currently being lexed, the |
| 862 | end of the lexer buffer. This is equal to C<SvPVX(PL_parser-E<gt>linestr) |
| 863 | + SvCUR(PL_parser-E<gt>linestr)>. A NUL character (zero octet) is |
| 864 | always located at the end of the buffer, and does not count as part of |
| 865 | the buffer's contents. |
| 866 | |
| 867 | =for apidoc AmxU|char *|PL_parser-E<gt>bufptr |
| 868 | |
| 869 | Points to the current position of lexing inside the lexer buffer. |
| 870 | Characters around this point may be freely examined, within |
| 871 | the range delimited by C<SvPVX(L</PL_parser-E<gt>linestr>)> and |
| 872 | L</PL_parser-E<gt>bufend>. The octets of the buffer may be intended to be |
| 873 | interpreted as either UTF-8 or Latin-1, as indicated by L</lex_bufutf8>. |
| 874 | |
| 875 | Lexing code (whether in the Perl core or not) moves this pointer past |
| 876 | the characters that it consumes. It is also expected to perform some |
| 877 | bookkeeping whenever a newline character is consumed. This movement |
| 878 | can be more conveniently performed by the function L</lex_read_to>, |
| 879 | which handles newlines appropriately. |
| 880 | |
| 881 | Interpretation of the buffer's octets can be abstracted out by |
| 882 | using the slightly higher-level functions L</lex_peek_unichar> and |
| 883 | L</lex_read_unichar>. |
| 884 | |
| 885 | =for apidoc AmxU|char *|PL_parser-E<gt>linestart |
| 886 | |
| 887 | Points to the start of the current line inside the lexer buffer. |
| 888 | This is useful for indicating at which column an error occurred, and |
| 889 | not much else. This must be updated by any lexing code that consumes |
| 890 | a newline; the function L</lex_read_to> handles this detail. |
| 891 | |
| 892 | =cut |
| 893 | */ |
| 894 | |
| 895 | /* |
| 896 | =for apidoc Amx|bool|lex_bufutf8 |
| 897 | |
| 898 | Indicates whether the octets in the lexer buffer |
| 899 | (L</PL_parser-E<gt>linestr>) should be interpreted as the UTF-8 encoding |
| 900 | of Unicode characters. If not, they should be interpreted as Latin-1 |
| 901 | characters. This is analogous to the C<SvUTF8> flag for scalars. |
| 902 | |
| 903 | In UTF-8 mode, it is not guaranteed that the lexer buffer actually |
| 904 | contains valid UTF-8. Lexing code must be robust in the face of invalid |
| 905 | encoding. |
| 906 | |
| 907 | The actual C<SvUTF8> flag of the L</PL_parser-E<gt>linestr> scalar |
| 908 | is significant, but not the whole story regarding the input character |
| 909 | encoding. Normally, when a file is being read, the scalar contains octets |
| 910 | and its C<SvUTF8> flag is off, but the octets should be interpreted as |
| 911 | UTF-8 if the C<use utf8> pragma is in effect. During a string eval, |
| 912 | however, the scalar may have the C<SvUTF8> flag on, and in this case its |
| 913 | octets should be interpreted as UTF-8 unless the C<use bytes> pragma |
| 914 | is in effect. This logic may change in the future; use this function |
| 915 | instead of implementing the logic yourself. |
| 916 | |
| 917 | =cut |
| 918 | */ |
| 919 | |
| 920 | bool |
| 921 | Perl_lex_bufutf8(pTHX) |
| 922 | { |
| 923 | return UTF; |
| 924 | } |
| 925 | |
| 926 | /* |
| 927 | =for apidoc Amx|char *|lex_grow_linestr|STRLEN len |
| 928 | |
| 929 | Reallocates the lexer buffer (L</PL_parser-E<gt>linestr>) to accommodate |
| 930 | at least I<len> octets (including terminating NUL). Returns a |
| 931 | pointer to the reallocated buffer. This is necessary before making |
| 932 | any direct modification of the buffer that would increase its length. |
| 933 | L</lex_stuff_pvn> provides a more convenient way to insert text into |
| 934 | the buffer. |
| 935 | |
| 936 | Do not use C<SvGROW> or C<sv_grow> directly on C<PL_parser-E<gt>linestr>; |
| 937 | this function updates all of the lexer's variables that point directly |
| 938 | into the buffer. |
| 939 | |
| 940 | =cut |
| 941 | */ |
| 942 | |
| 943 | char * |
| 944 | Perl_lex_grow_linestr(pTHX_ STRLEN len) |
| 945 | { |
| 946 | SV *linestr; |
| 947 | char *buf; |
| 948 | STRLEN bufend_pos, bufptr_pos, oldbufptr_pos, oldoldbufptr_pos; |
| 949 | STRLEN linestart_pos, last_uni_pos, last_lop_pos, re_eval_start_pos; |
| 950 | linestr = PL_parser->linestr; |
| 951 | buf = SvPVX(linestr); |
| 952 | if (len <= SvLEN(linestr)) |
| 953 | return buf; |
| 954 | bufend_pos = PL_parser->bufend - buf; |
| 955 | bufptr_pos = PL_parser->bufptr - buf; |
| 956 | oldbufptr_pos = PL_parser->oldbufptr - buf; |
| 957 | oldoldbufptr_pos = PL_parser->oldoldbufptr - buf; |
| 958 | linestart_pos = PL_parser->linestart - buf; |
| 959 | last_uni_pos = PL_parser->last_uni ? PL_parser->last_uni - buf : 0; |
| 960 | last_lop_pos = PL_parser->last_lop ? PL_parser->last_lop - buf : 0; |
| 961 | re_eval_start_pos = PL_parser->lex_shared->re_eval_start ? |
| 962 | PL_parser->lex_shared->re_eval_start - buf : 0; |
| 963 | |
| 964 | buf = sv_grow(linestr, len); |
| 965 | |
| 966 | PL_parser->bufend = buf + bufend_pos; |
| 967 | PL_parser->bufptr = buf + bufptr_pos; |
| 968 | PL_parser->oldbufptr = buf + oldbufptr_pos; |
| 969 | PL_parser->oldoldbufptr = buf + oldoldbufptr_pos; |
| 970 | PL_parser->linestart = buf + linestart_pos; |
| 971 | if (PL_parser->last_uni) |
| 972 | PL_parser->last_uni = buf + last_uni_pos; |
| 973 | if (PL_parser->last_lop) |
| 974 | PL_parser->last_lop = buf + last_lop_pos; |
| 975 | if (PL_parser->lex_shared->re_eval_start) |
| 976 | PL_parser->lex_shared->re_eval_start = buf + re_eval_start_pos; |
| 977 | return buf; |
| 978 | } |
| 979 | |
| 980 | /* |
| 981 | =for apidoc Amx|void|lex_stuff_pvn|const char *pv|STRLEN len|U32 flags |
| 982 | |
| 983 | Insert characters into the lexer buffer (L</PL_parser-E<gt>linestr>), |
| 984 | immediately after the current lexing point (L</PL_parser-E<gt>bufptr>), |
| 985 | reallocating the buffer if necessary. This means that lexing code that |
| 986 | runs later will see the characters as if they had appeared in the input. |
| 987 | It is not recommended to do this as part of normal parsing, and most |
| 988 | uses of this facility run the risk of the inserted characters being |
| 989 | interpreted in an unintended manner. |
| 990 | |
| 991 | The string to be inserted is represented by I<len> octets starting |
| 992 | at I<pv>. These octets are interpreted as either UTF-8 or Latin-1, |
| 993 | according to whether the C<LEX_STUFF_UTF8> flag is set in I<flags>. |
| 994 | The characters are recoded for the lexer buffer, according to how the |
| 995 | buffer is currently being interpreted (L</lex_bufutf8>). If a string |
| 996 | to be inserted is available as a Perl scalar, the L</lex_stuff_sv> |
| 997 | function is more convenient. |
| 998 | |
| 999 | =cut |
| 1000 | */ |
| 1001 | |
| 1002 | void |
| 1003 | Perl_lex_stuff_pvn(pTHX_ const char *pv, STRLEN len, U32 flags) |
| 1004 | { |
| 1005 | dVAR; |
| 1006 | char *bufptr; |
| 1007 | PERL_ARGS_ASSERT_LEX_STUFF_PVN; |
| 1008 | if (flags & ~(LEX_STUFF_UTF8)) |
| 1009 | Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_stuff_pvn"); |
| 1010 | if (UTF) { |
| 1011 | if (flags & LEX_STUFF_UTF8) { |
| 1012 | goto plain_copy; |
| 1013 | } else { |
| 1014 | STRLEN highhalf = 0; /* Count of variants */ |
| 1015 | const char *p, *e = pv+len; |
| 1016 | for (p = pv; p != e; p++) { |
| 1017 | if (! UTF8_IS_INVARIANT(*p)) { |
| 1018 | highhalf++; |
| 1019 | } |
| 1020 | } |
| 1021 | if (!highhalf) |
| 1022 | goto plain_copy; |
| 1023 | lex_grow_linestr(SvCUR(PL_parser->linestr)+1+len+highhalf); |
| 1024 | bufptr = PL_parser->bufptr; |
| 1025 | Move(bufptr, bufptr+len+highhalf, PL_parser->bufend+1-bufptr, char); |
| 1026 | SvCUR_set(PL_parser->linestr, |
| 1027 | SvCUR(PL_parser->linestr) + len+highhalf); |
| 1028 | PL_parser->bufend += len+highhalf; |
| 1029 | for (p = pv; p != e; p++) { |
| 1030 | U8 c = (U8)*p; |
| 1031 | if (! UTF8_IS_INVARIANT(c)) { |
| 1032 | *bufptr++ = UTF8_TWO_BYTE_HI(c); |
| 1033 | *bufptr++ = UTF8_TWO_BYTE_LO(c); |
| 1034 | } else { |
| 1035 | *bufptr++ = (char)c; |
| 1036 | } |
| 1037 | } |
| 1038 | } |
| 1039 | } else { |
| 1040 | if (flags & LEX_STUFF_UTF8) { |
| 1041 | STRLEN highhalf = 0; |
| 1042 | const char *p, *e = pv+len; |
| 1043 | for (p = pv; p != e; p++) { |
| 1044 | U8 c = (U8)*p; |
| 1045 | if (UTF8_IS_ABOVE_LATIN1(c)) { |
| 1046 | Perl_croak(aTHX_ "Lexing code attempted to stuff " |
| 1047 | "non-Latin-1 character into Latin-1 input"); |
| 1048 | } else if (UTF8_IS_NEXT_CHAR_DOWNGRADEABLE(p, e)) { |
| 1049 | p++; |
| 1050 | highhalf++; |
| 1051 | } else if (! UTF8_IS_INVARIANT(c)) { |
| 1052 | /* malformed UTF-8 */ |
| 1053 | ENTER; |
| 1054 | SAVESPTR(PL_warnhook); |
| 1055 | PL_warnhook = PERL_WARNHOOK_FATAL; |
| 1056 | utf8n_to_uvuni((U8*)p, e-p, NULL, 0); |
| 1057 | LEAVE; |
| 1058 | } |
| 1059 | } |
| 1060 | if (!highhalf) |
| 1061 | goto plain_copy; |
| 1062 | lex_grow_linestr(SvCUR(PL_parser->linestr)+1+len-highhalf); |
| 1063 | bufptr = PL_parser->bufptr; |
| 1064 | Move(bufptr, bufptr+len-highhalf, PL_parser->bufend+1-bufptr, char); |
| 1065 | SvCUR_set(PL_parser->linestr, |
| 1066 | SvCUR(PL_parser->linestr) + len-highhalf); |
| 1067 | PL_parser->bufend += len-highhalf; |
| 1068 | p = pv; |
| 1069 | while (p < e) { |
| 1070 | if (UTF8_IS_INVARIANT(*p)) { |
| 1071 | *bufptr++ = *p; |
| 1072 | p++; |
| 1073 | } |
| 1074 | else { |
| 1075 | assert(p < e -1 ); |
| 1076 | *bufptr++ = TWO_BYTE_UTF8_TO_UNI(*p, *(p+1)); |
| 1077 | p += 2; |
| 1078 | } |
| 1079 | } |
| 1080 | } else { |
| 1081 | plain_copy: |
| 1082 | lex_grow_linestr(SvCUR(PL_parser->linestr)+1+len); |
| 1083 | bufptr = PL_parser->bufptr; |
| 1084 | Move(bufptr, bufptr+len, PL_parser->bufend+1-bufptr, char); |
| 1085 | SvCUR_set(PL_parser->linestr, SvCUR(PL_parser->linestr) + len); |
| 1086 | PL_parser->bufend += len; |
| 1087 | Copy(pv, bufptr, len, char); |
| 1088 | } |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | /* |
| 1093 | =for apidoc Amx|void|lex_stuff_pv|const char *pv|U32 flags |
| 1094 | |
| 1095 | Insert characters into the lexer buffer (L</PL_parser-E<gt>linestr>), |
| 1096 | immediately after the current lexing point (L</PL_parser-E<gt>bufptr>), |
| 1097 | reallocating the buffer if necessary. This means that lexing code that |
| 1098 | runs later will see the characters as if they had appeared in the input. |
| 1099 | It is not recommended to do this as part of normal parsing, and most |
| 1100 | uses of this facility run the risk of the inserted characters being |
| 1101 | interpreted in an unintended manner. |
| 1102 | |
| 1103 | The string to be inserted is represented by octets starting at I<pv> |
| 1104 | and continuing to the first nul. These octets are interpreted as either |
| 1105 | UTF-8 or Latin-1, according to whether the C<LEX_STUFF_UTF8> flag is set |
| 1106 | in I<flags>. The characters are recoded for the lexer buffer, according |
| 1107 | to how the buffer is currently being interpreted (L</lex_bufutf8>). |
| 1108 | If it is not convenient to nul-terminate a string to be inserted, the |
| 1109 | L</lex_stuff_pvn> function is more appropriate. |
| 1110 | |
| 1111 | =cut |
| 1112 | */ |
| 1113 | |
| 1114 | void |
| 1115 | Perl_lex_stuff_pv(pTHX_ const char *pv, U32 flags) |
| 1116 | { |
| 1117 | PERL_ARGS_ASSERT_LEX_STUFF_PV; |
| 1118 | lex_stuff_pvn(pv, strlen(pv), flags); |
| 1119 | } |
| 1120 | |
| 1121 | /* |
| 1122 | =for apidoc Amx|void|lex_stuff_sv|SV *sv|U32 flags |
| 1123 | |
| 1124 | Insert characters into the lexer buffer (L</PL_parser-E<gt>linestr>), |
| 1125 | immediately after the current lexing point (L</PL_parser-E<gt>bufptr>), |
| 1126 | reallocating the buffer if necessary. This means that lexing code that |
| 1127 | runs later will see the characters as if they had appeared in the input. |
| 1128 | It is not recommended to do this as part of normal parsing, and most |
| 1129 | uses of this facility run the risk of the inserted characters being |
| 1130 | interpreted in an unintended manner. |
| 1131 | |
| 1132 | The string to be inserted is the string value of I<sv>. The characters |
| 1133 | are recoded for the lexer buffer, according to how the buffer is currently |
| 1134 | being interpreted (L</lex_bufutf8>). If a string to be inserted is |
| 1135 | not already a Perl scalar, the L</lex_stuff_pvn> function avoids the |
| 1136 | need to construct a scalar. |
| 1137 | |
| 1138 | =cut |
| 1139 | */ |
| 1140 | |
| 1141 | void |
| 1142 | Perl_lex_stuff_sv(pTHX_ SV *sv, U32 flags) |
| 1143 | { |
| 1144 | char *pv; |
| 1145 | STRLEN len; |
| 1146 | PERL_ARGS_ASSERT_LEX_STUFF_SV; |
| 1147 | if (flags) |
| 1148 | Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_stuff_sv"); |
| 1149 | pv = SvPV(sv, len); |
| 1150 | lex_stuff_pvn(pv, len, flags | (SvUTF8(sv) ? LEX_STUFF_UTF8 : 0)); |
| 1151 | } |
| 1152 | |
| 1153 | /* |
| 1154 | =for apidoc Amx|void|lex_unstuff|char *ptr |
| 1155 | |
| 1156 | Discards text about to be lexed, from L</PL_parser-E<gt>bufptr> up to |
| 1157 | I<ptr>. Text following I<ptr> will be moved, and the buffer shortened. |
| 1158 | This hides the discarded text from any lexing code that runs later, |
| 1159 | as if the text had never appeared. |
| 1160 | |
| 1161 | This is not the normal way to consume lexed text. For that, use |
| 1162 | L</lex_read_to>. |
| 1163 | |
| 1164 | =cut |
| 1165 | */ |
| 1166 | |
| 1167 | void |
| 1168 | Perl_lex_unstuff(pTHX_ char *ptr) |
| 1169 | { |
| 1170 | char *buf, *bufend; |
| 1171 | STRLEN unstuff_len; |
| 1172 | PERL_ARGS_ASSERT_LEX_UNSTUFF; |
| 1173 | buf = PL_parser->bufptr; |
| 1174 | if (ptr < buf) |
| 1175 | Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_unstuff"); |
| 1176 | if (ptr == buf) |
| 1177 | return; |
| 1178 | bufend = PL_parser->bufend; |
| 1179 | if (ptr > bufend) |
| 1180 | Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_unstuff"); |
| 1181 | unstuff_len = ptr - buf; |
| 1182 | Move(ptr, buf, bufend+1-ptr, char); |
| 1183 | SvCUR_set(PL_parser->linestr, SvCUR(PL_parser->linestr) - unstuff_len); |
| 1184 | PL_parser->bufend = bufend - unstuff_len; |
| 1185 | } |
| 1186 | |
| 1187 | /* |
| 1188 | =for apidoc Amx|void|lex_read_to|char *ptr |
| 1189 | |
| 1190 | Consume text in the lexer buffer, from L</PL_parser-E<gt>bufptr> up |
| 1191 | to I<ptr>. This advances L</PL_parser-E<gt>bufptr> to match I<ptr>, |
| 1192 | performing the correct bookkeeping whenever a newline character is passed. |
| 1193 | This is the normal way to consume lexed text. |
| 1194 | |
| 1195 | Interpretation of the buffer's octets can be abstracted out by |
| 1196 | using the slightly higher-level functions L</lex_peek_unichar> and |
| 1197 | L</lex_read_unichar>. |
| 1198 | |
| 1199 | =cut |
| 1200 | */ |
| 1201 | |
| 1202 | void |
| 1203 | Perl_lex_read_to(pTHX_ char *ptr) |
| 1204 | { |
| 1205 | char *s; |
| 1206 | PERL_ARGS_ASSERT_LEX_READ_TO; |
| 1207 | s = PL_parser->bufptr; |
| 1208 | if (ptr < s || ptr > PL_parser->bufend) |
| 1209 | Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_read_to"); |
| 1210 | for (; s != ptr; s++) |
| 1211 | if (*s == '\n') { |
| 1212 | COPLINE_INC_WITH_HERELINES; |
| 1213 | PL_parser->linestart = s+1; |
| 1214 | } |
| 1215 | PL_parser->bufptr = ptr; |
| 1216 | } |
| 1217 | |
| 1218 | /* |
| 1219 | =for apidoc Amx|void|lex_discard_to|char *ptr |
| 1220 | |
| 1221 | Discards the first part of the L</PL_parser-E<gt>linestr> buffer, |
| 1222 | up to I<ptr>. The remaining content of the buffer will be moved, and |
| 1223 | all pointers into the buffer updated appropriately. I<ptr> must not |
| 1224 | be later in the buffer than the position of L</PL_parser-E<gt>bufptr>: |
| 1225 | it is not permitted to discard text that has yet to be lexed. |
| 1226 | |
| 1227 | Normally it is not necessarily to do this directly, because it suffices to |
| 1228 | use the implicit discarding behaviour of L</lex_next_chunk> and things |
| 1229 | based on it. However, if a token stretches across multiple lines, |
| 1230 | and the lexing code has kept multiple lines of text in the buffer for |
| 1231 | that purpose, then after completion of the token it would be wise to |
| 1232 | explicitly discard the now-unneeded earlier lines, to avoid future |
| 1233 | multi-line tokens growing the buffer without bound. |
| 1234 | |
| 1235 | =cut |
| 1236 | */ |
| 1237 | |
| 1238 | void |
| 1239 | Perl_lex_discard_to(pTHX_ char *ptr) |
| 1240 | { |
| 1241 | char *buf; |
| 1242 | STRLEN discard_len; |
| 1243 | PERL_ARGS_ASSERT_LEX_DISCARD_TO; |
| 1244 | buf = SvPVX(PL_parser->linestr); |
| 1245 | if (ptr < buf) |
| 1246 | Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_discard_to"); |
| 1247 | if (ptr == buf) |
| 1248 | return; |
| 1249 | if (ptr > PL_parser->bufptr) |
| 1250 | Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_discard_to"); |
| 1251 | discard_len = ptr - buf; |
| 1252 | if (PL_parser->oldbufptr < ptr) |
| 1253 | PL_parser->oldbufptr = ptr; |
| 1254 | if (PL_parser->oldoldbufptr < ptr) |
| 1255 | PL_parser->oldoldbufptr = ptr; |
| 1256 | if (PL_parser->last_uni && PL_parser->last_uni < ptr) |
| 1257 | PL_parser->last_uni = NULL; |
| 1258 | if (PL_parser->last_lop && PL_parser->last_lop < ptr) |
| 1259 | PL_parser->last_lop = NULL; |
| 1260 | Move(ptr, buf, PL_parser->bufend+1-ptr, char); |
| 1261 | SvCUR_set(PL_parser->linestr, SvCUR(PL_parser->linestr) - discard_len); |
| 1262 | PL_parser->bufend -= discard_len; |
| 1263 | PL_parser->bufptr -= discard_len; |
| 1264 | PL_parser->oldbufptr -= discard_len; |
| 1265 | PL_parser->oldoldbufptr -= discard_len; |
| 1266 | if (PL_parser->last_uni) |
| 1267 | PL_parser->last_uni -= discard_len; |
| 1268 | if (PL_parser->last_lop) |
| 1269 | PL_parser->last_lop -= discard_len; |
| 1270 | } |
| 1271 | |
| 1272 | /* |
| 1273 | =for apidoc Amx|bool|lex_next_chunk|U32 flags |
| 1274 | |
| 1275 | Reads in the next chunk of text to be lexed, appending it to |
| 1276 | L</PL_parser-E<gt>linestr>. This should be called when lexing code has |
| 1277 | looked to the end of the current chunk and wants to know more. It is |
| 1278 | usual, but not necessary, for lexing to have consumed the entirety of |
| 1279 | the current chunk at this time. |
| 1280 | |
| 1281 | If L</PL_parser-E<gt>bufptr> is pointing to the very end of the current |
| 1282 | chunk (i.e., the current chunk has been entirely consumed), normally the |
| 1283 | current chunk will be discarded at the same time that the new chunk is |
| 1284 | read in. If I<flags> includes C<LEX_KEEP_PREVIOUS>, the current chunk |
| 1285 | will not be discarded. If the current chunk has not been entirely |
| 1286 | consumed, then it will not be discarded regardless of the flag. |
| 1287 | |
| 1288 | Returns true if some new text was added to the buffer, or false if the |
| 1289 | buffer has reached the end of the input text. |
| 1290 | |
| 1291 | =cut |
| 1292 | */ |
| 1293 | |
| 1294 | #define LEX_FAKE_EOF 0x80000000 |
| 1295 | #define LEX_NO_TERM 0x40000000 |
| 1296 | |
| 1297 | bool |
| 1298 | Perl_lex_next_chunk(pTHX_ U32 flags) |
| 1299 | { |
| 1300 | SV *linestr; |
| 1301 | char *buf; |
| 1302 | STRLEN old_bufend_pos, new_bufend_pos; |
| 1303 | STRLEN bufptr_pos, oldbufptr_pos, oldoldbufptr_pos; |
| 1304 | STRLEN linestart_pos, last_uni_pos, last_lop_pos; |
| 1305 | bool got_some_for_debugger = 0; |
| 1306 | bool got_some; |
| 1307 | if (flags & ~(LEX_KEEP_PREVIOUS|LEX_FAKE_EOF|LEX_NO_TERM)) |
| 1308 | Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_next_chunk"); |
| 1309 | linestr = PL_parser->linestr; |
| 1310 | buf = SvPVX(linestr); |
| 1311 | if (!(flags & LEX_KEEP_PREVIOUS) && |
| 1312 | PL_parser->bufptr == PL_parser->bufend) { |
| 1313 | old_bufend_pos = bufptr_pos = oldbufptr_pos = oldoldbufptr_pos = 0; |
| 1314 | linestart_pos = 0; |
| 1315 | if (PL_parser->last_uni != PL_parser->bufend) |
| 1316 | PL_parser->last_uni = NULL; |
| 1317 | if (PL_parser->last_lop != PL_parser->bufend) |
| 1318 | PL_parser->last_lop = NULL; |
| 1319 | last_uni_pos = last_lop_pos = 0; |
| 1320 | *buf = 0; |
| 1321 | SvCUR(linestr) = 0; |
| 1322 | } else { |
| 1323 | old_bufend_pos = PL_parser->bufend - buf; |
| 1324 | bufptr_pos = PL_parser->bufptr - buf; |
| 1325 | oldbufptr_pos = PL_parser->oldbufptr - buf; |
| 1326 | oldoldbufptr_pos = PL_parser->oldoldbufptr - buf; |
| 1327 | linestart_pos = PL_parser->linestart - buf; |
| 1328 | last_uni_pos = PL_parser->last_uni ? PL_parser->last_uni - buf : 0; |
| 1329 | last_lop_pos = PL_parser->last_lop ? PL_parser->last_lop - buf : 0; |
| 1330 | } |
| 1331 | if (flags & LEX_FAKE_EOF) { |
| 1332 | goto eof; |
| 1333 | } else if (!PL_parser->rsfp && !PL_parser->filtered) { |
| 1334 | got_some = 0; |
| 1335 | } else if (filter_gets(linestr, old_bufend_pos)) { |
| 1336 | got_some = 1; |
| 1337 | got_some_for_debugger = 1; |
| 1338 | } else if (flags & LEX_NO_TERM) { |
| 1339 | got_some = 0; |
| 1340 | } else { |
| 1341 | if (!SvPOK(linestr)) /* can get undefined by filter_gets */ |
| 1342 | sv_setpvs(linestr, ""); |
| 1343 | eof: |
| 1344 | /* End of real input. Close filehandle (unless it was STDIN), |
| 1345 | * then add implicit termination. |
| 1346 | */ |
| 1347 | if (PL_parser->lex_flags & LEX_DONT_CLOSE_RSFP) |
| 1348 | PerlIO_clearerr(PL_parser->rsfp); |
| 1349 | else if (PL_parser->rsfp) |
| 1350 | (void)PerlIO_close(PL_parser->rsfp); |
| 1351 | PL_parser->rsfp = NULL; |
| 1352 | PL_parser->in_pod = PL_parser->filtered = 0; |
| 1353 | #ifdef PERL_MAD |
| 1354 | if (PL_madskills && !PL_in_eval && (PL_minus_p || PL_minus_n)) |
| 1355 | PL_faketokens = 1; |
| 1356 | #endif |
| 1357 | if (!PL_in_eval && PL_minus_p) { |
| 1358 | sv_catpvs(linestr, |
| 1359 | /*{*/";}continue{print or die qq(-p destination: $!\\n);}"); |
| 1360 | PL_minus_n = PL_minus_p = 0; |
| 1361 | } else if (!PL_in_eval && PL_minus_n) { |
| 1362 | sv_catpvs(linestr, /*{*/";}"); |
| 1363 | PL_minus_n = 0; |
| 1364 | } else |
| 1365 | sv_catpvs(linestr, ";"); |
| 1366 | got_some = 1; |
| 1367 | } |
| 1368 | buf = SvPVX(linestr); |
| 1369 | new_bufend_pos = SvCUR(linestr); |
| 1370 | PL_parser->bufend = buf + new_bufend_pos; |
| 1371 | PL_parser->bufptr = buf + bufptr_pos; |
| 1372 | PL_parser->oldbufptr = buf + oldbufptr_pos; |
| 1373 | PL_parser->oldoldbufptr = buf + oldoldbufptr_pos; |
| 1374 | PL_parser->linestart = buf + linestart_pos; |
| 1375 | if (PL_parser->last_uni) |
| 1376 | PL_parser->last_uni = buf + last_uni_pos; |
| 1377 | if (PL_parser->last_lop) |
| 1378 | PL_parser->last_lop = buf + last_lop_pos; |
| 1379 | if (got_some_for_debugger && (PERLDB_LINE || PERLDB_SAVESRC) && |
| 1380 | PL_curstash != PL_debstash) { |
| 1381 | /* debugger active and we're not compiling the debugger code, |
| 1382 | * so store the line into the debugger's array of lines |
| 1383 | */ |
| 1384 | update_debugger_info(NULL, buf+old_bufend_pos, |
| 1385 | new_bufend_pos-old_bufend_pos); |
| 1386 | } |
| 1387 | return got_some; |
| 1388 | } |
| 1389 | |
| 1390 | /* |
| 1391 | =for apidoc Amx|I32|lex_peek_unichar|U32 flags |
| 1392 | |
| 1393 | Looks ahead one (Unicode) character in the text currently being lexed. |
| 1394 | Returns the codepoint (unsigned integer value) of the next character, |
| 1395 | or -1 if lexing has reached the end of the input text. To consume the |
| 1396 | peeked character, use L</lex_read_unichar>. |
| 1397 | |
| 1398 | If the next character is in (or extends into) the next chunk of input |
| 1399 | text, the next chunk will be read in. Normally the current chunk will be |
| 1400 | discarded at the same time, but if I<flags> includes C<LEX_KEEP_PREVIOUS> |
| 1401 | then the current chunk will not be discarded. |
| 1402 | |
| 1403 | If the input is being interpreted as UTF-8 and a UTF-8 encoding error |
| 1404 | is encountered, an exception is generated. |
| 1405 | |
| 1406 | =cut |
| 1407 | */ |
| 1408 | |
| 1409 | I32 |
| 1410 | Perl_lex_peek_unichar(pTHX_ U32 flags) |
| 1411 | { |
| 1412 | dVAR; |
| 1413 | char *s, *bufend; |
| 1414 | if (flags & ~(LEX_KEEP_PREVIOUS)) |
| 1415 | Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_peek_unichar"); |
| 1416 | s = PL_parser->bufptr; |
| 1417 | bufend = PL_parser->bufend; |
| 1418 | if (UTF) { |
| 1419 | U8 head; |
| 1420 | I32 unichar; |
| 1421 | STRLEN len, retlen; |
| 1422 | if (s == bufend) { |
| 1423 | if (!lex_next_chunk(flags)) |
| 1424 | return -1; |
| 1425 | s = PL_parser->bufptr; |
| 1426 | bufend = PL_parser->bufend; |
| 1427 | } |
| 1428 | head = (U8)*s; |
| 1429 | if (UTF8_IS_INVARIANT(head)) |
| 1430 | return head; |
| 1431 | if (UTF8_IS_START(head)) { |
| 1432 | len = UTF8SKIP(&head); |
| 1433 | while ((STRLEN)(bufend-s) < len) { |
| 1434 | if (!lex_next_chunk(flags | LEX_KEEP_PREVIOUS)) |
| 1435 | break; |
| 1436 | s = PL_parser->bufptr; |
| 1437 | bufend = PL_parser->bufend; |
| 1438 | } |
| 1439 | } |
| 1440 | unichar = utf8n_to_uvuni((U8*)s, bufend-s, &retlen, UTF8_CHECK_ONLY); |
| 1441 | if (retlen == (STRLEN)-1) { |
| 1442 | /* malformed UTF-8 */ |
| 1443 | ENTER; |
| 1444 | SAVESPTR(PL_warnhook); |
| 1445 | PL_warnhook = PERL_WARNHOOK_FATAL; |
| 1446 | utf8n_to_uvuni((U8*)s, bufend-s, NULL, 0); |
| 1447 | LEAVE; |
| 1448 | } |
| 1449 | return unichar; |
| 1450 | } else { |
| 1451 | if (s == bufend) { |
| 1452 | if (!lex_next_chunk(flags)) |
| 1453 | return -1; |
| 1454 | s = PL_parser->bufptr; |
| 1455 | } |
| 1456 | return (U8)*s; |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | /* |
| 1461 | =for apidoc Amx|I32|lex_read_unichar|U32 flags |
| 1462 | |
| 1463 | Reads the next (Unicode) character in the text currently being lexed. |
| 1464 | Returns the codepoint (unsigned integer value) of the character read, |
| 1465 | and moves L</PL_parser-E<gt>bufptr> past the character, or returns -1 |
| 1466 | if lexing has reached the end of the input text. To non-destructively |
| 1467 | examine the next character, use L</lex_peek_unichar> instead. |
| 1468 | |
| 1469 | If the next character is in (or extends into) the next chunk of input |
| 1470 | text, the next chunk will be read in. Normally the current chunk will be |
| 1471 | discarded at the same time, but if I<flags> includes C<LEX_KEEP_PREVIOUS> |
| 1472 | then the current chunk will not be discarded. |
| 1473 | |
| 1474 | If the input is being interpreted as UTF-8 and a UTF-8 encoding error |
| 1475 | is encountered, an exception is generated. |
| 1476 | |
| 1477 | =cut |
| 1478 | */ |
| 1479 | |
| 1480 | I32 |
| 1481 | Perl_lex_read_unichar(pTHX_ U32 flags) |
| 1482 | { |
| 1483 | I32 c; |
| 1484 | if (flags & ~(LEX_KEEP_PREVIOUS)) |
| 1485 | Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_read_unichar"); |
| 1486 | c = lex_peek_unichar(flags); |
| 1487 | if (c != -1) { |
| 1488 | if (c == '\n') |
| 1489 | COPLINE_INC_WITH_HERELINES; |
| 1490 | if (UTF) |
| 1491 | PL_parser->bufptr += UTF8SKIP(PL_parser->bufptr); |
| 1492 | else |
| 1493 | ++(PL_parser->bufptr); |
| 1494 | } |
| 1495 | return c; |
| 1496 | } |
| 1497 | |
| 1498 | /* |
| 1499 | =for apidoc Amx|void|lex_read_space|U32 flags |
| 1500 | |
| 1501 | Reads optional spaces, in Perl style, in the text currently being |
| 1502 | lexed. The spaces may include ordinary whitespace characters and |
| 1503 | Perl-style comments. C<#line> directives are processed if encountered. |
| 1504 | L</PL_parser-E<gt>bufptr> is moved past the spaces, so that it points |
| 1505 | at a non-space character (or the end of the input text). |
| 1506 | |
| 1507 | If spaces extend into the next chunk of input text, the next chunk will |
| 1508 | be read in. Normally the current chunk will be discarded at the same |
| 1509 | time, but if I<flags> includes C<LEX_KEEP_PREVIOUS> then the current |
| 1510 | chunk will not be discarded. |
| 1511 | |
| 1512 | =cut |
| 1513 | */ |
| 1514 | |
| 1515 | #define LEX_NO_NEXT_CHUNK 0x80000000 |
| 1516 | |
| 1517 | void |
| 1518 | Perl_lex_read_space(pTHX_ U32 flags) |
| 1519 | { |
| 1520 | char *s, *bufend; |
| 1521 | bool need_incline = 0; |
| 1522 | if (flags & ~(LEX_KEEP_PREVIOUS|LEX_NO_NEXT_CHUNK)) |
| 1523 | Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_read_space"); |
| 1524 | #ifdef PERL_MAD |
| 1525 | if (PL_skipwhite) { |
| 1526 | sv_free(PL_skipwhite); |
| 1527 | PL_skipwhite = NULL; |
| 1528 | } |
| 1529 | if (PL_madskills) |
| 1530 | PL_skipwhite = newSVpvs(""); |
| 1531 | #endif /* PERL_MAD */ |
| 1532 | s = PL_parser->bufptr; |
| 1533 | bufend = PL_parser->bufend; |
| 1534 | while (1) { |
| 1535 | char c = *s; |
| 1536 | if (c == '#') { |
| 1537 | do { |
| 1538 | c = *++s; |
| 1539 | } while (!(c == '\n' || (c == 0 && s == bufend))); |
| 1540 | } else if (c == '\n') { |
| 1541 | s++; |
| 1542 | PL_parser->linestart = s; |
| 1543 | if (s == bufend) |
| 1544 | need_incline = 1; |
| 1545 | else |
| 1546 | incline(s); |
| 1547 | } else if (isSPACE(c)) { |
| 1548 | s++; |
| 1549 | } else if (c == 0 && s == bufend) { |
| 1550 | bool got_more; |
| 1551 | #ifdef PERL_MAD |
| 1552 | if (PL_madskills) |
| 1553 | sv_catpvn(PL_skipwhite, PL_parser->bufptr, s-PL_parser->bufptr); |
| 1554 | #endif /* PERL_MAD */ |
| 1555 | if (flags & LEX_NO_NEXT_CHUNK) |
| 1556 | break; |
| 1557 | PL_parser->bufptr = s; |
| 1558 | COPLINE_INC_WITH_HERELINES; |
| 1559 | got_more = lex_next_chunk(flags); |
| 1560 | CopLINE_dec(PL_curcop); |
| 1561 | s = PL_parser->bufptr; |
| 1562 | bufend = PL_parser->bufend; |
| 1563 | if (!got_more) |
| 1564 | break; |
| 1565 | if (need_incline && PL_parser->rsfp) { |
| 1566 | incline(s); |
| 1567 | need_incline = 0; |
| 1568 | } |
| 1569 | } else { |
| 1570 | break; |
| 1571 | } |
| 1572 | } |
| 1573 | #ifdef PERL_MAD |
| 1574 | if (PL_madskills) |
| 1575 | sv_catpvn(PL_skipwhite, PL_parser->bufptr, s-PL_parser->bufptr); |
| 1576 | #endif /* PERL_MAD */ |
| 1577 | PL_parser->bufptr = s; |
| 1578 | } |
| 1579 | |
| 1580 | /* |
| 1581 | |
| 1582 | =for apidoc EXMp|bool|validate_proto|SV *name|SV *proto|bool warn |
| 1583 | |
| 1584 | This function performs syntax checking on a prototype, C<proto>. |
| 1585 | If C<warn> is true, any illegal characters or mismatched brackets |
| 1586 | will trigger illegalproto warnings, declaring that they were |
| 1587 | detected in the prototype for C<name>. |
| 1588 | |
| 1589 | The return value is C<true> if this is a valid prototype, and |
| 1590 | C<false> if it is not, regardless of whether C<warn> was C<true> or |
| 1591 | C<false>. |
| 1592 | |
| 1593 | Note that C<NULL> is a valid C<proto> and will always return C<true>. |
| 1594 | |
| 1595 | =cut |
| 1596 | |
| 1597 | */ |
| 1598 | |
| 1599 | bool |
| 1600 | Perl_validate_proto(pTHX_ SV *name, SV *proto, bool warn) |
| 1601 | { |
| 1602 | STRLEN len, origlen; |
| 1603 | char *p = proto ? SvPV(proto, len) : NULL; |
| 1604 | bool bad_proto = FALSE; |
| 1605 | bool in_brackets = FALSE; |
| 1606 | bool after_slash = FALSE; |
| 1607 | char greedy_proto = ' '; |
| 1608 | bool proto_after_greedy_proto = FALSE; |
| 1609 | bool must_be_last = FALSE; |
| 1610 | bool underscore = FALSE; |
| 1611 | bool seen_underscore = FALSE; |
| 1612 | |
| 1613 | PERL_ARGS_ASSERT_VALIDATE_PROTO; |
| 1614 | |
| 1615 | if (!proto) |
| 1616 | return TRUE; |
| 1617 | |
| 1618 | origlen = len; |
| 1619 | for (; len--; p++) { |
| 1620 | if (!isSPACE(*p)) { |
| 1621 | if (must_be_last) |
| 1622 | proto_after_greedy_proto = TRUE; |
| 1623 | if (!strchr("$@%*;[]&\\_+", *p) || *p == '\0') { |
| 1624 | bad_proto = TRUE; |
| 1625 | } |
| 1626 | else { |
| 1627 | if (underscore) { |
| 1628 | if(!strchr(";@%", *p)) |
| 1629 | bad_proto = TRUE; |
| 1630 | underscore = FALSE; |
| 1631 | } |
| 1632 | |
| 1633 | if (*p == '[') |
| 1634 | in_brackets = TRUE; |
| 1635 | else if (*p == ']') |
| 1636 | in_brackets = FALSE; |
| 1637 | else if ((*p == '@' || *p == '%') && |
| 1638 | !after_slash && |
| 1639 | !in_brackets ) { |
| 1640 | must_be_last = TRUE; |
| 1641 | greedy_proto = *p; |
| 1642 | } |
| 1643 | else if (*p == '_') |
| 1644 | underscore = seen_underscore = TRUE; |
| 1645 | } |
| 1646 | if (*p == '\\') |
| 1647 | after_slash = TRUE; |
| 1648 | else |
| 1649 | after_slash = FALSE; |
| 1650 | } |
| 1651 | } |
| 1652 | |
| 1653 | if (warn) { |
| 1654 | SV *tmpsv = newSVpvs_flags("", SVs_TEMP); |
| 1655 | p -= origlen; |
| 1656 | p = SvUTF8(proto) |
| 1657 | ? sv_uni_display(tmpsv, newSVpvn_flags(p, origlen, SVs_TEMP | SVf_UTF8), |
| 1658 | origlen, UNI_DISPLAY_ISPRINT) |
| 1659 | : pv_pretty(tmpsv, p, origlen, 60, NULL, NULL, PERL_PV_ESCAPE_NONASCII); |
| 1660 | |
| 1661 | if (proto_after_greedy_proto) |
| 1662 | Perl_warner(aTHX_ packWARN(WARN_ILLEGALPROTO), |
| 1663 | "Prototype after '%c' for %"SVf" : %s", |
| 1664 | greedy_proto, SVfARG(name), p); |
| 1665 | if (bad_proto) |
| 1666 | Perl_warner(aTHX_ packWARN(WARN_ILLEGALPROTO), |
| 1667 | "Illegal character %sin prototype for %"SVf" : %s", |
| 1668 | seen_underscore ? "after '_' " : "", SVfARG(name), p); |
| 1669 | } |
| 1670 | |
| 1671 | return (! (proto_after_greedy_proto || bad_proto) ); |
| 1672 | } |
| 1673 | |
| 1674 | /* |
| 1675 | * S_incline |
| 1676 | * This subroutine has nothing to do with tilting, whether at windmills |
| 1677 | * or pinball tables. Its name is short for "increment line". It |
| 1678 | * increments the current line number in CopLINE(PL_curcop) and checks |
| 1679 | * to see whether the line starts with a comment of the form |
| 1680 | * # line 500 "foo.pm" |
| 1681 | * If so, it sets the current line number and file to the values in the comment. |
| 1682 | */ |
| 1683 | |
| 1684 | STATIC void |
| 1685 | S_incline(pTHX_ const char *s) |
| 1686 | { |
| 1687 | dVAR; |
| 1688 | const char *t; |
| 1689 | const char *n; |
| 1690 | const char *e; |
| 1691 | line_t line_num; |
| 1692 | |
| 1693 | PERL_ARGS_ASSERT_INCLINE; |
| 1694 | |
| 1695 | COPLINE_INC_WITH_HERELINES; |
| 1696 | if (!PL_rsfp && !PL_parser->filtered && PL_lex_state == LEX_NORMAL |
| 1697 | && s+1 == PL_bufend && *s == ';') { |
| 1698 | /* fake newline in string eval */ |
| 1699 | CopLINE_dec(PL_curcop); |
| 1700 | return; |
| 1701 | } |
| 1702 | if (*s++ != '#') |
| 1703 | return; |
| 1704 | while (SPACE_OR_TAB(*s)) |
| 1705 | s++; |
| 1706 | if (strnEQ(s, "line", 4)) |
| 1707 | s += 4; |
| 1708 | else |
| 1709 | return; |
| 1710 | if (SPACE_OR_TAB(*s)) |
| 1711 | s++; |
| 1712 | else |
| 1713 | return; |
| 1714 | while (SPACE_OR_TAB(*s)) |
| 1715 | s++; |
| 1716 | if (!isDIGIT(*s)) |
| 1717 | return; |
| 1718 | |
| 1719 | n = s; |
| 1720 | while (isDIGIT(*s)) |
| 1721 | s++; |
| 1722 | if (!SPACE_OR_TAB(*s) && *s != '\r' && *s != '\n' && *s != '\0') |
| 1723 | return; |
| 1724 | while (SPACE_OR_TAB(*s)) |
| 1725 | s++; |
| 1726 | if (*s == '"' && (t = strchr(s+1, '"'))) { |
| 1727 | s++; |
| 1728 | e = t + 1; |
| 1729 | } |
| 1730 | else { |
| 1731 | t = s; |
| 1732 | while (!isSPACE(*t)) |
| 1733 | t++; |
| 1734 | e = t; |
| 1735 | } |
| 1736 | while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f') |
| 1737 | e++; |
| 1738 | if (*e != '\n' && *e != '\0') |
| 1739 | return; /* false alarm */ |
| 1740 | |
| 1741 | line_num = atoi(n)-1; |
| 1742 | |
| 1743 | if (t - s > 0) { |
| 1744 | const STRLEN len = t - s; |
| 1745 | SV *const temp_sv = CopFILESV(PL_curcop); |
| 1746 | const char *cf; |
| 1747 | STRLEN tmplen; |
| 1748 | |
| 1749 | if (temp_sv) { |
| 1750 | cf = SvPVX(temp_sv); |
| 1751 | tmplen = SvCUR(temp_sv); |
| 1752 | } else { |
| 1753 | cf = NULL; |
| 1754 | tmplen = 0; |
| 1755 | } |
| 1756 | |
| 1757 | if (!PL_rsfp && !PL_parser->filtered) { |
| 1758 | /* must copy *{"::_<(eval N)[oldfilename:L]"} |
| 1759 | * to *{"::_<newfilename"} */ |
| 1760 | /* However, the long form of evals is only turned on by the |
| 1761 | debugger - usually they're "(eval %lu)" */ |
| 1762 | char smallbuf[128]; |
| 1763 | char *tmpbuf; |
| 1764 | GV **gvp; |
| 1765 | STRLEN tmplen2 = len; |
| 1766 | if (tmplen + 2 <= sizeof smallbuf) |
| 1767 | tmpbuf = smallbuf; |
| 1768 | else |
| 1769 | Newx(tmpbuf, tmplen + 2, char); |
| 1770 | tmpbuf[0] = '_'; |
| 1771 | tmpbuf[1] = '<'; |
| 1772 | memcpy(tmpbuf + 2, cf, tmplen); |
| 1773 | tmplen += 2; |
| 1774 | gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE); |
| 1775 | if (gvp) { |
| 1776 | char *tmpbuf2; |
| 1777 | GV *gv2; |
| 1778 | |
| 1779 | if (tmplen2 + 2 <= sizeof smallbuf) |
| 1780 | tmpbuf2 = smallbuf; |
| 1781 | else |
| 1782 | Newx(tmpbuf2, tmplen2 + 2, char); |
| 1783 | |
| 1784 | if (tmpbuf2 != smallbuf || tmpbuf != smallbuf) { |
| 1785 | /* Either they malloc'd it, or we malloc'd it, |
| 1786 | so no prefix is present in ours. */ |
| 1787 | tmpbuf2[0] = '_'; |
| 1788 | tmpbuf2[1] = '<'; |
| 1789 | } |
| 1790 | |
| 1791 | memcpy(tmpbuf2 + 2, s, tmplen2); |
| 1792 | tmplen2 += 2; |
| 1793 | |
| 1794 | gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE); |
| 1795 | if (!isGV(gv2)) { |
| 1796 | gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE); |
| 1797 | /* adjust ${"::_<newfilename"} to store the new file name */ |
| 1798 | GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2); |
| 1799 | /* The line number may differ. If that is the case, |
| 1800 | alias the saved lines that are in the array. |
| 1801 | Otherwise alias the whole array. */ |
| 1802 | if (CopLINE(PL_curcop) == line_num) { |
| 1803 | GvHV(gv2) = MUTABLE_HV(SvREFCNT_inc(GvHV(*gvp))); |
| 1804 | GvAV(gv2) = MUTABLE_AV(SvREFCNT_inc(GvAV(*gvp))); |
| 1805 | } |
| 1806 | else if (GvAV(*gvp)) { |
| 1807 | AV * const av = GvAV(*gvp); |
| 1808 | const I32 start = CopLINE(PL_curcop)+1; |
| 1809 | I32 items = AvFILLp(av) - start; |
| 1810 | if (items > 0) { |
| 1811 | AV * const av2 = GvAVn(gv2); |
| 1812 | SV **svp = AvARRAY(av) + start; |
| 1813 | I32 l = (I32)line_num+1; |
| 1814 | while (items--) |
| 1815 | av_store(av2, l++, SvREFCNT_inc(*svp++)); |
| 1816 | } |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | if (tmpbuf2 != smallbuf) Safefree(tmpbuf2); |
| 1821 | } |
| 1822 | if (tmpbuf != smallbuf) Safefree(tmpbuf); |
| 1823 | } |
| 1824 | CopFILE_free(PL_curcop); |
| 1825 | CopFILE_setn(PL_curcop, s, len); |
| 1826 | } |
| 1827 | CopLINE_set(PL_curcop, line_num); |
| 1828 | } |
| 1829 | |
| 1830 | #ifdef PERL_MAD |
| 1831 | /* skip space before PL_thistoken */ |
| 1832 | |
| 1833 | STATIC char * |
| 1834 | S_skipspace0(pTHX_ char *s) |
| 1835 | { |
| 1836 | PERL_ARGS_ASSERT_SKIPSPACE0; |
| 1837 | |
| 1838 | s = skipspace(s); |
| 1839 | if (!PL_madskills) |
| 1840 | return s; |
| 1841 | if (PL_skipwhite) { |
| 1842 | if (!PL_thiswhite) |
| 1843 | PL_thiswhite = newSVpvs(""); |
| 1844 | sv_catsv(PL_thiswhite, PL_skipwhite); |
| 1845 | sv_free(PL_skipwhite); |
| 1846 | PL_skipwhite = 0; |
| 1847 | } |
| 1848 | PL_realtokenstart = s - SvPVX(PL_linestr); |
| 1849 | return s; |
| 1850 | } |
| 1851 | |
| 1852 | /* skip space after PL_thistoken */ |
| 1853 | |
| 1854 | STATIC char * |
| 1855 | S_skipspace1(pTHX_ char *s) |
| 1856 | { |
| 1857 | const char *start = s; |
| 1858 | I32 startoff = start - SvPVX(PL_linestr); |
| 1859 | |
| 1860 | PERL_ARGS_ASSERT_SKIPSPACE1; |
| 1861 | |
| 1862 | s = skipspace(s); |
| 1863 | if (!PL_madskills) |
| 1864 | return s; |
| 1865 | start = SvPVX(PL_linestr) + startoff; |
| 1866 | if (!PL_thistoken && PL_realtokenstart >= 0) { |
| 1867 | const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart; |
| 1868 | PL_thistoken = newSVpvn(tstart, start - tstart); |
| 1869 | } |
| 1870 | PL_realtokenstart = -1; |
| 1871 | if (PL_skipwhite) { |
| 1872 | if (!PL_nextwhite) |
| 1873 | PL_nextwhite = newSVpvs(""); |
| 1874 | sv_catsv(PL_nextwhite, PL_skipwhite); |
| 1875 | sv_free(PL_skipwhite); |
| 1876 | PL_skipwhite = 0; |
| 1877 | } |
| 1878 | return s; |
| 1879 | } |
| 1880 | |
| 1881 | STATIC char * |
| 1882 | S_skipspace2(pTHX_ char *s, SV **svp) |
| 1883 | { |
| 1884 | char *start; |
| 1885 | const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr); |
| 1886 | const I32 startoff = s - SvPVX(PL_linestr); |
| 1887 | |
| 1888 | PERL_ARGS_ASSERT_SKIPSPACE2; |
| 1889 | |
| 1890 | s = skipspace(s); |
| 1891 | PL_bufptr = SvPVX(PL_linestr) + bufptroff; |
| 1892 | if (!PL_madskills || !svp) |
| 1893 | return s; |
| 1894 | start = SvPVX(PL_linestr) + startoff; |
| 1895 | if (!PL_thistoken && PL_realtokenstart >= 0) { |
| 1896 | char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart; |
| 1897 | PL_thistoken = newSVpvn(tstart, start - tstart); |
| 1898 | PL_realtokenstart = -1; |
| 1899 | } |
| 1900 | if (PL_skipwhite) { |
| 1901 | if (!*svp) |
| 1902 | *svp = newSVpvs(""); |
| 1903 | sv_setsv(*svp, PL_skipwhite); |
| 1904 | sv_free(PL_skipwhite); |
| 1905 | PL_skipwhite = 0; |
| 1906 | } |
| 1907 | |
| 1908 | return s; |
| 1909 | } |
| 1910 | #endif |
| 1911 | |
| 1912 | STATIC void |
| 1913 | S_update_debugger_info(pTHX_ SV *orig_sv, const char *const buf, STRLEN len) |
| 1914 | { |
| 1915 | AV *av = CopFILEAVx(PL_curcop); |
| 1916 | if (av) { |
| 1917 | SV * const sv = newSV_type(SVt_PVMG); |
| 1918 | if (orig_sv) |
| 1919 | sv_setsv(sv, orig_sv); |
| 1920 | else |
| 1921 | sv_setpvn(sv, buf, len); |
| 1922 | (void)SvIOK_on(sv); |
| 1923 | SvIV_set(sv, 0); |
| 1924 | av_store(av, (I32)CopLINE(PL_curcop), sv); |
| 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | /* |
| 1929 | * S_skipspace |
| 1930 | * Called to gobble the appropriate amount and type of whitespace. |
| 1931 | * Skips comments as well. |
| 1932 | */ |
| 1933 | |
| 1934 | STATIC char * |
| 1935 | S_skipspace(pTHX_ char *s) |
| 1936 | { |
| 1937 | #ifdef PERL_MAD |
| 1938 | char *start = s; |
| 1939 | #endif /* PERL_MAD */ |
| 1940 | PERL_ARGS_ASSERT_SKIPSPACE; |
| 1941 | #ifdef PERL_MAD |
| 1942 | if (PL_skipwhite) { |
| 1943 | sv_free(PL_skipwhite); |
| 1944 | PL_skipwhite = NULL; |
| 1945 | } |
| 1946 | #endif /* PERL_MAD */ |
| 1947 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
| 1948 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
| 1949 | s++; |
| 1950 | } else { |
| 1951 | STRLEN bufptr_pos = PL_bufptr - SvPVX(PL_linestr); |
| 1952 | PL_bufptr = s; |
| 1953 | lex_read_space(LEX_KEEP_PREVIOUS | |
| 1954 | (PL_sublex_info.sub_inwhat || PL_lex_state == LEX_FORMLINE ? |
| 1955 | LEX_NO_NEXT_CHUNK : 0)); |
| 1956 | s = PL_bufptr; |
| 1957 | PL_bufptr = SvPVX(PL_linestr) + bufptr_pos; |
| 1958 | if (PL_linestart > PL_bufptr) |
| 1959 | PL_bufptr = PL_linestart; |
| 1960 | return s; |
| 1961 | } |
| 1962 | #ifdef PERL_MAD |
| 1963 | if (PL_madskills) |
| 1964 | PL_skipwhite = newSVpvn(start, s-start); |
| 1965 | #endif /* PERL_MAD */ |
| 1966 | return s; |
| 1967 | } |
| 1968 | |
| 1969 | /* |
| 1970 | * S_check_uni |
| 1971 | * Check the unary operators to ensure there's no ambiguity in how they're |
| 1972 | * used. An ambiguous piece of code would be: |
| 1973 | * rand + 5 |
| 1974 | * This doesn't mean rand() + 5. Because rand() is a unary operator, |
| 1975 | * the +5 is its argument. |
| 1976 | */ |
| 1977 | |
| 1978 | STATIC void |
| 1979 | S_check_uni(pTHX) |
| 1980 | { |
| 1981 | dVAR; |
| 1982 | const char *s; |
| 1983 | const char *t; |
| 1984 | |
| 1985 | if (PL_oldoldbufptr != PL_last_uni) |
| 1986 | return; |
| 1987 | while (isSPACE(*PL_last_uni)) |
| 1988 | PL_last_uni++; |
| 1989 | s = PL_last_uni; |
| 1990 | while (isWORDCHAR_lazy_if(s,UTF) || *s == '-') |
| 1991 | s++; |
| 1992 | if ((t = strchr(s, '(')) && t < PL_bufptr) |
| 1993 | return; |
| 1994 | |
| 1995 | Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 1996 | "Warning: Use of \"%.*s\" without parentheses is ambiguous", |
| 1997 | (int)(s - PL_last_uni), PL_last_uni); |
| 1998 | } |
| 1999 | |
| 2000 | /* |
| 2001 | * LOP : macro to build a list operator. Its behaviour has been replaced |
| 2002 | * with a subroutine, S_lop() for which LOP is just another name. |
| 2003 | */ |
| 2004 | |
| 2005 | #define LOP(f,x) return lop(f,x,s) |
| 2006 | |
| 2007 | /* |
| 2008 | * S_lop |
| 2009 | * Build a list operator (or something that might be one). The rules: |
| 2010 | * - if we have a next token, then it's a list operator [why?] |
| 2011 | * - if the next thing is an opening paren, then it's a function |
| 2012 | * - else it's a list operator |
| 2013 | */ |
| 2014 | |
| 2015 | STATIC I32 |
| 2016 | S_lop(pTHX_ I32 f, int x, char *s) |
| 2017 | { |
| 2018 | dVAR; |
| 2019 | |
| 2020 | PERL_ARGS_ASSERT_LOP; |
| 2021 | |
| 2022 | pl_yylval.ival = f; |
| 2023 | CLINE; |
| 2024 | PL_expect = x; |
| 2025 | PL_bufptr = s; |
| 2026 | PL_last_lop = PL_oldbufptr; |
| 2027 | PL_last_lop_op = (OPCODE)f; |
| 2028 | #ifdef PERL_MAD |
| 2029 | if (PL_lasttoke) |
| 2030 | goto lstop; |
| 2031 | #else |
| 2032 | if (PL_nexttoke) |
| 2033 | goto lstop; |
| 2034 | #endif |
| 2035 | if (*s == '(') |
| 2036 | return REPORT(FUNC); |
| 2037 | s = PEEKSPACE(s); |
| 2038 | if (*s == '(') |
| 2039 | return REPORT(FUNC); |
| 2040 | else { |
| 2041 | lstop: |
| 2042 | if (!PL_lex_allbrackets && PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC) |
| 2043 | PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC; |
| 2044 | return REPORT(LSTOP); |
| 2045 | } |
| 2046 | } |
| 2047 | |
| 2048 | #ifdef PERL_MAD |
| 2049 | /* |
| 2050 | * S_start_force |
| 2051 | * Sets up for an eventual force_next(). start_force(0) basically does |
| 2052 | * an unshift, while start_force(-1) does a push. yylex removes items |
| 2053 | * on the "pop" end. |
| 2054 | */ |
| 2055 | |
| 2056 | STATIC void |
| 2057 | S_start_force(pTHX_ int where) |
| 2058 | { |
| 2059 | int i; |
| 2060 | |
| 2061 | if (where < 0) /* so people can duplicate start_force(PL_curforce) */ |
| 2062 | where = PL_lasttoke; |
| 2063 | assert(PL_curforce < 0 || PL_curforce == where); |
| 2064 | if (PL_curforce != where) { |
| 2065 | for (i = PL_lasttoke; i > where; --i) { |
| 2066 | PL_nexttoke[i] = PL_nexttoke[i-1]; |
| 2067 | } |
| 2068 | PL_lasttoke++; |
| 2069 | } |
| 2070 | if (PL_curforce < 0) /* in case of duplicate start_force() */ |
| 2071 | Zero(&PL_nexttoke[where], 1, NEXTTOKE); |
| 2072 | PL_curforce = where; |
| 2073 | if (PL_nextwhite) { |
| 2074 | if (PL_madskills) |
| 2075 | curmad('^', newSVpvs("")); |
| 2076 | CURMAD('_', PL_nextwhite); |
| 2077 | } |
| 2078 | } |
| 2079 | |
| 2080 | STATIC void |
| 2081 | S_curmad(pTHX_ char slot, SV *sv) |
| 2082 | { |
| 2083 | MADPROP **where; |
| 2084 | |
| 2085 | if (!sv) |
| 2086 | return; |
| 2087 | if (PL_curforce < 0) |
| 2088 | where = &PL_thismad; |
| 2089 | else |
| 2090 | where = &PL_nexttoke[PL_curforce].next_mad; |
| 2091 | |
| 2092 | if (PL_faketokens) |
| 2093 | sv_setpvs(sv, ""); |
| 2094 | else { |
| 2095 | if (!IN_BYTES) { |
| 2096 | if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv))) |
| 2097 | SvUTF8_on(sv); |
| 2098 | else if (PL_encoding) { |
| 2099 | sv_recode_to_utf8(sv, PL_encoding); |
| 2100 | } |
| 2101 | } |
| 2102 | } |
| 2103 | |
| 2104 | /* keep a slot open for the head of the list? */ |
| 2105 | if (slot != '_' && *where && (*where)->mad_key == '^') { |
| 2106 | (*where)->mad_key = slot; |
| 2107 | sv_free(MUTABLE_SV(((*where)->mad_val))); |
| 2108 | (*where)->mad_val = (void*)sv; |
| 2109 | } |
| 2110 | else |
| 2111 | addmad(newMADsv(slot, sv), where, 0); |
| 2112 | } |
| 2113 | #else |
| 2114 | # define start_force(where) NOOP |
| 2115 | # define curmad(slot, sv) NOOP |
| 2116 | #endif |
| 2117 | |
| 2118 | /* |
| 2119 | * S_force_next |
| 2120 | * When the lexer realizes it knows the next token (for instance, |
| 2121 | * it is reordering tokens for the parser) then it can call S_force_next |
| 2122 | * to know what token to return the next time the lexer is called. Caller |
| 2123 | * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD), |
| 2124 | * and possibly PL_expect to ensure the lexer handles the token correctly. |
| 2125 | */ |
| 2126 | |
| 2127 | STATIC void |
| 2128 | S_force_next(pTHX_ I32 type) |
| 2129 | { |
| 2130 | dVAR; |
| 2131 | #ifdef DEBUGGING |
| 2132 | if (DEBUG_T_TEST) { |
| 2133 | PerlIO_printf(Perl_debug_log, "### forced token:\n"); |
| 2134 | tokereport(type, &NEXTVAL_NEXTTOKE); |
| 2135 | } |
| 2136 | #endif |
| 2137 | #ifdef PERL_MAD |
| 2138 | if (PL_curforce < 0) |
| 2139 | start_force(PL_lasttoke); |
| 2140 | PL_nexttoke[PL_curforce].next_type = type; |
| 2141 | if (PL_lex_state != LEX_KNOWNEXT) |
| 2142 | PL_lex_defer = PL_lex_state; |
| 2143 | PL_lex_state = LEX_KNOWNEXT; |
| 2144 | PL_lex_expect = PL_expect; |
| 2145 | PL_curforce = -1; |
| 2146 | #else |
| 2147 | PL_nexttype[PL_nexttoke] = type; |
| 2148 | PL_nexttoke++; |
| 2149 | if (PL_lex_state != LEX_KNOWNEXT) { |
| 2150 | PL_lex_defer = PL_lex_state; |
| 2151 | PL_lex_expect = PL_expect; |
| 2152 | PL_lex_state = LEX_KNOWNEXT; |
| 2153 | } |
| 2154 | #endif |
| 2155 | } |
| 2156 | |
| 2157 | void |
| 2158 | Perl_yyunlex(pTHX) |
| 2159 | { |
| 2160 | int yyc = PL_parser->yychar; |
| 2161 | if (yyc != YYEMPTY) { |
| 2162 | if (yyc) { |
| 2163 | start_force(-1); |
| 2164 | NEXTVAL_NEXTTOKE = PL_parser->yylval; |
| 2165 | if (yyc == '{'/*}*/ || yyc == HASHBRACK || yyc == '['/*]*/) { |
| 2166 | PL_lex_allbrackets--; |
| 2167 | PL_lex_brackets--; |
| 2168 | yyc |= (3<<24) | (PL_lex_brackstack[PL_lex_brackets] << 16); |
| 2169 | } else if (yyc == '('/*)*/) { |
| 2170 | PL_lex_allbrackets--; |
| 2171 | yyc |= (2<<24); |
| 2172 | } |
| 2173 | force_next(yyc); |
| 2174 | } |
| 2175 | PL_parser->yychar = YYEMPTY; |
| 2176 | } |
| 2177 | } |
| 2178 | |
| 2179 | STATIC SV * |
| 2180 | S_newSV_maybe_utf8(pTHX_ const char *const start, STRLEN len) |
| 2181 | { |
| 2182 | dVAR; |
| 2183 | SV * const sv = newSVpvn_utf8(start, len, |
| 2184 | !IN_BYTES |
| 2185 | && UTF |
| 2186 | && !is_ascii_string((const U8*)start, len) |
| 2187 | && is_utf8_string((const U8*)start, len)); |
| 2188 | return sv; |
| 2189 | } |
| 2190 | |
| 2191 | /* |
| 2192 | * S_force_word |
| 2193 | * When the lexer knows the next thing is a word (for instance, it has |
| 2194 | * just seen -> and it knows that the next char is a word char, then |
| 2195 | * it calls S_force_word to stick the next word into the PL_nexttoke/val |
| 2196 | * lookahead. |
| 2197 | * |
| 2198 | * Arguments: |
| 2199 | * char *start : buffer position (must be within PL_linestr) |
| 2200 | * int token : PL_next* will be this type of bare word (e.g., METHOD,WORD) |
| 2201 | * int check_keyword : if true, Perl checks to make sure the word isn't |
| 2202 | * a keyword (do this if the word is a label, e.g. goto FOO) |
| 2203 | * int allow_pack : if true, : characters will also be allowed (require, |
| 2204 | * use, etc. do this) |
| 2205 | * int allow_initial_tick : used by the "sub" lexer only. |
| 2206 | */ |
| 2207 | |
| 2208 | STATIC char * |
| 2209 | S_force_word(pTHX_ char *start, int token, int check_keyword, int allow_pack) |
| 2210 | { |
| 2211 | dVAR; |
| 2212 | char *s; |
| 2213 | STRLEN len; |
| 2214 | |
| 2215 | PERL_ARGS_ASSERT_FORCE_WORD; |
| 2216 | |
| 2217 | start = SKIPSPACE1(start); |
| 2218 | s = start; |
| 2219 | if (isIDFIRST_lazy_if(s,UTF) || |
| 2220 | (allow_pack && *s == ':') ) |
| 2221 | { |
| 2222 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len); |
| 2223 | if (check_keyword) { |
| 2224 | char *s2 = PL_tokenbuf; |
| 2225 | if (allow_pack && len > 6 && strnEQ(s2, "CORE::", 6)) |
| 2226 | s2 += 6, len -= 6; |
| 2227 | if (keyword(s2, len, 0)) |
| 2228 | return start; |
| 2229 | } |
| 2230 | start_force(PL_curforce); |
| 2231 | if (PL_madskills) |
| 2232 | curmad('X', newSVpvn(start,s-start)); |
| 2233 | if (token == METHOD) { |
| 2234 | s = SKIPSPACE1(s); |
| 2235 | if (*s == '(') |
| 2236 | PL_expect = XTERM; |
| 2237 | else { |
| 2238 | PL_expect = XOPERATOR; |
| 2239 | } |
| 2240 | } |
| 2241 | if (PL_madskills) |
| 2242 | curmad('g', newSVpvs( "forced" )); |
| 2243 | NEXTVAL_NEXTTOKE.opval |
| 2244 | = (OP*)newSVOP(OP_CONST,0, |
| 2245 | S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len)); |
| 2246 | NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE; |
| 2247 | force_next(token); |
| 2248 | } |
| 2249 | return s; |
| 2250 | } |
| 2251 | |
| 2252 | /* |
| 2253 | * S_force_ident |
| 2254 | * Called when the lexer wants $foo *foo &foo etc, but the program |
| 2255 | * text only contains the "foo" portion. The first argument is a pointer |
| 2256 | * to the "foo", and the second argument is the type symbol to prefix. |
| 2257 | * Forces the next token to be a "WORD". |
| 2258 | * Creates the symbol if it didn't already exist (via gv_fetchpv()). |
| 2259 | */ |
| 2260 | |
| 2261 | STATIC void |
| 2262 | S_force_ident(pTHX_ const char *s, int kind) |
| 2263 | { |
| 2264 | dVAR; |
| 2265 | |
| 2266 | PERL_ARGS_ASSERT_FORCE_IDENT; |
| 2267 | |
| 2268 | if (s[0]) { |
| 2269 | const STRLEN len = s[1] ? strlen(s) : 1; /* s = "\"" see yylex */ |
| 2270 | OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn_flags(s, len, |
| 2271 | UTF ? SVf_UTF8 : 0)); |
| 2272 | start_force(PL_curforce); |
| 2273 | NEXTVAL_NEXTTOKE.opval = o; |
| 2274 | force_next(WORD); |
| 2275 | if (kind) { |
| 2276 | o->op_private = OPpCONST_ENTERED; |
| 2277 | /* XXX see note in pp_entereval() for why we forgo typo |
| 2278 | warnings if the symbol must be introduced in an eval. |
| 2279 | GSAR 96-10-12 */ |
| 2280 | gv_fetchpvn_flags(s, len, |
| 2281 | (PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) |
| 2282 | : GV_ADD) | ( UTF ? SVf_UTF8 : 0 ), |
| 2283 | kind == '$' ? SVt_PV : |
| 2284 | kind == '@' ? SVt_PVAV : |
| 2285 | kind == '%' ? SVt_PVHV : |
| 2286 | SVt_PVGV |
| 2287 | ); |
| 2288 | } |
| 2289 | } |
| 2290 | } |
| 2291 | |
| 2292 | static void |
| 2293 | S_force_ident_maybe_lex(pTHX_ char pit) |
| 2294 | { |
| 2295 | start_force(PL_curforce); |
| 2296 | NEXTVAL_NEXTTOKE.ival = pit; |
| 2297 | force_next('p'); |
| 2298 | } |
| 2299 | |
| 2300 | NV |
| 2301 | Perl_str_to_version(pTHX_ SV *sv) |
| 2302 | { |
| 2303 | NV retval = 0.0; |
| 2304 | NV nshift = 1.0; |
| 2305 | STRLEN len; |
| 2306 | const char *start = SvPV_const(sv,len); |
| 2307 | const char * const end = start + len; |
| 2308 | const bool utf = SvUTF8(sv) ? TRUE : FALSE; |
| 2309 | |
| 2310 | PERL_ARGS_ASSERT_STR_TO_VERSION; |
| 2311 | |
| 2312 | while (start < end) { |
| 2313 | STRLEN skip; |
| 2314 | UV n; |
| 2315 | if (utf) |
| 2316 | n = utf8n_to_uvchr((U8*)start, len, &skip, 0); |
| 2317 | else { |
| 2318 | n = *(U8*)start; |
| 2319 | skip = 1; |
| 2320 | } |
| 2321 | retval += ((NV)n)/nshift; |
| 2322 | start += skip; |
| 2323 | nshift *= 1000; |
| 2324 | } |
| 2325 | return retval; |
| 2326 | } |
| 2327 | |
| 2328 | /* |
| 2329 | * S_force_version |
| 2330 | * Forces the next token to be a version number. |
| 2331 | * If the next token appears to be an invalid version number, (e.g. "v2b"), |
| 2332 | * and if "guessing" is TRUE, then no new token is created (and the caller |
| 2333 | * must use an alternative parsing method). |
| 2334 | */ |
| 2335 | |
| 2336 | STATIC char * |
| 2337 | S_force_version(pTHX_ char *s, int guessing) |
| 2338 | { |
| 2339 | dVAR; |
| 2340 | OP *version = NULL; |
| 2341 | char *d; |
| 2342 | #ifdef PERL_MAD |
| 2343 | I32 startoff = s - SvPVX(PL_linestr); |
| 2344 | #endif |
| 2345 | |
| 2346 | PERL_ARGS_ASSERT_FORCE_VERSION; |
| 2347 | |
| 2348 | s = SKIPSPACE1(s); |
| 2349 | |
| 2350 | d = s; |
| 2351 | if (*d == 'v') |
| 2352 | d++; |
| 2353 | if (isDIGIT(*d)) { |
| 2354 | while (isDIGIT(*d) || *d == '_' || *d == '.') |
| 2355 | d++; |
| 2356 | #ifdef PERL_MAD |
| 2357 | if (PL_madskills) { |
| 2358 | start_force(PL_curforce); |
| 2359 | curmad('X', newSVpvn(s,d-s)); |
| 2360 | } |
| 2361 | #endif |
| 2362 | if (*d == ';' || isSPACE(*d) || *d == '{' || *d == '}' || !*d) { |
| 2363 | SV *ver; |
| 2364 | #ifdef USE_LOCALE_NUMERIC |
| 2365 | char *loc = savepv(setlocale(LC_NUMERIC, NULL)); |
| 2366 | setlocale(LC_NUMERIC, "C"); |
| 2367 | #endif |
| 2368 | s = scan_num(s, &pl_yylval); |
| 2369 | #ifdef USE_LOCALE_NUMERIC |
| 2370 | setlocale(LC_NUMERIC, loc); |
| 2371 | Safefree(loc); |
| 2372 | #endif |
| 2373 | version = pl_yylval.opval; |
| 2374 | ver = cSVOPx(version)->op_sv; |
| 2375 | if (SvPOK(ver) && !SvNIOK(ver)) { |
| 2376 | SvUPGRADE(ver, SVt_PVNV); |
| 2377 | SvNV_set(ver, str_to_version(ver)); |
| 2378 | SvNOK_on(ver); /* hint that it is a version */ |
| 2379 | } |
| 2380 | } |
| 2381 | else if (guessing) { |
| 2382 | #ifdef PERL_MAD |
| 2383 | if (PL_madskills) { |
| 2384 | sv_free(PL_nextwhite); /* let next token collect whitespace */ |
| 2385 | PL_nextwhite = 0; |
| 2386 | s = SvPVX(PL_linestr) + startoff; |
| 2387 | } |
| 2388 | #endif |
| 2389 | return s; |
| 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | #ifdef PERL_MAD |
| 2394 | if (PL_madskills && !version) { |
| 2395 | sv_free(PL_nextwhite); /* let next token collect whitespace */ |
| 2396 | PL_nextwhite = 0; |
| 2397 | s = SvPVX(PL_linestr) + startoff; |
| 2398 | } |
| 2399 | #endif |
| 2400 | /* NOTE: The parser sees the package name and the VERSION swapped */ |
| 2401 | start_force(PL_curforce); |
| 2402 | NEXTVAL_NEXTTOKE.opval = version; |
| 2403 | force_next(WORD); |
| 2404 | |
| 2405 | return s; |
| 2406 | } |
| 2407 | |
| 2408 | /* |
| 2409 | * S_force_strict_version |
| 2410 | * Forces the next token to be a version number using strict syntax rules. |
| 2411 | */ |
| 2412 | |
| 2413 | STATIC char * |
| 2414 | S_force_strict_version(pTHX_ char *s) |
| 2415 | { |
| 2416 | dVAR; |
| 2417 | OP *version = NULL; |
| 2418 | #ifdef PERL_MAD |
| 2419 | I32 startoff = s - SvPVX(PL_linestr); |
| 2420 | #endif |
| 2421 | const char *errstr = NULL; |
| 2422 | |
| 2423 | PERL_ARGS_ASSERT_FORCE_STRICT_VERSION; |
| 2424 | |
| 2425 | while (isSPACE(*s)) /* leading whitespace */ |
| 2426 | s++; |
| 2427 | |
| 2428 | if (is_STRICT_VERSION(s,&errstr)) { |
| 2429 | SV *ver = newSV(0); |
| 2430 | s = (char *)scan_version(s, ver, 0); |
| 2431 | version = newSVOP(OP_CONST, 0, ver); |
| 2432 | } |
| 2433 | else if ( (*s != ';' && *s != '{' && *s != '}' ) && |
| 2434 | (s = SKIPSPACE1(s), (*s != ';' && *s != '{' && *s != '}' ))) |
| 2435 | { |
| 2436 | PL_bufptr = s; |
| 2437 | if (errstr) |
| 2438 | yyerror(errstr); /* version required */ |
| 2439 | return s; |
| 2440 | } |
| 2441 | |
| 2442 | #ifdef PERL_MAD |
| 2443 | if (PL_madskills && !version) { |
| 2444 | sv_free(PL_nextwhite); /* let next token collect whitespace */ |
| 2445 | PL_nextwhite = 0; |
| 2446 | s = SvPVX(PL_linestr) + startoff; |
| 2447 | } |
| 2448 | #endif |
| 2449 | /* NOTE: The parser sees the package name and the VERSION swapped */ |
| 2450 | start_force(PL_curforce); |
| 2451 | NEXTVAL_NEXTTOKE.opval = version; |
| 2452 | force_next(WORD); |
| 2453 | |
| 2454 | return s; |
| 2455 | } |
| 2456 | |
| 2457 | /* |
| 2458 | * S_tokeq |
| 2459 | * Tokenize a quoted string passed in as an SV. It finds the next |
| 2460 | * chunk, up to end of string or a backslash. It may make a new |
| 2461 | * SV containing that chunk (if HINT_NEW_STRING is on). It also |
| 2462 | * turns \\ into \. |
| 2463 | */ |
| 2464 | |
| 2465 | STATIC SV * |
| 2466 | S_tokeq(pTHX_ SV *sv) |
| 2467 | { |
| 2468 | dVAR; |
| 2469 | char *s; |
| 2470 | char *send; |
| 2471 | char *d; |
| 2472 | STRLEN len = 0; |
| 2473 | SV *pv = sv; |
| 2474 | |
| 2475 | PERL_ARGS_ASSERT_TOKEQ; |
| 2476 | |
| 2477 | if (!SvLEN(sv)) |
| 2478 | goto finish; |
| 2479 | |
| 2480 | s = SvPV_force(sv, len); |
| 2481 | if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1) |
| 2482 | goto finish; |
| 2483 | send = s + len; |
| 2484 | /* This is relying on the SV being "well formed" with a trailing '\0' */ |
| 2485 | while (s < send && !(*s == '\\' && s[1] == '\\')) |
| 2486 | s++; |
| 2487 | if (s == send) |
| 2488 | goto finish; |
| 2489 | d = s; |
| 2490 | if ( PL_hints & HINT_NEW_STRING ) { |
| 2491 | pv = newSVpvn_flags(SvPVX_const(pv), len, SVs_TEMP | SvUTF8(sv)); |
| 2492 | } |
| 2493 | while (s < send) { |
| 2494 | if (*s == '\\') { |
| 2495 | if (s + 1 < send && (s[1] == '\\')) |
| 2496 | s++; /* all that, just for this */ |
| 2497 | } |
| 2498 | *d++ = *s++; |
| 2499 | } |
| 2500 | *d = '\0'; |
| 2501 | SvCUR_set(sv, d - SvPVX_const(sv)); |
| 2502 | finish: |
| 2503 | if ( PL_hints & HINT_NEW_STRING ) |
| 2504 | return new_constant(NULL, 0, "q", sv, pv, "q", 1); |
| 2505 | return sv; |
| 2506 | } |
| 2507 | |
| 2508 | /* |
| 2509 | * Now come three functions related to double-quote context, |
| 2510 | * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when |
| 2511 | * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They |
| 2512 | * interact with PL_lex_state, and create fake ( ... ) argument lists |
| 2513 | * to handle functions and concatenation. |
| 2514 | * For example, |
| 2515 | * "foo\lbar" |
| 2516 | * is tokenised as |
| 2517 | * stringify ( const[foo] concat lcfirst ( const[bar] ) ) |
| 2518 | */ |
| 2519 | |
| 2520 | /* |
| 2521 | * S_sublex_start |
| 2522 | * Assumes that pl_yylval.ival is the op we're creating (e.g. OP_LCFIRST). |
| 2523 | * |
| 2524 | * Pattern matching will set PL_lex_op to the pattern-matching op to |
| 2525 | * make (we return THING if pl_yylval.ival is OP_NULL, PMFUNC otherwise). |
| 2526 | * |
| 2527 | * OP_CONST and OP_READLINE are easy--just make the new op and return. |
| 2528 | * |
| 2529 | * Everything else becomes a FUNC. |
| 2530 | * |
| 2531 | * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we |
| 2532 | * had an OP_CONST or OP_READLINE). This just sets us up for a |
| 2533 | * call to S_sublex_push(). |
| 2534 | */ |
| 2535 | |
| 2536 | STATIC I32 |
| 2537 | S_sublex_start(pTHX) |
| 2538 | { |
| 2539 | dVAR; |
| 2540 | const I32 op_type = pl_yylval.ival; |
| 2541 | |
| 2542 | if (op_type == OP_NULL) { |
| 2543 | pl_yylval.opval = PL_lex_op; |
| 2544 | PL_lex_op = NULL; |
| 2545 | return THING; |
| 2546 | } |
| 2547 | if (op_type == OP_CONST || op_type == OP_READLINE) { |
| 2548 | SV *sv = tokeq(PL_lex_stuff); |
| 2549 | |
| 2550 | if (SvTYPE(sv) == SVt_PVIV) { |
| 2551 | /* Overloaded constants, nothing fancy: Convert to SVt_PV: */ |
| 2552 | STRLEN len; |
| 2553 | const char * const p = SvPV_const(sv, len); |
| 2554 | SV * const nsv = newSVpvn_flags(p, len, SvUTF8(sv)); |
| 2555 | SvREFCNT_dec(sv); |
| 2556 | sv = nsv; |
| 2557 | } |
| 2558 | pl_yylval.opval = (OP*)newSVOP(op_type, 0, sv); |
| 2559 | PL_lex_stuff = NULL; |
| 2560 | /* Allow <FH> // "foo" */ |
| 2561 | if (op_type == OP_READLINE) |
| 2562 | PL_expect = XTERMORDORDOR; |
| 2563 | return THING; |
| 2564 | } |
| 2565 | else if (op_type == OP_BACKTICK && PL_lex_op) { |
| 2566 | /* readpipe() vas overriden */ |
| 2567 | cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff); |
| 2568 | pl_yylval.opval = PL_lex_op; |
| 2569 | PL_lex_op = NULL; |
| 2570 | PL_lex_stuff = NULL; |
| 2571 | return THING; |
| 2572 | } |
| 2573 | |
| 2574 | PL_sublex_info.super_state = PL_lex_state; |
| 2575 | PL_sublex_info.sub_inwhat = (U16)op_type; |
| 2576 | PL_sublex_info.sub_op = PL_lex_op; |
| 2577 | PL_lex_state = LEX_INTERPPUSH; |
| 2578 | |
| 2579 | PL_expect = XTERM; |
| 2580 | if (PL_lex_op) { |
| 2581 | pl_yylval.opval = PL_lex_op; |
| 2582 | PL_lex_op = NULL; |
| 2583 | return PMFUNC; |
| 2584 | } |
| 2585 | else |
| 2586 | return FUNC; |
| 2587 | } |
| 2588 | |
| 2589 | /* |
| 2590 | * S_sublex_push |
| 2591 | * Create a new scope to save the lexing state. The scope will be |
| 2592 | * ended in S_sublex_done. Returns a '(', starting the function arguments |
| 2593 | * to the uc, lc, etc. found before. |
| 2594 | * Sets PL_lex_state to LEX_INTERPCONCAT. |
| 2595 | */ |
| 2596 | |
| 2597 | STATIC I32 |
| 2598 | S_sublex_push(pTHX) |
| 2599 | { |
| 2600 | dVAR; |
| 2601 | LEXSHARED *shared; |
| 2602 | ENTER; |
| 2603 | |
| 2604 | PL_lex_state = PL_sublex_info.super_state; |
| 2605 | SAVEBOOL(PL_lex_dojoin); |
| 2606 | SAVEI32(PL_lex_brackets); |
| 2607 | SAVEI32(PL_lex_allbrackets); |
| 2608 | SAVEI32(PL_lex_formbrack); |
| 2609 | SAVEI8(PL_lex_fakeeof); |
| 2610 | SAVEI32(PL_lex_casemods); |
| 2611 | SAVEI32(PL_lex_starts); |
| 2612 | SAVEI8(PL_lex_state); |
| 2613 | SAVESPTR(PL_lex_repl); |
| 2614 | SAVEVPTR(PL_lex_inpat); |
| 2615 | SAVEI16(PL_lex_inwhat); |
| 2616 | SAVECOPLINE(PL_curcop); |
| 2617 | SAVEPPTR(PL_bufptr); |
| 2618 | SAVEPPTR(PL_bufend); |
| 2619 | SAVEPPTR(PL_oldbufptr); |
| 2620 | SAVEPPTR(PL_oldoldbufptr); |
| 2621 | SAVEPPTR(PL_last_lop); |
| 2622 | SAVEPPTR(PL_last_uni); |
| 2623 | SAVEPPTR(PL_linestart); |
| 2624 | SAVESPTR(PL_linestr); |
| 2625 | SAVEGENERICPV(PL_lex_brackstack); |
| 2626 | SAVEGENERICPV(PL_lex_casestack); |
| 2627 | SAVEGENERICPV(PL_parser->lex_shared); |
| 2628 | SAVEBOOL(PL_parser->lex_re_reparsing); |
| 2629 | |
| 2630 | /* The here-doc parser needs to be able to peek into outer lexing |
| 2631 | scopes to find the body of the here-doc. So we put PL_linestr and |
| 2632 | PL_bufptr into lex_shared, to ‘share’ those values. |
| 2633 | */ |
| 2634 | PL_parser->lex_shared->ls_linestr = PL_linestr; |
| 2635 | PL_parser->lex_shared->ls_bufptr = PL_bufptr; |
| 2636 | |
| 2637 | PL_linestr = PL_lex_stuff; |
| 2638 | PL_lex_repl = PL_sublex_info.repl; |
| 2639 | PL_lex_stuff = NULL; |
| 2640 | PL_sublex_info.repl = NULL; |
| 2641 | |
| 2642 | PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart |
| 2643 | = SvPVX(PL_linestr); |
| 2644 | PL_bufend += SvCUR(PL_linestr); |
| 2645 | PL_last_lop = PL_last_uni = NULL; |
| 2646 | SAVEFREESV(PL_linestr); |
| 2647 | if (PL_lex_repl) SAVEFREESV(PL_lex_repl); |
| 2648 | |
| 2649 | PL_lex_dojoin = FALSE; |
| 2650 | PL_lex_brackets = PL_lex_formbrack = 0; |
| 2651 | PL_lex_allbrackets = 0; |
| 2652 | PL_lex_fakeeof = LEX_FAKEEOF_NEVER; |
| 2653 | Newx(PL_lex_brackstack, 120, char); |
| 2654 | Newx(PL_lex_casestack, 12, char); |
| 2655 | PL_lex_casemods = 0; |
| 2656 | *PL_lex_casestack = '\0'; |
| 2657 | PL_lex_starts = 0; |
| 2658 | PL_lex_state = LEX_INTERPCONCAT; |
| 2659 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
| 2660 | |
| 2661 | Newxz(shared, 1, LEXSHARED); |
| 2662 | shared->ls_prev = PL_parser->lex_shared; |
| 2663 | PL_parser->lex_shared = shared; |
| 2664 | |
| 2665 | PL_lex_inwhat = PL_sublex_info.sub_inwhat; |
| 2666 | if (PL_lex_inwhat == OP_TRANSR) PL_lex_inwhat = OP_TRANS; |
| 2667 | if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST) |
| 2668 | PL_lex_inpat = PL_sublex_info.sub_op; |
| 2669 | else |
| 2670 | PL_lex_inpat = NULL; |
| 2671 | |
| 2672 | PL_parser->lex_re_reparsing = cBOOL(PL_in_eval & EVAL_RE_REPARSING); |
| 2673 | PL_in_eval &= ~EVAL_RE_REPARSING; |
| 2674 | |
| 2675 | return '('; |
| 2676 | } |
| 2677 | |
| 2678 | /* |
| 2679 | * S_sublex_done |
| 2680 | * Restores lexer state after a S_sublex_push. |
| 2681 | */ |
| 2682 | |
| 2683 | STATIC I32 |
| 2684 | S_sublex_done(pTHX) |
| 2685 | { |
| 2686 | dVAR; |
| 2687 | if (!PL_lex_starts++) { |
| 2688 | SV * const sv = newSVpvs(""); |
| 2689 | if (SvUTF8(PL_linestr)) |
| 2690 | SvUTF8_on(sv); |
| 2691 | PL_expect = XOPERATOR; |
| 2692 | pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
| 2693 | return THING; |
| 2694 | } |
| 2695 | |
| 2696 | if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */ |
| 2697 | PL_lex_state = LEX_INTERPCASEMOD; |
| 2698 | return yylex(); |
| 2699 | } |
| 2700 | |
| 2701 | /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */ |
| 2702 | assert(PL_lex_inwhat != OP_TRANSR); |
| 2703 | if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) { |
| 2704 | PL_linestr = PL_lex_repl; |
| 2705 | PL_lex_inpat = 0; |
| 2706 | PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr); |
| 2707 | PL_bufend += SvCUR(PL_linestr); |
| 2708 | PL_last_lop = PL_last_uni = NULL; |
| 2709 | PL_lex_dojoin = FALSE; |
| 2710 | PL_lex_brackets = 0; |
| 2711 | PL_lex_allbrackets = 0; |
| 2712 | PL_lex_fakeeof = LEX_FAKEEOF_NEVER; |
| 2713 | PL_lex_casemods = 0; |
| 2714 | *PL_lex_casestack = '\0'; |
| 2715 | PL_lex_starts = 0; |
| 2716 | if (SvEVALED(PL_lex_repl)) { |
| 2717 | PL_lex_state = LEX_INTERPNORMAL; |
| 2718 | PL_lex_starts++; |
| 2719 | /* we don't clear PL_lex_repl here, so that we can check later |
| 2720 | whether this is an evalled subst; that means we rely on the |
| 2721 | logic to ensure sublex_done() is called again only via the |
| 2722 | branch (in yylex()) that clears PL_lex_repl, else we'll loop */ |
| 2723 | } |
| 2724 | else { |
| 2725 | PL_lex_state = LEX_INTERPCONCAT; |
| 2726 | PL_lex_repl = NULL; |
| 2727 | } |
| 2728 | return ','; |
| 2729 | } |
| 2730 | else { |
| 2731 | #ifdef PERL_MAD |
| 2732 | if (PL_madskills) { |
| 2733 | if (PL_thiswhite) { |
| 2734 | if (!PL_endwhite) |
| 2735 | PL_endwhite = newSVpvs(""); |
| 2736 | sv_catsv(PL_endwhite, PL_thiswhite); |
| 2737 | PL_thiswhite = 0; |
| 2738 | } |
| 2739 | if (PL_thistoken) |
| 2740 | sv_setpvs(PL_thistoken,""); |
| 2741 | else |
| 2742 | PL_realtokenstart = -1; |
| 2743 | } |
| 2744 | #endif |
| 2745 | LEAVE; |
| 2746 | PL_bufend = SvPVX(PL_linestr); |
| 2747 | PL_bufend += SvCUR(PL_linestr); |
| 2748 | PL_expect = XOPERATOR; |
| 2749 | PL_sublex_info.sub_inwhat = 0; |
| 2750 | return ')'; |
| 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | PERL_STATIC_INLINE SV* |
| 2755 | S_get_and_check_backslash_N_name(pTHX_ const char* s, const char* const e) |
| 2756 | { |
| 2757 | /* <s> points to first character of interior of \N{}, <e> to one beyond the |
| 2758 | * interior, hence to the "}". Finds what the name resolves to, returning |
| 2759 | * an SV* containing it; NULL if no valid one found */ |
| 2760 | |
| 2761 | SV* res = newSVpvn_flags(s, e - s, UTF ? SVf_UTF8 : 0); |
| 2762 | |
| 2763 | HV * table; |
| 2764 | SV **cvp; |
| 2765 | SV *cv; |
| 2766 | SV *rv; |
| 2767 | HV *stash; |
| 2768 | const U8* first_bad_char_loc; |
| 2769 | const char* backslash_ptr = s - 3; /* Points to the <\> of \N{... */ |
| 2770 | |
| 2771 | PERL_ARGS_ASSERT_GET_AND_CHECK_BACKSLASH_N_NAME; |
| 2772 | |
| 2773 | if (UTF && ! is_utf8_string_loc((U8 *) backslash_ptr, |
| 2774 | e - backslash_ptr, |
| 2775 | &first_bad_char_loc)) |
| 2776 | { |
| 2777 | /* If warnings are on, this will print a more detailed analysis of what |
| 2778 | * is wrong than the error message below */ |
| 2779 | utf8n_to_uvuni(first_bad_char_loc, |
| 2780 | e - ((char *) first_bad_char_loc), |
| 2781 | NULL, 0); |
| 2782 | |
| 2783 | /* We deliberately don't try to print the malformed character, which |
| 2784 | * might not print very well; it also may be just the first of many |
| 2785 | * malformations, so don't print what comes after it */ |
| 2786 | yyerror(Perl_form(aTHX_ |
| 2787 | "Malformed UTF-8 character immediately after '%.*s'", |
| 2788 | (int) (first_bad_char_loc - (U8 *) backslash_ptr), backslash_ptr)); |
| 2789 | return NULL; |
| 2790 | } |
| 2791 | |
| 2792 | res = new_constant( NULL, 0, "charnames", res, NULL, backslash_ptr, |
| 2793 | /* include the <}> */ |
| 2794 | e - backslash_ptr + 1); |
| 2795 | if (! SvPOK(res)) { |
| 2796 | SvREFCNT_dec_NN(res); |
| 2797 | return NULL; |
| 2798 | } |
| 2799 | |
| 2800 | /* See if the charnames handler is the Perl core's, and if so, we can skip |
| 2801 | * the validation needed for a user-supplied one, as Perl's does its own |
| 2802 | * validation. */ |
| 2803 | table = GvHV(PL_hintgv); /* ^H */ |
| 2804 | cvp = hv_fetchs(table, "charnames", FALSE); |
| 2805 | if (cvp && (cv = *cvp) && SvROK(cv) && ((rv = SvRV(cv)) != NULL) |
| 2806 | && SvTYPE(rv) == SVt_PVCV && ((stash = CvSTASH(rv)) != NULL)) |
| 2807 | { |
| 2808 | const char * const name = HvNAME(stash); |
| 2809 | if strEQ(name, "_charnames") { |
| 2810 | return res; |
| 2811 | } |
| 2812 | } |
| 2813 | |
| 2814 | /* Here, it isn't Perl's charname handler. We can't rely on a |
| 2815 | * user-supplied handler to validate the input name. For non-ut8 input, |
| 2816 | * look to see that the first character is legal. Then loop through the |
| 2817 | * rest checking that each is a continuation */ |
| 2818 | |
| 2819 | /* This code needs to be sync'ed with a regex in _charnames.pm which does |
| 2820 | * the same thing */ |
| 2821 | |
| 2822 | if (! UTF) { |
| 2823 | if (! isALPHAU(*s)) { |
| 2824 | goto bad_charname; |
| 2825 | } |
| 2826 | s++; |
| 2827 | while (s < e) { |
| 2828 | if (! isCHARNAME_CONT(*s)) { |
| 2829 | goto bad_charname; |
| 2830 | } |
| 2831 | if (*s == ' ' && *(s-1) == ' ' && ckWARN_d(WARN_DEPRECATED)) { |
| 2832 | Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), |
| 2833 | "A sequence of multiple spaces in a charnames " |
| 2834 | "alias definition is deprecated"); |
| 2835 | } |
| 2836 | s++; |
| 2837 | } |
| 2838 | if (*(s-1) == ' ' && ckWARN_d(WARN_DEPRECATED)) { |
| 2839 | Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), |
| 2840 | "Trailing white-space in a charnames alias " |
| 2841 | "definition is deprecated"); |
| 2842 | } |
| 2843 | } |
| 2844 | else { |
| 2845 | /* Similarly for utf8. For invariants can check directly; for other |
| 2846 | * Latin1, can calculate their code point and check; otherwise use a |
| 2847 | * swash */ |
| 2848 | if (UTF8_IS_INVARIANT(*s)) { |
| 2849 | if (! isALPHAU(*s)) { |
| 2850 | goto bad_charname; |
| 2851 | } |
| 2852 | s++; |
| 2853 | } else if (UTF8_IS_DOWNGRADEABLE_START(*s)) { |
| 2854 | if (! isALPHAU(UNI_TO_NATIVE(TWO_BYTE_UTF8_TO_UNI(*s, *(s+1))))) { |
| 2855 | goto bad_charname; |
| 2856 | } |
| 2857 | s += 2; |
| 2858 | } |
| 2859 | else { |
| 2860 | if (! PL_utf8_charname_begin) { |
| 2861 | U8 flags = _CORE_SWASH_INIT_ACCEPT_INVLIST; |
| 2862 | PL_utf8_charname_begin = _core_swash_init("utf8", |
| 2863 | "_Perl_Charname_Begin", |
| 2864 | &PL_sv_undef, |
| 2865 | 1, 0, NULL, &flags); |
| 2866 | } |
| 2867 | if (! swash_fetch(PL_utf8_charname_begin, (U8 *) s, TRUE)) { |
| 2868 | goto bad_charname; |
| 2869 | } |
| 2870 | s += UTF8SKIP(s); |
| 2871 | } |
| 2872 | |
| 2873 | while (s < e) { |
| 2874 | if (UTF8_IS_INVARIANT(*s)) { |
| 2875 | if (! isCHARNAME_CONT(*s)) { |
| 2876 | goto bad_charname; |
| 2877 | } |
| 2878 | if (*s == ' ' && *(s-1) == ' ' |
| 2879 | && ckWARN_d(WARN_DEPRECATED)) { |
| 2880 | Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), |
| 2881 | "A sequence of multiple spaces in a charnam" |
| 2882 | "es alias definition is deprecated"); |
| 2883 | } |
| 2884 | s++; |
| 2885 | } |
| 2886 | else if (UTF8_IS_DOWNGRADEABLE_START(*s)) { |
| 2887 | if (! isCHARNAME_CONT(UNI_TO_NATIVE(TWO_BYTE_UTF8_TO_UNI(*s, |
| 2888 | *(s+1))))) |
| 2889 | { |
| 2890 | goto bad_charname; |
| 2891 | } |
| 2892 | s += 2; |
| 2893 | } |
| 2894 | else { |
| 2895 | if (! PL_utf8_charname_continue) { |
| 2896 | U8 flags = _CORE_SWASH_INIT_ACCEPT_INVLIST; |
| 2897 | PL_utf8_charname_continue = _core_swash_init("utf8", |
| 2898 | "_Perl_Charname_Continue", |
| 2899 | &PL_sv_undef, |
| 2900 | 1, 0, NULL, &flags); |
| 2901 | } |
| 2902 | if (! swash_fetch(PL_utf8_charname_continue, (U8 *) s, TRUE)) { |
| 2903 | goto bad_charname; |
| 2904 | } |
| 2905 | s += UTF8SKIP(s); |
| 2906 | } |
| 2907 | } |
| 2908 | if (*(s-1) == ' ' && ckWARN_d(WARN_DEPRECATED)) { |
| 2909 | Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), |
| 2910 | "Trailing white-space in a charnames alias " |
| 2911 | "definition is deprecated"); |
| 2912 | } |
| 2913 | } |
| 2914 | |
| 2915 | if (SvUTF8(res)) { /* Don't accept malformed input */ |
| 2916 | const U8* first_bad_char_loc; |
| 2917 | STRLEN len; |
| 2918 | const char* const str = SvPV_const(res, len); |
| 2919 | if (! is_utf8_string_loc((U8 *) str, len, &first_bad_char_loc)) { |
| 2920 | /* If warnings are on, this will print a more detailed analysis of |
| 2921 | * what is wrong than the error message below */ |
| 2922 | utf8n_to_uvuni(first_bad_char_loc, |
| 2923 | (char *) first_bad_char_loc - str, |
| 2924 | NULL, 0); |
| 2925 | |
| 2926 | /* We deliberately don't try to print the malformed character, |
| 2927 | * which might not print very well; it also may be just the first |
| 2928 | * of many malformations, so don't print what comes after it */ |
| 2929 | yyerror_pv( |
| 2930 | Perl_form(aTHX_ |
| 2931 | "Malformed UTF-8 returned by %.*s immediately after '%.*s'", |
| 2932 | (int) (e - backslash_ptr + 1), backslash_ptr, |
| 2933 | (int) ((char *) first_bad_char_loc - str), str |
| 2934 | ), |
| 2935 | SVf_UTF8); |
| 2936 | return NULL; |
| 2937 | } |
| 2938 | } |
| 2939 | |
| 2940 | return res; |
| 2941 | |
| 2942 | bad_charname: { |
| 2943 | int bad_char_size = ((UTF) ? UTF8SKIP(s) : 1); |
| 2944 | |
| 2945 | /* The final %.*s makes sure that should the trailing NUL be missing |
| 2946 | * that this print won't run off the end of the string */ |
| 2947 | yyerror_pv( |
| 2948 | Perl_form(aTHX_ |
| 2949 | "Invalid character in \\N{...}; marked by <-- HERE in %.*s<-- HERE %.*s", |
| 2950 | (int)(s - backslash_ptr + bad_char_size), backslash_ptr, |
| 2951 | (int)(e - s + bad_char_size), s + bad_char_size |
| 2952 | ), |
| 2953 | UTF ? SVf_UTF8 : 0); |
| 2954 | return NULL; |
| 2955 | } |
| 2956 | } |
| 2957 | |
| 2958 | /* |
| 2959 | scan_const |
| 2960 | |
| 2961 | Extracts the next constant part of a pattern, double-quoted string, |
| 2962 | or transliteration. This is terrifying code. |
| 2963 | |
| 2964 | For example, in parsing the double-quoted string "ab\x63$d", it would |
| 2965 | stop at the '$' and return an OP_CONST containing 'abc'. |
| 2966 | |
| 2967 | It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's |
| 2968 | processing a pattern (PL_lex_inpat is true), a transliteration |
| 2969 | (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string. |
| 2970 | |
| 2971 | Returns a pointer to the character scanned up to. If this is |
| 2972 | advanced from the start pointer supplied (i.e. if anything was |
| 2973 | successfully parsed), will leave an OP_CONST for the substring scanned |
| 2974 | in pl_yylval. Caller must intuit reason for not parsing further |
| 2975 | by looking at the next characters herself. |
| 2976 | |
| 2977 | In patterns: |
| 2978 | expand: |
| 2979 | \N{FOO} => \N{U+hex_for_character_FOO} |
| 2980 | (if FOO expands to multiple characters, expands to \N{U+xx.XX.yy ...}) |
| 2981 | |
| 2982 | pass through: |
| 2983 | all other \-char, including \N and \N{ apart from \N{ABC} |
| 2984 | |
| 2985 | stops on: |
| 2986 | @ and $ where it appears to be a var, but not for $ as tail anchor |
| 2987 | \l \L \u \U \Q \E |
| 2988 | (?{ or (??{ |
| 2989 | |
| 2990 | |
| 2991 | In transliterations: |
| 2992 | characters are VERY literal, except for - not at the start or end |
| 2993 | of the string, which indicates a range. If the range is in bytes, |
| 2994 | scan_const expands the range to the full set of intermediate |
| 2995 | characters. If the range is in utf8, the hyphen is replaced with |
| 2996 | a certain range mark which will be handled by pmtrans() in op.c. |
| 2997 | |
| 2998 | In double-quoted strings: |
| 2999 | backslashes: |
| 3000 | double-quoted style: \r and \n |
| 3001 | constants: \x31, etc. |
| 3002 | deprecated backrefs: \1 (in substitution replacements) |
| 3003 | case and quoting: \U \Q \E |
| 3004 | stops on @ and $ |
| 3005 | |
| 3006 | scan_const does *not* construct ops to handle interpolated strings. |
| 3007 | It stops processing as soon as it finds an embedded $ or @ variable |
| 3008 | and leaves it to the caller to work out what's going on. |
| 3009 | |
| 3010 | embedded arrays (whether in pattern or not) could be: |
| 3011 | @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-. |
| 3012 | |
| 3013 | $ in double-quoted strings must be the symbol of an embedded scalar. |
| 3014 | |
| 3015 | $ in pattern could be $foo or could be tail anchor. Assumption: |
| 3016 | it's a tail anchor if $ is the last thing in the string, or if it's |
| 3017 | followed by one of "()| \r\n\t" |
| 3018 | |
| 3019 | \1 (backreferences) are turned into $1 in substitutions |
| 3020 | |
| 3021 | The structure of the code is |
| 3022 | while (there's a character to process) { |
| 3023 | handle transliteration ranges |
| 3024 | skip regexp comments /(?#comment)/ and codes /(?{code})/ |
| 3025 | skip #-initiated comments in //x patterns |
| 3026 | check for embedded arrays |
| 3027 | check for embedded scalars |
| 3028 | if (backslash) { |
| 3029 | deprecate \1 in substitution replacements |
| 3030 | handle string-changing backslashes \l \U \Q \E, etc. |
| 3031 | switch (what was escaped) { |
| 3032 | handle \- in a transliteration (becomes a literal -) |
| 3033 | if a pattern and not \N{, go treat as regular character |
| 3034 | handle \132 (octal characters) |
| 3035 | handle \x15 and \x{1234} (hex characters) |
| 3036 | handle \N{name} (named characters, also \N{3,5} in a pattern) |
| 3037 | handle \cV (control characters) |
| 3038 | handle printf-style backslashes (\f, \r, \n, etc) |
| 3039 | } (end switch) |
| 3040 | continue |
| 3041 | } (end if backslash) |
| 3042 | handle regular character |
| 3043 | } (end while character to read) |
| 3044 | |
| 3045 | */ |
| 3046 | |
| 3047 | STATIC char * |
| 3048 | S_scan_const(pTHX_ char *start) |
| 3049 | { |
| 3050 | dVAR; |
| 3051 | char *send = PL_bufend; /* end of the constant */ |
| 3052 | SV *sv = newSV(send - start); /* sv for the constant. See |
| 3053 | note below on sizing. */ |
| 3054 | char *s = start; /* start of the constant */ |
| 3055 | char *d = SvPVX(sv); /* destination for copies */ |
| 3056 | bool dorange = FALSE; /* are we in a translit range? */ |
| 3057 | bool didrange = FALSE; /* did we just finish a range? */ |
| 3058 | bool in_charclass = FALSE; /* within /[...]/ */ |
| 3059 | bool has_utf8 = FALSE; /* Output constant is UTF8 */ |
| 3060 | bool this_utf8 = cBOOL(UTF); /* Is the source string assumed |
| 3061 | to be UTF8? But, this can |
| 3062 | show as true when the source |
| 3063 | isn't utf8, as for example |
| 3064 | when it is entirely composed |
| 3065 | of hex constants */ |
| 3066 | SV *res; /* result from charnames */ |
| 3067 | |
| 3068 | /* Note on sizing: The scanned constant is placed into sv, which is |
| 3069 | * initialized by newSV() assuming one byte of output for every byte of |
| 3070 | * input. This routine expects newSV() to allocate an extra byte for a |
| 3071 | * trailing NUL, which this routine will append if it gets to the end of |
| 3072 | * the input. There may be more bytes of input than output (eg., \N{LATIN |
| 3073 | * CAPITAL LETTER A}), or more output than input if the constant ends up |
| 3074 | * recoded to utf8, but each time a construct is found that might increase |
| 3075 | * the needed size, SvGROW() is called. Its size parameter each time is |
| 3076 | * based on the best guess estimate at the time, namely the length used so |
| 3077 | * far, plus the length the current construct will occupy, plus room for |
| 3078 | * the trailing NUL, plus one byte for every input byte still unscanned */ |
| 3079 | |
| 3080 | UV uv = UV_MAX; /* Initialize to weird value to try to catch any uses |
| 3081 | before set */ |
| 3082 | #ifdef EBCDIC |
| 3083 | UV literal_endpoint = 0; |
| 3084 | bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */ |
| 3085 | #endif |
| 3086 | |
| 3087 | PERL_ARGS_ASSERT_SCAN_CONST; |
| 3088 | |
| 3089 | assert(PL_lex_inwhat != OP_TRANSR); |
| 3090 | if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) { |
| 3091 | /* If we are doing a trans and we know we want UTF8 set expectation */ |
| 3092 | has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF); |
| 3093 | this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); |
| 3094 | } |
| 3095 | |
| 3096 | /* Protect sv from errors and fatal warnings. */ |
| 3097 | ENTER_with_name("scan_const"); |
| 3098 | SAVEFREESV(sv); |
| 3099 | |
| 3100 | while (s < send || dorange) { |
| 3101 | |
| 3102 | /* get transliterations out of the way (they're most literal) */ |
| 3103 | if (PL_lex_inwhat == OP_TRANS) { |
| 3104 | /* expand a range A-Z to the full set of characters. AIE! */ |
| 3105 | if (dorange) { |
| 3106 | I32 i; /* current expanded character */ |
| 3107 | I32 min; /* first character in range */ |
| 3108 | I32 max; /* last character in range */ |
| 3109 | |
| 3110 | #ifdef EBCDIC |
| 3111 | UV uvmax = 0; |
| 3112 | #endif |
| 3113 | |
| 3114 | if (has_utf8 |
| 3115 | #ifdef EBCDIC |
| 3116 | && !native_range |
| 3117 | #endif |
| 3118 | ) { |
| 3119 | char * const c = (char*)utf8_hop((U8*)d, -1); |
| 3120 | char *e = d++; |
| 3121 | while (e-- > c) |
| 3122 | *(e + 1) = *e; |
| 3123 | *c = (char)UTF_TO_NATIVE(0xff); |
| 3124 | /* mark the range as done, and continue */ |
| 3125 | dorange = FALSE; |
| 3126 | didrange = TRUE; |
| 3127 | continue; |
| 3128 | } |
| 3129 | |
| 3130 | i = d - SvPVX_const(sv); /* remember current offset */ |
| 3131 | #ifdef EBCDIC |
| 3132 | SvGROW(sv, |
| 3133 | SvLEN(sv) + (has_utf8 ? |
| 3134 | (512 - UTF_CONTINUATION_MARK + |
| 3135 | UNISKIP(0x100)) |
| 3136 | : 256)); |
| 3137 | /* How many two-byte within 0..255: 128 in UTF-8, |
| 3138 | * 96 in UTF-8-mod. */ |
| 3139 | #else |
| 3140 | SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */ |
| 3141 | #endif |
| 3142 | d = SvPVX(sv) + i; /* refresh d after realloc */ |
| 3143 | #ifdef EBCDIC |
| 3144 | if (has_utf8) { |
| 3145 | int j; |
| 3146 | for (j = 0; j <= 1; j++) { |
| 3147 | char * const c = (char*)utf8_hop((U8*)d, -1); |
| 3148 | const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0); |
| 3149 | if (j) |
| 3150 | min = (U8)uv; |
| 3151 | else if (uv < 256) |
| 3152 | max = (U8)uv; |
| 3153 | else { |
| 3154 | max = (U8)0xff; /* only to \xff */ |
| 3155 | uvmax = uv; /* \x{100} to uvmax */ |
| 3156 | } |
| 3157 | d = c; /* eat endpoint chars */ |
| 3158 | } |
| 3159 | } |
| 3160 | else { |
| 3161 | #endif |
| 3162 | d -= 2; /* eat the first char and the - */ |
| 3163 | min = (U8)*d; /* first char in range */ |
| 3164 | max = (U8)d[1]; /* last char in range */ |
| 3165 | #ifdef EBCDIC |
| 3166 | } |
| 3167 | #endif |
| 3168 | |
| 3169 | if (min > max) { |
| 3170 | Perl_croak(aTHX_ |
| 3171 | "Invalid range \"%c-%c\" in transliteration operator", |
| 3172 | (char)min, (char)max); |
| 3173 | } |
| 3174 | |
| 3175 | #ifdef EBCDIC |
| 3176 | if (literal_endpoint == 2 && |
| 3177 | ((isLOWER(min) && isLOWER(max)) || |
| 3178 | (isUPPER(min) && isUPPER(max)))) { |
| 3179 | if (isLOWER(min)) { |
| 3180 | for (i = min; i <= max; i++) |
| 3181 | if (isLOWER(i)) |
| 3182 | *d++ = NATIVE_TO_NEED(has_utf8,i); |
| 3183 | } else { |
| 3184 | for (i = min; i <= max; i++) |
| 3185 | if (isUPPER(i)) |
| 3186 | *d++ = NATIVE_TO_NEED(has_utf8,i); |
| 3187 | } |
| 3188 | } |
| 3189 | else |
| 3190 | #endif |
| 3191 | for (i = min; i <= max; i++) |
| 3192 | #ifdef EBCDIC |
| 3193 | if (has_utf8) { |
| 3194 | const U8 ch = (U8)NATIVE_TO_UTF(i); |
| 3195 | if (UNI_IS_INVARIANT(ch)) |
| 3196 | *d++ = (U8)i; |
| 3197 | else { |
| 3198 | *d++ = (U8)UTF8_EIGHT_BIT_HI(ch); |
| 3199 | *d++ = (U8)UTF8_EIGHT_BIT_LO(ch); |
| 3200 | } |
| 3201 | } |
| 3202 | else |
| 3203 | #endif |
| 3204 | *d++ = (char)i; |
| 3205 | |
| 3206 | #ifdef EBCDIC |
| 3207 | if (uvmax) { |
| 3208 | d = (char*)uvchr_to_utf8((U8*)d, 0x100); |
| 3209 | if (uvmax > 0x101) |
| 3210 | *d++ = (char)UTF_TO_NATIVE(0xff); |
| 3211 | if (uvmax > 0x100) |
| 3212 | d = (char*)uvchr_to_utf8((U8*)d, uvmax); |
| 3213 | } |
| 3214 | #endif |
| 3215 | |
| 3216 | /* mark the range as done, and continue */ |
| 3217 | dorange = FALSE; |
| 3218 | didrange = TRUE; |
| 3219 | #ifdef EBCDIC |
| 3220 | literal_endpoint = 0; |
| 3221 | #endif |
| 3222 | continue; |
| 3223 | } |
| 3224 | |
| 3225 | /* range begins (ignore - as first or last char) */ |
| 3226 | else if (*s == '-' && s+1 < send && s != start) { |
| 3227 | if (didrange) { |
| 3228 | Perl_croak(aTHX_ "Ambiguous range in transliteration operator"); |
| 3229 | } |
| 3230 | if (has_utf8 |
| 3231 | #ifdef EBCDIC |
| 3232 | && !native_range |
| 3233 | #endif |
| 3234 | ) { |
| 3235 | *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */ |
| 3236 | s++; |
| 3237 | continue; |
| 3238 | } |
| 3239 | dorange = TRUE; |
| 3240 | s++; |
| 3241 | } |
| 3242 | else { |
| 3243 | didrange = FALSE; |
| 3244 | #ifdef EBCDIC |
| 3245 | literal_endpoint = 0; |
| 3246 | native_range = TRUE; |
| 3247 | #endif |
| 3248 | } |
| 3249 | } |
| 3250 | |
| 3251 | /* if we get here, we're not doing a transliteration */ |
| 3252 | |
| 3253 | else if (*s == '[' && PL_lex_inpat && !in_charclass) { |
| 3254 | char *s1 = s-1; |
| 3255 | int esc = 0; |
| 3256 | while (s1 >= start && *s1-- == '\\') |
| 3257 | esc = !esc; |
| 3258 | if (!esc) |
| 3259 | in_charclass = TRUE; |
| 3260 | } |
| 3261 | |
| 3262 | else if (*s == ']' && PL_lex_inpat && in_charclass) { |
| 3263 | char *s1 = s-1; |
| 3264 | int esc = 0; |
| 3265 | while (s1 >= start && *s1-- == '\\') |
| 3266 | esc = !esc; |
| 3267 | if (!esc) |
| 3268 | in_charclass = FALSE; |
| 3269 | } |
| 3270 | |
| 3271 | /* skip for regexp comments /(?#comment)/, except for the last |
| 3272 | * char, which will be done separately. |
| 3273 | * Stop on (?{..}) and friends */ |
| 3274 | |
| 3275 | else if (*s == '(' && PL_lex_inpat && s[1] == '?') { |
| 3276 | if (s[2] == '#') { |
| 3277 | while (s+1 < send && *s != ')') |
| 3278 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
| 3279 | } |
| 3280 | else if (!PL_lex_casemods && !in_charclass && |
| 3281 | ( s[2] == '{' /* This should match regcomp.c */ |
| 3282 | || (s[2] == '?' && s[3] == '{'))) |
| 3283 | { |
| 3284 | break; |
| 3285 | } |
| 3286 | } |
| 3287 | |
| 3288 | /* likewise skip #-initiated comments in //x patterns */ |
| 3289 | else if (*s == '#' && PL_lex_inpat && |
| 3290 | ((PMOP*)PL_lex_inpat)->op_pmflags & RXf_PMf_EXTENDED) { |
| 3291 | while (s+1 < send && *s != '\n') |
| 3292 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
| 3293 | } |
| 3294 | |
| 3295 | /* no further processing of single-quoted regex */ |
| 3296 | else if (PL_lex_inpat && SvIVX(PL_linestr) == '\'') |
| 3297 | goto default_action; |
| 3298 | |
| 3299 | /* check for embedded arrays |
| 3300 | (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-) |
| 3301 | */ |
| 3302 | else if (*s == '@' && s[1]) { |
| 3303 | if (isWORDCHAR_lazy_if(s+1,UTF)) |
| 3304 | break; |
| 3305 | if (strchr(":'{$", s[1])) |
| 3306 | break; |
| 3307 | if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-')) |
| 3308 | break; /* in regexp, neither @+ nor @- are interpolated */ |
| 3309 | } |
| 3310 | |
| 3311 | /* check for embedded scalars. only stop if we're sure it's a |
| 3312 | variable. |
| 3313 | */ |
| 3314 | else if (*s == '$') { |
| 3315 | if (!PL_lex_inpat) /* not a regexp, so $ must be var */ |
| 3316 | break; |
| 3317 | if (s + 1 < send && !strchr("()| \r\n\t", s[1])) { |
| 3318 | if (s[1] == '\\') { |
| 3319 | Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 3320 | "Possible unintended interpolation of $\\ in regex"); |
| 3321 | } |
| 3322 | break; /* in regexp, $ might be tail anchor */ |
| 3323 | } |
| 3324 | } |
| 3325 | |
| 3326 | /* End of else if chain - OP_TRANS rejoin rest */ |
| 3327 | |
| 3328 | /* backslashes */ |
| 3329 | if (*s == '\\' && s+1 < send) { |
| 3330 | char* e; /* Can be used for ending '}', etc. */ |
| 3331 | |
| 3332 | s++; |
| 3333 | |
| 3334 | /* warn on \1 - \9 in substitution replacements, but note that \11 |
| 3335 | * is an octal; and \19 is \1 followed by '9' */ |
| 3336 | if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat && |
| 3337 | isDIGIT(*s) && *s != '0' && !isDIGIT(s[1])) |
| 3338 | { |
| 3339 | Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s); |
| 3340 | *--s = '$'; |
| 3341 | break; |
| 3342 | } |
| 3343 | |
| 3344 | /* string-change backslash escapes */ |
| 3345 | if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQF", *s)) { |
| 3346 | --s; |
| 3347 | break; |
| 3348 | } |
| 3349 | /* In a pattern, process \N, but skip any other backslash escapes. |
| 3350 | * This is because we don't want to translate an escape sequence |
| 3351 | * into a meta symbol and have the regex compiler use the meta |
| 3352 | * symbol meaning, e.g. \x{2E} would be confused with a dot. But |
| 3353 | * in spite of this, we do have to process \N here while the proper |
| 3354 | * charnames handler is in scope. See bugs #56444 and #62056. |
| 3355 | * There is a complication because \N in a pattern may also stand |
| 3356 | * for 'match a non-nl', and not mean a charname, in which case its |
| 3357 | * processing should be deferred to the regex compiler. To be a |
| 3358 | * charname it must be followed immediately by a '{', and not look |
| 3359 | * like \N followed by a curly quantifier, i.e., not something like |
| 3360 | * \N{3,}. regcurly returns a boolean indicating if it is a legal |
| 3361 | * quantifier */ |
| 3362 | else if (PL_lex_inpat |
| 3363 | && (*s != 'N' |
| 3364 | || s[1] != '{' |
| 3365 | || regcurly(s + 1, FALSE))) |
| 3366 | { |
| 3367 | *d++ = NATIVE_TO_NEED(has_utf8,'\\'); |
| 3368 | goto default_action; |
| 3369 | } |
| 3370 | |
| 3371 | switch (*s) { |
| 3372 | |
| 3373 | /* quoted - in transliterations */ |
| 3374 | case '-': |
| 3375 | if (PL_lex_inwhat == OP_TRANS) { |
| 3376 | *d++ = *s++; |
| 3377 | continue; |
| 3378 | } |
| 3379 | /* FALL THROUGH */ |
| 3380 | default: |
| 3381 | { |
| 3382 | if ((isALPHANUMERIC(*s))) |
| 3383 | Perl_ck_warner(aTHX_ packWARN(WARN_MISC), |
| 3384 | "Unrecognized escape \\%c passed through", |
| 3385 | *s); |
| 3386 | /* default action is to copy the quoted character */ |
| 3387 | goto default_action; |
| 3388 | } |
| 3389 | |
| 3390 | /* eg. \132 indicates the octal constant 0132 */ |
| 3391 | case '0': case '1': case '2': case '3': |
| 3392 | case '4': case '5': case '6': case '7': |
| 3393 | { |
| 3394 | I32 flags = PERL_SCAN_SILENT_ILLDIGIT; |
| 3395 | STRLEN len = 3; |
| 3396 | uv = NATIVE_TO_UNI(grok_oct(s, &len, &flags, NULL)); |
| 3397 | s += len; |
| 3398 | if (len < 3 && s < send && isDIGIT(*s) |
| 3399 | && ckWARN(WARN_MISC)) |
| 3400 | { |
| 3401 | Perl_warner(aTHX_ packWARN(WARN_MISC), |
| 3402 | "%s", form_short_octal_warning(s, len)); |
| 3403 | } |
| 3404 | } |
| 3405 | goto NUM_ESCAPE_INSERT; |
| 3406 | |
| 3407 | /* eg. \o{24} indicates the octal constant \024 */ |
| 3408 | case 'o': |
| 3409 | { |
| 3410 | const char* error; |
| 3411 | |
| 3412 | bool valid = grok_bslash_o(&s, &uv, &error, |
| 3413 | TRUE, /* Output warning */ |
| 3414 | FALSE, /* Not strict */ |
| 3415 | TRUE, /* Output warnings for |
| 3416 | non-portables */ |
| 3417 | UTF); |
| 3418 | if (! valid) { |
| 3419 | yyerror(error); |
| 3420 | continue; |
| 3421 | } |
| 3422 | goto NUM_ESCAPE_INSERT; |
| 3423 | } |
| 3424 | |
| 3425 | /* eg. \x24 indicates the hex constant 0x24 */ |
| 3426 | case 'x': |
| 3427 | { |
| 3428 | const char* error; |
| 3429 | |
| 3430 | bool valid = grok_bslash_x(&s, &uv, &error, |
| 3431 | TRUE, /* Output warning */ |
| 3432 | FALSE, /* Not strict */ |
| 3433 | TRUE, /* Output warnings for |
| 3434 | non-portables */ |
| 3435 | UTF); |
| 3436 | if (! valid) { |
| 3437 | yyerror(error); |
| 3438 | continue; |
| 3439 | } |
| 3440 | } |
| 3441 | |
| 3442 | NUM_ESCAPE_INSERT: |
| 3443 | /* Insert oct or hex escaped character. There will always be |
| 3444 | * enough room in sv since such escapes will be longer than any |
| 3445 | * UTF-8 sequence they can end up as, except if they force us |
| 3446 | * to recode the rest of the string into utf8 */ |
| 3447 | |
| 3448 | /* Here uv is the ordinal of the next character being added in |
| 3449 | * unicode (converted from native). */ |
| 3450 | if (!UNI_IS_INVARIANT(uv)) { |
| 3451 | if (!has_utf8 && uv > 255) { |
| 3452 | /* Might need to recode whatever we have accumulated so |
| 3453 | * far if it contains any chars variant in utf8 or |
| 3454 | * utf-ebcdic. */ |
| 3455 | |
| 3456 | SvCUR_set(sv, d - SvPVX_const(sv)); |
| 3457 | SvPOK_on(sv); |
| 3458 | *d = '\0'; |
| 3459 | /* See Note on sizing above. */ |
| 3460 | sv_utf8_upgrade_flags_grow(sv, |
| 3461 | SV_GMAGIC|SV_FORCE_UTF8_UPGRADE, |
| 3462 | UNISKIP(uv) + (STRLEN)(send - s) + 1); |
| 3463 | d = SvPVX(sv) + SvCUR(sv); |
| 3464 | has_utf8 = TRUE; |
| 3465 | } |
| 3466 | |
| 3467 | if (has_utf8) { |
| 3468 | d = (char*)uvuni_to_utf8((U8*)d, uv); |
| 3469 | if (PL_lex_inwhat == OP_TRANS && |
| 3470 | PL_sublex_info.sub_op) { |
| 3471 | PL_sublex_info.sub_op->op_private |= |
| 3472 | (PL_lex_repl ? OPpTRANS_FROM_UTF |
| 3473 | : OPpTRANS_TO_UTF); |
| 3474 | } |
| 3475 | #ifdef EBCDIC |
| 3476 | if (uv > 255 && !dorange) |
| 3477 | native_range = FALSE; |
| 3478 | #endif |
| 3479 | } |
| 3480 | else { |
| 3481 | *d++ = (char)uv; |
| 3482 | } |
| 3483 | } |
| 3484 | else { |
| 3485 | *d++ = (char) uv; |
| 3486 | } |
| 3487 | continue; |
| 3488 | |
| 3489 | case 'N': |
| 3490 | /* In a non-pattern \N must be a named character, like \N{LATIN |
| 3491 | * SMALL LETTER A} or \N{U+0041}. For patterns, it also can |
| 3492 | * mean to match a non-newline. For non-patterns, named |
| 3493 | * characters are converted to their string equivalents. In |
| 3494 | * patterns, named characters are not converted to their |
| 3495 | * ultimate forms for the same reasons that other escapes |
| 3496 | * aren't. Instead, they are converted to the \N{U+...} form |
| 3497 | * to get the value from the charnames that is in effect right |
| 3498 | * now, while preserving the fact that it was a named character |
| 3499 | * so that the regex compiler knows this */ |
| 3500 | |
| 3501 | /* This section of code doesn't generally use the |
| 3502 | * NATIVE_TO_NEED() macro to transform the input. I (khw) did |
| 3503 | * a close examination of this macro and determined it is a |
| 3504 | * no-op except on utfebcdic variant characters. Every |
| 3505 | * character generated by this that would normally need to be |
| 3506 | * enclosed by this macro is invariant, so the macro is not |
| 3507 | * needed, and would complicate use of copy(). XXX There are |
| 3508 | * other parts of this file where the macro is used |
| 3509 | * inconsistently, but are saved by it being a no-op */ |
| 3510 | |
| 3511 | /* The structure of this section of code (besides checking for |
| 3512 | * errors and upgrading to utf8) is: |
| 3513 | * Further disambiguate between the two meanings of \N, and if |
| 3514 | * not a charname, go process it elsewhere |
| 3515 | * If of form \N{U+...}, pass it through if a pattern; |
| 3516 | * otherwise convert to utf8 |
| 3517 | * Otherwise must be \N{NAME}: convert to \N{U+c1.c2...} if a |
| 3518 | * pattern; otherwise convert to utf8 */ |
| 3519 | |
| 3520 | /* Here, s points to the 'N'; the test below is guaranteed to |
| 3521 | * succeed if we are being called on a pattern as we already |
| 3522 | * know from a test above that the next character is a '{'. |
| 3523 | * On a non-pattern \N must mean 'named sequence, which |
| 3524 | * requires braces */ |
| 3525 | s++; |
| 3526 | if (*s != '{') { |
| 3527 | yyerror("Missing braces on \\N{}"); |
| 3528 | continue; |
| 3529 | } |
| 3530 | s++; |
| 3531 | |
| 3532 | /* If there is no matching '}', it is an error. */ |
| 3533 | if (! (e = strchr(s, '}'))) { |
| 3534 | if (! PL_lex_inpat) { |
| 3535 | yyerror("Missing right brace on \\N{}"); |
| 3536 | } else { |
| 3537 | yyerror("Missing right brace on \\N{} or unescaped left brace after \\N."); |
| 3538 | } |
| 3539 | continue; |
| 3540 | } |
| 3541 | |
| 3542 | /* Here it looks like a named character */ |
| 3543 | |
| 3544 | if (*s == 'U' && s[1] == '+') { /* \N{U+...} */ |
| 3545 | I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
| 3546 | | PERL_SCAN_DISALLOW_PREFIX; |
| 3547 | STRLEN len; |
| 3548 | |
| 3549 | /* For \N{U+...}, the '...' is a unicode value even on |
| 3550 | * EBCDIC machines */ |
| 3551 | s += 2; /* Skip to next char after the 'U+' */ |
| 3552 | len = e - s; |
| 3553 | uv = grok_hex(s, &len, &flags, NULL); |
| 3554 | if (len == 0 || len != (STRLEN)(e - s)) { |
| 3555 | yyerror("Invalid hexadecimal number in \\N{U+...}"); |
| 3556 | s = e + 1; |
| 3557 | continue; |
| 3558 | } |
| 3559 | |
| 3560 | if (PL_lex_inpat) { |
| 3561 | |
| 3562 | /* On non-EBCDIC platforms, pass through to the regex |
| 3563 | * compiler unchanged. The reason we evaluated the |
| 3564 | * number above is to make sure there wasn't a syntax |
| 3565 | * error. But on EBCDIC we convert to native so |
| 3566 | * downstream code can continue to assume it's native |
| 3567 | */ |
| 3568 | s -= 5; /* Include the '\N{U+' */ |
| 3569 | #ifdef EBCDIC |
| 3570 | d += my_snprintf(d, e - s + 1 + 1, /* includes the } |
| 3571 | and the \0 */ |
| 3572 | "\\N{U+%X}", |
| 3573 | (unsigned int) UNI_TO_NATIVE(uv)); |
| 3574 | #else |
| 3575 | Copy(s, d, e - s + 1, char); /* 1 = include the } */ |
| 3576 | d += e - s + 1; |
| 3577 | #endif |
| 3578 | } |
| 3579 | else { /* Not a pattern: convert the hex to string */ |
| 3580 | |
| 3581 | /* If destination is not in utf8, unconditionally |
| 3582 | * recode it to be so. This is because \N{} implies |
| 3583 | * Unicode semantics, and scalars have to be in utf8 |
| 3584 | * to guarantee those semantics */ |
| 3585 | if (! has_utf8) { |
| 3586 | SvCUR_set(sv, d - SvPVX_const(sv)); |
| 3587 | SvPOK_on(sv); |
| 3588 | *d = '\0'; |
| 3589 | /* See Note on sizing above. */ |
| 3590 | sv_utf8_upgrade_flags_grow( |
| 3591 | sv, |
| 3592 | SV_GMAGIC|SV_FORCE_UTF8_UPGRADE, |
| 3593 | UNISKIP(uv) + (STRLEN)(send - e) + 1); |
| 3594 | d = SvPVX(sv) + SvCUR(sv); |
| 3595 | has_utf8 = TRUE; |
| 3596 | } |
| 3597 | |
| 3598 | /* Add the string to the output */ |
| 3599 | if (UNI_IS_INVARIANT(uv)) { |
| 3600 | *d++ = (char) uv; |
| 3601 | } |
| 3602 | else d = (char*)uvuni_to_utf8((U8*)d, uv); |
| 3603 | } |
| 3604 | } |
| 3605 | else /* Here is \N{NAME} but not \N{U+...}. */ |
| 3606 | if ((res = get_and_check_backslash_N_name(s, e))) |
| 3607 | { |
| 3608 | STRLEN len; |
| 3609 | const char *str = SvPV_const(res, len); |
| 3610 | if (PL_lex_inpat) { |
| 3611 | |
| 3612 | if (! len) { /* The name resolved to an empty string */ |
| 3613 | Copy("\\N{}", d, 4, char); |
| 3614 | d += 4; |
| 3615 | } |
| 3616 | else { |
| 3617 | /* In order to not lose information for the regex |
| 3618 | * compiler, pass the result in the specially made |
| 3619 | * syntax: \N{U+c1.c2.c3...}, where c1 etc. are |
| 3620 | * the code points in hex of each character |
| 3621 | * returned by charnames */ |
| 3622 | |
| 3623 | const char *str_end = str + len; |
| 3624 | const STRLEN off = d - SvPVX_const(sv); |
| 3625 | |
| 3626 | if (! SvUTF8(res)) { |
| 3627 | /* For the non-UTF-8 case, we can determine the |
| 3628 | * exact length needed without having to parse |
| 3629 | * through the string. Each character takes up |
| 3630 | * 2 hex digits plus either a trailing dot or |
| 3631 | * the "}" */ |
| 3632 | d = off + SvGROW(sv, off |
| 3633 | + 3 * len |
| 3634 | + 6 /* For the "\N{U+", and |
| 3635 | trailing NUL */ |
| 3636 | + (STRLEN)(send - e)); |
| 3637 | Copy("\\N{U+", d, 5, char); |
| 3638 | d += 5; |
| 3639 | while (str < str_end) { |
| 3640 | char hex_string[4]; |
| 3641 | my_snprintf(hex_string, sizeof(hex_string), |
| 3642 | "%02X.", (U8) *str); |
| 3643 | Copy(hex_string, d, 3, char); |
| 3644 | d += 3; |
| 3645 | str++; |
| 3646 | } |
| 3647 | d--; /* We will overwrite below the final |
| 3648 | dot with a right brace */ |
| 3649 | } |
| 3650 | else { |
| 3651 | STRLEN char_length; /* cur char's byte length */ |
| 3652 | |
| 3653 | /* and the number of bytes after this is |
| 3654 | * translated into hex digits */ |
| 3655 | STRLEN output_length; |
| 3656 | |
| 3657 | /* 2 hex per byte; 2 chars for '\N'; 2 chars |
| 3658 | * for max('U+', '.'); and 1 for NUL */ |
| 3659 | char hex_string[2 * UTF8_MAXBYTES + 5]; |
| 3660 | |
| 3661 | /* Get the first character of the result. */ |
| 3662 | U32 uv = utf8n_to_uvuni((U8 *) str, |
| 3663 | len, |
| 3664 | &char_length, |
| 3665 | UTF8_ALLOW_ANYUV); |
| 3666 | /* Convert first code point to hex, including |
| 3667 | * the boiler plate before it. For all these, |
| 3668 | * we convert to native format so that |
| 3669 | * downstream code can continue to assume the |
| 3670 | * input is native */ |
| 3671 | output_length = |
| 3672 | my_snprintf(hex_string, sizeof(hex_string), |
| 3673 | "\\N{U+%X", |
| 3674 | (unsigned int) UNI_TO_NATIVE(uv)); |
| 3675 | |
| 3676 | /* Make sure there is enough space to hold it */ |
| 3677 | d = off + SvGROW(sv, off |
| 3678 | + output_length |
| 3679 | + (STRLEN)(send - e) |
| 3680 | + 2); /* '}' + NUL */ |
| 3681 | /* And output it */ |
| 3682 | Copy(hex_string, d, output_length, char); |
| 3683 | d += output_length; |
| 3684 | |
| 3685 | /* For each subsequent character, append dot and |
| 3686 | * its ordinal in hex */ |
| 3687 | while ((str += char_length) < str_end) { |
| 3688 | const STRLEN off = d - SvPVX_const(sv); |
| 3689 | U32 uv = utf8n_to_uvuni((U8 *) str, |
| 3690 | str_end - str, |
| 3691 | &char_length, |
| 3692 | UTF8_ALLOW_ANYUV); |
| 3693 | output_length = |
| 3694 | my_snprintf(hex_string, |
| 3695 | sizeof(hex_string), |
| 3696 | ".%X", |
| 3697 | (unsigned int) UNI_TO_NATIVE(uv)); |
| 3698 | |
| 3699 | d = off + SvGROW(sv, off |
| 3700 | + output_length |
| 3701 | + (STRLEN)(send - e) |
| 3702 | + 2); /* '}' + NUL */ |
| 3703 | Copy(hex_string, d, output_length, char); |
| 3704 | d += output_length; |
| 3705 | } |
| 3706 | } |
| 3707 | |
| 3708 | *d++ = '}'; /* Done. Add the trailing brace */ |
| 3709 | } |
| 3710 | } |
| 3711 | else { /* Here, not in a pattern. Convert the name to a |
| 3712 | * string. */ |
| 3713 | |
| 3714 | /* If destination is not in utf8, unconditionally |
| 3715 | * recode it to be so. This is because \N{} implies |
| 3716 | * Unicode semantics, and scalars have to be in utf8 |
| 3717 | * to guarantee those semantics */ |
| 3718 | if (! has_utf8) { |
| 3719 | SvCUR_set(sv, d - SvPVX_const(sv)); |
| 3720 | SvPOK_on(sv); |
| 3721 | *d = '\0'; |
| 3722 | /* See Note on sizing above. */ |
| 3723 | sv_utf8_upgrade_flags_grow(sv, |
| 3724 | SV_GMAGIC|SV_FORCE_UTF8_UPGRADE, |
| 3725 | len + (STRLEN)(send - s) + 1); |
| 3726 | d = SvPVX(sv) + SvCUR(sv); |
| 3727 | has_utf8 = TRUE; |
| 3728 | } else if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */ |
| 3729 | |
| 3730 | /* See Note on sizing above. (NOTE: SvCUR() is not |
| 3731 | * set correctly here). */ |
| 3732 | const STRLEN off = d - SvPVX_const(sv); |
| 3733 | d = off + SvGROW(sv, off + len + (STRLEN)(send - s) + 1); |
| 3734 | } |
| 3735 | Copy(str, d, len, char); |
| 3736 | d += len; |
| 3737 | } |
| 3738 | |
| 3739 | SvREFCNT_dec(res); |
| 3740 | |
| 3741 | } /* End \N{NAME} */ |
| 3742 | #ifdef EBCDIC |
| 3743 | if (!dorange) |
| 3744 | native_range = FALSE; /* \N{} is defined to be Unicode */ |
| 3745 | #endif |
| 3746 | s = e + 1; /* Point to just after the '}' */ |
| 3747 | continue; |
| 3748 | |
| 3749 | /* \c is a control character */ |
| 3750 | case 'c': |
| 3751 | s++; |
| 3752 | if (s < send) { |
| 3753 | *d++ = grok_bslash_c(*s++, has_utf8, 1); |
| 3754 | } |
| 3755 | else { |
| 3756 | yyerror("Missing control char name in \\c"); |
| 3757 | } |
| 3758 | continue; |
| 3759 | |
| 3760 | /* printf-style backslashes, formfeeds, newlines, etc */ |
| 3761 | case 'b': |
| 3762 | *d++ = NATIVE_TO_NEED(has_utf8,'\b'); |
| 3763 | break; |
| 3764 | case 'n': |
| 3765 | *d++ = NATIVE_TO_NEED(has_utf8,'\n'); |
| 3766 | break; |
| 3767 | case 'r': |
| 3768 | *d++ = NATIVE_TO_NEED(has_utf8,'\r'); |
| 3769 | break; |
| 3770 | case 'f': |
| 3771 | *d++ = NATIVE_TO_NEED(has_utf8,'\f'); |
| 3772 | break; |
| 3773 | case 't': |
| 3774 | *d++ = NATIVE_TO_NEED(has_utf8,'\t'); |
| 3775 | break; |
| 3776 | case 'e': |
| 3777 | *d++ = ASCII_TO_NEED(has_utf8,'\033'); |
| 3778 | break; |
| 3779 | case 'a': |
| 3780 | *d++ = ASCII_TO_NEED(has_utf8,'\007'); |
| 3781 | break; |
| 3782 | } /* end switch */ |
| 3783 | |
| 3784 | s++; |
| 3785 | continue; |
| 3786 | } /* end if (backslash) */ |
| 3787 | #ifdef EBCDIC |
| 3788 | else |
| 3789 | literal_endpoint++; |
| 3790 | #endif |
| 3791 | |
| 3792 | default_action: |
| 3793 | /* If we started with encoded form, or already know we want it, |
| 3794 | then encode the next character */ |
| 3795 | if (! NATIVE_IS_INVARIANT((U8)(*s)) && (this_utf8 || has_utf8)) { |
| 3796 | STRLEN len = 1; |
| 3797 | |
| 3798 | |
| 3799 | /* One might think that it is wasted effort in the case of the |
| 3800 | * source being utf8 (this_utf8 == TRUE) to take the next character |
| 3801 | * in the source, convert it to an unsigned value, and then convert |
| 3802 | * it back again. But the source has not been validated here. The |
| 3803 | * routine that does the conversion checks for errors like |
| 3804 | * malformed utf8 */ |
| 3805 | |
| 3806 | const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s); |
| 3807 | const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv)); |
| 3808 | if (!has_utf8) { |
| 3809 | SvCUR_set(sv, d - SvPVX_const(sv)); |
| 3810 | SvPOK_on(sv); |
| 3811 | *d = '\0'; |
| 3812 | /* See Note on sizing above. */ |
| 3813 | sv_utf8_upgrade_flags_grow(sv, |
| 3814 | SV_GMAGIC|SV_FORCE_UTF8_UPGRADE, |
| 3815 | need + (STRLEN)(send - s) + 1); |
| 3816 | d = SvPVX(sv) + SvCUR(sv); |
| 3817 | has_utf8 = TRUE; |
| 3818 | } else if (need > len) { |
| 3819 | /* encoded value larger than old, may need extra space (NOTE: |
| 3820 | * SvCUR() is not set correctly here). See Note on sizing |
| 3821 | * above. */ |
| 3822 | const STRLEN off = d - SvPVX_const(sv); |
| 3823 | d = SvGROW(sv, off + need + (STRLEN)(send - s) + 1) + off; |
| 3824 | } |
| 3825 | s += len; |
| 3826 | |
| 3827 | d = (char*)uvchr_to_utf8((U8*)d, nextuv); |
| 3828 | #ifdef EBCDIC |
| 3829 | if (uv > 255 && !dorange) |
| 3830 | native_range = FALSE; |
| 3831 | #endif |
| 3832 | } |
| 3833 | else { |
| 3834 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
| 3835 | } |
| 3836 | } /* while loop to process each character */ |
| 3837 | |
| 3838 | /* terminate the string and set up the sv */ |
| 3839 | *d = '\0'; |
| 3840 | SvCUR_set(sv, d - SvPVX_const(sv)); |
| 3841 | if (SvCUR(sv) >= SvLEN(sv)) |
| 3842 | Perl_croak(aTHX_ "panic: constant overflowed allocated space, %"UVuf |
| 3843 | " >= %"UVuf, (UV)SvCUR(sv), (UV)SvLEN(sv)); |
| 3844 | |
| 3845 | SvPOK_on(sv); |
| 3846 | if (PL_encoding && !has_utf8) { |
| 3847 | sv_recode_to_utf8(sv, PL_encoding); |
| 3848 | if (SvUTF8(sv)) |
| 3849 | has_utf8 = TRUE; |
| 3850 | } |
| 3851 | if (has_utf8) { |
| 3852 | SvUTF8_on(sv); |
| 3853 | if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) { |
| 3854 | PL_sublex_info.sub_op->op_private |= |
| 3855 | (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); |
| 3856 | } |
| 3857 | } |
| 3858 | |
| 3859 | /* shrink the sv if we allocated more than we used */ |
| 3860 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
| 3861 | SvPV_shrink_to_cur(sv); |
| 3862 | } |
| 3863 | |
| 3864 | /* return the substring (via pl_yylval) only if we parsed anything */ |
| 3865 | if (s > PL_bufptr) { |
| 3866 | SvREFCNT_inc_simple_void_NN(sv); |
| 3867 | if ( (PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING )) |
| 3868 | && ! PL_parser->lex_re_reparsing) |
| 3869 | { |
| 3870 | const char *const key = PL_lex_inpat ? "qr" : "q"; |
| 3871 | const STRLEN keylen = PL_lex_inpat ? 2 : 1; |
| 3872 | const char *type; |
| 3873 | STRLEN typelen; |
| 3874 | |
| 3875 | if (PL_lex_inwhat == OP_TRANS) { |
| 3876 | type = "tr"; |
| 3877 | typelen = 2; |
| 3878 | } else if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) { |
| 3879 | type = "s"; |
| 3880 | typelen = 1; |
| 3881 | } else if (PL_lex_inpat && SvIVX(PL_linestr) == '\'') { |
| 3882 | type = "q"; |
| 3883 | typelen = 1; |
| 3884 | } else { |
| 3885 | type = "qq"; |
| 3886 | typelen = 2; |
| 3887 | } |
| 3888 | |
| 3889 | sv = S_new_constant(aTHX_ start, s - start, key, keylen, sv, NULL, |
| 3890 | type, typelen); |
| 3891 | } |
| 3892 | pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
| 3893 | } |
| 3894 | LEAVE_with_name("scan_const"); |
| 3895 | return s; |
| 3896 | } |
| 3897 | |
| 3898 | /* S_intuit_more |
| 3899 | * Returns TRUE if there's more to the expression (e.g., a subscript), |
| 3900 | * FALSE otherwise. |
| 3901 | * |
| 3902 | * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/ |
| 3903 | * |
| 3904 | * ->[ and ->{ return TRUE |
| 3905 | * { and [ outside a pattern are always subscripts, so return TRUE |
| 3906 | * if we're outside a pattern and it's not { or [, then return FALSE |
| 3907 | * if we're in a pattern and the first char is a { |
| 3908 | * {4,5} (any digits around the comma) returns FALSE |
| 3909 | * if we're in a pattern and the first char is a [ |
| 3910 | * [] returns FALSE |
| 3911 | * [SOMETHING] has a funky algorithm to decide whether it's a |
| 3912 | * character class or not. It has to deal with things like |
| 3913 | * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/ |
| 3914 | * anything else returns TRUE |
| 3915 | */ |
| 3916 | |
| 3917 | /* This is the one truly awful dwimmer necessary to conflate C and sed. */ |
| 3918 | |
| 3919 | STATIC int |
| 3920 | S_intuit_more(pTHX_ char *s) |
| 3921 | { |
| 3922 | dVAR; |
| 3923 | |
| 3924 | PERL_ARGS_ASSERT_INTUIT_MORE; |
| 3925 | |
| 3926 | if (PL_lex_brackets) |
| 3927 | return TRUE; |
| 3928 | if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{')) |
| 3929 | return TRUE; |
| 3930 | if (*s != '{' && *s != '[') |
| 3931 | return FALSE; |
| 3932 | if (!PL_lex_inpat) |
| 3933 | return TRUE; |
| 3934 | |
| 3935 | /* In a pattern, so maybe we have {n,m}. */ |
| 3936 | if (*s == '{') { |
| 3937 | if (regcurly(s, FALSE)) { |
| 3938 | return FALSE; |
| 3939 | } |
| 3940 | return TRUE; |
| 3941 | } |
| 3942 | |
| 3943 | /* On the other hand, maybe we have a character class */ |
| 3944 | |
| 3945 | s++; |
| 3946 | if (*s == ']' || *s == '^') |
| 3947 | return FALSE; |
| 3948 | else { |
| 3949 | /* this is terrifying, and it works */ |
| 3950 | int weight; |
| 3951 | char seen[256]; |
| 3952 | const char * const send = strchr(s,']'); |
| 3953 | unsigned char un_char, last_un_char; |
| 3954 | char tmpbuf[sizeof PL_tokenbuf * 4]; |
| 3955 | |
| 3956 | if (!send) /* has to be an expression */ |
| 3957 | return TRUE; |
| 3958 | weight = 2; /* let's weigh the evidence */ |
| 3959 | |
| 3960 | if (*s == '$') |
| 3961 | weight -= 3; |
| 3962 | else if (isDIGIT(*s)) { |
| 3963 | if (s[1] != ']') { |
| 3964 | if (isDIGIT(s[1]) && s[2] == ']') |
| 3965 | weight -= 10; |
| 3966 | } |
| 3967 | else |
| 3968 | weight -= 100; |
| 3969 | } |
| 3970 | Zero(seen,256,char); |
| 3971 | un_char = 255; |
| 3972 | for (; s < send; s++) { |
| 3973 | last_un_char = un_char; |
| 3974 | un_char = (unsigned char)*s; |
| 3975 | switch (*s) { |
| 3976 | case '@': |
| 3977 | case '&': |
| 3978 | case '$': |
| 3979 | weight -= seen[un_char] * 10; |
| 3980 | if (isWORDCHAR_lazy_if(s+1,UTF)) { |
| 3981 | int len; |
| 3982 | scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE); |
| 3983 | len = (int)strlen(tmpbuf); |
| 3984 | if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, |
| 3985 | UTF ? SVf_UTF8 : 0, SVt_PV)) |
| 3986 | weight -= 100; |
| 3987 | else |
| 3988 | weight -= 10; |
| 3989 | } |
| 3990 | else if (*s == '$' && s[1] && |
| 3991 | strchr("[#!%*<>()-=",s[1])) { |
| 3992 | if (/*{*/ strchr("])} =",s[2])) |
| 3993 | weight -= 10; |
| 3994 | else |
| 3995 | weight -= 1; |
| 3996 | } |
| 3997 | break; |
| 3998 | case '\\': |
| 3999 | un_char = 254; |
| 4000 | if (s[1]) { |
| 4001 | if (strchr("wds]",s[1])) |
| 4002 | weight += 100; |
| 4003 | else if (seen[(U8)'\''] || seen[(U8)'"']) |
| 4004 | weight += 1; |
| 4005 | else if (strchr("rnftbxcav",s[1])) |
| 4006 | weight += 40; |
| 4007 | else if (isDIGIT(s[1])) { |
| 4008 | weight += 40; |
| 4009 | while (s[1] && isDIGIT(s[1])) |
| 4010 | s++; |
| 4011 | } |
| 4012 | } |
| 4013 | else |
| 4014 | weight += 100; |
| 4015 | break; |
| 4016 | case '-': |
| 4017 | if (s[1] == '\\') |
| 4018 | weight += 50; |
| 4019 | if (strchr("aA01! ",last_un_char)) |
| 4020 | weight += 30; |
| 4021 | if (strchr("zZ79~",s[1])) |
| 4022 | weight += 30; |
| 4023 | if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$')) |
| 4024 | weight -= 5; /* cope with negative subscript */ |
| 4025 | break; |
| 4026 | default: |
| 4027 | if (!isWORDCHAR(last_un_char) |
| 4028 | && !(last_un_char == '$' || last_un_char == '@' |
| 4029 | || last_un_char == '&') |
| 4030 | && isALPHA(*s) && s[1] && isALPHA(s[1])) { |
| 4031 | char *d = tmpbuf; |
| 4032 | while (isALPHA(*s)) |
| 4033 | *d++ = *s++; |
| 4034 | *d = '\0'; |
| 4035 | if (keyword(tmpbuf, d - tmpbuf, 0)) |
| 4036 | weight -= 150; |
| 4037 | } |
| 4038 | if (un_char == last_un_char + 1) |
| 4039 | weight += 5; |
| 4040 | weight -= seen[un_char]; |
| 4041 | break; |
| 4042 | } |
| 4043 | seen[un_char]++; |
| 4044 | } |
| 4045 | if (weight >= 0) /* probably a character class */ |
| 4046 | return FALSE; |
| 4047 | } |
| 4048 | |
| 4049 | return TRUE; |
| 4050 | } |
| 4051 | |
| 4052 | /* |
| 4053 | * S_intuit_method |
| 4054 | * |
| 4055 | * Does all the checking to disambiguate |
| 4056 | * foo bar |
| 4057 | * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise |
| 4058 | * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args). |
| 4059 | * |
| 4060 | * First argument is the stuff after the first token, e.g. "bar". |
| 4061 | * |
| 4062 | * Not a method if foo is a filehandle. |
| 4063 | * Not a method if foo is a subroutine prototyped to take a filehandle. |
| 4064 | * Not a method if it's really "Foo $bar" |
| 4065 | * Method if it's "foo $bar" |
| 4066 | * Not a method if it's really "print foo $bar" |
| 4067 | * Method if it's really "foo package::" (interpreted as package->foo) |
| 4068 | * Not a method if bar is known to be a subroutine ("sub bar; foo bar") |
| 4069 | * Not a method if bar is a filehandle or package, but is quoted with |
| 4070 | * => |
| 4071 | */ |
| 4072 | |
| 4073 | STATIC int |
| 4074 | S_intuit_method(pTHX_ char *start, GV *gv, CV *cv) |
| 4075 | { |
| 4076 | dVAR; |
| 4077 | char *s = start + (*start == '$'); |
| 4078 | char tmpbuf[sizeof PL_tokenbuf]; |
| 4079 | STRLEN len; |
| 4080 | GV* indirgv; |
| 4081 | #ifdef PERL_MAD |
| 4082 | int soff; |
| 4083 | #endif |
| 4084 | |
| 4085 | PERL_ARGS_ASSERT_INTUIT_METHOD; |
| 4086 | |
| 4087 | if (gv && SvTYPE(gv) == SVt_PVGV && GvIO(gv)) |
| 4088 | return 0; |
| 4089 | if (cv && SvPOK(cv)) { |
| 4090 | const char *proto = CvPROTO(cv); |
| 4091 | if (proto) { |
| 4092 | while (*proto && (isSPACE(*proto) || *proto == ';')) |
| 4093 | proto++; |
| 4094 | if (*proto == '*') |
| 4095 | return 0; |
| 4096 | } |
| 4097 | } |
| 4098 | |
| 4099 | if (*start == '$') { |
| 4100 | if (cv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY || |
| 4101 | isUPPER(*PL_tokenbuf)) |
| 4102 | return 0; |
| 4103 | #ifdef PERL_MAD |
| 4104 | len = start - SvPVX(PL_linestr); |
| 4105 | #endif |
| 4106 | s = PEEKSPACE(s); |
| 4107 | #ifdef PERL_MAD |
| 4108 | start = SvPVX(PL_linestr) + len; |
| 4109 | #endif |
| 4110 | PL_bufptr = start; |
| 4111 | PL_expect = XREF; |
| 4112 | return *s == '(' ? FUNCMETH : METHOD; |
| 4113 | } |
| 4114 | |
| 4115 | s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
| 4116 | /* start is the beginning of the possible filehandle/object, |
| 4117 | * and s is the end of it |
| 4118 | * tmpbuf is a copy of it (but with single quotes as double colons) |
| 4119 | */ |
| 4120 | |
| 4121 | if (!keyword(tmpbuf, len, 0)) { |
| 4122 | if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') { |
| 4123 | len -= 2; |
| 4124 | tmpbuf[len] = '\0'; |
| 4125 | #ifdef PERL_MAD |
| 4126 | soff = s - SvPVX(PL_linestr); |
| 4127 | #endif |
| 4128 | goto bare_package; |
| 4129 | } |
| 4130 | indirgv = gv_fetchpvn_flags(tmpbuf, len, ( UTF ? SVf_UTF8 : 0 ), SVt_PVCV); |
| 4131 | if (indirgv && GvCVu(indirgv)) |
| 4132 | return 0; |
| 4133 | /* filehandle or package name makes it a method */ |
| 4134 | if (!cv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, UTF ? SVf_UTF8 : 0)) { |
| 4135 | #ifdef PERL_MAD |
| 4136 | soff = s - SvPVX(PL_linestr); |
| 4137 | #endif |
| 4138 | s = PEEKSPACE(s); |
| 4139 | if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>') |
| 4140 | return 0; /* no assumptions -- "=>" quotes bareword */ |
| 4141 | bare_package: |
| 4142 | start_force(PL_curforce); |
| 4143 | NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, |
| 4144 | S_newSV_maybe_utf8(aTHX_ tmpbuf, len)); |
| 4145 | NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE; |
| 4146 | if (PL_madskills) |
| 4147 | curmad('X', newSVpvn_flags(start,SvPVX(PL_linestr) + soff - start, |
| 4148 | ( UTF ? SVf_UTF8 : 0 ))); |
| 4149 | PL_expect = XTERM; |
| 4150 | force_next(WORD); |
| 4151 | PL_bufptr = s; |
| 4152 | #ifdef PERL_MAD |
| 4153 | PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */ |
| 4154 | #endif |
| 4155 | return *s == '(' ? FUNCMETH : METHOD; |
| 4156 | } |
| 4157 | } |
| 4158 | return 0; |
| 4159 | } |
| 4160 | |
| 4161 | /* Encoded script support. filter_add() effectively inserts a |
| 4162 | * 'pre-processing' function into the current source input stream. |
| 4163 | * Note that the filter function only applies to the current source file |
| 4164 | * (e.g., it will not affect files 'require'd or 'use'd by this one). |
| 4165 | * |
| 4166 | * The datasv parameter (which may be NULL) can be used to pass |
| 4167 | * private data to this instance of the filter. The filter function |
| 4168 | * can recover the SV using the FILTER_DATA macro and use it to |
| 4169 | * store private buffers and state information. |
| 4170 | * |
| 4171 | * The supplied datasv parameter is upgraded to a PVIO type |
| 4172 | * and the IoDIRP/IoANY field is used to store the function pointer, |
| 4173 | * and IOf_FAKE_DIRP is enabled on datasv to mark this as such. |
| 4174 | * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for |
| 4175 | * private use must be set using malloc'd pointers. |
| 4176 | */ |
| 4177 | |
| 4178 | SV * |
| 4179 | Perl_filter_add(pTHX_ filter_t funcp, SV *datasv) |
| 4180 | { |
| 4181 | dVAR; |
| 4182 | if (!funcp) |
| 4183 | return NULL; |
| 4184 | |
| 4185 | if (!PL_parser) |
| 4186 | return NULL; |
| 4187 | |
| 4188 | if (PL_parser->lex_flags & LEX_IGNORE_UTF8_HINTS) |
| 4189 | Perl_croak(aTHX_ "Source filters apply only to byte streams"); |
| 4190 | |
| 4191 | if (!PL_rsfp_filters) |
| 4192 | PL_rsfp_filters = newAV(); |
| 4193 | if (!datasv) |
| 4194 | datasv = newSV(0); |
| 4195 | SvUPGRADE(datasv, SVt_PVIO); |
| 4196 | IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */ |
| 4197 | IoFLAGS(datasv) |= IOf_FAKE_DIRP; |
| 4198 | DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n", |
| 4199 | FPTR2DPTR(void *, IoANY(datasv)), |
| 4200 | SvPV_nolen(datasv))); |
| 4201 | av_unshift(PL_rsfp_filters, 1); |
| 4202 | av_store(PL_rsfp_filters, 0, datasv) ; |
| 4203 | if ( |
| 4204 | !PL_parser->filtered |
| 4205 | && PL_parser->lex_flags & LEX_EVALBYTES |
| 4206 | && PL_bufptr < PL_bufend |
| 4207 | ) { |
| 4208 | const char *s = PL_bufptr; |
| 4209 | while (s < PL_bufend) { |
| 4210 | if (*s == '\n') { |
| 4211 | SV *linestr = PL_parser->linestr; |
| 4212 | char *buf = SvPVX(linestr); |
| 4213 | STRLEN const bufptr_pos = PL_parser->bufptr - buf; |
| 4214 | STRLEN const oldbufptr_pos = PL_parser->oldbufptr - buf; |
| 4215 | STRLEN const oldoldbufptr_pos=PL_parser->oldoldbufptr-buf; |
| 4216 | STRLEN const linestart_pos = PL_parser->linestart - buf; |
| 4217 | STRLEN const last_uni_pos = |
| 4218 | PL_parser->last_uni ? PL_parser->last_uni - buf : 0; |
| 4219 | STRLEN const last_lop_pos = |
| 4220 | PL_parser->last_lop ? PL_parser->last_lop - buf : 0; |
| 4221 | av_push(PL_rsfp_filters, linestr); |
| 4222 | PL_parser->linestr = |
| 4223 | newSVpvn(SvPVX(linestr), ++s-SvPVX(linestr)); |
| 4224 | buf = SvPVX(PL_parser->linestr); |
| 4225 | PL_parser->bufend = buf + SvCUR(PL_parser->linestr); |
| 4226 | PL_parser->bufptr = buf + bufptr_pos; |
| 4227 | PL_parser->oldbufptr = buf + oldbufptr_pos; |
| 4228 | PL_parser->oldoldbufptr = buf + oldoldbufptr_pos; |
| 4229 | PL_parser->linestart = buf + linestart_pos; |
| 4230 | if (PL_parser->last_uni) |
| 4231 | PL_parser->last_uni = buf + last_uni_pos; |
| 4232 | if (PL_parser->last_lop) |
| 4233 | PL_parser->last_lop = buf + last_lop_pos; |
| 4234 | SvLEN(linestr) = SvCUR(linestr); |
| 4235 | SvCUR(linestr) = s-SvPVX(linestr); |
| 4236 | PL_parser->filtered = 1; |
| 4237 | break; |
| 4238 | } |
| 4239 | s++; |
| 4240 | } |
| 4241 | } |
| 4242 | return(datasv); |
| 4243 | } |
| 4244 | |
| 4245 | |
| 4246 | /* Delete most recently added instance of this filter function. */ |
| 4247 | void |
| 4248 | Perl_filter_del(pTHX_ filter_t funcp) |
| 4249 | { |
| 4250 | dVAR; |
| 4251 | SV *datasv; |
| 4252 | |
| 4253 | PERL_ARGS_ASSERT_FILTER_DEL; |
| 4254 | |
| 4255 | #ifdef DEBUGGING |
| 4256 | DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", |
| 4257 | FPTR2DPTR(void*, funcp))); |
| 4258 | #endif |
| 4259 | if (!PL_parser || !PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0) |
| 4260 | return; |
| 4261 | /* if filter is on top of stack (usual case) just pop it off */ |
| 4262 | datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters)); |
| 4263 | if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) { |
| 4264 | sv_free(av_pop(PL_rsfp_filters)); |
| 4265 | |
| 4266 | return; |
| 4267 | } |
| 4268 | /* we need to search for the correct entry and clear it */ |
| 4269 | Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)"); |
| 4270 | } |
| 4271 | |
| 4272 | |
| 4273 | /* Invoke the idxth filter function for the current rsfp. */ |
| 4274 | /* maxlen 0 = read one text line */ |
| 4275 | I32 |
| 4276 | Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen) |
| 4277 | { |
| 4278 | dVAR; |
| 4279 | filter_t funcp; |
| 4280 | SV *datasv = NULL; |
| 4281 | /* This API is bad. It should have been using unsigned int for maxlen. |
| 4282 | Not sure if we want to change the API, but if not we should sanity |
| 4283 | check the value here. */ |
| 4284 | unsigned int correct_length |
| 4285 | = maxlen < 0 ? |
| 4286 | #ifdef PERL_MICRO |
| 4287 | 0x7FFFFFFF |
| 4288 | #else |
| 4289 | INT_MAX |
| 4290 | #endif |
| 4291 | : maxlen; |
| 4292 | |
| 4293 | PERL_ARGS_ASSERT_FILTER_READ; |
| 4294 | |
| 4295 | if (!PL_parser || !PL_rsfp_filters) |
| 4296 | return -1; |
| 4297 | if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */ |
| 4298 | /* Provide a default input filter to make life easy. */ |
| 4299 | /* Note that we append to the line. This is handy. */ |
| 4300 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
| 4301 | "filter_read %d: from rsfp\n", idx)); |
| 4302 | if (correct_length) { |
| 4303 | /* Want a block */ |
| 4304 | int len ; |
| 4305 | const int old_len = SvCUR(buf_sv); |
| 4306 | |
| 4307 | /* ensure buf_sv is large enough */ |
| 4308 | SvGROW(buf_sv, (STRLEN)(old_len + correct_length + 1)) ; |
| 4309 | if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, |
| 4310 | correct_length)) <= 0) { |
| 4311 | if (PerlIO_error(PL_rsfp)) |
| 4312 | return -1; /* error */ |
| 4313 | else |
| 4314 | return 0 ; /* end of file */ |
| 4315 | } |
| 4316 | SvCUR_set(buf_sv, old_len + len) ; |
| 4317 | SvPVX(buf_sv)[old_len + len] = '\0'; |
| 4318 | } else { |
| 4319 | /* Want a line */ |
| 4320 | if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) { |
| 4321 | if (PerlIO_error(PL_rsfp)) |
| 4322 | return -1; /* error */ |
| 4323 | else |
| 4324 | return 0 ; /* end of file */ |
| 4325 | } |
| 4326 | } |
| 4327 | return SvCUR(buf_sv); |
| 4328 | } |
| 4329 | /* Skip this filter slot if filter has been deleted */ |
| 4330 | if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) { |
| 4331 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
| 4332 | "filter_read %d: skipped (filter deleted)\n", |
| 4333 | idx)); |
| 4334 | return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */ |
| 4335 | } |
| 4336 | if (SvTYPE(datasv) != SVt_PVIO) { |
| 4337 | if (correct_length) { |
| 4338 | /* Want a block */ |
| 4339 | const STRLEN remainder = SvLEN(datasv) - SvCUR(datasv); |
| 4340 | if (!remainder) return 0; /* eof */ |
| 4341 | if (correct_length > remainder) correct_length = remainder; |
| 4342 | sv_catpvn(buf_sv, SvEND(datasv), correct_length); |
| 4343 | SvCUR_set(datasv, SvCUR(datasv) + correct_length); |
| 4344 | } else { |
| 4345 | /* Want a line */ |
| 4346 | const char *s = SvEND(datasv); |
| 4347 | const char *send = SvPVX(datasv) + SvLEN(datasv); |
| 4348 | while (s < send) { |
| 4349 | if (*s == '\n') { |
| 4350 | s++; |
| 4351 | break; |
| 4352 | } |
| 4353 | s++; |
| 4354 | } |
| 4355 | if (s == send) return 0; /* eof */ |
| 4356 | sv_catpvn(buf_sv, SvEND(datasv), s-SvEND(datasv)); |
| 4357 | SvCUR_set(datasv, s-SvPVX(datasv)); |
| 4358 | } |
| 4359 | return SvCUR(buf_sv); |
| 4360 | } |
| 4361 | /* Get function pointer hidden within datasv */ |
| 4362 | funcp = DPTR2FPTR(filter_t, IoANY(datasv)); |
| 4363 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
| 4364 | "filter_read %d: via function %p (%s)\n", |
| 4365 | idx, (void*)datasv, SvPV_nolen_const(datasv))); |
| 4366 | /* Call function. The function is expected to */ |
| 4367 | /* call "FILTER_READ(idx+1, buf_sv)" first. */ |
| 4368 | /* Return: <0:error, =0:eof, >0:not eof */ |
| 4369 | return (*funcp)(aTHX_ idx, buf_sv, correct_length); |
| 4370 | } |
| 4371 | |
| 4372 | STATIC char * |
| 4373 | S_filter_gets(pTHX_ SV *sv, STRLEN append) |
| 4374 | { |
| 4375 | dVAR; |
| 4376 | |
| 4377 | PERL_ARGS_ASSERT_FILTER_GETS; |
| 4378 | |
| 4379 | #ifdef PERL_CR_FILTER |
| 4380 | if (!PL_rsfp_filters) { |
| 4381 | filter_add(S_cr_textfilter,NULL); |
| 4382 | } |
| 4383 | #endif |
| 4384 | if (PL_rsfp_filters) { |
| 4385 | if (!append) |
| 4386 | SvCUR_set(sv, 0); /* start with empty line */ |
| 4387 | if (FILTER_READ(0, sv, 0) > 0) |
| 4388 | return ( SvPVX(sv) ) ; |
| 4389 | else |
| 4390 | return NULL ; |
| 4391 | } |
| 4392 | else |
| 4393 | return (sv_gets(sv, PL_rsfp, append)); |
| 4394 | } |
| 4395 | |
| 4396 | STATIC HV * |
| 4397 | S_find_in_my_stash(pTHX_ const char *pkgname, STRLEN len) |
| 4398 | { |
| 4399 | dVAR; |
| 4400 | GV *gv; |
| 4401 | |
| 4402 | PERL_ARGS_ASSERT_FIND_IN_MY_STASH; |
| 4403 | |
| 4404 | if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__")) |
| 4405 | return PL_curstash; |
| 4406 | |
| 4407 | if (len > 2 && |
| 4408 | (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') && |
| 4409 | (gv = gv_fetchpvn_flags(pkgname, len, ( UTF ? SVf_UTF8 : 0 ), SVt_PVHV))) |
| 4410 | { |
| 4411 | return GvHV(gv); /* Foo:: */ |
| 4412 | } |
| 4413 | |
| 4414 | /* use constant CLASS => 'MyClass' */ |
| 4415 | gv = gv_fetchpvn_flags(pkgname, len, UTF ? SVf_UTF8 : 0, SVt_PVCV); |
| 4416 | if (gv && GvCV(gv)) { |
| 4417 | SV * const sv = cv_const_sv(GvCV(gv)); |
| 4418 | if (sv) |
| 4419 | pkgname = SvPV_const(sv, len); |
| 4420 | } |
| 4421 | |
| 4422 | return gv_stashpvn(pkgname, len, UTF ? SVf_UTF8 : 0); |
| 4423 | } |
| 4424 | |
| 4425 | /* |
| 4426 | * S_readpipe_override |
| 4427 | * Check whether readpipe() is overridden, and generates the appropriate |
| 4428 | * optree, provided sublex_start() is called afterwards. |
| 4429 | */ |
| 4430 | STATIC void |
| 4431 | S_readpipe_override(pTHX) |
| 4432 | { |
| 4433 | GV **gvp; |
| 4434 | GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV); |
| 4435 | pl_yylval.ival = OP_BACKTICK; |
| 4436 | if ((gv_readpipe |
| 4437 | && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)) |
| 4438 | || |
| 4439 | ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE)) |
| 4440 | && (gv_readpipe = *gvp) && isGV_with_GP(gv_readpipe) |
| 4441 | && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))) |
| 4442 | { |
| 4443 | PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, |
| 4444 | op_append_elem(OP_LIST, |
| 4445 | newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */ |
| 4446 | newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe)))); |
| 4447 | } |
| 4448 | } |
| 4449 | |
| 4450 | #ifdef PERL_MAD |
| 4451 | /* |
| 4452 | * Perl_madlex |
| 4453 | * The intent of this yylex wrapper is to minimize the changes to the |
| 4454 | * tokener when we aren't interested in collecting madprops. It remains |
| 4455 | * to be seen how successful this strategy will be... |
| 4456 | */ |
| 4457 | |
| 4458 | int |
| 4459 | Perl_madlex(pTHX) |
| 4460 | { |
| 4461 | int optype; |
| 4462 | char *s = PL_bufptr; |
| 4463 | |
| 4464 | /* make sure PL_thiswhite is initialized */ |
| 4465 | PL_thiswhite = 0; |
| 4466 | PL_thismad = 0; |
| 4467 | |
| 4468 | /* previous token ate up our whitespace? */ |
| 4469 | if (!PL_lasttoke && PL_nextwhite) { |
| 4470 | PL_thiswhite = PL_nextwhite; |
| 4471 | PL_nextwhite = 0; |
| 4472 | } |
| 4473 | |
| 4474 | /* isolate the token, and figure out where it is without whitespace */ |
| 4475 | PL_realtokenstart = -1; |
| 4476 | PL_thistoken = 0; |
| 4477 | optype = yylex(); |
| 4478 | s = PL_bufptr; |
| 4479 | assert(PL_curforce < 0); |
| 4480 | |
| 4481 | if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */ |
| 4482 | if (!PL_thistoken) { |
| 4483 | if (PL_realtokenstart < 0 || !CopLINE(PL_curcop)) |
| 4484 | PL_thistoken = newSVpvs(""); |
| 4485 | else { |
| 4486 | char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart; |
| 4487 | PL_thistoken = newSVpvn(tstart, s - tstart); |
| 4488 | } |
| 4489 | } |
| 4490 | if (PL_thismad) /* install head */ |
| 4491 | CURMAD('X', PL_thistoken); |
| 4492 | } |
| 4493 | |
| 4494 | /* last whitespace of a sublex? */ |
| 4495 | if (optype == ')' && PL_endwhite) { |
| 4496 | CURMAD('X', PL_endwhite); |
| 4497 | } |
| 4498 | |
| 4499 | if (!PL_thismad) { |
| 4500 | |
| 4501 | /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */ |
| 4502 | if (!PL_thiswhite && !PL_endwhite && !optype) { |
| 4503 | sv_free(PL_thistoken); |
| 4504 | PL_thistoken = 0; |
| 4505 | return 0; |
| 4506 | } |
| 4507 | |
| 4508 | /* put off final whitespace till peg */ |
| 4509 | if (optype == ';' && !PL_rsfp && !PL_parser->filtered) { |
| 4510 | PL_nextwhite = PL_thiswhite; |
| 4511 | PL_thiswhite = 0; |
| 4512 | } |
| 4513 | else if (PL_thisopen) { |
| 4514 | CURMAD('q', PL_thisopen); |
| 4515 | if (PL_thistoken) |
| 4516 | sv_free(PL_thistoken); |
| 4517 | PL_thistoken = 0; |
| 4518 | } |
| 4519 | else { |
| 4520 | /* Store actual token text as madprop X */ |
| 4521 | CURMAD('X', PL_thistoken); |
| 4522 | } |
| 4523 | |
| 4524 | if (PL_thiswhite) { |
| 4525 | /* add preceding whitespace as madprop _ */ |
| 4526 | CURMAD('_', PL_thiswhite); |
| 4527 | } |
| 4528 | |
| 4529 | if (PL_thisstuff) { |
| 4530 | /* add quoted material as madprop = */ |
| 4531 | CURMAD('=', PL_thisstuff); |
| 4532 | } |
| 4533 | |
| 4534 | if (PL_thisclose) { |
| 4535 | /* add terminating quote as madprop Q */ |
| 4536 | CURMAD('Q', PL_thisclose); |
| 4537 | } |
| 4538 | } |
| 4539 | |
| 4540 | /* special processing based on optype */ |
| 4541 | |
| 4542 | switch (optype) { |
| 4543 | |
| 4544 | /* opval doesn't need a TOKEN since it can already store mp */ |
| 4545 | case WORD: |
| 4546 | case METHOD: |
| 4547 | case FUNCMETH: |
| 4548 | case THING: |
| 4549 | case PMFUNC: |
| 4550 | case PRIVATEREF: |
| 4551 | case FUNC0SUB: |
| 4552 | case UNIOPSUB: |
| 4553 | case LSTOPSUB: |
| 4554 | if (pl_yylval.opval) |
| 4555 | append_madprops(PL_thismad, pl_yylval.opval, 0); |
| 4556 | PL_thismad = 0; |
| 4557 | return optype; |
| 4558 | |
| 4559 | /* fake EOF */ |
| 4560 | case 0: |
| 4561 | optype = PEG; |
| 4562 | if (PL_endwhite) { |
| 4563 | addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0); |
| 4564 | PL_endwhite = 0; |
| 4565 | } |
| 4566 | break; |
| 4567 | |
| 4568 | /* pval */ |
| 4569 | case LABEL: |
| 4570 | break; |
| 4571 | |
| 4572 | case ']': |
| 4573 | case '}': |
| 4574 | if (PL_faketokens) |
| 4575 | break; |
| 4576 | /* remember any fake bracket that lexer is about to discard */ |
| 4577 | if (PL_lex_brackets == 1 && |
| 4578 | ((expectation)PL_lex_brackstack[0] & XFAKEBRACK)) |
| 4579 | { |
| 4580 | s = PL_bufptr; |
| 4581 | while (s < PL_bufend && (*s == ' ' || *s == '\t')) |
| 4582 | s++; |
| 4583 | if (*s == '}') { |
| 4584 | PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr); |
| 4585 | addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0); |
| 4586 | PL_thiswhite = 0; |
| 4587 | PL_bufptr = s - 1; |
| 4588 | break; /* don't bother looking for trailing comment */ |
| 4589 | } |
| 4590 | else |
| 4591 | s = PL_bufptr; |
| 4592 | } |
| 4593 | if (optype == ']') |
| 4594 | break; |
| 4595 | /* FALLTHROUGH */ |
| 4596 | |
| 4597 | /* attach a trailing comment to its statement instead of next token */ |
| 4598 | case ';': |
| 4599 | if (PL_faketokens) |
| 4600 | break; |
| 4601 | if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) { |
| 4602 | s = PL_bufptr; |
| 4603 | while (s < PL_bufend && (*s == ' ' || *s == '\t')) |
| 4604 | s++; |
| 4605 | if (*s == '\n' || *s == '#') { |
| 4606 | while (s < PL_bufend && *s != '\n') |
| 4607 | s++; |
| 4608 | if (s < PL_bufend) |
| 4609 | s++; |
| 4610 | PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr); |
| 4611 | addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0); |
| 4612 | PL_thiswhite = 0; |
| 4613 | PL_bufptr = s; |
| 4614 | } |
| 4615 | } |
| 4616 | break; |
| 4617 | |
| 4618 | /* ival */ |
| 4619 | default: |
| 4620 | break; |
| 4621 | |
| 4622 | } |
| 4623 | |
| 4624 | /* Create new token struct. Note: opvals return early above. */ |
| 4625 | pl_yylval.tkval = newTOKEN(optype, pl_yylval, PL_thismad); |
| 4626 | PL_thismad = 0; |
| 4627 | return optype; |
| 4628 | } |
| 4629 | #endif |
| 4630 | |
| 4631 | STATIC char * |
| 4632 | S_tokenize_use(pTHX_ int is_use, char *s) { |
| 4633 | dVAR; |
| 4634 | |
| 4635 | PERL_ARGS_ASSERT_TOKENIZE_USE; |
| 4636 | |
| 4637 | if (PL_expect != XSTATE) |
| 4638 | yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression", |
| 4639 | is_use ? "use" : "no")); |
| 4640 | PL_expect = XTERM; |
| 4641 | s = SKIPSPACE1(s); |
| 4642 | if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) { |
| 4643 | s = force_version(s, TRUE); |
| 4644 | if (*s == ';' || *s == '}' |
| 4645 | || (s = SKIPSPACE1(s), (*s == ';' || *s == '}'))) { |
| 4646 | start_force(PL_curforce); |
| 4647 | NEXTVAL_NEXTTOKE.opval = NULL; |
| 4648 | force_next(WORD); |
| 4649 | } |
| 4650 | else if (*s == 'v') { |
| 4651 | s = force_word(s,WORD,FALSE,TRUE); |
| 4652 | s = force_version(s, FALSE); |
| 4653 | } |
| 4654 | } |
| 4655 | else { |
| 4656 | s = force_word(s,WORD,FALSE,TRUE); |
| 4657 | s = force_version(s, FALSE); |
| 4658 | } |
| 4659 | pl_yylval.ival = is_use; |
| 4660 | return s; |
| 4661 | } |
| 4662 | #ifdef DEBUGGING |
| 4663 | static const char* const exp_name[] = |
| 4664 | { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK", |
| 4665 | "ATTRTERM", "TERMBLOCK", "TERMORDORDOR" |
| 4666 | }; |
| 4667 | #endif |
| 4668 | |
| 4669 | #define word_takes_any_delimeter(p,l) S_word_takes_any_delimeter(p,l) |
| 4670 | STATIC bool |
| 4671 | S_word_takes_any_delimeter(char *p, STRLEN len) |
| 4672 | { |
| 4673 | return (len == 1 && strchr("msyq", p[0])) || |
| 4674 | (len == 2 && ( |
| 4675 | (p[0] == 't' && p[1] == 'r') || |
| 4676 | (p[0] == 'q' && strchr("qwxr", p[1])))); |
| 4677 | } |
| 4678 | |
| 4679 | /* |
| 4680 | yylex |
| 4681 | |
| 4682 | Works out what to call the token just pulled out of the input |
| 4683 | stream. The yacc parser takes care of taking the ops we return and |
| 4684 | stitching them into a tree. |
| 4685 | |
| 4686 | Returns: |
| 4687 | The type of the next token |
| 4688 | |
| 4689 | Structure: |
| 4690 | Switch based on the current state: |
| 4691 | - if we already built the token before, use it |
| 4692 | - if we have a case modifier in a string, deal with that |
| 4693 | - handle other cases of interpolation inside a string |
| 4694 | - scan the next line if we are inside a format |
| 4695 | In the normal state switch on the next character: |
| 4696 | - default: |
| 4697 | if alphabetic, go to key lookup |
| 4698 | unrecoginized character - croak |
| 4699 | - 0/4/26: handle end-of-line or EOF |
| 4700 | - cases for whitespace |
| 4701 | - \n and #: handle comments and line numbers |
| 4702 | - various operators, brackets and sigils |
| 4703 | - numbers |
| 4704 | - quotes |
| 4705 | - 'v': vstrings (or go to key lookup) |
| 4706 | - 'x' repetition operator (or go to key lookup) |
| 4707 | - other ASCII alphanumerics (key lookup begins here): |
| 4708 | word before => ? |
| 4709 | keyword plugin |
| 4710 | scan built-in keyword (but do nothing with it yet) |
| 4711 | check for statement label |
| 4712 | check for lexical subs |
| 4713 | goto just_a_word if there is one |
| 4714 | see whether built-in keyword is overridden |
| 4715 | switch on keyword number: |
| 4716 | - default: just_a_word: |
| 4717 | not a built-in keyword; handle bareword lookup |
| 4718 | disambiguate between method and sub call |
| 4719 | fall back to bareword |
| 4720 | - cases for built-in keywords |
| 4721 | */ |
| 4722 | |
| 4723 | |
| 4724 | #ifdef __SC__ |
| 4725 | #pragma segment Perl_yylex |
| 4726 | #endif |
| 4727 | int |
| 4728 | Perl_yylex(pTHX) |
| 4729 | { |
| 4730 | dVAR; |
| 4731 | char *s = PL_bufptr; |
| 4732 | char *d; |
| 4733 | STRLEN len; |
| 4734 | bool bof = FALSE; |
| 4735 | const bool saw_infix_sigil = PL_parser->saw_infix_sigil; |
| 4736 | U8 formbrack = 0; |
| 4737 | U32 fake_eof = 0; |
| 4738 | |
| 4739 | /* orig_keyword, gvp, and gv are initialized here because |
| 4740 | * jump to the label just_a_word_zero can bypass their |
| 4741 | * initialization later. */ |
| 4742 | I32 orig_keyword = 0; |
| 4743 | GV *gv = NULL; |
| 4744 | GV **gvp = NULL; |
| 4745 | |
| 4746 | DEBUG_T( { |
| 4747 | SV* tmp = newSVpvs(""); |
| 4748 | PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n", |
| 4749 | (IV)CopLINE(PL_curcop), |
| 4750 | lex_state_names[PL_lex_state], |
| 4751 | exp_name[PL_expect], |
| 4752 | pv_display(tmp, s, strlen(s), 0, 60)); |
| 4753 | SvREFCNT_dec(tmp); |
| 4754 | } ); |
| 4755 | |
| 4756 | switch (PL_lex_state) { |
| 4757 | #ifdef COMMENTARY |
| 4758 | case LEX_NORMAL: /* Some compilers will produce faster */ |
| 4759 | case LEX_INTERPNORMAL: /* code if we comment these out. */ |
| 4760 | break; |
| 4761 | #endif |
| 4762 | |
| 4763 | /* when we've already built the next token, just pull it out of the queue */ |
| 4764 | case LEX_KNOWNEXT: |
| 4765 | #ifdef PERL_MAD |
| 4766 | PL_lasttoke--; |
| 4767 | pl_yylval = PL_nexttoke[PL_lasttoke].next_val; |
| 4768 | if (PL_madskills) { |
| 4769 | PL_thismad = PL_nexttoke[PL_lasttoke].next_mad; |
| 4770 | PL_nexttoke[PL_lasttoke].next_mad = 0; |
| 4771 | if (PL_thismad && PL_thismad->mad_key == '_') { |
| 4772 | PL_thiswhite = MUTABLE_SV(PL_thismad->mad_val); |
| 4773 | PL_thismad->mad_val = 0; |
| 4774 | mad_free(PL_thismad); |
| 4775 | PL_thismad = 0; |
| 4776 | } |
| 4777 | } |
| 4778 | if (!PL_lasttoke) { |
| 4779 | PL_lex_state = PL_lex_defer; |
| 4780 | PL_expect = PL_lex_expect; |
| 4781 | PL_lex_defer = LEX_NORMAL; |
| 4782 | if (!PL_nexttoke[PL_lasttoke].next_type) |
| 4783 | return yylex(); |
| 4784 | } |
| 4785 | #else |
| 4786 | PL_nexttoke--; |
| 4787 | pl_yylval = PL_nextval[PL_nexttoke]; |
| 4788 | if (!PL_nexttoke) { |
| 4789 | PL_lex_state = PL_lex_defer; |
| 4790 | PL_expect = PL_lex_expect; |
| 4791 | PL_lex_defer = LEX_NORMAL; |
| 4792 | } |
| 4793 | #endif |
| 4794 | { |
| 4795 | I32 next_type; |
| 4796 | #ifdef PERL_MAD |
| 4797 | next_type = PL_nexttoke[PL_lasttoke].next_type; |
| 4798 | #else |
| 4799 | next_type = PL_nexttype[PL_nexttoke]; |
| 4800 | #endif |
| 4801 | if (next_type & (7<<24)) { |
| 4802 | if (next_type & (1<<24)) { |
| 4803 | if (PL_lex_brackets > 100) |
| 4804 | Renew(PL_lex_brackstack, PL_lex_brackets + 10, char); |
| 4805 | PL_lex_brackstack[PL_lex_brackets++] = |
| 4806 | (char) ((next_type >> 16) & 0xff); |
| 4807 | } |
| 4808 | if (next_type & (2<<24)) |
| 4809 | PL_lex_allbrackets++; |
| 4810 | if (next_type & (4<<24)) |
| 4811 | PL_lex_allbrackets--; |
| 4812 | next_type &= 0xffff; |
| 4813 | } |
| 4814 | return REPORT(next_type == 'p' ? pending_ident() : next_type); |
| 4815 | } |
| 4816 | |
| 4817 | /* interpolated case modifiers like \L \U, including \Q and \E. |
| 4818 | when we get here, PL_bufptr is at the \ |
| 4819 | */ |
| 4820 | case LEX_INTERPCASEMOD: |
| 4821 | #ifdef DEBUGGING |
| 4822 | if (PL_bufptr != PL_bufend && *PL_bufptr != '\\') |
| 4823 | Perl_croak(aTHX_ |
| 4824 | "panic: INTERPCASEMOD bufptr=%p, bufend=%p, *bufptr=%u", |
| 4825 | PL_bufptr, PL_bufend, *PL_bufptr); |
| 4826 | #endif |
| 4827 | /* handle \E or end of string */ |
| 4828 | if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') { |
| 4829 | /* if at a \E */ |
| 4830 | if (PL_lex_casemods) { |
| 4831 | const char oldmod = PL_lex_casestack[--PL_lex_casemods]; |
| 4832 | PL_lex_casestack[PL_lex_casemods] = '\0'; |
| 4833 | |
| 4834 | if (PL_bufptr != PL_bufend |
| 4835 | && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q' |
| 4836 | || oldmod == 'F')) { |
| 4837 | PL_bufptr += 2; |
| 4838 | PL_lex_state = LEX_INTERPCONCAT; |
| 4839 | #ifdef PERL_MAD |
| 4840 | if (PL_madskills) |
| 4841 | PL_thistoken = newSVpvs("\\E"); |
| 4842 | #endif |
| 4843 | } |
| 4844 | PL_lex_allbrackets--; |
| 4845 | return REPORT(')'); |
| 4846 | } |
| 4847 | else if ( PL_bufptr != PL_bufend && PL_bufptr[1] == 'E' ) { |
| 4848 | /* Got an unpaired \E */ |
| 4849 | Perl_ck_warner(aTHX_ packWARN(WARN_MISC), |
| 4850 | "Useless use of \\E"); |
| 4851 | } |
| 4852 | #ifdef PERL_MAD |
| 4853 | while (PL_bufptr != PL_bufend && |
| 4854 | PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') { |
| 4855 | if (PL_madskills) { |
| 4856 | if (!PL_thiswhite) |
| 4857 | PL_thiswhite = newSVpvs(""); |
| 4858 | sv_catpvn(PL_thiswhite, PL_bufptr, 2); |
| 4859 | } |
| 4860 | PL_bufptr += 2; |
| 4861 | } |
| 4862 | #else |
| 4863 | if (PL_bufptr != PL_bufend) |
| 4864 | PL_bufptr += 2; |
| 4865 | #endif |
| 4866 | PL_lex_state = LEX_INTERPCONCAT; |
| 4867 | return yylex(); |
| 4868 | } |
| 4869 | else { |
| 4870 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
| 4871 | "### Saw case modifier\n"); }); |
| 4872 | s = PL_bufptr + 1; |
| 4873 | if (s[1] == '\\' && s[2] == 'E') { |
| 4874 | #ifdef PERL_MAD |
| 4875 | if (PL_madskills) { |
| 4876 | if (!PL_thiswhite) |
| 4877 | PL_thiswhite = newSVpvs(""); |
| 4878 | sv_catpvn(PL_thiswhite, PL_bufptr, 4); |
| 4879 | } |
| 4880 | #endif |
| 4881 | PL_bufptr = s + 3; |
| 4882 | PL_lex_state = LEX_INTERPCONCAT; |
| 4883 | return yylex(); |
| 4884 | } |
| 4885 | else { |
| 4886 | I32 tmp; |
| 4887 | if (!PL_madskills) /* when just compiling don't need correct */ |
| 4888 | if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3)) |
| 4889 | tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */ |
| 4890 | if ((*s == 'L' || *s == 'U' || *s == 'F') && |
| 4891 | (strchr(PL_lex_casestack, 'L') |
| 4892 | || strchr(PL_lex_casestack, 'U') |
| 4893 | || strchr(PL_lex_casestack, 'F'))) { |
| 4894 | PL_lex_casestack[--PL_lex_casemods] = '\0'; |
| 4895 | PL_lex_allbrackets--; |
| 4896 | return REPORT(')'); |
| 4897 | } |
| 4898 | if (PL_lex_casemods > 10) |
| 4899 | Renew(PL_lex_casestack, PL_lex_casemods + 2, char); |
| 4900 | PL_lex_casestack[PL_lex_casemods++] = *s; |
| 4901 | PL_lex_casestack[PL_lex_casemods] = '\0'; |
| 4902 | PL_lex_state = LEX_INTERPCONCAT; |
| 4903 | start_force(PL_curforce); |
| 4904 | NEXTVAL_NEXTTOKE.ival = 0; |
| 4905 | force_next((2<<24)|'('); |
| 4906 | start_force(PL_curforce); |
| 4907 | if (*s == 'l') |
| 4908 | NEXTVAL_NEXTTOKE.ival = OP_LCFIRST; |
| 4909 | else if (*s == 'u') |
| 4910 | NEXTVAL_NEXTTOKE.ival = OP_UCFIRST; |
| 4911 | else if (*s == 'L') |
| 4912 | NEXTVAL_NEXTTOKE.ival = OP_LC; |
| 4913 | else if (*s == 'U') |
| 4914 | NEXTVAL_NEXTTOKE.ival = OP_UC; |
| 4915 | else if (*s == 'Q') |
| 4916 | NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA; |
| 4917 | else if (*s == 'F') |
| 4918 | NEXTVAL_NEXTTOKE.ival = OP_FC; |
| 4919 | else |
| 4920 | Perl_croak(aTHX_ "panic: yylex, *s=%u", *s); |
| 4921 | if (PL_madskills) { |
| 4922 | SV* const tmpsv = newSVpvs("\\ "); |
| 4923 | /* replace the space with the character we want to escape |
| 4924 | */ |
| 4925 | SvPVX(tmpsv)[1] = *s; |
| 4926 | curmad('_', tmpsv); |
| 4927 | } |
| 4928 | PL_bufptr = s + 1; |
| 4929 | } |
| 4930 | force_next(FUNC); |
| 4931 | if (PL_lex_starts) { |
| 4932 | s = PL_bufptr; |
| 4933 | PL_lex_starts = 0; |
| 4934 | #ifdef PERL_MAD |
| 4935 | if (PL_madskills) { |
| 4936 | if (PL_thistoken) |
| 4937 | sv_free(PL_thistoken); |
| 4938 | PL_thistoken = newSVpvs(""); |
| 4939 | } |
| 4940 | #endif |
| 4941 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ |
| 4942 | if (PL_lex_casemods == 1 && PL_lex_inpat) |
| 4943 | OPERATOR(','); |
| 4944 | else |
| 4945 | Aop(OP_CONCAT); |
| 4946 | } |
| 4947 | else |
| 4948 | return yylex(); |
| 4949 | } |
| 4950 | |
| 4951 | case LEX_INTERPPUSH: |
| 4952 | return REPORT(sublex_push()); |
| 4953 | |
| 4954 | case LEX_INTERPSTART: |
| 4955 | if (PL_bufptr == PL_bufend) |
| 4956 | return REPORT(sublex_done()); |
| 4957 | DEBUG_T({ if(*PL_bufptr != '(') PerlIO_printf(Perl_debug_log, |
| 4958 | "### Interpolated variable\n"); }); |
| 4959 | PL_expect = XTERM; |
| 4960 | /* for /@a/, we leave the joining for the regex engine to do |
| 4961 | * (unless we're within \Q etc) */ |
| 4962 | PL_lex_dojoin = (*PL_bufptr == '@' |
| 4963 | && (!PL_lex_inpat || PL_lex_casemods)); |
| 4964 | PL_lex_state = LEX_INTERPNORMAL; |
| 4965 | if (PL_lex_dojoin) { |
| 4966 | start_force(PL_curforce); |
| 4967 | NEXTVAL_NEXTTOKE.ival = 0; |
| 4968 | force_next(','); |
| 4969 | start_force(PL_curforce); |
| 4970 | force_ident("\"", '$'); |
| 4971 | start_force(PL_curforce); |
| 4972 | NEXTVAL_NEXTTOKE.ival = 0; |
| 4973 | force_next('$'); |
| 4974 | start_force(PL_curforce); |
| 4975 | NEXTVAL_NEXTTOKE.ival = 0; |
| 4976 | force_next((2<<24)|'('); |
| 4977 | start_force(PL_curforce); |
| 4978 | NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */ |
| 4979 | force_next(FUNC); |
| 4980 | } |
| 4981 | /* Convert (?{...}) and friends to 'do {...}' */ |
| 4982 | if (PL_lex_inpat && *PL_bufptr == '(') { |
| 4983 | PL_parser->lex_shared->re_eval_start = PL_bufptr; |
| 4984 | PL_bufptr += 2; |
| 4985 | if (*PL_bufptr != '{') |
| 4986 | PL_bufptr++; |
| 4987 | start_force(PL_curforce); |
| 4988 | /* XXX probably need a CURMAD(something) here */ |
| 4989 | PL_expect = XTERMBLOCK; |
| 4990 | force_next(DO); |
| 4991 | } |
| 4992 | |
| 4993 | if (PL_lex_starts++) { |
| 4994 | s = PL_bufptr; |
| 4995 | #ifdef PERL_MAD |
| 4996 | if (PL_madskills) { |
| 4997 | if (PL_thistoken) |
| 4998 | sv_free(PL_thistoken); |
| 4999 | PL_thistoken = newSVpvs(""); |
| 5000 | } |
| 5001 | #endif |
| 5002 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ |
| 5003 | if (!PL_lex_casemods && PL_lex_inpat) |
| 5004 | OPERATOR(','); |
| 5005 | else |
| 5006 | Aop(OP_CONCAT); |
| 5007 | } |
| 5008 | return yylex(); |
| 5009 | |
| 5010 | case LEX_INTERPENDMAYBE: |
| 5011 | if (intuit_more(PL_bufptr)) { |
| 5012 | PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */ |
| 5013 | break; |
| 5014 | } |
| 5015 | /* FALL THROUGH */ |
| 5016 | |
| 5017 | case LEX_INTERPEND: |
| 5018 | if (PL_lex_dojoin) { |
| 5019 | PL_lex_dojoin = FALSE; |
| 5020 | PL_lex_state = LEX_INTERPCONCAT; |
| 5021 | #ifdef PERL_MAD |
| 5022 | if (PL_madskills) { |
| 5023 | if (PL_thistoken) |
| 5024 | sv_free(PL_thistoken); |
| 5025 | PL_thistoken = newSVpvs(""); |
| 5026 | } |
| 5027 | #endif |
| 5028 | PL_lex_allbrackets--; |
| 5029 | return REPORT(')'); |
| 5030 | } |
| 5031 | if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl |
| 5032 | && SvEVALED(PL_lex_repl)) |
| 5033 | { |
| 5034 | if (PL_bufptr != PL_bufend) |
| 5035 | Perl_croak(aTHX_ "Bad evalled substitution pattern"); |
| 5036 | PL_lex_repl = NULL; |
| 5037 | } |
| 5038 | /* Paranoia. re_eval_start is adjusted when S_scan_heredoc sets |
| 5039 | re_eval_str. If the here-doc body’s length equals the previous |
| 5040 | value of re_eval_start, re_eval_start will now be null. So |
| 5041 | check re_eval_str as well. */ |
| 5042 | if (PL_parser->lex_shared->re_eval_start |
| 5043 | || PL_parser->lex_shared->re_eval_str) { |
| 5044 | SV *sv; |
| 5045 | if (*PL_bufptr != ')') |
| 5046 | Perl_croak(aTHX_ "Sequence (?{...}) not terminated with ')'"); |
| 5047 | PL_bufptr++; |
| 5048 | /* having compiled a (?{..}) expression, return the original |
| 5049 | * text too, as a const */ |
| 5050 | if (PL_parser->lex_shared->re_eval_str) { |
| 5051 | sv = PL_parser->lex_shared->re_eval_str; |
| 5052 | PL_parser->lex_shared->re_eval_str = NULL; |
| 5053 | SvCUR_set(sv, |
| 5054 | PL_bufptr - PL_parser->lex_shared->re_eval_start); |
| 5055 | SvPV_shrink_to_cur(sv); |
| 5056 | } |
| 5057 | else sv = newSVpvn(PL_parser->lex_shared->re_eval_start, |
| 5058 | PL_bufptr - PL_parser->lex_shared->re_eval_start); |
| 5059 | start_force(PL_curforce); |
| 5060 | /* XXX probably need a CURMAD(something) here */ |
| 5061 | NEXTVAL_NEXTTOKE.opval = |
| 5062 | (OP*)newSVOP(OP_CONST, 0, |
| 5063 | sv); |
| 5064 | force_next(THING); |
| 5065 | PL_parser->lex_shared->re_eval_start = NULL; |
| 5066 | PL_expect = XTERM; |
| 5067 | return REPORT(','); |
| 5068 | } |
| 5069 | |
| 5070 | /* FALLTHROUGH */ |
| 5071 | case LEX_INTERPCONCAT: |
| 5072 | #ifdef DEBUGGING |
| 5073 | if (PL_lex_brackets) |
| 5074 | Perl_croak(aTHX_ "panic: INTERPCONCAT, lex_brackets=%ld", |
| 5075 | (long) PL_lex_brackets); |
| 5076 | #endif |
| 5077 | if (PL_bufptr == PL_bufend) |
| 5078 | return REPORT(sublex_done()); |
| 5079 | |
| 5080 | /* m'foo' still needs to be parsed for possible (?{...}) */ |
| 5081 | if (SvIVX(PL_linestr) == '\'' && !PL_lex_inpat) { |
| 5082 | SV *sv = newSVsv(PL_linestr); |
| 5083 | sv = tokeq(sv); |
| 5084 | pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
| 5085 | s = PL_bufend; |
| 5086 | } |
| 5087 | else { |
| 5088 | s = scan_const(PL_bufptr); |
| 5089 | if (*s == '\\') |
| 5090 | PL_lex_state = LEX_INTERPCASEMOD; |
| 5091 | else |
| 5092 | PL_lex_state = LEX_INTERPSTART; |
| 5093 | } |
| 5094 | |
| 5095 | if (s != PL_bufptr) { |
| 5096 | start_force(PL_curforce); |
| 5097 | if (PL_madskills) { |
| 5098 | curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr)); |
| 5099 | } |
| 5100 | NEXTVAL_NEXTTOKE = pl_yylval; |
| 5101 | PL_expect = XTERM; |
| 5102 | force_next(THING); |
| 5103 | if (PL_lex_starts++) { |
| 5104 | #ifdef PERL_MAD |
| 5105 | if (PL_madskills) { |
| 5106 | if (PL_thistoken) |
| 5107 | sv_free(PL_thistoken); |
| 5108 | PL_thistoken = newSVpvs(""); |
| 5109 | } |
| 5110 | #endif |
| 5111 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ |
| 5112 | if (!PL_lex_casemods && PL_lex_inpat) |
| 5113 | OPERATOR(','); |
| 5114 | else |
| 5115 | Aop(OP_CONCAT); |
| 5116 | } |
| 5117 | else { |
| 5118 | PL_bufptr = s; |
| 5119 | return yylex(); |
| 5120 | } |
| 5121 | } |
| 5122 | |
| 5123 | return yylex(); |
| 5124 | case LEX_FORMLINE: |
| 5125 | s = scan_formline(PL_bufptr); |
| 5126 | if (!PL_lex_formbrack) |
| 5127 | { |
| 5128 | formbrack = 1; |
| 5129 | goto rightbracket; |
| 5130 | } |
| 5131 | PL_bufptr = s; |
| 5132 | return yylex(); |
| 5133 | } |
| 5134 | |
| 5135 | s = PL_bufptr; |
| 5136 | PL_oldoldbufptr = PL_oldbufptr; |
| 5137 | PL_oldbufptr = s; |
| 5138 | PL_parser->saw_infix_sigil = 0; |
| 5139 | |
| 5140 | retry: |
| 5141 | #ifdef PERL_MAD |
| 5142 | if (PL_thistoken) { |
| 5143 | sv_free(PL_thistoken); |
| 5144 | PL_thistoken = 0; |
| 5145 | } |
| 5146 | PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */ |
| 5147 | #endif |
| 5148 | switch (*s) { |
| 5149 | default: |
| 5150 | if (UTF ? isIDFIRST_utf8((U8*)s) : isALNUMC(*s)) |
| 5151 | goto keylookup; |
| 5152 | { |
| 5153 | SV *dsv = newSVpvs_flags("", SVs_TEMP); |
| 5154 | const char *c = UTF ? savepv(sv_uni_display(dsv, newSVpvn_flags(s, |
| 5155 | UTF8SKIP(s), |
| 5156 | SVs_TEMP | SVf_UTF8), |
| 5157 | 10, UNI_DISPLAY_ISPRINT)) |
| 5158 | : Perl_form(aTHX_ "\\x%02X", (unsigned char)*s); |
| 5159 | len = UTF ? Perl_utf8_length(aTHX_ (U8 *) PL_linestart, (U8 *) s) : (STRLEN) (s - PL_linestart); |
| 5160 | if (len > UNRECOGNIZED_PRECEDE_COUNT) { |
| 5161 | d = UTF ? (char *) Perl_utf8_hop(aTHX_ (U8 *) s, -UNRECOGNIZED_PRECEDE_COUNT) : s - UNRECOGNIZED_PRECEDE_COUNT; |
| 5162 | } else { |
| 5163 | d = PL_linestart; |
| 5164 | } |
| 5165 | *s = '\0'; |
| 5166 | sv_setpv(dsv, d); |
| 5167 | if (UTF) |
| 5168 | SvUTF8_on(dsv); |
| 5169 | Perl_croak(aTHX_ "Unrecognized character %s; marked by <-- HERE after %"SVf"<-- HERE near column %d", c, SVfARG(dsv), (int) len + 1); |
| 5170 | } |
| 5171 | case 4: |
| 5172 | case 26: |
| 5173 | goto fake_eof; /* emulate EOF on ^D or ^Z */ |
| 5174 | case 0: |
| 5175 | #ifdef PERL_MAD |
| 5176 | if (PL_madskills) |
| 5177 | PL_faketokens = 0; |
| 5178 | #endif |
| 5179 | if (!PL_rsfp && (!PL_parser->filtered || s+1 < PL_bufend)) { |
| 5180 | PL_last_uni = 0; |
| 5181 | PL_last_lop = 0; |
| 5182 | if (PL_lex_brackets && |
| 5183 | PL_lex_brackstack[PL_lex_brackets-1] != XFAKEEOF) { |
| 5184 | yyerror((const char *) |
| 5185 | (PL_lex_formbrack |
| 5186 | ? "Format not terminated" |
| 5187 | : "Missing right curly or square bracket")); |
| 5188 | } |
| 5189 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
| 5190 | "### Tokener got EOF\n"); |
| 5191 | } ); |
| 5192 | TOKEN(0); |
| 5193 | } |
| 5194 | if (s++ < PL_bufend) |
| 5195 | goto retry; /* ignore stray nulls */ |
| 5196 | PL_last_uni = 0; |
| 5197 | PL_last_lop = 0; |
| 5198 | if (!PL_in_eval && !PL_preambled) { |
| 5199 | PL_preambled = TRUE; |
| 5200 | #ifdef PERL_MAD |
| 5201 | if (PL_madskills) |
| 5202 | PL_faketokens = 1; |
| 5203 | #endif |
| 5204 | if (PL_perldb) { |
| 5205 | /* Generate a string of Perl code to load the debugger. |
| 5206 | * If PERL5DB is set, it will return the contents of that, |
| 5207 | * otherwise a compile-time require of perl5db.pl. */ |
| 5208 | |
| 5209 | const char * const pdb = PerlEnv_getenv("PERL5DB"); |
| 5210 | |
| 5211 | if (pdb) { |
| 5212 | sv_setpv(PL_linestr, pdb); |
| 5213 | sv_catpvs(PL_linestr,";"); |
| 5214 | } else { |
| 5215 | SETERRNO(0,SS_NORMAL); |
| 5216 | sv_setpvs(PL_linestr, "BEGIN { require 'perl5db.pl' };"); |
| 5217 | } |
| 5218 | } else |
| 5219 | sv_setpvs(PL_linestr,""); |
| 5220 | if (PL_preambleav) { |
| 5221 | SV **svp = AvARRAY(PL_preambleav); |
| 5222 | SV **const end = svp + AvFILLp(PL_preambleav); |
| 5223 | while(svp <= end) { |
| 5224 | sv_catsv(PL_linestr, *svp); |
| 5225 | ++svp; |
| 5226 | sv_catpvs(PL_linestr, ";"); |
| 5227 | } |
| 5228 | sv_free(MUTABLE_SV(PL_preambleav)); |
| 5229 | PL_preambleav = NULL; |
| 5230 | } |
| 5231 | if (PL_minus_E) |
| 5232 | sv_catpvs(PL_linestr, |
| 5233 | "use feature ':5." STRINGIFY(PERL_VERSION) "';"); |
| 5234 | if (PL_minus_n || PL_minus_p) { |
| 5235 | sv_catpvs(PL_linestr, "LINE: while (<>) {"/*}*/); |
| 5236 | if (PL_minus_l) |
| 5237 | sv_catpvs(PL_linestr,"chomp;"); |
| 5238 | if (PL_minus_a) { |
| 5239 | if (PL_minus_F) { |
| 5240 | if ((*PL_splitstr == '/' || *PL_splitstr == '\'' |
| 5241 | || *PL_splitstr == '"') |
| 5242 | && strchr(PL_splitstr + 1, *PL_splitstr)) |
| 5243 | Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr); |
| 5244 | else { |
| 5245 | /* "q\0${splitstr}\0" is legal perl. Yes, even NUL |
| 5246 | bytes can be used as quoting characters. :-) */ |
| 5247 | const char *splits = PL_splitstr; |
| 5248 | sv_catpvs(PL_linestr, "our @F=split(q\0"); |
| 5249 | do { |
| 5250 | /* Need to \ \s */ |
| 5251 | if (*splits == '\\') |
| 5252 | sv_catpvn(PL_linestr, splits, 1); |
| 5253 | sv_catpvn(PL_linestr, splits, 1); |
| 5254 | } while (*splits++); |
| 5255 | /* This loop will embed the trailing NUL of |
| 5256 | PL_linestr as the last thing it does before |
| 5257 | terminating. */ |
| 5258 | sv_catpvs(PL_linestr, ");"); |
| 5259 | } |
| 5260 | } |
| 5261 | else |
| 5262 | sv_catpvs(PL_linestr,"our @F=split(' ');"); |
| 5263 | } |
| 5264 | } |
| 5265 | sv_catpvs(PL_linestr, "\n"); |
| 5266 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
| 5267 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 5268 | PL_last_lop = PL_last_uni = NULL; |
| 5269 | if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash) |
| 5270 | update_debugger_info(PL_linestr, NULL, 0); |
| 5271 | goto retry; |
| 5272 | } |
| 5273 | do { |
| 5274 | fake_eof = 0; |
| 5275 | bof = PL_rsfp ? TRUE : FALSE; |
| 5276 | if (0) { |
| 5277 | fake_eof: |
| 5278 | fake_eof = LEX_FAKE_EOF; |
| 5279 | } |
| 5280 | PL_bufptr = PL_bufend; |
| 5281 | COPLINE_INC_WITH_HERELINES; |
| 5282 | if (!lex_next_chunk(fake_eof)) { |
| 5283 | CopLINE_dec(PL_curcop); |
| 5284 | s = PL_bufptr; |
| 5285 | TOKEN(';'); /* not infinite loop because rsfp is NULL now */ |
| 5286 | } |
| 5287 | CopLINE_dec(PL_curcop); |
| 5288 | #ifdef PERL_MAD |
| 5289 | if (!PL_rsfp) |
| 5290 | PL_realtokenstart = -1; |
| 5291 | #endif |
| 5292 | s = PL_bufptr; |
| 5293 | /* If it looks like the start of a BOM or raw UTF-16, |
| 5294 | * check if it in fact is. */ |
| 5295 | if (bof && PL_rsfp && |
| 5296 | (*s == 0 || |
| 5297 | *(U8*)s == 0xEF || |
| 5298 | *(U8*)s >= 0xFE || |
| 5299 | s[1] == 0)) { |
| 5300 | Off_t offset = (IV)PerlIO_tell(PL_rsfp); |
| 5301 | bof = (offset == (Off_t)SvCUR(PL_linestr)); |
| 5302 | #if defined(PERLIO_USING_CRLF) && defined(PERL_TEXTMODE_SCRIPTS) |
| 5303 | /* offset may include swallowed CR */ |
| 5304 | if (!bof) |
| 5305 | bof = (offset == (Off_t)SvCUR(PL_linestr)+1); |
| 5306 | #endif |
| 5307 | if (bof) { |
| 5308 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 5309 | s = swallow_bom((U8*)s); |
| 5310 | } |
| 5311 | } |
| 5312 | if (PL_parser->in_pod) { |
| 5313 | /* Incest with pod. */ |
| 5314 | #ifdef PERL_MAD |
| 5315 | if (PL_madskills) |
| 5316 | sv_catsv(PL_thiswhite, PL_linestr); |
| 5317 | #endif |
| 5318 | if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) { |
| 5319 | sv_setpvs(PL_linestr, ""); |
| 5320 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
| 5321 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 5322 | PL_last_lop = PL_last_uni = NULL; |
| 5323 | PL_parser->in_pod = 0; |
| 5324 | } |
| 5325 | } |
| 5326 | if (PL_rsfp || PL_parser->filtered) |
| 5327 | incline(s); |
| 5328 | } while (PL_parser->in_pod); |
| 5329 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s; |
| 5330 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 5331 | PL_last_lop = PL_last_uni = NULL; |
| 5332 | if (CopLINE(PL_curcop) == 1) { |
| 5333 | while (s < PL_bufend && isSPACE(*s)) |
| 5334 | s++; |
| 5335 | if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */ |
| 5336 | s++; |
| 5337 | #ifdef PERL_MAD |
| 5338 | if (PL_madskills) |
| 5339 | PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart); |
| 5340 | #endif |
| 5341 | d = NULL; |
| 5342 | if (!PL_in_eval) { |
| 5343 | if (*s == '#' && *(s+1) == '!') |
| 5344 | d = s + 2; |
| 5345 | #ifdef ALTERNATE_SHEBANG |
| 5346 | else { |
| 5347 | static char const as[] = ALTERNATE_SHEBANG; |
| 5348 | if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1)) |
| 5349 | d = s + (sizeof(as) - 1); |
| 5350 | } |
| 5351 | #endif /* ALTERNATE_SHEBANG */ |
| 5352 | } |
| 5353 | if (d) { |
| 5354 | char *ipath; |
| 5355 | char *ipathend; |
| 5356 | |
| 5357 | while (isSPACE(*d)) |
| 5358 | d++; |
| 5359 | ipath = d; |
| 5360 | while (*d && !isSPACE(*d)) |
| 5361 | d++; |
| 5362 | ipathend = d; |
| 5363 | |
| 5364 | #ifdef ARG_ZERO_IS_SCRIPT |
| 5365 | if (ipathend > ipath) { |
| 5366 | /* |
| 5367 | * HP-UX (at least) sets argv[0] to the script name, |
| 5368 | * which makes $^X incorrect. And Digital UNIX and Linux, |
| 5369 | * at least, set argv[0] to the basename of the Perl |
| 5370 | * interpreter. So, having found "#!", we'll set it right. |
| 5371 | */ |
| 5372 | SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL, |
| 5373 | SVt_PV)); /* $^X */ |
| 5374 | assert(SvPOK(x) || SvGMAGICAL(x)); |
| 5375 | if (sv_eq(x, CopFILESV(PL_curcop))) { |
| 5376 | sv_setpvn(x, ipath, ipathend - ipath); |
| 5377 | SvSETMAGIC(x); |
| 5378 | } |
| 5379 | else { |
| 5380 | STRLEN blen; |
| 5381 | STRLEN llen; |
| 5382 | const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen); |
| 5383 | const char * const lstart = SvPV_const(x,llen); |
| 5384 | if (llen < blen) { |
| 5385 | bstart += blen - llen; |
| 5386 | if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') { |
| 5387 | sv_setpvn(x, ipath, ipathend - ipath); |
| 5388 | SvSETMAGIC(x); |
| 5389 | } |
| 5390 | } |
| 5391 | } |
| 5392 | TAINT_NOT; /* $^X is always tainted, but that's OK */ |
| 5393 | } |
| 5394 | #endif /* ARG_ZERO_IS_SCRIPT */ |
| 5395 | |
| 5396 | /* |
| 5397 | * Look for options. |
| 5398 | */ |
| 5399 | d = instr(s,"perl -"); |
| 5400 | if (!d) { |
| 5401 | d = instr(s,"perl"); |
| 5402 | #if defined(DOSISH) |
| 5403 | /* avoid getting into infinite loops when shebang |
| 5404 | * line contains "Perl" rather than "perl" */ |
| 5405 | if (!d) { |
| 5406 | for (d = ipathend-4; d >= ipath; --d) { |
| 5407 | if ((*d == 'p' || *d == 'P') |
| 5408 | && !ibcmp(d, "perl", 4)) |
| 5409 | { |
| 5410 | break; |
| 5411 | } |
| 5412 | } |
| 5413 | if (d < ipath) |
| 5414 | d = NULL; |
| 5415 | } |
| 5416 | #endif |
| 5417 | } |
| 5418 | #ifdef ALTERNATE_SHEBANG |
| 5419 | /* |
| 5420 | * If the ALTERNATE_SHEBANG on this system starts with a |
| 5421 | * character that can be part of a Perl expression, then if |
| 5422 | * we see it but not "perl", we're probably looking at the |
| 5423 | * start of Perl code, not a request to hand off to some |
| 5424 | * other interpreter. Similarly, if "perl" is there, but |
| 5425 | * not in the first 'word' of the line, we assume the line |
| 5426 | * contains the start of the Perl program. |
| 5427 | */ |
| 5428 | if (d && *s != '#') { |
| 5429 | const char *c = ipath; |
| 5430 | while (*c && !strchr("; \t\r\n\f\v#", *c)) |
| 5431 | c++; |
| 5432 | if (c < d) |
| 5433 | d = NULL; /* "perl" not in first word; ignore */ |
| 5434 | else |
| 5435 | *s = '#'; /* Don't try to parse shebang line */ |
| 5436 | } |
| 5437 | #endif /* ALTERNATE_SHEBANG */ |
| 5438 | if (!d && |
| 5439 | *s == '#' && |
| 5440 | ipathend > ipath && |
| 5441 | !PL_minus_c && |
| 5442 | !instr(s,"indir") && |
| 5443 | instr(PL_origargv[0],"perl")) |
| 5444 | { |
| 5445 | dVAR; |
| 5446 | char **newargv; |
| 5447 | |
| 5448 | *ipathend = '\0'; |
| 5449 | s = ipathend + 1; |
| 5450 | while (s < PL_bufend && isSPACE(*s)) |
| 5451 | s++; |
| 5452 | if (s < PL_bufend) { |
| 5453 | Newx(newargv,PL_origargc+3,char*); |
| 5454 | newargv[1] = s; |
| 5455 | while (s < PL_bufend && !isSPACE(*s)) |
| 5456 | s++; |
| 5457 | *s = '\0'; |
| 5458 | Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*); |
| 5459 | } |
| 5460 | else |
| 5461 | newargv = PL_origargv; |
| 5462 | newargv[0] = ipath; |
| 5463 | PERL_FPU_PRE_EXEC |
| 5464 | PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv)); |
| 5465 | PERL_FPU_POST_EXEC |
| 5466 | Perl_croak(aTHX_ "Can't exec %s", ipath); |
| 5467 | } |
| 5468 | if (d) { |
| 5469 | while (*d && !isSPACE(*d)) |
| 5470 | d++; |
| 5471 | while (SPACE_OR_TAB(*d)) |
| 5472 | d++; |
| 5473 | |
| 5474 | if (*d++ == '-') { |
| 5475 | const bool switches_done = PL_doswitches; |
| 5476 | const U32 oldpdb = PL_perldb; |
| 5477 | const bool oldn = PL_minus_n; |
| 5478 | const bool oldp = PL_minus_p; |
| 5479 | const char *d1 = d; |
| 5480 | |
| 5481 | do { |
| 5482 | bool baduni = FALSE; |
| 5483 | if (*d1 == 'C') { |
| 5484 | const char *d2 = d1 + 1; |
| 5485 | if (parse_unicode_opts((const char **)&d2) |
| 5486 | != PL_unicode) |
| 5487 | baduni = TRUE; |
| 5488 | } |
| 5489 | if (baduni || *d1 == 'M' || *d1 == 'm') { |
| 5490 | const char * const m = d1; |
| 5491 | while (*d1 && !isSPACE(*d1)) |
| 5492 | d1++; |
| 5493 | Perl_croak(aTHX_ "Too late for \"-%.*s\" option", |
| 5494 | (int)(d1 - m), m); |
| 5495 | } |
| 5496 | d1 = moreswitches(d1); |
| 5497 | } while (d1); |
| 5498 | if (PL_doswitches && !switches_done) { |
| 5499 | int argc = PL_origargc; |
| 5500 | char **argv = PL_origargv; |
| 5501 | do { |
| 5502 | argc--,argv++; |
| 5503 | } while (argc && argv[0][0] == '-' && argv[0][1]); |
| 5504 | init_argv_symbols(argc,argv); |
| 5505 | } |
| 5506 | if (((PERLDB_LINE || PERLDB_SAVESRC) && !oldpdb) || |
| 5507 | ((PL_minus_n || PL_minus_p) && !(oldn || oldp))) |
| 5508 | /* if we have already added "LINE: while (<>) {", |
| 5509 | we must not do it again */ |
| 5510 | { |
| 5511 | sv_setpvs(PL_linestr, ""); |
| 5512 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
| 5513 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 5514 | PL_last_lop = PL_last_uni = NULL; |
| 5515 | PL_preambled = FALSE; |
| 5516 | if (PERLDB_LINE || PERLDB_SAVESRC) |
| 5517 | (void)gv_fetchfile(PL_origfilename); |
| 5518 | goto retry; |
| 5519 | } |
| 5520 | } |
| 5521 | } |
| 5522 | } |
| 5523 | } |
| 5524 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
| 5525 | PL_lex_state = LEX_FORMLINE; |
| 5526 | start_force(PL_curforce); |
| 5527 | NEXTVAL_NEXTTOKE.ival = 0; |
| 5528 | force_next(FORMRBRACK); |
| 5529 | TOKEN(';'); |
| 5530 | } |
| 5531 | goto retry; |
| 5532 | case '\r': |
| 5533 | #ifdef PERL_STRICT_CR |
| 5534 | Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r'); |
| 5535 | Perl_croak(aTHX_ |
| 5536 | "\t(Maybe you didn't strip carriage returns after a network transfer?)\n"); |
| 5537 | #endif |
| 5538 | case ' ': case '\t': case '\f': case 013: |
| 5539 | #ifdef PERL_MAD |
| 5540 | PL_realtokenstart = -1; |
| 5541 | if (PL_madskills) { |
| 5542 | if (!PL_thiswhite) |
| 5543 | PL_thiswhite = newSVpvs(""); |
| 5544 | sv_catpvn(PL_thiswhite, s, 1); |
| 5545 | } |
| 5546 | #endif |
| 5547 | s++; |
| 5548 | goto retry; |
| 5549 | case '#': |
| 5550 | case '\n': |
| 5551 | #ifdef PERL_MAD |
| 5552 | PL_realtokenstart = -1; |
| 5553 | if (PL_madskills) |
| 5554 | PL_faketokens = 0; |
| 5555 | #endif |
| 5556 | if (PL_lex_state != LEX_NORMAL || |
| 5557 | (PL_in_eval && !PL_rsfp && !PL_parser->filtered)) { |
| 5558 | if (*s == '#' && s == PL_linestart && PL_in_eval |
| 5559 | && !PL_rsfp && !PL_parser->filtered) { |
| 5560 | /* handle eval qq[#line 1 "foo"\n ...] */ |
| 5561 | CopLINE_dec(PL_curcop); |
| 5562 | incline(s); |
| 5563 | } |
| 5564 | if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) { |
| 5565 | s = SKIPSPACE0(s); |
| 5566 | if (!PL_in_eval || PL_rsfp || PL_parser->filtered) |
| 5567 | incline(s); |
| 5568 | } |
| 5569 | else { |
| 5570 | const bool in_comment = *s == '#'; |
| 5571 | d = s; |
| 5572 | while (d < PL_bufend && *d != '\n') |
| 5573 | d++; |
| 5574 | if (d < PL_bufend) |
| 5575 | d++; |
| 5576 | else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */ |
| 5577 | Perl_croak(aTHX_ "panic: input overflow, %p > %p", |
| 5578 | d, PL_bufend); |
| 5579 | #ifdef PERL_MAD |
| 5580 | if (PL_madskills) |
| 5581 | PL_thiswhite = newSVpvn(s, d - s); |
| 5582 | #endif |
| 5583 | s = d; |
| 5584 | if (in_comment && d == PL_bufend |
| 5585 | && PL_lex_state == LEX_INTERPNORMAL |
| 5586 | && PL_lex_inwhat == OP_SUBST && PL_lex_repl == PL_linestr |
| 5587 | && SvEVALED(PL_lex_repl) && d[-1] == '}') s--; |
| 5588 | else incline(s); |
| 5589 | } |
| 5590 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
| 5591 | PL_lex_state = LEX_FORMLINE; |
| 5592 | start_force(PL_curforce); |
| 5593 | NEXTVAL_NEXTTOKE.ival = 0; |
| 5594 | force_next(FORMRBRACK); |
| 5595 | TOKEN(';'); |
| 5596 | } |
| 5597 | } |
| 5598 | else { |
| 5599 | #ifdef PERL_MAD |
| 5600 | if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) { |
| 5601 | if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') { |
| 5602 | PL_faketokens = 0; |
| 5603 | s = SKIPSPACE0(s); |
| 5604 | TOKEN(PEG); /* make sure any #! line is accessible */ |
| 5605 | } |
| 5606 | s = SKIPSPACE0(s); |
| 5607 | } |
| 5608 | else { |
| 5609 | /* if (PL_madskills && PL_lex_formbrack) { */ |
| 5610 | d = s; |
| 5611 | while (d < PL_bufend && *d != '\n') |
| 5612 | d++; |
| 5613 | if (d < PL_bufend) |
| 5614 | d++; |
| 5615 | else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */ |
| 5616 | Perl_croak(aTHX_ "panic: input overflow"); |
| 5617 | if (PL_madskills && CopLINE(PL_curcop) >= 1) { |
| 5618 | if (!PL_thiswhite) |
| 5619 | PL_thiswhite = newSVpvs(""); |
| 5620 | if (CopLINE(PL_curcop) == 1) { |
| 5621 | sv_setpvs(PL_thiswhite, ""); |
| 5622 | PL_faketokens = 0; |
| 5623 | } |
| 5624 | sv_catpvn(PL_thiswhite, s, d - s); |
| 5625 | } |
| 5626 | s = d; |
| 5627 | /* } |
| 5628 | *s = '\0'; |
| 5629 | PL_bufend = s; */ |
| 5630 | } |
| 5631 | #else |
| 5632 | *s = '\0'; |
| 5633 | PL_bufend = s; |
| 5634 | #endif |
| 5635 | } |
| 5636 | goto retry; |
| 5637 | case '-': |
| 5638 | if (s[1] && isALPHA(s[1]) && !isWORDCHAR(s[2])) { |
| 5639 | I32 ftst = 0; |
| 5640 | char tmp; |
| 5641 | |
| 5642 | s++; |
| 5643 | PL_bufptr = s; |
| 5644 | tmp = *s++; |
| 5645 | |
| 5646 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
| 5647 | s++; |
| 5648 | |
| 5649 | if (strnEQ(s,"=>",2)) { |
| 5650 | s = force_word(PL_bufptr,WORD,FALSE,FALSE); |
| 5651 | DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } ); |
| 5652 | OPERATOR('-'); /* unary minus */ |
| 5653 | } |
| 5654 | PL_last_uni = PL_oldbufptr; |
| 5655 | switch (tmp) { |
| 5656 | case 'r': ftst = OP_FTEREAD; break; |
| 5657 | case 'w': ftst = OP_FTEWRITE; break; |
| 5658 | case 'x': ftst = OP_FTEEXEC; break; |
| 5659 | case 'o': ftst = OP_FTEOWNED; break; |
| 5660 | case 'R': ftst = OP_FTRREAD; break; |
| 5661 | case 'W': ftst = OP_FTRWRITE; break; |
| 5662 | case 'X': ftst = OP_FTREXEC; break; |
| 5663 | case 'O': ftst = OP_FTROWNED; break; |
| 5664 | case 'e': ftst = OP_FTIS; break; |
| 5665 | case 'z': ftst = OP_FTZERO; break; |
| 5666 | case 's': ftst = OP_FTSIZE; break; |
| 5667 | case 'f': ftst = OP_FTFILE; break; |
| 5668 | case 'd': ftst = OP_FTDIR; break; |
| 5669 | case 'l': ftst = OP_FTLINK; break; |
| 5670 | case 'p': ftst = OP_FTPIPE; break; |
| 5671 | case 'S': ftst = OP_FTSOCK; break; |
| 5672 | case 'u': ftst = OP_FTSUID; break; |
| 5673 | case 'g': ftst = OP_FTSGID; break; |
| 5674 | case 'k': ftst = OP_FTSVTX; break; |
| 5675 | case 'b': ftst = OP_FTBLK; break; |
| 5676 | case 'c': ftst = OP_FTCHR; break; |
| 5677 | case 't': ftst = OP_FTTTY; break; |
| 5678 | case 'T': ftst = OP_FTTEXT; break; |
| 5679 | case 'B': ftst = OP_FTBINARY; break; |
| 5680 | case 'M': case 'A': case 'C': |
| 5681 | gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV); |
| 5682 | switch (tmp) { |
| 5683 | case 'M': ftst = OP_FTMTIME; break; |
| 5684 | case 'A': ftst = OP_FTATIME; break; |
| 5685 | case 'C': ftst = OP_FTCTIME; break; |
| 5686 | default: break; |
| 5687 | } |
| 5688 | break; |
| 5689 | default: |
| 5690 | break; |
| 5691 | } |
| 5692 | if (ftst) { |
| 5693 | PL_last_lop_op = (OPCODE)ftst; |
| 5694 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
| 5695 | "### Saw file test %c\n", (int)tmp); |
| 5696 | } ); |
| 5697 | FTST(ftst); |
| 5698 | } |
| 5699 | else { |
| 5700 | /* Assume it was a minus followed by a one-letter named |
| 5701 | * subroutine call (or a -bareword), then. */ |
| 5702 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
| 5703 | "### '-%c' looked like a file test but was not\n", |
| 5704 | (int) tmp); |
| 5705 | } ); |
| 5706 | s = --PL_bufptr; |
| 5707 | } |
| 5708 | } |
| 5709 | { |
| 5710 | const char tmp = *s++; |
| 5711 | if (*s == tmp) { |
| 5712 | s++; |
| 5713 | if (PL_expect == XOPERATOR) |
| 5714 | TERM(POSTDEC); |
| 5715 | else |
| 5716 | OPERATOR(PREDEC); |
| 5717 | } |
| 5718 | else if (*s == '>') { |
| 5719 | s++; |
| 5720 | s = SKIPSPACE1(s); |
| 5721 | if (isIDFIRST_lazy_if(s,UTF)) { |
| 5722 | s = force_word(s,METHOD,FALSE,TRUE); |
| 5723 | TOKEN(ARROW); |
| 5724 | } |
| 5725 | else if (*s == '$') |
| 5726 | OPERATOR(ARROW); |
| 5727 | else |
| 5728 | TERM(ARROW); |
| 5729 | } |
| 5730 | if (PL_expect == XOPERATOR) { |
| 5731 | if (*s == '=' && !PL_lex_allbrackets && |
| 5732 | PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) { |
| 5733 | s--; |
| 5734 | TOKEN(0); |
| 5735 | } |
| 5736 | Aop(OP_SUBTRACT); |
| 5737 | } |
| 5738 | else { |
| 5739 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) |
| 5740 | check_uni(); |
| 5741 | OPERATOR('-'); /* unary minus */ |
| 5742 | } |
| 5743 | } |
| 5744 | |
| 5745 | case '+': |
| 5746 | { |
| 5747 | const char tmp = *s++; |
| 5748 | if (*s == tmp) { |
| 5749 | s++; |
| 5750 | if (PL_expect == XOPERATOR) |
| 5751 | TERM(POSTINC); |
| 5752 | else |
| 5753 | OPERATOR(PREINC); |
| 5754 | } |
| 5755 | if (PL_expect == XOPERATOR) { |
| 5756 | if (*s == '=' && !PL_lex_allbrackets && |
| 5757 | PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) { |
| 5758 | s--; |
| 5759 | TOKEN(0); |
| 5760 | } |
| 5761 | Aop(OP_ADD); |
| 5762 | } |
| 5763 | else { |
| 5764 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) |
| 5765 | check_uni(); |
| 5766 | OPERATOR('+'); |
| 5767 | } |
| 5768 | } |
| 5769 | |
| 5770 | case '*': |
| 5771 | if (PL_expect != XOPERATOR) { |
| 5772 | s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); |
| 5773 | PL_expect = XOPERATOR; |
| 5774 | force_ident(PL_tokenbuf, '*'); |
| 5775 | if (!*PL_tokenbuf) |
| 5776 | PREREF('*'); |
| 5777 | TERM('*'); |
| 5778 | } |
| 5779 | s++; |
| 5780 | if (*s == '*') { |
| 5781 | s++; |
| 5782 | if (*s == '=' && !PL_lex_allbrackets && |
| 5783 | PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) { |
| 5784 | s -= 2; |
| 5785 | TOKEN(0); |
| 5786 | } |
| 5787 | PWop(OP_POW); |
| 5788 | } |
| 5789 | if (*s == '=' && !PL_lex_allbrackets && |
| 5790 | PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) { |
| 5791 | s--; |
| 5792 | TOKEN(0); |
| 5793 | } |
| 5794 | PL_parser->saw_infix_sigil = 1; |
| 5795 | Mop(OP_MULTIPLY); |
| 5796 | |
| 5797 | case '%': |
| 5798 | if (PL_expect == XOPERATOR) { |
| 5799 | if (s[1] == '=' && !PL_lex_allbrackets && |
| 5800 | PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) |
| 5801 | TOKEN(0); |
| 5802 | ++s; |
| 5803 | PL_parser->saw_infix_sigil = 1; |
| 5804 | Mop(OP_MODULO); |
| 5805 | } |
| 5806 | PL_tokenbuf[0] = '%'; |
| 5807 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, |
| 5808 | sizeof PL_tokenbuf - 1, FALSE); |
| 5809 | if (!PL_tokenbuf[1]) { |
| 5810 | PREREF('%'); |
| 5811 | } |
| 5812 | PL_expect = XOPERATOR; |
| 5813 | force_ident_maybe_lex('%'); |
| 5814 | TERM('%'); |
| 5815 | |
| 5816 | case '^': |
| 5817 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= |
| 5818 | (s[1] == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_BITWISE)) |
| 5819 | TOKEN(0); |
| 5820 | s++; |
| 5821 | BOop(OP_BIT_XOR); |
| 5822 | case '[': |
| 5823 | if (PL_lex_brackets > 100) |
| 5824 | Renew(PL_lex_brackstack, PL_lex_brackets + 10, char); |
| 5825 | PL_lex_brackstack[PL_lex_brackets++] = 0; |
| 5826 | PL_lex_allbrackets++; |
| 5827 | { |
| 5828 | const char tmp = *s++; |
| 5829 | OPERATOR(tmp); |
| 5830 | } |
| 5831 | case '~': |
| 5832 | if (s[1] == '~' |
| 5833 | && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)) |
| 5834 | { |
| 5835 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) |
| 5836 | TOKEN(0); |
| 5837 | s += 2; |
| 5838 | Perl_ck_warner_d(aTHX_ |
| 5839 | packWARN(WARN_EXPERIMENTAL__SMARTMATCH), |
| 5840 | "Smartmatch is experimental"); |
| 5841 | Eop(OP_SMARTMATCH); |
| 5842 | } |
| 5843 | s++; |
| 5844 | OPERATOR('~'); |
| 5845 | case ',': |
| 5846 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMMA) |
| 5847 | TOKEN(0); |
| 5848 | s++; |
| 5849 | OPERATOR(','); |
| 5850 | case ':': |
| 5851 | if (s[1] == ':') { |
| 5852 | len = 0; |
| 5853 | goto just_a_word_zero_gv; |
| 5854 | } |
| 5855 | s++; |
| 5856 | switch (PL_expect) { |
| 5857 | OP *attrs; |
| 5858 | #ifdef PERL_MAD |
| 5859 | I32 stuffstart; |
| 5860 | #endif |
| 5861 | case XOPERATOR: |
| 5862 | if (!PL_in_my || PL_lex_state != LEX_NORMAL) |
| 5863 | break; |
| 5864 | PL_bufptr = s; /* update in case we back off */ |
| 5865 | if (*s == '=') { |
| 5866 | Perl_croak(aTHX_ |
| 5867 | "Use of := for an empty attribute list is not allowed"); |
| 5868 | } |
| 5869 | goto grabattrs; |
| 5870 | case XATTRBLOCK: |
| 5871 | PL_expect = XBLOCK; |
| 5872 | goto grabattrs; |
| 5873 | case XATTRTERM: |
| 5874 | PL_expect = XTERMBLOCK; |
| 5875 | grabattrs: |
| 5876 | #ifdef PERL_MAD |
| 5877 | stuffstart = s - SvPVX(PL_linestr) - 1; |
| 5878 | #endif |
| 5879 | s = PEEKSPACE(s); |
| 5880 | attrs = NULL; |
| 5881 | while (isIDFIRST_lazy_if(s,UTF)) { |
| 5882 | I32 tmp; |
| 5883 | SV *sv; |
| 5884 | d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
| 5885 | if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) { |
| 5886 | if (tmp < 0) tmp = -tmp; |
| 5887 | switch (tmp) { |
| 5888 | case KEY_or: |
| 5889 | case KEY_and: |
| 5890 | case KEY_for: |
| 5891 | case KEY_foreach: |
| 5892 | case KEY_unless: |
| 5893 | case KEY_if: |
| 5894 | case KEY_while: |
| 5895 | case KEY_until: |
| 5896 | goto got_attrs; |
| 5897 | default: |
| 5898 | break; |
| 5899 | } |
| 5900 | } |
| 5901 | sv = newSVpvn_flags(s, len, UTF ? SVf_UTF8 : 0); |
| 5902 | if (*d == '(') { |
| 5903 | d = scan_str(d,TRUE,TRUE,FALSE, FALSE); |
| 5904 | if (!d) { |
| 5905 | /* MUST advance bufptr here to avoid bogus |
| 5906 | "at end of line" context messages from yyerror(). |
| 5907 | */ |
| 5908 | PL_bufptr = s + len; |
| 5909 | yyerror("Unterminated attribute parameter in attribute list"); |
| 5910 | if (attrs) |
| 5911 | op_free(attrs); |
| 5912 | sv_free(sv); |
| 5913 | return REPORT(0); /* EOF indicator */ |
| 5914 | } |
| 5915 | } |
| 5916 | if (PL_lex_stuff) { |
| 5917 | sv_catsv(sv, PL_lex_stuff); |
| 5918 | attrs = op_append_elem(OP_LIST, attrs, |
| 5919 | newSVOP(OP_CONST, 0, sv)); |
| 5920 | SvREFCNT_dec(PL_lex_stuff); |
| 5921 | PL_lex_stuff = NULL; |
| 5922 | } |
| 5923 | else { |
| 5924 | if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) { |
| 5925 | sv_free(sv); |
| 5926 | if (PL_in_my == KEY_our) { |
| 5927 | deprecate(":unique"); |
| 5928 | } |
| 5929 | else |
| 5930 | Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables"); |
| 5931 | } |
| 5932 | |
| 5933 | /* NOTE: any CV attrs applied here need to be part of |
| 5934 | the CVf_BUILTIN_ATTRS define in cv.h! */ |
| 5935 | else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) { |
| 5936 | sv_free(sv); |
| 5937 | CvLVALUE_on(PL_compcv); |
| 5938 | } |
| 5939 | else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) { |
| 5940 | sv_free(sv); |
| 5941 | deprecate(":locked"); |
| 5942 | } |
| 5943 | else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) { |
| 5944 | sv_free(sv); |
| 5945 | CvMETHOD_on(PL_compcv); |
| 5946 | } |
| 5947 | /* After we've set the flags, it could be argued that |
| 5948 | we don't need to do the attributes.pm-based setting |
| 5949 | process, and shouldn't bother appending recognized |
| 5950 | flags. To experiment with that, uncomment the |
| 5951 | following "else". (Note that's already been |
| 5952 | uncommented. That keeps the above-applied built-in |
| 5953 | attributes from being intercepted (and possibly |
| 5954 | rejected) by a package's attribute routines, but is |
| 5955 | justified by the performance win for the common case |
| 5956 | of applying only built-in attributes.) */ |
| 5957 | else |
| 5958 | attrs = op_append_elem(OP_LIST, attrs, |
| 5959 | newSVOP(OP_CONST, 0, |
| 5960 | sv)); |
| 5961 | } |
| 5962 | s = PEEKSPACE(d); |
| 5963 | if (*s == ':' && s[1] != ':') |
| 5964 | s = PEEKSPACE(s+1); |
| 5965 | else if (s == d) |
| 5966 | break; /* require real whitespace or :'s */ |
| 5967 | /* XXX losing whitespace on sequential attributes here */ |
| 5968 | } |
| 5969 | { |
| 5970 | const char tmp |
| 5971 | = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */ |
| 5972 | if (*s != ';' && *s != '}' && *s != tmp |
| 5973 | && (tmp != '=' || *s != ')')) { |
| 5974 | const char q = ((*s == '\'') ? '"' : '\''); |
| 5975 | /* If here for an expression, and parsed no attrs, back |
| 5976 | off. */ |
| 5977 | if (tmp == '=' && !attrs) { |
| 5978 | s = PL_bufptr; |
| 5979 | break; |
| 5980 | } |
| 5981 | /* MUST advance bufptr here to avoid bogus "at end of line" |
| 5982 | context messages from yyerror(). |
| 5983 | */ |
| 5984 | PL_bufptr = s; |
| 5985 | yyerror( (const char *) |
| 5986 | (*s |
| 5987 | ? Perl_form(aTHX_ "Invalid separator character " |
| 5988 | "%c%c%c in attribute list", q, *s, q) |
| 5989 | : "Unterminated attribute list" ) ); |
| 5990 | if (attrs) |
| 5991 | op_free(attrs); |
| 5992 | OPERATOR(':'); |
| 5993 | } |
| 5994 | } |
| 5995 | got_attrs: |
| 5996 | if (attrs) { |
| 5997 | start_force(PL_curforce); |
| 5998 | NEXTVAL_NEXTTOKE.opval = attrs; |
| 5999 | CURMAD('_', PL_nextwhite); |
| 6000 | force_next(THING); |
| 6001 | } |
| 6002 | #ifdef PERL_MAD |
| 6003 | if (PL_madskills) { |
| 6004 | PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart, |
| 6005 | (s - SvPVX(PL_linestr)) - stuffstart); |
| 6006 | } |
| 6007 | #endif |
| 6008 | TOKEN(COLONATTR); |
| 6009 | } |
| 6010 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_CLOSING) { |
| 6011 | s--; |
| 6012 | TOKEN(0); |
| 6013 | } |
| 6014 | PL_lex_allbrackets--; |
| 6015 | OPERATOR(':'); |
| 6016 | case '(': |
| 6017 | s++; |
| 6018 | if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr) |
| 6019 | PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */ |
| 6020 | else |
| 6021 | PL_expect = XTERM; |
| 6022 | s = SKIPSPACE1(s); |
| 6023 | PL_lex_allbrackets++; |
| 6024 | TOKEN('('); |
| 6025 | case ';': |
| 6026 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR) |
| 6027 | TOKEN(0); |
| 6028 | CLINE; |
| 6029 | s++; |
| 6030 | OPERATOR(';'); |
| 6031 | case ')': |
| 6032 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_CLOSING) |
| 6033 | TOKEN(0); |
| 6034 | s++; |
| 6035 | PL_lex_allbrackets--; |
| 6036 | s = SKIPSPACE1(s); |
| 6037 | if (*s == '{') |
| 6038 | PREBLOCK(')'); |
| 6039 | TERM(')'); |
| 6040 | case ']': |
| 6041 | if (PL_lex_brackets && PL_lex_brackstack[PL_lex_brackets-1] == XFAKEEOF) |
| 6042 | TOKEN(0); |
| 6043 | s++; |
| 6044 | if (PL_lex_brackets <= 0) |
| 6045 | yyerror("Unmatched right square bracket"); |
| 6046 | else |
| 6047 | --PL_lex_brackets; |
| 6048 | PL_lex_allbrackets--; |
| 6049 | if (PL_lex_state == LEX_INTERPNORMAL) { |
| 6050 | if (PL_lex_brackets == 0) { |
| 6051 | if (*s == '-' && s[1] == '>') |
| 6052 | PL_lex_state = LEX_INTERPENDMAYBE; |
| 6053 | else if (*s != '[' && *s != '{') |
| 6054 | PL_lex_state = LEX_INTERPEND; |
| 6055 | } |
| 6056 | } |
| 6057 | TERM(']'); |
| 6058 | case '{': |
| 6059 | s++; |
| 6060 | leftbracket: |
| 6061 | if (PL_lex_brackets > 100) { |
| 6062 | Renew(PL_lex_brackstack, PL_lex_brackets + 10, char); |
| 6063 | } |
| 6064 | switch (PL_expect) { |
| 6065 | case XTERM: |
| 6066 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
| 6067 | PL_lex_allbrackets++; |
| 6068 | OPERATOR(HASHBRACK); |
| 6069 | case XOPERATOR: |
| 6070 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
| 6071 | s++; |
| 6072 | d = s; |
| 6073 | PL_tokenbuf[0] = '\0'; |
| 6074 | if (d < PL_bufend && *d == '-') { |
| 6075 | PL_tokenbuf[0] = '-'; |
| 6076 | d++; |
| 6077 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
| 6078 | d++; |
| 6079 | } |
| 6080 | if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) { |
| 6081 | d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, |
| 6082 | FALSE, &len); |
| 6083 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
| 6084 | d++; |
| 6085 | if (*d == '}') { |
| 6086 | const char minus = (PL_tokenbuf[0] == '-'); |
| 6087 | s = force_word(s + minus, WORD, FALSE, TRUE); |
| 6088 | if (minus) |
| 6089 | force_next('-'); |
| 6090 | } |
| 6091 | } |
| 6092 | /* FALL THROUGH */ |
| 6093 | case XATTRBLOCK: |
| 6094 | case XBLOCK: |
| 6095 | PL_lex_brackstack[PL_lex_brackets++] = XSTATE; |
| 6096 | PL_lex_allbrackets++; |
| 6097 | PL_expect = XSTATE; |
| 6098 | break; |
| 6099 | case XATTRTERM: |
| 6100 | case XTERMBLOCK: |
| 6101 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
| 6102 | PL_lex_allbrackets++; |
| 6103 | PL_expect = XSTATE; |
| 6104 | break; |
| 6105 | default: { |
| 6106 | const char *t; |
| 6107 | if (PL_oldoldbufptr == PL_last_lop) |
| 6108 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; |
| 6109 | else |
| 6110 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
| 6111 | PL_lex_allbrackets++; |
| 6112 | s = SKIPSPACE1(s); |
| 6113 | if (*s == '}') { |
| 6114 | if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) { |
| 6115 | PL_expect = XTERM; |
| 6116 | /* This hack is to get the ${} in the message. */ |
| 6117 | PL_bufptr = s+1; |
| 6118 | yyerror("syntax error"); |
| 6119 | break; |
| 6120 | } |
| 6121 | OPERATOR(HASHBRACK); |
| 6122 | } |
| 6123 | /* This hack serves to disambiguate a pair of curlies |
| 6124 | * as being a block or an anon hash. Normally, expectation |
| 6125 | * determines that, but in cases where we're not in a |
| 6126 | * position to expect anything in particular (like inside |
| 6127 | * eval"") we have to resolve the ambiguity. This code |
| 6128 | * covers the case where the first term in the curlies is a |
| 6129 | * quoted string. Most other cases need to be explicitly |
| 6130 | * disambiguated by prepending a "+" before the opening |
| 6131 | * curly in order to force resolution as an anon hash. |
| 6132 | * |
| 6133 | * XXX should probably propagate the outer expectation |
| 6134 | * into eval"" to rely less on this hack, but that could |
| 6135 | * potentially break current behavior of eval"". |
| 6136 | * GSAR 97-07-21 |
| 6137 | */ |
| 6138 | t = s; |
| 6139 | if (*s == '\'' || *s == '"' || *s == '`') { |
| 6140 | /* common case: get past first string, handling escapes */ |
| 6141 | for (t++; t < PL_bufend && *t != *s;) |
| 6142 | if (*t++ == '\\' && (*t == '\\' || *t == *s)) |
| 6143 | t++; |
| 6144 | t++; |
| 6145 | } |
| 6146 | else if (*s == 'q') { |
| 6147 | if (++t < PL_bufend |
| 6148 | && (!isWORDCHAR(*t) |
| 6149 | || ((*t == 'q' || *t == 'x') && ++t < PL_bufend |
| 6150 | && !isWORDCHAR(*t)))) |
| 6151 | { |
| 6152 | /* skip q//-like construct */ |
| 6153 | const char *tmps; |
| 6154 | char open, close, term; |
| 6155 | I32 brackets = 1; |
| 6156 | |
| 6157 | while (t < PL_bufend && isSPACE(*t)) |
| 6158 | t++; |
| 6159 | /* check for q => */ |
| 6160 | if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') { |
| 6161 | OPERATOR(HASHBRACK); |
| 6162 | } |
| 6163 | term = *t; |
| 6164 | open = term; |
| 6165 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) |
| 6166 | term = tmps[5]; |
| 6167 | close = term; |
| 6168 | if (open == close) |
| 6169 | for (t++; t < PL_bufend; t++) { |
| 6170 | if (*t == '\\' && t+1 < PL_bufend && open != '\\') |
| 6171 | t++; |
| 6172 | else if (*t == open) |
| 6173 | break; |
| 6174 | } |
| 6175 | else { |
| 6176 | for (t++; t < PL_bufend; t++) { |
| 6177 | if (*t == '\\' && t+1 < PL_bufend) |
| 6178 | t++; |
| 6179 | else if (*t == close && --brackets <= 0) |
| 6180 | break; |
| 6181 | else if (*t == open) |
| 6182 | brackets++; |
| 6183 | } |
| 6184 | } |
| 6185 | t++; |
| 6186 | } |
| 6187 | else |
| 6188 | /* skip plain q word */ |
| 6189 | while (t < PL_bufend && isWORDCHAR_lazy_if(t,UTF)) |
| 6190 | t += UTF8SKIP(t); |
| 6191 | } |
| 6192 | else if (isWORDCHAR_lazy_if(t,UTF)) { |
| 6193 | t += UTF8SKIP(t); |
| 6194 | while (t < PL_bufend && isWORDCHAR_lazy_if(t,UTF)) |
| 6195 | t += UTF8SKIP(t); |
| 6196 | } |
| 6197 | while (t < PL_bufend && isSPACE(*t)) |
| 6198 | t++; |
| 6199 | /* if comma follows first term, call it an anon hash */ |
| 6200 | /* XXX it could be a comma expression with loop modifiers */ |
| 6201 | if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s))) |
| 6202 | || (*t == '=' && t[1] == '>'))) |
| 6203 | OPERATOR(HASHBRACK); |
| 6204 | if (PL_expect == XREF) |
| 6205 | PL_expect = XTERM; |
| 6206 | else { |
| 6207 | PL_lex_brackstack[PL_lex_brackets-1] = XSTATE; |
| 6208 | PL_expect = XSTATE; |
| 6209 | } |
| 6210 | } |
| 6211 | break; |
| 6212 | } |
| 6213 | pl_yylval.ival = CopLINE(PL_curcop); |
| 6214 | if (isSPACE(*s) || *s == '#') |
| 6215 | PL_copline = NOLINE; /* invalidate current command line number */ |
| 6216 | TOKEN(formbrack ? '=' : '{'); |
| 6217 | case '}': |
| 6218 | if (PL_lex_brackets && PL_lex_brackstack[PL_lex_brackets-1] == XFAKEEOF) |
| 6219 | TOKEN(0); |
| 6220 | rightbracket: |
| 6221 | s++; |
| 6222 | if (PL_lex_brackets <= 0) |
| 6223 | yyerror("Unmatched right curly bracket"); |
| 6224 | else |
| 6225 | PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets]; |
| 6226 | PL_lex_allbrackets--; |
| 6227 | if (PL_lex_state == LEX_INTERPNORMAL) { |
| 6228 | if (PL_lex_brackets == 0) { |
| 6229 | if (PL_expect & XFAKEBRACK) { |
| 6230 | PL_expect &= XENUMMASK; |
| 6231 | PL_lex_state = LEX_INTERPEND; |
| 6232 | PL_bufptr = s; |
| 6233 | #if 0 |
| 6234 | if (PL_madskills) { |
| 6235 | if (!PL_thiswhite) |
| 6236 | PL_thiswhite = newSVpvs(""); |
| 6237 | sv_catpvs(PL_thiswhite,"}"); |
| 6238 | } |
| 6239 | #endif |
| 6240 | return yylex(); /* ignore fake brackets */ |
| 6241 | } |
| 6242 | if (PL_lex_inwhat == OP_SUBST && PL_lex_repl == PL_linestr |
| 6243 | && SvEVALED(PL_lex_repl)) |
| 6244 | PL_lex_state = LEX_INTERPEND; |
| 6245 | else if (*s == '-' && s[1] == '>') |
| 6246 | PL_lex_state = LEX_INTERPENDMAYBE; |
| 6247 | else if (*s != '[' && *s != '{') |
| 6248 | PL_lex_state = LEX_INTERPEND; |
| 6249 | } |
| 6250 | } |
| 6251 | if (PL_expect & XFAKEBRACK) { |
| 6252 | PL_expect &= XENUMMASK; |
| 6253 | PL_bufptr = s; |
| 6254 | return yylex(); /* ignore fake brackets */ |
| 6255 | } |
| 6256 | start_force(PL_curforce); |
| 6257 | if (PL_madskills) { |
| 6258 | curmad('X', newSVpvn(s-1,1)); |
| 6259 | CURMAD('_', PL_thiswhite); |
| 6260 | } |
| 6261 | force_next(formbrack ? '.' : '}'); |
| 6262 | if (formbrack) LEAVE; |
| 6263 | #ifdef PERL_MAD |
| 6264 | if (PL_madskills && !PL_thistoken) |
| 6265 | PL_thistoken = newSVpvs(""); |
| 6266 | #endif |
| 6267 | if (formbrack == 2) { /* means . where arguments were expected */ |
| 6268 | start_force(PL_curforce); |
| 6269 | force_next(';'); |
| 6270 | TOKEN(FORMRBRACK); |
| 6271 | } |
| 6272 | TOKEN(';'); |
| 6273 | case '&': |
| 6274 | s++; |
| 6275 | if (*s++ == '&') { |
| 6276 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= |
| 6277 | (*s == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_LOGIC)) { |
| 6278 | s -= 2; |
| 6279 | TOKEN(0); |
| 6280 | } |
| 6281 | AOPERATOR(ANDAND); |
| 6282 | } |
| 6283 | s--; |
| 6284 | if (PL_expect == XOPERATOR) { |
| 6285 | if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON) |
| 6286 | && isIDFIRST_lazy_if(s,UTF)) |
| 6287 | { |
| 6288 | CopLINE_dec(PL_curcop); |
| 6289 | Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi); |
| 6290 | CopLINE_inc(PL_curcop); |
| 6291 | } |
| 6292 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= |
| 6293 | (*s == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_BITWISE)) { |
| 6294 | s--; |
| 6295 | TOKEN(0); |
| 6296 | } |
| 6297 | PL_parser->saw_infix_sigil = 1; |
| 6298 | BAop(OP_BIT_AND); |
| 6299 | } |
| 6300 | |
| 6301 | PL_tokenbuf[0] = '&'; |
| 6302 | s = scan_ident(s - 1, PL_bufend, PL_tokenbuf + 1, |
| 6303 | sizeof PL_tokenbuf - 1, TRUE); |
| 6304 | if (PL_tokenbuf[1]) { |
| 6305 | PL_expect = XOPERATOR; |
| 6306 | force_ident_maybe_lex('&'); |
| 6307 | } |
| 6308 | else |
| 6309 | PREREF('&'); |
| 6310 | pl_yylval.ival = (OPpENTERSUB_AMPER<<8); |
| 6311 | TERM('&'); |
| 6312 | |
| 6313 | case '|': |
| 6314 | s++; |
| 6315 | if (*s++ == '|') { |
| 6316 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= |
| 6317 | (*s == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_LOGIC)) { |
| 6318 | s -= 2; |
| 6319 | TOKEN(0); |
| 6320 | } |
| 6321 | AOPERATOR(OROR); |
| 6322 | } |
| 6323 | s--; |
| 6324 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= |
| 6325 | (*s == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_BITWISE)) { |
| 6326 | s--; |
| 6327 | TOKEN(0); |
| 6328 | } |
| 6329 | BOop(OP_BIT_OR); |
| 6330 | case '=': |
| 6331 | s++; |
| 6332 | { |
| 6333 | const char tmp = *s++; |
| 6334 | if (tmp == '=') { |
| 6335 | if (!PL_lex_allbrackets && |
| 6336 | PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) { |
| 6337 | s -= 2; |
| 6338 | TOKEN(0); |
| 6339 | } |
| 6340 | Eop(OP_EQ); |
| 6341 | } |
| 6342 | if (tmp == '>') { |
| 6343 | if (!PL_lex_allbrackets && |
| 6344 | PL_lex_fakeeof >= LEX_FAKEEOF_COMMA) { |
| 6345 | s -= 2; |
| 6346 | TOKEN(0); |
| 6347 | } |
| 6348 | OPERATOR(','); |
| 6349 | } |
| 6350 | if (tmp == '~') |
| 6351 | PMop(OP_MATCH); |
| 6352 | if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX) |
| 6353 | && strchr("+-*/%.^&|<",tmp)) |
| 6354 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 6355 | "Reversed %c= operator",(int)tmp); |
| 6356 | s--; |
| 6357 | if (PL_expect == XSTATE && isALPHA(tmp) && |
| 6358 | (s == PL_linestart+1 || s[-2] == '\n') ) |
| 6359 | { |
| 6360 | if ((PL_in_eval && !PL_rsfp && !PL_parser->filtered) |
| 6361 | || PL_lex_state != LEX_NORMAL) { |
| 6362 | d = PL_bufend; |
| 6363 | while (s < d) { |
| 6364 | if (*s++ == '\n') { |
| 6365 | incline(s); |
| 6366 | if (strnEQ(s,"=cut",4)) { |
| 6367 | s = strchr(s,'\n'); |
| 6368 | if (s) |
| 6369 | s++; |
| 6370 | else |
| 6371 | s = d; |
| 6372 | incline(s); |
| 6373 | goto retry; |
| 6374 | } |
| 6375 | } |
| 6376 | } |
| 6377 | goto retry; |
| 6378 | } |
| 6379 | #ifdef PERL_MAD |
| 6380 | if (PL_madskills) { |
| 6381 | if (!PL_thiswhite) |
| 6382 | PL_thiswhite = newSVpvs(""); |
| 6383 | sv_catpvn(PL_thiswhite, PL_linestart, |
| 6384 | PL_bufend - PL_linestart); |
| 6385 | } |
| 6386 | #endif |
| 6387 | s = PL_bufend; |
| 6388 | PL_parser->in_pod = 1; |
| 6389 | goto retry; |
| 6390 | } |
| 6391 | } |
| 6392 | if (PL_expect == XBLOCK) { |
| 6393 | const char *t = s; |
| 6394 | #ifdef PERL_STRICT_CR |
| 6395 | while (SPACE_OR_TAB(*t)) |
| 6396 | #else |
| 6397 | while (SPACE_OR_TAB(*t) || *t == '\r') |
| 6398 | #endif |
| 6399 | t++; |
| 6400 | if (*t == '\n' || *t == '#') { |
| 6401 | formbrack = 1; |
| 6402 | ENTER; |
| 6403 | SAVEI8(PL_parser->form_lex_state); |
| 6404 | SAVEI32(PL_lex_formbrack); |
| 6405 | PL_parser->form_lex_state = PL_lex_state; |
| 6406 | PL_lex_formbrack = PL_lex_brackets + 1; |
| 6407 | goto leftbracket; |
| 6408 | } |
| 6409 | } |
| 6410 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) { |
| 6411 | s--; |
| 6412 | TOKEN(0); |
| 6413 | } |
| 6414 | pl_yylval.ival = 0; |
| 6415 | OPERATOR(ASSIGNOP); |
| 6416 | case '!': |
| 6417 | s++; |
| 6418 | { |
| 6419 | const char tmp = *s++; |
| 6420 | if (tmp == '=') { |
| 6421 | /* was this !=~ where !~ was meant? |
| 6422 | * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */ |
| 6423 | |
| 6424 | if (*s == '~' && ckWARN(WARN_SYNTAX)) { |
| 6425 | const char *t = s+1; |
| 6426 | |
| 6427 | while (t < PL_bufend && isSPACE(*t)) |
| 6428 | ++t; |
| 6429 | |
| 6430 | if (*t == '/' || *t == '?' || |
| 6431 | ((*t == 'm' || *t == 's' || *t == 'y') |
| 6432 | && !isWORDCHAR(t[1])) || |
| 6433 | (*t == 't' && t[1] == 'r' && !isWORDCHAR(t[2]))) |
| 6434 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 6435 | "!=~ should be !~"); |
| 6436 | } |
| 6437 | if (!PL_lex_allbrackets && |
| 6438 | PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) { |
| 6439 | s -= 2; |
| 6440 | TOKEN(0); |
| 6441 | } |
| 6442 | Eop(OP_NE); |
| 6443 | } |
| 6444 | if (tmp == '~') |
| 6445 | PMop(OP_NOT); |
| 6446 | } |
| 6447 | s--; |
| 6448 | OPERATOR('!'); |
| 6449 | case '<': |
| 6450 | if (PL_expect != XOPERATOR) { |
| 6451 | if (s[1] != '<' && !strchr(s,'>')) |
| 6452 | check_uni(); |
| 6453 | if (s[1] == '<') |
| 6454 | s = scan_heredoc(s); |
| 6455 | else |
| 6456 | s = scan_inputsymbol(s); |
| 6457 | PL_expect = XOPERATOR; |
| 6458 | TOKEN(sublex_start()); |
| 6459 | } |
| 6460 | s++; |
| 6461 | { |
| 6462 | char tmp = *s++; |
| 6463 | if (tmp == '<') { |
| 6464 | if (*s == '=' && !PL_lex_allbrackets && |
| 6465 | PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) { |
| 6466 | s -= 2; |
| 6467 | TOKEN(0); |
| 6468 | } |
| 6469 | SHop(OP_LEFT_SHIFT); |
| 6470 | } |
| 6471 | if (tmp == '=') { |
| 6472 | tmp = *s++; |
| 6473 | if (tmp == '>') { |
| 6474 | if (!PL_lex_allbrackets && |
| 6475 | PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) { |
| 6476 | s -= 3; |
| 6477 | TOKEN(0); |
| 6478 | } |
| 6479 | Eop(OP_NCMP); |
| 6480 | } |
| 6481 | s--; |
| 6482 | if (!PL_lex_allbrackets && |
| 6483 | PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) { |
| 6484 | s -= 2; |
| 6485 | TOKEN(0); |
| 6486 | } |
| 6487 | Rop(OP_LE); |
| 6488 | } |
| 6489 | } |
| 6490 | s--; |
| 6491 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) { |
| 6492 | s--; |
| 6493 | TOKEN(0); |
| 6494 | } |
| 6495 | Rop(OP_LT); |
| 6496 | case '>': |
| 6497 | s++; |
| 6498 | { |
| 6499 | const char tmp = *s++; |
| 6500 | if (tmp == '>') { |
| 6501 | if (*s == '=' && !PL_lex_allbrackets && |
| 6502 | PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) { |
| 6503 | s -= 2; |
| 6504 | TOKEN(0); |
| 6505 | } |
| 6506 | SHop(OP_RIGHT_SHIFT); |
| 6507 | } |
| 6508 | else if (tmp == '=') { |
| 6509 | if (!PL_lex_allbrackets && |
| 6510 | PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) { |
| 6511 | s -= 2; |
| 6512 | TOKEN(0); |
| 6513 | } |
| 6514 | Rop(OP_GE); |
| 6515 | } |
| 6516 | } |
| 6517 | s--; |
| 6518 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) { |
| 6519 | s--; |
| 6520 | TOKEN(0); |
| 6521 | } |
| 6522 | Rop(OP_GT); |
| 6523 | |
| 6524 | case '$': |
| 6525 | CLINE; |
| 6526 | |
| 6527 | if (PL_expect == XOPERATOR) { |
| 6528 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { |
| 6529 | return deprecate_commaless_var_list(); |
| 6530 | } |
| 6531 | } |
| 6532 | |
| 6533 | if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-@", s[2]))) { |
| 6534 | PL_tokenbuf[0] = '@'; |
| 6535 | s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1, |
| 6536 | sizeof PL_tokenbuf - 1, FALSE); |
| 6537 | if (PL_expect == XOPERATOR) |
| 6538 | no_op("Array length", s); |
| 6539 | if (!PL_tokenbuf[1]) |
| 6540 | PREREF(DOLSHARP); |
| 6541 | PL_expect = XOPERATOR; |
| 6542 | force_ident_maybe_lex('#'); |
| 6543 | TOKEN(DOLSHARP); |
| 6544 | } |
| 6545 | |
| 6546 | PL_tokenbuf[0] = '$'; |
| 6547 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, |
| 6548 | sizeof PL_tokenbuf - 1, FALSE); |
| 6549 | if (PL_expect == XOPERATOR) |
| 6550 | no_op("Scalar", s); |
| 6551 | if (!PL_tokenbuf[1]) { |
| 6552 | if (s == PL_bufend) |
| 6553 | yyerror("Final $ should be \\$ or $name"); |
| 6554 | PREREF('$'); |
| 6555 | } |
| 6556 | |
| 6557 | d = s; |
| 6558 | { |
| 6559 | const char tmp = *s; |
| 6560 | if (PL_lex_state == LEX_NORMAL || PL_lex_brackets) |
| 6561 | s = SKIPSPACE1(s); |
| 6562 | |
| 6563 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) |
| 6564 | && intuit_more(s)) { |
| 6565 | if (*s == '[') { |
| 6566 | PL_tokenbuf[0] = '@'; |
| 6567 | if (ckWARN(WARN_SYNTAX)) { |
| 6568 | char *t = s+1; |
| 6569 | |
| 6570 | while (isSPACE(*t) || isWORDCHAR_lazy_if(t,UTF) || *t == '$') |
| 6571 | t++; |
| 6572 | if (*t++ == ',') { |
| 6573 | PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */ |
| 6574 | while (t < PL_bufend && *t != ']') |
| 6575 | t++; |
| 6576 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 6577 | "Multidimensional syntax %.*s not supported", |
| 6578 | (int)((t - PL_bufptr) + 1), PL_bufptr); |
| 6579 | } |
| 6580 | } |
| 6581 | } |
| 6582 | else if (*s == '{') { |
| 6583 | char *t; |
| 6584 | PL_tokenbuf[0] = '%'; |
| 6585 | if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX) |
| 6586 | && (t = strchr(s, '}')) && (t = strchr(t, '='))) |
| 6587 | { |
| 6588 | char tmpbuf[sizeof PL_tokenbuf]; |
| 6589 | do { |
| 6590 | t++; |
| 6591 | } while (isSPACE(*t)); |
| 6592 | if (isIDFIRST_lazy_if(t,UTF)) { |
| 6593 | STRLEN len; |
| 6594 | t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, |
| 6595 | &len); |
| 6596 | while (isSPACE(*t)) |
| 6597 | t++; |
| 6598 | if (*t == ';' |
| 6599 | && get_cvn_flags(tmpbuf, len, UTF ? SVf_UTF8 : 0)) |
| 6600 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 6601 | "You need to quote \"%"UTF8f"\"", |
| 6602 | UTF8fARG(UTF, len, tmpbuf)); |
| 6603 | } |
| 6604 | } |
| 6605 | } |
| 6606 | } |
| 6607 | |
| 6608 | PL_expect = XOPERATOR; |
| 6609 | if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) { |
| 6610 | const bool islop = (PL_last_lop == PL_oldoldbufptr); |
| 6611 | if (!islop || PL_last_lop_op == OP_GREPSTART) |
| 6612 | PL_expect = XOPERATOR; |
| 6613 | else if (strchr("$@\"'`q", *s)) |
| 6614 | PL_expect = XTERM; /* e.g. print $fh "foo" */ |
| 6615 | else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF)) |
| 6616 | PL_expect = XTERM; /* e.g. print $fh &sub */ |
| 6617 | else if (isIDFIRST_lazy_if(s,UTF)) { |
| 6618 | char tmpbuf[sizeof PL_tokenbuf]; |
| 6619 | int t2; |
| 6620 | scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
| 6621 | if ((t2 = keyword(tmpbuf, len, 0))) { |
| 6622 | /* binary operators exclude handle interpretations */ |
| 6623 | switch (t2) { |
| 6624 | case -KEY_x: |
| 6625 | case -KEY_eq: |
| 6626 | case -KEY_ne: |
| 6627 | case -KEY_gt: |
| 6628 | case -KEY_lt: |
| 6629 | case -KEY_ge: |
| 6630 | case -KEY_le: |
| 6631 | case -KEY_cmp: |
| 6632 | break; |
| 6633 | default: |
| 6634 | PL_expect = XTERM; /* e.g. print $fh length() */ |
| 6635 | break; |
| 6636 | } |
| 6637 | } |
| 6638 | else { |
| 6639 | PL_expect = XTERM; /* e.g. print $fh subr() */ |
| 6640 | } |
| 6641 | } |
| 6642 | else if (isDIGIT(*s)) |
| 6643 | PL_expect = XTERM; /* e.g. print $fh 3 */ |
| 6644 | else if (*s == '.' && isDIGIT(s[1])) |
| 6645 | PL_expect = XTERM; /* e.g. print $fh .3 */ |
| 6646 | else if ((*s == '?' || *s == '-' || *s == '+') |
| 6647 | && !isSPACE(s[1]) && s[1] != '=') |
| 6648 | PL_expect = XTERM; /* e.g. print $fh -1 */ |
| 6649 | else if (*s == '/' && !isSPACE(s[1]) && s[1] != '=' |
| 6650 | && s[1] != '/') |
| 6651 | PL_expect = XTERM; /* e.g. print $fh /.../ |
| 6652 | XXX except DORDOR operator |
| 6653 | */ |
| 6654 | else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) |
| 6655 | && s[2] != '=') |
| 6656 | PL_expect = XTERM; /* print $fh <<"EOF" */ |
| 6657 | } |
| 6658 | } |
| 6659 | force_ident_maybe_lex('$'); |
| 6660 | TOKEN('$'); |
| 6661 | |
| 6662 | case '@': |
| 6663 | if (PL_expect == XOPERATOR) |
| 6664 | no_op("Array", s); |
| 6665 | PL_tokenbuf[0] = '@'; |
| 6666 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE); |
| 6667 | if (!PL_tokenbuf[1]) { |
| 6668 | PREREF('@'); |
| 6669 | } |
| 6670 | if (PL_lex_state == LEX_NORMAL) |
| 6671 | s = SKIPSPACE1(s); |
| 6672 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) { |
| 6673 | if (*s == '{') |
| 6674 | PL_tokenbuf[0] = '%'; |
| 6675 | |
| 6676 | /* Warn about @ where they meant $. */ |
| 6677 | if (*s == '[' || *s == '{') { |
| 6678 | if (ckWARN(WARN_SYNTAX)) { |
| 6679 | const char *t = s + 1; |
| 6680 | while (*t && (isWORDCHAR_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t))) |
| 6681 | t += UTF ? UTF8SKIP(t) : 1; |
| 6682 | if (*t == '}' || *t == ']') { |
| 6683 | t++; |
| 6684 | PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */ |
| 6685 | /* diag_listed_as: Scalar value @%s[%s] better written as $%s[%s] */ |
| 6686 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 6687 | "Scalar value %"UTF8f" better written as $%"UTF8f, |
| 6688 | UTF8fARG(UTF, t-PL_bufptr, PL_bufptr), |
| 6689 | UTF8fARG(UTF, t-PL_bufptr-1, PL_bufptr+1)); |
| 6690 | } |
| 6691 | } |
| 6692 | } |
| 6693 | } |
| 6694 | PL_expect = XOPERATOR; |
| 6695 | force_ident_maybe_lex('@'); |
| 6696 | TERM('@'); |
| 6697 | |
| 6698 | case '/': /* may be division, defined-or, or pattern */ |
| 6699 | if (PL_expect == XTERMORDORDOR && s[1] == '/') { |
| 6700 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= |
| 6701 | (s[2] == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_LOGIC)) |
| 6702 | TOKEN(0); |
| 6703 | s += 2; |
| 6704 | AOPERATOR(DORDOR); |
| 6705 | } |
| 6706 | case '?': /* may either be conditional or pattern */ |
| 6707 | if (PL_expect == XOPERATOR) { |
| 6708 | char tmp = *s++; |
| 6709 | if(tmp == '?') { |
| 6710 | if (!PL_lex_allbrackets && |
| 6711 | PL_lex_fakeeof >= LEX_FAKEEOF_IFELSE) { |
| 6712 | s--; |
| 6713 | TOKEN(0); |
| 6714 | } |
| 6715 | PL_lex_allbrackets++; |
| 6716 | OPERATOR('?'); |
| 6717 | } |
| 6718 | else { |
| 6719 | tmp = *s++; |
| 6720 | if(tmp == '/') { |
| 6721 | /* A // operator. */ |
| 6722 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= |
| 6723 | (*s == '=' ? LEX_FAKEEOF_ASSIGN : |
| 6724 | LEX_FAKEEOF_LOGIC)) { |
| 6725 | s -= 2; |
| 6726 | TOKEN(0); |
| 6727 | } |
| 6728 | AOPERATOR(DORDOR); |
| 6729 | } |
| 6730 | else { |
| 6731 | s--; |
| 6732 | if (*s == '=' && !PL_lex_allbrackets && |
| 6733 | PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) { |
| 6734 | s--; |
| 6735 | TOKEN(0); |
| 6736 | } |
| 6737 | Mop(OP_DIVIDE); |
| 6738 | } |
| 6739 | } |
| 6740 | } |
| 6741 | else { |
| 6742 | /* Disable warning on "study /blah/" */ |
| 6743 | if (PL_oldoldbufptr == PL_last_uni |
| 6744 | && (*PL_last_uni != 's' || s - PL_last_uni < 5 |
| 6745 | || memNE(PL_last_uni, "study", 5) |
| 6746 | || isWORDCHAR_lazy_if(PL_last_uni+5,UTF) |
| 6747 | )) |
| 6748 | check_uni(); |
| 6749 | if (*s == '?') |
| 6750 | deprecate("?PATTERN? without explicit operator"); |
| 6751 | s = scan_pat(s,OP_MATCH); |
| 6752 | TERM(sublex_start()); |
| 6753 | } |
| 6754 | |
| 6755 | case '.': |
| 6756 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack |
| 6757 | #ifdef PERL_STRICT_CR |
| 6758 | && s[1] == '\n' |
| 6759 | #else |
| 6760 | && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n')) |
| 6761 | #endif |
| 6762 | && (s == PL_linestart || s[-1] == '\n') ) |
| 6763 | { |
| 6764 | PL_expect = XSTATE; |
| 6765 | formbrack = 2; /* dot seen where arguments expected */ |
| 6766 | goto rightbracket; |
| 6767 | } |
| 6768 | if (PL_expect == XSTATE && s[1] == '.' && s[2] == '.') { |
| 6769 | s += 3; |
| 6770 | OPERATOR(YADAYADA); |
| 6771 | } |
| 6772 | if (PL_expect == XOPERATOR || !isDIGIT(s[1])) { |
| 6773 | char tmp = *s++; |
| 6774 | if (*s == tmp) { |
| 6775 | if (!PL_lex_allbrackets && |
| 6776 | PL_lex_fakeeof >= LEX_FAKEEOF_RANGE) { |
| 6777 | s--; |
| 6778 | TOKEN(0); |
| 6779 | } |
| 6780 | s++; |
| 6781 | if (*s == tmp) { |
| 6782 | s++; |
| 6783 | pl_yylval.ival = OPf_SPECIAL; |
| 6784 | } |
| 6785 | else |
| 6786 | pl_yylval.ival = 0; |
| 6787 | OPERATOR(DOTDOT); |
| 6788 | } |
| 6789 | if (*s == '=' && !PL_lex_allbrackets && |
| 6790 | PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) { |
| 6791 | s--; |
| 6792 | TOKEN(0); |
| 6793 | } |
| 6794 | Aop(OP_CONCAT); |
| 6795 | } |
| 6796 | /* FALL THROUGH */ |
| 6797 | case '0': case '1': case '2': case '3': case '4': |
| 6798 | case '5': case '6': case '7': case '8': case '9': |
| 6799 | s = scan_num(s, &pl_yylval); |
| 6800 | DEBUG_T( { printbuf("### Saw number in %s\n", s); } ); |
| 6801 | if (PL_expect == XOPERATOR) |
| 6802 | no_op("Number",s); |
| 6803 | TERM(THING); |
| 6804 | |
| 6805 | case '\'': |
| 6806 | s = scan_str(s,!!PL_madskills,FALSE,FALSE, FALSE); |
| 6807 | DEBUG_T( { printbuf("### Saw string before %s\n", s); } ); |
| 6808 | if (PL_expect == XOPERATOR) { |
| 6809 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { |
| 6810 | return deprecate_commaless_var_list(); |
| 6811 | } |
| 6812 | else |
| 6813 | no_op("String",s); |
| 6814 | } |
| 6815 | if (!s) |
| 6816 | missingterm(NULL); |
| 6817 | pl_yylval.ival = OP_CONST; |
| 6818 | TERM(sublex_start()); |
| 6819 | |
| 6820 | case '"': |
| 6821 | s = scan_str(s,!!PL_madskills,FALSE,FALSE, FALSE); |
| 6822 | DEBUG_T( { printbuf("### Saw string before %s\n", s); } ); |
| 6823 | if (PL_expect == XOPERATOR) { |
| 6824 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { |
| 6825 | return deprecate_commaless_var_list(); |
| 6826 | } |
| 6827 | else |
| 6828 | no_op("String",s); |
| 6829 | } |
| 6830 | if (!s) |
| 6831 | missingterm(NULL); |
| 6832 | pl_yylval.ival = OP_CONST; |
| 6833 | /* FIXME. I think that this can be const if char *d is replaced by |
| 6834 | more localised variables. */ |
| 6835 | for (d = SvPV(PL_lex_stuff, len); len; len--, d++) { |
| 6836 | if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) { |
| 6837 | pl_yylval.ival = OP_STRINGIFY; |
| 6838 | break; |
| 6839 | } |
| 6840 | } |
| 6841 | TERM(sublex_start()); |
| 6842 | |
| 6843 | case '`': |
| 6844 | s = scan_str(s,!!PL_madskills,FALSE,FALSE, FALSE); |
| 6845 | DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } ); |
| 6846 | if (PL_expect == XOPERATOR) |
| 6847 | no_op("Backticks",s); |
| 6848 | if (!s) |
| 6849 | missingterm(NULL); |
| 6850 | readpipe_override(); |
| 6851 | TERM(sublex_start()); |
| 6852 | |
| 6853 | case '\\': |
| 6854 | s++; |
| 6855 | if (PL_lex_inwhat && isDIGIT(*s)) |
| 6856 | Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression", |
| 6857 | *s, *s); |
| 6858 | if (PL_expect == XOPERATOR) |
| 6859 | no_op("Backslash",s); |
| 6860 | OPERATOR(REFGEN); |
| 6861 | |
| 6862 | case 'v': |
| 6863 | if (isDIGIT(s[1]) && PL_expect != XOPERATOR) { |
| 6864 | char *start = s + 2; |
| 6865 | while (isDIGIT(*start) || *start == '_') |
| 6866 | start++; |
| 6867 | if (*start == '.' && isDIGIT(start[1])) { |
| 6868 | s = scan_num(s, &pl_yylval); |
| 6869 | TERM(THING); |
| 6870 | } |
| 6871 | else if ((*start == ':' && start[1] == ':') |
| 6872 | || (PL_expect == XSTATE && *start == ':')) |
| 6873 | goto keylookup; |
| 6874 | else if (PL_expect == XSTATE) { |
| 6875 | d = start; |
| 6876 | while (d < PL_bufend && isSPACE(*d)) d++; |
| 6877 | if (*d == ':') goto keylookup; |
| 6878 | } |
| 6879 | /* avoid v123abc() or $h{v1}, allow C<print v10;> */ |
| 6880 | if (!isALPHA(*start) && (PL_expect == XTERM |
| 6881 | || PL_expect == XREF || PL_expect == XSTATE |
| 6882 | || PL_expect == XTERMORDORDOR)) { |
| 6883 | GV *const gv = gv_fetchpvn_flags(s, start - s, |
| 6884 | UTF ? SVf_UTF8 : 0, SVt_PVCV); |
| 6885 | if (!gv) { |
| 6886 | s = scan_num(s, &pl_yylval); |
| 6887 | TERM(THING); |
| 6888 | } |
| 6889 | } |
| 6890 | } |
| 6891 | goto keylookup; |
| 6892 | case 'x': |
| 6893 | if (isDIGIT(s[1]) && PL_expect == XOPERATOR) { |
| 6894 | s++; |
| 6895 | Mop(OP_REPEAT); |
| 6896 | } |
| 6897 | goto keylookup; |
| 6898 | |
| 6899 | case '_': |
| 6900 | case 'a': case 'A': |
| 6901 | case 'b': case 'B': |
| 6902 | case 'c': case 'C': |
| 6903 | case 'd': case 'D': |
| 6904 | case 'e': case 'E': |
| 6905 | case 'f': case 'F': |
| 6906 | case 'g': case 'G': |
| 6907 | case 'h': case 'H': |
| 6908 | case 'i': case 'I': |
| 6909 | case 'j': case 'J': |
| 6910 | case 'k': case 'K': |
| 6911 | case 'l': case 'L': |
| 6912 | case 'm': case 'M': |
| 6913 | case 'n': case 'N': |
| 6914 | case 'o': case 'O': |
| 6915 | case 'p': case 'P': |
| 6916 | case 'q': case 'Q': |
| 6917 | case 'r': case 'R': |
| 6918 | case 's': case 'S': |
| 6919 | case 't': case 'T': |
| 6920 | case 'u': case 'U': |
| 6921 | case 'V': |
| 6922 | case 'w': case 'W': |
| 6923 | case 'X': |
| 6924 | case 'y': case 'Y': |
| 6925 | case 'z': case 'Z': |
| 6926 | |
| 6927 | keylookup: { |
| 6928 | bool anydelim; |
| 6929 | bool lex; |
| 6930 | I32 tmp; |
| 6931 | SV *sv; |
| 6932 | CV *cv; |
| 6933 | PADOFFSET off; |
| 6934 | OP *rv2cv_op; |
| 6935 | |
| 6936 | lex = FALSE; |
| 6937 | orig_keyword = 0; |
| 6938 | off = 0; |
| 6939 | sv = NULL; |
| 6940 | cv = NULL; |
| 6941 | gv = NULL; |
| 6942 | gvp = NULL; |
| 6943 | rv2cv_op = NULL; |
| 6944 | |
| 6945 | PL_bufptr = s; |
| 6946 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
| 6947 | |
| 6948 | /* Some keywords can be followed by any delimiter, including ':' */ |
| 6949 | anydelim = word_takes_any_delimeter(PL_tokenbuf, len); |
| 6950 | |
| 6951 | /* x::* is just a word, unless x is "CORE" */ |
| 6952 | if (!anydelim && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE")) |
| 6953 | goto just_a_word; |
| 6954 | |
| 6955 | d = s; |
| 6956 | while (d < PL_bufend && isSPACE(*d)) |
| 6957 | d++; /* no comments skipped here, or s### is misparsed */ |
| 6958 | |
| 6959 | /* Is this a word before a => operator? */ |
| 6960 | if (*d == '=' && d[1] == '>') { |
| 6961 | CLINE; |
| 6962 | pl_yylval.opval |
| 6963 | = (OP*)newSVOP(OP_CONST, 0, |
| 6964 | S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len)); |
| 6965 | pl_yylval.opval->op_private = OPpCONST_BARE; |
| 6966 | TERM(WORD); |
| 6967 | } |
| 6968 | |
| 6969 | /* Check for plugged-in keyword */ |
| 6970 | { |
| 6971 | OP *o; |
| 6972 | int result; |
| 6973 | char *saved_bufptr = PL_bufptr; |
| 6974 | PL_bufptr = s; |
| 6975 | result = PL_keyword_plugin(aTHX_ PL_tokenbuf, len, &o); |
| 6976 | s = PL_bufptr; |
| 6977 | if (result == KEYWORD_PLUGIN_DECLINE) { |
| 6978 | /* not a plugged-in keyword */ |
| 6979 | PL_bufptr = saved_bufptr; |
| 6980 | } else if (result == KEYWORD_PLUGIN_STMT) { |
| 6981 | pl_yylval.opval = o; |
| 6982 | CLINE; |
| 6983 | PL_expect = XSTATE; |
| 6984 | return REPORT(PLUGSTMT); |
| 6985 | } else if (result == KEYWORD_PLUGIN_EXPR) { |
| 6986 | pl_yylval.opval = o; |
| 6987 | CLINE; |
| 6988 | PL_expect = XOPERATOR; |
| 6989 | return REPORT(PLUGEXPR); |
| 6990 | } else { |
| 6991 | Perl_croak(aTHX_ "Bad plugin affecting keyword '%s'", |
| 6992 | PL_tokenbuf); |
| 6993 | } |
| 6994 | } |
| 6995 | |
| 6996 | /* Check for built-in keyword */ |
| 6997 | tmp = keyword(PL_tokenbuf, len, 0); |
| 6998 | |
| 6999 | /* Is this a label? */ |
| 7000 | if (!anydelim && PL_expect == XSTATE |
| 7001 | && d < PL_bufend && *d == ':' && *(d + 1) != ':') { |
| 7002 | s = d + 1; |
| 7003 | pl_yylval.pval = savepvn(PL_tokenbuf, len+1); |
| 7004 | pl_yylval.pval[len] = '\0'; |
| 7005 | pl_yylval.pval[len+1] = UTF ? 1 : 0; |
| 7006 | CLINE; |
| 7007 | TOKEN(LABEL); |
| 7008 | } |
| 7009 | |
| 7010 | /* Check for lexical sub */ |
| 7011 | if (PL_expect != XOPERATOR) { |
| 7012 | char tmpbuf[sizeof PL_tokenbuf + 1]; |
| 7013 | *tmpbuf = '&'; |
| 7014 | Copy(PL_tokenbuf, tmpbuf+1, len, char); |
| 7015 | off = pad_findmy_pvn(tmpbuf, len+1, UTF ? SVf_UTF8 : 0); |
| 7016 | if (off != NOT_IN_PAD) { |
| 7017 | assert(off); /* we assume this is boolean-true below */ |
| 7018 | if (PAD_COMPNAME_FLAGS_isOUR(off)) { |
| 7019 | HV * const stash = PAD_COMPNAME_OURSTASH(off); |
| 7020 | HEK * const stashname = HvNAME_HEK(stash); |
| 7021 | sv = newSVhek(stashname); |
| 7022 | sv_catpvs(sv, "::"); |
| 7023 | sv_catpvn_flags(sv, PL_tokenbuf, len, |
| 7024 | (UTF ? SV_CATUTF8 : SV_CATBYTES)); |
| 7025 | gv = gv_fetchsv(sv, GV_NOADD_NOINIT | SvUTF8(sv), |
| 7026 | SVt_PVCV); |
| 7027 | off = 0; |
| 7028 | if (!gv) { |
| 7029 | sv_free(sv); |
| 7030 | sv = NULL; |
| 7031 | goto just_a_word; |
| 7032 | } |
| 7033 | } |
| 7034 | else { |
| 7035 | rv2cv_op = newOP(OP_PADANY, 0); |
| 7036 | rv2cv_op->op_targ = off; |
| 7037 | cv = find_lexical_cv(off); |
| 7038 | } |
| 7039 | lex = TRUE; |
| 7040 | goto just_a_word; |
| 7041 | } |
| 7042 | off = 0; |
| 7043 | } |
| 7044 | |
| 7045 | if (tmp < 0) { /* second-class keyword? */ |
| 7046 | GV *ogv = NULL; /* override (winner) */ |
| 7047 | GV *hgv = NULL; /* hidden (loser) */ |
| 7048 | if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) { |
| 7049 | CV *cv; |
| 7050 | if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, |
| 7051 | UTF ? SVf_UTF8 : 0, SVt_PVCV)) && |
| 7052 | (cv = GvCVu(gv))) |
| 7053 | { |
| 7054 | if (GvIMPORTED_CV(gv)) |
| 7055 | ogv = gv; |
| 7056 | else if (! CvMETHOD(cv)) |
| 7057 | hgv = gv; |
| 7058 | } |
| 7059 | if (!ogv && |
| 7060 | (gvp = (GV**)hv_fetch(PL_globalstash, PL_tokenbuf, |
| 7061 | UTF ? -(I32)len : (I32)len, FALSE)) && |
| 7062 | (gv = *gvp) && isGV_with_GP(gv) && |
| 7063 | GvCVu(gv) && GvIMPORTED_CV(gv)) |
| 7064 | { |
| 7065 | ogv = gv; |
| 7066 | } |
| 7067 | } |
| 7068 | if (ogv) { |
| 7069 | orig_keyword = tmp; |
| 7070 | tmp = 0; /* overridden by import or by GLOBAL */ |
| 7071 | } |
| 7072 | else if (gv && !gvp |
| 7073 | && -tmp==KEY_lock /* XXX generalizable kludge */ |
| 7074 | && GvCVu(gv)) |
| 7075 | { |
| 7076 | tmp = 0; /* any sub overrides "weak" keyword */ |
| 7077 | } |
| 7078 | else { /* no override */ |
| 7079 | tmp = -tmp; |
| 7080 | if (tmp == KEY_dump) { |
| 7081 | Perl_ck_warner(aTHX_ packWARN(WARN_MISC), |
| 7082 | "dump() better written as CORE::dump()"); |
| 7083 | } |
| 7084 | gv = NULL; |
| 7085 | gvp = 0; |
| 7086 | if (hgv && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */ |
| 7087 | Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 7088 | "Ambiguous call resolved as CORE::%s(), " |
| 7089 | "qualify as such or use &", |
| 7090 | GvENAME(hgv)); |
| 7091 | } |
| 7092 | } |
| 7093 | |
| 7094 | reserved_word: |
| 7095 | switch (tmp) { |
| 7096 | |
| 7097 | default: /* not a keyword */ |
| 7098 | /* Trade off - by using this evil construction we can pull the |
| 7099 | variable gv into the block labelled keylookup. If not, then |
| 7100 | we have to give it function scope so that the goto from the |
| 7101 | earlier ':' case doesn't bypass the initialisation. */ |
| 7102 | if (0) { |
| 7103 | just_a_word_zero_gv: |
| 7104 | sv = NULL; |
| 7105 | cv = NULL; |
| 7106 | gv = NULL; |
| 7107 | gvp = NULL; |
| 7108 | rv2cv_op = NULL; |
| 7109 | orig_keyword = 0; |
| 7110 | lex = 0; |
| 7111 | off = 0; |
| 7112 | } |
| 7113 | just_a_word: { |
| 7114 | int pkgname = 0; |
| 7115 | const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]); |
| 7116 | const char penultchar = |
| 7117 | lastchar && PL_bufptr - 2 >= PL_linestart |
| 7118 | ? PL_bufptr[-2] |
| 7119 | : 0; |
| 7120 | #ifdef PERL_MAD |
| 7121 | SV *nextPL_nextwhite = 0; |
| 7122 | #endif |
| 7123 | |
| 7124 | |
| 7125 | /* Get the rest if it looks like a package qualifier */ |
| 7126 | |
| 7127 | if (*s == '\'' || (*s == ':' && s[1] == ':')) { |
| 7128 | STRLEN morelen; |
| 7129 | s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len, |
| 7130 | TRUE, &morelen); |
| 7131 | if (!morelen) |
| 7132 | Perl_croak(aTHX_ "Bad name after %"UTF8f"%s", |
| 7133 | UTF8fARG(UTF, len, PL_tokenbuf), |
| 7134 | *s == '\'' ? "'" : "::"); |
| 7135 | len += morelen; |
| 7136 | pkgname = 1; |
| 7137 | } |
| 7138 | |
| 7139 | if (PL_expect == XOPERATOR) { |
| 7140 | if (PL_bufptr == PL_linestart) { |
| 7141 | CopLINE_dec(PL_curcop); |
| 7142 | Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi); |
| 7143 | CopLINE_inc(PL_curcop); |
| 7144 | } |
| 7145 | else |
| 7146 | no_op("Bareword",s); |
| 7147 | } |
| 7148 | |
| 7149 | /* Look for a subroutine with this name in current package, |
| 7150 | unless this is a lexical sub, or name is "Foo::", |
| 7151 | in which case Foo is a bareword |
| 7152 | (and a package name). */ |
| 7153 | |
| 7154 | if (len > 2 && !PL_madskills && |
| 7155 | PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':') |
| 7156 | { |
| 7157 | if (ckWARN(WARN_BAREWORD) |
| 7158 | && ! gv_fetchpvn_flags(PL_tokenbuf, len, UTF ? SVf_UTF8 : 0, SVt_PVHV)) |
| 7159 | Perl_warner(aTHX_ packWARN(WARN_BAREWORD), |
| 7160 | "Bareword \"%"UTF8f"\" refers to nonexistent package", |
| 7161 | UTF8fARG(UTF, len, PL_tokenbuf)); |
| 7162 | len -= 2; |
| 7163 | PL_tokenbuf[len] = '\0'; |
| 7164 | gv = NULL; |
| 7165 | gvp = 0; |
| 7166 | } |
| 7167 | else { |
| 7168 | if (!lex && !gv) { |
| 7169 | /* Mustn't actually add anything to a symbol table. |
| 7170 | But also don't want to "initialise" any placeholder |
| 7171 | constants that might already be there into full |
| 7172 | blown PVGVs with attached PVCV. */ |
| 7173 | gv = gv_fetchpvn_flags(PL_tokenbuf, len, |
| 7174 | GV_NOADD_NOINIT | ( UTF ? SVf_UTF8 : 0 ), |
| 7175 | SVt_PVCV); |
| 7176 | } |
| 7177 | len = 0; |
| 7178 | } |
| 7179 | |
| 7180 | /* if we saw a global override before, get the right name */ |
| 7181 | |
| 7182 | if (!sv) |
| 7183 | sv = S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, |
| 7184 | len ? len : strlen(PL_tokenbuf)); |
| 7185 | if (gvp) { |
| 7186 | SV * const tmp_sv = sv; |
| 7187 | sv = newSVpvs("CORE::GLOBAL::"); |
| 7188 | sv_catsv(sv, tmp_sv); |
| 7189 | SvREFCNT_dec(tmp_sv); |
| 7190 | } |
| 7191 | |
| 7192 | #ifdef PERL_MAD |
| 7193 | if (PL_madskills && !PL_thistoken) { |
| 7194 | char *start = SvPVX(PL_linestr) + PL_realtokenstart; |
| 7195 | PL_thistoken = newSVpvn(start,s - start); |
| 7196 | PL_realtokenstart = s - SvPVX(PL_linestr); |
| 7197 | } |
| 7198 | #endif |
| 7199 | |
| 7200 | /* Presume this is going to be a bareword of some sort. */ |
| 7201 | CLINE; |
| 7202 | pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
| 7203 | pl_yylval.opval->op_private = OPpCONST_BARE; |
| 7204 | |
| 7205 | /* And if "Foo::", then that's what it certainly is. */ |
| 7206 | if (len) |
| 7207 | goto safe_bareword; |
| 7208 | |
| 7209 | if (!off) |
| 7210 | { |
| 7211 | OP *const_op = newSVOP(OP_CONST, 0, SvREFCNT_inc_NN(sv)); |
| 7212 | const_op->op_private = OPpCONST_BARE; |
| 7213 | rv2cv_op = newCVREF(0, const_op); |
| 7214 | cv = lex ? GvCV(gv) : rv2cv_op_cv(rv2cv_op, 0); |
| 7215 | } |
| 7216 | |
| 7217 | /* See if it's the indirect object for a list operator. */ |
| 7218 | |
| 7219 | if (PL_oldoldbufptr && |
| 7220 | PL_oldoldbufptr < PL_bufptr && |
| 7221 | (PL_oldoldbufptr == PL_last_lop |
| 7222 | || PL_oldoldbufptr == PL_last_uni) && |
| 7223 | /* NO SKIPSPACE BEFORE HERE! */ |
| 7224 | (PL_expect == XREF || |
| 7225 | ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF)) |
| 7226 | { |
| 7227 | bool immediate_paren = *s == '('; |
| 7228 | |
| 7229 | /* (Now we can afford to cross potential line boundary.) */ |
| 7230 | s = SKIPSPACE2(s,nextPL_nextwhite); |
| 7231 | #ifdef PERL_MAD |
| 7232 | PL_nextwhite = nextPL_nextwhite; /* assume no & deception */ |
| 7233 | #endif |
| 7234 | |
| 7235 | /* Two barewords in a row may indicate method call. */ |
| 7236 | |
| 7237 | if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && |
| 7238 | (tmp = intuit_method(s, gv, cv))) { |
| 7239 | op_free(rv2cv_op); |
| 7240 | if (tmp == METHOD && !PL_lex_allbrackets && |
| 7241 | PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC) |
| 7242 | PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC; |
| 7243 | return REPORT(tmp); |
| 7244 | } |
| 7245 | |
| 7246 | /* If not a declared subroutine, it's an indirect object. */ |
| 7247 | /* (But it's an indir obj regardless for sort.) */ |
| 7248 | /* Also, if "_" follows a filetest operator, it's a bareword */ |
| 7249 | |
| 7250 | if ( |
| 7251 | ( !immediate_paren && (PL_last_lop_op == OP_SORT || |
| 7252 | (!cv && |
| 7253 | (PL_last_lop_op != OP_MAPSTART && |
| 7254 | PL_last_lop_op != OP_GREPSTART)))) |
| 7255 | || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0' |
| 7256 | && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP)) |
| 7257 | ) |
| 7258 | { |
| 7259 | PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR; |
| 7260 | goto bareword; |
| 7261 | } |
| 7262 | } |
| 7263 | |
| 7264 | PL_expect = XOPERATOR; |
| 7265 | #ifdef PERL_MAD |
| 7266 | if (isSPACE(*s)) |
| 7267 | s = SKIPSPACE2(s,nextPL_nextwhite); |
| 7268 | PL_nextwhite = nextPL_nextwhite; |
| 7269 | #else |
| 7270 | s = skipspace(s); |
| 7271 | #endif |
| 7272 | |
| 7273 | /* Is this a word before a => operator? */ |
| 7274 | if (*s == '=' && s[1] == '>' && !pkgname) { |
| 7275 | op_free(rv2cv_op); |
| 7276 | CLINE; |
| 7277 | /* This is our own scalar, created a few lines above, |
| 7278 | so this is safe. */ |
| 7279 | SvREADONLY_off(cSVOPx(pl_yylval.opval)->op_sv); |
| 7280 | sv_setpv(((SVOP*)pl_yylval.opval)->op_sv, PL_tokenbuf); |
| 7281 | if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len)) |
| 7282 | SvUTF8_on(((SVOP*)pl_yylval.opval)->op_sv); |
| 7283 | SvREADONLY_on(cSVOPx(pl_yylval.opval)->op_sv); |
| 7284 | TERM(WORD); |
| 7285 | } |
| 7286 | |
| 7287 | /* If followed by a paren, it's certainly a subroutine. */ |
| 7288 | if (*s == '(') { |
| 7289 | CLINE; |
| 7290 | if (cv) { |
| 7291 | d = s + 1; |
| 7292 | while (SPACE_OR_TAB(*d)) |
| 7293 | d++; |
| 7294 | if (*d == ')' && (sv = cv_const_sv(cv))) { |
| 7295 | s = d + 1; |
| 7296 | goto its_constant; |
| 7297 | } |
| 7298 | } |
| 7299 | #ifdef PERL_MAD |
| 7300 | if (PL_madskills) { |
| 7301 | PL_nextwhite = PL_thiswhite; |
| 7302 | PL_thiswhite = 0; |
| 7303 | } |
| 7304 | start_force(PL_curforce); |
| 7305 | #endif |
| 7306 | NEXTVAL_NEXTTOKE.opval = |
| 7307 | off ? rv2cv_op : pl_yylval.opval; |
| 7308 | PL_expect = XOPERATOR; |
| 7309 | #ifdef PERL_MAD |
| 7310 | if (PL_madskills) { |
| 7311 | PL_nextwhite = nextPL_nextwhite; |
| 7312 | curmad('X', PL_thistoken); |
| 7313 | PL_thistoken = newSVpvs(""); |
| 7314 | } |
| 7315 | #endif |
| 7316 | if (off) |
| 7317 | op_free(pl_yylval.opval), force_next(PRIVATEREF); |
| 7318 | else op_free(rv2cv_op), force_next(WORD); |
| 7319 | pl_yylval.ival = 0; |
| 7320 | TOKEN('&'); |
| 7321 | } |
| 7322 | |
| 7323 | /* If followed by var or block, call it a method (unless sub) */ |
| 7324 | |
| 7325 | if ((*s == '$' || *s == '{') && !cv) { |
| 7326 | op_free(rv2cv_op); |
| 7327 | PL_last_lop = PL_oldbufptr; |
| 7328 | PL_last_lop_op = OP_METHOD; |
| 7329 | if (!PL_lex_allbrackets && |
| 7330 | PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC) |
| 7331 | PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC; |
| 7332 | PREBLOCK(METHOD); |
| 7333 | } |
| 7334 | |
| 7335 | /* If followed by a bareword, see if it looks like indir obj. */ |
| 7336 | |
| 7337 | if (!orig_keyword |
| 7338 | && (isIDFIRST_lazy_if(s,UTF) || *s == '$') |
| 7339 | && (tmp = intuit_method(s, gv, cv))) { |
| 7340 | op_free(rv2cv_op); |
| 7341 | if (tmp == METHOD && !PL_lex_allbrackets && |
| 7342 | PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC) |
| 7343 | PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC; |
| 7344 | return REPORT(tmp); |
| 7345 | } |
| 7346 | |
| 7347 | /* Not a method, so call it a subroutine (if defined) */ |
| 7348 | |
| 7349 | if (cv) { |
| 7350 | if (lastchar == '-' && penultchar != '-') { |
| 7351 | const STRLEN l = len ? len : strlen(PL_tokenbuf); |
| 7352 | Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 7353 | "Ambiguous use of -%"UTF8f" resolved as -&%"UTF8f"()", |
| 7354 | UTF8fARG(UTF, l, PL_tokenbuf), |
| 7355 | UTF8fARG(UTF, l, PL_tokenbuf)); |
| 7356 | } |
| 7357 | /* Check for a constant sub */ |
| 7358 | if ((sv = cv_const_sv(cv))) { |
| 7359 | its_constant: |
| 7360 | op_free(rv2cv_op); |
| 7361 | SvREFCNT_dec(((SVOP*)pl_yylval.opval)->op_sv); |
| 7362 | ((SVOP*)pl_yylval.opval)->op_sv = SvREFCNT_inc_simple(sv); |
| 7363 | pl_yylval.opval->op_private = OPpCONST_FOLDED; |
| 7364 | pl_yylval.opval->op_flags |= OPf_SPECIAL; |
| 7365 | TOKEN(WORD); |
| 7366 | } |
| 7367 | |
| 7368 | op_free(pl_yylval.opval); |
| 7369 | pl_yylval.opval = |
| 7370 | off ? (OP *)newCVREF(0, rv2cv_op) : rv2cv_op; |
| 7371 | pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN; |
| 7372 | PL_last_lop = PL_oldbufptr; |
| 7373 | PL_last_lop_op = OP_ENTERSUB; |
| 7374 | /* Is there a prototype? */ |
| 7375 | if ( |
| 7376 | #ifdef PERL_MAD |
| 7377 | cv && |
| 7378 | #endif |
| 7379 | SvPOK(cv)) |
| 7380 | { |
| 7381 | STRLEN protolen = CvPROTOLEN(cv); |
| 7382 | const char *proto = CvPROTO(cv); |
| 7383 | bool optional; |
| 7384 | proto = S_strip_spaces(aTHX_ proto, &protolen); |
| 7385 | if (!protolen) |
| 7386 | TERM(FUNC0SUB); |
| 7387 | if ((optional = *proto == ';')) |
| 7388 | do |
| 7389 | proto++; |
| 7390 | while (*proto == ';'); |
| 7391 | if ( |
| 7392 | ( |
| 7393 | ( |
| 7394 | *proto == '$' || *proto == '_' |
| 7395 | || *proto == '*' || *proto == '+' |
| 7396 | ) |
| 7397 | && proto[1] == '\0' |
| 7398 | ) |
| 7399 | || ( |
| 7400 | *proto == '\\' && proto[1] && proto[2] == '\0' |
| 7401 | ) |
| 7402 | ) |
| 7403 | UNIPROTO(UNIOPSUB,optional); |
| 7404 | if (*proto == '\\' && proto[1] == '[') { |
| 7405 | const char *p = proto + 2; |
| 7406 | while(*p && *p != ']') |
| 7407 | ++p; |
| 7408 | if(*p == ']' && !p[1]) |
| 7409 | UNIPROTO(UNIOPSUB,optional); |
| 7410 | } |
| 7411 | if (*proto == '&' && *s == '{') { |
| 7412 | if (PL_curstash) |
| 7413 | sv_setpvs(PL_subname, "__ANON__"); |
| 7414 | else |
| 7415 | sv_setpvs(PL_subname, "__ANON__::__ANON__"); |
| 7416 | if (!PL_lex_allbrackets && |
| 7417 | PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC) |
| 7418 | PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC; |
| 7419 | PREBLOCK(LSTOPSUB); |
| 7420 | } |
| 7421 | } |
| 7422 | #ifdef PERL_MAD |
| 7423 | { |
| 7424 | if (PL_madskills) { |
| 7425 | PL_nextwhite = PL_thiswhite; |
| 7426 | PL_thiswhite = 0; |
| 7427 | } |
| 7428 | start_force(PL_curforce); |
| 7429 | NEXTVAL_NEXTTOKE.opval = pl_yylval.opval; |
| 7430 | PL_expect = XTERM; |
| 7431 | if (PL_madskills) { |
| 7432 | PL_nextwhite = nextPL_nextwhite; |
| 7433 | curmad('X', PL_thistoken); |
| 7434 | PL_thistoken = newSVpvs(""); |
| 7435 | } |
| 7436 | force_next(off ? PRIVATEREF : WORD); |
| 7437 | if (!PL_lex_allbrackets && |
| 7438 | PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC) |
| 7439 | PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC; |
| 7440 | TOKEN(NOAMP); |
| 7441 | } |
| 7442 | } |
| 7443 | |
| 7444 | /* Guess harder when madskills require "best effort". */ |
| 7445 | if (PL_madskills && (!gv || !GvCVu(gv))) { |
| 7446 | int probable_sub = 0; |
| 7447 | if (strchr("\"'`$@%0123456789!*+{[<", *s)) |
| 7448 | probable_sub = 1; |
| 7449 | else if (isALPHA(*s)) { |
| 7450 | char tmpbuf[1024]; |
| 7451 | STRLEN tmplen; |
| 7452 | d = s; |
| 7453 | d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen); |
| 7454 | if (!keyword(tmpbuf, tmplen, 0)) |
| 7455 | probable_sub = 1; |
| 7456 | else { |
| 7457 | while (d < PL_bufend && isSPACE(*d)) |
| 7458 | d++; |
| 7459 | if (*d == '=' && d[1] == '>') |
| 7460 | probable_sub = 1; |
| 7461 | } |
| 7462 | } |
| 7463 | if (probable_sub) { |
| 7464 | gv = gv_fetchpv(PL_tokenbuf, GV_ADD | ( UTF ? SVf_UTF8 : 0 ), |
| 7465 | SVt_PVCV); |
| 7466 | op_free(pl_yylval.opval); |
| 7467 | pl_yylval.opval = |
| 7468 | off ? (OP *)newCVREF(0, rv2cv_op) : rv2cv_op; |
| 7469 | pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN; |
| 7470 | PL_last_lop = PL_oldbufptr; |
| 7471 | PL_last_lop_op = OP_ENTERSUB; |
| 7472 | PL_nextwhite = PL_thiswhite; |
| 7473 | PL_thiswhite = 0; |
| 7474 | start_force(PL_curforce); |
| 7475 | NEXTVAL_NEXTTOKE.opval = pl_yylval.opval; |
| 7476 | PL_expect = XTERM; |
| 7477 | PL_nextwhite = nextPL_nextwhite; |
| 7478 | curmad('X', PL_thistoken); |
| 7479 | PL_thistoken = newSVpvs(""); |
| 7480 | force_next(off ? PRIVATEREF : WORD); |
| 7481 | if (!PL_lex_allbrackets && |
| 7482 | PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC) |
| 7483 | PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC; |
| 7484 | TOKEN(NOAMP); |
| 7485 | } |
| 7486 | #else |
| 7487 | NEXTVAL_NEXTTOKE.opval = pl_yylval.opval; |
| 7488 | PL_expect = XTERM; |
| 7489 | force_next(off ? PRIVATEREF : WORD); |
| 7490 | if (!PL_lex_allbrackets && |
| 7491 | PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC) |
| 7492 | PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC; |
| 7493 | TOKEN(NOAMP); |
| 7494 | #endif |
| 7495 | } |
| 7496 | |
| 7497 | /* Call it a bare word */ |
| 7498 | |
| 7499 | if (PL_hints & HINT_STRICT_SUBS) |
| 7500 | pl_yylval.opval->op_private |= OPpCONST_STRICT; |
| 7501 | else { |
| 7502 | bareword: |
| 7503 | /* after "print" and similar functions (corresponding to |
| 7504 | * "F? L" in opcode.pl), whatever wasn't already parsed as |
| 7505 | * a filehandle should be subject to "strict subs". |
| 7506 | * Likewise for the optional indirect-object argument to system |
| 7507 | * or exec, which can't be a bareword */ |
| 7508 | if ((PL_last_lop_op == OP_PRINT |
| 7509 | || PL_last_lop_op == OP_PRTF |
| 7510 | || PL_last_lop_op == OP_SAY |
| 7511 | || PL_last_lop_op == OP_SYSTEM |
| 7512 | || PL_last_lop_op == OP_EXEC) |
| 7513 | && (PL_hints & HINT_STRICT_SUBS)) |
| 7514 | pl_yylval.opval->op_private |= OPpCONST_STRICT; |
| 7515 | if (lastchar != '-') { |
| 7516 | if (ckWARN(WARN_RESERVED)) { |
| 7517 | d = PL_tokenbuf; |
| 7518 | while (isLOWER(*d)) |
| 7519 | d++; |
| 7520 | if (!*d && !gv_stashpv(PL_tokenbuf, UTF ? SVf_UTF8 : 0)) |
| 7521 | Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved, |
| 7522 | PL_tokenbuf); |
| 7523 | } |
| 7524 | } |
| 7525 | } |
| 7526 | op_free(rv2cv_op); |
| 7527 | |
| 7528 | safe_bareword: |
| 7529 | if ((lastchar == '*' || lastchar == '%' || lastchar == '&') |
| 7530 | && saw_infix_sigil) { |
| 7531 | Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 7532 | "Operator or semicolon missing before %c%"UTF8f, |
| 7533 | lastchar, |
| 7534 | UTF8fARG(UTF, strlen(PL_tokenbuf), |
| 7535 | PL_tokenbuf)); |
| 7536 | Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 7537 | "Ambiguous use of %c resolved as operator %c", |
| 7538 | lastchar, lastchar); |
| 7539 | } |
| 7540 | TOKEN(WORD); |
| 7541 | } |
| 7542 | |
| 7543 | case KEY___FILE__: |
| 7544 | FUN0OP( |
| 7545 | (OP*)newSVOP(OP_CONST, 0, newSVpv(CopFILE(PL_curcop),0)) |
| 7546 | ); |
| 7547 | |
| 7548 | case KEY___LINE__: |
| 7549 | FUN0OP( |
| 7550 | (OP*)newSVOP(OP_CONST, 0, |
| 7551 | Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop))) |
| 7552 | ); |
| 7553 | |
| 7554 | case KEY___PACKAGE__: |
| 7555 | FUN0OP( |
| 7556 | (OP*)newSVOP(OP_CONST, 0, |
| 7557 | (PL_curstash |
| 7558 | ? newSVhek(HvNAME_HEK(PL_curstash)) |
| 7559 | : &PL_sv_undef)) |
| 7560 | ); |
| 7561 | |
| 7562 | case KEY___DATA__: |
| 7563 | case KEY___END__: { |
| 7564 | GV *gv; |
| 7565 | if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) { |
| 7566 | const char *pname = "main"; |
| 7567 | STRLEN plen = 4; |
| 7568 | U32 putf8 = 0; |
| 7569 | if (PL_tokenbuf[2] == 'D') |
| 7570 | { |
| 7571 | HV * const stash = |
| 7572 | PL_curstash ? PL_curstash : PL_defstash; |
| 7573 | pname = HvNAME_get(stash); |
| 7574 | plen = HvNAMELEN (stash); |
| 7575 | if(HvNAMEUTF8(stash)) putf8 = SVf_UTF8; |
| 7576 | } |
| 7577 | gv = gv_fetchpvn_flags( |
| 7578 | Perl_form(aTHX_ "%*s::DATA", (int)plen, pname), |
| 7579 | plen+6, GV_ADD|putf8, SVt_PVIO |
| 7580 | ); |
| 7581 | GvMULTI_on(gv); |
| 7582 | if (!GvIO(gv)) |
| 7583 | GvIOp(gv) = newIO(); |
| 7584 | IoIFP(GvIOp(gv)) = PL_rsfp; |
| 7585 | #if defined(HAS_FCNTL) && defined(F_SETFD) |
| 7586 | { |
| 7587 | const int fd = PerlIO_fileno(PL_rsfp); |
| 7588 | fcntl(fd,F_SETFD,fd >= 3); |
| 7589 | } |
| 7590 | #endif |
| 7591 | /* Mark this internal pseudo-handle as clean */ |
| 7592 | IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT; |
| 7593 | if ((PerlIO*)PL_rsfp == PerlIO_stdin()) |
| 7594 | IoTYPE(GvIOp(gv)) = IoTYPE_STD; |
| 7595 | else |
| 7596 | IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY; |
| 7597 | #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS) |
| 7598 | /* if the script was opened in binmode, we need to revert |
| 7599 | * it to text mode for compatibility; but only iff it has CRs |
| 7600 | * XXX this is a questionable hack at best. */ |
| 7601 | if (PL_bufend-PL_bufptr > 2 |
| 7602 | && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r') |
| 7603 | { |
| 7604 | Off_t loc = 0; |
| 7605 | if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) { |
| 7606 | loc = PerlIO_tell(PL_rsfp); |
| 7607 | (void)PerlIO_seek(PL_rsfp, 0L, 0); |
| 7608 | } |
| 7609 | #ifdef NETWARE |
| 7610 | if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) { |
| 7611 | #else |
| 7612 | if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) { |
| 7613 | #endif /* NETWARE */ |
| 7614 | if (loc > 0) |
| 7615 | PerlIO_seek(PL_rsfp, loc, 0); |
| 7616 | } |
| 7617 | } |
| 7618 | #endif |
| 7619 | #ifdef PERLIO_LAYERS |
| 7620 | if (!IN_BYTES) { |
| 7621 | if (UTF) |
| 7622 | PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8"); |
| 7623 | else if (PL_encoding) { |
| 7624 | SV *name; |
| 7625 | dSP; |
| 7626 | ENTER; |
| 7627 | SAVETMPS; |
| 7628 | PUSHMARK(sp); |
| 7629 | EXTEND(SP, 1); |
| 7630 | XPUSHs(PL_encoding); |
| 7631 | PUTBACK; |
| 7632 | call_method("name", G_SCALAR); |
| 7633 | SPAGAIN; |
| 7634 | name = POPs; |
| 7635 | PUTBACK; |
| 7636 | PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, |
| 7637 | Perl_form(aTHX_ ":encoding(%"SVf")", |
| 7638 | SVfARG(name))); |
| 7639 | FREETMPS; |
| 7640 | LEAVE; |
| 7641 | } |
| 7642 | } |
| 7643 | #endif |
| 7644 | #ifdef PERL_MAD |
| 7645 | if (PL_madskills) { |
| 7646 | if (PL_realtokenstart >= 0) { |
| 7647 | char *tstart = SvPVX(PL_linestr) + PL_realtokenstart; |
| 7648 | if (!PL_endwhite) |
| 7649 | PL_endwhite = newSVpvs(""); |
| 7650 | sv_catsv(PL_endwhite, PL_thiswhite); |
| 7651 | PL_thiswhite = 0; |
| 7652 | sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart); |
| 7653 | PL_realtokenstart = -1; |
| 7654 | } |
| 7655 | while ((s = filter_gets(PL_endwhite, SvCUR(PL_endwhite))) |
| 7656 | != NULL) ; |
| 7657 | } |
| 7658 | #endif |
| 7659 | PL_rsfp = NULL; |
| 7660 | } |
| 7661 | goto fake_eof; |
| 7662 | } |
| 7663 | |
| 7664 | case KEY___SUB__: |
| 7665 | FUN0OP(newPVOP(OP_RUNCV,0,NULL)); |
| 7666 | |
| 7667 | case KEY_AUTOLOAD: |
| 7668 | case KEY_DESTROY: |
| 7669 | case KEY_BEGIN: |
| 7670 | case KEY_UNITCHECK: |
| 7671 | case KEY_CHECK: |
| 7672 | case KEY_INIT: |
| 7673 | case KEY_END: |
| 7674 | if (PL_expect == XSTATE) { |
| 7675 | s = PL_bufptr; |
| 7676 | goto really_sub; |
| 7677 | } |
| 7678 | goto just_a_word; |
| 7679 | |
| 7680 | case KEY_CORE: |
| 7681 | if (*s == ':' && s[1] == ':') { |
| 7682 | STRLEN olen = len; |
| 7683 | d = s; |
| 7684 | s += 2; |
| 7685 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
| 7686 | if ((*s == ':' && s[1] == ':') |
| 7687 | || (!(tmp = keyword(PL_tokenbuf, len, 1)) && *s == '\'')) |
| 7688 | { |
| 7689 | s = d; |
| 7690 | len = olen; |
| 7691 | Copy(PL_bufptr, PL_tokenbuf, olen, char); |
| 7692 | goto just_a_word; |
| 7693 | } |
| 7694 | if (!tmp) |
| 7695 | Perl_croak(aTHX_ "CORE::%"UTF8f" is not a keyword", |
| 7696 | UTF8fARG(UTF, len, PL_tokenbuf)); |
| 7697 | if (tmp < 0) |
| 7698 | tmp = -tmp; |
| 7699 | else if (tmp == KEY_require || tmp == KEY_do |
| 7700 | || tmp == KEY_glob) |
| 7701 | /* that's a way to remember we saw "CORE::" */ |
| 7702 | orig_keyword = tmp; |
| 7703 | goto reserved_word; |
| 7704 | } |
| 7705 | goto just_a_word; |
| 7706 | |
| 7707 | case KEY_abs: |
| 7708 | UNI(OP_ABS); |
| 7709 | |
| 7710 | case KEY_alarm: |
| 7711 | UNI(OP_ALARM); |
| 7712 | |
| 7713 | case KEY_accept: |
| 7714 | LOP(OP_ACCEPT,XTERM); |
| 7715 | |
| 7716 | case KEY_and: |
| 7717 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_LOWLOGIC) |
| 7718 | return REPORT(0); |
| 7719 | OPERATOR(ANDOP); |
| 7720 | |
| 7721 | case KEY_atan2: |
| 7722 | LOP(OP_ATAN2,XTERM); |
| 7723 | |
| 7724 | case KEY_bind: |
| 7725 | LOP(OP_BIND,XTERM); |
| 7726 | |
| 7727 | case KEY_binmode: |
| 7728 | LOP(OP_BINMODE,XTERM); |
| 7729 | |
| 7730 | case KEY_bless: |
| 7731 | LOP(OP_BLESS,XTERM); |
| 7732 | |
| 7733 | case KEY_break: |
| 7734 | FUN0(OP_BREAK); |
| 7735 | |
| 7736 | case KEY_chop: |
| 7737 | UNI(OP_CHOP); |
| 7738 | |
| 7739 | case KEY_continue: |
| 7740 | /* We have to disambiguate the two senses of |
| 7741 | "continue". If the next token is a '{' then |
| 7742 | treat it as the start of a continue block; |
| 7743 | otherwise treat it as a control operator. |
| 7744 | */ |
| 7745 | s = skipspace(s); |
| 7746 | if (*s == '{') |
| 7747 | PREBLOCK(CONTINUE); |
| 7748 | else |
| 7749 | FUN0(OP_CONTINUE); |
| 7750 | |
| 7751 | case KEY_chdir: |
| 7752 | /* may use HOME */ |
| 7753 | (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV); |
| 7754 | UNI(OP_CHDIR); |
| 7755 | |
| 7756 | case KEY_close: |
| 7757 | UNI(OP_CLOSE); |
| 7758 | |
| 7759 | case KEY_closedir: |
| 7760 | UNI(OP_CLOSEDIR); |
| 7761 | |
| 7762 | case KEY_cmp: |
| 7763 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) |
| 7764 | return REPORT(0); |
| 7765 | Eop(OP_SCMP); |
| 7766 | |
| 7767 | case KEY_caller: |
| 7768 | UNI(OP_CALLER); |
| 7769 | |
| 7770 | case KEY_crypt: |
| 7771 | #ifdef FCRYPT |
| 7772 | if (!PL_cryptseen) { |
| 7773 | PL_cryptseen = TRUE; |
| 7774 | init_des(); |
| 7775 | } |
| 7776 | #endif |
| 7777 | LOP(OP_CRYPT,XTERM); |
| 7778 | |
| 7779 | case KEY_chmod: |
| 7780 | LOP(OP_CHMOD,XTERM); |
| 7781 | |
| 7782 | case KEY_chown: |
| 7783 | LOP(OP_CHOWN,XTERM); |
| 7784 | |
| 7785 | case KEY_connect: |
| 7786 | LOP(OP_CONNECT,XTERM); |
| 7787 | |
| 7788 | case KEY_chr: |
| 7789 | UNI(OP_CHR); |
| 7790 | |
| 7791 | case KEY_cos: |
| 7792 | UNI(OP_COS); |
| 7793 | |
| 7794 | case KEY_chroot: |
| 7795 | UNI(OP_CHROOT); |
| 7796 | |
| 7797 | case KEY_default: |
| 7798 | PREBLOCK(DEFAULT); |
| 7799 | |
| 7800 | case KEY_do: |
| 7801 | s = SKIPSPACE1(s); |
| 7802 | if (*s == '{') |
| 7803 | PRETERMBLOCK(DO); |
| 7804 | if (*s != '\'') { |
| 7805 | *PL_tokenbuf = '&'; |
| 7806 | d = scan_word(s, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, |
| 7807 | 1, &len); |
| 7808 | if (len && !keyword(PL_tokenbuf + 1, len, 0)) { |
| 7809 | d = SKIPSPACE1(d); |
| 7810 | if (*d == '(') { |
| 7811 | force_ident_maybe_lex('&'); |
| 7812 | s = d; |
| 7813 | } |
| 7814 | } |
| 7815 | } |
| 7816 | if (orig_keyword == KEY_do) { |
| 7817 | orig_keyword = 0; |
| 7818 | pl_yylval.ival = 1; |
| 7819 | } |
| 7820 | else |
| 7821 | pl_yylval.ival = 0; |
| 7822 | OPERATOR(DO); |
| 7823 | |
| 7824 | case KEY_die: |
| 7825 | PL_hints |= HINT_BLOCK_SCOPE; |
| 7826 | LOP(OP_DIE,XTERM); |
| 7827 | |
| 7828 | case KEY_defined: |
| 7829 | UNI(OP_DEFINED); |
| 7830 | |
| 7831 | case KEY_delete: |
| 7832 | UNI(OP_DELETE); |
| 7833 | |
| 7834 | case KEY_dbmopen: |
| 7835 | Perl_populate_isa(aTHX_ STR_WITH_LEN("AnyDBM_File::ISA"), |
| 7836 | STR_WITH_LEN("NDBM_File::"), |
| 7837 | STR_WITH_LEN("DB_File::"), |
| 7838 | STR_WITH_LEN("GDBM_File::"), |
| 7839 | STR_WITH_LEN("SDBM_File::"), |
| 7840 | STR_WITH_LEN("ODBM_File::"), |
| 7841 | NULL); |
| 7842 | LOP(OP_DBMOPEN,XTERM); |
| 7843 | |
| 7844 | case KEY_dbmclose: |
| 7845 | UNI(OP_DBMCLOSE); |
| 7846 | |
| 7847 | case KEY_dump: |
| 7848 | PL_expect = XOPERATOR; |
| 7849 | s = force_word(s,WORD,TRUE,FALSE); |
| 7850 | LOOPX(OP_DUMP); |
| 7851 | |
| 7852 | case KEY_else: |
| 7853 | PREBLOCK(ELSE); |
| 7854 | |
| 7855 | case KEY_elsif: |
| 7856 | pl_yylval.ival = CopLINE(PL_curcop); |
| 7857 | OPERATOR(ELSIF); |
| 7858 | |
| 7859 | case KEY_eq: |
| 7860 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) |
| 7861 | return REPORT(0); |
| 7862 | Eop(OP_SEQ); |
| 7863 | |
| 7864 | case KEY_exists: |
| 7865 | UNI(OP_EXISTS); |
| 7866 | |
| 7867 | case KEY_exit: |
| 7868 | if (PL_madskills) |
| 7869 | UNI(OP_INT); |
| 7870 | UNI(OP_EXIT); |
| 7871 | |
| 7872 | case KEY_eval: |
| 7873 | s = SKIPSPACE1(s); |
| 7874 | if (*s == '{') { /* block eval */ |
| 7875 | PL_expect = XTERMBLOCK; |
| 7876 | UNIBRACK(OP_ENTERTRY); |
| 7877 | } |
| 7878 | else { /* string eval */ |
| 7879 | PL_expect = XTERM; |
| 7880 | UNIBRACK(OP_ENTEREVAL); |
| 7881 | } |
| 7882 | |
| 7883 | case KEY_evalbytes: |
| 7884 | PL_expect = XTERM; |
| 7885 | UNIBRACK(-OP_ENTEREVAL); |
| 7886 | |
| 7887 | case KEY_eof: |
| 7888 | UNI(OP_EOF); |
| 7889 | |
| 7890 | case KEY_exp: |
| 7891 | UNI(OP_EXP); |
| 7892 | |
| 7893 | case KEY_each: |
| 7894 | UNI(OP_EACH); |
| 7895 | |
| 7896 | case KEY_exec: |
| 7897 | LOP(OP_EXEC,XREF); |
| 7898 | |
| 7899 | case KEY_endhostent: |
| 7900 | FUN0(OP_EHOSTENT); |
| 7901 | |
| 7902 | case KEY_endnetent: |
| 7903 | FUN0(OP_ENETENT); |
| 7904 | |
| 7905 | case KEY_endservent: |
| 7906 | FUN0(OP_ESERVENT); |
| 7907 | |
| 7908 | case KEY_endprotoent: |
| 7909 | FUN0(OP_EPROTOENT); |
| 7910 | |
| 7911 | case KEY_endpwent: |
| 7912 | FUN0(OP_EPWENT); |
| 7913 | |
| 7914 | case KEY_endgrent: |
| 7915 | FUN0(OP_EGRENT); |
| 7916 | |
| 7917 | case KEY_for: |
| 7918 | case KEY_foreach: |
| 7919 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR) |
| 7920 | return REPORT(0); |
| 7921 | pl_yylval.ival = CopLINE(PL_curcop); |
| 7922 | s = SKIPSPACE1(s); |
| 7923 | if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) { |
| 7924 | char *p = s; |
| 7925 | #ifdef PERL_MAD |
| 7926 | int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */ |
| 7927 | #endif |
| 7928 | |
| 7929 | if ((PL_bufend - p) >= 3 && |
| 7930 | strnEQ(p, "my", 2) && isSPACE(*(p + 2))) |
| 7931 | p += 2; |
| 7932 | else if ((PL_bufend - p) >= 4 && |
| 7933 | strnEQ(p, "our", 3) && isSPACE(*(p + 3))) |
| 7934 | p += 3; |
| 7935 | p = PEEKSPACE(p); |
| 7936 | if (isIDFIRST_lazy_if(p,UTF)) { |
| 7937 | p = scan_ident(p, PL_bufend, |
| 7938 | PL_tokenbuf, sizeof PL_tokenbuf, TRUE); |
| 7939 | p = PEEKSPACE(p); |
| 7940 | } |
| 7941 | if (*p != '$') |
| 7942 | Perl_croak(aTHX_ "Missing $ on loop variable"); |
| 7943 | #ifdef PERL_MAD |
| 7944 | s = SvPVX(PL_linestr) + soff; |
| 7945 | #endif |
| 7946 | } |
| 7947 | OPERATOR(FOR); |
| 7948 | |
| 7949 | case KEY_formline: |
| 7950 | LOP(OP_FORMLINE,XTERM); |
| 7951 | |
| 7952 | case KEY_fork: |
| 7953 | FUN0(OP_FORK); |
| 7954 | |
| 7955 | case KEY_fc: |
| 7956 | UNI(OP_FC); |
| 7957 | |
| 7958 | case KEY_fcntl: |
| 7959 | LOP(OP_FCNTL,XTERM); |
| 7960 | |
| 7961 | case KEY_fileno: |
| 7962 | UNI(OP_FILENO); |
| 7963 | |
| 7964 | case KEY_flock: |
| 7965 | LOP(OP_FLOCK,XTERM); |
| 7966 | |
| 7967 | case KEY_gt: |
| 7968 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) |
| 7969 | return REPORT(0); |
| 7970 | Rop(OP_SGT); |
| 7971 | |
| 7972 | case KEY_ge: |
| 7973 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) |
| 7974 | return REPORT(0); |
| 7975 | Rop(OP_SGE); |
| 7976 | |
| 7977 | case KEY_grep: |
| 7978 | LOP(OP_GREPSTART, XREF); |
| 7979 | |
| 7980 | case KEY_goto: |
| 7981 | PL_expect = XOPERATOR; |
| 7982 | s = force_word(s,WORD,TRUE,FALSE); |
| 7983 | LOOPX(OP_GOTO); |
| 7984 | |
| 7985 | case KEY_gmtime: |
| 7986 | UNI(OP_GMTIME); |
| 7987 | |
| 7988 | case KEY_getc: |
| 7989 | UNIDOR(OP_GETC); |
| 7990 | |
| 7991 | case KEY_getppid: |
| 7992 | FUN0(OP_GETPPID); |
| 7993 | |
| 7994 | case KEY_getpgrp: |
| 7995 | UNI(OP_GETPGRP); |
| 7996 | |
| 7997 | case KEY_getpriority: |
| 7998 | LOP(OP_GETPRIORITY,XTERM); |
| 7999 | |
| 8000 | case KEY_getprotobyname: |
| 8001 | UNI(OP_GPBYNAME); |
| 8002 | |
| 8003 | case KEY_getprotobynumber: |
| 8004 | LOP(OP_GPBYNUMBER,XTERM); |
| 8005 | |
| 8006 | case KEY_getprotoent: |
| 8007 | FUN0(OP_GPROTOENT); |
| 8008 | |
| 8009 | case KEY_getpwent: |
| 8010 | FUN0(OP_GPWENT); |
| 8011 | |
| 8012 | case KEY_getpwnam: |
| 8013 | UNI(OP_GPWNAM); |
| 8014 | |
| 8015 | case KEY_getpwuid: |
| 8016 | UNI(OP_GPWUID); |
| 8017 | |
| 8018 | case KEY_getpeername: |
| 8019 | UNI(OP_GETPEERNAME); |
| 8020 | |
| 8021 | case KEY_gethostbyname: |
| 8022 | UNI(OP_GHBYNAME); |
| 8023 | |
| 8024 | case KEY_gethostbyaddr: |
| 8025 | LOP(OP_GHBYADDR,XTERM); |
| 8026 | |
| 8027 | case KEY_gethostent: |
| 8028 | FUN0(OP_GHOSTENT); |
| 8029 | |
| 8030 | case KEY_getnetbyname: |
| 8031 | UNI(OP_GNBYNAME); |
| 8032 | |
| 8033 | case KEY_getnetbyaddr: |
| 8034 | LOP(OP_GNBYADDR,XTERM); |
| 8035 | |
| 8036 | case KEY_getnetent: |
| 8037 | FUN0(OP_GNETENT); |
| 8038 | |
| 8039 | case KEY_getservbyname: |
| 8040 | LOP(OP_GSBYNAME,XTERM); |
| 8041 | |
| 8042 | case KEY_getservbyport: |
| 8043 | LOP(OP_GSBYPORT,XTERM); |
| 8044 | |
| 8045 | case KEY_getservent: |
| 8046 | FUN0(OP_GSERVENT); |
| 8047 | |
| 8048 | case KEY_getsockname: |
| 8049 | UNI(OP_GETSOCKNAME); |
| 8050 | |
| 8051 | case KEY_getsockopt: |
| 8052 | LOP(OP_GSOCKOPT,XTERM); |
| 8053 | |
| 8054 | case KEY_getgrent: |
| 8055 | FUN0(OP_GGRENT); |
| 8056 | |
| 8057 | case KEY_getgrnam: |
| 8058 | UNI(OP_GGRNAM); |
| 8059 | |
| 8060 | case KEY_getgrgid: |
| 8061 | UNI(OP_GGRGID); |
| 8062 | |
| 8063 | case KEY_getlogin: |
| 8064 | FUN0(OP_GETLOGIN); |
| 8065 | |
| 8066 | case KEY_given: |
| 8067 | pl_yylval.ival = CopLINE(PL_curcop); |
| 8068 | Perl_ck_warner_d(aTHX_ |
| 8069 | packWARN(WARN_EXPERIMENTAL__SMARTMATCH), |
| 8070 | "given is experimental"); |
| 8071 | OPERATOR(GIVEN); |
| 8072 | |
| 8073 | case KEY_glob: |
| 8074 | LOP( |
| 8075 | orig_keyword==KEY_glob ? (orig_keyword=0, -OP_GLOB) : OP_GLOB, |
| 8076 | XTERM |
| 8077 | ); |
| 8078 | |
| 8079 | case KEY_hex: |
| 8080 | UNI(OP_HEX); |
| 8081 | |
| 8082 | case KEY_if: |
| 8083 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR) |
| 8084 | return REPORT(0); |
| 8085 | pl_yylval.ival = CopLINE(PL_curcop); |
| 8086 | OPERATOR(IF); |
| 8087 | |
| 8088 | case KEY_index: |
| 8089 | LOP(OP_INDEX,XTERM); |
| 8090 | |
| 8091 | case KEY_int: |
| 8092 | UNI(OP_INT); |
| 8093 | |
| 8094 | case KEY_ioctl: |
| 8095 | LOP(OP_IOCTL,XTERM); |
| 8096 | |
| 8097 | case KEY_join: |
| 8098 | LOP(OP_JOIN,XTERM); |
| 8099 | |
| 8100 | case KEY_keys: |
| 8101 | UNI(OP_KEYS); |
| 8102 | |
| 8103 | case KEY_kill: |
| 8104 | LOP(OP_KILL,XTERM); |
| 8105 | |
| 8106 | case KEY_last: |
| 8107 | PL_expect = XOPERATOR; |
| 8108 | s = force_word(s,WORD,TRUE,FALSE); |
| 8109 | LOOPX(OP_LAST); |
| 8110 | |
| 8111 | case KEY_lc: |
| 8112 | UNI(OP_LC); |
| 8113 | |
| 8114 | case KEY_lcfirst: |
| 8115 | UNI(OP_LCFIRST); |
| 8116 | |
| 8117 | case KEY_local: |
| 8118 | pl_yylval.ival = 0; |
| 8119 | OPERATOR(LOCAL); |
| 8120 | |
| 8121 | case KEY_length: |
| 8122 | UNI(OP_LENGTH); |
| 8123 | |
| 8124 | case KEY_lt: |
| 8125 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) |
| 8126 | return REPORT(0); |
| 8127 | Rop(OP_SLT); |
| 8128 | |
| 8129 | case KEY_le: |
| 8130 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) |
| 8131 | return REPORT(0); |
| 8132 | Rop(OP_SLE); |
| 8133 | |
| 8134 | case KEY_localtime: |
| 8135 | UNI(OP_LOCALTIME); |
| 8136 | |
| 8137 | case KEY_log: |
| 8138 | UNI(OP_LOG); |
| 8139 | |
| 8140 | case KEY_link: |
| 8141 | LOP(OP_LINK,XTERM); |
| 8142 | |
| 8143 | case KEY_listen: |
| 8144 | LOP(OP_LISTEN,XTERM); |
| 8145 | |
| 8146 | case KEY_lock: |
| 8147 | UNI(OP_LOCK); |
| 8148 | |
| 8149 | case KEY_lstat: |
| 8150 | UNI(OP_LSTAT); |
| 8151 | |
| 8152 | case KEY_m: |
| 8153 | s = scan_pat(s,OP_MATCH); |
| 8154 | TERM(sublex_start()); |
| 8155 | |
| 8156 | case KEY_map: |
| 8157 | LOP(OP_MAPSTART, XREF); |
| 8158 | |
| 8159 | case KEY_mkdir: |
| 8160 | LOP(OP_MKDIR,XTERM); |
| 8161 | |
| 8162 | case KEY_msgctl: |
| 8163 | LOP(OP_MSGCTL,XTERM); |
| 8164 | |
| 8165 | case KEY_msgget: |
| 8166 | LOP(OP_MSGGET,XTERM); |
| 8167 | |
| 8168 | case KEY_msgrcv: |
| 8169 | LOP(OP_MSGRCV,XTERM); |
| 8170 | |
| 8171 | case KEY_msgsnd: |
| 8172 | LOP(OP_MSGSND,XTERM); |
| 8173 | |
| 8174 | case KEY_our: |
| 8175 | case KEY_my: |
| 8176 | case KEY_state: |
| 8177 | PL_in_my = (U16)tmp; |
| 8178 | s = SKIPSPACE1(s); |
| 8179 | if (isIDFIRST_lazy_if(s,UTF)) { |
| 8180 | #ifdef PERL_MAD |
| 8181 | char* start = s; |
| 8182 | #endif |
| 8183 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len); |
| 8184 | if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3)) |
| 8185 | { |
| 8186 | if (!FEATURE_LEXSUBS_IS_ENABLED) |
| 8187 | Perl_croak(aTHX_ |
| 8188 | "Experimental \"%s\" subs not enabled", |
| 8189 | tmp == KEY_my ? "my" : |
| 8190 | tmp == KEY_state ? "state" : "our"); |
| 8191 | Perl_ck_warner_d(aTHX_ |
| 8192 | packWARN(WARN_EXPERIMENTAL__LEXICAL_SUBS), |
| 8193 | "The lexical_subs feature is experimental"); |
| 8194 | goto really_sub; |
| 8195 | } |
| 8196 | PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len); |
| 8197 | if (!PL_in_my_stash) { |
| 8198 | char tmpbuf[1024]; |
| 8199 | PL_bufptr = s; |
| 8200 | my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf); |
| 8201 | yyerror_pv(tmpbuf, UTF ? SVf_UTF8 : 0); |
| 8202 | } |
| 8203 | #ifdef PERL_MAD |
| 8204 | if (PL_madskills) { /* just add type to declarator token */ |
| 8205 | sv_catsv(PL_thistoken, PL_nextwhite); |
| 8206 | PL_nextwhite = 0; |
| 8207 | sv_catpvn(PL_thistoken, start, s - start); |
| 8208 | } |
| 8209 | #endif |
| 8210 | } |
| 8211 | pl_yylval.ival = 1; |
| 8212 | OPERATOR(MY); |
| 8213 | |
| 8214 | case KEY_next: |
| 8215 | PL_expect = XOPERATOR; |
| 8216 | s = force_word(s,WORD,TRUE,FALSE); |
| 8217 | LOOPX(OP_NEXT); |
| 8218 | |
| 8219 | case KEY_ne: |
| 8220 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE) |
| 8221 | return REPORT(0); |
| 8222 | Eop(OP_SNE); |
| 8223 | |
| 8224 | case KEY_no: |
| 8225 | s = tokenize_use(0, s); |
| 8226 | TERM(USE); |
| 8227 | |
| 8228 | case KEY_not: |
| 8229 | if (*s == '(' || (s = SKIPSPACE1(s), *s == '(')) |
| 8230 | FUN1(OP_NOT); |
| 8231 | else { |
| 8232 | if (!PL_lex_allbrackets && |
| 8233 | PL_lex_fakeeof > LEX_FAKEEOF_LOWLOGIC) |
| 8234 | PL_lex_fakeeof = LEX_FAKEEOF_LOWLOGIC; |
| 8235 | OPERATOR(NOTOP); |
| 8236 | } |
| 8237 | |
| 8238 | case KEY_open: |
| 8239 | s = SKIPSPACE1(s); |
| 8240 | if (isIDFIRST_lazy_if(s,UTF)) { |
| 8241 | const char *t; |
| 8242 | d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, |
| 8243 | &len); |
| 8244 | for (t=d; isSPACE(*t);) |
| 8245 | t++; |
| 8246 | if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE) |
| 8247 | /* [perl #16184] */ |
| 8248 | && !(t[0] == '=' && t[1] == '>') |
| 8249 | && !(t[0] == ':' && t[1] == ':') |
| 8250 | && !keyword(s, d-s, 0) |
| 8251 | ) { |
| 8252 | Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE), |
| 8253 | "Precedence problem: open %"UTF8f" should be open(%"UTF8f")", |
| 8254 | UTF8fARG(UTF, d-s, s), UTF8fARG(UTF, d-s, s)); |
| 8255 | } |
| 8256 | } |
| 8257 | LOP(OP_OPEN,XTERM); |
| 8258 | |
| 8259 | case KEY_or: |
| 8260 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_LOWLOGIC) |
| 8261 | return REPORT(0); |
| 8262 | pl_yylval.ival = OP_OR; |
| 8263 | OPERATOR(OROP); |
| 8264 | |
| 8265 | case KEY_ord: |
| 8266 | UNI(OP_ORD); |
| 8267 | |
| 8268 | case KEY_oct: |
| 8269 | UNI(OP_OCT); |
| 8270 | |
| 8271 | case KEY_opendir: |
| 8272 | LOP(OP_OPEN_DIR,XTERM); |
| 8273 | |
| 8274 | case KEY_print: |
| 8275 | checkcomma(s,PL_tokenbuf,"filehandle"); |
| 8276 | LOP(OP_PRINT,XREF); |
| 8277 | |
| 8278 | case KEY_printf: |
| 8279 | checkcomma(s,PL_tokenbuf,"filehandle"); |
| 8280 | LOP(OP_PRTF,XREF); |
| 8281 | |
| 8282 | case KEY_prototype: |
| 8283 | UNI(OP_PROTOTYPE); |
| 8284 | |
| 8285 | case KEY_push: |
| 8286 | LOP(OP_PUSH,XTERM); |
| 8287 | |
| 8288 | case KEY_pop: |
| 8289 | UNIDOR(OP_POP); |
| 8290 | |
| 8291 | case KEY_pos: |
| 8292 | UNIDOR(OP_POS); |
| 8293 | |
| 8294 | case KEY_pack: |
| 8295 | LOP(OP_PACK,XTERM); |
| 8296 | |
| 8297 | case KEY_package: |
| 8298 | s = force_word(s,WORD,FALSE,TRUE); |
| 8299 | s = SKIPSPACE1(s); |
| 8300 | s = force_strict_version(s); |
| 8301 | PL_lex_expect = XBLOCK; |
| 8302 | OPERATOR(PACKAGE); |
| 8303 | |
| 8304 | case KEY_pipe: |
| 8305 | LOP(OP_PIPE_OP,XTERM); |
| 8306 | |
| 8307 | case KEY_q: |
| 8308 | s = scan_str(s,!!PL_madskills,FALSE,FALSE, FALSE); |
| 8309 | if (!s) |
| 8310 | missingterm(NULL); |
| 8311 | pl_yylval.ival = OP_CONST; |
| 8312 | TERM(sublex_start()); |
| 8313 | |
| 8314 | case KEY_quotemeta: |
| 8315 | UNI(OP_QUOTEMETA); |
| 8316 | |
| 8317 | case KEY_qw: { |
| 8318 | OP *words = NULL; |
| 8319 | s = scan_str(s,!!PL_madskills,FALSE,FALSE, FALSE); |
| 8320 | if (!s) |
| 8321 | missingterm(NULL); |
| 8322 | PL_expect = XOPERATOR; |
| 8323 | if (SvCUR(PL_lex_stuff)) { |
| 8324 | int warned_comma = !ckWARN(WARN_QW); |
| 8325 | int warned_comment = warned_comma; |
| 8326 | d = SvPV_force(PL_lex_stuff, len); |
| 8327 | while (len) { |
| 8328 | for (; isSPACE(*d) && len; --len, ++d) |
| 8329 | /**/; |
| 8330 | if (len) { |
| 8331 | SV *sv; |
| 8332 | const char *b = d; |
| 8333 | if (!warned_comma || !warned_comment) { |
| 8334 | for (; !isSPACE(*d) && len; --len, ++d) { |
| 8335 | if (!warned_comma && *d == ',') { |
| 8336 | Perl_warner(aTHX_ packWARN(WARN_QW), |
| 8337 | "Possible attempt to separate words with commas"); |
| 8338 | ++warned_comma; |
| 8339 | } |
| 8340 | else if (!warned_comment && *d == '#') { |
| 8341 | Perl_warner(aTHX_ packWARN(WARN_QW), |
| 8342 | "Possible attempt to put comments in qw() list"); |
| 8343 | ++warned_comment; |
| 8344 | } |
| 8345 | } |
| 8346 | } |
| 8347 | else { |
| 8348 | for (; !isSPACE(*d) && len; --len, ++d) |
| 8349 | /**/; |
| 8350 | } |
| 8351 | sv = newSVpvn_utf8(b, d-b, DO_UTF8(PL_lex_stuff)); |
| 8352 | words = op_append_elem(OP_LIST, words, |
| 8353 | newSVOP(OP_CONST, 0, tokeq(sv))); |
| 8354 | } |
| 8355 | } |
| 8356 | } |
| 8357 | if (!words) |
| 8358 | words = newNULLLIST(); |
| 8359 | if (PL_lex_stuff) { |
| 8360 | SvREFCNT_dec(PL_lex_stuff); |
| 8361 | PL_lex_stuff = NULL; |
| 8362 | } |
| 8363 | PL_expect = XOPERATOR; |
| 8364 | pl_yylval.opval = sawparens(words); |
| 8365 | TOKEN(QWLIST); |
| 8366 | } |
| 8367 | |
| 8368 | case KEY_qq: |
| 8369 | s = scan_str(s,!!PL_madskills,FALSE,FALSE, FALSE); |
| 8370 | if (!s) |
| 8371 | missingterm(NULL); |
| 8372 | pl_yylval.ival = OP_STRINGIFY; |
| 8373 | if (SvIVX(PL_lex_stuff) == '\'') |
| 8374 | SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should interpolate */ |
| 8375 | TERM(sublex_start()); |
| 8376 | |
| 8377 | case KEY_qr: |
| 8378 | s = scan_pat(s,OP_QR); |
| 8379 | TERM(sublex_start()); |
| 8380 | |
| 8381 | case KEY_qx: |
| 8382 | s = scan_str(s,!!PL_madskills,FALSE,FALSE, FALSE); |
| 8383 | if (!s) |
| 8384 | missingterm(NULL); |
| 8385 | readpipe_override(); |
| 8386 | TERM(sublex_start()); |
| 8387 | |
| 8388 | case KEY_return: |
| 8389 | OLDLOP(OP_RETURN); |
| 8390 | |
| 8391 | case KEY_require: |
| 8392 | s = SKIPSPACE1(s); |
| 8393 | PL_expect = XOPERATOR; |
| 8394 | if (isDIGIT(*s)) { |
| 8395 | s = force_version(s, FALSE); |
| 8396 | } |
| 8397 | else if (*s != 'v' || !isDIGIT(s[1]) |
| 8398 | || (s = force_version(s, TRUE), *s == 'v')) |
| 8399 | { |
| 8400 | *PL_tokenbuf = '\0'; |
| 8401 | s = force_word(s,WORD,TRUE,TRUE); |
| 8402 | if (isIDFIRST_lazy_if(PL_tokenbuf,UTF)) |
| 8403 | gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), |
| 8404 | GV_ADD | (UTF ? SVf_UTF8 : 0)); |
| 8405 | else if (*s == '<') |
| 8406 | yyerror("<> should be quotes"); |
| 8407 | } |
| 8408 | if (orig_keyword == KEY_require) { |
| 8409 | orig_keyword = 0; |
| 8410 | pl_yylval.ival = 1; |
| 8411 | } |
| 8412 | else |
| 8413 | pl_yylval.ival = 0; |
| 8414 | PL_expect = XTERM; |
| 8415 | PL_bufptr = s; |
| 8416 | PL_last_uni = PL_oldbufptr; |
| 8417 | PL_last_lop_op = OP_REQUIRE; |
| 8418 | s = skipspace(s); |
| 8419 | return REPORT( (int)REQUIRE ); |
| 8420 | |
| 8421 | case KEY_reset: |
| 8422 | UNI(OP_RESET); |
| 8423 | |
| 8424 | case KEY_redo: |
| 8425 | PL_expect = XOPERATOR; |
| 8426 | s = force_word(s,WORD,TRUE,FALSE); |
| 8427 | LOOPX(OP_REDO); |
| 8428 | |
| 8429 | case KEY_rename: |
| 8430 | LOP(OP_RENAME,XTERM); |
| 8431 | |
| 8432 | case KEY_rand: |
| 8433 | UNI(OP_RAND); |
| 8434 | |
| 8435 | case KEY_rmdir: |
| 8436 | UNI(OP_RMDIR); |
| 8437 | |
| 8438 | case KEY_rindex: |
| 8439 | LOP(OP_RINDEX,XTERM); |
| 8440 | |
| 8441 | case KEY_read: |
| 8442 | LOP(OP_READ,XTERM); |
| 8443 | |
| 8444 | case KEY_readdir: |
| 8445 | UNI(OP_READDIR); |
| 8446 | |
| 8447 | case KEY_readline: |
| 8448 | UNIDOR(OP_READLINE); |
| 8449 | |
| 8450 | case KEY_readpipe: |
| 8451 | UNIDOR(OP_BACKTICK); |
| 8452 | |
| 8453 | case KEY_rewinddir: |
| 8454 | UNI(OP_REWINDDIR); |
| 8455 | |
| 8456 | case KEY_recv: |
| 8457 | LOP(OP_RECV,XTERM); |
| 8458 | |
| 8459 | case KEY_reverse: |
| 8460 | LOP(OP_REVERSE,XTERM); |
| 8461 | |
| 8462 | case KEY_readlink: |
| 8463 | UNIDOR(OP_READLINK); |
| 8464 | |
| 8465 | case KEY_ref: |
| 8466 | UNI(OP_REF); |
| 8467 | |
| 8468 | case KEY_s: |
| 8469 | s = scan_subst(s); |
| 8470 | if (pl_yylval.opval) |
| 8471 | TERM(sublex_start()); |
| 8472 | else |
| 8473 | TOKEN(1); /* force error */ |
| 8474 | |
| 8475 | case KEY_say: |
| 8476 | checkcomma(s,PL_tokenbuf,"filehandle"); |
| 8477 | LOP(OP_SAY,XREF); |
| 8478 | |
| 8479 | case KEY_chomp: |
| 8480 | UNI(OP_CHOMP); |
| 8481 | |
| 8482 | case KEY_scalar: |
| 8483 | UNI(OP_SCALAR); |
| 8484 | |
| 8485 | case KEY_select: |
| 8486 | LOP(OP_SELECT,XTERM); |
| 8487 | |
| 8488 | case KEY_seek: |
| 8489 | LOP(OP_SEEK,XTERM); |
| 8490 | |
| 8491 | case KEY_semctl: |
| 8492 | LOP(OP_SEMCTL,XTERM); |
| 8493 | |
| 8494 | case KEY_semget: |
| 8495 | LOP(OP_SEMGET,XTERM); |
| 8496 | |
| 8497 | case KEY_semop: |
| 8498 | LOP(OP_SEMOP,XTERM); |
| 8499 | |
| 8500 | case KEY_send: |
| 8501 | LOP(OP_SEND,XTERM); |
| 8502 | |
| 8503 | case KEY_setpgrp: |
| 8504 | LOP(OP_SETPGRP,XTERM); |
| 8505 | |
| 8506 | case KEY_setpriority: |
| 8507 | LOP(OP_SETPRIORITY,XTERM); |
| 8508 | |
| 8509 | case KEY_sethostent: |
| 8510 | UNI(OP_SHOSTENT); |
| 8511 | |
| 8512 | case KEY_setnetent: |
| 8513 | UNI(OP_SNETENT); |
| 8514 | |
| 8515 | case KEY_setservent: |
| 8516 | UNI(OP_SSERVENT); |
| 8517 | |
| 8518 | case KEY_setprotoent: |
| 8519 | UNI(OP_SPROTOENT); |
| 8520 | |
| 8521 | case KEY_setpwent: |
| 8522 | FUN0(OP_SPWENT); |
| 8523 | |
| 8524 | case KEY_setgrent: |
| 8525 | FUN0(OP_SGRENT); |
| 8526 | |
| 8527 | case KEY_seekdir: |
| 8528 | LOP(OP_SEEKDIR,XTERM); |
| 8529 | |
| 8530 | case KEY_setsockopt: |
| 8531 | LOP(OP_SSOCKOPT,XTERM); |
| 8532 | |
| 8533 | case KEY_shift: |
| 8534 | UNIDOR(OP_SHIFT); |
| 8535 | |
| 8536 | case KEY_shmctl: |
| 8537 | LOP(OP_SHMCTL,XTERM); |
| 8538 | |
| 8539 | case KEY_shmget: |
| 8540 | LOP(OP_SHMGET,XTERM); |
| 8541 | |
| 8542 | case KEY_shmread: |
| 8543 | LOP(OP_SHMREAD,XTERM); |
| 8544 | |
| 8545 | case KEY_shmwrite: |
| 8546 | LOP(OP_SHMWRITE,XTERM); |
| 8547 | |
| 8548 | case KEY_shutdown: |
| 8549 | LOP(OP_SHUTDOWN,XTERM); |
| 8550 | |
| 8551 | case KEY_sin: |
| 8552 | UNI(OP_SIN); |
| 8553 | |
| 8554 | case KEY_sleep: |
| 8555 | UNI(OP_SLEEP); |
| 8556 | |
| 8557 | case KEY_socket: |
| 8558 | LOP(OP_SOCKET,XTERM); |
| 8559 | |
| 8560 | case KEY_socketpair: |
| 8561 | LOP(OP_SOCKPAIR,XTERM); |
| 8562 | |
| 8563 | case KEY_sort: |
| 8564 | checkcomma(s,PL_tokenbuf,"subroutine name"); |
| 8565 | s = SKIPSPACE1(s); |
| 8566 | PL_expect = XTERM; |
| 8567 | s = force_word(s,WORD,TRUE,TRUE); |
| 8568 | LOP(OP_SORT,XREF); |
| 8569 | |
| 8570 | case KEY_split: |
| 8571 | LOP(OP_SPLIT,XTERM); |
| 8572 | |
| 8573 | case KEY_sprintf: |
| 8574 | LOP(OP_SPRINTF,XTERM); |
| 8575 | |
| 8576 | case KEY_splice: |
| 8577 | LOP(OP_SPLICE,XTERM); |
| 8578 | |
| 8579 | case KEY_sqrt: |
| 8580 | UNI(OP_SQRT); |
| 8581 | |
| 8582 | case KEY_srand: |
| 8583 | UNI(OP_SRAND); |
| 8584 | |
| 8585 | case KEY_stat: |
| 8586 | UNI(OP_STAT); |
| 8587 | |
| 8588 | case KEY_study: |
| 8589 | UNI(OP_STUDY); |
| 8590 | |
| 8591 | case KEY_substr: |
| 8592 | LOP(OP_SUBSTR,XTERM); |
| 8593 | |
| 8594 | case KEY_format: |
| 8595 | case KEY_sub: |
| 8596 | really_sub: |
| 8597 | { |
| 8598 | char * const tmpbuf = PL_tokenbuf + 1; |
| 8599 | expectation attrful; |
| 8600 | bool have_name, have_proto; |
| 8601 | const int key = tmp; |
| 8602 | #ifndef PERL_MAD |
| 8603 | SV *format_name = NULL; |
| 8604 | #endif |
| 8605 | |
| 8606 | #ifdef PERL_MAD |
| 8607 | SV *tmpwhite = 0; |
| 8608 | |
| 8609 | char *tstart = SvPVX(PL_linestr) + PL_realtokenstart; |
| 8610 | SV *subtoken = PL_madskills |
| 8611 | ? newSVpvn_flags(tstart, s - tstart, SvUTF8(PL_linestr)) |
| 8612 | : NULL; |
| 8613 | PL_thistoken = 0; |
| 8614 | |
| 8615 | d = s; |
| 8616 | s = SKIPSPACE2(s,tmpwhite); |
| 8617 | #else |
| 8618 | d = s; |
| 8619 | s = skipspace(s); |
| 8620 | #endif |
| 8621 | |
| 8622 | if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' || |
| 8623 | (*s == ':' && s[1] == ':')) |
| 8624 | { |
| 8625 | #ifdef PERL_MAD |
| 8626 | SV *nametoke = NULL; |
| 8627 | #endif |
| 8628 | |
| 8629 | PL_expect = XBLOCK; |
| 8630 | attrful = XATTRBLOCK; |
| 8631 | d = scan_word(s, tmpbuf, sizeof PL_tokenbuf - 1, TRUE, |
| 8632 | &len); |
| 8633 | #ifdef PERL_MAD |
| 8634 | if (PL_madskills) |
| 8635 | nametoke = newSVpvn_flags(s, d - s, SvUTF8(PL_linestr)); |
| 8636 | #else |
| 8637 | if (key == KEY_format) |
| 8638 | format_name = S_newSV_maybe_utf8(aTHX_ s, d - s); |
| 8639 | #endif |
| 8640 | *PL_tokenbuf = '&'; |
| 8641 | if (memchr(tmpbuf, ':', len) || key != KEY_sub |
| 8642 | || pad_findmy_pvn( |
| 8643 | PL_tokenbuf, len + 1, UTF ? SVf_UTF8 : 0 |
| 8644 | ) != NOT_IN_PAD) |
| 8645 | sv_setpvn(PL_subname, tmpbuf, len); |
| 8646 | else { |
| 8647 | sv_setsv(PL_subname,PL_curstname); |
| 8648 | sv_catpvs(PL_subname,"::"); |
| 8649 | sv_catpvn(PL_subname,tmpbuf,len); |
| 8650 | } |
| 8651 | if (SvUTF8(PL_linestr)) |
| 8652 | SvUTF8_on(PL_subname); |
| 8653 | have_name = TRUE; |
| 8654 | |
| 8655 | |
| 8656 | #ifdef PERL_MAD |
| 8657 | start_force(0); |
| 8658 | CURMAD('X', nametoke); |
| 8659 | CURMAD('_', tmpwhite); |
| 8660 | force_ident_maybe_lex('&'); |
| 8661 | |
| 8662 | s = SKIPSPACE2(d,tmpwhite); |
| 8663 | #else |
| 8664 | s = skipspace(d); |
| 8665 | #endif |
| 8666 | } |
| 8667 | else { |
| 8668 | if (key == KEY_my || key == KEY_our || key==KEY_state) |
| 8669 | { |
| 8670 | *d = '\0'; |
| 8671 | /* diag_listed_as: Missing name in "%s sub" */ |
| 8672 | Perl_croak(aTHX_ |
| 8673 | "Missing name in \"%s\"", PL_bufptr); |
| 8674 | } |
| 8675 | PL_expect = XTERMBLOCK; |
| 8676 | attrful = XATTRTERM; |
| 8677 | sv_setpvs(PL_subname,"?"); |
| 8678 | have_name = FALSE; |
| 8679 | } |
| 8680 | |
| 8681 | if (key == KEY_format) { |
| 8682 | #ifdef PERL_MAD |
| 8683 | PL_thistoken = subtoken; |
| 8684 | s = d; |
| 8685 | #else |
| 8686 | if (format_name) { |
| 8687 | start_force(PL_curforce); |
| 8688 | NEXTVAL_NEXTTOKE.opval |
| 8689 | = (OP*)newSVOP(OP_CONST,0, format_name); |
| 8690 | NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE; |
| 8691 | force_next(WORD); |
| 8692 | } |
| 8693 | #endif |
| 8694 | PREBLOCK(FORMAT); |
| 8695 | } |
| 8696 | |
| 8697 | /* Look for a prototype */ |
| 8698 | if (*s == '(') { |
| 8699 | s = scan_str(s,!!PL_madskills,FALSE,FALSE, FALSE); |
| 8700 | if (!s) |
| 8701 | Perl_croak(aTHX_ "Prototype not terminated"); |
| 8702 | (void)validate_proto(PL_subname, PL_lex_stuff, ckWARN(WARN_ILLEGALPROTO)); |
| 8703 | have_proto = TRUE; |
| 8704 | |
| 8705 | #ifdef PERL_MAD |
| 8706 | start_force(0); |
| 8707 | CURMAD('q', PL_thisopen); |
| 8708 | CURMAD('_', tmpwhite); |
| 8709 | CURMAD('=', PL_thisstuff); |
| 8710 | CURMAD('Q', PL_thisclose); |
| 8711 | NEXTVAL_NEXTTOKE.opval = |
| 8712 | (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff); |
| 8713 | PL_lex_stuff = NULL; |
| 8714 | force_next(THING); |
| 8715 | |
| 8716 | s = SKIPSPACE2(s,tmpwhite); |
| 8717 | #else |
| 8718 | s = skipspace(s); |
| 8719 | #endif |
| 8720 | } |
| 8721 | else |
| 8722 | have_proto = FALSE; |
| 8723 | |
| 8724 | if (*s == ':' && s[1] != ':') |
| 8725 | PL_expect = attrful; |
| 8726 | else if (*s != '{' && key == KEY_sub) { |
| 8727 | if (!have_name) |
| 8728 | Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine"); |
| 8729 | else if (*s != ';' && *s != '}') |
| 8730 | Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname)); |
| 8731 | } |
| 8732 | |
| 8733 | #ifdef PERL_MAD |
| 8734 | start_force(0); |
| 8735 | if (tmpwhite) { |
| 8736 | if (PL_madskills) |
| 8737 | curmad('^', newSVpvs("")); |
| 8738 | CURMAD('_', tmpwhite); |
| 8739 | } |
| 8740 | force_next(0); |
| 8741 | |
| 8742 | PL_thistoken = subtoken; |
| 8743 | PERL_UNUSED_VAR(have_proto); |
| 8744 | #else |
| 8745 | if (have_proto) { |
| 8746 | NEXTVAL_NEXTTOKE.opval = |
| 8747 | (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff); |
| 8748 | PL_lex_stuff = NULL; |
| 8749 | force_next(THING); |
| 8750 | } |
| 8751 | #endif |
| 8752 | if (!have_name) { |
| 8753 | if (PL_curstash) |
| 8754 | sv_setpvs(PL_subname, "__ANON__"); |
| 8755 | else |
| 8756 | sv_setpvs(PL_subname, "__ANON__::__ANON__"); |
| 8757 | TOKEN(ANONSUB); |
| 8758 | } |
| 8759 | #ifndef PERL_MAD |
| 8760 | force_ident_maybe_lex('&'); |
| 8761 | #endif |
| 8762 | TOKEN(SUB); |
| 8763 | } |
| 8764 | |
| 8765 | case KEY_system: |
| 8766 | LOP(OP_SYSTEM,XREF); |
| 8767 | |
| 8768 | case KEY_symlink: |
| 8769 | LOP(OP_SYMLINK,XTERM); |
| 8770 | |
| 8771 | case KEY_syscall: |
| 8772 | LOP(OP_SYSCALL,XTERM); |
| 8773 | |
| 8774 | case KEY_sysopen: |
| 8775 | LOP(OP_SYSOPEN,XTERM); |
| 8776 | |
| 8777 | case KEY_sysseek: |
| 8778 | LOP(OP_SYSSEEK,XTERM); |
| 8779 | |
| 8780 | case KEY_sysread: |
| 8781 | LOP(OP_SYSREAD,XTERM); |
| 8782 | |
| 8783 | case KEY_syswrite: |
| 8784 | LOP(OP_SYSWRITE,XTERM); |
| 8785 | |
| 8786 | case KEY_tr: |
| 8787 | case KEY_y: |
| 8788 | s = scan_trans(s); |
| 8789 | TERM(sublex_start()); |
| 8790 | |
| 8791 | case KEY_tell: |
| 8792 | UNI(OP_TELL); |
| 8793 | |
| 8794 | case KEY_telldir: |
| 8795 | UNI(OP_TELLDIR); |
| 8796 | |
| 8797 | case KEY_tie: |
| 8798 | LOP(OP_TIE,XTERM); |
| 8799 | |
| 8800 | case KEY_tied: |
| 8801 | UNI(OP_TIED); |
| 8802 | |
| 8803 | case KEY_time: |
| 8804 | FUN0(OP_TIME); |
| 8805 | |
| 8806 | case KEY_times: |
| 8807 | FUN0(OP_TMS); |
| 8808 | |
| 8809 | case KEY_truncate: |
| 8810 | LOP(OP_TRUNCATE,XTERM); |
| 8811 | |
| 8812 | case KEY_uc: |
| 8813 | UNI(OP_UC); |
| 8814 | |
| 8815 | case KEY_ucfirst: |
| 8816 | UNI(OP_UCFIRST); |
| 8817 | |
| 8818 | case KEY_untie: |
| 8819 | UNI(OP_UNTIE); |
| 8820 | |
| 8821 | case KEY_until: |
| 8822 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR) |
| 8823 | return REPORT(0); |
| 8824 | pl_yylval.ival = CopLINE(PL_curcop); |
| 8825 | OPERATOR(UNTIL); |
| 8826 | |
| 8827 | case KEY_unless: |
| 8828 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR) |
| 8829 | return REPORT(0); |
| 8830 | pl_yylval.ival = CopLINE(PL_curcop); |
| 8831 | OPERATOR(UNLESS); |
| 8832 | |
| 8833 | case KEY_unlink: |
| 8834 | LOP(OP_UNLINK,XTERM); |
| 8835 | |
| 8836 | case KEY_undef: |
| 8837 | UNIDOR(OP_UNDEF); |
| 8838 | |
| 8839 | case KEY_unpack: |
| 8840 | LOP(OP_UNPACK,XTERM); |
| 8841 | |
| 8842 | case KEY_utime: |
| 8843 | LOP(OP_UTIME,XTERM); |
| 8844 | |
| 8845 | case KEY_umask: |
| 8846 | UNIDOR(OP_UMASK); |
| 8847 | |
| 8848 | case KEY_unshift: |
| 8849 | LOP(OP_UNSHIFT,XTERM); |
| 8850 | |
| 8851 | case KEY_use: |
| 8852 | s = tokenize_use(1, s); |
| 8853 | OPERATOR(USE); |
| 8854 | |
| 8855 | case KEY_values: |
| 8856 | UNI(OP_VALUES); |
| 8857 | |
| 8858 | case KEY_vec: |
| 8859 | LOP(OP_VEC,XTERM); |
| 8860 | |
| 8861 | case KEY_when: |
| 8862 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR) |
| 8863 | return REPORT(0); |
| 8864 | pl_yylval.ival = CopLINE(PL_curcop); |
| 8865 | Perl_ck_warner_d(aTHX_ |
| 8866 | packWARN(WARN_EXPERIMENTAL__SMARTMATCH), |
| 8867 | "when is experimental"); |
| 8868 | OPERATOR(WHEN); |
| 8869 | |
| 8870 | case KEY_while: |
| 8871 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_NONEXPR) |
| 8872 | return REPORT(0); |
| 8873 | pl_yylval.ival = CopLINE(PL_curcop); |
| 8874 | OPERATOR(WHILE); |
| 8875 | |
| 8876 | case KEY_warn: |
| 8877 | PL_hints |= HINT_BLOCK_SCOPE; |
| 8878 | LOP(OP_WARN,XTERM); |
| 8879 | |
| 8880 | case KEY_wait: |
| 8881 | FUN0(OP_WAIT); |
| 8882 | |
| 8883 | case KEY_waitpid: |
| 8884 | LOP(OP_WAITPID,XTERM); |
| 8885 | |
| 8886 | case KEY_wantarray: |
| 8887 | FUN0(OP_WANTARRAY); |
| 8888 | |
| 8889 | case KEY_write: |
| 8890 | #ifdef EBCDIC |
| 8891 | { |
| 8892 | char ctl_l[2]; |
| 8893 | ctl_l[0] = toCTRL('L'); |
| 8894 | ctl_l[1] = '\0'; |
| 8895 | gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV); |
| 8896 | } |
| 8897 | #else |
| 8898 | /* Make sure $^L is defined */ |
| 8899 | gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV); |
| 8900 | #endif |
| 8901 | UNI(OP_ENTERWRITE); |
| 8902 | |
| 8903 | case KEY_x: |
| 8904 | if (PL_expect == XOPERATOR) { |
| 8905 | if (*s == '=' && !PL_lex_allbrackets && |
| 8906 | PL_lex_fakeeof >= LEX_FAKEEOF_ASSIGN) |
| 8907 | return REPORT(0); |
| 8908 | Mop(OP_REPEAT); |
| 8909 | } |
| 8910 | check_uni(); |
| 8911 | goto just_a_word; |
| 8912 | |
| 8913 | case KEY_xor: |
| 8914 | if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_LOWLOGIC) |
| 8915 | return REPORT(0); |
| 8916 | pl_yylval.ival = OP_XOR; |
| 8917 | OPERATOR(OROP); |
| 8918 | } |
| 8919 | }} |
| 8920 | } |
| 8921 | #ifdef __SC__ |
| 8922 | #pragma segment Main |
| 8923 | #endif |
| 8924 | |
| 8925 | /* |
| 8926 | S_pending_ident |
| 8927 | |
| 8928 | Looks up an identifier in the pad or in a package |
| 8929 | |
| 8930 | Returns: |
| 8931 | PRIVATEREF if this is a lexical name. |
| 8932 | WORD if this belongs to a package. |
| 8933 | |
| 8934 | Structure: |
| 8935 | if we're in a my declaration |
| 8936 | croak if they tried to say my($foo::bar) |
| 8937 | build the ops for a my() declaration |
| 8938 | if it's an access to a my() variable |
| 8939 | build ops for access to a my() variable |
| 8940 | if in a dq string, and they've said @foo and we can't find @foo |
| 8941 | warn |
| 8942 | build ops for a bareword |
| 8943 | */ |
| 8944 | |
| 8945 | static int |
| 8946 | S_pending_ident(pTHX) |
| 8947 | { |
| 8948 | dVAR; |
| 8949 | PADOFFSET tmp = 0; |
| 8950 | const char pit = (char)pl_yylval.ival; |
| 8951 | const STRLEN tokenbuf_len = strlen(PL_tokenbuf); |
| 8952 | /* All routes through this function want to know if there is a colon. */ |
| 8953 | const char *const has_colon = (const char*) memchr (PL_tokenbuf, ':', tokenbuf_len); |
| 8954 | |
| 8955 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
| 8956 | "### Pending identifier '%s'\n", PL_tokenbuf); }); |
| 8957 | |
| 8958 | /* if we're in a my(), we can't allow dynamics here. |
| 8959 | $foo'bar has already been turned into $foo::bar, so |
| 8960 | just check for colons. |
| 8961 | |
| 8962 | if it's a legal name, the OP is a PADANY. |
| 8963 | */ |
| 8964 | if (PL_in_my) { |
| 8965 | if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */ |
| 8966 | if (has_colon) |
| 8967 | yyerror_pv(Perl_form(aTHX_ "No package name allowed for " |
| 8968 | "variable %s in \"our\"", |
| 8969 | PL_tokenbuf), UTF ? SVf_UTF8 : 0); |
| 8970 | tmp = allocmy(PL_tokenbuf, tokenbuf_len, UTF ? SVf_UTF8 : 0); |
| 8971 | } |
| 8972 | else { |
| 8973 | if (has_colon) |
| 8974 | yyerror_pv(Perl_form(aTHX_ PL_no_myglob, |
| 8975 | PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf), |
| 8976 | UTF ? SVf_UTF8 : 0); |
| 8977 | |
| 8978 | pl_yylval.opval = newOP(OP_PADANY, 0); |
| 8979 | pl_yylval.opval->op_targ = allocmy(PL_tokenbuf, tokenbuf_len, |
| 8980 | UTF ? SVf_UTF8 : 0); |
| 8981 | return PRIVATEREF; |
| 8982 | } |
| 8983 | } |
| 8984 | |
| 8985 | /* |
| 8986 | build the ops for accesses to a my() variable. |
| 8987 | */ |
| 8988 | |
| 8989 | if (!has_colon) { |
| 8990 | if (!PL_in_my) |
| 8991 | tmp = pad_findmy_pvn(PL_tokenbuf, tokenbuf_len, |
| 8992 | UTF ? SVf_UTF8 : 0); |
| 8993 | if (tmp != NOT_IN_PAD) { |
| 8994 | /* might be an "our" variable" */ |
| 8995 | if (PAD_COMPNAME_FLAGS_isOUR(tmp)) { |
| 8996 | /* build ops for a bareword */ |
| 8997 | HV * const stash = PAD_COMPNAME_OURSTASH(tmp); |
| 8998 | HEK * const stashname = HvNAME_HEK(stash); |
| 8999 | SV * const sym = newSVhek(stashname); |
| 9000 | sv_catpvs(sym, "::"); |
| 9001 | sv_catpvn_flags(sym, PL_tokenbuf+1, tokenbuf_len - 1, (UTF ? SV_CATUTF8 : SV_CATBYTES )); |
| 9002 | pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym); |
| 9003 | pl_yylval.opval->op_private = OPpCONST_ENTERED; |
| 9004 | if (pit != '&') |
| 9005 | gv_fetchsv(sym, |
| 9006 | (PL_in_eval |
| 9007 | ? (GV_ADDMULTI | GV_ADDINEVAL) |
| 9008 | : GV_ADDMULTI |
| 9009 | ), |
| 9010 | ((PL_tokenbuf[0] == '$') ? SVt_PV |
| 9011 | : (PL_tokenbuf[0] == '@') ? SVt_PVAV |
| 9012 | : SVt_PVHV)); |
| 9013 | return WORD; |
| 9014 | } |
| 9015 | |
| 9016 | pl_yylval.opval = newOP(OP_PADANY, 0); |
| 9017 | pl_yylval.opval->op_targ = tmp; |
| 9018 | return PRIVATEREF; |
| 9019 | } |
| 9020 | } |
| 9021 | |
| 9022 | /* |
| 9023 | Whine if they've said @foo in a doublequoted string, |
| 9024 | and @foo isn't a variable we can find in the symbol |
| 9025 | table. |
| 9026 | */ |
| 9027 | if (ckWARN(WARN_AMBIGUOUS) && |
| 9028 | pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) { |
| 9029 | GV *const gv = gv_fetchpvn_flags(PL_tokenbuf + 1, tokenbuf_len - 1, |
| 9030 | ( UTF ? SVf_UTF8 : 0 ), SVt_PVAV); |
| 9031 | if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv))) |
| 9032 | /* DO NOT warn for @- and @+ */ |
| 9033 | && !( PL_tokenbuf[2] == '\0' && |
| 9034 | ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' )) |
| 9035 | ) |
| 9036 | { |
| 9037 | /* Downgraded from fatal to warning 20000522 mjd */ |
| 9038 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 9039 | "Possible unintended interpolation of %"UTF8f |
| 9040 | " in string", |
| 9041 | UTF8fARG(UTF, tokenbuf_len, PL_tokenbuf)); |
| 9042 | } |
| 9043 | } |
| 9044 | |
| 9045 | /* build ops for a bareword */ |
| 9046 | pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
| 9047 | newSVpvn_flags(PL_tokenbuf + 1, |
| 9048 | tokenbuf_len - 1, |
| 9049 | UTF ? SVf_UTF8 : 0 )); |
| 9050 | pl_yylval.opval->op_private = OPpCONST_ENTERED; |
| 9051 | if (pit != '&') |
| 9052 | gv_fetchpvn_flags(PL_tokenbuf+1, tokenbuf_len - 1, |
| 9053 | (PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD) |
| 9054 | | ( UTF ? SVf_UTF8 : 0 ), |
| 9055 | ((PL_tokenbuf[0] == '$') ? SVt_PV |
| 9056 | : (PL_tokenbuf[0] == '@') ? SVt_PVAV |
| 9057 | : SVt_PVHV)); |
| 9058 | return WORD; |
| 9059 | } |
| 9060 | |
| 9061 | STATIC void |
| 9062 | S_checkcomma(pTHX_ const char *s, const char *name, const char *what) |
| 9063 | { |
| 9064 | dVAR; |
| 9065 | |
| 9066 | PERL_ARGS_ASSERT_CHECKCOMMA; |
| 9067 | |
| 9068 | if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */ |
| 9069 | if (ckWARN(WARN_SYNTAX)) { |
| 9070 | int level = 1; |
| 9071 | const char *w; |
| 9072 | for (w = s+2; *w && level; w++) { |
| 9073 | if (*w == '(') |
| 9074 | ++level; |
| 9075 | else if (*w == ')') |
| 9076 | --level; |
| 9077 | } |
| 9078 | while (isSPACE(*w)) |
| 9079 | ++w; |
| 9080 | /* the list of chars below is for end of statements or |
| 9081 | * block / parens, boolean operators (&&, ||, //) and branch |
| 9082 | * constructs (or, and, if, until, unless, while, err, for). |
| 9083 | * Not a very solid hack... */ |
| 9084 | if (!*w || !strchr(";&/|})]oaiuwef!=", *w)) |
| 9085 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 9086 | "%s (...) interpreted as function",name); |
| 9087 | } |
| 9088 | } |
| 9089 | while (s < PL_bufend && isSPACE(*s)) |
| 9090 | s++; |
| 9091 | if (*s == '(') |
| 9092 | s++; |
| 9093 | while (s < PL_bufend && isSPACE(*s)) |
| 9094 | s++; |
| 9095 | if (isIDFIRST_lazy_if(s,UTF)) { |
| 9096 | const char * const w = s; |
| 9097 | s += UTF ? UTF8SKIP(s) : 1; |
| 9098 | while (isWORDCHAR_lazy_if(s,UTF)) |
| 9099 | s += UTF ? UTF8SKIP(s) : 1; |
| 9100 | while (s < PL_bufend && isSPACE(*s)) |
| 9101 | s++; |
| 9102 | if (*s == ',') { |
| 9103 | GV* gv; |
| 9104 | if (keyword(w, s - w, 0)) |
| 9105 | return; |
| 9106 | |
| 9107 | gv = gv_fetchpvn_flags(w, s - w, ( UTF ? SVf_UTF8 : 0 ), SVt_PVCV); |
| 9108 | if (gv && GvCVu(gv)) |
| 9109 | return; |
| 9110 | Perl_croak(aTHX_ "No comma allowed after %s", what); |
| 9111 | } |
| 9112 | } |
| 9113 | } |
| 9114 | |
| 9115 | /* S_new_constant(): do any overload::constant lookup. |
| 9116 | |
| 9117 | Either returns sv, or mortalizes/frees sv and returns a new SV*. |
| 9118 | Best used as sv=new_constant(..., sv, ...). |
| 9119 | If s, pv are NULL, calls subroutine with one argument, |
| 9120 | and <type> is used with error messages only. |
| 9121 | <type> is assumed to be well formed UTF-8 */ |
| 9122 | |
| 9123 | STATIC SV * |
| 9124 | S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, STRLEN keylen, |
| 9125 | SV *sv, SV *pv, const char *type, STRLEN typelen) |
| 9126 | { |
| 9127 | dVAR; dSP; |
| 9128 | HV * table = GvHV(PL_hintgv); /* ^H */ |
| 9129 | SV *res; |
| 9130 | SV *errsv = NULL; |
| 9131 | SV **cvp; |
| 9132 | SV *cv, *typesv; |
| 9133 | const char *why1 = "", *why2 = "", *why3 = ""; |
| 9134 | |
| 9135 | PERL_ARGS_ASSERT_NEW_CONSTANT; |
| 9136 | /* We assume that this is true: */ |
| 9137 | if (*key == 'c') { assert (strEQ(key, "charnames")); } |
| 9138 | assert(type || s); |
| 9139 | |
| 9140 | /* charnames doesn't work well if there have been errors found */ |
| 9141 | if (PL_error_count > 0 && *key == 'c') |
| 9142 | { |
| 9143 | SvREFCNT_dec_NN(sv); |
| 9144 | return &PL_sv_undef; |
| 9145 | } |
| 9146 | |
| 9147 | sv_2mortal(sv); /* Parent created it permanently */ |
| 9148 | if (!table |
| 9149 | || ! (PL_hints & HINT_LOCALIZE_HH) |
| 9150 | || ! (cvp = hv_fetch(table, key, keylen, FALSE)) |
| 9151 | || ! SvOK(*cvp)) |
| 9152 | { |
| 9153 | char *msg; |
| 9154 | |
| 9155 | /* Here haven't found what we're looking for. If it is charnames, |
| 9156 | * perhaps it needs to be loaded. Try doing that before giving up */ |
| 9157 | if (*key == 'c') { |
| 9158 | Perl_load_module(aTHX_ |
| 9159 | 0, |
| 9160 | newSVpvs("_charnames"), |
| 9161 | /* version parameter; no need to specify it, as if |
| 9162 | * we get too early a version, will fail anyway, |
| 9163 | * not being able to find '_charnames' */ |
| 9164 | NULL, |
| 9165 | newSVpvs(":full"), |
| 9166 | newSVpvs(":short"), |
| 9167 | NULL); |
| 9168 | SPAGAIN; |
| 9169 | table = GvHV(PL_hintgv); |
| 9170 | if (table |
| 9171 | && (PL_hints & HINT_LOCALIZE_HH) |
| 9172 | && (cvp = hv_fetch(table, key, keylen, FALSE)) |
| 9173 | && SvOK(*cvp)) |
| 9174 | { |
| 9175 | goto now_ok; |
| 9176 | } |
| 9177 | } |
| 9178 | if (!table || !(PL_hints & HINT_LOCALIZE_HH)) { |
| 9179 | msg = Perl_form(aTHX_ |
| 9180 | "Constant(%.*s) unknown", |
| 9181 | (int)(type ? typelen : len), |
| 9182 | (type ? type: s)); |
| 9183 | } |
| 9184 | else { |
| 9185 | why1 = "$^H{"; |
| 9186 | why2 = key; |
| 9187 | why3 = "} is not defined"; |
| 9188 | report: |
| 9189 | if (*key == 'c') { |
| 9190 | msg = Perl_form(aTHX_ |
| 9191 | /* The +3 is for '\N{'; -4 for that, plus '}' */ |
| 9192 | "Unknown charname '%.*s'", (int)typelen - 4, type + 3 |
| 9193 | ); |
| 9194 | } |
| 9195 | else { |
| 9196 | msg = Perl_form(aTHX_ "Constant(%.*s): %s%s%s", |
| 9197 | (int)(type ? typelen : len), |
| 9198 | (type ? type: s), why1, why2, why3); |
| 9199 | } |
| 9200 | } |
| 9201 | yyerror_pv(msg, UTF ? SVf_UTF8 : 0); |
| 9202 | return SvREFCNT_inc_simple_NN(sv); |
| 9203 | } |
| 9204 | now_ok: |
| 9205 | cv = *cvp; |
| 9206 | if (!pv && s) |
| 9207 | pv = newSVpvn_flags(s, len, SVs_TEMP); |
| 9208 | if (type && pv) |
| 9209 | typesv = newSVpvn_flags(type, typelen, SVs_TEMP); |
| 9210 | else |
| 9211 | typesv = &PL_sv_undef; |
| 9212 | |
| 9213 | PUSHSTACKi(PERLSI_OVERLOAD); |
| 9214 | ENTER ; |
| 9215 | SAVETMPS; |
| 9216 | |
| 9217 | PUSHMARK(SP) ; |
| 9218 | EXTEND(sp, 3); |
| 9219 | if (pv) |
| 9220 | PUSHs(pv); |
| 9221 | PUSHs(sv); |
| 9222 | if (pv) |
| 9223 | PUSHs(typesv); |
| 9224 | PUTBACK; |
| 9225 | call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL)); |
| 9226 | |
| 9227 | SPAGAIN ; |
| 9228 | |
| 9229 | /* Check the eval first */ |
| 9230 | if (!PL_in_eval && ((errsv = ERRSV), SvTRUE_NN(errsv))) { |
| 9231 | STRLEN errlen; |
| 9232 | const char * errstr; |
| 9233 | sv_catpvs(errsv, "Propagated"); |
| 9234 | errstr = SvPV_const(errsv, errlen); |
| 9235 | yyerror_pvn(errstr, errlen, 0); /* Duplicates the message inside eval */ |
| 9236 | (void)POPs; |
| 9237 | res = SvREFCNT_inc_simple_NN(sv); |
| 9238 | } |
| 9239 | else { |
| 9240 | res = POPs; |
| 9241 | SvREFCNT_inc_simple_void_NN(res); |
| 9242 | } |
| 9243 | |
| 9244 | PUTBACK ; |
| 9245 | FREETMPS ; |
| 9246 | LEAVE ; |
| 9247 | POPSTACK; |
| 9248 | |
| 9249 | if (!SvOK(res)) { |
| 9250 | why1 = "Call to &{$^H{"; |
| 9251 | why2 = key; |
| 9252 | why3 = "}} did not return a defined value"; |
| 9253 | sv = res; |
| 9254 | (void)sv_2mortal(sv); |
| 9255 | goto report; |
| 9256 | } |
| 9257 | |
| 9258 | return res; |
| 9259 | } |
| 9260 | |
| 9261 | PERL_STATIC_INLINE void |
| 9262 | S_parse_ident(pTHX_ char **s, char **d, char * const e, int allow_package, bool is_utf8) { |
| 9263 | dVAR; |
| 9264 | PERL_ARGS_ASSERT_PARSE_IDENT; |
| 9265 | |
| 9266 | for (;;) { |
| 9267 | if (*d >= e) |
| 9268 | Perl_croak(aTHX_ "%s", ident_too_long); |
| 9269 | if (is_utf8 && isIDFIRST_utf8((U8*)*s)) { |
| 9270 | /* The UTF-8 case must come first, otherwise things |
| 9271 | * like c\N{COMBINING TILDE} would start failing, as the |
| 9272 | * isWORDCHAR_A case below would gobble the 'c' up. |
| 9273 | */ |
| 9274 | |
| 9275 | char *t = *s + UTF8SKIP(*s); |
| 9276 | while (isIDCONT_utf8((U8*)t)) |
| 9277 | t += UTF8SKIP(t); |
| 9278 | if (*d + (t - *s) > e) |
| 9279 | Perl_croak(aTHX_ "%s", ident_too_long); |
| 9280 | Copy(*s, *d, t - *s, char); |
| 9281 | *d += t - *s; |
| 9282 | *s = t; |
| 9283 | } |
| 9284 | else if ( isWORDCHAR_A(**s) ) { |
| 9285 | do { |
| 9286 | *(*d)++ = *(*s)++; |
| 9287 | } while isWORDCHAR_A(**s); |
| 9288 | } |
| 9289 | else if (allow_package && **s == '\'' && isIDFIRST_lazy_if(*s+1,is_utf8)) { |
| 9290 | *(*d)++ = ':'; |
| 9291 | *(*d)++ = ':'; |
| 9292 | (*s)++; |
| 9293 | } |
| 9294 | else if (allow_package && **s == ':' && (*s)[1] == ':' |
| 9295 | /* Disallow things like Foo::$bar. For the curious, this is |
| 9296 | * the code path that triggers the "Bad name after" warning |
| 9297 | * when looking for barewords. |
| 9298 | */ |
| 9299 | && (*s)[2] != '$') { |
| 9300 | *(*d)++ = *(*s)++; |
| 9301 | *(*d)++ = *(*s)++; |
| 9302 | } |
| 9303 | else |
| 9304 | break; |
| 9305 | } |
| 9306 | return; |
| 9307 | } |
| 9308 | |
| 9309 | /* Returns a NUL terminated string, with the length of the string written to |
| 9310 | *slp |
| 9311 | */ |
| 9312 | STATIC char * |
| 9313 | S_scan_word(pTHX_ char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp) |
| 9314 | { |
| 9315 | dVAR; |
| 9316 | char *d = dest; |
| 9317 | char * const e = d + destlen - 3; /* two-character token, ending NUL */ |
| 9318 | bool is_utf8 = cBOOL(UTF); |
| 9319 | |
| 9320 | PERL_ARGS_ASSERT_SCAN_WORD; |
| 9321 | |
| 9322 | parse_ident(&s, &d, e, allow_package, is_utf8); |
| 9323 | *d = '\0'; |
| 9324 | *slp = d - dest; |
| 9325 | return s; |
| 9326 | } |
| 9327 | |
| 9328 | STATIC char * |
| 9329 | S_scan_ident(pTHX_ char *s, const char *send, char *dest, STRLEN destlen, I32 ck_uni) |
| 9330 | { |
| 9331 | dVAR; |
| 9332 | char *bracket = NULL; |
| 9333 | char funny = *s++; |
| 9334 | char *d = dest; |
| 9335 | char * const e = d + destlen - 3; /* two-character token, ending NUL */ |
| 9336 | bool is_utf8 = cBOOL(UTF); |
| 9337 | |
| 9338 | PERL_ARGS_ASSERT_SCAN_IDENT; |
| 9339 | |
| 9340 | if (isSPACE(*s)) |
| 9341 | s = PEEKSPACE(s); |
| 9342 | if (isDIGIT(*s)) { |
| 9343 | while (isDIGIT(*s)) { |
| 9344 | if (d >= e) |
| 9345 | Perl_croak(aTHX_ "%s", ident_too_long); |
| 9346 | *d++ = *s++; |
| 9347 | } |
| 9348 | } |
| 9349 | else { |
| 9350 | parse_ident(&s, &d, e, 1, is_utf8); |
| 9351 | } |
| 9352 | *d = '\0'; |
| 9353 | d = dest; |
| 9354 | if (*d) { |
| 9355 | /* Either a digit variable, or parse_ident() found an identifier |
| 9356 | (anything valid as a bareword), so job done and return. */ |
| 9357 | if (PL_lex_state != LEX_NORMAL) |
| 9358 | PL_lex_state = LEX_INTERPENDMAYBE; |
| 9359 | return s; |
| 9360 | } |
| 9361 | if (*s == '$' && s[1] && |
| 9362 | (isIDFIRST_lazy_if(s+1,is_utf8) |
| 9363 | || isDIGIT_A((U8)s[1]) |
| 9364 | || s[1] == '$' |
| 9365 | || s[1] == '{' |
| 9366 | || strnEQ(s+1,"::",2)) ) |
| 9367 | { |
| 9368 | /* Dereferencing a value in a scalar variable. |
| 9369 | The alternatives are different syntaxes for a scalar variable. |
| 9370 | Using ' as a leading package separator isn't allowed. :: is. */ |
| 9371 | return s; |
| 9372 | } |
| 9373 | /* Handle the opening { of @{...}, &{...}, *{...}, %{...}, ${...} */ |
| 9374 | if (*s == '{') { |
| 9375 | bracket = s; |
| 9376 | s++; |
| 9377 | while (s < send && SPACE_OR_TAB(*s)) |
| 9378 | s++; |
| 9379 | } |
| 9380 | |
| 9381 | #define VALID_LEN_ONE_IDENT(d, u) (isPUNCT_A((U8)(d)) \ |
| 9382 | || isCNTRL_A((U8)(d)) \ |
| 9383 | || isDIGIT_A((U8)(d)) \ |
| 9384 | || (!(u) && !UTF8_IS_INVARIANT((U8)(d)))) |
| 9385 | if (s < send |
| 9386 | && (isIDFIRST_lazy_if(s, is_utf8) || VALID_LEN_ONE_IDENT(*s, is_utf8))) |
| 9387 | { |
| 9388 | if (is_utf8) { |
| 9389 | const STRLEN skip = UTF8SKIP(s); |
| 9390 | STRLEN i; |
| 9391 | d[skip] = '\0'; |
| 9392 | for ( i = 0; i < skip; i++ ) |
| 9393 | d[i] = *s++; |
| 9394 | } |
| 9395 | else { |
| 9396 | *d = *s++; |
| 9397 | d[1] = '\0'; |
| 9398 | } |
| 9399 | } |
| 9400 | /* Convert $^F, ${^F} and the ^F of ${^FOO} to control characters */ |
| 9401 | if (*d == '^' && *s && isCONTROLVAR(*s)) { |
| 9402 | *d = toCTRL(*s); |
| 9403 | s++; |
| 9404 | } |
| 9405 | /* Warn about ambiguous code after unary operators if {...} notation isn't |
| 9406 | used. There's no difference in ambiguity; it's merely a heuristic |
| 9407 | about when not to warn. */ |
| 9408 | else if (ck_uni && !bracket) |
| 9409 | check_uni(); |
| 9410 | if (bracket) { |
| 9411 | /* If we were processing {...} notation then... */ |
| 9412 | if (isIDFIRST_lazy_if(d,is_utf8)) { |
| 9413 | /* if it starts as a valid identifier, assume that it is one. |
| 9414 | (the later check for } being at the expected point will trap |
| 9415 | cases where this doesn't pan out.) */ |
| 9416 | d += is_utf8 ? UTF8SKIP(d) : 1; |
| 9417 | parse_ident(&s, &d, e, 1, is_utf8); |
| 9418 | *d = '\0'; |
| 9419 | while (s < send && SPACE_OR_TAB(*s)) |
| 9420 | s++; |
| 9421 | if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) { |
| 9422 | /* ${foo[0]} and ${foo{bar}} notation. */ |
| 9423 | if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) { |
| 9424 | const char * const brack = |
| 9425 | (const char *) |
| 9426 | ((*s == '[') ? "[...]" : "{...}"); |
| 9427 | /* diag_listed_as: Ambiguous use of %c{%s[...]} resolved to %c%s[...] */ |
| 9428 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 9429 | "Ambiguous use of %c{%s%s} resolved to %c%s%s", |
| 9430 | funny, dest, brack, funny, dest, brack); |
| 9431 | } |
| 9432 | bracket++; |
| 9433 | PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK); |
| 9434 | PL_lex_allbrackets++; |
| 9435 | return s; |
| 9436 | } |
| 9437 | } |
| 9438 | /* Handle extended ${^Foo} variables |
| 9439 | * 1999-02-27 mjd-perl-patch@plover.com */ |
| 9440 | else if (! isPRINT(*d) /* isCNTRL(d), plus all non-ASCII */ |
| 9441 | && isWORDCHAR(*s)) |
| 9442 | { |
| 9443 | d++; |
| 9444 | while (isWORDCHAR(*s) && d < e) { |
| 9445 | *d++ = *s++; |
| 9446 | } |
| 9447 | if (d >= e) |
| 9448 | Perl_croak(aTHX_ "%s", ident_too_long); |
| 9449 | *d = '\0'; |
| 9450 | } |
| 9451 | |
| 9452 | while (s < send && SPACE_OR_TAB(*s)) |
| 9453 | s++; |
| 9454 | |
| 9455 | /* Expect to find a closing } after consuming any trailing whitespace. |
| 9456 | */ |
| 9457 | if (*s == '}') { |
| 9458 | s++; |
| 9459 | if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) { |
| 9460 | PL_lex_state = LEX_INTERPEND; |
| 9461 | PL_expect = XREF; |
| 9462 | } |
| 9463 | if (PL_lex_state == LEX_NORMAL) { |
| 9464 | if (ckWARN(WARN_AMBIGUOUS) && |
| 9465 | (keyword(dest, d - dest, 0) |
| 9466 | || get_cvn_flags(dest, d - dest, is_utf8 ? SVf_UTF8 : 0))) |
| 9467 | { |
| 9468 | SV *tmp = newSVpvn_flags( dest, d - dest, |
| 9469 | SVs_TEMP | (is_utf8 ? SVf_UTF8 : 0) ); |
| 9470 | if (funny == '#') |
| 9471 | funny = '@'; |
| 9472 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 9473 | "Ambiguous use of %c{%"SVf"} resolved to %c%"SVf, |
| 9474 | funny, tmp, funny, tmp); |
| 9475 | } |
| 9476 | } |
| 9477 | } |
| 9478 | else { |
| 9479 | /* Didn't find the closing } at the point we expected, so restore |
| 9480 | state such that the next thing to process is the opening { and */ |
| 9481 | s = bracket; /* let the parser handle it */ |
| 9482 | *dest = '\0'; |
| 9483 | } |
| 9484 | } |
| 9485 | else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s)) |
| 9486 | PL_lex_state = LEX_INTERPEND; |
| 9487 | return s; |
| 9488 | } |
| 9489 | |
| 9490 | static bool |
| 9491 | S_pmflag(pTHX_ const char* const valid_flags, U32 * pmfl, char** s, char* charset) { |
| 9492 | |
| 9493 | /* Adds, subtracts to/from 'pmfl' based on regex modifier flags found in |
| 9494 | * the parse starting at 's', based on the subset that are valid in this |
| 9495 | * context input to this routine in 'valid_flags'. Advances s. Returns |
| 9496 | * TRUE if the input should be treated as a valid flag, so the next char |
| 9497 | * may be as well; otherwise FALSE. 'charset' should point to a NUL upon |
| 9498 | * first call on the current regex. This routine will set it to any |
| 9499 | * charset modifier found. The caller shouldn't change it. This way, |
| 9500 | * another charset modifier encountered in the parse can be detected as an |
| 9501 | * error, as we have decided to allow only one */ |
| 9502 | |
| 9503 | const char c = **s; |
| 9504 | STRLEN charlen = UTF ? UTF8SKIP(*s) : 1; |
| 9505 | |
| 9506 | if ( charlen != 1 || ! strchr(valid_flags, c) ) { |
| 9507 | if (isWORDCHAR_lazy_if(*s, UTF)) { |
| 9508 | yyerror_pv(Perl_form(aTHX_ "Unknown regexp modifier \"/%.*s\"", (int)charlen, *s), |
| 9509 | UTF ? SVf_UTF8 : 0); |
| 9510 | (*s) += charlen; |
| 9511 | /* Pretend that it worked, so will continue processing before |
| 9512 | * dieing */ |
| 9513 | return TRUE; |
| 9514 | } |
| 9515 | return FALSE; |
| 9516 | } |
| 9517 | |
| 9518 | switch (c) { |
| 9519 | |
| 9520 | CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl); |
| 9521 | case GLOBAL_PAT_MOD: *pmfl |= PMf_GLOBAL; break; |
| 9522 | case CONTINUE_PAT_MOD: *pmfl |= PMf_CONTINUE; break; |
| 9523 | case ONCE_PAT_MOD: *pmfl |= PMf_KEEP; break; |
| 9524 | case KEEPCOPY_PAT_MOD: *pmfl |= RXf_PMf_KEEPCOPY; break; |
| 9525 | case NONDESTRUCT_PAT_MOD: *pmfl |= PMf_NONDESTRUCT; break; |
| 9526 | case LOCALE_PAT_MOD: |
| 9527 | if (*charset) { |
| 9528 | goto multiple_charsets; |
| 9529 | } |
| 9530 | set_regex_charset(pmfl, REGEX_LOCALE_CHARSET); |
| 9531 | *charset = c; |
| 9532 | break; |
| 9533 | case UNICODE_PAT_MOD: |
| 9534 | if (*charset) { |
| 9535 | goto multiple_charsets; |
| 9536 | } |
| 9537 | set_regex_charset(pmfl, REGEX_UNICODE_CHARSET); |
| 9538 | *charset = c; |
| 9539 | break; |
| 9540 | case ASCII_RESTRICT_PAT_MOD: |
| 9541 | if (! *charset) { |
| 9542 | set_regex_charset(pmfl, REGEX_ASCII_RESTRICTED_CHARSET); |
| 9543 | } |
| 9544 | else { |
| 9545 | |
| 9546 | /* Error if previous modifier wasn't an 'a', but if it was, see |
| 9547 | * if, and accept, a second occurrence (only) */ |
| 9548 | if (*charset != 'a' |
| 9549 | || get_regex_charset(*pmfl) |
| 9550 | != REGEX_ASCII_RESTRICTED_CHARSET) |
| 9551 | { |
| 9552 | goto multiple_charsets; |
| 9553 | } |
| 9554 | set_regex_charset(pmfl, REGEX_ASCII_MORE_RESTRICTED_CHARSET); |
| 9555 | } |
| 9556 | *charset = c; |
| 9557 | break; |
| 9558 | case DEPENDS_PAT_MOD: |
| 9559 | if (*charset) { |
| 9560 | goto multiple_charsets; |
| 9561 | } |
| 9562 | set_regex_charset(pmfl, REGEX_DEPENDS_CHARSET); |
| 9563 | *charset = c; |
| 9564 | break; |
| 9565 | } |
| 9566 | |
| 9567 | (*s)++; |
| 9568 | return TRUE; |
| 9569 | |
| 9570 | multiple_charsets: |
| 9571 | if (*charset != c) { |
| 9572 | yyerror(Perl_form(aTHX_ "Regexp modifiers \"/%c\" and \"/%c\" are mutually exclusive", *charset, c)); |
| 9573 | } |
| 9574 | else if (c == 'a') { |
| 9575 | yyerror("Regexp modifier \"/a\" may appear a maximum of twice"); |
| 9576 | } |
| 9577 | else { |
| 9578 | yyerror(Perl_form(aTHX_ "Regexp modifier \"/%c\" may not appear twice", c)); |
| 9579 | } |
| 9580 | |
| 9581 | /* Pretend that it worked, so will continue processing before dieing */ |
| 9582 | (*s)++; |
| 9583 | return TRUE; |
| 9584 | } |
| 9585 | |
| 9586 | STATIC char * |
| 9587 | S_scan_pat(pTHX_ char *start, I32 type) |
| 9588 | { |
| 9589 | dVAR; |
| 9590 | PMOP *pm; |
| 9591 | char *s; |
| 9592 | const char * const valid_flags = |
| 9593 | (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS); |
| 9594 | char charset = '\0'; /* character set modifier */ |
| 9595 | #ifdef PERL_MAD |
| 9596 | char *modstart; |
| 9597 | #endif |
| 9598 | |
| 9599 | PERL_ARGS_ASSERT_SCAN_PAT; |
| 9600 | |
| 9601 | s = scan_str(start,!!PL_madskills,FALSE, (PL_in_eval & EVAL_RE_REPARSING), |
| 9602 | TRUE /* look for escaped bracketed metas */ ); |
| 9603 | |
| 9604 | if (!s) { |
| 9605 | const char * const delimiter = skipspace(start); |
| 9606 | Perl_croak(aTHX_ |
| 9607 | (const char *) |
| 9608 | (*delimiter == '?' |
| 9609 | ? "Search pattern not terminated or ternary operator parsed as search pattern" |
| 9610 | : "Search pattern not terminated" )); |
| 9611 | } |
| 9612 | |
| 9613 | pm = (PMOP*)newPMOP(type, 0); |
| 9614 | if (PL_multi_open == '?') { |
| 9615 | /* This is the only point in the code that sets PMf_ONCE: */ |
| 9616 | pm->op_pmflags |= PMf_ONCE; |
| 9617 | |
| 9618 | /* Hence it's safe to do this bit of PMOP book-keeping here, which |
| 9619 | allows us to restrict the list needed by reset to just the ?? |
| 9620 | matches. */ |
| 9621 | assert(type != OP_TRANS); |
| 9622 | if (PL_curstash) { |
| 9623 | MAGIC *mg = mg_find((const SV *)PL_curstash, PERL_MAGIC_symtab); |
| 9624 | U32 elements; |
| 9625 | if (!mg) { |
| 9626 | mg = sv_magicext(MUTABLE_SV(PL_curstash), 0, PERL_MAGIC_symtab, 0, 0, |
| 9627 | 0); |
| 9628 | } |
| 9629 | elements = mg->mg_len / sizeof(PMOP**); |
| 9630 | Renewc(mg->mg_ptr, elements + 1, PMOP*, char); |
| 9631 | ((PMOP**)mg->mg_ptr) [elements++] = pm; |
| 9632 | mg->mg_len = elements * sizeof(PMOP**); |
| 9633 | PmopSTASH_set(pm,PL_curstash); |
| 9634 | } |
| 9635 | } |
| 9636 | #ifdef PERL_MAD |
| 9637 | modstart = s; |
| 9638 | #endif |
| 9639 | |
| 9640 | /* if qr/...(?{..}).../, then need to parse the pattern within a new |
| 9641 | * anon CV. False positives like qr/[(?{]/ are harmless */ |
| 9642 | |
| 9643 | if (type == OP_QR) { |
| 9644 | STRLEN len; |
| 9645 | char *e, *p = SvPV(PL_lex_stuff, len); |
| 9646 | e = p + len; |
| 9647 | for (; p < e; p++) { |
| 9648 | if (p[0] == '(' && p[1] == '?' |
| 9649 | && (p[2] == '{' || (p[2] == '?' && p[3] == '{'))) |
| 9650 | { |
| 9651 | pm->op_pmflags |= PMf_HAS_CV; |
| 9652 | break; |
| 9653 | } |
| 9654 | } |
| 9655 | pm->op_pmflags |= PMf_IS_QR; |
| 9656 | } |
| 9657 | |
| 9658 | while (*s && S_pmflag(aTHX_ valid_flags, &(pm->op_pmflags), &s, &charset)) {}; |
| 9659 | #ifdef PERL_MAD |
| 9660 | if (PL_madskills && modstart != s) { |
| 9661 | SV* tmptoken = newSVpvn(modstart, s - modstart); |
| 9662 | append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0); |
| 9663 | } |
| 9664 | #endif |
| 9665 | /* issue a warning if /c is specified,but /g is not */ |
| 9666 | if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)) |
| 9667 | { |
| 9668 | Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP), |
| 9669 | "Use of /c modifier is meaningless without /g" ); |
| 9670 | } |
| 9671 | |
| 9672 | PL_lex_op = (OP*)pm; |
| 9673 | pl_yylval.ival = OP_MATCH; |
| 9674 | return s; |
| 9675 | } |
| 9676 | |
| 9677 | STATIC char * |
| 9678 | S_scan_subst(pTHX_ char *start) |
| 9679 | { |
| 9680 | dVAR; |
| 9681 | char *s; |
| 9682 | PMOP *pm; |
| 9683 | I32 first_start; |
| 9684 | I32 es = 0; |
| 9685 | char charset = '\0'; /* character set modifier */ |
| 9686 | #ifdef PERL_MAD |
| 9687 | char *modstart; |
| 9688 | #endif |
| 9689 | |
| 9690 | PERL_ARGS_ASSERT_SCAN_SUBST; |
| 9691 | |
| 9692 | pl_yylval.ival = OP_NULL; |
| 9693 | |
| 9694 | s = scan_str(start,!!PL_madskills,FALSE,FALSE, |
| 9695 | TRUE /* look for escaped bracketed metas */ ); |
| 9696 | |
| 9697 | if (!s) |
| 9698 | Perl_croak(aTHX_ "Substitution pattern not terminated"); |
| 9699 | |
| 9700 | if (s[-1] == PL_multi_open) |
| 9701 | s--; |
| 9702 | #ifdef PERL_MAD |
| 9703 | if (PL_madskills) { |
| 9704 | CURMAD('q', PL_thisopen); |
| 9705 | CURMAD('_', PL_thiswhite); |
| 9706 | CURMAD('E', PL_thisstuff); |
| 9707 | CURMAD('Q', PL_thisclose); |
| 9708 | PL_realtokenstart = s - SvPVX(PL_linestr); |
| 9709 | } |
| 9710 | #endif |
| 9711 | |
| 9712 | first_start = PL_multi_start; |
| 9713 | s = scan_str(s,!!PL_madskills,FALSE,FALSE, FALSE); |
| 9714 | if (!s) { |
| 9715 | if (PL_lex_stuff) { |
| 9716 | SvREFCNT_dec(PL_lex_stuff); |
| 9717 | PL_lex_stuff = NULL; |
| 9718 | } |
| 9719 | Perl_croak(aTHX_ "Substitution replacement not terminated"); |
| 9720 | } |
| 9721 | PL_multi_start = first_start; /* so whole substitution is taken together */ |
| 9722 | |
| 9723 | pm = (PMOP*)newPMOP(OP_SUBST, 0); |
| 9724 | |
| 9725 | #ifdef PERL_MAD |
| 9726 | if (PL_madskills) { |
| 9727 | CURMAD('z', PL_thisopen); |
| 9728 | CURMAD('R', PL_thisstuff); |
| 9729 | CURMAD('Z', PL_thisclose); |
| 9730 | } |
| 9731 | modstart = s; |
| 9732 | #endif |
| 9733 | |
| 9734 | while (*s) { |
| 9735 | if (*s == EXEC_PAT_MOD) { |
| 9736 | s++; |
| 9737 | es++; |
| 9738 | } |
| 9739 | else if (! S_pmflag(aTHX_ S_PAT_MODS, &(pm->op_pmflags), &s, &charset)) |
| 9740 | { |
| 9741 | break; |
| 9742 | } |
| 9743 | } |
| 9744 | |
| 9745 | #ifdef PERL_MAD |
| 9746 | if (PL_madskills) { |
| 9747 | if (modstart != s) |
| 9748 | curmad('m', newSVpvn(modstart, s - modstart)); |
| 9749 | append_madprops(PL_thismad, (OP*)pm, 0); |
| 9750 | PL_thismad = 0; |
| 9751 | } |
| 9752 | #endif |
| 9753 | if ((pm->op_pmflags & PMf_CONTINUE)) { |
| 9754 | Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" ); |
| 9755 | } |
| 9756 | |
| 9757 | if (es) { |
| 9758 | SV * const repl = newSVpvs(""); |
| 9759 | |
| 9760 | PL_multi_end = 0; |
| 9761 | pm->op_pmflags |= PMf_EVAL; |
| 9762 | while (es-- > 0) { |
| 9763 | if (es) |
| 9764 | sv_catpvs(repl, "eval "); |
| 9765 | else |
| 9766 | sv_catpvs(repl, "do "); |
| 9767 | } |
| 9768 | sv_catpvs(repl, "{"); |
| 9769 | sv_catsv(repl, PL_sublex_info.repl); |
| 9770 | sv_catpvs(repl, "}"); |
| 9771 | SvEVALED_on(repl); |
| 9772 | SvREFCNT_dec(PL_sublex_info.repl); |
| 9773 | PL_sublex_info.repl = repl; |
| 9774 | } |
| 9775 | |
| 9776 | PL_lex_op = (OP*)pm; |
| 9777 | pl_yylval.ival = OP_SUBST; |
| 9778 | return s; |
| 9779 | } |
| 9780 | |
| 9781 | STATIC char * |
| 9782 | S_scan_trans(pTHX_ char *start) |
| 9783 | { |
| 9784 | dVAR; |
| 9785 | char* s; |
| 9786 | OP *o; |
| 9787 | U8 squash; |
| 9788 | U8 del; |
| 9789 | U8 complement; |
| 9790 | bool nondestruct = 0; |
| 9791 | #ifdef PERL_MAD |
| 9792 | char *modstart; |
| 9793 | #endif |
| 9794 | |
| 9795 | PERL_ARGS_ASSERT_SCAN_TRANS; |
| 9796 | |
| 9797 | pl_yylval.ival = OP_NULL; |
| 9798 | |
| 9799 | s = scan_str(start,!!PL_madskills,FALSE,FALSE, FALSE); |
| 9800 | if (!s) |
| 9801 | Perl_croak(aTHX_ "Transliteration pattern not terminated"); |
| 9802 | |
| 9803 | if (s[-1] == PL_multi_open) |
| 9804 | s--; |
| 9805 | #ifdef PERL_MAD |
| 9806 | if (PL_madskills) { |
| 9807 | CURMAD('q', PL_thisopen); |
| 9808 | CURMAD('_', PL_thiswhite); |
| 9809 | CURMAD('E', PL_thisstuff); |
| 9810 | CURMAD('Q', PL_thisclose); |
| 9811 | PL_realtokenstart = s - SvPVX(PL_linestr); |
| 9812 | } |
| 9813 | #endif |
| 9814 | |
| 9815 | s = scan_str(s,!!PL_madskills,FALSE,FALSE, FALSE); |
| 9816 | if (!s) { |
| 9817 | if (PL_lex_stuff) { |
| 9818 | SvREFCNT_dec(PL_lex_stuff); |
| 9819 | PL_lex_stuff = NULL; |
| 9820 | } |
| 9821 | Perl_croak(aTHX_ "Transliteration replacement not terminated"); |
| 9822 | } |
| 9823 | if (PL_madskills) { |
| 9824 | CURMAD('z', PL_thisopen); |
| 9825 | CURMAD('R', PL_thisstuff); |
| 9826 | CURMAD('Z', PL_thisclose); |
| 9827 | } |
| 9828 | |
| 9829 | complement = del = squash = 0; |
| 9830 | #ifdef PERL_MAD |
| 9831 | modstart = s; |
| 9832 | #endif |
| 9833 | while (1) { |
| 9834 | switch (*s) { |
| 9835 | case 'c': |
| 9836 | complement = OPpTRANS_COMPLEMENT; |
| 9837 | break; |
| 9838 | case 'd': |
| 9839 | del = OPpTRANS_DELETE; |
| 9840 | break; |
| 9841 | case 's': |
| 9842 | squash = OPpTRANS_SQUASH; |
| 9843 | break; |
| 9844 | case 'r': |
| 9845 | nondestruct = 1; |
| 9846 | break; |
| 9847 | default: |
| 9848 | goto no_more; |
| 9849 | } |
| 9850 | s++; |
| 9851 | } |
| 9852 | no_more: |
| 9853 | |
| 9854 | o = newPVOP(nondestruct ? OP_TRANSR : OP_TRANS, 0, (char*)NULL); |
| 9855 | o->op_private &= ~OPpTRANS_ALL; |
| 9856 | o->op_private |= del|squash|complement| |
| 9857 | (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)| |
| 9858 | (DO_UTF8(PL_sublex_info.repl) ? OPpTRANS_TO_UTF : 0); |
| 9859 | |
| 9860 | PL_lex_op = o; |
| 9861 | pl_yylval.ival = nondestruct ? OP_TRANSR : OP_TRANS; |
| 9862 | |
| 9863 | #ifdef PERL_MAD |
| 9864 | if (PL_madskills) { |
| 9865 | if (modstart != s) |
| 9866 | curmad('m', newSVpvn(modstart, s - modstart)); |
| 9867 | append_madprops(PL_thismad, o, 0); |
| 9868 | PL_thismad = 0; |
| 9869 | } |
| 9870 | #endif |
| 9871 | |
| 9872 | return s; |
| 9873 | } |
| 9874 | |
| 9875 | /* scan_heredoc |
| 9876 | Takes a pointer to the first < in <<FOO. |
| 9877 | Returns a pointer to the byte following <<FOO. |
| 9878 | |
| 9879 | This function scans a heredoc, which involves different methods |
| 9880 | depending on whether we are in a string eval, quoted construct, etc. |
| 9881 | This is because PL_linestr could containing a single line of input, or |
| 9882 | a whole string being evalled, or the contents of the current quote- |
| 9883 | like operator. |
| 9884 | |
| 9885 | The two basic methods are: |
| 9886 | - Steal lines from the input stream |
| 9887 | - Scan the heredoc in PL_linestr and remove it therefrom |
| 9888 | |
| 9889 | In a file scope or filtered eval, the first method is used; in a |
| 9890 | string eval, the second. |
| 9891 | |
| 9892 | In a quote-like operator, we have to choose between the two, |
| 9893 | depending on where we can find a newline. We peek into outer lex- |
| 9894 | ing scopes until we find one with a newline in it. If we reach the |
| 9895 | outermost lexing scope and it is a file, we use the stream method. |
| 9896 | Otherwise it is treated as an eval. |
| 9897 | */ |
| 9898 | |
| 9899 | STATIC char * |
| 9900 | S_scan_heredoc(pTHX_ char *s) |
| 9901 | { |
| 9902 | dVAR; |
| 9903 | I32 op_type = OP_SCALAR; |
| 9904 | I32 len; |
| 9905 | SV *tmpstr; |
| 9906 | char term; |
| 9907 | char *d; |
| 9908 | char *e; |
| 9909 | char *peek; |
| 9910 | const bool infile = PL_rsfp || PL_parser->filtered; |
| 9911 | LEXSHARED *shared = PL_parser->lex_shared; |
| 9912 | #ifdef PERL_MAD |
| 9913 | I32 stuffstart = s - SvPVX(PL_linestr); |
| 9914 | char *tstart; |
| 9915 | |
| 9916 | PL_realtokenstart = -1; |
| 9917 | #endif |
| 9918 | |
| 9919 | PERL_ARGS_ASSERT_SCAN_HEREDOC; |
| 9920 | |
| 9921 | s += 2; |
| 9922 | d = PL_tokenbuf + 1; |
| 9923 | e = PL_tokenbuf + sizeof PL_tokenbuf - 1; |
| 9924 | *PL_tokenbuf = '\n'; |
| 9925 | peek = s; |
| 9926 | while (SPACE_OR_TAB(*peek)) |
| 9927 | peek++; |
| 9928 | if (*peek == '`' || *peek == '\'' || *peek =='"') { |
| 9929 | s = peek; |
| 9930 | term = *s++; |
| 9931 | s = delimcpy(d, e, s, PL_bufend, term, &len); |
| 9932 | if (s == PL_bufend) |
| 9933 | Perl_croak(aTHX_ "Unterminated delimiter for here document"); |
| 9934 | d += len; |
| 9935 | s++; |
| 9936 | } |
| 9937 | else { |
| 9938 | if (*s == '\\') |
| 9939 | /* <<\FOO is equivalent to <<'FOO' */ |
| 9940 | s++, term = '\''; |
| 9941 | else |
| 9942 | term = '"'; |
| 9943 | if (!isWORDCHAR_lazy_if(s,UTF)) |
| 9944 | deprecate("bare << to mean <<\"\""); |
| 9945 | for (; isWORDCHAR_lazy_if(s,UTF); s++) { |
| 9946 | if (d < e) |
| 9947 | *d++ = *s; |
| 9948 | } |
| 9949 | } |
| 9950 | if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1) |
| 9951 | Perl_croak(aTHX_ "Delimiter for here document is too long"); |
| 9952 | *d++ = '\n'; |
| 9953 | *d = '\0'; |
| 9954 | len = d - PL_tokenbuf; |
| 9955 | |
| 9956 | #ifdef PERL_MAD |
| 9957 | if (PL_madskills) { |
| 9958 | tstart = PL_tokenbuf + 1; |
| 9959 | PL_thisclose = newSVpvn(tstart, len - 1); |
| 9960 | tstart = SvPVX(PL_linestr) + stuffstart; |
| 9961 | PL_thisopen = newSVpvn(tstart, s - tstart); |
| 9962 | stuffstart = s - SvPVX(PL_linestr); |
| 9963 | } |
| 9964 | #endif |
| 9965 | #ifndef PERL_STRICT_CR |
| 9966 | d = strchr(s, '\r'); |
| 9967 | if (d) { |
| 9968 | char * const olds = s; |
| 9969 | s = d; |
| 9970 | while (s < PL_bufend) { |
| 9971 | if (*s == '\r') { |
| 9972 | *d++ = '\n'; |
| 9973 | if (*++s == '\n') |
| 9974 | s++; |
| 9975 | } |
| 9976 | else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */ |
| 9977 | *d++ = *s++; |
| 9978 | s++; |
| 9979 | } |
| 9980 | else |
| 9981 | *d++ = *s++; |
| 9982 | } |
| 9983 | *d = '\0'; |
| 9984 | PL_bufend = d; |
| 9985 | SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr)); |
| 9986 | s = olds; |
| 9987 | } |
| 9988 | #endif |
| 9989 | #ifdef PERL_MAD |
| 9990 | if (PL_madskills) { |
| 9991 | tstart = SvPVX(PL_linestr) + stuffstart; |
| 9992 | if (PL_thisstuff) |
| 9993 | sv_catpvn(PL_thisstuff, tstart, s - tstart); |
| 9994 | else |
| 9995 | PL_thisstuff = newSVpvn(tstart, s - tstart); |
| 9996 | } |
| 9997 | |
| 9998 | stuffstart = s - SvPVX(PL_linestr); |
| 9999 | #endif |
| 10000 | |
| 10001 | tmpstr = newSV_type(SVt_PVIV); |
| 10002 | SvGROW(tmpstr, 80); |
| 10003 | if (term == '\'') { |
| 10004 | op_type = OP_CONST; |
| 10005 | SvIV_set(tmpstr, -1); |
| 10006 | } |
| 10007 | else if (term == '`') { |
| 10008 | op_type = OP_BACKTICK; |
| 10009 | SvIV_set(tmpstr, '\\'); |
| 10010 | } |
| 10011 | |
| 10012 | PL_multi_start = CopLINE(PL_curcop) + 1; |
| 10013 | PL_multi_open = PL_multi_close = '<'; |
| 10014 | /* inside a string eval or quote-like operator */ |
| 10015 | if (!infile || PL_lex_inwhat) { |
| 10016 | SV *linestr; |
| 10017 | char *bufend; |
| 10018 | char * const olds = s; |
| 10019 | PERL_CONTEXT * const cx = &cxstack[cxstack_ix]; |
| 10020 | /* These two fields are not set until an inner lexing scope is |
| 10021 | entered. But we need them set here. */ |
| 10022 | shared->ls_bufptr = s; |
| 10023 | shared->ls_linestr = PL_linestr; |
| 10024 | if (PL_lex_inwhat) |
| 10025 | /* Look for a newline. If the current buffer does not have one, |
| 10026 | peek into the line buffer of the parent lexing scope, going |
| 10027 | up as many levels as necessary to find one with a newline |
| 10028 | after bufptr. |
| 10029 | */ |
| 10030 | while (!(s = (char *)memchr( |
| 10031 | (void *)shared->ls_bufptr, '\n', |
| 10032 | SvEND(shared->ls_linestr)-shared->ls_bufptr |
| 10033 | ))) { |
| 10034 | shared = shared->ls_prev; |
| 10035 | /* shared is only null if we have gone beyond the outermost |
| 10036 | lexing scope. In a file, we will have broken out of the |
| 10037 | loop in the previous iteration. In an eval, the string buf- |
| 10038 | fer ends with "\n;", so the while condition below will have |
| 10039 | evaluated to false. So shared can never be null. */ |
| 10040 | assert(shared); |
| 10041 | /* A LEXSHARED struct with a null ls_prev pointer is the outer- |
| 10042 | most lexing scope. In a file, shared->ls_linestr at that |
| 10043 | level is just one line, so there is no body to steal. */ |
| 10044 | if (infile && !shared->ls_prev) { |
| 10045 | s = olds; |
| 10046 | goto streaming; |
| 10047 | } |
| 10048 | } |
| 10049 | else { /* eval */ |
| 10050 | s = (char*)memchr((void*)s, '\n', PL_bufend - s); |
| 10051 | assert(s); |
| 10052 | } |
| 10053 | linestr = shared->ls_linestr; |
| 10054 | bufend = SvEND(linestr); |
| 10055 | d = s; |
| 10056 | while (s < bufend - len + 1 && |
| 10057 | memNE(s,PL_tokenbuf,len) ) { |
| 10058 | if (*s++ == '\n') |
| 10059 | ++shared->herelines; |
| 10060 | } |
| 10061 | if (s >= bufend - len + 1) { |
| 10062 | goto interminable; |
| 10063 | } |
| 10064 | sv_setpvn(tmpstr,d+1,s-d); |
| 10065 | #ifdef PERL_MAD |
| 10066 | if (PL_madskills) { |
| 10067 | if (PL_thisstuff) |
| 10068 | sv_catpvn(PL_thisstuff, d + 1, s - d); |
| 10069 | else |
| 10070 | PL_thisstuff = newSVpvn(d + 1, s - d); |
| 10071 | stuffstart = s - SvPVX(PL_linestr); |
| 10072 | } |
| 10073 | #endif |
| 10074 | s += len - 1; |
| 10075 | /* the preceding stmt passes a newline */ |
| 10076 | shared->herelines++; |
| 10077 | |
| 10078 | /* s now points to the newline after the heredoc terminator. |
| 10079 | d points to the newline before the body of the heredoc. |
| 10080 | */ |
| 10081 | |
| 10082 | /* We are going to modify linestr in place here, so set |
| 10083 | aside copies of the string if necessary for re-evals or |
| 10084 | (caller $n)[6]. */ |
| 10085 | /* See the Paranoia note in case LEX_INTERPEND in yylex, for why we |
| 10086 | check shared->re_eval_str. */ |
| 10087 | if (shared->re_eval_start || shared->re_eval_str) { |
| 10088 | /* Set aside the rest of the regexp */ |
| 10089 | if (!shared->re_eval_str) |
| 10090 | shared->re_eval_str = |
| 10091 | newSVpvn(shared->re_eval_start, |
| 10092 | bufend - shared->re_eval_start); |
| 10093 | shared->re_eval_start -= s-d; |
| 10094 | } |
| 10095 | if (cxstack_ix >= 0 && CxTYPE(cx) == CXt_EVAL && |
| 10096 | CxOLD_OP_TYPE(cx) == OP_ENTEREVAL && |
| 10097 | cx->blk_eval.cur_text == linestr) |
| 10098 | { |
| 10099 | cx->blk_eval.cur_text = newSVsv(linestr); |
| 10100 | SvSCREAM_on(cx->blk_eval.cur_text); |
| 10101 | } |
| 10102 | /* Copy everything from s onwards back to d. */ |
| 10103 | Move(s,d,bufend-s + 1,char); |
| 10104 | SvCUR_set(linestr, SvCUR(linestr) - (s-d)); |
| 10105 | /* Setting PL_bufend only applies when we have not dug deeper |
| 10106 | into other scopes, because sublex_done sets PL_bufend to |
| 10107 | SvEND(PL_linestr). */ |
| 10108 | if (shared == PL_parser->lex_shared) PL_bufend = SvEND(linestr); |
| 10109 | s = olds; |
| 10110 | } |
| 10111 | else |
| 10112 | { |
| 10113 | SV *linestr_save; |
| 10114 | streaming: |
| 10115 | sv_setpvs(tmpstr,""); /* avoid "uninitialized" warning */ |
| 10116 | term = PL_tokenbuf[1]; |
| 10117 | len--; |
| 10118 | linestr_save = PL_linestr; /* must restore this afterwards */ |
| 10119 | d = s; /* and this */ |
| 10120 | PL_linestr = newSVpvs(""); |
| 10121 | PL_bufend = SvPVX(PL_linestr); |
| 10122 | while (1) { |
| 10123 | #ifdef PERL_MAD |
| 10124 | if (PL_madskills) { |
| 10125 | tstart = SvPVX(PL_linestr) + stuffstart; |
| 10126 | if (PL_thisstuff) |
| 10127 | sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart); |
| 10128 | else |
| 10129 | PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart); |
| 10130 | } |
| 10131 | #endif |
| 10132 | PL_bufptr = PL_bufend; |
| 10133 | CopLINE_set(PL_curcop, |
| 10134 | PL_multi_start + shared->herelines); |
| 10135 | if (!lex_next_chunk(LEX_NO_TERM) |
| 10136 | && (!SvCUR(tmpstr) || SvEND(tmpstr)[-1] != '\n')) { |
| 10137 | SvREFCNT_dec(linestr_save); |
| 10138 | goto interminable; |
| 10139 | } |
| 10140 | CopLINE_set(PL_curcop, (line_t)PL_multi_start - 1); |
| 10141 | if (!SvCUR(PL_linestr) || PL_bufend[-1] != '\n') { |
| 10142 | lex_grow_linestr(SvCUR(PL_linestr) + 2); |
| 10143 | sv_catpvs(PL_linestr, "\n\0"); |
| 10144 | } |
| 10145 | s = PL_bufptr; |
| 10146 | #ifdef PERL_MAD |
| 10147 | stuffstart = s - SvPVX(PL_linestr); |
| 10148 | #endif |
| 10149 | shared->herelines++; |
| 10150 | PL_last_lop = PL_last_uni = NULL; |
| 10151 | #ifndef PERL_STRICT_CR |
| 10152 | if (PL_bufend - PL_linestart >= 2) { |
| 10153 | if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') || |
| 10154 | (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r')) |
| 10155 | { |
| 10156 | PL_bufend[-2] = '\n'; |
| 10157 | PL_bufend--; |
| 10158 | SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr)); |
| 10159 | } |
| 10160 | else if (PL_bufend[-1] == '\r') |
| 10161 | PL_bufend[-1] = '\n'; |
| 10162 | } |
| 10163 | else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r') |
| 10164 | PL_bufend[-1] = '\n'; |
| 10165 | #endif |
| 10166 | if (*s == term && memEQ(s,PL_tokenbuf + 1,len)) { |
| 10167 | SvREFCNT_dec(PL_linestr); |
| 10168 | PL_linestr = linestr_save; |
| 10169 | PL_linestart = SvPVX(linestr_save); |
| 10170 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 10171 | s = d; |
| 10172 | break; |
| 10173 | } |
| 10174 | else { |
| 10175 | sv_catsv(tmpstr,PL_linestr); |
| 10176 | } |
| 10177 | } |
| 10178 | } |
| 10179 | PL_multi_end = CopLINE(PL_curcop); |
| 10180 | if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) { |
| 10181 | SvPV_shrink_to_cur(tmpstr); |
| 10182 | } |
| 10183 | if (!IN_BYTES) { |
| 10184 | if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr))) |
| 10185 | SvUTF8_on(tmpstr); |
| 10186 | else if (PL_encoding) |
| 10187 | sv_recode_to_utf8(tmpstr, PL_encoding); |
| 10188 | } |
| 10189 | PL_lex_stuff = tmpstr; |
| 10190 | pl_yylval.ival = op_type; |
| 10191 | return s; |
| 10192 | |
| 10193 | interminable: |
| 10194 | SvREFCNT_dec(tmpstr); |
| 10195 | CopLINE_set(PL_curcop, (line_t)PL_multi_start - 1); |
| 10196 | missingterm(PL_tokenbuf + 1); |
| 10197 | } |
| 10198 | |
| 10199 | /* scan_inputsymbol |
| 10200 | takes: current position in input buffer |
| 10201 | returns: new position in input buffer |
| 10202 | side-effects: pl_yylval and lex_op are set. |
| 10203 | |
| 10204 | This code handles: |
| 10205 | |
| 10206 | <> read from ARGV |
| 10207 | <FH> read from filehandle |
| 10208 | <pkg::FH> read from package qualified filehandle |
| 10209 | <pkg'FH> read from package qualified filehandle |
| 10210 | <$fh> read from filehandle in $fh |
| 10211 | <*.h> filename glob |
| 10212 | |
| 10213 | */ |
| 10214 | |
| 10215 | STATIC char * |
| 10216 | S_scan_inputsymbol(pTHX_ char *start) |
| 10217 | { |
| 10218 | dVAR; |
| 10219 | char *s = start; /* current position in buffer */ |
| 10220 | char *end; |
| 10221 | I32 len; |
| 10222 | char *d = PL_tokenbuf; /* start of temp holding space */ |
| 10223 | const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */ |
| 10224 | |
| 10225 | PERL_ARGS_ASSERT_SCAN_INPUTSYMBOL; |
| 10226 | |
| 10227 | end = strchr(s, '\n'); |
| 10228 | if (!end) |
| 10229 | end = PL_bufend; |
| 10230 | s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */ |
| 10231 | |
| 10232 | /* die if we didn't have space for the contents of the <>, |
| 10233 | or if it didn't end, or if we see a newline |
| 10234 | */ |
| 10235 | |
| 10236 | if (len >= (I32)sizeof PL_tokenbuf) |
| 10237 | Perl_croak(aTHX_ "Excessively long <> operator"); |
| 10238 | if (s >= end) |
| 10239 | Perl_croak(aTHX_ "Unterminated <> operator"); |
| 10240 | |
| 10241 | s++; |
| 10242 | |
| 10243 | /* check for <$fh> |
| 10244 | Remember, only scalar variables are interpreted as filehandles by |
| 10245 | this code. Anything more complex (e.g., <$fh{$num}>) will be |
| 10246 | treated as a glob() call. |
| 10247 | This code makes use of the fact that except for the $ at the front, |
| 10248 | a scalar variable and a filehandle look the same. |
| 10249 | */ |
| 10250 | if (*d == '$' && d[1]) d++; |
| 10251 | |
| 10252 | /* allow <Pkg'VALUE> or <Pkg::VALUE> */ |
| 10253 | while (*d && (isWORDCHAR_lazy_if(d,UTF) || *d == '\'' || *d == ':')) |
| 10254 | d += UTF ? UTF8SKIP(d) : 1; |
| 10255 | |
| 10256 | /* If we've tried to read what we allow filehandles to look like, and |
| 10257 | there's still text left, then it must be a glob() and not a getline. |
| 10258 | Use scan_str to pull out the stuff between the <> and treat it |
| 10259 | as nothing more than a string. |
| 10260 | */ |
| 10261 | |
| 10262 | if (d - PL_tokenbuf != len) { |
| 10263 | pl_yylval.ival = OP_GLOB; |
| 10264 | s = scan_str(start,!!PL_madskills,FALSE,FALSE, FALSE); |
| 10265 | if (!s) |
| 10266 | Perl_croak(aTHX_ "Glob not terminated"); |
| 10267 | return s; |
| 10268 | } |
| 10269 | else { |
| 10270 | bool readline_overriden = FALSE; |
| 10271 | GV *gv_readline; |
| 10272 | GV **gvp; |
| 10273 | /* we're in a filehandle read situation */ |
| 10274 | d = PL_tokenbuf; |
| 10275 | |
| 10276 | /* turn <> into <ARGV> */ |
| 10277 | if (!len) |
| 10278 | Copy("ARGV",d,5,char); |
| 10279 | |
| 10280 | /* Check whether readline() is overriden */ |
| 10281 | gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV); |
| 10282 | if ((gv_readline |
| 10283 | && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)) |
| 10284 | || |
| 10285 | ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE)) |
| 10286 | && (gv_readline = *gvp) && isGV_with_GP(gv_readline) |
| 10287 | && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))) |
| 10288 | readline_overriden = TRUE; |
| 10289 | |
| 10290 | /* if <$fh>, create the ops to turn the variable into a |
| 10291 | filehandle |
| 10292 | */ |
| 10293 | if (*d == '$') { |
| 10294 | /* try to find it in the pad for this block, otherwise find |
| 10295 | add symbol table ops |
| 10296 | */ |
| 10297 | const PADOFFSET tmp = pad_findmy_pvn(d, len, UTF ? SVf_UTF8 : 0); |
| 10298 | if (tmp != NOT_IN_PAD) { |
| 10299 | if (PAD_COMPNAME_FLAGS_isOUR(tmp)) { |
| 10300 | HV * const stash = PAD_COMPNAME_OURSTASH(tmp); |
| 10301 | HEK * const stashname = HvNAME_HEK(stash); |
| 10302 | SV * const sym = sv_2mortal(newSVhek(stashname)); |
| 10303 | sv_catpvs(sym, "::"); |
| 10304 | sv_catpv(sym, d+1); |
| 10305 | d = SvPVX(sym); |
| 10306 | goto intro_sym; |
| 10307 | } |
| 10308 | else { |
| 10309 | OP * const o = newOP(OP_PADSV, 0); |
| 10310 | o->op_targ = tmp; |
| 10311 | PL_lex_op = readline_overriden |
| 10312 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, |
| 10313 | op_append_elem(OP_LIST, o, |
| 10314 | newCVREF(0, newGVOP(OP_GV,0,gv_readline)))) |
| 10315 | : (OP*)newUNOP(OP_READLINE, 0, o); |
| 10316 | } |
| 10317 | } |
| 10318 | else { |
| 10319 | GV *gv; |
| 10320 | ++d; |
| 10321 | intro_sym: |
| 10322 | gv = gv_fetchpv(d, |
| 10323 | (PL_in_eval |
| 10324 | ? (GV_ADDMULTI | GV_ADDINEVAL) |
| 10325 | : GV_ADDMULTI) | ( UTF ? SVf_UTF8 : 0 ), |
| 10326 | SVt_PV); |
| 10327 | PL_lex_op = readline_overriden |
| 10328 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, |
| 10329 | op_append_elem(OP_LIST, |
| 10330 | newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)), |
| 10331 | newCVREF(0, newGVOP(OP_GV, 0, gv_readline)))) |
| 10332 | : (OP*)newUNOP(OP_READLINE, 0, |
| 10333 | newUNOP(OP_RV2SV, 0, |
| 10334 | newGVOP(OP_GV, 0, gv))); |
| 10335 | } |
| 10336 | if (!readline_overriden) |
| 10337 | PL_lex_op->op_flags |= OPf_SPECIAL; |
| 10338 | /* we created the ops in PL_lex_op, so make pl_yylval.ival a null op */ |
| 10339 | pl_yylval.ival = OP_NULL; |
| 10340 | } |
| 10341 | |
| 10342 | /* If it's none of the above, it must be a literal filehandle |
| 10343 | (<Foo::BAR> or <FOO>) so build a simple readline OP */ |
| 10344 | else { |
| 10345 | GV * const gv = gv_fetchpv(d, GV_ADD | ( UTF ? SVf_UTF8 : 0 ), SVt_PVIO); |
| 10346 | PL_lex_op = readline_overriden |
| 10347 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, |
| 10348 | op_append_elem(OP_LIST, |
| 10349 | newGVOP(OP_GV, 0, gv), |
| 10350 | newCVREF(0, newGVOP(OP_GV, 0, gv_readline)))) |
| 10351 | : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv)); |
| 10352 | pl_yylval.ival = OP_NULL; |
| 10353 | } |
| 10354 | } |
| 10355 | |
| 10356 | return s; |
| 10357 | } |
| 10358 | |
| 10359 | |
| 10360 | /* scan_str |
| 10361 | takes: start position in buffer |
| 10362 | keep_quoted preserve \ on the embedded delimiter(s) |
| 10363 | keep_delims preserve the delimiters around the string |
| 10364 | re_reparse compiling a run-time /(?{})/: |
| 10365 | collapse // to /, and skip encoding src |
| 10366 | returns: position to continue reading from buffer |
| 10367 | side-effects: multi_start, multi_close, lex_repl or lex_stuff, and |
| 10368 | updates the read buffer. |
| 10369 | |
| 10370 | This subroutine pulls a string out of the input. It is called for: |
| 10371 | q single quotes q(literal text) |
| 10372 | ' single quotes 'literal text' |
| 10373 | qq double quotes qq(interpolate $here please) |
| 10374 | " double quotes "interpolate $here please" |
| 10375 | qx backticks qx(/bin/ls -l) |
| 10376 | ` backticks `/bin/ls -l` |
| 10377 | qw quote words @EXPORT_OK = qw( func() $spam ) |
| 10378 | m// regexp match m/this/ |
| 10379 | s/// regexp substitute s/this/that/ |
| 10380 | tr/// string transliterate tr/this/that/ |
| 10381 | y/// string transliterate y/this/that/ |
| 10382 | ($*@) sub prototypes sub foo ($) |
| 10383 | (stuff) sub attr parameters sub foo : attr(stuff) |
| 10384 | <> readline or globs <FOO>, <>, <$fh>, or <*.c> |
| 10385 | |
| 10386 | In most of these cases (all but <>, patterns and transliterate) |
| 10387 | yylex() calls scan_str(). m// makes yylex() call scan_pat() which |
| 10388 | calls scan_str(). s/// makes yylex() call scan_subst() which calls |
| 10389 | scan_str(). tr/// and y/// make yylex() call scan_trans() which |
| 10390 | calls scan_str(). |
| 10391 | |
| 10392 | It skips whitespace before the string starts, and treats the first |
| 10393 | character as the delimiter. If the delimiter is one of ([{< then |
| 10394 | the corresponding "close" character )]}> is used as the closing |
| 10395 | delimiter. It allows quoting of delimiters, and if the string has |
| 10396 | balanced delimiters ([{<>}]) it allows nesting. |
| 10397 | |
| 10398 | On success, the SV with the resulting string is put into lex_stuff or, |
| 10399 | if that is already non-NULL, into lex_repl. The second case occurs only |
| 10400 | when parsing the RHS of the special constructs s/// and tr/// (y///). |
| 10401 | For convenience, the terminating delimiter character is stuffed into |
| 10402 | SvIVX of the SV. |
| 10403 | */ |
| 10404 | |
| 10405 | STATIC char * |
| 10406 | S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims, int re_reparse, |
| 10407 | bool deprecate_escaped_meta /* Should we issue a deprecation warning |
| 10408 | for certain paired metacharacters that |
| 10409 | appear escaped within it */ |
| 10410 | ) |
| 10411 | { |
| 10412 | dVAR; |
| 10413 | SV *sv; /* scalar value: string */ |
| 10414 | const char *tmps; /* temp string, used for delimiter matching */ |
| 10415 | char *s = start; /* current position in the buffer */ |
| 10416 | char term; /* terminating character */ |
| 10417 | char *to; /* current position in the sv's data */ |
| 10418 | I32 brackets = 1; /* bracket nesting level */ |
| 10419 | bool has_utf8 = FALSE; /* is there any utf8 content? */ |
| 10420 | I32 termcode; /* terminating char. code */ |
| 10421 | U8 termstr[UTF8_MAXBYTES]; /* terminating string */ |
| 10422 | STRLEN termlen; /* length of terminating string */ |
| 10423 | int last_off = 0; /* last position for nesting bracket */ |
| 10424 | char *escaped_open = NULL; |
| 10425 | #ifdef PERL_MAD |
| 10426 | int stuffstart; |
| 10427 | char *tstart; |
| 10428 | #endif |
| 10429 | |
| 10430 | PERL_ARGS_ASSERT_SCAN_STR; |
| 10431 | |
| 10432 | /* skip space before the delimiter */ |
| 10433 | if (isSPACE(*s)) { |
| 10434 | s = PEEKSPACE(s); |
| 10435 | } |
| 10436 | |
| 10437 | #ifdef PERL_MAD |
| 10438 | if (PL_realtokenstart >= 0) { |
| 10439 | stuffstart = PL_realtokenstart; |
| 10440 | PL_realtokenstart = -1; |
| 10441 | } |
| 10442 | else |
| 10443 | stuffstart = start - SvPVX(PL_linestr); |
| 10444 | #endif |
| 10445 | /* mark where we are, in case we need to report errors */ |
| 10446 | CLINE; |
| 10447 | |
| 10448 | /* after skipping whitespace, the next character is the terminator */ |
| 10449 | term = *s; |
| 10450 | if (!UTF) { |
| 10451 | termcode = termstr[0] = term; |
| 10452 | termlen = 1; |
| 10453 | } |
| 10454 | else { |
| 10455 | termcode = utf8_to_uvchr_buf((U8*)s, (U8*)PL_bufend, &termlen); |
| 10456 | Copy(s, termstr, termlen, U8); |
| 10457 | if (!UTF8_IS_INVARIANT(term)) |
| 10458 | has_utf8 = TRUE; |
| 10459 | } |
| 10460 | |
| 10461 | /* mark where we are */ |
| 10462 | PL_multi_start = CopLINE(PL_curcop); |
| 10463 | PL_multi_open = term; |
| 10464 | |
| 10465 | /* find corresponding closing delimiter */ |
| 10466 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) |
| 10467 | termcode = termstr[0] = term = tmps[5]; |
| 10468 | |
| 10469 | PL_multi_close = term; |
| 10470 | |
| 10471 | /* A warning is raised if the input parameter requires it for escaped (by a |
| 10472 | * backslash) paired metacharacters {} [] and () when the delimiters are |
| 10473 | * those same characters, and the backslash is ineffective. This doesn't |
| 10474 | * happen for <>, as they aren't metas. */ |
| 10475 | if (deprecate_escaped_meta |
| 10476 | && (PL_multi_open == PL_multi_close |
| 10477 | || ! ckWARN_d(WARN_DEPRECATED) |
| 10478 | || PL_multi_open == '<')) |
| 10479 | { |
| 10480 | deprecate_escaped_meta = FALSE; |
| 10481 | } |
| 10482 | |
| 10483 | /* create a new SV to hold the contents. 79 is the SV's initial length. |
| 10484 | What a random number. */ |
| 10485 | sv = newSV_type(SVt_PVIV); |
| 10486 | SvGROW(sv, 80); |
| 10487 | SvIV_set(sv, termcode); |
| 10488 | (void)SvPOK_only(sv); /* validate pointer */ |
| 10489 | |
| 10490 | /* move past delimiter and try to read a complete string */ |
| 10491 | if (keep_delims) |
| 10492 | sv_catpvn(sv, s, termlen); |
| 10493 | s += termlen; |
| 10494 | #ifdef PERL_MAD |
| 10495 | tstart = SvPVX(PL_linestr) + stuffstart; |
| 10496 | if (PL_madskills && !PL_thisopen && !keep_delims) { |
| 10497 | PL_thisopen = newSVpvn(tstart, s - tstart); |
| 10498 | stuffstart = s - SvPVX(PL_linestr); |
| 10499 | } |
| 10500 | #endif |
| 10501 | for (;;) { |
| 10502 | if (PL_encoding && !UTF && !re_reparse) { |
| 10503 | bool cont = TRUE; |
| 10504 | |
| 10505 | while (cont) { |
| 10506 | int offset = s - SvPVX_const(PL_linestr); |
| 10507 | const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr, |
| 10508 | &offset, (char*)termstr, termlen); |
| 10509 | const char * const ns = SvPVX_const(PL_linestr) + offset; |
| 10510 | char * const svlast = SvEND(sv) - 1; |
| 10511 | |
| 10512 | for (; s < ns; s++) { |
| 10513 | if (*s == '\n' && !PL_rsfp && !PL_parser->filtered) |
| 10514 | COPLINE_INC_WITH_HERELINES; |
| 10515 | } |
| 10516 | if (!found) |
| 10517 | goto read_more_line; |
| 10518 | else { |
| 10519 | /* handle quoted delimiters */ |
| 10520 | if (SvCUR(sv) > 1 && *(svlast-1) == '\\') { |
| 10521 | const char *t; |
| 10522 | for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';) |
| 10523 | t--; |
| 10524 | if ((svlast-1 - t) % 2) { |
| 10525 | if (!keep_quoted) { |
| 10526 | *(svlast-1) = term; |
| 10527 | *svlast = '\0'; |
| 10528 | SvCUR_set(sv, SvCUR(sv) - 1); |
| 10529 | } |
| 10530 | continue; |
| 10531 | } |
| 10532 | } |
| 10533 | if (PL_multi_open == PL_multi_close) { |
| 10534 | cont = FALSE; |
| 10535 | } |
| 10536 | else { |
| 10537 | const char *t; |
| 10538 | char *w; |
| 10539 | for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) { |
| 10540 | /* At here, all closes are "was quoted" one, |
| 10541 | so we don't check PL_multi_close. */ |
| 10542 | if (*t == '\\') { |
| 10543 | if (!keep_quoted && *(t+1) == PL_multi_open) |
| 10544 | t++; |
| 10545 | else |
| 10546 | *w++ = *t++; |
| 10547 | } |
| 10548 | else if (*t == PL_multi_open) |
| 10549 | brackets++; |
| 10550 | |
| 10551 | *w = *t; |
| 10552 | } |
| 10553 | if (w < t) { |
| 10554 | *w++ = term; |
| 10555 | *w = '\0'; |
| 10556 | SvCUR_set(sv, w - SvPVX_const(sv)); |
| 10557 | } |
| 10558 | last_off = w - SvPVX(sv); |
| 10559 | if (--brackets <= 0) |
| 10560 | cont = FALSE; |
| 10561 | } |
| 10562 | } |
| 10563 | } |
| 10564 | if (!keep_delims) { |
| 10565 | SvCUR_set(sv, SvCUR(sv) - 1); |
| 10566 | *SvEND(sv) = '\0'; |
| 10567 | } |
| 10568 | break; |
| 10569 | } |
| 10570 | |
| 10571 | /* extend sv if need be */ |
| 10572 | SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1); |
| 10573 | /* set 'to' to the next character in the sv's string */ |
| 10574 | to = SvPVX(sv)+SvCUR(sv); |
| 10575 | |
| 10576 | /* if open delimiter is the close delimiter read unbridle */ |
| 10577 | if (PL_multi_open == PL_multi_close) { |
| 10578 | for (; s < PL_bufend; s++,to++) { |
| 10579 | /* embedded newlines increment the current line number */ |
| 10580 | if (*s == '\n' && !PL_rsfp && !PL_parser->filtered) |
| 10581 | COPLINE_INC_WITH_HERELINES; |
| 10582 | /* handle quoted delimiters */ |
| 10583 | if (*s == '\\' && s+1 < PL_bufend && term != '\\') { |
| 10584 | if (!keep_quoted |
| 10585 | && (s[1] == term |
| 10586 | || (re_reparse && s[1] == '\\')) |
| 10587 | ) |
| 10588 | s++; |
| 10589 | /* any other quotes are simply copied straight through */ |
| 10590 | else |
| 10591 | *to++ = *s++; |
| 10592 | } |
| 10593 | /* terminate when run out of buffer (the for() condition), or |
| 10594 | have found the terminator */ |
| 10595 | else if (*s == term) { |
| 10596 | if (termlen == 1) |
| 10597 | break; |
| 10598 | if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen)) |
| 10599 | break; |
| 10600 | } |
| 10601 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
| 10602 | has_utf8 = TRUE; |
| 10603 | *to = *s; |
| 10604 | } |
| 10605 | } |
| 10606 | |
| 10607 | /* if the terminator isn't the same as the start character (e.g., |
| 10608 | matched brackets), we have to allow more in the quoting, and |
| 10609 | be prepared for nested brackets. |
| 10610 | */ |
| 10611 | else { |
| 10612 | /* read until we run out of string, or we find the terminator */ |
| 10613 | for (; s < PL_bufend; s++,to++) { |
| 10614 | /* embedded newlines increment the line count */ |
| 10615 | if (*s == '\n' && !PL_rsfp && !PL_parser->filtered) |
| 10616 | COPLINE_INC_WITH_HERELINES; |
| 10617 | /* backslashes can escape the open or closing characters */ |
| 10618 | if (*s == '\\' && s+1 < PL_bufend) { |
| 10619 | if (!keep_quoted && |
| 10620 | ((s[1] == PL_multi_open) || (s[1] == PL_multi_close))) |
| 10621 | { |
| 10622 | s++; |
| 10623 | |
| 10624 | /* Here, 'deprecate_escaped_meta' is true iff the |
| 10625 | * delimiters are paired metacharacters, and 's' points |
| 10626 | * to an occurrence of one of them within the string, |
| 10627 | * which was preceded by a backslash. If this is a |
| 10628 | * context where the delimiter is also a metacharacter, |
| 10629 | * the backslash is useless, and deprecated. () and [] |
| 10630 | * are meta in any context. {} are meta only when |
| 10631 | * appearing in a quantifier or in things like '\p{'. |
| 10632 | * They also aren't meta unless there is a matching |
| 10633 | * closed, escaped char later on within the string. |
| 10634 | * If 's' points to an open, set a flag; if to a close, |
| 10635 | * test that flag, and raise a warning if it was set */ |
| 10636 | |
| 10637 | if (deprecate_escaped_meta) { |
| 10638 | if (*s == PL_multi_open) { |
| 10639 | if (*s != '{') { |
| 10640 | escaped_open = s; |
| 10641 | } |
| 10642 | else if (regcurly(s, |
| 10643 | TRUE /* Look for a closing |
| 10644 | '\}' */) |
| 10645 | || (s - start > 2 /* Look for e.g. |
| 10646 | '\x{' */ |
| 10647 | && _generic_isCC(*(s-2), _CC_BACKSLASH_FOO_LBRACE_IS_META))) |
| 10648 | { |
| 10649 | escaped_open = s; |
| 10650 | } |
| 10651 | } |
| 10652 | else if (escaped_open) { |
| 10653 | Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), |
| 10654 | "Useless use of '\\'; doesn't escape metacharacter '%c'", PL_multi_open); |
| 10655 | escaped_open = NULL; |
| 10656 | } |
| 10657 | } |
| 10658 | } |
| 10659 | else |
| 10660 | *to++ = *s++; |
| 10661 | } |
| 10662 | /* allow nested opens and closes */ |
| 10663 | else if (*s == PL_multi_close && --brackets <= 0) |
| 10664 | break; |
| 10665 | else if (*s == PL_multi_open) |
| 10666 | brackets++; |
| 10667 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
| 10668 | has_utf8 = TRUE; |
| 10669 | *to = *s; |
| 10670 | } |
| 10671 | } |
| 10672 | /* terminate the copied string and update the sv's end-of-string */ |
| 10673 | *to = '\0'; |
| 10674 | SvCUR_set(sv, to - SvPVX_const(sv)); |
| 10675 | |
| 10676 | /* |
| 10677 | * this next chunk reads more into the buffer if we're not done yet |
| 10678 | */ |
| 10679 | |
| 10680 | if (s < PL_bufend) |
| 10681 | break; /* handle case where we are done yet :-) */ |
| 10682 | |
| 10683 | #ifndef PERL_STRICT_CR |
| 10684 | if (to - SvPVX_const(sv) >= 2) { |
| 10685 | if ((to[-2] == '\r' && to[-1] == '\n') || |
| 10686 | (to[-2] == '\n' && to[-1] == '\r')) |
| 10687 | { |
| 10688 | to[-2] = '\n'; |
| 10689 | to--; |
| 10690 | SvCUR_set(sv, to - SvPVX_const(sv)); |
| 10691 | } |
| 10692 | else if (to[-1] == '\r') |
| 10693 | to[-1] = '\n'; |
| 10694 | } |
| 10695 | else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r') |
| 10696 | to[-1] = '\n'; |
| 10697 | #endif |
| 10698 | |
| 10699 | read_more_line: |
| 10700 | /* if we're out of file, or a read fails, bail and reset the current |
| 10701 | line marker so we can report where the unterminated string began |
| 10702 | */ |
| 10703 | #ifdef PERL_MAD |
| 10704 | if (PL_madskills) { |
| 10705 | char * const tstart = SvPVX(PL_linestr) + stuffstart; |
| 10706 | if (PL_thisstuff) |
| 10707 | sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart); |
| 10708 | else |
| 10709 | PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart); |
| 10710 | } |
| 10711 | #endif |
| 10712 | COPLINE_INC_WITH_HERELINES; |
| 10713 | PL_bufptr = PL_bufend; |
| 10714 | if (!lex_next_chunk(0)) { |
| 10715 | sv_free(sv); |
| 10716 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
| 10717 | return NULL; |
| 10718 | } |
| 10719 | s = PL_bufptr; |
| 10720 | #ifdef PERL_MAD |
| 10721 | stuffstart = 0; |
| 10722 | #endif |
| 10723 | } |
| 10724 | |
| 10725 | /* at this point, we have successfully read the delimited string */ |
| 10726 | |
| 10727 | if (!PL_encoding || UTF || re_reparse) { |
| 10728 | #ifdef PERL_MAD |
| 10729 | if (PL_madskills) { |
| 10730 | char * const tstart = SvPVX(PL_linestr) + stuffstart; |
| 10731 | const int len = s - tstart; |
| 10732 | if (PL_thisstuff) |
| 10733 | sv_catpvn(PL_thisstuff, tstart, len); |
| 10734 | else |
| 10735 | PL_thisstuff = newSVpvn(tstart, len); |
| 10736 | if (!PL_thisclose && !keep_delims) |
| 10737 | PL_thisclose = newSVpvn(s,termlen); |
| 10738 | } |
| 10739 | #endif |
| 10740 | |
| 10741 | if (keep_delims) |
| 10742 | sv_catpvn(sv, s, termlen); |
| 10743 | s += termlen; |
| 10744 | } |
| 10745 | #ifdef PERL_MAD |
| 10746 | else { |
| 10747 | if (PL_madskills) { |
| 10748 | char * const tstart = SvPVX(PL_linestr) + stuffstart; |
| 10749 | const int len = s - tstart - termlen; |
| 10750 | if (PL_thisstuff) |
| 10751 | sv_catpvn(PL_thisstuff, tstart, len); |
| 10752 | else |
| 10753 | PL_thisstuff = newSVpvn(tstart, len); |
| 10754 | if (!PL_thisclose && !keep_delims) |
| 10755 | PL_thisclose = newSVpvn(s - termlen,termlen); |
| 10756 | } |
| 10757 | } |
| 10758 | #endif |
| 10759 | if (has_utf8 || (PL_encoding && !re_reparse)) |
| 10760 | SvUTF8_on(sv); |
| 10761 | |
| 10762 | PL_multi_end = CopLINE(PL_curcop); |
| 10763 | |
| 10764 | /* if we allocated too much space, give some back */ |
| 10765 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
| 10766 | SvLEN_set(sv, SvCUR(sv) + 1); |
| 10767 | SvPV_renew(sv, SvLEN(sv)); |
| 10768 | } |
| 10769 | |
| 10770 | /* decide whether this is the first or second quoted string we've read |
| 10771 | for this op |
| 10772 | */ |
| 10773 | |
| 10774 | if (PL_lex_stuff) |
| 10775 | PL_sublex_info.repl = sv; |
| 10776 | else |
| 10777 | PL_lex_stuff = sv; |
| 10778 | return s; |
| 10779 | } |
| 10780 | |
| 10781 | /* |
| 10782 | scan_num |
| 10783 | takes: pointer to position in buffer |
| 10784 | returns: pointer to new position in buffer |
| 10785 | side-effects: builds ops for the constant in pl_yylval.op |
| 10786 | |
| 10787 | Read a number in any of the formats that Perl accepts: |
| 10788 | |
| 10789 | \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12. |
| 10790 | \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34 |
| 10791 | 0b[01](_?[01])* |
| 10792 | 0[0-7](_?[0-7])* |
| 10793 | 0x[0-9A-Fa-f](_?[0-9A-Fa-f])* |
| 10794 | |
| 10795 | Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the |
| 10796 | thing it reads. |
| 10797 | |
| 10798 | If it reads a number without a decimal point or an exponent, it will |
| 10799 | try converting the number to an integer and see if it can do so |
| 10800 | without loss of precision. |
| 10801 | */ |
| 10802 | |
| 10803 | char * |
| 10804 | Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp) |
| 10805 | { |
| 10806 | dVAR; |
| 10807 | const char *s = start; /* current position in buffer */ |
| 10808 | char *d; /* destination in temp buffer */ |
| 10809 | char *e; /* end of temp buffer */ |
| 10810 | NV nv; /* number read, as a double */ |
| 10811 | SV *sv = NULL; /* place to put the converted number */ |
| 10812 | bool floatit; /* boolean: int or float? */ |
| 10813 | const char *lastub = NULL; /* position of last underbar */ |
| 10814 | static const char* const number_too_long = "Number too long"; |
| 10815 | |
| 10816 | PERL_ARGS_ASSERT_SCAN_NUM; |
| 10817 | |
| 10818 | /* We use the first character to decide what type of number this is */ |
| 10819 | |
| 10820 | switch (*s) { |
| 10821 | default: |
| 10822 | Perl_croak(aTHX_ "panic: scan_num, *s=%d", *s); |
| 10823 | |
| 10824 | /* if it starts with a 0, it could be an octal number, a decimal in |
| 10825 | 0.13 disguise, or a hexadecimal number, or a binary number. */ |
| 10826 | case '0': |
| 10827 | { |
| 10828 | /* variables: |
| 10829 | u holds the "number so far" |
| 10830 | shift the power of 2 of the base |
| 10831 | (hex == 4, octal == 3, binary == 1) |
| 10832 | overflowed was the number more than we can hold? |
| 10833 | |
| 10834 | Shift is used when we add a digit. It also serves as an "are |
| 10835 | we in octal/hex/binary?" indicator to disallow hex characters |
| 10836 | when in octal mode. |
| 10837 | */ |
| 10838 | NV n = 0.0; |
| 10839 | UV u = 0; |
| 10840 | I32 shift; |
| 10841 | bool overflowed = FALSE; |
| 10842 | bool just_zero = TRUE; /* just plain 0 or binary number? */ |
| 10843 | static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 }; |
| 10844 | static const char* const bases[5] = |
| 10845 | { "", "binary", "", "octal", "hexadecimal" }; |
| 10846 | static const char* const Bases[5] = |
| 10847 | { "", "Binary", "", "Octal", "Hexadecimal" }; |
| 10848 | static const char* const maxima[5] = |
| 10849 | { "", |
| 10850 | "0b11111111111111111111111111111111", |
| 10851 | "", |
| 10852 | "037777777777", |
| 10853 | "0xffffffff" }; |
| 10854 | const char *base, *Base, *max; |
| 10855 | |
| 10856 | /* check for hex */ |
| 10857 | if (s[1] == 'x' || s[1] == 'X') { |
| 10858 | shift = 4; |
| 10859 | s += 2; |
| 10860 | just_zero = FALSE; |
| 10861 | } else if (s[1] == 'b' || s[1] == 'B') { |
| 10862 | shift = 1; |
| 10863 | s += 2; |
| 10864 | just_zero = FALSE; |
| 10865 | } |
| 10866 | /* check for a decimal in disguise */ |
| 10867 | else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E') |
| 10868 | goto decimal; |
| 10869 | /* so it must be octal */ |
| 10870 | else { |
| 10871 | shift = 3; |
| 10872 | s++; |
| 10873 | } |
| 10874 | |
| 10875 | if (*s == '_') { |
| 10876 | Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 10877 | "Misplaced _ in number"); |
| 10878 | lastub = s++; |
| 10879 | } |
| 10880 | |
| 10881 | base = bases[shift]; |
| 10882 | Base = Bases[shift]; |
| 10883 | max = maxima[shift]; |
| 10884 | |
| 10885 | /* read the rest of the number */ |
| 10886 | for (;;) { |
| 10887 | /* x is used in the overflow test, |
| 10888 | b is the digit we're adding on. */ |
| 10889 | UV x, b; |
| 10890 | |
| 10891 | switch (*s) { |
| 10892 | |
| 10893 | /* if we don't mention it, we're done */ |
| 10894 | default: |
| 10895 | goto out; |
| 10896 | |
| 10897 | /* _ are ignored -- but warned about if consecutive */ |
| 10898 | case '_': |
| 10899 | if (lastub && s == lastub + 1) |
| 10900 | Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 10901 | "Misplaced _ in number"); |
| 10902 | lastub = s++; |
| 10903 | break; |
| 10904 | |
| 10905 | /* 8 and 9 are not octal */ |
| 10906 | case '8': case '9': |
| 10907 | if (shift == 3) |
| 10908 | yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s)); |
| 10909 | /* FALL THROUGH */ |
| 10910 | |
| 10911 | /* octal digits */ |
| 10912 | case '2': case '3': case '4': |
| 10913 | case '5': case '6': case '7': |
| 10914 | if (shift == 1) |
| 10915 | yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s)); |
| 10916 | /* FALL THROUGH */ |
| 10917 | |
| 10918 | case '0': case '1': |
| 10919 | b = *s++ & 15; /* ASCII digit -> value of digit */ |
| 10920 | goto digit; |
| 10921 | |
| 10922 | /* hex digits */ |
| 10923 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': |
| 10924 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': |
| 10925 | /* make sure they said 0x */ |
| 10926 | if (shift != 4) |
| 10927 | goto out; |
| 10928 | b = (*s++ & 7) + 9; |
| 10929 | |
| 10930 | /* Prepare to put the digit we have onto the end |
| 10931 | of the number so far. We check for overflows. |
| 10932 | */ |
| 10933 | |
| 10934 | digit: |
| 10935 | just_zero = FALSE; |
| 10936 | if (!overflowed) { |
| 10937 | x = u << shift; /* make room for the digit */ |
| 10938 | |
| 10939 | if ((x >> shift) != u |
| 10940 | && !(PL_hints & HINT_NEW_BINARY)) { |
| 10941 | overflowed = TRUE; |
| 10942 | n = (NV) u; |
| 10943 | Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW), |
| 10944 | "Integer overflow in %s number", |
| 10945 | base); |
| 10946 | } else |
| 10947 | u = x | b; /* add the digit to the end */ |
| 10948 | } |
| 10949 | if (overflowed) { |
| 10950 | n *= nvshift[shift]; |
| 10951 | /* If an NV has not enough bits in its |
| 10952 | * mantissa to represent an UV this summing of |
| 10953 | * small low-order numbers is a waste of time |
| 10954 | * (because the NV cannot preserve the |
| 10955 | * low-order bits anyway): we could just |
| 10956 | * remember when did we overflow and in the |
| 10957 | * end just multiply n by the right |
| 10958 | * amount. */ |
| 10959 | n += (NV) b; |
| 10960 | } |
| 10961 | break; |
| 10962 | } |
| 10963 | } |
| 10964 | |
| 10965 | /* if we get here, we had success: make a scalar value from |
| 10966 | the number. |
| 10967 | */ |
| 10968 | out: |
| 10969 | |
| 10970 | /* final misplaced underbar check */ |
| 10971 | if (s[-1] == '_') { |
| 10972 | Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number"); |
| 10973 | } |
| 10974 | |
| 10975 | if (overflowed) { |
| 10976 | if (n > 4294967295.0) |
| 10977 | Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE), |
| 10978 | "%s number > %s non-portable", |
| 10979 | Base, max); |
| 10980 | sv = newSVnv(n); |
| 10981 | } |
| 10982 | else { |
| 10983 | #if UVSIZE > 4 |
| 10984 | if (u > 0xffffffff) |
| 10985 | Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE), |
| 10986 | "%s number > %s non-portable", |
| 10987 | Base, max); |
| 10988 | #endif |
| 10989 | sv = newSVuv(u); |
| 10990 | } |
| 10991 | if (just_zero && (PL_hints & HINT_NEW_INTEGER)) |
| 10992 | sv = new_constant(start, s - start, "integer", |
| 10993 | sv, NULL, NULL, 0); |
| 10994 | else if (PL_hints & HINT_NEW_BINARY) |
| 10995 | sv = new_constant(start, s - start, "binary", sv, NULL, NULL, 0); |
| 10996 | } |
| 10997 | break; |
| 10998 | |
| 10999 | /* |
| 11000 | handle decimal numbers. |
| 11001 | we're also sent here when we read a 0 as the first digit |
| 11002 | */ |
| 11003 | case '1': case '2': case '3': case '4': case '5': |
| 11004 | case '6': case '7': case '8': case '9': case '.': |
| 11005 | decimal: |
| 11006 | d = PL_tokenbuf; |
| 11007 | e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */ |
| 11008 | floatit = FALSE; |
| 11009 | |
| 11010 | /* read next group of digits and _ and copy into d */ |
| 11011 | while (isDIGIT(*s) || *s == '_') { |
| 11012 | /* skip underscores, checking for misplaced ones |
| 11013 | if -w is on |
| 11014 | */ |
| 11015 | if (*s == '_') { |
| 11016 | if (lastub && s == lastub + 1) |
| 11017 | Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 11018 | "Misplaced _ in number"); |
| 11019 | lastub = s++; |
| 11020 | } |
| 11021 | else { |
| 11022 | /* check for end of fixed-length buffer */ |
| 11023 | if (d >= e) |
| 11024 | Perl_croak(aTHX_ "%s", number_too_long); |
| 11025 | /* if we're ok, copy the character */ |
| 11026 | *d++ = *s++; |
| 11027 | } |
| 11028 | } |
| 11029 | |
| 11030 | /* final misplaced underbar check */ |
| 11031 | if (lastub && s == lastub + 1) { |
| 11032 | Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number"); |
| 11033 | } |
| 11034 | |
| 11035 | /* read a decimal portion if there is one. avoid |
| 11036 | 3..5 being interpreted as the number 3. followed |
| 11037 | by .5 |
| 11038 | */ |
| 11039 | if (*s == '.' && s[1] != '.') { |
| 11040 | floatit = TRUE; |
| 11041 | *d++ = *s++; |
| 11042 | |
| 11043 | if (*s == '_') { |
| 11044 | Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 11045 | "Misplaced _ in number"); |
| 11046 | lastub = s; |
| 11047 | } |
| 11048 | |
| 11049 | /* copy, ignoring underbars, until we run out of digits. |
| 11050 | */ |
| 11051 | for (; isDIGIT(*s) || *s == '_'; s++) { |
| 11052 | /* fixed length buffer check */ |
| 11053 | if (d >= e) |
| 11054 | Perl_croak(aTHX_ "%s", number_too_long); |
| 11055 | if (*s == '_') { |
| 11056 | if (lastub && s == lastub + 1) |
| 11057 | Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 11058 | "Misplaced _ in number"); |
| 11059 | lastub = s; |
| 11060 | } |
| 11061 | else |
| 11062 | *d++ = *s; |
| 11063 | } |
| 11064 | /* fractional part ending in underbar? */ |
| 11065 | if (s[-1] == '_') { |
| 11066 | Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 11067 | "Misplaced _ in number"); |
| 11068 | } |
| 11069 | if (*s == '.' && isDIGIT(s[1])) { |
| 11070 | /* oops, it's really a v-string, but without the "v" */ |
| 11071 | s = start; |
| 11072 | goto vstring; |
| 11073 | } |
| 11074 | } |
| 11075 | |
| 11076 | /* read exponent part, if present */ |
| 11077 | if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) { |
| 11078 | floatit = TRUE; |
| 11079 | s++; |
| 11080 | |
| 11081 | /* regardless of whether user said 3E5 or 3e5, use lower 'e' */ |
| 11082 | *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */ |
| 11083 | |
| 11084 | /* stray preinitial _ */ |
| 11085 | if (*s == '_') { |
| 11086 | Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 11087 | "Misplaced _ in number"); |
| 11088 | lastub = s++; |
| 11089 | } |
| 11090 | |
| 11091 | /* allow positive or negative exponent */ |
| 11092 | if (*s == '+' || *s == '-') |
| 11093 | *d++ = *s++; |
| 11094 | |
| 11095 | /* stray initial _ */ |
| 11096 | if (*s == '_') { |
| 11097 | Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 11098 | "Misplaced _ in number"); |
| 11099 | lastub = s++; |
| 11100 | } |
| 11101 | |
| 11102 | /* read digits of exponent */ |
| 11103 | while (isDIGIT(*s) || *s == '_') { |
| 11104 | if (isDIGIT(*s)) { |
| 11105 | if (d >= e) |
| 11106 | Perl_croak(aTHX_ "%s", number_too_long); |
| 11107 | *d++ = *s++; |
| 11108 | } |
| 11109 | else { |
| 11110 | if (((lastub && s == lastub + 1) || |
| 11111 | (!isDIGIT(s[1]) && s[1] != '_'))) |
| 11112 | Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 11113 | "Misplaced _ in number"); |
| 11114 | lastub = s++; |
| 11115 | } |
| 11116 | } |
| 11117 | } |
| 11118 | |
| 11119 | |
| 11120 | /* |
| 11121 | We try to do an integer conversion first if no characters |
| 11122 | indicating "float" have been found. |
| 11123 | */ |
| 11124 | |
| 11125 | if (!floatit) { |
| 11126 | UV uv; |
| 11127 | const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv); |
| 11128 | |
| 11129 | if (flags == IS_NUMBER_IN_UV) { |
| 11130 | if (uv <= IV_MAX) |
| 11131 | sv = newSViv(uv); /* Prefer IVs over UVs. */ |
| 11132 | else |
| 11133 | sv = newSVuv(uv); |
| 11134 | } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) { |
| 11135 | if (uv <= (UV) IV_MIN) |
| 11136 | sv = newSViv(-(IV)uv); |
| 11137 | else |
| 11138 | floatit = TRUE; |
| 11139 | } else |
| 11140 | floatit = TRUE; |
| 11141 | } |
| 11142 | if (floatit) { |
| 11143 | /* terminate the string */ |
| 11144 | *d = '\0'; |
| 11145 | nv = Atof(PL_tokenbuf); |
| 11146 | sv = newSVnv(nv); |
| 11147 | } |
| 11148 | |
| 11149 | if ( floatit |
| 11150 | ? (PL_hints & HINT_NEW_FLOAT) : (PL_hints & HINT_NEW_INTEGER) ) { |
| 11151 | const char *const key = floatit ? "float" : "integer"; |
| 11152 | const STRLEN keylen = floatit ? 5 : 7; |
| 11153 | sv = S_new_constant(aTHX_ PL_tokenbuf, d - PL_tokenbuf, |
| 11154 | key, keylen, sv, NULL, NULL, 0); |
| 11155 | } |
| 11156 | break; |
| 11157 | |
| 11158 | /* if it starts with a v, it could be a v-string */ |
| 11159 | case 'v': |
| 11160 | vstring: |
| 11161 | sv = newSV(5); /* preallocate storage space */ |
| 11162 | ENTER_with_name("scan_vstring"); |
| 11163 | SAVEFREESV(sv); |
| 11164 | s = scan_vstring(s, PL_bufend, sv); |
| 11165 | SvREFCNT_inc_simple_void_NN(sv); |
| 11166 | LEAVE_with_name("scan_vstring"); |
| 11167 | break; |
| 11168 | } |
| 11169 | |
| 11170 | /* make the op for the constant and return */ |
| 11171 | |
| 11172 | if (sv) |
| 11173 | lvalp->opval = newSVOP(OP_CONST, 0, sv); |
| 11174 | else |
| 11175 | lvalp->opval = NULL; |
| 11176 | |
| 11177 | return (char *)s; |
| 11178 | } |
| 11179 | |
| 11180 | STATIC char * |
| 11181 | S_scan_formline(pTHX_ char *s) |
| 11182 | { |
| 11183 | dVAR; |
| 11184 | char *eol; |
| 11185 | char *t; |
| 11186 | SV * const stuff = newSVpvs(""); |
| 11187 | bool needargs = FALSE; |
| 11188 | bool eofmt = FALSE; |
| 11189 | #ifdef PERL_MAD |
| 11190 | char *tokenstart = s; |
| 11191 | SV* savewhite = NULL; |
| 11192 | |
| 11193 | if (PL_madskills) { |
| 11194 | savewhite = PL_thiswhite; |
| 11195 | PL_thiswhite = 0; |
| 11196 | } |
| 11197 | #endif |
| 11198 | |
| 11199 | PERL_ARGS_ASSERT_SCAN_FORMLINE; |
| 11200 | |
| 11201 | while (!needargs) { |
| 11202 | if (*s == '.') { |
| 11203 | t = s+1; |
| 11204 | #ifdef PERL_STRICT_CR |
| 11205 | while (SPACE_OR_TAB(*t)) |
| 11206 | t++; |
| 11207 | #else |
| 11208 | while (SPACE_OR_TAB(*t) || *t == '\r') |
| 11209 | t++; |
| 11210 | #endif |
| 11211 | if (*t == '\n' || t == PL_bufend) { |
| 11212 | eofmt = TRUE; |
| 11213 | break; |
| 11214 | } |
| 11215 | } |
| 11216 | eol = (char *) memchr(s,'\n',PL_bufend-s); |
| 11217 | if (!eol++) |
| 11218 | eol = PL_bufend; |
| 11219 | if (*s != '#') { |
| 11220 | for (t = s; t < eol; t++) { |
| 11221 | if (*t == '~' && t[1] == '~' && SvCUR(stuff)) { |
| 11222 | needargs = FALSE; |
| 11223 | goto enough; /* ~~ must be first line in formline */ |
| 11224 | } |
| 11225 | if (*t == '@' || *t == '^') |
| 11226 | needargs = TRUE; |
| 11227 | } |
| 11228 | if (eol > s) { |
| 11229 | sv_catpvn(stuff, s, eol-s); |
| 11230 | #ifndef PERL_STRICT_CR |
| 11231 | if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') { |
| 11232 | char *end = SvPVX(stuff) + SvCUR(stuff); |
| 11233 | end[-2] = '\n'; |
| 11234 | end[-1] = '\0'; |
| 11235 | SvCUR_set(stuff, SvCUR(stuff) - 1); |
| 11236 | } |
| 11237 | #endif |
| 11238 | } |
| 11239 | else |
| 11240 | break; |
| 11241 | } |
| 11242 | s = (char*)eol; |
| 11243 | if ((PL_rsfp || PL_parser->filtered) |
| 11244 | && PL_parser->form_lex_state == LEX_NORMAL) { |
| 11245 | bool got_some; |
| 11246 | #ifdef PERL_MAD |
| 11247 | if (PL_madskills) { |
| 11248 | if (PL_thistoken) |
| 11249 | sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart); |
| 11250 | else |
| 11251 | PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart); |
| 11252 | } |
| 11253 | #endif |
| 11254 | PL_bufptr = PL_bufend; |
| 11255 | COPLINE_INC_WITH_HERELINES; |
| 11256 | got_some = lex_next_chunk(0); |
| 11257 | CopLINE_dec(PL_curcop); |
| 11258 | s = PL_bufptr; |
| 11259 | #ifdef PERL_MAD |
| 11260 | tokenstart = PL_bufptr; |
| 11261 | #endif |
| 11262 | if (!got_some) |
| 11263 | break; |
| 11264 | } |
| 11265 | incline(s); |
| 11266 | } |
| 11267 | enough: |
| 11268 | if (!SvCUR(stuff) || needargs) |
| 11269 | PL_lex_state = PL_parser->form_lex_state; |
| 11270 | if (SvCUR(stuff)) { |
| 11271 | PL_expect = XSTATE; |
| 11272 | if (needargs) { |
| 11273 | start_force(PL_curforce); |
| 11274 | NEXTVAL_NEXTTOKE.ival = 0; |
| 11275 | force_next(FORMLBRACK); |
| 11276 | } |
| 11277 | if (!IN_BYTES) { |
| 11278 | if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff))) |
| 11279 | SvUTF8_on(stuff); |
| 11280 | else if (PL_encoding) |
| 11281 | sv_recode_to_utf8(stuff, PL_encoding); |
| 11282 | } |
| 11283 | start_force(PL_curforce); |
| 11284 | NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff); |
| 11285 | force_next(THING); |
| 11286 | } |
| 11287 | else { |
| 11288 | SvREFCNT_dec(stuff); |
| 11289 | if (eofmt) |
| 11290 | PL_lex_formbrack = 0; |
| 11291 | } |
| 11292 | #ifdef PERL_MAD |
| 11293 | if (PL_madskills) { |
| 11294 | if (PL_thistoken) |
| 11295 | sv_catpvn(PL_thistoken, tokenstart, s - tokenstart); |
| 11296 | else |
| 11297 | PL_thistoken = newSVpvn(tokenstart, s - tokenstart); |
| 11298 | PL_thiswhite = savewhite; |
| 11299 | } |
| 11300 | #endif |
| 11301 | return s; |
| 11302 | } |
| 11303 | |
| 11304 | I32 |
| 11305 | Perl_start_subparse(pTHX_ I32 is_format, U32 flags) |
| 11306 | { |
| 11307 | dVAR; |
| 11308 | const I32 oldsavestack_ix = PL_savestack_ix; |
| 11309 | CV* const outsidecv = PL_compcv; |
| 11310 | |
| 11311 | SAVEI32(PL_subline); |
| 11312 | save_item(PL_subname); |
| 11313 | SAVESPTR(PL_compcv); |
| 11314 | |
| 11315 | PL_compcv = MUTABLE_CV(newSV_type(is_format ? SVt_PVFM : SVt_PVCV)); |
| 11316 | CvFLAGS(PL_compcv) |= flags; |
| 11317 | |
| 11318 | PL_subline = CopLINE(PL_curcop); |
| 11319 | CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB); |
| 11320 | CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outsidecv)); |
| 11321 | CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax; |
| 11322 | if (outsidecv && CvPADLIST(outsidecv)) |
| 11323 | CvPADLIST(PL_compcv)->xpadl_outid = |
| 11324 | PadlistNAMES(CvPADLIST(outsidecv)); |
| 11325 | |
| 11326 | return oldsavestack_ix; |
| 11327 | } |
| 11328 | |
| 11329 | #ifdef __SC__ |
| 11330 | #pragma segment Perl_yylex |
| 11331 | #endif |
| 11332 | static int |
| 11333 | S_yywarn(pTHX_ const char *const s, U32 flags) |
| 11334 | { |
| 11335 | dVAR; |
| 11336 | |
| 11337 | PERL_ARGS_ASSERT_YYWARN; |
| 11338 | |
| 11339 | PL_in_eval |= EVAL_WARNONLY; |
| 11340 | yyerror_pv(s, flags); |
| 11341 | PL_in_eval &= ~EVAL_WARNONLY; |
| 11342 | return 0; |
| 11343 | } |
| 11344 | |
| 11345 | int |
| 11346 | Perl_yyerror(pTHX_ const char *const s) |
| 11347 | { |
| 11348 | PERL_ARGS_ASSERT_YYERROR; |
| 11349 | return yyerror_pvn(s, strlen(s), 0); |
| 11350 | } |
| 11351 | |
| 11352 | int |
| 11353 | Perl_yyerror_pv(pTHX_ const char *const s, U32 flags) |
| 11354 | { |
| 11355 | PERL_ARGS_ASSERT_YYERROR_PV; |
| 11356 | return yyerror_pvn(s, strlen(s), flags); |
| 11357 | } |
| 11358 | |
| 11359 | int |
| 11360 | Perl_yyerror_pvn(pTHX_ const char *const s, STRLEN len, U32 flags) |
| 11361 | { |
| 11362 | dVAR; |
| 11363 | const char *context = NULL; |
| 11364 | int contlen = -1; |
| 11365 | SV *msg; |
| 11366 | SV * const where_sv = newSVpvs_flags("", SVs_TEMP); |
| 11367 | int yychar = PL_parser->yychar; |
| 11368 | |
| 11369 | PERL_ARGS_ASSERT_YYERROR_PVN; |
| 11370 | |
| 11371 | if (!yychar || (yychar == ';' && !PL_rsfp)) |
| 11372 | sv_catpvs(where_sv, "at EOF"); |
| 11373 | else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr && |
| 11374 | PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr && |
| 11375 | PL_oldbufptr != PL_bufptr) { |
| 11376 | /* |
| 11377 | Only for NetWare: |
| 11378 | The code below is removed for NetWare because it abends/crashes on NetWare |
| 11379 | when the script has error such as not having the closing quotes like: |
| 11380 | if ($var eq "value) |
| 11381 | Checking of white spaces is anyway done in NetWare code. |
| 11382 | */ |
| 11383 | #ifndef NETWARE |
| 11384 | while (isSPACE(*PL_oldoldbufptr)) |
| 11385 | PL_oldoldbufptr++; |
| 11386 | #endif |
| 11387 | context = PL_oldoldbufptr; |
| 11388 | contlen = PL_bufptr - PL_oldoldbufptr; |
| 11389 | } |
| 11390 | else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr && |
| 11391 | PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) { |
| 11392 | /* |
| 11393 | Only for NetWare: |
| 11394 | The code below is removed for NetWare because it abends/crashes on NetWare |
| 11395 | when the script has error such as not having the closing quotes like: |
| 11396 | if ($var eq "value) |
| 11397 | Checking of white spaces is anyway done in NetWare code. |
| 11398 | */ |
| 11399 | #ifndef NETWARE |
| 11400 | while (isSPACE(*PL_oldbufptr)) |
| 11401 | PL_oldbufptr++; |
| 11402 | #endif |
| 11403 | context = PL_oldbufptr; |
| 11404 | contlen = PL_bufptr - PL_oldbufptr; |
| 11405 | } |
| 11406 | else if (yychar > 255) |
| 11407 | sv_catpvs(where_sv, "next token ???"); |
| 11408 | else if (yychar == -2) { /* YYEMPTY */ |
| 11409 | if (PL_lex_state == LEX_NORMAL || |
| 11410 | (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL)) |
| 11411 | sv_catpvs(where_sv, "at end of line"); |
| 11412 | else if (PL_lex_inpat) |
| 11413 | sv_catpvs(where_sv, "within pattern"); |
| 11414 | else |
| 11415 | sv_catpvs(where_sv, "within string"); |
| 11416 | } |
| 11417 | else { |
| 11418 | sv_catpvs(where_sv, "next char "); |
| 11419 | if (yychar < 32) |
| 11420 | Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar)); |
| 11421 | else if (isPRINT_LC(yychar)) { |
| 11422 | const char string = yychar; |
| 11423 | sv_catpvn(where_sv, &string, 1); |
| 11424 | } |
| 11425 | else |
| 11426 | Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255); |
| 11427 | } |
| 11428 | msg = newSVpvn_flags(s, len, (flags & SVf_UTF8) | SVs_TEMP); |
| 11429 | Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ", |
| 11430 | OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop)); |
| 11431 | if (context) |
| 11432 | Perl_sv_catpvf(aTHX_ msg, "near \"%"UTF8f"\"\n", |
| 11433 | UTF8fARG(UTF, contlen, context)); |
| 11434 | else |
| 11435 | Perl_sv_catpvf(aTHX_ msg, "%"SVf"\n", SVfARG(where_sv)); |
| 11436 | if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) { |
| 11437 | Perl_sv_catpvf(aTHX_ msg, |
| 11438 | " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n", |
| 11439 | (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start); |
| 11440 | PL_multi_end = 0; |
| 11441 | } |
| 11442 | if (PL_in_eval & EVAL_WARNONLY) { |
| 11443 | Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg)); |
| 11444 | } |
| 11445 | else |
| 11446 | qerror(msg); |
| 11447 | if (PL_error_count >= 10) { |
| 11448 | SV * errsv; |
| 11449 | if (PL_in_eval && ((errsv = ERRSV), SvCUR(errsv))) |
| 11450 | Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n", |
| 11451 | SVfARG(errsv), OutCopFILE(PL_curcop)); |
| 11452 | else |
| 11453 | Perl_croak(aTHX_ "%s has too many errors.\n", |
| 11454 | OutCopFILE(PL_curcop)); |
| 11455 | } |
| 11456 | PL_in_my = 0; |
| 11457 | PL_in_my_stash = NULL; |
| 11458 | return 0; |
| 11459 | } |
| 11460 | #ifdef __SC__ |
| 11461 | #pragma segment Main |
| 11462 | #endif |
| 11463 | |
| 11464 | STATIC char* |
| 11465 | S_swallow_bom(pTHX_ U8 *s) |
| 11466 | { |
| 11467 | dVAR; |
| 11468 | const STRLEN slen = SvCUR(PL_linestr); |
| 11469 | |
| 11470 | PERL_ARGS_ASSERT_SWALLOW_BOM; |
| 11471 | |
| 11472 | switch (s[0]) { |
| 11473 | case 0xFF: |
| 11474 | if (s[1] == 0xFE) { |
| 11475 | /* UTF-16 little-endian? (or UTF-32LE?) */ |
| 11476 | if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */ |
| 11477 | /* diag_listed_as: Unsupported script encoding %s */ |
| 11478 | Perl_croak(aTHX_ "Unsupported script encoding UTF-32LE"); |
| 11479 | #ifndef PERL_NO_UTF16_FILTER |
| 11480 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (BOM)\n"); |
| 11481 | s += 2; |
| 11482 | if (PL_bufend > (char*)s) { |
| 11483 | s = add_utf16_textfilter(s, TRUE); |
| 11484 | } |
| 11485 | #else |
| 11486 | /* diag_listed_as: Unsupported script encoding %s */ |
| 11487 | Perl_croak(aTHX_ "Unsupported script encoding UTF-16LE"); |
| 11488 | #endif |
| 11489 | } |
| 11490 | break; |
| 11491 | case 0xFE: |
| 11492 | if (s[1] == 0xFF) { /* UTF-16 big-endian? */ |
| 11493 | #ifndef PERL_NO_UTF16_FILTER |
| 11494 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n"); |
| 11495 | s += 2; |
| 11496 | if (PL_bufend > (char *)s) { |
| 11497 | s = add_utf16_textfilter(s, FALSE); |
| 11498 | } |
| 11499 | #else |
| 11500 | /* diag_listed_as: Unsupported script encoding %s */ |
| 11501 | Perl_croak(aTHX_ "Unsupported script encoding UTF-16BE"); |
| 11502 | #endif |
| 11503 | } |
| 11504 | break; |
| 11505 | case 0xEF: |
| 11506 | if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) { |
| 11507 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n"); |
| 11508 | s += 3; /* UTF-8 */ |
| 11509 | } |
| 11510 | break; |
| 11511 | case 0: |
| 11512 | if (slen > 3) { |
| 11513 | if (s[1] == 0) { |
| 11514 | if (s[2] == 0xFE && s[3] == 0xFF) { |
| 11515 | /* UTF-32 big-endian */ |
| 11516 | /* diag_listed_as: Unsupported script encoding %s */ |
| 11517 | Perl_croak(aTHX_ "Unsupported script encoding UTF-32BE"); |
| 11518 | } |
| 11519 | } |
| 11520 | else if (s[2] == 0 && s[3] != 0) { |
| 11521 | /* Leading bytes |
| 11522 | * 00 xx 00 xx |
| 11523 | * are a good indicator of UTF-16BE. */ |
| 11524 | #ifndef PERL_NO_UTF16_FILTER |
| 11525 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n"); |
| 11526 | s = add_utf16_textfilter(s, FALSE); |
| 11527 | #else |
| 11528 | /* diag_listed_as: Unsupported script encoding %s */ |
| 11529 | Perl_croak(aTHX_ "Unsupported script encoding UTF-16BE"); |
| 11530 | #endif |
| 11531 | } |
| 11532 | } |
| 11533 | #ifdef EBCDIC |
| 11534 | case 0xDD: |
| 11535 | if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) { |
| 11536 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n"); |
| 11537 | s += 4; /* UTF-8 */ |
| 11538 | } |
| 11539 | break; |
| 11540 | #endif |
| 11541 | |
| 11542 | default: |
| 11543 | if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) { |
| 11544 | /* Leading bytes |
| 11545 | * xx 00 xx 00 |
| 11546 | * are a good indicator of UTF-16LE. */ |
| 11547 | #ifndef PERL_NO_UTF16_FILTER |
| 11548 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n"); |
| 11549 | s = add_utf16_textfilter(s, TRUE); |
| 11550 | #else |
| 11551 | /* diag_listed_as: Unsupported script encoding %s */ |
| 11552 | Perl_croak(aTHX_ "Unsupported script encoding UTF-16LE"); |
| 11553 | #endif |
| 11554 | } |
| 11555 | } |
| 11556 | return (char*)s; |
| 11557 | } |
| 11558 | |
| 11559 | |
| 11560 | #ifndef PERL_NO_UTF16_FILTER |
| 11561 | static I32 |
| 11562 | S_utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
| 11563 | { |
| 11564 | dVAR; |
| 11565 | SV *const filter = FILTER_DATA(idx); |
| 11566 | /* We re-use this each time round, throwing the contents away before we |
| 11567 | return. */ |
| 11568 | SV *const utf16_buffer = MUTABLE_SV(IoTOP_GV(filter)); |
| 11569 | SV *const utf8_buffer = filter; |
| 11570 | IV status = IoPAGE(filter); |
| 11571 | const bool reverse = cBOOL(IoLINES(filter)); |
| 11572 | I32 retval; |
| 11573 | |
| 11574 | PERL_ARGS_ASSERT_UTF16_TEXTFILTER; |
| 11575 | |
| 11576 | /* As we're automatically added, at the lowest level, and hence only called |
| 11577 | from this file, we can be sure that we're not called in block mode. Hence |
| 11578 | don't bother writing code to deal with block mode. */ |
| 11579 | if (maxlen) { |
| 11580 | Perl_croak(aTHX_ "panic: utf16_textfilter called in block mode (for %d characters)", maxlen); |
| 11581 | } |
| 11582 | if (status < 0) { |
| 11583 | Perl_croak(aTHX_ "panic: utf16_textfilter called after error (status=%"IVdf")", status); |
| 11584 | } |
| 11585 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
| 11586 | "utf16_textfilter(%p,%ce): idx=%d maxlen=%d status=%"IVdf" utf16=%"UVuf" utf8=%"UVuf"\n", |
| 11587 | FPTR2DPTR(void *, S_utf16_textfilter), |
| 11588 | reverse ? 'l' : 'b', idx, maxlen, status, |
| 11589 | (UV)SvCUR(utf16_buffer), (UV)SvCUR(utf8_buffer))); |
| 11590 | |
| 11591 | while (1) { |
| 11592 | STRLEN chars; |
| 11593 | STRLEN have; |
| 11594 | I32 newlen; |
| 11595 | U8 *end; |
| 11596 | /* First, look in our buffer of existing UTF-8 data: */ |
| 11597 | char *nl = (char *)memchr(SvPVX(utf8_buffer), '\n', SvCUR(utf8_buffer)); |
| 11598 | |
| 11599 | if (nl) { |
| 11600 | ++nl; |
| 11601 | } else if (status == 0) { |
| 11602 | /* EOF */ |
| 11603 | IoPAGE(filter) = 0; |
| 11604 | nl = SvEND(utf8_buffer); |
| 11605 | } |
| 11606 | if (nl) { |
| 11607 | STRLEN got = nl - SvPVX(utf8_buffer); |
| 11608 | /* Did we have anything to append? */ |
| 11609 | retval = got != 0; |
| 11610 | sv_catpvn(sv, SvPVX(utf8_buffer), got); |
| 11611 | /* Everything else in this code works just fine if SVp_POK isn't |
| 11612 | set. This, however, needs it, and we need it to work, else |
| 11613 | we loop infinitely because the buffer is never consumed. */ |
| 11614 | sv_chop(utf8_buffer, nl); |
| 11615 | break; |
| 11616 | } |
| 11617 | |
| 11618 | /* OK, not a complete line there, so need to read some more UTF-16. |
| 11619 | Read an extra octect if the buffer currently has an odd number. */ |
| 11620 | while (1) { |
| 11621 | if (status <= 0) |
| 11622 | break; |
| 11623 | if (SvCUR(utf16_buffer) >= 2) { |
| 11624 | /* Location of the high octet of the last complete code point. |
| 11625 | Gosh, UTF-16 is a pain. All the benefits of variable length, |
| 11626 | *coupled* with all the benefits of partial reads and |
| 11627 | endianness. */ |
| 11628 | const U8 *const last_hi = (U8*)SvPVX(utf16_buffer) |
| 11629 | + ((SvCUR(utf16_buffer) & ~1) - (reverse ? 1 : 2)); |
| 11630 | |
| 11631 | if (*last_hi < 0xd8 || *last_hi > 0xdb) { |
| 11632 | break; |
| 11633 | } |
| 11634 | |
| 11635 | /* We have the first half of a surrogate. Read more. */ |
| 11636 | DEBUG_P(PerlIO_printf(Perl_debug_log, "utf16_textfilter partial surrogate detected at %p\n", last_hi)); |
| 11637 | } |
| 11638 | |
| 11639 | status = FILTER_READ(idx + 1, utf16_buffer, |
| 11640 | 160 + (SvCUR(utf16_buffer) & 1)); |
| 11641 | DEBUG_P(PerlIO_printf(Perl_debug_log, "utf16_textfilter status=%"IVdf" SvCUR(sv)=%"UVuf"\n", status, (UV)SvCUR(utf16_buffer))); |
| 11642 | DEBUG_P({ sv_dump(utf16_buffer); sv_dump(utf8_buffer);}); |
| 11643 | if (status < 0) { |
| 11644 | /* Error */ |
| 11645 | IoPAGE(filter) = status; |
| 11646 | return status; |
| 11647 | } |
| 11648 | } |
| 11649 | |
| 11650 | chars = SvCUR(utf16_buffer) >> 1; |
| 11651 | have = SvCUR(utf8_buffer); |
| 11652 | SvGROW(utf8_buffer, have + chars * 3 + 1); |
| 11653 | |
| 11654 | if (reverse) { |
| 11655 | end = utf16_to_utf8_reversed((U8*)SvPVX(utf16_buffer), |
| 11656 | (U8*)SvPVX_const(utf8_buffer) + have, |
| 11657 | chars * 2, &newlen); |
| 11658 | } else { |
| 11659 | end = utf16_to_utf8((U8*)SvPVX(utf16_buffer), |
| 11660 | (U8*)SvPVX_const(utf8_buffer) + have, |
| 11661 | chars * 2, &newlen); |
| 11662 | } |
| 11663 | SvCUR_set(utf8_buffer, have + newlen); |
| 11664 | *end = '\0'; |
| 11665 | |
| 11666 | /* No need to keep this SV "well-formed" with a '\0' after the end, as |
| 11667 | it's private to us, and utf16_to_utf8{,reversed} take a |
| 11668 | (pointer,length) pair, rather than a NUL-terminated string. */ |
| 11669 | if(SvCUR(utf16_buffer) & 1) { |
| 11670 | *SvPVX(utf16_buffer) = SvEND(utf16_buffer)[-1]; |
| 11671 | SvCUR_set(utf16_buffer, 1); |
| 11672 | } else { |
| 11673 | SvCUR_set(utf16_buffer, 0); |
| 11674 | } |
| 11675 | } |
| 11676 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
| 11677 | "utf16_textfilter: returns, status=%"IVdf" utf16=%"UVuf" utf8=%"UVuf"\n", |
| 11678 | status, |
| 11679 | (UV)SvCUR(utf16_buffer), (UV)SvCUR(utf8_buffer))); |
| 11680 | DEBUG_P({ sv_dump(utf8_buffer); sv_dump(sv);}); |
| 11681 | return retval; |
| 11682 | } |
| 11683 | |
| 11684 | static U8 * |
| 11685 | S_add_utf16_textfilter(pTHX_ U8 *const s, bool reversed) |
| 11686 | { |
| 11687 | SV *filter = filter_add(S_utf16_textfilter, NULL); |
| 11688 | |
| 11689 | PERL_ARGS_ASSERT_ADD_UTF16_TEXTFILTER; |
| 11690 | |
| 11691 | IoTOP_GV(filter) = MUTABLE_GV(newSVpvn((char *)s, PL_bufend - (char*)s)); |
| 11692 | sv_setpvs(filter, ""); |
| 11693 | IoLINES(filter) = reversed; |
| 11694 | IoPAGE(filter) = 1; /* Not EOF */ |
| 11695 | |
| 11696 | /* Sadly, we have to return a valid pointer, come what may, so we have to |
| 11697 | ignore any error return from this. */ |
| 11698 | SvCUR_set(PL_linestr, 0); |
| 11699 | if (FILTER_READ(0, PL_linestr, 0)) { |
| 11700 | SvUTF8_on(PL_linestr); |
| 11701 | } else { |
| 11702 | SvUTF8_on(PL_linestr); |
| 11703 | } |
| 11704 | PL_bufend = SvEND(PL_linestr); |
| 11705 | return (U8*)SvPVX(PL_linestr); |
| 11706 | } |
| 11707 | #endif |
| 11708 | |
| 11709 | /* |
| 11710 | Returns a pointer to the next character after the parsed |
| 11711 | vstring, as well as updating the passed in sv. |
| 11712 | |
| 11713 | Function must be called like |
| 11714 | |
| 11715 | sv = sv_2mortal(newSV(5)); |
| 11716 | s = scan_vstring(s,e,sv); |
| 11717 | |
| 11718 | where s and e are the start and end of the string. |
| 11719 | The sv should already be large enough to store the vstring |
| 11720 | passed in, for performance reasons. |
| 11721 | |
| 11722 | This function may croak if fatal warnings are enabled in the |
| 11723 | calling scope, hence the sv_2mortal in the example (to prevent |
| 11724 | a leak). Make sure to do SvREFCNT_inc afterwards if you use |
| 11725 | sv_2mortal. |
| 11726 | |
| 11727 | */ |
| 11728 | |
| 11729 | char * |
| 11730 | Perl_scan_vstring(pTHX_ const char *s, const char *const e, SV *sv) |
| 11731 | { |
| 11732 | dVAR; |
| 11733 | const char *pos = s; |
| 11734 | const char *start = s; |
| 11735 | |
| 11736 | PERL_ARGS_ASSERT_SCAN_VSTRING; |
| 11737 | |
| 11738 | if (*pos == 'v') pos++; /* get past 'v' */ |
| 11739 | while (pos < e && (isDIGIT(*pos) || *pos == '_')) |
| 11740 | pos++; |
| 11741 | if ( *pos != '.') { |
| 11742 | /* this may not be a v-string if followed by => */ |
| 11743 | const char *next = pos; |
| 11744 | while (next < e && isSPACE(*next)) |
| 11745 | ++next; |
| 11746 | if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) { |
| 11747 | /* return string not v-string */ |
| 11748 | sv_setpvn(sv,(char *)s,pos-s); |
| 11749 | return (char *)pos; |
| 11750 | } |
| 11751 | } |
| 11752 | |
| 11753 | if (!isALPHA(*pos)) { |
| 11754 | U8 tmpbuf[UTF8_MAXBYTES+1]; |
| 11755 | |
| 11756 | if (*s == 'v') |
| 11757 | s++; /* get past 'v' */ |
| 11758 | |
| 11759 | sv_setpvs(sv, ""); |
| 11760 | |
| 11761 | for (;;) { |
| 11762 | /* this is atoi() that tolerates underscores */ |
| 11763 | U8 *tmpend; |
| 11764 | UV rev = 0; |
| 11765 | const char *end = pos; |
| 11766 | UV mult = 1; |
| 11767 | while (--end >= s) { |
| 11768 | if (*end != '_') { |
| 11769 | const UV orev = rev; |
| 11770 | rev += (*end - '0') * mult; |
| 11771 | mult *= 10; |
| 11772 | if (orev > rev) |
| 11773 | /* diag_listed_as: Integer overflow in %s number */ |
| 11774 | Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW), |
| 11775 | "Integer overflow in decimal number"); |
| 11776 | } |
| 11777 | } |
| 11778 | #ifdef EBCDIC |
| 11779 | if (rev > 0x7FFFFFFF) |
| 11780 | Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647"); |
| 11781 | #endif |
| 11782 | /* Append native character for the rev point */ |
| 11783 | tmpend = uvchr_to_utf8(tmpbuf, rev); |
| 11784 | sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf); |
| 11785 | if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev))) |
| 11786 | SvUTF8_on(sv); |
| 11787 | if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1])) |
| 11788 | s = ++pos; |
| 11789 | else { |
| 11790 | s = pos; |
| 11791 | break; |
| 11792 | } |
| 11793 | while (pos < e && (isDIGIT(*pos) || *pos == '_')) |
| 11794 | pos++; |
| 11795 | } |
| 11796 | SvPOK_on(sv); |
| 11797 | sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start); |
| 11798 | SvRMAGICAL_on(sv); |
| 11799 | } |
| 11800 | return (char *)s; |
| 11801 | } |
| 11802 | |
| 11803 | int |
| 11804 | Perl_keyword_plugin_standard(pTHX_ |
| 11805 | char *keyword_ptr, STRLEN keyword_len, OP **op_ptr) |
| 11806 | { |
| 11807 | PERL_ARGS_ASSERT_KEYWORD_PLUGIN_STANDARD; |
| 11808 | PERL_UNUSED_CONTEXT; |
| 11809 | PERL_UNUSED_ARG(keyword_ptr); |
| 11810 | PERL_UNUSED_ARG(keyword_len); |
| 11811 | PERL_UNUSED_ARG(op_ptr); |
| 11812 | return KEYWORD_PLUGIN_DECLINE; |
| 11813 | } |
| 11814 | |
| 11815 | #define parse_recdescent(g,p) S_parse_recdescent(aTHX_ g,p) |
| 11816 | static void |
| 11817 | S_parse_recdescent(pTHX_ int gramtype, I32 fakeeof) |
| 11818 | { |
| 11819 | SAVEI32(PL_lex_brackets); |
| 11820 | if (PL_lex_brackets > 100) |
| 11821 | Renew(PL_lex_brackstack, PL_lex_brackets + 10, char); |
| 11822 | PL_lex_brackstack[PL_lex_brackets++] = XFAKEEOF; |
| 11823 | SAVEI32(PL_lex_allbrackets); |
| 11824 | PL_lex_allbrackets = 0; |
| 11825 | SAVEI8(PL_lex_fakeeof); |
| 11826 | PL_lex_fakeeof = (U8)fakeeof; |
| 11827 | if(yyparse(gramtype) && !PL_parser->error_count) |
| 11828 | qerror(Perl_mess(aTHX_ "Parse error")); |
| 11829 | } |
| 11830 | |
| 11831 | #define parse_recdescent_for_op(g,p) S_parse_recdescent_for_op(aTHX_ g,p) |
| 11832 | static OP * |
| 11833 | S_parse_recdescent_for_op(pTHX_ int gramtype, I32 fakeeof) |
| 11834 | { |
| 11835 | OP *o; |
| 11836 | ENTER; |
| 11837 | SAVEVPTR(PL_eval_root); |
| 11838 | PL_eval_root = NULL; |
| 11839 | parse_recdescent(gramtype, fakeeof); |
| 11840 | o = PL_eval_root; |
| 11841 | LEAVE; |
| 11842 | return o; |
| 11843 | } |
| 11844 | |
| 11845 | #define parse_expr(p,f) S_parse_expr(aTHX_ p,f) |
| 11846 | static OP * |
| 11847 | S_parse_expr(pTHX_ I32 fakeeof, U32 flags) |
| 11848 | { |
| 11849 | OP *exprop; |
| 11850 | if (flags & ~PARSE_OPTIONAL) |
| 11851 | Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_expr"); |
| 11852 | exprop = parse_recdescent_for_op(GRAMEXPR, fakeeof); |
| 11853 | if (!exprop && !(flags & PARSE_OPTIONAL)) { |
| 11854 | if (!PL_parser->error_count) |
| 11855 | qerror(Perl_mess(aTHX_ "Parse error")); |
| 11856 | exprop = newOP(OP_NULL, 0); |
| 11857 | } |
| 11858 | return exprop; |
| 11859 | } |
| 11860 | |
| 11861 | /* |
| 11862 | =for apidoc Amx|OP *|parse_arithexpr|U32 flags |
| 11863 | |
| 11864 | Parse a Perl arithmetic expression. This may contain operators of precedence |
| 11865 | down to the bit shift operators. The expression must be followed (and thus |
| 11866 | terminated) either by a comparison or lower-precedence operator or by |
| 11867 | something that would normally terminate an expression such as semicolon. |
| 11868 | If I<flags> includes C<PARSE_OPTIONAL> then the expression is optional, |
| 11869 | otherwise it is mandatory. It is up to the caller to ensure that the |
| 11870 | dynamic parser state (L</PL_parser> et al) is correctly set to reflect |
| 11871 | the source of the code to be parsed and the lexical context for the |
| 11872 | expression. |
| 11873 | |
| 11874 | The op tree representing the expression is returned. If an optional |
| 11875 | expression is absent, a null pointer is returned, otherwise the pointer |
| 11876 | will be non-null. |
| 11877 | |
| 11878 | If an error occurs in parsing or compilation, in most cases a valid op |
| 11879 | tree is returned anyway. The error is reflected in the parser state, |
| 11880 | normally resulting in a single exception at the top level of parsing |
| 11881 | which covers all the compilation errors that occurred. Some compilation |
| 11882 | errors, however, will throw an exception immediately. |
| 11883 | |
| 11884 | =cut |
| 11885 | */ |
| 11886 | |
| 11887 | OP * |
| 11888 | Perl_parse_arithexpr(pTHX_ U32 flags) |
| 11889 | { |
| 11890 | return parse_expr(LEX_FAKEEOF_COMPARE, flags); |
| 11891 | } |
| 11892 | |
| 11893 | /* |
| 11894 | =for apidoc Amx|OP *|parse_termexpr|U32 flags |
| 11895 | |
| 11896 | Parse a Perl term expression. This may contain operators of precedence |
| 11897 | down to the assignment operators. The expression must be followed (and thus |
| 11898 | terminated) either by a comma or lower-precedence operator or by |
| 11899 | something that would normally terminate an expression such as semicolon. |
| 11900 | If I<flags> includes C<PARSE_OPTIONAL> then the expression is optional, |
| 11901 | otherwise it is mandatory. It is up to the caller to ensure that the |
| 11902 | dynamic parser state (L</PL_parser> et al) is correctly set to reflect |
| 11903 | the source of the code to be parsed and the lexical context for the |
| 11904 | expression. |
| 11905 | |
| 11906 | The op tree representing the expression is returned. If an optional |
| 11907 | expression is absent, a null pointer is returned, otherwise the pointer |
| 11908 | will be non-null. |
| 11909 | |
| 11910 | If an error occurs in parsing or compilation, in most cases a valid op |
| 11911 | tree is returned anyway. The error is reflected in the parser state, |
| 11912 | normally resulting in a single exception at the top level of parsing |
| 11913 | which covers all the compilation errors that occurred. Some compilation |
| 11914 | errors, however, will throw an exception immediately. |
| 11915 | |
| 11916 | =cut |
| 11917 | */ |
| 11918 | |
| 11919 | OP * |
| 11920 | Perl_parse_termexpr(pTHX_ U32 flags) |
| 11921 | { |
| 11922 | return parse_expr(LEX_FAKEEOF_COMMA, flags); |
| 11923 | } |
| 11924 | |
| 11925 | /* |
| 11926 | =for apidoc Amx|OP *|parse_listexpr|U32 flags |
| 11927 | |
| 11928 | Parse a Perl list expression. This may contain operators of precedence |
| 11929 | down to the comma operator. The expression must be followed (and thus |
| 11930 | terminated) either by a low-precedence logic operator such as C<or> or by |
| 11931 | something that would normally terminate an expression such as semicolon. |
| 11932 | If I<flags> includes C<PARSE_OPTIONAL> then the expression is optional, |
| 11933 | otherwise it is mandatory. It is up to the caller to ensure that the |
| 11934 | dynamic parser state (L</PL_parser> et al) is correctly set to reflect |
| 11935 | the source of the code to be parsed and the lexical context for the |
| 11936 | expression. |
| 11937 | |
| 11938 | The op tree representing the expression is returned. If an optional |
| 11939 | expression is absent, a null pointer is returned, otherwise the pointer |
| 11940 | will be non-null. |
| 11941 | |
| 11942 | If an error occurs in parsing or compilation, in most cases a valid op |
| 11943 | tree is returned anyway. The error is reflected in the parser state, |
| 11944 | normally resulting in a single exception at the top level of parsing |
| 11945 | which covers all the compilation errors that occurred. Some compilation |
| 11946 | errors, however, will throw an exception immediately. |
| 11947 | |
| 11948 | =cut |
| 11949 | */ |
| 11950 | |
| 11951 | OP * |
| 11952 | Perl_parse_listexpr(pTHX_ U32 flags) |
| 11953 | { |
| 11954 | return parse_expr(LEX_FAKEEOF_LOWLOGIC, flags); |
| 11955 | } |
| 11956 | |
| 11957 | /* |
| 11958 | =for apidoc Amx|OP *|parse_fullexpr|U32 flags |
| 11959 | |
| 11960 | Parse a single complete Perl expression. This allows the full |
| 11961 | expression grammar, including the lowest-precedence operators such |
| 11962 | as C<or>. The expression must be followed (and thus terminated) by a |
| 11963 | token that an expression would normally be terminated by: end-of-file, |
| 11964 | closing bracketing punctuation, semicolon, or one of the keywords that |
| 11965 | signals a postfix expression-statement modifier. If I<flags> includes |
| 11966 | C<PARSE_OPTIONAL> then the expression is optional, otherwise it is |
| 11967 | mandatory. It is up to the caller to ensure that the dynamic parser |
| 11968 | state (L</PL_parser> et al) is correctly set to reflect the source of |
| 11969 | the code to be parsed and the lexical context for the expression. |
| 11970 | |
| 11971 | The op tree representing the expression is returned. If an optional |
| 11972 | expression is absent, a null pointer is returned, otherwise the pointer |
| 11973 | will be non-null. |
| 11974 | |
| 11975 | If an error occurs in parsing or compilation, in most cases a valid op |
| 11976 | tree is returned anyway. The error is reflected in the parser state, |
| 11977 | normally resulting in a single exception at the top level of parsing |
| 11978 | which covers all the compilation errors that occurred. Some compilation |
| 11979 | errors, however, will throw an exception immediately. |
| 11980 | |
| 11981 | =cut |
| 11982 | */ |
| 11983 | |
| 11984 | OP * |
| 11985 | Perl_parse_fullexpr(pTHX_ U32 flags) |
| 11986 | { |
| 11987 | return parse_expr(LEX_FAKEEOF_NONEXPR, flags); |
| 11988 | } |
| 11989 | |
| 11990 | /* |
| 11991 | =for apidoc Amx|OP *|parse_block|U32 flags |
| 11992 | |
| 11993 | Parse a single complete Perl code block. This consists of an opening |
| 11994 | brace, a sequence of statements, and a closing brace. The block |
| 11995 | constitutes a lexical scope, so C<my> variables and various compile-time |
| 11996 | effects can be contained within it. It is up to the caller to ensure |
| 11997 | that the dynamic parser state (L</PL_parser> et al) is correctly set to |
| 11998 | reflect the source of the code to be parsed and the lexical context for |
| 11999 | the statement. |
| 12000 | |
| 12001 | The op tree representing the code block is returned. This is always a |
| 12002 | real op, never a null pointer. It will normally be a C<lineseq> list, |
| 12003 | including C<nextstate> or equivalent ops. No ops to construct any kind |
| 12004 | of runtime scope are included by virtue of it being a block. |
| 12005 | |
| 12006 | If an error occurs in parsing or compilation, in most cases a valid op |
| 12007 | tree (most likely null) is returned anyway. The error is reflected in |
| 12008 | the parser state, normally resulting in a single exception at the top |
| 12009 | level of parsing which covers all the compilation errors that occurred. |
| 12010 | Some compilation errors, however, will throw an exception immediately. |
| 12011 | |
| 12012 | The I<flags> parameter is reserved for future use, and must always |
| 12013 | be zero. |
| 12014 | |
| 12015 | =cut |
| 12016 | */ |
| 12017 | |
| 12018 | OP * |
| 12019 | Perl_parse_block(pTHX_ U32 flags) |
| 12020 | { |
| 12021 | if (flags) |
| 12022 | Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_block"); |
| 12023 | return parse_recdescent_for_op(GRAMBLOCK, LEX_FAKEEOF_NEVER); |
| 12024 | } |
| 12025 | |
| 12026 | /* |
| 12027 | =for apidoc Amx|OP *|parse_barestmt|U32 flags |
| 12028 | |
| 12029 | Parse a single unadorned Perl statement. This may be a normal imperative |
| 12030 | statement or a declaration that has compile-time effect. It does not |
| 12031 | include any label or other affixture. It is up to the caller to ensure |
| 12032 | that the dynamic parser state (L</PL_parser> et al) is correctly set to |
| 12033 | reflect the source of the code to be parsed and the lexical context for |
| 12034 | the statement. |
| 12035 | |
| 12036 | The op tree representing the statement is returned. This may be a |
| 12037 | null pointer if the statement is null, for example if it was actually |
| 12038 | a subroutine definition (which has compile-time side effects). If not |
| 12039 | null, it will be ops directly implementing the statement, suitable to |
| 12040 | pass to L</newSTATEOP>. It will not normally include a C<nextstate> or |
| 12041 | equivalent op (except for those embedded in a scope contained entirely |
| 12042 | within the statement). |
| 12043 | |
| 12044 | If an error occurs in parsing or compilation, in most cases a valid op |
| 12045 | tree (most likely null) is returned anyway. The error is reflected in |
| 12046 | the parser state, normally resulting in a single exception at the top |
| 12047 | level of parsing which covers all the compilation errors that occurred. |
| 12048 | Some compilation errors, however, will throw an exception immediately. |
| 12049 | |
| 12050 | The I<flags> parameter is reserved for future use, and must always |
| 12051 | be zero. |
| 12052 | |
| 12053 | =cut |
| 12054 | */ |
| 12055 | |
| 12056 | OP * |
| 12057 | Perl_parse_barestmt(pTHX_ U32 flags) |
| 12058 | { |
| 12059 | if (flags) |
| 12060 | Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_barestmt"); |
| 12061 | return parse_recdescent_for_op(GRAMBARESTMT, LEX_FAKEEOF_NEVER); |
| 12062 | } |
| 12063 | |
| 12064 | /* |
| 12065 | =for apidoc Amx|SV *|parse_label|U32 flags |
| 12066 | |
| 12067 | Parse a single label, possibly optional, of the type that may prefix a |
| 12068 | Perl statement. It is up to the caller to ensure that the dynamic parser |
| 12069 | state (L</PL_parser> et al) is correctly set to reflect the source of |
| 12070 | the code to be parsed. If I<flags> includes C<PARSE_OPTIONAL> then the |
| 12071 | label is optional, otherwise it is mandatory. |
| 12072 | |
| 12073 | The name of the label is returned in the form of a fresh scalar. If an |
| 12074 | optional label is absent, a null pointer is returned. |
| 12075 | |
| 12076 | If an error occurs in parsing, which can only occur if the label is |
| 12077 | mandatory, a valid label is returned anyway. The error is reflected in |
| 12078 | the parser state, normally resulting in a single exception at the top |
| 12079 | level of parsing which covers all the compilation errors that occurred. |
| 12080 | |
| 12081 | =cut |
| 12082 | */ |
| 12083 | |
| 12084 | SV * |
| 12085 | Perl_parse_label(pTHX_ U32 flags) |
| 12086 | { |
| 12087 | if (flags & ~PARSE_OPTIONAL) |
| 12088 | Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_label"); |
| 12089 | if (PL_lex_state == LEX_KNOWNEXT) { |
| 12090 | PL_parser->yychar = yylex(); |
| 12091 | if (PL_parser->yychar == LABEL) { |
| 12092 | char * const lpv = pl_yylval.pval; |
| 12093 | STRLEN llen = strlen(lpv); |
| 12094 | PL_parser->yychar = YYEMPTY; |
| 12095 | return newSVpvn_flags(lpv, llen, lpv[llen+1] ? SVf_UTF8 : 0); |
| 12096 | } else { |
| 12097 | yyunlex(); |
| 12098 | goto no_label; |
| 12099 | } |
| 12100 | } else { |
| 12101 | char *s, *t; |
| 12102 | STRLEN wlen, bufptr_pos; |
| 12103 | lex_read_space(0); |
| 12104 | t = s = PL_bufptr; |
| 12105 | if (!isIDFIRST_lazy_if(s, UTF)) |
| 12106 | goto no_label; |
| 12107 | t = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &wlen); |
| 12108 | if (word_takes_any_delimeter(s, wlen)) |
| 12109 | goto no_label; |
| 12110 | bufptr_pos = s - SvPVX(PL_linestr); |
| 12111 | PL_bufptr = t; |
| 12112 | lex_read_space(LEX_KEEP_PREVIOUS); |
| 12113 | t = PL_bufptr; |
| 12114 | s = SvPVX(PL_linestr) + bufptr_pos; |
| 12115 | if (t[0] == ':' && t[1] != ':') { |
| 12116 | PL_oldoldbufptr = PL_oldbufptr; |
| 12117 | PL_oldbufptr = s; |
| 12118 | PL_bufptr = t+1; |
| 12119 | return newSVpvn_flags(s, wlen, UTF ? SVf_UTF8 : 0); |
| 12120 | } else { |
| 12121 | PL_bufptr = s; |
| 12122 | no_label: |
| 12123 | if (flags & PARSE_OPTIONAL) { |
| 12124 | return NULL; |
| 12125 | } else { |
| 12126 | qerror(Perl_mess(aTHX_ "Parse error")); |
| 12127 | return newSVpvs("x"); |
| 12128 | } |
| 12129 | } |
| 12130 | } |
| 12131 | } |
| 12132 | |
| 12133 | /* |
| 12134 | =for apidoc Amx|OP *|parse_fullstmt|U32 flags |
| 12135 | |
| 12136 | Parse a single complete Perl statement. This may be a normal imperative |
| 12137 | statement or a declaration that has compile-time effect, and may include |
| 12138 | optional labels. It is up to the caller to ensure that the dynamic |
| 12139 | parser state (L</PL_parser> et al) is correctly set to reflect the source |
| 12140 | of the code to be parsed and the lexical context for the statement. |
| 12141 | |
| 12142 | The op tree representing the statement is returned. This may be a |
| 12143 | null pointer if the statement is null, for example if it was actually |
| 12144 | a subroutine definition (which has compile-time side effects). If not |
| 12145 | null, it will be the result of a L</newSTATEOP> call, normally including |
| 12146 | a C<nextstate> or equivalent op. |
| 12147 | |
| 12148 | If an error occurs in parsing or compilation, in most cases a valid op |
| 12149 | tree (most likely null) is returned anyway. The error is reflected in |
| 12150 | the parser state, normally resulting in a single exception at the top |
| 12151 | level of parsing which covers all the compilation errors that occurred. |
| 12152 | Some compilation errors, however, will throw an exception immediately. |
| 12153 | |
| 12154 | The I<flags> parameter is reserved for future use, and must always |
| 12155 | be zero. |
| 12156 | |
| 12157 | =cut |
| 12158 | */ |
| 12159 | |
| 12160 | OP * |
| 12161 | Perl_parse_fullstmt(pTHX_ U32 flags) |
| 12162 | { |
| 12163 | if (flags) |
| 12164 | Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_fullstmt"); |
| 12165 | return parse_recdescent_for_op(GRAMFULLSTMT, LEX_FAKEEOF_NEVER); |
| 12166 | } |
| 12167 | |
| 12168 | /* |
| 12169 | =for apidoc Amx|OP *|parse_stmtseq|U32 flags |
| 12170 | |
| 12171 | Parse a sequence of zero or more Perl statements. These may be normal |
| 12172 | imperative statements, including optional labels, or declarations |
| 12173 | that have compile-time effect, or any mixture thereof. The statement |
| 12174 | sequence ends when a closing brace or end-of-file is encountered in a |
| 12175 | place where a new statement could have validly started. It is up to |
| 12176 | the caller to ensure that the dynamic parser state (L</PL_parser> et al) |
| 12177 | is correctly set to reflect the source of the code to be parsed and the |
| 12178 | lexical context for the statements. |
| 12179 | |
| 12180 | The op tree representing the statement sequence is returned. This may |
| 12181 | be a null pointer if the statements were all null, for example if there |
| 12182 | were no statements or if there were only subroutine definitions (which |
| 12183 | have compile-time side effects). If not null, it will be a C<lineseq> |
| 12184 | list, normally including C<nextstate> or equivalent ops. |
| 12185 | |
| 12186 | If an error occurs in parsing or compilation, in most cases a valid op |
| 12187 | tree is returned anyway. The error is reflected in the parser state, |
| 12188 | normally resulting in a single exception at the top level of parsing |
| 12189 | which covers all the compilation errors that occurred. Some compilation |
| 12190 | errors, however, will throw an exception immediately. |
| 12191 | |
| 12192 | The I<flags> parameter is reserved for future use, and must always |
| 12193 | be zero. |
| 12194 | |
| 12195 | =cut |
| 12196 | */ |
| 12197 | |
| 12198 | OP * |
| 12199 | Perl_parse_stmtseq(pTHX_ U32 flags) |
| 12200 | { |
| 12201 | OP *stmtseqop; |
| 12202 | I32 c; |
| 12203 | if (flags) |
| 12204 | Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_stmtseq"); |
| 12205 | stmtseqop = parse_recdescent_for_op(GRAMSTMTSEQ, LEX_FAKEEOF_CLOSING); |
| 12206 | c = lex_peek_unichar(0); |
| 12207 | if (c != -1 && c != /*{*/'}') |
| 12208 | qerror(Perl_mess(aTHX_ "Parse error")); |
| 12209 | return stmtseqop; |
| 12210 | } |
| 12211 | |
| 12212 | /* |
| 12213 | * Local variables: |
| 12214 | * c-indentation-style: bsd |
| 12215 | * c-basic-offset: 4 |
| 12216 | * indent-tabs-mode: nil |
| 12217 | * End: |
| 12218 | * |
| 12219 | * ex: set ts=8 sts=4 sw=4 et: |
| 12220 | */ |