Added channelNames to all runtimes.

This commit is contained in:
Ivan Kochurkin 2017-01-08 17:26:08 +03:00
parent 3e61421e59
commit c3d96eb5d7
12 changed files with 66 additions and 3 deletions

View File

@ -502,7 +502,7 @@ outer_continue: ;
}
}
public virtual string[] ModeNames
public virtual string[] ChannelNames
{
get
{
@ -510,6 +510,13 @@ outer_continue: ;
}
}
public virtual string[] ModeNames
{
get
{
return null;
}
}
/// <summary>Return a list of all Token objects in input char stream.</summary>
/// <remarks>

View File

@ -156,6 +156,8 @@ namespace antlr4 {
virtual size_t getChannel();
virtual const std::vector<std::string>& getChannelNames() const = 0;
virtual const std::vector<std::string>& getModeNames() const = 0;
/// Return a list of all Token objects in input char stream.

View File

@ -320,6 +320,8 @@ public abstract class Lexer extends Recognizer<Integer, LexerATNSimulator>
return _channel;
}
public String[] getChannelNames() { return null; }
public String[] getModeNames() {
return null;
}

View File

@ -331,6 +331,10 @@ open class Lexer: Recognizer<LexerATNSimulator>
return _channel
}
open func getChannelNames() -> [String]? {
return nil
}
open func getModeNames() -> [String]? {
return nil
}

View File

@ -983,6 +983,11 @@ public partial class <csIdentifier.(lexer.name)> : <superClass; null="Lexer"> {
<lexer.channels:{k | <csIdentifier.(k)>=<lexer.channels.(k)>}; separator=", ", wrap, anchor>;
<endif>
<rest(lexer.modes):{m| public const int <modeName.(m)> = <i>;}; separator="\n">
public static string[] channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN", <lexer.channels:{c| "<c>"}; separator=", ", wrap, anchor>
};
public static string[] modeNames = {
<lexer.modes:{m| "<m>"}; separator=", ", wrap, anchor>
};
@ -1005,6 +1010,8 @@ public partial class <csIdentifier.(lexer.name)> : <superClass; null="Lexer"> {
public override string[] RuleNames { get { return ruleNames; } }
public override string[] ChannelNames { get { return channelNames; } }
public override string[] ModeNames { get { return modeNames; } }
public override string SerializedAtn { get { return _serializedATN; } }

View File

@ -70,6 +70,7 @@ public:
virtual std::string getGrammarFileName() const override;
virtual const std::vector\<std::string>& getRuleNames() const override;
virtual const std::vector\<std::string>& getChannelNames() const override;
virtual const std::vector\<std::string>& getModeNames() const override;
virtual const std::vector\<std::string>& getTokenNames() const override; // deprecated, use vocabulary instead
virtual antlr4::dfa::Vocabulary& getVocabulary() const override;
@ -89,6 +90,7 @@ private:
static antlr4::atn::PredictionContextCache _sharedContextCache;
static std::vector\<std::string> _ruleNames;
static std::vector\<std::string> _tokenNames;
static std::vector\<std::string> _channelNames;
static std::vector\<std::string> _modeNames;
static std::vector\<std::string> _literalNames;
@ -128,6 +130,10 @@ const std::vector\<std::string>& <lexer.name>::getRuleNames() const {
return _ruleNames;
}
const std::vector\<std::string>& <lexer.name>::getChannelNames() const {
return _channelNames;
}
const std::vector\<std::string>& <lexer.name>::getModeNames() const {
return _modeNames;
}
@ -189,6 +195,10 @@ std::vector\<std::string> <lexer.name>::_ruleNames = {
<lexer.ruleNames: {r | "<r>"}; separator = ", ", wrap, anchor>
};
std::vector\<std::string> <lexer.name>::_channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN", <lexer.channels: {c | "<c>"}; separator = ", ", wrap, anchor>
};
std::vector\<std::string> <lexer.name>::_modeNames = {
<lexer.modes: {m | "<m>"}; separator = ", ", wrap, anchor>
};

View File

@ -1379,6 +1379,14 @@ var serializedLexerAtn []uint16
var lexerDeserializer = antlr.NewATNDeserializer(nil)
var lexerAtn = lexerDeserializer.DeserializeFromUInt16(serializedLexerAtn)
<if(lexer.channels)>
var lexerChannelNames = []string{
"DEFAULT_TOKEN_CHANNEL", "HIDDEN", <lexer.channels:{c | "<c>"}; separator=", ", wrap>,
}
<else>
var lexerChannelNames []string
<endif>
<if(lexer.modes)>
var lexerModeNames = []string{
<lexer.modes:{m | "<m>"}; separator=", ", wrap>,
@ -1387,7 +1395,6 @@ var lexerModeNames = []string{
var lexerModeNames []string
<endif>
<if(lexer.literalNames)>
var lexerLiteralNames = []string{
<lexer.literalNames; null="\"\"", separator=", ", wrap>,
@ -1417,6 +1424,7 @@ var lexerRuleNames []string
type <lexer.name> struct {
*<if(superClass)><superClass><else>antlr.BaseLexer<endif>
channelNames []string
modeNames []string
// TODO: EOF string
}
@ -1433,6 +1441,7 @@ func New<lexer.name>(input antlr.CharStream) *<lexer.name> {
l.BaseLexer = antlr.NewBaseLexer(input)
l.Interpreter = antlr.NewLexerATNSimulator(l, lexerAtn, lexerDecisionToDFA, antlr.NewPredictionContextCache())
l.channelNames = lexerChannelNames
l.modeNames = lexerModeNames
l.RuleNames = lexerRuleNames
l.LiteralNames = lexerLiteralNames

View File

@ -901,6 +901,11 @@ public class <lexer.name> extends <superClass; null="Lexer"> {
<lexer.channels:{k | <k>=<lexer.channels.(k)>}; separator=", ", wrap, anchor>;
<endif>
<rest(lexer.modes):{m| public static final int <m> = <i>;}; separator="\n">
public static String[] channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN", <lexer.channels:{c| "<c>"}; separator=", ", wrap, anchor>
};
public static String[] modeNames = {
<lexer.modes:{m| "<m>"}; separator=", ", wrap, anchor>
};
@ -927,6 +932,9 @@ public class <lexer.name> extends <superClass; null="Lexer"> {
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public String[] getChannelNames() { return channelNames; }
@Override
public String[] getModeNames() { return modeNames; }

View File

@ -823,6 +823,8 @@ function <lexer.name>(input) {
<rest(lexer.modes):{m| <lexer.name>.<m> = <i>;}; separator="\n">
<lexer.name>.prototype.channelNames = [ "DEFAULT_TOKEN_CHANNEL", "HIDDEN", <lexer.channels:{c| "<c>"}; separator=", ", wrap, anchor> ];
<lexer.name>.prototype.modeNames = [ <lexer.modes:{m| "<m>"}; separator=", ", wrap, anchor> ];
<lexer.name>.prototype.literalNames = [ <lexer.literalNames:{t | <t>}; null="null", separator=", ", wrap, anchor> ];

View File

@ -760,6 +760,8 @@ class <lexer.name>(<if(superClass)><superClass><else>Lexer<endif>):
<lexer.tokens:{k | <k> = <lexer.tokens.(k)>}; separator="\n", wrap, anchor>
channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN", <lexer.channels:{c| u"<c>"}; separator=", ", wrap, anchor> ]
modeNames = [ <lexer.modes:{m| u"<m>"}; separator=", ", wrap, anchor> ]
literalNames = [ u"\<INVALID>",

View File

@ -765,6 +765,8 @@ class <lexer.name>(<if(superClass)><superClass><else>Lexer<endif>):
<lexer.tokens:{k | <k> = <lexer.tokens.(k)>}; separator="\n", wrap, anchor>
channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN", <lexer.channels:{c| u"<c>"}; separator=", ", wrap, anchor> ]
modeNames = [ <lexer.modes:{m| "<m>"}; separator=", ", wrap, anchor> ]
literalNames = [ "\<INVALID>",

View File

@ -962,9 +962,14 @@ open class <lexer.name>: <superClass; null="Lexer"> {
internal static let _sharedContextCache:PredictionContextCache = PredictionContextCache()
public static let <lexer.tokens:{k | <k>=<lexer.tokens.(k)>}; separator=", ", wrap, anchor>
<if(lexer.channels)>
public let <lexer.channels:{k | <k>=<lexer.channels.(k)>}; separator=", ", wrap, anchor>
public static let <lexer.channels:{k | <k>=<lexer.channels.(k)>}; separator=", ", wrap, anchor>
<endif>
<rest(lexer.modes):{m| public static let <m>: Int = <i>;}; separator="\n">
public static let channelNames: [String] = [
"DEFAULT_TOKEN_CHANNEL", "HIDDEN", <lexer.channels:{c| "<c>"}; separator=", ", wrap, anchor>
]
public static let modeNames: [String] = [
<lexer.modes:{m| "<m>"}; separator=", ", wrap, anchor>
]
@ -995,6 +1000,9 @@ open class <lexer.name>: <superClass; null="Lexer"> {
override
open func getSerializedATN() -> String { return <lexer.name>._serializedATN }
override
open func getChannelNames() -> [String] { return <lexer.name>.channelNames }
override
open func getModeNames() -> [String] { return <lexer.name>.modeNames }