rojects/source/components/code-panel/CSharpMode.ts

50 lines
1.9 KiB
TypeScript
Raw Permalink Normal View History

import { cLikeLexer } from './BrowserLexer.js';
import { CodeMirrorLexerMode } from './CodeMirrorLexerMode.js';
const TYPE_TO_CLASS: Record<string, string | null> =
{
SINGLE_LINE_COMMENT: 'comment',
MULTI_LINE_COMMENT: 'comment',
DOUBLE_QUOTED_STRING: 'string',
SINGLE_QUOTED_STRING: 'string',
NUMBER: 'number',
BOOL: 'atom',
NULL: 'atom',
LOGIC: 'keyword',
CLASS: 'keyword',
ACCESS_MODIFIER: 'keyword',
C_INSTRUCTION: 'meta',
CFUNCTION: 'variable-2',
CWORD: 'variable',
OPERATOR: 'operator',
BRACKET: 'bracket',
WHITESPACE: null,
BREAK: null,
ANY_SYMBOL: null,
};
const CS_KEYWORDS =
[
'abstract', 'as', 'async', 'await', 'base', 'byte',
'catch', 'char', 'checked', 'const', 'decimal', 'default',
'delegate', 'double', 'dynamic', 'enum', 'event', 'explicit',
'extern', 'finally', 'fixed', 'float', 'foreach', 'get',
'goto', 'implicit', 'in', 'int', 'interface', 'internal',
'is', 'lock', 'long', 'nameof', 'namespace', 'new',
'object', 'operator', 'out', 'override', 'params', 'partial',
'readonly', 'ref', 'remove', 'sbyte', 'sealed', 'set',
'short', 'sizeof', 'stackalloc', 'static', 'string', 'struct',
'this', 'throw', 'try', 'typeof', 'uint', 'ulong',
'unchecked','unsafe', 'ushort', 'using', 'value', 'var',
'virtual', 'void', 'volatile', 'when', 'where', 'with',
'yield',
];
export const csharpMode = new CodeMirrorLexerMode(
cLikeLexer(),
TYPE_TO_CLASS,
[ { type: 'MULTI_LINE_COMMENT', start: /\/\*/, end: /\*\//, cmClass: 'comment' } ]
);
csharpMode.setKeywordSet( 'keywords', CS_KEYWORDS, 'keyword', [ 'CWORD' ] );