Skip to main content

sysml_v2_parser/ast/
common.rs

1use crate::ast::core::{Expression, Node, Span};
2
3/// KerML ElementFilterMember: MemberPrefix? 'filter' condition ';'
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct FilterMember {
6    pub visibility: Option<Visibility>,
7    pub condition: Node<Expression>,
8}
9
10/// Placeholder node inserted when resilient parsing skips malformed input.
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct ParseErrorNode {
13    pub message: String,
14    pub code: String,
15    pub expected: Option<String>,
16    pub found: Option<String>,
17    pub suggestion: Option<String>,
18    pub category: Option<crate::error::DiagnosticCategory>,
19}
20/// Identification: optional short name in `< >`, optional name.
21/// BNF: ( '<' declaredShortName = NAME '>' )? ( declaredName = NAME )?
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub struct Identification {
24    /// Short name inside `< ... >`, if present.
25    pub short_name: Option<String>,
26    /// Main declared name (may be quoted, e.g. '1a-Parts Tree').
27    pub name: Option<String>,
28}
29
30/// Visibility for imports and members.
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub enum Visibility {
33    Public,
34    Private,
35    Protected,
36}
37
38/// KerML FilterPackageMember: `[` OwnedExpression `]`.
39#[derive(Debug, Clone, PartialEq, Eq)]
40pub struct FilterPackageMember {
41    pub expression: Node<Expression>,
42}
43
44/// Import: `private`? `import` `all`? QualifiedName (`::` `*`)? or FilterPackage form.
45#[derive(Debug, Clone, PartialEq, Eq)]
46pub struct Import {
47    pub visibility: Option<Visibility>,
48    /// Whether this is a namespace import (QualifiedName::* or FilterPackage) or membership import (single QualifiedName).
49    pub is_import_all: bool,
50    /// Import target, e.g. "SI::kg" or "Definitions::*".
51    pub target: String,
52    /// KerML: optional recursive import after :: (e.g. QualifiedName::** or QualifiedName::*::**).
53    pub is_recursive: bool,
54    /// KerML FilterPackage form: one or more `[ expr ]` members. When present, this is a namespace import of a filter package.
55    pub filter_members: Option<Vec<Node<FilterPackageMember>>>,
56}
57/// KerML Documentation: 'doc' Identification? ( 'locale' STRING_VALUE )? body = REGULAR_COMMENT.
58#[derive(Debug, Clone, PartialEq, Eq)]
59pub struct DocComment {
60    /// Optional identification after 'doc'.
61    pub identification: Option<Identification>,
62    /// Optional locale string (e.g. "en").
63    pub locale: Option<String>,
64    /// Body text (content between /* and */).
65    pub text: String,
66}
67
68/// KerML Comment: ( 'comment' Identification? )? ( 'locale' STRING_VALUE )? body = REGULAR_COMMENT.
69#[derive(Debug, Clone, PartialEq, Eq)]
70pub struct CommentAnnotation {
71    pub identification: Option<Identification>,
72    pub locale: Option<String>,
73    pub text: String,
74}
75
76/// KerML TextualRepresentation: ( 'rep' Identification )? 'language' STRING_VALUE body.
77#[derive(Debug, Clone, PartialEq, Eq)]
78pub struct TextualRepresentation {
79    pub rep_identification: Option<Identification>,
80    pub language: String,
81    pub language_span: Option<Span>,
82    pub text: String,
83}
84/// Body of a connect statement: `;` or `{` ... `}`.
85#[derive(Debug, Clone, PartialEq, Eq)]
86pub enum ConnectBody {
87    Semicolon,
88    Brace,
89}