~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/sdk/wxscintilla/src/scintilla/src/LexPLM.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 1990-2007, Scientific Toolworks, Inc.
 
2
// Author: Jason Haslam
 
3
// The License.txt file describes the conditions under which this software may be distributed.
 
4
 
 
5
#include <stdlib.h>
 
6
#include <string.h>
 
7
#include <ctype.h>
 
8
#include <stdio.h>
 
9
#include <stdarg.h>
 
10
 
 
11
#include "Platform.h"
 
12
 
 
13
#include "PropSet.h"
 
14
#include "Accessor.h"
 
15
#include "KeyWords.h"
 
16
#include "Scintilla.h"
 
17
#include "SciLexer.h"
 
18
#include "StyleContext.h"
 
19
 
 
20
#ifdef SCI_NAMESPACE
 
21
using namespace Scintilla;
 
22
#endif
 
23
 
 
24
static void GetRange(unsigned int start,
 
25
                     unsigned int end,
 
26
                     Accessor &styler,
 
27
                     char *s,
 
28
                     unsigned int len) {
 
29
        unsigned int i = 0;
 
30
        while ((i < end - start + 1) && (i < len-1)) {
 
31
                s[i] = static_cast<char>(tolower(styler[start + i]));
 
32
                i++;
 
33
        }
 
34
        s[i] = '\0';
 
35
}
 
36
 
 
37
static void ColourisePlmDoc(unsigned int startPos,
 
38
                            int length,
 
39
                            int initStyle,
 
40
                            WordList *keywordlists[],
 
41
                            Accessor &styler)
 
42
{
 
43
        unsigned int endPos = startPos + length;
 
44
        int state = initStyle;
 
45
 
 
46
        styler.StartAt(startPos);
 
47
        styler.StartSegment(startPos);
 
48
 
 
49
        for (unsigned int i = startPos; i < endPos; i++) {
 
50
                char ch = styler.SafeGetCharAt(i);
 
51
                char chNext = styler.SafeGetCharAt(i + 1);
 
52
 
 
53
                if (state == SCE_PLM_DEFAULT) {
 
54
                        if (ch == '/' && chNext == '*') {
 
55
                                styler.ColourTo(i - 1, state);
 
56
                                state = SCE_PLM_COMMENT;
 
57
                        } else if (ch == '\'') {
 
58
                                styler.ColourTo(i - 1, state);
 
59
                                state = SCE_PLM_STRING;
 
60
                        } else if (isdigit(ch)) {
 
61
                                styler.ColourTo(i - 1, state);
 
62
                                state = SCE_PLM_NUMBER;
 
63
                        } else if (isalpha(ch)) {
 
64
                                styler.ColourTo(i - 1, state);
 
65
                                state = SCE_PLM_IDENTIFIER;
 
66
                        } else if (ch == '+' || ch == '-' || ch == '*' || ch == '/' ||
 
67
                                   ch == '=' || ch == '<' || ch == '>' || ch == ':') {
 
68
                                styler.ColourTo(i - 1, state);
 
69
                                state = SCE_PLM_OPERATOR;
 
70
                        } else if (ch == '$') {
 
71
                                styler.ColourTo(i - 1, state);
 
72
                                state = SCE_PLM_CONTROL;
 
73
                        }
 
74
                } else if (state == SCE_PLM_COMMENT) {
 
75
                        if (ch == '*' && chNext == '/') {
 
76
                                i++;
 
77
                                styler.ColourTo(i, state);
 
78
                                state = SCE_PLM_DEFAULT;
 
79
                        }
 
80
                } else if (state == SCE_PLM_STRING) {
 
81
                        if (ch == '\'') {
 
82
                                if (chNext == '\'') {
 
83
                                        i++;
 
84
                                } else {
 
85
                                        styler.ColourTo(i, state);
 
86
                                        state = SCE_PLM_DEFAULT;
 
87
                                }
 
88
                        }
 
89
                } else if (state == SCE_PLM_NUMBER) {
 
90
                        if (!isdigit(ch) && !isalpha(ch) && ch != '$') {
 
91
                                i--;
 
92
                                styler.ColourTo(i, state);
 
93
                                state = SCE_PLM_DEFAULT;
 
94
                        }
 
95
                } else if (state == SCE_PLM_IDENTIFIER) {
 
96
                        if (!isdigit(ch) && !isalpha(ch) && ch != '$') {
 
97
                                // Get the entire identifier.
 
98
                                char word[1024];
 
99
                                int segmentStart = styler.GetStartSegment();
 
100
                                GetRange(segmentStart, i - 1, styler, word, sizeof(word));
 
101
 
 
102
                                i--;
 
103
                                if (keywordlists[0]->InList(word))
 
104
                                        styler.ColourTo(i, SCE_PLM_KEYWORD);
 
105
                                else
 
106
                                        styler.ColourTo(i, state);
 
107
                                state = SCE_PLM_DEFAULT;
 
108
                        }
 
109
                } else if (state == SCE_PLM_OPERATOR) {
 
110
                        if (ch != '=' && ch != '>') {
 
111
                                i--;
 
112
                                styler.ColourTo(i, state);
 
113
                                state = SCE_PLM_DEFAULT;
 
114
                        }
 
115
                } else if (state == SCE_PLM_CONTROL) {
 
116
                        if (ch == '\r' || ch == '\n') {
 
117
                                styler.ColourTo(i - 1, state);
 
118
                                state = SCE_PLM_DEFAULT;
 
119
                        }
 
120
                }
 
121
        }
 
122
        styler.ColourTo(endPos - 1, state);
 
123
}
 
124
 
 
125
static void FoldPlmDoc(unsigned int startPos,
 
126
                       int length,
 
127
                       int initStyle,
 
128
                       WordList *[],
 
129
                       Accessor &styler)
 
130
{
 
131
        bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
 
132
        bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
 
133
        unsigned int endPos = startPos + length;
 
134
        int visibleChars = 0;
 
135
        int lineCurrent = styler.GetLine(startPos);
 
136
        int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
 
137
        int levelCurrent = levelPrev;
 
138
        char chNext = styler[startPos];
 
139
        int styleNext = styler.StyleAt(startPos);
 
140
        int style = initStyle;
 
141
        int startKeyword = 0;
 
142
 
 
143
        for (unsigned int i = startPos; i < endPos; i++) {
 
144
                char ch = chNext;
 
145
                chNext = styler.SafeGetCharAt(i + 1);
 
146
                int stylePrev = style;
 
147
                style = styleNext;
 
148
                styleNext = styler.StyleAt(i + 1);
 
149
                bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
 
150
 
 
151
                if (stylePrev != SCE_PLM_KEYWORD && style == SCE_PLM_KEYWORD)
 
152
                        startKeyword = i;
 
153
 
 
154
                if (style == SCE_PLM_KEYWORD && styleNext != SCE_PLM_KEYWORD) {
 
155
                        char word[1024];
 
156
                        GetRange(startKeyword, i, styler, word, sizeof(word));
 
157
 
 
158
                        if (strcmp(word, "procedure") == 0 || strcmp(word, "do") == 0)
 
159
                                levelCurrent++;
 
160
                        else if (strcmp(word, "end") == 0)
 
161
                                levelCurrent--;
 
162
                }
 
163
 
 
164
                if (foldComment) {
 
165
                        if (stylePrev != SCE_PLM_COMMENT && style == SCE_PLM_COMMENT)
 
166
                                levelCurrent++;
 
167
                        else if (stylePrev == SCE_PLM_COMMENT && style != SCE_PLM_COMMENT)
 
168
                                levelCurrent--;
 
169
                }
 
170
 
 
171
                if (atEOL) {
 
172
                        int lev = levelPrev;
 
173
                        if (visibleChars == 0 && foldCompact)
 
174
                                lev |= SC_FOLDLEVELWHITEFLAG;
 
175
                        if ((levelCurrent > levelPrev) && (visibleChars > 0))
 
176
                                lev |= SC_FOLDLEVELHEADERFLAG;
 
177
                        if (lev != styler.LevelAt(lineCurrent)) {
 
178
                                styler.SetLevel(lineCurrent, lev);
 
179
                        }
 
180
                        lineCurrent++;
 
181
                        levelPrev = levelCurrent;
 
182
                        visibleChars = 0;
 
183
                }
 
184
 
 
185
                if (!isspacechar(ch))
 
186
                        visibleChars++;
 
187
        }
 
188
 
 
189
        int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
 
190
        styler.SetLevel(lineCurrent, levelPrev | flagsNext);
 
191
}
 
192
 
 
193
static const char *const plmWordListDesc[] = {
 
194
        "Keywords",
 
195
        0
 
196
};
 
197
 
 
198
LexerModule lmPLM(SCLEX_PLM, ColourisePlmDoc, "PL/M", FoldPlmDoc, plmWordListDesc);