surpass 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,602 +1,1765 @@
1
- # ExcelFormulaParser (ExcelFormula.g)
2
- # Generated by ANTLR 3.1.2-2008-10-21 on 2009-06-15 23:03:59
3
-
4
- require 'ExcelFormulaLexer' unless defined?(ExcelFormulaLexer)
5
-
6
- class ExcelFormulaParser
7
- attr_reader :lexer
8
-
9
- TOKENS = [
10
- ["EQ", 1],
11
- ["CONCAT", 2],
12
- ["ADD", 3],
13
- ["SUB", 4],
14
- ["MUL", 5],
15
- ["DIV", 6],
16
- ["POWER", 7],
17
- ["PERCENT", 8],
18
- ["TRUE_CONST", 9],
19
- ["FALSE_CONST", 10],
20
- ["STR_CONST", 11],
21
- ["INT_CONST", 12],
22
- ["NUM_CONST", 13],
23
- ["REF2D", 14],
24
- ["COLON", 15],
25
- ["LT", 16],
26
- ["GT", 17],
27
- ["NE", 18],
28
- ["LE", 19],
29
- ["GE", 20],
30
- ["SEMICOLON", 21],
31
- ["COMMA", 22],
32
- ["LP", 23],
33
- ["RP", 24],
34
- ["BANG", 25],
35
- ["DIGIT", 26],
36
- ["NAME", 27],
37
- ["QUOTENAME", 28],
38
- ["FUNC_IF", 29],
39
- ["FUNC_CHOOSE", 30]
40
- ].inject({}) { |hash, pair|
41
- name = pair[0]
42
- index = pair[1] + 3 # hardcoded for now... no way to get this value from ANTLR
43
-
44
- if name[0] == ?'
45
- hash[:"T__#{index}"] = index
46
- else
47
- hash[:"#{name}"] = index
48
- end
49
-
50
- hash
51
- }
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # ExcelFormula.g
4
+ #
5
+ # Generated using ANTLR version: 3.2.1-SNAPSHOT Dec 18, 2009 04:29:28
6
+ # Ruby runtime library version: 1.3.1
7
+ # Input grammar file: ExcelFormula.g
8
+ # Generated at: 2010-05-03 16:34:32
9
+ #
10
+
11
+ # ~~~> start load path setup
12
+ this_directory = File.expand_path( File.dirname( __FILE__ ) )
13
+ $:.unshift( this_directory ) unless $:.include?( this_directory )
14
+
15
+ antlr_load_failed = proc do
16
+ load_path = $LOAD_PATH.map { |dir| ' - ' << dir }.join( $/ )
17
+ raise LoadError, <<-END.strip!
18
+
19
+ Failed to load the ANTLR3 runtime library (version 1.3.1):
20
+
21
+ Ensure the library has been installed on your system and is available
22
+ on the load path. If rubygems is available on your system, this can
23
+ be done with the command:
24
+
25
+ gem install antlr3
26
+
27
+ Current load path:
28
+ #{ load_path }
29
+
30
+ END
31
+ end
32
+
33
+ defined?(ANTLR3) or begin
34
+
35
+ # 1: try to load the ruby antlr3 runtime library from the system path
36
+ require 'antlr3'
37
+
38
+ rescue LoadError
39
+
40
+ # 2: try to load rubygems if it isn't already loaded
41
+ defined?(Gem) or begin
42
+ require 'rubygems'
43
+ rescue LoadError
44
+ antlr_load_failed.call
45
+ end
46
+
47
+ # 3: try to activate the antlr3 gem
48
+ begin
49
+ Gem.activate( 'antlr3', '= 1.3.1' )
50
+ rescue Gem::LoadError
51
+ antlr_load_failed.call
52
+ end
53
+
54
+ require 'antlr3'
55
+
56
+ end
57
+ # <~~~ end load path setup
58
+
59
+ # - - - - - - begin action @parser::header - - - - - -
60
+ # ExcelFormula.g
61
+
62
+
63
+ RVA_DELTA = {"R" => 0, "V" => 0x20, "A" => 0x40}
64
+ RVA_DELTA_REF = {"R" => 0, "V" => 0x20, "A" => 0x40, "D" => 0x20}
65
+ RVA_DELTA_AREA = {"R" => 0, "V" => 0x20, "A" => 0x40, "D" => 0}
66
+
67
+ # - - - - - - end action @parser::header - - - - - - -
68
+
69
+
70
+ module ExcelFormula
71
+ # TokenData defines all of the token type integer values
72
+ # as constants, which will be included in all
73
+ # ANTLR-generated recognizers.
74
+ const_defined?(:TokenData) or TokenData = ANTLR3::TokenScheme.new
75
+
76
+ module TokenData
77
+
78
+ # define the token constants
79
+ define_tokens(:GE => 8, :LT => 7, :NUM_CONST => 21, :PERCENT => 16,
80
+ :REF2D => 22, :CONCAT => 10, :RP => 29, :LP => 26, :INT_CONST => 20,
81
+ :STR_CONST => 19, :POWER => 15, :SUB => 12, :FUNC_CHOOSE => 30,
82
+ :SEMICOLON => 27, :BANG => 24, :TRUE_CONST => 17, :EOF => -1,
83
+ :MUL => 13, :COLON => 23, :NAME => 31, :FALSE_CONST => 18,
84
+ :COMMA => 28, :GT => 6, :DIGIT => 33, :EQ => 4, :DIV => 14,
85
+ :FUNC_IF => 25, :QUOTENAME => 32, :LE => 9, :NE => 5,
86
+ :ADD => 11)
87
+
88
+ # register the proper human-readable name or literal value
89
+ # for each token type
90
+ #
91
+ # this is necessary because anonymous tokens, which are
92
+ # created from literal values in the grammar, do not
93
+ # have descriptive names
94
+ register_names("EQ", "NE", "GT", "LT", "GE", "LE", "CONCAT", "ADD",
95
+ "SUB", "MUL", "DIV", "POWER", "PERCENT", "TRUE_CONST",
96
+ "FALSE_CONST", "STR_CONST", "INT_CONST", "NUM_CONST",
97
+ "REF2D", "COLON", "BANG", "FUNC_IF", "LP", "SEMICOLON",
98
+ "COMMA", "RP", "FUNC_CHOOSE", "NAME", "QUOTENAME", "DIGIT")
52
99
 
53
- TOKENS[:EOF] = -1
54
-
55
- def initialize(input)
56
- if input.respond_to?(:to_str) || input.respond_to?(:read)
57
- input = ExcelFormulaLexer.new(input)
58
- end
100
+ end
59
101
 
60
- @lexer = input
61
- @input = TokenStream.new(input)
62
- @backtracking = 0
63
- @failed = false
64
102
 
103
+ class Parser < ANTLR3::Parser
104
+ @grammar_home = ExcelFormula
65
105
 
66
- @rpn = ''
67
- @sheet_references = []
68
- @xcall_references = []
106
+ RULE_METHODS = [:formula, :expr, :prec0_expr, :prec1_expr, :prec2_expr,
107
+ :prec3_expr, :prec4_expr, :prec5_expr, :primary, :expr_list,
108
+ :sheet].freeze
69
109
 
70
110
 
71
- end
111
+ include TokenData
72
112
 
73
- # 22:1: formula : expr[\"V\"] ;
74
- def formula()
113
+ generated_using( "ExcelFormula.g", "3.2.1-SNAPSHOT Dec 18, 2009 04:29:28", "1.3.1" )
75
114
 
115
+ def initialize(input, options = {})
116
+ super(input, options)
76
117
 
118
+ # - - - - - - begin action @parser::init - - - - - -
119
+ # ExcelFormula.g
77
120
 
78
- # 23:7: expr[\"V\"]
79
- expr("V")
80
121
 
122
+ @rpn = ''
123
+ @sheet_references = []
124
+ @xcall_references = []
81
125
 
126
+ # - - - - - - end action @parser::init - - - - - - -
82
127
 
83
128
 
84
129
  end
85
130
 
86
- # 26:1: expr[arg_type] : prec0_expr[arg_type] ( ( EQ ) prec0_expr[arg_type] )* ;
87
- def expr(arg_type)
88
-
131
+ attr_accessor :rpn
89
132
 
133
+ # - - - - - - - - - - - - Rules - - - - - - - - - - - - -
90
134
 
91
- # 27:7: prec0_expr[arg_type] ( ( EQ ) prec0_expr[arg_type] )*
92
- prec0_expr(arg_type)
135
+ # parser rule formula
136
+ #
137
+ # (in ExcelFormula.g)
138
+ # 24:1: formula : expr[\"V\"] ;
139
+ def formula
140
+ # -> uncomment the next line to manually enable rule tracing
141
+ # trace_in(__method__, 1)
93
142
 
94
- # 28:9: ( ( EQ ) prec0_expr[arg_type] )*
95
- while true
96
- alt1 = 2
97
- #
98
- look_ahead1_0 = look_ahead(1)
99
- if look_ahead1_0 == :EQ
100
- alt1 = 1
101
- end
102
- case alt1
103
- when 1
104
- # 29:13: ( EQ ) prec0_expr[arg_type]
105
- # 30:19: EQ
106
- match(:EQ)
107
- op = [PTGEQ].pack('C')
108
- prec0_expr(arg_type)
109
-
110
- @rpn += op
111
- else
112
- break
113
- end
114
- end
143
+ begin
144
+ # at line 25:7: expr[\"V\"]
145
+ @state.following.push(TOKENS_FOLLOWING_expr_IN_formula_60)
146
+ expr("V")
147
+ @state.following.pop
115
148
 
149
+ rescue ANTLR3::Error::RecognitionError => re
150
+ report_error(re)
151
+ recover(re)
116
152
 
153
+ ensure
154
+ # -> uncomment the next line to manually enable rule tracing
155
+ # trace_out(__method__, 1)
117
156
 
157
+ end
158
+
159
+ return
118
160
  end
119
161
 
120
- # 42:1: prec0_expr[arg_type] : prec1_expr[arg_type] ( ( CONCAT ) prec1_expr[arg_type] )* ;
121
- def prec0_expr(arg_type)
122
162
 
163
+ # parser rule expr
164
+ #
165
+ # (in ExcelFormula.g)
166
+ # 28:1: expr[arg_type] : prec0_expr[arg_type] ( ( EQ | NE | GT | LT | GE | LE ) prec0_expr[arg_type] )* ;
167
+ def expr(arg_type)
168
+ # -> uncomment the next line to manually enable rule tracing
169
+ # trace_in(__method__, 2)
123
170
 
171
+ begin
172
+ # at line 29:7: prec0_expr[arg_type] ( ( EQ | NE | GT | LT | GE | LE ) prec0_expr[arg_type] )*
173
+ @state.following.push(TOKENS_FOLLOWING_prec0_expr_IN_expr_79)
174
+ prec0_expr(arg_type)
175
+ @state.following.pop
176
+ # at line 30:9: ( ( EQ | NE | GT | LT | GE | LE ) prec0_expr[arg_type] )*
177
+ loop do # decision 2
178
+ alt_2 = 2
179
+ alt_2 = @dfa2.predict(@input)
180
+ case alt_2
181
+ when 1
182
+ # at line 31:13: ( EQ | NE | GT | LT | GE | LE ) prec0_expr[arg_type]
183
+ # at line 31:13: ( EQ | NE | GT | LT | GE | LE )
184
+ alt_1 = 6
185
+ case look_1 = @input.peek(1)
186
+ when EQ then alt_1 = 1
187
+ when NE then alt_1 = 2
188
+ when GT then alt_1 = 3
189
+ when LT then alt_1 = 4
190
+ when GE then alt_1 = 5
191
+ when LE then alt_1 = 6
192
+ else
193
+ nvae = NoViableAlternative("", 1, 0)
194
+ raise nvae
195
+ end
196
+ case alt_1
197
+ when 1
198
+ # at line 32:19: EQ
199
+ match(EQ, TOKENS_FOLLOWING_EQ_IN_expr_124)
200
+ # --> action
201
+ op = [PTGEQ].pack('C')
202
+ # <-- action
124
203
 
125
- # 43:7: prec1_expr[arg_type] ( ( CONCAT ) prec1_expr[arg_type] )*
126
- prec1_expr(arg_type)
204
+ when 2
205
+ # at line 33:19: NE
206
+ match(NE, TOKENS_FOLLOWING_NE_IN_expr_146)
207
+ # --> action
208
+ op = [PTGNE].pack('C')
209
+ # <-- action
127
210
 
128
- # 44:9: ( ( CONCAT ) prec1_expr[arg_type] )*
129
- while true
130
- alt2 = 2
131
- #
132
- look_ahead2_0 = look_ahead(1)
133
- if look_ahead2_0 == :CONCAT
134
- alt2 = 1
135
- end
136
- case alt2
137
- when 1
138
- # 45:13: ( CONCAT ) prec1_expr[arg_type]
139
- # 46:17: CONCAT
140
- match(:CONCAT)
141
- op = [PTGCONCAT].pack('C')
142
- prec1_expr(arg_type)
143
-
144
- @rpn += op
145
- else
146
- break
147
- end
148
- end
211
+ when 3
212
+ # at line 34:19: GT
213
+ match(GT, TOKENS_FOLLOWING_GT_IN_expr_168)
214
+ # --> action
215
+ op = [PTGGT].pack('C')
216
+ # <-- action
149
217
 
218
+ when 4
219
+ # at line 35:19: LT
220
+ match(LT, TOKENS_FOLLOWING_LT_IN_expr_190)
221
+ # --> action
222
+ op = [PTGLT].pack('C')
223
+ # <-- action
150
224
 
225
+ when 5
226
+ # at line 36:19: GE
227
+ match(GE, TOKENS_FOLLOWING_GE_IN_expr_212)
228
+ # --> action
229
+ op = [PTGGE].pack('C')
230
+ # <-- action
231
+
232
+ when 6
233
+ # at line 37:19: LE
234
+ match(LE, TOKENS_FOLLOWING_LE_IN_expr_234)
235
+ # --> action
236
+ op = [PTGLE].pack('C')
237
+ # <-- action
151
238
 
239
+ end
240
+ @state.following.push(TOKENS_FOLLOWING_prec0_expr_IN_expr_265)
241
+ prec0_expr(arg_type)
242
+ @state.following.pop
243
+ # --> action
244
+ @rpn += op
245
+ # <-- action
246
+
247
+ else
248
+ break # out of loop for decision 2
249
+ end
250
+ end # loop for decision 2
251
+
252
+ rescue ANTLR3::Error::RecognitionError => re
253
+ report_error(re)
254
+ recover(re)
255
+
256
+ ensure
257
+ # -> uncomment the next line to manually enable rule tracing
258
+ # trace_out(__method__, 2)
259
+
260
+ end
261
+
262
+ return
152
263
  end
153
264
 
154
- # 52:1: prec1_expr[arg_type] : prec2_expr[arg_type] ( ( ADD | SUB ) prec2_expr[arg_type] )* ;
155
- def prec1_expr(arg_type)
156
265
 
266
+ # parser rule prec0_expr
267
+ #
268
+ # (in ExcelFormula.g)
269
+ # 44:1: prec0_expr[arg_type] : prec1_expr[arg_type] ( ( CONCAT ) prec1_expr[arg_type] )* ;
270
+ def prec0_expr(arg_type)
271
+ # -> uncomment the next line to manually enable rule tracing
272
+ # trace_in(__method__, 3)
157
273
 
274
+ begin
275
+ # at line 45:7: prec1_expr[arg_type] ( ( CONCAT ) prec1_expr[arg_type] )*
276
+ @state.following.push(TOKENS_FOLLOWING_prec1_expr_IN_prec0_expr_297)
277
+ prec1_expr(arg_type)
278
+ @state.following.pop
279
+ # at line 46:9: ( ( CONCAT ) prec1_expr[arg_type] )*
280
+ loop do # decision 3
281
+ alt_3 = 2
282
+ alt_3 = @dfa3.predict(@input)
283
+ case alt_3
284
+ when 1
285
+ # at line 47:13: ( CONCAT ) prec1_expr[arg_type]
286
+ # at line 47:13: ( CONCAT )
287
+ # at line 48:17: CONCAT
288
+ match(CONCAT, TOKENS_FOLLOWING_CONCAT_IN_prec0_expr_340)
289
+ # --> action
290
+ op = [PTGCONCAT].pack('C')
291
+ # <-- action
292
+
293
+ @state.following.push(TOKENS_FOLLOWING_prec1_expr_IN_prec0_expr_370)
294
+ prec1_expr(arg_type)
295
+ @state.following.pop
296
+ # --> action
297
+ @rpn += op
298
+ # <-- action
299
+
300
+ else
301
+ break # out of loop for decision 3
302
+ end
303
+ end # loop for decision 3
304
+
305
+ rescue ANTLR3::Error::RecognitionError => re
306
+ report_error(re)
307
+ recover(re)
308
+
309
+ ensure
310
+ # -> uncomment the next line to manually enable rule tracing
311
+ # trace_out(__method__, 3)
312
+
313
+ end
314
+
315
+ return
316
+ end
158
317
 
159
- # 53:7: prec2_expr[arg_type] ( ( ADD | SUB ) prec2_expr[arg_type] )*
160
- prec2_expr(arg_type)
161
318
 
162
- # 54:9: ( ( ADD | SUB ) prec2_expr[arg_type] )*
163
- while true
164
- alt4 = 2
165
- #
166
- look_ahead4_0 = look_ahead(1)
167
- if (TOKENS[look_ahead4_0] >= 6 && TOKENS[look_ahead4_0] <= 7)
168
- alt4 = 1
169
- end
170
- case alt4
171
- when 1
172
- # 55:13: ( ADD | SUB ) prec2_expr[arg_type]
173
- # 55:13: ( ADD | SUB )
174
- alt3 = 2
175
- #
176
- look_ahead3_0 = look_ahead(1)
177
- if look_ahead3_0 == :ADD
178
- alt3 = 1
179
- elsif look_ahead3_0 == :SUB
180
- alt3 = 2
181
- else
182
- raise "Expected: "
183
- end
184
- case alt3
185
- when 1
186
- # 56:19: ADD
187
- match(:ADD)
188
- op = [PTGADD].pack('C')
189
- when 2
190
- # 57:19: SUB
191
- match(:SUB)
192
- op = [PTGSUB].pack('C')
193
- end
194
- prec2_expr(arg_type)
319
+ # parser rule prec1_expr
320
+ #
321
+ # (in ExcelFormula.g)
322
+ # 54:1: prec1_expr[arg_type] : prec2_expr[arg_type] ( ( ADD | SUB ) prec2_expr[arg_type] )* ;
323
+ def prec1_expr(arg_type)
324
+ # -> uncomment the next line to manually enable rule tracing
325
+ # trace_in(__method__, 4)
195
326
 
196
- @rpn += op
197
- else
198
- break
327
+ begin
328
+ # at line 55:7: prec2_expr[arg_type] ( ( ADD | SUB ) prec2_expr[arg_type] )*
329
+ @state.following.push(TOKENS_FOLLOWING_prec2_expr_IN_prec1_expr_402)
330
+ prec2_expr(arg_type)
331
+ @state.following.pop
332
+ # at line 56:9: ( ( ADD | SUB ) prec2_expr[arg_type] )*
333
+ loop do # decision 5
334
+ alt_5 = 2
335
+ alt_5 = @dfa5.predict(@input)
336
+ case alt_5
337
+ when 1
338
+ # at line 57:13: ( ADD | SUB ) prec2_expr[arg_type]
339
+ # at line 57:13: ( ADD | SUB )
340
+ alt_4 = 2
341
+ look_4_0 = @input.peek(1)
342
+
343
+ if (look_4_0 == ADD)
344
+ alt_4 = 1
345
+ elsif (look_4_0 == SUB)
346
+ alt_4 = 2
347
+ else
348
+ nvae = NoViableAlternative("", 4, 0)
349
+ raise nvae
199
350
  end
200
- end
201
-
351
+ case alt_4
352
+ when 1
353
+ # at line 58:19: ADD
354
+ match(ADD, TOKENS_FOLLOWING_ADD_IN_prec1_expr_447)
355
+ # --> action
356
+ op = [PTGADD].pack('C')
357
+ # <-- action
202
358
 
359
+ when 2
360
+ # at line 59:19: SUB
361
+ match(SUB, TOKENS_FOLLOWING_SUB_IN_prec1_expr_469)
362
+ # --> action
363
+ op = [PTGSUB].pack('C')
364
+ # <-- action
203
365
 
366
+ end
367
+ @state.following.push(TOKENS_FOLLOWING_prec2_expr_IN_prec1_expr_499)
368
+ prec2_expr(arg_type)
369
+ @state.following.pop
370
+ # --> action
371
+ @rpn += op
372
+ # <-- action
373
+
374
+ else
375
+ break # out of loop for decision 5
376
+ end
377
+ end # loop for decision 5
378
+
379
+ rescue ANTLR3::Error::RecognitionError => re
380
+ report_error(re)
381
+ recover(re)
382
+
383
+ ensure
384
+ # -> uncomment the next line to manually enable rule tracing
385
+ # trace_out(__method__, 4)
386
+
387
+ end
388
+
389
+ return
204
390
  end
205
391
 
206
- # 64:1: prec2_expr[arg_type] : prec3_expr[arg_type] ( ( MUL | DIV ) prec3_expr[arg_type] )* ;
207
- def prec2_expr(arg_type)
208
-
209
392
 
393
+ # parser rule prec2_expr
394
+ #
395
+ # (in ExcelFormula.g)
396
+ # 66:1: prec2_expr[arg_type] : prec3_expr[arg_type] ( ( MUL | DIV ) prec3_expr[arg_type] )* ;
397
+ def prec2_expr(arg_type)
398
+ # -> uncomment the next line to manually enable rule tracing
399
+ # trace_in(__method__, 5)
210
400
 
211
- # 65:7: prec3_expr[arg_type] ( ( MUL | DIV ) prec3_expr[arg_type] )*
401
+ begin
402
+ # at line 67:7: prec3_expr[arg_type] ( ( MUL | DIV ) prec3_expr[arg_type] )*
403
+ @state.following.push(TOKENS_FOLLOWING_prec3_expr_IN_prec2_expr_532)
212
404
  prec3_expr(arg_type)
213
-
214
- # 66:9: ( ( MUL | DIV ) prec3_expr[arg_type] )*
215
- while true
216
- alt6 = 2
217
- #
218
- look_ahead6_0 = look_ahead(1)
219
- if (TOKENS[look_ahead6_0] >= 8 && TOKENS[look_ahead6_0] <= 9)
220
- alt6 = 1
405
+ @state.following.pop
406
+ # at line 68:9: ( ( MUL | DIV ) prec3_expr[arg_type] )*
407
+ loop do # decision 7
408
+ alt_7 = 2
409
+ alt_7 = @dfa7.predict(@input)
410
+ case alt_7
411
+ when 1
412
+ # at line 69:13: ( MUL | DIV ) prec3_expr[arg_type]
413
+ # at line 69:13: ( MUL | DIV )
414
+ alt_6 = 2
415
+ look_6_0 = @input.peek(1)
416
+
417
+ if (look_6_0 == MUL)
418
+ alt_6 = 1
419
+ elsif (look_6_0 == DIV)
420
+ alt_6 = 2
421
+ else
422
+ nvae = NoViableAlternative("", 6, 0)
423
+ raise nvae
221
424
  end
222
- case alt6
223
- when 1
224
- # 67:13: ( MUL | DIV ) prec3_expr[arg_type]
225
- # 67:13: ( MUL | DIV )
226
- alt5 = 2
227
- #
228
- look_ahead5_0 = look_ahead(1)
229
- if look_ahead5_0 == :MUL
230
- alt5 = 1
231
- elsif look_ahead5_0 == :DIV
232
- alt5 = 2
233
- else
234
- raise "Expected: "
235
- end
236
- case alt5
237
- when 1
238
- # 68:19: MUL
239
- match(:MUL)
240
- op = [PTGMUL].pack('C')
241
- when 2
242
- # 69:19: DIV
243
- match(:DIV)
244
- op = [PTGDIV].pack('C')
245
- end
246
- prec3_expr(arg_type)
425
+ case alt_6
426
+ when 1
427
+ # at line 70:19: MUL
428
+ match(MUL, TOKENS_FOLLOWING_MUL_IN_prec2_expr_577)
429
+ # --> action
430
+ op = [PTGMUL].pack('C')
431
+ # <-- action
432
+
433
+ when 2
434
+ # at line 71:19: DIV
435
+ match(DIV, TOKENS_FOLLOWING_DIV_IN_prec2_expr_599)
436
+ # --> action
437
+ op = [PTGDIV].pack('C')
438
+ # <-- action
247
439
 
248
- @rpn += op
249
- else
250
- break
251
440
  end
252
- end
441
+ @state.following.push(TOKENS_FOLLOWING_prec3_expr_IN_prec2_expr_629)
442
+ prec3_expr(arg_type)
443
+ @state.following.pop
444
+ # --> action
445
+ @rpn += op
446
+ # <-- action
447
+
448
+ else
449
+ break # out of loop for decision 7
450
+ end
451
+ end # loop for decision 7
452
+
453
+ rescue ANTLR3::Error::RecognitionError => re
454
+ report_error(re)
455
+ recover(re)
456
+
457
+ ensure
458
+ # -> uncomment the next line to manually enable rule tracing
459
+ # trace_out(__method__, 5)
460
+
461
+ end
462
+
463
+ return
464
+ end
253
465
 
254
466
 
467
+ # parser rule prec3_expr
468
+ #
469
+ # (in ExcelFormula.g)
470
+ # 77:1: prec3_expr[arg_type] : prec5_expr[arg_type] ( ( POWER ) prec5_expr[arg_type] )* ;
471
+ def prec3_expr(arg_type)
472
+ # -> uncomment the next line to manually enable rule tracing
473
+ # trace_in(__method__, 6)
255
474
 
475
+ begin
476
+ # at line 78:7: prec5_expr[arg_type] ( ( POWER ) prec5_expr[arg_type] )*
477
+ @state.following.push(TOKENS_FOLLOWING_prec5_expr_IN_prec3_expr_661)
478
+ prec5_expr(arg_type)
479
+ @state.following.pop
480
+ # at line 79:9: ( ( POWER ) prec5_expr[arg_type] )*
481
+ loop do # decision 8
482
+ alt_8 = 2
483
+ alt_8 = @dfa8.predict(@input)
484
+ case alt_8
485
+ when 1
486
+ # at line 80:13: ( POWER ) prec5_expr[arg_type]
487
+ # at line 80:13: ( POWER )
488
+ # at line 81:17: POWER
489
+ match(POWER, TOKENS_FOLLOWING_POWER_IN_prec3_expr_704)
490
+ # --> action
491
+ op = [PTGPOWER].pack('C')
492
+ # <-- action
493
+
494
+ @state.following.push(TOKENS_FOLLOWING_prec5_expr_IN_prec3_expr_734)
495
+ prec5_expr(arg_type)
496
+ @state.following.pop
497
+ # --> action
498
+ @rpn += op
499
+ # <-- action
500
+
501
+ else
502
+ break # out of loop for decision 8
503
+ end
504
+ end # loop for decision 8
505
+
506
+ rescue ANTLR3::Error::RecognitionError => re
507
+ report_error(re)
508
+ recover(re)
509
+
510
+ ensure
511
+ # -> uncomment the next line to manually enable rule tracing
512
+ # trace_out(__method__, 6)
513
+
514
+ end
515
+
516
+ return
256
517
  end
257
518
 
258
- # 75:1: prec3_expr[arg_type] : prec5_expr[arg_type] ( ( POWER ) prec5_expr[arg_type] )* ;
259
- def prec3_expr(arg_type)
260
-
261
519
 
520
+ # parser rule prec4_expr
521
+ #
522
+ # (in ExcelFormula.g)
523
+ # 87:1: prec4_expr[arg_type] : prec5_expr[arg_type] ( PERCENT )? ;
524
+ def prec4_expr(arg_type)
525
+ # -> uncomment the next line to manually enable rule tracing
526
+ # trace_in(__method__, 7)
262
527
 
263
- # 76:7: prec5_expr[arg_type] ( ( POWER ) prec5_expr[arg_type] )*
528
+ begin
529
+ # at line 88:7: prec5_expr[arg_type] ( PERCENT )?
530
+ @state.following.push(TOKENS_FOLLOWING_prec5_expr_IN_prec4_expr_766)
264
531
  prec5_expr(arg_type)
532
+ @state.following.pop
533
+ # at line 89:9: ( PERCENT )?
534
+ alt_9 = 2
535
+ look_9_0 = @input.peek(1)
265
536
 
266
- # 77:9: ( ( POWER ) prec5_expr[arg_type] )*
267
- while true
268
- alt7 = 2
269
- #
270
- look_ahead7_0 = look_ahead(1)
271
- if look_ahead7_0 == :POWER
272
- alt7 = 1
273
- end
274
- case alt7
275
- when 1
276
- # 78:13: ( POWER ) prec5_expr[arg_type]
277
- # 79:17: POWER
278
- match(:POWER)
279
- op = [PTGPOWER].pack('C')
280
- prec5_expr(arg_type)
281
-
282
- @rpn += op
283
- else
284
- break
285
- end
537
+ if (look_9_0 == PERCENT)
538
+ alt_9 = 1
286
539
  end
540
+ case alt_9
541
+ when 1
542
+ # at line 90:13: PERCENT
543
+ match(PERCENT, TOKENS_FOLLOWING_PERCENT_IN_prec4_expr_791)
544
+ # --> action
545
+ @rpn += [PTGPERCENT].pack('C')
546
+ # <-- action
287
547
 
548
+ end
288
549
 
550
+ rescue ANTLR3::Error::RecognitionError => re
551
+ report_error(re)
552
+ recover(re)
289
553
 
290
- end
291
-
292
- # 85:1: prec4_expr[arg_type] : prec5_expr[arg_type] ( PERCENT )? ;
293
- def prec4_expr(arg_type)
294
-
554
+ ensure
555
+ # -> uncomment the next line to manually enable rule tracing
556
+ # trace_out(__method__, 7)
295
557
 
558
+ end
559
+
560
+ return
561
+ end
296
562
 
297
- # 86:7: prec5_expr[arg_type] ( PERCENT )?
298
- prec5_expr(arg_type)
299
563
 
300
- # 87:9: ( PERCENT )?
301
- alt8 = 2
302
- #
303
- look_ahead8_0 = look_ahead(1)
564
+ # parser rule prec5_expr
565
+ #
566
+ # (in ExcelFormula.g)
567
+ # 94:1: prec5_expr[arg_type] : ( primary[arg_type] | SUB primary[arg_type] );
568
+ def prec5_expr(arg_type)
569
+ # -> uncomment the next line to manually enable rule tracing
570
+ # trace_in(__method__, 8)
571
+
572
+ begin
573
+ # at line 95:5: ( primary[arg_type] | SUB primary[arg_type] )
574
+ alt_10 = 2
575
+ alt_10 = @dfa10.predict(@input)
576
+ case alt_10
577
+ when 1
578
+ # at line 95:7: primary[arg_type]
579
+ @state.following.push(TOKENS_FOLLOWING_primary_IN_prec5_expr_822)
580
+ primary(arg_type)
581
+ @state.following.pop
582
+
583
+ when 2
584
+ # at line 96:7: SUB primary[arg_type]
585
+ match(SUB, TOKENS_FOLLOWING_SUB_IN_prec5_expr_831)
586
+ @state.following.push(TOKENS_FOLLOWING_primary_IN_prec5_expr_833)
587
+ primary(arg_type)
588
+ @state.following.pop
589
+ # --> action
590
+ @rpn += [PTGUMINUS].pack('C')
591
+ # <-- action
304
592
 
305
- if look_ahead8_0 == :PERCENT
306
- alt8 = 1
307
- end
308
- case alt8
309
- when 1
310
- # 88:13: PERCENT
311
- match(:PERCENT)
312
- @rpn += [PTGPERCENT].pack('C')
313
593
  end
594
+ rescue ANTLR3::Error::RecognitionError => re
595
+ report_error(re)
596
+ recover(re)
314
597
 
598
+ ensure
599
+ # -> uncomment the next line to manually enable rule tracing
600
+ # trace_out(__method__, 8)
315
601
 
316
-
602
+ end
603
+
604
+ return
317
605
  end
318
606
 
319
- # 92:1: prec5_expr[arg_type] : ( primary[arg_type] | SUB primary[arg_type] );
320
- def prec5_expr(arg_type)
321
-
322
607
 
608
+ # parser rule primary
609
+ #
610
+ # (in ExcelFormula.g)
611
+ # 99:1: primary[arg_type] : ( TRUE_CONST | FALSE_CONST | str_tok= STR_CONST | int_tok= INT_CONST | num_tok= NUM_CONST | ref2d_tok= REF2D | ref2d1_tok= REF2D COLON ref2d2_tok= REF2D | sheet1= sheet ( COLON sheet2= sheet )? BANG ref3d_ref2d= REF2D ( COLON ref3d_ref2d2= REF2D )? | FUNC_IF LP expr[\"V\"] ( SEMICOLON | COMMA ) expr[arg_type] ( SEMICOLON | COMMA ) expr[arg_type] RP | FUNC_CHOOSE LP expr[\"V\"] ( ( SEMICOLON | COMMA ) ( expr[arg_type] | ) )* RP | name_tok= NAME | func_tok= NAME LP arg_count= expr_list[arg_type_list, min_argc, max_argc] RP | LP expr[arg_type] RP );
612
+ def primary(arg_type)
613
+ # -> uncomment the next line to manually enable rule tracing
614
+ # trace_in(__method__, 9)
615
+ str_tok = nil
616
+ int_tok = nil
617
+ num_tok = nil
618
+ ref2d_tok = nil
619
+ ref2d1_tok = nil
620
+ ref2d2_tok = nil
621
+ ref3d_ref2d = nil
622
+ ref3d_ref2d2 = nil
623
+ name_tok = nil
624
+ func_tok = nil
625
+ sheet1 = nil
626
+ sheet2 = nil
627
+ arg_count = nil
628
+
629
+ begin
630
+ # at line 100:5: ( TRUE_CONST | FALSE_CONST | str_tok= STR_CONST | int_tok= INT_CONST | num_tok= NUM_CONST | ref2d_tok= REF2D | ref2d1_tok= REF2D COLON ref2d2_tok= REF2D | sheet1= sheet ( COLON sheet2= sheet )? BANG ref3d_ref2d= REF2D ( COLON ref3d_ref2d2= REF2D )? | FUNC_IF LP expr[\"V\"] ( SEMICOLON | COMMA ) expr[arg_type] ( SEMICOLON | COMMA ) expr[arg_type] RP | FUNC_CHOOSE LP expr[\"V\"] ( ( SEMICOLON | COMMA ) ( expr[arg_type] | ) )* RP | name_tok= NAME | func_tok= NAME LP arg_count= expr_list[arg_type_list, min_argc, max_argc] RP | LP expr[arg_type] RP )
631
+ alt_15 = 13
632
+ alt_15 = @dfa15.predict(@input)
633
+ case alt_15
634
+ when 1
635
+ # at line 100:7: TRUE_CONST
636
+ match(TRUE_CONST, TOKENS_FOLLOWING_TRUE_CONST_IN_primary_854)
637
+ # --> action
638
+
639
+ @rpn += [PTGBOOL, 1].pack("C2")
640
+
641
+ # <-- action
642
+
643
+ when 2
644
+ # at line 104:7: FALSE_CONST
645
+ match(FALSE_CONST, TOKENS_FOLLOWING_FALSE_CONST_IN_primary_872)
646
+ # --> action
647
+
648
+ @rpn += [PTGBOOL, 0].pack("C2")
649
+
650
+ # <-- action
651
+
652
+ when 3
653
+ # at line 108:7: str_tok= STR_CONST
654
+ str_tok = match(STR_CONST, TOKENS_FOLLOWING_STR_CONST_IN_primary_894)
655
+ # --> action
656
+
657
+ s = str_tok.text.gsub("\"", "")
658
+ @rpn += [PTGSTR].pack("C") + [s.length].pack('v') + s
659
+
660
+ # <-- action
661
+
662
+ when 4
663
+ # at line 113:7: int_tok= INT_CONST
664
+ int_tok = match(INT_CONST, TOKENS_FOLLOWING_INT_CONST_IN_primary_916)
665
+ # --> action
666
+
667
+ int_value = int_tok.text.to_i
668
+ if int_value <= 65535
669
+ @rpn += [PTGINT, int_value].pack("Cv")
670
+ else
671
+ @rpn += [PTGNUM, int_value.to_f].pack("CE")
672
+ end
673
+
674
+ # <-- action
675
+
676
+ when 5
677
+ # at line 122:7: num_tok= NUM_CONST
678
+ num_tok = match(NUM_CONST, TOKENS_FOLLOWING_NUM_CONST_IN_primary_934)
679
+ # --> action
680
+
681
+ @rpn += [PTGNUM, num_tok.text.to_f].pack("CE")
682
+
683
+ # <-- action
684
+
685
+ when 6
686
+ # at line 126:7: ref2d_tok= REF2D
687
+ ref2d_tok = match(REF2D, TOKENS_FOLLOWING_REF2D_IN_primary_956)
688
+ # --> action
689
+
690
+ r, c = Utilities.cell_to_packed_rowcol(ref2d_tok.text)
691
+ ptg = PTGREFR + RVA_DELTA[arg_type]
692
+ @rpn += [ptg, r, c].pack("Cv2")
693
+
694
+ # <-- action
695
+
696
+ when 7
697
+ # at line 132:7: ref2d1_tok= REF2D COLON ref2d2_tok= REF2D
698
+ ref2d1_tok = match(REF2D, TOKENS_FOLLOWING_REF2D_IN_primary_978)
699
+ match(COLON, TOKENS_FOLLOWING_COLON_IN_primary_980)
700
+ ref2d2_tok = match(REF2D, TOKENS_FOLLOWING_REF2D_IN_primary_986)
701
+ # --> action
702
+
703
+ r1, c1 = Utilities.cell_to_packed_rowcol(ref2d1_tok.text)
704
+ r2, c2 = Utilities.cell_to_packed_rowcol(ref2d2_tok.text)
705
+ ptg = PTGAREAR + RVA_DELTA[arg_type]
706
+ @rpn += [ptg, r1, r2, c1, c2].pack("Cv4")
707
+
708
+ # <-- action
709
+
710
+ when 8
711
+ # at line 140:7: sheet1= sheet ( COLON sheet2= sheet )? BANG ref3d_ref2d= REF2D ( COLON ref3d_ref2d2= REF2D )?
712
+ @state.following.push(TOKENS_FOLLOWING_sheet_IN_primary_1010)
713
+ sheet1 = sheet
714
+ @state.following.pop
715
+ # --> action
716
+
717
+ sheet2 = sheet1
718
+
719
+ # <-- action
720
+ # at line 144:9: ( COLON sheet2= sheet )?
721
+ alt_11 = 2
722
+ look_11_0 = @input.peek(1)
723
+
724
+ if (look_11_0 == COLON)
725
+ alt_11 = 1
726
+ end
727
+ case alt_11
728
+ when 1
729
+ # at line 144:11: COLON sheet2= sheet
730
+ match(COLON, TOKENS_FOLLOWING_COLON_IN_primary_1032)
731
+ @state.following.push(TOKENS_FOLLOWING_sheet_IN_primary_1038)
732
+ sheet2 = sheet
733
+ @state.following.pop
734
+
735
+ end
736
+ match(BANG, TOKENS_FOLLOWING_BANG_IN_primary_1043)
737
+ ref3d_ref2d = match(REF2D, TOKENS_FOLLOWING_REF2D_IN_primary_1047)
738
+ # --> action
739
+
740
+ ptg = PTGREF3DR + RVA_DELTA[arg_type]
741
+ rpn_ref2d = ""
742
+ r1, c1 = Utilities.cell_to_packed_rowcol(ref3d_ref2d.text)
743
+ rpn_ref2d = [0x0000, r1, c1].pack("v3")
744
+
745
+ # <-- action
746
+ # at line 151:9: ( COLON ref3d_ref2d2= REF2D )?
747
+ alt_12 = 2
748
+ alt_12 = @dfa12.predict(@input)
749
+ case alt_12
750
+ when 1
751
+ # at line 151:11: COLON ref3d_ref2d2= REF2D
752
+ match(COLON, TOKENS_FOLLOWING_COLON_IN_primary_1069)
753
+ ref3d_ref2d2 = match(REF2D, TOKENS_FOLLOWING_REF2D_IN_primary_1074)
754
+ # --> action
755
+
756
+ ptg = PTGAREA3DR + RVA_DELTA[arg_type]
757
+ r2, c2 = Utilities.cell_to_packed_rowcol(ref3d_ref2d2.text)
758
+ rpn_ref2d = [0x0000, r1, r2, c1, c2].pack("v5")
759
+
760
+ # <-- action
761
+
762
+ end
763
+ # --> action
764
+
765
+ @rpn += [ptg].pack("C")
766
+ @sheet_references << [sheet1, sheet2, @rpn.size]
767
+ @rpn += rpn_ref2d
768
+
769
+ # <-- action
770
+
771
+ when 9
772
+ # at line 163:7: FUNC_IF LP expr[\"V\"] ( SEMICOLON | COMMA ) expr[arg_type] ( SEMICOLON | COMMA ) expr[arg_type] RP
773
+ match(FUNC_IF, TOKENS_FOLLOWING_FUNC_IF_IN_primary_1117)
774
+ match(LP, TOKENS_FOLLOWING_LP_IN_primary_1127)
775
+ @state.following.push(TOKENS_FOLLOWING_expr_IN_primary_1129)
776
+ expr("V")
777
+ @state.following.pop
778
+ if @input.peek(1).between?(SEMICOLON, COMMA)
779
+ @input.consume
780
+ @state.error_recovery = false
781
+ else
782
+ mse = MismatchedSet(nil)
783
+ raise mse
784
+ end
785
+
786
+
787
+ # --> action
788
+
789
+ @rpn += [PTGATTR, 0x02, 0].pack("C2v") # tAttrIf
790
+ pos0 = @rpn.size - 2
791
+
792
+ # <-- action
793
+ @state.following.push(TOKENS_FOLLOWING_expr_IN_primary_1158)
794
+ expr(arg_type)
795
+ @state.following.pop
796
+ if @input.peek(1).between?(SEMICOLON, COMMA)
797
+ @input.consume
798
+ @state.error_recovery = false
799
+ else
800
+ mse = MismatchedSet(nil)
801
+ raise mse
802
+ end
803
+
804
+
805
+ # --> action
806
+
807
+ @rpn += [PTGATTR, 0x08, 0].pack("C2v") # tAttrSkip
808
+ pos1 = @rpn.length - 2
809
+
810
+ rem = @rpn.length - (pos0 + 2)
811
+ @rpn = @rpn[0..pos0] + [pos1-pos0].pack("v") + @rpn[pos0+2, rem] # TODO Check for OBO
812
+
813
+ # <-- action
814
+ @state.following.push(TOKENS_FOLLOWING_expr_IN_primary_1187)
815
+ expr(arg_type)
816
+ @state.following.pop
817
+ match(RP, TOKENS_FOLLOWING_RP_IN_primary_1190)
818
+ # --> action
819
+
820
+ @rpn += [PTGATTR, 0x08, 3].pack("C2v") # tAttrSkip
821
+ @rpn += [PTGFUNCVARR, 3, 1].pack("C2v") # 3 = nargs, 1 = IF func
822
+ pos2 = @rpn.length
823
+
824
+ rem = @rpn.length - (pos1 + 2)
825
+ @rpn = @rpn[0..pos1] + [pos2-(pos1+2)-1].pack("v") + @rpn[pos1+2, rem] # TODO Check for OBO
826
+
827
+ # <-- action
828
+
829
+ when 10
830
+ # at line 186:7: FUNC_CHOOSE LP expr[\"V\"] ( ( SEMICOLON | COMMA ) ( expr[arg_type] | ) )* RP
831
+ match(FUNC_CHOOSE, TOKENS_FOLLOWING_FUNC_CHOOSE_IN_primary_1208)
832
+ # --> action
833
+
834
+ arg_type = "R"
835
+ rpn_chunks = []
836
+
837
+ # <-- action
838
+ match(LP, TOKENS_FOLLOWING_LP_IN_primary_1228)
839
+ @state.following.push(TOKENS_FOLLOWING_expr_IN_primary_1230)
840
+ expr("V")
841
+ @state.following.pop
842
+ # --> action
843
+
844
+ rpn_start = @rpn.length
845
+ ref_markers = [@sheet_references.length]
846
+
847
+ # <-- action
848
+ # at line 196:9: ( ( SEMICOLON | COMMA ) ( expr[arg_type] | ) )*
849
+ loop do # decision 14
850
+ alt_14 = 2
851
+ look_14_0 = @input.peek(1)
852
+
853
+ if (look_14_0.between?(SEMICOLON, COMMA))
854
+ alt_14 = 1
323
855
 
324
- # 93:5: ( primary[arg_type] | SUB primary[arg_type] )
325
- alt9 = 2
326
- #
327
- look_ahead9_0 = look_ahead(1)
328
- if (TOKENS[look_ahead9_0] >= 12 && TOKENS[look_ahead9_0] <= 17)
329
- alt9 = 1
330
- elsif look_ahead9_0 == :SUB
331
- alt9 = 2
332
- else
333
- raise "Expected: "
334
- end
335
- case alt9
856
+ end
857
+ case alt_14
336
858
  when 1
337
- # 93:7: primary[arg_type]
338
- primary(arg_type)
859
+ # at line 197:13: ( SEMICOLON | COMMA ) ( expr[arg_type] | )
860
+ if @input.peek(1).between?(SEMICOLON, COMMA)
861
+ @input.consume
862
+ @state.error_recovery = false
863
+ else
864
+ mse = MismatchedSet(nil)
865
+ raise mse
866
+ end
867
+
868
+
869
+ # --> action
870
+ mark = @rpn.length
871
+ # <-- action
872
+ # at line 199:17: ( expr[arg_type] | )
873
+ alt_13 = 2
874
+ alt_13 = @dfa13.predict(@input)
875
+ case alt_13
876
+ when 1
877
+ # at line 200:19: expr[arg_type]
878
+ @state.following.push(TOKENS_FOLLOWING_expr_IN_primary_1327)
879
+ expr(arg_type)
880
+ @state.following.pop
881
+
882
+ when 2
883
+ # at line 201:19:
884
+ # --> action
885
+ @rpn += [PTGMISSARG].pack("C")
886
+ # <-- action
887
+
888
+ end
889
+ # --> action
890
+
891
+ rem = @rpn.length - mark
892
+ rpn_chunks << @rpn[mark, rem]
893
+ ref_markers << @sheet_references.size
894
+
895
+ # <-- action
896
+
897
+ else
898
+ break # out of loop for decision 14
899
+ end
900
+ end # loop for decision 14
901
+ match(RP, TOKENS_FOLLOWING_RP_IN_primary_1405)
902
+ # --> action
903
+
904
+ @rpn = @rpn[0..rpn_start]
905
+ nc = rpn_chunks.length
906
+ chunklens = rpn_chunks.collect {|c| c.length}
907
+ skiplens = [0] * nc
908
+ skiplens[-1] = 3
909
+
910
+ (nc-1).downto(1) do |i|
911
+ skiplens[i-1] = skiplens[i] + chunklens[i] + 4
912
+ end
913
+ jump_pos = [2 * nc + 2]
914
+
915
+ (0...nc).each do |i|
916
+ jump_pos.append(jump_pos[-1] + chunklens[ic] + 4)
917
+ end
918
+ chunk_shift = 2 * nc + 6 # size of tAttrChoose
919
+
920
+ (0...nc).each do |i|
921
+ (ref_markers[i]...ref_markers[i+1]).each do |r|
922
+ ref = @sheet_references[r]
923
+ @sheet_references[r] = [ref[0], ref[1], ref[2] + chunk_shift]
924
+ end
925
+ chunk_shift += 4 # size of tAttrSkip
926
+ end
927
+
928
+ choose_rpn = []
929
+ choose_rpn << [PTGATTR, 0x04, nc].pack("CCv") # 0x04 is tAttrChoose
930
+ choose_rpn << jump_pos.pack("v*")
931
+
932
+ (0...nc).each do |i|
933
+ choose_rpn << rpn_chunks[i]
934
+ choose_rpn << [PTGATTR, 0x08, skiplens[i]].pack("CCv") # 0x08 is tAttrSkip
935
+ end
936
+ choose_rpn << [PTGFUNCVARV, nc+1, 100].pack("CCv") # 100 is CHOOSE fn
937
+ @rpn += choose_rpn.join
938
+
939
+ # <-- action
940
+
941
+ when 11
942
+ # at line 246:7: name_tok= NAME
943
+ name_tok = match(NAME, TOKENS_FOLLOWING_NAME_IN_primary_1427)
944
+ # --> action
945
+
946
+ raise "[formula] found unexpected NAME token #{name_tok.text}"
947
+
948
+ # <-- action
949
+
950
+ when 12
951
+ # at line 250:7: func_tok= NAME LP arg_count= expr_list[arg_type_list, min_argc, max_argc] RP
952
+ func_tok = match(NAME, TOKENS_FOLLOWING_NAME_IN_primary_1449)
953
+ # --> action
954
+
955
+ func_toku = func_tok.text.upcase
956
+ if STD_FUNC_BY_NAME.has_key?(func_toku)
957
+ opcode, min_argc, max_argc, func_type, arg_type_str = STD_FUNC_BY_NAME[func_toku]
958
+ arg_type_list = arg_type_str.split
959
+ else
960
+ raise "[formula] unknown function #{func_tok.text}"
961
+ end
962
+ xcall = (opcode < 0)
339
963
 
340
- when 2
341
- # 94:7: SUB primary[arg_type]
342
- match(:SUB)
343
- primary(arg_type)
964
+ if xcall
965
+ @xcall_references << [func_toku, @rpn.size + 1]
966
+ @rpn += [PTGNAMEXR, 0xadde, 0xefbe, 0x0000].pack("Cvvv")
967
+ end
968
+
969
+ # <-- action
970
+ match(LP, TOKENS_FOLLOWING_LP_IN_primary_1469)
971
+ @state.following.push(TOKENS_FOLLOWING_expr_list_IN_primary_1475)
972
+ arg_count = expr_list(arg_type_list, min_argc, max_argc)
973
+ @state.following.pop
974
+ match(RP, TOKENS_FOLLOWING_RP_IN_primary_1478)
975
+ # --> action
976
+
977
+ if (arg_count > max_argc) || (arg_count < min_argc)
978
+ raise "#{arg_count} parameters for function: #{func_tok.text}"
979
+ end
344
980
 
345
- @rpn += [PTGUMINUS].pack('C')
346
- end
981
+ if xcall
982
+ func_ptg = PTGFUNCVARR + RVA_DELTA[func_type]
983
+ @rpn += [func_ptg, arg_count + 1, 255].pack("CCv") # 255 is magic XCALL function
984
+ elsif (min_argc == max_argc)
985
+ func_ptg = PTGFUNCR + RVA_DELTA[func_type]
986
+ @rpn += [func_ptg, opcode].pack("Cv")
987
+ elsif (arg_count == 1) && (func_tok.text.upcase == "SUM")
988
+ @rpn += [PTGATTR, 0x10, 0].pack("CCv") # tAttrSum
989
+ else
990
+ func_ptg = PTGFUNCVARR + RVA_DELTA[func_type]
991
+ @rpn += [func_ptg, arg_count, opcode].pack("CCv")
992
+ end
993
+
994
+ # <-- action
995
+
996
+ when 13
997
+ # at line 285:7: LP expr[arg_type] RP
998
+ match(LP, TOKENS_FOLLOWING_LP_IN_primary_1496)
999
+ @state.following.push(TOKENS_FOLLOWING_expr_IN_primary_1498)
1000
+ expr(arg_type)
1001
+ @state.following.pop
1002
+ match(RP, TOKENS_FOLLOWING_RP_IN_primary_1501)
1003
+ # --> action
1004
+
1005
+ @rpn += [PTGPAREN].pack('C')
1006
+
1007
+ # <-- action
347
1008
 
1009
+ end
1010
+ rescue ANTLR3::Error::RecognitionError => re
1011
+ report_error(re)
1012
+ recover(re)
348
1013
 
1014
+ ensure
1015
+ # -> uncomment the next line to manually enable rule tracing
1016
+ # trace_out(__method__, 9)
349
1017
 
1018
+ end
1019
+
1020
+ return
350
1021
  end
351
1022
 
352
- # 97:1: primary[arg_type] : ( TRUE_CONST | FALSE_CONST | str_tok= STR_CONST | int_tok= INT_CONST | num_tok= NUM_CONST | ref2d_tok= REF2D | ref2d1_tok= REF2D COLON ref2d2_tok= REF2D );
353
- def primary(arg_type)
354
- _str_tok = nil
355
- _int_tok = nil
356
- _num_tok = nil
357
- _ref2d_tok = nil
358
- _ref2d1_tok = nil
359
- _ref2d2_tok = nil
360
-
361
1023
 
1024
+ # parser rule expr_list
1025
+ #
1026
+ # (in ExcelFormula.g)
1027
+ # 292:1: expr_list[arg_type_list, min_argc, max_argc] returns [arg_cnt] : ( expr[arg_type] ( ( SEMICOLON | COMMA ) ( expr[arg_type] | ) )* | );
1028
+ def expr_list(arg_type_list, min_argc, max_argc)
1029
+ # -> uncomment the next line to manually enable rule tracing
1030
+ # trace_in(__method__, 10)
1031
+ arg_cnt = nil
1032
+
1033
+ begin
1034
+ # at line 297:5: ( expr[arg_type] ( ( SEMICOLON | COMMA ) ( expr[arg_type] | ) )* | )
1035
+ alt_18 = 2
1036
+ alt_18 = @dfa18.predict(@input)
1037
+ case alt_18
1038
+ when 1
1039
+ # at line 297:7: expr[arg_type] ( ( SEMICOLON | COMMA ) ( expr[arg_type] | ) )*
1040
+ @state.following.push(TOKENS_FOLLOWING_expr_IN_expr_list_1542)
1041
+ expr(arg_type)
1042
+ @state.following.pop
1043
+ # --> action
1044
+ arg_cnt += 1
1045
+ # <-- action
1046
+ # at line 298:5: ( ( SEMICOLON | COMMA ) ( expr[arg_type] | ) )*
1047
+ loop do # decision 17
1048
+ alt_17 = 2
1049
+ look_17_0 = @input.peek(1)
1050
+
1051
+ if (look_17_0.between?(SEMICOLON, COMMA))
1052
+ alt_17 = 1
362
1053
 
363
-
364
- # 98:5: ( TRUE_CONST | FALSE_CONST | str_tok= STR_CONST | int_tok= INT_CONST | num_tok= NUM_CONST | ref2d_tok= REF2D | ref2d1_tok= REF2D COLON ref2d2_tok= REF2D )
365
- alt10 = 7
366
- alt10 = DFA10.predict(self, @input)
367
- case alt10
1054
+ end
1055
+ case alt_17
368
1056
  when 1
369
- # 98:7: TRUE_CONST
370
- match(:TRUE_CONST)
371
-
372
- @rpn += [PTGBOOL, 1].pack("C2")
373
-
374
- when 2
375
- # 102:7: FALSE_CONST
376
- match(:FALSE_CONST)
377
-
378
- @rpn += [PTGBOOL, 0].pack("C2")
379
-
380
- when 3
381
- # 106:7: str_tok= STR_CONST
382
- _str_tok = @input.look_ahead(1)
383
- match(:STR_CONST)
384
-
385
- @rpn += [PTGSTR].pack('C') + upack1(str_tok.text[1, -1]) #TODO
386
-
387
- when 4
388
- # 110:7: int_tok= INT_CONST
389
- _int_tok = @input.look_ahead(1)
390
- match(:INT_CONST)
391
-
392
- int_value = int_tok.text.to_i
393
- if int_value <= 65535
394
- @rpn += [PTGINT, int_value].pack("Cv")
395
- else
396
- @rpn += [PTGNUM, int_value.to_f].pack("CE")
397
- end
398
-
399
- when 5
400
- # 119:7: num_tok= NUM_CONST
401
- _num_tok = @input.look_ahead(1)
402
- match(:NUM_CONST)
1057
+ # at line 299:9: ( SEMICOLON | COMMA ) ( expr[arg_type] | )
1058
+ # --> action
1059
+
1060
+ if arg_cnt < arg_type_list.size
1061
+ arg_type = arg_type_list[arg_cnt]
1062
+ else
1063
+ arg_type = arg_type_list[-1]
1064
+ end
1065
+ if arg_type == "+"
1066
+ arg_type = arg_type_list[-2]
1067
+ end
1068
+
1069
+ # <-- action
1070
+ if @input.peek(1).between?(SEMICOLON, COMMA)
1071
+ @input.consume
1072
+ @state.error_recovery = false
1073
+ else
1074
+ mse = MismatchedSet(nil)
1075
+ raise mse
1076
+ end
1077
+
1078
+
1079
+ # at line 310:13: ( expr[arg_type] | )
1080
+ alt_16 = 2
1081
+ alt_16 = @dfa16.predict(@input)
1082
+ case alt_16
1083
+ when 1
1084
+ # at line 311:19: expr[arg_type]
1085
+ @state.following.push(TOKENS_FOLLOWING_expr_IN_expr_list_1611)
1086
+ expr(arg_type)
1087
+ @state.following.pop
1088
+
1089
+ when 2
1090
+ # at line 312:19:
1091
+ # --> action
1092
+ @rpn += [PTGMISSARG].pack("B")
1093
+ # <-- action
1094
+
1095
+ end
1096
+ # --> action
1097
+ arg_cnt += 1
1098
+ # <-- action
1099
+
1100
+ else
1101
+ break # out of loop for decision 17
1102
+ end
1103
+ end # loop for decision 17
403
1104
 
404
- @rpn += [ptgNum, num_tok.text.to_f].pack("CE")
405
-
406
- when 6
407
- # 123:7: ref2d_tok= REF2D
408
- _ref2d_tok = @input.look_ahead(1)
409
- match(:REF2D)
1105
+ when 2
1106
+ # at line 317:5:
410
1107
 
411
- r, c = Utils.cell_to_packed_rowcol(ref2d_tok.text) # TODO
412
- ptg = PTGREFR + RVA_DELTA[arg_type]
413
- @rpn += [ptg, r, c].pack("Cv2")
414
-
415
- when 7
416
- # 129:7: ref2d1_tok= REF2D COLON ref2d2_tok= REF2D
417
- _ref2d1_tok = @input.look_ahead(1)
418
- match(:REF2D)
419
- match(:COLON)
420
- _ref2d2_tok = @input.look_ahead(1)
421
- match(:REF2D)
422
-
423
- r1, c1 = Utils.cell_to_packed_rowcol(ref2d1_tok.text) #TODO
424
- r2, c2 = Utils.cell_to_packed_rowcol(ref2d2_tok.text) #TODO
425
- ptg = PTGAREAR + RVA_DELTA[arg_type]
426
- self.rpn += struct.pack("Cv4", ptg, r1, r2, c1, c2)
427
-
428
1108
  end
1109
+ rescue ANTLR3::Error::RecognitionError => re
1110
+ report_error(re)
1111
+ recover(re)
429
1112
 
1113
+ ensure
1114
+ # -> uncomment the next line to manually enable rule tracing
1115
+ # trace_out(__method__, 10)
430
1116
 
431
-
1117
+ end
1118
+
1119
+ return arg_cnt
432
1120
  end
433
1121
 
434
1122
 
435
- attr_accessor :rpn
436
-
437
-
438
- private
1123
+ # parser rule sheet
1124
+ #
1125
+ # (in ExcelFormula.g)
1126
+ # 319:1: sheet returns [ref] : (sheet_ref_name= NAME | sheet_ref_int= INT_CONST | sheet_ref_quote= QUOTENAME );
1127
+ def sheet
1128
+ # -> uncomment the next line to manually enable rule tracing
1129
+ # trace_in(__method__, 11)
1130
+ ref = nil
1131
+ sheet_ref_name = nil
1132
+ sheet_ref_int = nil
1133
+ sheet_ref_quote = nil
1134
+
1135
+ begin
1136
+ # at line 320:5: (sheet_ref_name= NAME | sheet_ref_int= INT_CONST | sheet_ref_quote= QUOTENAME )
1137
+ alt_19 = 3
1138
+ case look_19 = @input.peek(1)
1139
+ when NAME then alt_19 = 1
1140
+ when INT_CONST then alt_19 = 2
1141
+ when QUOTENAME then alt_19 = 3
1142
+ else
1143
+ nvae = NoViableAlternative("", 19, 0)
1144
+ raise nvae
1145
+ end
1146
+ case alt_19
1147
+ when 1
1148
+ # at line 320:7: sheet_ref_name= NAME
1149
+ sheet_ref_name = match(NAME, TOKENS_FOLLOWING_NAME_IN_sheet_1701)
1150
+ # --> action
1151
+ ref = sheet_ref_name.text
1152
+ # <-- action
1153
+
1154
+ when 2
1155
+ # at line 322:7: sheet_ref_int= INT_CONST
1156
+ sheet_ref_int = match(INT_CONST, TOKENS_FOLLOWING_INT_CONST_IN_sheet_1721)
1157
+ # --> action
1158
+ ref = sheet_ref_int.text
1159
+ # <-- action
1160
+
1161
+ when 3
1162
+ # at line 324:7: sheet_ref_quote= QUOTENAME
1163
+ sheet_ref_quote = match(QUOTENAME, TOKENS_FOLLOWING_QUOTENAME_IN_sheet_1741)
1164
+ # --> action
1165
+ ref = sheet_ref_quote.text[1, len(sheet_ref_quote.text) - 1].replace("''", "'")
1166
+ # <-- action
439
1167
 
440
- class TokenStream
441
- attr_reader :index
1168
+ end
1169
+ rescue ANTLR3::Error::RecognitionError => re
1170
+ report_error(re)
1171
+ recover(re)
442
1172
 
443
- def initialize(input)
444
- @buffer = []
445
- @input = input
446
- @channel = nil
1173
+ ensure
1174
+ # -> uncomment the next line to manually enable rule tracing
1175
+ # trace_out(__method__, 11)
447
1176
 
448
- @index = 0;
449
- end
1177
+ end
1178
+
1179
+ return ref
1180
+ end
450
1181
 
451
- # returns a Token
452
- def look_ahead(pos)
453
- offset = @index + pos - 1
454
1182
 
455
- while @buffer[-1] != :EOF && @buffer.length < offset + 1
456
- token = @input.next_token
457
- if token == :EOF || token.channel == @channel
458
- @buffer << token
459
- end
460
- end
461
1183
 
462
- offset = -1 if offset >= @buffer.length
463
- if offset < @buffer.length
464
- @buffer[offset]
465
- end
1184
+ # - - - - - - - - - - DFA definitions - - - - - - - - - - -
1185
+ class DFA2 < ANTLR3::DFA
1186
+ EOT = unpack(10, -1)
1187
+ EOF = unpack(1, 1, 9, -1)
1188
+ MIN = unpack(1, 4, 9, -1)
1189
+ MAX = unpack(1, 29, 9, -1)
1190
+ ACCEPT = unpack(1, -1, 1, 2, 2, -1, 1, 1, 5, -1)
1191
+ SPECIAL = unpack(10, -1)
1192
+ TRANSITION = [
1193
+ unpack(6, 4, 17, -1, 3, 1),
1194
+ unpack(),
1195
+ unpack(),
1196
+ unpack(),
1197
+ unpack(),
1198
+ unpack(),
1199
+ unpack(),
1200
+ unpack(),
1201
+ unpack(),
1202
+ unpack()
1203
+ ].freeze
1204
+
1205
+ ( 0 ... MIN.length ).zip( MIN, MAX ) do | i, a, z |
1206
+ if a > 0 and z < 0
1207
+ MAX[ i ] %= 0x10000
466
1208
  end
467
-
468
- def mark
469
- @state = { :index => @index }
470
- return 0
1209
+ end
1210
+
1211
+ @decision = 2
1212
+
1213
+
1214
+ def description
1215
+ <<-'__dfa_description__'.strip!
1216
+ ()* loopback of 30:9: ( ( EQ | NE | GT | LT | GE | LE ) prec0_expr[arg_type] )*
1217
+ __dfa_description__
1218
+ end
1219
+ end
1220
+ class DFA3 < ANTLR3::DFA
1221
+ EOT = unpack(11, -1)
1222
+ EOF = unpack(1, 1, 10, -1)
1223
+ MIN = unpack(1, 4, 10, -1)
1224
+ MAX = unpack(1, 29, 10, -1)
1225
+ ACCEPT = unpack(1, -1, 1, 2, 8, -1, 1, 1)
1226
+ SPECIAL = unpack(11, -1)
1227
+ TRANSITION = [
1228
+ unpack(6, 1, 1, 10, 16, -1, 3, 1),
1229
+ unpack(),
1230
+ unpack(),
1231
+ unpack(),
1232
+ unpack(),
1233
+ unpack(),
1234
+ unpack(),
1235
+ unpack(),
1236
+ unpack(),
1237
+ unpack(),
1238
+ unpack()
1239
+ ].freeze
1240
+
1241
+ ( 0 ... MIN.length ).zip( MIN, MAX ) do | i, a, z |
1242
+ if a > 0 and z < 0
1243
+ MAX[ i ] %= 0x10000
471
1244
  end
472
-
473
- def rewind(marker)
474
- @index = @state[:index]
1245
+ end
1246
+
1247
+ @decision = 3
1248
+
1249
+
1250
+ def description
1251
+ <<-'__dfa_description__'.strip!
1252
+ ()* loopback of 46:9: ( ( CONCAT ) prec1_expr[arg_type] )*
1253
+ __dfa_description__
1254
+ end
1255
+ end
1256
+ class DFA5 < ANTLR3::DFA
1257
+ EOT = unpack(13, -1)
1258
+ EOF = unpack(1, 1, 12, -1)
1259
+ MIN = unpack(1, 4, 12, -1)
1260
+ MAX = unpack(1, 29, 12, -1)
1261
+ ACCEPT = unpack(1, -1, 1, 2, 9, -1, 1, 1, 1, -1)
1262
+ SPECIAL = unpack(13, -1)
1263
+ TRANSITION = [
1264
+ unpack(7, 1, 2, 11, 14, -1, 3, 1),
1265
+ unpack(),
1266
+ unpack(),
1267
+ unpack(),
1268
+ unpack(),
1269
+ unpack(),
1270
+ unpack(),
1271
+ unpack(),
1272
+ unpack(),
1273
+ unpack(),
1274
+ unpack(),
1275
+ unpack(),
1276
+ unpack()
1277
+ ].freeze
1278
+
1279
+ ( 0 ... MIN.length ).zip( MIN, MAX ) do | i, a, z |
1280
+ if a > 0 and z < 0
1281
+ MAX[ i ] %= 0x10000
475
1282
  end
476
-
477
- def consume
478
- look_ahead(1) # force a read from the input if necessary
479
- @index = @index + 1
1283
+ end
1284
+
1285
+ @decision = 5
1286
+
1287
+
1288
+ def description
1289
+ <<-'__dfa_description__'.strip!
1290
+ ()* loopback of 56:9: ( ( ADD | SUB ) prec2_expr[arg_type] )*
1291
+ __dfa_description__
1292
+ end
1293
+ end
1294
+ class DFA7 < ANTLR3::DFA
1295
+ EOT = unpack(15, -1)
1296
+ EOF = unpack(1, 1, 14, -1)
1297
+ MIN = unpack(1, 4, 14, -1)
1298
+ MAX = unpack(1, 29, 14, -1)
1299
+ ACCEPT = unpack(1, -1, 1, 2, 11, -1, 1, 1, 1, -1)
1300
+ SPECIAL = unpack(15, -1)
1301
+ TRANSITION = [
1302
+ unpack(9, 1, 2, 13, 12, -1, 3, 1),
1303
+ unpack(),
1304
+ unpack(),
1305
+ unpack(),
1306
+ unpack(),
1307
+ unpack(),
1308
+ unpack(),
1309
+ unpack(),
1310
+ unpack(),
1311
+ unpack(),
1312
+ unpack(),
1313
+ unpack(),
1314
+ unpack(),
1315
+ unpack(),
1316
+ unpack()
1317
+ ].freeze
1318
+
1319
+ ( 0 ... MIN.length ).zip( MIN, MAX ) do | i, a, z |
1320
+ if a > 0 and z < 0
1321
+ MAX[ i ] %= 0x10000
480
1322
  end
1323
+ end
1324
+
1325
+ @decision = 7
1326
+
1327
+
1328
+ def description
1329
+ <<-'__dfa_description__'.strip!
1330
+ ()* loopback of 68:9: ( ( MUL | DIV ) prec3_expr[arg_type] )*
1331
+ __dfa_description__
1332
+ end
481
1333
  end
482
-
483
- def match(token = nil)
484
- if token.nil? || look_ahead(1) == token
485
- @input.consume
486
- @failed = false
487
- return
488
- elsif @backtracking > 0
489
- @failed = true
490
- else
491
- raise "Expected #{token}"
1334
+ class DFA8 < ANTLR3::DFA
1335
+ EOT = unpack(16, -1)
1336
+ EOF = unpack(1, 1, 15, -1)
1337
+ MIN = unpack(1, 4, 15, -1)
1338
+ MAX = unpack(1, 29, 15, -1)
1339
+ ACCEPT = unpack(1, -1, 1, 2, 13, -1, 1, 1)
1340
+ SPECIAL = unpack(16, -1)
1341
+ TRANSITION = [
1342
+ unpack(11, 1, 1, 15, 11, -1, 3, 1),
1343
+ unpack(),
1344
+ unpack(),
1345
+ unpack(),
1346
+ unpack(),
1347
+ unpack(),
1348
+ unpack(),
1349
+ unpack(),
1350
+ unpack(),
1351
+ unpack(),
1352
+ unpack(),
1353
+ unpack(),
1354
+ unpack(),
1355
+ unpack(),
1356
+ unpack(),
1357
+ unpack()
1358
+ ].freeze
1359
+
1360
+ ( 0 ... MIN.length ).zip( MIN, MAX ) do | i, a, z |
1361
+ if a > 0 and z < 0
1362
+ MAX[ i ] %= 0x10000
492
1363
  end
1364
+ end
1365
+
1366
+ @decision = 8
1367
+
1368
+
1369
+ def description
1370
+ <<-'__dfa_description__'.strip!
1371
+ ()* loopback of 79:9: ( ( POWER ) prec5_expr[arg_type] )*
1372
+ __dfa_description__
1373
+ end
493
1374
  end
494
-
495
- def look_ahead(k)
496
- token = @input.look_ahead(k)
497
- if token != :EOF
498
- token = token.token_type
1375
+ class DFA10 < ANTLR3::DFA
1376
+ EOT = unpack(13, -1)
1377
+ EOF = unpack(13, -1)
1378
+ MIN = unpack(1, 12, 12, -1)
1379
+ MAX = unpack(1, 32, 12, -1)
1380
+ ACCEPT = unpack(1, -1, 1, 1, 10, -1, 1, 2)
1381
+ SPECIAL = unpack(13, -1)
1382
+ TRANSITION = [
1383
+ unpack(1, 12, 4, -1, 6, 1, 2, -1, 2, 1, 3, -1, 3, 1),
1384
+ unpack(),
1385
+ unpack(),
1386
+ unpack(),
1387
+ unpack(),
1388
+ unpack(),
1389
+ unpack(),
1390
+ unpack(),
1391
+ unpack(),
1392
+ unpack(),
1393
+ unpack(),
1394
+ unpack(),
1395
+ unpack()
1396
+ ].freeze
1397
+
1398
+ ( 0 ... MIN.length ).zip( MIN, MAX ) do | i, a, z |
1399
+ if a > 0 and z < 0
1400
+ MAX[ i ] %= 0x10000
499
1401
  end
500
-
501
- token
1402
+ end
1403
+
1404
+ @decision = 10
1405
+
1406
+
1407
+ def description
1408
+ <<-'__dfa_description__'.strip!
1409
+ 94:1: prec5_expr[arg_type] : ( primary[arg_type] | SUB primary[arg_type] );
1410
+ __dfa_description__
1411
+ end
1412
+ end
1413
+ class DFA15 < ANTLR3::DFA
1414
+ EOT = unpack(66, -1)
1415
+ EOF = unpack(4, -1, 1, 12, 1, -1, 1, 31, 1, 48, 58, -1)
1416
+ MIN = unpack(1, 17, 3, -1, 1, 4, 1, -1, 2, 4, 58, -1)
1417
+ MAX = unpack(1, 32, 3, -1, 1, 29, 1, -1, 2, 29, 58, -1)
1418
+ ACCEPT = unpack(1, -1, 1, 1, 1, 2, 1, 3, 1, -1, 1, 5, 2, -1, 1, 8,
1419
+ 1, 9, 1, 10, 1, 13, 1, 4, 17, -1, 1, 7, 1, 6, 15,
1420
+ -1, 1, 12, 1, 11, 17, -1)
1421
+ SPECIAL = unpack(66, -1)
1422
+ TRANSITION = [
1423
+ unpack(1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 2, -1, 1, 9, 1, 11, 3,
1424
+ -1, 1, 10, 1, 7, 1, 8),
1425
+ unpack(),
1426
+ unpack(),
1427
+ unpack(),
1428
+ unpack(13, 12, 6, -1, 2, 8, 2, -1, 3, 12),
1429
+ unpack(),
1430
+ unpack(13, 31, 6, -1, 1, 30, 3, -1, 3, 31),
1431
+ unpack(13, 48, 6, -1, 2, 8, 1, -1, 1, 47, 3, 48),
1432
+ unpack(),
1433
+ unpack(),
1434
+ unpack(),
1435
+ unpack(),
1436
+ unpack(),
1437
+ unpack(),
1438
+ unpack(),
1439
+ unpack(),
1440
+ unpack(),
1441
+ unpack(),
1442
+ unpack(),
1443
+ unpack(),
1444
+ unpack(),
1445
+ unpack(),
1446
+ unpack(),
1447
+ unpack(),
1448
+ unpack(),
1449
+ unpack(),
1450
+ unpack(),
1451
+ unpack(),
1452
+ unpack(),
1453
+ unpack(),
1454
+ unpack(),
1455
+ unpack(),
1456
+ unpack(),
1457
+ unpack(),
1458
+ unpack(),
1459
+ unpack(),
1460
+ unpack(),
1461
+ unpack(),
1462
+ unpack(),
1463
+ unpack(),
1464
+ unpack(),
1465
+ unpack(),
1466
+ unpack(),
1467
+ unpack(),
1468
+ unpack(),
1469
+ unpack(),
1470
+ unpack(),
1471
+ unpack(),
1472
+ unpack(),
1473
+ unpack(),
1474
+ unpack(),
1475
+ unpack(),
1476
+ unpack(),
1477
+ unpack(),
1478
+ unpack(),
1479
+ unpack(),
1480
+ unpack(),
1481
+ unpack(),
1482
+ unpack(),
1483
+ unpack(),
1484
+ unpack(),
1485
+ unpack(),
1486
+ unpack(),
1487
+ unpack(),
1488
+ unpack(),
1489
+ unpack()
1490
+ ].freeze
1491
+
1492
+ ( 0 ... MIN.length ).zip( MIN, MAX ) do | i, a, z |
1493
+ if a > 0 and z < 0
1494
+ MAX[ i ] %= 0x10000
1495
+ end
1496
+ end
1497
+
1498
+ @decision = 15
1499
+
1500
+
1501
+ def description
1502
+ <<-'__dfa_description__'.strip!
1503
+ 99:1: primary[arg_type] : ( TRUE_CONST | FALSE_CONST | str_tok= STR_CONST | int_tok= INT_CONST | num_tok= NUM_CONST | ref2d_tok= REF2D | ref2d1_tok= REF2D COLON ref2d2_tok= REF2D | sheet1= sheet ( COLON sheet2= sheet )? BANG ref3d_ref2d= REF2D ( COLON ref3d_ref2d2= REF2D )? | FUNC_IF LP expr[\"V\"] ( SEMICOLON | COMMA ) expr[arg_type] ( SEMICOLON | COMMA ) expr[arg_type] RP | FUNC_CHOOSE LP expr[\"V\"] ( ( SEMICOLON | COMMA ) ( expr[arg_type] | ) )* RP | name_tok= NAME | func_tok= NAME LP arg_count= expr_list[arg_type_list, min_argc, max_argc] RP | LP expr[arg_type] RP );
1504
+ __dfa_description__
1505
+ end
1506
+ end
1507
+ class DFA12 < ANTLR3::DFA
1508
+ EOT = unpack(18, -1)
1509
+ EOF = unpack(1, 2, 17, -1)
1510
+ MIN = unpack(1, 4, 17, -1)
1511
+ MAX = unpack(1, 29, 17, -1)
1512
+ ACCEPT = unpack(1, -1, 1, 1, 1, 2, 15, -1)
1513
+ SPECIAL = unpack(18, -1)
1514
+ TRANSITION = [
1515
+ unpack(13, 2, 6, -1, 1, 1, 3, -1, 3, 2),
1516
+ unpack(),
1517
+ unpack(),
1518
+ unpack(),
1519
+ unpack(),
1520
+ unpack(),
1521
+ unpack(),
1522
+ unpack(),
1523
+ unpack(),
1524
+ unpack(),
1525
+ unpack(),
1526
+ unpack(),
1527
+ unpack(),
1528
+ unpack(),
1529
+ unpack(),
1530
+ unpack(),
1531
+ unpack(),
1532
+ unpack()
1533
+ ].freeze
1534
+
1535
+ ( 0 ... MIN.length ).zip( MIN, MAX ) do | i, a, z |
1536
+ if a > 0 and z < 0
1537
+ MAX[ i ] %= 0x10000
1538
+ end
1539
+ end
1540
+
1541
+ @decision = 12
1542
+
1543
+
1544
+ def description
1545
+ <<-'__dfa_description__'.strip!
1546
+ 151:9: ( COLON ref3d_ref2d2= REF2D )?
1547
+ __dfa_description__
1548
+ end
502
1549
  end
1550
+ class DFA13 < ANTLR3::DFA
1551
+ EOT = unpack(15, -1)
1552
+ EOF = unpack(15, -1)
1553
+ MIN = unpack(1, 12, 14, -1)
1554
+ MAX = unpack(1, 32, 14, -1)
1555
+ ACCEPT = unpack(1, -1, 1, 1, 11, -1, 1, 2, 1, -1)
1556
+ SPECIAL = unpack(15, -1)
1557
+ TRANSITION = [
1558
+ unpack(1, 1, 4, -1, 6, 1, 2, -1, 2, 1, 3, 13, 3, 1),
1559
+ unpack(),
1560
+ unpack(),
1561
+ unpack(),
1562
+ unpack(),
1563
+ unpack(),
1564
+ unpack(),
1565
+ unpack(),
1566
+ unpack(),
1567
+ unpack(),
1568
+ unpack(),
1569
+ unpack(),
1570
+ unpack(),
1571
+ unpack(),
1572
+ unpack()
1573
+ ].freeze
1574
+
1575
+ ( 0 ... MIN.length ).zip( MIN, MAX ) do | i, a, z |
1576
+ if a > 0 and z < 0
1577
+ MAX[ i ] %= 0x10000
1578
+ end
1579
+ end
1580
+
1581
+ @decision = 13
1582
+
1583
+
1584
+ def description
1585
+ <<-'__dfa_description__'.strip!
1586
+ 199:17: ( expr[arg_type] | )
1587
+ __dfa_description__
1588
+ end
1589
+ end
1590
+ class DFA18 < ANTLR3::DFA
1591
+ EOT = unpack(14, -1)
1592
+ EOF = unpack(14, -1)
1593
+ MIN = unpack(1, 12, 13, -1)
1594
+ MAX = unpack(1, 32, 13, -1)
1595
+ ACCEPT = unpack(1, -1, 1, 1, 11, -1, 1, 2)
1596
+ SPECIAL = unpack(14, -1)
1597
+ TRANSITION = [
1598
+ unpack(1, 1, 4, -1, 6, 1, 2, -1, 2, 1, 2, -1, 1, 13, 3, 1),
1599
+ unpack(),
1600
+ unpack(),
1601
+ unpack(),
1602
+ unpack(),
1603
+ unpack(),
1604
+ unpack(),
1605
+ unpack(),
1606
+ unpack(),
1607
+ unpack(),
1608
+ unpack(),
1609
+ unpack(),
1610
+ unpack(),
1611
+ unpack()
1612
+ ].freeze
1613
+
1614
+ ( 0 ... MIN.length ).zip( MIN, MAX ) do | i, a, z |
1615
+ if a > 0 and z < 0
1616
+ MAX[ i ] %= 0x10000
1617
+ end
1618
+ end
1619
+
1620
+ @decision = 18
1621
+
1622
+
1623
+ def description
1624
+ <<-'__dfa_description__'.strip!
1625
+ 292:1: expr_list[arg_type_list, min_argc, max_argc] returns [arg_cnt] : ( expr[arg_type] ( ( SEMICOLON | COMMA ) ( expr[arg_type] | ) )* | );
1626
+ __dfa_description__
1627
+ end
1628
+ end
1629
+ class DFA16 < ANTLR3::DFA
1630
+ EOT = unpack(15, -1)
1631
+ EOF = unpack(15, -1)
1632
+ MIN = unpack(1, 12, 14, -1)
1633
+ MAX = unpack(1, 32, 14, -1)
1634
+ ACCEPT = unpack(1, -1, 1, 1, 11, -1, 1, 2, 1, -1)
1635
+ SPECIAL = unpack(15, -1)
1636
+ TRANSITION = [
1637
+ unpack(1, 1, 4, -1, 6, 1, 2, -1, 2, 1, 3, 13, 3, 1),
1638
+ unpack(),
1639
+ unpack(),
1640
+ unpack(),
1641
+ unpack(),
1642
+ unpack(),
1643
+ unpack(),
1644
+ unpack(),
1645
+ unpack(),
1646
+ unpack(),
1647
+ unpack(),
1648
+ unpack(),
1649
+ unpack(),
1650
+ unpack(),
1651
+ unpack()
1652
+ ].freeze
1653
+
1654
+ ( 0 ... MIN.length ).zip( MIN, MAX ) do | i, a, z |
1655
+ if a > 0 and z < 0
1656
+ MAX[ i ] %= 0x10000
1657
+ end
1658
+ end
1659
+
1660
+ @decision = 16
1661
+
1662
+
1663
+ def description
1664
+ <<-'__dfa_description__'.strip!
1665
+ 310:13: ( expr[arg_type] | )
1666
+ __dfa_description__
1667
+ end
1668
+ end
1669
+
1670
+
1671
+ private
503
1672
 
1673
+ def initialize_dfas
1674
+ super rescue nil
1675
+ @dfa2 = DFA2.new(self, 2)
1676
+ @dfa3 = DFA3.new(self, 3)
1677
+ @dfa5 = DFA5.new(self, 5)
1678
+ @dfa7 = DFA7.new(self, 7)
1679
+ @dfa8 = DFA8.new(self, 8)
1680
+ @dfa10 = DFA10.new(self, 10)
1681
+ @dfa15 = DFA15.new(self, 15)
1682
+ @dfa12 = DFA12.new(self, 12)
1683
+ @dfa13 = DFA13.new(self, 13)
1684
+ @dfa18 = DFA18.new(self, 18)
1685
+ @dfa16 = DFA16.new(self, 16)
504
1686
 
505
- class DFA
506
- def initialize(eot, eof, min, max, accept, special, transition)
507
- @eot = eot
508
- @eof = eof
509
- @min = min
510
- @max = max
511
- @accept = accept
512
- @special = special
513
- @transition = transition
514
- end
515
-
516
- def predict(parser, input)
517
- mark = input.mark()
518
- s = 0 # we always start at s0
519
- begin
520
- loop do
521
- special_state = @special[s]
522
- if special_state >= 0
523
- s = parser.special_state_transition(special_state)
524
- input.consume()
525
- next
526
- end
527
-
528
- if @accept[s] >= 1
529
- return @accept[s]
530
- end
531
-
532
- # look for a normal char transition
533
- c = input.look_ahead(1).to_i
534
- if c != :EOF && c >= @min[s] && c <= @max[s]
535
- next_state = @transition[s][c - @min[s]] # move to next state
536
- if next_state < 0
537
- # was in range but not a normal transition
538
- # must check EOT, which is like the else clause.
539
- # eot[s]>=0 indicates that an EOT edge goes to another
540
- # state.
541
- if @eot[s] >= 0 # EOT Transition to accept state?
542
- s = @eot[s]
543
- input.consume()
544
- next
545
- end
546
- raise "No viable alt"
547
- end
548
- s = next_state
549
- input.consume()
550
- next
551
- end
552
- if @eot[s] >= 0 # EOT Transition?
553
- s = @eot[s]
554
- input.consume()
555
- next
556
- end
557
- if c == :EOF && @eof[s] >= 0 # EOF Transition to accept state?
558
- return @accept[@eof[s]]
559
- end
560
-
561
- # not in range and not EOF/EOT, must be invalid symbol
562
- raise "No viable alt"
563
- end
564
- ensure
565
- input.rewind(mark)
566
- end
567
- end
568
- end
569
-
570
- DFA10 = DFA.new(
571
- [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
572
- [-1,-1,-1,-1,-1,-1,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
573
- [12,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0],
574
- [17,0,0,0,0,0,18,0,0,0,0,0,0,0,0,0,0],
575
- [-1,1,2,3,4,5,-1,7,6,-1,-1,-1,-1,-1,-1,-1,-1],
576
- [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
577
- [
578
- [1,2,3,4,5,6],
579
- [],
580
- [],
581
- [],
582
- [],
583
- [],
584
- [8,8,8,8,8,8,8,8,-1,-1,-1,-1,-1,-1,7],
585
- [],
586
- [],
587
- [],
588
- [],
589
- [],
590
- [],
591
- [],
592
- [],
593
- [],
594
- []
595
- ])
596
-
597
- def special_state_transition(s)
598
- -1
599
1687
  end
1688
+ TOKENS_FOLLOWING_expr_IN_formula_60 = Set[1]
1689
+ TOKENS_FOLLOWING_prec0_expr_IN_expr_79 = Set[1, 4, 5, 6, 7, 8, 9]
1690
+ TOKENS_FOLLOWING_EQ_IN_expr_124 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1691
+ TOKENS_FOLLOWING_NE_IN_expr_146 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1692
+ TOKENS_FOLLOWING_GT_IN_expr_168 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1693
+ TOKENS_FOLLOWING_LT_IN_expr_190 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1694
+ TOKENS_FOLLOWING_GE_IN_expr_212 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1695
+ TOKENS_FOLLOWING_LE_IN_expr_234 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1696
+ TOKENS_FOLLOWING_prec0_expr_IN_expr_265 = Set[1, 4, 5, 6, 7, 8, 9]
1697
+ TOKENS_FOLLOWING_prec1_expr_IN_prec0_expr_297 = Set[1, 10]
1698
+ TOKENS_FOLLOWING_CONCAT_IN_prec0_expr_340 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1699
+ TOKENS_FOLLOWING_prec1_expr_IN_prec0_expr_370 = Set[1, 10]
1700
+ TOKENS_FOLLOWING_prec2_expr_IN_prec1_expr_402 = Set[1, 11, 12]
1701
+ TOKENS_FOLLOWING_ADD_IN_prec1_expr_447 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1702
+ TOKENS_FOLLOWING_SUB_IN_prec1_expr_469 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1703
+ TOKENS_FOLLOWING_prec2_expr_IN_prec1_expr_499 = Set[1, 11, 12]
1704
+ TOKENS_FOLLOWING_prec3_expr_IN_prec2_expr_532 = Set[1, 13, 14]
1705
+ TOKENS_FOLLOWING_MUL_IN_prec2_expr_577 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1706
+ TOKENS_FOLLOWING_DIV_IN_prec2_expr_599 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1707
+ TOKENS_FOLLOWING_prec3_expr_IN_prec2_expr_629 = Set[1, 13, 14]
1708
+ TOKENS_FOLLOWING_prec5_expr_IN_prec3_expr_661 = Set[1, 15]
1709
+ TOKENS_FOLLOWING_POWER_IN_prec3_expr_704 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1710
+ TOKENS_FOLLOWING_prec5_expr_IN_prec3_expr_734 = Set[1, 15]
1711
+ TOKENS_FOLLOWING_prec5_expr_IN_prec4_expr_766 = Set[1, 16]
1712
+ TOKENS_FOLLOWING_PERCENT_IN_prec4_expr_791 = Set[1]
1713
+ TOKENS_FOLLOWING_primary_IN_prec5_expr_822 = Set[1]
1714
+ TOKENS_FOLLOWING_SUB_IN_prec5_expr_831 = Set[17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1715
+ TOKENS_FOLLOWING_primary_IN_prec5_expr_833 = Set[1]
1716
+ TOKENS_FOLLOWING_TRUE_CONST_IN_primary_854 = Set[1]
1717
+ TOKENS_FOLLOWING_FALSE_CONST_IN_primary_872 = Set[1]
1718
+ TOKENS_FOLLOWING_STR_CONST_IN_primary_894 = Set[1]
1719
+ TOKENS_FOLLOWING_INT_CONST_IN_primary_916 = Set[1]
1720
+ TOKENS_FOLLOWING_NUM_CONST_IN_primary_934 = Set[1]
1721
+ TOKENS_FOLLOWING_REF2D_IN_primary_956 = Set[1]
1722
+ TOKENS_FOLLOWING_REF2D_IN_primary_978 = Set[23]
1723
+ TOKENS_FOLLOWING_COLON_IN_primary_980 = Set[22]
1724
+ TOKENS_FOLLOWING_REF2D_IN_primary_986 = Set[1]
1725
+ TOKENS_FOLLOWING_sheet_IN_primary_1010 = Set[23, 24]
1726
+ TOKENS_FOLLOWING_COLON_IN_primary_1032 = Set[20, 31, 32]
1727
+ TOKENS_FOLLOWING_sheet_IN_primary_1038 = Set[24]
1728
+ TOKENS_FOLLOWING_BANG_IN_primary_1043 = Set[22]
1729
+ TOKENS_FOLLOWING_REF2D_IN_primary_1047 = Set[1, 23]
1730
+ TOKENS_FOLLOWING_COLON_IN_primary_1069 = Set[22]
1731
+ TOKENS_FOLLOWING_REF2D_IN_primary_1074 = Set[1]
1732
+ TOKENS_FOLLOWING_FUNC_IF_IN_primary_1117 = Set[26]
1733
+ TOKENS_FOLLOWING_LP_IN_primary_1127 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1734
+ TOKENS_FOLLOWING_expr_IN_primary_1129 = Set[27, 28]
1735
+ TOKENS_FOLLOWING_set_IN_primary_1132 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1736
+ TOKENS_FOLLOWING_expr_IN_primary_1158 = Set[27, 28]
1737
+ TOKENS_FOLLOWING_set_IN_primary_1161 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1738
+ TOKENS_FOLLOWING_expr_IN_primary_1187 = Set[29]
1739
+ TOKENS_FOLLOWING_RP_IN_primary_1190 = Set[1]
1740
+ TOKENS_FOLLOWING_FUNC_CHOOSE_IN_primary_1208 = Set[26]
1741
+ TOKENS_FOLLOWING_LP_IN_primary_1228 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1742
+ TOKENS_FOLLOWING_expr_IN_primary_1230 = Set[27, 28, 29]
1743
+ TOKENS_FOLLOWING_set_IN_primary_1265 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 27, 28, 29, 30, 31, 32]
1744
+ TOKENS_FOLLOWING_expr_IN_primary_1327 = Set[27, 28, 29]
1745
+ TOKENS_FOLLOWING_RP_IN_primary_1405 = Set[1]
1746
+ TOKENS_FOLLOWING_NAME_IN_primary_1427 = Set[1]
1747
+ TOKENS_FOLLOWING_NAME_IN_primary_1449 = Set[26]
1748
+ TOKENS_FOLLOWING_LP_IN_primary_1469 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 29, 30, 31, 32]
1749
+ TOKENS_FOLLOWING_expr_list_IN_primary_1475 = Set[29]
1750
+ TOKENS_FOLLOWING_RP_IN_primary_1478 = Set[1]
1751
+ TOKENS_FOLLOWING_LP_IN_primary_1496 = Set[12, 17, 18, 19, 20, 21, 22, 25, 26, 30, 31, 32]
1752
+ TOKENS_FOLLOWING_expr_IN_primary_1498 = Set[29]
1753
+ TOKENS_FOLLOWING_RP_IN_primary_1501 = Set[1]
1754
+ TOKENS_FOLLOWING_expr_IN_expr_list_1542 = Set[1, 27, 28]
1755
+ TOKENS_FOLLOWING_set_IN_expr_list_1571 = Set[1, 12, 17, 18, 19, 20, 21, 22, 25, 26, 27, 28, 30, 31, 32]
1756
+ TOKENS_FOLLOWING_expr_IN_expr_list_1611 = Set[1, 27, 28]
1757
+ TOKENS_FOLLOWING_NAME_IN_sheet_1701 = Set[1]
1758
+ TOKENS_FOLLOWING_INT_CONST_IN_sheet_1721 = Set[1]
1759
+ TOKENS_FOLLOWING_QUOTENAME_IN_sheet_1741 = Set[1]
1760
+
1761
+ end # class Parser < ANTLR3::Parser
1762
+
1763
+ at_exit { Parser.main(ARGV) } if __FILE__ == $0
1764
+ end
600
1765
 
601
- public :special_state_transition
602
- end