writeexcel 0.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/.gitattributes +1 -0
  2. data/README.rdoc +12 -6
  3. data/VERSION +1 -1
  4. data/charts/chartex.rb +316 -315
  5. data/charts/demo1.rb +1 -0
  6. data/charts/demo2.rb +1 -0
  7. data/charts/demo3.rb +117 -116
  8. data/charts/demo4.rb +119 -118
  9. data/charts/demo5.rb +48 -47
  10. data/examples/a_simple.rb +1 -0
  11. data/examples/autofilter.rb +1 -0
  12. data/examples/bigfile.rb +30 -29
  13. data/examples/chart_area.rb +121 -120
  14. data/examples/chart_bar.rb +120 -119
  15. data/examples/chart_column.rb +120 -119
  16. data/examples/chart_line.rb +120 -119
  17. data/examples/chart_pie.rb +108 -107
  18. data/examples/chart_scatter.rb +121 -120
  19. data/examples/chart_stock.rb +148 -147
  20. data/examples/chess.rb +1 -0
  21. data/examples/colors.rb +1 -0
  22. data/examples/comments1.rb +1 -0
  23. data/examples/comments2.rb +3 -2
  24. data/examples/copyformat.rb +1 -0
  25. data/examples/data_validate.rb +1 -0
  26. data/examples/date_time.rb +1 -0
  27. data/examples/defined_name.rb +1 -0
  28. data/examples/demo.rb +1 -0
  29. data/examples/diag_border.rb +1 -0
  30. data/examples/formats.rb +1 -0
  31. data/examples/formula_result.rb +1 -0
  32. data/examples/header.rb +1 -0
  33. data/examples/hide_sheet.rb +1 -0
  34. data/examples/hyperlink.rb +1 -0
  35. data/examples/images.rb +1 -0
  36. data/examples/indent.rb +1 -0
  37. data/examples/merge1.rb +1 -0
  38. data/examples/merge2.rb +1 -0
  39. data/examples/merge3.rb +1 -0
  40. data/examples/merge4.rb +1 -0
  41. data/examples/merge5.rb +1 -0
  42. data/examples/merge6.rb +67 -66
  43. data/examples/outline.rb +1 -0
  44. data/examples/outline_collapsed.rb +1 -0
  45. data/examples/panes.rb +1 -0
  46. data/examples/properties.rb +1 -0
  47. data/examples/properties_jp.rb +1 -0
  48. data/examples/protection.rb +1 -0
  49. data/examples/regions.rb +1 -0
  50. data/examples/repeat.rb +1 -0
  51. data/examples/right_to_left.rb +1 -0
  52. data/examples/row_wrap.rb +1 -0
  53. data/examples/stats.rb +1 -0
  54. data/examples/stocks.rb +1 -0
  55. data/examples/tab_colors.rb +1 -0
  56. data/examples/write_arrays.rb +1 -0
  57. data/lib/writeexcel.rb +6 -1
  58. data/lib/writeexcel/biffwriter.rb +21 -20
  59. data/lib/writeexcel/chart.rb +25 -12
  60. data/lib/writeexcel/charts/area.rb +153 -152
  61. data/lib/writeexcel/charts/bar.rb +178 -177
  62. data/lib/writeexcel/charts/column.rb +157 -156
  63. data/lib/writeexcel/charts/external.rb +62 -61
  64. data/lib/writeexcel/charts/line.rb +153 -152
  65. data/lib/writeexcel/charts/pie.rb +170 -169
  66. data/lib/writeexcel/charts/scatter.rb +4 -3
  67. data/lib/writeexcel/charts/stock.rb +212 -211
  68. data/lib/writeexcel/compatibility.rb +320 -0
  69. data/lib/writeexcel/excelformulaparser.rb +587 -586
  70. data/lib/writeexcel/format.rb +12 -13
  71. data/lib/writeexcel/formula.rb +30 -28
  72. data/lib/writeexcel/helper.rb +23 -0
  73. data/lib/writeexcel/olewriter.rb +5 -16
  74. data/lib/writeexcel/properties.rb +43 -54
  75. data/lib/writeexcel/storage_lite.rb +981 -968
  76. data/lib/writeexcel/workbook.rb +94 -73
  77. data/lib/writeexcel/worksheet.rb +230 -210
  78. data/test/helper.rb +19 -0
  79. data/test/test_00_IEEE_double.rb +1 -0
  80. data/test/test_01_add_worksheet.rb +1 -0
  81. data/test/test_02_merge_formats.rb +3 -5
  82. data/test/test_04_dimensions.rb +3 -5
  83. data/test/test_05_rows.rb +6 -6
  84. data/test/test_06_extsst.rb +8 -8
  85. data/test/test_11_date_time.rb +3 -5
  86. data/test/test_12_date_only.rb +3 -5
  87. data/test/test_13_date_seconds.rb +4 -6
  88. data/test/test_21_escher.rb +3 -5
  89. data/test/test_22_mso_drawing_group.rb +20 -22
  90. data/test/test_23_note.rb +5 -7
  91. data/test/test_24_txo.rb +3 -5
  92. data/test/test_25_position_object.rb +84 -79
  93. data/test/test_26_autofilter.rb +3 -13
  94. data/test/test_27_autofilter.rb +3 -13
  95. data/test/test_28_autofilter.rb +3 -13
  96. data/test/test_29_process_jpg.rb +5 -0
  97. data/test/test_30_validation_dval.rb +3 -5
  98. data/test/test_31_validation_dv_strings.rb +3 -5
  99. data/test/test_32_validation_dv_formula.rb +3 -5
  100. data/test/test_40_property_types.rb +10 -9
  101. data/test/test_41_properties.rb +1 -0
  102. data/test/test_42_set_properties.rb +14 -15
  103. data/test/test_50_name_stored.rb +299 -302
  104. data/test/test_51_name_print_area.rb +357 -360
  105. data/test/test_52_name_print_titles.rb +454 -457
  106. data/test/test_53_autofilter.rb +203 -206
  107. data/test/test_60_chart_generic.rb +5 -0
  108. data/test/test_61_chart_subclasses.rb +95 -94
  109. data/test/test_62_chart_formats.rb +272 -267
  110. data/test/test_63_chart_area_formats.rb +649 -644
  111. data/test/test_biff.rb +12 -38
  112. data/test/test_compatibility.rb +627 -0
  113. data/test/test_example_match.rb +3 -18
  114. data/test/test_format.rb +46 -105
  115. data/test/test_formula.rb +1 -0
  116. data/test/test_ole.rb +3 -4
  117. data/test/test_storage_lite.rb +125 -146
  118. data/test/test_workbook.rb +2 -23
  119. data/test/test_worksheet.rb +4 -5
  120. data/utils/add_magic_comment.rb +80 -0
  121. data/writeexcel.gemspec +8 -2
  122. metadata +10 -4
@@ -0,0 +1,320 @@
1
+ # coding: utf-8
2
+ #
3
+ # Why would we ever use Ruby 1.8.7 when we can backport with something
4
+ # as simple as this?
5
+ #
6
+ # copied from prawn.
7
+ # modified by Hideo NAKAMURA
8
+ #
9
+ unless defined?(Encoding)
10
+ class Encoding # :nodoc:
11
+ class ConverterNotFoundError < StandardError; end
12
+ class UndefinedConversionError < StandardError; end
13
+
14
+ ASCII = 0
15
+ BINARY = 1
16
+ UTF_8 = 2
17
+ EUCJP = 3
18
+ SJIS = 4
19
+ UTF_16LE = 5
20
+ UTF_16BE = 6
21
+ end
22
+ end
23
+
24
+ class String #:nodoc:
25
+ def first_line
26
+ self.each_line { |line| return line }
27
+ end
28
+ unless "".respond_to?(:lines)
29
+ alias_method :lines, :to_a
30
+ end
31
+ unless "".respond_to?(:each_char)
32
+ def each_char #:nodoc:
33
+ # copied from jcode
34
+ if block_given?
35
+ scan(/./m) { |x| yield x }
36
+ else
37
+ scan(/./m)
38
+ end
39
+ end
40
+ end
41
+
42
+ unless "".respond_to?(:encode)
43
+ @encoding = Encoding::UTF_8
44
+
45
+ def encode(encoding) # :nodoc:
46
+ require 'nkf'
47
+ @encoding ||= Encoding::UTF_8
48
+ if @encoding == Encoding::UTF_8
49
+ # supported only $KCODE = 'u'. so @encoding.nil? means UTF_8.
50
+ case encoding
51
+ when /ASCII/i
52
+ if self.mbchar?('UTF8')
53
+ raise Encoding::UndefinedConversionError
54
+ else
55
+ str = String.new(self)
56
+ str.force_encoding(encoding)
57
+ str
58
+ end
59
+ when /BINARY/i
60
+ if self.mbchar?('UTF8')
61
+ raise Encoding::UndefinedConversionError
62
+ else
63
+ str = String.new(self)
64
+ str.force_encoding(encoding)
65
+ str
66
+ end
67
+ when /UTF_8/i
68
+ raise Encoding::ConverterNotFoundError
69
+ when /EUCJP/i, /SJIS/i
70
+ enc = encoding =~ /EUCJP/i ? 'e' : 's'
71
+ str = NKF.nkf("-#{enc} -m0 -W", self)
72
+ str.force_encoding(encoding)
73
+ str
74
+ when /UTF_16LE/i, /UTF_16BE/i
75
+ raise Encoding::ConverterNotFoundError
76
+ else
77
+ raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
78
+ end
79
+ elsif @encoding == Encoding::ASCII
80
+ case encoding
81
+ when /ASCII/i, /BINARY/i, /EUCJP/i, /SJIS/i
82
+ str = String.new(self)
83
+ str.force_encoding(encoding)
84
+ str
85
+ when /UTF_8/i, /UTF_16LE/i, /UTF_16BE/i
86
+ raise Encoding::ConverterNotFoundError
87
+ else
88
+ raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
89
+ end
90
+ elsif @encoding == Encoding::BINARY
91
+ case encoding
92
+ when /ASCII/i
93
+ if self.ascii_only? || self.mbchar?('UTF8') || self.mbchar?('EUCJP') || self.mbchar?('SJIS')
94
+ raise Encoding::UndefinedConversionError
95
+ else
96
+ str = String.new(self)
97
+ str.force_encoding(encoding)
98
+ str
99
+ end
100
+ when /BINARY/i
101
+ self
102
+ when /EUCJP/i, /SJIS/i
103
+ if self.ascii_only? || self.mbchar?('UTF8') || self.mbchar?('EUCJP') || self.mbchar?('SJIS')
104
+ raise Encoding::UndefinedConversionError
105
+ else
106
+ str = String.new(self)
107
+ str.force_encoding(encoding)
108
+ str
109
+ end
110
+ when /UTF_8/i, /UTF_16LE/i, /UTF_16BE/i
111
+ raise Encoding::ConverterNotFoundError
112
+ else
113
+ raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
114
+ end
115
+ elsif @encoding == Encoding::EUCJP || @encoding == Encoding::SJIS
116
+ type = @encoding == Encoding::EUCJP ? 'EUCJP' : 'SJIS'
117
+ inenc = @encoding == Encoding::EUCJP ? 'e' : 's'
118
+ case encoding
119
+ when /ASCII/i
120
+ if self.mbchar?(type)
121
+ raise Encoding::UndefinedConversionError
122
+ else
123
+ str = String.new(self)
124
+ str.force_encoding(encoding)
125
+ str
126
+ end
127
+ when /BINARY/i
128
+ if self.mbchar?(type)
129
+ raise Encoding::UndefinedConversionError
130
+ else
131
+ str = String.new(self)
132
+ str.force_encoding(encoding)
133
+ str
134
+ end
135
+ when /UTF_8/i
136
+ raise Encoding::ConverterNotFoundError
137
+ when /EUCJP/i, /SJIS/i
138
+ outenc = encoding =~ /EUCJP/i ? 'E' : 'S'
139
+ str = NKF.nkf("-#{inenc} -#{outenc}", self)
140
+ str.force_encoding(encoding)
141
+ str
142
+ when /UTF_16LE/i, /UTF_16BE/i
143
+ raise Encoding::ConverterNotFoundError
144
+ else
145
+ raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
146
+ end
147
+ elsif @encoding == Encoding::UTF_16LE || @encoding == Encoding::UTF_16BE
148
+ enc = @encoding == Encoding::UTF_16LE ? 'L' : 'B'
149
+ utf8 = NKF.nkf("-w -m0 -W16#{enc}", self)
150
+ case encoding
151
+ when /ASCII/i
152
+ if utf8.mbchar?
153
+ raise Encoding::UndefinedConversionError
154
+ else
155
+ str = String.new(self)
156
+ str.force_encoding(encoding)
157
+ str
158
+ end
159
+ when /BINARY/i
160
+ if utf8.mbchar?
161
+ raise Encoding::UndefinedConversionError
162
+ else
163
+ str = String.new(self)
164
+ str.force_encoding(encoding)
165
+ str
166
+ end
167
+ when /UTF_8/i
168
+ raise Encoding::ConverterNotFoundError
169
+ when /EUCJP/i, /SJIS/i
170
+ str = String.new(self)
171
+ str.force_encoding(encoding)
172
+ str
173
+ when /UTF_16LE/i, /UTF_16BE/i
174
+ raise Encoding::ConverterNotFoundError
175
+ else
176
+ raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
177
+ end
178
+ else
179
+ end
180
+ end
181
+
182
+ def self_with_encoding(encoding)
183
+ if encoding =~ /ASCII/i
184
+ @encoding = Encoding::ASCII
185
+ elsif encoding =~ /BINARY/i
186
+ @encoding = Encoding::BINARY
187
+ elsif encoding =~ /UTF_8/i
188
+ @encoding = Encoding::UTF_8
189
+ elsif encoding =~ /EUCJP/i
190
+ @encoding = Encoding::EUCJP
191
+ elsif encoding =~ /SJIS/i
192
+ @encoding = Encoding::SJIS
193
+ elsif encoding =~ /UTF_16LE/i
194
+ @encoding = Encoding::UTF_16LE
195
+ elsif encoding =~ /UTF_16BE/i
196
+ @encoding = Encoding::UTF_16BE
197
+ else
198
+ raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
199
+ end
200
+ self
201
+ end
202
+ private :self_with_encoding
203
+ end
204
+
205
+ unless "".respond_to?(:encoding)
206
+ def encoding
207
+ @encoding ||= Encoding::UTF_8
208
+ end
209
+ end
210
+
211
+ unless "".respond_to?(:bytesize)
212
+ def bytesize # :nodoc:
213
+ self.length
214
+ end
215
+ end
216
+
217
+ unless "".respond_to?(:ord)
218
+ def ord
219
+ self[0]
220
+ end
221
+ end
222
+
223
+ unless "".respond_to?(:force_encoding)
224
+ def force_encoding(encoding)
225
+ if encoding.kind_of?(String)
226
+ @encoding = case encoding
227
+ when /ASCII/i
228
+ Encoding::ASCII
229
+ when /BINARY/i
230
+ Encoding::BINARY
231
+ when /UTF[-_]8/i
232
+ Encoding::UTF_8
233
+ when /EUCJP/i
234
+ Encoding::EUCJP
235
+ when /SJIS/i
236
+ Encoding::SJIS
237
+ when /UTF[-_]16LE/i
238
+ Encoding::UTF_16LE
239
+ when /UTF[-_]16BE/i
240
+ Encoding::UTF_16BE
241
+ end
242
+ else
243
+ @encoding = case encoding
244
+ when Encoding::ASCII
245
+ Encoding::ASCII
246
+ when Encoding::BINARY
247
+ Encoding::BINARY
248
+ when Encoding::UTF_8
249
+ Encoding::UTF_8
250
+ when Encoding::EUCJP
251
+ Encoding::EUCJP
252
+ when Encoding::SJIS
253
+ Encoding::SJIS
254
+ when Encoding::UTF_16LE
255
+ Encoding::UTF_16LE
256
+ when Encoding::UTF_16BE
257
+ Encoding::UTF_16BE
258
+ end
259
+ end
260
+ self
261
+ end
262
+ end
263
+
264
+ unless "".respond_to?(:ascii_only?)
265
+ def ascii_only?
266
+ !!(self =~ /[^!"#\$%&'\(\)\*\+,\-\.\/\:\;<=>\?@0-9A-Za-z_\[\\\]\{\}^` ~\0\n]/)
267
+ end
268
+ end
269
+
270
+ if RUBY_VERSION < "1.9"
271
+ unless "".respond_to?(:mbchar?)
272
+ PATTERN_SJIS = '[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]' # :nodoc:
273
+ PATTERN_EUC = '[\xa1-\xfe][\xa1-\xfe]' # :nodoc:
274
+ PATTERN_UTF8 = '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]' # :nodoc:
275
+
276
+ RE_SJIS = Regexp.new(PATTERN_SJIS, 0, 'n') # :nodoc:
277
+ RE_EUC = Regexp.new(PATTERN_EUC, 0, 'n') # :nodoc:
278
+ RE_UTF8 = Regexp.new(PATTERN_UTF8, 0, 'n') # :nodoc:
279
+
280
+ def mbchar?(type = nil)# :nodoc: idea copied from jcode.rb
281
+ if (!type.nil? && type =~ /SJIS/i) || $KCODE == 'SJIS'
282
+ self =~ RE_SJIS
283
+ elsif (!type.nil? && type =~ /EUCJP/i) || $KCODE == 'EUC'
284
+ self =~ RE_EUC
285
+ elsif (!type.nil? && type =~ /UTF_8/i) || $KCODE == 'UTF8'
286
+ self =~ RE_UTF8
287
+ else
288
+ nil
289
+ end
290
+ end
291
+ end
292
+ end
293
+ end
294
+
295
+ unless File.respond_to?(:binread)
296
+ def File.binread(file) #:nodoc:
297
+ File.open(file,"rb") { |f| f.read }
298
+ end
299
+ end
300
+
301
+ if RUBY_VERSION < "1.9"
302
+
303
+ def ruby_18 #:nodoc:
304
+ yield
305
+ end
306
+
307
+ def ruby_19 #:nodoc:
308
+ false
309
+ end
310
+
311
+ else
312
+
313
+ def ruby_18 #:nodoc:
314
+ false
315
+ end
316
+
317
+ def ruby_19 #:nodoc:
318
+ yield
319
+ end
320
+ end
@@ -1,586 +1,587 @@
1
- #
2
- # DO NOT MODIFY!!!!
3
- # This file is automatically generated by Racc 1.4.6
4
- # from Racc grammer file "".
5
- #
6
-
7
- require 'racc/parser.rb'
8
- class ExcelFormulaParser < Racc::Parser # :nodoc:
9
- ##### State transition tables begin ###
10
-
11
- racc_action_table = [
12
- 16, 54, 26, 28, 30, 32, 34, 21, 20, 3,
13
- nil, nil, 53, 19, 23, 4, 5, 6, 7, 10,
14
- 13, 14, 15, 17, 18, 16, nil, 26, 28, 30,
15
- 32, 34, 8, nil, nil, nil, nil, 16, 19, nil,
16
- 4, 5, 6, 7, 10, 13, 14, 15, 17, 18,
17
- 19, 16, 4, 5, 6, 7, 10, 13, 14, 15,
18
- 17, 18, nil, 16, 19, nil, 4, 5, 6, 7,
19
- 10, 13, 14, 15, 17, 18, 19, 16, 4, 5,
20
- 6, 7, 10, 13, 14, 15, 17, 18, nil, 16,
21
- 19, nil, 4, 5, 6, 7, 10, 13, 14, 15,
22
- 17, 18, 19, 16, 4, 5, 6, 7, 10, 13,
23
- 14, 15, 17, 18, nil, 16, 19, 37, 4, 5,
24
- 6, 7, 10, 13, 14, 15, 17, 18, 19, 16,
25
- 4, 5, 6, 7, 10, 13, 14, 15, 17, 18,
26
- nil, 16, 19, nil, 4, 5, 6, 7, 10, 13,
27
- 14, 15, 17, 18, 19, 16, 4, 5, 6, 7,
28
- 10, 13, 14, 15, 17, 18, nil, 16, 19, nil,
29
- 4, 5, 6, 7, 10, 13, 14, 15, 17, 18,
30
- 19, 16, 4, 5, 6, 7, 10, 13, 14, 15,
31
- 17, 18, nil, 16, 19, nil, 4, 5, 6, 7,
32
- 10, 13, 14, 15, 17, 18, 19, 16, 4, 5,
33
- 6, 7, 10, 13, 14, 15, 17, 18, nil, 16,
34
- 19, nil, 4, 5, 6, 7, 10, 13, 14, 15,
35
- 17, 18, 19, nil, 4, 5, 6, 7, 10, 13,
36
- 14, 15, 17, 18, 23, 24, 27, 29, 31, 33,
37
- nil, nil, nil, nil, nil, 22, nil, 26, 28, 30,
38
- 32, 34, nil, 52, 23, 24, 27, 29, 31, 33,
39
- 23, 24, 27, 29, nil, nil, nil, 26, 28, 30,
40
- 32, 34, nil, 26, 28, 30, 32, 34, 23, 24,
41
- 27, 29, nil, nil, nil, 23, 24, 27, 29, 31,
42
- 33, 26, 28, 30, 32, 34, 22, 25, 26, 28,
43
- 30, 32, 34, 23, 24, 27, 29, 31, 33, nil,
44
- nil, nil, nil, nil, 22, nil, 26, 28, 30, 32,
45
- 34, 23, 24, 27, 29, 31, 33, nil, nil, nil,
46
- nil, nil, 22, nil, 26, 28, 30, 32, 34, 23,
47
- 24, 27, 29, 31, 33, 23, nil, nil, nil, nil,
48
- 22, nil, 26, 28, 30, 32, 34, nil, 26, 28,
49
- 30, 32, 34, 23, 24, 27, 29, 31, 33, 23,
50
- 24, nil, nil, nil, 22, nil, 26, 28, 30, 32,
51
- 34, nil, 26, 28, 30, 32, 34, 23, 24, 27,
52
- 29, 31, 33, 23, 24, nil, nil, nil, 22, nil,
53
- 26, 28, 30, 32, 34, nil, 26, 28, 30, 32,
54
- 34, 23, 24, 27, 29, 31, 33, nil, nil, nil,
55
- nil, nil, 22, nil, 26, 28, 30, 32, 34, 23,
56
- 24, 27, 29, 31, 33, nil, nil, nil, nil, nil,
57
- 22, nil, 26, 28, 30, 32, 34 ]
58
-
59
- racc_action_check = [
60
- 34, 39, 35, 35, 35, 35, 35, 4, 3, 1,
61
- nil, nil, 39, 34, 41, 34, 34, 34, 34, 34,
62
- 34, 34, 34, 34, 34, 2, nil, 41, 41, 41,
63
- 41, 41, 2, nil, nil, nil, nil, 53, 2, nil,
64
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
65
- 53, 33, 53, 53, 53, 53, 53, 53, 53, 53,
66
- 53, 53, nil, 32, 33, nil, 33, 33, 33, 33,
67
- 33, 33, 33, 33, 33, 33, 32, 16, 32, 32,
68
- 32, 32, 32, 32, 32, 32, 32, 32, nil, 19,
69
- 16, nil, 16, 16, 16, 16, 16, 16, 16, 16,
70
- 16, 16, 19, 21, 19, 19, 19, 19, 19, 19,
71
- 19, 19, 19, 19, nil, 22, 21, 21, 21, 21,
72
- 21, 21, 21, 21, 21, 21, 21, 21, 22, 23,
73
- 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
74
- nil, 24, 23, nil, 23, 23, 23, 23, 23, 23,
75
- 23, 23, 23, 23, 24, 26, 24, 24, 24, 24,
76
- 24, 24, 24, 24, 24, 24, nil, 27, 26, nil,
77
- 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
78
- 27, 28, 27, 27, 27, 27, 27, 27, 27, 27,
79
- 27, 27, nil, 29, 28, nil, 28, 28, 28, 28,
80
- 28, 28, 28, 28, 28, 28, 29, 30, 29, 29,
81
- 29, 29, 29, 29, 29, 29, 29, 29, nil, 31,
82
- 30, nil, 30, 30, 30, 30, 30, 30, 30, 30,
83
- 30, 30, 31, nil, 31, 31, 31, 31, 31, 31,
84
- 31, 31, 31, 31, 36, 36, 36, 36, 36, 36,
85
- nil, nil, nil, nil, nil, 36, nil, 36, 36, 36,
86
- 36, 36, nil, 36, 40, 40, 40, 40, 40, 40,
87
- 48, 48, 48, 48, nil, nil, nil, 40, 40, 40,
88
- 40, 40, nil, 48, 48, 48, 48, 48, 50, 50,
89
- 50, 50, nil, nil, nil, 9, 9, 9, 9, 9,
90
- 9, 50, 50, 50, 50, 50, 9, 9, 9, 9,
91
- 9, 9, 9, 38, 38, 38, 38, 38, 38, nil,
92
- nil, nil, nil, nil, 38, nil, 38, 38, 38, 38,
93
- 38, 49, 49, 49, 49, 49, 49, nil, nil, nil,
94
- nil, nil, 49, nil, 49, 49, 49, 49, 49, 51,
95
- 51, 51, 51, 51, 51, 42, nil, nil, nil, nil,
96
- 51, nil, 51, 51, 51, 51, 51, nil, 42, 42,
97
- 42, 42, 42, 43, 43, 43, 43, 43, 43, 44,
98
- 44, nil, nil, nil, 43, nil, 43, 43, 43, 43,
99
- 43, nil, 44, 44, 44, 44, 44, 45, 45, 45,
100
- 45, 45, 45, 46, 46, nil, nil, nil, 45, nil,
101
- 45, 45, 45, 45, 45, nil, 46, 46, 46, 46,
102
- 46, 47, 47, 47, 47, 47, 47, nil, nil, nil,
103
- nil, nil, 47, nil, 47, 47, 47, 47, 47, 55,
104
- 55, 55, 55, 55, 55, nil, nil, nil, nil, nil,
105
- 55, nil, 55, 55, 55, 55, 55 ]
106
-
107
- racc_action_pointer = [
108
- nil, 9, 17, 8, -14, nil, nil, nil, nil, 292,
109
- nil, nil, nil, nil, nil, nil, 69, nil, nil, 81,
110
- nil, 95, 107, 121, 133, nil, 147, 159, 173, 185,
111
- 199, 211, 55, 43, -8, -14, 241, nil, 310, -21,
112
- 261, 11, 352, 370, 376, 394, 400, 418, 267, 328,
113
- 285, 346, nil, 29, nil, 436 ]
114
-
115
- racc_action_default = [
116
- -2, -35, -1, -35, -20, -21, -22, -23, -4, -35,
117
- -24, -17, -30, -25, -26, -27, -35, -28, -29, -35,
118
- 56, -35, -35, -35, -35, -3, -35, -35, -35, -35,
119
- -35, -35, -35, -35, -35, -19, -35, -32, -33, -35,
120
- -16, -9, -10, -11, -7, -12, -8, -13, -5, -14,
121
- -6, -15, -18, -35, -31, -34 ]
122
-
123
- racc_goto_table = [
124
- 9, 1, 2, 39, nil, nil, nil, nil, nil, nil,
125
- nil, nil, nil, nil, 35, nil, nil, 36, nil, 38,
126
- 40, 41, 42, nil, 43, 44, 45, 46, 47, 48,
127
- 49, 50, 51, nil, nil, nil, nil, nil, nil, nil,
128
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
129
- nil, 55 ]
130
-
131
- racc_goto_check = [
132
- 3, 1, 2, 6, nil, nil, nil, nil, nil, nil,
133
- nil, nil, nil, nil, 3, nil, nil, 3, nil, 3,
134
- 3, 3, 3, nil, 3, 3, 3, 3, 3, 3,
135
- 3, 3, 3, nil, nil, nil, nil, nil, nil, nil,
136
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
137
- nil, 3 ]
138
-
139
- racc_goto_pointer = [
140
- nil, 1, 2, -2, nil, nil, -18 ]
141
-
142
- racc_goto_default = [
143
- nil, nil, nil, nil, 11, 12, nil ]
144
-
145
- racc_reduce_table = [
146
- 0, 0, :racc_error,
147
- 1, 35, :_reduce_none,
148
- 0, 36, :_reduce_2,
149
- 3, 36, :_reduce_3,
150
- 2, 36, :_reduce_none,
151
- 3, 37, :_reduce_5,
152
- 3, 37, :_reduce_6,
153
- 3, 37, :_reduce_7,
154
- 3, 37, :_reduce_8,
155
- 3, 37, :_reduce_9,
156
- 3, 37, :_reduce_10,
157
- 3, 37, :_reduce_11,
158
- 3, 37, :_reduce_12,
159
- 3, 37, :_reduce_13,
160
- 3, 37, :_reduce_14,
161
- 3, 37, :_reduce_15,
162
- 3, 37, :_reduce_16,
163
- 1, 37, :_reduce_none,
164
- 3, 38, :_reduce_18,
165
- 2, 38, :_reduce_19,
166
- 1, 38, :_reduce_none,
167
- 1, 38, :_reduce_21,
168
- 1, 38, :_reduce_22,
169
- 1, 38, :_reduce_23,
170
- 1, 38, :_reduce_24,
171
- 1, 38, :_reduce_25,
172
- 1, 38, :_reduce_26,
173
- 1, 38, :_reduce_27,
174
- 1, 38, :_reduce_28,
175
- 1, 38, :_reduce_29,
176
- 1, 38, :_reduce_none,
177
- 4, 39, :_reduce_31,
178
- 3, 39, :_reduce_32,
179
- 1, 40, :_reduce_33,
180
- 3, 40, :_reduce_34 ]
181
-
182
- racc_reduce_n = 35
183
-
184
- racc_shift_n = 56
185
-
186
- racc_token_table = {
187
- false => 0,
188
- :error => 1,
189
- :UMINUS => 2,
190
- "^" => 3,
191
- "&" => 4,
192
- "*" => 5,
193
- "/" => 6,
194
- "+" => 7,
195
- "-" => 8,
196
- "<" => 9,
197
- ">" => 10,
198
- "<=" => 11,
199
- ">=" => 12,
200
- "<>" => 13,
201
- "=" => 14,
202
- :EOL => 15,
203
- :LT => 16,
204
- :GT => 17,
205
- :LE => 18,
206
- :GE => 19,
207
- :NE => 20,
208
- "(" => 21,
209
- ")" => 22,
210
- :FUNC => 23,
211
- :NUMBER => 24,
212
- :STRING => 25,
213
- :REF2D => 26,
214
- :REF3D => 27,
215
- :RANGE2D => 28,
216
- :RANGE3D => 29,
217
- :NAME => 30,
218
- :TRUE => 31,
219
- :FALSE => 32,
220
- "," => 33 }
221
-
222
- racc_nt_base = 34
223
-
224
- racc_use_result_var = true
225
-
226
- Racc_arg = [
227
- racc_action_table,
228
- racc_action_check,
229
- racc_action_default,
230
- racc_action_pointer,
231
- racc_goto_table,
232
- racc_goto_check,
233
- racc_goto_default,
234
- racc_goto_pointer,
235
- racc_nt_base,
236
- racc_reduce_table,
237
- racc_token_table,
238
- racc_shift_n,
239
- racc_reduce_n,
240
- racc_use_result_var ]
241
-
242
- Racc_token_to_s_table = [
243
- "$end",
244
- "error",
245
- "UMINUS",
246
- "\"^\"",
247
- "\"&\"",
248
- "\"*\"",
249
- "\"/\"",
250
- "\"+\"",
251
- "\"-\"",
252
- "\"<\"",
253
- "\">\"",
254
- "\"<=\"",
255
- "\">=\"",
256
- "\"<>\"",
257
- "\"=\"",
258
- "EOL",
259
- "LT",
260
- "GT",
261
- "LE",
262
- "GE",
263
- "NE",
264
- "\"(\"",
265
- "\")\"",
266
- "FUNC",
267
- "NUMBER",
268
- "STRING",
269
- "REF2D",
270
- "REF3D",
271
- "RANGE2D",
272
- "RANGE3D",
273
- "NAME",
274
- "TRUE",
275
- "FALSE",
276
- "\",\"",
277
- "$start",
278
- "formula",
279
- "expr_list",
280
- "expr",
281
- "primary",
282
- "funcall",
283
- "args" ]
284
-
285
- Racc_debug_parser = false
286
-
287
- ##### State transition tables end #####
288
-
289
- # reduce 0 omitted
290
-
291
- # reduce 1 omitted
292
-
293
- module_eval(<<'.,.,', 'excelformula.y', 20)
294
- def _reduce_2(val, _values, result)
295
- result = []
296
- result
297
- end
298
- .,.,
299
-
300
- module_eval(<<'.,.,', 'excelformula.y', 21)
301
- def _reduce_3(val, _values, result)
302
- result.push val[1], '_arg', '1'
303
- result
304
- end
305
- .,.,
306
-
307
- # reduce 4 omitted
308
-
309
- module_eval(<<'.,.,', 'excelformula.y', 24)
310
- def _reduce_5(val, _values, result)
311
- result = [ val[0], val[2], 'ptgAdd' ]
312
- result
313
- end
314
- .,.,
315
-
316
- module_eval(<<'.,.,', 'excelformula.y', 25)
317
- def _reduce_6(val, _values, result)
318
- result = [ val[0], val[2], 'ptgSub' ]
319
- result
320
- end
321
- .,.,
322
-
323
- module_eval(<<'.,.,', 'excelformula.y', 26)
324
- def _reduce_7(val, _values, result)
325
- result = [ val[0], val[2], 'ptgMul' ]
326
- result
327
- end
328
- .,.,
329
-
330
- module_eval(<<'.,.,', 'excelformula.y', 27)
331
- def _reduce_8(val, _values, result)
332
- result = [ val[0], val[2], 'ptgDiv' ]
333
- result
334
- end
335
- .,.,
336
-
337
- module_eval(<<'.,.,', 'excelformula.y', 28)
338
- def _reduce_9(val, _values, result)
339
- result = [ val[0], val[2], 'ptgPower' ]
340
- result
341
- end
342
- .,.,
343
-
344
- module_eval(<<'.,.,', 'excelformula.y', 29)
345
- def _reduce_10(val, _values, result)
346
- result = [ val[0], val[2], 'ptgConcat' ]
347
- result
348
- end
349
- .,.,
350
-
351
- module_eval(<<'.,.,', 'excelformula.y', 30)
352
- def _reduce_11(val, _values, result)
353
- result = [ val[0], val[2], 'ptgLT' ]
354
- result
355
- end
356
- .,.,
357
-
358
- module_eval(<<'.,.,', 'excelformula.y', 31)
359
- def _reduce_12(val, _values, result)
360
- result = [ val[0], val[2], 'ptgGT' ]
361
- result
362
- end
363
- .,.,
364
-
365
- module_eval(<<'.,.,', 'excelformula.y', 32)
366
- def _reduce_13(val, _values, result)
367
- result = [ val[0], val[2], 'ptgLE' ]
368
- result
369
- end
370
- .,.,
371
-
372
- module_eval(<<'.,.,', 'excelformula.y', 33)
373
- def _reduce_14(val, _values, result)
374
- result = [ val[0], val[2], 'ptgGE' ]
375
- result
376
- end
377
- .,.,
378
-
379
- module_eval(<<'.,.,', 'excelformula.y', 34)
380
- def _reduce_15(val, _values, result)
381
- result = [ val[0], val[2], 'ptgNE' ]
382
- result
383
- end
384
- .,.,
385
-
386
- module_eval(<<'.,.,', 'excelformula.y', 35)
387
- def _reduce_16(val, _values, result)
388
- result = [ val[0], val[2], 'ptgEQ' ]
389
- result
390
- end
391
- .,.,
392
-
393
- # reduce 17 omitted
394
-
395
- module_eval(<<'.,.,', 'excelformula.y', 38)
396
- def _reduce_18(val, _values, result)
397
- result = [ val[1], '_arg', '1', 'ptgParen']
398
- result
399
- end
400
- .,.,
401
-
402
- module_eval(<<'.,.,', 'excelformula.y', 39)
403
- def _reduce_19(val, _values, result)
404
- result = [ '_num', '-1', val[1], 'ptgMul' ]
405
- result
406
- end
407
- .,.,
408
-
409
- # reduce 20 omitted
410
-
411
- module_eval(<<'.,.,', 'excelformula.y', 41)
412
- def _reduce_21(val, _values, result)
413
- result = [ '_num', val[0] ]
414
- result
415
- end
416
- .,.,
417
-
418
- module_eval(<<'.,.,', 'excelformula.y', 42)
419
- def _reduce_22(val, _values, result)
420
- result = [ '_str', val[0] ]
421
- result
422
- end
423
- .,.,
424
-
425
- module_eval(<<'.,.,', 'excelformula.y', 43)
426
- def _reduce_23(val, _values, result)
427
- result = [ '_ref2d', val[0] ]
428
- result
429
- end
430
- .,.,
431
-
432
- module_eval(<<'.,.,', 'excelformula.y', 44)
433
- def _reduce_24(val, _values, result)
434
- result = [ '_ref3d', val[0] ]
435
- result
436
- end
437
- .,.,
438
-
439
- module_eval(<<'.,.,', 'excelformula.y', 45)
440
- def _reduce_25(val, _values, result)
441
- result = [ '_range2d', val[0] ]
442
- result
443
- end
444
- .,.,
445
-
446
- module_eval(<<'.,.,', 'excelformula.y', 46)
447
- def _reduce_26(val, _values, result)
448
- result = [ '_range3d', val[0] ]
449
- result
450
- end
451
- .,.,
452
-
453
- module_eval(<<'.,.,', 'excelformula.y', 47)
454
- def _reduce_27(val, _values, result)
455
- result = [ '_name', val[0] ]
456
- result
457
- end
458
- .,.,
459
-
460
- module_eval(<<'.,.,', 'excelformula.y', 48)
461
- def _reduce_28(val, _values, result)
462
- result = [ 'ptgBool', '1' ]
463
- result
464
- end
465
- .,.,
466
-
467
- module_eval(<<'.,.,', 'excelformula.y', 49)
468
- def _reduce_29(val, _values, result)
469
- result = [ 'ptgBool', '0' ]
470
- result
471
- end
472
- .,.,
473
-
474
- # reduce 30 omitted
475
-
476
- module_eval(<<'.,.,', 'excelformula.y', 52)
477
- def _reduce_31(val, _values, result)
478
- result = [ '_class', val[0], val[2], '_arg', val[2].size.to_s, '_func', val[0] ]
479
- result
480
- end
481
- .,.,
482
-
483
- module_eval(<<'.,.,', 'excelformula.y', 53)
484
- def _reduce_32(val, _values, result)
485
- result = [ '_func', val[0] ]
486
- result
487
- end
488
- .,.,
489
-
490
- module_eval(<<'.,.,', 'excelformula.y', 55)
491
- def _reduce_33(val, _values, result)
492
- result = val
493
- result
494
- end
495
- .,.,
496
-
497
- module_eval(<<'.,.,', 'excelformula.y', 56)
498
- def _reduce_34(val, _values, result)
499
- result.push val[2]
500
- result
501
- end
502
- .,.,
503
-
504
- def _reduce_none(val, _values, result)
505
- val[0]
506
- end
507
-
508
- end # class ExcelFormulaParser
509
-
510
-
511
- class ExcelFormulaParserError < StandardError #:nodoc:
512
- end
513
-
514
- class Node # :nodoc:
515
-
516
- def exec_list(nodes)
517
- v = nil
518
- nodes.each { |i| v = i.evaluate }
519
- v
520
- end
521
-
522
- def excelformulaparser_error(msg)
523
- raise ExcelFormulaParserError,
524
- "in #{fname}:#{lineno}: #{msg}"
525
- end
526
-
527
- end
528
-
529
- class RootNode < Node # :nodoc:
530
-
531
- def initialize(tree)
532
- @tree = tree
533
- end
534
-
535
- def evaluate
536
- exec_list @tree
537
- end
538
-
539
- end
540
-
541
-
542
- class FuncallNode < Node # :nodoc:
543
-
544
- def initialize(func, args)
545
- @func = func
546
- @args = args
547
- end
548
-
549
- def evaluate
550
- arg = @args.collect {|i| i.evaluate }
551
- out = []
552
- arg.each { |i| o.push i }
553
- o.push @func
554
- p o
555
- end
556
-
557
- end
558
-
559
- class NumberNode < Node # :nodoc:
560
-
561
- def initialize(val)
562
- @val = val
563
- end
564
-
565
- def evaluate
566
- p @val
567
- end
568
-
569
- end
570
-
571
- class OperateNode < Node # :nodoc:
572
-
573
- def initialize(op, left, right)
574
- @op = op
575
- @left = left
576
- @right = right
577
- end
578
-
579
- def evaluate
580
- o = []
581
- o.push @left
582
- o.push @right
583
- o.push @op
584
- p o
585
- end
586
- end
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # DO NOT MODIFY!!!!
4
+ # This file is automatically generated by Racc 1.4.6
5
+ # from Racc grammer file "".
6
+ #
7
+
8
+ require 'racc/parser.rb'
9
+ class ExcelFormulaParser < Racc::Parser # :nodoc:
10
+ ##### State transition tables begin ###
11
+
12
+ racc_action_table = [
13
+ 16, 54, 26, 28, 30, 32, 34, 21, 20, 3,
14
+ nil, nil, 53, 19, 23, 4, 5, 6, 7, 10,
15
+ 13, 14, 15, 17, 18, 16, nil, 26, 28, 30,
16
+ 32, 34, 8, nil, nil, nil, nil, 16, 19, nil,
17
+ 4, 5, 6, 7, 10, 13, 14, 15, 17, 18,
18
+ 19, 16, 4, 5, 6, 7, 10, 13, 14, 15,
19
+ 17, 18, nil, 16, 19, nil, 4, 5, 6, 7,
20
+ 10, 13, 14, 15, 17, 18, 19, 16, 4, 5,
21
+ 6, 7, 10, 13, 14, 15, 17, 18, nil, 16,
22
+ 19, nil, 4, 5, 6, 7, 10, 13, 14, 15,
23
+ 17, 18, 19, 16, 4, 5, 6, 7, 10, 13,
24
+ 14, 15, 17, 18, nil, 16, 19, 37, 4, 5,
25
+ 6, 7, 10, 13, 14, 15, 17, 18, 19, 16,
26
+ 4, 5, 6, 7, 10, 13, 14, 15, 17, 18,
27
+ nil, 16, 19, nil, 4, 5, 6, 7, 10, 13,
28
+ 14, 15, 17, 18, 19, 16, 4, 5, 6, 7,
29
+ 10, 13, 14, 15, 17, 18, nil, 16, 19, nil,
30
+ 4, 5, 6, 7, 10, 13, 14, 15, 17, 18,
31
+ 19, 16, 4, 5, 6, 7, 10, 13, 14, 15,
32
+ 17, 18, nil, 16, 19, nil, 4, 5, 6, 7,
33
+ 10, 13, 14, 15, 17, 18, 19, 16, 4, 5,
34
+ 6, 7, 10, 13, 14, 15, 17, 18, nil, 16,
35
+ 19, nil, 4, 5, 6, 7, 10, 13, 14, 15,
36
+ 17, 18, 19, nil, 4, 5, 6, 7, 10, 13,
37
+ 14, 15, 17, 18, 23, 24, 27, 29, 31, 33,
38
+ nil, nil, nil, nil, nil, 22, nil, 26, 28, 30,
39
+ 32, 34, nil, 52, 23, 24, 27, 29, 31, 33,
40
+ 23, 24, 27, 29, nil, nil, nil, 26, 28, 30,
41
+ 32, 34, nil, 26, 28, 30, 32, 34, 23, 24,
42
+ 27, 29, nil, nil, nil, 23, 24, 27, 29, 31,
43
+ 33, 26, 28, 30, 32, 34, 22, 25, 26, 28,
44
+ 30, 32, 34, 23, 24, 27, 29, 31, 33, nil,
45
+ nil, nil, nil, nil, 22, nil, 26, 28, 30, 32,
46
+ 34, 23, 24, 27, 29, 31, 33, nil, nil, nil,
47
+ nil, nil, 22, nil, 26, 28, 30, 32, 34, 23,
48
+ 24, 27, 29, 31, 33, 23, nil, nil, nil, nil,
49
+ 22, nil, 26, 28, 30, 32, 34, nil, 26, 28,
50
+ 30, 32, 34, 23, 24, 27, 29, 31, 33, 23,
51
+ 24, nil, nil, nil, 22, nil, 26, 28, 30, 32,
52
+ 34, nil, 26, 28, 30, 32, 34, 23, 24, 27,
53
+ 29, 31, 33, 23, 24, nil, nil, nil, 22, nil,
54
+ 26, 28, 30, 32, 34, nil, 26, 28, 30, 32,
55
+ 34, 23, 24, 27, 29, 31, 33, nil, nil, nil,
56
+ nil, nil, 22, nil, 26, 28, 30, 32, 34, 23,
57
+ 24, 27, 29, 31, 33, nil, nil, nil, nil, nil,
58
+ 22, nil, 26, 28, 30, 32, 34 ]
59
+
60
+ racc_action_check = [
61
+ 34, 39, 35, 35, 35, 35, 35, 4, 3, 1,
62
+ nil, nil, 39, 34, 41, 34, 34, 34, 34, 34,
63
+ 34, 34, 34, 34, 34, 2, nil, 41, 41, 41,
64
+ 41, 41, 2, nil, nil, nil, nil, 53, 2, nil,
65
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
66
+ 53, 33, 53, 53, 53, 53, 53, 53, 53, 53,
67
+ 53, 53, nil, 32, 33, nil, 33, 33, 33, 33,
68
+ 33, 33, 33, 33, 33, 33, 32, 16, 32, 32,
69
+ 32, 32, 32, 32, 32, 32, 32, 32, nil, 19,
70
+ 16, nil, 16, 16, 16, 16, 16, 16, 16, 16,
71
+ 16, 16, 19, 21, 19, 19, 19, 19, 19, 19,
72
+ 19, 19, 19, 19, nil, 22, 21, 21, 21, 21,
73
+ 21, 21, 21, 21, 21, 21, 21, 21, 22, 23,
74
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
75
+ nil, 24, 23, nil, 23, 23, 23, 23, 23, 23,
76
+ 23, 23, 23, 23, 24, 26, 24, 24, 24, 24,
77
+ 24, 24, 24, 24, 24, 24, nil, 27, 26, nil,
78
+ 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
79
+ 27, 28, 27, 27, 27, 27, 27, 27, 27, 27,
80
+ 27, 27, nil, 29, 28, nil, 28, 28, 28, 28,
81
+ 28, 28, 28, 28, 28, 28, 29, 30, 29, 29,
82
+ 29, 29, 29, 29, 29, 29, 29, 29, nil, 31,
83
+ 30, nil, 30, 30, 30, 30, 30, 30, 30, 30,
84
+ 30, 30, 31, nil, 31, 31, 31, 31, 31, 31,
85
+ 31, 31, 31, 31, 36, 36, 36, 36, 36, 36,
86
+ nil, nil, nil, nil, nil, 36, nil, 36, 36, 36,
87
+ 36, 36, nil, 36, 40, 40, 40, 40, 40, 40,
88
+ 48, 48, 48, 48, nil, nil, nil, 40, 40, 40,
89
+ 40, 40, nil, 48, 48, 48, 48, 48, 50, 50,
90
+ 50, 50, nil, nil, nil, 9, 9, 9, 9, 9,
91
+ 9, 50, 50, 50, 50, 50, 9, 9, 9, 9,
92
+ 9, 9, 9, 38, 38, 38, 38, 38, 38, nil,
93
+ nil, nil, nil, nil, 38, nil, 38, 38, 38, 38,
94
+ 38, 49, 49, 49, 49, 49, 49, nil, nil, nil,
95
+ nil, nil, 49, nil, 49, 49, 49, 49, 49, 51,
96
+ 51, 51, 51, 51, 51, 42, nil, nil, nil, nil,
97
+ 51, nil, 51, 51, 51, 51, 51, nil, 42, 42,
98
+ 42, 42, 42, 43, 43, 43, 43, 43, 43, 44,
99
+ 44, nil, nil, nil, 43, nil, 43, 43, 43, 43,
100
+ 43, nil, 44, 44, 44, 44, 44, 45, 45, 45,
101
+ 45, 45, 45, 46, 46, nil, nil, nil, 45, nil,
102
+ 45, 45, 45, 45, 45, nil, 46, 46, 46, 46,
103
+ 46, 47, 47, 47, 47, 47, 47, nil, nil, nil,
104
+ nil, nil, 47, nil, 47, 47, 47, 47, 47, 55,
105
+ 55, 55, 55, 55, 55, nil, nil, nil, nil, nil,
106
+ 55, nil, 55, 55, 55, 55, 55 ]
107
+
108
+ racc_action_pointer = [
109
+ nil, 9, 17, 8, -14, nil, nil, nil, nil, 292,
110
+ nil, nil, nil, nil, nil, nil, 69, nil, nil, 81,
111
+ nil, 95, 107, 121, 133, nil, 147, 159, 173, 185,
112
+ 199, 211, 55, 43, -8, -14, 241, nil, 310, -21,
113
+ 261, 11, 352, 370, 376, 394, 400, 418, 267, 328,
114
+ 285, 346, nil, 29, nil, 436 ]
115
+
116
+ racc_action_default = [
117
+ -2, -35, -1, -35, -20, -21, -22, -23, -4, -35,
118
+ -24, -17, -30, -25, -26, -27, -35, -28, -29, -35,
119
+ 56, -35, -35, -35, -35, -3, -35, -35, -35, -35,
120
+ -35, -35, -35, -35, -35, -19, -35, -32, -33, -35,
121
+ -16, -9, -10, -11, -7, -12, -8, -13, -5, -14,
122
+ -6, -15, -18, -35, -31, -34 ]
123
+
124
+ racc_goto_table = [
125
+ 9, 1, 2, 39, nil, nil, nil, nil, nil, nil,
126
+ nil, nil, nil, nil, 35, nil, nil, 36, nil, 38,
127
+ 40, 41, 42, nil, 43, 44, 45, 46, 47, 48,
128
+ 49, 50, 51, nil, nil, nil, nil, nil, nil, nil,
129
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
130
+ nil, 55 ]
131
+
132
+ racc_goto_check = [
133
+ 3, 1, 2, 6, nil, nil, nil, nil, nil, nil,
134
+ nil, nil, nil, nil, 3, nil, nil, 3, nil, 3,
135
+ 3, 3, 3, nil, 3, 3, 3, 3, 3, 3,
136
+ 3, 3, 3, nil, nil, nil, nil, nil, nil, nil,
137
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
138
+ nil, 3 ]
139
+
140
+ racc_goto_pointer = [
141
+ nil, 1, 2, -2, nil, nil, -18 ]
142
+
143
+ racc_goto_default = [
144
+ nil, nil, nil, nil, 11, 12, nil ]
145
+
146
+ racc_reduce_table = [
147
+ 0, 0, :racc_error,
148
+ 1, 35, :_reduce_none,
149
+ 0, 36, :_reduce_2,
150
+ 3, 36, :_reduce_3,
151
+ 2, 36, :_reduce_none,
152
+ 3, 37, :_reduce_5,
153
+ 3, 37, :_reduce_6,
154
+ 3, 37, :_reduce_7,
155
+ 3, 37, :_reduce_8,
156
+ 3, 37, :_reduce_9,
157
+ 3, 37, :_reduce_10,
158
+ 3, 37, :_reduce_11,
159
+ 3, 37, :_reduce_12,
160
+ 3, 37, :_reduce_13,
161
+ 3, 37, :_reduce_14,
162
+ 3, 37, :_reduce_15,
163
+ 3, 37, :_reduce_16,
164
+ 1, 37, :_reduce_none,
165
+ 3, 38, :_reduce_18,
166
+ 2, 38, :_reduce_19,
167
+ 1, 38, :_reduce_none,
168
+ 1, 38, :_reduce_21,
169
+ 1, 38, :_reduce_22,
170
+ 1, 38, :_reduce_23,
171
+ 1, 38, :_reduce_24,
172
+ 1, 38, :_reduce_25,
173
+ 1, 38, :_reduce_26,
174
+ 1, 38, :_reduce_27,
175
+ 1, 38, :_reduce_28,
176
+ 1, 38, :_reduce_29,
177
+ 1, 38, :_reduce_none,
178
+ 4, 39, :_reduce_31,
179
+ 3, 39, :_reduce_32,
180
+ 1, 40, :_reduce_33,
181
+ 3, 40, :_reduce_34 ]
182
+
183
+ racc_reduce_n = 35
184
+
185
+ racc_shift_n = 56
186
+
187
+ racc_token_table = {
188
+ false => 0,
189
+ :error => 1,
190
+ :UMINUS => 2,
191
+ "^" => 3,
192
+ "&" => 4,
193
+ "*" => 5,
194
+ "/" => 6,
195
+ "+" => 7,
196
+ "-" => 8,
197
+ "<" => 9,
198
+ ">" => 10,
199
+ "<=" => 11,
200
+ ">=" => 12,
201
+ "<>" => 13,
202
+ "=" => 14,
203
+ :EOL => 15,
204
+ :LT => 16,
205
+ :GT => 17,
206
+ :LE => 18,
207
+ :GE => 19,
208
+ :NE => 20,
209
+ "(" => 21,
210
+ ")" => 22,
211
+ :FUNC => 23,
212
+ :NUMBER => 24,
213
+ :STRING => 25,
214
+ :REF2D => 26,
215
+ :REF3D => 27,
216
+ :RANGE2D => 28,
217
+ :RANGE3D => 29,
218
+ :NAME => 30,
219
+ :TRUE => 31,
220
+ :FALSE => 32,
221
+ "," => 33 }
222
+
223
+ racc_nt_base = 34
224
+
225
+ racc_use_result_var = true
226
+
227
+ Racc_arg = [
228
+ racc_action_table,
229
+ racc_action_check,
230
+ racc_action_default,
231
+ racc_action_pointer,
232
+ racc_goto_table,
233
+ racc_goto_check,
234
+ racc_goto_default,
235
+ racc_goto_pointer,
236
+ racc_nt_base,
237
+ racc_reduce_table,
238
+ racc_token_table,
239
+ racc_shift_n,
240
+ racc_reduce_n,
241
+ racc_use_result_var ]
242
+
243
+ Racc_token_to_s_table = [
244
+ "$end",
245
+ "error",
246
+ "UMINUS",
247
+ "\"^\"",
248
+ "\"&\"",
249
+ "\"*\"",
250
+ "\"/\"",
251
+ "\"+\"",
252
+ "\"-\"",
253
+ "\"<\"",
254
+ "\">\"",
255
+ "\"<=\"",
256
+ "\">=\"",
257
+ "\"<>\"",
258
+ "\"=\"",
259
+ "EOL",
260
+ "LT",
261
+ "GT",
262
+ "LE",
263
+ "GE",
264
+ "NE",
265
+ "\"(\"",
266
+ "\")\"",
267
+ "FUNC",
268
+ "NUMBER",
269
+ "STRING",
270
+ "REF2D",
271
+ "REF3D",
272
+ "RANGE2D",
273
+ "RANGE3D",
274
+ "NAME",
275
+ "TRUE",
276
+ "FALSE",
277
+ "\",\"",
278
+ "$start",
279
+ "formula",
280
+ "expr_list",
281
+ "expr",
282
+ "primary",
283
+ "funcall",
284
+ "args" ]
285
+
286
+ Racc_debug_parser = false
287
+
288
+ ##### State transition tables end #####
289
+
290
+ # reduce 0 omitted
291
+
292
+ # reduce 1 omitted
293
+
294
+ module_eval(<<'.,.,', 'excelformula.y', 20)
295
+ def _reduce_2(val, _values, result)
296
+ result = []
297
+ result
298
+ end
299
+ .,.,
300
+
301
+ module_eval(<<'.,.,', 'excelformula.y', 21)
302
+ def _reduce_3(val, _values, result)
303
+ result.push val[1], '_arg', '1'
304
+ result
305
+ end
306
+ .,.,
307
+
308
+ # reduce 4 omitted
309
+
310
+ module_eval(<<'.,.,', 'excelformula.y', 24)
311
+ def _reduce_5(val, _values, result)
312
+ result = [ val[0], val[2], 'ptgAdd' ]
313
+ result
314
+ end
315
+ .,.,
316
+
317
+ module_eval(<<'.,.,', 'excelformula.y', 25)
318
+ def _reduce_6(val, _values, result)
319
+ result = [ val[0], val[2], 'ptgSub' ]
320
+ result
321
+ end
322
+ .,.,
323
+
324
+ module_eval(<<'.,.,', 'excelformula.y', 26)
325
+ def _reduce_7(val, _values, result)
326
+ result = [ val[0], val[2], 'ptgMul' ]
327
+ result
328
+ end
329
+ .,.,
330
+
331
+ module_eval(<<'.,.,', 'excelformula.y', 27)
332
+ def _reduce_8(val, _values, result)
333
+ result = [ val[0], val[2], 'ptgDiv' ]
334
+ result
335
+ end
336
+ .,.,
337
+
338
+ module_eval(<<'.,.,', 'excelformula.y', 28)
339
+ def _reduce_9(val, _values, result)
340
+ result = [ val[0], val[2], 'ptgPower' ]
341
+ result
342
+ end
343
+ .,.,
344
+
345
+ module_eval(<<'.,.,', 'excelformula.y', 29)
346
+ def _reduce_10(val, _values, result)
347
+ result = [ val[0], val[2], 'ptgConcat' ]
348
+ result
349
+ end
350
+ .,.,
351
+
352
+ module_eval(<<'.,.,', 'excelformula.y', 30)
353
+ def _reduce_11(val, _values, result)
354
+ result = [ val[0], val[2], 'ptgLT' ]
355
+ result
356
+ end
357
+ .,.,
358
+
359
+ module_eval(<<'.,.,', 'excelformula.y', 31)
360
+ def _reduce_12(val, _values, result)
361
+ result = [ val[0], val[2], 'ptgGT' ]
362
+ result
363
+ end
364
+ .,.,
365
+
366
+ module_eval(<<'.,.,', 'excelformula.y', 32)
367
+ def _reduce_13(val, _values, result)
368
+ result = [ val[0], val[2], 'ptgLE' ]
369
+ result
370
+ end
371
+ .,.,
372
+
373
+ module_eval(<<'.,.,', 'excelformula.y', 33)
374
+ def _reduce_14(val, _values, result)
375
+ result = [ val[0], val[2], 'ptgGE' ]
376
+ result
377
+ end
378
+ .,.,
379
+
380
+ module_eval(<<'.,.,', 'excelformula.y', 34)
381
+ def _reduce_15(val, _values, result)
382
+ result = [ val[0], val[2], 'ptgNE' ]
383
+ result
384
+ end
385
+ .,.,
386
+
387
+ module_eval(<<'.,.,', 'excelformula.y', 35)
388
+ def _reduce_16(val, _values, result)
389
+ result = [ val[0], val[2], 'ptgEQ' ]
390
+ result
391
+ end
392
+ .,.,
393
+
394
+ # reduce 17 omitted
395
+
396
+ module_eval(<<'.,.,', 'excelformula.y', 38)
397
+ def _reduce_18(val, _values, result)
398
+ result = [ val[1], '_arg', '1', 'ptgParen']
399
+ result
400
+ end
401
+ .,.,
402
+
403
+ module_eval(<<'.,.,', 'excelformula.y', 39)
404
+ def _reduce_19(val, _values, result)
405
+ result = [ '_num', '-1', val[1], 'ptgMul' ]
406
+ result
407
+ end
408
+ .,.,
409
+
410
+ # reduce 20 omitted
411
+
412
+ module_eval(<<'.,.,', 'excelformula.y', 41)
413
+ def _reduce_21(val, _values, result)
414
+ result = [ '_num', val[0] ]
415
+ result
416
+ end
417
+ .,.,
418
+
419
+ module_eval(<<'.,.,', 'excelformula.y', 42)
420
+ def _reduce_22(val, _values, result)
421
+ result = [ '_str', val[0] ]
422
+ result
423
+ end
424
+ .,.,
425
+
426
+ module_eval(<<'.,.,', 'excelformula.y', 43)
427
+ def _reduce_23(val, _values, result)
428
+ result = [ '_ref2d', val[0] ]
429
+ result
430
+ end
431
+ .,.,
432
+
433
+ module_eval(<<'.,.,', 'excelformula.y', 44)
434
+ def _reduce_24(val, _values, result)
435
+ result = [ '_ref3d', val[0] ]
436
+ result
437
+ end
438
+ .,.,
439
+
440
+ module_eval(<<'.,.,', 'excelformula.y', 45)
441
+ def _reduce_25(val, _values, result)
442
+ result = [ '_range2d', val[0] ]
443
+ result
444
+ end
445
+ .,.,
446
+
447
+ module_eval(<<'.,.,', 'excelformula.y', 46)
448
+ def _reduce_26(val, _values, result)
449
+ result = [ '_range3d', val[0] ]
450
+ result
451
+ end
452
+ .,.,
453
+
454
+ module_eval(<<'.,.,', 'excelformula.y', 47)
455
+ def _reduce_27(val, _values, result)
456
+ result = [ '_name', val[0] ]
457
+ result
458
+ end
459
+ .,.,
460
+
461
+ module_eval(<<'.,.,', 'excelformula.y', 48)
462
+ def _reduce_28(val, _values, result)
463
+ result = [ 'ptgBool', '1' ]
464
+ result
465
+ end
466
+ .,.,
467
+
468
+ module_eval(<<'.,.,', 'excelformula.y', 49)
469
+ def _reduce_29(val, _values, result)
470
+ result = [ 'ptgBool', '0' ]
471
+ result
472
+ end
473
+ .,.,
474
+
475
+ # reduce 30 omitted
476
+
477
+ module_eval(<<'.,.,', 'excelformula.y', 52)
478
+ def _reduce_31(val, _values, result)
479
+ result = [ '_class', val[0], val[2], '_arg', val[2].size.to_s, '_func', val[0] ]
480
+ result
481
+ end
482
+ .,.,
483
+
484
+ module_eval(<<'.,.,', 'excelformula.y', 53)
485
+ def _reduce_32(val, _values, result)
486
+ result = [ '_func', val[0] ]
487
+ result
488
+ end
489
+ .,.,
490
+
491
+ module_eval(<<'.,.,', 'excelformula.y', 55)
492
+ def _reduce_33(val, _values, result)
493
+ result = val
494
+ result
495
+ end
496
+ .,.,
497
+
498
+ module_eval(<<'.,.,', 'excelformula.y', 56)
499
+ def _reduce_34(val, _values, result)
500
+ result.push val[2]
501
+ result
502
+ end
503
+ .,.,
504
+
505
+ def _reduce_none(val, _values, result)
506
+ val[0]
507
+ end
508
+
509
+ end # class ExcelFormulaParser
510
+
511
+
512
+ class ExcelFormulaParserError < StandardError #:nodoc:
513
+ end
514
+
515
+ class Node # :nodoc:
516
+
517
+ def exec_list(nodes)
518
+ v = nil
519
+ nodes.each { |i| v = i.evaluate }
520
+ v
521
+ end
522
+
523
+ def excelformulaparser_error(msg)
524
+ raise ExcelFormulaParserError,
525
+ "in #{fname}:#{lineno}: #{msg}"
526
+ end
527
+
528
+ end
529
+
530
+ class RootNode < Node # :nodoc:
531
+
532
+ def initialize(tree)
533
+ @tree = tree
534
+ end
535
+
536
+ def evaluate
537
+ exec_list @tree
538
+ end
539
+
540
+ end
541
+
542
+
543
+ class FuncallNode < Node # :nodoc:
544
+
545
+ def initialize(func, args)
546
+ @func = func
547
+ @args = args
548
+ end
549
+
550
+ def evaluate
551
+ arg = @args.collect {|i| i.evaluate }
552
+ out = []
553
+ arg.each { |i| o.push i }
554
+ o.push @func
555
+ p o
556
+ end
557
+
558
+ end
559
+
560
+ class NumberNode < Node # :nodoc:
561
+
562
+ def initialize(val)
563
+ @val = val
564
+ end
565
+
566
+ def evaluate
567
+ p @val
568
+ end
569
+
570
+ end
571
+
572
+ class OperateNode < Node # :nodoc:
573
+
574
+ def initialize(op, left, right)
575
+ @op = op
576
+ @left = left
577
+ @right = right
578
+ end
579
+
580
+ def evaluate
581
+ o = []
582
+ o.push @left
583
+ o.push @right
584
+ o.push @op
585
+ p o
586
+ end
587
+ end