[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: line parsing in lua
- From: Max Ischenko <max@...>
- Date: Tue, 12 Dec 2000 15:18:02 +0200
I'm trying to implement line parsing in Lua.
Line syntax is similar to shell one, where double quotes protect words in
them to be splitted.
<word> [<word> <"word with spaces"> ...]
I want to parse the line into Lua table where fields are line words.
cmd first-arg "second arg" 3
should be converted into table t
t.1 = 'cmd' t.2 = 'first-arg', t.3='second arg', t.4='3'
I found two variants but both are sucks:
gsub(args, '"?([^"]+)"?', function (w) tinsert(%t, w) end)
gsub(args, '(%w+)', function (w) tinsert(%t, w) end)
Has anyone better one?
PS: Why Lua uses it's own pattern syntax instead of popular and standard
BYTE editors are people who separate the wheat from the chaff, and then
carefully print the chaff.