diff --git a/src/abstract_tree/assignment.rs b/src/abstract_tree/assignment.rs index d32e879..4dddfa1 100644 --- a/src/abstract_tree/assignment.rs +++ b/src/abstract_tree/assignment.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, AssignmentOperator, Error, Format, Identifier, Map, SourcePosition, Statement, + AbstractTree, AssignmentOperator, Format, Identifier, Map, SourcePosition, Statement, SyntaxNode, Type, TypeSpecification, Value, }; @@ -23,7 +23,7 @@ impl AbstractTree for Assignment { source: &str, context: &Map, ) -> Result { - Error::expect_syntax_node(source, "assignment", syntax_node)?; + SyntaxError::expect_syntax_node(source, "assignment", syntax_node)?; let child_count = syntax_node.child_count(); diff --git a/src/abstract_tree/assignment_operator.rs b/src/abstract_tree/assignment_operator.rs index 0fa4e30..8b996d0 100644 --- a/src/abstract_tree/assignment_operator.rs +++ b/src/abstract_tree/assignment_operator.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Error, Format, Map, SyntaxNode, Type, Value, + AbstractTree, Format, Map, SyntaxNode, Type, Value, }; /// Operators that be used in an assignment statement. @@ -19,7 +19,7 @@ impl AbstractTree for AssignmentOperator { source: &str, _context: &crate::Map, ) -> Result { - Error::expect_syntax_node(source, "assignment_operator", node)?; + SyntaxError::expect_syntax_node(source, "assignment_operator", node)?; let operator_node = node.child(0).unwrap(); let operator = match operator_node.kind() { diff --git a/src/abstract_tree/block.rs b/src/abstract_tree/block.rs index 1d19cc9..25c9ff5 100644 --- a/src/abstract_tree/block.rs +++ b/src/abstract_tree/block.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{rw_lock_error::RwLockError, RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Error, Format, Map, Statement, SyntaxNode, Type, Value, + AbstractTree, Format, Map, Statement, SyntaxNode, Type, Value, }; /// Abstract representation of a block. @@ -24,7 +24,7 @@ pub struct Block { impl AbstractTree for Block { fn from_syntax(node: SyntaxNode, source: &str, context: &Map) -> Result { - Error::expect_syntax_node(source, "block", node)?; + SyntaxError::expect_syntax_node(source, "block", node)?; let first_child = node.child(0).unwrap(); let is_async = first_child.kind() == "async"; diff --git a/src/abstract_tree/command.rs b/src/abstract_tree/command.rs index b172bb3..2adfd99 100644 --- a/src/abstract_tree/command.rs +++ b/src/abstract_tree/command.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Error, Format, Map, Type, Value, + AbstractTree, Format, Map, Type, Value, }; /// An external program invokation. @@ -20,7 +20,7 @@ impl AbstractTree for Command { source: &str, _context: &crate::Map, ) -> Result { - Error::expect_syntax_node(source, "command", node)?; + SyntaxError::expect_syntax_node(source, "command", node)?; let command_text_node = node.child(1).unwrap(); let command_text = source[command_text_node.byte_range()].to_string(); diff --git a/src/abstract_tree/expression.rs b/src/abstract_tree/expression.rs index 3571986..aaf43b5 100644 --- a/src/abstract_tree/expression.rs +++ b/src/abstract_tree/expression.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, value_node::ValueNode, - AbstractTree, Command, Error, Format, FunctionCall, Identifier, Index, Logic, Map, Math, New, + AbstractTree, Command, Format, FunctionCall, Identifier, Index, Logic, Map, Math, New, SyntaxNode, Type, Value, Yield, }; @@ -27,7 +27,7 @@ pub enum Expression { impl AbstractTree for Expression { fn from_syntax(node: SyntaxNode, source: &str, _context: &Map) -> Result { - Error::expect_syntax_node(source, "expression", node)?; + SyntaxError::expect_syntax_node(source, "expression", node)?; let child = if node.child(0).unwrap().is_named() { node.child(0).unwrap() diff --git a/src/abstract_tree/for.rs b/src/abstract_tree/for.rs index daad3d3..22c250d 100644 --- a/src/abstract_tree/for.rs +++ b/src/abstract_tree/for.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Block, Error, Expression, Format, Identifier, Map, SyntaxNode, Type, Value, + AbstractTree, Block, Expression, Format, Identifier, Map, SyntaxNode, Type, Value, }; /// Abstract representation of a for loop statement. @@ -17,7 +17,7 @@ pub struct For { impl AbstractTree for For { fn from_syntax(node: SyntaxNode, source: &str, context: &Map) -> Result { - Error::expect_syntax_node(source, "for", node)?; + SyntaxError::expect_syntax_node(source, "for", node)?; let for_node = node.child(0).unwrap(); let is_async = match for_node.kind() { diff --git a/src/abstract_tree/function_call.rs b/src/abstract_tree/function_call.rs index eb72510..5c5d9c4 100644 --- a/src/abstract_tree/function_call.rs +++ b/src/abstract_tree/function_call.rs @@ -2,8 +2,8 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Error, Expression, Format, FunctionExpression, Map, SourcePosition, SyntaxNode, - Type, Value, + AbstractTree, Expression, Format, FunctionExpression, Map, SourcePosition, SyntaxNode, Type, + Value, }; /// A function being invoked and the arguments it is being passed. @@ -31,7 +31,7 @@ impl FunctionCall { impl AbstractTree for FunctionCall { fn from_syntax(node: SyntaxNode, source: &str, context: &Map) -> Result { - Error::expect_syntax_node(source, "function_call", node)?; + SyntaxError::expect_syntax_node(source, "function_call", node)?; let function_node = node.child(0).unwrap(); let function_expression = FunctionExpression::from_syntax(function_node, source, context)?; diff --git a/src/abstract_tree/function_expression.rs b/src/abstract_tree/function_expression.rs index c957751..65a3e79 100644 --- a/src/abstract_tree/function_expression.rs +++ b/src/abstract_tree/function_expression.rs @@ -2,8 +2,8 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Error, Format, FunctionCall, Identifier, Index, Map, SyntaxNode, Type, Value, - ValueNode, Yield, + AbstractTree, Format, FunctionCall, Identifier, Index, Map, SyntaxNode, Type, Value, ValueNode, + Yield, }; #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] @@ -17,7 +17,7 @@ pub enum FunctionExpression { impl AbstractTree for FunctionExpression { fn from_syntax(node: SyntaxNode, source: &str, context: &Map) -> Result { - Error::expect_syntax_node(source, "function_expression", node)?; + SyntaxError::expect_syntax_node(source, "function_expression", node)?; let first_child = node.child(0).unwrap(); let child = if first_child.is_named() { diff --git a/src/abstract_tree/function_node.rs b/src/abstract_tree/function_node.rs index 66d8d92..a69a1ff 100644 --- a/src/abstract_tree/function_node.rs +++ b/src/abstract_tree/function_node.rs @@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Block, Error, Format, Function, Identifier, Map, SourcePosition, SyntaxNode, - Type, TypeSpecification, Value, + AbstractTree, Block, Format, Function, Identifier, Map, SourcePosition, SyntaxNode, Type, + TypeSpecification, Value, }; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] @@ -90,7 +90,7 @@ impl AbstractTree for FunctionNode { source: &str, outer_context: &Map, ) -> Result { - Error::expect_syntax_node(source, "function", node)?; + SyntaxError::expect_syntax_node(source, "function", node)?; let child_count = node.child_count(); let mut parameters = Vec::new(); diff --git a/src/abstract_tree/identifier.rs b/src/abstract_tree/identifier.rs index 229606e..9c1eb35 100644 --- a/src/abstract_tree/identifier.rs +++ b/src/abstract_tree/identifier.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Error, Format, Map, SyntaxNode, Type, Value, + AbstractTree, Format, Map, SyntaxNode, Type, Value, }; /// A string by which a variable is known to a context. @@ -30,7 +30,7 @@ impl Identifier { impl AbstractTree for Identifier { fn from_syntax(node: SyntaxNode, source: &str, _context: &Map) -> Result { - Error::expect_syntax_node(source, "identifier", node)?; + SyntaxError::expect_syntax_node(source, "identifier", node)?; let text = &source[node.byte_range()]; diff --git a/src/abstract_tree/index.rs b/src/abstract_tree/index.rs index cab03d2..8872338 100644 --- a/src/abstract_tree/index.rs +++ b/src/abstract_tree/index.rs @@ -2,8 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Error, Format, IndexExpression, List, Map, SourcePosition, SyntaxNode, Type, - Value, + AbstractTree, Format, IndexExpression, List, Map, SourcePosition, SyntaxNode, Type, Value, }; /// Abstract representation of an index expression. @@ -19,7 +18,7 @@ pub struct Index { impl AbstractTree for Index { fn from_syntax(node: SyntaxNode, source: &str, context: &Map) -> Result { - Error::expect_syntax_node(source, "index", node)?; + SyntaxError::expect_syntax_node(source, "index", node)?; let collection_node = node.child(0).unwrap(); let collection = IndexExpression::from_syntax(collection_node, source, context)?; diff --git a/src/abstract_tree/index_assignment.rs b/src/abstract_tree/index_assignment.rs index b538806..022d96b 100644 --- a/src/abstract_tree/index_assignment.rs +++ b/src/abstract_tree/index_assignment.rs @@ -2,8 +2,8 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, AssignmentOperator, Error, Format, Index, IndexExpression, Map, Statement, - SyntaxNode, Type, Value, + AbstractTree, AssignmentOperator, Format, Index, IndexExpression, Map, Statement, SyntaxNode, + Type, Value, }; #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] @@ -15,7 +15,7 @@ pub struct IndexAssignment { impl AbstractTree for IndexAssignment { fn from_syntax(node: SyntaxNode, source: &str, context: &Map) -> Result { - Error::expect_syntax_node(source, "index_assignment", node)?; + SyntaxError::expect_syntax_node(source, "index_assignment", node)?; let index_node = node.child(0).unwrap(); let index = Index::from_syntax(index_node, source, context)?; diff --git a/src/abstract_tree/index_expression.rs b/src/abstract_tree/index_expression.rs index 11630e0..8a9b775 100644 --- a/src/abstract_tree/index_expression.rs +++ b/src/abstract_tree/index_expression.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, value_node::ValueNode, - AbstractTree, Error, Format, FunctionCall, Identifier, Index, Map, SyntaxNode, Type, Value, + AbstractTree, Format, FunctionCall, Identifier, Index, Map, SyntaxNode, Type, Value, }; #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] @@ -16,7 +16,7 @@ pub enum IndexExpression { impl AbstractTree for IndexExpression { fn from_syntax(node: SyntaxNode, source: &str, context: &Map) -> Result { - Error::expect_syntax_node(source, "index_expression", node)?; + SyntaxError::expect_syntax_node(source, "index_expression", node)?; let first_child = node.child(0).unwrap(); let child = if first_child.is_named() { diff --git a/src/abstract_tree/logic.rs b/src/abstract_tree/logic.rs index e7bcbca..8ea9db5 100644 --- a/src/abstract_tree/logic.rs +++ b/src/abstract_tree/logic.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Error, Expression, Format, LogicOperator, Map, SyntaxNode, Type, Value, + AbstractTree, Expression, Format, LogicOperator, Map, SyntaxNode, Type, Value, }; /// Abstract representation of a logic expression. @@ -15,7 +15,7 @@ pub struct Logic { impl AbstractTree for Logic { fn from_syntax(node: SyntaxNode, source: &str, context: &Map) -> Result { - Error::expect_syntax_node(source, "logic", node)?; + SyntaxError::expect_syntax_node(source, "logic", node)?; let first_node = node.child(0).unwrap(); let (left_node, operator_node, right_node) = { diff --git a/src/abstract_tree/logic_operator.rs b/src/abstract_tree/logic_operator.rs index 58971e3..21c671e 100644 --- a/src/abstract_tree/logic_operator.rs +++ b/src/abstract_tree/logic_operator.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Error, Format, Map, SyntaxNode, Type, Value, + AbstractTree, Format, Map, SyntaxNode, Type, Value, }; #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] @@ -19,7 +19,7 @@ pub enum LogicOperator { impl AbstractTree for LogicOperator { fn from_syntax(node: SyntaxNode, source: &str, _context: &Map) -> Result { - Error::expect_syntax_node(source, "logic_operator", node)?; + SyntaxError::expect_syntax_node(source, "logic_operator", node)?; let operator_node = node.child(0).unwrap(); let operator = match operator_node.kind() { diff --git a/src/abstract_tree/match.rs b/src/abstract_tree/match.rs index 8c1d3e4..c6490dc 100644 --- a/src/abstract_tree/match.rs +++ b/src/abstract_tree/match.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Error, Expression, Format, Map, Statement, SyntaxNode, Type, Value, + AbstractTree, Expression, Format, Map, Statement, SyntaxNode, Type, Value, }; /// Abstract representation of a match statement. @@ -19,7 +19,7 @@ pub struct Match { impl AbstractTree for Match { fn from_syntax(node: SyntaxNode, source: &str, context: &Map) -> Result { - Error::expect_syntax_node(source, "match", node)?; + SyntaxError::expect_syntax_node(source, "match", node)?; let matcher_node = node.child(1).unwrap(); let matcher = Expression::from_syntax(matcher_node, source, context)?; diff --git a/src/abstract_tree/math.rs b/src/abstract_tree/math.rs index c7a80aa..3dc477e 100644 --- a/src/abstract_tree/math.rs +++ b/src/abstract_tree/math.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Error, Expression, Format, Map, MathOperator, SyntaxNode, Type, Value, + AbstractTree, Expression, Format, Map, MathOperator, SyntaxNode, Type, Value, }; /// Abstract representation of a math operation. @@ -18,7 +18,7 @@ pub struct Math { impl AbstractTree for Math { fn from_syntax(node: SyntaxNode, source: &str, context: &Map) -> Result { - Error::expect_syntax_node(source, "math", node)?; + SyntaxError::expect_syntax_node(source, "math", node)?; let left_node = node.child(0).unwrap(); let left = Expression::from_syntax(left_node, source, context)?; diff --git a/src/abstract_tree/mod.rs b/src/abstract_tree/mod.rs index 42cef9d..c53e314 100644 --- a/src/abstract_tree/mod.rs +++ b/src/abstract_tree/mod.rs @@ -46,7 +46,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - Error, Map, SyntaxNode, Value, + Map, SyntaxNode, Value, }; #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] @@ -82,7 +82,7 @@ pub struct Root { // top-level statements in the tree. impl AbstractTree for Root { fn from_syntax(node: SyntaxNode, source: &str, context: &Map) -> Result { - Error::expect_syntax_node(source, "root", node)?; + SyntaxError::expect_syntax_node(source, "root", node)?; let statement_count = node.child_count(); let mut statements = Vec::with_capacity(statement_count); diff --git a/src/abstract_tree/statement.rs b/src/abstract_tree/statement.rs index 8c326f9..b0612f9 100644 --- a/src/abstract_tree/statement.rs +++ b/src/abstract_tree/statement.rs @@ -2,8 +2,8 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Assignment, Block, Error, Expression, For, Format, IfElse, IndexAssignment, Map, - Match, SyntaxNode, Type, Value, While, + AbstractTree, Assignment, Block, Expression, For, Format, IfElse, IndexAssignment, Map, Match, + SyntaxNode, Type, Value, While, }; /// Abstract representation of a statement. @@ -22,7 +22,7 @@ pub enum Statement { impl AbstractTree for Statement { fn from_syntax(node: SyntaxNode, source: &str, context: &Map) -> Result { - Error::expect_syntax_node(source, "statement", node)?; + SyntaxError::expect_syntax_node(source, "statement", node)?; let child = node.child(0).unwrap(); diff --git a/src/abstract_tree/type.rs b/src/abstract_tree/type.rs index 3e5ca93..13b01e6 100644 --- a/src/abstract_tree/type.rs +++ b/src/abstract_tree/type.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Error, Format, Identifier, Map, Structure, SyntaxNode, Value, + AbstractTree, Format, Identifier, Map, Structure, SyntaxNode, Value, }; #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] @@ -127,7 +127,7 @@ impl Type { impl AbstractTree for Type { fn from_syntax(node: SyntaxNode, _source: &str, _context: &Map) -> Result { - Error::expect_syntax_node(_source, "type", node)?; + SyntaxError::expect_syntax_node(_source, "type", node)?; let type_node = node.child(0).unwrap(); diff --git a/src/abstract_tree/type_specification.rs b/src/abstract_tree/type_specification.rs index f5aa116..a158b84 100644 --- a/src/abstract_tree/type_specification.rs +++ b/src/abstract_tree/type_specification.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Error, Format, Map, SyntaxNode, Type, Value, + AbstractTree, Format, Map, SyntaxNode, Type, Value, }; #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] @@ -26,7 +26,7 @@ impl TypeSpecification { impl AbstractTree for TypeSpecification { fn from_syntax(node: SyntaxNode, source: &str, context: &Map) -> Result { - Error::expect_syntax_node(source, "type_specification", node)?; + SyntaxError::expect_syntax_node(source, "type_specification", node)?; let type_node = node.child(1).unwrap(); let r#type = Type::from_syntax(type_node, source, context)?; diff --git a/src/abstract_tree/value_node.rs b/src/abstract_tree/value_node.rs index e2fe159..0ed962f 100644 --- a/src/abstract_tree/value_node.rs +++ b/src/abstract_tree/value_node.rs @@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, BuiltInValue, Error, Expression, Format, Function, FunctionNode, Identifier, - List, Map, Statement, Structure, SyntaxNode, Type, TypeSpecification, Value, + AbstractTree, BuiltInValue, Expression, Format, Function, FunctionNode, Identifier, List, Map, + Statement, Structure, SyntaxNode, Type, TypeSpecification, Value, }; #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] @@ -25,7 +25,7 @@ pub enum ValueNode { impl AbstractTree for ValueNode { fn from_syntax(node: SyntaxNode, source: &str, context: &Map) -> Result { - Error::expect_syntax_node(source, "value", node)?; + SyntaxError::expect_syntax_node(source, "value", node)?; let child = node.child(0).unwrap(); let value_node = match child.kind() { diff --git a/src/abstract_tree/while.rs b/src/abstract_tree/while.rs index 22243f1..f373573 100644 --- a/src/abstract_tree/while.rs +++ b/src/abstract_tree/while.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, - AbstractTree, Block, Error, Expression, Format, Map, SyntaxNode, Type, Value, + AbstractTree, Block, Expression, Format, Map, SyntaxNode, Type, Value, }; /// Abstract representation of a while loop. @@ -16,7 +16,7 @@ pub struct While { impl AbstractTree for While { fn from_syntax(node: SyntaxNode, source: &str, context: &Map) -> Result { - Error::expect_syntax_node(source, "while", node)?; + SyntaxError::expect_syntax_node(source, "while", node)?; let expression_node = node.child(1).unwrap(); let expression = Expression::from_syntax(expression_node, source, context)?; diff --git a/src/abstract_tree/yield.rs b/src/abstract_tree/yield.rs index 9657196..a8e718b 100644 --- a/src/abstract_tree/yield.rs +++ b/src/abstract_tree/yield.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, function_expression::FunctionExpression, - AbstractTree, Error, Expression, Format, FunctionCall, Map, SyntaxNode, Type, Value, + AbstractTree, Expression, Format, FunctionCall, Map, SyntaxNode, Type, Value, }; /// Abstract representation of a yield expression. @@ -16,7 +16,7 @@ pub struct Yield { impl AbstractTree for Yield { fn from_syntax(node: SyntaxNode, source: &str, context: &Map) -> Result { - Error::expect_syntax_node(source, "yield", node)?; + SyntaxError::expect_syntax_node(source, "yield", node)?; let input_node = node.child(0).unwrap(); let input = Expression::from_syntax(input_node, source, context)?; diff --git a/src/error/mod.rs b/src/error/mod.rs index 369bacc..13fbcba 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -11,12 +11,11 @@ pub use runtime_error::RuntimeError; pub use syntax_error::SyntaxError; pub use validation_error::ValidationError; -use tree_sitter::{LanguageError, Node, Point}; - -use crate::{SourcePosition}; +use tree_sitter::{LanguageError, Point}; use std::fmt::{self, Formatter}; +#[derive(PartialEq)] pub enum Error { Syntax(SyntaxError), @@ -29,32 +28,6 @@ pub enum Error { Language(LanguageError), } -impl Error { - pub fn expect_syntax_node( - source: &str, - expected: &str, - actual: Node, - ) -> Result<(), SyntaxError> { - log::info!("Converting {} to abstract node", actual.kind()); - - if expected == actual.kind() { - Ok(()) - } else if actual.is_error() { - Err(SyntaxError::InvalidSource { - source: source[actual.byte_range()].to_string(), - position: SourcePosition::from(actual.range()), - }) - } else { - Err(SyntaxError::UnexpectedSyntaxNode { - expected: expected.to_string(), - actual: actual.kind().to_string(), - location: actual.start_position(), - relevant_source: source[actual.byte_range()].to_string(), - }) - } - } -} - impl From for Error { fn from(error: SyntaxError) -> Self { Error::Syntax(error) diff --git a/src/error/runtime_error.rs b/src/error/runtime_error.rs index 9e9e3cc..a813c0f 100644 --- a/src/error/runtime_error.rs +++ b/src/error/runtime_error.rs @@ -3,23 +3,24 @@ use std::{ io, num::ParseFloatError, string::FromUtf8Error, - time::{self, SystemTimeError}, + time, }; -use crate::{Value}; +use crate::Value; use super::rw_lock_error::RwLockError; +#[derive(PartialEq)] pub enum RuntimeError { - Csv(csv::Error), + Csv(String), - Io(io::Error), + Io(String), - Reqwest(reqwest::Error), + Reqwest(String), - Json(serde_json::Error), + Json(String), - SystemTime(SystemTimeError), + SystemTime(String), Toml(toml::de::Error), @@ -128,31 +129,31 @@ impl RuntimeError { impl From for RuntimeError { fn from(error: csv::Error) -> Self { - RuntimeError::Csv(error) + RuntimeError::Csv(error.to_string()) } } impl From for RuntimeError { fn from(error: std::io::Error) -> Self { - RuntimeError::Io(error) + RuntimeError::Io(error.to_string()) } } impl From for RuntimeError { fn from(error: reqwest::Error) -> Self { - RuntimeError::Reqwest(error) + RuntimeError::Reqwest(error.to_string()) } } impl From for RuntimeError { fn from(error: serde_json::Error) -> Self { - RuntimeError::Json(error) + RuntimeError::Json(error.to_string()) } } impl From for RuntimeError { fn from(error: time::SystemTimeError) -> Self { - RuntimeError::SystemTime(error) + RuntimeError::SystemTime(error.to_string()) } } diff --git a/src/error/syntax_error.rs b/src/error/syntax_error.rs index dfb35d6..a0a7df8 100644 --- a/src/error/syntax_error.rs +++ b/src/error/syntax_error.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use tree_sitter::Point; +use tree_sitter::{Node as SyntaxNode, Point}; use crate::SourcePosition; @@ -26,6 +26,32 @@ pub enum SyntaxError { }, } +impl SyntaxError { + pub fn expect_syntax_node( + source: &str, + expected: &str, + actual: SyntaxNode, + ) -> Result<(), SyntaxError> { + log::info!("Converting {} to abstract node", actual.kind()); + + if expected == actual.kind() { + Ok(()) + } else if actual.is_error() { + Err(SyntaxError::InvalidSource { + source: source[actual.byte_range()].to_string(), + position: SourcePosition::from(actual.range()), + }) + } else { + Err(SyntaxError::UnexpectedSyntaxNode { + expected: expected.to_string(), + actual: actual.kind().to_string(), + location: actual.start_position(), + relevant_source: source[actual.byte_range()].to_string(), + }) + } + } +} + impl From for SyntaxError { fn from(error: RwLockError) -> Self { SyntaxError::RwLock(error) diff --git a/tests/assignment.rs b/tests/assignment.rs index 1ff91a0..6df7f82 100644 --- a/tests/assignment.rs +++ b/tests/assignment.rs @@ -1,4 +1,4 @@ -use dust_lang::*; +use dust_lang::{error::ValidationError, *}; #[test] fn simple_assignment() { @@ -39,8 +39,19 @@ fn list_add_wrong_type() { ", ); - assert!(result.unwrap_err().is_error(&Error::TypeCheck { - expected: Type::String, - actual: Type::Integer - })) + assert_eq!( + Err(Error::Validation(ValidationError::TypeCheck { + expected: Type::String, + actual: Type::Integer, + position: SourcePosition { + start_byte: 0, + end_byte: 0, + start_row: 0, + start_column: 0, + end_row: 0, + end_column: 0 + } + })), + result + ); } diff --git a/tests/functions.rs b/tests/functions.rs index 25b8067..3734ae6 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -1,4 +1,4 @@ -use dust_lang::*; +use dust_lang::{error::ValidationError, *}; #[test] fn function_call() { @@ -48,14 +48,18 @@ fn built_in_function_call() { #[test] fn function_context_does_not_capture_normal_values() { - assert!(interpret( - " + assert_eq!( + interpret( + " x = 1 foo = () { x } " - ) - .is_err_and(|error| error.is_error(&Error::VariableIdentifierNotFound("x".to_string())))); + ), + Err(Error::Validation( + ValidationError::VariableIdentifierNotFound(Identifier::new("x".to_string())) + )) + ); assert_eq!( interpret( diff --git a/tests/types.rs b/tests/types.rs index 6afade9..3caed77 100644 --- a/tests/types.rs +++ b/tests/types.rs @@ -1,13 +1,24 @@ -use dust_lang::*; +use dust_lang::{error::ValidationError, *}; #[test] fn simple_type_check() { let result = interpret("x = 1"); - assert!(result.unwrap_err().is_error(&Error::TypeCheck { - expected: Type::Boolean, - actual: Type::Integer - })); + assert_eq!( + Err(Error::Validation(ValidationError::TypeCheck { + expected: Type::Boolean, + actual: Type::Integer, + position: SourcePosition { + start_byte: 0, + end_byte: 0, + start_row: 0, + start_column: 0, + end_row: 0, + end_column: 0, + } + })), + result + ); } #[test] @@ -37,14 +48,25 @@ fn callback_type_check() { ", ); - assert!(result.unwrap_err().is_error(&Error::TypeCheck { - expected: Type::Function { - parameter_types: vec![], - return_type: Box::new(Type::Boolean), - }, - actual: Type::Function { - parameter_types: vec![], - return_type: Box::new(Type::Integer), - }, - })); + assert_eq!( + Err(Error::Validation(ValidationError::TypeCheck { + expected: Type::Function { + parameter_types: vec![], + return_type: Box::new(Type::Boolean), + }, + actual: Type::Function { + parameter_types: vec![], + return_type: Box::new(Type::Integer), + }, + position: SourcePosition { + start_byte: 0, + end_byte: 0, + start_row: 0, + start_column: 0, + end_row: 0, + end_column: 0 + } + })), + result + ); } diff --git a/tests/value.rs b/tests/value.rs index beced42..f1bc814 100644 --- a/tests/value.rs +++ b/tests/value.rs @@ -99,12 +99,21 @@ fn map_types() { #[test] fn map_type_errors() { - assert!(interpret("{ foo = 'bar' }") - .unwrap_err() - .is_error(&Error::TypeCheck { + assert_eq!( + interpret("{ foo = 'bar' }"), + Err(Error::Validation(error::ValidationError::TypeCheck { expected: Type::Boolean, - actual: Type::String + actual: Type::String, + position: SourcePosition { + start_byte: 0, + end_byte: 0, + start_row: 0, + start_column: 0, + end_row: 0, + end_column: 0 + } })) + ); } #[test]