aboutsummaryrefslogtreecommitdiff
path: root/repl.d
diff options
context:
space:
mode:
Diffstat (limited to 'repl.d')
-rw-r--r--repl.d24
1 files changed, 14 insertions, 10 deletions
diff --git a/repl.d b/repl.d
index e3aef2b..b68b46a 100644
--- a/repl.d
+++ b/repl.d
@@ -11,14 +11,17 @@ import src.stack;
static import definition = src.definition;
static import primitives = src.primitives.eval;
-void process(int x) {
- try {
- if ( !primitives.evaluate(x) ) {
- stack.push(x);
+template process(T)
+if ( is(T == int) || is(T == bool) ) {
+ void process(T value) {
+ try {
+ if ( !primitives.evaluate(value) ) {
+ stack.push(value);
+ }
+ }
+ catch (Exception ex) {
+ writeln("Error: ", ex.msg);
}
- }
- catch (Exception ex) {
- writeln("Error: ", ex.msg);
}
}
@@ -41,8 +44,9 @@ void process(string word) {
void process(Token token) {
token.visit!(
- (int x ) => process(x),
- (string word) => process(word)
+ (int value) => process(value),
+ (bool value) => process(value),
+ (string word ) => process(word)
);
}
@@ -50,7 +54,7 @@ void main() {
while ( !stdin.eof ) {
foreach ( token; stdin.readln.split ) {
if ( token.isNumeric ) {
- immutable int value = parse!int(token);
+ auto value = parse!int(token);
if ( !definition.handle(value) ) {
process(value);