Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Syntax improvements for defs and symbols #75

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions grammars/clojure.cson
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
}
]
'dynamic-variables':
'match': '\\*[\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\d]+\\*'
'match': '\\*[0-9#\'A-Z_a-z!$%&+\\-.:<=>?|]+\\*'
'name': 'meta.symbol.dynamic.clojure'
'map':
'begin': '(\\{)'
Expand Down Expand Up @@ -279,7 +279,7 @@
'patterns': [
{
# ns, declare and everything that starts with def* or namespace/def*
'begin': '(?<=\\()(ns|declare|def[\\w\\d._:+=><!?*-]*|[\\w._:+=><!?*-][\\w\\d._:+=><!?*-]*/def[\\w\\d._:+=><!?*-]*)\\s+'
'begin': '(?<=\\()(ns|declare|def[0-9#\'A-Z_a-z!$%&+\\-.:<=>?|*]*|[A-Z_a-z!$%&+\\-.:<=>?|*][0-9#\'A-Z_a-z!$%&+\\-.:<=>?|*]*/def[0-9#\'A-Z_a-z!$%&+\\-.:<=>?|*]*)\\s+'
'beginCaptures':
'1':
'name': 'keyword.control.clojure'
Expand All @@ -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'
Expand Down Expand Up @@ -327,11 +327,11 @@
'captures':
'1':
'name': 'entity.name.function.clojure'
'patterns': [
{
'include': '$self'
}
]
'patterns': [
{
'include': '$self'
}
]
}
{
'include': '$self'
Expand Down Expand Up @@ -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'
Expand All @@ -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': '(\\[)'
Expand Down
20 changes: 12 additions & 8 deletions spec/clojure-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down