Unknown syntactical construct: HsSpliceE{} #90
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#90
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?
Hello!
I've found some code that the formatter is unable to format:
A single line XQuasiQuote seems to work as intended
@lspitzner Do you have any ideas about how best to support
QuasiQuotes
? There is no reliable way to correctly handle their contents, since their syntax rules are unknown. I seems correctly aligning the opening and ending splice are what matters.@eborden hum.. wait. is the initial comment's example even valid haskell? I would assume that
Which also points to why we have to also take indentation into account in general. "retain indentation relative to opening parenthesis" might be sufficient, assuming those don't become negative. With negative indentations, instead "retain indentation relative to the inner-most layouting column". How whitespace-sensitive are common QQ blocks?
I think in general we cannot avoid re-indenting the whole block, but we cannot re-indent because it might change QQ semantics. Might become a question of which generality we sacrifice.
That syntax is valid Haskell. Quasi quotes completely disregard any layout, I think.
Oh, interesting. Yeah, i tested on TH QQs, but those are not even
HsSpliceE
s in the AST. (If you do[t|Int|]
with a similar linebreak after opening bracket, ghc barks, but that is irrelevant, unless/until we also want to support TH QQs.)This.. might make basic support (without any re-indentation) much easier than I had assumed: We probably can defer directly to exactprint for any
HsSpliceE
, not just the single-line ones?@lspitzner As far as I'm aware anything between the splice brackets is up to the quasi quoter itself. So white space sensitivity is defined by the given parser. With that in mind any white space alterations besides the alignment of the opening bracket could become destructive.
right. you can disregard my re-indentation idea.
unfortunately exactprinting does not work, it turns
into
so we need to manually not-transform the splice contents.
@eborden why does the closing position matter? only if there is stuff in the same line after it?
If I'm understanding you correctly, the closing position matters because it's still part of the splice:
right, i see.
I think this aspect can be handled just by appending "|]" to the splice contents. This narrows it down to the one task of exactly reproducing the splice contents, including any newline/whitespace.
I'd certainly prefer if the opening and closing brackets were aligned in form we'd expect with indentation alignment. Maybe
brittany
should do this and just assume that trailing whitespace doesn't matter in a parser since in the 99.9999% case it shouldn't.into
Maybe the starting point could be to just preserve everything between quasiquoting? Right now I have to filter out files with quasiquotes when using Brittany, which means those files don't get the same love :)
I just encountered this behavior, and I'm not sure it's covered by this issue, so I'll add it as an extra data point. Let me know if I should open a separate issue!
We are using
git ls-files | grep 'hs$' | xargs grep -L QuasiQuotes | xargs brittany --write-mode inplace
to avoid this issue (and keep those quasiquoted modules small).Note that
grep -L
will exit with 123 if no files in the input contain the script, so best to useack -L
.For the TH equivalent there is #206.