All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.unlaxer.TokenKind Maven / Gradle / Ivy

package org.unlaxer;

import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public enum TokenKind{
	matchOnly,
	consumed,
	;
	public static TokenKind of(boolean doConsume){
		return doConsume ? TokenKind.consumed : matchOnly;
	}
	
	public boolean isConsumed(){
		return this == TokenKind.consumed;
	}
	
	public boolean isMatchOnly(){
		return this == TokenKind.matchOnly;
	}
	
	public Predicate passFilter = token-> token.tokenKind == this;
	public Predicate cutFilter = token-> token.tokenKind != this;
	
	public List pass(List tokens){
		return tokens.stream()
			.filter(passFilter)
			.collect(Collectors.toList());
	}
	
	public List cut(List tokens){
		return tokens.stream()
			.filter(cutFilter)
			.collect(Collectors.toList());
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy