scintilla: Update scintilla with changeset 3662:1d1c06df8a2f using gtk+3
[anjuta-extras.git] / plugins / scintilla / scintilla / LexerModule.cxx
blobdefc86356a5422361ba6ad670bed16b1eb622365
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.
8 #include <stdlib.h>
9 #include <string.h>
10 #include <stdio.h>
11 #include <stdarg.h>
12 #include <assert.h>
13 #include <ctype.h>
15 #include <string>
17 #include "ILexer.h"
18 #include "Scintilla.h"
19 #include "SciLexer.h"
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"
29 #ifdef SCI_NAMESPACE
30 using namespace Scintilla;
31 #endif
33 LexerModule::LexerModule(int language_,
34 LexerFunction fnLexer_,
35 const char *languageName_,
36 LexerFunction fnFolder_,
37 const char *const wordListDescriptions_[],
38 int styleBits_) :
39 language(language_),
40 fnLexer(fnLexer_),
41 fnFolder(fnFolder_),
42 fnFactory(0),
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_[],
52 int styleBits_) :
53 language(language_),
54 fnLexer(0),
55 fnFolder(0),
56 fnFactory(fnFactory_),
57 wordListDescriptions(wordListDescriptions_),
58 styleBits(styleBits_),
59 languageName(languageName_) {
62 int LexerModule::GetNumWordLists() const {
63 if (wordListDescriptions == NULL) {
64 return -1;
65 } else {
66 int numWordLists = 0;
68 while (wordListDescriptions[numWordLists]) {
69 ++numWordLists;
72 return numWordLists;
76 const char *LexerModule::GetWordListDescription(int index) const {
77 static const char *emptyStr = "";
79 assert(index < GetNumWordLists());
80 if (index >= GetNumWordLists()) {
81 return emptyStr;
82 } else {
83 return wordListDescriptions[index];
87 int LexerModule::GetStyleBitsNeeded() const {
88 return styleBits;
91 ILexer *LexerModule::Create() const {
92 if (fnFactory)
93 return fnFactory();
94 else
95 return new LexerSimple(this);
98 void LexerModule::Lex(unsigned int startPos, int lengthDoc, int initStyle,
99 WordList *keywordlists[], Accessor &styler) const {
100 if (fnLexer)
101 fnLexer(startPos, lengthDoc, initStyle, keywordlists, styler);
104 void LexerModule::Fold(unsigned int startPos, int lengthDoc, int initStyle,
105 WordList *keywordlists[], Accessor &styler) const {
106 if (fnFolder) {
107 int lineCurrent = styler.GetLine(startPos);
108 // Move back one line in case deletion wrecked current line fold state
109 if (lineCurrent > 0) {
110 lineCurrent--;
111 int newStartPos = styler.LineStart(lineCurrent);
112 lengthDoc += startPos - newStartPos;
113 startPos = newStartPos;
114 initStyle = 0;
115 if (startPos > 0) {
116 initStyle = styler.StyleAt(startPos - 1);
119 fnFolder(startPos, lengthDoc, initStyle, keywordlists, styler);