qemacs-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemacs-commit] qemacs qe.h clang.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs qe.h clang.c
Date: Thu, 01 May 2014 19:32:01 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/05/01 19:32:01

Modified files:
        .              : qe.h clang.c 

Log message:
        add D flavor for C colorizer

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.165&r2=1.166
http://cvs.savannah.gnu.org/viewcvs/qemacs/clang.c?cvsroot=qemacs&r1=1.59&r2=1.60

Patches:
Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.165
retrieving revision 1.166
diff -u -b -r1.165 -r1.166
--- qe.h        18 Apr 2014 21:04:40 -0000      1.165
+++ qe.h        1 May 2014 19:32:01 -0000       1.166
@@ -1961,6 +1961,7 @@
 #define CLANG_REGEX  0x0080
 #define CLANG_PHP    0x0100
 #define CLANG_GO     0x0200
+#define CLANG_D      0x0400
 
 void c_colorize_line(QEColorizeContext *cp,
                      unsigned int *str, int n, int mode_flags);

Index: clang.c
===================================================================
RCS file: /sources/qemacs/qemacs/clang.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -b -r1.59 -r1.60
--- clang.c     29 Apr 2014 22:29:56 -0000      1.59
+++ clang.c     1 May 2014 19:32:01 -0000       1.60
@@ -102,6 +102,29 @@
     "uint|uint16|uint32|uint64|uint8|uintptr|"
 };
 
+static const char d_keywords[] = {
+    "abstract|alias|align|asm|assert|auto|body|break|"
+    "case|cast|catch|class|const|continue|debug|default|"
+    "delegate|deprecated|do|else|enum|export|extern|false|"
+    "final|finally|for|foreach|foreach_reverse|function|goto|"
+    "if|immutable|import|in|inout|int|interface|invariant|is|"
+    "lazy|mixin|module|new|nothrow|null|out|override|package|"
+    "pragma|private|protected|public|pure|ref|return|scope|shared|"
+    "static|struct|super|switch|synchronized|template|this|throw|"
+    "true|try|typeid|typeof|union|unittest|version|while|with|"
+    "delete|typedef|volatile|"  /* deprecated */
+    "macro|"    /* reserved, unused */
+    "__FILE__|__MODULE__|__LINE__|__FUNCTION__|__PRETTY_FUNCTION__|"
+    "__gshared|__traits|__vector|__parameters|"
+    "__DATE__|__EOF__|__TIME__|__TIMESPAMP__|__VENDOR__|__VERSION__|"
+};
+
+static const char d_types[] = {
+    "bool|byte|ubyte|short|ushort|int|uint|long|ulong|char|wchar|dchar|"
+    "float|double|real|ifloat|idouble|ireal|cfloat|cdouble|creal|void|"
+    "|cent|ucent|string|wstring|dstring|size_t|ptrdiff_t|"
+};
+
 static const char c_mode_extensions[] = {
     "c|h|C|H|"          /* C language */
     "y|l|lex|"          /* yacc, lex */
@@ -114,6 +137,7 @@
     "pcc|"              /* Oracle C++ */
     "cal|"              /* GNU Calc */
     "go|"               /* Go language */
+    "d|di|"             /* D language */
 };
 
 /* grab a C identifier from a uint buf, stripping color.
@@ -163,12 +187,14 @@
     IN_C_PREPROCESS = 0x20,  /* preprocessor directive with \ at EOL */
     IN_C_REGEX      = 0x40,  /* regex */
     IN_C_CHARCLASS  = 0x80,  /* regex char class */
+    IN_C_COMMENT_D  = 0x700, /* nesting D comment level (max 7 deep) */
+    IN_C_COMMENT_D_SHIFT = 8,
 };
 
 void c_colorize_line(QEColorizeContext *cp,
                      unsigned int *str, int n, int mode_flags)
 {
-    int i = 0, start, i1, i2, indent;
+    int i = 0, start, i1, i2, indent, level;
     int c, state, style, style0, style1, type_decl, klen, delim;
     char kbuf[32];
 
@@ -193,6 +219,8 @@
             goto parse_comment;
         if (state & IN_C_COMMENT1)
             goto parse_comment1;
+        if (state & IN_C_COMMENT_D)
+            goto parse_comment_d;
         if (state & IN_C_STRING)
             goto parse_string;
         if (state & IN_C_STRING_Q)
@@ -274,12 +302,46 @@
                 SET_COLOR(str, start, i, C_STYLE_REGEX);
                 continue;
             }
+            if ((mode_flags & CLANG_D) && (str[i] == '+')) {
+                /* D language nesting long comment */
+                i++;
+                state |= (1 << IN_C_COMMENT_D_SHIFT);
+            parse_comment_d:
+                style = C_STYLE_COMMENT;
+                level = (state & IN_C_COMMENT_D) >> IN_C_COMMENT_D_SHIFT;
+                while (i < n) {
+                    if (str[i] == '/' && str[i + 1] == '+') {
+                        i += 2;
+                        level++;
+                    } else
+                    if (str[i] == '+' && str[i + 1] == '/') {
+                        i += 2;
+                        level--;
+                        if (level == 0) {
+                            state &= ~IN_C_COMMENT;
+                            style = style0;
+                            break;
+                        }
+                    } else {
+                        i++;
+                    }
+                }
+                state = (state & ~IN_C_COMMENT_D) |
+                        (min(level, 7) << IN_C_COMMENT_D_SHIFT);
+                SET_COLOR(str, start, i, C_STYLE_COMMENT);
+                continue;
+            }
             break;
         case '#':       /* preprocessor */
             if (mode_flags & (CLANG_C | CLANG_CPP | CLANG_OBJC)) {
                 state = IN_C_PREPROCESS;
                 style = style0 = C_STYLE_PREPROCESS;
             }
+            if (mode_flags & CLANG_D) {
+                /* only #line is supported, but can occur anywhere */
+                state = IN_C_PREPROCESS;
+                style = style0 = C_STYLE_PREPROCESS;
+            }
             if (mode_flags & CLANG_PHP) {
                 goto parse_comment1;
             }
@@ -296,6 +358,13 @@
                 }
             }
             goto normal;
+        // case 'r':
+            /* XXX: D language r" wysiwyg chars " */
+        // case 'X':
+            /* XXX: D language X" hex string chars " */
+        // case 'q':
+            /* XXX: D language q" delim wysiwyg chars delim " */
+            /* XXX: D language q{ tokens } */
         case '\'':      /* character constant */
         parse_string_q:
             state |= IN_C_STRING_Q;
@@ -303,7 +372,7 @@
             delim = '\'';
             goto string;
         case '`':
-            if (mode_flags & CLANG_GO) {
+            if (mode_flags & (CLANG_GO | CLANG_D)) {
                 /* go language multi-line string, no escape sequences */
             parse_string_bq:
                 state |= IN_C_STRING_BQ;
@@ -342,6 +411,11 @@
                     break;
                 }
             }
+            if (mode_flags & CLANG_D) {
+                /* ignore optional string postfix */
+                if (qe_findchar("cwd", str[i]))
+                    i++;
+            }
             if (state & IN_C_PREPROCESS)
                 style1 = C_STYLE_PREPROCESS;
             SET_COLOR(str, start, i, style1);
@@ -363,6 +437,8 @@
                 break;
             if (qe_isdigit(c)) {
                 /* XXX: should parse actual number syntax */
+                /* XXX: D lang ignores embedded '_' and accepts 'l'
+                 * 'u' or 'U' 'f' or 'F', 'i' suffixes */
                 while (qe_isalnum(str[i]) || str[i] == '.') {
                     i++;
                 }
@@ -381,6 +457,7 @@
                 ||  ((mode_flags & CLANG_JS) && strfind(js_keywords, kbuf))
                 ||  ((mode_flags & CLANG_PHP) && strfind(php_keywords, kbuf))
                 ||  ((mode_flags & CLANG_GO) && strfind(go_keywords, kbuf))
+                ||  ((mode_flags & CLANG_D) && strfind(d_keywords, kbuf))
                    ) {
                     SET_COLOR(str, start, i, C_STYLE_KEYWORD);
                     continue;
@@ -400,6 +477,7 @@
                 ||  ((mode_flags & CLANG_JS) && strfind(js_types, kbuf))
                 ||  ((mode_flags & CLANG_PHP) && strfind(php_types, kbuf))
                 ||  ((mode_flags & CLANG_GO) && strfind(go_types, kbuf))
+                ||  ((mode_flags & CLANG_D) && strfind(d_types, kbuf))
                    ) {
                     /* if not cast, assume type declaration */
                     if (str[i2] != ')') {
@@ -450,6 +528,7 @@
     /* strip state if not overflowing from a comment */
     if (!(state & IN_C_COMMENT) && n > 0 && ((str[n - 1] & CHAR_MASK) != '\\'))
         state &= ~(IN_C_COMMENT1 | IN_C_PREPROCESS);
+
     cp->colorize_state = state;
 }
 
@@ -1005,6 +1084,10 @@
     if (match_extension(s->b->filename, "go")) {
         s->mode_name = "Go";
         s->mode_flags = CLANG_GO;
+    } else
+    if (match_extension(s->b->filename, "d|di")) {
+        s->mode_name = "D";
+        s->mode_flags = CLANG_D;
     }
     return 0;
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]