You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I find that a builder to create an AST programmatically would be helpful for generating code targeting a language built using Langium. My current approach is to use the CompositeGeneratorNode syntax to manually craft text which should be compliant with my language's syntax, however this can be cumbersome and prone to error.
My thought is that if a person implements a formatter for an AST, it should be able to produce the CST and thus spit out valid syntax. The construction of the AST node types however currently requires setting the parent $container of each AST node.
Is there a recommended way to do something like this already, or would adding AST node generator functions/utilities to Langium potentially make sense?
The text was updated successfully, but these errors were encountered:
My thought is that if a person implements a formatter for an AST, it should be able to produce the CST and thus spit out valid syntax.
Note that the current formatter implementation operates on the existing CST, and does not produce a CST (i.e. it simply shifts the existing text nodes, and does not create any nodes).
The construction of the AST node types however currently requires setting the parent $container of each AST node.
You can just set the $container property to undefined! and then run the linkContentToContainer function on everything.
Is there a recommended way to do something like this already, or would adding AST node generator functions/utilities to Langium potentially make sense?
The recommendation is to create a manual serializer right now (as you're already doing). What you're looking for is an automatic serializer. However, building a completely generic, grammar agnostic serializer is really complicated, and while it can be done (see Xtext's serializer), we currently don't have any plans to work on that.
I find that a builder to create an AST programmatically would be helpful for generating code targeting a language built using Langium. My current approach is to use the
CompositeGeneratorNode
syntax to manually craft text which should be compliant with my language's syntax, however this can be cumbersome and prone to error.My thought is that if a person implements a formatter for an AST, it should be able to produce the CST and thus spit out valid syntax. The construction of the AST node types however currently requires setting the parent
$container
of each AST node.Is there a recommended way to do something like this already, or would adding AST node generator functions/utilities to Langium potentially make sense?
The text was updated successfully, but these errors were encountered: