newr is a general-purpose programming language. You write one readable source file, and the compiler produces readable code in eight target languages. It takes the best ideas from the languages that came before it and puts them in one place, so the same language works for AI code, IT tools, security work, and anything else you build. A Discord bot is one use of newr, through the discord module. The language itself is not bot-specific.
git clone https://github.com/drewdestar/newr.git
cd newr
./newr check examples/hello.newr
./newr build --target py -o /tmp/hello.py examples/hello.newr
python3 /tmp/hello.pyexamples/hello.newr: ok
examples/hello.newr: ok, wrote /tmp/hello.py
Hello, world!
examples/hello.newr:
print "Hello, world!"
The Python emitter produces readable code, not a blob. This is the whole emitted file:
# Generated by newr from examples/hello.newr. Do not edit by hand.
# Edit the .newr file and rebuild with: newr build examples/hello.newr
print("Hello, world!")The same file builds for all eight targets today. examples/showcase.newr shows the other side of the language: a small Discord bot with four commands and two events, written in the same syntax.
One front end serves every target. The lexer, parser, resolver, and checker run once, then one emitter per language writes readable code. The conformance corpus decides what correct means: each program in it carries an expected verdict, and every emitter has to produce it. A target that cannot pass does not ship.
| Target | Library | Status |
|---|---|---|
| Python | discord.py 2.7.1 | Done in M2 |
| JavaScript | discord.js 14.28.1, Node 24 LTS | Done in M3 |
| Java | JDA 6.7.0 | Done in M4 |
| C# | Discord.Net 3.20.2 | Done in M4 |
| Rust | serenity 0.12.5, poise 0.7.1 | Done in M5 |
| Kotlin | Kord 0.18.1 | Done in M5 |
| Dart | nyxx 6.9.1 | Done in M5 |
| Swift | — | Core emitter done (PR #11); no runtime yet, emit-only; bot programs not yet supported |
- Types:
int(signed 64-bit, checked overflow is a runtime error),float(IEEE-754 binary64),str,bool,list[T],dict[K, V], and more. Nullability is spelledT?(for examplestr?); the null value isnone. - No implicit numeric coercion:
intdoes not convert tofloatimplicitly, usefloat(x). On ints,/truncates toward zero,%takes the sign of the dividend, and division by zero is a runtime error. while, recursion, closures and lambdas, ternarycond ? a : b,?./??, pipeline|>(the piped value becomes the first argument:a |> f(b)isf(a, b)), typed enums, a corematchstatement, runtime-onlyrequires/ensurescontracts, statement-level?propagation,tryblocks returningResult[T, error],try/catch/finally,pubvisibility, and qualified imports (import "shop_items.newr"binds the module under its file stem; call it asshop_items.price_of(...)).- The
discordmodule holds the bot surface:bot/command/eventdeclarations,store/ economy operations,stringsblocks +t(),task, and embeds. Bot blocks implicitly import it. General programs persist with thedbmodule (SQLite),fileI/O, or thehttpmodule (server + fetch);jsonencode/decode and theuimodule round out full-stack programs (M8).
See SPEC.md for the full specification.
Numbers from the M9 verification (suite, conformance):
- Full suite: 1576 tests, passing in system Python.
- Conformance: 101/101 on each of the seven targets that execute programs (py, js, java, cs, rs, kt, dart). Swift is emit-only for now: all 101 programs emit, but none run yet, because the Swift runtime (
compiler/newr_rt.swift) is not built.
New to newr? Start with the usage guide.
./newr check <file.newr> # parse, resolve, check; writes nothing
./newr build --check <file.newr> # same checks; writes nothing
./newr build --target py|js|java|cs|rs|kt|dart|swift <file.newr> # emit readable code for the target
./newr build --target py -o <out.py> <file.newr> # emit to a file of your choice
./newr fmt <file.newr> # rewrite in canonical form (see `newr help fmt`)
./newr fix <file.newr> # apply safe fixes for errors that have one (see `newr help fix`)
./newr test <file.newr> # run the file's tests (see `newr help test`)
./newr docs # generate docs/api.md and docs/examples.md (see `newr help docs`)
./newr explain <code> # explain a diagnostic codeExit codes: 0 success, 1 usage, 2 environment, 4 build error. There is no exit code 3 in v1, the spec reserves 3 for network errors, which no current command can produce.
A /// line at the start of a logical line documents the declaration directly below it:
/// Doubles a number.
fn double(x: int) -> int:
return x * 2
A /// block at the top of a file, followed by a blank line, is the file header. newr docs renders the comments into docs/api.md (the stdlib reference) and docs/examples.md (one section per example program). See docs/guide.md.
newr-lang is not on PyPI yet. Until it is, run newr from a checkout, or build a single-file zipapp:
python3 -m zipapp . -o newr.pyz
python3 newr.pyz check examples/hello.newrPlanned alongside the PyPI release: a pipx install, GitHub Releases, and a PowerShell installer. The release workflow is ready (.github/workflows/release.yml, PyPI trusted publishing, no token); the one-time PyPI trusted-publisher setup is still pending.
- M0: spec frozen (see SPEC.md).
- M1: front end complete, lexer, parser, AST, resolver, checker, and the discord checker.
newr checkverifies programs;newr build --checkruns the same checks. - M2: Python emitter complete.
- M3: JavaScript emitter complete.
- M4: Java and C# emitters complete - suite 902/902, conformance 74/74 on all four targets (py, js, java, cs), cold re-evaluation CLEAN.
- M5: Rust, Kotlin, and Dart emitters complete, suite 963/963, conformance 74/74 on all seven targets (py, js, java, cs, rs, kt, dart), cold re-evaluation CLEAN.
- M6: the toolchain,
newr fmt(canonical formatting),newr init(project scaffold +newr.json),newr test(test functions and test blocks),newr fix(safe E3001 renames),newr docs(generated docs from///comments). Suite 1209/1209, conformance 79/79 on all seven targets. Version 0.2.0. - M7: run anywhere — standalone one-file binary (PyInstaller, built by CI on Linux, macOS and Windows), single-file zipapp, and the browser playground proven with the real compiler. Design and proof in docs/run-anywhere.md.
- M8: full-stack —
db(SQLite),http(server + fetch),json, anduimodules on all seven targets;newr.jsonmanifest keys andnewr build --apppackaging; the five-file shop app (shared types, view, backend, js frontend, py frontend). Suite 1536/1536, conformance 101/101 on all seven targets. - M9: fix round — emitter bugs (rs, cs, kt, dart), imported
pub const, qualified types (module.Type), per-thread SQLite connections on py; the CI workflow fix that turned the matrix green. Swift lands as the eighth target (PR #11, core emitter; no runtime yet, so Swift programs emit but don't run; bot programs not yet supported).
Verification runs in CI on every pull request.
SPEC.md the language specification (v0.2.0)
compiler/ the compiler front end and emitters
tests/ front-end test suite (python3 -m unittest discover -s tests)
examples/ .newr examples, plus the v0 golden outputs (hello.py, showcase.py)
conformance/ the conformance corpus: ok/err programs with expected verdicts,
the single definition of correct behavior
docs/ error index and diagrams
.github/workflows/ CI
- Windows and macOS execution is proven by the CI matrix (ubuntu-latest, macos-latest, windows-latest), which runs green on all three OSes.
- Performance numbers are measured on Linux only, per milestone (benchmarks B1-B7, see
benchmarks/). Nothing is claimed for other OSes.
MIT. See LICENSE.