Skip to content

Commit 859f99a

Browse files
authored
Added bqn language support (#3515)
1 parent 0cad9ae commit 859f99a

13 files changed

+592
-2
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+4
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@
251251
},
252252
"owner": "RunDevelopment"
253253
},
254+
"bqn": {
255+
"title": "BQN",
256+
"owner": "yewscion"
257+
},
254258
"brainfuck": {
255259
"title": "Brainfuck",
256260
"owner": "Golmote"

components/prism-bqn.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
Prism.languages.bqn = {
2+
'shebang': {
3+
pattern: /^#![ \t]*\/.*/,
4+
alias: 'important',
5+
greedy: true
6+
},
7+
'comment': {
8+
pattern: /#.*/,
9+
greedy: true
10+
},
11+
'string-literal': {
12+
pattern: /"(?:[^"]|"")*"/,
13+
greedy: true,
14+
alias: 'string'
15+
},
16+
'character-literal': {
17+
pattern: /'(?:[\s\S]|[\uD800-\uDBFF][\uDC00-\uDFFF])'/,
18+
greedy: true,
19+
alias: 'char'
20+
},
21+
'function': /[\w¯.π]+[\w¯.π]*/,
22+
'dot-notation-on-brackets': {
23+
pattern: /\{(?=.*\}\.)|\}\./,
24+
alias: 'namespace'
25+
},
26+
'special-name': {
27+
pattern: /(?:𝕨|𝕩|𝕗|𝕘|𝕤|𝕣|𝕎|𝕏|𝔽|𝔾|𝕊|_𝕣_|_𝕣)/,
28+
alias: 'keyword'
29+
},
30+
'dot-notation-on-name': {
31+
pattern: /[A-Za-z_][\w¯π]*\./,
32+
alias: 'namespace'
33+
},
34+
'word-number-scientific': {
35+
pattern: /\d+(?:\.\d+)?[eE]¯?\d+/,
36+
alias: 'number'
37+
},
38+
'word-name': {
39+
pattern: /[A-Za-z_][\w¯π]*/,
40+
alias: 'symbol'
41+
},
42+
'word-number': {
43+
pattern: /[¯π]?(?:\d*\.?\b\d+(?:e[+¯]?\d+|E[+¯]?\d+)?|¯||π)(?:j¯?(?:(?:\d+(?:\.\d+)?|\.\d+)(?:e[+¯]?\d+|E[+¯]?\d+)?|¯||π))?/,
44+
alias: 'number'
45+
},
46+
'null-literal': {
47+
pattern: /@/,
48+
alias: 'char'
49+
},
50+
'primitive-functions': {
51+
pattern: /[-+×÷|¬<>=«»/!]/,
52+
alias: 'operator'
53+
},
54+
'primitive-1-operators': {
55+
pattern: /[`˜˘¨´˝˙]/,
56+
alias: 'operator'
57+
},
58+
'primitive-2-operators': {
59+
pattern: /[]/,
60+
alias: 'operator'
61+
},
62+
'punctuation': /[(){}[\]·,.;:?]/
63+
};

components/prism-bqn.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-bqn.html

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<h2>Examples From Rosetta Code</h2>
2+
<h3>100 Doors</h3>
3+
<pre><code>
4+
swch ← ≠´{100⥊1«𝕩⥊0}¨1+↕100
5+
¯1↓∾{𝕩∾@+10}¨•Fmt¨⟨swch,/swch⟩
6+
</code></pre>
7+
<h3>Archimedean Spiral</h3>
8+
<pre><code>
9+
{(•math.Sin •Plot○(⊢×↕∘≠) •math.Cos) -(2×π) × 𝕩⥊(↕÷-⟜1)100}
10+
</code></pre>
11+
<h3>Damm Algorithm</h3>
12+
<pre><code>
13+
table ← >⟨ 0‿3‿1‿7‿5‿9‿8‿6‿4‿2
14+
7‿0‿9‿2‿1‿5‿4‿8‿6‿3
15+
4‿2‿0‿6‿8‿7‿1‿3‿5‿9
16+
1‿7‿5‿0‿9‿8‿3‿4‿2‿6
17+
6‿1‿2‿3‿0‿4‿5‿9‿7‿8
18+
3‿6‿7‿4‿2‿0‿9‿5‿8‿1
19+
5‿8‿6‿9‿7‿2‿0‿1‿3‿4
20+
8‿9‿4‿5‿3‿6‿2‿0‿1‿7
21+
9‿4‿3‿8‿6‿1‿7‿2‿0‿5
22+
2‿5‿8‿1‿4‿3‿6‿7‿9‿0 ⟩
23+
24+
25+
Digits ← 10{⌽𝕗|⌊∘÷⟜𝕗⍟(↕1+·⌊𝕗⋆⁼1⌈⊢)}
26+
27+
Damm ← {0=0(table⊑˜⋈)˜´⌽Digits 𝕩}
28+
29+
Damm¨5724‿5727‿112946
30+
</code></pre>
31+
<h3>Knuth/Fisher-Yates Shuffle</h3>
32+
<pre><code>
33+
Knuth ← {
34+
𝕊 arr:
35+
l ← ≠arr
36+
{
37+
arr ↩ ⌽⌾(⟨•rand.Range l, 𝕩⟩⊸⊏)arr
38+
}¨↕l
39+
arr
40+
}
41+
P ← •Show Knuth
42+
43+
P ⟨⟩
44+
P ⟨10⟩
45+
P ⟨10, 20⟩
46+
P ⟨10, 20, 30⟩
47+
</code></pre>
48+
<h2>Comments</h2>
49+
<pre><code>#!/usr/bin/env bqn
50+
# Full Line Comment
51+
'#' # The preceding should not be a comment.
52+
"BQN is #1" # The preceding should not be a comment.
53+
1 + 1 # Comment at End of Line.
54+
</code></pre>
55+
56+
<h2>Literals</h2>
57+
<pre><code>
58+
"String Literal"
59+
'c'
60+
"""There is a double quote at the start of this string."
61+
"'c'"
62+
# "Comment, not String"
63+
"String, # Not Comment"
64+
@
65+
</code></pre>
66+
67+
<h2>Tokens</h2>
68+
<h3>Primitive Functions</h3>
69+
<pre><code>
70+
+-×÷⋆√⌊⌈|¬∧∨&lt;&gt;≠=≤≥≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!
71+
</code></pre>
72+
<h3>1-Operators</h3>
73+
<pre><code>
74+
˙˜˘¨⌜⁼´˝`
75+
</code></pre>
76+
<h3>2-Operators</h3>
77+
<pre><code>
78+
∘○⊸⟜⌾⊘◶⎉⚇⍟⎊
79+
</code></pre>
80+
<h3>Special Names</h3>
81+
<pre><code>
82+
𝕨𝕩𝕗𝕘𝕤𝕎𝕏𝔽𝔾𝕊𝕣_𝕣
83+
_𝕣_
84+
</code></pre>
85+
<h3>Punctuation</h3>
86+
<pre><code>
87+
←⇐↩(){}⟨⟩[]‿·⋄,.;:?
88+
</code></pre>
89+
90+
<h2>Words</h2>
91+
<h3>Numbers</h3>
92+
<pre><code>
93+
1464
94+
3.14159
95+
¯2
96+
97+
π
98+
¯∞
99+
2.8e¯4
100+
1.618E2
101+
</code></pre>
102+
<h3>Names</h3>
103+
<pre><code>
104+
VariableName
105+
ThereAre4Symbols_¯∞πAllowedInNames
106+
</code></pre>
107+
<h2>Namespaces</h2>
108+
<pre><code>
109+
example.b
110+
{n⇐7}.n
111+
</code></pre>
112+
<h2>System Functions</h2>
113+
<pre><code>
114+
•Function
115+
•function
116+
•_function_
117+
@•Function@
118+
+•Function+
119+
˙•Function˙
120+
∘•Function∘
121+
𝕨•Function𝕩
122+
←•Function?
123+
•Function_.¯∞πCanHaveSymbols
124+
•0.0.0.0
125+
</code></pre>

plugins/show-language/prism-show-language.js

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"bbj": "BBj",
6060
"bnf": "BNF",
6161
"rbnf": "RBNF",
62+
"bqn": "BQN",
6263
"bsl": "BSL (1C:Enterprise)",
6364
"oscript": "OneScript",
6465
"csharp": "C#",

plugins/show-language/prism-show-language.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/bqn/comments.test

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env bqn
2+
# Full Line Comment. The above is a shebang.
3+
+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔! # Comment at End of Line.
4+
'#' # The preceding should not be a comment.
5+
"BQN is #1" # The preceding should not be a comment.
6+
# Comments # Continue # To # The # EOL #
7+
########################################
8+
Symbol
9+
10+
----------------------------------------------------
11+
12+
[
13+
["shebang", "#!/usr/bin/env bqn"],
14+
15+
["comment", "# Full Line Comment. The above is a shebang."],
16+
17+
["primitive-functions", "+"],
18+
["primitive-functions", "-"],
19+
["primitive-functions", "×"],
20+
["primitive-functions", "÷"],
21+
["primitive-functions", "⋆"],
22+
["primitive-functions", "√"],
23+
["primitive-functions", "⌊"],
24+
["primitive-functions", "⌈"],
25+
["primitive-functions", "|"],
26+
["primitive-functions", "¬"],
27+
["primitive-functions", "∧"],
28+
["primitive-functions", "∨"],
29+
["primitive-functions", "<"],
30+
["primitive-functions", ">"],
31+
["primitive-functions", "≠"],
32+
["primitive-functions", "="],
33+
["primitive-functions", "≤"],
34+
["primitive-functions", "≥"],
35+
["primitive-functions", "≡"],
36+
["primitive-functions", "≢"],
37+
["primitive-functions", "⊣"],
38+
["primitive-functions", "⊢"],
39+
["primitive-functions", "⥊"],
40+
["primitive-functions", "∾"],
41+
["primitive-functions", "≍"],
42+
["primitive-functions", "⋈"],
43+
["primitive-functions", "↑"],
44+
["primitive-functions", "↓"],
45+
["primitive-functions", "↕"],
46+
["primitive-functions", "«"],
47+
["primitive-functions", "»"],
48+
["primitive-functions", "⌽"],
49+
["primitive-functions", "⍉"],
50+
["primitive-functions", "/"],
51+
["primitive-functions", "⍋"],
52+
["primitive-functions", "⍒"],
53+
["primitive-functions", "⊏"],
54+
["primitive-functions", "⊑"],
55+
["primitive-functions", "⊐"],
56+
["primitive-functions", "⊒"],
57+
["primitive-functions", "∊"],
58+
["primitive-functions", "⍷"],
59+
["primitive-functions", "⊔"],
60+
["primitive-functions", "!"],
61+
["comment", "# Comment at End of Line."],
62+
63+
["character-literal", "'#'"],
64+
["comment", "# The preceding should not be a comment."],
65+
66+
["string-literal", "\"BQN is #1\""],
67+
["comment", "# The preceding should not be a comment."],
68+
69+
["comment", "# Comments # Continue # To # The # EOL #"],
70+
71+
["comment", "########################################"],
72+
73+
["word-name", "Symbol"]
74+
]
75+
76+
----------------------------------------------------
77+
78+
Comments follow a '#' character only, on a single line, to the end of the
79+
line, unless in a shebang, character literal, or string literal.

0 commit comments

Comments
 (0)