Skip to content

Commit fcbfd4e

Browse files
committed
Parser: add union support; keywords: union as KEYWORD6
1 parent c58a003 commit fcbfd4e

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

keywords.txt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,21 @@ signed KEYWORD5
1818
short KEYWORD5
1919
bool KEYWORD5
2020
string KEYWORD5
21-
mouseDX KEYWORD4
22-
mouseDY KEYWORD4
21+
mouseDX KEYWORD4
22+
mouseDY KEYWORD4
23+
frameCount KEYWORD4
24+
frameRate KEYWORD4
25+
mousePressed KEYWORD4
26+
keyPressed KEYWORD4
27+
mouseButton KEYWORD4
28+
keyCode KEYWORD4
29+
key KEYWORD4
30+
focused KEYWORD4
31+
displayWidth KEYWORD4
32+
displayHeight KEYWORD4
33+
pixelWidth KEYWORD4
34+
pixelHeight KEYWORD4
35+
pixelDensity KEYWORD4
2336

2437

2538
# processing-cpp keywords.txt
@@ -391,6 +404,7 @@ static KEYWORD6
391404
const KEYWORD6
392405
auto KEYWORD6
393406
struct KEYWORD6
407+
union KEYWORD6
394408
enum KEYWORD6
395409
namespace KEYWORD6
396410
using KEYWORD6

src/java/Parser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ private List<TopLevelItem> parseTopLevelItem(List<CppLexerToken> leadingComments
414414
// This is handled in parseTemplateParamName already.
415415
}
416416

417-
if (checkKeyword("class") || checkKeyword("struct")) {
417+
if (checkKeyword("class") || checkKeyword("struct") || checkKeyword("union")) {
418418
// Partial specialization: "template<typename T> struct Foo<T*> { ... }"
419419
// After parsing the class/struct, check for a specialization arg list.
420420
// BUT: "struct TypeName funcName(...)" is a function with elaborated return type
@@ -777,7 +777,7 @@ private String parseTemplateParamName() {
777777
*/
778778
private List<TopLevelItem> parseTypeDef(List<CppLexerToken> leadingComments, List<String> templateParams) {
779779
CppLexerToken start = peek();
780-
String kind = checkKeyword("class") ? "class" : "struct";
780+
String kind = checkKeyword("class") ? "class" : checkKeyword("union") ? "union" : "struct";
781781
advance();
782782
// alignas specifier: "struct alignas(64) CacheLine"
783783
if (checkKeyword("alignas") && pos + 1 < tokens.size() && tokens.get(pos + 1).isPunct("(")) {
@@ -982,7 +982,7 @@ private List<TopLevelItem> parseClassMember(List<CppLexerToken> leadingComments,
982982
consumeLeadingComments();
983983
}
984984
}
985-
if (checkKeyword("class") || checkKeyword("struct")) {
985+
if (checkKeyword("class") || checkKeyword("struct") || checkKeyword("union")) {
986986
// Anonymous struct: "struct { float x, y; } position;"
987987
if (pos + 1 < tokens.size() && tokens.get(pos + 1).isPunct("{")) {
988988
int anonStart = pos;

0 commit comments

Comments
 (0)