Documentation
¶
Overview ¶
Package convert is the entry point of `sysml -convert`, `%save` and the service's Export: it names the formats a model is read from and written to and drives each conversion, parsing notation and migrating SysML v1 XMI before handing the tree or graph to internal/translate/export.
Index ¶
- Constants
- Variables
- func Advise(err error, advice string) error
- func Convert(name string, data []byte, from, to Format) ([]byte, error)
- func ConvertModel(inputs []Input, to Format, opts Options) ([]byte, error)
- func ConvertModelTo(out io.Writer, inputs []Input, to Format, opts Options) error
- func ConvertTo(out io.Writer, name string, data []byte, from, to Format, opts Options) error
- func ConvertWith(name string, data []byte, from, to Format, opts Options) ([]byte, error)
- func FormatNames() []string
- func FromGraph(graph *rdf.Graph, to Format) ([]byte, error)
- func FromGraphTo(out io.Writer, graph *rdf.Graph, to Format, opts Options) error
- func FromGraphWith(graph *rdf.Graph, to Format, opts Options) ([]byte, error)
- func IsExperimental(from, to Format) bool
- func ModelGraph(inputs []Input, opts Options) (*rdf.Graph, error)
- func ModelSource(name string, data []byte, warn func(string)) (text []byte, converted bool, err error)
- func Notice(from, to Format) string
- func Notices(from, to Format) []string
- func SysMLToRDF(name string, data []byte) (*rdf.Graph, error)
- type FMUChangedError
- type FMUNotAFileError
- type Format
- type Input
- type MigrateOptions
- type Migration
- type MigrationReport
- type NotMigratedError
- type NotV1Error
- type NotWritableError
- type Options
- type SyntaxError
- func ConvertTolerant(name string, data []byte, from, to Format) ([]byte, *SyntaxError, error)
- func ConvertTolerantTo(out io.Writer, name string, data []byte, from, to Format, opts Options) (*SyntaxError, error)
- func ConvertTolerantWith(name string, data []byte, from, to Format, opts Options) ([]byte, *SyntaxError, error)
- func SyntaxErrorOf(name string, file *source.SourceFile, diags []parser.Diagnostic) *SyntaxError
- func SysMLElement(file *source.SourceFile, span source.Span) ([]byte, *SyntaxError, error)
- type UnknownFormatError
- type Verdict
Constants ¶
const ( Mapped = migrate.Mapped Approximated = migrate.Approximated Unmapped = migrate.Unmapped Skipped = migrate.Skipped )
The verdicts a migration report records.
const ExperimentalNotice = "RDF conversion — Turtle and the API's JSON element form alike — 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.
const ExtensionAdvice = "name the file with a .sysml, .kerml, .ttl, .json or .fmu 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.
const FMINotice = "FMI model import is experimental: an FMU's model description becomes a calc " +
"def, its variables, experiment and outputs the parameters and @ToolVariable bindings, " +
"structural parameters, multi-dimensional and structural arrays, Binary and Clock values comments where they stood, and " +
"what the import writes may change without a compatibility path; see docs/reference/fmi.md"
FMINotice is the wording every surface reports the FMI model import's status in.
const FormatList = "sysml, kerml, ttl, turtle, rdf, api-json, fmu or xmi/uml/mdzip (input only)"
FormatList is the wording every surface lists the format names in.
const MigratedNotConverted = "is a SysML v1 model, which is migrated, not converted: every element " +
"is mapped, approximated or left unmapped and reported element by element"
MigratedNotConverted is why a SysML v1 model is refused by a conversion: its elements are mapped, approximated or left unmapped, and a conversion promises none of that. Each surface appends the remedy in its own terms.
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 ¶
var ErrFMUChanged = errors.New("the FMU changed since it was read")
ErrFMUChanged is the typed error for an FMU whose file changed since it was read.
var ErrFMUNotAFile = errors.New("the FMU did not come from a file")
ErrFMUNotAFile is the typed error for an FMU import that names no file.
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.
Functions ¶
func Advise ¶
Advise returns err with the surface's remedy attached when it is an *UnknownFormatError, and unchanged otherwise.
func Convert ¶
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 ConvertModel ¶ added in v0.9.2
ConvertModel converts the notation of several documents, one model, to one graph written in to (Turtle or the API's JSON element form): a reference from one document to an element another declares links it, as within one document. A document that does not parse fails the conversion.
func ConvertModelTo ¶ added in v0.13.0
ConvertModelTo is ConvertModel writing to out; the API's JSON element array is written an element at a time rather than built whole.
func ConvertTo ¶ added in v0.13.0
ConvertTo is ConvertWith writing to out; the API's JSON element array is written an element at a time rather than built whole.
func ConvertWith ¶
ConvertWith is Convert under non-default options.
func FormatNames ¶
func FormatNames() []string
FormatNames returns every name ParseFormat accepts, sorted.
func FromGraph ¶
FromGraph writes a graph in the to format, so a graph that did not come from a Turtle file — a repository branch read as RDF — converts alike.
func FromGraphTo ¶ added in v0.13.0
FromGraphTo is FromGraphWith writing to out.
func FromGraphWith ¶ added in v0.9.2
FromGraphWith writes a graph in the to format with conversion options.
func IsExperimental ¶
IsExperimental reports whether a conversion between these formats goes through the RDF mapping, the SysML v1 migration or the FMI model import. Notation to notation does not.
func ModelGraph ¶ added in v0.11.0
ModelGraph parses several documents as one model and returns its RDF graph, the one ConvertModel writes out as Turtle; ids are spelled as opts.ID says.
func ModelSource ¶ added in v0.10.0
func ModelSource(name string, data []byte, warn func(string)) (text []byte, converted bool, err error)
ModelSource converts an explicitly named API-JSON source to SysML notation. Other formats are returned unchanged.
Types ¶
type FMUChangedError ¶ added in v0.9.2
type FMUChangedError struct{ Name string }
FMUChangedError reports an FMU import whose name resolves a file that does not hold the bytes converted: the archive moved between the read and the uri the calc def would carry.
func (*FMUChangedError) Error ¶ added in v0.9.2
func (e *FMUChangedError) Error() string
Error names the file that changed.
func (*FMUChangedError) Is ¶ added in v0.9.2
func (e *FMUChangedError) Is(target error) bool
Is matches ErrFMUChanged.
type FMUNotAFileError ¶ added in v0.9.2
type FMUNotAFileError struct{ Name string }
FMUNotAFileError reports an FMU import whose name resolves no file on disk: the archive came from standard input or an inline document, and the calc def's uri must name the archive, so there is nothing correct to write.
func (*FMUNotAFileError) Error ¶ added in v0.9.2
func (e *FMUNotAFileError) Error() string
Error names where the FMU came from.
func (*FMUNotAFileError) Is ¶ added in v0.9.2
func (e *FMUNotAFileError) Is(target error) bool
Is matches ErrFMUNotAFile.
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 // FormatAPIJSON is the OMG SysML v2 API element form: JSON objects with // "@type", "@id" and the metamodel properties as keys, over the same graph // the Turtle mapping builds. FormatAPIJSON // FormatFMU is a Functional Mock-up Unit: a zip archive whose // modelDescription.xml imports as a calc def computed by the `fmi` tool. // It is input only. FormatFMU )
func FormatOfPath ¶
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 ¶
ParseFormat resolves a format name, as given to `-convert`/`-from`.
type MigrateOptions ¶ added in v0.10.0
MigrateOptions carries a migration's augments, as Migrate takes them: an MTIP export whose diagram records lay out the views, the server a comment's relative image is resolved against, and strictness. It is migrate.Options, named here so a caller drives the migration through this package alone.
type Migration ¶
type Migration struct {
Output []byte
Report *migrate.Report
Results *simresults.Results
// Files are the attached image files the migration wrote for its document
// Image blocks, by the relative path they belong under; a caller writes
// them beside Output, empty when none was attached.
Files map[string][]byte
}
Migration is a v1 model written in another format, with the report of what each v1 element became and the results its simulation tool stored.
type MigrationReport ¶ added in v0.10.0
MigrationReport is the ledger a migration writes: one entry per v1 element with its Verdict.
type NotMigratedError ¶ added in v0.10.0
type NotMigratedError struct {
// Name is the model named: a path, or what stands for inline content.
Name string
// Remedy says how to migrate it on the surface that refused.
Remedy string
}
NotMigratedError refuses a SysML v1 model asked to be converted, naming the model and what to do instead.
func (*NotMigratedError) Error ¶ added in v0.10.0
func (e *NotMigratedError) Error() string
type NotV1Error ¶ added in v0.10.0
NotV1Error refuses a migration of a model that is not SysML v1: a v2 model or an RDF graph is converted, not migrated.
func (*NotV1Error) Error ¶ added in v0.10.0
func (e *NotV1Error) Error() string
type NotWritableError ¶
NotWritableError reports a request to write a format that is only read. Migrating is set when the request was a migration, so the remedy names that verb.
func (*NotWritableError) Error ¶
func (e *NotWritableError) Error() string
type Options ¶
type Options struct {
// ID is the form derived element ids are written in; the zero value is
// qualified-name-derived ids.
ID export.IDForm
Warn func(string)
// Compact, when set, writes the API's JSON element form as the compact
// document (export.WriteAPIJSONCompact) rather than the standard array.
Compact *export.CompactAPIJSONOptions
// IncludeLibraryStubs restores ownerless standard-library stubs for legacy readers.
IncludeLibraryStubs bool
// LibraryReferences receives the API JSON output's standard-library name table.
LibraryReferences func([]export.APIJSONLibraryReference)
// InheritedMembers has the API JSON output repeat each Namespace's and Type's inherited
// members (export.APIJSONOptions.InheritedMembers); off, it holds the owned structure.
InheritedMembers bool
// KeepLineBreaks keeps the input's line breaks on notation → notation (a
// save or echo); otherwise each statement of a body gets its own line.
KeepLineBreaks bool
}
Options carries the conversion settings a caller may change from their defaults.
func (Options) WritesLibraryStubs ¶ added in v0.13.0
WritesLibraryStubs reports an api-json conversion that writes the library stubs as elements, so its graph has to state every one before the writer orders them.
type SyntaxError ¶
type SyntaxError = parser.SyntaxError
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 ¶
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 ConvertTolerantTo ¶ added in v0.13.0
func ConvertTolerantTo(out io.Writer, name string, data []byte, from, to Format, opts Options) (*SyntaxError, error)
ConvertTolerantTo is ConvertTolerantWith writing to out.
func ConvertTolerantWith ¶
func ConvertTolerantWith(name string, data []byte, from, to Format, opts Options) ([]byte, *SyntaxError, error)
ConvertTolerantWith is ConvertTolerant under non-default options.
func SyntaxErrorOf ¶ added in v0.9.2
func SyntaxErrorOf(name string, file *source.SourceFile, diags []parser.Diagnostic) *SyntaxError
SyntaxErrorOf reports a document's parser diagnostics as a SyntaxError, or nil when there are none: a graph built from a tree the parser could not read whole would silently miss what it skipped.
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.
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