Skip to content

Commit 52f6d6f

Browse files
committed
fix: introducing evaluation errors
1 parent 28d1e0d commit 52f6d6f

File tree

93 files changed

+537
-404
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+537
-404
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "monkey_interpreter"
3-
version = "0.15.2"
3+
version = "0.15.3"
44
description = "Implementation of an interpreter for the Monkey language written in Rust, currently under active development."
55
authors = ["C <[email protected]>"]
66
edition = "2021"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Monkey Interpreter
2-
[![pipeline status](https://img.shields.io/badge/Version-0.15.2-blue)](https://gitlab.com/DeveloperC/monkey_interpreter/commits/master) [![pipeline status](https://gitlab.com/DeveloperC/monkey_interpreter/badges/master/pipeline.svg)](https://gitlab.com/DeveloperC/monkey_interpreter/commits/master) [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org) [![License: AGPL v3](https://img.shields.io/badge/License-AGPLv3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
2+
[![pipeline status](https://img.shields.io/badge/Version-0.15.3-blue)](https://gitlab.com/DeveloperC/monkey_interpreter/commits/master) [![pipeline status](https://gitlab.com/DeveloperC/monkey_interpreter/badges/master/pipeline.svg)](https://gitlab.com/DeveloperC/monkey_interpreter/commits/master) [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org) [![License: AGPL v3](https://img.shields.io/badge/License-AGPLv3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
33

44

55
![The Monkey Programming Language Logo](https://cloud.githubusercontent.com/assets/1013641/22617482/9c60c27c-eb09-11e6-9dfa-b04c7fe498ea.png)

src/evaluator/expression/boolean/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
use crate::evaluator::model::evaluation_error::EvaluationError;
12
use crate::evaluator::model::object::Object;
23
use crate::evaluator::Evaluator;
34
use crate::lexical_analysis::model::token::Token;
45

56
impl Evaluator {
6-
pub(super) fn evaluate_boolean(&self, boolean_token: Token) -> Object {
7+
pub(super) fn evaluate_boolean(&self, boolean_token: Token) -> Result<Object, EvaluationError> {
78
match boolean_token {
8-
Token::True => Object::True,
9-
Token::False => Object::False,
10-
_ => panic!("Boolean token not a boolean token."),
9+
Token::True => Ok(Object::True),
10+
Token::False => Ok(Object::False),
11+
_ => Err(EvaluationError::NotBooleanToken),
1112
}
1213
}
1314
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
source: src/evaluator/expression/boolean/tests/mod.rs
3-
expression: "evaluator.evaluate(crate::syntax_analysis::SyntaxAnalysis::from(crate::lexical_analysis::LexicalAnalysis::from(code)))"
3+
expression: "evaluator.evaluate(crate::syntax_analysis::SyntaxAnalysis::from(crate::lexical_analysis::LexicalAnalysis::from(code).unwrap()).unwrap())"
44

55
---
6-
True
6+
Ok(
7+
True,
8+
)
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
source: src/evaluator/expression/boolean/tests/mod.rs
3-
expression: "evaluator.evaluate(crate::syntax_analysis::SyntaxAnalysis::from(crate::lexical_analysis::LexicalAnalysis::from(code)))"
3+
expression: "evaluator.evaluate(crate::syntax_analysis::SyntaxAnalysis::from(crate::lexical_analysis::LexicalAnalysis::from(code).unwrap()).unwrap())"
44

55
---
6-
False
6+
Ok(
7+
False,
8+
)

src/evaluator/expression/call/mod.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::evaluator::model::object::{ErrorType, Object};
1+
use crate::evaluator::model::evaluation_error::EvaluationError;
2+
use crate::evaluator::model::object::Object;
23
use crate::evaluator::Evaluator;
34
use crate::syntax_analysis::model::syntax_tree_node::Expression;
45

@@ -7,31 +8,23 @@ impl Evaluator {
78
&mut self,
89
function: Expression,
910
arguments: Vec<Expression>,
10-
) -> Object {
11-
match self.evaluate_expression(function) {
11+
) -> Result<Object, EvaluationError> {
12+
match self.evaluate_expression(function)? {
1213
Object::Function { parameters, block } => {
1314
self.environment.push();
1415

1516
for (argument, parameter_identifier) in arguments.into_iter().zip(parameters) {
16-
let argument_evaluation = self.evaluate_expression(argument);
17-
18-
if let Object::Error { error_type } = argument_evaluation.clone() {
19-
self.environment.pop();
20-
return Object::Error { error_type };
21-
}
17+
let argument_evaluation = self.evaluate_expression(argument)?;
2218

2319
self.environment
2420
.set(parameter_identifier, argument_evaluation);
2521
}
2622

27-
let block_call_evaluation = self.evaluate_block(block);
23+
let block_call_evaluation = self.evaluate_block(block)?;
2824
self.environment.pop();
29-
block_call_evaluation
25+
Ok(block_call_evaluation)
3026
}
31-
Object::Error { error_type } => Object::Error { error_type },
32-
_ => Object::Error {
33-
error_type: ErrorType::UncallableObject,
34-
},
27+
_ => Err(EvaluationError::UncallableObject),
3528
}
3629
}
3730
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
---
22
source: src/evaluator/expression/call/tests/mod.rs
3-
expression: "evaluator.evaluate(crate::syntax_analysis::SyntaxAnalysis::from(crate::lexical_analysis::LexicalAnalysis::from(code)))"
3+
expression: "evaluator.evaluate(crate::syntax_analysis::SyntaxAnalysis::from(crate::lexical_analysis::LexicalAnalysis::from(code).unwrap()).unwrap())"
44

55
---
6-
Integer {
7-
value: 5,
8-
}
6+
Ok(
7+
Integer {
8+
value: 5,
9+
},
10+
)
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
---
22
source: src/evaluator/expression/call/tests/mod.rs
3-
expression: "evaluator.evaluate(crate::syntax_analysis::SyntaxAnalysis::from(crate::lexical_analysis::LexicalAnalysis::from(code)))"
3+
expression: "evaluator.evaluate(crate::syntax_analysis::SyntaxAnalysis::from(crate::lexical_analysis::LexicalAnalysis::from(code).unwrap()).unwrap())"
44

55
---
6-
Integer {
7-
value: 5,
8-
}
6+
Ok(
7+
Integer {
8+
value: 5,
9+
},
10+
)
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
---
22
source: src/evaluator/expression/call/tests/mod.rs
3-
expression: "evaluator.evaluate(crate::syntax_analysis::SyntaxAnalysis::from(crate::lexical_analysis::LexicalAnalysis::from(code)))"
3+
expression: "evaluator.evaluate(crate::syntax_analysis::SyntaxAnalysis::from(crate::lexical_analysis::LexicalAnalysis::from(code).unwrap()).unwrap())"
44

55
---
6-
Integer {
7-
value: 10,
8-
}
6+
Ok(
7+
Integer {
8+
value: 10,
9+
},
10+
)

0 commit comments

Comments
 (0)