Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
reorder enum, fix group formatting, allow keyword as identify, remove…
Browse files Browse the repository at this point in the history
… unused ,prepare for proto2 group
  • Loading branch information
Ernest Micklei authored and Ernest Micklei committed Feb 2, 2017
1 parent 533519d commit f3932ef
Showing 1 changed file with 47 additions and 43 deletions.
90 changes: 47 additions & 43 deletions enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,50 @@ func (e *Enum) Accept(v Visitor) {
v.VisitEnum(e)
}

func (e *Enum) parse(p *Parser) error {
tok, lit := p.scanIgnoreWhitespace()
if tok != tIDENT {
if !isKeyword(tok) {
return p.unexpected(lit, "enum identifier", e)
}
}
e.Name = lit
tok, lit = p.scanIgnoreWhitespace()
if tok != tLEFTCURLY {
return p.unexpected(lit, "enum opening {", e)
}
for {
tok, lit = p.scanIgnoreWhitespace()
switch tok {
case tCOMMENT:
e.Elements = append(e.Elements, p.newComment(lit))
case tOPTION:
v := new(Option)
err := v.parse(p)
if err != nil {
return err
}
e.Elements = append(e.Elements, v)
case tRIGHTCURLY:
goto done
case tSEMICOLON:
default:
p.unscan()
f := new(EnumField)
err := f.parse(p)
if err != nil {
return err
}
e.Elements = append(e.Elements, f)
}
}
done:
if tok != tRIGHTCURLY {
return p.unexpected(lit, "enum closing }", e)
}
return nil
}

// EnumField is part of the body of an Enum.
type EnumField struct {
Name string
Expand All @@ -38,7 +82,9 @@ func (f EnumField) columns() (cols []aligned) {
func (f *EnumField) parse(p *Parser) error {
tok, lit := p.scanIgnoreWhitespace()
if tok != tIDENT {
return p.unexpected(lit, "enum field identifier", f)
if !isKeyword(tok) {
return p.unexpected(lit, "enum field identifier", f)
}
}
f.Name = lit
tok, lit = p.scanIgnoreWhitespace()
Expand Down Expand Up @@ -66,45 +112,3 @@ func (f *EnumField) parse(p *Parser) error {
}
return nil
}

func (e *Enum) parse(p *Parser) error {
tok, lit := p.s.scanIdent()
if tok != tIDENT {
return p.unexpected(lit, "enum identifier", e)
}
e.Name = lit
tok, lit = p.scanIgnoreWhitespace()
if tok != tLEFTCURLY {
return p.unexpected(lit, "enum opening {", e)
}
for {
tok, lit = p.scanIgnoreWhitespace()
switch tok {
case tCOMMENT:
e.Elements = append(e.Elements, p.newComment(lit))
case tOPTION:
v := new(Option)
err := v.parse(p)
if err != nil {
return err
}
e.Elements = append(e.Elements, v)
case tRIGHTCURLY:
goto done
case tSEMICOLON:
default:
p.unscan()
f := new(EnumField)
err := f.parse(p)
if err != nil {
return err
}
e.Elements = append(e.Elements, f)
}
}
done:
if tok != tRIGHTCURLY {
return p.unexpected(lit, "enum closing }", e)
}
return nil
}

0 comments on commit f3932ef

Please sign in to comment.