highlight::CodeGenerator Class Reference

Base class for parsing. Works similar to a Turing machine. More...

Inheritance diagram for highlight::CodeGenerator:

highlight::AnsiGenerator highlight::HtmlGenerator highlight::LatexGenerator highlight::TexGenerator highlight::XmlGenerator highlight::XslFoGenerator highlight::XHtmlGenerator List of all members.

Public Member Functions

ParseError generateFile (const string &inFileName, const string &outFileName)
string generateString (const string &input, const string &title="")
const char * generateCString (const string &input, const string &title="")
bool styleFound ()
virtual bool initStyle (const string &stylePath)
bool formattingDisabled ()
bool formattingIsPossible ()
LoadResult initLanguage (const string &langDefPath)
LanguageDefinitiongetLanguage ()
void setPrintLineNumbers (bool flag, unsigned int startCnt=0)
bool getPrintLineNumbers ()
void setPrintZeroes (bool flag)
bool getPrintZeroes ()
void setFragmentCode (bool flag)
void setLineNumberWidth (int w)
int getLineNumberWidth ()
bool getFragmentCode ()
const string & getStyleName ()
void setBaseFont (const string &s)
const string getBaseFont () const
void setBaseFontSize (const string &s)
const string & getBaseFontSize ()
void setPreformatting (WrapMode lineWrappingStyle, unsigned int lineLength, int numberSpaces)
void setIncludeStyle (bool flag)
void setSpecialOptions (bool htmlAttachAnchors, bool htmlOrderedList, bool latexReplQuotes, bool latexDisableShorthands, bool xslFopCompatible, const string &rtfPageSize)
bool printExternalStyle (const string &outFile)
virtual bool printIndexFile (const vector< string > &fileList, const string &outPath)
bool initIndentationScheme (const string &indentSchemePath)
void setStyleInputPath (const string &path)
void setStyleOutputPath (const string &path)
void setEncoding (const string &encodingName)
const string & getStyleInputPath ()
const string & getStyleOutputPath ()

Static Public Member Functions

static CodeGeneratorgetInstance (OutputType type)
static void deleteInstance ()

Protected Member Functions

 CodeGenerator (highlight::OutputType type)
virtual string maskCharacter (unsigned char c)=0
string maskString (const string &s)
State getState (const string &s, unsigned int searchPos)
virtual void insertLineNumber (bool insertNewLine=true)
virtual string getFooter ()=0
virtual void printBody ()=0
virtual string getHeader (const string &title)=0
unsigned int getLineNumber ()
void processRootState ()
virtual string getNewLine ()
unsigned int getStyleID (State s, unsigned int kwClassID=0)
unsigned int getLineIndex ()
void flushWs ()
string readUserStyleDef ()
virtual string getStyleDefinition ()
bool encodingDefined ()

Protected Attributes

vector< string > styleTagOpen
vector< string > styleTagClose
DocumentStyle docStyle
LanguageDefinition langInfo
string newLineTag
string spacer
istream * in
ostream * out
string maskWsBegin
string maskWsEnd
string styleCommentOpen
string styleCommentClose
string encoding
bool maskWs
bool excludeWs
bool fragmentOutput
bool showLineNumbers
bool lineNumberFillZeroes
string baseFont
string baseFontSize
string line
unsigned int lineNumber
unsigned int lineNumberOffset
State currentState
unsigned int currentKeywordClass
string wsBuffer
bool includeStyleDef

Detailed Description

Base class for parsing. Works similar to a Turing machine.

The virtual class provides source code parsing functionality, based on information stored in language definitions.
The derived classes have to define the output format.
Codegenerator is a singleton class.

Author:
Andre Simon


Member Function Documentation

CodeGenerator * highlight::CodeGenerator::getInstance ( OutputType  type  )  [static]

Get appropriate Codegenerator instance

Parameters:
type Output file type (HTML, XHTML, RTF, LATEX, TEX, XSLFO, ANSI)

void highlight::CodeGenerator::deleteInstance (  )  [static]

Deletes the singleton CodeGenerator instance. Call this method if getInstance was already called, or if you want to free the momory after usage.

ParseError highlight::CodeGenerator::generateFile ( const string &  inFileName,
const string &  outFileName 
)

Generates output file

Parameters:
inFileName Path of input file (if empty use stdin)
outFileName Path of output file (if empty use stdout)
Returns:
ParseError

string highlight::CodeGenerator::generateString ( const string &  input,
const string &  title = "" 
)

Generates output string

Parameters:
input input code
title document title
Returns:
formatted output code

const char * highlight::CodeGenerator::generateCString ( const string &  input,
const string &  title = "" 
)

Generates output string (added to make SWIG integration easier)

Parameters:
input input code
title document title
Returns:
formatted output code

bool highlight::CodeGenerator::styleFound (  ) 

Returns:
True if document style was found

bool highlight::CodeGenerator::initStyle ( const string &  stylePath  )  [virtual]

Define colour style information

Parameters:
stylePath Path of style description file
Returns:
true if successfull

Reimplemented in highlight::XslFoGenerator.

bool highlight::CodeGenerator::formattingDisabled (  ) 

Returns:
True if reformatting of current input is disabled

bool highlight::CodeGenerator::formattingIsPossible (  ) 

Returns:
True if reformatting of current input is possible

LoadResult highlight::CodeGenerator::initLanguage ( const string &  langDefPath  ) 

Parameters:
langDefPath Absolute path to language definition
Returns:
Failure: LOAD_FAILED; Reload necessary: LOAD_NEW, no reload necessary: LOAD_NONE

LanguageDefinition & highlight::CodeGenerator::getLanguage (  ) 

Returns:
Language definition

void highlight::CodeGenerator::setPrintLineNumbers ( bool  flag,
unsigned int  startCnt = 0 
)

tell parser to output line numbers

Parameters:
flag true if line numbers should be printed
startCnt line number starting count

bool highlight::CodeGenerator::getPrintLineNumbers (  ) 

Returns:
line number flag

void highlight::CodeGenerator::setPrintZeroes ( bool  flag  ) 

tell parser to output line numbers filled with zeroes

Parameters:
flag true if zeroes should be printed

bool highlight::CodeGenerator::getPrintZeroes (  ) 

Returns:
print zeroes flag

void highlight::CodeGenerator::setFragmentCode ( bool  flag  ) 

tell parser to omit document header and footer

Parameters:
flag true if output should be fragmented

void highlight::CodeGenerator::setLineNumberWidth ( int  w  ) 

define line number width

Parameters:
w width

int highlight::CodeGenerator::getLineNumberWidth (  ) 

Returns:
line number width

bool highlight::CodeGenerator::getFragmentCode (  ) 

Returns:
fragment flag

const string & highlight::CodeGenerator::getStyleName (  ) 

Returns:
style path

void highlight::CodeGenerator::setBaseFont ( const string &  s  ) 

tell parser to use this font as base font

Parameters:
s the font name, e.g. "Courier New"

const string highlight::CodeGenerator::getBaseFont (  )  const

Returns:
base font

void highlight::CodeGenerator::setBaseFontSize ( const string &  s  ) 

tell parser to use this size as base font size

Parameters:
s the font size, e.g. "12"

const string & highlight::CodeGenerator::getBaseFontSize (  ) 

Returns:
base font size

void highlight::CodeGenerator::setPreformatting ( WrapMode  lineWrappingStyle,
unsigned int  lineLength,
int  numberSpaces 
)

tell parser the wrapping mode

Parameters:
lineWrappingStyle wrapping style
lineLength max line length
numberSpaces number of spaces which replace a tab

void highlight::CodeGenerator::setIncludeStyle ( bool  flag  ) 

tell parser the include style definition in output

Parameters:
flag true if style should be included

void highlight::CodeGenerator::setSpecialOptions ( bool  htmlAttachAnchors,
bool  htmlOrderedList,
bool  latexReplQuotes,
bool  latexDisableShorthands,
bool  xslFopCompatible,
const string &  rtfPageSize 
)

define output format specific options

Parameters:
htmlAttachAnchors set true if anchors should be added to line numbers
htmlOrderedList set true if line numbers should be replaced by ordered list
latexReplQuotes set true if quotes should be replaced by
latexDisableShorthands set true if Babel shorthands should be disabled
xslFopCompatible set true if XSL output should be compatible with Apache FOP
rtfPageSize RTF page size (a3, a4, a5, b4, b5, b6, letter, legal)

bool highlight::CodeGenerator::printExternalStyle ( const string &  outFile  ) 

Print style definitions to external file

Parameters:
outFile Path of external style definition

Reimplemented in highlight::HtmlGenerator.

bool highlight::CodeGenerator::printIndexFile ( const vector< string > &  fileList,
const string &  outPath 
) [virtual]

Print index file with all input file names

Parameters:
fileList List of output file names
outPath Output path

Reimplemented in highlight::HtmlGenerator.

bool highlight::CodeGenerator::initIndentationScheme ( const string &  indentSchemePath  ) 

initialize source code indentation

Parameters:
indentSchemePath Path of indentation scheme
Returns:
true id successfull

void highlight::CodeGenerator::setStyleInputPath ( const string &  path  ) 

Set style input path

Parameters:
path path to style input file

void highlight::CodeGenerator::setStyleOutputPath ( const string &  path  ) 

Set style output path

Parameters:
path path to style output file

void highlight::CodeGenerator::setEncoding ( const string &  encodingName  ) 

Set encloding

Parameters:
encodingName encoding name

const string & highlight::CodeGenerator::getStyleInputPath (  ) 

Returns:
style input file path

const string & highlight::CodeGenerator::getStyleOutputPath (  ) 

Returns:
style output file path

virtual string highlight::CodeGenerator::maskCharacter ( unsigned char  c  )  [protected, pure virtual]

Parameters:
c Character to be masked
Returns:
Escape sequence of output format

string highlight::CodeGenerator::maskString ( const string &  s  )  [protected]

Parameters:
s string
Returns:
Copy of s with all escaped characters

State highlight::CodeGenerator::getState ( const string &  s,
unsigned int  searchPos 
) [protected]

Parameters:
s Symbol string
searchPos Position where search starts
Returns:
Found state (integer value)

void highlight::CodeGenerator::insertLineNumber ( bool  insertNewLine = true  )  [protected, virtual]

Insert line number at the beginning of current output line

Reimplemented in highlight::HtmlGenerator.

virtual string highlight::CodeGenerator::getFooter (  )  [protected, pure virtual]

Prints document footer

Implemented in highlight::AnsiGenerator, highlight::HtmlGenerator, highlight::LatexGenerator, highlight::TexGenerator, highlight::XmlGenerator, and highlight::XslFoGenerator.

virtual void highlight::CodeGenerator::printBody (  )  [protected, pure virtual]

Prints document body

Implemented in highlight::AnsiGenerator, highlight::HtmlGenerator, highlight::LatexGenerator, highlight::TexGenerator, highlight::XmlGenerator, and highlight::XslFoGenerator.

virtual string highlight::CodeGenerator::getHeader ( const string &  title  )  [protected, pure virtual]

prints document header

Parameters:
title Title of the document

Implemented in highlight::AnsiGenerator, highlight::HtmlGenerator, highlight::LatexGenerator, highlight::TexGenerator, highlight::XmlGenerator, and highlight::XslFoGenerator.

unsigned int highlight::CodeGenerator::getLineNumber (  )  [protected]

Get current line number

Returns:
line number

void highlight::CodeGenerator::processRootState (  )  [protected]

Processes origin state

string highlight::CodeGenerator::getNewLine (  )  [protected, virtual]

Returns:
line break sequence

unsigned int highlight::CodeGenerator::getStyleID ( State  s,
unsigned int  kwClassID = 0 
) [protected]

Parameters:
s current state
kwClassID keyword class (has to be set when s=KEYWORD)
Returns:
Index of style tag corresponding to the states

unsigned int highlight::CodeGenerator::getLineIndex (  )  [protected]

Returns:
line index

void highlight::CodeGenerator::flushWs (  )  [protected]

print all remaining white space

string highlight::CodeGenerator::readUserStyleDef (  )  [protected]

Returns:
Content of user defined input style

Reimplemented in highlight::HtmlGenerator.

virtual string highlight::CodeGenerator::getStyleDefinition (  )  [inline, protected, virtual]

Returns:
Style definition of the chosen output format

Reimplemented in highlight::HtmlGenerator.

bool highlight::CodeGenerator::encodingDefined (  )  [inline, protected]

Returns:
true id encoding is defined


Member Data Documentation

vector<string> highlight::CodeGenerator::styleTagOpen [protected]

Tag Delimiters for every colour style

DocumentStyle highlight::CodeGenerator::docStyle [protected]

Description of document colour style

LanguageDefinition highlight::CodeGenerator::langInfo [protected]

Language definition

string highlight::CodeGenerator::newLineTag [protected]

Tag for inserting line feeds

string highlight::CodeGenerator::spacer [protected]

String that represents a white space in output

istream* highlight::CodeGenerator::in [protected]

file input

ostream* highlight::CodeGenerator::out [protected]

file output

string highlight::CodeGenerator::maskWsBegin [protected]

Tags which enclose white space indentation blocks

string highlight::CodeGenerator::styleCommentOpen [protected]

Style comment delimiters

string highlight::CodeGenerator::encoding [protected]

Encoding name

bool highlight::CodeGenerator::maskWs [protected]

Test if maskWsBegin and maskWsEnd should be applied

bool highlight::CodeGenerator::excludeWs [protected]

Test if whitespace sould always be separated from enclosing tokens

bool highlight::CodeGenerator::fragmentOutput [protected]

Test if header and footer should be omitted

bool highlight::CodeGenerator::showLineNumbers [protected]

Test if line numbers should be printed

bool highlight::CodeGenerator::lineNumberFillZeroes [protected]

Test if leading spyce of line number should be filled with zeroes

string highlight::CodeGenerator::baseFont [protected]

The base font to use

string highlight::CodeGenerator::baseFontSize [protected]

The base font size to use

string highlight::CodeGenerator::line [protected]

Current line of input file

unsigned int highlight::CodeGenerator::lineNumber [protected]

Current line number

State highlight::CodeGenerator::currentState [protected]

Current state

unsigned int highlight::CodeGenerator::currentKeywordClass [protected]

keyword class id, used to apply the corresponding keyword style

string highlight::CodeGenerator::wsBuffer [protected]

contains white space, which will be printed after a closing tag

bool highlight::CodeGenerator::includeStyleDef [protected]

Flag to test if style definition should be included in output document


The documentation for this class was generated from the following files:
Generated on Fri Apr 27 13:12:36 2007 for Highlight Code Converter by  doxygen 1.5.2