convert

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 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

View Source
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.

View Source
const ExtensionAdvice = "name the file with a .sysml, .kerml, .ttl or .json 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, api-json, or xmi/uml/mdzip (input only)"

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

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 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

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 ConvertWith

func ConvertWith(name string, data []byte, from, to Format, opts Options) ([]byte, error)

ConvertWith is Convert under non-default options.

func FormatNames

func FormatNames() []string

FormatNames returns every name ParseFormat accepts, sorted.

func FromGraph

func FromGraph(graph *rdf.Graph, to Format) ([]byte, error)

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 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 Notice

func Notice(from, to Format) string

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

func Notices

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 SysMLToRDF

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

SysMLToRDF parses SysML notation and converts it to a graph.

Types

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
)

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

func (f Format) Writable() bool

Writable reports whether models can be written in the format.

type Migration

type Migration struct {
	Output  []byte
	Report  *migrate.Report
	Results *simresults.Results
}

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.

func Migrate

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

Migrate reads a SysML v1 model in XMI and writes it in the to format. opts carries the migration's augments: an MTIP export whose diagram records lay out the views the migration writes.

type NotWritableError

type NotWritableError struct{ Format Format }

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

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
}

Options carries the conversion settings a caller may change from their defaults.

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 ConvertTolerantWith

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

ConvertTolerantWith is ConvertTolerant under non-default options.

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 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

Jump to

Keyboard shortcuts

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