mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
Added the named capture explanation in README.
This commit is contained in:
parent
6d8826741a
commit
652e25a10b
21
README.md
21
README.md
@ -175,6 +175,7 @@ Simple interface
|
||||
|
||||
```c++
|
||||
peglib::match m;
|
||||
|
||||
auto ret = peglib::peg_match(
|
||||
R"(
|
||||
ROOT <- _ ('[' $< TAG_NAME > ']' _)*
|
||||
@ -191,6 +192,26 @@ assert(m.str(2) == "tag:2");
|
||||
assert(m.str(3) == "tag-3");
|
||||
```
|
||||
|
||||
It also supports named capture with the `$name<` ... `>` operator.
|
||||
|
||||
```c++
|
||||
peglib::match m;
|
||||
|
||||
auto ret = peglib::peg_match(
|
||||
" ROOT <- _ ('[' $test< TAG_NAME > ']' _)* "
|
||||
" TAG_NAME <- (!']' .)+ "
|
||||
" _ <- [ \t]* ",
|
||||
" [tag1] [tag:2] [tag-3] ",
|
||||
m);
|
||||
|
||||
auto cap = m.named_capture("test");
|
||||
|
||||
REQUIRE(ret == true);
|
||||
REQUIRE(m.size() == 4);
|
||||
REQUIRE(cap.size() == 3);
|
||||
REQUIRE(m.str(cap[2]) == "tag-3");
|
||||
```
|
||||
|
||||
There are some ways to *search* a peg pattern in a document.
|
||||
|
||||
```c++
|
||||
|
Loading…
Reference in New Issue
Block a user