mdl

package
v0.24.5 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package mdl provides an api for building the database used by the tapestry runtime. The Reader*() functions provide csv style output for use with testing. For the definitions of the tables see tapestry/tables/model.sql

Index

Constants

View Source
const Conflict = errutil.Error("Conflict")

when the definition would contradict existing information: the returned error wraps this tag. errors.Is can be used to detect it.

View Source
const Duplicate = errutil.NoPanicError("Duplicate")

when the definition would repeat existing information: the returned error wraps this tag. errors.Is can be used to detect it.

View Source
const Missing = errutil.NoPanicError("Missing")

when the definition can't find some required information: the returned error wraps this tag. errors.Is can be used to detect it.

Variables

View Source
var LogWarning = func(e error) {
	log.Println("Warning:", e)
}

Functions

func AddNamedNoun

func AddNamedNoun(pen NounMaker, longName, kind string) (ret string, err error)

given an author specified name generate a new noun and its names

func AddNounNames

func AddNounNames(pen NounMaker, noun string, names []string) (err error)

func MakeNames

func MakeNames(source string) (out []string)

generate names for a noun; the standard rules use these for printing when no specific printed names exist; and for finding nouns that were specified by authors in a story.

func MakePath

func MakePath(path ...string) string

func ReadAssignments

func ReadAssignments(db *sql.DB) ([]string, error)

func ReadDomain

func ReadDomain(db *sql.DB, n string) (ret []string, err error)

an array of dependencies

func ReadDomains

func ReadDomains(db *sql.DB) ([]string, error)

func ReadFields

func ReadFields(db *sql.DB) ([]string, error)

domain, kind, field name, affinity, subtype sorted by kind and within each kind, the field name

func ReadGrammar

func ReadGrammar(db *sql.DB) ([]string, error)

domain, input, serialized program

func ReadKinds

func ReadKinds(db *sql.DB) (ret []string, err error)

domain, kind, expanded materialized path ordered by domain, length of path, and name ( that erases their natural, dependency order --

but independent siblings dont otherwise have a consistent order for testing )

func ReadLocals

func ReadLocals(db *sql.DB) ([]string, error)

domain, kind, name, serialized initialization

func ReadNames

func ReadNames(db *sql.DB) ([]string, error)

domain, noun, name, rank

func ReadNouns

func ReadNouns(db *sql.DB) ([]string, error)

domain, noun, kind

func ReadPairs

func ReadPairs(db *sql.DB) ([]string, error)

domain, relation, noun, other noun original order was domain, and alpha relation name

func ReadPatterns

func ReadPatterns(db *sql.DB) ([]string, error)

domain, pattern, labels, result field

func ReadPlurals

func ReadPlurals(db *sql.DB) ([]string, error)

domain, many, one

func ReadRelations

func ReadRelations(db *sql.DB) ([]string, error)

domain, relation, one kind, other kind, cardinality ordered by name of the relation for test consistency.

func ReadRules

func ReadRules(db *sql.DB) ([]string, error)

domain, pattern, target, rank, rule

func ReadValues

func ReadValues(db *sql.DB) ([]string, error)

domain, noun, field, dot, value

Types

type DomainValueError

type DomainValueError struct {
	Noun, Field string
	Value       rt.Assignment
}

func (DomainValueError) Error

func (e DomainValueError) Error() string

type FieldInfo

type FieldInfo struct {
	Name, Class string
	Affinity    affine.Affinity
	Init        rt.Assignment
	Error       error
}

type Log

type Log func(fmt string, parts ...any)

type MatchedField

type MatchedField struct {
	Name string // name of the trait in the db
}

func (MatchedField) WordCount

func (m MatchedField) WordCount() int

same logic as MatchedTrait

type MatchedKind

type MatchedKind struct {
	Name  string        // the name of the kind in the db
	Base  kindsOf.Kinds // which of the built-in kinds is the returned kind most like?
	Match string        // the word(s) (singular or plural) used to match
}

func (MatchedKind) WordCount

func (m MatchedKind) WordCount() int

type MatchedNoun

type MatchedNoun struct {
	Name  string // the id of the noun in the db
	Kind  string // the noun's kind
	Match string // the words used to match
}

func (MatchedNoun) WordCount

func (m MatchedNoun) WordCount() int

type MatchedTrait

type MatchedTrait struct {
	Name string // name of the trait in the db
}

func (MatchedTrait) WordCount

func (m MatchedTrait) WordCount() int

the returned name is the name of the trait from the db it was used to match the front of the passed string so the words in the trait are the words in the string.

type Modeler

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

Modeler wraps writing to the model table so the implementation can handle verifying dependent names when needed.

func NewModeler

func NewModeler(db *sql.DB) (ret *Modeler, err error)

*

*

func NewModelerWithWarnings

func NewModelerWithWarnings(db *sql.DB, warn Log) (ret *Modeler, err error)

func (*Modeler) Pin

func (m *Modeler) Pin(domain, at string) *Pen

func (*Modeler) PrecachePaths

func (m *Modeler) PrecachePaths()

meant for tests which inject their own data outside of weave

type NounMaker

type NounMaker interface {
	AddNounKind(name, kind string) error
	AddNounName(noun, name string, rank int) error
}

type Pattern

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

public snapshot of the desired pattern

func (*Pattern) Name

func (p *Pattern) Name() string

func (*Pattern) Parent

func (p *Pattern) Parent() string

func (*Pattern) Rules

func (p *Pattern) Rules() []Rule

type PatternBuilder

type PatternBuilder struct {
	Pattern
}

func NewPatternBuilder

func NewPatternBuilder(name string) *PatternBuilder

func NewPatternSubtype

func NewPatternSubtype(name string, parent string) *PatternBuilder

func (*PatternBuilder) AddLocals

func (b *PatternBuilder) AddLocals(fs []FieldInfo)

defers execution; so no return value.

func (*PatternBuilder) AddParams

func (b *PatternBuilder) AddParams(fs []FieldInfo)

defers execution; so no return value.

func (*PatternBuilder) AddResult

func (b *PatternBuilder) AddResult(f FieldInfo)

defers execution; so no return value.

func (*PatternBuilder) AppendRule

func (b *PatternBuilder) AppendRule(rank int, rule rt.Rule)

defers execution; so no return value. expects target class name to be normalized.

type Pen

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

func (*Pen) AddAspectTraits

func (pen *Pen) AddAspectTraits(aspect string, traits []string) (err error)

func (*Pen) AddCheck

func (pen *Pen) AddCheck(name string, value literal.LiteralValue, prog []rt.Execute) (err error)

author tests of stories

func (*Pen) AddDefaultValue

func (pen *Pen) AddDefaultValue(kind, field string, value rt.Assignment) (err error)

the top level fields of kinds can hold runtime evaluated assignments.

func (*Pen) AddDependency

func (pen *Pen) AddDependency(requires string) (err error)

pairs of domain name and (domain) dependencies fix: are we forcing/checking parent domains to exist before writing? that might be cool .... but maybe this is the wrong level?

func (*Pen) AddFact

func (pen *Pen) AddFact(key string, partsAndValue ...string) (okay bool, err error)

arbitrary key-value storage returns true if its a new fact, false otherwise or on error.

func (*Pen) AddGrammar

func (pen *Pen) AddGrammar(name string, prog *grammar.Directive) (err error)

player input parsing

func (*Pen) AddKind

func (pen *Pen) AddKind(name, parent string) (err error)

plural name of kind and materialized hierarchy of ancestors separated by commas this (somewhat) duplicates the algorithm used by Noun()

func (*Pen) AddKindFields

func (pen *Pen) AddKindFields(kind string, fields []FieldInfo) error

func (*Pen) AddKindTrait

func (pen *Pen) AddKindTrait(kind, trait string) (err error)

func (*Pen) AddNounKind

func (pen *Pen) AddNounKind(noun, kind string) (err error)

add a noun with the passed identifier and kind ( both normalized ) the kind must exist. note: returns mdl.Duplicate if the noun is already know. see also: the utility function AddNamedNoun()

func (*Pen) AddNounName

func (pen *Pen) AddNounName(noun, name string, rank int) (err error)

currently negative ranks are runtime aliases, and positive values are weave time.

func (*Pen) AddNounPair

func (pen *Pen) AddNounPair(rel, oneNoun, otherNoun string) (err error)

currently assumes exact noun names

func (*Pen) AddNounPath

func (pen *Pen) AddNounPath(noun string, path []string, value literal.LiteralValue) (err error)

store a literal value somewhere within a record held by a noun. note: assumes noun is an exact name fix: merge with AddNounValue; use the bits inside marshalAssignment ... and strip assignment down to a literal value

func (*Pen) AddNounValue

func (pen *Pen) AddNounValue(noun, field string, value rt.Assignment) (err error)

the top level fields of nouns can hold runtime evaluated assignments. wrap with "ProvisionalAssignment" to assign implied values that can be overridden by explicit statements. note: assumes noun is an exact name

func (*Pen) AddPattern

func (pen *Pen) AddPattern(pat Pattern) (err error)

func (*Pen) AddPlural

func (pen *Pen) AddPlural(many, one string) (err error)

a plural word (many) can have at most one singular definition per domain ie. people and persons are valid plurals of person, but people as a singular can only be defined as person ( not also human ) error

func (*Pen) AddRelation

func (pen *Pen) AddRelation(name, oneKind, otherKind string, amany bool, bmany bool) (err error)

relation and constraint between two kinds

func (*Pen) AddTestField

func (pen *Pen) AddTestField(kind, field string, aff affine.Affinity, cls string) (err error)

for testing: a generic field of the kind

func (*Pen) AddTestParameter

func (pen *Pen) AddTestParameter(kind, field string, aff affine.Affinity, cls string) (err error)

func (*Pen) AddTestResult

func (pen *Pen) AddTestResult(kind, field string, aff affine.Affinity, cls string) (err error)

func (*Pen) AddTestRule

func (pen *Pen) AddTestRule(pattern string, rank int, prog string) (err error)

public for tests:

func (*Pen) AddTestValue

func (pen *Pen) AddTestValue(noun string, final bool, path, out string) (err error)

unmarshaled version of AddValue for testing.

func (*Pen) ExtendPattern

func (pen *Pen) ExtendPattern(pat Pattern) (err error)

func (*Pen) GetClosestNoun

func (pen *Pen) GetClosestNoun(name string) (ret MatchedNoun, err error)

prefer runtime meta.ObjectId

func (*Pen) GetNounValue

func (pen *Pen) GetNounValue(noun, field string) (ret []byte, err error)

return a specific field of a specific noun. this is a more limited form of the runtime version; it doesn't attempt to unpack records.

func (*Pen) GetPartialField

func (pen *Pen) GetPartialField(kind, field string) (ret MatchedField, err error)

match the passed words with the known fields of all in-scope kinds. return the full name of the field that matched. an unmatched noun returns the empty string and no error.

func (*Pen) GetPartialKind

func (pen *Pen) GetPartialKind(str string) (ret MatchedKind, err error)

searches for the kind which uses the most number of words from the front of the passed string. for example: the words "container of the apocalypse" would match the kind "container." assumes the words are lowercased and whitespace is normalized.

func (*Pen) GetPartialNoun

func (pen *Pen) GetPartialNoun(name, kind string) (ret MatchedNoun, err error)

if specified, kind must match exactly an unmatched noun returns the empty string and no error.

func (*Pen) GetPartialTrait

func (pen *Pen) GetPartialTrait(str string) (ret MatchedTrait, err error)

an unmatched trait returns the empty string and no error tbd: technically there's some possibility that there might be three traits: "wood", "veneer", and "wood veneer" -- subset names with the first two applying to one kind, and the third applying to a different kind; all in scope. this would always match the second -- even if its not applicable. ( i guess that's where commas can be used by the user to separate things )

func (*Pen) GetRelativeNouns

func (pen *Pen) GetRelativeNouns(noun, relation string, primary bool) (ret []string, err error)

type ProvisionalAssignment

type ProvisionalAssignment struct {
	rt.Assignment
}

type ProvisionalLiteral

type ProvisionalLiteral struct {
	literal.LiteralValue
}

type Rule

type Rule struct {
	rt.Rule
	Rank int
}

type Warnings

type Warnings []error

func (*Warnings) All

func (w *Warnings) All() (ret []error)

return the warnings as a raw list, clear all stored errors.

func (*Warnings) Catch

func (w *Warnings) Catch(fatal func(args ...any)) func()

override the global warning function returns a defer-able function which: 1. restores the warning function; and, 2. raises a Fatal error if there are any unhandled warnings.

func (*Warnings) Expect

func (w *Warnings) Expect(prefix string) (err error)

remove and return the first warning, error if there is none, or if warning doesnt start with the passed prefix.

Jump to

Keyboard shortcuts

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