Skip to content

Commit 7d0f5a4

Browse files
committed
Reordered syntax definitions
1 parent 77e2ebc commit 7d0f5a4

File tree

2 files changed

+149
-119
lines changed

2 files changed

+149
-119
lines changed

Clojure (Sublimed).sublime-syntax

Lines changed: 126 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ contexts:
2323
- include: line_comment
2424
- include: reader_comment
2525
- include: metadata
26+
- include: quote
2627
- include: syntax_quote
2728
- include: syntax_unquote
28-
- include: quote
29-
- include: var
3029
- include: deref
31-
- include: reader_conditional
3230
- match: (?=\S)
3331
push: forms
3432

@@ -37,47 +35,52 @@ contexts:
3735
- include: line_comment
3836
- include: reader_comment
3937
- include: metadata
40-
- include: anonymous_fn
41-
- include: regexp
42-
- include: string
38+
- include: quote
39+
- include: syntax_quote
40+
- include: syntax_unquote
41+
- include: deref
4342
- include: character
44-
- include: keyword
43+
- include: string
44+
- include: regexp
4545
- include: constant
46-
- include: symbol_unused
47-
- include: symbol
46+
- include: keyword
4847
- include: integer
4948
- include: float
5049
- include: ratio
51-
- include: tag
50+
- include: symbol_unused
51+
- include: symbol
52+
- include: var
5253
- include: list
54+
- include: anonymous_fn
55+
- include: reader_conditional
5356
- include: vector
5457
- include: map
5558
- include: set
59+
- include: tag
5660
- include: stray_bracket
5761

5862
comma:
5963
- match: ','
6064
scope: punctuation.definition.comma.clojure
6165

62-
var:
63-
- match: '#'''
64-
scope: punctuation.definition.var.clojure
65-
push:
66-
- meta_scope: meta.var.clojure
67-
- include: forms
66+
line_comment:
67+
- match: '(;+).*$'
68+
scope: comment.line.clojure
69+
captures:
70+
1: punctuation.definition.comment.line.clojure
6871

69-
deref:
70-
- match: '@'
71-
scope: keyword.operator.deref.clojure
72+
reader_comment:
73+
- match: '#_'
74+
scope: punctuation.definition.comment.reader.clojure
7275
push:
73-
- meta_scope: meta.deref.clojure
76+
- meta_scope: comment.reader.clojure
7477
- include: forms
7578

76-
reader_conditional:
77-
- match: '#\?@?'
78-
scope: punctuation.definition.reader_conditional.clojure meta.parens.clojure punctuation.section.parens.begin.clojure
79+
metadata:
80+
- match: '\^'
81+
scope: punctuation.definition.metadata.clojure
7982
push:
80-
- meta_scope: meta.reader_conditional.clojure
83+
- meta_scope: meta.metadata.clojure
8184
- include: forms
8285

8386
quote:
@@ -101,30 +104,37 @@ contexts:
101104
- meta_scope: meta.unquoted.clojure
102105
- include: forms
103106

104-
metadata:
105-
- match: '\^'
106-
scope: punctuation.definition.metadata.clojure
107+
deref:
108+
- match: '@'
109+
scope: keyword.operator.deref.clojure
107110
push:
108-
- meta_scope: meta.metadata.clojure
111+
- meta_scope: meta.deref.clojure
109112
- include: forms
110113

111-
anonymous_fn:
112-
- match: '(#)(\()'
114+
character:
115+
- match: '{{wsb}}((\\)(u\h{4}|o[0-3]?[0-7]{1,2}|newline|tab|space|backspace|formfeed|return|[^\s]){{wse}}|((\\){{nwse}}*))'
116+
scope: constant.character.clojure
113117
captures:
114-
1: punctuation.definition.anon_fn.clojure
115-
scope: punctuation.section.parens.begin.clojure
118+
2: punctuation.definition.character.begin.clojure
119+
4: invalid.illegal.character.clojure
120+
5: punctuation.definition.character.begin.clojure
121+
pop: 1
122+
123+
string:
124+
- match: '{{wsb}}"'
125+
scope: punctuation.definition.string.begin.clojure
116126
push:
117-
- meta_scope: meta.parens.clojure meta.function.anon.clojure
118-
- match: \)
119-
scope: punctuation.section.parens.end.clojure
127+
- meta_scope: string.quoted.double.clojure
128+
- match: '(\\)(u\h{4}|b|t|n|f|r|"|''|\\|[0-3]?[0-7]{1,2})|((\\).)'
129+
scope: constant.character.escape.clojure
130+
captures:
131+
1: punctuation.definition.character.escape.begin.clojure
132+
3: invalid.illegal.escape.string.clojure
133+
4: punctuation.definition.character.escape.begin.clojure
134+
- match: '"'
135+
scope: punctuation.definition.string.end.clojure
120136
pop: 2
121-
- include: main
122137

123-
constant:
124-
- match: '{{wsb}}(nil|true|false){{wse}}'
125-
scope: constant.language.clojure
126-
pop: 1
127-
128138
regexp_quote:
129139
- match: '\\Q'
130140
scope: punctuation.section.quotation.begin.clojure
@@ -191,42 +201,10 @@ contexts:
191201
- meta_scope: string.regexp.clojure
192202
- include: regexp_group
193203

194-
string:
195-
- match: '{{wsb}}"'
196-
scope: punctuation.definition.string.begin.clojure
197-
push:
198-
- meta_scope: string.quoted.double.clojure
199-
- match: '(\\)(u\h{4}|b|t|n|f|r|"|''|\\|[0-3]?[0-7]{1,2})|((\\).)'
200-
scope: constant.character.escape.clojure
201-
captures:
202-
1: punctuation.definition.character.escape.begin.clojure
203-
3: invalid.illegal.escape.string.clojure
204-
4: punctuation.definition.character.escape.begin.clojure
205-
- match: '"'
206-
scope: punctuation.definition.string.end.clojure
207-
pop: 2
208-
209-
character:
210-
- match: '{{wsb}}((\\)(u\h{4}|o[0-3]?[0-7]{1,2}|newline|tab|space|backspace|formfeed|return|[^\s]){{wse}}|((\\){{nwse}}*))'
211-
scope: constant.character.clojure
212-
captures:
213-
2: punctuation.definition.character.begin.clojure
214-
4: invalid.illegal.character.clojure
215-
5: punctuation.definition.character.begin.clojure
216-
pop: 1
217-
218-
line_comment:
219-
- match: '(;+).*$'
220-
scope: comment.line.clojure
221-
captures:
222-
1: punctuation.definition.comment.line.clojure
223-
224-
reader_comment:
225-
- match: '#_'
226-
scope: punctuation.definition.comment.reader.clojure
227-
push:
228-
- meta_scope: comment.reader.clojure
229-
- include: forms
204+
constant:
205+
- match: '{{wsb}}(nil|true|false){{wse}}'
206+
scope: constant.language.clojure
207+
pop: 1
230208

231209
keyword:
232210
- match: '{{wsb}}(::?)(?:{{keyword}}|({{keyword}})(/){{keyword}}){{wse}}'
@@ -262,6 +240,49 @@ contexts:
262240
scope: constant.numeric.ratio.clojure
263241
pop: 1
264242

243+
symbol_def:
244+
- match: '{{wsb}}(?:(?=def){{symbol}}|({{ns_symbol}})(/)(?=def){{symbol}}){{wse}}'
245+
scope: source.symbol.def.clojure
246+
captures:
247+
1: meta.namespace.symbol.clojure
248+
2: punctuation.definition.namespace.clojure
249+
pop: 1
250+
push: list_second
251+
252+
symbol_name:
253+
- match: '{{wsb}}(?:{{symbol}}|({{ns_symbol}})(/){{symbol}}){{wse}}'
254+
scope: source.symbol.clojure entity.name.clojure
255+
captures:
256+
1: meta.namespace.symbol.clojure
257+
2: punctuation.definition.namespace.clojure
258+
pop: 1
259+
push: list_rest
260+
261+
symbol_unused:
262+
- match: '{{wsb}}(?:(?=_){{symbol}}|({{ns_symbol}})(/)(?=_){{symbol}}){{wse}}'
263+
scope: source.symbol.unused.clojure
264+
captures:
265+
1: meta.namespace.symbol.clojure
266+
2: punctuation.definition.namespace.clojure
267+
pop: 1
268+
269+
symbol:
270+
- match: '{{wsb}}(?:{{symbol}}|({{ns_symbol}})(/){{symbol}}){{wse}}'
271+
scope: source.symbol.clojure
272+
captures:
273+
1: meta.namespace.symbol.clojure
274+
2: punctuation.definition.namespace.clojure
275+
pop: 1
276+
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+
265286
tag:
266287
- 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}}'
267288
scope: constant.other.instant.clojure
@@ -349,39 +370,32 @@ contexts:
349370
pop: 2
350371
- include: main
351372

352-
symbol_def:
353-
- match: '{{wsb}}(?:(?=def){{symbol}}|({{ns_symbol}})(/)(?=def){{symbol}}){{wse}}'
354-
scope: source.symbol.def.clojure
355-
captures:
356-
1: meta.namespace.symbol.clojure
357-
2: punctuation.definition.namespace.clojure
358-
pop: 1
359-
push: list_second
360-
361-
symbol_name:
362-
- match: '{{wsb}}(?:{{symbol}}|({{ns_symbol}})(/){{symbol}}){{wse}}'
363-
scope: source.symbol.clojure entity.name.clojure
364-
captures:
365-
1: meta.namespace.symbol.clojure
366-
2: punctuation.definition.namespace.clojure
367-
pop: 1
368-
push: list_rest
369-
370-
symbol_unused:
371-
- match: '{{wsb}}(?:(?=_){{symbol}}|({{ns_symbol}})(/)(?=_){{symbol}}){{wse}}'
372-
scope: source.symbol.unused.clojure
373+
anonymous_fn:
374+
- match: '(#)(\()'
373375
captures:
374-
1: meta.namespace.symbol.clojure
375-
2: punctuation.definition.namespace.clojure
376-
pop: 1
376+
1: punctuation.definition.anon_fn.clojure
377+
scope: punctuation.section.parens.begin.clojure
378+
push:
379+
- meta_scope: meta.parens.clojure meta.function.anon.clojure
380+
- match: \)
381+
scope: punctuation.section.parens.end.clojure
382+
pop: 2
383+
- include: main
377384

378-
symbol:
379-
- match: '{{wsb}}(?:{{symbol}}|({{ns_symbol}})(/){{symbol}}){{wse}}'
380-
scope: source.symbol.clojure
381-
captures:
382-
1: meta.namespace.symbol.clojure
383-
2: punctuation.definition.namespace.clojure
384-
pop: 1
385+
reader_conditional:
386+
- match: '#\?@?'
387+
scope: punctuation.definition.reader_conditional.clojure punctuation.section.parens.begin.clojure
388+
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
385399

386400
vector:
387401
- match: \[
@@ -417,3 +431,7 @@ contexts:
417431
- match: '[\]\)\}]'
418432
scope: invalid.illegal.stray-bracket-end
419433
pop: 1
434+
435+
fail:
436+
- match: '(?=\S)'
437+
pop: 1

test_syntax/syntax_test_clojure.cljc

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -539,12 +539,14 @@ string"
539539
#'map
540540
; ^^^^^ meta.var
541541
; ^ punctuation.definition.var
542-
#' ,,, #_skip map
543-
; ^^^^^^^^^^^^^^^^^ meta.var
542+
#' ,,, map
543+
; ^^^^^^^^^^ meta.var
544544
; ^^ punctuation.definition.var
545-
; ^^^^^^^^^^^^^^^ - punctuation.definition.var
545+
; ^^^^^^^^ - punctuation.definition.var
546546
; ^^^ punctuation.definition.comma
547-
547+
#'123
548+
; ^^ meta.var
549+
; ^^^ - meta.var
548550

549551
;;;;;;;;;; DEREF ;;;;;;;;;;
550552

@@ -561,22 +563,32 @@ string"
561563
;;;;;;;;;; READER CONDITIONALS ;;;;;;;;;;
562564

563565
#?(:clj 1 :cljs 2)
564-
; ^^^^^^^^^^^^^^^^^^ meta.reader_conditional
566+
; ^^^^^^^^^^^^^^^^^^ meta.reader_conditional meta.parens
567+
; ^^^ punctuation.section.parens.begin
565568
; ^^ punctuation.definition.reader_conditional
566-
; ^ punctuation.section.parens.begin
567-
; ^^^^^^^^^^^^^^^^ meta.parens
568569
; ^ punctuation.section.parens.end
569570
; ^ - punctuation - meta.section
570571
#?@(:clj [3 4] :cljs [5 6])
571-
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.reader_conditional
572+
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.reader_conditional meta.parens
572573
; ^^^ punctuation.definition.reader_conditional
573-
; ^ punctuation.section.parens.begin
574-
; ^^^^^^^^^^^^^^^^^^^^^^^^ meta.parens
574+
; ^^^^ punctuation.section.parens.begin
575575
; ^ punctuation.section.parens.end
576576
; ^ - punctuation - meta.section
577577
#? ,,, ,, (:clj 1 :cljs 2)
578-
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.reader_conditional
578+
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.reader_conditional meta.parens
579579
; ^^ punctuation.definition.reader_conditional
580+
; ^^ punctuation.section.parens.begin
581+
; ^ punctuation.section.parens.begin
582+
; ^^^ punctuation.definition.comma
583+
; ^^ punctuation.definition.comma
584+
[[#?(:clj 1 :cljs 2)]]
585+
; ^^^^^^^^^^^^^^^^^^ meta.reader_conditional meta.parens
586+
#? #_clj (:clj 123)
587+
; ^^ meta.reader_conditional
588+
; ^^^^^^^^^^^^^^^^ - meta.reader_conditional
589+
#? [123]
590+
; ^^ meta.reader_conditional
591+
; ^^^^^ - meta.reader_conditional
580592

581593

582594
;;;;;;;;;; QUOTE ;;;;;;;;;;

0 commit comments

Comments
 (0)