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.
19 #include "Scintilla.h"
23 #include "LexAccessor.h"
25 #include "StyleContext.h"
26 #include "CharacterSet.h"
27 #include "LexerModule.h"
30 using namespace Scintilla
;
33 static int GetLotLineState(std::string
&line
) {
35 // Most of the time the first non-blank character in line determines that line's type
36 // Now finds the first non-blank character
37 unsigned i
; // Declares counter here to make it persistent after the for loop
38 for (i
= 0; i
< line
.length(); ++i
) {
39 if (!(isascii(line
[i
]) && isspace(line
[i
])))
43 // Checks if it was a blank line
44 if (i
== line
.length())
45 return SCE_LOT_DEFAULT
;
48 case '*': // Fail measurement
53 return SCE_LOT_HEADER
;
55 case ':': // Set test limits
58 case '-': // Section break
61 default: // Any other line
62 // Checks for message at the end of lot file
63 if (line
.find("PASSED") != std::string::npos
) {
66 else if (line
.find("FAILED") != std::string::npos
) {
69 else if (line
.find("ABORTED") != std::string::npos
) {
73 return i
? SCE_LOT_PASS
: SCE_LOT_DEFAULT
;
78 return SCE_LOT_DEFAULT
;
82 static void ColourizeLotDoc(unsigned int startPos
, int length
, int, WordList
*[], Accessor
&styler
) {
83 styler
.StartAt(startPos
);
84 styler
.StartSegment(startPos
);
85 bool atLineStart
= true;// Arms the 'at line start' flag
86 char chNext
= styler
.SafeGetCharAt(startPos
);
88 line
.reserve(256); // Lot lines are less than 256 chars long most of the time. This should avoid reallocations
90 // Styles LOT document
91 unsigned int i
; // Declared here because it's used after the for loop
92 for (i
= startPos
; i
< startPos
+ length
; ++i
) {
94 chNext
= styler
.SafeGetCharAt(i
+ 1);
98 // LOT files are only used on the Win32 platform, thus EOL == CR+LF
99 // Searches for the end of line
100 if (ch
== '\r' && chNext
== '\n') {
101 line
+= chNext
; // Gets the '\n'
102 ++i
; // Advances past the '\n'
103 chNext
= styler
.SafeGetCharAt(i
+ 1); // Gets character of next line
104 styler
.ColourTo(i
, GetLotLineState(line
));
106 atLineStart
= true; // Arms flag for next line
110 // Last line may not have a line ending
112 styler
.ColourTo(i
- 1, GetLotLineState(line
));
116 // Folds an MPT LOT file: the blocks that can be folded are:
117 // sections (headed by a set line)
118 // passes (contiguous pass results within a section)
119 // fails (contiguous fail results within a section)
120 static void FoldLotDoc(unsigned int startPos
, int length
, int, WordList
*[], Accessor
&styler
) {
121 bool foldCompact
= styler
.GetPropertyInt("fold.compact", 0) != 0;
122 unsigned int endPos
= startPos
+ length
;
123 int visibleChars
= 0;
124 int lineCurrent
= styler
.GetLine(startPos
);
126 char chNext
= styler
.SafeGetCharAt(startPos
);
127 int style
= SCE_LOT_DEFAULT
;
128 int styleNext
= styler
.StyleAt(startPos
);
129 int lev
= SC_FOLDLEVELBASE
;
131 // Gets style of previous line if not at the beginning of the document
133 style
= styler
.StyleAt(startPos
- 2);
135 for (unsigned int i
= startPos
; i
< endPos
; i
++) {
137 chNext
= styler
.SafeGetCharAt(i
+ 1);
139 if (ch
== '\r' && chNext
== '\n') {
141 // Should really get the state of the previous line from the styler
142 int stylePrev
= style
;
144 styleNext
= styler
.StyleAt(i
+ 2);
149 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
154 if (stylePrev != SCE_LOT_FAIL)
155 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
157 lev = SC_FOLDLEVELBASE + 1;
159 lev
= SC_FOLDLEVELBASE
;
163 if (lineCurrent
== 0 || stylePrev
== SCE_LOT_FAIL
)
164 lev
= SC_FOLDLEVELBASE
| SC_FOLDLEVELHEADERFLAG
;
166 lev
= SC_FOLDLEVELBASE
+ 1;
168 if (visibleChars
== 0 && foldCompact
)
169 lev
|= SC_FOLDLEVELWHITEFLAG
;
173 if (lev
!= styler
.LevelAt(lineCurrent
))
174 styler
.SetLevel(lineCurrent
, lev
);
180 if (!isspacechar(ch
))
184 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
185 styler
.SetLevel(lineCurrent
, lev
| flagsNext
);
188 static const char * const emptyWordListDesc
[] = {
192 LexerModule
lmLot(SCLEX_LOT
, ColourizeLotDoc
, "lot", FoldLotDoc
, emptyWordListDesc
);