lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Sep 24, 2013 at 6:43 PM, Craig Barnes <craigbarnes85@gmail.com> wrote:
On 24 September 2013 13:07, David Crayford <dcrayford@gmail.com> wrote:
> I'm another layman wanting to grok LPeg. I come from a mainframe background
> where the lingua franca is REXX. Lua really does nuke REXX in just about
> every aspect other than simplicity of parsing.
>
> Take the following output from a netstat command.
>
> Client Name: SMTP                     Client Id: 000000B7
>   Local Socket: 0.0.0.0..1049
>   Foreign Socket: *..*
>     BytesIn:            00000000000000493311
>     BytesOut:           00000000000000366747
>     DgramIn:            00000000000000008397
>     DgramOut:           00000000000000008529
>     Last Touched:       10:51:10
>     MaxSendLim:         0000065535       MaxRecvLim: 0000065535
>     SockOpt:            D0000000         DSField:            00
>     QOSPolicy:          No
>     RoutingPolicy:      No
>     ReceiveDataQueued:  0000000000       ReceiveMsgCnt: 0000000000
>
> I would love to learn how to write LPeg parser to yank the key->values from
> that multi-line report easily. I know it can be done I just can't work it
> out because I'm a neophyte.
>

I just threw together a rough example with LPeg, if it helps at all:

https://gist.github.com/craigbarnes/6684442/raw/a116dbe6de85be76a54ec2321e0eb9c3e51e96f8/gistfile1.lua


Somewhat confused... isn't the LPEG module included using:
   require("lpeg")
and not:
   require("re")

Is it the regex emulation done using LPEG ?