Parameterize block

This commit is contained in:
Greg Shuflin 2021-11-20 22:19:59 -08:00
parent e5b6f2bc2f
commit 8f3c982131

View File

@ -150,7 +150,8 @@ pub fn program(input: Span) -> ParseResult<AST> {
Ok((rest, ast))
}
fn block_template<'a, O>(
fn block_template<'a, O, O2>(
delimiter: impl Parser<Span<'a>, O2, VerboseError<Span<'a>>>,
input_parser: impl Parser<Span<'a>, O, VerboseError<Span<'a>>>,
) -> impl FnMut(Span<'a>) -> IResult<Span<'a>, Vec<O>, VerboseError<Span<'a>>> {
delimited(
@ -161,7 +162,7 @@ fn block_template<'a, O>(
}
pub fn block(input: Span) -> ParseResult<Block> {
map(block_template(statement), |items| items.into())(input)
map(block_template(many1(statement_delimiter), statement), |items| items.into())(input)
}
fn statement(input: Span) -> ParseResult<Statement> {
@ -245,7 +246,7 @@ fn implementation(input: Span) -> ParseResult<Declaration> {
}
fn decl_block(input: Span) -> ParseResult<Vec<Declaration>> {
block_template(func_decl)(input)
block_template(many1(statement_delimiter), func_decl)(input)
}
fn interface(input: Span) -> ParseResult<Declaration> {
@ -255,7 +256,7 @@ fn interface(input: Span) -> ParseResult<Declaration> {
}
fn signature_block(input: Span) -> ParseResult<Vec<Signature>> {
block_template(func_signature)(input)
block_template(many1(statement_delimiter), func_signature)(input)
}
fn annotation(input: Span) -> ParseResult<Declaration> {
@ -329,13 +330,14 @@ fn type_body(input: Span) -> ParseResult<TypeBody> {
))(input)
}
fn record_variant(input: Span) -> ParseResult<VariantKind> {
map(
delimited(tok(char('{')), separated_list1(tok(char(',')), record_variant_item), tok(char('}'))),
VariantKind::Record,
)(input)
}
fn variant_spec(input: Span) -> ParseResult<Variant> {
fn record_variant(input: Span) -> ParseResult<VariantKind> {
map(
delimited(tok(char('{')), separated_list1(tok(char(',')), record_variant_item), tok(char('}'))),
VariantKind::Record,
)(input)
}
fn tuple_variant(input: Span) -> ParseResult<VariantKind> {
map(
@ -623,7 +625,7 @@ fn if_expr(input: Span) -> ParseResult<ExpressionKind> {
}
fn cond_block(input: Span) -> ParseResult<IfExpressionBody> {
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<ConditionArm> {