Skip to content

Commit d532ea5

Browse files
Add structs to parser
1 parent beb02ef commit d532ea5

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

src/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ mod tests {
229229

230230
// create fileid and read file
231231
let input =
232-
std::fs::read_to_string("tests/calyx_go_doneStruct.prot").expect("failed to load");
232+
std::fs::read_to_string("tests/calyx_go_done_struct.prot").expect("failed to load");
233233
let calyx_fileid = handler.add_file("calyx_go_done.prot".to_string(), input);
234234

235235
// 2) create transaction

src/parser.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,18 @@ mod tests {
7272
parse_file("tests/mul.prot");
7373
}
7474

75+
#[test]
76+
fn test_easycond_prot() {
77+
parse_file("tests/cond.prot");
78+
}
79+
7580
#[test]
7681
fn test_cond_prot() {
7782
parse_file("tests/cond.prot");
7883
}
84+
85+
#[test]
86+
fn test_calyx_go_done_struct_prot() {
87+
parse_file("tests/calyx_go_done_struct.prot");
88+
}
7989
}

src/protocols.pest

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ cmd = { path_id ~ "(" ~ ")" ~ ";"}
4444
stmt = _{ (assign | cmd | while | cond) }
4545
dir = _{"in" | "out" }
4646
arg = { dir ~ id ~ ":" ~ tpe }
47-
arglist = { (arg ~ "," ~ arglist) | arg }
47+
arglist = { (arg ~ "," ~ arglist) | arg ~ ","? }
48+
type_param = { "<" ~ id ~ ":" ~ id ~ ">" }
4849

4950
// Loops
5051
while = { "while" ~ expr ~ "{" ~ stmt* ~ "}" }
@@ -55,5 +56,8 @@ else_if = { "else" ~ "if" ~ expr ~ "{" ~ stmt* ~ "}"}
5556
else = { "else" ~ "{" ~ stmt* ~ "}" }
5657
cond = { if ~ else_if* ~ else? }
5758

58-
fun = { "fn" ~ id ~ "(" ~ arglist ~ ")" ~ "{" ~ stmt* ~ "}" }
59-
file = { SOI ~ fun* ~ EOI }
59+
// Structs
60+
struct = { "struct" ~ id ~ "{" ~ arglist? ~ "}" }
61+
62+
fun = { "fn" ~ id ~ type_param? ~ "(" ~ arglist ~ ")" ~ "{" ~ stmt* ~ "}" }
63+
file = { SOI ~ (fun | struct)* ~ EOI }

src/typecheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ mod tests {
171171

172172
// create fileid and read file
173173
let input =
174-
std::fs::read_to_string("tests/calyx_go_doneStruct.prot").expect("failed to load");
174+
std::fs::read_to_string("tests/calyx_go_done_struct.prot").expect("failed to load");
175175
let calyx_fileid = handler.add_file("calyx_go_done.prot".to_string(), input);
176176

177177
// 2) create transaction

0 commit comments

Comments
 (0)