| use XML::Parser; my $p = new XML::Parser Style => 'stream'; $p->parsefile($ARGV[0]); sub StartDocument { print "<html><head><title>List of Terms</title></head>\n"; print "<body><h2>List of Terms</h2>\n<dl>\n"; } sub StartTag { my $expat = shift; if (/<termdef/) { print "<dt>$_{term}</dt><dd>"; } elsif (/<term>/) { print "<b>"; } # some termdefs include grammar productions, sigh elsif (/<prod/ && grep(/^termdef$/, $expat->context)) { print "<br><tt>"; } } sub EndTag { my $expat = shift; if (/<termdef/) { print "<dt>$_{term}</dt><dd>"; } if (/<.termdef/) { print "</dd>\n"; } elsif (/<.term>/) { print "</b>"; } elsif (/<.prod/ && grep(/^termdef$/, $expat->context)) { print "</tt>"; } elsif (/<.lhs/ && grep(/^termdef$/, $expat->context)) { print " ::= "; } } sub Text { my $expat = shift; if (grep(/^termdef$/, $expat->context) && !grep(/^head$/, $expat->context)) { s/&/&/g; s/</</g; print; } } sub EndDocument { print "</dt></body></html>\n"; } |