protected function buildLocator()
    {
        $this
            ->resetLocatorBuffer()
            ->getReferenceBuffer()
            ->reset();
        $state = self::STATE_POINTER_PART;
        while (true) {
            switch ($state) {
                case self::STATE_POINTER_PART:
                    // Expecting part of a pointer or end of text.
                    $state = $this->processPointerPartState();
                    break;

                case self::STATE_REFERENCE_PART:
                    // Expecting reference token part.
                    $state = $this->processReferencePartState();
                    break;

                case self::STATE_FINISH:
                    // End of text is found, parsing is finished successfully.
                    break 2;

                default:
                    throw new DomainException("Invalid parser state: {$state}");
            }
        }
        $this->locator = $this->getLocatorBuffer();
        return $this
            ->resetLocatorBuffer();
    }