diff --git a/grammars/clojure.cson b/grammars/clojure.cson index 7af94e5..2738bdb 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' @@ -290,14 +290,14 @@ # 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': 'entity.global.clojure' + 'match': '([A-Z_a-z!$%&+\\-.:<=>?|*][0-9#\'A-Z_a-z!$%&+\\-.:<=>?|*]*)' + 'name': 'entity.name.definition.clojure' + } + { # dynamic variables are rendered diferently + 'include': '#dynamic-variables' } { 'include': '$self' @@ -327,11 +327,11 @@ 'captures': '1': 'name': 'entity.name.function.clojure' - 'patterns': [ - { - 'include': '$self' - } - ] + 'patterns': [ + { + 'include': '$self' + } + ] } { 'include': '$self' @@ -365,7 +365,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' @@ -374,12 +374,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': '(\\[)' diff --git a/spec/clojure-spec.coffee b/spec/clojure-spec.coffee index 2528dec..eb19a06 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", "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*"] + 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.