forked from itod/parsekit
/
proto.grammar
93 lines (64 loc) · 3.33 KB
/
proto.grammar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// proto ::= ( message | extend | enum | import | package | option | ";" )*
proto = ( message | extend | enum | import | package | option | ";" )*;
// import ::= "import" strLit ";"
import = "import" strLit ";";
// package ::= "package" ident ";"
package = "package" ident ";";
// option ::= "option" optionBody ";"
option = "option" optionBody ";";
// optionBody ::= ident ( "." ident )* "=" constant
optionBody = ident ( "." ident )* "=" constant;
// message ::= "message" ident messageBody
message = "message" ident messageBody;
// extend ::= "extend" userType messageBody
extend = "extend" userType messageBody;
// enum ::= "enum" ident "{" ( option | enumField | ";" )* "}"
enum = "enum" ident "{" ( option | enumField | ";" )* "}";
// enumField ::= ident "=" intLit ";"
enumField = ident "=" intLit ";";
// service ::= "service" ident "{" ( option | rpc | ";" )* "}"
service = "service" ident "{" ( option | rpc | ";" )* "}";
// rpc ::= "rpc" ident "(" userType ")" "returns" "(" userType ")" ";"
rpc = "rpc" ident "(" userType ")" "returns" "(" userType ")" ";";
// messageBody ::= "{" ( field | enum | message | extend | extensions | group | option | ":" )* "}"
messageBody = "{" ( field | enum | message | extend | extensions | group | option | ":" )* "}";
// group ::= modifier "group" camelIdent "=" intLit messageBody
group = modifier "group" camelIdent "=" intLit messageBody;
// // tag number must be 2^28-1 or lower
// field ::= modifier type ident "=" intLit ( "[" fieldOption ( "," fieldOption )* "]" )? ";"
field = modifier type ident "=" intLit ( "[" fieldOption ( "," fieldOption )* "]" )? ";";
// fieldOption ::= optionBody | "default" "=" constant
fieldOption = optionBody | "default" "=" constant;
// extensions ::= "extensions" intLit "to" ( intLit | "max" ) ";"
extensions = "extensions" intLit "to" ( intLit | "max" ) ";";
// modifier ::= "required" | "optional" | "repeated"
modifier ::= "required" | "optional" | "repeated";
// type ::= "double" | "float" | "int32" | "int64" | "uint32" | "uint64" | "sint32" | "sint64" | "fixed32" | "fixed64" | "sfixed32" | "sfixed64" | "bool" | "string" | "bytes" | userType
type = "double" | "float" | "int32" | "int64" | "uint32" | "uint64" | "sint32" | "sint64" | "fixed32" | "fixed64" | "sfixed32" | "sfixed64" | "bool" | "string" | "bytes" | userType;
// // leading dot for identifiers means they're fully qualified
// userType ::= ( "."? ident )+
userType = ( "."? ident )+;
// constant ::= ident | intLit | floatLit | strLit | boolLit
constant = ident | numLit | strLit | boolLit;
// ident ::= /[A-Za-z_][\w_]*/
ident = /[A-Za-z_][\w_]*/;
// // according to parser.cc, group names must start with a capital letter as a
// // hack for backwards-compatibility
// camelIdent ::= /[A-Z][\w_]*/
camelIdent = /[A-Z][\w_]*/;
// intLit ::= decInt | hexInt | octInt
// decInt ::= /\d+/
// hexInt ::= /0[xX]([A-Fa-f0-9])+/
// octInt ::= /0[0-7]+/
// floatLit ::= /\d+(\.\d+)?([Ee][\+-]?\d+)?/ // allow_f_after_float_ is
numLit = Number;
// disabled by default in tokenizer.cc
// boolLit ::= "true" | "false"
boolLit = "true" | "false";
// strLit ::= quote ( hexEscape | octEscape | charEscape | /[^\0\n]/ )*
strLit = QuotedString;
// quote
// quote ::= /["']/
// hexEscape ::= /\\[Xx][A-Fa-f0-9]{1,2}/
// octEscape ::= /\\0?[0-7]{1,3}/
// charEscape ::= /\\[abfnrtv\\\?'"]/