Lexical Structure
Aera’s lexical structure defines the basic symbols, tokens, and formatting rules that make up valid source code.
Character Set
Aera source files are encoded in UTF-8.
Identifiers
An identifier starts with an alphabetic character or an underscore, followed by any number of alphanumeric characters or underscores: [a-zA-Z_][a-zA-Z0-9_]
Keywords
The following are reserved keywords and cannot be used as identifiers:
fn, let, mut, const, pub, if, else, for, while, loop, match, break, return, module, use, struct, variant, in, as
Note
As the language expands, so will the reserved keywords.
Symbolic Tokens
Operator Tokens
Listed below are the following valid operators in Aera:
| Token | Description |
|---|---|
| + | Addition |
| - | Subtraction |
| * | Multiplication |
| / | Division |
| % | Modulus |
| && | Logical AND |
| || | Logical OR |
| ! | Logical NOT |
| & | Bitwise AND |
| | | Bitwise OR |
| ^ | Bitwise XOR |
| >> | Arithmetic and Logical Left-shift |
| << | Arithmetic and Logical Right-shift |
| = | Assignment and Initialization |
| += | Add-and-assign |
| -= | Subtract-and-assign |
| *= | Multiply-and-assign |
| /= | Divide-and-assign |
| %= | Modulus-and-assign |
| &= | Bitwise AND-and-assign |
| |= | Bitwise OR-and-assign |
| ^= | Bitwise XOR-and-assign |
| <<= | Left-shift-and-assign |
| >>= | Right-shift-and-assign |
| == | Equality / Equal to |
| != | Inequality / Not equal to |
| > | Greater than |
| >= | Greater than or equal to |
| < | Less than |
| <= | Less than or equal to |
| ? | Try propagation |
| ?? | Fallback |
| .. | Exclusive range |
| ..= | Inclusive range |
Punctuation & Separator Tokens
Listed below are the following punctuation and separator tokens used in Aera:
| Token | Description |
|---|---|
| [ and ] | Subscript and deduced parameter lists |
| ( and ) | Function calls and tuple literals |
| { and } | Blocks of control flow expressions, struct literals, body definitions |
| , | Separate tuple and array elements |
| . | Member access |
| : | Name binding patterns |
| :: | Module access |
Other Tokens
Listed below are some other tokens used in Aera that don’t fit into the above categories:
| Token | Description |
|---|---|
| -> | Return type |
| => | Match syntax, Lambda |
| @ | Compiler directive |
Comments
Single-line comments begin with # and continue to the end of the line. Multi-line comments begin with an opening <# and a closing #>.
# This is a single line comment
<# This is
a multi-line comment #>
<#
This function returns the sum of two integers.
#>
fn add(a: int32, b: int32) -> int32 {
a + b
}
Whitespace
Spaces and tabs are used as token separators and are otherwise ignored.