suga
v0.2.0
Published
The Suga Programming Language - A modern language that compiles to JavaScript, powered by Bun
Maintainers
Readme
Suga Programming Language
Suga is a programming language that transpiles to TypeScript and runs on the Bun runtime.
Features
- Custom Syntax: Use
fninstead offunction - TypeScript Output: Compiles to clean TypeScript code
- Bun Integration: Direct support for running
.sugafiles with Bun - Simple & Fast: Lightweight parser and transformer
Installation
npm install
npm run buildUsage
CLI
# Run a Suga file directly
bun run src/cli.ts hello.suga
# Or after building
suga hello.suga
# Compile to TypeScript
goku compile hello.goku > hello.tsExample Goku Code
fn greet(name) {
return "Hello, " + name
}
let message = greet("World")
console.log(message)This compiles to:
function greet(name) {
return "Hello, " + name;
}
let message = greet("World");
console.log(message);Using with Bun Loader
You can register the Goku loader in your bunfig.toml:
[loaders]
".goku" = "./node_modules/goku/dist/bun-loader.js"Then you can import .goku files directly:
import "./my-module.goku";Or use the plugin API:
import { plugin } from "bun";
import gokuLoader from "goku/bun-loader";
plugin(gokuLoader);
// Now you can import .goku files
import "./app.goku";Language Syntax
Functions
fn add(a, b) {
return a + b
}
async fn fetchData() {
// async functions supported
}Variables
let x = 10
init name = "Goku" // 'init' replaces 'const' - unified initialization
var mutable = true // 'var' behaves like 'let' (block-scoped)Note:
initreplacesconstand provides unified initialization syntax for all typesvarbehaves exactly likelet- block-scoped, no hoisting quirks- See VAR-VS-LET.md and INIT-AND-PUB-FN.md for details
Encapsulation with pub fn
fn Shop() {
pub fn checkout() {
console.log("Checking out...")
}
pub fn addItem(item) {
console.log("Adding item:", item)
}
}
init myshop = Shop() // Factory pattern - no 'new' needed!
myshop.checkout()Functions with pub fn methods compile to factory functions that return objects. This is the functional approach - simpler and cleaner than classes. See INIT-AND-PUB-FN.md for details.
Expressions
let sum = 1 + 2 * 3
let isTrue = x > 0 && y < 10
let message = "Hello" + " " + "World"Development
# Build
npm run build
# Watch mode
npm run watch
# Run CLI in dev mode
npm run dev hello.gokuArchitecture
- Parser (
src/parser.ts): Parses Goku syntax into an AST - Transformer (
src/transformer.ts): Transforms AST to TypeScript - Compiler (
src/compiler.ts): Main compilation interface - Bun Loader (
src/bun-loader.ts): Bun plugin for.gokufiles - CLI (
src/cli.ts): Command-line interface
Roadmap
- [ ] Type annotations
- [ ] Classes and objects
- [ ] Imports/exports
- [ ] More operators
- [ ] Control flow (if/else, loops)
- [ ] Error handling
- [ ] Standard library
License
ISC
