csv_plus_plus 0.1.1 → 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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +18 -62
  4. data/lib/csv_plus_plus/benchmarked_compiler.rb +62 -0
  5. data/lib/csv_plus_plus/{code_section.rb → can_define_references.rb} +22 -35
  6. data/lib/csv_plus_plus/can_resolve_references.rb +8 -0
  7. data/lib/csv_plus_plus/cell.rb +3 -3
  8. data/lib/csv_plus_plus/cli.rb +24 -7
  9. data/lib/csv_plus_plus/color.rb +12 -6
  10. data/lib/csv_plus_plus/compiler.rb +156 -0
  11. data/lib/csv_plus_plus/data_validation.rb +138 -0
  12. data/lib/csv_plus_plus/{language → entities}/ast_builder.rb +3 -5
  13. data/lib/csv_plus_plus/entities/boolean.rb +31 -0
  14. data/lib/csv_plus_plus/{language → entities}/builtins.rb +2 -4
  15. data/lib/csv_plus_plus/entities/cell_reference.rb +60 -0
  16. data/lib/csv_plus_plus/entities/date.rb +30 -0
  17. data/lib/csv_plus_plus/entities/entity.rb +84 -0
  18. data/lib/csv_plus_plus/entities/function.rb +33 -0
  19. data/lib/csv_plus_plus/entities/function_call.rb +35 -0
  20. data/lib/csv_plus_plus/entities/number.rb +34 -0
  21. data/lib/csv_plus_plus/entities/runtime_value.rb +26 -0
  22. data/lib/csv_plus_plus/entities/string.rb +29 -0
  23. data/lib/csv_plus_plus/entities/variable.rb +25 -0
  24. data/lib/csv_plus_plus/entities.rb +33 -0
  25. data/lib/csv_plus_plus/error/error.rb +10 -0
  26. data/lib/csv_plus_plus/error/formula_syntax_error.rb +36 -0
  27. data/lib/csv_plus_plus/error/modifier_syntax_error.rb +27 -0
  28. data/lib/csv_plus_plus/error/modifier_validation_error.rb +49 -0
  29. data/lib/csv_plus_plus/{language → error}/syntax_error.rb +6 -14
  30. data/lib/csv_plus_plus/error/writer_error.rb +9 -0
  31. data/lib/csv_plus_plus/error.rb +9 -2
  32. data/lib/csv_plus_plus/expand.rb +3 -1
  33. data/lib/csv_plus_plus/google_api_client.rb +4 -0
  34. data/lib/csv_plus_plus/lexer/lexer.rb +13 -6
  35. data/lib/csv_plus_plus/modifier/conditional_formatting.rb +17 -0
  36. data/lib/csv_plus_plus/modifier.rb +73 -65
  37. data/lib/csv_plus_plus/{language → parser}/cell_value.tab.rb +20 -20
  38. data/lib/csv_plus_plus/{language → parser}/code_section.tab.rb +83 -87
  39. data/lib/csv_plus_plus/parser/modifier.tab.rb +484 -0
  40. data/lib/csv_plus_plus/references.rb +68 -0
  41. data/lib/csv_plus_plus/row.rb +0 -3
  42. data/lib/csv_plus_plus/runtime.rb +199 -0
  43. data/lib/csv_plus_plus/scope.rb +196 -0
  44. data/lib/csv_plus_plus/template.rb +10 -10
  45. data/lib/csv_plus_plus/validated_modifier.rb +164 -0
  46. data/lib/csv_plus_plus/version.rb +1 -1
  47. data/lib/csv_plus_plus/writer/file_backer_upper.rb +6 -4
  48. data/lib/csv_plus_plus/writer/google_sheet_builder.rb +24 -29
  49. data/lib/csv_plus_plus/writer/google_sheet_modifier.rb +33 -12
  50. data/lib/csv_plus_plus/writer/rubyxl_builder.rb +3 -6
  51. data/lib/csv_plus_plus.rb +19 -10
  52. metadata +34 -24
  53. data/lib/csv_plus_plus/language/benchmarked_compiler.rb +0 -65
  54. data/lib/csv_plus_plus/language/compiler.rb +0 -152
  55. data/lib/csv_plus_plus/language/entities/boolean.rb +0 -33
  56. data/lib/csv_plus_plus/language/entities/cell_reference.rb +0 -33
  57. data/lib/csv_plus_plus/language/entities/entity.rb +0 -86
  58. data/lib/csv_plus_plus/language/entities/function.rb +0 -35
  59. data/lib/csv_plus_plus/language/entities/function_call.rb +0 -37
  60. data/lib/csv_plus_plus/language/entities/number.rb +0 -36
  61. data/lib/csv_plus_plus/language/entities/runtime_value.rb +0 -28
  62. data/lib/csv_plus_plus/language/entities/string.rb +0 -31
  63. data/lib/csv_plus_plus/language/entities/variable.rb +0 -25
  64. data/lib/csv_plus_plus/language/entities.rb +0 -28
  65. data/lib/csv_plus_plus/language/references.rb +0 -70
  66. data/lib/csv_plus_plus/language/runtime.rb +0 -205
  67. data/lib/csv_plus_plus/language/scope.rb +0 -192
  68. data/lib/csv_plus_plus/modifier.tab.rb +0 -907
@@ -7,20 +7,19 @@
7
7
  require 'racc/parser.rb'
8
8
 
9
9
  require_relative '../lexer'
10
- require_relative '../code_section'
11
- require_relative '../language/ast_builder'
10
+ require_relative '../entities/ast_builder'
12
11
 
13
12
  module CSVPlusPlus
14
- module Language
15
- class CodeSectionParser < Racc::Parser
13
+ module Parser
14
+ class CodeSection < Racc::Parser
16
15
 
17
- module_eval(<<'...end code_section.y/module_eval...', 'code_section.y', 71)
16
+ module_eval(<<'...end code_section.y/module_eval...', 'code_section.y', 69)
18
17
  include ::CSVPlusPlus::Lexer
19
- include ::CSVPlusPlus::Language::ASTBuilder
18
+ include ::CSVPlusPlus::Entities::ASTBuilder
20
19
 
21
- def initialize
22
- super
23
- @code_section = CodeSection.new
20
+ def initialize(scope)
21
+ super()
22
+ @scope = scope
24
23
  end
25
24
 
26
25
  protected
@@ -47,7 +46,6 @@ module_eval(<<'...end code_section.y/module_eval...', 'code_section.y', 71)
47
46
  true
48
47
  end,
49
48
  tokens: [
50
- [/\n/, :EOL], # XXX do I need this?
51
49
  [/:=/, :ASSIGN],
52
50
  [/def/, :FN_DEF],
53
51
  TOKEN_LIBRARY[:TRUE],
@@ -62,48 +60,48 @@ module_eval(<<'...end code_section.y/module_eval...', 'code_section.y', 71)
62
60
  end
63
61
 
64
62
  def return_value
65
- [@code_section, @rest]
63
+ @rest
66
64
  end
67
65
 
68
66
  private
69
67
 
70
68
  def def_function(id, arguments, body)
71
69
  fn_def = function(id, arguments, body)
72
- @code_section.def_function(fn_def.id, fn_def)
70
+ @scope.def_function(fn_def.id, fn_def)
73
71
  end
74
72
 
75
73
  def def_variable(id, ast)
76
- @code_section.def_variable(id, ast)
74
+ @scope.def_variable(id, ast)
77
75
  end
78
76
  ...end code_section.y/module_eval...
79
77
  ##### State transition tables begin ###
80
78
 
81
79
  racc_action_table = [
82
- 20, 38, 35, 9, 12, 13, 14, 20, 16, 31,
83
- 33, 34, 31, 42, 20, 31, 29, 36, 25, 26,
84
- 31, 23, 22, 24, 21, 25, 26, 20, 23, 22,
85
- 24, 21, 25, 26, 30, 23, 22, 24, 21, 20,
86
- 41, 31, 31, nil, 43, 25, 26, 20, 23, 22,
87
- 24, 21, 3, 10, nil, 7, 7, 25, 26, 44,
88
- 23, 22, 24, 21, nil, 25, 26, nil, 23, 22,
89
- 24, 21, 8, 8 ]
80
+ 20, 38, 9, 12, 13, 14, 16, 20, 31, 33,
81
+ 34, 31, 42, 31, 20, 31, 29, 25, 26, 31,
82
+ 23, 22, 24, 21, 25, 26, 20, 23, 22, 24,
83
+ 21, 25, 26, 30, 23, 22, 24, 21, 20, 41,
84
+ 31, nil, 35, 25, 26, 20, 23, 22, 24, 21,
85
+ 3, 10, nil, 7, 7, 25, 26, 36, 23, 22,
86
+ 24, 21, 25, 26, 43, 23, 22, 24, 21, 8,
87
+ 8, nil, nil, nil, nil, nil, nil, nil, nil, 44 ]
90
88
 
91
89
  racc_action_check = [
92
- 13, 32, 28, 1, 7, 8, 9, 15, 12, 17,
93
- 21, 26, 27, 36, 20, 37, 16, 28, 13, 13,
94
- 32, 13, 13, 13, 13, 15, 15, 31, 15, 15,
95
- 15, 15, 20, 20, 16, 20, 20, 20, 20, 34,
96
- 34, 39, 45, nil, 40, 31, 31, 44, 31, 31,
97
- 31, 31, 0, 2, nil, 0, 2, 34, 34, 40,
98
- 34, 34, 34, 34, nil, 44, 44, nil, 44, 44,
99
- 44, 44, 0, 2 ]
90
+ 13, 32, 1, 7, 8, 9, 12, 15, 17, 21,
91
+ 26, 27, 36, 37, 20, 39, 16, 13, 13, 32,
92
+ 13, 13, 13, 13, 15, 15, 31, 15, 15, 15,
93
+ 15, 20, 20, 16, 20, 20, 20, 20, 34, 34,
94
+ 45, nil, 28, 31, 31, 44, 31, 31, 31, 31,
95
+ 0, 2, nil, 0, 2, 34, 34, 28, 34, 34,
96
+ 34, 34, 44, 44, 40, 44, 44, 44, 44, 0,
97
+ 2, nil, nil, nil, nil, nil, nil, nil, nil, 40 ]
100
98
 
101
99
  racc_action_pointer = [
102
- 50, 3, 51, nil, nil, nil, nil, -18, -1, 6,
103
- nil, nil, 5, -3, nil, 4, 12, -14, nil, nil,
104
- 11, -12, nil, nil, nil, nil, 8, -11, -2, nil,
105
- nil, 24, -3, nil, 36, nil, -9, -8, nil, 18,
106
- 40, nil, nil, nil, 44, 19 ]
100
+ 48, 2, 49, nil, nil, nil, nil, -18, -2, 5,
101
+ nil, nil, 3, -3, nil, 4, 12, -14, nil, nil,
102
+ 11, -12, nil, nil, nil, nil, 7, -11, 38, nil,
103
+ nil, 23, -3, nil, 35, nil, -9, -9, nil, -7,
104
+ 60, nil, nil, nil, 42, 18 ]
107
105
 
108
106
  racc_action_default = [
109
107
  -27, -27, -27, -2, -4, -5, -6, -27, -27, -27,
@@ -134,32 +132,32 @@ racc_goto_default = [
134
132
 
135
133
  racc_reduce_table = [
136
134
  0, 0, :racc_error,
135
+ 2, 28, :_reduce_none,
136
+ 1, 28, :_reduce_none,
137
137
  2, 29, :_reduce_none,
138
138
  1, 29, :_reduce_none,
139
- 2, 30, :_reduce_none,
140
139
  1, 30, :_reduce_none,
141
- 1, 31, :_reduce_none,
142
- 1, 31, :_reduce_none,
143
- 4, 32, :_reduce_7,
144
- 3, 34, :_reduce_8,
145
- 2, 34, :_reduce_9,
146
- 3, 36, :_reduce_10,
147
- 1, 36, :_reduce_11,
148
- 3, 33, :_reduce_12,
149
- 1, 35, :_reduce_none,
150
- 1, 35, :_reduce_none,
151
- 3, 35, :_reduce_15,
152
- 2, 35, :_reduce_16,
153
- 1, 35, :_reduce_17,
154
- 1, 35, :_reduce_18,
155
- 1, 35, :_reduce_19,
156
- 1, 35, :_reduce_20,
157
- 1, 35, :_reduce_21,
158
- 3, 38, :_reduce_22,
159
- 4, 37, :_reduce_23,
160
- 3, 37, :_reduce_24,
161
- 3, 39, :_reduce_25,
162
- 1, 39, :_reduce_26 ]
140
+ 1, 30, :_reduce_none,
141
+ 4, 31, :_reduce_7,
142
+ 3, 33, :_reduce_8,
143
+ 2, 33, :_reduce_9,
144
+ 3, 35, :_reduce_10,
145
+ 1, 35, :_reduce_11,
146
+ 3, 32, :_reduce_12,
147
+ 1, 34, :_reduce_none,
148
+ 1, 34, :_reduce_none,
149
+ 3, 34, :_reduce_15,
150
+ 2, 34, :_reduce_16,
151
+ 1, 34, :_reduce_17,
152
+ 1, 34, :_reduce_18,
153
+ 1, 34, :_reduce_19,
154
+ 1, 34, :_reduce_20,
155
+ 1, 34, :_reduce_21,
156
+ 3, 37, :_reduce_22,
157
+ 4, 36, :_reduce_23,
158
+ 3, 36, :_reduce_24,
159
+ 3, 38, :_reduce_25,
160
+ 1, 38, :_reduce_26 ]
163
161
 
164
162
  racc_reduce_n = 27
165
163
 
@@ -186,16 +184,15 @@ racc_token_table = {
186
184
  ">=" => 17,
187
185
  "<>" => 18,
188
186
  "," => 19,
189
- :EOL => 20,
190
- :FALSE => 21,
191
- :ID => 22,
192
- :INFIX_OP => 23,
193
- :NUMBER => 24,
194
- :STRING => 25,
195
- :TRUE => 26,
196
- :VAR_REF => 27 }
187
+ :FALSE => 20,
188
+ :ID => 21,
189
+ :INFIX_OP => 22,
190
+ :NUMBER => 23,
191
+ :STRING => 24,
192
+ :TRUE => 25,
193
+ :VAR_REF => 26 }
197
194
 
198
- racc_nt_base = 28
195
+ racc_nt_base = 27
199
196
 
200
197
  racc_use_result_var = true
201
198
 
@@ -236,7 +233,6 @@ Racc_token_to_s_table = [
236
233
  "\">=\"",
237
234
  "\"<>\"",
238
235
  "\",\"",
239
- "EOL",
240
236
  "FALSE",
241
237
  "ID",
242
238
  "INFIX_OP",
@@ -275,42 +271,42 @@ Racc_debug_parser = false
275
271
 
276
272
  # reduce 6 omitted
277
273
 
278
- module_eval(<<'.,.,', 'code_section.y', 34)
274
+ module_eval(<<'.,.,', 'code_section.y', 33)
279
275
  def _reduce_7(val, _values, result)
280
276
  def_function(val[1], val[2], val[3])
281
277
  result
282
278
  end
283
279
  .,.,
284
280
 
285
- module_eval(<<'.,.,', 'code_section.y', 36)
281
+ module_eval(<<'.,.,', 'code_section.y', 35)
286
282
  def _reduce_8(val, _values, result)
287
283
  result = val[1]
288
284
  result
289
285
  end
290
286
  .,.,
291
287
 
292
- module_eval(<<'.,.,', 'code_section.y', 37)
288
+ module_eval(<<'.,.,', 'code_section.y', 36)
293
289
  def _reduce_9(val, _values, result)
294
290
  result = []
295
291
  result
296
292
  end
297
293
  .,.,
298
294
 
299
- module_eval(<<'.,.,', 'code_section.y', 39)
295
+ module_eval(<<'.,.,', 'code_section.y', 38)
300
296
  def _reduce_10(val, _values, result)
301
297
  result = val[0] << val[2]
302
298
  result
303
299
  end
304
300
  .,.,
305
301
 
306
- module_eval(<<'.,.,', 'code_section.y', 40)
302
+ module_eval(<<'.,.,', 'code_section.y', 39)
307
303
  def _reduce_11(val, _values, result)
308
304
  result = [val[0]]
309
305
  result
310
306
  end
311
307
  .,.,
312
308
 
313
- module_eval(<<'.,.,', 'code_section.y', 42)
309
+ module_eval(<<'.,.,', 'code_section.y', 41)
314
310
  def _reduce_12(val, _values, result)
315
311
  def_variable(val[0], val[2])
316
312
  result
@@ -321,84 +317,84 @@ module_eval(<<'.,.,', 'code_section.y', 42)
321
317
 
322
318
  # reduce 14 omitted
323
319
 
324
- module_eval(<<'.,.,', 'code_section.y', 46)
320
+ module_eval(<<'.,.,', 'code_section.y', 45)
325
321
  def _reduce_15(val, _values, result)
326
322
  result = val[1]
327
323
  result
328
324
  end
329
325
  .,.,
330
326
 
331
- module_eval(<<'.,.,', 'code_section.y', 47)
327
+ module_eval(<<'.,.,', 'code_section.y', 46)
332
328
  def _reduce_16(val, _values, result)
333
329
  result = variable(val[1])
334
330
  result
335
331
  end
336
332
  .,.,
337
333
 
338
- module_eval(<<'.,.,', 'code_section.y', 48)
334
+ module_eval(<<'.,.,', 'code_section.y', 47)
339
335
  def _reduce_17(val, _values, result)
340
336
  result = string(val[0])
341
337
  result
342
338
  end
343
339
  .,.,
344
340
 
345
- module_eval(<<'.,.,', 'code_section.y', 49)
341
+ module_eval(<<'.,.,', 'code_section.y', 48)
346
342
  def _reduce_18(val, _values, result)
347
343
  result = number(val[0])
348
344
  result
349
345
  end
350
346
  .,.,
351
347
 
352
- module_eval(<<'.,.,', 'code_section.y', 50)
348
+ module_eval(<<'.,.,', 'code_section.y', 49)
353
349
  def _reduce_19(val, _values, result)
354
350
  result = boolean(true)
355
351
  result
356
352
  end
357
353
  .,.,
358
354
 
359
- module_eval(<<'.,.,', 'code_section.y', 51)
355
+ module_eval(<<'.,.,', 'code_section.y', 50)
360
356
  def _reduce_20(val, _values, result)
361
357
  result = boolean(false)
362
358
  result
363
359
  end
364
360
  .,.,
365
361
 
366
- module_eval(<<'.,.,', 'code_section.y', 52)
362
+ module_eval(<<'.,.,', 'code_section.y', 51)
367
363
  def _reduce_21(val, _values, result)
368
364
  result = cell_reference(val[0])
369
365
  result
370
366
  end
371
367
  .,.,
372
368
 
373
- module_eval(<<'.,.,', 'code_section.y', 54)
369
+ module_eval(<<'.,.,', 'code_section.y', 53)
374
370
  def _reduce_22(val, _values, result)
375
371
  result = function_call(val[1], [val[0], val[2]], infix: true)
376
372
  result
377
373
  end
378
374
  .,.,
379
375
 
380
- module_eval(<<'.,.,', 'code_section.y', 56)
376
+ module_eval(<<'.,.,', 'code_section.y', 55)
381
377
  def _reduce_23(val, _values, result)
382
378
  result = function_call(val[0], val[2])
383
379
  result
384
380
  end
385
381
  .,.,
386
382
 
387
- module_eval(<<'.,.,', 'code_section.y', 57)
383
+ module_eval(<<'.,.,', 'code_section.y', 56)
388
384
  def _reduce_24(val, _values, result)
389
385
  result = function_call(val[0], [])
390
386
  result
391
387
  end
392
388
  .,.,
393
389
 
394
- module_eval(<<'.,.,', 'code_section.y', 59)
390
+ module_eval(<<'.,.,', 'code_section.y', 58)
395
391
  def _reduce_25(val, _values, result)
396
392
  result = val[0] << val[2]
397
393
  result
398
394
  end
399
395
  .,.,
400
396
 
401
- module_eval(<<'.,.,', 'code_section.y', 60)
397
+ module_eval(<<'.,.,', 'code_section.y', 59)
402
398
  def _reduce_26(val, _values, result)
403
399
  result = [val[0]]
404
400
  result
@@ -409,6 +405,6 @@ def _reduce_none(val, _values, result)
409
405
  val[0]
410
406
  end
411
407
 
412
- end # class CodeSectionParser
413
- end # module Language
408
+ end # class CodeSection
409
+ end # module Parser
414
410
  end # module CSVPlusPlus