SIL Non-Roman Script Initiative

Graphite

A free and open rendering engine for complex scripts

Graphite Tutorial

Exercise

Unit 17: Optional items

Discussion

It is possible to specify optional items in a rule. This is done by following the optional item with a question mark. For instance, if we say that the intervening X in the rule from Unit 16 is optional, our rule looks like this:

gA  gB  >  @3  @1  /  _  gX?  _;

Notice that the indexing of elements must take into account all optional items; hence gB is considered item #3 in the above rule.

Optional markers can be placed either in the left-hand side or the context, but not in the right-hand side.

Ranges of items can be marked optional by using square brackets:

gA  gB  >  @3  @1  /  _  [gX gY gZ]?  _;

Note that in the rule above, the entire sequence ‘X Y Z’ must occur or none of it is allowed. You can also embed sequences of optional items. In the following rule, X may occur zero to three times:

gA  gB  >  @3  @1  /  _  [gX [gX gX? ]? ]?  _;

Exercise

Extend your program from Exercise 16 to handle the presence of a consonant cluster before the vowel to be moved; i.e., allow one or two optional consonants between the initial consonant and the vowel.

Hint: instead of switching items, you may need to delete the vowel and reinsert it.

Compare the rules listed in the dbg_ruleprec.txt file with your source code.

Solution

Copyright © 2012 SIL International® and released under the  Creative Commons Attribution-ShareAlike 3.0 license (CC-BY-SA) unless noted otherwise.