| # Repository of Scripts

### CONTENT Overview Why use this tool? Getting Started (47kb) Documentation Tutorials Wiki Repository of scripts XML Program transformation source-to-source translation CGI scripts Download Related links |
Pending themes
C++ / ISO 14882 parser
State | Description
in progress | BNF-parsing script of the C++ grammar to be able to extract the AST and to provide smart and powerful C++ source file transformation.
UML / Rational ROSE 98
State | Description
pending | BNF-parsing script of a `"*.mdl"` file generated by Rational ROSE for extracting class diagrams to start.
Modeling language
State | Description
pending | BNF-parsing script of a tailorable modeling language and some template-based scripts to offer useful transversal features for the software infrastructure.
Repository
XML
This section proposes some scripts to work on XML, which isn't the native manner to represent the knowledge in CodeWorker but that cannot be ignored as a very convenient and widely admitted format for expressing specifications.
| XML parser
A script for scanning a XML file in general (with no DTD) and for populating a parse tree of CodeWorker that conforms to the logic structure of the XML hierarchy.
| Script | Description
| XMLparser.cwp | the production rule XML_DOCUMENT scans and parses XML files in general. The parse tree conforms to the following logic structure that matches to the XML one exactly: name-of-XML-element[]: all elements that share the same parent node and the same name name-of-XML-element are put into an array of nodes whose name is the name of the XML element. If the element is alone, the structure doesn't change and the array contains the element only. name-of-XML-attribute: the value of the attribute is assigned to a folder of the parse tree, which stands as a child of the owner element and whose name is the name of the attribute. Please note that an XML identifier admits '.' and '-' characters, which are rejected by CodeWorker in an identifier. So, these characters are degenerated in underscores.
| Example | Description
| XMLparser-example1.cws | Parses the XML file `"cdcatalog.xml"` and then generates a HTML presentation of data in `"XMLparser-cdcatalog.html"` following the template `"cdcatalog.cwt"`. Input files: examples/cdcatalog.xml, examples/cdcatalog.cwt. output files: examples/cdcatalog.html.
| DTD parser
A script for building the AST (Abstract Syntactic Tree) of a DTD file. This AST might be used for translating from a DTD to a template-based script or for any other application.
| Script | Description
| DTDparser.cwp | Parses a `DTD` (Document Type Description) file. The parse tree conforms to the following logic structure: comment (optional) holds the last comment block found into the DTD before the first DTD element, if any. This comment is interpreted as an explanation on what the DTD is for. listOfElements[] contains the list of all `"<!ELEMENT"` nodes encountered: comment (optional) holds the comment block that stands just before the element description in the DTD, if any. category (optional) is worth `"EMPTY"` or `"ANY"`. composite (present if and only if category doesn't exist) multiplicity (optional) is worth '?' or '*' or '+' nodes put into the array (composite[]): operator (present on each node, except the last one) is worth ',' or '|' constant (one and only one field amongst constant and element and composite) is worth "#PCDATA" element name of an element multiplicity (optional) is worth '?' or '*' or '+' composite recursive structure listOfAttributes[] contains the list of all attributes belonging to the element (one and only one amongst type, listOfEnums and constant): type is worth `"CDATA"` or `"ID"` or `"IDREF"` or `"IDREFS"` or `"NMTOKEN"` or `"NMTOKENS"` or `"ENTITY"` or `"ENTITIES"` or `"NOTATION"` listOfEnums list of enumerated values constant a constant value value (optional, constant must be populated) is worth `"#IMPLIED"` or `"#REQUIRED"` or `"DEFAULT"` or `"FIXED"` listOfEntities[] contains the list of all `"<!ENTITY"` nodes encountered. comment (optional) holds the comment block that stands just before the entity description in the DTD, if any. external (optional) is worth `"SYSTEM"` constant is the value of the entity after resolution of references to other entities. Note that the grammar doesn't handle entities correctly yet. If you need it or if you encounter some bugs, please send an email to codeworker@free.fr and your request will be taken into account as fast as possible.
| Example | Description
| DTDtoBNF-example1.cws | Parses the DTD of the `ejb_jar` descriptor as provided by `Sun Microsystems, Inc` and generates a BNF-parsing script for parsing and validating any kind of XML `ejb_jar` files. Input files: examples/ejb-jar_2_0.dtd. output files: examples/ejb-jar_2_0-parser.cwp.
| XSL parser
A script for building the AST (Abstract Syntactic Tree) of a XSL file. This AST might be used for translating from XSL to TL (Template Language of Craig Cleaveland) or to a template-based script or for any other application.
| Script | Description
| XSLparser.cwp | Parses an XSL file, building a parse tree that conforms to the following logic structure: It recognizes some XSL elements (not all yet), such as: `xsl:template` `xsl:foreach` `xsl:value-of` `xsl:sort` `xsl:when` `xsl:choose` `xsl:otherwise` XPath is parsed completely according to the specifications for `XSLT 1.0`. If you encounter bugs or limitations, please send a mail to codeworker@free.fr.
Program transformation
A program transformation changes the source code, to do optimizations, code intrusion or rewriting.
| C++ profiling
Here is a coding pattern that enables to include source code for profiling in the C++ function bodies. This transformation doesn't require to construct the AST of the C++ source code.
| Script | Description
| RawProfilingLeader.cws | Leader script that drives the intrusion of profiling code in C++ source files. This is called a raw profiling, because it doesn't pretend to offer a smart and efficient profiling mechanism. It is more like an illustration of what is possible as a program transformation. Two properties must be passed on the command line: SOURCES gives the file masks of C++ bodies to select for the transformation. If more than one mask, one cancatenates them, separated by a semi-comma. RAW_PROFILING_DIR provides the directory where to generate the profiling module. The profiling module manages the time spent in each profiled function and how many times they have been called. The profiling module is implemented in files `"RawProfiling.h"` and `"RawProfiling.cpp"`.
| RawProfilingCppTransformation.cwp | Script that operates the transformation of a C++ source file to insert profiling code in the body of functions. Here, no parsing is processed for recognizing the signature of functions and the body. So, some troubles might appear if a `#define` macro describes a part or the whole of the function. One activates the profiling by setting the preprocessor definition RAW_PROFILING at compile-time (`-D RAW_PROFILING` on the command line of the C++ compiler). To make it simple, the header of the profiling module is inserted after the first `#include` encountered. It may cause some troubles if the first include is put in a conditional preprocessing block (`#ifdef WIN32` ... `#endif`/`#else`). The body of the function starts by incrementing its assigned counter held by the profiling module and by timing the visit of the controlled sequence. Note that the transformation can be applied more than once: the second pass will not affect the source file.
| RawProfilingCpp.cwt | This script generates the mplementation of the profiling module. Each function scanned for the profiling has both a counter and a chronograph assigned. The chronograph holds the total time spent in the function. The display of result is the simplest that may exist: functions are listed with the number of calls and the total time (`RawProfiling::displayResults()`). The file to generate is `"RawProfiling.cpp"` and will be put in `RAW_PROFILING_DIR`.
| RawProfilingHpp.cwt |
| File | Description
| RawProfiling.h | Header of the profiling module. It must be expanded by the template-based script called `"RawProfilingHpp.cwt"`.
| Example | Description
| RawProfiling-example1.cws | To illustrate the profiling intrusion of code, one distinguish the C++ sources before and after the transformation. C++ source files before transformation are postfixed by "_before.*". C++ source files after transformation are postfixed by "_after.*". In the real life, this distinction has no sense and one modifies the C++ source files directly. But in all cases, the file `"repository/RawProfiling.h"` must be copied in the directory used for the profiling module. The file `"examples/RawProfiling_main.cpp"` computes the Towers of Hanoi. Then, it writes the results of the profiling in a HTML file. Input files: examples/RawProfiling_before.cpp. quoted files: examples/RawProfiling_example1.h, examples/RawProfiling_main.cpp. output files: examples/RawProfiling_after.cpp, examples/RawProfiling.html.
source-to-source translation
A source-to-source translation consists on translating a text from a format to another. It may require a first pass to extract the parse tree of the text or may construct the target on the fly.
| CodeWorker script to HTML
Translates any CodeWorker script to HTML, highlighting the code according to the syntax and linking keywords to the online-documentation.
| Script | Description
| CWscript2HTML.cwp | It takes in charge of translating any CodeWorker script to HTML. The source file is highlighted and keywords plus particular symbols of the language are linked to the online-documentation. Note that `this.docURL` designates the URL or the directory where both the CSS and the HTML documentation of CodeWorker are stored. If not populated, it will resolve links from the directory where is the target HTML file. Don't forget to end the URL or directory with a trailing slash. If `this.includeCSS` is set to a path, the styles are included into the HTML file from the path, rather that being linked to a file while browsing. To highlight any script, type: `CodeWorker -translate CWscript2HTML.cwp <CW-script.cw> <CW-script.html>` to consider that the documentation and the CSS are in the same directory, and: `CodeWorker -translate CWscript2HTML.cwp <CW-script.cw> <CW-script.html> -insert docURL HTML-doc-URL` otherwise.
| CodeWorker_grammar.cwp | Here is the complete grammar of the CodeWorker's scripting language. It is expressed in the extended-BNF dialect of CodeWorker, so has the advantage of running under CodeWorker for scanning scripts, and has the original feature to be auto-descriptive.
| DTD to BNF-parsing script
Translating a DTD to a CodeWorker script isn't a straightforward process, so the translation requires first to extract a parse tree of the DTD before generating the corresponding BNF-parsing script.
| Script | Description
| DTDparser.cwp | see source-to-source translation::DTD to BNF-parsing script
| DTDtoBNF.cwt | Walks through the AST of a DTD file parsed previously, and generates a CodeWorker script for parsing and validating any XML file that conforms to the DTD. If you encounter some bugs, please send a mail to codeworker@free.fr.
| Example | Description
| DTDtoBNF-example1.cws | Parses the DTD of the `ejb_jar` descriptor as provided by `Sun Microsystems, Inc` and generates a BNF-parsing script for parsing and validating any kind of XML `ejb_jar` files. Input files: examples/ejb-jar_2_0.dtd. output files: examples/ejb-jar_2_0-parser.cwp.
| XSL to template-based script
Translating a XSL file to a CodeWorker script isn't a straightforward process, so the translation requires first to extract a parse tree of the XSL file before generating the corresponding template-based script. Executing the script will operate the corresponding XSL transformation.
| Script | Description
| XSLparser.cwp | see source-to-source translation::XSL to template-based script
| XSLtoCodeWorker.cwt |
| Example | Description
| XSLtoBNF-example1.cws | Parses a XSL file and generates the corresponding template-based script. Then, it executes the script on the XML file for transforming it in a HTML file. This example works on a CD catalog, which is copied from `W3School` integrally. Input files: examples/cdcatalog.xsl, examples/cdcatalog.xml. output files: examples/cdcatalog.cwt, examples/cdcatalog.html.
CGI scripts
CodeWorker is able to run as a CGI program since version `2.10`. One presents some little use-cases for illustrating the advantage of using CodeWorker on the Web server-side. The scripts encountered below must be copied on the Web server-side, after registration of CodeWorker as attached to the `".cwt"` file extension.
| Basic information
A script for displaying all CGI environment variables and for showing the client request.
| Script | Description
| basicInformation.cwt | This script checks whether CodeWorker is running as a CGI program or as an interpreter. If running in CGI mode, all CGI environment variables are displayed, followed by the attributes/values of the client request, filled into a form and sent via a `POST` or `GET` method. Note that the global array `_REQUEST` contains the list of all attributes of the request, with their values. Example: if the client writes `http://myServer/basicInformation.cwt?country=Finland`, then: `_REQUEST["country"]` is worth `"Finland"` a global variable `country` is declared and is worth `"Finland"`. output files: examples/basicInformation.html.
| Simple hit counter
A script for counting the number of hits by remote host and by date.
| Script | Description
| hitCounter.cwt | It updates the number of hits done on project page. The history saves all remote hosts that have already loaded the page, and keeps the number of hits by date for each remote host. To make it persistent, these data are saved in a file `"hitCounter.txt"`, which is parsed via the script `"hitCounterParser.cwp"`. The file is updated by generating it via the template-based script `"hitCounterUpdate.cwt"`. output files: examples/hitCounter.txt, examples/hitCounter.html.
| hitCounterParser.cwp | Parses the description of all hits done. Format: `hitCounter ::= [remote_host]*` `remote_host ::= "host" hostNameAsString '{' [date_split]* '}'` `date_split ::= DATE numberOfHits` The parse tree: hits: total number of hits hosts[]: list of all remote hosts hits: total number of hits for this remote host dates[]: hits by date for this remote host hits: total number of hits for this remote host at this date dates[]: list of all dates hits: total number of hits for this date
| hitCounterUpdate.cwt | Saves the parse tree conforming to the syntax presented in the BNF-parsing script `"hitCounterParser.cwp"`.
| Remote graph generation
The server generates the `png` class diagram of an object modelling.
| Script | Description
| classDiagram.cwt | It parses an object design (the syntax conforms to `CWML`, an object modelling language that CodeWorker proposes by default) and generates a class diagram as a `png` picture. GraphViz is an open source graph drawing software, called here for building the class diagram. It requires the description of the graph, generated in `classDiagram.txt` by the script `classDiagramGraphviz.cwt`. This example cannot work without GraphViz installed on the Web server. Note that one saves the object design in a virtual file (function `createVirtualTemporaryFile()`). It avoids saving the design of the client in a temporary physical file before parsing it. quoted files: examples/classDiagram.txt. output files: examples/classDiagramResult.html.
| classDiagramGraphViz.cwt | It generates an input file for asking GraphViz to draw the class diagram of an object design. The parse tree of the object design must conform to the logic structure of `CWML`, the default modelling language proposed by CodeWorker as illustration. Please refer to the documentation of GraphViz to understand more about the syntax of the graph description.
| CWML.cwp | This script parses an object modelling file that conform to `CWML`, a modelling language proposed by CodeWorker as an illustration. `package_declaration ::= "package" package_path '{' package_body '}'` `package_body ::= package_declaration | class_declaration | service_declaration`
CodeWorker is maintained by Cedric Lemaire. Please send a mail to Submit a bug or feature