Skip to content

Commit

Permalink
Fix printing of strings inside functions
Browse files Browse the repository at this point in the history
Previously we normalised all whitespace in printed out functions,
which would effect whitespace inside strings.
  • Loading branch information
ChrisJefferson committed May 6, 2021
1 parent d8fdd19 commit ada526c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/function.gi
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ end);

InstallMethod(String, "for a function, with whitespace reduced", [IsFunction and IsInternalRep],
function(fun)
local s, stream;
local s, stream,lines, pos, i;
s := "";
stream := OutputTextString(s, true);
SetPrintFormattingStatus(stream, false);
PrintTo(stream, fun);
CloseStream(stream);
NormalizeWhitespace(s);
return MakeImmutable(s);
return ReplacedString(s, "\n", " ");
end);

BIND_GLOBAL( "VIEW_STRING_OPERATION",
Expand Down
25 changes: 25 additions & 0 deletions tst/testinstall/function.tst
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,31 @@ gap> Print({x,y} -> x + y, "\n");
function ( x, y )
return x + y;
end
gap> String({x,y} -> x + y);
"function ( x, y ) return x + y; end"

# Test nesting
gap> Print(function(x) if x then if x then while x do od; fi; fi; end, "\n");
function ( x )
if x then
if x then
while x do
;
od;
fi;
fi;
return;
end
gap> String(function(x) if x then if x then while x do od; fi; fi; end);
"function ( x ) if x then if x then while x do ; od; fi; fi; return; end"

# Check strings in functions
gap> Print({x} -> "a b","\n");
function ( x )
return "a b";
end
gap> String({x} -> "a b");
"function ( x ) return \"a b\"; end"
gap> f := ({x,y} -> x + y);
function( x, y ) ... end
gap> f(2,3);
Expand Down

0 comments on commit ada526c

Please sign in to comment.