From 33d4b28786bfddf0d86b6940b62bc058a859c6c1 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 7 Mar 2020 04:54:38 -0800 Subject: [PATCH] More work --- schala-lang/language/src/parser.rs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/schala-lang/language/src/parser.rs b/schala-lang/language/src/parser.rs index 9f5c73a..b02ab5e 100644 --- a/schala-lang/language/src/parser.rs +++ b/schala-lang/language/src/parser.rs @@ -17,7 +17,6 @@ use crate::builtin::Builtin; type ParseResult<'a, T> = IResult<&'a str, T, VerboseError<&'a str>>; - pub fn ws, F>(parser: F) -> impl Fn(I) -> IResult where I: nom::InputTakeAtPosition, @@ -27,7 +26,6 @@ where delimited(space0, parser, space0) } - fn single_alphabetic_character(text: &str) -> ParseResult { let p = verify(take(1usize), |s: &str| s.chars().nth(0).map(|c| c.is_alphabetic()).unwrap_or(false)); map(p, |s: &str| s.chars().nth(0).unwrap())(text) @@ -78,7 +76,6 @@ fn number_literal(text: &str) -> ParseResult { Ok((text, ExpressionKind::NatLiteral(n))) } - fn binary_literal(text: &str) -> ParseResult { let p = preceded(tag("0b"), cut(take_while1(|c: char| c == '0' || c == '1'))); let (rest, n): (&str, u64) = map_res( @@ -148,6 +145,7 @@ fn primary_expr(text: &str) -> ParseResult { literal, paren_expr, identifier_expr, + //if_expr, ))(text) } @@ -161,19 +159,32 @@ fn invocation_argument(text: &str) -> ParseResult { ))(text) } +/* +fn if_expr(text: &str) -> ParseResult { + let p = preceded(tag("if"), pair(discriminator, if_expr_body)); + map(p, |(discriminator, body)| { + + })(text) + + let expr = IfExpression { + discriminator: Option>, + body: Box, + }; +} +*/ + fn call_expr(text: &str) -> ParseResult { use nom::character::complete::char; - let (text, expr) = primary_expr(text)?; - let (text, call_part) = opt( + let parse_call = opt( delimited(char('('), separated_list(char(','), invocation_argument), char(')')) - )(text)?; - let output = if let Some(arguments) = call_part { + ); + let p = pair(primary_expr, parse_call); + map(p, |(expr, call_part)| if let Some(arguments) = call_part { let f = bx!(Expression { id: ItemId::new(0), kind: expr, type_anno: None }); ExpressionKind::Call { f, arguments } } else { expr - }; - Ok((text, output)) + })(text) } fn prefix_expr(text: &str) -> ParseResult {