state-parser take-quoted-string rewinds if the string is not found

db4
Doug Coleman 2009-04-01 14:50:43 -05:00
parent 1e4eebda3a
commit 947bcc3d33
2 changed files with 20 additions and 2 deletions

View File

@ -66,3 +66,16 @@ IN: html.parser.state.tests
[ CHAR: \ CHAR: " take-quoted-string drop ]
[ skip-whitespace "asdf" take-sequence ] bi
] 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

View File

@ -83,11 +83,16 @@ TUPLE: state-parser sequence n ;
[ <state-parser> ] dip call ; inline
:: take-quoted-string ( state-parser escape-char quote-char -- string )
state-parser n>> :> start-n
state-parser advance
[
{
[ { [ previous quote-char = ] [ current quote-char = ] } 1&& ]
[ current quote-char = not ]
} 1||
] take-while
state-parser advance* ;
] take-while :> string
state-parser current quote-char = [
state-parser advance* string
] [
start-n state-parser (>>n) f
] if ;