]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/lexers/LexKix.cxx
Don't document wxSortedArrayString as deriving from wxArrayString.
[wxWidgets.git] / src / stc / scintilla / lexers / LexKix.cxx
1 // Scintilla source code edit control
2 /** @file LexKix.cxx
3 ** Lexer for KIX-Scripts.
4 **/
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.
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 "ILexer.h"
16 #include "Scintilla.h"
17 #include "SciLexer.h"
18
19 #include "WordList.h"
20 #include "LexAccessor.h"
21 #include "Accessor.h"
22 #include "StyleContext.h"
23 #include "CharacterSet.h"
24 #include "LexerModule.h"
25
26 #ifdef SCI_NAMESPACE
27 using namespace Scintilla;
28 #endif
29
30 // Extended to accept accented characters
31 static inline bool IsAWordChar(int ch) {
32 return ch >= 0x80 || isalnum(ch) || ch == '_';
33 }
34
35 static inline bool IsOperator(const int ch) {
36 return (ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '&' || ch == '|' || ch == '<' || ch == '>' || ch == '=');
37 }
38
39 static void ColouriseKixDoc(unsigned int startPos, int length, int initStyle,
40 WordList *keywordlists[], Accessor &styler) {
41
42 WordList &keywords = *keywordlists[0];
43 WordList &keywords2 = *keywordlists[1];
44 WordList &keywords3 = *keywordlists[2];
45 // WordList &keywords4 = *keywordlists[3];
46
47 styler.StartAt(startPos);
48
49 StyleContext sc(startPos, length, initStyle, styler);
50
51 for (; sc.More(); sc.Forward()) {
52
53 if (sc.state == SCE_KIX_COMMENT) {
54 if (sc.atLineEnd) {
55 sc.SetState(SCE_KIX_DEFAULT);
56 }
57 } else if (sc.state == SCE_KIX_STRING1) {
58 // This is a doubles quotes string
59 if (sc.ch == '\"') {
60 sc.ForwardSetState(SCE_KIX_DEFAULT);
61 }
62 } else if (sc.state == SCE_KIX_STRING2) {
63 // This is a single quote string
64 if (sc.ch == '\'') {
65 sc.ForwardSetState(SCE_KIX_DEFAULT);
66 }
67 } else if (sc.state == SCE_KIX_NUMBER) {
68 if (!IsADigit(sc.ch)) {
69 sc.SetState(SCE_KIX_DEFAULT);
70 }
71 } else if (sc.state == SCE_KIX_VAR) {
72 if (!IsAWordChar(sc.ch)) {
73 sc.SetState(SCE_KIX_DEFAULT);
74 }
75 } else if (sc.state == SCE_KIX_MACRO) {
76 if (!IsAWordChar(sc.ch) && !IsADigit(sc.ch)) {
77 char s[100];
78 sc.GetCurrentLowered(s, sizeof(s));
79
80 if (!keywords3.InList(&s[1])) {
81 sc.ChangeState(SCE_KIX_DEFAULT);
82 }
83 sc.SetState(SCE_KIX_DEFAULT);
84 }
85 } else if (sc.state == SCE_KIX_OPERATOR) {
86 if (!IsOperator(sc.ch)) {
87 sc.SetState(SCE_KIX_DEFAULT);
88 }
89 } else if (sc.state == SCE_KIX_IDENTIFIER) {
90 if (!IsAWordChar(sc.ch)) {
91 char s[100];
92 sc.GetCurrentLowered(s, sizeof(s));
93
94 if (keywords.InList(s)) {
95 sc.ChangeState(SCE_KIX_KEYWORD);
96 } else if (keywords2.InList(s)) {
97 sc.ChangeState(SCE_KIX_FUNCTIONS);
98 }
99 sc.SetState(SCE_KIX_DEFAULT);
100 }
101 }
102
103 // Determine if a new state should be entered.
104 if (sc.state == SCE_KIX_DEFAULT) {
105 if (sc.ch == ';') {
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);
121 }
122 }
123 }
124 sc.Complete();
125 }
126
127
128 LexerModule lmKix(SCLEX_KIX, ColouriseKixDoc, "kix");
129