#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):
Replying to [comment:13 kfisher]:
> Could you explain it in a bit more detail, perhaps
> working out a small example that shows a bit of
> Haskell containing a |] contained within the pads/haskell
> quasi-quoter?
Hmm, I wasn't immediately able to find much information
about the pads quasiquoter. But I'll do my best to work
out a simple hypothetical example below.
> I don't want to have to define multiple quasi quoters
> in multiple files to get this corner case right
You certainly would not need to do that.
Let's say that you currently define the pads
quasiquoter for top-level declarations. So your
definition of the quasiquoter looks something like
this:
{{{
pads :: QuasiQuoter
pads = QuasiQuoter { quoteDec = padsQuoteDec }
padsQuoteDec = ...
}}}
Suppose you'd now like to allow embedded
oxford brackets.
You would simply replace the definition of
`padsQuoteDec` with something like:
{{{
padsQuoteDec = padsQuoteDecBase . escapeBrackets
padsQuoteDecBase = ...
}}}
Use the exact same definition for `padsQuoteDecBase`
as you used before for `padsQuoteDec`. That's it!
Now, let's say users want to use a pads quasiquoter
to describe data that looks like this:
{{{
[| 42 |]
}}}
They might then write:
{{{
[pads|
Pstruct oxford_t {
"[| "; Puint32 num;
" |\]";
}
|]
}}}
The PADS expression parser will see {{{"|]"}}} where the
user wrote {{{"|\]"}}}.
If the users want a literal {{{"|\]"}}} to be part of the
PADS expression, they can write {{{"|\\]"}}}. And so on.
The character {{{'\'}}} only has this special pre-processing when
it is directly sandwiched between {{{'|'}}} and {{{']'}}}.
In any other context, the {{{'\'}}} is passed literally
to the base PADS quasiquoter as before.
Perhaps this syntax for quoting the closing oxford bracket
does not suit you for PADS, e.g., due to interaction with
a special meaning of {{{'\'}}} in PADS itself.
Then instead of the `escapeBracket` library function used
above, you can define your own syntax for a quoted closing
oxford bracket:
{{{
padsQuoteDec = padsQuoteDecBase . myEscapeBracket
myEscapeBracket :: String -> String
myEscapeBracket = ...
padsQuoteDecBase = ...
}}}
For example, one quasiquoter author mentioned above that
he used {{{"|~]"}}} to represent {{{"|]"}}}.
See my earlier comment in this ticket for an example of
how to write a bracket escape function.
With this proposal, you have complete flexibility to decide
what syntax users use to embed a literal {{{"|]"}}}.
You can easily use the built-in syntax as above, or you can define
your own syntax without too much more effort, or you can decide
not to allow them at all.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5348#comment:14>
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