Continue error overhaul
This commit is contained in:
parent
88ca9c5ea4
commit
9a465cb42d
@ -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<Self, SyntaxError> {
|
||||
Error::expect_syntax_node(source, "assignment", syntax_node)?;
|
||||
SyntaxError::expect_syntax_node(source, "assignment", syntax_node)?;
|
||||
|
||||
let child_count = syntax_node.child_count();
|
||||
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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() {
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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";
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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();
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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()
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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() {
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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)?;
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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() {
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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();
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
Error::expect_syntax_node(source, "identifier", node)?;
|
||||
SyntaxError::expect_syntax_node(source, "identifier", node)?;
|
||||
|
||||
let text = &source[node.byte_range()];
|
||||
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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)?;
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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)?;
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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() {
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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) = {
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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() {
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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)?;
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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)?;
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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);
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
Error::expect_syntax_node(source, "statement", node)?;
|
||||
SyntaxError::expect_syntax_node(source, "statement", node)?;
|
||||
|
||||
let child = node.child(0).unwrap();
|
||||
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
Error::expect_syntax_node(_source, "type", node)?;
|
||||
SyntaxError::expect_syntax_node(_source, "type", node)?;
|
||||
|
||||
let type_node = node.child(0).unwrap();
|
||||
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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)?;
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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() {
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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)?;
|
||||
|
@ -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<Self, SyntaxError> {
|
||||
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)?;
|
||||
|
@ -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<SyntaxError> for Error {
|
||||
fn from(error: SyntaxError) -> Self {
|
||||
Error::Syntax(error)
|
||||
|
@ -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<csv::Error> for RuntimeError {
|
||||
fn from(error: csv::Error) -> Self {
|
||||
RuntimeError::Csv(error)
|
||||
RuntimeError::Csv(error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for RuntimeError {
|
||||
fn from(error: std::io::Error) -> Self {
|
||||
RuntimeError::Io(error)
|
||||
RuntimeError::Io(error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<reqwest::Error> for RuntimeError {
|
||||
fn from(error: reqwest::Error) -> Self {
|
||||
RuntimeError::Reqwest(error)
|
||||
RuntimeError::Reqwest(error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for RuntimeError {
|
||||
fn from(error: serde_json::Error) -> Self {
|
||||
RuntimeError::Json(error)
|
||||
RuntimeError::Json(error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<time::SystemTimeError> for RuntimeError {
|
||||
fn from(error: time::SystemTimeError) -> Self {
|
||||
RuntimeError::SystemTime(error)
|
||||
RuntimeError::SystemTime(error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<RwLockError> for SyntaxError {
|
||||
fn from(error: RwLockError) -> Self {
|
||||
SyntaxError::RwLock(error)
|
||||
|
@ -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 {
|
||||
assert_eq!(
|
||||
Err(Error::Validation(ValidationError::TypeCheck {
|
||||
expected: Type::String,
|
||||
actual: Type::Integer
|
||||
}))
|
||||
actual: Type::Integer,
|
||||
position: SourcePosition {
|
||||
start_byte: 0,
|
||||
end_byte: 0,
|
||||
start_row: 0,
|
||||
start_column: 0,
|
||||
end_row: 0,
|
||||
end_column: 0
|
||||
}
|
||||
})),
|
||||
result
|
||||
);
|
||||
}
|
||||
|
@ -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 = () <any> { 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(
|
||||
|
@ -1,13 +1,24 @@
|
||||
use dust_lang::*;
|
||||
use dust_lang::{error::ValidationError, *};
|
||||
|
||||
#[test]
|
||||
fn simple_type_check() {
|
||||
let result = interpret("x <bool> = 1");
|
||||
|
||||
assert!(result.unwrap_err().is_error(&Error::TypeCheck {
|
||||
assert_eq!(
|
||||
Err(Error::Validation(ValidationError::TypeCheck {
|
||||
expected: Type::Boolean,
|
||||
actual: Type::Integer
|
||||
}));
|
||||
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,7 +48,8 @@ fn callback_type_check() {
|
||||
",
|
||||
);
|
||||
|
||||
assert!(result.unwrap_err().is_error(&Error::TypeCheck {
|
||||
assert_eq!(
|
||||
Err(Error::Validation(ValidationError::TypeCheck {
|
||||
expected: Type::Function {
|
||||
parameter_types: vec![],
|
||||
return_type: Box::new(Type::Boolean),
|
||||
@ -46,5 +58,15 @@ fn callback_type_check() {
|
||||
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
|
||||
);
|
||||
}
|
||||
|
@ -99,12 +99,21 @@ fn map_types() {
|
||||
|
||||
#[test]
|
||||
fn map_type_errors() {
|
||||
assert!(interpret("{ foo <bool> = 'bar' }")
|
||||
.unwrap_err()
|
||||
.is_error(&Error::TypeCheck {
|
||||
assert_eq!(
|
||||
interpret("{ foo <bool> = '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]
|
||||
|
Loading…
Reference in New Issue
Block a user