qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs arm.c ebnf.c swift.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs arm.c ebnf.c swift.c
Date: Fri, 07 Aug 2015 17:26:13 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        15/08/07 17:26:13

Modified files:
        .              : arm.c ebnf.c swift.c 

Log message:
        factorize code in colorizers

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/arm.c?cvsroot=qemacs&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/qemacs/ebnf.c?cvsroot=qemacs&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/qemacs/swift.c?cvsroot=qemacs&r1=1.3&r2=1.4

Patches:
Index: arm.c
===================================================================
RCS file: /sources/qemacs/qemacs/arm.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- arm.c       9 Aug 2014 17:31:50 -0000       1.3
+++ arm.c       7 Aug 2015 17:26:13 -0000       1.4
@@ -56,7 +56,7 @@
                                   unsigned int *str, int n, ModeDef *syn)
 {
     char keyword[MAX_KEYWORD_SIZE];
-    int i = 0, start = 0, c, w = 0, wn = 0, len;
+    int i = 0, start = 0, c, style, klen, w = 0, wn = 0;
     int colstate = cp->colorize_state;
 
     if (colstate & IN_ASM_TRAIL)
@@ -65,7 +65,9 @@
     for (; qe_isspace(str[i]); i++)
         continue;
 
-    for (w = i; i < n;) {
+    style = 0;
+    w = i;
+    while (i < n) {
         start = i;
         c = str[i++];
         switch (c) {
@@ -89,13 +91,13 @@
                 if (str[i] == '@')
                     break;
             }
-            SET_COLOR(str, start, i, ASM_STYLE_PREPROCESS);
-            continue;
+            style = ASM_STYLE_PREPROCESS;
+            break;
         case '@':
         comment:
             i = n;
-            SET_COLOR(str, start, i, ASM_STYLE_COMMENT);
-            continue;
+            style = ASM_STYLE_COMMENT;
+            break;
         case '\'':
         case '\"':
             /* parse string const */
@@ -105,14 +107,12 @@
                     break;
                 }
             }
-            SET_COLOR(str, start, i, ASM_STYLE_STRING);
-            continue;
+            style = ASM_STYLE_STRING;
+            break;
         case ';':       /* instruction separator */
             wn = 0;
             continue;
         default:
-            break;
-        }
         /* parse numbers */
         if (qe_isdigit(c)) {
             for (; qe_isalnum(str[i]) || str[i] == '.'; i++)
@@ -120,34 +120,40 @@
             if (str[i] == ':')
                 goto label;
             wn++;
-            SET_COLOR(str, start, i, ASM_STYLE_NUMBER);
-            continue;
+                style = ASM_STYLE_NUMBER;
+                break;
         }
         /* parse identifiers and keywords */
         if (qe_isalpha_(c)) {
         opcode:
-            len = 0;
-            keyword[len++] = qe_tolower(c);
+                klen = 0;
+                keyword[klen++] = qe_tolower(c);
             for (; qe_isalnum_(str[i]) || str[i] == '.'; i++) {
-                if (len < countof(keyword) - 1)
-                    keyword[len++] = qe_tolower(str[i]);
+                    if (klen < countof(keyword) - 1)
+                        keyword[klen++] = qe_tolower(str[i]);
             }
-            keyword[len] = '\0';
+                keyword[klen] = '\0';
             if (str[i] == ':') {
             label:
-                SET_COLOR(str, start, i, ASM_STYLE_LABEL);
-                continue;
+                    style = ASM_STYLE_LABEL;
+                    break;
             }
             if (++wn == 1) {
-                SET_COLOR(str, start, i, ASM_STYLE_OPCODE);
-                continue;
+                    style = ASM_STYLE_OPCODE;
+                    break;
             }
             if (strfind(syn->keywords, keyword)) {
-                SET_COLOR(str, start, i, ASM_STYLE_REGISTER);
+                    style = ASM_STYLE_REGISTER;
+                    break;
+                }
                 continue;
             }
             continue;
         }
+        if (style) {
+            SET_COLOR(str, start, i, style);
+            style = 0;
+        }
     }
     cp->colorize_state = colstate;
 }

Index: ebnf.c
===================================================================
RCS file: /sources/qemacs/qemacs/ebnf.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ebnf.c      19 Jun 2015 21:42:58 -0000      1.1
+++ ebnf.c      7 Aug 2015 17:26:13 -0000       1.2
@@ -73,6 +73,7 @@
     if (colstate & IN_EBNF_COMMENT3)
         goto in_comment3;
 
+    style = 0;
     while (i < n) {
         start = i;
         c = str[i++];
@@ -105,8 +106,8 @@
                 i = n;
             }
             style = EBNF_STYLE_COMMENT;
-            SET_COLOR(str, start, i, style);
-            continue;
+            break;
+
         case '/':
             if (str[i] == '*') {  /* C block comment */
                 colstate |= IN_EBNF_COMMENT3;
@@ -119,16 +120,16 @@
                         break;
                     }
                 }
-                SET_COLOR(str, start, i, EBNF_STYLE_COMMENT);
-                continue;
-            } else
+                style = EBNF_STYLE_COMMENT;
+                break;
+            }
             if (str[i] == '/') { /* line comment */
                 i = n;
-                SET_COLOR(str, start, i, EBNF_STYLE_COMMENT);
-                continue;
-            } else {
+                style = EBNF_STYLE_COMMENT;
                 break;
             }
+            continue;
+
         case '\'':
         case '`':
         case U_LEFT_SINGLE_QUOTATION_MARK:
@@ -138,8 +139,9 @@
                 if (c == '\'' || c == U_RIGHT_SINGLE_QUOTATION_MARK)
                     break;
             }
-            SET_COLOR(str, start, i, EBNF_STYLE_CHARCONST);
-            continue;
+            style = EBNF_STYLE_CHARCONST;
+            break;
+
         case '\"':
             /* parse quoted token */
             while (i < n) {
@@ -147,19 +149,18 @@
                 if (c == '\"')
                     break;
             }
-            SET_COLOR(str, start, i, EBNF_STYLE_STRING);
-            continue;
-        default:
+            style = EBNF_STYLE_STRING;
             break;
-        }
+
+        default:
         /* parse numbers */
         if (qe_isdigit(c)) {
             for (; i < n; i++) {
                 if (!qe_isalnum(str[i]) && str[i] != '.')
                     break;
             }
-            SET_COLOR(str, start, i, EBNF_STYLE_NUMBER);
-            continue;
+                style = EBNF_STYLE_NUMBER;
+                break;
         }
         /* parse identifiers and keywords */
         if (qe_isalpha_(c) || c == U_HORIZONTAL_ELLIPSIS) {
@@ -175,16 +176,22 @@
             }
             keyword[len] = '\0';
             if (strfind(syn->keywords, keyword)) {
-                SET_COLOR(str, start, i, EBNF_STYLE_KEYWORD);
-                continue;
+                    style = EBNF_STYLE_KEYWORD;
+                    break;
             }
             if (strfind(syn->types, keyword)) {
-                SET_COLOR(str, start, i, EBNF_STYLE_TYPE);
-                continue;
+                    style = EBNF_STYLE_TYPE;
+                    break;
+                }
+                style = EBNF_STYLE_IDENTIFIER;
+                break;
             }
-            SET_COLOR(str, start, i, EBNF_STYLE_IDENTIFIER);
             continue;
         }
+        if (style) {
+            SET_COLOR(str, start, i, style);
+            style = 0;
+        }
     }
 }
 

Index: swift.c
===================================================================
RCS file: /sources/qemacs/qemacs/swift.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- swift.c     7 Aug 2015 16:45:11 -0000       1.3
+++ swift.c     7 Aug 2015 17:26:13 -0000       1.4
@@ -179,29 +179,20 @@
 static void swift_colorize_line(QEColorizeContext *cp,
                                 unsigned int *str, int n, ModeDef *syn)
 {
-    int i = 0, start, level;
-    int c, state, style, klen, flavor;
-    int mode_flags;
+    int i = 0, start = 0, c, style, klen, level;
+    int state = cp->colorize_state;
     char kbuf[32];
 
-    mode_flags = syn->colorize_flags;
-    flavor = (mode_flags & CLANG_FLAVOR);
-
-    state = cp->colorize_state;
-    start = i;
-
-    c = 0;
-
     if (state) {
         /* if already in a state, go directly in the code parsing it */
         if (state & IN_C_COMMENT_D)
             goto parse_comment_d;
     }
 
+    style = 0;
     while (i < n) {
         start = i;
         c = str[i++];
-
         switch (c) {
         case '/':
             if (str[i] == '*') {
@@ -234,16 +225,17 @@
                      */
                     i++;
                 }
-                SET_COLOR(str, start, i, C_STYLE_COMMENT);
-                continue;
+                style = C_STYLE_COMMENT;
+                break;
             }
             if (str[i] == '/') {
                 /* end of line comment (include eol char, see above) */
                 i = n + 1;
-                SET_COLOR(str, start, i, C_STYLE_COMMENT);
-                continue;
-            }
+                style = C_STYLE_COMMENT;
             break;
+            }
+            continue;
+
         case '`':       /* `symbol` for reserved words */
         case '@':       /* @attribute */
             goto identifier;
@@ -261,14 +253,15 @@
                     break;
                 }
             }
-            SET_COLOR(str, start, i, C_STYLE_STRING);
-            continue;
+            style = C_STYLE_STRING;
+            break;
+
         default:
             if (qe_isdigit(c)) {
                 i -= 1;
                 i += swift_parse_number(str + i);
-                SET_COLOR(str, start, i, C_STYLE_NUMBER);
-                continue;
+                style = C_STYLE_NUMBER;
+                break;
             }
             if (is_swift_identifier_head(c)) {
             identifier:
@@ -276,24 +269,28 @@
                 i = start + klen;
 
                 if (strfind(syn->keywords, kbuf)) {
-                    SET_COLOR(str, start, i, C_STYLE_KEYWORD);
-                    continue;
+                    style = C_STYLE_KEYWORD;
+                    break;
                 }
                 if (strfind(syn->types, kbuf)) {
                     style = C_STYLE_TYPE;
-                    if (check_fcall(str, i) && flavor != CLANG_PIKE) {
+                    if (check_fcall(str, i)) {
                         /* function style cast */
                         style = C_STYLE_KEYWORD;
                     }
-                    SET_COLOR(str, start, i, style);
-                    continue;
+                    break;
                 }
                 if (check_fcall(str, i)) {
-                    SET_COLOR(str, start, i, C_STYLE_FUNCTION);
+                    style = C_STYLE_FUNCTION;
+                    break;
+                }
                     continue;
                 }
                 continue;
             }
+        if (style) {
+            SET_COLOR(str, start, i, style);
+            style = 0;
         }
     }
     cp->colorize_state = state;



reply via email to

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