Skip to content

Instantly share code, notes, and snippets.

@angrypie
Created May 7, 2020 11:44
Show Gist options
  • Save angrypie/aae8ea1b53e53187b32eade411bb735a to your computer and use it in GitHub Desktop.
Save angrypie/aae8ea1b53e53187b32eade411bb735a to your computer and use it in GitHub Desktop.
letter = "A" … "Z" | "a" … "z" .
decimalDigit = "0" … "9" .
octalDigit = "0" … "7" .
hexDigit = "0" … "9" | "A" … "F" | "a" … "f" .
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" … "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 .
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 "{" { option | 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