complex numbers no longer require a 0+ prefix

master
Jordan Orelli 10 years ago
parent 1f755f90aa
commit a7f942aa08

@ -284,10 +284,8 @@ func (n *numberNode) Type() nodeType {
func (n *numberNode) parse(p *parser) error {
t := p.next()
if t.t != t_real_number {
return fmt.Errorf("unexpected %s token while parsing number", t.t)
}
switch t.t {
case t_real_number:
if p.peek().t == t_imaginary_number {
n.t = num_complex
s := t.s + p.next().s
@ -296,6 +294,15 @@ func (n *numberNode) parse(p *parser) error {
}
return nil
}
case t_imaginary_number:
n.t = num_complex
if _, err := fmt.Sscan("0+"+t.s, &n.c); err != nil {
return fmt.Errorf("ungood imaginary number format %s: %s", t.s, err)
}
return nil
default:
return fmt.Errorf("unexpected %s token while parsing number", t.t)
}
i, err := strconv.ParseInt(t.s, 0, 64)
if err == nil {

@ -13,6 +13,7 @@ const ()
var nodes = map[tokenType]func(p *parser) node{
t_string: func(p *parser) node { return new(stringNode) },
t_real_number: func(p *parser) node { return new(numberNode) },
t_imaginary_number: func(p *parser) node { return new(numberNode) },
t_list_start: func(p *parser) node { p.next(); return &listNode{} },
t_object_start: func(p *parser) node { p.next(); return &objectNode{} },
t_variable: func(p *parser) node { return new(variableNode) },

Loading…
Cancel
Save