highlight::CodeGenerator Class Reference

Base class for parsing. Works like a finite state machine. More...

Inheritance diagram for highlight::CodeGenerator:

highlight::AnsiGenerator highlight::BBCodeGenerator highlight::HtmlGenerator highlight::LatexGenerator highlight::RtfGenerator highlight::SVGGenerator highlight::TexGenerator highlight::XmlGenerator highlight::Xterm256Generator

List of all members.

Public Member Functions

bool initTheme (const string &themePath)
bool initIndentationScheme (const string &indentScheme)
bool initTagInformation (const string &ctagsPath)
LoadResult loadLanguage (const string &langDefPath)
ParseError generateFile (const string &inFileName, const string &outFileName)
string generateString (const string &input)
string generateStringFromFile (const string &inFileName)
bool printExternalStyle (const string &outFile)
virtual bool printIndexFile (const vector< string > &fileList, const string &outPath)
void setPreformatting (WrapMode lineWrappingStyle, unsigned int lineLength, int numberSpaces)
bool styleFound ()
bool formattingDisabled ()
bool formattingIsPossible ()
LoadResult initLanguage (const string &langDefPath)
const LanguageDefinitiongetLanguage ()
void setPrintLineNumbers (bool flag, unsigned int startCnt=1)
bool getPrintLineNumbers ()
void setPrintZeroes (bool flag)
bool getPrintZeroes ()
void setFragmentCode (bool flag)
bool getFragmentCode ()
void setLineNumberWidth (int w)
int getLineNumberWidth ()
void setValidateInput (bool flag)
bool getValidateInput ()
const string & getStyleName ()
void setBaseFont (const string &s)
const string getBaseFont () const
void setBaseFontSize (const string &s)
const string getBaseFontSize ()
void setIncludeStyle (bool flag)
void disableTrailingNL (bool flag)
void setStyleInputPath (const string &path)
void setStyleOutputPath (const string &path)
void setEncoding (const string &encodingName)
const string & getStyleInputPath ()
const string & getStyleOutputPath ()
void setTitle (const string &title)
string getTitle ()
void setMaxInputLineCnt (unsigned int cnt)
bool hasWhiteBGColour ()
void setKeyWordCase (StringTools::KeywordCase keyCase)
void addMarkedLine (int lineNo, string &helpTxt)
void setEOLDelimiter (char delim)
void setStartingNestedLang (const string &langName)
virtual void setHTMLAttachAnchors (bool)
virtual void setHTMLOrderedList (bool)
virtual void setHTMLInlineCSS (bool)
virtual void setHTMLEnclosePreTag (bool)
virtual void setHTMLAnchorPrefix (const string &)
virtual void setHTMLClassName (const string &)
virtual void setLATEXReplaceQuotes (bool)
virtual void setLATEXNoShorthands (bool)
virtual void setLATEXPrettySymbols (bool)
virtual void setRTFPageSize (const string &)
virtual void setRTFCharStyles (bool)
virtual void setSVGSize (const string &, const string &)

Static Public Member Functions

static CodeGeneratorgetInstance (OutputType type)
static void deleteInstance (CodeGenerator *inst)

Protected Member Functions

 CodeGenerator (highlight::OutputType type)
virtual string maskCharacter (unsigned char c)=0
void maskString (ostream &ss, const string &s)
State getState (const string &s, unsigned int searchPos)
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 > openTags
 list of format delimiters (open new format descriptions)
vector< string > closeTags
 list of format delimiters (close format descriptions)
DocumentStyle docStyle
LanguageDefinition langInfo
CTagsReader metaInfo
string newLineTag
string spacer
istream * in
ostream * out
string maskWsBegin
 open whitespace mask
string maskWsEnd
 close whitespace mask
string styleCommentOpen
 open comment delimiter
string styleCommentClose
 close comment delimiter
string embedBlockOpen
 open block delimiter to highlight embedded code
string embedBlockClose
 close block delimiter
string encoding
string docTitle
string inFile
 input file name
string outFile
 output file name
bool maskWs
bool excludeWs
bool fragmentOutput
bool showLineNumbers
bool lineNumberFillZeroes
bool printNewLines
string baseFont
string baseFontSize
string line
unsigned int lineNumber
int lineNumberOffset
State currentState
unsigned int currentKeywordClass
string wsBuffer
bool includeStyleDef
map< int, string > markLines
PreFormatter preFormatter

Static Protected Attributes

static const unsigned int NUMBER_BUILTIN_STATES = 10
 number of token states (without keyword group IDs)
static const string STY_NAME_STD = "std"
static const string STY_NAME_STR = "str"
static const string STY_NAME_NUM = "num"
static const string STY_NAME_SLC = "slc"
static const string STY_NAME_COM = "com"
static const string STY_NAME_ESC = "esc"
static const string STY_NAME_DIR = "dir"
static const string STY_NAME_DST = "dstr"
static const string STY_NAME_LIN = "line"
static const string STY_NAME_SYM = "sym"


Detailed Description

Base class for parsing. Works like a finite state 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.
The colour information is stored in a DocumentStyle instance.
Codegenerator is a singleton class.
Use getInstance for a singleton class instance. Then call the init* methods and loadLanguage to initialize the parser. Init methods have to be called first. Call generate* methods to get results.

Author:
Andre Simon

Constructor & Destructor Documentation

highlight::CodeGenerator::CodeGenerator ( highlight::OutputType  type  )  [protected]

Parameters:
type Output type


Member Function Documentation

void highlight::CodeGenerator::addMarkedLine ( int  lineNo,
string &  helpTxt 
)

Parameters:
lineNo number of line that should be marked
helpTxt additional help text

References markLines.

static void highlight::CodeGenerator::deleteInstance ( CodeGenerator inst  )  [inline, static]

Delete CodeGenerator instance (this is intended for SWIG integration only, in normal C++ code the result of getInstance() should be saved in an auto_ptr)

Parameters:
CodeGenerator* CodeGenerator instance

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

tell parser to omit trailing newline character

Parameters:
flag true if no trailing newline should be printed

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

Returns:
true id encoding is defined

References StringTools::change_case(), and encoding.

Referenced by highlight::HtmlGenerator::getHeaderStart().

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

print all remaining white space

References out, and wsBuffer.

Referenced by processRootState().

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

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

Generate output file from input file

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

References docStyle, highlight::DocumentStyle::found(), fragmentOutput, in, inFile, out, and outFile.

string highlight::CodeGenerator::generateString ( const string &  input  ) 

Generate output string from input string

Parameters:
input input code string
Returns:
formatted output code

References docStyle, highlight::DocumentStyle::found(), fragmentOutput, in, and out.

string highlight::CodeGenerator::generateStringFromFile ( const string &  inFileName  ) 

Generate output string from input file

Parameters:
inFileName file path
Returns:
formatted output code

References docStyle, highlight::DocumentStyle::found(), fragmentOutput, in, inFile, and out.

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

Returns:
base font

References baseFont.

Referenced by highlight::HtmlGenerator::getStyleDefinition().

const string highlight::CodeGenerator::getBaseFontSize (  ) 

bool highlight::CodeGenerator::getFragmentCode (  ) 

Returns:
fragment flag

References fragmentOutput.

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

Get appropriate Codegenerator instance (should be used with auto_ptr)

Parameters:
type Output file type (HTML, XHTML, RTF, LATEX, TEX, ANSI, XTERM256)
Returns:
CodeGenerator

Referenced by HLCmdLineApp::run().

const LanguageDefinition & highlight::CodeGenerator::getLanguage (  ) 

Returns:
Language definition

References langInfo.

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

Returns:
line index

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

Get current line number

Returns:
line number

References lineNumber.

int highlight::CodeGenerator::getLineNumberWidth (  ) 

Returns:
line number width

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

Returns:
line break sequence

References newLineTag, and printNewLines.

Referenced by processRootState().

bool highlight::CodeGenerator::getPrintLineNumbers (  ) 

Returns:
line number flag

References showLineNumbers.

bool highlight::CodeGenerator::getPrintZeroes (  ) 

Returns:
print zeroes flag

References lineNumberFillZeroes.

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)
sucht vorwaerts ab Position searchPos Ziffer in s und liefert Integerwert der gefundenen Zahl zurueck. Im SymbolString stehen die den einzelnen Symbolen zugeordneten Konstanten immer HINTER diesen Symbolen

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

Returns:
Style definition of the chosen output format

Reimplemented in highlight::HtmlGenerator.

Referenced by printExternalStyle().

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

References NUMBER_BUILTIN_STATES.

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

Returns:
style input file path

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

Returns:
style path

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

Returns:
style output file path

string highlight::CodeGenerator::getTitle (  ) 

Returns:
Document title

References docTitle.

bool highlight::CodeGenerator::getValidateInput (  ) 

Returns:
input validation flag

bool highlight::CodeGenerator::hasWhiteBGColour (  ) 

Returns:
true if chosen document style has white background colour

References docStyle, and highlight::DocumentStyle::getBgColour().

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

initialize source code indentation and reformatting scheme; needs to be called before using a generate* method

Parameters:
indentScheme Name of indentation scheme
Returns:
true if successfull

LoadResult highlight::CodeGenerator::initLanguage ( const string &  langDefPath  )  [inline]

Deprecated:
Parameters:
langDefPath Absolute path to language definition; use loadLanguage instead
Returns:
LOAD_FAILED: failure, LOAD_NEW: Reload necessary, LOAD_NONE: no reload necessary

References loadLanguage().

bool highlight::CodeGenerator::initTagInformation ( const string &  ctagsPath  ) 

Load ctags meta information; needs to be called before using a generate* method

Parameters:
ctagsPath Path of tags file
Returns:
true if successfull

References metaInfo.

bool highlight::CodeGenerator::initTheme ( const string &  themePath  ) 

Define colour theme information; needs to be called before using a generate* method. Call this method before loadLanguage().

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

References docStyle, and highlight::DocumentStyle::load().

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

Parameters:
langDefPath Absolute path to language definition, may be used multiple times for a generator instance
Returns:
LOAD_FAILED: failure, LOAD_NEW: Reload necessary, LOAD_NONE: no reload necessary

References closeTags, highlight::LanguageDefinition::enableReformatting(), highlight::LanguageDefinition::getFailedRegex(), highlight::LanguageDefinition::getKeywordClasses(), langInfo, highlight::LanguageDefinition::load(), highlight::LanguageDefinition::needsReload(), NUMBER_BUILTIN_STATES, and openTags.

Referenced by initLanguage().

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

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

Referenced by maskString().

void highlight::CodeGenerator::maskString ( ostream &  ss,
const string &  s 
) [protected]

Parameters:
ss destination stream
s string

References maskCharacter().

Referenced by processRootState().

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

Print style definitions to external file or stdout

Parameters:
outFile Path of external style definition; print to stdout if empty
Returns:
true if successfull

Reimplemented in highlight::HtmlGenerator.

References getStyleDefinition(), highlight::LanguageDefinition::highlightingEnabled(), includeStyleDef, langInfo, readUserStyleDef(), styleCommentClose, and styleCommentOpen.

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
Returns:
true if successfull

Reimplemented in highlight::HtmlGenerator.

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

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

Returns:
Content of user defined input style

Reimplemented in highlight::HtmlGenerator.

References styleCommentClose, and styleCommentOpen.

Referenced by printExternalStyle().

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

use this font as base font

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

References baseFont.

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

use this size as base font size

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

References baseFontSize.

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

Set encoding (output encoding must match input file)

Parameters:
encodingName encoding name

References encoding.

void highlight::CodeGenerator::setEOLDelimiter ( char  delim  ) 

Parameters:
delim End of line delimiter (default: NL)

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

omit document header and footer

Parameters:
flag true if output should be fragmented

References fragmentOutput.

virtual void highlight::CodeGenerator::setHTMLAnchorPrefix ( const string &   )  [inline, virtual]

set HTML output anchor prefix

Reimplemented in highlight::HtmlGenerator.

virtual void highlight::CodeGenerator::setHTMLAttachAnchors ( bool   )  [inline, virtual]

set HTML output anchor flag

Reimplemented in highlight::HtmlGenerator.

virtual void highlight::CodeGenerator::setHTMLClassName ( const string &   )  [inline, virtual]

set HTML output class name

Reimplemented in highlight::HtmlGenerator.

virtual void highlight::CodeGenerator::setHTMLEnclosePreTag ( bool   )  [inline, virtual]

set HTML output enclose pre tag flag

Reimplemented in highlight::HtmlGenerator.

virtual void highlight::CodeGenerator::setHTMLInlineCSS ( bool   )  [inline, virtual]

set HTML output inline CSS flag

Reimplemented in highlight::HtmlGenerator.

virtual void highlight::CodeGenerator::setHTMLOrderedList ( bool   )  [inline, virtual]

set HTML output ordered list flag

Reimplemented in highlight::HtmlGenerator.

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

tell parser the include style definition in output

Parameters:
flag true if style should be included

References includeStyleDef.

void highlight::CodeGenerator::setKeyWordCase ( StringTools::KeywordCase  keyCase  ) 

Parameters:
keyCase Keyword case

virtual void highlight::CodeGenerator::setLATEXNoShorthands ( bool   )  [inline, virtual]

set LaTeX no Babel shorthands flag

Reimplemented in highlight::LatexGenerator.

virtual void highlight::CodeGenerator::setLATEXPrettySymbols ( bool   )  [inline, virtual]

set LaTeX pretty Symbols flag

Reimplemented in highlight::LatexGenerator.

virtual void highlight::CodeGenerator::setLATEXReplaceQuotes ( bool   )  [inline, virtual]

set LaTeX replace quotes flag

Reimplemented in highlight::LatexGenerator.

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

define line number width

Parameters:
w width

void highlight::CodeGenerator::setMaxInputLineCnt ( unsigned int  cnt  ) 

Parameters:
cnt maximum number of input lines to be processed

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

define the preformatting parameters. Preformatting takes place before the optional astyle reformatting and indenting is performed (defined by initIndentationScheme)

Parameters:
lineWrappingStyle wrapping style (WRAP_DISABLED, WRAP_SIMPLE, WRAP_DEFAULT)
lineLength max line length
numberSpaces number of spaces which replace a tab

References preFormatter, highlight::PreFormatter::setNumberSpaces(), highlight::PreFormatter::setReplaceTabs(), highlight::PreFormatter::setWrap(), highlight::PreFormatter::setWrapIndentBraces(), and highlight::PreFormatter::setWrapLineLength().

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

output line numbers

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

References lineNumberOffset, and showLineNumbers.

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

output line numbers filled with zeroes

Parameters:
flag true if zeroes should be printed

References lineNumberFillZeroes.

virtual void highlight::CodeGenerator::setRTFCharStyles ( bool   )  [inline, virtual]

set RTF output character styles flag

Reimplemented in highlight::RtfGenerator.

virtual void highlight::CodeGenerator::setRTFPageSize ( const string &   )  [inline, virtual]

set RTF page size

Reimplemented in highlight::RtfGenerator.

void highlight::CodeGenerator::setStartingNestedLang ( const string &  langName  ) 

Define the name of a nested langage which is located at the beginning of input. The opening embedded delimiter is missing, but the closing delimiter must exist.

Parameters:
langName name of nested language

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

virtual void highlight::CodeGenerator::setSVGSize ( const string &  ,
const string &   
) [inline, virtual]

set SVG page size

Reimplemented in highlight::SVGGenerator.

void highlight::CodeGenerator::setTitle ( const string &  title  ) 

Parameters:
title Document title

References docTitle.

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

check if input is binary or text

Parameters:
flag true if input should be checked

bool highlight::CodeGenerator::styleFound (  ) 

Deprecated:
Returns:
True if document style was found

References docStyle, and highlight::DocumentStyle::found().


Member Data Documentation

The base font to use

Referenced by getBaseFont(), and setBaseFont().

The base font size to use

Referenced by getBaseFontSize(), and setBaseFontSize().

keyword class id, used to apply the corresponding keyword style

Current state

document title

Referenced by getTitle(), and setTitle().

Test if whitespace sould always be separated from enclosing tokens

Test if header and footer should be omitted

Referenced by generateFile(), generateString(), generateStringFromFile(), getFragmentCode(), and setFragmentCode().

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

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

Referenced by printExternalStyle(), and setIncludeStyle().

Language definition

Referenced by getLanguage(), loadLanguage(), printExternalStyle(), and processRootState().

string highlight::CodeGenerator::line [protected]

Current line of input file

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

Current line number

Referenced by getLineNumber(), and processRootState().

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

Referenced by getPrintZeroes(), and setPrintZeroes().

output line number count start

Referenced by setPrintLineNumbers().

map<int, string> highlight::CodeGenerator::markLines [protected]

map which saves all lines that should be highlghted

Referenced by addMarkedLine().

Test if maskWsBegin and maskWsEnd should be applied

CTagsReader highlight::CodeGenerator::metaInfo [protected]

CTags meta information

Referenced by initTagInformation().

Tag for inserting line feeds

Referenced by getNewLine().

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

Class for line wrapping and tab replacement

Referenced by setPreformatting().

Flag to test if newlines should be printed

Referenced by getNewLine(), and processRootState().

Test if line numbers should be printed

Referenced by getPrintLineNumbers(), and setPrintLineNumbers().

String that represents a white space in output

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

Referenced by flushWs().


The documentation for this class was generated from the following files:

Generated on Wed Jun 9 20:40:12 2010 for Highlight Code Converter by  doxygen 1.5.7.1