mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 11:55:30 +00:00
Fixed Infinite loop 9 problem
This commit is contained in:
parent
3d68799d9c
commit
a9f7572a6c
6
peglib.h
6
peglib.h
@ -2945,6 +2945,12 @@ inline void DetectInfiniteLoop::visit(Reference &ope) {
|
||||
ope.rule_->accept(*this);
|
||||
refs_.pop_back();
|
||||
}
|
||||
|
||||
if (ope.is_macro_) {
|
||||
for (auto arg : ope.args_) {
|
||||
arg->accept(*this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void ReferenceChecker::visit(Reference &ope) {
|
||||
|
@ -168,39 +168,10 @@ TEST_CASE("Infinite loop 8", "[infinite loop]") {
|
||||
REQUIRE(!pg);
|
||||
}
|
||||
|
||||
TEST_CASE("Infinite 9", "[infinite loop]") {
|
||||
parser pg(R"(
|
||||
START <- __? SECTION*
|
||||
|
||||
SECTION <- HEADER __ ENTRIES __?
|
||||
|
||||
HEADER <- '[' _ CATEGORY (':' _ ATTRIBUTES)? ']'^header
|
||||
|
||||
CATEGORY <- < [-_a-zA-Z0-9\u0080-\uFFFF ]+ > _
|
||||
ATTRIBUTES <- ATTRIBUTE (',' _ ATTRIBUTE)*
|
||||
ATTRIBUTE <- < [-_a-zA-Z0-9\u0080-\uFFFF]+ > _
|
||||
|
||||
ENTRIES <- (ENTRY (__ ENTRY)*)?
|
||||
|
||||
ENTRY <- ONE_WAY PHRASE ('|' _ PHRASE)* !'='
|
||||
/ PHRASE ('|' _ PHRASE)+ !'='
|
||||
/ %recover(entry)
|
||||
|
||||
ONE_WAY <- PHRASE '=' _
|
||||
PHRASE <- WORD (' ' WORD)* _
|
||||
WORD <- < (![ \t\r\n=|[\]#] .)+ >
|
||||
|
||||
~__ <- _ (comment? nl _)+
|
||||
~_ <- [ \t]*
|
||||
|
||||
comment <- ('#' (!nl .)*)
|
||||
nl <- '\r'? '\n'
|
||||
|
||||
header <- (!__ .)* { message "invalid section header, missing ']'." }
|
||||
|
||||
# The `(!(__ / HEADER) )+` should be `(!(__ / HEADER) .)+`
|
||||
entry <- (!(__ / HEADER) )+ { message "invalid token '%t', expecting another phrase." }
|
||||
)");
|
||||
TEST_CASE("Infinite loop 9", "[infinite loop]") {
|
||||
parser pg(R"(
|
||||
ROOT <- %recover(('A' /)*)
|
||||
)");
|
||||
|
||||
REQUIRE(!pg);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user