Skip to content

Commit 698791c

Browse files
committed
Grouped syntax definitions by type, made #' and @ non-wrapping, simplified reader_conditional
1 parent 7d0f5a4 commit 698791c

File tree

3 files changed

+160
-101
lines changed

3 files changed

+160
-101
lines changed

Clojure (Sublimed).sublime-syntax

Lines changed: 107 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,46 @@ variables:
1919
regexp_name: '[a-zA-Z][a-zA-Z0-9]*'
2020
contexts:
2121
main:
22-
- include: comma
23-
- include: line_comment
24-
- include: reader_comment
25-
- include: metadata
26-
- include: quote
27-
- include: syntax_quote
28-
- include: syntax_unquote
29-
- include: deref
22+
- include: skip_forms
23+
- include: wrap_forms
3024
- match: (?=\S)
31-
push: forms
25+
push:
26+
- include: forms
3227

3328
forms:
29+
- include: skip_forms
30+
- include: wrap_forms
31+
- include: normal_forms
32+
- include: stray_bracket
33+
34+
deep_forms:
35+
- include: skip_forms
36+
- include: deep_normal_forms
37+
- include: stray_bracket
38+
39+
40+
# SKIP FORMS
41+
42+
skip_forms:
3443
- include: comma
44+
- include: deref
45+
- include: var
3546
- include: line_comment
3647
- include: reader_comment
3748
- include: metadata
38-
- include: quote
39-
- include: syntax_quote
40-
- include: syntax_unquote
41-
- include: deref
42-
- include: character
43-
- include: string
44-
- include: regexp
45-
- include: constant
46-
- include: keyword
47-
- include: integer
48-
- include: float
49-
- include: ratio
50-
- include: symbol_unused
51-
- include: symbol
52-
- include: var
53-
- include: list
54-
- include: anonymous_fn
55-
- include: reader_conditional
56-
- include: vector
57-
- include: map
58-
- include: set
59-
- include: tag
60-
- include: stray_bracket
6149

6250
comma:
6351
- match: ','
6452
scope: punctuation.definition.comma.clojure
6553

54+
deref:
55+
- match: '@'
56+
scope: keyword.operator.deref.clojure
57+
58+
var:
59+
- match: '#'''
60+
scope: punctuation.definition.var.clojure
61+
6662
line_comment:
6763
- match: '(;+).*$'
6864
scope: comment.line.clojure
@@ -83,6 +79,13 @@ contexts:
8379
- meta_scope: meta.metadata.clojure
8480
- include: forms
8581

82+
# WRAP FORMS
83+
84+
wrap_forms:
85+
- include: quote
86+
- include: syntax_quote
87+
- include: syntax_unquote
88+
8689
quote:
8790
- match: ''''
8891
scope: keyword.operator.quote.clojure
@@ -104,12 +107,27 @@ contexts:
104107
- meta_scope: meta.unquoted.clojure
105108
- include: forms
106109

107-
deref:
108-
- match: '@'
109-
scope: keyword.operator.deref.clojure
110-
push:
111-
- meta_scope: meta.deref.clojure
112-
- include: forms
110+
111+
# NORMAL FORMS
112+
113+
normal_forms:
114+
- include: character
115+
- include: string
116+
- include: regexp
117+
- include: constant
118+
- include: keyword
119+
- include: integer
120+
- include: float
121+
- include: ratio
122+
- include: symbol_unused
123+
- include: symbol
124+
- include: list
125+
- include: anonymous_fn
126+
- include: reader_conditional
127+
- include: vector
128+
- include: map
129+
- include: set
130+
- include: tag
113131

114132
character:
115133
- match: '{{wsb}}((\\)(u\h{4}|o[0-3]?[0-7]{1,2}|newline|tab|space|backspace|formfeed|return|[^\s]){{wse}}|((\\){{nwse}}*))'
@@ -274,30 +292,6 @@ contexts:
274292
2: punctuation.definition.namespace.clojure
275293
pop: 1
276294

277-
var:
278-
- match: '#'''
279-
scope: punctuation.definition.var.clojure
280-
push:
281-
- meta_scope: meta.var.clojure
282-
- include: symbol
283-
- include: comma
284-
- include: fail
285-
286-
tag:
287-
- match: '{{wsb}}(#inst\s*"\d\d\d\d(?:-[01]\d(?:-[0123]\d(?:T[012]\d(?::[012345]\d(?::[0123456]\d(?:[.]\d{1,9})?)?)?)?)?)?(?:Z|[-+][012]\d:[012345]\d)?"|(#inst\s*"[^"]*")){{wse}}'
288-
scope: constant.other.instant.clojure
289-
captures:
290-
2: invalid.illegal.instant.clojure
291-
pop: 1
292-
- match: '{{wsb}}(#uuid\s*"\h{8}-\h{4}-\h{4}-\h{4}-\h{12}"|(#uuid\s*"[^"]*")){{wse}}'
293-
scope: constant.other.uuid.clojure
294-
captures:
295-
2: invalid.illegal.uuid.clojure
296-
pop: 1
297-
- match: '{{wsb}}#(?![_#{])(?:{{symbol}}|{{ns_symbol}}(/){{symbol}}){{wse}}'
298-
scope: storage.type.tag.clojure
299-
pop: 1
300-
301295
list:
302296
- match: '(?=\()'
303297
branch_point: open_parens
@@ -379,23 +373,20 @@ contexts:
379373
- meta_scope: meta.parens.clojure meta.function.anon.clojure
380374
- match: \)
381375
scope: punctuation.section.parens.end.clojure
382-
pop: 2
376+
pop: 2
383377
- include: main
384378

385379
reader_conditional:
386-
- match: '#\?@?'
387-
scope: punctuation.definition.reader_conditional.clojure punctuation.section.parens.begin.clojure
380+
- match: '(#\?@?)\s*\('
381+
captures:
382+
1: punctuation.definition.reader_conditional.clojure
383+
scope: punctuation.section.parens.begin.clojure
388384
push:
389-
- meta_scope: meta.reader_conditional.clojure meta.parens.clojure
390-
- include: comma
391-
- match: '\('
392-
scope: punctuation.section.parens.begin.clojure
393-
push:
394-
- match: '\)'
395-
scope: punctuation.section.parens.end.clojure
396-
pop: 3
397-
- include: main
398-
- include: fail
385+
- meta_scope: meta.parens.clojure meta.reader_conditional.clojure
386+
- match: '\)'
387+
scope: punctuation.section.parens.end.clojure
388+
pop: 2
389+
- include: main
399390

400391
vector:
401392
- match: \[
@@ -427,6 +418,47 @@ contexts:
427418
pop: 2
428419
- include: main
429420

421+
tag:
422+
- match: '{{wsb}}(#inst\s*"\d\d\d\d(?:-[01]\d(?:-[0123]\d(?:T[012]\d(?::[012345]\d(?::[0123456]\d(?:[.]\d{1,9})?)?)?)?)?)?(?:Z|[-+][012]\d:[012345]\d)?"|(#inst\s*"[^"]*")){{wse}}'
423+
scope: constant.other.instant.clojure
424+
captures:
425+
2: invalid.illegal.instant.clojure
426+
pop: 1
427+
- match: '{{wsb}}(#uuid\s*"\h{8}-\h{4}-\h{4}-\h{4}-\h{12}"|(#uuid\s*"[^"]*")){{wse}}'
428+
scope: constant.other.uuid.clojure
429+
captures:
430+
2: invalid.illegal.uuid.clojure
431+
pop: 1
432+
- match: '{{wsb}}#(?![_#{])(?:{{symbol}}|{{ns_symbol}}(/){{symbol}}){{wse}}'
433+
scope: storage.type.tag.clojure
434+
pop: 1
435+
436+
437+
# DEEP FORMS
438+
439+
deep_normal_forms:
440+
- include: deep_character
441+
- include: deep_string
442+
- include: deep_regexp
443+
- include: deep_constant
444+
- include: deep_keyword
445+
- include: deep_integer
446+
- include: deep_float
447+
- include: deep_ratio
448+
- include: deep_symbol_unused
449+
- include: deep_symbol
450+
- include: deep_var
451+
- include: deep_list
452+
- include: deep_anonymous_fn
453+
- include: deep_reader_conditional
454+
- include: deep_vector
455+
- include: deep_map
456+
- include: deep_set
457+
- include: deep_tag
458+
459+
460+
# ERRORS
461+
430462
stray_bracket:
431463
- match: '[\]\)\}]'
432464
scope: invalid.illegal.stray-bracket-end

test_syntax/syntax_test_clojure.cljc

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ string"
253253
ghi
254254
; ^^^ - comment
255255

256+
(((#_x)))
257+
; ^^^^^ meta.parens meta.parens meta.parens
258+
; ^^^ comment.reader
256259

257260
;;;;;;;;;; SYMBOLS ;;;;;;;;;;
258261

@@ -537,58 +540,44 @@ string"
537540
;;;;;;;;;; VAR QUOTE ;;;;;;;;;;
538541

539542
#'map
540-
; ^^^^^ meta.var
541-
; ^ punctuation.definition.var
543+
; ^^ punctuation.definition.var
542544
#' ,,, map
543-
; ^^^^^^^^^^ meta.var
544545
; ^^ punctuation.definition.var
545-
; ^^^^^^^^ - punctuation.definition.var
546-
; ^^^ punctuation.definition.comma
547-
#'123
548-
; ^^ meta.var
549-
; ^^^ - meta.var
546+
(((#'map)))
547+
; ^^^^^^^ meta.parens meta.parens meta.parens
548+
; ^^ punctuation.definition.var
549+
550550

551551
;;;;;;;;;; DEREF ;;;;;;;;;;
552552

553553
@*atom
554-
; ^^^^^^ meta.deref
555554
; ^ keyword.operator.deref
556555
@ , *atom
557-
; ^^^^^^^^^ meta.deref
558556
; ^ keyword.operator.deref
559557
; ^^^^^^^^ - keyword.operator.deref
560558
; ^ punctuation.definition.comma
559+
(((@map)))
560+
; ^^^^^^ meta.parens meta.parens meta.parens
561+
; ^ keyword.operator.deref
561562

562563

563564
;;;;;;;;;; READER CONDITIONALS ;;;;;;;;;;
564-
565565
#?(:clj 1 :cljs 2)
566-
; ^^^^^^^^^^^^^^^^^^ meta.reader_conditional meta.parens
566+
; ^^^^^^^^^^^^^^^^^^ meta.parens meta.reader_conditional
567567
; ^^^ punctuation.section.parens.begin
568568
; ^^ punctuation.definition.reader_conditional
569569
; ^ punctuation.section.parens.end
570570
; ^ - punctuation - meta.section
571571
#?@(:clj [3 4] :cljs [5 6])
572-
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.reader_conditional meta.parens
572+
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.parens meta.reader_conditional
573573
; ^^^ punctuation.definition.reader_conditional
574574
; ^^^^ punctuation.section.parens.begin
575575
; ^ punctuation.section.parens.end
576576
; ^ - punctuation - meta.section
577-
#? ,,, ,, (:clj 1 :cljs 2)
578-
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.reader_conditional meta.parens
579-
; ^^ punctuation.definition.reader_conditional
580-
; ^^ punctuation.section.parens.begin
581-
; ^ punctuation.section.parens.begin
582-
; ^^^ punctuation.definition.comma
583-
; ^^ punctuation.definition.comma
584577
[[#?(:clj 1 :cljs 2)]]
585-
; ^^^^^^^^^^^^^^^^^^ meta.reader_conditional meta.parens
586-
#? #_clj (:clj 123)
587-
; ^^ meta.reader_conditional
588-
; ^^^^^^^^^^^^^^^^ - meta.reader_conditional
578+
; ^^^^^^^^^^^^^^^^^^ meta.parens meta.reader_conditional
589579
#? [123]
590-
; ^^ meta.reader_conditional
591-
; ^^^^^ - meta.reader_conditional
580+
; ^^^^^^^^ - meta.reader_conditional
592581

593582

594583
;;;;;;;;;; QUOTE ;;;;;;;;;;
@@ -630,6 +619,10 @@ string"
630619
''()()()
631620
; ^^^^ meta.quoted
632621
; ^^^^ - meta.quoted
622+
(('x))
623+
; ^^^^ meta.parens meta.parens
624+
; ^^ meta.quoted
625+
; ^^ - meta.quoted
633626
(((''x y z)))
634627
; ^^^^^^^^^^^^^ meta.parens
635628
; ^^^^^^^^^^^ meta.parens meta.parens
@@ -640,6 +633,11 @@ string"
640633

641634
;;;;;;;;;; SYNTAX QUOTE, UNQUOTE, UNQUOTE SPLICING ;;;;;;;;;;
642635

636+
((`x))
637+
; ^^^^ meta.parens meta.parens
638+
; ^^ meta.quoted.syntax
639+
; ^^ - meta.quoted.syntax
640+
643641
`(let [x# ~x] ~@(do `(...))) []
644642
; ^ keyword.operator.quote.syntax
645643
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.quoted.syntax
@@ -711,6 +709,10 @@ string"
711709
^^()()()
712710
; ^^^^ meta.metadata
713711
; ^^^^ - meta.metadata
712+
(((^x y)))
713+
; ^^^^^^ meta.parens meta.parens meta.parens
714+
; ^^ meta.metadata
715+
; ^^ - meta.metadata
714716
(((^^x y z)))
715717
; ^^^^^^^^^^^^^ meta.parens
716718
; ^^^^^^^^^^^ meta.parens meta.parens
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; SYNTAX TEST "Clojure (Sublimed).sublime-syntax"
2+
3+
#' ,,, map
4+
; ^^^^^^^^^^ meta.var
5+
; ^^ punctuation.definition.var
6+
; ^^^^^^^^ - punctuation.definition.var
7+
; ^^^ punctuation.definition.comma
8+
#'123
9+
; ^^ meta.var
10+
; ^^^ - meta.var
11+
12+
@ , *atom
13+
; ^^^^^^^^^ meta.deref
14+
15+
#? ,,, ,, (:clj 1 :cljs 2)
16+
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.reader_conditional meta.parens
17+
; ^^ punctuation.definition.reader_conditional
18+
; ^^ punctuation.section.parens.begin
19+
; ^ punctuation.section.parens.begin
20+
; ^^^ punctuation.definition.comma
21+
; ^^ punctuation.definition.comma
22+
23+
#? #_clj (:clj 123)
24+
; ^^ meta.reader_conditional
25+
; ^^^^^^^^^^^^^^^^ - meta.reader_conditional

0 commit comments

Comments
 (0)