Class NfaMatcher<T>

java.lang.Object
org.jline.builtins.NfaMatcher<T>
Type Parameters:
T - the type of objects to match against the pattern

public class NfaMatcher<T> extends Object
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 Details

    • NfaMatcher

      public NfaMatcher(String regexp, BiFunction<T,String,Boolean> matcher)
      Creates a new NfaMatcher with the specified regular expression and matcher function.
      Parameters:
      regexp - the regular expression pattern
      matcher - 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

      public boolean match(List<T> args)
      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

      public Set<String> matchPartial(List<T> args)
      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