excel_to_code 0.2.11 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a444173d8318385277afd731b47cedcb7fe2b783
4
- data.tar.gz: 13c5f6fa4d20cc45730c9c15f736c68c17a810af
3
+ metadata.gz: 2baeee0267ce2b334f2a58d06c07ea645ac9b00a
4
+ data.tar.gz: de70db7cc308642cecbb59450abccbce7de38e54
5
5
  SHA512:
6
- metadata.gz: 201c1f56ae3807bce72ca38c48f78300f2c1c6a2857e2ddf58e111dfe9a64660d0cfc4bf453fe9eb817a8d5c1719e60fb19943b998f5342aea9f9d0873c5d79e
7
- data.tar.gz: 9945c873cfc1d3e76f6fff18c8fd43ad38f3862efcd24c16e8eccc53670d247fe8d00792d920fd86efe8732f86c2be1b2cdb0db998af112f68ed10081bd6e358
6
+ metadata.gz: 0edd4bbe16625ecde2c13964a6a58f674ce3cc24757be4aad48e87617ef9f9a11e9c9b3d637ece3cb7f577559350276ef1fd9672f887f2e99a257efa212e6607
7
+ data.tar.gz: 10971e850f558c03104b7b562364ce4f7ea117f58a2b2a8bcb2ae9f4cdd48452819bd96dd6922ff22d59583b86802ac78fd964a7cc5b637b023bf40f36e1dbf1
@@ -607,7 +607,7 @@ class ExcelToX
607
607
  # many cells. They are awkward. We try and replace them with conventional
608
608
  # formulae here.
609
609
  def rewrite_array_formulae
610
- log.info "Rewriting array formulae"
610
+ log.info "Expanding #{@formulae_array.size} array formulae"
611
611
  # FIMXE: Refactor this
612
612
 
613
613
  named_reference_replacer = ReplaceNamedReferencesAst.new(@named_references)
@@ -638,6 +638,7 @@ class ExcelToX
638
638
  expand_array_formulae_replacer.map(details.last)
639
639
  end
640
640
 
641
+ log.info "Rewriting array formulae into conventional formulae"
641
642
  @formulae_array = RewriteArrayFormulae.rewrite(@formulae_array)
642
643
  end
643
644
 
data/src/excel_to_code.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class ExcelToCode
2
- def self.version() "0.2.11" end
2
+ def self.version() "0.2.13" end
3
3
  end
4
4
 
5
5
  require_relative 'commands'
@@ -57,6 +57,10 @@ class CachingFormulaParser
57
57
  ast
58
58
  end
59
59
 
60
+ def external_reference(ast)
61
+ raise ExcelToCodeException.new("Sorry, ExcelToCode cannot cope with external references (#{ast.inspect}. Please strip them from the workbook before attempting to compile it.")
62
+ end
63
+
60
64
  def sheet_reference(ast)
61
65
  ast[1] = ast[1].to_sym
62
66
  ast[2] = map(ast[2])
@@ -1,48 +1,61 @@
1
1
  class SimplifyArithmeticAst
2
-
2
+
3
+ attr_accessor :map_count
4
+
3
5
  def map(ast)
6
+ @brackets_to_remove = []
7
+ simplify_arithmetic(ast)
8
+ remove_brackets(ast)
9
+ end
10
+
11
+ def simplify_arithmetic(ast)
4
12
  return ast unless ast.is_a?(Array)
13
+ ast.each { |a| simplify_arithmetic(a) }
5
14
  case ast[0]
6
- when :brackets; brackets(ast)
7
15
  when :arithmetic; arithmetic(ast)
16
+ when :brackets; @brackets_to_remove << ast
8
17
  end
9
- ast.each { |a| map(a) }
10
18
  ast
11
19
  end
12
20
 
13
- def brackets(ast)
14
- raise NotSupportedException.new("Multiple arguments not supported in brackets #{args.inspect}") if ast.size > 2
15
- ast.replace(map(ast[1]))
21
+ def remove_brackets(ast)
22
+ @brackets_to_remove.uniq.each do |ast|
23
+ raise NotSupportedException.new("Multiple arguments not supported in brackets #{ast.inspect}") if ast.size > 2
24
+ ast.replace(ast[1])
25
+ end
26
+ ast
16
27
  end
28
+
29
+ # This sets the operator precedence
30
+ OPERATOR_PRECEDENCE = [
31
+ {:'^' => 1},
32
+ {:'*' => 2,:'/' => 2},
33
+ {:'+' => 3,:'-' => 3}
34
+ ]
17
35
 
18
36
  def arithmetic(ast)
19
- case ast.size
20
- when 2; return map(ast[1]) # Not really arithmetic
21
- when 4; # Normal arithmetic that doesn't need re-arranging
22
- ast.each { |a| map(a) }
23
- else
24
- # This sets the operator precedence
37
+ # If smaller than 4, will only be a simple operation (e.g., 1+1 or 2*4)
38
+ # If more than 4, will be like 1+2*3 and so needs turning into 1+(2*3)
39
+ return unless ast.size > 4
40
+ OPERATOR_PRECEDENCE.each do |op|
25
41
  i = nil
26
- [{:'^' => 1},{:'*' => 2,:'/' => 2},{:'+' => 3,:'-' => 3}].each do |op|
27
- i = ast.find_index { |a| a[0] == :operator && op.has_key?(a[1])}
28
- break if i
29
- end
30
- if i
42
+ while i = ast.find_index { |a| a[0] == :operator && op.has_key?(a[1])}
31
43
  # Now we need to wrap that operation in its own arithmetic clause
32
44
  old_clause = ast[(i-1)..(i+1)]
33
45
  # Make sure we do any mapping
34
- old_clause.each { |a| map(a) }
46
+ #old_clause.each { |a| map(a) }
35
47
  # Now create a new clause
36
48
  new_clause = [:arithmetic, *old_clause]
37
49
  # And insert it back into the ast
38
50
  ast[(i-1)..(i+1)] = [new_clause]
39
51
  # Redo the mapping
40
- map(ast)
41
52
  end
42
53
  end
43
- ast.each { |a| map(a) }
54
+ # FIXME: this feels like a bodge
55
+ if ast.size == 2 && ast[0] == :arithmetic && ast[1].is_a?(Array) && ast[1][0] == :arithmetic
56
+ ast.replace(ast[1])
57
+ end
44
58
  end
45
-
46
59
  end
47
60
 
48
61
 
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.2.11
4
+ version: 0.2.13
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: 2014-02-02 00:00:00.000000000 Z
11
+ date: 2014-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubypeg