[BangPypers] Do you think a more declarative RE syntax would make the world a better place ?

Dhananjay Nene dhananjay.nene at gmail.com
Tue Aug 10 05:27:56 CEST 2010


On Mon, Aug 9, 2010 at 5:04 PM, Vishal <vsapre80 at gmail.com> wrote:

> Hello fellas,
>
> I am trying to create a python function that can take an plain english
> description of a regular expression and return the regular expression to
> the
> caller.
>
> Currently I am thinking of the description in YAML format. So, we can store
> the description as a raw string variable, which is passed on to this
> another
> function and output of that function is then passed to the 're' module.
> Following is a rather simplistic example:
>
> # a(b|c)d+e*
>
> re1 = """
>
> - literal: 'a'
> - one_of: 'b,c'
> - one_or_more_of: 'd'
> - zero_or_more_of: 'e'
> """
>
> myre = re.compile(getRegex(re1))
>
> myre.search(...)
>
> etc.
>
> Does anyone think something of this sort would be of wider use? Do you know
> already existing packages that can do it? What are the limitations that you
> see to this approach? Does anyone think, having the declarative string in
> code, would make it more maintainable?
>

The real struggle here is the complexity of modeling the problem you are
attempting to solve. RE syntax per se isn't the problem though it could be
recast a bit in favour of readability and grokkability away from brevity
(not that I am in favour of that). The issue is really the complexity of the
diversity of situations that RE expressions attempt to model. Should you
wan't to attempt to support the entire range of scenarios that REs can
manage, I imagine the yaml will become excessively verbose to manage and
will eventually start suffering similar difficulties of grokkability that
complex REs end up with. While I don't think there's a good solution for
that, I think a victory if at all feasible could be better had through a
better modeling of how pattern matching expressions can be composed
(differently from current RE structures) rather than making the current
expression structures verbose and declarative.

Dhananjay

_______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>



-- 
--------------------------------------------------------
blog: http://blog.dhananjaynene.com
twitter: http://twitter.com/dnene


More information about the BangPypers mailing list