diff options
| -rw-r--r-- | dbg.d | 4 | ||||
| -rw-r--r-- | parser.d | 24 |
2 files changed, 26 insertions, 2 deletions
@@ -77,9 +77,9 @@ string printableValue(Value val) { return format("%g", val.as.number); case ValueType.BOOLEAN: if (val.as.boolean) { - return "true"; + return "#true"; } else { - return "false"; + return "#false"; } case ValueType.OBJ: return printableFunction(val.as.obj); @@ -486,6 +486,27 @@ class Parser { return new Atom(to!double(to!string(acc)), line); } + Form parseBoolean() { + char[] acc; + char next; + while (peekable()) { + next = peek(); + if (isBoundary(next)) { + break; + } + acc ~= next; + advance(); + } + switch (to!string(acc)) { + case "true": + return new Atom(true, line); + case "false": + return new Atom(false, line); + default: + return new ParseError(format("unparseable bool: #%s", to!string(acc)), line); + } + } + Form parseDef() { // we've parsed `def`, but not the symbol yet Form sym = parseForm(); @@ -726,6 +747,9 @@ class Parser { } writefln("received (but ignoring) type %s on line %d", to!string(typ), line); return parseForm(); + case '#': + advance(); // go past the hash + return parseBoolean(); default: return parseSymbol(); } |
