Package API & errors

longeron

longeron – define, export, and execute SysML v2 models in Python.

Powered by ANTLR4 grammars for SysML v2 and KerML.

Quick start:

import longeron

model = longeron.loads('''
    package Demo {
        part def Vehicle {
            attribute mass : Real = 1200.0;
        }
        calc def Double { in x : Real; return : Real = 2 * x; }
    }
''')

print(longeron.to_sysml(model))          # textual export
print(longeron.to_json(model))           # JSON export

interp = longeron.Interpreter(model)
car = interp.instantiate("Demo::Vehicle")
print(car.slots["mass"])               # 1200.0
print(interp.call("Demo::Double", 21)) # 42

The top level re-exports the everyday API; each object is documented on its home-module page:

longeron.errors

Exception types for the longeron package.

exception longeron.errors.SysMLError[source]

Bases: Exception

Base class for all longeron errors.

exception longeron.errors.MissingExtraError(feature, package, extra=None, *, command=None)[source]

Bases: SysMLError, ImportError

An optional dependency of this feature is not installed.

Every optional-import guard in the package raises this one type – it is both a SysMLError and an ImportError, so handlers written against either keep working – with a uniform message carrying the exact install command (pip install "longeron[extra]").

feature

what was being attempted, e.g. "the replay widget"

package

the missing distribution/module, e.g. "anywidget"

extra

the pip extra that provides it (None for non-extra installs)

command

the exact command that fixes it

class longeron.errors.SyntaxIssue(line, column, message, raw_message=None, source_line=None)[source]

Bases: object

A single syntax error reported by the ANTLR parser.

message is the humanized text shown to users; raw_message preserves the verbatim ANTLR wording (expected-token sets and all) for anyone debugging the grammar. source_line carries the offending line of source when the parser had it in hand.

class longeron.errors.SourceLocation(source_name, line, column)[source]

Bases: object

Where a model element was declared: source (file path or label), 1-based line, 1-based column.

Stamped on elements by the builder (as a plain source_location attribute) and carried by lint diagnostics. Models rebuilt from JSON – including model-cache hits – carry no source locations.

exception longeron.errors.ParseError(issues, source_name='<text>')[source]

Bases: SysMLError

Raised when source text does not conform to the grammar.

exception longeron.errors.BuildError[source]

Bases: SysMLError

Raised when a parse tree cannot be transformed into a model.

exception longeron.errors.ResolutionError[source]

Bases: SysMLError

Raised when a qualified name cannot be resolved.

exception longeron.errors.EditError[source]

Bases: SysMLError

Raised when a model edit is invalid or would corrupt references.

longeron.edit refuses any mutation it cannot prove safe – a rename that would break or silently re-bind references raises this error (listing the affected sites) instead of corrupting the model.

exception longeron.errors.EvaluationError[source]

Bases: SysMLError

Raised when an expression cannot be evaluated.

exception longeron.errors.ExecutionError[source]

Bases: SysMLError

Raised when an action or state machine cannot be executed.