Actually just three programming languages in a trenchcoat
1use super::*;
2use crate::{Parser, Spanned};
3use source_span::Span;
4use trilogy_scanner::{Token, TokenType::*};
5
6#[derive(Clone, Debug)]
7pub struct Guard {
8 pub r#if: Token,
9 pub expression: Expression,
10 pub span: Span,
11}
12
13impl Spanned for Guard {
14 fn span(&self) -> Span {
15 self.span
16 }
17}
18
19impl Guard {
20 pub(crate) fn parse_optional(parser: &mut Parser) -> SyntaxResult<Option<Self>> {
21 let Ok(r#if) = parser.expect(KwIf) else {
22 return Ok(None);
23 };
24 let expression = Expression::parse(parser)?;
25 Ok(Some(Self {
26 span: r#if.span.union(expression.span()),
27 r#if,
28 expression,
29 }))
30 }
31}