| Crates.io | resrap-rs |
| lib.rs | resrap-rs |
| version | 0.1.3 |
| created_at | 2025-10-08 11:25:03.226432+00 |
| updated_at | 2025-10-14 16:26:31.249989+00 |
| description | A rule based code generator |
| homepage | |
| repository | https://github.com/osdc/resrap-rs |
| max_upload_size | |
| id | 1873883 |
| size | 42,644 |
Just a parser… in reverse.
Resrap is a seedable, grammar-based code snippet generator. Instead of parsing code, it generates code from formal grammars — producing endless, realistic-looking (or hilariously nonsensical) snippets.
It works with any language that can be described with a grammar (even English if you like!) and is perfect for:
Resrap now also supports probabilistic and infinitely repeatable grammars via the ABNF (Awesome BNF) format — see docs/ABNF.md for full reference.
Resrap reads a grammar and builds a graph of expansions. It then randomly traverses the graph (or deterministically with a seed) to produce snippets that:
<0.2>)^ operatorExample grammar snippet (simplified C):
program : (header+<0.4>) function^;
header:'#include<'identifier'.h>\n';
function:functionheader'{''\n'functioncontent'}';
functionheader:datatype ' ' identifier '(' ')' ;
...
...
#include<success.h>
#include<email.h>
double class(){
while(variable < query && password < variable){
int result = variable + (user / hello);
}
}double user(){
if(class > user && result < class){
float password = 1024.13 - (13.7);
}
}double hello(
go get github.com/ItsArnavSh/Resrap@v0.1.0
//Resrap with Single threaded
rs := resrap.NewResrap()
err := rs.ParseGrammarFile("C", "example/C.g4")
if err != nil {
fmt.Println(err)
return
}
code := rs.GenerateRandom("C", "program", 10)
fmt.Println(code)
//Lets get a multithreaded API set up quick
r := resrap.NewResrapMT(20, 1000) //20 worker pool and 1000 wait queue max size
err = r.ParseGrammarFile("C", "example/C.g4")
if err != nil {
fmt.Println(err)
return
}
//Receive from this
r.StartResrap()
defer r.ShutDownResrap()
codeChan := r.GetCodeChannel()
id := "12321"
r.GenerateRandom(id, "C", "program", 10)
res := <-codeChan
fmt.Println(res.Code)
For benchmarks and performance comparisons, see benchmark-results/Multithreading.md.
Resrap was created to:
“Just a parser… in reverse.”
^ → Infinite generation (loops nodes without halting)<prob> → Weighted probabilities for branching+, *, ?, ()See docs/ABNF.md for full syntax and examples.