factorize code in colorizers
This commit is contained in:
parent
04bc922185
commit
5cc02fc9c7
3 changed files with 119 additions and 109 deletions
86
arm.c
86
arm.c
|
|
@ -56,7 +56,7 @@ static void arm_asm_colorize_line(QEColorizeContext *cp,
|
|||
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 @@ static void arm_asm_colorize_line(QEColorizeContext *cp,
|
|||
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 @@ static void arm_asm_colorize_line(QEColorizeContext *cp,
|
|||
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,49 +107,53 @@ static void arm_asm_colorize_line(QEColorizeContext *cp,
|
|||
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++)
|
||||
continue;
|
||||
if (str[i] == ':')
|
||||
goto label;
|
||||
wn++;
|
||||
SET_COLOR(str, start, i, ASM_STYLE_NUMBER);
|
||||
continue;
|
||||
}
|
||||
/* parse identifiers and keywords */
|
||||
if (qe_isalpha_(c)) {
|
||||
opcode:
|
||||
len = 0;
|
||||
keyword[len++] = qe_tolower(c);
|
||||
for (; qe_isalnum_(str[i]) || str[i] == '.'; i++) {
|
||||
if (len < countof(keyword) - 1)
|
||||
keyword[len++] = qe_tolower(str[i]);
|
||||
/* parse numbers */
|
||||
if (qe_isdigit(c)) {
|
||||
for (; qe_isalnum(str[i]) || str[i] == '.'; i++)
|
||||
continue;
|
||||
if (str[i] == ':')
|
||||
goto label;
|
||||
wn++;
|
||||
style = ASM_STYLE_NUMBER;
|
||||
break;
|
||||
}
|
||||
keyword[len] = '\0';
|
||||
if (str[i] == ':') {
|
||||
label:
|
||||
SET_COLOR(str, start, i, ASM_STYLE_LABEL);
|
||||
continue;
|
||||
}
|
||||
if (++wn == 1) {
|
||||
SET_COLOR(str, start, i, ASM_STYLE_OPCODE);
|
||||
continue;
|
||||
}
|
||||
if (strfind(syn->keywords, keyword)) {
|
||||
SET_COLOR(str, start, i, ASM_STYLE_REGISTER);
|
||||
/* parse identifiers and keywords */
|
||||
if (qe_isalpha_(c)) {
|
||||
opcode:
|
||||
klen = 0;
|
||||
keyword[klen++] = qe_tolower(c);
|
||||
for (; qe_isalnum_(str[i]) || str[i] == '.'; i++) {
|
||||
if (klen < countof(keyword) - 1)
|
||||
keyword[klen++] = qe_tolower(str[i]);
|
||||
}
|
||||
keyword[klen] = '\0';
|
||||
if (str[i] == ':') {
|
||||
label:
|
||||
style = ASM_STYLE_LABEL;
|
||||
break;
|
||||
}
|
||||
if (++wn == 1) {
|
||||
style = ASM_STYLE_OPCODE;
|
||||
break;
|
||||
}
|
||||
if (strfind(syn->keywords, keyword)) {
|
||||
style = ASM_STYLE_REGISTER;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (style) {
|
||||
SET_COLOR(str, start, i, style);
|
||||
style = 0;
|
||||
}
|
||||
}
|
||||
cp->colorize_state = colstate;
|
||||
}
|
||||
|
|
|
|||
93
ebnf.c
93
ebnf.c
|
|
@ -73,6 +73,7 @@ static void ebnf_colorize_line(QEColorizeContext *cp,
|
|||
if (colstate & IN_EBNF_COMMENT3)
|
||||
goto in_comment3;
|
||||
|
||||
style = 0;
|
||||
while (i < n) {
|
||||
start = i;
|
||||
c = str[i++];
|
||||
|
|
@ -105,8 +106,8 @@ static void ebnf_colorize_line(QEColorizeContext *cp,
|
|||
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 @@ static void ebnf_colorize_line(QEColorizeContext *cp,
|
|||
break;
|
||||
}
|
||||
}
|
||||
SET_COLOR(str, start, i, EBNF_STYLE_COMMENT);
|
||||
continue;
|
||||
} else
|
||||
if (str[i] == '/') { /* line comment */
|
||||
i = n;
|
||||
SET_COLOR(str, start, i, EBNF_STYLE_COMMENT);
|
||||
continue;
|
||||
} else {
|
||||
style = EBNF_STYLE_COMMENT;
|
||||
break;
|
||||
}
|
||||
if (str[i] == '/') { /* line comment */
|
||||
i = n;
|
||||
style = EBNF_STYLE_COMMENT;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
|
||||
case '\'':
|
||||
case '`':
|
||||
case U_LEFT_SINGLE_QUOTATION_MARK:
|
||||
|
|
@ -138,8 +139,9 @@ static void ebnf_colorize_line(QEColorizeContext *cp,
|
|||
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,44 +149,49 @@ static void ebnf_colorize_line(QEColorizeContext *cp,
|
|||
if (c == '\"')
|
||||
break;
|
||||
}
|
||||
SET_COLOR(str, start, i, EBNF_STYLE_STRING);
|
||||
continue;
|
||||
default:
|
||||
style = EBNF_STYLE_STRING;
|
||||
break;
|
||||
}
|
||||
/* parse numbers */
|
||||
if (qe_isdigit(c)) {
|
||||
for (; i < n; i++) {
|
||||
if (!qe_isalnum(str[i]) && str[i] != '.')
|
||||
break;
|
||||
|
||||
default:
|
||||
/* parse numbers */
|
||||
if (qe_isdigit(c)) {
|
||||
for (; i < n; i++) {
|
||||
if (!qe_isalnum(str[i]) && str[i] != '.')
|
||||
break;
|
||||
}
|
||||
style = EBNF_STYLE_NUMBER;
|
||||
break;
|
||||
}
|
||||
SET_COLOR(str, start, i, EBNF_STYLE_NUMBER);
|
||||
continue;
|
||||
}
|
||||
/* parse identifiers and keywords */
|
||||
if (qe_isalpha_(c) || c == U_HORIZONTAL_ELLIPSIS) {
|
||||
len = 0;
|
||||
keyword[len++] = c;
|
||||
for (; i < n; i++) {
|
||||
if (qe_isalnum_(str[i])) {
|
||||
if (len < countof(keyword) - 1)
|
||||
keyword[len++] = c;
|
||||
} else {
|
||||
/* parse identifiers and keywords */
|
||||
if (qe_isalpha_(c) || c == U_HORIZONTAL_ELLIPSIS) {
|
||||
len = 0;
|
||||
keyword[len++] = c;
|
||||
for (; i < n; i++) {
|
||||
if (qe_isalnum_(str[i])) {
|
||||
if (len < countof(keyword) - 1)
|
||||
keyword[len++] = c;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
keyword[len] = '\0';
|
||||
if (strfind(syn->keywords, keyword)) {
|
||||
style = EBNF_STYLE_KEYWORD;
|
||||
break;
|
||||
}
|
||||
if (strfind(syn->types, keyword)) {
|
||||
style = EBNF_STYLE_TYPE;
|
||||
break;
|
||||
}
|
||||
style = EBNF_STYLE_IDENTIFIER;
|
||||
break;
|
||||
}
|
||||
keyword[len] = '\0';
|
||||
if (strfind(syn->keywords, keyword)) {
|
||||
SET_COLOR(str, start, i, EBNF_STYLE_KEYWORD);
|
||||
continue;
|
||||
}
|
||||
if (strfind(syn->types, keyword)) {
|
||||
SET_COLOR(str, start, i, EBNF_STYLE_TYPE);
|
||||
continue;
|
||||
}
|
||||
SET_COLOR(str, start, i, EBNF_STYLE_IDENTIFIER);
|
||||
continue;
|
||||
}
|
||||
if (style) {
|
||||
SET_COLOR(str, start, i, style);
|
||||
style = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
53
swift.c
53
swift.c
|
|
@ -179,29 +179,20 @@ static int swift_parse_number(unsigned int *p)
|
|||
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 @@ static void swift_colorize_line(QEColorizeContext *cp,
|
|||
*/
|
||||
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;
|
||||
}
|
||||
break;
|
||||
continue;
|
||||
|
||||
case '`': /* `symbol` for reserved words */
|
||||
case '@': /* @attribute */
|
||||
goto identifier;
|
||||
|
|
@ -261,14 +253,15 @@ static void swift_colorize_line(QEColorizeContext *cp,
|
|||
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 @@ static void swift_colorize_line(QEColorizeContext *cp,
|
|||
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);
|
||||
continue;
|
||||
style = C_STYLE_FUNCTION;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (style) {
|
||||
SET_COLOR(str, start, i, style);
|
||||
style = 0;
|
||||
}
|
||||
}
|
||||
cp->colorize_state = state;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue