diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-11-11 18:02:20 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-11-11 18:02:20 -0800 |
commit | d5c34ba043d6fb470b2b358881a71aec079dd823 (patch) | |
tree | 586856d0377dc2e5dec4699f21b88720592f6739 | |
parent | a54e59446d9f80af9975eaacd226a9efe31b5bb6 (diff) | |
download | view.love-d5c34ba043d6fb470b2b358881a71aec079dd823.tar.gz |
source editing: highlight [[ ]] comments/strings
In the process I fixed suffix detection for patterns with more than 1 character.
-rw-r--r-- | colorize.lua | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/colorize.lua b/colorize.lua index c0d2117..6c2057c 100644 --- a/colorize.lua +++ b/colorize.lua @@ -4,9 +4,11 @@ -- at word boundaries. Next_state = { normal={ + {prefix='--[[', target='block_comment'}, -- only single-line for now {prefix='--', target='comment'}, {prefix='"', target='dstring'}, {prefix="'", target='sstring'}, + {prefix='[[', target='block_string'}, -- only single line for now }, dstring={ {suffix='"', target='normal'}, @@ -14,18 +16,26 @@ Next_state = { sstring={ {suffix="'", target='normal'}, }, + block_string={ + {suffix=']]', target='normal'}, + }, + block_comment={ + {suffix=']]', target='normal'}, + }, -- comments are a sink } -Comments_color = {r=0, g=0, b=1} +Comment_color = {r=0, g=0, b=1} String_color = {r=0, g=0.5, b=0.5} Divider_color = {r=0.7, g=0.7, b=0.7} Colors = { normal=Text_color, - comment=Comments_color, + comment=Comment_color, sstring=String_color, - dstring=String_color + dstring=String_color, + block_string=String_color, + block_comment=Comment_color, } Current_state = 'normal' @@ -63,7 +73,7 @@ function switch_color_based_on_suffix(frag) end frag = rtrim(frag) for _,edge in pairs(Next_state[Current_state]) do - if edge.suffix and rfind(frag, edge.suffix, nil, --[[plain]] true) == #frag then + if edge.suffix and rfind(frag, edge.suffix, nil, --[[plain]] true) == #frag - #edge.suffix + 1 then Current_state = edge.target break end |