excel_to_code 0.1.23 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/src/commands/excel_to_c.rb +39 -92
  3. data/src/commands/excel_to_ruby.rb +9 -35
  4. data/src/commands/excel_to_x.rb +515 -536
  5. data/src/compile/c/a.out +0 -0
  6. data/src/compile/c/compile_named_reference_setters.rb +4 -6
  7. data/src/compile/c/compile_to_c.rb +34 -21
  8. data/src/compile/c/compile_to_c_header.rb +7 -7
  9. data/src/compile/c/excel_to_c_runtime.c +8 -4
  10. data/src/compile/c/map_formulae_to_c.rb +85 -86
  11. data/src/compile/c/map_values_to_c.rb +7 -1
  12. data/src/compile/c/map_values_to_c_structs.rb +1 -1
  13. data/src/compile/ruby/compile_to_ruby.rb +14 -11
  14. data/src/compile/ruby/compile_to_ruby_unit_test.rb +17 -10
  15. data/src/compile/ruby/map_formulae_to_ruby.rb +56 -56
  16. data/src/compile/ruby/map_values_to_ruby.rb +14 -2
  17. data/src/excel/area.rb +6 -8
  18. data/src/excel/excel_functions/hlookup.rb +1 -1
  19. data/src/excel/excel_functions/vlookup.rb +1 -1
  20. data/src/excel/formula_peg.rb +1 -1
  21. data/src/excel/formula_peg.txt +1 -1
  22. data/src/excel/reference.rb +4 -3
  23. data/src/excel/table.rb +4 -4
  24. data/src/extract.rb +1 -0
  25. data/src/extract/check_for_unknown_functions.rb +2 -2
  26. data/src/extract/extract_array_formulae.rb +9 -9
  27. data/src/extract/extract_everything.rb +140 -0
  28. data/src/extract/extract_formulae.rb +30 -20
  29. data/src/extract/extract_named_references.rb +37 -22
  30. data/src/extract/extract_relationships.rb +16 -3
  31. data/src/extract/extract_shared_formulae.rb +8 -11
  32. data/src/extract/extract_shared_formulae_targets.rb +1 -6
  33. data/src/extract/extract_shared_strings.rb +21 -8
  34. data/src/extract/extract_simple_formulae.rb +11 -6
  35. data/src/extract/extract_table.rb +26 -13
  36. data/src/extract/extract_values.rb +35 -11
  37. data/src/extract/extract_worksheet_dimensions.rb +13 -3
  38. data/src/extract/extract_worksheet_names.rb +16 -3
  39. data/src/extract/extract_worksheet_table_relationships.rb +16 -4
  40. data/src/extract/simple_extract_from_xml.rb +9 -11
  41. data/src/rewrite.rb +3 -0
  42. data/src/rewrite/ast_copy_formula.rb +5 -1
  43. data/src/rewrite/ast_expand_array_formulae.rb +71 -59
  44. data/src/rewrite/caching_formula_parser.rb +110 -0
  45. data/src/rewrite/rewrite_array_formulae.rb +21 -14
  46. data/src/rewrite/rewrite_cell_references_to_include_sheet.rb +41 -13
  47. data/src/rewrite/rewrite_shared_formulae.rb +17 -18
  48. data/src/rewrite/rewrite_values_to_ast.rb +2 -0
  49. data/src/rewrite/rewrite_whole_row_column_references_to_areas.rb +28 -25
  50. data/src/simplify.rb +1 -0
  51. data/src/simplify/count_formula_references.rb +22 -23
  52. data/src/simplify/emergency_array_formula_replace_indirect_bodge.rb +44 -0
  53. data/src/simplify/identify_dependencies.rb +7 -8
  54. data/src/simplify/identify_repeated_formula_elements.rb +5 -6
  55. data/src/simplify/inline_formulae.rb +48 -48
  56. data/src/simplify/map_formulae_to_values.rb +197 -79
  57. data/src/simplify/remove_cells.rb +13 -6
  58. data/src/simplify/replace_arithmetic_on_ranges.rb +42 -28
  59. data/src/simplify/replace_arrays_with_single_cells.rb +11 -5
  60. data/src/simplify/replace_column_with_column_number.rb +31 -23
  61. data/src/simplify/replace_common_elements_in_formulae.rb +16 -17
  62. data/src/simplify/replace_indirects_with_references.rb +26 -21
  63. data/src/simplify/replace_named_references.rb +26 -31
  64. data/src/simplify/replace_offsets_with_references.rb +33 -34
  65. data/src/simplify/replace_ranges_with_array_literals.rb +48 -20
  66. data/src/simplify/replace_shared_strings.rb +15 -13
  67. data/src/simplify/replace_string_join_on_ranges.rb +7 -9
  68. data/src/simplify/replace_table_references.rb +16 -11
  69. data/src/simplify/replace_values_with_constants.rb +6 -4
  70. data/src/simplify/simplify_arithmetic.rb +33 -19
  71. data/src/simplify/sort_into_calculation_order.rb +13 -13
  72. data/src/simplify/wrap_formulae_that_return_arrays_and_are_not_in_arrays.rb +21 -13
  73. metadata +19 -2
@@ -1,5 +1,21 @@
1
1
  require_relative '../excel'
2
2
 
3
+ class WrapFormulaeThatReturnArraysAndAReNotInArraysAst
4
+ def map(ast)
5
+ return ast unless ast.is_a?(Array)
6
+ function(ast) if ast.first == :function
7
+ ast
8
+ end
9
+
10
+ # Only does MMULT at the moment
11
+ FORMULAE_THAT_RETURN_ARRAYS = { "MMULT" => true }
12
+
13
+ def function(ast)
14
+ return unless FORMULAE_THAT_RETURN_ARRAYS.has_key?(ast[1])
15
+ ast.replace( [:function, "INDEX", ast.dup, [:number, "1"], [:number, "1"]])
16
+ end
17
+ end
18
+
3
19
  class WrapFormulaeThatReturnArraysAndAReNotInArrays
4
20
 
5
21
  def self.replace(*args)
@@ -7,21 +23,13 @@ class WrapFormulaeThatReturnArraysAndAReNotInArrays
7
23
  end
8
24
 
9
25
  def replace(input,output)
10
-
26
+ r = WrapFormulaeThatReturnArraysAndAReNotInArraysAst.new
27
+
11
28
  input.each_line do |line|
12
29
  # Looks to match lines that contain formulae that return ranges, such as MMULT
13
- if line =~ /"MMULT"/
14
- content = line.split("\t")
15
- ast = eval(content.pop)
16
- if ast[0] == :function && ast[1] == "MMULT"
17
- new_ast = [:function, "INDEX", ast, [:number, "1"], [:number, "1"]]
18
- output.puts "#{content.join("\t")}\t#{new_ast.inspect}"
19
- else
20
- output.puts line
21
- end
22
- else
23
- output.puts line
24
- end
30
+ content = line.split("\t")
31
+ ast = eval(content.pop)
32
+ output.puts "#{content.join("\t")}\t#{r.map(ast).inspect}"
25
33
  end
26
34
  end
27
35
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excel_to_code
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.23
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Counsell, Green on Black Ltd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-04 00:00:00.000000000 Z
11
+ date: 2013-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubypeg
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.0.11
69
+ - !ruby/object:Gem::Dependency
70
+ name: ox
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.12
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 2.0.12
69
83
  description: "# excel_to_code\n\nConverts some excel spreadsheets (.xlsx, not .xls)
70
84
  into some other programming languages (currently ruby or c).\nThis allows the excel
71
85
  spreadsheets to be run programatically, without excel.\n\nIts cannonical source
@@ -184,6 +198,7 @@ files:
184
198
  - src/excel_to_code.rb
185
199
  - src/extract/check_for_unknown_functions.rb
186
200
  - src/extract/extract_array_formulae.rb
201
+ - src/extract/extract_everything.rb
187
202
  - src/extract/extract_formulae.rb
188
203
  - src/extract/extract_named_references.rb
189
204
  - src/extract/extract_relationships.rb
@@ -200,6 +215,7 @@ files:
200
215
  - src/extract.rb
201
216
  - src/rewrite/ast_copy_formula.rb
202
217
  - src/rewrite/ast_expand_array_formulae.rb
218
+ - src/rewrite/caching_formula_parser.rb
203
219
  - src/rewrite/rewrite_array_formulae.rb
204
220
  - src/rewrite/rewrite_array_formulae_to_arrays.rb
205
221
  - src/rewrite/rewrite_cell_references_to_include_sheet.rb
@@ -213,6 +229,7 @@ files:
213
229
  - src/rewrite/rewrite_worksheet_names.rb
214
230
  - src/rewrite.rb
215
231
  - src/simplify/count_formula_references.rb
232
+ - src/simplify/emergency_array_formula_replace_indirect_bodge.rb
216
233
  - src/simplify/identify_dependencies.rb
217
234
  - src/simplify/identify_repeated_formula_elements.rb
218
235
  - src/simplify/inline_formulae.rb