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

Commit

Permalink
add example to unformatted, begin change parse rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernest Micklei committed Mar 9, 2017
1 parent 8dee635 commit 94eb556
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
7 changes: 6 additions & 1 deletion cmd/protofmt/unformatted.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ extensions 100 to 199; // no 200

service SearchService { // comment
rpc Search ( SearchRequest ) returns ( SearchResponse ); // Search
rpc Find ( Finder ) returns ( stream Result ); // Find
rpc Find ( Finder ) returns ( stream Result ) { // Find
option (google.api.http) = {
post: "/v1/example/echo"
body: "*"
};
}
}

// emptiness
Expand Down
35 changes: 31 additions & 4 deletions service.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// Copyright (c) 2017 Ernest Micklei
//
//
// MIT License
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand Down Expand Up @@ -89,6 +89,7 @@ type RPC struct {
ReturnsType string
StreamsReturns bool
Comment *Comment
Options []*Option
}

// Accept dispatches the call to the visitor.
Expand Down Expand Up @@ -177,5 +178,31 @@ func (r *RPC) parse(p *Parser) error {
if tok != tRIGHTPAREN {
return p.unexpected(lit, "rpc type closing )", r)
}
tok, lit = p.scanIgnoreWhitespace()
if tSEMICOLON == tok {
p.s.unread(';') // allow for inline comment parsing
return nil
}
if tLEFTCURLY == tok {
// parse options
for {
tok, lit = p.scanIgnoreWhitespace()
if tRIGHTCURLY == tok {
break
}
if tCOMMENT == tok {
// TODO put comment in the next option
continue
}
if tOPTION != tok {
return p.unexpected(lit, "rpc option", r)
}
o := new(Option)
if err := o.parse(p); err != nil {
return err
}
r.Options = append(r.Options, o)
}
}
return nil
}

0 comments on commit 94eb556

Please sign in to comment.