From c0a790904791be6f356a0a5737fad17e8aeaeb6f Mon Sep 17 00:00:00 2001 From: Capital-Ex Date: Mon, 5 Sep 2022 23:40:27 -0400 Subject: [PATCH] Fixed Regexp to Handle \" Properly --- extra/lint/vocabs/vocabs-tests.factor | 38 ++++++++++++++------------- extra/lint/vocabs/vocabs.factor | 4 +-- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/extra/lint/vocabs/vocabs-tests.factor b/extra/lint/vocabs/vocabs-tests.factor index b73c0167ca..61e5ffa29f 100644 --- a/extra/lint/vocabs/vocabs-tests.factor +++ b/extra/lint/vocabs/vocabs-tests.factor @@ -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 +---- diff --git a/extra/lint/vocabs/vocabs.factor b/extra/lint/vocabs/vocabs.factor index 358a353dd9..c701a05145 100644 --- a/extra/lint/vocabs/vocabs.factor +++ b/extra/lint/vocabs/vocabs.factor @@ -34,8 +34,8 @@ SYMBOL: old-dictionary : find-import-statements ( string -- seq ) "USING: [^;]+ ;|USE: \\S+" all-matching-subseqs ; -: clean-up-source ( string -- string ) - "\"(\\\"|[^\"]*|\n)\"|(R/ (\\\\/|[^/])*/)|\\\\\\s+(USE:|USING:)|POSTPONE:\\s+(USE:|USING:)|! ([^\n])*" "" re-replace ; +: clean-up-source ( string -- string ) + "\"(\\\\\"|[^\"])*\"|(R/ (\\\\/|[^/])*/)|\\\\\\s+(USE:|USING:)|POSTPONE:\\s+(USE:|USING:)|! [^\n]*" "" re-replace ; : strip-syntax ( seq -- seq ) [ "USING: | ;|USE: " " " re-replace ] map ; -- 2.34.1