To install dependencies:
bun install
To run:
bun run src/compile.ts "filepath.mtg"
This project was created using bun init
in bun v1.0.1. Bun is a fast all-in-one JavaScript runtime.
The Magic The Compiler supports the following syntax:
To declare comments, use //
at any point, jumping a line ends the comment.
// This is an example
reveal("Hello World")
To declare a variable, use the cast
for a mutable variable and choose
for a immutable variable keyword followed by the variable name and an optional initial value
cast w;
cast x = 10;
choose y = 5;
x = y
reveal(x)
Supports strings
, numbers
, objects
and booleans
.
To declare a function, use the tap
keyword followed by the function name and its parameters
p.s: you don`t need to use a return
keyword to return a value from the function
tap sum(x, y) {
x + y
}
sum(10, 10)
To declare a loop, use the control
for while loops and storm
for for loops
cast i = 0;
control(i < 10) {
reveal(i)
i += 1
}
i = 0;
storm(i < 10; i += 1) {
reveal(i)
}
To declare a condition you can use the may
and or
keywords with a conditional expression inside the may statement
may(10 > 0) {
reveal("True")
} or {
reveal("False")
}
Magic the compiler supports all of the arithmetic and comparison operations:
Sum, Subtraction, Multiplication, Division, Deeply Equal, Greater (or equal) than, Less (or equal) than, Deeply Different
cast x = 10;
cast y = 11;
reveal(x == 10)
reveal(y != 10)
reveal(x >= 10)
reveal(x <= 10)
reveal(x > y)
reveal(x < y)
reveal(x + 10)
reveal(x - 10)
reveal(x * 10)
reveal(x / 10)
Magic the compiler has built in functions like:
reveal
(...args) -> Prints all the arguments of the function
exile
() -> Ends process
sacrifice
(variable) -> Deassign variables
match
(regex, string) -> match string against regex
shuffle
(variable) -> shuffles the string value of a variable
count
(variable) -> counts the number of characters in a string variable
cast x = "sad";
cast y = "sad";
reveal("hello", "world")
sacrifice(x)
match("/[0-9]/", "hello")
shuffle(y)
count(y)
tap calcFatorial(numero) {
may(numero > 0) {
numero * calcFatorial(numero - 1)
} or {
1
}
}
cast object = {
power: calcFatorial(8)
};
reveal(object.power)