From 8886ea163032fb8bf64211a94c5dc252a4572a9c Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 1 Feb 2020 17:21:40 +0100 Subject: patterns: Implement parsing of (...) groups --- apt-pkg/cachefilter-patterns.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'apt-pkg/cachefilter-patterns.cc') 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::parsePrimary() return node; if ((node = parsePattern()) != nullptr) return node; + if ((node = parseGroup()) != nullptr) + return node; return nullptr; } +std::unique_ptr 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::parseArgument() { std::unique_ptr node; -- cgit v1.2.3