diff --git a/core/modern/modern-tests.factor b/core/modern/modern-tests.factor index f5b61d8ecd..23bf0fc257 100644 --- a/core/modern/modern-tests.factor +++ b/core/modern/modern-tests.factor @@ -22,18 +22,21 @@ in: modern.tests { 2 } [ "{=={abc}==} {=={cba}==}" string>literals length ] unit-test { 2 } [ "(==(abc)==) (==(cba)==)" string>literals length ] unit-test -{ 1 } [ "hex`abc" string>literals length ] unit-test -{ 2 } [ "hex`abc hex`cba" string>literals length ] unit-test -{ 2 } [ "hex\"abc\" hex\"cba\"" string>literals length ] unit-test -{ 2 } [ "hex[[abc]] hex[[cba]]" string>literals length ] unit-test -{ 2 } [ "hex{{abc}} hex{{cba}}" string>literals length ] unit-test -{ 2 } [ "hex((abc)) hex((cba))" string>literals length ] unit-test -{ 2 } [ "hex[=[abc]=] hex[=[cba]=]" string>literals length ] unit-test -{ 2 } [ "hex{={abc}=} hex{={cba}=}" string>literals length ] unit-test -{ 2 } [ "hex(=(abc)=) hex(=(cba)=)" string>literals length ] unit-test -{ 2 } [ "hex[==[abc]==] hex[==[cba]==]" string>literals length ] unit-test -{ 2 } [ "hex{=={abc}==} hex{=={cba}==}" string>literals length ] unit-test -{ 2 } [ "hex(==(abc)==) hex(==(cba)==)" string>literals length ] unit-test +: literal-test ( string -- n string string string ) + string>literals [ length ] [ first [ tag>> ] [ delimiter>> ] [ payload>> ] tri ] bi ; + +{ 1 "hex" "`" "abc" } [ "hex`abc" literal-test ] unit-test +{ 2 "hex" "`" "abc" } [ "hex`abc hex`cba" literal-test ] unit-test +{ 2 "hex" "\"" "abc" } [ "hex\"abc\" hex\"cba\"" literal-test ] unit-test +{ 2 "hex" "[[" "abc" } [ "hex[[abc]] hex[[cba]]" literal-test ] unit-test +{ 2 "hex" "{{" "abc" } [ "hex{{abc}} hex{{cba}}" literal-test ] unit-test +{ 2 "hex" "((" "abc" } [ "hex((abc)) hex((cba))" literal-test ] unit-test +{ 2 "hex" "[=[" "abc" } [ "hex[=[abc]=] hex[=[cba]=]" literal-test ] unit-test +{ 2 "hex" "{={" "abc" } [ "hex{={abc}=} hex{={cba}=}" literal-test ] unit-test +{ 2 "hex" "(=(" "abc" } [ "hex(=(abc)=) hex(=(cba)=)" literal-test ] unit-test +{ 2 "hex" "[==[" "abc" } [ "hex[==[abc]==] hex[==[cba]==]" literal-test ] unit-test +{ 2 "hex" "{=={" "abc" } [ "hex{=={abc}==} hex{=={cba}==}" literal-test ] unit-test +{ 2 "hex" "(==(" "abc" } [ "hex(==(abc)==) hex(==(cba)==)" literal-test ] unit-test { 1 } [ "[ ]" string>literals length ] unit-test diff --git a/core/modern/modern.factor b/core/modern/modern.factor index 601089c37e..ebb22cc4aa 100644 --- a/core/modern/modern.factor +++ b/core/modern/modern.factor @@ -220,12 +220,12 @@ MACRO:: read-double-matched ( open-ch -- quot: ( lexer tag ch -- seq ) ) opening matching-delimiter-string :> needle lexer needle lex-til-string :> ( n'' string'' payload closing ) - payload closing tag opening double-matched-literal make-matched-literal + payload >string closing tag but-last-slice opening double-matched-literal make-matched-literal ] } { open-ch [ tag 1 cut-slice* swap tag! 1 modify-to :> opening lexer [ 1 + ] change-n closestr2 lex-til-string :> ( n' string' payload closing ) - payload closing tag opening double-matched-literal make-matched-literal + payload >string closing tag opening double-matched-literal make-matched-literal ] } [ [ tag openstr2 lexer ] dip long-opening-mismatch ] } case @@ -300,7 +300,7 @@ MACRO:: read-matched ( ch -- quot: ( lexer tag -- slice' ) ) lexer read-string-payload :> ( n' string slice ) ! n' string n' [ n string string-expected-got-eof ] unless - n n' 1 - string + n n' 1 - string >string n' 1 - n' string tag 1 cut-slice* dquote-literal make-matched-literal ;