I am developing an editor for a SQL-like database query language(GSQL) using codemirror and lezer. I am using Lezer’s nested grammar since this language can be nested within some database command statements.
Here is the code of how I define the language:
const mixedScriptParser = scriptParser.configure({
wrap: parseMixed((node) => {
return node.name == 'QueryText' ? { parser: queryParser } : null;
}),
props: [
styleTags({
[baseTypes.join(' ')]: t.typeName,
'TRUE FALSE': t.bool,
NULL: t.null,
Number: t.number,
[scriptKws.join(' ')]: t.keyword,
String: t.string,
Identifier: t.name,
LineComment: t.lineComment,
BlockComment: t.blockComment,
'.': t.derefOperator,
'( )': t.paren,
'{ }': t.brace,
'[ ]': t.squareBracket,
'< >': t.angleBracket,
}),
],
});
export function gsql(config: GSQLConfig = {}) {
const language = LRLanguage.define({
name: 'gsql',
parser: mixedScriptParser,
languageData: {
commentTokens: { line: '//', block: { open: '/*', close: '*/' } },
closeBrackets: { brackets: ['(', '[', '{', "'", '"', '`', '<'] },
},
});
return new LanguageSupport(language, [
autocompletion({
override: [
completeFromKeywords(),
completeFromIdents(),
completeFromAccumTypes(),
completeFromBaseTypes(),
completeFromSchema(),
],
}),
]);
}
queryParser
is the lezer-generated parser for the query language.
The issue is that seems the languageData
configuration only works outside the nested language. It has no effect if I trigger the shortcut of toggleComment command in the nested language.