Massive update (details within) #3
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I fully do not expect this PR to be adopted in its entirety. But I've forked this parser and made some changes, and I feel it would be rude not to at least offer up this work in case any of it looked intriguing.
Problems
Here are the main things I wanted to fix:
keyword
nodes, rather than the more common pattern of treating them as anonymous nodes. The first “word” in every tag was presumed to be a keyword; this offers flexibility for, say, extensions (and could be added back if there were generalized need for such a thing). But these two decisions combine to produce a tree that's very hard to query without adding#match?
predicates everywhere.{{ if }}
and its corresponding{{ /if }}
. That makes it hard to do things like code folding. It's even harder to do proper indentation hinting, since there's nothing built into the Vento syntax that tells me whether or not{{ foo "bar"}}
is a standalone tag or is just a start tag to be followed by an eventual{{ /foo }}
.{{ for value of collection }}
, the parser would claimfor
as thekeyword
and then wrapvalue of collection
in acode
node — but that's not fit to be highlighted by JS on its own, because it isn't valid JavaScript.There are some upsides to the current simplicity; for instance, it means that
highlights.scm
gets to be pretty short. But the price is paid infolds.scm
andindents.scm
, which have to be much larger, since they need to query against the content ofkeyword
nodes as the only way of identifying paired nodes. (And I don't use Neovim, so I don't even know if folds can be properly expressed using their query syntax.)Fixes
This approach definitely has some trade-offs rather than being an unmitigated positive, but I think it's worth it:
export
andset
— are parsed properly.{{for value of collection }}
example from above, onlycollection
is wrapped in acode
node;for
andof
are treated as keywords. This lets me markvalue
as a variable and allowscollection
to instead be any JS of arbitrary complexity, since the JS grammar is in charge of highlighting it.){{
delimiters began.And a couple others that are more like chores than refactors:
test/corpus
instead of merelycorpus
, so I moved them.tree-sitter-cli
. This introduces a lot of new boilerplate files, but also handles most of the gruntwork of exposing the parser to various Tree-sitter bindings.Once again, I do not even expect this to be landed as-is, since it would be disruptive! But if any of this appeals to you, let me know, and I'll see about isolating it and making a more precise contribution.