excel_to_code 0.2.25 → 0.2.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/src/commands/excel_to_x.rb +38 -28
- data/src/excel_to_code.rb +1 -1
- data/src/rewrite/ast_expand_array_formulae.rb +3 -1
- data/src/simplify/identify_dependencies.rb +29 -7
- 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: c64e8c6e7d12441b0f858d3a98aa97197eac5e52
|
4
|
+
data.tar.gz: 79afc6f86465ca664ce677be464572e87e170589
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b512da456ba1a3634d9971ad27537ffe4f7ff4efea6d3b434f548d1412c96552ee147bd7e574d5bb38c38f31757d1fbc8eb080441aad5821a61bf6564159c0e
|
7
|
+
data.tar.gz: 217072420254652330cb7cdca81c9f3c0fdba46ef0dcebf8ba391a443408bc2c2143b6a33415e355a0e48102b867771960d897e2d7f0771477f0c474d1188050
|
data/src/commands/excel_to_x.rb
CHANGED
@@ -297,17 +297,17 @@ class ExcelToX
|
|
297
297
|
# Then we parse them
|
298
298
|
@named_references.each do |name, reference|
|
299
299
|
begin
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
300
|
+
parsed = CachingFormulaParser.parse(reference)
|
301
|
+
if parsed
|
302
|
+
@named_references[name] = parsed
|
303
|
+
else
|
304
|
+
$stderr.puts "Named reference #{name} #{reference} not parsed"
|
305
|
+
exit
|
306
|
+
end
|
307
|
+
rescue Exception
|
308
308
|
$stderr.puts "Named reference #{name} #{reference} not parsed"
|
309
309
|
raise
|
310
|
-
|
310
|
+
end
|
311
311
|
end
|
312
312
|
# Replace A$1:B2 with [A1, A2, B1, B2]
|
313
313
|
@replace_ranges_with_array_literals_replacer ||= ReplaceRangesWithArrayLiteralsAst.new
|
@@ -678,22 +678,27 @@ class ExcelToX
|
|
678
678
|
emergency_indirect_replacement_bodge.named_references = @named_references
|
679
679
|
|
680
680
|
@formulae_array.each do |ref, details|
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
681
|
+
begin
|
682
|
+
@shared_string_replacer.map(details.last)
|
683
|
+
emergency_indirect_replacement_bodge.current_sheet_name = ref.first
|
684
|
+
emergency_indirect_replacement_bodge.referring_cell = ref.last
|
685
|
+
emergency_indirect_replacement_bodge.replace(details.last)
|
686
|
+
|
687
|
+
named_reference_replacer.default_sheet_name = ref.first
|
688
|
+
named_reference_replacer.map(details.last)
|
689
|
+
table_reference_replacer.worksheet = ref.first
|
690
|
+
table_reference_replacer.referring_cell = ref.last
|
691
|
+
table_reference_replacer.map(details.last)
|
692
|
+
@replace_ranges_with_array_literals_replacer.map(details.last)
|
693
|
+
transpose_function_replacer.map(details.last)
|
694
|
+
simplify_arithmetic_replacer.map(details.last)
|
695
|
+
# FIXME: Seem to need to do this twice, second time to eliminate brackets?!
|
696
|
+
simplify_arithmetic_replacer.map(details.last)
|
697
|
+
expand_array_formulae_replacer.map(details.last)
|
698
|
+
rescue Exception => e
|
699
|
+
log.fatal "Exception when expanding array formulae #{ref}: #{details}"
|
700
|
+
raise
|
701
|
+
end
|
697
702
|
end
|
698
703
|
|
699
704
|
log.info "Rewriting array formulae into conventional formulae"
|
@@ -899,7 +904,6 @@ class ExcelToX
|
|
899
904
|
|
900
905
|
# These types of cells don't conatain formulae and can therefore be skipped
|
901
906
|
VALUE_TYPE = {:number => true, :string => true, :blank => true, :null => true, :error => true, :boolean_true => true, :boolean_false => true}
|
902
|
-
INLINE_TYPE = {:number => true, :string => true, :blank => true, :null => true, :error => true, :boolean_true => true, :boolean_false => true, :sheet_reference => true, :cell => true}
|
903
907
|
|
904
908
|
def inline_ast_decision
|
905
909
|
@inline_ast_decision ||= lambda do |sheet, cell, references|
|
@@ -909,8 +913,14 @@ class ExcelToX
|
|
909
913
|
else
|
910
914
|
ast = references[[sheet,cell]]
|
911
915
|
if ast
|
912
|
-
|
913
|
-
|
916
|
+
case ast.first
|
917
|
+
when :number, :string; true
|
918
|
+
when :blank, :null; true
|
919
|
+
when :error; true
|
920
|
+
when :boolean_true, :boolean_false; true
|
921
|
+
when :cell; true
|
922
|
+
when :sheet_reference
|
923
|
+
ast[2][0] != :named_reference
|
914
924
|
else
|
915
925
|
false
|
916
926
|
end
|
data/src/excel_to_code.rb
CHANGED
@@ -3,6 +3,7 @@ class IdentifyDependencies
|
|
3
3
|
attr_accessor :references
|
4
4
|
attr_accessor :dependencies
|
5
5
|
attr_accessor :current_sheet
|
6
|
+
attr_accessor :circular_reference_check
|
6
7
|
|
7
8
|
def initialize(references = {}, dependencies = {})
|
8
9
|
@references = references
|
@@ -11,27 +12,48 @@ class IdentifyDependencies
|
|
11
12
|
hash[key] = {}
|
12
13
|
end
|
13
14
|
@current_sheet = []
|
15
|
+
@circular_reference_check = []
|
14
16
|
end
|
15
17
|
|
16
18
|
def add_depedencies_for(sheet,cell = :all)
|
17
19
|
if cell == :all
|
18
20
|
references.each do |ref,ast|
|
19
21
|
next unless ref.first == sheet
|
22
|
+
circular_reference_check.clear
|
20
23
|
recursively_add_dependencies_for(sheet,ref.last)
|
21
24
|
end
|
22
25
|
else
|
26
|
+
circular_reference_check.clear
|
23
27
|
recursively_add_dependencies_for(sheet,cell)
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
27
31
|
def recursively_add_dependencies_for(sheet,cell)
|
28
|
-
return if
|
29
|
-
dependencies[sheet]
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
return if circular_reference?([sheet, cell])
|
33
|
+
unless dependencies[sheet].has_key?(cell)
|
34
|
+
dependencies[sheet][cell] = true
|
35
|
+
ast = references[[sheet,cell]]
|
36
|
+
if ast
|
37
|
+
current_sheet.push(sheet)
|
38
|
+
begin
|
39
|
+
map(ast)
|
40
|
+
rescue ExcelToCodeException
|
41
|
+
puts "[:'#{sheet}', :#{cell}] => #{ast}"
|
42
|
+
raise
|
43
|
+
end
|
44
|
+
current_sheet.pop
|
45
|
+
end
|
46
|
+
end
|
47
|
+
circular_reference_check.pop
|
48
|
+
end
|
49
|
+
|
50
|
+
def circular_reference?(ref)
|
51
|
+
if circular_reference_check.include?(ref)
|
52
|
+
raise ExcelToCodeException.new("Possible circular reference in #{circular_reference_check} #{ref}")
|
53
|
+
else
|
54
|
+
circular_reference_check.push(ref)
|
55
|
+
end
|
56
|
+
false
|
35
57
|
end
|
36
58
|
|
37
59
|
def map(ast)
|
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.26
|
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-
|
11
|
+
date: 2014-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubypeg
|