yack

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: BSD-3-Clause Imports: 12 Imported by: 1

Documentation

Overview

Package yack reads and runs yack dialogs.

The EBNF grammar for yack files:

SourceFile = { Line } .

Line = [ (LabelTag | ConditionalStatement) ] [ comment ] newline .

LabelTag = ":" label .

ConditionalStatement = Statement { Condition } .

Condition = "[" ("once" | "showonce" | "onceever" | "showonceever" |
                 "temponce" | actor_name | Code) "]" .

Statement = SayStmt | GotoStmt | ExecuteStmt | ChoiceStmt | ShutUpStmt |
            PauseStmt | WaitForStmt | WaitWhileStmt | ParrotStmt | DialogStmt |
            OverrideStmt | AllowObjectsStmt | LimitStmt .

SayStmt          = actor_name ":" string_lit [ GotoStmt ] .
GotoStmt         = "->" label .
ExecuteStmt      = "!" Code .
ChoiceStmt       = int_lit (string_lit | ("$" Code)) GotoStmt .
ShutUpStmt       = "shutup" .
PauseStmt        = "pause" float_lit .
WaitForStmt      = "waitfor" [ actor_name ] .
WaitWhileStmt    = "waitwhile" Code .
ParrotStmt       = "parrot" bool_lit .
DialogStmt       = "dialog" actor_name .
OverrideStmt     = "override" label .
AllowObjectsStmt = "allowobjects" bool_lit .
LimitStmt        = "limit" int_lit .

Code = /* Scripting language expression, e.g. Squirrel */ .

comment        = ";" { unicode_char } .
actor_name     = unicode_letter { unicode_letter | unicode_digit } .
label          = letter_uscore { letter_uscore | unicode_digit } .
letter_uscore  = unicode_letter | "_" .
bool_lit       = "yes" | "YES" | "no" | "NO" .
int_lit        = decimal_digits .
float_lit      = decimal_digits | decimal_digits "." [ decimal_digits ] |
                 "." decimal_digits .
decimal_digits = { decimal_digit } .
decimal_digit  = "0" … "9" .
string_lit     = `"` { unicode_value } `"` .
unicode_value  = unicode_char | escaped_char .
escaped_char   = `\` ( "n" | `\` | `"` ) .

newline        = /* the Unicode code point U+000A */ .
unicode_char   = /* an arbitrary Unicode code point except newline */ .
unicode_letter = /* a Unicode code point classified as "Letter" */ .
unicode_digit  = /* a Unicode code point classified as "Number, decimal digit" */ .

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChoiceOption added in v0.3.0

type ChoiceOption struct {
	Text string
	// contains filtered or unexported fields
}

type Choices added in v0.3.0

type Choices struct {
	Actor   string
	Options []*ChoiceOption
	// contains filtered or unexported fields
}

func (*Choices) Choose added in v0.3.0

func (c *Choices) Choose(index int) *Choices

type ConditionalStatement

type ConditionalStatement struct {
	Statement  stmt.Statement
	Conditions []cond.Condition
}

A ConditionalStatement is a statement guarded by zero or more conditions.

func (ConditionalStatement) String

func (c ConditionalStatement) String() string

String formats the conditional statement in yack syntax, e.g. "statement [condition1] [condition2] [condition3]"

type Dialog

type Dialog struct {
	Statements []ConditionalStatement
	Labels     map[string]int
}

Dialog is a parsed yack dialog. It consists of a sequence of statements, each one guarded by zero or more conditions, and a label index. Each label points via index to a statement in the statements slice.

func Load

func Load(path string) (*Dialog, error)

Load reads and parses a dialog from a yack file. File IO or syntax errors are returned as error.

func Read added in v0.3.1

func Read(r io.Reader) (*Dialog, error)

Read reads a dialog from a source in yack format. Syntax errors are returned as error.

func (*Dialog) String

func (d *Dialog) String() string

String formats the dialog in yack syntax.

type Runner added in v0.3.0

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

func NewRunner added in v0.3.0

func NewRunner(s Scripting, t Talk, startActor string) *Runner

func (*Runner) Start added in v0.3.0

func (r *Runner) Start(d *Dialog) *Choices

Start begins the given dialog at the "start" label and returns dialog choices when available. If the Options slice of the returned Choices object is empty the end of the dialog has been reached.

func (*Runner) StartAt added in v0.3.0

func (r *Runner) StartAt(d *Dialog, label string) *Choices

StartAt begins the given dialog at the specified label and returns choices. If the Options slice of the returned Choices object is empty the end of the dialog has been reached.

type Scripting added in v0.3.0

type Scripting interface {
	Eval(code string) (result any, err error)
}

Scripting provides an interface for the evaluation of expressions in a scripting language. It can be used to plug in an interpreter or VM for any scripting language, e.g. Squirrel, Lua or JavaScript.

type Talk added in v0.3.0

type Talk interface {
	// Say makes the actor say a text.
	Say(actor, text string)
	// ShutUp makes all actors stop talking.
	ShutUp()
}

Directories

Path Synopsis
Package cond defines conditions for statements of the yack language.
Package cond defines conditions for statements of the yack language.
Package stmt defines statements of the yack language.
Package stmt defines statements of the yack language.

Jump to

Keyboard shortcuts

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