ast

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: MIT Imports: 2 Imported by: 0

README

thrift-ast Go Reference

Implementation of Thrift AST and parser

Documentation

Overview

Package ast implements Thrift AST and parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Const

type Const struct {
	Type  *Type  `parser:" 'const' @@ "`
	Name  string `parser:" @Ident "`
	Value *Value `parser:" '=' @@ "`
}

Const represents the Thrift const.

type Definition

type Definition struct {
	Const   *Const   `parser:"   @@ " json:",omitempty"`
	Typedef *Typedef `parser:" | @@ " json:",omitempty"`
	Enum    *Enum    `parser:" | @@ " json:",omitempty"`
	Struct  *Struct  `parser:" | @@ " json:",omitempty"`
	Service *Service `parser:" | @@ " json:",omitempty"`
}

Definition represents the Thrift definition.

type Enum

type Enum struct {
	Name      string          `parser:" 'enum' @Ident "`
	Constants []*EnumConstant `parser:" '{' @@* '}' " json:",omitempty"`
}

Enum represents the Thrift enum.

type EnumConstant

type EnumConstant struct {
	Name  string `parser:" @Ident "`
	Value *int   `parser:" ( '=' @Int )? " json:",omitempty"`
}

EnumConstant represents the constant of the Thrift enum.

type Field

type Field struct {
	ID       int    `parser:" @Int ':' "`
	Optional bool   `parser:" ( 'required' | @'optional' )? " json:",omitempty"`
	Type     *Type  `parser:" @@ "`
	Name     string `parser:" @Ident "`
}

Field represents the field of the Thrift struct.

type File

type File struct {
	Headers     []*Header     `parser:" ( @@* " json:",omitempty"`
	Definitions []*Definition `parser:"   @@* )? " json:",omitempty"`
}

File represents the Thrift file.

func ParseBytes

func ParseBytes(data []byte, filename ...string) (*File, error)

ParseBytes parses the Thrift file from []byte.

func ParseString

func ParseString(data string, filename ...string) (*File, error)

ParseString parses the Thrift file from string.

func (File) GetDefinition

func (f File) GetDefinition(name string) *Definition

GetDefinition returns the definition which matches the given name.

func (File) GetNamespace

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

GetNamespace returns the namespace which matches the given language.

type Header struct {
	Include   *Include   `parser:"   @@ " json:",omitempty"`
	Namespace *Namespace `parser:" | @@ " json:",omitempty"`
}

Header represents the Thrift header.

type Include

type Include struct {
	Path string `parser:" 'include' @String "`
}

Include represents the Thrift include.

type MapItem

type MapItem struct {
	Key   *Value `parser:" @@ ':' "`
	Value *Value `parser:" @@ ','? "`
}

MapItem represents the item of the Thrift map.

type Method

type Method struct {
	Oneway    bool     `parser:" @'oneway'? " json:",omitempty"`
	Void      bool     `parser:" ( @'void' " json:",omitempty"`
	Type      *Type    `parser:" | @@ ) " json:",omitempty"`
	Name      string   `parser:" @Ident "`
	Arguments []*Field `parser:" '(' @@* ')' " json:",omitempty"`
	Throws    []*Field `parser:" ( 'throws' '(' @@* ')' )? " json:",omitempty"`
}

Method represents the method of the Thrift service.

type Namespace

type Namespace struct {
	Language string `parser:" 'namespace' @( Ident | '*' ) "`
	Name     string `parser:" @Ident "`
}

Namespace represents the Thrift namespace.

type Service

type Service struct {
	Name    string    `parser:" 'service' @Ident "`
	Extends *string   `parser:" ( 'extends' @Ident )? " json:",omitempty"`
	Methods []*Method `parser:" '{' @@* '}' " json:",omitempty"`
}

Service represents the Thrift service.

type Struct

type Struct struct {
	Type   string   `parser:" @( 'struct' | 'union' | 'exception' ) "`
	Name   string   `parser:" @Ident "`
	Fields []*Field `parser:" '{' @@* '}' " json:",omitempty"`
}

Struct represents the Thrift struct.

type Type

type Type struct {
	Name      string  `parser:" @Ident "`
	Arguments []*Type `parser:" ( '<' @@ ( ',' @@ )* '>' )? " json:",omitempty"`
}

Type represents the Thrift type.

type Typedef

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

Typedef represents the Thrift typedef.

type Value

type Value struct {
	Int       *float64   `parser:"   @( ( '+' | '-' )? Int ( '.' Int? )? ) " json:",omitempty"`
	String    *string    `parser:" | @String " json:",omitempty"`
	List      []*Value   `parser:" | '[' ( @@ ','? )* ']' " json:",omitempty"`
	Map       []*MapItem `parser:" | '{' @@* '}' " json:",omitempty"`
	Reference string     `parser:" | @Ident " json:",omitempty"`
}

Value represents the Thrift value.

Jump to

Keyboard shortcuts

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