Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Parser.php

function Parser::parseSelectorPartPseudo

Parses a pseudo selector part

Return value

Node\Part\Pseudo|null

Throws

Exception

1 call to Parser::parseSelectorPartPseudo()
Parser::parseSelectorParts in vendor/mck89/peast/lib/Peast/Selector/Parser.php
Parses a set of selector pats

File

vendor/mck89/peast/lib/Peast/Selector/Parser.php, line 266

Class

Parser
Selector parser class

Namespace

Peast\Selector

Code

protected function parseSelectorPartPseudo() {
    if (!$this->consume(":")) {
        return null;
    }
    $name = $this->consumeWord("-");
    if (!isset($this->validPseudo[$name])) {
        throw new Exception("Unsupported pseudo selector '{$name}'");
    }
    $argsType = $this->validPseudo[$name];
    $error = false;
    if ($argsType === 1) {
        $part = new Node\Part\PseudoIndex();
        if (!$this->consume("(")) {
            $error = true;
        }
        if (!$error) {
            $this->consumeWhitespaces();
            if ($indices = $this->consumeRegex("-?\\d*n(?:\\+\\d+)?|\\d+")) {
                $indices = explode("n", $indices);
                if (count($indices) === 1) {
                    $part->setOffset((int) $indices[0]);
                }
                else {
                    switch ($indices[0]) {
                        case "":
                            $part->setStep(1);
                            break;
                        case "-":
                            $part->setStep(-1);
                            break;
                        default:
                            $part->setStep((int) $indices[0]);
                            break;
                    }
                    if ($indices[1] !== "") {
                        $part->setOffset((int) $indices[1]);
                    }
                }
            }
            elseif (($word = $this->consumeWord()) && ($word === "even" || $word === "odd")) {
                $part->setStep(2);
                if ($word === "odd") {
                    $part->setOffset(1);
                }
            }
            else {
                $error = true;
            }
            $this->consumeWhitespaces();
            if (!$error && !$this->consume(")")) {
                $error = true;
            }
        }
    }
    elseif ($argsType === 2) {
        $part = new Node\Part\PseudoSelector();
        if ($this->consume("(") && ($selector = $this->parseSelector($name !== "has")) && $this->consume(")")) {
            $part->setSelector($selector);
        }
        else {
            $error = true;
        }
    }
    else {
        $part = new Node\Part\PseudoSimple();
    }
    if ($error) {
        throw new Exception("Invalid argument for pseudo selector '{$name}'");
    }
    $part->setName($name);
    return $part;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal