Created
August 18, 2017 07:20
-
-
Save bbss/153e050f44db294cf7af3afc9a2f9a10 to your computer and use it in GitHub Desktop.
Proto ebnf definition from https://developers.google.com/protocol-buffers/docs/reference/proto3-spec
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
letter = "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z" | "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" | |
decimalDigit = "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" | |
octalDigit = "0" "1" "2" "3" "4" "5" "6" "7" | |
hexDigit = "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" | "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z" | "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" | |
ident = letter { letter | decimalDigit | "_" } | |
fullIdent = ident { "." ident } | |
messageName = ident | |
enumName = ident | |
fieldName = ident | |
oneofName = ident | |
mapName = ident | |
serviceName = ident | |
rpcName = ident | |
messageType = [ "." ] { ident "." } messageName | |
enumType = [ "." ] { ident "." } enumName | |
intLit = decimalLit | octalLit | hexLit | |
decimalLit = ( "1" "2" "3" "4" "5" "6" "7" "8" "9" ) { decimalDigit } | |
octalLit = "0" { octalDigit } | |
hexLit = "0" ( "x" | "X" ) hexDigit { hexDigit } | |
floatLit = ( decimals "." [ decimals ] [ exponent ] | decimals exponent | "."decimals [ exponent ] ) | "inf" | "nan" | |
decimals = decimalDigit { decimalDigit } | |
exponent = ( "e" | "E" ) [ "+" | "-" ] decimals | |
boolLit = "true" | "false" | |
strLit = ( "'" { charValue } "'" ) | ( '"' { charValue } '"' ) | |
charValue = hexEscape | octEscape | charEscape | #"[0-9]" | |
hexEscape = '\\' ( "x" | "X" ) hexDigit hexDigit | |
octEscape = '\\' octalDigit octalDigit octalDigit | |
charEscape = '\\' ( "a" | "b" | "f" | "n" | "r" | "t" | "v" | '\\' | "'" | '"' ) | |
quote = "'" | '"' | |
emptyStatement = ";" | |
constant = fullIdent | ( [ "-" | "+" ] intLit ) | ( [ "-" | "+" ] floatLit ) | strLit | boolLit | |
syntax = "syntax" "=" quote "proto3" quote ";" | |
import = "import" [ "weak" | "public" ] strLit ";" | |
package = "package" fullIdent ";" | |
option = "option" optionName "=" constant ";" | |
optionName = ( ident | "(" fullIdent ")" ) { "." ident } | |
type = "double" | "float" | "int32" | "int64" | "uint32" | "uint64" | |
| "sint32" | "sint64" | "fixed32" | "fixed64" | "sfixed32" | "sfixed64" | |
| "bool" | "string" | "bytes" | messageType | enumType | |
fieldNumber = intLit; | |
field = [ "repeated" ] type fieldName "=" fieldNumber [ "[" fieldOptions "]" ] ";" | |
fieldOptions = fieldOption { "," fieldOption } | |
fieldOption = optionName "=" constant | |
oneof = "oneof" oneofName "{" { oneofField | emptyStatement } "}" | |
oneofField = type fieldName "=" fieldNumber [ "[" fieldOptions "]" ] ";" | |
mapField = "map" "<" keyType "," type ">" mapName "=" fieldNumber [ "[" fieldOptions "]" ] ";" | |
keyType = "int32" | "int64" | "uint32" | "uint64" | "sint32" | "sint64" | | |
"fixed32" | "fixed64" | "sfixed32" | "sfixed64" | "bool" | "string" | |
reserved = "reserved" ( ranges | fieldNames ) ";" | |
ranges = range { "," range } | |
range = intLit [ "to" ( intLit | "max" ) ] | |
fieldNames = fieldName { "," fieldName } | |
enum = "enum" enumName enumBody | |
enumBody = "{" { option | enumField | emptyStatement } "}" | |
enumField = ident "=" intLit [ "[" enumValueOption { "," enumValueOption } "]" ]";" | |
enumValueOption = optionName "=" constant | |
message = "message" messageName messageBody | |
messageBody = "{" { field | enum | message | option | oneof | mapField | | |
reserved | emptyStatement } "}" | |
service = "service" serviceName "{" { option | rpc | emptyStatement } "}" | |
rpc = "rpc" rpcName "(" [ "stream" ] messageType ")" "returns" "(" [ "stream" ] | |
messageType ")" (( "{" {option | emptyStatement } "}" ) | ";") | |
proto = syntax { import | package | option | topLevelDef | emptyStatement } | |
topLevelDef = message | enum | service | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment