Class VtParser

java.lang.Object
org.aesh.terminal.parser.VtParser

public final class VtParser extends Object
Table-driven ANSI/VT escape sequence parser based on Paul Flo Williams' DEC-compatible parser.

The parser uses a pre-computed short[14][256] transition table where each entry encodes (action << 4) | nextState. This guarantees completeness (every byte in every state has a defined transition) and correctness (matches DEC VT220-VT525 observable behavior).

Deviations from Williams:

  • Colon (0x3A) is treated as a subparameter separator in CSI/DCS sequences, not as an error. This is required for SGR extended color sequences (38:2:R:G:B).
  • BEL (0x07) terminates OSC strings (xterm convention).

Usage:

VtParser parser = new VtParser(new VtHandler() {
    public void csiDispatch(int finalChar, int[] params, int paramCount,
            int[] intermediates, int intermediateCount,
            boolean hasSubParams) {
        // handle CSI sequence
    }
    // ... other callbacks
});
parser.advance(bytes, 0, length);
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new parser with the given handler.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    advance(byte[] data, int offset, int length)
    Advances the parser with a block of input bytes.
    void
    advance(int b)
    Advances the parser with a single byte or code point.
    void
    advance(int[] codePoints, int offset, int length)
    Advances the parser with a block of code points.
    boolean
    Returns true if the parser is in the GROUND state (no partial sequence is being accumulated).
    void
    Resets the parser to ground state.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • VtParser

      public VtParser(VtHandler handler)
      Creates a new parser with the given handler.
      Parameters:
      handler - the callback handler for parsed sequences
  • Method Details

    • isGroundState

      public boolean isGroundState()
      Returns true if the parser is in the GROUND state (no partial sequence is being accumulated). Used by callers to implement fast-path skipping when no escape sequences are in progress.
      Returns:
      true if in GROUND state
    • advance

      public void advance(byte[] data, int offset, int length)
      Advances the parser with a block of input bytes.
      Parameters:
      data - the input bytes
      offset - the start offset
      length - the number of bytes to process
    • advance

      public void advance(int[] codePoints, int offset, int length)
      Advances the parser with a block of code points. Code points > 255 are treated as printable characters in the ground state and as ignored characters in other states.
      Parameters:
      codePoints - the input code points
      offset - the start offset
      length - the number of code points to process
    • advance

      public void advance(int b)
      Advances the parser with a single byte or code point. Values 0-255 use the transition table directly. Values > 255 are treated as printable in ground state, ignored otherwise.
      Parameters:
      b - the byte (0-255) or code point (> 255)
    • reset

      public void reset()
      Resets the parser to ground state.