skip to main content
article

Packrats parse in packs

Published:07 September 2017Publication History
Skip Abstract Section

Abstract

We present a novel but remarkably simple formulation of formal language grammars in Haskell as functions mapping a record of pro- duction parsers to itself. Thus formulated grammars are first-class objects, composable and reusable. We also provide a simple parser implementation for them, based on an improved packrat algorithm. In order to make the grammar manipulation code reusable, we introduce a set of type classes mirroring the existing type classes from Haskell base library, but whose methods have rank-2 types.

References

  1. John W Backus. 1959. The syntax and semantics of the proposed international algebraic language of the Zurich ACM-GAMM conference. Proceedings of the International Comference on Information Processing, 1959 (1959).Google ScholarGoogle Scholar
  2. Mario Blažević. 2013. Adding structure to monoids. ACM SIGPLAN NOTICES 48, 12 (2013), 37–45. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Mario Blažević. 2013. monoid-subclasses. http://hackage.haskell.org/package/ monoid-subclasses . (2013).Google ScholarGoogle Scholar
  4. Jacques Carette, Oleg Kiselyov, and Chung-chieh Shan. 2009. Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. Journal of Functional Programming 19, 05 (2009), 509–543. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Noam Chomsky. 1956. Three models for the description of language. IRE Transactions on information theory 2, 3 (1956), 113–124.Google ScholarGoogle ScholarCross RefCross Ref
  6. Nils Anders Danielsson. 2010. Total Parser Combinators. In Proceedings of the 15th ACM SIGPLAN International Conference on Functional Programming (ICFP ’10) . ACM, New York, NY, USA, 285–296. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Edsko de Vries and Andres Löh. 2014. True Sums of Products. In Proceedings of the 10th ACM SIGPLAN Workshop on Generic Programming (WGP ’14) . ACM, New York, NY, USA, 83–94. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Dominique Devriese. 2010. The grammar-combinators package. http://hackage. haskell.org/package/grammar-combinators . (2010).Google ScholarGoogle Scholar
  9. Dominique Devriese and Frank Piessens. 2011. Explicitly Recursive Grammar Combinators: A Better Model for Shallow Parser DSLs. In Proceedings of the 13th International Conference on Practical Aspects of Declarative Languages (PADL’11) . Springer-Verlag, Berlin, Heidelberg, 84–98. http://dl.acm.org/citation.cfm?id= 1946313.1946326 Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Dominique Devriese and Frank Piessens. 2012. Finally tagless observable recursion for an abstract grammar model. Journal of Functional Programming 22, 06 (2012), 757–796. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Dominique Devriese, Ilya Sergey, Dave Clarke, and Frank Piessens. 2013. Fixing idioms: a recursion primitive for applicative DSLs. In Proceedings of the ACM SIGPLAN 2013 workshop on Partial evaluation and program manipulation . ACM, 97–106. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Mathias Doenitz. 2010. A pure-Java Markdown processor based on a parboiled PEG parser supporting a number of extensions. GitHub. (2010). https://github. com/sirthias/pegdown .Google ScholarGoogle Scholar
  13. Jay Earley. 1970. An efficient context-free parsing algorithm. Commun. ACM 13, 2 (1970), 94–102. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Levent Erkök and John Launchbury. 2000. Recursive monadic bindings. In ACM SIGPLAN Notices , Vol. 35. ACM, 174–185. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Levent Erkök and John Launchbury. 2002. A recursive do for Haskell. In Proceedings of the 2002 ACM SIGPLAN workshop on Haskell . ACM, 29–37. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Bryan Ford. 2002. Packrat parsing:: simple, powerful, lazy, linear time, functional pearl. In ACM SIGPLAN Notices, Vol. 37. ACM, 36–47. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Bryan Ford. 2004. Parsing expression grammars: a recognition-based syntactic foundation. SIGPLAN Not. 39, 1 (2004), 111–122. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Olle Fredriksson. 2011. The Grempa package. http://hackage.haskell.org/package/ Grempa . (2011).Google ScholarGoogle Scholar
  19. Olle Fredriksson. 2014. The Earley package. http://hackage.haskell.org/package/ Earley . (2014).Google ScholarGoogle Scholar
  20. Robert Grimm. 2004. Practical packrat parsing. Technical Report. Dept. of Computer Science, New York University.Google ScholarGoogle Scholar
  21. Robert Grimm. 2006. Better extensibility through modular syntax. In ACM SIGPLAN Notices , Vol. 41. ACM, 38–51. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Anastasia Izmaylova, Ali Afroozeh, and Tijs van der Storm. 2016. Practical, general parser combinators. In Proceedings of the 2016 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation . ACM, 1–12. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Stephen C. Johnson. 1975. Yacc: Yet another compiler-compiler. Vol. 32. Bell Laboratories Murray Hill, NJ.Google ScholarGoogle Scholar
  24. Daan Leijen and Erik Meijer. 2001. Parsec: Direct style monadic parser combinators for the real world . Technical Report. Department of Computer Science, Utrecht University.Google ScholarGoogle Scholar
  25. Conor McBride. 2011. Functional pearl: Kleisli arrows of outrageous fortune. Journal of Functional Programming (to appear) (2011).Google ScholarGoogle Scholar
  26. John Meacham. 2006. The Frisby package. http://hackage.haskell.org/package/ frisby . (2006).Google ScholarGoogle Scholar
  27. Matthew Might, David Darais, and Daniel Spiewak. 2011. Parsing with derivatives: a functional pearl. In ACM SIGPLAN notices, Vol. 46. ACM, 189–195. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Bruno C d S Oliveira and Andres Löh. 2013. Abstract syntax graphs for domain specific languages. In Proceedings of the ACM SIGPLAN 2013 workshop on Partial evaluation and program manipulation . ACM, 87–96. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Roman R Redziejowski. 2009. Mouse: from parsing expressions to a practical parser. In Concurrency Specification and Programming Workshop. Citeseer.Google ScholarGoogle Scholar
  30. S Doaitse Swierstra. 2009. Combinator parsing: A short tutorial. In Language Engineering and Rigorous Software Development . Springer, 252–300. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Marcos Viera, Doaitse Swierstra, and Atze Dijkstra. 2012. Grammar fragments fly first-class. In Proceedings of the Twelfth Workshop on Language Descriptions, Tools, and Applications . ACM, 5. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Marcos Viera, S. Doaitse Swierstra, and Eelco Lempsink. 2008. Haskell, Do You Read Me?: Constructing and Composing Efficient Top-down Parsers at Runtime. SIGPLAN Not. 44, 2 (Sept. 2008), 63–74. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Philip Wadler. 1985. How to Replace Failure by a List of Successes. In Proc. Of a Conference on Functional Programming Languages and Computer Architecture . Springer-Verlag New York, Inc., New York, NY, USA, 113–128. http://dl.acm.org/ citation.cfm?id=5280.5288 Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Alexey Rodriguez Yakushev, Stefan Holdermans, Andres Löh, and Johan Jeuring. 2009. Generic programming with fixed points for mutually recursive datatypes. In ACM SIGPLAN Notices, Vol. 44. ACM, 233–244. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Packrats parse in packs

        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 52, Issue 10
          Haskell '17
          October 2017
          211 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/3156695
          • Editor:
          • Andy Gill
          Issue’s Table of Contents
          • cover image ACM Conferences
            Haskell 2017: Proceedings of the 10th ACM SIGPLAN International Symposium on Haskell
            September 2017
            211 pages
            ISBN:9781450351829
            DOI:10.1145/3122955

          Copyright © 2017 ACM

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 7 September 2017

          Check for updates

          Qualifiers

          • article
        • Article Metrics

          • Downloads (Last 12 months)3
          • Downloads (Last 6 weeks)1

          Other Metrics

        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!