diff options
Diffstat (limited to 'parser.d')
| -rw-r--r-- | parser.d | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -16,6 +16,7 @@ enum FormType { BLOCK, IF, AND, + OR, EOF, PARSE_ERROR @@ -176,6 +177,20 @@ class And : Form { } } +class Or : Form { + + Form[] clauses; + + this(int line) { + this.line = line; + this.type = FormType.OR; + } + + void addClause(Form clause) { + clauses ~= clause; + } +} + class Func : Form { Symbol name; @@ -480,6 +495,26 @@ class Parser { } + Form parseOr() { + Or or_ = new Or(line); + char next; + while(peekable()) { + next = peek(); + if (next == ')') { + break; + } + or_.addClause(parseForm()); + } + + if (!peekable()) { + return new ParseError("unterminated or", line); + } + + advance(); // consume closing paren + + return or_; + } + Form parseBlock() { Block block = new Block(line); char next; @@ -526,6 +561,8 @@ class Parser { return parseIf(); case "and": return parseAnd(); + case "or": + return parseOr(); default: break; } |
