From 52ad4cec99d29718cf1f4b6a2e69f7a469976ec4 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Wed, 28 Jan 2026 16:35:42 +0800 Subject: [PATCH] refactor: rename all general to generic in EnumsAnalyzer --- .../EnumsMigration/EnumsAnalyzer/.gitignore | 2 +- .../EnumsAnalyzer/CKDefinesParser.g4 | 4 +-- .../EnumsAnalyzer/CKEnumsParser.g4 | 12 ++++----- .../EnumsAnalyzer/CKGeneralLexer.g4 | 26 ------------------- .../EnumsAnalyzer/CKGenericLexer.g4 | 26 +++++++++++++++++++ .../EnumsAnalyzer/ClassidWalker.java | 6 ++--- .../EnumsAnalyzer/CommentsFinder.java | 8 +++--- .../EnumsAnalyzer/CommonHelper.java | 8 +++--- .../EnumsAnalyzer/DefinesWalker.java | 8 +++--- .../EnumsAnalyzer/EnumsWalker.java | 10 +++---- .../EnumsAnalyzer/MainRunner.java | 6 ++--- Assets/CodeGen/EnumsMigration/README.md | 2 +- 12 files changed, 59 insertions(+), 59 deletions(-) delete mode 100644 Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CKGeneralLexer.g4 create mode 100644 Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CKGenericLexer.g4 diff --git a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/.gitignore b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/.gitignore index 65985f7..5afe1d7 100644 --- a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/.gitignore +++ b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/.gitignore @@ -7,7 +7,7 @@ *.interp *.tokens -CKGeneralLexer*.java +CKGenericLexer*.java CKEnumsParser*.java CKDefinesParser*.java diff --git a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CKDefinesParser.g4 b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CKDefinesParser.g4 index 8166219..07c1366 100644 --- a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CKDefinesParser.g4 +++ b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CKDefinesParser.g4 @@ -1,6 +1,6 @@ parser grammar CKDefinesParser; -options { tokenVocab = CKGeneralLexer; } +options { tokenVocab = CKGenericLexer; } prog: definePair+ ; -definePair: CKGENERAL_DEFINE CKGENERAL_ID (CKGENERAL_NUM | CKGENERAL_ID) ; +definePair: CKGENERIC_DEFINE CKGENERIC_ID (CKGENERIC_NUM | CKGENERIC_ID) ; diff --git a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CKEnumsParser.g4 b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CKEnumsParser.g4 index a067a01..2e362c9 100644 --- a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CKEnumsParser.g4 +++ b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CKEnumsParser.g4 @@ -1,14 +1,14 @@ parser grammar CKEnumsParser; -options { tokenVocab = CKGeneralLexer; } +options { tokenVocab = CKGenericLexer; } prog: enumBody* ; -enumBody: CKGENERAL_TYPEDEF? CKGENERAL_ENUM CKGENERAL_ID CKGENERAL_LBRACKET +enumBody: CKGENERIC_TYPEDEF? CKGENERIC_ENUM CKGENERIC_ID CKGENERIC_LBRACKET entryPair+ -CKGENERAL_RBRACKET CKGENERAL_ID? CKGENERAL_SEMICOLON ; +CKGENERIC_RBRACKET CKGENERIC_ID? CKGENERIC_SEMICOLON ; -entryPair: CKGENERAL_ID (CKGENERAL_EQUAL entryValue)? CKGENERAL_COMMA? ; +entryPair: CKGENERIC_ID (CKGENERIC_EQUAL entryValue)? CKGENERIC_COMMA? ; -entryValue: CKGENERAL_NUM (CKGENERAL_LSHIFT CKGENERAL_NUM)? # entryDirectValue -| CKGENERAL_ID (CKGENERAL_OR CKGENERAL_ID)* # entryRelativeValue +entryValue: CKGENERIC_NUM (CKGENERIC_LSHIFT CKGENERIC_NUM)? # entryDirectValue +| CKGENERIC_ID (CKGENERIC_OR CKGENERIC_ID)* # entryRelativeValue ; \ No newline at end of file diff --git a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CKGeneralLexer.g4 b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CKGeneralLexer.g4 deleted file mode 100644 index 64919eb..0000000 --- a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CKGeneralLexer.g4 +++ /dev/null @@ -1,26 +0,0 @@ -lexer grammar CKGeneralLexer; - -channels { COMMENTS, WHITESPACE } - -// keywords -CKGENERAL_TYPEDEF: 'typedef' ; -CKGENERAL_DEFINE: '#define' ; -CKGENERAL_ENUM: 'enum' ; -// symbols -CKGENERAL_LBRACKET: '{' ; -CKGENERAL_RBRACKET: '}' ; -CKGENERAL_EQUAL: '='; -CKGENERAL_SEMICOLON: ';' ; -CKGENERAL_LSHIFT: '<<' ; -CKGENERAL_OR: '|' ; -CKGENERAL_COMMA: ',' ; - -// identifider and number -CKGENERAL_ID: [_a-zA-Z][_a-zA-Z0-9]* ; -CKGENERAL_NUM: (('0'[xX]) | '-')? [0-9a-fA-F]+ [uUlL]* ; - -// comments -CKGENERAL_LINE_COMMENT: '//' ~[\r\n]* -> channel(COMMENTS); -CKGENERAL_BLOCK_COMMENT: '/*' .*? '*/' -> channel(COMMENTS); -// whitespace -CKGENERAL_WS: [ \t\r\n]+ -> channel(WHITESPACE); diff --git a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CKGenericLexer.g4 b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CKGenericLexer.g4 new file mode 100644 index 0000000..d21ebd2 --- /dev/null +++ b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CKGenericLexer.g4 @@ -0,0 +1,26 @@ +lexer grammar CKGenericLexer; + +channels { COMMENTS, WHITESPACE } + +// keywords +CKGENERIC_TYPEDEF: 'typedef' ; +CKGENERIC_DEFINE: '#define' ; +CKGENERIC_ENUM: 'enum' ; +// symbols +CKGENERIC_LBRACKET: '{' ; +CKGENERIC_RBRACKET: '}' ; +CKGENERIC_EQUAL: '='; +CKGENERIC_SEMICOLON: ';' ; +CKGENERIC_LSHIFT: '<<' ; +CKGENERIC_OR: '|' ; +CKGENERIC_COMMA: ',' ; + +// identifider and number +CKGENERIC_ID: [_a-zA-Z][_a-zA-Z0-9]* ; +CKGENERIC_NUM: (('0'[xX]) | '-')? [0-9a-fA-F]+ [uUlL]* ; + +// comments +CKGENERIC_LINE_COMMENT: '//' ~[\r\n]* -> channel(COMMENTS); +CKGENERIC_BLOCK_COMMENT: '/*' .*? '*/' -> channel(COMMENTS); +// whitespace +CKGENERIC_WS: [ \t\r\n]+ -> channel(WHITESPACE); diff --git a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/ClassidWalker.java b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/ClassidWalker.java index 6299123..031565e 100644 --- a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/ClassidWalker.java +++ b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/ClassidWalker.java @@ -23,7 +23,7 @@ public class ClassidWalker extends CKDefinesParserBaseListener { } private int getClassidLevel(Token defineHead) { - Token ws = CommonHelper.getPreChannelToken(mTokenStream, defineHead, CKGeneralLexer.WHITESPACE); + Token ws = CommonHelper.getPreChannelToken(mTokenStream, defineHead, CKGenericLexer.WHITESPACE); if (ws == null) return 0; @@ -87,8 +87,8 @@ public class ClassidWalker extends CKDefinesParserBaseListener { @Override public void exitDefinePair(CKDefinesParser.DefinePairContext ctx) { // fill entry info - mCurrentEntry.mEntryName = ctx.CKGENERAL_ID(0).getText(); - mCurrentEntry.mEntryValue = ctx.CKGENERAL_NUM().getText(); + mCurrentEntry.mEntryName = ctx.CKGENERIC_ID(0).getText(); + mCurrentEntry.mEntryValue = ctx.CKGENERIC_NUM().getText(); // fill entry level info int this_level = getClassidLevel(ctx.getStart()); diff --git a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CommentsFinder.java b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CommentsFinder.java index 59bd0d7..91cbf00 100644 --- a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CommentsFinder.java +++ b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CommentsFinder.java @@ -22,13 +22,13 @@ public class CommentsFinder { // if we don't know where is our token, // we should assume it is from precomment to postcomment // and check it. - List precomment = CommonHelper.getPreChannelTokens(mTokenStream, preToken, CKGeneralLexer.COMMENTS); + List precomment = CommonHelper.getPreChannelTokens(mTokenStream, preToken, CKGenericLexer.COMMENTS); if (precomment != null) { mCommentsPos = CommentsPosition.Precomment; return CommonHelper.cutComments(precomment); } - List postcomment = CommonHelper.getPostChannelTokens(mTokenStream, postToken, CKGeneralLexer.COMMENTS); + List postcomment = CommonHelper.getPostChannelTokens(mTokenStream, postToken, CKGenericLexer.COMMENTS); if (postcomment != null) { mCommentsPos = CommentsPosition.Postcomment; return CommonHelper.cutComments(postcomment); @@ -38,10 +38,10 @@ public class CommentsFinder { return null; } case Precomment: { - return CommonHelper.cutComments(CommonHelper.getPreChannelTokens(mTokenStream, preToken, CKGeneralLexer.COMMENTS)); + return CommonHelper.cutComments(CommonHelper.getPreChannelTokens(mTokenStream, preToken, CKGenericLexer.COMMENTS)); } case Postcomment: { - return CommonHelper.cutComments(CommonHelper.getPostChannelTokens(mTokenStream, postToken, CKGeneralLexer.COMMENTS)); + return CommonHelper.cutComments(CommonHelper.getPostChannelTokens(mTokenStream, postToken, CKGenericLexer.COMMENTS)); } default: return null; diff --git a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CommonHelper.java b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CommonHelper.java index aa9728b..01616e9 100644 --- a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CommonHelper.java +++ b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/CommonHelper.java @@ -46,7 +46,7 @@ public class CommonHelper { return null; switch (comment.getType()) { - case CKGeneralLexer.CKGENERAL_LINE_COMMENT: { + case CKGenericLexer.CKGENERIC_LINE_COMMENT: { // For line comment, we start to remove "//" prefix first String slashRemoved = comment.getText().substring(2); // Then remove successive starts @@ -58,7 +58,7 @@ public class CommonHelper { // Okey return eolRemoved; } - case CKGeneralLexer.CKGENERAL_BLOCK_COMMENT: { + case CKGenericLexer.CKGENERIC_BLOCK_COMMENT: { // For block comment, we first cut "/*" head and "*/" tail. String blockComment = comment.getText(); String slashRemoved = blockComment.substring(2, blockComment.length() - 4); @@ -103,7 +103,7 @@ public class CommonHelper { // =========== Number Operations =========== /** - * Check whether Antlr captured CKGENERAL_NUM is a negative number. + * Check whether Antlr captured CKGENERIC_NUM is a negative number. * * @param numstr The captured number. * @return true if it is negative number. @@ -113,7 +113,7 @@ public class CommonHelper { } /** - * Check whether Altlr captured CKGENERAL_NUM is a hex number. + * Check whether Altlr captured CKGENERIC_NUM is a hex number. * * @param numstr The captured number. * @return true if it is hex number. diff --git a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/DefinesWalker.java b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/DefinesWalker.java index b037df9..6e6ee8b 100644 --- a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/DefinesWalker.java +++ b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/DefinesWalker.java @@ -42,16 +42,16 @@ public class DefinesWalker extends CKDefinesParserBaseListener { @Override public void exitDefinePair(CKDefinesParser.DefinePairContext ctx) { // set values - mCurrentEntry.mEntryName = ctx.CKGENERAL_ID(0).getText(); + mCurrentEntry.mEntryName = ctx.CKGENERIC_ID(0).getText(); mCurrentEntry.mEntryComment = mCommentsFinder.getComment(ctx.getStart(), ctx.getStop()); - if (ctx.CKGENERAL_NUM() == null) { + if (ctx.CKGENERIC_NUM() == null) { // define with id - mCurrentEntry.mEntryValue = ctx.CKGENERAL_ID(1).getText(); + mCurrentEntry.mEntryValue = ctx.CKGENERIC_ID(1).getText(); } else { // define with number - String num = ctx.CKGENERAL_NUM().getText(); + String num = ctx.CKGENERIC_NUM().getText(); mCurrentEntry.mEntryValue = num; // check whether this enum can be unsigned diff --git a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/EnumsWalker.java b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/EnumsWalker.java index 3be4168..f2b240a 100644 --- a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/EnumsWalker.java +++ b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/EnumsWalker.java @@ -24,7 +24,7 @@ public class EnumsWalker extends CKEnumsParserBaseListener { private String getEnumComment(Token enumHead) { return CommonHelper - .cutComments(CommonHelper.getPreChannelTokens(mTokenStream, enumHead, CKGeneralLexer.COMMENTS)); + .cutComments(CommonHelper.getPreChannelTokens(mTokenStream, enumHead, CKGenericLexer.COMMENTS)); } private BufferedTokenStream mTokenStream; @@ -56,7 +56,7 @@ public class EnumsWalker extends CKEnumsParserBaseListener { // get enum comment mCurrentEnum.mEnumComment = getEnumComment(ctx.getStart()); // get the last name (for typedef case) - List allNames = ctx.CKGENERAL_ID(); + List allNames = ctx.CKGENERIC_ID(); mCurrentEnum.mEnumName = allNames.get(allNames.size() - 1).getText(); mCurrentProg.mEnums.add(mCurrentEnum); @@ -73,7 +73,7 @@ public class EnumsWalker extends CKEnumsParserBaseListener { // get entry comment mCurrentEntry.mEntryComment = mCommentsFinder.getComment(ctx.getStart(), ctx.getStop()); // get entry name - mCurrentEntry.mEntryName = ctx.CKGENERAL_ID().getText(); + mCurrentEntry.mEntryName = ctx.CKGENERIC_ID().getText(); mCurrentEnum.mEntries.add(mCurrentEntry); mCurrentEntry = null; @@ -82,7 +82,7 @@ public class EnumsWalker extends CKEnumsParserBaseListener { @Override public void exitEntryDirectValue(CKEnumsParser.EntryDirectValueContext ctx) { // get all numbers - List nums = ctx.CKGENERAL_NUM(); + List nums = ctx.CKGENERIC_NUM(); switch (nums.size()) { case 1: { @@ -120,7 +120,7 @@ public class EnumsWalker extends CKEnumsParserBaseListener { @Override public void exitEntryRelativeValue(CKEnumsParser.EntryRelativeValueContext ctx) { // get all identifiers and join them - mCurrentEntry.mEntryValue = ctx.CKGENERAL_ID().stream().map(value -> value.getText()) + mCurrentEntry.mEntryValue = ctx.CKGENERIC_ID().stream().map(value -> value.getText()) .collect(Collectors.joining(" | ")); // | operator appears. this enum must have flags feature diff --git a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/MainRunner.java b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/MainRunner.java index b7044ce..e86e0ed 100644 --- a/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/MainRunner.java +++ b/Assets/CodeGen/EnumsMigration/EnumsAnalyzer/MainRunner.java @@ -19,7 +19,7 @@ public class MainRunner { private static EnumsHelper.BEnumCollection getEnumsCollection(String filename) throws Exception { String infile = CommonHelper.getInputFilePath(filename); CommonHelper.InputFilePair pair = CommonHelper.openInputFile(infile); - CKGeneralLexer lexer = new CKGeneralLexer(pair.mAntlrStream); + CKGenericLexer lexer = new CKGenericLexer(pair.mAntlrStream); CommonTokenStream tokens = new CommonTokenStream(lexer); CKEnumsParser parser = new CKEnumsParser(tokens); @@ -50,7 +50,7 @@ public class MainRunner { private static EnumsHelper.BEnum organiseDefines(String filename, String assignedEnumName) throws Exception { String infile = CommonHelper.getInputFilePath(filename); CommonHelper.InputFilePair pair = CommonHelper.openInputFile(infile); - CKGeneralLexer lexer = new CKGeneralLexer(pair.mAntlrStream); + CKGenericLexer lexer = new CKGenericLexer(pair.mAntlrStream); CommonTokenStream tokens = new CommonTokenStream(lexer); CKDefinesParser parser = new CKDefinesParser(tokens); @@ -85,7 +85,7 @@ public class MainRunner { private static EnumsHelper.BEnum organiseClassid(String filename) throws Exception { String infile = CommonHelper.getInputFilePath(filename); CommonHelper.InputFilePair pair = CommonHelper.openInputFile(infile); - CKGeneralLexer lexer = new CKGeneralLexer(pair.mAntlrStream); + CKGenericLexer lexer = new CKGenericLexer(pair.mAntlrStream); CommonTokenStream tokens = new CommonTokenStream(lexer); CKDefinesParser parser = new CKDefinesParser(tokens); diff --git a/Assets/CodeGen/EnumsMigration/README.md b/Assets/CodeGen/EnumsMigration/README.md index 85ab4bc..ad6ad6b 100644 --- a/Assets/CodeGen/EnumsMigration/README.md +++ b/Assets/CodeGen/EnumsMigration/README.md @@ -26,7 +26,7 @@ And export them as JSON file which will be utilized by Enums Render. Enter `EnumsAnalyzer` directory, and execute following command to generate Antlr lexer and parser: ``` -antlr4 CKGeneralLexer.g4 +antlr4 CKGenericLexer.g4 antlr4 CKEnumsParser.g4 antlr4 CKDefinesParser.g4 ```