[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A little bit of golf
- From: Andrew Starks <andrew.starks@...>
- Date: Tue, 7 Apr 2015 22:06:23 -0500
On Tuesday, April 7, 2015, Sean Conner <sean@conman.org> wrote:
It was thus said that the Great Daurnimator once stated:
> On 8 April 2015 at 10:12, Hisham <h@hisham.hm> wrote:
> > Ah! NO LPEG ALLOWED! :)
>
> Why not?
Way too easy.
lpeg = require "lpeg"
id = lpeg.R("AZ","az","09","__")^1 / variables
expand_variables = lpeg.Cs((
(lpeg.P"${") / "" * id * (lpeg.P"}"/"")
+ (lpeg.P"$") / "" * id
+ lpeg.C(lpeg.P(1))
)^0)
-spc (Could be made even smaller ... )
Right. Too easy and too readable. :)
-Andrew