aboutsummaryrefslogtreecommitdiff
path: root/src/definition.d
diff options
context:
space:
mode:
authorAdrian Kummerlaender2017-04-12 21:55:26 +0200
committerAdrian Kummerlaender2017-04-12 21:55:26 +0200
commitd5ea77e49e30ad751678f90123f891344642a36c (patch)
tree947e183a950e9291263ddc2a84ad25f2e11652be /src/definition.d
parent061db1f3810efac768dc7a83a8fbfaecfc512577 (diff)
downloadslang-d5ea77e49e30ad751678f90123f891344642a36c.tar
slang-d5ea77e49e30ad751678f90123f891344642a36c.tar.gz
slang-d5ea77e49e30ad751678f90123f891344642a36c.tar.bz2
slang-d5ea77e49e30ad751678f90123f891344642a36c.tar.lz
slang-d5ea77e49e30ad751678f90123f891344642a36c.tar.xz
slang-d5ea77e49e30ad751678f90123f891344642a36c.tar.zst
slang-d5ea77e49e30ad751678f90123f891344642a36c.zip
Introduce native boolean type
Diffstat (limited to 'src/definition.d')
-rw-r--r--src/definition.d30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/definition.d b/src/definition.d
index dd4dddc..e6a7789 100644
--- a/src/definition.d
+++ b/src/definition.d
@@ -20,12 +20,13 @@ void end() {
string wordToBeDefined;
definition.front.visit!(
- (int x ) => wordToBeDefined = "",
- (string name) => wordToBeDefined = name
+ (int value) => wordToBeDefined = "",
+ (bool value) => wordToBeDefined = "",
+ (string name ) => wordToBeDefined = name
);
if ( wordToBeDefined == "" ) {
- throw new Exception("words may not be numeric");
+ throw new Exception("words may not be numeric or boolean");
}
definition.removeFront;
@@ -33,12 +34,15 @@ void end() {
definition.nullify;
}
-bool handle(int value) {
- if ( definition.isNull ) {
- return false;
- } else {
- definition.insertBack(Token(value));
- return true;
+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;
+ }
}
}
@@ -55,3 +59,11 @@ bool handle(string word) {
return true;
}
}
+
+bool handle(Token token) {
+ return token.visit!(
+ (int value) => handle(value),
+ (bool value) => handle(value),
+ (string word ) => handle(word)
+ );
+}