-
Notifications
You must be signed in to change notification settings - Fork 1
MS2 Syntax
The MS2 syntax is pretty similar to javascript, but there are a few differences, missing features, and some nice additions.
Inline:
// Comment...
Multiline:
/* Comment
Comment */
Meta tags don't get compiled to bytecode, they get returned by the parse function. The meta tag value can be a raw literal - string, number, boolean, or null.
meta name = "something"1
3.14
200_000 // 200 000true
falseStrings literals only work with double quotes. You can use variables inside strings by placing a $ before the variable name.
"Hello, World!"
"Thank you, $variable"There is no undefined in MS2.
null[1, 2, null, true, "Hello!"]Declaring a structure:
struct Person {
name,
age = 18, // Default values
skills? // Nullable
}Instantiating a structure:
const me = Person{name: "GoogleFeud"};
print(me); // {name: "GoogleFeud", age: 18}
Once a structure field has a default value, it's type cannot change.
Why strucutres?
Structures are the best way to guarantee type safety while also doing it implicitly.
This is the only way to define functions. Functions are treated as first-class citizens, they can be assigned to variables and passed as arguments.
(a, b) => {
return a + b;
}Functions can also have only one expression as their body:
(a, b) => a + b;Returns the value. This also accounts for +=, -=, *= and /=.
variableName = "value";Same for >, <, >=, <=, !=. Unlike javascript, there's only strict comparison, which means 1 == "1" will yield false.
variableName == "something"Same for ||. && returns the second one if both are true, and || will return the second one if the first one is falsey.
variable1 && variable!value
func(arg1, arg2, arg3);The [] notation CANNOT be used on objects!
const obj = X{a: 1, b: 2, c: 3};
obj.a;
const arr = [1, 2, 3, 4, 5];
arr[4];
Optional chaining:
const obj = X{a: { b: { c: null } } };
obj.a?.b?.c?.d;
if (expression) {
} else if (expression) {
} else {
}let name = "value";
const constantName = 3.14;Once a let variable is declared with an initializor, it's type cannot be changed after assignment.
loop(check) {
// Loop through an iterator
}
loop(check; after) {
// code
}
loop(init; check; after) {
// code
}
loop {
// Infinite loop
}
const something = 5;
export something;