Skip to content

Commit 78d47b4

Browse files
committed
Add Macros to parser
1 parent faeabbc commit 78d47b4

File tree

4 files changed

+207
-123
lines changed

4 files changed

+207
-123
lines changed

src/ast/desugar.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ pub(crate) fn desugar_program(
88
program: Vec<Command>,
99
symbol_gen: &mut SymbolGen,
1010
seminaive_transform: bool,
11+
macros: &Macros,
1112
) -> Result<Vec<NCommand>, Error> {
1213
let mut res = vec![];
1314
for command in program {
14-
let desugared = desugar_command(command, symbol_gen, seminaive_transform)?;
15+
let desugared = desugar_command(command, symbol_gen, seminaive_transform, macros)?;
1516
res.extend(desugared);
1617
}
1718
Ok(res)
@@ -24,6 +25,7 @@ pub(crate) fn desugar_command(
2425
command: Command,
2526
symbol_gen: &mut SymbolGen,
2627
seminaive_transform: bool,
28+
macros: &Macros,
2729
) -> Result<Vec<NCommand>, Error> {
2830
let res = match command {
2931
Command::SetOption { name, value } => {
@@ -112,9 +114,10 @@ pub(crate) fn desugar_command(
112114
let s = std::fs::read_to_string(&file)
113115
.unwrap_or_else(|_| panic!("{span} Failed to read file {file}"));
114116
return desugar_program(
115-
parse_program(Some(file), &s)?,
117+
parse_program(Some(file), &s, macros)?,
116118
symbol_gen,
117119
seminaive_transform,
120+
macros,
118121
);
119122
}
120123
Command::Rule {
@@ -144,7 +147,7 @@ pub(crate) fn desugar_command(
144147
span,
145148
expr,
146149
schedule,
147-
} => desugar_simplify(&expr, &schedule, span, symbol_gen),
150+
} => desugar_simplify(&expr, &schedule, span, symbol_gen, macros),
148151
Command::RunSchedule(sched) => {
149152
vec![NCommand::RunSchedule(sched.clone())]
150153
}
@@ -218,7 +221,7 @@ pub(crate) fn desugar_command(
218221
vec![NCommand::Pop(span, num)]
219222
}
220223
Command::Fail(span, cmd) => {
221-
let mut desugared = desugar_command(*cmd, symbol_gen, seminaive_transform)?;
224+
let mut desugared = desugar_command(*cmd, symbol_gen, seminaive_transform, macros)?;
222225

223226
let last = desugared.pop().unwrap();
224227
desugared.push(NCommand::Fail(span, Box::new(last)));
@@ -323,6 +326,7 @@ fn desugar_simplify(
323326
schedule: &Schedule,
324327
span: Span,
325328
symbol_gen: &mut SymbolGen,
329+
macros: &Macros,
326330
) -> Vec<NCommand> {
327331
let mut res = vec![NCommand::Push(1)];
328332
let lhs = symbol_gen.fresh(&"desugar_simplify".into());
@@ -341,6 +345,7 @@ fn desugar_simplify(
341345
},
342346
symbol_gen,
343347
false,
348+
macros,
344349
)
345350
.unwrap(),
346351
);

0 commit comments

Comments
 (0)