Skip to content

Commit 56cac86

Browse files
committed
Better keyword detection
1 parent b45dbdf commit 56cac86

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Syntax has been significantly reworked.
1010
- Quote & syntax quote highlight following form as `meta.quoted` and `meta.quoted.syntax`
1111
- Metadata highlights following form as `meta.metadata`
1212
- Octal & arbitrary radix integers
13+
- Better keyword detection
1314

1415
Other changes:
1516

Clojure (Sublimed).sublime-syntax

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ variables:
1313
sym_body: '[\p{Alpha}*!_?$%&=<>''\-+.#:0-9]'
1414
ns_symbol: '(?:[\-+.]|[\-+.]{{sym_head_lax}}{{sym_body}}*|{{sym_head}}{{sym_body}}*)'
1515
symbol: '(?:/|{{ns_symbol}})'
16-
kw_head: '[\p{Alpha}*!_?$%&=<>''\-+.#0-9]'
17-
kw_body: '[\p{Alpha}*!_?$%&=<>''\-+.#0-9:]'
18-
keyword: '{{kw_head}}{{kw_body}}*'
16+
kw: '\p{Alpha}*!_?$%&=<>''\-+.#0-9'
1917
regexp_name: '[a-zA-Z][a-zA-Z0-9]*'
2018
contexts:
2119
main:
@@ -225,13 +223,18 @@ contexts:
225223
pop: 1
226224

227225
keyword:
228-
- match: '{{wsb}}(::?)(?:{{keyword}}|({{keyword}})(/){{keyword}}){{wse}}'
226+
- match: '{{wsb}}(::?)([{{kw}}][{{kw}}:]*[{{kw}}]|[{{kw}}])(/)([{{kw}}:/]*[{{kw}}]|[{{kw}}]){{wse}}'
229227
scope: constant.other.keyword.clojure
230228
captures:
231229
1: punctuation.definition.keyword.begin.clojure
232230
2: meta.namespace.keyword.clojure
233231
3: punctuation.definition.namespace.clojure
234-
pop: 1
232+
pop: 1
233+
- match: '{{wsb}}(::?)([{{kw}}][{{kw}}:]*[{{kw}}]|[{{kw}}]){{wse}}'
234+
scope: constant.other.keyword.clojure
235+
captures:
236+
1: punctuation.definition.keyword.begin.clojure
237+
pop: 1
235238

236239
integer:
237240
- match: '{{wsb}}[+-]?(?:0[xX][0-9A-Fa-f]+|0[1-7]+|[1-9][0-9]*|[1-9][0-9]?[rR][0-9A-Za-z]+|0)(N)?{{wse}}'
@@ -540,13 +543,18 @@ contexts:
540543
pop: 2
541544

542545
deep_keyword:
543-
- match: '{{wsb}}(::?)(?:{{keyword}}|({{keyword}})(/){{keyword}}){{wse}}'
546+
- match: '{{wsb}}(::?)([{{kw}}][{{kw}}:]*[{{kw}}]|[{{kw}}])(/)([{{kw}}:/]*[{{kw}}]|[{{kw}}]){{wse}}'
544547
scope: constant.other.keyword.clojure
545548
captures:
546549
1: punctuation.definition.keyword.begin.clojure
547550
2: meta.namespace.keyword.clojure
548551
3: punctuation.definition.namespace.clojure
549552
pop: 2
553+
- match: '{{wsb}}(::?)([{{kw}}][{{kw}}:]*[{{kw}}]|[{{kw}}]){{wse}}'
554+
scope: constant.other.keyword.clojure
555+
captures:
556+
1: punctuation.definition.keyword.begin.clojure
557+
pop: 2
550558

551559
deep_integer:
552560
- match: '{{wsb}}[+-]?(?:0[xX][0-9A-Fa-f]+|0[1-7]+|[1-9][0-9]*|[1-9][0-9]?[rR][0-9A-Za-z]+|0)(N)?{{wse}}'

test_syntax/syntax_test_clojure.cljc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ string"
324324
; ^ -constant.other.keyword
325325
; ^^^^ constant.other.keyword
326326
; ^^^^ constant.other.keyword
327-
:. :* :+ :! :- :_ :? :$ :% :& := :< :> :# :1 :' :a: :k::v
327+
:. :* :+ :! :- :_ :? :$ :% :& := :< :> :# :1 :' :k::v
328328
; ^^ constant.other.keyword
329329
; ^^ constant.other.keyword
330330
; ^^ constant.other.keyword
@@ -341,8 +341,7 @@ string"
341341
; ^^ constant.other.keyword
342342
; ^^ constant.other.keyword
343343
; ^^ constant.other.keyword
344-
; ^^^ constant.other.keyword
345-
; ^^^^^ constant.other.keyword
344+
; ^^^^^ constant.other.keyword
346345
:a/b :1/2 :абв/где :abc.def/uvw.xyz
347346
; ^^^^ constant.other.keyword
348347
; ^ punctuation.definition.keyword.begin
@@ -365,10 +364,16 @@ string"
365364
; ^^ punctuation.definition.keyword.begin
366365
; ^ meta.namespace.keyword
367366
; ^ punctuation.definition.namespace
367+
:a:b :a/:b :a:b/c:d :a//b :k/v/v
368+
; ^^^^ constant.other.keyword
369+
; ^^^^^ constant.other.keyword
370+
; ^^^^^^^^ constant.other.keyword
371+
; ^^^^^ constant.other.keyword
372+
; ^^^^^^ constant.other.keyword
368373

369-
;; NOT KEYWORDS
370-
:kv/ :/kv :/ :k/:v :k/v/v :::kv
371-
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -constant.other.keyword
374+
;;;;; NOT KEYWORDS
375+
:kv: :kv/ :/kv :/ :kv/ab: :kv/ab/ :::kv
376+
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -constant.other.keyword
372377

373378

374379
;;;;;;;;;; INTEGERS ;;;;;;;;;;

0 commit comments

Comments
 (0)