An alternative way to parse it. This gets all of the vars loaded into a
directory (anything that is separated by '=>'). I did not parse the from
or to lines, as I didn't know if you needed that info. If you do, it
should be fairly simple to tweak it.
fs = .stream~new('test.txt')
if fs~open('read') == 'READY:' then do
/* parse */
jobs = .array~new()
inside_from = .false
inside_to = .false
do while fs~lines() > 0
line = fs~linein()
select
when line~pos('=>') > 0 then do
/* we have assignments on this line */
/* these vars need to live over the whole life of the
words loop */
index = ''
hasindex = .false
do i = 1 to line~words()
word = line~word(i)
select
when word == '=>' then do
hasindex = .true
end
when hasindex then do
index = index~strip()
select
when inside_from then do
if
\jobs[jobs~last]~hasIndex('From') then do
jobs[jobs~last]['From'] =
.directory~new()
end
jobs[jobs~last]['From'][index] = word
end
when inside_to then do
if \jobs[jobs~last]~hasIndex('To')
then do
jobs[jobs~last]['To'] =
.directory~new()
end
jobs[jobs~last]['To'][index] = word
end
otherwise do
jobs[jobs~last][index] = word
end
end
/* reset */
index = ''
hasindex = .false
end
when \hasindex then do
if index == '' & word == 'Function' then do
/* start parsing new job */
jobs~append(.directory~new())
inside_from = .false
inside_to = .false
index = index' 'word
end
else do
index = index' 'word
end
end
otherwise nop
end
end
end
when line~word(1) == '>From' then do
/* we are on From line */
inside_from = .true
inside_to = .false
end
when line~word(1) == 'To' then do
/* we are on To line */
inside_from = .false
inside_to = .true
end
otherwise nop
end
end
fs~close()
/* display */
say jobs~items()
do job over jobs
say '-------------------------'
do field over job
if job[field]~isa(.directory) then do subfield over job[field]
say field' => 'subfield' => 'job[field][subfield]
end
else do
say field' => 'job[field]
end
end
end
end
--
Brandon Cherry
------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Oorexx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oorexx-users