diff options
Diffstat (limited to 'cppbnf.cpp')
-rwxr-xr-x | cppbnf.cpp | 62 |
1 files changed, 27 insertions, 35 deletions
@@ -90,29 +90,6 @@ namespace { return true; } - // returns 1 if exactly one start symbol and - // all nodes size > 1, except terminal symbols - bool valid(const BNF& bnf) { - return numberOfStartSymbols(bnf) == 1 && symbolsValid(bnf); - } - - bool validLex(const BNF& bnf) { - // all terminal symbols exactly one character - - for (const auto& [symbol, lists] : bnf) { - for (const auto& list : lists) { - for (const auto& i : list) { - if (i.size() != 1 && isTerminal(bnf, i)) { - std::cerr << "Warning: Terminal symbol in " << symbol << " is too long: "s << i << std::endl; - return false; - } - } - } - } - - return true; - } - const std::string optionalMarker{"OPTIONAL:"}; std::string optional(const std::string& s) @@ -206,6 +183,32 @@ namespace { } // namespace +namespace CPPBNF { + +// returns 1 if exactly one start symbol and +// all nodes size > 1, except terminal symbols +bool valid(const BNF& bnf) { + return numberOfStartSymbols(bnf) == 1 && symbolsValid(bnf); +} + +bool validLex(const BNF& bnf) { + // all terminal symbols exactly one character + + for (const auto& [symbol, lists] : bnf) { + for (const auto& list : lists) { + for (const auto& i : list) { + if (i.size() != 1 && isTerminal(bnf, i)) { + std::cerr << "Warning: Terminal symbol in " << symbol << " is too long: "s << i << std::endl; + return false; + } + } + } + } + + return true; +} + + BNF GetCppBNFLex() { BNF bnf{ @@ -1919,15 +1922,4 @@ BNF GetCppBNFGram() return normalizeBNF(bnf); } -TEST(CppBnf, LexicalBnf) { - auto bnf = SubBNF(GetCppBNFLex(), "preprocessing-token"); - - EXPECT_TRUE(valid(bnf)); - EXPECT_TRUE(validLex(bnf)); -} - -TEST(CppBnf, GrammarBnf) { - auto bnf = SubBNF(GetCppBNFGram(), "translation-unit"); - - EXPECT_TRUE(valid(bnf)); -} +} // namespace CPPBNF |