Next: Guide Line for Distributed Style Sheets, Previous: The Entry in sheets.map, Up: A Tutorial on Style Sheets [Contents][Index]
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 (see Grouping Operators in Regex manual), 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.
Next: Guide Line for Distributed Style Sheets, Previous: The Entry in sheets.map, Up: A Tutorial on Style Sheets [Contents][Index]