1
0
mirror of https://github.com/DanilaFe/abacus synced 2026-01-28 01:25:19 +00:00

Implement a tentative pattern class that can be compiled from a string.

This commit is contained in:
2017-07-24 17:42:52 -07:00
parent 2374c167a4
commit 6200381016
2 changed files with 202 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
package org.nwapw.abacus.lexing.pattern;
public class PatternChain<T> {
public PatternNode<T> head;
public PatternNode<T> tail;
public PatternChain(PatternNode<T> head, PatternNode<T> tail){
this.head = head;
this.tail = tail;
}
public PatternChain(PatternNode<T> node){
this(node, node);
}
public PatternChain(){
this(null);
}
public void append(PatternChain<T> other){
if(other.head == null || tail == null) {
this.head = other.head;
this.tail = other.tail;
} else {
tail.outputStates.add(other.head);
tail = other.tail;
}
}
public void append(PatternNode<T> node){
if(tail == null){
head = tail = node;
} else {
tail.outputStates.add(node);
tail = node;
}
}
}