forum-msg-id-136398-edit

Original date:2021-10-26 02:00:26 Edited by: jmduro Subject: Re: Class programming with Euphoria

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 
include std/filesys.e 
 
public sequence InitialDir = init_curdir() 
 
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 
    lines[i] = trim(lines[i]) 
    if begins("end ", 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>

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu