diff --git a/src/protocol/parser/pass_definitions.rs b/src/protocol/parser/pass_definitions.rs
index 885c5aa4a83626d35fed98fa687fed9be50e92ff..94de9499c7f17bf17a73332551296924f9d7953d 100644
--- a/src/protocol/parser/pass_definitions.rs
+++ b/src/protocol/parser/pass_definitions.rs
@@ -487,10 +487,9 @@ impl PassDefinitions {
// Two fallback possibilities: the first one is a memory
// declaration, the other one is to parse it as a normal
// expression. This is a bit ugly.
- if let Some((memory_stmt_id, assignment_stmt_id)) = self.maybe_consume_memory_statement_without_semicolon(module, iter, ctx)? {
+ if let Some(memory_stmt_id) = self.maybe_consume_memory_statement_without_semicolon(module, iter, ctx)? {
consume_token(&module.source, iter, TokenKind::SemiColon)?;
section.push(memory_stmt_id.upcast().upcast());
- section.push(assignment_stmt_id.upcast());
} else {
let id = self.consume_expression_statement(module, iter, ctx)?;
section.push(id.upcast());
@@ -498,10 +497,9 @@ impl PassDefinitions {
}
} else if next == TokenKind::OpenParen {
// Same as above: memory statement or normal expression
- if let Some((memory_stmt_id, assignment_stmt_id)) = self.maybe_consume_memory_statement_without_semicolon(module, iter, ctx)? {
+ if let Some(memory_stmt_id) = self.maybe_consume_memory_statement_without_semicolon(module, iter, ctx)? {
consume_token(&module.source, iter, TokenKind::SemiColon);
section.push(memory_stmt_id.upcast().upcast());
- section.push(assignment_stmt_id.upcast());
} else {
let id = self.consume_expression_statement(module, iter, ctx)?;
section.push(id.upcast());
@@ -696,26 +694,26 @@ impl PassDefinitions {
let mut next = iter.next();
while Some(TokenKind::CloseCurly) != next {
- let (guard_var, guard_expr) = match self.maybe_consume_memory_statement_without_semicolon(module, iter, ctx)? {
- Some(guard_var_and_expr) => guard_var_and_expr,
+ let guard = match self.maybe_consume_memory_statement_without_semicolon(module, iter, ctx)? {
+ Some(guard_mem_stmt) => guard_mem_stmt.upcast().upcast(),
None => {
let start_pos = iter.last_valid_pos();
let expr = self.consume_expression(module, iter, ctx)?;
let end_pos = iter.last_valid_pos();
- let guard_expr = ctx.heap.alloc_expression_statement(|this| ExpressionStatement{
+ let guard_expr_stmt = ctx.heap.alloc_expression_statement(|this| ExpressionStatement{
this,
span: InputSpan::from_positions(start_pos, end_pos),
expression: expr,
next: StatementId::new_invalid(),
});
- (MemoryStatementId::new_invalid(), guard_expr)
+ guard_expr_stmt.upcast()
},
};
consume_token(&module.source, iter, TokenKind::ArrowRight)?;
let block = self.consume_block_or_wrapped_statement(module, iter, ctx)?;
- cases.push(SelectCase{ guard_var, guard_expr, block });
+ cases.push(SelectCase{ guard, block });
next = iter.next();
}
@@ -925,9 +923,14 @@ impl PassDefinitions {
Ok(())
}
+ /// Attempts to consume a memory statement (a statement along the lines of
+ /// `type var_name = initial_expr`). Will return `Ok(None)` if it didn't
+ /// seem like there was a memory statement, `Ok(Some(...))` if there was
+ /// one, and `Err(...)` if its reasonable to assume that there was a memory
+ /// statement, but we failed to parse it.
fn maybe_consume_memory_statement_without_semicolon(
&mut self, module: &Module, iter: &mut TokenIter, ctx: &mut PassCtx
- ) -> Result