private function pathToNode(RoutePath $path, Route $route, int $index): TreeNode
    {
        if ($path instanceof AttributePath) {
            return $this->createAttributeNode($path);
        }

        if ($path instanceof StaticPath) {
            return $this->createStaticNode($path);
        }

        if ($path instanceof OptionalPath) {
            return $this->createOptionalNode();
        }

        return $this->createLeafNode($route, $index);
    }