]>
git.saurik.com Git - wxWidgets.git/blob - contrib/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"
23 static int GetLotLineState(SString
&line
) {
25 // Most of the time the first non-blank character in line determines that line's type
26 // Now finds the first non-blank character
27 unsigned i
; // Declares counter here to make it persistent after the for loop
28 for (i
= 0; i
< line
.length(); ++i
) {
29 if (!isspace(line
[i
]))
33 // Checks if it was a blank line
34 if (i
== line
.length())
35 return SCE_LOT_DEFAULT
;
38 case '*': // Fail measurement
43 return SCE_LOT_HEADER
;
45 case ':': // Set test limits
48 case '-': // Section break
51 default: // Any other line
52 // Checks for message at the end of lot file
53 if (line
.contains("PASSED")) {
56 else if (line
.contains("FAILED")) {
59 else if (line
.contains("ABORTED")) {
63 return i
? SCE_LOT_PASS
: SCE_LOT_DEFAULT
;
68 return SCE_LOT_DEFAULT
;
72 static void ColourizeLotDoc(unsigned int startPos
, int length
, int, WordList
*[], Accessor
&styler
) {
73 styler
.StartAt(startPos
);
74 styler
.StartSegment(startPos
);
75 bool atLineStart
= true;// Arms the 'at line start' flag
76 char chNext
= styler
.SafeGetCharAt(startPos
);
78 line
.setsizegrowth(256); // Lot lines are less than 256 chars long most of the time. This should avoid reallocations
80 // Styles LOT document
81 unsigned int i
; // Declared here because it's used after the for loop
82 for (i
= startPos
; i
< startPos
+ length
; ++i
) {
84 chNext
= styler
.SafeGetCharAt(i
+ 1);
88 // LOT files are only used on the Win32 platform, thus EOL == CR+LF
89 // Searches for the end of line
90 if (ch
== '\r' && chNext
== '\n') {
91 line
+= chNext
; // Gets the '\n'
92 ++i
; // Advances past the '\n'
93 chNext
= styler
.SafeGetCharAt(i
+ 1); // Gets character of next line
94 styler
.ColourTo(i
, GetLotLineState(line
));
96 atLineStart
= true; // Arms flag for next line
100 // Last line may not have a line ending
102 styler
.ColourTo(i
- 1, GetLotLineState(line
));
106 // Folds an MPT LOT file: the blocks that can be folded are:
107 // sections (headed by a set line)
108 // passes (contiguous pass results within a section)
109 // fails (contiguous fail results within a section)
110 static void FoldLotDoc(unsigned int startPos
, int length
, int, WordList
*[], Accessor
&styler
) {
111 bool foldCompact
= styler
.GetPropertyInt("fold.compact", 0) != 0;
112 unsigned int endPos
= startPos
+ length
;
113 int visibleChars
= 0;
114 int lineCurrent
= styler
.GetLine(startPos
);
116 char chNext
= styler
.SafeGetCharAt(startPos
);
117 int style
= SCE_LOT_DEFAULT
;
118 int styleNext
= styler
.StyleAt(startPos
);
119 int lev
= SC_FOLDLEVELBASE
;
121 // Gets style of previous line if not at the beginning of the document
123 style
= styler
.StyleAt(startPos
- 2);
125 for (unsigned int i
= startPos
; i
< endPos
; i
++) {
127 chNext
= styler
.SafeGetCharAt(i
+ 1);
129 if (ch
== '\r' && chNext
== '\n') {
131 // Should really get the state of the previous line from the styler
132 int stylePrev
= style
;
134 styleNext
= styler
.StyleAt(i
+ 2);
139 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
144 if (stylePrev != SCE_LOT_FAIL)
145 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
147 lev = SC_FOLDLEVELBASE + 1;
149 lev
= SC_FOLDLEVELBASE
;
153 if (lineCurrent
== 0 || stylePrev
== SCE_LOT_FAIL
)
154 lev
= SC_FOLDLEVELBASE
| SC_FOLDLEVELHEADERFLAG
;
156 lev
= SC_FOLDLEVELBASE
+ 1;
158 if (visibleChars
== 0 && foldCompact
)
159 lev
|= SC_FOLDLEVELWHITEFLAG
;
163 if (lev
!= styler
.LevelAt(lineCurrent
))
164 styler
.SetLevel(lineCurrent
, lev
);
170 if (!isspacechar(ch
))
174 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
175 styler
.SetLevel(lineCurrent
, lev
| flagsNext
);
178 static const char * const emptyWordListDesc
[] = {
182 LexerModule
lmLot(SCLEX_LOT
, ColourizeLotDoc
, "lot", FoldLotDoc
, emptyWordListDesc
);