Skip to content

Commit aa92000

Browse files
committed
Added Origin types
Added an Origin function and Origin variable types.
1 parent 0cf5ed8 commit aa92000

File tree

8 files changed

+134
-23
lines changed

8 files changed

+134
-23
lines changed

CSSParser.php

100644100755
Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,25 @@ private function parseStringValue() {
146146
return new CSSString($sResult);
147147
}
148148

149+
private function parseOriginVariable() {
150+
$this->consume('$');
151+
$sValue = $this->parseIdentifier(false);
152+
153+
return new CSSOriginVariable($sValue);
154+
}
155+
156+
private function parseOriginFunction() {
157+
$this->consume('@');
158+
159+
// Get the function name
160+
$fName = $this->parseIdentifier(false);
161+
$this->consume('(');
162+
$result = new CSSOriginFunction($fName, $this->parseValue(array('=', ',')));
163+
$this->consume(')');
164+
return $result;
165+
166+
}
167+
149168
private function parseCharacter($bIsForIdentifier) {
150169
if($this->peek() === '\\') {
151170
$this->consume('\\');
@@ -176,7 +195,8 @@ private function parseCharacter($bIsForIdentifier) {
176195
return iconv('utf-32le', $this->sCharset, $sUtf32);
177196
}
178197
if($bIsForIdentifier) {
179-
if(preg_match('/[a-zA-Z0-9]|-|_/u', $this->peek()) === 1) {
198+
// We modified this to allow $section->name variables inside CSS functions
199+
if(preg_match('/[a-zA-Z0-9\>\$]|-|_/u', $this->peek()) === 1) {
180200
return $this->consume(1);
181201
} else if(ord($this->peek()) > 0xa1) {
182202
return $this->consume(1);
@@ -291,6 +311,11 @@ private function parsePrimitiveValue() {
291311
$oValue = $this->parseURLValue();
292312
} else if($this->comes("'") || $this->comes('"')){
293313
$oValue = $this->parseStringValue();
314+
} else if($this->comes('$')) {
315+
// This is part of the custom origin variable parsing
316+
$oValue = $this->parseOriginVariable();
317+
} else if($this->comes('@')) {
318+
$oValue = $this->parseOriginFunction();
294319
} else {
295320
$oValue = $this->parseIdentifier();
296321
}
@@ -461,5 +486,4 @@ private function consumeUntil($sEnd) {
461486
private function inputLeft() {
462487
return mb_substr($this->sText, $this->iCurrentPosition, -1, $this->sCharset);
463488
}
464-
}
465-
489+
}

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ PHP CSS Parser
33

44
A Parser for CSS Files written in PHP. Allows extraction of CSS files into a data structure, manipulation of said structure and output as (optimized) CSS.
55

6+
## Modifications
7+
8+
This version of PHP CSS Parser has been modified to work with the origin framework.
9+
10+
### CSS Origin Function
11+
12+
Added an Origin Function type, based on a standard CSS function. It's prefixed by @
13+
14+
### Origin Variable
15+
16+
Variables entered into CSS. Prefixed with $
17+
618
## Usage
719

820
### Installation

lib/CSSList.php

100644100755
Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -149,27 +149,37 @@ public function getSelectorsBySpecificity($sSpecificitySearch = null) {
149149
return $aResult;
150150
}
151151

152-
/**
153-
* Expands all shorthand properties to their long value
154-
*/
155-
public function expandShorthands()
156-
{
157-
foreach($this->getAllDeclarationBlocks() as $oDeclaration)
158-
{
159-
$oDeclaration->expandShorthands();
160-
}
161-
}
152+
/**
153+
* Expands all shorthand properties to their long value
154+
*/
155+
public function expandShorthands() {
156+
foreach($this->getAllDeclarationBlocks() as $oDeclaration) {
157+
$oDeclaration->expandShorthands();
158+
}
159+
}
162160

163-
/*
164-
* Create shorthands properties whenever possible
165-
*/
166-
public function createShorthands()
167-
{
168-
foreach($this->getAllDeclarationBlocks() as $oDeclaration)
169-
{
170-
$oDeclaration->createShorthands();
171-
}
172-
}
161+
/*
162+
* Create shorthands properties whenever possible
163+
*/
164+
public function createShorthands() {
165+
foreach($this->getAllDeclarationBlocks() as $oDeclaration) {
166+
$oDeclaration->createShorthands();
167+
}
168+
}
169+
170+
/**
171+
* Inserts values and executes functions defined by the executor.
172+
*/
173+
public function originProcess($values, $executor){
174+
175+
}
176+
177+
/**
178+
* @return array() Which origin variables affect which rules
179+
*/
180+
public function originGetRules(){
181+
182+
}
173183
}
174184

175185
/**

lib/CSSProperties.php

100644100755
File mode changed.

lib/CSSRule.php

100644100755
File mode changed.

lib/CSSRuleSet.php

100644100755
File mode changed.

lib/CSSValue.php

100644100755
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,36 @@ public function __toString() {
108108
}
109109
}
110110

111+
/**
112+
* An Origin framework style variable.
113+
*/
114+
class CSSOriginVariable extends CSSPrimitiveValue {
115+
private $v;
116+
117+
/**
118+
* @var string The proccessed variable
119+
*/
120+
private $pr;
121+
122+
public function __construct($v){
123+
$this->v = $v;
124+
$this->p = null;
125+
}
126+
127+
public function getVar(){
128+
return $this->v;
129+
}
130+
131+
/**
132+
* Substitutes values from the values array.
133+
*
134+
* @para array $values The values
135+
*/
136+
public function process($values){
137+
138+
}
139+
140+
public function __toString() {
141+
return $this->p;
142+
}
143+
}

lib/CSSValueList.php

100644100755
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,36 @@ public function getColorDescription() {
8989
}
9090
}
9191

92+
class CSSOriginFunction extends CSSValueList {
93+
private $sName;
94+
public function __construct($sName, $aArguments) {
95+
$this->sName = $sName;
96+
parent::__construct($aArguments);
97+
}
98+
99+
/**
100+
* Executes an origin function
101+
*/
102+
public function execute($executor) {
103+
104+
}
105+
106+
public function getName() {
107+
return $this->sName;
108+
}
109+
110+
public function setName($sName) {
111+
$this->sName = $sName;
112+
}
113+
114+
public function getArguments() {
115+
return $this->aComponents;
116+
}
117+
118+
public function __toString() {
119+
$aArguments = parent::__toString();
120+
return "{$this->sName}({$aArguments})";
121+
}
122+
}
123+
92124

0 commit comments

Comments
 (0)