Skip to content

Commit

Permalink
roll back some error handling code
Browse files Browse the repository at this point in the history
This needs more work. Current attempt causes infinite loop in parser
  • Loading branch information
oysandvik94 committed Aug 11, 2024
1 parent 69612f8 commit 56553a6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions crates/filerunner/tests/error_message_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub fn setup_logger() {
}

#[test]
#[ignore = "this still needs work"]
fn test_error_message() {
setup_logger();

Expand Down
38 changes: 25 additions & 13 deletions crates/interpreter/src/parser/lexer/lexedtokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl<'a> Lexer<'a> {
value.push(current_char);

while let Some(c) = self.chars.clone().next() {
if !c.is_alphabetic() || c == ',' {
if Self::not_valid_ident_char(c) {
break;
}
value.push(c);
Expand All @@ -229,6 +229,12 @@ impl<'a> Lexer<'a> {
TokenKind::parse_keyword(&value)
}

fn not_valid_ident_char(c: char) -> bool {
let is_allowed = c.is_alphabetic() || c == '_';

!is_allowed
}

pub fn next_token_has_infix(&mut self) -> bool {
let next_token = self.peek();
let has_infix = match next_token {
Expand All @@ -251,19 +257,25 @@ impl<'a> Lexer<'a> {
}
}

/// This is meant to keep parsing the program, even if we get an error,
/// so that the user can get multiple error reports for a single parse.
/// However, we need to figure out a good strategy to parse, since we dont use
/// statement seperators, and newlines dont matter
pub fn iterate_to_next_statement(&mut self) {
if self
.current_token
.as_ref()
.map_or(false, |token| token.token_kind.is_beginning_of_statement())
{
event!(
Level::TRACE,
"Current token {:?} is already valid beginning",
self.current_token
);
return;
}
// FIXME: This does not work if the parser fails on a token that
// is a valid statement-starter, as it will loop forever
// if self
// .current_token
// .as_ref()
// .map_or(false, |token| token.token_kind.is_beginning_of_statement())
// {
// event!(
// Level::TRACE,
// "Current token {:?} is already valid beginning",
// self.current_token
// );
// return;
// }

while let Some(token) = self.consume() {
event!(Level::TRACE, "Iterating to next statement: {:?}", token);
Expand Down

0 comments on commit 56553a6

Please sign in to comment.