Skip to content

BuggyOrg/rewrite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rewrite

Tools for replacing parts of a graph.

Usage

The generic replacement method is


g1 = API.apply(g, set, matcher, generator)
  • g is a graph
  • set is an arbitrary set of candidates for the matcher
  • matcher takes a candidate and the graph and returns false iff there is no match, otherwise the return value is arbitrary
  • generator takes the return value of the matcher and the graph and returns a new graph

A few candidate sets are provided:


g1 = API.applyNode(matcher, generator)(g)
g2 = API.applyEdge(matcher, generator)(g)
g3 = API.applyPort(matcher, generator)(g)
g4 = API.applyComponent(matcher, generator)(g)

These replacement rules can be iterated like this:


// matches nothing
const rule1 = API.applyNode((node, g) => false, (match, g) => null)
// matches everything, does nothing
const ruleTrivial = API.applyNode((node, g) => true, (match, g) => g)
const rewriter = API.rewrite([rule1, rule2], maxIterations)
g1 = rewriter(g)

where maxIterations is optional (default: Infinity)

Written with StackEdit.

About

Tools for replacing parts of a graph.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •