Skip to content

Commit

Permalink
Added sample page to website
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinborner committed Mar 10, 2024
1 parent 1f2c16e commit 6ff7510
Show file tree
Hide file tree
Showing 12 changed files with 515 additions and 47 deletions.
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
std/
wiki/
samples/
15 changes: 11 additions & 4 deletions docs/code.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// high-quality syntax highlighter
// TODO: Implement actual highlighter (or fix many regex bugs)
// TODO: Implement actual parser (or fix MANY regex bugs)

const term = (t) =>
t
.replaceAll(
/(?<!\([+-]\d*)(?<![a-z][^&; ]*)([0-9])/g,
"<span class='index'>$1</span>",
)
.replaceAll(/'(.)'/g, "<span class='string'>'$1'</span>")
.replaceAll(/"([^\"]*)"/g, "<span class='string'>\"$1\"</span>")
.replaceAll(/(\([+-][0-9]+[ubt]?\))/g, "<span class='number'>$1</span>")
.replaceAll(/(\([+-][0-9]+[ubtd]?\))/g, "<span class='number'>$1</span>")
.replaceAll(/(?<!\>)(\()/g, "<span class='left-app'>(</span>")
.replaceAll(/(\))(?!\<)/g, "<span class='right-app'>)</span>")
.replaceAll("[", "<span class='left-abs'>[</span>")
.replaceAll("]", "<span class='right-abs'>]</span>")
.replaceAll(/(?<!\([+-]\d*)([0-9])/g, "<span class='index'>$1</span>");
.replaceAll("]", "<span class='right-abs'>]</span>");

const highlightTerm = (elem) => {
elem.innerHTML = term(elem.innerHTML);
Expand All @@ -34,6 +37,10 @@ const highlight = (elem) => {
p,
)}.bruijn.html'>std/${p}</a>`,
)
.replaceAll(
/^:import (.*) (.*)$/gm,
(_, p, s) => `<span class="com">:import</span> ${p} ${s}`,
)
.replaceAll(
/^:test (\(.*\)) (\(.*\))$/gm,
(_, t1, t2) => `<span class='com'>:test</span> ${term(t1)} ${term(t2)}`,
Expand Down
23 changes: 4 additions & 19 deletions docs/gen.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
#!/bin/env bash

set -e

rm -rf std/ && mkdir -p std/

files=$(find ../std/ -type f -printf '%h\0%d\0%p\n' | sort -t '\0' -n | awk -F '\0' '{print $3}')
links=""

for file in $files; do
name=$(echo $file | cut -c8-)
filename=$(sed s@/@_@g <<<"$name")
links="$links\n<li><span class='com'>:import</span> <a href="$filename.html">$name</a></li>"
awk 'NR==FNR { gsub("<", "\\&lt;", $0); gsub(">", "\\&gt;", $0); a[n++]=$0; next } /CONTENT/ { for (i=0;i<n;++i) print a[i]; next } 1' "$file" content.template >std/$filename.html
sed -i -e "s@NAME@$name@g" std/$filename.html
done

sed -e "s@LINKS@$links@g" index.template >std/index.html

cp res/* code.js content.css index.css code.css std/

./genstd.sh
echo "std done"

./gensamples.sh
echo "samples done"

mkdocs build
echo "wiki done"
26 changes: 26 additions & 0 deletions docs/gensamples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/env bash

set -e

rm -rf samples/ && mkdir -p samples/

files=$(find ../samples/ -type f -name "*.bruijn" -printf '%h\0%d\0%p\n' | sort -t '\0' -n | awk -F '\0' '{print $3}')
links=""

prefix=""
for file in $files; do
name=$(echo "$file" | cut -c12-)
_prefix=$(cut -d/ -f1 <<<"$name")
if ! [ "$prefix" = "$_prefix" ]; then
prefix=$_prefix
links="$links\n</ul><h2>$prefix</h2><ul>"
fi
filename=$(sed s@/@_@g <<<"$name")
links="$links\n<li><a href="$filename.html">$name</a></li>"
awk 'NR==FNR { gsub("<", "\\&lt;", $0); gsub(">", "\\&gt;", $0); a[n++]=$0; next } /CONTENT/ { for (i=0;i<n;++i) print a[i]; next } 1' "$file" content.template >"samples/$filename.html"
sed -i -e "s@NAME@$name@g" "samples/$filename.html"
done

sed -e "s@LINKS@$links@g" samples.template >samples/index.html

cp res/* code.js content.css index.css code.css samples/
20 changes: 20 additions & 0 deletions docs/genstd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/env bash

set -e

rm -rf std/ && mkdir -p std/

files=$(find ../std/ -type f -printf '%h\0%d\0%p\n' | sort -t '\0' -n | awk -F '\0' '{print $3}')
links=""

for file in $files; do
name=$(echo "$file" | cut -c8-)
filename=$(sed s@/@_@g <<<"$name")
links="$links\n<li><span class='com'>:import</span> <a href="$filename.html">$name</a></li>"
awk 'NR==FNR { gsub("<", "\\&lt;", $0); gsub(">", "\\&gt;", $0); a[n++]=$0; next } /CONTENT/ { for (i=0;i<n;++i) print a[i]; next } 1' "$file" content.template >"std/$filename.html"
sed -i -e "s@NAME@$name@g" "std/$filename.html"
done

sed -e "s@LINKS@$links@g" std.template >std/index.html

cp res/* code.js content.css index.css code.css std/
27 changes: 14 additions & 13 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,14 @@ <h1>bruijn</h1>
<pre class="code">
<span class="repl">></span> <span class="symbol">length</span> <span class="meta">`</span><span class="symbol">factorial</span>
<span class="repl">></span> <span class="prefix">!</span><span class="left-app">(</span><span class="symbol">swap</span> <span class="meta">`</span><span class="left-app">(</span><span class="unary">(+2u)</span> <span class="unary">(+3u)</span><span class="right-app">))</span>
<span class="repl">></span> <span class="symbol">lhs</span> <span class="left-app">(</span><span class="symbol">blc→meta</span> <span class="string">"010000100000110"</span><span class="right-app">)</span></span>
<span class="repl">></span> <span class="symbol">lhs</span> <span class="left-app">(</span><span class="symbol">blc→meta</span> <span class="string">"010000100000110"</span><span class="right-app">)</span>
</pre>
</div>
</div>

<div class="bar big">
Learn more: <a href="wiki/">Wiki</a>, <a href="std/">Std</a>
Learn more: <a href="wiki/">Wiki</a>, <a href="std/">Std</a>,
<a href="samples/">Samples</a>
</div>

<div class="instructions">
Expand All @@ -141,6 +142,14 @@ <h1>Broogle</h1>
<div class="instructions">
<h1>Why?</h1>
<ul>
<li>
By having a very small core (the reducer), bruijn is safe, consistent,
and (potentially) proven to be correct!
</li>
<li>
Since it doesn't have builtin functions, bruijn is independent of
hardware internals and could easily be run on almost any architecture.
</li>
<li>
Compiled binary lambda calculus is incredibly expressive and tiny.
Read the articles by
Expand All @@ -149,20 +158,12 @@ <h1>Why?</h1>
</li>
<li>
Exploring different encodings of data as function abstractions is
fascinating.
</li>
<li>
Pure lambda calculus can be very beautiful. You will understand if you
try to have some fun with it.
</li>
<li>
The use of De Bruijn indices creates a clear distinction between
references to arguments and references to identifiers/functions.
really fascinating.
</li>
<li>
I don't like naming parameters of functions. De Bruijn indices are a
Naming parameters of functions is annoying. De Bruijn indices are a
universal reference independent of the function and can actually help
readability if you're familiar enough.
readability!
</li>
<li>
Really, <a href="https://justforfunnoreally.dev/">just for fun</a>.
Expand Down
16 changes: 16 additions & 0 deletions docs/samples.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="index.css" type="text/css" media="all">
<title>bruijn samples</title>
</head>
<body>
<h1>bruijn samples</h1>
These are some code samples written in the bruijn programming language. Most of the examples are copies of our solutions on <a href="https://rosettacode.org/wiki/Category:Bruijn">Rosetta Code</a>. All examples are written by bruijn's contributors and may be used according to the <a href="https://en.wikipedia.org/wiki/GNU_Free_Documentation_License">GNU FDL license</a>.
<ul>
LINKS
</ul>
</body>
</html>
File renamed without changes.
3 changes: 2 additions & 1 deletion docs/wiki_src/coding/examples.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Examples

You can find a lot more examples on [Rosetta
code](https://rosettacode.org/wiki/Category:Bruijn).
code](https://rosettacode.org/wiki/Category:Bruijn) or on the dedicated
interactive [samples](/samples/) page.

## Hello world!

Expand Down
3 changes: 3 additions & 0 deletions docs/wiki_src/introduction/philosophy.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Philosophy

- minimal, proven core
- abstraction from hardware architecture
- permaculture
- small, expressive functions
- style consistency
- thoroughly tested library (700+ tests!)
- API consistency
- implicit parallelisation
- shared evaluation
Loading

0 comments on commit 6ff7510

Please sign in to comment.