diff --git a/src/eden/std/exceptions.cljc b/src/eden/std/exceptions.cljc index daa3adf..f04e210 100644 --- a/src/eden/std/exceptions.cljc +++ b/src/eden/std/exceptions.cljc @@ -1,16 +1,22 @@ (ns eden.std.exceptions) +(defn generate-window + "TODO: write this function, with bigger window." + [{:keys [tokens index] :as astm}] + (let [])) + + (defn generate-parser-data [{:keys [tokens index] :as astm}] - {:index index + {:position index :window (str - (if (> index 1) "... " "") - (nth tokens (dec index)) " " - "<" (nth tokens index) "> " - (nth tokens (inc index)) - (if (< index (- (count tokens) 3)) " ..." ""))}) + (if (> index 1) "... " "|BEGINNING| ") + (get tokens (dec index) "") " " + "'" (get tokens index) "' " + (get tokens (inc index) "") + (if (< index (- (count tokens) 3)) " ..." " |END|"))}) (defn parser-error @@ -51,12 +57,10 @@ (cond (parser-error? ex) (do - (println "Parser Error Caught") (throw ex)) (runtime-error? ex) (do - (println "Runtime Error Caught") (throw ex)) :else (throw ex))) diff --git a/src/eden/std/impl/expression.cljc b/src/eden/std/impl/expression.cljc index 7341dfc..a5b731b 100644 --- a/src/eden/std/impl/expression.cljc +++ b/src/eden/std/impl/expression.cljc @@ -135,9 +135,9 @@ Expression (evaluate-expression [_] - (<= - (evaluate-expression left) - (evaluate-expression right))) + (let [lvalue (evaluate-expression left) + rvalue (evaluate-expression right)] + (<= lvalue rvalue))) display/Display (display-node [_] @@ -155,9 +155,17 @@ Expression (evaluate-expression [_] - (+ - (evaluate-expression left) - (evaluate-expression right))) + (let [lvalue (evaluate-expression left) + rvalue (evaluate-expression right)] + (when-not (number? lvalue) + (runtime-error "Given lvalue for '+' operation is not a number" + {:display (display-node left) :value lvalue})) + + (when-not (number? rvalue) + (runtime-error "Given rvalue for '+' operation is not a number" + {:display (display-node right) :value rvalue})) + + (+ lvalue rvalue))) display/Display (display-node [_] @@ -170,9 +178,17 @@ Expression (evaluate-expression [_] - (- - (evaluate-expression left) - (evaluate-expression right))) + (let [lvalue (evaluate-expression left) + rvalue (evaluate-expression right)] + (when-not (number? lvalue) + (runtime-error "Given lvalue for '-' operation is not a number" + {:display (display-node left) :value lvalue})) + + (when-not (number? rvalue) + (runtime-error "Given rvalue for '-' operation is not a number" + {:display (display-node right) :value rvalue})) + + (- lvalue rvalue))) display/Display (display-node [_] @@ -190,9 +206,17 @@ Expression (evaluate-expression [_] - (* - (evaluate-expression left) - (evaluate-expression right))) + (let [lvalue (evaluate-expression left) + rvalue (evaluate-expression right)] + (when-not (number? lvalue) + (runtime-error "Given lvalue for '*' operation is not a number" + {:display (display-node left) :value lvalue})) + + (when-not (number? rvalue) + (runtime-error "Given rvalue for '*' operation is not a number" + {:display (display-node right) :value rvalue})) + + (* lvalue rvalue))) display/Display (display-node [_] @@ -205,9 +229,17 @@ Expression (evaluate-expression [_] - (/ - (evaluate-expression left) - (evaluate-expression right))) + (let [lvalue (evaluate-expression left) + rvalue (evaluate-expression right)] + (when-not (number? lvalue) + (runtime-error "Given lvalue for '/' operation is not a number" + {:display (display-node left) :value lvalue})) + + (when-not (number? rvalue) + (runtime-error "Given rvalue for '/' operation is not a number" + {:display (display-node right) :value rvalue})) + + (/ lvalue rvalue))) display/Display (display-node [_] @@ -238,7 +270,11 @@ Expression (evaluate-expression [_] - (- (evaluate-expression value))) + (let [evalue (evaluate-expression value)] + (when-not (number? evalue) + (runtime-error "Given single value for '-' operation is not a number" + {:display (display-node value) :value evalue})) + (- evalue))) display/Display (display-node [_]