From ea62f15ac60a573f94299143e4390861d65ee38a Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Fri, 24 Sep 2021 15:41:45 +0200 Subject: [PATCH] no more errors --- ast/src/canonicalize/canonicalize.rs | 2 +- ast/src/lang/core/def/def_to_def2.rs | 21 ++++++++++++++++++++- ast/src/lang/core/expr/expr_to_expr2.rs | 14 ++++++++++++++ ast/src/mod.rs | 2 +- ast/src/pool/pool.rs | 4 ++-- 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/ast/src/canonicalize/canonicalize.rs b/ast/src/canonicalize/canonicalize.rs index c8bddb58fd..72d9e83846 100644 --- a/ast/src/canonicalize/canonicalize.rs +++ b/ast/src/canonicalize/canonicalize.rs @@ -20,7 +20,7 @@ enum FieldVar { OnlyVar(Variable), } -pub fn canonicalize_fields<'a>( +pub (crate) fn canonicalize_fields<'a>( env: &mut Env<'a>, scope: &mut Scope, fields: &'a [Located>>], diff --git a/ast/src/lang/core/def/def_to_def2.rs b/ast/src/lang/core/def/def_to_def2.rs index a30a65e3c6..b35b7e3890 100644 --- a/ast/src/lang/core/def/def_to_def2.rs +++ b/ast/src/lang/core/def/def_to_def2.rs @@ -1,6 +1,6 @@ use bumpalo::Bump; use bumpalo::collections::Vec as BumpVec; -use roc_parse::pattern::PatternType; +use roc_parse::{parser::SyntaxError, pattern::PatternType}; use roc_region::all::Region; use crate::lang::{core::{expr::expr_to_expr2::loc_expr_to_expr2, pattern::to_pattern2}, env::Env, scope::Scope}; @@ -72,4 +72,23 @@ pub fn to_def2_from_def<'a>( ) } } +} + +pub fn str_to_def2<'a>( + arena: &'a Bump, + input: &'a str, + env: &mut Env<'a>, + scope: &mut Scope, + region: Region, +) -> Result, SyntaxError<'a>> { + match roc_parse::test_helpers::parse_defs_with(arena, input.trim()) { + Ok(vec_loc_def) => Ok(defs_to_defs2( + arena, + env, + scope, + arena.alloc(vec_loc_def), + region, + )), + Err(fail) => Err(fail), + } } \ No newline at end of file diff --git a/ast/src/lang/core/expr/expr_to_expr2.rs b/ast/src/lang/core/expr/expr_to_expr2.rs index 9a5a67f9a6..4e277d590c 100644 --- a/ast/src/lang/core/expr/expr_to_expr2.rs +++ b/ast/src/lang/core/expr/expr_to_expr2.rs @@ -3,6 +3,7 @@ use roc_can::expr::Recursive; use roc_can::num::{finish_parsing_base, finish_parsing_float, finish_parsing_int}; use roc_can::operator::desugar_expr; use roc_collections::all::MutSet; +use roc_parse::parser::SyntaxError; use roc_parse::{ast::Expr, pattern::PatternType}; use roc_problem::can::{Problem, RuntimeError}; use roc_module::symbol::Symbol; @@ -18,6 +19,19 @@ use crate::{lang::{core::expr::expr2::{ExprId, FloatVal, IntStyle, IntVal}, env: use crate::canonicalize::canonicalize::{CanonicalizeRecordProblem, canonicalize_fields, canonicalize_lookup, canonicalize_when_branch}; use super::{expr2::Expr2, output::Output}; +pub fn str_to_expr2<'a>( + arena: &'a Bump, + input: &'a str, + env: &mut Env<'a>, + scope: &mut Scope, + region: Region, +) -> Result<(Expr2, self::Output), SyntaxError<'a>> { + match roc_parse::test_helpers::parse_loc_with(arena, input.trim()) { + Ok(loc_expr) => Ok(loc_expr_to_expr2(arena, loc_expr, env, scope, region)), + Err(fail) => Err(fail), + } +} + pub fn loc_expr_to_expr2<'a>( arena: &'a Bump, loc_expr: Located>, diff --git a/ast/src/mod.rs b/ast/src/mod.rs index addb2cebaf..7aed5d1c66 100644 --- a/ast/src/mod.rs +++ b/ast/src/mod.rs @@ -1,5 +1,5 @@ pub mod ast; -mod constrain; +pub mod constrain; pub mod lang; mod module; pub mod parse; diff --git a/ast/src/pool/pool.rs b/ast/src/pool/pool.rs index 8663ca4bcb..97ec3ca7af 100644 --- a/ast/src/pool/pool.rs +++ b/ast/src/pool/pool.rs @@ -60,9 +60,9 @@ pub const NODE_BYTES: usize = 32; // to see if it was #[derive(Debug, Eq)] -pub (crate) struct NodeId { +pub struct NodeId { pub (super) index: u32, - _phantom: PhantomData, + pub (super) _phantom: PhantomData, } impl Clone for NodeId {