lib/formulae/parse/formula_peg.rb in rubyfromexcel-0.0.4 vs lib/formulae/parse/formula_peg.rb in rubyfromexcel-0.0.5

- old
+ new

@@ -65,10 +65,14 @@ ignore { terminal("\"") } && terminal(/[^"]*/) && ignore { terminal("\"") } end end def any_reference + external_reference || any_internal_reference + end + + def any_internal_reference table_reference || local_table_reference || quoted_sheet_reference || sheet_reference || sheetless_reference end def percentage node :percentage do @@ -86,26 +90,36 @@ node :operator do terminal("+") || terminal("-") || terminal("/") || terminal("*") || terminal("^") end end + def external_reference + node :external_reference do + terminal(/\[\d+\]!?/) && any_internal_reference + end + end + def table_reference node :table_reference do - table_name && ignore { terminal("[") } && (complex_structured_reference || simple_structured_reference) && ignore { terminal("]") } + table_name && ignore { terminal("[") } && (range_structured_reference || complex_structured_reference || simple_structured_reference) && ignore { terminal("]") } end end def local_table_reference node :local_table_reference do - ignore { terminal("[") } && (complex_structured_reference || overly_structured_reference || simple_structured_reference) && ignore { terminal("]") } + ignore { terminal("[") } && (range_structured_reference || complex_structured_reference || overly_structured_reference || simple_structured_reference) && ignore { terminal("]") } end end def table_name terminal(/[.a-zA-Z0-9]+/) end + def range_structured_reference + terminal(/\[[^\u005d]*\],\[[^\u005d]*\]:\[[^\u005d]*\]/) + end + def complex_structured_reference terminal(/\[[^\u005d]*\],\[[^\u005d]*\]/) end def overly_structured_reference @@ -116,11 +130,11 @@ terminal(/[^\u005d]*/) end def named_reference node :named_reference do - terminal(/[a-zA-Z][\w_.]+/) + terminal(/[#a-zA-Z][\w_.!]+/) end end def quoted_sheet_reference node :quoted_sheet_reference do @@ -169,14 +183,14 @@ def row terminal(/\$?\d+/) end def column - terminal(/\$?[A-Z]+/) + terminal(/\$?[A-Za-z]{1,3}/) end def reference - terminal(/\$?[A-Z]+\$?[0-9]+/) + terminal(/\$?[A-Za-z]{1,3}\$?[0-9]+/) end def boolean boolean_true || boolean_false end