blob: afa9adc7a7307165a0bdb6b15d0cbbf39d6c537c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#! /usr/bin/env dbqn
# Javascript/JSON formatting
L ← "["∾"]"∾˜1↓·∾","⊸∾¨ # Native list/array
Ind ← {∾𝕨‿"["‿𝕩‿"]"} # Native list/array indexing
Cat ← {∾𝕨‿".concat("‿𝕩‿")"} # Native list/array concatenation (like ∾)
# Escape the special characters that appear in BQN sources.
Esc←{
in ← (@+0‿9‿10‿13)∾"'""" # Null, Tab, LF, CR, and quotes
out ← "0tnr" # Whitespace characters changed to letters
i ← in⊐𝕩
𝕩 ↩ i ⊏⟜out⌾((i<≠out)⊸/) 𝕩 # Replace
∾(i<≠in) /⟜"\"⊸∾¨ 𝕩 # Insert \
}
Str ← "str("""∾Esc∾""")"˜ # A BQN string
Char ← "'"(∾∾⊣)Esc∘⥊ # A BQN character
FP ← ∞⊸=◶⟨⍕,"Infinity"⟩ # Format positive number
Num ← 0⊸≤◶⟨"-"∾FP∘|,FP⟩ # Format number
F ← ⍕ # Format number
compile ← •Import "c.bqn"
useInd ← "-i"≡⊑args←•args ⋄ args↓˜↩useInd
Comp ← (3+useInd) ↑ ((<"runtime" Ind ⍕)¨↕62)⊸Compile
J ← ∾∾⟜(@+10)¨
Fconst ← ≡◶⟨@⊸≤◶Num‿Char, Str, ⊑⟩
Fout ← (≠↑⟨F,Fconst,L F¨,F⟩˙) {L𝕎¨𝕩}¨ ⊢
Frun ← "provide"⊸Cat⌾(1⊸⊑) Fout
Long ← ∾ (≠↑1‿3/⟨" "⊸∾⋄((@+10)∾" ,")⊸∾⟩˙) {𝕎𝕩}¨ ⊢
•Out (⊑"r"‿"c"‿"f"‿"e"⊐⊏)◶⟨
{𝕩⋄ref‿len←•Import"pr.bqn"⋄Long Frun len⊸↓⌾(1⊸⊑)Comp ref}
{𝕩⋄Long Fout Comp •FChars "c.bqn"}
{𝕩⋄Long Fout Comp •FChars "f.bqn"}
{𝕩⋄Long Fout Comp ⟨"Modify←GetHighlights←⊢⋄"⟩∾∾ •FChars∘∾⟜".bqn"¨ "../svg"‿"e"}
¯1 ↓ · J L∘Fout∘Comp¨
⟩ args
|