convert CNF-normalized operator tree to terms, a CNF AND-list of ALT-term lists
| 382 | |
| 383 | // convert CNF-normalized operator tree to terms, a CNF AND-list of ALT-term lists |
| 384 | void CNF::OpTree::convert(Terms& terms) |
| 385 | { |
| 386 | if (op == OpTree::AND) |
| 387 | { |
| 388 | for (const auto& i : list) |
| 389 | { |
| 390 | if (!terms.back().empty()) |
| 391 | terms.emplace_back(); |
| 392 | |
| 393 | if (i.op == OpTree::OR) |
| 394 | { |
| 395 | auto k = i.list.begin(); |
| 396 | auto e = i.list.end(); |
| 397 | |
| 398 | while (k != e && (k->op != NONE || !k->regex.empty())) |
| 399 | ++k; |
| 400 | |
| 401 | if (k != e) |
| 402 | { |
| 403 | // empty pattern found, ignore all other patterns |
| 404 | k->add_to(terms); |
| 405 | } |
| 406 | else |
| 407 | { |
| 408 | for (const auto& j : i.list) |
| 409 | j.add_to(terms); |
| 410 | } |
| 411 | } |
| 412 | else |
| 413 | { |
| 414 | i.add_to(terms); |
| 415 | } |
| 416 | |
| 417 | if (terms.back().empty()) |
| 418 | { |
| 419 | // pop unused ending '|' (or BRE '\|') |
| 420 | terms.pop_back(); |
| 421 | if (flag_basic_regexp) |
| 422 | terms.pop_back(); |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | else if (op == OpTree::OR) |
| 427 | { |
| 428 | for (const auto& i : list) |
| 429 | i.add_to(terms); |
| 430 | } |
| 431 | else |
| 432 | { |
| 433 | add_to(terms); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | // add a [NOT] term of the operator tree to terms |
| 438 | void CNF::OpTree::add_to(Terms& terms) const |