grimace: a fluent regular expression generator in Python

Johann Hibschman jhibschman at gmail.com
Wed Jul 17 08:55:37 EDT 2013


Ben Last <ben at benlast.com> writes:

> Good points. I wanted to find a syntax that allows comments as well as
> being fluent:
> RE()
> .any_number_of.digits # Recall that any_number_of includes zero 
> .followed_by.an_optional.dot.then.at_least_one.digit # The dot is
> specifically optional
> # but we must have one digit as a minimum
> .as_string()

Speaking of syntax, have you looked at pyparsing?  I like their
pattern-matching syntax, and I can see it being applied to regexes.

They use an operator-heavy syntax, like:

    '(' + digits * 3 + ')-' + digits * 3 + '-' + digits * 4

That seems easier for me to read than the foo.then.follow syntax.

That then makes me think of ometa, which is a fun read, but probably not
completely relevant.

Regards,
Johann



More information about the Python-list mailing list