two grammar rules should be independent [message #872519] |
Wed, 16 May 2012 05:06  |
Eclipse User |
|
|
|
Hi Team,
this is a snip out of my code, that makes some kind of trouble.
action:
typ=Event |
typ=Ex
;
Event hidden(UTS_COMMENT):
type='event' WS ('-d'|'-e') WS ID+ WS*
;
Ex hidden(UTS_COMMENT):
type='exit' (WS ('okay' | 'OKAY' | 'ERROR' | 'CRITERR' | 'TIMEOUT' | 'ABORT' | 'TRANS') WS* (value+=NEWmore_strings)?)?
;
This part should recognize the following as an example:
event -d TESTEVENT
exit OKAY
exit ERROR
This works so far. But I get into trouble, if the ID in the "Event" rule contains one of the values from the multiple choice String out of the "Ex" Rule.
From my Point of view these two rules are totaly independent, but they aren't anyway.
The following example should also be 'good', but it isn't recognized as good:
event -d OKAY
exit OKAY
event -d ERROR
exit ERROR
Eclipse tells me:
required (...)+ loop did not match anything at input 'OKAY'
So in my opinion the 'OKAY' is not recognized as an ID, but as a string from the Ex rule, but why.
Thanks in advance.
|
|
|
|
|
Re: two grammar rules should be independent [message #872691 is a reply to message #872528] |
Wed, 16 May 2012 11:51  |
Eclipse User |
|
|
|
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:
>
>
> action:
> typ=Event |
> typ=Ex
> ;
>
> ExKeyword:
> key=('okay' | 'OKAY' | 'ERROR' | 'CRITERR' | 'TIMEOUT' | 'ABORT' |
> 'TRANS');
>
> 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'.
Regards
- henrik
|
|
|
Powered by
FUDForum. Page generated in 0.03445 seconds