Propagation + static method in Visitor for TokenVisitor
This commit is contained in:
parent
b635c13d57
commit
e04b0f0262
2 changed files with 17 additions and 1 deletions
|
@ -11,6 +11,12 @@ public class TokenVisitor extends Visitor<Token>{
|
|||
private Predicate<TokenType> type;
|
||||
private Predicate<Integer> line;
|
||||
private Predicate<Integer> character;
|
||||
|
||||
private boolean propagate;
|
||||
|
||||
public TokenVisitor(boolean propagate){
|
||||
this.propagate = propagate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canVisit(Class<?> type){
|
||||
|
@ -19,7 +25,7 @@ public class TokenVisitor extends Visitor<Token>{
|
|||
|
||||
@Override
|
||||
public boolean canPropagate(){
|
||||
return false;
|
||||
return this.propagate;
|
||||
}
|
||||
|
||||
public TokenVisitor named(Predicate<String> predicate){
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
package dev.peerat.parser.visitor;
|
||||
|
||||
import dev.peerat.parser.Token;
|
||||
|
||||
public abstract class Visitor<T>{
|
||||
|
||||
public static Visitor<Token> allToken(){
|
||||
return new TokenVisitor(true);
|
||||
}
|
||||
|
||||
public static Visitor<Token> token(){
|
||||
return new TokenVisitor(false);
|
||||
}
|
||||
|
||||
public abstract boolean canVisit(Class<?> type); //TODO change "Class<?> type" into "Object element" ?
|
||||
|
||||
public abstract boolean canPropagate();
|
||||
|
|
Loading…
Add table
Reference in a new issue