summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2020-02-01 17:21:40 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2020-02-03 12:55:54 +0100
commit8886ea163032fb8bf64211a94c5dc252a4572a9c (patch)
tree7bfa93c12cc72e488411ca8ba3a5a610dd9fcdb7 /apt-pkg
parentd6f38436a229dc4421e77b58bf42d07bdb28b808 (diff)
patterns: Implement parsing of (...) groups
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/cachefilter-patterns.cc26
-rw-r--r--apt-pkg/cachefilter-patterns.h1
2 files changed, 27 insertions, 0 deletions
diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc
index 8c0b35de2..c6875d995 100644
--- a/apt-pkg/cachefilter-patterns.cc
+++ b/apt-pkg/cachefilter-patterns.cc
@@ -169,10 +169,36 @@ std::unique_ptr<PatternTreeParser::Node> PatternTreeParser::parsePrimary()
return node;
if ((node = parsePattern()) != nullptr)
return node;
+ if ((node = parseGroup()) != nullptr)
+ return node;
return nullptr;
}
+std::unique_ptr<PatternTreeParser::Node> PatternTreeParser::parseGroup()
+{
+ if (sentence[state.offset] != '(')
+ return nullptr;
+
+ auto start = state.offset++;
+
+ skipSpace();
+ auto node = parse();
+ if (node == nullptr)
+ throw Error{Node{state.offset, sentence.size()},
+ "Expected pattern after '('"};
+ skipSpace();
+
+ if (sentence[state.offset] != ')')
+ throw Error{Node{state.offset, sentence.size()},
+ "Expected closing parenthesis"};
+
+ auto end = ++state.offset;
+ node->start = start;
+ node->end = end;
+ return node;
+}
+
std::unique_ptr<PatternTreeParser::Node> PatternTreeParser::parseArgument()
{
std::unique_ptr<Node> node;
diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h
index c6e701880..1b7e70da5 100644
--- a/apt-pkg/cachefilter-patterns.h
+++ b/apt-pkg/cachefilter-patterns.h
@@ -99,6 +99,7 @@ struct PatternTreeParser
std::unique_ptr<Node> parseAnd();
std::unique_ptr<Node> parseUnary();
std::unique_ptr<Node> parsePrimary();
+ std::unique_ptr<Node> parseGroup();
std::unique_ptr<Node> parsePattern();
std::unique_ptr<Node> parseShortPattern();
std::unique_ptr<Node> parseArgument();