diff --git a/extra/modern/modern-tests.factor b/extra/modern/modern-tests.factor index 210da685b8..981321b450 100644 --- a/extra/modern/modern-tests.factor +++ b/extra/modern/modern-tests.factor @@ -62,7 +62,7 @@ IN: modern.tests { { "SYNTAX:" { "\\AVL{" } } } } [ "SYNTAX: \\AVL{" string>literals >strings ] unit-test -{ { "\\" } } [ "\\" string>literals >strings ] unit-test +[ "\\" string>literals >strings ] must-fail ! \ alone should be legal eventually (?) { { "\\FOO" } } [ "\\FOO" string>literals >strings ] unit-test { @@ -81,4 +81,10 @@ IN: modern.tests [ "char: {" string>literals >strings ] must-fail [ "char: \"" string>literals >strings ] must-fail { { { "char:" "\\\\" } } } [ "char: \\\\" string>literals >strings ] unit-test -{ { { "char:" "\\" } } } [ "char: \\" string>literals >strings ] unit-test \ No newline at end of file + +[ "char: \\" string>literals >strings ] must-fail ! char: \ should be legal eventually + +! \ backslash going away someday + +{ { { "\\" "(" } } } [ "\\ (" string>literals >strings ] unit-test + diff --git a/extra/modern/modern.factor b/extra/modern/modern.factor index 6fc3c39cb8..662e4f6359 100644 --- a/extra/modern/modern.factor +++ b/extra/modern/modern.factor @@ -198,7 +198,15 @@ ERROR: colon-word-must-be-all-uppercase-or-lowercase n string word ; dup { [ "!" sequence= ] [ "#!" sequence= ] } 1|| [ take-comment ] [ merge-slice-til-whitespace ] if ; -ERROR: backslash-expects-whitespace slice ; +ERROR: no-backslash-payload n string slice ; +: read-backslash ( n string slice -- n' string obj ) + merge-slice-til-whitespace dup "\\" tail? [ + ! \ foo, M\ foo + [ + skip-blank-from slice-til-whitespace drop + dup [ no-backslash-payload ] unless + ] dip swap 2array + ] when ; ! If the slice is 0 width, we stopped on whitespace. ! Advance the index and read again! @@ -267,6 +275,7 @@ ERROR: mismatched-terminator n string slice ; [ "\"!:[{(<>\s\r\n" slice-til-either ] dip swap [ span-slices ] dip over "\\" head? [ drop + dup "\\" sequence= [ read-backslash ] when ] [ (lex-factor) ] if diff --git a/extra/modern/slices/slices.factor b/extra/modern/slices/slices.factor index 5634e45499..aea85e1ced 100644 --- a/extra/modern/slices/slices.factor +++ b/extra/modern/slices/slices.factor @@ -131,7 +131,9 @@ ERROR: unexpected-end n string ; ] if ; inline : merge-slice-til-whitespace ( n string slice -- n' string slice' ) - [ slice-til-whitespace drop ] dip merge-slices ; + pick [ + [ slice-til-whitespace drop ] dip merge-slices + ] when ; : merge-slice-til-eol ( n string slice -- n' string slice' ) [ slice-til-eol drop ] dip merge-slices ;