This repository has been archived by the owner on Jan 5, 2019. It is now read-only.
forked from emicklei/proto
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring, better line count, begin with visitor, travis
- Loading branch information
Ernest Micklei
authored and
Ernest Micklei
committed
Jan 28, 2017
1 parent
1c16ca7
commit 768352c
Showing
19 changed files
with
205 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: go | ||
|
||
go: | ||
- 1.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# proto3 | ||
|
||
Package for parsing Google Protocol Buffers [.proto files version 3] (https://developers.google.com/protocol-buffers/docs/reference/proto3-spec) | ||
[](https://travis-ci.org/emicklei/proto3) | ||
|
||
Package in Go for parsing Google Protocol Buffers [.proto files version 3] (https://developers.google.com/protocol-buffers/docs/reference/proto3-spec) | ||
|
||
### install | ||
|
||
go get -u -v github.com/emicklei/proto | ||
|
||
(c) 2017, ernestmicklei.com. MIT License. Contributions welcome. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
syntax = "proto3"; | ||
|
||
import "google/protobuf/any.proto"; | ||
import "testdata/test.proto"; | ||
|
||
package proto3_proto; | ||
|
||
message Message { | ||
enum Humour { | ||
UNKNOWN = 0; | ||
PUNS = 1; | ||
SLAPSTICK = 2; | ||
BILL_BAILEY = 3; | ||
} | ||
|
||
string name = 1; | ||
Humour hilarity = 2; | ||
uint32 height_in_cm = 3; | ||
bytes data = 4; | ||
int64 result_count = 7; | ||
bool true_scotsman = 8; | ||
float score = 9; | ||
|
||
repeated uint64 key = 5; | ||
repeated int32 short_key = 19; | ||
Nested nested = 6; | ||
repeated Humour r_funny = 16; | ||
|
||
map<string, Nested> terrain = 10; | ||
testdata.SubDefaults proto2_field = 11; | ||
map<string, testdata.SubDefaults> proto2_value = 13; | ||
|
||
google.protobuf.Any anything = 14; | ||
repeated google.protobuf.Any many_things = 15; | ||
|
||
Message submessage = 17; | ||
repeated Message children = 18; | ||
} | ||
|
||
message Nested { | ||
string bunny = 1; | ||
bool cute = 2; | ||
} | ||
|
||
message MessageWithMap { | ||
map<bool, bytes> byte_mapping = 1; | ||
} | ||
|
||
|
||
message IntMap { | ||
map<int32, int32> rtt = 1; | ||
} | ||
|
||
message IntMaps { | ||
repeated IntMap maps = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"github.com/emicklei/proto3" | ||
) | ||
|
||
func main() { | ||
p := proto3.NewParser(os.Stdin) | ||
def, err := p.Parse() | ||
if err != nil { | ||
log.Fatalln("proto3fmt failed:", p.Line(), err) | ||
} | ||
log.Printf("%#v", def) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,28 @@ | ||
package proto3 | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
import "fmt" | ||
|
||
// Import holds a filename to another .proto definition. | ||
type Import struct { | ||
Line int | ||
Filename string | ||
Kind string // weak, public | ||
Kind string // weak, public, <empty> | ||
} | ||
|
||
func (i *Import) parse(p *Parser) error { | ||
tok, lit := p.scanIgnoreWhitespace() | ||
if tok != IDENT || !strings.Contains("weak public", lit) { | ||
return fmt.Errorf("found %q, expected kind (weak|public)", lit) | ||
} | ||
i.Line = p.s.line | ||
i.Kind = lit | ||
tok, lit = p.scanIgnoreWhitespace() | ||
if tok != QUOTE { | ||
return fmt.Errorf("found %q, expected \"", lit) | ||
} | ||
name := p.s.scanUntil('"') | ||
if len(name) == 0 { | ||
return fmt.Errorf("unexpected end of quoted string") | ||
switch tok { | ||
case WEAK: | ||
i.Kind = lit | ||
return i.parse(p) | ||
case PUBLIC: | ||
i.Kind = lit | ||
return i.parse(p) | ||
case QUOTE: | ||
i.Filename = p.s.scanUntil('"') | ||
default: | ||
return fmt.Errorf("found %q, expected weak|public|quoted identifier", lit) | ||
} | ||
i.Filename = name | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
package proto3 | ||
|
||
// Package specifies the namespace for all proto elements. | ||
type Package struct { | ||
Name string | ||
} | ||
|
||
func (a *Package) parse(p *Parser) error { | ||
// accept dispatches the call to the visitor. | ||
func (p *Package) accept(v Visitor) { | ||
v.VisitPackage(p) | ||
} | ||
|
||
func (p *Package) parse(pr *Parser) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.