aboutsummaryrefslogtreecommitdiff
path: root/md.bqn
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-11-26 10:33:27 -0500
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-11-26 10:33:27 -0500
commitc376c359e39eaa255ccb6a4962e4985e55c90c0f (patch)
tree9b674635a35b373398a58a1605f01253a651a787 /md.bqn
parent5bf4db5fd2f8878ada425de063d42aafb70b8fe8 (diff)
Precompute highlighting character classes
Diffstat (limited to 'md.bqn')
-rw-r--r--md.bqn13
1 files changed, 7 insertions, 6 deletions
diff --git a/md.bqn b/md.bqn
index 16791872..1109fc83 100644
--- a/md.bqn
+++ b/md.bqn
@@ -543,10 +543,9 @@ idChars ← ⟨
# Return BQN highlights for an string 𝕩, as an ⟨add,pos⟩ list for Modify
# (include will be all 1s).
-glyphs ← •Import "src/glyphs.bqn"
-GetHighlights ← {
+hlchars‿classTag ← {
+ func‿mod1‿mod2 ← •Import "src/glyphs.bqn"
# Characters used by BQN, and the HTML class they are associated with.
- func‿mod1‿mod2 ← glyphs
classes‿chars ← <˘ ⍉ ∘‿2⥊⟨
0 , " "∾@+9‿10 # Should never be highlighted
"Value" , "𝕨𝕩𝕗𝕘𝕤"
@@ -566,9 +565,11 @@ GetHighlights ← {
# Turn non-whitespace classes into ⟨open,close⟩ html tags.
classTag ← ""‿"" ∾ > {⟨"<span class='"∾𝕩∾"'>","</span>"⟩}¨ 1↓classes
-
+ chars‿classTag
+}
+GetHighlights ← {
# Find each character's group, sending unknowns to 1 and # to 0.
- col ← (1-˜≠chars) (⊢-⊣×≤) chars FindGroup 𝕩
+ col ← (1-˜≠hlchars) (⊢-⊣×≤) hlchars FindGroup 𝕩
col-↩ 4×(𝕩='.')>«𝕩∊'0'+↕10 # Namespace dot: 5→1
# Locate comments and strings.
@@ -589,7 +590,7 @@ GetHighlights ← {
# Split rows and group into text‿comments
tc ← ((⊏˘b)⊏c) ∾⟜2⊸⊔ <˘b
# Color with "String" and "Comment"
- col ⌈↩ +´ (2‿1-˜≠classes) × ToMask¨ tc
+ col ⌈↩ +´ (2‿1-˜≠classTag) × ToMask¨ tc
# Color numeric literals and identifiers
id ← col=5 # ←→ 𝕩∊idChars