mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 11:55:30 +00:00
Fixed sample.
This commit is contained in:
parent
f7eca8eac5
commit
f0351a9909
@ -53,9 +53,11 @@ int main(void) {
|
||||
[](const vector<any>& v) { return v[0]; } // 2nd choice
|
||||
};
|
||||
|
||||
/* This action is not necessary.
|
||||
parser["Primary"] = [](const vector<any>& 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);
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -164,18 +164,14 @@ TEST_CASE("Simple calculator test", "[general]")
|
||||
return v.size() == 1 ? v[0].get<int>() : v[0].get<int>() * v[1].get<int>();
|
||||
};
|
||||
|
||||
parser["Primary"] = [](const vector<any>& 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]")
|
||||
|
Loading…
Reference in New Issue
Block a user