Skip to content

Commit fe0c172

Browse files
committed
Allow "#\Q…\E" regions without matching \E
In order to match only the delimiters a subregion is matched within \Q…\E offset by the length of the delimiters. This subregion is linked to the normal regexp group to signal that interpretation of the tokens within the region is supressed. cf. #19
1 parent 91c54cd commit fe0c172

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

clj/test/syntax_test.clj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
(def !regexp-quantifier (complement regexp-quantifier))
2323
(def regexp-back-ref (all-fn :clojureRegexpBackRef))
2424
(def !regexp-back-ref (complement regexp-back-ref))
25-
(def regexp-quote (all-fn :clojureRegexpQuote))
26-
(def !regexp-quote (complement regexp-quote))
2725
(def regexp-or (all-fn :clojureRegexpOr))
2826
(def !regexp-or (complement regexp-or))
2927
(def regexp-group (all-fn :clojureRegexpGroup))
@@ -341,8 +339,9 @@
341339

342340
;; \Q Nothing, but quotes all characters until \E
343341
;; \E Nothing, but ends quoting started by \Q
344-
"\\Qabc\\E" regexp-quote
345-
"\\qabc\\E" !regexp-quote
342+
"\\Qa\\E" (partial = [:clojureRegexpQuote :clojureRegexpQuote :clojureRegexpQuoted :clojureRegexpQuote :clojureRegexpQuote])
343+
"\\Qa\\\"" (partial = [:clojureRegexpQuote :clojureRegexpQuote :clojureRegexpQuoted :clojureRegexpQuoted :clojureRegexpQuoted])
344+
"\\qa\\E" (partial not-any? #{:clojureRegexpQuote :clojureRegexpQuoted})
346345

347346
;;;; Special constructs (named-capturing and non-capturing)
348347
;; (?<name>X) X, as a named-capturing group

syntax/clojure.vim

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ syntax match clojureKeyword "\v<:{1,2}%([^ \n\r\t()\[\]{}";@^`~\\%/]+/)*[^ \n\r\
3838

3939
syntax match clojureStringEscape "\v\\%([\\btnfr"]|u\x{4}|[0-3]\o{2}|\o{1,2})" contained
4040

41-
syntax region clojureString start=/"/ skip=/\\"/ end=/"/ contains=clojureStringEscape
41+
syntax region clojureString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=clojureStringEscape
4242

4343
syntax match clojureCharacter "\\."
4444
syntax match clojureCharacter "\\o\%([0-3]\o\{2\}\|\o\{1,2\}\)"
@@ -79,8 +79,8 @@ syntax match clojureAnonArg "%\(20\|1\d\|[1-9]\|&\)\?"
7979
" characters ".", "+", "*", "?", "{", "}", "[", "]", "(", and ")" with a "\"
8080
" forms a legal escape sequence.
8181
syntax match clojureRegexpEscape "\v\\%(\\|[tnrfae]|c[A-Z]|0[0-3]?[0-7]{1,2}|x\x{2}|u\x{4}|[.+*?{}[\]()])" contained
82-
syntax region clojureRegexpQuote start="\v\<@!\\Q" end="\\E"
83-
syntax cluster clojureRegexpEscapes contains=clojureRegexpEscape,clojureRegexpQuote
82+
syntax region clojureRegexpQuoted start=/\v\<@!\\Q/ms=e+1 skip=/\v\\\\|\\"/ end=/\\E/me=s-1 end=/"/me=s-1 contained
83+
syntax region clojureRegexpQuote start=/\v\<@!\\Q/ skip=/\v\\\\|\\"/ end=/\\E/ end=/"/me=s-1 contains=clojureRegexpQuoted keepend contained
8484
" Charactar classes
8585
syntax match clojureRegexpPredefinedCharClass "\v%(\\[dDsSwW]|\.)" contained
8686
" XXX: Should we distinguish between posix, java, and unicode character
@@ -104,8 +104,8 @@ syntax match clojureRegexpMod "\v\(@<=\?[xdsmiuU]*-?[xdsmiuU]+:?" contained
104104
syntax match clojureRegexpMod "\v\(@<=\?%(\<?[=!]|\>)" contained
105105
syntax match clojureRegexpMod "\v\(@<=\?\<[a-zA-Z]+\>" contained
106106

107-
syntax region clojureRegexpGroup start="\\\@<!(" matchgroup=clojureRegexpGroup end="\\\@<!)" contained contains=clojureRegexpMod,clojureRegexpQuantifier,clojureRegexpBoundary,@clojureRegexpEscapes,@clojureRegexpCharClasses
108-
syntax region clojureRegexp start=/\#"/ skip=/\\"/ end=/"/ contains=@clojureRegexpEscapes,@clojureRegexpCharClasses,clojureRegexpBoundary,clojureRegexpQuantifier,clojureRegexpOr,clojureRegexpBackRef,clojureRegexpGroup
107+
syntax region clojureRegexpGroup start="\\\@<!(" matchgroup=clojureRegexpGroup end="\\\@<!)" contained contains=clojureRegexpMod,clojureRegexpQuantifier,clojureRegexpBoundary,clojureRegexpEscape,@clojureRegexpCharClasses
108+
syntax region clojureRegexp start=/\#"/ skip=/\\\\\|\\"/ end=/"/ contains=@clojureRegexpCharClasses,clojureRegexpEscape,clojureRegexpQuote,clojureRegexpBoundary,clojureRegexpQuantifier,clojureRegexpOr,clojureRegexpBackRef,clojureRegexpGroup keepend
109109

110110
syntax match clojureComment ";.*$" contains=clojureTodo,@Spell
111111
syntax match clojureComment "#!.*$"
@@ -131,7 +131,6 @@ highlight default link clojureStringEscape Character
131131

132132
highlight default link clojureRegexp Constant
133133
highlight default link clojureRegexpEscape Character
134-
highlight default link clojureRegexpQuote Character
135134
highlight default link clojureRegexpCharClass SpecialChar
136135
highlight default link clojureRegexpPosixCharClass SpecialChar
137136
highlight default link clojureRegexpPredefinedCharClass SpecialChar
@@ -141,6 +140,8 @@ highlight default link clojureRegexpMod SpecialChar
141140
highlight default link clojureRegexpOr SpecialChar
142141
highlight default link clojureRegexpBackRef SpecialChar
143142
highlight default link clojureRegexpGroup clojureRegexp
143+
highlight default link clojureRegexpQuoted clojureRegexp
144+
highlight default link clojureRegexpQuote clojureRegexpEscape
144145

145146
highlight default link clojureVariable Identifier
146147
highlight default link clojureCond Conditional

0 commit comments

Comments
 (0)