extract functions

This commit is contained in:
theFox6 2020-02-19 09:12:51 +01:00
parent 32afec0b36
commit 80dba4c7c7
Signed by: theFox6
GPG Key ID: C884FE8D3BCE128A
3 changed files with 147 additions and 88 deletions

View File

@ -263,34 +263,30 @@ local function parse_element(el,pc)
return el, prefix
end
--TODO: make functions handling the lambdas
local function parse_line(l,pc)
local pl = ""
local i = 0
for sp,s in vp_util.optmatch(l,elements.spaces) do
if s then
if pc.lambargs then
pc.lambargs = pc.lambargs .. sp
elseif pc.deccheck then
if pc.deccheck == true then
pc.deccheck = sp
else
pc.deccheck = pc.deccheck .. sp
end
else
pl = pl .. sp
end
local function store_space(sp,pc)
if pc.optassign then
if pc.optassign ~= true then
pc.optassign = pc.optassign .. sp
end
end
if pc.lambargs then
pc.lambargs = pc.lambargs .. sp
return false
elseif pc.deccheck then
if pc.deccheck == true then
pc.deccheck = sp
return false
else
for st in vp_util.optmatch(sp,non_space_elements) do
if pc.slcomm then
pl = pl .. st
pc.deccheck = pc.deccheck .. sp
return false
end
else
local el,pre = parse_element(st,pc)
return true
end
end
local function handle_prefix(el,p)
local pre = p
local lpre
if pre then
while pre:match("\n") do
@ -315,12 +311,13 @@ local function parse_line(l,pc)
print("prel:" .. el)
end
--]]
if el == "" then
el = pre
elseif pre ~= "" then
el = pre .. " " .. el
return vp_util.concat_optnil(pre,el),lpre
end
return el
end
local function store_lambargs(e,pc)
local el = e
if pc.newlamb then
if pc.lambargs then
el = pc.lambargs .. el
@ -339,6 +336,10 @@ local function parse_line(l,pc)
--print("notl:", el)
end
end
return el
end
local function store_optassign(el,pc)
if pc.optassign and el ~= "" then
if pc.linestart and el:match(elements.names) then
if pc.optassign == true then
@ -350,6 +351,24 @@ local function parse_line(l,pc)
pc.optassign = false
end
end
end
local function parse_line(l,pc)
local pl = ""
local i = 0
for sp,s in vp_util.optmatch(l,elements.spaces) do
if s then
if store_space(sp,pc) then
pl = pl .. sp
end
else
for st in vp_util.optmatch(sp,non_space_elements) do
if pc.slcomm then
pl = pl .. st
else
local el,lpre = handle_prefix(parse_element(st,pc))
el = store_lambargs(el,pc)
store_optassign(el,pc)
if lpre then
pl = pl .. lpre .. el
else

View File

@ -125,6 +125,46 @@ function vp_util.dftc(t1,t2)
return true
end
---
--concatenate strings
--if one string is nil the other is returned
--
--@function [parent=#vp_util] concat_optnil
--@param #string fstr the first string to be concatenated
--@param #string lstr the second string to be concatenated
--@param #string sep the seperator to be added between the strings if both are present
--@param #string retstr The string returned if both strings are empty.
-- Can be true to return an empty string.
function vp_util.concat_optnil(fstr,lstr,sep,retstr)
if fstr then
if lstr then
if sep then
if fstr == "" or lstr == "" then
return fstr..lstr
else
return fstr..sep..lstr
end
else
return fstr..lstr
end
else
return fstr
end
else
if lstr then
return lstr
else
if retstr == true then
return ""
elseif retstr then
return retstr
else
return nil
end
end
end
end
---
--The unit tests for the vp utilities.
local function tests()