[inseparable changes from patch from perl5.003_18 to perl5.003_19]
[p5sagit/p5-mst-13.2.git] / toke.c
diff --git a/toke.c b/toke.c
index 7dd35cb..5d53fb3 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -286,6 +286,7 @@ SV *line;
 void
 lex_end()
 {
+    doextract = FALSE;
 }
 
 static void
@@ -1012,7 +1013,7 @@ GV *gv;
     if (gv) {
        if (GvIO(gv))
            return 0;
-       if (!GvCV(gv))
+       if (!GvCVu(gv))
            gv = 0;
     }
     s = scan_word(s, tmpbuf, TRUE, &len);
@@ -1026,7 +1027,7 @@ GV *gv;
     }
     if (!keyword(tmpbuf, len)) {
        indirgv = gv_fetchpv(tmpbuf,FALSE, SVt_PVCV);
-       if (indirgv && GvCV(indirgv))
+       if (indirgv && GvCVu(indirgv))
            return 0;
        /* filehandle or package name makes it a method */
        if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
@@ -1208,7 +1209,7 @@ STRLEN append;
        { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "TERMBLOCK" };
 #endif
 
-extern int yychar;             /* last token */
+EXT int yychar;                /* last token */
 
 int
 yylex()
@@ -1255,7 +1256,7 @@ yylex()
        /* Force them to make up their mind on "@foo". */
        if (pit == '@' && lex_state != LEX_NORMAL && !lex_brackets) {
            GV *gv = gv_fetchpv(tokenbuf+1, FALSE, SVt_PVAV);
-           if (!gv || (tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)) {
+           if (!gv || ((tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv))) {
                char tmpbuf[1024];
                sprintf(tmpbuf, "Literal %s now requires backslash", tokenbuf);
                yyerror(tmpbuf);
@@ -1566,6 +1567,23 @@ yylex()
            if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
                s++;
            if (!in_eval && *s == '#' && s[1] == '!') {
+#ifdef ARG_ZERO_IS_SCRIPT
+               /*
+                * HP-UX (at least) sets argv[0] to the script
+                * name, which makes $^X incorrect.
+                * So, having found "#!", we'll set it right.
+                */
+               GV *x = gv_fetchpv("\030", TRUE, SVt_PV);
+               if (sv_eq(GvSV(x), GvSV(curcop->cop_filegv))) {
+                   char *a = s + 2;
+                   while (*a == ' ' || *a == '\t')
+                       a++;
+                   d = a;
+                   while (*d && !isSPACE(*d))
+                       d++;
+                   sv_setpvn(GvSV(x), a, d - a);
+               }
+#endif /* ARG_ZERO_IS_SCRIPT */
                d = instr(s,"perl -");
                if (!d)
                    d = instr(s,"perl");
@@ -2334,16 +2352,34 @@ yylex()
       keylookup:
        bufptr = s;
        s = scan_word(s, tokenbuf, FALSE, &len);
-       
-       if (*s == ':' && s[1] == ':' && strNE(tokenbuf, "CORE"))
+
+       /* Some keywords can be followed by any delimiter, including ':' */
+       tmp = (len == 1 && strchr("msyq", tokenbuf[0]) ||
+              len == 2 && ((tokenbuf[0] == 't' && tokenbuf[1] == 'r') ||
+                           (tokenbuf[0] == 'q' &&
+                            strchr("qwx", tokenbuf[1]))));
+
+       /* x::* is just a word, unless x is "CORE" */
+       if (!tmp && *s == ':' && s[1] == ':' && strNE(tokenbuf, "CORE"))
            goto just_a_word;
 
+       d = s;
+       while (d < bufend && isSPACE(*d))
+               d++;    /* no comments skipped here, or s### is misparsed */
+
+       /* Is this a label? */
+       if (!tmp && expect == XSTATE
+             && d < bufend && *d == ':' && *(d + 1) != ':') {
+           s = d + 1;
+           yylval.pval = savepv(tokenbuf);
+           CLINE;
+           TOKEN(LABEL);
+       }
+
+       /* Check for keywords */
        tmp = keyword(tokenbuf, len);
 
        /* Is this a word before a => operator? */
-       d = s;
-       while (d < bufend && (*d == ' ' || *d == '\t'))
-               d++;    /* no comments skipped here, or s### is misparsed */
        if (strnEQ(d,"=>",2)) {
            CLINE;
            if (dowarn && (tmp || perl_get_cv(tokenbuf, FALSE)))
@@ -2383,18 +2419,7 @@ yylex()
                        croak("Bad name after %s::", tokenbuf);
                }
 
-               /* Do special processing at start of statement. */
-
-               if (expect == XSTATE) {
-                   while (isSPACE(*s)) s++;
-                   if (*s == ':') {    /* It's a label. */
-                       yylval.pval = savepv(tokenbuf);
-                       s++;
-                       CLINE;
-                       TOKEN(LABEL);
-                   }
-               }
-               else if (expect == XOPERATOR) {
+               if (expect == XOPERATOR) {
                    if (bufptr == linestart) {
                        curcop->cop_line--;
                        warn(warn_nosemi);
@@ -2437,7 +2462,7 @@ yylex()
                    /* (But it's an indir obj regardless for sort.) */
 
                    if ((last_lop_op == OP_SORT ||
-                         (!immediate_paren && (!gv || !GvCV(gv))) ) &&
+                         (!immediate_paren && (!gv || !GvCVu(gv))) ) &&
                         (last_lop_op != OP_MAPSTART && last_lop_op != OP_GREPSTART)){
                        expect = (last_lop == oldoldbufptr) ? XTERM : XOPERATOR;
                        goto bareword;
@@ -2459,7 +2484,7 @@ yylex()
 
                /* If followed by var or block, call it a method (unless sub) */
 
-               if ((*s == '$' || *s == '{') && (!gv || !GvCV(gv))) {
+               if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
                    last_lop = oldbufptr;
                    last_lop_op = OP_METHOD;
                    PREBLOCK(METHOD);
@@ -2472,7 +2497,7 @@ yylex()
 
                /* Not a method, so call it a subroutine (if defined) */
 
-               if (gv && GvCV(gv)) {
+               if (gv && GvCVu(gv)) {
                    CV* cv = GvCV(gv);
                    if (*s == '(') {
                        nextval[nexttoke].opval = yylval.opval;
@@ -4341,8 +4366,6 @@ char *start;
     pm = (PMOP*)newPMOP(OP_MATCH, 0);
     if (multi_open == '?')
        pm->op_pmflags |= PMf_ONCE;
-    if (hints & HINT_LOCALE)
-       pm->op_pmflags |= PMf_LOCALE;
     while (*s && strchr("iogmsx", *s))
        pmflag(&pm->op_pmflags,*s++);
     pm->op_pmpermflags = pm->op_pmflags;
@@ -4570,7 +4593,7 @@ register char *s;
     if (!rsfp) {
        d = s;
        while (s < bufend &&
-         (*s != term || memcmp(s,tokenbuf,len) != 0) ) {
+         (*s != term || memNE(s,tokenbuf,len)) ) {
            if (*s++ == '\n')
                curcop->cop_line++;
        }
@@ -4603,7 +4626,7 @@ register char *s;
              (I32)curcop->cop_line,sv);
        }
        bufend = SvPVX(linestr) + SvCUR(linestr);
-       if (*s == term && memcmp(s,tokenbuf,len) == 0) {
+       if (*s == term && memEQ(s,tokenbuf,len)) {
            s = bufend - 1;
            *s = ' ';
            sv_catsv(linestr,herewas);
@@ -4882,7 +4905,7 @@ char *start;
        }
        *d = '\0';
        sv = NEWSV(92,0);
-       NUMERIC_STANDARD();
+       SET_NUMERIC_STANDARD();
        value = atof(tokenbuf);
        tryi32 = I_32(value);
        if (!floatit && (double)tryi32 == value)