|
| 1 | +[](https://github.com/sponsors/hyperpolymath) |
| 2 | + |
| 3 | +// SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | +// SPDX-FileCopyrightText: 2024-2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> |
| 5 | += CafeScripto |
| 6 | +:toc: preamble |
| 7 | +:icons: font |
| 8 | + |
| 9 | +CoffeeScript-syntax AffineScript. Significant whitespace, arrow functions, postfix conditionals, `@` shorthand — and behind the surface, affine resource guarantees and typed-wasm output. |
| 10 | + |
| 11 | +== What it is |
| 12 | + |
| 13 | +CafeScripto is link:https://github.com/hyperpolymath/affinescript[AffineScript] with its `cafe` face pre-selected. CoffeeScript developers will recognise: `(args) -> body` arrows, `@x` for self, `unless` and `until`, postfix `if` / `unless`, `Yes`/`No`/`On`/`Off` literal aliases, `#` line comments, `###` block comments, and significant indentation. |
| 14 | + |
| 15 | +This repo is a **brand surface only**. The compiler lives in link:https://github.com/hyperpolymath/affinescript[affinescript]. This repo carries: |
| 16 | + |
| 17 | +* Examples idiomatic to CoffeeScript developers |
| 18 | +* A `cafe` shim CLI that aliases `affinescript --face cafe` |
| 19 | +* Migration guides for CoffeeScript codebases (most have already migrated to JS / TS, but the syntax is still beloved by some) |
| 20 | + |
| 21 | +== Hello |
| 22 | + |
| 23 | +`examples/hello.affine`: |
| 24 | + |
| 25 | +[source,affine] |
| 26 | +---- |
| 27 | +# face: cafescripto |
| 28 | + |
| 29 | +### |
| 30 | + Distinctive features exercised below: |
| 31 | + - `#` line comments and `###` block comments |
| 32 | + - paren-arrow `(args) -> body` |
| 33 | + - bare-arrow `-> body` |
| 34 | + - Yes/No/On/Off literal aliases |
| 35 | +### |
| 36 | + |
| 37 | +effect IO { |
| 38 | + fn println(s: String) -> (); |
| 39 | +} |
| 40 | + |
| 41 | +fn main() -{IO}-> () { |
| 42 | + let greeting = "Hello, CafeScripto!"; |
| 43 | + let ready = Yes; |
| 44 | + println(greeting); |
| 45 | +} |
| 46 | +---- |
| 47 | + |
| 48 | +== Install |
| 49 | + |
| 50 | +[source,bash] |
| 51 | +---- |
| 52 | +opam install affinescript |
| 53 | +git clone https://github.com/hyperpolymath/cafescripto |
| 54 | +cd cafescripto |
| 55 | +---- |
| 56 | + |
| 57 | +== Use |
| 58 | + |
| 59 | +[source,bash] |
| 60 | +---- |
| 61 | +# Direct, via affinescript: |
| 62 | +affinescript eval --face cafe examples/hello.affine |
| 63 | +affinescript compile --face cafe examples/hello.affine -o hello.wasm |
| 64 | + |
| 65 | +# Or via the cafe shim: |
| 66 | +./bin/cafe eval examples/hello.affine |
| 67 | + |
| 68 | +# Or via the justfile: |
| 69 | +just run examples/hello.affine |
| 70 | +just preview examples/hello.affine # show the canonical lowering |
| 71 | +---- |
| 72 | + |
| 73 | +Source files use the canonical `.affine` extension. The face is selected by the `# face: cafescripto` pragma on the first comment line, or by the `--face cafe` flag. |
| 74 | + |
| 75 | +== Different faces, same cube |
| 76 | + |
| 77 | +CafeScripto is one of six established faces over the AffineScript core: |
| 78 | + |
| 79 | +* AffineScript — the canonical face |
| 80 | +* link:https://github.com/hyperpolymath/rattlescript[RattleScript] — Python-style |
| 81 | +* link:https://github.com/hyperpolymath/jaffascript[JaffaScript] — JavaScript / TypeScript-style |
| 82 | +* link:https://github.com/hyperpolymath/lucidscript[LucidScript] — PureScript / Haskell-style |
| 83 | +* **CafeScripto** — CoffeeScript-style (this repo) |
| 84 | +* link:https://github.com/hyperpolymath/pseudoscript[PseudoScript] — pseudocode-style |
| 85 | + |
| 86 | +== Why CafeScripto |
| 87 | + |
| 88 | +CoffeeScript peaked in 2014 and most of its population migrated to TypeScript or vanilla JavaScript years ago. CafeScripto isn't a mass-market acquisition play; it's a category-builder, and a comfortable destination for developers who liked CoffeeScript's syntax aesthetics and want it back, but with stronger guarantees and a real runtime story (typed-wasm everywhere). |
| 89 | + |
| 90 | +== Limitations (deferred) |
| 91 | + |
| 92 | +Some CoffeeScript surface features need AST-level rewrites that the text-to-text face transformer doesn't yet handle: |
| 93 | + |
| 94 | +* List comprehensions (`(x*2 for x in xs when x>0)`) |
| 95 | +* No-paren calls (`f x, y`) |
| 96 | +* Splat / destructuring (`...args`) |
| 97 | +* String interpolation (`"Hello, #{name}"`) |
| 98 | + |
| 99 | +These are tracked in link:https://github.com/hyperpolymath/affinescript/blob/main/examples/faces/README.adoc[the affinescript faces README]. Until they land, write the explicit forms (`.map` / `.filter`, paren-everything calls, explicit string concat). |
| 100 | + |
| 101 | +== Status |
| 102 | + |
| 103 | +Alpha. The face transformer is implemented in `affinescript/lib/cafe_face.ml` (added in commit 74024c6). |
| 104 | + |
| 105 | +== License |
| 106 | + |
| 107 | +AGPL-3.0-or-later. See `LICENSE`. |
0 commit comments