#include "CWcode.cwp"
#implicitCopy(composeHTMLLikeString)
function removeLayout(sText) {
return translateString({
#implicitCopy
remove ::=
[
->[
#explicitCopy
'[' ->(:sText)']'
=> if sText == "line/" {@; @}
]
]*
->#empty
;
}, project, sText);
}
function incrementSection(sNumber : value) {
local iIndex = $sNumber.findLastString('.') + 1$;
return sNumber.leftString(iIndex) + $sNumber.subString(iIndex) + 1$;
}
function formatCode(sCode : value) {
return translateString({
#implicitCopy
text_code ::=
[
['\r']? '\n' => {@<br/>@}
|
#explicitCopy ' ' => {@ @}
|
#explicitCopy '\t'
=> {
local iPosition = $countInputCols() - 1$;
do {
@ @
increment(iPosition);
} while $(iPosition % 4) != 0$;
}
|
#readChar
]*
;
}, project, sCode);
}
function highlightScript<"">(sScript : value) {
return formatCode(composeHTMLLikeString(sScript));
}
function highlightCWScript(script : node, sScript : value) {
insert script.embeddedScript = true;
return translateString("CWScript2HTML.cwp", script, sScript);
}
function highlightScript<"CodeWorker">(sScript : value) {
local script;
return highlightCWScript(script, sScript);
}
function highlightScript<"CodeWorker.cws">(sScript : value) {
local script = "procedural";
return highlightCWScript(script, sScript);
}
function highlightScript<"CodeWorker.cwt">(sScript : value) {
local script = "template-based";
return highlightCWScript(script, sScript);
}
function highlightScript<"CodeWorker.cwp">(sScript : value) {
local script = "extended-BNF";
return highlightCWScript(script, sScript);
}
function keyword<"C">(sId : value) {
return sId in {"auto", "register", "static", "extern", "typedef", "void", "char", "short", "int", "long", "float",
"double", "signed", "unsigned", "struct", "union", "const", "volatile", "sizeof", "enum", "case",
"default", "switch", "if", "else", "while", "do", "for", "goto", "continue", "break", "return"};
}
function keyword<"C++">(sId : value) {
return keyword<"C">(sId) || sId in {"virtual", "class", "public", "protected", "private", "throw", "template", "try", "catch"};
}
function keyword<"Java">(sId : value) {
return sId in {"package", "import", "class", "interface", "public", "protected", "private", "abstract", "static", "void", "byte",
"extends", "implements", "char", "short", "int", "long", "float", "double", "case", "default", "switch", "if",
"else", "while", "do", "for", "goto", "continue", "break", "return", "throw", "throws", "try", "catch", "finally", "final"};
}
function keyword<"IDL">(sId : value) {
return sId in {"abstract", "any", "attribute", "boolean", "case", "char", "component", "const", "consults",
"context", "custom", "default", "double", "emits", "enum", "eventtype", "exception", "factory",
"FALSE", "finder", "fixed", "float", "getraises", "home", "import", "in", "inout", "interface",
"local", "long", "manages", "module", "multiple", "native", "Object", "octet", "oneway", "out",
"primarykey", "private", "provides", "public", "publishes", "raises", "readonly", "sequence",
"setraises", "short", "string", "struct", "supports", "switch", "TRUE", "truncatable", "typedef",
"typeid", "typeprefix", "union", "unsigned", "uses", "ValueBase", "valuetype", "wchar", "wstring"};
}
function highlightScript<"XML">(sScript : value) {
return translateString({
#implicitCopy(composeHTMLLikeString)
xml2HTML ::=
[
->[
=> local iPosition = getOutputLocation();
[
'<'
#ignore(blanks)
tag
[attribute]*
['/']?
'>'
=> {
insertText(iPosition, "<span class=\"xml_balise\">");
@</span>@
}
|
'<' '/'
#ignore(blanks)
tag
'>'
=> {
insertText(iPosition, "<span class=\"xml_balise\">");
@</span>@
}
|
"<!--" [whitespace | ~"-->"]* "-->"
=> {
insertText(iPosition, "<span class=\"xml_comment\">");
@</span>@
}
|
whitespace
]
]
]*
;
tag ::=
=> local iPosition = getOutputLocation();
#readIdentifier #!ignore ['.' | ':' | #readIdentifier]*
=> {
insertText(iPosition, "<span class=\"php_type\">");
@</span>@
}
;
attribute ::= tag ['=' #continue #skipIgnore(blanks) value]?;
value ::=
=> local iPosition = getOutputLocation();
[
'"' ->'"'
|
"'" ->"'"
|
[~['>' | whitespace]]*
]
=> {
insertText(iPosition, "<span class=\"php_ch\">");
@</span>@
}
;
whitespace ::=
['\r']? '\n' => {@<br/>@}
|
#explicitCopy ' ' => {@ @}
|
#explicitCopy '\t'
=> {
local iPosition = $countInputCols() - 1$;
do {
@ @
increment(iPosition);
} while $(iPosition % 4) != 0$;
}
;
}, project, sScript);
}
function highlightScript<"HTML">(sScript : value) {
return highlightScript<"XML">(sScript);
}
function highlightScript<T>(sScript : value) {
return translateString({
#implicitCopy(composeHTMLLikeString)
cpp2HTML ::=
[
=> local iPosition = getOutputLocation();
[
'#'
#readIdentifier
=> {
insertText(iPosition, "<span class=\"cpp_define\">");
@</span>@
}
|
#readIdentifier:sId
[
#check(keyword<this>(sId))
=> {
insertText(iPosition, "<span class=\"csharp_type\">");
@</span>@
}
]?
|
#readCString
=> {
insertText(iPosition, "<span class=\"csharp_ch\">");
@</span>@
}
|
#readCChar
|
"//" [~[['\r']? '\n']]*
=> {
insertText(iPosition, "<span class=\"cpp_comment\">");
@</span>@
}
|
"/*" [whitespace | ~"*/"]* "*/"
=> {
insertText(iPosition, "<span class=\"cpp_comment\">");
@</span>@
}
|
whitespace
|
#readChar
]
]*
;
whitespace ::=
['\r']? '\n' => {@<br/>@}
|
#explicitCopy ' ' => {@ @}
|
#explicitCopy '\t'
=> {
local iPosition = $countInputCols() - 1$;
do {
@ @
increment(iPosition);
} while $(iPosition % 4) != 0$;
}
;
}, T, sScript);
}
function normalizeFilename(sFilename : value) {
return translateString({
#implicitCopy
normalize ::=
[
->[
#explicitCopy
'$'
#readIdentifier:sVar
=> {@@getEnv(sVar)@@}
]
]*
->#empty
;
}, project, sFilename);
}
function preexecuteOptions(options : node) {
foreach i in options {
if i.key() == "reference" {
@<a name="@i@"></a>@
}
}
}
function postexecuteOption(name : value, option : node) {
if name == "reference" return true;
return false;
}
#overload mainCWcode ::=
=> {
@<html>
<head>
<title>@newFloatingLocation("title");@</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="generator" content="developpez-com" />
<meta name="description" content=@newFloatingLocation("description");@ />
<meta name="keywords" content=@newFloatingLocation("keywords");@ />
<link rel="stylesheet" type="text/css" href="http://www.developpez.com/mainstyle2.css" />
<link rel="stylesheet" type="text/css" media="print" href="http://www.developpez.com/template/printer.css" />
<link rel="stylesheet" type="text/css" media="screen" href="./article.css">
<link rel="stylesheet" type="text/css" href="./CodeWorker.css">
</head>
<body>
<table cellspacing="1" width="100%" class="tbnoir"><tr><td class="fondart"><table class="cadrearticle" width="90%" cellpadding="10" cellspacing="0">
<tr>
<td>
@
}
#super::mainCWcode
=> {
if existFloatingLocation("TOC", false) insertText(getFloatingLocation("TOC"), "<p/><br/>");
@ </td>
</tr>
</table></td></tr></table>
@
if this.docinfo.author {
local iYear = formatDate(getNow(), "%Y");
if this.docinfo.creation && this.docinfo.creation.formatDate("%Y") != iYear {
iYear = this.docinfo.creation.formatDate("%Y") + '-' + iYear;
}
@<br><table class="noteBasPage"></table><hr><div class="licence">
© @iYear@ @composeHTMLLikeString(this.docinfo.author)@ - Tous droits réservés : @composeHTMLLikeString(this.docinfo.author)@. Toute reproduction,
utilisation ou diffusion de ce document par quelque moyen que ce soit autre que pour
un usage personnel doit faire l'objet d'une autorisation écrite préalable de la part
de : @composeHTMLLikeString(this.docinfo.author)@ , le propriétaire des droits intellectuels.
</div>
@
}
@ </body>
</html>
@
}
;
#overload EOL ::=
['.' | ':' | '!' | '?']
['\r']? '\n'
[
#explicitCopy [['\r']? '\n']+
=> {@<p/>@}
|
=> {@<br/>@}
]
|
['\r']? '\n'
[
#explicitCopy [['\r']? '\n']+
=> {@<p/>@}
]?
;
#overload readCode<T> ::=
'[' #readIdentifier:sCode
#check(!T || (sCode == T))
=> local options = $getOutputLocation() - sCode.length() - 1$;
[
=> local sValue;
[
'='
readValue:sValue
=> insert options[sCode] = sValue;
]?
[
','
#readIdentifier:sKey
'='
readValue:sValue
=> insert options[sKey] = sValue;
]*
]?
[
"/]"
CWcode<sCode + '/'>(options)
|
']'
CWcode<sCode>(options)
]
;
#overload endCode<T> ::= #explicitCopy "[/" #readText(T) ']';
#overload CWcode<"title">(options : node) ::=
#continue
removeCodeBegin(options)
=>{@<h1>@}
text:sText
=>{@</h1>@}
=> insertText(getFloatingLocation("title"), removeLayout(sText));
endCode<"title">
;
#overload CWcode<"docinfo/">(options : node) ::=
removeCodeBegin(options)
=> {
foreach i in options {
switch(i.key()) {
case "author":
insert this.docinfo.author = i;
break;
case "creation":
insert this.docinfo.creation = i;
break;
case "profileId":
insert this.docinfo.author.profileId = i;
break;
case "profileName":
insert this.docinfo.author.profileName = i;
break;
case "keywords":
insert this.docinfo.keywords = i;
break;
}
}
if this.docinfo.creation {
@<p class="dateArticle">Date de publication : @this.docinfo.creation.formatDate("%d/%m/%Y")@</p>
@
}
@<p class="dateArticle">Date de mise a jour : @formatDate(getNow(), "%d/%m/%Y")@</p>
@
if this.docinfo.author {
@<p align="center">Par @
if this.docinfo.author.profileId {
@<a class="auteur" href="http://www.developpez.net/forums/profile.php?mode=viewprofile&u=@this.docinfo.author.profileId@">@
if this.docinfo.author.profileName {
@@this.docinfo.author.profileName@@
} else {
@@this.docinfo.author@@
}
@</a>@
} else {
@@this.docinfo.author@@
}
@<br> </p>
@
}
if this.docinfo.keywords {
insertTextToFloatingLocation("keywords", "\"" + this.docinfo.keywords + "\"");
}
}
;
#overload CWcode<"synopsis">(options : node) ::=
removeCodeBegin(options)
=> {@<p class="synopsis">@}
#super::CWcode<"synopsis">(options):sText
=> sText = removeLayout(sText);
=> sText = sText.replaceString('\r', "");
=> sText = sText.replaceString('\n', " ");
=> insertTextToFloatingLocation("description", "\"" + sText + "\"");
=> {@</p>@}
;