]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexSorcus.cxx
1d8ba277a2dabb04ab85b7177f76d083d4e197a4
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.
20 #include "StyleContext.h"
22 #include "Scintilla.h"
26 using namespace Scintilla
;
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
)
34 if (isalpha(ch
) || (ch
== '_') || ((isdigit(ch
)) && (prev_ch
== 'M')))
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
)
44 if ((isdigit(ch
)) && (prev_ch
!= 'M'))
51 //only = is a valid operator
52 static inline bool IsSorcusOperator(const int ch
)
61 static void ColouriseSorcusDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
65 WordList
&Command
= *keywordlists
[0];
66 WordList
&Parameter
= *keywordlists
[1];
67 WordList
&Constant
= *keywordlists
[2];
69 // Do not leak onto next line
70 if (initStyle
== SCE_SORCUS_STRINGEOL
)
71 initStyle
= SCE_SORCUS_DEFAULT
;
73 StyleContext
sc(startPos
, length
, initStyle
, styler
);
75 for (; sc
.More(); sc
.Forward())
78 // Prevent SCE_SORCUS_STRINGEOL from leaking back to previous line
79 if (sc
.atLineStart
&& (sc
.state
== SCE_SORCUS_STRING
))
81 sc
.SetState(SCE_SORCUS_STRING
);
84 // Determine if the current state should terminate.
85 if (sc
.state
== SCE_SORCUS_OPERATOR
)
87 if (!IsSorcusOperator(sc
.ch
))
89 sc
.SetState(SCE_SORCUS_DEFAULT
);
92 else if(sc
.state
== SCE_SORCUS_NUMBER
)
94 if(!IsSorcusNumber(sc
.ch
, sc
.chPrev
))
96 sc
.SetState(SCE_SORCUS_DEFAULT
);
99 else if (sc
.state
== SCE_SORCUS_IDENTIFIER
)
101 if (!IsSWordStart(sc
.ch
, sc
.chPrev
))
105 sc
.GetCurrent(s
, sizeof(s
));
107 if (Command
.InList(s
))
109 sc
.ChangeState(SCE_SORCUS_COMMAND
);
111 else if (Parameter
.InList(s
))
113 sc
.ChangeState(SCE_SORCUS_PARAMETER
);
115 else if (Constant
.InList(s
))
117 sc
.ChangeState(SCE_SORCUS_CONSTANT
);
120 sc
.SetState(SCE_SORCUS_DEFAULT
);
123 else if (sc
.state
== SCE_SORCUS_COMMENTLINE
)
127 sc
.SetState(SCE_SORCUS_DEFAULT
);
130 else if (sc
.state
== SCE_SORCUS_STRING
)
134 sc
.ForwardSetState(SCE_SORCUS_DEFAULT
);
136 else if (sc
.atLineEnd
)
138 sc
.ChangeState(SCE_SORCUS_STRINGEOL
);
139 sc
.ForwardSetState(SCE_SORCUS_DEFAULT
);
143 // Determine if a new state should be entered.
144 if (sc
.state
== SCE_SORCUS_DEFAULT
)
146 if ((sc
.ch
== ';') || (sc
.ch
== '\''))
148 sc
.SetState(SCE_SORCUS_COMMENTLINE
);
150 else if (IsSWordStart(sc
.ch
, sc
.chPrev
))
152 sc
.SetState(SCE_SORCUS_IDENTIFIER
);
154 else if (sc
.ch
== '\"')
156 sc
.SetState(SCE_SORCUS_STRING
);
158 else if (IsSorcusOperator(sc
.ch
))
160 sc
.SetState(SCE_SORCUS_OPERATOR
);
162 else if (IsSorcusNumber(sc
.ch
, sc
.chPrev
))
164 sc
.SetState(SCE_SORCUS_NUMBER
);
173 static const char* const SorcusWordListDesc
[] = {"Command","Parameter", "Constant", 0};
175 LexerModule
lmSorc(SCLEX_SORCUS
, ColouriseSorcusDoc
, "sorcins", 0, SorcusWordListDesc
);