diff options
| -rw-r--r-- | gtk/makefile | 4 | ||||
| -rw-r--r-- | include/SciLexer.h | 18 | ||||
| -rw-r--r-- | src/LexLua.cxx | 298 | ||||
| -rw-r--r-- | win32/makefile | 4 | ||||
| -rw-r--r-- | win32/makefile_bor | 6 | ||||
| -rw-r--r-- | win32/makefile_vc | 5 | 
6 files changed, 331 insertions, 4 deletions
| diff --git a/gtk/makefile b/gtk/makefile index 27e94b2c4..d1f11ff55 100644 --- a/gtk/makefile +++ b/gtk/makefile @@ -20,7 +20,7 @@ CXXFLAGS= -DGTK -DSCI_LEXER -W -Wall  .cxx.o:  	$(CC) `gtk-config --cflags` $(INCLUDEDIRS) $(CXXFLAGS) -c $< -o $@ -LEXOBJS	=  LexCPP.o LexHTML.o LexOthers.o LexPerl.o LexPython.o LexSQL.o LexVB.o +LEXOBJS	=  LexCPP.o LexHTML.o LexLua.o LexOthers.o LexPerl.o LexPython.o LexSQL.o LexVB.o  # The LEXOBJS have to be treated specially as the functions in them are not called from external code @@ -53,6 +53,8 @@ LexCPP.o: LexCPP.cxx Platform.h PropSet.h Accessor.h KeyWords.h \   Scintilla.h WinDefs.h SciLexer.h  LexHTML.o: LexHTML.cxx Platform.h PropSet.h Accessor.h KeyWords.h \   Scintilla.h WinDefs.h SciLexer.h +LexLua.o: LexLua.cxx Platform.h PropSet.h Accessor.h KeyWords.h \ + Scintilla.h WinDefs.h SciLexer.h  LexOthers.o: LexOthers.cxx Platform.h PropSet.h Accessor.h KeyWords.h \   Scintilla.h WinDefs.h SciLexer.h  LexPerl.o: LexPerl.cxx Platform.h PropSet.h Accessor.h KeyWords.h \ diff --git a/include/SciLexer.h b/include/SciLexer.h index 94e8c7c71..58b11d32b 100644 --- a/include/SciLexer.h +++ b/include/SciLexer.h @@ -23,6 +23,7 @@  #define SCLEX_BATCH 12  #define SCLEX_XCODE 13  #define SCLEX_LATEX 14 +#define SCLEX_LUA 15  // Lexical states for SCLEX_PYTHON  #define SCE_P_DEFAULT 0 @@ -171,7 +172,7 @@  #define SCE_PL_LONGQUOTE 19  #define SCE_PL_BACKTICKS 20  #define SCE_PL_DATASECTION 21 -     +   // Lexical states for SCLEX_LATEX  #define SCE_L_DEFAULT 0  #define SCE_L_COMMAND 1 @@ -179,4 +180,19 @@  #define SCE_L_MATH 3  #define SCE_L_COMMENT 4 +// Lexical states for SCLEX_LUA +#define SCE_LUA_DEFAULT 0 +#define SCE_LUA_COMMENT 1 +#define SCE_LUA_COMMENTLINE 2 +#define SCE_LUA_COMMENTDOC 3 +#define SCE_LUA_NUMBER 4 +#define SCE_LUA_WORD 5 +#define SCE_LUA_STRING 6 +#define SCE_LUA_CHARACTER 7 +#define SCE_LUA_LITERALSTRING 8 +#define SCE_LUA_PREPROCESSOR 9 +#define SCE_LUA_OPERATOR 10 +#define SCE_LUA_IDENTIFIER 11 +#define SCE_LUA_STRINGEOL 12 +  #endif diff --git a/src/LexLua.cxx b/src/LexLua.cxx new file mode 100644 index 000000000..e6da7668d --- /dev/null +++ b/src/LexLua.cxx @@ -0,0 +1,298 @@ +// LexLua.cxx - lexer for Lua language +// Written by Paul Winwood  + +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include <stdarg.h> +#include <stdio.h> +#include <fcntl.h> + +#include "Platform.h" + +#include "PropSet.h" +#include "Accessor.h" +#include "KeyWords.h" +#include "Scintilla.h" +#include "SciLexer.h" + +static void classifyWordLua(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler) +{ +    char s[100]; +    bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.'); +     +    for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) +    { +        s[i] = styler[start + i]; +        s[i + 1] = '\0'; +    } + +    char chAttr = SCE_LUA_IDENTIFIER; +     +    if (wordIsNumber) +        chAttr = SCE_LUA_NUMBER; +    else +    { +        if (keywords.InList(s)) +        { +            chAttr = SCE_LUA_WORD; +        } +    } +    styler.ColourTo(end, chAttr); +} + +static void ColouriseLuaDoc(unsigned int startPos,  +                            int          length,  +                            int          initStyle,  +                            WordList    *keywordlists[], +                            Accessor    &styler) +{ + +    WordList &keywords = *keywordlists[0]; + +    styler.StartAt(startPos); +    styler.GetLine(startPos); + +    int  state = initStyle; +    char chPrev = ' '; +    char chNext = styler[startPos]; +    unsigned int lengthDoc = startPos + length; +    bool firstChar = true; +    int  literalString = 0; + +    styler.StartSegment(startPos); +    for (unsigned int i = startPos; i <= lengthDoc; i++) +    { +        char ch = chNext; +        chNext = styler.SafeGetCharAt(i + 1); + +        if (styler.IsLeadByte(ch)) +        { +            chNext = styler.SafeGetCharAt(i + 2); +            chPrev = ' '; +            i += 1; +            continue; +        } + +        if (state == SCE_LUA_STRINGEOL) +        { +            if (ch != '\r' && ch != '\n') +            { +                styler.ColourTo(i-1, state); +                state = SCE_LUA_DEFAULT; +            } +        } + +        if (state == SCE_LUA_LITERALSTRING && ch == '[' && chNext == '[') +        { +            literalString++; +        } +        else +        if (state == SCE_LUA_DEFAULT) +        { +            if (ch == '-' && chNext == '-') +            { +                styler.ColourTo(i-1, state); +                state = SCE_LUA_COMMENTLINE; +            } +            else +            if (ch == '[' && chNext == '[') +            { +                state = SCE_LUA_LITERALSTRING; +                literalString = 1; +            } +            else +            if (iswordstart(ch)) +            { +                styler.ColourTo(i-1, state); +                state = SCE_LUA_WORD; +            } +            else +            if (ch == '\"') +            { +                styler.ColourTo(i-1, state); +                state = SCE_LUA_STRING; +            } +            else +            if (ch == '\'') +            { +                styler.ColourTo(i-1, state); +                state = SCE_LUA_CHARACTER; +            } +            else +            if (ch == '$' && firstChar) +            { +                styler.ColourTo(i-1, state); +                state = SCE_LUA_PREPROCESSOR; +            } +            else +            if (isoperator(ch)) +            { +                styler.ColourTo(i-1, state); +                styler.ColourTo(i, SCE_LUA_OPERATOR); +            } +        } +        else +        if (state == SCE_LUA_WORD) +        { +            if (!iswordchar(ch)) +            { +                classifyWordLua(styler.GetStartSegment(), i - 1, keywords, styler); +                state = SCE_LUA_DEFAULT; +                if (ch == '[' && chNext == '[') +                { +                    literalString = 1; +                    state = SCE_LUA_LITERALSTRING; +                } +                else +                if (ch == '-' && chNext == '-') +                { +                    state = SCE_LUA_COMMENTLINE; +                } +                else +                if (ch == '\"') +                { +                    state = SCE_LUA_STRING; +                } +                else +                if (ch == '\'') +                { +                    state = SCE_LUA_CHARACTER; +                } +                else +                if (ch == '$' && firstChar) +                { +                    state = SCE_LUA_PREPROCESSOR; +                } +                else +                if (isoperator(ch)) +                { +                    styler.ColourTo(i, SCE_LUA_OPERATOR); +                } +            } +        } +        else +        { +            if (state == SCE_LUA_LITERALSTRING) +            { +                if (ch == ']' && (chPrev == ']') && (--literalString == 0)) +                { +                    styler.ColourTo(i, state); +                    state = SCE_LUA_DEFAULT; +                } +            } +            else +            if (state == SCE_LUA_PREPROCESSOR) +            { +                if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) +                { +                    styler.ColourTo(i-1, state); +                    state = SCE_LUA_DEFAULT; +                } +            } +            else +            if (state == SCE_LUA_COMMENTLINE) +            { +                if (ch == '\r' || ch == '\n') +                { +                    styler.ColourTo(i-1, state); +                    state = SCE_LUA_DEFAULT; +                } +            } +            else +            if (state == SCE_LUA_STRING) +            { +                if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) +                { +                    styler.ColourTo(i-1, state); +                    state = SCE_LUA_STRINGEOL; +                } +                else +                if (ch == '\\') +                { +                    if (chNext == '\"' || chNext == '\\') +                    { +                        i++; +                        ch = chNext; +                        chNext = styler.SafeGetCharAt(i + 1); +                    } +                } +                else +                if (ch == '\"') +                { +                    styler.ColourTo(i, state); +                    state = SCE_LUA_DEFAULT; +                    i++; +                    ch = chNext; +                    chNext = styler.SafeGetCharAt(i + 1); +                } +            } +            else +            if (state == SCE_LUA_CHARACTER) +            { +                if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) +                { +                    styler.ColourTo(i-1, state); +                    state = SCE_LUA_STRINGEOL; +                } +                else +                if (ch == '\\') +                { +                    if (chNext == '\'' || chNext == '\\') +                    { +                        i++; +                        ch = chNext; +                        chNext = styler.SafeGetCharAt(i + 1); +                    } +                } +                else +                if (ch == '\'') +                { +                    styler.ColourTo(i, state); +                    state = SCE_LUA_DEFAULT; +                    i++; +                    ch = chNext; +                    chNext = styler.SafeGetCharAt(i + 1); +                } +            } + +            if (state == SCE_LUA_DEFAULT) +            {     +                if (ch == '-' && chNext == '-') +                { +                    state = SCE_LUA_COMMENTLINE; +                } +                else +                if (ch == '\"') +                { +                    state = SCE_LUA_STRING; +                } +                else +                if (ch == '\'') +                { +                    state = SCE_LUA_CHARACTER; +                } +                else +                if (ch == '$' && firstChar) +                { +                    state = SCE_LUA_PREPROCESSOR; +                } +                else +                if (iswordstart(ch)) +                { +                    state = SCE_LUA_WORD; +                } +                else +                if (isoperator(ch)) +                { +                    styler.ColourTo(i, SCE_LUA_OPERATOR); +                } +            } +        } +        chPrev = ch; +        firstChar = (ch == '\r' || ch == '\n'); +    } +    styler.ColourTo(lengthDoc - 1, state); +} + +LexerModule lmLua(SCLEX_LUA, ColouriseLuaDoc); diff --git a/win32/makefile b/win32/makefile index b7002f7b6..7e3406d99 100644 --- a/win32/makefile +++ b/win32/makefile @@ -28,7 +28,7 @@ ALL:	$(COMPONENT) $(LEXCOMPONENT) ScintillaWinS.o WindowAccessor.o  clean:  	del /q *.exe *.o *.obj *.dll *.res *.map -LEXOBJS	=  LexCPP.o LexHTML.o LexOthers.o LexPerl.o LexPython.o LexSQL.o LexVB.o +LEXOBJS	=  LexCPP.o LexHTML.o LexLua.o LexOthers.o LexPerl.o LexPython.o LexSQL.o LexVB.o  SOBJS	= ScintillaWin.o ScintillaBase.o Editor.o Document.o \  	ContractionState.o CellBuffer.o CallTip.o \ @@ -60,6 +60,8 @@ LexCPP.o: LexCPP.cxx Platform.h PropSet.h Accessor.h KeyWords.h \   Scintilla.h SciLexer.h   LexHTML.o: LexHTML.cxx Platform.h PropSet.h Accessor.h KeyWords.h \   Scintilla.h SciLexer.h  +LexLua.o: LexLua.cxx Platform.h PropSet.h Accessor.h KeyWords.h \ + Scintilla.h SciLexer.h   LexOthers.o: LexOthers.cxx Platform.h PropSet.h Accessor.h KeyWords.h \   Scintilla.h SciLexer.h   LexPerl.o: LexPerl.cxx Platform.h PropSet.h Accessor.h KeyWords.h \ diff --git a/win32/makefile_bor b/win32/makefile_bor index 9f4e948c1..e4790ffe5 100644 --- a/win32/makefile_bor +++ b/win32/makefile_bor @@ -35,7 +35,7 @@ SOBJS	= ScintillaWin.obj ScintillaBase.obj Editor.obj Document.obj \  $(COMPONENT): $(SOBJS) ScintRes.res  	$(LD) -Tpd /c c0d32 $(SOBJS), $@, ,$(LDFLAGS), , ScintRes.res -LEXOBJS	= LexCPP.obj LexHTML.obj LexOthers.obj LexPerl.obj LexPython.obj LexSQL.obj LexVB.obj +LEXOBJS	= LexCPP.obj LexHTML.obj LexLua.obj LexOthers.obj LexPerl.obj LexPython.obj LexSQL.obj LexVB.obj  LOBJS	= ScintillaWinL.obj ScintillaBaseL.obj Editor.obj Document.obj \  	ContractionState.obj CellBuffer.obj CallTip.obj \ @@ -86,6 +86,10 @@ LexHTML.obj: ..\src\LexHTML.cxx ..\include\Platform.h ..\include\PropSet.h ..\in   ..\include\Scintilla.h ..\include\SciLexer.h   	$(CC) $(INCLUDEDIRS) $(CXXFLAGS) -c ..\src\$*.cxx -o$@ +LexLua.obj: ..\src\LexLua.cxx ..\include\Platform.h ..\include\PropSet.h ..\include\Accessor.h ..\include\KeyWords.h \ + ..\include\Scintilla.h ..\include\SciLexer.h  +	$(CC) $(INCLUDEDIRS) $(CXXFLAGS) -c ..\src\$*.cxx -o$@ +   LexOthers.obj: ..\src\LexOthers.cxx ..\include\Platform.h ..\include\PropSet.h ..\include\Accessor.h ..\include\KeyWords.h \   ..\include\Scintilla.h ..\include\SciLexer.h   	$(CC) $(INCLUDEDIRS) $(CXXFLAGS) -c ..\src\$*.cxx -o$@ diff --git a/win32/makefile_vc b/win32/makefile_vc index e4929b003..51f2bedd7 100644 --- a/win32/makefile_vc +++ b/win32/makefile_vc @@ -46,6 +46,7 @@ SOBJS	= $(DIR_O)\ScintillaWin.obj $(DIR_O)\ScintillaBase.obj \  LEXOBJS	= $(DIR_O)\LexCPP.obj \  	$(DIR_O)\LexHTML.obj \ +	$(DIR_O)\LexLua.obj \  	$(DIR_O)\LexOthers.obj \  	$(DIR_O)\LexPerl.obj \  	$(DIR_O)\LexPython.obj \ @@ -112,6 +113,10 @@ $(DIR_O)\LexHTML.obj: ..\src\LexHTML.cxx ..\include\Platform.h ..\include\PropSe   ..\include\Scintilla.h ..\include\SciLexer.h   	$(CC) $(INCLUDEDIRS) $(CXXFLAGS) /Fo$@ /c ..\src\$(@B).cxx +$(DIR_O)\LexLua.obj: ..\src\LexLua.cxx ..\include\Platform.h ..\include\PropSet.h ..\include\Accessor.h ..\include\KeyWords.h \ + ..\include\Scintilla.h ..\include\SciLexer.h  +	$(CC) $(INCLUDEDIRS) $(CXXFLAGS) /Fo$@ /c ..\src\$(@B).cxx +   $(DIR_O)\LexOthers.obj: ..\src\LexOthers.cxx ..\include\Platform.h ..\include\PropSet.h ..\include\Accessor.h ..\include\KeyWords.h \   ..\include\Scintilla.h ..\include\SciLexer.h   	$(CC) $(INCLUDEDIRS) $(CXXFLAGS) /Fo$@ /c ..\src\$(@B).cxx | 
