Menu

[r1152]: / trunk / ext / scintilla / lexers / LexKix.cxx  Maximize  Restore  History

Download this file

137 lines (118 with data), 3.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Scintilla source code edit control
/** @file LexKix.cxx
** Lexer for KIX-Scripts.
**/
// Copyright 2004 by Manfred Becker <manfred@becker-trdf.de>
// The License.txt file describes the conditions under which this software may be distributed.
// Edited by Lee Wilmott (24-Jun-2014) added support for block comments
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>
#include <ctype.h>
#include "ILexer.h"
#include "Scintilla.h"
#include "SciLexer.h"
#include "WordList.h"
#include "LexAccessor.h"
#include "Accessor.h"
#include "StyleContext.h"
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
// Extended to accept accented characters
static inline bool IsAWordChar(int ch) {
return ch >= 0x80 || isalnum(ch) || ch == '_';
}
static inline bool IsOperator(const int ch) {
return (ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '&' || ch == '|' || ch == '<' || ch == '>' || ch == '=');
}
static void ColouriseKixDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
WordList *keywordlists[], Accessor &styler) {
WordList &keywords = *keywordlists[0];
WordList &keywords2 = *keywordlists[1];
WordList &keywords3 = *keywordlists[2];
// WordList &keywords4 = *keywordlists[3];
styler.StartAt(startPos);
StyleContext sc(startPos, length, initStyle, styler);
for (; sc.More(); sc.Forward()) {
if (sc.state == SCE_KIX_COMMENT) {
if (sc.atLineEnd) {
sc.SetState(SCE_KIX_DEFAULT);
}
} else if (sc.state == SCE_KIX_COMMENTSTREAM) {
if (sc.ch == '/' && sc.chPrev == '*') {
sc.ForwardSetState(SCE_KIX_DEFAULT);
}
} else if (sc.state == SCE_KIX_STRING1) {
// This is a doubles quotes string
if (sc.ch == '\"') {
sc.ForwardSetState(SCE_KIX_DEFAULT);
}
} else if (sc.state == SCE_KIX_STRING2) {
// This is a single quote string
if (sc.ch == '\'') {
sc.ForwardSetState(SCE_KIX_DEFAULT);
}
} else if (sc.state == SCE_KIX_NUMBER) {
if (!IsADigit(sc.ch)) {
sc.SetState(SCE_KIX_DEFAULT);
}
} else if (sc.state == SCE_KIX_VAR) {
if (!IsAWordChar(sc.ch)) {
sc.SetState(SCE_KIX_DEFAULT);
}
} else if (sc.state == SCE_KIX_MACRO) {
if (!IsAWordChar(sc.ch) && !IsADigit(sc.ch)) {
char s[100];
sc.GetCurrentLowered(s, sizeof(s));
if (!keywords3.InList(&s[1])) {
sc.ChangeState(SCE_KIX_DEFAULT);
}
sc.SetState(SCE_KIX_DEFAULT);
}
} else if (sc.state == SCE_KIX_OPERATOR) {
if (!IsOperator(sc.ch)) {
sc.SetState(SCE_KIX_DEFAULT);
}
} else if (sc.state == SCE_KIX_IDENTIFIER) {
if (!IsAWordChar(sc.ch)) {
char s[100];
sc.GetCurrentLowered(s, sizeof(s));
if (keywords.InList(s)) {
sc.ChangeState(SCE_KIX_KEYWORD);
} else if (keywords2.InList(s)) {
sc.ChangeState(SCE_KIX_FUNCTIONS);
}
sc.SetState(SCE_KIX_DEFAULT);
}
}
// Determine if a new state should be entered.
if (sc.state == SCE_KIX_DEFAULT) {
if (sc.ch == ';') {
sc.SetState(SCE_KIX_COMMENT);
} else if (sc.ch == '/' && sc.chNext == '*') {
sc.SetState(SCE_KIX_COMMENTSTREAM);
} else if (sc.ch == '\"') {
sc.SetState(SCE_KIX_STRING1);
} else if (sc.ch == '\'') {
sc.SetState(SCE_KIX_STRING2);
} else if (sc.ch == '$') {
sc.SetState(SCE_KIX_VAR);
} else if (sc.ch == '@') {
sc.SetState(SCE_KIX_MACRO);
} else if (IsADigit(sc.ch) || ((sc.ch == '.' || sc.ch == '&') && IsADigit(sc.chNext))) {
sc.SetState(SCE_KIX_NUMBER);
} else if (IsOperator(sc.ch)) {
sc.SetState(SCE_KIX_OPERATOR);
} else if (IsAWordChar(sc.ch)) {
sc.SetState(SCE_KIX_IDENTIFIER);
}
}
}
sc.Complete();
}
LexerModule lmKix(SCLEX_KIX, ColouriseKixDoc, "kix");
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.