allow newlines and trailing commas in function declarations

This commit is contained in:
collin 2020-08-15 00:25:11 -07:00
parent 1c8699696c
commit 3d794c6a20
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;