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
#[cfg(test)]
#[path = "./instruction_test.rs"]
mod instruction_test;
pub trait InstructionOperations {
fn is_actionable(&self) -> bool;
}
#[derive(Debug, Clone, Default)]
pub struct PreProcessInstruction {
pub command: Option<String>,
pub arguments: Option<Vec<String>>,
}
impl PreProcessInstruction {
pub fn new() -> PreProcessInstruction {
Default::default()
}
}
impl InstructionOperations for PreProcessInstruction {
fn is_actionable(&self) -> bool {
return self.command.is_some();
}
}
#[derive(Debug, Clone, Default)]
pub struct ScriptInstruction {
pub label: Option<String>,
pub output: Option<String>,
pub command: Option<String>,
pub arguments: Option<Vec<String>>,
}
impl ScriptInstruction {
pub fn new() -> ScriptInstruction {
Default::default()
}
}
impl InstructionOperations for ScriptInstruction {
fn is_actionable(&self) -> bool {
return self.command.is_some();
}
}
#[derive(Debug, Clone)]
pub enum InstructionType {
Empty,
PreProcess(PreProcessInstruction),
Script(ScriptInstruction),
}
#[derive(Debug, Clone, Default)]
pub struct InstructionMetaInfo {
pub line: Option<usize>,
pub source: Option<String>,
}
impl InstructionMetaInfo {
pub fn new() -> InstructionMetaInfo {
Default::default()
}
}
#[derive(Debug, Clone)]
pub struct Instruction {
pub meta_info: InstructionMetaInfo,
pub instruction_type: InstructionType,
}
impl InstructionOperations for Instruction {
fn is_actionable(&self) -> bool {
match self.instruction_type {
InstructionType::Empty => false,
InstructionType::PreProcess(ref value) => value.is_actionable(),
InstructionType::Script(ref value) => value.is_actionable(),
}
}
}