1 // Scintilla source code edit control
\r
3 ** Lexer for MPT specific files. Based on LexOthers.cxx
\r
4 ** LOT = the text log file created by the MPT application while running a test program
\r
5 ** Other MPT specific files to be added later.
\r
7 // Copyright 2003 by Marius Gheorghe <mgheorghe@cabletest.com>
\r
8 // The License.txt file describes the conditions under which this software may be distributed.
\r
14 #include "Platform.h"
\r
16 #include "PropSet.h"
\r
17 #include "Accessor.h"
\r
18 #include "KeyWords.h"
\r
19 #include "Scintilla.h"
\r
20 #include "SciLexer.h"
\r
21 #include "SString.h"
\r
23 #ifdef SCI_NAMESPACE
\r
24 using namespace Scintilla;
\r
27 static int GetLotLineState(SString &line) {
\r
28 if (line.length()) {
\r
29 // Most of the time the first non-blank character in line determines that line's type
\r
30 // Now finds the first non-blank character
\r
31 unsigned i; // Declares counter here to make it persistent after the for loop
\r
32 for (i = 0; i < line.length(); ++i) {
\r
33 if (!isspace(line[i]))
\r
37 // Checks if it was a blank line
\r
38 if (i == line.length())
\r
39 return SCE_LOT_DEFAULT;
\r
42 case '*': // Fail measurement
\r
43 return SCE_LOT_FAIL;
\r
47 return SCE_LOT_HEADER;
\r
49 case ':': // Set test limits
\r
52 case '-': // Section break
\r
53 return SCE_LOT_BREAK;
\r
55 default: // Any other line
\r
56 // Checks for message at the end of lot file
\r
57 if (line.contains("PASSED")) {
\r
58 return SCE_LOT_PASS;
\r
60 else if (line.contains("FAILED")) {
\r
61 return SCE_LOT_FAIL;
\r
63 else if (line.contains("ABORTED")) {
\r
64 return SCE_LOT_ABORT;
\r
67 return i ? SCE_LOT_PASS : SCE_LOT_DEFAULT;
\r
72 return SCE_LOT_DEFAULT;
\r
76 static void ColourizeLotDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
\r
77 styler.StartAt(startPos);
\r
78 styler.StartSegment(startPos);
\r
79 bool atLineStart = true;// Arms the 'at line start' flag
\r
80 char chNext = styler.SafeGetCharAt(startPos);
\r
82 line.setsizegrowth(256); // Lot lines are less than 256 chars long most of the time. This should avoid reallocations
\r
84 // Styles LOT document
\r
85 unsigned int i; // Declared here because it's used after the for loop
\r
86 for (i = startPos; i < startPos + length; ++i) {
\r
88 chNext = styler.SafeGetCharAt(i + 1);
\r
90 atLineStart = false;
\r
92 // LOT files are only used on the Win32 platform, thus EOL == CR+LF
\r
93 // Searches for the end of line
\r
94 if (ch == '\r' && chNext == '\n') {
\r
95 line += chNext; // Gets the '\n'
\r
96 ++i; // Advances past the '\n'
\r
97 chNext = styler.SafeGetCharAt(i + 1); // Gets character of next line
\r
98 styler.ColourTo(i, GetLotLineState(line));
\r
100 atLineStart = true; // Arms flag for next line
\r
104 // Last line may not have a line ending
\r
105 if (!atLineStart) {
\r
106 styler.ColourTo(i - 1, GetLotLineState(line));
\r
110 // Folds an MPT LOT file: the blocks that can be folded are:
\r
111 // sections (headed by a set line)
\r
112 // passes (contiguous pass results within a section)
\r
113 // fails (contiguous fail results within a section)
\r
114 static void FoldLotDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
\r
115 bool foldCompact = styler.GetPropertyInt("fold.compact", 0) != 0;
\r
116 unsigned int endPos = startPos + length;
\r
117 int visibleChars = 0;
\r
118 int lineCurrent = styler.GetLine(startPos);
\r
120 char chNext = styler.SafeGetCharAt(startPos);
\r
121 int style = SCE_LOT_DEFAULT;
\r
122 int styleNext = styler.StyleAt(startPos);
\r
123 int lev = SC_FOLDLEVELBASE;
\r
125 // Gets style of previous line if not at the beginning of the document
\r
127 style = styler.StyleAt(startPos - 2);
\r
129 for (unsigned int i = startPos; i < endPos; i++) {
\r
131 chNext = styler.SafeGetCharAt(i + 1);
\r
133 if (ch == '\r' && chNext == '\n') {
\r
135 // Should really get the state of the previous line from the styler
\r
136 int stylePrev = style;
\r
138 styleNext = styler.StyleAt(i + 2);
\r
143 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
\r
148 if (stylePrev != SCE_LOT_FAIL)
\r
149 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
\r
151 lev = SC_FOLDLEVELBASE + 1;
\r
153 lev = SC_FOLDLEVELBASE;
\r
157 if (lineCurrent == 0 || stylePrev == SCE_LOT_FAIL)
\r
158 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
\r
160 lev = SC_FOLDLEVELBASE + 1;
\r
162 if (visibleChars == 0 && foldCompact)
\r
163 lev |= SC_FOLDLEVELWHITEFLAG;
\r
167 if (lev != styler.LevelAt(lineCurrent))
\r
168 styler.SetLevel(lineCurrent, lev);
\r
174 if (!isspacechar(ch))
\r
178 int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
\r
179 styler.SetLevel(lineCurrent, lev | flagsNext);
\r
182 static const char * const emptyWordListDesc[] = {
\r
186 LexerModule lmLot(SCLEX_LOT, ColourizeLotDoc, "lot", FoldLotDoc, emptyWordListDesc);
\r