ast

package
v4.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FromMethod          = "from"
	IntoMethod          = "into"
	UpdateMethod        = "update"
	ToMethod            = "to"
	DeleteMethod        = "delete"
	WithKeyword         = "with"
	OnlyKeyword         = "only"
	HeadersKeyword      = "headers"
	HiddenKeyword       = "hidden"
	TimeoutKeyword      = "timeout"
	MaxAgeKeyword       = "max-age"
	SmaxAgeKeyword      = "s-max-age"
	IgnoreErrorsKeyword = "ignore-errors"
	NoMultiplex         = "no-multiplex"
	Base64              = "base64"
	JSON                = "json"
	AsBody              = "as-body"
	Flatten             = "flatten"
)

restQL language keywords.

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 Block

type Block struct {
	Method     string
	Resource   string
	Alias      string
	In         []string
	Qualifiers []Qualifier
}

Block is the syntax node representing a statement.

type Chained

type Chained struct {
	PathVariable string
	PathItem     string
}

Chained is the syntax node representing a chain value.

type Filter

type Filter struct {
	Field []string
	Match *Match
}

Filter is the syntax node representing entries in the `only` clause.

type Generator

type Generator struct{}

Generator encapsulate the parsing implementation used to transform a query string into an AST.

func New

func New() (Generator, error)

New constructs an AST generator.

func (Generator) Parse

func (g Generator) Parse(query string) (*Query, error)

Parse transform a query string into an AST.

type HeaderItem

type HeaderItem struct {
	Key   string
	Value HeaderValue
}

HeaderItem is the syntax node representing an entry of the `headers` clause.

type HeaderValue

type HeaderValue struct {
	Variable *string
	String   *string
	Chain    []Chained
}

HeaderValue is the syntax node representing a `headers` clause entry value.

type KeyValue

type KeyValue struct {
	Key       string
	Value     Value
	Functions []string
}

KeyValue is the syntax node representing parameters in the `with` clause.

type Match

type Match struct {
	String   *string
	Variable *string
}

Match is the syntax node representing the `matches` function.

type MaxAgeValue

type MaxAgeValue variableOrInt

MaxAgeValue is the syntax node representing the value in the `max-age` clause.

type ObjectEntry

type ObjectEntry struct {
	Key   string
	Value Value
}

ObjectEntry is the syntax node representing an object value.

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 ParameterBody

type ParameterBody struct {
	Target    string
	Functions []string
}

ParameterBody is the syntax node representing the dynamic body feature of the `with` clause.

type Parameters

type Parameters struct {
	Body      *ParameterBody
	KeyValues []KeyValue
}

Parameters is the syntax node representing the `with` clause.

type Primitive

type Primitive struct {
	String  *string
	Int     *int
	Float   *float64
	Boolean *bool
	Chain   []Chained
	Null    bool
}

Primitive is the syntax node representing the basic restQL value types.

type Qualifier

type Qualifier struct {
	With         *Parameters
	Only         []Filter
	Headers      []HeaderItem
	Hidden       bool
	Timeout      *TimeoutValue
	MaxAge       *MaxAgeValue
	SMaxAge      *SMaxAgeValue
	IgnoreErrors bool
}

Qualifier is the syntax node representing statement clauses: `with`, `only`, `hidden`, `headers`, `timeout` `max-age`, `s-max-age` and `ignore-errors`.

type Query

type Query struct {
	Use    []Use
	Blocks []Block
}

Query is the root of the restQL AST.

type SMaxAgeValue

type SMaxAgeValue variableOrInt

SMaxAgeValue is the syntax node representing the value in the `s-max-age` clause.

type TimeoutValue

type TimeoutValue variableOrInt

TimeoutValue is the syntax node representing the value in the `timeout` clause.

type Use

type Use struct {
	Key   string
	Value UseValue
}

Use is the syntax node representing the `use` clause.

type UseValue

type UseValue struct {
	Int    *int
	String *string
}

UseValue is the syntax node representing the `use` clause possible values.

type Value

type Value struct {
	List      []Value
	Object    []ObjectEntry
	Variable  *string
	Primitive *Primitive
}

Value is the syntax node representing possible types used in the `with` clause parameters.

Jump to

Keyboard shortcuts

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