Repository navigation
Syntax‐Rules
This section covers core syntax conventions, equality operators, template literals, and comments in Tera.
Tera supports both loose and strict equality operators, adhering closely to JavaScript semantics:
-
==(Loose Equality): Performs type coercion if necessary before comparing. -
===(Strict Equality): Compares both value and type without coercion.
let a: 5 => int;
let b: "5" => string;
if (a == b) => print("Loose match!"); // Evaluates to true
if (a === b) => print("Strict match!"); // Evaluates to false| Operator | Meaning | Example |
|---|---|---|
! |
logical NOT (prefix) | !done |
&& |
logical AND, short-circuiting | a > 0 && b > 0 |
|| |
logical OR, short-circuiting | a > 0 || b > 0 |
>= |
greater than or equal | n >= 10 |
<= |
less than or equal | n <= 10 |
!= |
not equal | a != b |
!, && and || require bool operands and produce a bool. != follows the same
rules as ==: both operands must have the same type.
Note: != and ! previously failed in the lexer — there was no ! case at all, so both
died with Unexpected character '!'. Likewise && and || produced
Unexpected character '&' / '|', and >= / <= were lexed as > = (the = was
swallowed) so they failed to parse.
Feeding a non-bool value to these operators is a type error:
Operator '&&' requires boolean operands, got 'int' and 'int'.
Unary operator '!' requires a boolean operand, got 'int'.
let a: 5 => int
let b: 10 => int
print("a < b :", a < b) // true
print("a <= 5:", a <= 5) // true
print("b > a :", b > a) // true
print("b >= 10:", b >= 10) // true
print("a == 5:", a == 5) // true
print("a != b:", a != b) // true
print("and:", a > 0 && b > 0) // true
print("or :", a > 100 || b > 5) // true
let equal: a == b => bool
print("not:", !equal) // true
Output:
a < b : true
a <= 5: true
b > a : true
b >= 10: true
a == 5: true
a != b: true
and: true
or : true
not: true
&& and || only evaluate their right-hand side when they have to.
fn sideEffect() => bool {
print("side effect ran!")
return true
}
print("A:", false && sideEffect()) // false - right side skipped
print("B:", true || sideEffect()) // true - right side skipped
print("C:", true && sideEffect()) // right side runs
print("D:", false || sideEffect()) // right side runs
print("all done")
Output:
A: false
B: true
side effect ran!
C: true
side effect ran!
D: true
all done
From loosest to tightest binding:
= assignment
|| logical OR
&& logical AND
.. range
== != equality
< <= > >= comparison
+ - additive
* / % multiplicative
** power
unary - + ++ -- !
call / index / member (tightest)
So x + y * 2 groups as x + (y * 2) and x > 1 && y < 5 groups as (x > 1) && (y < 5).
Semicolons (;) are completely optional at the end of statements[cite: 1]. Tera uses automatic line-termination handling, but you can still use explicit semicolons to separate multiple statements on a single line:
let x: 10 => int // Valid without semicolon[cite: 1]
let y: 20 => int; // Valid with semicolon[cite: 1]
let a: 1 => int; let b: 2 => int // Multi-statement line[cite: 1]Tera supports single quotes ('), double quotes ("), and template literals using backticks (`) with string interpolation via ${expression}:
let greeting: 'Hello' => string;
let name: "Tera" => string;
let full: `${greeting}, ${name}!` => string; // Evaluates to "Hello, Tera!"[cite: 1]Tera supports standard JavaScript comment syntax for documenting your code:
// Single-line comment
/*
Multi-line
block comment
*/