ast

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2023 License: GPL-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package ast contains a simple AST for our scripts.

The intention is that the parser will process a list of rules, and will generate a Program which will be executed.

The program will consist of an arbitrary number of assignments, inclusions, and rules.

Index

Constants

This section is empty.

Variables

View Source
var FALSE = &Boolean{Value: false}

FALSE is a global false-value, which simplifies our function returns

View Source
var FUNCTIONS map[string]BuiltIn

FUNCTIONS contains our list of built-in functions, as a map.

The key is the name of the function, and the value is the pointer to the function which is used to implement it.

View Source
var STDIN *bufio.Reader

STDIN is where we read from in our `prompt` function

View Source
var TRUE = &Boolean{Value: true}

TRUE is a global true-value, which simplifies our function returns.

Functions

This section is empty.

Types

type Array added in v0.18.0

type Array struct {
	// Object is our parent object.
	Object

	// Values hold the literal values we contain.
	Values []Object
}

Array is a holder which can contain an arbitrary number of any of our primitive types.

NOTE: Arrays cannot be nested, due to our parser-limitations.

func (Array) Evaluate added in v0.18.0

func (a Array) Evaluate(env *environment.Environment) (string, error)

Evaluate returns the value of the array object.

The evaluation here consists of the joined output of evaluating all the children we contain.

func (Array) String added in v0.18.0

func (a Array) String() string

String returns our object as a string.

type Assign

type Assign struct {
	// Node is our parent object.
	Node

	// Key is the name of the variable.
	Key string

	// Value is the value which will be set.
	Value Object

	// ConditionType holds "if" or "unless" if this assignment
	// action is to be carried out conditionally.
	ConditionType string

	// Function holds a function to call, if this is a conditional
	// action.
	Function Funcall
}

Assign represents a variable assignment.

func (*Assign) String added in v0.12.0

func (a *Assign) String() string

String turns an Assign object into a decent string.

type Backtick added in v0.17.0

type Backtick struct {
	// Object is our parent object.
	Object

	// Value is the command we're to execute.
	Value string
}

Backtick is a value which returns the output of executing a command.

func (Backtick) Evaluate added in v0.17.0

func (b Backtick) Evaluate(env *environment.Environment) (string, error)

Evaluate returns the value of the Backtick object.

func (Backtick) String added in v0.17.0

func (b Backtick) String() string

String returns our object as a string.

type Boolean added in v0.17.0

type Boolean struct {
	// Object is our parent object.
	Object

	// Value is the literal value we hold
	Value bool
}

Boolean represents a true/false value

func (Boolean) Evaluate added in v0.17.0

func (b Boolean) Evaluate(env *environment.Environment) (string, error)

Evaluate returns the value of the Boolean object.

func (Boolean) String added in v0.17.0

func (b Boolean) String() string

String returns our object as a string.

type BuiltIn added in v0.17.0

type BuiltIn func(env *environment.Environment, args []string) (Object, error)

BuiltIn is the signature of a built-in function

type Funcall added in v0.17.0

type Funcall struct {
	// Object is our parent object.
	Object

	// Name is the name of the function to be invoked.
	Name string

	// Arguments are the arguments to be passed to the call.
	Args []Object
}

Funcall represents a function-call.

func (Funcall) Evaluate added in v0.17.0

func (f Funcall) Evaluate(env *environment.Environment) (string, error)

Evaluate returns the value of the function call.

func (Funcall) String added in v0.17.0

func (f Funcall) String() string

String returns our object as a string.

type Include

type Include struct {
	// Node is our parent object.
	Node

	// Source holds the location to include.
	Source Object

	// ConditionType holds "if" or "unless" if this inclusion is to
	// be executed conditionally.
	ConditionType string

	// Function holds a function to call, if this is a conditional
	// action.
	Function Funcall
}

Include represents a file inclusion.

This is produced by the parser by include statements.

func (*Include) String added in v0.12.0

func (i *Include) String() string

String turns an Include object into a useful string.

type Node

type Node interface {

	// String will convert this Node object to a human-readable form.
	String() string
}

Node represents a node that we can process.

type Number added in v0.17.0

type Number struct {
	// Object is our parent object.
	Object

	// Value is the literal number we're holding.
	Value int64
}

Number represents an integer/hexadecimal/octal number.

Note that we support integers only, not floating-point numbers.

func (Number) Evaluate added in v0.17.0

func (n Number) Evaluate(env *environment.Environment) (string, error)

Evaluate returns the value of the Number object.

func (Number) String added in v0.17.0

func (n Number) String() string

String returns our object as a string.

type Object added in v0.17.0

type Object interface {

	// String returns the object contents as a string
	String() string

	// Evaluate returns the value of the literal.
	//
	// The environment is made available because we want to
	// allow variable expansion within strings and backticks.
	Evaluate(env *environment.Environment) (string, error)
}

Object is an interface which must be implemented by anything which will be used as a core-primitive value.

A primitive can be output as a string, and also self-evaluate to return a string-value.

type Program

type Program struct {

	// Recipe contains the list of rule/assignment/include
	// statements we're going to process.
	Recipe []Node
}

Program contains a program

type Rule

type Rule struct {
	// Node is our parent node.
	Node

	// Type contains the rule-type.
	Type string

	// Name contains the name of the rule.
	Name string

	// Triggered is true if this rule is only triggered by
	// another rule notifying it.
	//
	// Triggered rules are ignored when processing our list.
	Triggered bool

	// Parameters contains the params supplied by the user.
	//
	// The keys will be strings, with the values being either
	// a single ast Node, or an array of them.
	//
	Params map[string]interface{}

	// ConditionType holds "if" or "unless" if this rule should
	// be executed only conditionally.
	ConditionType string

	// Function holds a function to call, if this is a conditional
	// action.
	Function Funcall
}

Rule represents a parsed rule.

func (*Rule) String added in v0.12.0

func (r *Rule) String() string

String turns a Rule object into a useful string

type String added in v0.17.0

type String struct {
	// Object is our parent object.
	Object

	// Value is the literal string we've got
	Value string
}

String represents a string literal

func (String) Evaluate added in v0.17.0

func (s String) Evaluate(env *environment.Environment) (string, error)

Evaluate returns the value of the String object.

This means expanding the variables contained within the string.

func (String) String added in v0.17.0

func (s String) String() string

String returns our object as a string.

Jump to

Keyboard shortcuts

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