]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexSQL.cxx
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 int lineCurrent
= styler
.GetLine(startPos
);
50 int state
= initStyle
;
52 char chNext
= styler
[startPos
];
53 styler
.StartSegment(startPos
);
54 unsigned int lengthDoc
= startPos
+ length
;
55 for (unsigned int i
= startPos
; i
< lengthDoc
; i
++) {
57 chNext
= styler
.SafeGetCharAt(i
+ 1);
59 if ((ch
== '\r' && chNext
!= '\n') || (ch
== '\n')) {
60 int indentCurrent
= styler
.IndentAmount(lineCurrent
, &spaceFlags
);
61 int lev
= indentCurrent
;
62 if (!(indentCurrent
& SC_FOLDLEVELWHITEFLAG
)) {
63 // Only non whitespace lines can be headers
64 int indentNext
= styler
.IndentAmount(lineCurrent
+ 1, &spaceFlags
);
65 if (indentCurrent
< (indentNext
& ~SC_FOLDLEVELWHITEFLAG
)) {
66 lev
|= SC_FOLDLEVELHEADERFLAG
;
70 styler
.SetLevel(lineCurrent
, lev
);
74 if (styler
.IsLeadByte(ch
)) {
75 chNext
= styler
.SafeGetCharAt(i
+ 2);
81 if (state
== SCE_C_DEFAULT
) {
82 if (iswordstart(ch
)) {
83 styler
.ColourTo(i
- 1, state
);
85 } else if (ch
== '/' && chNext
== '*') {
86 styler
.ColourTo(i
- 1, state
);
87 state
= SCE_C_COMMENT
;
88 } else if (ch
== '-' && chNext
== '-') {
89 styler
.ColourTo(i
- 1, state
);
90 state
= SCE_C_COMMENTLINE
;
91 } else if (ch
== '\'') {
92 styler
.ColourTo(i
- 1, state
);
93 state
= SCE_C_CHARACTER
;
94 } else if (ch
== '"') {
95 styler
.ColourTo(i
- 1, state
);
97 } else if (isoperator(ch
)) {
98 styler
.ColourTo(i
- 1, state
);
99 styler
.ColourTo(i
, SCE_C_OPERATOR
);
101 } else if (state
== SCE_C_WORD
) {
102 if (!iswordchar(ch
)) {
103 classifyWordSQL(styler
.GetStartSegment(), i
- 1, keywords
, styler
);
104 state
= SCE_C_DEFAULT
;
105 if (ch
== '/' && chNext
== '*') {
106 state
= SCE_C_COMMENT
;
107 } else if (ch
== '-' && chNext
== '-') {
108 state
= SCE_C_COMMENTLINE
;
109 } else if (ch
== '\'') {
110 state
= SCE_C_CHARACTER
;
111 } else if (ch
== '"') {
112 state
= SCE_C_STRING
;
113 } else if (isoperator(ch
)) {
114 styler
.ColourTo(i
, SCE_C_OPERATOR
);
118 if (state
== SCE_C_COMMENT
) {
119 if (ch
== '/' && chPrev
== '*') {
120 if (((i
> (styler
.GetStartSegment() + 2)) || ((initStyle
== SCE_C_COMMENT
) &&
121 (styler
.GetStartSegment() == startPos
)))) {
122 styler
.ColourTo(i
, state
);
123 state
= SCE_C_DEFAULT
;
126 } else if (state
== SCE_C_COMMENTLINE
) {
127 if (ch
== '\r' || ch
== '\n') {
128 styler
.ColourTo(i
- 1, state
);
129 state
= SCE_C_DEFAULT
;
131 } else if (state
== SCE_C_CHARACTER
) {
133 if ( chNext
== '\'' ) {
136 styler
.ColourTo(i
, state
);
137 state
= SCE_C_DEFAULT
;
141 chNext
= styler
.SafeGetCharAt(i
+ 1);
143 } else if (state
== SCE_C_STRING
) {
148 styler
.ColourTo(i
, state
);
149 state
= SCE_C_DEFAULT
;
153 chNext
= styler
.SafeGetCharAt(i
+ 1);
156 if (state
== SCE_C_DEFAULT
) { // One of the above succeeded
157 if (ch
== '/' && chNext
== '*') {
158 state
= SCE_C_COMMENT
;
159 } else if (ch
== '-' && chNext
== '-') {
160 state
= SCE_C_COMMENTLINE
;
161 } else if (ch
== '\'') {
162 state
= SCE_C_CHARACTER
;
163 } else if (ch
== '"') {
164 state
= SCE_C_STRING
;
165 } else if (iswordstart(ch
)) {
167 } else if (isoperator(ch
)) {
168 styler
.ColourTo(i
, SCE_C_OPERATOR
);
174 styler
.ColourTo(lengthDoc
- 1, state
);
177 static const char * const sqlWordListDesc
[] = {
182 LexerModule
lmSQL(SCLEX_SQL
, ColouriseSQLDoc
, "sql", 0, sqlWordListDesc
);