mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-12-02 12:57:32 -06:00
Merge pull request #1762 from rayman22201/nim-monaco-support
Added Monaco editor syntax highlight support for Nim.
This commit is contained in:
+1
-2
@@ -178,8 +178,7 @@ const languages = {
|
||||
},
|
||||
nim: {
|
||||
name: 'Nim',
|
||||
// Make it plain text until the language definition is ready
|
||||
monaco: 'text',
|
||||
monaco: 'nim',
|
||||
extensions: ['.nim'],
|
||||
alias: []
|
||||
}
|
||||
|
||||
+113
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2019, Matt Godbolt
|
||||
// Copyright (c) 2019, Ray Imber
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -21,7 +21,119 @@
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
"use strict";
|
||||
var monaco = require('monaco-editor');
|
||||
|
||||
function definition() {
|
||||
// Nim language definition
|
||||
|
||||
return {
|
||||
keywords: [
|
||||
"addr", "as", "asm",
|
||||
"bind", "block", "break",
|
||||
"case", "cast", "concept", "const", "continue", "converter",
|
||||
"defer", "discard", "distinct", "div", "do",
|
||||
"elif", "else", "end", "enum", "except", "export",
|
||||
"finally", "for", "from", "func",
|
||||
"if", "import", "include", "interface", "iterator",
|
||||
"let",
|
||||
"macro", "method", "mixin", "mod",
|
||||
"nil",
|
||||
"object", "out",
|
||||
"proc", "ptr",
|
||||
"raise", "ref", "return",
|
||||
"static",
|
||||
"template", "try", "tuple", "type",
|
||||
"using",
|
||||
"var",
|
||||
"when", "while",
|
||||
"yield"
|
||||
],
|
||||
operators: [
|
||||
'=', '+', '-', '*', '/', '<', '>',
|
||||
'@', '$', '~', '&', '%', '|',
|
||||
'!', '?', '^', '.', ':', '\\'
|
||||
],
|
||||
wordOperators: [
|
||||
'and', 'or', 'not', 'xor', 'shl', 'shr', 'div', 'mod', 'in', 'notin', 'is', 'isnot', 'of'
|
||||
],
|
||||
symbols: /[=><!~&|+\-*/^%]+/,
|
||||
escapes: /\\(p|r|c|n|l|f|t|v|a|b|e|\\|"|'|\d+|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|u\{[0-9a-fA-F]+\})/,
|
||||
charEscapes: /\\(r|c|n|l|f|t|v|a|b|e|\\|"|'|x[0-9a-fA-F]{2})/,
|
||||
|
||||
hexNumber: /0(x|X)[0-9a-fA-F](_?[0-9a-fA-F])*/,
|
||||
decNumber: /\d(_?\d)*/,
|
||||
octNumber: /0o[0-7](_?[0-7])*/,
|
||||
binNumber: /0(b|B)[0-1](_?[0-1])*/,
|
||||
exponent: /(e|E)(\+|-)?\d(_?\d)*/,
|
||||
|
||||
// The main tokenizer for our languages
|
||||
tokenizer: {
|
||||
root: [
|
||||
[/[A-Za-z]([_]?\w)*/, {
|
||||
cases: {
|
||||
'@keywords': 'keyword',
|
||||
'@wordOperators': 'keyword',
|
||||
'@default': 'identifier'
|
||||
}
|
||||
}],
|
||||
{include: '@whitespace'},
|
||||
[/([[{(][.:]|\.[\]})]|[[\]{}()])/, '@brackets'],
|
||||
[/@symbols/, {
|
||||
cases: {
|
||||
'@operators': 'operator',
|
||||
'@default': ''
|
||||
}
|
||||
}],
|
||||
|
||||
// number literals
|
||||
// floats
|
||||
[/@decNumber(\.@decNumber(@exponent)|@exponent)(')?(f|F|d|D)(32|64)?/, 'number.float'],
|
||||
[/(@decNumber|@octNumber|@binNumber)(')?(f|F|d|D)(32|64)?/, 'number.float'],
|
||||
[/@hexNumber'(f|F|d|D)(32|64)?/, 'number.float'],
|
||||
|
||||
// ints
|
||||
[/@hexNumber(')?((i|I|u|U)(8|16|32|64))?/, 'number.hex'],
|
||||
[/@octNumber(')?((i|I|u|U)(8|16|32|64))?/, 'number.octal'],
|
||||
[/@binNumber(')?((i|I|u|U)(8|16|32|64))?/, 'number.binary'],
|
||||
|
||||
[/@decNumber(')?((i|I|u|U)(8|16|32|64))?/, 'number'],
|
||||
|
||||
// char literals
|
||||
[/'/, 'string', '@character'],
|
||||
|
||||
// strings
|
||||
[/(r|R)"/, 'string', '@rawString'],
|
||||
[/"""/, 'string', '@tripleQuoteString'],
|
||||
[/"(?!")/, 'string', '@string']
|
||||
],
|
||||
whitespace: [
|
||||
[/[ \t\r\n]+/, 'white'],
|
||||
[/#\[/, 'comment', '@comment'],
|
||||
[/#.*$/, 'comment']
|
||||
],
|
||||
comment: [
|
||||
[/[^\]#]/, 'comment'],
|
||||
[/\]#/, 'comment', '@pop']
|
||||
],
|
||||
string: [
|
||||
[/@escapes/, 'string.escape'],
|
||||
[/"/, 'string', '@pop']
|
||||
],
|
||||
tripleQuoteString: [
|
||||
[/"""/, 'string', '@pop']
|
||||
],
|
||||
rawString: [
|
||||
[/"/, 'string', '@pop']
|
||||
],
|
||||
character: [
|
||||
[/@charEscapes/, 'string.escape'],
|
||||
[/'/, 'string', '@pop']
|
||||
]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
monaco.languages.register({id: 'nim'});
|
||||
monaco.languages.setMonarchTokensProvider('nim', definition());
|
||||
|
||||
Reference in New Issue
Block a user