MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

migrate theme to theme.toml

+93 -44
+12 -1
meson.build
··· 24 24 capture: true, 25 25 ) 26 26 27 + theme_h = custom_target('theme_h', 28 + input: 'src/highlight/theme.toml', 29 + output: 'theme.h', 30 + command: [python, files('meson/theme.py'), '@INPUT@'], 31 + capture: true, 32 + ) 33 + 27 34 lib_sources = files(run_command( 28 35 python, files('meson/sources.py'), files('sources.json'), 'engine', 29 36 check: true ··· 31 38 32 39 libant = static_library( 33 40 'ant', 34 - lib_sources + [snapshot_h, messages_h], 41 + lib_sources + [ 42 + snapshot_h, 43 + messages_h, 44 + theme_h 45 + ], 35 46 install: true, 36 47 include_directories: include, 37 48 dependencies: ant_deps
+35
meson/theme.py
··· 1 + import sys 2 + 3 + try: 4 + import tomllib 5 + except ModuleNotFoundError: 6 + try: 7 + import tomli as tomllib 8 + except ModuleNotFoundError as exc: 9 + raise ModuleNotFoundError( 10 + "No TOML parser available. Use Python 3.11+ or install 'tomli'." 11 + ) from exc 12 + 13 + with open(sys.argv[1], "rb") as f: 14 + theme = tomllib.load(f) 15 + 16 + colors = theme.get("colors", {}) 17 + 18 + def to_enum(name): 19 + return "HL_" + name.upper() 20 + 21 + print("#ifndef THEME_H") 22 + print("#define THEME_H") 23 + print("") 24 + print('#include "highlight.h"') 25 + print("") 26 + print("static const char *hl_theme_color(hl_token_class cls) {") 27 + print(" switch (cls) {") 28 + for name, value in colors.items(): 29 + escaped = value.replace("\\", "\\\\").replace('"', '\\"') 30 + print(f' case {to_enum(name)}: return "{escaped}";') 31 + print(" default: return NULL;") 32 + print(" }") 33 + print("}") 34 + print("") 35 + print("#endif")
+3 -43
src/highlight/emit.c
··· 1 1 #include <string.h> 2 + 3 + #include "theme.h" 2 4 #include "highlight/emit.h" 3 5 4 6 static inline void ob_putc(hl_outbuf *o, char c) { ··· 30 32 for (size_t i = 0; i < n; i++) ob_put_escaped(o, s[i]); 31 33 } 32 34 33 - static const char *class_to_crvar(hl_token_class cls) { 34 - switch (cls) { 35 - case HL_NUMBER: return "#E8CD7C"; 36 - case HL_NUMBER_PREFIX: return "#EADBAD"; 37 - case HL_BOOLEAN: return "#65B2FF"; 38 - case HL_LITERAL_NULL: return "#65B2FF"; 39 - 40 - case HL_STRING: return "#FF8A7F"; 41 - case HL_STRING_DELIMITER: return "#FF7265"; 42 - case HL_STRING_ESCAPE: return "#F4AAA3"; 43 - case HL_STRING_KEY: return "#CCA3F4"; 44 - case HL_STRING_TEMPLATE: return "#FFB265"; 45 - 46 - case HL_REGEX: return "#FFB265"; 47 - case HL_REGEX_ESCAPE: return "#FFCC99"; 48 - case HL_REGEX_DELIMITER: return "#FF9932"; 49 - case HL_REGEX_CDATA: return "#65B2FF"; 50 - 51 - case HL_KEYWORD: return "#65B2FF"; 52 - case HL_KEYWORD_DELETE: return "#F43D3D"; 53 - case HL_TYPE: return "#59D8F1"; 54 - case HL_TYPE_STRING: return "#30E8AA"; 55 - case HL_TYPE_BOOLEAN: return "#30E8AA"; 56 - case HL_COMMENT: return "#758CA3"; 57 - case HL_FUNCTION_NAME: return "#30E8AA"; 58 - case HL_FUNCTION: return "#30E8AA"; 59 - case HL_ARGUMENT: return "#CCA3F4"; 60 - case HL_PROPERTY: return "#CCA3F4"; 61 - case HL_OPERATOR: return "#8CB2D8"; 62 - case HL_OPTIONAL_CHAIN: return "#8CB2D8"; 63 - case HL_BRACKET: return "#8CB2D8"; 64 - case HL_SEMICOLON: return "#B2CCE5"; 65 - 66 - case HL_KEYWORD_ITALIC: return "italic+#65B2FF"; 67 - case HL_CLASS_NAME: return "bold+#F7B76D"; 68 - case HL_PARENT_CLASS: return "bold+#59D8F1"; 69 - case HL_KEYWORD_EXTENDS: return "italic+#59D8F1"; 70 - 71 - default: return NULL; 72 - } 73 - } 74 - 75 35 static inline void ob_write_with_class(hl_outbuf *o, hl_token_class cls, const char *s, size_t n) { 76 36 if (n == 0) return; 77 37 78 - const char *var = class_to_crvar(cls); 38 + const char *var = hl_theme_color(cls); 79 39 if (var) { 80 40 ob_putc(o, '<'); 81 41 ob_puts(o, var);
+43
src/highlight/theme.toml
··· 1 + # Highlight theme โ€” token class โ†’ crprintf color/style string 2 + # Styles: hex colors (#RRGGBB), with optional prefix modifiers (bold+, italic+) 3 + 4 + [colors] 5 + number = "#E8CD7C" 6 + number_prefix = "#EADBAD" 7 + boolean = "#65B2FF" 8 + literal_null = "#65B2FF" 9 + 10 + string = "#FF8A7F" 11 + string_delimiter = "#FF7265" 12 + string_escape = "#F4AAA3" 13 + string_key = "#CCA3F4" 14 + string_template = "#FFB265" 15 + 16 + regex = "#FFB265" 17 + regex_escape = "#FFCC99" 18 + regex_delimiter = "#FF9932" 19 + regex_cdata = "#65B2FF" 20 + 21 + keyword = "#65B2FF" 22 + keyword_delete = "#F43D3D" 23 + keyword_italic = "italic+#65B2FF" 24 + keyword_extends = "italic+#59D8F1" 25 + 26 + type = "#59D8F1" 27 + type_string = "#30E8AA" 28 + type_boolean = "#30E8AA" 29 + 30 + comment = "#758CA3" 31 + 32 + function_name = "#30E8AA" 33 + function = "#30E8AA" 34 + argument = "#CCA3F4" 35 + property = "#CCA3F4" 36 + 37 + operator = "#8CB2D8" 38 + optional_chain = "#8CB2D8" 39 + bracket = "#8CB2D8" 40 + semicolon = "#B2CCE5" 41 + 42 + class_name = "bold+#F7B76D" 43 + parent_class = "bold+#59D8F1"