Add an UI to enable/disable specific overlay handlers.
[TortoiseGit.git] / ext / scintilla / src / LexConf.cxx
blobd39317409d6d848c086961a47e01b59d89073bf5
1 // Scintilla source code edit control
2 /** @file LexConf.cxx
3 ** Lexer for Apache Configuration Files.
4 **
5 ** First working version contributed by Ahmad Zawawi <zeus_go64@hotmail.com> on October 28, 2000.
6 ** i created this lexer because i needed something pretty when dealing
7 ** when Apache Configuration files...
8 **/
9 // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
10 // The License.txt file describes the conditions under which this software may be distributed.
12 #include <stdlib.h>
13 #include <string.h>
14 #include <ctype.h>
15 #include <stdio.h>
16 #include <stdarg.h>
18 #include "Platform.h"
20 #include "PropSet.h"
21 #include "Accessor.h"
22 #include "KeyWords.h"
23 #include "Scintilla.h"
24 #include "SciLexer.h"
26 #ifdef SCI_NAMESPACE
27 using namespace Scintilla;
28 #endif
30 static void ColouriseConfDoc(unsigned int startPos, int length, int, WordList *keywordLists[], Accessor &styler)
32 int state = SCE_CONF_DEFAULT;
33 char chNext = styler[startPos];
34 int lengthDoc = startPos + length;
35 // create a buffer large enough to take the largest chunk...
36 char *buffer = new char[length];
37 int bufferCount = 0;
39 // this assumes that we have 2 keyword list in conf.properties
40 WordList &directives = *keywordLists[0];
41 WordList &params = *keywordLists[1];
43 // go through all provided text segment
44 // using the hand-written state machine shown below
45 styler.StartAt(startPos);
46 styler.StartSegment(startPos);
47 for (int i = startPos; i < lengthDoc; i++) {
48 char ch = chNext;
49 chNext = styler.SafeGetCharAt(i + 1);
51 if (styler.IsLeadByte(ch)) {
52 chNext = styler.SafeGetCharAt(i + 2);
53 i++;
54 continue;
56 switch(state) {
57 case SCE_CONF_DEFAULT:
58 if( ch == '\n' || ch == '\r' || ch == '\t' || ch == ' ') {
59 // whitespace is simply ignored here...
60 styler.ColourTo(i,SCE_CONF_DEFAULT);
61 break;
62 } else if( ch == '#' ) {
63 // signals the start of a comment...
64 state = SCE_CONF_COMMENT;
65 styler.ColourTo(i,SCE_CONF_COMMENT);
66 } else if( ch == '.' /*|| ch == '/'*/) {
67 // signals the start of a file...
68 state = SCE_CONF_EXTENSION;
69 styler.ColourTo(i,SCE_CONF_EXTENSION);
70 } else if( ch == '"') {
71 state = SCE_CONF_STRING;
72 styler.ColourTo(i,SCE_CONF_STRING);
73 } else if( ispunct(ch) ) {
74 // signals an operator...
75 // no state jump necessary for this
76 // simple case...
77 styler.ColourTo(i,SCE_CONF_OPERATOR);
78 } else if( isalpha(ch) ) {
79 // signals the start of an identifier
80 bufferCount = 0;
81 buffer[bufferCount++] = static_cast<char>(tolower(ch));
82 state = SCE_CONF_IDENTIFIER;
83 } else if( isdigit(ch) ) {
84 // signals the start of a number
85 bufferCount = 0;
86 buffer[bufferCount++] = ch;
87 //styler.ColourTo(i,SCE_CONF_NUMBER);
88 state = SCE_CONF_NUMBER;
89 } else {
90 // style it the default style..
91 styler.ColourTo(i,SCE_CONF_DEFAULT);
93 break;
95 case SCE_CONF_COMMENT:
96 // if we find a newline here,
97 // we simply go to default state
98 // else continue to work on it...
99 if( ch == '\n' || ch == '\r' ) {
100 state = SCE_CONF_DEFAULT;
101 } else {
102 styler.ColourTo(i,SCE_CONF_COMMENT);
104 break;
106 case SCE_CONF_EXTENSION:
107 // if we find a non-alphanumeric char,
108 // we simply go to default state
109 // else we're still dealing with an extension...
110 if( isalnum(ch) || (ch == '_') ||
111 (ch == '-') || (ch == '$') ||
112 (ch == '/') || (ch == '.') || (ch == '*') )
114 styler.ColourTo(i,SCE_CONF_EXTENSION);
115 } else {
116 state = SCE_CONF_DEFAULT;
117 chNext = styler[i--];
119 break;
121 case SCE_CONF_STRING:
122 // if we find the end of a string char, we simply go to default state
123 // else we're still dealing with an string...
124 if( (ch == '"' && styler.SafeGetCharAt(i-1)!='\\') || (ch == '\n') || (ch == '\r') ) {
125 state = SCE_CONF_DEFAULT;
127 styler.ColourTo(i,SCE_CONF_STRING);
128 break;
130 case SCE_CONF_IDENTIFIER:
131 // stay in CONF_IDENTIFIER state until we find a non-alphanumeric
132 if( isalnum(ch) || (ch == '_') || (ch == '-') || (ch == '/') || (ch == '$') || (ch == '.') || (ch == '*')) {
133 buffer[bufferCount++] = static_cast<char>(tolower(ch));
134 } else {
135 state = SCE_CONF_DEFAULT;
136 buffer[bufferCount] = '\0';
138 // check if the buffer contains a keyword, and highlight it if it is a keyword...
139 if(directives.InList(buffer)) {
140 styler.ColourTo(i-1,SCE_CONF_DIRECTIVE );
141 } else if(params.InList(buffer)) {
142 styler.ColourTo(i-1,SCE_CONF_PARAMETER );
143 } else if(strchr(buffer,'/') || strchr(buffer,'.')) {
144 styler.ColourTo(i-1,SCE_CONF_EXTENSION);
145 } else {
146 styler.ColourTo(i-1,SCE_CONF_DEFAULT);
149 // push back the faulty character
150 chNext = styler[i--];
153 break;
155 case SCE_CONF_NUMBER:
156 // stay in CONF_NUMBER state until we find a non-numeric
157 if( isdigit(ch) || ch == '.') {
158 buffer[bufferCount++] = ch;
159 } else {
160 state = SCE_CONF_DEFAULT;
161 buffer[bufferCount] = '\0';
163 // Colourize here...
164 if( strchr(buffer,'.') ) {
165 // it is an IP address...
166 styler.ColourTo(i-1,SCE_CONF_IP);
167 } else {
168 // normal number
169 styler.ColourTo(i-1,SCE_CONF_NUMBER);
172 // push back a character
173 chNext = styler[i--];
175 break;
179 delete []buffer;
182 static const char * const confWordListDesc[] = {
183 "Directives",
184 "Parameters",
188 LexerModule lmConf(SCLEX_CONF, ColouriseConfDoc, "conf", 0, confWordListDesc);