From 759cb702e76c789949f351e17768541586377006 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 8 Jun 2026 06:25:48 -0500 Subject: 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. --- scripts/theme-selector/generate.py | 2 +- scripts/theme-selector/samples.py | 74 +++++++++++++++++++++++++----- scripts/theme-selector/theme-selector.html | 2 +- 3 files changed, 65 insertions(+), 13 deletions(-) (limited to 'scripts') diff --git a/scripts/theme-selector/generate.py b/scripts/theme-selector/generate.py index 167fc7c6..269ee039 100644 --- a/scripts/theme-selector/generate.py +++ b/scripts/theme-selector/generate.py @@ -3,7 +3,7 @@ HERE=os.path.dirname(os.path.abspath(__file__)) ns={} src=open(os.path.join(HERE,'samples.py')).read() exec(src[:src.index('cols=')], ns) -SAMPLES={"Elisp":ns['ELS'],"Go":ns['GOS'],"Python":ns['PYS'],"TypeScript":ns['TSS'],"Shell":ns['SHS'],"C/C++":ns['CS']} +SAMPLES={"Elisp":ns['ELS'],"Go":ns['GOS'],"Python":ns['PYS'],"TypeScript":ns['TSS'],"Java":ns['JAS'],"C":ns['CS'],"C++":ns['CPS'],"Shell":ns['SHS']} COLS=ns['COLS'] MAP={k:v[0] for k,v in COLS.items()}; BOLD={k:v[1] for k,v in COLS.items()}; MAP['str']='#5d9b86'; MAP['bg']='#000000' PALETTE=[["#67809c","blue"],["#e8bd30","gold"],["#9b5fd0","regal"],["#2ba178","emerald"],["#5d9b86","sage"], 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','')], + [('pp','#include'),('p',' '),('str','')], [('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','')], + [('pp','#include'),('p',' '),('str','')], + [('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'

{n}

{render(s)}
' for n,s in [("Elisp",ELS),("Go",GOS),("Python",PYS),("TypeScript",TSS),("Shell",SHS),("C/C++",CS)]) +cols="".join(f'

{n}

{render(s)}
' 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"), diff --git a/scripts/theme-selector/theme-selector.html b/scripts/theme-selector/theme-selector.html index 5fbcc22b..f5701580 100644 --- a/scripts/theme-selector/theme-selector.html +++ b/scripts/theme-selector/theme-selector.html @@ -133,7 +133,7 @@