diff options
author | Julian Andres Klode <julian.klode@canonical.com> | 2020-01-28 22:38:46 +0100 |
---|---|---|
committer | Julian Andres Klode <julian.klode@canonical.com> | 2020-02-03 12:55:54 +0100 |
commit | 250119362e44599aad7e75462fa4298ad1ab1ad9 (patch) | |
tree | 8dc35269b74db8d099d8638866c404fc7c00d0bb /apt-pkg/cachefilter-patterns.cc | |
parent | ebe5f39bfbb64921d5d31e0a6e49287356a5e6e2 (diff) |
patterns: Parse sequence of patterns as ?and
Diffstat (limited to 'apt-pkg/cachefilter-patterns.cc')
-rw-r--r-- | apt-pkg/cachefilter-patterns.cc | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc index cf3e59ac6..dbf58e2a9 100644 --- a/apt-pkg/cachefilter-patterns.cc +++ b/apt-pkg/cachefilter-patterns.cc @@ -70,7 +70,37 @@ std::unique_ptr<PatternTreeParser::Node> PatternTreeParser::parseTop() // Parse any pattern std::unique_ptr<PatternTreeParser::Node> PatternTreeParser::parse() { - return parseUnary(); + return parseAnd(); +} + +std::unique_ptr<PatternTreeParser::Node> PatternTreeParser::parseAnd() +{ + auto start = state.offset; + std::vector<std::unique_ptr<PatternTreeParser::Node>> nodes; + + for (skipSpace(); state.offset < sentence.size(); skipSpace()) + { + auto node = parseUnary(); + + if (node == nullptr) + break; + + 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 = "?and"; + node->arguments = std::move(nodes); + node->haveArgumentList = true; + + return node; } std::unique_ptr<PatternTreeParser::Node> PatternTreeParser::parseUnary() |