mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2025-01-22 21:35:29 +00:00
Updated README.
This commit is contained in:
parent
9765e095ab
commit
5ed7c738a8
23
README.md
23
README.md
@ -242,7 +242,7 @@ There are some ways to *search* a peg pattern in a document.
|
|||||||
using namespace peglib;
|
using namespace peglib;
|
||||||
|
|
||||||
auto syntax = R"(
|
auto syntax = R"(
|
||||||
ROOT <- '[' $< [a-z0-9]+ > ']'
|
ROOT <- '[' $< [a-z0-9]+ > ']'
|
||||||
)";
|
)";
|
||||||
|
|
||||||
auto s = " [tag1] [tag2] [tag3] ";
|
auto s = " [tag1] [tag2] [tag3] ";
|
||||||
@ -253,23 +253,23 @@ size_t pos = 0;
|
|||||||
auto n = strlen(s);
|
auto n = strlen(s);
|
||||||
match m;
|
match m;
|
||||||
while (peg_search(pg, s + pos, n - pos, m)) {
|
while (peg_search(pg, s + pos, n - pos, m)) {
|
||||||
cout << m.str() << endl; // entire match
|
cout << m.str() << endl; // entire match
|
||||||
cout << m.str(1) << endl; // submatch #1
|
cout << m.str(1) << endl; // submatch #1
|
||||||
pos += m.length();
|
pos += m.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
// peglib::peg_token_iterator
|
// peglib::peg_token_iterator
|
||||||
peg_token_iterator it(syntax, s);
|
peg_token_iterator it(syntax, s);
|
||||||
while (it != peg_token_iterator()) {
|
while (it != peg_token_iterator()) {
|
||||||
cout << it->str() << endl; // entire match
|
cout << it->str() << endl; // entire match
|
||||||
cout << it->str(1) << endl; // submatch #1
|
cout << it->str(1) << endl; // submatch #1
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
// peglib::peg_token_range
|
// peglib::peg_token_range
|
||||||
for (auto& m: peg_token_range(syntax, s)) {
|
for (auto& m: peg_token_range(syntax, s)) {
|
||||||
cout << m.str() << endl; // entire match
|
cout << m.str() << endl; // entire match
|
||||||
cout << m.str(1) << endl; // submatch #1
|
cout << m.str(1) << endl; // submatch #1
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -330,10 +330,10 @@ Rules additional_rules = {
|
|||||||
static vector<string> names = { "PEG", "BNF" };
|
static vector<string> names = { "PEG", "BNF" };
|
||||||
for (const auto& name: names) {
|
for (const auto& name: names) {
|
||||||
if (name.size() <= n && !name.compare(0, name.size(), s, name.size())) {
|
if (name.size() <= n && !name.compare(0, name.size(), s, name.size())) {
|
||||||
return name.size();
|
return name.size(); // processed length
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1; // parse error
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -363,7 +363,6 @@ Tested Compilers
|
|||||||
TODO
|
TODO
|
||||||
----
|
----
|
||||||
|
|
||||||
* Predicate control
|
|
||||||
* Unicode support
|
* Unicode support
|
||||||
|
|
||||||
License
|
License
|
||||||
|
Loading…
Reference in New Issue
Block a user