excel_to_code 0.3.5 → 0.3.7
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_c.rb +1 -1
- data/src/compile/c/a.out +0 -0
- data/src/compile/c/a.out.dSYM/Contents/Resources/DWARF/a.out +0 -0
- data/src/compile/c/excel_to_c_runtime.c +10 -0
- data/src/compile/c/excel_to_c_runtime_test.c +12 -0
- data/src/compile/c/map_formulae_to_c.rb +1 -0
- data/src/compile/ruby/map_formulae_to_ruby.rb +1 -0
- data/src/excel/excel_functions.rb +2 -0
- data/src/excel/excel_functions/iserror.rb +8 -0
- data/src/excel_to_code.rb +1 -1
- data/src/extract/extract_data_from_worksheet.rb +7 -2
- data/src/rewrite/caching_formula_parser.rb +31 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7790188e924f5410d21cd2f4a25add63744f644a
|
4
|
+
data.tar.gz: 0467aff30ed411418ec3e7bcd7d8ea7fe7e7774f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8252e23572c8d13b4a223404588ad457186fa5ce43e5f8727d573bf2377069a0b8abd8791d683991aca752f245bbee6490be19397927e96ed1950e16d1b5ef5
|
7
|
+
data.tar.gz: 84624066f10040b16124a07d1d94b0293685a44dec338ac06c8e29e5aca7d07c545b047523369ac1d3296316ef3de0699acc4ac48097164fdeaacb1166840ada
|
data/src/commands/excel_to_c.rb
CHANGED
@@ -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
|
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
|
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 };
|
data/src/excel_to_code.rb
CHANGED
@@ -80,8 +80,13 @@ class ExtractDataFromWorksheet < ::Ox::Sax
|
|
80
80
|
return if only_extract_values
|
81
81
|
|
82
82
|
unless @formula.empty?
|
83
|
-
|
84
|
-
|
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
|
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.
|
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:
|
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
|