Skip to content

Commit 5663493

Browse files
committed
Remove whitespace sensitivity for * and &
Undo commit 30c79a0 Updates comment on partly-related hsutter#152 Closes hsutter#319 Closes hsutter#989
1 parent 38efdc7 commit 5663493

File tree

7 files changed

+24
-25
lines changed

7 files changed

+24
-25
lines changed

regression-tests/mixed-test-parens.cpp2

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ auto f(auto, auto) -> void { }
66
constexpr int a = 1;
77

88
main: () -> int = {
9+
p := new<int>(11);
10+
std::cout << p * << "\n";
11+
912
v : std::vector<int> = ( 1, 2, 3 );
10-
std::cout << (1+2) * (3+v[0]);
13+
std::cout << (1+2)*(3+v[0]);
14+
std::cout << "\n13*14 is (13*14)$\n";
1115
f<(1>2)>(3,4);
1216
f< a+a >(5,6);
1317
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
12
1+
11
2+
12
3+
13*14 is 182
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
12
1+
11
2+
12
3+
13*14 is 182
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
12
1+
11
2+
12
3+
13*14 is 182

regression-tests/test-results/mixed-test-parens.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ constexpr int a = 1;
2727

2828
#line 8 "mixed-test-parens.cpp2"
2929
[[nodiscard]] auto main() -> int{
30+
auto p {cpp2_new<int>(11)};
31+
std::cout << *cpp2::impl::assert_not_null(cpp2::move(p)) << "\n";
32+
3033
std::vector<int> v {1, 2, 3};
3134
std::cout << (1 + 2) * (3 + CPP2_ASSERT_IN_BOUNDS_LITERAL(cpp2::move(v), 0));
35+
std::cout << ("\n13*14 is " + cpp2::to_string(13 * 14) + "\n");
3236
f<(cpp2::impl::cmp_greater(1,2))>(3, 4);
3337
f<a + a>(5, 6);
3438
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
12
1+
11
2+
12
3+
13*14 is 182

source/parse.h

+3-20
Original file line numberDiff line numberDiff line change
@@ -5771,7 +5771,7 @@ class parser
57715771

57725772
//G postfix-expression:
57735773
//G primary-expression
5774-
//G postfix-expression postfix-operator // Note: without whitespace before the operator
5774+
//G postfix-expression postfix-operator
57755775
//G postfix-expression '[' expression-list? ','? ']'
57765776
//G postfix-expression '(' expression-list? ','? ')'
57775777
//G postfix-expression '.' id-expression
@@ -5788,23 +5788,18 @@ class parser
57885788
while (
57895789
!done()
57905790
&& (
5791-
(is_postfix_operator(curr().type())
5792-
// Postfix operators must be lexically adjacent
5793-
&& curr().position().lineno == peek(-1)->position().lineno
5794-
&& curr().position().colno == peek(-1)->position().colno + peek(-1)->length()
5795-
)
5791+
is_postfix_operator(curr().type())
57965792
|| curr().type() == lexeme::LeftBracket
57975793
|| curr().type() == lexeme::LeftParen
57985794
|| curr().type() == lexeme::Dot
57995795
)
58005796
)
58015797
{
5802-
// these can't be unary operators if followed by a (, identifier, or literal
5798+
// * and & can't be unary operators if followed by a (, identifier, or literal
58035799
if (
58045800
(
58055801
curr().type() == lexeme::Multiply
58065802
|| curr().type() == lexeme::Ampersand
5807-
|| curr().type() == lexeme::Tilde
58085803
)
58095804
&& peek(1)
58105805
&& (
@@ -5814,18 +5809,6 @@ class parser
58145809
)
58155810
)
58165811
{
5817-
auto op = curr().to_string();
5818-
auto msg = "postfix unary " + op;
5819-
if (curr().type() == lexeme::Multiply ) { msg += " (dereference)" ; }
5820-
else if (curr().type() == lexeme::Ampersand) { msg += " (address-of)" ; }
5821-
else if (curr().type() == lexeme::Tilde ) { msg += " (unary bit-complement)" ; }
5822-
msg += " cannot be immediately followed by a (, identifier, or literal - add whitespace before "
5823-
+ op + " here if you meant binary " + op;
5824-
if (curr().type() == lexeme::Multiply ) { msg += " (multiplication)" ; }
5825-
else if (curr().type() == lexeme::Ampersand) { msg += " (bitwise and)" ; }
5826-
else if (curr().type() == lexeme::Tilde ) { msg += " (binary bit-complement)"; }
5827-
5828-
error(msg, false);
58295812
break;
58305813
}
58315814

0 commit comments

Comments
 (0)