Skip to content

Commit bc5fa4e

Browse files
committed
Regenerate the c++ keywords classifier
1 parent 1ce9dc1 commit bc5fa4e

File tree

7 files changed

+723
-161
lines changed

7 files changed

+723
-161
lines changed

packages/cxx-gen-ast/src/gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ gen_tokenkind_ts({
150150
output: path.join(outdir, "packages/cxx-frontend/src/TokenKind.ts"),
151151
});
152152
gen_keywords_kwgen({
153-
output: path.join(outdir, "src/parser/cxx/keywords.kwgen"),
153+
output: path.join(outdir, "src/parser/cxx/private/keywords-priv.h"),
154154
});
155155

156156
child_process.execSync("clang-format -i *.h *.cc", {

packages/cxx-gen-ast/src/gen_keywords_kwgen.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,32 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
2020

21-
import * as fs from "fs";
2221
import * as tokens from "./tokens.ts";
22+
import kwgen from "./kwgen.ts";
2323

2424
export function gen_keywords_kwgen({ output }: { output: string }) {
25-
const code: string[] = [];
26-
const emit = (line = "") => code.push(line);
27-
2825
const isContextKeyword = (kw: string) => {
2926
return ["final", "override", "import", "module"].includes(kw);
3027
};
3128

29+
const keywords: string[] = [];
30+
3231
tokens.KEYWORDS.filter((kw) => !isContextKeyword(kw)).forEach((tk) =>
33-
emit(tk),
32+
keywords.push(tk),
3433
);
3534

36-
emit();
37-
tokens.TOKEN_ALIASES.forEach(([tk]) => emit(tk));
38-
39-
const out = `%no-enums
40-
%token-prefix=cxx::TokenKind::T_
41-
%token-type=cxx::TokenKind
42-
%toupper
43-
44-
%%
45-
${code.join("\n")}
46-
`;
47-
48-
fs.writeFileSync(output, out);
35+
tokens.TOKEN_ALIASES.forEach(([tk]) => {
36+
keywords.push(tk);
37+
});
38+
39+
kwgen({
40+
output,
41+
keywords,
42+
tokenPrefix: "cxx::TokenKind::T_",
43+
tokenType: "cxx::TokenKind",
44+
toUpper: true,
45+
noEnums: true,
46+
defaultToken: "cxx::TokenKind::T_IDENTIFIER",
47+
classifier: "classify",
48+
});
4949
}

src/parser/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ add_library(cxx-parser
6969
cxx/windows_toolchain.cc
7070

7171
# generated files
72-
keywords-priv.h
7372
pp_keywords-priv.h
7473
# headers
7574
${CXX_INCLUDE_HEADER_FILES}
@@ -97,11 +96,6 @@ target_link_libraries(cxx-parser
9796
PUBLIC $<BUILD_INTERFACE:utf8cpp>
9897
)
9998

100-
add_custom_command(OUTPUT keywords-priv.h
101-
COMMAND kwgen < ${CMAKE_CURRENT_SOURCE_DIR}/cxx/keywords.kwgen > keywords-priv.h
102-
DEPENDS cxx/keywords.kwgen
103-
COMMENT "Generate keywords-priv.h")
104-
10599
add_custom_command(OUTPUT pp_keywords-priv.h
106100
COMMAND kwgen < ${CMAKE_CURRENT_SOURCE_DIR}/cxx/pp_keywords.kwgen > pp_keywords-priv.h
107101
DEPENDS cxx/pp_keywords.kwgen

src/parser/cxx/keywords.kwgen

Lines changed: 0 additions & 132 deletions
This file was deleted.

src/parser/cxx/lexer.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
// SOFTWARE.
2020

2121
#include <cxx/lexer.h>
22+
#include <cxx/private/keywords-priv.h>
2223
#include <utf8/unchecked.h>
2324

2425
#include <cctype>
2526
#include <unordered_map>
2627
#include <vector>
2728

28-
#include "keywords-priv.h"
29-
3029
namespace cxx {
3130

3231
inline namespace {

0 commit comments

Comments
 (0)