Interface TokenRenderer

  • All Known Implementing Classes:
    HTMLTokenRenderer, PlainTokenRenderer

    public interface TokenRenderer
    Renders a runtime ANTLR token. ParseTokenListener controls a renderer and streams the rendered Strings to appropriate output.
    A renderer can define additional bean-style setter methods. They will be set before renderer is used.
    A concrete renderer should have a no argument constructor.
    ParseTokenListener or the framework calls a renderer in following sequence:
        bean-style setter methods as per the user configured
        getPrologue()
        for each token {
           if (line is changing) {
              endLine()
              newLine()
           }
           render()
        }
        getEpilogue();
     
    Author:
    Pinaki Poddar
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.lang.String endLine​(int line)
      Produce a string to signal end of a line.
      java.lang.String getEpilogue()
      Gets a string to be added after token processing ends.
      java.lang.String getPrologue()
      Gets a string to be added before token processing begins.
      java.lang.String newLine​(int line)
      Produce a string to signal beginning of a line.
      java.lang.String render​(int decision, org.antlr.runtime.Token token)
      Produce a string representation of the given token.
    • Method Detail

      • getPrologue

        java.lang.String getPrologue()
        Gets a string to be added before token processing begins.
        For example, a HTML renderer may return the opening HTML and BODY tags. A HTML render using a Cascaded Style Sheet may additionally specify the tag to include the style sheet.
      • getEpilogue

        java.lang.String getEpilogue()
        Gets a string to be added after token processing ends. For example, a HTML renderer may return the closing HTML and BODY tags.
      • render

        java.lang.String render​(int decision,
                                org.antlr.runtime.Token token)
        Produce a string representation of the given token.
        Parameters:
        decision - the index of the decision (or the context) in which the current token is being processed. The index refers to ANTLR DebugEventListener.enterDecision(int).
        token - the token to be rendered. Can be a hidden token as well.
        Returns:
        a string representation of the given token.
      • newLine

        java.lang.String newLine​(int line)
        Produce a string to signal beginning of a line.
        For example, a renderer printing line numbers can produce a String with the given line number.
        Parameters:
        line - the current line number
        Returns:
        a String can be a blank
      • endLine

        java.lang.String endLine​(int line)
        Produce a string to signal end of a line.
        For example, a renderer can produce a newline.
        Parameters:
        line - the line being ended
        Returns:
        a String can be a blank