Skip to content

Commit

Permalink
reintroduce Results to the expression parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ulmer-a committed Aug 2, 2021
1 parent c9b45c5 commit 0075e0e
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 100 deletions.
14 changes: 12 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ fn parse_array_type_definition(
expect_token!(lexer, KeywordSquareParensOpen, None);
lexer.advance();

let range_statement = parse_primary_expression(lexer);
let range_statement = parse_expression(lexer);

expect_token!(lexer, KeywordSquareParensClose, None);
lexer.advance();
Expand Down Expand Up @@ -539,7 +539,17 @@ pub fn parse_any_in_region<T, F: FnOnce(&mut ParseSession) -> T>(
}

fn parse_expression(lexer: &mut ParseSession) -> Statement {
parse_primary_expression(lexer)
let start = lexer.range().start;
match parse_primary_expression(lexer) {
Ok(statement) => statement,
Err(diagnostic) => {
lexer.accept_diagnostic(diagnostic);
let end = lexer.range().end;
Statement::EmptyStatement {
location: SourceRange::new(start..end)
}
}
}
}

fn parse_reference(lexer: &mut ParseSession) -> Statement {
Expand Down
16 changes: 8 additions & 8 deletions src/parser/control_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
};

use super::ParseSession;
use super::{parse_primary_expression, parse_reference, parse_statement};
use super::{parse_expression, parse_reference, parse_statement};

pub fn parse_control_statement(lexer: &mut ParseSession) -> Statement {
match lexer.token {
Expand All @@ -27,7 +27,7 @@ fn parse_if_statement(lexer: &mut ParseSession) -> Statement {
let mut conditional_blocks = vec![];

while lexer.last_token == KeywordElseIf || lexer.last_token == KeywordIf {
let condition = parse_primary_expression(lexer);
let condition = parse_expression(lexer);
expect_token!(
lexer,
KeywordThen,
Expand Down Expand Up @@ -74,7 +74,7 @@ fn parse_for_statement(lexer: &mut ParseSession) -> Statement {
);
lexer.advance();

let start_expression = parse_primary_expression(lexer);
let start_expression = parse_expression(lexer);
expect_token!(
lexer,
KeywordTo,
Expand All @@ -83,11 +83,11 @@ fn parse_for_statement(lexer: &mut ParseSession) -> Statement {
}
);
lexer.advance();
let end_expression = parse_primary_expression(lexer);
let end_expression = parse_expression(lexer);

let step = if lexer.token == KeywordBy {
lexer.advance(); // BY
Some(Box::new(parse_primary_expression(lexer)))
Some(Box::new(parse_expression(lexer)))
} else {
None
};
Expand All @@ -108,7 +108,7 @@ fn parse_while_statement(lexer: &mut ParseSession) -> Statement {
let start = lexer.range().start;
lexer.advance(); //WHILE

let condition = parse_primary_expression(lexer);
let condition = parse_expression(lexer);
lexer.consume_or_report(KeywordDo);

Statement::WhileLoopStatement {
Expand All @@ -125,7 +125,7 @@ fn parse_repeat_statement(lexer: &mut ParseSession) -> Statement {
let body = parse_body_in_region(lexer, vec![KeywordUntil, KeywordEndRepeat]); //UNTIL
let condition = if lexer.last_token == KeywordUntil {
parse_any_in_region(lexer, vec![KeywordEndRepeat], |lexer| {
parse_primary_expression(lexer)
parse_expression(lexer)
})
} else {
Statement::EmptyStatement {
Expand All @@ -144,7 +144,7 @@ fn parse_case_statement(lexer: &mut ParseSession) -> Statement {
let start = lexer.range().start;
lexer.advance(); // CASE

let selector = Box::new(parse_primary_expression(lexer));
let selector = Box::new(parse_expression(lexer));

expect_token!(
lexer,
Expand Down
Loading

0 comments on commit 0075e0e

Please sign in to comment.