SelectorLexer

This lexer will let us to extract the relevant tokens from our input string: a CSS selector

package

Docxpresso

subpackage

Parser

Methods

Construct

__construct() 
access

public

Classify the tokens in 4 different types: 1. literals: that correspond to names of classes and ids 2. numbers 3. HTML tags: like 'p', 'table', etcetera 4. pseudoclasses: like 'link', 'hover', etcetera 5. pseudoelements: like 'first-letter', 'first-line', etcetera

_detectTokenType(string $tok, boolean $valXPath, string $previous = '') : string
access

private

Arguments

$tok

string

the token that we wish to classify

$valXPath

boolean

if true

$previous

string

Response

string

possible values are 'literal', 'tag', 'pseudoclass' and 'pseudoelement'

Checks if the whitespace withinthe selector is meaningful

_meaningfulWhitespace(integer $k, string $selector) : boolean
access

private

Arguments

$k

integer

the current char in the $selector

$selector

string

the selector we are parsing

Response

boolean

Breaks the selector into tokens of six different types: 1. literals: that correspond to names of classes and ids 2. numbers 3. metachars: that correspond to the special characters used within CSS3 selectors like ' ', '#', '.', '>', etcetera 4. HTML tags: like 'p', 'table', etcetera 5. pseudoclasses: like 'link', 'hover', etcetera 6. pseudoelements: like 'first-letter', 'first-line', etcetera

tokenize(string $selector, boolean $valXPath = false) : array|NULL
access

public

Arguments

$selector

string

$valXPath

boolean

if true will check for non-aceptable XPath pesudoclass and pseudoelements

Response

array|NULL

an array with all tokens together with their types or NULL if $validXPathSelector has been set to true and the CSS selector has XPath equivalent