fix for loop

ober

2381112c963e2895e179e9083fedcf051bc9d6ff

diff --git a/parser.ss b/parser.ss
index fcdbc59..4c32627 100644
--- a/parser.ss
+++ b/parser.ss
@@ -960,6 +960,10 @@
                        ((and (token? tok) (eq? (token-type tok) 'WORD)
                              (not (string=? (token-value tok) "do")))
                         (loop (cons (token-value (parser-next! ps)) words)))
+                       ((eq? tok 'eof)
+                        (set! (parser-state-needs-more? ps) #t)
+                        (set! (lexer-want-more? (parser-state-lexer ps)) #t)
+                        (reverse words))
                        (else (reverse words))))))
                ;; No "in" clause — iterate over "$@"
                (begin
diff --git a/test/test-binary.sh b/test/test-binary.sh
index 833016f..371cb86 100755
--- a/test/test-binary.sh
+++ b/test/test-binary.sh
@@ -97,7 +97,10 @@ if pid == 0:
     os.dup2(slave, 1)
     os.dup2(slave, 2)
     os.close(slave)
-    os.execv(binary, [binary])
+    env = os.environ.copy()
+    env['PS1'] = 'jsh-test> '
+    env['PS2'] = 'jsh-more> '
+    os.execve(binary, [binary, '-i'], env)
     sys.exit(1)
 os.close(slave)
 
@@ -120,15 +123,29 @@ def send(cmd):
     os.write(master, (cmd + '\n').encode())
     return read_all(0.5)
 
+def clean(data):
+    return re.sub(r'\x1b\[[0-9;?]*[a-zA-Z]', '',
+                  data.decode('utf-8', errors='replace'))
+
 read_all(1.0)
-send('for x in a b; do')
+for_first = send('for x in a b')
+send('do')
 send('echo "x=$x"')
-out = send('done')
-text = re.sub(r'\x1b\[[0-9;?]*[a-zA-Z]', '', out.decode('utf-8', errors='replace'))
+for_done = send('done')
+while_first = send('while :')
+send('do')
+send('echo once')
+send('break')
+while_done = send('done')
 os.write(master, b'exit\n')
 read_all(0.5)
 os.waitpid(pid, 0)
-if 'x=a' in text and 'x=b' in text:
+first_text = clean(for_first) + clean(while_first)
+text = first_text + clean(for_done) + clean(while_done)
+if ('jsh-more>' in clean(for_first) and
+    'jsh-more>' in clean(while_first) and
+    'x=a' in text and 'x=b' in text and 'once' in text and
+    'syntax error' not in text):
     sys.exit(0)
 else:
     print(text, file=sys.stderr)
diff --git a/test/test-jsh.ss b/test/test-jsh.ss
index a9f73ad..b5c4cf7 100644
--- a/test/test-jsh.ss
+++ b/test/test-jsh.ss
@@ -84,6 +84,7 @@
 (check-true (>= (length (tokenize "echo ok")) 2))
 (check-true (list? (tokenize "printf '%s\\n' ok | cat")))
 (check-true (parse-complete-command "echo ok" #f #f))
+(check (parse-complete-command "for dir in jerboa*" #f #f) => 'need-more)
 
 (printf "--- environment ---~n")
 (let ([env (make-shell-environment)])