Documentation
¶
Overview ¶
Package sysml reads a SysML v2 model the way the SysML v2 API serves it (requirement DS-4): element queries (Query), reads of one element's metamodel properties (Props, cached), facts built on them (names, docs, representations, specializations) and expression evaluation (Evaluate). Nothing exports the whole model. It works on a model parsed by OpenSysML's in-process engine (github.com/Open-MBEE/OpenSysML).
Index ¶
- Constants
- Variables
- type Model
- func (m *Model) Close() error
- func (m *Model) Contains(id string) bool
- func (m *Model) Docs(ctx context.Context, id string) ([]string, error)
- func (m *Model) Evaluate(ctx context.Context, subject, expression string) (opensysml.Value, error)
- func (m *Model) Generals(ctx context.Context, id string) ([]string, error)
- func (m *Model) Members(ctx context.Context, id string) ([]Ref, error)
- func (m *Model) Name(ctx context.Context, id string) (string, error)
- func (m *Model) Owner(ctx context.Context, id string) (Ref, error)
- func (m *Model) Props(ctx context.Context, id string, names ...string) (*Props, error)
- func (m *Model) QualifiedName(ctx context.Context, id string) (string, error)
- func (m *Model) Query(ctx context.Context, q opensysml.Query) ([]opensysml.QueryElement, error)
- func (m *Model) Redefined(ctx context.Context, id string) ([]string, error)
- func (m *Model) RenderView(ctx context.Context, qualifiedName string, opts ...opensysml.RenderViewOption) (*opensysml.RenderedView, error)
- func (m *Model) Representation(ctx context.Context, id string) (Representation, error)
- func (m *Model) Representations(ctx context.Context, id string) ([]Representation, error)
- func (m *Model) ShortName(ctx context.Context, id string) (string, error)
- func (m *Model) Specializes(ctx context.Context, specific, general string) (bool, error)
- func (m *Model) Stats() Stats
- func (m *Model) Types(ctx context.Context, id string) ([]Ref, error)
- type Props
- type Ref
- type Representation
- type Stats
Constants ¶
const UnnamedName = "Unnamed"
UnnamedName stands in for the name of an element without one, wherever this tool shows its name (requirement PG-5).
Variables ¶
var ErrNoSuchElement = errors.New("model: no such element")
ErrNoSuchElement matches (errors.Is) the error Props returns for an id the model does not know.
Functions ¶
This section is empty.
Types ¶
type Model ¶
type Model struct {
// ElementCount is the number of elements in the model.
ElementCount int
// Tops are the top-level elements, in file order: the members of each
// file's root namespace.
Tops []Ref
// contains filtered or unexported fields
}
Model reads one parsed model. It is not safe for concurrent use: reads are cached.
func Open ¶
Open reads the model parsed by client: it queries every element once, for ElementCount, Tops and the model's own ids. Open takes the client over when it succeeds: Close closes it. On error the client stays the caller's.
func (*Model) Close ¶
Close releases the engine. What was read stays cached, but nothing more can be read.
func (*Model) Contains ¶
Contains reports whether id is an element of the model itself, not of the standard library it refers to.
func (*Model) Docs ¶
Docs are the bodies of the element's doc comments, trimmed, in declaration order.
func (*Model) Evaluate ¶
Evaluate evaluates a SysML expression with the element named subject (by qualified name) as its subject, so a feature reads that element's value: its own, a redefinition's, or one inherited from its types.
func (*Model) Generals ¶
Generals are the ids of the elements the element specializes directly, through any specialization it owns (typing, subclassification, subsetting, redefinition, reference subsetting), in declaration order. A standard-library element's are not read, and are none: reading any library element makes OpenSysML build its library document's element form, seconds per document (AGENTS.md §13), and the library has no pages.
func (*Model) Name ¶
Name is the element's name: its declared name, or the one it gets otherwise (a redefining feature borrows the redefined feature's); "" when it has none. A library element's is the last segment of its qualified name.
func (*Model) Owner ¶
Owner is the element that owns the element; the zero Ref for a root namespace.
func (*Model) Props ¶
Props reads the named properties of the element id names: an element form id (M__pd), a qualified name (M::pd) or a positional id (M::@2). Values are cached, so asking again costs nothing. A property the element's metaclass does not declare reads as empty. Not safe for concurrent use.
func (*Model) QualifiedName ¶
QualifiedName is how the element is identified in messages and to the evaluator: its qualified name, or for an element without one its positional name, its owner's name followed by @ and its position among the owner's members (M::@2, counted from 0), as OpenSysML writes it. A root namespace, which is no element of the model's text, has "".
func (*Model) Query ¶
Query selects the model's elements a query matches, in declaration order. A property it selects gives one value per element (see AGENTS.md §13): read multi-valued properties with Props.
func (*Model) Redefined ¶
Redefined are the ids of the features the feature redefines, in declaration order.
func (*Model) RenderView ¶
func (m *Model) RenderView(ctx context.Context, qualifiedName string, opts ...opensysml.RenderViewOption) (*opensysml.RenderedView, error)
RenderView renders the view with that qualified name as the view's data (nodes, edges, a table's columns and rows), shaped by the options; with opensysml.WithForm it also writes the view in that form — DOT for a diagram, CSV or text for a table (MC-21). Without a form, Columns and Rows say whether the view is tabular.
func (*Model) Representation ¶
Representation reads the textual representation id names.
func (*Model) Representations ¶
Representations are the textual representations the element owns, in any language, in declaration order.
func (*Model) Specializes ¶
Specializes reports whether element specific is typed by, subclasses or subsets element general, directly or through a chain of such relationships (part spare : Sport with Sport :> Wheel specializes Wheel). No element specializes itself.
type Props ¶
type Props struct {
Element Ref
// contains filtered or unexported fields
}
Props are metamodel properties of one element, as Model.Props read them.
func (*Props) Refs ¶
Refs are the elements a property refers to, in order; none when the property is empty, absent, or holds no elements.
type Ref ¶
type Ref struct {
// ID is the element's id in the SysML v2 API element form ("M__pd"),
// which Props accepts back.
ID string
// QualifiedName is "" for an unnamed element; a library element's is its
// library path (ScalarValues::Real).
QualifiedName string
// Metaclass is the element's metaclass: "PartUsage", "Package", ...
Metaclass string
}
Ref identifies an element: one of the model, or a standard-library element the model refers to.
type Representation ¶
type Representation struct {
ID string
Owner string // id of the element that owns it
Language string // as written
Body string // exactly as written, untrimmed
}
Representation is a textual representation, in any language.
type Stats ¶
type Stats struct {
Queries int // Query calls
Reads int // ElementProperties calls: elements, or properties, not cached yet
Hits int // Props calls answered from the cache
}
Stats count how the model was read: the cost of reading it through queries and element reads rather than one export (DS-4).