Class ParseRegion

java.lang.Object
org.olap4j.mdx.ParseRegion

public class ParseRegion extends Object
Region of parser source code.

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

SELECT FROM [Sales]
the SELECT token has region [1:1, 1:6].

Regions are immutable.

Author:
jhyde
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Combination of a region within an MDX statement with the source text of the whole MDX statement.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ParseRegion(int line, int column)
    Creates a ParseRegion.
    ParseRegion(int startLine, int startColumn, int endLine, int endColumn)
    Creates a ParseRegion.
  • Method Summary

    Modifier and Type
    Method
    Description
    annotate(String source)
    Generates a string of the source code annotated with caret symbols ("^") at the beginning and end of the region.
    boolean
     
    Looks for one or two carets in an MDX string, and if present, converts them into a parser position.
    int
    Return ending column number (1-based).
    int
    Return ending line number (1-based).
    int
    Return starting column number (1-based).
    int
    Return starting line number (1-based).
    int
     
    boolean
    Returns whether this region has the same start and end point.
    plus(List<? extends ParseTreeNode> nodes)
     
    plus(ParseRegion... regions)
    Combines this region with other regions.
    plus(ParseTreeNode... nodes)
    Combines this region with other 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.
    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.
    Returns a string representation of this ParseRegion.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ParseRegion

      public ParseRegion(int startLine, int startColumn, int endLine, int endColumn)
      Creates a ParseRegion.

      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].

      Parameters:
      startLine - Line of the beginning of the region
      startColumn - Column of the beginning of the region
      endLine - Line of the end of the region
      endColumn - Column of the end of the region
    • ParseRegion

      public ParseRegion(int line, int column)
      Creates a ParseRegion. All lines and columns are 1-based.
      Parameters:
      line - Line of the beginning and end of the region
      column - Column of the beginning and end of the region
  • Method Details

    • getStartLine

      public int getStartLine()
      Return starting line number (1-based).
      Returns:
      1-based starting line number
    • getStartColumn

      public int getStartColumn()
      Return starting column number (1-based).
      Returns:
      1-based starting column number
    • getEndLine

      public int getEndLine()
      Return ending line number (1-based).
      Returns:
      1-based ending line number
    • getEndColumn

      public int getEndColumn()
      Return ending column number (1-based).
      Returns:
      1-based starting endings column number
    • toString

      public String toString()
      Returns a string representation of this ParseRegion.

      Regions are of the form [startLine:startColumn, endLine:endColumn], or [startLine:startColumn] for point regions.

      Overrides:
      toString in class Object
      Returns:
      string representation of this ParseRegion
    • isPoint

      public boolean isPoint()
      Returns whether this region has the same start and end point.
      Returns:
      whether this region has the same start and end point
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • plus

      public ParseRegion plus(ParseTreeNode... nodes)
      Combines this region with other regions.
      Parameters:
      nodes - Source code regions
      Returns:
      region which represents the span of the given regions
    • plus

      public ParseRegion plus(List<? extends ParseTreeNode> nodes)
    • plus

      public ParseRegion plus(ParseRegion... regions)
      Combines this region with other regions.
      Parameters:
      regions - Source code regions
      Returns:
      region which represents the span of the given regions
    • plusAll

      public 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.
      Parameters:
      regions - Collection of source code regions
      Returns:
      region which represents the span of the given regions
    • sum

      public 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.
      Parameters:
      nodes - Collection of parse tree nodes
      Returns:
      region which represents the span of the given nodes
    • findPos

      public 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.

      Examples:

      • findPos("xxx^yyy") yields {"xxxyyy", position 3, line 1 column 4}
      • findPos("xxxyyy") yields {"xxxyyy", null}
      • findPos("xxx^yy^y") yields {"xxxyyy", position 3, line 4 column 4 through line 1 column 6}
      Parameters:
      code - Source code
      Returns:
      object containing source code annotated with region
    • annotate

      public String annotate(String source)
      Generates a string of the source code annotated with caret symbols ("^") at the beginning and end of the region.

      For example, for the region (1, 9, 1, 12) and source "values (foo)", yields the string "values (^foo^)".

      Parameters:
      source - Source code
      Returns:
      Source code annotated with position