Last active
August 26, 2023 19:54
-
-
Save xuwei-k/90d37c325dec81348e36 to your computer and use it in GitHub Desktop.
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" … "Z" | "a" … "z" | |
capitalLetter = "A" … "Z" | |
decimalDigit = "0" … "9" | |
octalDigit = "0" … "7" | |
hexDigit = "0" … "9" | "A" … "F" | "a" … "f" | |
ident = letter { letter | unicodeDigit | "_" } | |
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 ] | |
decimals = decimalDigit { decimalDigit } | |
exponent = ( "e" | "E" ) [ "+" | "-" ]decimals | |
boolLit = "true" | "false" | |
strLit = ("`" { charValue } "`") | (`"` { charValue } `"`) | |
charValue = hexEscape | octEscape | charEscape | /[^\0\n\\]/ | |
hexEscape = `\` ("x" | "X") hexDigit hexDigit | |
octEscape = `\` octalDigit octalDigit octalDigit | |
charEscape = `\` ( "a" | "b" | "f" | "n" | "r" | "t" | "v" | `\` | "'" | `"` ) | |
quote = "`"|`"` | |
emptyStatement = ";" | |
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 ";" | |
keyType = "int32" | "int64" | "uint32" | "uint64" | "sint32" | "sint64" | | |
"fixed32" | "fixed64" | "sfixed32" | "sfixed64" | "bool" | "string" | |
reserved = "reserved" ( ranges | fieldNames) ";" | |
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 | stream | 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