Skip to content

Commit f7019f8

Browse files
committed
Streamline parsing functions
1 parent 8ac156d commit f7019f8

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

src/Value/CSSFunction.php

+21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Sabberworm\CSS\Value;
44

55
use Sabberworm\CSS\OutputFormat;
6+
use Sabberworm\CSS\Parsing\ParserState;
67

78
/**
89
* A `CSSFunction` represents a special kind of value that also contains a function name and where the values are the
@@ -32,6 +33,26 @@ public function __construct($sName, $aArguments, $sSeparator = ',', $iLineNo = 0
3233
parent::__construct($aArguments, $sSeparator, $iLineNo);
3334
}
3435

36+
/**
37+
* @param ParserState $oParserState
38+
* @param bool $bIgnoreCase
39+
*
40+
* @return CSSFunction
41+
*
42+
* @throws SourceException
43+
* @throws UnexpectedEOFException
44+
* @throws UnexpectedTokenException
45+
*/
46+
public static function parse(ParserState $oParserState, $bIgnoreCase = false)
47+
{
48+
$mResult = $oParserState->parseIdentifier($bIgnoreCase);
49+
$oParserState->consume('(');
50+
$aArguments = Value::parseValue($oParserState, array('=', ' ', ','));
51+
$mResult = new CSSFunction($mResult, $aArguments, ',', $oParserState->currentLine());
52+
$oParserState->consume(')');
53+
return $mResult;
54+
}
55+
3556
/**
3657
* @return string
3758
*/

src/Value/CalcFunction.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ class CalcFunction extends CSSFunction
1919
const T_OPERATOR = 2;
2020

2121
/**
22+
* @param ParserState $oParserState
23+
* @param bool $bIgnoreCase
24+
*
2225
* @return CalcFunction
2326
*
2427
* @throws UnexpectedTokenException
2528
* @throws UnexpectedEOFException
2629
*/
27-
public static function parse(ParserState $oParserState)
30+
public static function parse(ParserState $oParserState, $bIgnoreCase = false)
2831
{
2932
$aOperators = ['+', '-', '*', '/'];
3033
$sFunction = $oParserState->parseIdentifier();

src/Value/Color.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ public function __construct(array $aColor, $iLineNo = 0)
2323
}
2424

2525
/**
26+
* @param ParserState $oParserState
27+
* @param bool $bIgnoreCase
28+
*
2629
* @return Color|CSSFunction
2730
*
2831
* @throws UnexpectedEOFException
2932
* @throws UnexpectedTokenException
3033
*/
31-
public static function parse(ParserState $oParserState)
34+
public static function parse(ParserState $oParserState, $bIgnoreCase = false)
3235
{
3336
$aColor = [];
3437
if ($oParserState->comes('#')) {

src/Value/Value.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,13 @@ public static function parseIdentifierOrFunction(ParserState $oParserState, $bIg
110110
$mResult = $oParserState->parseIdentifier($bIgnoreCase);
111111

112112
if ($oParserState->comes('(')) {
113+
$oAnchor->backtrack();
113114
if ($oParserState->streql('url', $mResult)) {
114-
$oAnchor->backtrack();
115115
$mResult = URL::parse($oParserState);
116116
} else if ($oParserState->streql('calc', $mResult) || $oParserState->streql('-webkit-calc', $mResult) || $oParserState->streql('-moz-calc', $mResult)) {
117-
$oAnchor->backtrack();
118117
$mResult = CalcFunction::parse($oParserState);
119118
} else {
120-
$oParserState->consume('(');
121-
$aArguments = Value::parseValue($oParserState, array('=', ' ', ','));
122-
$mResult = new CSSFunction($mResult, $aArguments, ',', $oParserState->currentLine());
123-
$oParserState->consume(')');
119+
$mResult = CSSFunction::parse($oParserState, $bIgnoreCase);
124120
}
125121
}
126122

0 commit comments

Comments
 (0)