@@ -2309,7 +2309,7 @@ algorithm
23092309 // print(String(diffEnum) + ":\n");
23102310 // print(parseTreeStr(tree));
23112311 // print("\n");
2312- (_ , treeLast) := List . first(diffLocal);
2312+ (diffEnum , treeLast) := List . first(diffLocal);
23132313 (firstTreeSecondLast, firstTreeLast) := match treeLast
23142314 case {} then (EMPTY (),EMPTY ());
23152315 case {firstTreeLast} then (EMPTY (),firstTreeLast);
@@ -2423,6 +2423,14 @@ algorithm
24232423 case ((diffEnum1,tree1)::(diffEnum2, tree2)::diffLocal)
24242424 guard diffEnum1== diffEnum2
24252425 then (diffEnum1, listAppend(tree1, tree2))::diffLocal;
2426+
2427+ // ADD(WS) NEWLINE => NEWLINE
2428+ case (Diff . Add ,tree1)::(diffLocal as ((Diff . Equal ,tree2)::_))
2429+ guard tokenId(lastToken(firstTreeLast))== TokenId . WHITESPACE and tokenId(firstToken(tree2))== TokenId . NEWLINE
2430+ algorithm
2431+ diff := (Diff . Add ,removeLastTokenInTrees(tree1))::diff;
2432+ then diffLocal;
2433+
24262434 // A normal tree :)
24272435 case diff1::diffLocal
24282436 algorithm
@@ -2438,7 +2446,7 @@ algorithm
24382446 hasAddedWS := false ;
24392447 for d in diff loop
24402448 _ := match d
2441- case (Diff . Add ,_ )
2449+ case (Diff . Add ,tree )
24422450 algorithm
24432451 for t in tree loop
24442452 _ := match firstNTokensInTree_reverse(t, 2 )
@@ -2834,7 +2842,7 @@ function lastToken
28342842 output Token token;
28352843algorithm
28362844 token := match t
2837- case EMPTY () then fail();
2845+ case EMPTY () algorithm if debug then print( "lastToken fail \n " ); end if ; then fail();
28382846 case LEAF () then t. token;
28392847 case NODE () then lastToken(List . last(t. nodes));
28402848 end match;
@@ -2900,7 +2908,7 @@ function makeNode
29002908 input ParseTree label = EMPTY ();
29012909 output ParseTree node;
29022910algorithm
2903- node := match (nodes,label )
2911+ node := match (list(n for n guard not isEmpty(n) in nodes) ,label )
29042912 case ({},EMPTY ()) then EMPTY ();
29052913 case ({node},EMPTY ()) then node;
29062914 else NODE (label , nodes);
0 commit comments