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

change struct declaration syntax

This commit is contained in:
schaeff 2019-09-25 12:06:11 +02:00
parent 20f3a980fe
commit 47395d0b4b
7 changed files with 35 additions and 35 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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