As we will use the pipe (|) character as a divider, we will need tools to parse around it. Something like this:
testing parsing +≡: |halt! ; parse..| testing Hello there 123|halt! atom" testing" atom-cr+ atom" Hello there" atom+ atom-cr+ atom" 123" atom+ = assert
We'll need to manipulate the input buffer.
parsing +≡: source@ source ( -- a ) drop >in @ + ; : source-remaining ( -- n ) source nip >in @ - ;
Then parse through multiple lines until (but not including), the next pipe character.
parsing +≡: drop| ( -- ) source@ 1- c@ [char] | = if -1 >in +! then ; : need-refill? ( -- f) source nip >in @ <= ; : on|? ( -- f ) need-refill? if false exit then source@ c@ [char] | = ; : replenish ( -- f ) need-refill? if refill else true then ; : ?atom-cr+ ( A -- A ) on|? 0= if atom-cr+ then ; : eat| ( -- ) [char] | parse drop| atom atom+ ?atom-cr+ ; : parse..| ( -- A ) atom"" begin replenish 0= if exit then eat| on|? until ;
We'll also have some words that grab input until the end of the line.
parsing +≡: parse-cr ( -- A ) source@ source-remaining atom source nip >in ! ;