From 0c22d631e8adfaefc1862245a475776f77c22314 Mon Sep 17 00:00:00 2001 From: damirka Date: Tue, 22 Feb 2022 02:18:33 +0300 Subject: [PATCH] adds tests, removes legacy code --- ast/src/_input/input.rs | 139 ---- ast/src/_input/macros.rs | 151 ---- ast/src/_input/mod.rs | 36 - .../_input/program_input/constant_input.rs | 22 - ast/src/_input/program_input/main_input.rs | 22 - ast/src/_input/program_input/mod.rs | 29 - ast/src/_input/program_input/program_input.rs | 91 --- ast/src/_input/program_input/registers.rs | 22 - ast/src/_input/program_state/mod.rs | 26 - .../_input/program_state/private_state/mod.rs | 26 - .../private_state/private_state.rs | 82 -- .../program_state/private_state/record.rs | 22 - .../program_state/private_state/state_leaf.rs | 22 - ast/src/_input/program_state/program_state.rs | 70 -- .../_input/program_state/public_state/mod.rs | 23 - .../public_state/public_state.rs | 66 -- .../program_state/public_state/state.rs | 22 - ast/src/input/_parameter.rs | 54 -- parser/src/test.rs | 13 + .../parser/inputs/input_success.leo.out | 767 ++++++++++++++++++ tests/parser/inputs/input_success.leo | 34 + 21 files changed, 814 insertions(+), 925 deletions(-) delete mode 100644 ast/src/_input/input.rs delete mode 100644 ast/src/_input/macros.rs delete mode 100644 ast/src/_input/mod.rs delete mode 100644 ast/src/_input/program_input/constant_input.rs delete mode 100644 ast/src/_input/program_input/main_input.rs delete mode 100644 ast/src/_input/program_input/mod.rs delete mode 100644 ast/src/_input/program_input/program_input.rs delete mode 100644 ast/src/_input/program_input/registers.rs delete mode 100644 ast/src/_input/program_state/mod.rs delete mode 100644 ast/src/_input/program_state/private_state/mod.rs delete mode 100644 ast/src/_input/program_state/private_state/private_state.rs delete mode 100644 ast/src/_input/program_state/private_state/record.rs delete mode 100644 ast/src/_input/program_state/private_state/state_leaf.rs delete mode 100644 ast/src/_input/program_state/program_state.rs delete mode 100644 ast/src/_input/program_state/public_state/mod.rs delete mode 100644 ast/src/_input/program_state/public_state/public_state.rs delete mode 100644 ast/src/_input/program_state/public_state/state.rs delete mode 100644 ast/src/input/_parameter.rs create mode 100644 tests/expectations/parser/parser/inputs/input_success.leo.out create mode 100644 tests/parser/inputs/input_success.leo diff --git a/ast/src/_input/input.rs b/ast/src/_input/input.rs deleted file mode 100644 index e4465300a9..0000000000 --- a/ast/src/_input/input.rs +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use crate::{ConstantInput, InputValue, MainInput, ProgramInput, ProgramState, Record, Registers, State, StateLeaf}; -use leo_input::{ - files::{File, TableOrSection}, - InputParserError, -}; -use leo_span::Symbol; - -#[derive(Clone, PartialEq, Eq)] -pub struct Input { - name: String, - program_input: ProgramInput, - program_state: ProgramState, -} - -impl Default for Input { - fn default() -> Self { - Self { - name: "default".to_owned(), - program_input: ProgramInput::new(), - program_state: ProgramState::new(), - } - } -} - -#[allow(clippy::len_without_is_empty)] -impl Input { - pub fn new() -> Self { - Self::default() - } - - /// Returns an empty version of this struct with `None` values. - /// Called during constraint synthesis to provide private input variables. - pub fn empty(&self) -> Self { - let input = self.program_input.empty(); - let state = self.program_state.empty(); - - Self { - name: self.name.clone(), - program_input: input, - program_state: state, - } - } - - /// Returns the number of input variables to pass into the `main` program function - pub fn len(&self) -> usize { - self.program_input.len() + self.program_state.len() - } - - /// Manually set the input variables to the `main` program function - pub fn set_main_input(&mut self, input: MainInput) { - self.program_input.main = input; - } - - /// Parse all input variables included in a file and store them in `self`. - pub fn parse_input(&mut self, file: File) -> Result<(), InputParserError> { - for entry in file.entries.into_iter() { - match entry { - TableOrSection::Section(section) => { - self.program_input.parse(section)?; - } - TableOrSection::Table(table) => return Err(InputParserError::table(table)), - } - } - - Ok(()) - } - - /// Parse all state variables included in a file and store them in `self`. - pub fn parse_state(&mut self, file: File) -> Result<(), InputParserError> { - for entry in file.entries.into_iter() { - match entry { - TableOrSection::Section(section) => return Err(InputParserError::section(section.header)), - TableOrSection::Table(table) => { - self.program_state.parse(table)?; - } - } - } - - Ok(()) - } - - /// Returns the main function input value with the given `name`. - #[allow(clippy::ptr_arg)] - pub fn get(&self, name: Symbol) -> Option> { - self.program_input.get(name) - } - - /// Returns the constant input value with the given `name`. - #[allow(clippy::ptr_arg)] - pub fn get_constant(&self, name: Symbol) -> Option> { - self.program_input.get_constant(name) - } - - /// Returns the main input values - pub fn get_main_inputs(&self) -> &MainInput { - &self.program_input.main - } - - /// Returns the main input values - pub fn get_constant_inputs(&self) -> &ConstantInput { - &self.program_input.constants - } - - /// Returns the runtime register input values - pub fn get_registers(&self) -> &Registers { - self.program_input.get_registers() - } - - /// Returns the runtime record input values - pub fn get_record(&self) -> &Record { - self.program_state.get_record() - } - - /// Returns the runtime state input values - pub fn get_state(&self) -> &State { - self.program_state.get_state() - } - - /// Returns the runtime state leaf input values - pub fn get_state_leaf(&self) -> &StateLeaf { - self.program_state.get_state_leaf() - } -} diff --git a/ast/src/_input/macros.rs b/ast/src/_input/macros.rs deleted file mode 100644 index 94d5b7454e..0000000000 --- a/ast/src/_input/macros.rs +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -/// Constructs an input section to store data parsed from a Leo input file. -/// Constructs sections that pass variables to the main function through the input keyword. -#[macro_export] -macro_rules! record_input_section { - ($($name: ident), *) => ($( - - /// An input section declared in an input file with `[$name]`. - #[derive(Clone, PartialEq, Eq, Default)] - pub struct $name { - is_present: bool, - values: IndexMap>, - } - - impl $name { - pub fn new() -> Self { - Self::default() - } - - /// Returns an empty version of this struct with `None` values. - /// Called during constraint synthesis to provide private input variables. - pub fn empty(&self) -> Self { - let is_present = self.is_present; - let mut values = self.values.clone(); - - values.iter_mut().for_each(|(_parameter, value)| { - *value = None; - }); - - Self { is_present, values } - } - - /// Returns `true` if the main function contains the `$name` variable. - pub fn is_present(&self) -> bool { - self.is_present - } - - /// Parses register input definitions and stores them in `self`. - /// This function is called if the main function input contains the `$name` variable. - pub fn parse(&mut self, definitions: Vec) -> Result<(), InputParserError> { - self.is_present = true; - - for definition in definitions { - let value = InputValue::from_expression(definition.parameter.type_.clone(), definition.expression)?; - let parameter = Parameter::from(definition.parameter); - - self.values.insert(parameter, Some(value)); - } - - Ok(()) - } - - /// Returns this section's [IndexMap] of values. - pub fn values(&self) -> IndexMap> { - self.values.clone() - } - - /// a list of all defined name -> type pairs - pub fn types(&self) -> Vec<(String, crate::Type)> { - self.values.iter() - .map(|(parameter, _)| (parameter.variable.name.to_string(), parameter.type_.clone())) - .collect() - } - - /// a map of all defined name -> value pairs, if present - pub fn raw_values(&self) -> IndexMap { - self.values.iter() - .filter(|(_, value)| value.is_some()) - .map(|(parameter, value)| (parameter.variable.name.to_string(), value.as_ref().unwrap().clone())) - .collect() - } - } - )*) -} - -/// Constructs an input section to store data parsed from a Leo input file. -/// Constructs sections that pass variables directly to the main function. -#[macro_export] -macro_rules! main_input_section { - ($($name: ident), *) => ($( - - /// `[$name]` program input section. - #[derive(Clone, PartialEq, Eq, Default)] - pub struct $name { - input: IndexMap>, - } - - #[allow(clippy::len_without_is_empty)] - impl $name { - pub fn new() -> Self { - Self::default() - } - - /// Returns an empty version of this struct with `None` values. - /// Called during constraint synthesis to provide private input variables. - pub fn empty(&self) -> Self { - let mut input = self.input.clone(); - - input.iter_mut().for_each(|(_name, value)| { - *value = None; - }); - - Self { input } - } - - pub fn len(&self) -> usize { - self.input.len() - } - - pub fn insert(&mut self, key: leo_span::Symbol, value: Option) { - self.input.insert(key, value); - } - - /// Parses main input definitions and stores them in `self`. - pub fn parse(&mut self, definitions: Vec) -> Result<(), InputParserError> { - for definition in definitions { - let name = leo_span::Symbol::intern(&definition.parameter.variable.value); - let value = InputValue::from_expression(definition.parameter.type_, definition.expression)?; - - self.insert(name, Some(value)); - } - - Ok(()) - } - - /// Returns an `Option` of the main function input at `name`. - pub fn get(&self, name: leo_span::Symbol) -> Option> { - self.input.get(&name).cloned() - } - - pub fn iter(&self) -> impl Iterator)> { - self.input.iter() - } - } - )*) -} diff --git a/ast/src/_input/mod.rs b/ast/src/_input/mod.rs deleted file mode 100644 index e27b113efb..0000000000 --- a/ast/src/_input/mod.rs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -#![allow(clippy::module_inception)] - -#[macro_use] -pub mod macros; -pub use macros::*; - -pub mod input; -pub use input::*; - -pub mod input_value; -pub use input_value::*; - -pub mod parameters; -pub use parameters::*; - -pub mod program_input; -pub use program_input::*; - -pub mod program_state; -pub use program_state::*; diff --git a/ast/src/_input/program_input/constant_input.rs b/ast/src/_input/program_input/constant_input.rs deleted file mode 100644 index 728feffd7e..0000000000 --- a/ast/src/_input/program_input/constant_input.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use crate::InputValue; -use leo_input::{definitions::Definition, InputParserError}; - -use indexmap::IndexMap; - -main_input_section!(ConstantInput); diff --git a/ast/src/_input/program_input/main_input.rs b/ast/src/_input/program_input/main_input.rs deleted file mode 100644 index f84233bbf9..0000000000 --- a/ast/src/_input/program_input/main_input.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use crate::InputValue; -use leo_input::{definitions::Definition, InputParserError}; - -use indexmap::IndexMap; - -main_input_section!(MainInput); diff --git a/ast/src/_input/program_input/mod.rs b/ast/src/_input/program_input/mod.rs deleted file mode 100644 index c672586aa3..0000000000 --- a/ast/src/_input/program_input/mod.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -#![allow(clippy::module_inception)] - -pub mod constant_input; -pub use constant_input::*; - -pub mod main_input; -pub use main_input::*; - -pub mod program_input; -pub use program_input::*; - -pub mod registers; -pub use registers::*; diff --git a/ast/src/_input/program_input/program_input.rs b/ast/src/_input/program_input/program_input.rs deleted file mode 100644 index 99996278ce..0000000000 --- a/ast/src/_input/program_input/program_input.rs +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use crate::{ConstantInput, InputValue, MainInput, Registers}; -use leo_input::{ - sections::{Header, Section}, - InputParserError, -}; -use leo_span::Symbol; - -#[derive(Clone, PartialEq, Eq, Default)] -pub struct ProgramInput { - pub main: MainInput, - pub constants: ConstantInput, - registers: Registers, -} - -#[allow(clippy::len_without_is_empty)] -impl ProgramInput { - pub fn new() -> Self { - Self::default() - } - - /// Returns an empty version of this struct with `None` values. - /// Called during constraint synthesis to provide private input values. - pub fn empty(&self) -> Self { - let main = self.main.empty(); - let constants = self.constants.empty(); - let registers = self.registers.empty(); - - Self { - main, - constants, - registers, - } - } - - pub fn len(&self) -> usize { - let mut len = 0; - - // Add main input variables and constants. - len += self.main.len(); - len += self.constants.len(); - - // Add registers. - if self.registers.is_present() { - len += 1; - } - - len - } - - /// Parse each input included in a file and store them in `self`. - pub fn parse(&mut self, section: Section) -> Result<(), InputParserError> { - match section.header { - Header::Constants(_constants) => self.constants.parse(section.definitions), - Header::Main(_main) => self.main.parse(section.definitions), - Header::Registers(_registers) => self.registers.parse(section.definitions), - header => Err(InputParserError::input_section_header(header)), - } - } - - /// Returns the main function input value with the given `name` - #[allow(clippy::ptr_arg)] - pub fn get(&self, name: Symbol) -> Option> { - self.main.get(name) - } - - #[allow(clippy::ptr_arg)] - pub fn get_constant(&self, name: Symbol) -> Option> { - self.constants.get(name) - } - - /// Returns the runtime register input values - pub fn get_registers(&self) -> &Registers { - &self.registers - } -} diff --git a/ast/src/_input/program_input/registers.rs b/ast/src/_input/program_input/registers.rs deleted file mode 100644 index 7fdd7fc276..0000000000 --- a/ast/src/_input/program_input/registers.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use crate::{InputValue, Parameter}; -use leo_input::{definitions::Definition, InputParserError}; - -use indexmap::IndexMap; - -record_input_section!(Registers); diff --git a/ast/src/_input/program_state/mod.rs b/ast/src/_input/program_state/mod.rs deleted file mode 100644 index 15b01e33ea..0000000000 --- a/ast/src/_input/program_state/mod.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -#![allow(clippy::module_inception)] - -pub mod private_state; -pub use private_state::*; - -pub mod program_state; -pub use program_state::*; - -pub mod public_state; -pub use public_state::*; diff --git a/ast/src/_input/program_state/private_state/mod.rs b/ast/src/_input/program_state/private_state/mod.rs deleted file mode 100644 index f2ae76c725..0000000000 --- a/ast/src/_input/program_state/private_state/mod.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -#![allow(clippy::module_inception)] - -pub mod private_state; -pub use private_state::*; - -pub mod record; -pub use record::*; - -pub mod state_leaf; -pub use state_leaf::*; diff --git a/ast/src/_input/program_state/private_state/private_state.rs b/ast/src/_input/program_state/private_state/private_state.rs deleted file mode 100644 index a31f97ea65..0000000000 --- a/ast/src/_input/program_state/private_state/private_state.rs +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use crate::{Record, StateLeaf}; -use leo_input::{ - sections::{Header, Section}, - InputParserError, -}; - -#[derive(Clone, PartialEq, Eq, Default)] -pub struct PrivateState { - record: Record, - state_leaf: StateLeaf, -} - -#[allow(clippy::len_without_is_empty)] -impl PrivateState { - pub fn new() -> Self { - Self::default() - } - - /// Returns an empty version of this struct with `None` values. - /// Called during constraint synthesis to provide private input variables. - pub fn empty(&self) -> Self { - let record = self.record.empty(); - let state_leaf = self.state_leaf.empty(); - - Self { record, state_leaf } - } - - pub fn len(&self) -> usize { - let mut len = 0; - - // add record variable - if self.record.is_present() { - len += 1; - } - - // add state_leaf variable - if self.state_leaf.is_present() { - len += 1; - } - - len - } - - /// Parse all input variables included in a file and store them in `self`. - pub fn parse(&mut self, sections: Vec
) -> Result<(), InputParserError> { - for section in sections { - match section.header { - Header::Record(_state) => self.record.parse(section.definitions)?, - Header::StateLeaf(_state_leaf) => self.state_leaf.parse(section.definitions)?, - header => return Err(InputParserError::private_section(header)), - } - } - - Ok(()) - } - - /// Returns the runtime record input values - pub fn get_record(&self) -> &Record { - &self.record - } - - /// Returns the runtime state leaf input values - pub fn get_state_leaf(&self) -> &StateLeaf { - &self.state_leaf - } -} diff --git a/ast/src/_input/program_state/private_state/record.rs b/ast/src/_input/program_state/private_state/record.rs deleted file mode 100644 index 1f903d0af6..0000000000 --- a/ast/src/_input/program_state/private_state/record.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use crate::{InputValue, Parameter}; -use leo_input::{definitions::Definition, InputParserError}; - -use indexmap::IndexMap; - -record_input_section!(Record); diff --git a/ast/src/_input/program_state/private_state/state_leaf.rs b/ast/src/_input/program_state/private_state/state_leaf.rs deleted file mode 100644 index d545d79b1c..0000000000 --- a/ast/src/_input/program_state/private_state/state_leaf.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use crate::{InputValue, Parameter}; -use leo_input::{definitions::Definition, InputParserError}; - -use indexmap::IndexMap; - -record_input_section!(StateLeaf); diff --git a/ast/src/_input/program_state/program_state.rs b/ast/src/_input/program_state/program_state.rs deleted file mode 100644 index bce55706a2..0000000000 --- a/ast/src/_input/program_state/program_state.rs +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use crate::{PrivateState, PublicState, Record, State, StateLeaf}; -use leo_input::{ - tables::{Table, Visibility}, - InputParserError, -}; - -#[derive(Clone, PartialEq, Eq, Default)] -pub struct ProgramState { - public: PublicState, - private: PrivateState, -} - -#[allow(clippy::len_without_is_empty)] -impl ProgramState { - pub fn new() -> Self { - Self::default() - } - - /// Returns an empty version of this struct with `None` values. - /// Called during constraint synthesis to provide private input variables. - pub fn empty(&self) -> Self { - let public = self.public.empty(); - let private = self.private.empty(); - - Self { public, private } - } - - pub fn len(&self) -> usize { - self.public.len() + self.private.len() - } - - /// Parse all input variables included in a file and store them in `self`. - pub fn parse(&mut self, table: Table) -> Result<(), InputParserError> { - match table.visibility { - Visibility::Private(_private) => self.private.parse(table.sections), - Visibility::Public(_public) => self.public.parse(table.sections), - } - } - - /// Returns the runtime record input values - pub fn get_record(&self) -> &Record { - self.private.get_record() - } - - /// Returns the runtime state input values - pub fn get_state(&self) -> &State { - self.public.get_state() - } - - /// Returns the runtime state leaf input values - pub fn get_state_leaf(&self) -> &StateLeaf { - self.private.get_state_leaf() - } -} diff --git a/ast/src/_input/program_state/public_state/mod.rs b/ast/src/_input/program_state/public_state/mod.rs deleted file mode 100644 index f12d7d2e2e..0000000000 --- a/ast/src/_input/program_state/public_state/mod.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -#![allow(clippy::module_inception)] - -pub mod public_state; -pub use public_state::*; - -pub mod state; -pub use state::*; diff --git a/ast/src/_input/program_state/public_state/public_state.rs b/ast/src/_input/program_state/public_state/public_state.rs deleted file mode 100644 index e4ede088b5..0000000000 --- a/ast/src/_input/program_state/public_state/public_state.rs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use crate::State; -use leo_input::{ - sections::{Header, Section}, - InputParserError, -}; - -#[derive(Clone, PartialEq, Eq, Default)] -pub struct PublicState { - state: State, -} - -#[allow(clippy::len_without_is_empty)] -impl PublicState { - pub fn new() -> Self { - Self::default() - } - - /// Returns an empty version of this struct with `None` values. - /// Called during constraint synthesis to provide private input variables. - pub fn empty(&self) -> Self { - let state = self.state.empty(); - - Self { state } - } - - pub fn len(&self) -> usize { - if self.state.is_present() { - 1usize - } else { - 0usize - } - } - - /// Parse all input variables included in a file and store them in `self`. - pub fn parse(&mut self, sections: Vec
) -> Result<(), InputParserError> { - for section in sections { - match section.header { - Header::State(_state) => self.state.parse(section.definitions)?, - header => return Err(InputParserError::public_section(header)), - } - } - - Ok(()) - } - - /// Returns the runtime state input values - pub fn get_state(&self) -> &State { - &self.state - } -} diff --git a/ast/src/_input/program_state/public_state/state.rs b/ast/src/_input/program_state/public_state/state.rs deleted file mode 100644 index aed560a535..0000000000 --- a/ast/src/_input/program_state/public_state/state.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use crate::{InputValue, Parameter}; -use leo_input::{definitions::Definition, InputParserError}; - -use indexmap::IndexMap; - -record_input_section!(State); diff --git a/ast/src/input/_parameter.rs b/ast/src/input/_parameter.rs deleted file mode 100644 index e901909884..0000000000 --- a/ast/src/input/_parameter.rs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use super::*; -use crate::{Identifier, Type}; - -/// A set of properties for a single definition in an input file. -/// Used as a key in [`ProgramInput`] and [`ProgramState`]. -#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize)] -pub struct Parameter { - pub variable: Identifier, - pub type_: Type, - pub span: Span, -} - -impl From for Parameter { - fn from(definition: Definition) -> Self { - Self { - variable: definition.name, - type_: definition.type_, - span: definition.span, - } - } -} - -impl fmt::Display for Parameter { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}: {}", self.variable, self.type_) - } -} - -/// Parameter is a key, so for allowing its JSON representation, -/// we need to make a string. -impl Serialize for Parameter { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - serializer.serialize_str(&self.to_string()) - } -} diff --git a/parser/src/test.rs b/parser/src/test.rs index af9b221600..f33161a9fa 100644 --- a/parser/src/test.rs +++ b/parser/src/test.rs @@ -209,6 +209,18 @@ impl Namespace for SerializeNamespace { } } +struct InputNamespace; + +impl Namespace for InputNamespace { + fn parse_type(&self) -> ParseType { + ParseType::Whole + } + + fn run_test(&self, test: Test) -> Result { + create_session_if_not_set_then(|_| with_handler(tokenize(test)?, |p| p.parse_input()).map(yaml_or_fail)) + } +} + struct TestRunner; impl Runner for TestRunner { @@ -219,6 +231,7 @@ impl Runner for TestRunner { "ParseExpression" => Box::new(ParseExpressionNamespace), "Token" => Box::new(TokenNamespace), "Serialize" => Box::new(SerializeNamespace), + "Input" => Box::new(InputNamespace), _ => return None, }) } diff --git a/tests/expectations/parser/parser/inputs/input_success.leo.out b/tests/expectations/parser/parser/inputs/input_success.leo.out new file mode 100644 index 0000000000..9521d165a1 --- /dev/null +++ b/tests/expectations/parser/parser/inputs/input_success.leo.out @@ -0,0 +1,767 @@ +--- +namespace: Input +expectation: Pass +outputs: + - sections: + - name: main + definitions: + - type_: Boolean + name: "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"a: bool = true; // booleans\\\"}\"}" + value: + Value: + Boolean: + - "true" + - span: + line_start: 4 + line_stop: 4 + col_start: 12 + col_stop: 16 + path: "" + content: "a: bool = true; // booleans" + span: + line_start: 4 + line_stop: 4 + col_start: 4 + col_stop: 8 + path: "" + content: "a: bool = true; // booleans" + - type_: + IntegerType: U8 + name: "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"b: u8 = 2; // integers\\\"}\"}" + value: + Value: + Implicit: + - "2" + - span: + line_start: 5 + line_stop: 5 + col_start: 12 + col_stop: 13 + path: "" + content: "b: u8 = 2; // integers" + span: + line_start: 5 + line_stop: 5 + col_start: 4 + col_stop: 6 + path: "" + content: "b: u8 = 2; // integers" + - type_: Field + name: "{\"name\":\"c\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"c: field = 0; // fields\\\"}\"}" + value: + Value: + Implicit: + - "0" + - span: + line_start: 6 + line_stop: 6 + col_start: 12 + col_stop: 13 + path: "" + content: "c: field = 0; // fields" + span: + line_start: 6 + line_stop: 6 + col_start: 4 + col_stop: 9 + path: "" + content: "c: field = 0; // fields" + - type_: Group + name: "{\"name\":\"d\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"d: group = (0, 1)group; // group elements\\\"}\"}" + value: + Value: + Group: + Tuple: + x: + Number: + - "0" + - span: + line_start: 7 + line_stop: 7 + col_start: 13 + col_stop: 14 + path: "" + content: "d: group = (0, 1)group; // group elements" + y: + Number: + - "1" + - span: + line_start: 7 + line_stop: 7 + col_start: 16 + col_stop: 17 + path: "" + content: "d: group = (0, 1)group; // group elements" + span: + line_start: 7 + line_stop: 7 + col_start: 13 + col_stop: 23 + path: "" + content: "d: group = (0, 1)group; // group elements" + span: + line_start: 7 + line_stop: 7 + col_start: 4 + col_stop: 9 + path: "" + content: "d: group = (0, 1)group; // group elements" + - type_: Address + name: "{\"name\":\"e\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}" + value: + Value: + Address: + - aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 + - span: + line_start: 8 + line_stop: 8 + col_start: 14 + col_stop: 77 + path: "" + content: "e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + span: + line_start: 8 + line_stop: 8 + col_start: 4 + col_stop: 11 + path: "" + content: "e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + - type_: + Array: + - IntegerType: U8 + - - value: "32" + name: "{\"name\":\"f\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"f: [u8; 32] = [0; 32]; // arrays\\\"}\"}" + value: + ArrayInit: + element: + Value: + Implicit: + - "0" + - span: + line_start: 9 + line_stop: 9 + col_start: 16 + col_stop: 17 + path: "" + content: "f: [u8; 32] = [0; 32]; // arrays" + dimensions: + - value: "32" + span: + line_start: 9 + line_stop: 9 + col_start: 15 + col_stop: 22 + path: "" + content: "f: [u8; 32] = [0; 32]; // arrays" + span: + line_start: 9 + line_stop: 9 + col_start: 4 + col_stop: 12 + path: "" + content: "f: [u8; 32] = [0; 32]; // arrays" + - type_: + Array: + - Array: + - IntegerType: U8 + - - value: "2" + - - value: "3" + name: "{\"name\":\"g\",\"span\":\"{\\\"line_start\\\":10,\\\"line_stop\\\":10,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"g: [[u8; 2]; 3] = [[0; 2]; 3]; // arrays of arrays\\\"}\"}" + value: + ArrayInit: + element: + ArrayInit: + element: + Value: + Implicit: + - "0" + - span: + line_start: 10 + line_stop: 10 + col_start: 21 + col_stop: 22 + path: "" + content: "g: [[u8; 2]; 3] = [[0; 2]; 3]; // arrays of arrays" + dimensions: + - value: "2" + span: + line_start: 10 + line_stop: 10 + col_start: 20 + col_stop: 26 + path: "" + content: "g: [[u8; 2]; 3] = [[0; 2]; 3]; // arrays of arrays" + dimensions: + - value: "3" + span: + line_start: 10 + line_stop: 10 + col_start: 19 + col_stop: 30 + path: "" + content: "g: [[u8; 2]; 3] = [[0; 2]; 3]; // arrays of arrays" + span: + line_start: 10 + line_stop: 10 + col_start: 4 + col_stop: 16 + path: "" + content: "g: [[u8; 2]; 3] = [[0; 2]; 3]; // arrays of arrays" + - type_: + Tuple: + - Boolean + - Boolean + name: "{\"name\":\"h\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"h: (bool, bool) = (true, false); // tuples\\\"}\"}" + value: + TupleInit: + elements: + - Value: + Boolean: + - "true" + - span: + line_start: 11 + line_stop: 11 + col_start: 20 + col_stop: 24 + path: "" + content: "h: (bool, bool) = (true, false); // tuples" + - Value: + Boolean: + - "false" + - span: + line_start: 11 + line_stop: 11 + col_start: 26 + col_stop: 31 + path: "" + content: "h: (bool, bool) = (true, false); // tuples" + span: + line_start: 11 + line_stop: 11 + col_start: 19 + col_stop: 32 + path: "" + content: "h: (bool, bool) = (true, false); // tuples" + span: + line_start: 11 + line_stop: 11 + col_start: 4 + col_stop: 16 + path: "" + content: "h: (bool, bool) = (true, false); // tuples" + is_public: true + span: + line_start: 3 + line_stop: 3 + col_start: 2 + col_stop: 6 + path: "" + content: "[main]" + - name: registers + definitions: + - type_: Boolean + name: "{\"name\":\"r0\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r0: bool = true; // booleans\\\"}\"}" + value: + Value: + Boolean: + - "true" + - span: + line_start: 14 + line_stop: 14 + col_start: 13 + col_stop: 17 + path: "" + content: "r0: bool = true; // booleans" + span: + line_start: 14 + line_stop: 14 + col_start: 5 + col_stop: 9 + path: "" + content: "r0: bool = true; // booleans" + - type_: + IntegerType: U8 + name: "{\"name\":\"r1\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r1: u8 = 2; // integers\\\"}\"}" + value: + Value: + Implicit: + - "2" + - span: + line_start: 15 + line_stop: 15 + col_start: 13 + col_stop: 14 + path: "" + content: "r1: u8 = 2; // integers" + span: + line_start: 15 + line_stop: 15 + col_start: 5 + col_stop: 7 + path: "" + content: "r1: u8 = 2; // integers" + - type_: Field + name: "{\"name\":\"r2\",\"span\":\"{\\\"line_start\\\":16,\\\"line_stop\\\":16,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r2: field = 0; // fields\\\"}\"}" + value: + Value: + Implicit: + - "0" + - span: + line_start: 16 + line_stop: 16 + col_start: 13 + col_stop: 14 + path: "" + content: "r2: field = 0; // fields" + span: + line_start: 16 + line_stop: 16 + col_start: 5 + col_stop: 10 + path: "" + content: "r2: field = 0; // fields" + - type_: Group + name: "{\"name\":\"r3\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r3: group = (0, 1)group; // group elements\\\"}\"}" + value: + Value: + Group: + Tuple: + x: + Number: + - "0" + - span: + line_start: 17 + line_stop: 17 + col_start: 14 + col_stop: 15 + path: "" + content: "r3: group = (0, 1)group; // group elements" + y: + Number: + - "1" + - span: + line_start: 17 + line_stop: 17 + col_start: 17 + col_stop: 18 + path: "" + content: "r3: group = (0, 1)group; // group elements" + span: + line_start: 17 + line_stop: 17 + col_start: 14 + col_stop: 24 + path: "" + content: "r3: group = (0, 1)group; // group elements" + span: + line_start: 17 + line_stop: 17 + col_start: 5 + col_stop: 10 + path: "" + content: "r3: group = (0, 1)group; // group elements" + - type_: Address + name: "{\"name\":\"r4\",\"span\":\"{\\\"line_start\\\":18,\\\"line_stop\\\":18,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}" + value: + Value: + Address: + - aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 + - span: + line_start: 18 + line_stop: 18 + col_start: 15 + col_stop: 78 + path: "" + content: "r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + span: + line_start: 18 + line_stop: 18 + col_start: 5 + col_stop: 12 + path: "" + content: "r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + - type_: + Array: + - IntegerType: U8 + - - value: "32" + name: "{\"name\":\"r5\",\"span\":\"{\\\"line_start\\\":19,\\\"line_stop\\\":19,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r5: [u8; 32] = [0; 32]; // arrays\\\"}\"}" + value: + ArrayInit: + element: + Value: + Implicit: + - "0" + - span: + line_start: 19 + line_stop: 19 + col_start: 17 + col_stop: 18 + path: "" + content: "r5: [u8; 32] = [0; 32]; // arrays" + dimensions: + - value: "32" + span: + line_start: 19 + line_stop: 19 + col_start: 16 + col_stop: 23 + path: "" + content: "r5: [u8; 32] = [0; 32]; // arrays" + span: + line_start: 19 + line_stop: 19 + col_start: 5 + col_stop: 13 + path: "" + content: "r5: [u8; 32] = [0; 32]; // arrays" + - type_: + Array: + - Array: + - IntegerType: U8 + - - value: "2" + - - value: "3" + name: "{\"name\":\"r6\",\"span\":\"{\\\"line_start\\\":20,\\\"line_stop\\\":20,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r6: [[u8; 2]; 3] = [[0; 2]; 3]; // arrays of arrays\\\"}\"}" + value: + ArrayInit: + element: + ArrayInit: + element: + Value: + Implicit: + - "0" + - span: + line_start: 20 + line_stop: 20 + col_start: 22 + col_stop: 23 + path: "" + content: "r6: [[u8; 2]; 3] = [[0; 2]; 3]; // arrays of arrays" + dimensions: + - value: "2" + span: + line_start: 20 + line_stop: 20 + col_start: 21 + col_stop: 27 + path: "" + content: "r6: [[u8; 2]; 3] = [[0; 2]; 3]; // arrays of arrays" + dimensions: + - value: "3" + span: + line_start: 20 + line_stop: 20 + col_start: 20 + col_stop: 31 + path: "" + content: "r6: [[u8; 2]; 3] = [[0; 2]; 3]; // arrays of arrays" + span: + line_start: 20 + line_stop: 20 + col_start: 5 + col_stop: 17 + path: "" + content: "r6: [[u8; 2]; 3] = [[0; 2]; 3]; // arrays of arrays" + - type_: + Tuple: + - Boolean + - Boolean + name: "{\"name\":\"r7\",\"span\":\"{\\\"line_start\\\":21,\\\"line_stop\\\":21,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r7: (bool, bool) = (true, false); // tuples\\\"}\"}" + value: + TupleInit: + elements: + - Value: + Boolean: + - "true" + - span: + line_start: 21 + line_stop: 21 + col_start: 21 + col_stop: 25 + path: "" + content: "r7: (bool, bool) = (true, false); // tuples" + - Value: + Boolean: + - "false" + - span: + line_start: 21 + line_stop: 21 + col_start: 27 + col_stop: 32 + path: "" + content: "r7: (bool, bool) = (true, false); // tuples" + span: + line_start: 21 + line_stop: 21 + col_start: 20 + col_stop: 33 + path: "" + content: "r7: (bool, bool) = (true, false); // tuples" + span: + line_start: 21 + line_stop: 21 + col_start: 5 + col_stop: 17 + path: "" + content: "r7: (bool, bool) = (true, false); // tuples" + is_public: true + span: + line_start: 13 + line_stop: 13 + col_start: 2 + col_stop: 11 + path: "" + content: "[registers]" + - name: constants + definitions: + - type_: Boolean + name: "{\"name\":\"c0\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"c0: bool = true; // booleans\\\"}\"}" + value: + Value: + Boolean: + - "true" + - span: + line_start: 24 + line_stop: 24 + col_start: 13 + col_stop: 17 + path: "" + content: "c0: bool = true; // booleans" + span: + line_start: 24 + line_stop: 24 + col_start: 5 + col_stop: 9 + path: "" + content: "c0: bool = true; // booleans" + - type_: + IntegerType: U8 + name: "{\"name\":\"c1\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"c1: u8 = 2; // integers\\\"}\"}" + value: + Value: + Implicit: + - "2" + - span: + line_start: 25 + line_stop: 25 + col_start: 13 + col_stop: 14 + path: "" + content: "c1: u8 = 2; // integers" + span: + line_start: 25 + line_stop: 25 + col_start: 5 + col_stop: 7 + path: "" + content: "c1: u8 = 2; // integers" + - type_: Field + name: "{\"name\":\"c2\",\"span\":\"{\\\"line_start\\\":26,\\\"line_stop\\\":26,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"c2: field = 0; // fields\\\"}\"}" + value: + Value: + Implicit: + - "0" + - span: + line_start: 26 + line_stop: 26 + col_start: 13 + col_stop: 14 + path: "" + content: "c2: field = 0; // fields" + span: + line_start: 26 + line_stop: 26 + col_start: 5 + col_stop: 10 + path: "" + content: "c2: field = 0; // fields" + - type_: Group + name: "{\"name\":\"c3\",\"span\":\"{\\\"line_start\\\":27,\\\"line_stop\\\":27,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"c3: group = (0, 1)group; // group elements\\\"}\"}" + value: + Value: + Group: + Tuple: + x: + Number: + - "0" + - span: + line_start: 27 + line_stop: 27 + col_start: 14 + col_stop: 15 + path: "" + content: "c3: group = (0, 1)group; // group elements" + y: + Number: + - "1" + - span: + line_start: 27 + line_stop: 27 + col_start: 17 + col_stop: 18 + path: "" + content: "c3: group = (0, 1)group; // group elements" + span: + line_start: 27 + line_stop: 27 + col_start: 14 + col_stop: 24 + path: "" + content: "c3: group = (0, 1)group; // group elements" + span: + line_start: 27 + line_stop: 27 + col_start: 5 + col_stop: 10 + path: "" + content: "c3: group = (0, 1)group; // group elements" + - type_: Address + name: "{\"name\":\"c4\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"c4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}" + value: + Value: + Address: + - aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 + - span: + line_start: 28 + line_stop: 28 + col_start: 15 + col_stop: 78 + path: "" + content: "c4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + span: + line_start: 28 + line_stop: 28 + col_start: 5 + col_stop: 12 + path: "" + content: "c4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + - type_: + Array: + - IntegerType: U8 + - - value: "32" + name: "{\"name\":\"c5\",\"span\":\"{\\\"line_start\\\":29,\\\"line_stop\\\":29,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"c5: [u8; 32] = [0; 32]; // arrays\\\"}\"}" + value: + ArrayInit: + element: + Value: + Implicit: + - "0" + - span: + line_start: 29 + line_stop: 29 + col_start: 17 + col_stop: 18 + path: "" + content: "c5: [u8; 32] = [0; 32]; // arrays" + dimensions: + - value: "32" + span: + line_start: 29 + line_stop: 29 + col_start: 16 + col_stop: 23 + path: "" + content: "c5: [u8; 32] = [0; 32]; // arrays" + span: + line_start: 29 + line_stop: 29 + col_start: 5 + col_stop: 13 + path: "" + content: "c5: [u8; 32] = [0; 32]; // arrays" + - type_: + Array: + - Array: + - IntegerType: U8 + - - value: "2" + - - value: "3" + name: "{\"name\":\"c6\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"c6: [[u8; 2]; 3] = [[0; 2]; 3]; // arrays of arrays\\\"}\"}" + value: + ArrayInit: + element: + ArrayInit: + element: + Value: + Implicit: + - "0" + - span: + line_start: 30 + line_stop: 30 + col_start: 22 + col_stop: 23 + path: "" + content: "c6: [[u8; 2]; 3] = [[0; 2]; 3]; // arrays of arrays" + dimensions: + - value: "2" + span: + line_start: 30 + line_stop: 30 + col_start: 21 + col_stop: 27 + path: "" + content: "c6: [[u8; 2]; 3] = [[0; 2]; 3]; // arrays of arrays" + dimensions: + - value: "3" + span: + line_start: 30 + line_stop: 30 + col_start: 20 + col_stop: 31 + path: "" + content: "c6: [[u8; 2]; 3] = [[0; 2]; 3]; // arrays of arrays" + span: + line_start: 30 + line_stop: 30 + col_start: 5 + col_stop: 17 + path: "" + content: "c6: [[u8; 2]; 3] = [[0; 2]; 3]; // arrays of arrays" + - type_: + Tuple: + - Boolean + - Boolean + name: "{\"name\":\"c7\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"c7: (bool, bool) = (true, false); // tuples\\\"}\"}" + value: + TupleInit: + elements: + - Value: + Boolean: + - "true" + - span: + line_start: 31 + line_stop: 31 + col_start: 21 + col_stop: 25 + path: "" + content: "c7: (bool, bool) = (true, false); // tuples" + - Value: + Boolean: + - "false" + - span: + line_start: 31 + line_stop: 31 + col_start: 27 + col_stop: 32 + path: "" + content: "c7: (bool, bool) = (true, false); // tuples" + span: + line_start: 31 + line_stop: 31 + col_start: 20 + col_stop: 33 + path: "" + content: "c7: (bool, bool) = (true, false); // tuples" + span: + line_start: 31 + line_stop: 31 + col_start: 5 + col_stop: 17 + path: "" + content: "c7: (bool, bool) = (true, false); // tuples" + is_public: true + span: + line_start: 23 + line_stop: 23 + col_start: 2 + col_stop: 11 + path: "" + content: "[constants]" diff --git a/tests/parser/inputs/input_success.leo b/tests/parser/inputs/input_success.leo new file mode 100644 index 0000000000..fae8348174 --- /dev/null +++ b/tests/parser/inputs/input_success.leo @@ -0,0 +1,34 @@ +/* +namespace: Input +expectation: Pass +*/ + +[main] +a: bool = true; +b: u8 = 2; +c: field = 0; +d: group = (0, 1)group; +e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; +f: [u8; 32] = [0; 32]; +g: [[u8; 2]; 3] = [[0; 2]; 3]; +h: (bool, bool) = (true, false); + +[registers] +r0: bool = true; +r1: u8 = 2; +r2: field = 0; +r3: group = (0, 1)group; +r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; +r5: [u8; 32] = [0; 32]; +r6: [[u8; 2]; 3] = [[0; 2]; 3]; +r7: (bool, bool) = (true, false); + +[constants] +c0: bool = true; +c1: u8 = 2; +c2: field = 0; +c3: group = (0, 1)group; +c4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; +c5: [u8; 32] = [0; 32]; +c6: [[u8; 2]; 3] = [[0; 2]; 3]; +c7: (bool, bool) = (true, false);