TextMateWeigh (@NotNull TextMateScope scope) { for (Node exclusion : exclusions) { if (exclusion.weigh(scope).weigh > 0) { return TextMateWeigh.ZERO; } } if (scope.getLevel() > 100) { return TextMateWeigh.ZERO; } Deque<Node> highlightingSelectors = new LinkedList<>(); for (Node child : children) { highlightingSelectors.push(child); } if (highlightingSelectors.isEmpty()) { highlightingSelectors.push(new Selector("")); } TextMateScope currentTargetSelector = scope; Node currentHighlightingSelector = highlightingSelectors.peek(); int nestingWeigh = NESTING_WEIGH_INITIAL; int result = 0; while (!highlightingSelectors.isEmpty() && currentTargetSelector != null) { TextMateWeigh weigh = currentHighlightingSelector instanceof Selector ? currentHighlightingSelector.weigh(currentTargetSelector) : currentHighlightingSelector.weigh(scope); if (weigh.weigh > 0) { result += weigh.weigh * nestingWeigh; highlightingSelectors.pop(); if (!highlightingSelectors.isEmpty()) { currentHighlightingSelector = highlightingSelectors.peek(); } } nestingWeigh--; currentTargetSelector = currentTargetSelector.getParent(); } if (!highlightingSelectors.isEmpty()) { return TextMateWeigh.ZERO; } return new TextMateWeigh(!startMatch || currentTargetSelector == null || currentTargetSelector.isEmpty() ? result : 0, priority); }