Build a glossary of terms in the XML specification
use XML::Parser; my $p = new XML::Parser Style => 'stream'; parsefile $p $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 { if (/<termdef/) { print "<dt>$_{term}</dt><dd>"; } elsif (/<term>/) { print "<b>"; } # some termdefs include grammar productions, sigh elsif (/<prod/ && grep(/^termdef$/, @{$p->{Context}})) { print "<br><tt>"; } } sub EndTag { if (/<.termdef/) { print "</dd>\n"; } elsif (/<.term>/) { print "</b>"; } elsif (/<.prod/ && grep(/^termdef$/, @{$p->{Context}})) { print "</tt>"; } elsif (/<.lhs/ && grep(/^termdef$/, @{$p->{Context}})) { print " ::= "; } } sub Text { if (grep(/^termdef$/, @{$p->{Context}}) && !grep(/^head$/, @{$p->{Context}})) { s/&/&/g; s/</</g; print; } } sub EndDocument { print "</dt></body></html>\n"; } |