csv_plus_plus 0.0.5 → 0.1.1

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/README.md +1 -0
  4. data/lib/csv_plus_plus/cell.rb +24 -8
  5. data/lib/csv_plus_plus/cli.rb +29 -16
  6. data/lib/csv_plus_plus/cli_flag.rb +10 -2
  7. data/lib/csv_plus_plus/code_section.rb +55 -3
  8. data/lib/csv_plus_plus/color.rb +19 -5
  9. data/lib/csv_plus_plus/google_options.rb +6 -2
  10. data/lib/csv_plus_plus/graph.rb +0 -1
  11. data/lib/csv_plus_plus/language/ast_builder.rb +68 -0
  12. data/lib/csv_plus_plus/language/benchmarked_compiler.rb +65 -0
  13. data/lib/csv_plus_plus/language/builtins.rb +46 -0
  14. data/lib/csv_plus_plus/language/cell_value.tab.rb +106 -134
  15. data/lib/csv_plus_plus/language/code_section.tab.rb +163 -192
  16. data/lib/csv_plus_plus/language/compiler.rb +75 -92
  17. data/lib/csv_plus_plus/language/entities/boolean.rb +3 -2
  18. data/lib/csv_plus_plus/language/entities/cell_reference.rb +10 -3
  19. data/lib/csv_plus_plus/language/entities/entity.rb +20 -8
  20. data/lib/csv_plus_plus/language/entities/function.rb +6 -4
  21. data/lib/csv_plus_plus/language/entities/function_call.rb +17 -5
  22. data/lib/csv_plus_plus/language/entities/number.rb +6 -4
  23. data/lib/csv_plus_plus/language/entities/runtime_value.rb +9 -8
  24. data/lib/csv_plus_plus/language/entities/string.rb +6 -4
  25. data/lib/csv_plus_plus/language/references.rb +22 -5
  26. data/lib/csv_plus_plus/language/runtime.rb +80 -22
  27. data/lib/csv_plus_plus/language/scope.rb +34 -39
  28. data/lib/csv_plus_plus/language/syntax_error.rb +10 -5
  29. data/lib/csv_plus_plus/lexer/lexer.rb +27 -13
  30. data/lib/csv_plus_plus/lexer/tokenizer.rb +35 -11
  31. data/lib/csv_plus_plus/modifier.rb +38 -18
  32. data/lib/csv_plus_plus/modifier.tab.rb +2 -2
  33. data/lib/csv_plus_plus/options.rb +20 -2
  34. data/lib/csv_plus_plus/row.rb +15 -4
  35. data/lib/csv_plus_plus/template.rb +26 -6
  36. data/lib/csv_plus_plus/version.rb +1 -1
  37. data/lib/csv_plus_plus/writer/excel.rb +2 -9
  38. data/lib/csv_plus_plus/writer/file_backer_upper.rb +22 -20
  39. data/lib/csv_plus_plus/writer/google_sheet_builder.rb +8 -10
  40. data/lib/csv_plus_plus/writer/google_sheets.rb +4 -10
  41. data/lib/csv_plus_plus/writer/rubyxl_builder.rb +23 -15
  42. data/lib/csv_plus_plus/writer/rubyxl_modifier.rb +15 -8
  43. data/lib/csv_plus_plus.rb +42 -8
  44. metadata +5 -2
@@ -7,12 +7,14 @@
7
7
  require 'racc/parser.rb'
8
8
 
9
9
  require_relative '../lexer'
10
+ require_relative '../language/ast_builder'
10
11
 
11
12
  module CSVPlusPlus
12
13
  module Language
13
14
  class CellValueParser < Racc::Parser
14
15
 
15
16
  module_eval(<<'...end cell_value.y/module_eval...', 'cell_value.y', 48)
17
+ include ::CSVPlusPlus::Language::ASTBuilder
16
18
  include ::CSVPlusPlus::Lexer
17
19
 
18
20
  protected
@@ -29,18 +31,18 @@ module_eval(<<'...end cell_value.y/module_eval...', 'cell_value.y', 48)
29
31
  @ast
30
32
  end
31
33
 
32
- def tokenizer(input)
34
+ def tokenizer
33
35
  ::CSVPlusPlus::Lexer::Tokenizer.new(
34
- catchall: /[\(\)\/\*\+\-,=&]/,
36
+ catchall: /[\{\}\(\),=]/,
35
37
  ignore: /\s+/,
36
- input:,
37
38
  tokens: [
38
- [/true/i, :TRUE],
39
- [/false/i, :FALSE],
40
- [/"(?:[^"\\]|\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4}))*"/, :STRING],
41
- [/-?[\d.]+/, :NUMBER],
42
- [/\$\$/, :VAR_REF],
43
- [/[\$\w_]+/, :ID]
39
+ TOKEN_LIBRARY[:TRUE],
40
+ TOKEN_LIBRARY[:FALSE],
41
+ TOKEN_LIBRARY[:NUMBER],
42
+ TOKEN_LIBRARY[:STRING],
43
+ TOKEN_LIBRARY[:INFIX_OP],
44
+ TOKEN_LIBRARY[:VAR_REF],
45
+ TOKEN_LIBRARY[:ID]
44
46
  ]
45
47
  )
46
48
  end
@@ -48,108 +50,99 @@ module_eval(<<'...end cell_value.y/module_eval...', 'cell_value.y', 48)
48
50
  ##### State transition tables begin ###
49
51
 
50
52
  racc_action_table = [
51
- 33, 16, 17, 20, 18, 19, 15, 7, 16, 17,
52
- 20, 18, 19, 7, 34, 12, 13, 10, 9, 11,
53
- 8, 12, 13, 10, 9, 11, 8, 7, 16, 17,
54
- 20, 18, 19, 7, 2, 12, 13, 10, 9, 11,
55
- 8, 12, 13, 10, 9, 11, 8, 7, 16, 17,
56
- 20, 3, 14, 7, 22, 12, 13, 10, 9, 11,
57
- 8, 12, 13, 10, 9, 11, 8, 7, 16, 17,
58
- 20, 23, 16, 7, 31, 12, 13, 10, 9, 11,
59
- 8, 12, 13, 10, 9, 11, 8, 7, 29, 16,
60
- 17, 20, 18, 19, 16, 12, 13, 10, 9, 11,
61
- 8 ]
53
+ 7, 21, 15, 25, 2, 16, 3, 7, 14, 18,
54
+ 19, 16, 16, 16, 7, 12, 13, 16, 10, 9,
55
+ 11, 8, 12, 13, 26, 10, 9, 11, 8, 12,
56
+ 13, nil, 10, 9, 11, 8, 7, 23, nil, nil,
57
+ nil, nil, nil, 7, nil, nil, nil, nil, nil, nil,
58
+ nil, 12, 13, nil, 10, 9, 11, 8, 12, 13,
59
+ nil, 10, 9, 11, 8 ]
62
60
 
63
61
  racc_action_check = [
64
- 30, 4, 4, 4, 4, 4, 4, 2, 32, 32,
65
- 32, 32, 32, 7, 30, 2, 2, 2, 2, 2,
66
- 2, 7, 7, 7, 7, 7, 7, 16, 35, 35,
67
- 35, 35, 35, 17, 0, 16, 16, 16, 16, 16,
68
- 16, 17, 17, 17, 17, 17, 17, 18, 26, 26,
69
- 26, 1, 3, 19, 8, 18, 18, 18, 18, 18,
70
- 18, 19, 19, 19, 19, 19, 19, 20, 27, 27,
71
- 27, 13, 25, 23, 23, 20, 20, 20, 20, 20,
72
- 20, 23, 23, 23, 23, 23, 23, 34, 21, 21,
73
- 21, 21, 21, 21, 28, 34, 34, 34, 34, 34,
74
- 34 ]
62
+ 2, 17, 4, 22, 0, 4, 1, 7, 3, 8,
63
+ 13, 20, 24, 27, 16, 2, 2, 17, 2, 2,
64
+ 2, 2, 7, 7, 22, 7, 7, 7, 7, 16,
65
+ 16, nil, 16, 16, 16, 16, 19, 19, nil, nil,
66
+ nil, nil, nil, 26, nil, nil, nil, nil, nil, nil,
67
+ nil, 19, 19, nil, 19, 19, 19, 19, 26, 26,
68
+ nil, 26, 26, 26, 26 ]
75
69
 
76
70
  racc_action_pointer = [
77
- 18, 51, 5, 52, -3, nil, nil, 11, 43, nil,
78
- nil, nil, nil, 69, nil, nil, 25, 31, 45, 51,
79
- 65, 85, nil, 71, nil, 68, 44, 64, 90, nil,
80
- -3, nil, 4, nil, 85, 24 ]
71
+ -6, 6, -2, 8, -14, nil, nil, 5, -9, nil,
72
+ nil, nil, nil, 8, nil, nil, 12, -2, nil, 34,
73
+ -8, nil, 0, nil, -7, nil, 41, -6 ]
81
74
 
82
75
  racc_action_default = [
83
- -20, -20, -20, -20, -20, -2, -3, -20, -20, -6,
84
- -7, -8, -9, -10, 36, -1, -20, -20, -20, -20,
85
- -20, -20, -5, -20, -15, -16, -17, -18, -19, -4,
86
- -20, -12, -14, -11, -20, -13 ]
76
+ -16, -16, -16, -16, -16, -2, -3, -16, -16, -6,
77
+ -7, -8, -9, -10, 28, -1, -16, -16, -5, -16,
78
+ -15, -4, -16, -12, -14, -11, -16, -13 ]
87
79
 
88
80
  racc_goto_table = [
89
- 4, 1, 30, nil, nil, 21, nil, nil, nil, nil,
90
- nil, nil, nil, nil, 24, 25, 26, 27, 28, nil,
91
- nil, 32, nil, nil, nil, nil, nil, nil, nil, nil,
92
- nil, nil, 35 ]
81
+ 4, 1, 22, nil, nil, 17, nil, nil, nil, nil,
82
+ nil, nil, nil, nil, 20, nil, nil, 24, nil, nil,
83
+ nil, nil, nil, nil, 27 ]
93
84
 
94
85
  racc_goto_check = [
95
86
  2, 1, 5, nil, nil, 2, nil, nil, nil, nil,
96
- nil, nil, nil, nil, 2, 2, 2, 2, 2, nil,
97
- nil, 2, nil, nil, nil, nil, nil, nil, nil, nil,
98
- nil, nil, 2 ]
87
+ nil, nil, nil, nil, 2, nil, nil, 2, nil, nil,
88
+ nil, nil, nil, nil, 2 ]
99
89
 
100
90
  racc_goto_pointer = [
101
- nil, 1, -2, nil, nil, -21 ]
91
+ nil, 1, -2, nil, nil, -17 ]
102
92
 
103
93
  racc_goto_default = [
104
94
  nil, nil, nil, 5, 6, nil ]
105
95
 
106
96
  racc_reduce_table = [
107
97
  0, 0, :racc_error,
108
- 3, 19, :_reduce_1,
109
- 1, 20, :_reduce_none,
110
- 1, 20, :_reduce_none,
111
- 3, 20, :_reduce_4,
112
- 2, 20, :_reduce_5,
113
- 1, 20, :_reduce_6,
114
- 1, 20, :_reduce_7,
115
- 1, 20, :_reduce_8,
116
- 1, 20, :_reduce_9,
117
- 1, 20, :_reduce_10,
118
- 4, 21, :_reduce_11,
119
- 3, 21, :_reduce_12,
120
- 3, 23, :_reduce_13,
121
- 1, 23, :_reduce_14,
122
- 3, 22, :_reduce_15,
123
- 3, 22, :_reduce_16,
124
- 3, 22, :_reduce_17,
125
- 3, 22, :_reduce_18,
126
- 3, 22, :_reduce_19 ]
127
-
128
- racc_reduce_n = 20
129
-
130
- racc_shift_n = 36
98
+ 3, 26, :_reduce_1,
99
+ 1, 27, :_reduce_none,
100
+ 1, 27, :_reduce_none,
101
+ 3, 27, :_reduce_4,
102
+ 2, 27, :_reduce_5,
103
+ 1, 27, :_reduce_6,
104
+ 1, 27, :_reduce_7,
105
+ 1, 27, :_reduce_8,
106
+ 1, 27, :_reduce_9,
107
+ 1, 27, :_reduce_10,
108
+ 4, 28, :_reduce_11,
109
+ 3, 28, :_reduce_12,
110
+ 3, 30, :_reduce_13,
111
+ 1, 30, :_reduce_14,
112
+ 3, 29, :_reduce_15 ]
113
+
114
+ racc_reduce_n = 16
115
+
116
+ racc_shift_n = 28
131
117
 
132
118
  racc_token_table = {
133
119
  false => 0,
134
120
  :error => 1,
135
121
  "(" => 2,
136
122
  ")" => 3,
137
- "&" => 4,
123
+ "^" => 4,
138
124
  "*" => 5,
139
125
  "/" => 6,
140
126
  "+" => 7,
141
127
  "-" => 8,
142
- :EOL => 9,
143
- :FALSE => 10,
144
- :ID => 11,
145
- :NUMBER => 12,
146
- :STRING => 13,
147
- :TRUE => 14,
148
- :VAR_REF => 15,
149
- "=" => 16,
150
- "," => 17 }
151
-
152
- racc_nt_base = 18
128
+ "&" => 9,
129
+ "=" => 10,
130
+ "<" => 11,
131
+ ">" => 12,
132
+ "<=" => 13,
133
+ ">=" => 14,
134
+ "<>" => 15,
135
+ :EOL => 16,
136
+ :FALSE => 17,
137
+ :ID => 18,
138
+ :INFIX_OP => 19,
139
+ :NUMBER => 20,
140
+ :STRING => 21,
141
+ :TRUE => 22,
142
+ :VAR_REF => 23,
143
+ "," => 24 }
144
+
145
+ racc_nt_base = 25
153
146
 
154
147
  racc_use_result_var = true
155
148
 
@@ -174,19 +167,26 @@ Racc_token_to_s_table = [
174
167
  "error",
175
168
  "\"(\"",
176
169
  "\")\"",
177
- "\"&\"",
170
+ "\"^\"",
178
171
  "\"*\"",
179
172
  "\"/\"",
180
173
  "\"+\"",
181
174
  "\"-\"",
175
+ "\"&\"",
176
+ "\"=\"",
177
+ "\"<\"",
178
+ "\">\"",
179
+ "\"<=\"",
180
+ "\">=\"",
181
+ "\"<>\"",
182
182
  "EOL",
183
183
  "FALSE",
184
184
  "ID",
185
+ "INFIX_OP",
185
186
  "NUMBER",
186
187
  "STRING",
187
188
  "TRUE",
188
189
  "VAR_REF",
189
- "\"=\"",
190
190
  "\",\"",
191
191
  "$start",
192
192
  "cell_value",
@@ -201,7 +201,7 @@ Racc_debug_parser = false
201
201
 
202
202
  # reduce 0 omitted
203
203
 
204
- module_eval(<<'.,.,', 'cell_value.y', 17)
204
+ module_eval(<<'.,.,', 'cell_value.y', 20)
205
205
  def _reduce_1(val, _values, result)
206
206
  @ast = val[1]
207
207
  result
@@ -212,114 +212,86 @@ module_eval(<<'.,.,', 'cell_value.y', 17)
212
212
 
213
213
  # reduce 3 omitted
214
214
 
215
- module_eval(<<'.,.,', 'cell_value.y', 21)
215
+ module_eval(<<'.,.,', 'cell_value.y', 24)
216
216
  def _reduce_4(val, _values, result)
217
217
  result = val[1]
218
218
  result
219
219
  end
220
220
  .,.,
221
221
 
222
- module_eval(<<'.,.,', 'cell_value.y', 22)
222
+ module_eval(<<'.,.,', 'cell_value.y', 25)
223
223
  def _reduce_5(val, _values, result)
224
- result = e(:variable, val[1])
224
+ result = variable(val[1])
225
225
  result
226
226
  end
227
227
  .,.,
228
228
 
229
- module_eval(<<'.,.,', 'cell_value.y', 23)
229
+ module_eval(<<'.,.,', 'cell_value.y', 26)
230
230
  def _reduce_6(val, _values, result)
231
- result = e(:string, val[0])
231
+ result = string(val[0])
232
232
  result
233
233
  end
234
234
  .,.,
235
235
 
236
- module_eval(<<'.,.,', 'cell_value.y', 24)
236
+ module_eval(<<'.,.,', 'cell_value.y', 27)
237
237
  def _reduce_7(val, _values, result)
238
- result = e(:number, val[0])
238
+ result = number(val[0])
239
239
  result
240
240
  end
241
241
  .,.,
242
242
 
243
- module_eval(<<'.,.,', 'cell_value.y', 25)
243
+ module_eval(<<'.,.,', 'cell_value.y', 28)
244
244
  def _reduce_8(val, _values, result)
245
- result = e(:boolean, true)
245
+ result = boolean(true)
246
246
  result
247
247
  end
248
248
  .,.,
249
249
 
250
- module_eval(<<'.,.,', 'cell_value.y', 26)
250
+ module_eval(<<'.,.,', 'cell_value.y', 29)
251
251
  def _reduce_9(val, _values, result)
252
- result = e(:boolean, false)
252
+ result = boolean(false)
253
253
  result
254
254
  end
255
255
  .,.,
256
256
 
257
- module_eval(<<'.,.,', 'cell_value.y', 27)
257
+ module_eval(<<'.,.,', 'cell_value.y', 30)
258
258
  def _reduce_10(val, _values, result)
259
- result = e(:cell_reference, val[0])
259
+ result = cell_reference(val[0])
260
260
  result
261
261
  end
262
262
  .,.,
263
263
 
264
- module_eval(<<'.,.,', 'cell_value.y', 29)
264
+ module_eval(<<'.,.,', 'cell_value.y', 32)
265
265
  def _reduce_11(val, _values, result)
266
- result = e(:function_call, val[0], val[2])
266
+ result = function_call(val[0], val[2])
267
267
  result
268
268
  end
269
269
  .,.,
270
270
 
271
- module_eval(<<'.,.,', 'cell_value.y', 30)
271
+ module_eval(<<'.,.,', 'cell_value.y', 33)
272
272
  def _reduce_12(val, _values, result)
273
- result = e(:function_call, val[0], [])
273
+ result = function_call(val[0], [])
274
274
  result
275
275
  end
276
276
  .,.,
277
277
 
278
- module_eval(<<'.,.,', 'cell_value.y', 32)
278
+ module_eval(<<'.,.,', 'cell_value.y', 35)
279
279
  def _reduce_13(val, _values, result)
280
280
  result = val[0] << val[2]
281
281
  result
282
282
  end
283
283
  .,.,
284
284
 
285
- module_eval(<<'.,.,', 'cell_value.y', 33)
285
+ module_eval(<<'.,.,', 'cell_value.y', 36)
286
286
  def _reduce_14(val, _values, result)
287
287
  result = [val[0]]
288
288
  result
289
289
  end
290
290
  .,.,
291
291
 
292
- module_eval(<<'.,.,', 'cell_value.y', 35)
293
- def _reduce_15(val, _values, result)
294
- result = e(:function_call, :concat, [val[0], val[2]])
295
- result
296
- end
297
- .,.,
298
-
299
- module_eval(<<'.,.,', 'cell_value.y', 36)
300
- def _reduce_16(val, _values, result)
301
- result = e(:function_call, :multiply, [val[0], val[2]])
302
- result
303
- end
304
- .,.,
305
-
306
- module_eval(<<'.,.,', 'cell_value.y', 37)
307
- def _reduce_17(val, _values, result)
308
- result = e(:function_call, :add, [val[0], val[2]])
309
- result
310
- end
311
- .,.,
312
-
313
292
  module_eval(<<'.,.,', 'cell_value.y', 38)
314
- def _reduce_18(val, _values, result)
315
- result = e(:function_call, :minus, [val[0], val[2]])
316
- result
317
- end
318
- .,.,
319
-
320
- module_eval(<<'.,.,', 'cell_value.y', 39)
321
- def _reduce_19(val, _values, result)
322
- result = e(:function_call, :divide, [val[0], val[2]])
293
+ def _reduce_15(val, _values, result)
294
+ result = function_call(val[1], [val[0], val[2]], infix: true)
323
295
  result
324
296
  end
325
297
  .,.,