]> gitweb.factorcode.org Git - factor.git/commitdiff
Fixed Regexp to Handle \" Properly
authorCapital-Ex <capitalex@protonmail.com>
Tue, 6 Sep 2022 03:40:27 +0000 (23:40 -0400)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 6 Sep 2022 15:41:04 +0000 (08:41 -0700)
extra/lint/vocabs/vocabs-tests.factor
extra/lint/vocabs/vocabs.factor

index b73c0167ca5c3d1dccf9a85f11f13acd2ca68e61..61e5ffa29fb8d44e5c56a00c6f138312d0eef5d9 100644 (file)
@@ -30,17 +30,18 @@ USE: math.complex
 
 USE: math.primes
 "
-CONSTANT: ignore-postpone-using  "POSTPONE: USING: : nop ( -- ) ;"
-CONSTANT: ingore-\-using         "\\ USING: : nop ( -- ) ;"
-CONSTANT: ignore-postpone-use    "POSTPONE: USE: ignore : nop ( -- ) ;"
-CONSTANT: ignore-\-use           "\\ USE: ignore : nop ( -- ) ;"
-CONSTANT: ignore-in-string-one   "\"USE:\" \"USING:\" : nop ( -- ) ;"
-CONSTANT: ignore-in-string-two   "\"asdfasdf USE:\" \"asdfasdf USING:\" : nop ( -- ) ;"
-CONSTANT: ignore-in-string-three "\"asdfasdf USE: asdfasdf\" : nop ( -- ) ;"
-CONSTANT: ignore-in-string-four  "\"asdfasdf USE: asdfasdf\" \"asdfasff USING: asdfasdf\" : nop ( -- ) ;"
-CONSTANT: ignore-use-regex       "R/ USE: ignore/ : nop ( -- ) ;"
-CONSTANT: ignore-using-regex     "R/ USING: ignore ;/ : nop ( -- ) ;"
-CONSTANT: empty-using-statement  "USING: ; nop ( -- ) ;"
+CONSTANT: ignore-postpone-using     "POSTPONE: USING: : nop ( -- ) ;"
+CONSTANT: ingore-\-using            "\\ USING: : nop ( -- ) ;"
+CONSTANT: ignore-postpone-use       "POSTPONE: USE: ignore : nop ( -- ) ;"
+CONSTANT: ignore-\-use              "\\ USE: ignore : nop ( -- ) ;"
+CONSTANT: ignore-in-string-one      "\"USE:\" \"USING:\" : nop ( -- ) ;"
+CONSTANT: ignore-in-string-two      "\"asdfasdf USE:\" \"asdfasdf USING:\" : nop ( -- ) ;"
+CONSTANT: ignore-in-string-three    "\"asdfasdf USE: asdfasdf\" : nop ( -- ) ;"
+CONSTANT: ignore-in-string-four     "\"asdfasdf USE: asdfasdf\" \"asdfasff USING: asdfasdf\" : nop ( -- ) ;"
+CONSTANT: ignore-string-with-quote  "\"\\\"USE:\" : nop ( -- ) ;"
+CONSTANT: ignore-use-regex          "R/ USE: ignore/ : nop ( -- ) ;"
+CONSTANT: ignore-using-regex        "R/ USING: ignore ;/ : nop ( -- ) ;"
+CONSTANT: empty-using-statement     "USING: ; nop ( -- ) ;"
 : ---- ( -- ) "-------------------------------------------------------------------------" print ;
 PRIVATE>
 
@@ -59,20 +60,21 @@ PRIVATE>
 ----
 
 "It should ignore USE: and USING: that are in strings: " print
-{ { } } [ ignore-in-string-one find-unused-in-string ] unit-test
-{ { } } [ ignore-in-string-two find-unused-in-string ] unit-test
-{ { } } [ ignore-in-string-three find-unused-in-string ] unit-test
-{ { } } [ ignore-in-string-four find-unused-in-string ] unit-test
+{ { } } [ ignore-in-string-one     find-unused-in-string ] unit-test
+{ { } } [ ignore-in-string-two     find-unused-in-string ] unit-test
+{ { } } [ ignore-in-string-three   find-unused-in-string ] unit-test
+{ { } } [ ignore-in-string-four    find-unused-in-string ] unit-test
+{ { } } [ ignore-string-with-quote find-unused-in-string ] unit-test
 
 ----
 
 "It should ignore USE: and USING: that are in RegEx: " print
-{ { } } [ ignore-use-regex find-unused-in-string ] unit-test
+{ { } } [ ignore-use-regex   find-unused-in-string ] unit-test
 { { } } [ ignore-using-regex find-unused-in-string ] unit-test
 
 ----
 
-"IT should return empty when no imports have been found: " print
+"It should return empty when no imports have been found: " print
 { { } } [ empty-using-statement find-unused-in-string ] unit-test
 
 ----
@@ -83,4 +85,4 @@ dictionary get clone 1array [
     dictionary get clone 
 ] unit-test
 
-----
\ No newline at end of file
+----
index 358a353dd9bf9f57cbd091a83fca230dba7a2a44..c701a05145b70ec9b3db9029dd6628d4f1898f39 100644 (file)
@@ -34,8 +34,8 @@ SYMBOL: old-dictionary
 : find-import-statements ( string -- seq )
     "USING: [^;]+ ;|USE: \\S+" <regexp> all-matching-subseqs ;
 
-: clean-up-source ( string -- string )
-    "\"(\\\"|[^\"]*|\n)\"|(R/ (\\\\/|[^/])*/)|\\\\\\s+(USE:|USING:)|POSTPONE:\\s+(USE:|USING:)|! ([^\n])*" <regexp> "" re-replace ;
+: clean-up-source ( string -- string ) 
+    "\"(\\\\\"|[^\"])*\"|(R/ (\\\\/|[^/])*/)|\\\\\\s+(USE:|USING:)|POSTPONE:\\s+(USE:|USING:)|! [^\n]*" <regexp> "" re-replace ;
 
 : strip-syntax ( seq -- seq )
     [ "USING: | ;|USE: " <regexp> " " re-replace ] map ;