mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 11:55:30 +00:00
Changed 'match' back to 'parse'.
This commit is contained in:
parent
8441a1f104
commit
0643f44b03
@ -41,7 +41,7 @@ parser["TAG_NAME"] = [&](const char* s, size_t l) {
|
||||
};
|
||||
|
||||
// (4) Parse
|
||||
auto ret = parser.match(" [tag1] [tag:2] [tag-3] ");
|
||||
auto ret = parser.parse(" [tag1] [tag:2] [tag-3] ");
|
||||
|
||||
assert(ret == true);
|
||||
assert(tags[0] == "tag1");
|
||||
@ -111,7 +111,7 @@ int main(void) {
|
||||
};
|
||||
|
||||
int val;
|
||||
parser.match("1+2*3", val);
|
||||
parser.parse("1+2*3", val);
|
||||
|
||||
assert(val == 7);
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ int main(int argc, const char** argv)
|
||||
parser["NUMBER"] = [](const char* s, size_t l) { return atol(s); };
|
||||
|
||||
long val = 0;
|
||||
if (parser.match(s, val)) {
|
||||
if (parser.parse(s, val)) {
|
||||
cout << s << " = " << val << endl;
|
||||
return 0;
|
||||
}
|
||||
|
12
peglib.h
12
peglib.h
@ -1226,7 +1226,7 @@ public:
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool match(const char* s, size_t l, T& out, bool exact = true) const {
|
||||
bool parse(const char* s, size_t l, T& out, bool exact = true) const {
|
||||
if (grammar_ != nullptr) {
|
||||
const auto& rule = (*grammar_)[start_];
|
||||
auto r = rule.parse(s, l, out);
|
||||
@ -1235,7 +1235,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool match(const char* s, size_t l, bool exact = true) const {
|
||||
bool parse(const char* s, size_t l, bool exact = true) const {
|
||||
if (grammar_ != nullptr) {
|
||||
const auto& rule = (*grammar_)[start_];
|
||||
auto r = rule.parse(s, l);
|
||||
@ -1245,14 +1245,14 @@ public:
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool match(const char* s, T& out, bool exact = true) const {
|
||||
bool parse(const char* s, T& out, bool exact = true) const {
|
||||
auto l = strlen(s);
|
||||
return match(s, l, out, exact);
|
||||
return parse(s, l, out, exact);
|
||||
}
|
||||
|
||||
bool match(const char* s, bool exact = true) const {
|
||||
bool parse(const char* s, bool exact = true) const {
|
||||
auto l = strlen(s);
|
||||
return match(s, l, exact);
|
||||
return parse(s, l, exact);
|
||||
}
|
||||
|
||||
bool lint(const char* s, size_t l, bool exact, Log log = nullptr) {
|
||||
|
10
test/test.cc
10
test/test.cc
@ -26,7 +26,7 @@ TEST_CASE("String capture test", "[general]")
|
||||
tags.push_back(std::string(s, l));
|
||||
};
|
||||
|
||||
auto ret = parser.match(" [tag1] [tag:2] [tag-3] ");
|
||||
auto ret = parser.parse(" [tag1] [tag:2] [tag-3] ");
|
||||
|
||||
REQUIRE(ret == true);
|
||||
REQUIRE(tags.size() == 3);
|
||||
@ -97,7 +97,7 @@ TEST_CASE("Lambda action test", "[general]")
|
||||
ss += *s;
|
||||
};
|
||||
|
||||
bool ret = parser.match("hello");
|
||||
bool ret = parser.parse("hello");
|
||||
REQUIRE(ret == true);
|
||||
REQUIRE(ss == "hello");
|
||||
}
|
||||
@ -116,7 +116,7 @@ TEST_CASE("Backtracking test", "[general]")
|
||||
count++;
|
||||
};
|
||||
|
||||
bool ret = parser.match("Hello Two");
|
||||
bool ret = parser.parse("Hello Two");
|
||||
REQUIRE(ret == true);
|
||||
REQUIRE(count == 2);
|
||||
}
|
||||
@ -153,7 +153,7 @@ TEST_CASE("Simple calculator test", "[general]")
|
||||
};
|
||||
|
||||
int val;
|
||||
parser.match("1+2*3", val);
|
||||
parser.parse("1+2*3", val);
|
||||
|
||||
REQUIRE(val == 7);
|
||||
}
|
||||
@ -281,7 +281,7 @@ TEST_CASE("Calculator test3", "[general]")
|
||||
|
||||
// Parse
|
||||
long val;
|
||||
auto ret = parser.match("1+2*3*(4-5+6)/7-8", val);
|
||||
auto ret = parser.parse("1+2*3*(4-5+6)/7-8", val);
|
||||
|
||||
REQUIRE(ret == true);
|
||||
REQUIRE(val == -3);
|
||||
|
Loading…
Reference in New Issue
Block a user