From d54aaff5de6111a5bc76672a00c7c25704e75bb2 Mon Sep 17 00:00:00 2001 From: rvcas Date: Thu, 1 Sep 2022 18:51:21 -0400 Subject: [PATCH] feat: fill in expr unit parser a bit --- crates/lang/src/parser.rs | 43 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/crates/lang/src/parser.rs b/crates/lang/src/parser.rs index 448ec3b2..f320ffc5 100644 --- a/crates/lang/src/parser.rs +++ b/crates/lang/src/parser.rs @@ -1,6 +1,11 @@ use chumsky::prelude::*; -use crate::{ast, error::ParseError, expr, token::Token}; +use crate::{ + ast::{self, TodoKind}, + error::ParseError, + expr, + token::Token, +}; pub fn module_parser( kind: ast::ModuleKind, @@ -256,7 +261,41 @@ pub fn expr_seq_parser() -> impl Parser impl Parser {} -pub fn expr_unit_parser() -> impl Parser {} +pub fn expr_unit_parser() -> impl Parser { + choice(( + select! {Token::String {value} => value}.map_with_span(|value, span| { + expr::UntypedExpr::String { + location: span, + value, + } + }), + select! { Token::Int {value} => value}.map_with_span(|value, span| { + expr::UntypedExpr::Int { + location: span, + value, + } + }), + select! { + Token::Name { name } => name, + Token::UpName { name } => name, + } + .map_with_span(|name, span| expr::UntypedExpr::Var { + location: span, + name, + }), + just(Token::Todo) + .ignore_then( + select! {Token::String {value} => value} + .delimited_by(just(Token::LeftParen), just(Token::RightParen)) + .or_not(), + ) + .map_with_span(|label, span| expr::UntypedExpr::Todo { + kind: TodoKind::Keyword, + location: span, + label, + }), + )) +} pub fn type_parser() -> impl Parser { recursive(|r| {