From 6614f8fc4f964d36a05921d64c579e5e2c58a99d Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Fri, 4 Jul 2014 13:44:30 +0900 Subject: [PATCH] support #true and #false literals --- src/read.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/read.c b/src/read.c index 5ea58f4a..7c995499 100644 --- a/src/read.c +++ b/src/read.c @@ -48,6 +48,19 @@ peek(struct pic_port *port) return c; } +static bool +expect(struct pic_port *port, const char *str) +{ + char c; + + while ((c = *str++) != 0) { + if (c != next(port)) + return false; + } + + return true; +} + static bool isdelim(char c) { @@ -250,13 +263,26 @@ read_boolean(pic_state *pic, struct pic_port *port, char c) UNUSED(pic); UNUSED(port); - /* TODO: support #true and #false */ + if (! isdelim(peek(port))) { + if (c == 't') { + if (! expect(port, "rue")) { + goto fail; + } + } else { + if (! expect(port, "alse")) { + goto fail; + } + } + } if (c == 't') { return pic_true_value(); } else { return pic_false_value(); } + + fail: + read_error(pic, "illegal character during reading boolean literal"); } static pic_value