Menu

[r170]: / trunk / ext / scintilla / src / LexKix.cxx  Maximize  Restore  History

Download this file

123 lines (105 with data), 3.5 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
// 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.
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <stdarg.h>
#include "Platform.h"
#include "PropSet.h"
#include "Accessor.h"
#include "StyleContext.h"
#include "KeyWords.h"
#include "Scintilla.h"
#include "SciLexer.h"
// 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(unsigned int startPos, int 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_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.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.