From 5aa356937f3124986820a297773a51150030dba5 Mon Sep 17 00:00:00 2001 From: Nikita Prokopov Date: Mon, 27 Nov 2017 17:43:17 +0300 Subject: [PATCH 1/8] Do not mark full def* body with "meta.definition.global.clojure", mark just fn name with "meta.definition.global.clojure entity.name.global.clojure" --- grammars/clojure.cson | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/grammars/clojure.cson b/grammars/clojure.cson index 7af94e5..b2d31d6 100644 --- a/grammars/clojure.cson +++ b/grammars/clojure.cson @@ -284,7 +284,6 @@ '1': 'name': 'keyword.control.clojure' 'end': '(?=\\))' - 'name': 'meta.definition.global.clojure' 'patterns': [ { # there may be some metadata before an actual definition @@ -297,7 +296,7 @@ # recognizing a symbol as being defined here # copied and pasted from #symbol, screw it 'match': '([\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*][\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*\\d]+)' - 'name': 'entity.global.clojure' + 'name': 'meta.definition.global.clojure entity.name.global.clojure' } { 'include': '$self' From 4390c2bd2b7ac5f98e51448a2f6df07eb07e5f19 Mon Sep 17 00:00:00 2001 From: Nikita Prokopov Date: Mon, 27 Nov 2017 17:43:47 +0300 Subject: [PATCH 2/8] Fixed defs of dynamic vars --- grammars/clojure.cson | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grammars/clojure.cson b/grammars/clojure.cson index b2d31d6..9b0cb3d 100644 --- a/grammars/clojure.cson +++ b/grammars/clojure.cson @@ -289,15 +289,15 @@ # there may be some metadata before an actual definition 'include': '#metadata' } - { # dynamic variables are rendered diferently - 'include': '#dynamic-variables' - } { # recognizing a symbol as being defined here # copied and pasted from #symbol, screw it 'match': '([\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*][\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*\\d]+)' 'name': 'meta.definition.global.clojure entity.name.global.clojure' } + { # dynamic variables are rendered diferently + 'include': '#dynamic-variables' + } { 'include': '$self' } From e74aaf591ba8a0ffa419bf6994a3e6949070da4e Mon Sep 17 00:00:00 2001 From: Nikita Prokopov Date: Mon, 27 Nov 2017 17:47:33 +0300 Subject: [PATCH 3/8] Recognize single-char symbols --- grammars/clojure.cson | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grammars/clojure.cson b/grammars/clojure.cson index 9b0cb3d..192660f 100644 --- a/grammars/clojure.cson +++ b/grammars/clojure.cson @@ -292,7 +292,7 @@ { # recognizing a symbol as being defined here # copied and pasted from #symbol, screw it - 'match': '([\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*][\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*\\d]+)' + 'match': '([\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*][\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*\\d]*)' 'name': 'meta.definition.global.clojure entity.name.global.clojure' } { # dynamic variables are rendered diferently @@ -364,7 +364,7 @@ 'patterns': [ { # copied from #symbol, plus a / at the end. Matches the "app/" part of # "app/*config*" - 'match': '([\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*][\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*\\d]+)/' + 'match': '([\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*][\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*\\d]*)/' 'captures': '1': 'name': 'meta.symbol.namespace.clojure' @@ -373,7 +373,7 @@ 'symbol': 'patterns': [ { - 'match': '([\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*][\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*\\d]+)' + 'match': '([\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*][\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*\\d]*)' 'name': 'meta.symbol.clojure' } ] From 9a50d4ffba84e02e03ad38cd415cccccad07b8d6 Mon Sep 17 00:00:00 2001 From: Nikita Prokopov Date: Mon, 27 Nov 2017 18:08:04 +0300 Subject: [PATCH 4/8] =?UTF-8?q?Symbols=20can=E2=80=99t=20start=20with=20[0?= =?UTF-8?q?-9#'],=20but=20can=20include=20[#$%&'|]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- grammars/clojure.cson | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/grammars/clojure.cson b/grammars/clojure.cson index 192660f..052e586 100644 --- a/grammars/clojure.cson +++ b/grammars/clojure.cson @@ -155,7 +155,7 @@ } ] 'dynamic-variables': - 'match': '\\*[\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\d]+\\*' + 'match': '\\*[0-9#\'A-Z_a-z!$%&+\\-.:<=>?|]+\\*' 'name': 'meta.symbol.dynamic.clojure' 'map': 'begin': '(\\{)' @@ -279,7 +279,7 @@ 'patterns': [ { # ns, declare and everything that starts with def* or namespace/def* - 'begin': '(?<=\\()(ns|declare|def[\\w\\d._:+=>?|*]*|[A-Z_a-z!$%&+\\-.:<=>?|*][0-9#\'A-Z_a-z!$%&+\\-.:<=>?|*]*/def[0-9#\'A-Z_a-z!$%&+\\-.:<=>?|*]*)\\s+' 'beginCaptures': '1': 'name': 'keyword.control.clojure' @@ -292,7 +292,7 @@ { # recognizing a symbol as being defined here # copied and pasted from #symbol, screw it - 'match': '([\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*][\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*\\d]*)' + 'match': '([A-Z_a-z!$%&+\\-.:<=>?|*][0-9#\'A-Z_a-z!$%&+\\-.:<=>?|*]*)' 'name': 'meta.definition.global.clojure entity.name.global.clojure' } { # dynamic variables are rendered diferently @@ -364,7 +364,7 @@ 'patterns': [ { # copied from #symbol, plus a / at the end. Matches the "app/" part of # "app/*config*" - 'match': '([\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*][\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*\\d]*)/' + 'match': '([A-Z_a-z!$%&+\\-.:<=>?|*][0-9#\'A-Z_a-z!$%&+\\-.:<=>?|*]*)/' 'captures': '1': 'name': 'meta.symbol.namespace.clojure' @@ -373,12 +373,12 @@ 'symbol': 'patterns': [ { - 'match': '([\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*][\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*\\d]*)' + 'match': '([A-Z_a-z!$%&+\\-.:<=>?|*][0-9#\'A-Z_a-z!$%&+\\-.:<=>?|*]*)' 'name': 'meta.symbol.clojure' } ] 'var': - 'match': '(?<=(\\s|\\(|\\[|\\{)\\#)\'[a-zA-Z0-9\\.\\-\\_\\:\\+\\=\\>\\<\\/\\!\\?\\*]+(?=(\\s|\\)|\\]|\\}))' + 'match': '(?<=(\\s|\\(|\\[|\\{)\\#)\'[A-Z_a-z!$%&+\\-.:<=>?|*][0-9#\'A-Z_a-z!$%&+\\-.:<=>?|*/]*(?=(\\s|\\)|\\]|\\}))' 'name': 'meta.var.clojure' 'vector': 'begin': '(\\[)' From 5412432716e68e934d3306ccfccb10f6fdb2ca9a Mon Sep 17 00:00:00 2001 From: Nikita Prokopov Date: Mon, 27 Nov 2017 18:25:19 +0300 Subject: [PATCH 5/8] Updated specs --- spec/clojure-spec.coffee | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/spec/clojure-spec.coffee b/spec/clojure-spec.coffee index 2528dec..39c2558 100644 --- a/spec/clojure-spec.coffee +++ b/spec/clojure-spec.coffee @@ -117,14 +117,16 @@ describe "Clojure grammar", -> it "tokenizes global definitions", -> macros = ["ns", "declare", "def", "defn", "defn-", "defroutes", "compojure/defroutes", "rum.core/defc123-", "some.nested-ns/def-nested->symbol!?*", "def+!.?abc8:<>", "ns/def+!.?abc8:<>"] + symbols = ["foo", "f", "f'", "*f*"] for macro in macros - {tokens} = grammar.tokenizeLine "(#{macro} foo 'bar)" - expect(tokens[1]).toEqual value: macro, scopes: ["source.clojure", "meta.expression.clojure", "meta.definition.global.clojure", "keyword.control.clojure"] - expect(tokens[3]).toEqual value: "foo", scopes: ["source.clojure", "meta.expression.clojure", "meta.definition.global.clojure", "entity.global.clojure"] + for symbol in symbols + {tokens} = grammar.tokenizeLine "(#{macro} #{symbol} 'bar)" + expect(tokens[1]).toEqual value: macro, scopes: ["source.clojure", "meta.expression.clojure", "keyword.control.clojure"] + expect(tokens[3]).toEqual value: symbol, scopes: ["source.clojure", "meta.expression.clojure", "meta.definition.global.clojure entity.name.global.clojure"] it "tokenizes dynamic variables", -> - mutables = ["*ns*", "*foo-bar*"] + mutables = ["*ns*", "*foo-bar*", "*1#*"] for mutable in mutables {tokens} = grammar.tokenizeLine mutable @@ -155,10 +157,12 @@ describe "Clojure grammar", -> expect(tokens[3]).toEqual value: "'foo", scopes: ["source.clojure", "meta.expression.clojure", "meta.var.clojure"] it "tokenizes symbols", -> - {tokens} = grammar.tokenizeLine "foo/bar" - expect(tokens[0]).toEqual value: "foo", scopes: ["source.clojure", "meta.symbol.namespace.clojure"] - expect(tokens[1]).toEqual value: "/", scopes: ["source.clojure"] - expect(tokens[2]).toEqual value: "bar", scopes: ["source.clojure", "meta.symbol.clojure"] + for ns in ["foo", "f", "f1", "ns.ns"] + for symbol in ["bar", "b", "b2", "b'", "bar.bar"] + {tokens} = grammar.tokenizeLine "#{ns}/#{symbol}" + expect(tokens[0]).toEqual value: ns, scopes: ["source.clojure", "meta.symbol.namespace.clojure"] + expect(tokens[1]).toEqual value: "/", scopes: ["source.clojure"] + expect(tokens[2]).toEqual value: symbol, scopes: ["source.clojure", "meta.symbol.clojure"] testMetaSection = (metaScope, puncScope, startsWith, endsWith) -> # Entire expression on one line. From 3e93e3351150559607dba88396b649618eca7e70 Mon Sep 17 00:00:00 2001 From: Nikita Prokopov Date: Wed, 6 Dec 2017 12:37:17 +0300 Subject: [PATCH 6/8] meta.definition to capture whole expression, entity.name to capture just fn/var name --- grammars/clojure.cson | 14 ++------------ spec/clojure-spec.coffee | 8 ++++---- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/grammars/clojure.cson b/grammars/clojure.cson index 052e586..a91a580 100644 --- a/grammars/clojure.cson +++ b/grammars/clojure.cson @@ -284,6 +284,7 @@ '1': 'name': 'keyword.control.clojure' 'end': '(?=\\))' + 'name': 'meta.definition.global.clojure' 'patterns': [ { # there may be some metadata before an actual definition @@ -293,7 +294,7 @@ # recognizing a symbol as being defined here # copied and pasted from #symbol, screw it 'match': '([A-Z_a-z!$%&+\\-.:<=>?|*][0-9#\'A-Z_a-z!$%&+\\-.:<=>?|*]*)' - 'name': 'meta.definition.global.clojure entity.name.global.clojure' + 'name': 'entity.name.definition.clojure' } { # dynamic variables are rendered diferently 'include': '#dynamic-variables' @@ -321,17 +322,6 @@ { 'include': '#sexp' } - { - 'match': '(?<=\\()(.+?)(?=\\s|\\))' - 'captures': - '1': - 'name': 'entity.name.function.clojure' - 'patterns': [ - { - 'include': '$self' - } - ] - } { 'include': '$self' } diff --git a/spec/clojure-spec.coffee b/spec/clojure-spec.coffee index 39c2558..efba444 100644 --- a/spec/clojure-spec.coffee +++ b/spec/clojure-spec.coffee @@ -122,8 +122,8 @@ describe "Clojure grammar", -> for macro in macros for symbol in symbols {tokens} = grammar.tokenizeLine "(#{macro} #{symbol} 'bar)" - expect(tokens[1]).toEqual value: macro, scopes: ["source.clojure", "meta.expression.clojure", "keyword.control.clojure"] - expect(tokens[3]).toEqual value: symbol, scopes: ["source.clojure", "meta.expression.clojure", "meta.definition.global.clojure entity.name.global.clojure"] + expect(tokens[1]).toEqual value: macro, scopes: ["source.clojure", "meta.expression.clojure", "meta.definition.global.clojure", "keyword.control.clojure"] + expect(tokens[3]).toEqual value: symbol, scopes: ["source.clojure", "meta.expression.clojure", "meta.definition.global.clojure", "entity.name.definition.clojure"] it "tokenizes dynamic variables", -> mutables = ["*ns*", "*foo-bar*", "*1#*"] @@ -149,7 +149,7 @@ describe "Clojure grammar", -> for expr in expressions {tokens} = grammar.tokenizeLine expr - expect(tokens[1]).toEqual value: "foo", scopes: ["source.clojure", "meta.expression.clojure", "entity.name.function.clojure"] + expect(tokens[1]).toEqual value: "foo", scopes: ["source.clojure", "meta.expression.clojure", "meta.symbol.clojure"] it "tokenizes vars", -> {tokens} = grammar.tokenizeLine "(func #'foo)" @@ -213,7 +213,7 @@ describe "Clojure grammar", -> {tokens} = grammar.tokenizeLine "((foo bar) baz)" expect(tokens[0]).toEqual value: "(", scopes: ["source.clojure", "meta.expression.clojure", "punctuation.section.expression.begin.clojure"] expect(tokens[1]).toEqual value: "(", scopes: ["source.clojure", "meta.expression.clojure", "meta.expression.clojure", "punctuation.section.expression.begin.clojure"] - expect(tokens[2]).toEqual value: "foo", scopes: ["source.clojure", "meta.expression.clojure", "meta.expression.clojure", "entity.name.function.clojure"] + expect(tokens[2]).toEqual value: "foo", scopes: ["source.clojure", "meta.expression.clojure", "meta.expression.clojure", "meta.symbol.clojure"] expect(tokens[3]).toEqual value: " ", scopes: ["source.clojure", "meta.expression.clojure", "meta.expression.clojure"] expect(tokens[4]).toEqual value: "bar", scopes: ["source.clojure", "meta.expression.clojure", "meta.expression.clojure", "meta.symbol.clojure"] expect(tokens[5]).toEqual value: ")", scopes: ["source.clojure", "meta.expression.clojure", "meta.expression.clojure", "punctuation.section.expression.end.clojure"] From 9220e86db6f635f935a11f804044560031b5a97f Mon Sep 17 00:00:00 2001 From: Nikita Prokopov Date: Wed, 6 Dec 2017 16:21:38 +0300 Subject: [PATCH 7/8] Returned entity.name.function.clojure --- grammars/clojure.cson | 11 +++++++++++ spec/clojure-spec.coffee | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/grammars/clojure.cson b/grammars/clojure.cson index a91a580..124212d 100644 --- a/grammars/clojure.cson +++ b/grammars/clojure.cson @@ -322,6 +322,17 @@ { 'include': '#sexp' } + { + 'match': '(?<=\\()(.+?)(?=\\s|\\))' + 'captures': + '1': + 'name': 'entity.name.function.clojure' + 'patterns': [ + { + 'include': '$self' + } + ] + } { 'include': '$self' } diff --git a/spec/clojure-spec.coffee b/spec/clojure-spec.coffee index efba444..eb19a06 100644 --- a/spec/clojure-spec.coffee +++ b/spec/clojure-spec.coffee @@ -149,7 +149,7 @@ describe "Clojure grammar", -> for expr in expressions {tokens} = grammar.tokenizeLine expr - expect(tokens[1]).toEqual value: "foo", scopes: ["source.clojure", "meta.expression.clojure", "meta.symbol.clojure"] + expect(tokens[1]).toEqual value: "foo", scopes: ["source.clojure", "meta.expression.clojure", "entity.name.function.clojure"] it "tokenizes vars", -> {tokens} = grammar.tokenizeLine "(func #'foo)" @@ -213,7 +213,7 @@ describe "Clojure grammar", -> {tokens} = grammar.tokenizeLine "((foo bar) baz)" expect(tokens[0]).toEqual value: "(", scopes: ["source.clojure", "meta.expression.clojure", "punctuation.section.expression.begin.clojure"] expect(tokens[1]).toEqual value: "(", scopes: ["source.clojure", "meta.expression.clojure", "meta.expression.clojure", "punctuation.section.expression.begin.clojure"] - expect(tokens[2]).toEqual value: "foo", scopes: ["source.clojure", "meta.expression.clojure", "meta.expression.clojure", "meta.symbol.clojure"] + expect(tokens[2]).toEqual value: "foo", scopes: ["source.clojure", "meta.expression.clojure", "meta.expression.clojure", "entity.name.function.clojure"] expect(tokens[3]).toEqual value: " ", scopes: ["source.clojure", "meta.expression.clojure", "meta.expression.clojure"] expect(tokens[4]).toEqual value: "bar", scopes: ["source.clojure", "meta.expression.clojure", "meta.expression.clojure", "meta.symbol.clojure"] expect(tokens[5]).toEqual value: ")", scopes: ["source.clojure", "meta.expression.clojure", "meta.expression.clojure", "punctuation.section.expression.end.clojure"] From 1dfe95f4c8b731f38905651d0ab83374e47a5979 Mon Sep 17 00:00:00 2001 From: Wliu <50Wliu@users.noreply.github.com> Date: Thu, 7 Dec 2017 02:05:46 +0100 Subject: [PATCH 8/8] Fix indentation --- grammars/clojure.cson | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/grammars/clojure.cson b/grammars/clojure.cson index 124212d..2738bdb 100644 --- a/grammars/clojure.cson +++ b/grammars/clojure.cson @@ -323,16 +323,16 @@ 'include': '#sexp' } { - 'match': '(?<=\\()(.+?)(?=\\s|\\))' - 'captures': - '1': - 'name': 'entity.name.function.clojure' - 'patterns': [ - { - 'include': '$self' - } - ] - } + 'match': '(?<=\\()(.+?)(?=\\s|\\))' + 'captures': + '1': + 'name': 'entity.name.function.clojure' + 'patterns': [ + { + 'include': '$self' + } + ] + } { 'include': '$self' }