#5348: Template Haskell quasiquote escapes
---------------------------------+------------------------------------------
Reporter: simonpj | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.0.3
Keywords: | Testcase:
Blockedby: | Difficulty:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
---------------------------------+------------------------------------------
Comment(by YitzGale):
Another alternative: support no escapes, ''without'' asking
`myparser` to determine where the quotation ends. Just use the
current closing oxford bracket, without a hard-wired way to
escape it.
If someone needs to be able to allow literal oxford brackets
in quasi-quotes, they can define their own syntax for that.
There is no need for GHC to provide it.
Of course there is then a limitation on what syntax can
be used for this purpose - it cannot contain
an entire closing oxford bracket, because that will be intercepted
by GHC to end the quasi-quote. So, for example, it can be
{{{"|\]"}}}, or {{{"'|']"}}}, but not {{{"\|]"}}}.
I think that limitation is well worth it. GHC must do its utmost
to avoid interfering with the syntax that the quasi-quoter
is trying to define. Frankly, I was shocked to learn of this
backslash meddling.
Whereas the need to allow literal oxford brackets in a quasi-quote
seems to be somewhat of a corner case. None of the popular
quasi-quoters I know about have any particular need for that.
Though I can imagine it coming up sometimes.
Perhaps, as a convenience, the library should provide a combinator
for backslash quoting. Users can optionally compose it with
their quasi-quoter. For example, something like this:
{{{
backslashQuoter :: String -> String
backslashQuoter s@('|':'\\':s') = case span (== '\\') s' of
(bs, cs@(']':_)) -> '|' : bs ++ cs
_ -> s
backslashQuoter s = s
}}}
I.e., recognize backslash quoting '''only''' for a sequence
of backslashes directly sandwiched between
{{{'|'}}} and {{{']'}}}. Otherwise stay out of the way.
Or we could define the combinator to be more like what
Simon suggested.
If we must have hard-wired backslash quoting, I would much
prefer something more polite, like the above, over what Simon
suggested.
To summarize, I am making two alternative proposals:
* No hard-wired quoting; provide a combinator for convenience. This is
what I prefer. Or,
* Hard-wired quoting that only affects oxford-bracket-like syntax.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5348#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs