aboutsummaryrefslogtreecommitdiff
path: root/source/base
diff options
context:
space:
mode:
Diffstat (limited to 'source/base')
-rw-r--r--source/base/definition.d47
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;