bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bison 3.0: semantic predicates are mis-scanned as invalid directives


From: Rici Lake
Subject: Bison 3.0: semantic predicates are mis-scanned as invalid directives
Date: Sun, 13 Oct 2013 00:32:34 -0500

Bug report comes from SO:
http://stackoverflow.com/questions/19330171/controlling-a-parse-with-arbitrary-predicates-not-working-in-bison

Example failing grammar:

The following was copied from bison manual section 1.5.4. It was minimized
by leaving out second widget production; the two declarations were added to
make it valid. It's not really a minimal example, but the fact that its
verbatim from the bison manual gives it some street-cred.

%glr-parser
%token id new_args
%%
widget:
       %?{  new_syntax } "widget" id new_args  { $$ = f($3, $4); }

Produces the error:

tst.y:5.8-10: error: invalid directive: ‘%?{’
        %?{  new_syntax } "widget" id new_args  { $$ = f($3, $4); }
        ^^^

(and others, resulting from not parsing new_syntax as a code block.)

Problem:

Line 269-271 of scan-gram.l:

  "%"{id}|"%"{notletter}([[:graph:]])+ {
    complain (loc, complaint, _("invalid directive: %s"), quote (yytext));
  }

definition of {notletter} at line 137 of the same file:

notletter [^.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]{-}[%\{]

(I don't understand why the '{' is backslash-escaped inside a character
class, nor why the {-} operator is used rather than just adding % and { to
the list of "letters" in the first character class. But that's not the
problem.)

notletter will match a `?`, so the pattern at line 269 will match `%?{`.
Since the pattern for semantic actions is later in the file (line 317), the
"invalid directive" match takes precedence. Moving line 317 up won't help,
though, because the pattern at 269 will match a longer string if there is
no space after the %?{ in the source file.

Suggested fix:

Add ? to the list of "letters" in the definition of {notletter}. Consider
cleaning up the definition a bit.

Possible workaround until fix is deployed:

Enter semantic predicates with a space after the `?`. This causes the
pattern at line 269 to fail to match, but does not affect the pattern at
line 317 because that pattern allows whitespace after the `?`


reply via email to

[Prev in Thread] Current Thread [Next in Thread]