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:
Area |
Names |
|---|---|
Parse / build |
|
Load / cache |
|
Export |
|
Import |
|
Validate |
|
Standard library |
|
Execute |
|
Model elements |
everything in |
longeron.errors¶
Exception types for the longeron package.
- exception longeron.errors.MissingExtraError(feature, package, extra=None, *, command=None)[source]¶
Bases:
SysMLError,ImportErrorAn optional dependency of this feature is not installed.
Every optional-import guard in the package raises this one type – it is both a
SysMLErrorand anImportError, 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 (
Nonefor 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:
objectA single syntax error reported by the ANTLR parser.
messageis the humanized text shown to users;raw_messagepreserves the verbatim ANTLR wording (expected-token sets and all) for anyone debugging the grammar.source_linecarries the offending line of source when the parser had it in hand.
- class longeron.errors.SourceLocation(source_name, line, column)[source]¶
Bases:
objectWhere 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_locationattribute) 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:
SysMLErrorRaised when source text does not conform to the grammar.
- exception longeron.errors.BuildError[source]¶
Bases:
SysMLErrorRaised when a parse tree cannot be transformed into a model.
- exception longeron.errors.ResolutionError[source]¶
Bases:
SysMLErrorRaised when a qualified name cannot be resolved.
- exception longeron.errors.EditError[source]¶
Bases:
SysMLErrorRaised when a model edit is invalid or would corrupt references.
longeron.editrefuses 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:
SysMLErrorRaised when an expression cannot be evaluated.
- exception longeron.errors.ExecutionError[source]¶
Bases:
SysMLErrorRaised when an action or state machine cannot be executed.