diff options
-rw-r--r-- | buffer.c | 4 | ||||
-rw-r--r-- | syntax.c | 29 | ||||
-rw-r--r-- | ted.h | 28 |
3 files changed, 34 insertions, 27 deletions
@@ -1980,7 +1980,7 @@ void buffer_render(TextBuffer *buffer, Rect r) { SyntaxCharType *char_types = NULL; for (u32 line_idx = 0; line_idx < start_line; ++line_idx) { Line *line = &lines[line_idx]; - syntax_highlight(&syntax_state, LANG_C, line->str, line->len, NULL); + syntax_highlight(&syntax_state, buffer->language, line->str, line->len, NULL); } for (u32 line_idx = start_line; line_idx < nlines; ++line_idx) { @@ -1988,7 +1988,7 @@ void buffer_render(TextBuffer *buffer, Rect r) { if (arr_len(char_types) < line->len) { arr_set_len(char_types, line->len); } - syntax_highlight(&syntax_state, LANG_C, line->str, line->len, char_types); + syntax_highlight(&syntax_state, buffer->language, line->str, line->len, char_types); for (u32 i = 0; i < line->len; ++i) { char32_t c = line->str[i]; SyntaxCharType type = char_types[i]; @@ -1,28 +1,3 @@ -typedef struct { - bool multi_line_comment:1; // are we in a multi-line comment? (delineated by /* */) - bool continued_single_line_comment:1; // if you add a \ to the end of a single-line comment, it is continued to the next line. - bool continued_preprocessor:1; // similar to above - bool continued_string:1; -} SyntaxStateC; - -typedef union { - SyntaxStateC c; -} SyntaxState; - -ENUM_U16 { - LANG_C -} ENUM_U16_END(Language); - -ENUM_U8 { - SYNTAX_NORMAL, - SYNTAX_KEYWORD, - SYNTAX_COMMENT, - SYNTAX_PREPROCESSOR, - SYNTAX_STRING, - SYNTAX_CHARACTER, - SYNTAX_CONSTANT -} ENUM_U8_END(SyntaxCharType); - // NOTE: returns the color setting, not the color ColorSetting syntax_char_type_to_color(SyntaxCharType t) { switch (t) { @@ -235,8 +210,12 @@ static void syntax_highlight_c(SyntaxStateC *state, char32_t *line, u32 line_len // You can set char_types to NULL if you just want to advance the state, and don't care about the character types. void syntax_highlight(SyntaxState *state, Language lang, char32_t *line, u32 line_len, SyntaxCharType *char_types) { switch (lang) { + case LANG_TEXT: + memset(char_types, 0, line_len * sizeof *char_types); + break; case LANG_C: syntax_highlight_c(&state->c, line, line_len, char_types); break; + case LANG_COUNT: assert(0); break; } } @@ -5,6 +5,33 @@ #define TEXT_SIZE_MAX 70 typedef struct { + bool multi_line_comment:1; // are we in a multi-line comment? (delineated by /* */) + bool continued_single_line_comment:1; // if you add a \ to the end of a single-line comment, it is continued to the next line. + bool continued_preprocessor:1; // similar to above + bool continued_string:1; +} SyntaxStateC; + +typedef union { + SyntaxStateC c; +} SyntaxState; + +ENUM_U16 { + LANG_TEXT, + LANG_C, + LANG_COUNT +} ENUM_U16_END(Language); + +ENUM_U8 { + SYNTAX_NORMAL, + SYNTAX_KEYWORD, + SYNTAX_COMMENT, + SYNTAX_PREPROCESSOR, + SYNTAX_STRING, + SYNTAX_CHARACTER, + SYNTAX_CONSTANT +} ENUM_U8_END(SyntaxCharType); + +typedef struct { float cursor_blink_time_on, cursor_blink_time_off; u32 colors[COLOR_COUNT]; u16 text_size; @@ -64,6 +91,7 @@ typedef struct { double scroll_x, scroll_y; // number of characters scrolled in the x/y direction BufferPos cursor_pos; BufferPos selection_pos; // if selection is true, the text between selection_pos and cursor_pos is selected. + Language language; bool is_line_buffer; // "line buffers" are buffers which can only have one line of text (used for inputs) bool selection; bool store_undo_events; // set to false to disable undo events |