modern: Fix some parsing issues with passing f to find-from. Add tests.
parent
013ed4f2ab
commit
1e4723ad2d
|
@ -7,7 +7,7 @@ sequences.generalizations sets shuffle splitting strings
|
|||
syntax.modern unicode vocabs.loader ;
|
||||
IN: modern
|
||||
|
||||
ERROR: string-expected-got-eof string n ;
|
||||
ERROR: unexpected-eof string n ;
|
||||
ERROR: long-opening-mismatch tag open string n ch ;
|
||||
ERROR: lex-expected-but-got-eof string n expected ;
|
||||
ERROR: expected-length-tokens string n length seq ;
|
||||
|
@ -123,14 +123,14 @@ MACRO:: read-matched ( ch -- quot: ( string n tag -- string n' slice' ) )
|
|||
{ char: \\ [ drop next-char-from drop read-string-payload ] }
|
||||
} case
|
||||
] [
|
||||
string-expected-got-eof
|
||||
unexpected-eof
|
||||
] if ;
|
||||
|
||||
:: read-string ( string n tag -- string n' seq )
|
||||
string n read-string-payload nip :> n'
|
||||
string
|
||||
n'
|
||||
n' [ string n string-expected-got-eof ] unless
|
||||
n' [ string n unexpected-eof ] unless
|
||||
n n' 1 - string <slice>
|
||||
n' 1 - n' string <slice>
|
||||
tag -rot 3array ;
|
||||
|
@ -157,8 +157,11 @@ MACRO:: read-matched ( ch -- quot: ( string n tag -- string n' slice' ) )
|
|||
: read-lowercase-colon ( string n slice -- string n' lowercase-colon )
|
||||
dup [ char: \: = ] count-tail
|
||||
'[
|
||||
_ [ slice-til-not-whitespace drop [ lex-factor ] dip swap 2array ] replicate
|
||||
ensure-no-false dup [ token-expected ] unless
|
||||
_ [
|
||||
slice-til-not-whitespace drop ! XXX: whitespace here
|
||||
[ dup [ unexpected-eof ] unless ] dip
|
||||
[ lex-factor ] dip swap 2array
|
||||
] replicate
|
||||
dup terminator? [ unexpected-terminator ] when
|
||||
] dip swap 2array ;
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
! Copyright (C) 2019 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: ascii modern.slices sequences tools.test ;
|
||||
IN: modern.slices.tests
|
||||
|
||||
{ "foo:" f f f } [
|
||||
"foo:" f slice-til-not-whitespace
|
||||
] unit-test
|
||||
|
||||
{ "foo:" f f f } [
|
||||
"foo:" f slice-til-whitespace
|
||||
] unit-test
|
||||
|
||||
{ "foo:" 0 T{ slice f 0 0 "foo:" } 102 } [
|
||||
"foo:" 0 slice-til-not-whitespace
|
||||
] unit-test
|
||||
|
||||
{ "foo:" 3 T{ slice f 3 3 "foo:" } 58 } [
|
||||
"foo:" 3 slice-til-not-whitespace
|
||||
] unit-test
|
||||
|
||||
{ "foo:" f T{ slice f 0 4 "foo:" } f } [
|
||||
"foo:" 0 slice-til-whitespace
|
||||
] unit-test
|
||||
|
||||
{ "foo:" f T{ slice f 3 4 "foo:" } f } [
|
||||
"foo:" 3 slice-til-whitespace
|
||||
] unit-test
|
||||
|
||||
{
|
||||
"foo "
|
||||
f
|
||||
T{ slice f 0 4 "foo " }
|
||||
f
|
||||
} [
|
||||
"foo " 0 [ blank? ] slice-until-include
|
||||
] unit-test
|
||||
|
||||
{
|
||||
"foo "
|
||||
3
|
||||
T{ slice f 0 3 "foo " }
|
||||
32
|
||||
} [
|
||||
"foo " 0 [ blank? ] slice-until-exclude
|
||||
] unit-test
|
|
@ -52,17 +52,25 @@ ERROR: unexpected-end string n ;
|
|||
swapd find-from* ; inline
|
||||
|
||||
: slice-until-exclude ( string n quot -- string n' slice/f ch/f )
|
||||
[ drop ]
|
||||
[ find-from' ] 3bi ! ( string n n' ch )
|
||||
[ drop nip ]
|
||||
[ [ rot ?<slice> ] dip ] 4bi ; inline
|
||||
over [
|
||||
[ drop ]
|
||||
[ find-from' ] 3bi ! ( string n n' ch )
|
||||
[ drop nip ]
|
||||
[ [ rot ?<slice> ] dip ] 4bi
|
||||
] [
|
||||
drop f f
|
||||
] if ; inline
|
||||
|
||||
: slice-until-include ( string n tokens -- string n' slice/f ch/f )
|
||||
'[ _ member? ]
|
||||
[ drop ]
|
||||
[ find-from' [ ?1+ ] dip ] 3bi ! ( string n n' ch )
|
||||
[ drop nip ]
|
||||
[ [ rot ?<slice> ] dip ] 4bi ; inline
|
||||
over [
|
||||
'[ _ member? ]
|
||||
[ drop ]
|
||||
[ find-from' [ ?1+ ] dip ] 3bi ! ( string n n' ch )
|
||||
[ drop nip ]
|
||||
[ [ rot ?<slice> ] dip ] 4bi
|
||||
] [
|
||||
drop f f
|
||||
] if ; inline
|
||||
|
||||
: slice-til-whitespace ( string n -- string n' slice/f ch/f )
|
||||
[ "\s\r\n" member? ] slice-until-exclude ; inline
|
||||
|
|
Loading…
Reference in New Issue