Skip to main content

Partial Parsing: Combining Choice with Commitment

  • Conference paper

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 5083))

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

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   74.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   99.00
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Baars, A., Löh, A., Swierstra, D.: Parsing permutation phrases. Journal of Functional Programming 14(6), 635–646 (2004)

    Article  MATH  Google Scholar 

  2. 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)

    Article  Google Scholar 

  3. Ford, B.: Packrat parsing: Simple, powerful, lazy, linear time. In: International Conference on Functional Programming, Pittsburgh, October 2002. ACM SIGPLAN, New York (2002)

    Google Scholar 

  4. 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)

    Google Scholar 

  5. Hutton, G.: Higher-order functions for parsing. Journal of Functional Programming 2(3), 323–343 (1992)

    Article  MATH  MathSciNet  Google Scholar 

  6. Hutton, G., Meijer, E.: Monadic parser combinators. Technical Report NOTTCS-TR-96-4, University of Nottingham (1996)

    Google Scholar 

  7. Leijen, D., Meijer, E.: Parsec: Direct style monadic parser combinators for the real world. Technical Report UU-CS-2001-35, University of Utrecht (2001)

    Google Scholar 

  8. McBride, C., Paterson, R.: Applicative programming with effects. Journal of Functional Programming 17(5), 1–13 (2007)

    MathSciNet  Google Scholar 

  9. Röjemo, N.: Garbage collection and memory efficiency in lazy functional languages. PhD thesis, Chalmers University of Technology (1995)

    Google Scholar 

  10. Swierstra, D.: Combinator Parsers: from toys to tools. ENTCS, vol. 41. Elsevier, Amsterdam (2001)

    Google Scholar 

  11. van Laarhoven, T.: ParseP: software distribution, http://twan.home.fmf.nl/parsep/

  12. 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)

    Google Scholar 

  13. Wallace, M.: HaXml software distribution, http://haskell.org/HaXml

  14. Wallace, M.: Polyparse combinators (2007), http://www.cs.york.ac.uk/fp/polyparse

  15. Wallace, M., Runciman, C.: Haskell and XML: generic combinators or type-based translation? In: Proceedings of ICFP, Paris. ACM Press, New York (1999)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Olaf Chitil Zoltán Horváth Viktória Zsók

Rights and permissions

Reprints 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)

Publish with us

Policies and ethics