uCBQN/cc.bqn
2021-11-03 20:16:04 +02:00

66 lines
2.7 KiB
BQN
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bqn
# Modified version of https://github.com/mlochbaum/BQN/blob/master/src/cjs.bqn, which is under the ISC license (https://github.com/mlochbaum/BQN/blob/master/LICENSE)
args•args
"Usage: ./cc.bqn path/to/mlochbaum/BQN [-i] <(r|r0|r1|c|cc|f|e|p) or an expression>"!2args
return 1args
args˜ return
path(args)"/src/"
args˜1
Import {𝕨•Import path𝕩}
FChars {𝕨•FChars path𝕩}
FLines {𝕨•FLines path𝕩}
F •Repr # Format number
# Escape the special characters that appear in BQN sources.
Esc{
in (@+091013)"'""" # Null, Tab, LF, CR, and quotes
out "0tnr" # Whitespace characters changed to letters
i in𝕩
𝕩 i out((i<out)/) 𝕩 # Replace
(i<in) /"\"¨ 𝕩 # Insert \
}
OStr "m_str32(U"""Esc""")"˙ # A BQN string
OChr {"m_c32(U'"(Esc𝕩)"')"} # A BQN character
ONum {s"-"/˜𝕩<0 =|"m_f64("")"˜sF| "m_f64("s"1.0/0.0)"𝕩} # Format number
OAny @ONumOChr, OStr,
List (0<)"",1·","¨
ShortList {"m_lv"𝕨"_"(F𝕩)"("(List𝕩)")"}
LongList {"m_ca"𝕨"("(F𝕩)",("𝕨"[]){"(List𝕩)"})"}
MakeList (>4˙)ShortListLongList
Li {"i32" MakeList F¨𝕩}
_Lo {"B" MakeList 𝔽¨𝕩}
glyphs Import "glyphs.bqn"
_getComp { (4+2×useInd) <˜ 5 (𝕗 Import "c.bqn"){𝔽} }
useInd "-i"args args˜useInd
Comp ((<"inc(runtime["F"])"˙)¨glyphs) glyphs _getComp
J (@+10)¨
Fout {((𝕩)Li OAny _Lo =ONum,Li _Lo _Lo _Lo (Li 2) _Lo Li _Lo OStr) {𝕎𝕩}¨ 𝕩}
Frun 1Fout
Long {¯2𝕩¨<","@+10}
LFC LongFoutComp
RT {
srcneedinputs𝕩Import"pr.bqn"
pr"runtime_0""provide"{(𝕨<(<{"inc("𝕨"["𝕩"])"}F¨)()¨𝕩)˜(𝕩)need}((-1+1=𝕩))inputs
Long Fout pr need _getComp src
}
CArg {J (¯5𝕩˙) FLines "c.bqn"}
SVG {"Modify←GetHighlights←⊢⋄" FChars".bqn"¨ "../svg"𝕩}
(@+10)˜ •Out(¬return) ("r""r0""r1""c""cc""f""e""p")
RT2, RT0, RT1
{𝕩LFC CArg "⟨""⟩"«","¨'"'(˜)¨glyphs}
{𝕩LFC "{""}"˜CArg"𝕩"}
{𝕩LFC FChars "f.bqn"}
{𝕩LFC SVG "e"}
{𝕩LFC SVG "p"}
LFC¨
# ¯1 ↓ · J L∘Fout∘Comp¨
args