From 63733ca7f8b06e40c8de549a1ab99f508b4d13d5 Mon Sep 17 00:00:00 2001 From: Thomas Braun Date: Fri, 8 Sep 2023 21:12:44 +0200 Subject: [PATCH 1/2] SF_PreprocessInput: Make it clearer that we are iterating the lines wave --- Packages/MIES/MIES_SweepFormula.ipf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/MIES/MIES_SweepFormula.ipf b/Packages/MIES/MIES_SweepFormula.ipf index 42c17dbb1d..bce2f804b3 100644 --- a/Packages/MIES/MIES_SweepFormula.ipf +++ b/Packages/MIES/MIES_SweepFormula.ipf @@ -2290,7 +2290,7 @@ static Function/S SF_PreprocessInput(string formula) endsWithCR = StringEndsWith(formula, SF_CHAR_CR) WAVE/T lines = ListToTextWave(formula, SF_CHAR_CR) - lines = StringFromList(0, lines[p], SF_CHAR_COMMENT) + lines[] = StringFromList(0, lines[p], SF_CHAR_COMMENT) formula = TextWaveToList(lines, SF_CHAR_CR) if(IsEmpty(formula)) return "" From 680bb87a7aa6a2a4d859c8dff1d31f8838958702 Mon Sep 17 00:00:00 2001 From: Thomas Braun Date: Fri, 8 Sep 2023 21:20:20 +0200 Subject: [PATCH 2/2] SF_PreprocessInput: Remove trailing whitespace to avoid bugging out with variable assignments The newly added test case fails without the fix in SF_PreprocessInput. We search for all variable statements in the preprocessed code in SF_GetVariableAssignments called via SF_ExecuteVariableAssignments. And we abort the variable search, as there is no explicit boundary between variables and operations, once we could not read a line as variables. And trailing whitespace in a line is not a valid variable statements, therefore we bug out with a message like "Only one operation are allowed" or other assertion messages from SF_FormulaExecutor. We now remove trailing whitespace in the SF code preprocessor. --- Packages/MIES/MIES_SweepFormula.ipf | 1 + Packages/tests/UTF_DataGenerators.ipf | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Packages/MIES/MIES_SweepFormula.ipf b/Packages/MIES/MIES_SweepFormula.ipf index bce2f804b3..b8e7c3c6b5 100644 --- a/Packages/MIES/MIES_SweepFormula.ipf +++ b/Packages/MIES/MIES_SweepFormula.ipf @@ -2291,6 +2291,7 @@ static Function/S SF_PreprocessInput(string formula) WAVE/T lines = ListToTextWave(formula, SF_CHAR_CR) lines[] = StringFromList(0, lines[p], SF_CHAR_COMMENT) + lines[] = RemoveEndingRegExp(lines[p], "[[:space:]]+$") formula = TextWaveToList(lines, SF_CHAR_CR) if(IsEmpty(formula)) return "" diff --git a/Packages/tests/UTF_DataGenerators.ipf b/Packages/tests/UTF_DataGenerators.ipf index 166e069681..4b025c2fb2 100644 --- a/Packages/tests/UTF_DataGenerators.ipf +++ b/Packages/tests/UTF_DataGenerators.ipf @@ -242,12 +242,18 @@ static Function/WAVE SF_TestVariablesGen() Make/FREE/T t4DimLbl = {"b"} Make/FREE/T t4Result = {"a$b=1"} +// does not bug out with trailing whitespace + Make/FREE/T t5FormulaAndRest = {"a=[1]\r \rb=$a\r\r$b", "$b"} + t5FormulaAndRest[] = MIES_SF#SF_PreprocessInput(t5FormulaAndRest[p]) + Make/FREE/T t5DimLbl = {"a", "b"} + Make/FREE/WAVE t1 = {t1FormulaAndRest, t1DimLbl, $""} Make/FREE/WAVE t2 = {t2FormulaAndRest, t2DimLbl, $""} Make/FREE/WAVE t3 = {t3FormulaAndRest, t3DimLbl, t3Result} Make/FREE/WAVE t4 = {t4FormulaAndRest, t4DimLbl, t4Result} + Make/FREE/WAVE t5 = {t5FormulaAndRest, t5DimLbl, $""} - Make/FREE/WAVE wv = {t1, t2, t3, t4} + Make/FREE/WAVE wv = {t1, t2, t3, t4, t5} return wv End