8 #ifndef CPPPEGLIB_PEGLIB_H 9 #define CPPPEGLIB_PEGLIB_H 15 #include <initializer_list> 23 #include <unordered_map> 29 #if (_MSC_VER == 1800) 30 #define PEGLIB_NO_CONSTEXPR_SUPPORT 31 #elif (_MSC_VER >= 1800) 33 #else (_MSC_VER < 1800) 34 #error "Requires C+11 support" 44 #if __clang__ == 1 && __clang_major__ == 5 && __clang_minor__ == 0 && __clang_patchlevel__ == 0 62 rhs.content_ =
nullptr;
84 rhs.content_ =
nullptr;
103 throw std::bad_cast();
108 throw std::bad_cast();
130 throw std::bad_cast();
149 template <
typename T>
171 template <
typename EF>
203 template <
typename EF>
228 auto col =
p - col_ptr + 1;
230 return std::make_pair(no,
col);
259 std::vector<std::pair<const char*, size_t>>
tokens;
263 assert(
id <
tokens.size());
271 template <
typename T>
278 using std::vector<any>::iterator;
279 using std::vector<any>::const_iterator;
281 using std::vector<any>::empty;
282 using std::vector<any>::assign;
283 using std::vector<any>::begin;
285 using std::vector<any>::rbegin;
286 using std::vector<any>::rend;
287 using std::vector<any>::operator[];
288 using std::vector<any>::at;
289 using std::vector<any>::resize;
290 using std::vector<any>::front;
291 using std::vector<any>::back;
292 using std::vector<any>::push_back;
293 using std::vector<any>::pop_back;
294 using std::vector<any>::insert;
295 using std::vector<any>::erase;
296 using std::vector<any>::clear;
298 using std::vector<any>::emplace;
299 using std::vector<any>::emplace_back;
310 template <
typename F>
312 vector<
typename std::remove_const<decltype(
f(
any()))>
::type>
r;
313 for (
const auto&
v: *
this) {
314 r.emplace_back(
f(
v));
319 template <
typename F>
321 vector<
typename std::remove_const<decltype(
f(
any()))>
::type>
r;
323 for (
size_t i = beg; i <
end; i++) {
324 r.emplace_back(
f((*
this)[i]));
334 typename R,
typename F,
338 fn(std::forward<Args>(
args)...);
343 typename R,
typename F,
347 return fn(std::forward<Args>(
args)...);
351 typename R,
typename F,
352 typename std::enable_if<
357 return any(fn(std::forward<Args>(
args)...));
400 template <
typename R>
405 return call<R>(
fn_, sv);
410 template <
typename R>
415 return call<R>(
fn_, sv, dt);
422 template<
typename F,
typename R>
427 template<
typename F,
typename R>
432 template<
typename F,
typename R>
437 template<
typename F,
typename R>
442 template<
typename F,
typename R>
447 template<
typename F,
typename R>
462 const char*
what()
const {
return s_.empty() ? nullptr :
s_.c_str(); }
476 return len !=
static_cast<size_t>(-1);
480 return len ==
static_cast<size_t>(-1);
518 std::map<std::pair<size_t, size_t>, std::tuple<size_t, any>>
cache_values;
527 std::shared_ptr<Ope> a_whitespaceOpe,
528 bool a_enablePackratParsing,
548 template <
typename T>
560 auto key = std::make_pair(
col, def_id);
564 len =
static_cast<size_t>(-1);
572 auto key = std::make_pair(
col, def_id);
582 value_stack.emplace_back(std::make_shared<SemanticValues>());
619 virtual void accept(Visitor&
v) = 0;
627 #if defined(_MSC_VER) && _MSC_VER < 1900 // Less than Visual Studio 2015 634 template <
typename... Args>
636 opes_ = std::vector<std::shared_ptr<Ope>>{
static_cast<std::shared_ptr<Ope>
>(
args)... };
639 template <
typename... Args>
647 c.trace(
"Sequence",
s,
n, sv, dt);
649 for (
const auto& ope :
opes_) {
652 const auto& rule = *ope;
653 auto len = rule.parse(
s + i,
n - i, sv,
c, dt);
655 return static_cast<size_t>(-1);
662 void accept(Visitor&
v)
override;
664 std::vector<std::shared_ptr<Ope>>
opes_;
670 #if defined(_MSC_VER) && _MSC_VER < 1900 // Less than Visual Studio 2015 677 template <
typename... Args>
679 opes_ = std::vector<std::shared_ptr<Ope>>{
static_cast<std::shared_ptr<Ope>
>(
args)... };
682 template <
typename... Args>
690 c.trace(
"PrioritizedChoice",
s,
n, sv, dt);
692 for (
const auto& ope :
opes_) {
694 auto& chldsv =
c.push();
699 const auto& rule = *ope;
700 auto len = rule.parse(
s,
n, chldsv,
c, dt);
702 if (!chldsv.empty()) {
703 sv.insert(sv.end(), chldsv.begin(), chldsv.end());
705 sv.
s_ = chldsv.c_str();
706 sv.
n_ = chldsv.length();
708 sv.
tokens.insert(sv.
tokens.end(), chldsv.tokens.begin(), chldsv.tokens.end());
713 return static_cast<size_t>(-1);
716 void accept(Visitor&
v)
override;
720 std::vector<std::shared_ptr<Ope>>
opes_;
729 c.trace(
"ZeroOrMore",
s,
n, sv, dt);
730 auto save_error_pos =
c.error_pos;
735 auto save_sv_size = sv.size();
736 auto save_tok_size = sv.
tokens.size();
737 const auto& rule = *
ope_;
738 auto len = rule.parse(
s + i,
n - i, sv,
c, dt);
740 if (sv.size() != save_sv_size) {
741 sv.erase(sv.begin() +
static_cast<std::ptrdiff_t
>(save_sv_size));
743 if (sv.
tokens.size() != save_tok_size) {
744 sv.
tokens.erase(sv.
tokens.begin() +
static_cast<std::ptrdiff_t
>(save_tok_size));
746 c.error_pos = save_error_pos;
754 void accept(Visitor&
v)
override;
765 c.trace(
"OneOrMore",
s,
n, sv, dt);
770 const auto& rule = *
ope_;
771 len = rule.parse(
s,
n, sv,
c, dt);
773 return static_cast<size_t>(-1);
776 auto save_error_pos =
c.error_pos;
781 auto save_sv_size = sv.size();
782 auto save_tok_size = sv.
tokens.size();
783 const auto& rule = *
ope_;
784 len = rule.parse(
s + i,
n - i, sv,
c, dt);
786 if (sv.size() != save_sv_size) {
787 sv.erase(sv.begin() +
static_cast<std::ptrdiff_t
>(save_sv_size));
789 if (sv.
tokens.size() != save_tok_size) {
790 sv.
tokens.erase(sv.
tokens.begin() +
static_cast<std::ptrdiff_t
>(save_tok_size));
792 c.error_pos = save_error_pos;
800 void accept(Visitor&
v)
override;
811 c.trace(
"Option",
s,
n, sv, dt);
812 auto save_error_pos =
c.error_pos;
814 auto save_sv_size = sv.size();
815 auto save_tok_size = sv.
tokens.size();
817 const auto& rule = *
ope_;
818 auto len = rule.parse(
s,
n, sv,
c, dt);
822 if (sv.size() != save_sv_size) {
823 sv.erase(sv.begin() +
static_cast<std::ptrdiff_t
>(save_sv_size));
825 if (sv.
tokens.size() != save_tok_size) {
826 sv.
tokens.erase(sv.
tokens.begin() +
static_cast<std::ptrdiff_t
>(save_tok_size));
828 c.error_pos = save_error_pos;
833 void accept(Visitor&
v)
override;
844 c.trace(
"AndPredicate",
s,
n, sv, dt);
846 auto& chldsv =
c.push();
851 const auto& rule = *
ope_;
852 auto len = rule.parse(
s,
n, chldsv,
c, dt);
856 return static_cast<size_t>(-1);
860 void accept(Visitor&
v)
override;
871 c.trace(
"NotPredicate",
s,
n, sv, dt);
872 auto save_error_pos =
c.error_pos;
874 auto& chldsv =
c.push();
879 const auto& rule = *
ope_;
880 auto len = rule.parse(
s,
n, chldsv,
c, dt);
883 return static_cast<size_t>(-1);
885 c.error_pos = save_error_pos;
890 void accept(Visitor&
v)
override;
902 void accept(Visitor&
v)
override;
913 c.trace(
"CharacterClass",
s,
n, sv, dt);
917 return static_cast<size_t>(-1);
921 while (i <
chars_.size()) {
935 return static_cast<size_t>(-1);
938 void accept(Visitor&
v)
override;
949 c.trace(
"Character",
s,
n, sv, dt);
951 if (
n < 1 ||
s[0] !=
ch_) {
953 return static_cast<size_t>(-1);
958 void accept(Visitor&
v)
override;
967 c.trace(
"AnyCharacter",
s,
n, sv, dt);
971 return static_cast<size_t>(-1);
976 void accept(Visitor&
v)
override;
986 const auto& rule = *
ope_;
987 auto len = rule.parse(
s,
n, sv,
c, dt);
994 void accept(Visitor&
v)
override;
1011 void accept(Visitor&
v)
override;
1022 const auto& rule = *
ope_;
1023 auto& chldsv =
c.push();
1027 return rule.parse(
s,
n, chldsv,
c, dt);
1030 void accept(Visitor&
v)
override;
1043 auto ope =
weak_.lock();
1045 const auto& rule = *ope;
1046 return rule.parse(
s,
n, sv,
c, dt);
1049 void accept(Visitor&
v)
override;
1062 void accept(Visitor&
v)
override;
1076 const std::unordered_map<std::string, Definition>& grammar,
const std::string&
name,
const char*
s)
1083 void accept(Visitor&
v)
override;
1085 std::shared_ptr<Ope>
get_rule()
const;
1087 const std::unordered_map<std::string, Definition>&
grammar_;
1102 if (
c.in_whitespace) {
1105 c.in_whitespace =
true;
1107 const auto& rule = *
ope_;
1108 return rule.parse(
s,
n, sv,
c, dt);
1111 void accept(Visitor&
v)
override;
1168 std::unordered_map<void*, size_t>
ids;
1260 operator std::shared_ptr<Ope>() {
1261 return std::make_shared<WeakHolder>(
holder_);
1266 ope->accept(isToken);
1296 template <
typename T>
1301 if (
r.ret && !sv.empty() && !sv.front().is_undefined()) {
1302 val = sv[0].get<
T>();
1307 template <
typename T>
1313 template <
typename T>
1317 if (
r.ret && !sv.empty() && !sv.front().is_undefined()) {
1318 val = sv[0].get<
T>();
1323 template <
typename T>
1334 template <
typename T>
1376 std::shared_ptr<Ope> ope =
holder_;
1382 auto len = ope->parse(
s,
n, sv, cxt, dt);
1394 c.trace(
"LiteralString",
s,
n, sv, dt);
1397 for (; i <
lit_.size(); i++) {
1398 if (i >=
n ||
s[i] !=
lit_[i]) {
1400 return static_cast<size_t>(-1);
1406 if (
c.whitespaceOpe) {
1407 auto len =
c.whitespaceOpe->parse(
s + i,
n - i, sv,
c, dt);
1409 return static_cast<size_t>(-1);
1421 const auto& rule = *
ope_;
1422 auto len = rule.parse(
s,
n, sv,
c, dt);
1426 if (
c.whitespaceOpe) {
1427 auto l =
c.whitespaceOpe->parse(
s +
len,
n -
len, sv,
c, dt);
1429 return static_cast<size_t>(-1);
1439 throw std::logic_error(
"Uninitialized definition ope was used...");
1450 auto& chldsv = c.push();
1452 if (outer_->enter) {
1464 const auto& rule = *
ope_;
1465 len = rule.parse(
s,
n, chldsv,
c, dt);
1473 a_val =
reduce(chldsv, dt);
1476 if (
c.message_pos <
s) {
1478 c.message = e.
what();
1481 len =
static_cast<size_t>(-1);
1487 if (!outer_->ignoreSemanticValue) {
1488 sv.emplace_back(
val);
1491 if (outer_->error_message) {
1492 if (
c.message_pos <
s) {
1494 c.message = outer_->error_message();
1503 if (outer_->action) {
1504 return outer_->action(sv, dt);
1505 }
else if (sv.empty()) {
1512 inline size_t DefinitionReference::parse(
1514 const auto& rule = *get_rule();
1515 return rule.parse(
s,
n, sv,
c, dt);
1518 inline std::shared_ptr<Ope> DefinitionReference::get_rule()
const {
1520 std::call_once(init_, [
this]() {
1521 rule_ = grammar_.at(name_).holder_;
1547 inline void AssignIDToDefinition::visit(
Holder& ope) {
1548 auto p =
static_cast<void*
>(ope.
outer_);
1552 auto id =
ids.size();
1555 ope.
ope_->accept(*
this);
1561 template <
typename... Args>
1563 return std::make_shared<Sequence>(
static_cast<std::shared_ptr<Ope>
>(
args)...);
1566 template <
typename... Args>
1568 return std::make_shared<PrioritizedChoice>(
static_cast<std::shared_ptr<Ope>
>(
args)...);
1571 inline std::shared_ptr<Ope>
zom(
const std::shared_ptr<Ope>& ope) {
1572 return std::make_shared<ZeroOrMore>(ope);
1575 inline std::shared_ptr<Ope>
oom(
const std::shared_ptr<Ope>& ope) {
1576 return std::make_shared<OneOrMore>(ope);
1579 inline std::shared_ptr<Ope>
opt(
const std::shared_ptr<Ope>& ope) {
1580 return std::make_shared<Option>(ope);
1583 inline std::shared_ptr<Ope>
apd(
const std::shared_ptr<Ope>& ope) {
1584 return std::make_shared<AndPredicate>(ope);
1587 inline std::shared_ptr<Ope>
npd(
const std::shared_ptr<Ope>& ope) {
1588 return std::make_shared<NotPredicate>(ope);
1592 return std::make_shared<LiteralString>(
lit);
1596 return std::make_shared<CharacterClass>(chars);
1599 inline std::shared_ptr<Ope>
chr(
char dt) {
1600 return std::make_shared<Character>(dt);
1603 inline std::shared_ptr<Ope>
dot() {
1604 return std::make_shared<AnyCharacter>();
1608 return std::make_shared<Capture>(ope, ma,
n,
s);
1612 return std::make_shared<Capture>(ope, ma,
static_cast<size_t>(-1),
std::string());
1615 inline std::shared_ptr<Ope>
tok(
const std::shared_ptr<Ope>& ope) {
1616 return std::make_shared<TokenBoundary>(ope);
1619 inline std::shared_ptr<Ope>
ign(
const std::shared_ptr<Ope>& ope) {
1620 return std::make_shared<Ignore>(ope);
1623 inline std::shared_ptr<Ope>
ref(
const std::unordered_map<std::string, Definition>& grammar,
const std::string&
name,
const char*
s) {
1624 return std::make_shared<DefinitionReference>(grammar,
name,
s);
1627 inline std::shared_ptr<Ope>
wsp(
const std::shared_ptr<Ope>& ope) {
1628 return std::make_shared<Whitespace>(std::make_shared<Ignore>(ope));
1635 typedef std::unordered_map<std::string, Definition>
Grammar;
1648 return get_instance().perform_core(
s,
n,
start, ma,
log);
1653 return get_instance().g;
1683 : s_(nullptr), name_(
name), done_(
false) {}
1685 using Ope::Visitor::visit;
1708 ope.
ope_->accept(*
this);
1712 ope.
ope_->accept(*
this);
1716 ope.
ope_->accept(*
this);
1720 ope.
ope_->accept(*
this);
1724 ope.
ope_->accept(*
this);
1728 done_ = !ope.
lit_.empty();
1740 ope.
ope_->accept(*
this);
1743 ope.
ope_->accept(*
this);
1746 ope.
ope_->accept(*
this);
1749 ope.
weak_.lock()->accept(*
this);
1752 ope.
ope_->accept(*
this);
1755 if (ope.
name_ == name_) {
1757 }
else if (refs_.count(ope.
name_)) {
1760 refs_.insert(ope.
name_);
1776 g[
"Grammar"] <=
seq(
g[
"Spacing"],
oom(
g[
"Definition"]),
g[
"EndOfFile"]);
1777 g[
"Definition"] <=
seq(
opt(
g[
"IGNORE"]),
g[
"Identifier"],
g[
"LEFTARROW"],
g[
"Expression"]);
1779 g[
"Expression"] <=
seq(
g[
"Sequence"],
zom(
seq(
g[
"SLASH"],
g[
"Sequence"])));
1780 g[
"Sequence"] <=
zom(
g[
"Prefix"]);
1781 g[
"Prefix"] <=
seq(
opt(
cho(
g[
"AND"],
g[
"NOT"])),
g[
"Suffix"]);
1782 g[
"Suffix"] <=
seq(
g[
"Primary"],
opt(
cho(
g[
"QUESTION"],
g[
"STAR"],
g[
"PLUS"])));
1783 g[
"Primary"] <=
cho(
seq(
opt(
g[
"IGNORE"]),
g[
"Identifier"],
npd(
g[
"LEFTARROW"])),
1784 seq(
g[
"OPEN"],
g[
"Expression"],
g[
"CLOSE"]),
1785 seq(
g[
"BeginTok"],
g[
"Expression"],
g[
"EndTok"]),
1786 seq(
g[
"BeginCap"],
g[
"Expression"],
g[
"EndCap"]),
1787 g[
"Literal"],
g[
"Class"],
g[
"DOT"]);
1789 g[
"Identifier"] <=
seq(
g[
"IdentCont"],
g[
"Spacing"]);
1790 g[
"IdentCont"] <=
seq(
g[
"IdentStart"],
zom(
g[
"IdentRest"]));
1791 g[
"IdentStart"] <=
cls(
"a-zA-Z_\x80-\xff%");
1792 g[
"IdentRest"] <=
cho(
g[
"IdentStart"],
cls(
"0-9"));
1799 g[
"Range"] <=
cho(
seq(
g[
"Char"],
chr(
'-'),
g[
"Char"]),
g[
"Char"]);
1806 #if !defined(PEGLIB_NO_UNICODE_CHARS) 1809 g[
"LEFTARROW"] <=
seq(
lit(
"<-"),
g[
"Spacing"]);
1811 ~
g[
"SLASH"] <=
seq(
chr(
'/'),
g[
"Spacing"]);
1812 g[
"AND"] <=
seq(
chr(
'&'),
g[
"Spacing"]);
1813 g[
"NOT"] <=
seq(
chr(
'!'),
g[
"Spacing"]);
1814 g[
"QUESTION"] <=
seq(
chr(
'?'),
g[
"Spacing"]);
1815 g[
"STAR"] <=
seq(
chr(
'*'),
g[
"Spacing"]);
1816 g[
"PLUS"] <=
seq(
chr(
'+'),
g[
"Spacing"]);
1817 g[
"OPEN"] <=
seq(
chr(
'('),
g[
"Spacing"]);
1818 g[
"CLOSE"] <=
seq(
chr(
')'),
g[
"Spacing"]);
1819 g[
"DOT"] <=
seq(
chr(
'.'),
g[
"Spacing"]);
1821 g[
"Spacing"] <=
zom(
cho(
g[
"Space"],
g[
"Comment"]));
1823 g[
"Space"] <=
cho(
chr(
' '),
chr(
'\t'),
g[
"EndOfLine"]);
1827 g[
"BeginTok"] <=
seq(
chr(
'<'),
g[
"Spacing"]);
1828 g[
"EndTok"] <=
seq(
chr(
'>'),
g[
"Spacing"]);
1831 g[
"EndCap"] <=
seq(
lit(
">"),
g[
"Spacing"]);
1833 g[
"IGNORE"] <=
chr(
'~');
1837 x.second.name =
x.first;
1845 auto ignore = (sv.size() == 4);
1846 auto baseId = ignore ? 1u : 0u;
1849 auto ope = sv[baseId + 2].get<std::shared_ptr<Ope>>();
1851 auto& grammar = *
data.grammar;
1852 if (!grammar.count(
name)) {
1853 auto& rule = grammar[
name];
1856 rule.ignoreSemanticValue = ignore;
1858 if (
data.start.empty()) {
1867 if (sv.size() == 1) {
1868 return sv[0].get<std::shared_ptr<Ope>>();
1870 std::vector<std::shared_ptr<Ope>> opes;
1871 for (
auto i = 0u; i < sv.size(); i++) {
1872 opes.emplace_back(sv[i].get<std::shared_ptr<Ope>>());
1874 const std::shared_ptr<Ope> ope = std::make_shared<PrioritizedChoice>(opes);
1880 if (sv.size() == 1) {
1881 return sv[0].get<std::shared_ptr<Ope>>();
1883 std::vector<std::shared_ptr<Ope>> opes;
1884 for (
const auto&
x: sv) {
1885 opes.emplace_back(
x.get<std::shared_ptr<Ope>>());
1887 const std::shared_ptr<Ope> ope = std::make_shared<Sequence>(opes);
1893 std::shared_ptr<Ope> ope;
1894 if (sv.size() == 1) {
1895 ope = sv[0].get<std::shared_ptr<Ope>>();
1897 assert(sv.size() == 2);
1898 auto tok = sv[0].get<
char>();
1899 ope = sv[1].get<std::shared_ptr<Ope>>();
1910 auto ope = sv[0].get<std::shared_ptr<Ope>>();
1911 if (sv.size() == 1) {
1914 assert(sv.size() == 2);
1915 auto tok = sv[1].get<
char>();
1918 }
else if (
tok ==
'*') {
1931 auto ignore = (sv.size() == 2);
1932 auto baseId = ignore ? 1u : 0u;
1934 const auto& ident = sv[baseId].get<
std::string>();
1936 if (!
data.references.count(ident)) {
1947 return sv[1].get<std::shared_ptr<Ope>>();
1950 return tok(sv[1].get<std::shared_ptr<Ope>>());
1954 auto ope = sv[1].get<std::shared_ptr<Ope>>();
1958 return sv[0].get<std::shared_ptr<Ope>>();
1969 return lit(resolve_escape_sequence(
tok.first,
tok.second));
1973 return cls(resolve_escape_sequence(
tok.first,
tok.second));
1995 data.match_action = ma;
1998 auto r =
g[
"Grammar"].parse(
s,
n, dt);
2002 if (
r.message_pos) {
2004 log(line.first, line.second,
r.message);
2007 log(line.first, line.second,
"syntax error");
2013 auto& grammar = *
data.grammar;
2016 bool ret =
data.duplicates.empty();
2018 for (
const auto&
x:
data.duplicates) {
2020 const auto&
name =
x.first;
2021 auto ptr =
x.second;
2023 log(line.first, line.second,
"'" +
name +
"' is already defined.");
2028 for (
const auto&
x :
data.references) {
2029 const auto&
name =
x.first;
2030 auto ptr =
x.second;
2031 if (!grammar.count(
name)) {
2034 log(line.first, line.second,
"'" +
name +
"' is not defined.");
2047 for (
auto&
x: grammar) {
2048 const auto&
name =
x.first;
2049 auto& rule =
x.second;
2056 log(line.first, line.second,
"'" +
name +
"' is left recursive.");
2075 return data.grammar;
2079 if (
'0' <=
c &&
c <=
'9') {
2082 }
else if (
'a' <=
c &&
c <=
'f') {
2085 }
else if (
'A' <=
c &&
c <=
'F') {
2093 if (
'0' <=
c &&
c <=
'9') {
2103 while (i <
n && is_hex(
s[i],
val)) {
2104 ret =
static_cast<char>(ret * 16 +
val);
2107 return std::make_pair(ret, i);
2114 ret =
static_cast<char>(ret * 8 +
val);
2117 return std::make_pair(ret, i);
2130 case 'n':
r +=
'\n'; i++;
break;
2131 case 'r':
r +=
'\r'; i++;
break;
2132 case 't':
r +=
'\t'; i++;
break;
2133 case '\'':
r +=
'\''; i++;
break;
2134 case '"':
r +=
'"'; i++;
break;
2135 case '[':
r +=
'['; i++;
break;
2136 case ']':
r +=
']'; i++;
break;
2137 case '\\':
r +=
'\\'; i++;
break;
2139 std::tie(ch, i) = parse_hex_number(
s,
n, i + 1);
2144 std::tie(ch, i) = parse_octal_number(
s,
n, i);
2166 #ifndef PEGLIB_NO_CONSTEXPR_SUPPORT 2172 inline constexpr
unsigned int operator "" _(
const char*
s,
size_t) {
2178 template <
typename Annotation>
2181 AstBase(
const char* a_path,
size_t a_line,
size_t a_column,
const char* a_name,
const std::vector<std::shared_ptr<AstBase>>& a_nodes)
2182 :
path(a_path ? a_path :
"")
2186 , original_name(a_name)
2187 #ifndef PEGLIB_NO_CONSTEXPR_SUPPORT
2195 AstBase(
const char* a_path,
size_t a_line,
size_t a_column,
const char* a_name,
const std::string& a_token)
2196 :
path(a_path ? a_path :
"")
2200 , original_name(a_name)
2201 #ifndef PEGLIB_NO_CONSTEXPR_SUPPORT
2214 , original_name(a_original_name)
2215 #ifndef PEGLIB_NO_CONSTEXPR_SUPPORT
2217 , original_tag(
str2tag(a_original_name))
2219 , is_token(ast.is_token)
2222 , parent(ast.parent)
2231 #ifndef PEGLIB_NO_CONSTEXPR_SUPPORT 2239 std::vector<std::shared_ptr<AstBase<Annotation>>>
nodes;
2246 if(node->name ==
name)
2251 operator const char *()
2253 return token.c_str();
2257 template <
typename T>
2259 const std::shared_ptr<T>&
ptr,
2264 const auto& ast = *
ptr;
2265 for (
auto i = 0; i <
level; i++) {
2269 if (ast.name == ast.original_name) {
2272 name = ast.original_name +
"[" + ast.name +
"]";
2275 s +=
"- " +
name +
" (" + ast.token +
")\n";
2277 s +=
"+ " +
name +
"\n";
2282 for (
auto node : ast.nodes) {
2287 template <
typename T>
2289 const std::shared_ptr<T>&
ptr,
2299 AstOptimizer(
bool optimize_nodes,
const std::vector<std::string>& filters = {})
2300 : optimize_nodes_(optimize_nodes)
2301 , filters_(filters) {}
2303 template <
typename T>
2304 std::shared_ptr<T>
optimize(std::shared_ptr<T> original, std::shared_ptr<T> parent =
nullptr) {
2306 auto found = std::find(filters_.begin(), filters_.end(), original->name) != filters_.end();
2307 bool opt = optimize_nodes_ ? !found : found;
2309 if (
opt && original->nodes.size() == 1) {
2310 auto child = optimize(original->nodes[0], parent);
2311 return std::make_shared<T>(*child, original->name.c_str());
2314 auto ast = std::make_shared<T>(*original);
2315 ast->parent = parent;
2317 for (
auto node : original->nodes) {
2318 auto child = optimize(node, ast);
2319 ast->nodes.push_back(child);
2329 template <
typename T>
2331 std::shared_ptr<T> ast,
2332 const std::vector<std::string>& filters = {}) {
2333 return AstOptimizer(
true, filters).optimize(ast);
2356 return grammar_ !=
nullptr;
2360 grammar_ = ParserGenerator::parse(
2363 [&](
const char* a_s,
size_t a_n,
size_t a_id,
const std::string& a_name) {
2364 if (match_action) match_action(a_s, a_n, a_id, a_name);
2368 return grammar_ !=
nullptr;
2373 return load_grammar(
s,
n);
2377 if (grammar_ !=
nullptr) {
2378 const auto& rule = (*grammar_)[start_];
2379 auto r = rule.parse(
s,
n,
path);
2380 output_log(
s,
n,
r);
2381 return r.ret &&
r.len ==
n;
2388 return parse_n(
s,
n,
path);
2392 if (grammar_ !=
nullptr) {
2393 const auto& rule = (*grammar_)[start_];
2394 auto r = rule.parse(
s,
n, dt,
path);
2395 output_log(
s,
n,
r);
2396 return r.ret &&
r.len ==
n;
2403 return parse_n(
s,
n, dt,
path);
2406 template <
typename T>
2408 if (grammar_ !=
nullptr) {
2409 const auto& rule = (*grammar_)[start_];
2410 auto r = rule.parse_and_get_value(
s,
n,
val,
path);
2411 output_log(
s,
n,
r);
2412 return r.ret &&
r.len ==
n;
2417 template <
typename T>
2423 template <
typename T>
2425 if (grammar_ !=
nullptr) {
2426 const auto& rule = (*grammar_)[start_];
2427 auto r = rule.parse_and_get_value(
s,
n, dt,
val,
path);
2428 output_log(
s,
n,
r);
2429 return r.ret &&
r.len ==
n;
2434 template <
typename T>
2437 return parse_n(
s,
n, dt,
val);
2440 bool search(
const char*
s,
size_t n,
size_t& mpos,
size_t& mlen)
const {
2441 const auto& rule = (*grammar_)[start_];
2442 if (grammar_ !=
nullptr) {
2445 size_t len =
n - pos;
2446 auto r = rule.parse(
s + pos,
len);
2460 bool search(
const char*
s,
size_t& mpos,
size_t& mlen)
const {
2462 return search(
s,
n, mpos, mlen);
2466 return (*grammar_)[
s];
2470 if (grammar_ !=
nullptr) {
2471 auto& rule = (*grammar_)[start_];
2472 rule.enablePackratParsing =
true;
2476 template <
typename T = Ast>
2478 for (
auto&
x: *grammar_) {
2479 const auto&
name =
x.first;
2480 auto& rule =
x.second;
2483 auto is_token = rule.is_token;
2485 auto line =
line_info(sv.ss, sv.c_str());
2488 return std::make_shared<T>(sv.path, line.first, line.second,
name.c_str(), sv.token());
2491 auto ast = std::make_shared<T>(sv.path, line.first, line.second,
name.c_str(), sv.transform<std::shared_ptr<T>>());
2493 for (
auto node: ast->nodes) {
2504 if (grammar_ !=
nullptr) {
2505 auto& rule = (*grammar_)[start_];
2506 rule.tracer = tracer;
2517 if (
r.message_pos) {
2519 log(line.first, line.second,
r.message);
2522 log(line.first, line.second,
"syntax error");
2524 }
else if (
r.len !=
n) {
2526 log(line.first, line.second,
"syntax error");
2557 return matches.empty();
2561 return matches.size();
2565 return matches[
n].length();
2569 return matches[
n].str();
2577 return matches.begin();
2581 return matches.end();
2585 return matches.cbegin();
2589 return matches.cend();
2593 std::vector<size_t> ret;
2594 for (
auto i = 0u; i < matches.size(); i++) {
2603 std::map<std::string, std::vector<size_t>> ret;
2604 for (
auto i = 0u; i < matches.size(); i++) {
2605 ret[matches[i].name].push_back(i);
2611 std::vector<size_t> ret;
2612 for (
auto i = 0u; i < matches.size(); i++) {
2613 if (matches[i].
id ==
id) {
2621 std::map<size_t, std::vector<size_t>> ret;
2622 for (
auto i = 0u; i < matches.size(); i++) {
2623 ret[matches[i].id].push_back(i);
2634 m.matches.push_back(
match::Item{ a_s, a_n, a_id, a_name });
2655 m.matches.push_back(
match::Item{ a_s, a_n, a_id, a_name });
2659 auto ret = pg.
search(
s,
n, mpos, mlen);
2690 , pos_((
std::numeric_limits<size_t>::max)()) {}
2697 peg_.match_action = [&](
const char* a_s,
size_t a_n,
size_t a_id,
const std::string& a_name) {
2698 m_.matches.push_back(
match::Item{ a_s, a_n, a_id, a_name });
2730 return pos_ == rhs.
pos_;
2734 return pos_ != rhs.
pos_;
2741 if (peg_.search(s_ + pos_, l_ - pos_, mpos, mlen)) {
2743 pos_ += mpos + mlen;
2745 pos_ = (std::numeric_limits<size_t>::max)();
2788 template<
class _Elem,
class _Traits,
typename Annotation>
2789 std::basic_ios<_Elem, _Traits> &
operator << (std::basic_ios<_Elem, _Traits> &ios,
2792 return ios << node.
token.c_str();
std::string chars_
Definition: peglib.h:940
iterator begin()
Definition: peglib.h:2764
Definition: peglib.h:2179
const any & get() const
Definition: peglib.h:139
virtual void visit(ZeroOrMore &)
Definition: peglib.h:1124
iterator begin()
Definition: peglib.h:2576
Fty make_adaptor(F fn, R(F::*)(const SemanticValues &sv) const)
Definition: peglib.h:423
AstBase(const char *a_path, size_t a_line, size_t a_column, const char *a_name, const std::string &a_token)
Definition: peglib.h:2195
static std::shared_ptr< T > optimize_ast(std::shared_ptr< T > ast, const std::vector< std::string > &filters={})
Definition: peglib.h:2330
std::vector< std::pair< std::string, const char * > > duplicates
Definition: peglib.h:1671
GLuint const GLchar * name
Definition: glext.h:6671
Definition: peglib.h:1638
GLuint * ids
Definition: glext.h:6547
std::pair< size_t, size_t > line_info() const
Definition: peglib.h:251
Definition & operator[](const char *s)
Definition: peglib.h:2465
virtual void visit(Sequence &)
Definition: peglib.h:1122
std::function< size_t(const char *s, size_t n, SemanticValues &sv, any &dt)> Parser
Definition: peglib.h:1035
const GLvoid * ptr
Definition: nx_glsym.h:242
std::string token(size_t id=0) const
Definition: peglib.h:261
const char * message_pos
Definition: peglib.h:1216
Fty make_adaptor(F fn, R(*)(const SemanticValues &sv, any &dt))
Definition: peglib.h:448
Whitespace(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:1099
peg_token_iterator beg_iter
Definition: peglib.h:2781
virtual ~placeholder()
Definition: peglib.h:145
virtual void visit(TokenBoundary &)
Definition: peglib.h:1134
Definition: peglib.h:1171
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:810
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
void visit(DefinitionReference &ope) override
Definition: peglib.h:1166
virtual void visit(Capture &)
Definition: peglib.h:1133
#define const
Definition: zconf.h:217
~scope_exit()
Definition: peglib.h:184
bool empty() const
Definition: peglib.h:2556
std::shared_ptr< AstBase< Annotation > > parent
Definition: peglib.h:2240
GLuint GLfloat * val
Definition: glext.h:7847
set set set set set set set macro pixldst1 op
Definition: pixman-arm-neon-asm.h:54
size_t nest_level
Definition: peglib.h:506
const peg_token_iterator const_iterator
Definition: peglib.h:2758
any(const any &rhs)
Definition: peglib.h:59
void visit(PrioritizedChoice &ope) override
Definition: peglib.h:1182
static const unsigned char tag[MAX_TESTS *3][16]
Definition: gcm.c:696
Result parse(const char *s, const char *path=nullptr) const
Definition: peglib.h:1281
Definition(Definition &&rhs)
Definition: peglib.h:1238
Action(F fn)
Definition: peglib.h:368
peg_token_iterator end_iter
Definition: peglib.h:2782
std::shared_ptr< Ope > wsp(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:1627
void accept(Visitor &v) override
Definition: peglib.h:1540
AstBase< EmptyType > Ast
Definition: peglib.h:2337
Definition: peglib.h:2541
std::pair< size_t, size_t > line_info(const char *start, const char *cur)
Definition: peglib.h:215
Sequence(const Sequence &rhs)
Definition: peglib.h:625
void pop()
Definition: peglib.h:596
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:728
void trace(const char *name, const char *a_s, size_t n, SemanticValues &sv, any &dt) const
Definition: peglib.h:604
match & operator*()
Definition: peglib.h:2721
std::basic_ios< _Elem, _Traits > & operator<<(std::basic_ios< _Elem, _Traits > &ios, peg::AstBase< Annotation > &node)
Definition: peglib.h:2789
std::shared_ptr< Ope > ope_
Definition: peglib.h:835
void visit(AndPredicate &ope) override
Definition: peglib.h:1159
Holder(Definition *outer)
Definition: peglib.h:1057
Definition: peglib.h:2336
bool parse_n(const char *s, size_t n, any &dt, T &val, const char *path=nullptr) const
Definition: peglib.h:2424
Definition()
Definition: peglib.h:1220
std::shared_ptr< Grammar > grammar_
Definition: peglib.h:2531
GLuint start
Definition: glext.h:6292
const std::string original_name
Definition: peglib.h:2230
Character(char ch)
Definition: peglib.h:946
auto transform(size_t beg=0, size_t end=static_cast< size_t >(-1)) const -> vector< T >
Definition: peglib.h:272
Definition: peglib.h:1681
std::vector< std::shared_ptr< Ope > > opes_
Definition: peglib.h:720
Definition * outer_
Definition: peglib.h:1067
bool operator!=(const peg_token_iterator &rhs)
Definition: peglib.h:2733
const bool enablePackratParsing
Definition: peglib.h:514
const std::string message
Definition: peglib.h:1217
Definition & operator=(Action a)
Definition: peglib.h:1329
const char * s_
Definition: peglib.h:1766
scope_exit(scope_exit &&rhs)
Definition: peglib.h:178
~any()
Definition: peglib.h:89
GLdouble GLdouble GLdouble r
Definition: glext.h:6406
std::shared_ptr< Ope > cho(Args &&...args)
Definition: peglib.h:1567
Action(const Action &rhs)
Definition: peglib.h:365
std::shared_ptr< Ope > seq(Args &&...args)
Definition: peglib.h:1562
GLsizei const GLchar ** path
Definition: glext.h:7901
bool done_
Definition: peglib.h:1771
std::function< void(const char *name, const char *s, size_t n, const SemanticValues &sv, const Context &c, const any &dt)> Tracer
Definition: peglib.h:488
void accept(Visitor &v) override
Definition: peglib.h:1528
std::shared_ptr< T > optimize(std::shared_ptr< T > original, std::shared_ptr< T > parent=nullptr)
Definition: peglib.h:2304
size_t id_
Definition: peglib.h:1000
peg_token_iterator iterator
Definition: peglib.h:2757
std::string lit_
Definition: peglib.h:904
static overlayled_t * cur
Definition: led_overlay.c:18
void visit(OneOrMore &ope) override
Definition: peglib.h:1157
Definition & operator<=(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:1264
GLenum GLsizei len
Definition: glext.h:7389
bool operator==(const peg_token_iterator &rhs)
Definition: peglib.h:2729
void accept(Visitor &v) override
Definition: peglib.h:1536
const std::vector< std::string > filters_
Definition: peglib.h:2326
void accept(Visitor &v) override
Definition: peglib.h:1532
virtual size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const =0
AndPredicate(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:841
GLsizeiptr size
Definition: glext.h:6559
const size_t l
Definition: peglib.h:497
const bool optimize_nodes_
Definition: peglib.h:2325
std::unordered_map< std::string, const char * > references
Definition: peglib.h:1672
virtual void visit(PrioritizedChoice &)
Definition: peglib.h:1123
GLfloat f
Definition: glext.h:8207
std::string name
Definition: peglib.h:2545
constexpr unsigned int str2tag(const char *str, int h=0)
Definition: peglib.h:2167
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld endif[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld_src SRC pixld MASK if DST_R else pixld DST_R endif if
Definition: pixman-arm-neon-asm.h:543
Result parse_and_get_value(const char *s, T &val, const char *path=nullptr) const
Definition: peglib.h:1308
size_t size() const
Definition: peglib.h:718
std::vector< Item >::const_iterator const_iterator
Definition: peglib.h:2554
std::function< R(const SemanticValues &sv, any &dt)> fn_
Definition: peglib.h:417
GLenum GLuint id
Definition: glext.h:6233
Definition: peglib.h:2756
std::shared_ptr< Grammar > grammar
Definition: peglib.h:1668
void visit(AnyCharacter &) override
Definition: peglib.h:1736
std::map< std::pair< size_t, size_t >, std::tuple< size_t, any > > cache_values
Definition: peglib.h:518
TypeAdaptor(std::function< R(const SemanticValues &sv)> fn)
Definition: peglib.h:402
size_t length(size_t n=0)
Definition: peglib.h:2564
bool search(const char *s, size_t n, size_t &mpos, size_t &mlen) const
Definition: peglib.h:2440
GLdouble s
Definition: glext.h:6390
size_t choice() const
Definition: peglib.h:256
std::shared_ptr< Ope > ref(const std::unordered_map< std::string, Definition > &grammar, const std::string &name, const char *s)
Definition: peglib.h:1623
Definition: peglib.h:2539
const size_t column
Definition: peglib.h:2227
std::once_flag init_
Definition: peglib.h:1092
void visit(CharacterClass &) override
Definition: peglib.h:1730
PrioritizedChoice(std::vector< std::shared_ptr< Ope >> &&opes)
Definition: peglib.h:687
size_t parse(const char *s, size_t n, SemanticValues &, Context &c, any &dt) const override
Definition: peglib.h:1021
void enable_trace(Tracer tracer)
Definition: peglib.h:2503
Result parse_core(const char *s, size_t n, SemanticValues &sv, any &dt, const char *path) const
Definition: peglib.h:1372
void visit(LiteralString &ope) override
Definition: peglib.h:1727
GLsizei const GLchar *const * string
Definition: glext.h:6699
Log log
Definition: peglib.h:2511
ParserGenerator()
Definition: peglib.h:1662
peg_token_range(const char *syntax, const char *s)
Definition: peglib.h:2760
static std::shared_ptr< Grammar > parse(const char *s, size_t n, std::string &start, MatchAction ma, Log log)
Definition: peglib.h:1641
const char * path
Definition: peglib.h:239
std::shared_ptr< Ope > get_rule() const
Definition: peglib.h:1518
scope_exit(EF &&f)
Definition: peglib.h:174
AstBase(const char *a_path, size_t a_line, size_t a_column, const char *a_name, const std::vector< std::shared_ptr< AstBase >> &a_nodes)
Definition: peglib.h:2181
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
void make_grammar()
Definition: peglib.h:1774
bool parse(const char *s, any &dt, const char *path=nullptr) const
Definition: peglib.h:2401
const Item & operator[](size_t n) const
Definition: peglib.h:2572
std::shared_ptr< Ope > get_core_operator()
Definition: peglib.h:1349
bool parse(const char *s, T &val, const char *path=nullptr) const
Definition: peglib.h:2418
void visit(TokenBoundary &) override
Definition: peglib.h:1191
T value_
Definition: peglib.h:155
OneOrMore(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:762
peg_token_iterator()
Definition: peglib.h:2687
bool success(size_t len)
Definition: peglib.h:475
any(const T &value)
Definition: peglib.h:66
void accept(Visitor &v) override
Definition: peglib.h:1530
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:912
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:6303
const GLubyte * c
Definition: glext.h:9812
void accept(Visitor &v) override
Definition: peglib.h:1535
size_t id
Definition: peglib.h:1354
typedef bool(RETRO_CALLCONV *retro_replace_image_index_t)(unsigned index
static Grammar & grammar()
Definition: peglib.h:1652
std::string name_
Definition: peglib.h:1769
bool is_hex(char c, int &v)
Definition: peglib.h:2078
std::string str() const
Definition: peglib.h:246
size_t len
Definition: peglib.h:1214
bool is_token() const
Definition: peglib.h:1196
void visit(ZeroOrMore &ope) override
Definition: peglib.h:1707
const std::unordered_map< std::string, Definition > & grammar_
Definition: peglib.h:1087
const char * s
Definition: peglib.h:496
const std::string name_
Definition: peglib.h:1088
void visit(Sequence &ope) override
Definition: peglib.h:1146
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:1512
std::pair< char, size_t > parse_octal_number(const char *s, size_t n, size_t i)
Definition: peglib.h:2110
bool parse(const char *s, const char *path=nullptr) const
Definition: peglib.h:2386
void accept(Visitor &v) override
Definition: peglib.h:1544
size_t pos_
Definition: peglib.h:2752
size_t l_
Definition: peglib.h:2751
Action(F)
Definition: peglib.h:374
const size_t def_count
Definition: peglib.h:513
NotPredicate(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:868
const_iterator begin() const
Definition: peglib.h:2584
static ParserGenerator & get_instance()
Definition: peglib.h:1657
std::vector< Item > matches
Definition: peglib.h:2551
void visit(Character &) override
Definition: peglib.h:1733
Data()
Definition: peglib.h:1675
void visit(Capture &ope) override
Definition: peglib.h:1190
#define log(...)
Definition: spirv_cross.cpp:28
GLenum type
Definition: glext.h:6233
virtual void visit(Whitespace &)
Definition: peglib.h:1139
bool parse_n(const char *s, size_t n, const char *path=nullptr) const
Definition: peglib.h:2376
virtual void visit(CharacterClass &)
Definition: peglib.h:1130
AstBase(const AstBase &ast, const char *a_original_name)
Definition: peglib.h:2209
std::string start
Definition: peglib.h:1669
bool l
Definition: connect_wiiupro.c:37
any & operator=(any &&rhs)
Definition: peglib.h:78
const char * ss
Definition: peglib.h:240
Fty fn_
Definition: peglib.h:452
std::shared_ptr< Ope > ope_
Definition: peglib.h:756
std::string name_
Definition: peglib.h:1001
void visit(Ignore &ope) override
Definition: peglib.h:1163
const unsigned int original_tag
Definition: peglib.h:2233
Definition: peglib.h:1004
std::shared_ptr< Ope > ope_
Definition: peglib.h:1113
placeholder * content_
Definition: peglib.h:162
IsToken()
Definition: peglib.h:1173
holder(const T &value)
Definition: peglib.h:151
virtual void visit(Option &)
Definition: peglib.h:1126
std::vector< std::shared_ptr< AstBase< Annotation > > > nodes
Definition: peglib.h:2239
void accept(Visitor &v) override
Definition: peglib.h:1537
PrioritizedChoice(const std::vector< std::shared_ptr< Ope >> &opes)
Definition: peglib.h:686
bool search(const char *s, size_t &mpos, size_t &mlen) const
Definition: peglib.h:2460
std::shared_ptr< Ope > oom(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:1575
DefinitionReference(const std::unordered_map< std::string, Definition > &grammar, const std::string &name, const char *s)
Definition: peglib.h:1075
std::shared_ptr< Ope > dot()
Definition: peglib.h:1603
const std::string name
Definition: peglib.h:2229
Definition & operator~()
Definition: peglib.h:1340
std::function< void(size_t, size_t, const std::string &)> Log
Definition: peglib.h:1636
Fty make_adaptor(F fn, R(F::*)(const SemanticValues &sv, any &dt) const)
Definition: peglib.h:438
std::function< any(const SemanticValues &sv, any &dt)> Fty
Definition: peglib.h:420
VULKAN_HPP_INLINE void swap(UniqueHandle< Type > &lhs, UniqueHandle< Type > &rhs)
Definition: vulkan.hpp:441
peg_token_iterator & operator++()
Definition: peglib.h:2710
std::shared_ptr< Ope > ope_
Definition: peglib.h:802
Sequence(const Args &...args)
Definition: peglib.h:640
std::shared_ptr< Ope > ope_
Definition: peglib.h:1066
std::vector< std::pair< const char *, size_t > > tokens
Definition: peglib.h:259
std::function< void(const char *, const char *, size_t, const SemanticValues &, const Context &, const any &)> tracer
Definition: peglib.h:520
size_t strlen(const char *str)
Definition: compat_ctype.c:152
void visit(OneOrMore &ope) override
Definition: peglib.h:1711
bool in_token
Definition: peglib.h:508
std::shared_ptr< Ope > rule_
Definition: peglib.h:1093
GLint level
Definition: glext.h:6293
bool is_undefined() const
Definition: peglib.h:93
any operator()(const SemanticValues &sv, any &dt)
Definition: peglib.h:414
void packrat(const char *a_s, size_t def_id, size_t &len, any &val, T fn)
Definition: peglib.h:549
std::string str(size_t n=0) const
Definition: peglib.h:2568
virtual void visit(NotPredicate &)
Definition: peglib.h:1128
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:843
std::shared_ptr< Holder > holder_
Definition: peglib.h:1386
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:948
void visit(OneOrMore &ope) override
Definition: peglib.h:1188
Definition: peglib.h:1096
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:870
std::function< void(any &dt)> enter
Definition: peglib.h:1356
std::string name
Definition: peglib.h:1353
TokenBoundary(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:1007
const char * what() const
Definition: peglib.h:462
std::shared_ptr< Ope > zom(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:1571
peg_token_iterator(const peg_token_iterator &rhs)
Definition: peglib.h:2703
const int AstDefaultTag
Definition: peglib.h:2164
const T & get() const
Definition: peglib.h:125
Result parse_and_get_value(const char *s, size_t n, T &val, const char *path=nullptr) const
Definition: peglib.h:1297
std::shared_ptr< Grammar > perform_core(const char *s, size_t n, std::string &start, MatchAction ma, Log log)
Definition: peglib.h:1987
iterator end()
Definition: peglib.h:2768
void visit(Holder &ope) override
Definition: peglib.h:1751
size_t n
Definition: peglib.h:2543
std::set< std::string > refs_
Definition: peglib.h:1770
GLint GLint GLint GLint GLint x
Definition: glext.h:6295
void visit(NotPredicate &ope) override
Definition: peglib.h:1723
parser peg_
Definition: peglib.h:2749
AstOptimizer(bool optimize_nodes, const std::vector< std::string > &filters={})
Definition: peglib.h:2299
void output_log(const char *s, size_t n, const Definition::Result &r) const
Definition: peglib.h:2514
size_t value_stack_size
Definition: peglib.h:504
iterator end()
Definition: peglib.h:2580
const size_t line
Definition: peglib.h:2226
void operator=(const scope_exit &)=delete
void visit(ZeroOrMore &ope) override
Definition: peglib.h:1156
bool ignoreSemanticValue
Definition: peglib.h:1359
void visit(TokenBoundary &ope) override
Definition: peglib.h:1742
void visit(TokenBoundary &ope) override
Definition: peglib.h:1162
dictionary args
Definition: test_shaders.py:20
match m_
Definition: peglib.h:2753
PrioritizedChoice(const Args &...args)
Definition: peglib.h:683
virtual void visit(Holder &)
Definition: peglib.h:1137
void visit(Option &ope) override
Definition: peglib.h:1189
const_iterator cbegin() const
Definition: peglib.h:2772
virtual void visit(Character &)
Definition: peglib.h:1131
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:966
std::shared_ptr< Ope > cls(const std::string &chars)
Definition: peglib.h:1595
void visit(Capture &ope) override
Definition: peglib.h:1739
const char * s_
Definition: peglib.h:1089
bool enablePackratParsing
Definition: peglib.h:1361
std::shared_ptr< Ope > ope_
Definition: peglib.h:892
std::string message
Definition: peglib.h:501
GLfloat GLfloat p
Definition: glext.h:9809
bool load_grammar(const char *s)
Definition: peglib.h:2371
const std::string token
Definition: peglib.h:2237
parse_error(const char *s)
Definition: peglib.h:461
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 idx
Definition: pixman-arm-neon-asm.h:96
GLenum GLenum GLvoid GLvoid * column
Definition: glext.h:6316
T & get()
Definition: peglib.h:101
bool is_token
Definition: peglib.h:1362
void visit(Sequence &ope) override
Definition: peglib.h:1687
const char * error_pos
Definition: peglib.h:499
std::string resolve_escape_sequence(const char *s, size_t n)
Definition: peglib.h:2120
Definition: peglib.h:1212
placeholder * clone() const
Definition: peglib.h:158
Result parse(const char *s, size_t n, any &dt, const char *path=nullptr) const
Definition: peglib.h:1286
void visit(ZeroOrMore &ope) override
Definition: peglib.h:1187
virtual void visit(OneOrMore &)
Definition: peglib.h:1125
match * operator->()
Definition: peglib.h:2725
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:1437
const char * s
Definition: peglib.h:2542
std::shared_ptr< Ope > opt(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:1579
std::shared_ptr< Ope > tok(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:1615
virtual placeholder * clone() const =0
parser(const char *s)
Definition: peglib.h:2352
Fty make_adaptor(F fn, R(*)(const SemanticValues &sv))
Definition: peglib.h:433
Grammar g
Definition: peglib.h:2157
void release()
Definition: peglib.h:190
Ignore(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:1019
bool has_token_boundary
Definition: peglib.h:1363
void accept(Visitor &v) override
Definition: peglib.h:1538
virtual ~Ope()
Definition: peglib.h:617
std::shared_ptr< Ope > ope_
Definition: peglib.h:1032
const char * error_pos
Definition: peglib.h:1215
Capture(const std::shared_ptr< Ope > &ope, MatchAction ma, size_t id, const std::string &name)
Definition: peglib.h:982
bool is_digit(char c, int &v)
Definition: peglib.h:2092
bool execute_on_destruction
Definition: peglib.h:200
void accept(Ope::Visitor &v)
Definition: peglib.h:1345
void accept(Visitor &v) override
Definition: peglib.h:1531
static peg::AstBase< Annotation > empty
Definition: peglib.h:2241
bool fail(size_t len)
Definition: peglib.h:479
SemanticValues()
Definition: peglib.h:276
void ast_to_s_core(const std::shared_ptr< T > &ptr, std::string &s, int level, std::function< std::string(const T &ast, int level)> fn)
Definition: peglib.h:2258
std::shared_ptr< Ope > ope_
Definition: peglib.h:1013
std::map< size_t, std::vector< size_t > > indexed_captures() const
Definition: peglib.h:2620
void visit(WeakHolder &ope) override
Definition: peglib.h:1193
std::shared_ptr< Ope > whitespaceOpe
Definition: peglib.h:510
void accept(Visitor &v) override
Definition: peglib.h:1539
Result parse(const char *s, any &dt, const char *path=nullptr) const
Definition: peglib.h:1291
const GLdouble * v
Definition: glext.h:6391
bool in_whitespace
Definition: peglib.h:511
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:646
Definition & operator,(T fn)
Definition: peglib.h:1335
void visit(Sequence &ope) override
Definition: peglib.h:1177
Definition: peglib.h:1037
void visit(PrioritizedChoice &ope) override
Definition: peglib.h:1698
GLenum cap
Definition: glext.h:10546
bool load_grammar(const char *s, size_t n)
Definition: peglib.h:2359
std::string str() const
Definition: peglib.h:2548
bool parse(const char *s, any &dt, T &val, const char *=nullptr) const
Definition: peglib.h:2435
const_iterator cend() const
Definition: peglib.h:2776
Option(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:808
std::shared_ptr< Ope > lit(const std::string &lit)
Definition: peglib.h:1591
const char * s_
Definition: peglib.h:2750
placeholder * clone() const override
Definition: peglib.h:152
Definition: peglib.h:2297
u32 col
Definition: gx_regdef.h:5093
std::function< R(const SemanticValues &sv)> fn_
Definition: peglib.h:407
std::vector< size_t > named_capture(const std::string &name) const
Definition: peglib.h:2592
void visit(AndPredicate &ope) override
Definition: peglib.h:1719
GLboolean GLboolean g
Definition: glext.h:6844
std::vector< std::shared_ptr< SemanticValues > > value_stack
Definition: peglib.h:503
void accept(Visitor &v) override
Definition: peglib.h:1542
size_t size() const
Definition: peglib.h:2560
const_iterator end() const
Definition: peglib.h:2588
void accept(Visitor &v) override
Definition: peglib.h:1534
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:1101
void search()
Definition: peglib.h:2738
std::vector< size_t > indexed_capture(size_t id) const
Definition: peglib.h:2610
std::shared_ptr< Ope > npd(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:1587
Tracer tracer
Definition: peglib.h:1364
Sequence(std::vector< std::shared_ptr< Ope >> &&opes)
Definition: peglib.h:644
virtual void visit(WeakHolder &)
Definition: peglib.h:1136
void visit(WeakHolder &ope) override
Definition: peglib.h:1748
std::shared_ptr< Ope > ope_
Definition: peglib.h:862
void operator=(F fn)
Definition: peglib.h:377
ZeroOrMore(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:726
void visit(WeakHolder &ope) override
Definition: peglib.h:1164
void accept(Visitor &v) override
Definition: peglib.h:1533
EF exit_function
Definition: peglib.h:199
parser(const char *s, size_t n)
Definition: peglib.h:2348
void accept(Visitor &v) override
Definition: peglib.h:1545
void visit(Ignore &ope) override
Definition: peglib.h:1745
std::shared_ptr< Ope > whitespaceOpe
Definition: peglib.h:1360
Definition(const Definition &rhs)
Definition: peglib.h:1227
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:1042
LiteralString(const std::string &s)
Definition: peglib.h:898
std::vector< Item >::iterator iterator
Definition: peglib.h:2553
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:985
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:689
size_t choice_
Definition: peglib.h:308
const char * c_str() const
Definition: peglib.h:243
auto make_scope_exit(EF &&exit_function) -> scope_exit< EF >
Definition: peglib.h:204
bool ret
Definition: peglib.h:1213
virtual void visit(DefinitionReference &)
Definition: peglib.h:1138
char ch_
Definition: peglib.h:960
void setup_actions()
Definition: peglib.h:1841
std::function< void(const char *s, size_t n, size_t id, const std::string &name)> MatchAction
Definition: peglib.h:470
any operator()(const SemanticValues &sv, any &)
Definition: peglib.h:404
Definition: peglib.h:1142
void visit(DefinitionReference &) override
Definition: peglib.h:1194
MatchAction match_action
Definition: peglib.h:2510
std::string s_
Definition: peglib.h:464
void visit(Option &ope) override
Definition: peglib.h:1158
Definition: peglib.h:2684
std::vector< bool > cache_registered
Definition: peglib.h:515
void visit(Ignore &ope) override
Definition: peglib.h:1192
std::string ast_to_s(const std::shared_ptr< T > &ptr, std::function< std::string(const T &ast, int level)> fn=nullptr)
Definition: peglib.h:2288
bool peg_search(const char *syntax, const char *s, match &m)
Definition: peglib.h:2678
any reduce(const SemanticValues &sv, any &dt) const
Definition: peglib.h:1502
virtual void visit(Ignore &)
Definition: peglib.h:1135
Definition: peglib.h:1072
any & operator=(const any &rhs)
Definition: peglib.h:68
GLsizei const GLfloat * value
Definition: glext.h:6709
std::shared_ptr< Ope > apd(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:1583
size_t length() const
Definition: peglib.h:244
std::shared_ptr< Ope > ign(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:1619
size_t length() const
Definition: peglib.h:2547
void visit(PrioritizedChoice &ope) override
Definition: peglib.h:1151
static const char * WHITESPACE_DEFINITION_NAME
Definition: peglib.h:1204
auto transform(F f) const -> vector< typename std::remove_const< decltype(f(any()))>::type >
Definition: peglib.h:311
bool has_token_boundary
Definition: peglib.h:1200
Definition: peglib.h:1016
const unsigned int tag
Definition: peglib.h:2232
void accept(Visitor &v) override
Definition: peglib.h:1543
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:764
parser & enable_ast()
Definition: peglib.h:2477
size_t n_
Definition: peglib.h:307
DetectLeftRecursion(const std::string &name)
Definition: peglib.h:1682
const bool is_token
Definition: peglib.h:2236
peg_token_iterator(const char *syntax, const char *s)
Definition: peglib.h:2692
const char * message_pos
Definition: peglib.h:500
GLuint GLuint end
Definition: glext.h:6292
peg_token_iterator operator++(int)
Definition: peglib.h:2715
bool parse_n(const char *s, size_t n, T &val, const char *path=nullptr) const
Definition: peglib.h:2407
std::map< std::string, std::vector< size_t > > named_captures() const
Definition: peglib.h:2602
void visit(NotPredicate &ope) override
Definition: peglib.h:1160
#define false
Definition: ordinals.h:83
Context(const char *a_path, const char *a_s, size_t a_l, size_t a_def_count, std::shared_ptr< Ope > a_whitespaceOpe, bool a_enablePackratParsing, Tracer a_tracer)
Definition: peglib.h:522
CharacterClass(const std::string &chars)
Definition: peglib.h:910
std::unordered_map< void *, size_t > ids
Definition: peglib.h:1168
std::shared_ptr< Ope > chr(char dt)
Definition: peglib.h:1599
void operator=(F)
Definition: peglib.h:387
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:8390
void set_error_pos(const char *a_s)
Definition: peglib.h:600
MatchAction match_action_
Definition: peglib.h:999
virtual ~Visitor()
Definition: peglib.h:1121
virtual void visit(AnyCharacter &)
Definition: peglib.h:1132
void visit(Option &ope) override
Definition: peglib.h:1715
#define true
Definition: ordinals.h:82
Definition: peglib.h:1667
SemanticValues & push()
Definition: peglib.h:579
std::vector< bool > cache_success
Definition: peglib.h:516
virtual void accept(Visitor &v)=0
Sequence(const std::vector< std::shared_ptr< Ope >> &opes)
Definition: peglib.h:643
Result parse_and_get_value(const char *s, size_t n, any &dt, T &val, const char *path=nullptr) const
Definition: peglib.h:1314
Fty make_adaptor(F fn, R(F::*)(const SemanticValues &sv))
Definition: peglib.h:428
uint8_t u8
8bit unsigned integer
Definition: gctypes.h:17
virtual void visit(LiteralString &)
Definition: peglib.h:1129
Result parse_and_get_value(const char *s, any &dt, T &val, const char *path=nullptr) const
Definition: peglib.h:1324
Definition: peglib.h:1209
std::vector< std::shared_ptr< Ope > > opes_
Definition: peglib.h:664
bool parse_n(const char *s, size_t n, any &dt, const char *path=nullptr) const
Definition: peglib.h:2391
any()
Definition: peglib.h:57
std::shared_ptr< Ope > ope_
Definition: peglib.h:996
size_t id
Definition: peglib.h:2544
Definition: peglib.h:1119
std::function< void(any &dt)> leave
Definition: peglib.h:1357
void visit(Capture &ope) override
Definition: peglib.h:1161
void accept(Visitor &v) override
Definition: peglib.h:1529
Context contains the render state used by various components.
Definition: Context.h:26
GLdouble n
Definition: glext.h:8396
size_t capture_count
Definition: peglib.h:1673
std::function< std::string()> error_message
Definition: peglib.h:1358
any call(F fn, Args &&... args)
Definition: peglib.h:337
const GLfloat * m
Definition: glext.h:11755
void enable_packrat_parsing()
Definition: peglib.h:2469
std::unordered_map< std::string, Definition > Grammar
Definition: peglib.h:1635
Definition(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:1250
#define is_digit(c)
Definition: kprintf.c:17
Result parse(const char *s, size_t n, const char *path=nullptr) const
Definition: peglib.h:1275
Definition: peglib.h:1054
bool has_rule
Definition: peglib.h:1201
const char *const str
Definition: portlistingparse.c:18
void accept(Visitor &v) override
Definition: peglib.h:1541
const std::string path
Definition: peglib.h:2225
void visit(DefinitionReference &ope) override
Definition: peglib.h:1754
virtual void visit(AndPredicate &)
Definition: peglib.h:1127
any operator()(const SemanticValues &sv, any &dt) const
Definition: peglib.h:395
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6844
bool peg_match(const char *syntax, const char *s)
Definition: peglib.h:2646
auto transform(size_t beg, size_t end, F f) const -> vector< typename std::remove_const< decltype(f(any()))>::type >
Definition: peglib.h:320
const char * s_
Definition: peglib.h:306
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:1393
TypeAdaptor_c(std::function< R(const SemanticValues &sv, any &dt)> fn)
Definition: peglib.h:412
std::string start_
Definition: peglib.h:2532
std::pair< char, size_t > parse_hex_number(const char *s, size_t n, size_t i)
Definition: peglib.h:2100
std::weak_ptr< Ope > weak_
Definition: peglib.h:1051
MatchAction match_action
Definition: peglib.h:1670
Action action
Definition: peglib.h:1355
const char * path
Definition: peglib.h:495
Definition: peglib.h:2343
any(any &&rhs)
Definition: peglib.h:61
size_t parse(const char *s, size_t n, SemanticValues &sv, Context &c, any &dt) const override
Definition: peglib.h:1418
WeakHolder(const std::shared_ptr< Ope > &ope)
Definition: peglib.h:1040
Fty make_adaptor(F fn, R(F::*)(const SemanticValues &sv, any &dt))
Definition: peglib.h:443