aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <unknown>2011-02-04 13:07:55 +1100
committernyamatongwe <unknown>2011-02-04 13:07:55 +1100
commit0655cc14611e4eae66cf2e6da6e69f8b1010dc0b (patch)
treea3140fe4310f6a8f4932cb805978618840db35ae
parente97ca54833213a1c71077d97d586d2e67254a1ae (diff)
downloadscintilla-mirror-0655cc14611e4eae66cf2e6da6e69f8b1010dc0b.tar.gz
Converted to lexer objects.
-rw-r--r--lexers/LexAsm.cxx146
-rw-r--r--lexers/LexBasic.cxx314
2 files changed, 329 insertions, 131 deletions
diff --git a/lexers/LexAsm.cxx b/lexers/LexAsm.cxx
index 3977bc3a9..b00420945 100644
--- a/lexers/LexAsm.cxx
+++ b/lexers/LexAsm.cxx
@@ -4,16 +4,24 @@
** Written by The Black Horus
** Enhancements and NASM stuff by Kein-Hong Man, 2003-10
** SCE_ASM_COMMENTBLOCK and SCE_ASM_CHARACTER are for future GNU as colouring
+ ** Converted to lexer object by "Udo Lechner" <dlchnr(at)gmx(dot)net>
**/
// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
// 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 <assert.h>
-#include <ctype.h>
+
+#ifdef _MSC_VER
+#pragma warning(disable: 4786)
+#endif
+
+#include <string>
+#include <map>
#include "ILexer.h"
#include "Scintilla.h"
@@ -25,6 +33,7 @@
#include "StyleContext.h"
#include "CharacterSet.h"
#include "LexerModule.h"
+#include "OptionSet.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
@@ -53,15 +62,119 @@ static inline bool IsAsmOperator(const int ch) {
return false;
}
-static void ColouriseAsmDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
- Accessor &styler) {
+// An individual named option for use in an OptionSet
+
+// Options used for LexerAsm
+struct OptionsAsm {
+ OptionsAsm() {
+ }
+};
+
+static const char * const asmWordListDesc[] = {
+ "CPU instructions",
+ "FPU instructions",
+ "Registers",
+ "Directives",
+ "Directive operands",
+ "Extended instructions",
+ 0
+};
+
+struct OptionSetAsm : public OptionSet<OptionsAsm> {
+ OptionSetAsm() {
+ DefineWordListSets(asmWordListDesc);
+ }
+};
+
+class LexerAsm : public ILexer {
+ WordList cpuInstruction;
+ WordList mathInstruction;
+ WordList registers;
+ WordList directive;
+ WordList directiveOperand;
+ WordList extInstruction;
+ OptionsAsm options;
+ OptionSetAsm osAsm;
+public:
+ LexerAsm() {
+ }
+ ~LexerAsm() {
+ }
+ void SCI_METHOD Release() {
+ delete this;
+ }
+ int SCI_METHOD Version() const {
+ return lvOriginal;
+ }
+ const char * SCI_METHOD PropertyNames() {
+ return osAsm.PropertyNames();
+ }
+ int SCI_METHOD PropertyType(const char *name) {
+ return osAsm.PropertyType(name);
+ }
+ const char * SCI_METHOD DescribeProperty(const char *name) {
+ return osAsm.DescribeProperty(name);
+ }
+ int SCI_METHOD PropertySet(const char *key, const char *val);
+ const char * SCI_METHOD DescribeWordListSets() {
+ return osAsm.DescribeWordListSets();
+ }
+ int SCI_METHOD WordListSet(int n, const char *wl);
+ void SCI_METHOD Lex(unsigned int startPos, int length, int initStyle, IDocument *pAccess);
+ void SCI_METHOD Fold(unsigned int startPos, int length, int initStyle, IDocument *pAccess);
+
+ void * SCI_METHOD PrivateCall(int, void *) {
+ return 0;
+ }
+
+ static ILexer *LexerFactoryAsm() {
+ return new LexerAsm();
+ }
+};
+
+int SCI_METHOD LexerAsm::PropertySet(const char *key, const char *val) {
+ if (osAsm.PropertySet(&options, key, val)) {
+ return 0;
+ }
+ return -1;
+}
+
+int SCI_METHOD LexerAsm::WordListSet(int n, const char *wl) {
+ WordList *wordListN = 0;
+ switch (n) {
+ case 0:
+ wordListN = &cpuInstruction;
+ break;
+ case 1:
+ wordListN = &mathInstruction;
+ break;
+ case 2:
+ wordListN = &registers;
+ break;
+ case 3:
+ wordListN = &directive;
+ break;
+ case 4:
+ wordListN = &directiveOperand;
+ break;
+ case 5:
+ wordListN = &extInstruction;
+ break;
+ }
+ int firstModification = -1;
+ if (wordListN) {
+ WordList wlNew;
+ wlNew.Set(wl);
+ if (*wordListN != wlNew) {
+ wordListN->Set(wl);
+ firstModification = 0;
+ }
+ }
+ return firstModification;
+}
- WordList &cpuInstruction = *keywordlists[0];
- WordList &mathInstruction = *keywordlists[1];
- WordList &registers = *keywordlists[2];
- WordList &directive = *keywordlists[3];
- WordList &directiveOperand = *keywordlists[4];
- WordList &extInstruction = *keywordlists[5];
+void SCI_METHOD LexerAsm::Lex(unsigned int startPos, int length, int initStyle, IDocument *pAccess) {
+ LexAccessor styler(pAccess);
// Do not leak onto next line
if (initStyle == SCE_ASM_STRINGEOL)
@@ -169,15 +282,10 @@ static void ColouriseAsmDoc(unsigned int startPos, int length, int initStyle, Wo
sc.Complete();
}
-static const char * const asmWordListDesc[] = {
- "CPU instructions",
- "FPU instructions",
- "Registers",
- "Directives",
- "Directive operands",
- "Extended instructions",
- 0
-};
+void SCI_METHOD LexerAsm::Fold(unsigned int /* startPos */, int /* length */, int /* initStyle */, IDocument* /* pAccess */) {
+
+ return;
+}
-LexerModule lmAsm(SCLEX_ASM, ColouriseAsmDoc, "asm", 0, asmWordListDesc);
+LexerModule lmAsm(SCLEX_ASM, LexerAsm::LexerFactoryAsm, "asm", asmWordListDesc);
diff --git a/lexers/LexBasic.cxx b/lexers/LexBasic.cxx
index d4954aa77..057afed65 100644
--- a/lexers/LexBasic.cxx
+++ b/lexers/LexBasic.cxx
@@ -1,6 +1,7 @@
// Scintilla source code edit control
/** @file LexBasic.cxx
** Lexer for BlitzBasic and PureBasic.
+ ** Converted to lexer object by "Udo Lechner" <dlchnr(at)gmx(dot)net>
**/
// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
@@ -22,6 +23,13 @@
#include <stdarg.h>
#include <assert.h>
+#ifdef _MSC_VER
+#pragma warning(disable: 4786)
+#endif
+
+#include <string>
+#include <map>
+
#include "ILexer.h"
#include "Scintilla.h"
#include "SciLexer.h"
@@ -32,6 +40,7 @@
#include "StyleContext.h"
#include "CharacterSet.h"
#include "LexerModule.h"
+#include "OptionSet.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
@@ -88,8 +97,186 @@ static int LowerCase(int c)
return c;
}
-static void ColouriseBasicDoc(unsigned int startPos, int length, int initStyle,
- WordList *keywordlists[], Accessor &styler, char comment_char) {
+static int CheckBlitzFoldPoint(char const *token, int &level) {
+ if (!strcmp(token, "function") ||
+ !strcmp(token, "type")) {
+ level |= SC_FOLDLEVELHEADERFLAG;
+ return 1;
+ }
+ if (!strcmp(token, "end function") ||
+ !strcmp(token, "end type")) {
+ return -1;
+ }
+ return 0;
+}
+
+static int CheckPureFoldPoint(char const *token, int &level) {
+ if (!strcmp(token, "procedure") ||
+ !strcmp(token, "enumeration") ||
+ !strcmp(token, "interface") ||
+ !strcmp(token, "structure")) {
+ level |= SC_FOLDLEVELHEADERFLAG;
+ return 1;
+ }
+ if (!strcmp(token, "endprocedure") ||
+ !strcmp(token, "endenumeration") ||
+ !strcmp(token, "endinterface") ||
+ !strcmp(token, "endstructure")) {
+ return -1;
+ }
+ return 0;
+}
+
+static int CheckFreeFoldPoint(char const *token, int &level) {
+ if (!strcmp(token, "function") ||
+ !strcmp(token, "sub") ||
+ !strcmp(token, "type")) {
+ level |= SC_FOLDLEVELHEADERFLAG;
+ return 1;
+ }
+ if (!strcmp(token, "end function") ||
+ !strcmp(token, "end sub") ||
+ !strcmp(token, "end type")) {
+ return -1;
+ }
+ return 0;
+}
+
+// An individual named option for use in an OptionSet
+
+// Options used for LexerBasic
+struct OptionsBasic {
+ bool fold;
+ bool foldCompact;
+ OptionsBasic() {
+ fold = false;
+ foldCompact = true;
+ }
+};
+
+static const char * const blitzbasicWordListDesc[] = {
+ "BlitzBasic Keywords",
+ "user1",
+ "user2",
+ "user3",
+ 0
+};
+
+static const char * const purebasicWordListDesc[] = {
+ "PureBasic Keywords",
+ "PureBasic PreProcessor Keywords",
+ "user defined 1",
+ "user defined 2",
+ 0
+};
+
+static const char * const freebasicWordListDesc[] = {
+ "FreeBasic Keywords",
+ "FreeBasic PreProcessor Keywords",
+ "user defined 1",
+ "user defined 2",
+ 0
+};
+
+struct OptionSetBasic : public OptionSet<OptionsBasic> {
+ OptionSetBasic(const char * const wordListDescriptions[]) {
+ DefineProperty("fold", &OptionsBasic::fold);
+
+ DefineProperty("fold.compact", &OptionsBasic::foldCompact);
+
+ DefineWordListSets(wordListDescriptions);
+ }
+};
+
+class LexerBasic : public ILexer {
+ char comment_char;
+ int (*CheckFoldPoint)(char const *, int &);
+ WordList keywordlists[4];
+ OptionsBasic options;
+ OptionSetBasic osBasic;
+public:
+ LexerBasic(char comment_char_, int (*CheckFoldPoint_)(char const *, int &), const char * const wordListDescriptions[]) :
+ comment_char(comment_char_),
+ CheckFoldPoint(CheckFoldPoint_),
+ osBasic(wordListDescriptions) {
+ }
+ ~LexerBasic() {
+ }
+ void SCI_METHOD Release() {
+ delete this;
+ }
+ int SCI_METHOD Version() const {
+ return lvOriginal;
+ }
+ const char * SCI_METHOD PropertyNames() {
+ return osBasic.PropertyNames();
+ }
+ int SCI_METHOD PropertyType(const char *name) {
+ return osBasic.PropertyType(name);
+ }
+ const char * SCI_METHOD DescribeProperty(const char *name) {
+ return osBasic.DescribeProperty(name);
+ }
+ int SCI_METHOD PropertySet(const char *key, const char *val);
+ const char * SCI_METHOD DescribeWordListSets() {
+ return osBasic.DescribeWordListSets();
+ }
+ int SCI_METHOD WordListSet(int n, const char *wl);
+ void SCI_METHOD Lex(unsigned int startPos, int length, int initStyle, IDocument *pAccess);
+ void SCI_METHOD Fold(unsigned int startPos, int length, int initStyle, IDocument *pAccess);
+
+ void * SCI_METHOD PrivateCall(int, void *) {
+ return 0;
+ }
+ static ILexer *LexerFactoryBlitzBasic() {
+ return new LexerBasic(';', CheckBlitzFoldPoint, blitzbasicWordListDesc);
+ }
+ static ILexer *LexerFactoryPureBasic() {
+ return new LexerBasic(';', CheckPureFoldPoint, purebasicWordListDesc);
+ }
+ static ILexer *LexerFactoryFreeBasic() {
+ return new LexerBasic('\'', CheckFreeFoldPoint, freebasicWordListDesc);
+ }
+};
+
+int SCI_METHOD LexerBasic::PropertySet(const char *key, const char *val) {
+ if (osBasic.PropertySet(&options, key, val)) {
+ return 0;
+ }
+ return -1;
+}
+
+int SCI_METHOD LexerBasic::WordListSet(int n, const char *wl) {
+ WordList *wordListN = 0;
+ switch (n) {
+ case 0:
+ wordListN = &keywordlists[0];
+ break;
+ case 1:
+ wordListN = &keywordlists[1];
+ break;
+ case 2:
+ wordListN = &keywordlists[2];
+ break;
+ case 3:
+ wordListN = &keywordlists[3];
+ break;
+ }
+ int firstModification = -1;
+ if (wordListN) {
+ WordList wlNew;
+ wlNew.Set(wl);
+ if (*wordListN != wlNew) {
+ wordListN->Set(wl);
+ firstModification = 0;
+ }
+ }
+ return firstModification;
+}
+
+void SCI_METHOD LexerBasic::Lex(unsigned int startPos, int length, int initStyle, IDocument *pAccess) {
+ LexAccessor styler(pAccess);
+
bool wasfirst = true, isfirst = true; // true if first token in a line
styler.StartAt(startPos);
@@ -113,7 +300,7 @@ static void ColouriseBasicDoc(unsigned int startPos, int length, int initStyle,
};
sc.GetCurrentLowered(s, sizeof(s));
for (int i = 0; i < 4; i++) {
- if (keywordlists[i]->InList(s)) {
+ if (keywordlists[i].InList(s)) {
sc.ChangeState(kstates[i]);
}
}
@@ -204,64 +391,25 @@ static void ColouriseBasicDoc(unsigned int startPos, int length, int initStyle,
sc.Complete();
}
-static int CheckBlitzFoldPoint(char const *token, int &level) {
- if (!strcmp(token, "function") ||
- !strcmp(token, "type")) {
- level |= SC_FOLDLEVELHEADERFLAG;
- return 1;
- }
- if (!strcmp(token, "end function") ||
- !strcmp(token, "end type")) {
- return -1;
- }
- return 0;
-}
-static int CheckPureFoldPoint(char const *token, int &level) {
- if (!strcmp(token, "procedure") ||
- !strcmp(token, "enumeration") ||
- !strcmp(token, "interface") ||
- !strcmp(token, "structure")) {
- level |= SC_FOLDLEVELHEADERFLAG;
- return 1;
- }
- if (!strcmp(token, "endprocedure") ||
- !strcmp(token, "endenumeration") ||
- !strcmp(token, "endinterface") ||
- !strcmp(token, "endstructure")) {
- return -1;
- }
- return 0;
-}
+void SCI_METHOD LexerBasic::Fold(unsigned int startPos, int length, int /* initStyle */, IDocument *pAccess) {
-static int CheckFreeFoldPoint(char const *token, int &level) {
- if (!strcmp(token, "function") ||
- !strcmp(token, "sub") ||
- !strcmp(token, "type")) {
- level |= SC_FOLDLEVELHEADERFLAG;
- return 1;
- }
- if (!strcmp(token, "end function") ||
- !strcmp(token, "end sub") ||
- !strcmp(token, "end type")) {
- return -1;
- }
- return 0;
-}
+ if (!options.fold)
+ return;
+
+
+ LexAccessor styler(pAccess);
-static void FoldBasicDoc(unsigned int startPos, int length,
- Accessor &styler, int (*CheckFoldPoint)(char const *, int &)) {
int line = styler.GetLine(startPos);
int level = styler.LevelAt(line);
int go = 0, done = 0;
int endPos = startPos + length;
char word[256];
int wordlen = 0;
- int i;
- bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
+
// Scan for tokens at the start of the line (they may include
// whitespace, for tokens like "End Function"
- for (i = startPos; i < endPos; i++) {
+ for (int i = startPos; i < endPos; i++) {
int c = styler.SafeGetCharAt(i);
if (!done && !go) {
if (wordlen) { // are we scanning a token already?
@@ -294,7 +442,7 @@ static void FoldBasicDoc(unsigned int startPos, int length,
}
}
if (c == '\n') { // line end
- if (!done && wordlen == 0 && foldCompact) // line was only space
+ if (!done && wordlen == 0 && options.foldCompact) // line was only space
level |= SC_FOLDLEVELWHITEFLAG;
if (level != styler.LevelAt(line))
styler.SetLevel(line, level);
@@ -310,66 +458,8 @@ static void FoldBasicDoc(unsigned int startPos, int length,
}
}
-static void ColouriseBlitzBasicDoc(unsigned int startPos, int length, int initStyle,
- WordList *keywordlists[], Accessor &styler) {
- ColouriseBasicDoc(startPos, length, initStyle, keywordlists, styler, ';');
-}
-
-static void ColourisePureBasicDoc(unsigned int startPos, int length, int initStyle,
- WordList *keywordlists[], Accessor &styler) {
- ColouriseBasicDoc(startPos, length, initStyle, keywordlists, styler, ';');
-}
-
-static void ColouriseFreeBasicDoc(unsigned int startPos, int length, int initStyle,
- WordList *keywordlists[], Accessor &styler) {
- ColouriseBasicDoc(startPos, length, initStyle, keywordlists, styler, '\'');
-}
-
-static void FoldBlitzBasicDoc(unsigned int startPos, int length, int,
- WordList *[], Accessor &styler) {
- FoldBasicDoc(startPos, length, styler, CheckBlitzFoldPoint);
-}
-
-static void FoldPureBasicDoc(unsigned int startPos, int length, int,
- WordList *[], Accessor &styler) {
- FoldBasicDoc(startPos, length, styler, CheckPureFoldPoint);
-}
-
-static void FoldFreeBasicDoc(unsigned int startPos, int length, int,
- WordList *[], Accessor &styler) {
- FoldBasicDoc(startPos, length, styler, CheckFreeFoldPoint);
-}
-
-static const char * const blitzbasicWordListDesc[] = {
- "BlitzBasic Keywords",
- "user1",
- "user2",
- "user3",
- 0
-};
-
-static const char * const purebasicWordListDesc[] = {
- "PureBasic Keywords",
- "PureBasic PreProcessor Keywords",
- "user defined 1",
- "user defined 2",
- 0
-};
-
-static const char * const freebasicWordListDesc[] = {
- "FreeBasic Keywords",
- "FreeBasic PreProcessor Keywords",
- "user defined 1",
- "user defined 2",
- 0
-};
-
-LexerModule lmBlitzBasic(SCLEX_BLITZBASIC, ColouriseBlitzBasicDoc, "blitzbasic",
- FoldBlitzBasicDoc, blitzbasicWordListDesc);
-
-LexerModule lmPureBasic(SCLEX_PUREBASIC, ColourisePureBasicDoc, "purebasic",
- FoldPureBasicDoc, purebasicWordListDesc);
+LexerModule lmBlitzBasic(SCLEX_BLITZBASIC, LexerBasic::LexerFactoryBlitzBasic, "blitzbasic", blitzbasicWordListDesc);
-LexerModule lmFreeBasic(SCLEX_FREEBASIC, ColouriseFreeBasicDoc, "freebasic",
- FoldFreeBasicDoc, freebasicWordListDesc);
+LexerModule lmPureBasic(SCLEX_PUREBASIC, LexerBasic::LexerFactoryPureBasic, "purebasic", purebasicWordListDesc);
+LexerModule lmFreeBasic(SCLEX_FREEBASIC, LexerBasic::LexerFactoryFreeBasic, "freebasic", freebasicWordListDesc);