void (@Nullable String region, boolean preprocess, @NotNull SnippetVisitor visitor) { Stack<String> regions = new Stack<>(); Map<String, List<LocationMarkupNode>> active = new LinkedHashMap<>(); int commonIndent = preprocess ? getCommonIndent(region) : 0; for (MarkupNode node : myNodes) { if (node instanceof StartRegion start) { regions.push(start.region()); } else if (node instanceof EndRegion end) { if (end.region() == null) { if (!regions.isEmpty()) { active.remove(regions.pop()); } } else { regions.remove(end.region()); active.remove(end.region()); } } else if (node instanceof LocationMarkupNode loc) { String regionName = loc.region(); if (regionName != null) { regions.push(regionName); } active.computeIfAbsent(regionName, k -> new ArrayList<>()).add(loc); } else if (node instanceof PlainText plainText) { if (region == null || regions.contains(region)) { plainText = stripIndent(plainText, commonIndent); List<LocationMarkupNode> flatActive = StreamEx.ofValues(active).toFlatList(Function.identity()); if (preprocess) { processReplacements(visitor, plainText, flatActive); } else { visitor.visitPlainText(plainText, flatActive); } } active.values().forEach( list -> list.replaceAll( n -> n instanceof Replace repl && repl.selector() instanceof WholeLine ? repl.withReplacement("") : n)); active.remove(null); } else if (node instanceof ErrorMarkup errorMarkup) { if (region == null || regions.contains(region)) { visitor.visitError(errorMarkup); } } } }