Skip to main content

oak_j/ast/
mod.rs

1#![doc = include_str!("readme.md")]
2/// Root node of the J syntax tree.
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct JRoot {
5    /// Items in this J file.
6    pub items: Vec<JItem>,
7}
8
9impl JRoot {
10    /// Creates a new J root node.
11    pub fn new(items: Vec<JItem>) -> Self {
12        Self { items }
13    }
14
15    /// Gets all top-level items in this J file.
16    pub fn items(&self) -> &[JItem] {
17        &self.items
18    }
19}
20
21/// Item in an J file.
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub enum JItem {
24    /// A sentence (the basic unit in J).
25    Sentence(JSentence),
26}
27
28/// J sentence.
29#[derive(Debug, Clone, PartialEq, Eq)]
30pub struct JSentence {
31    /// Content of the sentence.
32    pub content: String,
33}
34
35impl JSentence {
36    /// Creates a new sentence.
37    pub fn new(content: String) -> Self {
38        Self { content }
39    }
40}
41
42/// J assignment.
43#[derive(Debug, Clone, PartialEq, Eq)]
44pub struct JAssignment {
45    /// Name being assigned to.
46    pub name: String,
47    /// Whether it's a global assignment (=:).
48    pub is_global: bool,
49    /// The expression being assigned.
50    pub expression: String,
51}