diff options
Diffstat (limited to 'parser.d')
| -rw-r--r-- | parser.d | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -13,6 +13,7 @@ enum FormType { SYMBOL, FUNC, DEF, + BLOCK, EOF, PARSE_ERROR @@ -79,6 +80,20 @@ class ParseError : Form { } } +class Block : Form { + + Form[] blockBody; + + this(int line) { + this.line = line; + this.type = FormType.BLOCK; + } + + void addToBody(Form f) { + this.blockBody ~= f; + } +} + class Cons : Form { Form head; @@ -376,6 +391,27 @@ class Parser { return func; } + Form parseBlock() { + Block block = new Block(line); + char next; + while(peekable()) { + next = peek(); + if (next == ')') { + break; + } + block.addToBody(parseForm()); + } + + if (!peekable()) { + return new ParseError("unterminated block", line); + } + + advance(); // consume closing paren + + return block; + + } + Form parseCons() { skipWhitespace(); @@ -395,6 +431,8 @@ class Parser { return parseFunc(); case "def": return parseDef(); + case "block": + return parseBlock(); default: break; } |
