From 842e76d57274ea6f8d5929e96f2919fd9cf0afb5 Mon Sep 17 00:00:00 2001 From: Mel Date: Wed, 29 Dec 2021 00:48:16 +0100 Subject: Runtime errors --- src/parse/parser.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/parse/parser.rs') diff --git a/src/parse/parser.rs b/src/parse/parser.rs index 4363bbb..19f26b1 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -303,7 +303,10 @@ impl> Parser { _ => unreachable!(), }; - left = Expression { at: left.at, kind }; + left = Expression { + at: token.location, + kind, + }; } Ok(left) @@ -311,6 +314,8 @@ impl> Parser { fn unit_expression(&mut self) -> Result { if let Some(token) = self.tokens.peek() { + let location = token.location; + let kind = match token.kind { Int(_) | Float(_) | Str(_) | KeywordTrue | KeywordFalse => { let literal = self.tokens.next().unwrap(); @@ -352,10 +357,7 @@ impl> Parser { )), }?; - Ok(Expression { - at: token.location, - kind, - }) + Ok(Expression { at: location, kind }) } else { Err(parser_error( ErrorLocation::Eof, @@ -492,9 +494,9 @@ impl> Parser { let if_block = self.generic_block()?; conditionals.push(ConditionalBlockNode { + at: if_condition.at, condition: if_condition, block: if_block, - at: if_condition.at, }); // Elifs @@ -503,9 +505,9 @@ impl> Parser { let elif_block = self.generic_block()?; conditionals.push(ConditionalBlockNode { + at: elif_condition.at, condition: elif_condition, block: elif_block, - at: elif_condition.at, }); } @@ -559,8 +561,8 @@ impl> Parser { let expression = self.expression()?; if consume_if!(self, SemiColon).is_some() { statements.push(Statement { - kind: StatementKind::Expression(expression), at: expression.at, + kind: StatementKind::Expression(expression), }); } else { tail_expression = Some(expression); -- cgit 1.4.1