2.2. Lexical Structure
2.2.1. Identifiers
Identifiers start with an alphabetic character or an underscore (_), followed by any number
of alphabetic characters, underscores, digits (0–9), or backticks (````).
Daslang is a case-sensitive language, meaning that foo, Foo, and fOo are
three distinct identifiers.
Backticks are used in system-generated identifiers (such as mangled names) and are generally not used in user code:
my_variable // valid
_temp // valid
player2 // valid
2.2.2. Keywords
The following words are reserved as keywords and cannot be used as identifiers:
|
|
|
|
||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
||||
|
|
|
|||
|
|||||
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
||
|
|
|
|
|
The following words are reserved as built-in type names and cannot be used as identifiers:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
Keywords and types are covered in detail in subsequent sections of this documentation. Linked keywords above lead to their relevant documentation pages.
2.2.3. Operators
Daslang recognizes the following operators:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Notable operators unique to Daslang:
<-— move assignment:=— clone assignment??— null coalescing?.and?[— null-safe navigation<|and|>— pipe operators@@— function pointer / local function<<<and>>>— bit rotation^^— logical exclusive or..— interval (range creation)=>— tuple construction (a => bcreatestuple<auto,auto>(a, b); also used in table literals)
2.2.4. Other Tokens
Other significant tokens are:
|
|
|
|
|
|
|
|
|
|
|
|
|
2.2.5. Literals
Daslang accepts integer numbers, unsigned integers, floating-point and double-precision numbers, and string literals.
2.2.5.1. Numeric Literals
|
Integer (base 10) |
|
Unsigned integer (base 16) |
|
Unsigned integer (base 8) |
|
64-bit integer (base 10) |
|
64-bit unsigned integer (base 16) |
|
8-bit unsigned integer |
|
Character literal (integer value) |
|
Floating-point number |
|
Floating-point number (explicit suffix) |
|
Floating-point number (scientific) |
|
Floating-point number (scientific) |
|
Double-precision number |
|
Double-precision number |
|
Double-precision number |
Integer suffixes:
uorU— unsigned 32-bit integerlorL— signed 64-bit integerulorUL— unsigned 64-bit integeru8orU8— unsigned 8-bit integer
Float suffixes:
f(or no suffix after a decimal point) — 32-bit floatd,lf— 64-bit double
2.2.5.2. String Literals
Strings are delimited by double quotation marks ("). They support escape sequences
and string interpolation:
"I'm a string\n"
Escape sequences:
|
Tab |
|
Newline |
|
Carriage return |
|
Backslash |
|
Double quote |
|
Single quote |
|
Null character |
|
Bell |
|
Backspace |
|
Form feed |
|
Vertical tab |
|
Hexadecimal byte |
|
Unicode code point (16-bit) |
|
Unicode code point (32-bit) |
Multiline strings:
Strings can span multiple lines. The content includes all characters between the quotes:
let msg = "This is
a multi-line
string"
String interpolation:
Expressions enclosed in curly brackets {} inside a string are evaluated and their
results are inserted into the string:
let name = "world"
let greeting = "Hello, {name}!" // "Hello, world!"
let result = "2 + 2 = {2 + 2}" // "2 + 2 = 4"
To include literal curly brackets in a string, escape them with a backslash:
print("Use \{braces\} for interpolation") // prints: Use {braces} for interpolation
Format specifiers:
String interpolation supports optional format specifiers after a colon:
let pi = 3.14159
print("{pi:5.2f}") // formatted output
(see String Builder for more details on string interpolation).
2.2.7. Automatic Semicolons
Daslang automatically inserts semicolons at the end of lines when the code is enclosed in curly braces, unless the line is also inside parentheses or brackets:
def foo {
var a = 0 // semicolon inserted automatically
var b = 1; // explicit semicolon (redundant but valid)
var c = ( 1 // no automatic semicolon here (inside parentheses)
+ 2 ) * 3 // semicolon inserted after the closing parenthesis
}
This means that expressions can be split across multiple lines when parentheses or brackets keep them together:
let result = (
some_long_function_name(arg1, arg2)
+ another_value
)
2.2.6. Comments
A comment is text that the compiler ignores but is useful for programmers.
Block comments start with
/*and end with*/. Block comments can span multiple lines and can be nested:Line comments start with
//and extend to the end of the line: