lua-users home
lua-l archive

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


On Thursday, June 11, 2015 07:40:51 PM David Crayford wrote:
> I love it. I've got a Lua for z/OS port and REXX is *the* scripting 
> language of the mainframe. It's tricky for REXXers to learn Lua string 
> patterns when they are so used to parse, which is much simpler for lots 
> of use cases. Does your library handle positional parsing?

Yes it does. Also relative positions and positions supplied by a variable: the 
"=(vref)" format.

> It would be nice to be able to pre-compile a template pattern for 
> optimization. For example, parsing a large text file.

This is currently handled by the same parse function. The single call

    result = rexxparse.parse(testString, matchPattern, envTable)

has the arguments in that order to look similar to the Rexx command. But it 
can only handle a single string argument. The expanded way to call the parser 
and the only way to pass multiple arguments is

    parser = rexxparse.parse(matchPattern)
    result = parser(envTable, testString)

The parser is a coroutine that can be invoked again to parse other strings. If 
this is too confusing I could make it two separate functions.

    local today = os.date "%m/%d"
    local parser = rexxparse.parse "name1 11 name2 21 birthday 26" -- no year
    for record in io.lines("memberslist.txt") do
        local memberInfo = parser(record)
        if memberInfo.birthday == today then
            sendmail(memberInfo.name2 .. " "..memberInfo.name1,
                    "Happy birthday!")
        end
    end


-- 
(Pat Brown)