Skip to content

Commit

Permalink
recover syntax write-read roundtrip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpaulino committed Aug 9, 2023
1 parent dfccd02 commit 4f50440
Show file tree
Hide file tree
Showing 6 changed files with 708 additions and 509 deletions.
10 changes: 8 additions & 2 deletions src/eval/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2347,11 +2347,17 @@ fn test_sym_hash_values() {
let s = &mut Store::<Fr>::default();
let state = State::init_lurk_state().mutable();

let asdf_sym_package_name = state.borrow_mut().intern_path(&["asdf"], false).unwrap();
let asdf_sym_package_name = state
.borrow_mut()
.intern_path(&["asdf"], false, false)
.unwrap();
let asdf_sym_package = Package::new(asdf_sym_package_name.into());
state.borrow_mut().add_package(asdf_sym_package);

let asdf_key_package_name = state.borrow_mut().intern_path(&["asdf"], true).unwrap();
let asdf_key_package_name = state
.borrow_mut()
.intern_path(&["asdf"], true, false)
.unwrap();
let asdf_key_package = Package::new(asdf_key_package_name.into());
state.borrow_mut().add_package(asdf_key_package);

Expand Down
59 changes: 26 additions & 33 deletions src/lem/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,39 +862,32 @@ mod tests {

fn expr_in_expr_out_pairs(s: &mut Store<Fr>) -> Vec<(Ptr<Fr>, Ptr<Fr>)> {
let state = State::init_lurk_state().mutable();
let sum = s.read(state.clone(), "(+ 21 21)").unwrap();
let sum_res = s.read(state.clone(), "42").unwrap();
let car = s.read(state.clone(), "(car (cons 1 2))").unwrap();
let car_res = s.read(state.clone(), "1").unwrap();
let let_ = s
.read(
state.clone(),
"(let ((x (cons 1 2)))
(cons (car x) (cdr x)))",
)
.unwrap();
let let_res = s.read(state.clone(), "(1 . 2)").unwrap();
let lam0 = s.read(state.clone(), "((lambda () 1))").unwrap();
let lam0_res = s.read(state.clone(), "1").unwrap();
let lam = s
.read(state.clone(), "((lambda (x y) (+ x y)) 3 4)")
.unwrap();
let lam_res = s.read(state.clone(), "7").unwrap();
let fold = s
.read(
state.clone(),
"(letrec ((build (lambda (x)
(if (eq x 0)
nil
(cons x (build (- x 1))))))
(sum (lambda (xs)
(if (eq xs nil)
0
(+ (car xs) (sum (cdr xs)))))))
(sum (build 10)))",
)
.unwrap();
let fold_res = s.read(state, "55").unwrap();
let mut read = |code: &str| s.read(state.clone(), code).unwrap();
let sum = read("(+ 21 21)");
let sum_res = read("42");
let car = read("(car (cons 1 2))");
let car_res = read("1");
let let_ = read(
"(let ((x (cons 1 2)))
(cons (car x) (cdr x)))",
);
let let_res = read("(1 . 2)");
let lam0 = read("((lambda () 1))");
let lam0_res = read("1");
let lam = read("((lambda (x y) (+ x y)) 3 4)");
let lam_res = read("7");
let fold = read(
"(letrec ((build (lambda (x)
(if (eq x 0)
nil
(cons x (build (- x 1))))))
(sum (lambda (xs)
(if (eq xs nil)
0
(+ (car xs) (sum (cdr xs)))))))
(sum (build 10)))",
);
let fold_res = read("55");
vec![
(sum, sum_res),
(car, car_res),
Expand Down
7 changes: 5 additions & 2 deletions src/lem/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,11 @@ impl<F: LurkField> Store<F> {
use crate::parser::*;
use nom::sequence::preceded;
use nom::Parser;
match preceded(syntax::parse_space, syntax::parse_syntax(state, false))
.parse(Span::new(input))
match preceded(
syntax::parse_space,
syntax::parse_syntax(state, false, false),
)
.parse(Span::new(input))
{
Ok((_i, x)) => self.intern_syntax(x),
Err(e) => bail!("{}", e),
Expand Down
16 changes: 11 additions & 5 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ pub enum Error {
impl<F: LurkField> Store<F> {
pub fn read(&mut self, input: &str) -> Result<Ptr<F>, Error> {
let state = State::init_lurk_state().mutable();
match preceded(syntax::parse_space, syntax::parse_syntax(state, false))
.parse(Span::new(input))
match preceded(
syntax::parse_space,
syntax::parse_syntax(state, false, false),
)
.parse(Span::new(input))
{
Ok((_i, x)) => Ok(self.intern_syntax(x)),
Err(e) => Err(Error::Syntax(format!("{}", e))),
Expand All @@ -50,8 +53,11 @@ impl<F: LurkField> Store<F> {
state: Rc<RefCell<State>>,
input: &str,
) -> Result<Ptr<F>, Error> {
match preceded(syntax::parse_space, syntax::parse_syntax(state, false))
.parse(Span::new(input))
match preceded(
syntax::parse_space,
syntax::parse_syntax(state, false, false),
)
.parse(Span::new(input))
{
Ok((_i, x)) => Ok(self.intern_syntax(x)),
Err(e) => Err(Error::Syntax(format!("{}", e))),
Expand All @@ -64,7 +70,7 @@ impl<F: LurkField> Store<F> {
input: Span<'a>,
) -> Result<(Span<'a>, Ptr<F>, bool), Error> {
use syntax::*;
match preceded(parse_space, parse_maybe_meta(state)).parse(input) {
match preceded(parse_space, parse_maybe_meta(state, false)).parse(input) {
Ok((i, Some((is_meta, x)))) => Ok((i, self.intern_syntax(x), is_meta)),
Ok((_, None)) => Err(Error::NoInput),
Err(e) => Err(Error::Syntax(format!("{}", e))),
Expand Down
Loading

0 comments on commit 4f50440

Please sign in to comment.