1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00

change struct declaration syntax

This commit is contained in:
Thibaut 2019-09-28 18:24:29 +02:00
parent 20f3a980fe
commit 3b0b6959e3
7 changed files with 35 additions and 35 deletions

View file

@ -1,6 +1,6 @@
struct Bar { struct Bar {
field[2] c field[2] c
bool b bool d
} }
struct Foo { struct Foo {

View file

@ -1,6 +1,6 @@
struct Point { struct Point {
x: field, field x
y: field field y
} }
def main(Point p, Point q) -> (Point): def main(Point p, Point q) -> (Point):

View file

@ -1,11 +1,11 @@
struct Bar { struct Bar {
c: field[2], field[2] c
d: bool bool d
} }
struct Foo { struct Foo {
a: Bar, Bar a
b: bool bool b
} }
def main() -> (Foo): def main() -> (Foo):

View file

@ -1,6 +1,6 @@
struct A { struct A {
a: field, field a
b: bool bool b
} }
def main(A a) -> (A): def main(A a) -> (A):

View file

@ -149,40 +149,40 @@ mod tests {
fn parse_struct_def() { fn parse_struct_def() {
parses_to! { parses_to! {
parser: ZoKratesParser, parser: ZoKratesParser,
input: "struct Foo { foo: field, bar: field[2] } input: "struct Foo { field foo\n field[2] bar }
", ",
rule: Rule::ty_struct_definition, rule: Rule::ty_struct_definition,
tokens: [ tokens: [
ty_struct_definition(0, 41, [ ty_struct_definition(0, 39, [
identifier(7, 10), identifier(7, 10),
struct_field(13, 23, [ struct_field(13, 22, [
identifier(13, 16), ty(13, 18, [
ty(18, 23, [ ty_basic(13, 18, [
ty_basic(18, 23, [ ty_field(13, 18)
ty_field(18, 23)
]) ])
]) ]),
identifier(19, 22)
]), ]),
struct_field(25, 39, [ struct_field(24, 36, [
identifier(25, 28), ty(24, 33, [
ty(30, 39, [ ty_array(24, 33, [
ty_array(30, 39, [ ty_basic_or_struct(24, 29, [
ty_basic_or_struct(30, 35, [ ty_basic(24, 29, [
ty_basic(30, 35, [ ty_field(24, 29)
ty_field(30, 35)
]) ])
]), ]),
expression(36, 37, [ expression(30, 31, [
term(36, 37, [ term(30, 31, [
primary_expression(36, 37, [ primary_expression(30, 31, [
constant(36, 37, [ constant(30, 31, [
decimal_number(36, 37) decimal_number(30, 31)
]) ])
]) ])
]) ])
]) ])
]) ])
]) ]),
identifier(33, 36)
]) ])
]) ])
] ]

View file

@ -26,8 +26,8 @@ type_list = _{(ty ~ ("," ~ ty)*)?}
ty_struct = { identifier } ty_struct = { identifier }
// type definitions // type definitions
ty_struct_definition = { "struct" ~ identifier ~ "{" ~ NEWLINE* ~ struct_field_list ~ NEWLINE* ~ "}" ~ NEWLINE* } ty_struct_definition = { "struct" ~ identifier ~ "{" ~ NEWLINE* ~ struct_field_list ~ NEWLINE* ~ "}" ~ NEWLINE* }
struct_field_list = _{(struct_field ~ ("," ~ NEWLINE* ~ struct_field)*)? ~ ","? } struct_field_list = _{(struct_field ~ (NEWLINE+ ~ struct_field)*)? }
struct_field = { identifier ~ ":" ~ ty } struct_field = { ty ~ identifier }
vis_private = {"private"} vis_private = {"private"}
vis_public = {"public"} vis_public = {"public"}

View file

@ -178,8 +178,8 @@ mod ast {
#[derive(Debug, FromPest, PartialEq, Clone)] #[derive(Debug, FromPest, PartialEq, Clone)]
#[pest_ast(rule(Rule::struct_field))] #[pest_ast(rule(Rule::struct_field))]
pub struct StructField<'ast> { pub struct StructField<'ast> {
pub id: IdentifierExpression<'ast>,
pub ty: Type<'ast>, pub ty: Type<'ast>,
pub id: IdentifierExpression<'ast>,
#[pest_ast(outer())] #[pest_ast(outer())]
pub span: Span<'ast>, pub span: Span<'ast>,
} }
@ -1083,8 +1083,8 @@ mod tests {
let source = r#"import "heyman" as yo let source = r#"import "heyman" as yo
struct Foo { struct Foo {
foo: field[2], field[2] foo
bar: Bar Bar bar
} }
def main(private field[23] a) -> (bool[234 + 6]): def main(private field[23] a) -> (bool[234 + 6]):