Creating separate objects for multiple identifiers #1050
-
Hello everyone, I am working on a DSL for defining communication protocols. I have encountered a problem while defining the grammar of this language. One of the entities in this DSL is called "principal", and, as is the case with traditional programming languages, I would like to be able to declare multiple "principals" in a single statement, like this:
(similar to "int i, j, k" in Java or other languages) However, I would like the parsing process to create three separate Principal objects, rather than a single Principal object with three identifiers stored in an array. Now, I have written the grammar definition to allow writing this type of statement in the following way:
However, this method of defining the entity does not allow me to do cross-referencing when I use the name of a principal in another part of a file written in my DSL. The underlying problem is that the parser, when encountering a statement like this, creates a Principal object with a "name" field of type "Array<string>." What I want is to write statements where I can declare multiple principals at once, but I want the parser to create separate objects for each principal identifier. In other words, if I write:
I would like three "Principal" objects to be created, each with a single identifier (not one object with three identifiers). To be even more clear, the TypeScript interface to achieve this should look like this:
Currently, the interface generated by Langium for this entity looks like this:
How can I achieve what I have described? Is there a way to do it? If not, do the developers have plans to add support for this type of definition? Thank you in advance for any answers or any form of help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
@MarianBaba |
Beta Was this translation helpful? Give feedback.
A, B and C live in the scope of the Principals object and the default scope provider doesn't know about them outside of this object. You need to make these references available through the local scope mechanism. We have some documentation on that on our website. Look for the fully qualified name scoping guide.