csv_plus_plus 0.1.2 → 0.2.0

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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -5
  3. data/{CHANGELOG.md → docs/CHANGELOG.md} +25 -0
  4. data/lib/csv_plus_plus/a1_reference.rb +202 -0
  5. data/lib/csv_plus_plus/benchmarked_compiler.rb +70 -20
  6. data/lib/csv_plus_plus/cell.rb +29 -41
  7. data/lib/csv_plus_plus/cli.rb +53 -80
  8. data/lib/csv_plus_plus/cli_flag.rb +71 -71
  9. data/lib/csv_plus_plus/color.rb +32 -7
  10. data/lib/csv_plus_plus/compiler.rb +98 -66
  11. data/lib/csv_plus_plus/entities/ast_builder.rb +30 -39
  12. data/lib/csv_plus_plus/entities/boolean.rb +26 -10
  13. data/lib/csv_plus_plus/entities/builtins.rb +66 -24
  14. data/lib/csv_plus_plus/entities/date.rb +42 -6
  15. data/lib/csv_plus_plus/entities/entity.rb +17 -69
  16. data/lib/csv_plus_plus/entities/entity_with_arguments.rb +44 -0
  17. data/lib/csv_plus_plus/entities/function.rb +34 -11
  18. data/lib/csv_plus_plus/entities/function_call.rb +49 -10
  19. data/lib/csv_plus_plus/entities/has_identifier.rb +19 -0
  20. data/lib/csv_plus_plus/entities/number.rb +30 -11
  21. data/lib/csv_plus_plus/entities/reference.rb +77 -0
  22. data/lib/csv_plus_plus/entities/runtime_value.rb +43 -13
  23. data/lib/csv_plus_plus/entities/string.rb +23 -7
  24. data/lib/csv_plus_plus/entities.rb +7 -16
  25. data/lib/csv_plus_plus/error/cli_error.rb +17 -0
  26. data/lib/csv_plus_plus/error/compiler_error.rb +17 -0
  27. data/lib/csv_plus_plus/error/error.rb +25 -2
  28. data/lib/csv_plus_plus/error/formula_syntax_error.rb +12 -12
  29. data/lib/csv_plus_plus/error/modifier_syntax_error.rb +34 -12
  30. data/lib/csv_plus_plus/error/modifier_validation_error.rb +21 -27
  31. data/lib/csv_plus_plus/error/positional_error.rb +15 -0
  32. data/lib/csv_plus_plus/error/writer_error.rb +8 -0
  33. data/lib/csv_plus_plus/error.rb +5 -1
  34. data/lib/csv_plus_plus/error_formatter.rb +111 -0
  35. data/lib/csv_plus_plus/google_api_client.rb +25 -10
  36. data/lib/csv_plus_plus/lexer/racc_lexer.rb +144 -0
  37. data/lib/csv_plus_plus/lexer/tokenizer.rb +58 -17
  38. data/lib/csv_plus_plus/lexer.rb +64 -1
  39. data/lib/csv_plus_plus/modifier/conditional_formatting.rb +1 -0
  40. data/lib/csv_plus_plus/modifier/data_validation.rb +138 -0
  41. data/lib/csv_plus_plus/modifier/expand.rb +78 -0
  42. data/lib/csv_plus_plus/modifier/google_sheet_modifier.rb +133 -0
  43. data/lib/csv_plus_plus/modifier/modifier.rb +222 -0
  44. data/lib/csv_plus_plus/modifier/modifier_validator.rb +243 -0
  45. data/lib/csv_plus_plus/modifier/rubyxl_modifier.rb +84 -0
  46. data/lib/csv_plus_plus/modifier.rb +89 -160
  47. data/lib/csv_plus_plus/options/file_options.rb +49 -0
  48. data/lib/csv_plus_plus/options/google_sheets_options.rb +42 -0
  49. data/lib/csv_plus_plus/options/options.rb +97 -0
  50. data/lib/csv_plus_plus/options.rb +34 -77
  51. data/lib/csv_plus_plus/parser/cell_value.tab.rb +66 -67
  52. data/lib/csv_plus_plus/parser/code_section.tab.rb +86 -83
  53. data/lib/csv_plus_plus/parser/modifier.tab.rb +57 -53
  54. data/lib/csv_plus_plus/reader/csv.rb +50 -0
  55. data/lib/csv_plus_plus/reader/google_sheets.rb +129 -0
  56. data/lib/csv_plus_plus/reader/reader.rb +27 -0
  57. data/lib/csv_plus_plus/reader/rubyxl.rb +37 -0
  58. data/lib/csv_plus_plus/reader.rb +14 -0
  59. data/lib/csv_plus_plus/row.rb +53 -12
  60. data/lib/csv_plus_plus/runtime/graph.rb +68 -0
  61. data/lib/csv_plus_plus/runtime/position.rb +242 -0
  62. data/lib/csv_plus_plus/runtime/references.rb +115 -0
  63. data/lib/csv_plus_plus/runtime/runtime.rb +132 -0
  64. data/lib/csv_plus_plus/runtime/scope.rb +280 -0
  65. data/lib/csv_plus_plus/runtime.rb +34 -191
  66. data/lib/csv_plus_plus/source_code.rb +71 -0
  67. data/lib/csv_plus_plus/template.rb +71 -39
  68. data/lib/csv_plus_plus/version.rb +2 -1
  69. data/lib/csv_plus_plus/writer/csv.rb +37 -8
  70. data/lib/csv_plus_plus/writer/excel.rb +25 -5
  71. data/lib/csv_plus_plus/writer/file_backer_upper.rb +27 -13
  72. data/lib/csv_plus_plus/writer/google_sheets.rb +29 -85
  73. data/lib/csv_plus_plus/writer/google_sheets_builder.rb +179 -0
  74. data/lib/csv_plus_plus/writer/merger.rb +31 -0
  75. data/lib/csv_plus_plus/writer/open_document.rb +21 -2
  76. data/lib/csv_plus_plus/writer/rubyxl_builder.rb +140 -42
  77. data/lib/csv_plus_plus/writer/writer.rb +42 -0
  78. data/lib/csv_plus_plus/writer.rb +79 -10
  79. data/lib/csv_plus_plus.rb +47 -18
  80. metadata +50 -21
  81. data/lib/csv_plus_plus/can_define_references.rb +0 -88
  82. data/lib/csv_plus_plus/can_resolve_references.rb +0 -8
  83. data/lib/csv_plus_plus/data_validation.rb +0 -138
  84. data/lib/csv_plus_plus/entities/cell_reference.rb +0 -60
  85. data/lib/csv_plus_plus/entities/variable.rb +0 -25
  86. data/lib/csv_plus_plus/error/syntax_error.rb +0 -58
  87. data/lib/csv_plus_plus/expand.rb +0 -20
  88. data/lib/csv_plus_plus/google_options.rb +0 -27
  89. data/lib/csv_plus_plus/graph.rb +0 -62
  90. data/lib/csv_plus_plus/lexer/lexer.rb +0 -85
  91. data/lib/csv_plus_plus/references.rb +0 -68
  92. data/lib/csv_plus_plus/scope.rb +0 -196
  93. data/lib/csv_plus_plus/validated_modifier.rb +0 -164
  94. data/lib/csv_plus_plus/writer/base_writer.rb +0 -20
  95. data/lib/csv_plus_plus/writer/google_sheet_builder.rb +0 -147
  96. data/lib/csv_plus_plus/writer/google_sheet_modifier.rb +0 -77
  97. data/lib/csv_plus_plus/writer/rubyxl_modifier.rb +0 -59
@@ -7,6 +7,7 @@
7
7
  require 'racc/parser.rb'
8
8
 
9
9
  require_relative '../lexer'
10
+ require_relative '../lexer/racc_lexer'
10
11
  require_relative '../entities/ast_builder'
11
12
 
12
13
  module CSVPlusPlus
@@ -14,35 +15,43 @@ module CSVPlusPlus
14
15
  class CellValue < Racc::Parser
15
16
 
16
17
  module_eval(<<'...end cell_value.y/module_eval...', 'cell_value.y', 49)
18
+ extend ::T::Sig
19
+ extend ::T::Generic
17
20
  include ::CSVPlusPlus::Entities::ASTBuilder
18
- include ::CSVPlusPlus::Lexer
21
+ include ::CSVPlusPlus::Lexer::RaccLexer
22
+
23
+ ReturnType = type_member {{ fixed: ::T.nilable(::CSVPlusPlus::Entities::Entity) }}
19
24
 
20
25
  protected
21
26
 
27
+ sig { override.params(input: ::String).returns(::T::Boolean) }
22
28
  def anything_to_parse?(input)
23
29
  input.strip.start_with?('=')
24
30
  end
25
31
 
32
+ sig { override.returns(::String) }
26
33
  def parse_subject
27
34
  'cell value'
28
35
  end
29
36
 
37
+ sig { override.returns(ReturnType) }
30
38
  def return_value
31
39
  @ast
32
40
  end
33
41
 
42
+ sig { override.returns(::CSVPlusPlus::Lexer::Tokenizer) }
34
43
  def tokenizer
35
44
  ::CSVPlusPlus::Lexer::Tokenizer.new(
36
45
  catchall: /[\{\}\(\),=]/,
37
46
  ignore: /\s+/,
38
47
  tokens: [
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]
48
+ ::CSVPlusPlus::Lexer::TOKEN_LIBRARY[:TRUE],
49
+ ::CSVPlusPlus::Lexer::TOKEN_LIBRARY[:FALSE],
50
+ ::CSVPlusPlus::Lexer::TOKEN_LIBRARY[:NUMBER],
51
+ ::CSVPlusPlus::Lexer::TOKEN_LIBRARY[:STRING],
52
+ ::CSVPlusPlus::Lexer::TOKEN_LIBRARY[:INFIX_OP],
53
+ ::CSVPlusPlus::Lexer::TOKEN_LIBRARY[:VAR_REF],
54
+ ::CSVPlusPlus::Lexer::TOKEN_LIBRARY[:REF]
46
55
  ]
47
56
  )
48
57
  end
@@ -50,45 +59,43 @@ module_eval(<<'...end cell_value.y/module_eval...', 'cell_value.y', 49)
50
59
  ##### State transition tables begin ###
51
60
 
52
61
  racc_action_table = [
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
+ 23, 19, 14, 2, 15, 7, 3, 13, 17, 15,
63
+ 15, 7, 15, nil, nil, nil, 15, 7, nil, nil,
64
+ 11, 24, 9, 12, 8, 10, 11, 7, 9, 12,
65
+ 8, 10, 11, nil, 9, 12, 8, 10, 7, 21,
66
+ nil, nil, 11, nil, 9, 12, 8, 10, nil, nil,
67
+ nil, nil, nil, 11, nil, 9, 12, 8, 10 ]
60
68
 
61
69
  racc_action_check = [
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 ]
70
+ 20, 16, 4, 0, 4, 2, 1, 3, 12, 18,
71
+ 22, 7, 25, nil, nil, nil, 16, 15, nil, nil,
72
+ 2, 20, 2, 2, 2, 2, 7, 24, 7, 7,
73
+ 7, 7, 15, nil, 15, 15, 15, 15, 17, 17,
74
+ nil, nil, 24, nil, 24, 24, 24, 24, nil, nil,
75
+ nil, nil, nil, 17, nil, 17, 17, 17, 17 ]
69
76
 
70
77
  racc_action_pointer = [
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 ]
78
+ -7, 6, 3, 7, -14, nil, nil, 9, nil, nil,
79
+ nil, nil, 6, nil, nil, 15, -2, 36, -9, nil,
80
+ -3, nil, -8, nil, 25, -6 ]
74
81
 
75
82
  racc_action_default = [
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 ]
83
+ -15, -15, -15, -15, -15, -2, -3, -15, -5, -6,
84
+ -7, -8, -9, 26, -1, -15, -15, -15, -14, -4,
85
+ -15, -11, -13, -10, -15, -12 ]
79
86
 
80
87
  racc_goto_table = [
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 ]
88
+ 4, 1, 20, nil, nil, 16, nil, nil, nil, nil,
89
+ nil, nil, nil, 18, nil, 22, nil, nil, nil, nil,
90
+ nil, nil, 25 ]
84
91
 
85
92
  racc_goto_check = [
86
93
  2, 1, 5, nil, nil, 2, nil, nil, nil, nil,
87
- nil, nil, nil, nil, 2, nil, nil, 2, nil, nil,
88
- nil, nil, nil, nil, 2 ]
94
+ nil, nil, nil, 2, nil, 2, nil, nil, nil, nil,
95
+ nil, nil, 2 ]
89
96
 
90
97
  racc_goto_pointer = [
91
- nil, 1, -2, nil, nil, -17 ]
98
+ nil, 1, -2, nil, nil, -15 ]
92
99
 
93
100
  racc_goto_default = [
94
101
  nil, nil, nil, 5, 6, nil ]
@@ -99,21 +106,20 @@ racc_reduce_table = [
99
106
  1, 27, :_reduce_none,
100
107
  1, 27, :_reduce_none,
101
108
  3, 27, :_reduce_4,
102
- 2, 27, :_reduce_5,
109
+ 1, 27, :_reduce_5,
103
110
  1, 27, :_reduce_6,
104
111
  1, 27, :_reduce_7,
105
112
  1, 27, :_reduce_8,
106
113
  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 ]
114
+ 4, 28, :_reduce_10,
115
+ 3, 28, :_reduce_11,
116
+ 3, 30, :_reduce_12,
117
+ 1, 30, :_reduce_13,
118
+ 3, 29, :_reduce_14 ]
113
119
 
114
- racc_reduce_n = 16
120
+ racc_reduce_n = 15
115
121
 
116
- racc_shift_n = 28
122
+ racc_shift_n = 26
117
123
 
118
124
  racc_token_table = {
119
125
  false => 0,
@@ -134,9 +140,9 @@ racc_token_table = {
134
140
  "<>" => 15,
135
141
  :EOL => 16,
136
142
  :FALSE => 17,
137
- :ID => 18,
138
- :INFIX_OP => 19,
139
- :NUMBER => 20,
143
+ :INFIX_OP => 18,
144
+ :NUMBER => 19,
145
+ :REF => 20,
140
146
  :STRING => 21,
141
147
  :TRUE => 22,
142
148
  :VAR_REF => 23,
@@ -181,9 +187,9 @@ Racc_token_to_s_table = [
181
187
  "\"<>\"",
182
188
  "EOL",
183
189
  "FALSE",
184
- "ID",
185
190
  "INFIX_OP",
186
191
  "NUMBER",
192
+ "REF",
187
193
  "STRING",
188
194
  "TRUE",
189
195
  "VAR_REF",
@@ -221,77 +227,70 @@ module_eval(<<'.,.,', 'cell_value.y', 25)
221
227
 
222
228
  module_eval(<<'.,.,', 'cell_value.y', 26)
223
229
  def _reduce_5(val, _values, result)
224
- result = variable(val[1])
230
+ result = string(val[0])
225
231
  result
226
232
  end
227
233
  .,.,
228
234
 
229
235
  module_eval(<<'.,.,', 'cell_value.y', 27)
230
236
  def _reduce_6(val, _values, result)
231
- result = string(val[0])
237
+ result = number(val[0])
232
238
  result
233
239
  end
234
240
  .,.,
235
241
 
236
242
  module_eval(<<'.,.,', 'cell_value.y', 28)
237
243
  def _reduce_7(val, _values, result)
238
- result = number(val[0])
244
+ result = boolean(true)
239
245
  result
240
246
  end
241
247
  .,.,
242
248
 
243
249
  module_eval(<<'.,.,', 'cell_value.y', 29)
244
250
  def _reduce_8(val, _values, result)
245
- result = boolean(true)
251
+ result = boolean(false)
246
252
  result
247
253
  end
248
254
  .,.,
249
255
 
250
256
  module_eval(<<'.,.,', 'cell_value.y', 30)
251
257
  def _reduce_9(val, _values, result)
252
- result = boolean(false)
258
+ result = reference(ref: val[0])
253
259
  result
254
260
  end
255
261
  .,.,
256
262
 
257
- module_eval(<<'.,.,', 'cell_value.y', 31)
263
+ module_eval(<<'.,.,', 'cell_value.y', 32)
258
264
  def _reduce_10(val, _values, result)
259
- result = cell_reference(val[0])
265
+ result = function_call(val[0].to_sym, val[2])
260
266
  result
261
267
  end
262
268
  .,.,
263
269
 
264
270
  module_eval(<<'.,.,', 'cell_value.y', 33)
265
271
  def _reduce_11(val, _values, result)
266
- result = function_call(val[0], val[2])
272
+ result = function_call(val[0].to_sym, [])
267
273
  result
268
274
  end
269
275
  .,.,
270
276
 
271
- module_eval(<<'.,.,', 'cell_value.y', 34)
277
+ module_eval(<<'.,.,', 'cell_value.y', 35)
272
278
  def _reduce_12(val, _values, result)
273
- result = function_call(val[0], [])
279
+ result = val[0] << val[2]
274
280
  result
275
281
  end
276
282
  .,.,
277
283
 
278
284
  module_eval(<<'.,.,', 'cell_value.y', 36)
279
285
  def _reduce_13(val, _values, result)
280
- result = val[0] << val[2]
281
- result
282
- end
283
- .,.,
284
-
285
- module_eval(<<'.,.,', 'cell_value.y', 37)
286
- def _reduce_14(val, _values, result)
287
286
  result = [val[0]]
288
287
  result
289
288
  end
290
289
  .,.,
291
290
 
292
- module_eval(<<'.,.,', 'cell_value.y', 39)
293
- def _reduce_15(val, _values, result)
294
- result = function_call(val[1], [val[0], val[2]], infix: true)
291
+ module_eval(<<'.,.,', 'cell_value.y', 38)
292
+ def _reduce_14(val, _values, result)
293
+ result = function_call(val[1].to_sym, [val[0], val[2]], infix: true)
295
294
  result
296
295
  end
297
296
  .,.,
@@ -6,17 +6,22 @@
6
6
 
7
7
  require 'racc/parser.rb'
8
8
 
9
- require_relative '../lexer'
9
+ require_relative '../lexer/racc_lexer'
10
10
  require_relative '../entities/ast_builder'
11
11
 
12
12
  module CSVPlusPlus
13
13
  module Parser
14
14
  class CodeSection < Racc::Parser
15
15
 
16
- module_eval(<<'...end code_section.y/module_eval...', 'code_section.y', 69)
17
- include ::CSVPlusPlus::Lexer
16
+ module_eval(<<'...end code_section.y/module_eval...', 'code_section.y', 68)
17
+ extend ::T::Sig
18
+ extend ::T::Generic
19
+ include ::CSVPlusPlus::Lexer::RaccLexer
18
20
  include ::CSVPlusPlus::Entities::ASTBuilder
19
21
 
22
+ ReturnType = type_member {{ fixed: ::T.nilable(::String) }}
23
+
24
+ sig { params(scope: ::CSVPlusPlus::Runtime::Scope).void }
20
25
  def initialize(scope)
21
26
  super()
22
27
  @scope = scope
@@ -24,20 +29,23 @@ module_eval(<<'...end code_section.y/module_eval...', 'code_section.y', 69)
24
29
 
25
30
  protected
26
31
 
32
+ sig { override.params(input: ::String).returns(::T::Boolean) }
27
33
  def anything_to_parse?(input)
28
34
  @rest = input.strip
29
35
 
30
36
  return !@rest.index(::CSVPlusPlus::Lexer::END_OF_CODE_SECTION).nil?
31
37
  end
32
38
 
39
+ sig { override.returns(::String) }
33
40
  def parse_subject
34
41
  'code section'
35
42
  end
36
43
 
44
+ sig { override.returns(::CSVPlusPlus::Lexer::Tokenizer) }
37
45
  def tokenizer
38
46
  ::CSVPlusPlus::Lexer::Tokenizer.new(
39
47
  catchall: /[\{\}\(\),]/, # TODO: do I even need this (oh I think brackets are for arrays
40
- ignore: /\s+|\#[^\n]+\n/,
48
+ ignore: /\s+|\#.*/,
41
49
  stop_fn: lambda do |scanner|
42
50
  return false unless scanner.scan(/#{::CSVPlusPlus::Lexer::END_OF_CODE_SECTION}/)
43
51
 
@@ -46,30 +54,37 @@ module_eval(<<'...end code_section.y/module_eval...', 'code_section.y', 69)
46
54
  true
47
55
  end,
48
56
  tokens: [
49
- [/:=/, :ASSIGN],
50
- [/def/, :FN_DEF],
51
- TOKEN_LIBRARY[:TRUE],
52
- TOKEN_LIBRARY[:FALSE],
53
- TOKEN_LIBRARY[:NUMBER],
54
- TOKEN_LIBRARY[:STRING],
55
- TOKEN_LIBRARY[:INFIX_OP],
56
- TOKEN_LIBRARY[:VAR_REF],
57
- TOKEN_LIBRARY[:ID]
57
+ ::CSVPlusPlus::Lexer::Token.new(regexp: /:=/, token: :ASSIGN),
58
+ ::CSVPlusPlus::Lexer::Token.new(regexp: /\bdef\b/, token: :FN_DEF),
59
+ ::CSVPlusPlus::Lexer::TOKEN_LIBRARY[:TRUE],
60
+ ::CSVPlusPlus::Lexer::TOKEN_LIBRARY[:FALSE],
61
+ ::CSVPlusPlus::Lexer::TOKEN_LIBRARY[:NUMBER],
62
+ ::CSVPlusPlus::Lexer::TOKEN_LIBRARY[:STRING],
63
+ ::CSVPlusPlus::Lexer::TOKEN_LIBRARY[:INFIX_OP],
64
+ ::CSVPlusPlus::Lexer::TOKEN_LIBRARY[:REF]
58
65
  ],
59
66
  )
60
67
  end
61
68
 
69
+ sig { override.returns(ReturnType) }
62
70
  def return_value
63
71
  @rest
64
72
  end
65
73
 
66
74
  private
67
75
 
76
+ sig do
77
+ params(id: ::Symbol, arguments: ::T::Array[::Symbol], body: ::CSVPlusPlus::Entities::Entity)
78
+ .returns(::CSVPlusPlus::Entities::Entity)
79
+ end
68
80
  def def_function(id, arguments, body)
69
- fn_def = function(id, arguments, body)
70
- @scope.def_function(fn_def.id, fn_def)
81
+ @scope.def_function(id, function(id, arguments, body))
71
82
  end
72
83
 
84
+ sig do
85
+ params(id: ::Symbol, ast: ::CSVPlusPlus::Entities::Entity)
86
+ .returns(::CSVPlusPlus::Entities::Entity)
87
+ end
73
88
  def def_variable(id, ast)
74
89
  @scope.def_variable(id, ast)
75
90
  end
@@ -77,54 +92,50 @@ module_eval(<<'...end code_section.y/module_eval...', 'code_section.y', 69)
77
92
  ##### State transition tables begin ###
78
93
 
79
94
  racc_action_table = [
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 ]
95
+ 20, 33, 9, 12, 13, 28, 20, 14, 16, 30,
96
+ 32, 30, 20, 40, 30, 30, 34, 24, 20, 22,
97
+ 25, 21, 23, 24, 29, 22, 25, 21, 23, 24,
98
+ 20, 22, 25, 21, 23, 24, 36, 22, 25, 21,
99
+ 23, 20, 39, 3, 41, 10, 7, 24, 7, 22,
100
+ 25, 21, 23, 30, 30, nil, nil, nil, 24, 42,
101
+ 22, 25, 21, 23, 8, nil, 8 ]
88
102
 
89
103
  racc_action_check = [
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 ]
104
+ 13, 27, 1, 7, 8, 16, 15, 9, 12, 17,
105
+ 25, 26, 20, 34, 35, 37, 27, 13, 30, 13,
106
+ 13, 13, 13, 15, 16, 15, 15, 15, 15, 20,
107
+ 42, 20, 20, 20, 20, 30, 31, 30, 30, 30,
108
+ 30, 32, 32, 0, 38, 2, 0, 42, 2, 42,
109
+ 42, 42, 42, 31, 43, nil, nil, nil, 32, 38,
110
+ 32, 32, 32, 32, 0, nil, 2 ]
98
111
 
99
112
  racc_action_pointer = [
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 ]
113
+ 41, 2, 43, nil, nil, nil, nil, -20, -2, 7,
114
+ nil, nil, 5, -3, nil, 3, 1, -12, nil, nil,
115
+ 9, nil, nil, nil, nil, 7, -10, -3, nil, nil,
116
+ 15, 32, 38, nil, -10, -7, nil, -6, 40, nil,
117
+ nil, nil, 27, 33 ]
105
118
 
106
119
  racc_action_default = [
107
- -27, -27, -27, -2, -4, -5, -6, -27, -27, -27,
108
- -1, -3, -27, -27, 46, -27, -27, -12, -13, -14,
109
- -27, -27, -17, -18, -19, -20, -21, -7, -27, -9,
110
- -11, -27, -27, -16, -27, -8, -27, -22, -15, -26,
111
- -27, -24, -10, -23, -27, -25 ]
120
+ -26, -26, -26, -2, -4, -5, -6, -26, -26, -26,
121
+ -1, -3, -26, -26, 44, -26, -26, -12, -13, -14,
122
+ -26, -16, -17, -18, -19, -20, -7, -26, -9, -11,
123
+ -26, -26, -26, -8, -26, -21, -15, -25, -26, -23,
124
+ -10, -22, -26, -24 ]
112
125
 
113
126
  racc_goto_table = [
114
- 17, 4, 27, 11, 1, 2, 15, 32, 28, 40,
115
- nil, nil, nil, nil, nil, nil, nil, nil, 37, nil,
116
- nil, 39, nil, nil, nil, nil, nil, nil, nil, nil,
117
- nil, 45 ]
127
+ 17, 4, 26, 11, 1, 2, 15, 31, 27, 38,
128
+ nil, nil, nil, nil, nil, nil, nil, 35, nil, 37,
129
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, 43 ]
118
130
 
119
131
  racc_goto_check = [
120
132
  7, 3, 7, 3, 1, 2, 6, 7, 8, 11,
121
- nil, nil, nil, nil, nil, nil, nil, nil, 7, nil,
122
- nil, 7, nil, nil, nil, nil, nil, nil, nil, nil,
123
- nil, 7 ]
133
+ nil, nil, nil, nil, nil, nil, nil, 7, nil, 7,
134
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, 7 ]
124
135
 
125
136
  racc_goto_pointer = [
126
137
  nil, 4, 5, 1, nil, nil, -6, -13, -8, nil,
127
- nil, -25 ]
138
+ nil, -23 ]
128
139
 
129
140
  racc_goto_default = [
130
141
  nil, nil, nil, nil, 5, 6, nil, nil, nil, 18,
@@ -147,21 +158,20 @@ racc_reduce_table = [
147
158
  1, 34, :_reduce_none,
148
159
  1, 34, :_reduce_none,
149
160
  3, 34, :_reduce_15,
150
- 2, 34, :_reduce_16,
161
+ 1, 34, :_reduce_16,
151
162
  1, 34, :_reduce_17,
152
163
  1, 34, :_reduce_18,
153
164
  1, 34, :_reduce_19,
154
165
  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 ]
166
+ 3, 37, :_reduce_21,
167
+ 4, 36, :_reduce_22,
168
+ 3, 36, :_reduce_23,
169
+ 3, 38, :_reduce_24,
170
+ 1, 38, :_reduce_25 ]
161
171
 
162
- racc_reduce_n = 27
172
+ racc_reduce_n = 26
163
173
 
164
- racc_shift_n = 46
174
+ racc_shift_n = 44
165
175
 
166
176
  racc_token_table = {
167
177
  false => 0,
@@ -185,9 +195,9 @@ racc_token_table = {
185
195
  "<>" => 18,
186
196
  "," => 19,
187
197
  :FALSE => 20,
188
- :ID => 21,
189
- :INFIX_OP => 22,
190
- :NUMBER => 23,
198
+ :INFIX_OP => 21,
199
+ :NUMBER => 22,
200
+ :REF => 23,
191
201
  :STRING => 24,
192
202
  :TRUE => 25,
193
203
  :VAR_REF => 26 }
@@ -234,9 +244,9 @@ Racc_token_to_s_table = [
234
244
  "\"<>\"",
235
245
  "\",\"",
236
246
  "FALSE",
237
- "ID",
238
247
  "INFIX_OP",
239
248
  "NUMBER",
249
+ "REF",
240
250
  "STRING",
241
251
  "TRUE",
242
252
  "VAR_REF",
@@ -273,7 +283,7 @@ Racc_debug_parser = false
273
283
 
274
284
  module_eval(<<'.,.,', 'code_section.y', 33)
275
285
  def _reduce_7(val, _values, result)
276
- def_function(val[1], val[2], val[3])
286
+ def_function(val[1].to_sym, val[2], val[3])
277
287
  result
278
288
  end
279
289
  .,.,
@@ -308,7 +318,7 @@ module_eval(<<'.,.,', 'code_section.y', 39)
308
318
 
309
319
  module_eval(<<'.,.,', 'code_section.y', 41)
310
320
  def _reduce_12(val, _values, result)
311
- def_variable(val[0], val[2])
321
+ def_variable(val[0].to_sym, val[2])
312
322
  result
313
323
  end
314
324
  .,.,
@@ -326,76 +336,69 @@ module_eval(<<'.,.,', 'code_section.y', 45)
326
336
 
327
337
  module_eval(<<'.,.,', 'code_section.y', 46)
328
338
  def _reduce_16(val, _values, result)
329
- result = variable(val[1])
339
+ result = string(val[0])
330
340
  result
331
341
  end
332
342
  .,.,
333
343
 
334
344
  module_eval(<<'.,.,', 'code_section.y', 47)
335
345
  def _reduce_17(val, _values, result)
336
- result = string(val[0])
346
+ result = number(val[0])
337
347
  result
338
348
  end
339
349
  .,.,
340
350
 
341
351
  module_eval(<<'.,.,', 'code_section.y', 48)
342
352
  def _reduce_18(val, _values, result)
343
- result = number(val[0])
353
+ result = boolean(true)
344
354
  result
345
355
  end
346
356
  .,.,
347
357
 
348
358
  module_eval(<<'.,.,', 'code_section.y', 49)
349
359
  def _reduce_19(val, _values, result)
350
- result = boolean(true)
360
+ result = boolean(false)
351
361
  result
352
362
  end
353
363
  .,.,
354
364
 
355
365
  module_eval(<<'.,.,', 'code_section.y', 50)
356
366
  def _reduce_20(val, _values, result)
357
- result = boolean(false)
367
+ result = reference(ref: val[0])
358
368
  result
359
369
  end
360
370
  .,.,
361
371
 
362
- module_eval(<<'.,.,', 'code_section.y', 51)
372
+ module_eval(<<'.,.,', 'code_section.y', 52)
363
373
  def _reduce_21(val, _values, result)
364
- result = cell_reference(val[0])
374
+ result = function_call(val[1].to_sym, [val[0], val[2]], infix: true)
365
375
  result
366
376
  end
367
377
  .,.,
368
378
 
369
- module_eval(<<'.,.,', 'code_section.y', 53)
379
+ module_eval(<<'.,.,', 'code_section.y', 54)
370
380
  def _reduce_22(val, _values, result)
371
- result = function_call(val[1], [val[0], val[2]], infix: true)
381
+ result = function_call(val[0].to_sym, val[2])
372
382
  result
373
383
  end
374
384
  .,.,
375
385
 
376
386
  module_eval(<<'.,.,', 'code_section.y', 55)
377
387
  def _reduce_23(val, _values, result)
378
- result = function_call(val[0], val[2])
388
+ result = function_call(val[0].to_sym, [])
379
389
  result
380
390
  end
381
391
  .,.,
382
392
 
383
- module_eval(<<'.,.,', 'code_section.y', 56)
393
+ module_eval(<<'.,.,', 'code_section.y', 57)
384
394
  def _reduce_24(val, _values, result)
385
- result = function_call(val[0], [])
395
+ result = val[0] << val[2]
386
396
  result
387
397
  end
388
398
  .,.,
389
399
 
390
400
  module_eval(<<'.,.,', 'code_section.y', 58)
391
401
  def _reduce_25(val, _values, result)
392
- result = val[0] << val[2]
393
- result
394
- end
395
- .,.,
396
-
397
- module_eval(<<'.,.,', 'code_section.y', 59)
398
- def _reduce_26(val, _values, result)
399
402
  result = [val[0]]
400
403
  result
401
404
  end