Changed 'match' back to 'parse'.

This commit is contained in:
yhirose 2015-02-14 12:58:17 -05:00
parent 8441a1f104
commit 0643f44b03
4 changed files with 14 additions and 14 deletions

View File

@ -41,7 +41,7 @@ parser["TAG_NAME"] = [&](const char* s, size_t l) {
}; };
// (4) Parse // (4) Parse
auto ret = parser.match(" [tag1] [tag:2] [tag-3] "); auto ret = parser.parse(" [tag1] [tag:2] [tag-3] ");
assert(ret == true); assert(ret == true);
assert(tags[0] == "tag1"); assert(tags[0] == "tag1");
@ -111,7 +111,7 @@ int main(void) {
}; };
int val; int val;
parser.match("1+2*3", val); parser.parse("1+2*3", val);
assert(val == 7); assert(val == 7);
} }

View File

@ -64,7 +64,7 @@ int main(int argc, const char** argv)
parser["NUMBER"] = [](const char* s, size_t l) { return atol(s); }; parser["NUMBER"] = [](const char* s, size_t l) { return atol(s); };
long val = 0; long val = 0;
if (parser.match(s, val)) { if (parser.parse(s, val)) {
cout << s << " = " << val << endl; cout << s << " = " << val << endl;
return 0; return 0;
} }

View File

@ -1226,7 +1226,7 @@ public:
} }
template <typename T> 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) { if (grammar_ != nullptr) {
const auto& rule = (*grammar_)[start_]; const auto& rule = (*grammar_)[start_];
auto r = rule.parse(s, l, out); auto r = rule.parse(s, l, out);
@ -1235,7 +1235,7 @@ public:
return false; 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) { if (grammar_ != nullptr) {
const auto& rule = (*grammar_)[start_]; const auto& rule = (*grammar_)[start_];
auto r = rule.parse(s, l); auto r = rule.parse(s, l);
@ -1245,14 +1245,14 @@ public:
} }
template <typename T> 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); 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); 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) { bool lint(const char* s, size_t l, bool exact, Log log = nullptr) {

View File

@ -26,7 +26,7 @@ TEST_CASE("String capture test", "[general]")
tags.push_back(std::string(s, l)); 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(ret == true);
REQUIRE(tags.size() == 3); REQUIRE(tags.size() == 3);
@ -97,7 +97,7 @@ TEST_CASE("Lambda action test", "[general]")
ss += *s; ss += *s;
}; };
bool ret = parser.match("hello"); bool ret = parser.parse("hello");
REQUIRE(ret == true); REQUIRE(ret == true);
REQUIRE(ss == "hello"); REQUIRE(ss == "hello");
} }
@ -116,7 +116,7 @@ TEST_CASE("Backtracking test", "[general]")
count++; count++;
}; };
bool ret = parser.match("Hello Two"); bool ret = parser.parse("Hello Two");
REQUIRE(ret == true); REQUIRE(ret == true);
REQUIRE(count == 2); REQUIRE(count == 2);
} }
@ -153,7 +153,7 @@ TEST_CASE("Simple calculator test", "[general]")
}; };
int val; int val;
parser.match("1+2*3", val); parser.parse("1+2*3", val);
REQUIRE(val == 7); REQUIRE(val == 7);
} }
@ -281,7 +281,7 @@ TEST_CASE("Calculator test3", "[general]")
// Parse // Parse
long val; 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(ret == true);
REQUIRE(val == -3); REQUIRE(val == -3);