package org.nwapw.abacus.lexing.pattern;

import java.util.ArrayList;
import java.util.Collection;

/**
 * A node that is used as structural glue in pattern compilation.
 * @param <T> the type that's used to tell which pattern this node belongs to.
 */
public class LinkNode<T> extends PatternNode<T> {

    @Override
    public void addInto(Collection<PatternNode<T>> into) {
        addOutputsInto(into);
    }

}

@@ -370,16 +370,83 @@
 into) %7B%0A
+        if(!into.contains(this)) %7B%0A            into.add(this);%0A    
         
@@ -467,16 +467,26 @@
 (into);%0A
+        %7D%0A
     %7D%0A%0A%7D

Add link nodes to collections and check for their presence. This prevents infinite loops, as Link nodes do not follow regular addInto behavior.