~ubuntu-branches/ubuntu/lucid/codelite/lucid

« back to all changes in this revision

Viewing changes to sdk/wxscintilla/src/scintilla/src/LexFIF.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-01-12 15:46:55 UTC
  • Revision ID: james.westby@ubuntu.com-20090112154655-sdynrljcb6u167yw
Tags: upstream-1.0.2674+dfsg
ImportĀ upstreamĀ versionĀ 1.0.2674+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Scintilla source code edit control
 
2
/** @file LexFIF.cxx
 
3
 ** Lexers for Find In Files output format
 
4
 **/
 
5
// Copyright 1998-2001 by Eran Ifrah <eran.ifrah@gmail.com>
 
6
// The License.txt file describes the conditions under which this software may be distributed.
 
7
 
 
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 "PropSet.h"
 
17
#include "Accessor.h"
 
18
#include "KeyWords.h"
 
19
#include "Scintilla.h"
 
20
#include "SciLexer.h"
 
21
#include <string>
 
22
 
 
23
#ifdef SCI_NAMESPACE
 
24
using namespace Scintilla;
 
25
#endif
 
26
 
 
27
static inline bool AtEOL(Accessor &styler, unsigned int i)
 
28
{
 
29
        return (styler[i] == '\n') ||
 
30
               ((styler[i] == '\r') && (styler.SafeGetCharAt(i + 1) != '\n'));
 
31
}
 
32
 
 
33
static void ColouriseFifDoc(unsigned int pos, int length, int /*initStyle*/,
 
34
                            WordList *[], Accessor &styler)
 
35
{
 
36
        styler.StartAt(pos);
 
37
        styler.StartSegment(pos);
 
38
        for (int firstchar = -1; length > 0; pos++, length--) {
 
39
        if (firstchar == -1) {
 
40
            firstchar = styler[pos]; // first char of each line
 
41
        }
 
42
        if (styler[pos] == ':' && firstchar == ' ') {
 
43
            if (length > 1 && styler[pos+1] == ' ') {
 
44
                // include the following space
 
45
                pos++;
 
46
                length--;
 
47
            }
 
48
            styler.ColourTo(pos, SCLEX_FIF_FILE_SHORT);
 
49
            firstchar = ':'; // first colon only
 
50
            if (length > 1 && styler[pos+1] == '[') {
 
51
                firstchar = '[';
 
52
            }
 
53
                } else if (styler[pos] == ']' && firstchar == '['){
 
54
            if (length > 1 && styler[pos+1] == ' ') {
 
55
                // include the following space
 
56
                pos++;
 
57
                length--;
 
58
            }
 
59
                        styler.ColourTo(pos, SCLEX_FIF_SCOPE);
 
60
            firstchar = ']'; // first ']' only
 
61
                } else if (AtEOL(styler, pos)) {
 
62
            switch (firstchar) {
 
63
                case ' ':
 
64
                case ':':
 
65
                case '[':
 
66
                case ']':
 
67
                    styler.ColourTo(pos, SCLEX_FIF_MATCH);
 
68
                    break;
 
69
                case '=':
 
70
                    styler.ColourTo(pos, SCLEX_FIF_DEFAULT);
 
71
                    break;
 
72
                case '-':
 
73
                    styler.ColourTo(pos, SCLEX_FIF_PROJECT);
 
74
                    break;
 
75
                default:
 
76
                    styler.ColourTo(pos, SCLEX_FIF_FILE);
 
77
                    break;
 
78
            }
 
79
            firstchar = -1;
 
80
        }
 
81
        }
 
82
}
 
83
 
 
84
static void FoldFifDoc(unsigned int pos, int length, int,
 
85
                       WordList*[], Accessor &styler)
 
86
{
 
87
        int curLine = styler.GetLine(pos);
 
88
        int prevLevel = curLine > 0 ? styler.LevelAt(curLine-1) : SC_FOLDLEVELBASE;
 
89
 
 
90
    unsigned int end = pos+length;
 
91
    pos = styler.LineStart(curLine);
 
92
 
 
93
        do {
 
94
        int nextLevel;
 
95
        switch (styler.StyleAt(pos)) {
 
96
            case SCLEX_FIF_DEFAULT:
 
97
                nextLevel = SC_FOLDLEVELBASE;
 
98
                break;
 
99
            case SCLEX_FIF_PROJECT:
 
100
                nextLevel = (SC_FOLDLEVELBASE + 1) | SC_FOLDLEVELHEADERFLAG;
 
101
                break;
 
102
            case SCLEX_FIF_FILE:
 
103
                nextLevel = (SC_FOLDLEVELBASE + 2) | SC_FOLDLEVELHEADERFLAG;
 
104
                break;
 
105
            default:
 
106
                nextLevel = prevLevel & SC_FOLDLEVELHEADERFLAG ? (prevLevel & SC_FOLDLEVELNUMBERMASK) + 1 : prevLevel;
 
107
                break;
 
108
        }
 
109
                if ((nextLevel & SC_FOLDLEVELHEADERFLAG) && nextLevel == prevLevel) {
 
110
                        styler.SetLevel(curLine-1, prevLevel & ~SC_FOLDLEVELHEADERFLAG);
 
111
        }
 
112
                styler.SetLevel(curLine, nextLevel);
 
113
 
 
114
        curLine++;
 
115
                prevLevel = nextLevel;
 
116
                pos = styler.LineStart(curLine);
 
117
        } while (pos < end);
 
118
}
 
119
 
 
120
static const char * const fifWordListDesc[] = {
 
121
        "Internal Commands",
 
122
        "External Commands",
 
123
        0
 
124
};
 
125
 
 
126
static const char * const emptyWordListDesc[] = {
 
127
        0
 
128
};
 
129
 
 
130
LexerModule lmFif(SCLEX_FIF, ColouriseFifDoc, "fif", FoldFifDoc, fifWordListDesc);