Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Haskell: Quasiquotes escaping

I would like to add my new language to Haskell using the Quasiquotes, but the language itself uses |] as a keyword.

Is there some way, how to:

a) Escape |], so it is passed to my language

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

b) Let the parser of my language decide, when the quasiquotation ends itself

Thanks.

>Solution :

Short answer: slightly modify the embedded language.

The User’s Guide on QuasiQuoters explains that no escaping can done for the |]:

The quoted ⟨string⟩ finishes at the first occurrence of the two-character sequence "|]". Absolutely no escaping is performed. If you want to embed that character sequence in the string, you must invent your own escape convention (such as, say, using the string "|~]" instead), and make your quoter function interpret "|~]" as "|]".

Your parser can not decide when the quasiquoters ends, because the substring is passed to the quasiquoter that started after the [quasiquoter|… part and before the …|] part.

You thus should slightly alter your language and thus for example work with a pre-processor that translate |~] (which is not considered the end of the quasiquoted string) to |] instead.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading