google / codeworld

Educational computer programming environment using Haskell
http://code.world
Apache License 2.0
1.24k stars 193 forks source link

Better formatting for the Inspect dialog #725

Open cdsmith opened 6 years ago

cdsmith commented 6 years ago

Unfortunately, @kammitama5 adding properties to the inspect dialog, while useful, made it a bit ugly and harder to read.

Some ideas for cleaning this up:

cdsmith commented 6 years ago

Another important improvement would be to distinguish between & and pictures. They can remain the same constructor, but would need to be represented differently if expressions are displayed in source form.

At the same time, we can also do better at not collapsing & chains with explicit pictures calls. That is, today, a & pictures [b, c, d] will result in Pictures ... [a, b, c, d]. This isn't a faithful representation of the source code. If we knew that [b, c, d] was an explicit application of pictures, then we could avoid fusing an & onto it, and end up with Pictures ... [a, Pictures ... [b, c, d]], as expected.

This isn't a complete solution. We'd still fail at this example:

face = eyes & nose & mouth
eyes = leftEye & rightEye

I'd hope to see Pictures ... [Pictures ... [leftEye, rightEye], nose, mouth], but instead we get a flat list. This is a harder problem to solve, though.

cdsmith commented 6 years ago

The current source formatting should be almost entirely compatible with HTML, unless there are string literals that look like HTML markup. So one plan could be to switch the client to interpret labels as HTML, first, and then switch the codeworld-api library to start emitting better markup, including the tooltips and type-specific formatting. This seems better than inventing a whole new language for argument lists just to support formatting.

cdsmith commented 5 years ago

I've now fixed the issue with & versus pictures. Checking for overlap in the call stack let me do a much better job than I even expected, so expressions like a & b where b = b1 & b2 are properly grouped. (This case is detected because the SrcLoc of the right-hand side is not contained within the SrcLoc of the top-level & expression.)

cdsmith commented 5 years ago

Remaining tasks: