Skip to content

kkratterf/fratmscript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

35 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

JavaScript ma comme si deve

FratmScript 🀌🏻

JavaScript ma comme si deve (JavaScript, the way it should be)

A transpiler that converts Neapolitan code to JavaScript. Written in Rust.

chist Γ¨ nome = "Gennaro"

facc saluta(chi) {
    si (chi == nisciun) {
        piglie "E chi si tu?"
    }
    piglie "Uè " + chi + "!"
}

stamm a dì(saluta(nome))

Monorepo Structure

fratmscript/
β”œβ”€β”€ crates/
β”‚   β”œβ”€β”€ fratm-core/       # Core compiler (lexer, parser, codegen)
β”‚   β”œβ”€β”€ fratm-cli/        # CLI tool
β”‚   └── fratm-wasm/       # WebAssembly bindings
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ vscode-extension/ # Syntax highlighting
β”‚   └── playground/       # Online editor
β”œβ”€β”€ examples/             # Example programs
└── docs/                 # Documentation

Quick Start

# Clone
git clone https://github.com/kkratterf/fratmscript
cd fratmscript

# Build
cargo build --release

# Run
./target/release/fratm run examples/01_salutatore.fratm

# REPL
./target/release/fratm repl

CLI Commands

fratm run <file.fratm>              # Compile and run
fratm build <file.fratm>            # Compile to JavaScript
fratm build <file> --sourcemap      # With source map
fratm repl                          # Interactive REPL
fratm tokens <file>                 # Debug: show tokens
fratm ast <file>                    # Debug: show AST

Complete Syntax

Variables

chist Γ¨ costante = 42        // const
tien variabile = "ciao"      // let

Functions

facc somma(a, b) {
    piglie a + b
}

mo vir facc caricaDati() {   // async
    chist Γ¨ dati = aspett fetch(url)
    piglie dati
}

Control Flow

si (cond) { } sinnΓ² { }       // if/else
mentre che (cond) { }         // while
pe (init; cond; upd) { }      // for (ogni is optional)
rompe                         // break
salta                         // continue

Values

overo / sfΓ²ls                // true/false
nisciun                      // null
boh                          // undefined
stu cos                      // this

Operators

e / o / no                   // && / || / !
pure                         // && (alias for "e")
manco                        // ! (alias for "no")
!                            // ! (direct)

Classes

na famiglie Persona {
    facc costruttore(nome) {
        stu cos.nome = nome
    }
}
chist Γ¨ p = nu bell Persona("Gennaro")

Try/Catch

pruvamm {
    // ...
} e si schiatta (err) {
    // ...
}
iett nu bell Error("message")

Modules

chiamm { x } da "module"     // import
mann for facc fn() { }       // export
mann for predefinit App      // export default

Console Methods

stamm a dì(msg)              // console.log
avvis a dì(msg)              // console.warn
scrive a dì(msg)             // console.error

New Features

leva oggetto.prop            // delete
fermete                      // debugger

Keyword Reference

FratmScript JavaScript Neapolitan
chist Γ¨ const "this is"
tien let "hold"
facc function "I do"
piglie return "take"
si if "if"
sinnΓ² else "otherwise"
mentre che while "while"
pe for "for"
overo true "true"
sfΓ²ls false "false"
nisciun null "nobody"
boh undefined "dunno"
stamm a dì console.log "we say"
avvis a dì console.warn "warn"
scrive a dì console.error "write"
mo vir async "now see"
aspett await "wait"
pruvamm try "let's try"
e si schiatta catch "if it breaks"
iett throw "throw"
nu bell new "a nice"
na famiglie class "a family"
stu cos this "this thing"
chiamm import "call"
da from "from"
mann for export "send out"
e / pure && "and" / "also"
o || "or"
no / manco / ! ! "no" / "not even"
leva delete "remove"
fermete debugger "stop"

Development

# Build all crates
cargo build

# Run tests
cargo test

# Build WASM
cd crates/fratm-wasm
wasm-pack build --target web

# Package VSCode extension
cd packages/vscode-extension
vsce package

Playground

The playground is a web-based editor to try FratmScript in your browser.

# Build WASM module
cd crates/fratm-wasm
wasm-pack build --target web --out-dir ../../packages/playground/pkg

# Serve the playground
cd ../../packages/playground
python3 -m http.server 8080

# Open http://localhost:8080

The playground also works in demo mode without WASM using a regex-based transpiler.


Examples

Check the examples/ folder for complete programs:

  1. 01_salutatore.fratm - Hello World
  2. 02_variabili_matematica.fratm - Variables and operations
  3. 03_condizionali.fratm - If/else
  4. 04_loop.fratm - While and for
  5. 05_array_oggetti.fratm - Data structures
  6. 06_funzioni.fratm - Advanced functions
  7. 07_async.fratm - Async/await
  8. 08_classi.fratm - OOP
  9. 09_moduli.fratm - Import/export
  10. 10_nuove_feature.fratm - New features

Contributing

  1. Fork it
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

MIT


Made with Claude and coffee