Ask questionsMonarch: How do you add "@keywords" key to "language object"? (undocumented)
Version: 0.16.2
I'm trying to reproduce the "mylang" example for Monarch on https://microsoft.github.io/monaco-editor/monarch.html. However, I can't figure out where the object literal goes when using the Monaco API.
In particular, it's clear where to put the tokenizer object:
monacoEditor.languages.setMonarchTokensProvider("substance", {
tokenizer: {
...
But adding the keywords key to this object throws a type error. I want to have the keywords key, etc available to dynamically match against the list of keywords using @keywords syntax e,g, as seen in the example:
[/[a-z_$][\w$]*/, { cases: { '@typeKeywords': 'keyword',
'@keywords': 'keyword',
'@default': 'identifier' } }],
So where should this key go? The text on the page says
The attribute keywords must be defined in the language object and consist of an array of strings.
But what is a "language object"? I can't find it anywhere in the docs. Is it the object passed into monaco.languages.register({...})? That throws a type error too.
Answer questions
blacksteed232
@maxkrieger Hey, this is how I made it work
import * as monaco from 'monaco-editor';
interface MonarchLanguageConfiguration extends monaco.languages.IMonarchLanguage {
keywords: string[];
}
monaco.languages.setMonarchTokensProvider('yourLanguageName', {
keywords: ['class', 'extends', ...],
tokenizer: { ... }
} as MonarchLanguageConfiguration)
Also, it's undocumented because they auto-generate their docs. I think you can close this thread
Related questions