Documentation ¶
Overview ¶
Package ast implements Thrift AST.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Parser = participle.MustBuild((*File)(nil), participle.Lexer(lexer.DefaultDefinition), participle.Unquote("String"), )
Parser the default participle lexer for the Thrift file.
Functions ¶
This section is empty.
Types ¶
type CollectionType ¶
type CollectionType struct {
Element *Type `parser:" '<' @@ '>' " json:"element"`
}
CollectionType represents the collection-like type of the Thrift type.
type Definition ¶
type Definition struct { Typedef *Typedef `parser:" @@ " json:"typedef,omitempty"` Enum *Enum `parser:" | @@ " json:"enum,omitempty"` Struct *Struct `parser:" | @@ " json:"struct,omitempty"` Service *Service `parser:" | @@ " json:"service,omitempty"` }
Definition represents the Thrift definition.
type Enum ¶
type Enum struct { Name string `parser:" 'enum' @Ident " json:"name"` Constants []*EnumConst `parser:" '{' @@* '}' " json:"constants,omitempty"` }
Enum represents the Thrift enum.
type EnumConst ¶
type EnumConst struct { Name string `parser:" @Ident " json:"name"` Value *int `parser:" ( '=' @Int )? ( ',' | ';' )? " json:"value,omitempty"` }
EnumConst represents the constant of the Thrift enum.
type Field ¶
type Field struct { ID *int `parser:" ( @Int ':' )? " json:"id,omitempty"` Optional bool `parser:" ( 'required' | @'optional' )? " json:"optional,omitempty"` Type *Type `parser:" @@ " json:"type"` Name string `parser:" @Ident ( ',' | ';' )? " json:"name"` }
Field represents the field of the Thrift struct.
type File ¶
type File struct { Headers []*Header `parser:" ( @@ " json:"headers,omitempty"` Definitions []*Definition `parser:" | @@ )* " json:"definitions,omitempty"` }
File represents the Thrift file.
func ParseFromFile ¶
ParseFromFile parses the Thrift file from os.File.
func ParseFromReader ¶
ParseFromReader parses the Thrift file from io.Reader.
func ParseFromString ¶
ParseFromString parses the Thrift file from a string.
func (File) GetDefinition ¶
func (f File) GetDefinition(name string) *Definition
GetDefinition returns the definition which matches the given name. If there is no matching definition, it returns nil.
func (File) GetIncludes ¶
GetIncludes returns all includes.
func (File) GetNamespace ¶
GetNamespace returns the namespace of the given language. If there is no matching namespace, it returns nil.
type Header ¶
type Header struct { Include *Include `parser:" @@ " json:"include,omitempty"` Namespace *Namespace `parser:" | @@ " json:"namespace,omitempty"` }
Header represents the Thrift header.
type Include ¶
type Include struct {
File string `parser:" 'include' @String " json:"file"`
}
Include represents the Thrift include.
type MapType ¶
type MapType struct { Key *Type `parser:" '<' @@ ',' " json:"key"` Value *Type `parser:" @@ '>' " json:"value"` }
MapType represents the map-like type of the Thrift type.
type Method ¶
type Method struct { Oneway bool `parser:" @'oneway'? " json:"oneway,omitempty"` Void bool `parser:" ( @'void' " json:"void,omitempty"` Return *Type `parser:" | @@ ) " json:"return,omitempty"` Name string `parser:" @Ident " json:"name"` Arguments []*Field `parser:" '(' @@* ')' " json:"fields,omitempty"` Throws []*Field `parser:" ( 'throws' '(' @@* ')' )? ( ',' | ';' )? " json:"throws,omitempty"` }
Method represents the method of the Thrift service.
type Namespace ¶
type Namespace struct { Scope string `parser:" 'namespace' @( Ident ( '.' Ident )* | '*' ) " json:"scope"` As string `parser:" @( Ident ( '.' Ident )* ) " json:"as"` }
Namespace represents the Thrift namespace.
type Service ¶
type Service struct { Name string `parser:" 'service' @Ident " json:"name"` Extends *string `parser:" ( 'extends' @( Ident ( '.' Ident )? ) )? " json:"extends,omitempty"` Methods []*Method `parser:" '{' @@* '}' " json:"methods,omitempty"` }
Service represents the Thrift service.
type Struct ¶
type Struct struct { Type string `parser:" @( 'struct' | 'union' | 'exception' ) " json:"type"` Name string `parser:" @Ident " json:"name"` Fields []*Field `parser:" '{' @@* '}' " json:"fields,omitempty"` }
Struct represents the Thrift struct.
type Type ¶
type Type struct { Map *MapType `parser:" 'map' @@ " json:"map,omitempty"` Set *CollectionType `parser:" | 'set' @@ " json:"set,omitempty"` List *CollectionType `parser:" | 'list' @@ " json:"list,omitempty"` Base *string `parser:" | @( 'bool' | 'byte' | 'i8' | 'i16' | 'i32' | 'i64' | 'double' | 'string' | 'binary' ) " json:"base,omitempty"` Reference *string `parser:" | @( Ident ( '.' Ident )? ) " json:"reference,omitempty"` }
Type represents the Thrift type.