parser

package
v0.3.18 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

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.

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

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

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

func Pretty

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

func Size

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

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

func NewAnnotation

func NewAnnotation() *Annotation

func (*Annotation) GetKey

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

func (*Annotation) GetValues

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

func (*Annotation) String

func (p *Annotation) String() string

type Annotations

type Annotations []*Annotation

func (*Annotations) Append

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

Append append key value pair to Annotation slice.

func (*Annotations) Get

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

Get return annotations values.

func (*Annotations) ILocValueByKey

func (a *Annotations) ILocValueByKey(key string, idx int) string

ILocValueByKey return annotation value by key and index.

type Category

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

func CategoryFromString(s string) (Category, error)

func CategoryPtr

func CategoryPtr(v Category) *Category

func (Category) IsBaseType

func (p Category) IsBaseType() bool

IsBaseType tells if the category is one of the basetypes.

func (Category) IsBinary

func (p Category) IsBinary() bool

IsBinary tells if the category is binary.

func (Category) IsBool

func (p Category) IsBool() bool

IsBool tells if the category is bool.

func (Category) IsByte

func (p Category) IsByte() bool

IsByte tells if the category is byte.

func (Category) IsConstant

func (p Category) IsConstant() bool

IsConstant tells if the category is constant.

func (Category) IsContainerType

func (p Category) IsContainerType() bool

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

func (Category) IsDouble

func (p Category) IsDouble() bool

IsDouble tells if the category is double.

func (Category) IsEnum

func (p Category) IsEnum() bool

IsEnum tells if the category is enum.

func (Category) IsException

func (p Category) IsException() bool

IsException tells if the category is exception.

func (Category) IsI16

func (p Category) IsI16() bool

IsI16 tells if the category is i16.

func (Category) IsI32

func (p Category) IsI32() bool

IsI32 tells if the category is i32.

func (Category) IsI64

func (p Category) IsI64() bool

IsI64 tells if the category is i64.

func (Category) IsList

func (p Category) IsList() bool

IsList tells if the category is list.

func (Category) IsMap

func (p Category) IsMap() bool

IsMap tells if the category is map.

func (Category) IsService

func (p Category) IsService() bool

IsService tells if the category is service.

func (Category) IsSet

func (p Category) IsSet() bool

IsSet tells if the category is set.

func (Category) IsString

func (p Category) IsString() bool

IsString tells if the category is string.

func (Category) IsStruct

func (p Category) IsStruct() bool

IsStruct tells if the category is struct.

func (Category) IsStructLike

func (p Category) IsStructLike() bool

IsStructLike tells if the category is a struct-like.

func (Category) IsTypedef

func (p Category) IsTypedef() bool

IsTypedef tells if the category is typedef.

func (Category) IsUnion

func (p Category) IsUnion() bool

IsUnion tells if the category is union.

func (*Category) Scan

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

func (Category) String

func (p Category) String() string

func (*Category) Value

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

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

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

func (p *ConstValue) IsSetExtra() bool

func (*ConstValue) IsSetTypedValue

func (p *ConstValue) IsSetTypedValue() bool

func (*ConstValue) String

func (t *ConstValue) String() string

type ConstValueExtra

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

func NewConstValueExtra() *ConstValueExtra

func (*ConstValueExtra) GetIndex

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

func (*ConstValueExtra) GetIsEnum

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

func (*ConstValueExtra) GetName

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

func (*ConstValueExtra) GetSel

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

func (*ConstValueExtra) String

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

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

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

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

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

func (r FieldType) IsDefault() bool

IsDefault tells whether a field type is default.

func (FieldType) IsOptional

func (r FieldType) IsOptional() bool

IsOptional tells whether a field type is optional.

func (FieldType) IsRequired

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

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

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

ForEachArgument calls f on each argument of the current function.

func (*Function) ForEachThrow

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

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

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

func (*Include) IsSetReference

func (p *Include) IsSetReference() bool

func (*Include) IsSetUsed

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

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

func NewReference() *Reference

func (*Reference) GetIndex

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

func (*Reference) GetName

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

func (*Reference) String

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

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

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

func (*Service) GetReservedComments

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

func (*Service) IsSetReference

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

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

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 ParseBatchString

func ParseBatchString(mainIDLFilePath string, IDLFileContentMap map[string]string, includeDirs []string) (*Thrift, error)

ParseBatchString parses a group of string content and returns an AST. IDLContent is a map, which's key is IDLPath and value is IDL content.

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

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

ForEachConstant calls f on each constant in the current AST.

func (*Thrift) ForEachEnum

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

ForEachEnum calls f on each enum in the current AST.

func (*Thrift) ForEachException

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

ForEachException calls f on each exception in the current AST.

func (*Thrift) ForEachInclude

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

ForEachInclude calls f on each include of the current AST.

func (*Thrift) ForEachNamepace

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

ForEachNamepace calls f on each namespace of the current AST.

func (*Thrift) ForEachService

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

ForEachService calls f on each service in the current AST.

func (*Thrift) ForEachStruct

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

ForEachStruct calls f on each struct in the current AST.

func (*Thrift) ForEachStructLike

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

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

func (*Thrift) ForEachTypedef

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

ForEachTypedef calls f on each typedef in the current AST.

func (*Thrift) ForEachUnion

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

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

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

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

func (p *ThriftIDL) SprintSyntaxTree() string

func (*ThriftIDL) Tokens

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

func (*ThriftIDL) Trim

func (t *ThriftIDL) Trim(length uint32)

func (*ThriftIDL) WriteSyntaxTree

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

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

func (*Type) GetCppType

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

func (*Type) GetIsTypedef

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

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

func (*Type) GetValueType

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

func (*Type) IsSetIsTypedef

func (p *Type) IsSetIsTypedef() bool

func (*Type) IsSetKeyType

func (p *Type) IsSetKeyType() bool

func (*Type) IsSetReference

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

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

func (*Typedef) GetReservedComments

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