New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maximum call stack size exceeded when using many optional groups #775
Comments
Hello, is somebody working on this? Without this you can't use langium for any serious grammar. |
@tavoda I've provided a fix. We'll probably soon release a version 3.0.1 that contains this fix.
Note that I would strongly disagree with this. We're working quite intensively with Langium and designed some pretty "serious grammars", and so far the only time we've encountered this issue was when we migrated a legacy grammar from Xtext to Langium, which we needed to rewrite anyway. |
@msujew thanks for fix. How I can rewrite such rules? This is of course old XText project which I would like to port but I don't see other options. Please check e.g. DslAttribute: |
@tavoda I'd rewrite all these
These |
It's just moving syntactical rules to semantic layer. For me BNF rules are exactly for this purpose to express as much as possible in syntax. We can rewrite nearly whole grammar (and all C like grammars) to: |
IMO there's a big difference in BNF purely for parsing (i.e. something like a compiler) compared to editing (e.g. Xtext or Langium). In our experience (i.e. at TypeFox), the parser for an editor should allow a lot of "invalid" input, which is then validated against a set of known rules. This serves two purposes:
With that in mind, I think my suggestion serves that grammar better than just embedding all that information into the grammar directly. No offense here, that's exactly what I did when I started out with Xtext. But in my experience, making things more flexible usually leads to a better product/end result.
It's honestly pretty difficult to tell what the purpose of a parser is. To some, it's just validating some string input. Others want a visitor like pattern, that allows them to tell which rule/part of a rule has been called. This is usually the academic perspective. Some even want a full AST. We serve the last requirement together with all the editing and linking services. |
Yes, I'm more on AST side ;-). |
This is such a great take. While immediately obvious to some, this realization took me a while to grasp, but it fundamentally changed how I think about tooling in general. |
Langium version: current master
When using many optional groups
collectInferredTypes
(inferred-types.ts Line: 184) creates many different types. Currently it seems like2ⁿ
where n is number of optional groups.With the node v14 and 17 optional groups a "RangeError" error is thrown. Below is a example grammar for testing:
The text was updated successfully, but these errors were encountered: