forked from Orchid/orchid
Final fixes
This commit is contained in:
@@ -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)
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ fn op_parser<'a, T: AsRef<str> + Clone>(ops: &[T]) -> BoxedParser<'a, char, Stri
|
|||||||
/// TODO: `.` could possibly be parsed as an operator depending on context. This operator is very
|
/// 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.
|
/// common in maths so it's worth a try. Investigate.
|
||||||
pub fn modname_parser<'a>() -> impl Parser<char, String, Error = Simple<char>> + 'a {
|
pub fn modname_parser<'a>() -> impl Parser<char, String, Error = Simple<char>> + 'a {
|
||||||
let not_name_char: Vec<char> = vec![':', '\\', '@', '"', '\'', '(', ')', ',', '.'];
|
let not_name_char: Vec<char> = vec![':', '\\', '@', '"', '\'', '(', ')', '[', ']', '{', '}', ',', '.'];
|
||||||
filter(move |c| !not_name_char.contains(c) && !c.is_whitespace())
|
filter(move |c| !not_name_char.contains(c) && !c.is_whitespace())
|
||||||
.repeated().at_least(1)
|
.repeated().at_least(1)
|
||||||
.collect()
|
.collect()
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ where F: FnMut(Mrc<[Expr]>) -> Option<Mrc<[Expr]>> {
|
|||||||
|
|
||||||
/// Fill in a template from a state as produced by a pattern
|
/// Fill in a template from a state as produced by a pattern
|
||||||
fn write_slice(state: &State, tpl: &Mrc<[Expr]>) -> Mrc<[Expr]> {
|
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 {
|
tpl.iter().flat_map(|Expr(clause, xpr_typ)| match clause {
|
||||||
Clause::Auto(name_opt, typ, body) => box_once(Expr(Clause::Auto(
|
Clause::Auto(name_opt, typ, body) => box_once(Expr(Clause::Auto(
|
||||||
name_opt.as_ref().and_then(|name| {
|
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);
|
slice_to_vec(&mut src, &mut tgt);
|
||||||
// Generate matcher
|
// Generate matcher
|
||||||
let matcher = SliceMatcherDnC::new(src);
|
let matcher = SliceMatcherDnC::new(src);
|
||||||
println!("Matcher: {matcher:#?}");
|
|
||||||
let matcher_cache = SliceMatcherDnC::get_matcher_cache();
|
let matcher_cache = SliceMatcherDnC::get_matcher_cache();
|
||||||
Ok(update_all_seqs(Mrc::clone(&input), &mut |p| {
|
Ok(update_all_seqs(Mrc::clone(&input), &mut |p| {
|
||||||
let state = matcher.match_range_cached(p, &matcher_cache)?;
|
let state = matcher.match_range_cached(p, &matcher_cache)?;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use mappable_rc::Mrc;
|
use mappable_rc::Mrc;
|
||||||
@@ -131,17 +130,6 @@ impl SliceMatcherDnC {
|
|||||||
None,
|
None,
|
||||||
Some(Box::new(Self::new(mrc_derive(&pattern, |p| &p[1..]))))
|
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 {
|
Self {
|
||||||
pattern, right_subm, left_subm,
|
pattern, right_subm, left_subm,
|
||||||
clause: Mrc::clone(&clause),
|
clause: Mrc::clone(&clause),
|
||||||
@@ -285,7 +273,6 @@ impl SliceMatcherDnC {
|
|||||||
target: Mrc<[Expr]>,
|
target: Mrc<[Expr]>,
|
||||||
cache: &Cache<CacheEntry<'a>, Option<State>>
|
cache: &Cache<CacheEntry<'a>, Option<State>>
|
||||||
) -> Option<State> {
|
) -> Option<State> {
|
||||||
eprintln!("Matching {target:?} with {:?}", self.pattern);
|
|
||||||
if self.pattern.is_empty() {
|
if self.pattern.is_empty() {
|
||||||
return if target.is_empty() {Some(State::new())} else {None}
|
return if target.is_empty() {Some(State::new())} else {None}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ impl State {
|
|||||||
}
|
}
|
||||||
pub fn insert_vec<S>(mut self, k: &S, v: &[Expr]) -> Option<Self>
|
pub fn insert_vec<S>(mut self, k: &S, v: &[Expr]) -> Option<Self>
|
||||||
where S: AsRef<str> + ToString + ?Sized + Debug {
|
where S: AsRef<str> + ToString + ?Sized + Debug {
|
||||||
eprintln!("{:?} + {k:?}-{v:?}", self.0);
|
|
||||||
if let Some(old) = self.0.get(k.as_ref()) {
|
if let Some(old) = self.0.get(k.as_ref()) {
|
||||||
if let Entry::Vec(val) = old {
|
if let Entry::Vec(val) = old {
|
||||||
if val.as_slice() != v {return None}
|
if val.as_slice() != v {return None}
|
||||||
@@ -138,3 +137,9 @@ impl IntoIterator for State {
|
|||||||
self.0.into_iter()
|
self.0.into_iter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Debug for State {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{:?}", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user