class Rexical::Generator

def parse_action(st, lastmodes=[])

def parse_action(st, lastmodes=[])
  modes  =  lastmodes
  mode  =  lastmodes[-1]
  ss  =  StringScanner.new(st)
  until ss.eos?
    c  =  ss.scan(/./)
    case  c
    when '#'
      if (mode == :brace) or (mode == nil)
        #p [c, mode, modes]
        return  modes
      end
    when '{'
      if (mode == :brace) or (mode == nil)
        mode = :brace
        modes.push  mode
      end
    when '}'
      if (mode == :brace)
        modes.pop
        mode = modes[0]
      end
    when "'"
      if (mode == :brace)
        mode = :quote
        modes.push  mode
      elsif (mode == :quote)
        modes.pop
        mode = modes[0]
      end
    when '"'
      if (mode == :brace)
        mode = :doublequote
        modes.push  mode
      elsif (mode == :doublequote)
        modes.pop
        mode = modes[0]
      end
    when '`'
      if (mode == :brace)
        mode = :backquote
        modes.push  mode
      elsif (mode == :backquote)
        modes.pop
        mode = modes[0]
      end
    end
  end
  #p [c, mode, modes]
  return  modes
end