]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexMPT.cxx
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"
24 using namespace Scintilla
;
27 static int GetLotLineState(SString
&line
) {
29 // Most of the time the first non-blank character in line determines that line's type
30 // Now finds the first non-blank character
31 unsigned i
; // Declares counter here to make it persistent after the for loop
32 for (i
= 0; i
< line
.length(); ++i
) {
33 if (!isspace(line
[i
]))
37 // Checks if it was a blank line
38 if (i
== line
.length())
39 return SCE_LOT_DEFAULT
;
42 case '*': // Fail measurement
47 return SCE_LOT_HEADER
;
49 case ':': // Set test limits
52 case '-': // Section break
55 default: // Any other line
56 // Checks for message at the end of lot file
57 if (line
.contains("PASSED")) {
60 else if (line
.contains("FAILED")) {
63 else if (line
.contains("ABORTED")) {
67 return i
? SCE_LOT_PASS
: SCE_LOT_DEFAULT
;
72 return SCE_LOT_DEFAULT
;
76 static void ColourizeLotDoc(unsigned int startPos
, int length
, int, WordList
*[], Accessor
&styler
) {
77 styler
.StartAt(startPos
);
78 styler
.StartSegment(startPos
);
79 bool atLineStart
= true;// Arms the 'at line start' flag
80 char chNext
= styler
.SafeGetCharAt(startPos
);
82 line
.setsizegrowth(256); // Lot lines are less than 256 chars long most of the time. This should avoid reallocations
84 // Styles LOT document
85 unsigned int i
; // Declared here because it's used after the for loop
86 for (i
= startPos
; i
< startPos
+ length
; ++i
) {
88 chNext
= styler
.SafeGetCharAt(i
+ 1);
92 // LOT files are only used on the Win32 platform, thus EOL == CR+LF
93 // Searches for the end of line
94 if (ch
== '\r' && chNext
== '\n') {
95 line
+= chNext
; // Gets the '\n'
96 ++i
; // Advances past the '\n'
97 chNext
= styler
.SafeGetCharAt(i
+ 1); // Gets character of next line
98 styler
.ColourTo(i
, GetLotLineState(line
));
100 atLineStart
= true; // Arms flag for next line
104 // Last line may not have a line ending
106 styler
.ColourTo(i
- 1, GetLotLineState(line
));
110 // Folds an MPT LOT file: the blocks that can be folded are:
111 // sections (headed by a set line)
112 // passes (contiguous pass results within a section)
113 // fails (contiguous fail results within a section)
114 static void FoldLotDoc(unsigned int startPos
, int length
, int, WordList
*[], Accessor
&styler
) {
115 bool foldCompact
= styler
.GetPropertyInt("fold.compact", 0) != 0;
116 unsigned int endPos
= startPos
+ length
;
117 int visibleChars
= 0;
118 int lineCurrent
= styler
.GetLine(startPos
);
120 char chNext
= styler
.SafeGetCharAt(startPos
);
121 int style
= SCE_LOT_DEFAULT
;
122 int styleNext
= styler
.StyleAt(startPos
);
123 int lev
= SC_FOLDLEVELBASE
;
125 // Gets style of previous line if not at the beginning of the document
127 style
= styler
.StyleAt(startPos
- 2);
129 for (unsigned int i
= startPos
; i
< endPos
; i
++) {
131 chNext
= styler
.SafeGetCharAt(i
+ 1);
133 if (ch
== '\r' && chNext
== '\n') {
135 // Should really get the state of the previous line from the styler
136 int stylePrev
= style
;
138 styleNext
= styler
.StyleAt(i
+ 2);
143 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
148 if (stylePrev != SCE_LOT_FAIL)
149 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
151 lev = SC_FOLDLEVELBASE + 1;
153 lev
= SC_FOLDLEVELBASE
;
157 if (lineCurrent
== 0 || stylePrev
== SCE_LOT_FAIL
)
158 lev
= SC_FOLDLEVELBASE
| SC_FOLDLEVELHEADERFLAG
;
160 lev
= SC_FOLDLEVELBASE
+ 1;
162 if (visibleChars
== 0 && foldCompact
)
163 lev
|= SC_FOLDLEVELWHITEFLAG
;
167 if (lev
!= styler
.LevelAt(lineCurrent
))
168 styler
.SetLevel(lineCurrent
, lev
);
174 if (!isspacechar(ch
))
178 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
179 styler
.SetLevel(lineCurrent
, lev
| flagsNext
);
182 static const char * const emptyWordListDesc
[] = {
186 LexerModule
lmLot(SCLEX_LOT
, ColourizeLotDoc
, "lot", FoldLotDoc
, emptyWordListDesc
);