APT 2.0 search patterns

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

APT 2.0 search patterns

Julian Andres Klode-4
Hi,

so this below is roughly a first draft at understanding
the syntax of search patterns of aptitude and integrating
it into apt. It's very incomplete and needs more work.

I hope to get a complete parser with a documented syntax
description so everyone can easily understand what's going
on later this cycle.

# What we are missing:

1) aptitude has a bug where I cannot match versions with
   ~ in it, as ~ begins a short pattern.

        $ aptitude search '?version(1.0~1)'
        E: Expected ')', got '~'.                
        $ aptitude search '~v1.0~1'
        E: Unknown pattern type: 1              

   I am considering restricting the syntax so that if we are
   in a function style pattern (starting with ?) that they may
   only contain other functional style pattern, that would fix
   it.

   Alternatively, it might be useful to accept ~ inside of where
   we expect a regex, such as version above.

2) fnmatch handling.

3) regex/fnmatch on architecture specification

4) weird corner cases like task^:architecture

   aptitude supports :arch only in the form of an exact name before
   it, e.g. apt:i386; whereas apt allows any pattern before it right
   now. I believe the apt approach makes more sense, and we should
   continue doing that, e.g.
 
   <stuff>:<arch> is equivalent to ?and(<stuff>,?architecture(<arch>))

   it's a bit unclear how to do that though. Probably every branch
   of atom should have an (':' arch)? at the end, or well we redefine
   atom as atom_archless and then atom = atom_archless (':' arch)?

How it works in my mind is that we'll change the cacheset code
that we currently have to take each argument and build a pattern
for it, and then execute the pattern against the cache. The patterns
being implemented as CacheFilters.

I expect there'll be some syntax that will behave different than
in 1.x, but I hope we can behave as similar as possible.

# Divergence from aptitude

* No explicit search targets, probably

# Search pattern syntax

## apt arguments (parsing modifier from right, then rest)

argument        = pattern ('-' | '+' )                 # pattern with modifier
                | task_name '^' (':' arch)?            # task - roughly equivalent to ~ttask_name or ?task(task_name)

## aptitude search patterns (left to right, longest match)

pattern         = condition_list

condition_list  =  and_group ( '|' and_group )*
and_group       = atom atom*

atom      = '!' atom
          | '(' condition_list ')'
          | '?' function_style_tail
          | '~' short_tail
          | regex                        # architecture specified
          | exact_name:architecture      # architecture specified

function_style_tail =   '=' variable
                    |   name '('  term_args ')'
                    |   name ':' atom               # XXX?


term_args   = XXX                       # basically atom ( ',' atom )*

short_tail = 'v'                        # virtual
           | 'b'                        # broken
           | 'g'                        # garbage
           | 'c'                        # config-files
           | 'i'                        # installed
           | 'E'                        # essential
           | 'F'                        # false
           | 'M'                        # automatic
           | 'N'                        # new
           | 'T'                        # true
           | 'U'                        # upgradable
           | 'o'                        # obsolete
           | 'P' atom                   # provides
           | 'C' atom                   # conflicts
           | 'W' atom                   # widen
           | 'S' atom atom              # narrow
           | 'D' deptype atom           # depends
           | 'D' 'B'? deptype atom      # depends
           | 'R' 'B'? deptype atom      # reverse-depends
           | 'a' action                 # action
           | XXXX  substr              # XXX





--
debian developer - deb.li/jak | jak-linux.org - free software dev
ubuntu core developer                              i speak de, en

Reply | Threaded
Open this post in threaded view
|

Re: APT 2.0 search patterns

Julian Andres Klode-4
On Mon, May 06, 2019 at 07:00:02PM +0200, Julian Andres Klode wrote:
> Hi,
>
> so this below is roughly a first draft at understanding
> the syntax of search patterns of aptitude and integrating
> it into apt. It's very incomplete and needs more work.

I have narrowed the syntax down in order to make things easier
to implement and more uniform, so the parsing first creates
a rough parse tree and then a more usable abstract syntax
tree (which can then be tree-walked).

We only support three forms of syntax now:

        pattern = '?' NAME
                | '?' NAME '(' pattern (',' pattern)* ','? ')'
                | WORD
                | QUOTED-WORD

It's kind of a lisp, just with the list head moved to before
the '(', and commas separating arguments.

where

        WORD = [0-9a-zA-Z-.*^$\[\]_\\]+
        QUOTED-WORD = "[^"]+"
        NAME = [0-9a-zA-Z-]

that said, we don't use a separate tokenizer.

this is parsed into a simple parse tree. The simple parse tree
has a few differences from the grammar above, but see for yourself:

        // Handles ?NAME and ?NAME(...
        struct PatternNode : public Node {
                APT::StringView term;
                std::vector<std::unique_ptr<Node>> arguments;

                std::ostream& render(std::ostream& stream) override;
        };

        // Handles barewords and quoted words
        struct WordNode : public Node {
                APT::StringView word;
                bool quoted = false;
                std::ostream& render(std::ostream& stream) override;
        };

The next step then is transforming that parse tree into an
abstract syntax tree. Nothing done on that front yet.

Parser is attached, it parses a given argument and prints out
JSON.

--
debian developer - deb.li/jak | jak-linux.org - free software dev
ubuntu core developer                              i speak de, en

patterns.cc (4K) Download Attachment