From 4bc1b78a91c8190f15794c3fc2c836f798a5b22a Mon Sep 17 00:00:00 2001 From: anqiansong Date: Fri, 3 Mar 2023 12:09:15 +0800 Subject: [PATCH] Fix #2879 --- tools/goctl/api/parser/g4/gen/ApiLexer.interp | 59 ++++ tools/goctl/api/parser/g4/gen/ApiLexer.java | 253 ++++++++++++++++++ tools/goctl/api/parser/g4/gen/ApiLexer.tokens | 16 ++ tools/goctl/rpc/generator/gencall.go | 66 +++-- 4 files changed, 370 insertions(+), 24 deletions(-) create mode 100644 tools/goctl/api/parser/g4/gen/ApiLexer.interp create mode 100644 tools/goctl/api/parser/g4/gen/ApiLexer.java create mode 100644 tools/goctl/api/parser/g4/gen/ApiLexer.tokens diff --git a/tools/goctl/api/parser/g4/gen/ApiLexer.interp b/tools/goctl/api/parser/g4/gen/ApiLexer.interp new file mode 100644 index 00000000..a657f080 --- /dev/null +++ b/tools/goctl/api/parser/g4/gen/ApiLexer.interp @@ -0,0 +1,59 @@ +token literal names: +null +'@doc' +'@handler' +'interface{}' +'@server' +null +null +null +null +null +null +null +null + +token symbolic names: +null +ATDOC +ATHANDLER +INTERFACE +ATSERVER +WS +COMMENT +LINE_COMMENT +STRING +RAW_STRING +LINE_VALUE +ID +LetterOrDigit + +rule names: +ATDOC +ATHANDLER +INTERFACE +ATSERVER +WS +COMMENT +LINE_COMMENT +STRING +RAW_STRING +LINE_VALUE +ID +LetterOrDigit +ExponentPart +EscapeSequence +HexDigits +HexDigit +Digits +Letter + +channel names: +DEFAULT_TOKEN_CHANNEL +HIDDEN + +mode names: +DEFAULT_MODE + +atn: +[4, 0, 12, 207, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 4, 4, 4, 73, 8, 4, 11, 4, 12, 4, 74, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 5, 5, 83, 8, 5, 10, 5, 12, 5, 86, 9, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 5, 6, 97, 8, 6, 10, 6, 12, 6, 100, 9, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 5, 7, 107, 8, 7, 10, 7, 12, 7, 110, 9, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 4, 8, 117, 8, 8, 11, 8, 12, 8, 118, 1, 8, 1, 8, 1, 9, 1, 9, 5, 9, 125, 8, 9, 10, 9, 12, 9, 128, 9, 9, 1, 9, 1, 9, 5, 9, 132, 8, 9, 10, 9, 12, 9, 135, 9, 9, 3, 9, 137, 8, 9, 1, 10, 1, 10, 5, 10, 141, 8, 10, 10, 10, 12, 10, 144, 9, 10, 1, 11, 1, 11, 3, 11, 148, 8, 11, 1, 12, 1, 12, 3, 12, 152, 8, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 13, 3, 13, 160, 8, 13, 1, 13, 3, 13, 163, 8, 13, 1, 13, 1, 13, 1, 13, 4, 13, 168, 8, 13, 11, 13, 12, 13, 169, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 3, 13, 177, 8, 13, 1, 14, 1, 14, 1, 14, 5, 14, 182, 8, 14, 10, 14, 12, 14, 185, 9, 14, 1, 14, 3, 14, 188, 8, 14, 1, 15, 1, 15, 1, 16, 1, 16, 5, 16, 194, 8, 16, 10, 16, 12, 16, 197, 9, 16, 1, 16, 3, 16, 200, 8, 16, 1, 17, 1, 17, 1, 17, 1, 17, 3, 17, 206, 8, 17, 1, 84, 0, 18, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 0, 27, 0, 29, 0, 31, 0, 33, 0, 35, 0, 1, 0, 18, 3, 0, 9, 10, 12, 13, 32, 32, 2, 0, 10, 10, 13, 13, 2, 0, 34, 34, 92, 92, 4, 0, 10, 10, 13, 13, 92, 92, 96, 96, 2, 0, 9, 9, 32, 32, 4, 0, 10, 10, 13, 13, 34, 34, 96, 96, 1, 0, 48, 57, 2, 0, 69, 69, 101, 101, 2, 0, 43, 43, 45, 45, 8, 0, 34, 34, 39, 39, 92, 92, 98, 98, 102, 102, 110, 110, 114, 114, 116, 116, 1, 0, 48, 51, 1, 0, 48, 55, 3, 0, 48, 57, 65, 70, 97, 102, 2, 0, 48, 57, 95, 95, 4, 0, 36, 36, 65, 90, 95, 95, 97, 122, 2, 0, 0, 127, 55296, 56319, 1, 0, 55296, 56319, 1, 0, 56320, 57343, 225, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 1, 37, 1, 0, 0, 0, 3, 42, 1, 0, 0, 0, 5, 51, 1, 0, 0, 0, 7, 63, 1, 0, 0, 0, 9, 72, 1, 0, 0, 0, 11, 78, 1, 0, 0, 0, 13, 92, 1, 0, 0, 0, 15, 103, 1, 0, 0, 0, 17, 113, 1, 0, 0, 0, 19, 122, 1, 0, 0, 0, 21, 138, 1, 0, 0, 0, 23, 147, 1, 0, 0, 0, 25, 149, 1, 0, 0, 0, 27, 176, 1, 0, 0, 0, 29, 178, 1, 0, 0, 0, 31, 189, 1, 0, 0, 0, 33, 191, 1, 0, 0, 0, 35, 205, 1, 0, 0, 0, 37, 38, 5, 64, 0, 0, 38, 39, 5, 100, 0, 0, 39, 40, 5, 111, 0, 0, 40, 41, 5, 99, 0, 0, 41, 2, 1, 0, 0, 0, 42, 43, 5, 64, 0, 0, 43, 44, 5, 104, 0, 0, 44, 45, 5, 97, 0, 0, 45, 46, 5, 110, 0, 0, 46, 47, 5, 100, 0, 0, 47, 48, 5, 108, 0, 0, 48, 49, 5, 101, 0, 0, 49, 50, 5, 114, 0, 0, 50, 4, 1, 0, 0, 0, 51, 52, 5, 105, 0, 0, 52, 53, 5, 110, 0, 0, 53, 54, 5, 116, 0, 0, 54, 55, 5, 101, 0, 0, 55, 56, 5, 114, 0, 0, 56, 57, 5, 102, 0, 0, 57, 58, 5, 97, 0, 0, 58, 59, 5, 99, 0, 0, 59, 60, 5, 101, 0, 0, 60, 61, 5, 123, 0, 0, 61, 62, 5, 125, 0, 0, 62, 6, 1, 0, 0, 0, 63, 64, 5, 64, 0, 0, 64, 65, 5, 115, 0, 0, 65, 66, 5, 101, 0, 0, 66, 67, 5, 114, 0, 0, 67, 68, 5, 118, 0, 0, 68, 69, 5, 101, 0, 0, 69, 70, 5, 114, 0, 0, 70, 8, 1, 0, 0, 0, 71, 73, 7, 0, 0, 0, 72, 71, 1, 0, 0, 0, 73, 74, 1, 0, 0, 0, 74, 72, 1, 0, 0, 0, 74, 75, 1, 0, 0, 0, 75, 76, 1, 0, 0, 0, 76, 77, 6, 4, 0, 0, 77, 10, 1, 0, 0, 0, 78, 79, 5, 47, 0, 0, 79, 80, 5, 42, 0, 0, 80, 84, 1, 0, 0, 0, 81, 83, 9, 0, 0, 0, 82, 81, 1, 0, 0, 0, 83, 86, 1, 0, 0, 0, 84, 85, 1, 0, 0, 0, 84, 82, 1, 0, 0, 0, 85, 87, 1, 0, 0, 0, 86, 84, 1, 0, 0, 0, 87, 88, 5, 42, 0, 0, 88, 89, 5, 47, 0, 0, 89, 90, 1, 0, 0, 0, 90, 91, 6, 5, 1, 0, 91, 12, 1, 0, 0, 0, 92, 93, 5, 47, 0, 0, 93, 94, 5, 47, 0, 0, 94, 98, 1, 0, 0, 0, 95, 97, 8, 1, 0, 0, 96, 95, 1, 0, 0, 0, 97, 100, 1, 0, 0, 0, 98, 96, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 101, 1, 0, 0, 0, 100, 98, 1, 0, 0, 0, 101, 102, 6, 6, 1, 0, 102, 14, 1, 0, 0, 0, 103, 108, 5, 34, 0, 0, 104, 107, 8, 2, 0, 0, 105, 107, 3, 27, 13, 0, 106, 104, 1, 0, 0, 0, 106, 105, 1, 0, 0, 0, 107, 110, 1, 0, 0, 0, 108, 106, 1, 0, 0, 0, 108, 109, 1, 0, 0, 0, 109, 111, 1, 0, 0, 0, 110, 108, 1, 0, 0, 0, 111, 112, 5, 34, 0, 0, 112, 16, 1, 0, 0, 0, 113, 116, 5, 96, 0, 0, 114, 117, 8, 3, 0, 0, 115, 117, 3, 27, 13, 0, 116, 114, 1, 0, 0, 0, 116, 115, 1, 0, 0, 0, 117, 118, 1, 0, 0, 0, 118, 116, 1, 0, 0, 0, 118, 119, 1, 0, 0, 0, 119, 120, 1, 0, 0, 0, 120, 121, 5, 96, 0, 0, 121, 18, 1, 0, 0, 0, 122, 126, 5, 58, 0, 0, 123, 125, 7, 4, 0, 0, 124, 123, 1, 0, 0, 0, 125, 128, 1, 0, 0, 0, 126, 124, 1, 0, 0, 0, 126, 127, 1, 0, 0, 0, 127, 136, 1, 0, 0, 0, 128, 126, 1, 0, 0, 0, 129, 137, 3, 15, 7, 0, 130, 132, 8, 5, 0, 0, 131, 130, 1, 0, 0, 0, 132, 135, 1, 0, 0, 0, 133, 131, 1, 0, 0, 0, 133, 134, 1, 0, 0, 0, 134, 137, 1, 0, 0, 0, 135, 133, 1, 0, 0, 0, 136, 129, 1, 0, 0, 0, 136, 133, 1, 0, 0, 0, 137, 20, 1, 0, 0, 0, 138, 142, 3, 35, 17, 0, 139, 141, 3, 23, 11, 0, 140, 139, 1, 0, 0, 0, 141, 144, 1, 0, 0, 0, 142, 140, 1, 0, 0, 0, 142, 143, 1, 0, 0, 0, 143, 22, 1, 0, 0, 0, 144, 142, 1, 0, 0, 0, 145, 148, 3, 35, 17, 0, 146, 148, 7, 6, 0, 0, 147, 145, 1, 0, 0, 0, 147, 146, 1, 0, 0, 0, 148, 24, 1, 0, 0, 0, 149, 151, 7, 7, 0, 0, 150, 152, 7, 8, 0, 0, 151, 150, 1, 0, 0, 0, 151, 152, 1, 0, 0, 0, 152, 153, 1, 0, 0, 0, 153, 154, 3, 33, 16, 0, 154, 26, 1, 0, 0, 0, 155, 156, 5, 92, 0, 0, 156, 177, 7, 9, 0, 0, 157, 162, 5, 92, 0, 0, 158, 160, 7, 10, 0, 0, 159, 158, 1, 0, 0, 0, 159, 160, 1, 0, 0, 0, 160, 161, 1, 0, 0, 0, 161, 163, 7, 11, 0, 0, 162, 159, 1, 0, 0, 0, 162, 163, 1, 0, 0, 0, 163, 164, 1, 0, 0, 0, 164, 177, 7, 11, 0, 0, 165, 167, 5, 92, 0, 0, 166, 168, 5, 117, 0, 0, 167, 166, 1, 0, 0, 0, 168, 169, 1, 0, 0, 0, 169, 167, 1, 0, 0, 0, 169, 170, 1, 0, 0, 0, 170, 171, 1, 0, 0, 0, 171, 172, 3, 31, 15, 0, 172, 173, 3, 31, 15, 0, 173, 174, 3, 31, 15, 0, 174, 175, 3, 31, 15, 0, 175, 177, 1, 0, 0, 0, 176, 155, 1, 0, 0, 0, 176, 157, 1, 0, 0, 0, 176, 165, 1, 0, 0, 0, 177, 28, 1, 0, 0, 0, 178, 187, 3, 31, 15, 0, 179, 182, 3, 31, 15, 0, 180, 182, 5, 95, 0, 0, 181, 179, 1, 0, 0, 0, 181, 180, 1, 0, 0, 0, 182, 185, 1, 0, 0, 0, 183, 181, 1, 0, 0, 0, 183, 184, 1, 0, 0, 0, 184, 186, 1, 0, 0, 0, 185, 183, 1, 0, 0, 0, 186, 188, 3, 31, 15, 0, 187, 183, 1, 0, 0, 0, 187, 188, 1, 0, 0, 0, 188, 30, 1, 0, 0, 0, 189, 190, 7, 12, 0, 0, 190, 32, 1, 0, 0, 0, 191, 199, 7, 6, 0, 0, 192, 194, 7, 13, 0, 0, 193, 192, 1, 0, 0, 0, 194, 197, 1, 0, 0, 0, 195, 193, 1, 0, 0, 0, 195, 196, 1, 0, 0, 0, 196, 198, 1, 0, 0, 0, 197, 195, 1, 0, 0, 0, 198, 200, 7, 6, 0, 0, 199, 195, 1, 0, 0, 0, 199, 200, 1, 0, 0, 0, 200, 34, 1, 0, 0, 0, 201, 206, 7, 14, 0, 0, 202, 206, 8, 15, 0, 0, 203, 204, 7, 16, 0, 0, 204, 206, 7, 17, 0, 0, 205, 201, 1, 0, 0, 0, 205, 202, 1, 0, 0, 0, 205, 203, 1, 0, 0, 0, 206, 36, 1, 0, 0, 0, 24, 0, 74, 84, 98, 106, 108, 116, 118, 126, 133, 136, 142, 147, 151, 159, 162, 169, 176, 181, 183, 187, 195, 199, 205, 2, 0, 1, 0, 0, 88, 0] \ No newline at end of file diff --git a/tools/goctl/api/parser/g4/gen/ApiLexer.java b/tools/goctl/api/parser/g4/gen/ApiLexer.java new file mode 100644 index 00000000..41d23836 --- /dev/null +++ b/tools/goctl/api/parser/g4/gen/ApiLexer.java @@ -0,0 +1,253 @@ +// Generated from java-escape by ANTLR 4.11.1 +import org.antlr.v4.runtime.Lexer; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.TokenStream; +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.atn.*; +import org.antlr.v4.runtime.dfa.DFA; +import org.antlr.v4.runtime.misc.*; + +@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"}) +public class ApiLexer extends Lexer { + static { RuntimeMetaData.checkVersion("4.11.1", RuntimeMetaData.VERSION); } + + protected static final DFA[] _decisionToDFA; + protected static final PredictionContextCache _sharedContextCache = + new PredictionContextCache(); + public static final int + ATDOC=1, ATHANDLER=2, INTERFACE=3, ATSERVER=4, WS=5, COMMENT=6, LINE_COMMENT=7, + STRING=8, RAW_STRING=9, LINE_VALUE=10, ID=11, LetterOrDigit=12; + public static String[] channelNames = { + "DEFAULT_TOKEN_CHANNEL", "HIDDEN" + }; + + public static String[] modeNames = { + "DEFAULT_MODE" + }; + + private static String[] makeRuleNames() { + return new String[] { + "ATDOC", "ATHANDLER", "INTERFACE", "ATSERVER", "WS", "COMMENT", "LINE_COMMENT", + "STRING", "RAW_STRING", "LINE_VALUE", "ID", "LetterOrDigit", "ExponentPart", + "EscapeSequence", "HexDigits", "HexDigit", "Digits", "Letter" + }; + } + public static final String[] ruleNames = makeRuleNames(); + + private static String[] makeLiteralNames() { + return new String[] { + null, "'@doc'", "'@handler'", "'interface{}'", "'@server'" + }; + } + private static final String[] _LITERAL_NAMES = makeLiteralNames(); + private static String[] makeSymbolicNames() { + return new String[] { + null, "ATDOC", "ATHANDLER", "INTERFACE", "ATSERVER", "WS", "COMMENT", + "LINE_COMMENT", "STRING", "RAW_STRING", "LINE_VALUE", "ID", "LetterOrDigit" + }; + } + private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames(); + public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); + + /** + * @deprecated Use {@link #VOCABULARY} instead. + */ + @Deprecated + public static final String[] tokenNames; + static { + tokenNames = new String[_SYMBOLIC_NAMES.length]; + for (int i = 0; i < tokenNames.length; i++) { + tokenNames[i] = VOCABULARY.getLiteralName(i); + if (tokenNames[i] == null) { + tokenNames[i] = VOCABULARY.getSymbolicName(i); + } + + if (tokenNames[i] == null) { + tokenNames[i] = ""; + } + } + } + + @Override + @Deprecated + public String[] getTokenNames() { + return tokenNames; + } + + @Override + + public Vocabulary getVocabulary() { + return VOCABULARY; + } + + + public ApiLexer(CharStream input) { + super(input); + _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); + } + + @Override + public String getGrammarFileName() { return "ApiLexer.g4"; } + + @Override + public String[] getRuleNames() { return ruleNames; } + + @Override + public String getSerializedATN() { return _serializedATN; } + + @Override + public String[] getChannelNames() { return channelNames; } + + @Override + public String[] getModeNames() { return modeNames; } + + @Override + public ATN getATN() { return _ATN; } + + public static final String _serializedATN = + "\u0004\u0000\f\u00cf\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002\u0001"+ + "\u0007\u0001\u0002\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004"+ + "\u0007\u0004\u0002\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002\u0007"+ + "\u0007\u0007\u0002\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0002\u000b"+ + "\u0007\u000b\u0002\f\u0007\f\u0002\r\u0007\r\u0002\u000e\u0007\u000e\u0002"+ + "\u000f\u0007\u000f\u0002\u0010\u0007\u0010\u0002\u0011\u0007\u0011\u0001"+ + "\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0001\u0001"+ + "\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+ + "\u0001\u0001\u0001\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001"+ + "\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001"+ + "\u0002\u0001\u0002\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001"+ + "\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0004\u0004\u0004I\b"+ + "\u0004\u000b\u0004\f\u0004J\u0001\u0004\u0001\u0004\u0001\u0005\u0001"+ + "\u0005\u0001\u0005\u0001\u0005\u0005\u0005S\b\u0005\n\u0005\f\u0005V\t"+ + "\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001"+ + "\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0005\u0006a\b\u0006\n\u0006"+ + "\f\u0006d\t\u0006\u0001\u0006\u0001\u0006\u0001\u0007\u0001\u0007\u0001"+ + "\u0007\u0005\u0007k\b\u0007\n\u0007\f\u0007n\t\u0007\u0001\u0007\u0001"+ + "\u0007\u0001\b\u0001\b\u0001\b\u0004\bu\b\b\u000b\b\f\bv\u0001\b\u0001"+ + "\b\u0001\t\u0001\t\u0005\t}\b\t\n\t\f\t\u0080\t\t\u0001\t\u0001\t\u0005"+ + "\t\u0084\b\t\n\t\f\t\u0087\t\t\u0003\t\u0089\b\t\u0001\n\u0001\n\u0005"+ + "\n\u008d\b\n\n\n\f\n\u0090\t\n\u0001\u000b\u0001\u000b\u0003\u000b\u0094"+ + "\b\u000b\u0001\f\u0001\f\u0003\f\u0098\b\f\u0001\f\u0001\f\u0001\r\u0001"+ + "\r\u0001\r\u0001\r\u0003\r\u00a0\b\r\u0001\r\u0003\r\u00a3\b\r\u0001\r"+ + "\u0001\r\u0001\r\u0004\r\u00a8\b\r\u000b\r\f\r\u00a9\u0001\r\u0001\r\u0001"+ + "\r\u0001\r\u0001\r\u0003\r\u00b1\b\r\u0001\u000e\u0001\u000e\u0001\u000e"+ + "\u0005\u000e\u00b6\b\u000e\n\u000e\f\u000e\u00b9\t\u000e\u0001\u000e\u0003"+ + "\u000e\u00bc\b\u000e\u0001\u000f\u0001\u000f\u0001\u0010\u0001\u0010\u0005"+ + "\u0010\u00c2\b\u0010\n\u0010\f\u0010\u00c5\t\u0010\u0001\u0010\u0003\u0010"+ + "\u00c8\b\u0010\u0001\u0011\u0001\u0011\u0001\u0011\u0001\u0011\u0003\u0011"+ + "\u00ce\b\u0011\u0001T\u0000\u0012\u0001\u0001\u0003\u0002\u0005\u0003"+ + "\u0007\u0004\t\u0005\u000b\u0006\r\u0007\u000f\b\u0011\t\u0013\n\u0015"+ + "\u000b\u0017\f\u0019\u0000\u001b\u0000\u001d\u0000\u001f\u0000!\u0000"+ + "#\u0000\u0001\u0000\u0012\u0003\u0000\t\n\f\r \u0002\u0000\n\n\r\r\u0002"+ + "\u0000\"\"\\\\\u0004\u0000\n\n\r\r\\\\``\u0002\u0000\t\t \u0004\u0000"+ + "\n\n\r\r\"\"``\u0001\u000009\u0002\u0000EEee\u0002\u0000++--\b\u0000\""+ + "\"\'\'\\\\bbffnnrrtt\u0001\u000003\u0001\u000007\u0003\u000009AFaf\u0002"+ + "\u000009__\u0004\u0000$$AZ__az\u0002\u0000\u0000\u007f\u8000\ud800\u8000"+ + "\udbff\u0001\u0000\u8000\ud800\u8000\udbff\u0001\u0000\u8000\udc00\u8000"+ + "\udfff\u00e1\u0000\u0001\u0001\u0000\u0000\u0000\u0000\u0003\u0001\u0000"+ + "\u0000\u0000\u0000\u0005\u0001\u0000\u0000\u0000\u0000\u0007\u0001\u0000"+ + "\u0000\u0000\u0000\t\u0001\u0000\u0000\u0000\u0000\u000b\u0001\u0000\u0000"+ + "\u0000\u0000\r\u0001\u0000\u0000\u0000\u0000\u000f\u0001\u0000\u0000\u0000"+ + "\u0000\u0011\u0001\u0000\u0000\u0000\u0000\u0013\u0001\u0000\u0000\u0000"+ + "\u0000\u0015\u0001\u0000\u0000\u0000\u0000\u0017\u0001\u0000\u0000\u0000"+ + "\u0001%\u0001\u0000\u0000\u0000\u0003*\u0001\u0000\u0000\u0000\u00053"+ + "\u0001\u0000\u0000\u0000\u0007?\u0001\u0000\u0000\u0000\tH\u0001\u0000"+ + "\u0000\u0000\u000bN\u0001\u0000\u0000\u0000\r\\\u0001\u0000\u0000\u0000"+ + "\u000fg\u0001\u0000\u0000\u0000\u0011q\u0001\u0000\u0000\u0000\u0013z"+ + "\u0001\u0000\u0000\u0000\u0015\u008a\u0001\u0000\u0000\u0000\u0017\u0093"+ + "\u0001\u0000\u0000\u0000\u0019\u0095\u0001\u0000\u0000\u0000\u001b\u00b0"+ + "\u0001\u0000\u0000\u0000\u001d\u00b2\u0001\u0000\u0000\u0000\u001f\u00bd"+ + "\u0001\u0000\u0000\u0000!\u00bf\u0001\u0000\u0000\u0000#\u00cd\u0001\u0000"+ + "\u0000\u0000%&\u0005@\u0000\u0000&\'\u0005d\u0000\u0000\'(\u0005o\u0000"+ + "\u0000()\u0005c\u0000\u0000)\u0002\u0001\u0000\u0000\u0000*+\u0005@\u0000"+ + "\u0000+,\u0005h\u0000\u0000,-\u0005a\u0000\u0000-.\u0005n\u0000\u0000"+ + "./\u0005d\u0000\u0000/0\u0005l\u0000\u000001\u0005e\u0000\u000012\u0005"+ + "r\u0000\u00002\u0004\u0001\u0000\u0000\u000034\u0005i\u0000\u000045\u0005"+ + "n\u0000\u000056\u0005t\u0000\u000067\u0005e\u0000\u000078\u0005r\u0000"+ + "\u000089\u0005f\u0000\u00009:\u0005a\u0000\u0000:;\u0005c\u0000\u0000"+ + ";<\u0005e\u0000\u0000<=\u0005{\u0000\u0000=>\u0005}\u0000\u0000>\u0006"+ + "\u0001\u0000\u0000\u0000?@\u0005@\u0000\u0000@A\u0005s\u0000\u0000AB\u0005"+ + "e\u0000\u0000BC\u0005r\u0000\u0000CD\u0005v\u0000\u0000DE\u0005e\u0000"+ + "\u0000EF\u0005r\u0000\u0000F\b\u0001\u0000\u0000\u0000GI\u0007\u0000\u0000"+ + "\u0000HG\u0001\u0000\u0000\u0000IJ\u0001\u0000\u0000\u0000JH\u0001\u0000"+ + "\u0000\u0000JK\u0001\u0000\u0000\u0000KL\u0001\u0000\u0000\u0000LM\u0006"+ + "\u0004\u0000\u0000M\n\u0001\u0000\u0000\u0000NO\u0005/\u0000\u0000OP\u0005"+ + "*\u0000\u0000PT\u0001\u0000\u0000\u0000QS\t\u0000\u0000\u0000RQ\u0001"+ + "\u0000\u0000\u0000SV\u0001\u0000\u0000\u0000TU\u0001\u0000\u0000\u0000"+ + "TR\u0001\u0000\u0000\u0000UW\u0001\u0000\u0000\u0000VT\u0001\u0000\u0000"+ + "\u0000WX\u0005*\u0000\u0000XY\u0005/\u0000\u0000YZ\u0001\u0000\u0000\u0000"+ + "Z[\u0006\u0005\u0001\u0000[\f\u0001\u0000\u0000\u0000\\]\u0005/\u0000"+ + "\u0000]^\u0005/\u0000\u0000^b\u0001\u0000\u0000\u0000_a\b\u0001\u0000"+ + "\u0000`_\u0001\u0000\u0000\u0000ad\u0001\u0000\u0000\u0000b`\u0001\u0000"+ + "\u0000\u0000bc\u0001\u0000\u0000\u0000ce\u0001\u0000\u0000\u0000db\u0001"+ + "\u0000\u0000\u0000ef\u0006\u0006\u0001\u0000f\u000e\u0001\u0000\u0000"+ + "\u0000gl\u0005\"\u0000\u0000hk\b\u0002\u0000\u0000ik\u0003\u001b\r\u0000"+ + "jh\u0001\u0000\u0000\u0000ji\u0001\u0000\u0000\u0000kn\u0001\u0000\u0000"+ + "\u0000lj\u0001\u0000\u0000\u0000lm\u0001\u0000\u0000\u0000mo\u0001\u0000"+ + "\u0000\u0000nl\u0001\u0000\u0000\u0000op\u0005\"\u0000\u0000p\u0010\u0001"+ + "\u0000\u0000\u0000qt\u0005`\u0000\u0000ru\b\u0003\u0000\u0000su\u0003"+ + "\u001b\r\u0000tr\u0001\u0000\u0000\u0000ts\u0001\u0000\u0000\u0000uv\u0001"+ + "\u0000\u0000\u0000vt\u0001\u0000\u0000\u0000vw\u0001\u0000\u0000\u0000"+ + "wx\u0001\u0000\u0000\u0000xy\u0005`\u0000\u0000y\u0012\u0001\u0000\u0000"+ + "\u0000z~\u0005:\u0000\u0000{}\u0007\u0004\u0000\u0000|{\u0001\u0000\u0000"+ + "\u0000}\u0080\u0001\u0000\u0000\u0000~|\u0001\u0000\u0000\u0000~\u007f"+ + "\u0001\u0000\u0000\u0000\u007f\u0088\u0001\u0000\u0000\u0000\u0080~\u0001"+ + "\u0000\u0000\u0000\u0081\u0089\u0003\u000f\u0007\u0000\u0082\u0084\b\u0005"+ + "\u0000\u0000\u0083\u0082\u0001\u0000\u0000\u0000\u0084\u0087\u0001\u0000"+ + "\u0000\u0000\u0085\u0083\u0001\u0000\u0000\u0000\u0085\u0086\u0001\u0000"+ + "\u0000\u0000\u0086\u0089\u0001\u0000\u0000\u0000\u0087\u0085\u0001\u0000"+ + "\u0000\u0000\u0088\u0081\u0001\u0000\u0000\u0000\u0088\u0085\u0001\u0000"+ + "\u0000\u0000\u0089\u0014\u0001\u0000\u0000\u0000\u008a\u008e\u0003#\u0011"+ + "\u0000\u008b\u008d\u0003\u0017\u000b\u0000\u008c\u008b\u0001\u0000\u0000"+ + "\u0000\u008d\u0090\u0001\u0000\u0000\u0000\u008e\u008c\u0001\u0000\u0000"+ + "\u0000\u008e\u008f\u0001\u0000\u0000\u0000\u008f\u0016\u0001\u0000\u0000"+ + "\u0000\u0090\u008e\u0001\u0000\u0000\u0000\u0091\u0094\u0003#\u0011\u0000"+ + "\u0092\u0094\u0007\u0006\u0000\u0000\u0093\u0091\u0001\u0000\u0000\u0000"+ + "\u0093\u0092\u0001\u0000\u0000\u0000\u0094\u0018\u0001\u0000\u0000\u0000"+ + "\u0095\u0097\u0007\u0007\u0000\u0000\u0096\u0098\u0007\b\u0000\u0000\u0097"+ + "\u0096\u0001\u0000\u0000\u0000\u0097\u0098\u0001\u0000\u0000\u0000\u0098"+ + "\u0099\u0001\u0000\u0000\u0000\u0099\u009a\u0003!\u0010\u0000\u009a\u001a"+ + "\u0001\u0000\u0000\u0000\u009b\u009c\u0005\\\u0000\u0000\u009c\u00b1\u0007"+ + "\t\u0000\u0000\u009d\u00a2\u0005\\\u0000\u0000\u009e\u00a0\u0007\n\u0000"+ + "\u0000\u009f\u009e\u0001\u0000\u0000\u0000\u009f\u00a0\u0001\u0000\u0000"+ + "\u0000\u00a0\u00a1\u0001\u0000\u0000\u0000\u00a1\u00a3\u0007\u000b\u0000"+ + "\u0000\u00a2\u009f\u0001\u0000\u0000\u0000\u00a2\u00a3\u0001\u0000\u0000"+ + "\u0000\u00a3\u00a4\u0001\u0000\u0000\u0000\u00a4\u00b1\u0007\u000b\u0000"+ + "\u0000\u00a5\u00a7\u0005\\\u0000\u0000\u00a6\u00a8\u0005u\u0000\u0000"+ + "\u00a7\u00a6\u0001\u0000\u0000\u0000\u00a8\u00a9\u0001\u0000\u0000\u0000"+ + "\u00a9\u00a7\u0001\u0000\u0000\u0000\u00a9\u00aa\u0001\u0000\u0000\u0000"+ + "\u00aa\u00ab\u0001\u0000\u0000\u0000\u00ab\u00ac\u0003\u001f\u000f\u0000"+ + "\u00ac\u00ad\u0003\u001f\u000f\u0000\u00ad\u00ae\u0003\u001f\u000f\u0000"+ + "\u00ae\u00af\u0003\u001f\u000f\u0000\u00af\u00b1\u0001\u0000\u0000\u0000"+ + "\u00b0\u009b\u0001\u0000\u0000\u0000\u00b0\u009d\u0001\u0000\u0000\u0000"+ + "\u00b0\u00a5\u0001\u0000\u0000\u0000\u00b1\u001c\u0001\u0000\u0000\u0000"+ + "\u00b2\u00bb\u0003\u001f\u000f\u0000\u00b3\u00b6\u0003\u001f\u000f\u0000"+ + "\u00b4\u00b6\u0005_\u0000\u0000\u00b5\u00b3\u0001\u0000\u0000\u0000\u00b5"+ + "\u00b4\u0001\u0000\u0000\u0000\u00b6\u00b9\u0001\u0000\u0000\u0000\u00b7"+ + "\u00b5\u0001\u0000\u0000\u0000\u00b7\u00b8\u0001\u0000\u0000\u0000\u00b8"+ + "\u00ba\u0001\u0000\u0000\u0000\u00b9\u00b7\u0001\u0000\u0000\u0000\u00ba"+ + "\u00bc\u0003\u001f\u000f\u0000\u00bb\u00b7\u0001\u0000\u0000\u0000\u00bb"+ + "\u00bc\u0001\u0000\u0000\u0000\u00bc\u001e\u0001\u0000\u0000\u0000\u00bd"+ + "\u00be\u0007\f\u0000\u0000\u00be \u0001\u0000\u0000\u0000\u00bf\u00c7"+ + "\u0007\u0006\u0000\u0000\u00c0\u00c2\u0007\r\u0000\u0000\u00c1\u00c0\u0001"+ + "\u0000\u0000\u0000\u00c2\u00c5\u0001\u0000\u0000\u0000\u00c3\u00c1\u0001"+ + "\u0000\u0000\u0000\u00c3\u00c4\u0001\u0000\u0000\u0000\u00c4\u00c6\u0001"+ + "\u0000\u0000\u0000\u00c5\u00c3\u0001\u0000\u0000\u0000\u00c6\u00c8\u0007"+ + "\u0006\u0000\u0000\u00c7\u00c3\u0001\u0000\u0000\u0000\u00c7\u00c8\u0001"+ + "\u0000\u0000\u0000\u00c8\"\u0001\u0000\u0000\u0000\u00c9\u00ce\u0007\u000e"+ + "\u0000\u0000\u00ca\u00ce\b\u000f\u0000\u0000\u00cb\u00cc\u0007\u0010\u0000"+ + "\u0000\u00cc\u00ce\u0007\u0011\u0000\u0000\u00cd\u00c9\u0001\u0000\u0000"+ + "\u0000\u00cd\u00ca\u0001\u0000\u0000\u0000\u00cd\u00cb\u0001\u0000\u0000"+ + "\u0000\u00ce$\u0001\u0000\u0000\u0000\u0018\u0000JTbjltv~\u0085\u0088"+ + "\u008e\u0093\u0097\u009f\u00a2\u00a9\u00b0\u00b5\u00b7\u00bb\u00c3\u00c7"+ + "\u00cd\u0002\u0000\u0001\u0000\u0000X\u0000"; + public static final ATN _ATN = + new ATNDeserializer().deserialize(_serializedATN.toCharArray()); + static { + _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; + for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { + _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); + } + } +} \ No newline at end of file diff --git a/tools/goctl/api/parser/g4/gen/ApiLexer.tokens b/tools/goctl/api/parser/g4/gen/ApiLexer.tokens new file mode 100644 index 00000000..7fc4324a --- /dev/null +++ b/tools/goctl/api/parser/g4/gen/ApiLexer.tokens @@ -0,0 +1,16 @@ +ATDOC=1 +ATHANDLER=2 +INTERFACE=3 +ATSERVER=4 +WS=5 +COMMENT=6 +LINE_COMMENT=7 +STRING=8 +RAW_STRING=9 +LINE_VALUE=10 +ID=11 +LetterOrDigit=12 +'@doc'=1 +'@handler'=2 +'interface{}'=3 +'@server'=4 diff --git a/tools/goctl/rpc/generator/gencall.go b/tools/goctl/rpc/generator/gencall.go index 6d3d38b2..58eeb996 100644 --- a/tools/goctl/rpc/generator/gencall.go +++ b/tools/goctl/rpc/generator/gencall.go @@ -9,6 +9,7 @@ import ( "github.com/emicklei/proto" "github.com/zeromicro/go-zero/core/collection" + conf "github.com/zeromicro/go-zero/tools/goctl/config" "github.com/zeromicro/go-zero/tools/goctl/rpc/parser" "github.com/zeromicro/go-zero/tools/goctl/util" @@ -63,7 +64,24 @@ func (g *Generator) genCallGroup(ctx DirContext, proto parser.Proto, cfg *conf.C isCallPkgSameToPbPkg := childDir == ctx.GetProtoGo().Filename isCallPkgSameToGrpcPkg := childDir == ctx.GetProtoGo().Filename - functions, err := g.genFunction(proto.PbPackage, service, isCallPkgSameToGrpcPkg) + serviceName := stringx.From(service.Name).ToCamel() + alias := collection.NewSet() + var hasSameNameBetweenMessageAndService bool + for _, item := range proto.Message { + msgName := getMessageName(*item.Message) + if serviceName == msgName { + hasSameNameBetweenMessageAndService = true + } + if !isCallPkgSameToPbPkg { + alias.AddStr(fmt.Sprintf("%s = %s", parser.CamelCase(msgName), + fmt.Sprintf("%s.%s", proto.PbPackage, parser.CamelCase(msgName)))) + } + } + if hasSameNameBetweenMessageAndService { + serviceName = stringx.From(service.Name + "_zrpc_client").ToCamel() + } + + functions, err := g.genFunction(proto.PbPackage, serviceName, service, isCallPkgSameToGrpcPkg) if err != nil { return err } @@ -78,15 +96,6 @@ func (g *Generator) genCallGroup(ctx DirContext, proto parser.Proto, cfg *conf.C return err } - alias := collection.NewSet() - if !isCallPkgSameToPbPkg { - for _, item := range proto.Message { - msgName := getMessageName(*item.Message) - alias.AddStr(fmt.Sprintf("%s = %s", parser.CamelCase(msgName), - fmt.Sprintf("%s.%s", proto.PbPackage, parser.CamelCase(msgName)))) - } - } - pbPackage := fmt.Sprintf(`"%s"`, ctx.GetPb().Package) protoGoPackage := fmt.Sprintf(`"%s"`, ctx.GetProtoGo().Package) if isCallPkgSameToGrpcPkg { @@ -103,7 +112,7 @@ func (g *Generator) genCallGroup(ctx DirContext, proto parser.Proto, cfg *conf.C "filePackage": dir.Base, "pbPackage": pbPackage, "protoGoPackage": protoGoPackage, - "serviceName": stringx.From(service.Name).ToCamel(), + "serviceName": serviceName, "functions": strings.Join(functions, pathx.NL), "interface": strings.Join(iFunctions, pathx.NL), }, filename, true); err != nil { @@ -126,8 +135,26 @@ func (g *Generator) genCallInCompatibility(ctx DirContext, proto parser.Proto, return err } + serviceName := stringx.From(service.Name).ToCamel() + alias := collection.NewSet() + var hasSameNameBetweenMessageAndService bool + for _, item := range proto.Message { + msgName := getMessageName(*item.Message) + if serviceName == msgName { + hasSameNameBetweenMessageAndService = true + } + if !isCallPkgSameToPbPkg { + alias.AddStr(fmt.Sprintf("%s = %s", parser.CamelCase(msgName), + fmt.Sprintf("%s.%s", proto.PbPackage, parser.CamelCase(msgName)))) + } + } + + if hasSameNameBetweenMessageAndService { + serviceName = stringx.From(service.Name + "_zrpc_client").ToCamel() + } + filename := filepath.Join(dir.Filename, fmt.Sprintf("%s.go", callFilename)) - functions, err := g.genFunction(proto.PbPackage, service, isCallPkgSameToGrpcPkg) + functions, err := g.genFunction(proto.PbPackage, serviceName, service, isCallPkgSameToGrpcPkg) if err != nil { return err } @@ -142,15 +169,6 @@ func (g *Generator) genCallInCompatibility(ctx DirContext, proto parser.Proto, return err } - alias := collection.NewSet() - if !isCallPkgSameToPbPkg { - for _, item := range proto.Message { - msgName := getMessageName(*item.Message) - alias.AddStr(fmt.Sprintf("%s = %s", parser.CamelCase(msgName), - fmt.Sprintf("%s.%s", proto.PbPackage, parser.CamelCase(msgName)))) - } - } - pbPackage := fmt.Sprintf(`"%s"`, ctx.GetPb().Package) protoGoPackage := fmt.Sprintf(`"%s"`, ctx.GetProtoGo().Package) if isCallPkgSameToGrpcPkg { @@ -166,7 +184,7 @@ func (g *Generator) genCallInCompatibility(ctx DirContext, proto parser.Proto, "filePackage": dir.Base, "pbPackage": pbPackage, "protoGoPackage": protoGoPackage, - "serviceName": stringx.From(service.Name).ToCamel(), + "serviceName": serviceName, "functions": strings.Join(functions, pathx.NL), "interface": strings.Join(iFunctions, pathx.NL), }, filename, true) @@ -194,7 +212,7 @@ func getMessageName(msg proto.Message) string { return strings.Join(list, "_") } -func (g *Generator) genFunction(goPackage string, service parser.Service, +func (g *Generator) genFunction(goPackage string, serviceName string, service parser.Service, isCallPkgSameToGrpcPkg bool) ([]string, error) { functions := make([]string, 0) @@ -212,7 +230,7 @@ func (g *Generator) genFunction(goPackage string, service parser.Service, parser.CamelCase(rpc.Name), "Client") } buffer, err := util.With("sharedFn").Parse(text).Execute(map[string]any{ - "serviceName": stringx.From(service.Name).ToCamel(), + "serviceName": serviceName, "rpcServiceName": parser.CamelCase(service.Name), "method": parser.CamelCase(rpc.Name), "package": goPackage,