ast

package
v0.0.0-...-f3d8a94 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2018 License: MIT Imports: 3 Imported by: 0

README

** myitcv.io/g/protobuf/ast ** has moved

The repository hosting myitcv.io/g/protobuf/ast has changed.

myitcv.io/g/protobuf/ast can now be found at:

https://github.com/myitcv/x/tree/master/g/protobuf/ast

Documentation

Overview

Package ast defines the AST data structures used by gotoc.

Index

Constants

This section is empty.

Variables

View Source
var FieldTypeMap = map[FieldType]string{
	Double:   "double",
	Float:    "float",
	Int64:    "int64",
	Uint64:   "uint64",
	Int32:    "int32",
	Fixed64:  "fixed64",
	Fixed32:  "fixed32",
	Bool:     "bool",
	String:   "string",
	Bytes:    "bytes",
	Uint32:   "uint32",
	Sfixed32: "sfixed32",
	Sfixed64: "sfixed64",
	Sint32:   "sint32",
	Sint64:   "sint64",
}

Functions

func Walk

func Walk(v Visitor, n Node)

func WalkFile

func WalkFile(v Visitor, f *File)

Types

type Comment

type Comment struct {
	Start, End Position // position of first and last "//"
	Text       []string
}

Comment represents a comment.

func InlineComment

func InlineComment(n Node) *Comment

InlineComment returns the comment on the same line as a node, or nil if there's no inline comment. The returned comment is guaranteed to be a single line.

func LeadingComment

func LeadingComment(n Node) *Comment

LeadingComment returns the comment that immediately precedes a node, or nil if there's no such comment.

func (*Comment) Pos

func (c *Comment) Pos() Position

type Enum

type Enum struct {
	Position Position // position of "enum" token
	Name     string
	Values   []*EnumValue

	Up FileOrMessage // either *File or *Message
}

func (*Enum) File

func (enum *Enum) File() *File

func (*Enum) Pos

func (enum *Enum) Pos() Position

type EnumValue

type EnumValue struct {
	Position Position // position of Name
	Name     string
	Number   int32

	Up *Enum
}

func (*EnumValue) File

func (ev *EnumValue) File() *File

func (*EnumValue) Pos

func (ev *EnumValue) Pos() Position

type Extension

type Extension struct {
	Position Position // position of the "extend" token

	Extendee     string   // the thing being extended
	ExtendeeType *Message // set during resolution

	Fields []*Field

	Up FileOrMessage // either *File or *Message or ...
}

Extension represents an extension definition.

func (*Extension) File

func (e *Extension) File() *File

func (*Extension) Pos

func (e *Extension) Pos() Position

type Field

type Field struct {
	Position Position // position of "required"/"optional"/"repeated"/type

	// TypeName is the raw name parsed from the input.
	// Type is set during resolution; it will be a FieldType, *Message or *Enum.
	TypeName string
	Type     interface{}

	// For a map field, the TypeName/Type fields are the value type,
	// and KeyTypeName/KeyType will be set.
	KeyTypeName string
	KeyType     FieldType

	// At most one of {required,repeated} is set.
	Required bool
	Repeated bool
	Name     string
	Tag      int

	HasDefault bool
	Default    string // e.g. "foo", 7, true

	HasPacked bool
	Packed    bool

	HasDeprecated bool
	Deprecated    bool

	Options [][2]string // slice of key/value pairs

	Oneof *Oneof

	Up MessageOrExtension // either *Message or *Extension
}

Field represents a field in a message.

func (*Field) File

func (f *Field) File() *File

func (*Field) Pos

func (f *Field) Pos() Position

type FieldType

type FieldType int8
const (
	Double FieldType
	Float
	Int64
	Uint64
	Int32
	Fixed64
	Fixed32
	Bool
	String
	Bytes
	Uint32
	Sfixed32
	Sfixed64
	Sint32
	Sint64
)

func (FieldType) IsValid

func (ft FieldType) IsValid() bool

func (FieldType) String

func (ft FieldType) String() string

type File

type File struct {
	Name    string // filename
	Syntax  string // "proto2" or "proto3"
	Package []string
	Options [][2]string // slice of key/value pairs

	Imports       []string
	PublicImports []int // list of indexes in the Imports slice

	Messages   []*Message   // top-level messages
	Enums      []*Enum      // top-level enums
	Services   []*Service   // services
	Extensions []*Extension // top-level extensions

	Comments []*Comment // all the comments for this file, sorted by position
}

File represents a single proto file.

func (*File) Nodes

func (f *File) Nodes() []Node

type FileOrMessage

type FileOrMessage interface {
	FileOrNode
	// contains filtered or unexported methods
}

type FileOrNode

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

type FileSet

type FileSet struct {
	Files []*File
}

FileSet describes a set of proto files.

type Message

type Message struct {
	Position       Position // position of the "message" token
	Name           string
	Group          bool
	Fields         []*Field
	Extensions     []*Extension
	Oneofs         []*Oneof
	ReservedFields []Reserved
	Options        [][2]string

	Messages []*Message // includes groups
	Enums    []*Enum

	ExtensionRanges [][2]int // extension ranges (inclusive at both ends)

	Up FileOrMessage // either *File or *Message
}

Message represents a proto message.

func (*Message) File

func (m *Message) File() *File

func (*Message) Nodes

func (m *Message) Nodes() []Node

Nodes returns a slice of the Nodes contained within this message definition i.e. all the fields, enums etc, sorted by their Position.Offset

func (*Message) Pos

func (m *Message) Pos() Position

type MessageOrExtension

type MessageOrExtension interface {
	FileOrNode
	// contains filtered or unexported methods
}

type MessageOrField

type MessageOrField interface {
	FileOrNode
	// contains filtered or unexported methods
}

type Method

type Method struct {
	Position Position // position of the "rpc" token
	Name     string

	// InTypeName/OutTypeName are the raw names parsed from the input.
	// InType/OutType is set during resolution; it will be a *Message.
	InTypeName, OutTypeName string
	InType, OutType         interface{}

	// TODO: support streaming methods
	Options [][2]string // slice of key/value pairs

	Up *Service
}

Method represents an RPC method.

func (*Method) File

func (m *Method) File() *File

func (*Method) Pos

func (m *Method) Pos() Position

type Node

type Node interface {
	FileOrNode
	Pos() Position
	File() *File
}

Node is implemented by concrete types that represent things appearing in a proto file.

type NodeSort

type NodeSort []Node

func (NodeSort) Len

func (a NodeSort) Len() int

func (NodeSort) Less

func (a NodeSort) Less(i, j int) bool

func (NodeSort) Swap

func (a NodeSort) Swap(i, j int)

type Oneof

type Oneof struct {
	Position Position // position of "oneof" token
	Name     string

	Up *Message
}

Oneof represents a oneof bracketing a set of fields in a message.

func (*Oneof) File

func (o *Oneof) File() *File

func (*Oneof) Pos

func (o *Oneof) Pos() Position

type Position

type Position struct {
	Line   int // 1-based line number
	Offset int // 0-based byte offset
}

Position describes a source position in an input file. It is only valid if the line number is positive.

func (Position) Before

func (pos Position) Before(other Position) bool

func (Position) IsValid

func (pos Position) IsValid() bool

func (Position) String

func (pos Position) String() string

type Reserved

type Reserved struct {
	Name       string
	Start, End int
}

type Service

type Service struct {
	Position Position // position of the "service" token
	Name     string

	Methods []*Method

	Up *File
}

Service represents an RPC service.

func (*Service) File

func (s *Service) File() *File

func (*Service) Pos

func (s *Service) Pos() Position

type Visitor

type Visitor interface {
	Visit(node Node) (w Visitor)
}

Jump to

Keyboard shortcuts

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