mirror of https://github.com/Sam1301/Lite.git
Syntax highlight two types of keywords.
This commit is contained in:
parent
374f5ba474
commit
0418c00ea4
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"termios.h": "c"
|
||||||
|
}
|
||||||
|
}
|
42
editor.c
42
editor.c
|
@ -44,7 +44,9 @@ enum editorHighlight {
|
||||||
HL_COMMENT,
|
HL_COMMENT,
|
||||||
HL_STRING,
|
HL_STRING,
|
||||||
HL_NUMBER,
|
HL_NUMBER,
|
||||||
HL_MATCH
|
HL_MATCH,
|
||||||
|
HL_KEYWORD1,
|
||||||
|
HL_KEYWORD2
|
||||||
};
|
};
|
||||||
|
|
||||||
/*** data ***/
|
/*** data ***/
|
||||||
|
@ -54,6 +56,7 @@ struct editorSyntax {
|
||||||
char **filematch;
|
char **filematch;
|
||||||
int flags;
|
int flags;
|
||||||
char *singleline_comment_start; // single comment line pattern for this language
|
char *singleline_comment_start; // single comment line pattern for this language
|
||||||
|
char **keywords;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct editorrow {
|
typedef struct editorrow {
|
||||||
|
@ -85,12 +88,20 @@ struct editorConfig {
|
||||||
/*** filetypes ***/
|
/*** filetypes ***/
|
||||||
char *C_HL_extensions[] = { ".c", ".h", ".cpp", NULL };
|
char *C_HL_extensions[] = { ".c", ".h", ".cpp", NULL };
|
||||||
|
|
||||||
|
char *C_HL_keywords[] = {
|
||||||
|
"switch", "if", "while", "for", "break", "continue", "return", "else",
|
||||||
|
"struct", "union", "typedef", "static", "enum", "class", "case",
|
||||||
|
"int|", "long|", "double|", "float|", "char|", "unsigned|", "signed|",
|
||||||
|
"void|", "define", "include", NULL
|
||||||
|
};
|
||||||
|
|
||||||
struct editorSyntax HLDB[] = {
|
struct editorSyntax HLDB[] = {
|
||||||
{
|
{
|
||||||
"c",
|
"c",
|
||||||
C_HL_extensions,
|
C_HL_extensions,
|
||||||
HL_HIGHLIGHT_NUMBERS | HL_HIGHLIGHT_STRINGS,
|
HL_HIGHLIGHT_NUMBERS | HL_HIGHLIGHT_STRINGS,
|
||||||
"//"
|
"//",
|
||||||
|
C_HL_keywords
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -253,6 +264,8 @@ void editorUpdateSyntax(editorrow *row) {
|
||||||
|
|
||||||
if (E.syntax == NULL) return;
|
if (E.syntax == NULL) return;
|
||||||
|
|
||||||
|
char **keywords = E.syntax->keywords;
|
||||||
|
|
||||||
char *scs = E.syntax->singleline_comment_start;
|
char *scs = E.syntax->singleline_comment_start;
|
||||||
int scs_len = scs ? strlen(scs) : 0;
|
int scs_len = scs ? strlen(scs) : 0;
|
||||||
|
|
||||||
|
@ -306,6 +319,25 @@ void editorUpdateSyntax(editorrow *row) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (prev_sep) {
|
||||||
|
int j;
|
||||||
|
for (j = 0; keywords[j]; j++) {
|
||||||
|
int klen = strlen(keywords[j]);
|
||||||
|
int kw2 = keywords[j][klen - 1] == '|';
|
||||||
|
if (kw2) klen--;
|
||||||
|
if (!strncmp(&row->render[i], keywords[j], klen) &&
|
||||||
|
is_separator(row->render[i + klen])) {
|
||||||
|
memset(&row->hl[i], kw2 ? HL_KEYWORD2 : HL_KEYWORD1, klen);
|
||||||
|
i += klen;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (keywords[j] != NULL) {
|
||||||
|
prev_sep = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
prev_sep = is_separator(c);
|
prev_sep = is_separator(c);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -316,10 +348,14 @@ int editorSyntaxToColor(int hl) {
|
||||||
case HL_NUMBER:
|
case HL_NUMBER:
|
||||||
return 32;
|
return 32;
|
||||||
case HL_MATCH: // search query match
|
case HL_MATCH: // search query match
|
||||||
return 31;
|
return 91;
|
||||||
case HL_STRING:
|
case HL_STRING:
|
||||||
return 33;
|
return 33;
|
||||||
case HL_COMMENT:
|
case HL_COMMENT:
|
||||||
|
return 92;
|
||||||
|
case HL_KEYWORD1:
|
||||||
|
return 31;
|
||||||
|
case HL_KEYWORD2:
|
||||||
return 34;
|
return 34;
|
||||||
default:
|
default:
|
||||||
return 37;
|
return 37;
|
||||||
|
|
Loading…
Reference in New Issue