From c6d2b259a4f253403929f6f1104395a6a71b1be6 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Fri, 14 Apr 2017 23:21:51 +0200 Subject: Convert structure to _dub_ build system --- src/primitives/conditional.d | 77 -------------------------------------------- 1 file changed, 77 deletions(-) delete mode 100644 src/primitives/conditional.d (limited to 'src/primitives/conditional.d') diff --git a/src/primitives/conditional.d b/src/primitives/conditional.d deleted file mode 100644 index ee89ea5..0000000 --- a/src/primitives/conditional.d +++ /dev/null @@ -1,77 +0,0 @@ -module src.primitives.conditional; - -import std.variant; -import std.typecons; -import std.container : DList; - -import src.stack; - -Nullable!(DList!Token) buffer; -bool concluded = true; -bool drop_mode = false; - -void capture(Token token) { - if ( !drop_mode ) { - buffer.insertBack(token); - } -} - -bool drop(Token token) { - if ( concluded && buffer.isNull ) { - return false; - } - - if ( token.type == typeid(string) ) { - switch ( *token.peek!string ) { - case "if" : eval_if; break; - case "then" : eval_then; break; - case "else" : eval_else; break; - default : capture(token); break; - } - } else { - capture(token); - } - - return true; -} - -void eval_if() { - if ( concluded ) { - buffer = DList!Token(); - drop_mode = !stack.pop.get!bool; - concluded = false; - } else { - throw new Exception("conditionals may not be nested directly"); - } -} - -void eval_then() { - if ( concluded ) { - throw new Exception("`then` without preceding `if`"); - } else { - drop_mode = !drop_mode; - } -} - -void eval_else() { - if ( concluded ) { - throw new Exception("`else` without preceding `if`"); - } else { - drop_mode = false; - concluded = true; - } -} - -bool dischargeable() { - return concluded && !buffer.isNull; -} - -Stack!Token discharge() { - if ( concluded ) { - Stack!Token result = buffer[]; - buffer.nullify; - return result; - } else { - throw new Exception("unconcluded conditional may not be discharged"); - } -} -- cgit v1.2.3