parser

package
v0.0.0-...-020c65a Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 9 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

func Visit

func Visit(root Node, visit Visitor) error

Visit all nodes in the AST.

Types

type Array

type Array struct {
	Pos lexer.Position

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

type Boolean

type Boolean bool

func (*Boolean) Capture

func (b *Boolean) Capture(v []string) error

type Comment

type Comment struct {
	Pos lexer.Position

	Comment string `@Comment`
}

type Comments

type Comments struct {
	Pos lexer.Position

	Comments []*Comment `@@+`
}

type Direct

type Direct struct {
	Pos lexer.Position

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

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

type Entry

type Entry struct {
	Pos lexer.Position

	Comment *Comment `@@?`
	Package string   `( "package" @(Ident { "." Ident })`
	Import  *Import  `| @@`
	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

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

type EnumValue

type EnumValue struct {
	Pos lexer.Position

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

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

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" @@ { "," @@ }`
	Options    Options  `[ "[" @@ { "," @@ } "]" ]`
}

type Field

type Field struct {
	Pos lexer.Position

	Comments *Comments `@@?`

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

	Group  *Group  `( @@`
	Direct *Direct `| @@ ) ";"*`

	TrailingComments *Comments `@@?`
}

type Group

type Group struct {
	Pos lexer.Position

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

type Import

type Import struct {
	Public bool   `"import" @("public")?`
	Name   string `@String`
}

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

	Comment    *Comment    `@@`
	Enum       *Enum       `| @@`
	Option     *Option     `| "option" @@`
	Message    *Message    `| @@`
	Oneof      *OneOf      `| @@`
	Extend     *Extend     `| @@`
	Reserved   *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          `              @@ ")"`
	HasEntries        bool           `[ @"{" `
	Entries           []*MethodEntry `       { @@ [ ";" ] } "}" ]`
}

type MethodEntry

type MethodEntry struct {
	Pos lexer.Position

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

type Node

type Node interface {
	// contains filtered or unexported methods
}

type OneOf

type OneOf struct {
	Pos lexer.Position

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

type OneOfEntry

type OneOfEntry struct {
	Pos lexer.Position

	Comments *Comments `@@?`

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

type Option

type Option struct {
	Pos lexer.Position

	Comments *Comments `@@?`

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

type OptionName

type OptionName struct {
	Pos lexer.Position

	Name string `( @("."? "(" ("."? Ident { "." Ident }) ")") | @Ident ) "."?`
}

type Options

type Options []*Option

type Proto

type Proto struct {
	Pos lexer.Position

	Comments *Comments `@@?`

	Syntax  string   `("syntax" "=" @String ";")?`
	Entries []*Entry `{ @@ { ";" } }`
}

func Parse

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

Parse protobuf.

func ParseString

func ParseString(filename string, source string) (*Proto, error)

type ProtoText

type ProtoText struct {
	Pos lexer.Position

	Fields []*ProtoTextField `"{" ( @@ ( "," | ";" )? )* "}"`

	TrailingComments *Comments `@@?`
}

func (*ProtoText) String

func (p *ProtoText) String() string

type ProtoTextField

type ProtoTextField struct {
	Pos lexer.Position

	Comments *Comments `@@?`

	Name  string `(  @Ident`
	Type  string `  | "[" @("."? Ident { ("." | "/") Ident }) "]" )`
	Value *Value `( ":"? @@ )`
}

type Range

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

type Reserved

type Reserved struct {
	Pos lexer.Position

	Ranges     []*Range `@@ { "," @@ }`
	FieldNames []string `| @String { "," @String }`
}

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`
	Entries []*ServiceEntry `[ "{" { @@ [ ";" ] } "}" ]`
}

type ServiceEntry

type ServiceEntry struct {
	Pos lexer.Position

	Comment *Comment `@@`
	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    *big.Float `  | ("-" | "+")? (@Float | @Int)`
	Bool      *Boolean   `  | @("true"|"false")`
	Reference *string    `  | @("."? Ident { "." Ident })`
	ProtoText *ProtoText `  | @@`
	Array     *Array     `  | @@ )`

	TrailingComments *Comments `@@?`
}

func (*Value) ToString

func (v *Value) ToString() string

type Visitor

type Visitor func(node Node, next func() error) error

Visitor function.

Jump to

Keyboard shortcuts

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