refactor: rename all general to generic in EnumsAnalyzer
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
*.interp
|
||||
*.tokens
|
||||
|
||||
CKGeneralLexer*.java
|
||||
CKGenericLexer*.java
|
||||
CKEnumsParser*.java
|
||||
CKDefinesParser*.java
|
||||
|
||||
|
||||
@@ -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) ;
|
||||
|
||||
@@ -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
|
||||
;
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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());
|
||||
|
||||
@@ -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<Token> precomment = CommonHelper.getPreChannelTokens(mTokenStream, preToken, CKGeneralLexer.COMMENTS);
|
||||
List<Token> precomment = CommonHelper.getPreChannelTokens(mTokenStream, preToken, CKGenericLexer.COMMENTS);
|
||||
if (precomment != null) {
|
||||
mCommentsPos = CommentsPosition.Precomment;
|
||||
return CommonHelper.cutComments(precomment);
|
||||
}
|
||||
|
||||
List<Token> postcomment = CommonHelper.getPostChannelTokens(mTokenStream, postToken, CKGeneralLexer.COMMENTS);
|
||||
List<Token> 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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<TerminalNode> allNames = ctx.CKGENERAL_ID();
|
||||
List<TerminalNode> 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<TerminalNode> nums = ctx.CKGENERAL_NUM();
|
||||
List<TerminalNode> 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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user