~brian-sidebotham/wxwidgets-cmake/wxpython-2.9.4

« back to all changes in this revision

Viewing changes to src/stc/scintilla/src/LexMPT.cxx

  • Committer: Brian Sidebotham
  • Date: 2013-08-03 14:30:08 UTC
  • Revision ID: brian.sidebotham@gmail.com-20130803143008-c7806tkych1tp6fc
Initial import into Bazaar

Show diffs side-by-side

added added

removed removed

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