-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.pegvoice
85 lines (73 loc) · 1.6 KB
/
test.pegvoice
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
_digit = word:(
one / two / three / four / five /
six / seven / eight / nine / naught / zero
) _dragon? {
const digits = {
"one": 1,
"two": 2,
"three": 3,
"four": 4,
"five": 5,
"six": 6,
"seven": 7,
"eight": 8,
"nine": 9,
"zero": 0,
"naught": 0,
};
return digits.hasOwnProperty(word) ? digits[word] : parseInt(word, 10);
}
number_ten_word = ...{
ten => 10;
eleven => 11;
twelve => 12;
thirteen => 13;
fourteen => 14;
fifteen => 15;
sixteen => 16;
seventeen => 17;
eighteen => 18;
nineteen => 19;
}
number_ten_combo_word = ...{
twenty => 20;
thirty => 30;
fourty => 40;
fifty => 50;
sixty => 60;
seventy => 70;
eighty => 80;
ninety => 90;
}
_number_ten_combo = word:_number_ten_combo_word digit:(_ _digit)? {
return word + (extractOptional(digit, 1) || 0);
}
_number_ten = _number_ten_word / _number_ten_combo
_number_ten_or_less = _number_ten / _digit;
_number_hundred = hundred:(_number_ten_or_less _ "hundred" (_ "and")?) ten:(_ _number_ten_or_less)? {
let number = 0;
if (hundred) {
number += hundred[0] * 100;
}
return number + (ten ? ten[1] : 0);
}
_number_pair = hundred:_number_ten_or_less _ ten:_number_ten {
return hundred * 100 + ten;
}
_number_hundred_word = a _ hundred { return 100; }
_number = _number_hundred_word / _number_pair / _number_hundred / _number_ten_or_less;
:number back space => key('backspace');
:number jump => key('up');
back :number => key('up');
spell a;
spell one;
spell two;
spell three;
spell four;
spell five;
spell six;
spell seven;
spell eight;
spell nine;
spell naught;
spell zero;