fix for loop syntax

This commit is contained in:
collin 2020-04-27 16:06:50 -07:00
parent f69032c833
commit c5fc02b51d
3 changed files with 8 additions and 14 deletions

View File

@ -890,11 +890,7 @@ impl<'ast> fmt::Display for ConditionalNestedOrEnd<'ast> {
match *self {
ConditionalNestedOrEnd::Nested(ref nested) => write!(f, "else {}", nested),
ConditionalNestedOrEnd::End(ref statements) => {
write!(f, "else {{\n")?;
for statement in statements.iter() {
write!(f, "\t{}\n", statement)?;
}
write!(f, "}}")
write!(f, "else {{\n \t{:#?}\n }}", statements)
}
}
}
@ -903,9 +899,7 @@ impl<'ast> fmt::Display for ConditionalNestedOrEnd<'ast> {
impl<'ast> fmt::Display for ConditionalStatement<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "if ({}) {{\n", self.condition)?;
for statement in self.statements.iter() {
write!(f, "\t{}\n", statement)?;
}
write!(f, "\t{:#?}\n", self.statements)?;
self.next
.as_ref()
.map(|n_or_e| write!(f, "}} {}", n_or_e))
@ -917,7 +911,7 @@ impl<'ast> fmt::Display for ForStatement<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"for {} in {}..{} do {:#?} endfor",
"for {} in {}..{} {{ {:#?} }}",
self.index, self.start, self.stop, self.statements
)
}

View File

@ -149,13 +149,13 @@ statement_assign = { assignee ~ "=" ~ expression }
statement_multiple_assignment = { optionally_typed_variable_tuple ~ "=" ~ variable ~ "(" ~ expression_tuple ~ ")" }
statement_conditional = {"if" ~ "(" ~ expression ~ ")" ~ "{" ~ NEWLINE* ~ statement+ ~ "}" ~ ("else" ~ conditional_nested_or_end)?}
conditional_nested_or_end = { statement_conditional | "{" ~ NEWLINE* ~ statement+ ~ "}"}
statement_for = { "for" ~ variable ~ "in" ~ expression ~ ".." ~ expression ~ "do" ~ NEWLINE* ~ statement* ~ "endfor"}
statement_for = { "for" ~ variable ~ "in" ~ expression ~ ".." ~ expression ~ "{" ~ NEWLINE* ~ statement+ ~ "}"}
statement = {
(statement_return
| statement_conditional
| (statement_for
| statement_multiple_assignment
| statement_for
| (statement_multiple_assignment
| statement_definition
| statement_assign
) ~ LINE_END

View File

@ -197,11 +197,11 @@ impl<F: Field + PrimeField> fmt::Display for Statement<F> {
}
Statement::Conditional(ref statement) => write!(f, "{}", statement),
Statement::For(ref var, ref start, ref stop, ref list) => {
write!(f, "for {} in {}..{} do\n", var, start, stop)?;
write!(f, "for {} in {}..{} {{\n", var, start, stop)?;
for l in list {
write!(f, "\t\t{}\n", l)?;
}
write!(f, "\tendfor;")
write!(f, "\t}}")
}
}
}