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 the 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'
advances the line number and resets the column number
'\r'
both alone and followed by '\n' is normalized to '\n'
'\f'
no effect
'\t'
advances the column number to the next tab stop
Other ISO control characters must not occur among the input code points, or a IllegalArgumentException is thrown.
See Also:
  • 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:
    • clearBeginPoint

      public void clearBeginPoint()
      Erases the recorded interval begin point.
      See Also:
    • getRegion

      public Location<D> getRegion()
      Returns a location that spans the interval from the previously recorded begin point to the current position.
      Returns:
      a location that spans the interval from the previously recorded begin point to the current position
      Throws:
      IllegalStateException - if the begin point has not been set
      See Also:
    • getAsInt

      public int getAsInt()
      Returns the next code point if available.
      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