Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDE-569 Syntax highlight KEL #340

Merged
merged 1 commit into from Dec 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions EclEditor/CMakeLists.txt
@@ -1,14 +1,18 @@
project( ECLEDITOR )

set ( SRCS
lexgeneral.cxx
lexecl.cxx
lexsalt.cxx
lexesdl.cxx
lexkel.cxx

${SCINTILLA_INCLUDE_DIR}/include/SciLExer.h

${ECLEDITOR_SOURCE_DIR}/LexSALT.cxx
${SCINTILLA_INCLUDE_DIR}/lexers/LexESDL.cxx
${ECLEDITOR_SOURCE_DIR}/lexers/LexGENERAL.cxx
${ECLEDITOR_SOURCE_DIR}/lexers/LexSALT.cxx
${ECLEDITOR_SOURCE_DIR}/lexers/LexKEL.cxx
${ECLEDITOR_SOURCE_DIR}/lexers/LexESDL.cxx

${SCINTILLA_INCLUDE_DIR}/Src/AutoComplete.cxx
${SCINTILLA_INCLUDE_DIR}/Src/AutoComplete.h
Expand Down
2 changes: 2 additions & 0 deletions EclEditor/Catalogue.cxx
Expand Up @@ -81,9 +81,11 @@ int Scintilla_LinkLexers() {

//++Autogenerated -- run src/LexGen.py to regenerate
//**\(\tLINK_LEXER(\*);\n\)
LINK_LEXER(lmGENERAL);
LINK_LEXER(lmECL);
LINK_LEXER(lmESDL);
LINK_LEXER(lmSALT);
LINK_LEXER(lmKEL);

/*
LINK_LEXER(lmA68k);
Expand Down
20 changes: 8 additions & 12 deletions EclEditor/LexESDL.cxx
@@ -1,6 +1,6 @@
// Scintilla source code edit control
/** @file LexESDL.cxx
** Lexer for C++, C, Java, and JavaScript.
** Lexer for ESDL.
**/
// Copyright 1998-2005 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
Expand Down Expand Up @@ -98,7 +98,6 @@ static void ColouriseESDLDocSensitive(unsigned int startPos, int length, int ini
WordList &listAttributes = *keywordlists[2];

char s[1000];
int parens = 0;
bool checkword = false;

// look back to set chPrevNonWhite properly for better regex colouring
Expand Down Expand Up @@ -132,6 +131,7 @@ static void ColouriseESDLDocSensitive(unsigned int startPos, int length, int ini
sc.ForwardSetState(SCE_ESDL_DEFAULT);
}
break;
case SCE_ESDL_SEPARATOR:
case SCE_ESDL_STRUCTURE:
case SCE_ESDL_DATATYPE:
case SCE_ESDL_ATTRIBUTE:
Expand Down Expand Up @@ -168,19 +168,16 @@ static void ColouriseESDLDocSensitive(unsigned int startPos, int length, int ini
else if (sc.ch == '"') {
sc.SetState(SCE_ESDL_STRING);
}
else if (sc.ch == '(' || sc.ch == '<' || sc.ch == '{') {
else if (sc.ch == '(' || sc.ch == '<' || sc.ch == '{' || sc.ch == '[') {
checkword = true;
parens++;
}
else if (sc.ch == ')' || sc.ch == '>' || sc.ch == '}') {
parens--;
else if (sc.ch == ')' || sc.ch == '>' || sc.ch == '}' || sc.ch == ']') {
checkword = true;
}
else if (sc.ch == ' ') {
strtrim(s);
else if (sc.ch == ' ' || sc.ch == ',' || sc.ch == '.' || sc.ch == ';') {
checkword = true;
}
else if (sc.ch == '\r') {
strtrim(s);
else if (sc.ch == '\r' || sc.ch == '\n') {
checkword = true;
}
else if (sc.Match('/', '*')) {
Expand All @@ -196,7 +193,6 @@ static void ColouriseESDLDocSensitive(unsigned int startPos, int length, int ini
sc.SetState(SCE_ESDL_COMMENTLINE);
}
if (checkword) {
strtrim(s);
if (listStructures.InList(s)) {
sc.ChangeState(SCE_ESDL_STRUCTURE);
}
Expand All @@ -206,7 +202,7 @@ static void ColouriseESDLDocSensitive(unsigned int startPos, int length, int ini
else if (listAttributes.InList(s)) {
sc.ChangeState(SCE_ESDL_ATTRIBUTE);
}
sc.SetState(SCE_ESDL_DEFAULT);
sc.SetState(SCE_ESDL_SEPARATOR);
}
}
}
Expand Down
173 changes: 173 additions & 0 deletions EclEditor/LexGENERAL.cxx
@@ -0,0 +1,173 @@
// Scintilla source code edit control
/** @file LexGENERAL.cxx
** Lexer for general color preferences. Not an attribute type.
**/
// Copyright 1998-2005 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 <ctype.h>
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>

#ifdef _MSC_VER
#pragma warning(disable: 4786)
#endif
#ifdef __BORLANDC__
// Borland C++ displays warnings in vector header without this
#pragma option -w-ccc -w-rch
#endif

#include <string>
#include <vector>
#include <map>
#include <algorithm>

#include "ILexer.h"
#include "Scintilla.h"
#include "SciLexer.h"

#include "PropSetSimple.h"
#include "WordList.h"
#include "LexAccessor.h"
#include "Accessor.h"
#include "StyleContext.h"
#include "CharacterSet.h"
#include "LexerModule.h"
#include "OptionSet.h"

#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif

// Preconditions: sc.currentPos points to a character after '+' or '-'.
// The test for pos reaching 0 should be redundant,
// and is in only for safety measures.
// Limitation: this code will give the incorrect answer for code like
// a = b+++/ptn/...
// Putting a space between the '++' post-inc operator and the '+' binary op
// fixes this, and is highly recommended for readability anyway.
static bool FollowsPostfixOperator(StyleContext &sc, Accessor &styler) {
int pos = (int) sc.currentPos;
while (--pos > 0) {
char ch = styler[pos];
if (ch == '+' || ch == '-') {
return styler[pos - 1] == ch;
}
}
return false;
}

static void strtrim(char* str) {
int start = 0; // number of leading spaces
char* buffer = str;
while (*str && (*str == ' ' || *str == '\r' || *str == '\n' || *str == '\t'))
{
*str++;
++start;
}
while (*str++); // move to end of string
int end = str - buffer - 1;
while (end > 0 && (buffer[end - 1] == ' ' || buffer[end - 1] == '\n' || buffer[end - 1] == '\r' || buffer[end - 1] == '\t')) --end; // backup over trailing spaces
buffer[end] = 0; // remove trailing spaces
if (end <= start || start == 0) return; // exit if no leading spaces or string is now empty
str = buffer + start;
while ((*buffer++ = *str++)); // remove leading spaces: K&R
}

static void ColouriseGENERALDocSensitive(unsigned int startPos, int length, int initStyle, WordList *keywordlists[], Accessor &styler) {

WordList &headerList = *keywordlists[0];
WordList &thorList = *keywordlists[1];
WordList &hthorList = *keywordlists[2];
WordList &roxieList = *keywordlists[3];
WordList &localList = *keywordlists[4];

char s[1000];
bool checkword = false;
int linetype = 0;

StyleContext sc(startPos, length, initStyle, styler);
int line = 0;

for (; sc.More(); sc.Forward()) {
sc.GetCurrentLowered(s, sizeof(s));
strtrim(s);

// Determine if the current state should terminate.
switch (sc.state) {
case SCE_GEN_HEADER:
if (sc.chPrev == ':') {
sc.ChangeState(SCE_GEN_DEFAULT);
sc.SetState(SCE_GEN_DELIMITER);
if (linetype == SCE_GEN_CARET)
sc.ForwardSetState(SCE_GEN_CARET);
else
sc.ForwardSetState(SCE_GEN_DEFAULT);
}
break;
case SCE_GEN_CARET:
case SCE_GEN_THOR_BACKGROUND:
case SCE_GEN_HTHOR_BACKGROUND:
case SCE_GEN_ROXIE_BACKGROUND:
case SCE_GEN_LOCAL_BACKGROUND:
if (sc.atLineEnd)
{
sc.SetState(SCE_GEN_DEFAULT);
}
break;
}

if (sc.state == SCE_GEN_DEFAULT) {
checkword = false;
if (headerList.InList(s)) {
if (stricmp(s, "caret") == 0)
{
sc.SetState(SCE_GEN_HEADER);
linetype = SCE_GEN_CARET;
}
else if (stricmp(s, "target") == 0)
{
sc.ChangeState(SCE_GEN_HEADER);
linetype = SCE_GEN_TARGET;
}
}
else {
if (thorList.InList(s)) {
sc.ChangeState(SCE_GEN_THOR_BACKGROUND);
sc.SetState(SCE_GEN_THOR_BACKGROUND);
}
else if (hthorList.InList(s)) {
sc.ChangeState(SCE_GEN_HTHOR_BACKGROUND);
sc.SetState(SCE_GEN_HTHOR_BACKGROUND);
}
else if (roxieList.InList(s)) {
sc.ChangeState(SCE_GEN_ROXIE_BACKGROUND);
sc.SetState(SCE_GEN_ROXIE_BACKGROUND);
}
else if (localList.InList(s)) {
sc.ChangeState(SCE_GEN_LOCAL_BACKGROUND);
sc.SetState(SCE_GEN_LOCAL_BACKGROUND);
}
}
}
}
sc.Complete();
}

static void FoldGENERALDoc(unsigned int startPos, int length, int initStyle,
WordList *[], Accessor &styler) {
}

static const char * const generalWordLists[] = {
"Headers",
"Thor",
"HThor",
"Roxie",
"Local",
0,
};

LexerModule lmGENERAL(SCLEX_GENERAL, ColouriseGENERALDocSensitive, "general", FoldGENERALDoc, generalWordLists);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the goal of the General lexer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The general lexer is for non-language related color selections. I tried coding the "general" color settings without the lexer. After a 1 day trip down that road without success and everything broken beyond repair and only getting worse, I decided the easiest way to implement the non-language specific color preferences was to create a "general" lexer. It solved that problem quite nicely.