diff options
| author | nyamatongwe <devnull@localhost> | 2005-05-04 12:03:52 +0000 | 
|---|---|---|
| committer | nyamatongwe <devnull@localhost> | 2005-05-04 12:03:52 +0000 | 
| commit | f3347d829ffff834752ab4f4cf1e990ab45e42a8 (patch) | |
| tree | a0222074f509183a6d7ae8dfd7b941366f3b4a42 | |
| parent | cebf9adf0c80463586cc7e6ff55503668a60dbb6 (diff) | |
| download | scintilla-mirror-f3347d829ffff834752ab4f4cf1e990ab45e42a8.tar.gz | |
Smalltalk support added by Sergey Philippov.
| -rw-r--r-- | gtk/makefile | 4 | ||||
| -rw-r--r-- | gtk/scintilla.mak | 3 | ||||
| -rw-r--r-- | include/SciLexer.h | 18 | ||||
| -rw-r--r-- | include/Scintilla.iface | 20 | ||||
| -rw-r--r-- | src/KeyWords.cxx | 1 | ||||
| -rw-r--r-- | src/LexSmalltalk.cxx | 345 | ||||
| -rw-r--r-- | win32/makefile | 4 | ||||
| -rw-r--r-- | win32/scintilla.mak | 3 | ||||
| -rw-r--r-- | win32/scintilla_vc6.mak | 3 | 
9 files changed, 397 insertions, 4 deletions
| diff --git a/gtk/makefile b/gtk/makefile index be3c5defc..1b1ea98d6 100644 --- a/gtk/makefile +++ b/gtk/makefile @@ -69,8 +69,8 @@ LexCSS.o LexEiffel.o LexErlang.o LexEScript.o LexForth.o LexFortran.o \  LexGui4Cli.o LexHaskell.o LexHTML.o LexKix.o LexLisp.o LexLout.o LexLua.o \  LexMatlab.o LexMetapost.o LexMMIXAL.o LexMPT.o LexMSSQL.o LexNsis.o \  LexOthers.o LexPascal.o LexPB.o LexPerl.o LexPOV.o LexPS.o LexPython.o \ -LexRebol.o LexRuby.o LexScriptol.o LexSpecman.o LexSQL.o LexTADS3.o LexTeX.o \ -LexVB.o LexVerilog.o LexVHDL.o LexYAML.o +LexRebol.o LexRuby.o LexScriptol.o LexSmalltalk.o LexSpecman.o LexSQL.o \ +LexTADS3.o LexTeX.o LexVB.o LexVerilog.o LexVHDL.o LexYAML.o  #--Autogenerated -- end of automatically generated section  all: $(COMPLIB) diff --git a/gtk/scintilla.mak b/gtk/scintilla.mak index 221bd78c1..682db1934 100644 --- a/gtk/scintilla.mak +++ b/gtk/scintilla.mak @@ -183,6 +183,7 @@ LEXOBJS=\  	$(DIR_O)\LexRebol.obj \  	$(DIR_O)\LexRuby.obj \  	$(DIR_O)\LexScriptol.obj \ +	$(DIR_O)\LexSmalltalk.obj \  	$(DIR_O)\LexSpecman.obj \  	$(DIR_O)\LexSQL.obj \  	$(DIR_O)\LexTADS3.obj \ @@ -395,6 +396,8 @@ $(DIR_O)\LexRuby.obj: ..\src\LexRuby.cxx $(LEX_HEADERS)  $(DIR_O)\LexScriptol.obj: ..\src\LexScriptol.cxx $(LEX_HEADERS) +$(DIR_O)\LexSmalltalk.obj: ..\src\LexSmalltalk.cxx $(LEX_HEADERS) +  $(DIR_O)\LexSpecman.obj: ..\src\LexSpecman.cxx $(LEX_HEADERS)  $(DIR_O)\LexSQL.obj: ..\src\LexSQL.cxx $(LEX_HEADERS) diff --git a/include/SciLexer.h b/include/SciLexer.h index 187874734..af0f05910 100644 --- a/include/SciLexer.h +++ b/include/SciLexer.h @@ -84,6 +84,7 @@  #define SCLEX_PHPSCRIPT 69  #define SCLEX_TADS3 70  #define SCLEX_REBOL 71 +#define SCLEX_SMALLTALK 72  #define SCLEX_AUTOMATIC 1000  #define SCE_P_DEFAULT 0  #define SCE_P_COMMENTLINE 1 @@ -914,6 +915,23 @@  #define SCE_SQL_USER2 20  #define SCE_SQL_USER3 21  #define SCE_SQL_USER4 22 +#define SCE_ST_DEFAULT 0 +#define SCE_ST_STRING 1 +#define SCE_ST_NUMBER 2 +#define SCE_ST_COMMENT 3 +#define SCE_ST_SYMBOL 4 +#define SCE_ST_BINARY 5 +#define SCE_ST_BOOL 6 +#define SCE_ST_SELF 7 +#define SCE_ST_SUPER 8 +#define SCE_ST_NIL 9 +#define SCE_ST_GLOBAL 10 +#define SCE_ST_RETURN 11 +#define SCE_ST_SPECIAL 12 +#define SCE_ST_KWSEND 13 +#define SCE_ST_ASSIGN 14 +#define SCE_ST_CHARACTER 15 +#define SCE_ST_SPEC_SEL 16  #define SCLEX_ASP 29  #define SCLEX_PHP 30  //--Autogenerated -- end of section automatically generated from Scintilla.iface diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 3d4d203f4..5706177c9 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1784,6 +1784,7 @@ val SCLEX_HASKELL=68  val SCLEX_PHPSCRIPT=69  val SCLEX_TADS3=70  val SCLEX_REBOL=71 +val SCLEX_SMALLTALK=72  # When a lexer specifies its language as SCLEX_AUTOMATIC it receives a  # value assigned in sequence from SCLEX_AUTOMATIC+1. @@ -2745,6 +2746,25 @@ val SCE_SQL_USER1=19  val SCE_SQL_USER2=20  val SCE_SQL_USER3=21  val SCE_SQL_USER4=22 +# Lexical states for SCLEX_SMALLTALK +lex Smalltalk=SCLEX_SMALLTALK SCE_ST_ +val SCE_ST_DEFAULT=0 +val SCE_ST_STRING=1 +val SCE_ST_NUMBER=2 +val SCE_ST_COMMENT=3 +val SCE_ST_SYMBOL=4 +val SCE_ST_BINARY=5 +val SCE_ST_BOOL=6 +val SCE_ST_SELF=7 +val SCE_ST_SUPER=8 +val SCE_ST_NIL=9 +val SCE_ST_GLOBAL=10 +val SCE_ST_RETURN=11 +val SCE_ST_SPECIAL=12 +val SCE_ST_KWSEND=13 +val SCE_ST_ASSIGN=14 +val SCE_ST_CHARACTER=15 +val SCE_ST_SPEC_SEL=16  # Events diff --git a/src/KeyWords.cxx b/src/KeyWords.cxx index 01fe0fd4e..cee412b1e 100644 --- a/src/KeyWords.cxx +++ b/src/KeyWords.cxx @@ -190,6 +190,7 @@ int Scintilla_LinkLexers() {  	LINK_LEXER(lmREBOL);  	LINK_LEXER(lmRuby);  	LINK_LEXER(lmScriptol); +	LINK_LEXER(lmSmalltalk);  	LINK_LEXER(lmSpecman);  	LINK_LEXER(lmSQL);  	LINK_LEXER(lmTADS3); diff --git a/src/LexSmalltalk.cxx b/src/LexSmalltalk.cxx new file mode 100644 index 000000000..159390041 --- /dev/null +++ b/src/LexSmalltalk.cxx @@ -0,0 +1,345 @@ +// Scintilla source code edit control +/** @file LexSmalltalk.cxx + ** Lexer for Smalltalk language. + ** Written by Sergey Philippov, sphilippov-at-gmail-dot-com + **/ +// Copyright 1998-2002 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 "Platform.h" + +#include "PropSet.h" +#include "Accessor.h" +#include "StyleContext.h" +#include "KeyWords.h" +#include "Scintilla.h" +#include "SciLexer.h" + +/* +| lexTable classificationBlock charClasses | +charClasses := #(#DecDigit #Letter #Special #Upper #BinSel). +lexTable := ByteArray new: 128. +classificationBlock := [ :charClass :chars | +    | flag | +    flag := 1 bitShift: (charClasses indexOf: charClass) - 1. +    chars do: [ :char | lexTable at: char codePoint + 1 put: ((lexTable at: char codePoint + 1) bitOr: flag)]]. + +classificationBlock +    value: #DecDigit value: '0123456789'; +    value: #Letter value: '_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; +    value: #Special value: '()[]{};.^:'; +    value: #BinSel value: '~@%&*-+=|\/,<>?!'; +    value: #Upper value: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. + +((String new: 500) streamContents: [ :stream |             +    stream crLf; nextPutAll: 'static int ClassificationTable[256] = {'. +    lexTable keysAndValuesDo: [ :index :value | +        ((index - 1) rem: 16) == 0 ifTrue: [ +            stream crLf; tab] +        ifFalse: [ +            stream space]. +        stream print: value. +        index ~= 256 ifTrue: [ +            stream nextPut: $,]]. +    stream crLf; nextPutAll: '};'; crLf. +     +    charClasses keysAndValuesDo: [ :index :name | +        stream +            crLf; +            nextPutAll: ( +                ('static inline bool is<1s>(int ch) {return (ch > 0) && (ch %< 0x80) && ((ClassificationTable[ch] & <2p>) != 0);}') +                    expandMacrosWith: name with: (1 bitShift: (index - 1))) +    ]]) edit +*/ + +// autogenerated {{{{ + +static int ClassificationTable[256] = { +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +    0, 16, 0, 0, 0, 16, 16, 0, 4, 4, 16, 16, 16, 16, 4, 16, +    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 16, 16, 16, 16, +    16, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, +    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 4, 16, 4, 4, 2, +    0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 16, 4, 16, 0, +}; + +static inline bool isDecDigit(int ch) {return (ch > 0) && (ch < 0x80) && ((ClassificationTable[ch] & 1) != 0);} +static inline bool isLetter(int ch) {return (ch > 0) && (ch < 0x80) && ((ClassificationTable[ch] & 2) != 0);} +static inline bool isSpecial(int ch) {return (ch > 0) && (ch < 0x80) && ((ClassificationTable[ch] & 4) != 0);} +static inline bool isUpper(int ch) {return (ch > 0) && (ch < 0x80) && ((ClassificationTable[ch] & 8) != 0);} +static inline bool isBinSel(int ch) {return (ch > 0) && (ch < 0x80) && ((ClassificationTable[ch] & 16) != 0);} +// autogenerated }}}} + +static inline bool isAlphaNumeric(int ch) { +    return isDecDigit(ch) || isLetter(ch); +} + +static inline bool isDigitOfRadix(int ch, int radix) +{ +    if (isDecDigit(ch)) +        return (ch - '0') < radix; +    else if (!isUpper(ch)) +        return false; +    else +        return (ch - 'A' + 10) < radix; +} + +static inline void skipComment(StyleContext& sc) +{     +    while (sc.More() && sc.ch != '\"') +        sc.Forward(); +} + +static inline void skipString(StyleContext& sc) +{ +    while (sc.More()) { +        if (sc.ch == '\'') { +            if (sc.chNext != '\'') +                return; +            sc.Forward(); +        } +        sc.Forward(); +    } +} + +static void handleHash(StyleContext& sc) +{ +    if (isSpecial(sc.chNext)) { +        sc.SetState(SCE_ST_SPECIAL); +        return; +    } +     +    sc.SetState(SCE_ST_SYMBOL); +    sc.Forward(); +    if (sc.ch == '\'') { +        sc.Forward(); +        skipString(sc); +    } +    else { +        if (isLetter(sc.ch)) { +            while (isAlphaNumeric(sc.chNext) || sc.chNext == ':') +                sc.Forward(); +        } +        else if (isBinSel(sc.ch)) { +            while (isBinSel(sc.chNext)) +                sc.Forward(); +        } +    } +} + +static inline void handleSpecial(StyleContext& sc) +{ +    if (sc.ch == ':' && sc.chNext == '=') { +        sc.SetState(SCE_ST_ASSIGN); +        sc.Forward(); +    } +    else { +        if (sc.ch == '^') +            sc.SetState(SCE_ST_RETURN); +        else +            sc.SetState(SCE_ST_SPECIAL); +    } +} + +static inline void skipInt(StyleContext& sc, int radix) +{ +    while (isDigitOfRadix(sc.chNext, radix)) +        sc.Forward(); +} + +static void handleNumeric(StyleContext& sc) +{ +    char num[256]; +    int nl; +    int radix; +     +    sc.SetState(SCE_ST_NUMBER); +    num[0] = static_cast<char>(sc.ch); +    nl = 1; +    while (isDecDigit(sc.chNext)) { +        num[nl++] = static_cast<char>(sc.chNext); +        sc.Forward(); +        if (nl+1 == sizeof(num)/sizeof(num[0])) // overrun check +            break; +    } +    if (sc.chNext == 'r') { +        num[nl] = 0; +        if (num[0] == '-') +            radix = atoi(num + 1); +        else +            radix = atoi(num); +        sc.Forward(); +        if (sc.chNext == '-') +            sc.Forward(); +        skipInt(sc, radix); +    } +    else +        radix = 10; +    if (sc.chNext != '.' || !isDigitOfRadix(sc.GetRelative(2), radix)) +        return; +    sc.Forward(); +    skipInt(sc, radix); +    if (sc.chNext == 's') { +        // ScaledDecimal +        sc.Forward(); +        while (isDecDigit(sc.chNext)) +            sc.Forward(); +        return; +    } +    else if (sc.chNext != 'e' && sc.chNext != 'd' && sc.chNext != 'q') +        return; +    sc.Forward(); +    if (sc.chNext == '+' || sc.chNext == '-') +        sc.Forward(); +    skipInt(sc, radix); +} + +static inline void handleBinSel(StyleContext& sc) +{ +    sc.SetState(SCE_ST_BINARY); +    while (isBinSel(sc.chNext)) +        sc.Forward(); +} + +static const char* SpecialKwSelectors[] = { +    "ifTrue:", +    "ifFalse:", +    "whileTrue:", +    "whileFalse:", +    "ifNil:", +    "ifNotNil:", +    NULL +}; + +static const char* SpecialUnarySelectors[] = { +    "whileTrue", +    "whileFalse", +    "repeat", +    NULL +}; + +static inline bool isSpecialSelector(const char* sel, const char** sels) +{ +    int i; +     +    for (i = 0; sels[i] != NULL; i++) { +        if (!strcmp(sel, sels[i])) +            return true; +    } +    return false; +} + +static void handleLetter(StyleContext& sc) +{ +    char ident[256]; +    int il; +    int state; +    bool doubleColonPresent; +     +    sc.SetState(SCE_ST_DEFAULT); + +    ident[0] = static_cast<char>(sc.ch); +    il = 1; +    doubleColonPresent; +    while (isAlphaNumeric(sc.chNext)) { +        ident[il++] = static_cast<char>(sc.chNext); +        sc.Forward(); +        if (il+2 == sizeof(ident)/sizeof(ident[0])) // overrun check +            break; +    } + +    if (sc.chNext == ':') { +        doubleColonPresent = true; +        ident[il++] = ':'; +        sc.Forward(); +    } +    else +        doubleColonPresent = false; +    ident[il] = 0; +     +    if (doubleColonPresent) { +        if (isSpecialSelector(ident, SpecialKwSelectors)) +            state = SCE_ST_SPEC_SEL; +        else +            state = SCE_ST_KWSEND; +    } +    else if (isUpper(ident[0])) +        state = SCE_ST_GLOBAL; +    else if (isSpecialSelector(ident, SpecialUnarySelectors)) +        state = SCE_ST_SPEC_SEL; +    else { +        if (!strcmp(ident, "self")) +            state = SCE_ST_SELF; +        else if (!strcmp(ident, "super")) +            state = SCE_ST_SUPER; +        else if (!strcmp(ident, "nil")) +            state = SCE_ST_NIL; +        else if (!strcmp(ident, "true") || !strcmp(ident, "false")) +            state = SCE_ST_BOOL; +        else +            state = SCE_ST_DEFAULT; +    } +     +    sc.ChangeState(state); +} + +static void colorizeSmalltalkDoc(unsigned int startPos, int length, int initStyle, WordList *[], Accessor &styler) +{ +    StyleContext sc(startPos, length, initStyle, styler); + +    if (initStyle == SCE_ST_COMMENT) { +        skipComment(sc); +        if (sc.More()) +            sc.Forward(); +    } +    else if (initStyle == SCE_ST_STRING) { +        skipString(sc); +        if (sc.More()) +            sc.Forward(); +    } + +    for (; sc.More(); sc.Forward()) { +        int ch; +         +        ch = sc.ch; +        if (ch == '\"') { +            sc.SetState(SCE_ST_COMMENT); +            sc.Forward(); +            skipComment(sc); +        } +        else if (ch == '\'') { +            sc.SetState(SCE_ST_STRING); +            sc.Forward(); +            skipString(sc); +        } +        else if (ch == '#') +            handleHash(sc); +        else if (ch == '$') { +            sc.SetState(SCE_ST_CHARACTER); +            sc.Forward(); +        } +        else if (isSpecial(ch)) +            handleSpecial(sc); +        else if (isDecDigit(ch)) +            handleNumeric(sc); +        else if (isLetter(ch)) +            handleLetter(sc); +        else if (isBinSel(ch)) { +            if (ch == '-' && isDecDigit(sc.chNext)) +                handleNumeric(sc); +            else +                handleBinSel(sc); +        } +        else +            sc.SetState(SCE_ST_DEFAULT); +    } +    sc.Complete(); +} + +LexerModule lmSmalltalk(SCLEX_SMALLTALK, colorizeSmalltalkDoc, "smalltalk"); diff --git a/win32/makefile b/win32/makefile index 258d44140..e1f0f8f4c 100644 --- a/win32/makefile +++ b/win32/makefile @@ -57,8 +57,8 @@ LexCSS.o LexEiffel.o LexErlang.o LexEScript.o LexForth.o LexFortran.o \  LexGui4Cli.o LexHaskell.o LexHTML.o LexKix.o LexLisp.o LexLout.o LexLua.o \  LexMatlab.o LexMetapost.o LexMMIXAL.o LexMPT.o LexMSSQL.o LexNsis.o \  LexOthers.o LexPascal.o LexPB.o LexPerl.o LexPOV.o LexPS.o LexPython.o \ -LexRebol.o LexRuby.o LexScriptol.o LexSpecman.o LexSQL.o LexTADS3.o LexTeX.o \ -LexVB.o LexVerilog.o LexVHDL.o LexYAML.o +LexRebol.o LexRuby.o LexScriptol.o LexSmalltalk.o LexSpecman.o LexSQL.o \ +LexTADS3.o LexTeX.o LexVB.o LexVerilog.o LexVHDL.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 992afa46d..bf2ad07dc 100644 --- a/win32/scintilla.mak +++ b/win32/scintilla.mak @@ -153,6 +153,7 @@ LEXOBJS=\  	$(DIR_O)\LexRebol.obj \  	$(DIR_O)\LexRuby.obj \  	$(DIR_O)\LexScriptol.obj \ +	$(DIR_O)\LexSmalltalk.obj \  	$(DIR_O)\LexSpecman.obj \  	$(DIR_O)\LexSQL.obj \  	$(DIR_O)\LexTADS3.obj \ @@ -358,6 +359,8 @@ $(DIR_O)\LexRuby.obj: ..\src\LexRuby.cxx $(LEX_HEADERS)  $(DIR_O)\LexScriptol.obj: ..\src\LexScriptol.cxx $(LEX_HEADERS) +$(DIR_O)\LexSmalltalk.obj: ..\src\LexSmalltalk.cxx $(LEX_HEADERS) +  $(DIR_O)\LexSpecman.obj: ..\src\LexSpecman.cxx $(LEX_HEADERS)  $(DIR_O)\LexSQL.obj: ..\src\LexSQL.cxx $(LEX_HEADERS) diff --git a/win32/scintilla_vc6.mak b/win32/scintilla_vc6.mak index d9ec30b49..8bf63f319 100644 --- a/win32/scintilla_vc6.mak +++ b/win32/scintilla_vc6.mak @@ -155,6 +155,7 @@ LEXOBJS=\  	$(DIR_O)\LexRebol.obj \  	$(DIR_O)\LexRuby.obj \  	$(DIR_O)\LexScriptol.obj \ +	$(DIR_O)\LexSmalltalk.obj \  	$(DIR_O)\LexSpecman.obj \  	$(DIR_O)\LexSQL.obj \  	$(DIR_O)\LexTADS3.obj \ @@ -360,6 +361,8 @@ $(DIR_O)\LexRuby.obj: ..\src\LexRuby.cxx $(LEX_HEADERS)  $(DIR_O)\LexScriptol.obj: ..\src\LexScriptol.cxx $(LEX_HEADERS) +$(DIR_O)\LexSmalltalk.obj: ..\src\LexSmalltalk.cxx $(LEX_HEADERS) +  $(DIR_O)\LexSpecman.obj: ..\src\LexSpecman.cxx $(LEX_HEADERS)  $(DIR_O)\LexSQL.obj: ..\src\LexSQL.cxx $(LEX_HEADERS) | 
