modelform

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package modelform is the forms of a model an external engine reads: the sources form and the versioned graphs:1 form of the lowered action and state graphs.

Index

Constants

View Source
const GraphsVersion = 1

GraphsVersion is the version of the `graphs:<v>` form this build writes. It moves when a field the form carries changes meaning, is removed or is renamed; an added field keeps the version.

Variables

View Source
var ErrFormUnsupported = errors.New("export: model form not supported")

ErrFormUnsupported reports a model form this build does not export for an engine.

View Source
var ErrGraphsOrder = errors.New("graphs: elements of one graph cannot be ordered")

ErrGraphsOrder reports two graph elements the export cannot tell apart, which would make the output depend on memory layout; the lowering never produces them.

View Source
var ErrGraphsSubject = errors.New("graphs: subject has no lowered graph")

ErrGraphsSubject reports a subject no lowered graph is exported for: not an action or a state machine, or one the lowering refuses.

View Source
var ErrNoSources = errors.New("export: the model has no source documents")

ErrNoSources reports a model that registered no document to export.

Functions

func MarshalGraphs

func MarshalGraphs(g *Graphs) ([]byte, error)

MarshalGraphs writes the form as canonical JSON: keys in struct order, no indentation, one trailing newline. encoding/json writes map keys sorted and the form holds no map, so the bytes are a function of the model alone.

func RefuseRDFForm

func RefuseRDFForm() error

RefuseRDFForm is the typed refusal of the `rdf` model form for an engine: the design defines it and the stage that adds policies and samplers delivers it.

Types

type AcceptForm

type AcceptForm struct {
	Param        string       `json:"param,omitempty"`
	SignalType   string       `json:"signalType,omitempty"`
	ViaPort      string       `json:"viaPort,omitempty"`
	ViaSelf      bool         `json:"viaSelf,omitempty"`
	SubsetsEvent *ExprForm    `json:"subsetsEvent,omitempty"`
	Trigger      *TriggerForm `json:"trigger,omitempty"`
	Scope        string       `json:"scope,omitempty"`
}

AcceptForm is what an accept node or a transition trigger receives.

type ActionForm

type ActionForm struct {
	// Name is the qualified name of the action; Kind is its symbol kind.
	Name string `json:"name"`
	Kind string `json:"kind"`
	// Error is the lowering's refusal of a performed action, with no graph beside it.
	Error string `json:"error,omitempty"`
	// Scope is the scope the action's body resolves names in.
	Scope string `json:"scope,omitempty"`
	// Parameters is the signature a caller writes and reads back, in invocation
	// order: the action's own, then the inherited ones none redefines.
	Parameters []ParameterForm `json:"parameters,omitempty"`
	Attributes []AttributeForm `json:"attributes,omitempty"`
	Nodes      []NodeForm      `json:"nodes"`
	// Initial is the vertex the flow starts at, absent for a graph without one.
	Initial *int  `json:"initial,omitempty"`
	Finals  []int `json:"finals,omitempty"`
	// Edges are the control flows, by source vertex then declaration order.
	Edges []EdgeForm `json:"edges,omitempty"`
	// Flows are the object flows between pins, by source vertex then declaration order.
	Flows       []ObjectFlowForm `json:"flows,omitempty"`
	Bindings    []PinBindingForm `json:"bindings,omitempty"`
	Connections []ConnectionForm `json:"connections,omitempty"`
}

ActionForm is one lowered ActionGraph. Vertices are numbered by their position in Nodes; every other field refers to them by that number.

type AttributeForm

type AttributeForm struct {
	Name  string    `json:"name"`
	Types []string  `json:"types,omitempty"`
	Unit  string    `json:"unit,omitempty"`
	Value *ExprForm `json:"value,omitempty"`
	Span  SpanForm  `json:"span"`
	Scope string    `json:"scope,omitempty"`
}

AttributeForm is an attribute the behavior declares, with the types and unit the semantic model derives for it.

type BehaviorForm

type BehaviorForm struct {
	Name  string   `json:"name,omitempty"`
	Span  SpanForm `json:"span"`
	Scope string   `json:"scope,omitempty"`
	// Owner is the state whose attributes the behavior reads and writes.
	Owner *int            `json:"owner,omitempty"`
	Body  []StatementForm `json:"body"`
	// Nodes are the action nodes the body's blocks declare, each a
	// subperformance of the behavior's, by name.
	Nodes []string `json:"nodes,omitempty"`
}

BehaviorForm is an entry, do, exit or effect behavior.

type BlockForm

type BlockForm struct {
	Statements []StatementForm `json:"statements"`
	Scope      string          `json:"scope,omitempty"`
	Own        bool            `json:"own,omitempty"`
	Stated     bool            `json:"stated,omitempty"`
	Graph      *ActionForm     `json:"graph,omitempty"`
}

BlockForm is a block of statements, with the flow graph of one that states a flow of its own.

type ChainForm

type ChainForm struct {
	Base  *ExprForm `json:"base,omitempty"`
	Steps []string  `json:"steps,omitempty"`
	Text  string    `json:"text"`
}

ChainForm is a feature chain walked from a base expression.

type ChannelForm

type ChannelForm struct {
	Signal string `json:"signal,omitempty"`
	Port   string `json:"port,omitempty"`
}

ChannelForm is one message a move sends or waits for: the signal type as written (absent for any) and the port it travels through (absent for none).

type ConnectionForm

type ConnectionForm struct {
	Ends      []string `json:"ends"`
	Variation string   `json:"variation,omitempty"`
	Variant   string   `json:"variant,omitempty"`
	Owner     string   `json:"owner"`
	Scope     string   `json:"scope,omitempty"`
}

ConnectionForm is a connector the behavior routes a `send … via` through.

type Document

type Document struct {
	Path string `json:"path"`
	Text string `json:"text"`
}

Document is one source document of the model, its registered name and its text.

type EdgeForm

type EdgeForm struct {
	Source      int       `json:"source"`
	Target      int       `json:"target"`
	Guard       *ExprForm `json:"guard,omitempty"`
	Else        bool      `json:"else,omitempty"`
	Probability *ExprForm `json:"probability,omitempty"`
	Decl        SpanForm  `json:"decl"`
}

EdgeForm is a control flow, guarded when Guard is present; Else marks the branch of a decision written as `else`, taken when no guarded branch is. Probability is the weight a `@Probability` annotation gives a decision's branch.

type EntryTransitionForm

type EntryTransitionForm struct {
	// Body is the state or region the transition is written in; absent for the
	// machine's own body.
	Body   *int      `json:"body,omitempty"`
	Guard  *ExprForm `json:"guard,omitempty"`
	Target int       `json:"target"`
	Scope  string    `json:"scope,omitempty"`
	Decl   SpanForm  `json:"decl"`
}

EntryTransitionForm is a transition out of the entry action of Body.

type ExprForm

type ExprForm struct {
	Text string   `json:"text"`
	Span SpanForm `json:"span"`
}

ExprForm is an expression as the graph carries it: its source text and where it was written, so an engine parses the text and the host names the place.

type FeatureForm

type FeatureForm struct {
	Name      string    `json:"name"`
	Direction string    `json:"direction,omitempty"`
	Result    bool      `json:"result,omitempty"`
	Types     []string  `json:"types,omitempty"`
	Unit      string    `json:"unit,omitempty"`
	Value     *ExprForm `json:"value,omitempty"`
	Span      SpanForm  `json:"span"`
	Scope     string    `json:"scope,omitempty"`
}

FeatureForm is a parameter or attribute a node declares itself.

type FootprintForm

type FootprintForm struct {
	Reads   []PlaceForm   `json:"reads,omitempty"`
	Writes  []PlaceForm   `json:"writes,omitempty"`
	Sends   []ChannelForm `json:"sends,omitempty"`
	Accepts []ChannelForm `json:"accepts,omitempty"`
	Control []int         `json:"control,omitempty"`
	Dynamic bool          `json:"dynamic,omitempty"`
}

FootprintForm is a lower.Footprint: the places a move reads and writes, the channels it sends on and accepts from, the joins and merges it converges on (by vertex number) and whether its target is dynamic, in which case it depends on every other move.

type FormUnsupportedError

type FormUnsupportedError struct {
	Form   string
	Reason string
}

FormUnsupportedError says which form was asked for and why it is not exported.

func (*FormUnsupportedError) Error

func (e *FormUnsupportedError) Error() string

func (*FormUnsupportedError) Unwrap

func (e *FormUnsupportedError) Unwrap() error

Unwrap makes the error match ErrFormUnsupported.

type Graphs

type Graphs struct {
	// Version is GraphsVersion, first so a reader refuses a version it does not know.
	Version int `json:"version"`
	// Subject is the qualified name of the behavior the form was exported for.
	Subject string `json:"subject"`
	// Actions are the lowered action graphs, the subject's first when it is an
	// action, then the performed ones by name.
	Actions []*ActionForm `json:"actions,omitempty"`
	// States are the lowered state graphs, the subject's first when it is a state
	// machine, then the exhibited ones by name.
	States []*StateForm `json:"states,omitempty"`
}

Graphs is the `graphs:1` form: the lowered graph of a subject and of every behavior it performs, transitively, in a JSON an external engine reads. It is lossless for what the lowered IR carries, and its output is byte for byte the same for the same model.

func GraphsOf

func GraphsOf(model *runtime.Model, subject *symbols.Symbol) (*Graphs, error)

GraphsOf exports the lowered graph of subject, an action or a state machine declared in model, and of every behavior it performs, at GraphsVersion.

type NodeForm

type NodeForm struct {
	ID   int      `json:"id"`
	Kind string   `json:"kind"`
	Name string   `json:"name,omitempty"`
	Span SpanForm `json:"span"`
	// Scope is the scope the node's own members resolve in, when it owns one.
	Scope    string        `json:"scope,omitempty"`
	Features []FeatureForm `json:"features,omitempty"`
	// Body is the node's statements; StatementRun marks a body the node runs as
	// statements rather than as a flow of its own.
	Body         []StatementForm `json:"body,omitempty"`
	StatementRun bool            `json:"statementRun,omitempty"`
	// Block lists the vertices a block's body sequences, for a node that is one.
	Block []int `json:"block,omitempty"`
	// Accept is the message an accept node waits for.
	Accept *AcceptForm `json:"accept,omitempty"`
	// Subflow is the flow the node's own members state, for a node that has one.
	Subflow *SubflowForm `json:"subflow,omitempty"`
	// Performs are the qualified names of the behaviors the node performs or is
	// typed by, as they resolve; each has a graph of its own in the form.
	Performs []string `json:"performs,omitempty"`
	// Footprint is what advancing a token through the node may touch, the
	// independence relation of the model checker; see lower.Footprint.
	Footprint *FootprintForm `json:"footprint,omitempty"`
}

NodeForm is one vertex of an action graph with everything the lowering attached to it.

type ObjectFlowForm

type ObjectFlowForm struct {
	Name      string   `json:"name,omitempty"`
	Kind      string   `json:"kind"`
	Source    int      `json:"source"`
	SourcePin string   `json:"sourcePin,omitempty"`
	Target    int      `json:"target"`
	TargetPin string   `json:"targetPin,omitempty"`
	Decl      SpanForm `json:"decl"`
}

ObjectFlowForm is a data flow from a pin of Source to a pin of Target. Kind is how it carries its values: "streaming" (a plain `flow`) or "succession".

type ParameterForm

type ParameterForm struct {
	Name      string    `json:"name"`
	Direction string    `json:"direction,omitempty"`
	Result    bool      `json:"result,omitempty"`
	Optional  bool      `json:"optional,omitempty"`
	Types     []string  `json:"types,omitempty"`
	Unit      string    `json:"unit,omitempty"`
	Value     *ExprForm `json:"value,omitempty"`
	Span      SpanForm  `json:"span"`
	Scope     string    `json:"scope,omitempty"`
}

ParameterForm is one parameter of the action's signature. Optional marks one a caller may leave out: it declares a default or its multiplicity admits no value.

type PinBindingForm

type PinBindingForm struct {
	Node         *int       `json:"node,omitempty"`
	Path         []string   `json:"path,omitempty"`
	Pin          string     `json:"pin,omitempty"`
	Other        *ExprForm  `json:"other,omitempty"`
	OtherNode    *int       `json:"otherNode,omitempty"`
	OtherPath    []string   `json:"otherPath,omitempty"`
	OtherPin     string     `json:"otherPin,omitempty"`
	OtherChain   *ChainForm `json:"otherChain,omitempty"`
	OtherFeature string     `json:"otherFeature,omitempty"`
	Scope        string     `json:"scope,omitempty"`
	Decl         SpanForm   `json:"decl"`
	FromValue    bool       `json:"fromValue,omitempty"`
}

PinBindingForm is a binding connector with an end at a node's pin; see lower.PinBinding for the reading of each field.

type PlaceForm

type PlaceForm struct {
	Symbol string `json:"symbol,omitempty"`
	Name   string `json:"name"`
	Local  bool   `json:"local,omitempty"`
}

PlaceForm is one feature a move touches: the qualified name of the declaration it resolves to (absent when unresolved), the name it was written under, and whether it is a pin, held per performance.

type RegionForm

type RegionForm struct {
	ID   int      `json:"id"`
	Name string   `json:"name,omitempty"`
	Span SpanForm `json:"span"`
	// Owner is the composite state the region is in; Top marks a region of the
	// machine's own body.
	Owner *int `json:"owner,omitempty"`
	Top   bool `json:"top,omitempty"`
	// State is the graph-only state standing for the region, holding the
	// attributes its body declares.
	State   *int `json:"state,omitempty"`
	Initial *int `json:"initial,omitempty"`
}

RegionForm is a region of a composite state.

type Sources

type Sources struct {
	Library   string     `json:"library"`
	Documents []Document `json:"documents"`
}

Sources is the `sources` model form: every document of the model as text, in path order, and the version of the standard library the host loaded beside them.

func SourcesOf

func SourcesOf(model *runtime.Model) (*Sources, error)

SourcesOf exports the `sources` form of a model: the registered documents in name order with their whole text, and libs.Version for the standard library.

type SpanForm

type SpanForm struct {
	Document string `json:"document,omitempty"`
	Offset   int    `json:"offset"`
	Len      int    `json:"len"`
}

SpanForm locates a node in the model's text: the document and the byte span.

type StateForm

type StateForm struct {
	// Name is the qualified name of the state machine; Kind is its symbol kind.
	Name string `json:"name"`
	Kind string `json:"kind"`
	// Error is the lowering's refusal of an exhibited machine, with no graph beside it.
	Error string `json:"error,omitempty"`
	// Scope is the scope the machine's body resolves names in.
	Scope      string          `json:"scope,omitempty"`
	Attributes []AttributeForm `json:"attributes,omitempty"`
	// Machine is the vertex standing for the machine itself; Initial the state
	// it starts in, absent when the entry transitions choose it.
	Machine  *int              `json:"machine,omitempty"`
	Initial  *int              `json:"initial,omitempty"`
	Vertices []StateVertexForm `json:"vertices"`
	Regions  []RegionForm      `json:"regions,omitempty"`
	// Transitions are by source vertex, then declaration order.
	Transitions []TransitionForm `json:"transitions,omitempty"`
	// EntryTransitions are the transitions out of an entry action, by the body
	// they are written in: a state, a region, or the machine's own body.
	EntryTransitions []EntryTransitionForm `json:"entryTransitions,omitempty"`
	Connections      []ConnectionForm      `json:"connections,omitempty"`
}

StateForm is one lowered StateGraph. Vertices — the machine, its states and pseudostates, the graph-only states the lowering synthesizes for orthogonal regions — are numbered by their position in Vertices; regions by theirs in Regions. Every other field refers to them by those numbers.

type StateVertexForm

type StateVertexForm struct {
	ID   int      `json:"id"`
	Kind string   `json:"kind"`
	Name string   `json:"name,omitempty"`
	Span SpanForm `json:"span"`
	// Scope is the scope the state's own members resolve in.
	Scope string `json:"scope,omitempty"`
	// Hidden marks a graph-only state the lowering synthesized; HiddenRegion is
	// the region it stands for.
	Hidden       bool `json:"hidden,omitempty"`
	HiddenRegion *int `json:"hiddenRegion,omitempty"`
	// Parent is the composite state a substate is in; Region the region it is in.
	Parent *int `json:"parent,omitempty"`
	Region *int `json:"region,omitempty"`
	// Owner is the state a pseudostate belongs to; absent for the machine's own.
	Owner *int `json:"owner,omitempty"`
	// Regions are a composite state's regions, in order.
	Regions    []int           `json:"regions,omitempty"`
	Attributes []AttributeForm `json:"attributes,omitempty"`
	Entry      []BehaviorForm  `json:"entry,omitempty"`
	Do         []BehaviorForm  `json:"do,omitempty"`
	Exit       []BehaviorForm  `json:"exit,omitempty"`
	// Deferred are the triggers the state defers while active.
	Deferred []TriggerForm `json:"deferred,omitempty"`
}

StateVertexForm is a state, a pseudostate or the machine, with everything the lowering attached to it.

type StatementForm

type StatementForm struct {
	Kind  string   `json:"kind"`
	Span  SpanForm `json:"span"`
	Scope string   `json:"scope,omitempty"`
	// send
	Message      *ExprForm `json:"message,omitempty"`
	Target       string    `json:"target,omitempty"`
	TargetSymbol string    `json:"targetSymbol,omitempty"`
	TargetPath   bool      `json:"targetPath,omitempty"`
	TargetExpr   *ExprForm `json:"targetExpr,omitempty"`
	Via          bool      `json:"via,omitempty"`
	ViaSelf      bool      `json:"viaSelf,omitempty"`
	Receiver     string    `json:"receiver,omitempty"`
	ReceiverPath bool      `json:"receiverPath,omitempty"`
	ReceiverExpr *ExprForm `json:"receiverExpr,omitempty"`
	// assign, declare, declare usage
	Name  string     `json:"name,omitempty"`
	Chain *ChainForm `json:"chain,omitempty"`
	Value *ExprForm  `json:"value,omitempty"`
	// loop
	Loop       string     `json:"loop,omitempty"`
	Condition  *ExprForm  `json:"condition,omitempty"`
	Until      *ExprForm  `json:"until,omitempty"`
	Variable   string     `json:"variable,omitempty"`
	Collection *ExprForm  `json:"collection,omitempty"`
	Body       *BlockForm `json:"body,omitempty"`
	// if
	Then *BlockForm `json:"then,omitempty"`
	Else *BlockForm `json:"else,omitempty"`
	// effect
	Effect   string   `json:"effect,omitempty"`
	Performs []string `json:"performs,omitempty"`
	// unsupported
	Description string `json:"description,omitempty"`
}

StatementForm is one lowered statement; Kind selects which fields are set.

type SubflowForm

type SubflowForm struct {
	Graph *ActionForm `json:"graph,omitempty"`
	Error string      `json:"error,omitempty"`
}

SubflowForm is the flow nested under a node: its graph, or the lowering's refusal.

type TransitionForm

type TransitionForm struct {
	Name    string         `json:"name,omitempty"`
	Source  int            `json:"source"`
	Target  int            `json:"target"`
	Trigger *TriggerForm   `json:"trigger,omitempty"`
	Guard   *ExprForm      `json:"guard,omitempty"`
	Effect  []BehaviorForm `json:"effect,omitempty"`
	Via     string         `json:"via,omitempty"`
	Scope   string         `json:"scope,omitempty"`
	// BodyScope is the scope the guard and effect resolve in, when it differs
	// from Scope: a call trigger's parameters are visible there alone.
	BodyScope string   `json:"bodyScope,omitempty"`
	Decl      SpanForm `json:"decl"`
}

TransitionForm is a transition; a nil Trigger is a completion transition.

type TriggerForm

type TriggerForm struct {
	Kind string   `json:"kind"`
	Text string   `json:"text,omitempty"`
	Span SpanForm `json:"span"`
	// accept
	SignalType string `json:"signalType,omitempty"`
	Subsets    string `json:"subsets,omitempty"`
	Payload    string `json:"payload,omitempty"`
	// call
	Operation  string   `json:"operation,omitempty"`
	Parameters []string `json:"parameters,omitempty"`
	// change
	Condition *ExprForm `json:"condition,omitempty"`
	// time
	Duration *ExprForm `json:"duration,omitempty"`
	Absolute bool      `json:"absolute,omitempty"`
}

TriggerForm is a trigger event as classified by the lowering: an accepted signal, a change of a condition, or a time.

Jump to

Keyboard shortcuts

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