Skip to main content

gram_codec/cst/
syntax_node.rs

1//! Foundational CST data types shared by parsing and lowering.
2
3use crate::{Pattern, Subject, Value};
4use pattern_core::Symbol;
5
6#[derive(Clone, Debug, PartialEq, Eq)]
7pub struct SourceSpan {
8    pub start: usize,
9    pub end: usize,
10}
11
12#[derive(Clone, Debug, PartialEq, Eq)]
13pub enum ArrowKind {
14    Right,
15    Left,
16    Bidirectional,
17    Undirected,
18}
19
20#[derive(Clone, Debug, PartialEq, Eq)]
21pub enum SyntaxKind {
22    Document,
23    Node,
24    Relationship(ArrowKind),
25    Subject,
26    Annotated,
27    Comment,
28}
29
30#[derive(Clone, Debug)]
31pub enum Annotation {
32    Property {
33        key: String,
34        value: Value,
35    },
36    Identified {
37        identity: Option<Symbol>,
38        labels: Vec<String>,
39    },
40}
41
42#[derive(Clone, Debug)]
43pub struct SyntaxNode {
44    pub kind: SyntaxKind,
45    pub subject: Option<Subject>,
46    pub span: SourceSpan,
47    pub annotations: Vec<Annotation>,
48    pub text: Option<String>,
49}
50
51#[derive(Clone, Debug)]
52pub struct CstParseResult {
53    pub tree: Pattern<SyntaxNode>,
54    pub errors: Vec<SourceSpan>,
55}
56
57impl CstParseResult {
58    pub fn is_valid(&self) -> bool {
59        self.errors.is_empty()
60    }
61}