"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/src/include/codegenerator.h" (12 May 2020, 30014 Bytes) of package /windows/www/highlight-3.57-x64.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "codegenerator.h": 3.56_vs_3.57.

    1 /***************************************************************************
    2                           codegenerator.h  -  description
    3                              -------------------
    4     begin                : Die Jul 9 2002
    5     copyright            : (C) 2002-2018 by Andre Simon
    6     email                : a.simon@mailbox.org
    7  ***************************************************************************/
    8 
    9 
   10 /*
   11 This file is part of Highlight.
   12 
   13 Highlight is free software: you can redistribute it and/or modify
   14 it under the terms of the GNU General Public License as published by
   15 the Free Software Foundation, either version 3 of the License, or
   16 (at your option) any later version.
   17 
   18 Highlight is distributed in the hope that it will be useful,
   19 but WITHOUT ANY WARRANTY; without even the implied warranty of
   20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   21 GNU General Public License for more details.
   22 
   23 You should have received a copy of the GNU General Public License
   24 along with Highlight.  If not, see <http://www.gnu.org/licenses/>.
   25 */
   26 
   27 #ifndef CODEPARSER_H
   28 #define CODEPARSER_H
   29 
   30 #include <iostream>
   31 #include <sstream>
   32 #include <string>
   33 #include <iomanip>
   34 #include <stack>
   35 #include <vector>
   36 
   37 #include "syntaxreader.h"
   38 #include "themereader.h"
   39 #include "astyle/astyle.h"
   40 #include "preformatter.h"
   41 #include "enums.h"
   42 #include "stringtools.h"
   43 
   44 /// The highlight namespace contains all classes and data structures needed for parsing input data.
   45 
   46 namespace highlight
   47 {
   48 /** \brief Regular Expression Information
   49 
   50     This class associates a processing state with a keyword class and the length of the matched token.
   51 
   52 * @author Andre Simon
   53 */
   54 class ReGroup
   55 {
   56 public:
   57 
   58     /// Constructor
   59     ReGroup() : length ( 0 ), state ( STANDARD ), kwClass ( 0 ), name()
   60     {
   61     }
   62 
   63     /// Constructor
   64     ReGroup ( State s, unsigned int l , unsigned int c, const string&n ) :
   65         length ( l ), state ( s ), kwClass ( c ), name(n)
   66     {
   67     }
   68 
   69     /// Copy Constructor
   70     ReGroup ( const ReGroup& other )
   71     {
   72         length = other.length;
   73         state = other.state;
   74         kwClass = other.kwClass;
   75         name=other.name;
   76     }
   77 
   78     /// Operator overloading
   79     ReGroup& operator= ( const ReGroup & other )
   80     {
   81         length = other.length;
   82         state = other.state;
   83         kwClass = other.kwClass;
   84         name=other.name;
   85         return *this;
   86     }
   87 
   88     ~ReGroup()
   89     {
   90     }
   91 
   92     unsigned int length;    ///< length of the token
   93     State state;            ///< state of the matched token (keyword, string, etc)
   94     unsigned int kwClass;   ///< keyword class if state is keyword
   95     string name;           ///< language name needed to handle embedded languages
   96 };
   97 
   98 
   99 /** \brief Base class for parsing. Works like a finite state machine.
  100 
  101     The virtual class provides source code parsing functionality, based on
  102     information stored in language definitions.<br>
  103     The derived classes have to define the output format.<br>
  104     The colour information is stored in a ThemeReader instance.<br>
  105     Codegenerator is a singleton class.<br>
  106     Use getInstance for a singleton class instance. Then call the init* methods
  107     and loadLanguage to initialize the parser. Init methods have to be called first.
  108     Call generate* methods to get results.<br><br>
  109     
  110     Parser workflow (neglecting embedded syntax and other details):
  111     
  112     This flow chart shows the method calls, starting in processRootState:
  113     
  114     -> lineIndex=0
  115     -> processRootState()
  116        -> state = getCurrentState()
  117           -> c = getInputChar()
  118              -> increase lineIndex
  119              -> if new line: matchRegex()
  120                 -> cycle through all regexes of Syntaxreader:
  121                    KEYWORD, COMMENT, IDENTIFIER, NUMBER, STRING, INTERPOLATION, 
  122                    PREPROCESSOR, OPERATOR, NESTEDSECTIONS
  123                 -> save position and length of a match for the current line
  124           -> is there a match at line[lineIndex]?
  125              -> YES: - token = match substring of line
  126                      - lineIndex = lineIndex + length of token
  127                      - call OnStateChange chunk if available
  128                      - state = state of the associated regex or OnStateChange return value
  129              -> NO:  - token=c
  130                      - state = STANDARD
  131         -> state is used to determine the next process* method to call. There
  132            are process methods for each state (ie processKeywordState, processNumberState).
  133            These methods open and close the delimiter tags in the output format, and most
  134            importantly decide when the state ends. They also limit the allowed state changes,
  135            like INTERPOLATION in STRING.
  136           
  137 * @author Andre Simon
  138 */
  139 
  140 class CodeGenerator
  141 {
  142 
  143 public:
  144 
  145     virtual ~CodeGenerator();
  146 
  147     /**
  148       Get appropriate Codegenerator instance (should be used with auto_ptr)
  149       \param type Output file type (HTML, XHTML, RTF, LATEX, TEX, ANSI, XTERM256)
  150       \return CodeGenerator
  151     */
  152     static CodeGenerator* getInstance ( OutputType type );
  153 
  154     /**
  155       Delete CodeGenerator instance (this is intended for SWIG integration only,
  156       in normal C++ code the result of getInstance() should be saved in an auto_ptr)
  157       \param inst CodeGenerator instance
  158     */
  159     static void deleteInstance ( CodeGenerator* inst )
  160     {
  161         if ( inst ) delete inst;
  162     }
  163 
  164     /**
  165      Define colour theme information; needs to be called before using a generate* method.
  166      Call this method before loadLanguage().
  167      \param themePath Path of style description file
  168      \return true if successful
  169     */
  170     bool initTheme ( const string& themePath );
  171 
  172     /**
  173      \return description of the theme init error
  174     */
  175     string getThemeInitError();
  176 
  177     /**
  178      \return description of the plug-in script error
  179     */
  180     string getPluginScriptError();
  181 
  182     /** initialize source code indentation and reformatting scheme;
  183         needs to be called before using a generate* method
  184         \param indentScheme Name of indentation scheme
  185         \return true if successful
  186      */
  187     bool initIndentationScheme ( const string& indentScheme );
  188     
  189     void setIndentationOptions (const vector<string>& options);
  190 
  191     /** \param langDefPath Absolute path to language definition, may be used multiple times for a generator instance
  192      *  \param embedded set True if method is called to load an embedded language
  193         \return   LOAD_OK, LOAD_FAILED, LOAD_FAILED_REGEX, LOAD_FAILED_LUA
  194     */
  195     LoadResult loadLanguage ( const string& langDefPath, bool embedded=false );
  196 
  197     /**
  198      Generate output file from input file
  199      \param inFileName Path of input file (if empty use stdin)
  200      \param outFileName Path of output file (if empty use stdout)
  201      \return ParseError
  202     */
  203     ParseError generateFile ( const string &inFileName, const string &outFileName );
  204 
  205     /**
  206      Generate output string from input string
  207      \param input input code string
  208      \return formatted output code
  209     */
  210     string generateString ( const string &input );
  211 
  212     /**
  213      Generate output string from input file
  214      \param inFileName file path
  215      \return formatted output code
  216     */
  217     string generateStringFromFile ( const string &inFileName );
  218 
  219     /** Print style definitions to external file or stdout
  220       \param outFile Path of external style definition; print to stdout if empty
  221        \return true if successful
  222       */
  223     bool printExternalStyle ( const string &outFile );
  224 
  225         /** Print persistent state snippets to external file 
  226       \param outFile Path of plugin file to generate
  227        \return true if successful
  228       */
  229     bool printPersistentState ( const string &outFile );
  230     
  231     /** Print index file with all input file names
  232        \param fileList List of output file names
  233        \param outPath Output path
  234         \return true if successful
  235      */
  236     virtual bool printIndexFile ( const vector<string> & fileList,
  237                                   const string &outPath );
  238 
  239     /** define the preformatting parameters. Preformatting takes place before
  240         the optional astyle reformatting and indenting is performed (defined by initIndentationScheme)
  241        \param lineWrappingStyle wrapping style (WRAP_DISABLED, WRAP_SIMPLE, WRAP_DEFAULT)
  242        \param lineLength max line length
  243        \param numberSpaces number of spaces which replace a tab
  244     */
  245     void setPreformatting ( WrapMode lineWrappingStyle, unsigned int lineLength,int numberSpaces );
  246 
  247     /** \return True if document style was found */
  248     bool styleFound();
  249 
  250     /** \return True if reformatting of current input is disabled */
  251     bool formattingDisabled();
  252 
  253     /** \return True if reformatting of current input is possible */
  254     bool formattingIsPossible();
  255 
  256     /** output line numbers
  257        \param flag true if line numbers should be printed
  258        \param startCnt line number starting count
  259     */
  260     void setPrintLineNumbers ( bool flag, unsigned int startCnt=1 );
  261 
  262     /** \return line number flag */
  263     bool getPrintLineNumbers();
  264 
  265     /** output line numbers filled with zeroes
  266         \param  flag true if zeroes should be printed
  267     */
  268     void setPrintZeroes ( bool flag );
  269 
  270     /** \return print zeroes flag */
  271     bool getPrintZeroes();
  272 
  273     /** omit document header and footer
  274        \param  flag true if output should be fragmented
  275     */
  276     void setFragmentCode ( bool flag );
  277 
  278     /** \return fragment flag */
  279     bool getFragmentCode();
  280 
  281     /** define line number width
  282        \param  w width
  283     */
  284     void setLineNumberWidth ( int w );
  285 
  286     /** \return line number width */
  287     int getLineNumberWidth();
  288     
  289     /** check if input is binary or text
  290        \param  flag true if input should be checked
  291     */
  292     void setValidateInput ( bool flag );
  293 
  294     /** \return input validation flag */
  295     bool getValidateInput();
  296 
  297     /** set keep injections flag
  298      * \param  flag true if plug-in injections should be outputted if header 
  299      * and footer are omitted (fragmentCode is true)
  300      */
  301     void setKeepInjections( bool flag );;
  302 
  303     /** \return keep injection flag */
  304     bool getKeepInjections();
  305     
  306     bool requiresTwoPassParsing() const;
  307 
  308     /** \param  flag true if wrapped lines receive unique line numbers.
  309      *  otherwise wrapped lines don't have line numbers at all. */
  310     void setNumberWrappedLines ( bool flag );
  311 
  312     /** return number wrapped lines flag */
  313     bool getNumberWrappedLines ();
  314     
  315     /** \param flag true if version info comment should be omitted */
  316     void setOmitVersionComment ( bool flag );
  317 
  318     /** return version info comment flag */
  319     bool getOmitVersionComment ();
  320     
  321     /** \param flag true if token of the same syntax category should be outputted in separate tags */
  322     void setIsolateTags ( bool flag );
  323 
  324     /** return version info comment flag */
  325     bool getIsolateTags ();
  326     
  327     /** \return style path */
  328     const string& getStyleName();
  329 
  330     /** use this font as base font
  331       * \param fontName the font name, e.g. "Courier New"
  332      */
  333     void setBaseFont ( const string& fontName);
  334 
  335     /** \return base font */
  336     const string getBaseFont() const ;
  337 
  338     /** use this size as base font size
  339       * \param fontSize the font size, e.g. "12"
  340      */
  341     void setBaseFontSize ( const string& fontSize );
  342 
  343     /** \return base font size*/
  344     const string getBaseFontSize();
  345 
  346     /** tell parser the include style definition in output
  347         \param flag true if style should be included
  348      */
  349     void setIncludeStyle ( bool flag );
  350 
  351     /** tell parser to omit trailing newline character
  352         \param flag 1 if no trailing newline should be printed, 
  353                     2 omit newline only for empty input
  354      */
  355     void disableTrailingNL ( int flag );
  356 
  357     /** Set style input path
  358         \param path path to style input file
  359       */
  360     void setStyleInputPath ( const string& path );
  361 
  362     /** Set style output path
  363       \param path path to style output file
  364     */
  365     void setStyleOutputPath ( const string& path );
  366 
  367     /** Set encoding (output encoding must match input file)
  368       \param encodingName encoding name
  369     */
  370     void setEncoding ( const string& encodingName );
  371 
  372     /** \return style input file path */
  373     const string&  getStyleInputPath();
  374 
  375     /** \return style output file path */
  376     const string&  getStyleOutputPath();
  377 
  378     /** \param title Document title */
  379     void setTitle ( const string & title );
  380 
  381     /** \return Document title */
  382     string getTitle();
  383 
  384     /** \param begin number of the first input line to be processed */
  385     void setStartingInputLine ( unsigned int begin );
  386 
  387     /** \param cnt upper limit of input lines to be processed */
  388     void setMaxInputLineCnt ( unsigned int cnt );
  389 
  390     /** \param cnt number of input files */
  391     void setFilesCnt ( unsigned int cnt );
  392 
  393     /** \param keyCase Keyword case */
  394     void setKeyWordCase ( StringTools::KeywordCase keyCase );
  395 
  396     /** \param delim End of line delimiter (default: NL)
  397     */
  398     void setEOLDelimiter(char delim);
  399 
  400     /** Define the name of a nested language which is located at the beginning of input.
  401         The opening embedded delimiter is missing, but the closing delimiter must exist.
  402         \param langName name of nested language
  403     */
  404     void setStartingNestedLang(const string &langName);
  405 
  406     /** \param param path of plugin input file
  407     */
  408     void setPluginParameter ( const string& param );
  409 
  410     void resetSyntaxReaders();
  411     
  412     /** Load the Lua functions og the plug-in script
  413         \param script path of the plug-in script
  414     */
  415     bool initPluginScript(const string& script);
  416     
  417     bool syntaxRequiresTwoPassRun();
  418     
  419     void clearPersistentSnippets();
  420 
  421 
  422     /** \return Syntaxreader Regex error message */
  423     string getSyntaxRegexError();
  424 
  425     /** \return Syntaxreader Lua error message */
  426     string getSyntaxLuaError();
  427 
  428     /** \return Syntaxreader description */
  429     string getSyntaxDescription();
  430 
  431         /** \return Encoding hint */
  432     string getSyntaxEncodingHint();
  433     
  434     /** \return Theme description */
  435     string getThemeDescription();
  436 
  437     /** \return Syntaxreader category description */
  438     string getSyntaxCatDescription();
  439 
  440     /** \return Theme category description */
  441     string getThemeCatDescription();
  442 
  443     vector<string> getPosTestErrors() { return failedPosTests; }
  444     
  445     /** \return Pointer Syntaxreader, intended for debug output  */
  446     SyntaxReader* getSyntaxReader()
  447     {
  448         return currentSyntax;
  449     }
  450 
  451     /** set HTML output anchor flag
  452      */
  453     virtual void setHTMLAttachAnchors ( bool )  {};
  454 
  455     /** set HTML output ordered list flag
  456      */
  457     virtual void setHTMLOrderedList ( bool )  {};
  458 
  459     /** set HTML output inline CSS flag
  460      */
  461     virtual void setHTMLInlineCSS ( bool )  {};
  462 
  463     /** set HTML output enclose pre tag flag
  464      */
  465     virtual void setHTMLEnclosePreTag ( bool )  {};
  466 
  467     /** set HTML output replace space by &nbsp; flag
  468      */
  469     virtual void setHTMLUseNonBreakingSpace ( bool )  {};
  470 
  471     /** set HTML output anchor prefix
  472      */
  473     virtual void setHTMLAnchorPrefix ( const string& )  {};
  474 
  475     /** set HTML output class name
  476      */
  477     virtual void setHTMLClassName ( const string& )  {};
  478 
  479     /** set LaTeX replace quotes flag
  480      */
  481     virtual void setLATEXReplaceQuotes ( bool )  {};
  482 
  483     /** set LaTeX no Babel shorthands flag
  484      */
  485     virtual void setLATEXNoShorthands ( bool )  {};
  486 
  487     /** set LaTeX pretty Symbols flag
  488      */
  489     virtual void setLATEXPrettySymbols ( bool )  {};
  490 
  491     virtual void setLATEXBeamerMode ( bool )  {};
  492         
  493     /** set RTF page size
  494      */
  495     virtual void setRTFPageSize ( const string& )  {};
  496 
  497     /** set RTF output character styles flag
  498      */
  499     virtual void setRTFCharStyles ( bool )  {};
  500 
  501     /** set RTF page color flag
  502      */
  503     virtual void setRTFPageColor ( bool )  {};
  504     
  505     /** set SVG page size
  506      */
  507     virtual void setSVGSize ( const string&, const string& )  {};
  508     
  509     /** set True Color flag
  510      */
  511     virtual void setESCTrueColor ( bool )  {};
  512 
  513      /** set background padding width (<=0 to disable)
  514      */
  515     virtual void setESCCanvasPadding ( unsigned int )  {};
  516 
  517 protected:
  518 
  519     static const unsigned int NUMBER_BUILTIN_STATES;  ///< number of token states (without keyword group IDs)
  520 
  521     static const string STY_NAME_STD;
  522     static const string STY_NAME_STR;
  523     static const string STY_NAME_NUM;
  524     static const string STY_NAME_SLC;
  525     static const string STY_NAME_COM;
  526     static const string STY_NAME_ESC;
  527     static const string STY_NAME_DIR;
  528     static const string STY_NAME_DST;
  529     static const string STY_NAME_LIN;
  530     static const string STY_NAME_SYM;
  531     static const string STY_NAME_IPL;
  532 
  533     /** \param type Output type */
  534     CodeGenerator ( highlight::OutputType type );
  535     CodeGenerator() {};
  536 
  537     /** \param c Character to be masked
  538         \return Escape sequence of output format */
  539     virtual string maskCharacter ( unsigned char c ) = 0;
  540 
  541     /** \param ss destination stream
  542         \param s string */
  543     void maskString ( ostream& ss, const string &s ) ;
  544 
  545     /** Get current line number
  546       \return line number  */
  547     unsigned int getLineNumber();
  548 
  549     vector <string> openTags,   ///< list of format delimiters (open new format descriptions)
  550            closeTags;   ///< list of format delimiters (close format descriptions)
  551 
  552     /** Description of document colour style*/
  553     ThemeReader docStyle;
  554 
  555     /** Language definition*/
  556     SyntaxReader* currentSyntax;
  557 
  558     /** Tag for inserting line feeds*/
  559     string newLineTag;
  560 
  561     /** String that represents a white space in output */
  562     string spacer;
  563 
  564     /** file input*/
  565     istream *in;
  566 
  567     /** file output*/
  568     ostream *out;
  569 
  570     string maskWsBegin,  ///< open whitespace mask
  571            maskWsEnd;    ///< close whitespace mask
  572 
  573     string styleCommentOpen,  ///< open comment delimiter
  574            styleCommentClose; ///< close comment delimiter
  575 
  576     string embedBlockOpen,  ///< open block delimiter to highlight embedded code
  577            embedBlockClose; ///< close block delimiter
  578 
  579     /** Encoding name */
  580     string encoding;
  581 
  582     /** document title */
  583     string docTitle;
  584 
  585     string inFile,   ///< input file name
  586            outFile;  ///< output file name
  587            
  588     /** Test if maskWsBegin and maskWsEnd should be applied */
  589     bool maskWs;
  590 
  591     /** Test if whitespace should always be separated from enclosing tokens */
  592     bool excludeWs;
  593     
  594     /** Test if header and footer should be omitted */
  595     bool fragmentOutput;
  596 
  597     /** Test if plugin injections should be printed if fragmentOutput is true */
  598     bool keepInjections;
  599     
  600     /** Test if line numbers should be printed */
  601     bool showLineNumbers;
  602 
  603     /** Test if leading spyce of line number should be filled with zeroes*/
  604     bool lineNumberFillZeroes;
  605 
  606     /** Flag to test if newlines should be printed */
  607     bool printNewLines;
  608 
  609     /** Test if version info comment printed */
  610     bool omitVersionComment;
  611     
  612     /** Flag to output token of the same syntax category in separate tags */
  613     bool isolateTags;
  614     
  615     bool disableStyleCache;
  616     
  617     /** The base font to use */
  618     string baseFont ;
  619 
  620     /** The base font size to use */
  621     string baseFontSize ;
  622 
  623     /** Current line of input file*/
  624     string line;
  625 
  626     /** Current line number */
  627     unsigned int lineNumber;
  628 
  629     /**output line number count start */
  630     int lineNumberOffset;
  631 
  632     /** Current state*/
  633     State currentState;
  634 
  635     /** history of preceding states in the current line of input code (max 200 entries) */
  636     vector<State> stateTrace;
  637     
  638     /** keyword class id, used to apply the corresponding keyword style*/
  639     unsigned int currentKeywordClass;
  640 
  641     /** Processes origin state */
  642     void processRootState();
  643 
  644     /** \return line break sequence */
  645     virtual string getNewLine();
  646 
  647     /**
  648        \param s current state
  649        \param kwClassID keyword class (has to be set when s=KEYWORD)
  650        \return Index of style tag corresponding to the states
  651     */
  652     unsigned int getStyleID ( State s, unsigned int kwClassID = 0 );
  653 
  654     /** \return current line index */
  655     unsigned int getLineIndex();
  656 
  657     /** \return last line index */
  658     unsigned int getLastLineLength();
  659     
  660     /** print all remaining white space*/
  661     void flushWs(int );
  662 
  663     /** \return Content of user defined input style */
  664     string readUserStyleDef();
  665 
  666     /** \return Style definition of the chosen output format */
  667     virtual string  getStyleDefinition()
  668     {
  669         return "";
  670     };
  671 
  672     /** \return true id encoding is defined */
  673     bool encodingDefined()
  674     {
  675         return StringTools::change_case ( encoding ) !="none";
  676     }
  677 
  678     /** Invoke plugin decorate user function */
  679     Diluculum::LuaValueList callDecorateFct(const string& token);
  680     
  681     /** Invoke plugin decorate line user function 
  682      @param isLineStart set true if line start function should be called, 
  683             otherwise line end function is invoked */
  684     Diluculum::LuaValueList callDecorateLineFct(bool isLineStart);
  685     
  686     /** contains white space, which will be printed after a closing tag */
  687     string wsBuffer;
  688 
  689     /** Flag to test if style definition should be included in output document */
  690     bool includeStyleDef;
  691 
  692     /** Class for line wrapping and tab replacement*/
  693     PreFormatter preFormatter;
  694 
  695     /** Stores if the current line should receive a line number.
  696      *  If the line is just the continuation of a wrapped line,
  697      *  and numberWrappedLines is false, this is set true. */
  698     bool numberCurrentLine;
  699     
  700     /** method to fix output type in Lua state for XHTML and Truecolor 
  701         @param output type */
  702     void setOutputType(OutputType t) { outputType = t; }
  703     
  704 private:
  705 
  706     void printTrace(const string &s);
  707     
  708     CodeGenerator ( const CodeGenerator& ) {}
  709 
  710     CodeGenerator& operator= ( CodeGenerator& )
  711     {
  712         return *this;
  713     }
  714 
  715     /** Insert line number at the beginning of current output line 
  716         @param insertNewLine set true if newline should be outputted
  717      */
  718     virtual void insertLineNumber ( bool insertNewLine=true);
  719 
  720     /** returns output specific document footer
  721         @return footer */
  722     virtual string getFooter() = 0;
  723 
  724     /** returns output specific document header
  725       * @return header */             
  726     virtual string getHeader() = 0;
  727     
  728     /** Prints document header*/
  729     void printHeader();
  730     
  731     /** Prints document body*/
  732     virtual void printBody() = 0;
  733 
  734     /** Prints document footer*/
  735     void printFooter();
  736 
  737     /** initialize tags in specific format according to colouring information 
  738      *  provided in DucumentStyle */
  739     virtual void initOutputTags() = 0;
  740 
  741     /** \param styleID keyword style id
  742         \return  open tag  */
  743     virtual string getKeywordOpenTag ( unsigned int styleID) = 0;
  744 
  745     /** \param styleID keyword style id
  746         \return  close tag  */
  747     virtual string getKeywordCloseTag ( unsigned int styleID) = 0;
  748 
  749     /** open a new tag, set current state to s*/
  750     void openTag ( State s );
  751 
  752     /** close opened tag, clear current state */
  753     void closeTag ( State s );
  754 
  755     /** close Keyword tag of corresponding style ID */
  756     void closeKWTag ( unsigned int styleID );
  757 
  758     /** open Keyword tag of corresponding style ID */
  759     void openKWTag ( unsigned int styleID );
  760 
  761     /// path to style definition file
  762     string themePath;
  763 
  764     /// path to host language definition
  765     string hostLangDefPath;
  766 
  767     /// path to embedded language definition
  768     string embedLangDefPath;
  769 
  770     /// path to plugin input file
  771     string pluginParameter;
  772 
  773     /// name of nested language which starts the input (ie opening delim missing, but closing delim exists)
  774     string embedLangStart;
  775 
  776     /// contains current position in line
  777     unsigned int lineIndex;
  778 
  779     /// contains length of last line
  780     unsigned int lastLineLength;
  781 
  782     /// line index where syntax change takes place
  783     unsigned int syntaxChangeIndex;
  784 
  785     /// line number where syntax change takes place
  786     unsigned int syntaxChangeLineNo;
  787 
  788     /// width of line numbering column
  789     unsigned int lineNumberWidth;
  790 
  791     /**first input line to be processed*/
  792     unsigned int startLineCnt;
  793     unsigned int startLineCntCurFile;
  794     
  795     /**maximum count of input lines to be processed*/
  796     unsigned int maxLineCnt;
  797     
  798     
  799     /**number of files to be processed and counter*/
  800     unsigned int inputFilesCnt;
  801     unsigned int processedFilesCnt;
  802     
  803     /** Flag to test if trailing newline should be printed */
  804     int noTrailingNewLine;
  805 
  806     
  807     /**last character of the last line*/
  808     unsigned char terminatingChar;
  809 
  810     /** Class for reformatting */
  811     astyle::ASFormatter *formatter;
  812 
  813     /** Flag to test if formatting is enabled with current input document*/
  814     bool formattingEnabled;
  815 
  816     /** Flag to test if formatting is possible with current input document*/
  817     bool formattingPossible;
  818 
  819     /** Flag to test if input should be validated (binary or text) */
  820     bool validateInput;
  821 
  822     /** Flag if wrapped lines should receive unique line numbers as well */
  823     bool numberWrappedLines;
  824 
  825     /** indicator if current state was set by Lua hook function */
  826     bool resultOfHook;
  827     
  828     bool lineContainedTestCase;
  829     
  830     bool applySyntaxTestCase;
  831 
  832     bool toggleDynRawString;
  833 
  834     /** flag which determines keyword output (unchangeed, uppercase, lowercase)*/
  835     StringTools::KeywordCase keywordCase;
  836 
  837     /** contains the current token*/
  838     string token;
  839 
  840     string styleInputPath,   ///< style input file path
  841            styleOutputPath;  ///< style output file path
  842 
  843     string userScriptError;  ///< Plug-In script error message
  844 
  845     /** end-of-line delimiter*/
  846     char eolDelimiter;
  847 
  848     /** Resets parser to origin state, call this after every file conversion */
  849     void reset();
  850 
  851     /** read new line from in stream */
  852     bool readNewLine ( string &newLine );
  853 
  854     /** return next character from in stream */
  855     unsigned char getInputChar();
  856 
  857     /** output file type */
  858     OutputType outputType;
  859 
  860     /** return new state */
  861     State getCurrentState (State oldState);
  862     
  863     std::stack<std::string> nestedLangs;
  864 
  865     /* Methods that represent a parsing state */
  866     bool processKeywordState ( State myState );  ///< process keywords
  867     bool processNumberState() ;               ///< process numbers
  868     bool processMultiLineCommentState();      ///< process multi line comments
  869     bool processSingleLineCommentState();     ///< process single line comments
  870     bool processStringState ( State oldState ); ///< process strings
  871     bool processEscapeCharState();            ///< process escape characters
  872     bool processInterpolationState();         ///< process string interpolation sequences
  873     bool processDirectiveState();             ///< process directives
  874     bool processTagState();                   ///< process tags
  875     bool processSymbolState();                ///< process symbols
  876     void processWsState();                    ///< process whitespace
  877     bool processSyntaxChangeState(State myState ); ///< process syntax change of embedded languages
  878     
  879     /* checks whether the given state was defined in the same column of the last parsed input line */
  880     void runSyntaxTestcases(unsigned int column);
  881     
  882     /* returns name of testcase state */
  883     string getTestcaseName(State s, unsigned int kwClass);
  884     
  885     /** print escaped token and clears it
  886        \param flushWhiteSpace set true if white space should be flushed
  887        \param tcase keyword case
  888     */
  889     void printMaskedToken ( bool flushWhiteSpace = true,
  890             StringTools::KeywordCase tcase = StringTools::CASE_UNCHANGED );
  891 
  892     /** association of matched regexes and the corresponding keyword class ids*/
  893     map <int, ReGroup> regexGroups;
  894     
  895     /** history of states per line position in the current line of input code (max 200 entries) */
  896     
  897     struct PositionState {
  898         State state;
  899         unsigned int kwClass;
  900         bool isWhiteSpace;
  901         PositionState(const State s, const unsigned int kwc, bool ws)
  902         : state(s), kwClass(kwc), isWhiteSpace(ws) {
  903             if (s!=KEYWORD) kwClass=0;
  904         }
  905     };
  906     vector<PositionState> stateTraceCurrent, stateTraceTest;
  907 
  908     vector<string> failedPosTests; 
  909     
  910     /** association of syntax definitions and their paths*/
  911     map <string, SyntaxReader*> syntaxReaders;
  912 
  913     /** test for regular expressions
  914         \param line current input line
  915         \param skipState state which should be ignored*/
  916     void matchRegex ( const string &line, State skipState=_UNKNOWN );
  917 
  918     /** \return true if input is no binary stream */
  919     bool validateInputStream();
  920 
  921     /** load syntax description of embedded snippet's language
  922      \param embedLangDefPath path to language definition
  923       \return true if successful */
  924     bool loadEmbeddedLang(const string&embedLangDefPath);
  925 
  926     /** call user script OnStateChange function if defined to confirm state change
  927      \param newState new state
  928      \param oldState old state
  929      */
  930     State validateState(State newState, State oldState);
  931     
  932     unsigned int getCurrentKeywordClassId();
  933   
  934     string getParam(const string& arg, const char* op);
  935     string getParam(const string& arg, const char* op1, const char* op2);
  936     bool isOption(const string& arg, const char* op);
  937     bool isOption(const string& arg, const char* op1, const char* op2);
  938     bool isParamOption(const string& arg, const char* option);
  939     bool isParamOption(const string& arg, const char* option1, const char* option2);
  940   
  941     /**
  942         \param chunk Lua function to be added to the function list
  943     */
  944     void addUserChunk(const Diluculum::LuaFunction& chunk)
  945     {
  946         pluginChunks.push_back(new Diluculum::LuaFunction(chunk));
  947     }
  948     
  949     void applyPluginChunk(const string& fctName, string *result, bool *keepDefault);
  950     
  951     static vector<Diluculum::LuaFunction*> pluginChunks;
  952 };
  953 
  954 }
  955 
  956 #endif