Ensure @rematch and nextEmbedded can be used together in Monarch grammar#95742
Merged
alexdima merged 3 commits intomicrosoft:masterfrom Apr 27, 2020
Merged
Conversation
cd256d5 to
4e52140
Compare
Contributor
Author
|
/cc @alexdima |
…ammar. Similar to the repro case I created for microsoft#90266, I created a local playground with the following: ```js const DEMO_LANG_ID = "demo"; const SQL_QUERY_START = "(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|WITH)"; const languageConfiguration = { tokenizer: { root: [ [ `(\"\"\")${SQL_QUERY_START}`, [ { "token": "string.quote", }, { token: "@rematch", next: "@endStringWithSQL", nextEmbedded: "sql", }, ] ], [ /(""")$/, [ { token: "string.quote", next: "@maybeStringIsSQL", }, ] ], ], maybeStringIsSQL: [ [ /(.*)/, { cases: { [`${SQL_QUERY_START}\\b.*`]: { token: "@rematch", next: "@endStringWithSQL", nextEmbedded: "sql", }, "@default": { token: "@rematch", switchTo: "@endDblDocString", }, } } ], ], endDblDocString: [ [ "[^\"]+", "string" ], [ "\\\\\"", "string" ], [ "\"\"\"", "string", "@popall" ], [ "\"", "string" ] ], endStringWithSQL: [ [ /"""/, { token: "string.quote", next: "@popall", nextEmbedded: "@pop", }, ] ], }, }; monaco.languages.register({ id: DEMO_LANG_ID, extensions: ['.example'], }); monaco.languages.setMonarchTokensProvider(DEMO_LANG_ID, languageConfiguration); const value = `\ mysql_query("""SELECT * FROM table_name WHERE ds = '<DATEID>'""") mysql_query(""" SELECT * FROM table_name WHERE ds = '<DATEID>' """) `; var editor = monaco.editor.create(document.getElementById("container"), { value, language: DEMO_LANG_ID, lineNumbers: "off", roundedSelection: false, scrollBeyondLastLine: false, readOnly: false, theme: "vs-dark", }); ``` Without my change to monarchLexer.ts, I get this error in the console: > errors.ts:26 Uncaught Error: demo: cannot pop embedded mode if not inside one But with my change, I see a Python-esque multiline string literal with SQL syntax highlighting within it.
4e52140 to
b9f5b9e
Compare
Member
|
Thank you! |
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.
Similar to the repro case I created for #90266, I created a local
playground with the following:
Without my change to monarchLexer.ts, I get this error in the console:
But with my change, I see a Python-esque multiline string literal with
SQL syntax highlighting within it.