Parameterize block
This commit is contained in:
parent
e5b6f2bc2f
commit
8f3c982131
@ -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,7 +330,6 @@ fn type_body(input: Span) -> ParseResult<TypeBody> {
|
||||
))(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('}'))),
|
||||
@ -337,6 +337,8 @@ fn variant_spec(input: Span) -> ParseResult<Variant> {
|
||||
)(input)
|
||||
}
|
||||
|
||||
fn variant_spec(input: Span) -> ParseResult<Variant> {
|
||||
|
||||
fn tuple_variant(input: Span) -> ParseResult<VariantKind> {
|
||||
map(
|
||||
delimited(tok(char('(')), separated_list1(tok(char(',')), type_identifier), tok(char(')'))),
|
||||
@ -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> {
|
||||
|
Loading…
Reference in New Issue
Block a user