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

51 lines
2.3 KiB
TypeScript

import { CLikeLexer } from '../../library-ts/browser/text/lexer/CLikeLexer.js';
import { LexerTypes } from '../../library-ts/browser/text/lexer/LexerType.js';
import { CodeMirrorLexerMode } from './CodeMirrorLexerMode.js';
const TYPE_TO_CLASS: Record<string, string | null> =
{
[ LexerTypes.SINGLE_LINE_COMMENT ]: 'comment',
[ LexerTypes.MULTI_LINE_COMMENT ]: 'comment',
[ LexerTypes.DOUBLE_QUOTED_STRING ]: 'string',
[ LexerTypes.SINGLE_QUOTED_STRING ]: 'string',
[ LexerTypes.NUMBER ]: 'number',
[ LexerTypes.BOOL ]: 'atom',
[ LexerTypes.NULL ]: 'atom',
[ LexerTypes.LOGIC ]: 'keyword',
[ LexerTypes.CLASS ]: 'keyword',
[ LexerTypes.ACCESS_MODIFIER ]: 'keyword',
[ LexerTypes.C_INSTRUCTION ]: 'meta',
[ LexerTypes.CFUNCTION ]: 'variable-2',
[ LexerTypes.CWORD ]: 'variable',
[ LexerTypes.OPERATOR ]: 'operator',
[ LexerTypes.BRACKET ]: 'bracket',
[ LexerTypes.WHITESPACE ]: null,
[ LexerTypes.BREAK ]: null,
[ LexerTypes.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(
new CLikeLexer(),
TYPE_TO_CLASS,
[ { type: LexerTypes.MULTI_LINE_COMMENT, start: /\/\*/, end: /\*\//, cmClass: 'comment' } ]
);
csharpMode.setKeywordSet( 'keywords', CS_KEYWORDS, 'keyword', [ LexerTypes.CWORD ] );