Allow unassigned rule calls after an assignment #205
spoenemann
started this conversation in
Ideas
Replies: 1 comment
-
Currently, there is a workaround for Xtext and Langium:
Such grammar generates:
This syntax imitate behavior of the proposed syntax, however, it allows to grab the only 1 common element
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Xtext forbids an unassigned rule call after an assignment because it uses the assignment as trigger for creating an EClass instance. We could relax this, and with that would gain a big advantage when it comes to factoring out common prefixes.
Example:
The
Entry
rule requires a potentially long lookahead (depending on thePrefix
) rule, which can be bad for the parser performance. An alternative is to write it like this:The downside is that the AST then has two separate objects for
Entry
andContent
, while the original version had a single object whereEntry
is a supertype ofA
,B
andC
. New idea:This would first parse the
Prefix
and then reassign the object$type
to eitherA
,B
orC
without creating a separate object. We have extracted the common prefix without modifying the AST.This has limitations:
What shall we do here? Parse A, then reassign the type to B, and then again to C? We could constrain unassigned rule calls to a single set of alternatives per rule.
Beta Was this translation helpful? Give feedback.
All reactions