Referencing issues #1015
-
Hi, I am writing the grammar for the DSL language and making a langium-client to generate from my DSL into text. The part of grammar is expressed as below:
The relevant function, built up from AST tree in langium-cli:
The issue is likely lies in here.
I've read the langium documentation about the referencing issues [/discussions/829] and I wonder if my code falls in that scenario. I wonder if the issue is fixed now and there is a solution for this. The textual DSL file works fine without errors, but the code generator does not. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
P/s: The AST for given above piece of code is generated as follow:
|
Beta Was this translation helpful? Give feedback.
-
Hey @LockedAwya, at least with the grammar you have supplied us, I can't reproduce the issue (see this playground link). Langium seems to parse the The issue is likely somewhere else. Can you take a look at the output window of your language server in vscode? It might print a warning about grammar ambiguity, which could explain the behavior you're seeing. If anything, this is related to the parser part of Langium, not the generated code, which are just interface definitions that get erased at runtime anyway. |
Beta Was this translation helpful? Give feedback.
-
@msujew I just notice a reference complexity in the code thanks to the syntax tree in your playground. The syntax tree does not treat stepCS1, stepCS2 and stepCS3 as the same level, instead each latter declared component is treated as a nested component inside the previous declaration. The context grammar is:
That is for example in the content:
The following syntax tree for firstStep is: {
firstStep: {
$type: "StepCS",
stepCS1: {
$type: "UCStepCS",
includedUC: Reference('/elements@1')
},
nextStep: {
$type: "StepCSTemp",
stepCS3: {
$type: "ActorStepCS",
isActorStep: true,
name: "s1"
},
nextStep: {
$type: "StepCS",
stepCS2: {
$type: "RejoinStepCS",
rejoinTo: "s1"
},
nextStep: {
$type: "StepCSTemp",
stepCS3: {
$type: "ActorStepCS",
isActorStep: true,
name: "s4"
}
}
}
}
}
} If I reorder the content a little bit, that is:
The following syntax tree for firstStep is modified as well: {
firstStep: {
$type: "StepCS",
stepCS3: {
$type: "ActorStepCS",
isActorStep: true,
name: "s1"
},
nextStep: {
$type: "StepCSTemp",
stepCS2: {
$type: "RejoinStepCS",
rejoinTo: "s1"
},
nextStep: {
$type: "StepCS",
stepCS1: {
$type: "UCStepCS",
includedUC: Reference('/elements@1')
},
nextStep: {
$type: "StepCSTemp",
stepCS3: {
$type: "ActorStepCS",
isActorStep: true,
name: "s4"
},
}
}
}
}
} I wonder if there is a way to resolve the "nesting problem"? |
Beta Was this translation helpful? Give feedback.
-
@msujew I figured out to my own references issue. The recursive statement at Changing from this:
To this:
Note that |
Beta Was this translation helpful? Give feedback.
@msujew I figured out to my own references issue. The recursive statement at
(nextStep=StepCSTemp)?
which made the AST atfirstStep
nested. Simply deleting it and modifying several relating parts solved the problem. The ambiguity have nothing to do with this tho.Changing from this:
To this: