nikita-volkov / neat-interpolation

A quasiquoter for neat and simple multiline text interpolation
http://hackage.haskell.org/package/neat-interpolation
MIT License
55 stars 16 forks source link

Updating parser to allow dollar-sign to be escaped using a sequence o… #11

Closed ghost closed 8 years ago

ghost commented 8 years ago

I'm not really familiar with parsec, so I don't think it's the best way, but I think it's a pretty simple solution. I'm proposing an escape sequence of two consecutive dollar-signs. The parser is simple enough, if we find a $, try to consume another $, otherwise try to get an identifier. Example:

query :: Text -> Text
query fields = [text| SELECT $fields FROM foobar WHERE id=$$1 ]

Calling query "id, name" should output SELECT id, name FROM foobar WHERE id=$1. It should also work on silly strings like $$$a$$$b$$${a_long_identifier}$$.

nikita-volkov commented 8 years ago

Good job! It's merged and released now.

A general advice for the future: don't replace tests, add them. The more tests you have, the better you are covered.