SassScriptLexer.php in Sassy 7.3
File
phpsass/script/SassScriptLexer.php
View source
<?php
require_once 'literals/SassBoolean.php';
require_once 'literals/SassColour.php';
require_once 'literals/SassNumber.php';
require_once 'literals/SassString.php';
require_once 'SassScriptFunction.php';
require_once 'SassScriptOperation.php';
require_once 'SassScriptVariable.php';
class SassScriptLexer {
const MATCH_WHITESPACE = '/^\\s+/';
public static $instance;
public $parser;
public function __construct($parser) {
$this->parser = $parser;
self::$instance = $this;
}
public function lex($string, $context) {
$tokens = array();
while ($string !== false) {
if (($match = $this
->isWhitespace($string)) !== false) {
$tokens[] = null;
}
elseif (($match = SassScriptFunction::isa($string)) !== false) {
preg_match(SassScriptFunction::MATCH_FUNC, $match, $matches);
if (!isset($matches[SassScriptFunction::ARGS])) {
print_r($string);
}
$args = array();
foreach (SassScriptFunction::extractArgs($matches[SassScriptFunction::ARGS]) as $expression) {
$args[] = $this->parser
->evaluate($expression, $context);
}
$tokens[] = new SassScriptFunction($matches[SassScriptFunction::NAME], $args);
}
elseif (($match = SassString::isa($string)) !== false) {
$tokens[] = new SassString($match);
}
elseif (($match = SassBoolean::isa($string)) !== false) {
$tokens[] = new SassBoolean($match);
}
elseif (($match = SassColour::isa($string)) !== false) {
$tokens[] = new SassColour($match);
}
elseif (($match = SassNumber::isa($string)) !== false) {
$tokens[] = new SassNumber($match);
}
elseif (($match = SassScriptOperation::isa($string)) !== false) {
$tokens[] = new SassScriptOperation($match);
}
elseif (($match = SassScriptVariable::isa($string)) !== false) {
$tokens[] = new SassScriptVariable($match);
}
else {
$_string = $string;
$match = '';
while (strlen($_string) && !$this
->isWhitespace($_string)) {
foreach (SassScriptOperation::$inStrOperators as $operator) {
if (substr($_string, 0, strlen($operator)) == $operator) {
break 2;
}
}
$match .= $_string[0];
$_string = substr($_string, 1);
}
$tokens[] = new SassString($match);
}
$string = substr($string, strlen($match));
}
return $tokens;
}
public function isWhitespace($subject) {
return preg_match(self::MATCH_WHITESPACE, $subject, $matches) ? $matches[0] : false;
}
}
Classes
Name |
Description |
SassScriptLexer |
SassScriptLexer class.
Lexes SassSCript into tokens for the parser. |