diff --git a/examples/rule_demo/main.orc b/examples/rule_demo/main.orc index b26a0ca..2c2acd5 100644 --- a/examples/rule_demo/main.orc +++ b/examples/rule_demo/main.orc @@ -1 +1,12 @@ -expor main := foo bar baz +export main := [foo, bar, baz, quz] + +[...$data] := (cons_start ...$data cons_carriage(none)) + +[] := none + +, $item cons_carriage($tail) := cons_carriage( + (some (cons $item $tail)) +) + +cons_start $item cons_carriage($tail) := some (cons $item $tail) + diff --git a/src/parse/name.rs b/src/parse/name.rs index 755d496..8d50790 100644 --- a/src/parse/name.rs +++ b/src/parse/name.rs @@ -29,7 +29,7 @@ fn op_parser<'a, T: AsRef + Clone>(ops: &[T]) -> BoxedParser<'a, char, Stri /// TODO: `.` could possibly be parsed as an operator depending on context. This operator is very /// common in maths so it's worth a try. Investigate. pub fn modname_parser<'a>() -> impl Parser> + 'a { - let not_name_char: Vec = vec![':', '\\', '@', '"', '\'', '(', ')', ',', '.']; + let not_name_char: Vec = vec![':', '\\', '@', '"', '\'', '(', ')', '[', ']', '{', '}', ',', '.']; filter(move |c| !not_name_char.contains(c) && !c.is_whitespace()) .repeated().at_least(1) .collect() diff --git a/src/rule/executor/execute.rs b/src/rule/executor/execute.rs index d82fb48..5ec399f 100644 --- a/src/rule/executor/execute.rs +++ b/src/rule/executor/execute.rs @@ -88,6 +88,7 @@ where F: FnMut(Mrc<[Expr]>) -> Option> { /// Fill in a template from a state as produced by a pattern fn write_slice(state: &State, tpl: &Mrc<[Expr]>) -> Mrc<[Expr]> { + eprintln!("Writing {tpl:?} with state {state:?}"); tpl.iter().flat_map(|Expr(clause, xpr_typ)| match clause { Clause::Auto(name_opt, typ, body) => box_once(Expr(Clause::Auto( name_opt.as_ref().and_then(|name| { @@ -142,7 +143,6 @@ pub fn execute(mut src: Mrc<[Expr]>, mut tgt: Mrc<[Expr]>, input: Mrc<[Expr]>) slice_to_vec(&mut src, &mut tgt); // Generate matcher let matcher = SliceMatcherDnC::new(src); - println!("Matcher: {matcher:#?}"); let matcher_cache = SliceMatcherDnC::get_matcher_cache(); Ok(update_all_seqs(Mrc::clone(&input), &mut |p| { let state = matcher.match_range_cached(p, &matcher_cache)?; diff --git a/src/rule/executor/slice_matcher.rs b/src/rule/executor/slice_matcher.rs index 8501d48..0d0bd34 100644 --- a/src/rule/executor/slice_matcher.rs +++ b/src/rule/executor/slice_matcher.rs @@ -1,4 +1,3 @@ - use std::fmt::Debug; use mappable_rc::Mrc; @@ -131,17 +130,6 @@ impl SliceMatcherDnC { None, Some(Box::new(Self::new(mrc_derive(&pattern, |p| &p[1..])))) )); - // let (Expr(clause, _), left_subm, right_subm) = if pattern.len() == 1 { - // (&pattern[0], None, None) - // } else if let Some((left, _, right)) = split_at_max_vec(pattern) {( - // &pattern[left.len()], - // Some(Box::new(Self::new(left))), - // Some(Box::new(Self::new(right))) - // )} else {( - // &pattern[0], - // None, - // Some(Box::new(Self::new(&pattern[1..]))) - // )}; Self { pattern, right_subm, left_subm, clause: Mrc::clone(&clause), @@ -285,7 +273,6 @@ impl SliceMatcherDnC { target: Mrc<[Expr]>, cache: &Cache, Option> ) -> Option { - eprintln!("Matching {target:?} with {:?}", self.pattern); if self.pattern.is_empty() { return if target.is_empty() {Some(State::new())} else {None} } diff --git a/src/rule/executor/state.rs b/src/rule/executor/state.rs index cadc2ad..7714566 100644 --- a/src/rule/executor/state.rs +++ b/src/rule/executor/state.rs @@ -35,7 +35,6 @@ impl State { } pub fn insert_vec(mut self, k: &S, v: &[Expr]) -> Option where S: AsRef + ToString + ?Sized + Debug { - eprintln!("{:?} + {k:?}-{v:?}", self.0); if let Some(old) = self.0.get(k.as_ref()) { if let Entry::Vec(val) = old { if val.as_slice() != v {return None} @@ -138,3 +137,9 @@ impl IntoIterator for State { self.0.into_iter() } } + +impl Debug for State { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.0) + } +}