Changed 'match' back to 'parse'.

pull/3/head
yhirose 9 years ago
parent 8441a1f104
commit 0643f44b03
  1. 4
      README.md
  2. 2
      example/calc.cc
  3. 12
      peglib.h
  4. 10
      test/test.cc

@ -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;
}

@ -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) {

@ -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…
Cancel
Save