Compiler in Rust (lexer, parser, checker, C codegen), maps, chars, dino fmt, dino lsp (diagnostics, formatting, outline, definition, hover, completion, signature help), docs, examples, VS Code/Vim files. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
30 lines
642 B
Plaintext
30 lines
642 B
Plaintext
// A small CLI tool: count lines and words in files.
|
|
import os
|
|
|
|
struct Stats {
|
|
lines: int
|
|
words: int
|
|
}
|
|
|
|
func count(path: string): (Stats, error) {
|
|
var text = os.read_file(path)? // ? returns the error to the caller
|
|
var stats = Stats{}
|
|
for line in text.lines() {
|
|
stats.lines += 1
|
|
stats.words += line.fields().len()
|
|
}
|
|
return stats, nil
|
|
}
|
|
|
|
func main() {
|
|
var args = os.args
|
|
for path in args[1..] {
|
|
var s, err = count(path)
|
|
if err != nil {
|
|
print("{path}: error: {err}")
|
|
continue
|
|
}
|
|
print("{path}: {s.lines} lines, {s.words} words")
|
|
}
|
|
}
|