Re: Class programming with Euphoria

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

Following preprocessor (preprocessor.ex) converts this class-oriented code to Euphoria code (basic_out.ex):

include std/io.e 
include std/text.e 
include std/regex.e 
include std/search.e 
include std/sequence.e 
include std/datetime.e 
 
constant ATTR=1, PROC=2, FUNC=3 
 
function replace_all(sequence s, sequence old, sequence new)  
  integer lg = length(old)  
  integer index = match(old, s, 1)  
  while index != 0 do  
    s = replace(s, new, index, index+lg-1)  
    index = match(old, s, index+lg)  
  end while  
  return s  
end function  
 
function manage_routine(sequence code, sequence lines, integer start) 
  integer from, upto 
   
  for i = start+1 to length(lines) do 
    if begins("end ", trim(lines[i])) then 
      code &= lines[i] & "\n" 
      start = i 
      exit 
    end if 
    sequence rule = "self\\.([_A-Za-z][_A-Za-z0-9]*)" 
    -- puts(f_out, rule & "\n") 
    regex r = regex:new(rule) 
    object found = regex:find_all(r, lines[i]) 
    if sequence(found) then 
      for j = 1 to length(found) do 
        {from, upto} = found[j][2] 
        sequence name = lines[i][from..upto] 
        {from, upto} = found[j][1] 
        lines[i] = replace(lines[i], sprintf("entity[%s]", {upper(name)}), from, upto) 
      end for 
      code &= lines[i] & "\n" 
    end if 
  end for 
  return {code, start} 
end function 

To be continued ...

</eucode>

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

Search



Quick Links

User menu

Not signed in.

Misc Menu