Exemplo n.º 1
0
  /**
   * Gets whether or not {@code tree} is an epsilon non-terminal in the parse tree. An epsilon tree
   * is a node which does not contain any {@link TerminalNode} descendants.
   *
   * @param tree A node in a parse tree.
   * @return {@code true} if {@code tree} is an epsilon node in the parse tree, otherwise {@code
   *     false}.
   */
  public static boolean isEpsilon(@NonNull ParseTree tree) {
    if (tree instanceof TerminalNode) {
      return false;
    }

    Interval sourceInterval = tree.getSourceInterval();
    return sourceInterval.b < sourceInterval.a;
  }
Exemplo n.º 2
0
  /**
   * Gets whether or not {@code a} starts after the start of {@code b}.
   *
   * @param a The first tree.
   * @param b The second tree.
   * @return {@code true} if {@code a} starts after the start of {@code b}, otherwise {@code false}.
   */
  public static boolean startsAfterStartOf(@NonNull ParseTree a, @NonNull ParseTree b) {
    // TerminalNode<? extends Token> startNodeA = getStartNode(a);
    // TerminalNode<? extends Token> startNodeB = getStartNode(b);
    // if (startNodeA == null || startNodeB == null) {
    //    throw new NotImplementedException();
    // }

    Interval sourceIntervalA = a.getSourceInterval();
    Interval sourceIntervalB = b.getSourceInterval();

    // if (sourceIntervalA.a == sourceIntervalB.a) {
    //    if (isAncestorOf(a, b)) {
    //        return true;
    //    }
    //
    //    if (isEpsilon(a) || isEpsilon(b)) {
    //        // b could be a child of a later sibling of some ancestor of a
    //        throw new NotImplementedException();
    //    }
    // }

    return sourceIntervalA.a > sourceIntervalB.a;
  }
Exemplo n.º 3
0
 /**
  * Gets whether or not {@code a} ends before the end of {@code b}.
  *
  * @param a The first tree.
  * @param b The second tree.
  * @return {@code true} if {@code a} ends before the end of {@code b}, otherwise {@code false}.
  */
 public static boolean endsBeforeEndOf(@NonNull ParseTree a, @NonNull ParseTree b) {
   Interval sourceIntervalA = a.getSourceInterval();
   Interval sourceIntervalB = b.getSourceInterval();
   return sourceIntervalA.b < sourceIntervalB.b;
 }
Exemplo n.º 4
0
 /**
  * Gets whether or not {@code a} starts before the start of {@code b}.
  *
  * @param a The first tree.
  * @param b The second tree.
  * @return {@code true} if {@code a} starts before the start of {@code b}, otherwise {@code
  *     false}.
  */
 public static boolean startsBeforeStartOf(@NonNull ParseTree a, @NonNull ParseTree b) {
   Interval sourceIntervalA = a.getSourceInterval();
   Interval sourceIntervalB = b.getSourceInterval();
   return sourceIntervalA.a < sourceIntervalB.a;
 }