Merge pull request #233 from AleoHQ/feature/flexible-function-def

allow newlines and trailing commas in function declarations
This commit is contained in:
Howard Wu 2020-08-15 00:46:43 -07:00 committed by GitHub
commit 93b4634cad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 2 deletions

View File

@ -191,7 +191,7 @@ type_circuit = { identifier }
// Declared in types/array_type.rs
type_array = { type_data ~ ("[" ~ number_positive ~ "]")+ }
type_tuple = { "(" ~ type_ ~ ("," ~ type_)+ ~ ")" }
type_tuple = { "(" ~ NEWLINE* ~ type_ ~ ("," ~ NEWLINE* ~ type_)+ ~ ","? ~ NEWLINE* ~ ")" }
/// Values
@ -381,7 +381,7 @@ input = {
function_input
| input_keyword
}
input_tuple = _{ "(" ~(input ~ ("," ~ NEWLINE* ~ input)*)? ~ ")"}
input_tuple = _{ "(" ~ NEWLINE* ~ (input ~ ("," ~ NEWLINE* ~ input)* ~ ","?)? ~ NEWLINE* ~ ")"}
/// Imports

View File

@ -0,0 +1,7 @@
[main]
a: u32 = 0;
b: u32 = 0;
[registers]
a: u32 = 0;
b: u32 = 0;

View File

@ -41,6 +41,20 @@ fn test_iteration_repeated() {
assert_satisfied(program);
}
#[test]
fn test_newlines() {
let input_bytes = include_bytes!("input/newlines.in");
let program_bytes = include_bytes!("newlines.leo");
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
let expected_bytes = include_bytes!("output_/newlines.out");
let expected = std::str::from_utf8(expected_bytes).unwrap();
let actual_bytes = get_output(program);
let actual = std::str::from_utf8(actual_bytes.bytes().as_slice()).unwrap();
assert_eq!(expected, actual);
}
#[test]
fn test_multiple_returns() {
let bytes = include_bytes!("multiple.leo");

View File

@ -0,0 +1,9 @@
function main(
a: u32,
b: u32,
) -> (
u32,
u32,
) {
return (a, b)
}

View File

@ -0,0 +1,3 @@
[registers]
a: u32 = 0u32;
b: u32 = 0u32;