]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexSQL.cxx
fixed wxListBox inheritance
[wxWidgets.git] / src / stc / scintilla / src / LexSQL.cxx
1 // SciTE - Scintilla based Text Editor
2 // LexSQL.cxx - lexer for SQL
3 // Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
4 // The License.txt file describes the conditions under which this software may be distributed.
5
6 #include <stdlib.h>
7 #include <string.h>
8 #include <ctype.h>
9 #include <stdio.h>
10 #include <stdarg.h>
11
12 #include "Platform.h"
13
14 #include "PropSet.h"
15 #include "Accessor.h"
16 #include "KeyWords.h"
17 #include "Scintilla.h"
18 #include "SciLexer.h"
19
20 static void classifyWordSQL(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler) {
21 char s[100];
22 bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
23 for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
24 s[i] = static_cast<char>(toupper(styler[start + i]));
25 s[i + 1] = '\0';
26 }
27 char chAttr = SCE_C_IDENTIFIER;
28 if (wordIsNumber)
29 chAttr = SCE_C_NUMBER;
30 else {
31 if (keywords.InList(s))
32 chAttr = SCE_C_WORD;
33 }
34 styler.ColourTo(end, chAttr);
35 }
36
37 static void ColouriseSQLDoc(unsigned int startPos, int length,
38 int initStyle, WordList *keywordlists[], Accessor &styler) {
39
40 WordList &keywords = *keywordlists[0];
41
42 styler.StartAt(startPos);
43
44 bool fold = styler.GetPropertyInt("fold");
45 int lineCurrent = styler.GetLine(startPos);
46 int spaceFlags = 0;
47
48 int state = initStyle;
49 char chPrev = ' ';
50 char chNext = styler[startPos];
51 styler.StartSegment(startPos);
52 unsigned int lengthDoc = startPos + length;
53 for (unsigned int i = startPos; i < lengthDoc; i++) {
54 char ch = chNext;
55 chNext = styler.SafeGetCharAt(i + 1);
56
57 if ((ch == '\r' && chNext != '\n') || (ch == '\n')) {
58 int indentCurrent = styler.IndentAmount(lineCurrent, &spaceFlags);
59 int lev = indentCurrent;
60 if (!(indentCurrent & SC_FOLDLEVELWHITEFLAG)) {
61 // Only non whitespace lines can be headers
62 int indentNext = styler.IndentAmount(lineCurrent + 1, &spaceFlags);
63 if (indentCurrent < (indentNext & ~SC_FOLDLEVELWHITEFLAG)) {
64 lev |= SC_FOLDLEVELHEADERFLAG;
65 }
66 }
67 if (fold) {
68 styler.SetLevel(lineCurrent, lev);
69 }
70 }
71
72 if (styler.IsLeadByte(ch)) {
73 chNext = styler.SafeGetCharAt(i + 2);
74 chPrev = ' ';
75 i += 1;
76 continue;
77 }
78
79 if (state == SCE_C_DEFAULT) {
80 if (iswordstart(ch)) {
81 styler.ColourTo(i - 1, state);
82 state = SCE_C_WORD;
83 } else if (ch == '/' && chNext == '*') {
84 styler.ColourTo(i - 1, state);
85 state = SCE_C_COMMENT;
86 } else if (ch == '-' && chNext == '-') {
87 styler.ColourTo(i - 1, state);
88 state = SCE_C_COMMENTLINE;
89 } else if (ch == '\'') {
90 styler.ColourTo(i - 1, state);
91 state = SCE_C_STRING;
92 } else if (isoperator(ch)) {
93 styler.ColourTo(i - 1, state);
94 styler.ColourTo(i, SCE_C_OPERATOR);
95 }
96 } else if (state == SCE_C_WORD) {
97 if (!iswordchar(ch)) {
98 classifyWordSQL(styler.GetStartSegment(), i - 1, keywords, styler);
99 state = SCE_C_DEFAULT;
100 if (ch == '/' && chNext == '*') {
101 state = SCE_C_COMMENT;
102 } else if (ch == '-' && chNext == '-') {
103 state = SCE_C_COMMENTLINE;
104 } else if (ch == '\'') {
105 state = SCE_C_STRING;
106 } else if (isoperator(ch)) {
107 styler.ColourTo(i, SCE_C_OPERATOR);
108 }
109 }
110 } else {
111 if (state == SCE_C_COMMENT) {
112 if (ch == '/' && chPrev == '*') {
113 if (((i > (styler.GetStartSegment() + 2)) || ((initStyle == SCE_C_COMMENT) &&
114 (styler.GetStartSegment() == startPos)))) {
115 styler.ColourTo(i, state);
116 state = SCE_C_DEFAULT;
117 }
118 }
119 } else if (state == SCE_C_COMMENTLINE) {
120 if (ch == '\r' || ch == '\n') {
121 styler.ColourTo(i - 1, state);
122 state = SCE_C_DEFAULT;
123 }
124 } else if (state == SCE_C_STRING) {
125 if (ch == '\'') {
126 if ( chNext == '\'' ) {
127 i++;
128 } else {
129 styler.ColourTo(i, state);
130 state = SCE_C_DEFAULT;
131 i++;
132 }
133 ch = chNext;
134 chNext = styler.SafeGetCharAt(i + 1);
135 }
136 }
137 if (state == SCE_C_DEFAULT) { // One of the above succeeded
138 if (ch == '/' && chNext == '*') {
139 state = SCE_C_COMMENT;
140 } else if (ch == '-' && chNext == '-') {
141 state = SCE_C_COMMENTLINE;
142 } else if (ch == '\'') {
143 state = SCE_C_STRING;
144 } else if (iswordstart(ch)) {
145 state = SCE_C_WORD;
146 } else if (isoperator(ch)) {
147 styler.ColourTo(i, SCE_C_OPERATOR);
148 }
149 }
150 }
151 chPrev = ch;
152 }
153 styler.ColourTo(lengthDoc - 1, state);
154 }
155
156 LexerModule lmSQL(SCLEX_SQL, ColouriseSQLDoc);