[RavenclawDev 281] [924] Tools/RCTaskViz: Added a tool to publish Phoenix grammars on mediawiki wikis.
tk@edam.speech.cs.cmu.edu
tk at edam.speech.cs.cmu.edu
Tue Jun 12 23:44:44 EDT 2007
An HTML attachment was scrubbed...
URL: http://mailman.srv.cs.cmu.edu/pipermail/ravenclaw-developers/attachments/20070612/21b8a4c7/attachment.html
-------------- next part --------------
Property changes on: Tools/RCTaskViz
___________________________________________________________________
Name: svn:ignore
- taskviz.png
taskviz.txt
Thumbs.db
+ taskviz.png
taskviz.txt
Thumbs.db
lwpcookies.txt
Added: Tools/RCTaskViz/phoenix2mediawiki.pl
===================================================================
--- Tools/RCTaskViz/phoenix2mediawiki.pl (rev 0)
+++ Tools/RCTaskViz/phoenix2mediawiki.pl 2007-06-13 03:44:43 UTC (rev 924)
@@ -0,0 +1,91 @@
+#!/usr/local/bin/perl
+#
+# Thomas K Harris <tkharris at cs.cmu.edu>
+# June 2007
+#
+# Render a phoenix grammar as a mediawiki markup
+#
+########################################################################
+
+use CMS::MediaWiki;
+use Term::ReadPasswd;
+use Getopt::Long;
+use strict;
+
+sub usage {
+ die "usage: $0 [--title {title}] [--user {user}] [--debug {0 or 1 or 2}] {wikiurl} {phoenix grammar}";
+}
+
+my $CMDLINE = "$0 ".join(' ', @ARGV);
+my $TITLE = "Grammar";
+my $USER = undef;
+my $DEBUG = 0;
+GetOptions("--title=s", \$TITLE, "--user=s", \$USER, "--debug=i", \$DEBUG);
+&usage unless scalar @ARGV == 2;
+my ($PROTOCOL, $HOST, $PATH) = ($2 || 'http', $3, $4) if
+ $ARGV[0] =~ /(([^:]+):\/\/)?([^\/]+)\/?(\S*)/;
+die "Can't get host from $ARGV[0]$/" unless defined $HOST;
+my $GRAMMARFILE = $ARGV[1];
+open(GRAMMAR, $GRAMMARFILE) || die "Can't open grammarfile '$GRAMMARFILE'";
+
+for ('TITLE', 'USER', 'PROTOCOL', 'HOST', 'PATH') {
+ print STDERR "$_ => ", eval qq/\$$_/, $/;
+}
+
+my $mw = CMS::MediaWiki->new(protocol => $PROTOCOL,
+ host => $HOST,
+ path => $PATH,
+ debug => $DEBUG);
+
+my $PASS = undef;
+if (defined $USER) {
+ do {$PASS = read_passwd('password: ');} until defined $PASS;
+ die "Could not login" if $mw->login(user => $USER, pass => $PASS);
+}
+
+my $text = &process_grammar();
+
+$mw->editPage(title => $TITLE,
+ text => $text,
+ summary => "Automatically generated: $CMDLINE");
+
+exit 0;
+
+sub process_grammar {
+ my @text;
+ while(<GRAMMAR>) {
+ next if /^#/ || !/\S/;
+ if (/^\[([^\]]+)\]/) { #net
+ trim(my $net = $1);
+ push @text, "=$net=";
+ } elsif (/\s+\(([^\)]+)\)/) { #rule
+ trim(my $rule = $1);
+ push @text, process_rule($rule);
+ } elsif (/^[A-Z]+/) { #macro
+ my $macro = $&;
+ push @text, "==$macro==";
+ } elsif (/^;/) { #end net
+ #ignore
+ } else {
+ printf STDERR "Don't know what to do with: '$_'$/";
+ }
+ }
+ join $/, @text;
+}
+
+sub process_rule {
+ my @words = split(' ', shift);
+ for (@words) {
+ s/^([\*\+])?([A-Z]+)$/$1\[\[#$2|$2\]\]/g;
+ s/\*/\*/g;
+ s/\[([^#\]]+)\]/\[\[\[#$1|$1\]\]\]/g;
+ }
+ '*'.join(' ', @words);
+}
+
+sub trim {
+ $_ = shift;
+ s/^\s+//;
+ s/\s+$//;
+ $_;
+}
More information about the Ravenclaw-developers
mailing list