formula := space? expression+ expression = string_join | comparison | arithmetic | thing thing = percentage | function | array | brackets | any_reference | string | number | boolean | prefix | error | named_reference argument = expression | null function := /[a-zA-Z_]+/ `'(' space argument? (space `',' space argument)* space `')' brackets := `'(' space expression+ space `')' array := `'{' space row ( space `';' space row )* space `'}' row := basic_type ( space `',' space basic_type )* basic_type = string | percentage | number | boolean string_join := (arithmetic | thing) (space `“&” space (arithmetic | thing))+ arithmetic := thing (space operator space thing)+ comparison := (arithmetic | string_join | thing) space comparator space (arithmetic | string_join | thing) comparator := '>=' | '<=' | '<>' | '>' | '<' | '=' string := `'“' /(”“|[^”])*/ `'“' any_reference = external_reference | any_internal_reference any_internal_reference = table_reference | local_table_reference | sheet_reference | sheetless_reference percentage := (/[-+]?[0-9]+.?*/ | function) `'%' number := /[-+]?[0-9]+.?*([eE]?[0-9]+)?/ operator := '+' | '-' | '/' | '*' | '^' external_reference := /[d+]!?/ (any_internal_reference | named_reference) table_reference := table_name `'[' (range_structured_reference | short_range_structured_reference | complex_structured_reference | overly_structured_reference | simple_structured_reference) `']' local_table_reference := `'[' (range_structured_reference | short_range_structured_reference | complex_structured_reference | overly_structured_reference | simple_structured_reference) `']' table_name = /[.p{Word}_]+/ range_structured_reference = /[[^u005d]*],[*]:[[^u005d]*]/ short_range_structured_reference = /[[^u005d]*]:[*]/ complex_structured_reference = /[[^u005d]*],[*]/ overly_structured_reference = `'[' simple_structured_reference `']' simple_structured_reference = /[^u005d]*/ named_reference := /[#p{word}][p{word}_.!]+/ sheet_reference := (single_quoted_string | /[p{word}][p{word}_.]+/) `'!' (sheetless_reference | error | named_reference) single_quoted_string = `”'“ /[^']*/ `”'“ sheetless_reference = column_range | row_range | area | cell column_range := column `':' column row_range := row_number `':' row_number area := reference `':' reference cell := reference row_number = /$?d+/ column = /$?[A-Za-z]{1,3}/ reference = /$?[A-Za-z]{1,3}$?[0-9]+(?!)/ boolean = boolean_true | boolean_false boolean_true := `'TRUE' boolean_false := `'FALSE' prefix := /[-+]/ thing space = `/[ nr]*/ null := &',' error := '#REF!' | '#NAME?' | '#VALUE!' | '#DIV/0!' | '#N/A' | '#NUM!'