From fbc75bca57a3f66006468fb1a8f3988cdc8227d2 Mon Sep 17 00:00:00 2001 From: mryouse Date: Wed, 7 Jun 2023 22:52:09 -0400 Subject: initial commit of branch --- parser.d | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'parser.d') 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": -- cgit v1.2.3