1#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2pub enum AstNodeType {
3 File,
4
5 StatementConst,
6 StatementConstName,
7
8 StatementEmit,
9
10 StatementFn,
11 StatementFnName,
12 StatementFnBody,
13
14 AtomUtf8,
15 AtomHex,
16 AtomConst,
17 AtomFn,
18 AtomFnParam,
19 AtomFnParamValue,
20 AtomFnParamIdentifier,
21 AtomFnParams,
22 AtomBaseNumber,
23 AtomBaseNumberBase,
24 AtomBaseNumberValue,
25
26 AtomFnName,
27}
28
29impl AstNodeType {
30
31 pub(super) fn must_capture_value(&self) -> bool {
32 matches!(
33 self,
34 AstNodeType::AtomUtf8
35 | AstNodeType::AtomHex
36 | AstNodeType::AtomFnName
37 | AstNodeType::StatementConstName
38 | AstNodeType::AtomBaseNumberBase
39 | AstNodeType::AtomBaseNumberValue
40 | AstNodeType::StatementFnName
41 | AstNodeType::AtomFnParamIdentifier
42 | AstNodeType::AtomConst
43 )
44 }
45}
46
47#[derive(Debug, Clone, Eq, PartialEq)]
48pub struct AstNode {
49 pub(crate) node_type: AstNodeType,
50 pub(crate) content: Option<String>,
51 pub(crate) children: Vec<AstNode>,
52}
53
54impl AstNode {
55
56 pub(super) fn new(
57 node_type: AstNodeType,
58 content: Option<String>,
59 children: Vec<AstNode>,
60 ) -> Self {
61 AstNode {
62 node_type,
63 content,
64 children,
65 }
66 }
67
68 pub fn children(&self) -> &Vec<AstNode> {
69 return &self.children
70 }
71
72 pub fn node_type(&self) -> AstNodeType {
73 return self.node_type
74 }
75
76 pub fn content(&self) -> Option<&String> {
77 return self.content.as_ref()
78 }
79}