add a tagging system to the website

This commit is contained in:
りき萌 2025-08-24 13:18:51 +02:00
parent 701da6bc4b
commit e1b6578b2a
97 changed files with 1025 additions and 979 deletions

View file

@ -1,5 +1,7 @@
%% title = "haku - writing a little programming language for fun"
%% id = "b?01J4J5N6WZQ03VTB3TZ51J7QZK"
title = "haku - writing a little programming language for fun"
scripts = ["treehouse/vendor/codejar.js", "treehouse/components/literate-programming.js"]
tags = ["all", "programming", "plt"]
% id = "01J3K8A0D1774SFDPKDK5G9GPV"
- I've had this idea on my mind as of late, of a little pure functional programming language that would run in your browser.
@ -85,7 +87,7 @@ scripts = ["treehouse/vendor/codejar.js", "treehouse/components/literate-program
| identifier | 9 | 21 | `s-expression` |
| ) | 21 | 22 | `)` |
| end of file | 22 | 22 | |
% id = "01J3K8A0D1GGQ292D4MQBCGHWC"
- to lex the input into tokens, we'll need to know the input string (of course), and where we currently are in the string.
@ -185,7 +187,7 @@ scripts = ["treehouse/vendor/codejar.js", "treehouse/components/literate-program
}
}
}
printTokens(`()((()))`);
```
@ -376,7 +378,7 @@ scripts = ["treehouse/vendor/codejar.js", "treehouse/components/literate-program
lexer.advance(state);
return "error";
};
};
```
% id = "01J3K8A0D1DKA8YCBCJVZXXGR4"
@ -859,7 +861,7 @@ scripts = ["treehouse/vendor/codejar.js", "treehouse/components/literate-program
```
that's... the same string.
% id = "01J3K8A0D1XP4FQB2HZR9GV5CJ"
- let's try something more complicated, with comments and such.
@ -887,10 +889,10 @@ scripts = ["treehouse/vendor/codejar.js", "treehouse/components/literate-program
% id = "01J3K8A0D10DRSP49WF8YH5WSH"
- of course this is hardly the _prettiest_ printer in the world.
% id = "01J3K8A0D1VCJ7TV6CN7M07N5J"
- for one, it does not even preserve your comments.
% id = "01J3K8A0D1K3M9223YM96PS68B"
- it does not add indentation either, it just blindly dumps a minimal S-expression into the console.
@ -950,7 +952,7 @@ scripts = ["treehouse/vendor/codejar.js", "treehouse/components/literate-program
% id = "01J3K8A0D1F4R8KPHETV9N08YP"
- it's definitely not how I would write a parser nowadays.
it's pretty similar, but the syntax tree structures are quite different - it doesn't use the [lazy parsing][branch:01J3K8A0D1FYBKJ6X2W17QAK3Z] trick I talked about before.
% id = "01J3K8A0D178J6W49AFCE9HEQ6"
- I mean, it's only a trick I learned last year!
@ -1008,7 +1010,7 @@ scripts = ["treehouse/vendor/codejar.js", "treehouse/components/literate-program
```
for now we'll leave it empty.
% id = "01J3NVV2RX2T5K473GGY3K5VBX"
- in the meantime, let's prepare a couple convenient little wrappers to run our code:
@ -1092,7 +1094,7 @@ scripts = ["treehouse/vendor/codejar.js", "treehouse/components/literate-program
{:program=haku}
```javascript
export const builtins = {};
treewalk.eval = (state, node) => {
switch (node.kind) {
case "integer":
@ -1862,7 +1864,7 @@ scripts = ["treehouse/vendor/codejar.js", "treehouse/components/literate-program
{:program=haku}
```javascript
treewalk.eval = (state, node) => {
treewalk.eval = (state, node) => {
switch (node.kind) {
case "integer":
let sourceString = state.input.substring(node.start, node.end);
@ -2032,7 +2034,7 @@ scripts = ["treehouse/vendor/codejar.js", "treehouse/components/literate-program
throw new Error(`unhandled node kind: ${node.kind}`);
}
};
builtins.fn = (state, node) => {
if (node.children.length != 3)
throw new Error("an `fn` must have an argument list and a result expression");