parser

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: BSD-3-Clause Imports: 12 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(filename string, b []byte, opts ...Option) (interface{}, error)

Parse parses the data from b using filename as information in the error messages.

func ParseFile

func ParseFile(filename string, opts ...Option) (interface{}, error)

ParseFile parses the file identified by filename.

func ParseReader

func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error)

ParseReader parses the data from r using filename as information in the error messages.

Types

type Annotation

type Annotation struct {
	Pos   Pos
	Name  string
	Value string
}

type Constant

type Constant struct {
	Pos     Pos
	Comment string
	Name    string
	Type    *Type
	Value   interface{}
}

type Enum

type Enum struct {
	Pos         Pos
	Comment     string
	Name        string
	Values      map[string]*EnumValue
	Annotations []*Annotation `json:",omitempty"`
}

type EnumValue

type EnumValue struct {
	Pos         Pos
	Comment     string
	Name        string
	Value       int
	Annotations []*Annotation `json:",omitempty"`
}

type Field

type Field struct {
	Pos         Pos
	Comment     string
	ID          int
	Name        string
	Optional    bool
	Type        *Type
	Default     interface{}   `json:",omitempty"`
	Annotations []*Annotation `json:",omitempty"`
}

type Filesystem

type Filesystem interface {
	Open(filename string) (io.ReadCloser, error)
	// Abs makes "path" absolute, when relative to the directory "dir".
	Abs(dir, path string) (string, error)
}

type Identifier

type Identifier string

type KeyValue

type KeyValue struct {
	Key   interface{}
	Value interface{}
}

type Method

type Method struct {
	Pos         Pos
	Comment     string
	Name        string
	Oneway      bool
	ReturnType  *Type
	Arguments   []*Field
	Exceptions  []*Field      `json:",omitempty"`
	Annotations []*Annotation `json:",omitempty"`
}

type Option

type Option func(*parser) Option

Option is a function that can set an option on the parser. It returns the previous setting as an Option.

func Debug

func Debug(b bool) Option

Debug creates an Option to set the debug flag to b. When set to true, debugging information is printed to stdout while parsing.

The default is false.

func Memoize

func Memoize(b bool) Option

Memoize creates an Option to set the memoize flag to b. When set to true, the parser will cache all results so each expression is evaluated only once. This guarantees linear parsing time even for pathological cases, at the expense of more memory and slower times for typical cases.

The default is false.

func Recover

func Recover(b bool) Option

Recover creates an Option to set the recover flag to b. When set to true, this causes the parser to recover from panics and convert it to an error. Setting it to false can be useful while debugging to access the full stack trace.

The default is true.

type Parser

type Parser struct {
	Filesystem Filesystem // For handling includes. Can be set to nil to fall back to os package.
	Files      map[string]*Thrift
}

func New

func New() *Parser

func (*Parser) Parse

func (p *Parser) Parse(r io.Reader, opts ...Option) (*Thrift, error)

func (*Parser) ParseFile

func (p *Parser) ParseFile(filename string) (map[string]*Thrift, string, error)

type Pos

type Pos struct {
	Line int
	Col  int
}

type Service

type Service struct {
	Pos         Pos
	Comment     string
	Name        string
	Extends     string `json:",omitempty"`
	Methods     map[string]*Method
	Annotations []*Annotation `json:",omitempty"`
}

type Struct

type Struct struct {
	Pos         Pos
	Comment     string
	Name        string
	Fields      []*Field
	Annotations []*Annotation `json:",omitempty"`
}

type Thrift

type Thrift struct {
	Filename   string
	Includes   map[string]string    `json:",omitempty"` // name -> unique identifier (absolute path generally)
	Imports    map[string]*Thrift   `json:",omitempty"` // name -> imported file
	Typedefs   map[string]*Typedef  `json:",omitempty"`
	Namespaces map[string]string    `json:",omitempty"`
	Constants  map[string]*Constant `json:",omitempty"`
	Enums      map[string]*Enum     `json:",omitempty"`
	Structs    map[string]*Struct   `json:",omitempty"`
	Exceptions map[string]*Struct   `json:",omitempty"`
	Unions     map[string]*Struct   `json:",omitempty"`
	Services   map[string]*Service  `json:",omitempty"`
}

type Type

type Type struct {
	Pos         Pos
	Name        string        `json:",omitempty"`
	KeyType     *Type         `json:",omitempty"` // If map
	ValueType   *Type         `json:",omitempty"` // If map, list, or set
	Annotations []*Annotation `json:",omitempty"`
}

func (*Type) String

func (t *Type) String() string

type Typedef

type Typedef struct {
	*Type

	Pos         Pos
	Alias       string
	Annotations []*Annotation `json:",omitempty"`
}

Jump to

Keyboard shortcuts

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