mirror of
https://github.com/Dummi26/mers.git
synced 2026-02-05 06:46:31 +01:00
updated site + added docs/builtins.md + statements can end with ',' to differentiate '1, -2' from '1 - 2' == '-1'.
This commit is contained in:
@@ -6,52 +6,52 @@ 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 = ""
|
||||
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.substring(0 code_width_limit_chars)
|
||||
}
|
||||
line = line
|
||||
&line = line
|
||||
.replace("&" "&")
|
||||
.replace("<" "<")
|
||||
.replace(">" ">")
|
||||
out = out.add(line.add("<br>"))
|
||||
&out = out.add(line.add("<br>"))
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
// data
|
||||
|
||||
index = read_string("index.html")
|
||||
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)
|
||||
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 = ""
|
||||
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
|
||||
&out = out + welcome_script
|
||||
} else if line == "$build_script" {
|
||||
out = out + build_script
|
||||
&out = out + build_script
|
||||
} else if line == "$index.html" {
|
||||
out = out + index_html
|
||||
&out = out + index_html
|
||||
}
|
||||
} else {
|
||||
// remove spaces
|
||||
loop {
|
||||
if line.starts_with(" ") {
|
||||
line = line.substring(1)
|
||||
&line = line.substring(1)
|
||||
} else {
|
||||
true // break
|
||||
}
|
||||
}
|
||||
out = out + line + "\n"
|
||||
&out = out + line + "\n"
|
||||
}
|
||||
}
|
||||
fs_write("../index.html" string_to_bytes(out)).assume_no_enum()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
fn get_number_input(question string) {
|
||||
println(question)
|
||||
input = read_line()
|
||||
input := read_line()
|
||||
// try to parse to an int, then a float.
|
||||
in = match input {
|
||||
in := match input {
|
||||
input.parse_int() input
|
||||
input.parse_float() input
|
||||
}
|
||||
@@ -15,7 +15,7 @@ fn get_number_input(question string) {
|
||||
// return type is int/float/Err(string)
|
||||
}
|
||||
|
||||
answer = get_number_input("What is your favorite number?")
|
||||
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.
|
||||
@@ -39,9 +39,9 @@ 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 := 0
|
||||
() {
|
||||
i = i + 1
|
||||
&i = i + 1
|
||||
i * i
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user