Coco is a small, indentation-based language for Bun. It is designed to feel lightweight like a script, structured like Python, and ready for modern JavaScript tooling.
const version = "0.1"
fn greet name
print "Hello {name}"
if version == "0.1"
greet "Coco"
else
print "Unknown version"
Coco is early, but it now ships a working MVP compiler: lexer, parser, AST, JavaScript emitter, CLI commands, examples, docs, tests, and an optional runtime planning layer.
bun install
bun run install:global
cocoIn the REPL:
coco> const name = "Coco"
KEYWORD("const") IDENTIFIER("name") ASSIGN("=") STRING("\"Coco\"") NEWLINE("\n")
Multi-line input:
coco> .paste
... if ok
... print "yes"
...
KEYWORD("if") IDENTIFIER("ok") NEWLINE("\n") INDENT IDENTIFIER("print") STRING("\"yes\"") NEWLINE("\n") DEDENT
Useful REPL commands:
.paste multi-line input
.tokens toggle JSON token output
.clear clear input buffer
.help show help
.exit exit
coco lex examples/hello.cocoOr without installing globally:
bun run src/cli.ts lex examples/hello.cocococo parse examples/hello.coco
coco compile examples/hello.coco -o hello.js
coco run examples/hello.cocoWithout -o, compile prints JavaScript to stdout.
Readable blocks:
if user.active and not user.banned
print "Welcome {user.name}"
Functions without ceremony:
fn add a b
return a + b
Arrays and object-like layout:
users = [
"Tom"
"Jerry"
"Lucy"
]
profile =
name: "Tom"
age: 18
Optional chaining and modern operators:
avatar = user?.profile?.avatar
double = (x) => x * 2
for i in 1..3
print i
value |> double |> print
Coco Runtime is optional. The language core stays separate, and runtime support is loaded only when you ask for it.
coco runtime plan examples/runtime/agent-web.json
coco runtime dev examples/runtime/agent-web.json --dry-runThe current runtime layer plans apps across engines such as:
web api agent workflow queue db ui desktop game
It does not bundle heavy adapters yet. OpenAI, Redis, PixiJS, Tauri, HTTP servers, and database drivers are intended to become optional plugins.
Language core:
import { compile, parse, tokenize } from "coco-lang";
const tokens = tokenize('const name = "Coco"\n');
const ast = parse('print "hi"\n');
const js = compile('print "hi"\n');Runtime layer:
import { CocoRuntime, parseRuntimeManifest } from "coco-lang/runtime";Global install from this checkout:
bun run install:globalIf coco is not found:
echo 'export PATH="$HOME/.bun/bin:$PATH"' >> ~/.zshrc
source ~/.zshrcbun test
bun run check
bun run build
bun run test:pageImplemented:
- Lexer 1.0
- Parser and typed AST for MVP syntax
- JavaScript emitter/compiler
- REPL
coco lexcoco parsecoco compilecoco runcoco runtime inspect/plan/dev --dry-run- Runtime manifest planning, event bus, scheduler, and plugin registry
- Tests, docs, examples, and a static docs page
Supported compiler syntax:
- Variables, constants, assignment, expressions, calls, arrays, indentation
object literals, optional property access, functions, async/await, returns,
if/elif/else,for in,while,break,continue, inclusive ranges with.., pipeline calls with|>,matchstatements with_fallback, imports with default plus named bindings, named exports, classes,extends,new, methods, and string interpolation for simple expressions
Partial or planned:
- Exceptions, type annotations, generics, decorators, source maps, and a type checker
matchcurrently supports statement form only and requires a wildcard_case- Pipeline currently supports
value |> fnNameandvalue |> fnName arg - Range syntax is currently inclusive:
1..3emits values1, 2, 3 - Real runtime adapters
MIT