Skip to content

Commit ba8f0df

Browse files
MaxSagebaumhsutter
andauthored
Output the correct location when a statement can not be parsed. (#499)
* Output the correct location when a statement can not be parsed. Currently the start of the current compound statement is provided as a hint. * Tweak error message wording Signed-off-by: Herb Sutter <[email protected]> --------- Signed-off-by: Herb Sutter <[email protected]> Co-authored-by: Herb Sutter <[email protected]>
1 parent 706ebc8 commit ba8f0df

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
func: () = {
2+
a : int = 5;
3+
int b = 4;
4+
c: int = 3;
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pure2-statement-parse-error.cpp2...
2+
pure2-statement-parse-error.cpp2(3,9): error: Could not parse statement (at 'b')
3+

source/parse.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3920,6 +3920,10 @@ class parser
39203920
error( msg.c_str(), include_curr_token, err_pos, fallback );
39213921
}
39223922

3923+
bool has_error() {
3924+
return !errors.empty();
3925+
}
3926+
39233927

39243928
//-----------------------------------------------------------------------
39253929
// Token navigation: Only these functions should access this->token_
@@ -5772,6 +5776,11 @@ class parser
57725776
// contained statement() may have parameters
57735777
auto s = statement(true, source_position{}, true, n.get());
57745778
if (!s) {
5779+
5780+
// Only add error when no specific one already exist
5781+
if(!has_error()) {
5782+
error("Invalid statement encountered inside a compound-statement", true);
5783+
}
57755784
pos = start_pos; // backtrack
57765785
return {};
57775786
}

0 commit comments

Comments
 (0)