state-parser take-quoted-string rewinds if the string is not found
parent
1e4eebda3a
commit
947bcc3d33
|
@ -66,3 +66,16 @@ IN: html.parser.state.tests
|
||||||
[ CHAR: \ CHAR: " take-quoted-string drop ]
|
[ CHAR: \ CHAR: " take-quoted-string drop ]
|
||||||
[ skip-whitespace "asdf" take-sequence ] bi
|
[ skip-whitespace "asdf" take-sequence ] bi
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
[ f ]
|
||||||
|
[
|
||||||
|
"\"abc asdf" <state-parser>
|
||||||
|
CHAR: \ CHAR: " take-quoted-string
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ "\"abc" ]
|
||||||
|
[
|
||||||
|
"\"abc asdf" <state-parser>
|
||||||
|
[ CHAR: \ CHAR: " take-quoted-string drop ]
|
||||||
|
[ "\"abc" take-sequence ] bi
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -83,11 +83,16 @@ TUPLE: state-parser sequence n ;
|
||||||
[ <state-parser> ] dip call ; inline
|
[ <state-parser> ] dip call ; inline
|
||||||
|
|
||||||
:: take-quoted-string ( state-parser escape-char quote-char -- string )
|
:: take-quoted-string ( state-parser escape-char quote-char -- string )
|
||||||
|
state-parser n>> :> start-n
|
||||||
state-parser advance
|
state-parser advance
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
[ { [ previous quote-char = ] [ current quote-char = ] } 1&& ]
|
[ { [ previous quote-char = ] [ current quote-char = ] } 1&& ]
|
||||||
[ current quote-char = not ]
|
[ current quote-char = not ]
|
||||||
} 1||
|
} 1||
|
||||||
] take-while
|
] take-while :> string
|
||||||
state-parser advance* ;
|
state-parser current quote-char = [
|
||||||
|
state-parser advance* string
|
||||||
|
] [
|
||||||
|
start-n state-parser (>>n) f
|
||||||
|
] if ;
|
||||||
|
|
Loading…
Reference in New Issue