Xo is experimental. The source is now public on GitHub, or try Xo in your browser.
Menu · protoparse

Docs

std/protoparse

On this page

Index

Types

ParseErr

struct ParseErr {
  line: Int
  col: Int
  msg: Str
} derive Display

Where and why a parse failed; the position is 1 based.

Source: std/protoparse.xo:5

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.

Source: std/protoparse.xo:13

Token

struct Token {
  kind: Kind
  text: Str
  line: Int
  col: Int
}

Source: std/protoparse.xo:21

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.

Source: std/protoparse.xo:34

EnumValue

struct EnumValue {
  name: Str
  num: Int
}

Source: std/protoparse.xo:46

Enum

struct Enum {
  name: Str
  values: List[EnumValue]
}

Source: std/protoparse.xo:51

Message

struct Message {
  name: Str
  fields: List[Field]
  oneofs: List[Str]
  nested: List[Message]
  enums: List[Enum]
}

Source: std/protoparse.xo:56

Rpc

struct Rpc {
  name: Str
  req: Str
  resp: Str
  client_stream: Bool
  server_stream: Bool
}

Source: std/protoparse.xo:64

Service

struct Service {
  name: Str
  rpcs: List[Rpc]
}

Source: std/protoparse.xo:72

File

struct File {
  syntax: Str
  package: Str
  imports: List[Str]
  messages: List[Message]
  enums: List[Enum]
  services: List[Service]
}

Source: std/protoparse.xo:77

Functions

tokens

fn tokens(src: Str) -> List[Token] ! ParseErr

The tokens of src without comments (// and /* */). A token never spans lines except inside a comment.

Source: std/protoparse.xo:30

parse

fn parse(src: Str) -> File ! ParseErr

Parses 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.

Source: std/protoparse.xo:90

gen

fn gen(f: File) -> Str ! ParseErr

Xo 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.

Source: std/protoparse.xo:96

↑ index