mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
Fixed more infinite loop grammar problems
This commit is contained in:
parent
f560ceca97
commit
ac602d5542
BIN
docs/native.wasm
BIN
docs/native.wasm
Binary file not shown.
17
peglib.h
17
peglib.h
@ -3518,7 +3518,7 @@ private:
|
|||||||
for (auto &x : grammar) {
|
for (auto &x : grammar) {
|
||||||
auto &rule = x.second;
|
auto &rule = x.second;
|
||||||
|
|
||||||
ReferenceChecker vis(*data.grammar, rule.params);
|
ReferenceChecker vis(grammar, rule.params);
|
||||||
rule.accept(vis);
|
rule.accept(vis);
|
||||||
for (const auto &y : vis.error_s) {
|
for (const auto &y : vis.error_s) {
|
||||||
const auto &name = y.first;
|
const auto &name = y.first;
|
||||||
@ -3536,7 +3536,7 @@ private:
|
|||||||
// Link references
|
// Link references
|
||||||
for (auto &x : grammar) {
|
for (auto &x : grammar) {
|
||||||
auto &rule = x.second;
|
auto &rule = x.second;
|
||||||
LinkReferences vis(*data.grammar, rule.params);
|
LinkReferences vis(grammar, rule.params);
|
||||||
rule.accept(vis);
|
rule.accept(vis);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3561,12 +3561,12 @@ private:
|
|||||||
if (!ret) { return nullptr; }
|
if (!ret) { return nullptr; }
|
||||||
|
|
||||||
// Set root definition
|
// Set root definition
|
||||||
auto &start_rule = (*data.grammar)[data.start];
|
auto &start_rule = grammar[data.start];
|
||||||
|
|
||||||
// Check infinite loop
|
// Check infinite loop
|
||||||
{
|
for (auto &[name, rule] : grammar) {
|
||||||
DetectInfiniteLoop vis(data.start_pos, data.start);
|
DetectInfiniteLoop vis(rule.s_, name);
|
||||||
start_rule.accept(vis);
|
rule.accept(vis);
|
||||||
if (vis.has_error) {
|
if (vis.has_error) {
|
||||||
if (log) {
|
if (log) {
|
||||||
auto line = line_info(s, vis.error_s);
|
auto line = line_info(s, vis.error_s);
|
||||||
@ -3586,13 +3586,12 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
start_rule.whitespaceOpe =
|
start_rule.whitespaceOpe =
|
||||||
wsp((*data.grammar)[WHITESPACE_DEFINITION_NAME].get_core_operator());
|
wsp(grammar[WHITESPACE_DEFINITION_NAME].get_core_operator());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Word expression
|
// Word expression
|
||||||
if (grammar.count(WORD_DEFINITION_NAME)) {
|
if (grammar.count(WORD_DEFINITION_NAME)) {
|
||||||
start_rule.wordOpe =
|
start_rule.wordOpe = grammar[WORD_DEFINITION_NAME].get_core_operator();
|
||||||
(*data.grammar)[WORD_DEFINITION_NAME].get_core_operator();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply instructions
|
// Apply instructions
|
||||||
|
Loading…
Reference in New Issue
Block a user