mirror of
https://github.com/DanilaFe/abacus
synced 2026-01-28 01:25:19 +00:00
Add a lot of comments. More to come.
This commit is contained in:
@@ -1,23 +1,52 @@
|
||||
package org.nwapw.abacus.lexing.pattern;
|
||||
|
||||
/**
|
||||
* A chain of nodes that can be treated as a single unit.
|
||||
* Used during pattern compilation.
|
||||
* @param <T> the type used to identify which pattern has been matched.
|
||||
*/
|
||||
public class PatternChain<T> {
|
||||
|
||||
/**
|
||||
* The head node of the chain.
|
||||
*/
|
||||
public PatternNode<T> head;
|
||||
/**
|
||||
* The tail node of the chain.
|
||||
*/
|
||||
public PatternNode<T> tail;
|
||||
|
||||
/**
|
||||
* Creates a new chain with the given start and end.
|
||||
* @param head the start of the chain.
|
||||
* @param tail the end of the chain.
|
||||
*/
|
||||
public PatternChain(PatternNode<T> head, PatternNode<T> tail){
|
||||
this.head = head;
|
||||
this.tail = tail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a chain that starts and ends with the same node.
|
||||
* @param node the node to use.
|
||||
*/
|
||||
public PatternChain(PatternNode<T> node){
|
||||
this(node, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty chain.
|
||||
*/
|
||||
public PatternChain(){
|
||||
this(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the other chain to this one. This modifies
|
||||
* the nodes, as well.
|
||||
* If this chain is empty, it is set to the other.
|
||||
* @param other the other chain to append.
|
||||
*/
|
||||
public void append(PatternChain<T> other){
|
||||
if(other.head == null || tail == null) {
|
||||
this.head = other.head;
|
||||
@@ -28,6 +57,12 @@ public class PatternChain<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a single node to this chain. This modifies
|
||||
* the nodes, as well.
|
||||
* If this chain is empty, it is set to the node.
|
||||
* @param node the node to append to this chain.
|
||||
*/
|
||||
public void append(PatternNode<T> node){
|
||||
if(tail == null){
|
||||
head = tail = node;
|
||||
|
||||
Reference in New Issue
Block a user