Flow
This commit is contained in:
parent
88d2571401
commit
7ae7eaa07b
@ -86,7 +86,7 @@ pub fn program(input: Span) -> ParseResult<AST> {
|
||||
map(
|
||||
tuple((
|
||||
many0(statement_delimiter),
|
||||
separated_list0(statement_delimiter, statement),
|
||||
separated_list0(many1(statement_delimiter), statement),
|
||||
many0(statement_delimiter),
|
||||
)),
|
||||
|(_, items, _)| items.into(),
|
||||
@ -105,7 +105,7 @@ fn block_template<'a, O>(
|
||||
tok(char('{')),
|
||||
tuple((
|
||||
many0(statement_delimiter),
|
||||
separated_list0(statement_delimiter, input_parser),
|
||||
separated_list0(many1(statement_delimiter), input_parser),
|
||||
many0(statement_delimiter),
|
||||
)),
|
||||
tok(char('}')),
|
||||
@ -124,11 +124,23 @@ fn statement(input: Span) -> ParseResult<Statement> {
|
||||
let id = fresh_id(&input);
|
||||
let (rest, kind) = context(
|
||||
"Parsing-statement",
|
||||
alt((map(declaration, StatementKind::Declaration), map(expression, StatementKind::Expression))),
|
||||
alt((
|
||||
map(flow, StatementKind::Flow),
|
||||
map(declaration, StatementKind::Declaration),
|
||||
map(expression, StatementKind::Expression),
|
||||
)),
|
||||
)(input)?;
|
||||
Ok((rest, Statement { id, location, kind }))
|
||||
}
|
||||
|
||||
fn flow(input: Span) -> ParseResult<FlowControl> {
|
||||
alt((
|
||||
map(kw("continue"), |_| FlowControl::Continue),
|
||||
map(kw("break"), |_| FlowControl::Break),
|
||||
map(preceded(kw("return"), opt(expression)), FlowControl::Return),
|
||||
))(input)
|
||||
}
|
||||
|
||||
fn declaration(input: Span) -> ParseResult<Declaration> {
|
||||
alt((binding, type_decl, func, annotation, module, interface, implementation))(input)
|
||||
}
|
||||
@ -489,10 +501,14 @@ fn record_block(input: Span) -> ParseResult<Vec<(Rc<String>, Expression)>> {
|
||||
|
||||
fn lambda_expr(input: Span) -> ParseResult<ExpressionKind> {
|
||||
alt((
|
||||
map(preceded(tok(char('\\')), tuple((formal_params, opt(type_anno), block))),
|
||||
|(params, type_anno, body)| ExpressionKind::Lambda { params, type_anno, body }),
|
||||
map(preceded(tok(char('\\')), tuple((formal_param, opt(type_anno), block))),
|
||||
|(param, type_anno, body)| ExpressionKind::Lambda { params: vec![param], type_anno, body }),
|
||||
map(
|
||||
preceded(tok(char('\\')), tuple((formal_params, opt(type_anno), block))),
|
||||
|(params, type_anno, body)| ExpressionKind::Lambda { params, type_anno, body },
|
||||
),
|
||||
map(
|
||||
preceded(tok(char('\\')), tuple((formal_param, opt(type_anno), block))),
|
||||
|(param, type_anno, body)| ExpressionKind::Lambda { params: vec![param], type_anno, body },
|
||||
),
|
||||
))(input)
|
||||
}
|
||||
|
||||
|
@ -1289,7 +1289,7 @@ if (45, "panda", false, 2.2) {
|
||||
fn flow_control() {
|
||||
use ExpressionKind::*;
|
||||
|
||||
// This is an incorrect program, but shoudl parse correctly.
|
||||
// This is an incorrect program, but should parse correctly.
|
||||
let source = r#"
|
||||
fn test() {
|
||||
let a = 10;
|
||||
@ -1299,7 +1299,7 @@ fn flow_control() {
|
||||
return 10;
|
||||
}"#;
|
||||
|
||||
assert_ast!(
|
||||
assert_ast_comb!(
|
||||
source,
|
||||
vec![fn_decl(
|
||||
Signature { name: rc("test"), operator: false, type_anno: None, params: vec![] },
|
||||
@ -1337,7 +1337,7 @@ fn blocks() {
|
||||
fn foo() { }
|
||||
}
|
||||
}"#;
|
||||
let block = parser.block(source);
|
||||
let block = parser.block_comb(source);
|
||||
assert_eq!(
|
||||
block.unwrap(),
|
||||
vec![decl(Declaration::FuncDecl(
|
||||
|
Loading…
Reference in New Issue
Block a user