Replies: 2 comments 2 replies
-
Hey @sorawee, interestingly enough, I get a different set of errors when entering
It's kind of difficult to fulfill everyone's expectations with regards to what they expect of the generated AST definitions. I would argue that we do it "correctly" (whatever that means) as a syntactically correct input yields an exact instance of the types generated by the CLI. Invalid input will usually result in some form of malformed AST, but you only need to handle this in the scoping and validation infrastructure. If necessary, you can use a generic type that makes all AST node fields options. Something like Every step that works with an AST that has gone through a successful validation (i.e. for transpilation) is ensured to operate on a syntactically and semantically valid model. Therefore, using a type definition that reflects a valid input is pretty useful, at least for us. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hi! I'm new to Langium, and I would like to know if there's a guideline on how to check for missing nodes.
I could do it in the ad-hoc manner, but it would be very easy to make mistakes and miss the checks. For example, even in the showcase (https://langium.org/showcase/arithmetics/), if you type
b %;
, you will get the error:The second line is an internal error that is surely not meant to surface to users. The problem is that when we write validators, we usually assume that the AST is well-formed, but that assumption is wrong if there's a missing node.
More generally, I feel I have a fundamental misunderstanding of the Langium workflow. The text in the documentation says:
but this is clearly not the case, as the arithmetics showcase shows. The AST could be incomplete even in the validation phase.
Furthermore, the AST type definition generated by Langium is misleading. It makes it appear that the tree is always complete, when in fact,
| undefined
probably should be added everywhere.Am I missing anything?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions