Actually just three programming languages in a trenchcoat
at string-repr-callable 27 lines 841 B view raw
1use super::*; 2use crate::Parser; 3use trilogy_scanner::TokenType::*; 4 5#[derive(Clone, Debug, Spanned, PrettyPrintSExpr)] 6pub enum Handler { 7 When(Box<WhenHandler>), 8 Else(Box<ElseHandler>), 9} 10 11impl Handler { 12 pub(crate) fn parse(parser: &mut Parser) -> SyntaxResult<Self> { 13 match parser.peek().token_type { 14 KwWhen => Ok(Self::When(Box::new(WhenHandler::parse(parser)?))), 15 KwElse => Ok(Self::Else(Box::new(ElseHandler::parse(parser)?))), 16 _ => unreachable!("Caller should have checked the first token"), 17 } 18 } 19} 20 21#[cfg(test)] 22mod test { 23 use super::*; 24 25 test_parse!(handler_when: "when 'NAN resume 5" => Handler::parse => "(Handler::When (WhenHandler _ _ _ _))"); 26 test_parse!(handler_else: "else n resume 5" => Handler::parse => "(Handler::Else (ElseHandler _ _ _))"); 27}