Documentation ¶
Overview ¶
Package script provides authors an interface to create stories. The scripts generate source, which the compiler then turns into models.
Index ¶
- Variables
- func AddScript(cb InitCallback)
- func Go(phrase G.RuntimePhrase, phrases ...G.RuntimePhrase) G.Callback
- func ScriptCount() int
- type ActionAssertionFragment
- type CalledFragment
- type CanDoPhrase
- type ClassEnumFragment
- type ClassPropertyFragment
- type ClassRelationFragment
- type ClassRelativeFragment
- type EitherOrPhrase
- type EventFinalizer
- type EventPhrase
- type GoesFromFragment
- type GoesToFragment
- type GoingFragment
- type IFragment
- type InitCallback
- type IsPhrase
- type KnownAsFragment
- type ListOfItems
- type Origin
- type Parsing
- type RequiresWhatPhrase
- type Script
- func (s *Script) A(key string, fragments ...IFragment) (int, error)
- func (s *Script) Compile(writer io.Writer) (res compiler.MemoryResult, err error)
- func (s *Script) CompileCalls(writer io.Writer, calls call.Compiler) (res *M.Model, err error)
- func (s *Script) Execute(what string, as Parsing)
- func (s *Script) Our(key string, fragments ...IFragment) (int, error)
- func (s *Script) The(key string, fragments ...IFragment) (int, error)
- type SubjectBlock
- type TableAndFragment
- type TableFragment
Constants ¶
This section is empty.
Variables ¶
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 (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 ¶
func (frag ClassRelationFragment) Implying(kind string, dst ClassRelationFragment) IFragment
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 Exists ¶
func Exists() IFragment
Exists(): optional fragment for making otherwise empty statements more readable The("room", Called("parlor of despair"), Exists())
func Has ¶
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.
type InitCallback ¶
type InitCallback func(s *Script)
type IsPhrase ¶
type IsPhrase struct {
// contains filtered or unexported fields
}
func Is ¶
Instance statement to select the value of an enumerations The enumeration must (eventually) be declared for the class via AreEither(), or AreOneOf()
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 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
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) CompileCalls ¶
Compile the current script into a model which can be used by the runtime. writer used for logging.
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)