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"
30 using namespace Scintilla
;
32 static int GetLotLineState(std::string
&line
) {
34 // Most of the time the first non-blank character in line determines that line's type
35 // Now finds the first non-blank character
36 unsigned i
; // Declares counter here to make it persistent after the for loop
37 for (i
= 0; i
< line
.length(); ++i
) {
38 if (!(IsASCII(line
[i
]) && isspace(line
[i
])))
42 // Checks if it was a blank line
43 if (i
== line
.length())
44 return SCE_LOT_DEFAULT
;
47 case '*': // Fail measurement
52 return SCE_LOT_HEADER
;
54 case ':': // Set test limits
57 case '-': // Section break
60 default: // Any other line
61 // Checks for message at the end of lot file
62 if (line
.find("PASSED") != std::string::npos
) {
65 else if (line
.find("FAILED") != std::string::npos
) {
68 else if (line
.find("ABORTED") != std::string::npos
) {
72 return i
? SCE_LOT_PASS
: SCE_LOT_DEFAULT
;
77 return SCE_LOT_DEFAULT
;
81 static void ColourizeLotDoc(Sci_PositionU startPos
, Sci_Position length
, int, WordList
*[], Accessor
&styler
) {
82 styler
.StartAt(startPos
);
83 styler
.StartSegment(startPos
);
84 bool atLineStart
= true;// Arms the 'at line start' flag
85 char chNext
= styler
.SafeGetCharAt(startPos
);
87 line
.reserve(256); // Lot lines are less than 256 chars long most of the time. This should avoid reallocations
89 // Styles LOT document
90 Sci_PositionU i
; // Declared here because it's used after the for loop
91 for (i
= startPos
; i
< startPos
+ length
; ++i
) {
93 chNext
= styler
.SafeGetCharAt(i
+ 1);
97 // LOT files are only used on the Win32 platform, thus EOL == CR+LF
98 // Searches for the end of line
99 if (ch
== '\r' && chNext
== '\n') {
100 line
+= chNext
; // Gets the '\n'
101 ++i
; // Advances past the '\n'
102 chNext
= styler
.SafeGetCharAt(i
+ 1); // Gets character of next line
103 styler
.ColourTo(i
, GetLotLineState(line
));
105 atLineStart
= true; // Arms flag for next line
109 // Last line may not have a line ending
111 styler
.ColourTo(i
- 1, GetLotLineState(line
));
115 // Folds an MPT LOT file: the blocks that can be folded are:
116 // sections (headed by a set line)
117 // passes (contiguous pass results within a section)
118 // fails (contiguous fail results within a section)
119 static void FoldLotDoc(Sci_PositionU startPos
, Sci_Position length
, int, WordList
*[], Accessor
&styler
) {
120 bool foldCompact
= styler
.GetPropertyInt("fold.compact", 0) != 0;
121 Sci_PositionU endPos
= startPos
+ length
;
122 int visibleChars
= 0;
123 Sci_Position lineCurrent
= styler
.GetLine(startPos
);
125 char chNext
= styler
.SafeGetCharAt(startPos
);
126 int style
= SCE_LOT_DEFAULT
;
127 int styleNext
= styler
.StyleAt(startPos
);
128 int lev
= SC_FOLDLEVELBASE
;
130 // Gets style of previous line if not at the beginning of the document
132 style
= styler
.StyleAt(startPos
- 2);
134 for (Sci_PositionU i
= startPos
; i
< endPos
; i
++) {
136 chNext
= styler
.SafeGetCharAt(i
+ 1);
138 if (ch
== '\r' && chNext
== '\n') {
140 // Should really get the state of the previous line from the styler
141 int stylePrev
= style
;
143 styleNext
= styler
.StyleAt(i
+ 2);
148 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
153 if (stylePrev != SCE_LOT_FAIL)
154 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
156 lev = SC_FOLDLEVELBASE + 1;
158 lev
= SC_FOLDLEVELBASE
;
162 if (lineCurrent
== 0 || stylePrev
== SCE_LOT_FAIL
)
163 lev
= SC_FOLDLEVELBASE
| SC_FOLDLEVELHEADERFLAG
;
165 lev
= SC_FOLDLEVELBASE
+ 1;
167 if (visibleChars
== 0 && foldCompact
)
168 lev
|= SC_FOLDLEVELWHITEFLAG
;
172 if (lev
!= styler
.LevelAt(lineCurrent
))
173 styler
.SetLevel(lineCurrent
, lev
);
179 if (!isspacechar(ch
))
183 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
184 styler
.SetLevel(lineCurrent
, lev
| flagsNext
);
187 static const char * const emptyWordListDesc
[] = {
191 LexerModule
lmLot(SCLEX_LOT
, ColourizeLotDoc
, "lot", FoldLotDoc
, emptyWordListDesc
);