XText suggests left-factoring. Why? [message #1743084] |
Sun, 11 September 2016 19:47 |
|
I have the following model:
grammar com.septentrio.infrastructure.smf.Model with org.eclipse.xtext.common.Terminals
generate language "http://www.septentrio.com/infrastructure/smf/Model"
Model:
('package' name=QualifiedName)?
(imports+=Import)*
(entities+=Entity)*;
Import:
'import' importedNamespace=QualifiedNameWithWildcard;
QualifiedName:
ID ('.' ID)*;
QualifiedNameWithWildcard:
QualifiedName '.*'?;
Entity:
Class|Test;
Class:
'class' name=ID
( '<' (params+=ID','?)+ '>' )?
( 'extends' (parents+=[Class|QualifiedName]','?)+ )?
( '{' (members+=Member)* '}' )?;
Member:
Attribute|Method;
Attribute:
type=ElementType (array='['(length=INT)?']')? name=ID;
Method:
type=ElementType name=ID '()';
ElementType:
BasicType|ClassType;
BasicType:
type=('any'|'enum'|'logical'|'string'|'integer'|'float');
ClassType:
type=[Class|QualifiedName] ( '<' (params+=[Class|QualifiedName]','?)+ '>' )?;
Test:
'test' name=ID '{' (expressions+=Expression)* '}';
Expression:
Primary ({SubscriptReference.operand=current} (indices+=SubscriptIndex)*)?;
Primary returns Expression:
'(' Expression ')' |
{Instance} class=[Class] |
{Metaclass} '?' class=[Class] |
{Identifier} name=ID;
SubscriptIndex:
{DotIndex} '.' name=[Member] |
{ParenthesisIndex} '(' (argument=Expression)? ')';
I get the following error:
[fatal] rule ruleExpression has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
What's wrong?
|
|
|
|
Re: XText suggests left-factoring. Why? [message #1743176 is a reply to message #1743087] |
Tue, 13 September 2016 02:18 |
|
Thanks!
Problem 1:
I solved in a different way
Problem 2:
I had assumed that the parser would only perform the "Instance" action if the string corresponds to an existing "Class". If not it would fallback to the "Identifier" action with any other string. Can I achieve something like that?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03426 seconds