forum-msg-id-136400-edit

Original date:2021-10-24 04:29:21 Edited by: jmduro Subject: Re: Class programming with Euphoria

  -- replace target sequence attributes 
  code = replace_all(code, "%ENUM_TYPE%", upper(class_name)) 
  code = replace_all(code, "%ENUM_ITEMS%", join(enums, ',')) 
  code = replace_all(code, "%CLASS_NAME%", class_name) 
  code = replace_all(code, "%CLASS_CONTENT%", join(class_definition, ',')) 
   
  -- add converted code 
  puts(f_out, code) 
   
  -- add internal functions 
  puts(f_out, "\n") 
  puts(f_out, "procedure class_proc(sequence entity, integer method, sequence params = {})\n") 
  puts(f_out, "  call_proc(entity[method], {entity, params})\n") 
  puts(f_out, "end procedure\n") 
  puts(f_out, "\n") 
   
  puts(f_out, "function class_func(sequence entity, integer method, sequence params = {})\n") 
  puts(f_out, "  return call_func(entity[method], {entity, params})\n") 
  puts(f_out, "end function\n") 
  puts(f_out, "\n") 
   
  -- manage class entities 
  sequence entity_name = "" 
  sequence entities = "" 
  for l = start+1 to length(lines) do 
    -- lines[l] = trim(lines[l]) 
    sequence rule = sprintf("sequence (.*) = new\\(%s\\)$", {class_name}) 
    -- puts(f_out, rule & "\n") 
    r = regex:new(rule) 
    found = regex:find(r, lines[l]) 
    if sequence(found) then 
      {from, upto} = found[2] 
      entity_name = lines[l][from..upto] 
      entities = append(entities, entity_name) 
      printf(f_out, "sequence %s = %s\n", {entity_name, class_name}) 
    else 
      r = regex:new("([_A-za-z9-9]*)\\.([_A-za-z9-9]*)") 
      found = regex:find(r, lines[l]) 
      if sequence(found) then 
        {from, upto} = found[2] 
        entity_name = lines[l][from..upto] 
        if find(entity_name, entities) then  -- class referenced 
          -- check if it refers to a routine 
          {from, upto} = found[3] 
          name = lines[l][from..upto] 
          {from, upto} = found[1] 
          integer p = vlookup(name, elements, 1, 2, 0) 
          switch p do 
            case ATTR then 
              lines[l] = replace(lines[l], sprintf("%s[%s]", {entity_name, upper(name)}), from, upto) 
            case PROC then 
              from = find('(', lines[l], upto+1) 
              upto = find(')', lines[l], upto+1) 
              if upto > from+1 then 
                params = lines[l][from+1..upto-1] 
              else 
                params = {} 
              end if 
              lines[l] = sprintf("class_proc(%s, %s, %s)\n", {entity_name, upper(name), params}) 
            case FUNC then 
              from = find('(', lines[l], upto+1) 
              upto = find(')', lines[l], upto+1) 
              if upto > from+1 then 
                params = lines[l][from+1..upto-1] 
              else 
                params = {} 
              end if 
              lines[l] = sprintf("class_proc(%s, %s, %s)\n", {entity_name, upper(name), params}) 
            case else 
          end switch 
        end if 
      end if 
      puts(f_out, lines[l] & "\n") 
    end if 
  end for 
   
  close(f_out) 
end procedure 

It is launched this way:

convertOOP("test_classes_orig.oex", "basic_out.ex") 
Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu