script

package
v0.0.0-...-9034458 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2016 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package script provides authors an interface to create stories. The scripts generate source, which the compiler then turns into models.

Index

Constants

This section is empty.

Variables

View Source
var Directions = []string{"north", "south", "east", "west", "up", "down"}

Functions

func AddScript

func AddScript(cb InitCallback)

AddScript supports callbacks of this pattern:

 func init() {
	AddScript(func(s *Script) {
		s.The...
	})
	}

func Go

func Go(phrase G.RuntimePhrase, phrases ...G.RuntimePhrase) G.Callback

FIX: TESTING: add a function which returns a g.Go function? how to chain? etc.

func ScriptCount

func ScriptCount() int

Types

type ActionAssertionFragment

type ActionAssertionFragment struct {
	RequiresWhatPhrase
	// contains filtered or unexported fields
}

func (ActionAssertionFragment) AndOne

func (frag ActionAssertionFragment) AndOne(class string) IFragment

the context will be input by the user, and will of the passed class

func (ActionAssertionFragment) MakeStatement

func (frag ActionAssertionFragment) MakeStatement(b SubjectBlock) error

type CalledFragment

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

implementation:

func Called

func Called(subject string) CalledFragment

Fragment to assert the existence of a class or instance The("room", Called("home"))

func (CalledFragment) MakeStatement

func (frag CalledFragment) MakeStatement(b SubjectBlock) error

func (CalledFragment) WithSingularName

func (frag CalledFragment) WithSingularName(name string) IFragment

type CanDoPhrase

type CanDoPhrase struct {
	Origin
	// contains filtered or unexported fields
}

func Can

func Can(verb string) CanDoPhrase

active verb:

func (CanDoPhrase) And

func (frag CanDoPhrase) And(doing string) RequiresWhatPhrase

starts a requirements phrase for deciding how to provide nouns...

type ClassEnumFragment

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

implementation:

func AreOneOf

func AreOneOf(name string, or string, more string, rest ...string) ClassEnumFragment

Class statement to add a set of enumerated choices for all instances of the class TBD: turn into a function chain?

func (ClassEnumFragment) MakeStatement

func (frag ClassEnumFragment) MakeStatement(b SubjectBlock) error

func (ClassEnumFragment) Usually

func (frag ClassEnumFragment) Usually(choice string) ClassEnumFragment

cascades

type ClassPropertyFragment

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

func Have

func Have(name string, kind string) ClassPropertyFragment

Have statement to add a property to all instances of a class. FIX: currently, for relations, you must use HaveOne or HaveMany.

func (ClassPropertyFragment) MakeStatement

func (frag ClassPropertyFragment) MakeStatement(b SubjectBlock) error

type ClassRelationFragment

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

func HaveMany

func HaveMany(name string, kind string) ClassRelationFragment

HaveMany establishs a many-to-one relation.

func HaveOne

func HaveOne(name string, kind string) ClassRelationFragment

HaveOne establishes a one-to-one, or one-to-many relation.

func (ClassRelationFragment) Implying

Pivot to add a reciprocal kind property relation

func (ClassRelationFragment) MakeStatement

func (frag ClassRelationFragment) MakeStatement(b SubjectBlock) (err error)

type ClassRelativeFragment

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

type EitherOrPhrase

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

func AreEither

func AreEither(firstChoice string) EitherOrPhrase

Class statement to add an either/or choice for all instances of the class ex. AreEither("this").Or("that")

func (EitherOrPhrase) Or

func (phrase EitherOrPhrase) Or(secondChoice string) ClassEnumFragment

type EventFinalizer

type EventFinalizer struct {
	EventPhrase
	// contains filtered or unexported fields
}

func (EventFinalizer) MakeStatement

func (frag EventFinalizer) MakeStatement(b SubjectBlock) (err error)

type EventPhrase

type EventPhrase struct {
	Origin
	// contains filtered or unexported fields
}

func After

func After(event string) EventPhrase

a shortcut for meaning at the target ( queues the callback to run after the default actions have completed. )

func Before

func Before(event string) EventPhrase

a shortcut for meaning at the target ( implemented as a capturing event )

func When

func When(event string) EventPhrase

a shortcut for meaning at the target ( implemented as a bubbling event )

func (EventPhrase) Always

func (p EventPhrase) Always(cb G.Callback) EventFinalizer

func (EventPhrase) Or

func (p EventPhrase) Or(event string) EventPhrase

type GoesFromFragment

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

func Through

func Through(door string) GoesFromFragment

Begin a statement connecting one room to another via a door. Door: The exit from a room.

func (GoesFromFragment) ArrivesAt

func (goesFrom GoesFromFragment) ArrivesAt(room string) GoesToFragment

Establishes a one-way connection between the room From() and the passed destination.

func (GoesFromFragment) ConnectsTo

func (goesFrom GoesFromFragment) ConnectsTo(room string) GoesToFragment

Establishes a two-way connection between the room From() and the passed destination.

type GoesToFragment

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

func (GoesToFragment) Door

func (goesTo GoesToFragment) Door(door string) IFragment

Optional door to arrive at in the destination room.

func (GoesToFragment) MakeStatement

func (goesTo GoesToFragment) MakeStatement(b SubjectBlock) (err error)

implements IFragment for use in The()

type GoingFragment

type GoingFragment struct {
	GoesFromFragment
}

func Going

func Going(direction string) GoingFragment

Begin a statement connecting one room to another via a movement direction. Direction: a noun of "direction" type: ex. north, east, south.

func (GoingFragment) Through

func (goingFrom GoingFragment) Through(door string) GoesFromFragment

Causes directional movement to pass through an explicit departure door.

type IFragment

type IFragment interface {
	MakeStatement(SubjectBlock) error
}

Interface for generating statements.

func Exist

func Exist() IFragment

func Exists

func Exists() IFragment

Exists(): optional fragment for making otherwise empty statements more readable The("room", Called("parlor of despair"), Exists())

func Has

func Has(property string, values ...interface{}) (frag IFragment)

Instance statement to set the value of a property The property must (eventually) be declared for the class via Have().

func NewFunctionFragment

func NewFunctionFragment(cb functionFragmentCall) IFragment

NewFunctionFragment changes the passed function into an implementation of IFragment.

func To

func To(action string, c G.Callback) IFragment

statement to declare an default action handler

type InitCallback

type InitCallback func(s *Script)

type IsPhrase

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

func Is

func Is(choice string, choices ...string) IsPhrase

Instance statement to select the value of an enumerations The enumeration must (eventually) be declared for the class via AreEither(), or AreOneOf()

func (IsPhrase) And

func (phrase IsPhrase) And(choice string) IsPhrase

func (IsPhrase) MakeStatement

func (phrase IsPhrase) MakeStatement(b SubjectBlock) (err error)

type KnownAsFragment

type KnownAsFragment struct {
	Origin
	// contains filtered or unexported fields
}

func IsKnownAs

func IsKnownAs(name string) KnownAsFragment

Add an alias for the current subject. ex. The("cabinet", IsKnownAs("armoire").And("..."))

func (KnownAsFragment) And

func (frag KnownAsFragment) And(name string) KnownAsFragment

Add additional aliases for the current subject.

func (KnownAsFragment) MakeStatement

func (frag KnownAsFragment) MakeStatement(b SubjectBlock) error

type ListOfItems

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

func Contains

func Contains(prop string) ListOfItems

func In

func In(room string) ListOfItems

FIX: move these into a standard rules extension package?

func Possesses

func Possesses(prop string) ListOfItems

func Supports

func Supports(prop string) ListOfItems

func Wears

func Wears(prop string) ListOfItems

func (ListOfItems) And

func (this ListOfItems) And(name string) ListOfItems

func (ListOfItems) MakeStatement

func (this ListOfItems) MakeStatement(b SubjectBlock) (err error)

type Origin

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

location of that the fragment was declared

func NewOrigin

func NewOrigin(skip int) Origin

func (Origin) Code

func (this Origin) Code() S.Code

FIX: would be nice to change code from a string to an interface so that we can delay the expansion

func (Origin) String

func (this Origin) String() (str string)

type Parsing

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

func Matching

func Matching(how string) Parsing

func (Parsing) Or

func (this Parsing) Or(words string) Parsing

type RequiresWhatPhrase

type RequiresWhatPhrase struct {
	CanDoPhrase
	// contains filtered or unexported fields
}

func (RequiresWhatPhrase) RequiresNothing

func (frag RequiresWhatPhrase) RequiresNothing() IFragment

the target will be the same as the source

func (RequiresWhatPhrase) RequiresOne

func (frag RequiresWhatPhrase) RequiresOne(class string) ActionAssertionFragment

the target will be input by the user, and will of the passed class

func (RequiresWhatPhrase) RequiresTwo

func (frag RequiresWhatPhrase) RequiresTwo(class string) IFragment

the target and the context will be input by the user, and will both be of the passed class FIX: class must be singular right now :(

type Script

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

func InitScripts

func InitScripts() *Script

func (*Script) A

func (s *Script) A(key string, fragments ...IFragment) (int, error)

A=>The alias

func (*Script) Compile

func (s *Script) Compile(writer io.Writer) (res compiler.MemoryResult, err error)

func (*Script) CompileCalls

func (s *Script) CompileCalls(writer io.Writer, calls call.Compiler) (res *M.Model, err error)

Compile the current script into a model which can be used by the runtime. writer used for logging.

func (*Script) Execute

func (s *Script) Execute(what string, as Parsing)

Execute( action, Matching(regexp).Or(other regexp) )

func (*Script) Our

func (s *Script) Our(key string, fragments ...IFragment) (int, error)

Our=>The alias

func (*Script) The

func (s *Script) The(key string, fragments ...IFragment) (int, error)

The main script function used to asset the existence of a class, instance, property, etc. Returns a placeholder variable, and an error -- both of which are intended to help distinguish it from The() used in callbacks. ex. The("example", s.Has("...") )

type SubjectBlock

type SubjectBlock struct {
	*Script

	*S.BuildingBlocks
	// contains filtered or unexported fields
}

func (*SubjectBlock) Keyword

func (sb *SubjectBlock) Keyword() string

func (*SubjectBlock) Subject

func (sb *SubjectBlock) Subject() string

type TableAndFragment

type TableAndFragment struct {
	TableFragment
}

func (TableAndFragment) And

func (this TableAndFragment) And(values ...interface{}) TableAndFragment

type TableFragment

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

TableFragment assists in the generation of

func Table

func Table(columns ...string) TableFragment

Table statements create, or add data to, one or more instances at a time. The columns must match existing properties, noting that all objects have an implicit "name" property. If a table lacks a "name" column, the compiler will generate a unqiue name automatically.

func (TableFragment) Has

func (this TableFragment) Has(values ...interface{}) TableAndFragment

note: was "contains", changed to "Has" to align text with "And" statements

func (TableFragment) MakeStatement

func (this TableFragment) MakeStatement(b SubjectBlock) (err error)

Jump to

Keyboard shortcuts

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