Strings still don't work very well, because they often need smarter lexing than just detecting spaces. But comments work great in practice.
K5UKK5UVQBJN5Q27LLMJ7YQKENNHZOARPJQCJQOXQ4KFMKLINELQC QDSPFWFFL2JEGKBPPXQOGCWMB3KELKRMZNBSYNYUZIRNT7RL43JAC IO7JTVO75DECUIYIK5VY5NGYVSAVBBVYNRB2YEY2YX3V5VDEUOQQC 73OCE2MCBJJZZMN2KYPJTBOUCKBZAOQ2QIAMTGCNOOJ2AJAXFT2AC LXTTOB33N2HCUZFIUDRQGGBVHK2HODRG4NBLH6RXRQZDCHF27BSAC BULPIBEGL7TMK6CVIE7IS7WGAHGOSUJBGJSFQK542MOWGHP2ADQQC GSIYZ7K25HG2BYKUF3G5JKI4M3MBWC2LRC5KJIHKG2JES6GYX5DAC XUGDTYW2OALZNGX52BJXFYW2IJ6YSXA62ANG2NX2KDWULYAPZYOAC ILOA5BYFTQKBSHLFMMZUVPQ2JXBFJD62ERQFBTDK2WSRXUN525VQC AIP57TM4LFTWNVGTPJQXKAIY3H5CJWNG5LMK6ZH7LW7CICVP5O2AC 7PZ4CQFVYUMSJKVCNM75VKK5JCUYU6ICHWPZXXIC3S63YJVFCP5QC R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC -- State transitions while colorizing a single line.-- Just for comments and strings.-- Limitation: each fragment gets a uniform color so we can only change color-- at word boundaries.Next_state = {normal={{prefix='--', target='comment'},{prefix='"', target='dstring'},{prefix="'", target='sstring'},},dstring={{suffix='"', target='normal'},},sstring={{suffix="'", target='normal'},},-- comments are a sink}Comments_color = {r=0, g=0, b=1}String_color = {r=0, g=0.5, b=0.5}Colors = {normal=Text_color,comment=Comments_color,sstring=String_color,dstring=String_color}Current_state = 'normal'function initialize_color()--? print('new line')Current_state = 'normal'endfunction select_color(frag)switch_color(frag)--? print('using color', Current_state, Colors[Current_state])App.color(Colors[Current_state])endfunction switch_color(frag)--? print('switch', frag, Current_state, Next_state[Current_state])if Next_state[Current_state] == nil thenreturnendfor _,edge in pairs(Next_state[Current_state]) do--? print(Current_state, 'checking for transition', frag, edge.prefix)if edge.prefix and find(frag, edge.prefix, nil, --[[plain]] true) == 1 thenCurrent_state = edge.target--? print('switching to', Current_state)breakelseif edge.suffix and rfind(frag, edge.suffix, nil, --[[plain]] true) == #frag thenCurrent_state = edge.target--? print('switching to', Current_state)breakendendend