Understanding the Cross Reference feature #467
-
Hello, I'm interested in Langium and I am currently reading the documentation of the grammar, in particular the part about Cross References. I tried something like this to to identify the name by an integer:
but my extension returns this error: "Could not resolve reference to Person named '5'."
Last test I do:
And this time, no error, even if I put a value that does not reference anything. So I find it hard to understand the behavior of the cross-reference. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
HI @theogiraudet, by default, Langium tries to infer the terminal which is used for the name property, which is why it can be omitted. In some cases, this behavior might not be intended. For example, if you want to reference elements in your DSL using a fully qualified name (FQN, dot separated IDs), although their name is simply Regarding the It will probably try to compare a number and a string, and fails, which is why it doesn't resolve. I created a new issue #468 to track this. |
Beta Was this translation helpful? Give feedback.
-
I have a related question. Given the following grammar rules:
If I try to parse the following:
I also get the error I would expect the linker to infer the STRING type from the |
Beta Was this translation helpful? Give feedback.
HI @theogiraudet,
by default, Langium tries to infer the terminal which is used for the name property, which is why it can be omitted. In some cases, this behavior might not be intended. For example, if you want to reference elements in your DSL using a fully qualified name (FQN, dot separated IDs), although their name is simply
ID
. Then you would refer to it usingperson=[Person:FQN]
. Examples can be found in the domain model grammar:https://github.com/langium/langium/blob/8a1d1df07bbae6e2fb14f4f74ebe154402502038/examples/domainmodel/src/language-server/domain-model.langium#L25-L26
Regarding the
INT
issue at hand. This might be an oversight on our end, simply because we usually don't re…