/AsmL/Tools/Compiler/ASParser/html.awk
AWK | 270 lines | 213 code | 46 blank | 11 comment | 0 complexity | c6fddf20070fcf1906bf5d01ec6c86cd MD5 | raw file
- BEGIN{section_ct = 0;
- i=0;
- j =0;
- beg[beg_i++] = "<?xml version=\"1.0\"?>" "\n"
- beg[beg_i++] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"" "\n"
- beg[beg_i++] = " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" "\n"
-
- beg[beg_i++] = "<html xmlns=\"http://www.w3.org/1999/xhtml\">" "\n"
- beg[beg_i++] = "<head>""\n"
- beg[beg_i++] = "<title>Hyperlinked A# Grammar</title>" "\n"
- beg[beg_i++] = "</head>" "\n"
-
- beg[beg_i++] = "<body>" "\n"
-
- beg[beg_i++] = "<div align=\"right\"><i>For comments/corrections/suggestions</i></div>" "\n"
- beg[beg_i++] = "<div align=\"right\"><a href=\"mailto:xsdesign@microsoft.com\">asmldev@microsoft.com</a></div>" "\n"
-
- beg[beg_i++] = "<pre>" "\n"
- beg[beg_i++] = "<h1 class="grammar">A# Grammar</h1>" "\n"
-
- beg[beg_i++] = "This file was generated directly from an LALR grammar. It was " "\n"
- beg[beg_i++] = "derived from the existing specifications for C#, Version 1.0" "\n"
- beg[beg_i++] = "and Generics, Version 0.21. Asml Extensions are in red." "\n"
- beg[beg_i++] = "\n\n"
-
- }
-
- END {
- end[end_i++]="</pre>"
- end[end_i++]="</body>"
- end[end_i++]= "</html>"
- for(m=0; m< beg_i; m++)
- printf(beg[m])
- for(m=0; m< end_i; m++)
- printf(end[m])
- }
-
-
- /\/\/\. / {sub(/\/\/\. /,"");
- section_ct++;
- end[end_i++]= sprintf("\n\n\n<hr size="3"><a name=\"#%s %s\">%s %s</a>\n\n", section_ct, $0, section_ct, $0);
- beg[beg_i++] = sprintf("\n<a href=\"#%s %s\">%s %s</a>\n", section_ct, $0, section_ct, $0);
-
- subsection_ct = 0;
- next;
- }
- /\/\/\.\. / {
- sub(/\/\/\.\. /,"");
- subsection_ct++;
- end[end_i++]= sprintf("\n\n<hr size="3"><a name=\"#%s.%s %s\">%s.%s %s</a>\n\n", section_ct, subsection_ct, $0, section_ct, subsection_ct, $0);
- beg[beg_i++]= sprintf(" <a href=\"#%s.%s %s\">%s.%s %s</a>\n", section_ct, subsection_ct, $0, section_ct, subsection_ct, $0);
- paragraph_ct = 0;
- next;
- }
- /\/\/\.\.\. / {
- sub(/\/\/\.\.\. /,"");
- paragraph_ct++;
- end[end_i++]= sprintf("\n<hr size="3"><a name=\"#%s.%s.%s %s\">%s.%s.%s %s</a>\n\n", section_ct, subsection_ct, paragraph_ct, $0, section_ct, subsection_ct, paragraph_ct, $0);
- beg[beg_i++]= sprintf(" <a href=\"#%s.%s.%s %s\">%s.%s.%s %s</a>\n", section_ct, subsection_ct, paragraph_ct, $0, section_ct, subsection_ct, paragraph_ct, $0);
- note_ct = 0;
- next;
- }
-
- #/\/\/\.\.\.\. / {
- # sub(/\/\/\.\.\.\. /,"");
- # end[end_i++]= sprintf("\n<hr size="3"><a name=\"#%s.%s.%s.%s %s\">%s.%s.%s.%s %s</a>\n", section_ct, subsection_ct, paragraph_ct, note_ct, $0, section_ct, subsection_ct, paragraph_ct, note_ct, $0);
- # note_ct++;
- # next;
- # }
-
-
- $1 == "\/\/NEW[" {
- end[end_i++]="<font color=\"#FF0000\">"
- }
- $1 == "\/\/NEW]" {
- end[end_i++]="</font>"
- }
- $1 == "\/\/NEW_SQL[" {
- end[end_i++]="<font color=\"#FF00FF\">"
- }
- $1 == "\/\/NEW_SQL]" {
- end[end_i++]="</font>"
- }
- $1 == "\/\/INTERNAL[" {
- end[end_i++]="<!--"
- }
- $1 == "\/\/INTERNAL]" {
- end[end_i++]="-->"
- }
- $1 == "%macro" {
- macro = 1;
- }
-
- $1 == "%expression" {
- macro = 0;
- expression = 1;
- }
-
-
- $1 == "%production" {
- expression = 0;
- }
-
- index($1,"{") == 1 &¯o == 1{
- gsub(/'''/,"XXX", $0);
- gsub(/'/,"", $0);
- gsub(/XXX/,"\'", $0);
- gsub(/{/,"", $0);
- gsub(/}/,"", $0);
-
-
- end[end_i++] = sprintf("\t%s : \n", $(1), $(1))
- end[end_i++] = sprintf("\t\t%s\n", $(2))
- next;
- }
-
- $1 == "%expression" {
- end[end_i++] = sprintf("\t<a name=\"#%s\">%s</a>:\n",$2, $2);
- next;
- }
- /\/\/# / {
- gsub(/_/,"-", $0);
- sub(/\/\/#/,"",$0);
- end[end_i++] = sprintf("\t<a name=\"#%s\">%s</a>\n", $0,$0);
- }
-
-
-
- index($1,"'") == 1 && expression == 1{
- #gsub(/</,"\\<", $1);
- #gsub(/>/,"\\>", $1);
- #gsub(/&/,"\\&", $1);
-
- #end[end_i++] = "\t\t" $1 "\n"
-
-
- printed = 0
- if(substr($1,length($1)) !="'"){
- $1 = $1" " $2
- for(i = 2; i< NF; i++)
- $(i) = $(i+1)
- }
- for(i = 2; i < NF; i++) {
- if (index($i,"'") != 0) {
- copy = $1
- gsub(/\\/,"",copy)
- gsub(/{qname}/,"qname",copy)
- gsub(/</,"\\<", copy);
- gsub(/</,"\\<", $i);
-
- if( $i == "'@<'" || $i == "'@<'")
- $i = copy = "'<'"
- else if ($i == "'type0'")
- $i = "'type'"
- else if ($i == "'&'")
- $i = copy = "'&amp;'"
- else if ($i == "'<'")
- $i = copy = "'&lt;'"
- else if ($i == "'>'")
- $i = copy = "'&gt;'"
- else if ($i == "'"'")
- $i = copy = "'&quot;'"
- else if ($i == "'<![CDATA['")
- $i = "'<![CDATA['"
-
- if (copy != $i ) {
- end[end_i++] = "\t\t" $i "\n\t\t\t"$1
- } else
- end[end_i++] = "\t\t" $i
- printed = 1;
- } else if (index($i,"%ignore") != 0) {
- if (printed ==0) {
- end[end_i] = "\t\t" $1
- printed = 1
- }
- # end[end_i] = end[end_i] sprintf("\t-> ignore");
- } else if (index($i,"%pop") != 0) {
- if (printed ==0)
- end[end_i] = "\t\t" $1
- end[end_i] = end[end_i] sprintf("\t-> pop");
- } else if (index($i,"%push") != 0) {
- if (printed == 0)
- end[end_i] = "\t\t" $1
- end[end_i] = end[end_i] sprintf("\t-> push <a href=\"#%s\">%s</a>", $(i+1), $(i+1))
- } else if (index($i,"%goto") != 0) {
- if (printed ==0)
- end[end_i] = "\t\t" $1
- end[end_i] = end[end_i] sprintf("\t-> goto <a href=\"#%s\">%s</a>", $(i+1), $(i+1))
- }
- }
- end[end_i++] = end[end_i] "\n"
- next;
- }
-
- (/[^']->/ && !(/\/\//)) || (/->/ && (/\/\/!/)) {
- if (index($2,"_opt") != 0)
- next;
- if (index($0,"%error") != 0)
- next;
-
- if (index($0,"//!") !=0) {
- sub(/\/\/!/,"",$0);
- skipNext = 1;
-
- } else {
- skipNext =0;
- }
-
- gsub(/ % /," ", $0);
- gsub(/_/,"-", $0);
- if($2 != NT) {
- NT = $2;
-
- end[end_i++] = sprintf("\t<a name=\"#%s\">%s</a>:\n", NT,NT);
-
-
- skipReally = 0;
- } else {
- if (skipReally==1 && skipNext!=1) next;
- }
-
- gsub(/;/,"", $NF)
-
-
- nf = split($0,tmp,"[^']->")
- if (nf == 3)
- comment = 1
- else
- comment = 0
-
-
- nf = split(tmp[2],rhs)
-
- for(i = 1; i <= nf; i++) {
- if (index(rhs[i],"'") == 0) {
- if(index(rhs[i],"-opt") == 0) {
- rhs[i] = sprintf("<a href=\"#%s\">%s</a>", rhs[i], rhs[i]);
- } else {
- sub(/-opt/,"", rhs[i]);
- rhs[i] = sprintf("<a href=\"#%s\">%s</a><sub>opt</sub>", rhs[i], rhs[i]);
- }
- } else {
- gsub(/'/,"", rhs[i]);
- if (rhs[i] == "sq") rhs[i] = "'"
- else if (rhs[i] == "&")rhs[i] = "&amp;"
- else if (rhs[i] == "<")rhs[i] = "&lt;"
- else if (rhs[i] == ">")rhs[i] = "&gt;"
- else if (rhs[i] == """)rhs[i] = "&quot;"
- else if (rhs[i] == "'")rhs[i] = "&apos;"
- else if (rhs[i] == "-" && comment == 1) rhs[i] = "-->"
- gsub(/@</,"\\<", rhs[i]);
- gsub(/</,"\\<", rhs[i]);
- gsub(/>/,"\\>", rhs[i]);
- rhs[i] = sprintf("<b>%s</b>", rhs[i]);
- }
- }
-
- end[end_i]= sprintf("\t\t")
- for(i = 1; i <= nf; i++){
- end[end_i] = end[end_i] sprintf("%s ", rhs[i]);
-
- }
- end[end_i] = end[end_i] "\n"
- end_i++
-
- if (skipNext == 1)
- skipReally = 1;
-
-
- }