gnu-arch-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnu-arch-users] Preventing matches in regular expressions


From: Tom Lord
Subject: Re: [Gnu-arch-users] Preventing matches in regular expressions
Date: Wed, 11 Aug 2004 00:11:46 -0700 (PDT)


    > From: Aaron Bentley <address@hidden>

    > I'd like to have a "categorize" command in Fai that would rewrite the 
    > .arch-inventory and =tagging-method rules.  I'd like to be able to do:

    > --
    > $fai categorize --local --backup --extension .zip
    > $fai categorize --local --unrecognized fox.zip
    > --

    > That would add or update the regexes in the .arch-inventory.  But since 
    > backup is tried before unrecognized, the rule for backup must match 
    > every zip file except 'fox.zip'

So then this command:

    > $fai categorize --local --unrecognized fox.zip

means something like:

    "Let the rules I've specified so far be called X.
 
     The new rules are: 
        If the file is fox.zip it's unrecognized,
        otherwise, things work just like under rules X."

Is that really the idea?  


I don't know of an easy way to do that without modifying tla.

On the other hand, it can be an upward compatible change.

In general, you are looking for a way to efficiently classify
files using an extensible conditional like:


        if file matches R1
          then class is C1
        else if file matches R2
          then class is C2
        else if file matches R3
          then class is C3
        ...


Each call to `category' (normally) adds a new rule (appends a new
`else if' clause).  It could be made easy for users to delete or
re-order existing rules.

The problem here is that the per-file activities of the `inventory'
loop are performance-critical.   It's already bad that we cal
`regexec' several times.   One really doesn't want to make that loop
any more costly.

Rx offers a pretty decent solution:

How do you feel about arch depending upon Rx (for all practical
purposes)?   (Arguably, it already does, of course.)


In rx, you can write:

    R1[[:cut 1:]]|R2[[:cut 2:]]|R3[[:cut 3:]]| ...

and a single call to regexec will tell you which regexp matched.
(Rx `regexec' returns an extra value -- the "state label" which
can be set by using the `cut' operator.)

That rx trick is exactly equivalent to the conditional i think you are
trying to implement.

So, for your fai feature, you could:

  Propose a new alternative to =tagging-method files (or new 
  syntax to go inside of them), allowing for directives 
  in which the ordering of directives is significant.

  Modify the inventory code to use the rx optimization. 
  As a side effect, you'll probably make `tla inventory' faster.

-t





reply via email to

[Prev in Thread] Current Thread [Next in Thread]