-
Notifications
You must be signed in to change notification settings - Fork 4
/
protobuf.ebnf
79 lines (46 loc) · 2.05 KB
/
protobuf.ebnf
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
Protobuf's language EBNF grammar by Alek Strom obtained from:
http://groups.google.com/group/protobuf/browse_thread/thread/1cccfc624cd612da
proto ::= ( message | extend | enum | import | package | option | ";" )*
import ::= "import" strLit ";"
package ::= "package" ident ";"
option ::= "option" optionBody ";"
optionBody ::= ident ( "." ident )* "=" constant
message ::= "message" ident messageBody
extend ::= "extend" userType messageBody
enum ::= "enum" ident "{" ( option | enumField | ";" )* "}"
enumField ::= ident "=" intLit ";"
service ::= "service" ident "{" ( option | rpc | ";" )* "}"
rpc ::= "rpc" ident "(" userType ")" "returns" "(" userType ")" ";"
messageBody ::= "{" ( field | enum | message | extend | extensions |
group | option | ":" )* "}"
group ::= modifier "group" camelIdent "=" intLit messageBody
# tag number must be 2^28-1 or lower
field ::= modifier type ident "=" intLit ( "[" fieldOption ( ","
fieldOption )* "]" )? ";"
fieldOption ::= optionBody | "default" "=" constant
extensions ::= "extensions" intLit "to" ( intLit | "max" ) ";"
modifier ::= "required" | "optional" | "repeated"
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 )+
constant ::= ident | intLit | floatLit | strLit | boolLit
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_]*/
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
disabled by default in tokenizer.cc
boolLit ::= "true" | "false"
strLit ::= quote ( hexEscape | octEscape | charEscape | /[^\0\n]/ )*
quote
quote ::= /["']/
hexEscape ::= /\\[Xx][A-Fa-f0-9]{1,2}/
octEscape ::= /\\0?[0-7]{1,3}/
charEscape ::= /\\[abfnrtv\\\?'"]/