-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
63 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use egglog::{ast::*, util::FreshGen}; | ||
|
||
pub struct For; | ||
|
||
impl Macro<Vec<Command>> for For { | ||
fn get_head(&self) -> String { | ||
"for".to_string() | ||
} | ||
|
||
fn parse( | ||
&self, | ||
args: &[Sexp], | ||
span: Span, | ||
parser: &mut Parser, | ||
) -> Result<Vec<Command>, ParseError> { | ||
if args.len() != 2 { | ||
return Err(ParseError::new(span, "expected (for <query> <action>)")); | ||
} | ||
|
||
let ruleset = parser.symbol_gen.fresh(&"for_ruleset".into()); | ||
let rulename = parser.symbol_gen.fresh(&"for_rule".into()); | ||
let query = args[0] | ||
.expect_list("query")? | ||
.iter() | ||
.map(|s| parser.parse_fact(s)) | ||
.collect::<Result<Vec<_>, _>>()?; | ||
let action = args[1] | ||
.expect_list("action")? | ||
.iter() | ||
.map(|s| parser.parse_action(s)) | ||
.collect::<Result<Vec<_>, _>>()? | ||
.into_iter() | ||
.flatten() | ||
.collect::<Vec<_>>(); | ||
let rule = Rule { | ||
span: span.clone(), | ||
head: Actions::new(action), | ||
body: query, | ||
}; | ||
|
||
Ok(vec![ | ||
Command::AddRuleset(ruleset), | ||
Command::Rule { | ||
name: rulename, | ||
ruleset, | ||
rule, | ||
}, | ||
Command::RunSchedule(Schedule::Run( | ||
span, | ||
RunConfig { | ||
ruleset, | ||
until: None, | ||
}, | ||
)), | ||
]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
mod r#for; | ||
pub use r#for::*; | ||
mod with_ruleset; | ||
pub use with_ruleset::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters