]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/lexers/LexSorcus.cxx
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
8 // The License.txt file describes the conditions under which this software may be distributed.
18 #include "Scintilla.h"
22 #include "LexAccessor.h"
24 #include "StyleContext.h"
25 #include "CharacterSet.h"
26 #include "LexerModule.h"
29 using namespace Scintilla
;
33 //each character a..z and A..Z + '_' can be part of a keyword
34 //additionally numbers that follow 'M' can be contained in a keyword
35 static inline bool IsSWordStart(const int ch
, const int prev_ch
)
37 if (isalpha(ch
) || (ch
== '_') || ((isdigit(ch
)) && (prev_ch
== 'M')))
44 //only digits that are not preceded by 'M' count as a number
45 static inline bool IsSorcusNumber(const int ch
, const int prev_ch
)
47 if ((isdigit(ch
)) && (prev_ch
!= 'M'))
54 //only = is a valid operator
55 static inline bool IsSorcusOperator(const int ch
)
64 static void ColouriseSorcusDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
68 WordList
&Command
= *keywordlists
[0];
69 WordList
&Parameter
= *keywordlists
[1];
70 WordList
&Constant
= *keywordlists
[2];
72 // Do not leak onto next line
73 if (initStyle
== SCE_SORCUS_STRINGEOL
)
74 initStyle
= SCE_SORCUS_DEFAULT
;
76 StyleContext
sc(startPos
, length
, initStyle
, styler
);
78 for (; sc
.More(); sc
.Forward())
81 // Prevent SCE_SORCUS_STRINGEOL from leaking back to previous line
82 if (sc
.atLineStart
&& (sc
.state
== SCE_SORCUS_STRING
))
84 sc
.SetState(SCE_SORCUS_STRING
);
87 // Determine if the current state should terminate.
88 if (sc
.state
== SCE_SORCUS_OPERATOR
)
90 if (!IsSorcusOperator(sc
.ch
))
92 sc
.SetState(SCE_SORCUS_DEFAULT
);
95 else if(sc
.state
== SCE_SORCUS_NUMBER
)
97 if(!IsSorcusNumber(sc
.ch
, sc
.chPrev
))
99 sc
.SetState(SCE_SORCUS_DEFAULT
);
102 else if (sc
.state
== SCE_SORCUS_IDENTIFIER
)
104 if (!IsSWordStart(sc
.ch
, sc
.chPrev
))
108 sc
.GetCurrent(s
, sizeof(s
));
110 if (Command
.InList(s
))
112 sc
.ChangeState(SCE_SORCUS_COMMAND
);
114 else if (Parameter
.InList(s
))
116 sc
.ChangeState(SCE_SORCUS_PARAMETER
);
118 else if (Constant
.InList(s
))
120 sc
.ChangeState(SCE_SORCUS_CONSTANT
);
123 sc
.SetState(SCE_SORCUS_DEFAULT
);
126 else if (sc
.state
== SCE_SORCUS_COMMENTLINE
)
130 sc
.SetState(SCE_SORCUS_DEFAULT
);
133 else if (sc
.state
== SCE_SORCUS_STRING
)
137 sc
.ForwardSetState(SCE_SORCUS_DEFAULT
);
139 else if (sc
.atLineEnd
)
141 sc
.ChangeState(SCE_SORCUS_STRINGEOL
);
142 sc
.ForwardSetState(SCE_SORCUS_DEFAULT
);
146 // Determine if a new state should be entered.
147 if (sc
.state
== SCE_SORCUS_DEFAULT
)
149 if ((sc
.ch
== ';') || (sc
.ch
== '\''))
151 sc
.SetState(SCE_SORCUS_COMMENTLINE
);
153 else if (IsSWordStart(sc
.ch
, sc
.chPrev
))
155 sc
.SetState(SCE_SORCUS_IDENTIFIER
);
157 else if (sc
.ch
== '\"')
159 sc
.SetState(SCE_SORCUS_STRING
);
161 else if (IsSorcusOperator(sc
.ch
))
163 sc
.SetState(SCE_SORCUS_OPERATOR
);
165 else if (IsSorcusNumber(sc
.ch
, sc
.chPrev
))
167 sc
.SetState(SCE_SORCUS_NUMBER
);
176 static const char* const SorcusWordListDesc
[] = {"Command","Parameter", "Constant", 0};
178 LexerModule
lmSorc(SCLEX_SORCUS
, ColouriseSorcusDoc
, "sorcins", 0, SorcusWordListDesc
);