DataType 'returns' is Potentially Misleading
See original GitHub issueWhile discussing some details yesterday over another project, it came up that the form of writing a DataType rule could mislead new users into thinking it returns a primitive type, rather than the DataType itself. I believe this goes against the notion of having a low barrier to entry for newcomers, as it could confuse and frustrate them.
For example, the following produces a value of the type SomeDataType
, but is in itself a subtype of string. To make this work, we write ‘returns’ like so.
SomeDataType returns string: ID
For somebody unfamiliar with Langium, they may come to believe that SomeDataType actually returns string, given the literal wording. This is further reinforced by our consistent usage of ‘returns’ elsewhere for parser rules & terminals, where this is always the case.
My suggestion is that we at least consider whether we should:
- use a different keyword than returns to signify a subtyping relationship (although internally we just use a type alias).
- allow dropping
returns type
, and being able to infer the super type from utilized keywords, terminal rules, and data type rules - utilize highlighting to distinguish between DataType and ParserRules (this is present in Xtext)
Issue Analytics
- State:
- Created a year ago
- Comments:8 (8 by maintainers)
@luan-xiaokun thanks for chiming in! It’s of particular interest to make sure that new users are able to pick up Langium quite easily 🙂 . We will also be updating our documentation to hopefully make this clearer going forward as well.
If you haven’t read it yet, we do have an entry on Semantic Model Inference that goes more into how Types can declared, or inferred from rules. That may help clear up the difference between the two.
We release the current syntax as v1.0; we should keep it unless we find good reasons to change it.