be gone, commas

master
Jordan Orelli 10 years ago
parent 0820a130e5
commit db5ea6d634

@ -31,8 +31,6 @@ func (t tokenType) String() string {
return "t_list_start"
case t_list_end:
return "t_list_end"
case t_list_separator:
return "t_list_separator"
case t_object_start:
return "t_object_start"
case t_object_separator:
@ -57,7 +55,6 @@ const (
t_comment // a comment
t_list_start // [
t_list_end // ]
t_list_separator // ,
t_object_start // {
t_object_end // }
t_object_separator // :
@ -202,10 +199,6 @@ func lexRoot(l *lexer) stateFn {
l.keep(r)
l.emit(t_list_end)
return lexRoot
case r == ',':
l.keep(r)
l.emit(t_list_separator)
return lexRoot
case r == '{':
l.keep(r)
l.emit(t_object_start)

@ -46,7 +46,7 @@ func parsse() {
n, err := parse(r)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s", err)
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
if err := n.pretty(os.Stdout, ""); err != nil {

@ -104,13 +104,12 @@ func (p *parser) parseList(l list) (list, error) {
l = append(l, v)
}
switch t := p.next(); t.t {
case t_list_separator:
return p.parseList(l)
switch t := p.peek(); t.t {
case t_list_end:
p.next()
return l, nil
default:
return nil, fmt.Errorf("parse error: unexpected %v token while scanning for list", t.t)
return p.parseList(l)
}
}
@ -134,13 +133,12 @@ func (p *parser) parseObject(obj object) (object, error) {
obj[field_name] = v
}
switch t := p.next(); t.t {
case t_list_separator:
return p.parseObject(obj)
switch t := p.peek(); t.t {
case t_object_end:
p.next()
return obj, nil
default:
return nil, fmt.Errorf("parse error: unexpected %v token while scanning for object", t.t)
return p.parseObject(obj)
}
}

Loading…
Cancel
Save