Monkey's Typewriter is a PEG parsing framework for Python designed for simplicity, ease of understanding and liberal interpretation of PEG expression grammars.
Monkey's Typewriter is zero dependency and uses python's internal re regex library for matching axiomatic elements and then 3 complex matchers to allow you to express your grammars.
Monkey's Typewriter is a tiny PEG library for writing any grammars
import mnkytw
Integer = mnkytw.MatchAlternation([
mnkytw.RegexMatch(r"[1-9][0-9]*"),
mnkytw.LiteralMatch("0")
])
mnkytw.parse("42", Integer)
Monkey's Typewriter implements six basic matchers, LiteralMatch
, RegexMatch
, MatchAlternation
, MatchJoin
, and MatchQuantity
, which allow you to build more complex grammars, capable of parsing any language. Because each matcher returns only basic results you can build more complex match classes that structure your parse tree in a data structure you like.
Monkey's Typewriter is licenced under the Apache Licence 2.0 and may be integrated into both non-commercial and commercial projects.