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

Commit

Permalink
7 more
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernest Micklei committed Nov 27, 2017
1 parent f15df7c commit 07112a2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion field.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (f *NormalField) columns() (cols []aligned) {
// [ "repeated" | "optional" ] type fieldName "=" fieldNumber [ "[" fieldOptions "]" ] ";"
func (f *NormalField) parse(p *Parser) error {
for {
_, tok, lit := p.next()
_, tok, lit := p.nextIdentifier()
switch tok {
case tREPEATED:
f.Repeated = true
Expand Down
3 changes: 0 additions & 3 deletions field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ func TestField(t *testing.T) {
if got, want := f.Options[2].Constant.Source, "happy"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := f.Position.Line, 1; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
}

func TestFieldSimple(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion message.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (m *Message) groupName() string {

// parse expects ident { messageBody
func (m *Message) parse(p *Parser) error {
_, tok, lit := p.next()
_, tok, lit := p.nextIdentifier()
if tok != tIDENT {
if !isKeyword(tok) {
return p.unexpected(lit, m.groupName()+" identifier", m)
Expand Down
3 changes: 0 additions & 3 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ func TestMessage(t *testing.T) {
if got, want := m.Name, "Out"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := m.Position.String(), "<input>:2:3"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := len(m.Elements), 6; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
Expand Down
31 changes: 20 additions & 11 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ func (o *Option) keyValuePair(embedded bool) (cols []aligned) {
// parse reads an Option body
// ( ident | "(" fullIdent ")" ) { "." ident } "=" constant ";"
func (o *Option) parse(p *Parser) error {
pos, tok, lit := p.next()
pos, tok, lit := p.nextIdentifier()
if tLEFTPAREN == tok {
pos, tok, lit = p.next()
pos, tok, lit = p.nextIdentifier()
if tok != tIDENT {
if !isKeyword(tok) {
return p.unexpected(lit, "option full identifier", o)
Expand All @@ -96,15 +96,15 @@ func (o *Option) parse(p *Parser) error {
o.Name = lit
}
pos, tok, lit = p.next()
if tDOT == tok {
// extend identifier
pos, tok, lit = p.next()
if tok != tIDENT {
return p.unexpected(lit, "option postfix identifier", o)
}
o.Name = fmt.Sprintf("%s.%s", o.Name, lit)
pos, tok, lit = p.next()
}
// if tDOT == tok {
// // extend identifier
// pos, tok, lit = p.nextIdentifier()
// if tok != tIDENT {
// return p.unexpected(lit, "option postfix identifier", o)
// }
// o.Name = fmt.Sprintf("%s.%s", o.Name, lit)
// pos, tok, lit = p.next()
// }
if tEQUALS != tok {
return p.unexpected(lit, "option constant =", o)
}
Expand Down Expand Up @@ -161,6 +161,15 @@ func (l Literal) String() string {
// parse expects to read a literal constant after =.
func (l *Literal) parse(p *Parser) error {
pos, _, lit := p.next()
if "-" == lit {
// negative number
if err := l.parse(p); err != nil {
return err
}
// modify source and position
l.Position, l.Source = pos, "-"+l.Source
return nil
}
source := lit
isString := isString(lit)
if isString {
Expand Down

0 comments on commit 07112a2

Please sign in to comment.