csv_plus_plus 0.1.1 → 0.1.3

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