Class TokenUtils

java.lang.Object
edu.udel.cis.vsl.abc.token.IF.TokenUtils

public class TokenUtils extends Object
Utility class providing static methods dealing with Token objects.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.antlr.runtime.Token
     
    static final int
    The maximum number of tokens that will be printed when summarizing a range of tokens.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    contentOfRange(CivlcToken first, CivlcToken last, boolean abbreviated)
     
    static String
    getShortFilename(org.antlr.runtime.Token token, boolean abbreviated)
    Computes a short version of the file name from a token's source file.
    static String
    location(org.antlr.runtime.Token token, boolean abbreviated)
    A utility function to extract the filename, line number, and character index of a token of any type, and return a string representation of this in a consistent way.
    static org.antlr.runtime.TokenSource
     
    static String
    quotedText(org.antlr.runtime.Token token)
    A utility function to return the text of a token surrounded by double quotes, with newlines, returns and tabs replaced by escape sequences.
    static String
    summarizeDetailedRange(CivlcToken first, CivlcToken last, boolean abbreviated)
    Return the detailed source location information with highlights.
    static String
    summarizeRange(CivlcToken first, CivlcToken last, boolean abbreviated, boolean isException)
     
    static String
    summarizeRangeLocation(CivlcToken first, CivlcToken last, boolean abbreviated)
    Given a non-empty list of tokens, constructs a string which summarizes the range of text in the original source file(s) from whence those tokens came.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • eofToken

      public static final org.antlr.runtime.Token eofToken
    • summaryBound

      public static final int summaryBound
      The maximum number of tokens that will be printed when summarizing a range of tokens. If the number of tokens exceeds this bound, the ellipsis will be used in the summary.
      See Also:
  • Constructor Details

    • TokenUtils

      public TokenUtils()
  • Method Details

    • location

      public static String location(org.antlr.runtime.Token token, boolean abbreviated)
      A utility function to extract the filename, line number, and character index of a token of any type, and return a string representation of this in a consistent way.
      Parameters:
      token - any instance of Token
      abbreviated - true iff the resulting file name a the shorter one (f1, f2, ...) instead of the original one.
      Returns:
      string explaining where the token came from
    • getShortFilename

      public static String getShortFilename(org.antlr.runtime.Token token, boolean abbreviated)
      Computes a short version of the file name from a token's source file.
      Parameters:
      token - a token
      abbreviated - true iff the result is an abbreviated file name, i.e., shorter file name, which is calculated by the static hash map.
      Returns:
      the short file name
    • summarizeRangeLocation

      public static String summarizeRangeLocation(CivlcToken first, CivlcToken last, boolean abbreviated)
      Given a non-empty list of tokens, constructs a string which summarizes the range of text in the original source file(s) from whence those tokens came. The string may have a form such as "filename:n.a-m.b" where n is the line number of the first token, a is the character index of the first token, m is the line number of the last token, and b is the character index of the last token. Or this form may be abbreviated or modified as necessary.
      Parameters:
      first - first token in linked list
      last - last token in linked list
      abbreviated - should the filename be abbreviated?
      Returns:
      string representation of token range
    • summarizeRange

      public static String summarizeRange(CivlcToken first, CivlcToken last, boolean abbreviated, boolean isException)
    • contentOfRange

      public static String contentOfRange(CivlcToken first, CivlcToken last, boolean abbreviated)
    • quotedText

      public static String quotedText(org.antlr.runtime.Token token)
      A utility function to return the text of a token surrounded by double quotes, with newlines, returns and tabs replaced by escape sequences.
      Parameters:
      token - any instance of Token
      Returns:
      the text of the token, nicely formatted, in quotes
    • makeTokenSourceFromList

      public static org.antlr.runtime.TokenSource makeTokenSourceFromList(CivlcToken first)
    • summarizeDetailedRange

      public static String summarizeDetailedRange(CivlcToken first, CivlcToken last, boolean abbreviated)
      Return the detailed source location information with highlights.
      Parameters:
      first - first token in linked list
      last - last token in linked list
      abbreviated - should the filename be abbreviated?
      Returns:
      string representation of token range