1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-22 07:20:09 -08:00

Implement a few nodes for the pattern matching.

This commit is contained in:
Danila Fedorin 2017-07-24 17:42:25 -07:00
parent 3b91304175
commit 2374c167a4
6 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,10 @@
package org.nwapw.abacus.lexing.pattern;
public class AnyNode<T> extends PatternNode<T> {
@Override
public boolean matches(char other) {
return true;
}
}

View File

@ -0,0 +1,15 @@
package org.nwapw.abacus.lexing.pattern;
public class EndNode<T> extends PatternNode<T> {
private T patternId;
public EndNode(T patternId){
this.patternId = patternId;
}
public T getPatternId(){
return patternId;
}
}

View File

@ -0,0 +1,14 @@
package org.nwapw.abacus.lexing.pattern;
import java.util.ArrayList;
public class LinkNode<T> extends PatternNode<T> {
@Override
public void addInto(ArrayList<PatternNode<T>> into) {
for(PatternNode<T> node : outputStates){
node.addInto(into);
}
}
}

View File

@ -0,0 +1,25 @@
package org.nwapw.abacus.lexing.pattern;
import java.util.ArrayList;
public class PatternNode<T> {
protected ArrayList<PatternNode<T>> outputStates;
public PatternNode(){
outputStates = new ArrayList<>();
}
public boolean matches(char other){
return false;
}
public char range(){
return '\0';
}
public void addInto(ArrayList<PatternNode<T>> into){
into.add(this);
}
}

View File

@ -0,0 +1,18 @@
package org.nwapw.abacus.lexing.pattern;
public class RangeNode<T> extends PatternNode<T> {
private char from;
private char to;
public RangeNode(char from, char to){
this.from = from;
this.to = to;
}
@Override
public boolean matches(char other) {
return other >= from && other <= to;
}
}

View File

@ -0,0 +1,20 @@
package org.nwapw.abacus.lexing.pattern;
public class ValueNode<T> extends PatternNode<T> {
private char value;
public ValueNode(char value){
this.value = value;
}
@Override
public boolean matches(char other) {
return other == value;
}
@Override
public char range() {
return value;
}
}