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))
|
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>>>,
|
input_parser: impl Parser<Span<'a>, O, VerboseError<Span<'a>>>,
|
||||||
) -> impl FnMut(Span<'a>) -> IResult<Span<'a>, Vec<O>, VerboseError<Span<'a>>> {
|
) -> impl FnMut(Span<'a>) -> IResult<Span<'a>, Vec<O>, VerboseError<Span<'a>>> {
|
||||||
delimited(
|
delimited(
|
||||||
@ -161,7 +162,7 @@ fn block_template<'a, O>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn block(input: Span) -> ParseResult<Block> {
|
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> {
|
fn statement(input: Span) -> ParseResult<Statement> {
|
||||||
@ -245,7 +246,7 @@ fn implementation(input: Span) -> ParseResult<Declaration> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn decl_block(input: Span) -> ParseResult<Vec<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> {
|
fn interface(input: Span) -> ParseResult<Declaration> {
|
||||||
@ -255,7 +256,7 @@ fn interface(input: Span) -> ParseResult<Declaration> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn signature_block(input: Span) -> ParseResult<Vec<Signature>> {
|
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> {
|
fn annotation(input: Span) -> ParseResult<Declaration> {
|
||||||
@ -329,13 +330,14 @@ fn type_body(input: Span) -> ParseResult<TypeBody> {
|
|||||||
))(input)
|
))(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 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> {
|
fn tuple_variant(input: Span) -> ParseResult<VariantKind> {
|
||||||
map(
|
map(
|
||||||
@ -623,7 +625,7 @@ fn if_expr(input: Span) -> ParseResult<ExpressionKind> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn cond_block(input: Span) -> ParseResult<IfExpressionBody> {
|
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> {
|
fn cond_arm(input: Span) -> ParseResult<ConditionArm> {
|
||||||
|
Loading…
Reference in New Issue
Block a user