~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/sdk/wxscintilla/src/scintilla/lexlib/LexerModule.cxx

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Scintilla source code edit control
 
2
/** @file LexerModule.cxx
 
3
 ** Colourise for particular languages.
 
4
 **/
 
5
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
 
6
// The License.txt file describes the conditions under which this software may be distributed.
 
7
 
 
8
#include <stdlib.h>
 
9
#include <string.h>
 
10
#include <stdio.h>
 
11
#include <stdarg.h>
 
12
#include <assert.h>
 
13
#include <ctype.h>
 
14
 
 
15
#include <string>
 
16
 
 
17
#include "ILexer.h"
 
18
#include "Scintilla.h"
 
19
#include "SciLexer.h"
 
20
 
 
21
#include "PropSetSimple.h"
 
22
#include "WordList.h"
 
23
#include "LexAccessor.h"
 
24
#include "Accessor.h"
 
25
#include "LexerModule.h"
 
26
#include "LexerBase.h"
 
27
#include "LexerSimple.h"
 
28
 
 
29
#ifdef SCI_NAMESPACE
 
30
using namespace Scintilla;
 
31
#endif
 
32
 
 
33
LexerModule::LexerModule(int language_,
 
34
        LexerFunction fnLexer_,
 
35
        const char *languageName_,
 
36
        LexerFunction fnFolder_,
 
37
        const char *const wordListDescriptions_[]) :
 
38
        language(language_),
 
39
        fnLexer(fnLexer_),
 
40
        fnFolder(fnFolder_),
 
41
        fnFactory(0),
 
42
        wordListDescriptions(wordListDescriptions_),
 
43
        languageName(languageName_) {
 
44
}
 
45
 
 
46
LexerModule::LexerModule(int language_,
 
47
        LexerFactoryFunction fnFactory_,
 
48
        const char *languageName_,
 
49
        const char * const wordListDescriptions_[]) :
 
50
        language(language_),
 
51
        fnLexer(0),
 
52
        fnFolder(0),
 
53
        fnFactory(fnFactory_),
 
54
        wordListDescriptions(wordListDescriptions_),
 
55
        languageName(languageName_) {
 
56
}
 
57
 
 
58
int LexerModule::GetNumWordLists() const {
 
59
        if (wordListDescriptions == NULL) {
 
60
                return -1;
 
61
        } else {
 
62
                int numWordLists = 0;
 
63
 
 
64
                while (wordListDescriptions[numWordLists]) {
 
65
                        ++numWordLists;
 
66
                }
 
67
 
 
68
                return numWordLists;
 
69
        }
 
70
}
 
71
 
 
72
const char *LexerModule::GetWordListDescription(int index) const {
 
73
        assert(index < GetNumWordLists());
 
74
        if (!wordListDescriptions || (index >= GetNumWordLists())) {
 
75
                return "";
 
76
        } else {
 
77
                return wordListDescriptions[index];
 
78
        }
 
79
}
 
80
 
 
81
ILexer *LexerModule::Create() const {
 
82
        if (fnFactory)
 
83
                return fnFactory();
 
84
        else
 
85
                return new LexerSimple(this);
 
86
}
 
87
 
 
88
void LexerModule::Lex(unsigned int startPos, int lengthDoc, int initStyle,
 
89
          WordList *keywordlists[], Accessor &styler) const {
 
90
        if (fnLexer)
 
91
                fnLexer(startPos, lengthDoc, initStyle, keywordlists, styler);
 
92
}
 
93
 
 
94
void LexerModule::Fold(unsigned int startPos, int lengthDoc, int initStyle,
 
95
          WordList *keywordlists[], Accessor &styler) const {
 
96
        if (fnFolder) {
 
97
                int lineCurrent = styler.GetLine(startPos);
 
98
                // Move back one line in case deletion wrecked current line fold state
 
99
                if (lineCurrent > 0) {
 
100
                        lineCurrent--;
 
101
                        int newStartPos = styler.LineStart(lineCurrent);
 
102
                        lengthDoc += startPos - newStartPos;
 
103
                        startPos = newStartPos;
 
104
                        initStyle = 0;
 
105
                        if (startPos > 0) {
 
106
                                initStyle = styler.StyleAt(startPos - 1);
 
107
                        }
 
108
                }
 
109
                fnFolder(startPos, lengthDoc, initStyle, keywordlists, styler);
 
110
        }
 
111
}