diff options
Diffstat (limited to 'src/parse')
| -rw-r--r-- | src/parse/ast/expression.rs | 4 | ||||
| -rw-r--r-- | src/parse/ast/statement.rs | 2 | ||||
| -rw-r--r-- | src/parse/parser.rs | 18 |
3 files changed, 13 insertions, 11 deletions
diff --git a/src/parse/ast/expression.rs b/src/parse/ast/expression.rs index e883aaa..e67150a 100644 --- a/src/parse/ast/expression.rs +++ b/src/parse/ast/expression.rs @@ -52,7 +52,7 @@ impl Display for Expression { impl Expression { pub(crate) fn nested_fmt(&self, f: &mut Formatter<'_>, depth: usize) -> fmt::Result { let pad = " ".repeat(depth); - match self.kind { + match &self.kind { ExpressionKind::Binary { left, op, right } => { writeln!(f, "{}Binary:", pad)?; writeln!(f, "{}- Left:", pad)?; @@ -100,7 +100,7 @@ impl Expression { writeln!(f, "{}Str:", pad)?; for (i, statement) in expr.parts.iter().enumerate() { writeln!(f, "{}- {}:", pad, i)?; - match statement.kind { + match &statement.kind { StrPartKind::Literal(literal) => { writeln!(f, "{}{}", " ".repeat(depth + 1), literal.clone()) } diff --git a/src/parse/ast/statement.rs b/src/parse/ast/statement.rs index 7eb9978..7ed91dc 100644 --- a/src/parse/ast/statement.rs +++ b/src/parse/ast/statement.rs @@ -32,7 +32,7 @@ impl Statement { depth: usize, ) -> std::fmt::Result { let pad = " ".repeat(depth); - match self.kind { + match &self.kind { StatementKind::Expression(expression) => expression.nested_fmt(f, depth)?, StatementKind::Print(expression) => { writeln!(f, "{}Print:", pad)?; 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); |
