🤖 AI Summary
This paper addresses two key challenges in reversible grammar specifications: the difficulty of unifying parsers and printers, and the limited expressiveness of inductive structures (e.g., lists, trees). To resolve them, we propose a tuple-free reversible grammar combinator framework based on continuation-passing style (CPS). Unlike conventional approaches relying on dependent types or nested monads, our CPS-based reformulation of combinators inherently ensures bidirectional consistency and naturally supports recursive structures. We develop a three-tiered, progressively enhanced design that substantially improves expressive power without sacrificing concision. Our primary contribution is the first systematic application of Danvy’s CPS methodology to reversible grammar design—eliminating reliance on complex type-theoretic mechanisms while achieving a unified balance of generality, expressiveness, and formal simplicity. Empirical evaluation on parsing and printing tasks confirms the framework’s effectiveness and practical viability.
📝 Abstract
In the seminal paper Functional unparsing, Olivier Danvy used continuation passing to reanalyse printf-like format strings as combinators. In the intervening decades, the conversation shifted towards a concurrent line of work -- applicative, monadic or arrow-based combinator libraries -- in an effort to find combinators for invertible syntax descriptions that simultaneously determine a parser as well as a printer, and with more expressive power, able to handle inductive structures such as lists and trees. Along the way, continuation passing got lost. This paper argues that Danvy's insight remains as relevant to the general setting as it was to the restricted setting of his original paper. Like him, we present three solutions that exploit continuation-passing style as an alternative to both dependent types and monoidal aggregation via nested pairs, in our case to parse and print structured data with increasing expressive power.