Modules
Gansey Script
Gansey Script is small on purpose.
let n = 1; const greeting = "hi"; // let is mutable, const is not
fn add(a, b) { a + b } // last expression is the value
let double = |x| x * 2; // closures capture their scope
if n > 0 { ... } else if n == 0 { ... } else { ... }
while cond { break; } for x in list { continue; } for (k, v) in (map) { }
for i in 0..10 { } // ranges
let r = might_fail()?; // ? returns Err/None from the function
match value {
Ok(v) if v > 10 => "big",
Ok(v) => "small " + v,
Err(e) => "failed: " + e,
Some(x) => x, None => 0,
[a, b] => a + b, "literal" => 1, _ => 2,
}
Keywords may be map keys and field names ({ in: [1, 2] }, q.in). A closure or match arm may answer a map directly (|p| { name: p.name }), and if … else if … else chains of any length work as values.
Values: null, bools, ints, floats, strings, lists, maps, functions, Ok(v), Err(e), Some(v), None. Conditions must be bools. Strings concatenate with +; format("{} and {}", a, b). Lists: len, push, pop, get, first, last, map, filter, each, find, any, all, fold, sort, reverse, join, slice, contains, sum. Maps: get, set, has, remove, keys, values, entries, merge. Strings: trim, trim_start, trim_end, upper, lower, split, lines, replace, replace_first, contains, count, starts_with, ends_with, strip_prefix, strip_suffix (→ Some/None), index_of, last_index_of (character positions, -1 when absent), slice, chars, repeat, pad_left, pad_right, slug, escape, url_encode, is_empty, to_int, to_float. Lists also have unique, flatten, concat, index_of.
Regular expressions (the Rust regex syntax: no look-around or back-references) are string methods: re_test(p) → bool, re_find(p) → Some(match), re_find_all(p) → list, re_captures(p) → Some([whole, group1, …]), re_captures_all(p), re_replace(p, with) (every match; $1 names a group), re_replace_first(p, with) and re_split(p). Patterns are compiled once and cached.
let first = html.re_find("<img\\b[^>]*>"); // Some("<img …>")
let years = "2024, 2025".re_find_all("\\d{4}"); // ["2024", "2025"]
Results and options: is_ok, is_err, is_some, is_none, unwrap, unwrap_or, expect, map. Globals: print, len, str, int, float, type_of, range, format, json_parse, json_stringify, now, now_iso, format_date, parse_date (ISO date or date-time → Ok(unix seconds)), min, max, abs, floor, ceil, round, clamp, url_encode, url_decode, html_escape, slugify, random_string, assert, assert_eq(got, want, message?), error. random_string(len, alphabet?) uses the operating system's secure generator and is meant for keys and tokens.
Each call into a module has an evaluation budget and a depth limit, so a runaway loop ends with an error instead of hanging the site.