Parsing & building

longeron.parser

Parsing front-end: SysML v2 and KerML text -> ANTLR parse trees.

longeron.parser.Language

the two grammars this front-end parses (inferred from the file suffix by parse_file() when not given explicitly)

alias of Literal[‘sysml’, ‘kerml’]

class longeron.parser.ParseResult(tree, parser, tokens, language, source_name)[source]

Bases: object

A parse tree plus the machinery needed to interpret it.

tree_text()[source]

Lisp-style rendering of the parse tree (for debugging).

Return type:

str

longeron.parser.parse_sysml_text(text, source_name='<text>')[source]

Parse SysML v2 textual notation; raises ParseError on errors.

Return type:

ParseResult

longeron.parser.parse_kerml_text(text, source_name='<text>')[source]

Parse KerML textual notation; raises ParseError on errors.

KerML support is syntactic: you get a validated parse tree, not a model.

Return type:

ParseResult

longeron.parser.parse_file(path, language=None)[source]

Parse a .sysml or .kerml file (language inferred from suffix).

Return type:

ParseResult

longeron.parser.parse_expression_text(text, source_name='<expr>')[source]

Parse a single SysML owned-expression snippet, e.g. "2 + x * 3".

Return type:

ParseResult

longeron.builder

Transform ANTLR parse trees of SysML v2 text into longeron.model objects.

The builder covers the full textual notation: packages, imports/aliases, comments/docs, every definition and usage kind (including views, interfaces, flows, allocations, and metadata), expressions, calculations, constraints, requirements, actions (assign / if / loops / send / accept / perform / successions) and state machines. There is no lossy fallback: every construct maps to a typed model element, and the test suite asserts that building produces zero Unsupported elements. Unsupported survives only as a defensive dead-end for grammar rules the dispatch fails to claim.

longeron.builder.build_model(result)[source]

Build a model from a ParseResult (SysML only).

Return type:

Model

longeron.builder.loads(text, source_name='<text>')[source]

Parse SysML v2 text and build a model.

Return type:

Model

longeron.builder.parse_expression(text)[source]

Parse an expression snippet (e.g. "2 + x") into an AST node.

Return type:

Expr