export

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 30 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 export saves a SysML v2 model to a file and converts between the two representations OpenSysML can write: SysML textual notation and RDF Turtle. It also reads a third, SysML v1 in XMI, which is migrated to v2 notation on the way in.

SysML output

Saving a model that came from source writes that source, re-indented by internal/core/format. Printing the AST instead would drop comments, notes and anything the parser recorded as an ErrorNode, so a save has to keep the token stream (see the format package doc).

RDF output

The graph uses the SysML vocabulary and element IRIs of the Flexo MMS SysML v2 service (https://www.omg.org/spec/SysML# and urn:sysmlv2:element:), so a converted model loads into that service's triplestore. Elements are addressed by qualified name (`urn:sysmlv2:element:Demo::Vehicle`), which makes the IRIs stable across conversions of the same model rather than newly generated each time.

Each element carries its metaclass as rdf:type and its declaration as SysML metamodel properties: declaredName, declaredShortName, owningNamespace, visibility, direction, the feature flags, the typing and specialization clauses, multiplicity bounds and its value; expression-valued positions are expression trees. Properties the metamodel does not define live in a separate urn:opensysml:sysml: namespace so a consumer can tell them from the standard vocabulary: memberIndex (declaration order, which the notation is sensitive to and RDF is not), hasBody, the end forms of heads that bind ends, and each element's lines as written, comments included, as sourceText and sourceTail.

XMI input

SysML v1 as UML XMI (OMG XMI 2.5.1, the Eclipse UML2 .uml serialization Papyrus writes, or a .mdzip archive holding it) is migrated to v2 notation by internal/core/migrate, then takes the notation path. XMI is never written.

RDF back to notation

The structural triples are authoritative. An element is written from its source text while that text still states what the graph states — so comments and layout survive a round trip of an unedited model — and canonically where the two disagree or the graph carries no text, as one from another tool does not. docs/reference/rdf-mapping.md documents the mapping and its limitations.

Index

Constants

View Source
const ExperimentalNotice = "RDF conversion is experimental: the mapping covers model structure and the " +
	"behavior its bodies state, refuses what it cannot write back, and its vocabulary may change " +
	"without a compatibility path; see docs/reference/rdf-mapping.md § Status"

ExperimentalNotice is the wording every surface reports the RDF mapping's status in, so the CLI, the REPL, the service and the docs agree.

View Source
const ExtensionAdvice = "name the file with a .sysml, .kerml or .ttl extension"

ExtensionAdvice is the remedy every surface shares: the file name says which format to write. A surface with a format flag names it alongside this.

View Source
const FormatList = "sysml, kerml, ttl, turtle, rdf, or xmi/uml/mdzip (input only)"

FormatList is the wording every surface lists the format names in.

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.

View Source
const MigrationNotice = "SysML v1 migration is experimental: the mapping covers structure, ports and " +
	"connectors, requirements, constraints, instances and allocations, reports every element it " +
	"approximates or leaves behind, and what it writes for a v1 element may change without a " +
	"compatibility path; see docs/reference/sysml-v1-migration.md § Status"

MigrationNotice is the wording every surface reports the SysML v1 migration's status in.

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 ErrNoNotation = errors.New("no notation to write")

ErrNoNotation reports an element no notation can be written for: one the document holds no source of, as a symbol read from an index cache is.

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 Advise

func Advise(err error, advice string) error

Advise returns err with the surface's remedy attached when it is an *UnknownFormatError, and unchanged otherwise.

func Convert

func Convert(name string, data []byte, from, to Format) ([]byte, error)

Convert reads data in the from format and writes it in the to format. name is used in diagnostics and needs no relation to a file on disk.

Converting between two formats requires the input to be syntactically valid: a model with syntax errors is rejected, because the tree the parser recovers from broken input does not hold the declarations it could not read, and a graph built from it would be quietly missing them.

func Destination added in v0.4.2

func Destination(path string) (target string, info os.FileInfo, err error)

Destination returns the file a save should write and what is there now, which is nil when nothing is. A symlink resolves to what it points at, so saving over a linked model updates the model instead of unlinking it; a link that resolves to nothing is written where it points.

func FormatNames added in v0.4.3

func FormatNames() []string

FormatNames returns every name ParseFormat accepts, sorted.

func IsExperimental

func IsExperimental(from, to Format) bool

IsExperimental reports whether a conversion between these formats goes through the RDF mapping or the SysML v1 migration. Notation to notation does not.

func MarshalGraphs added in v0.8.0

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 Migrate added in v0.6.0

func Migrate(name string, data []byte, to Format) ([]byte, *migrate.Report, error)

Migrate reads a SysML v1 model in XMI and writes it in the to format, with the report of what each v1 element became.

func NormativeSubject added in v0.8.0

func NormativeSubject(id, qualifiedName string) bool

NormativeSubject reports whether id is the id the norm fixes for the subject a graph names qualifiedName: the library element the encoder writes under that name, or its owning membership, which names nothing. A user element that carries a library uuid is not the library element, so its id stays its own.

func Notice added in v0.6.0

func Notice(from, to Format) string

Notice joins the notices of a conversion into one string, one per line.

func Notices added in v0.6.0

func Notices(from, to Format) []string

Notices lists the experimental notices a conversion between these formats carries, migration first; empty when the conversion is stable.

func RefuseRDFForm added in v0.8.0

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.

func SysMLToRDF

func SysMLToRDF(name string, data []byte) (*rdf.Graph, error)

SysMLToRDF parses SysML notation and converts it to a graph.

func ToRDF

func ToRDF(file *source.SourceFile, root *ast.RootNamespace) (*rdf.Graph, error)

ToRDF converts a parsed document into an RDF graph. file must be the source the tree was parsed from: every element and expression carries the notation it was written as alongside its structural triples, so the conversion needs the bytes as well as the tree.

func ToSysML

func ToSysML(graph *rdf.Graph) ([]byte, error)

ToSysML converts an RDF graph back into SysML v2 source text. An element comes back as its sysx:sourceText, byte for byte, while that still states what the graph states, and in canonical notation otherwise.

A subject whose metaclass this mapping does not know, or which lacks the properties needed to rebuild its declaration, is reported as an UnsupportedError: a converted file that dropped an element would be worse than a failed conversion.

func WriteFile

func WriteFile(path string, data []byte) (replaced bool, err error)

WriteFile writes a converted model to path, reporting whether it replaced a file that was already there.

A regular file is written atomically: the bytes go to a temporary file in the same directory, are flushed, and are renamed over the destination, so an interrupted write leaves the previous model intact rather than a truncated or empty one. An existing file keeps its permissions, and a symlink is written through rather than replaced.

Anything that is not a regular file — a terminal, a pipe, /dev/null, a process substitution — is written directly, since there is no previous content to protect and replacing it by rename would destroy the pipe or device the user pointed at.

Types

type AcceptForm added in v0.8.0

type AcceptForm struct {
	Param        string       `json:"param,omitempty"`
	SignalType   string       `json:"signalType,omitempty"`
	ViaPort      string       `json:"viaPort,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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

type EdgeForm struct {
	Source int       `json:"source"`
	Target int       `json:"target"`
	Guard  *ExprForm `json:"guard,omitempty"`
	Else   bool      `json:"else,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.

type EntryTransitionForm added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

type FormUnsupportedError struct {
	Form   string
	Reason string
}

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

func (*FormUnsupportedError) Error added in v0.8.0

func (e *FormUnsupportedError) Error() string

func (*FormUnsupportedError) Unwrap added in v0.8.0

func (e *FormUnsupportedError) Unwrap() error

Unwrap makes the error match ErrFormUnsupported.

type Format

type Format int

Format is one of the representations a model can be read from or written to.

const (
	// FormatSysML is SysML v2 / KerML textual notation.
	FormatSysML Format = iota
	// FormatTurtle is RDF in Turtle syntax.
	FormatTurtle
	// FormatXMI is SysML v1 as UML XMI 2.5.1, the OMG SysML profile applied, or
	// a .mdzip archive holding it. It is an input format only.
	FormatXMI
)

func FormatOfPath

func FormatOfPath(path string) (Format, error)

FormatOfPath infers the format from a file extension, so that the common case needs no -from. A path that names no format yields an *UnknownFormatError carrying no advice; pass it through Advise to add the remedy the calling surface offers.

func ParseFormat

func ParseFormat(name string) (Format, error)

ParseFormat resolves a format name, as given to `-convert`/`-from`.

func (Format) String

func (f Format) String() string

func (Format) Writable added in v0.6.0

func (f Format) Writable() bool

Writable reports whether models can be written in the format.

type Graphs added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 NotWritableError added in v0.6.0

type NotWritableError struct{ Format Format }

NotWritableError reports a request to write a format that is only read.

func (*NotWritableError) Error added in v0.6.0

func (e *NotWritableError) Error() string

type ObjectFlowForm added in v0.8.0

type ObjectFlowForm struct {
	Name      string   `json:"name,omitempty"`
	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.

type ParameterForm added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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"`
	Via          bool      `json:"via,omitempty"`
	Receiver     string    `json:"receiver,omitempty"`
	ReceiverPath bool      `json:"receiverPath,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 added in v0.8.0

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 SyntaxError

type SyntaxError struct {
	Name     string
	Messages []string
	// Diags are the diagnostics behind Messages, for a caller that reports them
	// with their spans. Empty when the input is not notation, since a Turtle
	// reader reports a message and no span.
	Diags []parser.Diagnostic
	// File is what Diags' spans point into; nil when Diags is empty.
	File *source.SourceFile
}

SyntaxError reports that the input could not be read as its format. It lists every syntax error rather than only the first, so one conversion attempt shows everything that needs fixing.

func ConvertTolerant

func ConvertTolerant(name string, data []byte, from, to Format) ([]byte, *SyntaxError, error)

ConvertTolerant is Convert with one difference: notation converted back to notation is written even when the parser could not read all of it, and its syntax errors are returned as a warning instead of an error. That direction re-indents the input rather than building anything from the parse tree, so the output is exactly as valid as the input and refusing it would only strand work that exists nowhere else — which is why the REPL's `%save` uses it for a session buffer. Every other direction builds a graph from the tree, where declarations the parser could not read would be silently missing, so a broken model is still rejected.

func SysMLElement

func SysMLElement(file *source.SourceFile, span source.Span) ([]byte, *SyntaxError, error)

SysMLElement writes the notation of one element of a document: the source at span, through the same writer a whole-document notation save goes through, so what one surface writes cannot drift from what another writes. Syntax errors are tolerated and returned as a warning, as ConvertTolerant does, since the span comes from a buffer that is written back as typed.

Trailing comments are dropped: a declaration's span ends where the next token begins, so it runs over the notes written for whatever follows it.

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

type TransitionForm added in v0.8.0

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 added in v0.8.0

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.

type UnknownFormatError

type UnknownFormatError struct {
	Path string
	// NoExtension distinguishes a path with no extension from one whose
	// extension names a format we do not write.
	NoExtension bool
	// Advice is the surface's remedy, appended as "…, so <advice>".
	Advice string
}

UnknownFormatError reports that a path does not say which format to write. The remedy differs by surface — the command line has -convert/-from, the REPL only has the file name — so the caller supplies it with Advise.

func (*UnknownFormatError) Error

func (e *UnknownFormatError) Error() string

type UnsupportedError

type UnsupportedError struct {
	What string
	Note string
}

UnsupportedError reports a construct the conversion cannot represent. It names the element so the user can find it, rather than converting a model that silently lost part of itself.

func (*UnsupportedError) Error

func (e *UnsupportedError) Error() string

Jump to

Keyboard shortcuts

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