diff options
| author | Ben Winston | 2023-05-21 19:55:04 -0400 |
|---|---|---|
| committer | Ben Winston | 2023-05-21 19:55:04 -0400 |
| commit | a26bfccdc52ab50a83b8f8d170c9e1a3be0164a5 (patch) | |
| tree | b12118bebf7e22a29fa4d953ee3a8b7085008612 /parser.d | |
| parent | 618de4c70d8916f64781997f3ae538e3e6109d00 (diff) | |
'or' control statement
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; } |
