Skip to content

Commit

Permalink
Allow __identifier__keyword to be the identifier "keyword", closes #…
Browse files Browse the repository at this point in the history
…642

See
  • Loading branch information
hsutter committed Sep 13, 2023
1 parent f6ecbb4 commit 1043622
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion regression-tests/test-results/version
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

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

SPDX-License-Identifier: CC-BY-NC-ND-4.0
Expand Down
2 changes: 1 addition & 1 deletion source/build.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"8912:1051"
"8913:1037"
1 change: 1 addition & 0 deletions source/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ auto is_identifier_continue(char c)
}

//G identifier:
//G '__identifier__' keyword [Note: without whitespace before the keyword]
//G identifier-start
//G identifier identifier-continue
//G 'operator' operator
Expand Down
13 changes: 13 additions & 0 deletions source/lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,16 @@ class token
v.start(*this, depth);
}

auto remove_prefix_if(std::string_view prefix) {
if (
sv.size() > prefix.size()
&& sv.starts_with(prefix)
)
{
sv.remove_prefix(prefix.size());
}
}

private:
std::string_view sv;
source_position pos;
Expand Down Expand Up @@ -1682,6 +1692,9 @@ auto lex_line(
else
{
store(j, lexeme::Identifier);

tokens.back().remove_prefix_if("__identifier__");

if (tokens.back() == "NULL") {
errors.emplace_back(
source_position(lineno, i),
Expand Down
2 changes: 1 addition & 1 deletion source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -7106,7 +7106,7 @@ class parser


//G declaration:
//G access-specifier? identifier unnamed-declaration
//G access-specifier? identifier '...'? unnamed-declaration
//G access-specifier? identifier alias
//G
//G access-specifier:
Expand Down

2 comments on commit 1043622

@JohelEGP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails (https://cpp2.godbolt.org/z/eP16EPoYc):

u: @struct <T> type = { }
t: @struct type = {
  this: u<i32>;
  this: __identifier__u<i16>;
}
main: () = { }
main.cpp2...
main.cpp2(4,24): error: missing ';' at end of declaration or '=' at start of initializer (at '<')
main.cpp2(2,19): error: ill-formed initializer (at '{')
main.cpp2(2,1): error: unexpected text at end of Cpp2 code section (at 't')
main.cpp2(1,0): error: parse failed for section starting here

@hsutter
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks: 89f1830

Please sign in to comment.