Abstract
Parser combinators, often monadic, are a venerable and widely-used solution to read data from some external format. However, the capability to return a partial parse has, until now, been largely missing. When only a small portion of the entire data is desired, it has been necessary either to parse the entire input in any case, or to break up the grammar into smaller pieces and move some work outside the world of combinators.
This paper presents a technique for mixing lazy, demand-driven, parsing with strict parsing, all within the same set of combinators. The grammar specification remains complete and unbroken, yet only sufficient input is consumed to satisfy the result demanded. It is built on a combination of applicative and monadic parsers. Monadic parsing alone is insufficient to allow a choice operator to coexist with the early commitment needed for lazy results. Applicative parsing alone can give partial results, but does not permit context-sensitive grammars. But used together, we gain both partiality and a flexible ease of use.
Performance results demonstrate that partial parsing is often faster and more space-efficient than strict parsing, but never worse. The trade-off is that partiality has consequences when dealing with ill-formed input.
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsPreview
Unable to display preview. Download preview PDF.
References
Baars, A., Löh, A., Swierstra, D.: Parsing permutation phrases. Journal of Functional Programming 14(6), 635–646 (2004)
Duke, D., Wallace, M., Borgo, R., Runciman, C.: Fine-grained visualization pipelines and lazy functional languages. IEEE Transactions on Visualization and Computer Graphics 12(5), 973–980 (2006)
Ford, B.: Packrat parsing: Simple, powerful, lazy, linear time. In: International Conference on Functional Programming, Pittsburgh, October 2002. ACM SIGPLAN, New York (2002)
Hughes, R.J.M., Swierstra, S.D.: Polish parsers, step by step. In: Proceedings of ICFP, Uppsala, pp. 239–248. ACM Press, New York (2003)
Hutton, G.: Higher-order functions for parsing. Journal of Functional Programming 2(3), 323–343 (1992)
Hutton, G., Meijer, E.: Monadic parser combinators. Technical Report NOTTCS-TR-96-4, University of Nottingham (1996)
Leijen, D., Meijer, E.: Parsec: Direct style monadic parser combinators for the real world. Technical Report UU-CS-2001-35, University of Utrecht (2001)
McBride, C., Paterson, R.: Applicative programming with effects. Journal of Functional Programming 17(5), 1–13 (2007)
Röjemo, N.: Garbage collection and memory efficiency in lazy functional languages. PhD thesis, Chalmers University of Technology (1995)
Swierstra, D.: Combinator Parsers: from toys to tools. ENTCS, vol. 41. Elsevier, Amsterdam (2001)
van Laarhoven, T.: ParseP: software distribution, http://twan.home.fmf.nl/parsep/
Wadler, P.: Monads for functional programming. In: Broy, M. (ed.) Marktoberdorf Summer School on Program Design Calculi, August 1992. NATO ASI Series F: Computer and systems sciences, vol. 118. Springer, Heidelberg (1992)
Wallace, M.: HaXml software distribution, http://haskell.org/HaXml
Wallace, M.: Polyparse combinators (2007), http://www.cs.york.ac.uk/fp/polyparse
Wallace, M., Runciman, C.: Haskell and XML: generic combinators or type-based translation? In: Proceedings of ICFP, Paris. ACM Press, New York (1999)
Author information
Authors and Affiliations
Editor information
Rights and permissions
Copyright information
© 2008 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Wallace, M. (2008). Partial Parsing: Combining Choice with Commitment. In: Chitil, O., Horváth, Z., Zsók, V. (eds) Implementation and Application of Functional Languages. IFL 2007. Lecture Notes in Computer Science, vol 5083. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-85373-2_6
Download citation
DOI: https://doi.org/10.1007/978-3-540-85373-2_6
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-85372-5
Online ISBN: 978-3-540-85373-2
eBook Packages: Computer ScienceComputer Science (R0)