~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/sdk/wxscintilla/src/scintilla/lexers/LexSpice.cxx

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Scintilla source code edit control
 
2
/** @file LexSpice.cxx
 
3
 ** Lexer for Spice
 
4
 **/
 
5
// Copyright 2006 by Fabien Proriol
 
6
// The License.txt file describes the conditions under which this software may be distributed.
 
7
 
 
8
#include <stdlib.h>
 
9
#include <string.h>
 
10
#include <stdio.h>
 
11
#include <stdarg.h>
 
12
#include <assert.h>
 
13
#include <ctype.h>
 
14
 
 
15
#include <string>
 
16
 
 
17
#include "ILexer.h"
 
18
#include "Scintilla.h"
 
19
#include "SciLexer.h"
 
20
 
 
21
#include "WordList.h"
 
22
#include "LexAccessor.h"
 
23
#include "Accessor.h"
 
24
#include "StyleContext.h"
 
25
#include "CharacterSet.h"
 
26
#include "LexerModule.h"
 
27
 
 
28
#ifdef SCI_NAMESPACE
 
29
using namespace Scintilla;
 
30
#endif
 
31
 
 
32
/*
 
33
 * Interface
 
34
 */
 
35
 
 
36
static void ColouriseDocument(
 
37
    unsigned int startPos,
 
38
    int length,
 
39
    int initStyle,
 
40
    WordList *keywordlists[],
 
41
    Accessor &styler);
 
42
 
 
43
static const char * const spiceWordListDesc[] = {
 
44
    "Keywords",        // SPICE command
 
45
    "Keywords2",    // SPICE functions
 
46
    "Keywords3",    // SPICE params
 
47
    0
 
48
};
 
49
 
 
50
LexerModule lmSpice(SCLEX_SPICE, ColouriseDocument, "spice", NULL, spiceWordListDesc);
 
51
 
 
52
/*
 
53
 * Implementation
 
54
 */
 
55
 
 
56
static void ColouriseComment(StyleContext& sc, bool& apostropheStartsAttribute);
 
57
static void ColouriseDelimiter(StyleContext& sc, bool& apostropheStartsAttribute);
 
58
static void ColouriseNumber(StyleContext& sc, bool& apostropheStartsAttribute);
 
59
static void ColouriseWhiteSpace(StyleContext& sc, bool& apostropheStartsAttribute);
 
60
static void ColouriseWord(StyleContext& sc, WordList& keywords, WordList& keywords2, WordList& keywords3, bool& apostropheStartsAttribute);
 
61
 
 
62
static inline bool IsDelimiterCharacter(int ch);
 
63
static inline bool IsSeparatorOrDelimiterCharacter(int ch);
 
64
 
 
65
static void ColouriseComment(StyleContext& sc, bool&) {
 
66
    sc.SetState(SCE_SPICE_COMMENTLINE);
 
67
    while (!sc.atLineEnd) {
 
68
        sc.Forward();
 
69
    }
 
70
}
 
71
 
 
72
static void ColouriseDelimiter(StyleContext& sc, bool& apostropheStartsAttribute) {
 
73
    apostropheStartsAttribute = sc.Match (')');
 
74
    sc.SetState(SCE_SPICE_DELIMITER);
 
75
    sc.ForwardSetState(SCE_SPICE_DEFAULT);
 
76
}
 
77
 
 
78
static void ColouriseNumber(StyleContext& sc, bool& apostropheStartsAttribute) {
 
79
    apostropheStartsAttribute = true;
 
80
    std::string number;
 
81
    sc.SetState(SCE_SPICE_NUMBER);
 
82
    // Get all characters up to a delimiter or a separator, including points, but excluding
 
83
    // double points (ranges).
 
84
    while (!IsSeparatorOrDelimiterCharacter(sc.ch) || (sc.ch == '.' && sc.chNext != '.')) {
 
85
        number += static_cast<char>(sc.ch);
 
86
        sc.Forward();
 
87
    }
 
88
    // Special case: exponent with sign
 
89
    if ((sc.chPrev == 'e' || sc.chPrev == 'E') &&
 
90
            (sc.ch == '+' || sc.ch == '-')) {
 
91
        number += static_cast<char>(sc.ch);
 
92
        sc.Forward ();
 
93
        while (!IsSeparatorOrDelimiterCharacter(sc.ch)) {
 
94
            number += static_cast<char>(sc.ch);
 
95
            sc.Forward();
 
96
        }
 
97
    }
 
98
    sc.SetState(SCE_SPICE_DEFAULT);
 
99
}
 
100
 
 
101
static void ColouriseWhiteSpace(StyleContext& sc, bool& ) {
 
102
    sc.SetState(SCE_SPICE_DEFAULT);
 
103
    sc.ForwardSetState(SCE_SPICE_DEFAULT);
 
104
}
 
105
 
 
106
static void ColouriseWord(StyleContext& sc, WordList& keywords, WordList& keywords2, WordList& keywords3, bool& apostropheStartsAttribute) {
 
107
    apostropheStartsAttribute = true;
 
108
    sc.SetState(SCE_SPICE_IDENTIFIER);
 
109
    std::string word;
 
110
    while (!sc.atLineEnd && !IsSeparatorOrDelimiterCharacter(sc.ch)) {
 
111
        word += static_cast<char>(tolower(sc.ch));
 
112
        sc.Forward();
 
113
    }
 
114
    if (keywords.InList(word.c_str())) {
 
115
        sc.ChangeState(SCE_SPICE_KEYWORD);
 
116
        if (word != "all") {
 
117
            apostropheStartsAttribute = false;
 
118
        }
 
119
    }
 
120
    else if (keywords2.InList(word.c_str())) {
 
121
        sc.ChangeState(SCE_SPICE_KEYWORD2);
 
122
        if (word != "all") {
 
123
            apostropheStartsAttribute = false;
 
124
        }
 
125
    }
 
126
    else if (keywords3.InList(word.c_str())) {
 
127
        sc.ChangeState(SCE_SPICE_KEYWORD3);
 
128
        if (word != "all") {
 
129
            apostropheStartsAttribute = false;
 
130
        }
 
131
    }
 
132
    sc.SetState(SCE_SPICE_DEFAULT);
 
133
}
 
134
 
 
135
//
 
136
// ColouriseDocument
 
137
//
 
138
static void ColouriseDocument(
 
139
    unsigned int startPos,
 
140
    int length,
 
141
    int initStyle,
 
142
    WordList *keywordlists[],
 
143
    Accessor &styler) {
 
144
    WordList &keywords = *keywordlists[0];
 
145
    WordList &keywords2 = *keywordlists[1];
 
146
    WordList &keywords3 = *keywordlists[2];
 
147
    StyleContext sc(startPos, length, initStyle, styler);
 
148
    int lineCurrent = styler.GetLine(startPos);
 
149
    bool apostropheStartsAttribute = (styler.GetLineState(lineCurrent) & 1) != 0;
 
150
    while (sc.More()) {
 
151
        if (sc.atLineEnd) {
 
152
            // Go to the next line
 
153
            sc.Forward();
 
154
            lineCurrent++;
 
155
            // Remember the line state for future incremental lexing
 
156
            styler.SetLineState(lineCurrent, apostropheStartsAttribute);
 
157
            // Don't continue any styles on the next line
 
158
            sc.SetState(SCE_SPICE_DEFAULT);
 
159
        }
 
160
        // Comments
 
161
        if ((sc.Match('*') && sc.atLineStart) || sc.Match('*','~')) {
 
162
            ColouriseComment(sc, apostropheStartsAttribute);
 
163
        // Whitespace
 
164
        } else if (IsASpace(sc.ch)) {
 
165
            ColouriseWhiteSpace(sc, apostropheStartsAttribute);
 
166
        // Delimiters
 
167
        } else if (IsDelimiterCharacter(sc.ch)) {
 
168
            ColouriseDelimiter(sc, apostropheStartsAttribute);
 
169
        // Numbers
 
170
        } else if (IsADigit(sc.ch) || sc.ch == '#') {
 
171
            ColouriseNumber(sc, apostropheStartsAttribute);
 
172
        // Keywords or identifiers
 
173
        } else {
 
174
            ColouriseWord(sc, keywords, keywords2, keywords3, apostropheStartsAttribute);
 
175
        }
 
176
    }
 
177
    sc.Complete();
 
178
}
 
179
 
 
180
static inline bool IsDelimiterCharacter(int ch) {
 
181
    switch (ch) {
 
182
    case '&':
 
183
    case '\'':
 
184
    case '(':
 
185
    case ')':
 
186
    case '*':
 
187
    case '+':
 
188
    case ',':
 
189
    case '-':
 
190
    case '.':
 
191
    case '/':
 
192
    case ':':
 
193
    case ';':
 
194
    case '<':
 
195
    case '=':
 
196
    case '>':
 
197
    case '|':
 
198
        return true;
 
199
    default:
 
200
        return false;
 
201
    }
 
202
}
 
203
 
 
204
static inline bool IsSeparatorOrDelimiterCharacter(int ch) {
 
205
    return IsASpace(ch) || IsDelimiterCharacter(ch);
 
206
}