UI and a Lisp experiment

This commit is contained in:
Yura Dupyn 2026-04-25 01:10:49 +02:00
parent 38ff06ea45
commit f55b437037
24 changed files with 2746 additions and 89 deletions

View file

@ -1,77 +1,4 @@
import './style.css'
import { SourceText, SourceRegion, sourceText } from 'source-region';
import type { SourceLocation, Span } from 'source-region';
type Expr =
| { tag: "literal", value: Literal }
| { tag: "list", values: Expr[] }
namespace Expr {
export function number(value: number): Expr {
return { tag: "literal", value: { tag: "number", value } };
}
export function identifier(value: Identifier): Expr {
return { tag: "literal", value: { tag: "identifier", value } };
}
export function list(values: Expr[]): Expr {
return { tag: "list", values };
}
export function show(e: Expr): string {
switch (e.tag) {
case "literal":
return showLiteral(e.value);
case "list":
return `(${e.values.map(show).join(" ")})`;
}
}
function showLiteral(e: Literal): string {
switch (e.tag) {
case "number":
return `${e.value}`;
case "identifier":
return `${e.value}`;
}
}
}
type Literal =
| { tag: "number", value: number }
| { tag: "identifier", value: Identifier }
type Identifier = string
// === Examples ===
function example00() {
const v: Expr = Expr.list([Expr.identifier("f"), Expr.number(123), Expr.number(512)]);
console.log(v);
console.log(Expr.show(v));
}
function example01() {
const str = `hello, world!
foo
bar `;
const source = sourceText(str);
const region = source.fullRegion();
console.log(region);
console.log(region.lineCount);
region.forEachLine((span, lineNo) => {
console.log(lineNo, region.stringOf(span));
});
}
[
example00,
example01,
].forEach((f, i) => {
console.log(`====${i}===`);
f();
})
export { parseDocument } from './parser';
export type { FoundSyntax, ParseDocumentResult, ParseError } from './parser';
export { ConcreteSyntax, Expr } from './syntax';
export type { ConcreteSyntax as ConcreteSyntaxNode, Expr as ExprNode } from './syntax';