mirror of
https://github.com/DanilaFe/abacus
synced 2024-11-04 18:08:31 -08:00
Implement a few nodes for the pattern matching.
This commit is contained in:
parent
3b91304175
commit
2374c167a4
10
src/org/nwapw/abacus/lexing/pattern/AnyNode.java
Normal file
10
src/org/nwapw/abacus/lexing/pattern/AnyNode.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
15
src/org/nwapw/abacus/lexing/pattern/EndNode.java
Normal file
15
src/org/nwapw/abacus/lexing/pattern/EndNode.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
src/org/nwapw/abacus/lexing/pattern/LinkNode.java
Normal file
14
src/org/nwapw/abacus/lexing/pattern/LinkNode.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
25
src/org/nwapw/abacus/lexing/pattern/PatternNode.java
Normal file
25
src/org/nwapw/abacus/lexing/pattern/PatternNode.java
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
18
src/org/nwapw/abacus/lexing/pattern/RangeNode.java
Normal file
18
src/org/nwapw/abacus/lexing/pattern/RangeNode.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
src/org/nwapw/abacus/lexing/pattern/ValueNode.java
Normal file
20
src/org/nwapw/abacus/lexing/pattern/ValueNode.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user