Package org.apache.calcite.sql.parser
Class Span
java.lang.Object
org.apache.calcite.sql.parser.Span
Builder for
SqlParserPos
.
Because it is mutable, it is convenient for keeping track of the positions of the tokens that go into a non-terminal. It can be passed into methods, which can add the positions of tokens consumed to it.
Some patterns:
final Span s;
declaration of a Span at the top of a productions = span();
initializes s to a Span that includes the token we just saw; very often occurs immediately after the first token in the productions.end(this);
adds the most recent token to span s and evaluates to a SqlParserPosition that spans from beginning to end; commonly used when making a call to a functions.pos()
returns a position spanning all tokens in the lists.add(node);
adds a SqlNode's parser position to a spans.addAll(nodeList);
adds several SqlNodes' parser positions to a spans = Span.of();
initializes s to an empty Span, not even including the most recent token; rarely used
-
Method Summary
Modifier and TypeMethodDescriptionadd
(org.apache.calcite.sql.parser.SqlAbstractParserImpl parser) Adds the position of the last token emitted by a parser to the list, and returns this Span.add
(SqlParserPos pos) Adds a position to the list, and returns this Span.Adds a node's position to the list, and returns this Span.Adds the positions of a collection of nodes to the list, and returns this Span.Adds a node's position to the list if the node is not null, and returns this Span.clear()
Clears the contents of this Span, and returns this Span.end
(org.apache.calcite.sql.parser.SqlAbstractParserImpl parser) Adds the position of the last token emitted by a parser to the list, and returns a position that covers the whole range.Adds a node's position to the list, and returns a position that covers the whole range.static Span
of()
Creates an empty Span.static Span
of
(Collection<? extends SqlNode> nodes) Creates a Span of a list of nodes.static Span
of
(SqlParserPos p) Creates a Span with one position.static Span
Creates a Span of one node.static Span
of
(SqlNodeList nodeList) Creates a Span of a node list.static Span
Creates a Span between two nodes.pos()
Returns a position spanning the earliest position to the latest.
-
Method Details
-
of
Creates an empty Span. -
of
Creates a Span with one position. -
of
Creates a Span of one node. -
of
Creates a Span between two nodes. -
of
Creates a Span of a list of nodes. -
of
Creates a Span of a node list. -
add
Adds a node's position to the list, and returns this Span. -
addIf
Adds a node's position to the list if the node is not null, and returns this Span. -
add
Adds a position to the list, and returns this Span. -
addAll
Adds the positions of a collection of nodes to the list, and returns this Span. -
add
Adds the position of the last token emitted by a parser to the list, and returns this Span. -
pos
Returns a position spanning the earliest position to the latest. Does not assume that the positions are sorted. Throws if the list is empty. -
end
Adds the position of the last token emitted by a parser to the list, and returns a position that covers the whole range. -
end
Adds a node's position to the list, and returns a position that covers the whole range. -
clear
Clears the contents of this Span, and returns this Span.
-