Re: type test broken

new topic     » goto parent     » topic index » view thread      » older message » newer message

On 11 Jul 2005, at 5:31, Matt Lewis wrote:

> 
> 
> posted by: Matt Lewis <matthewwalkerlewis at gmail.com>
> 
> Kat wrote:
> > 
> > 
> > I added the "if sequence(c)" to strtok-v2-1.e while trying to find why
> > calling
> > parse() didn't work properly. I called thusly:
> > 
> > }}}
<eucode>
> > include get.e -- for wait_key()
> > include wildcard.e -- for upper()
> > include Strtok-v2-2.e
> > include file.e
> > with trace
> > 
> > object junk, data, writefile
> > 
> > trace(1)
> > data = parse("AbCdEF",{"si",'c'})
> > 
> > writefile = open("H:\\DataMinerCode\\minenews\\newgetter-wget\\wget\\tmp2-
> > parsed.txt","w")
> > 
> > for loop = 1 to length(data) do
> >   
> > puts(writefile,data[loop]&"\n====================================
> > ====================================\n")
> > end for
> > close(writefile)
> > --junk = wait_key()
> > <font color="#330033"></eucode>
{{{
</font>
> > 
> > I have since rebooted the machine, no joy. I also tried the interpreter in
> > several project directories, in case one of them had been corrupted, no joy.
> > I
> > also tried both exw.exe and exw40.exe, no joy.
> 
> I only have strtok v2.1 (maybe 2.2 is unreleased, couldn't find any 
> reference to it other than this post).  

It *is* unreleased. I found this bug(?) and cannot get past it.

> I modified it a bit by adding
> the test for sequence (str isn't here, so I just did a "? 0").  I also
> reformatted some of the code in the big if block where you test for an
> atom.  I think the problem was that the "while" was on the same line
> as "else" and the tracer skips right over them.  If you move the while
> to its own line, you can see that the while condition is evaluated,
> and just skips over it.

If you watch the variable contents in the trace window, str should have been 
set to 1 in the ..else.. code (see below where i added it). It isn't. Ergo, it
isn't
executing. I'll paste the entire parse code to this email (below), and the code 
which calls parse() again.
 
> I did a dissassembly of the il code using ooeu, and the reason for this
> I think is that an else doesn't get a STARTLINE opcode, which is what 
> the tracer looks for, and since it's not a new line, the while must not
> generate it.  So I think that the code is executing properly, but just
> looks like it isn't because of the formatting and the peculiarities with
> the tracer.
> }}}
<eucode>
> global function parse(sequence s, object c) -- "object" by kat
> integer slen, spt, flag, keep, case
> sequence parsed, upperc, uppers
> keep = 0
> case = 0
> upperc = ""
> uppers = ""
> 
> if sequence(c) then
>  ? 0
> end if
> 
> if atom(c) then -- kat
> 
>   c = {c}
>   else 
>    while equal(c[1],"k") or equal(c[1],"i") do

put this code where it's obvious to be:

else while equal(c[1],"k") or equal(c[1],"i") or equal(c[1],"s")do
  
         if equal(c[1],"s") then
           str = 1
           thestring = c[2]
           lenc = length(thestring)
           c = c[2..length(c)]
         end if
         



>          if equal(c[1],"k") then
>            keep = 1
>            c = c[2..length(c)]
>          end if
>          if equal(c[1],"i") then
>            case = 1
>            c = c[2..length(c)]
>          end if
>     end while
> end if -- kat
> </eucode>
{{{



--Andy Serpas Turbo version 3X faster
-- modified by Kat for case and keep-separator
-- getting modified more by Kat July 11 2005
-- yes, this is a mess, i am trying to add my parses() to parse()
-- and keep backwards compatability

global function parse(sequence s, object c) -- "object" by kat
integer slen, spt, flag, keep, case, str, lenc
sequence parsed, upperc, uppers, thestring, temp

keep = 0
case = 0
str = 0
upperc = ""
uppers = ""
parsed = {}

if sequence(c) then -- i added this *only* because the atom() failed
  str = 0  -- if the trace window stops here, it's a seq
end if  -- if a seq, then the else right below should run too

if atom(c) -- kat
  then 
       c = {c}
       temp = c
  else while equal(c[1],"k") or equal(c[1],"i") or equal(c[1],"s")do
  
         if equal(c[1],"s") then
           str = 1 -- this does NOT happen, watch the variable dump!
           thestring = c[2]
           lenc = length(thestring)
           c = c[2..length(c)]
         end if
         
         if equal(c[1],"k") then
           keep = 1
           c = c[2..length(c)]
         end if
         
         if equal(c[1],"i") then
           case = 1
           c = c[2..length(c)]
         end if
       end while
       
end if -- kat


if str then
  if case 
    then temp = -lenc & find_alls(upper(thestring),upper(s)) & length(s)
    else temp = -lenc & find_alls(thestring,s) & length(s)  
  end if
    
  for loop = 1 to length(temp)-1 do
    parsed &= {s[temp[loop]+lenc+1..temp[loop+1]-1]}
  end for
  
return parsed

end if

if atom(c) -- kat
  then c = {c}
end if
	parsed = {}
	slen = length(s)
	spt = 1
	flag = 0

if case = 0 then
	for i = 1 to slen do
		--if s[i] = c then -- kat
		if find(s[i],c) then
			if flag = 1 then
				parsed = append(parsed,s[spt..i-1])
				if keep then
				  parsed = append(parsed,{s[i]})
				end if
				flag = 0
				spt = i+1
			else
				spt += 1
			end if
		else
			flag = 1
		end if
	end for
	if flag = 1 then
		parsed = append(parsed,s[spt..slen])
	end if
end if

if case = 1 then  -- kat
  upperc = upper(c)
  uppers = upper(s)
	for i = 1 to slen do
		--if s[i] = c then -- kat
		if find(uppers[i],upperc) then
			if flag = 1 then
				parsed = append(parsed,s[spt..i-1])
				if keep then
				  parsed = append(parsed,{s[i]})
				end if
				flag = 0
				spt = i+1
			else
				spt += 1
			end if
		else
			flag = 1
		end if
	end for
	if flag = 1 then
		parsed = append(parsed,s[spt..slen])
	end if
end if

	return parsed
end function

include get.e -- for wait_key()
include wildcard.e -- for upper()
include Strtok-v2-2.e
include file.e
with trace

object junk, data, writefile

trace(1)
data = parse("AbCdEF",{"si",'c'})

writefile = open("H:\\DataMinerCode\\minenews\\newgetter-wget\\wget\\tmp2-
parsed.txt","w")

for loop = 1 to length(data) do
  
puts(writefile,data[loop]&"\n====================================
====================================\n")
end for
close(writefile)
--junk = wait_key()




new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu