grammar - Xtext: Recursive Rule Inovcations -


i attempting build language can declare methods , fields, intrinsic support generics. able use primitive types string, declare own classes.

this should valid syntax:

string someprimitive  class myclass { } myclass someobject;  class list { } list<string> stringlist; list<myclass> objectlist;  list<string> getnames() { } 

i have grammar supports these operations:

model:     (members+=modelmembers)*;  modelmembers:     class | field | methoddeclaration ;  class:     'class' name=id '{' '}' ;  field:     type=type     name=id ;  enum primitivetype: string="string" | number="number";  type:     (         {typeobject} clazz=[class] ("<" a+=type ("," a+=type)* ">")?          |         {typeprimitive} type=primitivetype      ) ;  methoddeclaration:     returntype=type name=id "(" ")" "{"      "}" ; 

but contains error:

[fatal] rule rule__modelmembers__alternatives has non-ll(*) decision due recursive rule invocations reachable alts 2,3.  resolve left-factoring or using syntactic predicates or using backtrack=true option. 

the problem seems stem fact type rule recursive, , can matches either beginning of methoddeclaration or field.

however, possible figure out rule 1 building, method have () { } after name.

what really confuses me, if replace recursive rule [class], e.g. field: type=[class] name=id (and same methoddeclaration) grammar valid.

i there ambiguity when 1 sees instance of type, lead onto method or field.... that's same when replace [class]. instances of class can lead onto method or field.

how can ambiguous using type, not ambiguous using [class]?

this not direct answer question, did considered using xbase instead of plain xtext? xbase can simple use predefined rules, match need:

  • java types generics
  • expressions
  • annotations

and many more.

here couple of useful links:

if xbase doesn't suite you, can learn it's xbase-xtext-grammar.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -