I'm running into a problem with a complex complex grammar in a problem that I'm building. Very complicated to post here, so I have helped to understand my problem.
I get the following error:
error (201): .. /org.xtext.example.mydsl.ui/src-gen/org/xtext/ Example / mydsl / ui / contentassist / antlr / internal / InternalMyDsl.g: 398: 12: The following options can never be matched: 2
with this grammar:
grammar org.xtext.example.mydsl.mydsl with org.eclipse.xtext.common.Terminals generate my DSL "http: //Www.xtext.org/example/mydsl/MyDsl" Model: ( Content + = model message) *; Model message: Field | Assignment Stable | class ; Stable: "static" type = typedf name = id; Class: "class" name = id "{" (field + = field) * "}"; Field: "var" type = TypeDef name = id; TypeDef: {Primitive} ("string" | "int") | {Object} clause = [class]; Reference: ({StaticField} static = [stable] (withDiamond? ""> ;)? | {DynamicField} Field = [field]); Object Reference: Reference = Reference ({ObjectReference.target = Current} . 'Context = reference) *; assignment: field = object reference "=" value = object reference;
I know that the problem is related to the context
Which rule has been chosen, it is battling ambiguity.
I can get it compile with changes in the following grammar , But it allows syntax which I consider to be invalid:
context: ref = [refType] (withDiamond? = "
Where is my use-case:
Stable string is a class person {string name} person Paul // It should be legal Paul. Name = a & lt; & gt ;; // This should not be illegal diamond against illegal war, paul.name = paul.name & lt; & gt ;; // It may be legal paul.name = paul. Name
Your second grammar is the way to go. The fact is that there is only legal for diamond static variables, it can be handled in the validator of your language.
Generally, loosen your grammar and make your verification tough, it is easy to maintain your grammar, it also gives a better error message to your users ("for invalid input" "non" Diamand is not allowed for steady wars "& lt; '")
Comments
Post a Comment