Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
143 changes: 136 additions & 7 deletions grammars/clojure.cson
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
{
'include': '#constants'
}
{
'include': '#dynamic-variables'
}
{
'include': '#metadata'
}
{
'include': '#namespace-symbol'
}
{
'include': '#symbol'
}
Expand Down Expand Up @@ -89,11 +98,13 @@
'match': '(\\d+)'
'name': 'constant.numeric.decimal.clojure'
}
{
'match': '(?<=(\\s|\\(|\\[|\\{)):[a-zA-Z0-9\\#\\.\\-\\_\\:\\+\\=\\>\\<\\/\\!\\?\\*]+(?=(\\s|\\)|\\]|\\}))'
'name': 'constant.keyword.clojure'
{ # separating the pattern for reuse
'include': '#keyword'
}
]
'keyword':
'match': '(?<=(\\s|\\(|\\[|\\{)):[a-zA-Z0-9\\#\\.\\-\\_\\:\\+\\=\\>\\<\\/\\!\\?\\*]+(?=(\\s|\\)|\\]|\\}))'
'name': 'constant.keyword.clojure'
'keyfn':
'patterns': [
{
Expand All @@ -105,15 +116,56 @@
'name': 'keyword.control.clojure'
}
]
'dynamic-variables':
'match': '\\*[\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\d]+\\*'
'name': 'meta.symbol.dynamic.clojure'
'map':
'begin': '(\\{)'
'beginCaptures':
'1':
'name': 'punctuation.section.map.begin.clojure'
'end': '(\\})'
'endCaptures':
'1':
'name': 'punctuation.section.map.end.clojure'
'name': 'meta.map.clojure'
'patterns': [
{
'include': '$self'
}
]
'metadata':
'patterns': [
{
'begin': '(\\^\\{)'
'beginCaptures':
'1':
'name': 'punctuation.section.metadata.map.begin.clojure'
'end': '(\\})'
'endCaptures':
'1':
'name': 'punctuation.section.metadata.map.end.clojure'
'name': 'meta.metadata.map.clojure'
'patterns': [
{
'include': '$self'
}
]
}
{
'begin': '(\\^)'
'end': '(\\s)'
'name': 'meta.metadata.simple.clojure'
'patterns': [
{
'include': '#keyword'
}
{
'include': '$self'
}
]
}
]
'quoted-sexp':
'begin': '([\'``]\\()'
'beginCaptures':
Expand Down Expand Up @@ -145,7 +197,13 @@
'name': 'string.regexp.clojure'
'set':
'begin': '(\\#\\{)'
'beginCaptures':
'1':
'name': 'punctuation.section.set.begin.clojure'
'end': '(\\})'
'endCaptures':
'1':
'name': 'punctuation.section.set.end.clojure'
'name': 'meta.set.clojure'
'patterns': [
{
Expand All @@ -166,14 +224,75 @@
'name': 'meta.expression.clojure'
'patterns': [
{
'begin': '(?<=\\()(ns|def|def-|defn|defn-|defvar|defvar-|defmacro|defmacro-|deftest)\\s+(.+?)(?=\\s|\\))'
'begin': '(?<=\\()(ns|def|def-|defn|defn-|defvar|defvar-|defmacro|defmacro-|deftest)\\s+'
'beginCaptures':
'1':
'name': 'keyword.control.clojure'
'2':
'name': 'entity.global.clojure'
'end': '(?=\\))'
'name': 'meta.definition.global.clojure'
'patterns': [
{
# there may be some metadata before an actual definition
'include': '#metadata'
'patterns': [
{
'include': '$self'
}
]
}
{ # dynamic variables are rendered diferently
'include': '#dynamic-variables'
'patterns': [
{
'include': '$self'
}
]
}
{
# recognizing a symbol as being defined here
# copied and pasted from #symbol, screw it
'match': '([\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*][\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*\\d]+)'
'name': 'entity.global.clojure'
'patterns': [
{
'include': '$self'
}
]
}
{
'include': '$self'
}
]
}
{
'include': '#keyfn'
'patterns': [
{
'include': '$self'
}
]
}
{
'include': '#constants'
'patterns': [
{
'include': '$self'
}
]
}
{
'include': '#vector'
'patterns': [
{
'include': '$self'
}
]
}
{
'match': '(?<=\\()(.+?)(?=\\s|\\))'
'captures':
'1':
'name': 'entity.name.function.clojure'
'patterns': [
{
'include': '$self'
Expand Down Expand Up @@ -206,10 +325,20 @@
'name': 'constant.character.escape.clojure'
}
]
'namespace-symbol':
'patterns': [
{ # copied from #symbol, plus a / at the end. Matches the "app/" part of
# "app/*config*"
'match': '([\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*][\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*\\d]+)/'
'captures':
'1':
'name': 'meta.symbol.namespace.clojure'
}
]
'symbol':
'patterns': [
{
'match': '(\\w[\\w\\d]+)'
'match': '([\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*][\\w\\.\\-\\_\\:\\+\\=\\>\\<\\!\\?\\*\\d]+)'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to have these all escaped since they are already in a character class. The only ones for sure would be things like \w and - to differentiate it from a range.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not. I copied it from somewhere else in the grammar; maybe the #keyword definition. Works well enough 😄

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, lets just leave it then

'name': 'meta.symbol.clojure'
}
]
Expand Down