[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Rexx-like parsing in Lua
- From: steve donovan <steve.j.donovan@...>
- Date: Mon, 25 Jun 2012 14:01:05 +0200
On Mon, Jun 25, 2012 at 12:18 PM, sergei karhof <karhof21@gmail.com> wrote:
> Basically, Rexx parsing is about chopping up strings into chunks,
> according to user-defined criteria, and serially assigning them to
> variables.
Somewhat similar is SIP (Simple Input Patterns, aka 'Lua string
patterns for Dummies'):
https://github.com/stevedonovan/Penlight/blob/master/lua/pl/sip.lua
sip.match('$v=$q','name="dolly"',res)
==> res=={'name','dolly'}
sip.match('($q{first},$q{second})','("john","smith")',res)
==> res=={second='smith',first='john'}
Nothing is magic in these strings, except for $TYPE [ {OPTIONAL_NAME}
]. Any space is treated as %s+
If I were redesigning this, I'd make the 'out' argument res optional,
and then it would return a new table.
Actually _assigning local variables_ is another matter, but David
Manura posted a most elegant solution, which I can't find.
steve d.