Repository navigation
Match vscode-textmate's tokenization rules more closely - #155
Merged
Merged
Conversation
Most differences from vscode-textmate came from the tokenizer and grammar
parser rather than the regex engines:
- Resolve `#name` includes against the repository of an enclosing rule.
- Support `applyEndPatternLast`.
- Keep back-references in match and begin patterns, escape the text
substituted into end patterns, and resolve them in while patterns.
- Parse injection selectors like vscode-textmate: neighbouring operands are
joined with "and", `-` inside a scope name is not an exclusion, and
exclusions bind more tightly than `|`.
- Leave out begin/end and begin/while rules whose patterns all include
rules or grammars that don't exist.
- Fix `${n:/downcase}` scope names, begin/while captures after a gap,
captures inside a lookahead, and retokenizing captures after multibyte
text.
- Treat empty names, null captures, and empty or missing ends the way
vscode-textmate does.
- Use byte offsets throughout the Oniguruma engine.
PCRE now matches vscode-textmate for 219 of 227 grammars (from 163), and
Oniguruma for 152 (from 113). Regenerate COMPATIBILITY.md.
Amp-Thread-ID: https://ampcode.com/threads/T-01a1a80f-8c39-72fb-be3a-ae1b9ab154f7
Co-authored-by: Ryan Chandler <ryan@ryangjchandler.co.uk>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Most of the differences between Phiki and vscode-textmate in COMPATIBILITY.md were caused by the tokenizer and grammar parser, not by the regex engines. This PR fixes them, so both engines get closer to vscode-textmate.
Fixes
#nameincludes now look in the enclosing rule'srepositoryfirst, as vscode-textmate does. Objective-C, Objective-C++, Wikitext, Clarity and Cadence use these heavily.applyEndPatternLastis now supported. 21 bundled grammars use it, including Groovy, GraphQL, Markdown frontmatter, Fortran and Marko.\1was removed from everymatchandbeginpattern. The text substituted intoendpatterns wasn't escaped, andwhilepatterns never got the begin captures.(a | b) (c | d) - ematched like(a | b). It also treated-inside a scope name such asvue-htmlas an exclusion, and evaluated|and-left to right. Selectors are now tokenized and grouped the way vscode-textmate does it. This is why Svelte and Astro embedded the wrong language.${n:/downcase}scope names always used capture 0.nullcaptures, and empty or missingendpatterns are now handled the way vscode-textmate handles them."0"as unmatched.Behaviour change to review
A
beginwithout anendused to be treated as amatch. It is now a region that never closes, as in vscode-textmate. Only thexmlandbladegrammars have such rules.Captures written as a bare string (
"1": "name") still get their name. vscode-textmate ignores them, so Stata keeps a small difference.Remaining PCRE differences
cpp-macro. That file is bundled but isn't aGrammarcase, so Phiki can't resolve it by scope.meta/vscode-textmate-samples.jsdoesn't load grammars that are only referenced fromcaptures. Phiki does tokenize them.Tests
TokenizerTestcovers each tokenizer fix with both engines. I checked every expected value against vscode-textmate, and all but one case fail without these changes.InjectionParserTestcovers the selector fixes.composer compatibility.