[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Patterns and parens (was: Newbie question list: Was The perverse vibe of lua-l)
- From: David Kastrup <dak@...>
- Date: Thu, 27 Jan 2011 00:29:37 +0100
Tim Mensch <tim-lua-l@bitgems.com> writes:
> Something I noticed as I was reading the pattern docs for my post is
> that Lua adds one thing to patterns that I've not seen in regular
> expressions that does allow you to parse nested brackets:
>
> ----
> %bxy, where x and y are two distinct characters; such item matches
> strings that start with x, end with y, and where the x and y are
> balanced. This means that, if one reads the string from left to right,
> counting +1 for an x and -1 for a y, the ending y is the first y where
> the count reaches 0. For instance, the item %b() matches expressions
> with balanced parentheses.
> ----
>
> I hadn't run across that before, and it's cool.
It is not cool enough since it does not help matching stuff with escape
sequences or similar in it.
One would rather need:
%+n matches the empty string and increases counter n
%-n matches the empty string if counter n is non-zero, decreasing it
%=n matches the empty string if counter n is zero
Another possibility would be to have %rn where %rn substitutes the
definition of %n recursively.
--
David Kastrup
- References:
- The perverse vibe of lua-l, Dirk Laurie
- Newbie question list: Was The perverse vibe of lua-l, Steve Litt
- Re: Newbie question list: Was The perverse vibe of lua-l, Javier Guerra Giraldez
- Re: Newbie question list: Was The perverse vibe of lua-l, Steve Litt
- Re: Newbie question list: Was The perverse vibe of lua-l, Tim Mensch
- Re: Newbie question list: Was The perverse vibe of lua-l, Miles Bader
- RE: Newbie question list: Was The perverse vibe of lua-l, Aaron Brown
- RE: Newbie question list: Was The perverse vibe of lua-l, Aaron Brown
- Re: Newbie question list: Was The perverse vibe of lua-l, Miles Bader
- Re: Newbie question list: Was The perverse vibe of lua-l, Peter Cawley
- Re: Newbie question list: Was The perverse vibe of lua-l, Tony Finch
- Re: Newbie question list: Was The perverse vibe of lua-l, Tim Mensch