diff options
-rw-r--r-- | lexer.cpp | 2 | ||||
-rw-r--r-- | lexer.h | 1 | ||||
-rw-r--r-- | test-lexer.cpp | 31 |
3 files changed, 31 insertions, 3 deletions
@@ -256,6 +256,8 @@ Lexer::Lexer(const BNF& bnf, const std::string& Top): bnf(bnf), Top(Top), Revers std::vector<Token> Lexer::Lex(const std::string& s) { + location = {1, 0}; + std::vector<Token> result; std::string token; @@ -53,7 +53,6 @@ public: Lexer(const BNF& bnf, const std::string& Top); std::vector<Token> Lex(const std::string& s); - }; } // namespace Lex diff --git a/test-lexer.cpp b/test-lexer.cpp index 05633d0..c2bc824 100644 --- a/test-lexer.cpp +++ b/test-lexer.cpp @@ -61,7 +61,7 @@ TEST_F(Test, BNF) { // implicit? //std::set<std::string> Terminals{"identifier", "=", ";"}; - std::string Code{"a = bc ; c = 123 ; esd = Ff ; 1 = XYZ "}; + std::string Code{"a = bc ; c = 123 ; esd = Ff ; 1 = XYZ ; "}; std::vector<Token> tokens_reference{ {"identifier", "a", { 1, 1} }, {"preprocessing-op-or-punc", "=", { 1, 3}}, @@ -78,7 +78,7 @@ TEST_F(Test, BNF) { {"pp-number", "1", { 1, 31}}, {"preprocessing-op-or-punc", "=", { 1, 33}}, {"identifier", "XYZ", { 1, 35}}, - //{"preprocessing-op-or-punc", ";", { 1, 39}}, + {"preprocessing-op-or-punc", ";", { 1, 39}}, }; Lex::Lexer lexer(LexBNF, LexTop); @@ -97,6 +97,33 @@ TEST_F(Test, BNF) { auto Tree = compiler.compile(tokens); compiler.DumpTree(); + + //---------------------------------------------------------------- + + std::string Code2{"a = bc ; c = 123 ; esd = Ff ; 1 = XYZ "}; + std::vector<Token> tokens_reference2{ + {"identifier", "a", { 1, 1} }, + {"preprocessing-op-or-punc", "=", { 1, 3}}, + {"identifier", "bc", { 1, 5}}, + {"preprocessing-op-or-punc", ";", { 1, 8}}, + {"identifier", "c", { 1, 10}}, + {"preprocessing-op-or-punc", "=", { 1, 12}}, + {"pp-number", "123", { 1, 14}}, + {"preprocessing-op-or-punc", ";", { 1, 18}}, + {"identifier", "esd", { 1, 20}}, + {"preprocessing-op-or-punc", "=", { 1, 24}}, + {"identifier", "Ff", { 1, 26}}, + {"preprocessing-op-or-punc", ";", { 1, 29}}, + {"pp-number", "1", { 1, 31}}, + {"preprocessing-op-or-punc", "=", { 1, 33}}, + {"identifier", "XYZ", { 1, 35}}, + //{"preprocessing-op-or-punc", ";", { 1, 39}}, + }; + + tokens = lexer.Lex(Code2); + ASSERT_EQ(tokens, tokens_reference2); + CPP::PreprocessorTokensToTokens(tokens); + Tree = compiler.compile(tokens); } int main(int argc, char* argv[]) { |