Fixed a code example in README

This commit is contained in:
yhirose 2020-08-26 21:47:19 -04:00
parent b3b29ce8f3
commit 11ed83e46f

View File

@ -177,20 +177,18 @@ struct SemanticValues : protected std::vector<any>
The following example uses `<` ... ` >` operator, which is *token boundary* operator. The following example uses `<` ... ` >` operator, which is *token boundary* operator.
```cpp ```cpp
auto syntax = R"( peg::parser parser(R"(
ROOT <- _ TOKEN (',' _ TOKEN)* ROOT <- _ TOKEN (',' _ TOKEN)*
TOKEN <- < [a-z0-9]+ > _ TOKEN <- < [a-z0-9]+ > _
_ <- [ \t\r\n]* _ <- [ \t\r\n]*
)"; )");
peg pg(syntax); parser["TOKEN"] = [](const SemanticValues& sv) {
pg["TOKEN"] = [](const SemanticValues& sv) {
// 'token' doesn't include trailing whitespaces // 'token' doesn't include trailing whitespaces
auto token = sv.token(); auto token = sv.token();
}; };
auto ret = pg.parse(" token1, token2 "); auto ret = parser.parse(" token1, token2 ");
``` ```
We can ignore unnecessary semantic values from the list by using `~` operator. We can ignore unnecessary semantic values from the list by using `~` operator.