Keep a stack of tagnames around. This will even work if things are nested. (Of course, if the file is in bad shape, you'll have to go through by hand, but that's the case anyway.) Pseudo-code:
# find something like @interface
push @stack, 'interface';
# parse lines until reaching a closing curly
my $tagname = pop @stack;
print "</$tagname>";
| [reply] [d/l] |
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,,,
| [reply] [d/l] |
I THINK I know what you are trying to ask, but maybe you could provide us with a concrete example of before and after so that we can better get our monk-minds around the problem.C-. | [reply] |
@interface {
i : in(1);
o : out(1);
}
After:
<interface>
<in name="i" width="1"/>
<out name="o" width="1"/>
</interface>
Thanks.
Edit: chipmunk 2001-08-02
| [reply] [d/l] [select] |
I screwed up on my reply. Here's another try,
leaving off the opening on the xml tags so it's
not interpreted as html:
Before:
@interface {
i : in(1);
o : out(1);
}
After:
interface>
in name="i" width="1"
out name="o" width="1"/
/interface>
The main trick is changing that closing bracket,
since there are other closing brackets that have
different names.
Thanks.
| [reply] |