\QueryPath\CSSParser

Parse a CSS selector.

In CSS, a selector is used to identify which element or elements in a DOM are being selected for the application of a particular style. Effectively, selectors function as a query language for a structured document -- almost always HTML or XML.

This class provides an event-based parser for CSS selectors. It can be used, for example, as a basis for writing a DOM query engine based on CSS.

Summary

Methods
Properties
Constants
__construct()
parse()
No public properties found
No constants found
No protected methods found
$scanner
$buffer
$handler
$strict
$DEBUG
N/A
selector()
consumeWhitespace()
combinator()
isCombinator()
simpleSelectors()
elementID()
elementClass()
pseudoClass()
pseudoClassValue()
elementName()
allElements()
attribute()
throwError()
No private properties found
N/A

Properties

$scanner

$scanner : 

Type

$buffer

$buffer : 

Type

$handler

$handler : 

Type

$strict

$strict : 

Type

$DEBUG

$DEBUG : 

Type

Methods

__construct()

__construct(  $string, \QueryPath\CSS\EventHandler  $handler) 

Construct a new CSS parser object. This will attempt to parse the string as a CSS selector. As it parses, it will send events to the EventHandler implementation.

Parameters

$string
\QueryPath\CSS\EventHandler $handler

parse()

parse() 

Parse the selector.

This begins an event-based parsing process that will fire events as the selector is handled. A EventHandler implementation will be responsible for handling the events.

Throws

\QueryPath\CSS\ParseException

selector()

selector() 

Handle an entire CSS selector.

consumeWhitespace()

consumeWhitespace() 

Consume whitespace and return a count of the number of whitespace consumed.

combinator()

combinator() 

Handle one of the five combinators: '>', '+', ' ', '~', and ','.

This will call the appropriate event handlers.

isCombinator()

isCombinator(  $tok) 

Check if the token is a combinator.

Parameters

$tok

simpleSelectors()

simpleSelectors() 

Handle a simple selector.

elementID()

elementID() 

Handles CSS ID selectors.

This will call EventHandler::elementID().

elementClass()

elementClass() 

Handles CSS class selectors.

This will call the EventHandler::elementClass() method.

pseudoClass()

pseudoClass(  $restricted = FALSE) 

Handle a pseudo-class and pseudo-element.

CSS 3 selectors support separate pseudo-elements, using :: instead of : for separator. This is now supported, and calls the pseudoElement handler, EventHandler::pseudoElement().

This will call EventHandler::pseudoClass() when a pseudo-class is parsed.

Parameters

$restricted

pseudoClassValue()

pseudoClassValue() : string

Get the value of a pseudo-classes.

Returns

string —

Returns the value found from a pseudo-class.

elementName()

elementName() 

Handle element names.

This will call the EventHandler::elementName().

This handles: name (EventHandler::element()) |name (EventHandler::element()) ns|name (EventHandler::elementNS()) ns|* (EventHandler::elementNS())

allElements()

allElements() 

Check for all elements designators. Due to the new CSS 3 namespace support, this is slightly more complicated, now, as it handles the *|name and *|* cases as well as *.

Calls EventHandler::anyElement() or EventHandler::elementName().

attribute()

attribute() 

Handler an attribute.

An attribute can be in one of two forms: [attrName] or [attrName="AttrValue"]

This may call the following event handlers: EventHandler::attribute().

throwError()

throwError(  $expected,   $got) 

Utility for throwing a consistantly-formatted parse error.

Parameters

$expected
$got