system/src/sc/parser/ParseUtil.java
public static IParseNode findClosestParseNode(IParseNode parent, int offset) {
      if (parent.getStartIndex() > offset)
         return null; // We start after the requested offset so just return null.

      // We're the leaf node and we started just before the requested offset so return this node.
      if (!(parent instanceof ParentParseNode)) {

         if (parent instanceof ParseNode) {
            ParseNode parentParseNode = (ParseNode) parent;
            Object child = parentParseNode.value;
            if (!(child instanceof IParseNode))
               return parent;
            IParseNode childNode = (IParseNode) child;
            if (childNode.getStartIndex() > offset)
               return parent;
            return findClosestParseNodeOnChild(parentParseNode, childNode, offset);
         }
         return parent;
      }

      ParentParseNode parentNode = (ParentParseNode) parent;

      if (parentNode.children == null)
         return parentNode;

      IParseNode lastChild = null;
      for (Object child:parentNode.children) {
         if (child instanceof IParseNode) {
            if (child instanceof ErrorParseNode)
               continue;

            IParseNode childNode = (IParseNode) child;
            // This child starts after the requested offset
            if (childNode.getStartIndex() >= offset) {
               if (lastChild != null)
                  break;
               else
                  return parentNode;
            }
            // This child still starts before the requested offset
            lastChild = childNode;
         }
      }
      Object semValue;
      return findClosestParseNodeOnChild(parentNode, lastChild, offset);
   }
/** Given a parse node, returns either that parse node or a child of that parse node. */
Given a parse node, returns either that parse node or a child of that parse node.
Given a parse node returns either that parse node or a child of that parse node .
public static IParseNode findClosestParseNode(IParseNode parent, int offset) {
      if (parent.getStartIndex() > offset)
         return null; 
      if (!(parent instanceof ParentParseNode)) {
         if (parent instanceof ParseNode) {
            ParseNode parentParseNode = (ParseNode) parent;
            Object child = parentParseNode.value;
            if (!(child instanceof IParseNode))
               return parent;
            IParseNode childNode = (IParseNode) child;
            if (childNode.getStartIndex() > offset)
               return parent;
            return findClosestParseNodeOnChild(parentParseNode, childNode, offset);
         }
         return parent;
      }
      ParentParseNode parentNode = (ParentParseNode) parent;
      if (parentNode.children == null)
         return parentNode;
      IParseNode lastChild = null;
      for (Object child:parentNode.children) {
         if (child instanceof IParseNode) {
            if (child instanceof ErrorParseNode)
               continue;
            IParseNode childNode = (IParseNode) child;
            if (childNode.getStartIndex() >= offset) {
               if (lastChild != null)
                  break;
               else
                  return parentNode;
            }
            lastChild = childNode;
         }
      }
      Object semValue;
      return findClosestParseNodeOnChild(parentNode, lastChild, offset);
   }
public static IParseNode findClosestParseNode ( IParseNode parent , int offset ) { if ( parent . getStartIndex ( ) > offset ) return null ; if ( ! ( parent instanceof ParentParseNode ) ) { if ( parent instanceof ParseNode ) { ParseNode parentParseNode = ( ParseNode ) parent ; Object child = parentParseNode . value ; if ( ! ( child instanceof IParseNode ) ) return parent ; IParseNode childNode = ( IParseNode ) child ; if ( childNode . getStartIndex ( ) > offset ) return parent ; return findClosestParseNodeOnChild ( parentParseNode , childNode , offset ) ; } return parent ; } ParentParseNode parentNode = ( ParentParseNode ) parent ; if ( parentNode . children == null ) return parentNode ; IParseNode lastChild = null ; for ( Object child : parentNode . children ) { if ( child instanceof IParseNode ) { if ( child instanceof ErrorParseNode ) continue ; IParseNode childNode = ( IParseNode ) child ; if ( childNode . getStartIndex ( ) >= offset ) { if ( lastChild != null ) break ; else return parentNode ; } lastChild = childNode ; } } Object semValue ; return findClosestParseNodeOnChild ( parentNode , lastChild , offset ) ; }
Given a parse node, returns either that parse node or a child of that parse node.
Given a parse node returns either that parse node or a child of that parse node .
// We start after the requested offset so just return null. // We're the leaf node and we started just before the requested offset so return this node. // This child starts after the requested offset // This child still starts before the requested offset