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 <ctype.h>
11 #include <stdio.h>
12 #include <stdarg.h>
13
14 #include "Platform.h"
15
16 #include "PropSet.h"
17 #include "Accessor.h"
18 #include "StyleContext.h"
19 #include "KeyWords.h"
20 #include "Scintilla.h"
21 #include "SciLexer.h"
22
23 // Extended to accept accented characters
IsAWordChar(int ch)24 static inline bool IsAWordChar(int ch) {
25 return ch >= 0x80 || isalnum(ch) || ch == '_';
26 }
27
IsOperator(const int ch)28 static inline bool IsOperator(const int ch) {
29 return (ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '&' || ch == '|' || ch == '<' || ch == '>' || ch == '=');
30 }
31
ColouriseKixDoc(unsigned int startPos,int length,int initStyle,WordList * keywordlists[],Accessor & styler)32 static void ColouriseKixDoc(unsigned int startPos, int length, int initStyle,
33 WordList *keywordlists[], Accessor &styler) {
34
35 WordList &keywords = *keywordlists[0];
36 WordList &keywords2 = *keywordlists[1];
37 WordList &keywords3 = *keywordlists[2];
38 // WordList &keywords4 = *keywordlists[3];
39
40 styler.StartAt(startPos);
41
42 StyleContext sc(startPos, length, initStyle, styler);
43
44 for (; sc.More(); sc.Forward()) {
45
46 if (sc.state == SCE_KIX_COMMENT) {
47 if (sc.atLineEnd) {
48 sc.SetState(SCE_KIX_DEFAULT);
49 }
50 } else if (sc.state == SCE_KIX_STRING1) {
51 // This is a doubles quotes string
52 if (sc.ch == '\"') {
53 sc.ForwardSetState(SCE_KIX_DEFAULT);
54 }
55 } else if (sc.state == SCE_KIX_STRING2) {
56 // This is a single quote string
57 if (sc.ch == '\'') {
58 sc.ForwardSetState(SCE_KIX_DEFAULT);
59 }
60 } else if (sc.state == SCE_KIX_NUMBER) {
61 if (!IsADigit(sc.ch)) {
62 sc.SetState(SCE_KIX_DEFAULT);
63 }
64 } else if (sc.state == SCE_KIX_VAR) {
65 if (!IsAWordChar(sc.ch)) {
66 sc.SetState(SCE_KIX_DEFAULT);
67 }
68 } else if (sc.state == SCE_KIX_MACRO) {
69 if (!IsAWordChar(sc.ch) && !IsADigit(sc.ch)) {
70 char s[100];
71 sc.GetCurrentLowered(s, sizeof(s));
72
73 if (!keywords3.InList(&s[1])) {
74 sc.ChangeState(SCE_KIX_DEFAULT);
75 }
76 sc.SetState(SCE_KIX_DEFAULT);
77 }
78 } else if (sc.state == SCE_KIX_OPERATOR) {
79 if (!IsOperator(sc.ch)) {
80 sc.SetState(SCE_KIX_DEFAULT);
81 }
82 } else if (sc.state == SCE_KIX_IDENTIFIER) {
83 if (!IsAWordChar(sc.ch)) {
84 char s[100];
85 sc.GetCurrentLowered(s, sizeof(s));
86
87 if (keywords.InList(s)) {
88 sc.ChangeState(SCE_KIX_KEYWORD);
89 } else if (keywords2.InList(s)) {
90 sc.ChangeState(SCE_KIX_FUNCTIONS);
91 }
92 sc.SetState(SCE_KIX_DEFAULT);
93 }
94 }
95
96 // Determine if a new state should be entered.
97 if (sc.state == SCE_KIX_DEFAULT) {
98 if (sc.ch == ';') {
99 sc.SetState(SCE_KIX_COMMENT);
100 } else if (sc.ch == '\"') {
101 sc.SetState(SCE_KIX_STRING1);
102 } else if (sc.ch == '\'') {
103 sc.SetState(SCE_KIX_STRING2);
104 } else if (sc.ch == '$') {
105 sc.SetState(SCE_KIX_VAR);
106 } else if (sc.ch == '@') {
107 sc.SetState(SCE_KIX_MACRO);
108 } else if (IsADigit(sc.ch) || ((sc.ch == '.' || sc.ch == '&') && IsADigit(sc.chNext))) {
109 sc.SetState(SCE_KIX_NUMBER);
110 } else if (IsOperator(sc.ch)) {
111 sc.SetState(SCE_KIX_OPERATOR);
112 } else if (IsAWordChar(sc.ch)) {
113 sc.SetState(SCE_KIX_IDENTIFIER);
114 }
115 }
116 }
117 sc.Complete();
118 }
119
120
121 LexerModule lmKix(SCLEX_KIX, ColouriseKixDoc, "kix");
122
123