lehit 0.2.0

Embeddable Lehit language frontend and Cranelift JIT runtime
Documentation
use chumsky::prelude::*;

use crate::parsing::{Span, ast::Expression, lexer::Token};

#[derive(Debug, Clone)]
pub struct WhileExpression {
    pub span: Span,
    pub condition: Expression,
    pub expression: Expression,
}

pub(crate) fn while_expression_parser<'src, I, EP>(
    expression_parser: EP,
) -> impl Parser<'src, I, WhileExpression, extra::Err<Rich<'src, Token, Span>>> + Clone
where
    I: Input<'src, Token = Token, Span = Span>,
    EP: Parser<'src, I, Expression, extra::Err<Rich<'src, Token, Span>>> + Clone + 'src,
{
    just(Token::WhileKw)
        .ignore_then(expression_parser.clone())
        .then(expression_parser)
        .map_with(|(cond, expr), ex| WhileExpression {
            span: ex.span(),
            condition: cond,
            expression: expr,
        })
}