mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 14:13:52 +01:00
remove github.io site due to overlap with readme
This commit is contained in:
parent
b6d01c7c25
commit
c831512661
@ -29,6 +29,15 @@ Mers is written in rust. If you have `cargo`, use the build script in `build_scr
|
|||||||
|
|
||||||
Now, create a new text file (or choose one from the examples) and run it: `mers <file>`.
|
Now, create a new text file (or choose one from the examples) and run it: `mers <file>`.
|
||||||
|
|
||||||
|
## Known Issues (only major ones)
|
||||||
|
|
||||||
|
### Multithreading
|
||||||
|
|
||||||
|
If a function is called from two threads, all local variables of that function are shared.
|
||||||
|
This doesn't affect builtin functions, and since functions usually don't take long to execute,
|
||||||
|
the change of anyone encountering this is low, but it's something to be aware of.
|
||||||
|
It's a simple fix in theory, but a lot of work to implement, which is why the bug isn't fixed yet.
|
||||||
|
|
||||||
## Docs
|
## Docs
|
||||||
|
|
||||||
[intro](docs/intro.md)
|
[intro](docs/intro.md)
|
||||||
|
78
external.css
78
external.css
@ -1,78 +0,0 @@
|
|||||||
body {
|
|
||||||
color: white;
|
|
||||||
background-color: #200f21;
|
|
||||||
}
|
|
||||||
h1, h2, h3 {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
hr {
|
|
||||||
display: block;
|
|
||||||
height: 1px;
|
|
||||||
border: 0;
|
|
||||||
border-top: 1px solid #ccc;
|
|
||||||
margin: 1em 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mers-code-snippet {
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container {
|
|
||||||
height: auto;
|
|
||||||
overflow: auto;
|
|
||||||
}
|
|
||||||
.container_left {
|
|
||||||
margin-left: 8%;
|
|
||||||
width: 20%;
|
|
||||||
margin-right: 5%;
|
|
||||||
float: left;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
.container_center {
|
|
||||||
margin-left: 0.5%;
|
|
||||||
width: 30%;
|
|
||||||
margin-right: 0.5%;
|
|
||||||
border-style: dotted;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
.container_left2 {
|
|
||||||
margin-left: 8%;
|
|
||||||
width: 50%;
|
|
||||||
margin-right: 5%;
|
|
||||||
float: left;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
.container_right {
|
|
||||||
margin-left: 5%;
|
|
||||||
width: 20%;
|
|
||||||
margin-right: 8%;
|
|
||||||
float: right;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
.container2_left {
|
|
||||||
margin-left: 8%;
|
|
||||||
width: 40%;
|
|
||||||
float: left;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
.container2_right {
|
|
||||||
margin-right: 8%;
|
|
||||||
width: 40%;
|
|
||||||
float: right;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.code-border {
|
|
||||||
border-style: double;
|
|
||||||
}
|
|
||||||
.textalign-center {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
.afterpagebreak {
|
|
||||||
width: 100%;
|
|
||||||
page-break-before: always;
|
|
||||||
}
|
|
||||||
.fullwide {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
48
index.html
48
index.html
@ -1,48 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<head>
|
|
||||||
<meta charset=“UTF-8”>
|
|
||||||
<link rel="stylesheet" href="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">
|
|
||||||
fn get_number_input(question string) {<br> println(question)<br> input := read_line()<br> // try to parse to an int, then a float.<br> in := match {<br> input.parse_int() n n<br> input.parse_float() n n<br> }<br> // 'in' has type int/float/[] because of the match statement<br> switch! in {<br> int/float in in<br> // replace [] with an appropriate error before returning<br> [] [] Err: "input was not a number."<br> }<br> // return type is int/float/Err(string)<br>}<br><br>answer := get_number_input("What is your favorite number?")<br><br>answer.debug() // type: int/float/Err(string)<br>// switch can be used to branch based on a variables type.<br>// switch! indicates that every possible type must be handled.<br>switch! answer {<br> int num {<br> println("Entered an integer")<br> num.debug() // type: int<br> }<br> float num {<br> println("Entered a decimal number")<br> num.debug() // type: float<br> }<br> Err(string) [] println("Input was not a number!")<br>}<br><br>// wait one second<br>sleep(1)<br><br>// function that returns an anonymous function (function object).<br>// anonymous functions can be used as iterators in for-loops.<br>fn square_numbers() {<br> i := 0<br> () {<br> &i = i + 1<br> i * i<br> }<br>}<br><br>for num square_numbers() {<br> println(num.to_string())<br> // once num is greater than 60, the loop stops.<br> num.gt(50)<br>}<br></code></pre>
|
|
||||||
</section>
|
|
||||||
<section class="container_right">
|
|
||||||
<image
|
|
||||||
alt="some picture related to mers (todo)"
|
|
||||||
src="data:image/jpg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAP//////////////////////////////////////////////////////////////////////////////////////2wBDAf//////////////////////////////////////////////////////////////////////////////////////wAARCAGCAcQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAECA//EACIQAQEAAgICAwEBAQEAAAAAAAABAhESMUFRIWFxgTLRIv/EABUBAQEAAAAAAAAAAAAAAAAAAAAB/8QAFhEBAQEAAAAAAAAAAAAAAAAAABFB/9oADAMBAAIRAxEAPwDQACgAAAAAKAAAIoCCoAAAAAAAioAAAAAACYeW2MPLYAAAAAAAAAAAAAAAAAAAAAAAAAAMgAoAAACooAICbWXbDWINAAAAIoCAAAAAAIoCBakoKDNoLh5bYw8tgAAAAAAAAAAAAAAAAAAAAAAAAAAyCgAAAoAACKwCXSy6RFR03By26Y1FaAAAARUABAUEBWLV2yAgA3OmasqA1h1W2MOq2Dje6F7pJsAa4nEGRricQZCzSAogCiAKIAogCiAKIAoig7AAAAyqKAAAqKAACXphuufQKyuyfKomlx+KfiyIroz5Wsg2ImwL2qeUBpIJsGmL2WpsBAAAAABvDptj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ano1PSgJqejU9KAmp6NT0oCano1PSgJqejU9KAmp6NT0oCano1PSgJqehQAAAAAAByt3W8unMBBZN0CS10mMiyaUAAHKzSOtm3KgjWN1UQHTlE5sANcqm0AAAFl1TVQHaXauWN1XUBjPr+tsZ9f0Gp0pAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGM74YXK7qAOmM1GJN11AAAAAZym2gHFHayVOMByHXjF1AcdVqY11AYmMa1FAGMsfMbAcXZni0Axn1P1tjPqfoNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJbqK55b2DKKsm6DeM+GgAAAAAAAAAAAAAAAAAAAYz6n62xn4/QbAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABN6BXPK+FttZ0COmM0xO46gAAAAAAAAAAAAAAAAAAAAMZ+P1tjPx+g2AAAAAAAAAAAAAAAAAAAAAAAAAAAAlUBj/0y6gOR8umoaBznbqmooAAAAAAAAAAAAAAAAAAAADGXj9bYy8foNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMZeP0AbAAAAAAAAAAAAAAAAAAAAAAAAAAAB//Z"
|
|
||||||
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 float.
|
|
||||||
Optional types can be <code>[]/[t]</code> - either nothing or one value (tuple with length 0 or 1).
|
|
||||||
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 explicitly.
|
|
||||||
Mers will not crash in unexpected places, because the only way to crash
|
|
||||||
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>
|
|
||||||
<!DOCTYPE html><br># This document will be processed by build.mers.<br># Lines starting with hashtags are comments and will be ignored.<br># Lines starting with dollar-signs insert special text.<br># To escape this, put a space before the hashtag or dollar sign.<br><head><br> <meta charset=“UTF-8”><br> <link rel="stylesheet" href="external.css"><br> <title>Mark :: mers</title><br></head><br><body><br> <h1>Mers</h1><br> <section class="container"><br> <section class="container_left2 code-border"><br> <pre><code class="mers-code-snippet"><br>$welcome_script<br> </code></pre><br> </section><br> <section class="container_right"><br> <image<br> alt="some picture related to mers (todo)"<br> src="data:image/jpg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAP//////<br> width="100%" height="100%"<br> ><br> <h3>Mers types</h3><br> <div><br> Mers uses a multiple-types system.<br> It keeps track of which types a variable could have<br> and constructs a type with that information.<br> <br><br> For example, <code>int/float</code> can represent a number - int or<br> Optional types can be <code>[]/[t]</code> - either nothing or one v<br> Mers doesn't have null, it just has the empty tuple <code>[]</code><br> </div><br> <h3>No exceptions, no crashes</h3><br> <div><br> Errors in mers are passed as values.<br> Because of the type system, you are forced to handle them explicitl<br> Mers will not crash in unexpected places, because the only way to c<br> it is by using one of the assume*() functions (similar to unwrap()s<br> </div><br> </section><br> </section><br> <hr><br> <h3>HTML preprocessor to help build this document written in mers:</h3><br> <section class="container"><br> <pre class="container2_left"><code><br>$index.html<br> </code></pre><br> <pre class="container2_right"><code class="mers-code-snippet"><br>$build_script<br> </code></pre><br> </section><br></body><br><br></code></pre>
|
|
||||||
<pre class="container2_right"><code class="mers-code-snippet">
|
|
||||||
#!/usr/bin/env mers<br><br>// helper functions<br><br>fn read_string(path string) {<br> bytes_to_string(fs_read(path).assume_no_enum()).assume_no_enum()<br>}<br>fn code_to_html(code string code_width_limit_chars int) {<br> out := ""<br> for line code.regex(".*").assume_no_enum() {<br> if code_width_limit_chars.gtoe(0).and(line.len().gt(code_width_limit_chars)) {<br> &line = line.substring(0 code_width_limit_chars)<br> }<br> &line = line<br> .replace("&" "&amp;")<br> .replace("<" "&lt;")<br> .replace(">" "&gt;")<br> &out = out.add(line.add("<br>"))<br> }<br> out<br>}<br><br>// data<br><br>index := read_string("index.html")<br><br>index_html := index.code_to_html(75)<br>build_script := read_string("build.mers").code_to_html(-1)<br>welcome_script := read_string("welcome.mers").code_to_html(-1)<br><br>// process index.html<br><br>out := ""<br>for line index.regex("\\S*.*").assume_no_enum() {<br> if line.starts_with("#") {<br> // comment, ignore<br> } else if line.starts_with("$") {<br> if line == "$welcome_script" {<br> &out = out + welcome_script<br> } else if line == "$build_script" {<br> &out = out + build_script<br> } else if line == "$index.html" {<br> &out = out + index_html<br> }<br> } else {<br> // remove spaces<br> loop {<br> if line.starts_with(" ") {<br> &line = line.substring(1)<br> } else {<br> true // break<br> }<br> }<br> &out = out + line + "\n"<br> }<br>}<br>fs_write("../index.html" string_to_bytes(out)).assume_no_enum()<br><br></code></pre>
|
|
||||||
</section>
|
|
||||||
</body>
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
|||||||
#!/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 == "$welcome_script" {
|
|
||||||
&out = out + welcome_script
|
|
||||||
} else if line == "$build_script" {
|
|
||||||
&out = out + build_script
|
|
||||||
} else if line == "$index.html" {
|
|
||||||
&out = out + index_html
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// remove spaces
|
|
||||||
loop {
|
|
||||||
if line.starts_with(" ") {
|
|
||||||
&line = line.substring(1)
|
|
||||||
} else {
|
|
||||||
true // break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&out = out + line + "\n"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fs_write("../index.html" string_to_bytes(out)).assume_no_enum()
|
|
@ -1,54 +0,0 @@
|
|||||||
<!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="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//////////////////////////////////////////////////////////////////////////////////////2wBDAf//////////////////////////////////////////////////////////////////////////////////////wAARCAGCAcQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAECA//EACIQAQEAAgICAwEBAQEAAAAAAAABAhESMUFRIWFxgTLRIv/EABUBAQEAAAAAAAAAAAAAAAAAAAAB/8QAFhEBAQEAAAAAAAAAAAAAAAAAABFB/9oADAMBAAIRAxEAPwDQACgAAAAAKAAAIoCCoAAAAAAAioAAAAAACYeW2MPLYAAAAAAAAAAAAAAAAAAAAAAAAAAMgAoAAACooAICbWXbDWINAAAAIoCAAAAAAIoCBakoKDNoLh5bYw8tgAAAAAAAAAAAAAAAAAAAAAAAAAAyCgAAAoAACKwCXSy6RFR03By26Y1FaAAAARUABAUEBWLV2yAgA3OmasqA1h1W2MOq2Dje6F7pJsAa4nEGRricQZCzSAogCiAKIAogCiAKIAoig7AAAAyqKAAAqKAACXphuufQKyuyfKomlx+KfiyIroz5Wsg2ImwL2qeUBpIJsGmL2WpsBAAAAABvDptjDpsHG91cUvdXEHRm5KxQXksu3NqA1YxXRigyKaBAABdGgQU0CC6NUEF0AiooOwAAAMgbBRNqCeVZ8tUE2bRIDW0olvwCImwGo1GcemgavTMNoCoAKixARFQAAAAAEBRAHTDptjDpsHG91cUvdXEG2K6M3EGGpF4nQK51bUBqLUi0GKFAbiZLEyBmOmmI2B0biWsA6M2LKUHNQB2AAABkFBBQEFAZ+DUaAZ0lnw2lnwDkDWINaNNAM6qarYDGqfLYDHyny6AOaOqQHMdNRNQGBvXyagMDWouoDmN6iaBrDptjDpsHG91cUvdXEHRi1pigsrVc43AYqOljANRakWgxQpAbiZLEyBI2xG/AMVlqsg3GqzGqDnQoDsAAADKooAAAKCCoAXqiZX4oOSy6J2tx9A6S7VxlsrcyBsZ2bBTcZAa3E3E0mga3DbGjQNbNs/J8gogCgnyCoANYdNs4dNA43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AAAAAlUBj/0y6gOR8umoaBznbqmooAAAAAAAAAAAAAAAAAAAADGXj9bYy8foNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMZeP0AbAAAAAAAAAAAAAAAAAAAAAAAAAAAB//Z"
|
|
||||||
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 float.
|
|
||||||
Optional types can be <code>[]/[t]</code> - either nothing or one value (tuple with length 0 or 1).
|
|
||||||
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 explicitly.
|
|
||||||
Mers will not crash in unexpected places, because the only way to crash
|
|
||||||
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>
|
|
@ -1,52 +0,0 @@
|
|||||||
fn get_number_input(question string) {
|
|
||||||
println(question)
|
|
||||||
input := read_line()
|
|
||||||
// try to parse to an int, then a float.
|
|
||||||
in := match {
|
|
||||||
input.parse_int() n n
|
|
||||||
input.parse_float() n n
|
|
||||||
}
|
|
||||||
// 'in' has type int/float/[] because of the match statement
|
|
||||||
switch! in {
|
|
||||||
int/float in 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?")
|
|
||||||
|
|
||||||
answer.debug() // type: int/float/Err(string)
|
|
||||||
// switch can be used to branch based on a variables type.
|
|
||||||
// switch! indicates that every possible type must be handled.
|
|
||||||
switch! answer {
|
|
||||||
int num {
|
|
||||||
println("Entered an integer")
|
|
||||||
num.debug() // type: int
|
|
||||||
}
|
|
||||||
float num {
|
|
||||||
println("Entered a decimal number")
|
|
||||||
num.debug() // type: float
|
|
||||||
}
|
|
||||||
Err(string) [] println("Input was not a number!")
|
|
||||||
}
|
|
||||||
|
|
||||||
// wait one second
|
|
||||||
sleep(1)
|
|
||||||
|
|
||||||
// function that returns an anonymous function (function object).
|
|
||||||
// anonymous functions can be used as iterators in for-loops.
|
|
||||||
fn square_numbers() {
|
|
||||||
i := 0
|
|
||||||
() {
|
|
||||||
&i = i + 1
|
|
||||||
i * i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for num square_numbers() {
|
|
||||||
println(num.to_string())
|
|
||||||
// once num is greater than 60, the loop stops.
|
|
||||||
num.gt(50)
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user