complex numbers no longer require a 0+ prefix

master
Jordan Orelli 10 years ago
parent 1f755f90aa
commit a7f942aa08

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

@ -11,13 +11,14 @@ import (
const () const ()
var nodes = map[tokenType]func(p *parser) node{ var nodes = map[tokenType]func(p *parser) node{
t_string: func(p *parser) node { return new(stringNode) }, t_string: func(p *parser) node { return new(stringNode) },
t_real_number: func(p *parser) node { return new(numberNode) }, t_real_number: func(p *parser) node { return new(numberNode) },
t_list_start: func(p *parser) node { p.next(); return &listNode{} }, t_imaginary_number: func(p *parser) node { return new(numberNode) },
t_object_start: func(p *parser) node { p.next(); return &objectNode{} }, t_list_start: func(p *parser) node { p.next(); return &listNode{} },
t_variable: func(p *parser) node { return new(variableNode) }, t_object_start: func(p *parser) node { p.next(); return &objectNode{} },
t_bool: func(p *parser) node { return new(boolNode) }, t_variable: func(p *parser) node { return new(variableNode) },
t_duration: func(p *parser) node { return new(durationNode) }, t_bool: func(p *parser) node { return new(boolNode) },
t_duration: func(p *parser) node { return new(durationNode) },
} }
var DefaultPath = "./config.moon" var DefaultPath = "./config.moon"

Loading…
Cancel
Save