RosettaCodeData/Task/Tokenize-a-string-with-escaping/Forth/tokenize-a-string-with-escaping.fth
2023-07-01 13:44:08 -04:00

16 lines
557 B
Forth

variable 'src
variable #src
variable offset
: advance 1 offset +! ;
: chr@ offset @ 'src @ + c@ ;
: nextchr advance chr@ ;
: bound offset @ #src @ u< ;
: separator? dup [char] | = if drop cr else emit then ;
: escape? dup [char] ^ = if drop nextchr emit else separator? then ;
: tokenize 0 offset ! begin bound while nextchr escape? repeat ;
\ Test of function
Here 'src ! ," one^|uno||three^^^^|four^^^|^cuatro|" here 'src @ - #src !
page
cr ." #### start ####" cr tokenize cr ." #### End ####" cr