pbast

package module
v0.0.0-...-caac6ab Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

pbast Build Status

Simple AST library for Protocol Buffers (proto3) in Golang

Description

This package provides constructs defined Protocol Buffers Version 3 Language Specification. It is designed to create a Protocol Buffers' AST by those constructs, but not designed to parse ".proto" files. One of the typical use cases is builing a Protocol Buffers' AST when transforming an AST defined for a different language. printer sub-package allows us to output an AST to io.Writer in Protocol Buffers' file format.

Install

This package is "go gettable".

go get github.com/oshothebig/pbast

Reference

License

Apache License Version 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSameType

func IsSameType(t1, t2 Type) bool

func NewDecorateWriter

func NewDecorateWriter(w io.Writer, prefix, postfix string) io.Writer

func NewSpaceWriter

func NewSpaceWriter(w io.Writer, count int) io.Writer

func NewTabWriter

func NewTabWriter(w io.Writer) io.Writer

Types

type BuiltinType

type BuiltinType string
const (
	Double   BuiltinType = "double"
	Float    BuiltinType = "float"
	Int32    BuiltinType = "int32"
	Int64    BuiltinType = "int64"
	UInt32   BuiltinType = "uint32"
	UInt64   BuiltinType = "uint64"
	SInt32   BuiltinType = "sint32"
	SInt64   BuiltinType = "sint64"
	Fixed32  BuiltinType = "fixed32"
	Fixed64  BuiltinType = "fixed64"
	SFixed32 BuiltinType = "sfixed32"
	SFixed64 BuiltinType = "sfixed64"
	Bool     BuiltinType = "bool"
	String   BuiltinType = "string"
	Bytes    BuiltinType = "bytes"
)

func (BuiltinType) TypeName

func (t BuiltinType) TypeName() string

type Comment

type Comment []string

func (Comment) String

func (c Comment) String() string

type Enum

type Enum struct {
	Name    string       `json:"name"`
	Options []*Option    `json:"options"`
	Comment Comment      `json:"comment"`
	Fields  []*EnumField `json:"fields"`
}

func NewEnum

func NewEnum(name string) *Enum

func (*Enum) AddField

func (e *Enum) AddField(f *EnumField) *Enum

func (*Enum) AddOption

func (e *Enum) AddOption(o *Option) *Enum

func (Enum) TypeName

func (e Enum) TypeName() string

type EnumField

type EnumField struct {
	Name    string             `json:"name"`
	Index   int                `json:"index"`
	Comment []string           `json:"comment"`
	Options []*EnumValueOption `json:"option"`
}

func NewEnumField

func NewEnumField(name string, index int) *EnumField

func (*EnumField) AddOption

func (f *EnumField) AddOption(o *EnumValueOption) *EnumField

type EnumValueOption

type EnumValueOption struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

func NewEnumValueOption

func NewEnumValueOption(name, value string) *EnumValueOption

type FieldOption

type FieldOption struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

func NewFieldOption

func NewFieldOption(name, value string) *FieldOption

type File

type File struct {
	Syntax   Syntax     `json:"-"`
	Package  Package    `json:"package"`
	Comment  Comment    `json:"comment"`
	Imports  []*Import  `json:"imports"`
	Options  []*Option  `json:"options"`
	Messages []*Message `json:"messages"`
	Enums    []*Enum    `json:"enums"`
	Services []*Service `json:"services"`
}

func NewFile

func NewFile(p Package) *File

func (*File) AddEnum

func (f *File) AddEnum(e *Enum) *File

func (*File) AddImport

func (f *File) AddImport(i *Import) *File

func (*File) AddMessage

func (f *File) AddMessage(m *Message) *File

func (*File) AddOption

func (f *File) AddOption(o *Option) *File

func (*File) AddService

func (f *File) AddService(s *Service) *File

func (*File) AddType

func (f *File) AddType(t Type)

type Import

type Import struct {
	Name       string
	Visibility Visibility
}

func NewImport

func NewImport(name string) *Import

func NewPublicImport

func NewPublicImport(name string) *Import

func NewWeakImport

func NewWeakImport(name string) *Import

type Message

type Message struct {
	Name     string          `json:"name"`
	Comment  Comment         `json:"comment"`
	Fields   []*MessageField `json:"fields"`
	Enums    []*Enum         `json:"enums"`
	Messages []*Message      `json:"messages"`
	OneOfs   []*OneOf        `json:"oneOfs"`
}

func NewMessage

func NewMessage(name string) *Message

func (*Message) AddEnum

func (m *Message) AddEnum(e *Enum) *Message

func (*Message) AddField

func (m *Message) AddField(f *MessageField) *Message

func (*Message) AddMessage

func (m *Message) AddMessage(n *Message) *Message

func (*Message) AddOneOf

func (m *Message) AddOneOf(o *OneOf) *Message

func (*Message) AddType

func (m *Message) AddType(t Type)

func (Message) TypeName

func (e Message) TypeName() string

type MessageField

type MessageField struct {
	Repeated bool           `json:"repeated"`
	Type     string         `json:"type"`
	Name     string         `json:"name"`
	Index    int            `json:"index"`
	Options  []*FieldOption `json:"options"`
	Comment  Comment        `json:"comment"`
}

func NewMessageField

func NewMessageField(t Type, name string, index int) *MessageField

func NewRepeatedMessageField

func NewRepeatedMessageField(t Type, name string, index int) *MessageField

func (*MessageField) AddOption

func (f *MessageField) AddOption(o *FieldOption) *MessageField

type Node

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

Node represents a node in an abstract syntax tree

type OneOf

type OneOf struct {
	Name    string        `json:"name"`
	Comment Comment       `json:"comment"`
	Fields  []*OneOfField `json:"fields"`
}

func NewOneOf

func NewOneOf(name string) *OneOf

func (*OneOf) AddField

func (o *OneOf) AddField(f *OneOfField) *OneOf

type OneOfField

type OneOfField struct {
	Type    string    `json:"type"`
	Name    string    `json:"name"`
	Index   int       `json:"index"`
	Comment Comment   `json:"comment"`
	Options []*Option `json:"options"`
}

func NewOneOfField

func NewOneOfField(t Type, name string, index int) *OneOfField

func (*OneOfField) AddOption

func (f *OneOfField) AddOption(o *Option) *OneOfField

type Option

type Option struct {
	Name string `json:"name"`
	// TODO: Revisit for type safety
	Value string `json:"value"`
}

func NewOption

func NewOption(name, value string) *Option

type Package

type Package string

func NewPackage

func NewPackage(name string) Package

type RPC

type RPC struct {
	Name    string
	Comment Comment
	Input   *ReturnType
	Output  *ReturnType
	Options []*Option
}

func NewRPC

func NewRPC(name string, input *ReturnType, output *ReturnType) *RPC

func (*RPC) AddOption

func (r *RPC) AddOption(o *Option) *RPC

type ReturnType

type ReturnType struct {
	Name       string
	Streamable bool
}

func NewReturnType

func NewReturnType(name string) *ReturnType

func (*ReturnType) SetStreamable

func (r *ReturnType) SetStreamable(s bool) *ReturnType

type Service

type Service struct {
	Name    string
	Comment Comment
	Options []*Option
	RPCs    []*RPC
}

func NewService

func NewService(name string) *Service

func (*Service) AddOptions

func (s *Service) AddOptions(o *Option) *Service

func (*Service) AddRPC

func (s *Service) AddRPC(r *RPC) *Service

type Syntax

type Syntax struct{}

func (Syntax) String

func (Syntax) String() string

type Type

type Type interface {
	TypeName() string
}

type TypeAdder

type TypeAdder interface {
	AddType(Type)
}

type Visibility

type Visibility int
const (
	NotSpecified Visibility = iota
	Weak
	Public
)

func (Visibility) String

func (v Visibility) String() string

type WellKnownType

type WellKnownType string
const (
	Any             WellKnownType = "google.protobuf.Any"
	Api             WellKnownType = "google.protobuf.Api"
	BoolValue       WellKnownType = "google.protobuf.BoolValue"
	BytesValue      WellKnownType = "google.protobuf.BytesValue"
	DoubleValue     WellKnownType = "google.protobuf.DoubleValue"
	Duration        WellKnownType = "google.protobuf.Duration"
	Empty           WellKnownType = "google.protobuf.Empty"
	WellKnownEnum   WellKnownType = "google.protobuf.Enum"
	EnumValue       WellKnownType = "google.protobuf.EnumValue"
	WellKnownField  WellKnownType = "google.protobuf.Field"
	Cardinality     WellKnownType = "google.protobuf.Cardinality"
	Kind            WellKnownType = "google.protobuf.Kind"
	FieldMask       WellKnownType = "google.protobuf.FieldMask"
	FloatValue      WellKnownType = "google.protobuf.FloatValue"
	Int32Value      WellKnownType = "google.protobuf.Int32Value"
	Int64Value      WellKnownType = "google.protobuf.Int64Value"
	ListValue       WellKnownType = "google.protobuf.ListValue"
	Method          WellKnownType = "google.protobuf.Method"
	Mixin           WellKnownType = "google.protobuf.Mixin"
	NullValue       WellKnownType = "google.protobuf.NullValue"
	WellKnownOption WellKnownType = "google.protobuf.Option"
	SourceContext   WellKnownType = "google.protobuf.SourceContext"
	StringValue     WellKnownType = "google.protobuf.StringValue"
	WellKnownStruct WellKnownType = "google.protobuf.Struct"
	WellKnownSyntax WellKnownType = "google.protobuf.Syntax"
	Timestamp       WellKnownType = "google.protobuf.Timestamp"
	UInt32Value     WellKnownType = "google.protobuf.UInt32Value"
	UInt64Value     WellKnownType = "google.protobuf.UInt64Value"
	Value           WellKnownType = "google.protobuf.Value"
)

func (WellKnownType) TypeName

func (t WellKnownType) TypeName() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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