1
// Scintilla source code edit control
3
** Lexer for Apache Configuration Files.
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...
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.
23
#include "Scintilla.h"
26
static void ColouriseConfDoc(unsigned int startPos, int length, int, WordList *keywordLists[], Accessor &styler)
28
int state = SCE_CONF_DEFAULT;
29
char chNext = styler[startPos];
30
int lengthDoc = startPos + length;
31
// create a buffer large enough to take the largest chunk...
32
char *buffer = new char[length];
35
// this assumes that we have 2 keyword list in conf.properties
36
WordList &directives = *keywordLists[0];
37
WordList ¶ms = *keywordLists[1];
39
// go through all provided text segment
40
// using the hand-written state machine shown below
41
styler.StartAt(startPos);
42
styler.StartSegment(startPos);
43
for (int i = startPos; i < lengthDoc; i++) {
45
chNext = styler.SafeGetCharAt(i + 1);
47
if (styler.IsLeadByte(ch)) {
48
chNext = styler.SafeGetCharAt(i + 2);
53
case SCE_CONF_DEFAULT:
54
if( ch == '\n' || ch == '\r' || ch == '\t' || ch == ' ') {
55
// whitespace is simply ignored here...
56
styler.ColourTo(i,SCE_CONF_DEFAULT);
58
} else if( ch == '#' ) {
59
// signals the start of a comment...
60
state = SCE_CONF_COMMENT;
61
styler.ColourTo(i,SCE_CONF_COMMENT);
62
} else if( ch == '.' /*|| ch == '/'*/) {
63
// signals the start of a file...
64
state = SCE_CONF_EXTENSION;
65
styler.ColourTo(i,SCE_CONF_EXTENSION);
66
} else if( ch == '"') {
67
state = SCE_CONF_STRING;
68
styler.ColourTo(i,SCE_CONF_STRING);
69
} else if( ispunct(ch) ) {
70
// signals an operator...
71
// no state jump necessary for this
73
styler.ColourTo(i,SCE_CONF_OPERATOR);
74
} else if( isalpha(ch) ) {
75
// signals the start of an identifier
77
buffer[bufferCount++] = static_cast<char>(tolower(ch));
78
state = SCE_CONF_IDENTIFIER;
79
} else if( isdigit(ch) ) {
80
// signals the start of a number
82
buffer[bufferCount++] = ch;
83
//styler.ColourTo(i,SCE_CONF_NUMBER);
84
state = SCE_CONF_NUMBER;
86
// style it the default style..
87
styler.ColourTo(i,SCE_CONF_DEFAULT);
91
case SCE_CONF_COMMENT:
92
// if we find a newline here,
93
// we simply go to default state
94
// else continue to work on it...
95
if( ch == '\n' || ch == '\r' ) {
96
state = SCE_CONF_DEFAULT;
98
styler.ColourTo(i,SCE_CONF_COMMENT);
102
case SCE_CONF_EXTENSION:
103
// if we find a non-alphanumeric char,
104
// we simply go to default state
105
// else we're still dealing with an extension...
106
if( isalnum(ch) || (ch == '_') ||
107
(ch == '-') || (ch == '$') ||
108
(ch == '/') || (ch == '.') || (ch == '*') )
110
styler.ColourTo(i,SCE_CONF_EXTENSION);
112
state = SCE_CONF_DEFAULT;
113
chNext = styler[i--];
117
case SCE_CONF_STRING:
118
// if we find the end of a string char, we simply go to default state
119
// else we're still dealing with an string...
120
if( (ch == '"' && styler.SafeGetCharAt(i-1)!='\\') || (ch == '\n') || (ch == '\r') ) {
121
state = SCE_CONF_DEFAULT;
123
styler.ColourTo(i,SCE_CONF_STRING);
126
case SCE_CONF_IDENTIFIER:
127
// stay in CONF_IDENTIFIER state until we find a non-alphanumeric
128
if( isalnum(ch) || (ch == '_') || (ch == '-') || (ch == '/') || (ch == '$') || (ch == '.') || (ch == '*')) {
129
buffer[bufferCount++] = static_cast<char>(tolower(ch));
131
state = SCE_CONF_DEFAULT;
132
buffer[bufferCount] = '\0';
134
// check if the buffer contains a keyword, and highlight it if it is a keyword...
135
if(directives.InList(buffer)) {
136
styler.ColourTo(i-1,SCE_CONF_DIRECTIVE );
137
} else if(params.InList(buffer)) {
138
styler.ColourTo(i-1,SCE_CONF_PARAMETER );
139
} else if(strchr(buffer,'/') || strchr(buffer,'.')) {
140
styler.ColourTo(i-1,SCE_CONF_EXTENSION);
142
styler.ColourTo(i-1,SCE_CONF_DEFAULT);
145
// push back the faulty character
146
chNext = styler[i--];
151
case SCE_CONF_NUMBER:
152
// stay in CONF_NUMBER state until we find a non-numeric
153
if( isdigit(ch) || ch == '.') {
154
buffer[bufferCount++] = ch;
156
state = SCE_CONF_DEFAULT;
157
buffer[bufferCount] = '\0';
160
if( strchr(buffer,'.') ) {
161
// it is an IP address...
162
styler.ColourTo(i-1,SCE_CONF_IP);
165
styler.ColourTo(i-1,SCE_CONF_NUMBER);
168
// push back a character
169
chNext = styler[i--];
178
static const char * const confWordListDesc[] = {
184
LexerModule lmConf(SCLEX_CONF, ColouriseConfDoc, "conf", 0, confWordListDesc);