aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--doc/ScintillaHistory.html5
-rw-r--r--include/SciLexer.h12
-rw-r--r--include/Scintilla.iface14
-rw-r--r--lexers/LexDMAP.cxx228
-rw-r--r--src/Catalogue.cxx1
-rw-r--r--win32/scintilla.mak3
6 files changed, 263 insertions, 0 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 16dbfbbb9..4bee589d3 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -434,6 +434,7 @@
<td>SiegeLord</td>
<td>Erik</td>
<td>TJF</td>
+ <td>Mark Robinson</td>
</tr>
</table>
<p>
@@ -453,6 +454,10 @@
Released 15 October 2013.
</li>
<li>
+ Lexer added for DMAP language.
+ <a href="http://sourceforge.net/p/scintilla/feature-requests/1026/">Feature #1026.</a>
+ </li>
+ <li>
Basic lexer supports multiline comments in FreeBASIC.
<a href="http://sourceforge.net/p/scintilla/feature-requests/1023/">Feature #1023.</a>
</li>
diff --git a/include/SciLexer.h b/include/SciLexer.h
index 5edbc620c..957509d1e 100644
--- a/include/SciLexer.h
+++ b/include/SciLexer.h
@@ -124,6 +124,7 @@
#define SCLEX_STTXT 109
#define SCLEX_KVIRC 110
#define SCLEX_RUST 111
+#define SCLEX_DMAP 112
#define SCLEX_AUTOMATIC 1000
#define SCE_P_DEFAULT 0
#define SCE_P_COMMENTLINE 1
@@ -1687,6 +1688,17 @@
#define SCE_RUST_LIFETIME 18
#define SCE_RUST_MACRO 19
#define SCE_RUST_LEXERROR 20
+#define SCE_DMAP_DEFAULT 0
+#define SCE_DMAP_COMMENT 1
+#define SCE_DMAP_NUMBER 2
+#define SCE_DMAP_STRING1 3
+#define SCE_DMAP_STRING2 4
+#define SCE_DMAP_STRINGEOL 5
+#define SCE_DMAP_OPERATOR 6
+#define SCE_DMAP_IDENTIFIER 7
+#define SCE_DMAP_WORD 8
+#define SCE_DMAP_WORD2 9
+#define SCE_DMAP_WORD3 10
/* --Autogenerated -- end of section automatically generated from Scintilla.iface */
#endif
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index d23e18020..a94e490d8 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -2601,6 +2601,7 @@ val SCLEX_LITERATEHASKELL=108
val SCLEX_STTXT=109
val SCLEX_KVIRC=110
val SCLEX_RUST=111
+val SCLEX_DMAP=112
# When a lexer specifies its language as SCLEX_AUTOMATIC it receives a
# value assigned in sequence from SCLEX_AUTOMATIC+1.
@@ -4368,6 +4369,19 @@ val SCE_RUST_IDENTIFIER=17
val SCE_RUST_LIFETIME=18
val SCE_RUST_MACRO=19
val SCE_RUST_LEXERROR=20
+# Lexical states for SCLEX_DMAP
+lex DMAP=SCLEX_DMAP SCE_DMAP_
+val SCE_DMAP_DEFAULT=0
+val SCE_DMAP_COMMENT=1
+val SCE_DMAP_NUMBER=2
+val SCE_DMAP_STRING1=3
+val SCE_DMAP_STRING2=4
+val SCE_DMAP_STRINGEOL=5
+val SCE_DMAP_OPERATOR=6
+val SCE_DMAP_IDENTIFIER=7
+val SCE_DMAP_WORD=8
+val SCE_DMAP_WORD2=9
+val SCE_DMAP_WORD3=10
# Events
diff --git a/lexers/LexDMAP.cxx b/lexers/LexDMAP.cxx
new file mode 100644
index 000000000..431000a4e
--- /dev/null
+++ b/lexers/LexDMAP.cxx
@@ -0,0 +1,228 @@
+// Scintilla source code edit control
+/** @file LexDMAP.cxx
+ ** Lexer for MSC Nastran DMAP.
+ ** Written by Mark Robinson, based on the Fortran lexer by Chuan-jian Shen, Last changed Aug. 2013
+ **/
+// Copyright 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 <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"
+/***************************************/
+
+#ifdef SCI_NAMESPACE
+using namespace Scintilla;
+#endif
+
+/***********************************************/
+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));
+}
+/***************************************/
+static void ColouriseDMAPDoc(unsigned int startPos, int length, int initStyle,
+ WordList *keywordlists[], Accessor &styler) {
+ WordList &keywords = *keywordlists[0];
+ WordList &keywords2 = *keywordlists[1];
+ WordList &keywords3 = *keywordlists[2];
+ /***************************************/
+ int posLineStart = 0, numNonBlank = 0;
+ int endPos = startPos + length;
+ /***************************************/
+ // backtrack to the nearest keyword
+ while ((startPos > 1) && (styler.StyleAt(startPos) != SCE_DMAP_WORD)) {
+ startPos--;
+ }
+ startPos = styler.LineStart(styler.GetLine(startPos));
+ initStyle = styler.StyleAt(startPos - 1);
+ StyleContext sc(startPos, endPos-startPos, initStyle, styler);
+ /***************************************/
+ for (; sc.More(); sc.Forward()) {
+ // remember the start position of the line
+ if (sc.atLineStart) {
+ posLineStart = sc.currentPos;
+ numNonBlank = 0;
+ sc.SetState(SCE_DMAP_DEFAULT);
+ }
+ if (!IsASpaceOrTab(sc.ch)) numNonBlank ++;
+ /***********************************************/
+ // Handle data appearing after column 72; it is ignored
+ int toLineStart = sc.currentPos - posLineStart;
+ if (toLineStart >= 72 || sc.ch == '$') {
+ sc.SetState(SCE_DMAP_COMMENT);
+ while (!sc.atLineEnd && sc.More()) sc.Forward(); // Until line end
+ continue;
+ }
+ /***************************************/
+ // Determine if the current state should terminate.
+ if (sc.state == SCE_DMAP_OPERATOR) {
+ sc.SetState(SCE_DMAP_DEFAULT);
+ } else if (sc.state == SCE_DMAP_NUMBER) {
+ if (!(IsAWordChar(sc.ch) || sc.ch=='\'' || sc.ch=='\"' || sc.ch=='.')) {
+ sc.SetState(SCE_DMAP_DEFAULT);
+ }
+ } else if (sc.state == SCE_DMAP_IDENTIFIER) {
+ if (!IsAWordChar(sc.ch) || (sc.ch == '%')) {
+ char s[100];
+ sc.GetCurrentLowered(s, sizeof(s));
+ if (keywords.InList(s)) {
+ sc.ChangeState(SCE_DMAP_WORD);
+ } else if (keywords2.InList(s)) {
+ sc.ChangeState(SCE_DMAP_WORD2);
+ } else if (keywords3.InList(s)) {
+ sc.ChangeState(SCE_DMAP_WORD3);
+ }
+ sc.SetState(SCE_DMAP_DEFAULT);
+ }
+ } else if (sc.state == SCE_DMAP_COMMENT) {
+ if (sc.ch == '\r' || sc.ch == '\n') {
+ sc.SetState(SCE_DMAP_DEFAULT);
+ }
+ } else if (sc.state == SCE_DMAP_STRING1) {
+ if (sc.ch == '\'') {
+ if (sc.chNext == '\'') {
+ sc.Forward();
+ } else {
+ sc.ForwardSetState(SCE_DMAP_DEFAULT);
+ }
+ } else if (sc.atLineEnd) {
+ sc.ChangeState(SCE_DMAP_STRINGEOL);
+ sc.ForwardSetState(SCE_DMAP_DEFAULT);
+ }
+ } else if (sc.state == SCE_DMAP_STRING2) {
+ if (sc.atLineEnd) {
+ sc.ChangeState(SCE_DMAP_STRINGEOL);
+ sc.ForwardSetState(SCE_DMAP_DEFAULT);
+ } else if (sc.ch == '\"') {
+ if (sc.chNext == '\"') {
+ sc.Forward();
+ } else {
+ sc.ForwardSetState(SCE_DMAP_DEFAULT);
+ }
+ }
+ }
+ /***************************************/
+ // Determine if a new state should be entered.
+ if (sc.state == SCE_DMAP_DEFAULT) {
+ if (sc.ch == '$') {
+ sc.SetState(SCE_DMAP_COMMENT);
+ } else if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext)) || (sc.ch == '-' && IsADigit(sc.chNext))) {
+ sc.SetState(SCE_F_NUMBER);
+ } else if (IsAWordStart(sc.ch)) {
+ sc.SetState(SCE_DMAP_IDENTIFIER);
+ } else if (sc.ch == '\"') {
+ sc.SetState(SCE_DMAP_STRING2);
+ } else if (sc.ch == '\'') {
+ sc.SetState(SCE_DMAP_STRING1);
+ } else if (isoperator(static_cast<char>(sc.ch))) {
+ sc.SetState(SCE_DMAP_OPERATOR);
+ }
+ }
+ }
+ sc.Complete();
+}
+/***************************************/
+// To determine the folding level depending on keywords
+static int classifyFoldPointDMAP(const char* s, const char* prevWord) {
+ int lev = 0;
+ if ((strcmp(prevWord, "else") == 0 && strcmp(s, "if") == 0) || strcmp(s, "enddo") == 0 || strcmp(s, "endif") == 0) {
+ lev = -1;
+ } else if ((strcmp(prevWord, "do") == 0 && strcmp(s, "while") == 0) || strcmp(s, "then") == 0) {
+ lev = 1;
+ }
+ return lev;
+}
+// Folding the code
+static void FoldDMAPDoc(unsigned int startPos, int length, int initStyle,
+ WordList *[], Accessor &styler) {
+ //
+ // bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
+ // Do not know how to fold the comment at the moment.
+ //
+ bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
+ unsigned int endPos = startPos + length;
+ int visibleChars = 0;
+ int lineCurrent = styler.GetLine(startPos);
+ int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
+ int levelCurrent = levelPrev;
+ char chNext = styler[startPos];
+ int styleNext = styler.StyleAt(startPos);
+ int style = initStyle;
+ /***************************************/
+ int lastStart = 0;
+ char prevWord[32] = "";
+ /***************************************/
+ for (unsigned int i = startPos; i < endPos; i++) {
+ char ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ int stylePrev = style;
+ style = styleNext;
+ styleNext = styler.StyleAt(i + 1);
+ bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
+ //
+ if ((stylePrev == SCE_DMAP_DEFAULT || stylePrev == SCE_DMAP_OPERATOR || stylePrev == SCE_DMAP_COMMENT) && (style == SCE_DMAP_WORD)) {
+ // Store last word and label start point.
+ lastStart = i;
+ }
+ /***************************************/
+ if (style == SCE_DMAP_WORD) {
+ if(iswordchar(ch) && !iswordchar(chNext)) {
+ char s[32];
+ unsigned int k;
+ for(k=0; (k<31 ) && (k<i-lastStart+1 ); k++) {
+ s[k] = static_cast<char>(tolower(styler[lastStart+k]));
+ }
+ s[k] = '\0';
+ levelCurrent += classifyFoldPointDMAP(s, prevWord);
+ strcpy(prevWord, s);
+ }
+ }
+ if (atEOL) {
+ int lev = levelPrev;
+ if (visibleChars == 0 && foldCompact)
+ lev |= SC_FOLDLEVELWHITEFLAG;
+ if ((levelCurrent > levelPrev) && (visibleChars > 0))
+ lev |= SC_FOLDLEVELHEADERFLAG;
+ if (lev != styler.LevelAt(lineCurrent)) {
+ styler.SetLevel(lineCurrent, lev);
+ }
+ lineCurrent++;
+ levelPrev = levelCurrent;
+ visibleChars = 0;
+ strcpy(prevWord, "");
+ }
+ /***************************************/
+ if (!isspacechar(ch)) visibleChars++;
+ }
+ /***************************************/
+ // Fill in the real level of the next line, keeping the current flags as they will be filled in later
+ int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
+ styler.SetLevel(lineCurrent, levelPrev | flagsNext);
+}
+/***************************************/
+static const char * const DMAPWordLists[] = {
+ "Primary keywords and identifiers",
+ "Intrinsic functions",
+ "Extended and user defined functions",
+ 0,
+};
+/***************************************/
+LexerModule lmDMAP(SCLEX_DMAP, ColouriseDMAPDoc, "DMAP", FoldDMAPDoc, DMAPWordLists);
diff --git a/src/Catalogue.cxx b/src/Catalogue.cxx
index e728f3480..b7f816d76 100644
--- a/src/Catalogue.cxx
+++ b/src/Catalogue.cxx
@@ -104,6 +104,7 @@ int Scintilla_LinkLexers() {
LINK_LEXER(lmCss);
LINK_LEXER(lmD);
LINK_LEXER(lmDiff);
+ LINK_LEXER(lmDMAP);
LINK_LEXER(lmECL);
LINK_LEXER(lmEiffel);
LINK_LEXER(lmEiffelkw);
diff --git a/win32/scintilla.mak b/win32/scintilla.mak
index 56dc20b7c..d9b0be80e 100644
--- a/win32/scintilla.mak
+++ b/win32/scintilla.mak
@@ -115,6 +115,7 @@ LEXOBJS=\
$(DIR_O)\LexCsound.obj \
$(DIR_O)\LexCSS.obj \
$(DIR_O)\LexD.obj \
+ $(DIR_O)\LexDMAP.obj \
$(DIR_O)\LexECL.obj \
$(DIR_O)\LexEiffel.obj \
$(DIR_O)\LexErlang.obj \
@@ -366,6 +367,8 @@ $(DIR_O)\LexCSS.obj: ..\lexers\LexCSS.cxx $(LEX_HEADERS)
$(DIR_O)\LexD.obj: ..\lexers\LexD.cxx $(LEX_HEADERS)
+$(DIR_O)\LexDMAP.obj: ..\lexers\LexDMAP.cxx $(LEX_HEADERS)
+
$(DIR_O)\LexECL.obj: ..\lexers\LexECL.cxx $(LEX_HEADERS)
$(DIR_O)\LexEiffel.obj: ..\lexers\LexEiffel.cxx $(LEX_HEADERS)