From a255a4a861882be956e79af124e6a285092c010a Mon Sep 17 00:00:00 2001 From: Ray Imber Date: Thu, 2 Jan 2020 13:31:49 -0800 Subject: [PATCH 1/2] Added Monaco editor syntax highlight support for Nim. --- lib/languages.js | 3 +- static/modes/nim-mode.js | 115 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 115 insertions(+), 3 deletions(-) diff --git a/lib/languages.js b/lib/languages.js index 18dc5f0b7..e75be3538 100644 --- a/lib/languages.js +++ b/lib/languages.js @@ -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: [] } diff --git a/static/modes/nim-mode.js b/static/modes/nim-mode.js index a936e7100..74e7a060d 100644 --- a/static/modes/nim-mode.js +++ b/static/modes/nim-mode.js @@ -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,120 @@ // 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: /[=> Date: Thu, 2 Jan 2020 14:44:48 -0800 Subject: [PATCH 2/2] Fix linter errors. --- static/modes/nim-mode.js | 137 +++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 69 deletions(-) diff --git a/static/modes/nim-mode.js b/static/modes/nim-mode.js index 74e7a060d..9292e4215 100644 --- a/static/modes/nim-mode.js +++ b/static/modes/nim-mode.js @@ -30,107 +30,106 @@ function 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" + "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' + 'and', 'or', 'not', 'xor', 'shl', 'shr', 'div', 'mod', 'in', 'notin', 'is', 'isnot', 'of' ], symbols: /[=>