Class FsmDescriptor

java.lang.Object
org.apache.drill.exec.compile.FsmDescriptor

public class FsmDescriptor extends Object
Describes a finite state machine in terms of a mapping of tokens to characters, a regular expression describing the valid transitions using the characters, and an end state. Used to validate state transitions. One simple example is the implementation of the Check*VisitorFsm classes used to validate call sequences in ASM visitors (classes like CheckClassAdapter only validate per-call arguments, not the entire sequence of calls, according to http://asm.ow2.org/asm50/javadoc/user/org/objectweb/asm/util/CheckClassAdapter.html

The current implementation is very simple, and requires some user setup. Basically, we use Java's Pattern and Matcher to verify a regular expression on demand. The user must map state transitions' string names onto characters, and specify a regex that describes the state machine. Using this technique, we can only validate when we transition to an end state; we just check to see if accumulated characters comprise an allowed regular expression.

In this simple implementation, the tokens and characters may represent states or transitions, depending on what is most convenient. In either case, we just check that a sequence of them matches the regular expression governing this state machine.

  • Constructor Details

    • FsmDescriptor

      public FsmDescriptor(Map<String,Character> tokenMap, String fsmRegex, String lastTransition)
      Create a finite state machine descriptor. The descriptor is immutable, and may be shared across many cursors that are executing the FSM.
      Parameters:
      tokenMap - mapping of transitions/states to characters
      fsmRegex - the regular expression, defined using the characters from the tokenMap
      lastTransition - the name of the final transition/state
  • Method Details

    • createCursor

      public FsmCursor createCursor()
      Create a cursor for performing and validating transitions according to this state machine.
      Returns:
      the new cursor