diff options
author | Gunter Königsmann <unknown> | 2018-03-06 15:52:23 +1100 |
---|---|---|
committer | Gunter Königsmann <unknown> | 2018-03-06 15:52:23 +1100 |
commit | bb59ac2319ce5229d021c4a0496b1931ad4684c3 (patch) | |
tree | 84b538c5e11d26d69db56ea5ca7f988dd2c4c43a | |
parent | 1645601aa99664c9fecb98a1a46aacfb660a936b (diff) | |
download | scintilla-mirror-bb59ac2319ce5229d021c4a0496b1931ad4684c3.tar.gz |
Backport: Feature [feature-requests:#1210]. Maxima lexer added.
Backport of changeset 6474:7a2aeece58b6.
-rw-r--r-- | cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj | 4 | ||||
-rw-r--r-- | doc/ScintillaHistory.html | 5 | ||||
-rw-r--r-- | gtk/deps.mak | 5 | ||||
-rw-r--r-- | include/SciLexer.h | 9 | ||||
-rw-r--r-- | include/Scintilla.iface | 11 | ||||
-rw-r--r-- | lexers/LexMaxima.cxx | 214 | ||||
-rw-r--r-- | src/Catalogue.cxx | 1 | ||||
-rw-r--r-- | win32/deps.mak | 5 | ||||
-rw-r--r-- | win32/scintilla.mak | 3 |
9 files changed, 257 insertions, 0 deletions
diff --git a/cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj b/cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj index 4dde074ef..3578bda9c 100644 --- a/cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj +++ b/cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj @@ -229,6 +229,7 @@ 8DC2EF570486A6940098B216 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */; }; F437405F9F32C7DEFCA38C11 /* LexIndent.cxx in Sources */ = {isa = PBXBuildFile; fileRef = 282E41F3B9E2BFEDD6A05BE7 /* LexIndent.cxx */; }; 4D0C4365AB6DF998CD48B1FC /* LexLPeg.cxx in Sources */ = {isa = PBXBuildFile; fileRef = 5EB3467789767C0ACE40A46A /* LexLPeg.cxx */; }; + 3D994BD7A5EAC4FA5B3CFBDF /* LexMaxima.cxx in Sources */ = {isa = PBXBuildFile; fileRef = 29B042978C1F93EF42F9E4AB /* LexMaxima.cxx */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -459,6 +460,7 @@ D2F7E79907B2D74100F64583 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; }; 282E41F3B9E2BFEDD6A05BE7 /* LexIndent.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LexIndent.cxx; path = ../../lexers/LexIndent.cxx; sourceTree = SOURCE_ROOT; }; 5EB3467789767C0ACE40A46A /* LexLPeg.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LexLPeg.cxx; path = ../../lexers/LexLPeg.cxx; sourceTree = SOURCE_ROOT; }; + 29B042978C1F93EF42F9E4AB /* LexMaxima.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LexMaxima.cxx; path = ../../lexers/LexMaxima.cxx; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -614,6 +616,7 @@ 28B647091B54C0720009DC49 /* LexMake.cxx */, 114B6EE411FA7526004FB6AB /* LexMarkdown.cxx */, 114B6EE511FA7526004FB6AB /* LexMatlab.cxx */, + 29B042978C1F93EF42F9E4AB /* LexMaxima.cxx */, 114B6EE611FA7526004FB6AB /* LexMetapost.cxx */, 114B6EE711FA7526004FB6AB /* LexMMIXAL.cxx */, 11BB124C12FF9C1300F6BCF7 /* LexModula.cxx */, @@ -1116,6 +1119,7 @@ 11FF3FE21810EB3900E13F13 /* LexDMAP.cxx in Sources */, F437405F9F32C7DEFCA38C11 /* LexIndent.cxx in Sources */, 4D0C4365AB6DF998CD48B1FC /* LexLPeg.cxx in Sources */, + 3D994BD7A5EAC4FA5B3CFBDF /* LexMaxima.cxx in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 92a525eeb..61f6680d9 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -519,6 +519,7 @@ </tr><tr> <td>Georger Araújo</td> <td>Dimitar Radev</td> + <td>Gunter Königsmann</td> </tr> </table> <p> @@ -592,6 +593,10 @@ Fix move-extends-selection mode for rectangular and line selections. </li> <li> + Lexer added for the Maxima computer algebra language. + <a href="http://sourceforge.net/p/scintilla/feature-requests/1210/">Feature #1210.</a> + </li> + <li> Fix hang in Lua lexer when lexing a label upto the terminating "::". <a href="http://sourceforge.net/p/scintilla/bugs/1999/">Bug #1999</a>. </li> diff --git a/gtk/deps.mak b/gtk/deps.mak index a5540180d..a472b5151 100644 --- a/gtk/deps.mak +++ b/gtk/deps.mak @@ -480,6 +480,11 @@ LexMatlab.o: ../lexers/LexMatlab.cxx ../include/ILexer.h \ ../lexlib/WordList.h ../lexlib/LexAccessor.h ../lexlib/Accessor.h \ ../lexlib/StyleContext.h ../lexlib/CharacterSet.h \ ../lexlib/LexerModule.h +LexMaxima.o: ../lexers/LexMaxima.cxx ../include/ILexer.h \ + ../include/Sci_Position.h ../include/Scintilla.h ../include/SciLexer.h \ + ../lexlib/WordList.h ../lexlib/LexAccessor.h ../lexlib/Accessor.h \ + ../lexlib/StyleContext.h ../lexlib/CharacterSet.h \ + ../lexlib/LexerModule.h LexMetapost.o: ../lexers/LexMetapost.cxx ../include/ILexer.h \ ../include/Sci_Position.h ../include/Scintilla.h ../include/SciLexer.h \ ../lexlib/WordList.h ../lexlib/LexAccessor.h ../lexlib/Accessor.h \ diff --git a/include/SciLexer.h b/include/SciLexer.h index 70fdb97f8..8772d8cb1 100644 --- a/include/SciLexer.h +++ b/include/SciLexer.h @@ -135,6 +135,7 @@ #define SCLEX_JSON 120 #define SCLEX_EDIFACT 121 #define SCLEX_INDENT 122 +#define SCLEX_MAXIMA 123 #define SCLEX_LPEG 999 #define SCLEX_AUTOMATIC 1000 #define SCE_P_DEFAULT 0 @@ -673,6 +674,14 @@ #define SCE_MATLAB_OPERATOR 6 #define SCE_MATLAB_IDENTIFIER 7 #define SCE_MATLAB_DOUBLEQUOTESTRING 8 +#define SCE_MAXIMA_OPERATOR 0 +#define SCE_MAXIMA_COMMANDENDING 1 +#define SCE_MAXIMA_COMMENT 2 +#define SCE_MAXIMA_NUMBER 3 +#define SCE_MAXIMA_STRING 4 +#define SCE_MAXIMA_COMMAND 5 +#define SCE_MAXIMA_VARIABLE 6 +#define SCE_MAXIMA_UNKNOWN 7 #define SCE_SCRIPTOL_DEFAULT 0 #define SCE_SCRIPTOL_WHITE 1 #define SCE_SCRIPTOL_COMMENTLINE 2 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 3eb4a5439..d2bca177c 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -2928,6 +2928,7 @@ val SCLEX_TEHEX=119 val SCLEX_JSON=120 val SCLEX_EDIFACT=121 val SCLEX_INDENT=122 +val SCLEX_MAXIMA=123 val SCLEX_LPEG=999 # When a lexer specifies its language as SCLEX_AUTOMATIC it receives a @@ -3548,6 +3549,16 @@ val SCE_MATLAB_STRING=5 val SCE_MATLAB_OPERATOR=6 val SCE_MATLAB_IDENTIFIER=7 val SCE_MATLAB_DOUBLEQUOTESTRING=8 +# Lexical states for SCLEX_MAXIMA +lex Maxima=SCLEX_MAXIMA SCE_MAXIMA_ +val SCE_MAXIMA_OPERATOR=0 +val SCE_MAXIMA_COMMANDENDING=1 +val SCE_MAXIMA_COMMENT=2 +val SCE_MAXIMA_NUMBER=3 +val SCE_MAXIMA_STRING=4 +val SCE_MAXIMA_COMMAND=5 +val SCE_MAXIMA_VARIABLE=6 +val SCE_MAXIMA_UNKNOWN=7 # Lexical states for SCLEX_SCRIPTOL lex Sol=SCLEX_SCRIPTOL SCE_SCRIPTOL_ val SCE_SCRIPTOL_DEFAULT=0 diff --git a/lexers/LexMaxima.cxx b/lexers/LexMaxima.cxx new file mode 100644 index 000000000..4dcfa5208 --- /dev/null +++ b/lexers/LexMaxima.cxx @@ -0,0 +1,214 @@ +// Scintilla source code edit control +/** @file LexMaxima.cxx + ** Lexer for Maxima (http://maxima.sourceforge.net). + ** Written by Gunter Königsmann based on the lisp lexer by Alexey Yutkin and Neil Hodgson . + **/ +// Copyright 2018 by Gunter Königsmann <wxMaxima@physikbuch.de> +// The License.txt file describes the conditions under which this software may be distributed. + +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <stdarg.h> +#include <assert.h> +#include <ctype.h> + +#include "ILexer.h" +#include "Scintilla.h" +#include "SciLexer.h" + +#include "WordList.h" +#include "LexAccessor.h" +#include "Accessor.h" +#include "StyleContext.h" +#include "CharacterSet.h" +#include "LexerModule.h" +using namespace Scintilla; + +static inline bool isMaximaoperator(char ch) { + return (ch == '\'' || ch == '`' || ch == '(' || + ch == ')' || ch == '[' || ch == ']' || + ch == '{' || ch == '}' || ch == '!' || + ch == '*' || ch == '/' || ch == '^' || + ch == ',' || ch == ':' || ch == '+' || + ch == '-'); +} + +static void ColouriseMaximaDoc(Sci_PositionU startPos, Sci_Position length, int, + WordList *[], + Accessor &styler) { + + styler.StartAt(startPos); + + char chNext = styler[startPos]; + Sci_PositionU lengthDoc = startPos + length; + styler.StartSegment(startPos); + for (Sci_PositionU i = startPos; i < lengthDoc; i++) { + char ch = styler.SafeGetCharAt(i); + chNext = styler.SafeGetCharAt(i + 1); + + if (styler.IsLeadByte(ch)) + continue; + + // Handle comments. + // Comments start with /* and end with */ + if((ch == '/') && (chNext == '*')) + { + i++;i++; + + chNext = styler.SafeGetCharAt(i); + for (; i < lengthDoc; i++) + { + ch = chNext; + chNext = styler.SafeGetCharAt(i + 1); + if((ch == '*') && (chNext == '/')) + { + i++; + i++; + break; + } + } + if(i > lengthDoc) + i = lengthDoc; + i--; + styler.ColourTo(i, SCE_MAXIMA_COMMENT); + continue; + } + + // Handle Operators + if(isMaximaoperator(ch)) + { + styler.ColourTo(i, SCE_MAXIMA_OPERATOR); + continue; + } + + // Handle command endings. + if((ch == '$') || (ch == ';')) + { + styler.ColourTo(i, SCE_MAXIMA_COMMANDENDING); + continue; + } + + // Handle numbers. Numbers always begin with a digit. + if(IsASCII(ch) && isdigit(ch)) + { + i++; + for (; i < lengthDoc; i++) + { + ch = chNext; + chNext = styler.SafeGetCharAt(i + 1); + + if(ch == '.') + continue; + + // A "e" or similar can be followed by a "+" or a "-" + if(((ch == 'e') || (ch == 'b') || (ch == 'g') || (ch == 'f')) && + ((chNext == '+') || (chNext == '-'))) + { + i++; + chNext = styler.SafeGetCharAt(i + 1); + continue; + } + + if(!IsASCII(ch) || !(isdigit(ch) || islower(ch) || isupper(ch))) + { + i--; + break; + } + } + styler.ColourTo(i, SCE_MAXIMA_NUMBER); + continue; + } + + // Handle strings + if(ch == '\"') + { + i++; + for (; i < lengthDoc; i++) + { + ch = chNext; + chNext = styler.SafeGetCharAt(i + 1); + if(ch == '\\') + i++; + else + { + if(ch == '\"') + break; + } + } + styler.ColourTo(i, SCE_MAXIMA_STRING); + continue; + } + + // Handle keywords. Maxima treats Non-ASCII chars as ordinary letters. + if(((!IsASCII(ch))) || isalpha(ch)) + { + char cmd[100]; + int cmdidx = 0; + memset(cmd,0,100); + cmd[cmdidx++] = ch; + i++; + for (; i < lengthDoc; i++) + { + ch = chNext; + chNext = styler.SafeGetCharAt(i + 1); + if(ch == '\\') + { + if(cmdidx < 99) + cmd[cmdidx++] = ch; + i++; + if(cmdidx < 99) + cmd[cmdidx++] = ch; + continue; + } + if(isMaximaoperator(ch) || ((IsASCII(ch) && !isalpha(ch) && !isdigit(ch)))) + { + i--; + break; + } + if(cmdidx < 99) + cmd[cmdidx++] = ch; + } + + // A few known keywords + if( + (strncmp(cmd,"if",99) == 0) || + (strncmp(cmd,"then",99) == 0) || + (strncmp(cmd,"else",99) == 0) || + (strncmp(cmd,"thru",99) == 0) || + (strncmp(cmd,"for",99) == 0) || + (strncmp(cmd,"while",99) == 0) || + (strncmp(cmd,"do",99) == 0) + ) + { + styler.ColourTo(i, SCE_MAXIMA_COMMAND); + chNext = styler.SafeGetCharAt(i + 1); + continue; + } + + // All other keywords are functions if they are followed + // by an opening parenthesis + char nextNonwhitespace = ' '; + for (Sci_PositionU o = i + 1; o < lengthDoc; o++) + { + nextNonwhitespace = styler.SafeGetCharAt(o); + if(!IsASCII(ch) || !isspacechar(nextNonwhitespace)) + break; + } + if(nextNonwhitespace == '(') + { + styler.ColourTo(i, SCE_MAXIMA_COMMAND); + } + else + { + styler.ColourTo(i, SCE_MAXIMA_VARIABLE); + } + chNext = styler.SafeGetCharAt(i + 1); + continue; + } + + styler.ColourTo(i-1, SCE_MAXIMA_UNKNOWN); + } +} + +LexerModule lmMaxima(SCLEX_MAXIMA, ColouriseMaximaDoc, "maxima", 0, 0); diff --git a/src/Catalogue.cxx b/src/Catalogue.cxx index be1a7395f..3f75096ad 100644 --- a/src/Catalogue.cxx +++ b/src/Catalogue.cxx @@ -135,6 +135,7 @@ int Scintilla_LinkLexers() { LINK_LEXER(lmMake); LINK_LEXER(lmMarkdown); LINK_LEXER(lmMatlab); + LINK_LEXER(lmMaxima); LINK_LEXER(lmMETAPOST); LINK_LEXER(lmMMIXAL); LINK_LEXER(lmModula); diff --git a/win32/deps.mak b/win32/deps.mak index 4b0dff17e..547406db9 100644 --- a/win32/deps.mak +++ b/win32/deps.mak @@ -449,6 +449,11 @@ LexMatlab.o: ../lexers/LexMatlab.cxx ../include/ILexer.h \ ../lexlib/WordList.h ../lexlib/LexAccessor.h ../lexlib/Accessor.h \ ../lexlib/StyleContext.h ../lexlib/CharacterSet.h \ ../lexlib/LexerModule.h +LexMaxima.o: ../lexers/LexMaxima.cxx ../include/ILexer.h \ + ../include/Sci_Position.h ../include/Scintilla.h ../include/SciLexer.h \ + ../lexlib/WordList.h ../lexlib/LexAccessor.h ../lexlib/Accessor.h \ + ../lexlib/StyleContext.h ../lexlib/CharacterSet.h \ + ../lexlib/LexerModule.h LexMetapost.o: ../lexers/LexMetapost.cxx ../include/ILexer.h \ ../include/Sci_Position.h ../include/Scintilla.h ../include/SciLexer.h \ ../lexlib/WordList.h ../lexlib/LexAccessor.h ../lexlib/Accessor.h \ diff --git a/win32/scintilla.mak b/win32/scintilla.mak index d3b6caf41..1aa648e8c 100644 --- a/win32/scintilla.mak +++ b/win32/scintilla.mak @@ -164,6 +164,7 @@ LEXOBJS=\ $(DIR_O)\LexMake.obj \ $(DIR_O)\LexMarkdown.obj \ $(DIR_O)\LexMatlab.obj \ + $(DIR_O)\LexMaxima.obj \ $(DIR_O)\LexMetapost.obj \ $(DIR_O)\LexMMIXAL.obj \ $(DIR_O)\LexModula.obj \ @@ -622,6 +623,8 @@ $(DIR_O)\LexMarkdown.obj: ..\lexers\LexMarkdown.cxx $(LEX_HEADERS) $(DIR_O)\LexMatlab.obj: ..\lexers\LexMatlab.cxx $(LEX_HEADERS) +$(DIR_O)\LexMaxima.obj: ..\lexers\LexMaxima.cxx $(LEX_HEADERS) + $(DIR_O)\LexMetapost.obj: ..\lexers\LexMetapost.cxx $(LEX_HEADERS) $(DIR_O)\LexMMIXAL.obj: ..\lexers\LexMMIXAL.cxx $(LEX_HEADERS) |