next up previous 204
Next: Indirection Elements
Up: Group Expressions
Previous: Elements and Delimiters

Editing of Names

Each element in a group expression will give rise to one or more names (depending on whether the element consists of a literal name, an indirection element or a modification element). These names may be edited before being stored in a group by including certain ``editing strings'' within the text of the element. The general format of an element with editing strings included is:

      prefix{kernel}suffix|old|new|

The kernel string can be a single element, or can be a full group expression. Processing of the element proceeds as follows:

  1. The kernel is first expanded to give a list of literal names. This may involve reading names from files, copying names from another group, etc, depending on the exact nature of the kernel. The characters which mark the start and end of the kernel are known as the opening and closing kernel delimiters. They are usually set to be ``{'' and ``}'', but can be changed if needed.

  2. Each name is checked to see if it contains the old string. If it does, all occurrences of the old string are replaced by the new string. The character which delimits the old and new strings is known as the ``separator'' character and is usually a ``$\mid$'' character, but can be changed if needed. This substitution will be case sensitive if the group to which the names are to be added has been designated as case sensitive (see section [*]). If no substitutions are to be performed then the old and new strings, together with the three separator characters, should be omitted.

  3. The prefix string is added to the start of each name, and the suffix string is appended to the end of each name. Either or both of these strings may be null (i.e. of zero length).

The names which result from this processing are then added to a group. If there is no ambiguity about where the kernel starts and finishes (for instance if the prefix and suffix are both omitted, and the kernel consists of a single element) then the kernel does not need to be enclosed within kernel delimiters. The contents of the kernel can be any group expression. In particular, the kernel can contain other nested kernels with their own associated editing strings.

Let's look at some examples:

      A_{TOM,DICK,HARRY}_B

This will give rise to the three names A_TOM_B, A_DICK_B and A_HARRY_B.

      ^FILE.LIS|_OLD|_NEW|

This will read names from the text file FILE.LIS (see the description of indirection elements below), and replace all occurrences of the string ``_OLD'' within the names with the string ``_NEW''.

      WW,{A,B_{ONE,TWO,THREE}|T|Z|,C}KK|_Z|_Y|

This is a complex example and needs looking at carefully. Looking at it at the highest level, it can be thought of as:

      WW,{kernel}KK|_Z|_Y|

where kernel is the group expression:

      A,B_{ONE,TWO,THREE}|T|Z|,C

The first and third elements in this inner group expression are simple literal names and give rise to the two names A and C. The second element specifies that the three names ONE, TWO and THREE are to be edited by replacement of the letter T by the letter Z, and the addition of the prefix B_. After editing, these three names become B_ONE, B_ZWO and B_ZHREE. So the total group specified by this inner kernel is:

      A
      B_ONE
      B_ZWO
      B_ZHREE
      C

We can now go back and look at the full group expression in the form:

      WW,{kernel}KK|_Z|_Y|

The first element specifies the single name WW. The second element specifies that each of the names arising from the expansion of the inner kernel (i.e. the names listed above) should be edited by replacing _Z with _Y, and then appending the suffix KK. Thus the final group contains:

      WW
      AKK
      B_ONEKK
      B_YWOKK
      B_YHREEKK
      CKK


next up previous 204
Next: Indirection Elements
Up: Group Expressions
Previous: Elements and Delimiters

GRP Routines for Managing Groups of Objects
Starlink User Note 150
D.S. Berry
21st October 2009
E-mail:ussc@star.rl.ac.uk

Copyright © 2009 Science and Technology Facilities Council