|
| 1 | +import { languages, editor } from 'monaco-editor'; |
| 2 | + |
| 3 | +export const config: languages.LanguageConfiguration = { |
| 4 | + comments: { |
| 5 | + lineComment: '//', |
| 6 | + blockComment: ['/*', '*/'], |
| 7 | + }, |
| 8 | + brackets: [ |
| 9 | + ['{', '}'], |
| 10 | + ['[', ']'], |
| 11 | + ['(', ')'], |
| 12 | + ], |
| 13 | + autoClosingPairs: [ |
| 14 | + { open: '[', close: ']' }, |
| 15 | + { open: '{', close: '}' }, |
| 16 | + { open: '(', close: ')' }, |
| 17 | + { open: '"', close: '"', notIn: ['string'] }, |
| 18 | + ], |
| 19 | + surroundingPairs: [ |
| 20 | + { open: '{', close: '}' }, |
| 21 | + { open: '[', close: ']' }, |
| 22 | + { open: '(', close: ')' }, |
| 23 | + { open: '"', close: '"' }, |
| 24 | + { open: '\'', close: '\'' }, |
| 25 | + ], |
| 26 | + folding: { |
| 27 | + markers: { |
| 28 | + start: new RegExp('^\\s*#pragma\\s+region\\b'), |
| 29 | + end: new RegExp('^\\s*#pragma\\s+endregion\\b'), |
| 30 | + }, |
| 31 | + }, |
| 32 | +}; |
| 33 | + |
| 34 | +export const grammar: languages.IMonarchLanguage = { |
| 35 | + // Set defaultToken to invalid to see what you do not tokenize yet |
| 36 | + // defaultToken: 'invalid', |
| 37 | + |
| 38 | + keywords: [ |
| 39 | + 'as', 'break', 'const', 'crate', 'enum', 'extern', 'false', 'fn', 'impl', 'in', |
| 40 | + 'let', 'mod', 'move', 'mut', 'pub', 'ref', 'return', 'self', 'Self', 'static', |
| 41 | + 'struct', 'super', 'trait', 'true', 'type', 'unsafe', 'use', 'where', |
| 42 | + 'macro_rules', |
| 43 | + ], |
| 44 | + |
| 45 | + controlFlowKeywords: [ |
| 46 | + 'continue', 'else', 'for', 'if', 'while', 'loop', 'match', |
| 47 | + ], |
| 48 | + |
| 49 | + typeKeywords: [ |
| 50 | + 'Self', 'm32', 'm64', 'm128', 'f80', 'f16', 'f128', 'int', 'uint', 'float', 'char', |
| 51 | + 'bool', 'u8', 'u16', 'u32', 'u64', 'f32', 'f64', 'i8', 'i16', 'i32', 'i64', 'str', |
| 52 | + 'Option', 'Either', 'c_float', 'c_double', 'c_void', 'FILE', 'fpos_t', 'DIR', 'dirent', |
| 53 | + 'c_char', 'c_schar', 'c_uchar', 'c_short', 'c_ushort', 'c_int', 'c_uint', 'c_long', 'c_ulong', |
| 54 | + 'size_t', 'ptrdiff_t', 'clock_t', 'time_t', 'c_longlong', 'c_ulonglong', 'intptr_t', |
| 55 | + 'uintptr_t', 'off_t', 'dev_t', 'ino_t', 'pid_t', 'mode_t', 'ssize_t', |
| 56 | + ], |
| 57 | + |
| 58 | + operators: [ |
| 59 | + '=', '>', '<', '!', '~', '?', ':', '==', '<=', '>=', '!=', |
| 60 | + '&&', '||', '++', '--', '+', '-', '*', '/', '&', '|', '^', '%', |
| 61 | + '<<', '>>', '>>>', '+=', '-=', '*=', '/=', '&=', '|=', '^=', |
| 62 | + '%=', '<<=', '>>=', '>>>=', |
| 63 | + ], |
| 64 | + |
| 65 | + // we include these common regular expressions |
| 66 | + symbols: /[=><!~?:&|+\-*\/\^%]+/, |
| 67 | + |
| 68 | + // for strings |
| 69 | + escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/, |
| 70 | + |
| 71 | + // The main tokenizer for our languages |
| 72 | + tokenizer: { |
| 73 | + root: [ |
| 74 | + // identifiers and keywords |
| 75 | + [/[a-z_$][\w$]*/, { |
| 76 | + cases: { |
| 77 | + '@typeKeywords': 'type.identifier', |
| 78 | + '@keywords': { |
| 79 | + cases: { |
| 80 | + 'fn': { token: 'keyword', next: '@func_decl' }, |
| 81 | + '@default': 'keyword', |
| 82 | + }, |
| 83 | + }, |
| 84 | + '@controlFlowKeywords': 'keyword.control', |
| 85 | + '@default': 'variable', |
| 86 | + }, |
| 87 | + }], |
| 88 | + [/[A-Z][\w\$]*/, 'type.identifier'], // to show class names nicely |
| 89 | + |
| 90 | + // whitespace |
| 91 | + { include: '@whitespace' }, |
| 92 | + |
| 93 | + // delimiters and operators |
| 94 | + [/[{}()\[\]]/, '@brackets'], |
| 95 | + [/[<>](?!@symbols)/, '@brackets'], |
| 96 | + [/@symbols/, { |
| 97 | + cases: { |
| 98 | + '@operators': 'operator', |
| 99 | + '@default': '', |
| 100 | + }, |
| 101 | + }], |
| 102 | + |
| 103 | + // @ annotations. |
| 104 | + // As an example, we emit a debugging log message on these tokens. |
| 105 | + // Note: message are supressed during the first load -- change some lines to see them. |
| 106 | + [/@\s*[a-zA-Z_\$][\w\$]*/, { token: 'annotation', log: 'annotation token: $0' }], |
| 107 | + |
| 108 | + // numbers |
| 109 | + [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'], |
| 110 | + [/0[xX][0-9a-fA-F]+/, 'number.hex'], |
| 111 | + [/\d+/, 'number'], |
| 112 | + |
| 113 | + // delimiter: after number because of .\d floats |
| 114 | + [/[;,.]/, 'delimiter'], |
| 115 | + |
| 116 | + // strings |
| 117 | + [/"([^"\\]|\\.)*$/, 'string.invalid'], // non-teminated string |
| 118 | + [/"/, { token: 'string.quote', bracket: '@open', next: '@string' }], |
| 119 | + |
| 120 | + // characters |
| 121 | + [/'[^\\']'/, 'string'], |
| 122 | + [/(')(@escapes)(')/, ['string', 'string.escape', 'string']], |
| 123 | + [/'/, 'string.invalid'], |
| 124 | + ], |
| 125 | + |
| 126 | + comment: [ |
| 127 | + [/[^\/*]+/, 'comment'], |
| 128 | + [/\/\*/, 'comment', '@push'], // nested comment |
| 129 | + ['\\*/', 'comment', '@pop'], |
| 130 | + [/[\/*]/, 'comment'], |
| 131 | + ], |
| 132 | + |
| 133 | + string: [ |
| 134 | + [/[^\\"]+/, 'string'], |
| 135 | + [/@escapes/, 'string.escape'], |
| 136 | + [/\\./, 'string.escape.invalid'], |
| 137 | + [/"/, { token: 'string.quote', bracket: '@close', next: '@pop' }], |
| 138 | + ], |
| 139 | + |
| 140 | + whitespace: [ |
| 141 | + [/[ \t\r\n]+/, 'white'], |
| 142 | + [/\/\*/, 'comment', '@comment'], |
| 143 | + [/\/\/.*$/, 'comment'], |
| 144 | + ], |
| 145 | + |
| 146 | + func_decl: [ |
| 147 | + [ |
| 148 | + /[a-z_$][\w$]*/, 'support.function', '@pop', |
| 149 | + ], |
| 150 | + ], |
| 151 | + }, |
| 152 | +}; |
| 153 | + |
| 154 | +export const themeVsDarkPlus: editor.IStandaloneThemeData = { |
| 155 | + base: 'vs-dark', |
| 156 | + inherit: true, |
| 157 | + colors: {}, |
| 158 | + rules: [ |
| 159 | + { token: 'keyword.control', foreground: 'C586C0' }, |
| 160 | + { token: 'variable', foreground: '9CDCFE' }, |
| 161 | + { token: 'support.function', foreground: 'DCDCAA' }, |
| 162 | + ], |
| 163 | +}; |
0 commit comments