![]() |
Overview |
![]() |
Getting started |
// file "GettingStarted/Tiny.tml":
1 class A {
2 }
3
4 class B : A {
5 }
6
7 class C {
8 B[] b
9 }
10
11 class D {
12 A a
13 C[] c
14 }
CodeWorker -console
insert listOfClasses["A"].name = "A";
traceObject(project);
set listOfClasses["B"].name = "B";
ref listOfClasses["B"].parent = listOfClasses["A"];
traceLine(listOfClasses["B"].parent.name);
insert listOfClasses["C"].name = "C";
pushItem listOfClasses["C"].listOfAttributes;
local myAttribute;
ref myAttribute = listOfClasses["C"].listOfAttributes#back;
insert myAttribute.name = "b";
ref myAttribute.class = listOfClasses["B"];
insert myAttribute.isArray = true;
// file "GettingStarted/Tiny-BNF.cwp":
1 TinyBNF ::=
2 #ignore(JAVA)
3 [classDeclaration]*
4 #empty
5 => { traceLine("this file is valid"); };
6 classDeclaration ::=
7 IDENT:"class"
8 IDENT
9 [':' IDENT ]?
10 classBody;
11 classBody ::= '{' [attributeDeclaration]* '}';
12 attributeDeclaration ::= IDENT ['[' ']']? IDENT;
13 IDENT ::= #!ignore ['a'..'z'|'A'..'Z']+;
parseAsBNF("Scripts/Tutorial/GettingStarted/Tiny-BNF.cwp", project,
"Scripts/Tutorial/GettingStarted/Tiny.tml");
this file is valid
// file "GettingStarted/Tiny-BNFparsing.cwp":
1 TinyBNF ::= #ignore(JAVA) [classDeclaration]* #empty
2 => { traceLine("this file has been parsed successfully"); };
3 classDeclaration ::=
4 IDENT:"class"
5 IDENT:sName
6 => insert project.listOfClasses[sName].name = sName;
7 [
8 ':'
9 IDENT:sParent
10 => {
11 if !findElement(sParent, project.listOfClasses)
12 error("class '" + sParent + "' should have been declared before");
13 ref project.listOfClasses[sName].parent = project.listOfClasses[sParent];
14 }
15 ]?
16 classBody(project.listOfClasses[sName]);
17 classBody(myClass : node) ::=
18 '{' [attributeDeclaration(myClass)]* '}';
19 attributeDeclaration(myClass : node) ::=
20 IDENT
21 ['[' ']']?
22 IDENT;
23 IDENT ::= #!ignore ['a'..'z'|'A'..'Z']+;
// file "GettingStarted/Tiny-BNFparsing1.cwp":
1 classBody(myClass : node) ::=
2 '{' [attributeDeclaration(myClass)]* '}';
3 attributeDeclaration(myClass : node) ::=
4 IDENT:sClass
5 => local myAttribute;
6 => {
7 pushItem myClass.listOfAttributes;
8 ref myAttribute = myClass.listOfAttributes#back;
9 if !findElement(sClass, project.listOfClasses)
10 error("class '" + sClass + "' should have been declared before");
11 ref myAttribute.class = project.listOfClasses[sClass];
12 }
13 ['[' ']' => insert myAttribute.isArray = true;]?
14 IDENT:sName => {insert myAttribute.name = sName;};
15
16 IDENT ::= #!ignore ['a'..'z'|'A'..'Z']+;
parseAsBNF("Scripts/Tutorial/GettingStarted/Tiny-BNFparsing1.cwp", project,
"Scripts/Tutorial/GettingStarted/Tiny.tml");
this file has been parsed successfully
// file "GettingStarted/Tiny-leaderScript0.cws":
1 parseAsBNF("Tiny-BNFparsing1.cwp", project, "Scripts/Tutorial/GettingStarted/Tiny.tml");
2
3
4 function displayParsingTree() {
5 foreach i in project.listOfClasses {
6 traceLine("class '" + i.name + "'");
7 if existVariable(i.parent)
8 traceLine("\tparent = '" + i.parent.name + "'");
9 foreach j in i.listOfAttributes {
10 traceLine("\tattribute '" + j.name + "'");
11 traceLine("\t\tclass = '" + j.class.name + "'");
12 if existVariable(j.isArray)
13 traceLine("\t\tarray = '" + j.isArray + "'");
14 }
15 }
16 }
17
18 displayParsingTree();
this file has been parsed successfully
class 'A'
class 'B'
parent = 'A'
class 'C'
attribute 'b'
class = 'B'
array = 'true'
class 'D'
attribute 'a'
class = 'A'
attribute 'c'
class = 'C'
array = 'true'
// file "Scripts/Tutorial/GettingStarted/Tiny-JAVA.cwt":
1 package tiny;
2
3 public class @this.name@ @
4 if existVariable(this.parent) {
5 @ extends @this.parent.name@ @
6 }
7 @{
8 // attributes:
9 @
10 function getJAVAType(myAttribute : node) {
11 local sType = myAttribute.class.name;
12 if myAttribute.isArray {
13 set sType = "java.util.ArrayList/*<" + sType + ">*/";
14 }
15 return sType;
16 }
17
18 foreach i in this.listOfAttributes {
19 @ private @getJAVAType(i)@ _@i.name@ = null;
20 @
21 }
22 @
23 //constructor:
24 public @this.name@() {
25 }
26
27 // accessors:
28 @
29 foreach i in this.listOfAttributes {
30 @ public @getJAVAType(i)@ get@toUpperString(i.name)@() { return _@i.name@; }
31 public void set@toUpperString(i.name)@(@getJAVAType(i)@ @i.name@) { _@i.name@ = @i.name@; }
32 @
33 }
34 setProtectedArea("Methods");
35 @}
// file "Scripts/Tutorial/GettingStarted/Tiny-leaderScript1.cws":
1 parseAsBNF("Scripts/Tutorial/GettingStarted/Tiny-BNFparsing1.cwp", project, "Scripts/Tutorial/GettingStarted/Tiny.tml");
2
3 foreach i in project.listOfClasses {
4 generate("Scripts/Tutorial/GettingStarted/Tiny-JAVA.cwt", i, "Scripts/Tutorial/GettingStarted/tiny/" + i.name + ".java");
5 }
6
this file has been parsed successfully
// file "Scripts/Tutorial/GettingStarted/tiny/D.java":
package tiny;
public class D {
// attributes:
private A _a = null;
private java.util.ArrayList/*<C>*/ _c = null;
//constructor:
public D() {
}
// accessors:
public A getA() { return _a; }
public void setA(A a) { _a = a; }
public java.util.ArrayList/*<C>*/ getC() { return _c; }
public void setC(java.util.ArrayList/*<C>*/ c) { _c = c; }
//##protect##"Methods"
//##protect##"Methods"
}
// file "Scripts/Tutorial/GettingStarted/Tiny.html":
<HTML>
<HEAD>
</HEAD>
<BODY>
<!--##markup##"classes"-->
</BODY>
</HTML>
// file "Scripts/Tutorial/GettingStarted/Tiny-HTML.cwt":
1 @
2 if getMarkupKey() == "classes" {
3 foreach i in project.listOfClasses {
4 @ <TABLE>
5 <TR>
6 <TD colspan=3><B>@i.name@</B></TD>
7 </TR>
8 <TR>
9 <TD><EM>Attribute</EM></TD><TD><EM>Type</EM></TD> <TD><EM>Description</EM></TD>
10 </TR>
11 @
12 foreach j in i.listOfAttributes {
13 @ <TR>
14 <TD><I>@j.name@</I></TD><TD><CODE>@
15 @@j.class.name@@
16 if j.isArray {
17 @[]@
18 }
19 @</CODE></TD><TD>@
20 setProtectedArea(i.name + "::" + j.name);
21 @</TD>
22 </TR>
23 @
24 }
25 @ </TABLE>
26 @
27 }
28 }
// file "Scripts/Tutorial/GettingStarted/Tiny-leaderScript2.cws":
1 parseAsBNF("Scripts/Tutorial/GettingStarted/Tiny-BNFparsing1.cwp", project, "Scripts/Tutorial/GettingStarted/Tiny.tml");
2
3 foreach i in project.listOfClasses {
4 generate("Scripts/Tutorial/GettingStarted/Tiny-JAVA.cwt", i, "Scripts/Tutorial/GettingStarted/tiny/" + i.name + ".java");
5 }
6
7 traceLine("expanding file 'Tiny0.html'...");
8 setCommentBegin("<!--");
9 setCommentEnd("-->");
10 expand("Scripts/Tutorial/GettingStarted/Tiny-HTML.cwt", project, "Scripts/Tutorial/GettingStarted/Tiny0.html");
11 //normal;
this file has been parsed successfully
expanding file 'Tiny0.html'...
![]() |
Discovering more with an example |
// file "GettingStarted/SolarSystem0.sml":
1 class Planet {
2 double diameter;
3 double getDistanceToSun(int day, int month, int year);
4 }
5
6 class Earth : Planet {
7 string[] countryNames;
8 }
9
10 class SolarSystem {
11 aggregate Planet[] planets;
12 }
Tracing variable 'project':
a = "little"
b = "big"
End of variable's trace 'project'.
Tracing variable 'project':
a = "little"
b = "big"
classes = ""
classes["Planet", "Earth"]
End of variable's trace 'project'.
handling class 'Planet'...
handling class 'Earth'...
// file "GettingStarted/SimpleML-token-reading.cws":
1 declare function readType();
2
3 while skipEmptyCpp() {
4 if !readIfEqualToIdentifier("class") error("'class' expected");
5 skipEmptyCpp();
6 local sClassName = readIdentifier();
7 if !sClassName error("class name expected");
8 skipEmptyCpp();
9 if readIfEqualTo(":") {
10 skipEmptyCpp();
11 local sParentName = readIdentifier();
12 if !sParentName error("parent name expected for class '" + sClassName + "'");
13 skipEmptyCpp();
14 }
15 if !readIfEqualTo("{") error("'{' expected");
16 skipEmptyCpp();
17 while !readIfEqualTo("}") {
18 skipEmptyCpp();
19 readType();
20 skipEmptyCpp();
21 local sMemberName = readIdentifier();
22 if !sMemberName error("attribute or method name expected");
23 skipEmptyCpp();
24 if readIfEqualTo("(") {
25 skipEmptyCpp();
26 if !readIfEqualTo(")") {
27 do {
28 skipEmptyCpp();
29 local iPosition = getInputLocation();
30 local sMode = readIdentifier();
31 if !sMode error("parameter type or mode expected");
32 if (sMode != "in") && (sMode != "out") && (sMode != "inout") {
33 setInputLocation(iPosition);
34 set sMode = "";
35 }
36 skipEmptyCpp();
37 readType();
38 skipEmptyCpp();
39 local sParameterName = readIdentifier();
40 if !sParameterName error("parameter name expected");
41 skipEmptyCpp();
42 } while readIfEqualTo(",");
43 if !readIfEqualTo(")") error("')' expected");
44 }
45 skipEmptyCpp();
46 }
47 if !readIfEqualTo(";") {
48 error("';' expected to close an attribute, instead of '" + readChar() + "'");
49 }
50 skipEmptyCpp();
51 }
52 }
53 traceLine("the file has been read successfully");
54
55 function readType() {
56 local sType = readIdentifier();
57 if !sType error("type modifier or name expected, instead of '" + readChar() + "'");
58 if sType == "aggregate" {
59 skipEmptyCpp();
60 sType = readIdentifier();
61 if !sType error("aggregated class name expected");
62 }
63 skipEmptyCpp();
64 if readIfEqualTo("[") {
65 skipEmptyCpp();
66 if !readIfEqualTo("]") error("']' expected to close an array declaration");
67 }
68 }
parseFree("GettingStarted/SimpleML-token-reading.cws",
project, "GettingStarted/SolarSystem0.sml");
the file has been read successfully
// file "GettingStarted/SimpleML-token-parsing.cws":
1 declare function readType(myType : node);
2
3 while skipEmptyCpp() {
4 if !readIfEqualToIdentifier("class") error("'class' expected");
5 skipEmptyCpp();
6 local sClassName = readIdentifier();
7 if !sClassName error("class name expected");
8 insert project.listOfClasses[sClassName].name = sClassName;
9 skipEmptyCpp();
10 if readIfEqualTo(":") {
11 skipEmptyCpp();
12 local sParentName = readIdentifier();
13 if !sParentName error("parent name expected for class '" + sClassName + "'");
14 insert project.listOfClasses[sClassName].parent = sParentName;
15 skipEmptyCpp();
16 }
17 if !readIfEqualTo("{") error("'{' expected");
18 skipEmptyCpp();
19 local myClass;
20 ref myClass = project.listOfClasses[sClassName];
21 while !readIfEqualTo("}") {
22 skipEmptyCpp();
23 local myType;
24 readType(myType);
25 skipEmptyCpp();
26 local sMemberName = readIdentifier();
27 if !sMemberName error("attribute or method name expected");
28 skipEmptyCpp();
29 if readIfEqualTo("(") {
30 insert myClass.listOfMethods[sMemberName].name = sMemberName;
31 if myType.name != "void" {
32 setall myClass.listOfMethods[sMemberName].type = myType;
33 }
34 skipEmptyCpp();
35 if !readIfEqualTo(")") {
36 local myMethod;
37 ref myMethod = myClass.listOfMethods[sMemberName];
38 do {
39 skipEmptyCpp();
40 local iPosition = getInputLocation();
41 local sMode = readIdentifier();
42 if !sMode error("parameter type or mode expected");
43 if (sMode != "in") && (sMode != "out") && (sMode != "inout") {
44 setInputLocation(iPosition);
45 set sMode = "";
46 }
47 skipEmptyCpp();
48 local myParameterType;
49 readType(myParameterType);
50 skipEmptyCpp();
51 local sParameterName = readIdentifier();
52 if !sParameterName error("parameter name expected");
53 insert myMethod.listOfParameters[sParameterName].name = sParameterName;
54 setall myMethod.listOfParameters[sParameterName].type = myParameterType;
55 if sMode {
56 insert myMethod.listOfParameters[sParameterName].name = sMode;
57 }
58 skipEmptyCpp();
59 } while readIfEqualTo(",");
60 if !readIfEqualTo(")") error("')' expected");
61 }
62 skipEmptyCpp();
63 } else {
64 insert myClass.listOfAttributes[sMemberName].name = sMemberName;
65 setall myClass.listOfAttributes[sMemberName].type = myType;
66 }
67 if !readIfEqualTo(";") error("';' expected to close an attribute, instead of '" + readChar() + "'");
68 skipEmptyCpp();
69 }
70 }
71 traceLine("the file has been parsed successfully");
72
73 function readType(myType : node) {
74 local sType = readIdentifier();
75 if !sType error("type modifier or name expected, instead of '" + readChar() + "'");
76 if sType == "aggregate" {
77 insert myType.isAggregation = true;
78 skipEmptyCpp();
79 sType = readIdentifier();
80 if !sType error("aggregated class name expected");
81 }
82 insert myType.name = sType;
83 if (sType != "int") && (sType != "double") && (sType != "boolean") && (sType != "string") {
84 insert myType.isObject = true;
85 }
86 skipEmptyCpp();
87 if readIfEqualTo("[") {
88 skipEmptyCpp();
89 if !readIfEqualTo("]") error("']' expected to close an array declaration");
90 insert myType.isArray = true;
91 }
92 }
parseFree("GettingStarted/SimpleML-token-parsing.cws",
project, "GettingStarted/SolarSystem0.sml");
the file has been parsed successfully
// file "GettingStarted/SimpleML-reading.cwp":
1 // syntactical clauses:
2 world ::= #ignore(C++) [class_declaration]* #empty
3 => { traceLine("file read successfully"); };
4 class_declaration ::= IDENT:"class" IDENT [':' IDENT]? class_body;
5 class_body ::= '{' [attribute_decl | method_decl]* '}';
6 attribute_decl ::= type_specifier IDENT ';';
7 method_decl ::= [IDENT:"void" | type_specifier] IDENT
8 '(' [parameters_decl]? ')' ';';
9 parameters_decl ::= parameter [',' parameters_decl]*;
10 parameter ::= [parameter_mode]? type_specifier IDENT;
11 parameter_mode ::= IDENT:{"in", "inout", "out"};
12 type_specifier ::= basic_type ['[' ']']?;
13 basic_type ::= "int" | "boolean" | "double" | "string" | class_specifier;
14 class_specifier ::= ["aggregate"]? IDENT;
15
16 // lexical clauses:
17 IDENT ::= #!ignore ['a'..'z'|'A'..'Z'|'_']
18 ['a'..'z'|'A'..'Z'|'_'|'0'..'9']*;
parseAsBNF("GettingStarted/SimpleML-reading.cwp",
project, "GettingStarted/SolarSystem0.sml");
file read successfully
// file "GettingStarted/SimpleML-parsing.cwp":
1 // syntactical clauses:
2 world ::= #ignore(C++) [class_declaration]* #empty
3 => {
4 traceLine("file parsed successfully");
5 saveProject("Scripts/Tutorial/SolarSystem0.xml");
6 };
7 class_declaration ::= IDENT:"class" #continue
8 IDENT:sClassName
9 => insert project.listOfClasses[sClassName].name = sClassName;
10 [':' #continue IDENT:sParentName
11 => insert project.listOfClasses[sClassName].parent = sParentName;
12 ]?
13 class_body(project.listOfClasses[sClassName]);
14 class_body(myClass : node) ::= '{'
15 [attribute_decl(myClass) | method_decl(myClass)]* '}';
16 attribute_decl(myClass : node) ::=
17 => local myType;
18 type_specifier(myType) IDENT:sAttributeName ';'
19 => {
20 insert myClass.listOfAttributes[sAttributeName].name = sAttributeName;
21 setall myClass.listOfAttributes[sAttributeName].type = myType;
22 };
23 method_decl(myClass : node) ::=
24 => local myType;
25 [IDENT:"void" | type_specifier(myType)]
26 IDENT:sMethodName '('
27 #continue
28 => {
29 insert myClass.listOfMethods[sMethodName].name = sMethodName;
30 if myType.name
31 setall myClass.listOfMethods[sMethodName].type = myType;
32 }
33 [parameters_decl(myClass.listOfMethods[sMethodName])]? ')' ';';
34 parameters_decl(myMethod : node) ::=
35 parameter(myMethod)
36 [',' #continue parameters_decl(myMethod)]*;
37 parameter(myMethod : node) ::=
38 [parameter_mode]?:sMode
39 => local myType;
40 type_specifier(myType)
41 IDENT:sParameterName
42 => {
43 insert myMethod.listOfParameters[sParameterName].name = sParameterName;
44 setall myMethod.listOfParameters[sParameterName].type = myType;
45 if sMode {
46 insert myMethod.listOfParameters[sParameterName].name = sMode;
47 }
48 };
49 parameter_mode ::= IDENT:{"in", "inout", "out"};
50 type_specifier(myType : node) ::=
51 basic_type(myType)
52 ['[' #continue ']' => insert myType.isArray = true; ]?;
53 basic_type(myType : node) ::=
54 ["int" | "boolean" | "double" | "string"]:myType.name
55 |
56 class_specifier(myType);
57 class_specifier(myType : node) ::=
58 ["aggregate" => insert myType.isAggregation = true; ]?
59 IDENT:myType.name => {insert myType.isObject = true; };
60
61 IDENT ::= #!ignore ['a'..'z'|'A'..'Z'|'_']
62 ['a'..'z'|'A'..'Z'|'_'|'0'..'9']*;
parseAsBNF("GettingStarted/SimpleML-parsing.cwp",
project, "GettingStarted/SolarSystem0.sml");
file parsed successfully
// file "GettingStarted/TreeDecoration.cws":
1 foreach myClass in project.listOfClasses {
2 if myClass.parent {
3 if !findElement(myClass.parent, project.listOfClasses)
4 error("class '" + myClass.parent + "' doesn't exist while class '"
5 + myClass.name + "intends to inherit from it");
6 ref myClass.parent = project.listOfClasses[myClass.parent];
7 }
8 foreach myAttribute in myClass.listOfAttributes {
9 local myType;
10 ref myType = myAttribute.type;
11 if myType.isObject {
12 if !findElement(myType.name, project.listOfClasses)
13 error("class '" + myType.name + "' doesn't exist while attribute '"
14 + myClass.name + "::" + myAttribute.name + "' refers to it");
15 ref myType.class = project.listOfClasses[myType.name];
16 }
17 }
18 foreach myMethod in myClass.listOfMethods {
19 if existVariable(myMethod.type) && myMethod.type.isObject {
20 localref myType = myMethod.type;
21 if !findElement(myType.name, project.listOfClasses)
22 error("class '" + myType.name + "' doesn't exist while method '"
23 + myClass.name + "::" + myMethod.name + "' refers to it");
24 ref myType.class = project.listOfClasses[myType.name];
25 }
26 foreach myParameter in myMethod.listOfParameters {
27 localref myType = myParameter.type;
28 if myType.isObject {
29 if !findElement(myType.name, project.listOfClasses)
30 error("class '" + myType.name
31 + "' doesn't exist while method '"
32 + myClass.name + "::" + myMethod.name
33 + "' refers to it");
34 ref myType.class = project.listOfClasses[myType.name];
35 }
36 }
37 }
38 }
// file "GettingStarted/LeaderScript0.cws":
1 if !getProperty("DESIGN_FILE")
2 error("'-define DESIGN_FILE=file' expected on the command line");
3 traceLine("'Simple Modeling' design file to parse = \""
4 + getProperty("DESIGN_FILE") + "\"");
5 parseAsBNF("SimpleML-parsing.cwp",
6 project, getProperty("DESIGN_FILE"));
7 #include "TreeDecoration.cws"
if doc_language == "C++" {
sType = getCppType(myParameterType);
} else if doc_language == "JAVA" {
sType = getJAVAType(myParameterType);
} else {
error("unrecognized language '" + doc_language + "'");
}
sType = getType<doc_language>(myParameterType);
...
function getType<"JAVA">(myType : node) {
... // implementation for returning a Java type
}
function getType<"C++">(myType : node) {
... // implementation for returning a C++ type
}
function getType<T>(myType : node) {
... // implementation for any unrecognized language
}
function f<1>() { return 1; }
function f<N>() { return $N*f<$N - 1$>()$; }
local f10 = f<10>();
if $f10 != 3628800$ error("10! should be worth 3628800");
traceLine("10! = " + f10);
10! = 3628800
// file "GettingStarted/SharedFunctions.cws":
1 function normalizeIdentifier(sName) {
2 if sName {
3 if startString(sName, "_")
4 return "_" + normalizeIdentifier(subString(sName, 1));
5 set sName = toUpperString(charAt(sName, 0))
6 + subString(sName, 1);
7 local iIndex = findFirstChar(sName, "_.");
8 if !isNegative(iIndex) {
9 local sNext = subString(sName, add(iIndex, 1));
10 return leftString(sName, iIndex)
11 + normalizeIdentifier(sNext);
12 }
13 }
14 return sName;
15 }
16
17 function getType<"C++">(myType : node) {
18 local sType;
19 if myType.isObject set sType = myType.name + "*";
20 else if myType.name == "boolean" set sType = "bool";
21 else if myType.name == "string" set sType = "std::string";
22 else set sType = myType.name;
23 if myType.isArray set sType = "std::vector<" + sType + ">";
24 return sType;
25 }
26
27 function getParameterType<"C++">(myType : node, sMode) {
28 local sType = getType<"C++">(myType);
29 if endString(sMode, "out") set sType += "&";
30 else if (sMode == "in") set sType = "const " + sType + "&";
31 return sType;
32 }
33
34 function getType<"JAVA">(myType : node) {
35 local sType;
36 if myType.name == "string" set sType = "String";
37 else set sType = myType.name;
38 if myType.isArray set sType = "java.util.ArrayList/*<" + sType + ">*/";
39 return sType;
40 }
41
42 function getParameterType<"JAVA">(myType : node, sMode) {
43 return getType<"JAVA">(myType);
44 }
45
46 function getVariableName(sName, myType : node) {
47 local sPrefix;
48 if myType.isArray set sPrefix = "t";
49 if myType.isObject set sPrefix += "p";
50 else {
51 switch(myType.name) {
52 case "int": set sPrefix += "i";break;
53 case "double": set sPrefix += "d";break;
54 case "boolean": set sPrefix += "b";break;
55 case "string": set sPrefix += "s";break;
56 }
57 }
58 return sPrefix + normalizeIdentifier(sName);
59 }
60
61 function getMethodID(myMethod : node) {
62 local sMethodID = myMethod.name;
63 foreach i in myMethod.listOfParameters {
64 set sMethodID += "." + i.type.name;
65 if i.type.isArray set sMethodID += "[]";
66 }
67 return sMethodID;
68 }
// file "GettingStarted/CppObjectHeader.cwt":
1 #ifndef _@this.name@_h_
2 #define _@this.name@_h_
3
4 @
5 newFloatingLocation("include files");
6 @
7 // this line separates the two insertion points, so as to distinguish them!
8 @
9 newFloatingLocation("class declarations");
10
11 function populateHeaderDeclarations(myType : node) {
12 if myType.isObject insertTextOnce(getFloatingLocation("class declarations"), "class " + myType.name + ";" + endl());
13 if myType.isArray insertTextOnce(getFloatingLocation("include files"), "#include <vector>" + endl());
14 if myType.name insertTextOnce(getFloatingLocation("include files"), "#include <string>" + endl());
15 }
16
17 @
18 class @this.name@ @
19 if existVariable(this.parent) {
20 insertTextOnce(getFloatingLocation("include files"), "#include \"" + this.parent.name +".h\"" + endl());
21 @: public @this.parent.name@ @
22 }
23 @{
24 private:
25 @
26 foreach i in this.listOfAttributes {
27 populateHeaderDeclarations(i.type);
28 @ @getType<"C++">(i.type)@ _@getVariableName(i.name, i.type)@;
29 @
30 }
31 @
32 public:
33 @this.name@();
34 ~@this.name@();
35
36 // accessors:
37 @
38 foreach i in this.listOfAttributes {
39 local sVariableName = getVariableName(i.name, i.type);
40 %> inline <%getType<"C++">(i.type)%> get<%normalizeIdentifier (i.name)%>() const { return _<%sVariableName%>; }
41 inline void set<%normalizeIdentifier(i.name)@(<%getType <"C++">(i.type)%> <%sVariableName@) { _<%sVariableName%> = <%sVariableName%>; }
42 @
43 }
44 @
45 // methods:
46 @
47 foreach i in this.listOfMethods {
48 @ virtual @
49 if existVariable(i.type) {
50 populateHeaderDeclarations(i.type);
51 @@getType<"C++">(i.type)@@
52 } else {
53 @void@
54 }
55 @ @i.name@(@
56 foreach j in i.listOfParameters {
57 if !first(j) {
58 @, @
59 }
60 populateHeaderDeclarations(j.type);
61 @@getParameterType<"C++">(j.type, j.mode)@ @getVariableName(j.name, j.type)@@
62 }
63 @);
64 @
65 }
66 @
67 private:
68 @this.name@(const @this.name@&);
69 @this.name@& operator =(const @this.name@&);
70 };
71
72 #endif
// file "GettingStarted/CppObjectBody.cwt":
1 #ifdef WIN32
2 #pragma warning(disable : 4786)
3 #endif
4
5 @
6 setProtectedArea("include files");
7 @
8 #include "@this.name@.h"
9
10 @this.name@::@this.name@()@
11 local bAtLeastOne = false;
12 foreach i in this.listOfAttributes {
13 if !i.type.isArray && (i.type.name != "string") {
14 if bAtLeastOne {
15 @, @
16 } else {
17 @ : @
18 set bAtLeastOne = true;
19 }
20 @_@getVariableName(i.name, i.type)@(@
21 if i.type.isObject {
22 @0L@
23 } else {
24 switch(i.type.name) {
25 case "int":
26 @0@
27 break;
28 case "double":
29 @0.0@
30 break;
31 case "boolean":
32 @false@
33 break;
34 }
35 }
36 @)@
37 }
38 }
39 @ {
40 }
41
42 @this.name@::~@this.name@() {
43 @
44 foreach i in this.listOfAttributes {
45 if i.type.isAggregation && i.type.isObject {
46 local sAttributeName = "_" + getVariableName(i.name, i.type);
47 local sIndex = "iterate" + normalizeIdentifier(i.name);
48 if i.type.isArray {
49 @ for (std::vector<@i.name@*>::const_iterator @sIndex@ = @sAttributeName@.begin(); @sIndex@ != @sAttributeName@.end(); ++@sIndex@) {
50 delete *@sIndex@;
51 }
52 @
53 } else {
54 @ delete @sAttributeName@;
55 @
56 }
57 }
58 }
59 @}
60
61 @
62 foreach i in this.listOfMethods {
63 if existVariable(i.type) {
64 @@getType<"C++">(i.type)@@
65 } else {
66 @void@
67 }
68 @ @this.name@::@i.name@(@
69 foreach j in i.listOfParameters {
70 if !first(j) {
71 @, @
72 }
73 @@getParameterType<"C++">(j.type, j.mode)@ @getVariableName(j.name, j.type)@@
74 }
75 @) {
76 @
77 setProtectedArea(getMethodID(i));
78 @}
79 @
80 }
// file "GettingStarted/LeaderScript1.cws":
1 if !getProperty("DESIGN_FILE")
2 error("'-define DESIGN_FILE=file' expected on the command line");
3 traceLine("'Simple Modeling' design file to parse = \""
4 + getProperty("DESIGN_FILE") + "\"");
5 parseAsBNF("GettingStarted/SimpleML-parsing.cwp",
6 project, getProperty("DESIGN_FILE"));
7 #include "TreeDecoration.cws"
8
9 #include "SharedFunctions.cws"
10 foreach myClass in project.listOfClasses {
11 traceLine("generating class '" + myClass.name + "' ...");
12 generate("GettingStarted/CppObjectHeader.cwt", myClass,
13 getWorkingPath() + "Scripts/Tutorial/GettingStarted/Cpp/"
14 + myClass.name + ".h");
15 generate("GettingStarted/CppObjectBody.cwt", myClass,
16 getWorkingPath() + "Scripts/Tutorial/GettingStarted/Cpp/"
17 + myClass.name + ".cpp");
18 }
'Simple Modeling' design file to parse = "GettingStarted/SolarSystem0.sml"
file parsed successfully
generating class 'Planet' ...
generating class 'Earth' ...
generating class 'SolarSystem' ...
// file "GettingStarted/Cpp/SolarSystem.h":
#ifndef _SolarSystem_h_
#define _SolarSystem_h_
#include <vector>
#include <string>
// this line separates the two insertion points, so as to distinguish them!
class Planet;
class SolarSystem {
private:
std::vector<Planet*> _tpPlanets;
public:
SolarSystem();
~SolarSystem();
// accessors:
inline std::vector<Planet*> getPlanets() const { return _tpPlanets; }
inline void setPlanets(std::vector<Planet*> tpPlanets) { _tpPlanets = tpPlanets; }
// methods:
private:
SolarSystem(const SolarSystem&);
SolarSystem& operator =(const SolarSystem&);
};
#endif
// file "GettingStarted/Cpp/Planet.cpp":
1 #ifdef WIN32
2 #pragma warning(disable : 4786)
3 #endif
4
5 //##protect##"include files"
6 //##protect##"include files"
7
8 #include "Planet.h"
9
10 Planet::Planet() : _dDiameter(0.0) {
11 }
12
13 Planet::~Planet() {
14 }
15
16 double Planet::getDistanceToSun(int iDay, int iMonth, int iYear) {
17 //##protect##"getDistanceToSun.int.int.int"
18 //##protect##"getDistanceToSun.int.int.int"
19 }
// file "GettingStarted/JAVAObject.cwt":
1 package solarsystem;
2
3 public class @this.name@ @
4 if existVariable(this.parent) {
5 @extends @this.parent.name@ @
6 }
7 @{
8 @
9 foreach i in this.listOfAttributes {
10 @ private @getType<"JAVA">(i.type)@ _@getVariableName(i.name, i.type)@;
11 @
12 }
13 @
14 public @this.name@() {}
15
16 // accessors:
17 @
18 foreach i in this.listOfAttributes {
19 local sVariableName = getVariableName(i.name, i.type);
20 @ public @getType<"JAVA">(i.type)@ get@normalizeIdentifier(i.name)@() { return _@sVariableName@; }
21 public void set@normalizeIdentifier(i.name)@(@getType<"JAVA">(i.type)@ @sVariableName@) { _@sVariableName@ = @sVariableName@; }
22 @
23 }
24 @
25 // methods:
26 @
27 foreach i in this.listOfMethods {
28 @ public @
29 if existVariable(i.type) {
30 @@getType<"JAVA">(i.type)@@
31 } else {
32 @void@
33 }
34 @ @i.name@(@
35 foreach j in i.listOfParameters {
36 if !first(j) {
37 @, @
38 }
39 @@getParameterType<"JAVA">(j.type, j.mode)@ @getVariableName(j.name, j.type)@@
40 }
41 @) {
42 @
43 setProtectedArea(getMethodID(i));
44 @ }
45
46 @
47 }
48 @}
// file "GettingStarted/LeaderScript2.cws":
1 if !getProperty("DESIGN_FILE")
2 error("'-define DESIGN_FILE=file' expected on the command line");
3 traceLine("'Simple Modeling' design file to parse = \""
4 + getProperty("DESIGN_FILE") + "\"");
5 parseAsBNF("GettingStarted/SimpleML-parsing.cwp",
6 project, getProperty("DESIGN_FILE"));
7 #include "TreeDecoration.cws"
8
9 #include "SharedFunctions.cws"
10 foreach myClass in project.listOfClasses {
11 traceLine("generating class '" + myClass.name + "' ...");
12 generate("GettingStarted/CppObjectHeader.cwt", myClass, getWorkingPath() + "Scripts/Tutorial/GettingStarted/Cpp/" + myClass.name + ".h");
13 generate("GettingStarted/CppObjectBody.cwt", myClass, getWorkingPath() + "Scripts/Tutorial/GettingStarted/Cpp/" + myClass.name + ".cpp");
14 generate("GettingStarted/JAVAObject.cwt", myClass, getWorkingPath() + "Scripts/Tutorial/GettingStarted/JAVA/solarsystem/" + myClass.name + ".java");
15 }
'Simple Modeling' design file to parse = "GettingStarted/SolarSystem0.sml"
file parsed successfully
generating class 'Planet' ...
generating class 'Earth' ...
generating class 'SolarSystem' ...
// file "GettingStarted/JAVA/solarsystem/SolarSystem.java":
package solarsystem;
public class SolarSystem {
private java.util.ArrayList/*<Planet>*/ _tpPlanets;
public SolarSystem() {}
// accessors:
public java.util.ArrayList/*<Planet>*/ getPlanets() { return _tpPlanets; }
public void setPlanets(java.util.ArrayList/*<Planet>*/ tpPlanets) { _tpPlanets = tpPlanets; }
// methods:
}
// file "GettingStarted/JAVA/solarsystem/Planet.java":
package solarsystem;
public class Planet {
private double _dDiameter;
public Planet() {}
// accessors:
public double getDiameter() { return _dDiameter; }
public void setDiameter(double dDiameter) { _dDiameter = dDiameter; }
// methods:
public double getDistanceToSun(int iDay, int iMonth, int iYear) {
//##protect##"getDistanceToSun.int.int.int"
//##protect##"getDistanceToSun.int.int.int"
}
}
// file "GettingStarted/defaultDocumentation.html":
<HTML>
<HEAD>
<TITLE>some title...</TITLE>
</HEAD>
<BODY>
<H1>some title...</H1>
some global documentation...
<!--##markup##"classes presentation"-->
</BODY>
</HTML>
// file "GettingStarted/HTMLDocumentation.cwt":
1 @
2 if getMarkupKey() == "classes presentation" {
3 foreach i in project.listOfClasses {
4 @
5 <H2><A href="#@i.name@">@i.name@</A></H2>
6 @
7 setProtectedArea(i.name + ":presentation");
8 if !isEmpty(i.listOfAttributes) {
9 @
10 <TABLE border="1" cellpadding="3" cellspacing="0" width="100%">
11 <TR BGCOLOR="#CCCCFF">
12 <TD><B>Type</B></TD>
13 <TD><B>Attribute name</B></TD>
14 <TD><B>Description</B></TD>
15 </TR>
16 @
17 foreach j in i.listOfAttributes {
18 @ <TR>
19 <TD>@composeHTMLLikeString(getType<this.language> (j.type))@</TD>
20 <TD>@j.name@</TD>
21 <TD>
22 @
23 setProtectedArea(i.name + "::" + j.name + ":description");
24 @
25 </TD>
26 </TR>
27 @
28 }
29 @ </TABLE>
30 @
31 }
32 if !isEmpty(i.listOfMethods) {
33 @
34 <UL>
35 @
36 foreach j in i.listOfMethods {
37 @ <LI>@
38 if existVariable(j.type) {
39 @function @composeHTMLLikeString(getType <this.language>(j.type))@ @
40 } else {
41 @procedure@
42 }
43 @<B>@j.name@</B>(@
44 foreach k in j.listOfParameters {
45 if !first(k) {
46 @, @
47 }
48 @@composeHTMLLikeString(getParameterType <this.language>(k.type, k.mode))@ <I>@getVariableName(k.name, k.type)@</I>@
49 }
50 @)
51 <BR>
52 @
53 setProtectedArea(i.name + "::" + getMethodID(j) + ":description");
54 @
55 </LI>
56 @
57 }
58 @ </UL>
59 @
60 }
61 }
62 }
// file "GettingStarted/LeaderScript3.cws":
1 if !getProperty("DESIGN_FILE")
2 error("'-define DESIGN_FILE=file' expected on the command line");
3 traceLine("'Simple Modeling' design file to parse = \""
4 + getProperty("DESIGN_FILE") + "\"");
5 parseAsBNF("GettingStarted/SimpleML-parsing.cwp",
6 project, getProperty("DESIGN_FILE"));
7 #include "TreeDecoration.cws"
8
9 #include "SharedFunctions.cws"
10 foreach myClass in project.listOfClasses {
11 traceLine("generating class '" + myClass.name + "' ...");
12 generate("GettingStarted/CppObjectHeader.cwt", myClass, getWorkingPath() + "Scripts/Tutorial/GettingStarted/Cpp/" + myClass.name + ".h");
13 generate("GettingStarted/CppObjectBody.cwt", myClass, getWorkingPath() + "Scripts/Tutorial/GettingStarted/Cpp/" + myClass.name + ".cpp");
14 generate("GettingStarted/JAVAObject.cwt", myClass, getWorkingPath() + "Scripts/Tutorial/GettingStarted/JAVA/solarsystem/" + myClass.name + ".java");
15 }
16 if !existFile("Scripts/Tutorial/GettingStarted/SolarSystem0.html") {
17 copyFile("Scripts/Tutorial/GettingStarted/defaultDocumentation.html", "Scripts/Tutorial/GettingStarted/SolarSystem0.html");
18 }
19
20 local myDocumentationContext;
21 insert myDocumentationContext.language = "C++";
22 traceLine("generating the HTML documentation...");
23 setCommentBegin("<!--");
24 setCommentEnd("-->");
25 expand("GettingStarted/HTMLDocumentation.cwt",
26 myDocumentationContext, getWorkingPath()
27 + "Scripts/Tutorial/GettingStarted/SolarSystem0.html");
'Simple Modeling' design file to parse = "GettingStarted/SolarSystem0.sml"
file parsed successfully
generating class 'Planet' ...
generating class 'Earth' ...
generating class 'SolarSystem' ...
generating the HTML documentation...
// file "GettingStarted/SolarSystem0.html":
<HTML>
<HEAD>
<TITLE>some title...</TITLE>
</HEAD>
<BODY>
<H1>some title...</H1>
some global documentation...
<!--##markup##"classes presentation"--><!--##begin##"classes presentation"-->
<H2><A href="#Planet">Planet</A></H2>
<!--##protect##"Planet:presentation"--><!--##protect##"Planet:presentation"-->
<TABLE border="1" cellpadding="3" cellspacing="0" width="100%">
<TR BGCOLOR="#CCCCFF">
<TD><B>Type</B></TD>
<TD><B>Attribute name</B></TD>
<TD><B>Description</B></TD>
</TR>
<TR>
<TD>double</TD>
<TD>diameter</TD>
<TD>
<!--##protect##"Planet::diameter:description"--><!--##protect##"Planet::diameter:description"-->
</TD>
</TR>
</TABLE>
<UL>
<LI>function double <B>getDistanceToSun</B>(int <I>iDay</I>, int <I>iMonth</I>, int <I>iYear</I>)
<BR>
<!--##protect##"Planet::getDistanceToSun.int.int.int:description"--><!--##protect##"Planet::getDistanceToSun.int.int.int:description"-->
</LI>
</UL>
<H2><A href="#Earth">Earth</A></H2>
<!--##protect##"Earth:presentation"--><!--##protect##"Earth:presentation"-->
<TABLE border="1" cellpadding="3" cellspacing="0" width="100%">
<TR BGCOLOR="#CCCCFF">
<TD><B>Type</B></TD>
<TD><B>Attribute name</B></TD>
<TD><B>Description</B></TD>
</TR>
<TR>
<TD>std::vector<std::string></TD>
<TD>countryNames</TD>
<TD>
<!--##protect##"Earth::countryNames:description"--><!--##protect##"Earth::countryNames:description"-->
</TD>
</TR>
</TABLE>
<H2><A href="#SolarSystem">SolarSystem</A></H2>
<!--##protect##"SolarSystem:presentation"--><!--##protect##"SolarSystem:presentation"-->
<TABLE border="1" cellpadding="3" cellspacing="0" width="100%">
<TR BGCOLOR="#CCCCFF">
<TD><B>Type</B></TD>
<TD><B>Attribute name</B></TD>
<TD><B>Description</B></TD>
</TR>
<TR>
<TD>std::vector<Planet*></TD>
<TD>planets</TD>
<TD>
<!--##protect##"SolarSystem::planets:description"--><!--##protect##"SolarSystem::planets:description"-->
</TD>
</TR>
</TABLE>
<!--##end##"classes presentation"-->
</BODY>
</HTML>
// file "GettingStarted/HTML-parsing.cwp":
1 #noCase
2
3 HTML ::= #ignore(HTML) #continue '<' "HTML" '>' HTMLHeader HTMLBody '<' '/' "HTML" '>' #empty;
4 HTMLHeader ::= '<' #continue "HEAD" '>' [~['<' '/' "HEAD" '>']]* '<' '/' "HEAD" '>';
5 HTMLBody ::= '<' #continue "BODY" '>' HTMLText '<' '/' "BODY" '>';
6 HTMLText ::=
7 [
8 ~'<'
9 |
10 !['<' '/'] #continue '<'
11 #readIdentifier:sTag HTMLNextOfTag<sTag>
12 ]*;
13 HTMLNextOfTag<"H1"> ::= #continue '>' HTMLText '<' '/' "H1" '>';
14 HTMLNextOfTag<"H2"> ::= #continue '>' HTMLText '<' '/' "H2" '>';
15 HTMLNextOfTag<"A"> ::= [HTMLAttribute]* #continue '>' HTMLText '<' '/' 'A' '>';
16 HTMLNextOfTag<"TABLE"> ::= [HTMLAttribute]* #continue '>' [HTMLTag("TR")]* '<' '/' "TABLE" '>';
17 HTMLTag(sTag : value) ::= '<' #readText(sTag) #continue HTMLNextOfTag<sTag>;
18 HTMLNextOfTag<"TR"> ::= [HTMLAttribute]* #continue '>' [HTMLTag("TD")]* '<' '/' "TR" '>';
19 HTMLNextOfTag<"TD"> ::= [HTMLAttribute]* #continue '>' HTMLText '<' '/' "TD" '>';
20 HTMLNextOfTag<"UL"> ::= [HTMLAttribute]* #continue '>' [HTMLTag("LI")]* '<' '/' "UL" '>';
21 HTMLNextOfTag<"LI"> ::= [HTMLAttribute]* #continue '>' HTMLText '<' '/' "LI" '>';
22 HTMLNextOfTag<"B"> ::= #continue '>' HTMLText '<' '/' "B" '>';
23 HTMLNextOfTag<"I"> ::= #continue '>' HTMLText '<' '/' "I" '>';
24 HTMLNextOfTag<"FONT"> ::= [HTMLAttribute]* #continue '>' HTMLText '<' '/' "FONT" '>';
25 HTMLNextOfTag<"BR"> ::= ['/']? #continue '>';
26 HTMLAttribute ::= #readIdentifier ['=' #continue [STRING_LITERAL | WORD_LITERAL]]?;
27
28
29 STRING_LITERAL ::= #!ignore '\"' [~'\"']* '\"';
30 WORD_LITERAL ::= #!ignore [~['>' | '/' | ' ' | '\t']]+;
// file "GettingStarted/HTML2LaTeX.cwp":
1 #noCase
2
3 HTML2LaTeX ::= #ignore(HTML) #continue '<' "HTML" '>' HTMLHeader HTMLBody '<' '/' "HTML" '>' #empty;
4 HTMLHeader ::= '<' #continue "HEAD" '>' [~['<' '/' "HEAD" '>']]* '<' '/' "HEAD" '>';
5 HTMLBody ::= '<' #continue "BODY" '>' HTMLText '<' '/' "BODY" '>';
6 HTMLText ::= #!ignore
7 [
8 '&' #continue #readIdentifier:sEscape HTMLEscape<sEscape> ';'
9 |
10 ~'<':cChar => writeText(cChar);
11 |
12 !['<' blanks '/']
13 [
14 "<!--" #continue [~"-->"]* "-->"
15 |
16 '<' #continue #ignore(HTML) #readIdentifier:sTag HTMLNextOfTag<sTag>
17 ]
18 ]*;
19 HTMLEscape<"lt"> ::= => {@<@};
20 HTMLEscape<"gt"> ::= => {@>@};
21 HTMLTag(sTag : value) ::= '<' #readText(sTag) #continue HTMLNextOfTag<sTag>;
22 HTMLNextOfTag<"H1"> ::=
23 #continue '>' => {@\subsection{@}
24 HTMLText
25 '<' '/' "H1" '>' => {@}@};
26 HTMLNextOfTag<"H2"> ::=
27 #continue '>' => {@\subsubsection{@}
28 HTMLText
29 '<' '/' "H2" '>' => {@}@};
30 HTMLNextOfTag<"A"> ::= [HTMLAttribute]* #continue '>' HTMLText '<' '/' 'A' '>';
31 HTMLNextOfTag<"TABLE"> ::=
32 [HTMLAttribute]* #continue '>' => {
33 @\begin{table@
34 newFloatingLocation("table PDF suffix");
35 @}{@
36 newFloatingLocation("table columns");
37 @}{.5}@
38 }
39 => local sPDFTableSuffix;
40 HTMLTableTitle(sPDFTableSuffix)
41 [HTMLTableLine(sPDFTableSuffix)]*
42 '<' '/' "TABLE" '>' => {@\end{table@sPDFTableSuffix@}
43 @};
44 HTMLTableTitle(sPDFTableSuffix : node) ::=
45 '<' "TR" [HTMLAttribute]*
46 #continue '>'
47 [HTMLTableCol(sPDFTableSuffix)]*
48 '<' '/' "TR" '>' => {
49 insertText(getFloatingLocation("table PDF suffix"), sPDFTableSuffix);
50 writeText(endl());
51 };
52 HTMLTableCol(sPDFTableSuffix : node) ::=
53 '<' "TD" [HTMLAttribute]* #continue '>' => {
54 @{@
55 if !sPDFTableSuffix insertText(getFloatingLocation("table columns"), "l");
56 else insertText(getFloatingLocation("table columns"), "|l");
57 set sPDFTableSuffix += "i";
58 }
59 '<' 'B' '>' [#!ignore [~'<':cChar => writeText(cChar);]*] '<' '/' 'B' '>'
60 '<' '/' "TD" '>' => {@}@};
61 HTMLTableLine(sPDFTableSuffix : value) ::=
62 '<' "TR" [HTMLAttribute]* #continue '>' => {@\line@sPDFTableSuffix@@}
63 [HTMLTag("TD")]* '<' '/' "TR" '>' => {writeText(endl());};
64 HTMLNextOfTag<"TD"> ::=
65 [HTMLAttribute]* #continue '>' => {@{@}
66 HTMLCellText '<' '/' "TD" '>' => {@}@};
67 HTMLCellText ::= #!ignore
68 [
69 '&' #continue #readIdentifier:sEscape HTMLEscape<sEscape> ';'
70 |
71 ['\r']? ['\n'] => {@ @}
72 |
73 ~'<':cChar => writeText(cChar);
74 |
75 !['<' blanks '/']
76 [
77 "<!--" #continue [~"-->"]* "-->"
78 |
79 '<' #continue #ignore(HTML) #readIdentifier:sTag HTMLNextOfTag<sTag>
80 ]
81 ]*;
82 HTMLNextOfTag<"UL"> ::=
83 [HTMLAttribute]* #continue '>' => {@\begin{itemize}
84 @}
85 [HTMLTag("LI")]*
86 '<' '/' "UL" '>' => {@\end{itemize}
87 @};
88 HTMLNextOfTag<"LI"> ::=
89 [HTMLAttribute]* #continue '>' => {@\item @}
90 HTMLText
91 '<' '/' "LI" '>' => {writeText(endl());};
92 HTMLNextOfTag<"B"> ::=
93 #continue '>' => {@\textbf{@}
94 HTMLText
95 '<' '/' "B" '>' => {@}@};
96 HTMLNextOfTag<"I"> ::=
97 #continue '>' => {@\textbf{@}
98 HTMLText
99 '<' '/' "I" '>' => {@}@};
100 HTMLNextOfTag<"FONT"> ::= [HTMLAttribute]* #continue '>' HTMLText '<' '/' "FONT" '>';
101 HTMLNextOfTag<"BR"> ::= ['/']? #continue '>' => { writeText(endl());};
102 HTMLAttribute ::= #readIdentifier ['=' #continue [STRING_LITERAL | WORD_LITERAL]]?;
103
104
105 blanks ::= [' '| '\t' | '\r' | '\n']*;
106 STRING_LITERAL ::= #!ignore '\"' [~'\"']* '\"';
107 WORD_LITERAL ::= #!ignore [~['>' | '/' | ' ' | '\t']]+;
// file "GettingStarted/LeaderScript4.cws":
1 if !getProperty("DESIGN_FILE")
2 error("'-define DESIGN_FILE=file' expected on the command line");
3 traceLine("'Simple Modeling' design file to parse = \""
4 + getProperty("DESIGN_FILE") + "\"");
5 parseAsBNF("GettingStarted/SimpleML-parsing.cwp",
6 project, getProperty("DESIGN_FILE"));
7 #include "TreeDecoration.cws"
8
9 #include "SharedFunctions.cws"
10 foreach myClass in project.listOfClasses {
11 traceLine("generating class '" + myClass.name + "' ...");
12 generate("GettingStarted/CppObjectHeader.cwt", myClass, getWorkingPath() + "Scripts/Tutorial/GettingStarted/Cpp/" + myClass.name + ".h");
13 generate("GettingStarted/CppObjectBody.cwt", myClass, getWorkingPath() + "Scripts/Tutorial/GettingStarted/Cpp/" + myClass.name + ".cpp");
14 generate("GettingStarted/JAVAObject.cwt", myClass, getWorkingPath() + "Scripts/Tutorial/GettingStarted/JAVA/solarsystem/" + myClass.name + ".java");
15 }
16
17 local myDocumentationContext;
18 insert myDocumentationContext.language = "C++";
19 traceLine("generating the HTML documentation...");
20 setCommentBegin("<!--");
21 setCommentEnd("-->");
22 expand("GettingStarted/HTMLDocumentation.cwt",
23 myDocumentationContext, getWorkingPath()
24 + "Scripts/Tutorial/GettingStarted/SolarSystem1.html");
25 translate("GettingStarted/HTML2LaTeX.cwp", project, "GettingStarted/SolarSystem1.html", getWorkingPath() + "Scripts/Tutorial/GettingStarted/SolarSystem.tex");
'Simple Modeling' design file to parse = "GettingStarted/SolarSystem0.sml"
file parsed successfully
generating class 'Planet' ...
generating class 'Earth' ...
generating class 'SolarSystem' ...
generating the HTML documentation...
| Type | Attribute name | Description |
| double | diameter | the average diameter of the planet |
| Type | Attribute name | Description |
| std::vector<std::string> | countryNames | the name of all countries are put into |
| Type | Attribute name | Description |
| std::vector<Planet*> | planets | the planets that compose the solar system. |
// file "GettingStarted/LeaderScript5.cws":
if !getProperty("DESIGN_FILE")
error("'-define DESIGN_FILE=file' expected on the command line");
traceLine("'Simple Modeling' design file to parse = \""
+ getProperty("DESIGN_FILE") + "\"");
parseAsBNF("GettingStarted/SimpleML-parsing.cwp",
project, getProperty("DESIGN_FILE"));
#include "TreeDecoration.cws"
#include "SharedFunctions.cws"
foreach myClass in project.listOfClasses {
traceLine("generating class '" + myClass.name + "' ...");
generate("GettingStarted/CppObjectHeader.cwt", myClass, getWorkingPath() + "Scripts/Tutorial/GettingStarted/Cpp/" + myClass.name + ".h");
generate("GettingStarted/CppObjectBody.cwt", myClass, getWorkingPath() + "Scripts/Tutorial/GettingStarted/Cpp/" + myClass.name + ".cpp");
generate("GettingStarted/JAVAObject.cwt", myClass, getWorkingPath() + "Scripts/Tutorial/GettingStarted/JAVA/solarsystem/" + myClass.name + ".java");
}
local myDocumentationContext;
insert myDocumentationContext.language = "C++";
traceLine("generating the HTML documentation...");
setCommentBegin("<!--");
setCommentEnd("-->");
expand("GettingStarted/HTMLDocumentation.cwt",
myDocumentationContext, getWorkingPath()
+ "Scripts/Tutorial/GettingStarted/SolarSystem1.html");
translate("GettingStarted/HTML2LaTeX.cwp", project, "GettingStarted/SolarSystem1.html", getWorkingPath() + "Scripts/Tutorial/GettingStarted/SolarSystem.tex");
"LeaderScript5.cws" at 5: if !getProperty("DESIGN_FILE")
// The controlling sequence stops on the first statement of the leader script.
// We go the next instruction:
n
"LeaderScript5.cws" at 7: traceLine("'Simple Modeling' design file to parse = \""
// twice more:
n2
'Simple Modeling' design file to parse = "GettingStarted/SolarSystem0.sml"
"LeaderScript5.cws" at 11: parseAsBNF("GettingStarted/SimpleML-parsing.cwp",
//let plunge into the BNF-driven script:
s
parsed file is "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SolarSystem0.sml":1,1
"SimpleML-parsing.cwp" at 6: world ::= #ignore(C++) [class_declaration]* #empty
//We are pointing to the beginning of the rule. Let execute '#ignore(C++)':
s
parsed file is "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SolarSystem0.sml":1,1
"SimpleML-parsing.cwp" at 6: world ::= #ignore(C++) [class_declaration]* #empty
//Let go to the unbounded expression '[class_declaration]*':
s
parsed file is "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SolarSystem0.sml":1,1
"SimpleML-parsing.cwp" at 6: world ::= #ignore(C++) [class_declaration]* #empty
//Now, we have a look to 'class_declaration':
s
parsed file is "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SolarSystem0.sml":2,1
"SimpleML-parsing.cwp" at 16: class_declaration ::= IDENT:"class" #continue
//We visit 'INDENT:"class"' and we step over immediatly. Into a BNF-driven script, tokens of a
//sequence are iterated step by step, and 'next' runs all the sequence in one shot:
s
parsed file is "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SolarSystem0.sml":2,1
"SimpleML-parsing.cwp" at 112: IDENT ::= #!ignore ['a'..'z'|'A'..'Z'|'_']
n
parsed file is "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SolarSystem0.sml":2,6
"SimpleML-parsing.cwp" at 21: IDENT:sClassName
//We visit 'INDENT:sClassName' and we step over immediatly:
s
parsed file is "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SolarSystem0.sml":2,7
"SimpleML-parsing.cwp" at 112: IDENT ::= #!ignore ['a'..'z'|'A'..'Z'|'_']
n
parsed file is "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SolarSystem0.sml":2,13
"SimpleML-parsing.cwp" at 25: => insert project.listOfClasses[sClassName].name = sClassName;
//What about all local variables available on the stack?
l
sClassName
//What is the value of 'sClassName'?
t sClassName
Planet
//Now, we are looking at a classical statement of the language, an 'insert' assignment. But
//it might be more convenient to see more source code:
d 4
parsed file is "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SolarSystem0.sml":2,13
21: IDENT:sClassName
22: //note: about parsing, classes are modeled into node
23: //note: \textbf{project.listOfClasses[}\textit{sClassName}\textbf{]}. Its attribute
24: //note: \samp{name} contains the value of \textit{sClassName}.
25: => insert project.listOfClasses[sClassName].name = sClassName;
26: //note: if the class inherits from a parent, \samp{\textbf{':'}} is necessary followed by
27: //note: an identifier (pattern \samp{\#continue}), and the identifier that matches with
28: //note: clause call \textit{IDENT} is assigned to the local variable \samp{sClassName},
29: [':' #continue IDENT:sParentName
//What about the call stack?
stack
parsed file is "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SolarSystem0.sml":2,13
"SimpleML-parsing.cwp" at 25: => insert project.listOfClasses[sClassName].name = sClassName;
parsed file is "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SolarSystem0.sml":2,13
"SimpleML-parsing.cwp" at 6: world ::= #ignore(C++) [class_declaration]* #empty
parsed file is "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SolarSystem0.sml":2,13
"LeaderScript5.cws" at 11: parseAsBNF("GettingStarted/SimpleML-parsing.cwp",
//Exiting the debug session:
q
file parsed successfully
generating class 'Planet' ...
generating class 'Earth' ...
generating class 'SolarSystem' ...
generating the HTML documentation...
// file "GettingStarted/LeaderScript6.cws":
if !getProperty("DESIGN_FILE")
error("'-define DESIGN_FILE=file' expected on the command line");
traceLine("'Simple Modeling' design file to parse = \""
+ getProperty("DESIGN_FILE") + "\"");
parseAsBNF("GettingStarted/SimpleML-parsing.cwp",
project, getProperty("DESIGN_FILE"));
#include "TreeDecoration.cws"
#include "SharedFunctions.cws"
foreach myClass in project.listOfClasses {
traceLine("generating class '" + myClass.name + "' ...");
generate("GettingStarted/CppObjectHeader.cwt", myClass, getWorkingPath() + "Scripts/Tutorial/GettingStarted/Cpp/" + myClass.name + ".h");
generate("GettingStarted/CppObjectBody.cwt", myClass, getWorkingPath() + "Scripts/Tutorial/GettingStarted/Cpp/" + myClass.name + ".cpp");
generate("GettingStarted/JAVAObject.cwt", myClass, getWorkingPath() + "Scripts/Tutorial/GettingStarted/JAVA/solarsystem/" + myClass.name + ".java");
}
local myDocumentationContext;
insert myDocumentationContext.language = "C++";
traceLine("generating the HTML documentation...");
setCommentBegin("<!--");
setCommentEnd("-->");
expand("GettingStarted/HTMLDocumentation.cwt",
myDocumentationContext, getWorkingPath()
+ "Scripts/Tutorial/GettingStarted/SolarSystem1.html");
translate("GettingStarted/HTML2LaTeX.cwp", project, "GettingStarted/SolarSystem1.html", getWorkingPath() + "Scripts/Tutorial/GettingStarted/SolarSystem.tex");
'Simple Modeling' design file to parse = "GettingStarted/SolarSystem0.sml"
file parsed successfully
generating class 'Planet' ...
generating class 'Earth' ...
generating class 'SolarSystem' ...
generating the HTML documentation...
-- quantify session --
quantify execution time = 438ms
User defined functions:
populateHeaderDeclarations(...) file "c:/Projects/generator/Scripts/Tutorial/GettingStarted/CppObjectHeader.cwt" at 29: 7 occurences in 0ms
getMethodID(...) file "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SharedFunctions.cws" at 98: 3 occurences in 0ms
getParameterType(...) file "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SharedFunctions.cws" at 44: 3 occurences in 0ms
getType(...) file "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SharedFunctions.cws" at 31: 13 occurences in 0ms
getVariableName(...) file "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SharedFunctions.cws" at 76: 26 occurences in 2ms
normalizeIdentifier(...) file "c:/Projects/generator/Scripts/Tutorial/GettingStarted/SharedFunctions.cws" at 5: 39 occurences in 1ms
Predefined functions:
charAt(...): 39 occurrences
composeHTMLLikeString(...): 7 occurrences
endString(...): 9 occurrences
endl(...): 19 occurrences
executeStringQuiet(...): 1 occurrences
existVariable(...): 11 occurrences
findElement(...): 2 occurrences
findFirstChar(...): 39 occurrences
first(...): 12 occurrences
getFloatingLocation(...): 23 occurrences
getMarkupKey(...): 1 occurrences
getProperty(...): 3 occurrences
getWorkingPath(...): 11 occurrences
isEmpty(...): 6 occurrences
isNegative(...): 39 occurrences
newFloatingLocation(...): 12 occurrences
not(...): 72 occurrences
startString(...): 39 occurrences
subString(...): 39 occurrences
toUpperString(...): 39 occurrences
Procedures:
__RAW_TEXT_TO_WRITE(...): 498 occurrences
clearVariable(...): 1 occurrences
expand(...): 1 occurrences
generate(...): 9 occurrences
insertTextOnce(...): 24 occurrences
parseAsBNF(...): 1 occurrences
setCommentBegin(...): 1 occurrences
setCommentEnd(...): 1 occurrences
setProtectedArea(...): 19 occurrences
traceLine(...): 5 occurrences
translate(...): 1 occurrences
writeText(...): 325 occurrences
Covered source code: 83%
-- end of quantify session --
compileToCpp("GettingStarted/LeaderScript6.cws",
"Scripts/Tutorial/GettingStarted/bin", ".");
Scripts/Tutorial/GettingStarted/bin/CGExternalHandling.h
Scripts/Tutorial/GettingStarted/bin/CGRuntime.h
Scripts/Tutorial/GettingStarted/bin/CppObjectBody_cwt.cpp
Scripts/Tutorial/GettingStarted/bin/CppObjectBody_cwt.h
Scripts/Tutorial/GettingStarted/bin/CppObjectHeader_cwt.cpp
Scripts/Tutorial/GettingStarted/bin/CppObjectHeader_cwt.h
Scripts/Tutorial/GettingStarted/bin/CppParsingTree.h
Scripts/Tutorial/GettingStarted/bin/DynPackage.h
Scripts/Tutorial/GettingStarted/bin/HTML2LaTeX_cwp.cpp
Scripts/Tutorial/GettingStarted/bin/HTML2LaTeX_cwp.h
Scripts/Tutorial/GettingStarted/bin/HTMLDocumentation_cwt.cpp
Scripts/Tutorial/GettingStarted/bin/HTMLDocumentation_cwt.h
Scripts/Tutorial/GettingStarted/bin/JAVAObject_cwt.cpp
Scripts/Tutorial/GettingStarted/bin/JAVAObject_cwt.h
Scripts/Tutorial/GettingStarted/bin/LeaderScript6.dsp
Scripts/Tutorial/GettingStarted/bin/LeaderScript6_cws.cpp
Scripts/Tutorial/GettingStarted/bin/LeaderScript6_cws.h
Scripts/Tutorial/GettingStarted/bin/Makefile
Scripts/Tutorial/GettingStarted/bin/SimpleML-parsing_cwp.cpp
Scripts/Tutorial/GettingStarted/bin/SimpleML-parsing_cwp.h
Scripts/Tutorial/GettingStarted/bin/UtlException.h
![]() |
The scripting language |
| Switch | Description |
| -args [arg]* | Pass some arguments to the command line. The list of arguments stops at the end of the command line or as soon as an option is encountered. The arguments are stored in a global array variable called _ARGS. |
| -autoexpand file-to-expand | The file file-to-expand is explored for expanding code at markups, executing a template-based script inserted just below each markup. It is identical to execute the script function autoexpand(file-to-expand, project). |
| -c++ generated-project-path CodeWorker-path? |
To translate the leader script and all its dependencies in C++ source code, once the execution of the leader script has achieved (same job as compileToCpp() compileToCpp()). The CodeWorker-path is optional and gives the path through includes and libraries of the software. However, it is now recommended to specify CodeWorker-path by the switch -home. |
| -c++2target script-file generated-project-path target-language? |
To translate the leader script and all its dependencies in C++ source code.
Hence, the C++ is translated to a target language, all that once the execution
of the leader script has achieved. Do not forget to give the path through
includes and libraries of CodeWorker, setting the switch -home. A preprocessor definition called "c++2target-path" is automatically created. It contains the path of the generated project. Call getProperty("c++2target-path") to retrieve the path value. target-language is optional if at least one script of the project holds the target into its filename, just before the extension. Example: "myscript.java.cwt" means that the target language of this script is "java". A property can follow the name of the target language, separated by a '=' symbol. The property is accessible via getProperty("c++2target-property"), and its nature depends on the target. For instance, in Java, this property represents the package the generated classes will belong to. Example: java=org.landscape.mountains. |
| -c++external filename | To generate C++ source code for implementing all functions declared as external into scripts. |
| -commentBegin format | To specify the format of a beginning of comment. |
| -commentEnd format | To specify the format of a comment's end. |
| -compile scriptFile | To compile a script file, just to check whether the syntax is correct. |
| Switch | Description |
| -commands commandFile | To load all arguments processed ordinary on the command-line. It must be the only switch or else passed on the command-line. |
| -console | To open a console session (default mode if no script to interpret is specified via -script or -compile or -generate or -expand. |
| -debug [remote]? | To debug a script in a console while executing it. The optional
argument remote defines parameters for a remote socket control of the debugging session.
remote looks like <hostname>:<port>. If <hostname> is empty, CodeWorker runs as a
socket server. |
| -define VAR=value or -D ... |
To define some variables, as
when using the C++ preprocessor or when passing properties to the JAVA compiler.
These variables are similar to properties, insofar as they aren't exploited during
the preprocessing of scripts to interpret. This option conforms to the format
-define VAR when no value has to be assigned ; in that case,
"true" is assigned by default to variable VAR. The script
function getProperty("VAR") gives
the value of variable VAR. |
| -expand pattern-script file-to-expand |
Script file pattern-script is executed to expand file file-to-expand into markups. It is identical to execute script function expand(pattern-script, project, file-to-expand). |
| -fast | To optimize speed. While processing generation, the output
file is built into memory, instead of into a temporary file. |
| -generate pattern-script file-to-generate |
Script
file pattern-script is executed to generate file file-to-generate.
It is identical to execute script function generate(pattern-script, project, file-to-generate). |
| -genheader text | Adds a header at the beginning of all generated files, followed by a text (see procedure setGenerationHeader() setGenerationHeader()). |
| -help or ? | Help about the command line. |
| -home CodeWorker-path | Specifies the path to the home directory of CodeWorker. |
| -I path | Specify a path to explore when trying to find a file while invoking include or parseFree or parseAsBNF or generate or expand or ... This option may be repeated to specify more than one path. |
| -insert variable_expression value |
Creates a new node in
the main parse tree project and assigns a constant value to it. It is identical
to execute the statement insert variable_expression = " value " ;. |
| -nologo | The interpreter doesn't write the copyright in the shell at the beginning. |
| Switch | Description |
| -nowarn warnings | Specified warning types are ignored. They are separated by pipe symbols. Today, the only recognized type is undeclvar, which prevents the developer against the use of a undeclared variable. |
| -parseBNF BNF-parsing-script source-file |
The script
file BNF-parsing-script parses source-file from an extended BNF grammar.
It is identical to execute the script function parseAsBNF(BNF-parsing-script, project, source-file). |
| -path path | Output directory, returned by the script function getWorkingPath(), and used ordinary to specify where to generate or copy a file. |
| -quantify [outputFile]? | To execute scripts into quantify mode that consists of measuring the coverage and the time consuming. Results are saved to HTML file outputFile or displayed to the console if not present. |
| -report report-file request-flag |
To generate a report once the execution has achieved.
The report is saved to file report-file and nature of information
depends on the flag request-flag. This flag must be built by computing
a bitwise OR for one or several of the following integer constants:
|
| -script script-file | Defines the leader script, which will be executed first. |
| -stack depth | To limit the recursive call of functions, for avoiding an overflow stack memory. By default, the depth is set to 1000. |
| -stdin filename | To change the standard input for reading from an existing file. It may be useful for running a scenario. |
| -stdout filename | To change the standard output for writing it to a file. |
| -time | To display the execution time expressed in milliseconds, just before exiting. |
| Switch | Description |
| -translate translation-script source-file file-to-generate |
Script
file translation-script processes a source-to-source translation.
It is identical to execute the script function translate(translation-script, project, source-file, file-to-generate). |
| -varexist | To trigger a warning when the value of a variable that doesn't exist is required into a script. |
| -verbose | To display internal messages of the interpreter (information). |
| -version version-name | To force interpreted scripts as written in a precedent version given by version-name. |
codeworker <script-file> <arg1> ... <argN> [<switch>]*
codeworker -script <script-file> -args <arg1> ... <argN> [<switch>]*
| Extension | Description |
| ".cwt" | a template-based script, for text generation |
| ".cwp" | a extended-BNF parse script, for parsing text |
| ".cws" | a common script, none of the precedent |
#if existFunction(f)
function g() {
return "result of f(): " + f();
}
#else
function f() {
return "f() was missing: declare it now";
}
#end
#use PGSQL
PGSQL::connect("-U pilot -d emergencyDB");
local sRequest = "SELECT solution FROM average_adjustment WHERE damage = 'broken wing'";
local listOfSolutions;
PGSQL::selectList(sRequest, listOfSolutions);
if listOfSolutions.empty()
traceLine("No solution. Suggestion: parachute jump?");
else {
traceLine("Solutions:");
foreach i in listOfSolutions
traceLine(" -" + i);
}
PGSQL::disconnect(); // if the plane hasn't crashed yet
CW4DL_EXPORT_SYMBOL const char*
selectList(CW4dl::Interpreter*,
CW4dl::Parameter p1, CW4dl::Parameter p2);
createCommand("selectList", VALUE_PARAMETER, NODE_PARAMETER);
CW4DL_EXPORT_SYMBOL const char*
myFunction(CW4dl::Interpreter*,
int nbParams, CW4dl::Parameter* tParams);
createCommand("myFunction", 6, tParams);
traceLine("Creating directory 'CodeWorker'...");
removeDirectory("CodeWorker");
copyFile("readme.txt", "CodeWorker/readme.txt");
...
#syntax shell:"TinyShell.cwp"
echo Creating directory 'CodeWorker'...
rmdir CodeWorker
copy readme.txt CodeWorker/readme.txt
...
#end syntax
// the first time, a parsing mode may be attached to the BNF script file
#syntax shell:"TinyShell.cwp"
...
#end syntax
// at the second call, it isn't recommended to use the path of the parsing file
// it is better to use the parsing mode registered previously
#syntax shell
...
#end syntax
// here, I know that I'll call it once only, so I don't care about a parsing mode
#syntax "MakeFile.cwp"
...
#end syntax
// file "GettingStarted/TinyShell.cwp":
tinyShell ::=
#ignore(C++)
#continue
[
#readIdentifier:sCommand
#ignore(blanks) #continue
command<sCommand>
]* #empty;
//----------------------------//
// commands of the tiny shell //
//----------------------------//
command<"copy"> ::=
#continue parameter:sSource parameter:sDestination
=> {copyFile(sSource, sDestination);};
command<"rmdir"> ::=
#continue parameter:sDirectory
=> {removeDirectory(sDirectory);};
command<"del"> ::=
#continue parameter:sFile
=> {deleteFile(sFile);};
//--------------------
// Some useful clauses
//--------------------
parameter:value ::=
#readCString:parameter
|
#!ignore #continue [~[' ' | '\t' | '\r' | '\n']]+:parameter;
increment(index)
local aVariable = "a"{["yellow", "red":"or"{.alternative="orange"
| Variable Name | Description |
| project | The main parse tree, always present. |
| this | It points to the current context variable. |
| _ARGS | An array of all custom command-line arguments. Custom arguments are following the script file name or the switch -args on the command-line. |
| _REQUEST | If the interpreter works as a CGI program, it stores all parameters of the request in a association table. The key is the parameter name, which associates the corresponding value. |
local aVariable = {"a", {"yellow", "red"}, "submarine"};
local aVariable;
pushItem aVariable = "a";
pushItem aVariable;
pushItem aVariable#back = "yellow";
pushItem aVariable#back = "red";
pushItem aVariable = "submarine";
#evaluateVariable("a.b.c")
function badFunction(myVar : node) {
...
// myVar will keep up a reference to aNode
// up to the end of the function:
ref myVar = aNode;
...
// myVar is passed as variable, so the
// reference is cancelled once the function is left!
}
// To keep the reference after leaving the function, change the parameter
// mode to reference:
function goodFunction(myVar : reference) {
...
// myVar will keep up a reference to aNode
// up to the end of the function:
ref myVar = aNode;
...
// myVar is passed as reference, so the
// reference is kept once the function is left!
}
sHTMLTag in { 'i', "kbd" }
local a = 11;
local b = 7;
traceLine("Classical mode = '"
+ inf(add(mult(5, a), 3), sub(mult(a, a), mult(b, b))) + "'");
traceLine("Escape mode = '" + $5*a + 3 < a*a - b*b$ + "'");
Classical mode = 'true'
Escape mode = 'true'
// file "Documentation/ForeachSampleSorted.cws":
local list;
insert list["silverware"] = "tea spoon";
insert list["Mountain"] = "Everest";
insert list["SilverWare"] = "Tea Spoon";
insert list["Boat"] = "Titanic";
insert list["acrobat"] = "Circus";
traceLine("Sorted list in a classical order:");
foreach i in sorted list {
traceLine("\t" + key(i));
}
traceLine("Note that uppercases are listed before lowercases." + endl());
traceLine("Sorted list where the case is ignored:");
foreach i in sorted no_case list {
traceLine("\t" + key(i));
}
traceLine("Reverse sorted list:");
foreach i in reverse sorted list {
traceLine("\t" + key(i));
}
traceLine("Reverse sorted list where the case is ignored:");
foreach i in reverse sorted no_case list {
traceLine("\t" + key(i));
}
Sorted list in a classical order:
Boat
Mountain
SilverWare
acrobat
silverware
Note that uppercases are listed before lowercases.
Sorted list where the case is ignored:
acrobat
Boat
Mountain
SilverWare
silverware
Reverse sorted list:
silverware
acrobat
SilverWare
Mountain
Boat
Reverse sorted list where the case is ignored:
silverware
SilverWare
Mountain
Boat
acrobat
foreach i in cascading myObjectModeling.packages ...
function propagateOnPackages(myPackage : node) {
foreach i in myPackage {
// my code to apply on this package
if existVariable(myPackages.packages)
propagateOnPackages(myPackages.packages);
}
}
propagateOnPackages(myObjectModeling.packages);
// file "Documentation/ForeachSampleFirst.cws":
local myObjectModeling;
insert myObjectModeling.packages["Massif"] = "...";
local myPackage;
ref myPackage = myObjectModeling.packages["Massif"];
insert myPackage.packages["Alps"] = "...";
insert myPackage.packages["Himalaya"] = "...";
insert myPackage.packages["Rock Mountains"] = "...";
insert myObjectModeling.packages["Silverware"] = "...";
ref myPackage = myObjectModeling.packages["Silverware"];
insert myPackage.packages["Spoon"] = "...";
insert myPackage.packages["Fork"] = "...";
insert myPackage.packages["Knife"] = "...";
foreach i in cascading first myObjectModeling.packages {
traceLine("\t" + key(i));
}
Alps
Himalaya
Rock Mountains
Massif
Spoon
Fork
Knife
Silverware
// file "Documentation/ForeachSampleLast.cws":
local myObjectModeling;
insert myObjectModeling.packages["Massif"] = "...";
local myPackage;
ref myPackage = myObjectModeling.packages["Massif"];
insert myPackage.packages["Alps"] = "...";
insert myPackage.packages["Himalaya"] = "...";
insert myPackage.packages["Rock Mountains"] = "...";
insert myObjectModeling.packages["Silverware"] = "...";
ref myPackage = myObjectModeling.packages["Silverware"];
insert myPackage.packages["Spoon"] = "...";
insert myPackage.packages["Fork"] = "...";
insert myPackage.packages["Knife"] = "...";
foreach i in cascading last myObjectModeling.packages {
traceLine("\t" + key(i));
}
Massif
Alps
Himalaya
Rock Mountains
Silverware
Spoon
Fork
Knife
// file "Documentation/ForfileSample.cws":
local iIndex = 0;
forfile i in cascading "*.html" {
if $findString(i, "manual_") < 0$ &&
$findString(i, "Bugs") < 0$ {
traceLine(i);
}
// if too long, stop the iteration
if $iIndex > 15$ break;
increment(iIndex);
}
cs/DOTNET.html
cs/tests/data/MatchingTest/example.csv.html
Documentation/LastChanges.html
java/JAVAAPI.html
java/data/MatchingTest/example.csv.html
Scripts/Tutorial/GettingStarted/defaultDocumentation.html
WebSite/AllDownloads.html
WebSite/examples/basicInformation.html
WebSite/highlighting/basicInformation.html
WebSite/repository/highlighting.html
WebSite/repository/JEdit/Entity.java.cwt.html
WebSite/serewin/ExempleIllustre.html
WebSite/tutorials/DesignSpecificModeling/tutorial.html
WebSite/tutorials/DesignSpecificModeling/highlighting/demo.cws.html
WebSite/tutorials/overview/tinyDSL_spec.html
WebSite/tutorials/overview/scripts2HTML/CodeWorker_grammar.html
// file "Documentation/SelectSample.cws":
local a;
pushItem a.b;
pushItem a.b#back.c = "01";
pushItem a.b#back.c = "02";
pushItem a.b#back.c = "03";
pushItem a.b;
pushItem a.b#back.c = "11";
pushItem a.b#back.c = "12";
pushItem a.b#back.c = "13";
pushItem a.b;
pushItem a.b#back.c = "21";
pushItem a.b#back.c = "22";
pushItem a.b#back.c = "23";
select i in a.b[].c[] {
traceLine("i = "+ i);
}
i = 01
i = 02
i = 03
i = 11
i = 12
i = 13
i = 21
i = 22
i = 23
exit -1;
// file "Documentation/FinallySample.cws":
1 function f(v : value) {
2 traceLine("BEGIN f(v)");
3 finally {
4 traceLine("END f(v)");
5 }
6 // the body of the function, with more than
7 // one way to exit the function, for example:
8 if !v return "empty";
9 if v == "1" return "first";
10 if v == "2" return "second";
11 if v == "3" return "third";
12 return "other";
13 }
14
15 traceLine("...f(1) has been executed and returned '" + f(1) + "'");
BEGIN f(v)
END f(v)
...f(1) has been executed and returned 'first'
if doc_language == "C++" {
sType = getCppType(myParameterType);
} else if doc_language == "JAVA" {
sType = getJAVAType(myParameterType);
} else {
error("unrecognized language '" + doc_language + "'");
}
sType = getType<doc_language>(myParameterType);
function getType<"JAVA">(myType : node) {
... // implementation for returning a Java type
}
function getType<"C++">(myType : node) {
... // implementation for returning a C++ type
}
function getType<T>(myType : node) {
... // common implementation for any unrecognized language
}
function f<1>() { return 1; }
function f<N>() { return $N*f<$N - 1$>()$; }
local f10 = f<10>();
if $f10 != 3628800$ error("10! should be worth 3628800");
traceLine("10! = " + f10);
10! = 3628800
function f<"field">(x : node) {
insert x.field = "field";
f<"fiel">(x); // cut the last character
}
//a synonym of f<"">(x : node), terminal condition for recusive calls
function f(x : node) {/*does nothing*/}
function f<T>(x : node) {{
// '{{' announces a template-based script, which
// will generate the correct implementation during the instantiation
insert x.@T@ = "@T@";
f<"@T.rsubString(1)@">(x);
@
// '}}' announces the end of the template-based script
}}
f<"field">(project);
traceObject(project);
Tracing variable 'project':
field = "field"
fiel = "fiel"
fie = "fie"
fi = "fi"
f = "f"
End of variable's trace 'project'.
readonlyHook(sFilename) {
if !getProperty("SSProjectFolder") || !getProperty("SSWorkingFolder") || !getProperty("SSExecutablePath") || !getProperty("SSArchiveDir") {
traceLine("WARNING: properties 'SSProjectFolder' and 'SSWorkingFolder' and 'SSExecutablePath' and 'SSArchiveDir' should be passed to the command line for checking out read-only files from Source Safe");
} else {
if startString(sFilename, getProperty("SSWorkingFolder")) {
local sourceSafe;
insert sourceSafe.fileName = sFilename;
generate("SourceSafe.cwt", sourceSafe, getEnv("TMP") + "/SourceSafe.bat");
if sourceSafe.isOk {
putEnv("SSDIR", getProperty("SSArchiveDir"));
traceLine("checking out '" + sFilename + "' from Source Safe archive '" + getProperty("SSArchiveDir") + "'");
local sFailed = system(getEnv("TMP") + "/SourceSafe.bat");
if sFailed {
traceLine("Check out failed: '" + sFailed + "'");
}
}
} else {
traceLine("Unable to check out '" + sFilename + "': working folder starting with '" + getProperty("SSWorkingFolder") + "' expected");
}
}
}
| Argument | Type | Description |
| filename | string | The argument name that the user chooses for
passing the file name to the body of the hook. |
| position | int | The argument name that the user chooses for
passing a position where a difference occurs between the new
generated version of the file and the precedent one. If the files don't have the same size, the position is worth -1. |
| creation | boolean | The argument name that the user chooses for
passing whether the file is created or updated. The argument is worth true if the file doesn't exist yet. |
writefileHook(sFilename, iPosition, bCreation) {
if bCreation {
traceLine("Creating file '" + sFilename + "'!");
} else {
traceLine("Updating file '" + sFilename + "', difference at " + iPosition + "!");
}
return true;
}
| Argument | Type | Description |
| sClauseName | string | The name of the non-terminal. |
| localScope | tree | The scope of parameters used into the production rule. |
| Argument | Type | Description |
| sClauseName | string | The name of the non-terminal. |
| localScope | tree | The scope of local variables and parameters used into the production rule. |
| bSuccess | boolean | Whether the resolution of the production rule has succeeded or not. |
local list;
local iIndex = 4;
delay while isPositive(decrement(iIndex)) {
pushItem list = "element " + iIndex;
traceLine("creating node '" + list#back + "'");
}
traceLine("time of execution = " + getLastDelay() + " seconds");
creating node 'element 3'
creating node 'element 2'
creating node 'element 1'
time of execution = 0.000036282342017391922 seconds
| Category interpreter | Function for running a CodeWorker script |
| autoexpand | Expands a file on markups, following the directives self-contained in the file. |
| executeString | Executes a script given in a string. |
| executeStringQuiet | Interprets a string as a script and returns all traces intended to the console. |
| expand | Expands a file on markups, following the directives of a template-based script. |
| extendExecutedScript | Extend the current executed script dynamically with the content of the string. |
| generate | Generates a file, following the directives of a template-based script. |
| generateString | Generates a string, following the directives of a template-based script. |
| parseAsBNF | Parses a file with a BNF script. |
| parseFree | Parses a file with an imperative script. |
| parseFreeQuiet | Parses a file with an imperative script, reroute all console messages and returns them as a string. |
| parseStringAsBNF | Parses a string with a BNF script. |
| traceEngine | Displays the state of the interpreter. |
| translate | Performs a source-to-source translation or a program transformation. |
| translateString | Performs a source-to-source translation or a program transformation on strings. |
| Category string | Functions for handling strings |
| charAt | Returns the characters present at a given position of a string. |
| completeLeftSpaces | Completes a string with spaces to the left so that it reaches a given size. |
| completeRightSpaces | Completes a string with spaces to the right so that it reaches a given size. |
| composeAdaLikeString | Converts a sequence of characters to a Ada-like string without double quote delimiters. |
| composeCLikeString | Converts a sequence of characters to a C-like string without double quote delimiters. |
| composeHTMLLikeString | Converts a sequence of characters to an HTML-like text |
| composeSQLLikeString | Converts a sequence of characters to a SQL-like string without single quote delimiters. |
| coreString | Extracts the core of a string, leaving the beginning and the end. |
| countStringOccurences | How many occurences of a string to another. |
| cutString | Cuts a string at each separator encountered. |
| endString | Compares the end of the string. |
| endl | Returns an end-of-line, depending on the operating system. |
| equalsIgnoreCase | Compares two strings, ignoring the case. |
| executeString | Executes a script given in a string. |
| executeStringQuiet | Interprets a string as a script and returns all traces intended to the console. |
| findFirstChar | Returns the position of the first character amongst a set, encountered into a string. |
| findLastString | Returns the position of the last occurence of a string to another. |
| findNextString | Returns the next occurence of a string to another. |
| findString | Returns the first occurence of a string to another. |
| generateString | Generates a string, following the directives of a template-based script. |
| joinStrings | Joins a list of strings, adding a separator between them. |
| leftString | Returns the beginning of a string. |
| lengthString | Returns the length of a string. |
| midString | Returns a substring starting at a point for a given length. |
| parseStringAsBNF | Parses a string with a BNF script. |
| repeatString | Returns the concatenation of a string repeated a few times. |
| replaceString | Replaces a substring with another. |
| replaceTabulations | Replaces tabulations with spaces. |
| rightString | Returns the end of a string. |
| rsubString | Returns the left part of a string, ignoring last characters. |
| startString | Checks the beginning of a string. |
| subString | Returns a substring, ignoring the first characters. |
| toLowerString | Converts a string to lowercase. |
| toUpperString | Converts a string to uppercase. |
| trim | Eliminates heading and trailing whitespaces. |
| trimLeft | Eliminates the leading whitespaces. |
| trimRight | Eliminates the trailing whitespaces. |
| truncateAfterString | Special truncation of a string. |
| truncateBeforeString | Special truncation of a string. |
| Category array | Functions handling arrays |
| findElement | Checks the existence of an entry key in an array. |
| findFirstSubstringIntoKeys | Returns the first entry key of an array, containing a given string. |
| findNextSubstringIntoKeys | Returns the next entry key of an array, containing a given string. |
| getArraySize | Returns the number of items in an array. |
| insertElementAt | Inserts a new element to a list, at a given position. |
| invertArray | Inverts the order of items in an array. |
| isEmpty | Checks whether a node has items or not. |
| removeAllElements | Removes all items of the array. |
| removeElement | Removes an item, given its entry key. |
| removeFirstElement | Removes the first item of the array. |
| removeLastElement | Removes the last item of the array. |
| Category node | Functions handling a node |
| clearVariable | Removes the subtree and assigns an empty value. |
| equalTrees | Compares two subtrees. |
| existVariable | Checks the existence of a node. |
| getVariableAttributes | Extract all attribute names of a tree node. |
| removeRecursive | Removes a given attribute from the subtree. |
| removeVariable | Removes a given variable. |
| slideNodeContent | Moves the subtree elsewhere on a branch. |
| sortArray | Sort an array, considering the entry keys. |
| Category iterator | Functions handling an iterator |
| createIterator | Creates an iterator pointing to the beginning of a list. |
| createReverseIterator | Creates a reverse iterator pointing to the end of a list. |
| duplicateIterator | Duplicates an iterator. |
| first | Returns true if the iterator points to the first item. |
| index | Returns the position of an item in a list. |
| key | Returns the entry key of the item pointed to by the iterator. |
| last | Returns true if the iterator points to the last item. |
| next | Move an iterator to the next item of a list. |
| prec | Move an iterator to the precedent item of a list. |
| Category file | Functions handling files |
| appendFile | Writes the content of a string to the end of a file |
| canonizePath | Builds an absolute path, starting to the current directory. |
| changeFileTime | Changes the access and modification times of a file. |
| chmod | Changes the permissions of a file. |
| copyFile | Copies a file. |
| copyGenerableFile | Copies a file with protected areas or expandable markups, only if the hand-typed code differs between source and destination. |
| copySmartFile | Copies a file only if the destination differs. |
| createVirtualFile | Creates a transient file in memory. |
| createVirtualTemporaryFile | Creates a transient file in memory, CodeWorker choosing its name. |
| deleteFile | Deletes a file on the disk. |
| deleteVirtualFile | Deletes a transient file from memory. |
| existFile | Checks the existence of a file. |
| existVirtualFile | Checks the existence of a transient file, created in memory. |
| exploreDirectory | Browses all files of a directory, recursively or not. |
| fileCreation | Returns the creation date of a file. |
| fileLastAccess | Returns the last access date of a file. |
| fileLastModification | Returns the last modification date of a file. |
| fileLines | Returns the number of lines in a file. |
| fileMode | Returns the permissions of a file. |
| fileSize | Returns the size of a file. |
| getGenerationHeader | Returns the comment to put into the header of generated files. |
| getShortFilename | Returns the short name of a file |
| indentFile | Indents a file, depending on the target language. |
| loadBinaryFile | Loads a binary file and stores each byte in a hexadecimal representation of 2 digits. |
| loadFile | Returns the content of a file or raises an error if not found. |
| loadVirtualFile | Returns the content of a transient file or raises an error if not found. |
| pathFromPackage | Converts a package path to a directory path. |
| relativePath | Returns the relative path, which allows going from a path to another. |
| resolveFilePath | Gives the location of a file with no ambiguity. |
| saveBinaryToFile | Saves binary data to a file. |
| saveToFile | Saves the content of a string to a file |
| scanDirectories | Explores a directory, filtering filenames. |
| scanFiles | Returns a flat list of all filenames matching with a filter. |
| Category directory | Functions handling directories |
| changeDirectory | Changes the current directory (chdir() in C). |
| copySmartDirectory | Copies files of a directory recursively only when destination files differ from source files. |
| createDirectory | Creates a new directory. |
| existDirectory | Check the existence of a directory. |
| exploreDirectory | Browses all files of a directory, recursively or not. |
| getCurrentDirectory | Returns the current directory (getcwd() in C). |
| removeDirectory | Removes a directory from the disk. |
| scanDirectories | Explores a directory, filtering filenames. |
| scanFiles | Returns a flat list of all filenames matching with a filter. |
| Category URL | Functions working on URL transfers (HTTP,...) |
| decodeURL | Decodes an HTTP URL. |
| encodeURL | Encodes an URL to HTTP. |
| getHTTPRequest | Sends an HTTP's GET request. |
| postHTTPRequest | Sends an HTTP's POST request. |
| sendHTTPRequest | Sends an HTTP request. |
| Category datetime | Functions handling date-time |
| addToDate | Change a date by shifting its internal fields days/months/years or time. |
| compareDate | Compares two dates. |
| completeDate | Extends an incomplete date with today characteristics. |
| fileCreation | Returns the creation date of a file. |
| fileLastAccess | Returns the last access date of a file. |
| fileLastModification | Returns the last modification date of a file. |
| formatDate | Changes the format of a date. |
| getLastDelay | Returns the time consumed to execute a statement. |
| getNow | Returns the current date-time. |
| setNow | Fixes the current date-time. |
| Category numeric | Functions handling numbers |
| add | Equivalent admitted writing is $a + b$. |
| ceil | Returns the smallest integer greater that or equal to a number |
| decrement | Equivalent admitted writing is set a = $a - 1$;. |
| div | Equivalent admitted writing is $a / b$. |
| equal | Equivalent admitted writing is $a == b$. |
| exp | Returns the exponential of a value. |
| floor | Returns the largest integer less that or equal to a number |
| increment | Equivalent admitted writing is set a = $a + 1$;. |
| inf | Equivalent admitted writing is $a < b$. |
| isNegative | Equivalent admitted writing is $a < 0$. |
| isPositive | Equivalent admitted writing is $a > 0$. |
| log | Returns the Neperian logarithm. |
| mod | Equivalent admitted writing is $a % b$. |
| mult | Equivalent admitted writing is $a * b$. |
| pow | Raises a number to the power of another. |
| sqrt | Calculates the square root. |
| sub | Equivalent admitted writing is $a - b$. |
| sup | Equivalent admitted writing is $a > b$. |
| Category standard | Classical functions of any standard library |
| UUID | Generates an UUID. |
| error | Raises an error message |
| inputKey | If any, returns the last key pressed on the standard input. |
| inputLine | Wait for the standard input to the console. |
| isIdentifier | Checks whether a string is a C-like identifier or not. |
| isNumeric | Checks whether a string is a floating-point number or not. |
| randomInteger | Generates a pseudorandom number. |
| randomSeed | Changes the seed of the pseudorandom generator. |
| traceLine | Displays a message to the console, adding a carriage return. |
| traceObject | Displays the content of a node to the console. |
| traceStack | Displays the stack to the console. |
| traceText | Displays a message to the console. |
| Category conversion | Type conversion |
| byteToChar | Converts a byte (hexadecimal representation of 2 digits) to a character. |
| bytesToLong | Converts a 4-bytes sequence to an unsigned long integer in its decimal representation. |
| bytesToShort | Converts a 2-bytes sequence to an unsigned short integer in its decimal representation. |
| charToByte | Converts a character to a byte (hexadecimal representation of 2 digits). |
| charToInt | Converts a character to the integer value of the corresponding ASCII. |
| hexaToDecimal | Converts an hexadecimal representation to an integer. |
| hostToNetworkLong | Converts a 4-bytes representation of a long integer to the network bytes order. |
| hostToNetworkShort | Converts a 2-bytes representation of a short integer to the network bytes order. |
| longToBytes | Converts an unsigned long integer in decimal base to its 4-bytes representation. |
| networkLongToHost | Converts a 4-bytes representation of a long integer to the host bytes order. |
| networkShortToHost | Converts a 2-bytes representation of a short integer to the host bytes order. |
| octalToDecimal | Converts an octal representation to a decimal integer. |
| shortToBytes | Converts an unsigned short integer in decimal base to its 2-bytes representation. |
| Category system | Functions relative to the operating system |
| computeMD5 | Computes the MD5 of a string. |
| environTable | Equivalent of environ() in C |
| existEnv | Checks the existence of an environment variable. |
| getEnv | Returns an environment variable, or raises an error if not exist. |
| openLogFile | Opens a log file for logging every console trace. |
| putEnv | Puts a value to an environment variable. |
| sleep | Suspends the execution for millis milliseconds. |
| system | Equivalent to the C function system(). |
| Category command | Relative to the command line |
| compileToCpp | Translates a script to C++. |
| getIncludePath | Returns the include path passed via the option -I. |
| getProperty | Returns the value of a property passed via the option -D. |
| getVersion | Returns the version of the interpreter. |
| getWorkingPath | Returns the output directory passed via option -path. |
| setIncludePath | Changes the option -I while running. |
| setProperty | Adds/changes a property (option -D) while running. |
| setVersion | Gives the version of scripts currently interpreted by CodeWorker. |
| setWorkingPath | Does the job of the option -path. |
| Category generation | Functions relative to generation |
| addGenerationTagsHandler | Adds your own CodeWorker's tags handler |
| autoexpand | Expands a file on markups, following the directives self-contained in the file. |
| expand | Expands a file on markups, following the directives of a template-based script. |
| extractGenerationHeader | Gives the generation header of a generated file, if any. |
| generate | Generates a file, following the directives of a template-based script. |
| generateString | Generates a string, following the directives of a template-based script. |
| getCommentBegin | Returns the current format of a comment's beginning. |
| getCommentEnd | Returns the current format of a comment's end. |
| getGenerationHeader | Returns the comment to put into the header of generated files. |
| getTextMode | Returns the text mode amongst "DOS", "UNIX" and "BINARY". |
| getWriteMode | Returns how text is written during a generation (insert/overwrite). |
| listAllGeneratedFiles | Gives the list of all generated files. |
| removeGenerationTagsHandler | Removes a custom generation tags handler |
| selectGenerationTagsHandler | Selects your own CodeWorker's tags handler for processing generation tasks |
| setCommentBegin | Changes what a beginning of comment looks like, perhaps before expanding a file. |
| setCommentEnd | Changes what an end of comment looks like, perhaps before expanding a file. |
| setGenerationHeader | Specifies a comment to put at the beginning of every generated file. |
| setTextMode | "DOS", "UNIX" or "BINARY" |
| setWriteMode | Selects how to write text during a generation (insert/overwrite). |
| translate | Performs a source-to-source translation or a program transformation. |
| translateString | Performs a source-to-source translation or a program transformation on strings. |
| Category parsing | Functions relative to scanning/parsing |
| parseAsBNF | Parses a file with a BNF script. |
| parseFree | Parses a file with an imperative script. |
| parseFreeQuiet | Parses a file with an imperative script, reroute all console messages and returns them as a string. |
| parseStringAsBNF | Parses a string with a BNF script. |
| translate | Performs a source-to-source translation or a program transformation. |
| translateString | Performs a source-to-source translation or a program transformation on strings. |
| Category socket | Socket operations |
| acceptSocket | Listens for a client connection and accepts it. |
| closeSocket | Closes a socket descriptor. |
| createINETClientSocket | Creates a stream socket connected to the specified port and IP address. |
| createINETServerSocket | Creates a server stream socket bound to a specified port. |
| receiveBinaryFromSocket | Reads binary data from the socket, knowing the size. |
| receiveFromSocket | Reads text or binary data from a socket. |
| receiveTextFromSocket | Reads text from a socket, knowing the size. |
| sendBinaryToSocket | Writes binary data to a socket. |
| sendTextToSocket | Writes text to a socket. |
| Category unknown | Various types of function |
| loadProject | Loads a parse tree previously saved thanks to saveProject(). |
| not | The boolean negation, equivalent to !a. |
| produceHTML | |
| saveProject | Saves a parse tree to XML or to a particular text format. |
| saveProjectTypes | Factorizes nodes of the projects to distinguish implicit types for node and saves it to XML. |
| Parameter | Type | Description |
| serverSocket | int | a server socket previously created via createINETServerSocket() |
| Parameter | Type | Description |
| left | double | left arithmetic member |
| right | double | right arithmetic member |
local a = 3.2;
traceLine(a + " + 4.5 = " + add(a, "4.5"));
traceLine(a + " + 2.8 = " + add(a, 2.8) + " <- integer value");
3.2 + 4.5 = 7.7
3.2 + 2.8 = 6 <- integer value
| Parameter | Type | Description |
| key | string | designates the handler |
| reader | script<BNF> | extended-BNF script of the reader |
| writer | script<pattern> | template-based script of the writer |
| Parameter | Type | Description |
| date | string | the date to change |
| format | string | the format to apply on the reading of the shifting argument |
| shifting | string | the offset values to apply on the date, whose meanings are known by the offset argument |
traceLine("Substract 2 months and add 20 hours to the current date-time:");
local newDate = addToDate(getNow(), "%m,%H", "-2,20");
traceLine("one manner: " + getNow() + " -> " + newDate);
newDate = addToDate(getNow(), "%m%H", "-0220");
traceLine("another manner: " + getNow() + " -> " + newDate);
Substract 2 months and add 20 hours to the current date-time:
one manner: 01may2010 20:42:00.500 -> 02mar2010 16:42:00.500
another manner: 01may2010 20:42:00.500 -> 02mar2010 16:42:00.500
| Parameter | Type | Description |
| filename | string | name of the file to append |
| content | string | sequence of characters to write at the end of the file |
| Parameter | Type | Description |
| outputFileName | string | the existing file to expand |
| this | treeref | the current node that will be accessed with this variable |
| Parameter | Type | Description |
| bytes | string | a 4-bytes representation of an unsigned long integer (host bytes order) |
traceLine("bytesToLong('FFFFFFFF') = '" + bytesToLong("FFFFFFFF") + "'");
bytesToLong('FFFFFFFF') = '4294967295'
| Parameter | Type | Description |
| bytes | string | a 2-bytes representation of an unsigned short integer (host bytes order) |
traceLine("bytesToShort('FFFF') = '" + bytesToShort("FFFF") + "'");
bytesToShort('FFFF') = '65535'
| Parameter | Type | Description |
| byte | string | an hexadecimal number of 2 digits exactly |
traceLine("byteToChar('20') = '" + byteToChar("20") + "'");
traceLine("byteToChar('61') = '" + byteToChar("61") + "'");
byteToChar('20') = ' '
byteToChar('61') = 'a'
| Parameter | Type | Description |
| path | string | the path to canonize |
traceLine("current directory = '" + getCurrentDirectory() + "'");
local sPath = "WebSite/downloads/CodeWorker.zip";
traceLine(" path = '" + sPath + "'");
traceLine(" result = '" + canonizePath(sPath) + "'");
local sCurrentDirectory = getCurrentDirectory();
changeDirectory(sCurrentDirectory + "Documentation");
traceLine("current directory = '" + getCurrentDirectory() + "'");
set sPath = "../Scripts/Tutorial/GettingStarted/tiny.html";
traceLine(" path = '" + sPath + "'");
traceLine(" result = '" + canonizePath(sPath) + "'");
changeDirectory(sCurrentDirectory);
traceLine("current directory = '" + getCurrentDirectory() + "'");
set sPath = ".";
traceLine(" path = '" + sPath + "'");
traceLine(" result = '" + canonizePath(sPath) + "'");
current directory = 'C:/Projects/generator/'
path = 'WebSite/downloads/CodeWorker.zip'
result = 'c:/Projects/generator/WebSite/downloads/CodeWorker.zip'
current directory = 'C:/Projects/generator/Documentation/'
path = '../Scripts/Tutorial/GettingStarted/tiny.html'
result = 'c:/Projects/generator/Scripts/Tutorial/GettingStarted/tiny.html'
current directory = 'C:/Projects/generator/'
path = '.'
result = 'c:/Projects/generator'
| Parameter | Type | Description |
| number | double | the floating-point number to ceil |
traceLine("ceil(5.369e+1) = " + ceil(5.369e1));
ceil(5.369e+1) = 54
| Parameter | Type | Description |
| path | string | path name of the directory |
traceLine("current directory = '" + getCurrentDirectory() + "'");
local sOldDirectory = getCurrentDirectory();
local sNewDirectory = sOldDirectory + "Documentation";
traceLine("call to changeDirectory('" + sNewDirectory + "')");
changeDirectory(sNewDirectory);
traceLine("new current directory = '" + getCurrentDirectory() + "'");
changeDirectory(sOldDirectory);
current directory = 'C:/Projects/generator/'
call to changeDirectory('C:/Projects/generator/Documentation')
new current directory = 'C:/Projects/generator/Documentation/'
| Parameter | Type | Description |
| filename | string | name of the file to set |
| accessTime | string | date-time of the last access |
| modificationTime | string | date-time of the last modification |
local oldAccessTime = fileLastAccess("readme.txt");
local oldModifTime = fileLastModification("readme.txt");
traceLine("old modification time of 'readme.txt' = '" + oldModifTime + "'");
if $changeFileTime("readme.txt", getNow(), getNow()) < 0$
error("'changeFileTime()' has failed!");
local newModifTime = fileLastModification("readme.txt");
traceLine("new modification time of 'readme.txt' = '" + newModifTime + "'");
// put the same times as before calling the example:
if $changeFileTime("readme.txt", oldAccessTime, oldModifTime) < 0$
error("'changeFileTime()' has failed!");
old modification time of 'readme.txt' = '02may2008 06:51:36'
new modification time of 'readme.txt' = '01may2010 20:42:00'
| Parameter | Type | Description |
| text | string | a sequence of characters |
| index | int | the index of the character to extract from text |
local sText = "I have but one lamp by which my feet are guided, and that is the lamp of experience. (P. Henry)";
traceLine("charAt('" + sText + "', 2) = '" + charAt(sText, 2) + "' <- index = 2 gives the third character of the string");
charAt('I have but one lamp by which my feet are guided, and that is the lamp of experience. (P. Henry)', 2) = 'h' <- index = 2 gives the third character of the string
| Parameter | Type | Description |
| char | string | a character |
traceLine("charToByte('A') = '" + charToByte("A") + "'");
traceLine("charToByte('\\n') = '" + charToByte("\n") + "'");
charToByte('A') = '41'
charToByte('\n') = '0A'
| Parameter | Type | Description |
| char | string | a string containing just one char |
traceLine("charToInt('A') = " + charToInt("A") + " <- ASCII code of 'A'");
charToInt('A') = 65 <- ASCII code of 'A'
| Parameter | Type | Description |
| filename | string | file to which change the permission setting |
| mode | string | permission setting as a concatenation of 'R' and/or 'W' and/or 'X' |
local bSuccess = chmod("Documentation/CodeWorker.tex", "RW");
if !bSuccess error("file 'Documentation/CodeWorker.tex' not found!");
traceLine("R + W permitted on file 'Documentation/CodeWorker.tex'");
R + W permitted on file 'Documentation/CodeWorker.tex'
| Parameter | Type | Description |
| node | treeref | the node to clear |
local myNode = "the value";
insert myNode.a1 = "attribute 1";
insert myNode.a2 = "attribute 2";
insert myNode.array["1"] = "node 1";
insert myNode.array["2"] = "node 2";
traceObject(myNode);
traceLine("-- the variable 'myNode' is cleared:");
clearVariable(myNode);
traceObject(myNode);
Tracing variable 'myNode':
"the value"
a1 = "attribute 1"
a2 = "attribute 2"
array
array["1", "2"]
End of variable's trace 'myNode'.
-- the variable 'myNode' is cleared:
Tracing variable 'myNode':
End of variable's trace 'myNode'.