flat assembler
Message board for the users of flat assembler.

flat assembler > Heap > help needed: failed to adapt split syntax look like match

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 170
Location: Russian Federation, Sochi
Is it possible to make analog of match that splitting phrase not by complete tokens but by their parts:
Code:
define phrase Have a nice day
match any =a more,phrase ; any=Have ; more = nice day
split any =a more,phrase ; any=H ; more = ve a nice day    

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.


Last edited by ProMiNick on 12 Jul 2018, 07:23; edited 2 times in total
Post 11 Jul 2018, 09:37
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6927
Location: Kraków, Poland
The only option is to convert tokens to string and after processing tokenize it back with EVAL:
Code:
macro split phrase&
        cmd ='define any '
        ; replace "eval" with "display" to see what gets defined
        eval string cmd + (`phrase and 0FFh) shl (8 * lengthof cmd)
        cmd ='define more '
        eval string cmd + (`phrase shr 8) shl (8 * lengthof cmd)
end macro

split Have a nice day    
And string processing you'd have to do manually.
Post 11 Jul 2018, 09:47
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 170
Location: Russian Federation, Sochi
Thanks
With parsing phrase& to format like format on that match operate (I think) I will do it myself.
I will share results in this topic.

helper macro
Code:
macro catstr str,[arg]
  forward
    str = str +arg shl (8 * lengthof str)
end macro    
For now (unfinished):
Code:
macro split? phrase&
  local ?phrase 
  local ?s,@pattern,@source
  define @pattern
  define @source

  macro reslash args
    local cmd
    iterate arg,args
      cmd='define '
      catstr cmd,`arg,' '
      repeat lengthof `arg
        if (`arg shr (8*(%-1))) and 0FFh = '\'
        else
          catstr cmd,(`arg shr (8*(%-1))) and 0FFh
      end repeat
      eval string cmd
    end iterate
  end macro 

  macro end?.split?! 
    end match 
  end macro

  define ?s
  iterate element,phrase ;parse phrase
     match ,?s 
       match any ==,element 
         define @pattern @pattern any =,
       else
         define @pattern @pattern element
         define ?s 1
       end if 
     else 
       define @source @source ,element
     end if 
  end iterate

  ;prepare ?phrase 
  cmd='define ?phrase ' 
  repeat lengthof `@source
    if (`@source shr (8*(%-1))) and 0FFh = ' '
      catstr cmd," " 
    else 
      catstr cmd,"\",(`@source shr (8*(%-1))) and 0FFh
    end if 
  eval string cmd

  ;prepare ?pattern 
  define @source ;reuse ?source
  define ?s @pattern 
   define @pattern
   while 1         ; extract vars in pattern that should be defined 
     match =,?s ; sequence "= " in pattern dosn`t operated correctly for now (or for forever) 
       break 
     else match any more,?s 
       match ==,any 
         match first rest,more 
           cmd='define @pattern @pattern '
           repeat lengthof first 
             catstr cmd,"=\ =",(`first shr (8*(%-1))) and 0FFh, 
           end repeat 
           eval string cmd
           define ?s rest
         else
           ;define ?pattern ?pattern =
           break
         end if 
       else 
         define @pattern @pattern any
         define @source @source,any
         define ?s more
       end if 
     end if 
   end while 
  match @pattern,?phrase
    match =, any,@source
      reslash any 
    end match 
  ;end match - will be in end split 
end macro


split any =a more,Have a nice day
  ;here we should get H in any, ve a nice day in more
end split    


tried to catch where I wrong:
Code:
macro split? phrase&
  local ?phrase 
  local ?s,@pattern,@source
  define @pattern
  define @source

  macro reslash args
    local cmd
    iterate arg,args
      cmd='define '
      catstr cmd,`arg,' '
      repeat lengthof `arg
        if (`arg shr (8*(%-1))) and 0FFh = '\'
        else
          catstr cmd,(`arg shr (8*(%-1))) and 0FFh
      end repeat
      eval string cmd
    end iterate
  end macro 

  macro end?.split?! 
    end match 
  end macro

  define ?s
  iterate element,phrase ;parse phrase
     match ,?s 
       match any ==,element 
         define @pattern @pattern any =,
       else
         define @pattern @pattern element
         display `element,13,10
         display `@pattern,13,10
         define ?s 1
       end if 
     else 
       define @source @source ,element
     end if 
  end iterate
  display 'OK',13,10
  display `@pattern,13,10
  display `@source,13,10

  ;prepare ?phrase 
  cmd='define ?phrase ' 
  repeat lengthof `@source
    if (`@source shr (8*(%-1))) and 0FFh = ' '
      catstr cmd," " 
    else 
      catstr cmd,"\",(`@source shr (8*(%-1))) and 0FFh
    end if 
  eval string cmd

  ;prepare ?pattern 
  define @source ;reuse ?source
  define ?s @pattern 
   define @pattern
   while 1         ; extract vars in pattern that should be defined 
     match =,?s ; sequence "= " in pattern dosn`t operated correctly for now (or for forever) 
       break 
     else match any more,?s 
       match ==,any 
         match first rest,more 
           cmd='define @pattern @pattern '
           repeat lengthof first 
             catstr cmd,"=\ =",(`first shr (8*(%-1))) and 0FFh, 
           end repeat 
           eval string cmd
           define ?s rest
         else
           ;define ?pattern ?pattern =
           break
         end if 
       else 
         define @pattern @pattern any
         define @source @source,any
         define ?s more
       end if 
     end if 
   end while 
  match @pattern,?phrase
    match =, any,@source
      reslash any 
    end match 
  ;end match - will be in end split 
end macro


split any =a more,Have a nice day
  ;here we should get H in any, ve a nice day in more
end split    
Post 11 Jul 2018, 09:59
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.