ast

package
v0.0.0-...-6d75143 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ast implements Thrift AST.

Index

Constants

This section is empty.

Variables

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

func ParseFromFile(f *os.File) (*File, error)

ParseFromFile parses the Thrift file from os.File.

func ParseFromReader

func ParseFromReader(rd io.Reader, filename ...string) (*File, error)

ParseFromReader parses the Thrift file from io.Reader.

func ParseFromString

func ParseFromString(s string, filename ...string) (*File, error)

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

func (f File) GetIncludes() (result []*Include)

GetIncludes returns all includes.

func (File) GetNamespace

func (f File) GetNamespace(language string) *Namespace

GetNamespace returns the namespace of the given language. If there is no matching namespace, it returns nil.

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.

func (Namespace) Match

func (n Namespace) Match(language string) bool

Match reports whether the given language matches the scope of n.

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.

type Typedef

type Typedef struct {
	Type *Type  `parser:" 'typedef' @@ " json:"type"`
	Name string `parser:" @Ident " json:"name"`
}

Typedef represents the Thrift typedef.

Jump to

Keyboard shortcuts

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