diff --git a/src/gladvent/internal/runners.gleam b/src/gladvent/internal/runners.gleam index 782a336..56c58f9 100644 --- a/src/gladvent/internal/runners.gleam +++ b/src/gladvent/internal/runners.gleam @@ -102,7 +102,11 @@ pub fn runner_retrieval_error_to_snag(e: RunnerRetrievalErr) -> snag.Snag { "function '" <> f <> "' has parameter(s) " - <> string.inspect(g) + <> { + g + |> list.map(type_to_string) + |> string.join(", ") + } <> ", but should only have one parameter and it must be of type " <> e } @@ -126,7 +130,6 @@ pub fn get_day( use <- snagify_error(with: runner_retrieval_error_to_snag) let module_name = "aoc_" <> int.to_string(year) <> "/day_" <> int.to_string(day) - // let module_atom = atom.create_from_string(to_erlang_module_name(module_name)) // get the module for the specified year + day use module <- result.try( @@ -139,8 +142,8 @@ pub fn get_day( use runner_param_type <- result.try(case parse { Error(Nil) -> Ok(string) - Ok(package_interface.Function(parameters: [param], return: return, ..)) if param.type_ - == string -> Ok(return) + Ok(package_interface.Function(parameters: [param], return: return, ..)) if param.type_ == string -> + Ok(return) _ -> Error(ParseFunctionInvalid( "parse function must have 1 input parameter of type String", @@ -153,17 +156,16 @@ pub fn get_day( _, runner_param_type, ) - // get pt_1 + use pt_1 <- result.try(retrieve_runner("pt_1")) - // get pt_2 use pt_2 <- result.try(retrieve_runner("pt_2")) Ok(#( pt_1, pt_2, parse - |> result.replace(parse_function(module_name)) - |> option.from_result, + |> result.replace(parse_function(module_name)) + |> option.from_result, )) } @@ -185,7 +187,7 @@ fn retrieve_runner( }, return: Error(IncorrectInputParameters( function: function_name, - expected: string.inspect(runner_param_type), + expected: type_to_string(runner_param_type), got: list.map(pt_1.parameters, fn(p) { p.type_ }), )), ) @@ -219,3 +221,33 @@ const string = package_interface.Named( package: "", parameters: [], ) + +fn type_to_string(t: package_interface.Type) -> String { + let stringify_type_list = fn(elements) { + elements + |> list.map(type_to_string) + |> string.join(", ") + } + + case t { + package_interface.Tuple(elements: elements) -> + "#(" <> stringify_type_list(elements) <> ")" + package_interface.Fn(parameters: parameters, return: return) -> + "fn(" + <> stringify_type_list(elements) + <> ") -> " + <> type_to_string(return) + package_interface.Variable(id: id) -> int.to_string(id) + package_interface.Named( + name: name, + package: _, + module: module, + parameters: parameters, + ) -> + case parameters { + [] -> module <> "." <> name + _ -> + module <> "." <> name <> "(" <> stringify_type_list(elements) <> ")" + } + } +}