Skip to content

Commit

Permalink
Fixed regression problem caused by #217
Browse files Browse the repository at this point in the history
  • Loading branch information
yhirose committed Aug 20, 2022
1 parent 9f27513 commit 9c3497e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ public class Example {
}

> peglint java.peg sample.java
sample.java:5:12: syntax error, unexpected '<', expecting <NAME>, <NUMBER>, <WhileStmt>.
sample.java:5:12: syntax error, unexpected '<', expecting '(', <NUMBER>, <NAME>.
sample.java:8:5: missing semicolon in assignment.
sample.java:8:6: invalid statement
```
Expand Down
Binary file modified docs/native.wasm
Binary file not shown.
9 changes: 8 additions & 1 deletion peglib.h
Original file line number Diff line number Diff line change
Expand Up @@ -3045,7 +3045,14 @@ inline size_t Recovery::parse_core(const char *s, size_t n,
len = rule.parse(s, n, dummy_vs, c, dummy_dt);
}

if (success(len)) { c.recovered = true; }
if (success(len)) {
c.recovered = true;

if (c.log) {
c.error_info.output_log(c.log, c.s, c.l);
c.error_info.clear();
}
}

// Cut
if (!c.cut_stack.empty()) {
Expand Down
15 changes: 12 additions & 3 deletions test/test2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,7 @@ TEST(ErrorTest, Default_error_handling_1) {
};

EXPECT_FALSE(pg.parse(" @ aaa typo "));
EXPECT_EQ(i, errors.size());
}

TEST(ErrorTest, Default_error_handling_2) {
Expand All @@ -1477,6 +1478,7 @@ TEST(ErrorTest, Default_error_handling_2) {
};

EXPECT_FALSE(pg.parse(" @ aaa typo "));
EXPECT_EQ(i, errors.size());
}

TEST(ErrorTest, Default_error_handling_fiblang) {
Expand Down Expand Up @@ -1525,6 +1527,7 @@ TEST(ErrorTest, Default_error_handling_fiblang) {
for n frm 1 to 30
puts(fib(n))
)"));
EXPECT_EQ(i, errors.size());
}

TEST(ErrorTest, Error_recovery_1) {
Expand Down Expand Up @@ -1603,6 +1606,8 @@ rrr | sss
)",
ast));

EXPECT_EQ(i, errors.size());

ast = pg.optimize_ast(ast);

EXPECT_EQ(R"(+ START
Expand Down Expand Up @@ -1655,20 +1660,20 @@ rrr | sss

TEST(ErrorTest, Error_recovery_2) {
parser pg(R"(
START <- ENTRY (',' ENTRY)* _*
START <- ENTRY ((',' ENTRY) / %recover((!(',' / Space) .)+))* (_ / %recover(.*))
ENTRY <- '[' ITEM (',' ITEM)* ']'
ITEM <- WORD / NUM / %recover((!(',' / ']') .)+)
NUM <- [0-9]+ ![a-z]
WORD <- '"' [a-z]+ '"'
~_ <- Space
~_ <- Space*
Space <- [ \n]
)");

EXPECT_TRUE(!!pg);

std::vector<std::string> errors{
R"(1:6: syntax error, unexpected ']', expecting <Space>.)",
R"(1:6: syntax error, unexpected ']', expecting ','.)",
R"(1:18: syntax error, unexpected 'z', expecting <NUM>.)",
R"(1:24: syntax error, unexpected ',', expecting '"'.)",
R"(1:31: syntax error, unexpected 'ccc', expecting '"', <NUM>.)",
Expand All @@ -1692,6 +1697,7 @@ TEST(ErrorTest, Error_recovery_2) {
pg.parse(R"([000]],[111],[222z,"aaa,"bbb",ccc"],[ddd",444,555,"eee],[
)",
ast));
EXPECT_EQ(i, errors.size());

EXPECT_FALSE(ast);
}
Expand Down Expand Up @@ -1761,6 +1767,7 @@ skip_puncs <- [|=]* _
R"(21:17: Use of invalid operator)",
R"(24:10: Use of invalid operator combination)",
R"(26:10: Missing OR operator (|))",
R"(28:3: Missing opening/closing square bracket)",
};

size_t i = 0;
Expand Down Expand Up @@ -1803,6 +1810,8 @@ sss | ttt
)",
ast));

EXPECT_EQ(i, errors.size());

ast = pg.optimize_ast(ast);

EXPECT_EQ(R"(+ START
Expand Down

0 comments on commit 9c3497e

Please sign in to comment.