]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexConf.cxx
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"
27 using namespace Scintilla
;
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
];
39 // this assumes that we have 2 keyword list in conf.properties
40 WordList
&directives
= *keywordLists
[0];
41 WordList
¶ms
= *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
++) {
49 chNext
= styler
.SafeGetCharAt(i
+ 1);
51 if (styler
.IsLeadByte(ch
)) {
52 chNext
= styler
.SafeGetCharAt(i
+ 2);
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
);
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
77 styler
.ColourTo(i
,SCE_CONF_OPERATOR
);
78 } else if( isalpha(ch
) ) {
79 // signals the start of an identifier
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
86 buffer
[bufferCount
++] = ch
;
87 //styler.ColourTo(i,SCE_CONF_NUMBER);
88 state
= SCE_CONF_NUMBER
;
90 // style it the default style..
91 styler
.ColourTo(i
,SCE_CONF_DEFAULT
);
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
;
102 styler
.ColourTo(i
,SCE_CONF_COMMENT
);
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
);
116 state
= SCE_CONF_DEFAULT
;
117 chNext
= styler
[i
--];
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
);
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
));
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
);
146 styler
.ColourTo(i
-1,SCE_CONF_DEFAULT
);
149 // push back the faulty character
150 chNext
= styler
[i
--];
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
;
160 state
= SCE_CONF_DEFAULT
;
161 buffer
[bufferCount
] = '\0';
164 if( strchr(buffer
,'.') ) {
165 // it is an IP address...
166 styler
.ColourTo(i
-1,SCE_CONF_IP
);
169 styler
.ColourTo(i
-1,SCE_CONF_NUMBER
);
172 // push back a character
173 chNext
= styler
[i
--];
182 static const char * const confWordListDesc
[] = {
188 LexerModule
lmConf(SCLEX_CONF
, ColouriseConfDoc
, "conf", 0, confWordListDesc
);