]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/lexers/LexGui4Cli.cxx
1 // Scintilla source code edit control
2 // Copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org>
4 This is the Lexer for Gui4Cli, included in SciLexer.dll
5 - by d. Keletsekis, 2/10/2003
7 To add to SciLexer.dll:
8 1. Add the values below to INCLUDE\Scintilla.iface
9 2. Run the include/HFacer.py script
10 3. Run the src/lexGen.py script
13 val SCE_GC_COMMENTLINE=1
14 val SCE_GC_COMMENTBLOCK=2
17 val SCE_GC_ATTRIBUTE=5
32 #include "Scintilla.h"
36 #include "LexAccessor.h"
38 #include "StyleContext.h"
39 #include "CharacterSet.h"
40 #include "LexerModule.h"
43 using namespace Scintilla
;
46 #define debug Platform::DebugPrintf
48 static inline bool IsAWordChar(const int ch
) {
49 return (ch
< 0x80) && (isalnum(ch
) || ch
== '.' || ch
== '_' || ch
=='\\');
52 static inline bool IsAWordStart(const int ch
) {
53 return (ch
< 0x80) && (isalnum(ch
) || ch
== '_' || ch
== '.');
56 inline bool isGCOperator(int ch
)
59 // '.' left out as it is used to make up numbers
60 if (ch
== '*' || ch
== '/' || ch
== '-' || ch
== '+' ||
61 ch
== '(' || ch
== ')' || ch
== '=' || ch
== '%' ||
62 ch
== '[' || ch
== ']' || ch
== '<' || ch
== '>' ||
63 ch
== ',' || ch
== ';' || ch
== ':')
68 #define isSpace(x) ((x)==' ' || (x)=='\t')
69 #define isNL(x) ((x)=='\n' || (x)=='\r')
70 #define isSpaceOrNL(x) (isSpace(x) || isNL(x))
72 #define isFoldPoint(x) ((styler.LevelAt(x) & SC_FOLDLEVELNUMBERMASK) == 1024)
74 static void colorFirstWord(WordList
*keywordlists
[], Accessor
&styler
,
75 StyleContext
*sc
, char *buff
, int length
, int)
78 while (sc
->More() && isSpaceOrNL(sc
->ch
))
81 styler
.ColourTo(sc
->currentPos
- 1, sc
->state
);
83 if (!IsAWordChar(sc
->ch
)) // comment, marker, etc..
86 while (sc
->More() && !isSpaceOrNL(sc
->ch
) && (c
< length
-1) && !isGCOperator(sc
->ch
))
87 { buff
[c
] = static_cast<char>(sc
->ch
);
92 while (*p
) // capitalize..
93 { if (islower(*p
)) *p
= static_cast<char>(toupper(*p
));
97 WordList
&kGlobal
= *keywordlists
[0]; // keyword lists set by the user
98 WordList
&kEvent
= *keywordlists
[1];
99 WordList
&kAttribute
= *keywordlists
[2];
100 WordList
&kControl
= *keywordlists
[3];
101 WordList
&kCommand
= *keywordlists
[4];
104 // int level = styler.LevelAt(line) & SC_FOLDLEVELNUMBERMASK;
105 // debug ("line = %d, level = %d", line, level);
107 if (kGlobal
.InList(buff
)) state
= SCE_GC_GLOBAL
;
108 else if (kAttribute
.InList(buff
)) state
= SCE_GC_ATTRIBUTE
;
109 else if (kControl
.InList(buff
)) state
= SCE_GC_CONTROL
;
110 else if (kCommand
.InList(buff
)) state
= SCE_GC_COMMAND
;
111 else if (kEvent
.InList(buff
)) state
= SCE_GC_EVENT
;
114 { sc
->ChangeState(state
);
115 styler
.ColourTo(sc
->currentPos
- 1, sc
->state
);
116 sc
->ChangeState(SCE_GC_DEFAULT
);
119 { sc
->ChangeState(SCE_GC_DEFAULT
);
120 styler
.ColourTo(sc
->currentPos
- 1, sc
->state
);
124 // Main colorizing function called by Scintilla
126 ColouriseGui4CliDoc(unsigned int startPos
, int length
, int initStyle
,
127 WordList
*keywordlists
[], Accessor
&styler
)
129 styler
.StartAt(startPos
);
131 int quotestart
= 0, oldstate
, currentline
= styler
.GetLine(startPos
);
132 styler
.StartSegment(startPos
);
134 char buff
[BUFFSIZE
+1]; // buffer for command name
136 StyleContext
sc(startPos
, length
, initStyle
, styler
);
137 buff
[0] = '\0'; // cbuff = 0;
139 if (sc
.state
!= SCE_GC_COMMENTBLOCK
) // colorize 1st word..
140 colorFirstWord(keywordlists
, styler
, &sc
, buff
, BUFFSIZE
, currentline
);
148 if (sc
.state
== SCE_GC_COMMENTBLOCK
|| sc
.state
== SCE_GC_STRING
)
150 if (sc
.chNext
== '/') // line comment
151 { sc
.SetState (SCE_GC_COMMENTLINE
);
153 styler
.ColourTo(sc
.currentPos
, sc
.state
);
155 else if (sc
.chNext
== '*') // block comment
156 { sc
.SetState(SCE_GC_COMMENTBLOCK
);
158 styler
.ColourTo(sc
.currentPos
, sc
.state
);
161 styler
.ColourTo(sc
.currentPos
, sc
.state
);
164 case '*': // end of comment block, or operator..
165 if (sc
.state
== SCE_GC_STRING
)
167 if (sc
.state
== SCE_GC_COMMENTBLOCK
&& sc
.chNext
== '/')
169 styler
.ColourTo(sc
.currentPos
, sc
.state
);
170 sc
.ChangeState (SCE_GC_DEFAULT
);
173 styler
.ColourTo(sc
.currentPos
, sc
.state
);
176 case '\'': case '\"': // strings..
177 if (sc
.state
== SCE_GC_COMMENTBLOCK
|| sc
.state
== SCE_GC_COMMENTLINE
)
179 if (sc
.state
== SCE_GC_STRING
)
180 { if (sc
.ch
== quotestart
) // match same quote char..
181 { styler
.ColourTo(sc
.currentPos
, sc
.state
);
182 sc
.ChangeState(SCE_GC_DEFAULT
);
186 { styler
.ColourTo(sc
.currentPos
- 1, sc
.state
);
187 sc
.ChangeState(SCE_GC_STRING
);
192 case ';': // end of commandline character
193 if (sc
.state
!= SCE_GC_COMMENTBLOCK
&& sc
.state
!= SCE_GC_COMMENTLINE
&&
194 sc
.state
!= SCE_GC_STRING
)
196 styler
.ColourTo(sc
.currentPos
- 1, sc
.state
);
197 styler
.ColourTo(sc
.currentPos
, SCE_GC_OPERATOR
);
198 sc
.ChangeState(SCE_GC_DEFAULT
);
200 colorFirstWord(keywordlists
, styler
, &sc
, buff
, BUFFSIZE
, currentline
);
201 noforward
= 1; // don't move forward - already positioned at next char..
205 case '+': case '-': case '=': case '!': // operators..
206 case '<': case '>': case '&': case '|': case '$':
207 if (sc
.state
!= SCE_GC_COMMENTBLOCK
&& sc
.state
!= SCE_GC_COMMENTLINE
&&
208 sc
.state
!= SCE_GC_STRING
)
210 styler
.ColourTo(sc
.currentPos
- 1, sc
.state
);
211 styler
.ColourTo(sc
.currentPos
, SCE_GC_OPERATOR
);
212 sc
.ChangeState(SCE_GC_DEFAULT
);
216 case '\\': // escape - same as operator, but also mark in strings..
217 if (sc
.state
!= SCE_GC_COMMENTBLOCK
&& sc
.state
!= SCE_GC_COMMENTLINE
)
220 styler
.ColourTo(sc
.currentPos
- 1, sc
.state
);
221 sc
.Forward(); // mark also the next char..
222 styler
.ColourTo(sc
.currentPos
, SCE_GC_OPERATOR
);
223 sc
.ChangeState(oldstate
);
227 case '\n': case '\r':
229 if (sc
.state
== SCE_GC_COMMENTLINE
)
230 { styler
.ColourTo(sc
.currentPos
, sc
.state
);
231 sc
.ChangeState (SCE_GC_DEFAULT
);
233 else if (sc
.state
!= SCE_GC_COMMENTBLOCK
)
234 { colorFirstWord(keywordlists
, styler
, &sc
, buff
, BUFFSIZE
, currentline
);
235 noforward
= 1; // don't move forward - already positioned at next char..
239 // case ' ': case '\t':
243 if (!noforward
) sc
.Forward();
249 // Main folding function called by Scintilla - (based on props (.ini) files function)
250 static void FoldGui4Cli(unsigned int startPos
, int length
, int,
251 WordList
*[], Accessor
&styler
)
253 bool foldCompact
= styler
.GetPropertyInt("fold.compact", 1) != 0;
255 unsigned int endPos
= startPos
+ length
;
256 int visibleChars
= 0;
257 int lineCurrent
= styler
.GetLine(startPos
);
259 char chNext
= styler
[startPos
];
260 int styleNext
= styler
.StyleAt(startPos
);
261 bool headerPoint
= false;
263 for (unsigned int i
= startPos
; i
< endPos
; i
++)
266 chNext
= styler
[i
+1];
268 int style
= styleNext
;
269 styleNext
= styler
.StyleAt(i
+ 1);
270 bool atEOL
= (ch
== '\r' && chNext
!= '\n') || (ch
== '\n');
272 if (style
== SCE_GC_EVENT
|| style
== SCE_GC_GLOBAL
)
273 { headerPoint
= true; // fold at events and globals
277 { int lev
= SC_FOLDLEVELBASE
+1;
280 lev
= SC_FOLDLEVELBASE
;
282 if (visibleChars
== 0 && foldCompact
)
283 lev
|= SC_FOLDLEVELWHITEFLAG
;
286 lev
|= SC_FOLDLEVELHEADERFLAG
;
288 if (lev
!= styler
.LevelAt(lineCurrent
)) // set level, if not already correct
289 { styler
.SetLevel(lineCurrent
, lev
);
292 lineCurrent
++; // re-initialize our flags
297 if (!(isspacechar(ch
))) // || (style == SCE_GC_COMMENTLINE) || (style != SCE_GC_COMMENTBLOCK)))
301 int lev
= headerPoint
? SC_FOLDLEVELBASE
: SC_FOLDLEVELBASE
+1;
302 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
303 styler
.SetLevel(lineCurrent
, lev
| flagsNext
);
306 // I have no idea what these are for.. probably accessible by some message.
307 static const char * const gui4cliWordListDesc
[] = {
308 "Globals", "Events", "Attributes", "Control", "Commands",
312 // Declare language & pass our function pointers to Scintilla
313 LexerModule
lmGui4Cli(SCLEX_GUI4CLI
, ColouriseGui4CliDoc
, "gui4cli", FoldGui4Cli
, gui4cliWordListDesc
);