feat: Only evaluate grammar.js to grammar.json#4601
feat: Only evaluate grammar.js to grammar.json#4601WillLillis merged 3 commits intotree-sitter:masterfrom
grammar.js to grammar.json#4601Conversation
|
I'd prefer |
|
I thought it would cause confusion with |
|
Yeah, that flag is a bit poorly named. The issue is that "evaluate" is a bit of a meaningless term as it doesn't express the output. |
|
What if we pulled the different "output" types into a single flag expressed as an enum, maybe something like enum GenerateArtifact {
JSON,
Parser,
Lib,
}The to just create the |
|
Hmm. I like that, but if we rethink this, we should also include the input (grammar.js, grammar.json, parser.c) into the discussion. (And I'm not excited about the name "artifact"; I feel we can come up with a better term.) (I could simplify the nvim-treesitter pipeline if we could |
|
Perhaps "stage" could be a better term than "artifact"? |
And |
|
|
|
Ideally, yes. |
|
Could you tell me how exactly? I can think of multiple ways:
|
|
I don't think it makes sense to add a separate step for this. It's closer to grammar.json, so it should be included in the same step. |
|
I've changed the CLI option to |
|
I like your suggestion of Have you tested if this behaves correctly when giving an argument (such as |
|
Maybe |
WillLillis
left a comment
There was a problem hiding this comment.
Looks good, I left a few comments.
WillLillis
left a comment
There was a problem hiding this comment.
Changes LGTM. When you get a chance, could you squash the last 4 commits into the appropriate changes from the first 3? Happy to merge once that's cleaned up, thanks for the PR!
This adds an `--evaluate-only` option to `tree-sitter generate` so that it only does the evaluation of `grammar.js` to `src/grammar.json`, without continuing on with the generation of `src/parser.c` and related files. It's a follow-up to tree-sitter#4580.
|
@wetneb looking back at this (and noticing how the lib variant makes no sense....), is this even needed? I would recommend grammars commit |
|
This PR was mostly designed to enable #4646. The use cases I have in mind are:
|
|
The makefile is its own thing, we don't really care about that (and the makefile can easily call generate then build, so no need to change the CLI). Do you have benchmarks that show that skipping the parser generation makes a significant difference (order of minutes)? |
|
Changing the Makefile only was indeed my first approach, in #4580. It was requested by @WillLillis (here) and @ObserverOfTime (here) that we first change the CLI to avoid the double generation of artifacts, which also makes sense to me. If you would rather do it differently (or not at all), I'm sure you can revert my changes - no hard feelings about that on my side :) |
|
Yeah I'd rather update the Makefile/CMake, I'm not totally against having an early exit for |
|
Some parsers take a rather long time to generate. Regardless of where the bottleneck lies, running the entire generation process twice is not desirable. If we want to have separate steps in make/CMake (which I do like having), they need to be separate steps in the generate command as well. |
|
Why not just unify it in the make/cmake files (why even generate twice)? |
|
Can you give an example of the Makefile rules you would use? It would help me understand the solution you have in mind. |
We used to generate from |
|
I think we need to partially revert this; @amaanq Note that even with a native JS runtime, working from evaluated JSON as an intermediate state is still very valuable for grammars that extend other grammars (and hence require |
|
We should soft deprecate imports from |
This adds an
--evaluate-onlyoption totree-sitter generateso that it only does the evaluation ofgrammar.jstosrc/grammar.json, without continuing on with the generation ofsrc/parser.cand related files.It's a follow-up to #4580.