diff options
Diffstat (limited to 'interpret.e')
| -rw-r--r-- | interpret.e | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/interpret.e b/interpret.e index 7f839ac..7695d0b 100644 --- a/interpret.e +++ b/interpret.e @@ -179,7 +179,10 @@ drop 0 ; ~ Greater than "z". -~ Okay, this is the big one, the lexer! Wow. +~ Okay, this is the big one, the lexer! Wow. +~ +~ The only way this can ever return a zero-length string is if it hit EOF, +~ and callers can rely on that. ~ ~ (-- stack string occupying multiple words) : word @@ -190,14 +193,21 @@ ~ Skip whitespace. { key dup is-space } { drop } while - ~ Early exit if it's a zero byte. - dup 0 = { drop dropstring 0 exit } if + ~ Early exit if it's an EOF. We leave the accumulated string on the stack; + ~ since we're not in the loop yet, it will be empty and this will function + ~ as the caller's indication we're at EOF. + dup -1 = { drop exit } if accumulate-string { peek dup is-space { drop exit } if - dup { drop exit } unless + + ~ If it's an EOF, exit, leaving the accumulated string on the stack. + ~ It's nonempty, since we're in the loop already, and from the caller's + ~ perspective it's valid input. + dup -1 = { drop exit } if + consume accumulate-string } forever ; |