]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/lexlib/LexerModule.cxx
Add missing WXK constants for the control keys
[wxWidgets.git] / src / stc / scintilla / lexlib / LexerModule.cxx
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 int styleBits_) :
39 language(language_),
40 fnLexer(fnLexer_),
41 fnFolder(fnFolder_),
42 fnFactory(0),
43 wordListDescriptions(wordListDescriptions_),
44 styleBits(styleBits_),
45 languageName(languageName_) {
46 }
47
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_) {
60 }
61
62 int LexerModule::GetNumWordLists() const {
63 if (wordListDescriptions == NULL) {
64 return -1;
65 } else {
66 int numWordLists = 0;
67
68 while (wordListDescriptions[numWordLists]) {
69 ++numWordLists;
70 }
71
72 return numWordLists;
73 }
74 }
75
76 const char *LexerModule::GetWordListDescription(int index) const {
77 static const char *emptyStr = "";
78
79 assert(index < GetNumWordLists());
80 if (index >= GetNumWordLists()) {
81 return emptyStr;
82 } else {
83 return wordListDescriptions[index];
84 }
85 }
86
87 int LexerModule::GetStyleBitsNeeded() const {
88 return styleBits;
89 }
90
91 ILexer *LexerModule::Create() const {
92 if (fnFactory)
93 return fnFactory();
94 else
95 return new LexerSimple(this);
96 }
97
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);
102 }
103
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);
117 }
118 }
119 fnFolder(startPos, lengthDoc, initStyle, keywordlists, styler);
120 }
121 }