1
// Scintilla source code edit control
3
** Lexers for Find In Files output format
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.
19
#include "Scintilla.h"
24
using namespace Scintilla;
27
static inline bool AtEOL(Accessor &styler, unsigned int i)
29
return (styler[i] == '\n') ||
30
((styler[i] == '\r') && (styler.SafeGetCharAt(i + 1) != '\n'));
33
static void ColouriseFifDoc(unsigned int pos, int length, int /*initStyle*/,
34
WordList *[], Accessor &styler)
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
42
if (styler[pos] == ':' && firstchar == ' ') {
43
if (length > 1 && styler[pos+1] == ' ') {
44
// include the following space
48
styler.ColourTo(pos, SCLEX_FIF_FILE_SHORT);
49
firstchar = ':'; // first colon only
50
if (length > 1 && styler[pos+1] == '[') {
53
} else if (styler[pos] == ']' && firstchar == '['){
54
if (length > 1 && styler[pos+1] == ' ') {
55
// include the following space
59
styler.ColourTo(pos, SCLEX_FIF_SCOPE);
60
firstchar = ']'; // first ']' only
61
} else if (AtEOL(styler, pos)) {
67
styler.ColourTo(pos, SCLEX_FIF_MATCH);
70
styler.ColourTo(pos, SCLEX_FIF_DEFAULT);
73
styler.ColourTo(pos, SCLEX_FIF_PROJECT);
76
styler.ColourTo(pos, SCLEX_FIF_FILE);
84
static void FoldFifDoc(unsigned int pos, int length, int,
85
WordList*[], Accessor &styler)
87
int curLine = styler.GetLine(pos);
88
int prevLevel = curLine > 0 ? styler.LevelAt(curLine-1) : SC_FOLDLEVELBASE;
90
unsigned int end = pos+length;
91
pos = styler.LineStart(curLine);
95
switch (styler.StyleAt(pos)) {
96
case SCLEX_FIF_DEFAULT:
97
nextLevel = SC_FOLDLEVELBASE;
99
case SCLEX_FIF_PROJECT:
100
nextLevel = (SC_FOLDLEVELBASE + 1) | SC_FOLDLEVELHEADERFLAG;
103
nextLevel = (SC_FOLDLEVELBASE + 2) | SC_FOLDLEVELHEADERFLAG;
106
nextLevel = prevLevel & SC_FOLDLEVELHEADERFLAG ? (prevLevel & SC_FOLDLEVELNUMBERMASK) + 1 : prevLevel;
109
if ((nextLevel & SC_FOLDLEVELHEADERFLAG) && nextLevel == prevLevel) {
110
styler.SetLevel(curLine-1, prevLevel & ~SC_FOLDLEVELHEADERFLAG);
112
styler.SetLevel(curLine, nextLevel);
115
prevLevel = nextLevel;
116
pos = styler.LineStart(curLine);
120
static const char * const fifWordListDesc[] = {
126
static const char * const emptyWordListDesc[] = {
130
LexerModule lmFif(SCLEX_FIF, ColouriseFifDoc, "fif", FoldFifDoc, fifWordListDesc);