excel_to_code 0.2.11 → 0.2.13
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.
- checksums.yaml +4 -4
- data/src/commands/excel_to_x.rb +2 -1
- data/src/excel_to_code.rb +1 -1
- data/src/rewrite/caching_formula_parser.rb +4 -0
- data/src/simplify/simplify_arithmetic.rb +34 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2baeee0267ce2b334f2a58d06c07ea645ac9b00a
|
4
|
+
data.tar.gz: de70db7cc308642cecbb59450abccbce7de38e54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0edd4bbe16625ecde2c13964a6a58f674ce3cc24757be4aad48e87617ef9f9a11e9c9b3d637ece3cb7f577559350276ef1fd9672f887f2e99a257efa212e6607
|
7
|
+
data.tar.gz: 10971e850f558c03104b7b562364ce4f7ea117f58a2b2a8bcb2ae9f4cdd48452819bd96dd6922ff22d59583b86802ac78fd964a7cc5b637b023bf40f36e1dbf1
|
data/src/commands/excel_to_x.rb
CHANGED
@@ -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 "
|
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
@@ -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
|
14
|
-
|
15
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubypeg
|