cli: Adapt default Makefile/CMakeLists to work without grammar.json#4580
cli: Adapt default Makefile/CMakeLists to work without grammar.json#4580wetneb wants to merge 1 commit intotree-sitter:masterfrom
grammar.json#4580Conversation
…json This is a step towards making it easier for folks not to include tree-sitter generated files in grammar repos, as outlined in tree-sitter#930. This makes it possible to run `make` or `cmake` in grammar repos where `grammar.json` hasn't been included, and still get the parser compilation to work. The build scripts still work if `grammar.json` is included. One problem that if `grammar.json` isn't include, the generation process will run twice: * once as `tree-sitter generate grammar.js` * a second time as `tree-sitter generate src/grammar.json` But that's not actually necessary as the first invokation already generates both `src/grammar.json` and `src/parser.c` (plus other files). If that's an issue, one could introduce a parameter to `tree-sitter generate` so that it only does the evaluation from `grammar.js` to `src/grammar.json` and stops there. This would avoid work getting done twice.
Please do track the generated JSON files. This allows consumers to generate the grammar without having node (or npm) installed and also improves the performance. (This is orthogonal to the change here, which makes sense.) |
That is also an interesting idea which would be helpful for a) grammars that track the json but not the parser (and want to enforce this in CI) and b) independently benchmarking the JSON and C generation, which might indicate more opportunities for optimizations. @WillLillis ? |
This would definitely be a nice data point to work with! |
This should be done first. |
|
Nice, thank you all for your feedback! I will look into adding this feature to Concerning the tracking of |
I would argue not -- without running But it's your project -- you do you. But be aware that not having a generated |
Thank you! This makes this PR obsolete, so I'm taking the liberty of closing it. |
I don't think it would make those changes obsolete, as I think those changes would still be needed even after
Of course I still run |
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.
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.
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.
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 #4580.
…json This is a new version of tree-sitter#4580, to make it easier not to include tree-sitter generated files in grammar repos, as outlined in tree-sitter#930. This makes it possible to run `make` or `cmake --build .` in grammar repos where `grammar.json` hasn't been included, and still get the parser compilation to work. The build scripts still work if `grammar.json` is included.
This is a step towards making it easier for folks not to include tree-sitter generated files in grammar repos, as outlined in #930.
This makes it possible to run
makeorcmakein grammar repos wheregrammar.jsonhasn't been included, and still get the parser compilation to work. The build scripts still work ifgrammar.jsonis included.One problem that if
grammar.jsonisn't included, the generation process will run twice:tree-sitter generate grammar.jstree-sitter generate src/grammar.jsonBut that's not actually necessary as the first invokation already generates bothsrc/grammar.jsonandsrc/parser.c(plus other files).If that's an issue, one could introduce a parameter to
tree-sitter generateso that it only does the evaluation fromgrammar.jstosrc/grammar.jsonand stops there. This would avoid work getting done twice.This change was suggested to me by @mavit in a grammar I maintain which doesn't track generated files. I'm far from a
makeexpert so I hope this makes sense.