aboutsummaryrefslogtreecommitdiff
path: root/parser.d
diff options
context:
space:
mode:
Diffstat (limited to 'parser.d')
-rw-r--r--parser.d38
1 files changed, 38 insertions, 0 deletions
diff --git a/parser.d b/parser.d
index 004e1fb..0b31be8 100644
--- a/parser.d
+++ b/parser.d
@@ -17,6 +17,7 @@ enum FormType {
DEF,
BLOCK,
IF,
+ BRANCH,
AND,
OR,
@@ -157,6 +158,20 @@ class If : Form {
}
+class Branch : Form {
+
+ Form[] clauses;
+
+ this(int line) {
+ this.line = line;
+ this.type = FormType.BRANCH;
+ }
+
+ void addClause(Form clause) {
+ this.clauses ~= clause;
+ }
+}
+
class And : Form {
Form[] clauses;
@@ -605,6 +620,27 @@ class Parser {
return if_;
}
+ Form parseBranch() {
+ Branch branch = new Branch(-1);
+ Form f;
+ char next;
+ while(peekable()) {
+ next = peek();
+ if (next == ')') {
+ break;
+ }
+ branch.addClause(parseForm());
+ }
+
+ if (!peekable()) {
+ return new ParseError("unterminated branch", line);
+ }
+
+ advance(); // consume closing paren
+
+ return branch;
+ }
+
Form parseAnd() {
And and_ = new And(line);
char next;
@@ -691,6 +727,8 @@ class Parser {
return parseBlock();
case "if":
return parseIf();
+ case "branch":
+ return parseBranch();
case "and":
return parseAnd();
case "or":