~ubuntu-branches/ubuntu/wily/geany/wily

« back to all changes in this revision

Viewing changes to scintilla/LexNsis.cxx

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2011-12-10 07:43:26 UTC
  • mfrom: (3.3.7 sid)
  • Revision ID: package-import@ubuntu.com-20111210074326-s8yqbew5i20h33tf
Tags: 0.21-1ubuntu1
* Merge from Debian Unstable, remaining changes:
  - debian/patches/20_use_evince_viewer.patch:
     + use evince as viewer for pdf and dvi files
  - debian/patches/20_use_x_terminal_emulator.patch:
     + use x-terminal-emulator as terminal
  - debian/control
     + Add breaks on geany-plugins-common << 0.20
* Also fixes bugs:
  - Filter for MATLAB/Octave files filters everythign (LP: 885505)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Scintilla source code edit control
2
 
/** @file LexNsis.cxx
3
 
 ** Lexer for NSIS
4
 
 **/
5
 
// Copyright 2003 - 2005 by Angelo Mandato <angelo [at] spaceblue [dot] com>
6
 
// Last Updated: 03/13/2005
7
 
// The License.txt file describes the conditions under which this software may be distributed.
8
 
#include <stdlib.h>
9
 
#include <string.h>
10
 
#include <ctype.h>
11
 
#include <stdio.h>
12
 
#include <stdarg.h>
13
 
 
14
 
#include "Platform.h"
15
 
 
16
 
#include "CharClassify.h"
17
 
#include "PropSet.h"
18
 
#include "Accessor.h"
19
 
#include "KeyWords.h"
20
 
#include "Scintilla.h"
21
 
#include "SciLexer.h"
22
 
 
23
 
#ifdef SCI_NAMESPACE
24
 
using namespace Scintilla;
25
 
#endif
26
 
 
27
 
/*
28
 
// located in SciLexer.h
29
 
#define SCLEX_NSIS 43
30
 
 
31
 
#define SCE_NSIS_DEFAULT 0
32
 
#define SCE_NSIS_COMMENT 1
33
 
#define SCE_NSIS_STRINGDQ 2
34
 
#define SCE_NSIS_STRINGLQ 3
35
 
#define SCE_NSIS_STRINGRQ 4
36
 
#define SCE_NSIS_FUNCTION 5
37
 
#define SCE_NSIS_VARIABLE 6
38
 
#define SCE_NSIS_LABEL 7
39
 
#define SCE_NSIS_USERDEFINED 8
40
 
#define SCE_NSIS_SECTIONDEF 9
41
 
#define SCE_NSIS_SUBSECTIONDEF 10
42
 
#define SCE_NSIS_IFDEFINEDEF 11
43
 
#define SCE_NSIS_MACRODEF 12
44
 
#define SCE_NSIS_STRINGVAR 13
45
 
#define SCE_NSIS_NUMBER 14
46
 
// ADDED for Scintilla v1.63
47
 
#define SCE_NSIS_SECTIONGROUP 15
48
 
#define SCE_NSIS_PAGEEX 16
49
 
#define SCE_NSIS_FUNCTIONDEF 17
50
 
#define SCE_NSIS_COMMENTBOX 18
51
 
*/
52
 
 
53
 
static bool isNsisNumber(char ch)
54
 
{
55
 
  return (ch >= '0' && ch <= '9');
56
 
}
57
 
 
58
 
static bool isNsisChar(char ch)
59
 
{
60
 
  return (ch == '.' ) || (ch == '_' ) || isNsisNumber(ch) || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
61
 
}
62
 
 
63
 
static bool isNsisLetter(char ch)
64
 
{
65
 
  return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
66
 
}
67
 
 
68
 
static bool NsisNextLineHasElse(unsigned int start, unsigned int end, Accessor &styler)
69
 
{
70
 
  int nNextLine = -1;
71
 
  for( unsigned int i = start; i < end; i++ )
72
 
  {
73
 
    char cNext = styler.SafeGetCharAt( i );
74
 
    if( cNext == '\n' )
75
 
    {
76
 
      nNextLine = i+1;
77
 
      break;
78
 
    }
79
 
  }
80
 
 
81
 
  if( nNextLine == -1 ) // We never found the next line...
82
 
    return false;
83
 
 
84
 
  for( unsigned int firstChar = nNextLine; firstChar < end; firstChar++ )
85
 
  {
86
 
    char cNext = styler.SafeGetCharAt( firstChar );
87
 
    if( cNext == ' ' )
88
 
      continue;
89
 
    if( cNext == '\t' )
90
 
      continue;
91
 
    if( cNext == '!' )
92
 
    {
93
 
      if( styler.Match(firstChar, "!else") )
94
 
        return true;
95
 
    }
96
 
    break;
97
 
  }
98
 
 
99
 
  return false;
100
 
}
101
 
 
102
 
static int NsisCmp( const char *s1, const char *s2, bool bIgnoreCase )
103
 
{
104
 
  if( bIgnoreCase )
105
 
     return CompareCaseInsensitive( s1, s2);
106
 
 
107
 
  return strcmp( s1, s2 );
108
 
}
109
 
 
110
 
static int calculateFoldNsis(unsigned int start, unsigned int end, int foldlevel, Accessor &styler, bool bElse, bool foldUtilityCmd )
111
 
{
112
 
  int style = styler.StyleAt(end);
113
 
 
114
 
  // If the word is too long, it is not what we are looking for
115
 
  if( end - start > 20 )
116
 
    return foldlevel;
117
 
 
118
 
  if( foldUtilityCmd )
119
 
  {
120
 
    // Check the style at this point, if it is not valid, then return zero
121
 
    if( style != SCE_NSIS_FUNCTIONDEF && style != SCE_NSIS_SECTIONDEF &&
122
 
        style != SCE_NSIS_SUBSECTIONDEF && style != SCE_NSIS_IFDEFINEDEF &&
123
 
        style != SCE_NSIS_MACRODEF && style != SCE_NSIS_SECTIONGROUP &&
124
 
        style != SCE_NSIS_PAGEEX )
125
 
          return foldlevel;
126
 
  }
127
 
  else
128
 
  {
129
 
    if( style != SCE_NSIS_FUNCTIONDEF && style != SCE_NSIS_SECTIONDEF &&
130
 
        style != SCE_NSIS_SUBSECTIONDEF && style != SCE_NSIS_SECTIONGROUP &&
131
 
        style != SCE_NSIS_PAGEEX )
132
 
          return foldlevel;
133
 
  }
134
 
 
135
 
  int newFoldlevel = foldlevel;
136
 
  bool bIgnoreCase = false;
137
 
  if( styler.GetPropertyInt("nsis.ignorecase") == 1 )
138
 
    bIgnoreCase = true;
139
 
 
140
 
  char s[20]; // The key word we are looking for has atmost 13 characters
141
 
  for (unsigned int i = 0; i < end - start + 1 && i < 19; i++)
142
 
        {
143
 
                s[i] = static_cast<char>( styler[ start + i ] );
144
 
                s[i + 1] = '\0';
145
 
        }
146
 
 
147
 
  if( s[0] == '!' )
148
 
  {
149
 
    if( NsisCmp(s, "!ifndef", bIgnoreCase) == 0 || NsisCmp(s, "!ifdef", bIgnoreCase ) == 0 || NsisCmp(s, "!ifmacrodef", bIgnoreCase ) == 0 || NsisCmp(s, "!ifmacrondef", bIgnoreCase ) == 0 || NsisCmp(s, "!if", bIgnoreCase ) == 0 || NsisCmp(s, "!macro", bIgnoreCase ) == 0 )
150
 
      newFoldlevel++;
151
 
    else if( NsisCmp(s, "!endif", bIgnoreCase) == 0 || NsisCmp(s, "!macroend", bIgnoreCase ) == 0 )
152
 
      newFoldlevel--;
153
 
    else if( bElse && NsisCmp(s, "!else", bIgnoreCase) == 0 )
154
 
      newFoldlevel++;
155
 
  }
156
 
  else
157
 
  {
158
 
    if( NsisCmp(s, "Section", bIgnoreCase ) == 0 || NsisCmp(s, "SectionGroup", bIgnoreCase ) == 0 || NsisCmp(s, "Function", bIgnoreCase) == 0 || NsisCmp(s, "SubSection", bIgnoreCase ) == 0 || NsisCmp(s, "PageEx", bIgnoreCase ) == 0 )
159
 
      newFoldlevel++;
160
 
    else if( NsisCmp(s, "SectionGroupEnd", bIgnoreCase ) == 0 || NsisCmp(s, "SubSectionEnd", bIgnoreCase ) == 0 || NsisCmp(s, "FunctionEnd", bIgnoreCase) == 0 || NsisCmp(s, "SectionEnd", bIgnoreCase ) == 0 || NsisCmp(s, "PageExEnd", bIgnoreCase ) == 0 )
161
 
      newFoldlevel--;
162
 
  }
163
 
 
164
 
  return newFoldlevel;
165
 
}
166
 
 
167
 
static int classifyWordNsis(unsigned int start, unsigned int end, WordList *keywordLists[], Accessor &styler )
168
 
{
169
 
  bool bIgnoreCase = false;
170
 
  if( styler.GetPropertyInt("nsis.ignorecase") == 1 )
171
 
    bIgnoreCase = true;
172
 
 
173
 
  bool bUserVars = false;
174
 
  if( styler.GetPropertyInt("nsis.uservars") == 1 )
175
 
    bUserVars = true;
176
 
 
177
 
        char s[100];
178
 
 
179
 
        WordList &Functions = *keywordLists[0];
180
 
        WordList &Variables = *keywordLists[1];
181
 
        WordList &Lables = *keywordLists[2];
182
 
        WordList &UserDefined = *keywordLists[3];
183
 
 
184
 
        for (unsigned int i = 0; i < end - start + 1 && i < 99; i++)
185
 
        {
186
 
    if( bIgnoreCase )
187
 
      s[i] = static_cast<char>( tolower(styler[ start + i ] ) );
188
 
    else
189
 
                  s[i] = static_cast<char>( styler[ start + i ] );
190
 
                s[i + 1] = '\0';
191
 
        }
192
 
 
193
 
        // Check for special words...
194
 
        if( NsisCmp(s, "!macro", bIgnoreCase ) == 0 || NsisCmp(s, "!macroend", bIgnoreCase) == 0 ) // Covers !macro and !macroend
195
 
                return SCE_NSIS_MACRODEF;
196
 
 
197
 
        if( NsisCmp(s, "!ifdef", bIgnoreCase ) == 0 ||  NsisCmp(s, "!ifndef", bIgnoreCase) == 0 ||  NsisCmp(s, "!endif", bIgnoreCase) == 0 ) // Covers !ifdef, !ifndef and !endif
198
 
                return SCE_NSIS_IFDEFINEDEF;
199
 
 
200
 
        if( NsisCmp(s, "!if", bIgnoreCase ) == 0 || NsisCmp(s, "!else", bIgnoreCase )  == 0 ) // Covers !if and else
201
 
                return SCE_NSIS_IFDEFINEDEF;
202
 
 
203
 
        if (NsisCmp(s, "!ifmacrodef", bIgnoreCase ) == 0 || NsisCmp(s, "!ifmacrondef", bIgnoreCase )  == 0 ) // Covers !ifmacrodef and !ifnmacrodef
204
 
                return SCE_NSIS_IFDEFINEDEF;
205
 
 
206
 
  if( NsisCmp(s, "SectionGroup", bIgnoreCase) == 0 || NsisCmp(s, "SectionGroupEnd", bIgnoreCase) == 0 ) // Covers SectionGroup and SectionGroupEnd
207
 
    return SCE_NSIS_SECTIONGROUP;
208
 
 
209
 
        if( NsisCmp(s, "Section", bIgnoreCase ) == 0 || NsisCmp(s, "SectionEnd", bIgnoreCase) == 0 ) // Covers Section and SectionEnd
210
 
                return SCE_NSIS_SECTIONDEF;
211
 
 
212
 
        if( NsisCmp(s, "SubSection", bIgnoreCase) == 0 || NsisCmp(s, "SubSectionEnd", bIgnoreCase) == 0 ) // Covers SubSection and SubSectionEnd
213
 
                return SCE_NSIS_SUBSECTIONDEF;
214
 
 
215
 
  if( NsisCmp(s, "PageEx", bIgnoreCase) == 0 || NsisCmp(s, "PageExEnd", bIgnoreCase) == 0 ) // Covers PageEx and PageExEnd
216
 
    return SCE_NSIS_PAGEEX;
217
 
 
218
 
        if( NsisCmp(s, "Function", bIgnoreCase) == 0 || NsisCmp(s, "FunctionEnd", bIgnoreCase) == 0 ) // Covers Function and FunctionEnd
219
 
                return SCE_NSIS_FUNCTIONDEF;
220
 
 
221
 
        if ( Functions.InList(s) )
222
 
                return SCE_NSIS_FUNCTION;
223
 
 
224
 
        if ( Variables.InList(s) )
225
 
                return SCE_NSIS_VARIABLE;
226
 
 
227
 
        if ( Lables.InList(s) )
228
 
                return SCE_NSIS_LABEL;
229
 
 
230
 
        if( UserDefined.InList(s) )
231
 
                return SCE_NSIS_USERDEFINED;
232
 
 
233
 
        if( strlen(s) > 3 )
234
 
        {
235
 
                if( s[1] == '{' && s[strlen(s)-1] == '}' )
236
 
                        return SCE_NSIS_VARIABLE;
237
 
        }
238
 
 
239
 
  // See if the variable is a user defined variable
240
 
  if( s[0] == '$' && bUserVars )
241
 
  {
242
 
    bool bHasSimpleNsisChars = true;
243
 
    for (unsigned int j = 1; j < end - start + 1 && j < 99; j++)
244
 
          {
245
 
      if( !isNsisChar( s[j] ) )
246
 
      {
247
 
        bHasSimpleNsisChars = false;
248
 
        break;
249
 
      }
250
 
          }
251
 
 
252
 
    if( bHasSimpleNsisChars )
253
 
      return SCE_NSIS_VARIABLE;
254
 
  }
255
 
 
256
 
  // To check for numbers
257
 
  if( isNsisNumber( s[0] ) )
258
 
  {
259
 
    bool bHasSimpleNsisNumber = true;
260
 
    for (unsigned int j = 1; j < end - start + 1 && j < 99; j++)
261
 
          {
262
 
      if( !isNsisNumber( s[j] ) )
263
 
      {
264
 
        bHasSimpleNsisNumber = false;
265
 
        break;
266
 
      }
267
 
          }
268
 
 
269
 
    if( bHasSimpleNsisNumber )
270
 
      return SCE_NSIS_NUMBER;
271
 
  }
272
 
 
273
 
        return SCE_NSIS_DEFAULT;
274
 
}
275
 
 
276
 
static void ColouriseNsisDoc(unsigned int startPos, int length, int, WordList *keywordLists[], Accessor &styler)
277
 
{
278
 
        int state = SCE_NSIS_DEFAULT;
279
 
  if( startPos > 0 )
280
 
    state = styler.StyleAt(startPos-1); // Use the style from the previous line, usually default, but could be commentbox
281
 
 
282
 
        styler.StartAt( startPos );
283
 
        styler.GetLine( startPos );
284
 
 
285
 
        unsigned int nLengthDoc = startPos + length;
286
 
        styler.StartSegment( startPos );
287
 
 
288
 
        char cCurrChar;
289
 
        bool bVarInString = false;
290
 
  bool bClassicVarInString = false;
291
 
 
292
 
        unsigned int i;
293
 
        for( i = startPos; i < nLengthDoc; i++ )
294
 
        {
295
 
                cCurrChar = styler.SafeGetCharAt( i );
296
 
                char cNextChar = styler.SafeGetCharAt(i+1);
297
 
 
298
 
                switch(state)
299
 
                {
300
 
                        case SCE_NSIS_DEFAULT:
301
 
                                if( cCurrChar == ';' || cCurrChar == '#' ) // we have a comment line
302
 
                                {
303
 
                                        styler.ColourTo(i-1, state );
304
 
                                        state = SCE_NSIS_COMMENT;
305
 
                                        break;
306
 
                                }
307
 
                                if( cCurrChar == '"' )
308
 
                                {
309
 
                                        styler.ColourTo(i-1, state );
310
 
                                        state = SCE_NSIS_STRINGDQ;
311
 
                                        bVarInString = false;
312
 
          bClassicVarInString = false;
313
 
                                        break;
314
 
                                }
315
 
                                if( cCurrChar == '\'' )
316
 
                                {
317
 
                                        styler.ColourTo(i-1, state );
318
 
                                        state = SCE_NSIS_STRINGRQ;
319
 
                                        bVarInString = false;
320
 
          bClassicVarInString = false;
321
 
                                        break;
322
 
                                }
323
 
                                if( cCurrChar == '`' )
324
 
                                {
325
 
                                        styler.ColourTo(i-1, state );
326
 
                                        state = SCE_NSIS_STRINGLQ;
327
 
                                        bVarInString = false;
328
 
          bClassicVarInString = false;
329
 
                                        break;
330
 
                                }
331
 
 
332
 
                                // NSIS KeyWord,Function, Variable, UserDefined:
333
 
                                if( cCurrChar == '$' || isNsisChar(cCurrChar) || cCurrChar == '!' )
334
 
                                {
335
 
                                        styler.ColourTo(i-1,state);
336
 
                                  state = SCE_NSIS_FUNCTION;
337
 
 
338
 
          // If it is a number, we must check and set style here first...
339
 
          if( isNsisNumber(cCurrChar) && (cNextChar == '\t' || cNextChar == ' ' || cNextChar == '\r' || cNextChar == '\n' ) )
340
 
              styler.ColourTo( i, SCE_NSIS_NUMBER);
341
 
 
342
 
                                        break;
343
 
                                }
344
 
 
345
 
        if( cCurrChar == '/' && cNextChar == '*' )
346
 
        {
347
 
          styler.ColourTo(i-1,state);
348
 
          state = SCE_NSIS_COMMENTBOX;
349
 
          break;
350
 
        }
351
 
 
352
 
                                break;
353
 
                        case SCE_NSIS_COMMENT:
354
 
                                if( cNextChar == '\n' || cNextChar == '\r' )
355
 
        {
356
 
          // Special case:
357
 
          if( cCurrChar == '\\' )
358
 
          {
359
 
            styler.ColourTo(i-2,state);
360
 
            styler.ColourTo(i,SCE_NSIS_DEFAULT);
361
 
          }
362
 
          else
363
 
          {
364
 
                                    styler.ColourTo(i,state);
365
 
            state = SCE_NSIS_DEFAULT;
366
 
          }
367
 
        }
368
 
                                break;
369
 
                        case SCE_NSIS_STRINGDQ:
370
 
      case SCE_NSIS_STRINGLQ:
371
 
      case SCE_NSIS_STRINGRQ:
372
 
 
373
 
        if( styler.SafeGetCharAt(i-1) == '\\' && styler.SafeGetCharAt(i-2) == '$' )
374
 
          break; // Ignore the next character, even if it is a quote of some sort
375
 
 
376
 
        if( cCurrChar == '"' && state == SCE_NSIS_STRINGDQ )
377
 
                                {
378
 
                                        styler.ColourTo(i,state);
379
 
                                  state = SCE_NSIS_DEFAULT;
380
 
          break;
381
 
                                }
382
 
 
383
 
        if( cCurrChar == '`' && state == SCE_NSIS_STRINGLQ )
384
 
        {
385
 
                                        styler.ColourTo(i,state);
386
 
                                  state = SCE_NSIS_DEFAULT;
387
 
          break;
388
 
                                }
389
 
 
390
 
        if( cCurrChar == '\'' && state == SCE_NSIS_STRINGRQ )
391
 
                                {
392
 
                                        styler.ColourTo(i,state);
393
 
                                  state = SCE_NSIS_DEFAULT;
394
 
          break;
395
 
                                }
396
 
 
397
 
        if( cNextChar == '\r' || cNextChar == '\n' )
398
 
        {
399
 
          int nCurLine = styler.GetLine(i+1);
400
 
          int nBack = i;
401
 
          // We need to check if the previous line has a \ in it...
402
 
          bool bNextLine = false;
403
 
 
404
 
          while( nBack > 0 )
405
 
          {
406
 
            if( styler.GetLine(nBack) != nCurLine )
407
 
              break;
408
 
 
409
 
            char cTemp = styler.SafeGetCharAt(nBack, 'a'); // Letter 'a' is safe here
410
 
 
411
 
            if( cTemp == '\\' )
412
 
            {
413
 
              bNextLine = true;
414
 
              break;
415
 
            }
416
 
            if( cTemp != '\r' && cTemp != '\n' && cTemp != '\t' && cTemp != ' ' )
417
 
              break;
418
 
 
419
 
            nBack--;
420
 
          }
421
 
 
422
 
          if( bNextLine )
423
 
          {
424
 
            styler.ColourTo(i+1,state);
425
 
          }
426
 
          if( bNextLine == false )
427
 
          {
428
 
            styler.ColourTo(i,state);
429
 
                                    state = SCE_NSIS_DEFAULT;
430
 
          }
431
 
        }
432
 
                                break;
433
 
 
434
 
                        case SCE_NSIS_FUNCTION:
435
 
 
436
 
                                // NSIS KeyWord:
437
 
        if( cCurrChar == '$' )
438
 
          state = SCE_NSIS_DEFAULT;
439
 
        else if( cCurrChar == '\\' && (cNextChar == 'n' || cNextChar == 'r' || cNextChar == 't' ) )
440
 
          state = SCE_NSIS_DEFAULT;
441
 
                                else if( (isNsisChar(cCurrChar) && !isNsisChar( cNextChar) && cNextChar != '}') || cCurrChar == '}' )
442
 
                                {
443
 
                                        state = classifyWordNsis( styler.GetStartSegment(), i, keywordLists, styler );
444
 
                                        styler.ColourTo( i, state);
445
 
                                        state = SCE_NSIS_DEFAULT;
446
 
                                }
447
 
                                else if( !isNsisChar( cCurrChar ) && cCurrChar != '{' && cCurrChar != '}' )
448
 
                                {
449
 
          if( classifyWordNsis( styler.GetStartSegment(), i-1, keywordLists, styler) == SCE_NSIS_NUMBER )
450
 
             styler.ColourTo( i-1, SCE_NSIS_NUMBER );
451
 
 
452
 
                                        state = SCE_NSIS_DEFAULT;
453
 
 
454
 
                                        if( cCurrChar == '"' )
455
 
                                        {
456
 
                                                state = SCE_NSIS_STRINGDQ;
457
 
                                                bVarInString = false;
458
 
            bClassicVarInString = false;
459
 
                                        }
460
 
                                        else if( cCurrChar == '`' )
461
 
                                        {
462
 
                                                state = SCE_NSIS_STRINGLQ;
463
 
                                                bVarInString = false;
464
 
            bClassicVarInString = false;
465
 
                                        }
466
 
                                        else if( cCurrChar == '\'' )
467
 
                                        {
468
 
                                                state = SCE_NSIS_STRINGRQ;
469
 
                                                bVarInString = false;
470
 
            bClassicVarInString = false;
471
 
                                        }
472
 
                                        else if( cCurrChar == '#' || cCurrChar == ';' )
473
 
          {
474
 
                                                state = SCE_NSIS_COMMENT;
475
 
          }
476
 
                                }
477
 
                                break;
478
 
      case SCE_NSIS_COMMENTBOX:
479
 
 
480
 
        if( styler.SafeGetCharAt(i-1) == '*' && cCurrChar == '/' )
481
 
        {
482
 
          styler.ColourTo(i,state);
483
 
          state = SCE_NSIS_DEFAULT;
484
 
        }
485
 
        break;
486
 
                }
487
 
 
488
 
                if( state == SCE_NSIS_COMMENT || state == SCE_NSIS_COMMENTBOX )
489
 
                {
490
 
                        styler.ColourTo(i,state);
491
 
                }
492
 
                else if( state == SCE_NSIS_STRINGDQ || state == SCE_NSIS_STRINGLQ || state == SCE_NSIS_STRINGRQ )
493
 
                {
494
 
      bool bIngoreNextDollarSign = false;
495
 
      bool bUserVars = false;
496
 
      if( styler.GetPropertyInt("nsis.uservars") == 1 )
497
 
        bUserVars = true;
498
 
 
499
 
      if( bVarInString && cCurrChar == '$' )
500
 
      {
501
 
        bVarInString = false;
502
 
        bIngoreNextDollarSign = true;
503
 
      }
504
 
      else if( bVarInString && cCurrChar == '\\' && (cNextChar == 'n' || cNextChar == 'r' || cNextChar == 't' || cNextChar == '"' || cNextChar == '`' || cNextChar == '\'' ) )
505
 
      {
506
 
        styler.ColourTo( i+1, SCE_NSIS_STRINGVAR);
507
 
        bVarInString = false;
508
 
        bIngoreNextDollarSign = false;
509
 
      }
510
 
 
511
 
      // Covers "$INSTDIR and user vars like $MYVAR"
512
 
      else if( bVarInString && !isNsisChar(cNextChar) )
513
 
      {
514
 
        int nWordState = classifyWordNsis( styler.GetStartSegment(), i, keywordLists, styler);
515
 
                                if( nWordState == SCE_NSIS_VARIABLE )
516
 
                                        styler.ColourTo( i, SCE_NSIS_STRINGVAR);
517
 
        else if( bUserVars )
518
 
          styler.ColourTo( i, SCE_NSIS_STRINGVAR);
519
 
        bVarInString = false;
520
 
      }
521
 
      // Covers "${TEST}..."
522
 
      else if( bClassicVarInString && cNextChar == '}' )
523
 
      {
524
 
        styler.ColourTo( i+1, SCE_NSIS_STRINGVAR);
525
 
                                bClassicVarInString = false;
526
 
      }
527
 
 
528
 
      // Start of var in string
529
 
                        if( !bIngoreNextDollarSign && cCurrChar == '$' && cNextChar == '{' )
530
 
                        {
531
 
                                styler.ColourTo( i-1, state);
532
 
                                bClassicVarInString = true;
533
 
        bVarInString = false;
534
 
                        }
535
 
      else if( !bIngoreNextDollarSign && cCurrChar == '$' )
536
 
      {
537
 
        styler.ColourTo( i-1, state);
538
 
        bVarInString = true;
539
 
        bClassicVarInString = false;
540
 
      }
541
 
                }
542
 
        }
543
 
 
544
 
  // Colourise remaining document
545
 
        styler.ColourTo(nLengthDoc-1,state);
546
 
}
547
 
 
548
 
static void FoldNsisDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler)
549
 
{
550
 
        // No folding enabled, no reason to continue...
551
 
        if( styler.GetPropertyInt("fold") == 0 )
552
 
                return;
553
 
 
554
 
  bool foldAtElse = styler.GetPropertyInt("fold.at.else", 0) == 1;
555
 
  bool foldUtilityCmd = styler.GetPropertyInt("nsis.foldutilcmd", 1) == 1;
556
 
  bool blockComment = false;
557
 
 
558
 
  int lineCurrent = styler.GetLine(startPos);
559
 
  unsigned int safeStartPos = styler.LineStart( lineCurrent );
560
 
 
561
 
  bool bArg1 = true;
562
 
  int nWordStart = -1;
563
 
 
564
 
  int levelCurrent = SC_FOLDLEVELBASE;
565
 
        if (lineCurrent > 0)
566
 
                levelCurrent = styler.LevelAt(lineCurrent-1) >> 16;
567
 
        int levelNext = levelCurrent;
568
 
  int style = styler.StyleAt(safeStartPos);
569
 
  if( style == SCE_NSIS_COMMENTBOX )
570
 
  {
571
 
    if( styler.SafeGetCharAt(safeStartPos) == '/' && styler.SafeGetCharAt(safeStartPos+1) == '*' )
572
 
      levelNext++;
573
 
    blockComment = true;
574
 
  }
575
 
 
576
 
  for (unsigned int i = safeStartPos; i < startPos + length; i++)
577
 
        {
578
 
    char chCurr = styler.SafeGetCharAt(i);
579
 
    style = styler.StyleAt(i);
580
 
    if( blockComment && style != SCE_NSIS_COMMENTBOX )
581
 
    {
582
 
      levelNext--;
583
 
      blockComment = false;
584
 
    }
585
 
    else if( !blockComment && style == SCE_NSIS_COMMENTBOX )
586
 
    {
587
 
      levelNext++;
588
 
      blockComment = true;
589
 
    }
590
 
 
591
 
    if( bArg1 && !blockComment)
592
 
    {
593
 
      if( nWordStart == -1 && (isNsisLetter(chCurr) || chCurr == '!') )
594
 
      {
595
 
        nWordStart = i;
596
 
      }
597
 
      else if( isNsisLetter(chCurr) == false && nWordStart > -1 )
598
 
      {
599
 
        int newLevel = calculateFoldNsis( nWordStart, i-1, levelNext, styler, foldAtElse, foldUtilityCmd );
600
 
 
601
 
        if( newLevel == levelNext )
602
 
        {
603
 
          if( foldAtElse && foldUtilityCmd )
604
 
          {
605
 
            if( NsisNextLineHasElse(i, startPos + length, styler) )
606
 
              levelNext--;
607
 
          }
608
 
        }
609
 
        else
610
 
          levelNext = newLevel;
611
 
        bArg1 = false;
612
 
      }
613
 
    }
614
 
 
615
 
    if( chCurr == '\n' )
616
 
    {
617
 
      if( bArg1 && foldAtElse && foldUtilityCmd && !blockComment )
618
 
      {
619
 
        if( NsisNextLineHasElse(i, startPos + length, styler) )
620
 
          levelNext--;
621
 
      }
622
 
 
623
 
      // If we are on a new line...
624
 
      int levelUse = levelCurrent;
625
 
                        int lev = levelUse | levelNext << 16;
626
 
      if (levelUse < levelNext )
627
 
                                lev |= SC_FOLDLEVELHEADERFLAG;
628
 
                        if (lev != styler.LevelAt(lineCurrent))
629
 
                                styler.SetLevel(lineCurrent, lev);
630
 
 
631
 
                        lineCurrent++;
632
 
                        levelCurrent = levelNext;
633
 
      bArg1 = true; // New line, lets look at first argument again
634
 
      nWordStart = -1;
635
 
    }
636
 
  }
637
 
 
638
 
        int levelUse = levelCurrent;
639
 
        int lev = levelUse | levelNext << 16;
640
 
        if (levelUse < levelNext)
641
 
                lev |= SC_FOLDLEVELHEADERFLAG;
642
 
        if (lev != styler.LevelAt(lineCurrent))
643
 
                styler.SetLevel(lineCurrent, lev);
644
 
}
645
 
 
646
 
static const char * const nsisWordLists[] = {
647
 
        "Functions",
648
 
        "Variables",
649
 
        "Lables",
650
 
        "UserDefined",
651
 
        0, };
652
 
 
653
 
 
654
 
LexerModule lmNsis(SCLEX_NSIS, ColouriseNsisDoc, "nsis", FoldNsisDoc, nsisWordLists);
655