extern crate bumpalo; extern crate roc; use self::bumpalo::Bump; use roc::can; use roc::can::expr::Expr; use roc::can::problem::Problem; use roc::can::procedure::Procedure; use roc::can::symbol::Symbol; use roc::can::Output; use roc::collections::{ImMap, MutMap}; use roc::ident::Ident; use roc::parse; use roc::parse::ast::{self, Attempting}; use roc::parse::blankspace::space0_before; use roc::parse::parser::{attempt, loc, map, Fail, Parser, State}; use roc::region::{Located, Region}; pub fn parse_with<'a>(arena: &'a Bump, input: &'a str) -> Result, Fail> { let state = State::new(&input, Attempting::Module); let parser = attempt( Attempting::Expression, map(space0_before(loc(parse::expr(0)), 0), |loc_expr| { loc_expr.value }), ); let answer = parser.parse(&arena, state); answer.map(|(expr, _)| expr).map_err(|(fail, _)| fail) } #[allow(dead_code)] pub fn can_expr(expr_str: &str) -> (Expr, Output, Vec, MutMap) { can_expr_with( &Bump::new(), "blah", expr_str, &ImMap::default(), &ImMap::default(), ) } #[allow(dead_code)] pub fn can_expr_with( arena: &Bump, name: &str, expr_str: &str, declared_idents: &ImMap, declared_variants: &ImMap>>, ) -> (Expr, Output, Vec, MutMap) { let expr = parse_with(&arena, expr_str).unwrap_or_else(|_| { panic!( "can_expr_with() got a parse error when attempting to canonicalize:\n\n{:?}", expr_str ) }); let home = "Test".to_string(); let (loc_expr, output, problems, procedures) = can::canonicalize_declaration( home, name, &Located::new(0, 0, 0, 0, expr), declared_idents, declared_variants, ); (loc_expr.value, output, problems, procedures) } // pub fn mut_map_from_pairs(pairs: I) -> MutMap // where // I: IntoIterator, // K: Hash + Eq, // { // let mut answer = MutMap::default(); // for (key, value) in pairs { // answer.insert(key, value); // } // answer // }