use crate::{ ast::expression::expression_node::ExpressionNode, ast::parser::{InnerASTParsingError, Parser, Result}, lexer::token::{self, TokenType}, }; use super::Statement; #[derive(Debug)] pub struct ExpressionStatement(pub ExpressionNode); impl ExpressionStatement { pub fn new(expr: ExpressionNode) -> Self { Self(expr) } } impl<'a, T: Iterator>> Parser<'a, T> { pub fn expression_statement(&mut self) -> Result { let expr = self.expression()?; let token = self.token_iter.peek(); if let TokenType::Semicolon = token.token_type { self.token_iter.next(); Ok(ExpressionStatement::new(expr).into()) } else { Err(token.location.wrap(InnerASTParsingError::ExpectedSemi)) } } }