From cfc5b00bad1c81092901fcb2bc138391af73b56e Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Sun, 10 Apr 2022 23:10:55 -0700 Subject: [PATCH 1/6] add constant keyword, only used for params --- .../ast/src/functions/input/function_input.rs | 4 +- compiler/parser/src/parser/file.rs | 6 +- compiler/parser/src/parser/input.rs | 2 +- compiler/parser/src/parser/statement.rs | 2 +- compiler/parser/src/tokenizer/lexer.rs | 1 + compiler/parser/src/tokenizer/mod.rs | 5 +- compiler/parser/src/tokenizer/token.rs | 4 + leo/package/tests/manifest/manifest.rs | 4 +- leo/span/src/symbol.rs | 1 + .../functions/bounded_recursion.leo.out | 20 ++-- .../parser/functions/const_input_fail.leo.out | 2 +- .../parser/functions/const_param.leo.out | 52 +++++------ .../functions/const_public_param_fail.leo.out | 2 +- .../functions/public_const_param_fail.leo.out | 2 +- .../parser/parser/inputs/input_const.leo.out | 92 +++++++++---------- .../inputs/input_const_public_fail.leo.out | 2 +- .../inputs/input_public_const_fail.leo.out | 2 +- tests/parser/functions/bounded_recursion.leo | 2 +- tests/parser/functions/const_input_fail.leo | 4 + tests/parser/functions/const_param.leo | 4 +- .../functions/const_public_param_fail.leo | 2 +- .../functions/public_const_param_fail.leo | 2 +- tests/parser/inputs/input_const.leo | 10 +- .../parser/inputs/input_const_public_fail.leo | 10 +- .../parser/inputs/input_public_const_fail.leo | 10 +- 25 files changed, 128 insertions(+), 119 deletions(-) diff --git a/compiler/ast/src/functions/input/function_input.rs b/compiler/ast/src/functions/input/function_input.rs index be5afef527..19494375e5 100644 --- a/compiler/ast/src/functions/input/function_input.rs +++ b/compiler/ast/src/functions/input/function_input.rs @@ -22,7 +22,7 @@ use std::fmt; #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub enum ParamMode { - Const, + Constant, Private, Public, } @@ -32,7 +32,7 @@ impl fmt::Display for ParamMode { use ParamMode::*; match self { - Const => write!(f, "const"), + Constant => write!(f, "constant"), Private => write!(f, "private"), Public => write!(f, "public"), } diff --git a/compiler/parser/src/parser/file.rs b/compiler/parser/src/parser/file.rs index a90b35165f..fcfd1a1713 100644 --- a/compiler/parser/src/parser/file.rs +++ b/compiler/parser/src/parser/file.rs @@ -66,10 +66,10 @@ impl ParserContext<'_> { /// pub fn parse_function_parameter_mode(&mut self) -> Result { let public = self.eat(Token::Public); - let const_ = self.eat(Token::Const); + let constant = self.eat(Token::Constant); - match (public, const_) { - (None, Some(_)) => Ok(ParamMode::Const), + match (public, constant) { + (None, Some(_)) => Ok(ParamMode::Constant), (None, None) => Ok(ParamMode::Private), (Some(_), None) => Ok(ParamMode::Public), (Some(p), Some(c)) => Err(ParserError::inputs_multiple_variable_types_specified(&(p.span + c.span)).into()), diff --git a/compiler/parser/src/parser/input.rs b/compiler/parser/src/parser/input.rs index 2c0b68d6f8..e0f1a3ec37 100644 --- a/compiler/parser/src/parser/input.rs +++ b/compiler/parser/src/parser/input.rs @@ -49,7 +49,7 @@ impl ParserContext<'_> { let mut definitions = Vec::new(); while let Some(SpannedToken { - token: Token::Const | Token::Public | Token::Ident(_), + token: Token::Constant | Token::Public | Token::Ident(_), .. }) = self.peek_option() { diff --git a/compiler/parser/src/parser/statement.rs b/compiler/parser/src/parser/statement.rs index 354257738c..440a66e8c5 100644 --- a/compiler/parser/src/parser/statement.rs +++ b/compiler/parser/src/parser/statement.rs @@ -26,7 +26,7 @@ impl ParserContext<'_> { /// Returns an [`Identifier`] AST node if the given [`Expression`] AST node evaluates to an /// identifier access. The access is stored in the given accesses. /// - pub fn construct_assignee_access(expr: Expression, _accesses: &mut Vec) -> Result { + pub fn construct_assignee_access(expr: Expression, _accesses: &mut [AssigneeAccess]) -> Result { match expr { Expression::Identifier(id) => Ok(id), _ => return Err(ParserError::invalid_assignment_target(expr.span()).into()), diff --git a/compiler/parser/src/tokenizer/lexer.rs b/compiler/parser/src/tokenizer/lexer.rs index f65260ff24..b7a1162b29 100644 --- a/compiler/parser/src/tokenizer/lexer.rs +++ b/compiler/parser/src/tokenizer/lexer.rs @@ -393,6 +393,7 @@ impl Token { "char" => Token::Char, "console" => Token::Console, "const" => Token::Const, + "constant" => Token::Constant, "else" => Token::Else, "false" => Token::False, "field" => Token::Field, diff --git a/compiler/parser/src/tokenizer/mod.rs b/compiler/parser/src/tokenizer/mod.rs index 2b99a86027..52309e06bd 100644 --- a/compiler/parser/src/tokenizer/mod.rs +++ b/compiler/parser/src/tokenizer/mod.rs @@ -183,8 +183,7 @@ mod tests { ? // test /* test */ - //"# - .into(), + //"#, ) .unwrap(); let mut output = String::new(); @@ -213,7 +212,7 @@ ppp test test */ test "#; - let tokens = tokenize("test_path", raw.into()).unwrap(); + let tokens = tokenize("test_path", raw).unwrap(); let mut line_indicies = vec![0]; for (i, c) in raw.chars().enumerate() { if c == '\n' { diff --git a/compiler/parser/src/tokenizer/token.rs b/compiler/parser/src/tokenizer/token.rs index 05862cb591..9d4164363a 100644 --- a/compiler/parser/src/tokenizer/token.rs +++ b/compiler/parser/src/tokenizer/token.rs @@ -116,6 +116,8 @@ pub enum Token { Console, /// Const variable and a const function. Const, + /// Constant parameter + Constant, Else, For, Function, @@ -180,6 +182,7 @@ impl Token { Token::Char => sym::char, Token::Console => sym::console, Token::Const => sym::Const, + Token::Constant => sym::Const, Token::Else => sym::Else, Token::False => sym::False, Token::Field => sym::field, @@ -281,6 +284,7 @@ impl fmt::Display for Token { Console => write!(f, "console"), Const => write!(f, "const"), + Constant => write!(f, "constant"), Else => write!(f, "else"), For => write!(f, "for"), Function => write!(f, "function"), diff --git a/leo/package/tests/manifest/manifest.rs b/leo/package/tests/manifest/manifest.rs index d58fce5150..a00743a8bb 100644 --- a/leo/package/tests/manifest/manifest.rs +++ b/leo/package/tests/manifest/manifest.rs @@ -68,7 +68,7 @@ fn read_manifest_file(path: &Path) -> String { /// Read the manifest file and check that the remote format is updated. fn remote_is_updated(path: &Path) -> bool { - let manifest_string = read_manifest_file(&path); + let manifest_string = read_manifest_file(path); for line in manifest_string.lines() { if line.starts_with("remote") { return false; @@ -80,7 +80,7 @@ fn remote_is_updated(path: &Path) -> bool { /// Read the manifest file and check that the project format is updated. fn project_is_updated(path: &Path) -> bool { - let manifest_string = read_manifest_file(&path); + let manifest_string = read_manifest_file(path); !manifest_string.contains(OLD_PROJECT_FORMAT) && manifest_string.contains(NEW_PROJECT_FORMAT) } diff --git a/leo/span/src/symbol.rs b/leo/span/src/symbol.rs index 095f0f83b6..a051db60c5 100644 --- a/leo/span/src/symbol.rs +++ b/leo/span/src/symbol.rs @@ -111,6 +111,7 @@ symbols! { CoreFunction, console, Const: "const", + Constant, Else: "else", error, False: "false", diff --git a/tests/expectations/parser/parser/functions/bounded_recursion.leo.out b/tests/expectations/parser/parser/functions/bounded_recursion.leo.out index a788043e32..b26580013a 100644 --- a/tests/expectations/parser/parser/functions/bounded_recursion.leo.out +++ b/tests/expectations/parser/parser/functions/bounded_recursion.leo.out @@ -5,21 +5,21 @@ outputs: - name: "" expected_input: [] functions: - "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const y: u32) {\\\"}\"}": - identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const y: u32) {\\\"}\"}" + "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(constant y: u32) {\\\"}\"}": + identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(constant y: u32) {\\\"}\"}" input: - Variable: - identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const y: u32) {\\\"}\"}" - mode: Const + identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":21,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(constant y: u32) {\\\"}\"}" + mode: Constant type_: IntegerType: U32 span: line_start: 3 line_stop: 3 - col_start: 18 - col_stop: 19 + col_start: 21 + col_stop: 22 path: "" - content: "function x(const y: u32) {" + content: "function x(constant y: u32) {" const_: false output: ~ core_mapping: ~ @@ -112,17 +112,17 @@ outputs: span: line_start: 3 line_stop: 7 - col_start: 26 + col_start: 29 col_stop: 2 path: "" - content: "function x(const y: u32) {\n ...\n ...\n ...\n}" + content: "function x(constant y: u32) {\n ...\n ...\n ...\n}" span: line_start: 3 line_stop: 7 col_start: 1 col_stop: 2 path: "" - content: "function x(const y: u32) {\n ...\n ...\n ...\n}" + content: "function x(constant y: u32) {\n ...\n ...\n ...\n}" "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(y: bool) -> bool {\\\"}\"}": identifier: "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(y: bool) -> bool {\\\"}\"}" input: diff --git a/tests/expectations/parser/parser/functions/const_input_fail.leo.out b/tests/expectations/parser/parser/functions/const_input_fail.leo.out index d0d34e7510..0ed857b27c 100644 --- a/tests/expectations/parser/parser/functions/const_input_fail.leo.out +++ b/tests/expectations/parser/parser/functions/const_input_fail.leo.out @@ -2,4 +2,4 @@ namespace: Parse expectation: Fail outputs: - - "Error [EPAR0370009]: unexpected string: expected 'ident', got 'input'\n --> test:3:18\n |\n 3 | function x(const input) {\n | ^^^^^" + - "Error [EPAR0370009]: unexpected string: expected 'ident', got 'const'\n --> test:3:12\n |\n 3 | function x(const input) {\n | ^^^^^" diff --git a/tests/expectations/parser/parser/functions/const_param.leo.out b/tests/expectations/parser/parser/functions/const_param.leo.out index 7d45b0007a..c88d7684b1 100644 --- a/tests/expectations/parser/parser/functions/const_param.leo.out +++ b/tests/expectations/parser/parser/functions/const_param.leo.out @@ -5,11 +5,11 @@ outputs: - name: "" expected_input: [] functions: - "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, const y: i32) {\\\"}\"}": - identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, const y: i32) {\\\"}\"}" + "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, constant y: i32) {\\\"}\"}": + identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, constant y: i32) {\\\"}\"}" input: - 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) {\\\"}\"}" + identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":12,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, constant y: i32) {\\\"}\"}" mode: Private type_: IntegerType: U32 @@ -19,19 +19,19 @@ outputs: col_start: 12 col_stop: 13 path: "" - content: "function x(x: u32, const y: i32) {" + content: "function x(x: u32, constant y: i32) {" - 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) {\\\"}\"}" - mode: Const + identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":29,\\\"col_stop\\\":30,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, constant y: i32) {\\\"}\"}" + mode: Constant type_: IntegerType: I32 span: line_start: 3 line_stop: 3 - col_start: 26 - col_stop: 27 + col_start: 29 + col_stop: 30 path: "" - content: "function x(x: u32, const y: i32) {" + content: "function x(x: u32, constant y: i32) {" const_: false output: ~ core_mapping: ~ @@ -59,44 +59,44 @@ outputs: span: line_start: 3 line_stop: 5 - col_start: 34 + col_start: 37 col_stop: 2 path: "" - content: "function x(x: u32, const y: i32) {\n ...\n}" + content: "function x(x: u32, constant y: i32) {\n ...\n}" span: line_start: 3 line_stop: 5 col_start: 1 col_stop: 2 path: "" - content: "function x(x: u32, const y: i32) {\n ...\n}" - "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const x: u32, y: i32) {\\\"}\"}": - identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const x: u32, y: i32) {\\\"}\"}" + content: "function x(x: u32, constant y: i32) {\n ...\n}" + "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(constant x: u32, y: i32) {\\\"}\"}": + identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(constant x: u32, y: i32) {\\\"}\"}" input: - 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) {\\\"}\"}" - mode: Const + identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":21,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(constant x: u32, y: i32) {\\\"}\"}" + mode: Constant type_: IntegerType: U32 span: line_start: 7 line_stop: 7 - col_start: 18 - col_stop: 19 + col_start: 21 + col_stop: 22 path: "" - content: "function x(const x: u32, y: i32) {" + content: "function x(constant x: u32, y: i32) {" - 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) {\\\"}\"}" + identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":29,\\\"col_stop\\\":30,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(constant x: u32, y: i32) {\\\"}\"}" mode: Private type_: IntegerType: I32 span: line_start: 7 line_stop: 7 - col_start: 26 - col_stop: 27 + col_start: 29 + col_stop: 30 path: "" - content: "function x(const x: u32, y: i32) {" + content: "function x(constant x: u32, y: i32) {" const_: false output: ~ core_mapping: ~ @@ -124,14 +124,14 @@ outputs: span: line_start: 7 line_stop: 9 - col_start: 34 + col_start: 37 col_stop: 2 path: "" - content: "function x(const x: u32, y: i32) {\n ...\n}" + content: "function x(constant x: u32, y: i32) {\n ...\n}" span: line_start: 7 line_stop: 9 col_start: 1 col_stop: 2 path: "" - content: "function x(const x: u32, y: i32) {\n ...\n}" + content: "function x(constant x: u32, y: i32) {\n ...\n}" diff --git a/tests/expectations/parser/parser/functions/const_public_param_fail.leo.out b/tests/expectations/parser/parser/functions/const_public_param_fail.leo.out index 24c32456b2..b0b6b50cde 100644 --- a/tests/expectations/parser/parser/functions/const_public_param_fail.leo.out +++ b/tests/expectations/parser/parser/functions/const_public_param_fail.leo.out @@ -2,4 +2,4 @@ namespace: Parse expectation: Fail outputs: - - "Error [EPAR0370009]: unexpected string: expected 'ident', got 'public'\n --> test:3:26\n |\n 3 | function x(x: u32, const public y: i32) {\n | ^^^^^^" + - "Error [EPAR0370009]: unexpected string: expected 'ident', got 'const'\n --> test:3:20\n |\n 3 | function x(x: u32, const public y: i32) {\n | ^^^^^" diff --git a/tests/expectations/parser/parser/functions/public_const_param_fail.leo.out b/tests/expectations/parser/parser/functions/public_const_param_fail.leo.out index 98cce4b400..2c19755651 100644 --- a/tests/expectations/parser/parser/functions/public_const_param_fail.leo.out +++ b/tests/expectations/parser/parser/functions/public_const_param_fail.leo.out @@ -2,4 +2,4 @@ namespace: Parse expectation: Fail outputs: - - "Error [EPAR0370041]: A parameter cannot be both public and const.\n --> test:3:20\n |\n 3 | function x(x: u32, public const y: i32) {\n | ^^^^^^^^^^^^" + - "Error [EPAR0370009]: unexpected string: expected 'ident', got 'const'\n --> test:3:27\n |\n 3 | function x(x: u32, public const y: i32) {\n | ^^^^^" diff --git a/tests/expectations/parser/parser/inputs/input_const.leo.out b/tests/expectations/parser/parser/inputs/input_const.leo.out index ad0b1a231a..aa63f60951 100644 --- a/tests/expectations/parser/parser/inputs/input_const.leo.out +++ b/tests/expectations/parser/parser/inputs/input_const.leo.out @@ -5,9 +5,9 @@ outputs: - sections: - name: main definitions: - - mode: Const + - mode: Constant type_: Boolean - name: "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const a: bool = true; \\\"}\"}" + name: "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"constant a: bool = true; \\\"}\"}" value: Value: Boolean: @@ -15,21 +15,21 @@ outputs: - span: line_start: 4 line_stop: 4 - col_start: 18 - col_stop: 22 + col_start: 21 + col_stop: 25 path: "" - content: "const a: bool = true; " + content: "constant a: bool = true; " span: line_start: 4 line_stop: 4 - col_start: 10 - col_stop: 14 + col_start: 13 + col_stop: 17 path: "" - content: "const a: bool = true; " - - mode: Const + content: "constant a: bool = true; " + - mode: Constant 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; \\\"}\"}" + name: "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"constant b: u8 = 2; \\\"}\"}" value: Value: Implicit: @@ -37,20 +37,20 @@ outputs: - span: line_start: 5 line_stop: 5 - col_start: 18 - col_stop: 19 + col_start: 21 + col_stop: 22 path: "" - content: "const b: u8 = 2; " + content: "constant b: u8 = 2; " span: line_start: 5 line_stop: 5 - col_start: 10 - col_stop: 12 + col_start: 13 + col_stop: 15 path: "" - content: "const b: u8 = 2; " - - mode: Const + content: "constant b: u8 = 2; " + - mode: Constant type_: Field - name: "{\"name\":\"c\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const c: field = 0; \\\"}\"}" + name: "{\"name\":\"c\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"constant c: field = 0; \\\"}\"}" value: Value: Implicit: @@ -58,20 +58,20 @@ outputs: - span: line_start: 6 line_stop: 6 - col_start: 18 - col_stop: 19 + col_start: 21 + col_stop: 22 path: "" - content: "const c: field = 0; " + content: "constant c: field = 0; " span: line_start: 6 line_stop: 6 - col_start: 10 - col_stop: 15 + col_start: 13 + col_stop: 18 path: "" - content: "const c: field = 0; " - - mode: Const + content: "constant c: field = 0; " + - mode: Constant 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; \\\"}\"}" + name: "{\"name\":\"d\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"constant d: group = (0, 1)group; \\\"}\"}" value: Value: Group: @@ -82,37 +82,37 @@ outputs: - span: line_start: 7 line_stop: 7 - col_start: 19 - col_stop: 20 + col_start: 22 + col_stop: 23 path: "" - content: "const d: group = (0, 1)group; " + content: "constant d: group = (0, 1)group; " y: Number: - "1" - span: line_start: 7 line_stop: 7 - col_start: 22 - col_stop: 23 + col_start: 25 + col_stop: 26 path: "" - content: "const d: group = (0, 1)group; " + content: "constant d: group = (0, 1)group; " span: line_start: 7 line_stop: 7 - col_start: 19 - col_stop: 29 + col_start: 22 + col_stop: 32 path: "" - content: "const d: group = (0, 1)group; " + content: "constant d: group = (0, 1)group; " span: line_start: 7 line_stop: 7 - col_start: 10 - col_stop: 15 + col_start: 13 + col_stop: 18 path: "" - content: "const d: group = (0, 1)group; " - - mode: Const + content: "constant d: group = (0, 1)group; " + - mode: Constant type_: Address - name: "{\"name\":\"e\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}" + name: "{\"name\":\"e\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"constant e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}" value: Value: Address: @@ -120,17 +120,17 @@ outputs: - span: line_start: 8 line_stop: 8 - col_start: 20 - col_stop: 83 + col_start: 23 + col_stop: 86 path: "" - content: "const e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + content: "constant e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" span: line_start: 8 line_stop: 8 - col_start: 10 - col_stop: 17 + col_start: 13 + col_stop: 20 path: "" - content: "const e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + content: "constant e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" span: line_start: 3 line_stop: 3 diff --git a/tests/expectations/parser/parser/inputs/input_const_public_fail.leo.out b/tests/expectations/parser/parser/inputs/input_const_public_fail.leo.out index c06dc8bb66..f618c2ebbb 100644 --- a/tests/expectations/parser/parser/inputs/input_const_public_fail.leo.out +++ b/tests/expectations/parser/parser/inputs/input_const_public_fail.leo.out @@ -2,4 +2,4 @@ namespace: Input expectation: Fail outputs: - - "Error [EPAR0370009]: unexpected string: expected 'ident', got 'public'\n --> test:4:7\n |\n 4 | const public a: bool = true; \n | ^^^^^^" + - "Error [EPAR0370009]: unexpected string: expected 'ident', got 'public'\n --> test:4:10\n |\n 4 | constant public a: bool = true; \n | ^^^^^^" diff --git a/tests/expectations/parser/parser/inputs/input_public_const_fail.leo.out b/tests/expectations/parser/parser/inputs/input_public_const_fail.leo.out index 410702f056..2060e85c72 100644 --- a/tests/expectations/parser/parser/inputs/input_public_const_fail.leo.out +++ b/tests/expectations/parser/parser/inputs/input_public_const_fail.leo.out @@ -2,4 +2,4 @@ namespace: Input expectation: Fail outputs: - - "Error [EPAR0370041]: A parameter cannot be both public and const.\n --> test:4:1\n |\n 4 | public const a: bool = true; \n | ^^^^^^^^^^^^" + - "Error [EPAR0370041]: A parameter cannot be both public and const.\n --> test:4:1\n |\n 4 | public constant a: bool = true; \n | ^^^^^^^^^^^^^^^" diff --git a/tests/parser/functions/bounded_recursion.leo b/tests/parser/functions/bounded_recursion.leo index 6ca5a10f4e..44465998a0 100644 --- a/tests/parser/functions/bounded_recursion.leo +++ b/tests/parser/functions/bounded_recursion.leo @@ -3,7 +3,7 @@ namespace: Parse expectation: Pass */ -function x(const y: u32) { +function x(constant y: u32) { if y < 5u32 { x(y+1); } diff --git a/tests/parser/functions/const_input_fail.leo b/tests/parser/functions/const_input_fail.leo index 2b4c0b69a6..ac4b998021 100644 --- a/tests/parser/functions/const_input_fail.leo +++ b/tests/parser/functions/const_input_fail.leo @@ -5,4 +5,8 @@ expectation: Fail function x(const input) { return (); +} + +function y(constant input) { + return (); } \ No newline at end of file diff --git a/tests/parser/functions/const_param.leo b/tests/parser/functions/const_param.leo index a69f08e3d7..19407f1b46 100644 --- a/tests/parser/functions/const_param.leo +++ b/tests/parser/functions/const_param.leo @@ -3,10 +3,10 @@ namespace: Parse expectation: Pass */ -function x(x: u32, const y: i32) { +function x(x: u32, constant y: i32) { return 0; } -function x(const x: u32, y: i32) { +function x(constant x: u32, y: i32) { return 0; } \ No newline at end of file diff --git a/tests/parser/functions/const_public_param_fail.leo b/tests/parser/functions/const_public_param_fail.leo index 9d91630c72..1085d25358 100644 --- a/tests/parser/functions/const_public_param_fail.leo +++ b/tests/parser/functions/const_public_param_fail.leo @@ -7,6 +7,6 @@ function x(x: u32, const public y: i32) { return 0; } -function x(const public x: u32, y: i32) { +function x(constant public x: u32, y: i32) { return 0; } \ No newline at end of file diff --git a/tests/parser/functions/public_const_param_fail.leo b/tests/parser/functions/public_const_param_fail.leo index d9bc818a6d..a40b6e175f 100644 --- a/tests/parser/functions/public_const_param_fail.leo +++ b/tests/parser/functions/public_const_param_fail.leo @@ -7,6 +7,6 @@ function x(x: u32, public const y: i32) { return 0; } -function x(public const x: u32, y: i32) { +function x(public constant x: u32, y: i32) { return 0; } \ No newline at end of file diff --git a/tests/parser/inputs/input_const.leo b/tests/parser/inputs/input_const.leo index 8db7f767ff..5a72f3f754 100644 --- a/tests/parser/inputs/input_const.leo +++ b/tests/parser/inputs/input_const.leo @@ -4,11 +4,11 @@ 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; +constant a: bool = true; +constant b: u8 = 2; +constant c: field = 0; +constant d: group = (0, 1)group; +constant e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; [registers] r0: bool = true; diff --git a/tests/parser/inputs/input_const_public_fail.leo b/tests/parser/inputs/input_const_public_fail.leo index d9721dd77b..5e892b9795 100644 --- a/tests/parser/inputs/input_const_public_fail.leo +++ b/tests/parser/inputs/input_const_public_fail.leo @@ -4,11 +4,11 @@ expectation: Fail */ [main] -const public a: bool = true; -const public b: u8 = 2; -const public c: field = 0; -const public d: group = (0, 1)group; -const public e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; +constant public a: bool = true; +constant public b: u8 = 2; +constant public c: field = 0; +constant public d: group = (0, 1)group; +constant public e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; [registers] r0: bool = true; diff --git a/tests/parser/inputs/input_public_const_fail.leo b/tests/parser/inputs/input_public_const_fail.leo index b775eb9c51..bce42f3e53 100644 --- a/tests/parser/inputs/input_public_const_fail.leo +++ b/tests/parser/inputs/input_public_const_fail.leo @@ -4,11 +4,11 @@ expectation: Fail */ [main] -public const a: bool = true; -public const b: u8 = 2; -public const c: field = 0; -public const d: group = (0, 1)group; -public const e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; +public constant a: bool = true; +public constant b: u8 = 2; +public constant c: field = 0; +public constant d: group = (0, 1)group; +public constant e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; [registers] r0: bool = true; From 304044546ce1ab5bb73a2d29e026a502f3c1721e Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Mon, 11 Apr 2022 10:01:54 -0700 Subject: [PATCH 2/6] add constant keyword to grammar, change parameter grammar --- docs/grammar/README.md | Bin 22302 -> 46382 bytes docs/grammar/abnf-grammar.txt | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/grammar/README.md b/docs/grammar/README.md index f8edf344cdd8765d1ba507cf20bf2e503283d831..891e76c7fdb2e39c30e5085ef5457567207b7d92 100644 GIT binary patch literal 46382 zcmeHQ`Ey*w5uTq@mH%P0DF@qOeaNvLK#+2T?WD>9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gx*0J-bhhd-MYm z-;{Jk5_d2#q>X#=4v4Cp;SNAL$LB4tX6dpqzsd{zzd4U~>mRHqVG_!=ZtSP&Je`C-pJ%nJQ=v(Q;y;!_=(Q$wj9PQ?CpgRbq1&l` Date: Tue, 12 Apr 2022 11:46:35 -0700 Subject: [PATCH 3/6] allow const but throw a recoverable error --- compiler/parser/src/parser/file.rs | 10 + compiler/parser/src/parser/input.rs | 2 +- leo/errors/src/parser/parser_errors.rs | 8 + .../parser/functions/const_input_fail.leo.out | 2 +- .../functions/const_public_param_fail.leo.out | 2 +- .../functions/public_const_param_fail.leo.out | 2 +- .../parser/parser/inputs/input_const.leo.out | 274 +---------------- .../parser/inputs/input_constant.leo.out | 275 ++++++++++++++++++ .../inputs/input_constant_public_fail.leo.out | 5 + .../inputs/input_public_const_fail.leo.out | 2 +- .../inputs/input_public_constant_fail.leo.out | 5 + tests/parser/inputs/input_const.leo | 20 +- tests/parser/inputs/input_constant.leo | 18 ++ ...ail.leo => input_constant_public_fail.leo} | 0 .../parser/inputs/input_public_const_fail.leo | 19 -- .../inputs/input_public_constant_fail.leo | 19 ++ 16 files changed, 357 insertions(+), 306 deletions(-) create mode 100644 tests/expectations/parser/parser/inputs/input_constant.leo.out create mode 100644 tests/expectations/parser/parser/inputs/input_constant_public_fail.leo.out create mode 100644 tests/expectations/parser/parser/inputs/input_public_constant_fail.leo.out create mode 100644 tests/parser/inputs/input_constant.leo rename tests/parser/inputs/{input_const_public_fail.leo => input_constant_public_fail.leo} (100%) delete mode 100644 tests/parser/inputs/input_public_const_fail.leo create mode 100644 tests/parser/inputs/input_public_constant_fail.leo diff --git a/compiler/parser/src/parser/file.rs b/compiler/parser/src/parser/file.rs index fcfd1a1713..33cbf9e0d2 100644 --- a/compiler/parser/src/parser/file.rs +++ b/compiler/parser/src/parser/file.rs @@ -67,10 +67,20 @@ impl ParserContext<'_> { pub fn parse_function_parameter_mode(&mut self) -> Result { let public = self.eat(Token::Public); let constant = self.eat(Token::Constant); + let const_ = self.eat(Token::Const); + + if const_.is_some() { + dbg!(&const_.as_ref().unwrap().span); + self.emit_err(ParserError::const_parameter_or_input(&const_.as_ref().unwrap().span)); + } match (public, constant) { (None, Some(_)) => Ok(ParamMode::Constant), + (None, None) if const_.is_some() => Ok(ParamMode::Constant), (None, None) => Ok(ParamMode::Private), + (Some(p), None) if const_.is_some() => { + Err(ParserError::inputs_multiple_variable_types_specified(&(p.span + const_.unwrap().span)).into()) + } (Some(_), None) => Ok(ParamMode::Public), (Some(p), Some(c)) => Err(ParserError::inputs_multiple_variable_types_specified(&(p.span + c.span)).into()), } diff --git a/compiler/parser/src/parser/input.rs b/compiler/parser/src/parser/input.rs index e0f1a3ec37..afdcf3d7b4 100644 --- a/compiler/parser/src/parser/input.rs +++ b/compiler/parser/src/parser/input.rs @@ -49,7 +49,7 @@ impl ParserContext<'_> { let mut definitions = Vec::new(); while let Some(SpannedToken { - token: Token::Constant | Token::Public | Token::Ident(_), + token: Token::Const | Token::Constant | Token::Public | Token::Ident(_), .. }) = self.peek_option() { diff --git a/leo/errors/src/parser/parser_errors.rs b/leo/errors/src/parser/parser_errors.rs index 217e305152..741f7ccd9b 100644 --- a/leo/errors/src/parser/parser_errors.rs +++ b/leo/errors/src/parser/parser_errors.rs @@ -366,4 +366,12 @@ create_errors!( msg: "A parameter cannot be both public and const.", help: None, } + + /// For when a user used const on a parameter or input instead of constant. + @formatted + const_parameter_or_input { + args: (), + msg: "`constant` is preferred over `const` for function parameters to indicate a R1CS constant.", + help: None, + } ); diff --git a/tests/expectations/parser/parser/functions/const_input_fail.leo.out b/tests/expectations/parser/parser/functions/const_input_fail.leo.out index 0ed857b27c..309a679337 100644 --- a/tests/expectations/parser/parser/functions/const_input_fail.leo.out +++ b/tests/expectations/parser/parser/functions/const_input_fail.leo.out @@ -2,4 +2,4 @@ namespace: Parse expectation: Fail outputs: - - "Error [EPAR0370009]: unexpected string: expected 'ident', got 'const'\n --> test:3:12\n |\n 3 | function x(const input) {\n | ^^^^^" + - "Error [EPAR0370042]: `constant` is preferred over `const` for function parameters to indicate a R1CS constant.\n --> test:3:12\n |\n 3 | function x(const input) {\n | ^^^^^\nError [EPAR0370009]: unexpected string: expected 'ident', got 'input'\n --> test:3:18\n |\n 3 | function x(const input) {\n | ^^^^^" diff --git a/tests/expectations/parser/parser/functions/const_public_param_fail.leo.out b/tests/expectations/parser/parser/functions/const_public_param_fail.leo.out index b0b6b50cde..9b17602f02 100644 --- a/tests/expectations/parser/parser/functions/const_public_param_fail.leo.out +++ b/tests/expectations/parser/parser/functions/const_public_param_fail.leo.out @@ -2,4 +2,4 @@ namespace: Parse expectation: Fail outputs: - - "Error [EPAR0370009]: unexpected string: expected 'ident', got 'const'\n --> test:3:20\n |\n 3 | function x(x: u32, const public y: i32) {\n | ^^^^^" + - "Error [EPAR0370042]: `constant` is preferred over `const` for function parameters to indicate a R1CS constant.\n --> test:3:20\n |\n 3 | function x(x: u32, const public y: i32) {\n | ^^^^^\nError [EPAR0370009]: unexpected string: expected 'ident', got 'public'\n --> test:3:26\n |\n 3 | function x(x: u32, const public y: i32) {\n | ^^^^^^" diff --git a/tests/expectations/parser/parser/functions/public_const_param_fail.leo.out b/tests/expectations/parser/parser/functions/public_const_param_fail.leo.out index 2c19755651..cd850eadcb 100644 --- a/tests/expectations/parser/parser/functions/public_const_param_fail.leo.out +++ b/tests/expectations/parser/parser/functions/public_const_param_fail.leo.out @@ -2,4 +2,4 @@ namespace: Parse expectation: Fail outputs: - - "Error [EPAR0370009]: unexpected string: expected 'ident', got 'const'\n --> test:3:27\n |\n 3 | function x(x: u32, public const y: i32) {\n | ^^^^^" + - "Error [EPAR0370042]: `constant` is preferred over `const` for function parameters to indicate a R1CS constant.\n --> test:3:27\n |\n 3 | function x(x: u32, public const y: i32) {\n | ^^^^^\nError [EPAR0370041]: A parameter cannot be both public and const.\n --> test:3:20\n |\n 3 | function x(x: u32, public const y: i32) {\n | ^^^^^^^^^^^^" diff --git a/tests/expectations/parser/parser/inputs/input_const.leo.out b/tests/expectations/parser/parser/inputs/input_const.leo.out index aa63f60951..5d120639e3 100644 --- a/tests/expectations/parser/parser/inputs/input_const.leo.out +++ b/tests/expectations/parser/parser/inputs/input_const.leo.out @@ -1,275 +1,5 @@ --- namespace: Input -expectation: Pass +expectation: Fail outputs: - - sections: - - name: main - definitions: - - mode: Constant - type_: Boolean - name: "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"constant a: bool = true; \\\"}\"}" - value: - Value: - Boolean: - - "true" - - span: - line_start: 4 - line_stop: 4 - col_start: 21 - col_stop: 25 - path: "" - content: "constant a: bool = true; " - span: - line_start: 4 - line_stop: 4 - col_start: 13 - col_stop: 17 - path: "" - content: "constant a: bool = true; " - - mode: Constant - type_: - IntegerType: U8 - name: "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"constant b: u8 = 2; \\\"}\"}" - value: - Value: - Implicit: - - "2" - - span: - line_start: 5 - line_stop: 5 - col_start: 21 - col_stop: 22 - path: "" - content: "constant b: u8 = 2; " - span: - line_start: 5 - line_stop: 5 - col_start: 13 - col_stop: 15 - path: "" - content: "constant b: u8 = 2; " - - mode: Constant - type_: Field - name: "{\"name\":\"c\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"constant c: field = 0; \\\"}\"}" - value: - Value: - Implicit: - - "0" - - span: - line_start: 6 - line_stop: 6 - col_start: 21 - col_stop: 22 - path: "" - content: "constant c: field = 0; " - span: - line_start: 6 - line_stop: 6 - col_start: 13 - col_stop: 18 - path: "" - content: "constant c: field = 0; " - - mode: Constant - type_: Group - name: "{\"name\":\"d\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"constant d: group = (0, 1)group; \\\"}\"}" - value: - Value: - Group: - Tuple: - x: - Number: - - "0" - - span: - line_start: 7 - line_stop: 7 - col_start: 22 - col_stop: 23 - path: "" - content: "constant d: group = (0, 1)group; " - y: - Number: - - "1" - - span: - line_start: 7 - line_stop: 7 - col_start: 25 - col_stop: 26 - path: "" - content: "constant d: group = (0, 1)group; " - span: - line_start: 7 - line_stop: 7 - col_start: 22 - col_stop: 32 - path: "" - content: "constant d: group = (0, 1)group; " - span: - line_start: 7 - line_stop: 7 - col_start: 13 - col_stop: 18 - path: "" - content: "constant d: group = (0, 1)group; " - - mode: Constant - type_: Address - name: "{\"name\":\"e\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"constant e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}" - value: - Value: - Address: - - aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 - - span: - line_start: 8 - line_stop: 8 - col_start: 23 - col_stop: 86 - path: "" - content: "constant e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" - span: - line_start: 8 - line_stop: 8 - col_start: 13 - col_stop: 20 - path: "" - content: "constant e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" - span: - line_start: 3 - line_stop: 3 - col_start: 2 - col_stop: 6 - path: "" - content: "[main]" - - name: registers - definitions: - - mode: Private - 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; " - - mode: Private - 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; " - - mode: Private - 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; " - - mode: Private - 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; " - - mode: Private - 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]" + - "Error [EPAR0370042]: `constant` is preferred over `const` for function parameters to indicate a R1CS constant.\n --> test:4:1\n |\n 4 | const a: bool = true;\n | ^^^^^\nError [EPAR0370042]: `constant` is preferred over `const` for function parameters to indicate a R1CS constant.\n --> test:5:1\n |\n 5 | const b: u8 = 2;\n | ^^^^^\nError [EPAR0370042]: `constant` is preferred over `const` for function parameters to indicate a R1CS constant.\n --> test:6:1\n |\n 6 | const c: field = 0;\n | ^^^^^\nError [EPAR0370042]: `constant` is preferred over `const` for function parameters to indicate a R1CS constant.\n --> test:7:1\n |\n 7 | const d: group = (0, 1)group;\n | ^^^^^\nError [EPAR0370042]: `constant` is preferred over `const` for function parameters to indicate a R1CS constant.\n --> test:8:1\n |\n 8 | const e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\n | ^^^^^" diff --git a/tests/expectations/parser/parser/inputs/input_constant.leo.out b/tests/expectations/parser/parser/inputs/input_constant.leo.out new file mode 100644 index 0000000000..a206272bc7 --- /dev/null +++ b/tests/expectations/parser/parser/inputs/input_constant.leo.out @@ -0,0 +1,275 @@ +--- +namespace: Input +expectation: Pass +outputs: + - sections: + - name: main + definitions: + - mode: Constant + type_: Boolean + name: "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"constant a: bool = true;\\\"}\"}" + value: + Value: + Boolean: + - "true" + - span: + line_start: 4 + line_stop: 4 + col_start: 21 + col_stop: 25 + path: "" + content: "constant a: bool = true;" + span: + line_start: 4 + line_stop: 4 + col_start: 13 + col_stop: 17 + path: "" + content: "constant a: bool = true;" + - mode: Constant + type_: + IntegerType: U8 + name: "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"constant b: u8 = 2;\\\"}\"}" + value: + Value: + Implicit: + - "2" + - span: + line_start: 5 + line_stop: 5 + col_start: 21 + col_stop: 22 + path: "" + content: "constant b: u8 = 2;" + span: + line_start: 5 + line_stop: 5 + col_start: 13 + col_stop: 15 + path: "" + content: "constant b: u8 = 2;" + - mode: Constant + type_: Field + name: "{\"name\":\"c\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"constant c: field = 0;\\\"}\"}" + value: + Value: + Implicit: + - "0" + - span: + line_start: 6 + line_stop: 6 + col_start: 21 + col_stop: 22 + path: "" + content: "constant c: field = 0;" + span: + line_start: 6 + line_stop: 6 + col_start: 13 + col_stop: 18 + path: "" + content: "constant c: field = 0;" + - mode: Constant + type_: Group + name: "{\"name\":\"d\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"constant d: group = (0, 1)group;\\\"}\"}" + value: + Value: + Group: + Tuple: + x: + Number: + - "0" + - span: + line_start: 7 + line_stop: 7 + col_start: 22 + col_stop: 23 + path: "" + content: "constant d: group = (0, 1)group;" + y: + Number: + - "1" + - span: + line_start: 7 + line_stop: 7 + col_start: 25 + col_stop: 26 + path: "" + content: "constant d: group = (0, 1)group;" + span: + line_start: 7 + line_stop: 7 + col_start: 22 + col_stop: 32 + path: "" + content: "constant d: group = (0, 1)group;" + span: + line_start: 7 + line_stop: 7 + col_start: 13 + col_stop: 18 + path: "" + content: "constant d: group = (0, 1)group;" + - mode: Constant + type_: Address + name: "{\"name\":\"e\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"constant e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}" + value: + Value: + Address: + - aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 + - span: + line_start: 8 + line_stop: 8 + col_start: 23 + col_stop: 86 + path: "" + content: "constant e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + span: + line_start: 8 + line_stop: 8 + col_start: 13 + col_stop: 20 + path: "" + content: "constant e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;" + span: + line_start: 3 + line_stop: 3 + col_start: 2 + col_stop: 6 + path: "" + content: "[main]" + - name: registers + definitions: + - mode: Private + 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;" + - mode: Private + 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;" + - mode: Private + 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;" + - mode: Private + 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;" + - mode: Private + 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_constant_public_fail.leo.out b/tests/expectations/parser/parser/inputs/input_constant_public_fail.leo.out new file mode 100644 index 0000000000..f618c2ebbb --- /dev/null +++ b/tests/expectations/parser/parser/inputs/input_constant_public_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Input +expectation: Fail +outputs: + - "Error [EPAR0370009]: unexpected string: expected 'ident', got 'public'\n --> test:4:10\n |\n 4 | constant public a: bool = true; \n | ^^^^^^" diff --git a/tests/expectations/parser/parser/inputs/input_public_const_fail.leo.out b/tests/expectations/parser/parser/inputs/input_public_const_fail.leo.out index 2060e85c72..720d0d41dc 100644 --- a/tests/expectations/parser/parser/inputs/input_public_const_fail.leo.out +++ b/tests/expectations/parser/parser/inputs/input_public_const_fail.leo.out @@ -2,4 +2,4 @@ namespace: Input expectation: Fail outputs: - - "Error [EPAR0370041]: A parameter cannot be both public and const.\n --> test:4:1\n |\n 4 | public constant a: bool = true; \n | ^^^^^^^^^^^^^^^" + - "Error [EPAR0370041]: A parameter cannot be both public and const.\n --> test:4:1\n |\n 4 | public constant a: bool = true;\n | ^^^^^^^^^^^^^^^" diff --git a/tests/expectations/parser/parser/inputs/input_public_constant_fail.leo.out b/tests/expectations/parser/parser/inputs/input_public_constant_fail.leo.out new file mode 100644 index 0000000000..720d0d41dc --- /dev/null +++ b/tests/expectations/parser/parser/inputs/input_public_constant_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Input +expectation: Fail +outputs: + - "Error [EPAR0370041]: A parameter cannot be both public and const.\n --> test:4:1\n |\n 4 | public constant a: bool = true;\n | ^^^^^^^^^^^^^^^" diff --git a/tests/parser/inputs/input_const.leo b/tests/parser/inputs/input_const.leo index 5a72f3f754..bd7c15d93d 100644 --- a/tests/parser/inputs/input_const.leo +++ b/tests/parser/inputs/input_const.leo @@ -1,18 +1,18 @@ /* namespace: Input -expectation: Pass +expectation: Fail */ [main] -constant a: bool = true; -constant b: u8 = 2; -constant c: field = 0; -constant d: group = (0, 1)group; -constant e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; +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; +r0: bool = true; +r1: u8 = 2; +r2: field = 0; +r3: group = (0, 1)group; r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; diff --git a/tests/parser/inputs/input_constant.leo b/tests/parser/inputs/input_constant.leo new file mode 100644 index 0000000000..c14e72a52b --- /dev/null +++ b/tests/parser/inputs/input_constant.leo @@ -0,0 +1,18 @@ +/* +namespace: Input +expectation: Pass +*/ + +[main] +constant a: bool = true; +constant b: u8 = 2; +constant c: field = 0; +constant d: group = (0, 1)group; +constant 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_const_public_fail.leo b/tests/parser/inputs/input_constant_public_fail.leo similarity index 100% rename from tests/parser/inputs/input_const_public_fail.leo rename to tests/parser/inputs/input_constant_public_fail.leo diff --git a/tests/parser/inputs/input_public_const_fail.leo b/tests/parser/inputs/input_public_const_fail.leo deleted file mode 100644 index bce42f3e53..0000000000 --- a/tests/parser/inputs/input_public_const_fail.leo +++ /dev/null @@ -1,19 +0,0 @@ -/* -namespace: Input -expectation: Fail -*/ - -[main] -public constant a: bool = true; -public constant b: u8 = 2; -public constant c: field = 0; -public constant d: group = (0, 1)group; -public constant 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_constant_fail.leo b/tests/parser/inputs/input_public_constant_fail.leo new file mode 100644 index 0000000000..94325d2ef4 --- /dev/null +++ b/tests/parser/inputs/input_public_constant_fail.leo @@ -0,0 +1,19 @@ +/* +namespace: Input +expectation: Fail +*/ + +[main] +public constant a: bool = true; +public constant b: u8 = 2; +public constant c: field = 0; +public constant d: group = (0, 1)group; +public constant e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; + +[registers] +r0: bool = true; +r1: u8 = 2; +r2: field = 0; +r3: group = (0, 1)group; +r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; + From 168080942b42fe86c8cff0a5973c62e16e03707b Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Tue, 12 Apr 2022 11:52:12 -0700 Subject: [PATCH 4/6] better match pattern for catching more error situations --- compiler/parser/src/parser/file.rs | 25 ++++++++++++++++--------- docs/grammar/README.md | Bin 46382 -> 46406 bytes docs/grammar/abnf-grammar.txt | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/compiler/parser/src/parser/file.rs b/compiler/parser/src/parser/file.rs index 33cbf9e0d2..842f97b258 100644 --- a/compiler/parser/src/parser/file.rs +++ b/compiler/parser/src/parser/file.rs @@ -70,19 +70,26 @@ impl ParserContext<'_> { let const_ = self.eat(Token::Const); if const_.is_some() { - dbg!(&const_.as_ref().unwrap().span); self.emit_err(ParserError::const_parameter_or_input(&const_.as_ref().unwrap().span)); } - match (public, constant) { - (None, Some(_)) => Ok(ParamMode::Constant), - (None, None) if const_.is_some() => Ok(ParamMode::Constant), - (None, None) => Ok(ParamMode::Private), - (Some(p), None) if const_.is_some() => { - Err(ParserError::inputs_multiple_variable_types_specified(&(p.span + const_.unwrap().span)).into()) + match (public, constant, const_) { + (None, Some(_), None) => Ok(ParamMode::Constant), + (None, None, Some(_)) => Ok(ParamMode::Constant), + (None, None, None) => Ok(ParamMode::Private), + (Some(_), None, None) => Ok(ParamMode::Public), + (Some(p), None, Some(c)) => { + Err(ParserError::inputs_multiple_variable_types_specified(&(p.span + c.span)).into()) + } + (None, Some(c), Some(co)) => { + Err(ParserError::inputs_multiple_variable_types_specified(&(c.span + co.span)).into()) + } + (Some(p), Some(c), None) => { + Err(ParserError::inputs_multiple_variable_types_specified(&(p.span + c.span)).into()) + } + (Some(p), Some(c), Some(co)) => { + Err(ParserError::inputs_multiple_variable_types_specified(&(p.span + c.span + co.span)).into()) } - (Some(_), None) => Ok(ParamMode::Public), - (Some(p), Some(c)) => Err(ParserError::inputs_multiple_variable_types_specified(&(p.span + c.span)).into()), } } diff --git a/docs/grammar/README.md b/docs/grammar/README.md index 891e76c7fdb2e39c30e5085ef5457567207b7d92..5da5bbee20584cf0b129f9acc2fa7dd6ca8cb3b9 100644 GIT binary patch delta 18 acmZ4Yis{%ZrVTEuCabLy+3c|D9TxyvBnbBa delta 28 mcmV+%0OSA0>H@Cn0 Date: Tue, 12 Apr 2022 12:22:52 -0700 Subject: [PATCH 5/6] fix token and constant pairing --- compiler/parser/src/tokenizer/token.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/parser/src/tokenizer/token.rs b/compiler/parser/src/tokenizer/token.rs index 9d4164363a..e01607471d 100644 --- a/compiler/parser/src/tokenizer/token.rs +++ b/compiler/parser/src/tokenizer/token.rs @@ -182,7 +182,7 @@ impl Token { Token::Char => sym::char, Token::Console => sym::console, Token::Const => sym::Const, - Token::Constant => sym::Const, + Token::Constant => sym::Constant, Token::Else => sym::Else, Token::False => sym::False, Token::Field => sym::field, From ba993b3a839012751074134038fbc0bdfd9f430d Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Tue, 12 Apr 2022 13:13:02 -0700 Subject: [PATCH 6/6] match pattern cleanup --- compiler/parser/src/parser/file.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/compiler/parser/src/parser/file.rs b/compiler/parser/src/parser/file.rs index 842f97b258..d7d43ab0b5 100644 --- a/compiler/parser/src/parser/file.rs +++ b/compiler/parser/src/parser/file.rs @@ -78,17 +78,11 @@ impl ParserContext<'_> { (None, None, Some(_)) => Ok(ParamMode::Constant), (None, None, None) => Ok(ParamMode::Private), (Some(_), None, None) => Ok(ParamMode::Public), - (Some(p), None, Some(c)) => { - Err(ParserError::inputs_multiple_variable_types_specified(&(p.span + c.span)).into()) + (Some(m1), Some(m2), None) | (Some(m1), None, Some(m2)) | (None, Some(m1), Some(m2)) => { + Err(ParserError::inputs_multiple_variable_types_specified(&(m1.span + m2.span)).into()) } - (None, Some(c), Some(co)) => { - Err(ParserError::inputs_multiple_variable_types_specified(&(c.span + co.span)).into()) - } - (Some(p), Some(c), None) => { - Err(ParserError::inputs_multiple_variable_types_specified(&(p.span + c.span)).into()) - } - (Some(p), Some(c), Some(co)) => { - Err(ParserError::inputs_multiple_variable_types_specified(&(p.span + c.span + co.span)).into()) + (Some(m1), Some(m2), Some(m3)) => { + Err(ParserError::inputs_multiple_variable_types_specified(&(m1.span + m2.span + m3.span)).into()) } } }