modern: Still support ``\ foo`` for now.

modern-harvey2
Doug Coleman 2017-08-26 13:52:35 -05:00
parent fbb5f871c4
commit 161a50c0b8
3 changed files with 21 additions and 4 deletions

View File

@ -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
[ "char: \\" string>literals >strings ] must-fail ! char: \ should be legal eventually
! \ backslash going away someday
{ { { "\\" "(" } } } [ "\\ (" string>literals >strings ] unit-test

View File

@ -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

View File

@ -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 ;