in wstl1/tools/notebook/wstl-syntax-highlighting/src/index.ts [30:89]
function defineWhistleMode(app: JupyterFrontEnd): void {
// TODO(): autogenerate rules from whistle grammar.
CodeMirror.defineSimpleMode(WHISTLE_MODE, {
// The start state contains the rules that are intially used.
start: [
// Strings.
{regex: /"(?:[^\\]|\\.)*?(?:"|$)/, token: 'string'},
// Builtin functions.
{regex: /\$([a-zA-Z_\d]*)/, token: ['keyword', null, 'def']},
// Iterator brackets.
{regex: /\[\]/, token: 'meta'},
// Function declarations.
{
regex: /(def)(\s+)([a-zA-Z_$][\w$]*)/,
token: ['keyword', null, 'variable-2']
},
// Rules are matched in the order in which they appear, so there is
// no ambiguity between this one and the one above.
{
regex:
/(\$root|\$this)|(?:def|if|where|else|var|out|root|dest|post|this|\^)\b/,
token: ['builtin', null, 'keyword']
},
{regex: /true|false|null|undefined|required/, token: 'builtin'},
{
regex: /0x[a-f\d]+|\s+[-+]?(?:\.\d+|\d+\.?\d*)(?:e[-+]?\d+)?/i,
token: 'number'
},
{regex: /\/\/.*/, token: 'comment'},
// Language operators.
{regex: /[-+\/*=<>!~?@]+|and|or|\[\*\]/, token: 'operator'},
// Indent and dedent properties guide autoindentation.
{regex: /[\{\[\(]/, indent: true},
{regex: /[\}\]\)]/, dedent: true},
{regex: /[a-z$][\w$]*/, token: 'variable'},
],
// The meta property contains global information about the mode. It
// can contain properties like lineComment, which are supported by
// all modes, and also directives like dontIndentStates, which are
// specific to simple modes.
meta: {dontIndentStates: ['comment'], lineComment: '//'}
});
CodeMirror.defineMIME(WHISTLE_MODE_MIME_TYPE, WHISTLE_MODE);
Mode.getModeInfo().push({
ext: [WHISTLE_EXT],
mime: WHISTLE_MODE_MIME_TYPE,
mode: WHISTLE_MODE,
name: WHISTLE_MODE
});
app.docRegistry.addFileType({
name: 'wstl',
displayName: 'Whistle File',
extensions: ['.wstl'],
mimeTypes: [WHISTLE_MODE_MIME_TYPE],
iconClass: 'jp-MaterialIcon reactivecore_icon',
iconLabel: '',
contentType: 'file',
fileFormat: 'text'
});
}