skip to main content
article

Packrats parse in packs

Published: 07 September 2017 Publication History

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).
[2]
Mario Blažević. 2013. Adding structure to monoids. ACM SIGPLAN NOTICES 48, 12 (2013), 37–45.
[3]
Mario Blažević. 2013. monoid-subclasses. http://hackage.haskell.org/package/ monoid-subclasses . (2013).
[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.
[5]
Noam Chomsky. 1956. Three models for the description of language. IRE Transactions on information theory 2, 3 (1956), 113–124.
[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.
[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.
[8]
Dominique Devriese. 2010. The grammar-combinators package. http://hackage. haskell.org/package/grammar-combinators . (2010).
[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
[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.
[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.
[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 .
[13]
Jay Earley. 1970. An efficient context-free parsing algorithm. Commun. ACM 13, 2 (1970), 94–102.
[14]
Levent Erkök and John Launchbury. 2000. Recursive monadic bindings. In ACM SIGPLAN Notices, Vol. 35. ACM, 174–185.
[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.
[16]
Bryan Ford. 2002. Packrat parsing:: simple, powerful, lazy, linear time, functional pearl. In ACM SIGPLAN Notices, Vol. 37. ACM, 36–47.
[17]
Bryan Ford. 2004. Parsing expression grammars: a recognition-based syntactic foundation. SIGPLAN Not. 39, 1 (2004), 111–122.
[18]
Olle Fredriksson. 2011. The Grempa package. http://hackage.haskell.org/package/ Grempa . (2011).
[19]
Olle Fredriksson. 2014. The Earley package. http://hackage.haskell.org/package/ Earley . (2014).
[20]
Robert Grimm. 2004. Practical packrat parsing. Technical Report. Dept. of Computer Science, New York University.
[21]
Robert Grimm. 2006. Better extensibility through modular syntax. In ACM SIGPLAN Notices, Vol. 41. ACM, 38–51.
[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.
[23]
Stephen C. Johnson. 1975. Yacc: Yet another compiler-compiler. Vol. 32. Bell Laboratories Murray Hill, NJ.
[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.
[25]
Conor McBride. 2011. Functional pearl: Kleisli arrows of outrageous fortune. Journal of Functional Programming (to appear) (2011).
[26]
John Meacham. 2006. The Frisby package. http://hackage.haskell.org/package/ frisby . (2006).
[27]
Matthew Might, David Darais, and Daniel Spiewak. 2011. Parsing with derivatives: a functional pearl. In ACM SIGPLAN notices, Vol. 46. ACM, 189–195.
[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.
[29]
Roman R Redziejowski. 2009. Mouse: from parsing expressions to a practical parser. In Concurrency Specification and Programming Workshop. Citeseer.
[30]
S Doaitse Swierstra. 2009. Combinator parsing: A short tutorial. In Language Engineering and Rigorous Software Development . Springer, 252–300.
[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.
[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.
[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
[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.

Recommendations

Comments

Information & Contributors

Information

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
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 07 September 2017
Published in SIGPLAN Volume 52, Issue 10

Check for updates

Author Tags

  1. Haskell
  2. memoizing
  3. packrat
  4. parser combinators
  5. rank-2 types

Qualifiers

  • Article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)6
  • Downloads (Last 6 weeks)0
Reflects downloads up to 27 Dec 2024

Other Metrics

Citations

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media