std/protoparse
On this page
Index
- type
ParseErr - type
Kind - type
Token - type
Field - type
EnumValue - type
Enum - type
Message - type
Rpc - type
Service - type
File - fn
tokens - fn
parse - fn
gen
Types
ParseErr
struct ParseErr {
line: Int
col: Int
msg: Str
} derive DisplayWhere and why a parse failed; the position is 1 based.
Kind
enum Kind {
Ident
Int
Float
Str
Sym
}A token kind: an identifier (dots allowed inside, as in foo.Bar), an integer, a float, a
string literal (unquoted, escapes decoded), or one symbol character.
Token
struct Token {
kind: Kind
text: Str
line: Int
col: Int
}Field
struct Field {
name: Str
num: Int
typ: Str
key: Str
repeated: Bool
optional: Bool
required: Bool
oneof: Str
}A field of a message. typ is the type as written (int32, Other.Msg); for a map it is the
value type and key the key type. oneof names the oneof it belongs to, or is empty.
EnumValue
struct EnumValue {
name: Str
num: Int
}Enum
struct Enum {
name: Str
values: List[EnumValue]
}Message
struct Message {
name: Str
fields: List[Field]
oneofs: List[Str]
nested: List[Message]
enums: List[Enum]
}Rpc
struct Rpc {
name: Str
req: Str
resp: Str
client_stream: Bool
server_stream: Bool
}Service
struct Service {
name: Str
rpcs: List[Rpc]
}File
struct File {
syntax: Str
package: Str
imports: List[Str]
messages: List[Message]
enums: List[Enum]
services: List[Service]
}Functions
tokens
fn tokens(src: Str) -> List[Token] ! ParseErrThe tokens of src without comments (// and /* */). A token never spans lines except
inside a comment.
parse
fn parse(src: Str) -> File ! ParseErrParses a proto3 or proto2 file. Options, reserved, extensions, field options (including
default) and extend blocks are read and dropped. In proto2 every field outside a oneof needs a
label (required, optional or repeated); a group becomes a nested message and a field of
that type named in lower case. A proto3 file rejects required and group.
gen
fn gen(f: File) -> Str ! ParseErrXo source for the messages, enums and oneofs of f, using derive Proto (decision 0530):
a nested type Inner of Outer becomes OuterInner, a oneof kind of Msg the enum
MsgKind held in an optional field marked proto "oneof", an enum an open Int enum with a
catch-all Other(v: Int). Fields keep their proto names. Services are not generated here.