Skip to content

Commit

Permalink
Make the diff algorithm handle within in new code
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Mar 26, 2019
1 parent 759292c commit b70342a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Compiler/Parsers/SimpleModelicaParser.mo
Expand Up @@ -47,6 +47,8 @@ import StringUtil;
import MetaModelica.Dangerous.listReverseInPlace;
import DoubleEndedList;

constant Token newlineToken = Token.TOKEN("", TokenId.NEWLINE, "\n", 1, 1, 1, 1, 1, 1);

public

uniontype ParseTree
Expand Down Expand Up @@ -87,19 +89,20 @@ function treeDiff
protected
list<tuple<Diff,list<ParseTree>>> res1, res2;
ParseTree within1, within2;
list<ParseTree> t2_updated;
list<ParseTree> t1_updated, t2_updated;
algorithm
within1 := findWithin(t1);
within2 := findWithin(t2);
// If the new file lacks a within that was in the first file, pretend it is there
// The other option is to preserve within in OMEdit...
t2_updated := match (within1,within2)
case (EMPTY(), EMPTY()) then t2;
case (_, EMPTY()) then within1::t2;
else t2;
(t1_updated, t2_updated) := match (within1,within2)
case (EMPTY(), EMPTY()) then (t1,t2);
case (_, EMPTY()) then (t1, within1::t2);
case (EMPTY(), _) then (within2::LEAF(newlineToken)::LEAF(newlineToken)::t1, t2);
else (t1,t2);
end match;
t2_updated := moveComments(t1, t2_updated);
res := treeDiffWork1(t1, t2_updated, nTokens);
t2_updated := moveComments(t1_updated, t2_updated);
res := treeDiffWork1(t1_updated, t2_updated, nTokens);
res := moveCommentsAfterDiff(res);
end treeDiff;

Expand Down

0 comments on commit b70342a

Please sign in to comment.