diff --git a/src/error/syntax_error.rs b/src/error/syntax_error.rs index e6cac72..25c0c60 100644 --- a/src/error/syntax_error.rs +++ b/src/error/syntax_error.rs @@ -69,11 +69,11 @@ impl Display for SyntaxError { [( position.start_byte..position.end_byte, format!( - "Syntax error at ({}, {}) to ({}, {}).", + "Invalid syntax from ({}, {}) to ({}, {}).", position.start_row, position.start_column, - position.end_row, - position.end_column + position.end_column, + position.end_row ), (255, 100, 100), )], diff --git a/src/interpret.rs b/src/interpret.rs index 0e4775d..19a03a7 100644 --- a/src/interpret.rs +++ b/src/interpret.rs @@ -124,31 +124,7 @@ impl Interpreter { /// - generate an abstract tree from the source and syntax tree /// - check the abstract tree for type errors pub fn validate(&mut self, source: &str) -> Result { - fn check_for_error( - node: SyntaxNode, - source: &str, - cursor: &mut TreeCursor, - ) -> Result<(), Error> { - if node.is_error() { - Err(Error::Syntax(SyntaxError::InvalidSource { - source: source[node.byte_range()].to_string(), - position: SourcePosition::from(node.range()), - })) - } else { - for child in node.children(&mut cursor.clone()) { - check_for_error(child, source, cursor)?; - } - - Ok(()) - } - } - let syntax_tree = self.parse(source)?; - let root = syntax_tree.root_node(); - let mut cursor = syntax_tree.root_node().walk(); - - check_for_error(root, source, &mut cursor)?; - let abstract_tree = Root::from_syntax(syntax_tree.root_node(), source, &self.context)?; abstract_tree.validate(source, &self.context)?;