Skip to content

Commit cacd826

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 2c55d46 commit cacd826

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
@@ -2853,16 +2853,31 @@ class parser
28532853
-> void
28542854
{
28552855
auto m = std::string{msg};
2856-
if (include_curr_token) {
2857-
m += std::string(" (at '") + curr().to_string(true) + "')";
2858-
}
2859-
if (
2860-
err_pos == source_position{}
2861-
&& peek(0)
2862-
)
2863-
{
2864-
err_pos = peek(0)->position();
2856+
2857+
if (done()) {
2858+
int i = 0;
2859+
while(!peek(i) && pos + i > 0) { --i; };
2860+
if (peek(i)) {
2861+
m += std::string(" (after '") + peek(i)->to_string(true) + "')";
2862+
if (
2863+
err_pos == source_position{}
2864+
) {
2865+
err_pos = peek(i)->position();
2866+
}
2867+
}
2868+
} else {
2869+
if (include_curr_token) {
2870+
m += std::string(" (at '") + curr().to_string(true) + "')";
2871+
}
2872+
if (
2873+
err_pos == source_position{}
2874+
&& peek(0)
2875+
)
2876+
{
2877+
err_pos = peek(0)->position();
2878+
}
28652879
}
2880+
28662881
errors.emplace_back( err_pos, m, false, fallback );
28672882
}
28682883

@@ -4879,7 +4894,8 @@ class parser
48794894

48804895
// If there's no [ [ then this isn't a contract
48814896
if (
4882-
curr().type() != lexeme::LeftBracket
4897+
done()
4898+
|| curr().type() != lexeme::LeftBracket
48834899
|| !peek(1)
48844900
|| peek(1)->type() != lexeme::LeftBracket
48854901
)

0 commit comments

Comments
 (0)