Towards normalization
[framework/uifw/harfbuzz.git] / src / hb-ot-shape-complex-indic-machine.rl
1 /*
2  * Copyright © 2011  Google, Inc.
3  *
4  *  This is part of HarfBuzz, a text shaping library.
5  *
6  * Permission is hereby granted, without written agreement and without
7  * license or royalty fees, to use, copy, modify, and distribute this
8  * software and its documentation for any purpose, provided that the
9  * above copyright notice and the following two paragraphs appear in
10  * all copies of this software.
11  *
12  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16  * DAMAGE.
17  *
18  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23  *
24  * Google Author(s): Behdad Esfahbod
25  */
26
27 #ifndef HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH
28 #define HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH
29
30 #include "hb-private.hh"
31
32 HB_BEGIN_DECLS
33
34 %%{
35   machine indic_syllable_machine;
36   alphtype unsigned char;
37   write data;
38 }%%
39
40 %%{
41
42 # Same order as enum indic_category_t.  Not sure how to avoid duplication.
43 X    = 0;
44 C    = 1;
45 Ra   = 2;
46 V    = 3;
47 N    = 4;
48 H    = 5;
49 ZWNJ = 6;
50 ZWJ  = 7;
51 M    = 8;
52 SM   = 9;
53 VD   = 10;
54 A    = 11;
55 NBSP = 12;
56
57 c = C | Ra;
58 z = ZWJ|ZWNJ;
59 matra_group = M N? H?;
60 syllable_tail = SM? (VD VD?)?;
61
62 action found_syllable {
63   found_syllable (map, buffer, last, p);
64   last = p;
65 }
66
67 consonant_syllable =    (c.N? (z.H|H.z?))* c.N? A? (H.z? | matra_group*)? syllable_tail %(found_syllable);
68 vowel_syllable =        (Ra H)? V N? (z.H.c | ZWJ.c)? matra_group* syllable_tail;
69 standalone_cluster =    (Ra H)? NBSP N? (z? H c)? matra_group* syllable_tail;
70 non_indic = X;
71
72 syllable =
73           consonant_syllable
74         | vowel_syllable
75         | standalone_cluster
76         | non_indic
77         ;
78
79 main := syllable**;
80
81 }%%
82
83
84 #include <stdio.h>
85 #include <string.h>
86
87 static void
88 find_syllables (hb_ot_map_t *map, hb_buffer_t *buffer)
89 {
90   unsigned int p, pe, eof;
91   int cs;
92   %%{
93     write init;
94     getkey buffer->info[p].indic_category();
95   }%%
96
97   p = 0;
98   pe = eof = buffer->len;
99
100   unsigned int last = 0;
101   %%{
102     write exec;
103   }%%
104 }
105
106 HB_END_DECLS
107
108 #endif /* HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH */