]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexLua.cxx
1 // LexLua.cxx - lexer for Lua language
2 // Written by Paul Winwood
16 #include "Scintilla.h"
19 static void classifyWordLua(unsigned int start
, unsigned int end
, WordList
&keywords
, Accessor
&styler
)
22 bool wordIsNumber
= isdigit(styler
[start
]) || (styler
[start
] == '.');
24 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++)
26 s
[i
] = styler
[start
+ i
];
30 char chAttr
= SCE_LUA_IDENTIFIER
;
33 chAttr
= SCE_LUA_NUMBER
;
36 if (keywords
.InList(s
))
38 chAttr
= SCE_LUA_WORD
;
41 styler
.ColourTo(end
, chAttr
);
44 static void ColouriseLuaDoc(unsigned int startPos
,
47 WordList
*keywordlists
[],
51 WordList
&keywords
= *keywordlists
[0];
53 styler
.StartAt(startPos
);
54 styler
.GetLine(startPos
);
56 int state
= initStyle
;
58 char chNext
= styler
[startPos
];
59 unsigned int lengthDoc
= startPos
+ length
;
60 bool firstChar
= true;
61 int literalString
= 0;
63 styler
.StartSegment(startPos
);
64 for (unsigned int i
= startPos
; i
<= lengthDoc
; i
++)
67 chNext
= styler
.SafeGetCharAt(i
+ 1);
69 if (styler
.IsLeadByte(ch
))
71 chNext
= styler
.SafeGetCharAt(i
+ 2);
77 if (state
== SCE_LUA_STRINGEOL
)
79 if (ch
!= '\r' && ch
!= '\n')
81 styler
.ColourTo(i
-1, state
);
82 state
= SCE_LUA_DEFAULT
;
86 if (state
== SCE_LUA_LITERALSTRING
&& ch
== '[' && chNext
== '[')
91 if (state
== SCE_LUA_DEFAULT
)
93 if (ch
== '-' && chNext
== '-')
95 styler
.ColourTo(i
-1, state
);
96 state
= SCE_LUA_COMMENTLINE
;
99 if (ch
== '[' && chNext
== '[')
101 state
= SCE_LUA_LITERALSTRING
;
107 styler
.ColourTo(i
-1, state
);
108 state
= SCE_LUA_WORD
;
113 styler
.ColourTo(i
-1, state
);
114 state
= SCE_LUA_STRING
;
119 styler
.ColourTo(i
-1, state
);
120 state
= SCE_LUA_CHARACTER
;
123 if (ch
== '$' && firstChar
)
125 styler
.ColourTo(i
-1, state
);
126 state
= SCE_LUA_PREPROCESSOR
;
131 styler
.ColourTo(i
-1, state
);
132 styler
.ColourTo(i
, SCE_LUA_OPERATOR
);
136 if (state
== SCE_LUA_WORD
)
140 classifyWordLua(styler
.GetStartSegment(), i
- 1, keywords
, styler
);
141 state
= SCE_LUA_DEFAULT
;
142 if (ch
== '[' && chNext
== '[')
145 state
= SCE_LUA_LITERALSTRING
;
148 if (ch
== '-' && chNext
== '-')
150 state
= SCE_LUA_COMMENTLINE
;
155 state
= SCE_LUA_STRING
;
160 state
= SCE_LUA_CHARACTER
;
163 if (ch
== '$' && firstChar
)
165 state
= SCE_LUA_PREPROCESSOR
;
170 styler
.ColourTo(i
, SCE_LUA_OPERATOR
);
176 if (state
== SCE_LUA_LITERALSTRING
)
178 if (ch
== ']' && (chPrev
== ']') && (--literalString
== 0))
180 styler
.ColourTo(i
, state
);
181 state
= SCE_LUA_DEFAULT
;
185 if (state
== SCE_LUA_PREPROCESSOR
)
187 if ((ch
== '\r' || ch
== '\n') && (chPrev
!= '\\'))
189 styler
.ColourTo(i
-1, state
);
190 state
= SCE_LUA_DEFAULT
;
194 if (state
== SCE_LUA_COMMENTLINE
)
196 if (ch
== '\r' || ch
== '\n')
198 styler
.ColourTo(i
-1, state
);
199 state
= SCE_LUA_DEFAULT
;
203 if (state
== SCE_LUA_STRING
)
205 if ((ch
== '\r' || ch
== '\n') && (chPrev
!= '\\'))
207 styler
.ColourTo(i
-1, state
);
208 state
= SCE_LUA_STRINGEOL
;
213 if (chNext
== '\"' || chNext
== '\\')
217 chNext
= styler
.SafeGetCharAt(i
+ 1);
223 styler
.ColourTo(i
, state
);
224 state
= SCE_LUA_DEFAULT
;
227 chNext
= styler
.SafeGetCharAt(i
+ 1);
231 if (state
== SCE_LUA_CHARACTER
)
233 if ((ch
== '\r' || ch
== '\n') && (chPrev
!= '\\'))
235 styler
.ColourTo(i
-1, state
);
236 state
= SCE_LUA_STRINGEOL
;
241 if (chNext
== '\'' || chNext
== '\\')
245 chNext
= styler
.SafeGetCharAt(i
+ 1);
251 styler
.ColourTo(i
, state
);
252 state
= SCE_LUA_DEFAULT
;
255 chNext
= styler
.SafeGetCharAt(i
+ 1);
259 if (state
== SCE_LUA_DEFAULT
)
261 if (ch
== '-' && chNext
== '-')
263 state
= SCE_LUA_COMMENTLINE
;
268 state
= SCE_LUA_STRING
;
273 state
= SCE_LUA_CHARACTER
;
276 if (ch
== '$' && firstChar
)
278 state
= SCE_LUA_PREPROCESSOR
;
283 state
= SCE_LUA_WORD
;
288 styler
.ColourTo(i
, SCE_LUA_OPERATOR
);
293 firstChar
= (ch
== '\r' || ch
== '\n');
295 styler
.ColourTo(lengthDoc
- 1, state
);
298 LexerModule
lmLua(SCLEX_LUA
, ColouriseLuaDoc
);