procdecl getgroup depth . out$[] s$ ok .
proc getitem depth . s$ out$[] .
   out$[] = [ "" ]
   while s$ <> ""
      c$ = substr s$ 1 1
      if depth > 0 and (c$ = "," or c$ = "}")
         return
      .
      s$ = substr s$ 2 9999
      isgroup = 0
      if c$ = "{"
         s0$ = s$
         getgroup depth + 1 og$[] s$ isgroup
         if isgroup = 1
            outn$[] = [ ]
            for o1$ in out$[]
               for o2$ in og$[]
                  outn$[] &= o1$ & o2$
               .
            .
            swap out$[] outn$[]
         else
            s$ = s0$
         .
      .
      if isgroup = 0
         if c$ = "\\"
            c$ = substr s$ 1 1
            s$ = substr s$ 2 9999
         .
         for i to len out$[]
            out$[i] &= c$
         .
      .
   .
.
proc getgroup depth . out$[] s$ ok .
   out$[] = [ ]
   while s$ <> ""
      getitem depth s$ g$[]
      for g$ in g$[]
         out$[] &= g$
      .
      c$ = substr s$ 1 1
      if c$ = "}"
         s$ = substr s$ 2 9999
         if comma = 0
            for i to len out$[]
               out$[i] = "{" & out$[i] & "}"
            .
         .
         ok = 1
         return
      .
      if c$ = ","
         comma = 1
         s$ = substr s$ 2 9999
      .
   .
   ok = 0
.
repeat
   s$ = input
   until s$ = ""
   print s$ & " ->"
   getitem 0 s$ r$[]
   for r$ in r$[]
      print r$
   .
   print ""
.
# 
input_data
~/{Downloads,Pictures}/*.{jpg,gif,png}
It{{em,alic}iz,erat}e{d,}, please.
{,{,gotta have{ ,\, again\, }}more }cowbell!
{}} some }{,{\\{ edge, edge} \,}{ cases, {here} \\\\\}
