diff --git a/examples/clue_solver.ds b/examples/clue_solver.ds index 256c500..e62c7da 100644 --- a/examples/clue_solver.ds +++ b/examples/clue_solver.ds @@ -1,22 +1,28 @@ -cards = { +type Cards { + rooms <[str]> + suspects <[str]> + weapons <[str]> +} + +cards = Cards { rooms = ['Library' 'Kitchen' 'Conservatory'] suspects = ['White' 'Green' 'Scarlett'] weapons = ['Rope' 'Lead_Pipe' 'Knife'] } -is_ready_to_solve = (cards ) { +is_ready_to_solve = (cards ) { (length(cards:suspects) == 1) && (length(cards:rooms) == 1) && (length(cards:weapons) == 1) } -remove_card = (cards , opponent_card ) { +remove_card = (cards , opponent_card ) { cards:rooms -= opponent_card cards:suspects -= opponent_card cards:weapons -= opponent_card } -make_guess = (cards , current_room ) { +make_guess = (cards , current_room ) { if is_ready_to_solve(cards) { output( 'I accuse ' @@ -40,7 +46,7 @@ make_guess = (cards , current_room ) { } } -take_turn = (cards , opponent_card , current_room ) { +take_turn = (cards , opponent_card , current_room ) { remove_card(cards opponent_card) make_guess(cards current_room) } diff --git a/src/abstract_tree/function_call.rs b/src/abstract_tree/function_call.rs index af41ea5..9b7aa14 100644 --- a/src/abstract_tree/function_call.rs +++ b/src/abstract_tree/function_call.rs @@ -52,8 +52,8 @@ impl AbstractTree for FunctionCall { { parameter_types } else { - return Err(Error::ExpectedFunctionType { - actual: function_expression_type, + return Err(Error::ExpectedFunctionExpression { + actual: self.function_expression.clone(), }); }; diff --git a/src/error.rs b/src/error.rs index 76fd770..eee5528 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,12 +1,10 @@ //! Error and Result types. //! -//! To deal with errors from dependencies, either create a new error variant -//! or use the ToolFailure variant if the error can only occur inside a tool. - +//! To deal with errors from dependencies, create a new Error variant. use serde::{Deserialize, Serialize}; use tree_sitter::{LanguageError, Node, Point}; -use crate::{value::Value, Type}; +use crate::{value::Value, FunctionExpression, Type}; use std::{ fmt::{self, Formatter}, @@ -83,8 +81,8 @@ pub enum Error { actual: usize, }, - ExpectedFunctionType { - actual: Type, + ExpectedFunctionExpression { + actual: FunctionExpression, }, ExpectedString { @@ -434,11 +432,13 @@ impl fmt::Display for Error { f, "Parsing was cancelled either manually or because it took too long." ), - ExpectedFunctionType { actual } => write!(f, "Expected a function but got {actual}."), + ExpectedFunctionExpression { actual } => { + write!(f, "Expected a function expression but got {actual:?}.") + } } } } fn get_position(position: &Point) -> String { - format!("column {}, row {}", position.row + 1, position.column) + format!("row {}, column {}", position.row + 1, position.column) }