Integrating Langium with a UI Editor like React-flow #1373
-
I am using Langium to define a DSL that will consist of operators. As an example operator, I have an addition operator that will be expected to take in two numbers Now I want to extract this operator's definition from the Lanigum-generated files and use it in a UI editor (React-flow as an example) that will represent this operator as a node in the UI. The UI will require the operator's keyword, inputs and their types, and the return type. I do see I can get the keywords and input arguments from both the 'ast.ts' and grammar files that Langium generates. But I cannot find a way to specify what return type should be expected from the operator. Is there a way to tell Langium what type of input a rule returns and have Langium add this return type to the rule's metadata in the generated grammar file? I cannot define a return type for the the addition operator because Langium does not seem to support return types for normal parser rules. Another option I was considering is if there is a way to add additional metadata for each parser rule such that it is added to the data generated in the grammar file. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hey @Lemour-sudo, first off - Langium is not a modelling framework and trying to use it as such isn't exactly recommended. That being said, the type information for a given grammar is derived in here. You can use the code yourself to derive additional information about your own grammar types at runtime if needed.
You should be able to adjust the return type by using declared types. Alternatively you can use the |
Beta Was this translation helpful? Give feedback.
You would need to write a type system yourself. Type systems effectively sit on top of a parsed AST and provide additional information about types of the parsed AST elements. I would recommend you to take a look at our Lox example language repo and especially the type system related code.
The lox language itself is from the crafting interpreters book. I can only recommend to take a look at that if you're completely new to anything compiler related.
Pro…