1 #--------------------------------------------------------------------
2 # Copyright (c) 1999-2004, International Business Machines
3 # Corporation and others. All Rights Reserved.
4 #--------------------------------------------------------------------
6 # According to the pinyin definitions I've been able to find:
7 # 'a', 'e' are the preferred bases
11 # The trailing form of syllables are the following:
12 # "a", "ai", "ao", "an", "ang",
14 # "e", "ei", "er", "en", "eng",
15 # "i", "ia", "iao", "ie", "iu", "ian", "in", "iang", "ing", "iong",
16 # "u", "ua", "uo", "uai", "ui", "uan", "un", "uang", "ueng",
17 # "ü", "üe", "üan", "ün"
18 # so the letters the tone will 'hop' are:
21 $tone = [\u0304\u0301\u030C\u0300\u0306] ;
23 # Move the tone to the end of a syllable, and convert to number
24 e {($tone) r} > r &tone-digit($1);
25 ($tone) ( [i o n u {o n} {n g}]) > $2 &tone-digit($1);
26 ($tone) > &tone-digit($1);
28 # The following backs up until it finds the right vowel, then deposits the tone
30 $vowel = [aAeEiIoOuUüÜ];
31 $consonant = [[a-z A-Z] - [$vowel]];
33 $1 &digit-tone($3) $2 < ([aAeE]) ($vowel* $consonant*) ($digit);
34 $1 &digit-tone($3) $2 < ([oO]) ([$vowel-[aeAE]]* $consonant*) ($digit);
35 $1 &digit-tone($3) $2 < ($vowel) ($consonant*) ($digit);
36 &digit-tone($1) < [:letter:] {($digit)};