Merge pull request #2839 from IohannRabeson/cpp_vocabulary_cleanup
[C++ runtime] Improvements of Vocabulary::fromTokenNames
This commit is contained in:
commit
49ac9d066a
|
@ -250,6 +250,7 @@ YYYY/MM/DD, github id, Full name, email
|
|||
2020/04/30, TristonianJones, Tristan Swadell, tswadell@google.com
|
||||
2020/05/25, graknol, Sindre van der Linden, graknol@gmail.com
|
||||
2020/05/31, d-markey, David Markey, dmarkey@free.fr
|
||||
2020/06/04, IohannRabeson, Iohann Rabeson, iotaka6@gmail.com
|
||||
2020/07/01, sha-N, Shan M Mathews, admin@bluestarqatar.com
|
||||
2020/08/22, stevenjohnstone, Steven Johnstone, steven.james.johnstone@gmail.com
|
||||
2020/09/06, ArthurSonzogni, Sonzogni Arthur, arthursonzogni@gmail.com
|
|
@ -22,8 +22,7 @@ Vocabulary::Vocabulary(const std::vector<std::string> &literalNames,
|
|||
// See note here on -1 part: https://github.com/antlr/antlr4/pull/1146
|
||||
}
|
||||
|
||||
Vocabulary::~Vocabulary() {
|
||||
}
|
||||
Vocabulary::~Vocabulary() = default;
|
||||
|
||||
Vocabulary Vocabulary::fromTokenNames(const std::vector<std::string> &tokenNames) {
|
||||
if (tokenNames.empty()) {
|
||||
|
@ -34,25 +33,18 @@ Vocabulary Vocabulary::fromTokenNames(const std::vector<std::string> &tokenNames
|
|||
std::vector<std::string> symbolicNames = tokenNames;
|
||||
std::locale locale;
|
||||
for (size_t i = 0; i < tokenNames.size(); i++) {
|
||||
std::string tokenName = tokenNames[i];
|
||||
if (tokenName == "") {
|
||||
const std::string& tokenName = tokenNames[i];
|
||||
if (tokenName.empty()) {
|
||||
continue;
|
||||
} else if (tokenName.front() == '\'') {
|
||||
symbolicNames[i].clear();
|
||||
} else if (std::isupper(tokenName.front(), locale)) {
|
||||
literalNames[i].clear();
|
||||
} else {
|
||||
// wasn't a literal or symbolic name
|
||||
literalNames[i].clear();
|
||||
symbolicNames[i].clear();
|
||||
}
|
||||
|
||||
if (!tokenName.empty()) {
|
||||
char firstChar = tokenName[0];
|
||||
if (firstChar == '\'') {
|
||||
symbolicNames[i] = "";
|
||||
continue;
|
||||
} else if (std::isupper(firstChar, locale)) {
|
||||
literalNames[i] = "";
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// wasn't a literal or symbolic name
|
||||
literalNames[i] = "";
|
||||
symbolicNames[i] = "";
|
||||
}
|
||||
|
||||
return Vocabulary(literalNames, symbolicNames, tokenNames);
|
||||
|
|
|
@ -14,9 +14,6 @@ namespace dfa {
|
|||
/// interface.
|
||||
class ANTLR4CPP_PUBLIC Vocabulary {
|
||||
public:
|
||||
Vocabulary(Vocabulary const&) = default;
|
||||
virtual ~Vocabulary();
|
||||
|
||||
/// Gets an empty <seealso cref="Vocabulary"/> instance.
|
||||
///
|
||||
/// <para>
|
||||
|
@ -25,7 +22,9 @@ namespace dfa {
|
|||
/// except <seealso cref="Token#EOF"/>.</para>
|
||||
static const Vocabulary EMPTY_VOCABULARY;
|
||||
|
||||
Vocabulary() {}
|
||||
Vocabulary() = default;
|
||||
Vocabulary(Vocabulary const&) = default;
|
||||
virtual ~Vocabulary();
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance of <seealso cref="Vocabulary"/> from the specified
|
||||
|
|
Loading…
Reference in New Issue