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, AstNode, AttributeBody, AttributeDef, AttributeUsage, Bind, CaseDef,
17    CaseUsage, CommentAnnotation, Connect, ConnectBody, ConnectStmt, DocComment, EndDecl,
18    Expression, FilterMember, FilterPackageMember, FirstMergeBody, FirstStmt, Flow, FlowDef,
19    FlowUsage, Identification, Import, InOut, InOutDecl, InterfaceDef, InterfaceDefBody,
20    InterfaceDefBodyElement, InterfaceUsage, InterfaceUsageBodyElement, MergeStmt, NamespaceDecl,
21    Node, OccurrenceUsage, Package, PackageBody, PackageBodyElement, ParseErrorNode, PartDef,
22    PartDefBody, PartDefBodyElement, PartUsage, PartUsageBody, PartUsageBodyElement, Perform,
23    PerformBody, PerformBodyElement, PerformInOutBinding, PortBody, PortDef, PortDefBody,
24    PortDefBodyElement, PortUsage, RefBody, RefDecl, RequireConstraint, RequireConstraintBody,
25    RequirementDef, RequirementDefBody, RequirementDefBodyElement, RequirementUsage, RootElement,
26    RootNamespace, Span, TextualRepresentation, VerificationCaseDef, VerificationCaseUsage,
27    Visibility,
28};
29pub use error::{DiagnosticSeverity, ParseError};
30pub use parser::{parse_root, parse_with_diagnostics, ParseResult};
31
32/// Parse a SysML v2 textual input into a root namespace AST.
33///
34/// Returns an error if the input is not valid SysML or if not all input is consumed.
35#[allow(clippy::result_large_err)]
36pub fn parse(input: &str) -> Result<RootNamespace, ParseError> {
37    parse_root(input)
38}
39
40/// Parse for editor/LSP use: returns a partial AST plus diagnostics.
41///
42/// Prefer this over [`parse_root`] when you want IDE features (outline/hover/semantic tokens) to
43/// keep working even when the file contains syntax errors.
44pub fn parse_for_editor(input: &str) -> ParseResult {
45    parse_with_diagnostics(input)
46}