Lexical Structure
RSS source is UTF-8 text. Whitespace separates tokens, comments are discarded, and semicolons terminate statements where the grammar requires them.
Line comments
// continues to the end of the current line.
// A complete line comment.
let answer = 42; // A trailing comment.
answer;
Block comments
/ ... / may span lines.
/* Compute the public result.
This comment spans two lines. */
let answer = 40 + 2;
answer;
Identifiers
Identifiers begin with an ASCII letter or _ and continue with ASCII letters, digits, or _.
let answer_42 = 42;
let _internal = answer_42;
let final_result = _internal;
final_result;
Keywords
Reserved words introduce declarations and control flow. Type names such as int and string are schema identifiers interpreted in type position.
pub fn choose(value: Option<int>) -> int {
match value {
Some(found) => found,
None => 0,
}
}
let mut result = choose(Some(42));
result;
| Declarations | Control flow | Literals and bindings |
|---|---|---|
pub, fn, struct, use, as | if, else, while, for, in, match, break, continue | let, true, false |
null is neither a keyword nor a literal. Absence is written None, and "no value produced" is the Unit value (). Option and Result are built-in type names. In RSS, Some and None are reserved constructor names in expressions and patterns, so they cannot be used as local variable names; the lexer still reads them as identifiers. Field names such as obj.None and quoted map keys such as {"None": 1} remain valid. Result::Ok and Result::Err retain their qualified spelling.
Integer literals
Integers are decimal or hexadecimal. The accepted range is signed 64-bit.
let decimal = 42;
let hexadecimal = 0x2A;
let minimum = -9223372036854775808;
decimal + hexadecimal + minimum;
Floating-point literals
A decimal point followed by at least one digit produces a float literal.
let one = 1.0;
let fraction = 0.125;
let negative = -2.5;
one + fraction + negative;
String literals and escapes
Single and double quotes both create strings. Supported escapes include \n, \r, \t, \\, \", \', \0, and two-digit \xNN.
let double_quoted = "line 1\nline 2";
let single_quoted = 'RustScript';
let escaped = "\x52\x53\x53\0";
double_quoted + single_quoted + escaped;
Byte literals and escapes
Prefix a double-quoted literal with b to create bytes. Byte escapes use the same spellings and \xNN inserts one byte.
let header = b"RSS\x00";
let control = b"\n\t";
header.length + control.length;
Delimiters and punctuation
Parentheses group expressions and calls, braces delimit blocks and maps, brackets delimit arrays and indexes, commas separate items, colons attach schemas or values, and :: selects namespace members. An empty ( ) pair spells both the Unit type and the Unit value, and the punctuator list also includes the two distinct postfix operators ? (propagation) and ?. (fallible projection), which follow their operand with no intervening token.
use math;
let values: array<int> = [1, 2, 3];
let record = {answer: values[0] + values[1]};
math::max(record.answer, values[2]);
Statement semicolons
Bindings, assignments, calls used as statements, break, and continue end with ;.
let mut value = 0;
value = 41;
value += 1;
value;
Trailing result expressions
A function body or expression branch returns its final expression without requiring a trailing semicolon.
fn answer() -> int {
let base = 40;
base + 2
}
let value = if true => { answer() } else => { 0 };
value;
Source files
The native source extension is .rss. pd-vm-run accepts a file directly.
// hello.rss
fn greeting(name: string) -> string {
"hello, " + name
}
greeting("RSS");