diff options
| author | Mel <einebeere@gmail.com> | 2021-12-29 00:48:16 +0100 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2021-12-29 00:48:16 +0100 |
| commit | 842e76d57274ea6f8d5929e96f2919fd9cf0afb5 (patch) | |
| tree | 2aae20bdc9e7e60f02e3b89bc1db396eb43a3f61 /src/parse/parser.rs | |
| parent | e621f13a226d297d5368f4c294a8549a93843934 (diff) | |
| download | rabbithole-842e76d57274ea6f8d5929e96f2919fd9cf0afb5.tar.zst rabbithole-842e76d57274ea6f8d5929e96f2919fd9cf0afb5.zip | |
Runtime errors
Diffstat (limited to 'src/parse/parser.rs')
| -rw-r--r-- | src/parse/parser.rs | 18 |
1 files changed, 10 insertions, 8 deletions
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<T: Iterator<Item = Token>> Parser<T> { _ => unreachable!(), }; - left = Expression { at: left.at, kind }; + left = Expression { + at: token.location, + kind, + }; } Ok(left) @@ -311,6 +314,8 @@ impl<T: Iterator<Item = Token>> Parser<T> { fn unit_expression(&mut self) -> Result<Expression, RHError> { 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<T: Iterator<Item = Token>> Parser<T> { )), }?; - Ok(Expression { - at: token.location, - kind, - }) + Ok(Expression { at: location, kind }) } else { Err(parser_error( ErrorLocation::Eof, @@ -492,9 +494,9 @@ impl<T: Iterator<Item = Token>> Parser<T> { 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<T: Iterator<Item = Token>> Parser<T> { 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<T: Iterator<Item = Token>> Parser<T> { 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); |
