mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +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.
|
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.
|
||||||
|
Loading…
Reference in New Issue
Block a user