Control flow
This commit is contained in:
+11
-1
@@ -343,7 +343,8 @@ block = {
|
||||
}
|
||||
|
||||
statement = _{
|
||||
(expr ~ semicolon)
|
||||
control_flow
|
||||
| (expr ~ semicolon)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
@@ -377,6 +378,15 @@ var_decl_statement = {
|
||||
// CONDITIONALS
|
||||
// ------------------------------------------------------
|
||||
|
||||
control_flow = {
|
||||
if_stmt
|
||||
| while_stmt
|
||||
| c_for_stmt
|
||||
| for_stmt
|
||||
| match_stmt
|
||||
| block
|
||||
}
|
||||
|
||||
statement_branch = { "(" ~ expr ~ ")" ~ statement }
|
||||
|
||||
else_if = {
|
||||
|
||||
@@ -78,12 +78,9 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Expression {
|
||||
Rule::static_path => ast_expr!(Expression::Path(pair.try_into())),
|
||||
Rule::literal => ast_expr!(Expression::Literal(pair.try_into())),
|
||||
Rule::expr_path => ast_expr!(Expression::Path(pair.try_into())),
|
||||
Rule::statement => ast_expr!(Expression::Statement(
|
||||
pair.try_into().get_map(Box::new).map(Box::new)
|
||||
)),
|
||||
Rule::basic_stmt => ast_expr!(Expression::Statement(
|
||||
pair.try_into().get_map(Box::new).map(Box::new)
|
||||
)),
|
||||
Rule::statement | Rule::basic_stmt | Rule::control_flow => ast_expr!(
|
||||
Expression::Statement(pair.try_into().get_map(Box::new).map(Box::new))
|
||||
),
|
||||
|
||||
_ => AstError::bug_unimplemented(pair),
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Statement {
|
||||
let mut inner = pair.clone().into_inner();
|
||||
|
||||
match rule {
|
||||
Rule::statement | Rule::basic_stmt => Statement::try_from(inner.next().unwrap()),
|
||||
Rule::statement | Rule::basic_stmt | Rule::control_flow => Statement::try_from(inner.next().unwrap()),
|
||||
|
||||
Rule::block => ast_expr!(Statement::Block(pair.try_into())),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user