Package nz.org.riskscape.dsl
Class SourceLocation
java.lang.Object
nz.org.riskscape.dsl.SourceLocation
Information about a specific character location within a string of source code
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates that extends/modifies the given URI so that it includes an anchor fragment that points to this source code locationadvance
(int moveByChars) protected boolean
boolean
int
Column number within the current line (1 based)int
getIndex()
Absolute index in to the source string.int
getLine()
Line number (1 based)int
hashCode()
static SourceLocation
index
(int index) boolean
newline()
static Optional<SourceLocation>
parseUriFragment
(String fragment) Attempt to parse the given URI fragment and turn it in to aSourceLocation
, returning empty if it doesn't parse.toString()
Creates a string that can be embedded in a URI as an anchor fragment, seeparseUriFragment(String)
for the inverse method.static SourceLocation
unlined
(int index)
-
Field Details
-
START
Starting position.
-
-
Constructor Details
-
SourceLocation
public SourceLocation(int index, int line, int column)
-
-
Method Details
-
parseUriFragment
Attempt to parse the given URI fragment and turn it in to a
SourceLocation
, returning empty if it doesn't parse. SeetoUriFragment()
for the inverse method.- Parameters:
fragment
- the anchor fragment part of a URI, can be null, seeURI.getFragment()
.
-
unlined
- Returns:
- a location in source that has lost track of line numbers.
-
index
- Returns:
- a single lined location at the given index
-
toString
-
advance
- Returns:
- a new SourceLocation shifted forward by moveByChars.
-
newline
- Returns:
- a new SourceLocation at the same overall index, but at the start of a new line, i.e. index stays the same, line is incremented and column is set to 1.
-
isUnlined
public boolean isUnlined()- Returns:
- true if this source location has lost track of lines
-
toUriFragment
Creates a string that can be embedded in a URI as an anchor fragment, see
parseUriFragment(String)
for the inverse method. -
addToUri
Creates that extends/modifies the given URI so that it includes an anchor fragment that points to this source code location
-
getIndex
public int getIndex()Absolute index in to the source string.
-
getLine
public int getLine()Line number (1 based)
-
getColumn
public int getColumn()Column number within the current line (1 based)
-
equals
-
canEqual
-
hashCode
public int hashCode()
-