diff options
author | Adrian Kummerlaender | 2017-04-15 18:16:39 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2017-04-15 18:16:39 +0200 |
commit | 568e457d5f879633adc8a33d8c2979d563556868 (patch) | |
tree | 1c5ec482edb0c6643b32278a2eb2e31a37dfa734 /source/base | |
parent | bce4d934a47023096e74ac39ed4d3a2cd99bc8e4 (diff) | |
download | slang-568e457d5f879633adc8a33d8c2979d563556868.tar slang-568e457d5f879633adc8a33d8c2979d563556868.tar.gz slang-568e457d5f879633adc8a33d8c2979d563556868.tar.bz2 slang-568e457d5f879633adc8a33d8c2979d563556868.tar.lz slang-568e457d5f879633adc8a33d8c2979d563556868.tar.xz slang-568e457d5f879633adc8a33d8c2979d563556868.tar.zst slang-568e457d5f879633adc8a33d8c2979d563556868.zip |
Handle definition, conditional primitive words in respective modules
Diffstat (limited to 'source/base')
-rw-r--r-- | source/base/definition.d | 47 |
1 files changed, 32 insertions, 15 deletions
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; |