skip to main content
research-article

Indentation-sensitive parsing for Parsec

Published:03 September 2014Publication History
Skip Abstract Section

Abstract

Several popular languages including Haskell and Python use the indentation and layout of code as an essential part of their syntax. In the past, implementations of these languages used ad hoc techniques to implement layout. Recent work has shown that a simple extension to context-free grammars can replace these ad hoc techniques and provide both formal foundations and efficient parsing algorithms for indentation sensitivity.

However, that previous work is limited to bottom-up, LR($k$) parsing, and many combinator-based parsing frameworks including Parsec use top-down algorithms that are outside its scope. This paper remedies this by showing how to add indentation sensitivity to parsing frameworks like Parsec. It explores both the formal semantics of and efficient algorithms for indentation sensitivity. It derives a Parsec-based library for indentation-sensitive parsing and presents benchmarks on a real-world language that show its efficiency and practicality.

References

  1. Michael D. Adams. Principled parsing for indentation-sensitive languages: revisiting landin's offside rule. In Proceedings of the 40th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL '13, pages 511--522, New York, NY, USA, 2013. ACM. ISBN 978-1-4503-1832-7. 10.1145/2429069.2429129. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Alfred V. Aho and Jeffrey D. Ullman. The theory of parsing, translation, and compiling, volume 1. Prentice-Hall, Englewood Cliffs, NJ, 1972. ISBN 0-13-914556-7. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Sam Anklesaria. indents version 0.3.3, May 2012. URL http://hackage.haskell.org/package/indents/.Google ScholarGoogle Scholar
  4. Oren Ben-Kiki, Clark Evans, and Ingy döt Net. YAML Ain't Markup Language (YAML) Version 1.2, 3rd edition, October 2009. URL http://www.yaml.org/spec/1.2/spec.html.Google ScholarGoogle Scholar
  5. Edwin Brady. Idris, a general-purpose dependently typed programming language: Design and implementation. Journal of Functional Programming, 23 (05): 552--593, September 2013. ISSN 1469-7653. 10.1017/S095679681300018X.Google ScholarGoogle ScholarCross RefCross Ref
  6. Edwin Brady. Ws-idr, February 2013. URL https://github.com/edwinb/WS-idr. Commit db65516b87863fcc0b066d26cb262bcddfff5514.Google ScholarGoogle Scholar
  7. Edwin Brady. idris-0.9.8-demos, December 2013. URL https://github.com/edwinb/idris-demos. Commit 9c1355445dee0a41e6850a9c8d33cb0f2072cf78.Google ScholarGoogle Scholar
  8. Edwin Brady. idris-0.9.8-examples-benchmarks-tests, December 2013. URL https://github.com/idris-lang/Idris-dev. Commit 869564663b8309a4984ba8ad700baf7b65c926bb.Google ScholarGoogle Scholar
  9. Edwin Brady. idris-0.9.8-stdlib, January 2013. URL https://github.com/idris-lang/Idris-dev. Commit a3c8020d50def27d7e1eb01d0ec8e10a00e9b90e.Google ScholarGoogle Scholar
  10. Leonhard Brunauer and Bernhard Mühlbacher. Indentation sensitive languages. Unpublished manuscript, July 2006. URL http://www.cs.uni-salzburg.at/~ck/wiki/uploads/TCS-Summer-2006.IndentationSensitiveLanguages/.Google ScholarGoogle Scholar
  11. Sebastian Erdweg, Tillmann Rendel, Christian Kästner, and Klaus Ostermann. Layout-sensitive generalized parsing. In Software Language Engineering, Lecture Notes in Computer Science. Springer Berlin / Heidelberg, 2012. URL http://sugarj.org/layout-parsing.pdf. To appear.Google ScholarGoogle Scholar
  12. Bryan Ford. Parsing expression grammars: a recognition-based syntactic foundation. In Proceedings of the 31st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL '04, pages 111--122, New York, NY, USA, 2004. ACM. ISBN 1-58113-729-X. 10.1145/964001.964011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Simon Fowler. idrisweb, December 2013. URL https://github.com/idris-hackers/IdrisWeb. Committexttt0c823ff5af0fd9f04b66d05a138585acdc656722.Google ScholarGoogle Scholar
  14. The Glorious Glasgow Haskell Compilation System User's Guide, Version 7.2.1. The GHC Team, August 2011. URL http://www.haskell.org/ghc/docs/7.2.1/html/users_guide/.Google ScholarGoogle Scholar
  15. David Goodger. reStructuredText Markup Specification, January 2012. URL http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html. Revision 7302.Google ScholarGoogle Scholar
  16. John Gruber. Markdown: Syntax. URL http://daringfireball.net/projects/markdown/syntax. Retrieved on June 24, 2012.Google ScholarGoogle Scholar
  17. Michael Hanus (ed.). Curry: An integrated functional logic language (version 0.8.2). Technical report, March 2006. URL http://www.informatik.uni-kiel.de/~curry/report.html.Google ScholarGoogle Scholar
  18. HASP Project. The Habit programming language: The revised preliminary report, November 2010. URL http://hasp.cs.pdx.edu/habit-report-Nov2010.pdf.Google ScholarGoogle Scholar
  19. Graham Hutton. Higher-order functions for parsing. Journal of Functional Programming, 2 (03): 323--343, July 1992. 10.1017/S0956796800000411.Google ScholarGoogle ScholarCross RefCross Ref
  20. Graham Hutton and Erik Meijer. Monadic parser combinators. Technical Report NOTTCS-TR-96-4, Department of Computer Science, University of Nottingham, 1996.Google ScholarGoogle Scholar
  21. INMOS Limited. occam programming manual. Prentice-Hall international series in computer science. Prentice-Hall International, 1984. ISBN 978-0-13-629296-8. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Mark P. Jones. The implementation of the Gofer functional programming system. Research Report YALEU/DCS/RR-1030, Yale University, New Haven, Connecticut, USA, May 1994.Google ScholarGoogle Scholar
  23. Piyush P. Kurur. indentparser version 0.1, January 2012. URL http://hackage.haskell.org/package/indentparser/.Google ScholarGoogle Scholar
  24. P. J. Landin. The next 700 programming languages. Communications of the ACM, 9 (3): 157--166, March 1966. ISSN 0001-0782. 10.1145/365230.365257. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Daan Leijen and Paolo Martini. parsec version 3.1.3, June 2012. URL http://hackage.haskell.org/package/parsec/.Google ScholarGoogle Scholar
  26. Simon Marlow (ed.). Haskell 2010 Language Report, April 2010. URL http://www.haskell.org/onlinereport/haskell2010/.Google ScholarGoogle Scholar
  27. Egil Möller. SRFI-49: Indentation-sensitive syntax, May 2005. URL http://srfi.schemers.org/srfi-49/srfi-49.html.Google ScholarGoogle Scholar
  28. Bryan O'Sullivan. Criterion version 0.6.0.1, January 2012. URL http://hackage.haskell.org/package/criterion/.Google ScholarGoogle Scholar
  29. Python. The Python Language Reference. URL http://docs.python.org/reference/. Retrieved on June 26, 2012.Google ScholarGoogle Scholar
  30. Benjamin Saunders. bitstreams, August 2013. URL https://github.com/Ralith/bitstreams. Committextttb4da0ea346d506e7fd9fc7b2c9637281addec9ba.Google ScholarGoogle Scholar
  31. S. Doaitse Swierstra. uulib version 0.9.14, August 2011. URL http://hackage.haskell.org/package/uulib/.Google ScholarGoogle Scholar
  32. Don Syme et al. The F# 2.0 Language Specification. Microsoft Corporation, April 2010. URL https://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/spec.html. Updated April 2012.Google ScholarGoogle Scholar
  33. Matúš Tejiščák. lightyear, December 2013. URL https://github.com/ziman/lightyear. Committextttd74e48ad13451e763250ec1412989fdebe7af66a.Google ScholarGoogle Scholar
  34. D. A. Turner. Miranda System Manual. Research Software Limited, 1989. URL http://www.cs.kent.ac.uk/people/staff/dat/miranda/manual/.Google ScholarGoogle Scholar
  35. Philip Wadler. An introduction to Orwell. Technical report, Programming Research Group at Oxford University, 1985.Google ScholarGoogle Scholar

Index Terms

  1. Indentation-sensitive parsing for Parsec

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        Full Access

        • Published in

          cover image ACM SIGPLAN Notices
          ACM SIGPLAN Notices  Volume 49, Issue 12
          Haskell '14
          December 2014
          141 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/2775050
          • Editor:
          • Andy Gill
          Issue’s Table of Contents
          • cover image ACM Conferences
            Haskell '14: Proceedings of the 2014 ACM SIGPLAN symposium on Haskell
            September 2014
            154 pages
            ISBN:9781450330411
            DOI:10.1145/2633357

          Copyright © 2014 ACM

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 3 September 2014

          Check for updates

          Qualifiers

          • research-article

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!