CuffScript is a lightweight scripting language designed for readable, natural-language-like syntax and simple general-purpose scripting. This repository includes its language engine, a script runner (cuffc), an interactive shell (cuffsh), built-in libraries, and runnable examples.
The engine can be used through the command-line interpreter, embedded in a C++ application, or run in a browser through WebAssembly.
str name = "World"
func greet(str person) do:
return f"Hello, {person}!"
end
print(greet(name))
Hello, World!
Before building CuffScript, make sure you have:
- A C++17 compatible compiler (GCC, Clang, or MinGW-w64 on Windows)
makeavailable on your system (mingw32-makeon Windows)
If you are using Linux or macOS, the standard system make should work. If you are on Windows, install MinGW-w64 and ensure it is on your PATH before running the build commands below. Installation has the details for each platform.
On Linux or macOS:
make
On Windows with MinGW:
mingw32-make -f Makefile.win
The executable is cuffc on Linux/macOS and cuffc.exe on Windows. The interactive shell is built separately with ./cli/build.sh (cli\build.bat on Windows).
./cuffc examples/01_hello.cuff
On Windows:
.\cuffc.exe examples\01_hello.cuffTo read a script from standard input, run cuffc without a file. Use --help to see available command-line options.
use DLC:list
list scores = [72, 95, 88, 61]
number total = 0
loop each number score in scores do:
if score >= 70 do:
total = total + 1
end
end
print(f"{total} of {length(scores)} passed")
str code = "AB-1234"
if code matches p"[up]2-[num]4" do:
print("the code has the right shape")
end
class Player do:
str name = "unknown"
number points = 0
func init(str name) do:
self.name = name
end
func score(number n) do:
self.points = self.points + n
end
end
Player ann = Player("Ann")
ann.score(30)
print(f"{ann.name} has {ann.points} points")
3 of 4 passed
the code has the right shape
Ann has 30 points
- Variables, constants, functions, conditionals, and loops
- Lists, ordered maps, indexing, and slicing
- Classes with fields, methods, inheritance and private members, and a
withblock - A built-in pattern-matching language with word-style tokens (
[num],[email]) instead of cryptic symbols, and patterns as values (p"...") - Async functions, modules, and recoverable errors that are objects (
or_else as,fail) - Eleven built-in libraries: math, strings, lists, maps, conversion, time, dates, random numbers, JSON, files and a small HTTP client
- Error reports with the source line, a caret under the position, and a hint, and a catalogue of every error code
- Limits on nesting, recursion, size and matching work, so a script can fail without crashing its host
- A C++ API for embedding the engine, plus a WebAssembly build target
Everything is under docs/, organised by what you are trying to do:
| If you want to... | Read |
|---|---|
| Build it and run your first script | Installation, Getting started |
| Learn the language | A tour of the language, classes and objects, the cookbook, the FAQ |
| Look something up | Language reference, classes, grammar, libraries, patterns, errors, limits |
| Use the shell or the runner | cuffsh, cuffc |
| Embed the engine in a C++ program | Embedding the engine, C++ API, security policy |
| Understand how it works | Architecture, source map |
| Contribute | Contributing |
Runnable programs are in examples/, and the WebAssembly package is described in npm/README.md.
| Path | Contents |
|---|---|
engine/ |
The language engine (header-only C++17) |
main.cpp, cli/ |
cuffc, the script runner, and cuffsh, the interactive shell |
wasm/, npm/ |
The WebAssembly binding and the npm package |
examples/ |
Runnable programs, error cases and a C++ embedding example |
tests/ |
The engine and language test suite |
tools/ |
The documentation generator and checker |
docs/ |
The documentation, including the changelog |
Questions, bug reports and proposals are welcome: see Getting help and Contributing. Security problems are reported privately; see the Security Policy. Everyone taking part is expected to follow the Code of Conduct.
make bash tests/run.sh
On Windows, use mingw32-make -f Makefile.win followed by powershell -File tests\run.ps1. The shell, the documentation and the sanitizer builds have their own checks; see Testing.
CuffScript is licensed under the Apache License 2.0.