]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/lint/vocabs/vocabs.factor
Account For Character Escapes
[factor.git] / extra / lint / vocabs / vocabs.factor
index 3063edb0908cabff42cf9b251955203b7e106704..031f5df81489bd5749c1b9b5e7a5c7792e9811e3 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2022 CapitalEx
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays assocs compiler.units continuations
-formatting hash-sets hashtables io io.encodings.utf8 io.files
+USING: accessors arrays assocs compiler.units formatting 
+hash-sets hashtables io io.encodings.utf8 io.files
 kernel namespaces regexp sequences sequences.deep sets sorting
 splitting unicode vocabs vocabs.loader ;
 FROM: namespaces => set ;
@@ -9,6 +9,11 @@ IN: lint.vocabs
 
 <PRIVATE
 SYMBOL: old-dictionary
+SYMBOL: LINT-VOCABS-REGEX
+
+! Cache regular expression to avoid compile time slowdowns
+"CHAR:\\s+\\S+\\s+|\"(\\\\\\\\|\\\\[\\\\stnrbvf0e\"]|\\\\x[a-fA-F0-9]{2}|\\\\u[a-fA-F0-9]{6}|[^\\\\\"])*\"|R/ (\\\\/|[^/])*/|\\\\\\s+(USE:|USING:)|POSTPONE:\\s+(USE:|USING:)|(?<!\\S+)! [^\n]*" <regexp>
+LINT-VOCABS-REGEX set-global
 
 : save-dictionary ( -- )
     dictionary     get clone 
@@ -34,8 +39,8 @@ SYMBOL: old-dictionary
 : find-import-statements ( string -- seq )
     "USING: [^;]+ ;|USE: \\S+" <regexp> all-matching-subseqs ;
 
-: clean-up-source ( string -- string )
-    "\"(\\\"|[^\"]*)\"|(R/ (\\\\/|[^/])*/)|\\\\\\s+\\S+|POSTPONE: \\S+|! ([^\n])*" <regexp> "" re-replace ;
+: clean-up-source ( string -- string ) 
+    LINT-VOCABS-REGEX get-global "" re-replace ;
 
 : strip-syntax ( seq -- seq )
     [ "USING: | ;|USE: " <regexp> " " re-replace ] map ;