subtly change meaning of XATTRBLOCK, XATTRTERM
authorDavid Mitchell <davem@iabyn.com>
Mon, 26 Feb 2018 13:50:50 +0000 (13:50 +0000)
committerDavid Mitchell <davem@iabyn.com>
Fri, 2 Mar 2018 13:36:43 +0000 (13:36 +0000)
Currently they tell the toker that the next thing will be attributes,
followed by an XBLOCK or XTERMBLOCK respectively.

This commit subtly changes their meanings so that they indicate that
attributes legally *might* follow. This makes the code which initially
sets them slightly simpler (no need to check whether the next char is
':'), and the code elsewhere in yylex() which handles XATTR* only triggers
if the next char is ':' anyway.

Doing it this way will shortly make detection simpler of an attribute
illegally following a signature.

perl.h
toke.c

diff --git a/perl.h b/perl.h
index deafa0f..82c1858 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -4983,8 +4983,8 @@ typedef enum {
     XREF,
     XSTATE,
     XBLOCK,
-    XATTRBLOCK,
-    XATTRTERM,
+    XATTRBLOCK, /* next token should be an attribute or block */
+    XATTRTERM,  /* next token should be an attribute, or block in a term */
     XTERMBLOCK,
     XBLOCKTERM,
     XPOSTDEREF,
diff --git a/toke.c b/toke.c
index 020a545..df1d7fe 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -8660,7 +8660,6 @@ Perl_yylex(pTHX)
          really_sub:
            {
                char * const tmpbuf = PL_tokenbuf + 1;
-               expectation attrful;
                bool have_name, have_proto;
                const int key = tmp;
                 SV *format_name = NULL;
@@ -8675,8 +8674,7 @@ Perl_yylex(pTHX)
                     || (*s == ':' && s[1] == ':'))
                {
 
-                   PL_expect = XBLOCK;
-                   attrful = XATTRBLOCK;
+                   PL_expect = XATTRBLOCK;
                    d = scan_word(s, tmpbuf, sizeof PL_tokenbuf - 1, TRUE,
                                  &len);
                     if (key == KEY_format)
@@ -8707,8 +8705,7 @@ Perl_yylex(pTHX)
                        Perl_croak(aTHX_
                                  "Missing name in \"%s\"", PL_bufptr);
                    }
-                   PL_expect = XTERMBLOCK;
-                   attrful = XATTRTERM;
+                   PL_expect = XATTRTERM;
                    sv_setpvs(PL_subname,"?");
                    have_name = FALSE;
                }
@@ -8738,9 +8735,9 @@ Perl_yylex(pTHX)
                else
                    have_proto = FALSE;
 
-               if (*s == ':' && s[1] != ':')
-                   PL_expect = attrful;
-               else if ((*s != '{' && *s != '(') && key != KEY_format) {
+               if (  !(*s == ':' && s[1] != ':')
+                    && (*s != '{' && *s != '(') && key != KEY_format)
+                {
                     assert(key == KEY_sub || key == KEY_AUTOLOAD ||
                            key == KEY_DESTROY || key == KEY_BEGIN ||
                            key == KEY_UNITCHECK || key == KEY_CHECK ||