Skip to main content
Version: 0.1.1

Syntax Basics

This page documents the core language syntax of RayQuiro 0.1.0.


๐Ÿ“„ Source Filesโ€‹

RayQuiro source files use the .rq extension:

main.rq
hello.rq
game.rq

๐Ÿ’ฌ Commentsโ€‹

Single-Line Commentsโ€‹

// this is a comment
var name = "RayQuiro"; // inline comment

Block Commentsโ€‹

/*
This is a multi-line comment.
Useful for documentation blocks.
*/
print("hello");

๐Ÿ”ค Stringsโ€‹

Normal Stringsโ€‹

var name = "RayQuiro";
var greeting = "Hello, World!";

Supported escape sequences:

EscapeMeaning
\nNewline
\tTab
\"Double-quote literal
\\Backslash literal

Triple-Quoted Multiline Stringsโ€‹

0.1.0 supports triple-quoted ("""...""") strings, ideal for embedding HTML, JSON templates, or multiline text:

var html = """
<section class="hero">
<h1>RayQuiro</h1>
<p>Write content directly.</p>
</section>
""";

This is especially useful with web.html(...) and web.style(...).


๐Ÿ”ข Numbersโ€‹

Integer and decimal literals:

var a = 12;
var b = 3.14;
var c = 0;
var d = -99.5;

โœ… Booleans And Nullโ€‹

var online = true;
var done = false;
var value = null;

๐Ÿ“ฆ Variablesโ€‹

var โ€” Mutable Bindingโ€‹

var score = 0;
score = score + 1;

let โ€” Read-Only Bindingโ€‹

let title = "RayQuiro";
// title = "other"; // This would cause an error

๐Ÿ”ง Functionsโ€‹

Declare functions with fn:

fn greet(name) {
return "Hello, " + name;
}

print(greet("World"));

Multiple parameters:

fn clamp_score(value, min_val, max_val) {
if (value < min_val) { return min_val; }
if (value > max_val) { return max_val; }
return value;
}

Functions are first-class values and can be stored in variables:

fn double(x) {
return x * 2;
}

var transform = double;
print(transform(5)); // 10

๐ŸŒŠ Control Flowโ€‹

if / else if / elseโ€‹

if (score > 90) {
print("Grade A");
} else if (score > 70) {
print("Grade B");
} else {
print("Grade C");
}

whileโ€‹

var i = 0;
while (i < 5) {
print(i);
i = i + 1;
}

forโ€‹

for (var i = 0; i < 5; i = i + 1) {
print(i);
}

Omitting parts is allowed:

var i = 0;
for (; i < 3; i = i + 1) {
print(i);
}

break and continueโ€‹

for (var i = 0; i < 10; i = i + 1) {
if (i == 3) { continue; }
if (i == 7) { break; }
print(i);
}

๐Ÿ—ƒ๏ธ Arraysโ€‹

Declare with square brackets:

var items = [1, 2, 3, 4, 5];
var colors = ["red", "green", "blue"];
var rgba = [98, 204, 255, 255];

Access by index:

print(items[0]); // 1
print(colors[2]); // "blue"

String indexing works the same way:

print("Ray"[0]); // "R"

JSON-parsed tables can be indexed like objects:

var info = json.parse("{\"name\":\"RayQuiro\"}");
print(info["name"]); // "RayQuiro"

โž— Operatorsโ€‹

Arithmeticโ€‹

OperatorDescription
+Addition (also string concatenation)
-Subtraction
*Multiplication
/Division
%Modulo (remainder)

Comparisonโ€‹

OperatorDescription
==Equal to
!=Not equal to
<Less than
<=Less than or equal to
>Greater than
>=Greater than or equal to

Logicalโ€‹

OperatorDescription
!Logical NOT
&&Logical AND
||Logical OR

๐Ÿ“ Truthiness Rulesโ€‹

The following values are treated as falsy:

  • null
  • false
  • 0
  • Empty string ""
  • Empty array []
  • Empty object-like runtime value

Everything else is truthy.


๐Ÿ“ Core Built-In Functionsโ€‹

Outputโ€‹

print("hello", 42, true); // prints multiple values separated by spaces
log.info => "log message"; // alternative log-style syntax

Type Conversionโ€‹

str(42) // "42"
num("3.14") // 3.14
bool(1) // true
type("hello") // "string"

Arraysโ€‹

FunctionDescription
len(value)Length of string, array, or table
push(array, value)Append a value to an array
pop(array)Remove and return the last element
range(end)Integer array [0..end-1]
range(start, end)Integer array [start..end-1]
range(start, end, step)Stepped integer array

Stringsโ€‹

FunctionDescription
join(array, sep)Join array elements as a string
split(text, sep)Split a string into an array
upper(text)Uppercase
lower(text)Lowercase
trim(text)Strip surrounding whitespace
replace(text, needle, rep)Replace occurrences
slice(value, start, end)Slice an array or string
contains(value, search)Returns true if found

Mathโ€‹

FunctionDescription
floor(n)Round down
ceil(n)Round up
round(n)Round to nearest integer
min(a, b, ...)Minimum of values
max(a, b, ...)Maximum of values
clamp(v, min, max)Clamp value between bounds

Randomโ€‹

FunctionDescription
random()Float in [0, 1)
random(max)Float in [0, max)
random(min, max)Float in [min, max)
random.int()Random integer
random.int(max)Integer in [0, max)
random.int(min, max)Integer in [min, max)

Timeโ€‹

FunctionDescription
sleep(ms)Block for ms milliseconds
clock.ms()Runtime clock in milliseconds

โœ๏ธ Semicolonsโ€‹

All statements should end with a semicolon:

var name = "RayQuiro";
print(name);

๐Ÿงช Example: Full Language Demoโ€‹

var nums = range(1, 6);
push(nums, 9);

print("Length:", len(nums));
print("Joined:", join(nums, ", "));
print("Slice:", slice(nums, 1, 4));
print("Contains 3:", contains(nums, 3));
print("Random:", random(10, 20));
print("Dice:", random.int(1, 6));

fn describe(value) {
if (value > 15) {
return "high";
} else if (value > 10) {
return "medium";
} else {
return "low";
}
}

var r = random(5, 20);
print("Roll:", r, "is", describe(r));