Account For Character Escapes
authorCapital-Ex <capitalex@protonmail.com>
Tue, 6 Sep 2022 15:09:26 +0000 (11:09 -0400)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 6 Sep 2022 15:41:04 +0000 (08:41 -0700)
Additionally, precompute and store the regexp to avoid slowdowns from added complexity of expression.

extra/lint/vocabs/vocabs.factor

index 8b692cc1c05b2586314238605aa7dd0b96340618..031f5df81489bd5749c1b9b5e7a5c7792e9811e3 100644 (file)
@@ -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 
@@ -35,7 +40,7 @@ SYMBOL: old-dictionary
     "USING: [^;]+ ;|USE: \\S+" <regexp> all-matching-subseqs ;
 
 : clean-up-source ( string -- string ) 
-    "\"(\\\\\"|[^\"])*\"|R/ (\\\\/|[^/])*/|\\\\\\s+(USE:|USING:)|POSTPONE:\\s+(USE:|USING:)|! [^\n]*|CHAR:\\s+\\S+\\s+" <regexp> "" re-replace ;
+    LINT-VOCABS-REGEX get-global "" re-replace ;
 
 : strip-syntax ( seq -- seq )
     [ "USING: | ;|USE: " <regexp> " " re-replace ] map ;