A port of ripgrep (rg) to MoonBit, for native and WebAssembly
git clone https://github.com/moonbit-community/rg.mbt
cd rg.mbt
moon build --release cmd/rg# native
moon build --release cmd/rg
_build/native/release/build/cmd/rg/rg.exe --help
# wasm, via moon's runner (paths are relative to the current directory)
moon run --target wasm cmd/rg -- PATTERN some/dir
# wasm, via wasmtime (preopen the directories you want to search); the
# script builds and optimizes the module (see "Performance")
scripts/build_wasm.sh
wasmtime run --dir . _build/wasm/release/build/cmd/rg/rg.opt.wasm PATTERN .| ripgrep crate | package | notes |
|---|---|---|
| regex-syntax | regex/syntax, regex/unicode | parser, HIR, Unicode tables, literal extraction |
| regex-automata | regex/automata, regex | Thompson NFA, PikeVM, lazy DFA, prefilters, meta regex |
| grep-matcher | matcher | the Matcher trait |
| grep-regex | grep_regex | RegexMatcher |
| grep-searcher | searcher | line-oriented searching, binary detection, transcoding |
| grep-printer | printer, termcolor | standard, summary and JSON output |
| globset | globset | |
| ignore | ignore | gitignore, file types, overrides, directory walking |
| grep-cli | cli | |
| ripgrep (core) | core, cmd/rg | flags, help/man/completions, search driver |
| (std) | sys | OS abstraction for native and WASI |
moon test # native
moon test --target wasm # wasmscripts/run_rg_integration_tests.sh native
scripts/run_rg_integration_tests.sh wasm # needs wasmtime| platform | tests | native | wasm (wasmtime) |
|---|---|---|---|
| Linux | 332 | all pass | 306 pass, 26 skipped |
| macOS | 323 | all pass | 302 pass, 21 skipped |
| search | native | wasm (wasmtime) | wasm (moonrun / V8) |
|---|---|---|---|
| rare literal / no match | 1.0x | 2.1x | 2.8–2.9x |
| case-insensitive literal (-i) | 1.1x | 1.9x | 2.1x |
| alternation of literals | 1.0x | 1.8x | 2.2x |
| regex with a literal suffix ([A-Z][a-z]+Error) | 1.1x | 2.4x | 2.9x |
| regex dominated by the DFA (\w+_\w+\() | 0.9x | 1.9x | 1.9x |
| Unicode class (\p{Greek}) | 1.0x | 2.5x | 3.0x |
| many matches (-c self, -n self, -w, -o) | 1.2–1.3x | 2.6–3.0x | 2.7–3.2x |
| -v (every other line through the sink) | 1.3x | 2.5x | 2.7x |
| -C2 (context lines) | 1.6x | 3.8x | 3.6x |