parser

package
v0.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package parser contains a protobuf parser. nolint: govet, golint

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	Pos lexer.Position

	Elements []*Value `"[" [ @@ { [ "," ] @@ } ] "]"`
}

type Direct

type Direct struct {
	Pos lexer.Position

	Type *Type  `@@`
	Name string `@Ident`
	Tag  int    `"=" @Int`

	Options []*Option `[ "[" @@ { "," @@ } "]" ]`
}

type Entry

type Entry struct {
	Pos lexer.Position

	Syntax  string   `  "syntax" "=" @String`
	Package string   `| "package" @(Ident { "." Ident })`
	Import  string   `| "import" "public"? @String`
	Message *Message `| @@`
	Service *Service `| @@`
	Enum    *Enum    `| @@`
	Option  *Option  `| "option" @@`
	Extend  *Extend  `| @@`
}

type Enum

type Enum struct {
	Pos lexer.Position

	Name   string       `"enum" @Ident`
	Values []*EnumEntry `"{" { @@ { ";" } } "}"`
}

type EnumEntry

type EnumEntry struct {
	Pos lexer.Position

	Value    *EnumValue `  @@`
	Option   *Option    `| "option" @@`
	Reserved *Reserved  `| @@`
}

type EnumValue

type EnumValue struct {
	Pos lexer.Position

	Key   string `@Ident`
	Value int    `"=" @( [ "-" ] Int )`

	Options []*Option `[ "[" @@ { "," @@ } "]" ]`
}

type Extend

type Extend struct {
	Pos lexer.Position

	Reference string   `"extend" @("."? Ident { "." Ident })`
	Fields    []*Field `"{" { @@ [ ";" ] } "}"`
}

type Extensions

type Extensions struct {
	Pos lexer.Position

	Extensions []Range `"extensions" @@ { "," @@ }`
}

type Field

type Field struct {
	Pos lexer.Position

	Optional bool `[   @"optional"`
	Required bool `  | @"required"`
	Repeated bool `  | @"repeated" ]`

	Group  *Group  `( @@`
	Direct *Direct `| @@ )`
}

type Group

type Group struct {
	Pos lexer.Position

	Name    string          `"group" @Ident`
	Tag     int             `"=" @Int`
	Entries []*MessageEntry `"{" { @@ [ ";" ] } "}"`
}

type Map

type Map struct {
	Pos lexer.Position

	Entries []*MapEntry `"{" (@@ ("," | ";")?)* "}"`
}

type MapEntry

type MapEntry struct {
	Pos lexer.Position

	Key   *Value `@@`
	Value *Value `":" @@`
}

type MapType

type MapType struct {
	Pos lexer.Position

	Key   *Type `"map" "<" @@`
	Value *Type `"," @@ ">"`
}

type Message

type Message struct {
	Pos lexer.Position

	Name    string          `"message" @Ident`
	Entries []*MessageEntry `"{" { @@ } "}"`
}

type MessageEntry

type MessageEntry struct {
	Pos lexer.Position

	Enum       *Enum       `( @@`
	Option     *Option     ` | "option" @@`
	Message    *Message    ` | @@`
	Oneof      *Oneof      ` | @@`
	Extend     *Extend     ` | @@`
	Reserved   *Reserved   ` | @@`
	Extensions *Extensions ` | @@`
	Field      *Field      ` | @@ ) { ";" }`
}

type Method

type Method struct {
	Pos lexer.Position

	Name              string    `"rpc" @Ident`
	StreamingRequest  bool      `"(" [ @"stream" ]`
	Request           *Type     `    @@ ")"`
	StreamingResponse bool      `"returns" "(" [ @"stream" ]`
	Response          *Type     `              @@ ")"`
	Options           []*Option `[ "{" { "option" @@ ";" } "}" ]`
}

type Oneof

type Oneof struct {
	Pos lexer.Position

	Name    string        `"oneof" @Ident`
	Entries []*OneofEntry `"{" { @@ { ";" } } "}"`
}

type OneofEntry

type OneofEntry struct {
	Pos lexer.Position

	Field  *Field  `  @@`
	Option *Option `| "option" @@`
}

type Option

type Option struct {
	Pos lexer.Position

	Name  string  `( "(" @("."? Ident { "." Ident }) ")" | @("."? Ident { "." Ident }) )`
	Attr  *string `[ @("."? Ident { "." Ident }) ]`
	Value *Value  `"=" @@`
}

type Proto

type Proto struct {
	Pos lexer.Position

	Entries []*Entry `{ @@ { ";" } }`
}

func Parse

func Parse(r io.Reader) (*Proto, error)

Parse protobuf.

type Range

type Range struct {
	Ident string `  @String`
	Start int    `| ( @Int`
	End   *int   `  [ "to" ( @Int`
	Max   bool   `           | @"max" ) ] )`
}

type Reserved

type Reserved struct {
	Pos lexer.Position

	Reserved []Range `"reserved" @@ { "," @@ }`
}

type Scalar

type Scalar int
const (
	None Scalar = iota
	Double
	Float
	Int32
	Int64
	Uint32
	Uint64
	Sint32
	Sint64
	Fixed32
	Fixed64
	SFixed32
	SFixed64
	Bool
	String
	Bytes
)

func (Scalar) GoString

func (s Scalar) GoString() string

func (*Scalar) Parse

func (s *Scalar) Parse(lex *lexer.PeekingLexer) error

type Service

type Service struct {
	Pos lexer.Position

	Name  string          `"service" @Ident`
	Entry []*ServiceEntry `"{" { @@ [ ";" ] } "}"`
}

type ServiceEntry

type ServiceEntry struct {
	Pos lexer.Position

	Option *Option `  "option" @@`
	Method *Method `| @@`
}

type Type

type Type struct {
	Pos lexer.Position

	Scalar    Scalar   `  @@`
	Map       *MapType `| @@`
	Reference *string  `| @("."? Ident { "." Ident })`
}

type Value

type Value struct {
	Pos lexer.Position

	String    *string  `  @String`
	Number    *float64 `| ("-" | "+")? @(Float | "inf")`
	Int       *int64   `| ("-" | "+")? @Int`
	Bool      *bool    `| (@"true" | "false")`
	Reference *string  `| @("."? Ident { "." Ident })`
	Map       *Map     `| @@`
	Array     *Array   `| @@`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL