123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- import type { languages } from '../fillers/monaco-editor-core';
- export const conf: languages.LanguageConfiguration = {
- wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\#\$\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
- comments: {
- lineComment: '//',
- blockComment: ['/*', '*/']
- },
- brackets: [
- ['{', '}'],
- ['[', ']'],
- ['(', ')']
- ],
- autoClosingPairs: [
- { open: '{', close: '}' },
- { open: '[', close: ']' },
- { open: '(', close: ')' },
- { open: "'", close: "'", notIn: ['string', 'comment'] },
- { open: '"', close: '"', notIn: ['string', 'comment'] }
- ],
- surroundingPairs: [
- { open: '{', close: '}' },
- { open: '[', close: ']' },
- { open: '(', close: ')' },
- { open: '<', close: '>' },
- { open: "'", close: "'" },
- { open: '"', close: '"' }
- ],
- folding: {
- markers: {
- start: new RegExp('^\\s*#region\\b'),
- end: new RegExp('^\\s*#endregion\\b')
- }
- }
- };
- export const language = <languages.IMonarchLanguage>{
- defaultToken: '',
- tokenPostfix: '.cs',
- brackets: [
- { open: '{', close: '}', token: 'delimiter.curly' },
- { open: '[', close: ']', token: 'delimiter.square' },
- { open: '(', close: ')', token: 'delimiter.parenthesis' },
- { open: '<', close: '>', token: 'delimiter.angle' }
- ],
- keywords: [
- 'extern',
- 'alias',
- 'using',
- 'bool',
- 'decimal',
- 'sbyte',
- 'byte',
- 'short',
- 'ushort',
- 'int',
- 'uint',
- 'long',
- 'ulong',
- 'char',
- 'float',
- 'double',
- 'object',
- 'dynamic',
- 'string',
- 'assembly',
- 'is',
- 'as',
- 'ref',
- 'out',
- 'this',
- 'base',
- 'new',
- 'typeof',
- 'void',
- 'checked',
- 'unchecked',
- 'default',
- 'delegate',
- 'var',
- 'const',
- 'if',
- 'else',
- 'switch',
- 'case',
- 'while',
- 'do',
- 'for',
- 'foreach',
- 'in',
- 'break',
- 'continue',
- 'goto',
- 'return',
- 'throw',
- 'try',
- 'catch',
- 'finally',
- 'lock',
- 'yield',
- 'from',
- 'let',
- 'where',
- 'join',
- 'on',
- 'equals',
- 'into',
- 'orderby',
- 'ascending',
- 'descending',
- 'select',
- 'group',
- 'by',
- 'namespace',
- 'partial',
- 'class',
- 'field',
- 'event',
- 'method',
- 'param',
- 'public',
- 'protected',
- 'internal',
- 'private',
- 'abstract',
- 'sealed',
- 'static',
- 'struct',
- 'readonly',
- 'volatile',
- 'virtual',
- 'override',
- 'params',
- 'get',
- 'set',
- 'add',
- 'remove',
- 'operator',
- 'true',
- 'false',
- 'implicit',
- 'explicit',
- 'interface',
- 'enum',
- 'null',
- 'async',
- 'await',
- 'fixed',
- 'sizeof',
- 'stackalloc',
- 'unsafe',
- 'nameof',
- 'when'
- ],
- namespaceFollows: ['namespace', 'using'],
- parenFollows: ['if', 'for', 'while', 'switch', 'foreach', 'using', 'catch', 'when'],
- operators: [
- '=',
- '??',
- '||',
- '&&',
- '|',
- '^',
- '&',
- '==',
- '!=',
- '<=',
- '>=',
- '<<',
- '+',
- '-',
- '*',
- '/',
- '%',
- '!',
- '~',
- '++',
- '--',
- '+=',
- '-=',
- '*=',
- '/=',
- '%=',
- '&=',
- '|=',
- '^=',
- '<<=',
- '>>=',
- '>>',
- '=>'
- ],
- symbols: /[=><!~?:&|+\-*\/\^%]+/,
- // escape sequences
- escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
- // The main tokenizer for our languages
- tokenizer: {
- root: [
- // identifiers and keywords
- [
- /\@?[a-zA-Z_]\w*/,
- {
- cases: {
- '@namespaceFollows': {
- token: 'keyword.$0',
- next: '@namespace'
- },
- '@keywords': {
- token: 'keyword.$0',
- next: '@qualified'
- },
- '@default': { token: 'identifier', next: '@qualified' }
- }
- }
- ],
- // whitespace
- { include: '@whitespace' },
- // delimiters and operators
- [
- /}/,
- {
- cases: {
- '$S2==interpolatedstring': {
- token: 'string.quote',
- next: '@pop'
- },
- '$S2==litinterpstring': {
- token: 'string.quote',
- next: '@pop'
- },
- '@default': '@brackets'
- }
- }
- ],
- [/[{}()\[\]]/, '@brackets'],
- [/[<>](?!@symbols)/, '@brackets'],
- [
- /@symbols/,
- {
- cases: {
- '@operators': 'delimiter',
- '@default': ''
- }
- }
- ],
- // numbers
- [/[0-9_]*\.[0-9_]+([eE][\-+]?\d+)?[fFdD]?/, 'number.float'],
- [/0[xX][0-9a-fA-F_]+/, 'number.hex'],
- [/0[bB][01_]+/, 'number.hex'], // binary: use same theme style as hex
- [/[0-9_]+/, 'number'],
- // delimiter: after number because of .\d floats
- [/[;,.]/, 'delimiter'],
- // strings
- [/"([^"\\]|\\.)*$/, 'string.invalid'], // non-teminated string
- [/"/, { token: 'string.quote', next: '@string' }],
- [/\$\@"/, { token: 'string.quote', next: '@litinterpstring' }],
- [/\@"/, { token: 'string.quote', next: '@litstring' }],
- [/\$"/, { token: 'string.quote', next: '@interpolatedstring' }],
- // characters
- [/'[^\\']'/, 'string'],
- [/(')(@escapes)(')/, ['string', 'string.escape', 'string']],
- [/'/, 'string.invalid']
- ],
- qualified: [
- [
- /[a-zA-Z_][\w]*/,
- {
- cases: {
- '@keywords': { token: 'keyword.$0' },
- '@default': 'identifier'
- }
- }
- ],
- [/\./, 'delimiter'],
- ['', '', '@pop']
- ],
- namespace: [
- { include: '@whitespace' },
- [/[A-Z]\w*/, 'namespace'],
- [/[\.=]/, 'delimiter'],
- ['', '', '@pop']
- ],
- comment: [
- [/[^\/*]+/, 'comment'],
- // [/\/\*/, 'comment', '@push' ], // no nested comments :-(
- ['\\*/', 'comment', '@pop'],
- [/[\/*]/, 'comment']
- ],
- string: [
- [/[^\\"]+/, 'string'],
- [/@escapes/, 'string.escape'],
- [/\\./, 'string.escape.invalid'],
- [/"/, { token: 'string.quote', next: '@pop' }]
- ],
- litstring: [
- [/[^"]+/, 'string'],
- [/""/, 'string.escape'],
- [/"/, { token: 'string.quote', next: '@pop' }]
- ],
- litinterpstring: [
- [/[^"{]+/, 'string'],
- [/""/, 'string.escape'],
- [/{{/, 'string.escape'],
- [/}}/, 'string.escape'],
- [/{/, { token: 'string.quote', next: 'root.litinterpstring' }],
- [/"/, { token: 'string.quote', next: '@pop' }]
- ],
- interpolatedstring: [
- [/[^\\"{]+/, 'string'],
- [/@escapes/, 'string.escape'],
- [/\\./, 'string.escape.invalid'],
- [/{{/, 'string.escape'],
- [/}}/, 'string.escape'],
- [/{/, { token: 'string.quote', next: 'root.interpolatedstring' }],
- [/"/, { token: 'string.quote', next: '@pop' }]
- ],
- whitespace: [
- [/^[ \t\v\f]*#((r)|(load))(?=\s)/, 'directive.csx'],
- [/^[ \t\v\f]*#\w.*$/, 'namespace.cpp'],
- [/[ \t\v\f\r\n]+/, ''],
- [/\/\*/, 'comment', '@comment'],
- [/\/\/.*$/, 'comment']
- ]
- }
- };
|