//! Corresponds to `ast::basic`. use chumsky::prelude::*; use chumsky::text::Character; use crate::ast::{Ident, Line, Space}; use crate::span::Span; pub type Error = Simple; // TODO https://github.com/rust-lang/rust/issues/63063 pub fn inline() -> impl Parser { filter(|c: &char| c.is_whitespace() && *c != '\n') .repeated() .to(()) } pub fn newline() -> impl Parser { just('\n').to(()) } pub fn line() -> impl Parser { let empty = newline().to(Line::Empty); let comment = just('#') .ignore_then(take_until(newline())) .map(|(s, _)| s) .collect::() .map(Line::Comment); empty.or(comment) } pub fn space() -> impl Parser { inline() .ignore_then(line()) .repeated() .then_ignore(inline()) .map_with_span(|lines, span| Space { lines, span }) } pub fn ident() -> impl Parser { // TODO Forbid keywords text::ident().map_with_span(|name, span| Ident { name, span }) }