Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve #304: adding start node parameter #305

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions peglib.h
Original file line number Diff line number Diff line change
Expand Up @@ -4569,19 +4569,19 @@ class parser {
return load_grammar(sv.data(), sv.size());
}

bool parse_n(const char *s, size_t n, const char *path = nullptr) const {
bool parse_n(const char *s, size_t n, const char *path = nullptr, std::string_view start = "") const {
if (grammar_ != nullptr) {
const auto &rule = (*grammar_)[start_];
const auto &rule = (*grammar_)[!start.empty() ? std::string(start) : start_];
auto result = rule.parse(s, n, path, log_);
return post_process(s, n, result);
}
return false;
}

bool parse_n(const char *s, size_t n, std::any &dt,
const char *path = nullptr) const {
const char *path = nullptr, std::string_view start = "") const {
if (grammar_ != nullptr) {
const auto &rule = (*grammar_)[start_];
const auto &rule = (*grammar_)[!start.empty() ? std::string(start) : start_];
auto result = rule.parse(s, n, dt, path, log_);
return post_process(s, n, result);
}
Expand All @@ -4590,9 +4590,9 @@ class parser {

template <typename T>
bool parse_n(const char *s, size_t n, T &val,
const char *path = nullptr) const {
const char *path = nullptr, std::string_view start = "") const {
if (grammar_ != nullptr) {
const auto &rule = (*grammar_)[start_];
const auto &rule = (*grammar_)[!start.empty() ? std::string(start) : start_];
auto result = rule.parse_and_get_value(s, n, val, path, log_);
return post_process(s, n, result);
}
Expand All @@ -4601,57 +4601,57 @@ class parser {

template <typename T>
bool parse_n(const char *s, size_t n, std::any &dt, T &val,
const char *path = nullptr) const {
const char *path = nullptr, std::string_view start = "") const {
if (grammar_ != nullptr) {
const auto &rule = (*grammar_)[start_];
const auto &rule = (*grammar_)[!start.empty() ? std::string(start) : start_];
auto result = rule.parse_and_get_value(s, n, dt, val, path, log_);
return post_process(s, n, result);
}
return false;
}

bool parse(std::string_view sv, const char *path = nullptr) const {
bool parse(std::string_view sv, const char *path = nullptr, std::string_view start = "") const {
return parse_n(sv.data(), sv.size(), path);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path should be path, start

}

bool parse(std::string_view sv, std::any &dt,
const char *path = nullptr) const {
return parse_n(sv.data(), sv.size(), dt, path);
const char *path = nullptr, std::string_view start = "") const {
return parse_n(sv.data(), sv.size(), dt, path, start);
}

template <typename T>
bool parse(std::string_view sv, T &val, const char *path = nullptr) const {
return parse_n(sv.data(), sv.size(), val, path);
bool parse(std::string_view sv, T &val, const char *path = nullptr, std::string_view start = "") const {
return parse_n(sv.data(), sv.size(), val, path, start);
}

template <typename T>
bool parse(std::string_view sv, std::any &dt, T &val,
const char *path = nullptr) const {
return parse_n(sv.data(), sv.size(), dt, val, path);
const char *path = nullptr, std::string_view start = "") const {
return parse_n(sv.data(), sv.size(), dt, val, path, start);
}

#if defined(__cpp_lib_char8_t)
bool parse(std::u8string_view sv, const char *path = nullptr) const {
return parse_n(reinterpret_cast<const char *>(sv.data()), sv.size(), path);
bool parse(std::u8string_view sv, const char *path = nullptr, std::string_view start = "") const {
return parse_n(reinterpret_cast<const char *>(sv.data()), sv.size(), path, start);
}

bool parse(std::u8string_view sv, std::any &dt,
const char *path = nullptr) const {
const char *path = nullptr, std::string_view start = "") const {
return parse_n(reinterpret_cast<const char *>(sv.data()), sv.size(), dt,
path);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path should be path, start

}

template <typename T>
bool parse(std::u8string_view sv, T &val, const char *path = nullptr) const {
bool parse(std::u8string_view sv, T &val, const char *path = nullptr, std::string_view start = "") const {
return parse_n(reinterpret_cast<const char *>(sv.data()), sv.size(), val,
path);
path, start);
}

template <typename T>
bool parse(std::u8string_view sv, std::any &dt, T &val,
const char *path = nullptr) const {
const char *path = nullptr, std::string_view start = "") const {
return parse_n(reinterpret_cast<const char *>(sv.data()), sv.size(), dt,
val, path);
val, path, start);
}
#endif

Expand Down