excel_to_code 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +41 -0
- data/bin/excel_to_c +63 -0
- data/bin/excel_to_ruby +9 -0
- data/src/commands.rb +2 -0
- data/src/commands/excel_to_c.rb +858 -0
- data/src/commands/excel_to_ruby.rb +620 -0
- data/src/compile.rb +2 -0
- data/src/compile/c.rb +5 -0
- data/src/compile/c/compile_to_c.rb +62 -0
- data/src/compile/c/compile_to_c_header.rb +26 -0
- data/src/compile/c/compile_to_c_unit_test.rb +42 -0
- data/src/compile/c/excel_to_c_runtime.c +2029 -0
- data/src/compile/c/map_formulae_to_c.rb +184 -0
- data/src/compile/c/map_sheet_names_to_c_names.rb +19 -0
- data/src/compile/c/map_values_to_c.rb +85 -0
- data/src/compile/c/map_values_to_c_structs.rb +37 -0
- data/src/compile/ruby.rb +3 -0
- data/src/compile/ruby/compile_to_ruby.rb +33 -0
- data/src/compile/ruby/compile_to_ruby_unit_test.rb +28 -0
- data/src/compile/ruby/excel_to_ruby_runtime.rb +1 -0
- data/src/compile/ruby/map_formulae_to_ruby.rb +95 -0
- data/src/compile/ruby/map_sheet_names_to_ruby_names.rb +19 -0
- data/src/compile/ruby/map_values_to_ruby.rb +65 -0
- data/src/excel.rb +5 -0
- data/src/excel/area.rb +93 -0
- data/src/excel/excel_functions.rb +84 -0
- data/src/excel/excel_functions/abs.rb +14 -0
- data/src/excel/excel_functions/add.rb +18 -0
- data/src/excel/excel_functions/and.rb +30 -0
- data/src/excel/excel_functions/apply_to_range.rb +17 -0
- data/src/excel/excel_functions/average.rb +12 -0
- data/src/excel/excel_functions/choose.rb +18 -0
- data/src/excel/excel_functions/cosh.rb +9 -0
- data/src/excel/excel_functions/count.rb +9 -0
- data/src/excel/excel_functions/counta.rb +8 -0
- data/src/excel/excel_functions/divide.rb +23 -0
- data/src/excel/excel_functions/excel_equal.rb +20 -0
- data/src/excel/excel_functions/excel_if.rb +8 -0
- data/src/excel/excel_functions/excel_match.rb +51 -0
- data/src/excel/excel_functions/find.rb +39 -0
- data/src/excel/excel_functions/iferror.rb +10 -0
- data/src/excel/excel_functions/index.rb +48 -0
- data/src/excel/excel_functions/left.rb +12 -0
- data/src/excel/excel_functions/less_than.rb +26 -0
- data/src/excel/excel_functions/less_than_or_equal.rb +26 -0
- data/src/excel/excel_functions/max.rb +12 -0
- data/src/excel/excel_functions/min.rb +12 -0
- data/src/excel/excel_functions/mod.rb +15 -0
- data/src/excel/excel_functions/more_than.rb +26 -0
- data/src/excel/excel_functions/more_than_or_equal.rb +26 -0
- data/src/excel/excel_functions/multiply.rb +24 -0
- data/src/excel/excel_functions/negative.rb +12 -0
- data/src/excel/excel_functions/not_equal.rb +19 -0
- data/src/excel/excel_functions/number_argument.rb +30 -0
- data/src/excel/excel_functions/pi.rb +7 -0
- data/src/excel/excel_functions/pmt.rb +16 -0
- data/src/excel/excel_functions/power.rb +18 -0
- data/src/excel/excel_functions/round.rb +13 -0
- data/src/excel/excel_functions/rounddown.rb +14 -0
- data/src/excel/excel_functions/roundup.rb +17 -0
- data/src/excel/excel_functions/string_join.rb +19 -0
- data/src/excel/excel_functions/subtotal.rb +13 -0
- data/src/excel/excel_functions/subtract.rb +18 -0
- data/src/excel/excel_functions/sum.rb +8 -0
- data/src/excel/excel_functions/sumif.rb +7 -0
- data/src/excel/excel_functions/sumifs.rb +74 -0
- data/src/excel/excel_functions/sumproduct.rb +32 -0
- data/src/excel/excel_functions/vlookup.rb +49 -0
- data/src/excel/formula_peg.rb +238 -0
- data/src/excel/formula_peg.txt +45 -0
- data/src/excel/reference.rb +56 -0
- data/src/excel/table.rb +108 -0
- data/src/excel_to_code.rb +7 -0
- data/src/extract.rb +13 -0
- data/src/extract/check_for_unknown_functions.rb +20 -0
- data/src/extract/extract_array_formulae.rb +23 -0
- data/src/extract/extract_formulae.rb +36 -0
- data/src/extract/extract_named_references.rb +38 -0
- data/src/extract/extract_relationships.rb +10 -0
- data/src/extract/extract_shared_formulae.rb +23 -0
- data/src/extract/extract_shared_strings.rb +20 -0
- data/src/extract/extract_simple_formulae.rb +18 -0
- data/src/extract/extract_table.rb +24 -0
- data/src/extract/extract_values.rb +29 -0
- data/src/extract/extract_worksheet_dimensions.rb +11 -0
- data/src/extract/extract_worksheet_names.rb +10 -0
- data/src/extract/extract_worksheet_table_relationships.rb +10 -0
- data/src/extract/simple_extract_from_xml.rb +19 -0
- data/src/rewrite.rb +10 -0
- data/src/rewrite/ast_copy_formula.rb +42 -0
- data/src/rewrite/ast_expand_array_formulae.rb +180 -0
- data/src/rewrite/rewrite_array_formulae.rb +71 -0
- data/src/rewrite/rewrite_array_formulae_to_arrays.rb +18 -0
- data/src/rewrite/rewrite_cell_references_to_include_sheet.rb +56 -0
- data/src/rewrite/rewrite_formulae_to_ast.rb +24 -0
- data/src/rewrite/rewrite_merge_formulae_and_values.rb +18 -0
- data/src/rewrite/rewrite_relationship_id_to_filename.rb +22 -0
- data/src/rewrite/rewrite_shared_formulae.rb +38 -0
- data/src/rewrite/rewrite_values_to_ast.rb +28 -0
- data/src/rewrite/rewrite_whole_row_column_references_to_areas.rb +90 -0
- data/src/rewrite/rewrite_worksheet_names.rb +20 -0
- data/src/simplify.rb +16 -0
- data/src/simplify/count_formula_references.rb +58 -0
- data/src/simplify/identify_dependencies.rb +56 -0
- data/src/simplify/identify_repeated_formula_elements.rb +37 -0
- data/src/simplify/inline_formulae.rb +77 -0
- data/src/simplify/map_formulae_to_values.rb +157 -0
- data/src/simplify/remove_cells.rb +18 -0
- data/src/simplify/replace_arrays_with_single_cells.rb +27 -0
- data/src/simplify/replace_blanks.rb +58 -0
- data/src/simplify/replace_common_elements_in_formulae.rb +19 -0
- data/src/simplify/replace_formulae_with_calculated_values.rb +21 -0
- data/src/simplify/replace_indirects_with_references.rb +44 -0
- data/src/simplify/replace_named_references.rb +82 -0
- data/src/simplify/replace_ranges_with_array_literals.rb +54 -0
- data/src/simplify/replace_shared_strings.rb +49 -0
- data/src/simplify/replace_table_references.rb +71 -0
- data/src/simplify/replace_values_with_constants.rb +47 -0
- data/src/simplify/simplify_arithmetic.rb +54 -0
- data/src/util.rb +2 -0
- data/src/util/not_supported_exception.rb +2 -0
- data/src/util/try.rb +9 -0
- metadata +207 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
module ExcelFunctions
|
2
|
+
|
3
|
+
def pmt(rate,number_of_periods,present_value)
|
4
|
+
rate = number_argument(rate)
|
5
|
+
number_of_periods = number_argument(number_of_periods)
|
6
|
+
present_value = number_argument(present_value)
|
7
|
+
|
8
|
+
return rate if rate.is_a?(Symbol)
|
9
|
+
return number_of_periods if number_of_periods.is_a?(Symbol)
|
10
|
+
return present_value if present_value.is_a?(Symbol)
|
11
|
+
|
12
|
+
return -(present_value / number_of_periods) if rate == 0
|
13
|
+
-present_value*(rate*((1+rate)**number_of_periods))/(((1+rate)**number_of_periods)-1)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'number_argument'
|
2
|
+
require_relative 'apply_to_range'
|
3
|
+
|
4
|
+
module ExcelFunctions
|
5
|
+
|
6
|
+
def power(a,b)
|
7
|
+
# return apply_to_range(a,b) { |a,b| power(a,b) } if a.is_a?(Array) || b.is_a?(Array)
|
8
|
+
|
9
|
+
a = number_argument(a)
|
10
|
+
b = number_argument(b)
|
11
|
+
|
12
|
+
return a if a.is_a?(Symbol)
|
13
|
+
return b if b.is_a?(Symbol)
|
14
|
+
|
15
|
+
a**b
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ExcelFunctions
|
2
|
+
|
3
|
+
def round(number,decimal_places)
|
4
|
+
number = number_argument(number)
|
5
|
+
decimal_places = number_argument(decimal_places)
|
6
|
+
|
7
|
+
return number if number.is_a?(Symbol)
|
8
|
+
return decimal_places if decimal_places.is_a?(Symbol)
|
9
|
+
|
10
|
+
number.round(decimal_places)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ExcelFunctions
|
2
|
+
|
3
|
+
def rounddown(number,decimal_places)
|
4
|
+
number = number_argument(number)
|
5
|
+
decimal_places = number_argument(decimal_places)
|
6
|
+
|
7
|
+
return number if number.is_a?(Symbol)
|
8
|
+
return decimal_places if decimal_places.is_a?(Symbol)
|
9
|
+
|
10
|
+
(number * 10**decimal_places).truncate.to_f / 10**decimal_places
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ExcelFunctions
|
2
|
+
|
3
|
+
def roundup(number,decimal_places)
|
4
|
+
number = number_argument(number)
|
5
|
+
decimal_places = number_argument(decimal_places)
|
6
|
+
|
7
|
+
return number if number.is_a?(Symbol)
|
8
|
+
return decimal_places if decimal_places.is_a?(Symbol)
|
9
|
+
|
10
|
+
if number < 0
|
11
|
+
(number * 10**decimal_places).floor.to_f / 10**decimal_places
|
12
|
+
else
|
13
|
+
(number * 10**decimal_places).ceil.to_f / 10**decimal_places
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ExcelFunctions
|
2
|
+
|
3
|
+
def string_join(*strings)
|
4
|
+
strings.find {|s| s.is_a?(Symbol)} || strings.map do |s|
|
5
|
+
case s
|
6
|
+
when nil; "0"
|
7
|
+
when Numeric
|
8
|
+
if s.round == s
|
9
|
+
s.to_i.to_s
|
10
|
+
else
|
11
|
+
s.to_s
|
12
|
+
end
|
13
|
+
else
|
14
|
+
s.to_s
|
15
|
+
end
|
16
|
+
end.join('')
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ExcelFunctions
|
2
|
+
|
3
|
+
def subtotal(type,*args)
|
4
|
+
case number_argument(type)
|
5
|
+
when Symbol; type
|
6
|
+
when 1.0, 101.0; average(*args)
|
7
|
+
when 2.0, 102.0; count(*args)
|
8
|
+
when 3.0, 103.0; counta(*args)
|
9
|
+
when 9.0, 109.0; sum(*args)
|
10
|
+
else :value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'number_argument'
|
2
|
+
require_relative 'apply_to_range'
|
3
|
+
|
4
|
+
module ExcelFunctions
|
5
|
+
|
6
|
+
def subtract(a,b)
|
7
|
+
# return apply_to_range(a,b) { |a,b| subtract(a,b) } if a.is_a?(Array) || b.is_a?(Array)
|
8
|
+
|
9
|
+
a = number_argument(a)
|
10
|
+
b = number_argument(b)
|
11
|
+
|
12
|
+
return a if a.is_a?(Symbol)
|
13
|
+
return b if b.is_a?(Symbol)
|
14
|
+
|
15
|
+
a - b
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module ExcelFunctions
|
2
|
+
|
3
|
+
def sumifs(sum_range,*criteria)
|
4
|
+
# First, get rid of the errors
|
5
|
+
return sum_range if sum_range.is_a?(Symbol)
|
6
|
+
error = criteria.find { |a| a.is_a?(Symbol) }
|
7
|
+
return error if error
|
8
|
+
|
9
|
+
# Sort out the sum range
|
10
|
+
sum_range = [sum_range] unless sum_range.is_a?(Array)
|
11
|
+
sum_range = sum_range.flatten
|
12
|
+
|
13
|
+
# Sort out the criteria
|
14
|
+
0.step(criteria.length-1,2).each do |i|
|
15
|
+
if criteria[i].is_a?(Array)
|
16
|
+
criteria[i] = criteria[i].flatten
|
17
|
+
else
|
18
|
+
criteria[i] = [criteria[i]]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# This will be the final answer
|
23
|
+
accumulator = 0
|
24
|
+
|
25
|
+
# Work through each part of the sum range
|
26
|
+
sum_range.each_with_index do |potential_sum,index|
|
27
|
+
next unless potential_sum.is_a?(Numeric)
|
28
|
+
|
29
|
+
# If a criteria fails, this is set to false and no further criteria are evaluated
|
30
|
+
pass = true
|
31
|
+
|
32
|
+
0.step(criteria.length-1,2).each do |i|
|
33
|
+
check_range = criteria[i]
|
34
|
+
required_value = criteria[i+1]
|
35
|
+
return :value if index >= check_range.length
|
36
|
+
check_value = check_range[index]
|
37
|
+
|
38
|
+
pass = case check_value
|
39
|
+
when String
|
40
|
+
check_value.downcase == required_value.to_s.downcase
|
41
|
+
when true, false
|
42
|
+
check_value == required_value
|
43
|
+
when nil
|
44
|
+
required_value == ""
|
45
|
+
when Numeric
|
46
|
+
case required_value
|
47
|
+
when Numeric
|
48
|
+
check_value == required_value
|
49
|
+
when String
|
50
|
+
required_value =~ /^(<=|>=|<|>)?([-+]?[0-9]+\.?[0-9]*([eE][-+]?[0-9]+)?)$/
|
51
|
+
if $1 && $2
|
52
|
+
check_value.send($1,$2.to_f)
|
53
|
+
elsif $2
|
54
|
+
check_value == $2.to_f
|
55
|
+
else
|
56
|
+
false
|
57
|
+
end
|
58
|
+
else
|
59
|
+
check_value == required_value
|
60
|
+
end
|
61
|
+
end # case check_value
|
62
|
+
|
63
|
+
break unless pass
|
64
|
+
end # criteria loop
|
65
|
+
|
66
|
+
accumulator += potential_sum if pass
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
return accumulator
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ExcelFunctions
|
2
|
+
|
3
|
+
def sumproduct(*args)
|
4
|
+
error = args.find { |a| a.is_a?(Symbol) }
|
5
|
+
return error if error
|
6
|
+
return :value if args.any? { |a| a == nil }
|
7
|
+
args = args.map { |a| a.is_a?(Array) ? a : [[a]] }
|
8
|
+
first = args.shift
|
9
|
+
accumulator = 0
|
10
|
+
first.each_with_index do |row,row_number|
|
11
|
+
row.each_with_index do |cell,column_number|
|
12
|
+
next unless cell.is_a?(Numeric)
|
13
|
+
product = cell
|
14
|
+
args.each do |area|
|
15
|
+
return :value unless area.length > row_number
|
16
|
+
r = area[row_number]
|
17
|
+
return :value unless r.length > column_number
|
18
|
+
c = r[column_number]
|
19
|
+
if c.is_a?(Numeric)
|
20
|
+
product = product * c
|
21
|
+
else
|
22
|
+
product = product * 0
|
23
|
+
break
|
24
|
+
end
|
25
|
+
end
|
26
|
+
accumulator += product
|
27
|
+
end
|
28
|
+
end
|
29
|
+
accumulator
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module ExcelFunctions
|
2
|
+
|
3
|
+
def vlookup(lookup_value,lookup_table,column_number, match_type = true)
|
4
|
+
return lookup_value if lookup_value.is_a?(Symbol)
|
5
|
+
return lookup_table if lookup_table.is_a?(Symbol)
|
6
|
+
return column_number if column_number.is_a?(Symbol)
|
7
|
+
return match_type if match_type.is_a?(Symbol)
|
8
|
+
|
9
|
+
return :na if lookup_value == nil
|
10
|
+
return :na if lookup_table == nil
|
11
|
+
return :na if column_number == nil
|
12
|
+
return :na if match_type == nil
|
13
|
+
|
14
|
+
lookup_value = lookup_value.downcase if lookup_value.is_a?(String)
|
15
|
+
|
16
|
+
last_good_match = 0
|
17
|
+
|
18
|
+
lookup_table.each_with_index do |row,index|
|
19
|
+
possible_match = row.first
|
20
|
+
|
21
|
+
next if lookup_value.is_a?(String) && !possible_match.is_a?(String)
|
22
|
+
next if lookup_value.is_a?(Numeric) && !possible_match.is_a?(Numeric)
|
23
|
+
|
24
|
+
possible_match.downcase! if lookup_value.is_a?(String)
|
25
|
+
|
26
|
+
if lookup_value == possible_match
|
27
|
+
return :value unless column_number <= row.length
|
28
|
+
return row[column_number-1]
|
29
|
+
elsif match_type == true
|
30
|
+
if possible_match > lookup_value
|
31
|
+
return :na if index == 0
|
32
|
+
previous_row = lookup_table[last_good_match]
|
33
|
+
return :value unless column_number <= previous_row.length
|
34
|
+
return previous_row[column_number-1]
|
35
|
+
else
|
36
|
+
last_good_match = index
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# We don't have a match
|
42
|
+
if match_type == true
|
43
|
+
return lookup_table[last_good_match][column_number-1]
|
44
|
+
else
|
45
|
+
return :na
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,238 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubypeg'
|
3
|
+
|
4
|
+
class Formula < RubyPeg
|
5
|
+
|
6
|
+
def root
|
7
|
+
formula
|
8
|
+
end
|
9
|
+
|
10
|
+
def formula
|
11
|
+
node :formula do
|
12
|
+
optional { space } && one_or_more { expression }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def expression
|
17
|
+
string_join || comparison || arithmetic || thing
|
18
|
+
end
|
19
|
+
|
20
|
+
def thing
|
21
|
+
function || array || brackets || any_reference || string || percentage || number || boolean || prefix || named_reference
|
22
|
+
end
|
23
|
+
|
24
|
+
def argument
|
25
|
+
expression || null
|
26
|
+
end
|
27
|
+
|
28
|
+
def function
|
29
|
+
node :function do
|
30
|
+
terminal(/[A-Z]+/) && ignore { terminal("(") } && space && optional { argument } && any_number_of { (space && ignore { terminal(",") } && space && argument) } && space && ignore { terminal(")") }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def brackets
|
35
|
+
node :brackets do
|
36
|
+
ignore { terminal("(") } && space && one_or_more { expression } && space && ignore { terminal(")") }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def array
|
41
|
+
node :array do
|
42
|
+
ignore { terminal("{") } && space && row && any_number_of { (space && ignore { terminal(";") } && space && row) } && space && ignore { terminal("}") }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def row
|
47
|
+
node :row do
|
48
|
+
basic_type && any_number_of { (space && ignore { terminal(",") } && space && basic_type) }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def basic_type
|
53
|
+
string || percentage || number || boolean
|
54
|
+
end
|
55
|
+
|
56
|
+
def string_join
|
57
|
+
node :string_join do
|
58
|
+
(arithmetic || thing) && one_or_more { (space && ignore { terminal("&") } && space && (arithmetic || thing)) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def arithmetic
|
63
|
+
node :arithmetic do
|
64
|
+
thing && one_or_more { (space && operator && space && thing) }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def comparison
|
69
|
+
node :comparison do
|
70
|
+
(arithmetic || thing) && space && comparator && space && (arithmetic || thing)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def comparator
|
75
|
+
node :comparator do
|
76
|
+
terminal(">=") || terminal("<=") || terminal("<>") || terminal(">") || terminal("<") || terminal("=")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def string
|
81
|
+
node :string do
|
82
|
+
ignore { terminal("\"") } && terminal(/(""|[^"])*/) && ignore { terminal("\"") }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def any_reference
|
87
|
+
external_reference || any_internal_reference
|
88
|
+
end
|
89
|
+
|
90
|
+
def any_internal_reference
|
91
|
+
table_reference || local_table_reference || sheet_reference || sheetless_reference
|
92
|
+
end
|
93
|
+
|
94
|
+
def percentage
|
95
|
+
node :percentage do
|
96
|
+
terminal(/[-+]?[0-9]+\.?[0-9]*/) && ignore { terminal("%") }
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def number
|
101
|
+
node :number do
|
102
|
+
terminal(/[-+]?[0-9]+\.?[0-9]*([eE][-+]?[0-9]+)?/)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def operator
|
107
|
+
node :operator do
|
108
|
+
terminal("+") || terminal("-") || terminal("/") || terminal("*") || terminal("^")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def external_reference
|
113
|
+
node :external_reference do
|
114
|
+
terminal(/\[\d+\]!?/) && any_internal_reference
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def table_reference
|
119
|
+
node :table_reference do
|
120
|
+
table_name && ignore { terminal("[") } && (range_structured_reference || complex_structured_reference || simple_structured_reference) && ignore { terminal("]") }
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def local_table_reference
|
125
|
+
node :local_table_reference do
|
126
|
+
ignore { terminal("[") } && (range_structured_reference || complex_structured_reference || overly_structured_reference || simple_structured_reference) && ignore { terminal("]") }
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def table_name
|
131
|
+
terminal(/[.a-zA-Z0-9_]+/)
|
132
|
+
end
|
133
|
+
|
134
|
+
def range_structured_reference
|
135
|
+
terminal(/\[[^\u005d]*\],\[[^\u005d]*\]:\[[^\u005d]*\]/)
|
136
|
+
end
|
137
|
+
|
138
|
+
def complex_structured_reference
|
139
|
+
terminal(/\[[^\u005d]*\],\[[^\u005d]*\]/)
|
140
|
+
end
|
141
|
+
|
142
|
+
def overly_structured_reference
|
143
|
+
ignore { terminal("[") } && simple_structured_reference && ignore { terminal("]") }
|
144
|
+
end
|
145
|
+
|
146
|
+
def simple_structured_reference
|
147
|
+
terminal(/[^\u005d]*/)
|
148
|
+
end
|
149
|
+
|
150
|
+
def named_reference
|
151
|
+
node :named_reference do
|
152
|
+
terminal(/[#a-zA-Z][\w_.!]+/)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def sheet_reference
|
157
|
+
node :sheet_reference do
|
158
|
+
(single_quoted_string || terminal(/[a-zA-Z0-9][\w_.]+/)) && ignore { terminal("!") } && (sheetless_reference || named_reference)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def single_quoted_string
|
163
|
+
ignore { terminal("'") } && terminal(/[^']*/) && ignore { terminal("'") }
|
164
|
+
end
|
165
|
+
|
166
|
+
def sheetless_reference
|
167
|
+
column_range || row_range || area || cell
|
168
|
+
end
|
169
|
+
|
170
|
+
def column_range
|
171
|
+
node :column_range do
|
172
|
+
column && ignore { terminal(":") } && column
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def row_range
|
177
|
+
node :row_range do
|
178
|
+
row_number && ignore { terminal(":") } && row_number
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def area
|
183
|
+
node :area do
|
184
|
+
reference && ignore { terminal(":") } && reference
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def cell
|
189
|
+
node :cell do
|
190
|
+
reference
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def row_number
|
195
|
+
terminal(/\$?\d+/)
|
196
|
+
end
|
197
|
+
|
198
|
+
def column
|
199
|
+
terminal(/\$?[A-Za-z]{1,3}/)
|
200
|
+
end
|
201
|
+
|
202
|
+
def reference
|
203
|
+
terminal(/\$?[A-Za-z]{1,3}\$?[0-9]+(?![0-9A-Za-z_])/)
|
204
|
+
end
|
205
|
+
|
206
|
+
def boolean
|
207
|
+
boolean_true || boolean_false
|
208
|
+
end
|
209
|
+
|
210
|
+
def boolean_true
|
211
|
+
node :boolean_true do
|
212
|
+
ignore { terminal("TRUE") }
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def boolean_false
|
217
|
+
node :boolean_false do
|
218
|
+
ignore { terminal("FALSE") }
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def prefix
|
223
|
+
node :prefix do
|
224
|
+
terminal(/[-+]/) && thing
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def space
|
229
|
+
ignore { terminal(/[ \n]*/) }
|
230
|
+
end
|
231
|
+
|
232
|
+
def null
|
233
|
+
node :null do
|
234
|
+
followed_by { terminal(",") }
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|