GRW — Graph Rewriting in Rust
GRW is an embedded graph rewriting system that runs inside a Rust process. It provides type-safe domain-specific languages for graph construction, transactional mutation, and morphism-based pattern matching.
The Three DSLs
mgraph!— graph literal (likevec!) for constructing graphs declarativelymodify!— transactional graph mutation: add/remove/change nodes and edges atomicallysearch!— graph pattern matching iterator with morphism control
A link between two nodes can hold a composite value: several typed parts, included, excluded and searched for one at a time.
All DSL fragments are plain Rust structs — they can be constructed, composed, and manipulated programmatically before being passed to the macros or the underlying from_fragment() / modify() / compile() functions directly.
The graph and modify DSLs — mgraph!, vgraph! and modify! — are macro_rules! macros that overload Rust operators (^, >>, <<, &, !) to express graph edge semantics. search! and pattern! are procedural macros whose pattern grammar lives in the grw_pattern crate; they, the #[grw::repl] attribute, #[derive(Val)] and #[derive(Part)] come from grw_derive, a required dependency of grw.
Quick Example
use grw::*;
use grw::graph::edge;
// construct a triangle
let g: graph::MUndir0 = mgraph![
N(0) ^ (N(1) ^ (N(2) ^ n(0)))
].unwrap();
// search for edges (Mono morphism)
let session = search![&g,
get(Mono) { N(0) ^ N(1) }
].unwrap();
for m in &session {
let a = m.get(0).unwrap();
let b = m.get(1).unwrap();
println!("{:?} — {:?}", a, b);
}