Command syntax

Each rule contains a sequence of commands introduced by the keyword commands, separated by semicolon symbol ; and surrounded by braces.

Node deletion

The following command removes the A nodes and all its incident edges.

del_node A

Node creation

To create a new node, the command is add_node. The command below creates a new node and give it the identifier A until the end the rule application.

add_node A

Moreover, if the node must be placed at a specific position in the linear order of the nodes, two syntax are available: the new node B (resp. C) is placed on the immediate left (resp. right) of the node N.

add_node B :< N
add_node C :> N

Edge deletion

To delete an edge, the del_edge command can refer either to the full description of the edge or to an identifier e given in the pattern:

del_edge A -[obj]-> B;
del_edge e;

NOTE: for the first syntax, if the corresponding edge does not exists, an exception is raised and the full rewriting process is stopped.

Add a new edge

There are two ways to add a new edge: with an given label edge or with a label edge coming from the pattern.

Add a new edge with a given label

The syntax of the command is:

add_edge N -[suj]-> M

Add a new edge with a label taken in the pattern

The command add_edge e: N -> M add a new edge in the current graph from the node matched with identifier N to the node matched with identifier M with the same label as the edge that was match in the pattern with the edge identifier e.



package M {
  rule r {
    pattern { A[phon=A]; B[phon=B]; e: B -> A }
    commands { del_edge e; add_edge e: A -> B }
strat main { Onf(M) }

graph {
  A [phon="A"];
  B [phon="B"];
  B -[x]-> A;
  B -[y]-> A;
  B -[z]-> A;

With the command grew transform -grs add_edge_pattern.grs -i -o, the rewriting will produce the graph below.

Edge redirection

Commands are available to move globally incident edges of some node of the pattern. keywords are shift_in, shift_out and shift, respectively for moving in-edges, out-edges and all incident edges.

Brackets can be used to select the set of edges to move according to their labelling.

  shift A ==> B
  shift_out B =[suj|obj]=> C
  shift_in C =[^suj|obj]=> D

The action of the 3 commands above are respectively:

Effective commands

There are situations where commands may not be properly defined. Consider the rule r below and and a graph with two nodes A and B linked by two edges X and Y both going from A to B. The rule R can be applied to the graph but the command add_edge can not be applied (the edge labelled Y already exists).

rule r {
  pattern { N -[X]-> M }
  commands { add_edge N -[Y]-> M }

The fact that a rule is effective or not depends on the graph on which the rule is applied.

In fact, to deal with this case, Grew has two running modes with different behaviors.

  1. In the default mode, ineffective commands are simply ignored and the rewriting goes on with the next commands or rules.
  2. In the safe mode (set by the -safe_commands argument), an ineffective command stop the rewriting with and produces an exection error.

List of ineffective Commands

Command which may be ineffective are:

Note that it is always possible to define a Graph Rewriting System with only effective commands following the procedure: