From 325dc85b2c756d13b329dba4541fcb35feabdda9 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Wed, 23 Mar 2005 03:13:31 +0000 Subject: Fix syntax highlighting bug in the editor demo, and port changes to the CodeEditor widget in FLUID. Use the CodeEditor widget for the other code windows. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4163 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- fluid/CodeEditor.cxx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'fluid/CodeEditor.cxx') diff --git a/fluid/CodeEditor.cxx b/fluid/CodeEditor.cxx index 926f30506..f979ce107 100644 --- a/fluid/CodeEditor.cxx +++ b/fluid/CodeEditor.cxx @@ -138,8 +138,18 @@ void CodeEditor::style_parse(const char *text, char *style, int length) { *bufptr; const char *temp; + // Style letters: + // + // A - Plain + // B - Line comments + // C - Block comments + // D - Strings + // E - Directives + // F - Types + // G - Keywords + for (current = *style, col = 0, last = 0; length > 0; length --, text ++) { - if (current == 'B') current = 'A'; + if (current == 'B' || current == 'F' || current == 'G') current = 'A'; if (current == 'A') { // Check for directives, comments, strings, and keywords... if (col == 0 && *text == '#') { @@ -162,13 +172,13 @@ void CodeEditor::style_parse(const char *text, char *style, int length) { continue; } else if (*text == '\"') { current = 'D'; - } else if (!last && islower(*text)) { + } else if (!last && (islower(*text) || *text == '_')) { // Might be a keyword... for (temp = text, bufptr = buf; - islower(*temp) && bufptr < (buf + sizeof(buf) - 1); + (islower(*temp) || *temp == '_') && bufptr < (buf + sizeof(buf) - 1); *bufptr++ = *temp++); - if (!islower(*temp)) { + if (!islower(*temp) && *temp != '_') { *bufptr = '\0'; bufptr = buf; @@ -237,7 +247,7 @@ void CodeEditor::style_parse(const char *text, char *style, int length) { else *style++ = current; col ++; - last = isalnum(*text) || *text == '.'; + last = isalnum(*text) || *text == '_' || *text == '.'; if (*text == '\n') { // Reset column and possibly reset the style -- cgit v1.2.3