eye-of-newt 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eye_of_newt/parser.rb +73 -53
- data/lib/eye_of_newt/parser.y +6 -4
- data/lib/eye_of_newt/tokenizer.rb +3 -0
- data/lib/eye_of_newt/version.rb +1 -1
- data/script/console +3 -0
- data/test/examples.txt +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa8794a5cef2066049431c1e0e171421b9f5fcca
|
4
|
+
data.tar.gz: 378020227175a0472e55f4ecb111c403b53549d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9284a0c28614d6a8ef5a20c040879ed0a5db9f162ea6065556e3a25e68a91fb80d99ec2929cc4425b3d7ab1fbb0c8cf54981fccb322f8a3027ec033691d9bc0
|
7
|
+
data.tar.gz: f7b2184eb2a7bf627e7e6f9324a00c9f0a4ee453b9ecee3e452968b47c99ad5814aef31ace40fb2aa72a0b515b038fb8d6f8579768aff68794de95d6c8c1d7b8
|
data/lib/eye_of_newt/parser.rb
CHANGED
@@ -32,69 +32,75 @@ module EyeOfNewt
|
|
32
32
|
##### State transition tables begin ###
|
33
33
|
|
34
34
|
racc_action_table = [
|
35
|
-
|
36
|
-
|
35
|
+
-19, 11, 15, 25, 14, 13, 11, -19, 11, 14,
|
36
|
+
13, 14, 13, 11, 23, 14, 14, 13, 27, 28,
|
37
|
+
20, 29, 20, 16, 14, 27, 33, 34 ]
|
37
38
|
|
38
39
|
racc_action_check = [
|
39
|
-
|
40
|
-
|
40
|
+
9, 0, 0, 6, 0, 0, 2, 9, 20, 2,
|
41
|
+
2, 20, 20, 10, 5, 5, 10, 10, 15, 15,
|
42
|
+
3, 16, 17, 1, 21, 25, 27, 28 ]
|
41
43
|
|
42
44
|
racc_action_pointer = [
|
43
|
-
-1,
|
44
|
-
|
45
|
-
|
46
|
-
nil, nil ]
|
45
|
+
-1, 23, 4, 13, nil, 10, 0, nil, nil, 0,
|
46
|
+
11, nil, nil, nil, nil, 10, 21, 15, nil, nil,
|
47
|
+
6, 19, nil, nil, nil, 17, nil, 23, 24, nil,
|
48
|
+
nil, nil, nil, nil, nil ]
|
47
49
|
|
48
50
|
racc_action_default = [
|
49
|
-
-
|
50
|
-
-
|
51
|
-
-
|
52
|
-
-
|
51
|
+
-27, -27, -27, -4, -5, -9, -10, -12, -13, -14,
|
52
|
+
-17, -18, -20, -21, -22, -24, -27, -2, -19, -3,
|
53
|
+
-27, -7, -8, -23, -11, -27, -16, -27, -27, 35,
|
54
|
+
-1, -15, -6, -25, -26 ]
|
53
55
|
|
54
56
|
racc_goto_table = [
|
55
|
-
22,
|
56
|
-
2,
|
57
|
+
22, 19, 26, 7, 3, 21, 17, 5, 1, 24,
|
58
|
+
6, 2, 31, 8, 9, 30, 32 ]
|
57
59
|
|
58
60
|
racc_goto_check = [
|
59
|
-
|
60
|
-
|
61
|
+
8, 4, 5, 10, 3, 7, 3, 6, 1, 10,
|
62
|
+
9, 2, 5, 11, 12, 4, 8 ]
|
61
63
|
|
62
64
|
racc_goto_pointer = [
|
63
|
-
nil, 8,
|
64
|
-
|
65
|
+
nil, 8, 11, 4, -2, -8, 7, 0, -5, 10,
|
66
|
+
3, 13, 14, nil ]
|
65
67
|
|
66
68
|
racc_goto_default = [
|
67
|
-
nil, nil, nil, nil, nil, 4, nil, nil,
|
68
|
-
nil, nil,
|
69
|
+
nil, nil, nil, nil, nil, 4, nil, nil, 12, nil,
|
70
|
+
nil, nil, 18, 10 ]
|
69
71
|
|
70
72
|
racc_reduce_table = [
|
71
73
|
0, 0, :racc_error,
|
72
|
-
3, 10, :_reduce_none,
|
73
|
-
2, 10, :_reduce_none,
|
74
|
-
2, 10, :_reduce_none,
|
75
|
-
1, 10, :_reduce_none,
|
76
|
-
1, 12, :_reduce_5,
|
77
74
|
3, 11, :_reduce_none,
|
78
75
|
2, 11, :_reduce_none,
|
79
76
|
2, 11, :_reduce_none,
|
80
77
|
1, 11, :_reduce_none,
|
81
|
-
1,
|
82
|
-
|
83
|
-
|
84
|
-
2,
|
85
|
-
|
78
|
+
1, 13, :_reduce_5,
|
79
|
+
3, 12, :_reduce_none,
|
80
|
+
2, 12, :_reduce_none,
|
81
|
+
2, 12, :_reduce_none,
|
82
|
+
1, 12, :_reduce_none,
|
83
|
+
1, 16, :_reduce_10,
|
84
|
+
2, 16, :_reduce_11,
|
85
|
+
1, 16, :_reduce_12,
|
86
|
+
1, 16, :_reduce_13,
|
87
|
+
1, 16, :_reduce_14,
|
86
88
|
2, 14, :_reduce_15,
|
87
|
-
|
88
|
-
1,
|
89
|
-
1,
|
90
|
-
1,
|
91
|
-
1,
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
89
|
+
2, 15, :_reduce_16,
|
90
|
+
1, 15, :_reduce_none,
|
91
|
+
1, 23, :_reduce_none,
|
92
|
+
1, 23, :_reduce_none,
|
93
|
+
1, 23, :_reduce_none,
|
94
|
+
1, 22, :_reduce_none,
|
95
|
+
1, 18, :_reduce_none,
|
96
|
+
1, 17, :_reduce_23,
|
97
|
+
1, 19, :_reduce_24,
|
98
|
+
3, 20, :_reduce_25,
|
99
|
+
3, 21, :_reduce_26 ]
|
100
|
+
|
101
|
+
racc_reduce_n = 27
|
102
|
+
|
103
|
+
racc_shift_n = 35
|
98
104
|
|
99
105
|
racc_token_table = {
|
100
106
|
false => 0,
|
@@ -103,11 +109,12 @@ racc_token_table = {
|
|
103
109
|
:NUMBER => 3,
|
104
110
|
:UNIT => 4,
|
105
111
|
:OF => 5,
|
106
|
-
|
107
|
-
"
|
108
|
-
"
|
112
|
+
:A => 6,
|
113
|
+
"," => 7,
|
114
|
+
"/" => 8,
|
115
|
+
"." => 9 }
|
109
116
|
|
110
|
-
racc_nt_base =
|
117
|
+
racc_nt_base = 10
|
111
118
|
|
112
119
|
racc_use_result_var = true
|
113
120
|
|
@@ -134,6 +141,7 @@ Racc_token_to_s_table = [
|
|
134
141
|
"NUMBER",
|
135
142
|
"UNIT",
|
136
143
|
"OF",
|
144
|
+
"A",
|
137
145
|
"\",\"",
|
138
146
|
"\"/\"",
|
139
147
|
"\".\"",
|
@@ -149,6 +157,7 @@ Racc_token_to_s_table = [
|
|
149
157
|
"number",
|
150
158
|
"fraction",
|
151
159
|
"decimal",
|
160
|
+
"a",
|
152
161
|
"word" ]
|
153
162
|
|
154
163
|
Racc_debug_parser = false
|
@@ -194,42 +203,53 @@ def _reduce_12(val, _values, result)
|
|
194
203
|
end
|
195
204
|
|
196
205
|
def _reduce_13(val, _values, result)
|
197
|
-
@ingredient.
|
206
|
+
@ingredient.quantity = result
|
198
207
|
result
|
199
208
|
end
|
200
209
|
|
201
210
|
def _reduce_14(val, _values, result)
|
202
|
-
|
211
|
+
@ingredient.quantity = 1
|
203
212
|
result
|
204
213
|
end
|
205
214
|
|
206
215
|
def _reduce_15(val, _values, result)
|
207
|
-
|
216
|
+
@ingredient.style = val[1]
|
208
217
|
result
|
209
218
|
end
|
210
219
|
|
211
|
-
|
220
|
+
def _reduce_16(val, _values, result)
|
221
|
+
result = val.join(' ')
|
222
|
+
result
|
223
|
+
end
|
212
224
|
|
213
225
|
# reduce 17 omitted
|
214
226
|
|
215
227
|
# reduce 18 omitted
|
216
228
|
|
217
|
-
|
229
|
+
# reduce 19 omitted
|
230
|
+
|
231
|
+
# reduce 20 omitted
|
232
|
+
|
233
|
+
# reduce 21 omitted
|
234
|
+
|
235
|
+
# reduce 22 omitted
|
236
|
+
|
237
|
+
def _reduce_23(val, _values, result)
|
218
238
|
@ingredient.unit = to_unit(result)
|
219
239
|
result
|
220
240
|
end
|
221
241
|
|
222
|
-
def
|
242
|
+
def _reduce_24(val, _values, result)
|
223
243
|
result = val[0].to_i
|
224
244
|
result
|
225
245
|
end
|
226
246
|
|
227
|
-
def
|
247
|
+
def _reduce_25(val, _values, result)
|
228
248
|
result = val[0].to_f / val[2].to_f
|
229
249
|
result
|
230
250
|
end
|
231
251
|
|
232
|
-
def
|
252
|
+
def _reduce_26(val, _values, result)
|
233
253
|
result = val.join.to_f
|
234
254
|
result
|
235
255
|
end
|
data/lib/eye_of_newt/parser.y
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class EyeOfNewt::Parser
|
2
|
-
token WORD NUMBER UNIT OF
|
2
|
+
token WORD NUMBER UNIT OF A
|
3
3
|
rule
|
4
4
|
ingredient
|
5
5
|
: quantity ingredient_name style
|
@@ -19,16 +19,18 @@ rule
|
|
19
19
|
amount
|
20
20
|
: number { @ingredient.quantity = result }
|
21
21
|
| number fraction { @ingredient.quantity = val[0] + val[1] }
|
22
|
+
| fraction { @ingredient.quantity = result }
|
22
23
|
| decimal { @ingredient.quantity = result }
|
24
|
+
| a { @ingredient.quantity = 1 }
|
23
25
|
;
|
24
26
|
style : ',' words { @ingredient.style = val[1] } ;
|
25
27
|
words
|
26
|
-
: word
|
27
|
-
| word words { result = val.join(' ') }
|
28
|
+
: word words { result = val.join(' ') }
|
28
29
|
| word
|
29
30
|
;
|
31
|
+
word : WORD | a | of ;
|
32
|
+
a : A ;
|
30
33
|
of : OF ;
|
31
|
-
word : WORD ;
|
32
34
|
unit : UNIT { @ingredient.unit = to_unit(result) } ;
|
33
35
|
number : NUMBER { result = val[0].to_i } ;
|
34
36
|
fraction : NUMBER '/' NUMBER { result = val[0].to_f / val[2].to_f } ;
|
@@ -9,6 +9,7 @@ module EyeOfNewt
|
|
9
9
|
WORD = /[\w-]+/
|
10
10
|
NUMBER = /\d+/
|
11
11
|
OF = /of/
|
12
|
+
A = /an?/
|
12
13
|
|
13
14
|
def initialize(string, units=Unit.all)
|
14
15
|
@units = units
|
@@ -25,6 +26,8 @@ module EyeOfNewt
|
|
25
26
|
[:NUMBER, text]
|
26
27
|
when text = @ss.scan(/#{OF}\b/)
|
27
28
|
[:OF, text]
|
29
|
+
when text = @ss.scan(/#{A}\b/)
|
30
|
+
[:A, text]
|
28
31
|
when text = @ss.scan(/#{unit_matcher}\b/)
|
29
32
|
[:UNIT, text]
|
30
33
|
when text = @ss.scan(/#{WORD}\b/)
|
data/lib/eye_of_newt/version.rb
CHANGED
data/script/console
ADDED
data/test/examples.txt
CHANGED
@@ -5,11 +5,13 @@ tomatoes | tomatoes | 1 | units
|
|
5
5
|
2 cups flour | flour | 2 | cups
|
6
6
|
1 cup all-purpose flour | all-purpose flour | 1 | cups
|
7
7
|
1 1/2 cups all-purpose flour | all-purpose flour | 1.5 | cups
|
8
|
+
1/2 cups all-purpose flour | all-purpose flour | .5 | cups
|
8
9
|
1.5 cups tomatoes | tomatoes | 1.5 | cups
|
9
10
|
1 tomato, diced | tomato | 1 | units | diced
|
10
11
|
1 onion, finely chopped | onion | 1 | units | finely chopped
|
11
12
|
1 cup of flour | flour | 1 | cups
|
12
13
|
1 teaspoon of cream of tartar | cream of tartar | 1 | teaspoons
|
14
|
+
a pinch of salt | salt | 1 | pinches
|
13
15
|
|
14
16
|
#1 (46 fluid ounce) can tomato juice' => ["1 (46 fluid ounce) can", "tomato juice"],
|
15
17
|
#1 (29 ounce) can tomato sauce' => ["1 (29 ounce) can", "tomato sauce"],
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eye-of-newt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter McCracken
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- lib/eye_of_newt/tokenizer.rb
|
132
132
|
- lib/eye_of_newt/unit.rb
|
133
133
|
- lib/eye_of_newt/version.rb
|
134
|
+
- script/console
|
134
135
|
- test/examples.txt
|
135
136
|
- test/eye_of_newt/tokenizer_test.rb
|
136
137
|
- test/eye_of_newt_test.rb
|