SIL Writing Systems Technology


A free and open rendering engine for complex scripts

Graphite Tutorial

Unit 6: Context



Often it is desirable to include items in your rule that are not modified by the rule but are simply used for matching. These items are specified in the rule context. The syntax for the rule then becomes:

left-hand-side  >  right-hand-side  /  context;

Each item from the left- and right-hand sides is represented by an underscore in the context. (Note that this is a somewhat different meaning of an underscore than we saw in the previous unit for insertions and deletions.)

gA  gB  gC  >  gX  gY  gZ  /  gP  _  gQ  _  _  gR;

The above rule replaces A with X, B with Y, and C with Z. But it only is fired in the situation where gP, gQ, and gR occur as specified in the context, i.e., ‘P A Q B C R’. Notice that there is a one-to-one correspondence between the items in the left-hand side, the items in the right-hand side, and the underscores in the context.

Exercise 6a

Write a program to replace every instance of the letter c. Replace soft c’s with s and hard c’s with k. (Use the rule that soft c’s preceed e, i, and y, and hard c’s preceed a, o, u, and consonants.) Make sure that the case of the substituted letter matches that of the original “c”.


Exercise 6b

Extend your Greek program from Exercise 5b to always insert a lowercase u unless both the “Q” and the following letter are uppercase, in which case an uppercase “U” is inserted.


Exercise 6c

Extend your Greek program from Exercise 4c or 5a to replace a sigma with the word-final form (, U+03C2) where appropriate. Hint: use two rules, the first recognizing the situation where the sigma is not word-final.


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