css-sanitizer
Classes to parse and sanitize CSS
|
Base class for grammar matchers. More...
Public Member Functions | |
capture ( $captureName) | |
Return a copy of this matcher that will capture its matches. | |
matchAgainst (ComponentValueList $values, array $options=[]) | |
Match against a list of ComponentValues. | |
getDefaultOptions () | |
Fetch the default options for this Matcher. | |
setDefaultOptions (array $options) | |
Set the default options for this Matcher. | |
Static Public Member Functions | |
static | create (... $args) |
Create an instance. | |
Protected Member Functions | |
next (ComponentValueList $values, $start, array $options) | |
Find the next ComponentValue in the input, possibly skipping whitespace. | |
makeMatch (ComponentValueList $list, $start, $end, GrammarMatch $submatch=null, array $stack=[]) | |
Create a GrammarMatch. | |
generateMatches (ComponentValueList $values, $start, array $options) | |
Match against a list of ComponentValues. | |
Protected Attributes | |
$captureName = null | |
$defaultOptions | |
Base class for grammar matchers.
The CSS Syntax Level 3 and Values Level 3 specifications use a mostly context-free grammar to define what things like selectors and property values look like. The Matcher classes allow for constructing an object that will determine whether a ComponentValueList actually matches this grammar.
Wikimedia\CSS\Grammar\Matcher::capture | ( | $captureName | ) |
Return a copy of this matcher that will capture its matches.
A "capturing" Matcher will produce GrammarMatches that return a value from the GrammarMatch::getName() method. The GrammarMatch::getCapturedMatches() method may be used to retrieve them from the top-level GrammarMatch.
The concept is similar to capturing groups in PCRE and other regex languages.
string | null | $captureName | Name to apply to captured GrammarMatch objects |
|
static |
Create an instance.
mixed | ...$args See static::__construct() |
|
abstractprotected |
Match against a list of ComponentValues.
The job of a Matcher is to determine all the ways its particular grammar fragment can consume ComponentValues starting at a particular location in the ComponentValueList, represented by returning GrammarMatch objects. For example, a matcher implementing IDENT*
at a starting position where there are three IDENT tokens in a row would be able to match 0, 1, 2, or all 3 of those IDENT tokens, and therefore should return an iterator over that set of GrammarMatch objects.
Some matchers take other matchers as input, for example IDENT*
is probably going to be implemented as a matcher for *
that repeatedly applies a matcher for IDENT
. The *
matcher would call the IDENT
matcher's generateMatches() method directly.
Most Matchers implement this method as a generator to not build up the full set of results when it's reasonably likely the caller is going to terminate early.
ComponentValueList | $values | |
int | $start | Starting position in $values |
array | $options | See self::$defaultOptions. Always use the options passed in, don't use $this->defaultOptions yourself. |
Reimplemented in Wikimedia\CSS\Grammar\Alternative, Wikimedia\CSS\Grammar\AnythingMatcher, Wikimedia\CSS\Grammar\BlockMatcher, Wikimedia\CSS\Grammar\CheckedMatcher, Wikimedia\CSS\Grammar\DelimMatcher, Wikimedia\CSS\Grammar\FunctionMatcher, Wikimedia\CSS\Grammar\KeywordMatcher, Wikimedia\CSS\Grammar\NonEmpty, Wikimedia\CSS\Grammar\NothingMatcher, Wikimedia\CSS\Grammar\NoWhitespace, Wikimedia\CSS\Grammar\TokenMatcher, Wikimedia\CSS\Grammar\UrangeMatcher, Wikimedia\CSS\Grammar\UrlMatcher, and Wikimedia\CSS\Grammar\WhitespaceMatcher.
Wikimedia\CSS\Grammar\Matcher::getDefaultOptions | ( | ) |
Fetch the default options for this Matcher.
|
protected |
Create a GrammarMatch.
ComponentValueList | $list | |
int | $start | |
int | $end | First position after the match |
GrammarMatch | null | $submatch | Sub-match, for capturing. If $submatch itself named it will be kept as a capture in the returned GrammarMatch, otherwise its captured matches (if any) as returned by getCapturedMatches() will be kept as captures in the returned GrammarMatch. |
array | $stack | Stack from which to fetch more submatches for capturing (see $submatch). The stack is expected to be an array of arrays, with the first element of each subarray being a GrammarMatch. |
Wikimedia\CSS\Grammar\Matcher::matchAgainst | ( | ComponentValueList | $values, |
array | $options = [] |
||
) |
Match against a list of ComponentValues.
ComponentValueList | $values | |
array | $options | Matching options, see self::$defaultOptions |
|
protected |
Find the next ComponentValue in the input, possibly skipping whitespace.
ComponentValueList | $values | Input values |
int | $start | Current position in the input. May be -1, in which case the first position in the input should be returned. |
array | $options | See self::$defaultOptions |
Wikimedia\CSS\Grammar\Matcher::setDefaultOptions | ( | array | $options | ) |
Set the default options for this Matcher.
array | $options | See self::$defaultOptions |
|
protected |