Lexical Grammar, Preprocessor & Expressions
RaggieScript uses UTF-8 source files (.rssc) with C# / TypeScript-style curly-brace blocks, ;-terminated statements, // line comments, and /* ... */ block comments.
Compile-Time Preprocessor & include
Before tokenization, RaggieScript resolves compile-time conditionals and modular .rssc includes:
| Directive | Example | Behavior |
|---|---|---|
#define KEY VALUE | #define EDITION "Architect" | Defines a compile-time macro constant readable via def("KEY") or #ifdef. |
#ifdef KEY / #ifndef KEY | #ifndef BOOK_SLUG | Includes block when KEY was (or was not) passed via -DKEY=VAL or #define. |
#if / #elif / #else / #endif | #if TARGET_ARCH == "arm64" | Conditional compilation supporting ==, !=, defined(KEY), &&, and ||. |
include "rel/path.rssc"; | include "../includes/common.rssc"; | Splices reusable helper functions, structs, and enums with cycle protection. |
#ifndef RELEASE_RING
#define RELEASE_RING "stable"
#endif
include "shared-enterprise-checks.rssc";
const activeRing = def("RELEASE_RING", "stable");
Literals (string, Raw r"...", Single '...', SemVer v"...")
1. Interpolated Double-Quoted Strings ("...")
Double-quoted strings expand ${expr} expressions automatically (calling str(expr) on any inner expression) and support \n, \r, \t, \\, \", and \$ escapes:
const summary = "Installing ${product.name} on ${sys.arch()} (Build ${sys.osBuild()})";
2. Single-Quoted Non-Interpolated Strings ('...')
Single-quoted strings do not expand ${...} and can be nested cleanly inside "${...}" interpolations without escaping double quotes:
log("Manufacturer: ${msi.getProperty(dbFile, 'Manufacturer')}");
3. Raw Windows Path & Registry Strings (r"...")
Prefixing a string with r disables backslash escape processing—ideal for Windows Registry keys, UNC shares, and regular expressions:
const uninstallKey = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
4. First-Class Semantic Version Literals (v"..." & Bare 3-Part Versions)
Version literals parse into 4-part Major.Minor.Build.Revision 64-bit tuples so relational comparisons (<, <=, >, >=, ==, !=) never suffer lexicographical "10.0.9" > "10.0.22000" string bugs:
const minWin11: version = v"10.0.22000.0";
if (sys.osVersion() >= minWin11) {
log.info("Windows 11 or newer verified.");
}
5. Numbers, Booleans, Arrays & Maps
- Integers (
int): 64-bit signed (42,-1,500_000, hex0x1040). - Floats (
float): 64-bit IEEE 754 (4.5,0.25). - Booleans & Null:
true,false,null. - Arrays (
array):[10, 20, 30](0-indexed, supports+concatenation). - Maps (
map):{ host: "https://raggiesoftstudio.com", port: 443 }.
Operators & Precedence (Highest to Lowest)
| Precedence | Operators | Description |
|---|---|---|
| 1 (Postfix) | obj.prop, obj?.prop, arr[i], arr?.[i], fn(a, name: b) | Member access, v1.3 null-safe optional chaining (?. / ?.[), indexing, & calls |
| 2 (Unary) | !x, -x, ref varName | Logical NOT, numeric negation, two-way mutable ref binding |
| 3 (Multiplicative) | *, / (Path Join or Divide), % | When either operand is path, a / b joins path segments cleanly! |
| 4 (Additive) | +, - | Numeric add/subtract, string concatenation, or array + array merge |
| 5 (Relational) | <, <=, >, >= | Numeric or 4-part version (SemVer) comparison |
| 6 (Equality) | ==, != | Deep structural value equality |
| 7 (Logical) | &&, || | Short-circuit boolean AND / OR |
| 8 (Coalesce) | lhs ?? rhs | Evaluates to rhs when lhs is null or empty ""; otherwise lhs |
| 9 (Conditional) | cond ? whenTrue : whenFalse | Ternary conditional expression |
| 10 (Assignment) | =, +=, -=, *=, /= | Mutable let / param assignment (const rejected by RSW713) |
Control-Flow Statements
// 1. if / elif / else
if (sys.isArm64()) {
log.info("ARM64 silicon");
} elif (sys.isX64()) {
log.info("x64 silicon");
} else {
exit(EXIT_UNSUPPORTED_OS);
}
// 2. for-in over arrays or (key, value) over maps
for (item in ["Core", "Docs"]) {
log.info(item);
}
for (k, v in { channel: "stable", ring: "1" }) {
log.info("${k}=${v}");
}
// 3. while & repeat-until loops (with break; and continue;)
let attempts = 0;
repeat {
attempts += 1;
} until (attempts >= 3);
// 4. Structured exception handling & setup exit codes
try {
assert(sys.freeDiskMB(installDir) >= 100, "At least 100 MB free space is required.");
} catch (err: string) {
ui.error("Pre-Flight Check Failed", err);
exit(1603);
}
// 5. v1.3 LIFO Scope-Exit Cleanup ('defer { ... }') & Optional Chaining ('?.')
fn inspectEndpoint(cfg: any) : int {
defer { log.info("Finished inspecting endpoint configuration."); }
return cfg?.network?.port ?? 8443;
}
// 6. v1.3 First-Class Unit Test Blocks ('raggiescript.exe test <file_or_dir> [--json]')
test "Optional chaining falls back to port 8443 when config is null" {
assert(inspectEndpoint(null) == 8443, "Expected fallback port 8443");
}