Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1432361
BlockMatcher.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
BlockMatcher.php
View Options
<?php
/**
* @file
* @license https://opensource.org/licenses/Apache-2.0 Apache-2.0
*/
namespace
Wikimedia\CSS\Grammar
;
use
InvalidArgumentException
;
use
Wikimedia\CSS\Objects\ComponentValueList
;
use
Wikimedia\CSS\Objects\SimpleBlock
;
/**
* Matcher that matches a SimpleBlock
*
* The grammar definitions in the standards seem to be written assuming they're
* being passed a sequence of Tokens only, even though they're defined over a
* sequence of ComponentValues (which includes SimpleBlocks and CSSFunctions)
* instead.
*
* Thus, to be safe you'll want to use this when a grammar specifies something
* like `'[' <stuff> ']'`.
*/
class
BlockMatcher
extends
Matcher
{
/** @var string One of the Token::T_* constants */
protected
$blockType
;
/** @var Matcher */
protected
$matcher
;
/**
* @param string $blockType One of the Token::T_* constants
* @param Matcher $matcher Matcher for the contents of the block
*/
public
function
__construct
(
$blockType
,
Matcher
$matcher
)
{
if
(
SimpleBlock
::
matchingDelimiter
(
$blockType
)
===
null
)
{
throw
new
InvalidArgumentException
(
'A block is delimited by either {}, [], or ().'
);
}
$this
->
blockType
=
$blockType
;
$this
->
matcher
=
$matcher
;
}
/** @inheritDoc */
protected
function
generateMatches
(
ComponentValueList
$values
,
$start
,
array
$options
)
{
$cv
=
$values
[
$start
]
??
null
;
if
(
$cv
instanceof
SimpleBlock
&&
$cv
->
getStartTokenType
()
===
$this
->
blockType
)
{
// To successfully match, our sub-Matcher needs to match the whole
// content of the block.
$l
=
$cv
->
getValue
()->
count
();
$s
=
$this
->
next
(
$cv
->
getValue
(),
-
1
,
$options
);
foreach
(
$this
->
matcher
->
generateMatches
(
$cv
->
getValue
(),
$s
,
$options
)
as
$match
)
{
if
(
$match
->
getNext
()
===
$l
)
{
// Matched the whole content of the block, so yield the
// token after the block.
yield
$this
->
makeMatch
(
$values
,
$start
,
$this
->
next
(
$values
,
$start
,
$options
),
$match
);
return
;
}
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 21:40 (1 d, 8 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
fc/05/8db52b1172a8b356dcbfcb25b2f3
Default Alt Text
BlockMatcher.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment