1pub type Ident<'a> = &'a str;
3pub type Branch<'a> = Vec<(&'a str, &'a str)>;
5
6#[derive(Debug, PartialEq, Eq)]
10pub enum Rhs<'a> {
11 Unbound,
13 Literal { val: &'a str },
15 Variable { name: &'a str },
17 ShorthandVariable,
19 GraftedVariable { name: Ident<'a>, branch: Branch<'a> },
21 TaskOutput { task: &'a str, output: &'a str },
23 ShorthandTaskOutput { task: &'a str },
25 GraftedTaskOutput {
27 task: &'a str,
28 output: &'a str,
29 branch: Vec<(&'a str, &'a str)>,
30 },
31 ShorthandGraftedTaskOutput {
33 task: &'a str,
34 branch: Vec<(&'a str, &'a str)>,
35 },
36 Branchpoint {
38 branchpoint: &'a str,
39 vals: Vec<(&'a str, Self)>,
40 },
41 Interp { text: &'a str, vars: Vec<&'a str> },
43}
44
45#[cfg(test)]
47impl<'a> Rhs<'a> {
48 pub fn literal(val: &'a str) -> Self {
49 Self::Literal { val }
50 }
51 pub fn variable(name: &'a str) -> Self {
52 Self::Variable { name }
53 }
54 pub fn grafted_variable(name: &'a str, branch: Branch<'a>) -> Self {
58 Self::GraftedVariable { name, branch }
59 }
60 pub fn task_output(output: Ident<'a>, task: Ident<'a>) -> Self {
61 Self::TaskOutput { output, task }
62 }
63 pub fn shorthand_task_output(task: Ident<'a>) -> Self {
64 Self::ShorthandTaskOutput { task }
65 }
66 pub fn grafted_task_output(output: Ident<'a>, task: Ident<'a>, branch: Branch<'a>) -> Self {
67 Self::GraftedTaskOutput {
68 output,
69 task,
70 branch,
71 }
72 }
73 pub fn shorthand_grafted_task_output(task: Ident<'a>, branch: Branch<'a>) -> Self {
74 Self::ShorthandGraftedTaskOutput { task, branch }
75 }
76 pub fn branchpoint(branchpoint: Ident<'a>, vals: Vec<(Ident<'a>, Self)>) -> Self {
77 Self::Branchpoint { branchpoint, vals }
78 }
79}
80
81#[derive(Debug, PartialEq, Eq)]
84pub enum BlockSpec<'a> {
85 Output {
86 lhs: &'a str,
87 rhs: Rhs<'a>,
88 },
89 Input {
90 lhs: &'a str,
91 rhs: Rhs<'a>,
92 },
93 Param {
94 lhs: &'a str,
95 rhs: Rhs<'a>,
96 dot: bool,
97 },
98 Module {
99 name: Ident<'a>,
100 },
101}
102
103#[cfg(test)]
104impl<'a> BlockSpec<'a> {
105 pub fn output(lhs: Ident<'a>, rhs: Rhs<'a>) -> Self {
106 Self::Output { lhs, rhs }
107 }
108 pub fn input(lhs: Ident<'a>, rhs: Rhs<'a>) -> Self {
109 Self::Input { lhs, rhs }
110 }
111 pub fn param(lhs: Ident<'a>, rhs: Rhs<'a>) -> Self {
112 Self::Param {
113 lhs,
114 rhs,
115 dot: false,
116 }
117 }
118 pub fn dot_param(lhs: Ident<'a>, rhs: Rhs<'a>) -> Self {
119 Self::Param {
120 lhs,
121 rhs,
122 dot: true,
123 }
124 }
125}
126
127#[derive(Debug, Clone, Copy, PartialEq, Eq)]
132pub enum BlockType {
133 Task,
134}
135
136#[derive(Debug, PartialEq, Eq)]
138pub struct TasklikeBlock<'a> {
139 pub name: &'a str,
141 pub subtype: BlockType,
143 pub specs: Vec<BlockSpec<'a>>,
145 pub code: BashCode<'a>,
147}
148
149#[derive(Debug, PartialEq, Eq)]
151pub struct GrouplikeBlock<'a> {
152 pub name: &'a str,
154 pub subtype: BlockType,
156 pub specs: Vec<BlockSpec<'a>>,
158 pub blocks: Vec<TasklikeBlock<'a>>,
160}
161
162#[derive(Debug, PartialEq, Eq)]
164pub struct BashCode<'a> {
165 pub text: &'a str,
167 pub vars: crate::HashSet<Ident<'a>>,
169}
170
171#[derive(Debug, PartialEq, Eq)]
173pub enum Branches<'a> {
174 Glob,
176 Specified(Vec<&'a str>),
178}
179
180#[derive(Debug, PartialEq, Eq)]
182pub struct CrossProduct<'a> {
183 pub goals: Vec<Ident<'a>>,
185 pub branches: Vec<(Ident<'a>, Branches<'a>)>,
187}
188
189#[derive(Debug, PartialEq, Eq)]
191pub struct Plan<'a> {
192 pub name: &'a str,
194 pub cross_products: Vec<CrossProduct<'a>>,
196}
197
198#[derive(Debug, PartialEq, Eq)]
200pub enum Item<'a> {
201 Task(TasklikeBlock<'a>),
204 Import(&'a str),
206 GlobalConfig(Vec<(&'a str, Rhs<'a>)>),
209 Plan(Plan<'a>),
211 Module(Ident<'a>, Rhs<'a>),
213}