ast

package
v0.58.1-0...-af594cf Latest Latest
Warning

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

Go to latest
Published: May 1, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package ast declares the types used to represent the syntax tree for Flux source code.

Index

Constants

View Source
const (
	NanosecondUnit  = "ns"
	MicrosecondUnit = "us"
	MillisecondUnit = "ms"
	SecondUnit      = "s"
	MinuteUnit      = "m"
	HourUnit        = "h"
	DayUnit         = "d"
	WeekUnit        = "w"
	MonthUnit       = "mo"
	YearUnit        = "y"
)

Variables

View Source
var LogicalOperatorTokens = map[LogicalOperatorKind]string{
	AndOperator: "and",
	OrOperator:  "or",
}

LogicalOperatorTokens converts LogicalOperatorKind to string

OperatorTokens converts OperatorKind to string

Functions

func Check

func Check(root Node) int

Check will inspect each node and annotate it with any AST errors. It will return the number of errors that were found.

func DurationFrom

func DurationFrom(l *DurationLiteral, _ time.Time) (time.Duration, error)

Duration gives you a DurationLiteral from a time.Duration. Currently this is an approximation, but since we accept time, it can be made exact. TODO: makes this exact and not an approximation. currently the time.Time is ignored

func Format

func Format(n Node) string

Returns a valid script for a given AST rooted at node `n`. Formatting rules:

  • In a list of statements, if two statements are of a different type (e.g. an `OptionStatement` followed by an `ExpressionStatement`), they are separated by a double newline.
  • In a function call (or object definition), if the arguments (or properties) are more than 3, they are split into multiple lines.

func GetError

func GetError(n Node) error

GetError will return the first error within an AST.

func GetErrors

func GetErrors(n Node) (errs []error)

GetErrors will return each of the errors within an AST.

func PrintErrors

func PrintErrors(w io.Writer, root Node)

PrintErrors will format the errors within the AST and output them to the writer.

func Visit

func Visit(node Node, f func(Node))

func Walk

func Walk(v Visitor, node Node)

Walk recursively visits every children of a given `Node` given a `Visitor`. It performs a pre-order visit of the AST (visit parent node, then visit children from left to right). If a call to `Visit` for a node returns a nil visitor, walk stops and doesn't visit the AST rooted at that node, otherwise it uses the returned visitor to continue walking. Once Walk has finished visiting a node (the node itself and its children), it invokes `Done` on the node's visitor. NOTE: `Walk` doesn't visit `nil` nodes.

Types

type ArrayExpression

type ArrayExpression struct {
	BaseNode
	Elements []Expression `json:"elements"`
}

ArrayExpression is used to create and directly specify the elements of an array object

func (*ArrayExpression) Copy

func (e *ArrayExpression) Copy() Node

func (ArrayExpression) FromBuf

func (*ArrayExpression) MarshalJSON

func (e *ArrayExpression) MarshalJSON() ([]byte, error)

func (*ArrayExpression) Type

func (*ArrayExpression) Type() string

Type is the abstract type

func (*ArrayExpression) UnmarshalJSON

func (e *ArrayExpression) UnmarshalJSON(data []byte) error

type Assignment

type Assignment interface {
	Statement
	// contains filtered or unexported methods
}

type BadStatement

type BadStatement struct {
	BaseNode
	Text string `json:"text"`
}

BadStatement is a placeholder for statements for which no correct statement nodes can be created.

func (*BadStatement) Copy

func (s *BadStatement) Copy() Node

func (BadStatement) FromBuf

func (s BadStatement) FromBuf(buf *fbast.BadStatement) *BadStatement

func (*BadStatement) MarshalJSON

func (s *BadStatement) MarshalJSON() ([]byte, error)

func (*BadStatement) Type

func (*BadStatement) Type() string

Type is the abstract type.

type BaseNode

type BaseNode struct {
	Loc    *SourceLocation `json:"location,omitempty"`
	Errors []Error         `json:"errors,omitempty"`
}

BaseNode holds the attributes every expression or statement should have

func (BaseNode) Copy

func (b BaseNode) Copy() BaseNode

func (BaseNode) Errs

func (b BaseNode) Errs() []Error

func (*BaseNode) FromBuf

func (b *BaseNode) FromBuf(buf *fbast.BaseNode)

func (BaseNode) Location

func (b BaseNode) Location() SourceLocation

Location is the source location of the Node

type BinaryExpression

type BinaryExpression struct {
	BaseNode
	Operator OperatorKind `json:"operator"`
	Left     Expression   `json:"left"`
	Right    Expression   `json:"right"`
}

BinaryExpression use binary operators act on two operands in an expression. BinaryExpression includes relational and arithmetic operators

func (*BinaryExpression) Copy

func (e *BinaryExpression) Copy() Node

func (BinaryExpression) FromBuf

func (*BinaryExpression) MarshalJSON

func (e *BinaryExpression) MarshalJSON() ([]byte, error)

func (*BinaryExpression) Type

func (*BinaryExpression) Type() string

Type is the abstract type

func (*BinaryExpression) UnmarshalJSON

func (e *BinaryExpression) UnmarshalJSON(data []byte) error

type Block

type Block struct {
	BaseNode
	Body []Statement `json:"body"`
}

Block is a set of statements

func (*Block) Copy

func (s *Block) Copy() Node

func (Block) FromBuf

func (s Block) FromBuf(buf *fbast.Block) *Block

func (*Block) MarshalJSON

func (s *Block) MarshalJSON() ([]byte, error)

func (*Block) Type

func (*Block) Type() string

Type is the abstract type

func (*Block) UnmarshalJSON

func (s *Block) UnmarshalJSON(data []byte) error

type BooleanLiteral

type BooleanLiteral struct {
	BaseNode
	Value bool `json:"value"`
}

BooleanLiteral represent boolean values

func (*BooleanLiteral) Copy

func (l *BooleanLiteral) Copy() Node

func (BooleanLiteral) FromBuf

func (*BooleanLiteral) MarshalJSON

func (l *BooleanLiteral) MarshalJSON() ([]byte, error)

func (*BooleanLiteral) Type

func (*BooleanLiteral) Type() string

Type is the abstract type

type BuiltinStatement

type BuiltinStatement struct {
	BaseNode
	ID *Identifier `json:"id"`
}

BuiltinStatement declares a builtin identifier and its type

func (*BuiltinStatement) Copy

func (s *BuiltinStatement) Copy() Node

Copy returns a deep copy of an BuiltinStatement Node

func (BuiltinStatement) FromBuf

func (*BuiltinStatement) MarshalJSON

func (s *BuiltinStatement) MarshalJSON() ([]byte, error)

func (*BuiltinStatement) Type

func (*BuiltinStatement) Type() string

Type is the abstract type

type CallExpression

type CallExpression struct {
	BaseNode
	Callee    Expression   `json:"callee"`
	Arguments []Expression `json:"arguments,omitempty"`
}

CallExpression represents a function call

func (*CallExpression) Copy

func (e *CallExpression) Copy() Node

func (CallExpression) FromBuf

func (*CallExpression) MarshalJSON

func (e *CallExpression) MarshalJSON() ([]byte, error)

func (*CallExpression) Type

func (*CallExpression) Type() string

Type is the abstract type

func (*CallExpression) UnmarshalJSON

func (e *CallExpression) UnmarshalJSON(data []byte) error

type ConditionalExpression

type ConditionalExpression struct {
	BaseNode
	Test       Expression `json:"test"`
	Consequent Expression `json:"consequent"`
	Alternate  Expression `json:"alternate"`
}

ConditionalExpression selects one of two expressions, `Alternate` or `Consequent` depending on a third, boolean, expression, `Test`.

func (*ConditionalExpression) Copy

func (e *ConditionalExpression) Copy() Node

func (ConditionalExpression) FromBuf

func (*ConditionalExpression) MarshalJSON

func (e *ConditionalExpression) MarshalJSON() ([]byte, error)

func (*ConditionalExpression) Type

func (*ConditionalExpression) Type() string

Type is the abstract type

func (*ConditionalExpression) UnmarshalJSON

func (e *ConditionalExpression) UnmarshalJSON(data []byte) error

type DateTimeLiteral

type DateTimeLiteral struct {
	BaseNode
	Value time.Time `json:"value"`
}

DateTimeLiteral represents an instant in time with nanosecond precision using the syntax of golang's RFC3339 Nanosecond variant TODO: this may be better as a class initialization

func (*DateTimeLiteral) Copy

func (l *DateTimeLiteral) Copy() Node

func (DateTimeLiteral) FromBuf

func (*DateTimeLiteral) MarshalJSON

func (l *DateTimeLiteral) MarshalJSON() ([]byte, error)

func (*DateTimeLiteral) Type

func (*DateTimeLiteral) Type() string

Type is the abstract type

type Duration

type Duration struct {
	Magnitude int64  `json:"magnitude"`
	Unit      string `json:"unit"`
}

Duration is a pair consisting of length of time and the unit of time measured. It is the atomic unit from which all duration literals are composed.

func (Duration) FromBuf

func (d Duration) FromBuf(buf *fbast.Duration) Duration

type DurationLiteral

type DurationLiteral struct {
	BaseNode
	Values []Duration `json:"values"`
}

DurationLiteral represents the elapsed time between two instants as an int64 nanosecond count with syntax of golang's time.Duration TODO: this may be better as a class initialization

func (*DurationLiteral) Copy

func (l *DurationLiteral) Copy() Node

func (DurationLiteral) FromBuf

func (*DurationLiteral) MarshalJSON

func (l *DurationLiteral) MarshalJSON() ([]byte, error)

func (*DurationLiteral) Type

func (*DurationLiteral) Type() string

Type is the abstract type

type Error

type Error struct {
	Msg string `json:"msg"`
}

Error represents an error in the AST construction. The node that this is attached to is not valid.

func (Error) Error

func (e Error) Error() string

type Expression

type Expression interface {
	Node
	// contains filtered or unexported methods
}

Expression represents an action that can be performed by InfluxDB that can be evaluated to a value.

type ExpressionStatement

type ExpressionStatement struct {
	BaseNode
	Expression Expression `json:"expression"`
}

ExpressionStatement may consist of an expression that does not return a value and is executed solely for its side-effects.

func (*ExpressionStatement) Copy

func (s *ExpressionStatement) Copy() Node

func (ExpressionStatement) FromBuf

func (*ExpressionStatement) MarshalJSON

func (s *ExpressionStatement) MarshalJSON() ([]byte, error)

func (*ExpressionStatement) Type

func (*ExpressionStatement) Type() string

Type is the abstract type

func (*ExpressionStatement) UnmarshalJSON

func (s *ExpressionStatement) UnmarshalJSON(data []byte) error

type File

type File struct {
	BaseNode
	Name     string               `json:"name,omitempty"` // name of the file
	Metadata string               `json:"metadata,omitempty"`
	Package  *PackageClause       `json:"package"`
	Imports  []*ImportDeclaration `json:"imports"`
	Body     []Statement          `json:"body"`
}

File represents a source from a single file

func (*File) Copy

func (f *File) Copy() Node

func (File) FromBuf

func (f File) FromBuf(buf *fbast.File) *File

func (*File) MarshalJSON

func (f *File) MarshalJSON() ([]byte, error)

func (*File) Type

func (*File) Type() string

Type is the abstract type

func (*File) UnmarshalJSON

func (f *File) UnmarshalJSON(data []byte) error

type FloatLiteral

type FloatLiteral struct {
	BaseNode
	Value float64 `json:"value"`
}

FloatLiteral represent floating point numbers according to the double representations defined by the IEEE-754-1985

func (*FloatLiteral) Copy

func (l *FloatLiteral) Copy() Node

func (FloatLiteral) FromBuf

func (l FloatLiteral) FromBuf(buf *fbast.FloatLiteral) *FloatLiteral

func (*FloatLiteral) MarshalJSON

func (l *FloatLiteral) MarshalJSON() ([]byte, error)

func (*FloatLiteral) Type

func (*FloatLiteral) Type() string

Type is the abstract type

type FunctionExpression

type FunctionExpression struct {
	BaseNode
	Params []*Property `json:"params"`
	Body   Node        `json:"body"`
}

func (*FunctionExpression) Copy

func (e *FunctionExpression) Copy() Node

func (FunctionExpression) FromBuf

func (*FunctionExpression) MarshalJSON

func (e *FunctionExpression) MarshalJSON() ([]byte, error)

func (*FunctionExpression) Type

func (*FunctionExpression) Type() string

Type is the abstract type

func (*FunctionExpression) UnmarshalJSON

func (e *FunctionExpression) UnmarshalJSON(data []byte) error

type Identifier

type Identifier struct {
	BaseNode
	Name string `json:"name"`
}

Identifier represents a name that identifies a unique Node

func (*Identifier) Copy

func (i *Identifier) Copy() Node

func (Identifier) FromBuf

func (i Identifier) FromBuf(buf *fbast.Identifier) *Identifier

func (*Identifier) Key

func (i *Identifier) Key() string

Identifiers are valid object keys

func (*Identifier) MarshalJSON

func (i *Identifier) MarshalJSON() ([]byte, error)

func (*Identifier) Type

func (*Identifier) Type() string

Type is the abstract type

type ImportDeclaration

type ImportDeclaration struct {
	BaseNode
	As   *Identifier    `json:"as"`
	Path *StringLiteral `json:"path"`
}

ImportDeclaration declares a single import

func (*ImportDeclaration) Copy

func (d *ImportDeclaration) Copy() Node

func (ImportDeclaration) FromBuf

func (*ImportDeclaration) MarshalJSON

func (d *ImportDeclaration) MarshalJSON() ([]byte, error)

func (*ImportDeclaration) Type

func (*ImportDeclaration) Type() string

Type is the abstract type

type IndexExpression

type IndexExpression struct {
	BaseNode
	Array Expression `json:"array"`
	Index Expression `json:"index"`
}

IndexExpression represents indexing into an array

func (*IndexExpression) Copy

func (e *IndexExpression) Copy() Node

func (IndexExpression) FromBuf

func (*IndexExpression) MarshalJSON

func (e *IndexExpression) MarshalJSON() ([]byte, error)

func (*IndexExpression) Type

func (*IndexExpression) Type() string

func (*IndexExpression) UnmarshalJSON

func (e *IndexExpression) UnmarshalJSON(data []byte) error

type IntegerLiteral

type IntegerLiteral struct {
	BaseNode
	Value int64 `json:"value"`
}

IntegerLiteral represent integer numbers.

func (*IntegerLiteral) Copy

func (l *IntegerLiteral) Copy() Node

func (IntegerLiteral) FromBuf

func (*IntegerLiteral) MarshalJSON

func (l *IntegerLiteral) MarshalJSON() ([]byte, error)

func (*IntegerLiteral) Type

func (*IntegerLiteral) Type() string

Type is the abstract type

func (*IntegerLiteral) UnmarshalJSON

func (l *IntegerLiteral) UnmarshalJSON(data []byte) error

type InterpolatedPart

type InterpolatedPart struct {
	BaseNode
	Expression Expression `json:"expression"`
}

func (*InterpolatedPart) Copy

func (p *InterpolatedPart) Copy() Node

func (InterpolatedPart) FromBuf

func (*InterpolatedPart) MarshalJSON

func (p *InterpolatedPart) MarshalJSON() ([]byte, error)

func (*InterpolatedPart) Type

func (*InterpolatedPart) Type() string

func (*InterpolatedPart) UnmarshalJSON

func (p *InterpolatedPart) UnmarshalJSON(data []byte) error

type Literal

type Literal interface {
	Expression
	// contains filtered or unexported methods
}

Literal is the lexical form for a literal expression which defines boolean, string, integer, number, duration, datetime or field values. Literals must be coerced explicitly.

type LogicalExpression

type LogicalExpression struct {
	BaseNode
	Operator LogicalOperatorKind `json:"operator"`
	Left     Expression          `json:"left"`
	Right    Expression          `json:"right"`
}

LogicalExpression represent the rule conditions that collectively evaluate to either true or false. `or` expressions compute the disjunction of two boolean expressions and return boolean values. `and“ expressions compute the conjunction of two boolean expressions and return boolean values.

func (*LogicalExpression) Copy

func (e *LogicalExpression) Copy() Node

func (LogicalExpression) FromBuf

func (*LogicalExpression) MarshalJSON

func (e *LogicalExpression) MarshalJSON() ([]byte, error)

func (*LogicalExpression) Type

func (*LogicalExpression) Type() string

Type is the abstract type

func (*LogicalExpression) UnmarshalJSON

func (e *LogicalExpression) UnmarshalJSON(data []byte) error

type LogicalOperatorKind

type LogicalOperatorKind int

LogicalOperatorKind are used with boolean (logical) values

const (
	AndOperator LogicalOperatorKind
	OrOperator
)

func LogicalOperatorLookup

func LogicalOperatorLookup(op string) LogicalOperatorKind

LogicalOperatorLookup converts the operators to LogicalOperatorKind

func (LogicalOperatorKind) MarshalText

func (o LogicalOperatorKind) MarshalText() ([]byte, error)

func (LogicalOperatorKind) String

func (o LogicalOperatorKind) String() string

func (*LogicalOperatorKind) UnmarshalText

func (o *LogicalOperatorKind) UnmarshalText(data []byte) error

type MemberAssignment

type MemberAssignment struct {
	BaseNode
	Member *MemberExpression `json:"member"`
	Init   Expression        `json:"init"`
}

func (*MemberAssignment) Copy

func (a *MemberAssignment) Copy() Node

func (MemberAssignment) FromBuf

func (*MemberAssignment) MarshalJSON

func (a *MemberAssignment) MarshalJSON() ([]byte, error)

func (*MemberAssignment) Type

func (*MemberAssignment) Type() string

func (*MemberAssignment) UnmarshalJSON

func (a *MemberAssignment) UnmarshalJSON(data []byte) error

type MemberExpression

type MemberExpression struct {
	BaseNode
	Object   Expression  `json:"object"`
	Property PropertyKey `json:"property"`
}

MemberExpression represents calling a property of a CallExpression

func (*MemberExpression) Copy

func (e *MemberExpression) Copy() Node

func (MemberExpression) FromBuf

func (*MemberExpression) MarshalJSON

func (e *MemberExpression) MarshalJSON() ([]byte, error)

func (*MemberExpression) Type

func (*MemberExpression) Type() string

Type is the abstract type

func (*MemberExpression) UnmarshalJSON

func (e *MemberExpression) UnmarshalJSON(data []byte) error

type Node

type Node interface {
	Type() string // Type property is a string that contains the variant type of the node
	Location() SourceLocation
	Errs() []Error
	Copy() Node

	// All node must support json marshalling
	json.Marshaler
	// contains filtered or unexported methods
}

Node represents a node in the InfluxDB abstract syntax tree.

func UnmarshalNode

func UnmarshalNode(data []byte) (Node, error)

type ObjectExpression

type ObjectExpression struct {
	BaseNode
	With       *Identifier `json:"with,omitempty"`
	Properties []*Property `json:"properties"`
}

ObjectExpression allows the declaration of an anonymous object within a declaration.

func (*ObjectExpression) Copy

func (e *ObjectExpression) Copy() Node

func (ObjectExpression) FromBuf

func (*ObjectExpression) MarshalJSON

func (e *ObjectExpression) MarshalJSON() ([]byte, error)

func (*ObjectExpression) Type

func (*ObjectExpression) Type() string

Type is the abstract type

type OperatorKind

type OperatorKind int

OperatorKind are Equality and Arithmatic operators. Result of evaluating an equality operator is always of type Boolean based on whether the comparison is true Arithmetic operators take numerical values (either literals or variables) as their operands

and return a single numerical value.
const (
	MultiplicationOperator OperatorKind
	DivisionOperator
	ModuloOperator
	PowerOperator
	AdditionOperator
	SubtractionOperator
	LessThanEqualOperator
	LessThanOperator
	GreaterThanEqualOperator
	GreaterThanOperator
	StartsWithOperator
	InOperator
	NotOperator
	ExistsOperator
	NotEmptyOperator
	EmptyOperator
	EqualOperator
	NotEqualOperator
	RegexpMatchOperator
	NotRegexpMatchOperator
)

func OperatorLookup

func OperatorLookup(op string) OperatorKind

OperatorLookup converts the operators to OperatorKind

func (OperatorKind) MarshalText

func (o OperatorKind) MarshalText() ([]byte, error)

func (OperatorKind) String

func (o OperatorKind) String() string

func (*OperatorKind) UnmarshalText

func (o *OperatorKind) UnmarshalText(data []byte) error

type OptionStatement

type OptionStatement struct {
	BaseNode
	Assignment Assignment `json:"assignment"`
}

OptionStatement syntactically is a single variable declaration

func (*OptionStatement) Copy

func (s *OptionStatement) Copy() Node

Copy returns a deep copy of an OptionStatement Node

func (OptionStatement) FromBuf

func (*OptionStatement) MarshalJSON

func (s *OptionStatement) MarshalJSON() ([]byte, error)

func (*OptionStatement) Type

func (*OptionStatement) Type() string

Type is the abstract type

func (*OptionStatement) UnmarshalJSON

func (s *OptionStatement) UnmarshalJSON(data []byte) error

type Package

type Package struct {
	BaseNode
	Path    string  `json:"path,omitempty"`
	Package string  `json:"package"`
	Files   []*File `json:"files"`
}

Package represents a complete package source tree

func DeserializeFromFlatBuffer

func DeserializeFromFlatBuffer(buf []byte) *Package

DeserializeFromFlatBuffer takes the given byte slice that is an AST flatbuffer and deserializes it to an AST package.

func (*Package) Copy

func (p *Package) Copy() Node

func (Package) FromBuf

func (p Package) FromBuf(buf []byte) *Package

func (*Package) MarshalJSON

func (p *Package) MarshalJSON() ([]byte, error)

func (*Package) Type

func (*Package) Type() string

Type is the abstract type

type PackageClause

type PackageClause struct {
	BaseNode
	Name *Identifier `json:"name"`
}

PackageClause defines the current package identifier.

func (*PackageClause) Copy

func (c *PackageClause) Copy() Node

func (PackageClause) FromBuf

func (*PackageClause) MarshalJSON

func (c *PackageClause) MarshalJSON() ([]byte, error)

func (*PackageClause) Type

func (*PackageClause) Type() string

Type is the abstract type

type ParenExpression

type ParenExpression struct {
	BaseNode
	Expression Expression `json:"expression"`
}

ParenExpression represents an expressions that is wrapped in parentheses in the source code. It has no semantic meaning, rather it only communicates information about the syntax of the source code.

func (*ParenExpression) Copy

func (e *ParenExpression) Copy() Node

func (ParenExpression) FromBuf

func (*ParenExpression) MarshalJSON

func (e *ParenExpression) MarshalJSON() ([]byte, error)

func (*ParenExpression) Type

func (*ParenExpression) Type() string

func (*ParenExpression) UnmarshalJSON

func (e *ParenExpression) UnmarshalJSON(data []byte) error

type PipeExpression

type PipeExpression struct {
	BaseNode
	Argument Expression      `json:"argument"`
	Call     *CallExpression `json:"call"`
}

func (*PipeExpression) Copy

func (e *PipeExpression) Copy() Node

func (PipeExpression) FromBuf

func (*PipeExpression) MarshalJSON

func (e *PipeExpression) MarshalJSON() ([]byte, error)

func (*PipeExpression) Type

func (*PipeExpression) Type() string

Type is the abstract type

func (*PipeExpression) UnmarshalJSON

func (e *PipeExpression) UnmarshalJSON(data []byte) error

type PipeLiteral

type PipeLiteral struct {
	BaseNode
}

PipeLiteral represents an specialized literal value, indicating the left hand value of a pipe expression.

func (*PipeLiteral) Copy

func (p *PipeLiteral) Copy() Node

func (PipeLiteral) FromBuf

func (p PipeLiteral) FromBuf(buf *fbast.PipeLiteral) *PipeLiteral

func (*PipeLiteral) MarshalJSON

func (p *PipeLiteral) MarshalJSON() ([]byte, error)

func (*PipeLiteral) Type

func (*PipeLiteral) Type() string

Type is the abstract type

type Position

type Position struct {
	Line   int `json:"line"`   // Line is the line in the source marked by this position
	Column int `json:"column"` // Column is the column in the source marked by this position
}

Position represents a specific location in the source

func (*Position) FromBuf

func (p *Position) FromBuf(buf *fbast.Position)

func (Position) IsValid

func (p Position) IsValid() bool

func (Position) Less

func (p Position) Less(o Position) bool

func (Position) String

func (p Position) String() string

type Property

type Property struct {
	BaseNode
	Key   PropertyKey `json:"key"`
	Value Expression  `json:"value"`
}

Property is the value associated with a key. A property's key can be either an identifier or string literal.

func (*Property) Copy

func (p *Property) Copy() Node

func (Property) FromBuf

func (p Property) FromBuf(buf *fbast.Property) *Property

func (*Property) MarshalJSON

func (p *Property) MarshalJSON() ([]byte, error)

func (*Property) Type

func (*Property) Type() string

Type is the abstract type

func (*Property) UnmarshalJSON

func (p *Property) UnmarshalJSON(data []byte) error

type PropertyKey

type PropertyKey interface {
	Node
	Key() string
}

PropertyKey represents an object key

type RegexpLiteral

type RegexpLiteral struct {
	BaseNode
	Value *regexp.Regexp `json:"value"`
}

RegexpLiteral expressions begin and end with `/` and are regular expressions with syntax accepted by RE2

func (*RegexpLiteral) Copy

func (l *RegexpLiteral) Copy() Node

func (RegexpLiteral) FromBuf

func (*RegexpLiteral) MarshalJSON

func (l *RegexpLiteral) MarshalJSON() ([]byte, error)

func (*RegexpLiteral) Type

func (*RegexpLiteral) Type() string

Type is the abstract type

func (*RegexpLiteral) UnmarshalJSON

func (l *RegexpLiteral) UnmarshalJSON(data []byte) error

type ReturnStatement

type ReturnStatement struct {
	BaseNode
	Argument Expression `json:"argument"`
}

ReturnStatement defines an Expression to return

func (*ReturnStatement) Copy

func (s *ReturnStatement) Copy() Node

func (ReturnStatement) FromBuf

func (*ReturnStatement) MarshalJSON

func (s *ReturnStatement) MarshalJSON() ([]byte, error)

func (*ReturnStatement) Type

func (*ReturnStatement) Type() string

Type is the abstract type

func (*ReturnStatement) UnmarshalJSON

func (s *ReturnStatement) UnmarshalJSON(data []byte) error

type SourceLocation

type SourceLocation struct {
	File   string   `json:"file,omitempty"`
	Start  Position `json:"start"`            // Start is the location in the source the node starts
	End    Position `json:"end"`              // End is the location in the source the node ends
	Source string   `json:"source,omitempty"` // Source is optional raw source
}

SourceLocation represents the location of a node in the AST

func (*SourceLocation) Copy

func (l *SourceLocation) Copy() *SourceLocation

func (SourceLocation) FromBuf

func (SourceLocation) IsValid

func (l SourceLocation) IsValid() bool

func (SourceLocation) Less

func (SourceLocation) String

func (l SourceLocation) String() string

type Statement

type Statement interface {
	Node
	// contains filtered or unexported methods
}

Statement Perhaps we don't even want statements nor expression statements

type StringExpression

type StringExpression struct {
	BaseNode

	Parts []StringExpressionPart `json:"parts"`
}

func (*StringExpression) Copy

func (e *StringExpression) Copy() Node

func (StringExpression) FromBuf

func (*StringExpression) MarshalJSON

func (e *StringExpression) MarshalJSON() ([]byte, error)

func (*StringExpression) Type

func (*StringExpression) Type() string

func (*StringExpression) UnmarshalJSON

func (e *StringExpression) UnmarshalJSON(data []byte) error

type StringExpressionPart

type StringExpressionPart interface {
	Node
	// contains filtered or unexported methods
}

type StringLiteral

type StringLiteral struct {
	BaseNode
	// Value is the unescaped value of the string literal
	Value string `json:"value"`
}

StringLiteral expressions begin and end with double quote marks.

func (*StringLiteral) Copy

func (l *StringLiteral) Copy() Node

func (StringLiteral) FromBuf

func (*StringLiteral) Key

func (l *StringLiteral) Key() string

StringLiterals are valid object keys

func (*StringLiteral) MarshalJSON

func (l *StringLiteral) MarshalJSON() ([]byte, error)

func (*StringLiteral) Type

func (*StringLiteral) Type() string

type TestStatement

type TestStatement struct {
	BaseNode
	Assignment *VariableAssignment `json:"assignment"`
}

TestStatement declares a Flux test case

func (*TestStatement) Copy

func (s *TestStatement) Copy() Node

Copy returns a deep copy of a TestStatement Node

func (TestStatement) FromBuf

func (*TestStatement) MarshalJSON

func (s *TestStatement) MarshalJSON() ([]byte, error)

func (*TestStatement) Type

func (*TestStatement) Type() string

Type is the abstract type

type TextPart

type TextPart struct {
	BaseNode
	Value string `json:"value"`
}

func (*TextPart) Copy

func (p *TextPart) Copy() Node

func (TextPart) FromBuf

func (p TextPart) FromBuf(buf *fbast.StringExpressionPart) *TextPart

func (*TextPart) MarshalJSON

func (p *TextPart) MarshalJSON() ([]byte, error)

func (*TextPart) Type

func (*TextPart) Type() string

func (*TextPart) UnmarshalJSON

func (p *TextPart) UnmarshalJSON(data []byte) error

type UnaryExpression

type UnaryExpression struct {
	BaseNode
	Operator OperatorKind `json:"operator"`
	Argument Expression   `json:"argument"`
}

UnaryExpression use operators act on a single operand in an expression.

func (*UnaryExpression) Copy

func (e *UnaryExpression) Copy() Node

func (UnaryExpression) FromBuf

func (*UnaryExpression) MarshalJSON

func (e *UnaryExpression) MarshalJSON() ([]byte, error)

func (*UnaryExpression) Type

func (*UnaryExpression) Type() string

Type is the abstract type

func (*UnaryExpression) UnmarshalJSON

func (e *UnaryExpression) UnmarshalJSON(data []byte) error

type UnsignedIntegerLiteral

type UnsignedIntegerLiteral struct {
	BaseNode
	Value uint64 `json:"value"`
}

UnsignedIntegerLiteral represent integer numbers.

func (*UnsignedIntegerLiteral) Copy

func (l *UnsignedIntegerLiteral) Copy() Node

func (UnsignedIntegerLiteral) FromBuf

func (*UnsignedIntegerLiteral) MarshalJSON

func (l *UnsignedIntegerLiteral) MarshalJSON() ([]byte, error)

func (*UnsignedIntegerLiteral) Type

Type is the abstract type

func (*UnsignedIntegerLiteral) UnmarshalJSON

func (l *UnsignedIntegerLiteral) UnmarshalJSON(data []byte) error

type VariableAssignment

type VariableAssignment struct {
	BaseNode
	ID   *Identifier `json:"id"`
	Init Expression  `json:"init"`
}

VariableAssignment represents the declaration of a variable

func (*VariableAssignment) Copy

func (d *VariableAssignment) Copy() Node

func (VariableAssignment) FromBuf

func (*VariableAssignment) MarshalJSON

func (d *VariableAssignment) MarshalJSON() ([]byte, error)

func (*VariableAssignment) Type

func (*VariableAssignment) Type() string

Type is the abstract type

func (*VariableAssignment) UnmarshalJSON

func (d *VariableAssignment) UnmarshalJSON(data []byte) error

type Visitor

type Visitor interface {
	Visit(node Node) Visitor
	Done(node Node)
}

Visitor implements the visitor pattern.

When used with the Walk function, Visit will be called for every node in depth-first order. After all children for a Node have been visted, Done is called on that Node to signal that we are done with that Node.

If Visit returns nil, Walk will not recurse on the children. Neither Visit nor Done will be invoked on nil nodes.

func CreateVisitor

func CreateVisitor(f func(Node)) Visitor

Directories

Path Synopsis
Package asttest implements utilities for testing the abstract syntax tree.
Package asttest implements utilities for testing the abstract syntax tree.
internal
fbast
Package fbast contains code generated by the FlatBuffers compiler for serializing AST.
Package fbast contains code generated by the FlatBuffers compiler for serializing AST.

Jump to

Keyboard shortcuts

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