@@ -26,32 +26,56 @@ pub Top: ast::Mod = {
2626};
2727
2828Program: ast::Suite = {
29- <lines:FileLine*> => {
30- lines.into_iter().flatten().collect()
29+ => vec![],
30+ // Compound statements
31+ <mut statements:Program> <next:CompoundStatement> => {
32+ statements.push(next);
33+ statements
34+ },
35+
36+ // Small statements
37+ <mut statements:Program> <small:(<SmallStatement> ";")*> <last:SmallStatement> ";"? "\n" => {
38+ statements.extend(small);
39+ statements.push(last);
40+ statements
3141 },
32- };
3342
34- // A file line either has a declaration, or an empty newline:
35- FileLine: ast::Suite = {
36- Statement,
37- "\n" => vec![],
43+ // Empty lines
44+ <s:Program> "\n" => s,
3845};
3946
4047Suite: ast::Suite = {
41- SimpleStatement,
42- "\n" Indent <s:Statement+> Dedent => s.into_iter().flatten().collect(),
48+ <mut statements:(<SmallStatement> ";")*> <last:SmallStatement> ";"? "\n" => {
49+ statements.push(last);
50+ statements
51+ },
52+ "\n" Indent <s:Statements> Dedent => s,
4353};
4454
45- Statement: ast::Suite = {
46- SimpleStatement,
55+
56+ // One or more statements
57+ Statements: Vec<ast::Stmt> = {
58+ // First simple statement
59+ <mut head:(<SmallStatement> ";")*> <last:SmallStatement> ";"? "\n" => {
60+ head.push(last);
61+ head
62+ },
63+
64+ // The first compound statement
4765 <s:CompoundStatement> => vec![s],
48- };
4966
50- SimpleStatement: ast::Suite = {
51- <mut statements:(<SmallStatement> ";")*> <last:SmallStatement> ";"? "\n" => {
67+ // Any subsequent compound statements
68+ <mut statements:Statements> <next:CompoundStatement> => {
69+ statements.push(next);
70+ statements
71+ },
72+
73+ // Any subsequent small statements
74+ <mut statements:Statements> <small:(<SmallStatement> ";")*> <last:SmallStatement> ";"? "\n" => {
75+ statements.extend(small);
5276 statements.push(last);
5377 statements
54- }
78+ },
5579};
5680
5781SmallStatement: ast::Stmt = {
0 commit comments