scripting

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2022 License: LGPL-2.1 Imports: 22 Imported by: 1

Documentation

Index

Constants

View Source
const (
	BlockContext     ContextType = `block`
	StatementContext             = `statement`
	CommandContext               = `command`
)

Variables

View Source
var DefaultIteratorCommandResultVariableName = `result`
View Source
var UnqualifiedModuleName = `core`

This represents the name of a module whose commands do not need to be qualified with a "name::" prefix.

Functions

This section is empty.

Types

type Assignment

type Assignment struct {
	LeftHandSide  []string
	Operator      AssignmentOperator
	RightHandSide []*Expression
	// contains filtered or unexported fields
}

func (*Assignment) String

func (self *Assignment) String() string

type AssignmentOperator

type AssignmentOperator int

func (AssignmentOperator) Evaluate

func (self AssignmentOperator) Evaluate(lhs interface{}, rhs interface{}) (interface{}, error)

func (AssignmentOperator) ShouldPreclear

func (self AssignmentOperator) ShouldPreclear() bool

func (AssignmentOperator) String

func (self AssignmentOperator) String() string

type Block

type Block struct {
	// contains filtered or unexported fields
}

func (*Block) FlowBreak

func (self *Block) FlowBreak() int

func (*Block) FlowContinue

func (self *Block) FlowContinue() int

func (*Block) Script

func (self *Block) Script() *Friendscript

func (*Block) SourceContext

func (self *Block) SourceContext() *Context

Return the character offset and length of this block's source code.

func (*Block) Statements

func (self *Block) Statements() []*Statement

func (*Block) String

func (self *Block) String() string

func (*Block) Type

func (self *Block) Type() BlockType

type BlockType

type BlockType int
const (
	UnknownBlock BlockType = iota
	StatementBlock
	EventHandlerBlock
	FlowControlWord
)

func (BlockType) String

func (self BlockType) String() string

type Command

type Command struct {
	// contains filtered or unexported fields
}

func (*Command) Args

func (self *Command) Args() (first interface{}, second map[string]interface{}, argerr error)

Return the first and (optional) second arguments to a command. If the first argument is nil, but the second argument is not, then the second argument will be returned as first, and the second argument will return as nil. In this way, nil first arguments are collapsed and omitted.

func (*Command) Name

func (self *Command) Name() (string, string)

Return the name of the module the command resides in and the command name.

func (*Command) OutputName

func (self *Command) OutputName() string

Return the name of the variable that command output should be stored in.

func (*Command) Script

func (self *Command) Script() *Friendscript

func (*Command) SetOutputNameOverride

func (self *Command) SetOutputNameOverride(name string)

func (*Command) SourceContext

func (self *Command) SourceContext() *Context

func (*Command) String

func (self *Command) String() string

type Comparator

type Comparator int

func (Comparator) Evaluate

func (self Comparator) Evaluate(lhs *Expression, rhs *Expression) bool

type Conditional

type Conditional struct {
	// contains filtered or unexported fields
}

func (*Conditional) ElseBlocks

func (self *Conditional) ElseBlocks() []*Block

func (*Conditional) ElseIfConditions

func (self *Conditional) ElseIfConditions() []*Conditional

func (*Conditional) IfBlocks

func (self *Conditional) IfBlocks() []*Block

func (*Conditional) IsNegated

func (self *Conditional) IsNegated() bool

func (*Conditional) String

func (self *Conditional) String() string

func (*Conditional) Type

func (self *Conditional) Type() ConditionalType

func (*Conditional) WithAssignment

func (self *Conditional) WithAssignment() (*Assignment, *ConditionalExpression)

Return the objects necessary to perform assignment then evaluate an expression

func (*Conditional) WithCommand

func (self *Conditional) WithCommand() (*Command, *ConditionalExpression)

Return the objects necessary to execute a command then evaluate an expression

func (*Conditional) WithComparator

func (self *Conditional) WithComparator() (*Expression, Comparator, *Expression)

Return the the left- and right-hand sides of an if-test, joined by the comparator.

func (*Conditional) WithRegex

func (self *Conditional) WithRegex() (*Expression, MatchOperator, *regexp.Regexp)

Return the expression, operator, and regular expression in a regex if-test

type ConditionalExpression

type ConditionalExpression struct {
	// contains filtered or unexported fields
}

func NewConditionalExpression

func NewConditionalExpression(statement *Statement, node *node32) *ConditionalExpression

func (*ConditionalExpression) IsTrue

func (self *ConditionalExpression) IsTrue() bool

type ConditionalType

type ConditionalType int
const (
	ConditionWithAssignment ConditionalType = iota
	ConditionWithCommand
	ConditionWithRegex
	ConditionWithComparator
)

func (ConditionalType) String

func (self ConditionalType) String() string

type Context

type Context struct {
	Type                ContextType
	Label               string
	Script              *Friendscript
	Filename            string
	Parent              *Context
	AbsoluteStartOffset int
	Length              int
	Error               error
	StartedAt           time.Time
	Took                time.Duration
}

func (*Context) Snippet

func (self *Context) Snippet() string

func (*Context) String

func (self *Context) String() string

type ContextType

type ContextType string

type Directive

type Directive struct {
	// contains filtered or unexported fields
}

func (*Directive) String

func (self *Directive) String() string

func (*Directive) Type

func (self *Directive) Type() DirectiveType

func (*Directive) VariableNames

func (self *Directive) VariableNames() []string

type DirectiveType

type DirectiveType int
const (
	UnknownDirective DirectiveType = iota
	UnsetDirective
	IncludeDirective
	DeclareDirective
)

func (DirectiveType) String

func (self DirectiveType) String() string

type Expression

type Expression struct {
	// contains filtered or unexported fields
}

func NewExpression

func NewExpression(statement *Statement, node *node32) *Expression

func (*Expression) Script

func (self *Expression) Script() *Friendscript

func (*Expression) String

func (self *Expression) String() string

func (*Expression) Value

func (self *Expression) Value() (interface{}, error)

type FlowControlErr

type FlowControlErr struct {
	Type  FlowControlType
	Level int
}

func NewFlowControl

func NewFlowControl(flowType FlowControlType, levels int) *FlowControlErr

func (FlowControlErr) Error

func (self FlowControlErr) Error() string

type FlowControlType

type FlowControlType int
const (
	FlowBreak FlowControlType = iota
	FlowContinue
)

type Friendscript

type Friendscript struct {
	Buffer string

	Parse  func(rule ...int) error
	Reset  func()
	Pretty bool
	// contains filtered or unexported fields
}

func LoadFromFile

func LoadFromFile(filename string) (*Friendscript, error)

func Parse

func Parse(input string) (*Friendscript, error)

func (*Friendscript) AST

func (t *Friendscript) AST() *node32

func (*Friendscript) Add

func (t *Friendscript) Add(rule pegRule, begin, end, depth uint32, index int)

func (*Friendscript) Blocks

func (self *Friendscript) Blocks() []*Block

Return all top-level blocks in the current script.

func (*Friendscript) Error

func (t *Friendscript) Error() []token32

func (*Friendscript) Expand

func (t *Friendscript) Expand(index int)

func (*Friendscript) Filename

func (self *Friendscript) Filename() string

func (*Friendscript) Highlighter

func (p *Friendscript) Highlighter()

func (*Friendscript) Init

func (p *Friendscript) Init()

func (*Friendscript) Order

func (t *Friendscript) Order() [][]token32

func (*Friendscript) PreOrder

func (t *Friendscript) PreOrder() (<-chan state32, [][]token32)

func (*Friendscript) Print

func (t *Friendscript) Print()

func (*Friendscript) PrintSyntax

func (t *Friendscript) PrintSyntax()

func (*Friendscript) PrintSyntaxTree

func (p *Friendscript) PrintSyntaxTree()

func (*Friendscript) Scope

func (self *Friendscript) Scope() *Scope

func (*Friendscript) SetScope

func (self *Friendscript) SetScope(scope *Scope)

func (*Friendscript) Tokens

func (t *Friendscript) Tokens() <-chan token32

type Loop

type Loop struct {
	// contains filtered or unexported fields
}

func (*Loop) Blocks

func (self *Loop) Blocks() []*Block

func (*Loop) CurrentIndex

func (self *Loop) CurrentIndex() int

func (*Loop) IteratableParts

func (self *Loop) IteratableParts() ([]string, interface{})

func (*Loop) Reset

func (self *Loop) Reset()

func (*Loop) ShouldContinue

func (self *Loop) ShouldContinue() bool

func (*Loop) String

func (self *Loop) String() string

func (*Loop) Type

func (self *Loop) Type() LoopType

func (*Loop) UpperBound

func (self *Loop) UpperBound() int

type LoopType

type LoopType int
const (
	InfiniteLoop LoopType = iota
	FixedLengthLoop
	IteratorLoop
	ConditionBoundedLoop
	WhileLoop
)

func (LoopType) String

func (self LoopType) String() string

type MatchOperator

type MatchOperator int

func (MatchOperator) Evaluate

func (self MatchOperator) Evaluate(pattern *regexp.Regexp, want interface{}) bool

type Resolvable

type Resolvable interface {
	Resolve() interface{}
}

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

func NewEphemeralScope

func NewEphemeralScope(parent *Scope) *Scope

func NewIsolatedScope

func NewIsolatedScope(parent *Scope) *Scope

func NewScope

func NewScope(parent *Scope) *Scope

func (*Scope) Data

func (self *Scope) Data() map[string]interface{}

func (*Scope) Declare

func (self *Scope) Declare(key string)

func (*Scope) EvalContext

func (self *Scope) EvalContext() *Context

Returnt the current evaluation context (if any, may be nil).

func (*Scope) Get

func (self *Scope) Get(key string, fallback ...interface{}) interface{}

func (*Scope) Interpolate

func (self *Scope) Interpolate(in string) string

func (*Scope) IsLocal

func (self *Scope) IsLocal(key string) bool

func (*Scope) Level

func (self *Scope) Level() int

func (*Scope) LockContext

func (self *Scope) LockContext(ctx *Context)

Sets the scope evaluation lock and store the given context.

func (*Scope) MostRecentValue

func (self *Scope) MostRecentValue() interface{}

func (*Scope) OwnerOf

func (self *Scope) OwnerOf(key string) *Scope

Returns the scope that "owns" the given key. This works by first checking for an already-set key in the current scope. If none exists, the parent scope is consulted for non-nil values (and so on, all the way up the scope chain).

If none of the ancestor scopes have a non-nil value at the given key, the current scope becomes the owner of the key and will be returned.

func (*Scope) Set

func (self *Scope) Set(key string, value interface{})

func (*Scope) String

func (self *Scope) String() string

func (*Scope) Unlock

func (self *Scope) Unlock()

Clears the evaluation context and clears the lock.

type Statement

type Statement struct {
	// contains filtered or unexported fields
}

func (*Statement) Assignment

func (self *Statement) Assignment() *Assignment

func (*Statement) Command

func (self *Statement) Command() *Command

func (*Statement) Conditional

func (self *Statement) Conditional() *Conditional

func (*Statement) Directive

func (self *Statement) Directive() *Directive

func (*Statement) Loop

func (self *Statement) Loop() *Loop

func (*Statement) Script

func (self *Statement) Script() *Friendscript

func (*Statement) SourceContext

func (self *Statement) SourceContext() *Context

func (*Statement) Type

func (self *Statement) Type() StatementType

type StatementType

type StatementType int
const (
	UnknownStatement StatementType = iota
	AssignmentStatement
	DirectiveStatement
	ExpressionStatement
	CommandStatement
	ConditionalStatement
	LoopStatement
	FlowControlStatement
	NoOpStatement
)

func (StatementType) String

func (self StatementType) String() string

Jump to

Keyboard shortcuts

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