int (@NotNull CharSequence buffer, int start) { int[] curOffset = {start}; acceptTree(new RecursiveTreeElementWalkingVisitor() { @Override public void visitLeaf(LeafElement leaf) { matchText(leaf); } private void matchText(TreeElement leaf) { curOffset[0] = leaf.textMatches(buffer, curOffset[0]); if (curOffset[0] < 0) { stopWalking(); } } @Override public void visitComposite(CompositeElement composite) { if (composite instanceof LazyParseableElement && !((LazyParseableElement)composite).isParsed()) { matchText(composite); } else { super.visitComposite(composite); } } }); return curOffset[0]; }