Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf #5

Merged
merged 11 commits into from
Feb 24, 2021
1 change: 1 addition & 0 deletions clj/src/vim_clojure_static/test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
test-file (str "tmp/" name ".clj")
syntable (gensym "syntable")]
`(test/deftest ~name
(~io/make-parents ~test-file)
(spit ~test-file "")
(let [~syntable (syn-id-names ~test-file ~@strings)]
~@(map (fn [{:keys [fmt ss λs]}]
Expand Down
67 changes: 44 additions & 23 deletions clj/test/vim_clojure_static/syntax_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

(defpredicates number :clojureNumber)
(defpredicates kw :clojureKeyword)
(defpredicates character :clojureCharacter)
(defpredicates regexp :clojureRegexp)
(defpredicates regexp-escape :clojureRegexpEscape)
(defpredicates regexp-char-class :clojureRegexpCharClass)
Expand Down Expand Up @@ -37,6 +38,7 @@
"0x0" number "+0x0" number "-0x0" number ; Hexadecimal zero
"3/2" number "+3/2" number "-3/2" number ; Rational
"0/0" number "+0/0" number "-0/0" number ; Rational (not a syntax error)
"36r0XYZ" number "16rFF" number "8r077" number ; Radix
"2r1" number "+2r1" number "-2r1" number ; Radix
"36R1" number "+36R1" number "-36R1" number ; Radix

Expand All @@ -49,7 +51,7 @@
"1.0/1" !number
"01/2" !number
"1/02" !number
"2r2" !number
; "2r2" !number ;; Removed for performance
"1r0" !number
"37r36" !number

Expand All @@ -70,7 +72,7 @@
"08.9M" !number
"0x1fM" !number
"3/4M" !number
"2r1M" !number
; "2r1M" !number ;; Removed for performance

;; Exponential notation

Expand All @@ -84,27 +86,46 @@

(comment (test #'test-number-literals))

;; TODO: Finish me! (this was in an old git stash)
;; (defsyntaxtest keywords-test
;; (with-format "%s"
;; ":1" kw
;; ":A" kw
;; ":a" kw
;; ":αβγ" kw
;; "::a" kw
;; ":a/b" kw
;; ":a:b" kw
;; ":a:b/:c:b" kw
;; ":a/b/c/d" kw
;; "::a/b" !kw
;; "::" !kw
;; ":a:" !kw
;; ":a/" !kw
;; ":/" !kw
;; ":" !kw
;; ))
;;
;; (comment (test #'keywords-test))
(defsyntaxtest test-character-literals
["[%s]"
["\\0" character "\\a" character "\\Z" character
"\\." character "\\\\" character "\\❤" character
"\\o7" character "\\o07" character "\\o307" character
"\\o8" !character "\\o477" !character "\\o0007" !character

"\\u09af" character

"\\u0" !character "\\u01" !character "\\u012" !character
"\\u01234" !character "\\u0123g" !character

"\\newline" character "\\new" !character
"\\tab" character "\\ta" !character
"\\space" character "\\sp" !character
"\\return" character "\\ret" !character
"\\backspace" character "\\bs" !character
"\\formfeed" character "\\ff" !character]])

(comment (test #'test-character-literals))

(defsyntaxtest keywords-test
["%s"
[":1" kw
":A" kw
":a" kw
":αβγ" kw
"::a" kw
":a/b" kw
":a:b" kw
":a:b/:c:b" kw
":a/b/c/d" kw
"::a/b" kw
"::" !kw
":a:" !kw
":a/" !kw
; ":/" !kw ; This is legal, but for simplicity we do not match it
":" !kw]])

(comment (test #'keywords-test))

(defsyntaxtest test-java-regexp-literals
["#\"%s\""
Expand Down
2 changes: 1 addition & 1 deletion ftplugin/clojure.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set cpo&vim

let b:undo_ftplugin = 'setlocal iskeyword< define< formatoptions< comments< commentstring< lispwords<'

setlocal iskeyword+=?,-,*,!,+,/,=,<,>,.,:,$
setlocal iskeyword+=?,-,*,!,+,/,=,<,>,.,:,$,%,&,\|

" There will be false positives, but this is better than missing the whole set
" of user-defined def* definitions.
Expand Down
35 changes: 9 additions & 26 deletions syntax/clojure.vim
Original file line number Diff line number Diff line change
Expand Up @@ -68,40 +68,23 @@ delfunction s:syntax_keyword
" * Must not end in a : or /
" * Must not have two adjacent colons except at the beginning
" * Must not contain any reader metacharacters except for ' and #
syntax match clojureKeyword "\v<:{1,2}%([^ \n\r\t()\[\]{}";@^`~\\%/]+/)*[^ \n\r\t()\[\]{}";@^`~\\%/]+:@<!>"
syntax match clojureKeyword "\v<:{1,2}%([^ \n\r\t()\[\]{}";@^`~\\%/]+/)*[^ \n\r\t()\[\]{}";@^`~\\%/]+:@1<!>"

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

syntax region clojureString matchgroup=clojureStringDelimiter start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=clojureStringEscape,@Spell

syntax match clojureCharacter "\\."
syntax match clojureCharacter "\\o\%([0-3]\o\{2\}\|\o\{1,2\}\)"
syntax match clojureCharacter "\\u\x\{4\}"
syntax match clojureCharacter "\\space"
syntax match clojureCharacter "\\tab"
syntax match clojureCharacter "\\newline"
syntax match clojureCharacter "\\return"
syntax match clojureCharacter "\\backspace"
syntax match clojureCharacter "\\formfeed"
syntax match clojureCharacter "\v\\%(o%([0-3]\o{2}|\o{1,2})|u\x{4}|newline|tab|space|return|backspace|formfeed|.)"

syntax match clojureSymbol "\v%([a-zA-Z!$&*_+=|<.>?-]|[^\x00-\x7F])+%(:?%([a-zA-Z0-9!#$%&*_+=|'<.>/?-]|[^\x00-\x7F]))*[#:]@<!"
syntax match clojureSymbol "\v%([a-zA-Z!$&*_+=|<.>?-]|[^\x00-\x7F])+%(:?%([a-zA-Z0-9!#$%&*_+=|'<.>/?-]|[^\x00-\x7F]))*[#:]@1<!"

let s:radix_chars = "0123456789abcdefghijklmnopqrstuvwxyz"
for s:radix in range(2, 36)
execute 'syntax match clojureNumber "\v\c<[-+]?' . s:radix . 'r[' . strpart(s:radix_chars, 0, s:radix) . ']+>"'
endfor
unlet! s:radix_chars s:radix

syntax match clojureNumber "\v<[-+]?%(0\o*|0x\x+|[1-9]\d*)N?>"
syntax match clojureNumber "\v<[-+]?%(0|[1-9]\d*|%(0|[1-9]\d*)\.\d*)%(M|[eE][-+]?\d+)?>"
syntax match clojureNumber "\v<[-+]?%(0|[1-9]\d*)/%(0|[1-9]\d*)>"
" NB. Correct matching of radix literals was removed for better performance.
syntax match clojureNumber "\v<[-+]?%(%([2-9]|[12]\d|3[0-6])[rR][[:alnum:]]+|%(0\o*|0x\x+|[1-9]\d*)N?|%(0|[1-9]\d*|%(0|[1-9]\d*)\.\d*)%(M|[eE][-+]?\d+)?|%(0|[1-9]\d*)/%(0|[1-9]\d*))>"

syntax match clojureVarArg "&"

syntax match clojureQuote "'"
syntax match clojureQuote "`"
syntax match clojureUnquote "\~"
syntax match clojureUnquote "\~@"
syntax match clojureQuote "\v['`]"
syntax match clojureUnquote "\v\~\@?"
syntax match clojureMeta "\^"
syntax match clojureDeref "@"
syntax match clojureDispatch "\v#[\^'=<_]?"
Expand Down Expand Up @@ -134,14 +117,14 @@ syntax match clojureRegexpBoundary "[$^]" contained display
syntax match clojureRegexpQuantifier "[?*+][?+]\=" contained display
syntax match clojureRegexpQuantifier "\v\{\d+%(,|,\d+)?}\??" contained display
syntax match clojureRegexpOr "|" contained display
syntax match clojureRegexpBackRef "\v\\%([1-9]\d*|k\<[a-zA-z]+\>)" contained display
syntax match clojureRegexpBackRef "\v\\%([1-9]\d*|k\<[[:alpha:]]+\>)" contained display

" Mode modifiers, mode-modified spans, lookaround, regular and atomic
" grouping, and named-capturing.
syntax match clojureRegexpMod "\v\(@<=\?:" contained display
syntax match clojureRegexpMod "\v\(@<=\?[xdsmiuU]*-?[xdsmiuU]+:?" contained display
syntax match clojureRegexpMod "\v\(@<=\?%(\<?[=!]|\>)" contained display
syntax match clojureRegexpMod "\v\(@<=\?\<[a-zA-Z]+\>" contained display
syntax match clojureRegexpMod "\v\(@<=\?\<[[:alpha:]]+\>" contained display

syntax region clojureRegexpGroup start="(" skip=/\\\\\|\\)/ end=")" matchgroup=clojureRegexpGroup contained contains=clojureRegexpMod,clojureRegexpQuantifier,clojureRegexpBoundary,clojureRegexpEscape,@clojureRegexpCharClasses
syntax region clojureRegexp start=/\#"/ skip=/\\\\\|\\"/ end=/"/ contains=@clojureRegexpCharClasses,clojureRegexpEscape,clojureRegexpQuote,clojureRegexpBoundary,clojureRegexpQuantifier,clojureRegexpOr,clojureRegexpBackRef,clojureRegexpGroup keepend
Expand Down