diff options
author | nyamatongwe <unknown> | 2003-10-13 12:25:33 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2003-10-13 12:25:33 +0000 |
commit | d20359c95c59676a8267a8cbf366134372de4252 (patch) | |
tree | 736190e7f10b5724c6aaf7f46b407258fa182c2b | |
parent | 7358e44ada115f8d23cd0c2131172b45462c5a47 (diff) | |
download | scintilla-mirror-d20359c95c59676a8267a8cbf366134372de4252.tar.gz |
PowerBasic lexer added.
-rw-r--r-- | doc/ScintillaHistory.html | 1 | ||||
-rw-r--r-- | gtk/makefile | 4 | ||||
-rw-r--r-- | gtk/scintilla.mak | 3 | ||||
-rw-r--r-- | src/KeyWords.cxx | 1 | ||||
-rw-r--r-- | src/LexPB.cxx | 242 | ||||
-rw-r--r-- | win32/makefile | 4 | ||||
-rw-r--r-- | win32/scintilla.mak | 3 | ||||
-rw-r--r-- | win32/scintilla_vc6.mak | 3 |
8 files changed, 257 insertions, 4 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 118d90e28..76daf7549 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -146,6 +146,7 @@ <li>Stefanos Togoulidis</li> <li>Hans Hagen</li> <li>Jim Cape</li> + <li>Roland Walter</li> </ul> <p> Images used in GTK+ version diff --git a/gtk/makefile b/gtk/makefile index 985ac8f60..8b1d7ba66 100644 --- a/gtk/makefile +++ b/gtk/makefile @@ -63,8 +63,8 @@ LEXOBJS=\ LexAda.o LexAsm.o LexAVE.o LexBaan.o LexBullant.o LexCLW.o LexConf.o LexCPP.o \ LexCrontab.o LexCSS.o LexEiffel.o LexEScript.o LexFortran.o LexHTML.o \ LexLisp.o LexLout.o LexLua.o LexMatlab.o LexMetapost.o LexMMIXAL.o LexMPT.o \ -LexNsis.o LexOthers.o LexPascal.o LexPerl.o LexPOV.o LexPS.o LexPython.o \ -LexRuby.o LexScriptol.o LexSQL.o LexTeX.o LexVB.o LexYAML.o +LexNsis.o LexOthers.o LexPascal.o LexPB.o LexPerl.o LexPOV.o LexPS.o \ +LexPython.o LexRuby.o LexScriptol.o LexSQL.o LexTeX.o LexVB.o LexYAML.o #--Autogenerated -- end of automatically generated section # The LEXOBJS have to be treated specially as the functions in them are not called from external code diff --git a/gtk/scintilla.mak b/gtk/scintilla.mak index 8f1c4a168..4a689d92b 100644 --- a/gtk/scintilla.mak +++ b/gtk/scintilla.mak @@ -144,6 +144,7 @@ LEXOBJS=\ $(DIR_O)\LexNsis.obj \ $(DIR_O)\LexOthers.obj \ $(DIR_O)\LexPascal.obj \ + $(DIR_O)\LexPB.obj \ $(DIR_O)\LexPerl.obj \ $(DIR_O)\LexPOV.obj \ $(DIR_O)\LexPS.obj \ @@ -314,6 +315,8 @@ $(DIR_O)\LexOthers.obj: ..\src\LexOthers.cxx $(LEX_HEADERS) $(DIR_O)\LexPascal.obj: ..\src\LexPascal.cxx $(LEX_HEADERS) +$(DIR_O)\LexPB.obj: ..\src\LexPB.cxx $(LEX_HEADERS) + $(DIR_O)\LexPerl.obj: ..\src\LexPerl.cxx $(LEX_HEADERS) $(DIR_O)\LexPOV.obj: ..\src\LexPOV.cxx $(LEX_HEADERS) diff --git a/src/KeyWords.cxx b/src/KeyWords.cxx index 7ec5d9922..45eb83027 100644 --- a/src/KeyWords.cxx +++ b/src/KeyWords.cxx @@ -167,6 +167,7 @@ int Scintilla_LinkLexers() { LINK_LEXER(lmLatex); LINK_LEXER(lmNull); LINK_LEXER(lmPascal); + LINK_LEXER(lmPB); LINK_LEXER(lmPerl); LINK_LEXER(lmPOV); LINK_LEXER(lmPS); diff --git a/src/LexPB.cxx b/src/LexPB.cxx new file mode 100644 index 000000000..3564207df --- /dev/null +++ b/src/LexPB.cxx @@ -0,0 +1,242 @@ +// Scintilla source code edit control +/** @file LexPB.cxx + ** Lexer for PowerBasic by Roland Walter, roland@rowalt.de + **/ +// +// Necessary changes in Scintilla project: +// - In SciLexer.h and Scintilla.iface: +// +// #define SCLEX_PB 49 //Provisional inofficial ID for PowerBasic lexer, +// (...) +// #define SCE_B_DEFAULT 0 //in both VB and PB lexer +// #define SCE_B_COMMENT 1 //in both VB and PB lexer +// #define SCE_B_NUMBER 2 //in both VB and PB lexer +// #define SCE_B_KEYWORD 3 //in both VB and PB lexer +// #define SCE_B_STRING 4 //in both VB and PB lexer +// #define SCE_B_PREPROCESSOR 5 //VB lexer only, unsupported by PB lexer +// #define SCE_B_OPERATOR 6 //in both VB and PB lexer +// #define SCE_B_IDENTIFIER 7 //in both VB and PB lexer +// #define SCE_B_DATE 8 //VB lexer only, unsupported by PB lexer + +// - Statement added to KeyWords.cxx: 'LINK_LEXER(lmPB);' +// - Statement added to scintilla_vc6.mak: '$(DIR_O)\LexPB.obj: ..\src\LexPB.cxx $(LEX_HEADERS)' +// +// Copyright for Scintilla: 1998-2001 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 "Platform.h" + +#include "PropSet.h" +#include "Accessor.h" +#include "StyleContext.h" +#include "KeyWords.h" +#include "Scintilla.h" +#include "SciLexer.h" + +static inline bool IsTypeCharacter(const int ch) { + return ch == '%' || ch == '&' || ch == '@' || ch == '!' || ch == '#' || ch == '$'; +} + +static inline bool IsAWordChar(const int ch) { + return (ch < 0x80) && (isalnum(ch) || ch == '.' || ch == '_'); +} + +static inline bool IsAWordStart(const int ch) { + return (ch < 0x80) && (isalnum(ch) || ch == '_'); +} + +bool MatchUpperCase(Accessor &styler, int pos, const char *s) //Same as styler.Match() but uppercase comparison (a-z,A-Z and space only) +{ + char ch; + for (int i=0; *s; i++) + { + ch=styler.SafeGetCharAt(pos+i); + if (ch > 0x60) ch -= '\x20'; + if (*s != ch) return false; + s++; + } + return true; +} + +static void ColourisePBDoc(unsigned int startPos, int length, int initStyle,WordList *keywordlists[], + Accessor &styler) { + + WordList &keywords = *keywordlists[0]; + + styler.StartAt(startPos); + + StyleContext sc(startPos, length, initStyle, styler); + + for (; sc.More(); sc.Forward()) { + + if (sc.state == SCE_B_OPERATOR) + { + sc.SetState(SCE_B_DEFAULT); + } + else if (sc.state == SCE_B_KEYWORD) + { + if (!IsAWordChar(sc.ch)) + { + if (!IsTypeCharacter(sc.ch)) + { + if (sc.ch == ']') {sc.Forward();} + char s[100]; + sc.GetCurrentLowered(s, sizeof(s)); + if (keywords.InList(s)) + { + if (strcmp(s, "rem") == 0) + { + sc.ChangeState(SCE_B_COMMENT); + if (sc.atLineEnd) {sc.SetState(SCE_B_DEFAULT);} + } + else + { + sc.SetState(SCE_B_DEFAULT); + } + } + else + { + sc.ChangeState(SCE_B_IDENTIFIER); + sc.SetState(SCE_B_DEFAULT); + } + } + } + } + else if (sc.state == SCE_B_NUMBER) + { + if (!IsAWordChar(sc.ch)) {sc.SetState(SCE_B_DEFAULT);} + } + else if (sc.state == SCE_B_STRING) + { + // PB doubles quotes to preserve them, so just end this string + // state now as a following quote will start again + if (sc.ch == '\"') + { + if (tolower(sc.chNext) == 'c') {sc.Forward();} + sc.ForwardSetState(SCE_B_DEFAULT); + } + } + else if (sc.state == SCE_B_COMMENT) + { + if (sc.atLineEnd) {sc.SetState(SCE_B_DEFAULT);} + } + + if (sc.state == SCE_B_DEFAULT) + { + if (sc.ch == '\'') {sc.SetState(SCE_B_COMMENT);} + else if (sc.ch == '\"') {sc.SetState(SCE_B_STRING);} + else if (sc.ch == '#') + { int n = 1; + int chSeek = ' '; + while ((n < 100) && (chSeek == ' ' || chSeek == '\t')) + { + chSeek = sc.GetRelative(n); + n++; + } + sc.SetState(SCE_B_OPERATOR); + } + else if (sc.ch == '&' && tolower(sc.chNext) == 'h') {sc.SetState(SCE_B_NUMBER);} + else if (sc.ch == '&' && tolower(sc.chNext) == 'b') {sc.SetState(SCE_B_NUMBER);} + else if (sc.ch == '&' && tolower(sc.chNext) == 'o') {sc.SetState(SCE_B_NUMBER);} + else if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext))) {sc.SetState(SCE_B_NUMBER);} + else if (IsAWordStart(sc.ch) || (sc.ch == '[')) {sc.SetState(SCE_B_KEYWORD);} + else if (isoperator(static_cast<char>(sc.ch)) || (sc.ch == '\\')) {sc.SetState(SCE_B_OPERATOR);} + } + + } + sc.Complete(); +} + +static void FoldPBDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) +{ + // No folding enabled, no reason to continue... + if( styler.GetPropertyInt("fold") == 0 ) + return; + + unsigned int endPos = startPos + length; + int lineCurrent = styler.GetLine(startPos); + int levelCurrent = SC_FOLDLEVELBASE; + if (lineCurrent > 0) + levelCurrent = styler.LevelAt(lineCurrent-1) >> 16; + int levelNext = levelCurrent; + char chNext = styler[startPos]; + + bool atEOL=1; + for (unsigned int i = startPos; i < endPos; i++) + { + char ch = chNext; + chNext = styler.SafeGetCharAt(i + 1); + // Functions Start: Function, Sub + // Functions End: End Function, End Sub + + if( atEOL ) //Begin of a new line (The Sub/Function/Macro keywords may occur at begin of line only) + { + if( MatchUpperCase(styler,i,"END FUNCTION") ) + levelNext=SC_FOLDLEVELBASE; + else if( MatchUpperCase(styler,i,"FUNCTION") ) + { + styler.SetLevel(lineCurrent, (SC_FOLDLEVELBASE << 16) | SC_FOLDLEVELHEADERFLAG); + levelNext=SC_FOLDLEVELBASE+1; + } + else if( MatchUpperCase(styler,i,"CALLBACK FUNCTION") ) + { + styler.SetLevel(lineCurrent, (SC_FOLDLEVELBASE << 16) | SC_FOLDLEVELHEADERFLAG); + levelNext=SC_FOLDLEVELBASE+1; + } + else if( MatchUpperCase(styler,i,"STATIC FUNCTION") ) + { + styler.SetLevel(lineCurrent, (SC_FOLDLEVELBASE << 16) | SC_FOLDLEVELHEADERFLAG); + levelNext=SC_FOLDLEVELBASE+1; + } + else if( MatchUpperCase(styler,i,"END SUB") ) + levelNext=SC_FOLDLEVELBASE; + else if( MatchUpperCase(styler,i,"SUB") ) + { + styler.SetLevel(lineCurrent, (SC_FOLDLEVELBASE << 16) | SC_FOLDLEVELHEADERFLAG); + levelNext=SC_FOLDLEVELBASE+1; + } + else if( MatchUpperCase(styler,i,"STATIC SUB") ) + { + styler.SetLevel(lineCurrent, (SC_FOLDLEVELBASE << 16) | SC_FOLDLEVELHEADERFLAG); + levelNext=SC_FOLDLEVELBASE+1; + } + //else if( MatchUpperCase(styler,i,"END MACRO") ) + // levelNext--; + //else if( MatchUpperCase(styler,i,"MACRO") ) //ToDo: What's with single-line macros? + // levelNext++; + } + + atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n'); + if( atEOL ) + { + if (levelNext == SC_FOLDLEVELBASE) + { + int levelUse = levelCurrent; + int lev = levelUse | levelNext << 16; + styler.SetLevel(lineCurrent, lev); + } + lineCurrent++; + levelCurrent = levelNext; + } + } + + if (levelNext == SC_FOLDLEVELBASE) + { + int levelUse = levelCurrent; + int lev = levelUse | levelNext << 16; + styler.SetLevel(lineCurrent, lev); + } +} + +static const char * const pbWordListDesc[] = { + "Keywords", + 0 +}; + +LexerModule lmPB(SCLEX_POWERBASIC, ColourisePBDoc, "powerbasic", FoldPBDoc, pbWordListDesc); diff --git a/win32/makefile b/win32/makefile index 13a13da0b..010f3be16 100644 --- a/win32/makefile +++ b/win32/makefile @@ -53,8 +53,8 @@ LEXOBJS=\ LexAda.o LexAsm.o LexAVE.o LexBaan.o LexBullant.o LexCLW.o LexConf.o LexCPP.o \ LexCrontab.o LexCSS.o LexEiffel.o LexEScript.o LexFortran.o LexHTML.o \ LexLisp.o LexLout.o LexLua.o LexMatlab.o LexMetapost.o LexMMIXAL.o LexMPT.o \ -LexNsis.o LexOthers.o LexPascal.o LexPerl.o LexPOV.o LexPS.o LexPython.o \ -LexRuby.o LexScriptol.o LexSQL.o LexTeX.o LexVB.o LexYAML.o +LexNsis.o LexOthers.o LexPascal.o LexPB.o LexPerl.o LexPOV.o LexPS.o \ +LexPython.o LexRuby.o LexScriptol.o LexSQL.o LexTeX.o LexVB.o LexYAML.o #--Autogenerated -- end of automatically generated section SOBJS = ScintillaWin.o ScintillaBase.o Editor.o Document.o \ diff --git a/win32/scintilla.mak b/win32/scintilla.mak index 0be1f35b4..1026fdc89 100644 --- a/win32/scintilla.mak +++ b/win32/scintilla.mak @@ -133,6 +133,7 @@ LEXOBJS=\ $(DIR_O)\LexNsis.obj \ $(DIR_O)\LexOthers.obj \ $(DIR_O)\LexPascal.obj \ + $(DIR_O)\LexPB.obj \ $(DIR_O)\LexPerl.obj \ $(DIR_O)\LexPOV.obj \ $(DIR_O)\LexPS.obj \ @@ -300,6 +301,8 @@ $(DIR_O)\LexOthers.obj: ..\src\LexOthers.cxx $(LEX_HEADERS) $(DIR_O)\LexPascal.obj: ..\src\LexPascal.cxx $(LEX_HEADERS) +$(DIR_O)\LexPB.obj: ..\src\LexPB.cxx $(LEX_HEADERS) + $(DIR_O)\LexPerl.obj: ..\src\LexPerl.cxx $(LEX_HEADERS) $(DIR_O)\LexPOV.obj: ..\src\LexPOV.cxx $(LEX_HEADERS) diff --git a/win32/scintilla_vc6.mak b/win32/scintilla_vc6.mak index 78e17bf2b..d8d2d0b59 100644 --- a/win32/scintilla_vc6.mak +++ b/win32/scintilla_vc6.mak @@ -135,6 +135,7 @@ LEXOBJS=\ $(DIR_O)\LexNsis.obj \ $(DIR_O)\LexOthers.obj \ $(DIR_O)\LexPascal.obj \ + $(DIR_O)\LexPB.obj \ $(DIR_O)\LexPerl.obj \ $(DIR_O)\LexPOV.obj \ $(DIR_O)\LexPS.obj \ @@ -302,6 +303,8 @@ $(DIR_O)\LexOthers.obj: ..\src\LexOthers.cxx $(LEX_HEADERS) $(DIR_O)\LexPascal.obj: ..\src\LexPascal.cxx $(LEX_HEADERS) +$(DIR_O)\LexPB.obj: ..\src\LexPB.cxx $(LEX_HEADERS) + $(DIR_O)\LexPerl.obj: ..\src\LexPerl.cxx $(LEX_HEADERS) $(DIR_O)\LexPOV.obj: ..\src\LexPOV.cxx $(LEX_HEADERS) |