diff --git a/index.html b/index.html index 17193bb..67bf674 100644 --- a/index.html +++ b/index.html @@ -6,19 +6,43 @@
-#!/usr/bin/env mers
/* welcome to mers */
println("Hello, World!")
42 // return value
+
+fn get_number_input(question string) {
println(question)
input = read_line()
// try to parse to an int, then a float.
in = match input {
input.parse_int() input
input.parse_float() input
}
// 'in' has type int/float/[] because of the match statement
switch! in {
int/float in
// replace [] with an appropriate error before returning
[] Err: "input was not a number."
}
// return type is int/float/Err(string)
}
answer = get_number_input("What is your favorite number?")
// switch can be used to branch based on a variables type.
// switch! indicates that every possible type must be handled.
switch! answer {
int {
println("Entered an integer")
answer.debug() // int
}
float {
println("Entered a decimal number")
answer.debug() // float
}
Err(string) println("Input was not a number!")
}
sleep(2)
// function that returns an anonymous function (function object).
// anonymous functions can be used as iterators in for-loops.
fn count_up() {
count = -1
() {
count = count.add(1)
count
}
}
for num count_up() {
println(num.to_string())
// once num is greater than 60,
// the loop stops and returns num.
if num.gt(60) num else []
}
int/float
can represent a number - int or float.
+Optional types can be []/[t]
- either nothing or one value (tuple with length 0 or 1).
+Mers doesn't have null, it just has the empty tuple []
.
+
+<!DOCTYPE html>
# This document will be processed by build.mers.
# Lines starting with hashtags are comments and will be ignored.
# Lines starting with dollar-signs insert special text.
# To escape this, put a space before the hashtag or dollar sign.
<head>
<meta charset=“UTF-8”>
<link rel="stylesheet" href="site/external.css">
<title>Mark :: mers</title>
</head>
<body>
<h1>Mers</h1>
<section class="container">
<section class="container_left2 code-border">
<pre><code class="mers-code-snippet">
$welcome_script
</code></pre>
</section>
<section class="container_right">
<image
alt="some picture related to mers (todo)"
src="data:image/jpg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAP//////
width="100%" height="100%"
>
<h3>Mers types</h3>
<div>
Mers uses a multiple-types system.
It keeps track of which types a variable could have
and constructs a type with that information.
<br>
For example, <code>int/float</code> can represent a number - int or
Optional types can be <code>[]/[t]</code> - either nothing or one v
Mers doesn't have null, it just has the empty tuple <code>[]</code>
</div>
<h3>No exceptions, no crashes</h3>
<div>
Errors in mers are passed as values.
Because of the type system, you are forced to handle them explicitl
Mers will not crash in unexpected places, because the only way to c
it is by using one of the assume*() functions (similar to unwrap()s
</div>
</section>
</section>
<hr>
<h3>HTML preprocessor to help build this document written in mers:</h3>
<section class="container">
<pre class="container2_left"><code>
$index.html
</code></pre>
<pre class="container2_right"><code class="mers-code-snippet">
$build_script
</code></pre>
</section>
</body>
+
+#!/usr/bin/env mers
// helper functions
fn read_string(path string) {
bytes_to_string(fs_read(path).assume_no_enum()).assume_no_enum()
}
fn code_to_html(code string code_width_limit_chars int) {
out = ""
for line code.regex(".*").assume_no_enum() {
if code_width_limit_chars.gtoe(0).and(line.len().gt(code_width_limit_chars)) {
line = line.substring(0 code_width_limit_chars)
}
line = line
.replace("&" "&")
.replace("<" "<")
.replace(">" ">")
out = out.add(line.add("<br>"))
}
out
}
// data
index = read_string("index.html")
index_html = index.code_to_html(75)
build_script = read_string("build.mers").code_to_html(-1)
welcome_script = read_string("welcome.mers").code_to_html(-1)
// process index.html
out = ""
for line index.regex("\\S*.*").assume_no_enum() {
if line.starts_with("#") {
// comment, ignore
} else if line.starts_with("$") {
if line.eq("$welcome_script") {
out = out.add(welcome_script)
} else if line.eq("$build_script") {
out = out.add(build_script)
} else if line.eq("$index.html") {
out = out.add(index_html)
}
} else {
// remove spaces
loop {
if line.starts_with(" ") {
line = line.substring(1)
} else {
true // break
}
}
out = out.add(line.add("\n"))
}
}
fs_write("../index.html" string_to_bytes(out)).assume_no_enum()
+
+
+
+
$welcome_script
-
+
int/float
can represent a number - int or float.
+ Optional types can be []/[t]
- either nothing or one value (tuple with length 0 or 1).
+ Mers doesn't have null, it just has the empty tuple []
.
+
+$index.html
+
+
+$build_script
+
+