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)
moon build --release --target wasm cmd/rg
wasmtime run --dir . _build/wasm/release/build/cmd/rg/rg.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.0–1.1x | 2.0–2.1x | 2.9–3.1x |
| case-insensitive literal (-i) | 1.1x | 2.2x | 2.3x |
| alternation of literals | 1.0x | 2.0x | 2.4x |
| regex with a literal suffix ([A-Z][a-z]+Error) | 1.1x | 2.7x | 3.2x |
| regex dominated by the DFA (\w+_\w+\() | 0.9x | 2.5x | 1.9x |
| Unicode class (\p{Greek}) | 1.0x | 4.0x | 2.7x |
| many matches (-c self, -n self, -w, -o) | 1.2–1.3x | 3.0–3.7x | 3.0–3.7x |
| -v (every other line through the sink) | 1.3x | 3.2x | 2.9x |
| -C2 (context lines) | 1.6x | 5.2x | 4.2x |
Install
Download zipA port of ripgrep (rg) to MoonBit, for native and WebAssembly