Actually just three programming languages in a trenchcoat
at main 32 lines 751 B view raw
1use super::*; 2use crate::{Parser, Spanned}; 3use source_span::Span; 4use trilogy_scanner::{Token, TokenType}; 5 6#[derive(Clone, Debug)] 7pub struct WhileStatement { 8 pub r#while: Token, 9 pub condition: Expression, 10 pub body: Block, 11 pub span: Span, 12} 13 14impl Spanned for WhileStatement { 15 fn span(&self) -> Span { 16 self.span 17 } 18} 19 20impl WhileStatement { 21 pub(crate) fn parse(parser: &mut Parser) -> SyntaxResult<Self> { 22 let r#while = parser.expect(TokenType::KwWhile).unwrap(); 23 let condition = Expression::parse(parser)?; 24 let body = Block::parse(parser)?; 25 Ok(Self { 26 span: r#while.span.union(body.span()), 27 r#while, 28 condition, 29 body, 30 }) 31 } 32}