Skip to content

oelin/combinators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published

Languages