From 4de546a198f8fca4b489d64f5a08ed2fc464d362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Nihlg=C3=A5rd?= Date: Mon, 29 Oct 2018 08:44:13 +0100 Subject: [PATCH 1/2] Improved syntax definition for pragmas --- syntaxes/nim.json | 95 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 6 deletions(-) diff --git a/syntaxes/nim.json b/syntaxes/nim.json index bc61fa3..d718144 100644 --- a/syntaxes/nim.json +++ b/syntaxes/nim.json @@ -303,20 +303,103 @@ }, { "begin": "\\{\\.", - "end": "\\.{0,1}\\}", - "name": "meta.preprocessor.nim", + "beginCaptures": { + "0": { + "name": "punctuation.pragma.start.nim" + } + }, + "end": "\\.?\\}", + "endCaptures": { + "0": { + "name": "punctuation.pragma.end.nim" + } + }, "patterns": [ { - "include": "#string_quoted_triple" + "begin": "\\b([[:alpha:]]\\w*)(?:\\s|\\s*:)", + "beginCaptures": { + "1": { + "name": "meta.preprocessor.pragma.nim" + } + }, + "end": "(?=\\.?\\}|,)", + "patterns": [ + { + "include": "source.nim" + } + ] + }, + { + "begin": "\\b([[:alpha:]]\\w*)\\(", + "beginCaptures": { + "1": { + "name": "meta.preprocessor.pragma.nim" + } + }, + "end": "\\)", + "patterns": [ + { + "include": "source.nim" + } + ] + }, + { + "match": "\\b([[:alpha:]]\\w*)(?=\\.?\\}|,)", + "captures": { + "1": { + "name": "meta.preprocessor.pragma.nim" + } + } }, { - "include": "#string_quoted_double_raw" + "begin": "\\b([[:alpha:]]\\w*)(\"\"\")", + "beginCaptures": { + "1": { + "name": "meta.preprocessor.pragma.nim" + }, + "2": { + "meta": "punctuation.definition.string.begin.nim" + } + }, + "end": "\"\"\"(?!\")", + "endCaptures": { + "0": "punctuation.definition.string.end.nim" + }, + "name": "string.quoted.triple.raw.nim" }, { - "include": "#string_quoted_double" + "begin": "\\b([[:alpha:]]\\w*)(\")", + "beginCaptures": { + "1": { + "name": "meta.preprocessor.pragma.nim" + }, + "2": { + "meta": "punctuation.definition.string.begin.nim" + } + }, + "end": "\"", + "endCaptures": { + "0": "punctuation.definition.string.end.nim" + }, + "name": "string.quoted.double.raw.nim" }, { - "include": "#string_quoted_single" + "begin": "\\b(hint\\[\\w+\\]):", + "beginCaptures": { + "1": { + "name": "meta.preprocessor.pragma.nim" + } + }, + "end": "(?=\\.?\\}|,)", + "patterns": [ + { + "include": "source.nim" + } + ] + }, + { + "match": ",", + "name": "punctuation.separator.comma.nim" } ] }, From d8db5b62ef7337670b8ea0022a55b9a6ceae1cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Nihlg=C3=A5rd?= Date: Mon, 29 Oct 2018 08:46:37 +0100 Subject: [PATCH 2/2] Improved syntax definition for strings - Highlight the \u and "" escapes. - Highlight interpolations in `strformat.fmt` --- syntaxes/nim.json | 372 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 291 insertions(+), 81 deletions(-) diff --git a/syntaxes/nim.json b/syntaxes/nim.json index d718144..3da1789 100644 --- a/syntaxes/nim.json +++ b/syntaxes/nim.json @@ -10,20 +10,24 @@ "contentName": "comment.block.doc-comment.content.nim", "end": "\\]##", "name": "comment.block.doc-comment.nim", - "patterns": [{ - "include": "#multilinedoccomment", - "name": "comment.block.doc-comment.nested.nim" - }] + "patterns": [ + { + "include": "#multilinedoccomment", + "name": "comment.block.doc-comment.nested.nim" + } + ] }, { "begin": "[ \\t]*#\\[", "contentName": "comment.block.content.nim", "end": "\\]#", "name": "comment.block.nim", - "patterns": [{ - "include": "#multilinecomment", - "name": "comment.block.nested.nim" - }] + "patterns": [ + { + "include": "#multilinecomment", + "name": "comment.block.nested.nim" + } + ] }, { "begin": "(^[ \\t]+)?(?=##)", @@ -72,7 +76,7 @@ "name": "meta.proc.nim", "patterns": [ { - "begin": "\\b(proc|method|template|macro|iterator|converter|func)\\s+\\`?([^\\:\\{\\s\\`\\*\\(]*)\\`?(\\s*\\*)?\\s*(\\(|\\=|:|\\[|\\n|\\{)", + "begin": "\\b(proc|method|template|macro|iterator|converter|func)\\s+\\`?([^\\:\\{\\s\\`\\*\\(]*)\\`?(\\s*\\*)?\\s*(?=\\(|\\=|:|\\[|\\n|\\{)", "captures": { "1": { "name": "keyword.other" @@ -150,6 +154,9 @@ } } }, + { + "include": "#string_literal" + }, { "comment": "Language Constants.", "match": "\\b(true|false|Inf|NegInf|NaN|nil)\\b", @@ -215,44 +222,6 @@ "match": "\\b\\w+\\b(?=\\()", "name": "support.function.any-method.nim" }, - { - "comment": "Empty raw string", - "match": "\\br\"\"(?!\")", - "name": "string.quoted.double.raw.nim" - }, - { - "comment": "Empty extended raw string", - "match": "\\b(\\w+)(\"\")(?!\")", - "captures": { - "1": { - "name": "support.function.any-method.nim" - }, - "2": { - "name": "string.quoted.double.raw.nim" - } - } - }, - { - "include": "#string_quoted_triple_raw" - }, - { - "include": "#string_quoted_triple" - }, - { - "include": "#extended_string_quoted_triple_raw" - }, - { - "include": "#string_quoted_double_raw" - }, - { - "include": "#extended_string_quoted_double_raw" - }, - { - "include": "#string_quoted_double" - }, - { - "include": "#string_quoted_single" - }, { "begin": "(^\\s*)?(?=\\{\\.emit: ?\"\"\")", "beginCaptures": { @@ -337,8 +306,8 @@ } }, "end": "\\)", - "patterns": [ - { + "patterns": [ + { "include": "source.nim" } ] @@ -360,7 +329,7 @@ "2": { "meta": "punctuation.definition.string.begin.nim" } - }, + }, "end": "\"\"\"(?!\")", "endCaptures": { "0": "punctuation.definition.string.end.nim" @@ -372,7 +341,7 @@ "beginCaptures": { "1": { "name": "meta.preprocessor.pragma.nim" - }, + }, "2": { "meta": "punctuation.definition.string.begin.nim" } @@ -389,15 +358,15 @@ "1": { "name": "meta.preprocessor.pragma.nim" } - }, + }, "end": "(?=\\.?\\}|,)", "patterns": [ - { + { "include": "source.nim" - } - ] - }, - { + } + ] + }, + { "match": ",", "name": "punctuation.separator.comma.nim" } @@ -1068,23 +1037,23 @@ "multilinecomment": { "begin": "#\\[", "end": "\\]#", - "patterns": [{ - "include": "#multilinecomment" - }] + "patterns": [ + { + "include": "#multilinecomment" + } + ] }, "multilinedoccomment": { "begin": "##\\[", "end": "\\]##", - "patterns": [{ - "include": "#multilinedoccomment" - }] - }, - "escaped_char": { "patterns": [ { - "match": "\\\\[pP]", - "name": "constant.character.escape.newline.nim" - }, + "include": "#multilinedoccomment" + } + ] + }, + "char_escapes": { + "patterns": [ { "match": "\\\\[cC]|\\\\[rR]", "name": "constant.character.escape.carriagereturn.nim" @@ -1139,6 +1108,242 @@ } ] }, + "string_escapes": { + "patterns": [ + { + "match": "\\\\[pP]", + "name": "constant.character.escape.newline.nim" + }, + { + "match": "\\\\[uU]\\h\\h\\h\\h", + "name": "constant.character.escape.hex.nim" + }, + { + "match": "\\\\[uU]\\{\\h+\\}", + "name": "constant.character.escape.hex.nim" + }, + { + "include": "#char_escapes" + } + ] + }, + "raw_string_escapes": { + "match": "[^\"](\"\")", + "captures": { + "1": { + "name": "constant.character.escape.double-quote.nim" + } + } + }, + "fmt_interpolation": { + "begin": "\\{", + "beginCaptures": { + "0": { + "name": "punctuation.definition.template-expression.begin.nim" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "punctuation.definition.template-expression.end.nim" + } + }, + "patterns": [ + { + "begin": ":", + "end": "(?=\\})", + "name": "meta.template.format-specifier.nim" + }, + { + "include": "source.nim" + } + ], + "name": "meta.template.expression.nim" + }, + "string_literal": { + "patterns": [ + { + "include": "#fmt_string_triple" + }, + { + "include": "#fmt_string_triple_operator" + }, + { + "include": "#extended_string_quoted_triple_raw" + }, + { + "include": "#string_quoted_triple_raw" + }, + { + "include": "#fmt_string_operator" + }, + { + "include": "#fmt_string" + }, + { + "include": "#fmt_string_call" + }, + { + "include": "#string_quoted_double_raw" + }, + { + "include": "#extended_string_quoted_double_raw" + }, + { + "include": "#string_quoted_single" + }, + { + "include": "#string_quoted_triple" + }, + { + "include": "#string_quoted_double" + } + ] + }, + "fmt_string": { + "begin": "\\b(fmt)(\")", + "beginCaptures": { + "1": { + "name": "support.function.any-method.nim" + }, + "2": { + "name": "punctuation.definition.string.begin.nim" + } + }, + "end": "\"", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.nim" + } + }, + "name": "string.quoted.double.raw.nim", + "patterns": [ + { + "match": "(?