diff --git a/README.md b/README.md index 6ef42cc..683a98c 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,11 @@ int main(void) { [](const vector& v) { return v[0]; } // 2nd choice }; + /* This action is not necessary. parser["Primary"] = [](const vector& v) { - return v.size() == 1 ? v[0] : v[1]; + return v[0]; }; + */ parser["Number"] = [](const char* s, size_t l) { return stoi(string(s, l), nullptr, 10); @@ -63,9 +65,9 @@ int main(void) { // (4) Parse int val; - parser.parse("1+2*3", val); + parser.parse("(1+2)*3", val); - assert(val == 7); + assert(val == 9); } ``` diff --git a/test/test.cc b/test/test.cc index 440d6cc..35726ce 100644 --- a/test/test.cc +++ b/test/test.cc @@ -164,18 +164,14 @@ TEST_CASE("Simple calculator test", "[general]") return v.size() == 1 ? v[0].get() : v[0].get() * v[1].get(); }; - parser["Primary"] = [](const vector& v) { - return v.size() == 1 ? v[0] : v[1]; - }; - parser["Number"] = [](const char* s, size_t l) { return atoi(s); }; int val; - parser.parse("1+2*3", val); + parser.parse("(1+2)*3", val); - REQUIRE(val == 7); + REQUIRE(val == 9); } TEST_CASE("Calculator test", "[general]")