]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/lexers/LexMPT.cxx
wxRTC text box layout fixes
[wxWidgets.git] / src / stc / scintilla / lexers / LexMPT.cxx
1 // Scintilla source code edit control
2 /** @file LexMPT.cxx
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.
6 **/
7 // Copyright 2003 by Marius Gheorghe <mgheorghe@cabletest.com>
8 // The License.txt file describes the conditions under which this software may be distributed.
9
10 #include <stdlib.h>
11 #include <string.h>
12 #include <stdio.h>
13 #include <stdarg.h>
14 #include <assert.h>
15 #include <ctype.h>
16
17 #include <string>
18
19 #include "ILexer.h"
20 #include "Scintilla.h"
21 #include "SciLexer.h"
22
23 #include "WordList.h"
24 #include "LexAccessor.h"
25 #include "Accessor.h"
26 #include "StyleContext.h"
27 #include "CharacterSet.h"
28 #include "LexerModule.h"
29
30 #ifdef SCI_NAMESPACE
31 using namespace Scintilla;
32 #endif
33
34 static int GetLotLineState(std::string &line) {
35 if (line.length()) {
36 // Most of the time the first non-blank character in line determines that line's type
37 // Now finds the first non-blank character
38 unsigned i; // Declares counter here to make it persistent after the for loop
39 for (i = 0; i < line.length(); ++i) {
40 if (!(isascii(line[i]) && isspace(line[i])))
41 break;
42 }
43
44 // Checks if it was a blank line
45 if (i == line.length())
46 return SCE_LOT_DEFAULT;
47
48 switch (line[i]) {
49 case '*': // Fail measurement
50 return SCE_LOT_FAIL;
51
52 case '+': // Header
53 case '|': // Header
54 return SCE_LOT_HEADER;
55
56 case ':': // Set test limits
57 return SCE_LOT_SET;
58
59 case '-': // Section break
60 return SCE_LOT_BREAK;
61
62 default: // Any other line
63 // Checks for message at the end of lot file
64 if (line.find("PASSED") != std::string::npos) {
65 return SCE_LOT_PASS;
66 }
67 else if (line.find("FAILED") != std::string::npos) {
68 return SCE_LOT_FAIL;
69 }
70 else if (line.find("ABORTED") != std::string::npos) {
71 return SCE_LOT_ABORT;
72 }
73 else {
74 return i ? SCE_LOT_PASS : SCE_LOT_DEFAULT;
75 }
76 }
77 }
78 else {
79 return SCE_LOT_DEFAULT;
80 }
81 }
82
83 static void ColourizeLotDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
84 styler.StartAt(startPos);
85 styler.StartSegment(startPos);
86 bool atLineStart = true;// Arms the 'at line start' flag
87 char chNext = styler.SafeGetCharAt(startPos);
88 std::string line("");
89 line.reserve(256); // Lot lines are less than 256 chars long most of the time. This should avoid reallocations
90
91 // Styles LOT document
92 unsigned int i; // Declared here because it's used after the for loop
93 for (i = startPos; i < startPos + length; ++i) {
94 char ch = chNext;
95 chNext = styler.SafeGetCharAt(i + 1);
96 line += ch;
97 atLineStart = false;
98
99 // LOT files are only used on the Win32 platform, thus EOL == CR+LF
100 // Searches for the end of line
101 if (ch == '\r' && chNext == '\n') {
102 line += chNext; // Gets the '\n'
103 ++i; // Advances past the '\n'
104 chNext = styler.SafeGetCharAt(i + 1); // Gets character of next line
105 styler.ColourTo(i, GetLotLineState(line));
106 line = "";
107 atLineStart = true; // Arms flag for next line
108 }
109 }
110
111 // Last line may not have a line ending
112 if (!atLineStart) {
113 styler.ColourTo(i - 1, GetLotLineState(line));
114 }
115 }
116
117 // Folds an MPT LOT file: the blocks that can be folded are:
118 // sections (headed by a set line)
119 // passes (contiguous pass results within a section)
120 // fails (contiguous fail results within a section)
121 static void FoldLotDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
122 bool foldCompact = styler.GetPropertyInt("fold.compact", 0) != 0;
123 unsigned int endPos = startPos + length;
124 int visibleChars = 0;
125 int lineCurrent = styler.GetLine(startPos);
126
127 char chNext = styler.SafeGetCharAt(startPos);
128 int style = SCE_LOT_DEFAULT;
129 int styleNext = styler.StyleAt(startPos);
130 int lev = SC_FOLDLEVELBASE;
131
132 // Gets style of previous line if not at the beginning of the document
133 if (startPos > 1)
134 style = styler.StyleAt(startPos - 2);
135
136 for (unsigned int i = startPos; i < endPos; i++) {
137 char ch = chNext;
138 chNext = styler.SafeGetCharAt(i + 1);
139
140 if (ch == '\r' && chNext == '\n') {
141 // TO DO:
142 // Should really get the state of the previous line from the styler
143 int stylePrev = style;
144 style = styleNext;
145 styleNext = styler.StyleAt(i + 2);
146
147 switch (style) {
148 /*
149 case SCE_LOT_SET:
150 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
151 break;
152 */
153 case SCE_LOT_FAIL:
154 /*
155 if (stylePrev != SCE_LOT_FAIL)
156 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
157 else
158 lev = SC_FOLDLEVELBASE + 1;
159 */
160 lev = SC_FOLDLEVELBASE;
161 break;
162
163 default:
164 if (lineCurrent == 0 || stylePrev == SCE_LOT_FAIL)
165 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
166 else
167 lev = SC_FOLDLEVELBASE + 1;
168
169 if (visibleChars == 0 && foldCompact)
170 lev |= SC_FOLDLEVELWHITEFLAG;
171 break;
172 }
173
174 if (lev != styler.LevelAt(lineCurrent))
175 styler.SetLevel(lineCurrent, lev);
176
177 lineCurrent++;
178 visibleChars = 0;
179 }
180
181 if (!isspacechar(ch))
182 visibleChars++;
183 }
184
185 int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
186 styler.SetLevel(lineCurrent, lev | flagsNext);
187 }
188
189 static const char * const emptyWordListDesc[] = {
190 0
191 };
192
193 LexerModule lmLot(SCLEX_LOT, ColourizeLotDoc, "lot", FoldLotDoc, emptyWordListDesc);