Skip to content

MS2 Syntax

GoogleFeud edited this page Feb 1, 2021 · 10 revisions

The MS2 syntax is pretty similar to javascript, but there are a few differences, missing features, and some nice additions.

Table Of Contents

Literals

Comments

There are only inline comments.

// Comment...

Meta tags

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"

Numbers

1
3.14
200_000 // 200 000

Boolean

true
false

Strings

Strings literals only work with double quotes. You can use variables inside strings by placing a $ before the variable name.

"Hello, World!"
"Thank you, $variable"

Null

There is no undefined in MS2.

null

Arrays

[1, 2, null, true, "Hello!"]

Objects

{
a: 1,
b: 2,
c: null
}

Functions

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;

Expressions

Assignment

Returns the value. This also accounts for +=, -=, *= and /=.

variableName = "value";

Comparison

Same for >, <, >=, <=, !=. Unlike javascript, there's only strict comparison, which means 1 == "1" will yield false.

variableName == "something"

And

Same for ||. && returns the second one if both are true, and || will return the second one if the first one is falsey.

variable1 && variable

Ternery

a > b ?? ifTrue:ifFalse 

Not

!value

Call

func(arg1, arg2, arg3);

Call pipeline

expression |> function |> function1 |> ...

Property access

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];

Statements

Declaration

let name = "value";
const constantName = 3.14;

If

if (expression) {

} else if (expression) {

} else {

}

Loop

loop(check) {
 // Loop through an iterator
}
loop(check; after) {
   // code
}  
loop(init; check; after) {
   // code
} 
loop {
  // Infinite loop
}

Export

const something = 5;
export something;

Clone this wiki locally