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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d72318213cf0081f534b5f4831a7a1e1835dbd3
4
- data.tar.gz: 2700a1eef57c8edbc96432fa4140713b6a15c37f
3
+ metadata.gz: c64e8c6e7d12441b0f858d3a98aa97197eac5e52
4
+ data.tar.gz: 79afc6f86465ca664ce677be464572e87e170589
5
5
  SHA512:
6
- metadata.gz: f2796806f37fff89494e84f60cc73305ab9cdcc19e44540954fbe9f9961d73914c82af786bafc01936aa1e1e2553fbc1b23fd9902950e70cefcafd007ada22ca
7
- data.tar.gz: 9a15536fd266ac59fea374200645ff395b11dff32f45ae7acb85c158aa90dcb8486f1e03c8ba8312c034086606bbef41a8884fc0a65e91c713f9f3470e27aedf
6
+ metadata.gz: 8b512da456ba1a3634d9971ad27537ffe4f7ff4efea6d3b434f548d1412c96552ee147bd7e574d5bb38c38f31757d1fbc8eb080441aad5821a61bf6564159c0e
7
+ data.tar.gz: 217072420254652330cb7cdca81c9f3c0fdba46ef0dcebf8ba391a443408bc2c2143b6a33415e355a0e48102b867771960d897e2d7f0771477f0c474d1188050
@@ -297,17 +297,17 @@ class ExcelToX
297
297
  # Then we parse them
298
298
  @named_references.each do |name, reference|
299
299
  begin
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
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
- end
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
- @shared_string_replacer.map(details.last)
682
- emergency_indirect_replacement_bodge.current_sheet_name = ref.first
683
- emergency_indirect_replacement_bodge.referring_cell = ref.last
684
- emergency_indirect_replacement_bodge.replace(details.last)
685
-
686
- named_reference_replacer.default_sheet_name = ref.first
687
- named_reference_replacer.map(details.last)
688
- table_reference_replacer.worksheet = ref.first
689
- table_reference_replacer.referring_cell = ref.last
690
- table_reference_replacer.map(details.last)
691
- @replace_ranges_with_array_literals_replacer.map(details.last)
692
- transpose_function_replacer.map(details.last)
693
- simplify_arithmetic_replacer.map(details.last)
694
- # FIXME: Seem to need to do this twice, second time to eliminate brackets?!
695
- simplify_arithmetic_replacer.map(details.last)
696
- expand_array_formulae_replacer.map(details.last)
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
- if INLINE_TYPE[ast.first]
913
- true
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
@@ -1,5 +1,5 @@
1
1
  class ExcelToCode
2
- def self.version() "0.2.25" end
2
+ def self.version() "0.2.26" end
3
3
  end
4
4
 
5
5
  require_relative 'commands'
@@ -167,8 +167,10 @@ class AstExpandArrayFormulae
167
167
  [:function, ast[1], *args.map.with_index do |a,i|
168
168
  if ok_to_be_an_array[i]
169
169
  a
170
- else
170
+ elsif a[row]
171
171
  a[row][column] || [:error, :"#N/A"]
172
+ else
173
+ [:error, :"#N/A"]
172
174
  end
173
175
  end]
174
176
  end]
@@ -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 dependencies[sheet].has_key?(cell)
29
- dependencies[sheet][cell] = true
30
- ast = references[[sheet,cell]]
31
- return unless ast
32
- current_sheet.push(sheet)
33
- map(ast)
34
- current_sheet.pop
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.25
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-05-23 00:00:00.000000000 Z
11
+ date: 2014-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubypeg