@cicada-lang/sexp
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

S-expression

Syntax without representation is tyranny.

-- Sussman's mantra

An implementation of S-expression in JavaScript.

Installation

npm i @cicada-lang/sexp

Examples

Parsing lambda calculus expressions:

<exp> = <variable>
      | (lambda (<name> ...) <exp>)
      | (<exp> <exp> ...)

Example from from @cicada-lang/lambda.sexp:

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))],
  ])
}

Development

npm install           # Install dependencies
npm run build         # Compile `src/` to `lib/`
npm run build:watch   # Watch the compilation
npm run format        # Format the code
npm run test          # Run test
npm run test:watch    # Watch the testing

Contributions

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.

It is assumed that all non draft PRs are ready to be merged. If your PR is not ready to be merged yet, please make it a draft PR:

During the development of your PR, you can make use of the TODO.md file to record ideas temporarily, and this file should be clean again at the end of your development.

License

GPLv3

Readme

Keywords

none

Package Sidebar

Install

npm i @cicada-lang/sexp

Weekly Downloads

1

Version

0.1.2

License

GPL-3.0-or-later

Unpacked Size

202 kB

Total Files

203

Last publish

Collaborators

  • xieyuheng