diff options
author | pommicket <pommicket@gmail.com> | 2023-05-11 11:36:23 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-05-11 11:36:23 -0400 |
commit | 79724dc47d0fe9b6ceaa21cd3af1052bdcaea653 (patch) | |
tree | 1fa8b5f0c9fd7575b80f405bb83aee0aadf1871f | |
parent | 2794f396484bc8f1fb29190478c668cda22ce22d (diff) |
improve number syntax highligting
-rw-r--r-- | main.c | 10 | ||||
-rw-r--r-- | syntax.c | 34 | ||||
-rw-r--r-- | test/test.cpp | 1 | ||||
-rw-r--r-- | test/test.rs | 2 |
4 files changed, 42 insertions, 5 deletions
@@ -1,5 +1,13 @@ /* +TODO: +- fix backup file creation wrt hard links (right now saving a hard-linked file creates a new link) + idea: just copy to the backup file, then overwrite the original. + also, add a setting for whether or not to back up. +- option for whether to jump to build error when the build command finishes, and maybe :build-jump, :build-nojump commands +- highlight TODO, FIXME, XXX, others(?) in comments +- :go-to-matching-bracket FUTURE FEATURES: +- autodetect indentation (tabs vs spaces) - better undo chaining (dechain on backspace?) - font setting & support for multiple fonts to cover more characters - support for variable-width fonts @@ -17,6 +25,8 @@ FUTURE FEATURES: - TED_PLUGIN macro defined before including ted.h this can remove struct definitions to guarantee forwards compatibility - language dynamic registration + - built-in plugins + - "remove file..." menu - with macros we can really test performance of buffer_insert_text_at_pos, etc. (which should ideally be fast) - manual.md - LSP request timeout @@ -3,9 +3,6 @@ #include "ted.h" #include "keywords.h" -// all characters that can appear in a number -#define SYNTAX_DIGITS "0123456789.xXoObBlLuUiIabcdefABCDEF_" - // ---- syntax state constants ---- // syntax state is explained in development.md @@ -208,8 +205,37 @@ static bool syntax_number_continues(Language lang, const char32_t *line, u32 lin } } + // for simplicity, we don't actually recognize integer suffixes. + // we just treat any letter in any suffix as a digit. + // so 1lllllllllbablalbal will be highlighted as a number in C, + // but that's not legal C anyways so it doesn't really matter. + const char *digits; + switch (lang) { + case LANG_RUST: + // note: the sz is for 1usize + digits = "0123456789.xXoObBuUiIszabcdefABCDEF_"; + break; + case LANG_C: + case LANG_CPP: + digits = "0123456789.xXbBlLuUiIabcdefABCDEFpP'"; + break; + case LANG_GLSL: + digits = "0123456789.xXbBlLuUabcdefABCDEF_"; + break; + case LANG_GO: + digits = "0123456789.xXoObBabcdefABCDEFpPi_"; + break; + case LANG_JAVASCRIPT: + case LANG_TYPESCRIPT: + digits = "0123456789.xXoObBabcdefABCDEFn_"; + break; + default: + digits = "0123456789.xXoObBabcdefABCDEF_"; + break; + } + return (line[i] < CHAR_MAX && - (strchr(SYNTAX_DIGITS, (char)line[i]) + (strchr(digits, (char)line[i]) || (i && line[i-1] == 'e' && (line[i] == '+' || line[i] == '-')))); } diff --git a/test/test.cpp b/test/test.cpp index e373bff..d976e4d 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -52,6 +52,7 @@ void print_option(Option<T> const &o) { } int main() { + int my_num = 0b10011'101011'1010111lu >> 0x349.4p2; Option<int> o(7); print_option(o); o.clear(); diff --git a/test/test.rs b/test/test.rs index 40c2438..3d938f2 100644 --- a/test/test.rs +++ b/test/test.rs @@ -25,6 +25,6 @@ let x = lines. } print!(" string - "); + {}", 1usize); Ok(()) } |