Class CommonTokenFactory

java.lang.Object
org.antlr.v4.runtime.CommonTokenFactory
All Implemented Interfaces:
TokenFactory<CommonToken>

public class CommonTokenFactory extends Object implements TokenFactory<CommonToken>
This default implementation of TokenFactory creates CommonToken objects.
  • Field Details

    • DEFAULT

      public static final TokenFactory<CommonToken> DEFAULT
      The default CommonTokenFactory instance.

      This token factory does not explicitly copy token text when constructing tokens.

    • copyText

      protected final boolean copyText
      Indicates whether CommonToken.setText(String) should be called after constructing tokens to explicitly set the text. This is useful for cases where the input stream might not be able to provide arbitrary substrings of text from the input after the lexer creates a token (e.g. the implementation of CharStream.getText(Interval) in UnbufferedCharStream throws an UnsupportedOperationException). Explicitly setting the token text allows Token.getText() to be called at any time regardless of the input stream implementation.

      The default value is false to avoid the performance and memory overhead of copying text for every token unless explicitly requested.

  • Constructor Details

    • CommonTokenFactory

      public CommonTokenFactory(boolean copyText)
      Constructs a CommonTokenFactory with the specified value for copyText.

      When copyText is false, the DEFAULT instance should be used instead of constructing a new instance.

      Parameters:
      copyText - The value for copyText.
    • CommonTokenFactory

      public CommonTokenFactory()
      Constructs a CommonTokenFactory with copyText set to false.

      The DEFAULT instance should be used instead of calling this directly.

  • Method Details