OOXML writes the union operator as the same comma that separates function arguments, so a union with no parentheses of its own fell apart on save: SUM(A1~B2) became SUM(A1,B2), which reads as two arguments, and INDEX(A1:B3~D1:E3;1;1;2) changed its meaning even on Calc's own reload. A union already inside a parenthesised group was safe, since the group's tokens are kept. The walk now records where the union-level expression of each parenthesis scope starts. The first union operator opens a list there, and the list takes one pair of parentheses when the expression ends: at a looser operator, an argument separator, the parenthesis that closes the scope, or the end of the formula. A list that fills a grouping parenthesis exactly keeps that pair, so a formula holds its shape over repeated round trips. Two kinds of parenthesis cannot be reused that way: the one behind AND, OR or the call operator, which opens an argument list rather than a group, and one that an @ wrapper beginning at the same place has already taken. The group check behind the @ wrapper refuses a group with a comma directly inside it, passing over the commas an inline matrix or a bracketed reference carries. Text that no parse could read takes no parentheses at all, so a list reaching such text drops its pair. Unit tests pin the written string for each union shape, and the positions the inserted parenthesis shifts. A round-trip test checks the saved XML and the reloaded formulas and values. Signed-off-by: Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> Change-Id: I970f3b4ecea680f6e70d146a2f1608c4adff9c1f Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/9308 Tested-by: Tomaž Vajngerl <tomaz.vajngerl@collabora.com> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> (cherry picked from commit dd8104342d7147f07006bebb1dbeec60b48250f6) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/209411 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org> Tested-by: Jenkins
Formula Helper Code
Contains parts of the formula parser used outside LibreOffice Calc code that has been pulled out from Calc's formula parser code.
Also contains some functions that are needed by code in both sc and
scaddins. Located here just for convenience. So sue me.