mers/mers_lib
Mark 817ed25f96 add warning to if-statement in check mode
warning is shown if the condition of an
if statement can never be true or false,
and the user used the check command.
warnings are not shown when you use `mers run`.
2024-08-29 15:48:01 +02:00
..
examples convert more stdlib functions and add rounding 2024-07-03 11:59:22 +02:00
src add warning to if-statement in check mode 2024-08-29 15:48:01 +02:00
tests add some basic tests 2024-07-03 20:24:14 +02:00
Cargo.toml version bump 2024-07-03 13:42:56 +02:00
init_to.rs full rewrite, kinda works 2023-07-28 00:33:15 +02:00
README.md mers_lib to 0.5.0, readme updated 2024-02-17 14:06:19 +01:00

mers-lib

The library behind mers.

With this, you can parse, compile, check and run mers code. You can also add your own functions and types which can then be used from mers, if you really want to.

Running mers

There are four steps to running mers code. The examples show you how to actually implement them, this readme only explains what they do any why.

1. Parsing

This first step converts the source code, a string, to a parsed mers statement.

In this step, syntax errors and unknown variables are caught.

2. Compiling

This converts a parsed mers statement to a compiled one. It almost never produces an error.

3. Checking

This step is optional. If you parse and compile your source code, you can (try to) run it. However, mers assumes that all mers code you run is actually valid, so if you don't check your codes validity, mers will probably panic while running your code.

This step performs all the type-checking and determines the output type of your code, if it is valid.

For example, the following code is valid and has the return type Int/Float:

my_condition := true

if my_condition {
  5
} else {
  1.4
}

4. Running

This step assumes that the code it is running is actually valid, so it never returns an error. As long as check didn't return an error in Step 3, it is safe to assume that this will return the value produced by the code. We can also assume that the return value has a type which is included in that determined by check. If check returned an error, this will likely panic.