Registry / RepositoryTypeScriptRustPython
Rollpie
ReadmeFiles
Versions
Info
Download
0.2.3555.5 KB2026-10-160.2.2572.8 KB2026-10-150.2.1580.5 KB2026-10-150.2.0579.9 KB2026-09-150.1.1576.6 KB2026-09-12
Version
0.2.3
Copyright
Rollpie, Irohabook
Publisher
math
Published
2026-10-16
Size
555.5 KB
Downloads
26
Checksum
c6c938cc3641f85bee86c9360c2356581a4b1efb11333b9d97b3c5605c8bb71c
Dependencies
None

node.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Class {
    Variable,
    Ordinary,
    Binary,
    Relation,
    Open,
    Close,
    Punctuation,
    Function,
    Large,
    Space(f64),
}


#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Style {
    Auto,
    Roman,
    Italic,
    Bold,
    BoldItalic,
    Blackboard,
    Script,
    Fraktur,
    SansSerif,
    Monospace,
}


#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Limits {
    Auto,
    Always,
    Never,
}


#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Level {
    Display,
    Text,
    Script,
    ScriptScript,
}


#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Align {
    Left,
    Center,
    Right,
}


#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Spacing {
    Matrix,
    Align,
    Alignat,
}


#[derive(Debug, Clone, PartialEq)]
pub enum Node {
    Symbol {
        text: String,
        class: Class,
    },
    Text(String),
    Row(Vec<Node>),
    Fraction {
        numerator: Box<Node>,
        denominator: Box<Node>,
        bar: bool,
    },
    Root {
        index: Option<Box<Node>>,
        body: Box<Node>,
    },
    Scripts {
        base: Box<Node>,
        superscript: Option<Box<Node>>,
        subscript: Option<Box<Node>>,
        limits: Limits,
    },
    Fenced {
        left: &'static str,
        right: &'static str,
        body: Box<Node>,
    },
    Matrix {
        rows: Vec<Vec<Node>>,
        left: &'static str,
        right: &'static str,
        align: Vec<Align>,
        lines: Vec<usize>,
        spacing: Spacing,
    },
    Styled {
        style: Style,
        body: Box<Node>,
    },
    Operator {
        body: Box<Node>,
    },
    Accent {
        mark: &'static str,
        body: Box<Node>,
        above: bool,
    },
    Sized {
        level: Level,
        body: Box<Node>,
    },
    Delimiter {
        text: &'static str,
        height: f64,
        class: Class,
    },
    Extend {
        mark: &'static str,
        above: Option<Box<Node>>,
        below: Option<Box<Node>>,
    },
    Line {
        body: Box<Node>,
        above: bool,
    },
    Phantom {
        body: Box<Node>,
        width: bool,
        height: bool,
    },
}


pub fn empty() -> Node {
    Node::Row(Vec::new())
}


pub fn is_empty(node: &Node) -> bool {
    matches!(node, Node::Row(items) if items.is_empty())
}


pub fn class_of(node: &Node) -> Class {
    match node {
        Node::Symbol {class, ..} => *class,
        Node::Scripts {base, ..} => class_of(base),
        Node::Styled {body, ..} => class_of(body),
        Node::Operator {..} => Class::Function,
        Node::Sized {body, ..} => class_of(body),
        Node::Delimiter {class, ..} => *class,
        Node::Extend {..} => Class::Relation,
        _ => Class::Ordinary,
    }
}


pub fn class_name(class: Class) -> &'static str {
    match class {
        Class::Variable => "variable",
        Class::Ordinary => "ordinary",
        Class::Binary => "binary",
        Class::Relation => "relation",
        Class::Open => "open",
        Class::Close => "close",
        Class::Punctuation => "punctuation",
        Class::Function => "function",
        Class::Large => "large",
        Class::Space(_) => "space",
    }
}