Skip to main content

sysml_v2_parser/
lib.rs

1//! SysML v2 textual notation parser.
2//!
3//! Reusable library for parsing SysML v2 textual syntax into an AST.
4#![cfg_attr(
5    not(test),
6    deny(clippy::unwrap_used, clippy::expect_used, clippy::panic)
7)]
8
9pub mod ast;
10pub mod error;
11pub mod parser;
12
13pub use ast::{
14    ActionDef, ActionDefBody, ActionDefBodyElement, ActionUsage, ActionUsageBody,
15    ActionUsageBodyElement, AliasBody, AliasDef, AllocationDef, AllocationUsage, AnalysisCaseDef,
16    AnalysisCaseUsage, Annotation, AstNode, AttributeBody, AttributeDef, AttributeUsage, Bind,
17    CaseDef, CaseUsage, CommentAnnotation, Connect, ConnectBody, ConnectStmt, ConnectionDef,
18    ConnectionDefBody, ConnectionDefBodyElement, DocComment, EndDecl, Expression, FilterMember,
19    FilterPackageMember, FirstMergeBody, FirstStmt, Flow, FlowDef, FlowUsage, Identification,
20    Import, InOut, InOutDecl, InterfaceDef, InterfaceDefBody, InterfaceDefBodyElement,
21    InterfaceUsage, InterfaceUsageBodyElement, MergeStmt, NamespaceDecl, Node,
22    OccurrenceBodyElement, OccurrenceUsage, OccurrenceUsageBody, Package, PackageBody,
23    PackageBodyElement, ParseErrorNode, PartDef, PartDefBody, PartDefBodyElement, PartUsage,
24    PartUsageBody, PartUsageBodyElement, Perform, PerformBody, PerformBodyElement,
25    PerformInOutBinding, PortBody, PortBodyElement, PortDef, PortDefBody, PortDefBodyElement, PortUsage, RefBody,
26    RefDecl, RequireConstraint, RequireConstraintBody, RequirementDef, RequirementDefBody,
27    RequirementDefBodyElement, RequirementUsage, RootElement, RootNamespace, Span,
28    TextualRepresentation, VerificationCaseDef, VerificationCaseUsage, Visibility,
29};
30pub use error::{DiagnosticCategory, DiagnosticSeverity, ParseError};
31pub use parser::{parse_root, parse_with_diagnostics, ParseResult};
32
33/// Parse a SysML v2 textual input into a root namespace AST.
34///
35/// Returns an error if the input is not valid SysML or if not all input is consumed.
36#[allow(clippy::result_large_err)]
37pub fn parse(input: &str) -> Result<RootNamespace, ParseError> {
38    parse_root(input)
39}
40
41/// Parse for editor/LSP use: returns a partial AST plus diagnostics.
42///
43/// Prefer this over [`parse_root`] when you want IDE features (outline/hover/semantic tokens) to
44/// keep working even when the file contains syntax errors.
45pub fn parse_for_editor(input: &str) -> ParseResult {
46    parse_with_diagnostics(input)
47}