diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2017-11-13 04:54:09 -0500 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2017-11-13 04:54:09 -0500 |
| commit | 9e693be5cd3d50f2f9c86edd5c021130bc3066c2 (patch) | |
| tree | 7a54b768f695d9fc0ba9ba165e7854ff8d169fea | |
| parent | 67738039c33956cc80444dce5543c8fa09e8bc9d (diff) | |
Distinguish EOF and () in read()
| -rw-r--r-- | actinide/reader.py | 6 | ||||
| -rwxr-xr-x | bin/actinide-repl | 3 |
2 files changed, 7 insertions, 2 deletions
diff --git a/actinide/reader.py b/actinide/reader.py index 0955309..f7703b5 100644 --- a/actinide/reader.py +++ b/actinide/reader.py @@ -10,6 +10,10 @@ from .types import * class SyntaxError(Exception): pass +# Returned on ``read`` if it has reached the end of the input. This is a +# special, non-interned token guaranteed to be unequal to any other token. +EOF = Symbol('#<end-of-input>') + # Reads one form from a port. This will consume all of the tokens included in # the form, but leave trailing data after the final token untouched. # @@ -23,7 +27,7 @@ class SyntaxError(Exception): def read(port, symbols): head = read_token(port) if head is None: - return None + return EOF if head == ')': raise SyntaxError("Unexpected ')'") if head == '(': diff --git a/bin/actinide-repl b/bin/actinide-repl index de19617..c4343b6 100755 --- a/bin/actinide-repl +++ b/bin/actinide-repl @@ -3,6 +3,7 @@ import sys import actinide as a +import actinide.reader as ar import actinide.ports as ap import actinide.types as at @@ -12,7 +13,7 @@ def repl(session, port): sys.stdout.write("> ") sys.stdout.flush() form = session.read(port) - if form is None: + if form is ar.EOF: print() return 0 results = session.eval(form) |
