|Re: two grammar rules should be independent [message #872691 is a reply to message #872528]
||Wed, 16 May 2012 15:51
| Henrik Lindberg
Registered: July 2009
On 2012-16-05 11:20, Mikael Karpberg wrote:|
> Hello, Tim!
> What's happening is that all explicit strings you put into your grammar
> turn into keywords (including the 'e', if you implement doubles with
> scientific notation the way it's recommended, i.e. via datatype rules,
> so I made mine a terminal anyway).
> I have the same problem with some of my grammar... I want to have a an
> identifier at a place in the grammar and then continue parsing down one
> path only if that identifier is a certain string, without it turning
> into a keyword, since the keyword can then not be used as an identifier
> in other places in the grammar. The reason in my cases is that I'm
> implementing an already designed DSL that's parsed in a more flexible
> framework elsewhere.
The standard solution would be to have a MyID that is ID | your keywords
and use that instead of ID.
MyID : ID | ExKeyword ;
You then need to take care of coloring of the ExKeywords when they are
used as identifiers.
> Anyway, I hope that at least helps you figure out what's going wrong.
> I'm afraid I don't have a solution for you, except this:
> typ=Event |
> key=('okay' | 'OKAY' | 'ERROR' | 'CRITERR' | 'TIMEOUT' | 'ABORT' |
> Event hidden(UTS_COMMENT):
> type='event' WS ('-d'|'-e') WS (ID | ExKeyword)+ WS*
Depending on the rest of the grammar the '-d' and '-e' may give you
problems. You could instead do '-' ID and validate that the ID is a 'd'
or an 'e'.
Powered by FUDForum
. Page generated in 0.01766 seconds