aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--format.go2
-rw-r--r--lexer.go23
2 files changed, 20 insertions, 5 deletions
diff --git a/format.go b/format.go
index 5a554eb..48ffcfd 100644
--- a/format.go
+++ b/format.go
@@ -26,7 +26,7 @@ func (f F) String() string {
pre = "¯"
f = -f
}
- return fmt.Sprint(pre, int64(f))
+ return fmt.Sprint(pre, float64(f))
}
func (c C) String() string {
diff --git a/lexer.go b/lexer.go
index a52cc96..ab7165f 100644
--- a/lexer.go
+++ b/lexer.go
@@ -33,17 +33,32 @@ func (y *yyLex) Lex(lval *yySymType) int {
lval.sval = S(strings.Replace(item.val, "''", "'", -1))
case INTEGER:
item.val = strings.Replace(item.val, "¯", "-", -1)
- v, _ := strconv.ParseInt(item.val, 10, 64)
+ v, err := strconv.ParseInt(item.val, 10, 64)
+ if err != nil {
+ y.Error(err.Error())
+ }
lval.ival = I(v)
case FLOAT:
item.val = strings.Replace(item.val, "¯", "-", -1)
- v, _ := strconv.ParseFloat(item.val, 64)
+ v, err := strconv.ParseFloat(item.val, 64)
+ if err != nil {
+ y.Error(err.Error())
+ }
lval.fval = F(v)
case COMPLEX:
item.val = strings.Replace(item.val, "¯", "-", -1)
pos := strings.IndexAny(item.val, "jJ")
- r, _ := strconv.ParseFloat(item.val[:pos], 64)
- i, _ := strconv.ParseFloat(item.val[pos+1:], 64)
+ if pos < 0 {
+ y.Error("not a complex number")
+ }
+ r, err := strconv.ParseFloat(item.val[:pos], 64)
+ if err != nil {
+ y.Error(err.Error())
+ }
+ i, err := strconv.ParseFloat(item.val[pos+1:], 64)
+ if err != nil {
+ y.Error(err.Error())
+ }
lval.cval = C(complex(r, i))
}
return item.typ