summaryrefslogtreecommitdiff
path: root/apt-pkg/cachefilter-patterns.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2020-02-01 17:12:35 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2020-02-03 12:55:54 +0100
commitd6f38436a229dc4421e77b58bf42d07bdb28b808 (patch)
treeb281d073ceea4e4d670d243e88b0bf1201b45c29 /apt-pkg/cachefilter-patterns.cc
parentcfec457d599373e6014b1f4472f48d5f989d76a5 (diff)
Implement | as or
Diffstat (limited to 'apt-pkg/cachefilter-patterns.cc')
-rw-r--r--apt-pkg/cachefilter-patterns.cc44
1 files changed, 41 insertions, 3 deletions
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::Node> PatternTreeParser::parseTop()
// Parse any pattern
std::unique_ptr<PatternTreeParser::Node> PatternTreeParser::parse()
{
- return parseAnd();
+ return parseOr();
+}
+
+std::unique_ptr<PatternTreeParser::Node> PatternTreeParser::parseOr()
+{
+ auto start = state.offset;
+ std::vector<std::unique_ptr<PatternTreeParser::Node>> 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<PatternNode>();
+ 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::Node> PatternTreeParser::parseAnd()
@@ -266,8 +304,8 @@ std::unique_ptr<PatternTreeParser::Node> PatternTreeParser::parseQuotedWord()
// Parse a bare word atom
std::unique_ptr<PatternTreeParser::Node> 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;