aboutsummaryrefslogtreecommitdiff
path: root/parser.d
diff options
context:
space:
mode:
authorBen Winston2023-05-21 19:55:04 -0400
committerBen Winston2023-05-21 19:55:04 -0400
commita26bfccdc52ab50a83b8f8d170c9e1a3be0164a5 (patch)
treeb12118bebf7e22a29fa4d953ee3a8b7085008612 /parser.d
parent618de4c70d8916f64781997f3ae538e3e6109d00 (diff)
'or' control statement
Diffstat (limited to 'parser.d')
-rw-r--r--parser.d37
1 files changed, 37 insertions, 0 deletions
diff --git a/parser.d b/parser.d
index 3dd32ef..0b8f863 100644
--- a/parser.d
+++ b/parser.d
@@ -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;
}