accept($visitor); return (string)$visitor; } /** * Parses a css selector and transforms it into an xpath expression * * @param string $cssSelector * @param int $options * @return string * @throws ParserException */ public static function toXpath(string $cssSelector, int $options = 0): string { $ast = self::getAst($cssSelector); $visitor = new PhpCss\Ast\Visitor\Xpath($options); $ast->accept($visitor); return (string)$visitor; } /** * Parses a css selector and returns the AST * * @param string $cssSelector * @return PhpCss\Ast\Node * @throws ParserException */ public static function getAst(string $cssSelector): PhpCss\Ast\Node { $tokens = array(); $scanner = new PhpCss\Scanner(new PhpCss\Scanner\Status\Selector()); $scanner->scan($tokens, $cssSelector); $parser = new PhpCss\Parser\Standard($tokens); return $parser->parse(); } }