1/*description: 2{ 3 It takes in charge of translating any \CodeWorker\ script to HTML. 4 5 The source file is highlighted and keywords plus particular symbols of the 6 language are linked to the online-documentation. 7 8 Note that \samp{this.docURL} designates the URL or the directory where both the CSS 9 and the HTML documentation of \CodeWorker\ are stored. If not populated, it will resolve 10 links from the directory where is the target HTML file. Don't forget to end the URL or 11 directory with a trailing slash. 12 13 If \samp{this.includeCSS} is set to a path, the styles are included into the HTML file from the path, 14 rather that being linked to a file while browsing. 15 16 To highlight any script, type:\\ 17 \texttt{CodeWorker \textbf{-translate} CWscript2HTML.cwp \textit{<CW-script.cw>} \textit{<CW-script.html>}}\\ 18 to consider that the documentation and the CSS are in the same directory, and:\\ 19 \texttt{CodeWorker \textbf{-translate} CWscript2HTML.cwp \textit{<CW-script.cw>} \textit{<CW-script.html>} \textbf{-insert} docURL \textit{HTML-doc-URL}}\\ 20 otherwise. 21} 22*/ 23 24#include "CodeWorker_grammar.cwp" 25 26#overload #ignore ::= 27 [ 28 ' ' | '\t' | '\r' | '\n' 29 | 30 "/*" 31 => insertText($getOutputLocation() - 2$, "<span class=\"comment\">"); 32 ignoreEmbeddedComment 33 => {@</span>@} 34 | 35 "//" 36 => insertText($getOutputLocation() - 2$, "<span class=\"comment\">"); 37 [~[['\r']? '\n' | #empty]]* 38 #explicitCopy 39 [ 40 ['\r']? '\n' 41 => { 42 @</span>@ 43 if !this.multilineScript {@<br/>@} 44 @@endl()@@ 45 } 46 | 47 => {@</span>@} 48 ] 49 50 ]* 51 ; 52 53function transformChar(cChar : value) { 54 if cChar == ' ' return (this.multilineScript) ? " " : " "; 55 if cChar == '\t' return (this.multilineScript) ? " " : " "; 56 if cChar == '\n' return (this.multilineScript) ? endl() : "<br/>" + endl(); 57 if cChar != '\r' return composeHTMLLikeString(cChar); 58} 59 60#implicitCopy(transformChar) 61 62#overload translation_unit ::= 63 => if !this.embeddedScript {@<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 64<html> 65 <head> 66@ 67 if this.includeCSS { 68 @ <style type='text/css'> 69 <!-- 70@loadFile(this.includeCSS)@ 71 --> 72 </style> 73@ 74 } else { 75 @ <link rel="stylesheet" type="text/css" href="@this.docURL@CodeWorker.css" /> 76@ 77 } 78@ </head> 79 <body class="script"> 80 @} 81 [!![->'\n'] => insert this.multilineScript = true;]? 82 => if this.multilineScript {@<pre>@} 83 script<this> 84 => if this.multilineScript {@</pre>@} 85 => if !this.embeddedScript { 86 @<hr /> 87 <div style="background-color: #eeeedd">Generated by <a href="http://www.codeworker.org/index.html">@ 88 local sPath = getOutputFilename(); 89 sPath = sPath.rsubString(lengthString(sPath.getShortFilename())); 90 if existFile(sPath + "CodeWorker99x38.png") { 91 @<img border=0 src="CodeWorker99x38.png"/>@ 92 } else if this.docURL.startString("http://") || existFile(this.docURL + "CodeWorker99x38.png") { 93 @<img border=0 src="@this.docURL@CodeWorker99x38.png"/>@ 94 } else { 95 @<img border=0 src="http://www.codeworker.org/CodeWorker99x38.png"/>@ 96 } 97 @</a> v@getVersion()@ from @ 98 99 if existFile(sPath + "CWscript2HTML.html") { 100 @<a href="CWscript2HTML.html">CWscript2HTML.cwp</a>@ 101 } else if this.docURL.startString("http://") || existFile(this.docURL + "CWscript2HTML.html") { 102 @<a href="@this.docURL@CWscript2HTML.html">CWscript2HTML.cwp</a>@ 103 } else { 104 @<a href="http://www.codeworker.org/CWscript2HTML.html">CWscript2HTML.cwp</a>@ 105 } 106 @.</div> 107 </body> 108</html> 109@} 110 ; 111 112#overload instruction ::= 113 '{' #continue [instruction]* '}' 114 | 115 #readIdentifier:sKeyword 116 => local iLocation = getOutputLocation(); 117 [ 118 instruction<sKeyword> 119 => insertText(iLocation, "</A>"); 120 => insertText($iLocation - sKeyword.length()$, "<A class=\"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#" + sKeyword + "\">"); 121 | 122 predefined_function_call<sKeyword> ';' 123 => insertText(iLocation, "</A>"); 124 => insertText($iLocation - sKeyword.length()$, "<A class=\"function\" href=\"" + this.docURL + "manual_The_scripting_language.html#" + sKeyword + "\">"); 125 | 126 predefined_procedure_call<sKeyword> ';' 127 => insertText(iLocation, "</A>"); 128 => insertText($iLocation - sKeyword.length()$, "<A class=\"procedure\" href=\"" + this.docURL + "manual_The_scripting_language.html#" + sKeyword + "\">"); 129 | 130 module_function_call ';' 131 | 132 user_function_call ';' 133 ] 134 | 135 preprocessor 136 | 137 variable_expression '.' #continue method_call ';' 138 | 139 //#check(this != "procedural") 140 STARTING_TAG 141 #!ignore 142 #continue STARTING_ENDING_RAW_TEXT 143 #ignore 144 [!preprocessor expression ![!'@' !"%>" !#empty]]? 145 ; 146 147#overload instruction<"try"> ::= 148 #continue instruction 149 "catch" 150 => insertText($getOutputLocation() - 5$, "<A class=\"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#try\">"); 151 => {@</A>@} 152 '(' variable_expression ')' instruction 153 ; 154 155#overload preprocessor ::= 156 => local iLocation = getOutputLocation(); 157 '#' 158 #readIdentifier:sKeyword 159 => insertText(iLocation, "<a class=\"directive\" href=\"" + this.docURL + "manual_The_scripting_language.html#_" + sKeyword + "\">"); 160 => {@</a>@} 161 preprocessor<sKeyword> 162 ; 163 164#overload literal_expression<bNumeric> ::= 165 => local iLocation = getOutputLocation(); 166 [ 167 CONSTANT_STRING 168 | 169 '(' #continue expression<bNumeric> ')' 170 | 171 '$' 172 => insertText(iLocation, "<a class=\"constant\" href=\"" + this.docURL + "manual_The_scripting_language.html#$\">"); 173 => {@</a>@} 174 #continue #check(!bNumeric) expression<true> 175 => {@<a class="constant" href="@this.docURL@manual_The_scripting_language.html#$">@} 176 '$' 177 => {@</a>@} 178 | 179 '~' 180 => insertText(iLocation, "<a class=\"constant\" href=\"" + this.docURL + "manual_The_scripting_language.html#numeric_expression\">"); 181 => {@</a>@} 182 #continue #check(bNumeric) literal_expression<true> 183 | 184 CONSTANT_CHAR 185 | 186 '!' 187 => insertText(iLocation, "<a class=\"constant\" href=\"" + this.docURL + "manual_The_scripting_language.html#boolean_expression\">"); 188 => {@</a>@} 189 #continue literal_expression<bNumeric> 190 | 191 #readNumeric 192 => insertText(iLocation, "<span class=\"numeric\">"); 193 => {@</span>@} 194 | 195 #readIdentifier:{"true", "false"} 196 => insertText(iLocation, "<a class=\"constant\" href=\"" + this.docURL + "manual_The_scripting_language.html#boolean_literals\">"); 197 => {@</a>@} 198 | 199 function_call 200 | 201 variable_expression ['.' #continue method_call]? 202 ] 203 ; 204 205#overload function_call ::= 206 #readIdentifier:sFunctionName 207 => local iLocation = getOutputLocation(); 208 [ 209 predefined_function_call<sFunctionName> 210 => insertText(iLocation, "</A>"); 211 => insertText($iLocation - sFunctionName.length()$, "<A class=\"function\" href=\"" + this.docURL + "manual_The_scripting_language.html#" + sFunctionName + "\">"); 212 | 213 module_function_call 214 | 215 user_function_call 216 ]; 217 218#overload method_call ::= 219 #readIdentifier:sMethodName 220 => local iLocation = getOutputLocation(); 221 [ 222 predefined_method_call<sMethodName>:sFunctionName 223 => insertText(iLocation, "</A>"); 224 => insertText($iLocation - sMethodName.length()$, "<A class=\"function\" href=\"" + this.docURL + "manual_The_scripting_language.html#" + sFunctionName + "\">"); 225 | 226 user_method_call 227 ]; 228 229#overload variable_expression<sIdentifier> : #!ignore ::= 230 => if sIdentifier == "project" || sIdentifier == "this" || sIdentifier == "_ARGS" || sIdentifier == "_REQUEST" { 231 insertText($getOutputLocation() - sIdentifier.length()$, "<a class = \"constant\" href=\"" + this.docURL + "manual_The_scripting_language.html#" + sIdentifier + "\">"); 232 @</a>@ 233 } 234 #super::variable_expression<sIdentifier> 235 ; 236 237#overload function_parameter_type ::= 238 => {@<a class="constant" href="@this.docURL@manual_The_scripting_language.html#function_parameters">@} 239 #super::function_parameter_type 240 => {@</a>@}; 241 242 243#overload DEFAULT ::= 244 #readIdentifier:"default" 245 => insertText($getOutputLocation() - 7$, "<a class = \"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#switch\">"); 246 => {@</a>@}; 247 248#overload CASE ::= 249 #readIdentifier:"case" 250 => insertText($getOutputLocation() - 4$, "<a class = \"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#switch\">"); 251 => {@</a>@}; 252 253#overload START ::= 254 #readIdentifier:"start" 255 => insertText($getOutputLocation() - 5$, "<a class = \"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#switch\">"); 256 => {@</a>@}; 257 258#overload CASCADING ::= 259 #readIdentifier:"cascading" 260 => insertText($getOutputLocation() - 9$, "<a class = \"constant\" href=\"" + this.docURL + "manual_The_scripting_language.html#foreach\">"); 261 => {@</a>@}; 262 263#overload ELSE ::= 264 #readIdentifier:"else" 265 => insertText($getOutputLocation() - 4$, "<a class = \"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#if\">"); 266 => {@</a>@}; 267 268#overload IN ::= 269 #readIdentifier:"in" 270 => insertText($getOutputLocation() - 2$, "<a class = \"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#foreach\">"); 271 => {@</a>@}; 272 273#overload INSET ::= 274 #readIdentifier:"in" 275 => insertText($getOutputLocation() - 2$, "<a class = \"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#boolean_expression\">"); 276 => {@</a>@}; 277 278#overload NO_CASE ::= 279 #readIdentifier:"no_case" 280 => insertText($getOutputLocation() - 7$, "<a class = \"constant\" href=\"" + this.docURL + "manual_The_scripting_language.html#foreach\">"); 281 => {@</a>@}; 282 283#overload REVERSE ::= 284 #readIdentifier:"reverse" 285 => insertText($getOutputLocation() - 7$, "<a class = \"constant\" href=\"" + this.docURL + "manual_The_scripting_language.html#foreach\">"); 286 => {@</a>@}; 287 288#overload SORTED ::= 289 #readIdentifier:"sorted" 290 => insertText($getOutputLocation() - 6$, "<a class = \"constant\" href=\"" + this.docURL + "manual_The_scripting_language.html#foreach\">"); 291 => {@</a>@}; 292 293#overload WHILE ::= 294 #readIdentifier:"while" 295 => insertText($getOutputLocation() - 5$, "<a class = \"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#while\">"); 296 => {@</a>@}; 297 298#overload CONSTANT_STRING ::= 299 => local iLocation = getOutputLocation(); 300 [#readCString]+ 301 => insertText(iLocation, "<span class=\"string\">"); 302 => {@</span>@} 303 ; 304 305#overload CONSTANT_CHAR ::= 306 => local iLocation = getOutputLocation(); 307 '\'' #!ignore #continue ['\\']? #readChar '\'' 308 => insertText(iLocation, "<span class=\"string\">"); 309 => {@</span>@} 310 ; 311 312#overload VARIABLE_SPECIAL_ACCESSOR ::= 313 #super::VARIABLE_SPECIAL_ACCESSOR:sKeyword 314 => insertText($getOutputLocation() - sKeyword.length()$, "<a class = \"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#_" + sKeyword + "\">"); 315 => {@</a>@}; 316 317#overload FUNCTION ::= 318 #readIdentifier:"function" 319 => insertText($getOutputLocation() - 8$, "<a class = \"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#function\">"); 320 => {@</a>@}; 321 322#overload DECLARE ::= 323 #readIdentifier:"declare" 324 => insertText($getOutputLocation() - 7$, "<a class = \"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#declare\">"); 325 => {@</a>@}; 326 327#overload EXTERNAL ::= 328 #readIdentifier:"external" 329 => insertText($getOutputLocation() - 8$, "<a class = \"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#external\">"); 330 => {@</a>@}; 331 332 333#overload PRULE_SYMBOL ::= 334 => {@<a class="constant" href="@this.docURL@manual_The_scripting_language.html#parsing_BNF_syntax">@} 335 "::=" 336 => {@</a>@} 337 ; 338 339#overload NON_TERMINAL ::= 340 => {@<i>@} 341 #readIdentifier 342 => {@</i>@} 343 ; 344 345#overload ALTERNATION ::= 346 => local iLocation = getOutputLocation(); 347 '|' 348 => insertText(iLocation, "<a class=\"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#parsing_alternation\">"); 349 => {@</a>@} 350 ; 351 352#overload TR_BEGIN ::= 353 => local iLocation = getOutputLocation(); 354 '<' 355 => insertText(iLocation, "<a class=\"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#BNF_declaring_a_clause\">"); 356 => {@</a>@} 357 ; 358 359#overload TR_END ::= 360 => local iLocation = getOutputLocation(); 361 '>' 362 => insertText(iLocation, "<a class=\"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#BNF_declaring_a_clause\">"); 363 => {@</a>@} 364 ; 365 366#overload PIPESUP ::= 367 => local iLocation = getOutputLocation(); 368 "|>" 369 => insertText(iLocation, "<a class=\"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#BNF_restricting_the_sentence\">"); 370 => {@</a>@} 371 ; 372 373#overload ANDOR ::= 374 => local iLocation = getOutputLocation(); 375 "&|" 376 => insertText(iLocation, "<a class=\"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#BNF_restricting_the_sentence\">"); 377 => {@</a>@} 378 ; 379 380#overload ADVICE_TYPE ::= 381 => {@<a class="constant" href="@this.docURL@manual_The_scripting_language.html#advice">@} 382 #super::ADVICE_TYPE 383 => {@</a>@}; 384 385#overload STARTING_RAW_TEXT ::= => {@<span class="raw_text">@} #super::STARTING_RAW_TEXT => {@</span>@}; 386#overload STARTING_ENDING_RAW_TEXT ::= => {@<span class="raw_text">@} #super::STARTING_ENDING_RAW_TEXT => {@</span>@}; 387#overload STARTING_TAG ::= => {@<span class="raw_text">@} #super::STARTING_TAG => {@</span>@}; 388#overload STARTING_TAG_OR_END ::= => {@<span class="raw_text">@} #super::STARTING_TAG_OR_END => {@</span>@}; 389 390#overload BNF_general_directive ::= 391 => local iLocation = getOutputLocation(); 392 '#' 393 #readIdentifier:sKeyword 394 => insertText(iLocation, "<a class=\"directive\" href=\"" + this.docURL + "manual_The_scripting_language.html#_" + sKeyword + "\">"); 395 => {@</a>@} 396 BNF_general_directive<sKeyword> 397 ; 398 399#overload BNF_general_directive<"overload"> ::= 400 '#' 401 => insertText($getOutputLocation() - 1$, "<a class=\"directive\" href=\"" + this.docURL + "manual_The_scripting_language.html#_ignore\">"); 402 #continue #readIdentifier:"ignore" 403 => {@</a>@} 404 BNF_general_directive<"ignore"> 405 | 406 production_rule; 407 408#overload BNF_catch ::= 409 '#' 410 => insertText($getOutputLocation() - 1$, "<a class=\"directive\" href=\"" + this.docURL + "manual_The_scripting_language.html#_try\">"); 411 #continue 412 "catch" 413 => {@</a>@} 414 '(' variable_expression ')'; 415 416#overload clause_parameter_type ::= 417 => {@<a class="constant" href="@this.docURL@manual_The_scripting_language.html#BNF_declaring_a_clause">@} 418 #super::function_parameter_type 419 => {@</a>@}; 420 421#overload BNF_clause_return_value ::= 422 => {@<a class="constant" href="@this.docURL@manual_The_scripting_language.html#BNF_declaring_a_clause">@} 423 #super::BNF_clause_return_value 424 => {@</a>@} 425 ; 426 427#overload BNF_clause_preprocessing ::= 428 ':' '#' 429 => insertText($getOutputLocation() - 1$, "<a class=\"directive\" href=\"" + this.docURL + "manual_The_scripting_language.html#BNF_preprocessing_of_a_clause\">"); 430 #continue 431 [ 432 '!' 433 #continue 434 #readIdentifier:"ignore" 435 | 436 #readIdentifier:"ignore" 437 ['(' #continue BNF_ignore_type ')']? 438 ] 439 => {@</a>@}; 440 441#overload BNF_ignore_type ::= 442 => { 443 @<a class="constant" href="@this.docURL@manual_The_scripting_language.html#BNF_directives__ignore">@ 444 } 445 #super::BNF_ignore_type 446 => {@</a>@}; 447 448#overload BNF_literal<bTokenCondition> ::= 449 [ 450 CONSTANT_STRING 451 [#check(bTokenCondition) BNF_variable_assignation]? 452 | 453 CONSTANT_CHAR 454 [ 455 ".." #continue CONSTANT_CHAR 456 [#check(bTokenCondition) BNF_token_post_processing]? 457 | 458 [#check(bTokenCondition) BNF_variable_assignation]? 459 ] 460 | 461 [ 462 '~' 463 => insertText($getOutputLocation() - 1$, "<a class=\"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#BNF_token_complementary\">"); 464 => {@</a>@} 465 | 466 '^' 467 => insertText($getOutputLocation() - 1$, "<a class=\"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#BNF_token_complementary\">"); 468 => {@</a>@} 469 | 470 '!' 471 => insertText($getOutputLocation() - 1$, "<a class=\"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#BNF_token_negation\">"); 472 => {@</a>@} 473 | 474 "->" 475 => insertText($getOutputLocation() - 5$, "<a class=\"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#-_amp_gt_\">"); 476 [multiplicity]? 477 => {@</a>@} 478 [ 479 '(' #continue 480 [BNF_variable_assignation]? 481 ['-' BNF_variable_assignation]? 482 [BNF_sequence]? 483 ')' 484 ]? 485 ] 486 #continue BNF_literal<false> 487 [#check(bTokenCondition) BNF_token_post_processing]? 488 | 489 '[' 490 => insertText($getOutputLocation() - 1$, "<a class=\"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#BNF_token_repeating_a_token\">"); 491 => {@</a>@} 492 #continue BNF_sequence [ALTERNATION #continue BNF_sequence]* 493 => {@<a class="instruction" href="@this.docURL@manual_The_scripting_language.html#BNF_token_repeating_a_token">@} 494 ']' 495 [multiplicity]? 496 => {@</a>@} 497 [#check(bTokenCondition) BNF_token_post_processing]? 498 | 499 '#' 500 => local iLocation = $getOutputLocation() - 1$; 501 #continue 502 [ 503 '!' 504 #continue 505 #readIdentifier:"ignore" 506 => insertText(iLocation, "<a class=\"directive\" href=\"" + this.docURL + "manual_The_scripting_language.html#_ignore\">"); 507 => {@</a>@} 508 | 509 #readIdentifier:sDirective 510 => insertText(iLocation, "<a class=\"directive\" href=\"" + this.docURL + "manual_The_scripting_language.html#_" + sDirective + "\">"); 511 => {@</a>@} 512 BNF_directive<sDirective>:bTokenConditionAllowed 513 [ 514 #check(bTokenCondition && bTokenConditionAllowed) 515 BNF_token_post_processing 516 ]? 517 ] 518 | 519 "=>" 520 => insertText($getOutputLocation() - 5$, "<a class=\"instruction\" href=\"" + this.docURL + "manual_The_scripting_language.html#BNF_operator__eq__amp_gt_\">"); 521 => {@</a>@} 522 #continue instruction 523 | 524 BNF_clause_call 525 [#check(bTokenCondition) BNF_token_post_processing]? 526 ] 527 [ 528 [PIPESUP | ANDOR] 529 #continue 530 BNF_literal<bTokenCondition> 531 ]? 532 ; 533 534 535script_file_link(T : value) ::= 536 => local iLocation = getOutputLocation(); 537 #readCString:sCWFilename 538 !![',' | ')' | #check(T == "include")] 539 #check(sCWFilename.rightString(4) in {".cwt", ".cws", ".cwp", ".gen"}) 540 => local sTargetPath = rsubString(getOutputFilename(), lengthString(getShortFilename(getOutputFilename()))); 541 => local sHTMLFilename = sTargetPath + sCWFilename + ".html"; 542 #check(sHTMLFilename.existFile()) 543 => insertText(iLocation, "<a href=\"" + sCWFilename + ".html" + "\" class=\"string\">"); 544 => {@</a>@} 545 | 546 #super::script_file_expression<T> 547 ; 548 549#overload script_file_expression<"free"> ::= script_file_link("free"); 550#overload script_file_expression<"pattern"> ::= script_file_link("pattern"); 551#overload script_file_expression<"BNF"> ::= script_file_link("BNF"); 552#overload script_file_expression<"translate"> ::= script_file_link("translate"); 553