Skip to content

Commit b70342a

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Make the diff algorithm handle within in new code
The code assumed that we would not be moving the code where it is diffed, so the within sort of had to match. Now we add the within in the source text and it won't show up in the diff but the white- space should be properly preserved. Belonging to [master]: - OpenModelica/OMCompiler#2998 - OpenModelica/OpenModelica-testsuite#1147
1 parent 759292c commit b70342a

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Compiler/Parsers/SimpleModelicaParser.mo

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import StringUtil;
4747
import MetaModelica.Dangerous.listReverseInPlace;
4848
import DoubleEndedList;
4949

50+
constant Token newlineToken = Token.TOKEN("", TokenId.NEWLINE, "\n", 1, 1, 1, 1, 1, 1);
51+
5052
public
5153

5254
uniontype ParseTree
@@ -87,19 +89,20 @@ function treeDiff
8789
protected
8890
list<tuple<Diff,list<ParseTree>>> res1, res2;
8991
ParseTree within1, within2;
90-
list<ParseTree> t2_updated;
92+
list<ParseTree> t1_updated, t2_updated;
9193
algorithm
9294
within1 := findWithin(t1);
9395
within2 := findWithin(t2);
9496
// If the new file lacks a within that was in the first file, pretend it is there
9597
// The other option is to preserve within in OMEdit...
96-
t2_updated := match (within1,within2)
97-
case (EMPTY(), EMPTY()) then t2;
98-
case (_, EMPTY()) then within1::t2;
99-
else t2;
98+
(t1_updated, t2_updated) := match (within1,within2)
99+
case (EMPTY(), EMPTY()) then (t1,t2);
100+
case (_, EMPTY()) then (t1, within1::t2);
101+
case (EMPTY(), _) then (within2::LEAF(newlineToken)::LEAF(newlineToken)::t1, t2);
102+
else (t1,t2);
100103
end match;
101-
t2_updated := moveComments(t1, t2_updated);
102-
res := treeDiffWork1(t1, t2_updated, nTokens);
104+
t2_updated := moveComments(t1_updated, t2_updated);
105+
res := treeDiffWork1(t1_updated, t2_updated, nTokens);
103106
res := moveCommentsAfterDiff(res);
104107
end treeDiff;
105108

0 commit comments

Comments
 (0)