A TypeScript / Bun interpreter for РАПИРА — the Soviet educational programming language designed in the early 1980s under G. A. Zvenigorodsky as part of the Школьница (Shkolnitsa) school computing system for the Агат (Agat) microcomputer.
▶ Try it in your browser: https://begoon.github.io/rapira
▶ Run it from your terminal:
npx rapira factorial.rap
ФУНК ФАКТ (Н);
ИМЕНА: Р;
1 -> Р;
ДЛЯ И ОТ 1 ДО Н ::
Р * И -> Р
ВСЕ
РЕЗ: Р
КНЦ;
ДЛЯ Н ОТ 0 ДО 6 ::
? "ФАКТ(", Н, ") = ", ФАКТ(Н)
ВСЕ;
- Interpreter core (
src/) — lexer, parser, tree-walking evaluator. Faithful to the 1985 Agat dialect: Russian-only keywords, case-insensitive identifiers,(* … *)block comments,;statement separator, three compound types (tuples< >, sets<* *>, records<¤ ¤>), three-arrow procedure parameter scheme (name/name =>/<=> name), trailingРЕЗ:for function results. - CLI (
cli/) —rapira FILE.rapruns a program,rapiradrops into a multi-line REPL,--svg PATHcaptures turtle graphics as SVG. - Web playground (
web/) — vanilla HTML + CodeMirror 6 + Web Worker, light/dark theme, example selector loading fromtests/snippets/. Build withbun build, output sits indocs/ready for GitHub Pages. Live at https://begoon.github.io/rapira. - Snippet test pipeline (
tests/snippets/) —.rapfiles diffed against sibling.expected.txt/.expected.svgon every run ofbun test. - Чертёжник turtle — Soviet "Draftsman" executor exposed as ordinary Rapira procedures (
ВПЕРЕД,НАЗАД,НАПРАВО,НАЛЕВО,ПЕРО_ВНИЗ,ПЕРО_ВВЕРХ,ДОМОЙ,В_ТОЧКУ,КУРС). Layered on top of the sameGfxEventstream as the documented graphics primitives (ЛИН,ПРЯМ,ОБЛ, etc.) so the CLI's SVG renderer and the playground's canvas renderer draw identical output.
The CLI ships as a self-contained Node bundle. With Node ≥ 18 you can run it without cloning:
npx rapira FILE.rap # run a program
npx rapira FILE.rap --svg out.svg # capture turtle graphics
npx rapira # multi-line REPL (Ctrl-D to quit)Or install globally:
npm install -g rapira
rapira FILE.rapFor local development you'll want Bun (it runs the tests and the dev server natively):
bun install
bun test # 129 tests across 9 files
bun run cli/index.ts examples/factorial.rap # ФАКТ(0..7)
bun run dev # playground on http://localhost:10000
bun run cli:build # bundle the CLI to dist/rapira.jsIf you have just installed, you can use the recipe names — just test, just dev, just run examples/turtle_star.rap --svg star.svg, etc.
| File | What it shows |
|---|---|
examples/hello.rap |
canonical ВЫВОД: "Здравствуй, мир!" |
examples/factorial.rap |
ФУНК with trailing РЕЗ:, ДЛЯ … ОТ … ДО, integer math |
examples/turtle_square.rap |
Чертёжник draws a square via ПОВТОР … РАЗА :: ВПЕРЕД(50); НАПРАВО(90) |
examples/turtle_star.rap |
five-pointed star from a single repeat loop |
examples/io_files.rap |
ОТКРЫТЬ … КАК, ВЫВОД В ФАЙЛ, ВВОД ИЗ ФАЙЛА ТЕКСТОВ, ЗАКРЫТЬ |
examples/io_seek.rap |
ПОЗИЦИЯ Ф = N for random-access file reading |
SPEC.md— the implementation contract: lexical structure, statements, operators, built-ins, what's done vs. honestly deferred.RAPIRA.md— the canonical 1985 spec (Фг.00031-01 35 01) reformatted to Markdown from the agatcomp.ru KOI-8 source.CLAUDE.md— onboarding notes for working on this codebase.
MIT © Alexander Demin