From d6f38436a229dc4421e77b58bf42d07bdb28b808 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 1 Feb 2020 17:12:35 +0100 Subject: Implement | as or --- apt-pkg/cachefilter-patterns.cc | 44 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'apt-pkg/cachefilter-patterns.cc') diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc index dbe42b83f..8c0b35de2 100644 --- a/apt-pkg/cachefilter-patterns.cc +++ b/apt-pkg/cachefilter-patterns.cc @@ -70,7 +70,45 @@ std::unique_ptr PatternTreeParser::parseTop() // Parse any pattern std::unique_ptr PatternTreeParser::parse() { - return parseAnd(); + return parseOr(); +} + +std::unique_ptr PatternTreeParser::parseOr() +{ + auto start = state.offset; + std::vector> nodes; + + auto firstNode = parseAnd(); + + if (firstNode == nullptr) + return nullptr; + + nodes.push_back(std::move(firstNode)); + for (skipSpace(); sentence[state.offset] == '|'; skipSpace()) + { + state.offset++; + skipSpace(); + auto node = parseAnd(); + + if (node == nullptr) + throw Error{Node{state.offset, sentence.size()}, "Expected pattern after |"}; + + nodes.push_back(std::move(node)); + } + + if (nodes.size() == 0) + return nullptr; + if (nodes.size() == 1) + return std::move(nodes[0]); + + auto node = std::make_unique(); + node->start = start; + node->end = nodes[nodes.size() - 1]->end; + node->term = "?or"; + node->arguments = std::move(nodes); + node->haveArgumentList = true; + + return node; } std::unique_ptr PatternTreeParser::parseAnd() @@ -266,8 +304,8 @@ std::unique_ptr PatternTreeParser::parseQuotedWord() // Parse a bare word atom std::unique_ptr PatternTreeParser::parseWord() { - static const constexpr auto DISALLOWED_START = "!?~,()\0"_sv; - static const constexpr auto DISALLOWED = ",()\0"_sv; + static const constexpr auto DISALLOWED_START = "!?~|,()\0"_sv; + static const constexpr auto DISALLOWED = "|,()\0"_sv; if (DISALLOWED_START.find(sentence[state.offset]) != APT::StringView::npos) return nullptr; -- cgit v1.2.3-70-g09d2