Recognize .exp (Expect) files as Tcl
[geany-mirror.git] / scintilla / lexlib / LexerModule.cxx
blob390bae06e3992f1a9c68a959905e724ada387413
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 language(language_),
39 fnLexer(fnLexer_),
40 fnFolder(fnFolder_),
41 fnFactory(0),
42 wordListDescriptions(wordListDescriptions_),
43 languageName(languageName_) {
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_) {
58 int LexerModule::GetNumWordLists() const {
59 if (wordListDescriptions == NULL) {
60 return -1;
61 } else {
62 int numWordLists = 0;
64 while (wordListDescriptions[numWordLists]) {
65 ++numWordLists;
68 return numWordLists;
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];
81 ILexer *LexerModule::Create() const {
82 if (fnFactory)
83 return fnFactory();
84 else
85 return new LexerSimple(this);
88 void LexerModule::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle,
89 WordList *keywordlists[], Accessor &styler) const {
90 if (fnLexer)
91 fnLexer(startPos, lengthDoc, initStyle, keywordlists, styler);
94 void LexerModule::Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle,
95 WordList *keywordlists[], Accessor &styler) const {
96 if (fnFolder) {
97 Sci_Position lineCurrent = styler.GetLine(startPos);
98 // Move back one line in case deletion wrecked current line fold state
99 if (lineCurrent > 0) {
100 lineCurrent--;
101 Sci_Position newStartPos = styler.LineStart(lineCurrent);
102 lengthDoc += startPos - newStartPos;
103 startPos = newStartPos;
104 initStyle = 0;
105 if (startPos > 0) {
106 initStyle = styler.StyleAt(startPos - 1);
109 fnFolder(startPos, lengthDoc, initStyle, keywordlists, styler);