restructure: move el compiler content into lang/

This commit is contained in:
Will Anderson
2026-05-05 01:38:51 -05:00
parent ce68f91a38
commit 1ae68962cf
143 changed files with 0 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
// char-classes.el ASCII character classification.
// is_letter("A") && is_digit("7") && is_whitespace(" ")
// && !is_letter("3") && !is_digit("X")
fn run_test() -> Bool {
if !is_letter("A") { return false }
if !is_digit("7") { return false }
if !is_whitespace(" ") { return false }
if is_letter("3") { return false }
if is_digit("X") { return false }
return true
}
fn main() -> Void {
if run_test() {
println("true")
} else {
println("false")
}
}
@@ -0,0 +1,16 @@
// count-lines-words-letters.el composite count test.
// Input "Hello world\nGoodbye world\n":
// lines: 2 (each \n closes a line)
// words: 4 (Hello, world, Goodbye, world)
// letters: 22 (Hello=5 + world=5 + Goodbye=7 + world=5)
fn run_test() -> String {
let s: String = "Hello world\nGoodbye world\n"
let lines: Int = str_count_lines(s)
let words: Int = str_count_words(s)
let letters: Int = str_count_letters(s)
return int_to_str(lines) + "/" + int_to_str(words) + "/" + int_to_str(letters)
}
fn main() -> Void {
println(run_test())
}
@@ -0,0 +1,11 @@
// count-overlap-skip.el non-overlapping advance: "aaaa" / "aa" -> 2.
// After each match, the cursor advances by len(sub), so overlapping matches
// are skipped. This is the universal default in C/Python/Go/etc.
fn run_test() -> Int {
let s: String = "aaaa"
return str_count(s, "aa")
}
fn main() -> Void {
println(int_to_str(run_test()))
}
@@ -0,0 +1,9 @@
// count-substring.el non-overlapping substring count.
fn run_test() -> Int {
let s: String = "abc abc abc"
return str_count(s, "abc")
}
fn main() -> Void {
println(int_to_str(run_test()))
}
+21
View File
@@ -0,0 +1,21 @@
// index-of-all.el every byte offset of a substring.
// "abXcdXefX" / "X" -> [2, 5, 8]. Empty list when no matches.
fn run_test() -> String {
let positions: [Int] = str_index_of_all("abXcdXefX", "X")
let n: Int = native_list_len(positions)
let out: String = ""
let i: Int = 0
while i < n {
let p: Int = native_list_get(positions, i)
if i > 0 {
let out = out + ","
}
let out = out + int_to_str(p)
let i = i + 1
}
return out
}
fn main() -> Void {
println(run_test())
}
+12
View File
@@ -0,0 +1,12 @@
// join.el list-of-string join with separator.
fn run_test() -> String {
let parts: [String] = native_list_empty()
let parts = native_list_append(parts, "alpha")
let parts = native_list_append(parts, "beta")
let parts = native_list_append(parts, "gamma")
return str_join(parts, ", ")
}
fn main() -> Void {
println(run_test())
}
+10
View File
@@ -0,0 +1,10 @@
// split-lines.el \n-delimited split, \r\n folded, trailing empty dropped.
// "alpha\nbeta\r\ngamma\n" -> ["alpha", "beta", "gamma"], len = 3.
fn run_test() -> Int {
let lines: [String] = str_split_lines("alpha\nbeta\r\ngamma\n")
return native_list_len(lines)
}
fn main() -> Void {
println(int_to_str(run_test()))
}
@@ -0,0 +1,13 @@
// transform-suite.el repeat, reverse, strip prefix/suffix/chars.
fn run_test() -> String {
let a: String = str_repeat("ab", 3) // "ababab"
let b: String = str_reverse("hello") // "olleh"
let c: String = str_strip_prefix("foobar", "foo") // "bar"
let d: String = str_strip_suffix("hello.md", ".md") // "hello"
let e: String = str_strip_chars(" \thello \n", " \t\n") // "hello"
return a + "|" + b + "|" + c + "|" + d + "|" + e
}
fn main() -> Void {
println(run_test())
}