]>
git.saurik.com Git - wxWidgets.git/blob - 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.
17 #include "Scintilla.h"
20 static void classifyWordSQL(unsigned int start
, unsigned int end
, WordList
&keywords
, Accessor
&styler
) {
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
]));
27 char chAttr
= SCE_C_IDENTIFIER
;
29 chAttr
= SCE_C_NUMBER
;
31 if (keywords
.InList(s
))
34 styler
.ColourTo(end
, chAttr
);
37 static void ColouriseSQLDoc(unsigned int startPos
, int length
,
38 int initStyle
, WordList
*keywordlists
[], Accessor
&styler
) {
40 WordList
&keywords
= *keywordlists
[0];
42 styler
.StartAt(startPos
);
44 bool fold
= styler
.GetPropertyInt("fold");
45 int lineCurrent
= styler
.GetLine(startPos
);
48 int state
= initStyle
;
50 char chNext
= styler
[startPos
];
51 styler
.StartSegment(startPos
);
52 unsigned int lengthDoc
= startPos
+ length
;
53 for (unsigned int i
= startPos
; i
< lengthDoc
; i
++) {
55 chNext
= styler
.SafeGetCharAt(i
+ 1);
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
;
68 styler
.SetLevel(lineCurrent
, lev
);
72 if (styler
.IsLeadByte(ch
)) {
73 chNext
= styler
.SafeGetCharAt(i
+ 2);
79 if (state
== SCE_C_DEFAULT
) {
80 if (iswordstart(ch
)) {
81 styler
.ColourTo(i
- 1, state
);
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
);
92 } else if (isoperator(ch
)) {
93 styler
.ColourTo(i
- 1, state
);
94 styler
.ColourTo(i
, SCE_C_OPERATOR
);
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
);
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
;
119 } else if (state
== SCE_C_COMMENTLINE
) {
120 if (ch
== '\r' || ch
== '\n') {
121 styler
.ColourTo(i
- 1, state
);
122 state
= SCE_C_DEFAULT
;
124 } else if (state
== SCE_C_STRING
) {
126 if ( chNext
== '\'' ) {
129 styler
.ColourTo(i
, state
);
130 state
= SCE_C_DEFAULT
;
134 chNext
= styler
.SafeGetCharAt(i
+ 1);
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
)) {
146 } else if (isoperator(ch
)) {
147 styler
.ColourTo(i
, SCE_C_OPERATOR
);
153 styler
.ColourTo(lengthDoc
- 1, state
);
156 LexerModule
lmSQL(SCLEX_SQL
, ColouriseSQLDoc
);