From 1c10fd3d76d5ddbd745528820dcfe74b4c3df202 Mon Sep 17 00:00:00 2001 From: mryouse Date: Tue, 6 Jun 2023 21:14:01 -0400 Subject: parse booleans --- dbg.d | 4 ++-- parser.d | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/dbg.d b/dbg.d index c09b199..66250b6 100644 --- a/dbg.d +++ b/dbg.d @@ -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); diff --git a/parser.d b/parser.d index 1a1e5fb..004e1fb 100644 --- a/parser.d +++ b/parser.d @@ -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(); } -- cgit v1.2.3