aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-03-23 12:35:42 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-03-23 12:35:42 +0100
commit187684cdb5fc801b655d77d39addfd7119610d1a (patch)
treefd31f5a00696c05aa2d35ede3831fe857e598754
parent73a4e6134c0ae131b68dd946bd9f585dd21b97ee (diff)
Add some error reporting
-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