Skip to content

Latest commit

 

History

History
38 lines (19 loc) · 730 Bytes

README.md

File metadata and controls

38 lines (19 loc) · 730 Bytes

Combinators

Parser combinators for Python.

Introduction

Combinators is a tiny parser combinator library which allows you to construct sophisticated parsers using context-free grammars.

# A parser for propositional logic.

from combinators import Match, Placeholder


# Terminals.

LeftBrace = Match("\(")

RightBrace = Match("\)")

UnaryConnective = Match("¬")

BinaryConnective = Match("[v\^>]")

Literal = Match("[A-Z]")


# Nonterminals.

Expression = Placeholder()

UnaryExpression = UnaryConnective + Expression

BinaryExpression = LeftBrace + Expression + BinaryConnective + Expression + RightBrace

Expression.parser = Literal | UnaryExpression | BinaryExpression