2016-12-29 22:50:47 +01:00
|
|
|
local function parse_zeile(marken, imms, z, ip)
|
2016-11-13 14:42:57 +01:00
|
|
|
-- Kommentar entfernen
|
|
|
|
local komment = z:find";"
|
|
|
|
if komment then
|
|
|
|
z = z:sub(1, komment-1)
|
|
|
|
end
|
|
|
|
|
|
|
|
z = z:trim()
|
|
|
|
if #z == 0 then
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Marke erkennen
|
|
|
|
local marke = z:find":"
|
|
|
|
if marke then
|
2016-12-28 18:27:41 +01:00
|
|
|
local mname = z:sub(1, marke - 1)
|
2016-12-29 22:50:47 +01:00
|
|
|
marken[mname] = ip
|
2016-11-13 14:42:57 +01:00
|
|
|
|
|
|
|
z = z:sub(marke+1):trim()
|
|
|
|
if #z == 0 then
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Befehl erkennen
|
|
|
|
local immn = #imms+1
|
|
|
|
local befehl = z
|
|
|
|
local args
|
|
|
|
local leernb = z:find" "
|
|
|
|
if leernb then
|
|
|
|
befehl = z:sub(1, leernb - 1)
|
|
|
|
|
|
|
|
-- Argument(e) erkennen
|
|
|
|
z = z:sub(leernb+1):trim()
|
|
|
|
args = z:split","
|
|
|
|
for i = 1,#args do
|
|
|
|
local arg = args[i]:trim()
|
|
|
|
if #arg == 0
|
|
|
|
or arg == "false" then
|
2017-06-26 19:39:20 +02:00
|
|
|
arg = -1
|
2016-11-13 14:42:57 +01:00
|
|
|
elseif arg == "true" then
|
2017-06-26 19:39:20 +02:00
|
|
|
arg = -2
|
2016-11-13 14:42:57 +01:00
|
|
|
elseif arg:sub(1, 1) == "$" then
|
|
|
|
imms[immn] = arg:sub(2)
|
|
|
|
arg = immn
|
|
|
|
immn = immn+1
|
|
|
|
elseif tonumber(arg) then
|
|
|
|
imms[immn] = tonumber(arg)
|
|
|
|
arg = immn
|
|
|
|
immn = immn+1
|
|
|
|
end
|
|
|
|
args[i] = arg
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return {befehl, args}
|
|
|
|
end
|
|
|
|
|
2017-04-13 23:05:50 +02:00
|
|
|
local function zeileniter(text)
|
|
|
|
return function()
|
|
|
|
if not text then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local umbruch = text:find"\n"
|
|
|
|
if not umbruch then
|
|
|
|
local rv = text
|
|
|
|
text = nil
|
|
|
|
return rv
|
|
|
|
end
|
|
|
|
local rv = text:sub(1, umbruch-1)
|
|
|
|
text = text:sub(umbruch+1)
|
|
|
|
return rv
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-13 14:42:57 +01:00
|
|
|
return function(programm)
|
2017-06-26 19:39:20 +02:00
|
|
|
local imms = {[-2] = true, [-1] = false}
|
2016-11-13 14:42:57 +01:00
|
|
|
local marken = {}
|
|
|
|
|
|
|
|
-- Programm erkennen
|
2016-12-28 18:27:41 +01:00
|
|
|
local anz = 0
|
|
|
|
local liste = {}
|
2017-04-13 23:05:50 +02:00
|
|
|
local zn = 1
|
|
|
|
for zeile in zeileniter(programm) do
|
|
|
|
local befehl = parse_zeile(marken, imms, zeile, anz + 1)
|
2016-12-28 18:27:41 +01:00
|
|
|
if befehl[1] then
|
2017-04-13 23:05:50 +02:00
|
|
|
befehl[3] = zn -- Zeilennummer für Fehlernachrichten
|
2016-12-28 18:27:41 +01:00
|
|
|
anz = anz + 1
|
|
|
|
liste[anz] = befehl
|
|
|
|
end
|
2017-04-13 23:05:50 +02:00
|
|
|
zn = zn+1
|
2016-11-13 14:42:57 +01:00
|
|
|
end
|
|
|
|
local immn = #imms+1
|
|
|
|
|
|
|
|
-- Marken durch immediates ersetzen
|
2016-12-28 18:27:41 +01:00
|
|
|
for i = 1,anz do
|
2016-11-13 14:42:57 +01:00
|
|
|
local args = liste[i][2]
|
|
|
|
if args then
|
|
|
|
for i = 1,#args do
|
|
|
|
local mwert = marken[args[i]]
|
|
|
|
if mwert then
|
|
|
|
imms[immn] = mwert
|
|
|
|
args[i] = immn
|
|
|
|
immn = immn+1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return {imms, liste}
|
|
|
|
end
|