Skip to content

Commit 75eed67

Browse files
authored
refactor(parse): consider the case of missing equal in initializer (#562)
1 parent 9c6ac65 commit 75eed67

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
main: () { }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pure2-bugfix-for-declaration-equal-error.cpp2...
2+
pure2-bugfix-for-declaration-equal-error.cpp2(1,10): error: missing semicolon at end of declaration or equal at start of initializer (at '{')
3+
pure2-bugfix-for-declaration-equal-error.cpp2(1,1): error: unexpected text at end of Cpp2 code section (at 'main')
4+
pure2-bugfix-for-declaration-equal-error.cpp2(1,0): error: parse failed for section starting here
5+

source/parse.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ struct postfix_expression_node
721721
if (ops.empty()) {
722722
return false;
723723
} else {
724-
return (ops.front().op->type() == lexeme::Ampersand
724+
return (ops.front().op->type() == lexeme::Ampersand
725725
|| ops.front().op->type() == lexeme::Tilde);
726726
}
727727
}
@@ -3993,7 +3993,7 @@ class parser
39933993
// || curr().type() == lexeme::LeftBrace
39943994
)
39953995
{
3996-
bool inside_initializer = (
3996+
bool inside_initializer = (
39973997
peek(-1) && peek(-1)->type() == lexeme::Assignment
39983998
);
39993999
auto open_paren = &curr();
@@ -4015,12 +4015,12 @@ class parser
40154015
next();
40164016
if (
40174017
curr().type() != lexeme::Semicolon
4018-
&& curr().type() != lexeme::RightParen
4019-
&& curr().type() != lexeme::RightBracket
4018+
&& curr().type() != lexeme::RightParen
4019+
&& curr().type() != lexeme::RightBracket
40204020
&& curr().type() != lexeme::Comma
40214021
) {
40224022
expr_list->inside_initializer = false;
4023-
}
4023+
}
40244024
n->expr = std::move(expr_list);
40254025
return n;
40264026
}
@@ -4374,7 +4374,7 @@ class parser
43744374
//G shift-expression '<<' additive-expression
43754375
//G shift-expression '>>' additive-expression
43764376
//G
4377-
auto shift_expression(bool allow_angle_operators = true)
4377+
auto shift_expression(bool allow_angle_operators = true)
43784378
-> auto
43794379
{
43804380
if (allow_angle_operators) {
@@ -4409,7 +4409,7 @@ class parser
44094409
//G shift-expression
44104410
//G compare-expression '<=>' shift-expression
44114411
//G
4412-
auto compare_expression(bool allow_angle_operators = true)
4412+
auto compare_expression(bool allow_angle_operators = true)
44134413
-> auto
44144414
{
44154415
return binary_expression<compare_expression_node> (
@@ -4425,7 +4425,7 @@ class parser
44254425
//G relational-expression '<=' compare-expression
44264426
//G relational-expression '>=' compare-expression
44274427
//G
4428-
auto relational_expression(bool allow_angle_operators = true)
4428+
auto relational_expression(bool allow_angle_operators = true)
44294429
-> auto
44304430
{
44314431
if (allow_angle_operators) {
@@ -4457,7 +4457,7 @@ class parser
44574457
//G equality-expression '==' relational-expression
44584458
//G equality-expression '!=' relational-expression
44594459
//G
4460-
auto equality_expression(bool allow_angle_operators = true)
4460+
auto equality_expression(bool allow_angle_operators = true)
44614461
-> auto
44624462
{
44634463
return binary_expression<equality_expression_node> (
@@ -4470,7 +4470,7 @@ class parser
44704470
//G equality-expression
44714471
//G bit-and-expression '&' equality-expression
44724472
//G
4473-
auto bit_and_expression(bool allow_angle_operators = true)
4473+
auto bit_and_expression(bool allow_angle_operators = true)
44744474
-> auto
44754475
{
44764476
return binary_expression<bit_and_expression_node> (
@@ -4483,7 +4483,7 @@ class parser
44834483
//G bit-and-expression
44844484
//G bit-xor-expression '^' bit-and-expression
44854485
//G
4486-
auto bit_xor_expression(bool allow_angle_operators = true)
4486+
auto bit_xor_expression(bool allow_angle_operators = true)
44874487
-> auto
44884488
{
44894489
return binary_expression<bit_xor_expression_node> (
@@ -4496,7 +4496,7 @@ class parser
44964496
//G bit-xor-expression
44974497
//G bit-or-expression '|' bit-xor-expression
44984498
//G
4499-
auto bit_or_expression(bool allow_angle_operators = true)
4499+
auto bit_or_expression(bool allow_angle_operators = true)
45004500
-> auto
45014501
{
45024502
return binary_expression<bit_or_expression_node> (
@@ -4509,7 +4509,7 @@ class parser
45094509
//G bit-or-expression
45104510
//G logical-and-expression '&&' bit-or-expression
45114511
//G
4512-
auto logical_and_expression(bool allow_angle_operators = true)
4512+
auto logical_and_expression(bool allow_angle_operators = true)
45134513
-> auto
45144514
{
45154515
return binary_expression<logical_and_expression_node> (
@@ -4524,7 +4524,7 @@ class parser
45244524
//G logical-and-expression
45254525
//G logical-or-expression '||' logical-and-expression
45264526
//G
4527-
auto logical_or_expression(bool allow_angle_operators = true)
4527+
auto logical_or_expression(bool allow_angle_operators = true)
45284528
-> auto
45294529
{
45304530
return binary_expression<logical_or_expression_node> (
@@ -4842,7 +4842,7 @@ class parser
48424842

48434843
n->open_angle = curr().position();
48444844
next();
4845-
4845+
48464846
auto term = unqualified_id_node::term{};
48474847

48484848
do {
@@ -6433,7 +6433,7 @@ class parser
64336433
}
64346434
assert (n->is_type());
64356435
}
6436-
6436+
64376437
// Or a function type, declaring a function - and tell the function whether it's in a user-defined type
64386438
else if (auto t = function_type(n.get(), named))
64396439
{
@@ -6552,7 +6552,7 @@ class parser
65526552
}
65536553
// But if there isn't one and it was required, diagnose an error
65546554
else if (semicolon_required) {
6555-
error("missing semicolon at end of declaration", true, {}, true);
6555+
error("missing semicolon at end of declaration or equal at start of initializer", true, {}, true);
65566556
return {};
65576557
}
65586558
}
@@ -6591,11 +6591,11 @@ class parser
65916591
)
65926592
{
65936593
auto& type = std::get<declaration_node::an_object>(n->type);
6594-
// object initialized by the address of the curr() object
6594+
// object initialized by the address of the curr() object
65956595
if (peek(1)->type() == lexeme::Ampersand) {
65966596
type->address_of = &curr();
65976597
}
6598-
// object initialized by (potentially multiple) dereference of the curr() object
6598+
// object initialized by (potentially multiple) dereference of the curr() object
65996599
else if (peek(1)->type() == lexeme::Multiply) {
66006600
type->dereference_of = &curr();
66016601
for (int i = 1; peek(i)->type() == lexeme::Multiply; ++i)
@@ -6800,7 +6800,7 @@ class parser
68006800
return {};
68016801
}
68026802
if (
6803-
t->is_wildcard()
6803+
t->is_wildcard()
68046804
|| ( t->get_token() && t->get_token()->to_string(true) == "auto" )
68056805
) {
68066806
errors.emplace_back(

0 commit comments

Comments
 (0)