/////////////////////////////////////////////////////////////////////////// Two consecutive FILTER, non-OP arguments that are not "(" or ")" need an "and" operator inserted between them. ) --> ) and ( --> ( ) ( --> ) and ( --> and
| 1739 | // <non-op> <non-op> --> <non-op> and <non-op> |
| 1740 | // |
| 1741 | void CLI2::insertJunctions() { |
| 1742 | bool changes = false; |
| 1743 | std::vector<A2> reconstructed; |
| 1744 | auto prev = _args.begin(); |
| 1745 | |
| 1746 | for (auto a = _args.begin(); a != _args.end(); ++a) { |
| 1747 | if (a->hasTag("FILTER")) { |
| 1748 | // The prev iterator should be the first FILTER arg. |
| 1749 | if (prev == _args.begin()) prev = a; |
| 1750 | |
| 1751 | // Insert AND between terms. |
| 1752 | else if (a != prev) { |
| 1753 | if ((prev->_lextype != Lexer::Type::op && a->attribute("raw") == "(" && |
| 1754 | !isEmptyParenExpression(a, true)) || |
| 1755 | (prev->attribute("raw") == ")" && a->_lextype != Lexer::Type::op && |
| 1756 | !isEmptyParenExpression(prev, false)) || |
| 1757 | (prev->attribute("raw") == ")" && a->attribute("raw") == "(" && |
| 1758 | !isEmptyParenExpression(a, true) && !isEmptyParenExpression(prev, false)) || |
| 1759 | (prev->_lextype != Lexer::Type::op && a->_lextype != Lexer::Type::op)) { |
| 1760 | A2 opOr("and", Lexer::Type::op); |
| 1761 | opOr.tag("FILTER"); |
| 1762 | reconstructed.push_back(opOr); |
| 1763 | changes = true; |
| 1764 | } |
| 1765 | } |
| 1766 | |
| 1767 | // Previous FILTER arg. |
| 1768 | prev = a; |
| 1769 | } |
| 1770 | |
| 1771 | reconstructed.push_back(*a); |
| 1772 | } |
| 1773 | |
| 1774 | if (changes) { |
| 1775 | _args = reconstructed; |
| 1776 | |
| 1777 | if (Context::getContext().config.getInteger("debug.parser") >= 2) |
| 1778 | Context::getContext().debug(dump("CLI2::prepareFilter insertJunctions")); |
| 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | //////////////////////////////////////////////////////////////////////////////// |
| 1783 | // Look for situations that require defaults: |