Skip to content

Commit ab25cd1

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 ab25cd1

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

source/parse.h

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,16 +2756,31 @@ 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) && pos + i > 0) { --i; };
2763+
if (peek(i)) {
2764+
m += std::string(" (after '") + peek(i)->to_string(true) + "')";
2765+
if (
2766+
err_pos == source_position{}
2767+
) {
2768+
err_pos = peek(i)->position();
2769+
}
2770+
}
2771+
} else {
2772+
if (include_curr_token) {
2773+
m += std::string(" (at '") + curr().to_string(true) + "')";
2774+
}
2775+
if (
2776+
err_pos == source_position{}
2777+
&& peek(0)
2778+
)
2779+
{
2780+
err_pos = peek(0)->position();
2781+
}
27682782
}
2783+
27692784
errors.emplace_back( err_pos, m, false, fallback );
27702785
}
27712786

@@ -4777,7 +4792,8 @@ class parser
47774792

47784793
// If there's no [ [ then this isn't a contract
47794794
if (
4780-
curr().type() != lexeme::LeftBracket
4795+
done()
4796+
|| curr().type() != lexeme::LeftBracket
47814797
|| !peek(1)
47824798
|| peek(1)->type() != lexeme::LeftBracket
47834799
)

0 commit comments

Comments
 (0)