syntax

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package syntax provides functions for parsing req scripts into their ASTs for evaluation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	Items []Node
	// contains filtered or unexported fields
}

Array represents an array of operands. Arrays defined by the user will contain only a single type, either being a literal, or an array or object. [Items[0], Items[1], ...]

func (Array) Err

func (n Array) Err(msg string) error

func (Array) Pos

func (n Array) Pos() Pos

type AssignStmt

type AssignStmt struct {
	Left  Node
	Right Node
	// contains filtered or unexported fields
}

AssignStmt for assigning values to variables. Left = Right

func (AssignStmt) Err

func (n AssignStmt) Err(msg string) error

func (AssignStmt) Pos

func (n AssignStmt) Pos() Pos

type BlockStmt

type BlockStmt struct {
	Nodes []Node
	// contains filtered or unexported fields
}

BlockStmt for a list of top-level statements, each separated by a semi. {Nodes[0]; Nodes[1]; ...}

func (BlockStmt) Err

func (n BlockStmt) Err(msg string) error

func (BlockStmt) Pos

func (n BlockStmt) Pos() Pos

type BranchStmt

type BranchStmt struct {
	Tok token
	// contains filtered or unexported fields
}

BranchStmt for break or continue statements within a for-loop.

func (BranchStmt) Err

func (n BranchStmt) Err(msg string) error

func (BranchStmt) Pos

func (n BranchStmt) Pos() Pos

type CaseStmt

type CaseStmt struct {
	Value Node
	Then  Node
	// contains filtered or unexported fields
}

CaseStmt for use within a match statement. If the condition of the match statement matches the value, the Then block is executed. Value -> Then Value -> { Then }

func (CaseStmt) Err

func (n CaseStmt) Err(msg string) error

func (CaseStmt) Pos

func (n CaseStmt) Pos() Pos

type ChainExpr

type ChainExpr struct {
	Commands []*CommandStmt
	// contains filtered or unexported fields
}

ChainExpr for using the output of one command as the first argument to a subsequent command. Commands[0] -> Commands[1] -> ...

func (ChainExpr) Err

func (n ChainExpr) Err(msg string) error

func (ChainExpr) Pos

func (n ChainExpr) Pos() Pos

type CommandStmt

type CommandStmt struct {
	Name *Name
	Args []Node
	// contains filtered or unexported fields
}

CommandStmt for the invocation of a command. The arguments passed to the command are space separated. Name Args[0] Args[1] ...

func (CommandStmt) Err

func (n CommandStmt) Err(msg string) error

func (CommandStmt) Pos

func (n CommandStmt) Pos() Pos

type DotExpr

type DotExpr struct {
	Left  Node
	Right Node
	// contains filtered or unexported fields
}

DotExpr for selecting fields on an entity. The left most node of this expression will always be a Ref. $Left.Right

func (DotExpr) Err

func (n DotExpr) Err(msg string) error

func (DotExpr) Pos

func (n DotExpr) Pos() Pos

type ExprList

type ExprList struct {
	Nodes []Node
	// contains filtered or unexported fields
}

ExprList is a list of comma separated expressions. Node[0], Node[1], ...

func (ExprList) Err

func (n ExprList) Err(msg string) error

func (ExprList) Pos

func (n ExprList) Pos() Pos

type ForStmt

type ForStmt struct {
	Init Node
	Cond Node
	Post Node
	Body *BlockStmt
	// contains filtered or unexported fields
}

ForStmt for executing a block code multiple times. for Cond { Body } for Init; Cond; Post { Body }

func (ForStmt) Err

func (n ForStmt) Err(msg string) error

func (ForStmt) Pos

func (n ForStmt) Pos() Pos

type IfStmt

type IfStmt struct {
	Cond Node
	Then Node
	Else Node
	// contains filtered or unexported fields
}

IfStmt for checking the condition and executing the given Then node if that condition evaluates to a truthy value. if Cond { Then } else { Else }

func (IfStmt) Err

func (n IfStmt) Err(msg string) error

func (IfStmt) Pos

func (n IfStmt) Pos() Pos

type IndExpr

type IndExpr struct {
	Left  Node
	Right Node
	// contains filtered or unexported fields
}

IndExpr for accessing items in an indexable type such as an array or an object. The left most node of this expression will always be a Ref. $Left[Right]

func (IndExpr) Err

func (n IndExpr) Err(msg string) error

func (IndExpr) Pos

func (n IndExpr) Pos() Pos

type KeyExpr

type KeyExpr struct {
	Key   *Name
	Value Node
	// contains filtered or unexported fields
}

KeyExpr for defining a key-value pair within an object. The key of this pair is a name and not a string literal. Key: Value

func (KeyExpr) Err

func (n KeyExpr) Err(msg string) error

func (KeyExpr) Pos

func (n KeyExpr) Pos() Pos

type Lit

type Lit struct {
	Type  LitType
	Value string
	// contains filtered or unexported fields
}

Lit represents either a String, Int, or Bool literal. Value

func (Lit) Err

func (n Lit) Err(msg string) error

func (Lit) Pos

func (n Lit) Pos() Pos

type LitType

type LitType uint
const (
	StringLit   LitType = iota + 1 // string
	IntLit                         // int
	FloatLit                       // float
	DurationLit                    // duration
	BoolLit                        // bool
)

func (LitType) String

func (i LitType) String() string

type MatchStmt

type MatchStmt struct {
	Cond    Node
	Cases   []*CaseStmt
	Default Node
	// contains filtered or unexported fields
}

MatchStmt for checking the condition against different literals. The default condition for a match statement is defined with the name _.

match Cond {
    Cases[0];
    Cases[1];
    Default;
}

func (MatchStmt) Err

func (n MatchStmt) Err(msg string) error

func (MatchStmt) Pos

func (n MatchStmt) Pos() Pos

type Name

type Name struct {
	Value string
	// contains filtered or unexported fields
}

Name represents an identifier, such as a variable name, object key, or reference name. Value

func (Name) Err

func (n Name) Err(msg string) error

func (Name) Pos

func (n Name) Pos() Pos

type Node

type Node interface {
	// Pos returns the position the node can be found out in the original
	// source.
	Pos() Pos

	// Err reports an error that occurred at the node's position.
	Err(msg string) error
}

func Parse

func Parse(name string, r io.Reader, errh func(Pos, string)) ([]Node, error)

Parse reads all content from the given reader and parses it into an AST. The given callback is used to reporting any and all errors that may occur during parsing, using the given name for uniquely identifying the parser (typically a filename).

func ParseExpr

func ParseExpr(s string) ([]Node, error)

ParseExpr parses all of the expressions from the given string. This is would be used as part of a REPL to parse each line that is input.

func ParseFile

func ParseFile(fname string, errh func(Pos, string)) ([]Node, error)

ParseFile is a convenience function that parses the given file using Parse.

func ParseRef

func ParseRef(s string) (Node, error)

ParseRef is a convenience function for parsing a single $Ref, $Ref.Dot, or $Ref[Ind] expression. This is used as part of string interpolation. If multiple errors occur during parsing, then the first of these errors is returned.

type Object

type Object struct {
	Pairs []*KeyExpr
	// contains filtered or unexported fields
}

Object is the type for key-value pairs. {Pairs[0], Pairs[1], ...}

func (Object) Err

func (n Object) Err(msg string) error

func (Object) Pos

func (n Object) Pos() Pos

type Op

type Op uint
const (
	EqOp  Op = iota + 1 // ==
	NeqOp               // !=
	LtOp                // <
	LeqOp               // <=
	GtOp                // >
	GeqOp               // >=

	// pseudo-operators
	InOp  // in
	AndOp // and
	OrOp  // or
)

func (Op) String

func (i Op) String() string

type Operation

type Operation struct {
	Op    Op
	Left  Node
	Right Node
	// contains filtered or unexported fields
}

Operation represents a binary expression. Left Op Right

func (Operation) Err

func (n Operation) Err(msg string) error

func (Operation) Pos

func (n Operation) Pos() Pos

type Pos

type Pos struct {
	File string
	Line int
	Col  int
}

func (Pos) Err

func (p Pos) Err(msg string) error

Err records an error at the given position.

func (Pos) String

func (p Pos) String() string

String formats the position into a string. The string will be formatted like so depending on the values present,

File File,Line File,Line:Col

type Range

type Range struct {
	Left  Node
	Right Node
	// contains filtered or unexported fields
}

Range for iterating over iterable values such as arrays and objects. Left = range Right

func (Range) Err

func (n Range) Err(msg string) error

func (Range) Pos

func (n Range) Pos() Pos

type Ref

type Ref struct {
	Left Node
	// contains filtered or unexported fields
}

Ref for referring to previous variable declarations. $Left

func (Ref) Err

func (n Ref) Err(msg string) error

func (Ref) Pos

func (n Ref) Pos() Pos

Jump to

Keyboard shortcuts

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