(a2ps.info)More Sophisticated Rules


Next: Distributed Style Sheets Prev: The Entry in sheets.map Up: A tutorial on style sheets
Enter node , (file) or (file)node

7.7.4 More Sophisticated Rules
------------------------------

The example we have presented until now uses only basic features, and
does not take advantage of the regexp.  In this section we should how to
write more evolved pretty printing rules.

   The target will be the lines like:
     Sun Apr 27 14:29:22 1997  Akim Demaille  <demaille@inf.enst.fr>

     Fri Apr 25 14:05:20 1997  Akim Demaille  <demaille@inf.enst.fr>

   There are three fields: the date, the name, the mail.  These lines
all start at the beginning of line.  The last field is the easier to
recognize: is starts with a '<', and finishes with a '>'.  Its rule is
then '/<[^>]+>/'.  It is now easier to specify the second: it is
composed only of words, at least one, separated by blanks, and is
followed by the mail: '/[[:alpha:]]+([ \t]+[[:alpha:]]+)*/'.  To
concatenate the two, we introduce optional blanks, and we put each one
into a pair of '('-')' to make each one a recognizable part:
     ([[:alpha:]]+([ \t]+[[:alpha:]]+)*)
     (.+)
     (<[^>]+>)

   Now the first part is rather easy: it starts at the beginning of the
line, finishes with a digit.  Once again, it is separated from the
following field by blanks.  Split by groups (*note Grouping Operators:
(regex)Grouping Operators.), we have:
     ^
     ([^\t ].*[0-9])
     ([ \t]+)
     ([[:alpha:]]+([ \t]+[[:alpha:]]+)*)
     (.+)
     (<[^>]+>)

   Now the destination is composed of back references to those groups,
together with a face:
     # We want to highlight the date and the maintainer name
     optional operators are
       (/^([^\t ].*[0-9])/                        # \1. The date
        /([ \t]+)/                                # \2. Spaces
        /([[:alpha:]]+([ \t]+[[:alpha:]]+)*)/     # \3. Name
        /(.+)/                                    # \5. space and <
        /(<[^>]+)>/                               # \6. email
        \1 Keyword, \2 Plain, \3 Keyword_strong,
        \5 Plain, \6 Keyword, > Plain)
     end operators

   Notice the way regexps are split, to ease reading.


automatically generated by info2www version 1.2.2.9