Search for closing pair of opening tag
@param {Object} open Open tag instance
@param {Object} matcher Matcher instance
358323
function findClosingPair(open, matcher) {
		var stack = [], tag = null;
		var text = matcher.text();
		
		for (var pos = open.range.end, len = text.length; pos < len; pos++) {
			if (matches(text, pos, '<!--')) {
				// skip to end of comment
				for (var j = pos; j < len; j++) {
					if (matches(text, j, '-->')) {
						pos = j + 3;
						break;
					}
				}
			}
			
			if ((tag = matcher.matches(pos))) {
				if (tag.type == 'open' && !tag.selfClose) {
					stack.push(tag.name);
				} else if (tag.type == 'close') {
					if (!stack.length) { // found valid pair?
						return tag.name == open.name ? tag : null;
					}
					
					// check if current closing tag matches previously opened one
					if (stack[stack.length - 1] == tag.name) {
						stack.pop();
					} else {
						var found = false;
						while (stack.length && !found) {
							var last = stack.pop();
							if (last == tag.name) {
								found = true;
							}
						}
						
						if (!stack.length && !found) {
							return tag.name == open.name ? tag : null;
						}
					}
				}

				pos = tag.range.end - 1;
			}
		}
	}
738885
function(match, startNode, visibleOnly) {
			match =
				typeof match === "string"
					? _makeNodeTitleStartMatcher(match)
					: match;
			startNode = startNode || this.getFirstChild();

			var stopNode = null,
				parentChildren = startNode.parent.children,
				matchingNode = null,
				walkVisible = function(parent, idx, fn) {
					var i,
						grandParent,
						parentChildren = parent.children,
						siblingCount = parentChildren.length,
						node = parentChildren[idx];
					// visit node itself
					if (node && fn(node) === false) {
						return false;
					}
					// visit descendants
					if (node && node.children && node.expanded) {
						if (walkVisible(node, 0, fn) === false) {
							return false;
						}
					}
					// visit subsequent siblings
					for (i = idx + 1; i < siblingCount; i++) {
						if (walkVisible(parent, i, fn) === false) {
							return false;
						}
					}
					// visit parent's subsequent siblings
					grandParent = parent.parent;
					if (grandParent) {
						return walkVisible(
							grandParent,
							grandParent.children.indexOf(parent) + 1,
							fn
						);
					} else {
						// wrap-around: restart with first node
						return walkVisible(parent, 0, fn);
					}
				};

			walkVisible(
				startNode.parent,
				parentChildren.indexOf(startNode),
				function(node) {
					// Stop iteration if we see the start node a second time
					if (node === stopNode) {
						return false;
					}
					stopNode = stopNode || node;
					// Ignore nodes hidden by a filter
					if (!$(node.span).is(":visible")) {
						node.debug("quicksearch: skipping hidden node");
						return;
					}
					// Test if we found a match, but search for a second match if this
					// was the currently active node
					if (match(node)) {
						// node.debug("quicksearch match " + node.title, startNode);
						matchingNode = node;
						if (matchingNode !== startNode) {
							return false;
						}
					}
				}
			);
			return matchingNode;
		}
235925
function (listTag) {
                var
                    tag,
                    len = this._openedTags.length;
                while (len) {
                    tag = this._openedTags.pop();
                    --len;
                    this._output("</" + tag + ">");
                    if ("li" === tag) {
                        break;
                    }
                }
                if (len) {
                    tag = this._openedTags[len - 1];
                    if (tag !== listTag) {
                        this._openedTags.pop();
                        this._output("</" + tag + ">");
                    } else {
                        return;
                    }
                }
                this._openTag(listTag);
            }
356865
function (tag) {
                var
                    len = this._openedTags.length;
                if (len && this._openedTags[len - 1] === tag) {
                    this._openedTags.pop();
                    this._output("</" + tag + ">");
                } else {
                    this._openTag(tag);
                }
            }
377183
@Override
  public Description matchMethod(MethodTree tree, VisitorState state) {
    if (!HAS_MUST_BE_CLOSED_ANNOTATION.matches(tree, state)) {
      // Ignore methods and constructors that are not annotated with {@link MustBeClosed}.
      return NO_MATCH;
    }

    boolean isAConstructor = methodIsConstructor().matches(tree, state);
    if (isAConstructor && !AUTO_CLOSEABLE_CONSTRUCTOR_MATCHER.matches(tree, state)) {
      return buildDescription(tree)
          .setMessage("MustBeClosed should only annotate constructors of AutoCloseables.")
          .build();
    }

    if (!isAConstructor && !METHOD_RETURNS_AUTO_CLOSEABLE_MATCHER.matches(tree, state)) {
      return buildDescription(tree)
          .setMessage("MustBeClosed should only annotate methods that return an AutoCloseable.")
          .build();
    }
    return NO_MATCH;
  }
279228
function (tagName, tagAttributes) {
    if (this._done) {
      return;
    }

    this._openElementStack.push(tagName);

    try {
      this._errorIfUnexpectedTag(tagName);

      for (var attributeName in tagAttributes) {
        var attributeValue = tagAttributes[attributeName];

        this._errorIfUnexpectedAttribute(tagName, attributeName);
        this._errorIfUnexpectedAttributeValue(tagName, attributeName, attributeValue);
      }
    } catch (err) {
      this._finish(err);
    }
  }
582419
public static <E> void removeMatcing(Collection<E> collection, Matcher<? super E> matcher) {
		Iterator<E> iter = collection.iterator();
		while (iter.hasNext()) {
			E item = iter.next();
			if (matcher.matches(item)) iter.remove();
		}
	}
338126
function matcher (patternFn, successFn, chain) {
    var matcherObj = new Matcher(patternFn, successFn);
  
    // If a chain was provided, add the new matcher to the end of the chain.
    if (chain) {
      chain.last().next = matcherObj;
    } else {
      chain = matcherObj;
    }
  
    var fn = function () {
      // This seems like an odd optimization, but manually copying the
      // arguments object over to an array instead of calling `slice` can
      // speed up dispatch time 2-3x.
      var args = [], i = 0, len = arguments.length;
      for (; i < len; i++) args[i] = arguments[i];
      return chain.match(args, this);
    };
  
    fn.alt = function () {
      var args = slice.call(arguments);
      args.push(chain);
      return pattern.apply(null, args);
    };
  
    fn.__matchChain = chain;
  
    return fn;
  }
511137
function endTagToTokens(endTag) {
            const tokens = [endTag.tagOpen, endTag.tagClose]

            return tokens
                .filter(t => Boolean(t))
                .sort((a, b) => a.range[0] - b.range[0])
        }
1141678
static Matcher removeMatchAnyFollowedByStart(Matcher matcher) {
    if (matcher instanceof ZeroOrMoreMatcher) {
      ZeroOrMoreMatcher zm = matcher.as();
      if (zm.repeated() instanceof AnyMatcher
          && zm.next() instanceof SeqMatcher
          && zm.next().<SeqMatcher>as().matchers().get(0).isStartAnchored()) {
        return zm.next();
      }
    }
    return matcher;
  }
1339156
function Matcher (patternFn, successFn, next) {
    this.patternFn = patternFn;
    this.successFn = successFn;
    this.next = next;
  }
1293362
public boolean contains(Matcher matcher) {
        return element.matcher == matcher || (parent != null && parent.contains(matcher));
    }
5347
function (source, nextToken) {
      var tm = this,
          tokenizerRe,
          lastIndex,
          matches,
          textType;

      // Initialize for first run
      // if no template passed assume first pass
      // and use the main template.
      if (typeof source === "undefined") {
        source = tm.template;
      }

      // if no token passed, this is an open tag lookup
      if (typeof nextToken === "undefined") {
        tm._tokens = [];
        nextToken = tm.lex.tagOpen;
      }

      while (source) {
        // Use created token.
        tokenizerRe = nextToken.compiledRe;
        matches = tokenizerRe.exec(source);

        lastIndex = tokenizerRe.lastIndex;
        tokenizerRe.lastIndex = 0;

        // This guy matched. So let's push the tokens.
        if (matches) {

          // Flags to see if code or text
          if (nextToken === tm.lex.tagOpen) {
            // if the match was done using the tagOpen, then everything we matched is normal text.
            textType = "text";
          } else {
            // assume the match was a closing tag, so everything we have is code.
            textType = "code";
          }

          // if the token is a tagOpen, or tagClose, we need to push it with the text value matched.
          if (nextToken.hasText) {
            tm._tokens.push({
              type : textType,
              value : matches[1]
            });
          } else {
            // push the token name into the array to mark the open/close/print status on it.
            tm._tokens.push({
              type : nextToken.name
            });
          }

          // A print indicator just shows open prints, so we buffer the open print.
          if (nextToken === tm.lex.printIndicator) {
            tm._openPrints.push(tm._openBrackets);
          }

          // Closing an open print needs to count for open brackets, so we can separate the code blocks.
          if (nextToken === tm.lex.tagClose && tm._openPrints.length > 0) {
            tm._countBrackets(matches[1]);
          }

          // We matched, so let's keep going.
          // from where we left with our new next token.
          source    = source.substr(lastIndex);
          nextToken = tm._nextToken(nextToken);

        //No match:
        } else {
          // We couldn't match anything else. So: Either it's a syntax error,
          // or it's just text. If we were awaiting another token we fail, otherwise
          // assume it's just text.
          if (nextToken == tm.lex.tagOpen) {
            tm._tokens.push({
              type  : "text",
              value : source
            });

            source = "";

          } else {
            // If it wasn't optional. GO!
            if (nextToken.optional) {
              // So continue from where we left with our new next token.
              source    = source.substr(lastIndex);
              nextToken = tm._nextToken(nextToken);

            // so it was not a printing tag, so something went wrong.
            } else {
              throw "Syntax Error: Expecting " + nextToken.name + " ... Nowhere to be found. So I was like, what?";
            }
          }
        }
      }
    }
1219250
function(state, datasetId, items, matchFound, nestingLevel, stopExpandingParents) {
            // initialize whatever wasn't passed to a default value
            datasetId = datasetId || 'default';
            items = items || concealed.items[datasetId];
            matchFound = matchFound || false;
            nestingLevel = nestingLevel || 0;

            for (var i = items.length; --i >= 0;) {
                if (!!items[i].items && !!items[i].items.length) {
                    // matchFound here would mean that a match was found in a descendant
                    matchFound = visible.setActive(state, datasetId, items[i].items, matchFound, nestingLevel + 1, stopExpandingParents);
                    if (matchFound && !stopExpandingParents) {
                        items[i].expanded = true;
                        if (nestingLevel === 0) {
                            stopExpandingParents = true;
                        }
                    }
                } else {
                    if (matchFound) {
                        // matchFound here would mean either a sibling node or some other node was already matched
                        // so we want to skip the comparison to save time
                        items[i].isActive = false;
                    } else {
                        if (!!items[i].stateName && items[i].stateName === state) {
                            // if the item's state is the one being searched for then set the item to active and flip the matched flag
                            items[i].isActive = true;
                            matchFound = true;
                            stopExpandingParents = true;
                        } else {
                            items[i].isActive = false;
                        }
                    }
                }
            }

            return matchFound;
        }
876241
function(text, pos) {
			var matcher = createMatcher(text); 
			var open = null, close = null;
			var j, jl;
			
			for (var i = pos; i >= 0; i--) {
				if ((open = matcher.open(i))) {
					// found opening tag
					if (open.selfClose) {
						if (open.range.cmp(pos, 'lt', 'gt')) {
							// inside self-closing tag, found match
							break;
						}
						
						// outside self-closing tag, continue
						continue;
					}
					
					close = findClosingPair(open, matcher);
					if (close) {
						// found closing tag.
						var r = range.create2(open.range.start, close.range.end);
						if (r.contains(pos)) {
							break;
						}
					} else if (open.range.contains(pos)) {
						// we inside empty HTML tag like <br>
						break;
					}
					
					open = null;
				} else if (matches(text, i, '-->')) {
					// skip back to comment start
					for (j = i - 1; j >= 0; j--) {
						if (matches(text, j, '-->')) {
							// found another comment end, do nothing
							break;
						} else if (matches(text, j, '<!--')) {
							i = j;
							break;
						}
					}
				} else if (matches(text, i, '<!--')) {
					// we're inside comment, match it
					for (j = i + 4, jl = text.length; j < jl; j++) {
						if (matches(text, j, '-->')) {
							j += 3;
							break;
						}
					}
					
					open = comment(i, j);
					break;
				}
			}
			
			matcher.clean();

			if (open) {
				var outerRange = null;
				var innerRange = null;
				
				if (close) {
					outerRange = range.create2(open.range.start, close.range.end);
					innerRange = range.create2(open.range.end, close.range.start);
				} else {
					outerRange = innerRange = range.create2(open.range.start, open.range.end);
				}
				
				if (open.type == 'comment') {
					// adjust positions of inner range for comment
					var _c = outerRange.substring(text);
					innerRange.start += _c.length - _c.replace(/^<\!--\s*/, '').length;
					innerRange.end -= _c.length - _c.replace(/\s*-->$/, '').length;
				}
				
				return {
					open: open,
					close: close,
					type: open.type == 'comment' ? 'comment' : 'tag',
					innerRange: innerRange,
					innerContent: function() {
						return this.innerRange.substring(text);
					},
					outerRange: outerRange,
					outerContent: function() {
						return this.outerRange.substring(text);
					},
					range: !innerRange.length() || !innerRange.cmp(pos, 'lte', 'gte') ? outerRange : innerRange,
					content: function() {
						return this.range.substring(text);
					},
					source: text
				};
			}
		}
848329
function (char) {
                var
                    newState,
                    tagsOpened = 0 < this._openedTags.length;
                if ("#" === char) {
                    this._hLevel = 1;
                    newState = this._parseTitle;
                } else if ("*" === char || "0" <= char && "9" >= char ) {
                    if (char !== "*") {
                        this._numericList = 1;
                    } else {
                        this._numericList = 0;
                    }
                    newState = this._parseList;
                    tagsOpened = false; // Wait for disambiguation
                } else if (" " !== char && "\t" !== char && "\n" !== char) {
                    if (tagsOpened) {
                        this._output(" ");
                        tagsOpened = false; // Avoid closing below
                    } else {
                        this._openTag("p");
                    }
                    newState = this._parseContent(char);
                    if (!newState) {
                        newState = this._parseContent;
                    }
                }
                if (tagsOpened) {
                    this._closeTags();
                }
                return newState;
            }
752214
protected boolean nestedMatch(Matcher<?> matcher, Object item, Description mismatch) {
        return Nested.matches(this, matcher, item, mismatch);
    }