Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bqn: Add bqn language support. #3515

Merged
merged 10 commits into from Aug 5, 2022
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Expand Up @@ -251,6 +251,10 @@
},
"owner": "RunDevelopment"
},
"bqn": {
"title": "BQN",
"owner": "yewscion"
},
"brainfuck": {
"title": "Brainfuck",
"owner": "Golmote"
Expand Down
65 changes: 65 additions & 0 deletions components/prism-bqn.js
@@ -0,0 +1,65 @@
Prism.languages.bqn = {
'shebang': {
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
pattern: /^#![ \t]*\/.*/,
alias: 'important',
greedy: true
},
'comment': {
pattern: /#.*/,
greedy: true
},
'string-literal': {
pattern: /"(?:\\[\s\S]|\$(?!\()|`[^`]+`|[^"\\`$])*"/,
yewscion marked this conversation as resolved.
Show resolved Hide resolved
greedy: true,
alias: 'string'
},
'character-literal': {
pattern: /'.'/,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
greedy: true,
alias: 'string'
yewscion marked this conversation as resolved.
Show resolved Hide resolved
},
'function': {
pattern: /•[\w¯.∞π]+[\w¯.∞π]*/i
},
yewscion marked this conversation as resolved.
Show resolved Hide resolved
'dot-notation-on-brackets': {
pattern: /\{(?=.*\}\.)|\}\./,
alias: 'namespace'
},
'special-name': {
pattern: /(?:𝕨|𝕩|𝕗|𝕘|𝕤|𝕣|𝕎|𝕏|𝔽|𝔾|𝕊|_𝕣_|_𝕣)/,
alias: 'keyword'
},
'dot-notation-on-name': {
pattern: /[A-Z_][\w¯∞π]*\./i,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
alias: 'namespace'
},
'word-number-scientific': {
pattern: /\d+(?:\.\d+)?[e|E]¯?\d+/,
yewscion marked this conversation as resolved.
Show resolved Hide resolved
alias: 'number'
},
'word-name': {
pattern: /[A-Z_][\w¯∞π]*/i,
alias: 'symbol'
},
'word-number': {
pattern: /[¯∞π]?(?:\d*\.?\b\d+(?:e[+¯]?\d+)?|¯|∞|π)(?:j¯?(?:(?:\d+(?:\.\d+)?|\.\d+)(?:e[+¯]?\d+)?|¯|∞|π))?/i,
alias: 'number'
},
'null-literal': {
pattern: /@/,
alias: 'string'
yewscion marked this conversation as resolved.
Show resolved Hide resolved
},
'primitive-functions': {
pattern: /[-+×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!]/,
alias: 'operator'
},
'primitive-1-operators': {
pattern: /[`˜˘¨⁼⌜´˝˙]/,
alias: 'operator'
},
'primitive-2-operators': {
pattern: /[∘⊸⟜○⌾⎉⚇⍟⊘◶⎊]/,
alias: 'operator'
},
'punctuation': /[←⇐↩(){}⟨⟩[\]‿·⋄,.;:?]/
};
1 change: 1 addition & 0 deletions components/prism-bqn.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 125 additions & 0 deletions examples/prism-bqn.html
@@ -0,0 +1,125 @@
<h2>Examples From Rosetta Code</h2>
<h3>100 Doors</h3>
<pre><code>
swch ← ≠´{100⥊1«𝕩⥊0}¨1+↕100
¯1↓∾{𝕩∾@+10}¨•Fmt¨⟨swch,/swch⟩
</code></pre>
<h3>Archimedean Spiral</h3>
<pre><code>
{(•math.Sin •Plot○(⊢×↕∘≠) •math.Cos) -(2×π) × 𝕩⥊(↕÷-⟜1)100}
</code></pre>
<h3>Damm Algorithm</h3>
<pre><code>
table ← >⟨ 0‿3‿1‿7‿5‿9‿8‿6‿4‿2
7‿0‿9‿2‿1‿5‿4‿8‿6‿3
4‿2‿0‿6‿8‿7‿1‿3‿5‿9
1‿7‿5‿0‿9‿8‿3‿4‿2‿6
6‿1‿2‿3‿0‿4‿5‿9‿7‿8
3‿6‿7‿4‿2‿0‿9‿5‿8‿1
5‿8‿6‿9‿7‿2‿0‿1‿3‿4
8‿9‿4‿5‿3‿6‿2‿0‿1‿7
9‿4‿3‿8‿6‿1‿7‿2‿0‿5
2‿5‿8‿1‿4‿3‿6‿7‿9‿0 ⟩


Digits ← 10{⌽𝕗|⌊∘÷⟜𝕗⍟(↕1+·⌊𝕗⋆⁼1⌈⊢)}

Damm ← {0=0(table⊑˜⋈)˜´⌽Digits 𝕩}

Damm¨5724‿5727‿112946
</code></pre>
<h3>Knuth/Fisher-Yates Shuffle</h3>
<pre><code>
Knuth ← {
𝕊 arr:
l ← ≠arr
{
arr ↩ ⌽⌾(⟨•rand.Range l, 𝕩⟩⊸⊏)arr
}¨↕l
arr
}
P ← •Show Knuth

P ⟨⟩
P ⟨10⟩
P ⟨10, 20⟩
P ⟨10, 20, 30⟩
</code></pre>
<h2>Comments</h2>
<pre><code>#!/usr/bin/env bqn
# Full Line Comment
'#' # The preceding should not be a comment.
"BQN is #1" # The preceding should not be a comment.
1 + 1 # Comment at End of Line.
</code></pre>

<h2>Literals</h2>
<pre><code>
"String Literal"
'c'
"""There is a double quote at the start of this string."
"'c'"
# "Comment, not String"
"String, # Not Comment"
@
</code></pre>

<h2>Tokens</h2>
<h3>Primitive Functions</h3>
<pre><code>
+-×÷⋆√⌊⌈|¬∧∨&lt;&gt;≠=≤≥≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!
</code></pre>
<h3>1-Operators</h3>
<pre><code>
˙˜˘¨⌜⁼´˝`
</code></pre>
<h3>2-Operators</h3>
<pre><code>
∘○⊸⟜⌾⊘◶⎉⚇⍟⎊
</code></pre>
<h3>Special Names</h3>
<pre><code>
𝕨𝕩𝕗𝕘𝕤𝕎𝕏𝔽𝔾𝕊𝕣_𝕣
_𝕣_
</code></pre>
<h3>Punctuation</h3>
<pre><code>
←⇐↩(){}⟨⟩[]‿·⋄,.;:?
</code></pre>

<h2>Words</h2>
<h3>Numbers</h3>
<pre><code>
1464
3.14159
¯2
π
¯∞
2.8e¯4
1.618E2
</code></pre>
<h3>Names</h3>
<pre><code>
VariableName
ThereAre4Symbols_¯∞πAllowedInNames
</code></pre>
<h2>Namespaces</h2>
<pre><code>
example.b
{n⇐7}.n
</code></pre>
<h2>System Functions</h2>
<pre><code>
•Function
•function
•_function_
@•Function@
+•Function+
˙•Function˙
∘•Function∘
𝕨•Function𝕩
←•Function?
•Function_.¯∞πCanHaveSymbols
•0.0.0.0
</code></pre>
1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Expand Up @@ -59,6 +59,7 @@
"bbj": "BBj",
"bnf": "BNF",
"rbnf": "RBNF",
"bqn": "BQN",
"bsl": "BSL (1C:Enterprise)",
"oscript": "OneScript",
"csharp": "C#",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions tests/languages/bqn/comments.test
@@ -0,0 +1,79 @@
#!/usr/bin/env bqn
# Full Line Comment. The above is a shebang.
+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔! # Comment at End of Line.
'#' # The preceding should not be a comment.
"BQN is #1" # The preceding should not be a comment.
# Comments # Continue # To # The # EOL #
########################################
Symbol

----------------------------------------------------

[
["shebang", "#!/usr/bin/env bqn"],

["comment", "# Full Line Comment. The above is a shebang."],

["primitive-functions", "+"],
["primitive-functions", "-"],
["primitive-functions", "×"],
["primitive-functions", "÷"],
["primitive-functions", "⋆"],
["primitive-functions", "√"],
["primitive-functions", "⌊"],
["primitive-functions", "⌈"],
["primitive-functions", "|"],
["primitive-functions", "¬"],
["primitive-functions", "∧"],
["primitive-functions", "∨"],
["primitive-functions", "<"],
["primitive-functions", ">"],
["primitive-functions", "≠"],
["primitive-functions", "="],
["primitive-functions", "≤"],
["primitive-functions", "≥"],
["primitive-functions", "≡"],
["primitive-functions", "≢"],
["primitive-functions", "⊣"],
["primitive-functions", "⊢"],
["primitive-functions", "⥊"],
["primitive-functions", "∾"],
["primitive-functions", "≍"],
["primitive-functions", "⋈"],
["primitive-functions", "↑"],
["primitive-functions", "↓"],
["primitive-functions", "↕"],
["primitive-functions", "«"],
["primitive-functions", "»"],
["primitive-functions", "⌽"],
["primitive-functions", "⍉"],
["primitive-functions", "/"],
["primitive-functions", "⍋"],
["primitive-functions", "⍒"],
["primitive-functions", "⊏"],
["primitive-functions", "⊑"],
["primitive-functions", "⊐"],
["primitive-functions", "⊒"],
["primitive-functions", "∊"],
["primitive-functions", "⍷"],
["primitive-functions", "⊔"],
["primitive-functions", "!"],
["comment", "# Comment at End of Line."],

["character-literal", "'#'"],
["comment", "# The preceding should not be a comment."],

["string-literal", "\"BQN is #1\""],
["comment", "# The preceding should not be a comment."],

["comment", "# Comments # Continue # To # The # EOL #"],

["comment", "########################################"],

["word-name", "Symbol"]
]

----------------------------------------------------

Comments follow a '#' character only, on a single line, to the end of the
line, unless in a shebang, character literal, or string literal.