lua-users home
lua-l archive

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

David Crayford wrote:
I've ported Lua to IBM mainframes and it's a joy and very fast, in some
cases by over an order of magnitude. However, selling it is going to be
difficult to the masses that grew up on REXX.

I want to parse a HTTP header string "name:value" pair. In REXX this is
quite simple with the parse instruction, "parse var line name ":"
value". In lua it seems much trickier using
the example i have "local _, _, name, value = string.find(line, "^([^:
]+)%s*:%s*(.+)")". I understand that captures are much more powerful but
what I want is to dumb them down so there
is a lower entry level of skill required to do what is simple in REXX.
Maybe it's possible to write a parse(line,"%s : %s:) function or
something similar. It's most likely the case that I just don't
know Lua string handling well enough to grok what is the best solution.

WARNING: Untested code follows...and don't take my comments re REXXers too seriously

I think you are saying that this:

local _, _, name, value = string.find(line, "^([^:]+)%s*:%s*(.+)")

is too hard for your typical REXX programmer to figure out - maybe that's true. The pattern will be generally useful, and they don't need to figure it out every place they need to parse an HTTP Header string, so I would suggest wrapping if like this (make foo some helpful library name)

foo.regex = { ["httpHeader'] = "^([^:]+)%s*:%s*(.+)"
            , ....
            , ....

local httpHeader = foo.regex.httpHeader

local _, _, name, value = string.find(line, httpHeader )

or if you want to skip the local:

local _, _, name, value = string.find(line, foo.regex.httpHeader )

It's a bit of work to gather up the common regexen you need, but it will help your feeble minded REXXers do their job without taxing their remaining brain cells.

My 2c