extract functions
This commit is contained in:
parent
32afec0b36
commit
80dba4c7c7
69
init.lua
69
init.lua
|
@ -263,34 +263,30 @@ local function parse_element(el,pc)
|
||||||
return el, prefix
|
return el, prefix
|
||||||
end
|
end
|
||||||
|
|
||||||
--TODO: make functions handling the lambdas
|
local function store_space(sp,pc)
|
||||||
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
|
|
||||||
if pc.optassign then
|
if pc.optassign then
|
||||||
if pc.optassign ~= true then
|
if pc.optassign ~= true then
|
||||||
pc.optassign = pc.optassign .. sp
|
pc.optassign = pc.optassign .. sp
|
||||||
end
|
end
|
||||||
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
|
else
|
||||||
for st in vp_util.optmatch(sp,non_space_elements) do
|
pc.deccheck = pc.deccheck .. sp
|
||||||
if pc.slcomm then
|
return false
|
||||||
pl = pl .. st
|
end
|
||||||
else
|
else
|
||||||
local el,pre = parse_element(st,pc)
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function handle_prefix(el,p)
|
||||||
|
local pre = p
|
||||||
local lpre
|
local lpre
|
||||||
if pre then
|
if pre then
|
||||||
while pre:match("\n") do
|
while pre:match("\n") do
|
||||||
|
@ -315,12 +311,13 @@ local function parse_line(l,pc)
|
||||||
print("prel:" .. el)
|
print("prel:" .. el)
|
||||||
end
|
end
|
||||||
--]]
|
--]]
|
||||||
if el == "" then
|
return vp_util.concat_optnil(pre,el),lpre
|
||||||
el = pre
|
|
||||||
elseif pre ~= "" then
|
|
||||||
el = pre .. " " .. el
|
|
||||||
end
|
end
|
||||||
|
return el
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function store_lambargs(e,pc)
|
||||||
|
local el = e
|
||||||
if pc.newlamb then
|
if pc.newlamb then
|
||||||
if pc.lambargs then
|
if pc.lambargs then
|
||||||
el = pc.lambargs .. el
|
el = pc.lambargs .. el
|
||||||
|
@ -339,6 +336,10 @@ local function parse_line(l,pc)
|
||||||
--print("notl:", el)
|
--print("notl:", el)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return el
|
||||||
|
end
|
||||||
|
|
||||||
|
local function store_optassign(el,pc)
|
||||||
if pc.optassign and el ~= "" then
|
if pc.optassign and el ~= "" then
|
||||||
if pc.linestart and el:match(elements.names) then
|
if pc.linestart and el:match(elements.names) then
|
||||||
if pc.optassign == true then
|
if pc.optassign == true then
|
||||||
|
@ -350,6 +351,24 @@ local function parse_line(l,pc)
|
||||||
pc.optassign = false
|
pc.optassign = false
|
||||||
end
|
end
|
||||||
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
|
if lpre then
|
||||||
pl = pl .. lpre .. el
|
pl = pl .. lpre .. el
|
||||||
else
|
else
|
||||||
|
|
40
vp_util.lua
40
vp_util.lua
|
@ -125,6 +125,46 @@ function vp_util.dftc(t1,t2)
|
||||||
return true
|
return true
|
||||||
end
|
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.
|
--The unit tests for the vp utilities.
|
||||||
local function tests()
|
local function tests()
|
||||||
|
|
Loading…
Reference in New Issue