mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 07:20:09 -08:00
Remove the Pattern's dependency on java.util.function
This commit is contained in:
parent
e82a13cde5
commit
0511c58b13
|
@ -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++;
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user