mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-24 07:48:04 +03:00
require loop type
This commit is contained in:
parent
85efd764a6
commit
19c27518cc
@ -409,12 +409,14 @@ impl Canonicalizer {
|
||||
})
|
||||
}
|
||||
Statement::Iteration(iteration) => {
|
||||
let type_ = self.canonicalize_self_type(Some(&iteration.type_)).unwrap();
|
||||
let start = self.canonicalize_expression(&iteration.start);
|
||||
let stop = self.canonicalize_expression(&iteration.stop);
|
||||
let block = self.canonicalize_block(&iteration.block);
|
||||
|
||||
Statement::Iteration(Box::new(IterationStatement {
|
||||
variable: iteration.variable.clone(),
|
||||
type_,
|
||||
start,
|
||||
stop,
|
||||
inclusive: iteration.inclusive,
|
||||
|
@ -364,11 +364,13 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
||||
|
||||
pub fn reduce_iteration(&mut self, iteration: &IterationStatement) -> Result<IterationStatement> {
|
||||
let variable = self.reduce_identifier(&iteration.variable)?;
|
||||
let type_ = self.reduce_type(&iteration.type_, iteration.span())?;
|
||||
let start = self.reduce_expression(&iteration.start)?;
|
||||
let stop = self.reduce_expression(&iteration.stop)?;
|
||||
let block = self.reduce_block(&iteration.block)?;
|
||||
|
||||
self.reducer.reduce_iteration(iteration, variable, start, stop, block)
|
||||
self.reducer
|
||||
.reduce_iteration(iteration, variable, type_, start, stop, block)
|
||||
}
|
||||
|
||||
pub fn reduce_console(&mut self, console_function_call: &ConsoleStatement) -> Result<ConsoleStatement> {
|
||||
|
@ -343,12 +343,14 @@ pub trait ReconstructingReducer {
|
||||
&mut self,
|
||||
iteration: &IterationStatement,
|
||||
variable: Identifier,
|
||||
type_: Type,
|
||||
start: Expression,
|
||||
stop: Expression,
|
||||
block: Block,
|
||||
) -> Result<IterationStatement> {
|
||||
Ok(IterationStatement {
|
||||
variable,
|
||||
type_,
|
||||
start,
|
||||
stop,
|
||||
inclusive: iteration.inclusive,
|
||||
|
@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{Block, Expression, Identifier, Node};
|
||||
use crate::{Block, Expression, Identifier, Node, Type};
|
||||
use leo_span::Span;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -25,6 +25,8 @@ use std::fmt;
|
||||
pub struct IterationStatement {
|
||||
/// The binding / variable to introduce in the body `block`.
|
||||
pub variable: Identifier,
|
||||
/// The type of the iteration.
|
||||
pub type_: Type,
|
||||
/// The start of the iteration.
|
||||
pub start: Expression,
|
||||
/// The end of the iteration, possibly `inclusive`.
|
||||
|
@ -193,6 +193,8 @@ impl ParserContext<'_> {
|
||||
pub fn parse_loop_statement(&mut self) -> Result<IterationStatement> {
|
||||
let start_span = self.expect(Token::For)?;
|
||||
let ident = self.expect_ident()?;
|
||||
self.expect(Token::Colon)?;
|
||||
let type_ = self.parse_type()?;
|
||||
self.expect(Token::In)?;
|
||||
|
||||
// Parse iteration range.
|
||||
@ -208,6 +210,7 @@ impl ParserContext<'_> {
|
||||
Ok(IterationStatement {
|
||||
span: start_span + block.span.clone(),
|
||||
variable: ident,
|
||||
type_: type_.0,
|
||||
start,
|
||||
stop,
|
||||
inclusive,
|
||||
|
Loading…
Reference in New Issue
Block a user