in reply to How do I replace brackets with XML tags?

Hello,

Here is something I cooked in 4 minutes. Here is how it works:

  1. Slurp the entire file into a string, removing all white spaces since we won't need them.
  2. Get the text matching "@somesthing{somestuff}"
  3. Print the opening tag "<something>"
  4. Match somestuff with "name:method(size);"
  5. Print the xml element '<method name="name" width="size"/>'
  6. Goto 4 until somestuff is depleted
  7. Print closing tag "</something>"
  8. Goto 2 until the file is depleted
There are other ways this can be done of course, but this is how I'd do it.
my $str = join '', map{s/\s+//g;$_}<DATA>; while($str =~ /@(\w+){([^}]*)}/g){ my ($int, $imp) = ($1,$2); print "<$int>\n"; printf qq{\t<%s name="%s" width="%s"/>\n}, $2,$1,$3 while $imp=~/([^:]+):([^(]+)\((\d+)\);/g; print "</$int>\n"; } __DATA__ @interface { i : in(1); o : out(1); } @interface2 { b : out(1); a : in(1); } @interface3 { x : in(1); y : in(1); } @interface4 { f : out(1); b : out(1); } OUTPUT: <interface> <in name="i" width="1"/> <out name="o" width="1"/> </interface> <interface2> <out name="b" width="1"/> <in name="a" width="1"/> </interface2> <interface3> <in name="x" width="1"/> <in name="y" width="1"/> </interface3> <interface4> <out name="f" width="1"/> <out name="b" width="1"/> </interface4>
Of course, this does not handle nested interfaces; did you want that?

Hope this helps,,,

Aziz,,,