From 80d97416cb7ee9c535b0795b92b2a1d1d65b0611 Mon Sep 17 00:00:00 2001 From: gluax Date: Mon, 4 Apr 2022 15:31:08 -0700 Subject: [PATCH] fixes and correct tests --- compiler/parser/src/parser/input.rs | 14 +- .../functions/bounded_recursion.leo.out | 4 + .../parser/functions/const_param.leo.out | 8 + .../functions/infinite_recursion.leo.out | 2 + .../parser/parser/functions/params.leo.out | 4 + .../parser/functions/params_return.leo.out | 4 + .../inputs/input_const_section_fail .leo.out | 5 + .../parser/inputs/input_const_success.leo.out | 295 ++++++++++++++++++ .../inputs/input_public_success.leo.out | 295 ++++++++++++++++++ .../parser/inputs/input_success.leo.out | 262 +++++----------- tests/parser/inputs/input_const_success.leo | 18 ++ tests/parser/inputs/input_public_success.leo | 19 ++ tests/parser/inputs/input_success.leo | 16 +- 13 files changed, 748 insertions(+), 198 deletions(-) create mode 100644 tests/expectations/parser/parser/inputs/input_const_section_fail .leo.out create mode 100644 tests/expectations/parser/parser/inputs/input_const_success.leo.out create mode 100644 tests/expectations/parser/parser/inputs/input_public_success.leo.out create mode 100644 tests/parser/inputs/input_const_success.leo create mode 100644 tests/parser/inputs/input_public_success.leo diff --git a/compiler/parser/src/parser/input.rs b/compiler/parser/src/parser/input.rs index dc1118a090..0354967d8d 100644 --- a/compiler/parser/src/parser/input.rs +++ b/compiler/parser/src/parser/input.rs @@ -17,6 +17,7 @@ use super::*; use leo_errors::{ParserError, Result}; +use leo_span::sym; impl ParserContext<'_> { /// Returns a [`ParsedInputFile`] struct filled with the data acquired in the file. @@ -49,10 +50,10 @@ impl ParserContext<'_> { let mut definitions = Vec::new(); while let Some(SpannedToken { - token: Token::Ident(_), .. + token: Token::Const | Token::Private | Token::Public | Token::Ident(_), .. }) = self.peek_option() { - definitions.push(self.parse_input_definition()?); + definitions.push(self.parse_input_definition(section.name == sym::main)?); } Ok(Section { @@ -65,15 +66,16 @@ impl ParserContext<'_> { /// Parses a single parameter definition: /// ` : = ;` /// Returns [`Definition`]. - pub fn parse_input_definition(&mut self) -> Result { + pub fn parse_input_definition(&mut self, is_main: bool) -> Result { let const_ = self.eat(Token::Const).is_some(); let private = self.eat(Token::Private).is_some(); let public = self.eat(Token::Public).is_some(); match (const_, private, public) { - (true, false, false) | (false, true, false) | (false, false, true) => {} - (false, false, false) => return Err(ParserError::inputs_no_variable_type_specified().into()), - _ => return Err(ParserError::inputs_multpe_variable_types_specified().into()), + (true, false, false) | (false, true, false) | (false, false, true) if is_main => {} + (false, false, false) if is_main => return Err(ParserError::inputs_no_variable_type_specified().into()), + _ if is_main => return Err(ParserError::inputs_multpe_variable_types_specified().into()), + _ => {} } let name = self.expect_ident()?; diff --git a/tests/expectations/parser/parser/functions/bounded_recursion.leo.out b/tests/expectations/parser/parser/functions/bounded_recursion.leo.out index c5daae1256..dc914ea67a 100644 --- a/tests/expectations/parser/parser/functions/bounded_recursion.leo.out +++ b/tests/expectations/parser/parser/functions/bounded_recursion.leo.out @@ -11,6 +11,8 @@ outputs: - Variable: identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const y: u32) {\\\"}\"}" const_: true + private: false + public: false mutable: false type_: IntegerType: U32 @@ -130,6 +132,8 @@ outputs: - Variable: identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":15,\\\"col_stop\\\":16,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(y: bool) -> bool {\\\"}\"}" const_: false + private: false + public: false mutable: true type_: Boolean span: diff --git a/tests/expectations/parser/parser/functions/const_param.leo.out b/tests/expectations/parser/parser/functions/const_param.leo.out index 1abefd7344..979a1f10af 100644 --- a/tests/expectations/parser/parser/functions/const_param.leo.out +++ b/tests/expectations/parser/parser/functions/const_param.leo.out @@ -11,6 +11,8 @@ outputs: - Variable: identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":12,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, const y: i32) {\\\"}\"}" const_: false + private: false + public: false mutable: true type_: IntegerType: U32 @@ -24,6 +26,8 @@ outputs: - Variable: identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, const y: i32) {\\\"}\"}" const_: true + private: false + public: false mutable: false type_: IntegerType: I32 @@ -78,6 +82,8 @@ outputs: - Variable: identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const x: u32, y: i32) {\\\"}\"}" const_: true + private: false + public: false mutable: false type_: IntegerType: U32 @@ -91,6 +97,8 @@ outputs: - Variable: identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const x: u32, y: i32) {\\\"}\"}" const_: false + private: false + public: false mutable: true type_: IntegerType: I32 diff --git a/tests/expectations/parser/parser/functions/infinite_recursion.leo.out b/tests/expectations/parser/parser/functions/infinite_recursion.leo.out index 196af95639..8e4db4fe1c 100644 --- a/tests/expectations/parser/parser/functions/infinite_recursion.leo.out +++ b/tests/expectations/parser/parser/functions/infinite_recursion.leo.out @@ -53,6 +53,8 @@ outputs: - Variable: identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":15,\\\"col_stop\\\":16,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(y: bool) -> bool {\\\"}\"}" const_: false + private: false + public: false mutable: true type_: Boolean span: diff --git a/tests/expectations/parser/parser/functions/params.leo.out b/tests/expectations/parser/parser/functions/params.leo.out index 555c27d59b..447f73de83 100644 --- a/tests/expectations/parser/parser/functions/params.leo.out +++ b/tests/expectations/parser/parser/functions/params.leo.out @@ -11,6 +11,8 @@ outputs: - Variable: identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":12,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, y: i32) {\\\"}\"}" const_: false + private: false + public: false mutable: true type_: IntegerType: U32 @@ -24,6 +26,8 @@ outputs: - Variable: identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":20,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, y: i32) {\\\"}\"}" const_: false + private: false + public: false mutable: true type_: IntegerType: I32 diff --git a/tests/expectations/parser/parser/functions/params_return.leo.out b/tests/expectations/parser/parser/functions/params_return.leo.out index 6be865eaa0..271407aae7 100644 --- a/tests/expectations/parser/parser/functions/params_return.leo.out +++ b/tests/expectations/parser/parser/functions/params_return.leo.out @@ -11,6 +11,8 @@ outputs: - Variable: identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":12,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, y: i32) -> u32 {\\\"}\"}" const_: false + private: false + public: false mutable: true type_: IntegerType: U32 @@ -24,6 +26,8 @@ outputs: - Variable: identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":20,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, y: i32) -> u32 {\\\"}\"}" const_: false + private: false + public: false mutable: true type_: IntegerType: I32 diff --git a/tests/expectations/parser/parser/inputs/input_const_section_fail .leo.out b/tests/expectations/parser/parser/inputs/input_const_section_fail .leo.out new file mode 100644 index 0000000000..0673b242df --- /dev/null +++ b/tests/expectations/parser/parser/inputs/input_const_section_fail .leo.out @@ -0,0 +1,5 @@ +--- +namespace: Input +expectation: Fail +outputs: + - "Error [EPAR0370000]: c0\n --> test:4:1\n |\n 4 | c0: bool = true; \n | ^^" diff --git a/tests/expectations/parser/parser/inputs/input_const_success.leo.out b/tests/expectations/parser/parser/inputs/input_const_success.leo.out new file mode 100644 index 0000000000..55bd221b09 --- /dev/null +++ b/tests/expectations/parser/parser/inputs/input_const_success.leo.out @@ -0,0 +1,295 @@ +--- +namespace: Input +expectation: Pass +outputs: + - sections: + - name: main + definitions: + - const_: true + private: false + public: false + type_: Boolean + name: "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const a: bool = true; \\\"}\"}" + value: + Value: + Boolean: + - "true" + - span: + line_start: 4 + line_stop: 4 + col_start: 18 + col_stop: 22 + path: "" + content: "const a: bool = true; " + span: + line_start: 4 + line_stop: 4 + col_start: 10 + col_stop: 14 + path: "" + content: "const a: bool = true; " + - const_: true + private: false + public: false + type_: + IntegerType: U8 + name: "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const b: u8 = 2; \\\"}\"}" + value: + Value: + Implicit: + - "2" + - span: + line_start: 5 + line_stop: 5 + col_start: 18 + col_stop: 19 + path: "" + content: "const b: u8 = 2; " + span: + line_start: 5 + line_stop: 5 + col_start: 10 + col_stop: 12 + path: "" + content: "const b: u8 = 2; " + - const_: true + private: false + public: false + type_: Field + name: "{\"name\":\"c\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const c: field = 0; \\\"}\"}" + value: + Value: + Implicit: + - "0" + - span: + line_start: 6 + line_stop: 6 + col_start: 18 + col_stop: 19 + path: "" + content: "const c: field = 0; " + span: + line_start: 6 + line_stop: 6 + col_start: 10 + col_stop: 15 + path: "" + content: "const c: field = 0; " + - const_: true + private: false + public: false + type_: Group + name: "{\"name\":\"d\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const d: group = (0, 1)group; \\\"}\"}" + value: + Value: + Group: + Tuple: + x: + Number: + - "0" + - span: + line_start: 7 + line_stop: 7 + col_start: 19 + col_stop: 20 + path: "" + content: "const d: group = (0, 1)group; " + y: + Number: + - "1" + - span: + line_start: 7 + line_stop: 7 + col_start: 22 + col_stop: 23 + path: "" + content: "const d: group = (0, 1)group; " + span: + line_start: 7 + line_stop: 7 + col_start: 19 + col_stop: 29 + path: "" + content: "const d: group = (0, 1)group; " + span: + line_start: 7 + line_stop: 7 + col_start: 10 + col_stop: 15 + path: "" + content: "const d: group = (0, 1)group; " + - const_: true + private: false + public: false + type_: Address + name: "{\"name\":\"e\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}" + value: + Value: + Address: + - aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 + - span: + line_start: 8 + line_stop: 8 + col_start: 20 + col_stop: 83 + path: "" + content: "const e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + span: + line_start: 8 + line_stop: 8 + col_start: 10 + col_stop: 17 + path: "" + content: "const e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + span: + line_start: 3 + line_stop: 3 + col_start: 2 + col_stop: 6 + path: "" + content: "[main]" + - name: registers + definitions: + - const_: false + private: false + public: false + type_: Boolean + name: "{\"name\":\"r0\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r0: bool = true; \\\"}\"}" + value: + Value: + Boolean: + - "true" + - span: + line_start: 11 + line_stop: 11 + col_start: 13 + col_stop: 17 + path: "" + content: "r0: bool = true; " + span: + line_start: 11 + line_stop: 11 + col_start: 5 + col_stop: 9 + path: "" + content: "r0: bool = true; " + - const_: false + private: false + public: false + type_: + IntegerType: U8 + name: "{\"name\":\"r1\",\"span\":\"{\\\"line_start\\\":12,\\\"line_stop\\\":12,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r1: u8 = 2; \\\"}\"}" + value: + Value: + Implicit: + - "2" + - span: + line_start: 12 + line_stop: 12 + col_start: 13 + col_stop: 14 + path: "" + content: "r1: u8 = 2; " + span: + line_start: 12 + line_stop: 12 + col_start: 5 + col_stop: 7 + path: "" + content: "r1: u8 = 2; " + - const_: false + private: false + public: false + type_: Field + name: "{\"name\":\"r2\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r2: field = 0; \\\"}\"}" + value: + Value: + Implicit: + - "0" + - span: + line_start: 13 + line_stop: 13 + col_start: 13 + col_stop: 14 + path: "" + content: "r2: field = 0; " + span: + line_start: 13 + line_stop: 13 + col_start: 5 + col_stop: 10 + path: "" + content: "r2: field = 0; " + - const_: false + private: false + public: false + type_: Group + name: "{\"name\":\"r3\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r3: group = (0, 1)group; \\\"}\"}" + value: + Value: + Group: + Tuple: + x: + Number: + - "0" + - span: + line_start: 14 + line_stop: 14 + col_start: 14 + col_stop: 15 + path: "" + content: "r3: group = (0, 1)group; " + y: + Number: + - "1" + - span: + line_start: 14 + line_stop: 14 + col_start: 17 + col_stop: 18 + path: "" + content: "r3: group = (0, 1)group; " + span: + line_start: 14 + line_stop: 14 + col_start: 14 + col_stop: 24 + path: "" + content: "r3: group = (0, 1)group; " + span: + line_start: 14 + line_stop: 14 + col_start: 5 + col_stop: 10 + path: "" + content: "r3: group = (0, 1)group; " + - const_: false + private: false + public: false + type_: Address + name: "{\"name\":\"r4\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}" + value: + Value: + Address: + - aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 + - span: + line_start: 15 + line_stop: 15 + col_start: 15 + col_stop: 78 + path: "" + content: "r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + span: + line_start: 15 + line_stop: 15 + col_start: 5 + col_stop: 12 + path: "" + content: "r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + span: + line_start: 10 + line_stop: 10 + col_start: 2 + col_stop: 11 + path: "" + content: "[registers]" diff --git a/tests/expectations/parser/parser/inputs/input_public_success.leo.out b/tests/expectations/parser/parser/inputs/input_public_success.leo.out new file mode 100644 index 0000000000..3233085279 --- /dev/null +++ b/tests/expectations/parser/parser/inputs/input_public_success.leo.out @@ -0,0 +1,295 @@ +--- +namespace: Input +expectation: Pass +outputs: + - sections: + - name: main + definitions: + - const_: false + private: false + public: true + type_: Boolean + name: "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":8,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"public a: bool = true; \\\"}\"}" + value: + Value: + Boolean: + - "true" + - span: + line_start: 4 + line_stop: 4 + col_start: 19 + col_stop: 23 + path: "" + content: "public a: bool = true; " + span: + line_start: 4 + line_stop: 4 + col_start: 11 + col_stop: 15 + path: "" + content: "public a: bool = true; " + - const_: false + private: false + public: true + type_: + IntegerType: U8 + name: "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":8,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"public b: u8 = 2; \\\"}\"}" + value: + Value: + Implicit: + - "2" + - span: + line_start: 5 + line_stop: 5 + col_start: 19 + col_stop: 20 + path: "" + content: "public b: u8 = 2; " + span: + line_start: 5 + line_stop: 5 + col_start: 11 + col_stop: 13 + path: "" + content: "public b: u8 = 2; " + - const_: false + private: false + public: true + type_: Field + name: "{\"name\":\"c\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":8,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"public c: field = 0; \\\"}\"}" + value: + Value: + Implicit: + - "0" + - span: + line_start: 6 + line_stop: 6 + col_start: 19 + col_stop: 20 + path: "" + content: "public c: field = 0; " + span: + line_start: 6 + line_stop: 6 + col_start: 11 + col_stop: 16 + path: "" + content: "public c: field = 0; " + - const_: false + private: false + public: true + type_: Group + name: "{\"name\":\"d\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":8,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"public d: group = (0, 1)group; \\\"}\"}" + value: + Value: + Group: + Tuple: + x: + Number: + - "0" + - span: + line_start: 7 + line_stop: 7 + col_start: 20 + col_stop: 21 + path: "" + content: "public d: group = (0, 1)group; " + y: + Number: + - "1" + - span: + line_start: 7 + line_stop: 7 + col_start: 23 + col_stop: 24 + path: "" + content: "public d: group = (0, 1)group; " + span: + line_start: 7 + line_stop: 7 + col_start: 20 + col_stop: 30 + path: "" + content: "public d: group = (0, 1)group; " + span: + line_start: 7 + line_stop: 7 + col_start: 11 + col_stop: 16 + path: "" + content: "public d: group = (0, 1)group; " + - const_: false + private: false + public: true + type_: Address + name: "{\"name\":\"e\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":8,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"public e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}" + value: + Value: + Address: + - aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 + - span: + line_start: 8 + line_stop: 8 + col_start: 21 + col_stop: 84 + path: "" + content: "public e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + span: + line_start: 8 + line_stop: 8 + col_start: 11 + col_stop: 18 + path: "" + content: "public e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + span: + line_start: 3 + line_stop: 3 + col_start: 2 + col_stop: 6 + path: "" + content: "[main]" + - name: registers + definitions: + - const_: false + private: false + public: false + type_: Boolean + name: "{\"name\":\"r0\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r0: bool = true; \\\"}\"}" + value: + Value: + Boolean: + - "true" + - span: + line_start: 11 + line_stop: 11 + col_start: 13 + col_stop: 17 + path: "" + content: "r0: bool = true; " + span: + line_start: 11 + line_stop: 11 + col_start: 5 + col_stop: 9 + path: "" + content: "r0: bool = true; " + - const_: false + private: false + public: false + type_: + IntegerType: U8 + name: "{\"name\":\"r1\",\"span\":\"{\\\"line_start\\\":12,\\\"line_stop\\\":12,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r1: u8 = 2; \\\"}\"}" + value: + Value: + Implicit: + - "2" + - span: + line_start: 12 + line_stop: 12 + col_start: 13 + col_stop: 14 + path: "" + content: "r1: u8 = 2; " + span: + line_start: 12 + line_stop: 12 + col_start: 5 + col_stop: 7 + path: "" + content: "r1: u8 = 2; " + - const_: false + private: false + public: false + type_: Field + name: "{\"name\":\"r2\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r2: field = 0; \\\"}\"}" + value: + Value: + Implicit: + - "0" + - span: + line_start: 13 + line_stop: 13 + col_start: 13 + col_stop: 14 + path: "" + content: "r2: field = 0; " + span: + line_start: 13 + line_stop: 13 + col_start: 5 + col_stop: 10 + path: "" + content: "r2: field = 0; " + - const_: false + private: false + public: false + type_: Group + name: "{\"name\":\"r3\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r3: group = (0, 1)group; \\\"}\"}" + value: + Value: + Group: + Tuple: + x: + Number: + - "0" + - span: + line_start: 14 + line_stop: 14 + col_start: 14 + col_stop: 15 + path: "" + content: "r3: group = (0, 1)group; " + y: + Number: + - "1" + - span: + line_start: 14 + line_stop: 14 + col_start: 17 + col_stop: 18 + path: "" + content: "r3: group = (0, 1)group; " + span: + line_start: 14 + line_stop: 14 + col_start: 14 + col_stop: 24 + path: "" + content: "r3: group = (0, 1)group; " + span: + line_start: 14 + line_stop: 14 + col_start: 5 + col_stop: 10 + path: "" + content: "r3: group = (0, 1)group; " + - const_: false + private: false + public: false + type_: Address + name: "{\"name\":\"r4\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}" + value: + Value: + Address: + - aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 + - span: + line_start: 15 + line_stop: 15 + col_start: 15 + col_stop: 78 + path: "" + content: "r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + span: + line_start: 15 + line_stop: 15 + col_start: 5 + col_stop: 12 + path: "" + content: "r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + span: + line_start: 10 + line_stop: 10 + col_start: 2 + col_stop: 11 + path: "" + content: "[registers]" diff --git a/tests/expectations/parser/parser/inputs/input_success.leo.out b/tests/expectations/parser/parser/inputs/input_success.leo.out index e8089469d1..276903324a 100644 --- a/tests/expectations/parser/parser/inputs/input_success.leo.out +++ b/tests/expectations/parser/parser/inputs/input_success.leo.out @@ -5,8 +5,11 @@ 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; \\\"}\"}" + - const_: false + private: true + public: false + type_: Boolean + name: "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"private a: bool = true; \\\"}\"}" value: Value: Boolean: @@ -14,20 +17,23 @@ outputs: - span: line_start: 4 line_stop: 4 - col_start: 12 - col_stop: 16 + col_start: 20 + col_stop: 24 path: "" - content: "a: bool = true; " + content: "private a: bool = true; " span: line_start: 4 line_stop: 4 - col_start: 4 - col_stop: 8 + col_start: 12 + col_stop: 16 path: "" - content: "a: bool = true; " - - type_: + content: "private a: bool = true; " + - const_: false + private: true + public: false + type_: IntegerType: U8 - name: "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"b: u8 = 2; \\\"}\"}" + name: "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"private b: u8 = 2; \\\"}\"}" value: Value: Implicit: @@ -35,19 +41,22 @@ outputs: - span: line_start: 5 line_stop: 5 - col_start: 12 - col_stop: 13 + col_start: 20 + col_stop: 21 path: "" - content: "b: u8 = 2; " + content: "private b: u8 = 2; " span: line_start: 5 line_stop: 5 - col_start: 4 - col_stop: 6 + col_start: 12 + col_stop: 14 path: "" - content: "b: u8 = 2; " - - type_: Field - name: "{\"name\":\"c\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"c: field = 0; \\\"}\"}" + content: "private b: u8 = 2; " + - const_: false + private: true + public: false + type_: Field + name: "{\"name\":\"c\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"private c: field = 0; \\\"}\"}" value: Value: Implicit: @@ -55,19 +64,22 @@ outputs: - span: line_start: 6 line_stop: 6 - col_start: 12 - col_stop: 13 + col_start: 20 + col_stop: 21 path: "" - content: "c: field = 0; " + content: "private c: field = 0; " span: line_start: 6 line_stop: 6 - col_start: 4 - col_stop: 9 + col_start: 12 + col_stop: 17 path: "" - content: "c: field = 0; " - - 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; \\\"}\"}" + content: "private c: field = 0; " + - const_: false + private: true + public: false + type_: Group + name: "{\"name\":\"d\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"private d: group = (0, 1)group; \\\"}\"}" value: Value: Group: @@ -78,36 +90,39 @@ outputs: - span: line_start: 7 line_stop: 7 - col_start: 13 - col_stop: 14 + col_start: 21 + col_stop: 22 path: "" - content: "d: group = (0, 1)group; " + content: "private d: group = (0, 1)group; " y: Number: - "1" - span: line_start: 7 line_stop: 7 - col_start: 16 - col_stop: 17 + col_start: 24 + col_stop: 25 path: "" - content: "d: group = (0, 1)group; " + content: "private d: group = (0, 1)group; " span: line_start: 7 line_stop: 7 - col_start: 13 - col_stop: 23 + col_start: 21 + col_stop: 31 path: "" - content: "d: group = (0, 1)group; " + content: "private d: group = (0, 1)group; " span: line_start: 7 line_stop: 7 - col_start: 4 - col_stop: 9 + col_start: 12 + col_stop: 17 path: "" - content: "d: group = (0, 1)group; " - - type_: Address - name: "{\"name\":\"e\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}" + content: "private d: group = (0, 1)group; " + - const_: false + private: true + public: false + type_: Address + name: "{\"name\":\"e\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"private e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}" value: Value: Address: @@ -115,17 +130,17 @@ outputs: - span: line_start: 8 line_stop: 8 - col_start: 14 - col_stop: 77 + col_start: 22 + col_stop: 85 path: "" - content: "e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + content: "private e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" span: line_start: 8 line_stop: 8 - col_start: 4 - col_stop: 11 + col_start: 12 + col_stop: 19 path: "" - content: "e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + content: "private e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" span: line_start: 3 line_stop: 3 @@ -135,7 +150,10 @@ outputs: content: "[main]" - name: registers definitions: - - type_: Boolean + - const_: false + private: false + public: false + type_: Boolean name: "{\"name\":\"r0\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r0: bool = true; \\\"}\"}" value: Value: @@ -155,7 +173,10 @@ outputs: col_stop: 9 path: "" content: "r0: bool = true; " - - type_: + - const_: false + private: false + public: false + type_: IntegerType: U8 name: "{\"name\":\"r1\",\"span\":\"{\\\"line_start\\\":12,\\\"line_stop\\\":12,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r1: u8 = 2; \\\"}\"}" value: @@ -176,7 +197,10 @@ outputs: col_stop: 7 path: "" content: "r1: u8 = 2; " - - type_: Field + - const_: false + private: false + public: false + type_: Field name: "{\"name\":\"r2\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r2: field = 0; \\\"}\"}" value: Value: @@ -196,7 +220,10 @@ outputs: col_stop: 10 path: "" content: "r2: field = 0; " - - type_: Group + - const_: false + private: false + public: false + type_: Group name: "{\"name\":\"r3\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r3: group = (0, 1)group; \\\"}\"}" value: Value: @@ -236,7 +263,10 @@ outputs: col_stop: 10 path: "" content: "r3: group = (0, 1)group; " - - type_: Address + - const_: false + private: false + public: false + type_: Address name: "{\"name\":\"r4\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}" value: Value: @@ -263,133 +293,3 @@ outputs: col_stop: 11 path: "" content: "[registers]" - - name: constants - definitions: - - type_: Boolean - name: "{\"name\":\"c0\",\"span\":\"{\\\"line_start\\\":18,\\\"line_stop\\\":18,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"c0: bool = true; \\\"}\"}" - value: - Value: - Boolean: - - "true" - - span: - line_start: 18 - line_stop: 18 - col_start: 13 - col_stop: 17 - path: "" - content: "c0: bool = true; " - span: - line_start: 18 - line_stop: 18 - col_start: 5 - col_stop: 9 - path: "" - content: "c0: bool = true; " - - type_: - IntegerType: U8 - name: "{\"name\":\"c1\",\"span\":\"{\\\"line_start\\\":19,\\\"line_stop\\\":19,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"c1: u8 = 2; \\\"}\"}" - value: - Value: - Implicit: - - "2" - - span: - line_start: 19 - line_stop: 19 - col_start: 13 - col_stop: 14 - path: "" - content: "c1: u8 = 2; " - span: - line_start: 19 - line_stop: 19 - col_start: 5 - col_stop: 7 - path: "" - content: "c1: u8 = 2; " - - type_: Field - name: "{\"name\":\"c2\",\"span\":\"{\\\"line_start\\\":20,\\\"line_stop\\\":20,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"c2: field = 0; \\\"}\"}" - value: - Value: - Implicit: - - "0" - - span: - line_start: 20 - line_stop: 20 - col_start: 13 - col_stop: 14 - path: "" - content: "c2: field = 0; " - span: - line_start: 20 - line_stop: 20 - col_start: 5 - col_stop: 10 - path: "" - content: "c2: field = 0; " - - type_: Group - name: "{\"name\":\"c3\",\"span\":\"{\\\"line_start\\\":21,\\\"line_stop\\\":21,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"c3: group = (0, 1)group; \\\"}\"}" - value: - Value: - Group: - Tuple: - x: - Number: - - "0" - - span: - line_start: 21 - line_stop: 21 - col_start: 14 - col_stop: 15 - path: "" - content: "c3: group = (0, 1)group; " - y: - Number: - - "1" - - span: - line_start: 21 - line_stop: 21 - col_start: 17 - col_stop: 18 - path: "" - content: "c3: group = (0, 1)group; " - span: - line_start: 21 - line_stop: 21 - col_start: 14 - col_stop: 24 - path: "" - content: "c3: group = (0, 1)group; " - span: - line_start: 21 - line_stop: 21 - col_start: 5 - col_stop: 10 - path: "" - content: "c3: group = (0, 1)group; " - - type_: Address - name: "{\"name\":\"c4\",\"span\":\"{\\\"line_start\\\":22,\\\"line_stop\\\":22,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"c4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}" - value: - Value: - Address: - - aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 - - span: - line_start: 22 - line_stop: 22 - col_start: 15 - col_stop: 78 - path: "" - content: "c4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" - span: - line_start: 22 - line_stop: 22 - col_start: 5 - col_stop: 12 - path: "" - content: "c4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" - span: - line_start: 17 - line_stop: 17 - col_start: 2 - col_stop: 11 - path: "" - content: "[constants]" diff --git a/tests/parser/inputs/input_const_success.leo b/tests/parser/inputs/input_const_success.leo new file mode 100644 index 0000000000..8db7f767ff --- /dev/null +++ b/tests/parser/inputs/input_const_success.leo @@ -0,0 +1,18 @@ +/* +namespace: Input +expectation: Pass +*/ + +[main] +const a: bool = true; +const b: u8 = 2; +const c: field = 0; +const d: group = (0, 1)group; +const e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; + +[registers] +r0: bool = true; +r1: u8 = 2; +r2: field = 0; +r3: group = (0, 1)group; +r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; diff --git a/tests/parser/inputs/input_public_success.leo b/tests/parser/inputs/input_public_success.leo new file mode 100644 index 0000000000..cc449fe9e1 --- /dev/null +++ b/tests/parser/inputs/input_public_success.leo @@ -0,0 +1,19 @@ +/* +namespace: Input +expectation: Pass +*/ + +[main] +public a: bool = true; +public b: u8 = 2; +public c: field = 0; +public d: group = (0, 1)group; +public e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; + +[registers] +r0: bool = true; +r1: u8 = 2; +r2: field = 0; +r3: group = (0, 1)group; +r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; + diff --git a/tests/parser/inputs/input_success.leo b/tests/parser/inputs/input_success.leo index ed24602a59..ada20e1c29 100644 --- a/tests/parser/inputs/input_success.leo +++ b/tests/parser/inputs/input_success.leo @@ -4,11 +4,11 @@ expectation: Pass */ [main] -a: bool = true; -b: u8 = 2; -c: field = 0; -d: group = (0, 1)group; -e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; +private a: bool = true; +private b: u8 = 2; +private c: field = 0; +private d: group = (0, 1)group; +private e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; [registers] r0: bool = true; @@ -17,9 +17,3 @@ r2: field = 0; r3: group = (0, 1)group; r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; -[constants] -c0: bool = true; -c1: u8 = 2; -c2: field = 0; -c3: group = (0, 1)group; -c4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;