Syntax without representation is tyranny.
-- Sussman's mantra
An implementation of S-expression in JavaScript.
npm i @cicada-lang/sexp
Parsing lambda calculus expressions:
<exp> = <variable>
| (lambda (<name> ...) <exp>)
| (<exp> <exp> ...)
Example from from @cicada-lang/lambda.sexp:
- See src/lang/parser/ for the complete example.
import { cons, match, matchList, matchSymbol, Sexp, v } from "@cicada-lang/sexp"
import { Exp } from "../exp"
import * as Exps from "../exps"
export function matchExp(sexp: Sexp): Exp {
return match<Exp>(sexp, [
[
["lambda", v("names"), v("exp")],
({ names, exp }) =>
matchList(names, matchSymbol).reduceRight(
(fn, name) => new Exps.Fn(name, fn),
matchExp(exp),
),
],
[
cons(v("target"), v("args")),
({ target, args }) =>
matchList(args, matchExp).reduce(
(result, arg) => new Exps.Ap(result, arg),
matchExp(target),
),
],
[v("name"), ({ name }) => new Exps.Var(matchSymbol(name))],
])
}
npm install # Install dependencies
npm run build # Compile `src/` to `lib/`
npm run format # Format the code
npm run test # Run test
To make a contribution, fork this project and create a pull request.
Please read the STYLE-GUIDE.md before you change the code.
Remember to add yourself to AUTHORS. Your line belongs to you, you can write a little introduction to yourself but not too long.