updated Scintilla to 2.29
[TortoiseGit.git] / ext / scintilla / lexers / LexKix.cxx
blob2891f68a1813f9914a4a691551d0122bdaff1bf8
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.
8 #include <stdlib.h>
9 #include <string.h>
10 #include <stdio.h>
11 #include <stdarg.h>
12 #include <assert.h>
13 #include <ctype.h>
15 #include "ILexer.h"
16 #include "Scintilla.h"
17 #include "SciLexer.h"
19 #include "WordList.h"
20 #include "LexAccessor.h"
21 #include "Accessor.h"
22 #include "StyleContext.h"
23 #include "CharacterSet.h"
24 #include "LexerModule.h"
26 #ifdef SCI_NAMESPACE
27 using namespace Scintilla;
28 #endif
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) {
54 if (sc.atLineEnd) {
55 sc.SetState(SCE_KIX_DEFAULT);
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);
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);
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)) {
77 char s[100];
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)) {
91 char s[100];
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) {
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);
124 sc.Complete();
128 LexerModule lmKix(SCLEX_KIX, ColouriseKixDoc, "kix");