channelNames support in LexerInterpreter (C#, C++, Java, Swift).
This commit is contained in:
parent
8359a998b6
commit
7b8ba3550b
|
@ -21,6 +21,8 @@ namespace Antlr4.Runtime
|
|||
|
||||
private readonly string[] ruleNames;
|
||||
|
||||
private readonly string[] channelNames;
|
||||
|
||||
private readonly string[] modeNames;
|
||||
|
||||
[NotNull]
|
||||
|
@ -29,7 +31,7 @@ namespace Antlr4.Runtime
|
|||
protected DFA[] decisionToDFA;
|
||||
protected PredictionContextCache sharedContextCache = new PredictionContextCache();
|
||||
|
||||
public LexerInterpreter(string grammarFileName, IVocabulary vocabulary, IEnumerable<string> ruleNames, IEnumerable<string> modeNames, ATN atn, ICharStream input)
|
||||
public LexerInterpreter(string grammarFileName, IVocabulary vocabulary, IEnumerable<string> ruleNames, IEnumerable<string> channelNames, IEnumerable<string> modeNames, ATN atn, ICharStream input)
|
||||
: base(input)
|
||||
{
|
||||
if (atn.grammarType != ATNType.Lexer)
|
||||
|
@ -39,6 +41,7 @@ namespace Antlr4.Runtime
|
|||
this.grammarFileName = grammarFileName;
|
||||
this.atn = atn;
|
||||
this.ruleNames = ruleNames.ToArray();
|
||||
this.channelNames = channelNames.ToArray();
|
||||
this.modeNames = modeNames.ToArray();
|
||||
this.vocabulary = vocabulary;
|
||||
this.decisionToDFA = new DFA[atn.NumberOfDecisions];
|
||||
|
@ -73,6 +76,14 @@ namespace Antlr4.Runtime
|
|||
}
|
||||
}
|
||||
|
||||
public override string[] ChannelNames
|
||||
{
|
||||
get
|
||||
{
|
||||
return channelNames;
|
||||
}
|
||||
}
|
||||
|
||||
public override string[] ModeNames
|
||||
{
|
||||
get
|
||||
|
|
|
@ -15,15 +15,16 @@
|
|||
using namespace antlr4;
|
||||
|
||||
LexerInterpreter::LexerInterpreter(const std::string &grammarFileName, const std::vector<std::string> &tokenNames,
|
||||
const std::vector<std::string> &ruleNames, const std::vector<std::string> &modeNames, const atn::ATN &atn,
|
||||
CharStream *input)
|
||||
: LexerInterpreter(grammarFileName, dfa::Vocabulary::fromTokenNames(tokenNames), ruleNames, modeNames, atn, input) {
|
||||
const std::vector<std::string> &ruleNames, const std::vector<std::string> &channelNames, const std::vector<std::string> &modeNames,
|
||||
const atn::ATN &atn, CharStream *input)
|
||||
: LexerInterpreter(grammarFileName, dfa::Vocabulary::fromTokenNames(tokenNames), ruleNames, channelNames, modeNames, atn, input) {
|
||||
}
|
||||
|
||||
LexerInterpreter::LexerInterpreter(const std::string &grammarFileName, const dfa::Vocabulary &vocabulary,
|
||||
const std::vector<std::string> &ruleNames, const std::vector<std::string> &modeNames, const atn::ATN &atn,
|
||||
CharStream *input)
|
||||
: Lexer(input), _grammarFileName(grammarFileName), _atn(atn), _ruleNames(ruleNames), _modeNames(modeNames),
|
||||
const std::vector<std::string> &ruleNames, const std::vector<std::string> &channelNames, const std::vector<std::string> &modeNames,
|
||||
const atn::ATN &atn, CharStream *input)
|
||||
: Lexer(input), _grammarFileName(grammarFileName), _atn(atn), _ruleNames(ruleNames),
|
||||
_channelNames(channelNames), _modeNames(modeNames),
|
||||
_vocabulary(vocabulary) {
|
||||
|
||||
if (_atn.grammarType != atn::ATNType::LEXER) {
|
||||
|
@ -61,6 +62,10 @@ const std::vector<std::string>& LexerInterpreter::getRuleNames() const {
|
|||
return _ruleNames;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& LexerInterpreter::getChannelNames() const {
|
||||
return _channelNames;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& LexerInterpreter::getModeNames() const {
|
||||
return _modeNames;
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@ namespace antlr4 {
|
|||
public:
|
||||
// @deprecated
|
||||
LexerInterpreter(const std::string &grammarFileName, const std::vector<std::string> &tokenNames,
|
||||
const std::vector<std::string> &ruleNames, const std::vector<std::string> &modeNames,
|
||||
const atn::ATN &atn, CharStream *input);
|
||||
const std::vector<std::string> &ruleNames, const std::vector<std::string> &channelNames,
|
||||
const std::vector<std::string> &modeNames, const atn::ATN &atn, CharStream *input);
|
||||
LexerInterpreter(const std::string &grammarFileName, const dfa::Vocabulary &vocabulary,
|
||||
const std::vector<std::string> &ruleNames, const std::vector<std::string> &modeNames,
|
||||
const atn::ATN &atn, CharStream *input);
|
||||
const std::vector<std::string> &ruleNames, const std::vector<std::string> &channelNames,
|
||||
const std::vector<std::string> &modeNames, const atn::ATN &atn, CharStream *input);
|
||||
|
||||
~LexerInterpreter();
|
||||
|
||||
|
@ -27,6 +27,7 @@ namespace antlr4 {
|
|||
virtual std::string getGrammarFileName() const override;
|
||||
virtual const std::vector<std::string>& getTokenNames() 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 dfa::Vocabulary& getVocabulary() const override;
|
||||
|
@ -38,6 +39,7 @@ namespace antlr4 {
|
|||
// @deprecated
|
||||
std::vector<std::string> _tokenNames;
|
||||
const std::vector<std::string> &_ruleNames;
|
||||
const std::vector<std::string> &_channelNames;
|
||||
const std::vector<std::string> &_modeNames;
|
||||
std::vector<dfa::DFA> _decisionToDFA;
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ public class LexerInterpreter extends Lexer {
|
|||
@Deprecated
|
||||
protected final String[] tokenNames;
|
||||
protected final String[] ruleNames;
|
||||
protected final String[] channelNames;
|
||||
protected final String[] modeNames;
|
||||
|
||||
|
||||
|
@ -31,11 +32,11 @@ public class LexerInterpreter extends Lexer {
|
|||
new PredictionContextCache();
|
||||
|
||||
@Deprecated
|
||||
public LexerInterpreter(String grammarFileName, Collection<String> tokenNames, Collection<String> ruleNames, Collection<String> modeNames, ATN atn, CharStream input) {
|
||||
this(grammarFileName, VocabularyImpl.fromTokenNames(tokenNames.toArray(new String[tokenNames.size()])), ruleNames, modeNames, atn, input);
|
||||
public LexerInterpreter(String grammarFileName, Collection<String> tokenNames, Collection<String> ruleNames, Collection<String> channelNames, Collection<String> modeNames, ATN atn, CharStream input) {
|
||||
this(grammarFileName, VocabularyImpl.fromTokenNames(tokenNames.toArray(new String[tokenNames.size()])), ruleNames, channelNames, modeNames, atn, input);
|
||||
}
|
||||
|
||||
public LexerInterpreter(String grammarFileName, Vocabulary vocabulary, Collection<String> ruleNames, Collection<String> modeNames, ATN atn, CharStream input) {
|
||||
public LexerInterpreter(String grammarFileName, Vocabulary vocabulary, Collection<String> ruleNames, Collection<String> channelNames, Collection<String> modeNames, ATN atn, CharStream input) {
|
||||
super(input);
|
||||
|
||||
if (atn.grammarType != ATNType.LEXER) {
|
||||
|
@ -50,6 +51,7 @@ public class LexerInterpreter extends Lexer {
|
|||
}
|
||||
|
||||
this.ruleNames = ruleNames.toArray(new String[ruleNames.size()]);
|
||||
this.channelNames = channelNames.toArray(new String[channelNames.size()]);
|
||||
this.modeNames = modeNames.toArray(new String[modeNames.size()]);
|
||||
this.vocabulary = vocabulary;
|
||||
|
||||
|
@ -81,6 +83,11 @@ public class LexerInterpreter extends Lexer {
|
|||
return ruleNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getChannelNames() {
|
||||
return channelNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getModeNames() {
|
||||
return modeNames;
|
||||
|
|
|
@ -10,6 +10,7 @@ public class LexerInterpreter: Lexer {
|
|||
////@Deprecated
|
||||
internal final var tokenNames: [String?]?
|
||||
internal final var ruleNames: [String]
|
||||
internal final var channelNames: [String]
|
||||
internal final var modeNames: [String]
|
||||
|
||||
|
||||
|
@ -27,11 +28,11 @@ public class LexerInterpreter: Lexer {
|
|||
// self._tokenFactorySourcePair = (self, input);
|
||||
// }
|
||||
//@Deprecated
|
||||
public convenience init(_ grammarFileName: String, _ tokenNames: Array<String?>?, _ ruleNames: Array<String>, _ modeNames: Array<String>, _ atn: ATN, _ input: CharStream) throws {
|
||||
try self.init(grammarFileName, Vocabulary.fromTokenNames(tokenNames), ruleNames, modeNames, atn, input)
|
||||
public convenience init(_ grammarFileName: String, _ tokenNames: Array<String?>?, _ ruleNames: Array<String>, _ channelNames: Array<String>, _ modeNames: Array<String>, _ atn: ATN, _ input: CharStream) throws {
|
||||
try self.init(grammarFileName, Vocabulary.fromTokenNames(tokenNames), ruleNames, channelNames, modeNames, atn, input)
|
||||
}
|
||||
|
||||
public init(_ grammarFileName: String, _ vocabulary: Vocabulary, _ ruleNames: Array<String>, _ modeNames: Array<String>, _ atn: ATN, _ input: CharStream) throws {
|
||||
public init(_ grammarFileName: String, _ vocabulary: Vocabulary, _ ruleNames: Array<String>, _ channelNames: Array<String>, _ modeNames: Array<String>, _ atn: ATN, _ input: CharStream) throws {
|
||||
|
||||
self.grammarFileName = grammarFileName
|
||||
self.atn = atn
|
||||
|
@ -43,6 +44,7 @@ public class LexerInterpreter: Lexer {
|
|||
}
|
||||
|
||||
self.ruleNames = ruleNames
|
||||
self.channelNames = channelNames
|
||||
self.modeNames = modeNames
|
||||
self.vocabulary = vocabulary
|
||||
|
||||
|
@ -83,6 +85,11 @@ public class LexerInterpreter: Lexer {
|
|||
return ruleNames
|
||||
}
|
||||
|
||||
override
|
||||
public func getChannelNames() -> [String] {
|
||||
return channelNames
|
||||
}
|
||||
|
||||
override
|
||||
public func getModeNames() -> [String] {
|
||||
return modeNames
|
||||
|
|
|
@ -1301,7 +1301,11 @@ public class Grammar implements AttributeResolver {
|
|||
|
||||
char[] serializedAtn = ATNSerializer.getSerializedAsChars(atn);
|
||||
ATN deserialized = new ATNDeserializer().deserialize(serializedAtn);
|
||||
return new LexerInterpreter(fileName, getVocabulary(), Arrays.asList(getRuleNames()), ((LexerGrammar)this).modes.keySet(), deserialized, input);
|
||||
List<String> allChannels = new ArrayList<String>();
|
||||
allChannels.add("DEFAULT_TOKEN_CHANNEL");
|
||||
allChannels.add("HIDDEN");
|
||||
allChannels.addAll(channelValueToNameList);
|
||||
return new LexerInterpreter(fileName, getVocabulary(), Arrays.asList(getRuleNames()), allChannels, ((LexerGrammar)this).modes.keySet(), deserialized, input);
|
||||
}
|
||||
|
||||
/** @since 4.5.1 */
|
||||
|
|
Loading…
Reference in New Issue