Class LookaheadTokenSourceProxy<D,T,L>

java.lang.Object
eu.bandm.tools.lexic.LookaheadTokenSourceProxy<D,T,L>
Type Parameters:
D - the type of source document identifiers
T - the type of token types
L - the type of lookahead data
All Implemented Interfaces:
LookaheadTokenSource<D,T,L>, Closeable, AutoCloseable, Supplier<Token<D,T>>

public class LookaheadTokenSourceProxy<D,T,L> extends Object implements LookaheadTokenSource<D,T,L>
A dynamic proxy that can be reconfigured which token source to forward at any time.
  • Constructor Details

    • LookaheadTokenSourceProxy

      public LookaheadTokenSourceProxy()
      Creates a new instance with no source to forward.
    • LookaheadTokenSourceProxy

      public LookaheadTokenSourceProxy(@Opt @Opt LookaheadTokenSource<D,T,L> source)
      Creates a new instance with the given source to forward.
      Parameters:
      source - the source to forward
  • Method Details

    • setSource

      public void setSource(@Opt @Opt LookaheadTokenSource<D,T,L> source)
      Sets the given source to forward.
      Parameters:
      source - the source to forward, or null if there is none
    • get

      public Token<D,T> get()
      Specified by:
      get in interface Supplier<D>
      Throws:
      NullPointerException - is there is currently no source to forward
    • relinquishLookahead

      public L relinquishLookahead()
      Clears the internal lookahead buffer and return its contents.
      Specified by:
      relinquishLookahead in interface LookaheadTokenSource<D,T,L>
      Returns:
      the former contents of the internal lookahead buffer
      Throws:
      NullPointerException - is there is currently no source to forward
    • takeOverLookahead

      public void takeOverLookahead(L lookaheadData)
      Fills the internal lookahead buffer with data.

      The buffer must be empty before this method is invoked. After return, the given data will be consumed from the buffer before the usual input is considered.

      Specified by:
      takeOverLookahead in interface LookaheadTokenSource<D,T,L>
      Parameters:
      lookaheadData - the lookahead data to fill in
      Throws:
      NullPointerException - is there is currently no source to forward
    • close

      public void close()
      Closes this source and releases any resources associated with it.

      The default implementation does nothing.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface LookaheadTokenSource<D,T,L>