Expand monarch functionality to allow state access within rules#183463
Merged
alexdima merged 4 commits intomicrosoft:mainfrom Mar 19, 2024
Merged
Expand monarch functionality to allow state access within rules#183463alexdima merged 4 commits intomicrosoft:mainfrom
alexdima merged 4 commits intomicrosoft:mainfrom
Conversation
Contributor
Author
|
@microsoft-github-policy-service agree |
Contributor
Author
|
The automated test cases and unit tests pass. I could use some guidance on how to test the changes in conjunction with monaco / a test monarch grammar. |
bpasero
approved these changes
Mar 19, 2024
This was referenced Mar 20, 2024
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 think monarch is not powerful enough to tokenize constructs such as C++ raw string literals in the general case. This is an attempt to expand monarch functionality so it can.
Monaco tokenization of C++ raw strings is broken when the d-char-sequence contains double quotes microsoft/monaco-editor#3128
This is because https://github.com/microsoft/monaco-editor/blob/main/src/basic-languages/cpp/cpp.ts looks for the end of a raw string literal by searching for
/(.*)(\))(?:([^ ()\\\t"]*))(\")/and then checks$3==$S2to see if the end has in fact been found, but only compares what is between a closing parenthesis and the first double quote.As far as I can tell, there is no way to solve this currently in monarch, without doing something hacky like hard-coding for all d-char-sequences of 16 or fewer characters, for example (the C++ standard does specify this limit). Maybe there is a way that I haven't thought of, in which case this PR isn't needed. Most languages do not seem to place such limitations on the delimiter sequences, e.g. PHP and C#. Rust tokenization can be improved as well with the tools provided by the PR.
This PR expands monarch functionality by allowing
$S2to be used within rule regexes, so the fix for microsoft/monaco-editor#3128 can be something along the lines ofroot: [ // C++ 11 Raw String [/@encoding?R\"(?:([^ ()\\\t]*))\(/, { token: 'string.raw.begin', next: '@raw.$1' }], ... ], raw: [ + [/.*\)$S2\"/, 'string.raw', '@pop'] - [ - /(.*)(\))(?:([^ ()\\\t"]*))(\")/, - { - cases: { - '$3==$S2': [ - 'string.raw', - 'string.raw.end', - 'string.raw.end', - { token: 'string.raw.end', next: '@pop' } - ], - '@default': ['string.raw', 'string.raw', 'string.raw', 'string.raw'] - } - } - ], [/.*/, 'string.raw'] ],I have not fully tested this PR yet.