ast

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ast ...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Expr

type Expr interface {
	Accept(v Visitor)
}

Expr defines the expression interface for the visitor to operate on the contents of the expression node.

type Filter

type Filter struct {
	Kind Expr
}

Filter stands for a single tq filter. It the fundamental building block of the tq query.

func (*Filter) Accept

func (f *Filter) Accept(v Visitor)

Accept implements the Expr interface for the visitor design pattern.

func (*Filter) String

func (*Filter) String() string

String provides the string representation of the AST expression.

type Identity

type Identity struct{}

Identity specifies the identity data transformation that returns the filtered data argument unchanged.

func (*Identity) Accept

func (i *Identity) Accept(v Visitor)

Accept implements the Expr interface for the visitor design pattern.

func (*Identity) String

func (*Identity) String() string

String provides the string representation of the AST expression.

type Integer

type Integer struct {
	Value string
}

Integer represents your everyday integer. It can be used, for example, as an index of a data point in a sequence or a start/stop index of a span.

func (*Integer) Accept

func (i *Integer) Accept(v Visitor)

Accept implements the Expr interface for the visitor design pattern.

func (*Integer) String

func (i *Integer) String() string

String provides the string representation of the AST expression.

func (*Integer) Vtoi

func (i *Integer) Vtoi() (int, error)

Vtoi returns the value of the Integer expression node converted to a value of the type int.

type Iterator

type Iterator struct{}

Iterator represents a sequeced iterator. The implementation of the iterator for TOML data types is to be provided by the visiting interpreter.

func (*Iterator) Accept

func (i *Iterator) Accept(v Visitor)

Accept implements the Expr interface for the visitor design pattern.

func (*Iterator) String

func (i *Iterator) String() string

String provides the string representation of the AST expression.

type Query

type Query struct {
	Filters []Expr
}

Query represents a single tq query that can be run against a de-serialized TOML data object. It potentially comprises of zero or more filters used to filter the TOML data. Although filters are stored in a slice implying a sequence, the order in not enforced neither by the expression nor the parser. It is the responsibility of the visiting interpreter run against the AST to provide the filtering mechanism.

func (*Query) Accept

func (q *Query) Accept(v Visitor)

Accept implements the Expr interface for the visitor design pattern.

func (*Query) String

func (*Query) String() string

String provides the string representation of the AST expression.

type Root

type Root struct {
	Query Expr
}

Root stands for the top-level root node of the tq query. This version of the tq parser allows a single query, but extending the root to span multiple queries in always an option.

func (*Root) Accept

func (r *Root) Accept(v Visitor)

Accept implements the Expr interface for the visitor design pattern.

func (*Root) String

func (*Root) String() string

String provides the string representation of the AST expression.

type Selector

type Selector struct {
	Value Expr
}

Selector represents a select-driven data filter.

func (*Selector) Accept

func (s *Selector) Accept(v Visitor)

Accept implements the Expr interface for the visitor design pattern.

func (*Selector) String

func (*Selector) String() string

String provides the string representation of the AST expression.

type Span

type Span struct {
	Left, Right *Integer
}

Span represents a filter that takes a slice of a list-like sequence.

func (*Span) Accept

func (s *Span) Accept(v Visitor)

Accept implements the Expr interface for the visitor design pattern.

func (*Span) GetLeft

func (s *Span) GetLeft(def int) int

GetLeft returns the value of the left-hand side expression node of the Span.

func (*Span) GetRight

func (s *Span) GetRight(def int) int

GetRight returns the value of the right-hand side expression node of the Span.

func (*Span) String

func (s *Span) String() string

String provides the string representation of the AST expression.

type String

type String struct {
	Value string
}

String represents the key selector that can be used, for instance, in a form of dictionary lookup.

func (*String) Accept

func (s *String) Accept(v Visitor)

Accept implements the Expr interface for the visitor design pattern.

func (*String) String

func (s *String) String() string

String ...

func (*String) Trim

func (s *String) Trim() string

Trim returns the value of the String expression node with the surrounding quotation marks stripped off.

type Visitor

type Visitor interface {
	VisitRoot(Expr)
	VisitQuery(Expr)
	VisitFilter(Expr)
	VisitIdentity(Expr)
	VisitSelector(Expr)
	VisitIterator(Expr)
	VisitSpan(Expr)
	VisitString(Expr)
	VisitInteger(Expr)
}

Visitor declares the interface for the AST visitor class. It declares signatures invoked by respective AST expression nodes.

Jump to

Keyboard shortcuts

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