ast

package
v0.0.0-...-5aebcfc Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2016 License: BSD-3-Clause Imports: 3 Imported by: 1

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

This section is empty.

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 interface{} // 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 interface{} // 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

	Oneof *Oneof

	Up Node // 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.

type FileSet

type FileSet struct {
	// Files is sorted in topological order, bottom up.
	// That means that a file X will only import a file Y
	// if Y occurs in this slice before X.
	Files []*File
}

FileSet describes a set of proto files.

func (*FileSet) Sort

func (fs *FileSet) Sort()

Sort sorts fs.Files topologically.

type Message

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

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

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

	Up interface{} // either *File or *Message
}

Message represents a proto message.

func (*Message) File

func (m *Message) File() *File

func (*Message) Pos

func (m *Message) Pos() Position

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{}

	// ClientStreaming and ServerStreaming indicate whether the argument and
	// return value to the rpc are streams.
	ClientStreaming, ServerStreaming bool

	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 {
	Pos() Position
	File() *File
}

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

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.

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

Jump to

Keyboard shortcuts

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