Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI #4

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading