]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/LexSQL.cxx
8383eefb02efc556081b55b734ab2e521ad6aece
1 // Scintilla source code edit control
5 // Copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
19 #include "Scintilla.h"
22 static void classifyWordSQL(unsigned int start
, unsigned int end
, WordList
&keywords
, Accessor
&styler
) {
24 bool wordIsNumber
= isdigit(styler
[start
]) || (styler
[start
] == '.');
25 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
26 s
[i
] = static_cast<char>(tolower(styler
[start
+ i
]));
29 char chAttr
= SCE_C_IDENTIFIER
;
31 chAttr
= SCE_C_NUMBER
;
33 if (keywords
.InList(s
))
36 styler
.ColourTo(end
, chAttr
);
39 static void ColouriseSQLDoc(unsigned int startPos
, int length
,
40 int initStyle
, WordList
*keywordlists
[], Accessor
&styler
) {
42 WordList
&keywords
= *keywordlists
[0];
44 styler
.StartAt(startPos
);
46 bool fold
= styler
.GetPropertyInt("fold") != 0;
47 bool sqlBackslashEscapes
= styler
.GetPropertyInt("sql.backslash.escapes", 0) != 0;
48 int lineCurrent
= styler
.GetLine(startPos
);
51 int state
= initStyle
;
53 char chNext
= styler
[startPos
];
54 styler
.StartSegment(startPos
);
55 unsigned int lengthDoc
= startPos
+ length
;
56 for (unsigned int i
= startPos
; i
< lengthDoc
; i
++) {
58 chNext
= styler
.SafeGetCharAt(i
+ 1);
60 if ((ch
== '\r' && chNext
!= '\n') || (ch
== '\n')) {
61 int indentCurrent
= styler
.IndentAmount(lineCurrent
, &spaceFlags
);
62 int lev
= indentCurrent
;
63 if (!(indentCurrent
& SC_FOLDLEVELWHITEFLAG
)) {
64 // Only non whitespace lines can be headers
65 int indentNext
= styler
.IndentAmount(lineCurrent
+ 1, &spaceFlags
);
66 if (indentCurrent
< (indentNext
& ~SC_FOLDLEVELWHITEFLAG
)) {
67 lev
|= SC_FOLDLEVELHEADERFLAG
;
71 styler
.SetLevel(lineCurrent
, lev
);
75 if (styler
.IsLeadByte(ch
)) {
76 chNext
= styler
.SafeGetCharAt(i
+ 2);
82 if (state
== SCE_C_DEFAULT
) {
83 if (iswordstart(ch
)) {
84 styler
.ColourTo(i
- 1, state
);
86 } else if (ch
== '/' && chNext
== '*') {
87 styler
.ColourTo(i
- 1, state
);
88 state
= SCE_C_COMMENT
;
89 } else if (ch
== '-' && chNext
== '-') {
90 styler
.ColourTo(i
- 1, state
);
91 state
= SCE_C_COMMENTLINE
;
92 } else if (ch
== '#') {
93 styler
.ColourTo(i
- 1, state
);
94 state
= SCE_C_COMMENTLINEDOC
;
95 } else if (ch
== '\'') {
96 styler
.ColourTo(i
- 1, state
);
97 state
= SCE_C_CHARACTER
;
98 } else if (ch
== '"') {
99 styler
.ColourTo(i
- 1, state
);
100 state
= SCE_C_STRING
;
101 } else if (isoperator(ch
)) {
102 styler
.ColourTo(i
- 1, state
);
103 styler
.ColourTo(i
, SCE_C_OPERATOR
);
105 } else if (state
== SCE_C_WORD
) {
106 if (!iswordchar(ch
)) {
107 classifyWordSQL(styler
.GetStartSegment(), i
- 1, keywords
, styler
);
108 state
= SCE_C_DEFAULT
;
109 if (ch
== '/' && chNext
== '*') {
110 state
= SCE_C_COMMENT
;
111 } else if (ch
== '-' && chNext
== '-') {
112 state
= SCE_C_COMMENTLINE
;
113 } else if (ch
== '#') {
114 state
= SCE_C_COMMENTLINEDOC
;
115 } else if (ch
== '\'') {
116 state
= SCE_C_CHARACTER
;
117 } else if (ch
== '"') {
118 state
= SCE_C_STRING
;
119 } else if (isoperator(ch
)) {
120 styler
.ColourTo(i
, SCE_C_OPERATOR
);
124 if (state
== SCE_C_COMMENT
) {
125 if (ch
== '/' && chPrev
== '*') {
126 if (((i
> (styler
.GetStartSegment() + 2)) || ((initStyle
== SCE_C_COMMENT
) &&
127 (styler
.GetStartSegment() == startPos
)))) {
128 styler
.ColourTo(i
, state
);
129 state
= SCE_C_DEFAULT
;
132 } else if (state
== SCE_C_COMMENTLINE
|| state
== SCE_C_COMMENTLINEDOC
) {
133 if (ch
== '\r' || ch
== '\n') {
134 styler
.ColourTo(i
- 1, state
);
135 state
= SCE_C_DEFAULT
;
137 } else if (state
== SCE_C_CHARACTER
) {
138 if (sqlBackslashEscapes
&& ch
== '\\') {
141 chNext
= styler
.SafeGetCharAt(i
+ 1);
142 } else if (ch
== '\'') {
143 if (chNext
== '\'') {
146 styler
.ColourTo(i
, state
);
147 state
= SCE_C_DEFAULT
;
151 chNext
= styler
.SafeGetCharAt(i
+ 1);
153 } else if (state
== SCE_C_STRING
) {
158 styler
.ColourTo(i
, state
);
159 state
= SCE_C_DEFAULT
;
163 chNext
= styler
.SafeGetCharAt(i
+ 1);
166 if (state
== SCE_C_DEFAULT
) { // One of the above succeeded
167 if (ch
== '/' && chNext
== '*') {
168 state
= SCE_C_COMMENT
;
169 } else if (ch
== '-' && chNext
== '-') {
170 state
= SCE_C_COMMENTLINE
;
171 } else if (ch
== '#') {
172 state
= SCE_C_COMMENTLINEDOC
;
173 } else if (ch
== '\'') {
174 state
= SCE_C_CHARACTER
;
175 } else if (ch
== '"') {
176 state
= SCE_C_STRING
;
177 } else if (iswordstart(ch
)) {
179 } else if (isoperator(ch
)) {
180 styler
.ColourTo(i
, SCE_C_OPERATOR
);
186 styler
.ColourTo(lengthDoc
- 1, state
);
189 static const char * const sqlWordListDesc
[] = {
194 LexerModule
lmSQL(SCLEX_SQL
, ColouriseSQLDoc
, "sql", 0, sqlWordListDesc
);