Class: Formula
- Inherits:
-
RubyPeg
- Object
- RubyPeg
- Formula
- Defined in:
- lib/formulae/parse/formula_peg.rb
Instance Method Summary collapse
- #any_internal_reference ⇒ Object
- #any_reference ⇒ Object
- #area ⇒ Object
- #argument ⇒ Object
- #arithmetic ⇒ Object
- #boolean ⇒ Object
- #boolean_false ⇒ Object
- #boolean_true ⇒ Object
- #brackets ⇒ Object
- #cell ⇒ Object
- #column ⇒ Object
- #column_range ⇒ Object
- #comparator ⇒ Object
- #comparison ⇒ Object
- #complex_structured_reference ⇒ Object
- #expression ⇒ Object
- #external_reference ⇒ Object
- #formula ⇒ Object
- #function ⇒ Object
- #local_table_reference ⇒ Object
- #named_reference ⇒ Object
- #null ⇒ Object
- #number ⇒ Object
- #operator ⇒ Object
- #overly_structured_reference ⇒ Object
- #percentage ⇒ Object
- #prefix ⇒ Object
- #quoted_sheet_reference ⇒ Object
- #range_structured_reference ⇒ Object
- #reference ⇒ Object
- #root ⇒ Object
- #row ⇒ Object
- #row_range ⇒ Object
- #sheet_reference ⇒ Object
- #sheetless_reference ⇒ Object
- #simple_structured_reference ⇒ Object
- #single_quoted_string ⇒ Object
- #space ⇒ Object
- #string ⇒ Object
- #string_join ⇒ Object
- #table_name ⇒ Object
- #table_reference ⇒ Object
- #thing ⇒ Object
Instance Method Details
#any_internal_reference ⇒ Object
74 75 76 |
# File 'lib/formulae/parse/formula_peg.rb', line 74 def any_internal_reference table_reference || local_table_reference || quoted_sheet_reference || sheet_reference || sheetless_reference end |
#any_reference ⇒ Object
70 71 72 |
# File 'lib/formulae/parse/formula_peg.rb', line 70 def any_reference external_reference || any_internal_reference end |
#area ⇒ Object
172 173 174 175 176 |
# File 'lib/formulae/parse/formula_peg.rb', line 172 def area node :area do reference && ignore { terminal(":") } && reference end end |
#argument ⇒ Object
24 25 26 |
# File 'lib/formulae/parse/formula_peg.rb', line 24 def argument expression || null end |
#arithmetic ⇒ Object
46 47 48 49 50 |
# File 'lib/formulae/parse/formula_peg.rb', line 46 def arithmetic node :arithmetic do thing && one_or_more { (space && operator && space && thing) } end end |
#boolean ⇒ Object
196 197 198 |
# File 'lib/formulae/parse/formula_peg.rb', line 196 def boolean boolean_true || boolean_false end |
#boolean_false ⇒ Object
206 207 208 209 210 |
# File 'lib/formulae/parse/formula_peg.rb', line 206 def boolean_false node :boolean_false do ignore { terminal("FALSE") } end end |
#boolean_true ⇒ Object
200 201 202 203 204 |
# File 'lib/formulae/parse/formula_peg.rb', line 200 def boolean_true node :boolean_true do ignore { terminal("TRUE") } end end |
#brackets ⇒ Object
34 35 36 37 38 |
# File 'lib/formulae/parse/formula_peg.rb', line 34 def brackets node :brackets do ignore { terminal("(") } && space && one_or_more { expression } && space && ignore { terminal(")") } end end |
#cell ⇒ Object
178 179 180 181 182 |
# File 'lib/formulae/parse/formula_peg.rb', line 178 def cell node :cell do reference end end |
#column ⇒ Object
188 189 190 |
# File 'lib/formulae/parse/formula_peg.rb', line 188 def column terminal(/\$?[A-Za-z]{1,3}/) end |
#column_range ⇒ Object
160 161 162 163 164 |
# File 'lib/formulae/parse/formula_peg.rb', line 160 def column_range node :column_range do column && ignore { terminal(":") } && column end end |
#comparator ⇒ Object
58 59 60 61 62 |
# File 'lib/formulae/parse/formula_peg.rb', line 58 def comparator node :comparator do terminal(">=") || terminal("<=") || terminal("<>") || terminal(">") || terminal("<") || terminal("=") end end |
#comparison ⇒ Object
52 53 54 55 56 |
# File 'lib/formulae/parse/formula_peg.rb', line 52 def comparison node :comparison do (arithmetic || thing) && space && comparator && space && (arithmetic || thing) end end |
#complex_structured_reference ⇒ Object
122 123 124 |
# File 'lib/formulae/parse/formula_peg.rb', line 122 def complex_structured_reference terminal(/\[[^\u005d]*\],\[[^\u005d]*\]/) end |
#expression ⇒ Object
16 17 18 |
# File 'lib/formulae/parse/formula_peg.rb', line 16 def expression string_join || comparison || arithmetic || thing end |
#external_reference ⇒ Object
96 97 98 99 100 |
# File 'lib/formulae/parse/formula_peg.rb', line 96 def external_reference node :external_reference do terminal(/\[\d+\]!?/) && any_internal_reference end end |
#formula ⇒ Object
10 11 12 13 14 |
# File 'lib/formulae/parse/formula_peg.rb', line 10 def formula node :formula do optional { space } && one_or_more { expression } end end |
#function ⇒ Object
28 29 30 31 32 |
# File 'lib/formulae/parse/formula_peg.rb', line 28 def function node :function do terminal(/[A-Z]+/) && ignore { terminal("(") } && space && optional { argument } && any_number_of { (space && ignore { terminal(",") } && space && argument) } && space && ignore { terminal(")") } end end |
#local_table_reference ⇒ Object
108 109 110 111 112 |
# File 'lib/formulae/parse/formula_peg.rb', line 108 def local_table_reference node :local_table_reference do ignore { terminal("[") } && (range_structured_reference || complex_structured_reference || overly_structured_reference || simple_structured_reference) && ignore { terminal("]") } end end |
#named_reference ⇒ Object
134 135 136 137 138 |
# File 'lib/formulae/parse/formula_peg.rb', line 134 def named_reference node :named_reference do terminal(/[\p{Word}#][\p{Word}.!]*/) end end |
#null ⇒ Object
222 223 224 225 226 |
# File 'lib/formulae/parse/formula_peg.rb', line 222 def null node :null do followed_by { terminal(",") } end end |
#number ⇒ Object
84 85 86 87 88 |
# File 'lib/formulae/parse/formula_peg.rb', line 84 def number node :number do terminal(/[-+]?[0-9]+\.?[0-9]*([eE][-+]?[0-9]+)?/) end end |
#operator ⇒ Object
90 91 92 93 94 |
# File 'lib/formulae/parse/formula_peg.rb', line 90 def operator node :operator do terminal("+") || terminal("-") || terminal("/") || terminal("*") || terminal("^") end end |
#overly_structured_reference ⇒ Object
126 127 128 |
# File 'lib/formulae/parse/formula_peg.rb', line 126 def overly_structured_reference ignore { terminal("[") } && simple_structured_reference && ignore { terminal("]") } end |
#percentage ⇒ Object
78 79 80 81 82 |
# File 'lib/formulae/parse/formula_peg.rb', line 78 def percentage node :percentage do terminal(/[-+]?[0-9]+\.?[0-9]*/) && ignore { terminal("%") } end end |
#prefix ⇒ Object
212 213 214 215 216 |
# File 'lib/formulae/parse/formula_peg.rb', line 212 def prefix node :prefix do terminal(/[-+]/) && thing end end |
#quoted_sheet_reference ⇒ Object
140 141 142 143 144 |
# File 'lib/formulae/parse/formula_peg.rb', line 140 def quoted_sheet_reference node :quoted_sheet_reference do single_quoted_string && ignore { terminal("!") } && (sheetless_reference || named_reference) end end |
#range_structured_reference ⇒ Object
118 119 120 |
# File 'lib/formulae/parse/formula_peg.rb', line 118 def range_structured_reference terminal(/\[[^\u005d]*\],\[[^\u005d]*\]:\[[^\u005d]*\]/) end |
#reference ⇒ Object
192 193 194 |
# File 'lib/formulae/parse/formula_peg.rb', line 192 def reference terminal(/\$?[A-Za-z]{1,3}\$?[0-9]+(?![0-9A-Za-z_])/) end |
#root ⇒ Object
6 7 8 |
# File 'lib/formulae/parse/formula_peg.rb', line 6 def root formula end |
#row ⇒ Object
184 185 186 |
# File 'lib/formulae/parse/formula_peg.rb', line 184 def row terminal(/\$?\d+/) end |
#row_range ⇒ Object
166 167 168 169 170 |
# File 'lib/formulae/parse/formula_peg.rb', line 166 def row_range node :row_range do row && ignore { terminal(":") } && row end end |
#sheet_reference ⇒ Object
146 147 148 149 150 |
# File 'lib/formulae/parse/formula_peg.rb', line 146 def sheet_reference node :sheet_reference do terminal(/[\p{Word}][\p{Word}_.]+/) && ignore { terminal("!") } && (sheetless_reference || named_reference) end end |
#sheetless_reference ⇒ Object
156 157 158 |
# File 'lib/formulae/parse/formula_peg.rb', line 156 def sheetless_reference column_range || row_range || area || cell end |
#simple_structured_reference ⇒ Object
130 131 132 |
# File 'lib/formulae/parse/formula_peg.rb', line 130 def simple_structured_reference terminal(/[^\u005d]*/) end |
#single_quoted_string ⇒ Object
152 153 154 |
# File 'lib/formulae/parse/formula_peg.rb', line 152 def single_quoted_string ignore { terminal("'") } && terminal(/[^']*/) && ignore { terminal("'") } end |
#space ⇒ Object
218 219 220 |
# File 'lib/formulae/parse/formula_peg.rb', line 218 def space ignore { terminal(/[ \n]*/) } end |
#string ⇒ Object
64 65 66 67 68 |
# File 'lib/formulae/parse/formula_peg.rb', line 64 def string node :string do ignore { terminal("\"") } && terminal(/(""|[^"])*/) && ignore { terminal("\"") } end end |
#string_join ⇒ Object
40 41 42 43 44 |
# File 'lib/formulae/parse/formula_peg.rb', line 40 def string_join node :string_join do (arithmetic || thing) && one_or_more { (space && ignore { terminal("&") } && space && (arithmetic || thing)) } end end |
#table_name ⇒ Object
114 115 116 |
# File 'lib/formulae/parse/formula_peg.rb', line 114 def table_name terminal(/[.\p{Word}]+/) end |
#table_reference ⇒ Object
102 103 104 105 106 |
# File 'lib/formulae/parse/formula_peg.rb', line 102 def table_reference node :table_reference do table_name && ignore { terminal("[") } && (range_structured_reference || complex_structured_reference || simple_structured_reference) && ignore { terminal("]") } end end |
#thing ⇒ Object
20 21 22 |
# File 'lib/formulae/parse/formula_peg.rb', line 20 def thing function || brackets || any_reference || string || percentage || number || boolean || prefix || named_reference end |