summaryrefslogtreecommitdiff
path: root/syntax.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-27 14:39:01 -0500
committerpommicket <pommicket@gmail.com>2022-12-27 14:39:01 -0500
commitc9907c20599728286e73115d11b46b169d10e1a3 (patch)
treeb1a287d830d8ee7e013e519df9b082485af1082c /syntax.c
parenta11545e25cf2f65047158cc1fd7ed5a0f11a9fa0 (diff)
add typescript highlighting
Diffstat (limited to 'syntax.c')
-rw-r--r--syntax.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/syntax.c b/syntax.c
index dfd7035..18bc076 100644
--- a/syntax.c
+++ b/syntax.c
@@ -29,6 +29,7 @@ char const *language_comment_start(Language l) {
case LANG_RUST:
case LANG_CPP:
case LANG_JAVASCRIPT:
+ case LANG_TYPESCRIPT:
case LANG_JAVA:
case LANG_GO:
return "// ";
@@ -1168,7 +1169,8 @@ static void syntax_highlight_config(SyntaxState *state, char32_t const *line, u3
}
}
-static void syntax_highlight_javascript(SyntaxState *state, char32_t const *line, u32 line_len, SyntaxCharType *char_types) {
+static void syntax_highlight_javascript_typescript(
+ SyntaxState *state, char32_t const *line, u32 line_len, SyntaxCharType *char_types, bool is_typescript) {
(void)state;
bool string_is_template = (*state & SYNTAX_STATE_JAVASCRIPT_TEMPLATE_STRING) != 0;
bool in_multiline_comment = (*state & SYNTAX_STATE_JAVASCRIPT_MULTILINE_COMMENT) != 0;
@@ -1281,7 +1283,9 @@ static void syntax_highlight_javascript(SyntaxState *state, char32_t const *line
if (char_types && !in_string && !in_number && !in_multiline_comment) {
u32 keyword_len = syntax_keyword_len(LANG_JAVASCRIPT, line, i, line_len);
- Keyword const *keyword = syntax_keyword_lookup(syntax_all_keywords_javascript, arr_count(syntax_all_keywords_javascript),
+ Keyword const *keyword = syntax_keyword_lookup(
+ is_typescript ? syntax_all_keywords_typescript : syntax_all_keywords_javascript,
+ is_typescript ? arr_count(syntax_all_keywords_typescript) : arr_count(syntax_all_keywords_javascript),
&line[i], keyword_len);
if (keyword) {
SyntaxCharType type = keyword->type;
@@ -1622,7 +1626,10 @@ void syntax_highlight(SyntaxState *state, Language lang, char32_t const *line, u
syntax_highlight_config(state, line, line_len, char_types, true);
break;
case LANG_JAVASCRIPT:
- syntax_highlight_javascript(state, line, line_len, char_types);
+ syntax_highlight_javascript_typescript(state, line, line_len, char_types, false);
+ break;
+ case LANG_TYPESCRIPT:
+ syntax_highlight_javascript_typescript(state, line, line_len, char_types, true);
break;
case LANG_JAVA:
syntax_highlight_java(state, line, line_len, char_types);