I am completely new to code mirror. I have the following three files.
When I type in jack in the editor I get Uncaught ReferenceError:CoolItem is not defined
I know it has to do with return statement in tokens.js
However I am completely lost as to what is to be returned here – how is the token declared in grammar file inside braces of external specializer passed to the function in token.js
In grammar file
@external specialize {Identifier} SpecializeIdent from “./tokens” {
CoolItem
}
in tokens.js
const SpecializeIdent = {
SpecializeIdent: function(name) {
name = name.toLowerCase();
let specials = ["jack", "jim"];
if (specials.includes(name)) {
return CoolItem
}
return -1
}
}
in index.ts
export const MyLanguage = LRLanguage.define({
parser: parser.configure({
props: [
indentNodeProp.add({
Application: delimitedIndent({closing: ")", align: false})
}),
foldNodeProp.add({
Application: foldInside
}),
styleTags({
Identifier: t.variableName,
Boolean: t.bool,
String: t.string,
LineComment: t.lineComment,
CoolItem:t.typeName,
"( )": t.paren
}),
],
}),
languageData: {
commentTokens: {line: ";"}
}
})
export function MyLang() {
return new LanguageSupport(MyLanguage)
}
in editor.js
const myHighlightStyle = HighlightStyle.define([
{tag: tags.typeName, color: “#fc6”},
{tag: tags.comment, color: “#f5d”, fontStyle: “italic”}
])
let editor = new EditorView({
extensions: [basicSetup, MyLang(),syntaxHighlighting(myHighlightStyle)],
parent: document.querySelector(“#editor”)
})