Class LocationCodePointSource<D>

java.lang.Object
eu.bandm.tools.lexic.LocationCodePointSource<D>
Type Parameters:
D - the type of document identifiers
All Implemented Interfaces:
CodePointSource, IntSupplier

public class LocationCodePointSource<D> extends Object implements CodePointSource
A secondary code point source that tracks location information.

Code points are obtained from another code point source. For the consistency of the computed location information, it is required that there are no other, concurrent consumers of code points from that source.

For tracking line and column number information, the following ISO control characters are recognized:
'\n' not preceded by a '\r' advances the line number and resets the column number.
'\r' and the sequence "\r\n" are normalized to '\n' and do the same.
This corresponds to the behaviour of LineNumberReader.

'\f' is delivered as a normal character. This is required for processing Java source texts, see language specification.

'\t' advances the column number to the next tab stop. Tab stops are set at multiples of the given tabWidth.

Other ISO "group zero" control characters must not occur among the input code points, or a IllegalArgumentException is thrown.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The default width of tab stops.
  • Constructor Summary

    Constructors
    Constructor
    Description
    LocationCodePointSource(CodePointSource input, D documentId, int firstLine, int firstColumn)
    Creates a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Records the end of the current interval as the beginning of the next.
    int
    Returns the next code point if available.
    Returns a location corresponding to the beginning of the current interval.
    Returns a location that spans the interval between the previously recorded begining and end points.
    Returns a location corresponding to the end of the current interval.
    Returns a location that spans the interval between the previously recorded begin point and the current position.
    Returns a location that points to the current input position.
    void
    Records the current input position as the beginning of an interval.
    void
    Records the current input position as the end of an interval.
    void
    setTabWidth(int tabWidth)
    Sets the width of tab stops.

    Methods inherited from class java.lang.Object

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

    • DEFAULT_TAB_WIDTH

      public static final int DEFAULT_TAB_WIDTH
      The default width of tab stops. The value is 1, such that tabs count as single spaces.
      See Also:
  • Constructor Details

    • LocationCodePointSource

      public LocationCodePointSource(CodePointSource input, @Opt D documentId, int firstLine, int firstColumn)
      Creates a new instance.
      Parameters:
      input - the input code point source
      documentId - the identifier of the underlying document, or null if not available
      firstLine - the non-negative first line number of the underlying document, or one of the special values Location.UNKNOWN or Location.NOT_APPLICABLE
      firstColumn - the non-negative first column number of each line of the underlying document, or one of the special values Location.UNKNOWN or Location.NOT_APPLICABLE
      See Also:
  • Method Details

    • getPoint

      public Location<D> getPoint()
      Returns a location that points to the current input position.
      Returns:
      a location that points to the current input position
    • setBeginPoint

      public void setBeginPoint()
      Records the current input position as the beginning of an interval.
      See Also:
    • setEndPoint

      public void setEndPoint()
      Records the current input position as the end of an interval.
      See Also:
    • advancePoint

      public void advancePoint()
      Records the end of the current interval as the beginning of the next.
      See Also:
    • getBeginPoint

      public Location<D> getBeginPoint()
      Returns a location corresponding to the beginning of the current interval.

      The result is unspecified if setBeginPoint() has not been called.

      See Also:
    • getEndPoint

      public Location<D> getEndPoint()
      Returns a location corresponding to the end of the current interval.

      The result is unspecified if setEndPoint() has not been called.

      See Also:
    • getClosedRegion

      public Location<D> getClosedRegion()
      Returns a location that spans the interval between the previously recorded begining and end points.
      See Also:
    • getOpenRegion

      public Location<D> getOpenRegion()
      Returns a location that spans the interval between the previously recorded begin point and the current position.
      See Also:
    • getAsInt

      public int getAsInt()
      Returns the next code point if available. Unifies the different CR/LF-strategies: returns "\n" for "\r" and "\r\n".
      Specified by:
      getAsInt in interface CodePointSource
      Specified by:
      getAsInt in interface IntSupplier
      Returns:
      either a valid Unicode code point, or -1 to indicate that the end of the stream has been reached
      Throws:
      IllegalArgumentException - if a code point is encountered that denotes any ISO control character other than the recognized ones
      See Also:
    • setTabWidth

      public void setTabWidth(int tabWidth)
      Sets the width of tab stops.
      Parameters:
      tabWidth - the new width of tab stops
      Throws:
      IllegalArgumentException - if the given width is non-positive