diff options
-rw-r--r-- | cpp.cpp | 2 | ||||
-rw-r--r-- | grammer.cpp | 4 | ||||
-rw-r--r-- | test-cpp.cpp | 22 |
3 files changed, 16 insertions, 12 deletions
@@ -30,7 +30,7 @@ void CPP::backslash_escape() // TODO } -// Phase 3: Parse preprocessing tokens +// Phase 3: Parse preprocessing tokens, TODO: discard comments std::vector<Token> CPP::preprocessing_tokenize(const std::string& s) { auto bnf{SubBNF(CPPBNF::GetCppBNFLex(), "preprocessing-token")}; diff --git a/grammer.cpp b/grammer.cpp index cd5b50f..cb6b3bf 100644 --- a/grammer.cpp +++ b/grammer.cpp @@ -308,7 +308,7 @@ std::vector<TreeNode> Compiler::compile(std::vector<Token> p_tokens) tokens = p_tokens; if (tokens.size() == 0) - throw std::runtime_error("No tokens!"); + throw std::runtime_error("No tokens"); // // top-down algorithm: @@ -317,7 +317,7 @@ std::vector<TreeNode> Compiler::compile(std::vector<Token> p_tokens) // 2. Construct Node Tree from symbol_variants // if (!match(m_top, 0, tokens.size())) - throw std::runtime_error("Compile error."); + throw std::runtime_error("Compile error"); //DumpTree(); diff --git a/test-cpp.cpp b/test-cpp.cpp index 47a57f5..aabc4f4 100644 --- a/test-cpp.cpp +++ b/test-cpp.cpp @@ -40,11 +40,6 @@ TEST_F(CppTest, preprocessing_tokenize) { auto tokens = cpp.tokens_from_pptokens(pp_tokens); ASSERT_EQ(tokens.size(), 9); -#if 0 - for (auto &i: tokens) { - std::cout << i.type << ": " << i.value << std::endl; - } -#endif auto nodes = cpp.analysis(tokens); @@ -52,14 +47,23 @@ TEST_F(CppTest, preprocessing_tokenize) { } #endif -#if 0 -TEST_F(CppTest, preprocessing_tokenize2) { +TEST_F(CppTest, preprocessing_tokenize_compile_error) { CPP cpp; auto ppTree = cpp.preprocessing_tokenize("in ma"); - cpp.tokens_from_pptokens(ppTree); + auto tokens = cpp.tokens_from_pptokens(ppTree); + + ASSERT_EQ(tokens.size(), 2); + + try { + auto nodes = cpp.analysis(tokens); + } catch (const std::exception& ex) { + EXPECT_EQ(ex.what(), "Compile error"s); + return; + } + + FAIL() << "Exception expected"; } -#endif #if 0 TEST(Cpp, translate) { |