1# Copyright (C) 2017  Olga Yakovleva <yakovleva.o.v@gmail.com>
2
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU Lesser General Public License as published by
5# the Free Software Foundation, either version 2.1 of the License, or
6# (at your option) any later version.
7
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU Lesser General Public License for more details.
12
13# You should have received a copy of the GNU Lesser General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16define NZDigit 1|2|3|4|5|6|7|8|9;
17define Digit %0|NZDigit;
18define Number [%0|[NZDigit Digit^<12]];
19
20define NamesOfPowersOfTen мең|миллион|миллиард ;
21
22define InsertThousands
23[..] -> мең || Digit _ Digit^3 .#.;
24
25define InsertMillions
26[..] -> миллион || Digit _ Digit^3 мең;
27
28define InsertBillions
29[..] -> миллиард || Digit _ Digit^3 миллион;
30
31define InsertHundreds
32[NZDigit 0:йөз] | [%0:0] -> || _ Digit^2 ;
33
34define RemoveSkippedParts
35%0^3 NamesOfPowersOfTen @-> 0 ;
36
37define Units %0:0|1:бер|2:ике|3:өч|4:дүрт|5:биш|6:алты|7:җиде|8:сигез|9:тугыз;
38
39define Teens 1:0 [%0:ун|1:унбер|2:унике|3:унөч|4:ундүрт|5:унбиш|6:уналты|7:унҗиде|8:унсигез|9:унтугыз] ;
40
41define Tens %0:0|2:егерме|3:утыз|4:кырык|5:илле|6:алтмыш|7:җитмеш|8:сиксән|9:туксан ;
42
43define UpToHundred %0:нүл .P. [Teens | [(Tens) Units]];
44
45define DigitsToWords
46UpToHundred @-> ;
47
48regex
49Number .o.
50InsertThousands .o.
51InsertMillions .o.
52InsertBillions .o.
53RemoveSkippedParts .o.
54InsertHundreds .o.
55DigitsToWords ;
56