Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing and pretty printing the same file format in Haskell

I was wondering, if there is a standard, canonical way in Haskell to write not only a parser for a specific file format, but also a writer.

In my case, I need to parse a data file for analysis. However, I also simulate data to be analyzed and save it in the same file format. I could now write a parser using Parsec or something equivalent and also write functions that perform the text output in the way that it is needed, but whenever I change my file format, I would have to change two functions in my code. Is there a better way to achieve this goal?

Thank you, Dominik

like image 915
Dominik Schrempf Avatar asked Jul 21 '17 13:07

Dominik Schrempf


1 Answers

The BNFC-meta package https://hackage.haskell.org/package/BNFC-meta-0.4.0.3

might be what you looking for

"Specifically, given a quasi-quoted LBNF grammar (as used by the BNF Converter) it generates (using Template Haskell) a LALR parser and pretty pretty printer for the language."

update: found this package that also seems to fulfill the objective (not tested yet) http://hackage.haskell.org/package/syntax

like image 87
neu-rah Avatar answered Nov 10 '22 07:11

neu-rah