コード例 #1
0
ファイル: Legacy.cpp プロジェクト: legit-hax/npp-gmod-lua
void LexOrFold(bool foldOrLex, unsigned int startPos, unsigned int length, int initStyle,
               char *words[], WindowID window, char *props)
{
    // Create and initialize the WindowAccessor (including contained PropSet)
    PropSetSimple ps;
    ps.SetMultiple(props);
    WindowAccessor wa(window, ps);

    //  Create and initialize WordList(s).
    //  If you have an extremely large word file, or lots of styling rules you may want to speed
    //  up processing by storing the wordlists instead of reprocessing them on each call.
    int nWL = 0;
    for (; words[nWL]; nWL++) ;	// count # of WordList PTRs needed
    WordList** wl = new WordList* [nWL + 1];// alloc WordList PTRs
    int i = 0;
    for (; i < nWL; i++) {
        wl[i] = new WordList();	// (works or THROWS bad_alloc EXCEPTION)
        wl[i]->Set(words[i]);
    }
    wl[i] = 0;

    //  Call the internal folding and styling functions.
    // foldOrLex is false for lex and true for fold
    if (foldOrLex) {

        // This is a nice helpful routine to back up a line to fix broken folds.
        int lineCurrent = wa.GetLine(startPos);
        if (lineCurrent > 0) {
            lineCurrent--;
            int newStartPos = wa.LineStart(lineCurrent);
            length += startPos - newStartPos;
            startPos = newStartPos;
            initStyle = 0;
            if (startPos > 0) {
                initStyle = wa.StyleAt(startPos - 1);
            }
        }

        Fold_Doc(startPos, length, initStyle, wl, wa);

    }
    else {

        //  You may want to put a routine here to backtrack past leaking styles, typically
        //  multiline styles, or just put such logic in the Colour_Doc function itself.  Just
        //  be sure to do it prior to creating your Style Context.

        Colourise_Doc(startPos, length, initStyle, wl, wa);

    }

    //  The flush function is what actually finalizes settings the styles you just coloured.
    wa.Flush();

    // Clean up the wordlists before leaving.
    for (i = nWL - 1; i >= 0; i--)
        delete wl[i];
    delete [] wl;
}
コード例 #2
0
ファイル: LexHaskell.cpp プロジェクト: 6qat/robomongo
void EXT_LEXER_DECL Lex(unsigned int lexer, unsigned int startPos, int length, int initStyle,
                        char *words[], WindowID window, char *props)
{
   PropSetSimple ps;
   ps.SetMultiple(props);
   WindowAccessor wa(window, ps);

   int nWL = 0;
   for (; words[nWL]; nWL++) ;
   WordList** wl = new WordList* [nWL + 1];
   int i = 0;
   for (; i<nWL; i++)
   {
      wl[i] = new WordList();
      wl[i]->Set(words[i]);
   }
   wl[i] = 0;

   ColorizeHaskellDoc(startPos, length, initStyle, wl, wa);
   wa.Flush();
   for (i=nWL-1;i>=0;i--)
      delete wl[i];
   delete [] wl;
}