summaryrefslogtreecommitdiffhomepage
path: root/cpp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp.cpp')
-rw-r--r--cpp.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/cpp.cpp b/cpp.cpp
index 2f65a19..8526cff 100644
--- a/cpp.cpp
+++ b/cpp.cpp
@@ -4,6 +4,7 @@
#include "cppbnf.h"
#include "grammer.h"
#include "minicc.h"
+#include "debug.h"
#include <gtest/gtest.h>
#include <gmock/gmock.h>
@@ -49,7 +50,29 @@ void CPP::preprocessing_tokenize(const std::string& s)
auto charTokens {sourceToCharTokens(s)};
auto bnf{SubBNF(GetCppBNFLex(), "preprocessing-token")};
- Gram::Compiler compiler(bnf, "preprocessing-token");
+
+ // add to bnf to match whole file
+ bnf["file"] = {
+ {"preprocessing-token-list"},
+ {"whitespace-list", "preprocessing-token-list"}
+ };
+ bnf["preprocessing-token-list"] = {
+ {"preprocessing-token-padded"},
+ {"preprocessing-token-list", "preprocessing-token-padded"}
+ };
+ bnf["preprocessing-token-padded"] = {
+ {"preprocessing-token"},
+ {"preprocessing-token", "whitespace-list"}
+ };
+ bnf["whitespace-list"] = {
+ {"whitespace-char"},
+ {"whitespace-list", "whitespace-char" }
+ };
+ bnf["whitespace-char"] = {
+ {" "}, {"\t"}, {"\n"}, {"\r"}
+ };
+ Gram::Compiler compiler(bnf, "file");
+ debug = true;
auto Tree = compiler.compile(charTokens);
}
@@ -111,7 +134,17 @@ void CPP::translate(const std::string& code)
link();
}
-TEST(Cpp, preprocessing_tokenize) {
+class CppTest: public ::testing::Test
+{
+protected:
+ CppTest() {
+ debug = false;
+ }
+ ~CppTest() {
+ }
+};
+
+TEST_F(CppTest, preprocessing_tokenize) {
CPP::preprocessing_tokenize("int main() { return 1; }");
}