From 568e457d5f879633adc8a33d8c2979d563556868 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 15 Apr 2017 18:16:39 +0200 Subject: Handle definition, conditional primitive words in respective modules --- source/base/definition.d | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'source/base/definition.d') diff --git a/source/base/definition.d b/source/base/definition.d index cf64f3e..4c0f50c 100644 --- a/source/base/definition.d +++ b/source/base/definition.d @@ -13,11 +13,7 @@ alias Words = Stack!Token[string]; Nullable!(DList!Token) definition; Words words; -void start() { - definition = DList!Token(); -} - -void end() { +void register(DList!Token definition) { string wordToBeDefined; definition.front.visit!( @@ -32,27 +28,48 @@ void end() { definition.removeFront; words[wordToBeDefined] = Stack!Token(definition[]); - definition.nullify; } -bool handle(Token token) { +template handle(T) +if ( is(T == int) || is(T == bool) ) { + bool handle(T value) { + if ( definition.isNull ) { + return false; + } else { + definition.insertBack(Token(value)); + return true; + } + } +} + +bool handle(string word) { if ( definition.isNull ) { - return false; + if ( word == "ยง" ) { + definition = DList!Token(); + return true; + } else { + return false; + } } else { - if ( token.type == typeid(string) ) { - if ( *token.peek!string == ";" ) { - end; - } else { - definition.insertBack(token); - } + if ( word == ";" ) { + register(definition); + definition.nullify; } else { - definition.insertBack(token); + definition.insertBack(Token(word)); } return true; } } +bool handle(Token token) { + return token.visit!( + (int value) => handle(value), + (bool value) => handle(value), + (string word ) => handle(word) + ); +} + Stack!Token get(string word) { if ( word in words ) { return words[word].dup; -- cgit v1.2.3