#! /usr/bin/gawk -f # Last edited on 2000-06-14 04:54:06 by stolfi BEGIN { abort = -1; usage = ( ARGV[0] " [ -v title=STRING ] < INFILE.grx > OUTFILE.html" ); # Reads a grammar in ".grx" format, outputs a nice # HTML rendering of the same. # If the title is specified, outputs the HTML header end trailer, # as well as a
\n";
}
/^ *$/ {
printf "\n";
next;
}
/^ *[#] *Data-File *:/ {
next;
}
/^ *[#]/ {
cmt = $0;
sub(/# =/, "===", cmt);
sub(/# -/, "---", cmt);
sub(/#/, " ", cmt);
printf "%s\n", cmtcolor, html_protect(cmt);
next;
}
/^[A-Z()].*[:]/ {
name = $0; gsub(/ *[:] *$/, "", name);
printf "\n", html_protect(name);
printf "%s:\n", ntscolor, html_protect(name);
next;
}
/./ {
match($0, /[ ][^ ]+[ ]*$/);
cts = substr($0,1,RSTART);
def = substr($0,RSTART+1);
printf "%s%s\n",
numcolor, html_protect(cts),
defcolor, html_protect(def);
next;
}
END {
printf "\n";
printf "\n";
if (title != "") { output_html_tail(); }
}
function output_html_head(title)
{
printf "\n";
printf "\n";
printf "