aboutsummaryrefslogtreecommitdiff
path: root/src/cjs.bqn
blob: 2a282b84099470da950a33f81472cf8303b74be0 (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
37
38
#! /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  (@+091013)"'"""    # 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  @NumChar, Str, 
Fout  (≠↑F,Fconst,L F¨,F˙) {L𝕎¨𝕩}¨ 
Frun  "provide"Cat(1) Fout
Long   (≠↑13/"  "((@+10)" ,")˙) {𝕎𝕩}¨ 
SVG  {"Modify←GetHighlights←⊢⋄" •FChars".bqn"¨ "../svg"𝕩}
•Out ("r""c""f""e""p"⊐⊏)
  {𝕩reflen•Import"pr.bqn"Long Frun len(1)Comp ref}
  {𝕩Long Fout Comp •FChars "c.bqn"}
  {𝕩Long Fout Comp •FChars "f.bqn"}
  {𝕩Long Fout Comp SVG "e"}
  {𝕩Long Fout Comp SVG "p"}
  ¯1  · J LFoutComp¨
 args