| 1 | /* toke.c |
| 2 | * |
| 3 | * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
| 4 | * 2000, 2001, 2002, 2003, 2004, 2005, 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 | |
| 15 | /* |
| 16 | * This file is the lexer for Perl. It's closely linked to the |
| 17 | * parser, perly.y. |
| 18 | * |
| 19 | * The main routine is yylex(), which returns the next token. |
| 20 | */ |
| 21 | |
| 22 | #include "EXTERN.h" |
| 23 | #define PERL_IN_TOKE_C |
| 24 | #include "perl.h" |
| 25 | |
| 26 | #define yychar (*PL_yycharp) |
| 27 | #define yylval (*PL_yylvalp) |
| 28 | |
| 29 | static const char ident_too_long[] = |
| 30 | "Identifier too long"; |
| 31 | static const char c_without_g[] = |
| 32 | "Use of /c modifier is meaningless without /g"; |
| 33 | static const char c_in_subst[] = |
| 34 | "Use of /c modifier is meaningless in s///"; |
| 35 | |
| 36 | static void restore_rsfp(pTHX_ void *f); |
| 37 | #ifndef PERL_NO_UTF16_FILTER |
| 38 | static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen); |
| 39 | static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen); |
| 40 | #endif |
| 41 | |
| 42 | #define XFAKEBRACK 128 |
| 43 | #define XENUMMASK 127 |
| 44 | |
| 45 | #ifdef USE_UTF8_SCRIPTS |
| 46 | # define UTF (!IN_BYTES) |
| 47 | #else |
| 48 | # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8)) |
| 49 | #endif |
| 50 | |
| 51 | /* In variables named $^X, these are the legal values for X. |
| 52 | * 1999-02-27 mjd-perl-patch@plover.com */ |
| 53 | #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x))) |
| 54 | |
| 55 | /* On MacOS, respect nonbreaking spaces */ |
| 56 | #ifdef MACOS_TRADITIONAL |
| 57 | #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t') |
| 58 | #else |
| 59 | #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t') |
| 60 | #endif |
| 61 | |
| 62 | /* LEX_* are values for PL_lex_state, the state of the lexer. |
| 63 | * They are arranged oddly so that the guard on the switch statement |
| 64 | * can get by with a single comparison (if the compiler is smart enough). |
| 65 | */ |
| 66 | |
| 67 | /* #define LEX_NOTPARSING 11 is done in perl.h. */ |
| 68 | |
| 69 | #define LEX_NORMAL 10 |
| 70 | #define LEX_INTERPNORMAL 9 |
| 71 | #define LEX_INTERPCASEMOD 8 |
| 72 | #define LEX_INTERPPUSH 7 |
| 73 | #define LEX_INTERPSTART 6 |
| 74 | #define LEX_INTERPEND 5 |
| 75 | #define LEX_INTERPENDMAYBE 4 |
| 76 | #define LEX_INTERPCONCAT 3 |
| 77 | #define LEX_INTERPCONST 2 |
| 78 | #define LEX_FORMLINE 1 |
| 79 | #define LEX_KNOWNEXT 0 |
| 80 | |
| 81 | #ifdef DEBUGGING |
| 82 | static const char* const lex_state_names[] = { |
| 83 | "KNOWNEXT", |
| 84 | "FORMLINE", |
| 85 | "INTERPCONST", |
| 86 | "INTERPCONCAT", |
| 87 | "INTERPENDMAYBE", |
| 88 | "INTERPEND", |
| 89 | "INTERPSTART", |
| 90 | "INTERPPUSH", |
| 91 | "INTERPCASEMOD", |
| 92 | "INTERPNORMAL", |
| 93 | "NORMAL" |
| 94 | }; |
| 95 | #endif |
| 96 | |
| 97 | #ifdef ff_next |
| 98 | #undef ff_next |
| 99 | #endif |
| 100 | |
| 101 | #include "keywords.h" |
| 102 | |
| 103 | /* CLINE is a macro that ensures PL_copline has a sane value */ |
| 104 | |
| 105 | #ifdef CLINE |
| 106 | #undef CLINE |
| 107 | #endif |
| 108 | #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline)) |
| 109 | |
| 110 | /* |
| 111 | * Convenience functions to return different tokens and prime the |
| 112 | * lexer for the next token. They all take an argument. |
| 113 | * |
| 114 | * TOKEN : generic token (used for '(', DOLSHARP, etc) |
| 115 | * OPERATOR : generic operator |
| 116 | * AOPERATOR : assignment operator |
| 117 | * PREBLOCK : beginning the block after an if, while, foreach, ... |
| 118 | * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref) |
| 119 | * PREREF : *EXPR where EXPR is not a simple identifier |
| 120 | * TERM : expression term |
| 121 | * LOOPX : loop exiting command (goto, last, dump, etc) |
| 122 | * FTST : file test operator |
| 123 | * FUN0 : zero-argument function |
| 124 | * FUN1 : not used, except for not, which isn't a UNIOP |
| 125 | * BOop : bitwise or or xor |
| 126 | * BAop : bitwise and |
| 127 | * SHop : shift operator |
| 128 | * PWop : power operator |
| 129 | * PMop : pattern-matching operator |
| 130 | * Aop : addition-level operator |
| 131 | * Mop : multiplication-level operator |
| 132 | * Eop : equality-testing operator |
| 133 | * Rop : relational operator <= != gt |
| 134 | * |
| 135 | * Also see LOP and lop() below. |
| 136 | */ |
| 137 | |
| 138 | #ifdef DEBUGGING /* Serve -DT. */ |
| 139 | # define REPORT(retval) tokereport(s,(int)retval) |
| 140 | #else |
| 141 | # define REPORT(retval) (retval) |
| 142 | #endif |
| 143 | |
| 144 | #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval)) |
| 145 | #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval)) |
| 146 | #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval))) |
| 147 | #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval)) |
| 148 | #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval)) |
| 149 | #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval)) |
| 150 | #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval)) |
| 151 | #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX)) |
| 152 | #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP)) |
| 153 | #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0)) |
| 154 | #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1)) |
| 155 | #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP))) |
| 156 | #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP))) |
| 157 | #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP))) |
| 158 | #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP))) |
| 159 | #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP)) |
| 160 | #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP))) |
| 161 | #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP))) |
| 162 | #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP)) |
| 163 | #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP)) |
| 164 | |
| 165 | /* This bit of chicanery makes a unary function followed by |
| 166 | * a parenthesis into a function with one argument, highest precedence. |
| 167 | * The UNIDOR macro is for unary functions that can be followed by the // |
| 168 | * operator (such as C<shift // 0>). |
| 169 | */ |
| 170 | #define UNI2(f,x) return ( \ |
| 171 | yylval.ival = f, \ |
| 172 | PL_expect = x, \ |
| 173 | PL_bufptr = s, \ |
| 174 | PL_last_uni = PL_oldbufptr, \ |
| 175 | PL_last_lop_op = f, \ |
| 176 | REPORT( \ |
| 177 | (*s == '(' || (s = skipspace(s), *s == '(') \ |
| 178 | ? (int)FUNC1 : (int)UNIOP))) |
| 179 | #define UNI(f) UNI2(f,XTERM) |
| 180 | #define UNIDOR(f) UNI2(f,XTERMORDORDOR) |
| 181 | |
| 182 | #define UNIBRACK(f) return ( \ |
| 183 | yylval.ival = f, \ |
| 184 | PL_bufptr = s, \ |
| 185 | PL_last_uni = PL_oldbufptr, \ |
| 186 | REPORT( \ |
| 187 | (*s == '(' || (s = skipspace(s), *s == '(') \ |
| 188 | ? (int)FUNC1 : (int)UNIOP))) |
| 189 | |
| 190 | /* grandfather return to old style */ |
| 191 | #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP) |
| 192 | |
| 193 | #ifdef DEBUGGING |
| 194 | |
| 195 | /* how to interpret the yylval associated with the token */ |
| 196 | enum token_type { |
| 197 | TOKENTYPE_NONE, |
| 198 | TOKENTYPE_IVAL, |
| 199 | TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */ |
| 200 | TOKENTYPE_PVAL, |
| 201 | TOKENTYPE_OPVAL, |
| 202 | TOKENTYPE_GVVAL |
| 203 | }; |
| 204 | |
| 205 | static struct debug_tokens { const int token, type; const char *name; } |
| 206 | const debug_tokens[] = |
| 207 | { |
| 208 | { ADDOP, TOKENTYPE_OPNUM, "ADDOP" }, |
| 209 | { ANDAND, TOKENTYPE_NONE, "ANDAND" }, |
| 210 | { ANDOP, TOKENTYPE_NONE, "ANDOP" }, |
| 211 | { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" }, |
| 212 | { ARROW, TOKENTYPE_NONE, "ARROW" }, |
| 213 | { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" }, |
| 214 | { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" }, |
| 215 | { BITOROP, TOKENTYPE_OPNUM, "BITOROP" }, |
| 216 | { COLONATTR, TOKENTYPE_NONE, "COLONATTR" }, |
| 217 | { CONTINUE, TOKENTYPE_NONE, "CONTINUE" }, |
| 218 | { DO, TOKENTYPE_NONE, "DO" }, |
| 219 | { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" }, |
| 220 | { DORDOR, TOKENTYPE_NONE, "DORDOR" }, |
| 221 | { DOROP, TOKENTYPE_OPNUM, "DOROP" }, |
| 222 | { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" }, |
| 223 | { ELSE, TOKENTYPE_NONE, "ELSE" }, |
| 224 | { ELSIF, TOKENTYPE_IVAL, "ELSIF" }, |
| 225 | { EQOP, TOKENTYPE_OPNUM, "EQOP" }, |
| 226 | { FOR, TOKENTYPE_IVAL, "FOR" }, |
| 227 | { FORMAT, TOKENTYPE_NONE, "FORMAT" }, |
| 228 | { FUNC, TOKENTYPE_OPNUM, "FUNC" }, |
| 229 | { FUNC0, TOKENTYPE_OPNUM, "FUNC0" }, |
| 230 | { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" }, |
| 231 | { FUNC1, TOKENTYPE_OPNUM, "FUNC1" }, |
| 232 | { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" }, |
| 233 | { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" }, |
| 234 | { IF, TOKENTYPE_IVAL, "IF" }, |
| 235 | { LABEL, TOKENTYPE_PVAL, "LABEL" }, |
| 236 | { LOCAL, TOKENTYPE_IVAL, "LOCAL" }, |
| 237 | { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" }, |
| 238 | { LSTOP, TOKENTYPE_OPNUM, "LSTOP" }, |
| 239 | { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" }, |
| 240 | { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" }, |
| 241 | { METHOD, TOKENTYPE_OPVAL, "METHOD" }, |
| 242 | { MULOP, TOKENTYPE_OPNUM, "MULOP" }, |
| 243 | { MY, TOKENTYPE_IVAL, "MY" }, |
| 244 | { MYSUB, TOKENTYPE_NONE, "MYSUB" }, |
| 245 | { NOAMP, TOKENTYPE_NONE, "NOAMP" }, |
| 246 | { NOTOP, TOKENTYPE_NONE, "NOTOP" }, |
| 247 | { OROP, TOKENTYPE_IVAL, "OROP" }, |
| 248 | { OROR, TOKENTYPE_NONE, "OROR" }, |
| 249 | { PACKAGE, TOKENTYPE_NONE, "PACKAGE" }, |
| 250 | { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" }, |
| 251 | { POSTDEC, TOKENTYPE_NONE, "POSTDEC" }, |
| 252 | { POSTINC, TOKENTYPE_NONE, "POSTINC" }, |
| 253 | { POWOP, TOKENTYPE_OPNUM, "POWOP" }, |
| 254 | { PREDEC, TOKENTYPE_NONE, "PREDEC" }, |
| 255 | { PREINC, TOKENTYPE_NONE, "PREINC" }, |
| 256 | { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" }, |
| 257 | { REFGEN, TOKENTYPE_NONE, "REFGEN" }, |
| 258 | { RELOP, TOKENTYPE_OPNUM, "RELOP" }, |
| 259 | { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" }, |
| 260 | { SUB, TOKENTYPE_NONE, "SUB" }, |
| 261 | { THING, TOKENTYPE_OPVAL, "THING" }, |
| 262 | { UMINUS, TOKENTYPE_NONE, "UMINUS" }, |
| 263 | { UNIOP, TOKENTYPE_OPNUM, "UNIOP" }, |
| 264 | { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" }, |
| 265 | { UNLESS, TOKENTYPE_IVAL, "UNLESS" }, |
| 266 | { UNTIL, TOKENTYPE_IVAL, "UNTIL" }, |
| 267 | { USE, TOKENTYPE_IVAL, "USE" }, |
| 268 | { WHILE, TOKENTYPE_IVAL, "WHILE" }, |
| 269 | { WORD, TOKENTYPE_OPVAL, "WORD" }, |
| 270 | { 0, TOKENTYPE_NONE, 0 } |
| 271 | }; |
| 272 | |
| 273 | /* dump the returned token in rv, plus any optional arg in yylval */ |
| 274 | |
| 275 | STATIC int |
| 276 | S_tokereport(pTHX_ const char* s, I32 rv) |
| 277 | { |
| 278 | if (DEBUG_T_TEST) { |
| 279 | const char *name = Nullch; |
| 280 | enum token_type type = TOKENTYPE_NONE; |
| 281 | struct debug_tokens *p; |
| 282 | SV* report = newSVpvn("<== ", 4); |
| 283 | |
| 284 | for (p = (struct debug_tokens *)debug_tokens; p->token; p++) { |
| 285 | if (p->token == (int)rv) { |
| 286 | name = p->name; |
| 287 | type = p->type; |
| 288 | break; |
| 289 | } |
| 290 | } |
| 291 | if (name) |
| 292 | Perl_sv_catpv(aTHX_ report, name); |
| 293 | else if ((char)rv > ' ' && (char)rv < '~') |
| 294 | Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv); |
| 295 | else if (!rv) |
| 296 | Perl_sv_catpv(aTHX_ report, "EOF"); |
| 297 | else |
| 298 | Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv); |
| 299 | switch (type) { |
| 300 | case TOKENTYPE_NONE: |
| 301 | case TOKENTYPE_GVVAL: /* doesn't appear to be used */ |
| 302 | break; |
| 303 | case TOKENTYPE_IVAL: |
| 304 | Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival); |
| 305 | break; |
| 306 | case TOKENTYPE_OPNUM: |
| 307 | Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)", |
| 308 | PL_op_name[yylval.ival]); |
| 309 | break; |
| 310 | case TOKENTYPE_PVAL: |
| 311 | Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval); |
| 312 | break; |
| 313 | case TOKENTYPE_OPVAL: |
| 314 | if (yylval.opval) |
| 315 | Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)", |
| 316 | PL_op_name[yylval.opval->op_type]); |
| 317 | else |
| 318 | Perl_sv_catpv(aTHX_ report, "(opval=null)"); |
| 319 | break; |
| 320 | } |
| 321 | Perl_sv_catpvf(aTHX_ report, " at line %"IVdf" [", (IV)CopLINE(PL_curcop)); |
| 322 | if (s - PL_bufptr > 0) |
| 323 | sv_catpvn(report, PL_bufptr, s - PL_bufptr); |
| 324 | else { |
| 325 | if (PL_oldbufptr && *PL_oldbufptr) |
| 326 | sv_catpv(report, PL_tokenbuf); |
| 327 | } |
| 328 | PerlIO_printf(Perl_debug_log, "### %s]\n", SvPV_nolen(report)); |
| 329 | }; |
| 330 | return (int)rv; |
| 331 | } |
| 332 | |
| 333 | #endif |
| 334 | |
| 335 | /* |
| 336 | * S_ao |
| 337 | * |
| 338 | * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR |
| 339 | * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN |
| 340 | */ |
| 341 | |
| 342 | STATIC int |
| 343 | S_ao(pTHX_ int toketype) |
| 344 | { |
| 345 | if (*PL_bufptr == '=') { |
| 346 | PL_bufptr++; |
| 347 | if (toketype == ANDAND) |
| 348 | yylval.ival = OP_ANDASSIGN; |
| 349 | else if (toketype == OROR) |
| 350 | yylval.ival = OP_ORASSIGN; |
| 351 | else if (toketype == DORDOR) |
| 352 | yylval.ival = OP_DORASSIGN; |
| 353 | toketype = ASSIGNOP; |
| 354 | } |
| 355 | return toketype; |
| 356 | } |
| 357 | |
| 358 | /* |
| 359 | * S_no_op |
| 360 | * When Perl expects an operator and finds something else, no_op |
| 361 | * prints the warning. It always prints "<something> found where |
| 362 | * operator expected. It prints "Missing semicolon on previous line?" |
| 363 | * if the surprise occurs at the start of the line. "do you need to |
| 364 | * predeclare ..." is printed out for code like "sub bar; foo bar $x" |
| 365 | * where the compiler doesn't know if foo is a method call or a function. |
| 366 | * It prints "Missing operator before end of line" if there's nothing |
| 367 | * after the missing operator, or "... before <...>" if there is something |
| 368 | * after the missing operator. |
| 369 | */ |
| 370 | |
| 371 | STATIC void |
| 372 | S_no_op(pTHX_ const char *what, char *s) |
| 373 | { |
| 374 | char *oldbp = PL_bufptr; |
| 375 | bool is_first = (PL_oldbufptr == PL_linestart); |
| 376 | |
| 377 | if (!s) |
| 378 | s = oldbp; |
| 379 | else |
| 380 | PL_bufptr = s; |
| 381 | yywarn(Perl_form(aTHX_ "%s found where operator expected", what)); |
| 382 | if (ckWARN_d(WARN_SYNTAX)) { |
| 383 | if (is_first) |
| 384 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 385 | "\t(Missing semicolon on previous line?)\n"); |
| 386 | else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) { |
| 387 | char *t; |
| 388 | for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ; |
| 389 | if (t < PL_bufptr && isSPACE(*t)) |
| 390 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 391 | "\t(Do you need to predeclare %.*s?)\n", |
| 392 | t - PL_oldoldbufptr, PL_oldoldbufptr); |
| 393 | } |
| 394 | else { |
| 395 | assert(s >= oldbp); |
| 396 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 397 | "\t(Missing operator before %.*s?)\n", s - oldbp, oldbp); |
| 398 | } |
| 399 | } |
| 400 | PL_bufptr = oldbp; |
| 401 | } |
| 402 | |
| 403 | /* |
| 404 | * S_missingterm |
| 405 | * Complain about missing quote/regexp/heredoc terminator. |
| 406 | * If it's called with (char *)NULL then it cauterizes the line buffer. |
| 407 | * If we're in a delimited string and the delimiter is a control |
| 408 | * character, it's reformatted into a two-char sequence like ^C. |
| 409 | * This is fatal. |
| 410 | */ |
| 411 | |
| 412 | STATIC void |
| 413 | S_missingterm(pTHX_ char *s) |
| 414 | { |
| 415 | char tmpbuf[3]; |
| 416 | char q; |
| 417 | if (s) { |
| 418 | char *nl = strrchr(s,'\n'); |
| 419 | if (nl) |
| 420 | *nl = '\0'; |
| 421 | } |
| 422 | else if ( |
| 423 | #ifdef EBCDIC |
| 424 | iscntrl(PL_multi_close) |
| 425 | #else |
| 426 | PL_multi_close < 32 || PL_multi_close == 127 |
| 427 | #endif |
| 428 | ) { |
| 429 | *tmpbuf = '^'; |
| 430 | tmpbuf[1] = toCTRL(PL_multi_close); |
| 431 | tmpbuf[2] = '\0'; |
| 432 | s = tmpbuf; |
| 433 | } |
| 434 | else { |
| 435 | *tmpbuf = (char)PL_multi_close; |
| 436 | tmpbuf[1] = '\0'; |
| 437 | s = tmpbuf; |
| 438 | } |
| 439 | q = strchr(s,'"') ? '\'' : '"'; |
| 440 | Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q); |
| 441 | } |
| 442 | |
| 443 | /* |
| 444 | * Perl_deprecate |
| 445 | */ |
| 446 | |
| 447 | void |
| 448 | Perl_deprecate(pTHX_ const char *s) |
| 449 | { |
| 450 | if (ckWARN(WARN_DEPRECATED)) |
| 451 | Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s); |
| 452 | } |
| 453 | |
| 454 | void |
| 455 | Perl_deprecate_old(pTHX_ const char *s) |
| 456 | { |
| 457 | /* This function should NOT be called for any new deprecated warnings */ |
| 458 | /* Use Perl_deprecate instead */ |
| 459 | /* */ |
| 460 | /* It is here to maintain backward compatibility with the pre-5.8 */ |
| 461 | /* warnings category hierarchy. The "deprecated" category used to */ |
| 462 | /* live under the "syntax" category. It is now a top-level category */ |
| 463 | /* in its own right. */ |
| 464 | |
| 465 | if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX)) |
| 466 | Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX), |
| 467 | "Use of %s is deprecated", s); |
| 468 | } |
| 469 | |
| 470 | /* |
| 471 | * depcom |
| 472 | * Deprecate a comma-less variable list. |
| 473 | */ |
| 474 | |
| 475 | STATIC void |
| 476 | S_depcom(pTHX) |
| 477 | { |
| 478 | deprecate_old("comma-less variable list"); |
| 479 | } |
| 480 | |
| 481 | /* |
| 482 | * experimental text filters for win32 carriage-returns, utf16-to-utf8 and |
| 483 | * utf16-to-utf8-reversed. |
| 484 | */ |
| 485 | |
| 486 | #ifdef PERL_CR_FILTER |
| 487 | static void |
| 488 | strip_return(SV *sv) |
| 489 | { |
| 490 | register char *s = SvPVX(sv); |
| 491 | register char *e = s + SvCUR(sv); |
| 492 | /* outer loop optimized to do nothing if there are no CR-LFs */ |
| 493 | while (s < e) { |
| 494 | if (*s++ == '\r' && *s == '\n') { |
| 495 | /* hit a CR-LF, need to copy the rest */ |
| 496 | register char *d = s - 1; |
| 497 | *d++ = *s++; |
| 498 | while (s < e) { |
| 499 | if (*s == '\r' && s[1] == '\n') |
| 500 | s++; |
| 501 | *d++ = *s++; |
| 502 | } |
| 503 | SvCUR(sv) -= s - d; |
| 504 | return; |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | STATIC I32 |
| 510 | S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
| 511 | { |
| 512 | I32 count = FILTER_READ(idx+1, sv, maxlen); |
| 513 | if (count > 0 && !maxlen) |
| 514 | strip_return(sv); |
| 515 | return count; |
| 516 | } |
| 517 | #endif |
| 518 | |
| 519 | /* |
| 520 | * Perl_lex_start |
| 521 | * Initialize variables. Uses the Perl save_stack to save its state (for |
| 522 | * recursive calls to the parser). |
| 523 | */ |
| 524 | |
| 525 | void |
| 526 | Perl_lex_start(pTHX_ SV *line) |
| 527 | { |
| 528 | char *s; |
| 529 | STRLEN len; |
| 530 | |
| 531 | SAVEI32(PL_lex_dojoin); |
| 532 | SAVEI32(PL_lex_brackets); |
| 533 | SAVEI32(PL_lex_casemods); |
| 534 | SAVEI32(PL_lex_starts); |
| 535 | SAVEI32(PL_lex_state); |
| 536 | SAVEVPTR(PL_lex_inpat); |
| 537 | SAVEI32(PL_lex_inwhat); |
| 538 | if (PL_lex_state == LEX_KNOWNEXT) { |
| 539 | I32 toke = PL_nexttoke; |
| 540 | while (--toke >= 0) { |
| 541 | SAVEI32(PL_nexttype[toke]); |
| 542 | SAVEVPTR(PL_nextval[toke]); |
| 543 | } |
| 544 | SAVEI32(PL_nexttoke); |
| 545 | } |
| 546 | SAVECOPLINE(PL_curcop); |
| 547 | SAVEPPTR(PL_bufptr); |
| 548 | SAVEPPTR(PL_bufend); |
| 549 | SAVEPPTR(PL_oldbufptr); |
| 550 | SAVEPPTR(PL_oldoldbufptr); |
| 551 | SAVEPPTR(PL_last_lop); |
| 552 | SAVEPPTR(PL_last_uni); |
| 553 | SAVEPPTR(PL_linestart); |
| 554 | SAVESPTR(PL_linestr); |
| 555 | SAVEGENERICPV(PL_lex_brackstack); |
| 556 | SAVEGENERICPV(PL_lex_casestack); |
| 557 | SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp); |
| 558 | SAVESPTR(PL_lex_stuff); |
| 559 | SAVEI32(PL_lex_defer); |
| 560 | SAVEI32(PL_sublex_info.sub_inwhat); |
| 561 | SAVESPTR(PL_lex_repl); |
| 562 | SAVEINT(PL_expect); |
| 563 | SAVEINT(PL_lex_expect); |
| 564 | |
| 565 | PL_lex_state = LEX_NORMAL; |
| 566 | PL_lex_defer = 0; |
| 567 | PL_expect = XSTATE; |
| 568 | PL_lex_brackets = 0; |
| 569 | New(899, PL_lex_brackstack, 120, char); |
| 570 | New(899, PL_lex_casestack, 12, char); |
| 571 | PL_lex_casemods = 0; |
| 572 | *PL_lex_casestack = '\0'; |
| 573 | PL_lex_dojoin = 0; |
| 574 | PL_lex_starts = 0; |
| 575 | PL_lex_stuff = Nullsv; |
| 576 | PL_lex_repl = Nullsv; |
| 577 | PL_lex_inpat = 0; |
| 578 | PL_nexttoke = 0; |
| 579 | PL_lex_inwhat = 0; |
| 580 | PL_sublex_info.sub_inwhat = 0; |
| 581 | PL_linestr = line; |
| 582 | if (SvREADONLY(PL_linestr)) |
| 583 | PL_linestr = sv_2mortal(newSVsv(PL_linestr)); |
| 584 | s = SvPV(PL_linestr, len); |
| 585 | if (!len || s[len-1] != ';') { |
| 586 | if (!(SvFLAGS(PL_linestr) & SVs_TEMP)) |
| 587 | PL_linestr = sv_2mortal(newSVsv(PL_linestr)); |
| 588 | sv_catpvn(PL_linestr, "\n;", 2); |
| 589 | } |
| 590 | SvTEMP_off(PL_linestr); |
| 591 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr); |
| 592 | PL_bufend = PL_bufptr + SvCUR(PL_linestr); |
| 593 | PL_last_lop = PL_last_uni = Nullch; |
| 594 | PL_rsfp = 0; |
| 595 | } |
| 596 | |
| 597 | /* |
| 598 | * Perl_lex_end |
| 599 | * Finalizer for lexing operations. Must be called when the parser is |
| 600 | * done with the lexer. |
| 601 | */ |
| 602 | |
| 603 | void |
| 604 | Perl_lex_end(pTHX) |
| 605 | { |
| 606 | PL_doextract = FALSE; |
| 607 | } |
| 608 | |
| 609 | /* |
| 610 | * S_incline |
| 611 | * This subroutine has nothing to do with tilting, whether at windmills |
| 612 | * or pinball tables. Its name is short for "increment line". It |
| 613 | * increments the current line number in CopLINE(PL_curcop) and checks |
| 614 | * to see whether the line starts with a comment of the form |
| 615 | * # line 500 "foo.pm" |
| 616 | * If so, it sets the current line number and file to the values in the comment. |
| 617 | */ |
| 618 | |
| 619 | STATIC void |
| 620 | S_incline(pTHX_ char *s) |
| 621 | { |
| 622 | char *t; |
| 623 | char *n; |
| 624 | char *e; |
| 625 | char ch; |
| 626 | |
| 627 | CopLINE_inc(PL_curcop); |
| 628 | if (*s++ != '#') |
| 629 | return; |
| 630 | while (SPACE_OR_TAB(*s)) s++; |
| 631 | if (strnEQ(s, "line", 4)) |
| 632 | s += 4; |
| 633 | else |
| 634 | return; |
| 635 | if (SPACE_OR_TAB(*s)) |
| 636 | s++; |
| 637 | else |
| 638 | return; |
| 639 | while (SPACE_OR_TAB(*s)) s++; |
| 640 | if (!isDIGIT(*s)) |
| 641 | return; |
| 642 | n = s; |
| 643 | while (isDIGIT(*s)) |
| 644 | s++; |
| 645 | while (SPACE_OR_TAB(*s)) |
| 646 | s++; |
| 647 | if (*s == '"' && (t = strchr(s+1, '"'))) { |
| 648 | s++; |
| 649 | e = t + 1; |
| 650 | } |
| 651 | else { |
| 652 | for (t = s; !isSPACE(*t); t++) ; |
| 653 | e = t; |
| 654 | } |
| 655 | while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f') |
| 656 | e++; |
| 657 | if (*e != '\n' && *e != '\0') |
| 658 | return; /* false alarm */ |
| 659 | |
| 660 | ch = *t; |
| 661 | *t = '\0'; |
| 662 | if (t - s > 0) { |
| 663 | CopFILE_free(PL_curcop); |
| 664 | CopFILE_set(PL_curcop, s); |
| 665 | } |
| 666 | *t = ch; |
| 667 | CopLINE_set(PL_curcop, atoi(n)-1); |
| 668 | } |
| 669 | |
| 670 | /* |
| 671 | * S_skipspace |
| 672 | * Called to gobble the appropriate amount and type of whitespace. |
| 673 | * Skips comments as well. |
| 674 | */ |
| 675 | |
| 676 | STATIC char * |
| 677 | S_skipspace(pTHX_ register char *s) |
| 678 | { |
| 679 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
| 680 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
| 681 | s++; |
| 682 | return s; |
| 683 | } |
| 684 | for (;;) { |
| 685 | STRLEN prevlen; |
| 686 | SSize_t oldprevlen, oldoldprevlen; |
| 687 | SSize_t oldloplen = 0, oldunilen = 0; |
| 688 | while (s < PL_bufend && isSPACE(*s)) { |
| 689 | if (*s++ == '\n' && PL_in_eval && !PL_rsfp) |
| 690 | incline(s); |
| 691 | } |
| 692 | |
| 693 | /* comment */ |
| 694 | if (s < PL_bufend && *s == '#') { |
| 695 | while (s < PL_bufend && *s != '\n') |
| 696 | s++; |
| 697 | if (s < PL_bufend) { |
| 698 | s++; |
| 699 | if (PL_in_eval && !PL_rsfp) { |
| 700 | incline(s); |
| 701 | continue; |
| 702 | } |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | /* only continue to recharge the buffer if we're at the end |
| 707 | * of the buffer, we're not reading from a source filter, and |
| 708 | * we're in normal lexing mode |
| 709 | */ |
| 710 | if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat || |
| 711 | PL_lex_state == LEX_FORMLINE) |
| 712 | return s; |
| 713 | |
| 714 | /* try to recharge the buffer */ |
| 715 | if ((s = filter_gets(PL_linestr, PL_rsfp, |
| 716 | (prevlen = SvCUR(PL_linestr)))) == Nullch) |
| 717 | { |
| 718 | /* end of file. Add on the -p or -n magic */ |
| 719 | if (PL_minus_p) { |
| 720 | sv_setpv(PL_linestr, |
| 721 | ";}continue{print or die qq(-p destination: $!\\n);}"); |
| 722 | PL_minus_n = PL_minus_p = 0; |
| 723 | } |
| 724 | else if (PL_minus_n) { |
| 725 | sv_setpvn(PL_linestr, ";}", 2); |
| 726 | PL_minus_n = 0; |
| 727 | } |
| 728 | else |
| 729 | sv_setpvn(PL_linestr,";", 1); |
| 730 | |
| 731 | /* reset variables for next time we lex */ |
| 732 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart |
| 733 | = SvPVX(PL_linestr); |
| 734 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 735 | PL_last_lop = PL_last_uni = Nullch; |
| 736 | |
| 737 | /* Close the filehandle. Could be from -P preprocessor, |
| 738 | * STDIN, or a regular file. If we were reading code from |
| 739 | * STDIN (because the commandline held no -e or filename) |
| 740 | * then we don't close it, we reset it so the code can |
| 741 | * read from STDIN too. |
| 742 | */ |
| 743 | |
| 744 | if (PL_preprocess && !PL_in_eval) |
| 745 | (void)PerlProc_pclose(PL_rsfp); |
| 746 | else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) |
| 747 | PerlIO_clearerr(PL_rsfp); |
| 748 | else |
| 749 | (void)PerlIO_close(PL_rsfp); |
| 750 | PL_rsfp = Nullfp; |
| 751 | return s; |
| 752 | } |
| 753 | |
| 754 | /* not at end of file, so we only read another line */ |
| 755 | /* make corresponding updates to old pointers, for yyerror() */ |
| 756 | oldprevlen = PL_oldbufptr - PL_bufend; |
| 757 | oldoldprevlen = PL_oldoldbufptr - PL_bufend; |
| 758 | if (PL_last_uni) |
| 759 | oldunilen = PL_last_uni - PL_bufend; |
| 760 | if (PL_last_lop) |
| 761 | oldloplen = PL_last_lop - PL_bufend; |
| 762 | PL_linestart = PL_bufptr = s + prevlen; |
| 763 | PL_bufend = s + SvCUR(PL_linestr); |
| 764 | s = PL_bufptr; |
| 765 | PL_oldbufptr = s + oldprevlen; |
| 766 | PL_oldoldbufptr = s + oldoldprevlen; |
| 767 | if (PL_last_uni) |
| 768 | PL_last_uni = s + oldunilen; |
| 769 | if (PL_last_lop) |
| 770 | PL_last_lop = s + oldloplen; |
| 771 | incline(s); |
| 772 | |
| 773 | /* debugger active and we're not compiling the debugger code, |
| 774 | * so store the line into the debugger's array of lines |
| 775 | */ |
| 776 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
| 777 | SV *sv = NEWSV(85,0); |
| 778 | |
| 779 | sv_upgrade(sv, SVt_PVMG); |
| 780 | sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr); |
| 781 | (void)SvIOK_on(sv); |
| 782 | SvIV_set(sv, 0); |
| 783 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
| 784 | } |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | /* |
| 789 | * S_check_uni |
| 790 | * Check the unary operators to ensure there's no ambiguity in how they're |
| 791 | * used. An ambiguous piece of code would be: |
| 792 | * rand + 5 |
| 793 | * This doesn't mean rand() + 5. Because rand() is a unary operator, |
| 794 | * the +5 is its argument. |
| 795 | */ |
| 796 | |
| 797 | STATIC void |
| 798 | S_check_uni(pTHX) |
| 799 | { |
| 800 | char *s; |
| 801 | char *t; |
| 802 | |
| 803 | if (PL_oldoldbufptr != PL_last_uni) |
| 804 | return; |
| 805 | while (isSPACE(*PL_last_uni)) |
| 806 | PL_last_uni++; |
| 807 | for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ; |
| 808 | if ((t = strchr(s, '(')) && t < PL_bufptr) |
| 809 | return; |
| 810 | if (ckWARN_d(WARN_AMBIGUOUS)){ |
| 811 | char ch = *s; |
| 812 | *s = '\0'; |
| 813 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 814 | "Warning: Use of \"%s\" without parentheses is ambiguous", |
| 815 | PL_last_uni); |
| 816 | *s = ch; |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | /* |
| 821 | * LOP : macro to build a list operator. Its behaviour has been replaced |
| 822 | * with a subroutine, S_lop() for which LOP is just another name. |
| 823 | */ |
| 824 | |
| 825 | #define LOP(f,x) return lop(f,x,s) |
| 826 | |
| 827 | /* |
| 828 | * S_lop |
| 829 | * Build a list operator (or something that might be one). The rules: |
| 830 | * - if we have a next token, then it's a list operator [why?] |
| 831 | * - if the next thing is an opening paren, then it's a function |
| 832 | * - else it's a list operator |
| 833 | */ |
| 834 | |
| 835 | STATIC I32 |
| 836 | S_lop(pTHX_ I32 f, int x, char *s) |
| 837 | { |
| 838 | yylval.ival = f; |
| 839 | CLINE; |
| 840 | PL_expect = x; |
| 841 | PL_bufptr = s; |
| 842 | PL_last_lop = PL_oldbufptr; |
| 843 | PL_last_lop_op = (OPCODE)f; |
| 844 | if (PL_nexttoke) |
| 845 | return REPORT(LSTOP); |
| 846 | if (*s == '(') |
| 847 | return REPORT(FUNC); |
| 848 | s = skipspace(s); |
| 849 | if (*s == '(') |
| 850 | return REPORT(FUNC); |
| 851 | else |
| 852 | return REPORT(LSTOP); |
| 853 | } |
| 854 | |
| 855 | /* |
| 856 | * S_force_next |
| 857 | * When the lexer realizes it knows the next token (for instance, |
| 858 | * it is reordering tokens for the parser) then it can call S_force_next |
| 859 | * to know what token to return the next time the lexer is called. Caller |
| 860 | * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer |
| 861 | * handles the token correctly. |
| 862 | */ |
| 863 | |
| 864 | STATIC void |
| 865 | S_force_next(pTHX_ I32 type) |
| 866 | { |
| 867 | PL_nexttype[PL_nexttoke] = type; |
| 868 | PL_nexttoke++; |
| 869 | if (PL_lex_state != LEX_KNOWNEXT) { |
| 870 | PL_lex_defer = PL_lex_state; |
| 871 | PL_lex_expect = PL_expect; |
| 872 | PL_lex_state = LEX_KNOWNEXT; |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | STATIC SV * |
| 877 | S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len) |
| 878 | { |
| 879 | SV *sv = newSVpvn(start,len); |
| 880 | if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len)) |
| 881 | SvUTF8_on(sv); |
| 882 | return sv; |
| 883 | } |
| 884 | |
| 885 | /* |
| 886 | * S_force_word |
| 887 | * When the lexer knows the next thing is a word (for instance, it has |
| 888 | * just seen -> and it knows that the next char is a word char, then |
| 889 | * it calls S_force_word to stick the next word into the PL_next lookahead. |
| 890 | * |
| 891 | * Arguments: |
| 892 | * char *start : buffer position (must be within PL_linestr) |
| 893 | * int token : PL_next will be this type of bare word (e.g., METHOD,WORD) |
| 894 | * int check_keyword : if true, Perl checks to make sure the word isn't |
| 895 | * a keyword (do this if the word is a label, e.g. goto FOO) |
| 896 | * int allow_pack : if true, : characters will also be allowed (require, |
| 897 | * use, etc. do this) |
| 898 | * int allow_initial_tick : used by the "sub" lexer only. |
| 899 | */ |
| 900 | |
| 901 | STATIC char * |
| 902 | S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick) |
| 903 | { |
| 904 | register char *s; |
| 905 | STRLEN len; |
| 906 | |
| 907 | start = skipspace(start); |
| 908 | s = start; |
| 909 | if (isIDFIRST_lazy_if(s,UTF) || |
| 910 | (allow_pack && *s == ':') || |
| 911 | (allow_initial_tick && *s == '\'') ) |
| 912 | { |
| 913 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len); |
| 914 | if (check_keyword && keyword(PL_tokenbuf, len)) |
| 915 | return start; |
| 916 | if (token == METHOD) { |
| 917 | s = skipspace(s); |
| 918 | if (*s == '(') |
| 919 | PL_expect = XTERM; |
| 920 | else { |
| 921 | PL_expect = XOPERATOR; |
| 922 | } |
| 923 | } |
| 924 | PL_nextval[PL_nexttoke].opval |
| 925 | = (OP*)newSVOP(OP_CONST,0, |
| 926 | S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len)); |
| 927 | PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE; |
| 928 | force_next(token); |
| 929 | } |
| 930 | return s; |
| 931 | } |
| 932 | |
| 933 | /* |
| 934 | * S_force_ident |
| 935 | * Called when the lexer wants $foo *foo &foo etc, but the program |
| 936 | * text only contains the "foo" portion. The first argument is a pointer |
| 937 | * to the "foo", and the second argument is the type symbol to prefix. |
| 938 | * Forces the next token to be a "WORD". |
| 939 | * Creates the symbol if it didn't already exist (via gv_fetchpv()). |
| 940 | */ |
| 941 | |
| 942 | STATIC void |
| 943 | S_force_ident(pTHX_ register const char *s, int kind) |
| 944 | { |
| 945 | if (s && *s) { |
| 946 | OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0)); |
| 947 | PL_nextval[PL_nexttoke].opval = o; |
| 948 | force_next(WORD); |
| 949 | if (kind) { |
| 950 | o->op_private = OPpCONST_ENTERED; |
| 951 | /* XXX see note in pp_entereval() for why we forgo typo |
| 952 | warnings if the symbol must be introduced in an eval. |
| 953 | GSAR 96-10-12 */ |
| 954 | gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE, |
| 955 | kind == '$' ? SVt_PV : |
| 956 | kind == '@' ? SVt_PVAV : |
| 957 | kind == '%' ? SVt_PVHV : |
| 958 | SVt_PVGV |
| 959 | ); |
| 960 | } |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | NV |
| 965 | Perl_str_to_version(pTHX_ SV *sv) |
| 966 | { |
| 967 | NV retval = 0.0; |
| 968 | NV nshift = 1.0; |
| 969 | STRLEN len; |
| 970 | char *start = SvPVx(sv,len); |
| 971 | bool utf = SvUTF8(sv) ? TRUE : FALSE; |
| 972 | char *end = start + len; |
| 973 | while (start < end) { |
| 974 | STRLEN skip; |
| 975 | UV n; |
| 976 | if (utf) |
| 977 | n = utf8n_to_uvchr((U8*)start, len, &skip, 0); |
| 978 | else { |
| 979 | n = *(U8*)start; |
| 980 | skip = 1; |
| 981 | } |
| 982 | retval += ((NV)n)/nshift; |
| 983 | start += skip; |
| 984 | nshift *= 1000; |
| 985 | } |
| 986 | return retval; |
| 987 | } |
| 988 | |
| 989 | /* |
| 990 | * S_force_version |
| 991 | * Forces the next token to be a version number. |
| 992 | * If the next token appears to be an invalid version number, (e.g. "v2b"), |
| 993 | * and if "guessing" is TRUE, then no new token is created (and the caller |
| 994 | * must use an alternative parsing method). |
| 995 | */ |
| 996 | |
| 997 | STATIC char * |
| 998 | S_force_version(pTHX_ char *s, int guessing) |
| 999 | { |
| 1000 | OP *version = Nullop; |
| 1001 | char *d; |
| 1002 | |
| 1003 | s = skipspace(s); |
| 1004 | |
| 1005 | d = s; |
| 1006 | if (*d == 'v') |
| 1007 | d++; |
| 1008 | if (isDIGIT(*d)) { |
| 1009 | while (isDIGIT(*d) || *d == '_' || *d == '.') |
| 1010 | d++; |
| 1011 | if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) { |
| 1012 | SV *ver; |
| 1013 | s = scan_num(s, &yylval); |
| 1014 | version = yylval.opval; |
| 1015 | ver = cSVOPx(version)->op_sv; |
| 1016 | if (SvPOK(ver) && !SvNIOK(ver)) { |
| 1017 | (void)SvUPGRADE(ver, SVt_PVNV); |
| 1018 | SvNV_set(ver, str_to_version(ver)); |
| 1019 | SvNOK_on(ver); /* hint that it is a version */ |
| 1020 | } |
| 1021 | } |
| 1022 | else if (guessing) |
| 1023 | return s; |
| 1024 | } |
| 1025 | |
| 1026 | /* NOTE: The parser sees the package name and the VERSION swapped */ |
| 1027 | PL_nextval[PL_nexttoke].opval = version; |
| 1028 | force_next(WORD); |
| 1029 | |
| 1030 | return s; |
| 1031 | } |
| 1032 | |
| 1033 | /* |
| 1034 | * S_tokeq |
| 1035 | * Tokenize a quoted string passed in as an SV. It finds the next |
| 1036 | * chunk, up to end of string or a backslash. It may make a new |
| 1037 | * SV containing that chunk (if HINT_NEW_STRING is on). It also |
| 1038 | * turns \\ into \. |
| 1039 | */ |
| 1040 | |
| 1041 | STATIC SV * |
| 1042 | S_tokeq(pTHX_ SV *sv) |
| 1043 | { |
| 1044 | register char *s; |
| 1045 | register char *send; |
| 1046 | register char *d; |
| 1047 | STRLEN len = 0; |
| 1048 | SV *pv = sv; |
| 1049 | |
| 1050 | if (!SvLEN(sv)) |
| 1051 | goto finish; |
| 1052 | |
| 1053 | s = SvPV_force(sv, len); |
| 1054 | if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1) |
| 1055 | goto finish; |
| 1056 | send = s + len; |
| 1057 | while (s < send && *s != '\\') |
| 1058 | s++; |
| 1059 | if (s == send) |
| 1060 | goto finish; |
| 1061 | d = s; |
| 1062 | if ( PL_hints & HINT_NEW_STRING ) { |
| 1063 | pv = sv_2mortal(newSVpvn(SvPVX(pv), len)); |
| 1064 | if (SvUTF8(sv)) |
| 1065 | SvUTF8_on(pv); |
| 1066 | } |
| 1067 | while (s < send) { |
| 1068 | if (*s == '\\') { |
| 1069 | if (s + 1 < send && (s[1] == '\\')) |
| 1070 | s++; /* all that, just for this */ |
| 1071 | } |
| 1072 | *d++ = *s++; |
| 1073 | } |
| 1074 | *d = '\0'; |
| 1075 | SvCUR_set(sv, d - SvPVX(sv)); |
| 1076 | finish: |
| 1077 | if ( PL_hints & HINT_NEW_STRING ) |
| 1078 | return new_constant(NULL, 0, "q", sv, pv, "q"); |
| 1079 | return sv; |
| 1080 | } |
| 1081 | |
| 1082 | /* |
| 1083 | * Now come three functions related to double-quote context, |
| 1084 | * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when |
| 1085 | * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They |
| 1086 | * interact with PL_lex_state, and create fake ( ... ) argument lists |
| 1087 | * to handle functions and concatenation. |
| 1088 | * They assume that whoever calls them will be setting up a fake |
| 1089 | * join call, because each subthing puts a ',' after it. This lets |
| 1090 | * "lower \luPpEr" |
| 1091 | * become |
| 1092 | * join($, , 'lower ', lcfirst( 'uPpEr', ) ,) |
| 1093 | * |
| 1094 | * (I'm not sure whether the spurious commas at the end of lcfirst's |
| 1095 | * arguments and join's arguments are created or not). |
| 1096 | */ |
| 1097 | |
| 1098 | /* |
| 1099 | * S_sublex_start |
| 1100 | * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST). |
| 1101 | * |
| 1102 | * Pattern matching will set PL_lex_op to the pattern-matching op to |
| 1103 | * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise). |
| 1104 | * |
| 1105 | * OP_CONST and OP_READLINE are easy--just make the new op and return. |
| 1106 | * |
| 1107 | * Everything else becomes a FUNC. |
| 1108 | * |
| 1109 | * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we |
| 1110 | * had an OP_CONST or OP_READLINE). This just sets us up for a |
| 1111 | * call to S_sublex_push(). |
| 1112 | */ |
| 1113 | |
| 1114 | STATIC I32 |
| 1115 | S_sublex_start(pTHX) |
| 1116 | { |
| 1117 | register I32 op_type = yylval.ival; |
| 1118 | |
| 1119 | if (op_type == OP_NULL) { |
| 1120 | yylval.opval = PL_lex_op; |
| 1121 | PL_lex_op = Nullop; |
| 1122 | return THING; |
| 1123 | } |
| 1124 | if (op_type == OP_CONST || op_type == OP_READLINE) { |
| 1125 | SV *sv = tokeq(PL_lex_stuff); |
| 1126 | |
| 1127 | if (SvTYPE(sv) == SVt_PVIV) { |
| 1128 | /* Overloaded constants, nothing fancy: Convert to SVt_PV: */ |
| 1129 | STRLEN len; |
| 1130 | char *p; |
| 1131 | SV *nsv; |
| 1132 | |
| 1133 | p = SvPV(sv, len); |
| 1134 | nsv = newSVpvn(p, len); |
| 1135 | if (SvUTF8(sv)) |
| 1136 | SvUTF8_on(nsv); |
| 1137 | SvREFCNT_dec(sv); |
| 1138 | sv = nsv; |
| 1139 | } |
| 1140 | yylval.opval = (OP*)newSVOP(op_type, 0, sv); |
| 1141 | PL_lex_stuff = Nullsv; |
| 1142 | /* Allow <FH> // "foo" */ |
| 1143 | if (op_type == OP_READLINE) |
| 1144 | PL_expect = XTERMORDORDOR; |
| 1145 | return THING; |
| 1146 | } |
| 1147 | |
| 1148 | PL_sublex_info.super_state = PL_lex_state; |
| 1149 | PL_sublex_info.sub_inwhat = op_type; |
| 1150 | PL_sublex_info.sub_op = PL_lex_op; |
| 1151 | PL_lex_state = LEX_INTERPPUSH; |
| 1152 | |
| 1153 | PL_expect = XTERM; |
| 1154 | if (PL_lex_op) { |
| 1155 | yylval.opval = PL_lex_op; |
| 1156 | PL_lex_op = Nullop; |
| 1157 | return PMFUNC; |
| 1158 | } |
| 1159 | else |
| 1160 | return FUNC; |
| 1161 | } |
| 1162 | |
| 1163 | /* |
| 1164 | * S_sublex_push |
| 1165 | * Create a new scope to save the lexing state. The scope will be |
| 1166 | * ended in S_sublex_done. Returns a '(', starting the function arguments |
| 1167 | * to the uc, lc, etc. found before. |
| 1168 | * Sets PL_lex_state to LEX_INTERPCONCAT. |
| 1169 | */ |
| 1170 | |
| 1171 | STATIC I32 |
| 1172 | S_sublex_push(pTHX) |
| 1173 | { |
| 1174 | dVAR; |
| 1175 | ENTER; |
| 1176 | |
| 1177 | PL_lex_state = PL_sublex_info.super_state; |
| 1178 | SAVEI32(PL_lex_dojoin); |
| 1179 | SAVEI32(PL_lex_brackets); |
| 1180 | SAVEI32(PL_lex_casemods); |
| 1181 | SAVEI32(PL_lex_starts); |
| 1182 | SAVEI32(PL_lex_state); |
| 1183 | SAVEVPTR(PL_lex_inpat); |
| 1184 | SAVEI32(PL_lex_inwhat); |
| 1185 | SAVECOPLINE(PL_curcop); |
| 1186 | SAVEPPTR(PL_bufptr); |
| 1187 | SAVEPPTR(PL_bufend); |
| 1188 | SAVEPPTR(PL_oldbufptr); |
| 1189 | SAVEPPTR(PL_oldoldbufptr); |
| 1190 | SAVEPPTR(PL_last_lop); |
| 1191 | SAVEPPTR(PL_last_uni); |
| 1192 | SAVEPPTR(PL_linestart); |
| 1193 | SAVESPTR(PL_linestr); |
| 1194 | SAVEGENERICPV(PL_lex_brackstack); |
| 1195 | SAVEGENERICPV(PL_lex_casestack); |
| 1196 | |
| 1197 | PL_linestr = PL_lex_stuff; |
| 1198 | PL_lex_stuff = Nullsv; |
| 1199 | |
| 1200 | PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart |
| 1201 | = SvPVX(PL_linestr); |
| 1202 | PL_bufend += SvCUR(PL_linestr); |
| 1203 | PL_last_lop = PL_last_uni = Nullch; |
| 1204 | SAVEFREESV(PL_linestr); |
| 1205 | |
| 1206 | PL_lex_dojoin = FALSE; |
| 1207 | PL_lex_brackets = 0; |
| 1208 | New(899, PL_lex_brackstack, 120, char); |
| 1209 | New(899, PL_lex_casestack, 12, char); |
| 1210 | PL_lex_casemods = 0; |
| 1211 | *PL_lex_casestack = '\0'; |
| 1212 | PL_lex_starts = 0; |
| 1213 | PL_lex_state = LEX_INTERPCONCAT; |
| 1214 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
| 1215 | |
| 1216 | PL_lex_inwhat = PL_sublex_info.sub_inwhat; |
| 1217 | if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST) |
| 1218 | PL_lex_inpat = PL_sublex_info.sub_op; |
| 1219 | else |
| 1220 | PL_lex_inpat = Nullop; |
| 1221 | |
| 1222 | return '('; |
| 1223 | } |
| 1224 | |
| 1225 | /* |
| 1226 | * S_sublex_done |
| 1227 | * Restores lexer state after a S_sublex_push. |
| 1228 | */ |
| 1229 | |
| 1230 | STATIC I32 |
| 1231 | S_sublex_done(pTHX) |
| 1232 | { |
| 1233 | dVAR; |
| 1234 | if (!PL_lex_starts++) { |
| 1235 | SV *sv = newSVpvn("",0); |
| 1236 | if (SvUTF8(PL_linestr)) |
| 1237 | SvUTF8_on(sv); |
| 1238 | PL_expect = XOPERATOR; |
| 1239 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
| 1240 | return THING; |
| 1241 | } |
| 1242 | |
| 1243 | if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */ |
| 1244 | PL_lex_state = LEX_INTERPCASEMOD; |
| 1245 | return yylex(); |
| 1246 | } |
| 1247 | |
| 1248 | /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */ |
| 1249 | if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) { |
| 1250 | PL_linestr = PL_lex_repl; |
| 1251 | PL_lex_inpat = 0; |
| 1252 | PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr); |
| 1253 | PL_bufend += SvCUR(PL_linestr); |
| 1254 | PL_last_lop = PL_last_uni = Nullch; |
| 1255 | SAVEFREESV(PL_linestr); |
| 1256 | PL_lex_dojoin = FALSE; |
| 1257 | PL_lex_brackets = 0; |
| 1258 | PL_lex_casemods = 0; |
| 1259 | *PL_lex_casestack = '\0'; |
| 1260 | PL_lex_starts = 0; |
| 1261 | if (SvEVALED(PL_lex_repl)) { |
| 1262 | PL_lex_state = LEX_INTERPNORMAL; |
| 1263 | PL_lex_starts++; |
| 1264 | /* we don't clear PL_lex_repl here, so that we can check later |
| 1265 | whether this is an evalled subst; that means we rely on the |
| 1266 | logic to ensure sublex_done() is called again only via the |
| 1267 | branch (in yylex()) that clears PL_lex_repl, else we'll loop */ |
| 1268 | } |
| 1269 | else { |
| 1270 | PL_lex_state = LEX_INTERPCONCAT; |
| 1271 | PL_lex_repl = Nullsv; |
| 1272 | } |
| 1273 | return ','; |
| 1274 | } |
| 1275 | else { |
| 1276 | LEAVE; |
| 1277 | PL_bufend = SvPVX(PL_linestr); |
| 1278 | PL_bufend += SvCUR(PL_linestr); |
| 1279 | PL_expect = XOPERATOR; |
| 1280 | PL_sublex_info.sub_inwhat = 0; |
| 1281 | return ')'; |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | /* |
| 1286 | scan_const |
| 1287 | |
| 1288 | Extracts a pattern, double-quoted string, or transliteration. This |
| 1289 | is terrifying code. |
| 1290 | |
| 1291 | It looks at lex_inwhat and PL_lex_inpat to find out whether it's |
| 1292 | processing a pattern (PL_lex_inpat is true), a transliteration |
| 1293 | (lex_inwhat & OP_TRANS is true), or a double-quoted string. |
| 1294 | |
| 1295 | Returns a pointer to the character scanned up to. Iff this is |
| 1296 | advanced from the start pointer supplied (ie if anything was |
| 1297 | successfully parsed), will leave an OP for the substring scanned |
| 1298 | in yylval. Caller must intuit reason for not parsing further |
| 1299 | by looking at the next characters herself. |
| 1300 | |
| 1301 | In patterns: |
| 1302 | backslashes: |
| 1303 | double-quoted style: \r and \n |
| 1304 | regexp special ones: \D \s |
| 1305 | constants: \x3 |
| 1306 | backrefs: \1 (deprecated in substitution replacements) |
| 1307 | case and quoting: \U \Q \E |
| 1308 | stops on @ and $, but not for $ as tail anchor |
| 1309 | |
| 1310 | In transliterations: |
| 1311 | characters are VERY literal, except for - not at the start or end |
| 1312 | of the string, which indicates a range. scan_const expands the |
| 1313 | range to the full set of intermediate characters. |
| 1314 | |
| 1315 | In double-quoted strings: |
| 1316 | backslashes: |
| 1317 | double-quoted style: \r and \n |
| 1318 | constants: \x3 |
| 1319 | backrefs: \1 (deprecated) |
| 1320 | case and quoting: \U \Q \E |
| 1321 | stops on @ and $ |
| 1322 | |
| 1323 | scan_const does *not* construct ops to handle interpolated strings. |
| 1324 | It stops processing as soon as it finds an embedded $ or @ variable |
| 1325 | and leaves it to the caller to work out what's going on. |
| 1326 | |
| 1327 | @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo. |
| 1328 | |
| 1329 | $ in pattern could be $foo or could be tail anchor. Assumption: |
| 1330 | it's a tail anchor if $ is the last thing in the string, or if it's |
| 1331 | followed by one of ")| \n\t" |
| 1332 | |
| 1333 | \1 (backreferences) are turned into $1 |
| 1334 | |
| 1335 | The structure of the code is |
| 1336 | while (there's a character to process) { |
| 1337 | handle transliteration ranges |
| 1338 | skip regexp comments |
| 1339 | skip # initiated comments in //x patterns |
| 1340 | check for embedded @foo |
| 1341 | check for embedded scalars |
| 1342 | if (backslash) { |
| 1343 | leave intact backslashes from leave (below) |
| 1344 | deprecate \1 in strings and sub replacements |
| 1345 | handle string-changing backslashes \l \U \Q \E, etc. |
| 1346 | switch (what was escaped) { |
| 1347 | handle - in a transliteration (becomes a literal -) |
| 1348 | handle \132 octal characters |
| 1349 | handle 0x15 hex characters |
| 1350 | handle \cV (control V) |
| 1351 | handle printf backslashes (\f, \r, \n, etc) |
| 1352 | } (end switch) |
| 1353 | } (end if backslash) |
| 1354 | } (end while character to read) |
| 1355 | |
| 1356 | */ |
| 1357 | |
| 1358 | STATIC char * |
| 1359 | S_scan_const(pTHX_ char *start) |
| 1360 | { |
| 1361 | register char *send = PL_bufend; /* end of the constant */ |
| 1362 | SV *sv = NEWSV(93, send - start); /* sv for the constant */ |
| 1363 | register char *s = start; /* start of the constant */ |
| 1364 | register char *d = SvPVX(sv); /* destination for copies */ |
| 1365 | bool dorange = FALSE; /* are we in a translit range? */ |
| 1366 | bool didrange = FALSE; /* did we just finish a range? */ |
| 1367 | I32 has_utf8 = FALSE; /* Output constant is UTF8 */ |
| 1368 | I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */ |
| 1369 | UV uv; |
| 1370 | |
| 1371 | const char *leaveit = /* set of acceptably-backslashed characters */ |
| 1372 | PL_lex_inpat |
| 1373 | ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#" |
| 1374 | : ""; |
| 1375 | |
| 1376 | if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) { |
| 1377 | /* If we are doing a trans and we know we want UTF8 set expectation */ |
| 1378 | has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF); |
| 1379 | this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); |
| 1380 | } |
| 1381 | |
| 1382 | |
| 1383 | while (s < send || dorange) { |
| 1384 | /* get transliterations out of the way (they're most literal) */ |
| 1385 | if (PL_lex_inwhat == OP_TRANS) { |
| 1386 | /* expand a range A-Z to the full set of characters. AIE! */ |
| 1387 | if (dorange) { |
| 1388 | I32 i; /* current expanded character */ |
| 1389 | I32 min; /* first character in range */ |
| 1390 | I32 max; /* last character in range */ |
| 1391 | |
| 1392 | if (has_utf8) { |
| 1393 | char *c = (char*)utf8_hop((U8*)d, -1); |
| 1394 | char *e = d++; |
| 1395 | while (e-- > c) |
| 1396 | *(e + 1) = *e; |
| 1397 | *c = (char)UTF_TO_NATIVE(0xff); |
| 1398 | /* mark the range as done, and continue */ |
| 1399 | dorange = FALSE; |
| 1400 | didrange = TRUE; |
| 1401 | continue; |
| 1402 | } |
| 1403 | |
| 1404 | i = d - SvPVX(sv); /* remember current offset */ |
| 1405 | SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */ |
| 1406 | d = SvPVX(sv) + i; /* refresh d after realloc */ |
| 1407 | d -= 2; /* eat the first char and the - */ |
| 1408 | |
| 1409 | min = (U8)*d; /* first char in range */ |
| 1410 | max = (U8)d[1]; /* last char in range */ |
| 1411 | |
| 1412 | if (min > max) { |
| 1413 | Perl_croak(aTHX_ |
| 1414 | "Invalid range \"%c-%c\" in transliteration operator", |
| 1415 | (char)min, (char)max); |
| 1416 | } |
| 1417 | |
| 1418 | #ifdef EBCDIC |
| 1419 | if ((isLOWER(min) && isLOWER(max)) || |
| 1420 | (isUPPER(min) && isUPPER(max))) { |
| 1421 | if (isLOWER(min)) { |
| 1422 | for (i = min; i <= max; i++) |
| 1423 | if (isLOWER(i)) |
| 1424 | *d++ = NATIVE_TO_NEED(has_utf8,i); |
| 1425 | } else { |
| 1426 | for (i = min; i <= max; i++) |
| 1427 | if (isUPPER(i)) |
| 1428 | *d++ = NATIVE_TO_NEED(has_utf8,i); |
| 1429 | } |
| 1430 | } |
| 1431 | else |
| 1432 | #endif |
| 1433 | for (i = min; i <= max; i++) |
| 1434 | *d++ = (char)i; |
| 1435 | |
| 1436 | /* mark the range as done, and continue */ |
| 1437 | dorange = FALSE; |
| 1438 | didrange = TRUE; |
| 1439 | continue; |
| 1440 | } |
| 1441 | |
| 1442 | /* range begins (ignore - as first or last char) */ |
| 1443 | else if (*s == '-' && s+1 < send && s != start) { |
| 1444 | if (didrange) { |
| 1445 | Perl_croak(aTHX_ "Ambiguous range in transliteration operator"); |
| 1446 | } |
| 1447 | if (has_utf8) { |
| 1448 | *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */ |
| 1449 | s++; |
| 1450 | continue; |
| 1451 | } |
| 1452 | dorange = TRUE; |
| 1453 | s++; |
| 1454 | } |
| 1455 | else { |
| 1456 | didrange = FALSE; |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | /* if we get here, we're not doing a transliteration */ |
| 1461 | |
| 1462 | /* skip for regexp comments /(?#comment)/ and code /(?{code})/, |
| 1463 | except for the last char, which will be done separately. */ |
| 1464 | else if (*s == '(' && PL_lex_inpat && s[1] == '?') { |
| 1465 | if (s[2] == '#') { |
| 1466 | while (s+1 < send && *s != ')') |
| 1467 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
| 1468 | } |
| 1469 | else if (s[2] == '{' /* This should match regcomp.c */ |
| 1470 | || ((s[2] == 'p' || s[2] == '?') && s[3] == '{')) |
| 1471 | { |
| 1472 | I32 count = 1; |
| 1473 | char *regparse = s + (s[2] == '{' ? 3 : 4); |
| 1474 | char c; |
| 1475 | |
| 1476 | while (count && (c = *regparse)) { |
| 1477 | if (c == '\\' && regparse[1]) |
| 1478 | regparse++; |
| 1479 | else if (c == '{') |
| 1480 | count++; |
| 1481 | else if (c == '}') |
| 1482 | count--; |
| 1483 | regparse++; |
| 1484 | } |
| 1485 | if (*regparse != ')') |
| 1486 | regparse--; /* Leave one char for continuation. */ |
| 1487 | while (s < regparse) |
| 1488 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | /* likewise skip #-initiated comments in //x patterns */ |
| 1493 | else if (*s == '#' && PL_lex_inpat && |
| 1494 | ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) { |
| 1495 | while (s+1 < send && *s != '\n') |
| 1496 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
| 1497 | } |
| 1498 | |
| 1499 | /* check for embedded arrays |
| 1500 | (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-) |
| 1501 | */ |
| 1502 | else if (*s == '@' && s[1] |
| 1503 | && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1]))) |
| 1504 | break; |
| 1505 | |
| 1506 | /* check for embedded scalars. only stop if we're sure it's a |
| 1507 | variable. |
| 1508 | */ |
| 1509 | else if (*s == '$') { |
| 1510 | if (!PL_lex_inpat) /* not a regexp, so $ must be var */ |
| 1511 | break; |
| 1512 | if (s + 1 < send && !strchr("()| \r\n\t", s[1])) |
| 1513 | break; /* in regexp, $ might be tail anchor */ |
| 1514 | } |
| 1515 | |
| 1516 | /* End of else if chain - OP_TRANS rejoin rest */ |
| 1517 | |
| 1518 | /* backslashes */ |
| 1519 | if (*s == '\\' && s+1 < send) { |
| 1520 | s++; |
| 1521 | |
| 1522 | /* some backslashes we leave behind */ |
| 1523 | if (*leaveit && *s && strchr(leaveit, *s)) { |
| 1524 | *d++ = NATIVE_TO_NEED(has_utf8,'\\'); |
| 1525 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
| 1526 | continue; |
| 1527 | } |
| 1528 | |
| 1529 | /* deprecate \1 in strings and substitution replacements */ |
| 1530 | if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat && |
| 1531 | isDIGIT(*s) && *s != '0' && !isDIGIT(s[1])) |
| 1532 | { |
| 1533 | if (ckWARN(WARN_SYNTAX)) |
| 1534 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s); |
| 1535 | *--s = '$'; |
| 1536 | break; |
| 1537 | } |
| 1538 | |
| 1539 | /* string-change backslash escapes */ |
| 1540 | if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) { |
| 1541 | --s; |
| 1542 | break; |
| 1543 | } |
| 1544 | |
| 1545 | /* if we get here, it's either a quoted -, or a digit */ |
| 1546 | switch (*s) { |
| 1547 | |
| 1548 | /* quoted - in transliterations */ |
| 1549 | case '-': |
| 1550 | if (PL_lex_inwhat == OP_TRANS) { |
| 1551 | *d++ = *s++; |
| 1552 | continue; |
| 1553 | } |
| 1554 | /* FALL THROUGH */ |
| 1555 | default: |
| 1556 | { |
| 1557 | if (ckWARN(WARN_MISC) && |
| 1558 | isALNUM(*s) && |
| 1559 | *s != '_') |
| 1560 | Perl_warner(aTHX_ packWARN(WARN_MISC), |
| 1561 | "Unrecognized escape \\%c passed through", |
| 1562 | *s); |
| 1563 | /* default action is to copy the quoted character */ |
| 1564 | goto default_action; |
| 1565 | } |
| 1566 | |
| 1567 | /* \132 indicates an octal constant */ |
| 1568 | case '0': case '1': case '2': case '3': |
| 1569 | case '4': case '5': case '6': case '7': |
| 1570 | { |
| 1571 | I32 flags = 0; |
| 1572 | STRLEN len = 3; |
| 1573 | uv = grok_oct(s, &len, &flags, NULL); |
| 1574 | s += len; |
| 1575 | } |
| 1576 | goto NUM_ESCAPE_INSERT; |
| 1577 | |
| 1578 | /* \x24 indicates a hex constant */ |
| 1579 | case 'x': |
| 1580 | ++s; |
| 1581 | if (*s == '{') { |
| 1582 | char* e = strchr(s, '}'); |
| 1583 | I32 flags = PERL_SCAN_ALLOW_UNDERSCORES | |
| 1584 | PERL_SCAN_DISALLOW_PREFIX; |
| 1585 | STRLEN len; |
| 1586 | |
| 1587 | ++s; |
| 1588 | if (!e) { |
| 1589 | yyerror("Missing right brace on \\x{}"); |
| 1590 | continue; |
| 1591 | } |
| 1592 | len = e - s; |
| 1593 | uv = grok_hex(s, &len, &flags, NULL); |
| 1594 | s = e + 1; |
| 1595 | } |
| 1596 | else { |
| 1597 | { |
| 1598 | STRLEN len = 2; |
| 1599 | I32 flags = PERL_SCAN_DISALLOW_PREFIX; |
| 1600 | uv = grok_hex(s, &len, &flags, NULL); |
| 1601 | s += len; |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | NUM_ESCAPE_INSERT: |
| 1606 | /* Insert oct or hex escaped character. |
| 1607 | * There will always enough room in sv since such |
| 1608 | * escapes will be longer than any UTF-8 sequence |
| 1609 | * they can end up as. */ |
| 1610 | |
| 1611 | /* We need to map to chars to ASCII before doing the tests |
| 1612 | to cover EBCDIC |
| 1613 | */ |
| 1614 | if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) { |
| 1615 | if (!has_utf8 && uv > 255) { |
| 1616 | /* Might need to recode whatever we have |
| 1617 | * accumulated so far if it contains any |
| 1618 | * hibit chars. |
| 1619 | * |
| 1620 | * (Can't we keep track of that and avoid |
| 1621 | * this rescan? --jhi) |
| 1622 | */ |
| 1623 | int hicount = 0; |
| 1624 | U8 *c; |
| 1625 | for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) { |
| 1626 | if (!NATIVE_IS_INVARIANT(*c)) { |
| 1627 | hicount++; |
| 1628 | } |
| 1629 | } |
| 1630 | if (hicount) { |
| 1631 | STRLEN offset = d - SvPVX(sv); |
| 1632 | U8 *src, *dst; |
| 1633 | d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset; |
| 1634 | src = (U8 *)d - 1; |
| 1635 | dst = src+hicount; |
| 1636 | d += hicount; |
| 1637 | while (src >= (U8 *)SvPVX(sv)) { |
| 1638 | if (!NATIVE_IS_INVARIANT(*src)) { |
| 1639 | U8 ch = NATIVE_TO_ASCII(*src); |
| 1640 | *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch); |
| 1641 | *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch); |
| 1642 | } |
| 1643 | else { |
| 1644 | *dst-- = *src; |
| 1645 | } |
| 1646 | src--; |
| 1647 | } |
| 1648 | } |
| 1649 | } |
| 1650 | |
| 1651 | if (has_utf8 || uv > 255) { |
| 1652 | d = (char*)uvchr_to_utf8((U8*)d, uv); |
| 1653 | has_utf8 = TRUE; |
| 1654 | if (PL_lex_inwhat == OP_TRANS && |
| 1655 | PL_sublex_info.sub_op) { |
| 1656 | PL_sublex_info.sub_op->op_private |= |
| 1657 | (PL_lex_repl ? OPpTRANS_FROM_UTF |
| 1658 | : OPpTRANS_TO_UTF); |
| 1659 | } |
| 1660 | } |
| 1661 | else { |
| 1662 | *d++ = (char)uv; |
| 1663 | } |
| 1664 | } |
| 1665 | else { |
| 1666 | *d++ = (char) uv; |
| 1667 | } |
| 1668 | continue; |
| 1669 | |
| 1670 | /* \N{LATIN SMALL LETTER A} is a named character */ |
| 1671 | case 'N': |
| 1672 | ++s; |
| 1673 | if (*s == '{') { |
| 1674 | char* e = strchr(s, '}'); |
| 1675 | SV *res; |
| 1676 | STRLEN len; |
| 1677 | char *str; |
| 1678 | |
| 1679 | if (!e) { |
| 1680 | yyerror("Missing right brace on \\N{}"); |
| 1681 | e = s - 1; |
| 1682 | goto cont_scan; |
| 1683 | } |
| 1684 | if (e > s + 2 && s[1] == 'U' && s[2] == '+') { |
| 1685 | /* \N{U+...} */ |
| 1686 | I32 flags = PERL_SCAN_ALLOW_UNDERSCORES | |
| 1687 | PERL_SCAN_DISALLOW_PREFIX; |
| 1688 | s += 3; |
| 1689 | len = e - s; |
| 1690 | uv = grok_hex(s, &len, &flags, NULL); |
| 1691 | s = e + 1; |
| 1692 | goto NUM_ESCAPE_INSERT; |
| 1693 | } |
| 1694 | res = newSVpvn(s + 1, e - s - 1); |
| 1695 | res = new_constant( Nullch, 0, "charnames", |
| 1696 | res, Nullsv, "\\N{...}" ); |
| 1697 | if (has_utf8) |
| 1698 | sv_utf8_upgrade(res); |
| 1699 | str = SvPV(res,len); |
| 1700 | #ifdef EBCDIC_NEVER_MIND |
| 1701 | /* charnames uses pack U and that has been |
| 1702 | * recently changed to do the below uni->native |
| 1703 | * mapping, so this would be redundant (and wrong, |
| 1704 | * the code point would be doubly converted). |
| 1705 | * But leave this in just in case the pack U change |
| 1706 | * gets revoked, but the semantics is still |
| 1707 | * desireable for charnames. --jhi */ |
| 1708 | { |
| 1709 | UV uv = utf8_to_uvchr((U8*)str, 0); |
| 1710 | |
| 1711 | if (uv < 0x100) { |
| 1712 | U8 tmpbuf[UTF8_MAXBYTES+1], *d; |
| 1713 | |
| 1714 | d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv)); |
| 1715 | sv_setpvn(res, (char *)tmpbuf, d - tmpbuf); |
| 1716 | str = SvPV(res, len); |
| 1717 | } |
| 1718 | } |
| 1719 | #endif |
| 1720 | if (!has_utf8 && SvUTF8(res)) { |
| 1721 | char *ostart = SvPVX(sv); |
| 1722 | SvCUR_set(sv, d - ostart); |
| 1723 | SvPOK_on(sv); |
| 1724 | *d = '\0'; |
| 1725 | sv_utf8_upgrade(sv); |
| 1726 | /* this just broke our allocation above... */ |
| 1727 | SvGROW(sv, (STRLEN)(send - start)); |
| 1728 | d = SvPVX(sv) + SvCUR(sv); |
| 1729 | has_utf8 = TRUE; |
| 1730 | } |
| 1731 | if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */ |
| 1732 | char *odest = SvPVX(sv); |
| 1733 | |
| 1734 | SvGROW(sv, (SvLEN(sv) + len - (e - s + 4))); |
| 1735 | d = SvPVX(sv) + (d - odest); |
| 1736 | } |
| 1737 | Copy(str, d, len, char); |
| 1738 | d += len; |
| 1739 | SvREFCNT_dec(res); |
| 1740 | cont_scan: |
| 1741 | s = e + 1; |
| 1742 | } |
| 1743 | else |
| 1744 | yyerror("Missing braces on \\N{}"); |
| 1745 | continue; |
| 1746 | |
| 1747 | /* \c is a control character */ |
| 1748 | case 'c': |
| 1749 | s++; |
| 1750 | if (s < send) { |
| 1751 | U8 c = *s++; |
| 1752 | #ifdef EBCDIC |
| 1753 | if (isLOWER(c)) |
| 1754 | c = toUPPER(c); |
| 1755 | #endif |
| 1756 | *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c)); |
| 1757 | } |
| 1758 | else { |
| 1759 | yyerror("Missing control char name in \\c"); |
| 1760 | } |
| 1761 | continue; |
| 1762 | |
| 1763 | /* printf-style backslashes, formfeeds, newlines, etc */ |
| 1764 | case 'b': |
| 1765 | *d++ = NATIVE_TO_NEED(has_utf8,'\b'); |
| 1766 | break; |
| 1767 | case 'n': |
| 1768 | *d++ = NATIVE_TO_NEED(has_utf8,'\n'); |
| 1769 | break; |
| 1770 | case 'r': |
| 1771 | *d++ = NATIVE_TO_NEED(has_utf8,'\r'); |
| 1772 | break; |
| 1773 | case 'f': |
| 1774 | *d++ = NATIVE_TO_NEED(has_utf8,'\f'); |
| 1775 | break; |
| 1776 | case 't': |
| 1777 | *d++ = NATIVE_TO_NEED(has_utf8,'\t'); |
| 1778 | break; |
| 1779 | case 'e': |
| 1780 | *d++ = ASCII_TO_NEED(has_utf8,'\033'); |
| 1781 | break; |
| 1782 | case 'a': |
| 1783 | *d++ = ASCII_TO_NEED(has_utf8,'\007'); |
| 1784 | break; |
| 1785 | } /* end switch */ |
| 1786 | |
| 1787 | s++; |
| 1788 | continue; |
| 1789 | } /* end if (backslash) */ |
| 1790 | |
| 1791 | default_action: |
| 1792 | /* If we started with encoded form, or already know we want it |
| 1793 | and then encode the next character */ |
| 1794 | if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) { |
| 1795 | STRLEN len = 1; |
| 1796 | UV uv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s); |
| 1797 | STRLEN need = UNISKIP(NATIVE_TO_UNI(uv)); |
| 1798 | s += len; |
| 1799 | if (need > len) { |
| 1800 | /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */ |
| 1801 | STRLEN off = d - SvPVX(sv); |
| 1802 | d = SvGROW(sv, SvLEN(sv) + (need-len)) + off; |
| 1803 | } |
| 1804 | d = (char*)uvchr_to_utf8((U8*)d, uv); |
| 1805 | has_utf8 = TRUE; |
| 1806 | } |
| 1807 | else { |
| 1808 | *d++ = NATIVE_TO_NEED(has_utf8,*s++); |
| 1809 | } |
| 1810 | } /* while loop to process each character */ |
| 1811 | |
| 1812 | /* terminate the string and set up the sv */ |
| 1813 | *d = '\0'; |
| 1814 | SvCUR_set(sv, d - SvPVX(sv)); |
| 1815 | if (SvCUR(sv) >= SvLEN(sv)) |
| 1816 | Perl_croak(aTHX_ "panic: constant overflowed allocated space"); |
| 1817 | |
| 1818 | SvPOK_on(sv); |
| 1819 | if (PL_encoding && !has_utf8) { |
| 1820 | sv_recode_to_utf8(sv, PL_encoding); |
| 1821 | if (SvUTF8(sv)) |
| 1822 | has_utf8 = TRUE; |
| 1823 | } |
| 1824 | if (has_utf8) { |
| 1825 | SvUTF8_on(sv); |
| 1826 | if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) { |
| 1827 | PL_sublex_info.sub_op->op_private |= |
| 1828 | (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | /* shrink the sv if we allocated more than we used */ |
| 1833 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
| 1834 | SvPV_shrink_to_cur(sv); |
| 1835 | } |
| 1836 | |
| 1837 | /* return the substring (via yylval) only if we parsed anything */ |
| 1838 | if (s > PL_bufptr) { |
| 1839 | if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) |
| 1840 | sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"), |
| 1841 | sv, Nullsv, |
| 1842 | ( PL_lex_inwhat == OP_TRANS |
| 1843 | ? "tr" |
| 1844 | : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) |
| 1845 | ? "s" |
| 1846 | : "qq"))); |
| 1847 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
| 1848 | } else |
| 1849 | SvREFCNT_dec(sv); |
| 1850 | return s; |
| 1851 | } |
| 1852 | |
| 1853 | /* S_intuit_more |
| 1854 | * Returns TRUE if there's more to the expression (e.g., a subscript), |
| 1855 | * FALSE otherwise. |
| 1856 | * |
| 1857 | * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/ |
| 1858 | * |
| 1859 | * ->[ and ->{ return TRUE |
| 1860 | * { and [ outside a pattern are always subscripts, so return TRUE |
| 1861 | * if we're outside a pattern and it's not { or [, then return FALSE |
| 1862 | * if we're in a pattern and the first char is a { |
| 1863 | * {4,5} (any digits around the comma) returns FALSE |
| 1864 | * if we're in a pattern and the first char is a [ |
| 1865 | * [] returns FALSE |
| 1866 | * [SOMETHING] has a funky algorithm to decide whether it's a |
| 1867 | * character class or not. It has to deal with things like |
| 1868 | * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/ |
| 1869 | * anything else returns TRUE |
| 1870 | */ |
| 1871 | |
| 1872 | /* This is the one truly awful dwimmer necessary to conflate C and sed. */ |
| 1873 | |
| 1874 | STATIC int |
| 1875 | S_intuit_more(pTHX_ register char *s) |
| 1876 | { |
| 1877 | if (PL_lex_brackets) |
| 1878 | return TRUE; |
| 1879 | if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{')) |
| 1880 | return TRUE; |
| 1881 | if (*s != '{' && *s != '[') |
| 1882 | return FALSE; |
| 1883 | if (!PL_lex_inpat) |
| 1884 | return TRUE; |
| 1885 | |
| 1886 | /* In a pattern, so maybe we have {n,m}. */ |
| 1887 | if (*s == '{') { |
| 1888 | s++; |
| 1889 | if (!isDIGIT(*s)) |
| 1890 | return TRUE; |
| 1891 | while (isDIGIT(*s)) |
| 1892 | s++; |
| 1893 | if (*s == ',') |
| 1894 | s++; |
| 1895 | while (isDIGIT(*s)) |
| 1896 | s++; |
| 1897 | if (*s == '}') |
| 1898 | return FALSE; |
| 1899 | return TRUE; |
| 1900 | |
| 1901 | } |
| 1902 | |
| 1903 | /* On the other hand, maybe we have a character class */ |
| 1904 | |
| 1905 | s++; |
| 1906 | if (*s == ']' || *s == '^') |
| 1907 | return FALSE; |
| 1908 | else { |
| 1909 | /* this is terrifying, and it works */ |
| 1910 | int weight = 2; /* let's weigh the evidence */ |
| 1911 | char seen[256]; |
| 1912 | unsigned char un_char = 255, last_un_char; |
| 1913 | char *send = strchr(s,']'); |
| 1914 | char tmpbuf[sizeof PL_tokenbuf * 4]; |
| 1915 | |
| 1916 | if (!send) /* has to be an expression */ |
| 1917 | return TRUE; |
| 1918 | |
| 1919 | Zero(seen,256,char); |
| 1920 | if (*s == '$') |
| 1921 | weight -= 3; |
| 1922 | else if (isDIGIT(*s)) { |
| 1923 | if (s[1] != ']') { |
| 1924 | if (isDIGIT(s[1]) && s[2] == ']') |
| 1925 | weight -= 10; |
| 1926 | } |
| 1927 | else |
| 1928 | weight -= 100; |
| 1929 | } |
| 1930 | for (; s < send; s++) { |
| 1931 | last_un_char = un_char; |
| 1932 | un_char = (unsigned char)*s; |
| 1933 | switch (*s) { |
| 1934 | case '@': |
| 1935 | case '&': |
| 1936 | case '$': |
| 1937 | weight -= seen[un_char] * 10; |
| 1938 | if (isALNUM_lazy_if(s+1,UTF)) { |
| 1939 | scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE); |
| 1940 | if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV)) |
| 1941 | weight -= 100; |
| 1942 | else |
| 1943 | weight -= 10; |
| 1944 | } |
| 1945 | else if (*s == '$' && s[1] && |
| 1946 | strchr("[#!%*<>()-=",s[1])) { |
| 1947 | if (/*{*/ strchr("])} =",s[2])) |
| 1948 | weight -= 10; |
| 1949 | else |
| 1950 | weight -= 1; |
| 1951 | } |
| 1952 | break; |
| 1953 | case '\\': |
| 1954 | un_char = 254; |
| 1955 | if (s[1]) { |
| 1956 | if (strchr("wds]",s[1])) |
| 1957 | weight += 100; |
| 1958 | else if (seen['\''] || seen['"']) |
| 1959 | weight += 1; |
| 1960 | else if (strchr("rnftbxcav",s[1])) |
| 1961 | weight += 40; |
| 1962 | else if (isDIGIT(s[1])) { |
| 1963 | weight += 40; |
| 1964 | while (s[1] && isDIGIT(s[1])) |
| 1965 | s++; |
| 1966 | } |
| 1967 | } |
| 1968 | else |
| 1969 | weight += 100; |
| 1970 | break; |
| 1971 | case '-': |
| 1972 | if (s[1] == '\\') |
| 1973 | weight += 50; |
| 1974 | if (strchr("aA01! ",last_un_char)) |
| 1975 | weight += 30; |
| 1976 | if (strchr("zZ79~",s[1])) |
| 1977 | weight += 30; |
| 1978 | if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$')) |
| 1979 | weight -= 5; /* cope with negative subscript */ |
| 1980 | break; |
| 1981 | default: |
| 1982 | if (!isALNUM(last_un_char) |
| 1983 | && !(last_un_char == '$' || last_un_char == '@' |
| 1984 | || last_un_char == '&') |
| 1985 | && isALPHA(*s) && s[1] && isALPHA(s[1])) { |
| 1986 | char *d = tmpbuf; |
| 1987 | while (isALPHA(*s)) |
| 1988 | *d++ = *s++; |
| 1989 | *d = '\0'; |
| 1990 | if (keyword(tmpbuf, d - tmpbuf)) |
| 1991 | weight -= 150; |
| 1992 | } |
| 1993 | if (un_char == last_un_char + 1) |
| 1994 | weight += 5; |
| 1995 | weight -= seen[un_char]; |
| 1996 | break; |
| 1997 | } |
| 1998 | seen[un_char]++; |
| 1999 | } |
| 2000 | if (weight >= 0) /* probably a character class */ |
| 2001 | return FALSE; |
| 2002 | } |
| 2003 | |
| 2004 | return TRUE; |
| 2005 | } |
| 2006 | |
| 2007 | /* |
| 2008 | * S_intuit_method |
| 2009 | * |
| 2010 | * Does all the checking to disambiguate |
| 2011 | * foo bar |
| 2012 | * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise |
| 2013 | * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args). |
| 2014 | * |
| 2015 | * First argument is the stuff after the first token, e.g. "bar". |
| 2016 | * |
| 2017 | * Not a method if bar is a filehandle. |
| 2018 | * Not a method if foo is a subroutine prototyped to take a filehandle. |
| 2019 | * Not a method if it's really "Foo $bar" |
| 2020 | * Method if it's "foo $bar" |
| 2021 | * Not a method if it's really "print foo $bar" |
| 2022 | * Method if it's really "foo package::" (interpreted as package->foo) |
| 2023 | * Not a method if bar is known to be a subroutine ("sub bar; foo bar") |
| 2024 | * Not a method if bar is a filehandle or package, but is quoted with |
| 2025 | * => |
| 2026 | */ |
| 2027 | |
| 2028 | STATIC int |
| 2029 | S_intuit_method(pTHX_ char *start, GV *gv) |
| 2030 | { |
| 2031 | char *s = start + (*start == '$'); |
| 2032 | char tmpbuf[sizeof PL_tokenbuf]; |
| 2033 | STRLEN len; |
| 2034 | GV* indirgv; |
| 2035 | |
| 2036 | if (gv) { |
| 2037 | CV *cv; |
| 2038 | if (GvIO(gv)) |
| 2039 | return 0; |
| 2040 | if ((cv = GvCVu(gv))) { |
| 2041 | char *proto = SvPVX(cv); |
| 2042 | if (proto) { |
| 2043 | if (*proto == ';') |
| 2044 | proto++; |
| 2045 | if (*proto == '*') |
| 2046 | return 0; |
| 2047 | } |
| 2048 | } else |
| 2049 | gv = 0; |
| 2050 | } |
| 2051 | s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
| 2052 | /* start is the beginning of the possible filehandle/object, |
| 2053 | * and s is the end of it |
| 2054 | * tmpbuf is a copy of it |
| 2055 | */ |
| 2056 | |
| 2057 | if (*start == '$') { |
| 2058 | if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf)) |
| 2059 | return 0; |
| 2060 | s = skipspace(s); |
| 2061 | PL_bufptr = start; |
| 2062 | PL_expect = XREF; |
| 2063 | return *s == '(' ? FUNCMETH : METHOD; |
| 2064 | } |
| 2065 | if (!keyword(tmpbuf, len)) { |
| 2066 | if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') { |
| 2067 | len -= 2; |
| 2068 | tmpbuf[len] = '\0'; |
| 2069 | goto bare_package; |
| 2070 | } |
| 2071 | indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV); |
| 2072 | if (indirgv && GvCVu(indirgv)) |
| 2073 | return 0; |
| 2074 | /* filehandle or package name makes it a method */ |
| 2075 | if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) { |
| 2076 | s = skipspace(s); |
| 2077 | if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>') |
| 2078 | return 0; /* no assumptions -- "=>" quotes bearword */ |
| 2079 | bare_package: |
| 2080 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, |
| 2081 | newSVpvn(tmpbuf,len)); |
| 2082 | PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE; |
| 2083 | PL_expect = XTERM; |
| 2084 | force_next(WORD); |
| 2085 | PL_bufptr = s; |
| 2086 | return *s == '(' ? FUNCMETH : METHOD; |
| 2087 | } |
| 2088 | } |
| 2089 | return 0; |
| 2090 | } |
| 2091 | |
| 2092 | /* |
| 2093 | * S_incl_perldb |
| 2094 | * Return a string of Perl code to load the debugger. If PERL5DB |
| 2095 | * is set, it will return the contents of that, otherwise a |
| 2096 | * compile-time require of perl5db.pl. |
| 2097 | */ |
| 2098 | |
| 2099 | STATIC const char* |
| 2100 | S_incl_perldb(pTHX) |
| 2101 | { |
| 2102 | if (PL_perldb) { |
| 2103 | const char *pdb = PerlEnv_getenv("PERL5DB"); |
| 2104 | |
| 2105 | if (pdb) |
| 2106 | return pdb; |
| 2107 | SETERRNO(0,SS_NORMAL); |
| 2108 | return "BEGIN { require 'perl5db.pl' }"; |
| 2109 | } |
| 2110 | return ""; |
| 2111 | } |
| 2112 | |
| 2113 | |
| 2114 | /* Encoded script support. filter_add() effectively inserts a |
| 2115 | * 'pre-processing' function into the current source input stream. |
| 2116 | * Note that the filter function only applies to the current source file |
| 2117 | * (e.g., it will not affect files 'require'd or 'use'd by this one). |
| 2118 | * |
| 2119 | * The datasv parameter (which may be NULL) can be used to pass |
| 2120 | * private data to this instance of the filter. The filter function |
| 2121 | * can recover the SV using the FILTER_DATA macro and use it to |
| 2122 | * store private buffers and state information. |
| 2123 | * |
| 2124 | * The supplied datasv parameter is upgraded to a PVIO type |
| 2125 | * and the IoDIRP/IoANY field is used to store the function pointer, |
| 2126 | * and IOf_FAKE_DIRP is enabled on datasv to mark this as such. |
| 2127 | * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for |
| 2128 | * private use must be set using malloc'd pointers. |
| 2129 | */ |
| 2130 | |
| 2131 | SV * |
| 2132 | Perl_filter_add(pTHX_ filter_t funcp, SV *datasv) |
| 2133 | { |
| 2134 | if (!funcp) |
| 2135 | return Nullsv; |
| 2136 | |
| 2137 | if (!PL_rsfp_filters) |
| 2138 | PL_rsfp_filters = newAV(); |
| 2139 | if (!datasv) |
| 2140 | datasv = NEWSV(255,0); |
| 2141 | if (!SvUPGRADE(datasv, SVt_PVIO)) |
| 2142 | Perl_die(aTHX_ "Can't upgrade filter_add data to SVt_PVIO"); |
| 2143 | IoANY(datasv) = (void *)funcp; /* stash funcp into spare field */ |
| 2144 | IoFLAGS(datasv) |= IOf_FAKE_DIRP; |
| 2145 | DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n", |
| 2146 | (void*)funcp, SvPV_nolen(datasv))); |
| 2147 | av_unshift(PL_rsfp_filters, 1); |
| 2148 | av_store(PL_rsfp_filters, 0, datasv) ; |
| 2149 | return(datasv); |
| 2150 | } |
| 2151 | |
| 2152 | |
| 2153 | /* Delete most recently added instance of this filter function. */ |
| 2154 | void |
| 2155 | Perl_filter_del(pTHX_ filter_t funcp) |
| 2156 | { |
| 2157 | SV *datasv; |
| 2158 | DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", (void*)funcp)); |
| 2159 | if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0) |
| 2160 | return; |
| 2161 | /* if filter is on top of stack (usual case) just pop it off */ |
| 2162 | datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters)); |
| 2163 | if (IoANY(datasv) == (void *)funcp) { |
| 2164 | IoFLAGS(datasv) &= ~IOf_FAKE_DIRP; |
| 2165 | IoANY(datasv) = (void *)NULL; |
| 2166 | sv_free(av_pop(PL_rsfp_filters)); |
| 2167 | |
| 2168 | return; |
| 2169 | } |
| 2170 | /* we need to search for the correct entry and clear it */ |
| 2171 | Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)"); |
| 2172 | } |
| 2173 | |
| 2174 | |
| 2175 | /* Invoke the idxth filter function for the current rsfp. */ |
| 2176 | /* maxlen 0 = read one text line */ |
| 2177 | I32 |
| 2178 | Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen) |
| 2179 | { |
| 2180 | filter_t funcp; |
| 2181 | SV *datasv = NULL; |
| 2182 | |
| 2183 | if (!PL_rsfp_filters) |
| 2184 | return -1; |
| 2185 | if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */ |
| 2186 | /* Provide a default input filter to make life easy. */ |
| 2187 | /* Note that we append to the line. This is handy. */ |
| 2188 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
| 2189 | "filter_read %d: from rsfp\n", idx)); |
| 2190 | if (maxlen) { |
| 2191 | /* Want a block */ |
| 2192 | int len ; |
| 2193 | int old_len = SvCUR(buf_sv) ; |
| 2194 | |
| 2195 | /* ensure buf_sv is large enough */ |
| 2196 | SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ; |
| 2197 | if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){ |
| 2198 | if (PerlIO_error(PL_rsfp)) |
| 2199 | return -1; /* error */ |
| 2200 | else |
| 2201 | return 0 ; /* end of file */ |
| 2202 | } |
| 2203 | SvCUR_set(buf_sv, old_len + len) ; |
| 2204 | } else { |
| 2205 | /* Want a line */ |
| 2206 | if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) { |
| 2207 | if (PerlIO_error(PL_rsfp)) |
| 2208 | return -1; /* error */ |
| 2209 | else |
| 2210 | return 0 ; /* end of file */ |
| 2211 | } |
| 2212 | } |
| 2213 | return SvCUR(buf_sv); |
| 2214 | } |
| 2215 | /* Skip this filter slot if filter has been deleted */ |
| 2216 | if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) { |
| 2217 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
| 2218 | "filter_read %d: skipped (filter deleted)\n", |
| 2219 | idx)); |
| 2220 | return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */ |
| 2221 | } |
| 2222 | /* Get function pointer hidden within datasv */ |
| 2223 | funcp = (filter_t)IoANY(datasv); |
| 2224 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
| 2225 | "filter_read %d: via function %p (%s)\n", |
| 2226 | idx, (void*)funcp, SvPV_nolen(datasv))); |
| 2227 | /* Call function. The function is expected to */ |
| 2228 | /* call "FILTER_READ(idx+1, buf_sv)" first. */ |
| 2229 | /* Return: <0:error, =0:eof, >0:not eof */ |
| 2230 | return (*funcp)(aTHX_ idx, buf_sv, maxlen); |
| 2231 | } |
| 2232 | |
| 2233 | STATIC char * |
| 2234 | S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append) |
| 2235 | { |
| 2236 | #ifdef PERL_CR_FILTER |
| 2237 | if (!PL_rsfp_filters) { |
| 2238 | filter_add(S_cr_textfilter,NULL); |
| 2239 | } |
| 2240 | #endif |
| 2241 | if (PL_rsfp_filters) { |
| 2242 | if (!append) |
| 2243 | SvCUR_set(sv, 0); /* start with empty line */ |
| 2244 | if (FILTER_READ(0, sv, 0) > 0) |
| 2245 | return ( SvPVX(sv) ) ; |
| 2246 | else |
| 2247 | return Nullch ; |
| 2248 | } |
| 2249 | else |
| 2250 | return (sv_gets(sv, fp, append)); |
| 2251 | } |
| 2252 | |
| 2253 | STATIC HV * |
| 2254 | S_find_in_my_stash(pTHX_ const char *pkgname, I32 len) |
| 2255 | { |
| 2256 | GV *gv; |
| 2257 | |
| 2258 | if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__")) |
| 2259 | return PL_curstash; |
| 2260 | |
| 2261 | if (len > 2 && |
| 2262 | (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') && |
| 2263 | (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV))) |
| 2264 | { |
| 2265 | return GvHV(gv); /* Foo:: */ |
| 2266 | } |
| 2267 | |
| 2268 | /* use constant CLASS => 'MyClass' */ |
| 2269 | if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) { |
| 2270 | SV *sv; |
| 2271 | if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) { |
| 2272 | pkgname = SvPV_nolen(sv); |
| 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | return gv_stashpv(pkgname, FALSE); |
| 2277 | } |
| 2278 | |
| 2279 | #ifdef DEBUGGING |
| 2280 | static const char* const exp_name[] = |
| 2281 | { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK", |
| 2282 | "ATTRTERM", "TERMBLOCK", "TERMORDORDOR" |
| 2283 | }; |
| 2284 | #endif |
| 2285 | |
| 2286 | /* |
| 2287 | yylex |
| 2288 | |
| 2289 | Works out what to call the token just pulled out of the input |
| 2290 | stream. The yacc parser takes care of taking the ops we return and |
| 2291 | stitching them into a tree. |
| 2292 | |
| 2293 | Returns: |
| 2294 | PRIVATEREF |
| 2295 | |
| 2296 | Structure: |
| 2297 | if read an identifier |
| 2298 | if we're in a my declaration |
| 2299 | croak if they tried to say my($foo::bar) |
| 2300 | build the ops for a my() declaration |
| 2301 | if it's an access to a my() variable |
| 2302 | are we in a sort block? |
| 2303 | croak if my($a); $a <=> $b |
| 2304 | build ops for access to a my() variable |
| 2305 | if in a dq string, and they've said @foo and we can't find @foo |
| 2306 | croak |
| 2307 | build ops for a bareword |
| 2308 | if we already built the token before, use it. |
| 2309 | */ |
| 2310 | |
| 2311 | |
| 2312 | #ifdef __SC__ |
| 2313 | #pragma segment Perl_yylex |
| 2314 | #endif |
| 2315 | int |
| 2316 | Perl_yylex(pTHX) |
| 2317 | { |
| 2318 | register char *s = PL_bufptr; |
| 2319 | register char *d; |
| 2320 | register I32 tmp; |
| 2321 | STRLEN len; |
| 2322 | GV *gv = Nullgv; |
| 2323 | GV **gvp = 0; |
| 2324 | bool bof = FALSE; |
| 2325 | I32 orig_keyword = 0; |
| 2326 | |
| 2327 | DEBUG_T( { |
| 2328 | PerlIO_printf(Perl_debug_log, "### LEX_%s\n", |
| 2329 | lex_state_names[PL_lex_state]); |
| 2330 | } ); |
| 2331 | /* check if there's an identifier for us to look at */ |
| 2332 | if (PL_pending_ident) |
| 2333 | return REPORT(S_pending_ident(aTHX)); |
| 2334 | |
| 2335 | /* no identifier pending identification */ |
| 2336 | |
| 2337 | switch (PL_lex_state) { |
| 2338 | #ifdef COMMENTARY |
| 2339 | case LEX_NORMAL: /* Some compilers will produce faster */ |
| 2340 | case LEX_INTERPNORMAL: /* code if we comment these out. */ |
| 2341 | break; |
| 2342 | #endif |
| 2343 | |
| 2344 | /* when we've already built the next token, just pull it out of the queue */ |
| 2345 | case LEX_KNOWNEXT: |
| 2346 | PL_nexttoke--; |
| 2347 | yylval = PL_nextval[PL_nexttoke]; |
| 2348 | if (!PL_nexttoke) { |
| 2349 | PL_lex_state = PL_lex_defer; |
| 2350 | PL_expect = PL_lex_expect; |
| 2351 | PL_lex_defer = LEX_NORMAL; |
| 2352 | } |
| 2353 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
| 2354 | "### Next token after '%s' was known, type %"IVdf"\n", PL_bufptr, |
| 2355 | (IV)PL_nexttype[PL_nexttoke]); }); |
| 2356 | |
| 2357 | return REPORT(PL_nexttype[PL_nexttoke]); |
| 2358 | |
| 2359 | /* interpolated case modifiers like \L \U, including \Q and \E. |
| 2360 | when we get here, PL_bufptr is at the \ |
| 2361 | */ |
| 2362 | case LEX_INTERPCASEMOD: |
| 2363 | #ifdef DEBUGGING |
| 2364 | if (PL_bufptr != PL_bufend && *PL_bufptr != '\\') |
| 2365 | Perl_croak(aTHX_ "panic: INTERPCASEMOD"); |
| 2366 | #endif |
| 2367 | /* handle \E or end of string */ |
| 2368 | if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') { |
| 2369 | char oldmod; |
| 2370 | |
| 2371 | /* if at a \E */ |
| 2372 | if (PL_lex_casemods) { |
| 2373 | oldmod = PL_lex_casestack[--PL_lex_casemods]; |
| 2374 | PL_lex_casestack[PL_lex_casemods] = '\0'; |
| 2375 | |
| 2376 | if (PL_bufptr != PL_bufend |
| 2377 | && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) { |
| 2378 | PL_bufptr += 2; |
| 2379 | PL_lex_state = LEX_INTERPCONCAT; |
| 2380 | } |
| 2381 | return REPORT(')'); |
| 2382 | } |
| 2383 | if (PL_bufptr != PL_bufend) |
| 2384 | PL_bufptr += 2; |
| 2385 | PL_lex_state = LEX_INTERPCONCAT; |
| 2386 | return yylex(); |
| 2387 | } |
| 2388 | else { |
| 2389 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
| 2390 | "### Saw case modifier at '%s'\n", PL_bufptr); }); |
| 2391 | s = PL_bufptr + 1; |
| 2392 | if (s[1] == '\\' && s[2] == 'E') { |
| 2393 | PL_bufptr = s + 3; |
| 2394 | PL_lex_state = LEX_INTERPCONCAT; |
| 2395 | return yylex(); |
| 2396 | } |
| 2397 | else { |
| 2398 | if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3)) |
| 2399 | tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */ |
| 2400 | if ((*s == 'L' || *s == 'U') && |
| 2401 | (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) { |
| 2402 | PL_lex_casestack[--PL_lex_casemods] = '\0'; |
| 2403 | return REPORT(')'); |
| 2404 | } |
| 2405 | if (PL_lex_casemods > 10) |
| 2406 | Renew(PL_lex_casestack, PL_lex_casemods + 2, char); |
| 2407 | PL_lex_casestack[PL_lex_casemods++] = *s; |
| 2408 | PL_lex_casestack[PL_lex_casemods] = '\0'; |
| 2409 | PL_lex_state = LEX_INTERPCONCAT; |
| 2410 | PL_nextval[PL_nexttoke].ival = 0; |
| 2411 | force_next('('); |
| 2412 | if (*s == 'l') |
| 2413 | PL_nextval[PL_nexttoke].ival = OP_LCFIRST; |
| 2414 | else if (*s == 'u') |
| 2415 | PL_nextval[PL_nexttoke].ival = OP_UCFIRST; |
| 2416 | else if (*s == 'L') |
| 2417 | PL_nextval[PL_nexttoke].ival = OP_LC; |
| 2418 | else if (*s == 'U') |
| 2419 | PL_nextval[PL_nexttoke].ival = OP_UC; |
| 2420 | else if (*s == 'Q') |
| 2421 | PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA; |
| 2422 | else |
| 2423 | Perl_croak(aTHX_ "panic: yylex"); |
| 2424 | PL_bufptr = s + 1; |
| 2425 | } |
| 2426 | force_next(FUNC); |
| 2427 | if (PL_lex_starts) { |
| 2428 | s = PL_bufptr; |
| 2429 | PL_lex_starts = 0; |
| 2430 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ |
| 2431 | if (PL_lex_casemods == 1 && PL_lex_inpat) |
| 2432 | OPERATOR(','); |
| 2433 | else |
| 2434 | Aop(OP_CONCAT); |
| 2435 | } |
| 2436 | else |
| 2437 | return yylex(); |
| 2438 | } |
| 2439 | |
| 2440 | case LEX_INTERPPUSH: |
| 2441 | return REPORT(sublex_push()); |
| 2442 | |
| 2443 | case LEX_INTERPSTART: |
| 2444 | if (PL_bufptr == PL_bufend) |
| 2445 | return REPORT(sublex_done()); |
| 2446 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
| 2447 | "### Interpolated variable at '%s'\n", PL_bufptr); }); |
| 2448 | PL_expect = XTERM; |
| 2449 | PL_lex_dojoin = (*PL_bufptr == '@'); |
| 2450 | PL_lex_state = LEX_INTERPNORMAL; |
| 2451 | if (PL_lex_dojoin) { |
| 2452 | PL_nextval[PL_nexttoke].ival = 0; |
| 2453 | force_next(','); |
| 2454 | force_ident("\"", '$'); |
| 2455 | PL_nextval[PL_nexttoke].ival = 0; |
| 2456 | force_next('$'); |
| 2457 | PL_nextval[PL_nexttoke].ival = 0; |
| 2458 | force_next('('); |
| 2459 | PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */ |
| 2460 | force_next(FUNC); |
| 2461 | } |
| 2462 | if (PL_lex_starts++) { |
| 2463 | s = PL_bufptr; |
| 2464 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ |
| 2465 | if (!PL_lex_casemods && PL_lex_inpat) |
| 2466 | OPERATOR(','); |
| 2467 | else |
| 2468 | Aop(OP_CONCAT); |
| 2469 | } |
| 2470 | return yylex(); |
| 2471 | |
| 2472 | case LEX_INTERPENDMAYBE: |
| 2473 | if (intuit_more(PL_bufptr)) { |
| 2474 | PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */ |
| 2475 | break; |
| 2476 | } |
| 2477 | /* FALL THROUGH */ |
| 2478 | |
| 2479 | case LEX_INTERPEND: |
| 2480 | if (PL_lex_dojoin) { |
| 2481 | PL_lex_dojoin = FALSE; |
| 2482 | PL_lex_state = LEX_INTERPCONCAT; |
| 2483 | return REPORT(')'); |
| 2484 | } |
| 2485 | if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl |
| 2486 | && SvEVALED(PL_lex_repl)) |
| 2487 | { |
| 2488 | if (PL_bufptr != PL_bufend) |
| 2489 | Perl_croak(aTHX_ "Bad evalled substitution pattern"); |
| 2490 | PL_lex_repl = Nullsv; |
| 2491 | } |
| 2492 | /* FALLTHROUGH */ |
| 2493 | case LEX_INTERPCONCAT: |
| 2494 | #ifdef DEBUGGING |
| 2495 | if (PL_lex_brackets) |
| 2496 | Perl_croak(aTHX_ "panic: INTERPCONCAT"); |
| 2497 | #endif |
| 2498 | if (PL_bufptr == PL_bufend) |
| 2499 | return REPORT(sublex_done()); |
| 2500 | |
| 2501 | if (SvIVX(PL_linestr) == '\'') { |
| 2502 | SV *sv = newSVsv(PL_linestr); |
| 2503 | if (!PL_lex_inpat) |
| 2504 | sv = tokeq(sv); |
| 2505 | else if ( PL_hints & HINT_NEW_RE ) |
| 2506 | sv = new_constant(NULL, 0, "qr", sv, sv, "q"); |
| 2507 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
| 2508 | s = PL_bufend; |
| 2509 | } |
| 2510 | else { |
| 2511 | s = scan_const(PL_bufptr); |
| 2512 | if (*s == '\\') |
| 2513 | PL_lex_state = LEX_INTERPCASEMOD; |
| 2514 | else |
| 2515 | PL_lex_state = LEX_INTERPSTART; |
| 2516 | } |
| 2517 | |
| 2518 | if (s != PL_bufptr) { |
| 2519 | PL_nextval[PL_nexttoke] = yylval; |
| 2520 | PL_expect = XTERM; |
| 2521 | force_next(THING); |
| 2522 | if (PL_lex_starts++) { |
| 2523 | /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */ |
| 2524 | if (!PL_lex_casemods && PL_lex_inpat) |
| 2525 | OPERATOR(','); |
| 2526 | else |
| 2527 | Aop(OP_CONCAT); |
| 2528 | } |
| 2529 | else { |
| 2530 | PL_bufptr = s; |
| 2531 | return yylex(); |
| 2532 | } |
| 2533 | } |
| 2534 | |
| 2535 | return yylex(); |
| 2536 | case LEX_FORMLINE: |
| 2537 | PL_lex_state = LEX_NORMAL; |
| 2538 | s = scan_formline(PL_bufptr); |
| 2539 | if (!PL_lex_formbrack) |
| 2540 | goto rightbracket; |
| 2541 | OPERATOR(';'); |
| 2542 | } |
| 2543 | |
| 2544 | s = PL_bufptr; |
| 2545 | PL_oldoldbufptr = PL_oldbufptr; |
| 2546 | PL_oldbufptr = s; |
| 2547 | DEBUG_T( { |
| 2548 | PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at [%s]\n", |
| 2549 | exp_name[PL_expect], s); |
| 2550 | } ); |
| 2551 | |
| 2552 | retry: |
| 2553 | switch (*s) { |
| 2554 | default: |
| 2555 | if (isIDFIRST_lazy_if(s,UTF)) |
| 2556 | goto keylookup; |
| 2557 | Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255); |
| 2558 | case 4: |
| 2559 | case 26: |
| 2560 | goto fake_eof; /* emulate EOF on ^D or ^Z */ |
| 2561 | case 0: |
| 2562 | if (!PL_rsfp) { |
| 2563 | PL_last_uni = 0; |
| 2564 | PL_last_lop = 0; |
| 2565 | if (PL_lex_brackets) { |
| 2566 | if (PL_lex_formbrack) |
| 2567 | yyerror("Format not terminated"); |
| 2568 | else |
| 2569 | yyerror("Missing right curly or square bracket"); |
| 2570 | } |
| 2571 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
| 2572 | "### Tokener got EOF\n"); |
| 2573 | } ); |
| 2574 | TOKEN(0); |
| 2575 | } |
| 2576 | if (s++ < PL_bufend) |
| 2577 | goto retry; /* ignore stray nulls */ |
| 2578 | PL_last_uni = 0; |
| 2579 | PL_last_lop = 0; |
| 2580 | if (!PL_in_eval && !PL_preambled) { |
| 2581 | PL_preambled = TRUE; |
| 2582 | sv_setpv(PL_linestr,incl_perldb()); |
| 2583 | if (SvCUR(PL_linestr)) |
| 2584 | sv_catpvn(PL_linestr,";", 1); |
| 2585 | if (PL_preambleav){ |
| 2586 | while(AvFILLp(PL_preambleav) >= 0) { |
| 2587 | SV *tmpsv = av_shift(PL_preambleav); |
| 2588 | sv_catsv(PL_linestr, tmpsv); |
| 2589 | sv_catpvn(PL_linestr, ";", 1); |
| 2590 | sv_free(tmpsv); |
| 2591 | } |
| 2592 | sv_free((SV*)PL_preambleav); |
| 2593 | PL_preambleav = NULL; |
| 2594 | } |
| 2595 | if (PL_minus_n || PL_minus_p) { |
| 2596 | sv_catpv(PL_linestr, "LINE: while (<>) {"); |
| 2597 | if (PL_minus_l) |
| 2598 | sv_catpv(PL_linestr,"chomp;"); |
| 2599 | if (PL_minus_a) { |
| 2600 | if (PL_minus_F) { |
| 2601 | if ((*PL_splitstr == '/' || *PL_splitstr == '\'' |
| 2602 | || *PL_splitstr == '"') |
| 2603 | && strchr(PL_splitstr + 1, *PL_splitstr)) |
| 2604 | Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr); |
| 2605 | else { |
| 2606 | /* "q\0${splitstr}\0" is legal perl. Yes, even NUL |
| 2607 | bytes can be used as quoting characters. :-) */ |
| 2608 | /* The count here deliberately includes the NUL |
| 2609 | that terminates the C string constant. This |
| 2610 | embeds the opening NUL into the string. */ |
| 2611 | const char *splits = PL_splitstr; |
| 2612 | sv_catpvn(PL_linestr, "our @F=split(q", 15); |
| 2613 | do { |
| 2614 | /* Need to \ \s */ |
| 2615 | if (*splits == '\\') |
| 2616 | sv_catpvn(PL_linestr, splits, 1); |
| 2617 | sv_catpvn(PL_linestr, splits, 1); |
| 2618 | } while (*splits++); |
| 2619 | /* This loop will embed the trailing NUL of |
| 2620 | PL_linestr as the last thing it does before |
| 2621 | terminating. */ |
| 2622 | sv_catpvn(PL_linestr, ");", 2); |
| 2623 | } |
| 2624 | } |
| 2625 | else |
| 2626 | sv_catpv(PL_linestr,"our @F=split(' ');"); |
| 2627 | } |
| 2628 | } |
| 2629 | sv_catpvn(PL_linestr, "\n", 1); |
| 2630 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
| 2631 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 2632 | PL_last_lop = PL_last_uni = Nullch; |
| 2633 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
| 2634 | SV *sv = NEWSV(85,0); |
| 2635 | |
| 2636 | sv_upgrade(sv, SVt_PVMG); |
| 2637 | sv_setsv(sv,PL_linestr); |
| 2638 | (void)SvIOK_on(sv); |
| 2639 | SvIV_set(sv, 0); |
| 2640 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
| 2641 | } |
| 2642 | goto retry; |
| 2643 | } |
| 2644 | do { |
| 2645 | bof = PL_rsfp ? TRUE : FALSE; |
| 2646 | if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) { |
| 2647 | fake_eof: |
| 2648 | if (PL_rsfp) { |
| 2649 | if (PL_preprocess && !PL_in_eval) |
| 2650 | (void)PerlProc_pclose(PL_rsfp); |
| 2651 | else if ((PerlIO *)PL_rsfp == PerlIO_stdin()) |
| 2652 | PerlIO_clearerr(PL_rsfp); |
| 2653 | else |
| 2654 | (void)PerlIO_close(PL_rsfp); |
| 2655 | PL_rsfp = Nullfp; |
| 2656 | PL_doextract = FALSE; |
| 2657 | } |
| 2658 | if (!PL_in_eval && (PL_minus_n || PL_minus_p)) { |
| 2659 | sv_setpv(PL_linestr,PL_minus_p |
| 2660 | ? ";}continue{print;}" : ";}"); |
| 2661 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
| 2662 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 2663 | PL_last_lop = PL_last_uni = Nullch; |
| 2664 | PL_minus_n = PL_minus_p = 0; |
| 2665 | goto retry; |
| 2666 | } |
| 2667 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
| 2668 | PL_last_lop = PL_last_uni = Nullch; |
| 2669 | sv_setpv(PL_linestr,""); |
| 2670 | TOKEN(';'); /* not infinite loop because rsfp is NULL now */ |
| 2671 | } |
| 2672 | /* If it looks like the start of a BOM or raw UTF-16, |
| 2673 | * check if it in fact is. */ |
| 2674 | else if (bof && |
| 2675 | (*s == 0 || |
| 2676 | *(U8*)s == 0xEF || |
| 2677 | *(U8*)s >= 0xFE || |
| 2678 | s[1] == 0)) { |
| 2679 | #ifdef PERLIO_IS_STDIO |
| 2680 | # ifdef __GNU_LIBRARY__ |
| 2681 | # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */ |
| 2682 | # define FTELL_FOR_PIPE_IS_BROKEN |
| 2683 | # endif |
| 2684 | # else |
| 2685 | # ifdef __GLIBC__ |
| 2686 | # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */ |
| 2687 | # define FTELL_FOR_PIPE_IS_BROKEN |
| 2688 | # endif |
| 2689 | # endif |
| 2690 | # endif |
| 2691 | #endif |
| 2692 | #ifdef FTELL_FOR_PIPE_IS_BROKEN |
| 2693 | /* This loses the possibility to detect the bof |
| 2694 | * situation on perl -P when the libc5 is being used. |
| 2695 | * Workaround? Maybe attach some extra state to PL_rsfp? |
| 2696 | */ |
| 2697 | if (!PL_preprocess) |
| 2698 | bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr); |
| 2699 | #else |
| 2700 | bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr); |
| 2701 | #endif |
| 2702 | if (bof) { |
| 2703 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 2704 | s = swallow_bom((U8*)s); |
| 2705 | } |
| 2706 | } |
| 2707 | if (PL_doextract) { |
| 2708 | /* Incest with pod. */ |
| 2709 | if (*s == '=' && strnEQ(s, "=cut", 4)) { |
| 2710 | sv_setpv(PL_linestr, ""); |
| 2711 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
| 2712 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 2713 | PL_last_lop = PL_last_uni = Nullch; |
| 2714 | PL_doextract = FALSE; |
| 2715 | } |
| 2716 | } |
| 2717 | incline(s); |
| 2718 | } while (PL_doextract); |
| 2719 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s; |
| 2720 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
| 2721 | SV *sv = NEWSV(85,0); |
| 2722 | |
| 2723 | sv_upgrade(sv, SVt_PVMG); |
| 2724 | sv_setsv(sv,PL_linestr); |
| 2725 | (void)SvIOK_on(sv); |
| 2726 | SvIV_set(sv, 0); |
| 2727 | av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv); |
| 2728 | } |
| 2729 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 2730 | PL_last_lop = PL_last_uni = Nullch; |
| 2731 | if (CopLINE(PL_curcop) == 1) { |
| 2732 | while (s < PL_bufend && isSPACE(*s)) |
| 2733 | s++; |
| 2734 | if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */ |
| 2735 | s++; |
| 2736 | d = Nullch; |
| 2737 | if (!PL_in_eval) { |
| 2738 | if (*s == '#' && *(s+1) == '!') |
| 2739 | d = s + 2; |
| 2740 | #ifdef ALTERNATE_SHEBANG |
| 2741 | else { |
| 2742 | static char const as[] = ALTERNATE_SHEBANG; |
| 2743 | if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1)) |
| 2744 | d = s + (sizeof(as) - 1); |
| 2745 | } |
| 2746 | #endif /* ALTERNATE_SHEBANG */ |
| 2747 | } |
| 2748 | if (d) { |
| 2749 | char *ipath; |
| 2750 | char *ipathend; |
| 2751 | |
| 2752 | while (isSPACE(*d)) |
| 2753 | d++; |
| 2754 | ipath = d; |
| 2755 | while (*d && !isSPACE(*d)) |
| 2756 | d++; |
| 2757 | ipathend = d; |
| 2758 | |
| 2759 | #ifdef ARG_ZERO_IS_SCRIPT |
| 2760 | if (ipathend > ipath) { |
| 2761 | /* |
| 2762 | * HP-UX (at least) sets argv[0] to the script name, |
| 2763 | * which makes $^X incorrect. And Digital UNIX and Linux, |
| 2764 | * at least, set argv[0] to the basename of the Perl |
| 2765 | * interpreter. So, having found "#!", we'll set it right. |
| 2766 | */ |
| 2767 | SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV)); /* $^X */ |
| 2768 | assert(SvPOK(x) || SvGMAGICAL(x)); |
| 2769 | if (sv_eq(x, CopFILESV(PL_curcop))) { |
| 2770 | sv_setpvn(x, ipath, ipathend - ipath); |
| 2771 | SvSETMAGIC(x); |
| 2772 | } |
| 2773 | else { |
| 2774 | STRLEN blen; |
| 2775 | STRLEN llen; |
| 2776 | char *bstart = SvPV(CopFILESV(PL_curcop),blen); |
| 2777 | char *lstart = SvPV(x,llen); |
| 2778 | if (llen < blen) { |
| 2779 | bstart += blen - llen; |
| 2780 | if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') { |
| 2781 | sv_setpvn(x, ipath, ipathend - ipath); |
| 2782 | SvSETMAGIC(x); |
| 2783 | } |
| 2784 | } |
| 2785 | } |
| 2786 | TAINT_NOT; /* $^X is always tainted, but that's OK */ |
| 2787 | } |
| 2788 | #endif /* ARG_ZERO_IS_SCRIPT */ |
| 2789 | |
| 2790 | /* |
| 2791 | * Look for options. |
| 2792 | */ |
| 2793 | d = instr(s,"perl -"); |
| 2794 | if (!d) { |
| 2795 | d = instr(s,"perl"); |
| 2796 | #if defined(DOSISH) |
| 2797 | /* avoid getting into infinite loops when shebang |
| 2798 | * line contains "Perl" rather than "perl" */ |
| 2799 | if (!d) { |
| 2800 | for (d = ipathend-4; d >= ipath; --d) { |
| 2801 | if ((*d == 'p' || *d == 'P') |
| 2802 | && !ibcmp(d, "perl", 4)) |
| 2803 | { |
| 2804 | break; |
| 2805 | } |
| 2806 | } |
| 2807 | if (d < ipath) |
| 2808 | d = Nullch; |
| 2809 | } |
| 2810 | #endif |
| 2811 | } |
| 2812 | #ifdef ALTERNATE_SHEBANG |
| 2813 | /* |
| 2814 | * If the ALTERNATE_SHEBANG on this system starts with a |
| 2815 | * character that can be part of a Perl expression, then if |
| 2816 | * we see it but not "perl", we're probably looking at the |
| 2817 | * start of Perl code, not a request to hand off to some |
| 2818 | * other interpreter. Similarly, if "perl" is there, but |
| 2819 | * not in the first 'word' of the line, we assume the line |
| 2820 | * contains the start of the Perl program. |
| 2821 | */ |
| 2822 | if (d && *s != '#') { |
| 2823 | char *c = ipath; |
| 2824 | while (*c && !strchr("; \t\r\n\f\v#", *c)) |
| 2825 | c++; |
| 2826 | if (c < d) |
| 2827 | d = Nullch; /* "perl" not in first word; ignore */ |
| 2828 | else |
| 2829 | *s = '#'; /* Don't try to parse shebang line */ |
| 2830 | } |
| 2831 | #endif /* ALTERNATE_SHEBANG */ |
| 2832 | #ifndef MACOS_TRADITIONAL |
| 2833 | if (!d && |
| 2834 | *s == '#' && |
| 2835 | ipathend > ipath && |
| 2836 | !PL_minus_c && |
| 2837 | !instr(s,"indir") && |
| 2838 | instr(PL_origargv[0],"perl")) |
| 2839 | { |
| 2840 | dVAR; |
| 2841 | char **newargv; |
| 2842 | |
| 2843 | *ipathend = '\0'; |
| 2844 | s = ipathend + 1; |
| 2845 | while (s < PL_bufend && isSPACE(*s)) |
| 2846 | s++; |
| 2847 | if (s < PL_bufend) { |
| 2848 | Newz(899,newargv,PL_origargc+3,char*); |
| 2849 | newargv[1] = s; |
| 2850 | while (s < PL_bufend && !isSPACE(*s)) |
| 2851 | s++; |
| 2852 | *s = '\0'; |
| 2853 | Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*); |
| 2854 | } |
| 2855 | else |
| 2856 | newargv = PL_origargv; |
| 2857 | newargv[0] = ipath; |
| 2858 | PERL_FPU_PRE_EXEC |
| 2859 | PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv)); |
| 2860 | PERL_FPU_POST_EXEC |
| 2861 | Perl_croak(aTHX_ "Can't exec %s", ipath); |
| 2862 | } |
| 2863 | #endif |
| 2864 | if (d) { |
| 2865 | U32 oldpdb = PL_perldb; |
| 2866 | bool oldn = PL_minus_n; |
| 2867 | bool oldp = PL_minus_p; |
| 2868 | |
| 2869 | while (*d && !isSPACE(*d)) d++; |
| 2870 | while (SPACE_OR_TAB(*d)) d++; |
| 2871 | |
| 2872 | if (*d++ == '-') { |
| 2873 | bool switches_done = PL_doswitches; |
| 2874 | do { |
| 2875 | if (*d == 'M' || *d == 'm' || *d == 'C') { |
| 2876 | char *m = d; |
| 2877 | while (*d && !isSPACE(*d)) d++; |
| 2878 | Perl_croak(aTHX_ "Too late for \"-%.*s\" option", |
| 2879 | (int)(d - m), m); |
| 2880 | } |
| 2881 | d = moreswitches(d); |
| 2882 | } while (d); |
| 2883 | if (PL_doswitches && !switches_done) { |
| 2884 | int argc = PL_origargc; |
| 2885 | char **argv = PL_origargv; |
| 2886 | do { |
| 2887 | argc--,argv++; |
| 2888 | } while (argc && argv[0][0] == '-' && argv[0][1]); |
| 2889 | init_argv_symbols(argc,argv); |
| 2890 | } |
| 2891 | if ((PERLDB_LINE && !oldpdb) || |
| 2892 | ((PL_minus_n || PL_minus_p) && !(oldn || oldp))) |
| 2893 | /* if we have already added "LINE: while (<>) {", |
| 2894 | we must not do it again */ |
| 2895 | { |
| 2896 | sv_setpv(PL_linestr, ""); |
| 2897 | PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr); |
| 2898 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 2899 | PL_last_lop = PL_last_uni = Nullch; |
| 2900 | PL_preambled = FALSE; |
| 2901 | if (PERLDB_LINE) |
| 2902 | (void)gv_fetchfile(PL_origfilename); |
| 2903 | goto retry; |
| 2904 | } |
| 2905 | if (PL_doswitches && !switches_done) { |
| 2906 | int argc = PL_origargc; |
| 2907 | char **argv = PL_origargv; |
| 2908 | do { |
| 2909 | argc--,argv++; |
| 2910 | } while (argc && argv[0][0] == '-' && argv[0][1]); |
| 2911 | init_argv_symbols(argc,argv); |
| 2912 | } |
| 2913 | } |
| 2914 | } |
| 2915 | } |
| 2916 | } |
| 2917 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
| 2918 | PL_bufptr = s; |
| 2919 | PL_lex_state = LEX_FORMLINE; |
| 2920 | return yylex(); |
| 2921 | } |
| 2922 | goto retry; |
| 2923 | case '\r': |
| 2924 | #ifdef PERL_STRICT_CR |
| 2925 | Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r'); |
| 2926 | Perl_croak(aTHX_ |
| 2927 | "\t(Maybe you didn't strip carriage returns after a network transfer?)\n"); |
| 2928 | #endif |
| 2929 | case ' ': case '\t': case '\f': case 013: |
| 2930 | #ifdef MACOS_TRADITIONAL |
| 2931 | case '\312': |
| 2932 | #endif |
| 2933 | s++; |
| 2934 | goto retry; |
| 2935 | case '#': |
| 2936 | case '\n': |
| 2937 | if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) { |
| 2938 | if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) { |
| 2939 | /* handle eval qq[#line 1 "foo"\n ...] */ |
| 2940 | CopLINE_dec(PL_curcop); |
| 2941 | incline(s); |
| 2942 | } |
| 2943 | d = PL_bufend; |
| 2944 | while (s < d && *s != '\n') |
| 2945 | s++; |
| 2946 | if (s < d) |
| 2947 | s++; |
| 2948 | else if (s > d) /* Found by Ilya: feed random input to Perl. */ |
| 2949 | Perl_croak(aTHX_ "panic: input overflow"); |
| 2950 | incline(s); |
| 2951 | if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) { |
| 2952 | PL_bufptr = s; |
| 2953 | PL_lex_state = LEX_FORMLINE; |
| 2954 | return yylex(); |
| 2955 | } |
| 2956 | } |
| 2957 | else { |
| 2958 | *s = '\0'; |
| 2959 | PL_bufend = s; |
| 2960 | } |
| 2961 | goto retry; |
| 2962 | case '-': |
| 2963 | if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) { |
| 2964 | I32 ftst = 0; |
| 2965 | |
| 2966 | s++; |
| 2967 | PL_bufptr = s; |
| 2968 | tmp = *s++; |
| 2969 | |
| 2970 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
| 2971 | s++; |
| 2972 | |
| 2973 | if (strnEQ(s,"=>",2)) { |
| 2974 | s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE); |
| 2975 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
| 2976 | "### Saw unary minus before =>, forcing word '%s'\n", s); |
| 2977 | } ); |
| 2978 | OPERATOR('-'); /* unary minus */ |
| 2979 | } |
| 2980 | PL_last_uni = PL_oldbufptr; |
| 2981 | switch (tmp) { |
| 2982 | case 'r': ftst = OP_FTEREAD; break; |
| 2983 | case 'w': ftst = OP_FTEWRITE; break; |
| 2984 | case 'x': ftst = OP_FTEEXEC; break; |
| 2985 | case 'o': ftst = OP_FTEOWNED; break; |
| 2986 | case 'R': ftst = OP_FTRREAD; break; |
| 2987 | case 'W': ftst = OP_FTRWRITE; break; |
| 2988 | case 'X': ftst = OP_FTREXEC; break; |
| 2989 | case 'O': ftst = OP_FTROWNED; break; |
| 2990 | case 'e': ftst = OP_FTIS; break; |
| 2991 | case 'z': ftst = OP_FTZERO; break; |
| 2992 | case 's': ftst = OP_FTSIZE; break; |
| 2993 | case 'f': ftst = OP_FTFILE; break; |
| 2994 | case 'd': ftst = OP_FTDIR; break; |
| 2995 | case 'l': ftst = OP_FTLINK; break; |
| 2996 | case 'p': ftst = OP_FTPIPE; break; |
| 2997 | case 'S': ftst = OP_FTSOCK; break; |
| 2998 | case 'u': ftst = OP_FTSUID; break; |
| 2999 | case 'g': ftst = OP_FTSGID; break; |
| 3000 | case 'k': ftst = OP_FTSVTX; break; |
| 3001 | case 'b': ftst = OP_FTBLK; break; |
| 3002 | case 'c': ftst = OP_FTCHR; break; |
| 3003 | case 't': ftst = OP_FTTTY; break; |
| 3004 | case 'T': ftst = OP_FTTEXT; break; |
| 3005 | case 'B': ftst = OP_FTBINARY; break; |
| 3006 | case 'M': case 'A': case 'C': |
| 3007 | gv_fetchpv("\024",TRUE, SVt_PV); |
| 3008 | switch (tmp) { |
| 3009 | case 'M': ftst = OP_FTMTIME; break; |
| 3010 | case 'A': ftst = OP_FTATIME; break; |
| 3011 | case 'C': ftst = OP_FTCTIME; break; |
| 3012 | default: break; |
| 3013 | } |
| 3014 | break; |
| 3015 | default: |
| 3016 | break; |
| 3017 | } |
| 3018 | if (ftst) { |
| 3019 | PL_last_lop_op = (OPCODE)ftst; |
| 3020 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
| 3021 | "### Saw file test %c\n", (int)ftst); |
| 3022 | } ); |
| 3023 | FTST(ftst); |
| 3024 | } |
| 3025 | else { |
| 3026 | /* Assume it was a minus followed by a one-letter named |
| 3027 | * subroutine call (or a -bareword), then. */ |
| 3028 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
| 3029 | "### '-%c' looked like a file test but was not\n", |
| 3030 | (int) tmp); |
| 3031 | } ); |
| 3032 | s = --PL_bufptr; |
| 3033 | } |
| 3034 | } |
| 3035 | tmp = *s++; |
| 3036 | if (*s == tmp) { |
| 3037 | s++; |
| 3038 | if (PL_expect == XOPERATOR) |
| 3039 | TERM(POSTDEC); |
| 3040 | else |
| 3041 | OPERATOR(PREDEC); |
| 3042 | } |
| 3043 | else if (*s == '>') { |
| 3044 | s++; |
| 3045 | s = skipspace(s); |
| 3046 | if (isIDFIRST_lazy_if(s,UTF)) { |
| 3047 | s = force_word(s,METHOD,FALSE,TRUE,FALSE); |
| 3048 | TOKEN(ARROW); |
| 3049 | } |
| 3050 | else if (*s == '$') |
| 3051 | OPERATOR(ARROW); |
| 3052 | else |
| 3053 | TERM(ARROW); |
| 3054 | } |
| 3055 | if (PL_expect == XOPERATOR) |
| 3056 | Aop(OP_SUBTRACT); |
| 3057 | else { |
| 3058 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) |
| 3059 | check_uni(); |
| 3060 | OPERATOR('-'); /* unary minus */ |
| 3061 | } |
| 3062 | |
| 3063 | case '+': |
| 3064 | tmp = *s++; |
| 3065 | if (*s == tmp) { |
| 3066 | s++; |
| 3067 | if (PL_expect == XOPERATOR) |
| 3068 | TERM(POSTINC); |
| 3069 | else |
| 3070 | OPERATOR(PREINC); |
| 3071 | } |
| 3072 | if (PL_expect == XOPERATOR) |
| 3073 | Aop(OP_ADD); |
| 3074 | else { |
| 3075 | if (isSPACE(*s) || !isSPACE(*PL_bufptr)) |
| 3076 | check_uni(); |
| 3077 | OPERATOR('+'); |
| 3078 | } |
| 3079 | |
| 3080 | case '*': |
| 3081 | if (PL_expect != XOPERATOR) { |
| 3082 | s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); |
| 3083 | PL_expect = XOPERATOR; |
| 3084 | force_ident(PL_tokenbuf, '*'); |
| 3085 | if (!*PL_tokenbuf) |
| 3086 | PREREF('*'); |
| 3087 | TERM('*'); |
| 3088 | } |
| 3089 | s++; |
| 3090 | if (*s == '*') { |
| 3091 | s++; |
| 3092 | PWop(OP_POW); |
| 3093 | } |
| 3094 | Mop(OP_MULTIPLY); |
| 3095 | |
| 3096 | case '%': |
| 3097 | if (PL_expect == XOPERATOR) { |
| 3098 | ++s; |
| 3099 | Mop(OP_MODULO); |
| 3100 | } |
| 3101 | PL_tokenbuf[0] = '%'; |
| 3102 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE); |
| 3103 | if (!PL_tokenbuf[1]) { |
| 3104 | PREREF('%'); |
| 3105 | } |
| 3106 | PL_pending_ident = '%'; |
| 3107 | TERM('%'); |
| 3108 | |
| 3109 | case '^': |
| 3110 | s++; |
| 3111 | BOop(OP_BIT_XOR); |
| 3112 | case '[': |
| 3113 | PL_lex_brackets++; |
| 3114 | /* FALL THROUGH */ |
| 3115 | case '~': |
| 3116 | case ',': |
| 3117 | tmp = *s++; |
| 3118 | OPERATOR(tmp); |
| 3119 | case ':': |
| 3120 | if (s[1] == ':') { |
| 3121 | len = 0; |
| 3122 | goto just_a_word; |
| 3123 | } |
| 3124 | s++; |
| 3125 | switch (PL_expect) { |
| 3126 | OP *attrs; |
| 3127 | case XOPERATOR: |
| 3128 | if (!PL_in_my || PL_lex_state != LEX_NORMAL) |
| 3129 | break; |
| 3130 | PL_bufptr = s; /* update in case we back off */ |
| 3131 | goto grabattrs; |
| 3132 | case XATTRBLOCK: |
| 3133 | PL_expect = XBLOCK; |
| 3134 | goto grabattrs; |
| 3135 | case XATTRTERM: |
| 3136 | PL_expect = XTERMBLOCK; |
| 3137 | grabattrs: |
| 3138 | s = skipspace(s); |
| 3139 | attrs = Nullop; |
| 3140 | while (isIDFIRST_lazy_if(s,UTF)) { |
| 3141 | d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
| 3142 | if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) { |
| 3143 | if (tmp < 0) tmp = -tmp; |
| 3144 | switch (tmp) { |
| 3145 | case KEY_or: |
| 3146 | case KEY_and: |
| 3147 | case KEY_err: |
| 3148 | case KEY_for: |
| 3149 | case KEY_unless: |
| 3150 | case KEY_if: |
| 3151 | case KEY_while: |
| 3152 | case KEY_until: |
| 3153 | goto got_attrs; |
| 3154 | default: |
| 3155 | break; |
| 3156 | } |
| 3157 | } |
| 3158 | if (*d == '(') { |
| 3159 | d = scan_str(d,TRUE,TRUE); |
| 3160 | if (!d) { |
| 3161 | /* MUST advance bufptr here to avoid bogus |
| 3162 | "at end of line" context messages from yyerror(). |
| 3163 | */ |
| 3164 | PL_bufptr = s + len; |
| 3165 | yyerror("Unterminated attribute parameter in attribute list"); |
| 3166 | if (attrs) |
| 3167 | op_free(attrs); |
| 3168 | return REPORT(0); /* EOF indicator */ |
| 3169 | } |
| 3170 | } |
| 3171 | if (PL_lex_stuff) { |
| 3172 | SV *sv = newSVpvn(s, len); |
| 3173 | sv_catsv(sv, PL_lex_stuff); |
| 3174 | attrs = append_elem(OP_LIST, attrs, |
| 3175 | newSVOP(OP_CONST, 0, sv)); |
| 3176 | SvREFCNT_dec(PL_lex_stuff); |
| 3177 | PL_lex_stuff = Nullsv; |
| 3178 | } |
| 3179 | else { |
| 3180 | if (len == 6 && strnEQ(s, "unique", len)) { |
| 3181 | if (PL_in_my == KEY_our) |
| 3182 | #ifdef USE_ITHREADS |
| 3183 | GvUNIQUE_on(cGVOPx_gv(yylval.opval)); |
| 3184 | #else |
| 3185 | ; /* skip to avoid loading attributes.pm */ |
| 3186 | #endif |
| 3187 | else |
| 3188 | Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables"); |
| 3189 | } |
| 3190 | |
| 3191 | /* NOTE: any CV attrs applied here need to be part of |
| 3192 | the CVf_BUILTIN_ATTRS define in cv.h! */ |
| 3193 | else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len)) |
| 3194 | CvLVALUE_on(PL_compcv); |
| 3195 | else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len)) |
| 3196 | CvLOCKED_on(PL_compcv); |
| 3197 | else if (!PL_in_my && len == 6 && strnEQ(s, "method", len)) |
| 3198 | CvMETHOD_on(PL_compcv); |
| 3199 | else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len)) |
| 3200 | CvASSERTION_on(PL_compcv); |
| 3201 | /* After we've set the flags, it could be argued that |
| 3202 | we don't need to do the attributes.pm-based setting |
| 3203 | process, and shouldn't bother appending recognized |
| 3204 | flags. To experiment with that, uncomment the |
| 3205 | following "else". (Note that's already been |
| 3206 | uncommented. That keeps the above-applied built-in |
| 3207 | attributes from being intercepted (and possibly |
| 3208 | rejected) by a package's attribute routines, but is |
| 3209 | justified by the performance win for the common case |
| 3210 | of applying only built-in attributes.) */ |
| 3211 | else |
| 3212 | attrs = append_elem(OP_LIST, attrs, |
| 3213 | newSVOP(OP_CONST, 0, |
| 3214 | newSVpvn(s, len))); |
| 3215 | } |
| 3216 | s = skipspace(d); |
| 3217 | if (*s == ':' && s[1] != ':') |
| 3218 | s = skipspace(s+1); |
| 3219 | else if (s == d) |
| 3220 | break; /* require real whitespace or :'s */ |
| 3221 | } |
| 3222 | tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */ |
| 3223 | if (*s != ';' && *s != '}' && *s != tmp && (tmp != '=' || *s != ')')) { |
| 3224 | char q = ((*s == '\'') ? '"' : '\''); |
| 3225 | /* If here for an expression, and parsed no attrs, back off. */ |
| 3226 | if (tmp == '=' && !attrs) { |
| 3227 | s = PL_bufptr; |
| 3228 | break; |
| 3229 | } |
| 3230 | /* MUST advance bufptr here to avoid bogus "at end of line" |
| 3231 | context messages from yyerror(). |
| 3232 | */ |
| 3233 | PL_bufptr = s; |
| 3234 | if (!*s) |
| 3235 | yyerror("Unterminated attribute list"); |
| 3236 | else |
| 3237 | yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list", |
| 3238 | q, *s, q)); |
| 3239 | if (attrs) |
| 3240 | op_free(attrs); |
| 3241 | OPERATOR(':'); |
| 3242 | } |
| 3243 | got_attrs: |
| 3244 | if (attrs) { |
| 3245 | PL_nextval[PL_nexttoke].opval = attrs; |
| 3246 | force_next(THING); |
| 3247 | } |
| 3248 | TOKEN(COLONATTR); |
| 3249 | } |
| 3250 | OPERATOR(':'); |
| 3251 | case '(': |
| 3252 | s++; |
| 3253 | if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr) |
| 3254 | PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */ |
| 3255 | else |
| 3256 | PL_expect = XTERM; |
| 3257 | s = skipspace(s); |
| 3258 | TOKEN('('); |
| 3259 | case ';': |
| 3260 | CLINE; |
| 3261 | tmp = *s++; |
| 3262 | OPERATOR(tmp); |
| 3263 | case ')': |
| 3264 | tmp = *s++; |
| 3265 | s = skipspace(s); |
| 3266 | if (*s == '{') |
| 3267 | PREBLOCK(tmp); |
| 3268 | TERM(tmp); |
| 3269 | case ']': |
| 3270 | s++; |
| 3271 | if (PL_lex_brackets <= 0) |
| 3272 | yyerror("Unmatched right square bracket"); |
| 3273 | else |
| 3274 | --PL_lex_brackets; |
| 3275 | if (PL_lex_state == LEX_INTERPNORMAL) { |
| 3276 | if (PL_lex_brackets == 0) { |
| 3277 | if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>')) |
| 3278 | PL_lex_state = LEX_INTERPEND; |
| 3279 | } |
| 3280 | } |
| 3281 | TERM(']'); |
| 3282 | case '{': |
| 3283 | leftbracket: |
| 3284 | s++; |
| 3285 | if (PL_lex_brackets > 100) { |
| 3286 | Renew(PL_lex_brackstack, PL_lex_brackets + 10, char); |
| 3287 | } |
| 3288 | switch (PL_expect) { |
| 3289 | case XTERM: |
| 3290 | if (PL_lex_formbrack) { |
| 3291 | s--; |
| 3292 | PRETERMBLOCK(DO); |
| 3293 | } |
| 3294 | if (PL_oldoldbufptr == PL_last_lop) |
| 3295 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; |
| 3296 | else |
| 3297 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
| 3298 | OPERATOR(HASHBRACK); |
| 3299 | case XOPERATOR: |
| 3300 | while (s < PL_bufend && SPACE_OR_TAB(*s)) |
| 3301 | s++; |
| 3302 | d = s; |
| 3303 | PL_tokenbuf[0] = '\0'; |
| 3304 | if (d < PL_bufend && *d == '-') { |
| 3305 | PL_tokenbuf[0] = '-'; |
| 3306 | d++; |
| 3307 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
| 3308 | d++; |
| 3309 | } |
| 3310 | if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) { |
| 3311 | d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, |
| 3312 | FALSE, &len); |
| 3313 | while (d < PL_bufend && SPACE_OR_TAB(*d)) |
| 3314 | d++; |
| 3315 | if (*d == '}') { |
| 3316 | char minus = (PL_tokenbuf[0] == '-'); |
| 3317 | s = force_word(s + minus, WORD, FALSE, TRUE, FALSE); |
| 3318 | if (minus) |
| 3319 | force_next('-'); |
| 3320 | } |
| 3321 | } |
| 3322 | /* FALL THROUGH */ |
| 3323 | case XATTRBLOCK: |
| 3324 | case XBLOCK: |
| 3325 | PL_lex_brackstack[PL_lex_brackets++] = XSTATE; |
| 3326 | PL_expect = XSTATE; |
| 3327 | break; |
| 3328 | case XATTRTERM: |
| 3329 | case XTERMBLOCK: |
| 3330 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
| 3331 | PL_expect = XSTATE; |
| 3332 | break; |
| 3333 | default: { |
| 3334 | char *t; |
| 3335 | if (PL_oldoldbufptr == PL_last_lop) |
| 3336 | PL_lex_brackstack[PL_lex_brackets++] = XTERM; |
| 3337 | else |
| 3338 | PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR; |
| 3339 | s = skipspace(s); |
| 3340 | if (*s == '}') { |
| 3341 | if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) { |
| 3342 | PL_expect = XTERM; |
| 3343 | /* This hack is to get the ${} in the message. */ |
| 3344 | PL_bufptr = s+1; |
| 3345 | yyerror("syntax error"); |
| 3346 | break; |
| 3347 | } |
| 3348 | OPERATOR(HASHBRACK); |
| 3349 | } |
| 3350 | /* This hack serves to disambiguate a pair of curlies |
| 3351 | * as being a block or an anon hash. Normally, expectation |
| 3352 | * determines that, but in cases where we're not in a |
| 3353 | * position to expect anything in particular (like inside |
| 3354 | * eval"") we have to resolve the ambiguity. This code |
| 3355 | * covers the case where the first term in the curlies is a |
| 3356 | * quoted string. Most other cases need to be explicitly |
| 3357 | * disambiguated by prepending a `+' before the opening |
| 3358 | * curly in order to force resolution as an anon hash. |
| 3359 | * |
| 3360 | * XXX should probably propagate the outer expectation |
| 3361 | * into eval"" to rely less on this hack, but that could |
| 3362 | * potentially break current behavior of eval"". |
| 3363 | * GSAR 97-07-21 |
| 3364 | */ |
| 3365 | t = s; |
| 3366 | if (*s == '\'' || *s == '"' || *s == '`') { |
| 3367 | /* common case: get past first string, handling escapes */ |
| 3368 | for (t++; t < PL_bufend && *t != *s;) |
| 3369 | if (*t++ == '\\' && (*t == '\\' || *t == *s)) |
| 3370 | t++; |
| 3371 | t++; |
| 3372 | } |
| 3373 | else if (*s == 'q') { |
| 3374 | if (++t < PL_bufend |
| 3375 | && (!isALNUM(*t) |
| 3376 | || ((*t == 'q' || *t == 'x') && ++t < PL_bufend |
| 3377 | && !isALNUM(*t)))) |
| 3378 | { |
| 3379 | /* skip q//-like construct */ |
| 3380 | char *tmps; |
| 3381 | char open, close, term; |
| 3382 | I32 brackets = 1; |
| 3383 | |
| 3384 | while (t < PL_bufend && isSPACE(*t)) |
| 3385 | t++; |
| 3386 | /* check for q => */ |
| 3387 | if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') { |
| 3388 | OPERATOR(HASHBRACK); |
| 3389 | } |
| 3390 | term = *t; |
| 3391 | open = term; |
| 3392 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) |
| 3393 | term = tmps[5]; |
| 3394 | close = term; |
| 3395 | if (open == close) |
| 3396 | for (t++; t < PL_bufend; t++) { |
| 3397 | if (*t == '\\' && t+1 < PL_bufend && open != '\\') |
| 3398 | t++; |
| 3399 | else if (*t == open) |
| 3400 | break; |
| 3401 | } |
| 3402 | else { |
| 3403 | for (t++; t < PL_bufend; t++) { |
| 3404 | if (*t == '\\' && t+1 < PL_bufend) |
| 3405 | t++; |
| 3406 | else if (*t == close && --brackets <= 0) |
| 3407 | break; |
| 3408 | else if (*t == open) |
| 3409 | brackets++; |
| 3410 | } |
| 3411 | } |
| 3412 | t++; |
| 3413 | } |
| 3414 | else |
| 3415 | /* skip plain q word */ |
| 3416 | while (t < PL_bufend && isALNUM_lazy_if(t,UTF)) |
| 3417 | t += UTF8SKIP(t); |
| 3418 | } |
| 3419 | else if (isALNUM_lazy_if(t,UTF)) { |
| 3420 | t += UTF8SKIP(t); |
| 3421 | while (t < PL_bufend && isALNUM_lazy_if(t,UTF)) |
| 3422 | t += UTF8SKIP(t); |
| 3423 | } |
| 3424 | while (t < PL_bufend && isSPACE(*t)) |
| 3425 | t++; |
| 3426 | /* if comma follows first term, call it an anon hash */ |
| 3427 | /* XXX it could be a comma expression with loop modifiers */ |
| 3428 | if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s))) |
| 3429 | || (*t == '=' && t[1] == '>'))) |
| 3430 | OPERATOR(HASHBRACK); |
| 3431 | if (PL_expect == XREF) |
| 3432 | PL_expect = XTERM; |
| 3433 | else { |
| 3434 | PL_lex_brackstack[PL_lex_brackets-1] = XSTATE; |
| 3435 | PL_expect = XSTATE; |
| 3436 | } |
| 3437 | } |
| 3438 | break; |
| 3439 | } |
| 3440 | yylval.ival = CopLINE(PL_curcop); |
| 3441 | if (isSPACE(*s) || *s == '#') |
| 3442 | PL_copline = NOLINE; /* invalidate current command line number */ |
| 3443 | TOKEN('{'); |
| 3444 | case '}': |
| 3445 | rightbracket: |
| 3446 | s++; |
| 3447 | if (PL_lex_brackets <= 0) |
| 3448 | yyerror("Unmatched right curly bracket"); |
| 3449 | else |
| 3450 | PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets]; |
| 3451 | if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL) |
| 3452 | PL_lex_formbrack = 0; |
| 3453 | if (PL_lex_state == LEX_INTERPNORMAL) { |
| 3454 | if (PL_lex_brackets == 0) { |
| 3455 | if (PL_expect & XFAKEBRACK) { |
| 3456 | PL_expect &= XENUMMASK; |
| 3457 | PL_lex_state = LEX_INTERPEND; |
| 3458 | PL_bufptr = s; |
| 3459 | return yylex(); /* ignore fake brackets */ |
| 3460 | } |
| 3461 | if (*s == '-' && s[1] == '>') |
| 3462 | PL_lex_state = LEX_INTERPENDMAYBE; |
| 3463 | else if (*s != '[' && *s != '{') |
| 3464 | PL_lex_state = LEX_INTERPEND; |
| 3465 | } |
| 3466 | } |
| 3467 | if (PL_expect & XFAKEBRACK) { |
| 3468 | PL_expect &= XENUMMASK; |
| 3469 | PL_bufptr = s; |
| 3470 | return yylex(); /* ignore fake brackets */ |
| 3471 | } |
| 3472 | force_next('}'); |
| 3473 | TOKEN(';'); |
| 3474 | case '&': |
| 3475 | s++; |
| 3476 | tmp = *s++; |
| 3477 | if (tmp == '&') |
| 3478 | AOPERATOR(ANDAND); |
| 3479 | s--; |
| 3480 | if (PL_expect == XOPERATOR) { |
| 3481 | if (ckWARN(WARN_SEMICOLON) |
| 3482 | && isIDFIRST_lazy_if(s,UTF) && PL_bufptr == PL_linestart) |
| 3483 | { |
| 3484 | CopLINE_dec(PL_curcop); |
| 3485 | Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi); |
| 3486 | CopLINE_inc(PL_curcop); |
| 3487 | } |
| 3488 | BAop(OP_BIT_AND); |
| 3489 | } |
| 3490 | |
| 3491 | s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); |
| 3492 | if (*PL_tokenbuf) { |
| 3493 | PL_expect = XOPERATOR; |
| 3494 | force_ident(PL_tokenbuf, '&'); |
| 3495 | } |
| 3496 | else |
| 3497 | PREREF('&'); |
| 3498 | yylval.ival = (OPpENTERSUB_AMPER<<8); |
| 3499 | TERM('&'); |
| 3500 | |
| 3501 | case '|': |
| 3502 | s++; |
| 3503 | tmp = *s++; |
| 3504 | if (tmp == '|') |
| 3505 | AOPERATOR(OROR); |
| 3506 | s--; |
| 3507 | BOop(OP_BIT_OR); |
| 3508 | case '=': |
| 3509 | s++; |
| 3510 | tmp = *s++; |
| 3511 | if (tmp == '=') |
| 3512 | Eop(OP_EQ); |
| 3513 | if (tmp == '>') |
| 3514 | OPERATOR(','); |
| 3515 | if (tmp == '~') |
| 3516 | PMop(OP_MATCH); |
| 3517 | if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp)) |
| 3518 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Reversed %c= operator",(int)tmp); |
| 3519 | s--; |
| 3520 | if (PL_expect == XSTATE && isALPHA(tmp) && |
| 3521 | (s == PL_linestart+1 || s[-2] == '\n') ) |
| 3522 | { |
| 3523 | if (PL_in_eval && !PL_rsfp) { |
| 3524 | d = PL_bufend; |
| 3525 | while (s < d) { |
| 3526 | if (*s++ == '\n') { |
| 3527 | incline(s); |
| 3528 | if (strnEQ(s,"=cut",4)) { |
| 3529 | s = strchr(s,'\n'); |
| 3530 | if (s) |
| 3531 | s++; |
| 3532 | else |
| 3533 | s = d; |
| 3534 | incline(s); |
| 3535 | goto retry; |
| 3536 | } |
| 3537 | } |
| 3538 | } |
| 3539 | goto retry; |
| 3540 | } |
| 3541 | s = PL_bufend; |
| 3542 | PL_doextract = TRUE; |
| 3543 | goto retry; |
| 3544 | } |
| 3545 | if (PL_lex_brackets < PL_lex_formbrack) { |
| 3546 | char *t; |
| 3547 | #ifdef PERL_STRICT_CR |
| 3548 | for (t = s; SPACE_OR_TAB(*t); t++) ; |
| 3549 | #else |
| 3550 | for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ; |
| 3551 | #endif |
| 3552 | if (*t == '\n' || *t == '#') { |
| 3553 | s--; |
| 3554 | PL_expect = XBLOCK; |
| 3555 | goto leftbracket; |
| 3556 | } |
| 3557 | } |
| 3558 | yylval.ival = 0; |
| 3559 | OPERATOR(ASSIGNOP); |
| 3560 | case '!': |
| 3561 | s++; |
| 3562 | tmp = *s++; |
| 3563 | if (tmp == '=') { |
| 3564 | /* was this !=~ where !~ was meant? |
| 3565 | * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */ |
| 3566 | |
| 3567 | if (*s == '~' && ckWARN(WARN_SYNTAX)) { |
| 3568 | char *t = s+1; |
| 3569 | |
| 3570 | while (t < PL_bufend && isSPACE(*t)) |
| 3571 | ++t; |
| 3572 | |
| 3573 | if (*t == '/' || *t == '?' || |
| 3574 | ((*t == 'm' || *t == 's' || *t == 'y') && !isALNUM(t[1])) || |
| 3575 | (*t == 't' && t[1] == 'r' && !isALNUM(t[2]))) |
| 3576 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 3577 | "!=~ should be !~"); |
| 3578 | } |
| 3579 | Eop(OP_NE); |
| 3580 | } |
| 3581 | if (tmp == '~') |
| 3582 | PMop(OP_NOT); |
| 3583 | s--; |
| 3584 | OPERATOR('!'); |
| 3585 | case '<': |
| 3586 | if (PL_expect != XOPERATOR) { |
| 3587 | if (s[1] != '<' && !strchr(s,'>')) |
| 3588 | check_uni(); |
| 3589 | if (s[1] == '<') |
| 3590 | s = scan_heredoc(s); |
| 3591 | else |
| 3592 | s = scan_inputsymbol(s); |
| 3593 | TERM(sublex_start()); |
| 3594 | } |
| 3595 | s++; |
| 3596 | tmp = *s++; |
| 3597 | if (tmp == '<') |
| 3598 | SHop(OP_LEFT_SHIFT); |
| 3599 | if (tmp == '=') { |
| 3600 | tmp = *s++; |
| 3601 | if (tmp == '>') |
| 3602 | Eop(OP_NCMP); |
| 3603 | s--; |
| 3604 | Rop(OP_LE); |
| 3605 | } |
| 3606 | s--; |
| 3607 | Rop(OP_LT); |
| 3608 | case '>': |
| 3609 | s++; |
| 3610 | tmp = *s++; |
| 3611 | if (tmp == '>') |
| 3612 | SHop(OP_RIGHT_SHIFT); |
| 3613 | if (tmp == '=') |
| 3614 | Rop(OP_GE); |
| 3615 | s--; |
| 3616 | Rop(OP_GT); |
| 3617 | |
| 3618 | case '$': |
| 3619 | CLINE; |
| 3620 | |
| 3621 | if (PL_expect == XOPERATOR) { |
| 3622 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { |
| 3623 | PL_expect = XTERM; |
| 3624 | depcom(); |
| 3625 | return REPORT(','); /* grandfather non-comma-format format */ |
| 3626 | } |
| 3627 | } |
| 3628 | |
| 3629 | if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) { |
| 3630 | PL_tokenbuf[0] = '@'; |
| 3631 | s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1, |
| 3632 | sizeof PL_tokenbuf - 1, FALSE); |
| 3633 | if (PL_expect == XOPERATOR) |
| 3634 | no_op("Array length", s); |
| 3635 | if (!PL_tokenbuf[1]) |
| 3636 | PREREF(DOLSHARP); |
| 3637 | PL_expect = XOPERATOR; |
| 3638 | PL_pending_ident = '#'; |
| 3639 | TOKEN(DOLSHARP); |
| 3640 | } |
| 3641 | |
| 3642 | PL_tokenbuf[0] = '$'; |
| 3643 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, |
| 3644 | sizeof PL_tokenbuf - 1, FALSE); |
| 3645 | if (PL_expect == XOPERATOR) |
| 3646 | no_op("Scalar", s); |
| 3647 | if (!PL_tokenbuf[1]) { |
| 3648 | if (s == PL_bufend) |
| 3649 | yyerror("Final $ should be \\$ or $name"); |
| 3650 | PREREF('$'); |
| 3651 | } |
| 3652 | |
| 3653 | /* This kludge not intended to be bulletproof. */ |
| 3654 | if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) { |
| 3655 | yylval.opval = newSVOP(OP_CONST, 0, |
| 3656 | newSViv(PL_compiling.cop_arybase)); |
| 3657 | yylval.opval->op_private = OPpCONST_ARYBASE; |
| 3658 | TERM(THING); |
| 3659 | } |
| 3660 | |
| 3661 | d = s; |
| 3662 | tmp = (I32)*s; |
| 3663 | if (PL_lex_state == LEX_NORMAL) |
| 3664 | s = skipspace(s); |
| 3665 | |
| 3666 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) { |
| 3667 | char *t; |
| 3668 | if (*s == '[') { |
| 3669 | PL_tokenbuf[0] = '@'; |
| 3670 | if (ckWARN(WARN_SYNTAX)) { |
| 3671 | for(t = s + 1; |
| 3672 | isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$'; |
| 3673 | t++) ; |
| 3674 | if (*t++ == ',') { |
| 3675 | PL_bufptr = skipspace(PL_bufptr); |
| 3676 | while (t < PL_bufend && *t != ']') |
| 3677 | t++; |
| 3678 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 3679 | "Multidimensional syntax %.*s not supported", |
| 3680 | (t - PL_bufptr) + 1, PL_bufptr); |
| 3681 | } |
| 3682 | } |
| 3683 | } |
| 3684 | else if (*s == '{') { |
| 3685 | PL_tokenbuf[0] = '%'; |
| 3686 | if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") && |
| 3687 | (t = strchr(s, '}')) && (t = strchr(t, '='))) |
| 3688 | { |
| 3689 | char tmpbuf[sizeof PL_tokenbuf]; |
| 3690 | STRLEN len; |
| 3691 | for (t++; isSPACE(*t); t++) ; |
| 3692 | if (isIDFIRST_lazy_if(t,UTF)) { |
| 3693 | t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len); |
| 3694 | for (; isSPACE(*t); t++) ; |
| 3695 | if (*t == ';' && get_cv(tmpbuf, FALSE)) |
| 3696 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 3697 | "You need to quote \"%s\"", tmpbuf); |
| 3698 | } |
| 3699 | } |
| 3700 | } |
| 3701 | } |
| 3702 | |
| 3703 | PL_expect = XOPERATOR; |
| 3704 | if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) { |
| 3705 | bool islop = (PL_last_lop == PL_oldoldbufptr); |
| 3706 | if (!islop || PL_last_lop_op == OP_GREPSTART) |
| 3707 | PL_expect = XOPERATOR; |
| 3708 | else if (strchr("$@\"'`q", *s)) |
| 3709 | PL_expect = XTERM; /* e.g. print $fh "foo" */ |
| 3710 | else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF)) |
| 3711 | PL_expect = XTERM; /* e.g. print $fh &sub */ |
| 3712 | else if (isIDFIRST_lazy_if(s,UTF)) { |
| 3713 | char tmpbuf[sizeof PL_tokenbuf]; |
| 3714 | scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
| 3715 | if ((tmp = keyword(tmpbuf, len))) { |
| 3716 | /* binary operators exclude handle interpretations */ |
| 3717 | switch (tmp) { |
| 3718 | case -KEY_x: |
| 3719 | case -KEY_eq: |
| 3720 | case -KEY_ne: |
| 3721 | case -KEY_gt: |
| 3722 | case -KEY_lt: |
| 3723 | case -KEY_ge: |
| 3724 | case -KEY_le: |
| 3725 | case -KEY_cmp: |
| 3726 | break; |
| 3727 | default: |
| 3728 | PL_expect = XTERM; /* e.g. print $fh length() */ |
| 3729 | break; |
| 3730 | } |
| 3731 | } |
| 3732 | else { |
| 3733 | PL_expect = XTERM; /* e.g. print $fh subr() */ |
| 3734 | } |
| 3735 | } |
| 3736 | else if (isDIGIT(*s)) |
| 3737 | PL_expect = XTERM; /* e.g. print $fh 3 */ |
| 3738 | else if (*s == '.' && isDIGIT(s[1])) |
| 3739 | PL_expect = XTERM; /* e.g. print $fh .3 */ |
| 3740 | else if ((*s == '?' || *s == '-' || *s == '+') |
| 3741 | && !isSPACE(s[1]) && s[1] != '=') |
| 3742 | PL_expect = XTERM; /* e.g. print $fh -1 */ |
| 3743 | else if (*s == '/' && !isSPACE(s[1]) && s[1] != '=' && s[1] != '/') |
| 3744 | PL_expect = XTERM; /* e.g. print $fh /.../ |
| 3745 | XXX except DORDOR operator */ |
| 3746 | else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=') |
| 3747 | PL_expect = XTERM; /* print $fh <<"EOF" */ |
| 3748 | } |
| 3749 | PL_pending_ident = '$'; |
| 3750 | TOKEN('$'); |
| 3751 | |
| 3752 | case '@': |
| 3753 | if (PL_expect == XOPERATOR) |
| 3754 | no_op("Array", s); |
| 3755 | PL_tokenbuf[0] = '@'; |
| 3756 | s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE); |
| 3757 | if (!PL_tokenbuf[1]) { |
| 3758 | PREREF('@'); |
| 3759 | } |
| 3760 | if (PL_lex_state == LEX_NORMAL) |
| 3761 | s = skipspace(s); |
| 3762 | if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) { |
| 3763 | if (*s == '{') |
| 3764 | PL_tokenbuf[0] = '%'; |
| 3765 | |
| 3766 | /* Warn about @ where they meant $. */ |
| 3767 | if (ckWARN(WARN_SYNTAX)) { |
| 3768 | if (*s == '[' || *s == '{') { |
| 3769 | char *t = s + 1; |
| 3770 | while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t))) |
| 3771 | t++; |
| 3772 | if (*t == '}' || *t == ']') { |
| 3773 | t++; |
| 3774 | PL_bufptr = skipspace(PL_bufptr); |
| 3775 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 3776 | "Scalar value %.*s better written as $%.*s", |
| 3777 | t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1); |
| 3778 | } |
| 3779 | } |
| 3780 | } |
| 3781 | } |
| 3782 | PL_pending_ident = '@'; |
| 3783 | TERM('@'); |
| 3784 | |
| 3785 | case '/': /* may be division, defined-or, or pattern */ |
| 3786 | if (PL_expect == XTERMORDORDOR && s[1] == '/') { |
| 3787 | s += 2; |
| 3788 | AOPERATOR(DORDOR); |
| 3789 | } |
| 3790 | case '?': /* may either be conditional or pattern */ |
| 3791 | if(PL_expect == XOPERATOR) { |
| 3792 | tmp = *s++; |
| 3793 | if(tmp == '?') { |
| 3794 | OPERATOR('?'); |
| 3795 | } |
| 3796 | else { |
| 3797 | tmp = *s++; |
| 3798 | if(tmp == '/') { |
| 3799 | /* A // operator. */ |
| 3800 | AOPERATOR(DORDOR); |
| 3801 | } |
| 3802 | else { |
| 3803 | s--; |
| 3804 | Mop(OP_DIVIDE); |
| 3805 | } |
| 3806 | } |
| 3807 | } |
| 3808 | else { |
| 3809 | /* Disable warning on "study /blah/" */ |
| 3810 | if (PL_oldoldbufptr == PL_last_uni |
| 3811 | && (*PL_last_uni != 's' || s - PL_last_uni < 5 |
| 3812 | || memNE(PL_last_uni, "study", 5) |
| 3813 | || isALNUM_lazy_if(PL_last_uni+5,UTF) |
| 3814 | )) |
| 3815 | check_uni(); |
| 3816 | s = scan_pat(s,OP_MATCH); |
| 3817 | TERM(sublex_start()); |
| 3818 | } |
| 3819 | |
| 3820 | case '.': |
| 3821 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack |
| 3822 | #ifdef PERL_STRICT_CR |
| 3823 | && s[1] == '\n' |
| 3824 | #else |
| 3825 | && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n')) |
| 3826 | #endif |
| 3827 | && (s == PL_linestart || s[-1] == '\n') ) |
| 3828 | { |
| 3829 | PL_lex_formbrack = 0; |
| 3830 | PL_expect = XSTATE; |
| 3831 | goto rightbracket; |
| 3832 | } |
| 3833 | if (PL_expect == XOPERATOR || !isDIGIT(s[1])) { |
| 3834 | tmp = *s++; |
| 3835 | if (*s == tmp) { |
| 3836 | s++; |
| 3837 | if (*s == tmp) { |
| 3838 | s++; |
| 3839 | yylval.ival = OPf_SPECIAL; |
| 3840 | } |
| 3841 | else |
| 3842 | yylval.ival = 0; |
| 3843 | OPERATOR(DOTDOT); |
| 3844 | } |
| 3845 | if (PL_expect != XOPERATOR) |
| 3846 | check_uni(); |
| 3847 | Aop(OP_CONCAT); |
| 3848 | } |
| 3849 | /* FALL THROUGH */ |
| 3850 | case '0': case '1': case '2': case '3': case '4': |
| 3851 | case '5': case '6': case '7': case '8': case '9': |
| 3852 | s = scan_num(s, &yylval); |
| 3853 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
| 3854 | "### Saw number in '%s'\n", s); |
| 3855 | } ); |
| 3856 | if (PL_expect == XOPERATOR) |
| 3857 | no_op("Number",s); |
| 3858 | TERM(THING); |
| 3859 | |
| 3860 | case '\'': |
| 3861 | s = scan_str(s,FALSE,FALSE); |
| 3862 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
| 3863 | "### Saw string before '%s'\n", s); |
| 3864 | } ); |
| 3865 | if (PL_expect == XOPERATOR) { |
| 3866 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { |
| 3867 | PL_expect = XTERM; |
| 3868 | depcom(); |
| 3869 | return REPORT(','); /* grandfather non-comma-format format */ |
| 3870 | } |
| 3871 | else |
| 3872 | no_op("String",s); |
| 3873 | } |
| 3874 | if (!s) |
| 3875 | missingterm((char*)0); |
| 3876 | yylval.ival = OP_CONST; |
| 3877 | TERM(sublex_start()); |
| 3878 | |
| 3879 | case '"': |
| 3880 | s = scan_str(s,FALSE,FALSE); |
| 3881 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
| 3882 | "### Saw string before '%s'\n", s); |
| 3883 | } ); |
| 3884 | if (PL_expect == XOPERATOR) { |
| 3885 | if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) { |
| 3886 | PL_expect = XTERM; |
| 3887 | depcom(); |
| 3888 | return REPORT(','); /* grandfather non-comma-format format */ |
| 3889 | } |
| 3890 | else |
| 3891 | no_op("String",s); |
| 3892 | } |
| 3893 | if (!s) |
| 3894 | missingterm((char*)0); |
| 3895 | yylval.ival = OP_CONST; |
| 3896 | for (d = SvPV(PL_lex_stuff, len); len; len--, d++) { |
| 3897 | if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) { |
| 3898 | yylval.ival = OP_STRINGIFY; |
| 3899 | break; |
| 3900 | } |
| 3901 | } |
| 3902 | TERM(sublex_start()); |
| 3903 | |
| 3904 | case '`': |
| 3905 | s = scan_str(s,FALSE,FALSE); |
| 3906 | DEBUG_T( { PerlIO_printf(Perl_debug_log, |
| 3907 | "### Saw backtick string before '%s'\n", s); |
| 3908 | } ); |
| 3909 | if (PL_expect == XOPERATOR) |
| 3910 | no_op("Backticks",s); |
| 3911 | if (!s) |
| 3912 | missingterm((char*)0); |
| 3913 | yylval.ival = OP_BACKTICK; |
| 3914 | set_csh(); |
| 3915 | TERM(sublex_start()); |
| 3916 | |
| 3917 | case '\\': |
| 3918 | s++; |
| 3919 | if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s)) |
| 3920 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression", |
| 3921 | *s, *s); |
| 3922 | if (PL_expect == XOPERATOR) |
| 3923 | no_op("Backslash",s); |
| 3924 | OPERATOR(REFGEN); |
| 3925 | |
| 3926 | case 'v': |
| 3927 | if (isDIGIT(s[1]) && PL_expect != XOPERATOR) { |
| 3928 | char *start = s; |
| 3929 | start++; |
| 3930 | start++; |
| 3931 | while (isDIGIT(*start) || *start == '_') |
| 3932 | start++; |
| 3933 | if (*start == '.' && isDIGIT(start[1])) { |
| 3934 | s = scan_num(s, &yylval); |
| 3935 | TERM(THING); |
| 3936 | } |
| 3937 | /* avoid v123abc() or $h{v1}, allow C<print v10;> */ |
| 3938 | else if (!isALPHA(*start) && (PL_expect == XTERM |
| 3939 | || PL_expect == XREF || PL_expect == XSTATE |
| 3940 | || PL_expect == XTERMORDORDOR)) { |
| 3941 | char c = *start; |
| 3942 | GV *gv; |
| 3943 | *start = '\0'; |
| 3944 | gv = gv_fetchpv(s, FALSE, SVt_PVCV); |
| 3945 | *start = c; |
| 3946 | if (!gv) { |
| 3947 | s = scan_num(s, &yylval); |
| 3948 | TERM(THING); |
| 3949 | } |
| 3950 | } |
| 3951 | } |
| 3952 | goto keylookup; |
| 3953 | case 'x': |
| 3954 | if (isDIGIT(s[1]) && PL_expect == XOPERATOR) { |
| 3955 | s++; |
| 3956 | Mop(OP_REPEAT); |
| 3957 | } |
| 3958 | goto keylookup; |
| 3959 | |
| 3960 | case '_': |
| 3961 | case 'a': case 'A': |
| 3962 | case 'b': case 'B': |
| 3963 | case 'c': case 'C': |
| 3964 | case 'd': case 'D': |
| 3965 | case 'e': case 'E': |
| 3966 | case 'f': case 'F': |
| 3967 | case 'g': case 'G': |
| 3968 | case 'h': case 'H': |
| 3969 | case 'i': case 'I': |
| 3970 | case 'j': case 'J': |
| 3971 | case 'k': case 'K': |
| 3972 | case 'l': case 'L': |
| 3973 | case 'm': case 'M': |
| 3974 | case 'n': case 'N': |
| 3975 | case 'o': case 'O': |
| 3976 | case 'p': case 'P': |
| 3977 | case 'q': case 'Q': |
| 3978 | case 'r': case 'R': |
| 3979 | case 's': case 'S': |
| 3980 | case 't': case 'T': |
| 3981 | case 'u': case 'U': |
| 3982 | case 'V': |
| 3983 | case 'w': case 'W': |
| 3984 | case 'X': |
| 3985 | case 'y': case 'Y': |
| 3986 | case 'z': case 'Z': |
| 3987 | |
| 3988 | keylookup: { |
| 3989 | orig_keyword = 0; |
| 3990 | gv = Nullgv; |
| 3991 | gvp = 0; |
| 3992 | |
| 3993 | PL_bufptr = s; |
| 3994 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
| 3995 | |
| 3996 | /* Some keywords can be followed by any delimiter, including ':' */ |
| 3997 | tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) || |
| 3998 | (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') || |
| 3999 | (PL_tokenbuf[0] == 'q' && |
| 4000 | strchr("qwxr", PL_tokenbuf[1]))))); |
| 4001 | |
| 4002 | /* x::* is just a word, unless x is "CORE" */ |
| 4003 | if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE")) |
| 4004 | goto just_a_word; |
| 4005 | |
| 4006 | d = s; |
| 4007 | while (d < PL_bufend && isSPACE(*d)) |
| 4008 | d++; /* no comments skipped here, or s### is misparsed */ |
| 4009 | |
| 4010 | /* Is this a label? */ |
| 4011 | if (!tmp && PL_expect == XSTATE |
| 4012 | && d < PL_bufend && *d == ':' && *(d + 1) != ':') { |
| 4013 | s = d + 1; |
| 4014 | yylval.pval = savepv(PL_tokenbuf); |
| 4015 | CLINE; |
| 4016 | TOKEN(LABEL); |
| 4017 | } |
| 4018 | |
| 4019 | /* Check for keywords */ |
| 4020 | tmp = keyword(PL_tokenbuf, len); |
| 4021 | |
| 4022 | /* Is this a word before a => operator? */ |
| 4023 | if (*d == '=' && d[1] == '>') { |
| 4024 | CLINE; |
| 4025 | yylval.opval |
| 4026 | = (OP*)newSVOP(OP_CONST, 0, |
| 4027 | S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len)); |
| 4028 | yylval.opval->op_private = OPpCONST_BARE; |
| 4029 | TERM(WORD); |
| 4030 | } |
| 4031 | |
| 4032 | if (tmp < 0) { /* second-class keyword? */ |
| 4033 | GV *ogv = Nullgv; /* override (winner) */ |
| 4034 | GV *hgv = Nullgv; /* hidden (loser) */ |
| 4035 | if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) { |
| 4036 | CV *cv; |
| 4037 | if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) && |
| 4038 | (cv = GvCVu(gv))) |
| 4039 | { |
| 4040 | if (GvIMPORTED_CV(gv)) |
| 4041 | ogv = gv; |
| 4042 | else if (! CvMETHOD(cv)) |
| 4043 | hgv = gv; |
| 4044 | } |
| 4045 | if (!ogv && |
| 4046 | (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) && |
| 4047 | (gv = *gvp) != (GV*)&PL_sv_undef && |
| 4048 | GvCVu(gv) && GvIMPORTED_CV(gv)) |
| 4049 | { |
| 4050 | ogv = gv; |
| 4051 | } |
| 4052 | } |
| 4053 | if (ogv) { |
| 4054 | orig_keyword = tmp; |
| 4055 | tmp = 0; /* overridden by import or by GLOBAL */ |
| 4056 | } |
| 4057 | else if (gv && !gvp |
| 4058 | && -tmp==KEY_lock /* XXX generalizable kludge */ |
| 4059 | && GvCVu(gv) |
| 4060 | && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE)) |
| 4061 | { |
| 4062 | tmp = 0; /* any sub overrides "weak" keyword */ |
| 4063 | } |
| 4064 | else if (gv && !gvp |
| 4065 | && tmp == -KEY_err |
| 4066 | && GvCVu(gv) |
| 4067 | && PL_expect != XOPERATOR |
| 4068 | && PL_expect != XTERMORDORDOR) |
| 4069 | { |
| 4070 | /* any sub overrides the "err" keyword, except when really an |
| 4071 | * operator is expected */ |
| 4072 | tmp = 0; |
| 4073 | } |
| 4074 | else { /* no override */ |
| 4075 | tmp = -tmp; |
| 4076 | if (tmp == KEY_dump && ckWARN(WARN_MISC)) { |
| 4077 | Perl_warner(aTHX_ packWARN(WARN_MISC), |
| 4078 | "dump() better written as CORE::dump()"); |
| 4079 | } |
| 4080 | gv = Nullgv; |
| 4081 | gvp = 0; |
| 4082 | if (ckWARN(WARN_AMBIGUOUS) && hgv |
| 4083 | && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */ |
| 4084 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 4085 | "Ambiguous call resolved as CORE::%s(), %s", |
| 4086 | GvENAME(hgv), "qualify as such or use &"); |
| 4087 | } |
| 4088 | } |
| 4089 | |
| 4090 | reserved_word: |
| 4091 | switch (tmp) { |
| 4092 | |
| 4093 | default: /* not a keyword */ |
| 4094 | just_a_word: { |
| 4095 | SV *sv; |
| 4096 | int pkgname = 0; |
| 4097 | char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]); |
| 4098 | |
| 4099 | /* Get the rest if it looks like a package qualifier */ |
| 4100 | |
| 4101 | if (*s == '\'' || (*s == ':' && s[1] == ':')) { |
| 4102 | STRLEN morelen; |
| 4103 | s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len, |
| 4104 | TRUE, &morelen); |
| 4105 | if (!morelen) |
| 4106 | Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf, |
| 4107 | *s == '\'' ? "'" : "::"); |
| 4108 | len += morelen; |
| 4109 | pkgname = 1; |
| 4110 | } |
| 4111 | |
| 4112 | if (PL_expect == XOPERATOR) { |
| 4113 | if (PL_bufptr == PL_linestart) { |
| 4114 | CopLINE_dec(PL_curcop); |
| 4115 | Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi); |
| 4116 | CopLINE_inc(PL_curcop); |
| 4117 | } |
| 4118 | else |
| 4119 | no_op("Bareword",s); |
| 4120 | } |
| 4121 | |
| 4122 | /* Look for a subroutine with this name in current package, |
| 4123 | unless name is "Foo::", in which case Foo is a bearword |
| 4124 | (and a package name). */ |
| 4125 | |
| 4126 | if (len > 2 && |
| 4127 | PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':') |
| 4128 | { |
| 4129 | if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV)) |
| 4130 | Perl_warner(aTHX_ packWARN(WARN_BAREWORD), |
| 4131 | "Bareword \"%s\" refers to nonexistent package", |
| 4132 | PL_tokenbuf); |
| 4133 | len -= 2; |
| 4134 | PL_tokenbuf[len] = '\0'; |
| 4135 | gv = Nullgv; |
| 4136 | gvp = 0; |
| 4137 | } |
| 4138 | else { |
| 4139 | len = 0; |
| 4140 | if (!gv) |
| 4141 | gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV); |
| 4142 | } |
| 4143 | |
| 4144 | /* if we saw a global override before, get the right name */ |
| 4145 | |
| 4146 | if (gvp) { |
| 4147 | sv = newSVpvn("CORE::GLOBAL::",14); |
| 4148 | sv_catpv(sv,PL_tokenbuf); |
| 4149 | } |
| 4150 | else { |
| 4151 | /* If len is 0, newSVpv does strlen(), which is correct. |
| 4152 | If len is non-zero, then it will be the true length, |
| 4153 | and so the scalar will be created correctly. */ |
| 4154 | sv = newSVpv(PL_tokenbuf,len); |
| 4155 | } |
| 4156 | |
| 4157 | /* Presume this is going to be a bareword of some sort. */ |
| 4158 | |
| 4159 | CLINE; |
| 4160 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); |
| 4161 | yylval.opval->op_private = OPpCONST_BARE; |
| 4162 | /* UTF-8 package name? */ |
| 4163 | if (UTF && !IN_BYTES && |
| 4164 | is_utf8_string((U8*)SvPVX(sv), SvCUR(sv))) |
| 4165 | SvUTF8_on(sv); |
| 4166 | |
| 4167 | /* And if "Foo::", then that's what it certainly is. */ |
| 4168 | |
| 4169 | if (len) |
| 4170 | goto safe_bareword; |
| 4171 | |
| 4172 | /* See if it's the indirect object for a list operator. */ |
| 4173 | |
| 4174 | if (PL_oldoldbufptr && |
| 4175 | PL_oldoldbufptr < PL_bufptr && |
| 4176 | (PL_oldoldbufptr == PL_last_lop |
| 4177 | || PL_oldoldbufptr == PL_last_uni) && |
| 4178 | /* NO SKIPSPACE BEFORE HERE! */ |
| 4179 | (PL_expect == XREF || |
| 4180 | ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF)) |
| 4181 | { |
| 4182 | bool immediate_paren = *s == '('; |
| 4183 | |
| 4184 | /* (Now we can afford to cross potential line boundary.) */ |
| 4185 | s = skipspace(s); |
| 4186 | |
| 4187 | /* Two barewords in a row may indicate method call. */ |
| 4188 | |
| 4189 | if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv))) |
| 4190 | return REPORT(tmp); |
| 4191 | |
| 4192 | /* If not a declared subroutine, it's an indirect object. */ |
| 4193 | /* (But it's an indir obj regardless for sort.) */ |
| 4194 | |
| 4195 | if ( !immediate_paren && (PL_last_lop_op == OP_SORT || |
| 4196 | ((!gv || !GvCVu(gv)) && |
| 4197 | (PL_last_lop_op != OP_MAPSTART && |
| 4198 | PL_last_lop_op != OP_GREPSTART)))) |
| 4199 | { |
| 4200 | PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR; |
| 4201 | goto bareword; |
| 4202 | } |
| 4203 | } |
| 4204 | |
| 4205 | PL_expect = XOPERATOR; |
| 4206 | s = skipspace(s); |
| 4207 | |
| 4208 | /* Is this a word before a => operator? */ |
| 4209 | if (*s == '=' && s[1] == '>' && !pkgname) { |
| 4210 | CLINE; |
| 4211 | sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf); |
| 4212 | if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len)) |
| 4213 | SvUTF8_on(((SVOP*)yylval.opval)->op_sv); |
| 4214 | TERM(WORD); |
| 4215 | } |
| 4216 | |
| 4217 | /* If followed by a paren, it's certainly a subroutine. */ |
| 4218 | if (*s == '(') { |
| 4219 | CLINE; |
| 4220 | if (gv && GvCVu(gv)) { |
| 4221 | for (d = s + 1; SPACE_OR_TAB(*d); d++) ; |
| 4222 | if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) { |
| 4223 | s = d + 1; |
| 4224 | goto its_constant; |
| 4225 | } |
| 4226 | } |
| 4227 | PL_nextval[PL_nexttoke].opval = yylval.opval; |
| 4228 | PL_expect = XOPERATOR; |
| 4229 | force_next(WORD); |
| 4230 | yylval.ival = 0; |
| 4231 | TOKEN('&'); |
| 4232 | } |
| 4233 | |
| 4234 | /* If followed by var or block, call it a method (unless sub) */ |
| 4235 | |
| 4236 | if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) { |
| 4237 | PL_last_lop = PL_oldbufptr; |
| 4238 | PL_last_lop_op = OP_METHOD; |
| 4239 | PREBLOCK(METHOD); |
| 4240 | } |
| 4241 | |
| 4242 | /* If followed by a bareword, see if it looks like indir obj. */ |
| 4243 | |
| 4244 | if (!orig_keyword |
| 4245 | && (isIDFIRST_lazy_if(s,UTF) || *s == '$') |
| 4246 | && (tmp = intuit_method(s,gv))) |
| 4247 | return REPORT(tmp); |
| 4248 | |
| 4249 | /* Not a method, so call it a subroutine (if defined) */ |
| 4250 | |
| 4251 | if (gv && GvCVu(gv)) { |
| 4252 | CV* cv; |
| 4253 | if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS)) |
| 4254 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 4255 | "Ambiguous use of -%s resolved as -&%s()", |
| 4256 | PL_tokenbuf, PL_tokenbuf); |
| 4257 | /* Check for a constant sub */ |
| 4258 | cv = GvCV(gv); |
| 4259 | if ((sv = cv_const_sv(cv))) { |
| 4260 | its_constant: |
| 4261 | SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv); |
| 4262 | ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv); |
| 4263 | yylval.opval->op_private = 0; |
| 4264 | TOKEN(WORD); |
| 4265 | } |
| 4266 | |
| 4267 | /* Resolve to GV now. */ |
| 4268 | op_free(yylval.opval); |
| 4269 | yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv)); |
| 4270 | yylval.opval->op_private |= OPpENTERSUB_NOPAREN; |
| 4271 | PL_last_lop = PL_oldbufptr; |
| 4272 | PL_last_lop_op = OP_ENTERSUB; |
| 4273 | /* Is there a prototype? */ |
| 4274 | if (SvPOK(cv)) { |
| 4275 | STRLEN len; |
| 4276 | char *proto = SvPV((SV*)cv, len); |
| 4277 | if (!len) |
| 4278 | TERM(FUNC0SUB); |
| 4279 | if (*proto == '$' && proto[1] == '\0') |
| 4280 | OPERATOR(UNIOPSUB); |
| 4281 | while (*proto == ';') |
| 4282 | proto++; |
| 4283 | if (*proto == '&' && *s == '{') { |
| 4284 | sv_setpv(PL_subname, PL_curstash ? |
| 4285 | "__ANON__" : "__ANON__::__ANON__"); |
| 4286 | PREBLOCK(LSTOPSUB); |
| 4287 | } |
| 4288 | } |
| 4289 | PL_nextval[PL_nexttoke].opval = yylval.opval; |
| 4290 | PL_expect = XTERM; |
| 4291 | force_next(WORD); |
| 4292 | TOKEN(NOAMP); |
| 4293 | } |
| 4294 | |
| 4295 | /* Call it a bare word */ |
| 4296 | |
| 4297 | if (PL_hints & HINT_STRICT_SUBS) |
| 4298 | yylval.opval->op_private |= OPpCONST_STRICT; |
| 4299 | else { |
| 4300 | bareword: |
| 4301 | if (ckWARN(WARN_RESERVED)) { |
| 4302 | if (lastchar != '-') { |
| 4303 | for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ; |
| 4304 | if (!*d && !gv_stashpv(PL_tokenbuf,FALSE)) |
| 4305 | Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved, |
| 4306 | PL_tokenbuf); |
| 4307 | } |
| 4308 | } |
| 4309 | } |
| 4310 | |
| 4311 | safe_bareword: |
| 4312 | if ((lastchar == '*' || lastchar == '%' || lastchar == '&') |
| 4313 | && ckWARN_d(WARN_AMBIGUOUS)) { |
| 4314 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 4315 | "Operator or semicolon missing before %c%s", |
| 4316 | lastchar, PL_tokenbuf); |
| 4317 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 4318 | "Ambiguous use of %c resolved as operator %c", |
| 4319 | lastchar, lastchar); |
| 4320 | } |
| 4321 | TOKEN(WORD); |
| 4322 | } |
| 4323 | |
| 4324 | case KEY___FILE__: |
| 4325 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
| 4326 | newSVpv(CopFILE(PL_curcop),0)); |
| 4327 | TERM(THING); |
| 4328 | |
| 4329 | case KEY___LINE__: |
| 4330 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
| 4331 | Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop))); |
| 4332 | TERM(THING); |
| 4333 | |
| 4334 | case KEY___PACKAGE__: |
| 4335 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, |
| 4336 | (PL_curstash |
| 4337 | ? newSVpv(HvNAME(PL_curstash), 0) |
| 4338 | : &PL_sv_undef)); |
| 4339 | TERM(THING); |
| 4340 | |
| 4341 | case KEY___DATA__: |
| 4342 | case KEY___END__: { |
| 4343 | GV *gv; |
| 4344 | |
| 4345 | /*SUPPRESS 560*/ |
| 4346 | if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) { |
| 4347 | const char *pname = "main"; |
| 4348 | if (PL_tokenbuf[2] == 'D') |
| 4349 | pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash); |
| 4350 | gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO); |
| 4351 | GvMULTI_on(gv); |
| 4352 | if (!GvIO(gv)) |
| 4353 | GvIOp(gv) = newIO(); |
| 4354 | IoIFP(GvIOp(gv)) = PL_rsfp; |
| 4355 | #if defined(HAS_FCNTL) && defined(F_SETFD) |
| 4356 | { |
| 4357 | int fd = PerlIO_fileno(PL_rsfp); |
| 4358 | fcntl(fd,F_SETFD,fd >= 3); |
| 4359 | } |
| 4360 | #endif |
| 4361 | /* Mark this internal pseudo-handle as clean */ |
| 4362 | IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT; |
| 4363 | if (PL_preprocess) |
| 4364 | IoTYPE(GvIOp(gv)) = IoTYPE_PIPE; |
| 4365 | else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) |
| 4366 | IoTYPE(GvIOp(gv)) = IoTYPE_STD; |
| 4367 | else |
| 4368 | IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY; |
| 4369 | #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS) |
| 4370 | /* if the script was opened in binmode, we need to revert |
| 4371 | * it to text mode for compatibility; but only iff it has CRs |
| 4372 | * XXX this is a questionable hack at best. */ |
| 4373 | if (PL_bufend-PL_bufptr > 2 |
| 4374 | && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r') |
| 4375 | { |
| 4376 | Off_t loc = 0; |
| 4377 | if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) { |
| 4378 | loc = PerlIO_tell(PL_rsfp); |
| 4379 | (void)PerlIO_seek(PL_rsfp, 0L, 0); |
| 4380 | } |
| 4381 | #ifdef NETWARE |
| 4382 | if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) { |
| 4383 | #else |
| 4384 | if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) { |
| 4385 | #endif /* NETWARE */ |
| 4386 | #ifdef PERLIO_IS_STDIO /* really? */ |
| 4387 | # if defined(__BORLANDC__) |
| 4388 | /* XXX see note in do_binmode() */ |
| 4389 | ((FILE*)PL_rsfp)->flags &= ~_F_BIN; |
| 4390 | # endif |
| 4391 | #endif |
| 4392 | if (loc > 0) |
| 4393 | PerlIO_seek(PL_rsfp, loc, 0); |
| 4394 | } |
| 4395 | } |
| 4396 | #endif |
| 4397 | #ifdef PERLIO_LAYERS |
| 4398 | if (!IN_BYTES) { |
| 4399 | if (UTF) |
| 4400 | PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8"); |
| 4401 | else if (PL_encoding) { |
| 4402 | SV *name; |
| 4403 | dSP; |
| 4404 | ENTER; |
| 4405 | SAVETMPS; |
| 4406 | PUSHMARK(sp); |
| 4407 | EXTEND(SP, 1); |
| 4408 | XPUSHs(PL_encoding); |
| 4409 | PUTBACK; |
| 4410 | call_method("name", G_SCALAR); |
| 4411 | SPAGAIN; |
| 4412 | name = POPs; |
| 4413 | PUTBACK; |
| 4414 | PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, |
| 4415 | Perl_form(aTHX_ ":encoding(%"SVf")", |
| 4416 | name)); |
| 4417 | FREETMPS; |
| 4418 | LEAVE; |
| 4419 | } |
| 4420 | } |
| 4421 | #endif |
| 4422 | PL_rsfp = Nullfp; |
| 4423 | } |
| 4424 | goto fake_eof; |
| 4425 | } |
| 4426 | |
| 4427 | case KEY_AUTOLOAD: |
| 4428 | case KEY_DESTROY: |
| 4429 | case KEY_BEGIN: |
| 4430 | case KEY_CHECK: |
| 4431 | case KEY_INIT: |
| 4432 | case KEY_END: |
| 4433 | if (PL_expect == XSTATE) { |
| 4434 | s = PL_bufptr; |
| 4435 | goto really_sub; |
| 4436 | } |
| 4437 | goto just_a_word; |
| 4438 | |
| 4439 | case KEY_CORE: |
| 4440 | if (*s == ':' && s[1] == ':') { |
| 4441 | s += 2; |
| 4442 | d = s; |
| 4443 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len); |
| 4444 | if (!(tmp = keyword(PL_tokenbuf, len))) |
| 4445 | Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf); |
| 4446 | if (tmp < 0) |
| 4447 | tmp = -tmp; |
| 4448 | goto reserved_word; |
| 4449 | } |
| 4450 | goto just_a_word; |
| 4451 | |
| 4452 | case KEY_abs: |
| 4453 | UNI(OP_ABS); |
| 4454 | |
| 4455 | case KEY_alarm: |
| 4456 | UNI(OP_ALARM); |
| 4457 | |
| 4458 | case KEY_accept: |
| 4459 | LOP(OP_ACCEPT,XTERM); |
| 4460 | |
| 4461 | case KEY_and: |
| 4462 | OPERATOR(ANDOP); |
| 4463 | |
| 4464 | case KEY_atan2: |
| 4465 | LOP(OP_ATAN2,XTERM); |
| 4466 | |
| 4467 | case KEY_bind: |
| 4468 | LOP(OP_BIND,XTERM); |
| 4469 | |
| 4470 | case KEY_binmode: |
| 4471 | LOP(OP_BINMODE,XTERM); |
| 4472 | |
| 4473 | case KEY_bless: |
| 4474 | LOP(OP_BLESS,XTERM); |
| 4475 | |
| 4476 | case KEY_chop: |
| 4477 | UNI(OP_CHOP); |
| 4478 | |
| 4479 | case KEY_continue: |
| 4480 | PREBLOCK(CONTINUE); |
| 4481 | |
| 4482 | case KEY_chdir: |
| 4483 | (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */ |
| 4484 | UNI(OP_CHDIR); |
| 4485 | |
| 4486 | case KEY_close: |
| 4487 | UNI(OP_CLOSE); |
| 4488 | |
| 4489 | case KEY_closedir: |
| 4490 | UNI(OP_CLOSEDIR); |
| 4491 | |
| 4492 | case KEY_cmp: |
| 4493 | Eop(OP_SCMP); |
| 4494 | |
| 4495 | case KEY_caller: |
| 4496 | UNI(OP_CALLER); |
| 4497 | |
| 4498 | case KEY_crypt: |
| 4499 | #ifdef FCRYPT |
| 4500 | if (!PL_cryptseen) { |
| 4501 | PL_cryptseen = TRUE; |
| 4502 | init_des(); |
| 4503 | } |
| 4504 | #endif |
| 4505 | LOP(OP_CRYPT,XTERM); |
| 4506 | |
| 4507 | case KEY_chmod: |
| 4508 | LOP(OP_CHMOD,XTERM); |
| 4509 | |
| 4510 | case KEY_chown: |
| 4511 | LOP(OP_CHOWN,XTERM); |
| 4512 | |
| 4513 | case KEY_connect: |
| 4514 | LOP(OP_CONNECT,XTERM); |
| 4515 | |
| 4516 | case KEY_chr: |
| 4517 | UNI(OP_CHR); |
| 4518 | |
| 4519 | case KEY_cos: |
| 4520 | UNI(OP_COS); |
| 4521 | |
| 4522 | case KEY_chroot: |
| 4523 | UNI(OP_CHROOT); |
| 4524 | |
| 4525 | case KEY_do: |
| 4526 | s = skipspace(s); |
| 4527 | if (*s == '{') |
| 4528 | PRETERMBLOCK(DO); |
| 4529 | if (*s != '\'') |
| 4530 | s = force_word(s,WORD,TRUE,TRUE,FALSE); |
| 4531 | OPERATOR(DO); |
| 4532 | |
| 4533 | case KEY_die: |
| 4534 | PL_hints |= HINT_BLOCK_SCOPE; |
| 4535 | LOP(OP_DIE,XTERM); |
| 4536 | |
| 4537 | case KEY_defined: |
| 4538 | UNI(OP_DEFINED); |
| 4539 | |
| 4540 | case KEY_delete: |
| 4541 | UNI(OP_DELETE); |
| 4542 | |
| 4543 | case KEY_dbmopen: |
| 4544 | gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV); |
| 4545 | LOP(OP_DBMOPEN,XTERM); |
| 4546 | |
| 4547 | case KEY_dbmclose: |
| 4548 | UNI(OP_DBMCLOSE); |
| 4549 | |
| 4550 | case KEY_dump: |
| 4551 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
| 4552 | LOOPX(OP_DUMP); |
| 4553 | |
| 4554 | case KEY_else: |
| 4555 | PREBLOCK(ELSE); |
| 4556 | |
| 4557 | case KEY_elsif: |
| 4558 | yylval.ival = CopLINE(PL_curcop); |
| 4559 | OPERATOR(ELSIF); |
| 4560 | |
| 4561 | case KEY_eq: |
| 4562 | Eop(OP_SEQ); |
| 4563 | |
| 4564 | case KEY_exists: |
| 4565 | UNI(OP_EXISTS); |
| 4566 | |
| 4567 | case KEY_exit: |
| 4568 | UNI(OP_EXIT); |
| 4569 | |
| 4570 | case KEY_eval: |
| 4571 | s = skipspace(s); |
| 4572 | PL_expect = (*s == '{') ? XTERMBLOCK : XTERM; |
| 4573 | UNIBRACK(OP_ENTEREVAL); |
| 4574 | |
| 4575 | case KEY_eof: |
| 4576 | UNI(OP_EOF); |
| 4577 | |
| 4578 | case KEY_err: |
| 4579 | OPERATOR(DOROP); |
| 4580 | |
| 4581 | case KEY_exp: |
| 4582 | UNI(OP_EXP); |
| 4583 | |
| 4584 | case KEY_each: |
| 4585 | UNI(OP_EACH); |
| 4586 | |
| 4587 | case KEY_exec: |
| 4588 | set_csh(); |
| 4589 | LOP(OP_EXEC,XREF); |
| 4590 | |
| 4591 | case KEY_endhostent: |
| 4592 | FUN0(OP_EHOSTENT); |
| 4593 | |
| 4594 | case KEY_endnetent: |
| 4595 | FUN0(OP_ENETENT); |
| 4596 | |
| 4597 | case KEY_endservent: |
| 4598 | FUN0(OP_ESERVENT); |
| 4599 | |
| 4600 | case KEY_endprotoent: |
| 4601 | FUN0(OP_EPROTOENT); |
| 4602 | |
| 4603 | case KEY_endpwent: |
| 4604 | FUN0(OP_EPWENT); |
| 4605 | |
| 4606 | case KEY_endgrent: |
| 4607 | FUN0(OP_EGRENT); |
| 4608 | |
| 4609 | case KEY_for: |
| 4610 | case KEY_foreach: |
| 4611 | yylval.ival = CopLINE(PL_curcop); |
| 4612 | s = skipspace(s); |
| 4613 | if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) { |
| 4614 | char *p = s; |
| 4615 | if ((PL_bufend - p) >= 3 && |
| 4616 | strnEQ(p, "my", 2) && isSPACE(*(p + 2))) |
| 4617 | p += 2; |
| 4618 | else if ((PL_bufend - p) >= 4 && |
| 4619 | strnEQ(p, "our", 3) && isSPACE(*(p + 3))) |
| 4620 | p += 3; |
| 4621 | p = skipspace(p); |
| 4622 | if (isIDFIRST_lazy_if(p,UTF)) { |
| 4623 | p = scan_ident(p, PL_bufend, |
| 4624 | PL_tokenbuf, sizeof PL_tokenbuf, TRUE); |
| 4625 | p = skipspace(p); |
| 4626 | } |
| 4627 | if (*p != '$') |
| 4628 | Perl_croak(aTHX_ "Missing $ on loop variable"); |
| 4629 | } |
| 4630 | OPERATOR(FOR); |
| 4631 | |
| 4632 | case KEY_formline: |
| 4633 | LOP(OP_FORMLINE,XTERM); |
| 4634 | |
| 4635 | case KEY_fork: |
| 4636 | FUN0(OP_FORK); |
| 4637 | |
| 4638 | case KEY_fcntl: |
| 4639 | LOP(OP_FCNTL,XTERM); |
| 4640 | |
| 4641 | case KEY_fileno: |
| 4642 | UNI(OP_FILENO); |
| 4643 | |
| 4644 | case KEY_flock: |
| 4645 | LOP(OP_FLOCK,XTERM); |
| 4646 | |
| 4647 | case KEY_gt: |
| 4648 | Rop(OP_SGT); |
| 4649 | |
| 4650 | case KEY_ge: |
| 4651 | Rop(OP_SGE); |
| 4652 | |
| 4653 | case KEY_grep: |
| 4654 | LOP(OP_GREPSTART, XREF); |
| 4655 | |
| 4656 | case KEY_goto: |
| 4657 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
| 4658 | LOOPX(OP_GOTO); |
| 4659 | |
| 4660 | case KEY_gmtime: |
| 4661 | UNI(OP_GMTIME); |
| 4662 | |
| 4663 | case KEY_getc: |
| 4664 | UNIDOR(OP_GETC); |
| 4665 | |
| 4666 | case KEY_getppid: |
| 4667 | FUN0(OP_GETPPID); |
| 4668 | |
| 4669 | case KEY_getpgrp: |
| 4670 | UNI(OP_GETPGRP); |
| 4671 | |
| 4672 | case KEY_getpriority: |
| 4673 | LOP(OP_GETPRIORITY,XTERM); |
| 4674 | |
| 4675 | case KEY_getprotobyname: |
| 4676 | UNI(OP_GPBYNAME); |
| 4677 | |
| 4678 | case KEY_getprotobynumber: |
| 4679 | LOP(OP_GPBYNUMBER,XTERM); |
| 4680 | |
| 4681 | case KEY_getprotoent: |
| 4682 | FUN0(OP_GPROTOENT); |
| 4683 | |
| 4684 | case KEY_getpwent: |
| 4685 | FUN0(OP_GPWENT); |
| 4686 | |
| 4687 | case KEY_getpwnam: |
| 4688 | UNI(OP_GPWNAM); |
| 4689 | |
| 4690 | case KEY_getpwuid: |
| 4691 | UNI(OP_GPWUID); |
| 4692 | |
| 4693 | case KEY_getpeername: |
| 4694 | UNI(OP_GETPEERNAME); |
| 4695 | |
| 4696 | case KEY_gethostbyname: |
| 4697 | UNI(OP_GHBYNAME); |
| 4698 | |
| 4699 | case KEY_gethostbyaddr: |
| 4700 | LOP(OP_GHBYADDR,XTERM); |
| 4701 | |
| 4702 | case KEY_gethostent: |
| 4703 | FUN0(OP_GHOSTENT); |
| 4704 | |
| 4705 | case KEY_getnetbyname: |
| 4706 | UNI(OP_GNBYNAME); |
| 4707 | |
| 4708 | case KEY_getnetbyaddr: |
| 4709 | LOP(OP_GNBYADDR,XTERM); |
| 4710 | |
| 4711 | case KEY_getnetent: |
| 4712 | FUN0(OP_GNETENT); |
| 4713 | |
| 4714 | case KEY_getservbyname: |
| 4715 | LOP(OP_GSBYNAME,XTERM); |
| 4716 | |
| 4717 | case KEY_getservbyport: |
| 4718 | LOP(OP_GSBYPORT,XTERM); |
| 4719 | |
| 4720 | case KEY_getservent: |
| 4721 | FUN0(OP_GSERVENT); |
| 4722 | |
| 4723 | case KEY_getsockname: |
| 4724 | UNI(OP_GETSOCKNAME); |
| 4725 | |
| 4726 | case KEY_getsockopt: |
| 4727 | LOP(OP_GSOCKOPT,XTERM); |
| 4728 | |
| 4729 | case KEY_getgrent: |
| 4730 | FUN0(OP_GGRENT); |
| 4731 | |
| 4732 | case KEY_getgrnam: |
| 4733 | UNI(OP_GGRNAM); |
| 4734 | |
| 4735 | case KEY_getgrgid: |
| 4736 | UNI(OP_GGRGID); |
| 4737 | |
| 4738 | case KEY_getlogin: |
| 4739 | FUN0(OP_GETLOGIN); |
| 4740 | |
| 4741 | case KEY_glob: |
| 4742 | set_csh(); |
| 4743 | LOP(OP_GLOB,XTERM); |
| 4744 | |
| 4745 | case KEY_hex: |
| 4746 | UNI(OP_HEX); |
| 4747 | |
| 4748 | case KEY_if: |
| 4749 | yylval.ival = CopLINE(PL_curcop); |
| 4750 | OPERATOR(IF); |
| 4751 | |
| 4752 | case KEY_index: |
| 4753 | LOP(OP_INDEX,XTERM); |
| 4754 | |
| 4755 | case KEY_int: |
| 4756 | UNI(OP_INT); |
| 4757 | |
| 4758 | case KEY_ioctl: |
| 4759 | LOP(OP_IOCTL,XTERM); |
| 4760 | |
| 4761 | case KEY_join: |
| 4762 | LOP(OP_JOIN,XTERM); |
| 4763 | |
| 4764 | case KEY_keys: |
| 4765 | UNI(OP_KEYS); |
| 4766 | |
| 4767 | case KEY_kill: |
| 4768 | LOP(OP_KILL,XTERM); |
| 4769 | |
| 4770 | case KEY_last: |
| 4771 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
| 4772 | LOOPX(OP_LAST); |
| 4773 | |
| 4774 | case KEY_lc: |
| 4775 | UNI(OP_LC); |
| 4776 | |
| 4777 | case KEY_lcfirst: |
| 4778 | UNI(OP_LCFIRST); |
| 4779 | |
| 4780 | case KEY_local: |
| 4781 | yylval.ival = 0; |
| 4782 | OPERATOR(LOCAL); |
| 4783 | |
| 4784 | case KEY_length: |
| 4785 | UNI(OP_LENGTH); |
| 4786 | |
| 4787 | case KEY_lt: |
| 4788 | Rop(OP_SLT); |
| 4789 | |
| 4790 | case KEY_le: |
| 4791 | Rop(OP_SLE); |
| 4792 | |
| 4793 | case KEY_localtime: |
| 4794 | UNI(OP_LOCALTIME); |
| 4795 | |
| 4796 | case KEY_log: |
| 4797 | UNI(OP_LOG); |
| 4798 | |
| 4799 | case KEY_link: |
| 4800 | LOP(OP_LINK,XTERM); |
| 4801 | |
| 4802 | case KEY_listen: |
| 4803 | LOP(OP_LISTEN,XTERM); |
| 4804 | |
| 4805 | case KEY_lock: |
| 4806 | UNI(OP_LOCK); |
| 4807 | |
| 4808 | case KEY_lstat: |
| 4809 | UNI(OP_LSTAT); |
| 4810 | |
| 4811 | case KEY_m: |
| 4812 | s = scan_pat(s,OP_MATCH); |
| 4813 | TERM(sublex_start()); |
| 4814 | |
| 4815 | case KEY_map: |
| 4816 | LOP(OP_MAPSTART, XREF); |
| 4817 | |
| 4818 | case KEY_mkdir: |
| 4819 | LOP(OP_MKDIR,XTERM); |
| 4820 | |
| 4821 | case KEY_msgctl: |
| 4822 | LOP(OP_MSGCTL,XTERM); |
| 4823 | |
| 4824 | case KEY_msgget: |
| 4825 | LOP(OP_MSGGET,XTERM); |
| 4826 | |
| 4827 | case KEY_msgrcv: |
| 4828 | LOP(OP_MSGRCV,XTERM); |
| 4829 | |
| 4830 | case KEY_msgsnd: |
| 4831 | LOP(OP_MSGSND,XTERM); |
| 4832 | |
| 4833 | case KEY_our: |
| 4834 | case KEY_my: |
| 4835 | PL_in_my = tmp; |
| 4836 | s = skipspace(s); |
| 4837 | if (isIDFIRST_lazy_if(s,UTF)) { |
| 4838 | s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len); |
| 4839 | if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3)) |
| 4840 | goto really_sub; |
| 4841 | PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len); |
| 4842 | if (!PL_in_my_stash) { |
| 4843 | char tmpbuf[1024]; |
| 4844 | PL_bufptr = s; |
| 4845 | sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf); |
| 4846 | yyerror(tmpbuf); |
| 4847 | } |
| 4848 | } |
| 4849 | yylval.ival = 1; |
| 4850 | OPERATOR(MY); |
| 4851 | |
| 4852 | case KEY_next: |
| 4853 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
| 4854 | LOOPX(OP_NEXT); |
| 4855 | |
| 4856 | case KEY_ne: |
| 4857 | Eop(OP_SNE); |
| 4858 | |
| 4859 | case KEY_no: |
| 4860 | if (PL_expect != XSTATE) |
| 4861 | yyerror("\"no\" not allowed in expression"); |
| 4862 | s = force_word(s,WORD,FALSE,TRUE,FALSE); |
| 4863 | s = force_version(s, FALSE); |
| 4864 | yylval.ival = 0; |
| 4865 | OPERATOR(USE); |
| 4866 | |
| 4867 | case KEY_not: |
| 4868 | if (*s == '(' || (s = skipspace(s), *s == '(')) |
| 4869 | FUN1(OP_NOT); |
| 4870 | else |
| 4871 | OPERATOR(NOTOP); |
| 4872 | |
| 4873 | case KEY_open: |
| 4874 | s = skipspace(s); |
| 4875 | if (isIDFIRST_lazy_if(s,UTF)) { |
| 4876 | char *t; |
| 4877 | for (d = s; isALNUM_lazy_if(d,UTF); d++) ; |
| 4878 | for (t=d; *t && isSPACE(*t); t++) ; |
| 4879 | if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE) |
| 4880 | /* [perl #16184] */ |
| 4881 | && !(t[0] == '=' && t[1] == '>') |
| 4882 | ) { |
| 4883 | Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE), |
| 4884 | "Precedence problem: open %.*s should be open(%.*s)", |
| 4885 | d - s, s, d - s, s); |
| 4886 | } |
| 4887 | } |
| 4888 | LOP(OP_OPEN,XTERM); |
| 4889 | |
| 4890 | case KEY_or: |
| 4891 | yylval.ival = OP_OR; |
| 4892 | OPERATOR(OROP); |
| 4893 | |
| 4894 | case KEY_ord: |
| 4895 | UNI(OP_ORD); |
| 4896 | |
| 4897 | case KEY_oct: |
| 4898 | UNI(OP_OCT); |
| 4899 | |
| 4900 | case KEY_opendir: |
| 4901 | LOP(OP_OPEN_DIR,XTERM); |
| 4902 | |
| 4903 | case KEY_print: |
| 4904 | checkcomma(s,PL_tokenbuf,"filehandle"); |
| 4905 | LOP(OP_PRINT,XREF); |
| 4906 | |
| 4907 | case KEY_printf: |
| 4908 | checkcomma(s,PL_tokenbuf,"filehandle"); |
| 4909 | LOP(OP_PRTF,XREF); |
| 4910 | |
| 4911 | case KEY_prototype: |
| 4912 | UNI(OP_PROTOTYPE); |
| 4913 | |
| 4914 | case KEY_push: |
| 4915 | LOP(OP_PUSH,XTERM); |
| 4916 | |
| 4917 | case KEY_pop: |
| 4918 | UNIDOR(OP_POP); |
| 4919 | |
| 4920 | case KEY_pos: |
| 4921 | UNIDOR(OP_POS); |
| 4922 | |
| 4923 | case KEY_pack: |
| 4924 | LOP(OP_PACK,XTERM); |
| 4925 | |
| 4926 | case KEY_package: |
| 4927 | s = force_word(s,WORD,FALSE,TRUE,FALSE); |
| 4928 | OPERATOR(PACKAGE); |
| 4929 | |
| 4930 | case KEY_pipe: |
| 4931 | LOP(OP_PIPE_OP,XTERM); |
| 4932 | |
| 4933 | case KEY_q: |
| 4934 | s = scan_str(s,FALSE,FALSE); |
| 4935 | if (!s) |
| 4936 | missingterm((char*)0); |
| 4937 | yylval.ival = OP_CONST; |
| 4938 | TERM(sublex_start()); |
| 4939 | |
| 4940 | case KEY_quotemeta: |
| 4941 | UNI(OP_QUOTEMETA); |
| 4942 | |
| 4943 | case KEY_qw: |
| 4944 | s = scan_str(s,FALSE,FALSE); |
| 4945 | if (!s) |
| 4946 | missingterm((char*)0); |
| 4947 | force_next(')'); |
| 4948 | if (SvCUR(PL_lex_stuff)) { |
| 4949 | OP *words = Nullop; |
| 4950 | int warned = 0; |
| 4951 | d = SvPV_force(PL_lex_stuff, len); |
| 4952 | while (len) { |
| 4953 | SV *sv; |
| 4954 | for (; isSPACE(*d) && len; --len, ++d) ; |
| 4955 | if (len) { |
| 4956 | char *b = d; |
| 4957 | if (!warned && ckWARN(WARN_QW)) { |
| 4958 | for (; !isSPACE(*d) && len; --len, ++d) { |
| 4959 | if (*d == ',') { |
| 4960 | Perl_warner(aTHX_ packWARN(WARN_QW), |
| 4961 | "Possible attempt to separate words with commas"); |
| 4962 | ++warned; |
| 4963 | } |
| 4964 | else if (*d == '#') { |
| 4965 | Perl_warner(aTHX_ packWARN(WARN_QW), |
| 4966 | "Possible attempt to put comments in qw() list"); |
| 4967 | ++warned; |
| 4968 | } |
| 4969 | } |
| 4970 | } |
| 4971 | else { |
| 4972 | for (; !isSPACE(*d) && len; --len, ++d) ; |
| 4973 | } |
| 4974 | sv = newSVpvn(b, d-b); |
| 4975 | if (DO_UTF8(PL_lex_stuff)) |
| 4976 | SvUTF8_on(sv); |
| 4977 | words = append_elem(OP_LIST, words, |
| 4978 | newSVOP(OP_CONST, 0, tokeq(sv))); |
| 4979 | } |
| 4980 | } |
| 4981 | if (words) { |
| 4982 | PL_nextval[PL_nexttoke].opval = words; |
| 4983 | force_next(THING); |
| 4984 | } |
| 4985 | } |
| 4986 | if (PL_lex_stuff) { |
| 4987 | SvREFCNT_dec(PL_lex_stuff); |
| 4988 | PL_lex_stuff = Nullsv; |
| 4989 | } |
| 4990 | PL_expect = XTERM; |
| 4991 | TOKEN('('); |
| 4992 | |
| 4993 | case KEY_qq: |
| 4994 | s = scan_str(s,FALSE,FALSE); |
| 4995 | if (!s) |
| 4996 | missingterm((char*)0); |
| 4997 | yylval.ival = OP_STRINGIFY; |
| 4998 | if (SvIVX(PL_lex_stuff) == '\'') |
| 4999 | SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */ |
| 5000 | TERM(sublex_start()); |
| 5001 | |
| 5002 | case KEY_qr: |
| 5003 | s = scan_pat(s,OP_QR); |
| 5004 | TERM(sublex_start()); |
| 5005 | |
| 5006 | case KEY_qx: |
| 5007 | s = scan_str(s,FALSE,FALSE); |
| 5008 | if (!s) |
| 5009 | missingterm((char*)0); |
| 5010 | yylval.ival = OP_BACKTICK; |
| 5011 | set_csh(); |
| 5012 | TERM(sublex_start()); |
| 5013 | |
| 5014 | case KEY_return: |
| 5015 | OLDLOP(OP_RETURN); |
| 5016 | |
| 5017 | case KEY_require: |
| 5018 | s = skipspace(s); |
| 5019 | if (isDIGIT(*s)) { |
| 5020 | s = force_version(s, FALSE); |
| 5021 | } |
| 5022 | else if (*s != 'v' || !isDIGIT(s[1]) |
| 5023 | || (s = force_version(s, TRUE), *s == 'v')) |
| 5024 | { |
| 5025 | *PL_tokenbuf = '\0'; |
| 5026 | s = force_word(s,WORD,TRUE,TRUE,FALSE); |
| 5027 | if (isIDFIRST_lazy_if(PL_tokenbuf,UTF)) |
| 5028 | gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE); |
| 5029 | else if (*s == '<') |
| 5030 | yyerror("<> should be quotes"); |
| 5031 | } |
| 5032 | UNI(OP_REQUIRE); |
| 5033 | |
| 5034 | case KEY_reset: |
| 5035 | UNI(OP_RESET); |
| 5036 | |
| 5037 | case KEY_redo: |
| 5038 | s = force_word(s,WORD,TRUE,FALSE,FALSE); |
| 5039 | LOOPX(OP_REDO); |
| 5040 | |
| 5041 | case KEY_rename: |
| 5042 | LOP(OP_RENAME,XTERM); |
| 5043 | |
| 5044 | case KEY_rand: |
| 5045 | UNI(OP_RAND); |
| 5046 | |
| 5047 | case KEY_rmdir: |
| 5048 | UNI(OP_RMDIR); |
| 5049 | |
| 5050 | case KEY_rindex: |
| 5051 | LOP(OP_RINDEX,XTERM); |
| 5052 | |
| 5053 | case KEY_read: |
| 5054 | LOP(OP_READ,XTERM); |
| 5055 | |
| 5056 | case KEY_readdir: |
| 5057 | UNI(OP_READDIR); |
| 5058 | |
| 5059 | case KEY_readline: |
| 5060 | set_csh(); |
| 5061 | UNIDOR(OP_READLINE); |
| 5062 | |
| 5063 | case KEY_readpipe: |
| 5064 | set_csh(); |
| 5065 | UNI(OP_BACKTICK); |
| 5066 | |
| 5067 | case KEY_rewinddir: |
| 5068 | UNI(OP_REWINDDIR); |
| 5069 | |
| 5070 | case KEY_recv: |
| 5071 | LOP(OP_RECV,XTERM); |
| 5072 | |
| 5073 | case KEY_reverse: |
| 5074 | LOP(OP_REVERSE,XTERM); |
| 5075 | |
| 5076 | case KEY_readlink: |
| 5077 | UNIDOR(OP_READLINK); |
| 5078 | |
| 5079 | case KEY_ref: |
| 5080 | UNI(OP_REF); |
| 5081 | |
| 5082 | case KEY_s: |
| 5083 | s = scan_subst(s); |
| 5084 | if (yylval.opval) |
| 5085 | TERM(sublex_start()); |
| 5086 | else |
| 5087 | TOKEN(1); /* force error */ |
| 5088 | |
| 5089 | case KEY_chomp: |
| 5090 | UNI(OP_CHOMP); |
| 5091 | |
| 5092 | case KEY_scalar: |
| 5093 | UNI(OP_SCALAR); |
| 5094 | |
| 5095 | case KEY_select: |
| 5096 | LOP(OP_SELECT,XTERM); |
| 5097 | |
| 5098 | case KEY_seek: |
| 5099 | LOP(OP_SEEK,XTERM); |
| 5100 | |
| 5101 | case KEY_semctl: |
| 5102 | LOP(OP_SEMCTL,XTERM); |
| 5103 | |
| 5104 | case KEY_semget: |
| 5105 | LOP(OP_SEMGET,XTERM); |
| 5106 | |
| 5107 | case KEY_semop: |
| 5108 | LOP(OP_SEMOP,XTERM); |
| 5109 | |
| 5110 | case KEY_send: |
| 5111 | LOP(OP_SEND,XTERM); |
| 5112 | |
| 5113 | case KEY_setpgrp: |
| 5114 | LOP(OP_SETPGRP,XTERM); |
| 5115 | |
| 5116 | case KEY_setpriority: |
| 5117 | LOP(OP_SETPRIORITY,XTERM); |
| 5118 | |
| 5119 | case KEY_sethostent: |
| 5120 | UNI(OP_SHOSTENT); |
| 5121 | |
| 5122 | case KEY_setnetent: |
| 5123 | UNI(OP_SNETENT); |
| 5124 | |
| 5125 | case KEY_setservent: |
| 5126 | UNI(OP_SSERVENT); |
| 5127 | |
| 5128 | case KEY_setprotoent: |
| 5129 | UNI(OP_SPROTOENT); |
| 5130 | |
| 5131 | case KEY_setpwent: |
| 5132 | FUN0(OP_SPWENT); |
| 5133 | |
| 5134 | case KEY_setgrent: |
| 5135 | FUN0(OP_SGRENT); |
| 5136 | |
| 5137 | case KEY_seekdir: |
| 5138 | LOP(OP_SEEKDIR,XTERM); |
| 5139 | |
| 5140 | case KEY_setsockopt: |
| 5141 | LOP(OP_SSOCKOPT,XTERM); |
| 5142 | |
| 5143 | case KEY_shift: |
| 5144 | UNIDOR(OP_SHIFT); |
| 5145 | |
| 5146 | case KEY_shmctl: |
| 5147 | LOP(OP_SHMCTL,XTERM); |
| 5148 | |
| 5149 | case KEY_shmget: |
| 5150 | LOP(OP_SHMGET,XTERM); |
| 5151 | |
| 5152 | case KEY_shmread: |
| 5153 | LOP(OP_SHMREAD,XTERM); |
| 5154 | |
| 5155 | case KEY_shmwrite: |
| 5156 | LOP(OP_SHMWRITE,XTERM); |
| 5157 | |
| 5158 | case KEY_shutdown: |
| 5159 | LOP(OP_SHUTDOWN,XTERM); |
| 5160 | |
| 5161 | case KEY_sin: |
| 5162 | UNI(OP_SIN); |
| 5163 | |
| 5164 | case KEY_sleep: |
| 5165 | UNI(OP_SLEEP); |
| 5166 | |
| 5167 | case KEY_socket: |
| 5168 | LOP(OP_SOCKET,XTERM); |
| 5169 | |
| 5170 | case KEY_socketpair: |
| 5171 | LOP(OP_SOCKPAIR,XTERM); |
| 5172 | |
| 5173 | case KEY_sort: |
| 5174 | checkcomma(s,PL_tokenbuf,"subroutine name"); |
| 5175 | s = skipspace(s); |
| 5176 | if (*s == ';' || *s == ')') /* probably a close */ |
| 5177 | Perl_croak(aTHX_ "sort is now a reserved word"); |
| 5178 | PL_expect = XTERM; |
| 5179 | s = force_word(s,WORD,TRUE,TRUE,FALSE); |
| 5180 | LOP(OP_SORT,XREF); |
| 5181 | |
| 5182 | case KEY_split: |
| 5183 | LOP(OP_SPLIT,XTERM); |
| 5184 | |
| 5185 | case KEY_sprintf: |
| 5186 | LOP(OP_SPRINTF,XTERM); |
| 5187 | |
| 5188 | case KEY_splice: |
| 5189 | LOP(OP_SPLICE,XTERM); |
| 5190 | |
| 5191 | case KEY_sqrt: |
| 5192 | UNI(OP_SQRT); |
| 5193 | |
| 5194 | case KEY_srand: |
| 5195 | UNI(OP_SRAND); |
| 5196 | |
| 5197 | case KEY_stat: |
| 5198 | UNI(OP_STAT); |
| 5199 | |
| 5200 | case KEY_study: |
| 5201 | UNI(OP_STUDY); |
| 5202 | |
| 5203 | case KEY_substr: |
| 5204 | LOP(OP_SUBSTR,XTERM); |
| 5205 | |
| 5206 | case KEY_format: |
| 5207 | case KEY_sub: |
| 5208 | really_sub: |
| 5209 | { |
| 5210 | char tmpbuf[sizeof PL_tokenbuf]; |
| 5211 | SSize_t tboffset = 0; |
| 5212 | expectation attrful; |
| 5213 | bool have_name, have_proto, bad_proto; |
| 5214 | int key = tmp; |
| 5215 | |
| 5216 | s = skipspace(s); |
| 5217 | |
| 5218 | if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' || |
| 5219 | (*s == ':' && s[1] == ':')) |
| 5220 | { |
| 5221 | PL_expect = XBLOCK; |
| 5222 | attrful = XATTRBLOCK; |
| 5223 | /* remember buffer pos'n for later force_word */ |
| 5224 | tboffset = s - PL_oldbufptr; |
| 5225 | d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len); |
| 5226 | if (strchr(tmpbuf, ':')) |
| 5227 | sv_setpv(PL_subname, tmpbuf); |
| 5228 | else { |
| 5229 | sv_setsv(PL_subname,PL_curstname); |
| 5230 | sv_catpvn(PL_subname,"::",2); |
| 5231 | sv_catpvn(PL_subname,tmpbuf,len); |
| 5232 | } |
| 5233 | s = skipspace(d); |
| 5234 | have_name = TRUE; |
| 5235 | } |
| 5236 | else { |
| 5237 | if (key == KEY_my) |
| 5238 | Perl_croak(aTHX_ "Missing name in \"my sub\""); |
| 5239 | PL_expect = XTERMBLOCK; |
| 5240 | attrful = XATTRTERM; |
| 5241 | sv_setpv(PL_subname,"?"); |
| 5242 | have_name = FALSE; |
| 5243 | } |
| 5244 | |
| 5245 | if (key == KEY_format) { |
| 5246 | if (*s == '=') |
| 5247 | PL_lex_formbrack = PL_lex_brackets + 1; |
| 5248 | if (have_name) |
| 5249 | (void) force_word(PL_oldbufptr + tboffset, WORD, |
| 5250 | FALSE, TRUE, TRUE); |
| 5251 | OPERATOR(FORMAT); |
| 5252 | } |
| 5253 | |
| 5254 | /* Look for a prototype */ |
| 5255 | if (*s == '(') { |
| 5256 | char *p; |
| 5257 | |
| 5258 | s = scan_str(s,FALSE,FALSE); |
| 5259 | if (!s) |
| 5260 | Perl_croak(aTHX_ "Prototype not terminated"); |
| 5261 | /* strip spaces and check for bad characters */ |
| 5262 | d = SvPVX(PL_lex_stuff); |
| 5263 | tmp = 0; |
| 5264 | bad_proto = FALSE; |
| 5265 | for (p = d; *p; ++p) { |
| 5266 | if (!isSPACE(*p)) { |
| 5267 | d[tmp++] = *p; |
| 5268 | if (!strchr("$@%*;[]&\\", *p)) |
| 5269 | bad_proto = TRUE; |
| 5270 | } |
| 5271 | } |
| 5272 | d[tmp] = '\0'; |
| 5273 | if (bad_proto && ckWARN(WARN_SYNTAX)) |
| 5274 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 5275 | "Illegal character in prototype for %"SVf" : %s", |
| 5276 | PL_subname, d); |
| 5277 | SvCUR_set(PL_lex_stuff, tmp); |
| 5278 | have_proto = TRUE; |
| 5279 | |
| 5280 | s = skipspace(s); |
| 5281 | } |
| 5282 | else |
| 5283 | have_proto = FALSE; |
| 5284 | |
| 5285 | if (*s == ':' && s[1] != ':') |
| 5286 | PL_expect = attrful; |
| 5287 | else if (*s != '{' && key == KEY_sub) { |
| 5288 | if (!have_name) |
| 5289 | Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine"); |
| 5290 | else if (*s != ';') |
| 5291 | Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname); |
| 5292 | } |
| 5293 | |
| 5294 | if (have_proto) { |
| 5295 | PL_nextval[PL_nexttoke].opval = |
| 5296 | (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff); |
| 5297 | PL_lex_stuff = Nullsv; |
| 5298 | force_next(THING); |
| 5299 | } |
| 5300 | if (!have_name) { |
| 5301 | sv_setpv(PL_subname, |
| 5302 | PL_curstash ? "__ANON__" : "__ANON__::__ANON__"); |
| 5303 | TOKEN(ANONSUB); |
| 5304 | } |
| 5305 | (void) force_word(PL_oldbufptr + tboffset, WORD, |
| 5306 | FALSE, TRUE, TRUE); |
| 5307 | if (key == KEY_my) |
| 5308 | TOKEN(MYSUB); |
| 5309 | TOKEN(SUB); |
| 5310 | } |
| 5311 | |
| 5312 | case KEY_system: |
| 5313 | set_csh(); |
| 5314 | LOP(OP_SYSTEM,XREF); |
| 5315 | |
| 5316 | case KEY_symlink: |
| 5317 | LOP(OP_SYMLINK,XTERM); |
| 5318 | |
| 5319 | case KEY_syscall: |
| 5320 | LOP(OP_SYSCALL,XTERM); |
| 5321 | |
| 5322 | case KEY_sysopen: |
| 5323 | LOP(OP_SYSOPEN,XTERM); |
| 5324 | |
| 5325 | case KEY_sysseek: |
| 5326 | LOP(OP_SYSSEEK,XTERM); |
| 5327 | |
| 5328 | case KEY_sysread: |
| 5329 | LOP(OP_SYSREAD,XTERM); |
| 5330 | |
| 5331 | case KEY_syswrite: |
| 5332 | LOP(OP_SYSWRITE,XTERM); |
| 5333 | |
| 5334 | case KEY_tr: |
| 5335 | s = scan_trans(s); |
| 5336 | TERM(sublex_start()); |
| 5337 | |
| 5338 | case KEY_tell: |
| 5339 | UNI(OP_TELL); |
| 5340 | |
| 5341 | case KEY_telldir: |
| 5342 | UNI(OP_TELLDIR); |
| 5343 | |
| 5344 | case KEY_tie: |
| 5345 | LOP(OP_TIE,XTERM); |
| 5346 | |
| 5347 | case KEY_tied: |
| 5348 | UNI(OP_TIED); |
| 5349 | |
| 5350 | case KEY_time: |
| 5351 | FUN0(OP_TIME); |
| 5352 | |
| 5353 | case KEY_times: |
| 5354 | FUN0(OP_TMS); |
| 5355 | |
| 5356 | case KEY_truncate: |
| 5357 | LOP(OP_TRUNCATE,XTERM); |
| 5358 | |
| 5359 | case KEY_uc: |
| 5360 | UNI(OP_UC); |
| 5361 | |
| 5362 | case KEY_ucfirst: |
| 5363 | UNI(OP_UCFIRST); |
| 5364 | |
| 5365 | case KEY_untie: |
| 5366 | UNI(OP_UNTIE); |
| 5367 | |
| 5368 | case KEY_until: |
| 5369 | yylval.ival = CopLINE(PL_curcop); |
| 5370 | OPERATOR(UNTIL); |
| 5371 | |
| 5372 | case KEY_unless: |
| 5373 | yylval.ival = CopLINE(PL_curcop); |
| 5374 | OPERATOR(UNLESS); |
| 5375 | |
| 5376 | case KEY_unlink: |
| 5377 | LOP(OP_UNLINK,XTERM); |
| 5378 | |
| 5379 | case KEY_undef: |
| 5380 | UNIDOR(OP_UNDEF); |
| 5381 | |
| 5382 | case KEY_unpack: |
| 5383 | LOP(OP_UNPACK,XTERM); |
| 5384 | |
| 5385 | case KEY_utime: |
| 5386 | LOP(OP_UTIME,XTERM); |
| 5387 | |
| 5388 | case KEY_umask: |
| 5389 | UNIDOR(OP_UMASK); |
| 5390 | |
| 5391 | case KEY_unshift: |
| 5392 | LOP(OP_UNSHIFT,XTERM); |
| 5393 | |
| 5394 | case KEY_use: |
| 5395 | if (PL_expect != XSTATE) |
| 5396 | yyerror("\"use\" not allowed in expression"); |
| 5397 | s = skipspace(s); |
| 5398 | if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) { |
| 5399 | s = force_version(s, TRUE); |
| 5400 | if (*s == ';' || (s = skipspace(s), *s == ';')) { |
| 5401 | PL_nextval[PL_nexttoke].opval = Nullop; |
| 5402 | force_next(WORD); |
| 5403 | } |
| 5404 | else if (*s == 'v') { |
| 5405 | s = force_word(s,WORD,FALSE,TRUE,FALSE); |
| 5406 | s = force_version(s, FALSE); |
| 5407 | } |
| 5408 | } |
| 5409 | else { |
| 5410 | s = force_word(s,WORD,FALSE,TRUE,FALSE); |
| 5411 | s = force_version(s, FALSE); |
| 5412 | } |
| 5413 | yylval.ival = 1; |
| 5414 | OPERATOR(USE); |
| 5415 | |
| 5416 | case KEY_values: |
| 5417 | UNI(OP_VALUES); |
| 5418 | |
| 5419 | case KEY_vec: |
| 5420 | LOP(OP_VEC,XTERM); |
| 5421 | |
| 5422 | case KEY_while: |
| 5423 | yylval.ival = CopLINE(PL_curcop); |
| 5424 | OPERATOR(WHILE); |
| 5425 | |
| 5426 | case KEY_warn: |
| 5427 | PL_hints |= HINT_BLOCK_SCOPE; |
| 5428 | LOP(OP_WARN,XTERM); |
| 5429 | |
| 5430 | case KEY_wait: |
| 5431 | FUN0(OP_WAIT); |
| 5432 | |
| 5433 | case KEY_waitpid: |
| 5434 | LOP(OP_WAITPID,XTERM); |
| 5435 | |
| 5436 | case KEY_wantarray: |
| 5437 | FUN0(OP_WANTARRAY); |
| 5438 | |
| 5439 | case KEY_write: |
| 5440 | #ifdef EBCDIC |
| 5441 | { |
| 5442 | char ctl_l[2]; |
| 5443 | ctl_l[0] = toCTRL('L'); |
| 5444 | ctl_l[1] = '\0'; |
| 5445 | gv_fetchpv(ctl_l,TRUE, SVt_PV); |
| 5446 | } |
| 5447 | #else |
| 5448 | gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */ |
| 5449 | #endif |
| 5450 | UNI(OP_ENTERWRITE); |
| 5451 | |
| 5452 | case KEY_x: |
| 5453 | if (PL_expect == XOPERATOR) |
| 5454 | Mop(OP_REPEAT); |
| 5455 | check_uni(); |
| 5456 | goto just_a_word; |
| 5457 | |
| 5458 | case KEY_xor: |
| 5459 | yylval.ival = OP_XOR; |
| 5460 | OPERATOR(OROP); |
| 5461 | |
| 5462 | case KEY_y: |
| 5463 | s = scan_trans(s); |
| 5464 | TERM(sublex_start()); |
| 5465 | } |
| 5466 | }} |
| 5467 | } |
| 5468 | #ifdef __SC__ |
| 5469 | #pragma segment Main |
| 5470 | #endif |
| 5471 | |
| 5472 | static int |
| 5473 | S_pending_ident(pTHX) |
| 5474 | { |
| 5475 | register char *d; |
| 5476 | register I32 tmp = 0; |
| 5477 | /* pit holds the identifier we read and pending_ident is reset */ |
| 5478 | char pit = PL_pending_ident; |
| 5479 | PL_pending_ident = 0; |
| 5480 | |
| 5481 | DEBUG_T({ PerlIO_printf(Perl_debug_log, |
| 5482 | "### Tokener saw identifier '%s'\n", PL_tokenbuf); }); |
| 5483 | |
| 5484 | /* if we're in a my(), we can't allow dynamics here. |
| 5485 | $foo'bar has already been turned into $foo::bar, so |
| 5486 | just check for colons. |
| 5487 | |
| 5488 | if it's a legal name, the OP is a PADANY. |
| 5489 | */ |
| 5490 | if (PL_in_my) { |
| 5491 | if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */ |
| 5492 | if (strchr(PL_tokenbuf,':')) |
| 5493 | yyerror(Perl_form(aTHX_ "No package name allowed for " |
| 5494 | "variable %s in \"our\"", |
| 5495 | PL_tokenbuf)); |
| 5496 | tmp = allocmy(PL_tokenbuf); |
| 5497 | } |
| 5498 | else { |
| 5499 | if (strchr(PL_tokenbuf,':')) |
| 5500 | yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf)); |
| 5501 | |
| 5502 | yylval.opval = newOP(OP_PADANY, 0); |
| 5503 | yylval.opval->op_targ = allocmy(PL_tokenbuf); |
| 5504 | return PRIVATEREF; |
| 5505 | } |
| 5506 | } |
| 5507 | |
| 5508 | /* |
| 5509 | build the ops for accesses to a my() variable. |
| 5510 | |
| 5511 | Deny my($a) or my($b) in a sort block, *if* $a or $b is |
| 5512 | then used in a comparison. This catches most, but not |
| 5513 | all cases. For instance, it catches |
| 5514 | sort { my($a); $a <=> $b } |
| 5515 | but not |
| 5516 | sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; } |
| 5517 | (although why you'd do that is anyone's guess). |
| 5518 | */ |
| 5519 | |
| 5520 | if (!strchr(PL_tokenbuf,':')) { |
| 5521 | if (!PL_in_my) |
| 5522 | tmp = pad_findmy(PL_tokenbuf); |
| 5523 | if (tmp != NOT_IN_PAD) { |
| 5524 | /* might be an "our" variable" */ |
| 5525 | if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) { |
| 5526 | /* build ops for a bareword */ |
| 5527 | SV *sym = newSVpv(HvNAME(PAD_COMPNAME_OURSTASH(tmp)), 0); |
| 5528 | sv_catpvn(sym, "::", 2); |
| 5529 | sv_catpv(sym, PL_tokenbuf+1); |
| 5530 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym); |
| 5531 | yylval.opval->op_private = OPpCONST_ENTERED; |
| 5532 | gv_fetchsv(sym, |
| 5533 | (PL_in_eval |
| 5534 | ? (GV_ADDMULTI | GV_ADDINEVAL) |
| 5535 | : GV_ADDMULTI |
| 5536 | ), |
| 5537 | ((PL_tokenbuf[0] == '$') ? SVt_PV |
| 5538 | : (PL_tokenbuf[0] == '@') ? SVt_PVAV |
| 5539 | : SVt_PVHV)); |
| 5540 | return WORD; |
| 5541 | } |
| 5542 | |
| 5543 | /* if it's a sort block and they're naming $a or $b */ |
| 5544 | if (PL_last_lop_op == OP_SORT && |
| 5545 | PL_tokenbuf[0] == '$' && |
| 5546 | (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b') |
| 5547 | && !PL_tokenbuf[2]) |
| 5548 | { |
| 5549 | for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart; |
| 5550 | d < PL_bufend && *d != '\n'; |
| 5551 | d++) |
| 5552 | { |
| 5553 | if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) { |
| 5554 | Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison", |
| 5555 | PL_tokenbuf); |
| 5556 | } |
| 5557 | } |
| 5558 | } |
| 5559 | |
| 5560 | yylval.opval = newOP(OP_PADANY, 0); |
| 5561 | yylval.opval->op_targ = tmp; |
| 5562 | return PRIVATEREF; |
| 5563 | } |
| 5564 | } |
| 5565 | |
| 5566 | /* |
| 5567 | Whine if they've said @foo in a doublequoted string, |
| 5568 | and @foo isn't a variable we can find in the symbol |
| 5569 | table. |
| 5570 | */ |
| 5571 | if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) { |
| 5572 | GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV); |
| 5573 | if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv))) |
| 5574 | && ckWARN(WARN_AMBIGUOUS)) |
| 5575 | { |
| 5576 | /* Downgraded from fatal to warning 20000522 mjd */ |
| 5577 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 5578 | "Possible unintended interpolation of %s in string", |
| 5579 | PL_tokenbuf); |
| 5580 | } |
| 5581 | } |
| 5582 | |
| 5583 | /* build ops for a bareword */ |
| 5584 | yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0)); |
| 5585 | yylval.opval->op_private = OPpCONST_ENTERED; |
| 5586 | gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE, |
| 5587 | ((PL_tokenbuf[0] == '$') ? SVt_PV |
| 5588 | : (PL_tokenbuf[0] == '@') ? SVt_PVAV |
| 5589 | : SVt_PVHV)); |
| 5590 | return WORD; |
| 5591 | } |
| 5592 | |
| 5593 | /* |
| 5594 | * The following code was generated by perl_keyword.pl. |
| 5595 | */ |
| 5596 | |
| 5597 | I32 |
| 5598 | Perl_keyword (pTHX_ char *name, I32 len) |
| 5599 | { |
| 5600 | switch (len) |
| 5601 | { |
| 5602 | case 1: /* 5 tokens of length 1 */ |
| 5603 | switch (name[0]) |
| 5604 | { |
| 5605 | case 'm': |
| 5606 | { /* m */ |
| 5607 | return KEY_m; |
| 5608 | } |
| 5609 | |
| 5610 | case 'q': |
| 5611 | { /* q */ |
| 5612 | return KEY_q; |
| 5613 | } |
| 5614 | |
| 5615 | case 's': |
| 5616 | { /* s */ |
| 5617 | return KEY_s; |
| 5618 | } |
| 5619 | |
| 5620 | case 'x': |
| 5621 | { /* x */ |
| 5622 | return -KEY_x; |
| 5623 | } |
| 5624 | |
| 5625 | case 'y': |
| 5626 | { /* y */ |
| 5627 | return KEY_y; |
| 5628 | } |
| 5629 | |
| 5630 | default: |
| 5631 | goto unknown; |
| 5632 | } |
| 5633 | |
| 5634 | case 2: /* 18 tokens of length 2 */ |
| 5635 | switch (name[0]) |
| 5636 | { |
| 5637 | case 'd': |
| 5638 | if (name[1] == 'o') |
| 5639 | { /* do */ |
| 5640 | return KEY_do; |
| 5641 | } |
| 5642 | |
| 5643 | goto unknown; |
| 5644 | |
| 5645 | case 'e': |
| 5646 | if (name[1] == 'q') |
| 5647 | { /* eq */ |
| 5648 | return -KEY_eq; |
| 5649 | } |
| 5650 | |
| 5651 | goto unknown; |
| 5652 | |
| 5653 | case 'g': |
| 5654 | switch (name[1]) |
| 5655 | { |
| 5656 | case 'e': |
| 5657 | { /* ge */ |
| 5658 | return -KEY_ge; |
| 5659 | } |
| 5660 | |
| 5661 | case 't': |
| 5662 | { /* gt */ |
| 5663 | return -KEY_gt; |
| 5664 | } |
| 5665 | |
| 5666 | default: |
| 5667 | goto unknown; |
| 5668 | } |
| 5669 | |
| 5670 | case 'i': |
| 5671 | if (name[1] == 'f') |
| 5672 | { /* if */ |
| 5673 | return KEY_if; |
| 5674 | } |
| 5675 | |
| 5676 | goto unknown; |
| 5677 | |
| 5678 | case 'l': |
| 5679 | switch (name[1]) |
| 5680 | { |
| 5681 | case 'c': |
| 5682 | { /* lc */ |
| 5683 | return -KEY_lc; |
| 5684 | } |
| 5685 | |
| 5686 | case 'e': |
| 5687 | { /* le */ |
| 5688 | return -KEY_le; |
| 5689 | } |
| 5690 | |
| 5691 | case 't': |
| 5692 | { /* lt */ |
| 5693 | return -KEY_lt; |
| 5694 | } |
| 5695 | |
| 5696 | default: |
| 5697 | goto unknown; |
| 5698 | } |
| 5699 | |
| 5700 | case 'm': |
| 5701 | if (name[1] == 'y') |
| 5702 | { /* my */ |
| 5703 | return KEY_my; |
| 5704 | } |
| 5705 | |
| 5706 | goto unknown; |
| 5707 | |
| 5708 | case 'n': |
| 5709 | switch (name[1]) |
| 5710 | { |
| 5711 | case 'e': |
| 5712 | { /* ne */ |
| 5713 | return -KEY_ne; |
| 5714 | } |
| 5715 | |
| 5716 | case 'o': |
| 5717 | { /* no */ |
| 5718 | return KEY_no; |
| 5719 | } |
| 5720 | |
| 5721 | default: |
| 5722 | goto unknown; |
| 5723 | } |
| 5724 | |
| 5725 | case 'o': |
| 5726 | if (name[1] == 'r') |
| 5727 | { /* or */ |
| 5728 | return -KEY_or; |
| 5729 | } |
| 5730 | |
| 5731 | goto unknown; |
| 5732 | |
| 5733 | case 'q': |
| 5734 | switch (name[1]) |
| 5735 | { |
| 5736 | case 'q': |
| 5737 | { /* qq */ |
| 5738 | return KEY_qq; |
| 5739 | } |
| 5740 | |
| 5741 | case 'r': |
| 5742 | { /* qr */ |
| 5743 | return KEY_qr; |
| 5744 | } |
| 5745 | |
| 5746 | case 'w': |
| 5747 | { /* qw */ |
| 5748 | return KEY_qw; |
| 5749 | } |
| 5750 | |
| 5751 | case 'x': |
| 5752 | { /* qx */ |
| 5753 | return KEY_qx; |
| 5754 | } |
| 5755 | |
| 5756 | default: |
| 5757 | goto unknown; |
| 5758 | } |
| 5759 | |
| 5760 | case 't': |
| 5761 | if (name[1] == 'r') |
| 5762 | { /* tr */ |
| 5763 | return KEY_tr; |
| 5764 | } |
| 5765 | |
| 5766 | goto unknown; |
| 5767 | |
| 5768 | case 'u': |
| 5769 | if (name[1] == 'c') |
| 5770 | { /* uc */ |
| 5771 | return -KEY_uc; |
| 5772 | } |
| 5773 | |
| 5774 | goto unknown; |
| 5775 | |
| 5776 | default: |
| 5777 | goto unknown; |
| 5778 | } |
| 5779 | |
| 5780 | case 3: /* 28 tokens of length 3 */ |
| 5781 | switch (name[0]) |
| 5782 | { |
| 5783 | case 'E': |
| 5784 | if (name[1] == 'N' && |
| 5785 | name[2] == 'D') |
| 5786 | { /* END */ |
| 5787 | return KEY_END; |
| 5788 | } |
| 5789 | |
| 5790 | goto unknown; |
| 5791 | |
| 5792 | case 'a': |
| 5793 | switch (name[1]) |
| 5794 | { |
| 5795 | case 'b': |
| 5796 | if (name[2] == 's') |
| 5797 | { /* abs */ |
| 5798 | return -KEY_abs; |
| 5799 | } |
| 5800 | |
| 5801 | goto unknown; |
| 5802 | |
| 5803 | case 'n': |
| 5804 | if (name[2] == 'd') |
| 5805 | { /* and */ |
| 5806 | return -KEY_and; |
| 5807 | } |
| 5808 | |
| 5809 | goto unknown; |
| 5810 | |
| 5811 | default: |
| 5812 | goto unknown; |
| 5813 | } |
| 5814 | |
| 5815 | case 'c': |
| 5816 | switch (name[1]) |
| 5817 | { |
| 5818 | case 'h': |
| 5819 | if (name[2] == 'r') |
| 5820 | { /* chr */ |
| 5821 | return -KEY_chr; |
| 5822 | } |
| 5823 | |
| 5824 | goto unknown; |
| 5825 | |
| 5826 | case 'm': |
| 5827 | if (name[2] == 'p') |
| 5828 | { /* cmp */ |
| 5829 | return -KEY_cmp; |
| 5830 | } |
| 5831 | |
| 5832 | goto unknown; |
| 5833 | |
| 5834 | case 'o': |
| 5835 | if (name[2] == 's') |
| 5836 | { /* cos */ |
| 5837 | return -KEY_cos; |
| 5838 | } |
| 5839 | |
| 5840 | goto unknown; |
| 5841 | |
| 5842 | default: |
| 5843 | goto unknown; |
| 5844 | } |
| 5845 | |
| 5846 | case 'd': |
| 5847 | if (name[1] == 'i' && |
| 5848 | name[2] == 'e') |
| 5849 | { /* die */ |
| 5850 | return -KEY_die; |
| 5851 | } |
| 5852 | |
| 5853 | goto unknown; |
| 5854 | |
| 5855 | case 'e': |
| 5856 | switch (name[1]) |
| 5857 | { |
| 5858 | case 'o': |
| 5859 | if (name[2] == 'f') |
| 5860 | { /* eof */ |
| 5861 | return -KEY_eof; |
| 5862 | } |
| 5863 | |
| 5864 | goto unknown; |
| 5865 | |
| 5866 | case 'r': |
| 5867 | if (name[2] == 'r') |
| 5868 | { /* err */ |
| 5869 | return -KEY_err; |
| 5870 | } |
| 5871 | |
| 5872 | goto unknown; |
| 5873 | |
| 5874 | case 'x': |
| 5875 | if (name[2] == 'p') |
| 5876 | { /* exp */ |
| 5877 | return -KEY_exp; |
| 5878 | } |
| 5879 | |
| 5880 | goto unknown; |
| 5881 | |
| 5882 | default: |
| 5883 | goto unknown; |
| 5884 | } |
| 5885 | |
| 5886 | case 'f': |
| 5887 | if (name[1] == 'o' && |
| 5888 | name[2] == 'r') |
| 5889 | { /* for */ |
| 5890 | return KEY_for; |
| 5891 | } |
| 5892 | |
| 5893 | goto unknown; |
| 5894 | |
| 5895 | case 'h': |
| 5896 | if (name[1] == 'e' && |
| 5897 | name[2] == 'x') |
| 5898 | { /* hex */ |
| 5899 | return -KEY_hex; |
| 5900 | } |
| 5901 | |
| 5902 | goto unknown; |
| 5903 | |
| 5904 | case 'i': |
| 5905 | if (name[1] == 'n' && |
| 5906 | name[2] == 't') |
| 5907 | { /* int */ |
| 5908 | return -KEY_int; |
| 5909 | } |
| 5910 | |
| 5911 | goto unknown; |
| 5912 | |
| 5913 | case 'l': |
| 5914 | if (name[1] == 'o' && |
| 5915 | name[2] == 'g') |
| 5916 | { /* log */ |
| 5917 | return -KEY_log; |
| 5918 | } |
| 5919 | |
| 5920 | goto unknown; |
| 5921 | |
| 5922 | case 'm': |
| 5923 | if (name[1] == 'a' && |
| 5924 | name[2] == 'p') |
| 5925 | { /* map */ |
| 5926 | return KEY_map; |
| 5927 | } |
| 5928 | |
| 5929 | goto unknown; |
| 5930 | |
| 5931 | case 'n': |
| 5932 | if (name[1] == 'o' && |
| 5933 | name[2] == 't') |
| 5934 | { /* not */ |
| 5935 | return -KEY_not; |
| 5936 | } |
| 5937 | |
| 5938 | goto unknown; |
| 5939 | |
| 5940 | case 'o': |
| 5941 | switch (name[1]) |
| 5942 | { |
| 5943 | case 'c': |
| 5944 | if (name[2] == 't') |
| 5945 | { /* oct */ |
| 5946 | return -KEY_oct; |
| 5947 | } |
| 5948 | |
| 5949 | goto unknown; |
| 5950 | |
| 5951 | case 'r': |
| 5952 | if (name[2] == 'd') |
| 5953 | { /* ord */ |
| 5954 | return -KEY_ord; |
| 5955 | } |
| 5956 | |
| 5957 | goto unknown; |
| 5958 | |
| 5959 | case 'u': |
| 5960 | if (name[2] == 'r') |
| 5961 | { /* our */ |
| 5962 | return KEY_our; |
| 5963 | } |
| 5964 | |
| 5965 | goto unknown; |
| 5966 | |
| 5967 | default: |
| 5968 | goto unknown; |
| 5969 | } |
| 5970 | |
| 5971 | case 'p': |
| 5972 | if (name[1] == 'o') |
| 5973 | { |
| 5974 | switch (name[2]) |
| 5975 | { |
| 5976 | case 'p': |
| 5977 | { /* pop */ |
| 5978 | return -KEY_pop; |
| 5979 | } |
| 5980 | |
| 5981 | case 's': |
| 5982 | { /* pos */ |
| 5983 | return KEY_pos; |
| 5984 | } |
| 5985 | |
| 5986 | default: |
| 5987 | goto unknown; |
| 5988 | } |
| 5989 | } |
| 5990 | |
| 5991 | goto unknown; |
| 5992 | |
| 5993 | case 'r': |
| 5994 | if (name[1] == 'e' && |
| 5995 | name[2] == 'f') |
| 5996 | { /* ref */ |
| 5997 | return -KEY_ref; |
| 5998 | } |
| 5999 | |
| 6000 | goto unknown; |
| 6001 | |
| 6002 | case 's': |
| 6003 | switch (name[1]) |
| 6004 | { |
| 6005 | case 'i': |
| 6006 | if (name[2] == 'n') |
| 6007 | { /* sin */ |
| 6008 | return -KEY_sin; |
| 6009 | } |
| 6010 | |
| 6011 | goto unknown; |
| 6012 | |
| 6013 | case 'u': |
| 6014 | if (name[2] == 'b') |
| 6015 | { /* sub */ |
| 6016 | return KEY_sub; |
| 6017 | } |
| 6018 | |
| 6019 | goto unknown; |
| 6020 | |
| 6021 | default: |
| 6022 | goto unknown; |
| 6023 | } |
| 6024 | |
| 6025 | case 't': |
| 6026 | if (name[1] == 'i' && |
| 6027 | name[2] == 'e') |
| 6028 | { /* tie */ |
| 6029 | return KEY_tie; |
| 6030 | } |
| 6031 | |
| 6032 | goto unknown; |
| 6033 | |
| 6034 | case 'u': |
| 6035 | if (name[1] == 's' && |
| 6036 | name[2] == 'e') |
| 6037 | { /* use */ |
| 6038 | return KEY_use; |
| 6039 | } |
| 6040 | |
| 6041 | goto unknown; |
| 6042 | |
| 6043 | case 'v': |
| 6044 | if (name[1] == 'e' && |
| 6045 | name[2] == 'c') |
| 6046 | { /* vec */ |
| 6047 | return -KEY_vec; |
| 6048 | } |
| 6049 | |
| 6050 | goto unknown; |
| 6051 | |
| 6052 | case 'x': |
| 6053 | if (name[1] == 'o' && |
| 6054 | name[2] == 'r') |
| 6055 | { /* xor */ |
| 6056 | return -KEY_xor; |
| 6057 | } |
| 6058 | |
| 6059 | goto unknown; |
| 6060 | |
| 6061 | default: |
| 6062 | goto unknown; |
| 6063 | } |
| 6064 | |
| 6065 | case 4: /* 40 tokens of length 4 */ |
| 6066 | switch (name[0]) |
| 6067 | { |
| 6068 | case 'C': |
| 6069 | if (name[1] == 'O' && |
| 6070 | name[2] == 'R' && |
| 6071 | name[3] == 'E') |
| 6072 | { /* CORE */ |
| 6073 | return -KEY_CORE; |
| 6074 | } |
| 6075 | |
| 6076 | goto unknown; |
| 6077 | |
| 6078 | case 'I': |
| 6079 | if (name[1] == 'N' && |
| 6080 | name[2] == 'I' && |
| 6081 | name[3] == 'T') |
| 6082 | { /* INIT */ |
| 6083 | return KEY_INIT; |
| 6084 | } |
| 6085 | |
| 6086 | goto unknown; |
| 6087 | |
| 6088 | case 'b': |
| 6089 | if (name[1] == 'i' && |
| 6090 | name[2] == 'n' && |
| 6091 | name[3] == 'd') |
| 6092 | { /* bind */ |
| 6093 | return -KEY_bind; |
| 6094 | } |
| 6095 | |
| 6096 | goto unknown; |
| 6097 | |
| 6098 | case 'c': |
| 6099 | if (name[1] == 'h' && |
| 6100 | name[2] == 'o' && |
| 6101 | name[3] == 'p') |
| 6102 | { /* chop */ |
| 6103 | return -KEY_chop; |
| 6104 | } |
| 6105 | |
| 6106 | goto unknown; |
| 6107 | |
| 6108 | case 'd': |
| 6109 | if (name[1] == 'u' && |
| 6110 | name[2] == 'm' && |
| 6111 | name[3] == 'p') |
| 6112 | { /* dump */ |
| 6113 | return -KEY_dump; |
| 6114 | } |
| 6115 | |
| 6116 | goto unknown; |
| 6117 | |
| 6118 | case 'e': |
| 6119 | switch (name[1]) |
| 6120 | { |
| 6121 | case 'a': |
| 6122 | if (name[2] == 'c' && |
| 6123 | name[3] == 'h') |
| 6124 | { /* each */ |
| 6125 | return -KEY_each; |
| 6126 | } |
| 6127 | |
| 6128 | goto unknown; |
| 6129 | |
| 6130 | case 'l': |
| 6131 | if (name[2] == 's' && |
| 6132 | name[3] == 'e') |
| 6133 | { /* else */ |
| 6134 | return KEY_else; |
| 6135 | } |
| 6136 | |
| 6137 | goto unknown; |
| 6138 | |
| 6139 | case 'v': |
| 6140 | if (name[2] == 'a' && |
| 6141 | name[3] == 'l') |
| 6142 | { /* eval */ |
| 6143 | return KEY_eval; |
| 6144 | } |
| 6145 | |
| 6146 | goto unknown; |
| 6147 | |
| 6148 | case 'x': |
| 6149 | switch (name[2]) |
| 6150 | { |
| 6151 | case 'e': |
| 6152 | if (name[3] == 'c') |
| 6153 | { /* exec */ |
| 6154 | return -KEY_exec; |
| 6155 | } |
| 6156 | |
| 6157 | goto unknown; |
| 6158 | |
| 6159 | case 'i': |
| 6160 | if (name[3] == 't') |
| 6161 | { /* exit */ |
| 6162 | return -KEY_exit; |
| 6163 | } |
| 6164 | |
| 6165 | goto unknown; |
| 6166 | |
| 6167 | default: |
| 6168 | goto unknown; |
| 6169 | } |
| 6170 | |
| 6171 | default: |
| 6172 | goto unknown; |
| 6173 | } |
| 6174 | |
| 6175 | case 'f': |
| 6176 | if (name[1] == 'o' && |
| 6177 | name[2] == 'r' && |
| 6178 | name[3] == 'k') |
| 6179 | { /* fork */ |
| 6180 | return -KEY_fork; |
| 6181 | } |
| 6182 | |
| 6183 | goto unknown; |
| 6184 | |
| 6185 | case 'g': |
| 6186 | switch (name[1]) |
| 6187 | { |
| 6188 | case 'e': |
| 6189 | if (name[2] == 't' && |
| 6190 | name[3] == 'c') |
| 6191 | { /* getc */ |
| 6192 | return -KEY_getc; |
| 6193 | } |
| 6194 | |
| 6195 | goto unknown; |
| 6196 | |
| 6197 | case 'l': |
| 6198 | if (name[2] == 'o' && |
| 6199 | name[3] == 'b') |
| 6200 | { /* glob */ |
| 6201 | return KEY_glob; |
| 6202 | } |
| 6203 | |
| 6204 | goto unknown; |
| 6205 | |
| 6206 | case 'o': |
| 6207 | if (name[2] == 't' && |
| 6208 | name[3] == 'o') |
| 6209 | { /* goto */ |
| 6210 | return KEY_goto; |
| 6211 | } |
| 6212 | |
| 6213 | goto unknown; |
| 6214 | |
| 6215 | case 'r': |
| 6216 | if (name[2] == 'e' && |
| 6217 | name[3] == 'p') |
| 6218 | { /* grep */ |
| 6219 | return KEY_grep; |
| 6220 | } |
| 6221 | |
| 6222 | goto unknown; |
| 6223 | |
| 6224 | default: |
| 6225 | goto unknown; |
| 6226 | } |
| 6227 | |
| 6228 | case 'j': |
| 6229 | if (name[1] == 'o' && |
| 6230 | name[2] == 'i' && |
| 6231 | name[3] == 'n') |
| 6232 | { /* join */ |
| 6233 | return -KEY_join; |
| 6234 | } |
| 6235 | |
| 6236 | goto unknown; |
| 6237 | |
| 6238 | case 'k': |
| 6239 | switch (name[1]) |
| 6240 | { |
| 6241 | case 'e': |
| 6242 | if (name[2] == 'y' && |
| 6243 | name[3] == 's') |
| 6244 | { /* keys */ |
| 6245 | return -KEY_keys; |
| 6246 | } |
| 6247 | |
| 6248 | goto unknown; |
| 6249 | |
| 6250 | case 'i': |
| 6251 | if (name[2] == 'l' && |
| 6252 | name[3] == 'l') |
| 6253 | { /* kill */ |
| 6254 | return -KEY_kill; |
| 6255 | } |
| 6256 | |
| 6257 | goto unknown; |
| 6258 | |
| 6259 | default: |
| 6260 | goto unknown; |
| 6261 | } |
| 6262 | |
| 6263 | case 'l': |
| 6264 | switch (name[1]) |
| 6265 | { |
| 6266 | case 'a': |
| 6267 | if (name[2] == 's' && |
| 6268 | name[3] == 't') |
| 6269 | { /* last */ |
| 6270 | return KEY_last; |
| 6271 | } |
| 6272 | |
| 6273 | goto unknown; |
| 6274 | |
| 6275 | case 'i': |
| 6276 | if (name[2] == 'n' && |
| 6277 | name[3] == 'k') |
| 6278 | { /* link */ |
| 6279 | return -KEY_link; |
| 6280 | } |
| 6281 | |
| 6282 | goto unknown; |
| 6283 | |
| 6284 | case 'o': |
| 6285 | if (name[2] == 'c' && |
| 6286 | name[3] == 'k') |
| 6287 | { /* lock */ |
| 6288 | return -KEY_lock; |
| 6289 | } |
| 6290 | |
| 6291 | goto unknown; |
| 6292 | |
| 6293 | default: |
| 6294 | goto unknown; |
| 6295 | } |
| 6296 | |
| 6297 | case 'n': |
| 6298 | if (name[1] == 'e' && |
| 6299 | name[2] == 'x' && |
| 6300 | name[3] == 't') |
| 6301 | { /* next */ |
| 6302 | return KEY_next; |
| 6303 | } |
| 6304 | |
| 6305 | goto unknown; |
| 6306 | |
| 6307 | case 'o': |
| 6308 | if (name[1] == 'p' && |
| 6309 | name[2] == 'e' && |
| 6310 | name[3] == 'n') |
| 6311 | { /* open */ |
| 6312 | return -KEY_open; |
| 6313 | } |
| 6314 | |
| 6315 | goto unknown; |
| 6316 | |
| 6317 | case 'p': |
| 6318 | switch (name[1]) |
| 6319 | { |
| 6320 | case 'a': |
| 6321 | if (name[2] == 'c' && |
| 6322 | name[3] == 'k') |
| 6323 | { /* pack */ |
| 6324 | return -KEY_pack; |
| 6325 | } |
| 6326 | |
| 6327 | goto unknown; |
| 6328 | |
| 6329 | case 'i': |
| 6330 | if (name[2] == 'p' && |
| 6331 | name[3] == 'e') |
| 6332 | { /* pipe */ |
| 6333 | return -KEY_pipe; |
| 6334 | } |
| 6335 | |
| 6336 | goto unknown; |
| 6337 | |
| 6338 | case 'u': |
| 6339 | if (name[2] == 's' && |
| 6340 | name[3] == 'h') |
| 6341 | { /* push */ |
| 6342 | return -KEY_push; |
| 6343 | } |
| 6344 | |
| 6345 | goto unknown; |
| 6346 | |
| 6347 | default: |
| 6348 | goto unknown; |
| 6349 | } |
| 6350 | |
| 6351 | case 'r': |
| 6352 | switch (name[1]) |
| 6353 | { |
| 6354 | case 'a': |
| 6355 | if (name[2] == 'n' && |
| 6356 | name[3] == 'd') |
| 6357 | { /* rand */ |
| 6358 | return -KEY_rand; |
| 6359 | } |
| 6360 | |
| 6361 | goto unknown; |
| 6362 | |
| 6363 | case 'e': |
| 6364 | switch (name[2]) |
| 6365 | { |
| 6366 | case 'a': |
| 6367 | if (name[3] == 'd') |
| 6368 | { /* read */ |
| 6369 | return -KEY_read; |
| 6370 | } |
| 6371 | |
| 6372 | goto unknown; |
| 6373 | |
| 6374 | case 'c': |
| 6375 | if (name[3] == 'v') |
| 6376 | { /* recv */ |
| 6377 | return -KEY_recv; |
| 6378 | } |
| 6379 | |
| 6380 | goto unknown; |
| 6381 | |
| 6382 | case 'd': |
| 6383 | if (name[3] == 'o') |
| 6384 | { /* redo */ |
| 6385 | return KEY_redo; |
| 6386 | } |
| 6387 | |
| 6388 | goto unknown; |
| 6389 | |
| 6390 | default: |
| 6391 | goto unknown; |
| 6392 | } |
| 6393 | |
| 6394 | default: |
| 6395 | goto unknown; |
| 6396 | } |
| 6397 | |
| 6398 | case 's': |
| 6399 | switch (name[1]) |
| 6400 | { |
| 6401 | case 'e': |
| 6402 | switch (name[2]) |
| 6403 | { |
| 6404 | case 'e': |
| 6405 | if (name[3] == 'k') |
| 6406 | { /* seek */ |
| 6407 | return -KEY_seek; |
| 6408 | } |
| 6409 | |
| 6410 | goto unknown; |
| 6411 | |
| 6412 | case 'n': |
| 6413 | if (name[3] == 'd') |
| 6414 | { /* send */ |
| 6415 | return -KEY_send; |
| 6416 | } |
| 6417 | |
| 6418 | goto unknown; |
| 6419 | |
| 6420 | default: |
| 6421 | goto unknown; |
| 6422 | } |
| 6423 | |
| 6424 | case 'o': |
| 6425 | if (name[2] == 'r' && |
| 6426 | name[3] == 't') |
| 6427 | { /* sort */ |
| 6428 | return KEY_sort; |
| 6429 | } |
| 6430 | |
| 6431 | goto unknown; |
| 6432 | |
| 6433 | case 'q': |
| 6434 | if (name[2] == 'r' && |
| 6435 | name[3] == 't') |
| 6436 | { /* sqrt */ |
| 6437 | return -KEY_sqrt; |
| 6438 | } |
| 6439 | |
| 6440 | goto unknown; |
| 6441 | |
| 6442 | case 't': |
| 6443 | if (name[2] == 'a' && |
| 6444 | name[3] == 't') |
| 6445 | { /* stat */ |
| 6446 | return -KEY_stat; |
| 6447 | } |
| 6448 | |
| 6449 | goto unknown; |
| 6450 | |
| 6451 | default: |
| 6452 | goto unknown; |
| 6453 | } |
| 6454 | |
| 6455 | case 't': |
| 6456 | switch (name[1]) |
| 6457 | { |
| 6458 | case 'e': |
| 6459 | if (name[2] == 'l' && |
| 6460 | name[3] == 'l') |
| 6461 | { /* tell */ |
| 6462 | return -KEY_tell; |
| 6463 | } |
| 6464 | |
| 6465 | goto unknown; |
| 6466 | |
| 6467 | case 'i': |
| 6468 | switch (name[2]) |
| 6469 | { |
| 6470 | case 'e': |
| 6471 | if (name[3] == 'd') |
| 6472 | { /* tied */ |
| 6473 | return KEY_tied; |
| 6474 | } |
| 6475 | |
| 6476 | goto unknown; |
| 6477 | |
| 6478 | case 'm': |
| 6479 | if (name[3] == 'e') |
| 6480 | { /* time */ |
| 6481 | return -KEY_time; |
| 6482 | } |
| 6483 | |
| 6484 | goto unknown; |
| 6485 | |
| 6486 | default: |
| 6487 | goto unknown; |
| 6488 | } |
| 6489 | |
| 6490 | default: |
| 6491 | goto unknown; |
| 6492 | } |
| 6493 | |
| 6494 | case 'w': |
| 6495 | if (name[1] == 'a') |
| 6496 | { |
| 6497 | switch (name[2]) |
| 6498 | { |
| 6499 | case 'i': |
| 6500 | if (name[3] == 't') |
| 6501 | { /* wait */ |
| 6502 | return -KEY_wait; |
| 6503 | } |
| 6504 | |
| 6505 | goto unknown; |
| 6506 | |
| 6507 | case 'r': |
| 6508 | if (name[3] == 'n') |
| 6509 | { /* warn */ |
| 6510 | return -KEY_warn; |
| 6511 | } |
| 6512 | |
| 6513 | goto unknown; |
| 6514 | |
| 6515 | default: |
| 6516 | goto unknown; |
| 6517 | } |
| 6518 | } |
| 6519 | |
| 6520 | goto unknown; |
| 6521 | |
| 6522 | default: |
| 6523 | goto unknown; |
| 6524 | } |
| 6525 | |
| 6526 | case 5: /* 36 tokens of length 5 */ |
| 6527 | switch (name[0]) |
| 6528 | { |
| 6529 | case 'B': |
| 6530 | if (name[1] == 'E' && |
| 6531 | name[2] == 'G' && |
| 6532 | name[3] == 'I' && |
| 6533 | name[4] == 'N') |
| 6534 | { /* BEGIN */ |
| 6535 | return KEY_BEGIN; |
| 6536 | } |
| 6537 | |
| 6538 | goto unknown; |
| 6539 | |
| 6540 | case 'C': |
| 6541 | if (name[1] == 'H' && |
| 6542 | name[2] == 'E' && |
| 6543 | name[3] == 'C' && |
| 6544 | name[4] == 'K') |
| 6545 | { /* CHECK */ |
| 6546 | return KEY_CHECK; |
| 6547 | } |
| 6548 | |
| 6549 | goto unknown; |
| 6550 | |
| 6551 | case 'a': |
| 6552 | switch (name[1]) |
| 6553 | { |
| 6554 | case 'l': |
| 6555 | if (name[2] == 'a' && |
| 6556 | name[3] == 'r' && |
| 6557 | name[4] == 'm') |
| 6558 | { /* alarm */ |
| 6559 | return -KEY_alarm; |
| 6560 | } |
| 6561 | |
| 6562 | goto unknown; |
| 6563 | |
| 6564 | case 't': |
| 6565 | if (name[2] == 'a' && |
| 6566 | name[3] == 'n' && |
| 6567 | name[4] == '2') |
| 6568 | { /* atan2 */ |
| 6569 | return -KEY_atan2; |
| 6570 | } |
| 6571 | |
| 6572 | goto unknown; |
| 6573 | |
| 6574 | default: |
| 6575 | goto unknown; |
| 6576 | } |
| 6577 | |
| 6578 | case 'b': |
| 6579 | if (name[1] == 'l' && |
| 6580 | name[2] == 'e' && |
| 6581 | name[3] == 's' && |
| 6582 | name[4] == 's') |
| 6583 | { /* bless */ |
| 6584 | return -KEY_bless; |
| 6585 | } |
| 6586 | |
| 6587 | goto unknown; |
| 6588 | |
| 6589 | case 'c': |
| 6590 | switch (name[1]) |
| 6591 | { |
| 6592 | case 'h': |
| 6593 | switch (name[2]) |
| 6594 | { |
| 6595 | case 'd': |
| 6596 | if (name[3] == 'i' && |
| 6597 | name[4] == 'r') |
| 6598 | { /* chdir */ |
| 6599 | return -KEY_chdir; |
| 6600 | } |
| 6601 | |
| 6602 | goto unknown; |
| 6603 | |
| 6604 | case 'm': |
| 6605 | if (name[3] == 'o' && |
| 6606 | name[4] == 'd') |
| 6607 | { /* chmod */ |
| 6608 | return -KEY_chmod; |
| 6609 | } |
| 6610 | |
| 6611 | goto unknown; |
| 6612 | |
| 6613 | case 'o': |
| 6614 | switch (name[3]) |
| 6615 | { |
| 6616 | case 'm': |
| 6617 | if (name[4] == 'p') |
| 6618 | { /* chomp */ |
| 6619 | return -KEY_chomp; |
| 6620 | } |
| 6621 | |
| 6622 | goto unknown; |
| 6623 | |
| 6624 | case 'w': |
| 6625 | if (name[4] == 'n') |
| 6626 | { /* chown */ |
| 6627 | return -KEY_chown; |
| 6628 | } |
| 6629 | |
| 6630 | goto unknown; |
| 6631 | |
| 6632 | default: |
| 6633 | goto unknown; |
| 6634 | } |
| 6635 | |
| 6636 | default: |
| 6637 | goto unknown; |
| 6638 | } |
| 6639 | |
| 6640 | case 'l': |
| 6641 | if (name[2] == 'o' && |
| 6642 | name[3] == 's' && |
| 6643 | name[4] == 'e') |
| 6644 | { /* close */ |
| 6645 | return -KEY_close; |
| 6646 | } |
| 6647 | |
| 6648 | goto unknown; |
| 6649 | |
| 6650 | case 'r': |
| 6651 | if (name[2] == 'y' && |
| 6652 | name[3] == 'p' && |
| 6653 | name[4] == 't') |
| 6654 | { /* crypt */ |
| 6655 | return -KEY_crypt; |
| 6656 | } |
| 6657 | |
| 6658 | goto unknown; |
| 6659 | |
| 6660 | default: |
| 6661 | goto unknown; |
| 6662 | } |
| 6663 | |
| 6664 | case 'e': |
| 6665 | if (name[1] == 'l' && |
| 6666 | name[2] == 's' && |
| 6667 | name[3] == 'i' && |
| 6668 | name[4] == 'f') |
| 6669 | { /* elsif */ |
| 6670 | return KEY_elsif; |
| 6671 | } |
| 6672 | |
| 6673 | goto unknown; |
| 6674 | |
| 6675 | case 'f': |
| 6676 | switch (name[1]) |
| 6677 | { |
| 6678 | case 'c': |
| 6679 | if (name[2] == 'n' && |
| 6680 | name[3] == 't' && |
| 6681 | name[4] == 'l') |
| 6682 | { /* fcntl */ |
| 6683 | return -KEY_fcntl; |
| 6684 | } |
| 6685 | |
| 6686 | goto unknown; |
| 6687 | |
| 6688 | case 'l': |
| 6689 | if (name[2] == 'o' && |
| 6690 | name[3] == 'c' && |
| 6691 | name[4] == 'k') |
| 6692 | { /* flock */ |
| 6693 | return -KEY_flock; |
| 6694 | } |
| 6695 | |
| 6696 | goto unknown; |
| 6697 | |
| 6698 | default: |
| 6699 | goto unknown; |
| 6700 | } |
| 6701 | |
| 6702 | case 'i': |
| 6703 | switch (name[1]) |
| 6704 | { |
| 6705 | case 'n': |
| 6706 | if (name[2] == 'd' && |
| 6707 | name[3] == 'e' && |
| 6708 | name[4] == 'x') |
| 6709 | { /* index */ |
| 6710 | return -KEY_index; |
| 6711 | } |
| 6712 | |
| 6713 | goto unknown; |
| 6714 | |
| 6715 | case 'o': |
| 6716 | if (name[2] == 'c' && |
| 6717 | name[3] == 't' && |
| 6718 | name[4] == 'l') |
| 6719 | { /* ioctl */ |
| 6720 | return -KEY_ioctl; |
| 6721 | } |
| 6722 | |
| 6723 | goto unknown; |
| 6724 | |
| 6725 | default: |
| 6726 | goto unknown; |
| 6727 | } |
| 6728 | |
| 6729 | case 'l': |
| 6730 | switch (name[1]) |
| 6731 | { |
| 6732 | case 'o': |
| 6733 | if (name[2] == 'c' && |
| 6734 | name[3] == 'a' && |
| 6735 | name[4] == 'l') |
| 6736 | { /* local */ |
| 6737 | return KEY_local; |
| 6738 | } |
| 6739 | |
| 6740 | goto unknown; |
| 6741 | |
| 6742 | case 's': |
| 6743 | if (name[2] == 't' && |
| 6744 | name[3] == 'a' && |
| 6745 | name[4] == 't') |
| 6746 | { /* lstat */ |
| 6747 | return -KEY_lstat; |
| 6748 | } |
| 6749 | |
| 6750 | goto unknown; |
| 6751 | |
| 6752 | default: |
| 6753 | goto unknown; |
| 6754 | } |
| 6755 | |
| 6756 | case 'm': |
| 6757 | if (name[1] == 'k' && |
| 6758 | name[2] == 'd' && |
| 6759 | name[3] == 'i' && |
| 6760 | name[4] == 'r') |
| 6761 | { /* mkdir */ |
| 6762 | return -KEY_mkdir; |
| 6763 | } |
| 6764 | |
| 6765 | goto unknown; |
| 6766 | |
| 6767 | case 'p': |
| 6768 | if (name[1] == 'r' && |
| 6769 | name[2] == 'i' && |
| 6770 | name[3] == 'n' && |
| 6771 | name[4] == 't') |
| 6772 | { /* print */ |
| 6773 | return KEY_print; |
| 6774 | } |
| 6775 | |
| 6776 | goto unknown; |
| 6777 | |
| 6778 | case 'r': |
| 6779 | switch (name[1]) |
| 6780 | { |
| 6781 | case 'e': |
| 6782 | if (name[2] == 's' && |
| 6783 | name[3] == 'e' && |
| 6784 | name[4] == 't') |
| 6785 | { /* reset */ |
| 6786 | return -KEY_reset; |
| 6787 | } |
| 6788 | |
| 6789 | goto unknown; |
| 6790 | |
| 6791 | case 'm': |
| 6792 | if (name[2] == 'd' && |
| 6793 | name[3] == 'i' && |
| 6794 | name[4] == 'r') |
| 6795 | { /* rmdir */ |
| 6796 | return -KEY_rmdir; |
| 6797 | } |
| 6798 | |
| 6799 | goto unknown; |
| 6800 | |
| 6801 | default: |
| 6802 | goto unknown; |
| 6803 | } |
| 6804 | |
| 6805 | case 's': |
| 6806 | switch (name[1]) |
| 6807 | { |
| 6808 | case 'e': |
| 6809 | if (name[2] == 'm' && |
| 6810 | name[3] == 'o' && |
| 6811 | name[4] == 'p') |
| 6812 | { /* semop */ |
| 6813 | return -KEY_semop; |
| 6814 | } |
| 6815 | |
| 6816 | goto unknown; |
| 6817 | |
| 6818 | case 'h': |
| 6819 | if (name[2] == 'i' && |
| 6820 | name[3] == 'f' && |
| 6821 | name[4] == 't') |
| 6822 | { /* shift */ |
| 6823 | return -KEY_shift; |
| 6824 | } |
| 6825 | |
| 6826 | goto unknown; |
| 6827 | |
| 6828 | case 'l': |
| 6829 | if (name[2] == 'e' && |
| 6830 | name[3] == 'e' && |
| 6831 | name[4] == 'p') |
| 6832 | { /* sleep */ |
| 6833 | return -KEY_sleep; |
| 6834 | } |
| 6835 | |
| 6836 | goto unknown; |
| 6837 | |
| 6838 | case 'p': |
| 6839 | if (name[2] == 'l' && |
| 6840 | name[3] == 'i' && |
| 6841 | name[4] == 't') |
| 6842 | { /* split */ |
| 6843 | return KEY_split; |
| 6844 | } |
| 6845 | |
| 6846 | goto unknown; |
| 6847 | |
| 6848 | case 'r': |
| 6849 | if (name[2] == 'a' && |
| 6850 | name[3] == 'n' && |
| 6851 | name[4] == 'd') |
| 6852 | { /* srand */ |
| 6853 | return -KEY_srand; |
| 6854 | } |
| 6855 | |
| 6856 | goto unknown; |
| 6857 | |
| 6858 | case 't': |
| 6859 | if (name[2] == 'u' && |
| 6860 | name[3] == 'd' && |
| 6861 | name[4] == 'y') |
| 6862 | { /* study */ |
| 6863 | return KEY_study; |
| 6864 | } |
| 6865 | |
| 6866 | goto unknown; |
| 6867 | |
| 6868 | default: |
| 6869 | goto unknown; |
| 6870 | } |
| 6871 | |
| 6872 | case 't': |
| 6873 | if (name[1] == 'i' && |
| 6874 | name[2] == 'm' && |
| 6875 | name[3] == 'e' && |
| 6876 | name[4] == 's') |
| 6877 | { /* times */ |
| 6878 | return -KEY_times; |
| 6879 | } |
| 6880 | |
| 6881 | goto unknown; |
| 6882 | |
| 6883 | case 'u': |
| 6884 | switch (name[1]) |
| 6885 | { |
| 6886 | case 'm': |
| 6887 | if (name[2] == 'a' && |
| 6888 | name[3] == 's' && |
| 6889 | name[4] == 'k') |
| 6890 | { /* umask */ |
| 6891 | return -KEY_umask; |
| 6892 | } |
| 6893 | |
| 6894 | goto unknown; |
| 6895 | |
| 6896 | case 'n': |
| 6897 | switch (name[2]) |
| 6898 | { |
| 6899 | case 'd': |
| 6900 | if (name[3] == 'e' && |
| 6901 | name[4] == 'f') |
| 6902 | { /* undef */ |
| 6903 | return KEY_undef; |
| 6904 | } |
| 6905 | |
| 6906 | goto unknown; |
| 6907 | |
| 6908 | case 't': |
| 6909 | if (name[3] == 'i') |
| 6910 | { |
| 6911 | switch (name[4]) |
| 6912 | { |
| 6913 | case 'e': |
| 6914 | { /* untie */ |
| 6915 | return KEY_untie; |
| 6916 | } |
| 6917 | |
| 6918 | case 'l': |
| 6919 | { /* until */ |
| 6920 | return KEY_until; |
| 6921 | } |
| 6922 | |
| 6923 | default: |
| 6924 | goto unknown; |
| 6925 | } |
| 6926 | } |
| 6927 | |
| 6928 | goto unknown; |
| 6929 | |
| 6930 | default: |
| 6931 | goto unknown; |
| 6932 | } |
| 6933 | |
| 6934 | case 't': |
| 6935 | if (name[2] == 'i' && |
| 6936 | name[3] == 'm' && |
| 6937 | name[4] == 'e') |
| 6938 | { /* utime */ |
| 6939 | return -KEY_utime; |
| 6940 | } |
| 6941 | |
| 6942 | goto unknown; |
| 6943 | |
| 6944 | default: |
| 6945 | goto unknown; |
| 6946 | } |
| 6947 | |
| 6948 | case 'w': |
| 6949 | switch (name[1]) |
| 6950 | { |
| 6951 | case 'h': |
| 6952 | if (name[2] == 'i' && |
| 6953 | name[3] == 'l' && |
| 6954 | name[4] == 'e') |
| 6955 | { /* while */ |
| 6956 | return KEY_while; |
| 6957 | } |
| 6958 | |
| 6959 | goto unknown; |
| 6960 | |
| 6961 | case 'r': |
| 6962 | if (name[2] == 'i' && |
| 6963 | name[3] == 't' && |
| 6964 | name[4] == 'e') |
| 6965 | { /* write */ |
| 6966 | return -KEY_write; |
| 6967 | } |
| 6968 | |
| 6969 | goto unknown; |
| 6970 | |
| 6971 | default: |
| 6972 | goto unknown; |
| 6973 | } |
| 6974 | |
| 6975 | default: |
| 6976 | goto unknown; |
| 6977 | } |
| 6978 | |
| 6979 | case 6: /* 33 tokens of length 6 */ |
| 6980 | switch (name[0]) |
| 6981 | { |
| 6982 | case 'a': |
| 6983 | if (name[1] == 'c' && |
| 6984 | name[2] == 'c' && |
| 6985 | name[3] == 'e' && |
| 6986 | name[4] == 'p' && |
| 6987 | name[5] == 't') |
| 6988 | { /* accept */ |
| 6989 | return -KEY_accept; |
| 6990 | } |
| 6991 | |
| 6992 | goto unknown; |
| 6993 | |
| 6994 | case 'c': |
| 6995 | switch (name[1]) |
| 6996 | { |
| 6997 | case 'a': |
| 6998 | if (name[2] == 'l' && |
| 6999 | name[3] == 'l' && |
| 7000 | name[4] == 'e' && |
| 7001 | name[5] == 'r') |
| 7002 | { /* caller */ |
| 7003 | return -KEY_caller; |
| 7004 | } |
| 7005 | |
| 7006 | goto unknown; |
| 7007 | |
| 7008 | case 'h': |
| 7009 | if (name[2] == 'r' && |
| 7010 | name[3] == 'o' && |
| 7011 | name[4] == 'o' && |
| 7012 | name[5] == 't') |
| 7013 | { /* chroot */ |
| 7014 | return -KEY_chroot; |
| 7015 | } |
| 7016 | |
| 7017 | goto unknown; |
| 7018 | |
| 7019 | default: |
| 7020 | goto unknown; |
| 7021 | } |
| 7022 | |
| 7023 | case 'd': |
| 7024 | if (name[1] == 'e' && |
| 7025 | name[2] == 'l' && |
| 7026 | name[3] == 'e' && |
| 7027 | name[4] == 't' && |
| 7028 | name[5] == 'e') |
| 7029 | { /* delete */ |
| 7030 | return KEY_delete; |
| 7031 | } |
| 7032 | |
| 7033 | goto unknown; |
| 7034 | |
| 7035 | case 'e': |
| 7036 | switch (name[1]) |
| 7037 | { |
| 7038 | case 'l': |
| 7039 | if (name[2] == 's' && |
| 7040 | name[3] == 'e' && |
| 7041 | name[4] == 'i' && |
| 7042 | name[5] == 'f') |
| 7043 | { /* elseif */ |
| 7044 | if(ckWARN_d(WARN_SYNTAX)) |
| 7045 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif"); |
| 7046 | } |
| 7047 | |
| 7048 | goto unknown; |
| 7049 | |
| 7050 | case 'x': |
| 7051 | if (name[2] == 'i' && |
| 7052 | name[3] == 's' && |
| 7053 | name[4] == 't' && |
| 7054 | name[5] == 's') |
| 7055 | { /* exists */ |
| 7056 | return KEY_exists; |
| 7057 | } |
| 7058 | |
| 7059 | goto unknown; |
| 7060 | |
| 7061 | default: |
| 7062 | goto unknown; |
| 7063 | } |
| 7064 | |
| 7065 | case 'f': |
| 7066 | switch (name[1]) |
| 7067 | { |
| 7068 | case 'i': |
| 7069 | if (name[2] == 'l' && |
| 7070 | name[3] == 'e' && |
| 7071 | name[4] == 'n' && |
| 7072 | name[5] == 'o') |
| 7073 | { /* fileno */ |
| 7074 | return -KEY_fileno; |
| 7075 | } |
| 7076 | |
| 7077 | goto unknown; |
| 7078 | |
| 7079 | case 'o': |
| 7080 | if (name[2] == 'r' && |
| 7081 | name[3] == 'm' && |
| 7082 | name[4] == 'a' && |
| 7083 | name[5] == 't') |
| 7084 | { /* format */ |
| 7085 | return KEY_format; |
| 7086 | } |
| 7087 | |
| 7088 | goto unknown; |
| 7089 | |
| 7090 | default: |
| 7091 | goto unknown; |
| 7092 | } |
| 7093 | |
| 7094 | case 'g': |
| 7095 | if (name[1] == 'm' && |
| 7096 | name[2] == 't' && |
| 7097 | name[3] == 'i' && |
| 7098 | name[4] == 'm' && |
| 7099 | name[5] == 'e') |
| 7100 | { /* gmtime */ |
| 7101 | return -KEY_gmtime; |
| 7102 | } |
| 7103 | |
| 7104 | goto unknown; |
| 7105 | |
| 7106 | case 'l': |
| 7107 | switch (name[1]) |
| 7108 | { |
| 7109 | case 'e': |
| 7110 | if (name[2] == 'n' && |
| 7111 | name[3] == 'g' && |
| 7112 | name[4] == 't' && |
| 7113 | name[5] == 'h') |
| 7114 | { /* length */ |
| 7115 | return -KEY_length; |
| 7116 | } |
| 7117 | |
| 7118 | goto unknown; |
| 7119 | |
| 7120 | case 'i': |
| 7121 | if (name[2] == 's' && |
| 7122 | name[3] == 't' && |
| 7123 | name[4] == 'e' && |
| 7124 | name[5] == 'n') |
| 7125 | { /* listen */ |
| 7126 | return -KEY_listen; |
| 7127 | } |
| 7128 | |
| 7129 | goto unknown; |
| 7130 | |
| 7131 | default: |
| 7132 | goto unknown; |
| 7133 | } |
| 7134 | |
| 7135 | case 'm': |
| 7136 | if (name[1] == 's' && |
| 7137 | name[2] == 'g') |
| 7138 | { |
| 7139 | switch (name[3]) |
| 7140 | { |
| 7141 | case 'c': |
| 7142 | if (name[4] == 't' && |
| 7143 | name[5] == 'l') |
| 7144 | { /* msgctl */ |
| 7145 | return -KEY_msgctl; |
| 7146 | } |
| 7147 | |
| 7148 | goto unknown; |
| 7149 | |
| 7150 | case 'g': |
| 7151 | if (name[4] == 'e' && |
| 7152 | name[5] == 't') |
| 7153 | { /* msgget */ |
| 7154 | return -KEY_msgget; |
| 7155 | } |
| 7156 | |
| 7157 | goto unknown; |
| 7158 | |
| 7159 | case 'r': |
| 7160 | if (name[4] == 'c' && |
| 7161 | name[5] == 'v') |
| 7162 | { /* msgrcv */ |
| 7163 | return -KEY_msgrcv; |
| 7164 | } |
| 7165 | |
| 7166 | goto unknown; |
| 7167 | |
| 7168 | case 's': |
| 7169 | if (name[4] == 'n' && |
| 7170 | name[5] == 'd') |
| 7171 | { /* msgsnd */ |
| 7172 | return -KEY_msgsnd; |
| 7173 | } |
| 7174 | |
| 7175 | goto unknown; |
| 7176 | |
| 7177 | default: |
| 7178 | goto unknown; |
| 7179 | } |
| 7180 | } |
| 7181 | |
| 7182 | goto unknown; |
| 7183 | |
| 7184 | case 'p': |
| 7185 | if (name[1] == 'r' && |
| 7186 | name[2] == 'i' && |
| 7187 | name[3] == 'n' && |
| 7188 | name[4] == 't' && |
| 7189 | name[5] == 'f') |
| 7190 | { /* printf */ |
| 7191 | return KEY_printf; |
| 7192 | } |
| 7193 | |
| 7194 | goto unknown; |
| 7195 | |
| 7196 | case 'r': |
| 7197 | switch (name[1]) |
| 7198 | { |
| 7199 | case 'e': |
| 7200 | switch (name[2]) |
| 7201 | { |
| 7202 | case 'n': |
| 7203 | if (name[3] == 'a' && |
| 7204 | name[4] == 'm' && |
| 7205 | name[5] == 'e') |
| 7206 | { /* rename */ |
| 7207 | return -KEY_rename; |
| 7208 | } |
| 7209 | |
| 7210 | goto unknown; |
| 7211 | |
| 7212 | case 't': |
| 7213 | if (name[3] == 'u' && |
| 7214 | name[4] == 'r' && |
| 7215 | name[5] == 'n') |
| 7216 | { /* return */ |
| 7217 | return KEY_return; |
| 7218 | } |
| 7219 | |
| 7220 | goto unknown; |
| 7221 | |
| 7222 | default: |
| 7223 | goto unknown; |
| 7224 | } |
| 7225 | |
| 7226 | case 'i': |
| 7227 | if (name[2] == 'n' && |
| 7228 | name[3] == 'd' && |
| 7229 | name[4] == 'e' && |
| 7230 | name[5] == 'x') |
| 7231 | { /* rindex */ |
| 7232 | return -KEY_rindex; |
| 7233 | } |
| 7234 | |
| 7235 | goto unknown; |
| 7236 | |
| 7237 | default: |
| 7238 | goto unknown; |
| 7239 | } |
| 7240 | |
| 7241 | case 's': |
| 7242 | switch (name[1]) |
| 7243 | { |
| 7244 | case 'c': |
| 7245 | if (name[2] == 'a' && |
| 7246 | name[3] == 'l' && |
| 7247 | name[4] == 'a' && |
| 7248 | name[5] == 'r') |
| 7249 | { /* scalar */ |
| 7250 | return KEY_scalar; |
| 7251 | } |
| 7252 | |
| 7253 | goto unknown; |
| 7254 | |
| 7255 | case 'e': |
| 7256 | switch (name[2]) |
| 7257 | { |
| 7258 | case 'l': |
| 7259 | if (name[3] == 'e' && |
| 7260 | name[4] == 'c' && |
| 7261 | name[5] == 't') |
| 7262 | { /* select */ |
| 7263 | return -KEY_select; |
| 7264 | } |
| 7265 | |
| 7266 | goto unknown; |
| 7267 | |
| 7268 | case 'm': |
| 7269 | switch (name[3]) |
| 7270 | { |
| 7271 | case 'c': |
| 7272 | if (name[4] == 't' && |
| 7273 | name[5] == 'l') |
| 7274 | { /* semctl */ |
| 7275 | return -KEY_semctl; |
| 7276 | } |
| 7277 | |
| 7278 | goto unknown; |
| 7279 | |
| 7280 | case 'g': |
| 7281 | if (name[4] == 'e' && |
| 7282 | name[5] == 't') |
| 7283 | { /* semget */ |
| 7284 | return -KEY_semget; |
| 7285 | } |
| 7286 | |
| 7287 | goto unknown; |
| 7288 | |
| 7289 | default: |
| 7290 | goto unknown; |
| 7291 | } |
| 7292 | |
| 7293 | default: |
| 7294 | goto unknown; |
| 7295 | } |
| 7296 | |
| 7297 | case 'h': |
| 7298 | if (name[2] == 'm') |
| 7299 | { |
| 7300 | switch (name[3]) |
| 7301 | { |
| 7302 | case 'c': |
| 7303 | if (name[4] == 't' && |
| 7304 | name[5] == 'l') |
| 7305 | { /* shmctl */ |
| 7306 | return -KEY_shmctl; |
| 7307 | } |
| 7308 | |
| 7309 | goto unknown; |
| 7310 | |
| 7311 | case 'g': |
| 7312 | if (name[4] == 'e' && |
| 7313 | name[5] == 't') |
| 7314 | { /* shmget */ |
| 7315 | return -KEY_shmget; |
| 7316 | } |
| 7317 | |
| 7318 | goto unknown; |
| 7319 | |
| 7320 | default: |
| 7321 | goto unknown; |
| 7322 | } |
| 7323 | } |
| 7324 | |
| 7325 | goto unknown; |
| 7326 | |
| 7327 | case 'o': |
| 7328 | if (name[2] == 'c' && |
| 7329 | name[3] == 'k' && |
| 7330 | name[4] == 'e' && |
| 7331 | name[5] == 't') |
| 7332 | { /* socket */ |
| 7333 | return -KEY_socket; |
| 7334 | } |
| 7335 | |
| 7336 | goto unknown; |
| 7337 | |
| 7338 | case 'p': |
| 7339 | if (name[2] == 'l' && |
| 7340 | name[3] == 'i' && |
| 7341 | name[4] == 'c' && |
| 7342 | name[5] == 'e') |
| 7343 | { /* splice */ |
| 7344 | return -KEY_splice; |
| 7345 | } |
| 7346 | |
| 7347 | goto unknown; |
| 7348 | |
| 7349 | case 'u': |
| 7350 | if (name[2] == 'b' && |
| 7351 | name[3] == 's' && |
| 7352 | name[4] == 't' && |
| 7353 | name[5] == 'r') |
| 7354 | { /* substr */ |
| 7355 | return -KEY_substr; |
| 7356 | } |
| 7357 | |
| 7358 | goto unknown; |
| 7359 | |
| 7360 | case 'y': |
| 7361 | if (name[2] == 's' && |
| 7362 | name[3] == 't' && |
| 7363 | name[4] == 'e' && |
| 7364 | name[5] == 'm') |
| 7365 | { /* system */ |
| 7366 | return -KEY_system; |
| 7367 | } |
| 7368 | |
| 7369 | goto unknown; |
| 7370 | |
| 7371 | default: |
| 7372 | goto unknown; |
| 7373 | } |
| 7374 | |
| 7375 | case 'u': |
| 7376 | if (name[1] == 'n') |
| 7377 | { |
| 7378 | switch (name[2]) |
| 7379 | { |
| 7380 | case 'l': |
| 7381 | switch (name[3]) |
| 7382 | { |
| 7383 | case 'e': |
| 7384 | if (name[4] == 's' && |
| 7385 | name[5] == 's') |
| 7386 | { /* unless */ |
| 7387 | return KEY_unless; |
| 7388 | } |
| 7389 | |
| 7390 | goto unknown; |
| 7391 | |
| 7392 | case 'i': |
| 7393 | if (name[4] == 'n' && |
| 7394 | name[5] == 'k') |
| 7395 | { /* unlink */ |
| 7396 | return -KEY_unlink; |
| 7397 | } |
| 7398 | |
| 7399 | goto unknown; |
| 7400 | |
| 7401 | default: |
| 7402 | goto unknown; |
| 7403 | } |
| 7404 | |
| 7405 | case 'p': |
| 7406 | if (name[3] == 'a' && |
| 7407 | name[4] == 'c' && |
| 7408 | name[5] == 'k') |
| 7409 | { /* unpack */ |
| 7410 | return -KEY_unpack; |
| 7411 | } |
| 7412 | |
| 7413 | goto unknown; |
| 7414 | |
| 7415 | default: |
| 7416 | goto unknown; |
| 7417 | } |
| 7418 | } |
| 7419 | |
| 7420 | goto unknown; |
| 7421 | |
| 7422 | case 'v': |
| 7423 | if (name[1] == 'a' && |
| 7424 | name[2] == 'l' && |
| 7425 | name[3] == 'u' && |
| 7426 | name[4] == 'e' && |
| 7427 | name[5] == 's') |
| 7428 | { /* values */ |
| 7429 | return -KEY_values; |
| 7430 | } |
| 7431 | |
| 7432 | goto unknown; |
| 7433 | |
| 7434 | default: |
| 7435 | goto unknown; |
| 7436 | } |
| 7437 | |
| 7438 | case 7: /* 28 tokens of length 7 */ |
| 7439 | switch (name[0]) |
| 7440 | { |
| 7441 | case 'D': |
| 7442 | if (name[1] == 'E' && |
| 7443 | name[2] == 'S' && |
| 7444 | name[3] == 'T' && |
| 7445 | name[4] == 'R' && |
| 7446 | name[5] == 'O' && |
| 7447 | name[6] == 'Y') |
| 7448 | { /* DESTROY */ |
| 7449 | return KEY_DESTROY; |
| 7450 | } |
| 7451 | |
| 7452 | goto unknown; |
| 7453 | |
| 7454 | case '_': |
| 7455 | if (name[1] == '_' && |
| 7456 | name[2] == 'E' && |
| 7457 | name[3] == 'N' && |
| 7458 | name[4] == 'D' && |
| 7459 | name[5] == '_' && |
| 7460 | name[6] == '_') |
| 7461 | { /* __END__ */ |
| 7462 | return KEY___END__; |
| 7463 | } |
| 7464 | |
| 7465 | goto unknown; |
| 7466 | |
| 7467 | case 'b': |
| 7468 | if (name[1] == 'i' && |
| 7469 | name[2] == 'n' && |
| 7470 | name[3] == 'm' && |
| 7471 | name[4] == 'o' && |
| 7472 | name[5] == 'd' && |
| 7473 | name[6] == 'e') |
| 7474 | { /* binmode */ |
| 7475 | return -KEY_binmode; |
| 7476 | } |
| 7477 | |
| 7478 | goto unknown; |
| 7479 | |
| 7480 | case 'c': |
| 7481 | if (name[1] == 'o' && |
| 7482 | name[2] == 'n' && |
| 7483 | name[3] == 'n' && |
| 7484 | name[4] == 'e' && |
| 7485 | name[5] == 'c' && |
| 7486 | name[6] == 't') |
| 7487 | { /* connect */ |
| 7488 | return -KEY_connect; |
| 7489 | } |
| 7490 | |
| 7491 | goto unknown; |
| 7492 | |
| 7493 | case 'd': |
| 7494 | switch (name[1]) |
| 7495 | { |
| 7496 | case 'b': |
| 7497 | if (name[2] == 'm' && |
| 7498 | name[3] == 'o' && |
| 7499 | name[4] == 'p' && |
| 7500 | name[5] == 'e' && |
| 7501 | name[6] == 'n') |
| 7502 | { /* dbmopen */ |
| 7503 | return -KEY_dbmopen; |
| 7504 | } |
| 7505 | |
| 7506 | goto unknown; |
| 7507 | |
| 7508 | case 'e': |
| 7509 | if (name[2] == 'f' && |
| 7510 | name[3] == 'i' && |
| 7511 | name[4] == 'n' && |
| 7512 | name[5] == 'e' && |
| 7513 | name[6] == 'd') |
| 7514 | { /* defined */ |
| 7515 | return KEY_defined; |
| 7516 | } |
| 7517 | |
| 7518 | goto unknown; |
| 7519 | |
| 7520 | default: |
| 7521 | goto unknown; |
| 7522 | } |
| 7523 | |
| 7524 | case 'f': |
| 7525 | if (name[1] == 'o' && |
| 7526 | name[2] == 'r' && |
| 7527 | name[3] == 'e' && |
| 7528 | name[4] == 'a' && |
| 7529 | name[5] == 'c' && |
| 7530 | name[6] == 'h') |
| 7531 | { /* foreach */ |
| 7532 | return KEY_foreach; |
| 7533 | } |
| 7534 | |
| 7535 | goto unknown; |
| 7536 | |
| 7537 | case 'g': |
| 7538 | if (name[1] == 'e' && |
| 7539 | name[2] == 't' && |
| 7540 | name[3] == 'p') |
| 7541 | { |
| 7542 | switch (name[4]) |
| 7543 | { |
| 7544 | case 'g': |
| 7545 | if (name[5] == 'r' && |
| 7546 | name[6] == 'p') |
| 7547 | { /* getpgrp */ |
| 7548 | return -KEY_getpgrp; |
| 7549 | } |
| 7550 | |
| 7551 | goto unknown; |
| 7552 | |
| 7553 | case 'p': |
| 7554 | if (name[5] == 'i' && |
| 7555 | name[6] == 'd') |
| 7556 | { /* getppid */ |
| 7557 | return -KEY_getppid; |
| 7558 | } |
| 7559 | |
| 7560 | goto unknown; |
| 7561 | |
| 7562 | default: |
| 7563 | goto unknown; |
| 7564 | } |
| 7565 | } |
| 7566 | |
| 7567 | goto unknown; |
| 7568 | |
| 7569 | case 'l': |
| 7570 | if (name[1] == 'c' && |
| 7571 | name[2] == 'f' && |
| 7572 | name[3] == 'i' && |
| 7573 | name[4] == 'r' && |
| 7574 | name[5] == 's' && |
| 7575 | name[6] == 't') |
| 7576 | { /* lcfirst */ |
| 7577 | return -KEY_lcfirst; |
| 7578 | } |
| 7579 | |
| 7580 | goto unknown; |
| 7581 | |
| 7582 | case 'o': |
| 7583 | if (name[1] == 'p' && |
| 7584 | name[2] == 'e' && |
| 7585 | name[3] == 'n' && |
| 7586 | name[4] == 'd' && |
| 7587 | name[5] == 'i' && |
| 7588 | name[6] == 'r') |
| 7589 | { /* opendir */ |
| 7590 | return -KEY_opendir; |
| 7591 | } |
| 7592 | |
| 7593 | goto unknown; |
| 7594 | |
| 7595 | case 'p': |
| 7596 | if (name[1] == 'a' && |
| 7597 | name[2] == 'c' && |
| 7598 | name[3] == 'k' && |
| 7599 | name[4] == 'a' && |
| 7600 | name[5] == 'g' && |
| 7601 | name[6] == 'e') |
| 7602 | { /* package */ |
| 7603 | return KEY_package; |
| 7604 | } |
| 7605 | |
| 7606 | goto unknown; |
| 7607 | |
| 7608 | case 'r': |
| 7609 | if (name[1] == 'e') |
| 7610 | { |
| 7611 | switch (name[2]) |
| 7612 | { |
| 7613 | case 'a': |
| 7614 | if (name[3] == 'd' && |
| 7615 | name[4] == 'd' && |
| 7616 | name[5] == 'i' && |
| 7617 | name[6] == 'r') |
| 7618 | { /* readdir */ |
| 7619 | return -KEY_readdir; |
| 7620 | } |
| 7621 | |
| 7622 | goto unknown; |
| 7623 | |
| 7624 | case 'q': |
| 7625 | if (name[3] == 'u' && |
| 7626 | name[4] == 'i' && |
| 7627 | name[5] == 'r' && |
| 7628 | name[6] == 'e') |
| 7629 | { /* require */ |
| 7630 | return KEY_require; |
| 7631 | } |
| 7632 | |
| 7633 | goto unknown; |
| 7634 | |
| 7635 | case 'v': |
| 7636 | if (name[3] == 'e' && |
| 7637 | name[4] == 'r' && |
| 7638 | name[5] == 's' && |
| 7639 | name[6] == 'e') |
| 7640 | { /* reverse */ |
| 7641 | return -KEY_reverse; |
| 7642 | } |
| 7643 | |
| 7644 | goto unknown; |
| 7645 | |
| 7646 | default: |
| 7647 | goto unknown; |
| 7648 | } |
| 7649 | } |
| 7650 | |
| 7651 | goto unknown; |
| 7652 | |
| 7653 | case 's': |
| 7654 | switch (name[1]) |
| 7655 | { |
| 7656 | case 'e': |
| 7657 | switch (name[2]) |
| 7658 | { |
| 7659 | case 'e': |
| 7660 | if (name[3] == 'k' && |
| 7661 | name[4] == 'd' && |
| 7662 | name[5] == 'i' && |
| 7663 | name[6] == 'r') |
| 7664 | { /* seekdir */ |
| 7665 | return -KEY_seekdir; |
| 7666 | } |
| 7667 | |
| 7668 | goto unknown; |
| 7669 | |
| 7670 | case 't': |
| 7671 | if (name[3] == 'p' && |
| 7672 | name[4] == 'g' && |
| 7673 | name[5] == 'r' && |
| 7674 | name[6] == 'p') |
| 7675 | { /* setpgrp */ |
| 7676 | return -KEY_setpgrp; |
| 7677 | } |
| 7678 | |
| 7679 | goto unknown; |
| 7680 | |
| 7681 | default: |
| 7682 | goto unknown; |
| 7683 | } |
| 7684 | |
| 7685 | case 'h': |
| 7686 | if (name[2] == 'm' && |
| 7687 | name[3] == 'r' && |
| 7688 | name[4] == 'e' && |
| 7689 | name[5] == 'a' && |
| 7690 | name[6] == 'd') |
| 7691 | { /* shmread */ |
| 7692 | return -KEY_shmread; |
| 7693 | } |
| 7694 | |
| 7695 | goto unknown; |
| 7696 | |
| 7697 | case 'p': |
| 7698 | if (name[2] == 'r' && |
| 7699 | name[3] == 'i' && |
| 7700 | name[4] == 'n' && |
| 7701 | name[5] == 't' && |
| 7702 | name[6] == 'f') |
| 7703 | { /* sprintf */ |
| 7704 | return -KEY_sprintf; |
| 7705 | } |
| 7706 | |
| 7707 | goto unknown; |
| 7708 | |
| 7709 | case 'y': |
| 7710 | switch (name[2]) |
| 7711 | { |
| 7712 | case 'm': |
| 7713 | if (name[3] == 'l' && |
| 7714 | name[4] == 'i' && |
| 7715 | name[5] == 'n' && |
| 7716 | name[6] == 'k') |
| 7717 | { /* symlink */ |
| 7718 | return -KEY_symlink; |
| 7719 | } |
| 7720 | |
| 7721 | goto unknown; |
| 7722 | |
| 7723 | case 's': |
| 7724 | switch (name[3]) |
| 7725 | { |
| 7726 | case 'c': |
| 7727 | if (name[4] == 'a' && |
| 7728 | name[5] == 'l' && |
| 7729 | name[6] == 'l') |
| 7730 | { /* syscall */ |
| 7731 | return -KEY_syscall; |
| 7732 | } |
| 7733 | |
| 7734 | goto unknown; |
| 7735 | |
| 7736 | case 'o': |
| 7737 | if (name[4] == 'p' && |
| 7738 | name[5] == 'e' && |
| 7739 | name[6] == 'n') |
| 7740 | { /* sysopen */ |
| 7741 | return -KEY_sysopen; |
| 7742 | } |
| 7743 | |
| 7744 | goto unknown; |
| 7745 | |
| 7746 | case 'r': |
| 7747 | if (name[4] == 'e' && |
| 7748 | name[5] == 'a' && |
| 7749 | name[6] == 'd') |
| 7750 | { /* sysread */ |
| 7751 | return -KEY_sysread; |
| 7752 | } |
| 7753 | |
| 7754 | goto unknown; |
| 7755 | |
| 7756 | case 's': |
| 7757 | if (name[4] == 'e' && |
| 7758 | name[5] == 'e' && |
| 7759 | name[6] == 'k') |
| 7760 | { /* sysseek */ |
| 7761 | return -KEY_sysseek; |
| 7762 | } |
| 7763 | |
| 7764 | goto unknown; |
| 7765 | |
| 7766 | default: |
| 7767 | goto unknown; |
| 7768 | } |
| 7769 | |
| 7770 | default: |
| 7771 | goto unknown; |
| 7772 | } |
| 7773 | |
| 7774 | default: |
| 7775 | goto unknown; |
| 7776 | } |
| 7777 | |
| 7778 | case 't': |
| 7779 | if (name[1] == 'e' && |
| 7780 | name[2] == 'l' && |
| 7781 | name[3] == 'l' && |
| 7782 | name[4] == 'd' && |
| 7783 | name[5] == 'i' && |
| 7784 | name[6] == 'r') |
| 7785 | { /* telldir */ |
| 7786 | return -KEY_telldir; |
| 7787 | } |
| 7788 | |
| 7789 | goto unknown; |
| 7790 | |
| 7791 | case 'u': |
| 7792 | switch (name[1]) |
| 7793 | { |
| 7794 | case 'c': |
| 7795 | if (name[2] == 'f' && |
| 7796 | name[3] == 'i' && |
| 7797 | name[4] == 'r' && |
| 7798 | name[5] == 's' && |
| 7799 | name[6] == 't') |
| 7800 | { /* ucfirst */ |
| 7801 | return -KEY_ucfirst; |
| 7802 | } |
| 7803 | |
| 7804 | goto unknown; |
| 7805 | |
| 7806 | case 'n': |
| 7807 | if (name[2] == 's' && |
| 7808 | name[3] == 'h' && |
| 7809 | name[4] == 'i' && |
| 7810 | name[5] == 'f' && |
| 7811 | name[6] == 't') |
| 7812 | { /* unshift */ |
| 7813 | return -KEY_unshift; |
| 7814 | } |
| 7815 | |
| 7816 | goto unknown; |
| 7817 | |
| 7818 | default: |
| 7819 | goto unknown; |
| 7820 | } |
| 7821 | |
| 7822 | case 'w': |
| 7823 | if (name[1] == 'a' && |
| 7824 | name[2] == 'i' && |
| 7825 | name[3] == 't' && |
| 7826 | name[4] == 'p' && |
| 7827 | name[5] == 'i' && |
| 7828 | name[6] == 'd') |
| 7829 | { /* waitpid */ |
| 7830 | return -KEY_waitpid; |
| 7831 | } |
| 7832 | |
| 7833 | goto unknown; |
| 7834 | |
| 7835 | default: |
| 7836 | goto unknown; |
| 7837 | } |
| 7838 | |
| 7839 | case 8: /* 26 tokens of length 8 */ |
| 7840 | switch (name[0]) |
| 7841 | { |
| 7842 | case 'A': |
| 7843 | if (name[1] == 'U' && |
| 7844 | name[2] == 'T' && |
| 7845 | name[3] == 'O' && |
| 7846 | name[4] == 'L' && |
| 7847 | name[5] == 'O' && |
| 7848 | name[6] == 'A' && |
| 7849 | name[7] == 'D') |
| 7850 | { /* AUTOLOAD */ |
| 7851 | return KEY_AUTOLOAD; |
| 7852 | } |
| 7853 | |
| 7854 | goto unknown; |
| 7855 | |
| 7856 | case '_': |
| 7857 | if (name[1] == '_') |
| 7858 | { |
| 7859 | switch (name[2]) |
| 7860 | { |
| 7861 | case 'D': |
| 7862 | if (name[3] == 'A' && |
| 7863 | name[4] == 'T' && |
| 7864 | name[5] == 'A' && |
| 7865 | name[6] == '_' && |
| 7866 | name[7] == '_') |
| 7867 | { /* __DATA__ */ |
| 7868 | return KEY___DATA__; |
| 7869 | } |
| 7870 | |
| 7871 | goto unknown; |
| 7872 | |
| 7873 | case 'F': |
| 7874 | if (name[3] == 'I' && |
| 7875 | name[4] == 'L' && |
| 7876 | name[5] == 'E' && |
| 7877 | name[6] == '_' && |
| 7878 | name[7] == '_') |
| 7879 | { /* __FILE__ */ |
| 7880 | return -KEY___FILE__; |
| 7881 | } |
| 7882 | |
| 7883 | goto unknown; |
| 7884 | |
| 7885 | case 'L': |
| 7886 | if (name[3] == 'I' && |
| 7887 | name[4] == 'N' && |
| 7888 | name[5] == 'E' && |
| 7889 | name[6] == '_' && |
| 7890 | name[7] == '_') |
| 7891 | { /* __LINE__ */ |
| 7892 | return -KEY___LINE__; |
| 7893 | } |
| 7894 | |
| 7895 | goto unknown; |
| 7896 | |
| 7897 | default: |
| 7898 | goto unknown; |
| 7899 | } |
| 7900 | } |
| 7901 | |
| 7902 | goto unknown; |
| 7903 | |
| 7904 | case 'c': |
| 7905 | switch (name[1]) |
| 7906 | { |
| 7907 | case 'l': |
| 7908 | if (name[2] == 'o' && |
| 7909 | name[3] == 's' && |
| 7910 | name[4] == 'e' && |
| 7911 | name[5] == 'd' && |
| 7912 | name[6] == 'i' && |
| 7913 | name[7] == 'r') |
| 7914 | { /* closedir */ |
| 7915 | return -KEY_closedir; |
| 7916 | } |
| 7917 | |
| 7918 | goto unknown; |
| 7919 | |
| 7920 | case 'o': |
| 7921 | if (name[2] == 'n' && |
| 7922 | name[3] == 't' && |
| 7923 | name[4] == 'i' && |
| 7924 | name[5] == 'n' && |
| 7925 | name[6] == 'u' && |
| 7926 | name[7] == 'e') |
| 7927 | { /* continue */ |
| 7928 | return -KEY_continue; |
| 7929 | } |
| 7930 | |
| 7931 | goto unknown; |
| 7932 | |
| 7933 | default: |
| 7934 | goto unknown; |
| 7935 | } |
| 7936 | |
| 7937 | case 'd': |
| 7938 | if (name[1] == 'b' && |
| 7939 | name[2] == 'm' && |
| 7940 | name[3] == 'c' && |
| 7941 | name[4] == 'l' && |
| 7942 | name[5] == 'o' && |
| 7943 | name[6] == 's' && |
| 7944 | name[7] == 'e') |
| 7945 | { /* dbmclose */ |
| 7946 | return -KEY_dbmclose; |
| 7947 | } |
| 7948 | |
| 7949 | goto unknown; |
| 7950 | |
| 7951 | case 'e': |
| 7952 | if (name[1] == 'n' && |
| 7953 | name[2] == 'd') |
| 7954 | { |
| 7955 | switch (name[3]) |
| 7956 | { |
| 7957 | case 'g': |
| 7958 | if (name[4] == 'r' && |
| 7959 | name[5] == 'e' && |
| 7960 | name[6] == 'n' && |
| 7961 | name[7] == 't') |
| 7962 | { /* endgrent */ |
| 7963 | return -KEY_endgrent; |
| 7964 | } |
| 7965 | |
| 7966 | goto unknown; |
| 7967 | |
| 7968 | case 'p': |
| 7969 | if (name[4] == 'w' && |
| 7970 | name[5] == 'e' && |
| 7971 | name[6] == 'n' && |
| 7972 | name[7] == 't') |
| 7973 | { /* endpwent */ |
| 7974 | return -KEY_endpwent; |
| 7975 | } |
| 7976 | |
| 7977 | goto unknown; |
| 7978 | |
| 7979 | default: |
| 7980 | goto unknown; |
| 7981 | } |
| 7982 | } |
| 7983 | |
| 7984 | goto unknown; |
| 7985 | |
| 7986 | case 'f': |
| 7987 | if (name[1] == 'o' && |
| 7988 | name[2] == 'r' && |
| 7989 | name[3] == 'm' && |
| 7990 | name[4] == 'l' && |
| 7991 | name[5] == 'i' && |
| 7992 | name[6] == 'n' && |
| 7993 | name[7] == 'e') |
| 7994 | { /* formline */ |
| 7995 | return -KEY_formline; |
| 7996 | } |
| 7997 | |
| 7998 | goto unknown; |
| 7999 | |
| 8000 | case 'g': |
| 8001 | if (name[1] == 'e' && |
| 8002 | name[2] == 't') |
| 8003 | { |
| 8004 | switch (name[3]) |
| 8005 | { |
| 8006 | case 'g': |
| 8007 | if (name[4] == 'r') |
| 8008 | { |
| 8009 | switch (name[5]) |
| 8010 | { |
| 8011 | case 'e': |
| 8012 | if (name[6] == 'n' && |
| 8013 | name[7] == 't') |
| 8014 | { /* getgrent */ |
| 8015 | return -KEY_getgrent; |
| 8016 | } |
| 8017 | |
| 8018 | goto unknown; |
| 8019 | |
| 8020 | case 'g': |
| 8021 | if (name[6] == 'i' && |
| 8022 | name[7] == 'd') |
| 8023 | { /* getgrgid */ |
| 8024 | return -KEY_getgrgid; |
| 8025 | } |
| 8026 | |
| 8027 | goto unknown; |
| 8028 | |
| 8029 | case 'n': |
| 8030 | if (name[6] == 'a' && |
| 8031 | name[7] == 'm') |
| 8032 | { /* getgrnam */ |
| 8033 | return -KEY_getgrnam; |
| 8034 | } |
| 8035 | |
| 8036 | goto unknown; |
| 8037 | |
| 8038 | default: |
| 8039 | goto unknown; |
| 8040 | } |
| 8041 | } |
| 8042 | |
| 8043 | goto unknown; |
| 8044 | |
| 8045 | case 'l': |
| 8046 | if (name[4] == 'o' && |
| 8047 | name[5] == 'g' && |
| 8048 | name[6] == 'i' && |
| 8049 | name[7] == 'n') |
| 8050 | { /* getlogin */ |
| 8051 | return -KEY_getlogin; |
| 8052 | } |
| 8053 | |
| 8054 | goto unknown; |
| 8055 | |
| 8056 | case 'p': |
| 8057 | if (name[4] == 'w') |
| 8058 | { |
| 8059 | switch (name[5]) |
| 8060 | { |
| 8061 | case 'e': |
| 8062 | if (name[6] == 'n' && |
| 8063 | name[7] == 't') |
| 8064 | { /* getpwent */ |
| 8065 | return -KEY_getpwent; |
| 8066 | } |
| 8067 | |
| 8068 | goto unknown; |
| 8069 | |
| 8070 | case 'n': |
| 8071 | if (name[6] == 'a' && |
| 8072 | name[7] == 'm') |
| 8073 | { /* getpwnam */ |
| 8074 | return -KEY_getpwnam; |
| 8075 | } |
| 8076 | |
| 8077 | goto unknown; |
| 8078 | |
| 8079 | case 'u': |
| 8080 | if (name[6] == 'i' && |
| 8081 | name[7] == 'd') |
| 8082 | { /* getpwuid */ |
| 8083 | return -KEY_getpwuid; |
| 8084 | } |
| 8085 | |
| 8086 | goto unknown; |
| 8087 | |
| 8088 | default: |
| 8089 | goto unknown; |
| 8090 | } |
| 8091 | } |
| 8092 | |
| 8093 | goto unknown; |
| 8094 | |
| 8095 | default: |
| 8096 | goto unknown; |
| 8097 | } |
| 8098 | } |
| 8099 | |
| 8100 | goto unknown; |
| 8101 | |
| 8102 | case 'r': |
| 8103 | if (name[1] == 'e' && |
| 8104 | name[2] == 'a' && |
| 8105 | name[3] == 'd') |
| 8106 | { |
| 8107 | switch (name[4]) |
| 8108 | { |
| 8109 | case 'l': |
| 8110 | if (name[5] == 'i' && |
| 8111 | name[6] == 'n') |
| 8112 | { |
| 8113 | switch (name[7]) |
| 8114 | { |
| 8115 | case 'e': |
| 8116 | { /* readline */ |
| 8117 | return -KEY_readline; |
| 8118 | } |
| 8119 | |
| 8120 | case 'k': |
| 8121 | { /* readlink */ |
| 8122 | return -KEY_readlink; |
| 8123 | } |
| 8124 | |
| 8125 | default: |
| 8126 | goto unknown; |
| 8127 | } |
| 8128 | } |
| 8129 | |
| 8130 | goto unknown; |
| 8131 | |
| 8132 | case 'p': |
| 8133 | if (name[5] == 'i' && |
| 8134 | name[6] == 'p' && |
| 8135 | name[7] == 'e') |
| 8136 | { /* readpipe */ |
| 8137 | return -KEY_readpipe; |
| 8138 | } |
| 8139 | |
| 8140 | goto unknown; |
| 8141 | |
| 8142 | default: |
| 8143 | goto unknown; |
| 8144 | } |
| 8145 | } |
| 8146 | |
| 8147 | goto unknown; |
| 8148 | |
| 8149 | case 's': |
| 8150 | switch (name[1]) |
| 8151 | { |
| 8152 | case 'e': |
| 8153 | if (name[2] == 't') |
| 8154 | { |
| 8155 | switch (name[3]) |
| 8156 | { |
| 8157 | case 'g': |
| 8158 | if (name[4] == 'r' && |
| 8159 | name[5] == 'e' && |
| 8160 | name[6] == 'n' && |
| 8161 | name[7] == 't') |
| 8162 | { /* setgrent */ |
| 8163 | return -KEY_setgrent; |
| 8164 | } |
| 8165 | |
| 8166 | goto unknown; |
| 8167 | |
| 8168 | case 'p': |
| 8169 | if (name[4] == 'w' && |
| 8170 | name[5] == 'e' && |
| 8171 | name[6] == 'n' && |
| 8172 | name[7] == 't') |
| 8173 | { /* setpwent */ |
| 8174 | return -KEY_setpwent; |
| 8175 | } |
| 8176 | |
| 8177 | goto unknown; |
| 8178 | |
| 8179 | default: |
| 8180 | goto unknown; |
| 8181 | } |
| 8182 | } |
| 8183 | |
| 8184 | goto unknown; |
| 8185 | |
| 8186 | case 'h': |
| 8187 | switch (name[2]) |
| 8188 | { |
| 8189 | case 'm': |
| 8190 | if (name[3] == 'w' && |
| 8191 | name[4] == 'r' && |
| 8192 | name[5] == 'i' && |
| 8193 | name[6] == 't' && |
| 8194 | name[7] == 'e') |
| 8195 | { /* shmwrite */ |
| 8196 | return -KEY_shmwrite; |
| 8197 | } |
| 8198 | |
| 8199 | goto unknown; |
| 8200 | |
| 8201 | case 'u': |
| 8202 | if (name[3] == 't' && |
| 8203 | name[4] == 'd' && |
| 8204 | name[5] == 'o' && |
| 8205 | name[6] == 'w' && |
| 8206 | name[7] == 'n') |
| 8207 | { /* shutdown */ |
| 8208 | return -KEY_shutdown; |
| 8209 | } |
| 8210 | |
| 8211 | goto unknown; |
| 8212 | |
| 8213 | default: |
| 8214 | goto unknown; |
| 8215 | } |
| 8216 | |
| 8217 | case 'y': |
| 8218 | if (name[2] == 's' && |
| 8219 | name[3] == 'w' && |
| 8220 | name[4] == 'r' && |
| 8221 | name[5] == 'i' && |
| 8222 | name[6] == 't' && |
| 8223 | name[7] == 'e') |
| 8224 | { /* syswrite */ |
| 8225 | return -KEY_syswrite; |
| 8226 | } |
| 8227 | |
| 8228 | goto unknown; |
| 8229 | |
| 8230 | default: |
| 8231 | goto unknown; |
| 8232 | } |
| 8233 | |
| 8234 | case 't': |
| 8235 | if (name[1] == 'r' && |
| 8236 | name[2] == 'u' && |
| 8237 | name[3] == 'n' && |
| 8238 | name[4] == 'c' && |
| 8239 | name[5] == 'a' && |
| 8240 | name[6] == 't' && |
| 8241 | name[7] == 'e') |
| 8242 | { /* truncate */ |
| 8243 | return -KEY_truncate; |
| 8244 | } |
| 8245 | |
| 8246 | goto unknown; |
| 8247 | |
| 8248 | default: |
| 8249 | goto unknown; |
| 8250 | } |
| 8251 | |
| 8252 | case 9: /* 8 tokens of length 9 */ |
| 8253 | switch (name[0]) |
| 8254 | { |
| 8255 | case 'e': |
| 8256 | if (name[1] == 'n' && |
| 8257 | name[2] == 'd' && |
| 8258 | name[3] == 'n' && |
| 8259 | name[4] == 'e' && |
| 8260 | name[5] == 't' && |
| 8261 | name[6] == 'e' && |
| 8262 | name[7] == 'n' && |
| 8263 | name[8] == 't') |
| 8264 | { /* endnetent */ |
| 8265 | return -KEY_endnetent; |
| 8266 | } |
| 8267 | |
| 8268 | goto unknown; |
| 8269 | |
| 8270 | case 'g': |
| 8271 | if (name[1] == 'e' && |
| 8272 | name[2] == 't' && |
| 8273 | name[3] == 'n' && |
| 8274 | name[4] == 'e' && |
| 8275 | name[5] == 't' && |
| 8276 | name[6] == 'e' && |
| 8277 | name[7] == 'n' && |
| 8278 | name[8] == 't') |
| 8279 | { /* getnetent */ |
| 8280 | return -KEY_getnetent; |
| 8281 | } |
| 8282 | |
| 8283 | goto unknown; |
| 8284 | |
| 8285 | case 'l': |
| 8286 | if (name[1] == 'o' && |
| 8287 | name[2] == 'c' && |
| 8288 | name[3] == 'a' && |
| 8289 | name[4] == 'l' && |
| 8290 | name[5] == 't' && |
| 8291 | name[6] == 'i' && |
| 8292 | name[7] == 'm' && |
| 8293 | name[8] == 'e') |
| 8294 | { /* localtime */ |
| 8295 | return -KEY_localtime; |
| 8296 | } |
| 8297 | |
| 8298 | goto unknown; |
| 8299 | |
| 8300 | case 'p': |
| 8301 | if (name[1] == 'r' && |
| 8302 | name[2] == 'o' && |
| 8303 | name[3] == 't' && |
| 8304 | name[4] == 'o' && |
| 8305 | name[5] == 't' && |
| 8306 | name[6] == 'y' && |
| 8307 | name[7] == 'p' && |
| 8308 | name[8] == 'e') |
| 8309 | { /* prototype */ |
| 8310 | return KEY_prototype; |
| 8311 | } |
| 8312 | |
| 8313 | goto unknown; |
| 8314 | |
| 8315 | case 'q': |
| 8316 | if (name[1] == 'u' && |
| 8317 | name[2] == 'o' && |
| 8318 | name[3] == 't' && |
| 8319 | name[4] == 'e' && |
| 8320 | name[5] == 'm' && |
| 8321 | name[6] == 'e' && |
| 8322 | name[7] == 't' && |
| 8323 | name[8] == 'a') |
| 8324 | { /* quotemeta */ |
| 8325 | return -KEY_quotemeta; |
| 8326 | } |
| 8327 | |
| 8328 | goto unknown; |
| 8329 | |
| 8330 | case 'r': |
| 8331 | if (name[1] == 'e' && |
| 8332 | name[2] == 'w' && |
| 8333 | name[3] == 'i' && |
| 8334 | name[4] == 'n' && |
| 8335 | name[5] == 'd' && |
| 8336 | name[6] == 'd' && |
| 8337 | name[7] == 'i' && |
| 8338 | name[8] == 'r') |
| 8339 | { /* rewinddir */ |
| 8340 | return -KEY_rewinddir; |
| 8341 | } |
| 8342 | |
| 8343 | goto unknown; |
| 8344 | |
| 8345 | case 's': |
| 8346 | if (name[1] == 'e' && |
| 8347 | name[2] == 't' && |
| 8348 | name[3] == 'n' && |
| 8349 | name[4] == 'e' && |
| 8350 | name[5] == 't' && |
| 8351 | name[6] == 'e' && |
| 8352 | name[7] == 'n' && |
| 8353 | name[8] == 't') |
| 8354 | { /* setnetent */ |
| 8355 | return -KEY_setnetent; |
| 8356 | } |
| 8357 | |
| 8358 | goto unknown; |
| 8359 | |
| 8360 | case 'w': |
| 8361 | if (name[1] == 'a' && |
| 8362 | name[2] == 'n' && |
| 8363 | name[3] == 't' && |
| 8364 | name[4] == 'a' && |
| 8365 | name[5] == 'r' && |
| 8366 | name[6] == 'r' && |
| 8367 | name[7] == 'a' && |
| 8368 | name[8] == 'y') |
| 8369 | { /* wantarray */ |
| 8370 | return -KEY_wantarray; |
| 8371 | } |
| 8372 | |
| 8373 | goto unknown; |
| 8374 | |
| 8375 | default: |
| 8376 | goto unknown; |
| 8377 | } |
| 8378 | |
| 8379 | case 10: /* 9 tokens of length 10 */ |
| 8380 | switch (name[0]) |
| 8381 | { |
| 8382 | case 'e': |
| 8383 | if (name[1] == 'n' && |
| 8384 | name[2] == 'd') |
| 8385 | { |
| 8386 | switch (name[3]) |
| 8387 | { |
| 8388 | case 'h': |
| 8389 | if (name[4] == 'o' && |
| 8390 | name[5] == 's' && |
| 8391 | name[6] == 't' && |
| 8392 | name[7] == 'e' && |
| 8393 | name[8] == 'n' && |
| 8394 | name[9] == 't') |
| 8395 | { /* endhostent */ |
| 8396 | return -KEY_endhostent; |
| 8397 | } |
| 8398 | |
| 8399 | goto unknown; |
| 8400 | |
| 8401 | case 's': |
| 8402 | if (name[4] == 'e' && |
| 8403 | name[5] == 'r' && |
| 8404 | name[6] == 'v' && |
| 8405 | name[7] == 'e' && |
| 8406 | name[8] == 'n' && |
| 8407 | name[9] == 't') |
| 8408 | { /* endservent */ |
| 8409 | return -KEY_endservent; |
| 8410 | } |
| 8411 | |
| 8412 | goto unknown; |
| 8413 | |
| 8414 | default: |
| 8415 | goto unknown; |
| 8416 | } |
| 8417 | } |
| 8418 | |
| 8419 | goto unknown; |
| 8420 | |
| 8421 | case 'g': |
| 8422 | if (name[1] == 'e' && |
| 8423 | name[2] == 't') |
| 8424 | { |
| 8425 | switch (name[3]) |
| 8426 | { |
| 8427 | case 'h': |
| 8428 | if (name[4] == 'o' && |
| 8429 | name[5] == 's' && |
| 8430 | name[6] == 't' && |
| 8431 | name[7] == 'e' && |
| 8432 | name[8] == 'n' && |
| 8433 | name[9] == 't') |
| 8434 | { /* gethostent */ |
| 8435 | return -KEY_gethostent; |
| 8436 | } |
| 8437 | |
| 8438 | goto unknown; |
| 8439 | |
| 8440 | case 's': |
| 8441 | switch (name[4]) |
| 8442 | { |
| 8443 | case 'e': |
| 8444 | if (name[5] == 'r' && |
| 8445 | name[6] == 'v' && |
| 8446 | name[7] == 'e' && |
| 8447 | name[8] == 'n' && |
| 8448 | name[9] == 't') |
| 8449 | { /* getservent */ |
| 8450 | return -KEY_getservent; |
| 8451 | } |
| 8452 | |
| 8453 | goto unknown; |
| 8454 | |
| 8455 | case 'o': |
| 8456 | if (name[5] == 'c' && |
| 8457 | name[6] == 'k' && |
| 8458 | name[7] == 'o' && |
| 8459 | name[8] == 'p' && |
| 8460 | name[9] == 't') |
| 8461 | { /* getsockopt */ |
| 8462 | return -KEY_getsockopt; |
| 8463 | } |
| 8464 | |
| 8465 | goto unknown; |
| 8466 | |
| 8467 | default: |
| 8468 | goto unknown; |
| 8469 | } |
| 8470 | |
| 8471 | default: |
| 8472 | goto unknown; |
| 8473 | } |
| 8474 | } |
| 8475 | |
| 8476 | goto unknown; |
| 8477 | |
| 8478 | case 's': |
| 8479 | switch (name[1]) |
| 8480 | { |
| 8481 | case 'e': |
| 8482 | if (name[2] == 't') |
| 8483 | { |
| 8484 | switch (name[3]) |
| 8485 | { |
| 8486 | case 'h': |
| 8487 | if (name[4] == 'o' && |
| 8488 | name[5] == 's' && |
| 8489 | name[6] == 't' && |
| 8490 | name[7] == 'e' && |
| 8491 | name[8] == 'n' && |
| 8492 | name[9] == 't') |
| 8493 | { /* sethostent */ |
| 8494 | return -KEY_sethostent; |
| 8495 | } |
| 8496 | |
| 8497 | goto unknown; |
| 8498 | |
| 8499 | case 's': |
| 8500 | switch (name[4]) |
| 8501 | { |
| 8502 | case 'e': |
| 8503 | if (name[5] == 'r' && |
| 8504 | name[6] == 'v' && |
| 8505 | name[7] == 'e' && |
| 8506 | name[8] == 'n' && |
| 8507 | name[9] == 't') |
| 8508 | { /* setservent */ |
| 8509 | return -KEY_setservent; |
| 8510 | } |
| 8511 | |
| 8512 | goto unknown; |
| 8513 | |
| 8514 | case 'o': |
| 8515 | if (name[5] == 'c' && |
| 8516 | name[6] == 'k' && |
| 8517 | name[7] == 'o' && |
| 8518 | name[8] == 'p' && |
| 8519 | name[9] == 't') |
| 8520 | { /* setsockopt */ |
| 8521 | return -KEY_setsockopt; |
| 8522 | } |
| 8523 | |
| 8524 | goto unknown; |
| 8525 | |
| 8526 | default: |
| 8527 | goto unknown; |
| 8528 | } |
| 8529 | |
| 8530 | default: |
| 8531 | goto unknown; |
| 8532 | } |
| 8533 | } |
| 8534 | |
| 8535 | goto unknown; |
| 8536 | |
| 8537 | case 'o': |
| 8538 | if (name[2] == 'c' && |
| 8539 | name[3] == 'k' && |
| 8540 | name[4] == 'e' && |
| 8541 | name[5] == 't' && |
| 8542 | name[6] == 'p' && |
| 8543 | name[7] == 'a' && |
| 8544 | name[8] == 'i' && |
| 8545 | name[9] == 'r') |
| 8546 | { /* socketpair */ |
| 8547 | return -KEY_socketpair; |
| 8548 | } |
| 8549 | |
| 8550 | goto unknown; |
| 8551 | |
| 8552 | default: |
| 8553 | goto unknown; |
| 8554 | } |
| 8555 | |
| 8556 | default: |
| 8557 | goto unknown; |
| 8558 | } |
| 8559 | |
| 8560 | case 11: /* 8 tokens of length 11 */ |
| 8561 | switch (name[0]) |
| 8562 | { |
| 8563 | case '_': |
| 8564 | if (name[1] == '_' && |
| 8565 | name[2] == 'P' && |
| 8566 | name[3] == 'A' && |
| 8567 | name[4] == 'C' && |
| 8568 | name[5] == 'K' && |
| 8569 | name[6] == 'A' && |
| 8570 | name[7] == 'G' && |
| 8571 | name[8] == 'E' && |
| 8572 | name[9] == '_' && |
| 8573 | name[10] == '_') |
| 8574 | { /* __PACKAGE__ */ |
| 8575 | return -KEY___PACKAGE__; |
| 8576 | } |
| 8577 | |
| 8578 | goto unknown; |
| 8579 | |
| 8580 | case 'e': |
| 8581 | if (name[1] == 'n' && |
| 8582 | name[2] == 'd' && |
| 8583 | name[3] == 'p' && |
| 8584 | name[4] == 'r' && |
| 8585 | name[5] == 'o' && |
| 8586 | name[6] == 't' && |
| 8587 | name[7] == 'o' && |
| 8588 | name[8] == 'e' && |
| 8589 | name[9] == 'n' && |
| 8590 | name[10] == 't') |
| 8591 | { /* endprotoent */ |
| 8592 | return -KEY_endprotoent; |
| 8593 | } |
| 8594 | |
| 8595 | goto unknown; |
| 8596 | |
| 8597 | case 'g': |
| 8598 | if (name[1] == 'e' && |
| 8599 | name[2] == 't') |
| 8600 | { |
| 8601 | switch (name[3]) |
| 8602 | { |
| 8603 | case 'p': |
| 8604 | switch (name[4]) |
| 8605 | { |
| 8606 | case 'e': |
| 8607 | if (name[5] == 'e' && |
| 8608 | name[6] == 'r' && |
| 8609 | name[7] == 'n' && |
| 8610 | name[8] == 'a' && |
| 8611 | name[9] == 'm' && |
| 8612 | name[10] == 'e') |
| 8613 | { /* getpeername */ |
| 8614 | return -KEY_getpeername; |
| 8615 | } |
| 8616 | |
| 8617 | goto unknown; |
| 8618 | |
| 8619 | case 'r': |
| 8620 | switch (name[5]) |
| 8621 | { |
| 8622 | case 'i': |
| 8623 | if (name[6] == 'o' && |
| 8624 | name[7] == 'r' && |
| 8625 | name[8] == 'i' && |
| 8626 | name[9] == 't' && |
| 8627 | name[10] == 'y') |
| 8628 | { /* getpriority */ |
| 8629 | return -KEY_getpriority; |
| 8630 | } |
| 8631 | |
| 8632 | goto unknown; |
| 8633 | |
| 8634 | case 'o': |
| 8635 | if (name[6] == 't' && |
| 8636 | name[7] == 'o' && |
| 8637 | name[8] == 'e' && |
| 8638 | name[9] == 'n' && |
| 8639 | name[10] == 't') |
| 8640 | { /* getprotoent */ |
| 8641 | return -KEY_getprotoent; |
| 8642 | } |
| 8643 | |
| 8644 | goto unknown; |
| 8645 | |
| 8646 | default: |
| 8647 | goto unknown; |
| 8648 | } |
| 8649 | |
| 8650 | default: |
| 8651 | goto unknown; |
| 8652 | } |
| 8653 | |
| 8654 | case 's': |
| 8655 | if (name[4] == 'o' && |
| 8656 | name[5] == 'c' && |
| 8657 | name[6] == 'k' && |
| 8658 | name[7] == 'n' && |
| 8659 | name[8] == 'a' && |
| 8660 | name[9] == 'm' && |
| 8661 | name[10] == 'e') |
| 8662 | { /* getsockname */ |
| 8663 | return -KEY_getsockname; |
| 8664 | } |
| 8665 | |
| 8666 | goto unknown; |
| 8667 | |
| 8668 | default: |
| 8669 | goto unknown; |
| 8670 | } |
| 8671 | } |
| 8672 | |
| 8673 | goto unknown; |
| 8674 | |
| 8675 | case 's': |
| 8676 | if (name[1] == 'e' && |
| 8677 | name[2] == 't' && |
| 8678 | name[3] == 'p' && |
| 8679 | name[4] == 'r') |
| 8680 | { |
| 8681 | switch (name[5]) |
| 8682 | { |
| 8683 | case 'i': |
| 8684 | if (name[6] == 'o' && |
| 8685 | name[7] == 'r' && |
| 8686 | name[8] == 'i' && |
| 8687 | name[9] == 't' && |
| 8688 | name[10] == 'y') |
| 8689 | { /* setpriority */ |
| 8690 | return -KEY_setpriority; |
| 8691 | } |
| 8692 | |
| 8693 | goto unknown; |
| 8694 | |
| 8695 | case 'o': |
| 8696 | if (name[6] == 't' && |
| 8697 | name[7] == 'o' && |
| 8698 | name[8] == 'e' && |
| 8699 | name[9] == 'n' && |
| 8700 | name[10] == 't') |
| 8701 | { /* setprotoent */ |
| 8702 | return -KEY_setprotoent; |
| 8703 | } |
| 8704 | |
| 8705 | goto unknown; |
| 8706 | |
| 8707 | default: |
| 8708 | goto unknown; |
| 8709 | } |
| 8710 | } |
| 8711 | |
| 8712 | goto unknown; |
| 8713 | |
| 8714 | default: |
| 8715 | goto unknown; |
| 8716 | } |
| 8717 | |
| 8718 | case 12: /* 2 tokens of length 12 */ |
| 8719 | if (name[0] == 'g' && |
| 8720 | name[1] == 'e' && |
| 8721 | name[2] == 't' && |
| 8722 | name[3] == 'n' && |
| 8723 | name[4] == 'e' && |
| 8724 | name[5] == 't' && |
| 8725 | name[6] == 'b' && |
| 8726 | name[7] == 'y') |
| 8727 | { |
| 8728 | switch (name[8]) |
| 8729 | { |
| 8730 | case 'a': |
| 8731 | if (name[9] == 'd' && |
| 8732 | name[10] == 'd' && |
| 8733 | name[11] == 'r') |
| 8734 | { /* getnetbyaddr */ |
| 8735 | return -KEY_getnetbyaddr; |
| 8736 | } |
| 8737 | |
| 8738 | goto unknown; |
| 8739 | |
| 8740 | case 'n': |
| 8741 | if (name[9] == 'a' && |
| 8742 | name[10] == 'm' && |
| 8743 | name[11] == 'e') |
| 8744 | { /* getnetbyname */ |
| 8745 | return -KEY_getnetbyname; |
| 8746 | } |
| 8747 | |
| 8748 | goto unknown; |
| 8749 | |
| 8750 | default: |
| 8751 | goto unknown; |
| 8752 | } |
| 8753 | } |
| 8754 | |
| 8755 | goto unknown; |
| 8756 | |
| 8757 | case 13: /* 4 tokens of length 13 */ |
| 8758 | if (name[0] == 'g' && |
| 8759 | name[1] == 'e' && |
| 8760 | name[2] == 't') |
| 8761 | { |
| 8762 | switch (name[3]) |
| 8763 | { |
| 8764 | case 'h': |
| 8765 | if (name[4] == 'o' && |
| 8766 | name[5] == 's' && |
| 8767 | name[6] == 't' && |
| 8768 | name[7] == 'b' && |
| 8769 | name[8] == 'y') |
| 8770 | { |
| 8771 | switch (name[9]) |
| 8772 | { |
| 8773 | case 'a': |
| 8774 | if (name[10] == 'd' && |
| 8775 | name[11] == 'd' && |
| 8776 | name[12] == 'r') |
| 8777 | { /* gethostbyaddr */ |
| 8778 | return -KEY_gethostbyaddr; |
| 8779 | } |
| 8780 | |
| 8781 | goto unknown; |
| 8782 | |
| 8783 | case 'n': |
| 8784 | if (name[10] == 'a' && |
| 8785 | name[11] == 'm' && |
| 8786 | name[12] == 'e') |
| 8787 | { /* gethostbyname */ |
| 8788 | return -KEY_gethostbyname; |
| 8789 | } |
| 8790 | |
| 8791 | goto unknown; |
| 8792 | |
| 8793 | default: |
| 8794 | goto unknown; |
| 8795 | } |
| 8796 | } |
| 8797 | |
| 8798 | goto unknown; |
| 8799 | |
| 8800 | case 's': |
| 8801 | if (name[4] == 'e' && |
| 8802 | name[5] == 'r' && |
| 8803 | name[6] == 'v' && |
| 8804 | name[7] == 'b' && |
| 8805 | name[8] == 'y') |
| 8806 | { |
| 8807 | switch (name[9]) |
| 8808 | { |
| 8809 | case 'n': |
| 8810 | if (name[10] == 'a' && |
| 8811 | name[11] == 'm' && |
| 8812 | name[12] == 'e') |
| 8813 | { /* getservbyname */ |
| 8814 | return -KEY_getservbyname; |
| 8815 | } |
| 8816 | |
| 8817 | goto unknown; |
| 8818 | |
| 8819 | case 'p': |
| 8820 | if (name[10] == 'o' && |
| 8821 | name[11] == 'r' && |
| 8822 | name[12] == 't') |
| 8823 | { /* getservbyport */ |
| 8824 | return -KEY_getservbyport; |
| 8825 | } |
| 8826 | |
| 8827 | goto unknown; |
| 8828 | |
| 8829 | default: |
| 8830 | goto unknown; |
| 8831 | } |
| 8832 | } |
| 8833 | |
| 8834 | goto unknown; |
| 8835 | |
| 8836 | default: |
| 8837 | goto unknown; |
| 8838 | } |
| 8839 | } |
| 8840 | |
| 8841 | goto unknown; |
| 8842 | |
| 8843 | case 14: /* 1 tokens of length 14 */ |
| 8844 | if (name[0] == 'g' && |
| 8845 | name[1] == 'e' && |
| 8846 | name[2] == 't' && |
| 8847 | name[3] == 'p' && |
| 8848 | name[4] == 'r' && |
| 8849 | name[5] == 'o' && |
| 8850 | name[6] == 't' && |
| 8851 | name[7] == 'o' && |
| 8852 | name[8] == 'b' && |
| 8853 | name[9] == 'y' && |
| 8854 | name[10] == 'n' && |
| 8855 | name[11] == 'a' && |
| 8856 | name[12] == 'm' && |
| 8857 | name[13] == 'e') |
| 8858 | { /* getprotobyname */ |
| 8859 | return -KEY_getprotobyname; |
| 8860 | } |
| 8861 | |
| 8862 | goto unknown; |
| 8863 | |
| 8864 | case 16: /* 1 tokens of length 16 */ |
| 8865 | if (name[0] == 'g' && |
| 8866 | name[1] == 'e' && |
| 8867 | name[2] == 't' && |
| 8868 | name[3] == 'p' && |
| 8869 | name[4] == 'r' && |
| 8870 | name[5] == 'o' && |
| 8871 | name[6] == 't' && |
| 8872 | name[7] == 'o' && |
| 8873 | name[8] == 'b' && |
| 8874 | name[9] == 'y' && |
| 8875 | name[10] == 'n' && |
| 8876 | name[11] == 'u' && |
| 8877 | name[12] == 'm' && |
| 8878 | name[13] == 'b' && |
| 8879 | name[14] == 'e' && |
| 8880 | name[15] == 'r') |
| 8881 | { /* getprotobynumber */ |
| 8882 | return -KEY_getprotobynumber; |
| 8883 | } |
| 8884 | |
| 8885 | goto unknown; |
| 8886 | |
| 8887 | default: |
| 8888 | goto unknown; |
| 8889 | } |
| 8890 | |
| 8891 | unknown: |
| 8892 | return 0; |
| 8893 | } |
| 8894 | |
| 8895 | STATIC void |
| 8896 | S_checkcomma(pTHX_ register char *s, char *name, const char *what) |
| 8897 | { |
| 8898 | char *w; |
| 8899 | |
| 8900 | if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */ |
| 8901 | if (ckWARN(WARN_SYNTAX)) { |
| 8902 | int level = 1; |
| 8903 | for (w = s+2; *w && level; w++) { |
| 8904 | if (*w == '(') |
| 8905 | ++level; |
| 8906 | else if (*w == ')') |
| 8907 | --level; |
| 8908 | } |
| 8909 | if (*w) |
| 8910 | for (; *w && isSPACE(*w); w++) ; |
| 8911 | if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */ |
| 8912 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 8913 | "%s (...) interpreted as function",name); |
| 8914 | } |
| 8915 | } |
| 8916 | while (s < PL_bufend && isSPACE(*s)) |
| 8917 | s++; |
| 8918 | if (*s == '(') |
| 8919 | s++; |
| 8920 | while (s < PL_bufend && isSPACE(*s)) |
| 8921 | s++; |
| 8922 | if (isIDFIRST_lazy_if(s,UTF)) { |
| 8923 | w = s++; |
| 8924 | while (isALNUM_lazy_if(s,UTF)) |
| 8925 | s++; |
| 8926 | while (s < PL_bufend && isSPACE(*s)) |
| 8927 | s++; |
| 8928 | if (*s == ',') { |
| 8929 | int kw; |
| 8930 | *s = '\0'; |
| 8931 | kw = keyword(w, s - w) || get_cv(w, FALSE) != 0; |
| 8932 | *s = ','; |
| 8933 | if (kw) |
| 8934 | return; |
| 8935 | Perl_croak(aTHX_ "No comma allowed after %s", what); |
| 8936 | } |
| 8937 | } |
| 8938 | } |
| 8939 | |
| 8940 | /* Either returns sv, or mortalizes sv and returns a new SV*. |
| 8941 | Best used as sv=new_constant(..., sv, ...). |
| 8942 | If s, pv are NULL, calls subroutine with one argument, |
| 8943 | and type is used with error messages only. */ |
| 8944 | |
| 8945 | STATIC SV * |
| 8946 | S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv, |
| 8947 | const char *type) |
| 8948 | { |
| 8949 | dVAR; dSP; |
| 8950 | HV *table = GvHV(PL_hintgv); /* ^H */ |
| 8951 | SV *res; |
| 8952 | SV **cvp; |
| 8953 | SV *cv, *typesv; |
| 8954 | const char *why1, *why2, *why3; |
| 8955 | |
| 8956 | if (!table || !(PL_hints & HINT_LOCALIZE_HH)) { |
| 8957 | SV *msg; |
| 8958 | |
| 8959 | why2 = strEQ(key,"charnames") |
| 8960 | ? "(possibly a missing \"use charnames ...\")" |
| 8961 | : ""; |
| 8962 | msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s", |
| 8963 | (type ? type: "undef"), why2); |
| 8964 | |
| 8965 | /* This is convoluted and evil ("goto considered harmful") |
| 8966 | * but I do not understand the intricacies of all the different |
| 8967 | * failure modes of %^H in here. The goal here is to make |
| 8968 | * the most probable error message user-friendly. --jhi */ |
| 8969 | |
| 8970 | goto msgdone; |
| 8971 | |
| 8972 | report: |
| 8973 | msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s", |
| 8974 | (type ? type: "undef"), why1, why2, why3); |
| 8975 | msgdone: |
| 8976 | yyerror(SvPVX(msg)); |
| 8977 | SvREFCNT_dec(msg); |
| 8978 | return sv; |
| 8979 | } |
| 8980 | cvp = hv_fetch(table, key, strlen(key), FALSE); |
| 8981 | if (!cvp || !SvOK(*cvp)) { |
| 8982 | why1 = "$^H{"; |
| 8983 | why2 = key; |
| 8984 | why3 = "} is not defined"; |
| 8985 | goto report; |
| 8986 | } |
| 8987 | sv_2mortal(sv); /* Parent created it permanently */ |
| 8988 | cv = *cvp; |
| 8989 | if (!pv && s) |
| 8990 | pv = sv_2mortal(newSVpvn(s, len)); |
| 8991 | if (type && pv) |
| 8992 | typesv = sv_2mortal(newSVpv(type, 0)); |
| 8993 | else |
| 8994 | typesv = &PL_sv_undef; |
| 8995 | |
| 8996 | PUSHSTACKi(PERLSI_OVERLOAD); |
| 8997 | ENTER ; |
| 8998 | SAVETMPS; |
| 8999 | |
| 9000 | PUSHMARK(SP) ; |
| 9001 | EXTEND(sp, 3); |
| 9002 | if (pv) |
| 9003 | PUSHs(pv); |
| 9004 | PUSHs(sv); |
| 9005 | if (pv) |
| 9006 | PUSHs(typesv); |
| 9007 | PUTBACK; |
| 9008 | call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL)); |
| 9009 | |
| 9010 | SPAGAIN ; |
| 9011 | |
| 9012 | /* Check the eval first */ |
| 9013 | if (!PL_in_eval && SvTRUE(ERRSV)) { |
| 9014 | STRLEN n_a; |
| 9015 | sv_catpv(ERRSV, "Propagated"); |
| 9016 | yyerror(SvPV(ERRSV, n_a)); /* Duplicates the message inside eval */ |
| 9017 | (void)POPs; |
| 9018 | res = SvREFCNT_inc(sv); |
| 9019 | } |
| 9020 | else { |
| 9021 | res = POPs; |
| 9022 | (void)SvREFCNT_inc(res); |
| 9023 | } |
| 9024 | |
| 9025 | PUTBACK ; |
| 9026 | FREETMPS ; |
| 9027 | LEAVE ; |
| 9028 | POPSTACK; |
| 9029 | |
| 9030 | if (!SvOK(res)) { |
| 9031 | why1 = "Call to &{$^H{"; |
| 9032 | why2 = key; |
| 9033 | why3 = "}} did not return a defined value"; |
| 9034 | sv = res; |
| 9035 | goto report; |
| 9036 | } |
| 9037 | |
| 9038 | return res; |
| 9039 | } |
| 9040 | |
| 9041 | /* Returns a NUL terminated string, with the length of the string written to |
| 9042 | *slp |
| 9043 | */ |
| 9044 | STATIC char * |
| 9045 | S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp) |
| 9046 | { |
| 9047 | register char *d = dest; |
| 9048 | register char *e = d + destlen - 3; /* two-character token, ending NUL */ |
| 9049 | for (;;) { |
| 9050 | if (d >= e) |
| 9051 | Perl_croak(aTHX_ ident_too_long); |
| 9052 | if (isALNUM(*s)) /* UTF handled below */ |
| 9053 | *d++ = *s++; |
| 9054 | else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) { |
| 9055 | *d++ = ':'; |
| 9056 | *d++ = ':'; |
| 9057 | s++; |
| 9058 | } |
| 9059 | else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') { |
| 9060 | *d++ = *s++; |
| 9061 | *d++ = *s++; |
| 9062 | } |
| 9063 | else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
| 9064 | char *t = s + UTF8SKIP(s); |
| 9065 | while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
| 9066 | t += UTF8SKIP(t); |
| 9067 | if (d + (t - s) > e) |
| 9068 | Perl_croak(aTHX_ ident_too_long); |
| 9069 | Copy(s, d, t - s, char); |
| 9070 | d += t - s; |
| 9071 | s = t; |
| 9072 | } |
| 9073 | else { |
| 9074 | *d = '\0'; |
| 9075 | *slp = d - dest; |
| 9076 | return s; |
| 9077 | } |
| 9078 | } |
| 9079 | } |
| 9080 | |
| 9081 | STATIC char * |
| 9082 | S_scan_ident(pTHX_ register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni) |
| 9083 | { |
| 9084 | register char *d; |
| 9085 | register char *e; |
| 9086 | char *bracket = 0; |
| 9087 | char funny = *s++; |
| 9088 | |
| 9089 | if (isSPACE(*s)) |
| 9090 | s = skipspace(s); |
| 9091 | d = dest; |
| 9092 | e = d + destlen - 3; /* two-character token, ending NUL */ |
| 9093 | if (isDIGIT(*s)) { |
| 9094 | while (isDIGIT(*s)) { |
| 9095 | if (d >= e) |
| 9096 | Perl_croak(aTHX_ ident_too_long); |
| 9097 | *d++ = *s++; |
| 9098 | } |
| 9099 | } |
| 9100 | else { |
| 9101 | for (;;) { |
| 9102 | if (d >= e) |
| 9103 | Perl_croak(aTHX_ ident_too_long); |
| 9104 | if (isALNUM(*s)) /* UTF handled below */ |
| 9105 | *d++ = *s++; |
| 9106 | else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) { |
| 9107 | *d++ = ':'; |
| 9108 | *d++ = ':'; |
| 9109 | s++; |
| 9110 | } |
| 9111 | else if (*s == ':' && s[1] == ':') { |
| 9112 | *d++ = *s++; |
| 9113 | *d++ = *s++; |
| 9114 | } |
| 9115 | else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) { |
| 9116 | char *t = s + UTF8SKIP(s); |
| 9117 | while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t)) |
| 9118 | t += UTF8SKIP(t); |
| 9119 | if (d + (t - s) > e) |
| 9120 | Perl_croak(aTHX_ ident_too_long); |
| 9121 | Copy(s, d, t - s, char); |
| 9122 | d += t - s; |
| 9123 | s = t; |
| 9124 | } |
| 9125 | else |
| 9126 | break; |
| 9127 | } |
| 9128 | } |
| 9129 | *d = '\0'; |
| 9130 | d = dest; |
| 9131 | if (*d) { |
| 9132 | if (PL_lex_state != LEX_NORMAL) |
| 9133 | PL_lex_state = LEX_INTERPENDMAYBE; |
| 9134 | return s; |
| 9135 | } |
| 9136 | if (*s == '$' && s[1] && |
| 9137 | (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) ) |
| 9138 | { |
| 9139 | return s; |
| 9140 | } |
| 9141 | if (*s == '{') { |
| 9142 | bracket = s; |
| 9143 | s++; |
| 9144 | } |
| 9145 | else if (ck_uni) |
| 9146 | check_uni(); |
| 9147 | if (s < send) |
| 9148 | *d = *s++; |
| 9149 | d[1] = '\0'; |
| 9150 | if (*d == '^' && *s && isCONTROLVAR(*s)) { |
| 9151 | *d = toCTRL(*s); |
| 9152 | s++; |
| 9153 | } |
| 9154 | if (bracket) { |
| 9155 | if (isSPACE(s[-1])) { |
| 9156 | while (s < send) { |
| 9157 | char ch = *s++; |
| 9158 | if (!SPACE_OR_TAB(ch)) { |
| 9159 | *d = ch; |
| 9160 | break; |
| 9161 | } |
| 9162 | } |
| 9163 | } |
| 9164 | if (isIDFIRST_lazy_if(d,UTF)) { |
| 9165 | d++; |
| 9166 | if (UTF) { |
| 9167 | e = s; |
| 9168 | while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') { |
| 9169 | e += UTF8SKIP(e); |
| 9170 | while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e)) |
| 9171 | e += UTF8SKIP(e); |
| 9172 | } |
| 9173 | Copy(s, d, e - s, char); |
| 9174 | d += e - s; |
| 9175 | s = e; |
| 9176 | } |
| 9177 | else { |
| 9178 | while ((isALNUM(*s) || *s == ':') && d < e) |
| 9179 | *d++ = *s++; |
| 9180 | if (d >= e) |
| 9181 | Perl_croak(aTHX_ ident_too_long); |
| 9182 | } |
| 9183 | *d = '\0'; |
| 9184 | while (s < send && SPACE_OR_TAB(*s)) s++; |
| 9185 | if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) { |
| 9186 | if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) { |
| 9187 | const char *brack = *s == '[' ? "[...]" : "{...}"; |
| 9188 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 9189 | "Ambiguous use of %c{%s%s} resolved to %c%s%s", |
| 9190 | funny, dest, brack, funny, dest, brack); |
| 9191 | } |
| 9192 | bracket++; |
| 9193 | PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK); |
| 9194 | return s; |
| 9195 | } |
| 9196 | } |
| 9197 | /* Handle extended ${^Foo} variables |
| 9198 | * 1999-02-27 mjd-perl-patch@plover.com */ |
| 9199 | else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */ |
| 9200 | && isALNUM(*s)) |
| 9201 | { |
| 9202 | d++; |
| 9203 | while (isALNUM(*s) && d < e) { |
| 9204 | *d++ = *s++; |
| 9205 | } |
| 9206 | if (d >= e) |
| 9207 | Perl_croak(aTHX_ ident_too_long); |
| 9208 | *d = '\0'; |
| 9209 | } |
| 9210 | if (*s == '}') { |
| 9211 | s++; |
| 9212 | if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) { |
| 9213 | PL_lex_state = LEX_INTERPEND; |
| 9214 | PL_expect = XREF; |
| 9215 | } |
| 9216 | if (funny == '#') |
| 9217 | funny = '@'; |
| 9218 | if (PL_lex_state == LEX_NORMAL) { |
| 9219 | if (ckWARN(WARN_AMBIGUOUS) && |
| 9220 | (keyword(dest, d - dest) || get_cv(dest, FALSE))) |
| 9221 | { |
| 9222 | Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS), |
| 9223 | "Ambiguous use of %c{%s} resolved to %c%s", |
| 9224 | funny, dest, funny, dest); |
| 9225 | } |
| 9226 | } |
| 9227 | } |
| 9228 | else { |
| 9229 | s = bracket; /* let the parser handle it */ |
| 9230 | *dest = '\0'; |
| 9231 | } |
| 9232 | } |
| 9233 | else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s)) |
| 9234 | PL_lex_state = LEX_INTERPEND; |
| 9235 | return s; |
| 9236 | } |
| 9237 | |
| 9238 | void |
| 9239 | Perl_pmflag(pTHX_ U32* pmfl, int ch) |
| 9240 | { |
| 9241 | if (ch == 'i') |
| 9242 | *pmfl |= PMf_FOLD; |
| 9243 | else if (ch == 'g') |
| 9244 | *pmfl |= PMf_GLOBAL; |
| 9245 | else if (ch == 'c') |
| 9246 | *pmfl |= PMf_CONTINUE; |
| 9247 | else if (ch == 'o') |
| 9248 | *pmfl |= PMf_KEEP; |
| 9249 | else if (ch == 'm') |
| 9250 | *pmfl |= PMf_MULTILINE; |
| 9251 | else if (ch == 's') |
| 9252 | *pmfl |= PMf_SINGLELINE; |
| 9253 | else if (ch == 'x') |
| 9254 | *pmfl |= PMf_EXTENDED; |
| 9255 | } |
| 9256 | |
| 9257 | STATIC char * |
| 9258 | S_scan_pat(pTHX_ char *start, I32 type) |
| 9259 | { |
| 9260 | PMOP *pm; |
| 9261 | char *s; |
| 9262 | |
| 9263 | s = scan_str(start,FALSE,FALSE); |
| 9264 | if (!s) |
| 9265 | Perl_croak(aTHX_ "Search pattern not terminated"); |
| 9266 | |
| 9267 | pm = (PMOP*)newPMOP(type, 0); |
| 9268 | if (PL_multi_open == '?') |
| 9269 | pm->op_pmflags |= PMf_ONCE; |
| 9270 | if(type == OP_QR) { |
| 9271 | while (*s && strchr("iomsx", *s)) |
| 9272 | pmflag(&pm->op_pmflags,*s++); |
| 9273 | } |
| 9274 | else { |
| 9275 | while (*s && strchr("iogcmsx", *s)) |
| 9276 | pmflag(&pm->op_pmflags,*s++); |
| 9277 | } |
| 9278 | /* issue a warning if /c is specified,but /g is not */ |
| 9279 | if (ckWARN(WARN_REGEXP) && |
| 9280 | (pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)) |
| 9281 | { |
| 9282 | Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_without_g); |
| 9283 | } |
| 9284 | |
| 9285 | pm->op_pmpermflags = pm->op_pmflags; |
| 9286 | |
| 9287 | PL_lex_op = (OP*)pm; |
| 9288 | yylval.ival = OP_MATCH; |
| 9289 | return s; |
| 9290 | } |
| 9291 | |
| 9292 | STATIC char * |
| 9293 | S_scan_subst(pTHX_ char *start) |
| 9294 | { |
| 9295 | dVAR; |
| 9296 | register char *s; |
| 9297 | register PMOP *pm; |
| 9298 | I32 first_start; |
| 9299 | I32 es = 0; |
| 9300 | |
| 9301 | yylval.ival = OP_NULL; |
| 9302 | |
| 9303 | s = scan_str(start,FALSE,FALSE); |
| 9304 | |
| 9305 | if (!s) |
| 9306 | Perl_croak(aTHX_ "Substitution pattern not terminated"); |
| 9307 | |
| 9308 | if (s[-1] == PL_multi_open) |
| 9309 | s--; |
| 9310 | |
| 9311 | first_start = PL_multi_start; |
| 9312 | s = scan_str(s,FALSE,FALSE); |
| 9313 | if (!s) { |
| 9314 | if (PL_lex_stuff) { |
| 9315 | SvREFCNT_dec(PL_lex_stuff); |
| 9316 | PL_lex_stuff = Nullsv; |
| 9317 | } |
| 9318 | Perl_croak(aTHX_ "Substitution replacement not terminated"); |
| 9319 | } |
| 9320 | PL_multi_start = first_start; /* so whole substitution is taken together */ |
| 9321 | |
| 9322 | pm = (PMOP*)newPMOP(OP_SUBST, 0); |
| 9323 | while (*s) { |
| 9324 | if (*s == 'e') { |
| 9325 | s++; |
| 9326 | es++; |
| 9327 | } |
| 9328 | else if (strchr("iogcmsx", *s)) |
| 9329 | pmflag(&pm->op_pmflags,*s++); |
| 9330 | else |
| 9331 | break; |
| 9332 | } |
| 9333 | |
| 9334 | /* /c is not meaningful with s/// */ |
| 9335 | if (ckWARN(WARN_REGEXP) && (pm->op_pmflags & PMf_CONTINUE)) |
| 9336 | { |
| 9337 | Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_in_subst); |
| 9338 | } |
| 9339 | |
| 9340 | if (es) { |
| 9341 | SV *repl; |
| 9342 | PL_sublex_info.super_bufptr = s; |
| 9343 | PL_sublex_info.super_bufend = PL_bufend; |
| 9344 | PL_multi_end = 0; |
| 9345 | pm->op_pmflags |= PMf_EVAL; |
| 9346 | repl = newSVpvn("",0); |
| 9347 | while (es-- > 0) |
| 9348 | sv_catpv(repl, es ? "eval " : "do "); |
| 9349 | sv_catpvn(repl, "{ ", 2); |
| 9350 | sv_catsv(repl, PL_lex_repl); |
| 9351 | sv_catpvn(repl, " };", 2); |
| 9352 | SvEVALED_on(repl); |
| 9353 | SvREFCNT_dec(PL_lex_repl); |
| 9354 | PL_lex_repl = repl; |
| 9355 | } |
| 9356 | |
| 9357 | pm->op_pmpermflags = pm->op_pmflags; |
| 9358 | PL_lex_op = (OP*)pm; |
| 9359 | yylval.ival = OP_SUBST; |
| 9360 | return s; |
| 9361 | } |
| 9362 | |
| 9363 | STATIC char * |
| 9364 | S_scan_trans(pTHX_ char *start) |
| 9365 | { |
| 9366 | register char* s; |
| 9367 | OP *o; |
| 9368 | short *tbl; |
| 9369 | I32 squash; |
| 9370 | I32 del; |
| 9371 | I32 complement; |
| 9372 | |
| 9373 | yylval.ival = OP_NULL; |
| 9374 | |
| 9375 | s = scan_str(start,FALSE,FALSE); |
| 9376 | if (!s) |
| 9377 | Perl_croak(aTHX_ "Transliteration pattern not terminated"); |
| 9378 | if (s[-1] == PL_multi_open) |
| 9379 | s--; |
| 9380 | |
| 9381 | s = scan_str(s,FALSE,FALSE); |
| 9382 | if (!s) { |
| 9383 | if (PL_lex_stuff) { |
| 9384 | SvREFCNT_dec(PL_lex_stuff); |
| 9385 | PL_lex_stuff = Nullsv; |
| 9386 | } |
| 9387 | Perl_croak(aTHX_ "Transliteration replacement not terminated"); |
| 9388 | } |
| 9389 | |
| 9390 | complement = del = squash = 0; |
| 9391 | while (1) { |
| 9392 | switch (*s) { |
| 9393 | case 'c': |
| 9394 | complement = OPpTRANS_COMPLEMENT; |
| 9395 | break; |
| 9396 | case 'd': |
| 9397 | del = OPpTRANS_DELETE; |
| 9398 | break; |
| 9399 | case 's': |
| 9400 | squash = OPpTRANS_SQUASH; |
| 9401 | break; |
| 9402 | default: |
| 9403 | goto no_more; |
| 9404 | } |
| 9405 | s++; |
| 9406 | } |
| 9407 | no_more: |
| 9408 | |
| 9409 | New(803, tbl, complement&&!del?258:256, short); |
| 9410 | o = newPVOP(OP_TRANS, 0, (char*)tbl); |
| 9411 | o->op_private &= ~OPpTRANS_ALL; |
| 9412 | o->op_private |= del|squash|complement| |
| 9413 | (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)| |
| 9414 | (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0); |
| 9415 | |
| 9416 | PL_lex_op = o; |
| 9417 | yylval.ival = OP_TRANS; |
| 9418 | return s; |
| 9419 | } |
| 9420 | |
| 9421 | STATIC char * |
| 9422 | S_scan_heredoc(pTHX_ register char *s) |
| 9423 | { |
| 9424 | SV *herewas; |
| 9425 | I32 op_type = OP_SCALAR; |
| 9426 | I32 len; |
| 9427 | SV *tmpstr; |
| 9428 | char term; |
| 9429 | const char newline[] = "\n"; |
| 9430 | const char *found_newline; |
| 9431 | register char *d; |
| 9432 | register char *e; |
| 9433 | char *peek; |
| 9434 | int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR)); |
| 9435 | |
| 9436 | s += 2; |
| 9437 | d = PL_tokenbuf; |
| 9438 | e = PL_tokenbuf + sizeof PL_tokenbuf - 1; |
| 9439 | if (!outer) |
| 9440 | *d++ = '\n'; |
| 9441 | for (peek = s; SPACE_OR_TAB(*peek); peek++) ; |
| 9442 | if (*peek == '`' || *peek == '\'' || *peek =='"') { |
| 9443 | s = peek; |
| 9444 | term = *s++; |
| 9445 | s = delimcpy(d, e, s, PL_bufend, term, &len); |
| 9446 | d += len; |
| 9447 | if (s < PL_bufend) |
| 9448 | s++; |
| 9449 | } |
| 9450 | else { |
| 9451 | if (*s == '\\') |
| 9452 | s++, term = '\''; |
| 9453 | else |
| 9454 | term = '"'; |
| 9455 | if (!isALNUM_lazy_if(s,UTF)) |
| 9456 | deprecate_old("bare << to mean <<\"\""); |
| 9457 | for (; isALNUM_lazy_if(s,UTF); s++) { |
| 9458 | if (d < e) |
| 9459 | *d++ = *s; |
| 9460 | } |
| 9461 | } |
| 9462 | if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1) |
| 9463 | Perl_croak(aTHX_ "Delimiter for here document is too long"); |
| 9464 | *d++ = '\n'; |
| 9465 | *d = '\0'; |
| 9466 | len = d - PL_tokenbuf; |
| 9467 | #ifndef PERL_STRICT_CR |
| 9468 | d = strchr(s, '\r'); |
| 9469 | if (d) { |
| 9470 | char *olds = s; |
| 9471 | s = d; |
| 9472 | while (s < PL_bufend) { |
| 9473 | if (*s == '\r') { |
| 9474 | *d++ = '\n'; |
| 9475 | if (*++s == '\n') |
| 9476 | s++; |
| 9477 | } |
| 9478 | else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */ |
| 9479 | *d++ = *s++; |
| 9480 | s++; |
| 9481 | } |
| 9482 | else |
| 9483 | *d++ = *s++; |
| 9484 | } |
| 9485 | *d = '\0'; |
| 9486 | PL_bufend = d; |
| 9487 | SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr)); |
| 9488 | s = olds; |
| 9489 | } |
| 9490 | #endif |
| 9491 | if ( outer || !(found_newline = ninstr(s,PL_bufend,newline,newline+1)) ) { |
| 9492 | herewas = newSVpvn(s,PL_bufend-s); |
| 9493 | } |
| 9494 | else { |
| 9495 | s--; |
| 9496 | herewas = newSVpvn(s,found_newline-s); |
| 9497 | } |
| 9498 | s += SvCUR(herewas); |
| 9499 | |
| 9500 | tmpstr = NEWSV(87,79); |
| 9501 | sv_upgrade(tmpstr, SVt_PVIV); |
| 9502 | if (term == '\'') { |
| 9503 | op_type = OP_CONST; |
| 9504 | SvIV_set(tmpstr, -1); |
| 9505 | } |
| 9506 | else if (term == '`') { |
| 9507 | op_type = OP_BACKTICK; |
| 9508 | SvIV_set(tmpstr, '\\'); |
| 9509 | } |
| 9510 | |
| 9511 | CLINE; |
| 9512 | PL_multi_start = CopLINE(PL_curcop); |
| 9513 | PL_multi_open = PL_multi_close = '<'; |
| 9514 | term = *PL_tokenbuf; |
| 9515 | if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) { |
| 9516 | char *bufptr = PL_sublex_info.super_bufptr; |
| 9517 | char *bufend = PL_sublex_info.super_bufend; |
| 9518 | char *olds = s - SvCUR(herewas); |
| 9519 | s = strchr(bufptr, '\n'); |
| 9520 | if (!s) |
| 9521 | s = bufend; |
| 9522 | d = s; |
| 9523 | while (s < bufend && |
| 9524 | (*s != term || memNE(s,PL_tokenbuf,len)) ) { |
| 9525 | if (*s++ == '\n') |
| 9526 | CopLINE_inc(PL_curcop); |
| 9527 | } |
| 9528 | if (s >= bufend) { |
| 9529 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
| 9530 | missingterm(PL_tokenbuf); |
| 9531 | } |
| 9532 | sv_setpvn(herewas,bufptr,d-bufptr+1); |
| 9533 | sv_setpvn(tmpstr,d+1,s-d); |
| 9534 | s += len - 1; |
| 9535 | sv_catpvn(herewas,s,bufend-s); |
| 9536 | Copy(SvPVX(herewas),bufptr,SvCUR(herewas) + 1,char); |
| 9537 | |
| 9538 | s = olds; |
| 9539 | goto retval; |
| 9540 | } |
| 9541 | else if (!outer) { |
| 9542 | d = s; |
| 9543 | while (s < PL_bufend && |
| 9544 | (*s != term || memNE(s,PL_tokenbuf,len)) ) { |
| 9545 | if (*s++ == '\n') |
| 9546 | CopLINE_inc(PL_curcop); |
| 9547 | } |
| 9548 | if (s >= PL_bufend) { |
| 9549 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
| 9550 | missingterm(PL_tokenbuf); |
| 9551 | } |
| 9552 | sv_setpvn(tmpstr,d+1,s-d); |
| 9553 | s += len - 1; |
| 9554 | CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */ |
| 9555 | |
| 9556 | sv_catpvn(herewas,s,PL_bufend-s); |
| 9557 | sv_setsv(PL_linestr,herewas); |
| 9558 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr); |
| 9559 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 9560 | PL_last_lop = PL_last_uni = Nullch; |
| 9561 | } |
| 9562 | else |
| 9563 | sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */ |
| 9564 | while (s >= PL_bufend) { /* multiple line string? */ |
| 9565 | if (!outer || |
| 9566 | !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { |
| 9567 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
| 9568 | missingterm(PL_tokenbuf); |
| 9569 | } |
| 9570 | CopLINE_inc(PL_curcop); |
| 9571 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 9572 | PL_last_lop = PL_last_uni = Nullch; |
| 9573 | #ifndef PERL_STRICT_CR |
| 9574 | if (PL_bufend - PL_linestart >= 2) { |
| 9575 | if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') || |
| 9576 | (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r')) |
| 9577 | { |
| 9578 | PL_bufend[-2] = '\n'; |
| 9579 | PL_bufend--; |
| 9580 | SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr)); |
| 9581 | } |
| 9582 | else if (PL_bufend[-1] == '\r') |
| 9583 | PL_bufend[-1] = '\n'; |
| 9584 | } |
| 9585 | else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r') |
| 9586 | PL_bufend[-1] = '\n'; |
| 9587 | #endif |
| 9588 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
| 9589 | SV *sv = NEWSV(88,0); |
| 9590 | |
| 9591 | sv_upgrade(sv, SVt_PVMG); |
| 9592 | sv_setsv(sv,PL_linestr); |
| 9593 | (void)SvIOK_on(sv); |
| 9594 | SvIV_set(sv, 0); |
| 9595 | av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv); |
| 9596 | } |
| 9597 | if (*s == term && memEQ(s,PL_tokenbuf,len)) { |
| 9598 | STRLEN off = PL_bufend - 1 - SvPVX(PL_linestr); |
| 9599 | *(SvPVX(PL_linestr) + off ) = ' '; |
| 9600 | sv_catsv(PL_linestr,herewas); |
| 9601 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 9602 | s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */ |
| 9603 | } |
| 9604 | else { |
| 9605 | s = PL_bufend; |
| 9606 | sv_catsv(tmpstr,PL_linestr); |
| 9607 | } |
| 9608 | } |
| 9609 | s++; |
| 9610 | retval: |
| 9611 | PL_multi_end = CopLINE(PL_curcop); |
| 9612 | if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) { |
| 9613 | SvPV_shrink_to_cur(tmpstr); |
| 9614 | } |
| 9615 | SvREFCNT_dec(herewas); |
| 9616 | if (!IN_BYTES) { |
| 9617 | if (UTF && is_utf8_string((U8*)SvPVX(tmpstr), SvCUR(tmpstr))) |
| 9618 | SvUTF8_on(tmpstr); |
| 9619 | else if (PL_encoding) |
| 9620 | sv_recode_to_utf8(tmpstr, PL_encoding); |
| 9621 | } |
| 9622 | PL_lex_stuff = tmpstr; |
| 9623 | yylval.ival = op_type; |
| 9624 | return s; |
| 9625 | } |
| 9626 | |
| 9627 | /* scan_inputsymbol |
| 9628 | takes: current position in input buffer |
| 9629 | returns: new position in input buffer |
| 9630 | side-effects: yylval and lex_op are set. |
| 9631 | |
| 9632 | This code handles: |
| 9633 | |
| 9634 | <> read from ARGV |
| 9635 | <FH> read from filehandle |
| 9636 | <pkg::FH> read from package qualified filehandle |
| 9637 | <pkg'FH> read from package qualified filehandle |
| 9638 | <$fh> read from filehandle in $fh |
| 9639 | <*.h> filename glob |
| 9640 | |
| 9641 | */ |
| 9642 | |
| 9643 | STATIC char * |
| 9644 | S_scan_inputsymbol(pTHX_ char *start) |
| 9645 | { |
| 9646 | register char *s = start; /* current position in buffer */ |
| 9647 | register char *d; |
| 9648 | register char *e; |
| 9649 | char *end; |
| 9650 | I32 len; |
| 9651 | |
| 9652 | d = PL_tokenbuf; /* start of temp holding space */ |
| 9653 | e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */ |
| 9654 | end = strchr(s, '\n'); |
| 9655 | if (!end) |
| 9656 | end = PL_bufend; |
| 9657 | s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */ |
| 9658 | |
| 9659 | /* die if we didn't have space for the contents of the <>, |
| 9660 | or if it didn't end, or if we see a newline |
| 9661 | */ |
| 9662 | |
| 9663 | if (len >= sizeof PL_tokenbuf) |
| 9664 | Perl_croak(aTHX_ "Excessively long <> operator"); |
| 9665 | if (s >= end) |
| 9666 | Perl_croak(aTHX_ "Unterminated <> operator"); |
| 9667 | |
| 9668 | s++; |
| 9669 | |
| 9670 | /* check for <$fh> |
| 9671 | Remember, only scalar variables are interpreted as filehandles by |
| 9672 | this code. Anything more complex (e.g., <$fh{$num}>) will be |
| 9673 | treated as a glob() call. |
| 9674 | This code makes use of the fact that except for the $ at the front, |
| 9675 | a scalar variable and a filehandle look the same. |
| 9676 | */ |
| 9677 | if (*d == '$' && d[1]) d++; |
| 9678 | |
| 9679 | /* allow <Pkg'VALUE> or <Pkg::VALUE> */ |
| 9680 | while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':')) |
| 9681 | d++; |
| 9682 | |
| 9683 | /* If we've tried to read what we allow filehandles to look like, and |
| 9684 | there's still text left, then it must be a glob() and not a getline. |
| 9685 | Use scan_str to pull out the stuff between the <> and treat it |
| 9686 | as nothing more than a string. |
| 9687 | */ |
| 9688 | |
| 9689 | if (d - PL_tokenbuf != len) { |
| 9690 | yylval.ival = OP_GLOB; |
| 9691 | set_csh(); |
| 9692 | s = scan_str(start,FALSE,FALSE); |
| 9693 | if (!s) |
| 9694 | Perl_croak(aTHX_ "Glob not terminated"); |
| 9695 | return s; |
| 9696 | } |
| 9697 | else { |
| 9698 | bool readline_overriden = FALSE; |
| 9699 | GV *gv_readline = Nullgv; |
| 9700 | GV **gvp; |
| 9701 | /* we're in a filehandle read situation */ |
| 9702 | d = PL_tokenbuf; |
| 9703 | |
| 9704 | /* turn <> into <ARGV> */ |
| 9705 | if (!len) |
| 9706 | Copy("ARGV",d,5,char); |
| 9707 | |
| 9708 | /* Check whether readline() is overriden */ |
| 9709 | if (((gv_readline = gv_fetchpv("readline", FALSE, SVt_PVCV)) |
| 9710 | && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)) |
| 9711 | || |
| 9712 | ((gvp = (GV**)hv_fetch(PL_globalstash, "readline", 8, FALSE)) |
| 9713 | && (gv_readline = *gvp) != (GV*)&PL_sv_undef |
| 9714 | && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))) |
| 9715 | readline_overriden = TRUE; |
| 9716 | |
| 9717 | /* if <$fh>, create the ops to turn the variable into a |
| 9718 | filehandle |
| 9719 | */ |
| 9720 | if (*d == '$') { |
| 9721 | I32 tmp; |
| 9722 | |
| 9723 | /* try to find it in the pad for this block, otherwise find |
| 9724 | add symbol table ops |
| 9725 | */ |
| 9726 | if ((tmp = pad_findmy(d)) != NOT_IN_PAD) { |
| 9727 | if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) { |
| 9728 | SV *sym = sv_2mortal( |
| 9729 | newSVpv(HvNAME(PAD_COMPNAME_OURSTASH(tmp)),0)); |
| 9730 | sv_catpvn(sym, "::", 2); |
| 9731 | sv_catpv(sym, d+1); |
| 9732 | d = SvPVX(sym); |
| 9733 | goto intro_sym; |
| 9734 | } |
| 9735 | else { |
| 9736 | OP *o = newOP(OP_PADSV, 0); |
| 9737 | o->op_targ = tmp; |
| 9738 | PL_lex_op = readline_overriden |
| 9739 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, |
| 9740 | append_elem(OP_LIST, o, |
| 9741 | newCVREF(0, newGVOP(OP_GV,0,gv_readline)))) |
| 9742 | : (OP*)newUNOP(OP_READLINE, 0, o); |
| 9743 | } |
| 9744 | } |
| 9745 | else { |
| 9746 | GV *gv; |
| 9747 | ++d; |
| 9748 | intro_sym: |
| 9749 | gv = gv_fetchpv(d, |
| 9750 | (PL_in_eval |
| 9751 | ? (GV_ADDMULTI | GV_ADDINEVAL) |
| 9752 | : GV_ADDMULTI), |
| 9753 | SVt_PV); |
| 9754 | PL_lex_op = readline_overriden |
| 9755 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, |
| 9756 | append_elem(OP_LIST, |
| 9757 | newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)), |
| 9758 | newCVREF(0, newGVOP(OP_GV, 0, gv_readline)))) |
| 9759 | : (OP*)newUNOP(OP_READLINE, 0, |
| 9760 | newUNOP(OP_RV2SV, 0, |
| 9761 | newGVOP(OP_GV, 0, gv))); |
| 9762 | } |
| 9763 | if (!readline_overriden) |
| 9764 | PL_lex_op->op_flags |= OPf_SPECIAL; |
| 9765 | /* we created the ops in PL_lex_op, so make yylval.ival a null op */ |
| 9766 | yylval.ival = OP_NULL; |
| 9767 | } |
| 9768 | |
| 9769 | /* If it's none of the above, it must be a literal filehandle |
| 9770 | (<Foo::BAR> or <FOO>) so build a simple readline OP */ |
| 9771 | else { |
| 9772 | GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO); |
| 9773 | PL_lex_op = readline_overriden |
| 9774 | ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED, |
| 9775 | append_elem(OP_LIST, |
| 9776 | newGVOP(OP_GV, 0, gv), |
| 9777 | newCVREF(0, newGVOP(OP_GV, 0, gv_readline)))) |
| 9778 | : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv)); |
| 9779 | yylval.ival = OP_NULL; |
| 9780 | } |
| 9781 | } |
| 9782 | |
| 9783 | return s; |
| 9784 | } |
| 9785 | |
| 9786 | |
| 9787 | /* scan_str |
| 9788 | takes: start position in buffer |
| 9789 | keep_quoted preserve \ on the embedded delimiter(s) |
| 9790 | keep_delims preserve the delimiters around the string |
| 9791 | returns: position to continue reading from buffer |
| 9792 | side-effects: multi_start, multi_close, lex_repl or lex_stuff, and |
| 9793 | updates the read buffer. |
| 9794 | |
| 9795 | This subroutine pulls a string out of the input. It is called for: |
| 9796 | q single quotes q(literal text) |
| 9797 | ' single quotes 'literal text' |
| 9798 | qq double quotes qq(interpolate $here please) |
| 9799 | " double quotes "interpolate $here please" |
| 9800 | qx backticks qx(/bin/ls -l) |
| 9801 | ` backticks `/bin/ls -l` |
| 9802 | qw quote words @EXPORT_OK = qw( func() $spam ) |
| 9803 | m// regexp match m/this/ |
| 9804 | s/// regexp substitute s/this/that/ |
| 9805 | tr/// string transliterate tr/this/that/ |
| 9806 | y/// string transliterate y/this/that/ |
| 9807 | ($*@) sub prototypes sub foo ($) |
| 9808 | (stuff) sub attr parameters sub foo : attr(stuff) |
| 9809 | <> readline or globs <FOO>, <>, <$fh>, or <*.c> |
| 9810 | |
| 9811 | In most of these cases (all but <>, patterns and transliterate) |
| 9812 | yylex() calls scan_str(). m// makes yylex() call scan_pat() which |
| 9813 | calls scan_str(). s/// makes yylex() call scan_subst() which calls |
| 9814 | scan_str(). tr/// and y/// make yylex() call scan_trans() which |
| 9815 | calls scan_str(). |
| 9816 | |
| 9817 | It skips whitespace before the string starts, and treats the first |
| 9818 | character as the delimiter. If the delimiter is one of ([{< then |
| 9819 | the corresponding "close" character )]}> is used as the closing |
| 9820 | delimiter. It allows quoting of delimiters, and if the string has |
| 9821 | balanced delimiters ([{<>}]) it allows nesting. |
| 9822 | |
| 9823 | On success, the SV with the resulting string is put into lex_stuff or, |
| 9824 | if that is already non-NULL, into lex_repl. The second case occurs only |
| 9825 | when parsing the RHS of the special constructs s/// and tr/// (y///). |
| 9826 | For convenience, the terminating delimiter character is stuffed into |
| 9827 | SvIVX of the SV. |
| 9828 | */ |
| 9829 | |
| 9830 | STATIC char * |
| 9831 | S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims) |
| 9832 | { |
| 9833 | SV *sv; /* scalar value: string */ |
| 9834 | char *tmps; /* temp string, used for delimiter matching */ |
| 9835 | register char *s = start; /* current position in the buffer */ |
| 9836 | register char term; /* terminating character */ |
| 9837 | register char *to; /* current position in the sv's data */ |
| 9838 | I32 brackets = 1; /* bracket nesting level */ |
| 9839 | bool has_utf8 = FALSE; /* is there any utf8 content? */ |
| 9840 | I32 termcode; /* terminating char. code */ |
| 9841 | U8 termstr[UTF8_MAXBYTES]; /* terminating string */ |
| 9842 | STRLEN termlen; /* length of terminating string */ |
| 9843 | char *last = NULL; /* last position for nesting bracket */ |
| 9844 | |
| 9845 | /* skip space before the delimiter */ |
| 9846 | if (isSPACE(*s)) |
| 9847 | s = skipspace(s); |
| 9848 | |
| 9849 | /* mark where we are, in case we need to report errors */ |
| 9850 | CLINE; |
| 9851 | |
| 9852 | /* after skipping whitespace, the next character is the terminator */ |
| 9853 | term = *s; |
| 9854 | if (!UTF) { |
| 9855 | termcode = termstr[0] = term; |
| 9856 | termlen = 1; |
| 9857 | } |
| 9858 | else { |
| 9859 | termcode = utf8_to_uvchr((U8*)s, &termlen); |
| 9860 | Copy(s, termstr, termlen, U8); |
| 9861 | if (!UTF8_IS_INVARIANT(term)) |
| 9862 | has_utf8 = TRUE; |
| 9863 | } |
| 9864 | |
| 9865 | /* mark where we are */ |
| 9866 | PL_multi_start = CopLINE(PL_curcop); |
| 9867 | PL_multi_open = term; |
| 9868 | |
| 9869 | /* find corresponding closing delimiter */ |
| 9870 | if (term && (tmps = strchr("([{< )]}> )]}>",term))) |
| 9871 | termcode = termstr[0] = term = tmps[5]; |
| 9872 | |
| 9873 | PL_multi_close = term; |
| 9874 | |
| 9875 | /* create a new SV to hold the contents. 87 is leak category, I'm |
| 9876 | assuming. 79 is the SV's initial length. What a random number. */ |
| 9877 | sv = NEWSV(87,79); |
| 9878 | sv_upgrade(sv, SVt_PVIV); |
| 9879 | SvIV_set(sv, termcode); |
| 9880 | (void)SvPOK_only(sv); /* validate pointer */ |
| 9881 | |
| 9882 | /* move past delimiter and try to read a complete string */ |
| 9883 | if (keep_delims) |
| 9884 | sv_catpvn(sv, s, termlen); |
| 9885 | s += termlen; |
| 9886 | for (;;) { |
| 9887 | if (PL_encoding && !UTF) { |
| 9888 | bool cont = TRUE; |
| 9889 | |
| 9890 | while (cont) { |
| 9891 | int offset = s - SvPVX(PL_linestr); |
| 9892 | bool found = sv_cat_decode(sv, PL_encoding, PL_linestr, |
| 9893 | &offset, (char*)termstr, termlen); |
| 9894 | char *ns = SvPVX(PL_linestr) + offset; |
| 9895 | char *svlast = SvEND(sv) - 1; |
| 9896 | |
| 9897 | for (; s < ns; s++) { |
| 9898 | if (*s == '\n' && !PL_rsfp) |
| 9899 | CopLINE_inc(PL_curcop); |
| 9900 | } |
| 9901 | if (!found) |
| 9902 | goto read_more_line; |
| 9903 | else { |
| 9904 | /* handle quoted delimiters */ |
| 9905 | if (SvCUR(sv) > 1 && *(svlast-1) == '\\') { |
| 9906 | char *t; |
| 9907 | for (t = svlast-2; t >= SvPVX(sv) && *t == '\\';) |
| 9908 | t--; |
| 9909 | if ((svlast-1 - t) % 2) { |
| 9910 | if (!keep_quoted) { |
| 9911 | *(svlast-1) = term; |
| 9912 | *svlast = '\0'; |
| 9913 | SvCUR_set(sv, SvCUR(sv) - 1); |
| 9914 | } |
| 9915 | continue; |
| 9916 | } |
| 9917 | } |
| 9918 | if (PL_multi_open == PL_multi_close) { |
| 9919 | cont = FALSE; |
| 9920 | } |
| 9921 | else { |
| 9922 | char *t, *w; |
| 9923 | if (!last) |
| 9924 | last = SvPVX(sv); |
| 9925 | for (w = t = last; t < svlast; w++, t++) { |
| 9926 | /* At here, all closes are "was quoted" one, |
| 9927 | so we don't check PL_multi_close. */ |
| 9928 | if (*t == '\\') { |
| 9929 | if (!keep_quoted && *(t+1) == PL_multi_open) |
| 9930 | t++; |
| 9931 | else |
| 9932 | *w++ = *t++; |
| 9933 | } |
| 9934 | else if (*t == PL_multi_open) |
| 9935 | brackets++; |
| 9936 | |
| 9937 | *w = *t; |
| 9938 | } |
| 9939 | if (w < t) { |
| 9940 | *w++ = term; |
| 9941 | *w = '\0'; |
| 9942 | SvCUR_set(sv, w - SvPVX(sv)); |
| 9943 | } |
| 9944 | last = w; |
| 9945 | if (--brackets <= 0) |
| 9946 | cont = FALSE; |
| 9947 | } |
| 9948 | } |
| 9949 | } |
| 9950 | if (!keep_delims) { |
| 9951 | SvCUR_set(sv, SvCUR(sv) - 1); |
| 9952 | *SvEND(sv) = '\0'; |
| 9953 | } |
| 9954 | break; |
| 9955 | } |
| 9956 | |
| 9957 | /* extend sv if need be */ |
| 9958 | SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1); |
| 9959 | /* set 'to' to the next character in the sv's string */ |
| 9960 | to = SvPVX(sv)+SvCUR(sv); |
| 9961 | |
| 9962 | /* if open delimiter is the close delimiter read unbridle */ |
| 9963 | if (PL_multi_open == PL_multi_close) { |
| 9964 | for (; s < PL_bufend; s++,to++) { |
| 9965 | /* embedded newlines increment the current line number */ |
| 9966 | if (*s == '\n' && !PL_rsfp) |
| 9967 | CopLINE_inc(PL_curcop); |
| 9968 | /* handle quoted delimiters */ |
| 9969 | if (*s == '\\' && s+1 < PL_bufend && term != '\\') { |
| 9970 | if (!keep_quoted && s[1] == term) |
| 9971 | s++; |
| 9972 | /* any other quotes are simply copied straight through */ |
| 9973 | else |
| 9974 | *to++ = *s++; |
| 9975 | } |
| 9976 | /* terminate when run out of buffer (the for() condition), or |
| 9977 | have found the terminator */ |
| 9978 | else if (*s == term) { |
| 9979 | if (termlen == 1) |
| 9980 | break; |
| 9981 | if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen)) |
| 9982 | break; |
| 9983 | } |
| 9984 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
| 9985 | has_utf8 = TRUE; |
| 9986 | *to = *s; |
| 9987 | } |
| 9988 | } |
| 9989 | |
| 9990 | /* if the terminator isn't the same as the start character (e.g., |
| 9991 | matched brackets), we have to allow more in the quoting, and |
| 9992 | be prepared for nested brackets. |
| 9993 | */ |
| 9994 | else { |
| 9995 | /* read until we run out of string, or we find the terminator */ |
| 9996 | for (; s < PL_bufend; s++,to++) { |
| 9997 | /* embedded newlines increment the line count */ |
| 9998 | if (*s == '\n' && !PL_rsfp) |
| 9999 | CopLINE_inc(PL_curcop); |
| 10000 | /* backslashes can escape the open or closing characters */ |
| 10001 | if (*s == '\\' && s+1 < PL_bufend) { |
| 10002 | if (!keep_quoted && |
| 10003 | ((s[1] == PL_multi_open) || (s[1] == PL_multi_close))) |
| 10004 | s++; |
| 10005 | else |
| 10006 | *to++ = *s++; |
| 10007 | } |
| 10008 | /* allow nested opens and closes */ |
| 10009 | else if (*s == PL_multi_close && --brackets <= 0) |
| 10010 | break; |
| 10011 | else if (*s == PL_multi_open) |
| 10012 | brackets++; |
| 10013 | else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF) |
| 10014 | has_utf8 = TRUE; |
| 10015 | *to = *s; |
| 10016 | } |
| 10017 | } |
| 10018 | /* terminate the copied string and update the sv's end-of-string */ |
| 10019 | *to = '\0'; |
| 10020 | SvCUR_set(sv, to - SvPVX(sv)); |
| 10021 | |
| 10022 | /* |
| 10023 | * this next chunk reads more into the buffer if we're not done yet |
| 10024 | */ |
| 10025 | |
| 10026 | if (s < PL_bufend) |
| 10027 | break; /* handle case where we are done yet :-) */ |
| 10028 | |
| 10029 | #ifndef PERL_STRICT_CR |
| 10030 | if (to - SvPVX(sv) >= 2) { |
| 10031 | if ((to[-2] == '\r' && to[-1] == '\n') || |
| 10032 | (to[-2] == '\n' && to[-1] == '\r')) |
| 10033 | { |
| 10034 | to[-2] = '\n'; |
| 10035 | to--; |
| 10036 | SvCUR_set(sv, to - SvPVX(sv)); |
| 10037 | } |
| 10038 | else if (to[-1] == '\r') |
| 10039 | to[-1] = '\n'; |
| 10040 | } |
| 10041 | else if (to - SvPVX(sv) == 1 && to[-1] == '\r') |
| 10042 | to[-1] = '\n'; |
| 10043 | #endif |
| 10044 | |
| 10045 | read_more_line: |
| 10046 | /* if we're out of file, or a read fails, bail and reset the current |
| 10047 | line marker so we can report where the unterminated string began |
| 10048 | */ |
| 10049 | if (!PL_rsfp || |
| 10050 | !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) { |
| 10051 | sv_free(sv); |
| 10052 | CopLINE_set(PL_curcop, (line_t)PL_multi_start); |
| 10053 | return Nullch; |
| 10054 | } |
| 10055 | /* we read a line, so increment our line counter */ |
| 10056 | CopLINE_inc(PL_curcop); |
| 10057 | |
| 10058 | /* update debugger info */ |
| 10059 | if (PERLDB_LINE && PL_curstash != PL_debstash) { |
| 10060 | SV *sv = NEWSV(88,0); |
| 10061 | |
| 10062 | sv_upgrade(sv, SVt_PVMG); |
| 10063 | sv_setsv(sv,PL_linestr); |
| 10064 | (void)SvIOK_on(sv); |
| 10065 | SvIV_set(sv, 0); |
| 10066 | av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv); |
| 10067 | } |
| 10068 | |
| 10069 | /* having changed the buffer, we must update PL_bufend */ |
| 10070 | PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 10071 | PL_last_lop = PL_last_uni = Nullch; |
| 10072 | } |
| 10073 | |
| 10074 | /* at this point, we have successfully read the delimited string */ |
| 10075 | |
| 10076 | if (!PL_encoding || UTF) { |
| 10077 | if (keep_delims) |
| 10078 | sv_catpvn(sv, s, termlen); |
| 10079 | s += termlen; |
| 10080 | } |
| 10081 | if (has_utf8 || PL_encoding) |
| 10082 | SvUTF8_on(sv); |
| 10083 | |
| 10084 | PL_multi_end = CopLINE(PL_curcop); |
| 10085 | |
| 10086 | /* if we allocated too much space, give some back */ |
| 10087 | if (SvCUR(sv) + 5 < SvLEN(sv)) { |
| 10088 | SvLEN_set(sv, SvCUR(sv) + 1); |
| 10089 | SvPV_renew(sv, SvLEN(sv)); |
| 10090 | } |
| 10091 | |
| 10092 | /* decide whether this is the first or second quoted string we've read |
| 10093 | for this op |
| 10094 | */ |
| 10095 | |
| 10096 | if (PL_lex_stuff) |
| 10097 | PL_lex_repl = sv; |
| 10098 | else |
| 10099 | PL_lex_stuff = sv; |
| 10100 | return s; |
| 10101 | } |
| 10102 | |
| 10103 | /* |
| 10104 | scan_num |
| 10105 | takes: pointer to position in buffer |
| 10106 | returns: pointer to new position in buffer |
| 10107 | side-effects: builds ops for the constant in yylval.op |
| 10108 | |
| 10109 | Read a number in any of the formats that Perl accepts: |
| 10110 | |
| 10111 | \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12. |
| 10112 | \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34 |
| 10113 | 0b[01](_?[01])* |
| 10114 | 0[0-7](_?[0-7])* |
| 10115 | 0x[0-9A-Fa-f](_?[0-9A-Fa-f])* |
| 10116 | |
| 10117 | Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the |
| 10118 | thing it reads. |
| 10119 | |
| 10120 | If it reads a number without a decimal point or an exponent, it will |
| 10121 | try converting the number to an integer and see if it can do so |
| 10122 | without loss of precision. |
| 10123 | */ |
| 10124 | |
| 10125 | char * |
| 10126 | Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp) |
| 10127 | { |
| 10128 | register const char *s = start; /* current position in buffer */ |
| 10129 | register char *d; /* destination in temp buffer */ |
| 10130 | register char *e; /* end of temp buffer */ |
| 10131 | NV nv; /* number read, as a double */ |
| 10132 | SV *sv = Nullsv; /* place to put the converted number */ |
| 10133 | bool floatit; /* boolean: int or float? */ |
| 10134 | const char *lastub = 0; /* position of last underbar */ |
| 10135 | static char const number_too_long[] = "Number too long"; |
| 10136 | |
| 10137 | /* We use the first character to decide what type of number this is */ |
| 10138 | |
| 10139 | switch (*s) { |
| 10140 | default: |
| 10141 | Perl_croak(aTHX_ "panic: scan_num"); |
| 10142 | |
| 10143 | /* if it starts with a 0, it could be an octal number, a decimal in |
| 10144 | 0.13 disguise, or a hexadecimal number, or a binary number. */ |
| 10145 | case '0': |
| 10146 | { |
| 10147 | /* variables: |
| 10148 | u holds the "number so far" |
| 10149 | shift the power of 2 of the base |
| 10150 | (hex == 4, octal == 3, binary == 1) |
| 10151 | overflowed was the number more than we can hold? |
| 10152 | |
| 10153 | Shift is used when we add a digit. It also serves as an "are |
| 10154 | we in octal/hex/binary?" indicator to disallow hex characters |
| 10155 | when in octal mode. |
| 10156 | */ |
| 10157 | NV n = 0.0; |
| 10158 | UV u = 0; |
| 10159 | I32 shift; |
| 10160 | bool overflowed = FALSE; |
| 10161 | bool just_zero = TRUE; /* just plain 0 or binary number? */ |
| 10162 | static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 }; |
| 10163 | static const char* const bases[5] = |
| 10164 | { "", "binary", "", "octal", "hexadecimal" }; |
| 10165 | static const char* const Bases[5] = |
| 10166 | { "", "Binary", "", "Octal", "Hexadecimal" }; |
| 10167 | static const char* const maxima[5] = |
| 10168 | { "", |
| 10169 | "0b11111111111111111111111111111111", |
| 10170 | "", |
| 10171 | "037777777777", |
| 10172 | "0xffffffff" }; |
| 10173 | const char *base, *Base, *max; |
| 10174 | |
| 10175 | /* check for hex */ |
| 10176 | if (s[1] == 'x') { |
| 10177 | shift = 4; |
| 10178 | s += 2; |
| 10179 | just_zero = FALSE; |
| 10180 | } else if (s[1] == 'b') { |
| 10181 | shift = 1; |
| 10182 | s += 2; |
| 10183 | just_zero = FALSE; |
| 10184 | } |
| 10185 | /* check for a decimal in disguise */ |
| 10186 | else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E') |
| 10187 | goto decimal; |
| 10188 | /* so it must be octal */ |
| 10189 | else { |
| 10190 | shift = 3; |
| 10191 | s++; |
| 10192 | } |
| 10193 | |
| 10194 | if (*s == '_') { |
| 10195 | if (ckWARN(WARN_SYNTAX)) |
| 10196 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 10197 | "Misplaced _ in number"); |
| 10198 | lastub = s++; |
| 10199 | } |
| 10200 | |
| 10201 | base = bases[shift]; |
| 10202 | Base = Bases[shift]; |
| 10203 | max = maxima[shift]; |
| 10204 | |
| 10205 | /* read the rest of the number */ |
| 10206 | for (;;) { |
| 10207 | /* x is used in the overflow test, |
| 10208 | b is the digit we're adding on. */ |
| 10209 | UV x, b; |
| 10210 | |
| 10211 | switch (*s) { |
| 10212 | |
| 10213 | /* if we don't mention it, we're done */ |
| 10214 | default: |
| 10215 | goto out; |
| 10216 | |
| 10217 | /* _ are ignored -- but warned about if consecutive */ |
| 10218 | case '_': |
| 10219 | if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1) |
| 10220 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 10221 | "Misplaced _ in number"); |
| 10222 | lastub = s++; |
| 10223 | break; |
| 10224 | |
| 10225 | /* 8 and 9 are not octal */ |
| 10226 | case '8': case '9': |
| 10227 | if (shift == 3) |
| 10228 | yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s)); |
| 10229 | /* FALL THROUGH */ |
| 10230 | |
| 10231 | /* octal digits */ |
| 10232 | case '2': case '3': case '4': |
| 10233 | case '5': case '6': case '7': |
| 10234 | if (shift == 1) |
| 10235 | yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s)); |
| 10236 | /* FALL THROUGH */ |
| 10237 | |
| 10238 | case '0': case '1': |
| 10239 | b = *s++ & 15; /* ASCII digit -> value of digit */ |
| 10240 | goto digit; |
| 10241 | |
| 10242 | /* hex digits */ |
| 10243 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': |
| 10244 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': |
| 10245 | /* make sure they said 0x */ |
| 10246 | if (shift != 4) |
| 10247 | goto out; |
| 10248 | b = (*s++ & 7) + 9; |
| 10249 | |
| 10250 | /* Prepare to put the digit we have onto the end |
| 10251 | of the number so far. We check for overflows. |
| 10252 | */ |
| 10253 | |
| 10254 | digit: |
| 10255 | just_zero = FALSE; |
| 10256 | if (!overflowed) { |
| 10257 | x = u << shift; /* make room for the digit */ |
| 10258 | |
| 10259 | if ((x >> shift) != u |
| 10260 | && !(PL_hints & HINT_NEW_BINARY)) { |
| 10261 | overflowed = TRUE; |
| 10262 | n = (NV) u; |
| 10263 | if (ckWARN_d(WARN_OVERFLOW)) |
| 10264 | Perl_warner(aTHX_ packWARN(WARN_OVERFLOW), |
| 10265 | "Integer overflow in %s number", |
| 10266 | base); |
| 10267 | } else |
| 10268 | u = x | b; /* add the digit to the end */ |
| 10269 | } |
| 10270 | if (overflowed) { |
| 10271 | n *= nvshift[shift]; |
| 10272 | /* If an NV has not enough bits in its |
| 10273 | * mantissa to represent an UV this summing of |
| 10274 | * small low-order numbers is a waste of time |
| 10275 | * (because the NV cannot preserve the |
| 10276 | * low-order bits anyway): we could just |
| 10277 | * remember when did we overflow and in the |
| 10278 | * end just multiply n by the right |
| 10279 | * amount. */ |
| 10280 | n += (NV) b; |
| 10281 | } |
| 10282 | break; |
| 10283 | } |
| 10284 | } |
| 10285 | |
| 10286 | /* if we get here, we had success: make a scalar value from |
| 10287 | the number. |
| 10288 | */ |
| 10289 | out: |
| 10290 | |
| 10291 | /* final misplaced underbar check */ |
| 10292 | if (s[-1] == '_') { |
| 10293 | if (ckWARN(WARN_SYNTAX)) |
| 10294 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number"); |
| 10295 | } |
| 10296 | |
| 10297 | sv = NEWSV(92,0); |
| 10298 | if (overflowed) { |
| 10299 | if (ckWARN(WARN_PORTABLE) && n > 4294967295.0) |
| 10300 | Perl_warner(aTHX_ packWARN(WARN_PORTABLE), |
| 10301 | "%s number > %s non-portable", |
| 10302 | Base, max); |
| 10303 | sv_setnv(sv, n); |
| 10304 | } |
| 10305 | else { |
| 10306 | #if UVSIZE > 4 |
| 10307 | if (ckWARN(WARN_PORTABLE) && u > 0xffffffff) |
| 10308 | Perl_warner(aTHX_ packWARN(WARN_PORTABLE), |
| 10309 | "%s number > %s non-portable", |
| 10310 | Base, max); |
| 10311 | #endif |
| 10312 | sv_setuv(sv, u); |
| 10313 | } |
| 10314 | if (just_zero && (PL_hints & HINT_NEW_INTEGER)) |
| 10315 | sv = new_constant(start, s - start, "integer", |
| 10316 | sv, Nullsv, NULL); |
| 10317 | else if (PL_hints & HINT_NEW_BINARY) |
| 10318 | sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL); |
| 10319 | } |
| 10320 | break; |
| 10321 | |
| 10322 | /* |
| 10323 | handle decimal numbers. |
| 10324 | we're also sent here when we read a 0 as the first digit |
| 10325 | */ |
| 10326 | case '1': case '2': case '3': case '4': case '5': |
| 10327 | case '6': case '7': case '8': case '9': case '.': |
| 10328 | decimal: |
| 10329 | d = PL_tokenbuf; |
| 10330 | e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */ |
| 10331 | floatit = FALSE; |
| 10332 | |
| 10333 | /* read next group of digits and _ and copy into d */ |
| 10334 | while (isDIGIT(*s) || *s == '_') { |
| 10335 | /* skip underscores, checking for misplaced ones |
| 10336 | if -w is on |
| 10337 | */ |
| 10338 | if (*s == '_') { |
| 10339 | if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1) |
| 10340 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 10341 | "Misplaced _ in number"); |
| 10342 | lastub = s++; |
| 10343 | } |
| 10344 | else { |
| 10345 | /* check for end of fixed-length buffer */ |
| 10346 | if (d >= e) |
| 10347 | Perl_croak(aTHX_ number_too_long); |
| 10348 | /* if we're ok, copy the character */ |
| 10349 | *d++ = *s++; |
| 10350 | } |
| 10351 | } |
| 10352 | |
| 10353 | /* final misplaced underbar check */ |
| 10354 | if (lastub && s == lastub + 1) { |
| 10355 | if (ckWARN(WARN_SYNTAX)) |
| 10356 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number"); |
| 10357 | } |
| 10358 | |
| 10359 | /* read a decimal portion if there is one. avoid |
| 10360 | 3..5 being interpreted as the number 3. followed |
| 10361 | by .5 |
| 10362 | */ |
| 10363 | if (*s == '.' && s[1] != '.') { |
| 10364 | floatit = TRUE; |
| 10365 | *d++ = *s++; |
| 10366 | |
| 10367 | if (*s == '_') { |
| 10368 | if (ckWARN(WARN_SYNTAX)) |
| 10369 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 10370 | "Misplaced _ in number"); |
| 10371 | lastub = s; |
| 10372 | } |
| 10373 | |
| 10374 | /* copy, ignoring underbars, until we run out of digits. |
| 10375 | */ |
| 10376 | for (; isDIGIT(*s) || *s == '_'; s++) { |
| 10377 | /* fixed length buffer check */ |
| 10378 | if (d >= e) |
| 10379 | Perl_croak(aTHX_ number_too_long); |
| 10380 | if (*s == '_') { |
| 10381 | if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1) |
| 10382 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 10383 | "Misplaced _ in number"); |
| 10384 | lastub = s; |
| 10385 | } |
| 10386 | else |
| 10387 | *d++ = *s; |
| 10388 | } |
| 10389 | /* fractional part ending in underbar? */ |
| 10390 | if (s[-1] == '_') { |
| 10391 | if (ckWARN(WARN_SYNTAX)) |
| 10392 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 10393 | "Misplaced _ in number"); |
| 10394 | } |
| 10395 | if (*s == '.' && isDIGIT(s[1])) { |
| 10396 | /* oops, it's really a v-string, but without the "v" */ |
| 10397 | s = start; |
| 10398 | goto vstring; |
| 10399 | } |
| 10400 | } |
| 10401 | |
| 10402 | /* read exponent part, if present */ |
| 10403 | if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) { |
| 10404 | floatit = TRUE; |
| 10405 | s++; |
| 10406 | |
| 10407 | /* regardless of whether user said 3E5 or 3e5, use lower 'e' */ |
| 10408 | *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */ |
| 10409 | |
| 10410 | /* stray preinitial _ */ |
| 10411 | if (*s == '_') { |
| 10412 | if (ckWARN(WARN_SYNTAX)) |
| 10413 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 10414 | "Misplaced _ in number"); |
| 10415 | lastub = s++; |
| 10416 | } |
| 10417 | |
| 10418 | /* allow positive or negative exponent */ |
| 10419 | if (*s == '+' || *s == '-') |
| 10420 | *d++ = *s++; |
| 10421 | |
| 10422 | /* stray initial _ */ |
| 10423 | if (*s == '_') { |
| 10424 | if (ckWARN(WARN_SYNTAX)) |
| 10425 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 10426 | "Misplaced _ in number"); |
| 10427 | lastub = s++; |
| 10428 | } |
| 10429 | |
| 10430 | /* read digits of exponent */ |
| 10431 | while (isDIGIT(*s) || *s == '_') { |
| 10432 | if (isDIGIT(*s)) { |
| 10433 | if (d >= e) |
| 10434 | Perl_croak(aTHX_ number_too_long); |
| 10435 | *d++ = *s++; |
| 10436 | } |
| 10437 | else { |
| 10438 | if (ckWARN(WARN_SYNTAX) && |
| 10439 | ((lastub && s == lastub + 1) || |
| 10440 | (!isDIGIT(s[1]) && s[1] != '_'))) |
| 10441 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
| 10442 | "Misplaced _ in number"); |
| 10443 | lastub = s++; |
| 10444 | } |
| 10445 | } |
| 10446 | } |
| 10447 | |
| 10448 | |
| 10449 | /* make an sv from the string */ |
| 10450 | sv = NEWSV(92,0); |
| 10451 | |
| 10452 | /* |
| 10453 | We try to do an integer conversion first if no characters |
| 10454 | indicating "float" have been found. |
| 10455 | */ |
| 10456 | |
| 10457 | if (!floatit) { |
| 10458 | UV uv; |
| 10459 | int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv); |
| 10460 | |
| 10461 | if (flags == IS_NUMBER_IN_UV) { |
| 10462 | if (uv <= IV_MAX) |
| 10463 | sv_setiv(sv, uv); /* Prefer IVs over UVs. */ |
| 10464 | else |
| 10465 | sv_setuv(sv, uv); |
| 10466 | } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) { |
| 10467 | if (uv <= (UV) IV_MIN) |
| 10468 | sv_setiv(sv, -(IV)uv); |
| 10469 | else |
| 10470 | floatit = TRUE; |
| 10471 | } else |
| 10472 | floatit = TRUE; |
| 10473 | } |
| 10474 | if (floatit) { |
| 10475 | /* terminate the string */ |
| 10476 | *d = '\0'; |
| 10477 | nv = Atof(PL_tokenbuf); |
| 10478 | sv_setnv(sv, nv); |
| 10479 | } |
| 10480 | |
| 10481 | if ( floatit ? (PL_hints & HINT_NEW_FLOAT) : |
| 10482 | (PL_hints & HINT_NEW_INTEGER) ) |
| 10483 | sv = new_constant(PL_tokenbuf, d - PL_tokenbuf, |
| 10484 | (floatit ? "float" : "integer"), |
| 10485 | sv, Nullsv, NULL); |
| 10486 | break; |
| 10487 | |
| 10488 | /* if it starts with a v, it could be a v-string */ |
| 10489 | case 'v': |
| 10490 | vstring: |
| 10491 | sv = NEWSV(92,5); /* preallocate storage space */ |
| 10492 | s = scan_vstring(s,sv); |
| 10493 | break; |
| 10494 | } |
| 10495 | |
| 10496 | /* make the op for the constant and return */ |
| 10497 | |
| 10498 | if (sv) |
| 10499 | lvalp->opval = newSVOP(OP_CONST, 0, sv); |
| 10500 | else |
| 10501 | lvalp->opval = Nullop; |
| 10502 | |
| 10503 | return (char *)s; |
| 10504 | } |
| 10505 | |
| 10506 | STATIC char * |
| 10507 | S_scan_formline(pTHX_ register char *s) |
| 10508 | { |
| 10509 | register char *eol; |
| 10510 | register char *t; |
| 10511 | SV *stuff = newSVpvn("",0); |
| 10512 | bool needargs = FALSE; |
| 10513 | bool eofmt = FALSE; |
| 10514 | |
| 10515 | while (!needargs) { |
| 10516 | if (*s == '.') { |
| 10517 | /*SUPPRESS 530*/ |
| 10518 | #ifdef PERL_STRICT_CR |
| 10519 | for (t = s+1;SPACE_OR_TAB(*t); t++) ; |
| 10520 | #else |
| 10521 | for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ; |
| 10522 | #endif |
| 10523 | if (*t == '\n' || t == PL_bufend) { |
| 10524 | eofmt = TRUE; |
| 10525 | break; |
| 10526 | } |
| 10527 | } |
| 10528 | if (PL_in_eval && !PL_rsfp) { |
| 10529 | eol = (char *) memchr(s,'\n',PL_bufend-s); |
| 10530 | if (!eol++) |
| 10531 | eol = PL_bufend; |
| 10532 | } |
| 10533 | else |
| 10534 | eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); |
| 10535 | if (*s != '#') { |
| 10536 | for (t = s; t < eol; t++) { |
| 10537 | if (*t == '~' && t[1] == '~' && SvCUR(stuff)) { |
| 10538 | needargs = FALSE; |
| 10539 | goto enough; /* ~~ must be first line in formline */ |
| 10540 | } |
| 10541 | if (*t == '@' || *t == '^') |
| 10542 | needargs = TRUE; |
| 10543 | } |
| 10544 | if (eol > s) { |
| 10545 | sv_catpvn(stuff, s, eol-s); |
| 10546 | #ifndef PERL_STRICT_CR |
| 10547 | if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') { |
| 10548 | char *end = SvPVX(stuff) + SvCUR(stuff); |
| 10549 | end[-2] = '\n'; |
| 10550 | end[-1] = '\0'; |
| 10551 | SvCUR_set(stuff, SvCUR(stuff) - 1); |
| 10552 | } |
| 10553 | #endif |
| 10554 | } |
| 10555 | else |
| 10556 | break; |
| 10557 | } |
| 10558 | s = eol; |
| 10559 | if (PL_rsfp) { |
| 10560 | s = filter_gets(PL_linestr, PL_rsfp, 0); |
| 10561 | PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr); |
| 10562 | PL_bufend = PL_bufptr + SvCUR(PL_linestr); |
| 10563 | PL_last_lop = PL_last_uni = Nullch; |
| 10564 | if (!s) { |
| 10565 | s = PL_bufptr; |
| 10566 | break; |
| 10567 | } |
| 10568 | } |
| 10569 | incline(s); |
| 10570 | } |
| 10571 | enough: |
| 10572 | if (SvCUR(stuff)) { |
| 10573 | PL_expect = XTERM; |
| 10574 | if (needargs) { |
| 10575 | PL_lex_state = LEX_NORMAL; |
| 10576 | PL_nextval[PL_nexttoke].ival = 0; |
| 10577 | force_next(','); |
| 10578 | } |
| 10579 | else |
| 10580 | PL_lex_state = LEX_FORMLINE; |
| 10581 | if (!IN_BYTES) { |
| 10582 | if (UTF && is_utf8_string((U8*)SvPVX(stuff), SvCUR(stuff))) |
| 10583 | SvUTF8_on(stuff); |
| 10584 | else if (PL_encoding) |
| 10585 | sv_recode_to_utf8(stuff, PL_encoding); |
| 10586 | } |
| 10587 | PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff); |
| 10588 | force_next(THING); |
| 10589 | PL_nextval[PL_nexttoke].ival = OP_FORMLINE; |
| 10590 | force_next(LSTOP); |
| 10591 | } |
| 10592 | else { |
| 10593 | SvREFCNT_dec(stuff); |
| 10594 | if (eofmt) |
| 10595 | PL_lex_formbrack = 0; |
| 10596 | PL_bufptr = s; |
| 10597 | } |
| 10598 | return s; |
| 10599 | } |
| 10600 | |
| 10601 | STATIC void |
| 10602 | S_set_csh(pTHX) |
| 10603 | { |
| 10604 | #ifdef CSH |
| 10605 | if (!PL_cshlen) |
| 10606 | PL_cshlen = strlen(PL_cshname); |
| 10607 | #endif |
| 10608 | } |
| 10609 | |
| 10610 | I32 |
| 10611 | Perl_start_subparse(pTHX_ I32 is_format, U32 flags) |
| 10612 | { |
| 10613 | I32 oldsavestack_ix = PL_savestack_ix; |
| 10614 | CV* outsidecv = PL_compcv; |
| 10615 | |
| 10616 | if (PL_compcv) { |
| 10617 | assert(SvTYPE(PL_compcv) == SVt_PVCV); |
| 10618 | } |
| 10619 | SAVEI32(PL_subline); |
| 10620 | save_item(PL_subname); |
| 10621 | SAVESPTR(PL_compcv); |
| 10622 | |
| 10623 | PL_compcv = (CV*)NEWSV(1104,0); |
| 10624 | sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV); |
| 10625 | CvFLAGS(PL_compcv) |= flags; |
| 10626 | |
| 10627 | PL_subline = CopLINE(PL_curcop); |
| 10628 | CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB); |
| 10629 | CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv); |
| 10630 | CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax; |
| 10631 | |
| 10632 | return oldsavestack_ix; |
| 10633 | } |
| 10634 | |
| 10635 | #ifdef __SC__ |
| 10636 | #pragma segment Perl_yylex |
| 10637 | #endif |
| 10638 | int |
| 10639 | Perl_yywarn(pTHX_ const char *s) |
| 10640 | { |
| 10641 | PL_in_eval |= EVAL_WARNONLY; |
| 10642 | yyerror(s); |
| 10643 | PL_in_eval &= ~EVAL_WARNONLY; |
| 10644 | return 0; |
| 10645 | } |
| 10646 | |
| 10647 | int |
| 10648 | Perl_yyerror(pTHX_ const char *s) |
| 10649 | { |
| 10650 | const char *where = NULL; |
| 10651 | const char *context = NULL; |
| 10652 | int contlen = -1; |
| 10653 | SV *msg; |
| 10654 | |
| 10655 | if (!yychar || (yychar == ';' && !PL_rsfp)) |
| 10656 | where = "at EOF"; |
| 10657 | else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 && |
| 10658 | PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) { |
| 10659 | /* |
| 10660 | Only for NetWare: |
| 10661 | The code below is removed for NetWare because it abends/crashes on NetWare |
| 10662 | when the script has error such as not having the closing quotes like: |
| 10663 | if ($var eq "value) |
| 10664 | Checking of white spaces is anyway done in NetWare code. |
| 10665 | */ |
| 10666 | #ifndef NETWARE |
| 10667 | while (isSPACE(*PL_oldoldbufptr)) |
| 10668 | PL_oldoldbufptr++; |
| 10669 | #endif |
| 10670 | context = PL_oldoldbufptr; |
| 10671 | contlen = PL_bufptr - PL_oldoldbufptr; |
| 10672 | } |
| 10673 | else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 && |
| 10674 | PL_oldbufptr != PL_bufptr) { |
| 10675 | /* |
| 10676 | Only for NetWare: |
| 10677 | The code below is removed for NetWare because it abends/crashes on NetWare |
| 10678 | when the script has error such as not having the closing quotes like: |
| 10679 | if ($var eq "value) |
| 10680 | Checking of white spaces is anyway done in NetWare code. |
| 10681 | */ |
| 10682 | #ifndef NETWARE |
| 10683 | while (isSPACE(*PL_oldbufptr)) |
| 10684 | PL_oldbufptr++; |
| 10685 | #endif |
| 10686 | context = PL_oldbufptr; |
| 10687 | contlen = PL_bufptr - PL_oldbufptr; |
| 10688 | } |
| 10689 | else if (yychar > 255) |
| 10690 | where = "next token ???"; |
| 10691 | else if (yychar == -2) { /* YYEMPTY */ |
| 10692 | if (PL_lex_state == LEX_NORMAL || |
| 10693 | (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL)) |
| 10694 | where = "at end of line"; |
| 10695 | else if (PL_lex_inpat) |
| 10696 | where = "within pattern"; |
| 10697 | else |
| 10698 | where = "within string"; |
| 10699 | } |
| 10700 | else { |
| 10701 | SV *where_sv = sv_2mortal(newSVpvn("next char ", 10)); |
| 10702 | if (yychar < 32) |
| 10703 | Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar)); |
| 10704 | else if (isPRINT_LC(yychar)) |
| 10705 | Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar); |
| 10706 | else |
| 10707 | Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255); |
| 10708 | where = SvPVX(where_sv); |
| 10709 | } |
| 10710 | msg = sv_2mortal(newSVpv(s, 0)); |
| 10711 | Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ", |
| 10712 | OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop)); |
| 10713 | if (context) |
| 10714 | Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context); |
| 10715 | else |
| 10716 | Perl_sv_catpvf(aTHX_ msg, "%s\n", where); |
| 10717 | if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) { |
| 10718 | Perl_sv_catpvf(aTHX_ msg, |
| 10719 | " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n", |
| 10720 | (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start); |
| 10721 | PL_multi_end = 0; |
| 10722 | } |
| 10723 | if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX)) |
| 10724 | Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg); |
| 10725 | else |
| 10726 | qerror(msg); |
| 10727 | if (PL_error_count >= 10) { |
| 10728 | if (PL_in_eval && SvCUR(ERRSV)) |
| 10729 | Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n", |
| 10730 | ERRSV, OutCopFILE(PL_curcop)); |
| 10731 | else |
| 10732 | Perl_croak(aTHX_ "%s has too many errors.\n", |
| 10733 | OutCopFILE(PL_curcop)); |
| 10734 | } |
| 10735 | PL_in_my = 0; |
| 10736 | PL_in_my_stash = Nullhv; |
| 10737 | return 0; |
| 10738 | } |
| 10739 | #ifdef __SC__ |
| 10740 | #pragma segment Main |
| 10741 | #endif |
| 10742 | |
| 10743 | STATIC char* |
| 10744 | S_swallow_bom(pTHX_ U8 *s) |
| 10745 | { |
| 10746 | STRLEN slen; |
| 10747 | slen = SvCUR(PL_linestr); |
| 10748 | switch (s[0]) { |
| 10749 | case 0xFF: |
| 10750 | if (s[1] == 0xFE) { |
| 10751 | /* UTF-16 little-endian? (or UTF32-LE?) */ |
| 10752 | if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */ |
| 10753 | Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE"); |
| 10754 | #ifndef PERL_NO_UTF16_FILTER |
| 10755 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n"); |
| 10756 | s += 2; |
| 10757 | utf16le: |
| 10758 | if (PL_bufend > (char*)s) { |
| 10759 | U8 *news; |
| 10760 | I32 newlen; |
| 10761 | |
| 10762 | filter_add(utf16rev_textfilter, NULL); |
| 10763 | New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8); |
| 10764 | utf16_to_utf8_reversed(s, news, |
| 10765 | PL_bufend - (char*)s - 1, |
| 10766 | &newlen); |
| 10767 | sv_setpvn(PL_linestr, (const char*)news, newlen); |
| 10768 | Safefree(news); |
| 10769 | SvUTF8_on(PL_linestr); |
| 10770 | s = (U8*)SvPVX(PL_linestr); |
| 10771 | PL_bufend = SvPVX(PL_linestr) + newlen; |
| 10772 | } |
| 10773 | #else |
| 10774 | Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE"); |
| 10775 | #endif |
| 10776 | } |
| 10777 | break; |
| 10778 | case 0xFE: |
| 10779 | if (s[1] == 0xFF) { /* UTF-16 big-endian? */ |
| 10780 | #ifndef PERL_NO_UTF16_FILTER |
| 10781 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n"); |
| 10782 | s += 2; |
| 10783 | utf16be: |
| 10784 | if (PL_bufend > (char *)s) { |
| 10785 | U8 *news; |
| 10786 | I32 newlen; |
| 10787 | |
| 10788 | filter_add(utf16_textfilter, NULL); |
| 10789 | New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8); |
| 10790 | utf16_to_utf8(s, news, |
| 10791 | PL_bufend - (char*)s, |
| 10792 | &newlen); |
| 10793 | sv_setpvn(PL_linestr, (const char*)news, newlen); |
| 10794 | Safefree(news); |
| 10795 | SvUTF8_on(PL_linestr); |
| 10796 | s = (U8*)SvPVX(PL_linestr); |
| 10797 | PL_bufend = SvPVX(PL_linestr) + newlen; |
| 10798 | } |
| 10799 | #else |
| 10800 | Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE"); |
| 10801 | #endif |
| 10802 | } |
| 10803 | break; |
| 10804 | case 0xEF: |
| 10805 | if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) { |
| 10806 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n"); |
| 10807 | s += 3; /* UTF-8 */ |
| 10808 | } |
| 10809 | break; |
| 10810 | case 0: |
| 10811 | if (slen > 3) { |
| 10812 | if (s[1] == 0) { |
| 10813 | if (s[2] == 0xFE && s[3] == 0xFF) { |
| 10814 | /* UTF-32 big-endian */ |
| 10815 | Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE"); |
| 10816 | } |
| 10817 | } |
| 10818 | else if (s[2] == 0 && s[3] != 0) { |
| 10819 | /* Leading bytes |
| 10820 | * 00 xx 00 xx |
| 10821 | * are a good indicator of UTF-16BE. */ |
| 10822 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n"); |
| 10823 | goto utf16be; |
| 10824 | } |
| 10825 | } |
| 10826 | default: |
| 10827 | if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) { |
| 10828 | /* Leading bytes |
| 10829 | * xx 00 xx 00 |
| 10830 | * are a good indicator of UTF-16LE. */ |
| 10831 | if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n"); |
| 10832 | goto utf16le; |
| 10833 | } |
| 10834 | } |
| 10835 | return (char*)s; |
| 10836 | } |
| 10837 | |
| 10838 | /* |
| 10839 | * restore_rsfp |
| 10840 | * Restore a source filter. |
| 10841 | */ |
| 10842 | |
| 10843 | static void |
| 10844 | restore_rsfp(pTHX_ void *f) |
| 10845 | { |
| 10846 | PerlIO *fp = (PerlIO*)f; |
| 10847 | |
| 10848 | if (PL_rsfp == PerlIO_stdin()) |
| 10849 | PerlIO_clearerr(PL_rsfp); |
| 10850 | else if (PL_rsfp && (PL_rsfp != fp)) |
| 10851 | PerlIO_close(PL_rsfp); |
| 10852 | PL_rsfp = fp; |
| 10853 | } |
| 10854 | |
| 10855 | #ifndef PERL_NO_UTF16_FILTER |
| 10856 | static I32 |
| 10857 | utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
| 10858 | { |
| 10859 | STRLEN old = SvCUR(sv); |
| 10860 | I32 count = FILTER_READ(idx+1, sv, maxlen); |
| 10861 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
| 10862 | "utf16_textfilter(%p): %d %d (%d)\n", |
| 10863 | utf16_textfilter, idx, maxlen, (int) count)); |
| 10864 | if (count) { |
| 10865 | U8* tmps; |
| 10866 | I32 newlen; |
| 10867 | New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8); |
| 10868 | Copy(SvPVX(sv), tmps, old, char); |
| 10869 | utf16_to_utf8((U8*)SvPVX(sv) + old, tmps + old, |
| 10870 | SvCUR(sv) - old, &newlen); |
| 10871 | sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old); |
| 10872 | } |
| 10873 | DEBUG_P({sv_dump(sv);}); |
| 10874 | return SvCUR(sv); |
| 10875 | } |
| 10876 | |
| 10877 | static I32 |
| 10878 | utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen) |
| 10879 | { |
| 10880 | STRLEN old = SvCUR(sv); |
| 10881 | I32 count = FILTER_READ(idx+1, sv, maxlen); |
| 10882 | DEBUG_P(PerlIO_printf(Perl_debug_log, |
| 10883 | "utf16rev_textfilter(%p): %d %d (%d)\n", |
| 10884 | utf16rev_textfilter, idx, maxlen, (int) count)); |
| 10885 | if (count) { |
| 10886 | U8* tmps; |
| 10887 | I32 newlen; |
| 10888 | New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8); |
| 10889 | Copy(SvPVX(sv), tmps, old, char); |
| 10890 | utf16_to_utf8((U8*)SvPVX(sv) + old, tmps + old, |
| 10891 | SvCUR(sv) - old, &newlen); |
| 10892 | sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old); |
| 10893 | } |
| 10894 | DEBUG_P({ sv_dump(sv); }); |
| 10895 | return count; |
| 10896 | } |
| 10897 | #endif |
| 10898 | |
| 10899 | /* |
| 10900 | Returns a pointer to the next character after the parsed |
| 10901 | vstring, as well as updating the passed in sv. |
| 10902 | |
| 10903 | Function must be called like |
| 10904 | |
| 10905 | sv = NEWSV(92,5); |
| 10906 | s = scan_vstring(s,sv); |
| 10907 | |
| 10908 | The sv should already be large enough to store the vstring |
| 10909 | passed in, for performance reasons. |
| 10910 | |
| 10911 | */ |
| 10912 | |
| 10913 | char * |
| 10914 | Perl_scan_vstring(pTHX_ const char *s, SV *sv) |
| 10915 | { |
| 10916 | const char *pos = s; |
| 10917 | const char *start = s; |
| 10918 | if (*pos == 'v') pos++; /* get past 'v' */ |
| 10919 | while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_')) |
| 10920 | pos++; |
| 10921 | if ( *pos != '.') { |
| 10922 | /* this may not be a v-string if followed by => */ |
| 10923 | const char *next = pos; |
| 10924 | while (next < PL_bufend && isSPACE(*next)) |
| 10925 | ++next; |
| 10926 | if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) { |
| 10927 | /* return string not v-string */ |
| 10928 | sv_setpvn(sv,(char *)s,pos-s); |
| 10929 | return (char *)pos; |
| 10930 | } |
| 10931 | } |
| 10932 | |
| 10933 | if (!isALPHA(*pos)) { |
| 10934 | UV rev; |
| 10935 | U8 tmpbuf[UTF8_MAXBYTES+1]; |
| 10936 | U8 *tmpend; |
| 10937 | |
| 10938 | if (*s == 'v') s++; /* get past 'v' */ |
| 10939 | |
| 10940 | sv_setpvn(sv, "", 0); |
| 10941 | |
| 10942 | for (;;) { |
| 10943 | rev = 0; |
| 10944 | { |
| 10945 | /* this is atoi() that tolerates underscores */ |
| 10946 | const char *end = pos; |
| 10947 | UV mult = 1; |
| 10948 | while (--end >= s) { |
| 10949 | UV orev; |
| 10950 | if (*end == '_') |
| 10951 | continue; |
| 10952 | orev = rev; |
| 10953 | rev += (*end - '0') * mult; |
| 10954 | mult *= 10; |
| 10955 | if (orev > rev && ckWARN_d(WARN_OVERFLOW)) |
| 10956 | Perl_warner(aTHX_ packWARN(WARN_OVERFLOW), |
| 10957 | "Integer overflow in decimal number"); |
| 10958 | } |
| 10959 | } |
| 10960 | #ifdef EBCDIC |
| 10961 | if (rev > 0x7FFFFFFF) |
| 10962 | Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647"); |
| 10963 | #endif |
| 10964 | /* Append native character for the rev point */ |
| 10965 | tmpend = uvchr_to_utf8(tmpbuf, rev); |
| 10966 | sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf); |
| 10967 | if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev))) |
| 10968 | SvUTF8_on(sv); |
| 10969 | if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1])) |
| 10970 | s = ++pos; |
| 10971 | else { |
| 10972 | s = pos; |
| 10973 | break; |
| 10974 | } |
| 10975 | while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_')) |
| 10976 | pos++; |
| 10977 | } |
| 10978 | SvPOK_on(sv); |
| 10979 | sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start); |
| 10980 | SvRMAGICAL_on(sv); |
| 10981 | } |
| 10982 | return (char *)s; |
| 10983 | } |
| 10984 | |
| 10985 | /* |
| 10986 | * Local variables: |
| 10987 | * c-indentation-style: bsd |
| 10988 | * c-basic-offset: 4 |
| 10989 | * indent-tabs-mode: t |
| 10990 | * End: |
| 10991 | * |
| 10992 | * vim: shiftwidth=4: |
| 10993 | */ |