]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/lexers/LexKix.cxx
1 // Scintilla source code edit control
3 ** Lexer for KIX-Scripts.
5 // Copyright 2004 by Manfred Becker <manfred@becker-trdf.de>
6 // The License.txt file describes the conditions under which this software may be distributed.
16 #include "Scintilla.h"
20 #include "LexAccessor.h"
22 #include "StyleContext.h"
23 #include "CharacterSet.h"
24 #include "LexerModule.h"
27 using namespace Scintilla
;
30 // Extended to accept accented characters
31 static inline bool IsAWordChar(int ch
) {
32 return ch
>= 0x80 || isalnum(ch
) || ch
== '_';
35 static inline bool IsOperator(const int ch
) {
36 return (ch
== '+' || ch
== '-' || ch
== '*' || ch
== '/' || ch
== '&' || ch
== '|' || ch
== '<' || ch
== '>' || ch
== '=');
39 static void ColouriseKixDoc(unsigned int startPos
, int length
, int initStyle
,
40 WordList
*keywordlists
[], Accessor
&styler
) {
42 WordList
&keywords
= *keywordlists
[0];
43 WordList
&keywords2
= *keywordlists
[1];
44 WordList
&keywords3
= *keywordlists
[2];
45 // WordList &keywords4 = *keywordlists[3];
47 styler
.StartAt(startPos
);
49 StyleContext
sc(startPos
, length
, initStyle
, styler
);
51 for (; sc
.More(); sc
.Forward()) {
53 if (sc
.state
== SCE_KIX_COMMENT
) {
55 sc
.SetState(SCE_KIX_DEFAULT
);
57 } else if (sc
.state
== SCE_KIX_STRING1
) {
58 // This is a doubles quotes string
60 sc
.ForwardSetState(SCE_KIX_DEFAULT
);
62 } else if (sc
.state
== SCE_KIX_STRING2
) {
63 // This is a single quote string
65 sc
.ForwardSetState(SCE_KIX_DEFAULT
);
67 } else if (sc
.state
== SCE_KIX_NUMBER
) {
68 if (!IsADigit(sc
.ch
)) {
69 sc
.SetState(SCE_KIX_DEFAULT
);
71 } else if (sc
.state
== SCE_KIX_VAR
) {
72 if (!IsAWordChar(sc
.ch
)) {
73 sc
.SetState(SCE_KIX_DEFAULT
);
75 } else if (sc
.state
== SCE_KIX_MACRO
) {
76 if (!IsAWordChar(sc
.ch
) && !IsADigit(sc
.ch
)) {
78 sc
.GetCurrentLowered(s
, sizeof(s
));
80 if (!keywords3
.InList(&s
[1])) {
81 sc
.ChangeState(SCE_KIX_DEFAULT
);
83 sc
.SetState(SCE_KIX_DEFAULT
);
85 } else if (sc
.state
== SCE_KIX_OPERATOR
) {
86 if (!IsOperator(sc
.ch
)) {
87 sc
.SetState(SCE_KIX_DEFAULT
);
89 } else if (sc
.state
== SCE_KIX_IDENTIFIER
) {
90 if (!IsAWordChar(sc
.ch
)) {
92 sc
.GetCurrentLowered(s
, sizeof(s
));
94 if (keywords
.InList(s
)) {
95 sc
.ChangeState(SCE_KIX_KEYWORD
);
96 } else if (keywords2
.InList(s
)) {
97 sc
.ChangeState(SCE_KIX_FUNCTIONS
);
99 sc
.SetState(SCE_KIX_DEFAULT
);
103 // Determine if a new state should be entered.
104 if (sc
.state
== SCE_KIX_DEFAULT
) {
106 sc
.SetState(SCE_KIX_COMMENT
);
107 } else if (sc
.ch
== '\"') {
108 sc
.SetState(SCE_KIX_STRING1
);
109 } else if (sc
.ch
== '\'') {
110 sc
.SetState(SCE_KIX_STRING2
);
111 } else if (sc
.ch
== '$') {
112 sc
.SetState(SCE_KIX_VAR
);
113 } else if (sc
.ch
== '@') {
114 sc
.SetState(SCE_KIX_MACRO
);
115 } else if (IsADigit(sc
.ch
) || ((sc
.ch
== '.' || sc
.ch
== '&') && IsADigit(sc
.chNext
))) {
116 sc
.SetState(SCE_KIX_NUMBER
);
117 } else if (IsOperator(sc
.ch
)) {
118 sc
.SetState(SCE_KIX_OPERATOR
);
119 } else if (IsAWordChar(sc
.ch
)) {
120 sc
.SetState(SCE_KIX_IDENTIFIER
);
128 LexerModule
lmKix(SCLEX_KIX
, ColouriseKixDoc
, "kix");