diff options
author | Adrian Kummerlaender | 2017-04-14 23:21:51 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2017-04-14 23:21:51 +0200 |
commit | c6d2b259a4f253403929f6f1104395a6a71b1be6 (patch) | |
tree | 6d4cdfa4ab50fbe0fa982db601d772c67e4dda20 /source/base/definition.d | |
parent | 963ace2e5ba0337130e5f343d7ab97a30b4547ae (diff) | |
download | slang-c6d2b259a4f253403929f6f1104395a6a71b1be6.tar slang-c6d2b259a4f253403929f6f1104395a6a71b1be6.tar.gz slang-c6d2b259a4f253403929f6f1104395a6a71b1be6.tar.bz2 slang-c6d2b259a4f253403929f6f1104395a6a71b1be6.tar.lz slang-c6d2b259a4f253403929f6f1104395a6a71b1be6.tar.xz slang-c6d2b259a4f253403929f6f1104395a6a71b1be6.tar.zst slang-c6d2b259a4f253403929f6f1104395a6a71b1be6.zip |
Convert structure to _dub_ build system
Diffstat (limited to 'source/base/definition.d')
-rw-r--r-- | source/base/definition.d | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/source/base/definition.d b/source/base/definition.d new file mode 100644 index 0000000..cf64f3e --- /dev/null +++ b/source/base/definition.d @@ -0,0 +1,62 @@ +module base.definition; + +import std.string; +import std.variant; +import std.typecons; + +import std.container : DList; + +import base.stack; + +alias Words = Stack!Token[string]; + +Nullable!(DList!Token) definition; +Words words; + +void start() { + definition = DList!Token(); +} + +void end() { + string wordToBeDefined; + + definition.front.visit!( + (int value) => wordToBeDefined = "", + (bool value) => wordToBeDefined = "", + (string name ) => wordToBeDefined = name + ); + + if ( wordToBeDefined == "" ) { + throw new Exception("words may not be numeric or boolean"); + } + + definition.removeFront; + words[wordToBeDefined] = Stack!Token(definition[]); + definition.nullify; +} + +bool handle(Token token) { + if ( definition.isNull ) { + return false; + } else { + if ( token.type == typeid(string) ) { + if ( *token.peek!string == ";" ) { + end; + } else { + definition.insertBack(token); + } + } else { + definition.insertBack(token); + } + + return true; + } +} + +Stack!Token get(string word) { + if ( word in words ) { + return words[word].dup; + } else { + return Stack!Token(Token(word)); + } +} |