Hi there,
I am writing a language mode for Codemirror. Writing a Lezer parser seemed complex, so I settled upon using the simpleMode
function in @codemirror/legacy-modes
, and now I want to match a token which only appears at the start of the line.
I have the following language mode:
export const myLang = simpleMode({
start: [
{
regex: /\b[0-9]+\b/,
token: 'number',
},
{
regex: /^\w+:/,
token: 'keyword',
},
{
regex: /;[^\n]+/,
token: 'comment',
},
],
languageData: {
name: 'myLang',
commentTokens: { line: ';' },
},
});
However, if I give an input to the editor such as “foo: bar: baz: qux”, all three tokens “foo:”, “bar:” and “baz:” are recognized as keywords, instead of only “foo:”. I suspect this is because the regex is applied incrementally to the rest of the string.
A Stackblitz is available here: Webpack.js Getting Started Example - StackBlitz, if you want to try it out.
How can I modify the mode so that keyword tokens are only recognized at the beginning of a line?
Thank you.