dpscript/ir/ast/node/
mod.rs1mod arg;
2mod block;
3mod call;
4mod cmd;
5mod concat;
6mod condition;
7mod data;
8mod def;
9mod exec;
10mod func;
11mod literal;
12mod tag;
13
14use std::fmt;
15
16pub use arg::*;
17pub use block::*;
18pub use call::*;
19pub use cmd::*;
20pub use concat::*;
21pub use condition::*;
22pub use data::*;
23pub use def::*;
24pub use exec::*;
25pub use func::*;
26pub use literal::*;
27pub use tag::*;
28
29use serde::{Deserialize, Serialize};
30
31#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
33pub enum IRNode {
34 Definition(IRDefinition),
35 DataOperation(IRDataOperation),
36 Function(IRFunction),
37 Concat(IRConcat),
38 Literal(IRLiteral),
39 Argument(IRArgumentOperation),
40 Tag(IRTag),
41 Block(IRBlock),
42 Command(IRCommand),
43 Execute(IRExecute),
44 Call(IRCall),
45 Reference(String),
46 Condition(IRCondition),
47 Goto(String),
48
49 Group(Vec<IRNode>),
51
52 None,
55}
56
57macro_rules! node_from {
58 ($other: ident = $field: ident) => {
59 impl From<$other> for IRNode {
60 fn from(value: $other) -> Self {
61 Self::$field(value)
62 }
63 }
64 };
65}
66
67node_from!(IRDefinition = Definition);
68node_from!(IRDataOperation = DataOperation);
69node_from!(IRFunction = Function);
70node_from!(IRConcat = Concat);
71node_from!(IRLiteral = Literal);
72node_from!(IRArgumentOperation = Argument);
73node_from!(IRTag = Tag);
74node_from!(IRBlock = Block);
75node_from!(IRCommand = Command);
76node_from!(IRExecute = Execute);
77node_from!(IRCall = Call);
78node_from!(IRCondition = Condition);
79node_from!(String = Reference);
80
81impl fmt::Display for IRNode {
82 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
83 match self {
84 Self::Definition(_) => write!(f, "definition"),
85 Self::DataOperation(_) => write!(f, "data operation"),
86 Self::Function(_) => write!(f, "function"),
87 Self::Concat(_) => write!(f, "concatenation"),
88 Self::Literal(_) => write!(f, "literal"),
89 Self::Argument(_) => write!(f, "argument"),
90 Self::Tag(_) => write!(f, "tag"),
91 Self::Block(_) => write!(f, "block"),
92 Self::Command(_) => write!(f, "command"),
93 Self::Execute(_) => write!(f, "execution"),
94 Self::Call(_) => write!(f, "call"),
95 Self::Reference(_) => write!(f, "reference"),
96 Self::Condition(_) => write!(f, "condition"),
97 Self::Goto(_) => write!(f, "goto"),
98 Self::Group(_) => write!(f, "group"),
99 Self::None => write!(f, "none"),
100 }
101 }
102}