diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-08 06:25:48 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-08 06:25:48 -0500 |
| commit | 759cb702e76c789949f351e17768541586377006 (patch) | |
| tree | 0e9cb3dbefac62281b222759bca97152cc1ac9de /scripts/theme-selector/samples.py | |
| parent | 768c5d6a54adf87c124bdf7d754437261a0c3d23 (diff) | |
| download | dotemacs-759cb702e76c789949f351e17768541586377006.tar.gz dotemacs-759cb702e76c789949f351e17768541586377006.zip | |
feat(theme-selector): split C and C++ code samples, add Java
The combined C/C++ preview is now a dedicated C sample and a dedicated C++ sample, plus a new Java sample. Each is tokenized to exercise every syntax category the language actually has: C++ hits all 19 (including [[nodiscard]] attributes, a std::regex raw string, and a Doxygen doc comment); C hits 18 (no regex literal exists in C); Java hits 17 (no preprocessor and no global builtins). C also gained a doc comment and a __attribute__ decorator over the old combined sample.
Diffstat (limited to 'scripts/theme-selector/samples.py')
| -rw-r--r-- | scripts/theme-selector/samples.py | 74 |
1 files changed, 63 insertions, 11 deletions
diff --git a/scripts/theme-selector/samples.py b/scripts/theme-selector/samples.py index 539effc8..e487cc5e 100644 --- a/scripts/theme-selector/samples.py +++ b/scripts/theme-selector/samples.py @@ -122,31 +122,83 @@ TSS=[ ] CS=[ - [('cmd','//'),('cm',' theme.c')], + [('cmd','/**'),('doc',' Order queue. */')], [('pp','#include'),('p',' '),('str','<stdio.h>')], + [('pp','#include'),('p',' '),('str','<stdlib.h>')], [('pp','#define'),('p',' '),('con','MAX_PORT'),('p',' '),('num','8080')], [], [('kw','typedef'),('p',' '),('kw','struct'),('p',' '),('punc','{')], - [('p',' '),('ty','int'),('p',' '),('prop','id'),('punc',';')], - [('p',' '),('ty','char'),('p',' '),('op','*'),('prop','name'),('punc',';')], + [('p',' '),('ty','int'),('p',' '),('prop','id'),('punc',';')], + [('p',' '),('kw','const'),('p',' '),('ty','char'),('p',' '),('op','*'),('prop','name'),('punc',';')], [('punc','}'),('p',' '),('ty','Order'),('punc',';')], [], - [('ty','int'),('p',' '),('fnd','push'),('punc','('),('ty','Order'),('p',' '),('op','*'),('var','o'),('punc',')'),('p',' '),('punc','{')], - [('p',' '),('kw','if'),('p',' '),('punc','('),('var','o'),('p',' '),('op','=='),('p',' '),('con','NULL'),('punc',')'),('p',' '),('punc','{')], - [('p',' '),('kw','return'),('p',' '),('num','-1'),('punc',';')], - [('p',' '),('punc','}')], - [('p',' '),('fnc','printf'),('punc','('),('str','"id=%d'),('esc',chr(92)+'n'),('str','"'),('punc',','),('p',' '),('var','o'),('op','->'),('prop','id'),('punc',');')], + [('cmd','//'),('cm',' returns -1 on null input')], + [('ty','int'),('p',' '),('fnd','push'),('punc','('),('ty','Order'),('p',' '),('op','*'),('var','o'),('punc',')'),('p',' '),('dec','__attribute__'),('punc','(('),('dec','nonnull'),('punc','))'),('p',' '),('punc','{')], + [('p',' '),('kw','if'),('p',' '),('punc','('),('var','o'),('p',' '),('op','=='),('p',' '),('con','NULL'),('punc',')'),('p',' '),('kw','return'),('p',' '),('num','-1'),('punc',';')], + [('p',' '),('fnc','printf'),('punc','('),('str','"id=%d'),('esc','\\n'),('str','"'),('punc',','),('p',' '),('var','o'),('op','->'),('prop','id'),('punc',');')], [('p',' '),('kw','return'),('p',' '),('num','0'),('punc',';')], [('punc','}')], [], - [('cmd','//'),('cm',' entrypoint')], [('ty','int'),('p',' '),('fnd','main'),('punc','('),('ty','void'),('punc',')'),('p',' '),('punc','{')], - [('p',' '),('ty','Order'),('p',' '),('var','o'),('p',' '),('op','='),('p',' '),('punc','{'),('p',' '),('op','.'),('prop','id'),('p',' '),('op','='),('p',' '),('num','1'),('p',' '),('punc','}'),('punc',';')], + [('p',' '),('ty','Order'),('p',' '),('var','o'),('p',' '),('op','='),('p',' '),('punc','{'),('p',' '),('op','.'),('prop','id'),('p',' '),('op','='),('p',' '),('num','1'),('punc',','),('p',' '),('op','.'),('prop','name'),('p',' '),('op','='),('p',' '),('str','"dupre"'),('p',' '),('punc','}'),('punc',';')], [('p',' '),('ty','Order'),('p',' '),('op','*'),('var','p2'),('p',' '),('op','='),('p',' '),('bi','malloc'),('punc','('),('bi','sizeof'),('punc','('),('ty','Order'),('punc','))'),('punc',';')], [('p',' '),('fnc','push'),('punc','('),('op','&'),('var','o'),('punc',')'),('punc',';')], + [('p',' '),('bi','free'),('punc','('),('var','p2'),('punc',')'),('punc',';')], + [('p',' '),('kw','return'),('p',' '),('num','0'),('punc',';')], + [('punc','}')], +] +CPS=[ + [('cmd','/**'),('doc',' A color theme. */')], + [('pp','#include'),('p',' '),('str','<string>')], + [('pp','#include'),('p',' '),('str','<regex>')], + [('pp','#pragma'),('p',' '),('pp','once')], + [], + [('kw','namespace'),('p',' '),('var','dupre'),('p',' '),('punc','{')], + [], + [('kw','template'),('op','<'),('kw','typename'),('p',' '),('ty','T'),('op','>'),('p',' '),('kw','class'),('p',' '),('ty','Theme'),('p',' '),('punc','{')], + [('kw','public'),('op',':')], + [('p',' '),('kw','static'),('p',' '),('kw','constexpr'),('p',' '),('ty','int'),('p',' '),('con','MAX'),('p',' '),('op','='),('p',' '),('num','0x20'),('punc',';')], + [('p',' '),('ty','std'),('op','::'),('ty','string'),('p',' '),('prop','name_'),('p',' '),('op','='),('p',' '),('str','"dupre"'),('punc',';')], + [], + [('p',' '),('dec','[[nodiscard]]'),('p',' '),('ty','T'),('p',' '),('fnd','resolve'),('punc','('),('kw','const'),('p',' '),('ty','std'),('op','::'),('ty','string'),('op','&'),('p',' '),('var','key'),('punc',')'),('p',' '),('kw','const'),('p',' '),('punc','{')], + [('p',' '),('cmd','//'),('cm',' validate against a hex pattern')], + [('p',' '),('kw','static'),('p',' '),('ty','std'),('op','::'),('ty','regex'),('p',' '),('var','re'),('punc','('),('re','R"(#[0-9a-f]{6})"'),('punc',')'),('punc',';')], + [('p',' '),('kw','if'),('p',' '),('punc','('),('var','key'),('op','.'),('fnc','empty'),('punc','()'),('punc',')'),('p',' '),('kw','return'),('p',' '),('con','nullptr'),('punc',';')], + [('p',' '),('kw','return'),('p',' '),('ty','T'),('punc','{'),('var','key'),('punc','}'),('punc',';')], + [('p',' '),('punc','}')], + [('punc','}'),('punc',';')], + [], + [('ty','int'),('p',' '),('fnd','main'),('punc','()'),('p',' '),('punc','{')], + [('p',' '),('kw','auto'),('p',' '),('var','t'),('p',' '),('op','='),('p',' '),('ty','Theme'),('op','<'),('ty','int'),('op','>'),('punc','{}'),('punc',';')], + [('p',' '),('bi','static_cast'),('op','<'),('ty','int'),('op','>'),('punc','('),('var','t'),('op','.'),('prop','name_'),('op','.'),('fnc','size'),('punc','())'),('punc',';')], + [('p',' '),('ty','std'),('op','::'),('fnc','printf'),('punc','('),('str','"%s'),('esc','\\n'),('str','"'),('punc',','),('p',' '),('var','t'),('op','.'),('prop','name_'),('op','.'),('fnc','c_str'),('punc','())'),('punc',';')], [('p',' '),('kw','return'),('p',' '),('num','0'),('punc',';')], [('punc','}')], ] +JAS=[ + [('cmd','/**'),('doc',' A color theme. */')], + [('kw','package'),('p',' '),('var','com'),('op','.'),('var','dupre'),('punc',';')], + [('kw','import'),('p',' '),('var','java'),('op','.'),('var','util'),('op','.'),('var','regex'),('op','.'),('ty','Pattern'),('punc',';')], + [], + [('dec','@Deprecated')], + [('kw','public'),('p',' '),('kw','final'),('p',' '),('kw','class'),('p',' '),('ty','Theme'),('p',' '),('punc','{')], + [('p',' '),('kw','private'),('p',' '),('kw','static'),('p',' '),('kw','final'),('p',' '),('ty','int'),('p',' '),('con','MAX_PORT'),('p',' '),('op','='),('p',' '),('num','8080'),('punc',';')], + [('p',' '),('kw','private'),('p',' '),('kw','final'),('p',' '),('ty','String'),('p',' '),('prop','name'),('p',' '),('op','='),('p',' '),('str','"dupre"'),('punc',';')], + [('p',' '),('kw','private'),('p',' '),('kw','static'),('p',' '),('kw','final'),('p',' '),('ty','Pattern'),('p',' '),('con','HEX'),('p',' '),('op','='),('p',' '),('ty','Pattern'),('op','.'),('fnc','compile'),('punc','('),('re','"#[0-9a-f]{6}"'),('punc',')'),('punc',';')], + [], + [('p',' '),('dec','@Override')], + [('p',' '),('kw','public'),('p',' '),('ty','String'),('p',' '),('fnd','resolve'),('punc','('),('ty','String'),('p',' '),('var','key'),('punc',')'),('p',' '),('punc','{')], + [('p',' '),('cmd','//'),('cm',' fall back to null')], + [('p',' '),('kw','if'),('p',' '),('punc','('),('var','key'),('op','.'),('fnc','isEmpty'),('punc','()'),('punc',')'),('p',' '),('kw','return'),('p',' '),('con','null'),('punc',';')], + [('p',' '),('kw','return'),('p',' '),('var','key'),('op','.'),('fnc','strip'),('punc','('),('punc',')'),('op','+'),('str','"'),('esc','\\t'),('str','"'),('punc',';')], + [('p',' '),('punc','}')], + [], + [('p',' '),('kw','public'),('p',' '),('kw','static'),('p',' '),('ty','void'),('p',' '),('fnd','main'),('punc','('),('ty','String'),('punc','[]'),('p',' '),('var','args'),('punc',')'),('p',' '),('punc','{')], + [('p',' '),('ty','var'),('p',' '),('var','t'),('p',' '),('op','='),('p',' '),('kw','new'),('p',' '),('ty','Theme'),('punc','()'),('punc',';')], + [('p',' '),('ty','System'),('op','.'),('prop','out'),('op','.'),('fnc','println'),('punc','('),('var','t'),('op','.'),('fnc','resolve'),('punc','('),('str','"bg"'),('punc','))'),('punc',';')], + [('p',' '),('punc','}')], + [('punc','}')], +] SHS=[ [('cmd','#!'),('cm','/bin/bash')], [('cmd','#'),('cm',' deploy.sh')], @@ -174,7 +226,7 @@ SHS=[ [('fnc','main'),('p',' '),('str','"$@"')], ] -cols="".join(f'<div class="col"><h2>{n}</h2><pre>{render(s)}</pre></div>' for n,s in [("Elisp",ELS),("Go",GOS),("Python",PYS),("TypeScript",TSS),("Shell",SHS),("C/C++",CS)]) +cols="".join(f'<div class="col"><h2>{n}</h2><pre>{render(s)}</pre></div>' for n,s in [("Elisp",ELS),("Go",GOS),("Python",PYS),("TypeScript",TSS),("Java",JAS),("C",CS),("C++",CPS),("Shell",SHS)]) legend_rows=[ ("keyword (bold)","kw","class def if return import"),("builtin","bi","len range print"), ("function — definition (bold)","fnd","resolve cache-get push"),("function — call","fnc","get append fmt.Errorf"), |
