Hello,
Here is something I cooked in 4 minutes. Here is how it works:
- Slurp the entire file into a string, removing all white spaces since we won't need them.
- Get the text matching "@somesthing{somestuff}"
- Print the opening tag "<something>"
- Match somestuff with "name:method(size);"
- Print the xml element '<method name="name" width="size"/>'
- Goto 4 until somestuff is depleted
- Print closing tag "</something>"
- 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,,,
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.