mustafaquraish / parsyc

A toy combinatorial parsing library from scratch, in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parsyc: Yet another combinatorial parser library.

Heavily inspired by the Parsec library from Haskell, this library allows you to use certain operators to emulate fmap like functionality, composing functions with Parser objects. For instance:

p = str.upper % String("hello world")

constructs a parser object that matches the literal text hello world and then returns the result of applying the str.upper function to it (so 'HELLO WORLD'). It allows you do chain these together, so here would be a parser for an integer:

integerP = int % Regex(r'[-+]?[0-9]+')
# integerP.parse("-37") --> -37
# integerP.parse("bad") --> None

About

A toy combinatorial parsing library from scratch, in Python


Languages

Language:Python 100.0%