csv_plus_plus 0.1.0 → 0.1.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -1
- data/README.md +18 -62
- data/lib/csv_plus_plus/benchmarked_compiler.rb +62 -0
- data/lib/csv_plus_plus/can_define_references.rb +88 -0
- data/lib/csv_plus_plus/can_resolve_references.rb +8 -0
- data/lib/csv_plus_plus/cell.rb +3 -3
- data/lib/csv_plus_plus/cli.rb +24 -7
- data/lib/csv_plus_plus/color.rb +12 -6
- data/lib/csv_plus_plus/compiler.rb +156 -0
- data/lib/csv_plus_plus/data_validation.rb +138 -0
- data/lib/csv_plus_plus/{language → entities}/ast_builder.rb +5 -7
- data/lib/csv_plus_plus/entities/boolean.rb +31 -0
- data/lib/csv_plus_plus/{language → entities}/builtins.rb +2 -4
- data/lib/csv_plus_plus/entities/cell_reference.rb +60 -0
- data/lib/csv_plus_plus/entities/date.rb +30 -0
- data/lib/csv_plus_plus/entities/entity.rb +84 -0
- data/lib/csv_plus_plus/entities/function.rb +33 -0
- data/lib/csv_plus_plus/entities/function_call.rb +35 -0
- data/lib/csv_plus_plus/entities/number.rb +34 -0
- data/lib/csv_plus_plus/entities/runtime_value.rb +26 -0
- data/lib/csv_plus_plus/entities/string.rb +29 -0
- data/lib/csv_plus_plus/entities/variable.rb +25 -0
- data/lib/csv_plus_plus/entities.rb +33 -0
- data/lib/csv_plus_plus/error/error.rb +10 -0
- data/lib/csv_plus_plus/error/formula_syntax_error.rb +36 -0
- data/lib/csv_plus_plus/error/modifier_syntax_error.rb +27 -0
- data/lib/csv_plus_plus/error/modifier_validation_error.rb +49 -0
- data/lib/csv_plus_plus/{language → error}/syntax_error.rb +6 -14
- data/lib/csv_plus_plus/error/writer_error.rb +9 -0
- data/lib/csv_plus_plus/error.rb +9 -2
- data/lib/csv_plus_plus/expand.rb +3 -1
- data/lib/csv_plus_plus/google_api_client.rb +4 -0
- data/lib/csv_plus_plus/lexer/lexer.rb +19 -11
- data/lib/csv_plus_plus/modifier/conditional_formatting.rb +17 -0
- data/lib/csv_plus_plus/modifier.rb +73 -70
- data/lib/csv_plus_plus/options.rb +3 -0
- data/lib/csv_plus_plus/parser/cell_value.tab.rb +305 -0
- data/lib/csv_plus_plus/parser/code_section.tab.rb +410 -0
- data/lib/csv_plus_plus/parser/modifier.tab.rb +484 -0
- data/lib/csv_plus_plus/references.rb +68 -0
- data/lib/csv_plus_plus/row.rb +0 -3
- data/lib/csv_plus_plus/runtime.rb +199 -0
- data/lib/csv_plus_plus/scope.rb +196 -0
- data/lib/csv_plus_plus/template.rb +21 -5
- data/lib/csv_plus_plus/validated_modifier.rb +164 -0
- data/lib/csv_plus_plus/version.rb +1 -1
- data/lib/csv_plus_plus/writer/file_backer_upper.rb +6 -4
- data/lib/csv_plus_plus/writer/google_sheet_builder.rb +24 -29
- data/lib/csv_plus_plus/writer/google_sheet_modifier.rb +33 -12
- data/lib/csv_plus_plus/writer/rubyxl_builder.rb +3 -6
- data/lib/csv_plus_plus.rb +41 -16
- metadata +34 -24
- data/lib/csv_plus_plus/code_section.rb +0 -68
- data/lib/csv_plus_plus/language/benchmarked_compiler.rb +0 -65
- data/lib/csv_plus_plus/language/cell_value.tab.rb +0 -332
- data/lib/csv_plus_plus/language/code_section.tab.rb +0 -442
- data/lib/csv_plus_plus/language/compiler.rb +0 -157
- data/lib/csv_plus_plus/language/entities/boolean.rb +0 -33
- data/lib/csv_plus_plus/language/entities/cell_reference.rb +0 -33
- data/lib/csv_plus_plus/language/entities/entity.rb +0 -86
- data/lib/csv_plus_plus/language/entities/function.rb +0 -35
- data/lib/csv_plus_plus/language/entities/function_call.rb +0 -26
- data/lib/csv_plus_plus/language/entities/number.rb +0 -36
- data/lib/csv_plus_plus/language/entities/runtime_value.rb +0 -28
- data/lib/csv_plus_plus/language/entities/string.rb +0 -31
- data/lib/csv_plus_plus/language/entities/variable.rb +0 -25
- data/lib/csv_plus_plus/language/entities.rb +0 -28
- data/lib/csv_plus_plus/language/references.rb +0 -70
- data/lib/csv_plus_plus/language/runtime.rb +0 -205
- data/lib/csv_plus_plus/language/scope.rb +0 -188
- data/lib/csv_plus_plus/modifier.tab.rb +0 -907
@@ -0,0 +1,484 @@
|
|
1
|
+
#
|
2
|
+
# DO NOT MODIFY!!!!
|
3
|
+
# This file is automatically generated by Racc 1.6.2
|
4
|
+
# from Racc grammar file "".
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'racc/parser.rb'
|
8
|
+
|
9
|
+
|
10
|
+
require_relative '../expand'
|
11
|
+
require_relative '../lexer'
|
12
|
+
|
13
|
+
module CSVPlusPlus
|
14
|
+
module Parser
|
15
|
+
class Modifier < Racc::Parser
|
16
|
+
|
17
|
+
module_eval(<<'...end modifier.y/module_eval...', 'modifier.y', 61)
|
18
|
+
attr_reader :return_value
|
19
|
+
|
20
|
+
include ::CSVPlusPlus::Lexer
|
21
|
+
|
22
|
+
# @param cell_modifier [Modifier]
|
23
|
+
# @param row_modifier [Modifier]
|
24
|
+
# @param scope [Scope]
|
25
|
+
def initialize(cell_modifier:, row_modifier:, scope:)
|
26
|
+
super()
|
27
|
+
|
28
|
+
@parsing_row = false
|
29
|
+
@cell_modifier = cell_modifier
|
30
|
+
@row_modifier = row_modifier
|
31
|
+
@scope = scope
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def anything_to_parse?(input)
|
37
|
+
@modifiers_to_parse = input.scan(/!?\[\[/).count
|
38
|
+
|
39
|
+
if @modifiers_to_parse == 0
|
40
|
+
assign_defaults!
|
41
|
+
@return_value = input
|
42
|
+
end
|
43
|
+
|
44
|
+
@modifiers_to_parse > 0
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse_subject
|
48
|
+
'modifier'
|
49
|
+
end
|
50
|
+
|
51
|
+
def tokenizer
|
52
|
+
::CSVPlusPlus::Lexer::Tokenizer.new(
|
53
|
+
ignore: /\s+/,
|
54
|
+
stop_fn: lambda do |scanner|
|
55
|
+
return false unless scanner.scan(/\]\]/)
|
56
|
+
|
57
|
+
@tokens << [:END_MODIFIERS, scanner.matched]
|
58
|
+
@return_value = scanner.rest
|
59
|
+
|
60
|
+
@modifiers_to_parse -= 1
|
61
|
+
@modifiers_to_parse == 0
|
62
|
+
end,
|
63
|
+
tokens: [
|
64
|
+
[/\bborder\b/, 'border'],
|
65
|
+
[/\bbordercolor\b/, 'bordercolor'],
|
66
|
+
[/\bborderstyle\b/, 'borderstyle'],
|
67
|
+
[/\bcolor\b/, 'color'],
|
68
|
+
[/\bexpand\b/, 'expand'],
|
69
|
+
[/\bfontcolor\b/, 'fontcolor'],
|
70
|
+
[/\bfontfamily\b/, 'fontfamily'],
|
71
|
+
[/\bfontsize\b/, 'fontsize'],
|
72
|
+
[/\bformat\b/, 'format'],
|
73
|
+
[/\bfreeze\b/, 'freeze'],
|
74
|
+
[/\bhalign\b/, 'halign'],
|
75
|
+
[/\bnote\b/, 'note'],
|
76
|
+
[/\bnumberformat\b/, 'numberformat'],
|
77
|
+
[/\bvalidate\b/, 'validate'],
|
78
|
+
[/\bvalign\b/, 'valign'],
|
79
|
+
[/\bvar\b/, 'var'],
|
80
|
+
[/-?[\d.]+/, :NUMBER],
|
81
|
+
TOKEN_LIBRARY[:HEX_COLOR],
|
82
|
+
[
|
83
|
+
/
|
84
|
+
(?:
|
85
|
+
[\w,_:-] # something that accepts most basic input if it doesn't need to be quoted
|
86
|
+
[\w\s,_:-]+ # same thing but allow spaces in the middle
|
87
|
+
[\w,_:-] # no spaces at the end
|
88
|
+
)
|
89
|
+
| # - or -
|
90
|
+
(?:
|
91
|
+
'([^'\\]|\\.)*') # allow for a single-quoted string which can accept any input and also allow
|
92
|
+
# for escaping via backslash (i.e., 'ain\\'t won\\'t something' is valid)
|
93
|
+
/x,
|
94
|
+
:RIGHT_SIDE,
|
95
|
+
],
|
96
|
+
[/\[\[/, :START_CELL_MODIFIERS],
|
97
|
+
[/!\[\[/, :START_ROW_MODIFIERS],
|
98
|
+
[/\//, :MODIFIER_SEPARATOR],
|
99
|
+
[/=/, :EQ],
|
100
|
+
],
|
101
|
+
alter_matches: {
|
102
|
+
STRING: ->(s) { s.gsub(/^'|'$/, '') }
|
103
|
+
},
|
104
|
+
)
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def assign_defaults!
|
110
|
+
@cell_modifier.take_defaults_from!(@row_modifier)
|
111
|
+
end
|
112
|
+
|
113
|
+
def parsing_row!
|
114
|
+
@parsing_row = true
|
115
|
+
end
|
116
|
+
|
117
|
+
def finished_row!
|
118
|
+
parsing_cell!
|
119
|
+
end
|
120
|
+
|
121
|
+
def parsing_cell!
|
122
|
+
@parsing_row = false
|
123
|
+
assign_defaults!
|
124
|
+
end
|
125
|
+
|
126
|
+
def define_var(var_id)
|
127
|
+
@scope.bind_variable_to_cell(var_id)
|
128
|
+
modifier.var = var_id.to_sym
|
129
|
+
end
|
130
|
+
|
131
|
+
def modifier
|
132
|
+
@parsing_row ? @row_modifier : @cell_modifier
|
133
|
+
end
|
134
|
+
...end modifier.y/module_eval...
|
135
|
+
##### State transition tables begin ###
|
136
|
+
|
137
|
+
racc_action_table = [
|
138
|
+
13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
|
139
|
+
23, 24, 25, 26, 27, 28, 13, 14, 15, 16,
|
140
|
+
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
|
141
|
+
27, 28, 13, 14, 15, 16, 17, 18, 19, 20,
|
142
|
+
21, 22, 23, 24, 25, 26, 27, 28, 30, 47,
|
143
|
+
5, 4, 6, 31, 31, 5, 10, 32, 33, 34,
|
144
|
+
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
|
145
|
+
45, 46, 49, 50, 51, 52, 53, 54, 55, 56,
|
146
|
+
57, 58, 59, 60, 61, 62, 63 ]
|
147
|
+
|
148
|
+
racc_action_check = [
|
149
|
+
8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
150
|
+
8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
|
151
|
+
9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
152
|
+
9, 9, 31, 31, 31, 31, 31, 31, 31, 31,
|
153
|
+
31, 31, 31, 31, 31, 31, 31, 31, 11, 29,
|
154
|
+
0, 0, 1, 11, 29, 2, 6, 13, 14, 15,
|
155
|
+
16, 17, 18, 19, 20, 21, 23, 24, 25, 26,
|
156
|
+
27, 28, 32, 33, 34, 35, 36, 37, 38, 39,
|
157
|
+
40, 41, 42, 43, 44, 45, 46 ]
|
158
|
+
|
159
|
+
racc_action_pointer = [
|
160
|
+
36, 52, 41, nil, nil, nil, 56, nil, -17, -1,
|
161
|
+
nil, 41, nil, 49, 50, 51, 52, 53, 54, 55,
|
162
|
+
56, 57, nil, 58, 59, 60, 61, 62, 63, 42,
|
163
|
+
nil, 15, 59, 64, 61, 66, 66, 68, 65, 69,
|
164
|
+
67, 68, 69, 70, 71, 72, 73, nil, nil, nil,
|
165
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
166
|
+
nil, nil, nil, nil ]
|
167
|
+
|
168
|
+
racc_action_default = [
|
169
|
+
-27, -27, -2, -3, -4, -6, -27, -1, -27, -27,
|
170
|
+
64, -27, -9, -27, -27, -27, -27, -15, -27, -27,
|
171
|
+
-27, -27, -20, -27, -27, -27, -27, -27, -27, -27,
|
172
|
+
-5, -27, -27, -27, -27, -27, -27, -27, -27, -27,
|
173
|
+
-27, -27, -27, -27, -27, -27, -27, -7, -8, -10,
|
174
|
+
-11, -12, -13, -14, -16, -17, -18, -19, -21, -22,
|
175
|
+
-23, -24, -25, -26 ]
|
176
|
+
|
177
|
+
racc_goto_table = [
|
178
|
+
3, 1, 7, 11, 29, 2, 8, 9, 48 ]
|
179
|
+
|
180
|
+
racc_goto_check = [
|
181
|
+
3, 1, 3, 4, 4, 2, 5, 6, 7 ]
|
182
|
+
|
183
|
+
racc_goto_pointer = [
|
184
|
+
nil, 1, 5, 0, -5, 2, 2, -23 ]
|
185
|
+
|
186
|
+
racc_goto_default = [
|
187
|
+
nil, nil, nil, nil, nil, nil, nil, 12 ]
|
188
|
+
|
189
|
+
racc_reduce_table = [
|
190
|
+
0, 0, :racc_error,
|
191
|
+
2, 34, :_reduce_none,
|
192
|
+
1, 34, :_reduce_none,
|
193
|
+
1, 34, :_reduce_none,
|
194
|
+
0, 38, :_reduce_4,
|
195
|
+
4, 35, :_reduce_5,
|
196
|
+
0, 39, :_reduce_6,
|
197
|
+
4, 36, :_reduce_none,
|
198
|
+
3, 37, :_reduce_none,
|
199
|
+
1, 37, :_reduce_none,
|
200
|
+
3, 40, :_reduce_10,
|
201
|
+
3, 40, :_reduce_11,
|
202
|
+
3, 40, :_reduce_12,
|
203
|
+
3, 40, :_reduce_13,
|
204
|
+
3, 40, :_reduce_14,
|
205
|
+
1, 40, :_reduce_15,
|
206
|
+
3, 40, :_reduce_16,
|
207
|
+
3, 40, :_reduce_17,
|
208
|
+
3, 40, :_reduce_18,
|
209
|
+
3, 40, :_reduce_19,
|
210
|
+
1, 40, :_reduce_20,
|
211
|
+
3, 40, :_reduce_21,
|
212
|
+
3, 40, :_reduce_22,
|
213
|
+
3, 40, :_reduce_23,
|
214
|
+
3, 40, :_reduce_24,
|
215
|
+
3, 40, :_reduce_25,
|
216
|
+
3, 40, :_reduce_26 ]
|
217
|
+
|
218
|
+
racc_reduce_n = 27
|
219
|
+
|
220
|
+
racc_shift_n = 64
|
221
|
+
|
222
|
+
racc_token_table = {
|
223
|
+
false => 0,
|
224
|
+
:error => 1,
|
225
|
+
"![[" => 2,
|
226
|
+
"[[" => 3,
|
227
|
+
"]]" => 4,
|
228
|
+
"=" => 5,
|
229
|
+
"/" => 6,
|
230
|
+
:END_MODIFIERS => 7,
|
231
|
+
:EQ => 8,
|
232
|
+
:HEX_COLOR => 9,
|
233
|
+
:NUMBER => 10,
|
234
|
+
:MODIFIER => 11,
|
235
|
+
:MODIFIER_SEPARATOR => 12,
|
236
|
+
:RIGHT_SIDE => 13,
|
237
|
+
:START_CELL_MODIFIERS => 14,
|
238
|
+
:START_ROW_MODIFIERS => 15,
|
239
|
+
:STRING => 16,
|
240
|
+
"border" => 17,
|
241
|
+
"bordercolor" => 18,
|
242
|
+
"borderstyle" => 19,
|
243
|
+
"color" => 20,
|
244
|
+
"expand" => 21,
|
245
|
+
"fontcolor" => 22,
|
246
|
+
"fontfamily" => 23,
|
247
|
+
"fontsize" => 24,
|
248
|
+
"format" => 25,
|
249
|
+
"freeze" => 26,
|
250
|
+
"halign" => 27,
|
251
|
+
"note" => 28,
|
252
|
+
"numberformat" => 29,
|
253
|
+
"validate" => 30,
|
254
|
+
"valign" => 31,
|
255
|
+
"var" => 32 }
|
256
|
+
|
257
|
+
racc_nt_base = 33
|
258
|
+
|
259
|
+
racc_use_result_var = true
|
260
|
+
|
261
|
+
Racc_arg = [
|
262
|
+
racc_action_table,
|
263
|
+
racc_action_check,
|
264
|
+
racc_action_default,
|
265
|
+
racc_action_pointer,
|
266
|
+
racc_goto_table,
|
267
|
+
racc_goto_check,
|
268
|
+
racc_goto_default,
|
269
|
+
racc_goto_pointer,
|
270
|
+
racc_nt_base,
|
271
|
+
racc_reduce_table,
|
272
|
+
racc_token_table,
|
273
|
+
racc_shift_n,
|
274
|
+
racc_reduce_n,
|
275
|
+
racc_use_result_var ]
|
276
|
+
|
277
|
+
Racc_token_to_s_table = [
|
278
|
+
"$end",
|
279
|
+
"error",
|
280
|
+
"\"![[\"",
|
281
|
+
"\"[[\"",
|
282
|
+
"\"]]\"",
|
283
|
+
"\"=\"",
|
284
|
+
"\"/\"",
|
285
|
+
"END_MODIFIERS",
|
286
|
+
"EQ",
|
287
|
+
"HEX_COLOR",
|
288
|
+
"NUMBER",
|
289
|
+
"MODIFIER",
|
290
|
+
"MODIFIER_SEPARATOR",
|
291
|
+
"RIGHT_SIDE",
|
292
|
+
"START_CELL_MODIFIERS",
|
293
|
+
"START_ROW_MODIFIERS",
|
294
|
+
"STRING",
|
295
|
+
"\"border\"",
|
296
|
+
"\"bordercolor\"",
|
297
|
+
"\"borderstyle\"",
|
298
|
+
"\"color\"",
|
299
|
+
"\"expand\"",
|
300
|
+
"\"fontcolor\"",
|
301
|
+
"\"fontfamily\"",
|
302
|
+
"\"fontsize\"",
|
303
|
+
"\"format\"",
|
304
|
+
"\"freeze\"",
|
305
|
+
"\"halign\"",
|
306
|
+
"\"note\"",
|
307
|
+
"\"numberformat\"",
|
308
|
+
"\"validate\"",
|
309
|
+
"\"valign\"",
|
310
|
+
"\"var\"",
|
311
|
+
"$start",
|
312
|
+
"modifiers_definition",
|
313
|
+
"row_modifiers",
|
314
|
+
"cell_modifiers",
|
315
|
+
"modifiers",
|
316
|
+
"@1",
|
317
|
+
"@2",
|
318
|
+
"modifier" ]
|
319
|
+
|
320
|
+
Racc_debug_parser = false
|
321
|
+
|
322
|
+
##### State transition tables end #####
|
323
|
+
|
324
|
+
# reduce 0 omitted
|
325
|
+
|
326
|
+
# reduce 1 omitted
|
327
|
+
|
328
|
+
# reduce 2 omitted
|
329
|
+
|
330
|
+
# reduce 3 omitted
|
331
|
+
|
332
|
+
module_eval(<<'.,.,', 'modifier.y', 25)
|
333
|
+
def _reduce_4(val, _values, result)
|
334
|
+
parsing_row!
|
335
|
+
result
|
336
|
+
end
|
337
|
+
.,.,
|
338
|
+
|
339
|
+
module_eval(<<'.,.,', 'modifier.y', 27)
|
340
|
+
def _reduce_5(val, _values, result)
|
341
|
+
finished_row!
|
342
|
+
result
|
343
|
+
end
|
344
|
+
.,.,
|
345
|
+
|
346
|
+
module_eval(<<'.,.,', 'modifier.y', 29)
|
347
|
+
def _reduce_6(val, _values, result)
|
348
|
+
parsing_cell!
|
349
|
+
result
|
350
|
+
end
|
351
|
+
.,.,
|
352
|
+
|
353
|
+
# reduce 7 omitted
|
354
|
+
|
355
|
+
# reduce 8 omitted
|
356
|
+
|
357
|
+
# reduce 9 omitted
|
358
|
+
|
359
|
+
module_eval(<<'.,.,', 'modifier.y', 35)
|
360
|
+
def _reduce_10(val, _values, result)
|
361
|
+
modifier.border = val[2]
|
362
|
+
result
|
363
|
+
end
|
364
|
+
.,.,
|
365
|
+
|
366
|
+
module_eval(<<'.,.,', 'modifier.y', 36)
|
367
|
+
def _reduce_11(val, _values, result)
|
368
|
+
modifier.bordercolor = val[2]
|
369
|
+
result
|
370
|
+
end
|
371
|
+
.,.,
|
372
|
+
|
373
|
+
module_eval(<<'.,.,', 'modifier.y', 37)
|
374
|
+
def _reduce_12(val, _values, result)
|
375
|
+
modifier.borderstyle = val[2]
|
376
|
+
result
|
377
|
+
end
|
378
|
+
.,.,
|
379
|
+
|
380
|
+
module_eval(<<'.,.,', 'modifier.y', 38)
|
381
|
+
def _reduce_13(val, _values, result)
|
382
|
+
modifier.color = val[2]
|
383
|
+
result
|
384
|
+
end
|
385
|
+
.,.,
|
386
|
+
|
387
|
+
module_eval(<<'.,.,', 'modifier.y', 39)
|
388
|
+
def _reduce_14(val, _values, result)
|
389
|
+
modifier.expand = val[2]
|
390
|
+
result
|
391
|
+
end
|
392
|
+
.,.,
|
393
|
+
|
394
|
+
module_eval(<<'.,.,', 'modifier.y', 40)
|
395
|
+
def _reduce_15(val, _values, result)
|
396
|
+
modifier.expand!
|
397
|
+
result
|
398
|
+
end
|
399
|
+
.,.,
|
400
|
+
|
401
|
+
module_eval(<<'.,.,', 'modifier.y', 41)
|
402
|
+
def _reduce_16(val, _values, result)
|
403
|
+
modifier.fontcolor = val[2]
|
404
|
+
result
|
405
|
+
end
|
406
|
+
.,.,
|
407
|
+
|
408
|
+
module_eval(<<'.,.,', 'modifier.y', 42)
|
409
|
+
def _reduce_17(val, _values, result)
|
410
|
+
modifier.fontfamily = val[2]
|
411
|
+
result
|
412
|
+
end
|
413
|
+
.,.,
|
414
|
+
|
415
|
+
module_eval(<<'.,.,', 'modifier.y', 43)
|
416
|
+
def _reduce_18(val, _values, result)
|
417
|
+
modifier.fontsize = val[2]
|
418
|
+
result
|
419
|
+
end
|
420
|
+
.,.,
|
421
|
+
|
422
|
+
module_eval(<<'.,.,', 'modifier.y', 44)
|
423
|
+
def _reduce_19(val, _values, result)
|
424
|
+
modifier.format = val[2]
|
425
|
+
result
|
426
|
+
end
|
427
|
+
.,.,
|
428
|
+
|
429
|
+
module_eval(<<'.,.,', 'modifier.y', 45)
|
430
|
+
def _reduce_20(val, _values, result)
|
431
|
+
modifier.freeze!
|
432
|
+
result
|
433
|
+
end
|
434
|
+
.,.,
|
435
|
+
|
436
|
+
module_eval(<<'.,.,', 'modifier.y', 46)
|
437
|
+
def _reduce_21(val, _values, result)
|
438
|
+
modifier.halign = val[2]
|
439
|
+
result
|
440
|
+
end
|
441
|
+
.,.,
|
442
|
+
|
443
|
+
module_eval(<<'.,.,', 'modifier.y', 47)
|
444
|
+
def _reduce_22(val, _values, result)
|
445
|
+
modifier.note = val[2]
|
446
|
+
result
|
447
|
+
end
|
448
|
+
.,.,
|
449
|
+
|
450
|
+
module_eval(<<'.,.,', 'modifier.y', 48)
|
451
|
+
def _reduce_23(val, _values, result)
|
452
|
+
modifier.numberformat = val[2]
|
453
|
+
result
|
454
|
+
end
|
455
|
+
.,.,
|
456
|
+
|
457
|
+
module_eval(<<'.,.,', 'modifier.y', 49)
|
458
|
+
def _reduce_24(val, _values, result)
|
459
|
+
modifier.validation = val[2]
|
460
|
+
result
|
461
|
+
end
|
462
|
+
.,.,
|
463
|
+
|
464
|
+
module_eval(<<'.,.,', 'modifier.y', 50)
|
465
|
+
def _reduce_25(val, _values, result)
|
466
|
+
modifier.valign = val[2]
|
467
|
+
result
|
468
|
+
end
|
469
|
+
.,.,
|
470
|
+
|
471
|
+
module_eval(<<'.,.,', 'modifier.y', 51)
|
472
|
+
def _reduce_26(val, _values, result)
|
473
|
+
define_var(val[2])
|
474
|
+
result
|
475
|
+
end
|
476
|
+
.,.,
|
477
|
+
|
478
|
+
def _reduce_none(val, _values, result)
|
479
|
+
val[0]
|
480
|
+
end
|
481
|
+
|
482
|
+
end # class Modifier
|
483
|
+
end # module Parser
|
484
|
+
end # module CSVPlusPlus
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'graph'
|
4
|
+
require_relative 'scope'
|
5
|
+
|
6
|
+
module CSVPlusPlus
|
7
|
+
# References in an AST that need to be resolved
|
8
|
+
#
|
9
|
+
# @attr functions [Array<Entities::Function>] Functions references
|
10
|
+
# @attr variables [Array<Entities::Variable>] Variable references
|
11
|
+
class References
|
12
|
+
attr_accessor :functions, :variables
|
13
|
+
|
14
|
+
# Extract references from an AST and return them in a new +References+ object
|
15
|
+
#
|
16
|
+
# @param ast [Entity] An +Entity+ to do a depth first search on for references. Entities can be
|
17
|
+
# infinitely deep because they can contain other function calls as params to a function call
|
18
|
+
# @param scope [Scope] The +CodeSection+ containing all currently defined functions & variables
|
19
|
+
#
|
20
|
+
# @return [References]
|
21
|
+
def self.extract(ast, scope)
|
22
|
+
new.tap do |refs|
|
23
|
+
::CSVPlusPlus::Graph.depth_first_search(ast) do |node|
|
24
|
+
next unless node.function_call? || node.variable?
|
25
|
+
|
26
|
+
refs.functions << node if function_reference?(node, scope)
|
27
|
+
refs.variables << node if node.variable?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Is the node a resolvable reference?
|
33
|
+
#
|
34
|
+
# @param node [Entity] The node to check if it's resolvable
|
35
|
+
#
|
36
|
+
# @return [boolean]
|
37
|
+
# TODO: move this into the Entity subclasses
|
38
|
+
def self.function_reference?(node, scope)
|
39
|
+
node.function_call? && (scope.defined_function?(node.id) \
|
40
|
+
|| ::CSVPlusPlus::Entities::Builtins::FUNCTIONS.key?(node.id))
|
41
|
+
end
|
42
|
+
|
43
|
+
private_class_method :function_reference?
|
44
|
+
|
45
|
+
# Create an object with empty references. The caller will build them up as it depth-first-searches
|
46
|
+
def initialize
|
47
|
+
@functions = []
|
48
|
+
@variables = []
|
49
|
+
end
|
50
|
+
|
51
|
+
# Are there any references to be resolved?
|
52
|
+
#
|
53
|
+
# @return [boolean]
|
54
|
+
def empty?
|
55
|
+
@functions.empty? && @variables.empty?
|
56
|
+
end
|
57
|
+
|
58
|
+
# @return [String]
|
59
|
+
def to_s
|
60
|
+
"References(functions: #{@functions}, variables: #{@variables})"
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [boolean]
|
64
|
+
def ==(other)
|
65
|
+
@functions == other.functions && @variables == other.variables
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|