Skip to content

Commit 1043622

Browse files
committed
Allow __identifier__keyword to be the identifier "keyword", closes #642
See
1 parent f6ecbb4 commit 1043622

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

regression-tests/test-results/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cppfront compiler v0.2.1 Build 8912:1051
2+
cppfront compiler v0.2.1 Build 8913:1037
33
Copyright(c) Herb Sutter All rights reserved
44

55
SPDX-License-Identifier: CC-BY-NC-ND-4.0

source/build.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"8912:1051"
1+
"8913:1037"

source/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ auto is_identifier_continue(char c)
359359
}
360360

361361
//G identifier:
362+
//G '__identifier__' keyword [Note: without whitespace before the keyword]
362363
//G identifier-start
363364
//G identifier identifier-continue
364365
//G 'operator' operator

source/lex.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,16 @@ class token
306306
v.start(*this, depth);
307307
}
308308

309+
auto remove_prefix_if(std::string_view prefix) {
310+
if (
311+
sv.size() > prefix.size()
312+
&& sv.starts_with(prefix)
313+
)
314+
{
315+
sv.remove_prefix(prefix.size());
316+
}
317+
}
318+
309319
private:
310320
std::string_view sv;
311321
source_position pos;
@@ -1682,6 +1692,9 @@ auto lex_line(
16821692
else
16831693
{
16841694
store(j, lexeme::Identifier);
1695+
1696+
tokens.back().remove_prefix_if("__identifier__");
1697+
16851698
if (tokens.back() == "NULL") {
16861699
errors.emplace_back(
16871700
source_position(lineno, i),

source/parse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7106,7 +7106,7 @@ class parser
71067106

71077107

71087108
//G declaration:
7109-
//G access-specifier? identifier unnamed-declaration
7109+
//G access-specifier? identifier '...'? unnamed-declaration
71107110
//G access-specifier? identifier alias
71117111
//G
71127112
//G access-specifier:

0 commit comments

Comments
 (0)