public class ParseRegion extends Object
The main purpose of a ParseRegion is to give detailed locations in error messages and warnings from the parsing and validation process.
A region has a start and end line number and column number. A region is a point if the start and end positions are the same.
The line and column number are one-based, because that is what end-users understand.
A region's end-points are inclusive. For example, in the code
theSELECT FROM [Sales]
SELECT
token has region [1:1, 1:6].
Regions are immutable.
Modifier and Type | Class and Description |
---|---|
static class |
ParseRegion.RegionAndSource
Combination of a region within an MDX statement with the source text
of the whole MDX statement.
|
Constructor and Description |
---|
ParseRegion(int line,
int column)
Creates a ParseRegion.
|
ParseRegion(int startLine,
int startColumn,
int endLine,
int endColumn)
Creates a ParseRegion.
|
Modifier and Type | Method and Description |
---|---|
String |
annotate(String source)
Generates a string of the source code annotated with caret symbols ("^")
at the beginning and end of the region.
|
boolean |
equals(Object obj) |
static ParseRegion.RegionAndSource |
findPos(String code)
Looks for one or two carets in an MDX string, and if present, converts
them into a parser position.
|
int |
getEndColumn()
Return ending column number (1-based).
|
int |
getEndLine()
Return ending line number (1-based).
|
int |
getStartColumn()
Return starting column number (1-based).
|
int |
getStartLine()
Return starting line number (1-based).
|
int |
hashCode() |
boolean |
isPoint()
Returns whether this region has the same start and end point.
|
ParseRegion |
plus(List<? extends ParseTreeNode> nodes) |
ParseRegion |
plus(ParseRegion... regions)
Combines this region with other regions.
|
ParseRegion |
plus(ParseTreeNode... nodes)
Combines this region with other regions.
|
ParseRegion |
plusAll(Iterable<ParseRegion> regions)
Combines this region with a list of parse tree nodes to create a
region which spans from the first point in the first to the last point
in the other.
|
static ParseRegion |
sum(Iterable<ParseRegion> nodes)
Combines the parser positions of a list of nodes to create a position
which spans from the beginning of the first to the end of the last.
|
String |
toString()
Returns a string representation of this ParseRegion.
|
public ParseRegion(int startLine, int startColumn, int endLine, int endColumn)
All lines and columns are 1-based and inclusive. For example, the token "select" in "select from [Sales]" has a region [1:1, 1:6].
startLine
- Line of the beginning of the regionstartColumn
- Column of the beginning of the regionendLine
- Line of the end of the regionendColumn
- Column of the end of the regionpublic ParseRegion(int line, int column)
line
- Line of the beginning and end of the regioncolumn
- Column of the beginning and end of the regionpublic int getStartLine()
public int getStartColumn()
public int getEndLine()
public int getEndColumn()
public String toString()
Regions are of the form
[startLine:startColumn, endLine:endColumn]
, or
[startLine:startColumn]
for point regions.
public boolean isPoint()
public ParseRegion plus(ParseTreeNode... nodes)
nodes
- Source code regionspublic ParseRegion plus(List<? extends ParseTreeNode> nodes)
public ParseRegion plus(ParseRegion... regions)
regions
- Source code regionspublic ParseRegion plusAll(Iterable<ParseRegion> regions)
regions
- Collection of source code regionspublic static ParseRegion sum(Iterable<ParseRegion> nodes)
nodes
- Collection of parse tree nodespublic static ParseRegion.RegionAndSource findPos(String code)
Examples:
code
- Source codepublic String annotate(String source)
For example, for the region (1, 9, 1, 12)
and source
"values (foo)"
,
yields the string "values (^foo^)"
.
source
- Source code