Brittany can't cope with -XTupleSections
#41
Labels
No Label
blocked: dependency
blocked: info-needed
bug
duplicate
enhancement
fixed in HEAD
help wanted
hs:arrows
hs:brackets
hs:classes
hs:comments
hs:do-notation
hs:guards
hs:lists
hs:operators
hs:patterns
hs:records
hs:types
invalid
language extension support
layouting
needs confirmation
priority: high
priority: low
question
revisit before next release
wontfix
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: hexagoxel/brittany#41
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
Config:
Input:
Error:
Hey @lspitzner! I'd like to take a crack at solving this one. Where should I start?
@matthew-piziak great! There are several things to look at
and the other docs in that folder.
echo "func = (13, 14)" | brittany --dump-ast-full
, especially compared to the output for a tuplesection.ExplicitTuple
case inExpr.hs
. TheunknownNodeError "ExplicitTuple|.." lexpr
line is the one that will need a better implementation. Perhaps add somedocDebug "mylabel"
nodes inside the existing code for tuples, and see how that behaves. No other file will need changing.I am too familiar with the codebase to have a good feeling what part needs more explanation, so feel free to ask.
Thank you for the warm introduction, @lspitzner!
I am trying to transform the following guard:
As I read it this traversal only succeeds if all tuple arguments are
Present
.Presumably the goal is to replace
_ -> Nothing
(fail on empty sections) with(L _ (Missing Placeholder)) -> ?
. The problem is, I don't know what sort ofHsExpr
that would correspond to. It seems like the layout code should mostly also work for tuple sections. I feel like there is a kind of "empty"HsExpr
that I should be putting in the?
place. Any advice?Or maybe we want
layoutExpr
for all the args except theMissing
ones, which should beemptyDoc
?I tried naïvely transforming this...
...to this:
But the types are tricky for me:
Right, that guard currently filters out the "all are Just" case. Your last comment is definitely the right direction (while creating a new HsExpr was not, after all this code should turn AST into Bridoc structure, so
docEmpty
is a much better idea). Let me test that bit myself, one sec.This sort of works!
At least, it compiles, and transforms
func = (14,)
tofunc = (14, )
. Progress! I worry that I removeddocSharedWrapper
, and of course special logic needs to be added to tighten up the sections (since(14,)
is probably preferable to(14, )
).Yeah, you actually want the wrapper, otherwise this becomes exponential. At least in theory. But complexity is always theory. Use this:
(Oh and writing stuff in the guard is not necessary anymore, because.. it is not guarding anything anymore.)
But you seem on the right track, the special logic is indeed the only remaining bit.
or wait, is this nonsense in this case? i am not certain. one sec.
I don't suppose there's an analog of
docEmpty
that slurps up surrounding whitespace?For now I'll just try to match the
docEmpty
elements in the logic forFirstLast
.nah, it is not nonsense. use the wrapper version. the difference is approximately the difference between:
And we want the version that allocates a new bridoc node (i.e. executes
getLine
) only once.(hmm - i should copy this explanation to the docs.)
Maybe you want to carry the
Maybe
along longer. You can always create thedocEmpty
later.have you considered different cases? how many spaces would you insert for:
?
(given that the full tuple would currently be printed as
(1, 2, 3)
)Good question. Here are a few, but it's a hard decision.
I'm a fan of this one personally:
What do you think?
i don't have much of an opinion. I like the symmetry of space-after-comma, but for
i might agree with the latter.
Really, I don't want to decide this. If it is not grossly inconsistent (and your alternatives all follow some clear rule), i'm fine with anything (that retains the full-tuple behaviour). Maybe you could ask other users of
-XTupleSections
.oh, and we have not considered the multiline case yet :p
Well space-after-comma is done by default, so that's an advantage, haha.
Your long-elements example renders okay IMO:
Actually it seems to be exactly as you submitted it.
@lspitzner I've put up a tentative PR. Thanks for making it easy to contribute. :)
yeah, it probably is the only reasonable choice. although for the equivalent of
(verylaaaarge,,,,,)
it takes up a lot of space. But I am inclined to say that's the user's problem for overusing tuples. (Also, any collapsing that I can think of would produce rather confusing layout.)btw, i have been toying with ghcjs and put up an experimental brittany web service today. I have updated to include this commit.
although i notice that i don't properly handle errors yet, but let them override the input. Good old
-XDeleteSourceOnErrors
.(and no, it does not (and cannot) do the formatting on the clientside. dependency footprint is a bit too heavy for that, and ghcjs cannot build ghc-exactprint (yet).)