Skip to content

Commit

Permalink
All parser errors have an implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-M-Lucas committed Aug 2, 2024
1 parent 06a5cf8 commit e8ac871
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 68 deletions.
31 changes: 13 additions & 18 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion main.why
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl Test {
fn main() -> int {
let x: Test = Test { a: 3 };

+;
::a;

return 8;
}
7 changes: 2 additions & 5 deletions src/root/errors/parser_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ pub fn create_custom_error_tree(e: String, l: Span) -> ErrorTree {
pub fn to_error_tree<'a>(e: nom::Err<ErrorTree<'a>>, s: Span<'a>) -> ErrorTree<'a> {
match e {
nom::Err::Incomplete(i) => {
create_custom_error_tree(
"Expected more characters".to_string(),
s
)
create_custom_error_tree("Expected more characters".to_string(), s)
}
nom::Err::Error(e) => e,
nom::Err::Failure(f) => f,
}
}
}
122 changes: 79 additions & 43 deletions src/root/parser/parse_function/parse_evaluable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,34 +357,50 @@ pub fn parse_evaluable<'a, 'b>(
match eval {
TempEvaluableTokensOne::StaticAccess(n) => {
let Some((token, t2_span)) = new_evaluables.pop() else {
todo!() // Must have previous
return Err(create_custom_error(
"Must have something to perform a static access on".to_string(),
t1_span
));
};

match token {
TempEvaluableTokensTwo::Operator(_)=> todo!(), // Can't be operator
TempEvaluableTokensTwo::EvaluableToken(e) => new_evaluables.push(
(TempEvaluableTokensTwo::EvaluableToken(EvaluableToken {
match token {
TempEvaluableTokensTwo::Operator(_) => return Err(create_custom_error(
"Cannot perform a static access on an operator".to_string(),
t2_span
)),
TempEvaluableTokensTwo::EvaluableToken(e) => new_evaluables.push((
TempEvaluableTokensTwo::EvaluableToken(EvaluableToken {
location: e.location.clone(),
token: EvaluableTokens::StaticAccess(b!(e), n),
}), t1_span))
}),
t1_span,
)),
}
}
TempEvaluableTokensOne::DynamicAccess(n) => {
let Some((token, t2_span)) = new_evaluables.pop() else {
todo!() // Must have previous
return Err(create_custom_error(
"Must have something to perform a dynamic access on".to_string(),
t1_span
));
};

match token {
TempEvaluableTokensTwo::Operator(_) => todo!(), // Can't be operator
TempEvaluableTokensTwo::EvaluableToken(e) => new_evaluables.push(
(TempEvaluableTokensTwo::EvaluableToken(EvaluableToken {
TempEvaluableTokensTwo::Operator(_) => return Err(create_custom_error(
"Cannot perform a dynamic access on an operator".to_string(),
t2_span
)),
TempEvaluableTokensTwo::EvaluableToken(e) => new_evaluables.push((
TempEvaluableTokensTwo::EvaluableToken(EvaluableToken {
location: e.location.clone(),
token: EvaluableTokens::DynamicAccess(b!(e), n),
}), t1_span))
}),
t1_span,
)),
}
}
TempEvaluableTokensOne::FunctionCall(n, c, a) => {
new_evaluables.push((TempEvaluableTokensTwo::EvaluableToken(EvaluableToken {
TempEvaluableTokensOne::FunctionCall(n, c, a) => new_evaluables.push((
TempEvaluableTokensTwo::EvaluableToken(EvaluableToken {
location: n.location().clone(),
token: EvaluableTokens::FunctionCall(
b!(EvaluableToken {
Expand All @@ -393,47 +409,66 @@ pub fn parse_evaluable<'a, 'b>(
}),
a,
),
}), t1_span))
}
}),
t1_span,
)),
TempEvaluableTokensOne::DynamicFunctionCall(n, a) => {
let Some((token, t2_span)) = new_evaluables.pop() else {
todo!() // Must have previous
return Err(create_custom_error(
"Must have something to perform a method call on".to_string(),
t1_span
));
};

match token {
TempEvaluableTokensTwo::Operator(_) => todo!(), // Can't be operator
TempEvaluableTokensTwo::Operator(_) => return Err(create_custom_error(
"Cannot perform a method on an operator".to_string(),
t2_span
)),
TempEvaluableTokensTwo::EvaluableToken(e) => new_evaluables.push(
(TempEvaluableTokensTwo::EvaluableToken(EvaluableToken {
location: e.location.clone(),
token: EvaluableTokens::FunctionCall(
b!(EvaluableToken {
location: n.location().clone(),
token: EvaluableTokens::DynamicAccess(b!(e), n)
}),
a,
),
}), t1_span) // TODO: Review if using t1 instead of t2 is correct
(
TempEvaluableTokensTwo::EvaluableToken(EvaluableToken {
location: e.location.clone(),
token: EvaluableTokens::FunctionCall(
b!(EvaluableToken {
location: n.location().clone(),
token: EvaluableTokens::DynamicAccess(b!(e), n)
}),
a,
),
}),
t1_span,
), // TODO: Review if using t1 instead of t2 is correct
),
}
}
TempEvaluableTokensOne::StaticFunctionCall(n, a) => {
let Some((token, t2_span)) = new_evaluables.pop() else {
todo!() // Must have previous
return Err(create_custom_error(
"Must have something to perform a static function call on".to_string(),
t1_span
));
};

match token {
TempEvaluableTokensTwo::Operator(_) => todo!(), // Can't be operator
TempEvaluableTokensTwo::Operator(_) => return Err(create_custom_error(
"Cannot perform a static function call on an operator".to_string(),
t2_span
)),
TempEvaluableTokensTwo::EvaluableToken(e) => new_evaluables.push(
(TempEvaluableTokensTwo::EvaluableToken(EvaluableToken {
location: e.location.clone(),
token: EvaluableTokens::FunctionCall(
b!(EvaluableToken {
location: n.location().clone(),
token: EvaluableTokens::StaticAccess(b!(e), n)
}),
a,
),
}), t1_span) // TODO: Review if using t1 instead of t2 is correct
(
TempEvaluableTokensTwo::EvaluableToken(EvaluableToken {
location: e.location.clone(),
token: EvaluableTokens::FunctionCall(
b!(EvaluableToken {
location: n.location().clone(),
token: EvaluableTokens::StaticAccess(b!(e), n)
}),
a,
),
}),
t1_span,
),
),
}
}
Expand Down Expand Up @@ -465,7 +500,7 @@ pub fn parse_evaluable<'a, 'b>(
if section.len() < 2 {
return Err(create_custom_error(
"Expected evaluable after prefix operator".to_string(),
*span
*span,
));
}

Expand Down Expand Up @@ -503,18 +538,19 @@ pub fn parse_evaluable<'a, 'b>(
(_, (TempEvaluableTokensTwo::EvaluableToken(e), span)) => {
return Err(create_custom_error(
"Expected infix operator between previous and this evaluable".to_string(),
*span
*span,
));
}
}
} else {
None
};

if enumerated_slice.is_empty() { // Trailing operator
if enumerated_slice.is_empty() {
// Trailing operator
return Err(create_custom_error(
"Trailing operator".to_string(),
operator.unwrap().1
operator.unwrap().1,
));
}

Expand Down
4 changes: 3 additions & 1 deletion src/root/parser/parse_function/parse_line.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::root::errors::parser_errors::{create_custom_error, create_custom_error_tree, to_error_tree};
use crate::root::errors::parser_errors::{
create_custom_error, create_custom_error_tree, to_error_tree,
};
use crate::root::parser::parse::{ErrorTree, ParseResult, Span};
use crate::root::parser::parse_function::parse_break::{test_parse_break, BreakToken};
use crate::root::parser::parse_function::parse_evaluable::{parse_evaluable, EvaluableToken};
Expand Down

0 comments on commit e8ac871

Please sign in to comment.