Skip to content

Commit

Permalink
Merge pull request #4 from egraphs-good/cli
Browse files Browse the repository at this point in the history
Add CLI
  • Loading branch information
Alex-Fischman authored Jan 16, 2025
2 parents 2a5085e + 2b2d0c3 commit 8a1b3d6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ harness = false
name = "files"

[dependencies]
egglog = { git = "https://github.com/egraphs-good/egglog.git", rev = "01a4a61" }
egglog = { git = "https://github.com/egraphs-good/egglog.git", rev = "56cc61f" }

num = "0.4.3"
lazy_static = "1.4"
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pub use egglog::*;
use std::sync::Arc;
use sugar::{For, WithRuleset};

mod rational;
pub use rational::*;
mod sugar;
pub use sugar::*;

pub fn new_experimental_egraph() -> EGraph {
let mut egraph = EGraph::default();
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
todo!();
egglog::cli(egglog_experimental::new_experimental_egraph())
}
9 changes: 6 additions & 3 deletions src/sugar/for.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use egglog::{ast::*, util::FreshGen};
pub struct For;

impl Macro<Vec<Command>> for For {
fn get_head(&self) -> String {
"for".to_string()
fn name(&self) -> Symbol {
"for".into()
}

fn parse(
Expand All @@ -14,7 +14,10 @@ impl Macro<Vec<Command>> for For {
parser: &mut Parser,
) -> Result<Vec<Command>, ParseError> {
if args.len() != 2 {
return Err(ParseError::new(span, "expected (for <query> <action>)"));
return Err(ParseError(
span,
"expected (for <query> <action>)".to_string(),
));
}

let ruleset = parser.symbol_gen.fresh(&"for_ruleset".into());
Expand Down
29 changes: 16 additions & 13 deletions src/sugar/with_ruleset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use egglog::ast::*;
pub struct WithRuleset;

impl Macro<Vec<Command>> for WithRuleset {
fn get_head(&self) -> String {
"with-ruleset".to_string()
fn name(&self) -> Symbol {
"with-ruleset".into()
}

fn parse(
Expand All @@ -31,33 +31,36 @@ impl Macro<Vec<Command>> for WithRuleset {
rule,
} => {
if rule_ruleset != "".into() {
return Err(ParseError::new(
return Err(ParseError(
rule.span,
"expected rules in `with-ruleset` to have empty ruleset",
"expected rules in `with-ruleset` to have empty ruleset"
.to_string(),
));
}

Command::Rule {
ruleset,
name,
rule: rule.clone(),
rule,
}
}
Command::Rewrite(rule_ruleset, rewrite, subsume) => {
if rule_ruleset != "".into() {
return Err(ParseError::new(
return Err(ParseError(
rewrite.span,
"expected rules in `with-ruleset` to have empty ruleset",
"expected rules in `with-ruleset` to have empty ruleset"
.to_string(),
));
}

Command::Rewrite(ruleset, rewrite, subsume)
}
Command::BiRewrite(rule_ruleset, rewrite) => {
if rule_ruleset != "".into() {
return Err(ParseError::new(
return Err(ParseError(
rewrite.span,
"expected rules in `with-ruleset` to have empty ruleset",
"expected rules in `with-ruleset` to have empty ruleset"
.to_string(),
));
}

Expand All @@ -66,18 +69,18 @@ impl Macro<Vec<Command>> for WithRuleset {
_ => {
// Ideally the span should be the current command's span (i.e. cmd.span()),
// but currently not all of our commands have a span field.
return Err(ParseError::new(
return Err(ParseError(
span.clone(),
"expected rule or rewrite",
"expected rule or rewrite".to_string(),
));
}
})
})
.collect()
}
_ => Err(ParseError::new(
_ => Err(ParseError(
span,
"expected (with-ruleset <ruleset> <command>*)",
"expected (with-ruleset <ruleset> <command>*)".to_string(),
)),
}
}
Expand Down

0 comments on commit 8a1b3d6

Please sign in to comment.