Code editor lexer configuration files started.

This commit is contained in:
Scott Duensing 2023-01-28 19:12:50 -06:00
parent bc108fd73a
commit f274d56d0a
3 changed files with 276 additions and 39 deletions

View file

@ -31,6 +31,7 @@
#define BUILD_SETTINGS_VERSION "1.0" // Used for file format versioning. #define BUILD_SETTINGS_VERSION "1.0" // Used for file format versioning.
#define PROJECT_VERSION "1.0" // Used for file format versioning. #define PROJECT_VERSION "1.0" // Used for file format versioning.
#define LEXER_VERSION "1.0" // Used for file format versioning.
#define VICTOR_VERSION "1.0" // Used for file format versioning. #define VICTOR_VERSION "1.0" // Used for file format versioning.

View file

@ -26,6 +26,12 @@
#include "scintillaHeaders.h" #include "scintillaHeaders.h"
typedef struct SyntaxHighlightingS {
int style;
int color;
char *description;
} SyntaxHighlightingT;
typedef struct EditorDataS { typedef struct EditorDataS {
WindowDataT windowData; WindowDataT windowData;
GtkWidget *boxForEditor; GtkWidget *boxForEditor;
@ -42,9 +48,10 @@ static int _nextEditorId = 0;
EVENT void editorEditorNotify(GtkWidget *sciWidget, gint ctrlID, struct SCNotification *notifyData, gpointer userData); EVENT void editorEditorNotify(GtkWidget *sciWidget, gint ctrlID, struct SCNotification *notifyData, gpointer userData);
static void loadEditorConfig(char *lexer, EditorDataT *self);
EVENT gboolean winEditorClose(GtkWidget *object, gpointer userData); EVENT gboolean winEditorClose(GtkWidget *object, gpointer userData);
static void winEditorDelete(gpointer userData); static void winEditorDelete(gpointer userData);
static void writeEditorConfig(char *lexer, EditorDataT *self);
EVENT void editorEditorNotify(GtkWidget *sciWidget, gint ctrlID, struct SCNotification *notifyData, gpointer userData) { EVENT void editorEditorNotify(GtkWidget *sciWidget, gint ctrlID, struct SCNotification *notifyData, gpointer userData) {
@ -74,6 +81,53 @@ EVENT void editorEditorNotify(GtkWidget *sciWidget, gint ctrlID, struct SCNotifi
} }
static void loadEditorConfig(char *lexer, EditorDataT *self) {
char *config = NULL;
FILE *in = NULL;
char *line = NULL;
size_t len = 0;
char *c = NULL;
config = utilCreateString("%s%cjoeydev%ceditor-%s.conf", g_get_user_config_dir(), UTIL_PATH_CHAR, UTIL_PATH_CHAR, lexer);
if (!utilFileExists(config)) {
// Nothing to load.
DEL(config);
return;
}
in = fopen(config, "rt");
DEL(config);
if (in) {
// Load config.
utilEnsureBufferSize(&line, &len, 1024); // Not technically needed, but fixes a pointer warning from memmaker.
while (getline(&line, &len, in) != -1) {
if (strlen(line) > 0) line[strlen(line) - 1] = 0;
c = utilGetToken(line, " ", "\"", "\"");
utilDequote(c);
// Is this a 'style' line?
if (strcasecmp(c, "style") == 0) {
}
// Is this a 'property' line?
if (strcasecmp(c, "property") == 0) {
}
// Is this a 'keywords' line?
if (strcasecmp(c, "keywords") == 0) {
}
}
DEL(line);
fclose(in);
}
}
EVENT gboolean winEditorClose(GtkWidget *object, gpointer userData) { EVENT gboolean winEditorClose(GtkWidget *object, gpointer userData) {
// userData is not reliable due to menuVectorFileClose and util indirectly calling us. // userData is not reliable due to menuVectorFileClose and util indirectly calling us.
EditorDataT *self = (EditorDataT *)utilGetWindowData(object); EditorDataT *self = (EditorDataT *)utilGetWindowData(object);
@ -106,6 +160,25 @@ void winEditorCreate(void) {
NULL, NULL,
NULL NULL
}; };
SyntaxHighlightingT cpp[] = {
{ 0, 0x000000, "White Space" },
{ 1, 0x80807f,"Comment: /* */" },
{ 2, 0x80807f,"Line Comment: //" },
{ 3, 0x80807f,"Doc comment: block comments beginning with /** or /*!" },
{ 4, 0x6897b9,"Number" },
{ 5, 0xcc7832,"Keyword" },
{ 6, 0x6a8759,"Double-quoted string" },
{ 7, 0x6a8759,"Single-quoted string" },
{ 9, 0x8f8b25,"Preprocessor" },
{ 10, 0xffffff,"Operators" },
{ 11, 0x94b5c6,"Identifiers" },
{ 12, 0xff0000,"Error: End of line where string is not closed" },
{ 15, 0x80807f,"Doc Comment Line: line comments beginning with /// or //!." },
{ 25, 0x00ff00, "User defined literals" },
{ 27, 0x0000ff, "Escape sequence" },
{ 0, 0x000000, NULL }
};
int i;
// Set up instance data. // Set up instance data.
self = NEW(EditorDataT); self = NEW(EditorDataT);
@ -157,44 +230,13 @@ void winEditorCreate(void) {
self->pLexer = CreateLexer("cpp"); self->pLexer = CreateLexer("cpp");
SSM(SCI_SETILEXER, 0, (sptr_t)self->pLexer); SSM(SCI_SETILEXER, 0, (sptr_t)self->pLexer);
/* // For now, just CPP.
#define SCE_C_DEFAULT 0 for (i=0; cpp[i].description != NULL; i++) {
#define SCE_C_COMMENT 1 SSM(SCI_STYLESETFORE, cpp[i].style, cpp[i].color);
#define SCE_C_COMMENTLINE 2 }
#define SCE_C_COMMENTDOC 3
#define SCE_C_NUMBER 4
#define SCE_C_WORD 5
#define SCE_C_STRING 6
#define SCE_C_CHARACTER 7
#define SCE_C_UUID 8
#define SCE_C_PREPROCESSOR 9
#define SCE_C_OPERATOR 10
#define SCE_C_IDENTIFIER 11
#define SCE_C_STRINGEOL 12
#define SCE_C_VERBATIM 13
#define SCE_C_REGEX 14
#define SCE_C_COMMENTLINEDOC 15
#define SCE_C_WORD2 16
#define SCE_C_COMMENTDOCKEYWORD 17
#define SCE_C_COMMENTDOCKEYWORDERROR 18
#define SCE_C_GLOBALCLASS 19
#define SCE_C_STRINGRAW 20
#define SCE_C_TRIPLEVERBATIM 21
#define SCE_C_HASHQUOTEDSTRING 22
#define SCE_C_PREPROCESSORCOMMENT 23
#define SCE_C_PREPROCESSORCOMMENTDOC 24
#define SCE_C_USERLITERAL 25
#define SCE_C_TASKMARKER 26
#define SCE_C_ESCAPESEQUENCE 27
*/
SSM(SCI_STYLESETFORE, SCE_C_PREPROCESSOR, 0x0080ff); writeEditorConfig("cpp", self);
SSM(SCI_STYLESETFORE, SCE_C_COMMENT, 0x00FF00); loadEditorConfig("cpp", self);
SSM(SCI_STYLESETFORE, SCE_C_COMMENTLINE, 0x00FF00);
SSM(SCI_STYLESETFORE, SCE_C_NUMBER, 0xFFFF00);
SSM(SCI_STYLESETFORE, SCE_C_WORD, 0xFF0000);
SSM(SCI_STYLESETFORE, SCE_C_STRING, 0xFF00FF);
SSM(SCI_STYLESETBOLD, SCE_C_OPERATOR, 1);
// Connect editor to our code. // Connect editor to our code.
g_signal_connect(G_OBJECT(self->editor), "sci-notify", G_CALLBACK(editorEditorNotify), self); g_signal_connect(G_OBJECT(self->editor), "sci-notify", G_CALLBACK(editorEditorNotify), self);
@ -214,3 +256,109 @@ static void winEditorDelete(gpointer userData) {
DEL(self); DEL(self);
} }
static void writeEditorConfig(char *lexer, EditorDataT *self) {
char *name = NULL;
char *tags = NULL;
char *description = NULL;
char *config = NULL;
FILE *out = NULL;
int result = -1;
int size = -1;
int x;
config = utilCreateString("%s%cjoeydev%ceditor-%s.conf", g_get_user_config_dir(), UTIL_PATH_CHAR, UTIL_PATH_CHAR, lexer);
if (utilFileExists(config)) {
// Don't clobber existing files.
DEL(config);
return;
}
out = fopen(config, "wt");
DEL(config);
if (out) {
// Header
fprintf(out, "%s\n", LEXER_VERSION);
fprintf(out, "------------------------------------------------------------------------------\n");
// Styles
result = SSM(SCI_GETNAMEDSTYLES, 0, 0);
if (result > 0) {
for (x = 0; x < result; x++) {
size = SSM(SCI_NAMEOFSTYLE, x, 0);
name = (char *)malloc(size + 1);
SSM(SCI_NAMEOFSTYLE, x, (sptr_t)name);
size = SSM(SCI_TAGSOFSTYLE, x, 0);
tags = (char *)malloc(size + 1);
SSM(SCI_TAGSOFSTYLE, x, (sptr_t)tags);
size = SSM(SCI_DESCRIPTIONOFSTYLE, x, 0);
description = (char *)malloc(size + 1);
SSM(SCI_DESCRIPTIONOFSTYLE, x, (sptr_t)description);
if (strlen(tags) > 0) {
fprintf(out, "style %d \"%s\" \"%s\" fore 0xffffff\n", x, tags, description);
}
DEL(description);
DEL(tags);
DEL(name);
}
}
fprintf(out, "\n");
// Properties
size = SSM(SCI_PROPERTYNAMES, 0, 0);
name = (char *)malloc(size + 1);
SSM(SCI_PROPERTYNAMES, 0, (sptr_t)name);
tags = strtok(name, "\n");
do {
size = SSM(SCI_DESCRIBEPROPERTY, (sptr_t)tags, 0);
description = (char *)malloc(size + 1);
SSM(SCI_DESCRIBEPROPERTY, (sptr_t)tags, (sptr_t)description);
result = SSM(SCI_PROPERTYTYPE, (sptr_t)tags, 0);
fprintf(out, "property ");
switch (result) {
case SC_TYPE_BOOLEAN:
fprintf(out, "boolean");
size = SSM(SCI_GETPROPERTYINT, (sptr_t)tags, 0);
config = utilCreateString("%s", size ? "true" : "false");
break;
case SC_TYPE_STRING:
fprintf(out, "string");
//***TODO*** This doesn't appear to be working.
size = SSM(SCI_GETPROPERTY, (sptr_t)tags, 0);
config = (char *)malloc(size + 1);
SSM(SCI_GETPROPERTY, (sptr_t)tags, (sptr_t)config);
break;
case SC_TYPE_INTEGER:
fprintf(out, "integer");
size = SSM(SCI_GETPROPERTYINT, (sptr_t)tags, 0);
config = utilCreateString("%d", size);
break;
}
fprintf(out, " %s \"%s\" %s\n", tags, description, config);
DEL(config);
DEL(description);
tags = strtok(NULL, "\n");
} while (tags != NULL);
DEL(name);
fprintf(out, "\n");
// Keyword Sets
size = SSM(SCI_DESCRIBEKEYWORDSETS, 0, 0);
name = (char *)malloc(size + 1);
SSM(SCI_DESCRIBEKEYWORDSETS, 0, (sptr_t)name);
tags = strtok(name, "\n");
size = 0;
do {
fprintf(out, "keywords %d \"%s\"\n", size, tags);
size++;
tags = strtok(NULL, "\n");
} while (tags != NULL);
DEL(name);
fclose(out);
}
}

88
ui/editor-cpp.conf Normal file
View file

@ -0,0 +1,88 @@
1.0
------------------------------------------------------------------------------
style 0 "default" "White space" fore 0x6272a4
style 1 "comment" "Comment: /* */." fore 0x6272a4 bold
style 2 "comment line" "Line Comment: //." fore 0x6272a4 bold
style 3 "comment documentation" "Doc comment: block comments beginning with /** or /*!" fore 0x6272a4 bold
style 4 "literal numeric" "Number" fore 0xbd93f9
style 5 "keyword" "Keyword" fore 0xff79c6 bold
style 6 "literal string" "Double quoted string" fore 0xf1fa8c
style 7 "literal string character" "Single quoted string" fore 0xf1fa8c
style 8 "literal uuid" "UUIDs (only in IDL)" fore 0xffffff
style 9 "preprocessor" "Preprocessor" fore 0xff79c6
style 10 "operator" "Operators" fore 0xffffff
style 11 "identifier" "Identifiers" fore 0x50fa7b
style 12 "error literal string" "End of line where string is not closed" fore 0xff0000
style 13 "literal string multiline raw" "Verbatim strings for C#" fore 0xf1fa8c
style 14 "literal regex" "Regular expressions for JavaScript" fore 0xffffff
style 15 "comment documentation line" "Doc Comment Line: line comments beginning with /// or //!." fore 0x6272a4 bold
style 16 "identifier" "Keywords2" fore 0xffb86c bold
style 17 "comment documentation keyword" "Comment keyword" fore 0xffffff
style 18 "error comment documentation keyword" "Comment keyword error" fore 0xffffff
style 19 "identifier" "Global class" fore 0xffffff
style 20 "literal string multiline raw" "Raw strings for C++0x" fore 0xffffff
style 21 "literal string multiline raw" "Triple-quoted strings for Vala" fore 0xffffff
style 22 "literal string" "Hash-quoted strings for Pike" fore 0xffffff
style 23 "comment preprocessor" "Preprocessor stream comment" fore 0xffffff
style 24 "comment preprocessor documentation" "Preprocessor stream doc comment" fore 0xffffff
style 25 "literal" "User defined literals" fore 0xffb86c
style 26 "comment taskmarker" "Task Marker" fore 0xffffff
style 27 "literal string escapesequence" "Escape sequence" fore 0xffffff
style 64 "inactive default" "" fore 0xffffff
style 65 "inactive comment" "" fore 0xffffff
style 66 "inactive comment line" "" fore 0xffffff
style 67 "inactive comment documentation" "" fore 0xffffff
style 68 "inactive literal numeric" "" fore 0xffffff
style 69 "inactive keyword" "" fore 0xffffff
style 70 "inactive literal string" "" fore 0xffffff
style 71 "inactive literal string character" "" fore 0xffffff
style 72 "inactive literal uuid" "" fore 0xffffff
style 73 "inactive preprocessor" "" fore 0xffffff
style 74 "inactive operator" "" fore 0xffffff
style 75 "inactive identifier" "" fore 0xffffff
style 76 "inactive error literal string" "" fore 0xffffff
style 77 "inactive literal string multiline raw" "" fore 0xffffff
style 78 "inactive literal regex" "" fore 0xffffff
style 79 "inactive comment documentation line" "" fore 0xffffff
style 80 "inactive identifier" "" fore 0xffffff
style 81 "inactive comment documentation keyword" "" fore 0xffffff
style 82 "inactive error comment documentation keyword" "" fore 0xffffff
style 83 "inactive identifier" "" fore 0xffffff
style 84 "inactive literal string multiline raw" "" fore 0xffffff
style 85 "inactive literal string multiline raw" "" fore 0xffffff
style 86 "inactive literal string" "" fore 0xffffff
style 87 "inactive comment preprocessor" "" fore 0xffffff
style 88 "inactive comment preprocessor documentation" "" fore 0xffffff
style 89 "inactive literal" "" fore 0xffffff
style 90 "inactive comment taskmarker" "" fore 0xffffff
style 91 "inactive literal string escapesequence" "" fore 0xffffff
property boolean styling.within.preprocessor "For C++ code, determines whether all preprocessor code is styled in the preprocessor style (0, the default) or only from the initial # to the end of the command word(1)." false
property boolean lexer.cpp.allow.dollars "Set to 0 to disallow the '$' character in identifiers with the cpp lexer." false
property boolean lexer.cpp.track.preprocessor "Set to 1 to interpret #if/#else/#endif to grey out code that is not active." true
property boolean lexer.cpp.update.preprocessor "Set to 1 to update preprocessor definitions when #define found." true
property boolean lexer.cpp.verbatim.strings.allow.escapes "Set to 1 to allow verbatim strings to contain escape sequences." true
property boolean lexer.cpp.triplequoted.strings "Set to 1 to enable highlighting of triple-quoted strings." false
property boolean lexer.cpp.hashquoted.strings "Set to 1 to enable highlighting of hash-quoted strings." false
property boolean lexer.cpp.backquoted.strings "Set to 1 to enable highlighting of back-quoted raw strings ." false
property boolean lexer.cpp.escape.sequence "Set to 1 to enable highlighting of escape sequences in strings" true
property boolean fold "" true
property boolean fold.cpp.syntax.based "Set this property to 0 to disable syntax based folding." true
property boolean fold.comment "This option enables folding multi-line comments and explicit fold points when using the C++ lexer. Explicit fold points allows adding extra folding by placing a //{ comment at the start and a //} at the end of a section that should fold." true
property boolean fold.cpp.comment.multiline "Set this property to 0 to disable folding multi-line comments when fold.comment=1." true
property boolean fold.cpp.comment.explicit "Set this property to 0 to disable folding explicit fold points when fold.comment=1." true
property string fold.cpp.explicit.start "The string to use for explicit fold start points, replacing the standard //{." "//{"
property string fold.cpp.explicit.end "The string to use for explicit fold end points, replacing the standard //}." "//}"
property boolean fold.cpp.explicit.anywhere "Set this property to 1 to enable explicit fold points anywhere, not just in line comments." false
property boolean fold.cpp.preprocessor.at.else "This option enables folding on a preprocessor #else or #endif line of an #if statement." true
property boolean fold.preprocessor "This option enables folding preprocessor directives when using the C++ lexer. Includes C#'s explicit #region and #endregion folding directives." false
property boolean fold.compact "" false
property boolean fold.at.else "This option enables C++ folding on a "} else {" line of an if statement." true
keywords 0 "Primary keywords and identifiers" auto break case char const continue default do double else enum extern float for goto if inline int long nullptr register restrict return short signed sizeof static struct switch typedef union unsigned void volitile while
keywords 1 "Secondary keywords and identifiers" jlFree jlMalloc jlRealloc jlDisplayBorder jlDisplayPresent jlDrawBlit8x8 jlDrawBlit8x8a jlDrawBlitMap jlDrawBox jlDrawBoxFilled jlDrawCircle jlDrawClear jlDrawColorGet jlDrawColorSet jlDrawEllipse jlDrawFill jlDrawFillTo jlDrawLine jlDrawPixelGet jlDrawPixelSet jlSurfaceGet jlSurfaceSet jlGameGetAxis jlGameGetButton jlImgCopy jlImgCreate jlImgDisplay jlImgFree jlImgLoad jlImgSave jlImgSurfaceGet jlKeyPressed jlKeyRead jlKeyWaitForAny jlModContinue jlModFree jlModIsPlaying jlModLoad jlModPause jlModPlay jlModStop jlModVolume jlPaletteDefault jlPaletteSet jlPaletteSetFromImg jlSoundFree jlSoundIsPlaying jlSoundLoad jlSoundPlay jlSoundStop jlSoundSwapChannels jlStnFree jlStnLoad jlUtilByteSwap jlUtilDie jlUtilIdle jlUtilInputRead jlUtilIsOdd jlUtilMakePathname jlUtilMustExit jlUtilNibbleSwap jlUtilRandom jlUtilRandomSeedGet jlUtilRandomSeedSet jlUtilSay jlUtilSleep jlUtilStackPop jlUtilStackPush jlUtilTimer jlUtilTimeSpan jlUtilTitleSet jlVecDisplay jlVecFree jlVecLoad
keywords 2 "Documentation comment keywords"
keywords 3 "Global classes and typedefs" jbool jbyte jint16 jint32 juint16 juint32 jlSurfaceT jlSoundChannelE jlBorderColorE jlColorT jlPixelPair jlSoundT jlModT jlImgT jlStnT jlStackT jlVecT
keywords 4 "Preprocessor definitions" jfalse jtrue JINT16_MIN JINT16_MAX JUINT16_MIN JUINT16_MAX JINT32_MIN JINT32_MAX JUINT32_MIN JUINT32_MAX JOEY_DISPLAY JOEY_INPUT_NONE JOEY_INPUT_UP JOEY_INPUT_DOWN JOEY_INPUT_LEFT JOEY_INPUT_RIGHT JOEY_INPUT_PRIMARY JOEY_INPUT_SECONDARY JOEY_LITTLE_ENDIAN JOEY_BIG_ENDIAN JOEY_PATH_SEPARATOR JOEY_PC JOEY_LINUX JOEY_WINDOWS JOEY_MACOS JOEY_IIGS JOEY_AMIGA JOEY_BEOS JOEY_HAIKU JOEY_ST JOEY_DEBUG
keywords 5 "Task marker and error marker keywords"