parser

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: Apache-2.0 Imports: 13 Imported by: 55

Documentation

Overview

Package parser parses a thrift IDL file with its dependencies into an abstract syntax tree. The acceptable IDL grammar is defined in the 'thrift.peg' file.

Code generated by peg. DO NOT EDIT.

Index

Constants

View Source
const (
	STOP   = 0
	VOID   = 1
	BOOL   = 2
	BYTE   = 3
	I08    = 3
	DOUBLE = 4
	I16    = 6
	I32    = 8
	I64    = 10
	STRING = 11
	UTF7   = 11
	STRUCT = 12
	MAP    = 13
	SET    = 14
	LIST   = 15
	UTF8   = 16
	UTF16  = 17
	BINARY = 18

	UNKNOWN = 255
)

TType constants in the Thrift protocol.

View Source
const NOTSET = -999999

NOTSET is a value to express 'not set'.

Variables

View Source
var ConstTypedValue_Double_DEFAULT float64
View Source
var ConstTypedValue_Identifier_DEFAULT string
View Source
var ConstTypedValue_Int_DEFAULT int64
View Source
var ConstTypedValue_List_DEFAULT []*ConstValue
View Source
var ConstTypedValue_Literal_DEFAULT string
View Source
var ConstTypedValue_Map_DEFAULT []*MapConstValue
View Source
var Include_Used_DEFAULT bool
View Source
var Type_IsTypedef_DEFAULT bool

Functions

func CircleDetect

func CircleDetect(ast *Thrift) string

CircleDetect detects whether there is an include circle and return a string representing the loop. When no include circle is found, it returns an empty string.

func DetectKeyword added in v0.2.0

func DetectKeyword(t *Thrift) (warnings []string)

DetectKeyword detects if there is any identifier using a reserved word in common programming languages.

func Pretty added in v0.1.3

func Pretty(pretty bool) func(*ThriftIDL) error

func Size added in v0.1.3

func Size(size int) func(*ThriftIDL) error

func Typename2TypeID

func Typename2TypeID(name string) uint8

Typename2TypeID converts a TypeID name to its value.

Types

type Annotation added in v0.1.2

type Annotation struct {
	Key    string   `thrift:"Key,1" json:"Key"`
	Values []string `thrift:"Values,2" json:"Values"`
}

func NewAnnotation added in v0.1.2

func NewAnnotation() *Annotation

func (*Annotation) GetKey added in v0.1.2

func (p *Annotation) GetKey() (v string)

func (*Annotation) GetValues added in v0.1.2

func (p *Annotation) GetValues() (v []string)

func (*Annotation) String added in v0.1.2

func (p *Annotation) String() string

type Annotations added in v0.1.2

type Annotations []*Annotation

func (*Annotations) Append added in v0.1.2

func (a *Annotations) Append(key, value string)

Append append key value pair to Annotation slice.

func (*Annotations) Get added in v0.1.2

func (a *Annotations) Get(key string) []string

Get return annotations values.

type Category added in v0.1.2

type Category int64
const (
	Category_Constant  Category = 0
	Category_Bool      Category = 1
	Category_Byte      Category = 2
	Category_I16       Category = 3
	Category_I32       Category = 4
	Category_I64       Category = 5
	Category_Double    Category = 6
	Category_String    Category = 7
	Category_Binary    Category = 8
	Category_Map       Category = 9
	Category_List      Category = 10
	Category_Set       Category = 11
	Category_Enum      Category = 12
	Category_Struct    Category = 13
	Category_Union     Category = 14
	Category_Exception Category = 15
	Category_Typedef   Category = 16
	Category_Service   Category = 17
)

func CategoryFromString added in v0.1.2

func CategoryFromString(s string) (Category, error)

func CategoryPtr added in v0.1.2

func CategoryPtr(v Category) *Category

func (Category) IsBaseType added in v0.1.2

func (p Category) IsBaseType() bool

IsBaseType tells if the category is one of the basetypes.

func (Category) IsBinary added in v0.1.2

func (p Category) IsBinary() bool

IsBinary tells if the category is binary.

func (Category) IsBool added in v0.1.2

func (p Category) IsBool() bool

IsBool tells if the category is bool.

func (Category) IsByte added in v0.1.2

func (p Category) IsByte() bool

IsByte tells if the category is byte.

func (Category) IsConstant added in v0.1.2

func (p Category) IsConstant() bool

IsConstant tells if the category is constant.

func (Category) IsContainerType added in v0.1.2

func (p Category) IsContainerType() bool

IsContainerType tells if the category is one of the container types.

func (Category) IsDouble added in v0.1.2

func (p Category) IsDouble() bool

IsDouble tells if the category is double.

func (Category) IsEnum added in v0.1.2

func (p Category) IsEnum() bool

IsEnum tells if the category is enum.

func (Category) IsException added in v0.1.2

func (p Category) IsException() bool

IsException tells if the category is exception.

func (Category) IsI16 added in v0.1.2

func (p Category) IsI16() bool

IsI16 tells if the category is i16.

func (Category) IsI32 added in v0.1.2

func (p Category) IsI32() bool

IsI32 tells if the category is i32.

func (Category) IsI64 added in v0.1.2

func (p Category) IsI64() bool

IsI64 tells if the category is i64.

func (Category) IsList added in v0.1.2

func (p Category) IsList() bool

IsList tells if the category is list.

func (Category) IsMap added in v0.1.2

func (p Category) IsMap() bool

IsMap tells if the category is map.

func (Category) IsService added in v0.1.2

func (p Category) IsService() bool

IsService tells if the category is service.

func (Category) IsSet added in v0.1.2

func (p Category) IsSet() bool

IsSet tells if the category is set.

func (Category) IsString added in v0.1.2

func (p Category) IsString() bool

IsString tells if the category is string.

func (Category) IsStruct added in v0.1.2

func (p Category) IsStruct() bool

IsStruct tells if the category is struct.

func (Category) IsStructLike added in v0.1.2

func (p Category) IsStructLike() bool

IsStructLike tells if the category is a struct-like.

func (Category) IsTypedef added in v0.1.2

func (p Category) IsTypedef() bool

IsTypedef tells if the category is typedef.

func (Category) IsUnion added in v0.1.2

func (p Category) IsUnion() bool

IsUnion tells if the category is union.

func (*Category) Scan added in v0.1.2

func (p *Category) Scan(value interface{}) (err error)

func (Category) String added in v0.1.2

func (p Category) String() string

func (*Category) Value added in v0.1.2

func (p *Category) Value() (driver.Value, error)

type ConstType

type ConstType int64
const (
	ConstType_ConstDouble     ConstType = 0
	ConstType_ConstInt        ConstType = 1
	ConstType_ConstLiteral    ConstType = 2
	ConstType_ConstIdentifier ConstType = 3
	ConstType_ConstList       ConstType = 4
	ConstType_ConstMap        ConstType = 5
)

func ConstTypeFromString

func ConstTypeFromString(s string) (ConstType, error)

func ConstTypePtr

func ConstTypePtr(v ConstType) *ConstType

func (*ConstType) Scan

func (p *ConstType) Scan(value interface{}) (err error)

func (ConstType) String

func (p ConstType) String() string

func (*ConstType) Value added in v0.1.2

func (p *ConstType) Value() (driver.Value, error)

type ConstTypedValue

type ConstTypedValue struct {
	Double     *float64         `thrift:"Double,1,optional" json:"Double,omitempty"`
	Int        *int64           `thrift:"Int,2,optional" json:"Int,omitempty"`
	Literal    *string          `thrift:"Literal,3,optional" json:"Literal,omitempty"`
	Identifier *string          `thrift:"Identifier,4,optional" json:"Identifier,omitempty"`
	List       []*ConstValue    `thrift:"List,5,optional" json:"List,omitempty"`
	Map        []*MapConstValue `thrift:"Map,6,optional" json:"Map,omitempty"`
}
var ConstValue_TypedValue_DEFAULT *ConstTypedValue

func NewConstTypedValue

func NewConstTypedValue() *ConstTypedValue

func (*ConstTypedValue) CountSetFieldsConstTypedValue

func (p *ConstTypedValue) CountSetFieldsConstTypedValue() int

func (*ConstTypedValue) GetDouble

func (p *ConstTypedValue) GetDouble() (v float64)

func (*ConstTypedValue) GetIdentifier

func (p *ConstTypedValue) GetIdentifier() (v string)

func (*ConstTypedValue) GetInt

func (p *ConstTypedValue) GetInt() (v int64)

func (*ConstTypedValue) GetList

func (p *ConstTypedValue) GetList() (v []*ConstValue)

func (*ConstTypedValue) GetLiteral

func (p *ConstTypedValue) GetLiteral() (v string)

func (*ConstTypedValue) GetMap

func (p *ConstTypedValue) GetMap() (v []*MapConstValue)

func (*ConstTypedValue) IsSetDouble

func (p *ConstTypedValue) IsSetDouble() bool

func (*ConstTypedValue) IsSetIdentifier

func (p *ConstTypedValue) IsSetIdentifier() bool

func (*ConstTypedValue) IsSetInt

func (p *ConstTypedValue) IsSetInt() bool

func (*ConstTypedValue) IsSetList

func (p *ConstTypedValue) IsSetList() bool

func (*ConstTypedValue) IsSetLiteral

func (p *ConstTypedValue) IsSetLiteral() bool

func (*ConstTypedValue) IsSetMap

func (p *ConstTypedValue) IsSetMap() bool

func (*ConstTypedValue) String

func (p *ConstTypedValue) String() string

type ConstValue

type ConstValue struct {
	Type       ConstType        `thrift:"Type,1" json:"Type"`
	TypedValue *ConstTypedValue `thrift:"TypedValue,2,optional" json:"TypedValue,omitempty"`
	Extra      *ConstValueExtra `thrift:"Extra,3,optional" json:"Extra,omitempty"`
}
var Constant_Value_DEFAULT *ConstValue
var Field_Default_DEFAULT *ConstValue
var MapConstValue_Key_DEFAULT *ConstValue
var MapConstValue_Value_DEFAULT *ConstValue

func NewConstValue

func NewConstValue() *ConstValue

func (*ConstValue) GetExtra added in v0.1.2

func (p *ConstValue) GetExtra() (v *ConstValueExtra)

func (*ConstValue) GetType

func (p *ConstValue) GetType() (v ConstType)

func (*ConstValue) GetTypedValue

func (p *ConstValue) GetTypedValue() (v *ConstTypedValue)

func (*ConstValue) IsSetExtra added in v0.1.2

func (p *ConstValue) IsSetExtra() bool

func (*ConstValue) IsSetTypedValue

func (p *ConstValue) IsSetTypedValue() bool

func (*ConstValue) String

func (t *ConstValue) String() string

type ConstValueExtra added in v0.1.2

type ConstValueExtra struct {
	IsEnum bool   `thrift:"IsEnum,1" json:"IsEnum"`
	Index  int32  `thrift:"Index,2" json:"Index"`
	Name   string `thrift:"Name,3" json:"Name"`
	Sel    string `thrift:"Sel,4" json:"Sel"`
}
var ConstValue_Extra_DEFAULT *ConstValueExtra

func NewConstValueExtra added in v0.1.2

func NewConstValueExtra() *ConstValueExtra

func (*ConstValueExtra) GetIndex added in v0.1.2

func (p *ConstValueExtra) GetIndex() (v int32)

func (*ConstValueExtra) GetIsEnum added in v0.1.2

func (p *ConstValueExtra) GetIsEnum() (v bool)

func (*ConstValueExtra) GetName added in v0.1.2

func (p *ConstValueExtra) GetName() (v string)

func (*ConstValueExtra) GetSel added in v0.1.2

func (p *ConstValueExtra) GetSel() (v string)

func (*ConstValueExtra) String added in v0.1.2

func (p *ConstValueExtra) String() string

type Constant

type Constant struct {
	Name             string      `thrift:"Name,1" json:"Name"`
	Type             *Type       `thrift:"Type,2,optional" json:"Type,omitempty"`
	Value            *ConstValue `thrift:"Value,3,optional" json:"Value,omitempty"`
	Annotations      Annotations `thrift:"Annotations,4" json:"Annotations"`
	ReservedComments string      `thrift:"ReservedComments,5" json:"ReservedComments"`
}

func NewConstant

func NewConstant() *Constant

func (*Constant) GetAnnotations

func (p *Constant) GetAnnotations() (v Annotations)

func (*Constant) GetName

func (p *Constant) GetName() (v string)

func (*Constant) GetReservedComments added in v0.1.3

func (p *Constant) GetReservedComments() (v string)

func (*Constant) GetType

func (p *Constant) GetType() (v *Type)

func (*Constant) GetValue

func (p *Constant) GetValue() (v *ConstValue)

func (*Constant) IsSetType

func (p *Constant) IsSetType() bool

func (*Constant) IsSetValue

func (p *Constant) IsSetValue() bool

func (*Constant) String

func (p *Constant) String() string

type Enum

type Enum struct {
	Name             string       `thrift:"Name,1" json:"Name"`
	Values           []*EnumValue `thrift:"Values,2" json:"Values"`
	Annotations      Annotations  `thrift:"Annotations,3" json:"Annotations"`
	ReservedComments string       `thrift:"ReservedComments,4" json:"ReservedComments"`
}

func NewEnum

func NewEnum() *Enum

func (*Enum) GetAnnotations

func (p *Enum) GetAnnotations() (v Annotations)

func (*Enum) GetName

func (p *Enum) GetName() (v string)

func (*Enum) GetReservedComments added in v0.1.3

func (p *Enum) GetReservedComments() (v string)

func (*Enum) GetValues

func (p *Enum) GetValues() (v []*EnumValue)

func (*Enum) String

func (p *Enum) String() string

type EnumValue

type EnumValue struct {
	Name             string      `thrift:"Name,1" json:"Name"`
	Value            int64       `thrift:"Value,2" json:"Value"`
	Annotations      Annotations `thrift:"Annotations,3" json:"Annotations"`
	ReservedComments string      `thrift:"ReservedComments,4" json:"ReservedComments"`
}

func NewEnumValue

func NewEnumValue() *EnumValue

func (*EnumValue) GetAnnotations

func (p *EnumValue) GetAnnotations() (v Annotations)

func (*EnumValue) GetName

func (p *EnumValue) GetName() (v string)

func (*EnumValue) GetReservedComments added in v0.1.4

func (p *EnumValue) GetReservedComments() (v string)

func (*EnumValue) GetValue

func (p *EnumValue) GetValue() (v int64)

func (*EnumValue) String

func (p *EnumValue) String() string

type Field

type Field struct {
	ID               int32       `thrift:"ID,1" json:"ID"`
	Name             string      `thrift:"Name,2" json:"Name"`
	Requiredness     FieldType   `thrift:"Requiredness,3" json:"Requiredness"`
	Type             *Type       `thrift:"Type,4" json:"Type"`
	Default          *ConstValue `thrift:"Default,5,optional" json:"Default,omitempty"`
	Annotations      Annotations `thrift:"Annotations,6" json:"Annotations"`
	ReservedComments string      `thrift:"ReservedComments,7" json:"ReservedComments"`
}

func NewField

func NewField() *Field

func (*Field) GetAnnotations

func (p *Field) GetAnnotations() (v Annotations)

func (*Field) GetDefault

func (p *Field) GetDefault() (v *ConstValue)

func (*Field) GetID

func (p *Field) GetID() (v int32)

func (*Field) GetName

func (p *Field) GetName() (v string)

func (*Field) GetRequiredness

func (p *Field) GetRequiredness() (v FieldType)

func (*Field) GetReservedComments added in v0.1.3

func (p *Field) GetReservedComments() (v string)

func (*Field) GetType

func (p *Field) GetType() (v *Type)

func (*Field) IsSetDefault

func (p *Field) IsSetDefault() bool

func (*Field) IsSetType

func (p *Field) IsSetType() bool

func (*Field) String

func (p *Field) String() string

type FieldType

type FieldType int64
const (
	FieldType_Default  FieldType = 0
	FieldType_Required FieldType = 1
	FieldType_Optional FieldType = 2
)

func FieldTypeFromString

func FieldTypeFromString(s string) (FieldType, error)

func FieldTypePtr

func FieldTypePtr(v FieldType) *FieldType

func (FieldType) IsDefault added in v0.1.2

func (r FieldType) IsDefault() bool

IsDefault tells whether a field type is default.

func (FieldType) IsOptional added in v0.1.2

func (r FieldType) IsOptional() bool

IsOptional tells whether a field type is optional.

func (FieldType) IsRequired added in v0.1.2

func (r FieldType) IsRequired() bool

IsRequired tells whether a field type is required.

func (*FieldType) Scan

func (p *FieldType) Scan(value interface{}) (err error)

func (FieldType) String

func (p FieldType) String() string

func (*FieldType) Value added in v0.1.2

func (p *FieldType) Value() (driver.Value, error)

type Function

type Function struct {
	Name             string      `thrift:"Name,1" json:"Name"`
	Oneway           bool        `thrift:"Oneway,2" json:"Oneway"`
	Void             bool        `thrift:"Void,3" json:"Void"`
	FunctionType     *Type       `thrift:"FunctionType,4,optional" json:"FunctionType,omitempty"`
	Arguments        []*Field    `thrift:"Arguments,5" json:"Arguments"`
	Throws           []*Field    `thrift:"Throws,6" json:"Throws"`
	Annotations      Annotations `thrift:"Annotations,7" json:"Annotations"`
	ReservedComments string      `thrift:"ReservedComments,8" json:"ReservedComments"`
}

func NewFunction

func NewFunction() *Function

func (*Function) ForEachArgument added in v0.1.2

func (p *Function) ForEachArgument(f func(v *Field) bool)

ForEachArgument calls f on each argument of the current function.

func (*Function) ForEachThrow added in v0.1.2

func (p *Function) ForEachThrow(f func(v *Field) bool)

ForEachThrow calls f on each throw of the current function.

func (*Function) GetAnnotations

func (p *Function) GetAnnotations() (v Annotations)

func (*Function) GetArguments

func (p *Function) GetArguments() (v []*Field)

func (*Function) GetFunctionType

func (p *Function) GetFunctionType() (v *Type)

func (*Function) GetName

func (p *Function) GetName() (v string)

func (*Function) GetOneway

func (p *Function) GetOneway() (v bool)

func (*Function) GetReservedComments added in v0.1.3

func (p *Function) GetReservedComments() (v string)

func (*Function) GetThrows

func (p *Function) GetThrows() (v []*Field)

func (*Function) GetVoid

func (p *Function) GetVoid() (v bool)

func (*Function) IsSetFunctionType

func (p *Function) IsSetFunctionType() bool

func (*Function) String

func (p *Function) String() string

type Include

type Include struct {
	Path      string  `thrift:"Path,1" json:"Path"`
	Reference *Thrift `thrift:"Reference,2,optional" json:"Reference,omitempty"`
	Used      *bool   `thrift:"Used,3,optional" json:"Used,omitempty"`
}

func NewInclude

func NewInclude() *Include

func (*Include) GetPath

func (p *Include) GetPath() (v string)

func (*Include) GetReference

func (p *Include) GetReference() (v *Thrift)

func (*Include) GetUsed added in v0.1.2

func (p *Include) GetUsed() (v bool)

func (*Include) IsSetReference

func (p *Include) IsSetReference() bool

func (*Include) IsSetUsed added in v0.1.2

func (p *Include) IsSetUsed() bool

func (*Include) String

func (p *Include) String() string

type MapConstValue

type MapConstValue struct {
	Key   *ConstValue `thrift:"Key,1,optional" json:"Key,omitempty"`
	Value *ConstValue `thrift:"Value,2,optional" json:"Value,omitempty"`
}

func NewMapConstValue

func NewMapConstValue() *MapConstValue

func (*MapConstValue) GetKey

func (p *MapConstValue) GetKey() (v *ConstValue)

func (*MapConstValue) GetValue

func (p *MapConstValue) GetValue() (v *ConstValue)

func (*MapConstValue) IsSetKey

func (p *MapConstValue) IsSetKey() bool

func (*MapConstValue) IsSetValue

func (p *MapConstValue) IsSetValue() bool

func (*MapConstValue) String

func (p *MapConstValue) String() string

type Namespace

type Namespace struct {
	Language    string      `thrift:"Language,1" json:"Language"`
	Name        string      `thrift:"Name,2" json:"Name"`
	Annotations Annotations `thrift:"Annotations,3" json:"Annotations"`
}

func NewNamespace

func NewNamespace() *Namespace

func (*Namespace) GetAnnotations

func (p *Namespace) GetAnnotations() (v Annotations)

func (*Namespace) GetLanguage

func (p *Namespace) GetLanguage() (v string)

func (*Namespace) GetName

func (p *Namespace) GetName() (v string)

func (*Namespace) String

func (p *Namespace) String() string

type Reference added in v0.1.2

type Reference struct {
	Name  string `thrift:"Name,1" json:"Name"`
	Index int32  `thrift:"Index,2" json:"Index"`
}
var Service_Reference_DEFAULT *Reference
var Type_Reference_DEFAULT *Reference

func NewReference added in v0.1.2

func NewReference() *Reference

func (*Reference) GetIndex added in v0.1.2

func (p *Reference) GetIndex() (v int32)

func (*Reference) GetName added in v0.1.2

func (p *Reference) GetName() (v string)

func (*Reference) String added in v0.1.2

func (p *Reference) String() string

type Service

type Service struct {
	Name             string      `thrift:"Name,1" json:"Name"`
	Extends          string      `thrift:"Extends,2" json:"Extends"`
	Functions        []*Function `thrift:"Functions,3" json:"Functions"`
	Annotations      Annotations `thrift:"Annotations,4" json:"Annotations"`
	Reference        *Reference  `thrift:"Reference,5,optional" json:"Reference,omitempty"`
	ReservedComments string      `thrift:"ReservedComments,6" json:"ReservedComments"`
}

func NewService

func NewService() *Service

func (*Service) ForEachFunction added in v0.1.2

func (s *Service) ForEachFunction(f func(v *Function) bool)

ForEachFunction calls f on each function in the current service.

func (*Service) GetAnnotations

func (p *Service) GetAnnotations() (v Annotations)

func (*Service) GetExtends

func (p *Service) GetExtends() (v string)

func (*Service) GetFunctions

func (p *Service) GetFunctions() (v []*Function)

func (*Service) GetName

func (p *Service) GetName() (v string)

func (*Service) GetReference added in v0.1.2

func (p *Service) GetReference() (v *Reference)

func (*Service) GetReservedComments added in v0.1.3

func (p *Service) GetReservedComments() (v string)

func (*Service) IsSetReference added in v0.1.2

func (p *Service) IsSetReference() bool

func (*Service) String

func (p *Service) String() string

type StructLike

type StructLike struct {
	Category         string      `thrift:"Category,1" json:"Category"`
	Name             string      `thrift:"Name,2" json:"Name"`
	Fields           []*Field    `thrift:"Fields,3" json:"Fields"`
	Annotations      Annotations `thrift:"Annotations,4" json:"Annotations"`
	ReservedComments string      `thrift:"ReservedComments,5" json:"ReservedComments"`
}

func NewStructLike

func NewStructLike() *StructLike

func (*StructLike) ForEachField added in v0.1.2

func (s *StructLike) ForEachField(f func(v *Field) bool)

ForEachField calls f on each field of the current struct-like.

func (*StructLike) GetAnnotations

func (p *StructLike) GetAnnotations() (v Annotations)

func (*StructLike) GetCategory

func (p *StructLike) GetCategory() (v string)

func (*StructLike) GetField

func (s *StructLike) GetField(name string) (*Field, bool)

GetField returns a field of the struct-like that matches the name.

func (*StructLike) GetFields

func (p *StructLike) GetFields() (v []*Field)

func (*StructLike) GetName

func (p *StructLike) GetName() (v string)

func (*StructLike) GetReservedComments added in v0.1.3

func (p *StructLike) GetReservedComments() (v string)

func (*StructLike) String

func (p *StructLike) String() string

type Thrift

type Thrift struct {
	Filename      string              `thrift:"Filename,1" json:"Filename"`
	Includes      []*Include          `thrift:"Includes,2" json:"Includes"`
	CppIncludes   []string            `thrift:"CppIncludes,3" json:"CppIncludes"`
	Namespaces    []*Namespace        `thrift:"Namespaces,4" json:"Namespaces"`
	Typedefs      []*Typedef          `thrift:"Typedefs,5" json:"Typedefs"`
	Constants     []*Constant         `thrift:"Constants,6" json:"Constants"`
	Enums         []*Enum             `thrift:"Enums,7" json:"Enums"`
	Structs       []*StructLike       `thrift:"Structs,8" json:"Structs"`
	Unions        []*StructLike       `thrift:"Unions,9" json:"Unions"`
	Exceptions    []*StructLike       `thrift:"Exceptions,10" json:"Exceptions"`
	Services      []*Service          `thrift:"Services,11" json:"Services"`
	Name2Category map[string]Category `thrift:"Name2Category,12" json:"Name2Category"`
}
var Include_Reference_DEFAULT *Thrift

func NewThrift

func NewThrift() *Thrift

func ParseFile

func ParseFile(path string, includeDirs []string, recursive bool) (*Thrift, error)

ParseFile parses a thrift file and returns an AST. If recursive is true, then the include IDLs are parsed recursively as well.

func ParseString

func ParseString(path, content string) (*Thrift, error)

ParseString parses the thrift file path and file content then return an AST.

func (*Thrift) DepthFirstSearch

func (t *Thrift) DepthFirstSearch() chan *Thrift

DepthFirstSearch returns a channal providing Thrift ASTs in a depth-first order without duplication. Unparsed references will be ignored.

func (*Thrift) ForEachConstant added in v0.1.2

func (t *Thrift) ForEachConstant(f func(v *Constant) bool)

ForEachConstant calls f on each constant in the current AST.

func (*Thrift) ForEachEnum added in v0.1.2

func (t *Thrift) ForEachEnum(f func(v *Enum) bool)

ForEachEnum calls f on each enum in the current AST.

func (*Thrift) ForEachException added in v0.1.2

func (t *Thrift) ForEachException(f func(v *StructLike) bool)

ForEachException calls f on each exception in the current AST.

func (*Thrift) ForEachInclude added in v0.1.2

func (t *Thrift) ForEachInclude(f func(v *Include) bool)

ForEachInclude calls f on each include of the current AST.

func (*Thrift) ForEachNamepace added in v0.1.2

func (t *Thrift) ForEachNamepace(f func(v *Namespace) bool)

ForEachNamepace calls f on each namespace of the current AST.

func (*Thrift) ForEachService added in v0.1.2

func (t *Thrift) ForEachService(f func(v *Service) bool)

ForEachService calls f on each service in the current AST.

func (*Thrift) ForEachStruct added in v0.1.2

func (t *Thrift) ForEachStruct(f func(v *StructLike) bool)

ForEachStruct calls f on each struct in the current AST.

func (*Thrift) ForEachStructLike added in v0.1.2

func (t *Thrift) ForEachStructLike(f func(v *StructLike) bool)

ForEachStructLike calls f on each struct-like in the current AST.

func (*Thrift) ForEachTypedef added in v0.1.2

func (t *Thrift) ForEachTypedef(f func(v *Typedef) bool)

ForEachTypedef calls f on each typedef in the current AST.

func (*Thrift) ForEachUnion added in v0.1.2

func (t *Thrift) ForEachUnion(f func(v *StructLike) bool)

ForEachUnion calls f on each union in the current AST.

func (*Thrift) GetConstant

func (t *Thrift) GetConstant(name string) (*Constant, bool)

GetConstant returns a Constant node that mathces the name.

func (*Thrift) GetConstants

func (p *Thrift) GetConstants() (v []*Constant)

func (*Thrift) GetCppIncludes

func (p *Thrift) GetCppIncludes() (v []string)

func (*Thrift) GetEnum

func (t *Thrift) GetEnum(name string) (*Enum, bool)

GetEnum returns an Enum node that matches the name.

func (*Thrift) GetEnums

func (p *Thrift) GetEnums() (v []*Enum)

func (*Thrift) GetException

func (t *Thrift) GetException(name string) (*StructLike, bool)

GetException returns an Exception that matches the name.

func (*Thrift) GetExceptions

func (p *Thrift) GetExceptions() (v []*StructLike)

func (*Thrift) GetFilename

func (p *Thrift) GetFilename() (v string)

func (*Thrift) GetIncludes

func (p *Thrift) GetIncludes() (v []*Include)

func (*Thrift) GetName2Category added in v0.1.2

func (p *Thrift) GetName2Category() (v map[string]Category)

func (*Thrift) GetNamespace

func (t *Thrift) GetNamespace(lang string) (ns string, found bool)

GetNamespace returns a namespace for the language. When both "*" and the language have a namespace defined, the latter is preferred.

func (*Thrift) GetNamespaceOrReferenceName

func (t *Thrift) GetNamespaceOrReferenceName(lang string) string

GetNamespaceOrReferenceName returns a namespace for the language. If the namespace is not defined, then the base name without extension of the IDL will be returned.

func (*Thrift) GetNamespaces

func (p *Thrift) GetNamespaces() (v []*Namespace)

func (*Thrift) GetReference

func (t *Thrift) GetReference(refname string) (*Thrift, bool)

GetReference return a AST that matches the given name. References should be initialized before calling this method.

func (*Thrift) GetService

func (t *Thrift) GetService(name string) (*Service, bool)

GetService returns a Service node that matches the name.

func (*Thrift) GetServices

func (p *Thrift) GetServices() (v []*Service)

func (*Thrift) GetStruct

func (t *Thrift) GetStruct(name string) (*StructLike, bool)

GetStruct returns a Struct node that matches the name.

func (*Thrift) GetStructLikes added in v0.1.2

func (t *Thrift) GetStructLikes() (ss []*StructLike)

GetStructLikes returns all struct-like definitions in the AST.

func (*Thrift) GetStructs

func (p *Thrift) GetStructs() (v []*StructLike)

func (*Thrift) GetTypedef

func (t *Thrift) GetTypedef(alias string) (*Typedef, bool)

GetTypedef returns a Typedef node that matches the alias name.

func (*Thrift) GetTypedefs

func (p *Thrift) GetTypedefs() (v []*Typedef)

func (*Thrift) GetUnion

func (t *Thrift) GetUnion(name string) (*StructLike, bool)

GetUnion returns a Union node that matches the name.

func (*Thrift) GetUnions

func (p *Thrift) GetUnions() (v []*StructLike)

func (*Thrift) String

func (p *Thrift) String() string

type ThriftIDL

type ThriftIDL struct {
	Buffer string

	Pretty bool
	// contains filtered or unexported fields
}

func (*ThriftIDL) AST

func (t *ThriftIDL) AST() *node32

func (*ThriftIDL) Add

func (t *ThriftIDL) Add(rule pegRule, begin, end, index uint32)

func (*ThriftIDL) Init

func (p *ThriftIDL) Init(options ...func(*ThriftIDL) error) error

func (*ThriftIDL) Parse

func (p *ThriftIDL) Parse(rule ...int) error

func (*ThriftIDL) PrettyPrintSyntaxTree added in v0.1.3

func (t *ThriftIDL) PrettyPrintSyntaxTree(buffer string)

func (*ThriftIDL) Print

func (t *ThriftIDL) Print()

func (*ThriftIDL) PrintSyntaxTree

func (p *ThriftIDL) PrintSyntaxTree()

func (*ThriftIDL) Reset

func (p *ThriftIDL) Reset()

func (*ThriftIDL) SprintSyntaxTree added in v0.1.3

func (p *ThriftIDL) SprintSyntaxTree() string

func (*ThriftIDL) Tokens

func (t *ThriftIDL) Tokens() []token32

func (*ThriftIDL) Trim added in v0.1.3

func (t *ThriftIDL) Trim(length uint32)

func (*ThriftIDL) WriteSyntaxTree added in v0.1.3

func (p *ThriftIDL) WriteSyntaxTree(w io.Writer)

type Type

type Type struct {
	Name        string      `thrift:"Name,1" json:"Name"`
	KeyType     *Type       `thrift:"KeyType,2,optional" json:"KeyType,omitempty"`
	ValueType   *Type       `thrift:"ValueType,3,optional" json:"ValueType,omitempty"`
	CppType     string      `thrift:"CppType,4" json:"CppType"`
	Annotations Annotations `thrift:"Annotations,5" json:"Annotations"`
	Category    Category    `thrift:"Category,6" json:"Category"`
	Reference   *Reference  `thrift:"Reference,7,optional" json:"Reference,omitempty"`
	IsTypedef   *bool       `thrift:"IsTypedef,8,optional" json:"IsTypedef,omitempty"`
}
var Constant_Type_DEFAULT *Type
var Field_Type_DEFAULT *Type
var Function_FunctionType_DEFAULT *Type
var Type_KeyType_DEFAULT *Type
var Type_ValueType_DEFAULT *Type
var Typedef_Type_DEFAULT *Type

func NewType

func NewType() *Type

func (*Type) GetAnnotations

func (p *Type) GetAnnotations() (v Annotations)

func (*Type) GetCategory added in v0.1.2

func (p *Type) GetCategory() (v Category)

func (*Type) GetCppType

func (p *Type) GetCppType() (v string)

func (*Type) GetIsTypedef added in v0.1.2

func (p *Type) GetIsTypedef() (v bool)

func (*Type) GetKeyType

func (p *Type) GetKeyType() (v *Type)

func (*Type) GetName

func (p *Type) GetName() (v string)

func (*Type) GetReference added in v0.1.2

func (p *Type) GetReference() (v *Reference)

func (*Type) GetValueType

func (p *Type) GetValueType() (v *Type)

func (*Type) IsSetIsTypedef added in v0.1.2

func (p *Type) IsSetIsTypedef() bool

func (*Type) IsSetKeyType

func (p *Type) IsSetKeyType() bool

func (*Type) IsSetReference added in v0.1.2

func (p *Type) IsSetReference() bool

func (*Type) IsSetValueType

func (p *Type) IsSetValueType() bool

func (*Type) String

func (t *Type) String() string

type Typedef

type Typedef struct {
	Type             *Type       `thrift:"Type,1,optional" json:"Type,omitempty"`
	Alias            string      `thrift:"Alias,2" json:"Alias"`
	Annotations      Annotations `thrift:"Annotations,3" json:"Annotations"`
	ReservedComments string      `thrift:"ReservedComments,4" json:"ReservedComments"`
}

func NewTypedef

func NewTypedef() *Typedef

func (*Typedef) GetAlias

func (p *Typedef) GetAlias() (v string)

func (*Typedef) GetAnnotations

func (p *Typedef) GetAnnotations() (v Annotations)

func (*Typedef) GetReservedComments added in v0.1.3

func (p *Typedef) GetReservedComments() (v string)

func (*Typedef) GetType

func (p *Typedef) GetType() (v *Type)

func (*Typedef) IsSetType

func (p *Typedef) IsSetType() bool

func (*Typedef) String

func (p *Typedef) String() string

Jump to

Keyboard shortcuts

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