tree-sitter-julia
tree-sitter-julia copied to clipboard
Add nodes that mark the content of string literals
This adds additional nodes within string literals and command literals that marks the actual contents of the string itself. This is useful for writing queries that need to do something just with the contents, rather than the entire literal including the quotes, e.g. language injections in Neovim.
Previously you would have to do some #offset! calls within the queries that perform the language injections. Now you can just match against the string_content and raw_string_content nodes directly and avoid having to compute offsets manually.
Some TODOs:
- naming, I've gone with what seemed reasonable:
string_contentandraw_string_content. I couldn't come up with a nice way to unify the node types. Open to suggestions there. - must I commit a
tree-sitter generateto this PR, or is that done separately before a tag is done? - even though this has touched a bunch of test files I'll still be adding some additional ones for some more edge cases if the general approach taken in the implementation is suitable.
Thanks for the PR.
I worked on refactoring string parsing in 803b97f641a67587ba40b6415dc384cca5fda2a0, mainly to fix a couple of bugs, but also to remove the serialization stuff from the scanner. The newer version would conflict somewhat with your suggested string_content rule.
I'm wondering if it'd be enough to alias all the _content_* rules to a visible rule. Since most injections are for macro strings that don't have interpolations.
must I commit a tree-sitter generate to this PR, or is that done separately before a tag is done?
Yes, usually each PR should include its generated parser.c (that's why some PRs are so big). Also, I haven't merged #153 because my homebrew install of tree-sitter got messed up somehow 😖 but I'll fix that next week.
The newer version would conflict somewhat with your suggested
Feel free then to just pull in what changes you would want from this branch 👍
I'm wondering if it'd be enough to alias all the content* rules to a visible rule. Since most injections are for macro strings that don't have interpolations.
Yeah, that might be enough, so long as it allows some way to get at just the string contents that'll be fine.