PageRenderTime 38ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/AsmL/Tools/Compiler/ASParser/html.awk

http://AsmL.codeplex.com
AWK | 270 lines | 213 code | 46 blank | 11 comment | 0 complexity | c6fddf20070fcf1906bf5d01ec6c86cd MD5 | raw file
  1. BEGIN{section_ct = 0;
  2. i=0;
  3. j =0;
  4. beg[beg_i++] = "<?xml version=\"1.0\"?>" "\n"
  5. beg[beg_i++] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"" "\n"
  6. beg[beg_i++] = " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" "\n"
  7. beg[beg_i++] = "<html xmlns=\"http://www.w3.org/1999/xhtml\">" "\n"
  8. beg[beg_i++] = "<head>""\n"
  9. beg[beg_i++] = "<title>Hyperlinked A# Grammar</title>" "\n"
  10. beg[beg_i++] = "</head>" "\n"
  11. beg[beg_i++] = "<body>" "\n"
  12. beg[beg_i++] = "<div align=\"right\"><i>For comments/corrections/suggestions</i></div>" "\n"
  13. beg[beg_i++] = "<div align=\"right\"><a href=\"mailto:xsdesign@microsoft.com\">asmldev@microsoft.com</a></div>" "\n"
  14. beg[beg_i++] = "<pre>" "\n"
  15. beg[beg_i++] = "<h1 class="grammar">A# Grammar</h1>" "\n"
  16. beg[beg_i++] = "This file was generated directly from an LALR grammar. It was " "\n"
  17. beg[beg_i++] = "derived from the existing specifications for C#, Version 1.0" "\n"
  18. beg[beg_i++] = "and Generics, Version 0.21. Asml Extensions are in red." "\n"
  19. beg[beg_i++] = "\n\n"
  20. }
  21. END {
  22. end[end_i++]="</pre>"
  23. end[end_i++]="</body>"
  24. end[end_i++]= "</html>"
  25. for(m=0; m< beg_i; m++)
  26. printf(beg[m])
  27. for(m=0; m< end_i; m++)
  28. printf(end[m])
  29. }
  30. /\/\/\. / {sub(/\/\/\. /,"");
  31. section_ct++;
  32. 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);
  33. beg[beg_i++] = sprintf("\n<a href=\"#%s %s\">%s %s</a>\n", section_ct, $0, section_ct, $0);
  34. subsection_ct = 0;
  35. next;
  36. }
  37. /\/\/\.\. / {
  38. sub(/\/\/\.\. /,"");
  39. subsection_ct++;
  40. 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);
  41. beg[beg_i++]= sprintf(" <a href=\"#%s.%s %s\">%s.%s %s</a>\n", section_ct, subsection_ct, $0, section_ct, subsection_ct, $0);
  42. paragraph_ct = 0;
  43. next;
  44. }
  45. /\/\/\.\.\. / {
  46. sub(/\/\/\.\.\. /,"");
  47. paragraph_ct++;
  48. 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);
  49. 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);
  50. note_ct = 0;
  51. next;
  52. }
  53. #/\/\/\.\.\.\. / {
  54. # sub(/\/\/\.\.\.\. /,"");
  55. # 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);
  56. # note_ct++;
  57. # next;
  58. # }
  59. $1 == "\/\/NEW[" {
  60. end[end_i++]="<font color=\"#FF0000\">"
  61. }
  62. $1 == "\/\/NEW]" {
  63. end[end_i++]="</font>"
  64. }
  65. $1 == "\/\/NEW_SQL[" {
  66. end[end_i++]="<font color=\"#FF00FF\">"
  67. }
  68. $1 == "\/\/NEW_SQL]" {
  69. end[end_i++]="</font>"
  70. }
  71. $1 == "\/\/INTERNAL[" {
  72. end[end_i++]="<!--"
  73. }
  74. $1 == "\/\/INTERNAL]" {
  75. end[end_i++]="-->"
  76. }
  77. $1 == "%macro" {
  78. macro = 1;
  79. }
  80. $1 == "%expression" {
  81. macro = 0;
  82. expression = 1;
  83. }
  84. $1 == "%production" {
  85. expression = 0;
  86. }
  87. index($1,"{") == 1 &&macro == 1{
  88. gsub(/'''/,"XXX", $0);
  89. gsub(/'/,"", $0);
  90. gsub(/XXX/,"\'", $0);
  91. gsub(/{/,"", $0);
  92. gsub(/}/,"", $0);
  93. end[end_i++] = sprintf("\t%s : \n", $(1), $(1))
  94. end[end_i++] = sprintf("\t\t%s\n", $(2))
  95. next;
  96. }
  97. $1 == "%expression" {
  98. end[end_i++] = sprintf("\t<a name=\"#%s\">%s</a>:\n",$2, $2);
  99. next;
  100. }
  101. /\/\/# / {
  102. gsub(/_/,"-", $0);
  103. sub(/\/\/#/,"",$0);
  104. end[end_i++] = sprintf("\t<a name=\"#%s\">%s</a>\n", $0,$0);
  105. }
  106. index($1,"'") == 1 && expression == 1{
  107. #gsub(/</,"\\&lt;", $1);
  108. #gsub(/>/,"\\&gt;", $1);
  109. #gsub(/&/,"\\&amp;", $1);
  110. #end[end_i++] = "\t\t" $1 "\n"
  111. printed = 0
  112. if(substr($1,length($1)) !="'"){
  113. $1 = $1" " $2
  114. for(i = 2; i< NF; i++)
  115. $(i) = $(i+1)
  116. }
  117. for(i = 2; i < NF; i++) {
  118. if (index($i,"'") != 0) {
  119. copy = $1
  120. gsub(/\\/,"",copy)
  121. gsub(/{qname}/,"qname",copy)
  122. gsub(/</,"\\&lt;", copy);
  123. gsub(/</,"\\&lt;", $i);
  124. if( $i == "'@<'" || $i == "'@&lt;'")
  125. $i = copy = "'&lt;'"
  126. else if ($i == "'type0'")
  127. $i = "'type'"
  128. else if ($i == "'&amp;'")
  129. $i = copy = "'&amp;amp;'"
  130. else if ($i == "'&lt;'")
  131. $i = copy = "'&amp;lt;'"
  132. else if ($i == "'&gt;'")
  133. $i = copy = "'&amp;gt;'"
  134. else if ($i == "'&quot;'")
  135. $i = copy = "'&amp;quot;'"
  136. else if ($i == "'<![CDATA['")
  137. $i = "'&lt;![CDATA['"
  138. if (copy != $i ) {
  139. end[end_i++] = "\t\t" $i "\n\t\t\t"$1
  140. } else
  141. end[end_i++] = "\t\t" $i
  142. printed = 1;
  143. } else if (index($i,"%ignore") != 0) {
  144. if (printed ==0) {
  145. end[end_i] = "\t\t" $1
  146. printed = 1
  147. }
  148. # end[end_i] = end[end_i] sprintf("\t-> ignore");
  149. } else if (index($i,"%pop") != 0) {
  150. if (printed ==0)
  151. end[end_i] = "\t\t" $1
  152. end[end_i] = end[end_i] sprintf("\t-> pop");
  153. } else if (index($i,"%push") != 0) {
  154. if (printed == 0)
  155. end[end_i] = "\t\t" $1
  156. end[end_i] = end[end_i] sprintf("\t-> push <a href=\"#%s\">%s</a>", $(i+1), $(i+1))
  157. } else if (index($i,"%goto") != 0) {
  158. if (printed ==0)
  159. end[end_i] = "\t\t" $1
  160. end[end_i] = end[end_i] sprintf("\t-> goto <a href=\"#%s\">%s</a>", $(i+1), $(i+1))
  161. }
  162. }
  163. end[end_i++] = end[end_i] "\n"
  164. next;
  165. }
  166. (/[^']->/ && !(/\/\//)) || (/->/ && (/\/\/!/)) {
  167. if (index($2,"_opt") != 0)
  168. next;
  169. if (index($0,"%error") != 0)
  170. next;
  171. if (index($0,"//!") !=0) {
  172. sub(/\/\/!/,"",$0);
  173. skipNext = 1;
  174. } else {
  175. skipNext =0;
  176. }
  177. gsub(/ % /," ", $0);
  178. gsub(/_/,"-", $0);
  179. if($2 != NT) {
  180. NT = $2;
  181. end[end_i++] = sprintf("\t<a name=\"#%s\">%s</a>:\n", NT,NT);
  182. skipReally = 0;
  183. } else {
  184. if (skipReally==1 && skipNext!=1) next;
  185. }
  186. gsub(/;/,"", $NF)
  187. nf = split($0,tmp,"[^']->")
  188. if (nf == 3)
  189. comment = 1
  190. else
  191. comment = 0
  192. nf = split(tmp[2],rhs)
  193. for(i = 1; i <= nf; i++) {
  194. if (index(rhs[i],"'") == 0) {
  195. if(index(rhs[i],"-opt") == 0) {
  196. rhs[i] = sprintf("<a href=\"#%s\">%s</a>", rhs[i], rhs[i]);
  197. } else {
  198. sub(/-opt/,"", rhs[i]);
  199. rhs[i] = sprintf("<a href=\"#%s\">%s</a><sub>opt</sub>", rhs[i], rhs[i]);
  200. }
  201. } else {
  202. gsub(/'/,"", rhs[i]);
  203. if (rhs[i] == "sq") rhs[i] = "'"
  204. else if (rhs[i] == "&amp;")rhs[i] = "&amp;amp;"
  205. else if (rhs[i] == "&lt;")rhs[i] = "&amp;lt;"
  206. else if (rhs[i] == "&gt;")rhs[i] = "&amp;gt;"
  207. else if (rhs[i] == "&quot;")rhs[i] = "&amp;quot;"
  208. else if (rhs[i] == "&apos;")rhs[i] = "&amp;apos;"
  209. else if (rhs[i] == "-" && comment == 1) rhs[i] = "-->"
  210. gsub(/@</,"\\&lt;", rhs[i]);
  211. gsub(/</,"\\&lt;", rhs[i]);
  212. gsub(/>/,"\\&gt;", rhs[i]);
  213. rhs[i] = sprintf("<b>%s</b>", rhs[i]);
  214. }
  215. }
  216. end[end_i]= sprintf("\t\t")
  217. for(i = 1; i <= nf; i++){
  218. end[end_i] = end[end_i] sprintf("%s ", rhs[i]);
  219. }
  220. end[end_i] = end[end_i] "\n"
  221. end_i++
  222. if (skipNext == 1)
  223. skipReally = 1;
  224. }