moreati / ppeg

A Python port of Lua's LPeg pattern matching library
MIT License
6 stars 2 forks source link

API design: lpeg.P(nil|0|1|false|true) vs _ppeg.Pattern(None|0|1|False|True) #3

Open moreati opened 8 years ago

moreati commented 8 years ago

The current behaviour for LPeg and PPeg is

Lua Python Description
lpeg.P(), lpeg.P(nil) P() Raises an error
lpeg.P(false) P(None), P.Fail() A pattern that never matches
lpeg.P(true), lpeg.P(0) P(0), P.Any(0) A pattern that matches any string, and consumes no input
lpeg.P(1) P(1), P.Any(1) A pattern that matches and consumes 1 character

Pattern's constructor has no special treatment of booleans, so they happen to be treated to an int. This mean ppeg.P(True) currently has a different (misleadingly?) meaning to lpeg.P(true).