Skip to content

Commit 40d7e4e

Browse files
committed
Quotes can correctly wrap up to 1 level at once
1 parent 698791c commit 40d7e4e

File tree

3 files changed

+316
-16
lines changed

3 files changed

+316
-16
lines changed

Clojure (Sublimed).sublime-syntax

Lines changed: 286 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ variables:
2020
contexts:
2121
main:
2222
- include: skip_forms
23-
- include: wrap_forms
2423
- match: (?=\S)
2524
push:
2625
- include: forms
@@ -79,6 +78,7 @@ contexts:
7978
- meta_scope: meta.metadata.clojure
8079
- include: forms
8180

81+
8282
# WRAP FORMS
8383

8484
wrap_forms:
@@ -91,21 +91,21 @@ contexts:
9191
scope: keyword.operator.quote.clojure
9292
push:
9393
- meta_scope: meta.quoted.clojure
94-
- include: forms
94+
- include: deep_forms
9595

9696
syntax_quote:
9797
- match: '`'
9898
scope: keyword.operator.quote.syntax.clojure
9999
push:
100100
- meta_scope: meta.quoted.syntax.clojure
101-
- include: forms
101+
- include: deep_forms
102102

103103
syntax_unquote:
104104
- match: '~@?'
105105
scope: keyword.operator.unquote.clojure
106106
push:
107107
- meta_scope: meta.unquoted.clojure
108-
- include: forms
108+
- include: deep_forms
109109

110110

111111
# NORMAL FORMS
@@ -456,6 +456,288 @@ contexts:
456456
- include: deep_set
457457
- include: deep_tag
458458

459+
deep_character:
460+
- match: '{{wsb}}((\\)(u\h{4}|o[0-3]?[0-7]{1,2}|newline|tab|space|backspace|formfeed|return|[^\s]){{wse}}|((\\){{nwse}}*))'
461+
scope: constant.character.clojure
462+
captures:
463+
2: punctuation.definition.character.begin.clojure
464+
4: invalid.illegal.character.clojure
465+
5: punctuation.definition.character.begin.clojure
466+
pop: 2
467+
468+
deep_string:
469+
- match: '{{wsb}}"'
470+
scope: punctuation.definition.string.begin.clojure
471+
push:
472+
- meta_scope: string.quoted.double.clojure
473+
- match: '(\\)(u\h{4}|b|t|n|f|r|"|''|\\|[0-3]?[0-7]{1,2})|((\\).)'
474+
scope: constant.character.escape.clojure
475+
captures:
476+
1: punctuation.definition.character.escape.begin.clojure
477+
3: invalid.illegal.escape.string.clojure
478+
4: punctuation.definition.character.escape.begin.clojure
479+
- match: '"'
480+
scope: punctuation.definition.string.end.clojure
481+
pop: 3
482+
483+
deep_regexp_shared:
484+
- match: '(\\)(\\|0[0-3]?[0-7]{1,2}|x\h{2}|u\h{4}|x\{1?\h{1,5}\}|\N\{[a-zA-Z0-9\- ]+\}|[tnrfae]|c[A-Z]|[dDhHsSvVwW]|p\{[a-zA-Z]+\}|b\{g\}|[bBAGZz]|[RX]|[0-9]+|k<{{regexp_name}}>|[^a-zA-Z0-9])|((\\).)'
485+
scope: constant.character.escape.clojure
486+
captures:
487+
1: punctuation.definition.character.escape.begin.clojure
488+
3: invalid.illegal.escape.regexp.clojure
489+
4: punctuation.definition.character.escape.begin.clojure
490+
- match: '"'
491+
scope: punctuation.definition.string.end.clojure
492+
pop: 3
493+
- match: '(\[)(\^)?(-)?'
494+
captures:
495+
1: punctuation.section.brackets.begin.clojure
496+
2: keyword.operator.negation.regexp.clojure
497+
push:
498+
- match: '(?=")'
499+
pop: 1
500+
- match: '\]'
501+
scope: punctuation.section.brackets.end.clojure
502+
pop: 1
503+
- match: '-(?!\])'
504+
scope: keyword.operator.range.regexp.clojure
505+
- match: '&&'
506+
scope: keyword.operator.intersection.regexp.clojure
507+
- include: regexp_shared
508+
- match: '(?:[?*+]|\{\d+(?:,(?:\d+)?)?\})[?+]?'
509+
scope: keyword.operator.quantifier.regexp.clojure
510+
511+
deep_regexp_group:
512+
- include: regexp_quote
513+
- include: deep_regexp_shared
514+
- match: '\|'
515+
scope: keyword.operator.union.regexp.clojure
516+
- match: '(\()(\?(<{{regexp_name}}>|:|=|!|<=|<!|>|[idmsux]*(-[idmsux]+)?:|[idmsuxU]*(-[idmsuxU]+)?(?!:)))?'
517+
captures:
518+
1: punctuation.section.parens.begin.clojure
519+
2: keyword.operator.special.regexp.clojure
520+
push:
521+
- match: '(?=")'
522+
pop: 1
523+
- match: '\)'
524+
scope: punctuation.section.parens.end.clojure
525+
pop: 1
526+
- include: deep_regexp_group
527+
- match: '[\)]'
528+
scope: invalid.illegal.stray-bracket-end
529+
530+
deep_regexp:
531+
- match: '{{wsb}}#"'
532+
scope: punctuation.definition.string.begin.clojure
533+
push:
534+
- meta_scope: string.regexp.clojure
535+
- include: deep_regexp_group
536+
537+
deep_constant:
538+
- match: '{{wsb}}(nil|true|false){{wse}}'
539+
scope: constant.language.clojure
540+
pop: 2
541+
542+
deep_keyword:
543+
- match: '{{wsb}}(::?)(?:{{keyword}}|({{keyword}})(/){{keyword}}){{wse}}'
544+
scope: constant.other.keyword.clojure
545+
captures:
546+
1: punctuation.definition.keyword.begin.clojure
547+
2: meta.namespace.keyword.clojure
548+
3: punctuation.definition.namespace.clojure
549+
pop: 2
550+
551+
deep_integer:
552+
- match: '{{wsb}}[+-]?(?:0x0|0x[1-9a-fA-F][0-9a-fA-F]*|0|[1-9][0-9]*)(N)?{{wse}}'
553+
scope: constant.numeric.integer.clojure
554+
captures:
555+
1: punctuation.definition.integer.precision.clojure
556+
pop: 2
557+
558+
deep_float:
559+
- match: '{{wsb}}[+-]?(?:0|[1-9][0-9]*)(?:(M)|\.[0-9]*(M)?|[eE][+-]?[0-9]+(M)?|\.[0-9]*[eE][+-]?[0-9]+(M)?){{wse}}'
560+
scope: constant.numeric.float.clojure
561+
captures:
562+
1: punctuation.definition.float.precision.clojure
563+
2: punctuation.definition.float.precision.clojure
564+
3: punctuation.definition.float.precision.clojure
565+
4: punctuation.definition.float.precision.clojure
566+
pop: 2
567+
- match: '{{wsb}}(##Inf|##-Inf|##NaN){{wse}}'
568+
scope: constant.numeric.float.clojure
569+
pop: 2
570+
571+
deep_ratio:
572+
- match: '{{wsb}}[+-]?(0|[1-9][0-9]*)/[1-9][0-9]*{{wse}}'
573+
scope: constant.numeric.ratio.clojure
574+
pop: 2
575+
576+
deep_symbol_def:
577+
- match: '{{wsb}}(?:(?=def){{symbol}}|({{ns_symbol}})(/)(?=def){{symbol}}){{wse}}'
578+
scope: source.symbol.def.clojure
579+
captures:
580+
1: meta.namespace.symbol.clojure
581+
2: punctuation.definition.namespace.clojure
582+
pop: 1
583+
push: deep_list_second
584+
585+
deep_symbol_name:
586+
- match: '{{wsb}}(?:{{symbol}}|({{ns_symbol}})(/){{symbol}}){{wse}}'
587+
scope: source.symbol.clojure entity.name.clojure
588+
captures:
589+
1: meta.namespace.symbol.clojure
590+
2: punctuation.definition.namespace.clojure
591+
pop: 1
592+
push: deep_list_rest
593+
594+
deep_symbol_unused:
595+
- match: '{{wsb}}(?:(?=_){{symbol}}|({{ns_symbol}})(/)(?=_){{symbol}}){{wse}}'
596+
scope: source.symbol.unused.clojure
597+
captures:
598+
1: meta.namespace.symbol.clojure
599+
2: punctuation.definition.namespace.clojure
600+
pop: 2
601+
602+
deep_symbol:
603+
- match: '{{wsb}}(?:{{symbol}}|({{ns_symbol}})(/){{symbol}}){{wse}}'
604+
scope: source.symbol.clojure
605+
captures:
606+
1: meta.namespace.symbol.clojure
607+
2: punctuation.definition.namespace.clojure
608+
pop: 2
609+
610+
deep_list:
611+
- match: '(?=\()'
612+
branch_point: deep_open_parens
613+
branch:
614+
- deep_list_paren
615+
- deep_form_comment_paren
616+
617+
deep_list_paren:
618+
- match: '\('
619+
scope: punctuation.section.parens.begin.clojure
620+
set: deep_list_first
621+
622+
deep_list_first:
623+
- meta_scope: meta.parens.clojure
624+
- match: \)
625+
scope: punctuation.section.parens.end.clojure
626+
pop: 3
627+
- include: skip_forms
628+
- match: 'comment'
629+
fail: deep_open_parens
630+
- include: deep_symbol_def
631+
- match: '(?=\S)'
632+
set: deep_list_rest
633+
634+
deep_list_second:
635+
- meta_scope: meta.parens.clojure
636+
- match: \)
637+
scope: punctuation.section.parens.end.clojure
638+
pop: 3
639+
- include: skip_forms
640+
- include: deep_symbol_name
641+
- match: '(?=\S)'
642+
set: deep_list_rest
643+
644+
deep_list_rest:
645+
- meta_scope: meta.parens.clojure
646+
- match: \)
647+
scope: punctuation.section.parens.end.clojure
648+
pop: 3
649+
- include: main
650+
651+
deep_form_comment_paren:
652+
- match: '\('
653+
scope: punctuation.section.parens.begin.clojure
654+
set: form_comment_first
655+
656+
deep_form_comment_first:
657+
- meta_scope: comment.form.clojure
658+
- include: skip_forms
659+
- match: 'comment'
660+
set: deep_form_comment_rest
661+
- match: \)
662+
fail: deep_open_parens
663+
- match: '(?=\S)'
664+
fail: deep_open_parens
665+
666+
deep_form_comment_rest:
667+
- meta_scope: comment.form.clojure
668+
- match: \)
669+
scope: punctuation.section.parens.end.clojure
670+
pop: 3
671+
- include: main
672+
673+
deep_anonymous_fn:
674+
- match: '(#)(\()'
675+
captures:
676+
1: punctuation.definition.anon_fn.clojure
677+
scope: punctuation.section.parens.begin.clojure
678+
push:
679+
- meta_scope: meta.parens.clojure meta.function.anon.clojure
680+
- match: \)
681+
scope: punctuation.section.parens.end.clojure
682+
pop: 3
683+
- include: main
684+
685+
deep_reader_conditional:
686+
- match: '(#\?@?)\s*\('
687+
captures:
688+
1: punctuation.definition.reader_conditional.clojure
689+
scope: punctuation.section.parens.begin.clojure
690+
push:
691+
- meta_scope: meta.parens.clojure meta.reader_conditional.clojure
692+
- match: '\)'
693+
scope: punctuation.section.parens.end.clojure
694+
pop: 3
695+
- include: main
696+
697+
deep_vector:
698+
- match: \[
699+
scope: punctuation.section.brackets.begin.clojure
700+
push:
701+
- meta_scope: meta.brackets.clojure
702+
- match: \]
703+
scope: punctuation.section.brackets.end.clojure
704+
pop: 3
705+
- include: main
706+
707+
deep_map:
708+
- match: '\{'
709+
scope: punctuation.section.braces.begin.clojure
710+
push:
711+
- meta_scope: meta.braces.clojure
712+
- match: \}
713+
scope: punctuation.section.braces.end.clojure
714+
pop: 3
715+
- include: main
716+
717+
deep_set:
718+
- match: '#\{'
719+
scope: punctuation.section.braces.begin.clojure
720+
push:
721+
- meta_scope: meta.braces.clojure
722+
- match: \}
723+
scope: punctuation.section.braces.end.clojure
724+
pop: 3
725+
- include: main
726+
727+
deep_tag:
728+
- 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}}'
729+
scope: constant.other.instant.clojure
730+
captures:
731+
2: invalid.illegal.instant.clojure
732+
pop: 2
733+
- match: '{{wsb}}(#uuid\s*"\h{8}-\h{4}-\h{4}-\h{4}-\h{12}"|(#uuid\s*"[^"]*")){{wse}}'
734+
scope: constant.other.uuid.clojure
735+
captures:
736+
2: invalid.illegal.uuid.clojure
737+
pop: 2
738+
- match: '{{wsb}}#(?![_#{])(?:{{symbol}}|{{ns_symbol}}(/){{symbol}}){{wse}}'
739+
scope: storage.type.tag.clojure
740+
pop: 2
459741

460742
# ERRORS
461743

test_syntax/syntax_test_clojure.cljc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -703,22 +703,10 @@ string"
703703
x y z
704704
; ^ meta.metadata
705705
; ^^^^ - meta.metadata
706-
^^x y z
707-
; ^^^ meta.metadata
708-
; ^^^^ - meta.metadata
709-
^^()()()
710-
; ^^^^ meta.metadata
711-
; ^^^^ - meta.metadata
712706
(((^x y)))
713707
; ^^^^^^ meta.parens meta.parens meta.parens
714708
; ^^ meta.metadata
715709
; ^^ - meta.metadata
716-
(((^^x y z)))
717-
; ^^^^^^^^^^^^^ meta.parens
718-
; ^^^^^^^^^^^ meta.parens meta.parens
719-
; ^^^^^^^^^ meta.parens meta.parens meta.parens
720-
; ^^^ meta.metadata
721-
; ^^^^^^^ - meta.metadata
722710

723711

724712
;;;;;;;;;; REGEXPS ;;;;;;;;;;

test_syntax/syntax_test_clojure_fails.clj

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
; SYNTAX TEST "Clojure (Sublimed).sublime-syntax"
22

3+
`~x
4+
; ^ meta.quoted.syntax
5+
; ^^ meta.quoted.syntax meta.unquoted
6+
7+
'~x
8+
; ^ invalid
9+
10+
'#'var
11+
; ^^^^^^ meta.quoted
12+
; ^^^^^ meta.var
13+
314
#' ,,, map
415
; ^^^^^^^^^^ meta.var
516
; ^^ punctuation.definition.var
@@ -11,6 +22,10 @@
1122

1223
@ , *atom
1324
; ^^^^^^^^^ meta.deref
25+
@@@*atom
26+
; ^^^^^^^^ meta.deref meta.deref meta.deref
27+
; ^^^^^^^ meta.deref meta.deref
28+
; ^^^^^^ meta.deref
1429

1530
#? ,,, ,, (:clj 1 :cljs 2)
1631
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.reader_conditional meta.parens
@@ -23,3 +38,18 @@
2338
#? #_clj (:clj 123)
2439
; ^^ meta.reader_conditional
2540
; ^^^^^^^^^^^^^^^^ - meta.reader_conditional
41+
42+
^^x y z
43+
; ^^^^^ meta.metadata
44+
; ^^ meta.metadata meta.metadata
45+
; ^^ - meta.metadata
46+
^^()()()
47+
; ^^^^^^ meta.metadata
48+
; ^^^ meta.metadata meta.metadata
49+
; ^^ - meta.metadata
50+
(((^^x y z)))
51+
; ^^^^^^^^^^^^^ meta.parens
52+
; ^^^^^^^^^^^ meta.parens meta.parens
53+
; ^^^^^^^^^ meta.parens meta.parens meta.parens
54+
; ^^^ meta.metadata
55+
; ^^^^^^^ - meta.metadata

0 commit comments

Comments
 (0)