aboutsummaryrefslogtreecommitdiff
path: root/parser.d
diff options
context:
space:
mode:
authorBen Winston2023-05-20 22:54:07 -0400
committerBen Winston2023-05-20 22:54:07 -0400
commit2ad2be250a68e907b308b120b934edcbfc99ae6e (patch)
tree54cd9308286cb4a368a8f7eb11ad9011c74ac58a /parser.d
parent38dc63a67879a42f208b5642a8590e1192e8e2e5 (diff)
block scope and local variables (not really working)
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 ef1d736..978b218 100644
--- a/parser.d
+++ b/parser.d
@@ -13,6 +13,7 @@ enum FormType {
SYMBOL,
FUNC,
DEF,
+ BLOCK,
EOF,
PARSE_ERROR
@@ -79,6 +80,20 @@ class ParseError : Form {
}
}
+class Block : Form {
+
+ Form[] blockBody;
+
+ this(int line) {
+ this.line = line;
+ this.type = FormType.BLOCK;
+ }
+
+ void addToBody(Form f) {
+ this.blockBody ~= f;
+ }
+}
+
class Cons : Form {
Form head;
@@ -376,6 +391,27 @@ class Parser {
return func;
}
+ Form parseBlock() {
+ Block block = new Block(line);
+ char next;
+ while(peekable()) {
+ next = peek();
+ if (next == ')') {
+ break;
+ }
+ block.addToBody(parseForm());
+ }
+
+ if (!peekable()) {
+ return new ParseError("unterminated block", line);
+ }
+
+ advance(); // consume closing paren
+
+ return block;
+
+ }
+
Form parseCons() {
skipWhitespace();
@@ -395,6 +431,8 @@ class Parser {
return parseFunc();
case "def":
return parseDef();
+ case "block":
+ return parseBlock();
default:
break;
}