一句话:提出首个支持非单射解析器精确打印的 biparser 框架,用 lens 统一解析与打印,并实现 JSON/YAML 子集。
在不同序列化格式间同步数据时,解析器与打印器密切相关,但为解析出的数据恢复原始源文本(精确打印)仍具挑战,尤其对非单射解析器。本文把解析器-打印器对视为输入文本与数据之间的同步机制,并将其形式化为双向程序(lens),提出首个支持非单射解析器精确打印的 biparser 框架。该框架提供常用模式的组合子库,并给出 JSON 与 YAML 子集的 biparser 实现,展示其可用性。
Parsers and printers are vital for data synchronisation between different serialisation formats. As they are tightly related, much research has been devoted to showing that both can be derived from a single definition. It, however, turns out to be challenging to extend this work with exact-printing , which recovers the original source text for the parsed data. In this paper, we propose a new approach to tackling the challenge that considers a parser-printer pair as a mechanism to synchronize the input text string with the data, and formalizes them as a bidirectional program (lens). We propose the first biparser framework to support exact-printing with non-injective parsers, provide a library of combinators for common patterns, and demonstrate its usefulness with biparsers for subsets of JSON and YAML.
@article{XieSH25,
title = {Biparsers: Exact Printing for Data Synchronisation},
author = {Ruifeng Xie and Tom Schrijvers and Zhenjiang Hu},
journal = {Proceedings of the ACM on Programming Languages},
volume = {9},
number = {POPL},
year = {2025},
doi = {10.1145/3704910}
}