aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj4
-rw-r--r--doc/ScintillaHistory.html5
-rw-r--r--gtk/deps.mak12
-rw-r--r--include/SciLexer.h16
-rw-r--r--include/Scintilla.iface18
-rw-r--r--lexers/LexDataflex.cxx608
-rw-r--r--src/Catalogue.cxx1
-rw-r--r--win32/deps.mak12
-rw-r--r--win32/nmdeps.mak12
-rw-r--r--win32/scintilla.mak1
10 files changed, 689 insertions, 0 deletions
diff --git a/cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj b/cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj
index 9e8af0da3..9a19e7067 100644
--- a/cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj
+++ b/cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj
@@ -233,6 +233,7 @@
F437405F9F32C7DEFCA38C11 /* LexIndent.cxx in Sources */ = {isa = PBXBuildFile; fileRef = 282E41F3B9E2BFEDD6A05BE7 /* LexIndent.cxx */; };
FDC7442CAD70B9A67EF1639D /* LexSAS.cxx in Sources */ = {isa = PBXBuildFile; fileRef = A95147A1AB7CADB00DAFE724 /* LexSAS.cxx */; };
AE894E1CB7328CAE5B2EF47E /* LexX12.cxx in Sources */ = {isa = PBXBuildFile; fileRef = ADA64364A443F3E3F02D294E /* LexX12.cxx */; };
+ 902B40FE926FE48538B168F1 /* LexDataflex.cxx in Sources */ = {isa = PBXBuildFile; fileRef = 362E48F5A7F79598CB0B037D /* LexDataflex.cxx */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -469,6 +470,7 @@
A95147A1AB7CADB00DAFE724 /* LexSAS.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LexSAS.cxx; path = ../../lexers/LexSAS.cxx; sourceTree = SOURCE_ROOT; };
D2F7E79907B2D74100F64583 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
ADA64364A443F3E3F02D294E /* LexX12.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LexX12.cxx; path = ../../lexers/LexX12.cxx; sourceTree = SOURCE_ROOT; };
+ 362E48F5A7F79598CB0B037D /* LexDataflex.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LexDataflex.cxx; path = ../../lexers/LexDataflex.cxx; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -594,6 +596,7 @@
114B6ED111FA7526004FB6AB /* LexCsound.cxx */,
114B6ED211FA7526004FB6AB /* LexCSS.cxx */,
114B6ED311FA7526004FB6AB /* LexD.cxx */,
+ 362E48F5A7F79598CB0B037D /* LexDataflex.cxx */,
28B647071B54C0720009DC49 /* LexDiff.cxx */,
11FF3FE11810EB3900E13F13 /* LexDMAP.cxx */,
28064A04190F12E100E6E47F /* LexDMIS.cxx */,
@@ -1134,6 +1137,7 @@
0ED84236A703D57578EBFD2F /* LexNim.cxx in Sources */,
00724A59981D34F11A3D162F /* LexCIL.cxx in Sources */,
AE894E1CB7328CAE5B2EF47E /* LexX12.cxx in Sources */,
+ 902B40FE926FE48538B168F1 /* LexDataflex.cxx in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 7f9e41a1b..1ece8653b 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -542,6 +542,7 @@
<td>Jad Altahan</td>
<td>Andrea Ricchi</td>
<td>Juarez Rudsatz</td>
+ <td>Wil van Antwerpen</td>
</tr>
</table>
<p>
@@ -560,6 +561,10 @@
<li>
Released 13 June 2019.
</li>
+ <li>
+ Lexer added for DataFlex.
+ <a href="https://sourceforge.net/p/scintilla/feature-requests/1295/">Feature #1295</a>.
+ </li>
</ul>
<h3>
<a href="https://www.scintilla.org/scite417.zip">Release 4.1.7</a>
diff --git a/gtk/deps.mak b/gtk/deps.mak
index 104746cf6..faf8337a9 100644
--- a/gtk/deps.mak
+++ b/gtk/deps.mak
@@ -914,6 +914,18 @@ LexD.o: \
../lexlib/LexerModule.h \
../lexlib/OptionSet.h \
../lexlib/DefaultLexer.h
+LexDataflex.o: \
+ ../lexers/LexDataflex.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
LexDiff.o: \
../lexers/LexDiff.cxx \
../include/ILexer.h \
diff --git a/include/SciLexer.h b/include/SciLexer.h
index 2d2de4d03..39247b343 100644
--- a/include/SciLexer.h
+++ b/include/SciLexer.h
@@ -141,6 +141,7 @@
#define SCLEX_NIM 126
#define SCLEX_CIL 127
#define SCLEX_X12 128
+#define SCLEX_DATAFLEX 129
#define SCLEX_AUTOMATIC 1000
#define SCE_P_DEFAULT 0
#define SCE_P_COMMENTLINE 1
@@ -1895,6 +1896,21 @@
#define SCE_X12_SEGMENTEND 6
#define SCE_X12_SEP_ELEMENT 7
#define SCE_X12_SEP_SUBELEMENT 8
+#define SCE_DF_DEFAULT 0
+#define SCE_DF_IDENTIFIER 1
+#define SCE_DF_METATAG 2
+#define SCE_DF_IMAGE 3
+#define SCE_DF_COMMENTLINE 4
+#define SCE_DF_PREPROCESSOR 5
+#define SCE_DF_PREPROCESSOR2 6
+#define SCE_DF_NUMBER 7
+#define SCE_DF_HEXNUMBER 8
+#define SCE_DF_WORD 9
+#define SCE_DF_STRING 10
+#define SCE_DF_STRINGEOL 11
+#define SCE_DF_SCOPEWORD 12
+#define SCE_DF_OPERATOR 13
+#define SCE_DF_ICODE 14
/* --Autogenerated -- end of section automatically generated from Scintilla.iface */
#endif
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index c1c0a2ac1..4d75ef9ca 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -2970,6 +2970,7 @@ val SCLEX_SAS=125
val SCLEX_NIM=126
val SCLEX_CIL=127
val SCLEX_X12=128
+val SCLEX_DATAFLEX=129
# When a lexer specifies its language as SCLEX_AUTOMATIC it receives a
# value assigned in sequence from SCLEX_AUTOMATIC+1.
@@ -4966,6 +4967,23 @@ val SCE_X12_SEGMENTHEADER=5
val SCE_X12_SEGMENTEND=6
val SCE_X12_SEP_ELEMENT=7
val SCE_X12_SEP_SUBELEMENT=8
+# Lexical states for SCLEX_DATAFLEX
+lex Dataflex=SCLEX_DATAFLEX SCE_DF_
+val SCE_DF_DEFAULT=0
+val SCE_DF_IDENTIFIER=1
+val SCE_DF_METATAG=2
+val SCE_DF_IMAGE=3
+val SCE_DF_COMMENTLINE=4
+val SCE_DF_PREPROCESSOR=5
+val SCE_DF_PREPROCESSOR2=6
+val SCE_DF_NUMBER=7
+val SCE_DF_HEXNUMBER=8
+val SCE_DF_WORD=9
+val SCE_DF_STRING=10
+val SCE_DF_STRINGEOL=11
+val SCE_DF_SCOPEWORD=12
+val SCE_DF_OPERATOR=13
+val SCE_DF_ICODE=14
# Events
diff --git a/lexers/LexDataflex.cxx b/lexers/LexDataflex.cxx
new file mode 100644
index 000000000..42bd39b6b
--- /dev/null
+++ b/lexers/LexDataflex.cxx
@@ -0,0 +1,608 @@
+// Scintilla source code edit control
+/** @file LexDataflex.cxx
+ ** Lexer for DataFlex.
+ ** Based on LexPascal.cxx
+ ** Written by Wil van Antwerpen, June 2019
+ **/
+
+/*
+// The License.txt file describes the conditions under which this software may be distributed.
+
+A few words about features of LexDataflex...
+
+Generally speaking LexDataflex tries to support all available DataFlex features (up
+to DataFlex 19.1 at this time).
+
+~ FOLDING:
+
+Folding is supported in the following cases:
+
+- Folding of stream-like comments
+- Folding of groups of consecutive line comments
+- Folding of preprocessor blocks (the following preprocessor blocks are
+supported: #IFDEF, #IFNDEF, #ENDIF and #HEADER / #ENDHEADER
+blocks),
+- Folding of code blocks on appropriate keywords (the following code blocks are
+supported: "begin, struct, type, case / end" blocks, class & object
+declarations and interface declarations)
+
+Remarks:
+
+- We pass 4 arrays to the lexer:
+1. The DataFlex keyword list, these are normal DataFlex keywords
+2. The Scope Open list, for example, begin / procedure / while
+3. The Scope Close list, for example, end / end_procedure / loop
+4. Operator list, for ex. + / - / * / Lt / iand
+These lists are all mutually exclusive, scope open words should not be in the keyword list and vice versa
+
+- Folding of code blocks tries to handle all special cases in which folding
+should not occur.
+
+~ KEYWORDS:
+
+The list of keywords that can be used in dataflex.properties file (up to DataFlex
+19.1):
+
+- Keywords: .. snipped .. see dataflex.properties file.
+
+*/
+
+#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 void GetRangeLowered(Sci_PositionU start,
+ Sci_PositionU end,
+ Accessor &styler,
+ char *s,
+ Sci_PositionU len) {
+ Sci_PositionU i = 0;
+ while ((i < end - start + 1) && (i < len-1)) {
+ s[i] = static_cast<char>(tolower(styler[start + i]));
+ i++;
+ }
+ s[i] = '\0';
+}
+
+static void GetForwardRangeLowered(Sci_PositionU start,
+ CharacterSet &charSet,
+ Accessor &styler,
+ char *s,
+ Sci_PositionU len) {
+ Sci_PositionU i = 0;
+ while ((i < len-1) && charSet.Contains(styler.SafeGetCharAt(start + i))) {
+ s[i] = static_cast<char>(tolower(styler.SafeGetCharAt(start + i)));
+ i++;
+ }
+ s[i] = '\0';
+
+}
+
+enum {
+ stateInICode = 0x1000,
+ stateSingleQuoteOpen = 0x2000,
+ stateDoubleQuoteOpen = 0x4000,
+ stateFoldInPreprocessor = 0x0100,
+ stateFoldInCaseStatement = 0x0200,
+ stateFoldInPreprocessorLevelMask = 0x00FF,
+ stateFoldMaskAll = 0x0FFF
+};
+
+
+static bool IsFirstDataFlexWord(Sci_Position pos, Accessor &styler) {
+ Sci_Position line = styler.GetLine(pos);
+ Sci_Position start_pos = styler.LineStart(line);
+ for (Sci_Position i = start_pos; i < pos; i++) {
+ char ch = styler.SafeGetCharAt(i);
+ if (!(ch == ' ' || ch == '\t'))
+ return false;
+ }
+ return true;
+}
+
+
+inline bool IsADataFlexField(int ch) {
+ return (ch == '.');
+}
+
+
+static void ClassifyDataFlexWord(WordList *keywordlists[], StyleContext &sc, Accessor &styler) {
+ WordList& keywords = *keywordlists[0];
+ WordList& scopeOpen = *keywordlists[1];
+ WordList& scopeClosed = *keywordlists[2];
+ WordList& operators = *keywordlists[3];
+
+ char s[100];
+ int oldState;
+ int newState;
+ size_t tokenlen;
+
+ oldState = sc.state;
+ newState = oldState;
+ sc.GetCurrentLowered(s, sizeof(s));
+ tokenlen = strnlen(s,sizeof(s));
+ if (keywords.InList(s)) {
+ // keywords in DataFlex can be used as table column names (file.field) and as such they
+ // should not be characterized as a keyword. So test for that.
+ // for ex. somebody using date as field name.
+ if (!IsADataFlexField(sc.GetRelative(-static_cast<int>(tokenlen+1)))) {
+ newState = SCE_DF_WORD;
+ }
+ }
+ if (oldState == newState) {
+ if ((scopeOpen.InList(s) || scopeClosed.InList(s)) && (strcmp(s, "for") != 0) && (strcmp(s, "repeat") != 0)) {
+ // scope words in DataFlex can be used as table column names (file.field) and as such they
+ // should not be characterized as a scope word. So test for that.
+ // for ex. somebody using procedure for field name.
+ if (!IsADataFlexField(sc.GetRelative(-static_cast<int>(tokenlen+1)))) {
+ newState = SCE_DF_SCOPEWORD;
+ }
+ }
+ // no code folding on the next words, but just want to paint them like keywords (as they are) (??? doesn't the code to the opposite?)
+ if (strcmp(s, "if") == 0 ||
+ strcmp(s, "ifnot") == 0 ||
+ strcmp(s, "case") == 0 ||
+ strcmp(s, "else") == 0 ) {
+ newState = SCE_DF_SCOPEWORD;
+ }
+ }
+ if (oldState != newState && newState == SCE_DF_WORD) {
+ // a for loop must have for at the start of the line, for is also used in "define abc for 123"
+ if ( (strcmp(s, "for") == 0) && (IsFirstDataFlexWord(sc.currentPos-3, styler)) ) {
+ newState = SCE_DF_SCOPEWORD;
+ }
+ }
+ if (oldState != newState && newState == SCE_DF_WORD) {
+ // a repeat loop must have repeat at the start of the line, repeat is also used in 'move (repeat("d",5)) to sFoo'
+ if ( (strcmp(s, "repeat") == 0) && (IsFirstDataFlexWord(sc.currentPos-6, styler)) ) {
+ newState = SCE_DF_SCOPEWORD;
+ }
+ }
+ if (oldState == newState) {
+ if (operators.InList(s)) {
+ newState = SCE_DF_OPERATOR;
+ }
+ }
+
+ if (oldState != newState) {
+ sc.ChangeState(newState);
+ }
+ sc.SetState(SCE_DF_DEFAULT);
+}
+
+static void ColouriseDataFlexDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[],
+ Accessor &styler) {
+// bool bSmartHighlighting = styler.GetPropertyInt("lexer.dataflex.smart.highlighting", 1) != 0;
+
+ CharacterSet setWordStart(CharacterSet::setAlpha, "_$#@", 0x80, true);
+ CharacterSet setWord(CharacterSet::setAlphaNum, "_$#@", 0x80, true);
+ CharacterSet setNumber(CharacterSet::setDigits, ".-+eE");
+ CharacterSet setHexNumber(CharacterSet::setDigits, "abcdefABCDEF");
+ CharacterSet setOperator(CharacterSet::setNone, "*+-/<=>^");
+
+ Sci_Position curLine = styler.GetLine(startPos);
+ int curLineState = curLine > 0 ? styler.GetLineState(curLine - 1) : 0;
+
+ StyleContext sc(startPos, length, initStyle, styler);
+
+ for (; sc.More(); sc.Forward()) {
+ if (sc.atLineEnd) {
+ // Update the line state, so it can be seen by next line
+ curLine = styler.GetLine(sc.currentPos);
+ styler.SetLineState(curLine, curLineState);
+ }
+
+ // Determine if the current state should terminate.
+ switch (sc.state) {
+ case SCE_DF_NUMBER:
+ if (!setNumber.Contains(sc.ch) || (sc.ch == '.' && sc.chNext == '.')) {
+ sc.SetState(SCE_DF_DEFAULT);
+ } else if (sc.ch == '-' || sc.ch == '+') {
+ if (sc.chPrev != 'E' && sc.chPrev != 'e') {
+ sc.SetState(SCE_DF_DEFAULT);
+ }
+ }
+ break;
+ case SCE_DF_IDENTIFIER:
+ if (!setWord.Contains(sc.ch)) {
+ ClassifyDataFlexWord(keywordlists, sc, styler);
+ }
+ break;
+ case SCE_DF_HEXNUMBER:
+ if (!(setHexNumber.Contains(sc.ch) || sc.ch == 'I') ) { // in |CI$22a we also want to color the "I"
+ sc.SetState(SCE_DF_DEFAULT);
+ }
+ break;
+ case SCE_DF_METATAG:
+ if (sc.atLineStart || sc.chPrev == '}') {
+ sc.SetState(SCE_DF_DEFAULT);
+ }
+ break;
+ case SCE_DF_PREPROCESSOR:
+ if (sc.atLineStart || IsASpaceOrTab(sc.ch)) {
+ sc.SetState(SCE_DF_DEFAULT);
+ }
+ break;
+ case SCE_DF_IMAGE:
+ if (sc.atLineStart && sc.Match("/*")) {
+ sc.Forward(); // these characters are still part of the DF Image
+ sc.ForwardSetState(SCE_DF_DEFAULT);
+ }
+ break;
+ case SCE_DF_PREPROCESSOR2:
+ // we don't have inline comments or preprocessor2 commands
+ //if (sc.Match('*', ')')) {
+ // sc.Forward();
+ // sc.ForwardSetState(SCE_DF_DEFAULT);
+ //}
+ break;
+ case SCE_DF_COMMENTLINE:
+ if (sc.atLineStart) {
+ sc.SetState(SCE_DF_DEFAULT);
+ }
+ break;
+ case SCE_DF_STRING:
+ if (sc.atLineEnd) {
+ sc.ChangeState(SCE_DF_STRINGEOL);
+ } else if (sc.ch == '\'' && sc.chNext == '\'') {
+ sc.Forward();
+ } else if (sc.ch == '\"' && sc.chNext == '\"') {
+ sc.Forward();
+ } else if (sc.ch == '\'' || sc.ch == '\"') {
+ if (sc.ch == '\'' && (curLineState & stateSingleQuoteOpen) ) {
+ curLineState &= ~(stateSingleQuoteOpen);
+ sc.ForwardSetState(SCE_DF_DEFAULT);
+ }
+ else if (sc.ch == '\"' && (curLineState & stateDoubleQuoteOpen) ) {
+ curLineState &= ~(stateDoubleQuoteOpen);
+ sc.ForwardSetState(SCE_DF_DEFAULT);
+ }
+ }
+ break;
+ case SCE_DF_STRINGEOL:
+ if (sc.atLineStart) {
+ sc.SetState(SCE_DF_DEFAULT);
+ }
+ break;
+ case SCE_DF_SCOPEWORD:
+ //if (!setHexNumber.Contains(sc.ch) && sc.ch != '$') {
+ // sc.SetState(SCE_DF_DEFAULT);
+ //}
+ break;
+ case SCE_DF_OPERATOR:
+// if (bSmartHighlighting && sc.chPrev == ';') {
+// curLineState &= ~(stateInProperty | stateInExport);
+// }
+ sc.SetState(SCE_DF_DEFAULT);
+ break;
+ case SCE_DF_ICODE:
+ if (sc.atLineStart || IsASpace(sc.ch) || isoperator(sc.ch)) {
+ sc.SetState(SCE_DF_DEFAULT);
+ }
+ break;
+ }
+
+ // Determine if a new state should be entered.
+ if (sc.state == SCE_DF_DEFAULT) {
+ if (IsADigit(sc.ch)) {
+ sc.SetState(SCE_DF_NUMBER);
+ } else if (sc.Match('/', '/') || sc.Match("#REM")) {
+ sc.SetState(SCE_DF_COMMENTLINE);
+ } else if ((sc.ch == '#' && !sc.Match("#REM")) && IsFirstDataFlexWord(sc.currentPos, styler)) {
+ sc.SetState(SCE_DF_PREPROCESSOR);
+ // || (sc.ch == '|' && sc.chNext == 'C' && sc.GetRelativeCharacter(2) == 'I' && sc.GetRelativeCharacter(3) == '$') ) {
+ } else if ((sc.ch == '$' && ((!setWord.Contains(sc.chPrev)) || sc.chPrev == 'I' ) ) || (sc.Match("|CI$")) ) {
+ sc.SetState(SCE_DF_HEXNUMBER); // start with $ and previous character not in a..zA..Z0..9 excluding "I" OR start with |CI$
+ } else if (setWordStart.Contains(sc.ch)) {
+ sc.SetState(SCE_DF_IDENTIFIER);
+ } else if (sc.ch == '{') {
+ sc.SetState(SCE_DF_METATAG);
+ //} else if (sc.Match("(*$")) {
+ // sc.SetState(SCE_DF_PREPROCESSOR2);
+ } else if (sc.ch == '/' && setWord.Contains(sc.chNext) && sc.atLineStart) {
+ sc.SetState(SCE_DF_IMAGE);
+ // sc.Forward(); // Eat the * so it isn't used for the end of the comment
+ } else if (sc.ch == '\'' || sc.ch == '\"') {
+ if (sc.ch == '\'' && !(curLineState & stateDoubleQuoteOpen)) {
+ curLineState |= stateSingleQuoteOpen;
+ } else if (sc.ch == '\"' && !(curLineState & stateSingleQuoteOpen)) {
+ curLineState |= stateDoubleQuoteOpen;
+ }
+ sc.SetState(SCE_DF_STRING);
+ } else if (setOperator.Contains(sc.ch)) {
+ sc.SetState(SCE_DF_OPERATOR);
+// } else if (curLineState & stateInICode) {
+ // ICode start ! in a string followed by close string mark is not icode
+ } else if ((sc.ch == '!') && !(sc.ch == '!' && ((sc.chNext == '\"') || (sc.ch == '\'')) )) {
+ sc.SetState(SCE_DF_ICODE);
+ }
+ }
+ }
+
+ if (sc.state == SCE_DF_IDENTIFIER && setWord.Contains(sc.chPrev)) {
+ ClassifyDataFlexWord(keywordlists, sc, styler);
+ }
+
+ sc.Complete();
+}
+
+static bool IsStreamCommentStyle(int style) {
+ return style == SCE_DF_IMAGE;
+}
+
+static bool IsCommentLine(Sci_Position line, Accessor &styler) {
+ Sci_Position pos = styler.LineStart(line);
+ Sci_Position eolPos = styler.LineStart(line + 1) - 1;
+ for (Sci_Position i = pos; i < eolPos; i++) {
+ char ch = styler[i];
+ char chNext = styler.SafeGetCharAt(i + 1);
+ int style = styler.StyleAt(i);
+ if (ch == '/' && chNext == '/' && style == SCE_DF_COMMENTLINE) {
+ return true;
+ } else if (!IsASpaceOrTab(ch)) {
+ return false;
+ }
+ }
+ return false;
+}
+
+
+
+static unsigned int GetFoldInPreprocessorLevelFlag(int lineFoldStateCurrent) {
+ return lineFoldStateCurrent & stateFoldInPreprocessorLevelMask;
+}
+
+static void SetFoldInPreprocessorLevelFlag(int &lineFoldStateCurrent, unsigned int nestLevel) {
+ lineFoldStateCurrent &= ~stateFoldInPreprocessorLevelMask;
+ lineFoldStateCurrent |= nestLevel & stateFoldInPreprocessorLevelMask;
+}
+
+static int ClassifyDataFlexPreprocessorFoldPoint(int &levelCurrent, int &lineFoldStateCurrent,
+ Sci_PositionU startPos, Accessor &styler) {
+ CharacterSet setWord(CharacterSet::setAlpha);
+
+ char s[100]; // Size of the longest possible keyword + one additional character + null
+ GetForwardRangeLowered(startPos, setWord, styler, s, sizeof(s));
+ size_t iLen = strnlen(s,sizeof(s));
+ size_t iWordSize = 0;
+
+ unsigned int nestLevel = GetFoldInPreprocessorLevelFlag(lineFoldStateCurrent);
+
+ if (strcmp(s, "command") == 0 ||
+ // The #if/#ifdef etcetera commands are not currently foldable as it is easy to write code that
+ // breaks the collaps logic, so we keep things simple and not include that for now.
+ strcmp(s, "header") == 0) {
+ nestLevel++;
+ SetFoldInPreprocessorLevelFlag(lineFoldStateCurrent, nestLevel);
+ lineFoldStateCurrent |= stateFoldInPreprocessor;
+ levelCurrent++;
+ iWordSize = iLen;
+ } else if (strcmp(s, "endcommand") == 0 ||
+ strcmp(s, "endheader") == 0) {
+ nestLevel--;
+ SetFoldInPreprocessorLevelFlag(lineFoldStateCurrent, nestLevel);
+ if (nestLevel == 0) {
+ lineFoldStateCurrent &= ~stateFoldInPreprocessor;
+ }
+ levelCurrent--;
+ iWordSize = iLen;
+ if (levelCurrent < SC_FOLDLEVELBASE) {
+ levelCurrent = SC_FOLDLEVELBASE;
+ }
+ }
+ return static_cast<int>(iWordSize);
+}
+
+
+static void ClassifyDataFlexWordFoldPoint(int &levelCurrent, int &lineFoldStateCurrent,
+ Sci_PositionU lastStart, Sci_PositionU currentPos, WordList *[], Accessor &styler) {
+ char s[100];
+
+ // property fold.dataflex.compilerlist
+ // Set to 1 for enabling the code folding feature in *.prn files
+ bool foldPRN = styler.GetPropertyInt("fold.dataflex.compilerlist",0) != 0;
+
+ GetRangeLowered(lastStart, currentPos, styler, s, sizeof(s));
+
+ if (strcmp(s, "case") == 0) {
+ lineFoldStateCurrent |= stateFoldInCaseStatement;
+ } else if (strcmp(s, "begin") == 0) {
+ levelCurrent++;
+ } else if (strcmp(s, "for") == 0 ||
+ strcmp(s, "while") == 0 ||
+ strcmp(s, "repeat") == 0 ||
+ strcmp(s, "for_all") == 0 ||
+ strcmp(s, "struct") == 0 ||
+ strcmp(s, "type") == 0 ||
+ strcmp(s, "begin_row") == 0 ||
+ strcmp(s, "item_list") == 0 ||
+ strcmp(s, "begin_constraints") == 0 ||
+ strcmp(s, "begin_transaction") == 0 ||
+ strcmp(s, "enum_list") == 0 ||
+ strcmp(s, "class") == 0 ||
+ strcmp(s, "object") == 0 ||
+ strcmp(s, "cd_popup_object") == 0 ||
+ strcmp(s, "procedure") == 0 ||
+ strcmp(s, "procedure_section") == 0 ||
+ strcmp(s, "function") == 0 ) {
+ if ((IsFirstDataFlexWord(lastStart, styler )) || foldPRN) {
+ levelCurrent++;
+ }
+ } else if (strcmp(s, "end") == 0) { // end is not always the first keyword, for example "case end"
+ levelCurrent--;
+ if (levelCurrent < SC_FOLDLEVELBASE) {
+ levelCurrent = SC_FOLDLEVELBASE;
+ }
+ } else if (strcmp(s, "loop") == 0 ||
+ strcmp(s, "until") == 0 ||
+ strcmp(s, "end_class") == 0 ||
+ strcmp(s, "end_object") == 0 ||
+ strcmp(s, "cd_end_object") == 0 ||
+ strcmp(s, "end_procedure") == 0 ||
+ strcmp(s, "end_function") == 0 ||
+ strcmp(s, "end_for_all") == 0 ||
+ strcmp(s, "end_struct") == 0 ||
+ strcmp(s, "end_type") == 0 ||
+ strcmp(s, "end_row") == 0 ||
+ strcmp(s, "end_item_list") == 0 ||
+ strcmp(s, "end_constraints") == 0 ||
+ strcmp(s, "end_transaction") == 0 ||
+ strcmp(s, "end_enum_list") == 0 ) {
+ // lineFoldStateCurrent &= ~stateFoldInRecord;
+ if ((IsFirstDataFlexWord(lastStart, styler )) || foldPRN) {
+ levelCurrent--;
+ if (levelCurrent < SC_FOLDLEVELBASE) {
+ levelCurrent = SC_FOLDLEVELBASE;
+ }
+ }
+ }
+
+}
+
+
+static void ClassifyDataFlexMetaDataFoldPoint(int &levelCurrent,
+ Sci_PositionU lastStart, Sci_PositionU currentPos, WordList *[], Accessor &styler) {
+ char s[100];
+
+ GetRangeLowered(lastStart, currentPos, styler, s, sizeof(s));
+
+ if (strcmp(s, "#beginsection") == 0) {
+ levelCurrent++;
+ } else if (strcmp(s, "#endsection") == 0) {
+ levelCurrent--;
+ if (levelCurrent < SC_FOLDLEVELBASE) {
+ levelCurrent = SC_FOLDLEVELBASE;
+ }
+ }
+
+}
+
+static void FoldDataFlexDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[],
+ Accessor &styler) {
+ bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
+ bool foldPreprocessor = styler.GetPropertyInt("fold.preprocessor") != 0;
+ bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
+ Sci_PositionU endPos = startPos + length;
+ int visibleChars = 0;
+ Sci_Position lineCurrent = styler.GetLine(startPos);
+ int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
+ int levelCurrent = levelPrev;
+ int lineFoldStateCurrent = lineCurrent > 0 ? styler.GetLineState(lineCurrent - 1) & stateFoldMaskAll : 0;
+ char chNext = styler[startPos];
+ int styleNext = styler.StyleAt(startPos);
+ int style = initStyle;
+ int iWordSize;
+
+ Sci_Position lastStart = 0;
+ CharacterSet setWord(CharacterSet::setAlphaNum, "_$#@", 0x80, true);
+
+ for (Sci_PositionU 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 (foldComment && IsStreamCommentStyle(style)) {
+ if (!IsStreamCommentStyle(stylePrev)) {
+ levelCurrent++;
+ } else if (!IsStreamCommentStyle(styleNext)) {
+ levelCurrent--;
+ }
+ }
+ if (foldComment && atEOL && IsCommentLine(lineCurrent, styler))
+ {
+ if (!IsCommentLine(lineCurrent - 1, styler)
+ && IsCommentLine(lineCurrent + 1, styler))
+ levelCurrent++;
+ else if (IsCommentLine(lineCurrent - 1, styler)
+ && !IsCommentLine(lineCurrent+1, styler))
+ levelCurrent--;
+ }
+ if (foldPreprocessor) {
+ if (style == SCE_DF_PREPROCESSOR) {
+ iWordSize = ClassifyDataFlexPreprocessorFoldPoint(levelCurrent, lineFoldStateCurrent, i + 1, styler);
+ //} else if (style == SCE_DF_PREPROCESSOR2 && ch == '(' && chNext == '*'
+ // && styler.SafeGetCharAt(i + 2) == '$') {
+ // ClassifyDataFlexPreprocessorFoldPoint(levelCurrent, lineFoldStateCurrent, i + 3, styler);
+ i = i + iWordSize;
+ }
+ }
+
+ if (stylePrev != SCE_DF_SCOPEWORD && style == SCE_DF_SCOPEWORD)
+ {
+ // Store last word start point.
+ lastStart = i;
+ }
+ if (stylePrev == SCE_DF_SCOPEWORD) {
+ if(setWord.Contains(ch) && !setWord.Contains(chNext)) {
+ ClassifyDataFlexWordFoldPoint(levelCurrent, lineFoldStateCurrent, lastStart, i, keywordlists, styler);
+ }
+ }
+
+ if (stylePrev == SCE_DF_METATAG && ch == '#')
+ {
+ // Store last word start point.
+ lastStart = i;
+ }
+ if (stylePrev == SCE_DF_METATAG) {
+ if(setWord.Contains(ch) && !setWord.Contains(chNext)) {
+ ClassifyDataFlexMetaDataFoldPoint(levelCurrent, lastStart, i, keywordlists, styler);
+ }
+ }
+
+ if (!IsASpace(ch))
+ visibleChars++;
+
+ 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);
+ }
+ int newLineState = (styler.GetLineState(lineCurrent) & ~stateFoldMaskAll) | lineFoldStateCurrent;
+ styler.SetLineState(lineCurrent, newLineState);
+ lineCurrent++;
+ levelPrev = levelCurrent;
+ visibleChars = 0;
+ }
+ }
+
+ // If we didn't reach the EOL in previous loop, store line level and whitespace information.
+ // The rest will be filled in later...
+ int lev = levelPrev;
+ if (visibleChars == 0 && foldCompact)
+ lev |= SC_FOLDLEVELWHITEFLAG;
+ styler.SetLevel(lineCurrent, lev);
+}
+
+static const char * const dataflexWordListDesc[] = {
+ "Keywords",
+ "Scope open",
+ "Scope close",
+ "Operators",
+ 0
+};
+
+LexerModule lmDataflex(SCLEX_DATAFLEX, ColouriseDataFlexDoc, "dataflex", FoldDataFlexDoc, dataflexWordListDesc);
diff --git a/src/Catalogue.cxx b/src/Catalogue.cxx
index d221113ce..8a0a29259 100644
--- a/src/Catalogue.cxx
+++ b/src/Catalogue.cxx
@@ -102,6 +102,7 @@ int Scintilla_LinkLexers() {
LINK_LEXER(lmCsound);
LINK_LEXER(lmCss);
LINK_LEXER(lmD);
+ LINK_LEXER(lmDataflex);
LINK_LEXER(lmDiff);
LINK_LEXER(lmDMAP);
LINK_LEXER(lmDMIS);
diff --git a/win32/deps.mak b/win32/deps.mak
index 8c53840ad..cc0820cca 100644
--- a/win32/deps.mak
+++ b/win32/deps.mak
@@ -956,6 +956,18 @@ LexD.o: \
../lexlib/LexerModule.h \
../lexlib/OptionSet.h \
../lexlib/DefaultLexer.h
+LexDataflex.o: \
+ ../lexers/LexDataflex.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
LexDiff.o: \
../lexers/LexDiff.cxx \
../include/ILexer.h \
diff --git a/win32/nmdeps.mak b/win32/nmdeps.mak
index 8ddedfc79..83afc4abf 100644
--- a/win32/nmdeps.mak
+++ b/win32/nmdeps.mak
@@ -956,6 +956,18 @@ $(DIR_O)/LexD.obj: \
../lexlib/LexerModule.h \
../lexlib/OptionSet.h \
../lexlib/DefaultLexer.h
+$(DIR_O)/LexDataflex.obj: \
+ ../lexers/LexDataflex.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
$(DIR_O)/LexDiff.obj: \
../lexers/LexDiff.cxx \
../include/ILexer.h \
diff --git a/win32/scintilla.mak b/win32/scintilla.mak
index 9b91e7639..934a54b30 100644
--- a/win32/scintilla.mak
+++ b/win32/scintilla.mak
@@ -135,6 +135,7 @@ LEXOBJS=\
$(DIR_O)\LexCsound.obj \
$(DIR_O)\LexCSS.obj \
$(DIR_O)\LexD.obj \
+ $(DIR_O)\LexDataflex.obj \
$(DIR_O)\LexDiff.obj \
$(DIR_O)\LexDMAP.obj \
$(DIR_O)\LexDMIS.obj \