11 skipped lines |
|
13 | | 13 | | #include <stdarg.h> |
|
|
15 | | #include <fcntl.h> | | |
|
17 | | 16 | | #include "Platform.h" |
|
|
4 skipped lines |
23 | | 22 | | #include "Scintilla.h" |
|
24 | | 23 | | #include "SciLexer.h" |
|
|
| | 25 | | // Extended to accept accented characters |
26 | | static inline bool IsAWordChar(const int ch) { | | 26 | | static inline bool IsAWordChar(int ch) { |
| | 27 | | return ch >= 0x80 || |
27 | | return (ch < 0x80) && (isalnum(ch) || ch == '_' || ch == '.'); | | 28 | | (isalnum(ch) || ch == '.' || ch == '_'); |
|
|
30 | | static inline bool IsAWordStart(const int ch) { | | 31 | | static inline bool IsAWordStart(int ch) { |
| | 32 | | return ch >= 0x80 || |
31 | | return (ch < 0x80) && (isalnum(ch) || ch == '_'); | | 33 | | (isalpha(ch) || ch == '_'); |
|
|
34 | | static inline bool IsANumberChar(const int ch) { | | 36 | | static inline bool IsANumberChar(int ch) { |
35 | | 37 | | // Not exactly following number definition (several dots are seen as OK, etc.) |
|
36 | | 38 | | // but probably enough in most cases. |
|
37 | | 39 | | return (ch < 0x80) && |
|
17 skipped lines |
|
|
|
| | 60 | | // Test for [=[ ... ]=] delimiters, returns 0 if it's only a [ or ], |
| | 61 | | // return 1 for [[ or ]], returns >=2 for [=[ or ]=] and so on. |
| | 62 | | // The maximum number of '=' characters allowed is 254. |
| | 63 | | static int LongDelimCheck(StyleContext &sc) { |
| | 64 | | int sep = 1; |
2 skipped lines |
| | 67 | | if (sc.GetRelative(sep) == sc.ch) |
| | 68 | | return sep; |
| | 69 | | return 0; |
| | 70 | | } |
| | 71 | | |
58 | | 72 | | static void ColouriseLuaDoc( |
|
59 | | 73 | | unsigned int startPos, |
|
|
11 skipped lines |
72 | | 86 | | WordList &keywords8 = *keywordlists[7]; |
|
|
74 | | 88 | | int currentLine = styler.GetLine(startPos); |
|
75 | | // Initialize the literal string [[ ... ]] nesting level, if we are inside such a string. | | 89 | | // Initialize long string [[ ... ]] or block comment --[[ ... ]] nesting level, |
76 | | int literalStringLevel = 0; | | 90 | | // if we are inside such a string. Block comment was introduced in Lua 5.0, |
77 | | if (initStyle == SCE_LUA_LITERALSTRING) { | | |
78 | | literalStringLevel = styler.GetLineState(currentLine - 1); | | |
79 | | } | | |
80 | | // Initialize the block comment --[[ ... ]] nesting level, if we are inside such a comment | | 91 | | // blocks with separators [=[ ... ]=] in Lua 5.1. |
| | 92 | | int nestLevel = 0; |
81 | | int blockCommentLevel = 0; | | 93 | | int sepCount = 0; |
82 | | if (initStyle == SCE_LUA_COMMENT) { | | 94 | | if (initStyle == SCE_LUA_LITERALSTRING || initStyle == SCE_LUA_COMMENT) { |
83 | | blockCommentLevel = styler.GetLineState(currentLine - 1); | | 95 | | int lineState = styler.GetLineState(currentLine - 1); |
| | 96 | | nestLevel = lineState >> 8; |
| | 97 | | sepCount = lineState & 0xFF; |
|
|
86 | | 100 | | // Do not leak onto next line |
|
87 | | if (initStyle == SCE_LUA_STRINGEOL) { | | 101 | | if (initStyle == SCE_LUA_STRINGEOL || initStyle == SCE_LUA_COMMENTLINE || initStyle == SCE_LUA_PREPROCESSOR) { |
88 | | 102 | | initStyle = SCE_LUA_DEFAULT; |
|
|
|
8 skipped lines |
99 | | 113 | | currentLine = styler.GetLine(sc.currentPos); |
|
100 | | 114 | | switch (sc.state) { |
|
101 | | 115 | | case SCE_LUA_LITERALSTRING: |
|
102 | | // Inside a literal string, we set the line state | | |
103 | | styler.SetLineState(currentLine, literalStringLevel); | | |
104 | | break; | | |
105 | | case SCE_LUA_COMMENT: // Block comment | | 116 | | case SCE_LUA_COMMENT: |
106 | | // Inside a block comment, we set the line state | | 117 | | // Inside a literal string or block comment, we set the line state |
107 | | styler.SetLineState(currentLine, blockCommentLevel); | | 118 | | styler.SetLineState(currentLine, (nestLevel << 8) | sepCount); |
|
|
110 | | 121 | | // Reset the line state |
|
51 skipped lines |
|
163 | | 174 | | sc.SetState(SCE_LUA_DEFAULT); |
|
|
165 | | } else if (sc.state == SCE_LUA_COMMENTLINE ) { | | 176 | | } else if (sc.state == SCE_LUA_COMMENTLINE || sc.state == SCE_LUA_PREPROCESSOR) { |
166 | | 177 | | if (sc.atLineEnd) { |
|
167 | | sc.SetState(SCE_LUA_DEFAULT); | | |
168 | | } | | |
169 | | } else if (sc.state == SCE_LUA_PREPROCESSOR ) { | | |
170 | | if (sc.atLineEnd) { | | |
171 | | sc.SetState(SCE_LUA_DEFAULT); | | 178 | | sc.ForwardSetState(SCE_LUA_DEFAULT); |
|
173 | | 180 | | } else if (sc.state == SCE_LUA_STRING) { |
|
174 | | 181 | | if (sc.ch == '\\') { |
|
17 skipped lines |
192 | | 199 | | sc.ChangeState(SCE_LUA_STRINGEOL); |
|
193 | | 200 | | sc.ForwardSetState(SCE_LUA_DEFAULT); |
|
|
195 | | } else if (sc.state == SCE_LUA_LITERALSTRING) { | | 202 | | } else if (sc.state == SCE_LUA_LITERALSTRING || sc.state == SCE_LUA_COMMENT) { |
196 | | if (sc.Match('[', '[')) { | | |
197 | | literalStringLevel++; | | |
198 | | sc.Forward(); | | |
199 | | sc.SetState(SCE_LUA_LITERALSTRING); | | |
200 | | } else if (sc.Match(']', ']') && literalStringLevel > 0) { | | 203 | | if (sc.ch == '[') { |
201 | | literalStringLevel--; | | |
202 | | sc.Forward(); | | 204 | | int sep = LongDelimCheck(sc); |
203 | | if (literalStringLevel == 0) { | | 205 | | if (sep == 1 && sepCount == 1) { // [[-only allowed to nest |
| | 206 | | nestLevel++; |
204 | | sc.ForwardSetState(SCE_LUA_DEFAULT); | | 207 | | sc.Forward(); |
|
206 | | } | | |
207 | | } else if (sc.state == SCE_LUA_COMMENT) { // Lua 5.0's block comment | | 209 | | } else if (sc.ch == ']') { |
| | 210 | | int sep = LongDelimCheck(sc); |
208 | | if (sc.Match('[', '[')) { | | 211 | | if (sep == 1 && sepCount == 1) { // un-nest with ]]-only |
209 | | blockCommentLevel++; | | 212 | | nestLevel--; |
210 | | sc.Forward(); | | 213 | | sc.Forward(); |
211 | | } else if (sc.Match(']', ']') && blockCommentLevel > 0) { | | 214 | | if (nestLevel == 0) { |
212 | | blockCommentLevel--; | | |
213 | | sc.Forward(); | | 215 | | sc.ForwardSetState(SCE_LUA_DEFAULT); |
| | 216 | | } |
214 | | if (blockCommentLevel == 0) { | | 217 | | } else if (sep > 1 && sep == sepCount) { // ]=]-style delim |
| | 218 | | sc.Forward(sep); |
215 | | 219 | | sc.ForwardSetState(SCE_LUA_DEFAULT); |
|
|
|
5 skipped lines |
223 | | 227 | | sc.SetState(SCE_LUA_NUMBER); |
|
224 | | 228 | | } else if (IsAWordStart(sc.ch)) { |
|
225 | | 229 | | sc.SetState(SCE_LUA_IDENTIFIER); |
|
226 | | } else if (sc.Match('\"')) { | | 230 | | } else if (sc.ch == '\"') { |
227 | | 231 | | sc.SetState(SCE_LUA_STRING); |
|
228 | | } else if (sc.Match('\'')) { | | 232 | | } else if (sc.ch == '\'') { |
229 | | 233 | | sc.SetState(SCE_LUA_CHARACTER); |
|
230 | | } else if (sc.Match('[', '[')) { | | 234 | | } else if (sc.ch == '[') { |
231 | | literalStringLevel = 1; | | 235 | | sepCount = LongDelimCheck(sc); |
| | 236 | | if (sepCount == 0) { |
232 | | sc.SetState(SCE_LUA_LITERALSTRING); | | 237 | | sc.SetState(SCE_LUA_OPERATOR); |
233 | | sc.Forward(); | | |
234 | | } else if (sc.Match("--[[")) { // Lua 5.0's block comment | | 238 | | } else { |
235 | | blockCommentLevel = 1; | | 239 | | nestLevel = 1; |
236 | | sc.SetState(SCE_LUA_COMMENT); | | 240 | | sc.SetState(SCE_LUA_LITERALSTRING); |
237 | | sc.Forward(3); | | 241 | | sc.Forward(sepCount); |
| | 242 | | } |
238 | | 243 | | } else if (sc.Match('-', '-')) { |
|
239 | | 244 | | sc.SetState(SCE_LUA_COMMENTLINE); |
|
| | 245 | | if (sc.Match("--[")) { |
| | 246 | | sc.Forward(2); |
| | 247 | | sepCount = LongDelimCheck(sc); |
| | 248 | | if (sepCount > 0) { |
| | 249 | | nestLevel = 1; |
| | 250 | | sc.ChangeState(SCE_LUA_COMMENT); |
240 | | sc.Forward(); | | 251 | | sc.Forward(sepCount); |
| | 252 | | } |
| | 253 | | } else { |
| | 254 | | sc.Forward(); |
| | 255 | | } |
241 | | 256 | | } else if (sc.atLineStart && sc.Match('$')) { |
|
242 | | 257 | | sc.SetState(SCE_LUA_PREPROCESSOR); // Obsolete since Lua 4.0, but still in old code |
|
243 | | 258 | | } else if (IsLuaOperator(static_cast<char>(sc.ch))) { |
|
23 skipped lines |
267 | | 282 | | styleNext = styler.StyleAt(i + 1); |
|
268 | | 283 | | bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n'); |
|
269 | | 284 | | if (style == SCE_LUA_WORD) { |
|
270 | | if (ch == 'i' || ch == 'd' || ch == 'f' || ch == 'e') { | | 285 | | if (ch == 'i' || ch == 'd' || ch == 'f' || ch == 'e' || ch == 'r' || ch == 'u') { |
271 | | 286 | | for (unsigned int j = 0; j < 8; j++) { |
|
272 | | 287 | | if (!iswordchar(styler[i + j])) { |
|
|
2 skipped lines |
|
|
|
279 | | if ((strcmp(s, "if") == 0) || (strcmp(s, "do") == 0) || (strcmp(s, "function") == 0)) { | | 294 | | if ((strcmp(s, "if") == 0) || (strcmp(s, "do") == 0) || (strcmp(s, "function") == 0) || (strcmp(s, "repeat") == 0)) { |
|
|
282 | | if ((strcmp(s, "end") == 0) || (strcmp(s, "elseif") == 0)) { | | 297 | | if ((strcmp(s, "end") == 0) || (strcmp(s, "elseif") == 0) || (strcmp(s, "until") == 0)) { |
|
|
|
3 skipped lines |
289 | | 304 | | } else if (ch == '}' || ch == ')') { |
|
|
|
| | 307 | | } else if (style == SCE_LUA_LITERALSTRING || style == SCE_LUA_COMMENT) { |
| | 308 | | if (ch == '[') { |
| | 309 | | levelCurrent++; |
| | 310 | | } else if (ch == ']') { |
| | 311 | | levelCurrent--; |
| | 312 | | } |
|
|
|
26 skipped lines |
321 | | 342 | | "Basic functions", |
|
322 | | 343 | | "String, (table) & math functions", |
|
323 | | 344 | | "(coroutines), I/O & system facilities", |
|
324 | | "XXX", | | 345 | | "user1", |
| | 346 | | "user2", |
| | 347 | | "user3", |
325 | | "XXX", | | 348 | | "user4", |
|
|
|
2 skipped lines |