Class Range.Position

  • Enclosing class:
    Range

    public static class Range.Position
    extends java.lang.Object
    A Position object tracks the character position in the original input source where a Node starts or ends. If you want to track these positions, tracking must be enabled in the Parser with Parser.setTrackPosition(boolean).
    See Also:
    Node.sourceRange()
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int columnNumber  
      private int lineNumber  
      private int pos  
    • Constructor Summary

      Constructors 
      Constructor Description
      Position​(int pos, int lineNumber, int columnNumber)
      Create a new Position object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int columnNumber()
      Gets the cursor number (1-based) of the original input source that this Position was read at.
      boolean equals​(java.lang.Object o)  
      int hashCode()  
      boolean isTracked()
      Test if this position was tracked during parsing.
      int lineNumber()
      Gets the line number (1-based) of the original input source that this Position was read at.
      int pos()
      Gets the position index (0-based) of the original input source that this Position was read at.
      java.lang.String toString()
      Gets a String presentation of this Position, in the format line,column:pos.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • pos

        private final int pos
      • lineNumber

        private final int lineNumber
      • columnNumber

        private final int columnNumber
    • Constructor Detail

      • Position

        public Position​(int pos,
                        int lineNumber,
                        int columnNumber)
        Create a new Position object. Called by the TreeBuilder if source position tracking is on.
        Parameters:
        pos - position index
        lineNumber - line number
        columnNumber - column number
    • Method Detail

      • pos

        public int pos()
        Gets the position index (0-based) of the original input source that this Position was read at. This tracks the total number of characters read into the source at this position, regardless of the number of preceding lines.
        Returns:
        the position, or -1 if untracked.
      • lineNumber

        public int lineNumber()
        Gets the line number (1-based) of the original input source that this Position was read at.
        Returns:
        the line number, or -1 if untracked.
      • columnNumber

        public int columnNumber()
        Gets the cursor number (1-based) of the original input source that this Position was read at. The cursor number resets to 1 on every new line.
        Returns:
        the cursor number, or -1 if untracked.
      • isTracked

        public boolean isTracked()
        Test if this position was tracked during parsing.
        Returns:
        true if this was tracked during parsing, false otherwise (and all fields will be -1).
      • toString

        public java.lang.String toString()
        Gets a String presentation of this Position, in the format line,column:pos.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object