summaryrefslogtreecommitdiffhomepage
path: root/cppbnf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cppbnf.cpp')
-rwxr-xr-xcppbnf.cpp62
1 files changed, 27 insertions, 35 deletions
diff --git a/cppbnf.cpp b/cppbnf.cpp
index fd246ba..4f0b758 100755
--- a/cppbnf.cpp
+++ b/cppbnf.cpp
@@ -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