Skip to content

Commit 2b730e8

Browse files
committed
Fix error() method that throws when done() is true
When done() is true last correct token and its position is printed.
1 parent d41fc77 commit 2b730e8

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

source/parse.h

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,16 +2756,29 @@ class parser
27562756
-> void
27572757
{
27582758
auto m = std::string{msg};
2759-
if (include_curr_token) {
2760-
m += std::string(" (at '") + curr().to_string(true) + "')";
2761-
}
2762-
if (
2763-
err_pos == source_position{}
2764-
&& peek(0)
2765-
)
2766-
{
2767-
err_pos = peek(0)->position();
2759+
2760+
if (done()) {
2761+
int i = 0;
2762+
while(!peek(i)) { --i; };
2763+
m += std::string(" (after '") + peek(i)->to_string(true) + "')";
2764+
if (
2765+
err_pos == source_position{}
2766+
) {
2767+
err_pos = peek(i)->position();
2768+
}
2769+
} else {
2770+
if (include_curr_token) {
2771+
m += std::string(" (at '") + curr().to_string(true) + "')";
2772+
}
2773+
if (
2774+
err_pos == source_position{}
2775+
&& peek(0)
2776+
)
2777+
{
2778+
err_pos = peek(0)->position();
2779+
}
27682780
}
2781+
27692782
errors.emplace_back( err_pos, m, false, fallback );
27702783
}
27712784

@@ -4777,7 +4790,8 @@ class parser
47774790

47784791
// If there's no [ [ then this isn't a contract
47794792
if (
4780-
curr().type() != lexeme::LeftBracket
4793+
done()
4794+
|| curr().type() != lexeme::LeftBracket
47814795
|| !peek(1)
47824796
|| peek(1)->type() != lexeme::LeftBracket
47834797
)

0 commit comments

Comments
 (0)