1 // Scintilla source code edit control
2 /** @file LexerModule.cxx
3 ** Colourise for particular languages.
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.
18 #include "Scintilla.h"
21 #include "PropSetSimple.h"
23 #include "LexAccessor.h"
25 #include "LexerModule.h"
26 #include "LexerBase.h"
27 #include "LexerSimple.h"
30 using namespace Scintilla
;
33 LexerModule::LexerModule(int language_
,
34 LexerFunction fnLexer_
,
35 const char *languageName_
,
36 LexerFunction fnFolder_
,
37 const char *const wordListDescriptions_
[],
43 wordListDescriptions(wordListDescriptions_
),
44 styleBits(styleBits_
),
45 languageName(languageName_
) {
48 LexerModule::LexerModule(int language_
,
49 LexerFactoryFunction fnFactory_
,
50 const char *languageName_
,
51 const char * const wordListDescriptions_
[],
56 fnFactory(fnFactory_
),
57 wordListDescriptions(wordListDescriptions_
),
58 styleBits(styleBits_
),
59 languageName(languageName_
) {
62 int LexerModule::GetNumWordLists() const {
63 if (wordListDescriptions
== NULL
) {
68 while (wordListDescriptions
[numWordLists
]) {
76 const char *LexerModule::GetWordListDescription(int index
) const {
77 static const char *emptyStr
= "";
79 assert(index
< GetNumWordLists());
80 if (index
>= GetNumWordLists()) {
83 return wordListDescriptions
[index
];
87 int LexerModule::GetStyleBitsNeeded() const {
91 ILexer
*LexerModule::Create() const {
95 return new LexerSimple(this);
98 void LexerModule::Lex(unsigned int startPos
, int lengthDoc
, int initStyle
,
99 WordList
*keywordlists
[], Accessor
&styler
) const {
101 fnLexer(startPos
, lengthDoc
, initStyle
, keywordlists
, styler
);
104 void LexerModule::Fold(unsigned int startPos
, int lengthDoc
, int initStyle
,
105 WordList
*keywordlists
[], Accessor
&styler
) const {
107 int lineCurrent
= styler
.GetLine(startPos
);
108 // Move back one line in case deletion wrecked current line fold state
109 if (lineCurrent
> 0) {
111 int newStartPos
= styler
.LineStart(lineCurrent
);
112 lengthDoc
+= startPos
- newStartPos
;
113 startPos
= newStartPos
;
116 initStyle
= styler
.StyleAt(startPos
- 1);
119 fnFolder(startPos
, lengthDoc
, initStyle
, keywordlists
, styler
);