Abstract
Parsers and pretty-printers for a language are often quite similar, yet both are typically implemented separately, leading to redundancy and potential inconsistency. We propose a new interface of syntactic descriptions, with which both parser and pretty-printer can be described as a single program. Whether a syntactic description is used as a parser or as a pretty-printer is determined by the implementation of the interface. Syntactic descriptions enable programmers to describe the connection between concrete and abstract syntax once and for all, and use these descriptions for parsing or pretty-printing as needed. We also discuss the generalization of our programming technique towards an algebra of partial isomorphisms.
Supplemental Material
- }}Sergei Abramov and Robert Glück. Principles of inverse computation and the universal resolving algorithm. In The essence of computation: complexity, analysis, transformation, pages 269--295. Springer LNCS 2566, New York, 2002. Google Scholar
Digital Library
- }}Artem Alimarine, Sjaak Smetsers, Arjen van Weelden, Marko van Eekelen, and Rinus Plasmeijer. There and back again: arrows for invertible programming. In Proceedings of the workshop on Haskell (Haskell '05), pages 86--97, New York, 2005. Google Scholar
Digital Library
- }}Kenichi Asai. On typing delimited continuations: three new solutions to the printf problem. Higher-Order and Symbolic Computation, 22(3): 275--291, September 2009. Google Scholar
Digital Library
- }}Claus Brabrand, Anders Møller, and Michael I. Schwartzbach. Dual syntax for XML languages. Information Systems, 33(4-5):385--406, 2008. Google Scholar
Digital Library
- }}Olivier Danvy. Functional unparsing. Journal of Functional Programming,8(6):621--625, 1998. Google Scholar
Digital Library
- }}Olivier Danvy. From reduction-based to reduction-free normalization. In Advanced Functional Programming, pages 66--164. Springer LNCS 5832, 2008. Google Scholar
Digital Library
- }}J. Fokker. Functional parsers. In J. T. Jeuring and H. J. M. Meijer, editors, Advanced Functional Programming, First International Spring School, number 925 in LNCS, pages 1--23, 1995. Google Scholar
Digital Library
- }}J. Nathan Foster, Alexandre Pilkiewicz, and Benjamin C. Pierce. Quotient lenses. In Proceeding of the International Conference on Functional Programming (ICFP '08), pages 383--396, New York, 2008. Google Scholar
Digital Library
- }}Nathan J. Foster, Michael B. Greenwald, Jonathan T. Moore, Benjamin C. Pierce, and Alan Schmitt. Combinators for bi-directional tree transformations: A linguistic approach to the view update problem. In Proceedings of the symposium on Principles of Programming Languages (POPL '05), pages 233--246, New York, 2005. Google Scholar
Digital Library
- }}Ralf Hinze. Formatting: a class act. Journal of Functional Programming, 13(5):935--944, 2003. Google Scholar
Digital Library
- }}Christian Hofer, Klaus Ostermann, Tillmann Rendel, and Adriaan Moors. Polymorphic embedding of DSLs. In Proceedings of the Conference on Generative Programming and Component Engineering (GPCE '08), pages 137--148, New York, October 2008. Google Scholar
Digital Library
- }}John Hughes. The Design of a Pretty-printing Library. In J. Jeuring and E. Meijer, editors, Advanced Functional Programming, pages 53--96. Springer LNCS 925, 1995. Google Scholar
Digital Library
- }}John Hughes. Generalising monads to arrows. Science of Computer Programming, 37:67--111, May 2000. Google Scholar
Digital Library
- }}Graham Hutton and Erik Meijer. Monadic parsing in Haskell. Journal of Functional Programming, 8(4):437--444, 1998. Google Scholar
Digital Library
- }}Patrik Jansson and Johan Jeuring. Polytypic compact printing and parsing. In European Symposium on Programming, pages 273--287. Springer LNCS 1576, 1999. Google Scholar
Digital Library
- }}Patrik Jansson and Johan Jeuring. Polytypic data conversion programs. Science of Computer Programming, 43(1):35--75, 2002. Oleg Kiselyov. Type-safe functional formatted IO. Available at http://okmij.org/ftp/typed-formatting/, 2008. Google Scholar
Digital Library
- }}Edward A. Kmett. category extras: Various modules and constructs inspired by category theory. Available at http://hackage.haskell.org/package/category-extras, 2008.Google Scholar
- }}Daan Leijen and Erik Meijer. Parsec: Direct style monadic parser combinators for the real world. Technical Report UU-CS-2001-27, Department of Computer Science, Universiteit Utrecht, 2001.Google Scholar
- }}Conor McBride and Ross Paterson. Applicative programming with effects. Journal of Functional Programming, 18(1):1--13, 2008. Google Scholar
Digital Library
- }}Shin-Cheng Mu, Zhenjiang Hu, and Masato Takeichi. An injective language for reversible computation. In Proceedings of the International Conference on Mathematics of Program Construction (MPC '04). Springer Verlag, 2004.Google Scholar
Cross Ref
- }}Nicolas Oury and Wouter Swierstra. The power of pi. In Proceedings of the International Conference on Functional Programming (ICFP '08), pages 39--50, New York, 2008. Google Scholar
Digital Library
- }}Tim Sheard and Simon Peyton Jones. Template meta-programming for Haskell. SIGPLAN Not., 37(12):60--75, 2002. Google Scholar
Digital Library
Index Terms
Invertible syntax descriptions: unifying parsing and pretty printing
Recommendations
Invertible syntax descriptions: unifying parsing and pretty printing
Haskell '10: Proceedings of the third ACM Haskell symposium on HaskellParsers and pretty-printers for a language are often quite similar, yet both are typically implemented separately, leading to redundancy and potential inconsistency. We propose a new interface of syntactic descriptions, with which both parser and pretty-...
Syntax error recovery in parsing expression grammars
SAC '18: Proceedings of the 33rd Annual ACM Symposium on Applied ComputingParsing Expression Grammars (PEGs) are a formalism used to describe top-down parsers with backtracking. As PEGs do not provide a good error recovery mechanism, PEG-based parsers usually do not recover from syntax errors in the input, or recover from ...
LibDSL: a library for developing embedded domain specific languages in d via template metaprogramming
GPCE '14This paper presents a library called LibDSL that helps the implementer of an embedded domain specific language (EDSL) effectively develop it in D language. The LibDSL library accepts as input some kinds of ``specifications'' of the EDSL that the ...







Comments