I’m trying to extend the parser in @codemirror/lang-python
with hightlighting for custom words e.g CustomType. I have extended the pythonLanguage
parser with a StyleTags
as specified by Codemirror 6 and lezer/highlight documentation but the highlighting is not reflected. I don’t know what I’m missing here.
import {basicSetup, EditorView} from "codemirror"
import { styleTags, tags as t, Tag } from "@lezer/highlight";
import {python, pythonLanguage} from "@codemirror/lang-python"
import { LanguageSupport, LRLanguage } from "@codemirror/language";
const customParser = pythonLanguage.parser.configure({
props: [
styleTags({
CustomType: t.null,
}),
]
})
const CustomPython = () => {
return new LanguageSupport(LRLanguage.define({ parser: customParser }), [
]);
};
new EditorView({
doc: `\
def main():
y = CustomType(4)
x = None
print("Hello")`,
extensions: [basicSetup, CustomPython()],
// extensions: [basicSetup, python()],
parent: document.body
})
The sample code above can be tested here Try CodeMirror
Or in a react environment here: https://codesandbox.io/p/sandbox/jolly-panka-3y75zm