diff options
| author | mryouse | 2023-06-06 21:14:01 -0400 |
|---|---|---|
| committer | mryouse | 2023-06-06 21:14:01 -0400 |
| commit | 1c10fd3d76d5ddbd745528820dcfe74b4c3df202 (patch) | |
| tree | d5e160deb150186177db97c6040abf267925d0ff /parser.d | |
| parent | d246597ef728ec74152c93eea00ff2c9585ef716 (diff) | |
parse booleans
Diffstat (limited to 'parser.d')
| -rw-r--r-- | parser.d | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -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(); } |
