Class Span


  • public final class Span
    extends java.lang.Object
    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 production
    • s = span(); initializes s to a Span that includes the token we just saw; very often occurs immediately after the first token in the production
    • s.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 function
    • s.pos() returns a position spanning all tokens in the list
    • s.add(node); adds a SqlNode's parser position to a span
    • s.addAll(nodeList); adds several SqlNodes' parser positions to a span
    • s = Span.of(); initializes s to an empty Span, not even including the most recent token; rarely used
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<SqlParserPos> posList  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Span()
      Use one of the of() methods.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Span add​(SqlAbstractParserImpl parser)
      Adds the position of the last token emitted by a parser to the list, and returns this Span.
      Span add​(SqlParserPos pos)
      Adds a position to the list, and returns this Span.
      Span add​(SqlNode n)
      Adds a node's position to the list, and returns this Span.
      Span addAll​(java.lang.Iterable<? extends SqlNode> nodes)
      Adds the positions of a collection of nodes to the list, and returns this Span.
      Span addIf​(SqlNode n)
      Adds a node's position to the list if the node is not null, and returns this Span.
      Span clear()
      Clears the contents of this Span, and returns this Span.
      SqlParserPos end​(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.
      SqlParserPos end​(SqlNode n)
      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​(java.util.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 of​(SqlNode n)
      Creates a Span of one node.
      static Span of​(SqlNode n0, SqlNode n1)
      Creates a Span between two nodes.
      SqlParserPos pos()
      Returns a position spanning the earliest position to the latest.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • posList

        private final java.util.List<SqlParserPos> posList
    • Constructor Detail

      • Span

        private Span()
        Use one of the of() methods.
    • Method Detail

      • of

        public static Span of()
        Creates an empty Span.
      • of

        public static Span of​(SqlParserPos p)
        Creates a Span with one position.
      • of

        public static Span of​(SqlNode n)
        Creates a Span of one node.
      • of

        public static Span of​(SqlNode n0,
                              SqlNode n1)
        Creates a Span between two nodes.
      • of

        public static Span of​(java.util.Collection<? extends SqlNode> nodes)
        Creates a Span of a list of nodes.
      • add

        public Span add​(SqlNode n)
        Adds a node's position to the list, and returns this Span.
      • addIf

        public Span addIf​(SqlNode n)
        Adds a node's position to the list if the node is not null, and returns this Span.
      • add

        public Span add​(SqlParserPos pos)
        Adds a position to the list, and returns this Span.
      • addAll

        public Span addAll​(java.lang.Iterable<? extends SqlNode> nodes)
        Adds the positions of a collection of nodes to the list, and returns this Span.
      • add

        public Span add​(SqlAbstractParserImpl parser)
        Adds the position of the last token emitted by a parser to the list, and returns this Span.
      • pos

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

        public SqlParserPos end​(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.
      • end

        public SqlParserPos end​(SqlNode n)
        Adds a node's position to the list, and returns a position that covers the whole range.
      • clear

        public Span clear()
        Clears the contents of this Span, and returns this Span.