Skip to content

Commit

Permalink
SF_PreprocessInput: Remove trailing whitespace to avoid bugging out w…
Browse files Browse the repository at this point in the history
…ith 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.
  • Loading branch information
t-b committed Sep 9, 2023
1 parent 63733ca commit 680bb87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions Packages/MIES/MIES_SweepFormula.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
8 changes: 7 additions & 1 deletion Packages/tests/UTF_DataGenerators.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 680bb87

Please sign in to comment.