From 262a75ce6a33533aedb470c36226c25b5e35a58c Mon Sep 17 00:00:00 2001 From: guns Date: Wed, 8 Feb 2017 18:47:14 -0600 Subject: [PATCH 01/10] Merge nine clojureCharacter patterns into one --- clj/test/vim_clojure_static/syntax_test.clj | 22 +++++++++++++++++++++ syntax/clojure.vim | 10 +--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/clj/test/vim_clojure_static/syntax_test.clj b/clj/test/vim_clojure_static/syntax_test.clj index ebc4e9e..2d9a23c 100644 --- a/clj/test/vim_clojure_static/syntax_test.clj +++ b/clj/test/vim_clojure_static/syntax_test.clj @@ -6,6 +6,7 @@ (defpredicates number :clojureNumber) (defpredicates kw :clojureKeyword) +(defpredicates character :clojureCharacter) (defpredicates regexp :clojureRegexp) (defpredicates regexp-escape :clojureRegexpEscape) (defpredicates regexp-char-class :clojureRegexpCharClass) @@ -81,6 +82,27 @@ (comment (test #'test-number-literals)) +(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)) + ;; TODO: Finish me! (this was in an old git stash) ;; (defsyntaxtest keywords-test ;; (with-format "%s" diff --git a/syntax/clojure.vim b/syntax/clojure.vim index defd977..fb1c834 100644 --- a/syntax/clojure.vim +++ b/syntax/clojure.vim @@ -76,15 +76,7 @@ syntax match clojureStringEscape "\v\\%([\\btnfr"]|u\x{4}|[0-3]\o{2}|\o{1,2})" c 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]))*[#:]@ Date: Wed, 8 Feb 2017 19:26:31 -0600 Subject: [PATCH 02/10] Remove correct radix literal matching for better performance Halves syntime benchmark: TOTAL COUNT BEFORE: 0.116939 49694 AFTER: 0.052234 27016 --- clj/test/vim_clojure_static/syntax_test.clj | 5 +++-- syntax/clojure.vim | 8 ++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/clj/test/vim_clojure_static/syntax_test.clj b/clj/test/vim_clojure_static/syntax_test.clj index 2d9a23c..09f7c60 100644 --- a/clj/test/vim_clojure_static/syntax_test.clj +++ b/clj/test/vim_clojure_static/syntax_test.clj @@ -35,6 +35,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 @@ -47,7 +48,7 @@ "1.0/1" !number "01/2" !number "1/02" !number - "2r2" !number + ; "2r2" !number ;; Removed for performance "1r0" !number "37r36" !number @@ -68,7 +69,7 @@ "08.9M" !number "0x1fM" !number "3/4M" !number - "2r1M" !number + ; "2r1M" !number ;; Removed for performance ;; Exponential notation diff --git a/syntax/clojure.vim b/syntax/clojure.vim index fb1c834..82cd549 100644 --- a/syntax/clojure.vim +++ b/syntax/clojure.vim @@ -80,12 +80,8 @@ syntax match clojureCharacter "\v\\%(.$|o%([0-3]\o{2}|\o{1,2})|u\x{4}|newline|ta syntax match clojureSymbol "\v%([a-zA-Z!$&*_+=|<.>?-]|[^\x00-\x7F])+%(:?%([a-zA-Z0-9!#$%&*_+=|'<.>/?-]|[^\x00-\x7F]))*[#:]@"' -endfor -unlet! s:radix_chars s:radix - +" NB. Correct matching of radix literals was removed for better performance. +syntax match clojureNumber "\v<[-+]?%([2-9]|[12]\d|3[0-6])[rR][[:alnum:]]+>" 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*)>" From 4d05e766b3525968f4b6d3aec0cece687b194a13 Mon Sep 17 00:00:00 2001 From: guns Date: Wed, 8 Feb 2017 21:28:19 -0600 Subject: [PATCH 03/10] Add %, &, and | to iskeyword These are valid symbol characters. --- ftplugin/clojure.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/clojure.vim b/ftplugin/clojure.vim index bbfc65b..0669e74 100644 --- a/ftplugin/clojure.vim +++ b/ftplugin/clojure.vim @@ -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. From bb34f72777c8acaf7d5fb9562ac8ad2412a9f1eb Mon Sep 17 00:00:00 2001 From: guns Date: Thu, 9 Feb 2017 14:24:12 -0600 Subject: [PATCH 04/10] Fix error in clojureRegexpBackRef match --- syntax/clojure.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/clojure.vim b/syntax/clojure.vim index 82cd549..117251f 100644 --- a/syntax/clojure.vim +++ b/syntax/clojure.vim @@ -124,14 +124,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 From 3b5db3feddb20cef15e6ea4de00f62ffaddb1471 Mon Sep 17 00:00:00 2001 From: guns Date: Thu, 9 Feb 2017 19:45:54 -0600 Subject: [PATCH 05/10] Use a limit in the negative lookbehind clojureSymbol pattern $ syntime clj/src/vim_clojure_static/generate.clj Before: TOTAL COUNT MATCH SLOWEST AVERAGE NAME PATTERN 0.031679 2003 1906 0.000092 0.000016 clojureSymbol \v%([a-zA-Z!$&*_+=|<.>?-]|[^\x00-\x7F])+%(:?%([a-zA-Z0-9!#$%&*_+=|'<.>/?-]|[^\x00-\x7F]))*[#:]@?-]|[^\x00-\x7F])+%(:?%([a-zA-Z0-9!#$%&*_+=|'<.>/?-]|[^\x00-\x7F]))*[#:]@1?-]|[^\x00-\x7F])+%(:?%([a-zA-Z0-9!#$%&*_+=|'<.>/?-]|[^\x00-\x7F]))*[#:]@?-]|[^\x00-\x7F])+%(:?%([a-zA-Z0-9!#$%&*_+=|'<.>/?-]|[^\x00-\x7F]))*[#:]@1?-]|[^\x00-\x7F])+%(:?%([a-zA-Z0-9!#$%&*_+=|'<.>/?-]|[^\x00-\x7F]))*[#:]@?-]|[^\x00-\x7F])+%(:?%([a-zA-Z0-9!#$%&*_+=|'<.>/?-]|[^\x00-\x7F]))*[#:]@1" From 4d155ebe5a40d4ba06e694dd6675e06f652718dd Mon Sep 17 00:00:00 2001 From: guns Date: Thu, 9 Feb 2017 20:13:16 -0600 Subject: [PATCH 06/10] Fix file creation problem in defsyntaxtest --- clj/src/vim_clojure_static/test.clj | 1 + 1 file changed, 1 insertion(+) diff --git a/clj/src/vim_clojure_static/test.clj b/clj/src/vim_clojure_static/test.clj index 4f86ca1..dcbb7ab 100644 --- a/clj/src/vim_clojure_static/test.clj +++ b/clj/src/vim_clojure_static/test.clj @@ -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]}] From 4ed031c038712cb70c6d9f11ccad438000854623 Mon Sep 17 00:00:00 2001 From: guns Date: Sat, 11 Feb 2017 20:00:39 -0600 Subject: [PATCH 07/10] Limit negative lookbehind in clojureKeyword --- clj/test/vim_clojure_static/syntax_test.clj | 40 ++++++++++----------- syntax/clojure.vim | 2 +- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/clj/test/vim_clojure_static/syntax_test.clj b/clj/test/vim_clojure_static/syntax_test.clj index 09f7c60..16f97c8 100644 --- a/clj/test/vim_clojure_static/syntax_test.clj +++ b/clj/test/vim_clojure_static/syntax_test.clj @@ -104,27 +104,25 @@ (comment (test #'test-character-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 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\"" diff --git a/syntax/clojure.vim b/syntax/clojure.vim index 26e1c20..eff2472 100644 --- a/syntax/clojure.vim +++ b/syntax/clojure.vim @@ -70,7 +70,7 @@ 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 From 78ef0231dbd33f5aa8253af0947a7625ae156330 Mon Sep 17 00:00:00 2001 From: guns Date: Sat, 11 Feb 2017 20:29:16 -0600 Subject: [PATCH 08/10] Merge four clojureNumber patterns into one Reduces number syntax matching time by 65% --- syntax/clojure.vim | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/syntax/clojure.vim b/syntax/clojure.vim index eff2472..8a4e634 100644 --- a/syntax/clojure.vim +++ b/syntax/clojure.vim @@ -81,10 +81,7 @@ syntax match clojureCharacter "\v\\%(.$|o%([0-3]\o{2}|\o{1,2})|u\x{4}|newline|ta syntax match clojureSymbol "\v%([a-zA-Z!$&*_+=|<.>?-]|[^\x00-\x7F])+%(:?%([a-zA-Z0-9!#$%&*_+=|'<.>/?-]|[^\x00-\x7F]))*[#:]@1" -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*)>" +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 "&" From 58244561a35c5ad7d54b906c329c8799e556fd38 Mon Sep 17 00:00:00 2001 From: guns Date: Sat, 11 Feb 2017 20:37:27 -0600 Subject: [PATCH 09/10] Merge more syntax matches --- syntax/clojure.vim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/syntax/clojure.vim b/syntax/clojure.vim index 8a4e634..8a5bb00 100644 --- a/syntax/clojure.vim +++ b/syntax/clojure.vim @@ -85,10 +85,8 @@ syntax match clojureNumber "\v<[-+]?%(%([2-9]|[12]\d|3[0-6])[rR][[:alnum:]]+|%(0 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#[\^'=<_]?" From d46626d447059f300da00ceb2442982a845ff588 Mon Sep 17 00:00:00 2001 From: guns Date: Sat, 11 Feb 2017 23:43:34 -0600 Subject: [PATCH 10/10] Fix regression in clojureCharacter match --- clj/test/vim_clojure_static/syntax_test.clj | 2 +- syntax/clojure.vim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clj/test/vim_clojure_static/syntax_test.clj b/clj/test/vim_clojure_static/syntax_test.clj index 16f97c8..adaa477 100644 --- a/clj/test/vim_clojure_static/syntax_test.clj +++ b/clj/test/vim_clojure_static/syntax_test.clj @@ -84,7 +84,7 @@ (comment (test #'test-number-literals)) (defsyntaxtest test-character-literals - ["%s" + ["[%s]" ["\\0" character "\\a" character "\\Z" character "\\." character "\\\\" character "\\❤" character "\\o7" character "\\o07" character "\\o307" character diff --git a/syntax/clojure.vim b/syntax/clojure.vim index 8a5bb00..e94cb27 100644 --- a/syntax/clojure.vim +++ b/syntax/clojure.vim @@ -76,7 +76,7 @@ syntax match clojureStringEscape "\v\\%([\\btnfr"]|u\x{4}|[0-3]\o{2}|\o{1,2})" c syntax region clojureString matchgroup=clojureStringDelimiter start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=clojureStringEscape,@Spell -syntax match clojureCharacter "\v\\%(.$|o%([0-3]\o{2}|\o{1,2})|u\x{4}|newline|tab|space|return|backspace|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]))*[#:]@1