Package org.jline.builtins
Class NfaMatcher<T>
java.lang.Object
org.jline.builtins.NfaMatcher<T>
- Type Parameters:
T
- the type of objects to match against the pattern
Non-deterministic Finite Automaton (NFA) implementation for pattern matching.
This class implements a Thompson NFA for regular expression matching. It converts a regular expression to postfix notation, builds an NFA, and uses it to match sequences of objects against the pattern.
The implementation is based on the algorithm described in Russ Cox's article: https://swtch.com/~rsc/regexp/regexp1.html
-
Constructor Summary
ConstructorsConstructorDescriptionNfaMatcher
(String regexp, BiFunction<T, String, Boolean> matcher) Creates a new NfaMatcher with the specified regular expression and matcher function. -
Method Summary
-
Constructor Details
-
NfaMatcher
Creates a new NfaMatcher with the specified regular expression and matcher function.- Parameters:
regexp
- the regular expression patternmatcher
- the function to match an input against a pattern
-
-
Method Details
-
compile
public void compile()Compiles the regular expression into an NFA.This method is called automatically when needed, but can be called explicitly to precompile the pattern.
-
match
Matches a list of arguments against the pattern.This method uses the NFA to determine if the sequence of arguments matches the regular expression pattern.
- Parameters:
args
- the list of arguments to match- Returns:
- true if the arguments match the pattern, false otherwise
-
matchPartial
Returns the list of possible matcher names for the next object- Parameters:
args
- input list- Returns:
- the list of possible matcher names for the next object
-