mirror of https://github.com/Sam1301/Lite.git
Single line comments
This commit is contained in:
parent
67470d7707
commit
374f5ba474
18
editor.c
18
editor.c
|
@ -41,6 +41,7 @@ enum editorKey {
|
|||
|
||||
enum editorHighlight {
|
||||
HL_NORMAL = 0,
|
||||
HL_COMMENT,
|
||||
HL_STRING,
|
||||
HL_NUMBER,
|
||||
HL_MATCH
|
||||
|
@ -52,6 +53,7 @@ struct editorSyntax {
|
|||
char *filetype;
|
||||
char **filematch;
|
||||
int flags;
|
||||
char *singleline_comment_start; // single comment line pattern for this language
|
||||
};
|
||||
|
||||
typedef struct editorrow {
|
||||
|
@ -87,7 +89,8 @@ struct editorSyntax HLDB[] = {
|
|||
{
|
||||
"c",
|
||||
C_HL_extensions,
|
||||
HL_HIGHLIGHT_NUMBERS | HL_HIGHLIGHT_STRINGS
|
||||
HL_HIGHLIGHT_NUMBERS | HL_HIGHLIGHT_STRINGS,
|
||||
"//"
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -250,6 +253,9 @@ void editorUpdateSyntax(editorrow *row) {
|
|||
|
||||
if (E.syntax == NULL) return;
|
||||
|
||||
char *scs = E.syntax->singleline_comment_start;
|
||||
int scs_len = scs ? strlen(scs) : 0;
|
||||
|
||||
int prev_sep = 1;
|
||||
int in_string = 0;
|
||||
|
||||
|
@ -259,6 +265,14 @@ void editorUpdateSyntax(editorrow *row) {
|
|||
char c = row->render[i];
|
||||
unsigned char prev_hl = (i > 0) ? row->hl[i - 1] : HL_NORMAL;
|
||||
|
||||
if (scs_len && !in_string) {
|
||||
if (!strncmp(&row->render[i], scs, scs_len)) {
|
||||
memset(&row->hl[i], HL_COMMENT, row->rsize - i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (E.syntax->flags & HL_HIGHLIGHT_STRINGS) {
|
||||
if (in_string) {
|
||||
row->hl[i] = HL_STRING;
|
||||
|
@ -305,6 +319,8 @@ int editorSyntaxToColor(int hl) {
|
|||
return 31;
|
||||
case HL_STRING:
|
||||
return 33;
|
||||
case HL_COMMENT:
|
||||
return 34;
|
||||
default:
|
||||
return 37;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue