Package eu.bandm.tools.lexic
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
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
IllegalArgumentException
is thrown.- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The default width of tab stops. -
Constructor Summary
ConstructorDescriptionLocationCodePointSource
(CodePointSource input, D documentId, int firstLine, int firstColumn) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Erases the recorded interval begin point.int
getAsInt()
Returns the next code point if available.getPoint()
Returns a location that points to the current input position.Returns a location that spans the interval from the previously recorded begin point to the current position.void
Records the current input position as the beginning of an interval.void
setTabWidth
(int tabWidth) Sets the width of tab stops.
-
Field Details
-
DEFAULT_TAB_WIDTH
public static final int DEFAULT_TAB_WIDTHThe default width of tab stops. The value is1
, 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 sourcedocumentId
- the identifier of the underlying document, ornull
if not availablefirstLine
- the non-negative first line number of the underlying document, or one of the special valuesLocation.UNKNOWN
orLocation.NOT_APPLICABLE
firstColumn
- the non-negative first column number of each line of the underlying document, or one of the special valuesLocation.UNKNOWN
orLocation.NOT_APPLICABLE
- See Also:
-
-
Method Details
-
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
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 interfaceCodePointSource
- Specified by:
getAsInt
in interfaceIntSupplier
- 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
-