1
// Scintilla source code edit control
3
** Lexer for MPT specific files. Based on LexOthers.cxx
4
** LOT = the text log file created by the MPT application while running a test program
5
** Other MPT specific files to be added later.
7
// Copyright 2003 by Marius Gheorghe <mgheorghe@cabletest.com>
8
// The License.txt file describes the conditions under which this software may be distributed.
20
#include "Scintilla.h"
24
#include "LexAccessor.h"
26
#include "StyleContext.h"
27
#include "CharacterSet.h"
28
#include "LexerModule.h"
31
using namespace Scintilla;
34
static int GetLotLineState(std::string &line) {
36
// Most of the time the first non-blank character in line determines that line's type
37
// Now finds the first non-blank character
38
unsigned i; // Declares counter here to make it persistent after the for loop
39
for (i = 0; i < line.length(); ++i) {
40
if (!(IsASCII(line[i]) && isspace(line[i])))
44
// Checks if it was a blank line
45
if (i == line.length())
46
return SCE_LOT_DEFAULT;
49
case '*': // Fail measurement
54
return SCE_LOT_HEADER;
56
case ':': // Set test limits
59
case '-': // Section break
62
default: // Any other line
63
// Checks for message at the end of lot file
64
if (line.find("PASSED") != std::string::npos) {
67
else if (line.find("FAILED") != std::string::npos) {
70
else if (line.find("ABORTED") != std::string::npos) {
74
return i ? SCE_LOT_PASS : SCE_LOT_DEFAULT;
79
return SCE_LOT_DEFAULT;
83
static void ColourizeLotDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
84
styler.StartAt(startPos);
85
styler.StartSegment(startPos);
86
bool atLineStart = true;// Arms the 'at line start' flag
87
char chNext = styler.SafeGetCharAt(startPos);
89
line.reserve(256); // Lot lines are less than 256 chars long most of the time. This should avoid reallocations
91
// Styles LOT document
92
unsigned int i; // Declared here because it's used after the for loop
93
for (i = startPos; i < startPos + length; ++i) {
95
chNext = styler.SafeGetCharAt(i + 1);
99
// LOT files are only used on the Win32 platform, thus EOL == CR+LF
100
// Searches for the end of line
101
if (ch == '\r' && chNext == '\n') {
102
line += chNext; // Gets the '\n'
103
++i; // Advances past the '\n'
104
chNext = styler.SafeGetCharAt(i + 1); // Gets character of next line
105
styler.ColourTo(i, GetLotLineState(line));
107
atLineStart = true; // Arms flag for next line
111
// Last line may not have a line ending
113
styler.ColourTo(i - 1, GetLotLineState(line));
117
// Folds an MPT LOT file: the blocks that can be folded are:
118
// sections (headed by a set line)
119
// passes (contiguous pass results within a section)
120
// fails (contiguous fail results within a section)
121
static void FoldLotDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
122
bool foldCompact = styler.GetPropertyInt("fold.compact", 0) != 0;
123
unsigned int endPos = startPos + length;
124
int visibleChars = 0;
125
int lineCurrent = styler.GetLine(startPos);
127
char chNext = styler.SafeGetCharAt(startPos);
128
int style = SCE_LOT_DEFAULT;
129
int styleNext = styler.StyleAt(startPos);
130
int lev = SC_FOLDLEVELBASE;
132
// Gets style of previous line if not at the beginning of the document
134
style = styler.StyleAt(startPos - 2);
136
for (unsigned int i = startPos; i < endPos; i++) {
138
chNext = styler.SafeGetCharAt(i + 1);
140
if (ch == '\r' && chNext == '\n') {
142
// Should really get the state of the previous line from the styler
143
int stylePrev = style;
145
styleNext = styler.StyleAt(i + 2);
150
lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
155
if (stylePrev != SCE_LOT_FAIL)
156
lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
158
lev = SC_FOLDLEVELBASE + 1;
160
lev = SC_FOLDLEVELBASE;
164
if (lineCurrent == 0 || stylePrev == SCE_LOT_FAIL)
165
lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
167
lev = SC_FOLDLEVELBASE + 1;
169
if (visibleChars == 0 && foldCompact)
170
lev |= SC_FOLDLEVELWHITEFLAG;
174
if (lev != styler.LevelAt(lineCurrent))
175
styler.SetLevel(lineCurrent, lev);
181
if (!isspacechar(ch))
185
int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
186
styler.SetLevel(lineCurrent, lev | flagsNext);
189
static const char * const emptyWordListDesc[] = {
193
LexerModule lmLot(SCLEX_LOT, ColourizeLotDoc, "lot", FoldLotDoc, emptyWordListDesc);