Unexpected error when parsing input [message #991430] |
Tue, 18 December 2012 23:23  |
Eclipse User |
|
|
|
I have the following grammar:
grammar org.archstudio.prolog.xtext.Prolog hidden(WHITESPACE)
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate prolog "http://www.archstudio.org/prolog/xtext/Prolog"
TopExpression returns Expression:
exps+=BottomExpression (ops+=Operations exps+=BottomExpression)*;
Operations:
'*' | '/' | '//' | 'rdiv' | '<<' | '>>' | 'mod' | 'rem' ;
BottomExpression returns Expression:
(value=VARIABLE) | '(' exps+=TopExpression ')';
terminal DIGIT:
'0'..'9';
terminal LOWER_CASE_LETTER:
'a'..'z';
terminal UPPER_CASE_LETTER:
'A'..'Z';
terminal WHITESPACE:
(' ' | '\t' | '\r' | '\n')+;
VARIABLE:
LOWER_CASE_LETTER (DIGIT | LOWER_CASE_LETTER | UPPER_CASE_LETTER | '_')*;
However, it cannot parse the input "compatible_directions mod variable2". The parse error that I get is "mismatched character 'c' expecting 'm' at offset: 13". As far as I can tell it's trying to parse "rem" from the "re" in the middle of "directions".
In the grammar above, I can make VARIABLE terminal and it works. But, in the real grammar, I cannot make the VARIABLE rule terminal.
Any idea why xtext is trying to parse "rem" rather than "mod" in the input? Is there a way to fix that?
Any help is greatly appreciated.
Thank you,
-- Scott
|
|
|
|
|
|
Re: Unexpected error when parsing input [message #992111 is a reply to message #991979] |
Thu, 20 December 2012 17:29  |
Eclipse User |
|
|
|
On 2012-20-12 16:34, Scott Hendrickson wrote:
> Thank you Alex and Henrik! I incorporated your suggestions and it works
> now. I guess I need to use more terminal rules.
Not sure what you mean, but in general I would say that you want as few
terminal rules as possible, and that they return tokens that are as long
as possible :)
The more terminal rules you add the greater the risk that they overlap.
The set provided by the standard terminals is a pretty good start.
If you think you need a new terminal, you are probably better of with a
Data rule.
OTOH - if you find that you need to write really complex Data rules (and
many of them), then you may be better of with a custom lexer.
Hope that helps.
Regards
- henrik
|
|
|
Powered by
FUDForum. Page generated in 0.03812 seconds