mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 11:55:30 +00:00
parent
54b14aa4d9
commit
45fb3d4f3b
31
peglib.h
31
peglib.h
@ -461,7 +461,7 @@ struct SemanticValues : protected std::vector<std::any> {
|
||||
// Input text
|
||||
const char *path = nullptr;
|
||||
const char *ss = nullptr;
|
||||
const std::vector<size_t> *source_line_index = nullptr;
|
||||
std::function<const std::vector<size_t> &()> source_line_index;
|
||||
|
||||
// Matched string
|
||||
std::string_view sv() const { return sv_; }
|
||||
@ -473,7 +473,7 @@ struct SemanticValues : protected std::vector<std::any> {
|
||||
|
||||
// Line number and column at which the matched string is
|
||||
std::pair<size_t, size_t> line_info() const {
|
||||
const auto &idx = *source_line_index;
|
||||
auto &idx = source_line_index();
|
||||
|
||||
auto cur = static_cast<size_t>(std::distance(ss, sv_.data()));
|
||||
auto it = std::lower_bound(
|
||||
@ -838,11 +838,6 @@ public:
|
||||
cache_success(enablePackratParsing ? def_count * (l + 1) : 0),
|
||||
tracer_enter(tracer_enter), tracer_leave(tracer_leave), log(log) {
|
||||
|
||||
for (size_t pos = 0; pos < l; pos++) {
|
||||
if (s[pos] == '\n') { source_line_index.push_back(pos); }
|
||||
}
|
||||
source_line_index.push_back(l);
|
||||
|
||||
args_stack.resize(1);
|
||||
|
||||
push_capture_scope();
|
||||
@ -905,7 +900,16 @@ public:
|
||||
auto &vs = *value_stack[value_stack_size++];
|
||||
vs.path = path;
|
||||
vs.ss = s;
|
||||
vs.source_line_index = &source_line_index;
|
||||
vs.source_line_index = [&]() -> const std::vector<size_t> & {
|
||||
if (source_line_index.empty()) {
|
||||
for (size_t pos = 0; pos < l; pos++) {
|
||||
if (s[pos] == '\n') { source_line_index.push_back(pos); }
|
||||
}
|
||||
source_line_index.push_back(l);
|
||||
}
|
||||
return source_line_index;
|
||||
};
|
||||
|
||||
return vs;
|
||||
}
|
||||
|
||||
@ -2430,25 +2434,30 @@ inline size_t parse_literal(const char *s, size_t n, SemanticValues &vs,
|
||||
}
|
||||
|
||||
// Word check
|
||||
if (c.wordOpe) {
|
||||
std::call_once(init_is_word, [&]() {
|
||||
SemanticValues dummy_vs;
|
||||
Context dummy_c(nullptr, c.s, c.l, 0, nullptr, nullptr, false, nullptr,
|
||||
nullptr, nullptr);
|
||||
std::any dummy_dt;
|
||||
|
||||
std::call_once(init_is_word, [&]() {
|
||||
if (c.wordOpe) {
|
||||
auto len =
|
||||
c.wordOpe->parse(lit.data(), lit.size(), dummy_vs, dummy_c, dummy_dt);
|
||||
is_word = success(len);
|
||||
}
|
||||
});
|
||||
|
||||
if (is_word) {
|
||||
SemanticValues dummy_vs;
|
||||
Context dummy_c(nullptr, c.s, c.l, 0, nullptr, nullptr, false, nullptr,
|
||||
nullptr, nullptr);
|
||||
std::any dummy_dt;
|
||||
|
||||
NotPredicate ope(c.wordOpe);
|
||||
auto len = ope.parse(s + i, n - i, dummy_vs, dummy_c, dummy_dt);
|
||||
if (fail(len)) { return len; }
|
||||
i += len;
|
||||
}
|
||||
}
|
||||
|
||||
// Skip whiltespace
|
||||
if (!c.in_token_boundary_count) {
|
||||
|
Loading…
Reference in New Issue
Block a user