From 652e25a10b8b806adc5c1b62ea36e4d9548e998d Mon Sep 17 00:00:00 2001 From: yhirose Date: Sat, 13 Jun 2015 17:11:27 -0400 Subject: [PATCH] Added the named capture explanation in README. --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 6b3969a..a99f0e8 100644 --- a/README.md +++ b/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++