Skip to content

Commit 17d700d

Browse files
committed
[C/C++] Add complete list of keywords + add assert as keyword so it is escaped correctly.
1 parent 408dbc5 commit 17d700d

File tree

1 file changed

+161
-30
lines changed

1 file changed

+161
-30
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/ValidationUtil.java

Lines changed: 161 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,67 @@ public class ValidationUtil
2626
private static final Pattern PATTERN = Pattern.compile("\\.");
2727

2828
private static final Set<String> C_KEYWORDS = Set.of(
29-
"auto", "_Alignas", "_Alignof", "_Atomic", "bool",
30-
"_Bool", "break", "case", "_Complex",
31-
"char", "const", "continue", "default",
32-
"do", "double", "else", "enum", "extern", "false",
33-
"float", "for", "_Generic", "goto", "if", "_Imaginary", "inline",
34-
"int", "long", "_Noreturn", "register", "restrict", "return", "short",
35-
"signed", "sizeof", "static", "_Static_assert",
36-
"struct", "switch", "_Thread_local", "true", "typedef", "union",
37-
"unsigned", "void", "volatile", "wchar_t", "while");
29+
"alignas",
30+
"alignof",
31+
"assert",
32+
"auto",
33+
"bool",
34+
"break",
35+
"case",
36+
"char",
37+
"const",
38+
"constexpr",
39+
"continue",
40+
"default",
41+
"do",
42+
"double",
43+
"else",
44+
"enum",
45+
"extern",
46+
"false",
47+
"float",
48+
"for",
49+
"goto",
50+
"if",
51+
"inline",
52+
"int",
53+
"long",
54+
"nullptr",
55+
"register",
56+
"restrict",
57+
"return",
58+
"short",
59+
"signed",
60+
"sizeof",
61+
"static",
62+
"static_assert",
63+
"struct",
64+
"switch",
65+
"thread_local",
66+
"true",
67+
"typedef",
68+
"typeof",
69+
"typeof_unqual",
70+
"union",
71+
"unsigned",
72+
"void",
73+
"volatile",
74+
"while",
75+
"_Alignas",
76+
"_Alignof",
77+
"_Atomic",
78+
"_BitInt",
79+
"_Bool",
80+
"_Complex",
81+
"_Decimal128",
82+
"_Decimal32",
83+
"_Decimal64",
84+
"_Generic",
85+
"_Imaginary",
86+
"_Noreturn",
87+
"_Static_assert",
88+
"_Thread_local"
89+
);
3890

3991
/**
4092
* Check value for validity of usage as a C identifier. A programmatic variable
@@ -113,26 +165,105 @@ private static boolean isSbeCIdentifierPart(final char c)
113165
}
114166

115167
private static final Set<String> CPP_KEYWORDS = Set.of(
116-
"alignas", "and", "and_eq", "asm", "auto",
117-
"bitand", "bitor", "bool", "break", "case",
118-
"catch", "char", "class", "compl", "const",
119-
"const_cast", "continue", "char16_t", "char32_t", "default",
120-
"delete", "do", "double", "dynamic_cast", "else",
121-
"enum", "explicit", "export", "extern", "false",
122-
"float", "for", "friend", "goto", "if",
123-
"inline", "int", "long", "mutable", "namespace",
124-
"new", "not", "not_eq", "noexcept", "operator",
125-
"or", "or_eq", "private", "protected", "public",
126-
"register", "reinterpret_cast", "return", "short", "signed",
127-
"sizeof", "static", "static_cast", "struct", "switch",
128-
"template", "this", "throw", "true", "try",
129-
"typedef", "typeid", "typename", "union", "unsigned",
130-
"using", "virtual", "void", "volatile", "wchar_t",
131-
"while", "xor", "xor_eq", "override",
132-
// since C++11
133-
"alignof", "constexpr", "decltype", "nullptr", "static_assert", "thread_local",
134-
// since C++11 have special meaning, so avoid
135-
"final");
168+
"alignas",
169+
"alignof",
170+
"and",
171+
"and_eq",
172+
"assert",
173+
"asm",
174+
"atomic_cancel",
175+
"atomic_commit",
176+
"atomic_noexcept",
177+
"auto",
178+
"bitand",
179+
"bitor",
180+
"bool",
181+
"break",
182+
"case",
183+
"catch",
184+
"char",
185+
"char8_t",
186+
"char16_t",
187+
"char32_t",
188+
"class",
189+
"compl",
190+
"concept",
191+
"const",
192+
"consteval",
193+
"constexpr",
194+
"constinit",
195+
"const_cast",
196+
"continue",
197+
"contract_assert",
198+
"co_await",
199+
"co_return",
200+
"co_yield",
201+
"decltype",
202+
"default",
203+
"delete",
204+
"do",
205+
"double",
206+
"dynamic_cast",
207+
"else",
208+
"enum",
209+
"explicit",
210+
"export",
211+
"extern",
212+
"false",
213+
"float",
214+
"for",
215+
"friend",
216+
"goto",
217+
"if",
218+
"inline",
219+
"int",
220+
"long",
221+
"mutable",
222+
"namespace",
223+
"new",
224+
"noexcept",
225+
"not",
226+
"not_eq",
227+
"nullptr",
228+
"operator",
229+
"or",
230+
"or_eq",
231+
"private",
232+
"protected",
233+
"public",
234+
"reflexpr",
235+
"register",
236+
"reinterpret_cast",
237+
"requires",
238+
"return",
239+
"short",
240+
"signed",
241+
"sizeof",
242+
"static",
243+
"static_assert",
244+
"static_cast",
245+
"struct",
246+
"switch",
247+
"synchronized",
248+
"template",
249+
"this",
250+
"thread_local",
251+
"throw",
252+
"true",
253+
"try",
254+
"typedef",
255+
"typeid",
256+
"typename",
257+
"union",
258+
"unsigned",
259+
"using",
260+
"virtual",
261+
"void",
262+
"volatile",
263+
"wchar_t",
264+
"while",
265+
"xor",
266+
"xor_eq");
136267

137268
/**
138269
* Check value for validity of usage as a C++ identifier. A programmatic variable
@@ -393,7 +524,7 @@ private static boolean isSbeGolangIdentifierPart(final char c)
393524
/**
394525
* C# keywords.
395526
* <a href="https://docs.microsoft.com/en-gb/dotnet/articles/csharp/language-reference/keywords/index">
396-
* C# keywords</a>
527+
* C# keywords</a>
397528
* Note this does not include the contextual keywords
398529
* Note "virtual" is no longer but was in early versions of C#
399530
*/

0 commit comments

Comments
 (0)