Skip to content

Commit

Permalink
removed debug prints.
Browse files Browse the repository at this point in the history
  • Loading branch information
Demonstrandum committed Dec 2, 2024
1 parent 176485a commit 81fe6ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
34 changes: 20 additions & 14 deletions crates/seam/src/parse/macros.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Expander macros argument parsing utilities.
use std::{borrow::Borrow, collections::HashMap, iter::zip};
use std::{collections::HashMap, iter::zip};
use std::fmt::Write as _;

use regex::Regex;

Expand All @@ -17,7 +18,15 @@ pub enum ArgPredicate {

impl ArgPredicate {
pub fn check_node<'tree>(&self, node: &Node<'tree>) -> Result<(), ExpansionError<'tree>> {
Ok(())
match self {
Self::Exactly(value) => if node.value == *value { Ok(()) } else {
Err(ExpansionError(
format!("value must be equal to `{}`.", value),
node.site.to_owned(),
))
}
_ => Ok(())
}
}
pub fn check<'tree>(&self, node: &ParseNode<'tree>) -> Result<(), ExpansionError<'tree>> {
Ok(())
Expand Down Expand Up @@ -54,9 +63,13 @@ fn check_all_node<'tree>(preds: &Vec<ArgPredicate>, node: &Node<'tree>) -> Resul
}
if issues.is_empty() { return Ok(()); }
// Amalgamate errors.
let mut error = String::from("This argument's value did not satisfy one of the follwining:\n");
for issue in issues {
error += &format!(" * {}", issue.0);
let mut error = String::new();
let _ = writeln!(error, "This argument's value did not satisfy one of the follwining:");
for (i, issue) in issues.iter().enumerate() {
let _ = write!(error, " * {}", issue.0);
if i != issues.len() - 1 {
let _ = write!(error, "\n");
}
}
Err(ExpansionError(error, node.site.clone()))
}
Expand Down Expand Up @@ -154,7 +167,7 @@ impl Arg {

/// Positonal or named argument position.
#[derive(Debug, Clone)]
enum ArgPos<'a> { Int(usize), Str(&'a str) }
pub enum ArgPos<'a> { Int(usize), Str(&'a str) }
/// What kind of types can be matched against
/// when determining an arguments positionality.
pub trait ArgMatcher {
Expand Down Expand Up @@ -261,7 +274,6 @@ impl<'params, 'rules, 'tree> ArgParser<'params, 'rules, 'tree> {
let mut named = HashMap::with_capacity(params.len());
let mut trailing = vec![];
let mut mandatory_count: usize = 0;
println!("going through params: {:?}", params);

for param in params {
let matcher: Box<dyn ArgMatcher + 'rules>;
Expand All @@ -278,10 +290,8 @@ impl<'params, 'rules, 'tree> ArgParser<'params, 'rules, 'tree> {
// Check if they do actually match with any of the rules.
let mut arg_rule = None;
for rule in &rules.patterns {
println!("calling matcher");
// First check that there is a valid place for this argument.
let is_valid_argument = (rule.pattern)(&matcher);
println!("checked pattern {:?} against {:?} and got {:?}", rule.pattern, matcher.unwrap(), is_valid_argument);
if is_valid_argument {
arg_rule = Some(rule);
break;
Expand All @@ -291,7 +301,6 @@ impl<'params, 'rules, 'tree> ArgParser<'params, 'rules, 'tree> {
// check if it can be given as trailing argument.
match arg_rule {
Some(rule) => {
println!("matched param against rule: {:?}", rule);
// Now check that the types are satisfied.
let argtype = rule.argument.argtype();
argtype.check(param_node)?;
Expand All @@ -302,10 +311,7 @@ impl<'params, 'rules, 'tree> ArgParser<'params, 'rules, 'tree> {
};
// Register if a mandatory argument was consumed.
match rule.argument {
Arg::Mandatory(..) => {
println!("found mand");
mandatory_count += 1
},
Arg::Mandatory(..) => mandatory_count += 1,
_ => {},
};
},
Expand Down
2 changes: 1 addition & 1 deletion crates/seam/src/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod tokens;
pub mod lexer;
pub mod parser;
#[macro_use]
mod macros;
pub mod macros;
pub mod expander;

pub use parser::ParseTree;
Expand Down

0 comments on commit 81fe6ac

Please sign in to comment.