block template
This commit is contained in:
parent
d5cd0dada7
commit
6454cc5ad1
@ -95,28 +95,28 @@ pub fn program(input: Span) -> ParseResult<AST> {
|
||||
),
|
||||
)(input)?;
|
||||
|
||||
println!("REST: {}", rest.fragment());
|
||||
|
||||
let ast = AST { id, statements };
|
||||
Ok((rest, ast))
|
||||
}
|
||||
|
||||
pub fn block(input: Span) -> ParseResult<Block> {
|
||||
context(
|
||||
"block",
|
||||
map(
|
||||
delimited(
|
||||
tok(char('{')),
|
||||
tuple((
|
||||
many0(statement_delimiter),
|
||||
separated_list0(statement_delimiter, statement),
|
||||
many0(statement_delimiter),
|
||||
)),
|
||||
tok(char('}')),
|
||||
),
|
||||
|(_, items, _)| items.into(),
|
||||
fn block_template<'a, O>(input_parser: impl Parser<Span<'a>, O, VerboseError<Span<'a>>>) -> impl FnMut(Span<'a>) ->
|
||||
IResult<Span<'a>, Vec<O>, VerboseError<Span<'a>>> {
|
||||
map(
|
||||
delimited(
|
||||
tok(char('{')),
|
||||
tuple((
|
||||
many0(statement_delimiter),
|
||||
separated_list0(statement_delimiter, input_parser),
|
||||
many0(statement_delimiter),
|
||||
)),
|
||||
tok(char('}')),
|
||||
),
|
||||
)(input)
|
||||
|(_, items, _)| items,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn block(input: Span) -> ParseResult<Block> {
|
||||
map(block_template(statement), |items| items.into())(input)
|
||||
}
|
||||
|
||||
fn statement(input: Span) -> ParseResult<Statement> {
|
||||
@ -151,18 +151,7 @@ fn implementation(input: Span) -> ParseResult<Declaration> {
|
||||
}
|
||||
|
||||
fn decl_block(input: Span) -> ParseResult<Vec<Declaration>> {
|
||||
delimited(
|
||||
tok(char('{')),
|
||||
map(
|
||||
tuple((
|
||||
many0(statement_delimiter),
|
||||
separated_list0(statement_delimiter, func_decl),
|
||||
many0(statement_delimiter),
|
||||
)),
|
||||
|(_, signatures, _)| signatures,
|
||||
),
|
||||
tok(char('}')),
|
||||
)(input)
|
||||
block_template(func_decl)(input)
|
||||
}
|
||||
|
||||
fn interface(input: Span) -> ParseResult<Declaration> {
|
||||
@ -171,20 +160,8 @@ fn interface(input: Span) -> ParseResult<Declaration> {
|
||||
})(input)
|
||||
}
|
||||
|
||||
//TODO make the blocks parameterizable
|
||||
fn signature_block(input: Span) -> ParseResult<Vec<Signature>> {
|
||||
delimited(
|
||||
tok(char('{')),
|
||||
map(
|
||||
tuple((
|
||||
many0(statement_delimiter),
|
||||
separated_list0(statement_delimiter, func_signature),
|
||||
many0(statement_delimiter),
|
||||
)),
|
||||
|(_, signatures, _)| signatures,
|
||||
),
|
||||
tok(char('}')),
|
||||
)(input)
|
||||
block_template(func_signature)(input)
|
||||
}
|
||||
|
||||
fn annotation(input: Span) -> ParseResult<Declaration> {
|
||||
|
Loading…
Reference in New Issue
Block a user