Crates.io | mogglo-javascript |
lib.rs | mogglo-javascript |
version | 0.1.1 |
source | src |
created_at | 2023-04-01 19:46:05.454047 |
updated_at | 2023-04-03 15:45:11.195392 |
description | Multi-language AST-based code search and rewriting |
homepage | https://github.com/langston-barrett/mogglo |
repository | https://github.com/langston-barrett/mogglo |
max_upload_size | |
id | 827491 |
size | 19,173 |
Mogglo is a multi-language AST-based code search and rewriting tool. Mogglo supports embedding Lua code in search patterns and replacements.
Mogglo focuses on the following goals:
The following examples give a taste of Mogglo. Here's how to find pointless assignments of an expression to itself:
mogglo-rust --detail 'let $x = $x;' ./**/*.rs
Lua code is wrapped in braces. Lua can recursively match patterns with rec
.
Here's a pattern to detect out-of-bounds array accesses:
mogglo-rust 'while $i <= $buf.len() { ${{ rec("$buf.get($i)") }} }' ./**/*.rs
Here's how to unroll a simple loop:
mogglo-rust \
'for $i in 0..$h { $b; }' \
--where 'h_num = tonumber(h); return h_num ~= nil and h_num % 4 == 0' \
--replace 'for $i in 0..${{ string.format("%.0f", h / 4) }} { $b; $b; $b; $b; }' \
./*/**.rs
This transformation demonstrates the power of using Lua: it can't be done with regular expression substitutions and would be very difficult with other codemod tools.
See the documentation for more details!