mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 11:55:30 +00:00
Fixed a code example in README
This commit is contained in:
parent
b3b29ce8f3
commit
11ed83e46f
10
README.md
10
README.md
@ -177,20 +177,18 @@ struct SemanticValues : protected std::vector<any>
|
||||
The following example uses `<` ... ` >` operator, which is *token boundary* operator.
|
||||
|
||||
```cpp
|
||||
auto syntax = R"(
|
||||
peg::parser parser(R"(
|
||||
ROOT <- _ TOKEN (',' _ TOKEN)*
|
||||
TOKEN <- < [a-z0-9]+ > _
|
||||
_ <- [ \t\r\n]*
|
||||
)";
|
||||
)");
|
||||
|
||||
peg pg(syntax);
|
||||
|
||||
pg["TOKEN"] = [](const SemanticValues& sv) {
|
||||
parser["TOKEN"] = [](const SemanticValues& sv) {
|
||||
// 'token' doesn't include trailing whitespaces
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user