Skip to content

Commit

Permalink
handle semicolons in aggregated constants, fixes issue emicklei#79
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernest Micklei committed Apr 13, 2018
1 parent ff6be38 commit ef198d8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
12 changes: 10 additions & 2 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,16 @@ func parseAggregateConstants(p *Parser, container interface{}) (list []*NamedLit
return
}
if tSEMICOLON == tok {
p.nextPut(pos, tok, lit) // allow for inline comment parsing
return
// just consume it
continue
}
if tCOMMENT == tok {
// assign to last parsed literal
// TODO: see TestUseOfSemicolonsInAggregatedConstants
//if len(list) > 0 {
// list[len(list)-1].InlineComment = newComment(pos, lit)
//}
continue
}
if tCOMMA == tok {
if len(list) == 0 {
Expand Down
33 changes: 33 additions & 0 deletions option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,36 @@ func TestInvalidOptionAggregateWithRepeatedValues(t *testing.T) {
t.Error("expected syntax error")
}
}

// issue #79
func TestUseOfSemicolonsInAggregatedConstants(t *testing.T) {
src := `rpc Test(Void) returns (Void) {
option (google.api.http) = {
post: "/api/v1/test";
body: "*"; // ignored comment
};
}`
p := newParserOn(src)
rpc := new(RPC)
p.next()
err := rpc.parse(p)
if err != nil {
t.Fatal(err)
}
if got, want := len(rpc.Elements), 1; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
opt := rpc.Elements[0].(*Option)
if got, want := len(opt.AggregatedConstants), 2; got != want {
t.Fatalf("got [%v] want [%v]", got, want)
}
if got, want := opt.AggregatedConstants[0].Name, "post"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := opt.AggregatedConstants[1].Name, "body"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := opt.AggregatedConstants[1].Source, "*"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
}

0 comments on commit ef198d8

Please sign in to comment.