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