-
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, null, array (of raw literals) or an object (of raw literals)
#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!"]{
a: 1,
b: 2,
c: null
}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 && variablea > b ?? ifTrue:ifFalse
!value
func(arg1, arg2, arg3);expression->function1->function2->function3...
The [] notation CANNOT be used on objects!
const obj = {a: 1, b: 2, c: 3};
obj.a;
const arr = [1, 2, 3, 4, 5];
arr[4];
Optional chaining:
const obj = {a: { b: { c: null } } };
obj.a?.b?.c?.d;
let name = "value";
const constantName = 3.14;if (expression) {
} else if (expression) {
} else {
}loop(check) {
// Loop through an iterator
}
loop(check; after) {
// code
}
loop(init; check; after) {
// code
}
loop {
// Infinite loop
}
const something = 5;
export something;