2013-08-28 00:44:27 +00:00
|
|
|
// Scintilla source code edit control
|
|
|
|
/** @file LexVisualProlog.cxx
|
|
|
|
** Lexer for Visual Prolog.
|
|
|
|
**/
|
|
|
|
// Author Thomas Linder Puls, Prolog Development Denter A/S, http://www.visual-prolog.com
|
|
|
|
// Based on Lexer for C++, C, Java, and JavaScript.
|
|
|
|
// Copyright 1998-2005 by Neil Hodgson <neilh@scintilla.org>
|
|
|
|
// The License.txt file describes the conditions under which this software may be distributed.
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
// The line state contains:
|
|
|
|
// In SCE_VISUALPROLOG_STRING_VERBATIM_EOL (i.e. multiline string literal): The closingQuote.
|
|
|
|
// else (for SCE_VISUALPROLOG_COMMENT_BLOCK): The comment nesting level
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <assert.h>
|
2015-06-07 21:19:26 +00:00
|
|
|
#include <ctype.h>
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(disable: 4786)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "ILexer.h"
|
|
|
|
#include "Scintilla.h"
|
|
|
|
#include "SciLexer.h"
|
|
|
|
|
|
|
|
#include "WordList.h"
|
|
|
|
#include "LexAccessor.h"
|
|
|
|
#include "Accessor.h"
|
|
|
|
#include "StyleContext.h"
|
|
|
|
#include "CharacterSet.h"
|
2015-06-07 21:19:26 +00:00
|
|
|
#include "CharacterCategory.h"
|
2013-08-28 00:44:27 +00:00
|
|
|
#include "LexerModule.h"
|
|
|
|
#include "OptionSet.h"
|
2019-05-04 18:14:48 +00:00
|
|
|
#include "DefaultLexer.h"
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
using namespace Scintilla;
|
|
|
|
|
|
|
|
// Options used for LexerVisualProlog
|
|
|
|
struct OptionsVisualProlog {
|
|
|
|
OptionsVisualProlog() {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *const visualPrologWordLists[] = {
|
|
|
|
"Major keywords (class, predicates, ...)",
|
|
|
|
"Minor keywords (if, then, try, ...)",
|
|
|
|
"Directive keywords without the '#' (include, requires, ...)",
|
|
|
|
"Documentation keywords without the '@' (short, detail, ...)",
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OptionSetVisualProlog : public OptionSet<OptionsVisualProlog> {
|
|
|
|
OptionSetVisualProlog() {
|
|
|
|
DefineWordListSets(visualPrologWordLists);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
class LexerVisualProlog : public DefaultLexer {
|
2013-08-28 00:44:27 +00:00
|
|
|
WordList majorKeywords;
|
|
|
|
WordList minorKeywords;
|
|
|
|
WordList directiveKeywords;
|
|
|
|
WordList docKeywords;
|
|
|
|
OptionsVisualProlog options;
|
|
|
|
OptionSetVisualProlog osVisualProlog;
|
|
|
|
public:
|
|
|
|
LexerVisualProlog() {
|
|
|
|
}
|
|
|
|
virtual ~LexerVisualProlog() {
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
void SCI_METHOD Release() override {
|
2013-08-28 00:44:27 +00:00
|
|
|
delete this;
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
int SCI_METHOD Version() const override {
|
|
|
|
return lvRelease4;
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
const char * SCI_METHOD PropertyNames() override {
|
2013-08-28 00:44:27 +00:00
|
|
|
return osVisualProlog.PropertyNames();
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
int SCI_METHOD PropertyType(const char *name) override {
|
2013-08-28 00:44:27 +00:00
|
|
|
return osVisualProlog.PropertyType(name);
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
const char * SCI_METHOD DescribeProperty(const char *name) override {
|
2013-08-28 00:44:27 +00:00
|
|
|
return osVisualProlog.DescribeProperty(name);
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override;
|
|
|
|
const char * SCI_METHOD DescribeWordListSets() override {
|
2013-08-28 00:44:27 +00:00
|
|
|
return osVisualProlog.DescribeWordListSets();
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override;
|
|
|
|
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override;
|
|
|
|
void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override;
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
void * SCI_METHOD PrivateCall(int, void *) override {
|
2013-08-28 00:44:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
static ILexer4 *LexerFactoryVisualProlog() {
|
2013-08-28 00:44:27 +00:00
|
|
|
return new LexerVisualProlog();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci_Position SCI_METHOD LexerVisualProlog::PropertySet(const char *key, const char *val) {
|
2013-08-28 00:44:27 +00:00
|
|
|
if (osVisualProlog.PropertySet(&options, key, val)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci_Position SCI_METHOD LexerVisualProlog::WordListSet(int n, const char *wl) {
|
2013-08-28 00:44:27 +00:00
|
|
|
WordList *wordListN = 0;
|
|
|
|
switch (n) {
|
|
|
|
case 0:
|
|
|
|
wordListN = &majorKeywords;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
wordListN = &minorKeywords;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
wordListN = &directiveKeywords;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
wordListN = &docKeywords;
|
|
|
|
break;
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci_Position firstModification = -1;
|
2013-08-28 00:44:27 +00:00
|
|
|
if (wordListN) {
|
|
|
|
WordList wlNew;
|
|
|
|
wlNew.Set(wl);
|
|
|
|
if (*wordListN != wlNew) {
|
|
|
|
wordListN->Set(wl);
|
|
|
|
firstModification = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return firstModification;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Functor used to truncate history
|
|
|
|
struct After {
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci_Position line;
|
|
|
|
After(Sci_Position line_) : line(line_) {}
|
2013-08-28 00:44:27 +00:00
|
|
|
};
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
static bool isLowerLetter(int ch){
|
|
|
|
return ccLl == CategoriseCharacter(ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isUpperLetter(int ch){
|
|
|
|
return ccLu == CategoriseCharacter(ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isAlphaNum(int ch){
|
|
|
|
CharacterCategory cc = CategoriseCharacter(ch);
|
|
|
|
return (ccLu == cc || ccLl == cc || ccLt == cc || ccLm == cc || ccLo == cc || ccNd == cc || ccNl == cc || ccNo == cc);
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
static bool isStringVerbatimOpenClose(int ch){
|
|
|
|
CharacterCategory cc = CategoriseCharacter(ch);
|
|
|
|
return (ccPc <= cc && cc <= ccSo);
|
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
static bool isIdChar(int ch){
|
|
|
|
return ('_') == ch || isAlphaNum(ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isOpenStringVerbatim(int next, int &closingQuote){
|
|
|
|
switch (next) {
|
|
|
|
case L'<':
|
|
|
|
closingQuote = L'>';
|
|
|
|
return true;
|
|
|
|
case L'>':
|
|
|
|
closingQuote = L'<';
|
|
|
|
return true;
|
|
|
|
case L'(':
|
|
|
|
closingQuote = L')';
|
|
|
|
return true;
|
|
|
|
case L')':
|
|
|
|
closingQuote = L'(';
|
|
|
|
return true;
|
|
|
|
case L'[':
|
|
|
|
closingQuote = L']';
|
|
|
|
return true;
|
|
|
|
case L']':
|
|
|
|
closingQuote = L'[';
|
|
|
|
return true;
|
|
|
|
case L'{':
|
|
|
|
closingQuote = L'}';
|
|
|
|
return true;
|
|
|
|
case L'}':
|
|
|
|
closingQuote = L'{';
|
|
|
|
return true;
|
|
|
|
case L'_':
|
|
|
|
case L'.':
|
|
|
|
case L',':
|
|
|
|
case L';':
|
|
|
|
return false;
|
|
|
|
default:
|
2019-05-04 18:14:48 +00:00
|
|
|
if (isStringVerbatimOpenClose(next)) {
|
2015-06-07 21:19:26 +00:00
|
|
|
closingQuote = next;
|
|
|
|
return true;
|
2019-05-04 18:14:48 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
2015-06-07 21:19:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
// Look ahead to see which colour "end" should have (takes colour after the following keyword)
|
2019-05-04 18:14:48 +00:00
|
|
|
static void endLookAhead(char s[], LexAccessor &styler, Sci_Position start) {
|
2013-08-28 00:44:27 +00:00
|
|
|
char ch = styler.SafeGetCharAt(start, '\n');
|
|
|
|
while (' ' == ch) {
|
|
|
|
start++;
|
|
|
|
ch = styler.SafeGetCharAt(start, '\n');
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci_Position i = 0;
|
2015-06-07 21:19:26 +00:00
|
|
|
while (i < 100 && isLowerLetter(ch)){
|
2013-08-28 00:44:27 +00:00
|
|
|
s[i] = ch;
|
|
|
|
i++;
|
|
|
|
ch = styler.SafeGetCharAt(start + i, '\n');
|
|
|
|
}
|
|
|
|
s[i] = '\0';
|
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
static void forwardEscapeLiteral(StyleContext &sc, int EscapeState) {
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.Forward();
|
2015-06-07 21:19:26 +00:00
|
|
|
if (sc.Match('"') || sc.Match('\'') || sc.Match('\\') || sc.Match('n') || sc.Match('l') || sc.Match('r') || sc.Match('t')) {
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.ChangeState(EscapeState);
|
2015-06-07 21:19:26 +00:00
|
|
|
} else if (sc.Match('u')) {
|
2013-08-28 00:44:27 +00:00
|
|
|
if (IsADigit(sc.chNext, 16)) {
|
|
|
|
sc.Forward();
|
|
|
|
if (IsADigit(sc.chNext, 16)) {
|
|
|
|
sc.Forward();
|
|
|
|
if (IsADigit(sc.chNext, 16)) {
|
|
|
|
sc.Forward();
|
|
|
|
if (IsADigit(sc.chNext, 16)) {
|
|
|
|
sc.Forward();
|
|
|
|
sc.ChangeState(EscapeState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
void SCI_METHOD LexerVisualProlog::Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) {
|
2013-08-28 00:44:27 +00:00
|
|
|
LexAccessor styler(pAccess);
|
2015-06-07 21:19:26 +00:00
|
|
|
CharacterSet setDoxygen(CharacterSet::setAlpha, "");
|
2019-05-04 18:14:48 +00:00
|
|
|
CharacterSet setNumber(CharacterSet::setNone, "0123456789abcdefABCDEFxoXO");
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
StyleContext sc(startPos, length, initStyle, styler, 0x7f);
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
int styleBeforeDocKeyword = SCE_VISUALPROLOG_DEFAULT;
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci_Position currentLine = styler.GetLine(startPos);
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
int closingQuote = '"';
|
2013-08-28 00:44:27 +00:00
|
|
|
int nestLevel = 0;
|
|
|
|
if (currentLine >= 1)
|
|
|
|
{
|
|
|
|
nestLevel = styler.GetLineState(currentLine - 1);
|
2015-06-07 21:19:26 +00:00
|
|
|
closingQuote = nestLevel;
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Truncate ppDefineHistory before current line
|
|
|
|
|
|
|
|
for (; sc.More(); sc.Forward()) {
|
|
|
|
|
|
|
|
// Determine if the current state should terminate.
|
|
|
|
switch (sc.state) {
|
|
|
|
case SCE_VISUALPROLOG_OPERATOR:
|
|
|
|
sc.SetState(SCE_VISUALPROLOG_DEFAULT);
|
|
|
|
break;
|
|
|
|
case SCE_VISUALPROLOG_NUMBER:
|
|
|
|
// We accept almost anything because of hex. and number suffixes
|
2019-05-04 18:14:48 +00:00
|
|
|
if (!(setNumber.Contains(sc.ch)) || (sc.Match('.') && IsADigit(sc.chNext))) {
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_VISUALPROLOG_DEFAULT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCE_VISUALPROLOG_IDENTIFIER:
|
2015-06-07 21:19:26 +00:00
|
|
|
if (!isIdChar(sc.ch)) {
|
2013-08-28 00:44:27 +00:00
|
|
|
char s[1000];
|
|
|
|
sc.GetCurrent(s, sizeof(s));
|
|
|
|
if (0 == strcmp(s, "end")) {
|
2015-06-07 21:19:26 +00:00
|
|
|
endLookAhead(s, styler, sc.currentPos);
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
|
|
|
if (majorKeywords.InList(s)) {
|
|
|
|
sc.ChangeState(SCE_VISUALPROLOG_KEY_MAJOR);
|
|
|
|
} else if (minorKeywords.InList(s)) {
|
|
|
|
sc.ChangeState(SCE_VISUALPROLOG_KEY_MINOR);
|
|
|
|
}
|
|
|
|
sc.SetState(SCE_VISUALPROLOG_DEFAULT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCE_VISUALPROLOG_VARIABLE:
|
|
|
|
case SCE_VISUALPROLOG_ANONYMOUS:
|
2015-06-07 21:19:26 +00:00
|
|
|
if (!isIdChar(sc.ch)) {
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_VISUALPROLOG_DEFAULT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCE_VISUALPROLOG_KEY_DIRECTIVE:
|
2015-06-07 21:19:26 +00:00
|
|
|
if (!isLowerLetter(sc.ch)) {
|
2013-08-28 00:44:27 +00:00
|
|
|
char s[1000];
|
|
|
|
sc.GetCurrent(s, sizeof(s));
|
|
|
|
if (!directiveKeywords.InList(s+1)) {
|
|
|
|
sc.ChangeState(SCE_VISUALPROLOG_IDENTIFIER);
|
|
|
|
}
|
|
|
|
sc.SetState(SCE_VISUALPROLOG_DEFAULT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCE_VISUALPROLOG_COMMENT_BLOCK:
|
|
|
|
if (sc.Match('*', '/')) {
|
|
|
|
sc.Forward();
|
|
|
|
nestLevel--;
|
|
|
|
int nextState = (nestLevel == 0) ? SCE_VISUALPROLOG_DEFAULT : SCE_VISUALPROLOG_COMMENT_BLOCK;
|
|
|
|
sc.ForwardSetState(nextState);
|
|
|
|
} else if (sc.Match('/', '*')) {
|
|
|
|
sc.Forward();
|
|
|
|
nestLevel++;
|
2015-06-07 21:19:26 +00:00
|
|
|
} else if (sc.Match('@')) {
|
2013-08-28 00:44:27 +00:00
|
|
|
styleBeforeDocKeyword = sc.state;
|
|
|
|
sc.SetState(SCE_VISUALPROLOG_COMMENT_KEY_ERROR);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCE_VISUALPROLOG_COMMENT_LINE:
|
|
|
|
if (sc.atLineEnd) {
|
|
|
|
int nextState = (nestLevel == 0) ? SCE_VISUALPROLOG_DEFAULT : SCE_VISUALPROLOG_COMMENT_BLOCK;
|
|
|
|
sc.SetState(nextState);
|
2015-06-07 21:19:26 +00:00
|
|
|
} else if (sc.Match('@')) {
|
2013-08-28 00:44:27 +00:00
|
|
|
styleBeforeDocKeyword = sc.state;
|
|
|
|
sc.SetState(SCE_VISUALPROLOG_COMMENT_KEY_ERROR);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCE_VISUALPROLOG_COMMENT_KEY_ERROR:
|
2015-06-07 21:19:26 +00:00
|
|
|
if (!setDoxygen.Contains(sc.ch) || sc.atLineEnd) {
|
2013-08-28 00:44:27 +00:00
|
|
|
char s[1000];
|
|
|
|
sc.GetCurrent(s, sizeof(s));
|
|
|
|
if (docKeywords.InList(s+1)) {
|
|
|
|
sc.ChangeState(SCE_VISUALPROLOG_COMMENT_KEY);
|
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
if (SCE_VISUALPROLOG_COMMENT_LINE == styleBeforeDocKeyword && sc.atLineEnd) {
|
|
|
|
// end line comment
|
|
|
|
int nextState = (nestLevel == 0) ? SCE_VISUALPROLOG_DEFAULT : SCE_VISUALPROLOG_COMMENT_BLOCK;
|
|
|
|
sc.SetState(nextState);
|
|
|
|
} else {
|
|
|
|
sc.SetState(styleBeforeDocKeyword);
|
|
|
|
if (SCE_VISUALPROLOG_COMMENT_BLOCK == styleBeforeDocKeyword && sc.Match('*', '/')) {
|
|
|
|
// we have consumed the '*' if it comes immediately after the docKeyword
|
|
|
|
sc.Forward();
|
|
|
|
sc.Forward();
|
|
|
|
nestLevel--;
|
|
|
|
if (0 == nestLevel) {
|
|
|
|
sc.SetState(SCE_VISUALPROLOG_DEFAULT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCE_VISUALPROLOG_STRING_ESCAPE:
|
|
|
|
case SCE_VISUALPROLOG_STRING_ESCAPE_ERROR:
|
|
|
|
// return to SCE_VISUALPROLOG_STRING and treat as such (fall-through)
|
|
|
|
sc.SetState(SCE_VISUALPROLOG_STRING);
|
2019-05-04 18:14:48 +00:00
|
|
|
// Falls through.
|
2013-08-28 00:44:27 +00:00
|
|
|
case SCE_VISUALPROLOG_STRING:
|
|
|
|
if (sc.atLineEnd) {
|
|
|
|
sc.SetState(SCE_VISUALPROLOG_STRING_EOL_OPEN);
|
2015-06-07 21:19:26 +00:00
|
|
|
} else if (sc.Match(closingQuote)) {
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.ForwardSetState(SCE_VISUALPROLOG_DEFAULT);
|
2015-06-07 21:19:26 +00:00
|
|
|
} else if (sc.Match('\\')) {
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_VISUALPROLOG_STRING_ESCAPE_ERROR);
|
2015-06-07 21:19:26 +00:00
|
|
|
forwardEscapeLiteral(sc, SCE_VISUALPROLOG_STRING_ESCAPE);
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCE_VISUALPROLOG_STRING_EOL_OPEN:
|
|
|
|
if (sc.atLineStart) {
|
|
|
|
sc.SetState(SCE_VISUALPROLOG_DEFAULT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCE_VISUALPROLOG_STRING_VERBATIM_SPECIAL:
|
|
|
|
case SCE_VISUALPROLOG_STRING_VERBATIM_EOL:
|
|
|
|
// return to SCE_VISUALPROLOG_STRING_VERBATIM and treat as such (fall-through)
|
|
|
|
sc.SetState(SCE_VISUALPROLOG_STRING_VERBATIM);
|
2019-05-04 18:14:48 +00:00
|
|
|
// Falls through.
|
2013-08-28 00:44:27 +00:00
|
|
|
case SCE_VISUALPROLOG_STRING_VERBATIM:
|
|
|
|
if (sc.atLineEnd) {
|
|
|
|
sc.SetState(SCE_VISUALPROLOG_STRING_VERBATIM_EOL);
|
2015-06-07 21:19:26 +00:00
|
|
|
} else if (sc.Match(closingQuote)) {
|
|
|
|
if (closingQuote == sc.chNext) {
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_VISUALPROLOG_STRING_VERBATIM_SPECIAL);
|
|
|
|
sc.Forward();
|
|
|
|
} else {
|
|
|
|
sc.ForwardSetState(SCE_VISUALPROLOG_DEFAULT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
if (sc.atLineEnd) {
|
|
|
|
// Update the line state, so it can be seen by next line
|
|
|
|
int lineState = 0;
|
2019-05-04 18:14:48 +00:00
|
|
|
if (SCE_VISUALPROLOG_STRING_VERBATIM_EOL == sc.state) {
|
2015-06-07 21:19:26 +00:00
|
|
|
lineState = closingQuote;
|
|
|
|
} else if (SCE_VISUALPROLOG_COMMENT_BLOCK == sc.state) {
|
|
|
|
lineState = nestLevel;
|
|
|
|
}
|
|
|
|
styler.SetLineState(currentLine, lineState);
|
2013-08-28 00:44:27 +00:00
|
|
|
currentLine++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine if a new state should be entered.
|
|
|
|
if (sc.state == SCE_VISUALPROLOG_DEFAULT) {
|
2015-06-07 21:19:26 +00:00
|
|
|
if (sc.Match('@') && isOpenStringVerbatim(sc.chNext, closingQuote)) {
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_VISUALPROLOG_STRING_VERBATIM);
|
|
|
|
sc.Forward();
|
2015-06-07 21:19:26 +00:00
|
|
|
} else if (IsADigit(sc.ch) || (sc.Match('.') && IsADigit(sc.chNext))) {
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_VISUALPROLOG_NUMBER);
|
2015-06-07 21:19:26 +00:00
|
|
|
} else if (isLowerLetter(sc.ch)) {
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_VISUALPROLOG_IDENTIFIER);
|
2015-06-07 21:19:26 +00:00
|
|
|
} else if (isUpperLetter(sc.ch)) {
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_VISUALPROLOG_VARIABLE);
|
2015-06-07 21:19:26 +00:00
|
|
|
} else if (sc.Match('_')) {
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_VISUALPROLOG_ANONYMOUS);
|
|
|
|
} else if (sc.Match('/', '*')) {
|
|
|
|
sc.SetState(SCE_VISUALPROLOG_COMMENT_BLOCK);
|
|
|
|
nestLevel = 1;
|
|
|
|
sc.Forward(); // Eat the * so it isn't used for the end of the comment
|
2015-06-07 21:19:26 +00:00
|
|
|
} else if (sc.Match('%')) {
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_VISUALPROLOG_COMMENT_LINE);
|
2015-06-07 21:19:26 +00:00
|
|
|
} else if (sc.Match('\'')) {
|
|
|
|
closingQuote = '\'';
|
|
|
|
sc.SetState(SCE_VISUALPROLOG_STRING);
|
|
|
|
} else if (sc.Match('"')) {
|
|
|
|
closingQuote = '"';
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_VISUALPROLOG_STRING);
|
2015-06-07 21:19:26 +00:00
|
|
|
} else if (sc.Match('#')) {
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_VISUALPROLOG_KEY_DIRECTIVE);
|
2015-06-07 21:19:26 +00:00
|
|
|
} else if (isoperator(static_cast<char>(sc.ch)) || sc.Match('\\')) {
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_VISUALPROLOG_OPERATOR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
sc.Complete();
|
|
|
|
styler.Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store both the current line's fold level and the next lines in the
|
|
|
|
// level store to make it easy to pick up with each increment
|
|
|
|
// and to make it possible to fiddle the current level for "} else {".
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
void SCI_METHOD LexerVisualProlog::Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) {
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
LexAccessor styler(pAccess);
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci_PositionU endPos = startPos + length;
|
2013-08-28 00:44:27 +00:00
|
|
|
int visibleChars = 0;
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci_Position currentLine = styler.GetLine(startPos);
|
2013-08-28 00:44:27 +00:00
|
|
|
int levelCurrent = SC_FOLDLEVELBASE;
|
|
|
|
if (currentLine > 0)
|
|
|
|
levelCurrent = styler.LevelAt(currentLine-1) >> 16;
|
|
|
|
int levelMinCurrent = levelCurrent;
|
|
|
|
int levelNext = levelCurrent;
|
|
|
|
char chNext = styler[startPos];
|
|
|
|
int styleNext = styler.StyleAt(startPos);
|
|
|
|
int style = initStyle;
|
2019-05-04 18:14:48 +00:00
|
|
|
for (Sci_PositionU i = startPos; i < endPos; i++) {
|
2013-08-28 00:44:27 +00:00
|
|
|
char ch = chNext;
|
|
|
|
chNext = styler.SafeGetCharAt(i + 1);
|
|
|
|
style = styleNext;
|
|
|
|
styleNext = styler.StyleAt(i + 1);
|
|
|
|
bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
|
|
|
|
if (style == SCE_VISUALPROLOG_OPERATOR) {
|
|
|
|
if (ch == '{') {
|
|
|
|
// Measure the minimum before a '{' to allow
|
|
|
|
// folding on "} else {"
|
|
|
|
if (levelMinCurrent > levelNext) {
|
|
|
|
levelMinCurrent = levelNext;
|
|
|
|
}
|
|
|
|
levelNext++;
|
|
|
|
} else if (ch == '}') {
|
|
|
|
levelNext--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!IsASpace(ch))
|
|
|
|
visibleChars++;
|
|
|
|
if (atEOL || (i == endPos-1)) {
|
|
|
|
int levelUse = levelCurrent;
|
|
|
|
int lev = levelUse | levelNext << 16;
|
|
|
|
if (levelUse < levelNext)
|
|
|
|
lev |= SC_FOLDLEVELHEADERFLAG;
|
|
|
|
if (lev != styler.LevelAt(currentLine)) {
|
|
|
|
styler.SetLevel(currentLine, lev);
|
|
|
|
}
|
|
|
|
currentLine++;
|
|
|
|
levelCurrent = levelNext;
|
|
|
|
levelMinCurrent = levelCurrent;
|
2019-05-04 18:14:48 +00:00
|
|
|
if (atEOL && (i == static_cast<Sci_PositionU>(styler.Length()-1))) {
|
2013-08-28 00:44:27 +00:00
|
|
|
// There is an empty line at end of file so give it same level and empty
|
|
|
|
styler.SetLevel(currentLine, (levelCurrent | levelCurrent << 16) | SC_FOLDLEVELWHITEFLAG);
|
|
|
|
}
|
|
|
|
visibleChars = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LexerModule lmVisualProlog(SCLEX_VISUALPROLOG, LexerVisualProlog::LexerFactoryVisualProlog, "visualprolog", visualPrologWordLists);
|