//************************************************************************** // Translate the HTML documentation of the C++ API // // // This script generates an HTML file for CodeWorker while the parsing of // the corresponding file coming from the C++ API. // // It illustrates how CodeWorker proceeds for program transformation // (translation where the source and the target languages are the same). //************************************************************************** // Return the class name and the function name (if any, it could be the // description of a class), deduced of the HTML file name. function getClassFunctionName(sClassName : node, sFunctionName : node) { sClassName = rsubString(getShortFilename(getInputFilename()), 4); sFunctionName = sClassName.subString($sClassName.findString('.') + 1$); sClassName = sClassName.rsubString($sFunctionName.length() + 1$); } // The header BNF production rule of the grammar (entry point of the grammar). // As the transformation is very straight-forward and because of lazyness, the // whole transformation is written into this unique rule. HTMLdoc ::= // ignore whitespaces and carriage returns between BNF terminals and // non-terminals #ignore(blanks) // means that the rest of the sequence MUST NOT fail; if so, a detailed // error message interrupts the parsing #continue // what you read if what you generate: // the input file is automatically copied to the output file, while parsing #implicitCopy // jump directly to the version number of Chart Director ->"
ChartDirector Ver" // be sure the version number has the expected format #readInteger ['.' #continue #readInteger]* [ // desactivate the implicit copy: // we don't copy anymore what is read to the output file #explicitCopy "(C++ Edition)" // write '(CodeWorker Edition)' to the output file, in place of // '(C++ Edition)' => {@(CodeWorker Edition)@} ] "
" // at least one template must be recognized, but we could find more. // Each template gives rise to a specific translation. [ // jump to one of the following template alternatives ->[ // First template: it detects an embedded C++ example "[The following code is available in \"" #continue // must be valid up to the end of the sequence // don't copy the input file to the output file automatically // anymore #explicitCopy "cppdemo/" // the local variable 'sExample' contains the name of the C++ example #readIdentifier:sExample // replace the example path by the one for CodeWorker => {@cwdemo/@sExample@".]@endl()@@} // the following terminal is read, but certainly not copied! // (implicit copy still desactivated) "\". A MFC version of the code is available in \"mfcdemo\" (Windows edition only).]" [ // what you read is what you write, just for this block #implicitCopy "" ] // load the CodeWorker script and convert the special characters for HTML. // Close it with the tag '' that will be ignored 2 lines below => {@@composeHTMLLikeString(loadFile(getWorkingPath() + "cwdemo/" + sExample + '/' + sExample + ".cws"))@@} // ignore the C++ example upto the tag '' included ->"" // what you read is what you write #implicitCopy " |
Usage
" #continue "Arguments
" #continue "Argument | " // add a column into the table, indicating the type of the parameter => {@Type | @} "Default | Description | " "|
---|---|---|---|---|
" ->" | " => if $params.size() == iParamSize$ { // we have found a prototype of this function: // we populate the column added for the type @@getHTMLType(params#[iParam].type)@ | @ } else { // manifestly, we didn't find a prototype: no type @@ } " | " [ // check that we have found a prototype #check($params.size() == iParamSize$) // if the default value of the argument is a HTML link, // and if the type is an enum, we change the presentation: // an enum is seen as a constant string in the CodeWorker binding // of Chart Director (it's a choice!). " {@"@} [~""]* => {@"@} ]? ]? ->" | " "" ->" | " "Method | Inherited | Description | " #continue "" [ // while reading the first column (name of the method), we extract the // class name and the method name from the HTML link. If they don't // exist in the parse tree, we don't change the presentation. #explicitCopy "
" "" | ||||
" #continue " sFunctionName = sFunctionName.rsubString(1); ]? ->'>' // here is the change => {@CHART::@sFunctionName@@} [ #explicitCopy [~""]* ] ->"" " | " ->" | " "" ->" | " "
Constant | Value | Description" #continue [ " |
---|---|---|
" => {@"@} [~[" | " | ""]]* => {@"@} [~[" |
Title | Description | " "
---|