Documentation ¶
Overview ¶
Package tunascript is an interpretation engine for reading tunascript code and applying it to a running world.
Index ¶
- func TranslateOperators(s string) (string, error)
- type AST
- type Interpreter
- func (interp *Interpreter) AddFlag(label string, val string) error
- func (interp *Interpreter) Eval(code string) (Value, error)
- func (interp *Interpreter) EvalReader(r io.Reader) error
- func (interp *Interpreter) Exec(ast AST) Value
- func (interp *Interpreter) ExecTemplate(ast Template) string
- func (interp *Interpreter) Expand(tmpl string) (string, error)
- func (interp *Interpreter) ExpandReader(r io.Reader) (string, error)
- func (interp *Interpreter) GetFlag(label string) string
- func (interp *Interpreter) Init()
- func (interp *Interpreter) ListFlags() []string
- func (interp *Interpreter) Parse(code string) (ast AST, err error)
- func (interp *Interpreter) ParseReader(r io.Reader) (ast AST, err error)
- func (interp *Interpreter) ParseTemplate(code string) (ast Template, err error)
- func (interp *Interpreter) ParseTemplateReader(r io.Reader) (ast Template, err error)
- type Template
- type Value
- type WorldInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TranslateOperators ¶
TranslateOperators converts the operators in the given TunaScript string to function calls.
Types ¶
type AST ¶
TODO: these should not be aliased like this, aliasing is not intended for use outside of conversion. (Yeah, 8ut we're kind of doing exactly that!) true.
type Interpreter ¶
type Interpreter struct { InitialFlags map[string]Value // Target is where world mutations are applied to. Must be set before // calling Exec or Eval. Target WorldInterface // LastResult is the result of the last statement that was successfully // executed. LastResult Value // File is the name of the file currently being executed by the engine. This // is used in error reporting and is optional to set. File string // contains filtered or unexported fields }
Interpreter reads tunascript code and applies it to a target. The zero-value is ready for use, but Target needs to be assigned to before calling Exec or Eval.
func (*Interpreter) AddFlag ¶
func (interp *Interpreter) AddFlag(label string, val string) error
AddFlag adds a flag to the interpreter's flag store, with an initial value.
func (*Interpreter) Eval ¶
func (interp *Interpreter) Eval(code string) (Value, error)
Eval parses the given string as TunaScript code and applies it immediately. Returns a non-nil error if there is a syntax error in the text. The value of the last valid statement will be in interp.LastResult after Eval returns.
func (*Interpreter) EvalReader ¶
func (interp *Interpreter) EvalReader(r io.Reader) error
EvalReader parses the contents of a Reader as TunaScript code and applies it immediately. Returns a non-nil error if there is a syntax error in the text or if there is an error reading bytes from the Reader. The value of the last valid statement will be in interp.LastResult after EvalReader returns.
func (*Interpreter) Exec ¶
func (interp *Interpreter) Exec(ast AST) Value
Exec executes all statements contained in the AST and returns the result of the last statement. Additionally, interp.LastResult is set to that result. If no statements are in the AST, the returned TSValue will be the zero value and interp.LastResult will not be altered.
This function requires Target to have been set on the interpreter. If it is not set, this function will panic.
func (*Interpreter) ExecTemplate ¶
func (interp *Interpreter) ExecTemplate(ast Template) string
ExecTemplate executes the template represented by the given ExpansionAST and returns the result of expanding it. Additionally, interp.LastResult is set to the last pure TunaScript result executed within the template.
This function does not require Target to have been set on the interpreter.
func (*Interpreter) Expand ¶
func (interp *Interpreter) Expand(tmpl string) (string, error)
Expand parses the given string as a TunaQuest template and expands it into the full contents immediately. Returns a non-nil error if there is a syntax error in the template, in TunaScript within template flow-control statements, or if a non-pure function from TunaScript is within the template.
func (*Interpreter) ExpandReader ¶
func (interp *Interpreter) ExpandReader(r io.Reader) (string, error)
Expand parses the given contents of a Reader as a TunaQuest template and expands it into the full contents immediately. Returns a non-nil error if there is a syntax error in the template, in TunaScript within template flow-control statements, or if a non-pure function from TunaScript is within the template.
func (*Interpreter) GetFlag ¶
func (interp *Interpreter) GetFlag(label string) string
GetFlag gets the give flag's value. If it is unset, it will be "".
func (*Interpreter) Init ¶
func (interp *Interpreter) Init()
Init initializes the interpreter environment. All defined symbols and variables are removed and reset to those defined in InitialFlags, and LastResult is reset. interp.File is not modified.
func (*Interpreter) ListFlags ¶
func (interp *Interpreter) ListFlags() []string
ListFlags returns a list of all flags, sorted.
func (*Interpreter) Parse ¶
func (interp *Interpreter) Parse(code string) (ast AST, err error)
Parse parses (but does not execute) TunaScript code. The code is converted into an AST for further examination.
func (*Interpreter) ParseReader ¶
func (interp *Interpreter) ParseReader(r io.Reader) (ast AST, err error)
ParseReader parses (but does not execute) TunaScript code in the given reader. The entire contents of the Reader are read as TS code, which is returned as an AST for further examination.
func (*Interpreter) ParseTemplate ¶
func (interp *Interpreter) ParseTemplate(code string) (ast Template, err error)
ParseTemplate parses (but does not execute) a block of expandable TunaScript templated text. Any TunaScript within template flow control blocks is also parsed and checked for proper call semantics (i.e. they are checked to make sure only query functions are used, and not ones with side effects).
func (*Interpreter) ParseTemplateReader ¶
func (interp *Interpreter) ParseTemplateReader(r io.Reader) (ast Template, err error)
ParseTemplateReader parses (but does not execute) a block of expandable TunaScript templated text from the given reader. Any TunaScript within template flow control blocks is also parsed and checked for proper call semantics (i.e. they are checked to make sure only query functions are used, and not ones with side effects).
type WorldInterface ¶
type WorldInterface interface { // InInventory returns whether the given label Item is in the player // inventory. InInventory(label string) bool // Move moves the label to the dest. The label can be an NPC or an Item. If // label is "@PLAYER", the player will be moved. Returns whether the thing // moved. Move(label string, dest string) bool // Output prints the given string. Returns whether it did successfully. Output(s string) bool }
Directories ¶
Path | Synopsis |
---|---|
Package fe contains the frontend for analyzing TunaScript code.
|
Package fe contains the frontend for analyzing TunaScript code. |
fetoken
Package fetoken contains the token classes used by the frontend of TunaScript.
|
Package fetoken contains the token classes used by the frontend of TunaScript. |
Package fetmpl contains the frontend for analyzing TunaQuest Template code.
|
Package fetmpl contains the frontend for analyzing TunaQuest Template code. |
fetmpltoken
Package fetmpltoken contains the token classes used by the frontend of TunaQuest Template.
|
Package fetmpltoken contains the token classes used by the frontend of TunaQuest Template. |
Package syntax creates abstract TunaScript and TunaQuest template language constructs from parse trees passed to it from generated frontends.
|
Package syntax creates abstract TunaScript and TunaQuest template language constructs from parse trees passed to it from generated frontends. |