1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-21 23:10:09 -08:00

Remove the Pattern's dependency on java.util.function

This commit is contained in:
Danila Fedorin 2017-09-24 00:12:25 -07:00
parent e82a13cde5
commit 0511c58b13
2 changed files with 19 additions and 4 deletions

View File

@ -6,7 +6,6 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import java.util.function.Function;
/**
* A pattern that can be compiled from a string and used in lexing.
@ -36,8 +35,8 @@ public class Pattern<T> {
* A map of regex operator to functions that modify a PatternChain
* with the appropriate operation.
*/
private Map<Character, Function<PatternChain<T>, PatternChain<T>>> operations =
new HashMap<Character, Function<PatternChain<T>, PatternChain<T>>>() {{
private Map<Character, Transformation<T>> operations =
new HashMap<Character, Transformation<T>>() {{
put('+', Pattern.this::transformPlus);
put('*', Pattern.this::transformStar);
put('?', Pattern.this::transformQuestion);
@ -207,7 +206,7 @@ public class Pattern<T> {
if (operations.containsKey(currentChar)) {
if (currentChain == null) return null;
currentChain = operations.get(currentChar).apply(currentChain);
currentChain = operations.get(currentChar).transform(currentChain);
fullChain.append(currentChain);
currentChain = null;
index++;

View File

@ -0,0 +1,16 @@
package org.nwapw.abacus.lexing.pattern;
/**
* An interface that transforms a pattern chain into a different pattern chain.
* @param <T> the type used to identify the nodes in the pattern chain.
*/
public interface Transformation<T> {
/**
* Performs the actual transformation.
* @param from the original chain.
* @return the resulting chain.
*/
PatternChain<T> transform(PatternChain<T> from);
}