Preparation for sharing
- rustfmt - clippy - comments - README
This commit is contained in:
@@ -1,19 +1,29 @@
|
||||
use std::{rc::Rc, cell::RefCell};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use super::path_set::PathSet;
|
||||
use super::{interpreted, postmacro};
|
||||
use crate::utils::Side;
|
||||
|
||||
use super::{postmacro, interpreted, path_set::PathSet};
|
||||
|
||||
fn collect_paths_expr_rec(expr: &postmacro::Expr, depth: usize) -> Option<PathSet> {
|
||||
fn collect_paths_expr_rec(
|
||||
expr: &postmacro::Expr,
|
||||
depth: usize,
|
||||
) -> Option<PathSet> {
|
||||
collect_paths_cls_rec(&expr.value, depth)
|
||||
}
|
||||
|
||||
fn collect_paths_cls_rec(cls: &postmacro::Clause, depth: usize) -> Option<PathSet> {
|
||||
fn collect_paths_cls_rec(
|
||||
cls: &postmacro::Clause,
|
||||
depth: usize,
|
||||
) -> Option<PathSet> {
|
||||
match cls {
|
||||
postmacro::Clause::P(_) | postmacro::Clause::Constant(_) => None,
|
||||
postmacro::Clause::LambdaArg(h) => if *h != depth {None} else {
|
||||
Some(PathSet{ next: None, steps: Rc::new(vec![]) })
|
||||
}
|
||||
postmacro::Clause::LambdaArg(h) =>
|
||||
if *h != depth {
|
||||
None
|
||||
} else {
|
||||
Some(PathSet { next: None, steps: Rc::new(vec![]) })
|
||||
},
|
||||
postmacro::Clause::Lambda(b) => collect_paths_expr_rec(b, depth + 1),
|
||||
postmacro::Clause::Apply(f, x) => {
|
||||
let f_opt = collect_paths_expr_rec(f, depth);
|
||||
@@ -22,32 +32,29 @@ fn collect_paths_cls_rec(cls: &postmacro::Clause, depth: usize) -> Option<PathSe
|
||||
(Some(f_refs), Some(x_refs)) => Some(f_refs + x_refs),
|
||||
(Some(f_refs), None) => Some(f_refs + Side::Left),
|
||||
(None, Some(x_refs)) => Some(x_refs + Side::Right),
|
||||
(None, None) => None
|
||||
(None, None) => None,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clause(cls: &postmacro::Clause) -> interpreted::Clause {
|
||||
match cls {
|
||||
postmacro::Clause::Constant(name)
|
||||
=> interpreted::Clause::Constant(*name),
|
||||
postmacro::Clause::Constant(name) => interpreted::Clause::Constant(*name),
|
||||
postmacro::Clause::P(p) => interpreted::Clause::P(p.clone()),
|
||||
postmacro::Clause::Apply(f, x) => interpreted::Clause::Apply {
|
||||
f: expr(f.as_ref()),
|
||||
x: expr(x.as_ref()),
|
||||
},
|
||||
postmacro::Clause::Apply(f, x) =>
|
||||
interpreted::Clause::Apply { f: expr(f.as_ref()), x: expr(x.as_ref()) },
|
||||
postmacro::Clause::Lambda(body) => interpreted::Clause::Lambda {
|
||||
args: collect_paths_expr_rec(body, 0),
|
||||
body: expr(body)
|
||||
body: expr(body),
|
||||
},
|
||||
postmacro::Clause::LambdaArg(_) => interpreted::Clause::LambdaArg
|
||||
postmacro::Clause::LambdaArg(_) => interpreted::Clause::LambdaArg,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expr(expr: &postmacro::Expr) -> interpreted::ExprInst {
|
||||
interpreted::ExprInst(Rc::new(RefCell::new(interpreted::Expr{
|
||||
interpreted::ExprInst(Rc::new(RefCell::new(interpreted::Expr {
|
||||
location: expr.location.clone(),
|
||||
clause: clause(&expr.value),
|
||||
})))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user