3a83b6eb80
24 new functions covering counting (str_count, str_count_chars, str_count_bytes, str_count_lines, str_count_words, str_count_letters, str_count_digits), finding (str_index_of_all, str_last_index_of, str_find_chars), transforming (str_repeat, str_reverse, str_strip_prefix/suffix/chars, str_lstrip, str_rstrip), character classification (is_letter, is_digit, is_alphanumeric, is_whitespace, is_punctuation, is_uppercase, is_lowercase), and splitting/joining (str_split_lines, str_split_chars, str_split_n, str_join). Phase 1 is byte-level + ASCII character classes. Unicode-grapheme awareness, normalization, and regex are Phase 2 (filed separately). Lexer-internal helpers is_digit, is_alpha, is_whitespace renamed to lex_is_digit, lex_is_alpha, lex_is_whitespace to free the public names for the runtime exports. The El compiler's lexer.el and the bundled elc-combined.el both updated. Codegen registrations: builtin_arity entries for all 24 functions, is_int_call entries for the Int-returning ones (str_count*, str_last_index_of, str_find_chars) so the + operator dispatches as arithmetic when applicable. Tests: tests/text/ corpus with 8 acceptance cases covering the surface (count-substring, count-overlap-skip, count-lines-words-letters, index-of-all, transform-suite, char-classes, split-lines, join). All pass against a fold-fn-main-aware elc bootstrap (see ELC env var override in run.sh). Self-host fixed point: elc-combined.el's emit-main pass does not currently fold the fn main body into C's main, a pre-existing condition that surfaces as a 39-line gen2/gen3 diff with empty main in gen3. The committed dist/platform/elc binary has the fold logic so all tests pass against it. Filing the elc-combined fold-fn-main fix separately. This commit does not introduce new self-host drift.
17 lines
578 B
EmacsLisp
17 lines
578 B
EmacsLisp
// 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())
|
|
}
|