Accept only a single file as grammar#6
Conversation
elliottt
left a comment
There was a problem hiding this comment.
Seems reasonable to me, thanks!
|
I'll have a look at the doctest failures today and ping you when I have a solution. |
|
Tests should pass if you rebase on main. |
1a2f91c to
9b22187
Compare
|
The more I look at this, the less I'm certain that this is a good idea :) |
|
Now that I'm looking at my own use of this again, I do make use of the multiple files per grammar. Specifically, I make use of the |
|
What do you think about making the second change you suggested in the description, and updating the example to include the singleton list for the grammar file instead? |
|
I think in the end the I feel like the current logic is too subtle and needs changing: selecting the first file from the list as the main file is virtually never done in bazel rules. Looking at some prior art:
There needs to be a way to specify extra files, in particular there are extra .js file to extend another grammar, and also there is an extra scanner.c (or scanner.cc) that tree-sitter supports https://tree-sitter.github.io/tree-sitter/creating-parsers#external-scanners. Extending another grammar is essentially depending on another grammar so it should probably use a # In one folder
tree_sitter_cc_library(
name = "c",
grammar = "grammar.js",
)
# In another folder
tree_sitter_cc_library(
name = "cpp",
grammar = "grammar.js",
deps = ["//c"],
)Unfortunately, at this point I don't know if this suggestion is viable at all because I don't know enough about node and rules_js. This might require a proper integration with rules_js and a different user api. In the meantime, while we figure out the best way to depend on other grammars, we can
|
|
I like your first suggestion, thanks for the write-up! For the future where we allow depending on other |
|
I think that's a great idea. I would wait and see, however, how the |
|
I'm all for adding a provider even if it's not for supporting this specific use-case. Do you already have an implementation on your fork that you'd be interested in upstreaming? |
This might have been the intention considering that only the first element of the label_list is used and the README doesn't have the
[]:rules_tree_sitter/README.md
Lines 35 to 38 in 8e248d1
The alternative is that the README is wrong and needs to say
grammar = ["grammar.js"].