]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexSQL.cxx
0f29c830749f36e65afbd6d8fe1f8734c9ebc75f
   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
, StylingContext 
&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
] = 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
[], StylingContext 
&styler
) { 
  40         WordList 
&keywords 
= *keywordlists
[0]; 
  42         styler
.StartAt(startPos
); 
  44         bool fold 
= styler
.GetPropSet().GetInt("fold"); 
  45         int lineCurrent 
= styler
.GetLine(startPos
); 
  47         int indentCurrent 
= 0; 
  49         int state 
= initStyle
; 
  51         char chNext 
= styler
[startPos
]; 
  52         styler
.StartSegment(startPos
); 
  53         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                         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
); 
  94                         } else if (isoperator(ch
)) { 
  95                                 styler
.ColourTo(i 
- 1, state
); 
  96                                 styler
.ColourTo(i
, SCE_C_OPERATOR
); 
  98                 } else if (state 
== SCE_C_WORD
) { 
  99                         if (!iswordchar(ch
)) { 
 100                                 classifyWordSQL(styler
.GetStartSegment(), i 
- 1, keywords
, styler
); 
 101                                 state 
= SCE_C_DEFAULT
; 
 102                                 if (ch 
== '/' && chNext 
== '*') { 
 103                                         state 
= SCE_C_COMMENT
; 
 104                                 } else if (ch 
== '-' && chNext 
== '-') { 
 105                                         state 
= SCE_C_COMMENTLINE
; 
 106                                 } else if (ch 
== '\'') { 
 107                                         state 
= SCE_C_STRING
; 
 108                                 } else if (isoperator(ch
)) { 
 109                                         styler
.ColourTo(i
, SCE_C_OPERATOR
); 
 113                         if (state 
== SCE_C_COMMENT
) { 
 114                                 if (ch 
== '/' && chPrev 
== '*') { 
 115                                         if (((i 
> (styler
.GetStartSegment() + 2)) || ((initStyle 
== SCE_C_COMMENT
) && 
 116                                             (styler
.GetStartSegment() == startPos
)))) { 
 117                                                 styler
.ColourTo(i
, state
); 
 118                                                 state 
= SCE_C_DEFAULT
; 
 121                         } else if (state 
== SCE_C_COMMENTLINE
) { 
 122                                 if (ch 
== '\r' || ch 
== '\n') { 
 123                                         styler
.ColourTo(i 
- 1, state
); 
 124                                         state 
= SCE_C_DEFAULT
; 
 126                         } else if (state 
== SCE_C_STRING
) { 
 128                                         if ( chNext 
== '\'' ) { 
 131                                                 styler
.ColourTo(i
, state
); 
 132                                                 state 
= SCE_C_DEFAULT
; 
 136                                         chNext 
= styler
.SafeGetCharAt(i 
+ 1); 
 139                         if (state 
== SCE_C_DEFAULT
) {    // One of the above succeeded 
 140                                 if (ch 
== '/' && chNext 
== '*') { 
 141                                         state 
= SCE_C_COMMENT
; 
 142                                 } else if (ch 
== '-' && chNext 
== '-') { 
 143                                         state 
= SCE_C_COMMENTLINE
; 
 144                                 } else if (ch 
== '\'') { 
 145                                         state 
= SCE_C_STRING
; 
 146                                 } else if (iswordstart(ch
)) { 
 148                                 } else if (isoperator(ch
)) { 
 149                                         styler
.ColourTo(i
, SCE_C_OPERATOR
); 
 155         styler
.ColourTo(lengthDoc 
- 1, state
); 
 158 LexerModule 
lmSQL(SCLEX_SQL
, ColouriseSQLDoc
);