Skip to content

Commit

Permalink
fix test based on diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
xffxff committed Sep 26, 2023
1 parent a2f5965 commit 4ef0b09
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 119 deletions.
3 changes: 2 additions & 1 deletion components/lox-parse/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ impl<'me> Parser<'me> {
// "print" expression ";" ;
fn print_stmt(&mut self) -> Option<Stmt> {
let expr = self.parse_expr()?;
self.eat(Token::Semicolon);
self.eat(Token::Semicolon)
.or_report_error(self, || "expected `;`");
Some(Stmt::Print(expr))
}

Expand Down
8 changes: 4 additions & 4 deletions lox_tests/arithmetic.lox
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1 + 2
1 + 2;

1 + 2 * 3
1 + 2 * 3;

1 - 2 / 3
1 - 2 / 3;

1 + 2 * -3
1 + 2 * -3;
28 changes: 0 additions & 28 deletions lox_tests/arithmetic/output
Original file line number Diff line number Diff line change
@@ -1,28 +0,0 @@
Error: expected `;`
╭─[/home/zhoufan/workspace/lox/lox_tests/arithmetic.lox:3:1]
3 │ 1 + 2 * 3
│ ┬
│ ╰── here
───╯
Error: expected `;`
╭─[/home/zhoufan/workspace/lox/lox_tests/arithmetic.lox:5:1]
5 │ 1 - 2 / 3
│ ┬
│ ╰── here
───╯
Error: expected `;`
╭─[/home/zhoufan/workspace/lox/lox_tests/arithmetic.lox:7:1]
7 │ 1 + 2 * -3
│ ┬
│ ╰── here
───╯
Error: expected `;`
╭─[/home/zhoufan/workspace/lox/lox_tests/arithmetic.lox:7:10]
7 │ 1 + 2 * -3
│ ┬
│ ╰── here
───╯
6 changes: 5 additions & 1 deletion lox_tests/arithmetic/token
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
TokenTree {
source text: "1 + 2\n\n1 + 2 * 3\n\n1 - 2 / 3\n\n1 + 2 * -3",
source text: "1 + 2;\n\n1 + 2 * 3;\n\n1 - 2 / 3;\n\n1 + 2 * -3;",
tokens: [
Number(1),
Whitespace(' '),
Op(+),
Whitespace(' '),
Number(2),
Semicolon,
Whitespace('\n'),
Whitespace('\n'),
Number(1),
Expand All @@ -17,6 +18,7 @@ TokenTree {
Op(*),
Whitespace(' '),
Number(3),
Semicolon,
Whitespace('\n'),
Whitespace('\n'),
Number(1),
Expand All @@ -28,6 +30,7 @@ TokenTree {
Op(/),
Whitespace(' '),
Number(3),
Semicolon,
Whitespace('\n'),
Whitespace('\n'),
Number(1),
Expand All @@ -40,5 +43,6 @@ TokenTree {
Whitespace(' '),
Op(-),
Number(3),
Semicolon,
],
}
8 changes: 4 additions & 4 deletions lox_tests/boolean.lox
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
true
false
!true
!false
true;
false;
!true;
!false;
28 changes: 0 additions & 28 deletions lox_tests/boolean/output
Original file line number Diff line number Diff line change
@@ -1,28 +0,0 @@
Error: expected `;`
╭─[/home/zhoufan/workspace/lox/lox_tests/boolean.lox:2:1]
2 │ false
│ ──┬──
│ ╰──── here
───╯
Error: expected `;`
╭─[/home/zhoufan/workspace/lox/lox_tests/boolean.lox:3:1]
3 │ !true
│ ┬
│ ╰── here
───╯
Error: expected `;`
╭─[/home/zhoufan/workspace/lox/lox_tests/boolean.lox:4:1]
4 │ !false
│ ┬
│ ╰── here
───╯
Error: expected `;`
╭─[/home/zhoufan/workspace/lox/lox_tests/boolean.lox:4:2]
4 │ !false
│ ──┬──
│ ╰──── here
───╯
6 changes: 5 additions & 1 deletion lox_tests/boolean/token
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
TokenTree {
source text: "true\nfalse\n!true\n!false",
source text: "true;\nfalse;\n!true;\n!false;",
tokens: [
Alphabetic(true),
Semicolon,
Whitespace('\n'),
Alphabetic(false),
Semicolon,
Whitespace('\n'),
Op(!),
Alphabetic(true),
Semicolon,
Whitespace('\n'),
Op(!),
Alphabetic(false),
Semicolon,
],
}
8 changes: 4 additions & 4 deletions lox_tests/comparison.lox
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
1 < 2
1 <= 1
1 > 2
1 >= 1
1 < 2;
1 <= 1;
1 > 2;
1 >= 1;
28 changes: 0 additions & 28 deletions lox_tests/comparison/output
Original file line number Diff line number Diff line change
@@ -1,28 +0,0 @@
Error: expected `;`
╭─[/home/zhoufan/workspace/lox/lox_tests/comparison.lox:2:1]
2 │ 1 <= 1
│ ┬
│ ╰── here
───╯
Error: expected `;`
╭─[/home/zhoufan/workspace/lox/lox_tests/comparison.lox:3:1]
3 │ 1 > 2
│ ┬
│ ╰── here
───╯
Error: expected `;`
╭─[/home/zhoufan/workspace/lox/lox_tests/comparison.lox:4:1]
4 │ 1 >= 1
│ ┬
│ ╰── here
───╯
Error: expected `;`
╭─[/home/zhoufan/workspace/lox/lox_tests/comparison.lox:4:6]
4 │ 1 >= 1
│ ┬
│ ╰── here
───╯
6 changes: 5 additions & 1 deletion lox_tests/comparison/token
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
TokenTree {
source text: "1 < 2\n1 <= 1\n1 > 2\n1 >= 1",
source text: "1 < 2;\n1 <= 1;\n1 > 2;\n1 >= 1;",
tokens: [
Number(1),
Whitespace(' '),
Op(<),
Whitespace(' '),
Number(2),
Semicolon,
Whitespace('\n'),
Number(1),
Whitespace(' '),
Op(<),
Op(=),
Whitespace(' '),
Number(1),
Semicolon,
Whitespace('\n'),
Number(1),
Whitespace(' '),
Op(>),
Whitespace(' '),
Number(2),
Semicolon,
Whitespace('\n'),
Number(1),
Whitespace(' '),
Op(>),
Op(=),
Whitespace(' '),
Number(1),
Semicolon,
],
}
4 changes: 2 additions & 2 deletions lox_tests/equality.lox
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1 == 2
1 != 2
1 == 2;
1 != 2;
14 changes: 0 additions & 14 deletions lox_tests/equality/output
Original file line number Diff line number Diff line change
@@ -1,14 +0,0 @@
Error: expected `;`
╭─[/home/zhoufan/workspace/lox/lox_tests/equality.lox:2:1]
2 │ 1 != 2
│ ┬
│ ╰── here
───╯
Error: expected `;`
╭─[/home/zhoufan/workspace/lox/lox_tests/equality.lox:2:6]
2 │ 1 != 2
│ ┬
│ ╰── here
───╯
4 changes: 3 additions & 1 deletion lox_tests/equality/token
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
TokenTree {
source text: "1 == 2\n1 != 2",
source text: "1 == 2;\n1 != 2;",
tokens: [
Number(1),
Whitespace(' '),
Op(=),
Op(=),
Whitespace(' '),
Number(2),
Semicolon,
Whitespace('\n'),
Number(1),
Whitespace(' '),
Op(!),
Op(=),
Whitespace(' '),
Number(2),
Semicolon,
],
}
2 changes: 1 addition & 1 deletion lox_tests/print.lox
Original file line number Diff line number Diff line change
@@ -1 +1 @@
print 1 + 2
print 1 + 2;
Empty file added lox_tests/print/output
Empty file.
3 changes: 2 additions & 1 deletion lox_tests/print/token
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TokenTree {
source text: "print 1 + 2",
source text: "print 1 + 2;",
tokens: [
Alphabetic(print),
Whitespace(' '),
Expand All @@ -8,5 +8,6 @@ TokenTree {
Op(+),
Whitespace(' '),
Number(2),
Semicolon,
],
}

0 comments on commit 4ef0b09

Please sign in to comment.