Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 205 lines (145 sloc) 5.183 kb
f858c4b2 »
2010-05-16 Import Scintilla 2.11
1 // Scintilla source code edit control
2 /** @file LexSorcus.cxx
3 ** Lexer for SORCUS installation files
4 ** Written by Eugen Bitter and Christoph Baumann at SORCUS Computer, Heidelberg Germany
5 ** Based on the ASM Lexer by The Black Horus
6 **/
7
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 <ctype.h>
13 #include <stdio.h>
14 #include <stdarg.h>
15
16 #include "Platform.h"
17
18 #include "PropSet.h"
19 #include "Accessor.h"
20 #include "StyleContext.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
30 //each character a..z and A..Z + '_' can be part of a keyword
31 //additionally numbers that follow 'M' can be contained in a keyword
32 static inline bool IsSWordStart(const int ch, const int prev_ch)
33 {
34 if (isalpha(ch) || (ch == '_') || ((isdigit(ch)) && (prev_ch == 'M')))
35 return true;
36
37 return false;
38 }
39
40
41 //only digits that are not preceded by 'M' count as a number
42 static inline bool IsSorcusNumber(const int ch, const int prev_ch)
43 {
44 if ((isdigit(ch)) && (prev_ch != 'M'))
45 return true;
46
47 return false;
48 }
49
50
51 //only = is a valid operator
52 static inline bool IsSorcusOperator(const int ch)
53 {
54 if (ch == '=')
55 return true;
56
57 return false;
58 }
59
60
61 static void ColouriseSorcusDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
62 Accessor &styler)
63 {
64
65 WordList &Command = *keywordlists[0];
66 WordList &Parameter = *keywordlists[1];
67 WordList &Constant = *keywordlists[2];
68
69 // Do not leak onto next line
70 if (initStyle == SCE_SORCUS_STRINGEOL)
71 initStyle = SCE_SORCUS_DEFAULT;
72
73 StyleContext sc(startPos, length, initStyle, styler);
74
75 for (; sc.More(); sc.Forward())
76 {
77
78 // Prevent SCE_SORCUS_STRINGEOL from leaking back to previous line
79 if (sc.atLineStart && (sc.state == SCE_SORCUS_STRING))
80 {
81 sc.SetState(SCE_SORCUS_STRING);
82 }
83
84 // Determine if the current state should terminate.
85 if (sc.state == SCE_SORCUS_OPERATOR)
86 {
87 if (!IsSorcusOperator(sc.ch))
88 {
89 sc.SetState(SCE_SORCUS_DEFAULT);
90 }
91 }
92 else if(sc.state == SCE_SORCUS_NUMBER)
93 {
94 if(!IsSorcusNumber(sc.ch, sc.chPrev))
95 {
96 sc.SetState(SCE_SORCUS_DEFAULT);
97 }
98 }
99 else if (sc.state == SCE_SORCUS_IDENTIFIER)
100 {
101 if (!IsSWordStart(sc.ch, sc.chPrev))
102 {
103 char s[100];
104
105 sc.GetCurrent(s, sizeof(s));
106
107 if (Command.InList(s))
108 {
109 sc.ChangeState(SCE_SORCUS_COMMAND);
110 }
111 else if (Parameter.InList(s))
112 {
113 sc.ChangeState(SCE_SORCUS_PARAMETER);
114 }
115 else if (Constant.InList(s))
116 {
117 sc.ChangeState(SCE_SORCUS_CONSTANT);
118 }
119
120 sc.SetState(SCE_SORCUS_DEFAULT);
121 }
122 }
123 else if (sc.state == SCE_SORCUS_COMMENTLINE )
124 {
125 if (sc.atLineEnd)
126 {
127 sc.SetState(SCE_SORCUS_DEFAULT);
128 }
129 }
130 else if (sc.state == SCE_SORCUS_STRING)
131 {
132 if (sc.ch == '\"')
133 {
134 sc.ForwardSetState(SCE_SORCUS_DEFAULT);
135 }
136 else if (sc.atLineEnd)
137 {
138 sc.ChangeState(SCE_SORCUS_STRINGEOL);
139 sc.ForwardSetState(SCE_SORCUS_DEFAULT);
140 }
141 }
142
143 // Determine if a new state should be entered.
144 if (sc.state == SCE_SORCUS_DEFAULT)
145 {
146 if ((sc.ch == ';') || (sc.ch == '\''))
147 {
148 sc.SetState(SCE_SORCUS_COMMENTLINE);
149 }
150 else if (IsSWordStart(sc.ch, sc.chPrev))
151 {
152 sc.SetState(SCE_SORCUS_IDENTIFIER);
153 }
154 else if (sc.ch == '\"')
155 {
156 sc.SetState(SCE_SORCUS_STRING);
157 }
158 else if (IsSorcusOperator(sc.ch))
159 {
160 sc.SetState(SCE_SORCUS_OPERATOR);
161 }
162 else if (IsSorcusNumber(sc.ch, sc.chPrev))
163 {
164 sc.SetState(SCE_SORCUS_NUMBER);
165 }
166 }
167
168 }
169 sc.Complete();
170 }
171
172
173 static const char* const SorcusWordListDesc[] = {"Command","Parameter", "Constant", 0};
174
175 LexerModule lmSorc(SCLEX_SORCUS, ColouriseSorcusDoc, "sorcins", 0, SorcusWordListDesc);
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
Something went wrong with that request. Please try again.