excel_to_code 0.3.5 → 0.3.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b7eaef5e426ea529d3b33d237e2d41adc37c305
4
- data.tar.gz: ac576e8a20ca8bc58f9839c1018f45210cc9d0a6
3
+ metadata.gz: 7790188e924f5410d21cd2f4a25add63744f644a
4
+ data.tar.gz: 0467aff30ed411418ec3e7bcd7d8ea7fe7e7774f
5
5
  SHA512:
6
- metadata.gz: adb264736922ee868d1890cc9c390e8d34e29e4f31aa6be954a3980f49f5d9a02510d609ab1e72436be78ec6ad79359b0d5868d0e202e8732ffa837f535557be
7
- data.tar.gz: 4ce4a712b27076f76ae665dd158e0b7153ebdfea42643a8f8568bf4c8eeb58f0c7c7e6d84c4a33a13580f1a0781072f1bdff03a0406386998f304f6218f2c994
6
+ metadata.gz: d8252e23572c8d13b4a223404588ad457186fa5ce43e5f8727d573bf2377069a0b8abd8791d683991aca752f245bbee6490be19397927e96ed1950e16d1b5ef5
7
+ data.tar.gz: 84624066f10040b16124a07d1d94b0293685a44dec338ac06c8e29e5aca7d07c545b047523369ac1d3296316ef3de0699acc4ac48097164fdeaacb1166840ada
@@ -409,7 +409,7 @@ END
409
409
  def run_tests
410
410
  return unless actually_run_tests
411
411
  log.info "Running the resulting tests"
412
- if write_tests_as_c
412
+ if write_tests_in_c
413
413
  puts `cd #{File.join(output_directory)}; gcc "test_#{output_name.downcase}.c"; ./a.out`
414
414
  end
415
415
  puts `cd #{File.join(output_directory)}; ruby "test_#{output_name.downcase}.rb"`
data/src/compile/c/a.out CHANGED
Binary file
@@ -65,6 +65,7 @@ static ExcelValue hlookup_3(ExcelValue lookup_value_v,ExcelValue lookup_table_v,
65
65
  static ExcelValue hlookup(ExcelValue lookup_value_v,ExcelValue lookup_table_v, ExcelValue row_number_v, ExcelValue match_type_v);
66
66
  static ExcelValue iferror(ExcelValue value, ExcelValue value_if_error);
67
67
  static ExcelValue iserr(ExcelValue value);
68
+ static ExcelValue iserror(ExcelValue value);
68
69
  static ExcelValue excel_index(ExcelValue array_v, ExcelValue row_number_v, ExcelValue column_number_v);
69
70
  static ExcelValue excel_index_2(ExcelValue array_v, ExcelValue row_number_v);
70
71
  static ExcelValue excel_isnumber(ExcelValue number);
@@ -1095,6 +1096,15 @@ static ExcelValue iserr(ExcelValue value) {
1095
1096
  }
1096
1097
  }
1097
1098
 
1099
+ static ExcelValue iserror(ExcelValue value) {
1100
+ if(value.type == ExcelError) {
1101
+ return TRUE;
1102
+ } else {
1103
+ return FALSE;
1104
+ }
1105
+ }
1106
+
1107
+
1098
1108
 
1099
1109
  // Order is TRUE, FALSE, String, Number; Blank is zero
1100
1110
  static ExcelValue more_than(ExcelValue a_v, ExcelValue b_v) {
@@ -252,6 +252,18 @@ int test_functions() {
252
252
  assert(iserr(ONE).number == 0);
253
253
  assert(iserr(EXCEL_STRING("Hello")).number == 0);
254
254
  assert(iserr(EXCEL_STRING("Hello")).number == 0);
255
+
256
+ // Test the ISERROR function
257
+ assert_equal(iserror(NA), TRUE, "ISERROR(NA)");
258
+ assert_equal(iserror(DIV0), TRUE, "ISERROR(DIV0)");
259
+ assert_equal(iserror(REF), TRUE, "ISERROR(REF)");
260
+ assert_equal(iserror(VALUE), TRUE, "ISERROR(VALUE)");
261
+ assert_equal(iserror(NAME), TRUE, "ISERROR(NAME)");
262
+ assert_equal(iserror(BLANK), FALSE, "ISERROR(BLANK)");
263
+ assert_equal(iserror(TRUE), FALSE, "ISERROR(TRUE)");
264
+ assert_equal(iserror(FALSE), FALSE, "ISERROR(FALSE)");
265
+ assert_equal(iserror(ONE), FALSE, "ISERROR(ONE)");
266
+ assert_equal(iserror(EXCEL_STRING("Hello")), FALSE, "ISERROR('Hello')");
255
267
 
256
268
  // Test the INDEX function
257
269
  ExcelValue index_array_1[] = { EXCEL_NUMBER(10), EXCEL_NUMBER(20), BLANK };
@@ -47,6 +47,7 @@ class MapFormulaeToC < MapValuesToC
47
47
  :'IF3' => 'excel_if',
48
48
  :'IFERROR' => 'iferror',
49
49
  :'ISERR' => 'iserr',
50
+ :'ISERROR' => 'iserror',
50
51
  :'INDEX2' => 'excel_index_2',
51
52
  :'INDEX3' => 'excel_index',
52
53
  :'INT' => 'excel_int',
@@ -37,6 +37,7 @@ class MapFormulaeToRuby < MapValuesToRuby
37
37
  :'INT' => 'int',
38
38
  :'ISBLANK' => 'isblank',
39
39
  :'ISERR' => 'iserr',
40
+ :'ISERROR' => 'iserror',
40
41
  :'ISNUMBER' => 'isnumber',
41
42
  :'LARGE' => 'large',
42
43
  :'LEFT' => 'left',
@@ -115,3 +115,5 @@ require_relative 'excel_functions/ln'
115
115
  require_relative 'excel_functions/iserr'
116
116
 
117
117
  require_relative 'excel_functions/npv'
118
+
119
+ require_relative 'excel_functions/iserror'
@@ -0,0 +1,8 @@
1
+ module ExcelFunctions
2
+
3
+ def iserror(a)
4
+ return true if a.is_a?(Symbol)
5
+ false
6
+ end
7
+
8
+ end
data/src/excel_to_code.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class ExcelToCode
2
- def self.version() "0.3.5" end
2
+ def self.version() "0.3.7" end
3
3
  end
4
4
 
5
5
  require_relative 'commands'
@@ -80,8 +80,13 @@ class ExtractDataFromWorksheet < ::Ox::Sax
80
80
  return if only_extract_values
81
81
 
82
82
  unless @formula.empty?
83
- formula_text = @formula.join.gsub(/[\r\n]+/,'')
84
- ast = @fp.parse(formula_text)
83
+ begin
84
+ formula_text = @formula.join.gsub(/[\r\n]+/,'')
85
+ ast = @fp.parse(formula_text)
86
+ rescue ExternalReferenceException => e
87
+ e.ref = key # Attach the sheet and reference to the exception
88
+ raise
89
+ end
85
90
  unless ast
86
91
  $stderr.puts "Could not parse #{@sheet_name} #{@ref} #{formula_text}"
87
92
  exit
@@ -1,5 +1,32 @@
1
1
  require 'singleton'
2
2
 
3
+ class ExternalReferenceException < ExcelToCodeException
4
+
5
+ attr_accessor :reference_ast
6
+ attr_accessor :full_ast
7
+ attr_accessor :formula_text
8
+ attr_accessor :ref
9
+
10
+ def initialize(reference_ast, full_ast, formula_text)
11
+ @reference_ast, @full_ast, @formula_text = reference_ast, full_ast, formula_text
12
+ end
13
+
14
+ def message
15
+ <<-END
16
+
17
+ Sorry, ExcelToCode can't handle external references
18
+
19
+ It found one at #{ref}
20
+ The full formula was #{formula_text}
21
+ Which was parsed to #{full_ast}
22
+ Which seemed to have an external reference at #{reference_ast}
23
+
24
+ Please remove the external reference from the Excel and try again"
25
+
26
+ END
27
+ end
28
+ end
29
+
3
30
  class CachingFormulaParser
4
31
  include Singleton
5
32
 
@@ -26,6 +53,8 @@ class CachingFormulaParser
26
53
 
27
54
  def parse(text)
28
55
  ast = Formula.parse(text)
56
+ @text = text # Kept in case of Exception below
57
+ @full_ast = ast # Kept in case of Exception below
29
58
  if ast
30
59
  map(ast.to_ast[1])
31
60
  else
@@ -57,8 +86,9 @@ class CachingFormulaParser
57
86
  ast
58
87
  end
59
88
 
89
+ # We can't deal with external references at the moment
60
90
  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.")
91
+ raise ExternalReferenceException.new(ast, @full_ast, @text)
62
92
  end
63
93
 
64
94
  def sheet_reference(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.3.5
4
+ version: 0.3.7
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-12-18 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubypeg
@@ -173,6 +173,7 @@ files:
173
173
  - src/excel/excel_functions/int.rb
174
174
  - src/excel/excel_functions/isblank.rb
175
175
  - src/excel/excel_functions/iserr.rb
176
+ - src/excel/excel_functions/iserror.rb
176
177
  - src/excel/excel_functions/isnumber.rb
177
178
  - src/excel/excel_functions/large.rb
178
179
  - src/excel/excel_functions/left.rb