A SysML v2 and KerML textual notation parser for Rust. It has a strict mode for validation and a resilient mode for editors, which returns a partial tree with diagnostics for any input.
[dependencies]
sysml-v2-parser = "0.62"
# Add `features = ["serde"]` to serialize complete documents.Requires Rust 1.88. Upgrading? See the changelog and the v0.62.0 migration guide.
use sysml_v2_parser::{parse, parse_for_editor};
// Strict: rejects anything the grammar does not allow.
let document = parse("package Demo;").expect("valid SysML");
assert_eq!(document.root.elements.len(), 1);
// Editor: never fails, and keeps what it can of an unfinished document.
let result = parse_for_editor("package Demo { part def Motor;");
assert!(!result.is_ok());
assert!(!result.errors.is_empty());| Entry point | Use it for |
|---|---|
parse |
Validation and anywhere invalid text must be rejected. |
parse_for_editor |
Editors and language servers. Returns a partial ParsedDocument plus diagnostics. |
parse_with_name_language |
KerML sources, which reserve different keywords. Pass ast::NameLanguage::Kerml. |
emit_sysml |
Formatting a fully recognized document. Refuses recovered content. |
emit_recovered_sysml |
Formatting an editor document, reprinting malformed text in place. |
A ParsedDocument keeps the source, reference arena and tree together. References are
document-local IDs: resolve them with ParsedDocument::qualified_reference. With the serde
feature, the document serializes as one envelope carrying PARSE_AST_VERSION, and deserializing
validates it and rejects a version mismatch.
Read the connector field of a connection usage or standalone connect to inspect its
ConnectorPart. The Binary variant uses to, and the Nary variant uses parentheses and
commas, including when the list contains exactly two ends.
KerML connectors expose their declaration alternative as KermlConnectorForm. When a
connector end declares a name, read declared_name for its identification and operator
spelling and target for the referenced feature.
Reference and cross subsettings are ordered lists of SingleTargetSubsetting nodes.
Each authored ::>, references, =>, or crosses clause contributes one target.
View bodies expose shared definition and usage members through ViewDefinitionBodyMember.
Source successions expose the introduced occurrence usage and its optional source multiplicity.
The grammar is pinned in docs/conformance-target and exposed as
SUPPORTED_GRAMMAR. CI checks the parser against the release corpus and against an independent
parser. Known gaps are listed in docs/SYSML_V2_COMPLIANCE_GAP.md.
cargo fmt --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test --all-features
cargo snapshot checkSee docs/DEVELOPMENT.md for the full validation suite, snapshots and
benchmarks.
| Topic | Doc |
|---|---|
| Migration | v0.62.0, v0.61.0, v0.60.0, v0.59.0, v0.58.0 |
| Development | docs/DEVELOPMENT.md |
| Release procedure | docs/RELEASING.md |
| Error recovery | docs/ERROR_RECOVERY.md |
| Conformance | docs/CONFORMANCE.md, docs/BNF_COVERAGE.md, docs/PARSER-ORACLE.md |
| Backlog | docs/PARSER_BACKLOG_ROADMAP.md, docs/PARSER_TECHNICAL_DEBT.md |
MIT. See LICENSE.