1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-02-13 13:28:27 +02:00
chroma/lexers/testdata/bqn.actual
Hannu Hartikainen 5644f41865
Add lexer for BQN (#691)
Based on the Vim syntax highlighting by Marshall Lochbaum[[0]], with number
parsing from PrismJS highlighter by Christopher Rodriguez[[1]].

The lexed types are selected to be as descriptive as possible while
retaining similar groupings to the Vim highlighter, so the highlighted
code looks familiar to BQN users.

[0]: a436a71a08/editors/vim/syntax/bqn.vim
[1]: 859f99a042
2022-11-08 21:25:43 +11:00

32 lines
874 B
Plaintext

#! /usr/bin/env bqn
# From BQN documentation / quick start:
# https://mlochbaum.github.io/BQN/doc/quick.html
# Case conversion utilities
case ← {
diff ← -´ "Aa"
Lower ⇐ -⟜diff
Upper ⇐ Lower⁼
}
hw ← <˘ 2‿∘ ⥊ "helloworld"
hw case.Upper⌾(⊑¨)↩
•Out hw ↩ ∾ ⥊⍉ [hw, ", "‿"!"] # Hello, World!
# Split at spaces and repeated characters
Split ← {
!1==𝕩 ⋄ (!2=•Type)¨𝕩
Proc ← {
· 𝕊 ' ': spl⇐1 ; # Space: break and delete it
prev Fn cur: ⟨spl,str⟩⇐
spl←0 ⋄ str←⟨cur⟩ # Include and don't break...
{ prev=cur ? spl+↩1 ; @ } # except at equal characters
}
GV‿GS ← {𝕏¨}¨ ⟨ {⟨s⇐str⟩:s;""}
{𝕩.spl} ⟩
r ← Proc{»𝔽¨⊢} 𝕩
(∾¨ GV ⊔˜ ·+`GS) r
}
•Show Split hw # ⟨ "Hel" "lo," "World!" ⟩