aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-03-29 16:30:12 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-03-29 16:30:12 +0200
commit7c769b61459c01b164c475eca0f623362adb30f3 (patch)
tree5facee2bc65e85a1d525f51ee3b7e3f06c6d9cf2
parentc6194ac91c02773d6b4ffbd53b2735f3ec6199cc (diff)
Deneg
-rw-r--r--lexer.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/lexer.go b/lexer.go
index ab7165f..fca7607 100644
--- a/lexer.go
+++ b/lexer.go
@@ -24,6 +24,10 @@ func (y *yyLex) Error(s string) {
log.Println(s)
}
+func deneg(s string) string {
+ return strings.Replace(s, "¯", "-", -1)
+}
+
func (y *yyLex) Lex(lval *yySymType) int {
item := <-y.items
switch item.typ {
@@ -32,21 +36,21 @@ func (y *yyLex) Lex(lval *yySymType) int {
case QUOTED:
lval.sval = S(strings.Replace(item.val, "''", "'", -1))
case INTEGER:
- item.val = strings.Replace(item.val, "¯", "-", -1)
+ item.val = deneg(item.val)
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)
+ item.val = deneg(item.val)
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)
+ item.val = deneg(item.val)
pos := strings.IndexAny(item.val, "jJ")
if pos < 0 {
y.Error("not a complex number")