From 8f3c9821310b12075d0a7b3469e5d8124ef3857f Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sat, 20 Nov 2021 22:19:59 -0800 Subject: [PATCH] Parameterize block --- schala-lang/src/parsing/combinator.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/schala-lang/src/parsing/combinator.rs b/schala-lang/src/parsing/combinator.rs index 2d1b9c6..31e6719 100644 --- a/schala-lang/src/parsing/combinator.rs +++ b/schala-lang/src/parsing/combinator.rs @@ -150,7 +150,8 @@ pub fn program(input: Span) -> ParseResult { Ok((rest, ast)) } -fn block_template<'a, O>( +fn block_template<'a, O, O2>( + delimiter: impl Parser, O2, VerboseError>>, input_parser: impl Parser, O, VerboseError>>, ) -> impl FnMut(Span<'a>) -> IResult, Vec, VerboseError>> { delimited( @@ -161,7 +162,7 @@ fn block_template<'a, O>( } pub fn block(input: Span) -> ParseResult { - map(block_template(statement), |items| items.into())(input) + map(block_template(many1(statement_delimiter), statement), |items| items.into())(input) } fn statement(input: Span) -> ParseResult { @@ -245,7 +246,7 @@ fn implementation(input: Span) -> ParseResult { } fn decl_block(input: Span) -> ParseResult> { - block_template(func_decl)(input) + block_template(many1(statement_delimiter), func_decl)(input) } fn interface(input: Span) -> ParseResult { @@ -255,7 +256,7 @@ fn interface(input: Span) -> ParseResult { } fn signature_block(input: Span) -> ParseResult> { - block_template(func_signature)(input) + block_template(many1(statement_delimiter), func_signature)(input) } fn annotation(input: Span) -> ParseResult { @@ -329,13 +330,14 @@ fn type_body(input: Span) -> ParseResult { ))(input) } +fn record_variant(input: Span) -> ParseResult { + map( + delimited(tok(char('{')), separated_list1(tok(char(',')), record_variant_item), tok(char('}'))), + VariantKind::Record, + )(input) +} + fn variant_spec(input: Span) -> ParseResult { - fn record_variant(input: Span) -> ParseResult { - map( - delimited(tok(char('{')), separated_list1(tok(char(',')), record_variant_item), tok(char('}'))), - VariantKind::Record, - )(input) - } fn tuple_variant(input: Span) -> ParseResult { map( @@ -623,7 +625,7 @@ fn if_expr(input: Span) -> ParseResult { } fn cond_block(input: Span) -> ParseResult { - map(block_template(cond_arm), IfExpressionBody::CondList)(input) + map(block_template(many1(statement_delimiter), cond_arm), IfExpressionBody::CondList)(input) } fn cond_arm(input: Span) -> ParseResult {