Ensure @rematch and nextEmbedded can be used together in Monarch grammar by bolinfest · Pull Request #95742 · microsoft/vscode
…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.